FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/vf_pixdesctest.c
Date: 2025-07-28 20:30:09
Exec Total Coverage
Lines: 38 42 90.5%
Functions: 3 3 100.0%
Branches: 24 28 85.7%

Line Branch Exec Source
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
33 typedef struct PixdescTestContext {
34 const AVPixFmtDescriptor *pix_desc;
35 uint32_t *line;
36 } PixdescTestContext;
37
38 404 static av_cold void uninit(AVFilterContext *ctx)
39 {
40 404 PixdescTestContext *priv = ctx->priv;
41 404 av_freep(&priv->line);
42 404 }
43
44 202 static int config_props(AVFilterLink *inlink)
45 {
46 202 PixdescTestContext *priv = inlink->dst->priv;
47
48 202 priv->pix_desc = av_pix_fmt_desc_get(inlink->format);
49
50 202 av_freep(&priv->line);
51
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 202 times.
202 if (!(priv->line = av_malloc_array(sizeof(*priv->line), inlink->w)))
52 return AVERROR(ENOMEM);
53
54 202 return 0;
55 }
56
57 1212 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
58 {
59 1212 PixdescTestContext *priv = inlink->dst->priv;
60 1212 AVFilterLink *outlink = inlink->dst->outputs[0];
61 AVFrame *out;
62 1212 int i, c, w = inlink->w, h = inlink->h;
63 1212 const int cw = AV_CEIL_RSHIFT(w, priv->pix_desc->log2_chroma_w);
64 1212 const int ch = AV_CEIL_RSHIFT(h, priv->pix_desc->log2_chroma_h);
65
66 1212 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1212 times.
1212 if (!out) {
68 av_frame_free(&in);
69 return AVERROR(ENOMEM);
70 }
71
72 1212 av_frame_copy_props(out, in);
73
74
2/2
✓ Branch 0 taken 4848 times.
✓ Branch 1 taken 1212 times.
6060 for (i = 0; i < 4; i++) {
75
4/4
✓ Branch 0 taken 3636 times.
✓ Branch 1 taken 1212 times.
✓ Branch 2 taken 1212 times.
✓ Branch 3 taken 2424 times.
4848 const int h1 = i == 1 || i == 2 ? ch : h;
76
2/2
✓ Branch 0 taken 2802 times.
✓ Branch 1 taken 2046 times.
4848 if (out->data[i]) {
77 5604 uint8_t *data = out->data[i] +
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2802 times.
2802 (out->linesize[i] > 0 ? 0 : out->linesize[i] * (h1-1));
79 2802 memset(data, 0, FFABS(out->linesize[i]) * h1);
80 }
81 }
82
83 /* copy palette */
84
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1212 times.
1212 if (priv->pix_desc->flags & AV_PIX_FMT_FLAG_PAL)
85 memcpy(out->data[1], in->data[1], AVPALETTE_SIZE);
86
87
2/2
✓ Branch 0 taken 4848 times.
✓ Branch 1 taken 1212 times.
6060 for (c = 0; c < FF_ARRAY_ELEMS(priv->pix_desc->comp); c++) {
88
4/4
✓ Branch 0 taken 3636 times.
✓ Branch 1 taken 1212 times.
✓ Branch 2 taken 1212 times.
✓ Branch 3 taken 2424 times.
4848 const int w1 = c == 1 || c == 2 ? cw : w;
89
4/4
✓ Branch 0 taken 3636 times.
✓ Branch 1 taken 1212 times.
✓ Branch 2 taken 1212 times.
✓ Branch 3 taken 2424 times.
4848 const int h1 = c == 1 || c == 2 ? ch : h;
90
91
2/2
✓ Branch 0 taken 1336608 times.
✓ Branch 1 taken 4848 times.
1341456 for (i = 0; i < h1; i++) {
92 1336608 av_read_image_line2(priv->line,
93 1336608 (void*)in->data,
94 1336608 in->linesize,
95 priv->pix_desc,
96 0, i, c, w1, 0, 4);
97
98 1336608 av_write_image_line2(priv->line,
99 1336608 out->data,
100 1336608 out->linesize,
101 priv->pix_desc,
102 0, i, c, w1, 4);
103 }
104 }
105
106 1212 av_frame_free(&in);
107 1212 return ff_filter_frame(outlink, out);
108 }
109
110 static const AVFilterPad avfilter_vf_pixdesctest_inputs[] = {
111 {
112 .name = "default",
113 .type = AVMEDIA_TYPE_VIDEO,
114 .filter_frame = filter_frame,
115 .config_props = config_props,
116 },
117 };
118
119 const FFFilter ff_vf_pixdesctest = {
120 .p.name = "pixdesctest",
121 .p.description = NULL_IF_CONFIG_SMALL("Test pixel format definitions."),
122 .priv_size = sizeof(PixdescTestContext),
123 .uninit = uninit,
124 FILTER_INPUTS(avfilter_vf_pixdesctest_inputs),
125 FILTER_OUTPUTS(ff_video_default_filterpad),
126 };
127