h264_metadata: Add option to delete filler data
[libav.git] / libavfilter / vf_pixdesctest.c
CommitLineData
ce2e4ae3 1/*
3fa77bde
SS
2 * Copyright (c) 2009 Stefano Sabatini
3 *
2912e87a 4 * This file is part of Libav.
ce2e4ae3 5 *
2912e87a 6 * Libav is free software; you can redistribute it and/or
ce2e4ae3
SS
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 *
2912e87a 11 * Libav is distributed in the hope that it will be useful,
ce2e4ae3
SS
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
2912e87a 17 * License along with Libav; if not, write to the Free Software
ce2e4ae3
SS
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
22 * @file
23 * pixdesc test filter
24 */
25
1d9c2dc8 26#include "libavutil/common.h"
ce2e4ae3
SS
27#include "libavutil/pixdesc.h"
28#include "avfilter.h"
9d0bfc50 29#include "internal.h"
803391f7 30#include "video.h"
ce2e4ae3 31
58400ac1 32typedef struct PixdescTestContext {
ce2e4ae3
SS
33 const AVPixFmtDescriptor *pix_desc;
34 uint16_t *line;
35} PixdescTestContext;
36
37static av_cold void uninit(AVFilterContext *ctx)
38{
39 PixdescTestContext *priv = ctx->priv;
40 av_freep(&priv->line);
41}
42
43static int config_props(AVFilterLink *inlink)
44{
45 PixdescTestContext *priv = inlink->dst->priv;
46
59ee9f78 47 priv->pix_desc = av_pix_fmt_desc_get(inlink->format);
ce2e4ae3 48
16a645ad 49 av_freep(&priv->line);
ce2e4ae3
SS
50 if (!(priv->line = av_malloc(sizeof(*priv->line) * inlink->w)))
51 return AVERROR(ENOMEM);
52
53 return 0;
54}
55
7e350379 56static int filter_frame(AVFilterLink *inlink, AVFrame *in)
ce2e4ae3
SS
57{
58 PixdescTestContext *priv = inlink->dst->priv;
59 AVFilterLink *outlink = inlink->dst->outputs[0];
7e350379 60 AVFrame *out;
565e4993 61 int i, c, w = inlink->w, h = inlink->h;
ebc8d974 62
7e350379 63 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
565e4993 64 if (!out) {
7e350379 65 av_frame_free(&in);
ebc8d974 66 return AVERROR(ENOMEM);
565e4993 67 }
ce2e4ae3 68
7e350379 69 av_frame_copy_props(out, in);
ce2e4ae3
SS
70
71 for (i = 0; i < 4; i++) {
72 int h = outlink->h;
73 h = i == 1 || i == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
565e4993
AK
74 if (out->data[i]) {
75 uint8_t *data = out->data[i] +
76 (out->linesize[i] > 0 ? 0 : out->linesize[i] * (h-1));
77 memset(data, 0, FFABS(out->linesize[i]) * h);
ce2e4ae3
SS
78 }
79 }
80
81 /* copy palette */
e6c4ac7b
AK
82 if (priv->pix_desc->flags & AV_PIX_FMT_FLAG_PAL ||
83 priv->pix_desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL)
565e4993 84 memcpy(out->data[1], in->data[1], 256*4);
ce2e4ae3
SS
85
86 for (c = 0; c < priv->pix_desc->nb_components; c++) {
87 int w1 = c == 1 || c == 2 ? w>>priv->pix_desc->log2_chroma_w : w;
88 int h1 = c == 1 || c == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
ce2e4ae3 89
565e4993 90 for (i = 0; i < h1; i++) {
ce1cd1cb 91 av_read_image_line(priv->line,
565e4993
AK
92 in->data,
93 in->linesize,
ee435580
SS
94 priv->pix_desc,
95 0, i, c, w1, 0);
ce2e4ae3 96
ce1cd1cb 97 av_write_image_line(priv->line,
565e4993
AK
98 out->data,
99 out->linesize,
ee435580
SS
100 priv->pix_desc,
101 0, i, c, w1);
ce2e4ae3
SS
102 }
103 }
104
7e350379 105 av_frame_free(&in);
565e4993 106 return ff_filter_frame(outlink, out);
ce2e4ae3
SS
107}
108
568c70e7
MR
109static const AVFilterPad avfilter_vf_pixdesctest_inputs[] = {
110 {
111 .name = "default",
112 .type = AVMEDIA_TYPE_VIDEO,
565e4993 113 .filter_frame = filter_frame,
568c70e7 114 .config_props = config_props,
568c70e7
MR
115 },
116 { NULL }
117};
118
119static const AVFilterPad avfilter_vf_pixdesctest_outputs[] = {
120 {
121 .name = "default",
122 .type = AVMEDIA_TYPE_VIDEO,
123 },
124 { NULL }
125};
126
cd43ca04 127AVFilter ff_vf_pixdesctest = {
ce2e4ae3 128 .name = "pixdesctest",
a6881c6a 129 .description = NULL_IF_CONFIG_SMALL("Test pixel format definitions."),
ce2e4ae3
SS
130
131 .priv_size = sizeof(PixdescTestContext),
132 .uninit = uninit,
133
568c70e7
MR
134 .inputs = avfilter_vf_pixdesctest_inputs,
135
136 .outputs = avfilter_vf_pixdesctest_outputs,
ce2e4ae3 137};