ffmpeg / libavfilter / vf_pixdesctest.c @ ce2e4ae3
History | View | Annotate | Download (4.24 KB)
1 |
/*
|
---|---|
2 |
* This file is part of FFmpeg.
|
3 |
* copyright (C) 2009 Stefano Sabatini
|
4 |
*
|
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.
|
9 |
*
|
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.
|
14 |
*
|
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
|
18 |
*/
|
19 |
|
20 |
/**
|
21 |
* @file
|
22 |
* pixdesc test filter
|
23 |
*/
|
24 |
|
25 |
#include "libavutil/pixdesc.h" |
26 |
#include "avfilter.h" |
27 |
|
28 |
typedef struct { |
29 |
const AVPixFmtDescriptor *pix_desc;
|
30 |
uint16_t *line; |
31 |
} PixdescTestContext; |
32 |
|
33 |
static av_cold void uninit(AVFilterContext *ctx) |
34 |
{ |
35 |
PixdescTestContext *priv = ctx->priv; |
36 |
av_freep(&priv->line); |
37 |
} |
38 |
|
39 |
static int config_props(AVFilterLink *inlink) |
40 |
{ |
41 |
PixdescTestContext *priv = inlink->dst->priv; |
42 |
|
43 |
priv->pix_desc = &av_pix_fmt_descriptors[inlink->format]; |
44 |
|
45 |
if (!(priv->line = av_malloc(sizeof(*priv->line) * inlink->w))) |
46 |
return AVERROR(ENOMEM);
|
47 |
|
48 |
return 0; |
49 |
} |
50 |
|
51 |
static void start_frame(AVFilterLink *inlink, AVFilterPicRef *picref) |
52 |
{ |
53 |
PixdescTestContext *priv = inlink->dst->priv; |
54 |
AVFilterLink *outlink = inlink->dst->outputs[0];
|
55 |
AVFilterPicRef *outpicref; |
56 |
int i;
|
57 |
|
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); |
62 |
|
63 |
for (i = 0; i < 4; i++) { |
64 |
int h = outlink->h;
|
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);
|
70 |
} |
71 |
} |
72 |
|
73 |
/* copy palette */
|
74 |
if (priv->pix_desc->flags & PIX_FMT_PAL)
|
75 |
memcpy(outpicref->data[1], outpicref->data[1], 256*4); |
76 |
|
77 |
avfilter_start_frame(outlink, avfilter_ref_pic(outpicref, ~0));
|
78 |
} |
79 |
|
80 |
static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) |
81 |
{ |
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;
|
86 |
|
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; |
91 |
|
92 |
for (i = y1; i < y1 + h1; i++) {
|
93 |
read_line(priv->line, |
94 |
inpic->data, |
95 |
inpic->linesize, |
96 |
priv->pix_desc, |
97 |
0, i, c, w1, 0); |
98 |
|
99 |
write_line(priv->line, |
100 |
outpic->data, |
101 |
outpic->linesize, |
102 |
priv->pix_desc, |
103 |
0, i, c, w1);
|
104 |
} |
105 |
} |
106 |
|
107 |
avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
|
108 |
} |
109 |
|
110 |
AVFilter avfilter_vf_pixdesctest = { |
111 |
.name = "pixdesctest",
|
112 |
.description = "Test pixel format definitions.",
|
113 |
|
114 |
.priv_size = sizeof(PixdescTestContext),
|
115 |
.uninit = uninit, |
116 |
|
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, }, |
123 |
{ .name = NULL}},
|
124 |
|
125 |
.outputs = (AVFilterPad[]) {{ .name = "default",
|
126 |
.type = AVMEDIA_TYPE_VIDEO, }, |
127 |
{ .name = NULL}},
|
128 |
}; |