libavfilter/vf_swapuv.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00026 #include "avfilter.h"
00027 
00028 static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms,
00029                                            int w, int h)
00030 {
00031     AVFilterBufferRef *picref =
00032         avfilter_default_get_video_buffer(link, perms, w, h);
00033     uint8_t *tmp;
00034     int tmp2;
00035 
00036     tmp             = picref->data[2];
00037     picref->data[2] = picref->data[1];
00038     picref->data[1] = tmp;
00039 
00040     tmp2                = picref->linesize[2];
00041     picref->linesize[2] = picref->linesize[1];
00042     picref->linesize[1] = tmp2;
00043 
00044     return picref;
00045 }
00046 
00047 static void start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
00048 {
00049     AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
00050 
00051     outpicref->data[1] = inpicref->data[2];
00052     outpicref->data[2] = inpicref->data[1];
00053 
00054     outpicref->linesize[1] = inpicref->linesize[2];
00055     outpicref->linesize[2] = inpicref->linesize[1];
00056 
00057     avfilter_start_frame(link->dst->outputs[0], outpicref);
00058 }
00059 
00060 static int query_formats(AVFilterContext *ctx)
00061 {
00062     static const enum PixelFormat pix_fmts[] = {
00063         PIX_FMT_YUV420P, PIX_FMT_YUVJ420P, PIX_FMT_YUVA420P,
00064         PIX_FMT_YUV444P, PIX_FMT_YUVJ444P,
00065         PIX_FMT_YUV440P, PIX_FMT_YUVJ440P,
00066         PIX_FMT_YUV422P, PIX_FMT_YUVJ422P,
00067         PIX_FMT_YUV411P,
00068         PIX_FMT_NONE,
00069     };
00070 
00071     avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts));
00072     return 0;
00073 }
00074 
00075 AVFilter avfilter_vf_swapuv = {
00076     .name      = "swapuv",
00077     .description = NULL_IF_CONFIG_SMALL("Swap U and V components."),
00078     .priv_size = 0,
00079     .query_formats = query_formats,
00080 
00081     .inputs = (const AVFilterPad[]) {
00082         { .name             = "default",
00083           .type             = AVMEDIA_TYPE_VIDEO,
00084           .get_video_buffer = get_video_buffer,
00085           .start_frame      = start_frame, },
00086         { .name = NULL }
00087     },
00088     .outputs = (const AVFilterPad[]) {
00089         { .name             = "default",
00090           .type             = AVMEDIA_TYPE_VIDEO, },
00091         { .name             = NULL }
00092     },
00093 };