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