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 AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms,
35 AVFilterBufferRef *picref =
36 ff_default_get_video_buffer(link, perms, w, h);
38 FFSWAP(uint8_t*, picref->data[1], picref->data[2]);
39 FFSWAP(int, picref->linesize[1], picref->linesize[2]);
44 static int filter_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
46 FFSWAP(uint8_t*, inpicref->data[1], inpicref->data[2]);
47 FFSWAP(int, inpicref->linesize[1], inpicref->linesize[2]);
49 return ff_filter_frame(link->dst->outputs[0], inpicref);
52 static int is_planar_yuv(const AVPixFmtDescriptor *desc)
56 if (desc->flags & ~(PIX_FMT_BE | PIX_FMT_PLANAR | PIX_FMT_ALPHA) ||
57 desc->nb_components < 3 ||
58 (desc->comp[1].depth_minus1 != desc->comp[2].depth_minus1))
60 for (i = 0; i < desc->nb_components; i++) {
61 if (desc->comp[i].offset_plus1 != 1 ||
62 desc->comp[i].shift != 0 ||
63 desc->comp[i].plane != i)
70 static int query_formats(AVFilterContext *ctx)
72 AVFilterFormats *formats = NULL;
75 for (fmt = 0; fmt < AV_PIX_FMT_NB; fmt++) {
76 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
77 if (is_planar_yuv(desc))
78 ff_add_format(&formats, fmt);
81 ff_set_common_formats(ctx, formats);
85 static const AVFilterPad swapuv_inputs[] = {
88 .type = AVMEDIA_TYPE_VIDEO,
89 .get_video_buffer = get_video_buffer,
90 .filter_frame = filter_frame,
95 static const AVFilterPad swapuv_outputs[] = {
98 .type = AVMEDIA_TYPE_VIDEO,
103 AVFilter avfilter_vf_swapuv = {
105 .description = NULL_IF_CONFIG_SMALL("Swap U and V components."),
107 .query_formats = query_formats,
108 .inputs = swapuv_inputs,
109 .outputs = swapuv_outputs,