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