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
22 * @file libavfilter/vf_vflip.c
23 * video vertical flip filter
26 #include "libavutil/pixdesc.h"
30 int vsub; ///< vertical chroma subsampling
33 static int config_input(AVFilterLink *link)
35 FlipContext *flip = link->dst->priv;
37 flip->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;
42 static AVFilterPicRef *get_video_buffer(AVFilterLink *link, int perms,
45 FlipContext *flip = link->dst->priv;
48 AVFilterPicRef *picref = avfilter_get_video_buffer(link->dst->outputs[0],
51 for (i = 0; i < 4; i ++) {
52 int vsub = i == 1 || i == 2 ? flip->vsub : 0;
54 if (picref->data[i]) {
55 picref->data[i] += ((h >> vsub)-1) * picref->linesize[i];
56 picref->linesize[i] = -picref->linesize[i];
63 static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
65 FlipContext *flip = link->dst->priv;
68 for (i = 0; i < 4; i ++) {
69 int vsub = i == 1 || i == 2 ? flip->vsub : 0;
71 if (picref->data[i]) {
72 picref->data[i] += ((link->h >> vsub)-1) * picref->linesize[i];
73 picref->linesize[i] = -picref->linesize[i];
77 avfilter_start_frame(link->dst->outputs[0], picref);
80 static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
82 AVFilterContext *ctx = link->dst;
84 avfilter_draw_slice(ctx->outputs[0], link->h - (y+h), h, -1 * slice_dir);
87 AVFilter avfilter_vf_vflip = {
89 .description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
91 .priv_size = sizeof(FlipContext),
93 .inputs = (AVFilterPad[]) {{ .name = "default",
94 .type = CODEC_TYPE_VIDEO,
95 .get_video_buffer = get_video_buffer,
96 .start_frame = start_frame,
97 .draw_slice = draw_slice,
98 .end_frame = avfilter_null_end_frame,
99 .config_props = config_input, },
101 .outputs = (AVFilterPad[]) {{ .name = "default",
102 .type = CODEC_TYPE_VIDEO, },