2 * This file is part of FFmpeg.
3 * copyright (C) 2009 Stefano Sabatini
5 * FFmpeg is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * FFmpeg is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with FFmpeg; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "libavutil/pixdesc.h"
29 const AVPixFmtDescriptor *pix_desc;
33 static av_cold void uninit(AVFilterContext *ctx)
35 PixdescTestContext *priv = ctx->priv;
36 av_freep(&priv->line);
39 static int config_props(AVFilterLink *inlink)
41 PixdescTestContext *priv = inlink->dst->priv;
43 priv->pix_desc = &av_pix_fmt_descriptors[inlink->format];
45 if (!(priv->line = av_malloc(sizeof(*priv->line) * inlink->w)))
46 return AVERROR(ENOMEM);
51 static void start_frame(AVFilterLink *inlink, AVFilterPicRef *picref)
53 PixdescTestContext *priv = inlink->dst->priv;
54 AVFilterLink *outlink = inlink->dst->outputs[0];
55 AVFilterPicRef *outpicref;
58 outlink->outpic = avfilter_get_video_buffer(outlink, AV_PERM_WRITE,
59 outlink->w, outlink->h);
60 outpicref = outlink->outpic;
61 avfilter_copy_picref_props(outpicref, picref);
63 for (i = 0; i < 4; i++) {
65 h = i == 1 || i == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
66 if (outpicref->data[i]) {
67 uint8_t *data = outpicref->data[i] +
68 (outpicref->linesize[i] > 0 ? 0 : outpicref->linesize[i] * (h-1));
69 memset(data, 0, FFABS(outpicref->linesize[i]) * h);
74 if (priv->pix_desc->flags & PIX_FMT_PAL)
75 memcpy(outpicref->data[1], outpicref->data[1], 256*4);
77 avfilter_start_frame(outlink, avfilter_ref_pic(outpicref, ~0));
80 static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
82 PixdescTestContext *priv = inlink->dst->priv;
83 AVFilterPicRef *inpic = inlink->cur_pic;
84 AVFilterPicRef *outpic = inlink->dst->outputs[0]->outpic;
85 int i, c, w = inlink->w;
87 for (c = 0; c < priv->pix_desc->nb_components; c++) {
88 int w1 = c == 1 || c == 2 ? w>>priv->pix_desc->log2_chroma_w : w;
89 int h1 = c == 1 || c == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
90 int y1 = c == 1 || c == 2 ? y>>priv->pix_desc->log2_chroma_h : y;
92 for (i = y1; i < y1 + h1; i++) {
93 av_read_image_line(priv->line,
99 av_write_image_line(priv->line,
107 avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
110 AVFilter avfilter_vf_pixdesctest = {
111 .name = "pixdesctest",
112 .description = "Test pixel format definitions.",
114 .priv_size = sizeof(PixdescTestContext),
117 .inputs = (AVFilterPad[]) {{ .name = "default",
118 .type = AVMEDIA_TYPE_VIDEO,
119 .start_frame = start_frame,
120 .draw_slice = draw_slice,
121 .config_props = config_props,
122 .min_perms = AV_PERM_READ, },
125 .outputs = (AVFilterPad[]) {{ .name = "default",
126 .type = AVMEDIA_TYPE_VIDEO, },