FFmpeg
vf_pixdesctest.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 Stefano Sabatini
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  * pixdesc test filter
24  */
25 
26 #include "libavutil/common.h"
27 #include "libavutil/pixdesc.h"
28 #include "avfilter.h"
29 #include "internal.h"
30 #include "video.h"
31 
32 typedef struct PixdescTestContext {
34  uint32_t *line;
36 
38 {
39  PixdescTestContext *priv = ctx->priv;
40  av_freep(&priv->line);
41 }
42 
44 {
45  PixdescTestContext *priv = inlink->dst->priv;
46 
47  priv->pix_desc = av_pix_fmt_desc_get(inlink->format);
48 
49  av_freep(&priv->line);
50  if (!(priv->line = av_malloc_array(sizeof(*priv->line), inlink->w)))
51  return AVERROR(ENOMEM);
52 
53  return 0;
54 }
55 
57 {
58  PixdescTestContext *priv = inlink->dst->priv;
59  AVFilterLink *outlink = inlink->dst->outputs[0];
60  AVFrame *out;
61  int i, c, w = inlink->w, h = inlink->h;
62  const int cw = AV_CEIL_RSHIFT(w, priv->pix_desc->log2_chroma_w);
63  const int ch = AV_CEIL_RSHIFT(h, priv->pix_desc->log2_chroma_h);
64 
65  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
66  if (!out) {
67  av_frame_free(&in);
68  return AVERROR(ENOMEM);
69  }
70 
72 
73  for (i = 0; i < 4; i++) {
74  const int h1 = i == 1 || i == 2 ? ch : h;
75  if (out->data[i]) {
76  uint8_t *data = out->data[i] +
77  (out->linesize[i] > 0 ? 0 : out->linesize[i] * (h1-1));
78  memset(data, 0, FFABS(out->linesize[i]) * h1);
79  }
80  }
81 
82  /* copy palette */
83  if (priv->pix_desc->flags & AV_PIX_FMT_FLAG_PAL)
84  memcpy(out->data[1], in->data[1], AVPALETTE_SIZE);
85 
86  for (c = 0; c < priv->pix_desc->nb_components; c++) {
87  const int w1 = c == 1 || c == 2 ? cw : w;
88  const int h1 = c == 1 || c == 2 ? ch : h;
89 
90  for (i = 0; i < h1; i++) {
92  (void*)in->data,
93  in->linesize,
94  priv->pix_desc,
95  0, i, c, w1, 0, 4);
96 
98  out->data,
99  out->linesize,
100  priv->pix_desc,
101  0, i, c, w1, 4);
102  }
103  }
104 
105  av_frame_free(&in);
106  return ff_filter_frame(outlink, out);
107 }
108 
110  {
111  .name = "default",
112  .type = AVMEDIA_TYPE_VIDEO,
113  .filter_frame = filter_frame,
114  .config_props = config_props,
115  },
116 };
117 
119  .name = "pixdesctest",
120  .description = NULL_IF_CONFIG_SMALL("Test pixel format definitions."),
121  .priv_size = sizeof(PixdescTestContext),
122  .uninit = uninit,
125 };
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:112
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
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:1018
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2962
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:130
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
pixdesc.h
w
uint8_t w
Definition: llviddspenc.c:38
data
const char data[16]
Definition: mxf.c:148
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
video.h
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:365
PixdescTestContext::line
uint32_t * line
Definition: vf_pixdesctest.c:34
PixdescTestContext
Definition: vf_pixdesctest.c:32
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_pixdesctest.c:56
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:33
av_cold
#define av_cold
Definition: attributes.h:90
ff_video_default_filterpad
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
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
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
ff_vf_pixdesctest
const AVFilter ff_vf_pixdesctest
Definition: vf_pixdesctest.c:118
av_read_image_line2
void av_read_image_line2(void *dst, const uint8_t *data[4], const int linesize[4], const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int read_pal_component, int dst_element_size)
Read a line from an image, and write the values of the pixel format component c to dst.
Definition: pixdesc.c:31
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:182
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
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:679
AVPixFmtDescriptor::nb_components
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:71
AVPALETTE_SIZE
#define AVPALETTE_SIZE
Definition: pixfmt.h:32
PixdescTestContext::pix_desc
const AVPixFmtDescriptor * pix_desc
Definition: vf_pixdesctest.c:33
AVPixFmtDescriptor::flags
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:94
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
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:106
config_props
static int config_props(AVFilterLink *inlink)
Definition: vf_pixdesctest.c:43
internal.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
common.h
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:39
avfilter_vf_pixdesctest_inputs
static const AVFilterPad avfilter_vf_pixdesctest_inputs[]
Definition: vf_pixdesctest.c:109
AVFilter
Filter definition.
Definition: avfilter.h:166
avfilter.h
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_pixdesctest.c:37
AVFilterContext
An instance of a filter.
Definition: avfilter.h:407
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:183
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
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:389
h
h
Definition: vp9dsp_template.c:2038
av_write_image_line2
void av_write_image_line2(const void *src, uint8_t *data[4], const int linesize[4], const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int src_element_size)
Write the values from src to the pixel format component c of an image line.
Definition: pixdesc.c:114
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