vf_vflip.c
Go to the documentation of this file.
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 
26 #include "libavutil/pixdesc.h"
27 #include "avfilter.h"
28 
29 typedef struct {
30  int vsub;
31 } FlipContext;
32 
33 static int config_input(AVFilterLink *link)
34 {
35  FlipContext *flip = link->dst->priv;
36 
38 
39  return 0;
40 }
41 
43  int w, int h)
44 {
45  FlipContext *flip = link->dst->priv;
46  AVFilterBufferRef *picref;
47  int i;
48 
49  if (!(perms & AV_PERM_NEG_LINESIZES))
50  return avfilter_default_get_video_buffer(link, perms, w, h);
51 
52  picref = avfilter_get_video_buffer(link->dst->outputs[0], perms, w, h);
53  for (i = 0; i < 4; i ++) {
54  int vsub = i == 1 || i == 2 ? flip->vsub : 0;
55 
56  if (picref->data[i]) {
57  picref->data[i] += ((h >> vsub)-1) * picref->linesize[i];
58  picref->linesize[i] = -picref->linesize[i];
59  }
60  }
61 
62  return picref;
63 }
64 
65 static void start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
66 {
67  FlipContext *flip = link->dst->priv;
68  AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
69  int i;
70 
71  for (i = 0; i < 4; i ++) {
72  int vsub = i == 1 || i == 2 ? flip->vsub : 0;
73 
74  if (outpicref->data[i]) {
75  outpicref->data[i] += ((link->h >> vsub)-1) * outpicref->linesize[i];
76  outpicref->linesize[i] = -outpicref->linesize[i];
77  }
78  }
79 
80  avfilter_start_frame(link->dst->outputs[0], outpicref);
81 }
82 
83 static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
84 {
85  AVFilterContext *ctx = link->dst;
86 
87  avfilter_draw_slice(ctx->outputs[0], link->h - (y+h), h, -1 * slice_dir);
88 }
89 
91  .name = "vflip",
92  .description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
93 
94  .priv_size = sizeof(FlipContext),
95 
96  .inputs = (AVFilterPad[]) {{ .name = "default",
97  .type = AVMEDIA_TYPE_VIDEO,
98  .get_video_buffer = get_video_buffer,
99  .start_frame = start_frame,
100  .draw_slice = draw_slice,
101  .config_props = config_input, },
102  { .name = NULL}},
103  .outputs = (AVFilterPad[]) {{ .name = "default",
104  .type = AVMEDIA_TYPE_VIDEO, },
105  { .name = NULL}},
106 };
AVFilterBufferRef * avfilter_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: avfilter.c:289
int linesize[8]
number of bytes per line
Definition: avfilter.h:127
static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
Definition: vf_vflip.c:83
A filter pad used for either input or output.
Definition: avfilter.h:312
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:75
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:191
void * priv
private data for use by the filter
Definition: avfilter.h:553
AVFilterBufferRef * avfilter_default_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
default handler for get_video_buffer() for video inputs
Definition: defaults.c:38
const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB]
The array of all the pixel format descriptors.
Definition: pixdesc.c:119
AVFilter avfilter_vf_vflip
Definition: vf_vflip.c:90
void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
Send a slice to the next filter.
Definition: avfilter.c:447
static AVFilterBufferRef * get_video_buffer(AVFilterLink *link, int perms, int w, int h)
Definition: vf_vflip.c:42
static int config_input(AVFilterLink *link)
Definition: vf_vflip.c:33
A reference to an AVFilterBuffer.
Definition: avfilter.h:124
NULL
Definition: eval.c:50
Filter definition.
Definition: avfilter.h:497
AVFilterBufferRef * avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask)
Add a new reference to a buffer.
Definition: avfilter.c:47
void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
Notify the next filter of the start of a frame.
Definition: avfilter.c:400
static void start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
Definition: vf_vflip.c:65
const char * name
filter name
Definition: avfilter.h:498
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:551
static void flip(AVCodecContext *avctx, AVPicture *picture)
Definition: rawdec.c:110
uint8_t * data[8]
picture/audio data for each plane
Definition: avfilter.h:126
An instance of a filter.
Definition: avfilter.h:538
int vsub
chroma subsampling
Definition: vf_hflip.c:34
#define AV_PERM_NEG_LINESIZES
the buffer requested can have negative linesizes
Definition: avfilter.h:86