FFmpeg
Loading...
Searching...
No Matches
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 "avfilter.h"
30#include "filters.h"
31#include "formats.h"
32#include "hflip.h"
33#include "vf_hflip_init.h"
34#include "video.h"
35#include "libavutil/pixdesc.h"
36#include "libavutil/internal.h"
38#include "libavutil/imgutils.h"
39
41 AVFilterFormatsConfig **cfg_in,
42 AVFilterFormatsConfig **cfg_out)
43{
46 int fmt, ret;
47
48 for (fmt = 0; desc = av_pix_fmt_desc_get(fmt); fmt++) {
49 if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL ||
51 (desc->log2_chroma_w != desc->log2_chroma_h &&
52 desc->comp[0].plane == desc->comp[1].plane)) &&
53 (ret = ff_add_format(&pix_fmts, fmt)) < 0)
54 return ret;
55 }
56
57 return ff_set_common_formats2(ctx, cfg_in, cfg_out, pix_fmts);
58}
59
60static int config_props(AVFilterLink *inlink)
61{
62 FlipContext *s = inlink->dst->priv;
63 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
64 const int hsub = pix_desc->log2_chroma_w;
65 const int vsub = pix_desc->log2_chroma_h;
66 int nb_planes;
67
68 av_image_fill_max_pixsteps(s->max_step, NULL, pix_desc);
69 s->planewidth[0] = s->planewidth[3] = inlink->w;
70 s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, hsub);
71 s->planeheight[0] = s->planeheight[3] = inlink->h;
72 s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, vsub);
73 s->bayer_plus1 = !!(pix_desc->flags & AV_PIX_FMT_FLAG_BAYER) + 1;
74
75 nb_planes = av_pix_fmt_count_planes(inlink->format);
76
77 return ff_hflip_init(s, s->max_step, nb_planes);
78}
79
80typedef struct ThreadData {
81 AVFrame *in, *out;
83
84static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
85{
86 FlipContext *s = ctx->priv;
87 ThreadData *td = arg;
88 AVFrame *in = td->in;
89 AVFrame *out = td->out;
90 uint8_t *inrow, *outrow;
91 int i, plane, step;
92
93 for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; plane++) {
94 const int width = s->planewidth[plane] / s->bayer_plus1;
95 const int height = s->planeheight[plane];
96 const int start = (height * job ) / nb_jobs;
97 const int end = (height * (job+1)) / nb_jobs;
98
99 step = s->max_step[plane];
100
101 outrow = out->data[plane] + start * out->linesize[plane];
102 inrow = in ->data[plane] + start * in->linesize[plane] + (width - 1) * step;
103 for (i = start; i < end; i++) {
104 s->flip_line[plane](inrow, outrow, width);
105
106 inrow += in ->linesize[plane];
107 outrow += out->linesize[plane];
108 }
109 }
110
111 return 0;
112}
113
114static int filter_frame(AVFilterLink *inlink, AVFrame *in)
115{
116 AVFilterContext *ctx = inlink->dst;
117 AVFilterLink *outlink = ctx->outputs[0];
118 ThreadData td;
119 AVFrame *out;
120
121 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
122 if (!out) {
123 av_frame_free(&in);
124 return AVERROR(ENOMEM);
125 }
127
128 /* copy palette if required */
130 memcpy(out->data[1], in->data[1], AVPALETTE_SIZE);
131
132 td.in = in, td.out = out;
134 FFMIN(outlink->h, ff_filter_get_nb_threads(ctx)));
135
136 av_frame_free(&in);
137 return ff_filter_frame(outlink, out);
138}
139
141 {
142 .name = "default",
143 .type = AVMEDIA_TYPE_VIDEO,
144 .filter_frame = filter_frame,
145 .config_props = config_props,
146 },
147};
148
150 .p.name = "hflip",
151 .p.description = NULL_IF_CONFIG_SMALL("Horizontally flip the input video."),
153 .priv_size = sizeof(FlipContext),
157};
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition aeval.c:246
const FFFilter ff_vf_hflip
Definition vf_hflip.c:149
static FILE * out
static AVFormatContext * ctx
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1068
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition avfilter.c:1696
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition avfilter.c:846
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define AV_CEIL_RSHIFT(a, b)
Definition common.h:60
#define NULL
Definition coverity.c:32
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
int ff_set_common_formats2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *formats)
Definition formats.c:1137
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition formats.c:571
#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:196
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition avfilter.h:166
#define AVERROR(e)
Definition error.h:45
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition frame.c:599
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
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
misc image utilities
const char * arg
Definition jacosubdec.c:65
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define FILTER_QUERY_FUNC2(func)
Definition filters.h:241
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition vf_hflip.c:114
static const AVFilterPad avfilter_vf_hflip_inputs[]
Definition vf_hflip.c:140
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition vf_hflip.c:40
static int config_props(AVFilterLink *inlink)
Definition vf_hflip.c:60
static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
Definition vf_hflip.c:84
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
static enum AVPixelFormat pix_fmts[]
Definition libkvazaar.c:296
const char * desc
Definition libsvtav1.c:83
#define FFMIN(a, b)
Definition macros.h:49
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3500
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
Definition pixdesc.h:124
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition pixdesc.h:128
#define AV_PIX_FMT_FLAG_BAYER
The pixel format is following a Bayer pattern.
Definition pixdesc.h:152
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition pixdesc.h:120
#define AVPALETTE_SIZE
Definition pixfmt.h:32
static int config_props(AVBitStreamFilterLink *link)
Definition source.c:181
An instance of a filter.
Definition avfilter.h:273
void * priv
private data for use by the filter
Definition avfilter.h:288
Lists of formats / etc.
Definition avfilter.h:120
A list of supported formats for one end of a filter link.
Definition formats.h:64
A filter pad used for either input or output.
Definition filters.h:40
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:493
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:517
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition pixdesc.h:80
uint64_t flags
Combination of AV_PIX_FMT_FLAG_... flags.
Definition pixdesc.h:94
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition pixdesc.h:89
Used for passing data between threads.
Definition dsddec.c:71
AVFrame * out
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static av_unused int ff_hflip_init(FlipContext *s, int step[4], int nb_planes)
static void hsub(htype *dst, const htype *src, int bins)
Definition vf_median.c:74
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition video.c:37
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition video.c:89