vf_swapuv.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * swap UV filter
24  */
25 
26 #include "libavutil/pixdesc.h"
27 #include "avfilter.h"
28 #include "formats.h"
29 #include "internal.h"
30 #include "video.h"
31 
32 static void do_swap(AVFrame *frame)
33 {
34  FFSWAP(uint8_t*, frame->data[1], frame->data[2]);
35  FFSWAP(int, frame->linesize[1], frame->linesize[2]);
36  FFSWAP(uint64_t, frame->error[1], frame->error[2]);
37  FFSWAP(AVBufferRef*, frame->buf[1], frame->buf[2]);
38 }
39 
41 {
42  AVFrame *picref = ff_default_get_video_buffer(link, w, h);
43  do_swap(picref);
44  return picref;
45 }
46 
47 static int filter_frame(AVFilterLink *link, AVFrame *inpicref)
48 {
49  do_swap(inpicref);
50  return ff_filter_frame(link->dst->outputs[0], inpicref);
51 }
52 
53 static int is_planar_yuv(const AVPixFmtDescriptor *desc)
54 {
55  int i;
56 
57  if (desc->flags & ~(PIX_FMT_BE | PIX_FMT_PLANAR | PIX_FMT_ALPHA) ||
58  desc->nb_components < 3 ||
59  (desc->comp[1].depth_minus1 != desc->comp[2].depth_minus1))
60  return 0;
61  for (i = 0; i < desc->nb_components; i++) {
62  if (desc->comp[i].offset_plus1 != 1 ||
63  desc->comp[i].shift != 0 ||
64  desc->comp[i].plane != i)
65  return 0;
66  }
67 
68  return 1;
69 }
70 
72 {
74  int fmt;
75 
76  for (fmt = 0; fmt < AV_PIX_FMT_NB; fmt++) {
77  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
78  if (is_planar_yuv(desc))
79  ff_add_format(&formats, fmt);
80  }
81 
82  ff_set_common_formats(ctx, formats);
83  return 0;
84 }
85 
86 static const AVFilterPad swapuv_inputs[] = {
87  {
88  .name = "default",
89  .type = AVMEDIA_TYPE_VIDEO,
90  .get_video_buffer = get_video_buffer,
91  .filter_frame = filter_frame,
92  },
93  { NULL }
94 };
95 
96 static const AVFilterPad swapuv_outputs[] = {
97  {
98  .name = "default",
99  .type = AVMEDIA_TYPE_VIDEO,
100  },
101  { NULL }
102 };
103 
105  .name = "swapuv",
106  .description = NULL_IF_CONFIG_SMALL("Swap U and V components."),
107  .priv_size = 0,
108  .query_formats = query_formats,
109  .inputs = swapuv_inputs,
110  .outputs = swapuv_outputs,
111 };
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1778
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
static int query_formats(AVFilterContext *ctx)
Definition: vf_swapuv.c:71
const char * fmt
Definition: avisynth_c.h:669
external API header
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:343
AVFilter avfilter_vf_swapuv
Definition: vf_swapuv.c:104
static int is_planar_yuv(const AVPixFmtDescriptor *desc)
Definition: vf_swapuv.c:53
output residual component w
static int filter_frame(AVFilterLink *link, AVFrame *inpicref)
Definition: vf_swapuv.c:47
uint16_t shift
number of least significant bits that must be shifted away to get the value
Definition: pixdesc.h:42
const char * name
Pad name.
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:86
uint8_t
it can be given away to ff_start_frame *A reference passed to ff_filter_frame(or the deprecated ff_start_frame) is given away and must no longer be used.*A reference created with avfilter_ref_buffer belongs to the code that created it.*A reference obtained with ff_get_video_buffer or ff_get_audio_buffer belongs to the code that requested it.*A reference given as return value by the get_video_buffer or get_audio_buffer method is given away and must no longer be used.Link reference fields---------------------The AVFilterLink structure has a few AVFilterBufferRef fields.The cur_buf and out_buf were used with the deprecated start_frame/draw_slice/end_frame API and should no longer be used.src_buf
void ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:545
frame
Definition: stft.m:14
A filter pad used for either input or output.
uint16_t depth_minus1
number of bits in the component minus 1
Definition: pixdesc.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:344
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:57
static void do_swap(AVFrame *frame)
Definition: vf_swapuv.c:32
NULL
Definition: eval.c:55
uint64_t error[AV_NUM_DATA_POINTERS]
error
Definition: frame.h:254
#define PIX_FMT_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:93
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:101
uint8_t flags
Definition: pixdesc.h:76
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:55
Filter definition.
Definition: avfilter.h:436
synthesis window for stochastic i
const char * name
filter name
Definition: avfilter.h:437
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:539
static AVFrame * get_video_buffer(AVFilterLink *link, int w, int h)
Definition: vf_swapuv.c:40
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:87
AVFrame * ff_default_get_video_buffer(AVFilterLink *link, int w, int h)
Definition: video.c:43
A reference to a data buffer.
Definition: buffer.h:81
uint16_t plane
which of the 4 planes contains the component
Definition: pixdesc.h:29
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common formats
Definition: swscale.txt:33
#define PIX_FMT_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:102
uint16_t offset_plus1
Number of elements before the component of the first pixel plus 1.
Definition: pixdesc.h:41
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:524
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
Definition: pixfmt.h:237
#define FFSWAP(type, a, b)
Definition: common.h:61
static const AVFilterPad swapuv_inputs[]
Definition: vf_swapuv.c:86
static const AVFilterPad swapuv_outputs[]
Definition: vf_swapuv.c:96
internal API functions
#define PIX_FMT_BE
Pixel format is big-endian.
Definition: pixdesc.h:89