2 * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of FFmpeg.
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.
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.
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
26 #include "libavutil/pixdesc.h"
32 static void do_swap(AVFrame
*frame
)
34 FFSWAP(uint8_t*, frame
->data
[1], frame
->data
[2]);
35 FFSWAP(int, frame
->linesize
[1], frame
->linesize
[2]);
36 FFSWAP(AVBufferRef
*, frame
->buf
[1], frame
->buf
[2]);
39 static AVFrame
*get_video_buffer(AVFilterLink
*link
, int w
, int h
)
41 AVFrame
*picref
= ff_default_get_video_buffer(link
, w
, h
);
46 static int filter_frame(AVFilterLink
*link
, AVFrame
*inpicref
)
49 return ff_filter_frame(link
->dst
->outputs
[0], inpicref
);
52 static int is_planar_yuv(const AVPixFmtDescriptor
*desc
)
56 if (desc
->flags
& ~(AV_PIX_FMT_FLAG_BE
| AV_PIX_FMT_FLAG_PLANAR
| AV_PIX_FMT_FLAG_ALPHA
) ||
57 desc
->nb_components
< 3 ||
58 (desc
->comp
[1].depth
!= desc
->comp
[2].depth
))
60 for (i
= 0; i
< desc
->nb_components
; i
++) {
61 if (desc
->comp
[i
].offset
!= 0 ||
62 desc
->comp
[i
].shift
!= 0 ||
63 desc
->comp
[i
].plane
!= i
)
70 static int query_formats(const AVFilterContext
*ctx
,
71 AVFilterFormatsConfig
**cfg_in
,
72 AVFilterFormatsConfig
**cfg_out
)
74 AVFilterFormats
*formats
= NULL
;
77 for (fmt
= 0; av_pix_fmt_desc_get(fmt
); fmt
++) {
78 const AVPixFmtDescriptor
*desc
= av_pix_fmt_desc_get(fmt
);
79 if (is_planar_yuv(desc
) && (ret
= ff_add_format(&formats
, fmt
)) < 0)
83 return ff_set_common_formats2(ctx
, cfg_in
, cfg_out
, formats
);
86 static const AVFilterPad swapuv_inputs
[] = {
89 .type
= AVMEDIA_TYPE_VIDEO
,
90 .get_buffer
.video
= get_video_buffer
,
91 .filter_frame
= filter_frame
,
95 const FFFilter ff_vf_swapuv
= {
97 .p
.description
= NULL_IF_CONFIG_SMALL("Swap U and V components."),
98 .p
.flags
= AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
,
99 FILTER_INPUTS(swapuv_inputs
),
100 FILTER_OUTPUTS(ff_video_default_filterpad
),
101 FILTER_QUERY_FUNC2(query_formats
),