]> git.sesse.net Git - ffmpeg/blob - libavfilter/vf_vflip.c
lpc: Add a function for calculating reflection coefficients from samples
[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/internal.h"
27 #include "libavutil/pixdesc.h"
28 #include "avfilter.h"
29 #include "internal.h"
30 #include "video.h"
31
32 typedef struct {
33     int vsub;   ///< vertical chroma subsampling
34 } FlipContext;
35
36 static int config_input(AVFilterLink *link)
37 {
38     FlipContext *flip = link->dst->priv;
39     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format);
40
41     flip->vsub = desc->log2_chroma_h;
42
43     return 0;
44 }
45
46 static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms,
47                                         int w, int h)
48 {
49     FlipContext *flip = link->dst->priv;
50     AVFilterBufferRef *picref;
51     int i;
52
53     if (!(perms & AV_PERM_NEG_LINESIZES))
54         return ff_default_get_video_buffer(link, perms, w, h);
55
56     picref = ff_get_video_buffer(link->dst->outputs[0], perms, w, h);
57     if (!picref)
58         return NULL;
59
60     for (i = 0; i < 4; i ++) {
61         int vsub = i == 1 || i == 2 ? flip->vsub : 0;
62
63         if (picref->data[i]) {
64             picref->data[i] += ((h >> vsub)-1) * picref->linesize[i];
65             picref->linesize[i] = -picref->linesize[i];
66         }
67     }
68
69     return picref;
70 }
71
72 static int start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
73 {
74     FlipContext *flip = link->dst->priv;
75     AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
76     int i;
77
78     if (!outpicref)
79         return AVERROR(ENOMEM);
80
81     for (i = 0; i < 4; i ++) {
82         int vsub = i == 1 || i == 2 ? flip->vsub : 0;
83
84         if (outpicref->data[i]) {
85             outpicref->data[i] += ((link->h >> vsub)-1) * outpicref->linesize[i];
86             outpicref->linesize[i] = -outpicref->linesize[i];
87         }
88     }
89
90     return ff_start_frame(link->dst->outputs[0], outpicref);
91 }
92
93 static int draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
94 {
95     AVFilterContext *ctx = link->dst;
96
97     return ff_draw_slice(ctx->outputs[0], link->h - (y+h), h, -1 * slice_dir);
98 }
99
100 static const AVFilterPad avfilter_vf_vflip_inputs[] = {
101     {
102         .name             = "default",
103         .type             = AVMEDIA_TYPE_VIDEO,
104         .get_video_buffer = get_video_buffer,
105         .start_frame      = start_frame,
106         .draw_slice       = draw_slice,
107         .config_props     = config_input,
108     },
109     { NULL }
110 };
111
112 static const AVFilterPad avfilter_vf_vflip_outputs[] = {
113     {
114         .name = "default",
115         .type = AVMEDIA_TYPE_VIDEO,
116     },
117     { NULL }
118 };
119
120 AVFilter avfilter_vf_vflip = {
121     .name      = "vflip",
122     .description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
123
124     .priv_size = sizeof(FlipContext),
125
126     .inputs    = avfilter_vf_vflip_inputs,
127     .outputs   = avfilter_vf_vflip_outputs,
128 };