2 * Copyright (c) 2009 Stefano Sabatini
4 * This file is part of FFmpeg.
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.
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.
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
26 #include "libavutil/pixdesc.h"
32 const AVPixFmtDescriptor *pix_desc;
36 static av_cold void uninit(AVFilterContext *ctx)
38 PixdescTestContext *priv = ctx->priv;
39 av_freep(&priv->line);
42 static int config_props(AVFilterLink *inlink)
44 PixdescTestContext *priv = inlink->dst->priv;
46 priv->pix_desc = &av_pix_fmt_descriptors[inlink->format];
48 if (!(priv->line = av_malloc(sizeof(*priv->line) * inlink->w)))
49 return AVERROR(ENOMEM);
54 static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
56 PixdescTestContext *priv = inlink->dst->priv;
57 AVFilterLink *outlink = inlink->dst->outputs[0];
58 AVFilterBufferRef *outpicref;
61 outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE,
62 outlink->w, outlink->h);
63 outpicref = outlink->out_buf;
64 avfilter_copy_buffer_ref_props(outpicref, picref);
66 for (i = 0; i < 4; i++) {
68 h = i == 1 || i == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
69 if (outpicref->data[i]) {
70 uint8_t *data = outpicref->data[i] +
71 (outpicref->linesize[i] > 0 ? 0 : outpicref->linesize[i] * (h-1));
72 memset(data, 0, FFABS(outpicref->linesize[i]) * h);
77 if (priv->pix_desc->flags & PIX_FMT_PAL ||
78 priv->pix_desc->flags & PIX_FMT_PSEUDOPAL)
79 memcpy(outpicref->data[1], picref->data[1], AVPALETTE_SIZE);
81 ff_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
84 static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
86 PixdescTestContext *priv = inlink->dst->priv;
87 AVFilterBufferRef *inpic = inlink->cur_buf;
88 AVFilterBufferRef *outpic = inlink->dst->outputs[0]->out_buf;
89 int i, c, w = inlink->w;
91 for (c = 0; c < priv->pix_desc->nb_components; c++) {
92 int w1 = c == 1 || c == 2 ? w>>priv->pix_desc->log2_chroma_w : w;
93 int h1 = c == 1 || c == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
94 int y1 = c == 1 || c == 2 ? y>>priv->pix_desc->log2_chroma_h : y;
96 for (i = y1; i < y1 + h1; i++) {
97 av_read_image_line(priv->line,
103 av_write_image_line(priv->line,
111 ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
114 AVFilter avfilter_vf_pixdesctest = {
115 .name = "pixdesctest",
116 .description = NULL_IF_CONFIG_SMALL("Test pixel format definitions."),
118 .priv_size = sizeof(PixdescTestContext),
121 .inputs = (const AVFilterPad[]) {{ .name = "default",
122 .type = AVMEDIA_TYPE_VIDEO,
123 .start_frame = start_frame,
124 .draw_slice = draw_slice,
125 .config_props = config_props,
126 .min_perms = AV_PERM_READ, },
129 .outputs = (const AVFilterPad[]) {{ .name = "default",
130 .type = AVMEDIA_TYPE_VIDEO, },