]> git.sesse.net Git - ffmpeg/blob - libavfilter/vf_swapuv.c
lavfi/swapuv: switch to filter_frame API
[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 #include "formats.h"
28 #include "internal.h"
29 #include "video.h"
30
31 static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms,
32                                            int w, int h)
33 {
34     AVFilterBufferRef *picref =
35         ff_default_get_video_buffer(link, perms, w, h);
36     uint8_t *tmp;
37     int tmp2;
38
39     tmp             = picref->data[2];
40     picref->data[2] = picref->data[1];
41     picref->data[1] = tmp;
42
43     tmp2                = picref->linesize[2];
44     picref->linesize[2] = picref->linesize[1];
45     picref->linesize[1] = tmp2;
46
47     return picref;
48 }
49
50 static int filter_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
51 {
52     uint8_t *tmp_data;
53     int tmp_linesize;
54
55     tmp_data          = inpicref->data[1];
56     inpicref->data[1] = inpicref->data[2];
57     inpicref->data[2] = tmp_data;
58
59     tmp_linesize          = inpicref->linesize[1];
60     inpicref->linesize[1] = inpicref->linesize[2];
61     inpicref->linesize[2] = tmp_linesize;
62
63     return ff_filter_frame(link->dst->outputs[0], inpicref);
64 }
65
66 static int query_formats(AVFilterContext *ctx)
67 {
68     static const enum AVPixelFormat pix_fmts[] = {
69         AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVA420P,
70         AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVA444P,
71         AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUVJ440P,
72         AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVJ422P,
73         AV_PIX_FMT_YUV411P,
74         AV_PIX_FMT_NONE,
75     };
76
77     ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
78     return 0;
79 }
80
81 static const AVFilterPad swapuv_inputs[] = {
82     {
83         .name             = "default",
84         .type             = AVMEDIA_TYPE_VIDEO,
85         .get_video_buffer = get_video_buffer,
86         .filter_frame     = filter_frame,
87     },
88     { NULL }
89 };
90
91 static const AVFilterPad swapuv_outputs[] = {
92     {
93         .name = "default",
94         .type = AVMEDIA_TYPE_VIDEO,
95     },
96     { NULL }
97 };
98
99 AVFilter avfilter_vf_swapuv = {
100     .name      = "swapuv",
101     .description = NULL_IF_CONFIG_SMALL("Swap U and V components."),
102     .priv_size = 0,
103     .query_formats = query_formats,
104     .inputs        = swapuv_inputs,
105     .outputs       = swapuv_outputs,
106 };