h264_metadata: Add option to delete filler data
[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 31
58400ac1 32typedef struct FlipContext {
c38ae71f
SS
33 int vsub; ///< vertical chroma subsampling
34} FlipContext;
35
36static int config_input(AVFilterLink *link)
37{
38 FlipContext *flip = link->dst->priv;
59ee9f78 39 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format);
c38ae71f 40
59ee9f78 41 flip->vsub = desc->log2_chroma_h;
c38ae71f
SS
42
43 return 0;
44}
45
7e350379 46static AVFrame *get_video_buffer(AVFilterLink *link, int w, int h)
c38ae71f
SS
47{
48 FlipContext *flip = link->dst->priv;
7e350379 49 AVFrame *frame;
c38ae71f
SS
50 int i;
51
7e350379
AK
52 frame = ff_get_video_buffer(link->dst->outputs[0], w, h);
53 if (!frame)
8f3a3ce7
AK
54 return NULL;
55
e87eb039
SS
56 for (i = 0; i < 4; i ++) {
57 int vsub = i == 1 || i == 2 ? flip->vsub : 0;
58
7e350379
AK
59 if (frame->data[i]) {
60 frame->data[i] += ((h >> vsub) - 1) * frame->linesize[i];
61 frame->linesize[i] = -frame->linesize[i];
c38ae71f
SS
62 }
63 }
64
7e350379 65 return frame;
c38ae71f
SS
66}
67
7e350379 68static int filter_frame(AVFilterLink *link, AVFrame *frame)
c38ae71f
SS
69{
70 FlipContext *flip = link->dst->priv;
c38ae71f
SS
71 int i;
72
e87eb039
SS
73 for (i = 0; i < 4; i ++) {
74 int vsub = i == 1 || i == 2 ? flip->vsub : 0;
75
565e4993
AK
76 if (frame->data[i]) {
77 frame->data[i] += ((link->h >> vsub)-1) * frame->linesize[i];
78 frame->linesize[i] = -frame->linesize[i];
c38ae71f
SS
79 }
80 }
81
565e4993 82 return ff_filter_frame(link->dst->outputs[0], frame);
c38ae71f 83}
568c70e7
MR
84static const AVFilterPad avfilter_vf_vflip_inputs[] = {
85 {
86 .name = "default",
87 .type = AVMEDIA_TYPE_VIDEO,
88 .get_video_buffer = get_video_buffer,
565e4993 89 .filter_frame = filter_frame,
568c70e7
MR
90 .config_props = config_input,
91 },
92 { NULL }
93};
94
95static const AVFilterPad avfilter_vf_vflip_outputs[] = {
96 {
97 .name = "default",
98 .type = AVMEDIA_TYPE_VIDEO,
99 },
100 { NULL }
101};
102
cd43ca04 103AVFilter ff_vf_vflip = {
c38ae71f 104 .name = "vflip",
b70bc022
SS
105 .description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
106
c38ae71f
SS
107 .priv_size = sizeof(FlipContext),
108
568c70e7
MR
109 .inputs = avfilter_vf_vflip_inputs,
110 .outputs = avfilter_vf_vflip_outputs,
c38ae71f 111};