2 * Copyright (c) 2007 Bobby Bingham
4 * This file is part of Libav.
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.
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.
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
23 * video vertical flip filter
26 #include "libavutil/internal.h"
27 #include "libavutil/pixdesc.h"
33 int vsub
; ///< vertical chroma subsampling
36 static int config_input(AVFilterLink
*link
)
38 FlipContext
*flip
= link
->dst
->priv
;
39 const AVPixFmtDescriptor
*desc
= av_pix_fmt_desc_get(link
->format
);
41 flip
->vsub
= desc
->log2_chroma_h
;
46 static AVFilterBufferRef
*get_video_buffer(AVFilterLink
*link
, int perms
,
49 FlipContext
*flip
= link
->dst
->priv
;
50 AVFilterBufferRef
*picref
;
53 if (!(perms
& AV_PERM_NEG_LINESIZES
))
54 return ff_default_get_video_buffer(link
, perms
, w
, h
);
56 picref
= ff_get_video_buffer(link
->dst
->outputs
[0], perms
, w
, h
);
60 for (i
= 0; i
< 4; i
++) {
61 int vsub
= i
== 1 || i
== 2 ? flip
->vsub
: 0;
63 if (picref
->data
[i
]) {
64 picref
->data
[i
] += ((h
>> vsub
)-1) * picref
->linesize
[i
];
65 picref
->linesize
[i
] = -picref
->linesize
[i
];
72 static int filter_frame(AVFilterLink
*link
, AVFilterBufferRef
*frame
)
74 FlipContext
*flip
= link
->dst
->priv
;
77 for (i
= 0; i
< 4; i
++) {
78 int vsub
= i
== 1 || i
== 2 ? flip
->vsub
: 0;
81 frame
->data
[i
] += ((link
->h
>> vsub
)-1) * frame
->linesize
[i
];
82 frame
->linesize
[i
] = -frame
->linesize
[i
];
86 return ff_filter_frame(link
->dst
->outputs
[0], frame
);
88 static const AVFilterPad avfilter_vf_vflip_inputs
[] = {
91 .type
= AVMEDIA_TYPE_VIDEO
,
92 .get_video_buffer
= get_video_buffer
,
93 .filter_frame
= filter_frame
,
94 .config_props
= config_input
,
99 static const AVFilterPad avfilter_vf_vflip_outputs
[] = {
102 .type
= AVMEDIA_TYPE_VIDEO
,
107 AVFilter avfilter_vf_vflip
= {
109 .description
= NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
111 .priv_size
= sizeof(FlipContext
),
113 .inputs
= avfilter_vf_vflip_inputs
,
114 .outputs
= avfilter_vf_vflip_outputs
,