Merge remote-tracking branch 'libav/master'
[FFMpeg-mirror/mplayer-patches.git] / libavfilter / vf_vflip.c
blob589a05916c38427283a3191c55062c3a3698d2cf
1 /*
2 * Copyright (c) 2007 Bobby Bingham
4 * This file is part of Libav.
6 * Libav 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 * Libav 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 Libav; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 /**
22 * @file
23 * video vertical flip filter
26 #include "libavutil/internal.h"
27 #include "libavutil/pixdesc.h"
28 #include "avfilter.h"
29 #include "internal.h"
30 #include "video.h"
32 typedef struct {
33 int vsub; ///< vertical chroma subsampling
34 } FlipContext;
36 static int config_input(AVFilterLink *link)
38 FlipContext *flip = link->dst->priv;
39 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format);
41 flip->vsub = desc->log2_chroma_h;
43 return 0;
46 static AVFrame *get_video_buffer(AVFilterLink *link, int w, int h)
48 FlipContext *flip = link->dst->priv;
49 AVFrame *frame;
50 int i;
52 frame = ff_get_video_buffer(link->dst->outputs[0], w, h);
53 if (!frame)
54 return NULL;
56 for (i = 0; i < 4; i ++) {
57 int vsub = i == 1 || i == 2 ? flip->vsub : 0;
59 if (frame->data[i]) {
60 frame->data[i] += ((h >> vsub) - 1) * frame->linesize[i];
61 frame->linesize[i] = -frame->linesize[i];
65 return frame;
68 static int filter_frame(AVFilterLink *link, AVFrame *frame)
70 FlipContext *flip = link->dst->priv;
71 int i;
73 for (i = 0; i < 4; i ++) {
74 int vsub = i == 1 || i == 2 ? flip->vsub : 0;
76 if (frame->data[i]) {
77 frame->data[i] += ((link->h >> vsub)-1) * frame->linesize[i];
78 frame->linesize[i] = -frame->linesize[i];
82 return ff_filter_frame(link->dst->outputs[0], frame);
84 static const AVFilterPad avfilter_vf_vflip_inputs[] = {
86 .name = "default",
87 .type = AVMEDIA_TYPE_VIDEO,
88 .get_video_buffer = get_video_buffer,
89 .filter_frame = filter_frame,
90 .config_props = config_input,
92 { NULL }
95 static const AVFilterPad avfilter_vf_vflip_outputs[] = {
97 .name = "default",
98 .type = AVMEDIA_TYPE_VIDEO,
100 { NULL }
103 AVFilter avfilter_vf_vflip = {
104 .name = "vflip",
105 .description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
107 .priv_size = sizeof(FlipContext),
109 .inputs = avfilter_vf_vflip_inputs,
110 .outputs = avfilter_vf_vflip_outputs,