FFmpeg
Loading...
Searching...
No Matches
vf_swapuv.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg 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 * FFmpeg 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 FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
22 * @file
23 * swap UV filter
24 */
25
26#include "libavutil/pixdesc.h"
27#include "avfilter.h"
28#include "filters.h"
29#include "formats.h"
30#include "video.h"
31
32static void do_swap(AVFrame *frame)
33{
34 FFSWAP(uint8_t*, frame->data[1], frame->data[2]);
35 FFSWAP(int, frame->linesize[1], frame->linesize[2]);
36 FFSWAP(AVBufferRef*, frame->buf[1], frame->buf[2]);
37}
38
39static AVFrame *get_video_buffer(AVFilterLink *link, int w, int h)
40{
41 AVFrame *picref = ff_default_get_video_buffer(link, w, h);
42 do_swap(picref);
43 return picref;
44}
45
46static int filter_frame(AVFilterLink *link, AVFrame *inpicref)
47{
48 do_swap(inpicref);
49 return ff_filter_frame(link->dst->outputs[0], inpicref);
50}
51
53{
54 int i;
55
57 desc->nb_components < 3 ||
58 (desc->comp[1].depth != desc->comp[2].depth))
59 return 0;
60 for (i = 0; i < desc->nb_components; i++) {
61 if (desc->comp[i].offset != 0 ||
62 desc->comp[i].shift != 0 ||
63 desc->comp[i].plane != i)
64 return 0;
65 }
66
67 return 1;
68}
69
71 AVFilterFormatsConfig **cfg_in,
72 AVFilterFormatsConfig **cfg_out)
73{
75 int fmt, ret;
76
77 for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
79 if (is_planar_yuv(desc) && (ret = ff_add_format(&formats, fmt)) < 0)
80 return ret;
81 }
82
83 return ff_set_common_formats2(ctx, cfg_in, cfg_out, formats);
84}
85
86static const AVFilterPad swapuv_inputs[] = {
87 {
88 .name = "default",
89 .type = AVMEDIA_TYPE_VIDEO,
90 .get_buffer.video = get_video_buffer,
91 .filter_frame = filter_frame,
92 },
93};
94
96 .p.name = "swapuv",
97 .p.description = NULL_IF_CONFIG_SMALL("Swap U and V components."),
102};
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition aeval.c:246
const FFFilter ff_vf_swapuv
Definition vf_swapuv.c:95
static AVFrame * get_video_buffer(AVFilterLink *inlink, int w, int h)
Definition avf_concat.c:205
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1068
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define NULL
Definition coverity.c:32
static AVFrame * frame
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
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#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
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
const char * desc
Definition libsvtav1.c:83
uint8_t w
Definition llvidencdsp.c:39
#define FFSWAP(type, a, b)
Definition macros.h:52
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition pixdesc.h:147
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition pixdesc.h:132
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
Definition pixdesc.h:116
formats
Definition signature.h:47
A reference to a data buffer.
Definition buffer.h:82
An instance of a filter.
Definition avfilter.h:273
AVFilterLink ** outputs
array of pointers to output links
Definition avfilter.h:285
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
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
static AVFormatContext * ctx
Definition movenc.c:49
static AVFrame * get_video_buffer(AVFilterLink *link, int w, int h)
Definition vf_swapuv.c:39
static void do_swap(AVFrame *frame)
Definition vf_swapuv.c:32
static const AVFilterPad swapuv_inputs[]
Definition vf_swapuv.c:86
static int filter_frame(AVFilterLink *link, AVFrame *inpicref)
Definition vf_swapuv.c:46
static int is_planar_yuv(const AVPixFmtDescriptor *desc)
Definition vf_swapuv.c:52
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition vf_swapuv.c:70
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_default_get_video_buffer(AVFilterLink *link, int w, int h)
Definition video.c:84