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 "avfilter.h"
28 #include "libavutil/pixdesc.h"
29 #include "libavutil/intreadwrite.h"
30 #include "libavutil/imgutils.h"
31 
32 typedef struct {
33  int max_step[4];
34  int hsub, vsub;
35 } FlipContext;
36 
38 {
39  static const enum PixelFormat pix_fmts[] = {
63  };
64 
66  return 0;
67 }
68 
69 static int config_props(AVFilterLink *inlink)
70 {
71  FlipContext *flip = inlink->dst->priv;
72  const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[inlink->format];
73 
74  av_image_fill_max_pixsteps(flip->max_step, NULL, pix_desc);
77 
78  return 0;
79 }
80 
81 static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
82 {
83  FlipContext *flip = inlink->dst->priv;
84  AVFilterBufferRef *inpic = inlink->cur_buf;
85  AVFilterBufferRef *outpic = inlink->dst->outputs[0]->out_buf;
86  uint8_t *inrow, *outrow;
87  int i, j, plane, step, hsub, vsub;
88 
89  for (plane = 0; plane < 4 && inpic->data[plane]; plane++) {
90  step = flip->max_step[plane];
91  hsub = (plane == 1 || plane == 2) ? flip->hsub : 0;
92  vsub = (plane == 1 || plane == 2) ? flip->vsub : 0;
93 
94  outrow = outpic->data[plane] + (y>>vsub) * outpic->linesize[plane];
95  inrow = inpic ->data[plane] + (y>>vsub) * inpic ->linesize[plane] + ((inlink->w >> hsub) - 1) * step;
96  for (i = 0; i < h>>vsub; i++) {
97  switch (step) {
98  case 1:
99  {
100  for (j = 0; j < (inlink->w >> hsub); j++)
101  outrow[j] = inrow[-j];
102  }
103  break;
104 
105  case 2:
106  {
107  uint16_t *outrow16 = (uint16_t *)outrow;
108  uint16_t * inrow16 = (uint16_t *) inrow;
109  for (j = 0; j < (inlink->w >> hsub); j++)
110  outrow16[j] = inrow16[-j];
111  }
112  break;
113 
114  case 3:
115  {
116  uint8_t *in = inrow;
117  uint8_t *out = outrow;
118  for (j = 0; j < (inlink->w >> hsub); j++, out += 3, in -= 3) {
119  int32_t v = AV_RB24(in);
120  AV_WB24(out, v);
121  }
122  }
123  break;
124 
125  case 4:
126  {
127  uint32_t *outrow32 = (uint32_t *)outrow;
128  uint32_t * inrow32 = (uint32_t *) inrow;
129  for (j = 0; j < (inlink->w >> hsub); j++)
130  outrow32[j] = inrow32[-j];
131  }
132  break;
133 
134  default:
135  for (j = 0; j < (inlink->w >> hsub); j++)
136  memcpy(outrow + j*step, inrow - j*step, step);
137  }
138 
139  inrow += inpic ->linesize[plane];
140  outrow += outpic->linesize[plane];
141  }
142  }
143 
144  avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
145 }
146 
148  .name = "hflip",
149  .description = NULL_IF_CONFIG_SMALL("Horizontally flip the input video."),
150  .priv_size = sizeof(FlipContext),
152 
153  .inputs = (AVFilterPad[]) {{ .name = "default",
154  .type = AVMEDIA_TYPE_VIDEO,
155  .draw_slice = draw_slice,
156  .config_props = config_props,
157  .min_perms = AV_PERM_READ, },
158  { .name = NULL}},
159  .outputs = (AVFilterPad[]) {{ .name = "default",
160  .type = AVMEDIA_TYPE_VIDEO, },
161  { .name = NULL}},
162 };
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:68
int max_step[4]
max pixel step for each plane, expressed as a number of bytes
Definition: vf_hflip.c:33
int linesize[8]
number of bytes per line
Definition: avfilter.h:127
misc image utilities
Y , 16bpp, big-endian.
Definition: pixfmt.h:97
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV422P and setting color_...
Definition: pixfmt.h:77
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian
Definition: pixfmt.h:125
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:71
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:66
#define v(n)
Definition: regs.h:34
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:29
#define AV_PERM_READ
can read from the buffer
Definition: avfilter.h:81
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), big-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:78
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
Definition: pixfmt.h:124
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: pixfmt.h:86
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:64
packed BGR 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), little-endian, most significant bit to 1 ...
Definition: pixfmt.h:118
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:70
static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
Definition: vf_hflip.c:81
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:95
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV420P and setting color_...
Definition: pixfmt.h:76
static int config_props(AVFilterLink *inlink)
Definition: vf_hflip.c:69
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:108
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
Definition: pixfmt.h:110
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), little-endian
Definition: pixfmt.h:116
A filter pad used for either input or output.
Definition: avfilter.h:312
Y , 16bpp, little-endian.
Definition: pixfmt.h:98
static int query_formats(AVFilterContext *ctx)
Definition: vf_hflip.c:37
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
Definition: pixfmt.h:111
void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: defaults.c:234
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
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:107
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), big-endian
Definition: pixfmt.h:115
AVFilterFormats * avfilter_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:90
const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB]
The array of all the pixel format descriptors.
Definition: pixdesc.c:119
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:69
packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
Definition: pixfmt.h:85
packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
Definition: pixfmt.h:88
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:138
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:126
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of PIX_FMT_YUV440P and setting color_range ...
Definition: pixfmt.h:100
#define AV_WB24(p, d)
Definition: intreadwrite.h:412
AVFilter avfilter_vf_hflip
Definition: vf_hflip.c:147
void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
Send a slice to the next filter.
Definition: avfilter.c:447
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:128
A reference to an AVFilterBuffer.
Definition: avfilter.h:124
NULL
Definition: eval.c:50
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:55
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:92
packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), big-endian, most significant bit to 0 ...
Definition: pixfmt.h:112
Filter definition.
Definition: avfilter.h:497
packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), little-endian, most significant bit to 0 ...
Definition: pixfmt.h:113
packed BGR 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), big-endian, most significant bit to 1 ...
Definition: pixfmt.h:117
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:83
int hsub
Definition: vf_hflip.c:34
const char * name
filter name
Definition: avfilter.h:498
static int step
Definition: avplay.c:244
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:67
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:551
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:139
AV_WL32 AV_WL24 AV_WL16 AV_WB32 AV_RB24
Definition: bytestream.h:89
PixelFormat
Pixel format.
Definition: pixfmt.h:62
static void flip(AVCodecContext *avctx, AVPicture *picture)
Definition: rawdec.c:110
8 bit with PIX_FMT_RGB32 palette
Definition: pixfmt.h:75
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:66
uint8_t * data[8]
picture/audio data for each plane
Definition: avfilter.h:126
An instance of a filter.
Definition: avfilter.h:538
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:94
Y , 8bpp.
Definition: pixfmt.h:72
int vsub
chroma subsampling
Definition: vf_hflip.c:34
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:129
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101