]> git.sesse.net Git - ffmpeg/blob - libavfilter/vf_swapuv.c
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libavfilter / vf_swapuv.c
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 "avfilter.h"
27
28 static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms,
29                                            int w, int h)
30 {
31     AVFilterBufferRef *picref =
32         avfilter_default_get_video_buffer(link, perms, w, h);
33     uint8_t *tmp;
34     int tmp2;
35
36     tmp             = picref->data[2];
37     picref->data[2] = picref->data[1];
38     picref->data[1] = tmp;
39
40     tmp2                = picref->linesize[2];
41     picref->linesize[2] = picref->linesize[1];
42     picref->linesize[1] = tmp2;
43
44     return picref;
45 }
46
47 static void start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
48 {
49     AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
50
51     outpicref->data[1] = inpicref->data[2];
52     outpicref->data[2] = inpicref->data[1];
53
54     outpicref->linesize[1] = inpicref->linesize[2];
55     outpicref->linesize[2] = inpicref->linesize[1];
56
57     avfilter_start_frame(link->dst->outputs[0], outpicref);
58 }
59
60 static int query_formats(AVFilterContext *ctx)
61 {
62     static const enum PixelFormat pix_fmts[] = {
63         PIX_FMT_YUV420P, PIX_FMT_YUVJ420P, PIX_FMT_YUVA420P,
64         PIX_FMT_YUV444P, PIX_FMT_YUVJ444P, PIX_FMT_YUVA444P,
65         PIX_FMT_YUV440P, PIX_FMT_YUVJ440P,
66         PIX_FMT_YUV422P, PIX_FMT_YUVJ422P,
67         PIX_FMT_YUV411P,
68         PIX_FMT_NONE,
69     };
70
71     avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
72     return 0;
73 }
74
75 AVFilter avfilter_vf_swapuv = {
76     .name      = "swapuv",
77     .description = NULL_IF_CONFIG_SMALL("Swap U and V components."),
78     .priv_size = 0,
79     .query_formats = query_formats,
80
81     .inputs = (const AVFilterPad[]) {
82         { .name             = "default",
83           .type             = AVMEDIA_TYPE_VIDEO,
84           .get_video_buffer = get_video_buffer,
85           .start_frame      = start_frame, },
86         { .name = NULL }
87     },
88     .outputs = (const AVFilterPad[]) {
89         { .name             = "default",
90           .type             = AVMEDIA_TYPE_VIDEO, },
91         { .name             = NULL }
92     },
93 };