fate: add h263 obmc vsynth tests
[libav.git] / libavfilter / vf_vflip.c
CommitLineData
c38ae71f 1/*
3fa77bde 2 * Copyright (c) 2007 Bobby Bingham
c38ae71f 3 *
2912e87a 4 * This file is part of Libav.
c38ae71f 5 *
2912e87a 6 * Libav is free software; you can redistribute it and/or
c38ae71f
SS
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.
10 *
2912e87a 11 * Libav is distributed in the hope that it will be useful,
c38ae71f
SS
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.
15 *
16 * You should have received a copy of the GNU Lesser General Public
2912e87a 17 * License along with Libav; if not, write to the Free Software
c38ae71f
SS
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
ba87f080 22 * @file
c38ae71f
SS
23 * video vertical flip filter
24 */
25
1d9c2dc8 26#include "libavutil/internal.h"
b4b66456 27#include "libavutil/pixdesc.h"
c38ae71f 28#include "avfilter.h"
9d0bfc50 29#include "internal.h"
43c7a01e 30#include "video.h"
c38ae71f
SS
31
32typedef struct {
33 int vsub; ///< vertical chroma subsampling
34} FlipContext;
35
36static int config_input(AVFilterLink *link)
37{
38 FlipContext *flip = link->dst->priv;
c38ae71f 39
b4b66456 40 flip->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;
c38ae71f
SS
41
42 return 0;
43}
44
ecc8dada 45static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms,
c38ae71f
SS
46 int w, int h)
47{
48 FlipContext *flip = link->dst->priv;
0ccabeea 49 AVFilterBufferRef *picref;
c38ae71f
SS
50 int i;
51
0ccabeea 52 if (!(perms & AV_PERM_NEG_LINESIZES))
43c7a01e 53 return ff_default_get_video_buffer(link, perms, w, h);
c38ae71f 54
6d58358a 55 picref = ff_get_video_buffer(link->dst->outputs[0], perms, w, h);
8f3a3ce7
AK
56 if (!picref)
57 return NULL;
58
e87eb039
SS
59 for (i = 0; i < 4; i ++) {
60 int vsub = i == 1 || i == 2 ? flip->vsub : 0;
61
c38ae71f 62 if (picref->data[i]) {
e87eb039 63 picref->data[i] += ((h >> vsub)-1) * picref->linesize[i];
c38ae71f
SS
64 picref->linesize[i] = -picref->linesize[i];
65 }
66 }
67
68 return picref;
69}
70
ebc8d974 71static int start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
c38ae71f
SS
72{
73 FlipContext *flip = link->dst->priv;
2609ad3e 74 AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
c38ae71f
SS
75 int i;
76
1dc42050
AK
77 if (!outpicref)
78 return AVERROR(ENOMEM);
79
e87eb039
SS
80 for (i = 0; i < 4; i ++) {
81 int vsub = i == 1 || i == 2 ? flip->vsub : 0;
82
2609ad3e
SS
83 if (outpicref->data[i]) {
84 outpicref->data[i] += ((link->h >> vsub)-1) * outpicref->linesize[i];
85 outpicref->linesize[i] = -outpicref->linesize[i];
c38ae71f
SS
86 }
87 }
88
ebc8d974 89 return ff_start_frame(link->dst->outputs[0], outpicref);
c38ae71f
SS
90}
91
e9b992d0 92static int draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
c38ae71f
SS
93{
94 AVFilterContext *ctx = link->dst;
95
e9b992d0 96 return ff_draw_slice(ctx->outputs[0], link->h - (y+h), h, -1 * slice_dir);
c38ae71f
SS
97}
98
99AVFilter avfilter_vf_vflip = {
100 .name = "vflip",
b70bc022
SS
101 .description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
102
c38ae71f
SS
103 .priv_size = sizeof(FlipContext),
104
3db40703
RB
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, },
111 { .name = NULL}},
112 .outputs = (const AVFilterPad[]) {{ .name = "default",
113 .type = AVMEDIA_TYPE_VIDEO, },
114 { .name = NULL}},
c38ae71f 115};