FFmpeg
Loading...
Searching...
No Matches
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 "filters.h"
31#include "video.h"
32
37
39{
40 PixdescTestContext *priv = ctx->priv;
41 av_freep(&priv->line);
42}
43
44static int config_props(AVFilterLink *inlink)
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(inlink->w, sizeof(*priv->line))))
52 return AVERROR(ENOMEM);
53
54 return 0;
55}
56
57static int filter_frame(AVFilterLink *inlink, AVFrame *in)
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 */
85 memcpy(out->data[1], in->data[1], AVPALETTE_SIZE);
86
87 for (c = 0; c < FF_ARRAY_ELEMS(priv->pix_desc->comp); 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 .p.name = "pixdesctest",
121 .p.description = NULL_IF_CONFIG_SMALL("Test pixel format definitions."),
122 .priv_size = sizeof(PixdescTestContext),
123 .uninit = uninit,
126};
const FFFilter ff_vf_pixdesctest
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
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
Definition common.h:60
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition common.h:74
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
#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
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define av_cold
Definition attributes.h:117
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
uint8_t w
Definition llvidencdsp.c:39
Memory handling functions.
const char data[16]
Definition mxf.c:149
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:117
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
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
#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
#define FF_ARRAY_ELEMS(a)
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
AVFilterLink ** outputs
array of pointers to output links
Definition avfilter.h:285
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
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition pixdesc.h:105
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
const AVPixFmtDescriptor * pix_desc
#define av_malloc_array(a, b)
#define av_freep(p)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static const AVFilterPad avfilter_vf_pixdesctest_inputs[]
static int config_props(AVFilterLink *inlink)
static av_cold void uninit(AVFilterContext *ctx)
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
static double c[64]