FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/vf_pixdesctest.c
Date: 2022-12-05 03:11:11
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/pixdesc.h"
28 #include "avfilter.h"
29 #include "internal.h"
30 #include "video.h"
31
32 typedef struct PixdescTestContext {
33 const AVPixFmtDescriptor *pix_desc;
34 uint32_t *line;
35 } PixdescTestContext;
36
37 177 static av_cold void uninit(AVFilterContext *ctx)
38 {
39 177 PixdescTestContext *priv = ctx->priv;
40 177 av_freep(&priv->line);
41 177 }
42
43 177 static int config_props(AVFilterLink *inlink)
44 {
45 177 PixdescTestContext *priv = inlink->dst->priv;
46
47 177 priv->pix_desc = av_pix_fmt_desc_get(inlink->format);
48
49 177 av_freep(&priv->line);
50
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 177 times.
177 if (!(priv->line = av_malloc_array(sizeof(*priv->line), inlink->w)))
51 return AVERROR(ENOMEM);
52
53 177 return 0;
54 }
55
56 885 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
57 {
58 885 PixdescTestContext *priv = inlink->dst->priv;
59 885 AVFilterLink *outlink = inlink->dst->outputs[0];
60 AVFrame *out;
61 885 int i, c, w = inlink->w, h = inlink->h;
62 885 const int cw = AV_CEIL_RSHIFT(w, priv->pix_desc->log2_chroma_w);
63 885 const int ch = AV_CEIL_RSHIFT(h, priv->pix_desc->log2_chroma_h);
64
65 885 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
66
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 885 times.
885 if (!out) {
67 av_frame_free(&in);
68 return AVERROR(ENOMEM);
69 }
70
71 885 av_frame_copy_props(out, in);
72
73
2/2
✓ Branch 0 taken 3540 times.
✓ Branch 1 taken 885 times.
4425 for (i = 0; i < 4; i++) {
74
4/4
✓ Branch 0 taken 2655 times.
✓ Branch 1 taken 885 times.
✓ Branch 2 taken 885 times.
✓ Branch 3 taken 1770 times.
3540 const int h1 = i == 1 || i == 2 ? ch : h;
75
2/2
✓ Branch 0 taken 2070 times.
✓ Branch 1 taken 1470 times.
3540 if (out->data[i]) {
76 4140 uint8_t *data = out->data[i] +
77
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2070 times.
2070 (out->linesize[i] > 0 ? 0 : out->linesize[i] * (h1-1));
78 2070 memset(data, 0, FFABS(out->linesize[i]) * h1);
79 }
80 }
81
82 /* copy palette */
83
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 885 times.
885 if (priv->pix_desc->flags & AV_PIX_FMT_FLAG_PAL)
84 memcpy(out->data[1], in->data[1], AVPALETTE_SIZE);
85
86
2/2
✓ Branch 0 taken 2710 times.
✓ Branch 1 taken 885 times.
3595 for (c = 0; c < priv->pix_desc->nb_components; c++) {
87
4/4
✓ Branch 0 taken 1900 times.
✓ Branch 1 taken 810 times.
✓ Branch 2 taken 795 times.
✓ Branch 3 taken 1105 times.
2710 const int w1 = c == 1 || c == 2 ? cw : w;
88
4/4
✓ Branch 0 taken 1900 times.
✓ Branch 1 taken 810 times.
✓ Branch 2 taken 795 times.
✓ Branch 3 taken 1105 times.
2710 const int h1 = c == 1 || c == 2 ? ch : h;
89
90
2/2
✓ Branch 0 taken 730800 times.
✓ Branch 1 taken 2710 times.
733510 for (i = 0; i < h1; i++) {
91 730800 av_read_image_line2(priv->line,
92 730800 (void*)in->data,
93 730800 in->linesize,
94 priv->pix_desc,
95 0, i, c, w1, 0, 4);
96
97 730800 av_write_image_line2(priv->line,
98 730800 out->data,
99 730800 out->linesize,
100 priv->pix_desc,
101 0, i, c, w1, 4);
102 }
103 }
104
105 885 av_frame_free(&in);
106 885 return ff_filter_frame(outlink, out);
107 }
108
109 static const AVFilterPad avfilter_vf_pixdesctest_inputs[] = {
110 {
111 .name = "default",
112 .type = AVMEDIA_TYPE_VIDEO,
113 .filter_frame = filter_frame,
114 .config_props = config_props,
115 },
116 };
117
118 static const AVFilterPad avfilter_vf_pixdesctest_outputs[] = {
119 {
120 .name = "default",
121 .type = AVMEDIA_TYPE_VIDEO,
122 },
123 };
124
125 const AVFilter ff_vf_pixdesctest = {
126 .name = "pixdesctest",
127 .description = NULL_IF_CONFIG_SMALL("Test pixel format definitions."),
128 .priv_size = sizeof(PixdescTestContext),
129 .uninit = uninit,
130 FILTER_INPUTS(avfilter_vf_pixdesctest_inputs),
131 FILTER_OUTPUTS(avfilter_vf_pixdesctest_outputs),
132 };
133