FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/tests/pixfmt_best.c
Date: 2024-05-03 05:27:13
Exec Total Coverage
Lines: 95 97 97.9%
Functions: 7 7 100.0%
Branches: 21 22 95.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/pixdesc.c"
20
21 static const enum AVPixelFormat pixfmt_list[] = {
22 AV_PIX_FMT_MONOWHITE,
23 AV_PIX_FMT_GRAY8,
24 AV_PIX_FMT_GRAY10,
25 AV_PIX_FMT_GRAY16,
26 AV_PIX_FMT_YUV420P,
27 AV_PIX_FMT_YUV420P10,
28 AV_PIX_FMT_YUV420P16,
29 AV_PIX_FMT_YUV422P,
30 AV_PIX_FMT_YUV422P10,
31 AV_PIX_FMT_YUV422P16,
32 AV_PIX_FMT_YUV444P,
33 AV_PIX_FMT_YUV444P10,
34 AV_PIX_FMT_YUV444P16,
35 AV_PIX_FMT_RGB565,
36 AV_PIX_FMT_RGB24,
37 AV_PIX_FMT_RGB48,
38 AV_PIX_FMT_VDPAU,
39 AV_PIX_FMT_VAAPI,
40 };
41
42 static const enum AVPixelFormat semiplanar_list[] = {
43 AV_PIX_FMT_P016,
44 AV_PIX_FMT_P012,
45 AV_PIX_FMT_P010,
46 AV_PIX_FMT_NV12,
47 };
48
49 static const enum AVPixelFormat packed_list[] = {
50 AV_PIX_FMT_XV36,
51 AV_PIX_FMT_XV30,
52 AV_PIX_FMT_VUYX,
53 AV_PIX_FMT_Y212,
54 AV_PIX_FMT_Y210,
55 AV_PIX_FMT_YUYV422,
56 };
57
58 static const enum AVPixelFormat subsampled_list[] = {
59 AV_PIX_FMT_YUV411P,
60 AV_PIX_FMT_YUV420P,
61 AV_PIX_FMT_YUV422P,
62 AV_PIX_FMT_YUV444P,
63 };
64
65 static const enum AVPixelFormat depthchroma_list[] = {
66 AV_PIX_FMT_YUV420P14,
67 AV_PIX_FMT_YUV422P14,
68 AV_PIX_FMT_YUV444P16,
69 };
70
71 typedef enum AVPixelFormat (*find_best_t)(enum AVPixelFormat pixfmt);
72
73 #define find_best_wrapper(name, list) \
74 static enum AVPixelFormat find_best_ ## name (enum AVPixelFormat pixfmt) \
75 { \
76 enum AVPixelFormat best = AV_PIX_FMT_NONE; \
77 int i; \
78 for (i = 0; i < FF_ARRAY_ELEMS(list); i++) \
79 best = av_find_best_pix_fmt_of_2(best, list[i], \
80 pixfmt, 0, NULL); \
81 return best; \
82 }
83
84
2/2
✓ Branch 1 taken 1350 times.
✓ Branch 2 taken 75 times.
1425 find_best_wrapper(base, pixfmt_list)
85
2/2
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 9 times.
45 find_best_wrapper(seminplanar, semiplanar_list)
86
2/2
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 12 times.
84 find_best_wrapper(packed, packed_list)
87
2/2
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 5 times.
25 find_best_wrapper(subsampled, subsampled_list)
88
2/2
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 5 times.
20 find_best_wrapper(depthchroma, depthchroma_list)
89
90 106 static void test(enum AVPixelFormat input, enum AVPixelFormat expected,
91 int *pass, int *fail, find_best_t find_best_fn)
92 {
93 106 enum AVPixelFormat output = find_best_fn(input);
94
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 106 times.
106 if (output != expected) {
95 printf("Matching %s: got %s, expected %s\n",
96 av_get_pix_fmt_name(input),
97 av_get_pix_fmt_name(output),
98 av_get_pix_fmt_name(expected));
99 ++(*fail);
100 } else
101 106 ++(*pass);
102 106 }
103
104 1 int main(void)
105 {
106 1 int i, pass = 0, fail = 0;
107
108 #define TEST(input, expected) \
109 test(input, expected, &pass, &fail, find_best_base)
110
111 // Same formats.
112
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 1 times.
19 for (i = 0; i < FF_ARRAY_ELEMS(pixfmt_list); i++)
113 18 TEST(pixfmt_list[i], pixfmt_list[i]);
114
115 // Formats containing the same data in different layouts.
116 1 TEST(AV_PIX_FMT_MONOBLACK, AV_PIX_FMT_MONOWHITE);
117 1 TEST(AV_PIX_FMT_NV12, AV_PIX_FMT_YUV420P);
118 1 TEST(AV_PIX_FMT_P010, AV_PIX_FMT_YUV420P10);
119 1 TEST(AV_PIX_FMT_P016, AV_PIX_FMT_YUV420P16);
120 1 TEST(AV_PIX_FMT_NV16, AV_PIX_FMT_YUV422P);
121 1 TEST(AV_PIX_FMT_NV24, AV_PIX_FMT_YUV444P);
122 1 TEST(AV_PIX_FMT_YUYV422, AV_PIX_FMT_YUV422P);
123 1 TEST(AV_PIX_FMT_UYVY422, AV_PIX_FMT_YUV422P);
124 1 TEST(AV_PIX_FMT_BGR565, AV_PIX_FMT_RGB565);
125 1 TEST(AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB24);
126 1 TEST(AV_PIX_FMT_GBRP, AV_PIX_FMT_RGB24);
127 1 TEST(AV_PIX_FMT_0RGB, AV_PIX_FMT_RGB24);
128 1 TEST(AV_PIX_FMT_GBRP16, AV_PIX_FMT_RGB48);
129 1 TEST(AV_PIX_FMT_VUYX, AV_PIX_FMT_YUV444P);
130
131 // Formats additionally containing alpha (here ignored).
132 1 TEST(AV_PIX_FMT_YA8, AV_PIX_FMT_GRAY8);
133 1 TEST(AV_PIX_FMT_YA16, AV_PIX_FMT_GRAY16);
134 1 TEST(AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUV420P);
135 1 TEST(AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUV422P);
136 1 TEST(AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUV444P);
137 1 TEST(AV_PIX_FMT_VUYA, AV_PIX_FMT_YUV444P);
138 1 TEST(AV_PIX_FMT_AYUV64, AV_PIX_FMT_YUV444P16);
139 1 TEST(AV_PIX_FMT_RGBA, AV_PIX_FMT_RGB24);
140 1 TEST(AV_PIX_FMT_ABGR, AV_PIX_FMT_RGB24);
141 1 TEST(AV_PIX_FMT_GBRAP, AV_PIX_FMT_RGB24);
142 1 TEST(AV_PIX_FMT_RGBA64, AV_PIX_FMT_RGB48);
143 1 TEST(AV_PIX_FMT_BGRA64, AV_PIX_FMT_RGB48);
144 1 TEST(AV_PIX_FMT_GBRAP16, AV_PIX_FMT_RGB48);
145
146 // Formats requiring upsampling to represent exactly.
147 1 TEST(AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY16);
148 1 TEST(AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV420P);
149 1 TEST(AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV422P);
150 1 TEST(AV_PIX_FMT_UYYVYY411, AV_PIX_FMT_YUV422P);
151 1 TEST(AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P);
152 1 TEST(AV_PIX_FMT_YUV440P10, AV_PIX_FMT_YUV444P10);
153 1 TEST(AV_PIX_FMT_YUV440P12, AV_PIX_FMT_YUV444P16);
154 1 TEST(AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV420P10);
155 1 TEST(AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV420P16);
156 1 TEST(AV_PIX_FMT_YUV444P9, AV_PIX_FMT_YUV444P10);
157 1 TEST(AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV444P16);
158 1 TEST(AV_PIX_FMT_BGR4, AV_PIX_FMT_RGB565);
159 1 TEST(AV_PIX_FMT_RGB444, AV_PIX_FMT_RGB565);
160 1 TEST(AV_PIX_FMT_RGB555, AV_PIX_FMT_RGB565);
161 1 TEST(AV_PIX_FMT_GBRP10, AV_PIX_FMT_RGB48);
162 1 TEST(AV_PIX_FMT_GBRAP10, AV_PIX_FMT_RGB48);
163 1 TEST(AV_PIX_FMT_GBRAP12, AV_PIX_FMT_RGB48);
164
165 // Formats containing the same data in different endianness.
166 1 TEST(AV_PIX_FMT_GRAY10BE, AV_PIX_FMT_GRAY10);
167 1 TEST(AV_PIX_FMT_GRAY10LE, AV_PIX_FMT_GRAY10);
168 1 TEST(AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_GRAY16);
169 1 TEST(AV_PIX_FMT_GRAY16LE, AV_PIX_FMT_GRAY16);
170 1 TEST(AV_PIX_FMT_YUV422P10BE, AV_PIX_FMT_YUV422P10);
171 1 TEST(AV_PIX_FMT_YUV422P10LE, AV_PIX_FMT_YUV422P10);
172 1 TEST(AV_PIX_FMT_YUV444P16BE, AV_PIX_FMT_YUV444P16);
173 1 TEST(AV_PIX_FMT_YUV444P16LE, AV_PIX_FMT_YUV444P16);
174 1 TEST(AV_PIX_FMT_RGB565BE, AV_PIX_FMT_RGB565);
175 1 TEST(AV_PIX_FMT_RGB565LE, AV_PIX_FMT_RGB565);
176 1 TEST(AV_PIX_FMT_RGB48BE, AV_PIX_FMT_RGB48);
177 1 TEST(AV_PIX_FMT_RGB48LE, AV_PIX_FMT_RGB48);
178
179 // Opaque formats are least unlike each other.
180 1 TEST(AV_PIX_FMT_DXVA2_VLD, AV_PIX_FMT_VDPAU);
181
182 #define TEST_SEMIPLANAR(input, expected) \
183 test(input, expected, &pass, &fail, find_best_seminplanar)
184
185 // Same formats.
186
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (i = 0; i < FF_ARRAY_ELEMS(semiplanar_list); i++)
187 4 TEST_SEMIPLANAR(semiplanar_list[i], semiplanar_list[i]);
188
189 // Formats containing the same data in different layouts.
190 1 TEST_SEMIPLANAR(AV_PIX_FMT_YUV420P, AV_PIX_FMT_NV12);
191 1 TEST_SEMIPLANAR(AV_PIX_FMT_YUV420P10, AV_PIX_FMT_P010);
192 1 TEST_SEMIPLANAR(AV_PIX_FMT_YUV420P12, AV_PIX_FMT_P012);
193 1 TEST_SEMIPLANAR(AV_PIX_FMT_YUV420P16, AV_PIX_FMT_P016);
194 1 TEST_SEMIPLANAR(AV_PIX_FMT_YUV420P9, AV_PIX_FMT_P010);
195
196 #define TEST_PACKED(input, expected) \
197 test(input, expected, &pass, &fail, find_best_packed)
198
199 // Same formats.
200
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 for (i = 0; i < FF_ARRAY_ELEMS(packed_list); i++)
201 6 TEST_PACKED(packed_list[i], packed_list[i]);
202
203 // Formats containing the same data in different layouts.
204 1 TEST_PACKED(AV_PIX_FMT_YUV444P, AV_PIX_FMT_VUYX);
205 1 TEST_PACKED(AV_PIX_FMT_YUV444P10, AV_PIX_FMT_XV30);
206 1 TEST_PACKED(AV_PIX_FMT_YUV444P12, AV_PIX_FMT_XV36);
207 1 TEST_PACKED(AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUYV422);
208 1 TEST_PACKED(AV_PIX_FMT_YUV422P10, AV_PIX_FMT_Y210);
209 1 TEST_PACKED(AV_PIX_FMT_YUV422P12, AV_PIX_FMT_Y212);
210
211 #define TEST_SUBSAMPLED(input, expected) \
212 test(input, expected, &pass, &fail, find_best_subsampled)
213
214 // Same formats.
215
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (i = 0; i < FF_ARRAY_ELEMS(subsampled_list); i++)
216 4 TEST_SUBSAMPLED(subsampled_list[i], subsampled_list[i]);
217
218 1 TEST_SUBSAMPLED(AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV420P);
219
220 #define TEST_DEPTH_CHROMA(input, expected) \
221 test(input, expected, &pass, &fail, find_best_depthchroma)
222
223 // Same formats.
224
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (i = 0; i < FF_ARRAY_ELEMS(depthchroma_list); i++)
225 3 TEST_DEPTH_CHROMA(depthchroma_list[i], depthchroma_list[i]);
226
227 1 TEST_DEPTH_CHROMA(AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV444P16);
228 1 TEST_DEPTH_CHROMA(AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16);
229
230
231 1 printf("%d tests passed, %d tests failed.\n", pass, fail);
232 1 return !!fail;
233 }
234