FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/tests/imgutils.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 62 69 89.9%
Functions: 3 3 100.0%
Branches: 42 48 87.5%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "libavutil/imgutils.c"
20 #include "libavutil/crc.h"
21 #include "libavutil/mem.h"
22
23 #undef printf
24 229 static int check_image_fill(enum AVPixelFormat pix_fmt, int w, int h) {
25 uint8_t *data[4];
26 size_t sizes[4];
27 229 ptrdiff_t linesizes1[4], offsets[3] = { 0 };
28 int i, total_size, linesizes[4];
29
30
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 229 times.
229 if (av_image_fill_linesizes(linesizes, pix_fmt, w) < 0)
31 return -1;
32
2/2
✓ Branch 0 taken 916 times.
✓ Branch 1 taken 229 times.
1145 for (i = 0; i < 4; i++)
33 916 linesizes1[i] = linesizes[i];
34
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 229 times.
229 if (av_image_fill_plane_sizes(sizes, pix_fmt, h, linesizes1) < 0)
35 return -1;
36 229 total_size = av_image_fill_pointers(data, pix_fmt, h, (void *)1, linesizes);
37
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 229 times.
229 if (total_size < 0)
38 return -1;
39
4/4
✓ Branch 0 taken 672 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 479 times.
✓ Branch 3 taken 193 times.
708 for (i = 0; i < 4 && data[i]; i++);
40 229 printf("planes: %d", i);
41 // Test the output of av_image_fill_linesizes()
42 229 printf(", linesizes:");
43
2/2
✓ Branch 0 taken 916 times.
✓ Branch 1 taken 229 times.
1145 for (i = 0; i < 4; i++)
44 916 printf(" %3d", linesizes[i]);
45 // Test the output of av_image_fill_plane_sizes()
46 229 printf(", plane_sizes:");
47
2/2
✓ Branch 0 taken 916 times.
✓ Branch 1 taken 229 times.
1145 for (i = 0; i < 4; i++)
48 916 printf(" %5"SIZE_SPECIFIER, sizes[i]);
49 // Test the output of av_image_fill_pointers()
50
4/4
✓ Branch 0 taken 443 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 250 times.
✓ Branch 3 taken 193 times.
479 for (i = 0; i < 3 && data[i + 1]; i++)
51 250 offsets[i] = data[i + 1] - data[i];
52 229 printf(", plane_offsets:");
53
2/2
✓ Branch 0 taken 687 times.
✓ Branch 1 taken 229 times.
916 for (i = 0; i < 3; i++)
54 687 printf(" %5"PTRDIFF_SPECIFIER, offsets[i]);
55 229 printf(", total_size: %d", total_size);
56
57 229 return 0;
58 }
59
60 229 static int check_image_fill_black(const AVPixFmtDescriptor *desc, enum AVPixelFormat pix_fmt, int w, int h)
61 {
62 uint8_t *data[4];
63 ptrdiff_t linesizes1[4];
64 int ret, total_size, linesizes[4];
65
66 229 ret = av_image_fill_linesizes(linesizes, pix_fmt, w);
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 229 times.
229 if (ret < 0)
68 return ret;
69 229 total_size = av_image_alloc(data, linesizes, w, h, pix_fmt, 4);
70
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 229 times.
229 if (total_size < 0) {
71 printf("alloc failure");
72 return total_size;
73 }
74 229 printf("total_size: %6d", total_size);
75
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 228 times.
229 if (desc->flags & AV_PIX_FMT_FLAG_PAL)
76 1 total_size -= 256 * 4;
77 // Make it non-black by default...
78 229 memset(data[0], 0xA3, total_size);
79
2/2
✓ Branch 0 taken 916 times.
✓ Branch 1 taken 229 times.
1145 for (int i = 0; i < 4; i++)
80 916 linesizes1[i] = linesizes[i];
81
2/2
✓ Branch 0 taken 687 times.
✓ Branch 1 taken 229 times.
916 for (enum AVColorRange range = 0; range < AVCOL_RANGE_NB; range++) {
82 687 ret = av_image_fill_black(data, linesizes1, pix_fmt, range, w, h);
83 687 printf(", black_%s_crc: ", av_color_range_name(range));
84
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 687 times.
687 if (ret < 0) {
85 printf("----------");
86 } else {
87 687 const AVCRC *crc = av_crc_get_table(AV_CRC_32_IEEE_LE);
88 687 printf("0x%08"PRIx32, av_crc(crc, 0, data[0], total_size));
89 }
90 }
91 229 av_freep(&data[0]);
92
93 229 return 0;
94 }
95
96 1 int main(void)
97 {
98 int64_t x, y;
99
100
2/2
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 1 times.
56 for (y = -1; y<UINT_MAX; y+= y/2 + 1) {
101
2/2
✓ Branch 0 taken 3025 times.
✓ Branch 1 taken 55 times.
3080 for (x = -1; x<UINT_MAX; x+= x/2 + 1) {
102 3025 int ret = av_image_check_size(x, y, 0, NULL);
103 3025 printf("%d", ret >= 0);
104 }
105 55 printf("\n");
106 }
107 1 printf("\n");
108
109
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (int i = 0; i < 2; i++) {
110
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 printf(i ? "\nimage_fill_black tests\n" : "image_fill tests\n");
111
2/2
✓ Branch 1 taken 486 times.
✓ Branch 2 taken 2 times.
488 for (const AVPixFmtDescriptor *desc = NULL; desc = av_pix_fmt_desc_next(desc);) {
112 486 int w = 64, h = 48;
113 486 enum AVPixelFormat pix_fmt = av_pix_fmt_desc_get_id(desc);
114
115
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 458 times.
486 if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL)
116 28 continue;
117
118 458 printf("%-16s", desc->name);
119
2/2
✓ Branch 0 taken 229 times.
✓ Branch 1 taken 229 times.
458 if (i == 0)
120 229 check_image_fill(pix_fmt, w, h);
121 else
122 229 check_image_fill_black(desc, pix_fmt, w, h);
123 458 printf("\n");
124 }
125 }
126
127 1 return 0;
128 }
129