FFmpeg
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 FFmpeg.
6  *
7  * FFmpeg 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  * FFmpeg 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 FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * horizontal flip filter
25  */
26 
27 #include <string.h>
28 
29 #include "libavutil/opt.h"
30 #include "avfilter.h"
31 #include "formats.h"
32 #include "hflip.h"
33 #include "internal.h"
34 #include "vf_hflip_init.h"
35 #include "video.h"
36 #include "libavutil/pixdesc.h"
37 #include "libavutil/internal.h"
38 #include "libavutil/intreadwrite.h"
39 #include "libavutil/imgutils.h"
40 
41 static const AVOption hflip_options[] = {
42  { NULL }
43 };
44 
46 
48 {
50  const AVPixFmtDescriptor *desc;
51  int fmt, ret;
52 
53  for (fmt = 0; desc = av_pix_fmt_desc_get(fmt); fmt++) {
54  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL ||
56  (desc->log2_chroma_w != desc->log2_chroma_h &&
57  desc->comp[0].plane == desc->comp[1].plane)) &&
58  (ret = ff_add_format(&pix_fmts, fmt)) < 0)
59  return ret;
60  }
61 
63 }
64 
66 {
67  FlipContext *s = inlink->dst->priv;
68  const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
69  const int hsub = pix_desc->log2_chroma_w;
70  const int vsub = pix_desc->log2_chroma_h;
71  int nb_planes;
72 
73  av_image_fill_max_pixsteps(s->max_step, NULL, pix_desc);
74  s->planewidth[0] = s->planewidth[3] = inlink->w;
75  s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, hsub);
76  s->planeheight[0] = s->planeheight[3] = inlink->h;
77  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, vsub);
78  s->bayer_plus1 = !!(pix_desc->flags & AV_PIX_FMT_FLAG_BAYER) + 1;
79 
80  nb_planes = av_pix_fmt_count_planes(inlink->format);
81 
82  return ff_hflip_init(s, s->max_step, nb_planes);
83 }
84 
85 typedef struct ThreadData {
86  AVFrame *in, *out;
87 } ThreadData;
88 
89 static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
90 {
91  FlipContext *s = ctx->priv;
92  ThreadData *td = arg;
93  AVFrame *in = td->in;
94  AVFrame *out = td->out;
95  uint8_t *inrow, *outrow;
96  int i, plane, step;
97 
98  for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; plane++) {
99  const int width = s->planewidth[plane] / s->bayer_plus1;
100  const int height = s->planeheight[plane];
101  const int start = (height * job ) / nb_jobs;
102  const int end = (height * (job+1)) / nb_jobs;
103 
104  step = s->max_step[plane];
105 
106  outrow = out->data[plane] + start * out->linesize[plane];
107  inrow = in ->data[plane] + start * in->linesize[plane] + (width - 1) * step;
108  for (i = start; i < end; i++) {
109  s->flip_line[plane](inrow, outrow, width);
110 
111  inrow += in ->linesize[plane];
112  outrow += out->linesize[plane];
113  }
114  }
115 
116  return 0;
117 }
118 
120 {
121  AVFilterContext *ctx = inlink->dst;
122  AVFilterLink *outlink = ctx->outputs[0];
123  ThreadData td;
124  AVFrame *out;
125 
126  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
127  if (!out) {
128  av_frame_free(&in);
129  return AVERROR(ENOMEM);
130  }
132 
133  /* copy palette if required */
135  memcpy(out->data[1], in->data[1], AVPALETTE_SIZE);
136 
137  td.in = in, td.out = out;
139  FFMIN(outlink->h, ff_filter_get_nb_threads(ctx)));
140 
141  av_frame_free(&in);
142  return ff_filter_frame(outlink, out);
143 }
144 
146  {
147  .name = "default",
148  .type = AVMEDIA_TYPE_VIDEO,
149  .filter_frame = filter_frame,
150  .config_props = config_props,
151  },
152 };
153 
155  {
156  .name = "default",
157  .type = AVMEDIA_TYPE_VIDEO,
158  },
159 };
160 
162  .name = "hflip",
163  .description = NULL_IF_CONFIG_SMALL("Horizontally flip the input video."),
164  .priv_size = sizeof(FlipContext),
165  .priv_class = &hflip_class,
170 };
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:101
td
#define td
Definition: regdef.h:70
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
out
FILE * out
Definition: movenc.c:54
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:999
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2675
hflip_options
static const AVOption hflip_options[]
Definition: vf_hflip.c:41
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:116
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
pixdesc.h
step
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
Definition: rate_distortion.txt:58
AVOption
AVOption.
Definition: opt.h:251
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:167
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:175
ThreadData::out
AVFrame * out
Definition: af_adeclick.c:473
video.h
ThreadData::in
AVFrame * in
Definition: af_adecorrelate.c:154
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:346
hsub
static void hsub(htype *dst, const htype *src, int bins)
Definition: vf_median.c:74
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2715
AV_PIX_FMT_FLAG_HWACCEL
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:128
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:49
ff_set_common_formats
int 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:749
width
#define width
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:256
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:50
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_hflip.c:119
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:296
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AVPixFmtDescriptor::log2_chroma_w
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
vf_hflip_init.h
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:190
arg
const char * arg
Definition: jacosubdec.c:67
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:603
AVPALETTE_SIZE
#define AVPALETTE_SIZE
Definition: pixfmt.h:32
ff_add_format
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:449
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(hflip)
AVPixFmtDescriptor::flags
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:94
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
AV_PIX_FMT_FLAG_BITSTREAM
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
Definition: pixdesc.h:124
hflip.h
height
#define height
AV_PIX_FMT_FLAG_BAYER
#define AV_PIX_FMT_FLAG_BAYER
The pixel format is following a Bayer pattern.
Definition: pixdesc.h:152
internal.h
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:152
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
internal.h
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:783
ThreadData
Used for passing data between threads.
Definition: dsddec.c:68
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:55
avfilter_vf_hflip_inputs
static const AVFilterPad avfilter_vf_hflip_inputs[]
Definition: vf_hflip.c:145
AVFilter
Filter definition.
Definition: avfilter.h:171
config_props
static int config_props(AVFilterLink *inlink)
Definition: vf_hflip.c:65
ret
ret
Definition: filter_design.txt:187
FlipContext
Definition: hflip.h:27
avfilter.h
av_image_fill_max_pixsteps
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:35
AVFilterContext
An instance of a filter.
Definition: avfilter.h:408
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:127
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:191
avfilter_vf_hflip_outputs
static const AVFilterPad avfilter_vf_hflip_outputs[]
Definition: vf_hflip.c:154
filter_slice
static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
Definition: vf_hflip.c:89
imgutils.h
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:370
ff_filter_execute
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: internal.h:142
AV_PIX_FMT_FLAG_PAL
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition: pixdesc.h:120
AVPixFmtDescriptor::log2_chroma_h
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_hflip.c:47
ff_vf_hflip
const AVFilter ff_vf_hflip
Definition: vf_hflip.c:161
ff_hflip_init
static av_unused int ff_hflip_init(FlipContext *s, int step[4], int nb_planes)
Definition: vf_hflip_init.h:89