FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "libavutil/version.h"
28 #include "avfilter.h"
29 #include "formats.h"
30 #include "internal.h"
31 #include "video.h"
32 
33 static void do_swap(AVFrame *frame)
34 {
35  FFSWAP(uint8_t*, frame->data[1], frame->data[2]);
36  FFSWAP(int, frame->linesize[1], frame->linesize[2]);
37  FFSWAP(AVBufferRef*, frame->buf[1], frame->buf[2]);
38 
39 #if FF_API_ERROR_FRAME
41  FFSWAP(uint64_t, frame->error[1], frame->error[2]);
43 #endif
44 }
45 
46 static AVFrame *get_video_buffer(AVFilterLink *link, int w, int h)
47 {
48  AVFrame *picref = ff_default_get_video_buffer(link, w, h);
49  do_swap(picref);
50  return picref;
51 }
52 
53 static int filter_frame(AVFilterLink *link, AVFrame *inpicref)
54 {
55  do_swap(inpicref);
56  return ff_filter_frame(link->dst->outputs[0], inpicref);
57 }
58 
59 static int is_planar_yuv(const AVPixFmtDescriptor *desc)
60 {
61  int i;
62 
64  desc->nb_components < 3 ||
65  (desc->comp[1].depth != desc->comp[2].depth))
66  return 0;
67  for (i = 0; i < desc->nb_components; i++) {
68  if (desc->comp[i].offset != 0 ||
69  desc->comp[i].shift != 0 ||
70  desc->comp[i].plane != i)
71  return 0;
72  }
73 
74  return 1;
75 }
76 
78 {
80  int fmt, ret;
81 
82  for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
83  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
84  if (is_planar_yuv(desc) && (ret = ff_add_format(&formats, fmt)) < 0)
85  return ret;
86  }
87 
88  return ff_set_common_formats(ctx, formats);
89 }
90 
91 static const AVFilterPad swapuv_inputs[] = {
92  {
93  .name = "default",
94  .type = AVMEDIA_TYPE_VIDEO,
95  .get_video_buffer = get_video_buffer,
96  .filter_frame = filter_frame,
97  },
98  { NULL }
99 };
100 
101 static const AVFilterPad swapuv_outputs[] = {
102  {
103  .name = "default",
104  .type = AVMEDIA_TYPE_VIDEO,
105  },
106  { NULL }
107 };
108 
110  .name = "swapuv",
111  .description = NULL_IF_CONFIG_SMALL("Swap U and V components."),
112  .query_formats = query_formats,
113  .inputs = swapuv_inputs,
114  .outputs = swapuv_outputs,
115 };
int plane
Which of the 4 planes contains the component.
Definition: pixdesc.h:35
#define NULL
Definition: coverity.c:32
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2157
This structure describes decoded (raw) audio or video data.
Definition: frame.h:181
static int query_formats(AVFilterContext *ctx)
Definition: vf_swapuv.c:77
AVFormatContext * ctx
Definition: movenc-test.c:48
const char * fmt
Definition: avisynth_c.h:632
Main libavfilter public API header.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:357
static enum AVSampleFormat formats[]
static int is_planar_yuv(const AVPixFmtDescriptor *desc)
Definition: vf_swapuv.c:59
static int filter_frame(AVFilterLink *link, AVFrame *inpicref)
Definition: vf_swapuv.c:53
const char * name
Pad name.
Definition: internal.h:59
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1163
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:173
static AVFrame * frame
attribute_deprecated uint64_t error[AV_NUM_DATA_POINTERS]
Definition: frame.h:300
A filter pad used for either input or output.
Definition: internal.h:53
AVFilter ff_vf_swapuv
Definition: vf_swapuv.c:109
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:568
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:337
Libavutil version macros.
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:83
static void do_swap(AVFrame *frame)
Definition: vf_swapuv.c:33
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:209
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
Filter definition.
Definition: avfilter.h:141
const char * name
Filter name.
Definition: avfilter.h:145
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:316
int shift
Number of least significant bits that must be shifted away to get the value.
Definition: pixdesc.h:53
int offset
Number of elements before the component of the first pixel.
Definition: pixdesc.h:47
static AVFrame * get_video_buffer(AVFilterLink *link, int w, int h)
Definition: vf_swapuv.c:46
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:192
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
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:80
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
Definition: pixdesc.h:128
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:81
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:304
#define FFSWAP(type, a, b)
Definition: common.h:99
static const AVFilterPad swapuv_inputs[]
Definition: vf_swapuv.c:91
static const AVFilterPad swapuv_outputs[]
Definition: vf_swapuv.c:101
internal API functions
int depth
Number of bits in the component.
Definition: pixdesc.h:58
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:144