More accurate value for log2(10)
[libav.git] / libavfilter / vf_vflip.c
CommitLineData
c38ae71f
SS
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 libavfilter/vf_vflip.c
23 * video vertical flip filter
24 */
25
b4b66456 26#include "libavutil/pixdesc.h"
c38ae71f
SS
27#include "avfilter.h"
28
29typedef struct {
30 int vsub; ///< vertical chroma subsampling
31} FlipContext;
32
33static int config_input(AVFilterLink *link)
34{
35 FlipContext *flip = link->dst->priv;
c38ae71f 36
b4b66456 37 flip->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;
c38ae71f
SS
38
39 return 0;
40}
41
42static AVFilterPicRef *get_video_buffer(AVFilterLink *link, int perms,
43 int w, int h)
44{
45 FlipContext *flip = link->dst->priv;
46 int i;
47
48 AVFilterPicRef *picref = avfilter_get_video_buffer(link->dst->outputs[0],
49 perms, w, h);
50
e87eb039
SS
51 for (i = 0; i < 4; i ++) {
52 int vsub = i == 1 || i == 2 ? flip->vsub : 0;
53
c38ae71f 54 if (picref->data[i]) {
e87eb039 55 picref->data[i] += ((h >> vsub)-1) * picref->linesize[i];
c38ae71f
SS
56 picref->linesize[i] = -picref->linesize[i];
57 }
58 }
59
60 return picref;
61}
62
63static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
64{
65 FlipContext *flip = link->dst->priv;
66 AVFilterPicRef *ref2 = avfilter_ref_pic(picref, ~0);
67 int i;
68
e87eb039
SS
69 for (i = 0; i < 4; i ++) {
70 int vsub = i == 1 || i == 2 ? flip->vsub : 0;
71
c38ae71f 72 if (ref2->data[i]) {
e87eb039 73 ref2->data[i] += ((link->h >> vsub)-1) * ref2->linesize[i];
c38ae71f
SS
74 ref2->linesize[i] = -ref2->linesize[i];
75 }
76 }
77
78 avfilter_start_frame(link->dst->outputs[0], ref2);
79}
80
a13a5437 81static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
c38ae71f
SS
82{
83 AVFilterContext *ctx = link->dst;
84
a13a5437 85 avfilter_draw_slice(ctx->outputs[0], link->h - (y+h), h, -1 * slice_dir);
c38ae71f
SS
86}
87
88AVFilter avfilter_vf_vflip = {
89 .name = "vflip",
b70bc022
SS
90 .description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
91
c38ae71f
SS
92 .priv_size = sizeof(FlipContext),
93
94 .inputs = (AVFilterPad[]) {{ .name = "default",
95 .type = CODEC_TYPE_VIDEO,
96 .get_video_buffer = get_video_buffer,
97 .start_frame = start_frame,
98 .draw_slice = draw_slice,
99 .config_props = config_input, },
100 { .name = NULL}},
101 .outputs = (AVFilterPad[]) {{ .name = "default",
102 .type = CODEC_TYPE_VIDEO, },
103 { .name = NULL}},
104};