vf_hflip.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 Benoit Fouet
3  * Copyright (c) 2010 Stefano Sabatini
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
27 #include <string.h>
28 
29 #include "avfilter.h"
30 #include "formats.h"
31 #include "internal.h"
32 #include "video.h"
33 #include "libavutil/pixdesc.h"
34 #include "libavutil/internal.h"
35 #include "libavutil/intreadwrite.h"
36 #include "libavutil/imgutils.h"
37 
38 typedef struct {
39  int max_step[4];
40  int hsub, vsub;
41 } FlipContext;
42 
44 {
45  static const enum AVPixelFormat pix_fmts[] = {
69  };
70 
72  return 0;
73 }
74 
75 static int config_props(AVFilterLink *inlink)
76 {
77  FlipContext *flip = inlink->dst->priv;
78  const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
79 
80  av_image_fill_max_pixsteps(flip->max_step, NULL, pix_desc);
81  flip->hsub = pix_desc->log2_chroma_w;
82  flip->vsub = pix_desc->log2_chroma_h;
83 
84  return 0;
85 }
86 
88 {
89  AVFilterContext *ctx = inlink->dst;
90  FlipContext *flip = ctx->priv;
91  AVFilterLink *outlink = ctx->outputs[0];
92  AVFilterBufferRef *out;
93  uint8_t *inrow, *outrow;
94  int i, j, plane, step, hsub, vsub;
95 
96  out = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
97  if (!out) {
99  return AVERROR(ENOMEM);
100  }
102 
103  for (plane = 0; plane < 4 && in->data[plane]; plane++) {
104  step = flip->max_step[plane];
105  hsub = (plane == 1 || plane == 2) ? flip->hsub : 0;
106  vsub = (plane == 1 || plane == 2) ? flip->vsub : 0;
107 
108  outrow = out->data[plane];
109  inrow = in ->data[plane] + ((inlink->w >> hsub) - 1) * step;
110  for (i = 0; i < in->video->h >> vsub; i++) {
111  switch (step) {
112  case 1:
113  for (j = 0; j < (inlink->w >> hsub); j++)
114  outrow[j] = inrow[-j];
115  break;
116 
117  case 2:
118  {
119  uint16_t *outrow16 = (uint16_t *)outrow;
120  uint16_t * inrow16 = (uint16_t *) inrow;
121  for (j = 0; j < (inlink->w >> hsub); j++)
122  outrow16[j] = inrow16[-j];
123  }
124  break;
125 
126  case 3:
127  {
128  uint8_t *in = inrow;
129  uint8_t *out = outrow;
130  for (j = 0; j < (inlink->w >> hsub); j++, out += 3, in -= 3) {
131  int32_t v = AV_RB24(in);
132  AV_WB24(out, v);
133  }
134  }
135  break;
136 
137  case 4:
138  {
139  uint32_t *outrow32 = (uint32_t *)outrow;
140  uint32_t * inrow32 = (uint32_t *) inrow;
141  for (j = 0; j < (inlink->w >> hsub); j++)
142  outrow32[j] = inrow32[-j];
143  }
144  break;
145 
146  default:
147  for (j = 0; j < (inlink->w >> hsub); j++)
148  memcpy(outrow + j*step, inrow - j*step, step);
149  }
150 
151  inrow += in ->linesize[plane];
152  outrow += out->linesize[plane];
153  }
154  }
155 
157  return ff_filter_frame(outlink, out);
158 }
159 
161  {
162  .name = "default",
163  .type = AVMEDIA_TYPE_VIDEO,
164  .filter_frame = filter_frame,
165  .config_props = config_props,
166  .min_perms = AV_PERM_READ,
167  },
168  { NULL }
169 };
170 
172  {
173  .name = "default",
174  .type = AVMEDIA_TYPE_VIDEO,
175  },
176  { NULL }
177 };
178 
180  .name = "hflip",
181  .description = NULL_IF_CONFIG_SMALL("Horizontally flip the input video."),
182  .priv_size = sizeof(FlipContext),
184 
185  .inputs = avfilter_vf_hflip_inputs,
186  .outputs = avfilter_vf_hflip_outputs,
187 };
static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *in)
Definition: vf_hflip.c:87
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1435
int max_step[4]
max pixel step for each plane, expressed as a number of bytes
Definition: vf_hflip.c:39
AVFilterBufferRefVideoProps * video
video buffer specific properties
Definition: avfilter.h:159
int linesize[8]
number of bytes per line
Definition: avfilter.h:157
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:70
misc image utilities
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:122
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:67
int ff_filter_frame(AVFilterLink *link, AVFilterBufferRef *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:459
packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), little-endian, most significant bit to 0 ...
Definition: pixfmt.h:114
#define AV_RB24
Definition: intreadwrite.h:64
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), little-endian
Definition: pixfmt.h:117
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:125
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:66
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:165
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
Definition: pixfmt.h:112
packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
Definition: pixfmt.h:86
void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], const AVPixFmtDescriptor *pixdesc)
Compute the max pixel step for each plane of an image with a format described by pixdesc.
Definition: imgutils.c:30
#define AV_PERM_READ
can read from the buffer
Definition: avfilter.h:97
const char * name
Pad name.
Definition: internal.h:39
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:102
uint8_t
8 bit with PIX_FMT_RGB32 palette
Definition: pixfmt.h:76
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:109
static const AVFilterPad avfilter_vf_hflip_outputs[]
Definition: vf_hflip.c:171
void avfilter_unref_bufferp(AVFilterBufferRef **ref)
Remove a reference to a buffer and set the pointer to NULL.
Definition: buffer.c:88
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
Definition: pixfmt.h:111
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:95
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of PIX_FMT_YUV440P and setting color_range ...
Definition: pixfmt.h:101
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
Definition: pixfmt.h:78
static int config_props(AVFilterLink *inlink)
Definition: vf_hflip.c:75
void ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:375
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
static int query_formats(AVFilterContext *ctx)
Definition: vf_hflip.c:43
int h
image height
Definition: avfilter.h:123
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:75
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:130
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:88
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:96
void * priv
private data for use by the filter
Definition: avfilter.h:439
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:128
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:93
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:140
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:94
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:69
common internal API header
static const AVFilterPad avfilter_vf_hflip_inputs[]
Definition: vf_hflip.c:160
packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
Definition: pixfmt.h:89
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
Definition: pixfmt.h:77
int32_t
#define AV_WB24(p, d)
Definition: intreadwrite.h:412
AVFilter avfilter_vf_hflip
Definition: vf_hflip.c:179
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:68
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:139
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), big-endian
Definition: pixfmt.h:116
A reference to an AVFilterBuffer.
Definition: avfilter.h:139
NULL
Definition: eval.c:52
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:84
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:126
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:55
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:71
Filter definition.
Definition: avfilter.h:371
Y , 16bpp, big-endian.
Definition: pixfmt.h:98
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:110
int hsub
Definition: vf_hflip.c:40
const char * name
filter name
Definition: avfilter.h:372
static int step
Definition: avplay.c:252
packed BGR 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), little-endian, most significant bit to 1 ...
Definition: pixfmt.h:119
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:433
packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), big-endian, most significant bit to 0 ...
Definition: pixfmt.h:113
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:129
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:65
Y , 8bpp.
Definition: pixfmt.h:73
void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src)
Copy properties of src to dst, without copying the actual data.
Definition: buffer.c:164
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:108
static void flip(AVCodecContext *avctx, AVPicture *picture)
Definition: rawdec.c:110
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:127
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
Definition: pixfmt.h:79
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: pixfmt.h:87
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:72
#define AV_PERM_WRITE
can write to the buffer
Definition: avfilter.h:98
Y , 16bpp, little-endian.
Definition: pixfmt.h:99
uint8_t * data[8]
picture/audio data for each plane
Definition: avfilter.h:141
An instance of a filter.
Definition: avfilter.h:418
packed BGR 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), big-endian, most significant bit to 1 ...
Definition: pixfmt.h:118
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:100
int vsub
chroma subsampling
Definition: vf_hflip.c:40
internal API functions
AVPixelFormat
Pixel format.
Definition: pixfmt.h:63