FFmpeg
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/opt.h"
27 #include "libavutil/pixdesc.h"
28 #include "avfilter.h"
29 #include "formats.h"
30 #include "internal.h"
31 #include "video.h"
32 
33 typedef struct SwapUVContext {
34  const AVClass *class;
36 
37 static const AVOption swapuv_options[] = {
38  { NULL }
39 };
40 
41 AVFILTER_DEFINE_CLASS(swapuv);
42 
43 static void do_swap(AVFrame *frame)
44 {
45  FFSWAP(uint8_t*, frame->data[1], frame->data[2]);
46  FFSWAP(int, frame->linesize[1], frame->linesize[2]);
47  FFSWAP(AVBufferRef*, frame->buf[1], frame->buf[2]);
48 }
49 
51 {
53  do_swap(picref);
54  return picref;
55 }
56 
57 static int filter_frame(AVFilterLink *link, AVFrame *inpicref)
58 {
59  do_swap(inpicref);
60  return ff_filter_frame(link->dst->outputs[0], inpicref);
61 }
62 
64 {
65  int i;
66 
68  desc->nb_components < 3 ||
69  (desc->comp[1].depth != desc->comp[2].depth))
70  return 0;
71  for (i = 0; i < desc->nb_components; i++) {
72  if (desc->comp[i].offset != 0 ||
73  desc->comp[i].shift != 0 ||
74  desc->comp[i].plane != i)
75  return 0;
76  }
77 
78  return 1;
79 }
80 
82 {
84  int fmt, ret;
85 
86  for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
88  if (is_planar_yuv(desc) && (ret = ff_add_format(&formats, fmt)) < 0)
89  return ret;
90  }
91 
93 }
94 
95 static const AVFilterPad swapuv_inputs[] = {
96  {
97  .name = "default",
98  .type = AVMEDIA_TYPE_VIDEO,
99  .get_buffer.video = get_video_buffer,
100  .filter_frame = filter_frame,
101  },
102 };
103 
105  .name = "swapuv",
106  .description = NULL_IF_CONFIG_SMALL("Swap U and V components."),
107  .priv_size = sizeof(SwapUVContext),
108  .priv_class = &swapuv_class,
113 };
formats
formats
Definition: signature.h:48
opt.h
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1018
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2962
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
pixdesc.h
w
uint8_t w
Definition: llviddspenc.c:38
AVOption
AVOption.
Definition: opt.h:346
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:159
get_video_buffer
static AVFrame * get_video_buffer(AVFilterLink *link, int w, int h)
Definition: vf_swapuv.c:50
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
video.h
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:557
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:365
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(swapuv)
ff_default_get_video_buffer
AVFrame * ff_default_get_video_buffer(AVFilterLink *link, int w, int h)
Definition: video.c:107
swapuv_inputs
static const AVFilterPad swapuv_inputs[]
Definition: vf_swapuv.c:95
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:33
ff_set_common_formats
int 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:867
ff_video_default_filterpad
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition: video.c:37
do_swap
static void do_swap(AVFrame *frame)
Definition: vf_swapuv.c:43
AV_PIX_FMT_FLAG_ALPHA
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:147
ctx
AVFormatContext * ctx
Definition: movenc.c:48
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:182
link
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame 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
Definition: filter_design.txt:23
frame
static AVFrame * frame
Definition: demux_decode.c:54
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_swapuv.c:81
ff_add_format
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:504
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:106
is_planar_yuv
static int is_planar_yuv(const AVPixFmtDescriptor *desc)
Definition: vf_swapuv.c:63
ff_vf_swapuv
const AVFilter ff_vf_swapuv
Definition: vf_swapuv.c:104
internal.h
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:147
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AV_PIX_FMT_FLAG_BE
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
Definition: pixdesc.h:116
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:39
AVFilter
Filter definition.
Definition: avfilter.h:166
ret
ret
Definition: filter_design.txt:187
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
SwapUVContext
Definition: vf_swapuv.c:33
filter_frame
static int filter_frame(AVFilterLink *link, AVFrame *inpicref)
Definition: vf_swapuv.c:57
avfilter.h
AV_PIX_FMT_FLAG_PLANAR
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:132
AVFilterContext
An instance of a filter.
Definition: avfilter.h:407
desc
const char * desc
Definition: libsvtav1.c:75
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
swapuv_options
static const AVOption swapuv_options[]
Definition: vf_swapuv.c:37
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:183
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:389
h
h
Definition: vp9dsp_template.c:2038