FFmpeg coverage


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