2 * This file is part of FFmpeg.
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.
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.
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
19 #include "libavutil/pixelutils.c"
26 static int run_single_test(const char *test,
27 const uint8_t *block1, ptrdiff_t stride1,
28 const uint8_t *block2, ptrdiff_t stride2,
32 av_pixelutils_sad_fn f_ref = sad_c[n - 1];
33 av_pixelutils_sad_fn f_out = av_pixelutils_get_sad_fn(n, n, align, NULL);
36 case 0: block1++; block2++; break;
37 case 1: block2++; break;
41 out = f_out(block1, stride1, block2, stride2);
42 ref = f_ref(block1, stride1, block2, stride2);
43 printf("[%s] [%c%c] SAD [%s] %dx%d=%d ref=%d\n",
44 out == ref ? "OK" : "FAIL",
45 align ? 'A' : 'U', align == 2 ? 'A' : 'U',
46 test, 1<<n, 1<<n, out, ref);
50 static int run_test(const char *test,
51 const uint8_t *b1, const uint8_t *b2)
55 for (a = 0; a < 3; a++) {
56 const uint8_t *block1 = b1;
57 const uint8_t *block2 = b2;
60 case 0: block1++; block2++; break;
61 case 1: block2++; break;
64 for (i = 1; i <= FF_ARRAY_ELEMS(sad_c); i++) {
65 int r = run_single_test(test, b1, W1, b2, W2, a, i);
76 uint8_t *buf1 = av_malloc(W1*H1);
77 uint8_t *buf2 = av_malloc(W2*H2);
81 fprintf(stderr, "malloc failure\n");
86 ff_check_pixfmt_descriptors();
88 #define RANDOM_INIT(buf, size) do { \
90 for (k = 0; k < size; k++) { \
91 state = state * 1664525 + 1013904223; \
96 /* Normal test with different strides */
97 RANDOM_INIT(buf1, W1*H1);
98 RANDOM_INIT(buf2, W2*H2);
99 ret = run_test("random", buf1, buf2);
103 /* Check for maximum SAD */
104 memset(buf1, 0xff, W1*H1);
105 memset(buf2, 0x00, W2*H2);
106 ret = run_test("max", buf1, buf2);
110 /* Check for minimum SAD */
111 memset(buf1, 0x90, W1*H1);
112 memset(buf2, 0x90, W2*H2);
113 ret = run_test("min", buf1, buf2);
117 /* Exact buffer sizes, to check for overreads */
118 for (i = 1; i <= 5; i++) {
119 for (align = 0; align < 3; align++) {
125 size1 = size2 = 1 << (i << 1);
128 case 0: size1++; size2++; break;
129 case 1: size2++; break;
133 buf1 = av_malloc(size1);
134 buf2 = av_malloc(size2);
135 if (!buf1 || !buf2) {
136 fprintf(stderr, "malloc failure\n");
140 RANDOM_INIT(buf1, size1);
141 RANDOM_INIT(buf2, size2);
142 ret = run_single_test("small", buf1, 1<<i, buf2, 1<<i, align, i);