FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/tests/checkasm/sw_scale.c
Date: 2026-09-18 03:39:54
Exec Total Coverage
Lines: 222 248 89.5%
Functions: 8 12 66.7%
Branches: 124 232 53.4%

Line Branch Exec Source
1 /*
2 *
3 * This file is part of FFmpeg.
4 *
5 * FFmpeg is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * FFmpeg is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <string.h>
21
22 #include "libavutil/common.h"
23 #include "libavutil/intreadwrite.h"
24 #include "libavutil/mem.h"
25 #include "libavutil/mem_internal.h"
26
27 #include "libswscale/swscale.h"
28 #include "libswscale/swscale_internal.h"
29
30 #include "checkasm.h"
31
32 #define randomize_buffers(buf, size) \
33 do { \
34 int j; \
35 for (j = 0; j < size; j+=4) \
36 AV_WN32(buf + j, rnd()); \
37 } while (0)
38
39 608 static void yuv2planeX_8_ref(const int16_t *filter, int filterSize,
40 const int16_t **src, uint8_t *dest, int dstW,
41 const uint8_t *dither, int offset)
42 {
43 // This corresponds to the yuv2planeX_8_c function
44 int i;
45
2/2
✓ Branch 0 taken 122112 times.
✓ Branch 1 taken 608 times.
122720 for (i = 0; i < dstW; i++) {
46 122112 int val = dither[(i + offset) & 7] << 12;
47 int j;
48
2/2
✓ Branch 0 taken 915840 times.
✓ Branch 1 taken 122112 times.
1037952 for (j = 0; j < filterSize; j++)
49 915840 val += src[j][i] * filter[j];
50
51 122112 dest[i]= av_clip_uint8(val >> 19);
52 }
53 608 }
54
55 #define CMP_FUNC(bits) \
56 static int cmp_off_by_n_##bits(const uint##bits##_t *ref, const uint##bits##_t *test, \
57 size_t n, int accuracy) \
58 { \
59 for (size_t i = 0; i < n; i++) { \
60 if (abs((int)ref[i] - (int)test[i]) > accuracy) \
61 return 1; \
62 } \
63 return 0; \
64 }
65
66
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 363856 times.
✓ Branch 2 taken 363856 times.
✓ Branch 3 taken 920 times.
364776 CMP_FUNC(8)
67
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1089536 times.
✓ Branch 2 taken 1089536 times.
✓ Branch 3 taken 2128 times.
1091664 CMP_FUNC(16)
68
69 #define SHOW_DIFF_FUNC(bits) \
70 static void print_data_##bits(const uint##bits##_t *p, size_t len, size_t offset) \
71 { \
72 size_t i = 0; \
73 for (; i < len; i++) { \
74 if (i % 8 == 0) { \
75 printf("0x%04zx: ", i+offset); \
76 } \
77 printf("0x%02x ", (uint32_t) p[i]); \
78 if (i % 8 == 7) { \
79 printf("\n"); \
80 } \
81 } \
82 if (i % 8 != 0) { \
83 printf("\n"); \
84 } \
85 } \
86 static size_t show_differences_##bits(const uint##bits##_t *a, const uint##bits##_t *b, \
87 size_t len) \
88 { \
89 for (size_t i = 0; i < len; i++) { \
90 if (a[i] != b[i]) { \
91 size_t offset_of_mismatch = i; \
92 size_t offset; \
93 if (i >= 8) i-=8; \
94 offset = i & (~7); \
95 printf("test a:\n"); \
96 print_data_##bits(&a[offset], 32, offset); \
97 printf("\ntest b:\n"); \
98 print_data_##bits(&b[offset], 32, offset); \
99 printf("\n"); \
100 return offset_of_mismatch; \
101 } \
102 } \
103 return len; \
104 }
105
106 SHOW_DIFF_FUNC(8)
107 SHOW_DIFF_FUNC(16)
108
109 28 static void check_yuv2yuv1(int accurate)
110 {
111 SwsContext *sws;
112 SwsInternal *c;
113 int osi, isi;
114 int dstW, offset;
115 size_t fail_offset;
116 /* Add short widths that split across the SIMD vector tail paths, so that
117 * a single residual vector iteration is exercised on every platform;
118 * such residuals can underflow/overflow the destination buffer. */
119 enum {
120 LARGEST_INPUT_SIZE = 512,
121 /* Leading guard before dst: wide enough to catch a whole-vector
122 * underflow, i.e. the widest single write a current yuv2plane1 may
123 * make while tail-looping. That is the LoongArch LASX 256-bit (32B)
124 * store; LSX, NEON and x86 sse2/avx all write 16B or less. */
125 DEST_GUARD = 32,
126 DEST_SIZE = LARGEST_INPUT_SIZE + 2 * DEST_GUARD,
127 };
128 28 const int input_sizes[] = {5, 8, 9, 15, 17, 24, 128, 144, 256, 512};
129
130 28 const int offsets[] = {0, 3, 8, 11, 16, 19};
131 28 const int OFFSET_SIZES = sizeof(offsets)/sizeof(offsets[0]);
132
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 14 times.
28 const char *accurate_str = (accurate) ? "accurate" : "approximate";
133 uint8_t *dst_ref, *dst_new;
134
135 28 declare_func(void,
136 const int16_t *src, uint8_t *dest,
137 int dstW, const uint8_t *dither, int offset);
138
139 28 LOCAL_ALIGNED_16(int16_t, src_pixels, [LARGEST_INPUT_SIZE]);
140 28 LOCAL_ALIGNED_16(uint8_t, dst0, [DEST_SIZE]);
141 28 LOCAL_ALIGNED_16(uint8_t, dst1, [DEST_SIZE]);
142 28 LOCAL_ALIGNED_8(uint8_t, dither, [8]);
143
144
2/2
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 28 times.
84 randomize_buffers((uint8_t*)dither, 8);
145
2/2
✓ Branch 1 taken 7168 times.
✓ Branch 2 taken 28 times.
7196 randomize_buffers((uint8_t*)src_pixels, LARGEST_INPUT_SIZE * sizeof(int16_t));
146 28 sws = sws_alloc_context();
147
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 14 times.
28 if (accurate)
148 14 sws->flags |= SWS_ACCURATE_RND;
149
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
28 if (sws_init_context(sws, NULL, NULL) < 0)
150 fail();
151
152 28 c = sws_internal(sws);
153 28 ff_sws_init_scale(c);
154
2/2
✓ Branch 0 taken 280 times.
✓ Branch 1 taken 28 times.
308 for (isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); ++isi) {
155 280 dstW = input_sizes[isi];
156
2/2
✓ Branch 0 taken 1680 times.
✓ Branch 1 taken 280 times.
1960 for (osi = 0; osi < OFFSET_SIZES; osi++) {
157 1680 offset = offsets[osi];
158
2/2
✓ Branch 1 taken 240 times.
✓ Branch 2 taken 1440 times.
1680 if (check_func(c->yuv2plane1, "yuv2yuv1_%d_%d_%s", offset, dstW, accurate_str)){
159 /* dst0 and dst1 start bit-identical so that any write outside
160 * of the dstW output window shows up as a guard mismatch. */
161
2/2
✓ Branch 1 taken 34560 times.
✓ Branch 2 taken 240 times.
34800 randomize_buffers(dst0, DEST_SIZE);
162 240 memcpy(dst1, dst0, DEST_SIZE);
163 240 dst_ref = dst0 + DEST_GUARD;
164 240 dst_new = dst1 + DEST_GUARD;
165
166
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 240 times.
240 call_ref(src_pixels, dst_ref, dstW, dither, offset);
167 240 call_new(src_pixels, dst_new, dstW, dither, offset);
168
169
3/4
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 180 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 240 times.
240 if (cmp_off_by_n_8(dst_ref, dst_new, dstW, accurate ? 0 : 2)) {
170 fail();
171 printf("failed: yuv2yuv1_%d_%di_%s\n", offset, dstW, accurate_str);
172 fail_offset = show_differences_8(dst_ref, dst_new, dstW);
173 printf("failing values: src: 0x%04x dither: 0x%02x dst-c: %02x dst-asm: %02x\n",
174 (int) src_pixels[fail_offset],
175 (int) dither[(fail_offset + offset) & 7],
176 (int) dst_ref[fail_offset],
177 (int) dst_new[fail_offset]);
178 }
179
180 /* The guard regions on either side of the output window must
181 * remain identical between the reference and the tested
182 * implementation from the project-wide 16-byte alignment above
183 * dstW, the longest whole-vector write any current yuv2plane1
184 * may make: x86 sse2/avx store a 16-byte XMM per iteration
185 * and do not round down the tail, so the legal output window
186 * is dstW rounded up to 16, while LoongArch lsx/lasx write
187 * exactly dstW bytes. */
188 240 const int guard_off = (dstW + 15) & ~15;
189
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if (memcmp(dst0, dst1, DEST_GUARD) ||
190 240 memcmp(dst_ref + guard_off, dst_new + guard_off,
191
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 240 times.
240 DEST_SIZE - DEST_GUARD - guard_off)) {
192 fail();
193 printf("failed: yuv2yuv1_%d_%d_%s wrote outside destination\n",
194 offset, dstW, accurate_str);
195 }
196
197
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 216 times.
240 if (dstW == LARGEST_INPUT_SIZE)
198
1/18
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
24 bench_new(src_pixels, dst_new, dstW, dither, offset);
199 }
200 }
201 }
202 28 sws_freeContext(sws);
203 28 }
204
205 252 static void check_yuv2yuvX(int accurate, int bit_depth, int dst_pix_format)
206 {
207 SwsContext *sws;
208 SwsInternal *c;
209 int fsi, osi, isi, i, j;
210 int dstW;
211 #define LARGEST_FILTER 16
212 // ff_yuv2planeX_8_sse2 can't handle odd filter sizes
213 252 const int filter_sizes[] = {2, 4, 8, 16};
214 252 const int FILTER_SIZES = sizeof(filter_sizes)/sizeof(filter_sizes[0]);
215 #define LARGEST_INPUT_SIZE 512
216 static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
217
2/2
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 126 times.
252 const char *accurate_str = (accurate) ? "accurate" : "approximate";
218
219 252 declare_func(void, const int16_t *filter,
220 int filterSize, const int16_t **src, uint8_t *dest,
221 int dstW, const uint8_t *dither, int offset);
222
223 const int16_t **src;
224 252 LOCAL_ALIGNED_16(int16_t, src_pixels, [LARGEST_FILTER * LARGEST_INPUT_SIZE]);
225 252 LOCAL_ALIGNED_16(int16_t, filter_coeff, [LARGEST_FILTER]);
226 252 LOCAL_ALIGNED_16(uint16_t, dst0, [LARGEST_INPUT_SIZE]);
227 252 LOCAL_ALIGNED_16(uint16_t, dst1, [LARGEST_INPUT_SIZE]);
228 252 LOCAL_ALIGNED_16(uint8_t, dither, [LARGEST_INPUT_SIZE]);
229 union VFilterData{
230 const int16_t *src;
231 uint16_t coeff[8];
232 } *vFilterData;
233 252 uint8_t d_val = rnd();
234 252 memset(dither, d_val, LARGEST_INPUT_SIZE);
235
2/2
✓ Branch 1 taken 1032192 times.
✓ Branch 2 taken 252 times.
1032444 randomize_buffers((uint8_t*)src_pixels, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int16_t));
236 252 sws = sws_alloc_context();
237 252 sws->dst_format = dst_pix_format;
238
2/2
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 126 times.
252 if (accurate)
239 126 sws->flags |= SWS_ACCURATE_RND;
240
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 252 times.
252 if (sws_init_context(sws, NULL, NULL) < 0)
241 fail();
242
243 252 c = sws_internal(sws);
244 252 c->dstBpc = bit_depth;
245 252 ff_sws_init_scale(c);
246
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 252 times.
1764 for(isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); ++isi){
247 1512 dstW = input_sizes[isi];
248
2/2
✓ Branch 0 taken 6048 times.
✓ Branch 1 taken 1512 times.
7560 for(osi = 0; osi < 64; osi += 16){
249
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 4788 times.
6048 if (dstW <= osi)
250 1260 continue;
251
2/2
✓ Branch 0 taken 19152 times.
✓ Branch 1 taken 4788 times.
23940 for (fsi = 0; fsi < FILTER_SIZES; ++fsi) {
252 // Generate filter coefficients for the given filter size,
253 // with some properties:
254 // - The coefficients add up to the intended sum (4096, 1<<12)
255 // - The coefficients contain negative values
256 // - The filter intermediates don't overflow for worst case
257 // inputs (all positive coefficients are coupled with
258 // input_max and all negative coefficients with input_min,
259 // or vice versa).
260 // Produce a filter with all coefficients set to
261 // -((1<<12)/(filter_size-1)) except for one (randomly chosen)
262 // which is set to ((1<<13)-1).
263
2/2
✓ Branch 0 taken 143640 times.
✓ Branch 1 taken 19152 times.
162792 for (i = 0; i < filter_sizes[fsi]; ++i)
264 143640 filter_coeff[i] = -((1 << 12) / (filter_sizes[fsi] - 1));
265 19152 filter_coeff[rnd() % filter_sizes[fsi]] = (1 << 13) - 1;
266
267 19152 src = av_malloc(sizeof(int16_t*) * filter_sizes[fsi]);
268 19152 vFilterData = av_malloc((filter_sizes[fsi] + 2) * sizeof(union VFilterData));
269 19152 memset(vFilterData, 0, (filter_sizes[fsi] + 2) * sizeof(union VFilterData));
270
2/2
✓ Branch 0 taken 143640 times.
✓ Branch 1 taken 19152 times.
162792 for (i = 0; i < filter_sizes[fsi]; ++i) {
271 143640 src[i] = &src_pixels[i * LARGEST_INPUT_SIZE];
272 143640 vFilterData[i].src = src[i] - osi;
273
2/2
✓ Branch 0 taken 574560 times.
✓ Branch 1 taken 143640 times.
718200 for(j = 0; j < 4; ++j)
274 574560 vFilterData[i].coeff[j + 4] = filter_coeff[i];
275 }
276
6/6
✓ Branch 0 taken 17024 times.
✓ Branch 1 taken 2128 times.
✓ Branch 3 taken 8512 times.
✓ Branch 4 taken 8512 times.
✓ Branch 6 taken 2736 times.
✓ Branch 7 taken 16416 times.
19152 if (check_func(c->yuv2planeX, "yuv2yuvX_%d%s_%d_%d_%d_%s", bit_depth, (bit_depth == 8) ? "" : (isBE(dst_pix_format) ? "BE" : "LE"), filter_sizes[fsi], osi, dstW, accurate_str)) {
277 // use vFilterData for the mmx function
278
2/2
✓ Branch 0 taken 228 times.
✓ Branch 1 taken 2508 times.
2736 const int16_t *filter = c->use_mmx_vfilter ? (const int16_t*)vFilterData : &filter_coeff[0];
279 2736 memset(dst0, 0, LARGEST_INPUT_SIZE * sizeof(dst0[0]));
280 2736 memset(dst1, 0, LARGEST_INPUT_SIZE * sizeof(dst1[0]));
281
282
2/2
✓ Branch 0 taken 608 times.
✓ Branch 1 taken 2128 times.
2736 if (c->dstBpc == 8) {
283 // We can't use call_ref here, because we don't know if use_mmx_vfilter was set for that
284 // function or not, so we can't pass it the parameters correctly.
285
286 608 yuv2planeX_8_ref(&filter_coeff[0], filter_sizes[fsi], src, (uint8_t*)dst0, dstW - osi, dither, osi);
287 608 call_new(filter, filter_sizes[fsi], src, (uint8_t*)dst1, dstW - osi, dither, osi);
288
289
3/4
✓ Branch 0 taken 304 times.
✓ Branch 1 taken 304 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 608 times.
608 if (cmp_off_by_n_8((uint8_t*)dst0, (uint8_t*)dst1, LARGEST_INPUT_SIZE, accurate ? 0 : 2)) {
290 fail();
291 printf("failed: yuv2yuvX_%d_%d_%d_%d_%s\n", bit_depth, filter_sizes[fsi], osi, dstW, accurate_str);
292 show_differences_8((uint8_t*)dst0, (uint8_t*)dst1, LARGEST_INPUT_SIZE);
293 }
294 } else {
295
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 2128 times.
2128 call_ref(&filter_coeff[0], filter_sizes[fsi], src, (uint8_t*)dst0, dstW - osi, dither, osi);
296 2128 call_new(&filter_coeff[0], filter_sizes[fsi], src, (uint8_t*)dst1, dstW - osi, dither, osi);
297
298
3/4
✓ Branch 0 taken 1064 times.
✓ Branch 1 taken 1064 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2128 times.
2128 if (cmp_off_by_n_16(dst0, dst1, LARGEST_INPUT_SIZE, accurate ? 0 : 2)) {
299 fail();
300 printf("failed: yuv2yuvX_%d%s_%d_%d_%d_%s\n", bit_depth, isBE(dst_pix_format) ? "BE" : "LE", filter_sizes[fsi], osi, dstW, accurate_str);
301 show_differences_16(dst0, dst1, LARGEST_INPUT_SIZE);
302 }
303 }
304
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 2160 times.
2736 if (dstW == LARGEST_INPUT_SIZE)
305
1/18
✗ Branch 1 not taken.
✓ Branch 2 taken 576 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
576 bench_new(filter, filter_sizes[fsi], src, (uint8_t*)dst1, dstW - osi, dither, osi);
306
307 }
308 19152 av_freep(&src);
309 19152 av_freep(&vFilterData);
310 }
311 }
312 }
313 252 sws_freeContext(sws);
314 #undef FILTER_SIZES
315 252 }
316
317 28 static void check_yuv2nv12cX(int accurate)
318 {
319 SwsContext *sws;
320 SwsInternal *c;
321 #define LARGEST_FILTER 16
322 28 const int filter_sizes[] = {2, 4, 8, 16};
323 #define LARGEST_INPUT_SIZE 512
324 static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
325
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 14 times.
28 const char *accurate_str = (accurate) ? "accurate" : "approximate";
326
327 28 declare_func(void, enum AVPixelFormat dstFormat,
328 const uint8_t *chrDither, const int16_t *chrFilter,
329 int chrFilterSize, const int16_t **chrUSrc,
330 const int16_t **chrVSrc, uint8_t *dest, int dstW);
331
332 const int16_t *srcU[LARGEST_FILTER], *srcV[LARGEST_FILTER];
333 28 LOCAL_ALIGNED_16(int16_t, srcU_pixels, [LARGEST_FILTER * LARGEST_INPUT_SIZE]);
334 28 LOCAL_ALIGNED_16(int16_t, srcV_pixels, [LARGEST_FILTER * LARGEST_INPUT_SIZE]);
335 28 LOCAL_ALIGNED_16(int16_t, filter_coeff, [LARGEST_FILTER]);
336 28 LOCAL_ALIGNED_16(uint8_t, dst0, [LARGEST_INPUT_SIZE * 2]);
337 28 LOCAL_ALIGNED_16(uint8_t, dst1, [LARGEST_INPUT_SIZE * 2]);
338 28 LOCAL_ALIGNED_16(uint8_t, dither, [LARGEST_INPUT_SIZE]);
339 28 uint8_t d_val = rnd();
340 28 memset(dither, d_val, LARGEST_INPUT_SIZE);
341
2/2
✓ Branch 1 taken 114688 times.
✓ Branch 2 taken 28 times.
114716 randomize_buffers((uint8_t*)srcU_pixels, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int16_t));
342
2/2
✓ Branch 1 taken 114688 times.
✓ Branch 2 taken 28 times.
114716 randomize_buffers((uint8_t*)srcV_pixels, LARGEST_FILTER * LARGEST_INPUT_SIZE * sizeof(int16_t));
343
2/2
✓ Branch 0 taken 448 times.
✓ Branch 1 taken 28 times.
476 for (int i = 0; i < LARGEST_FILTER; i++) {
344 448 srcU[i] = &srcU_pixels[i * LARGEST_INPUT_SIZE];
345 448 srcV[i] = &srcV_pixels[i * LARGEST_INPUT_SIZE];
346 }
347
348 28 sws = sws_alloc_context();
349 28 sws->dst_format = AV_PIX_FMT_NV12;
350
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 14 times.
28 if (accurate)
351 14 sws->flags |= SWS_ACCURATE_RND;
352
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
28 if (sws_init_context(sws, NULL, NULL) < 0)
353 fail();
354
355 28 c = sws_internal(sws);
356 28 ff_sws_init_scale(c);
357
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 28 times.
196 for (int isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); isi++){
358 168 const int dstW = input_sizes[isi];
359
2/2
✓ Branch 0 taken 672 times.
✓ Branch 1 taken 168 times.
840 for (int fsi = 0; fsi < FF_ARRAY_ELEMS(filter_sizes); fsi++) {
360 672 const int filter_size = filter_sizes[fsi];
361
2/2
✓ Branch 0 taken 5040 times.
✓ Branch 1 taken 672 times.
5712 for (int i = 0; i < filter_size; i++)
362 5040 filter_coeff[i] = -((1 << 12) / (filter_size - 1));
363 672 filter_coeff[rnd() % filter_size] = (1 << 13) - 1;
364
365
2/2
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 600 times.
672 if (check_func(c->yuv2nv12cX, "yuv2nv12cX_%d_%d_%s", filter_size, dstW, accurate_str)){
366 72 memset(dst0, 0, LARGEST_INPUT_SIZE * sizeof(dst0[0]));
367 72 memset(dst1, 0, LARGEST_INPUT_SIZE * sizeof(dst1[0]));
368
369
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 72 times.
72 call_ref(sws->dst_format, dither, &filter_coeff[0], filter_size, srcU, srcV, dst0, dstW);
370 72 call_new(sws->dst_format, dither, &filter_coeff[0], filter_size, srcU, srcV, dst1, dstW);
371
372
3/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 72 times.
72 if (cmp_off_by_n_8(dst0, dst1, dstW * 2 * sizeof(dst0[0]), accurate ? 0 : 2)) {
373 fail();
374 printf("failed: yuv2nv12wX_%d_%d_%s\n", filter_size, dstW, accurate_str);
375 show_differences_8(dst0, dst1, dstW * 2 * sizeof(dst0[0]));
376 }
377
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 60 times.
72 if (dstW == LARGEST_INPUT_SIZE)
378
1/18
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
12 bench_new(sws->dst_format, dither, &filter_coeff[0], filter_size, srcU, srcV, dst1, dstW);
379
380 }
381 }
382 }
383 28 sws_freeContext(sws);
384 28 }
385 #undef LARGEST_FILTER
386 #undef LARGEST_INPUT_SIZE
387
388 #undef SRC_PIXELS
389 #define SRC_PIXELS 512
390
391 14 static void check_hscale(void)
392 {
393 #define MAX_FILTER_WIDTH 40
394 #define FILTER_SIZES 6
395 static const int filter_sizes[FILTER_SIZES] = { 4, 8, 12, 16, 32, 40 };
396
397 #define HSCALE_PAIRS 2
398 static const int hscale_pairs[HSCALE_PAIRS][2] = {
399 { 8, 14 },
400 { 8, 18 },
401 };
402
403 #define LARGEST_INPUT_SIZE 512
404 static const int input_sizes[] = {8, 24, 128, 144, 256, 512};
405
406 int i, j, fsi, hpi, width, dstWi;
407 SwsContext *sws;
408 SwsInternal *c;
409
410 // padded
411 14 LOCAL_ALIGNED_32(uint8_t, src, [FFALIGN(SRC_PIXELS + MAX_FILTER_WIDTH - 1, 4)]);
412 14 LOCAL_ALIGNED_32(uint32_t, dst0, [SRC_PIXELS]);
413 14 LOCAL_ALIGNED_32(uint32_t, dst1, [SRC_PIXELS]);
414
415 // padded
416 14 LOCAL_ALIGNED_32(int16_t, filter, [SRC_PIXELS * MAX_FILTER_WIDTH + MAX_FILTER_WIDTH]);
417 14 LOCAL_ALIGNED_32(int32_t, filterPos, [SRC_PIXELS]);
418 14 LOCAL_ALIGNED_32(int16_t, filterAvx2, [SRC_PIXELS * MAX_FILTER_WIDTH + MAX_FILTER_WIDTH]);
419 14 LOCAL_ALIGNED_32(int32_t, filterPosAvx, [SRC_PIXELS]);
420
421 // The dst parameter here is either int16_t or int32_t but we use void* to
422 // just cover both cases.
423 14 declare_func(void, SwsInternal *c, int16_t *dst, int dstW,
424 const uint8_t *src, const int16_t *filter,
425 const int32_t *filterPos, int filterSize);
426
427 14 sws = sws_alloc_context();
428
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
14 if (sws_init_context(sws, NULL, NULL) < 0)
429 fail();
430
431 14 c = sws_internal(sws);
432
2/2
✓ Branch 1 taken 1932 times.
✓ Branch 2 taken 14 times.
1946 randomize_buffers(src, SRC_PIXELS + MAX_FILTER_WIDTH - 1);
433
434
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 14 times.
42 for (hpi = 0; hpi < HSCALE_PAIRS; hpi++) {
435
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 28 times.
196 for (fsi = 0; fsi < FILTER_SIZES; fsi++) {
436
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 168 times.
1176 for (dstWi = 0; dstWi < FF_ARRAY_ELEMS(input_sizes); dstWi++) {
437 1008 width = filter_sizes[fsi];
438
439 1008 c->srcBpc = hscale_pairs[hpi][0];
440 1008 c->dstBpc = hscale_pairs[hpi][1];
441 1008 c->hLumFilterSize = c->hChrFilterSize = width;
442
443
2/2
✓ Branch 0 taken 516096 times.
✓ Branch 1 taken 1008 times.
517104 for (i = 0; i < SRC_PIXELS; i++) {
444 516096 filterPos[i] = i;
445 516096 filterPosAvx[i] = i;
446
447 // These filter coefficients are chosen to try break two corner
448 // cases, namely:
449 //
450 // - Negative filter coefficients. The filters output signed
451 // values, and it should be possible to end up with negative
452 // output values.
453 //
454 // - Positive clipping. The hscale filter function has clipping
455 // at (1<<15) - 1
456 //
457 // The coefficients sum to the 1.0 point for the hscale
458 // functions (1 << 14).
459
460
2/2
✓ Branch 0 taken 9633792 times.
✓ Branch 1 taken 516096 times.
10149888 for (j = 0; j < width; j++) {
461 9633792 filter[i * width + j] = -((1 << 14) / (width - 1));
462 }
463 516096 filter[i * width + (rnd() % width)] = ((1 << 15) - 1);
464 }
465
466
2/2
✓ Branch 0 taken 40320 times.
✓ Branch 1 taken 1008 times.
41328 for (i = 0; i < MAX_FILTER_WIDTH; i++) {
467 // These values should be unused in SIMD implementations but
468 // may still be read, random coefficients here should help show
469 // issues where they are used in error.
470
471 40320 filter[SRC_PIXELS * width + i] = rnd();
472 }
473 1008 sws->dst_w = c->chrDstW = input_sizes[dstWi];
474 1008 ff_sws_init_scale(c);
475 1008 memcpy(filterAvx2, filter, sizeof(uint16_t) * (SRC_PIXELS * MAX_FILTER_WIDTH + MAX_FILTER_WIDTH));
476 1008 ff_shuffle_filter_coefficients(c, filterPosAvx, width, filterAvx2, sws->dst_w);
477
478
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1008 times.
1008 av_assert0(c->hyScale == c->hcScale);
479
2/2
✓ Branch 1 taken 252 times.
✓ Branch 2 taken 756 times.
1008 if (check_func(c->hcScale, "hscale_%d_to_%d__fs_%d_dstW_%d", c->srcBpc, c->dstBpc + 1, width, sws->dst_w)) {
480 252 memset(dst0, 0, SRC_PIXELS * sizeof(dst0[0]));
481 252 memset(dst1, 0, SRC_PIXELS * sizeof(dst1[0]));
482
483
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 252 times.
252 call_ref(NULL, (int16_t *)dst0, sws->dst_w, src, filter, filterPos, width);
484 252 call_new(NULL, (int16_t *)dst1, sws->dst_w, src, filterAvx2, filterPosAvx, width);
485
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if (memcmp(dst0, dst1, sws->dst_w * sizeof(dst0[0])))
486 fail();
487
1/18
✗ Branch 1 not taken.
✓ Branch 2 taken 252 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
252 bench_new(NULL, (int16_t *)dst0, sws->dst_w, src, filter, filterPosAvx, width);
488 }
489 }
490 }
491 }
492 14 sws_freeContext(sws);
493 14 }
494
495 14 void checkasm_check_sw_scale(void)
496 {
497 14 check_hscale();
498 14 report("hscale");
499 14 check_yuv2yuv1(0);
500 14 check_yuv2yuv1(1);
501 14 report("yuv2yuv1");
502 14 check_yuv2yuvX(0, 8, AV_PIX_FMT_YUV420P);
503 14 check_yuv2yuvX(1, 8, AV_PIX_FMT_YUV420P);
504 14 report("yuv2yuvX_8");
505 14 check_yuv2yuvX(0, 9, AV_PIX_FMT_YUV420P9LE);
506 14 check_yuv2yuvX(1, 9, AV_PIX_FMT_YUV420P9LE);
507 14 report("yuv2yuvX_9LE");
508 14 check_yuv2yuvX(0, 9, AV_PIX_FMT_YUV420P9BE);
509 14 check_yuv2yuvX(1, 9, AV_PIX_FMT_YUV420P9BE);
510 14 report("yuv2yuvX_9BE");
511 14 check_yuv2yuvX(0, 10, AV_PIX_FMT_YUV420P10LE);
512 14 check_yuv2yuvX(1, 10, AV_PIX_FMT_YUV420P10LE);
513 14 report("yuv2yuvX_10LE");
514 14 check_yuv2yuvX(0, 10, AV_PIX_FMT_YUV420P10BE);
515 14 check_yuv2yuvX(1, 10, AV_PIX_FMT_YUV420P10BE);
516 14 report("yuv2yuvX_10BE");
517 14 check_yuv2yuvX(0, 12, AV_PIX_FMT_YUV420P12LE);
518 14 check_yuv2yuvX(1, 12, AV_PIX_FMT_YUV420P12LE);
519 14 report("yuv2yuvX_12LE");
520 14 check_yuv2yuvX(0, 12, AV_PIX_FMT_YUV420P12BE);
521 14 check_yuv2yuvX(1, 12, AV_PIX_FMT_YUV420P12BE);
522 14 report("yuv2yuvX_12BE");
523 14 check_yuv2yuvX(0, 14, AV_PIX_FMT_YUV420P14LE);
524 14 check_yuv2yuvX(1, 14, AV_PIX_FMT_YUV420P14LE);
525 14 report("yuv2yuvX_14LE");
526 14 check_yuv2yuvX(0, 14, AV_PIX_FMT_YUV420P14BE);
527 14 check_yuv2yuvX(1, 14, AV_PIX_FMT_YUV420P14BE);
528 14 report("yuv2yuvX_14BE");
529 14 check_yuv2nv12cX(0);
530 14 check_yuv2nv12cX(1);
531 14 report("yuv2nv12cX");
532 14 }
533