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
23 * video vertical flip filter
26 #include "libavutil/internal.h"
27 #include "libavutil/pixdesc.h"
33 int vsub; ///< vertical chroma subsampling
36 static int config_input(AVFilterLink *link)
38 FlipContext *flip = link->dst->priv;
40 flip->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;
45 static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms,
48 FlipContext *flip = link->dst->priv;
49 AVFilterBufferRef *picref;
52 if (!(perms & AV_PERM_NEG_LINESIZES))
53 return ff_default_get_video_buffer(link, perms, w, h);
55 picref = ff_get_video_buffer(link->dst->outputs[0], perms, w, h);
59 for (i = 0; i < 4; i ++) {
60 int vsub = i == 1 || i == 2 ? flip->vsub : 0;
62 if (picref->data[i]) {
63 picref->data[i] += ((h >> vsub)-1) * picref->linesize[i];
64 picref->linesize[i] = -picref->linesize[i];
71 static int start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
73 FlipContext *flip = link->dst->priv;
74 AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
78 return AVERROR(ENOMEM);
80 for (i = 0; i < 4; i ++) {
81 int vsub = i == 1 || i == 2 ? flip->vsub : 0;
83 if (outpicref->data[i]) {
84 outpicref->data[i] += ((link->h >> vsub)-1) * outpicref->linesize[i];
85 outpicref->linesize[i] = -outpicref->linesize[i];
89 return ff_start_frame(link->dst->outputs[0], outpicref);
92 static int draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
94 AVFilterContext *ctx = link->dst;
96 return ff_draw_slice(ctx->outputs[0], link->h - (y+h), h, -1 * slice_dir);
99 AVFilter avfilter_vf_vflip = {
101 .description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
103 .priv_size = sizeof(FlipContext),
105 .inputs = (const AVFilterPad[]) {{ .name = "default",
106 .type = AVMEDIA_TYPE_VIDEO,
107 .get_video_buffer = get_video_buffer,
108 .start_frame = start_frame,
109 .draw_slice = draw_slice,
110 .config_props = config_input, },
112 .outputs = (const AVFilterPad[]) {{ .name = "default",
113 .type = AVMEDIA_TYPE_VIDEO, },