]> git.sesse.net Git - ffmpeg/blob - libavfilter/vf_vflip.c
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libavfilter / vf_vflip.c
1 /*
2  * Copyright (c) 2007 Bobby Bingham
3  *
4  * This file is part of FFmpeg.
5  *
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.
10  *
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.
15  *
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
19  */
20
21 /**
22  * @file
23  * video vertical flip filter
24  */
25
26 #include "libavutil/pixdesc.h"
27 #include "avfilter.h"
28 #include "internal.h"
29 #include "video.h"
30
31 typedef struct {
32     int vsub;   ///< vertical chroma subsampling
33 } FlipContext;
34
35 static int config_input(AVFilterLink *link)
36 {
37     FlipContext *flip = link->dst->priv;
38
39     flip->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;
40
41     return 0;
42 }
43
44 static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms,
45                                         int w, int h)
46 {
47     FlipContext *flip = link->dst->priv;
48     AVFilterBufferRef *picref;
49     int i;
50
51     if (!(perms & AV_PERM_NEG_LINESIZES))
52         return ff_default_get_video_buffer(link, perms, w, h);
53
54     picref = ff_get_video_buffer(link->dst->outputs[0], perms, w, h);
55     for (i = 0; i < 4; i ++) {
56         int vsub = i == 1 || i == 2 ? flip->vsub : 0;
57
58         if (picref->data[i]) {
59             picref->data[i] += (((h + (1<<vsub)-1) >> vsub)-1) * picref->linesize[i];
60             picref->linesize[i] = -picref->linesize[i];
61         }
62     }
63
64     return picref;
65 }
66
67 static void start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
68 {
69     FlipContext *flip = link->dst->priv;
70     AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
71     int i;
72
73     for (i = 0; i < 4; i ++) {
74         int vsub = i == 1 || i == 2 ? flip->vsub : 0;
75
76         if (outpicref->data[i]) {
77             outpicref->data[i] += (((link->h + (1<<vsub)-1)>> vsub)-1) * outpicref->linesize[i];
78             outpicref->linesize[i] = -outpicref->linesize[i];
79         }
80     }
81
82     ff_start_frame(link->dst->outputs[0], outpicref);
83 }
84
85 static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
86 {
87     AVFilterContext *ctx = link->dst;
88
89     ff_draw_slice(ctx->outputs[0], link->h - (y+h), h, -1 * slice_dir);
90 }
91
92 AVFilter avfilter_vf_vflip = {
93     .name      = "vflip",
94     .description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
95
96     .priv_size = sizeof(FlipContext),
97
98     .inputs    = (const AVFilterPad[]) {{ .name       = "default",
99                                     .type             = AVMEDIA_TYPE_VIDEO,
100                                     .get_video_buffer = get_video_buffer,
101                                     .start_frame      = start_frame,
102                                     .draw_slice       = draw_slice,
103                                     .config_props     = config_input, },
104                                   { .name = NULL}},
105     .outputs   = (const AVFilterPad[]) {{ .name       = "default",
106                                     .type             = AVMEDIA_TYPE_VIDEO, },
107                                   { .name = NULL}},
108 };