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/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;
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 
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 filter_frame(AVFilterLink *link, AVFilterBufferRef *frame)
73 {
74  FlipContext *flip = link->dst->priv;
75  int i;
76 
77  for (i = 0; i < 4; i ++) {
78  int vsub = i == 1 || i == 2 ? flip->vsub : 0;
79 
80  if (frame->data[i]) {
81  frame->data[i] += ((link->h >> vsub)-1) * frame->linesize[i];
82  frame->linesize[i] = -frame->linesize[i];
83  }
84  }
85 
86  return ff_filter_frame(link->dst->outputs[0], frame);
87 }
89  {
90  .name = "default",
91  .type = AVMEDIA_TYPE_VIDEO,
92  .get_video_buffer = get_video_buffer,
93  .filter_frame = filter_frame,
94  .config_props = config_input,
95  },
96  { NULL }
97 };
98 
100  {
101  .name = "default",
102  .type = AVMEDIA_TYPE_VIDEO,
103  },
104  { NULL }
105 };
106 
108  .name = "vflip",
109  .description = NULL_IF_CONFIG_SMALL("Flip the input video vertically."),
110 
111  .priv_size = sizeof(FlipContext),
112 
113  .inputs = avfilter_vf_vflip_inputs,
114  .outputs = avfilter_vf_vflip_outputs,
115 };
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1435
int linesize[8]
number of bytes per line
Definition: avfilter.h:157
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:122
int ff_filter_frame(AVFilterLink *link, AVFilterBufferRef *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:459
const char * name
Pad name.
Definition: internal.h:39
AVFilterBufferRef * ff_default_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
Definition: video.c:80
static const AVFilterPad avfilter_vf_vflip_inputs[]
Definition: vf_vflip.c:88
A filter pad used for either input or output.
Definition: internal.h:33
AVFilterBufferRef * ff_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:145
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:88
void * priv
private data for use by the filter
Definition: avfilter.h:439
AVFilter avfilter_vf_vflip
Definition: vf_vflip.c:107
common internal API header
static AVFilterBufferRef * get_video_buffer(AVFilterLink *link, int perms, int w, int h)
Definition: vf_vflip.c:46
static int config_input(AVFilterLink *link)
Definition: vf_vflip.c:36
A reference to an AVFilterBuffer.
Definition: avfilter.h:139
NULL
Definition: eval.c:52
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:55
Filter definition.
Definition: avfilter.h:371
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:110
const char * name
filter name
Definition: avfilter.h:372
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:433
static void flip(AVCodecContext *avctx, AVPicture *picture)
Definition: rawdec.c:110
static int filter_frame(AVFilterLink *link, AVFilterBufferRef *frame)
Definition: vf_vflip.c:72
static const AVFilterPad avfilter_vf_vflip_outputs[]
Definition: vf_vflip.c:99
uint8_t * data[8]
picture/audio data for each plane
Definition: avfilter.h:141
int vsub
chroma subsampling
Definition: vf_hflip.c:40
internal API functions
#define AV_PERM_NEG_LINESIZES
the buffer requested can have negative linesizes
Definition: avfilter.h:102