Add video vertical flip filter.
[ffmpeg-lucabe.git] / libavfilter / vf_vflip.c
blob5a52479dc5c9aa7916867b77956eb6a94ffca786
1 /*
2 * copyright (c) 2007 Bobby Bingham
4 * This file is part of FFmpeg.
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.
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.
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
21 /**
22 * @file libavfilter/vf_vflip.c
23 * video vertical flip filter
26 #include "avfilter.h"
28 typedef struct {
29 int vsub; ///< vertical chroma subsampling
30 } FlipContext;
32 static int config_input(AVFilterLink *link)
34 FlipContext *flip = link->dst->priv;
35 int tmp;
37 avcodec_get_chroma_sub_sample(link->format, &tmp, &flip->vsub);
39 return 0;
42 static AVFilterPicRef *get_video_buffer(AVFilterLink *link, int perms,
43 int w, int h)
45 FlipContext *flip = link->dst->priv;
46 int i;
48 AVFilterPicRef *picref = avfilter_get_video_buffer(link->dst->outputs[0],
49 perms, w, h);
51 picref->data[0] += (h-1) * picref->linesize[0];
52 picref->linesize[0] = -picref->linesize[0];
53 for (i = 1; i < 4; i ++) {
54 if (picref->data[i]) {
55 picref->data[i] += ((h >> flip->vsub)-1) * picref->linesize[i];
56 picref->linesize[i] = -picref->linesize[i];
60 return picref;
63 static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
65 FlipContext *flip = link->dst->priv;
66 AVFilterPicRef *ref2 = avfilter_ref_pic(picref, ~0);
67 int i;
69 ref2->data[0] += (link->h-1) * ref2->linesize[0];
70 ref2->linesize[0] = -ref2->linesize[0];
71 for (i = 1; i < 4; i ++) {
72 if (ref2->data[i]) {
73 ref2->data[i] += ((link->h >> flip->vsub)-1) * ref2->linesize[i];
74 ref2->linesize[i] = -ref2->linesize[i];
78 avfilter_start_frame(link->dst->outputs[0], ref2);
81 static void draw_slice(AVFilterLink *link, int y, int h)
83 AVFilterContext *ctx = link->dst;
85 avfilter_draw_slice(ctx->outputs[0], link->h - (y+h), h);
88 AVFilter avfilter_vf_vflip = {
89 .name = "vflip",
90 .priv_size = sizeof(FlipContext),
92 .inputs = (AVFilterPad[]) {{ .name = "default",
93 .type = CODEC_TYPE_VIDEO,
94 .get_video_buffer = get_video_buffer,
95 .start_frame = start_frame,
96 .draw_slice = draw_slice,
97 .config_props = config_input, },
98 { .name = NULL}},
99 .outputs = (AVFilterPad[]) {{ .name = "default",
100 .type = CODEC_TYPE_VIDEO, },
101 { .name = NULL}},