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/mem.h"
28 #include "libavutil/pixdesc.h"
29 #include "avfilter.h"
30 #include "internal.h"
31 #include "video.h"
32 
33 typedef struct PixdescTestContext {
35  uint32_t *line;
37 
39 {
40  PixdescTestContext *priv = ctx->priv;
41  av_freep(&priv->line);
42 }
43 
45 {
46  PixdescTestContext *priv = inlink->dst->priv;
47 
48  priv->pix_desc = av_pix_fmt_desc_get(inlink->format);
49 
50  av_freep(&priv->line);
51  if (!(priv->line = av_malloc_array(sizeof(*priv->line), inlink->w)))
52  return AVERROR(ENOMEM);
53 
54  return 0;
55 }
56 
58 {
59  PixdescTestContext *priv = inlink->dst->priv;
60  AVFilterLink *outlink = inlink->dst->outputs[0];
61  AVFrame *out;
62  int i, c, w = inlink->w, h = inlink->h;
63  const int cw = AV_CEIL_RSHIFT(w, priv->pix_desc->log2_chroma_w);
64  const int ch = AV_CEIL_RSHIFT(h, priv->pix_desc->log2_chroma_h);
65 
66  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
67  if (!out) {
68  av_frame_free(&in);
69  return AVERROR(ENOMEM);
70  }
71 
73 
74  for (i = 0; i < 4; i++) {
75  const int h1 = i == 1 || i == 2 ? ch : h;
76  if (out->data[i]) {
77  uint8_t *data = out->data[i] +
78  (out->linesize[i] > 0 ? 0 : out->linesize[i] * (h1-1));
79  memset(data, 0, FFABS(out->linesize[i]) * h1);
80  }
81  }
82 
83  /* copy palette */
84  if (priv->pix_desc->flags & AV_PIX_FMT_FLAG_PAL)
85  memcpy(out->data[1], in->data[1], AVPALETTE_SIZE);
86 
87  for (c = 0; c < priv->pix_desc->nb_components; c++) {
88  const int w1 = c == 1 || c == 2 ? cw : w;
89  const int h1 = c == 1 || c == 2 ? ch : h;
90 
91  for (i = 0; i < h1; i++) {
93  (void*)in->data,
94  in->linesize,
95  priv->pix_desc,
96  0, i, c, w1, 0, 4);
97 
99  out->data,
100  out->linesize,
101  priv->pix_desc,
102  0, i, c, w1, 4);
103  }
104  }
105 
106  av_frame_free(&in);
107  return ff_filter_frame(outlink, out);
108 }
109 
111  {
112  .name = "default",
113  .type = AVMEDIA_TYPE_VIDEO,
114  .filter_frame = filter_frame,
115  .config_props = config_props,
116  },
117 };
118 
120  .name = "pixdesctest",
121  .description = NULL_IF_CONFIG_SMALL("Test pixel format definitions."),
122  .priv_size = sizeof(PixdescTestContext),
123  .uninit = uninit,
126 };
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:55
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1015
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2965
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:160
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
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:395
PixdescTestContext::line
uint32_t * line
Definition: vf_pixdesctest.c:35
PixdescTestContext
Definition: vf_pixdesctest.c:33
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_pixdesctest.c:57
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:59
ctx
AVFormatContext * ctx
Definition: movenc.c:49
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:119
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:73
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:709
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:34
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:94
config_props
static int config_props(AVFilterLink *inlink)
Definition: vf_pixdesctest.c:44
internal.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
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:110
AVFilter
Filter definition.
Definition: avfilter.h:166
avfilter.h
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_pixdesctest.c:38
AVFilterContext
An instance of a filter.
Definition: avfilter.h:407
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
mem.h
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:419
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