28 const uint8_t *src2, ptrdiff_t stride2,
33 for (y = 0; y < h; y++) {
34 for (x = 0; x < w; x++)
35 sum += abs(src1[x] - src2[x]);
42 #define DECLARE_BLOCK_FUNCTIONS(size) \
43 static int block_sad_##size##x##size##_c(const uint8_t *src1, ptrdiff_t stride1, \
44 const uint8_t *src2, ptrdiff_t stride2) \
46 return sad_wxh(src1, stride1, src2, stride2, size, size); \
49 DECLARE_BLOCK_FUNCTIONS(2)
50 DECLARE_BLOCK_FUNCTIONS(4)
51 DECLARE_BLOCK_FUNCTIONS(8)
52 DECLARE_BLOCK_FUNCTIONS(16)
65 #if !CONFIG_PIXELUTILS
67 "but libavutil is not compiled with it\n");
72 memcpy(sad, sad_c,
sizeof(sad));
84 return sad[w_bits - 1];
94 static int run_single_test(
const char *
test,
96 const uint8_t *block2, ptrdiff_t stride2,
104 case 0: block1++; block2++;
break;
105 case 1: block2++;
break;
109 out = f_out(block1, stride1, block2, stride2);
110 ref = f_ref(block1, stride1, block2, stride2);
111 printf(
"[%s] [%c%c] SAD [%s] %dx%d=%d ref=%d\n",
112 out == ref ?
"OK" :
"FAIL",
113 align ?
'A' :
'U', align == 2 ?
'A' :
'U',
114 test, 1<<n, 1<<n, out, ref);
118 static int run_test(
const char *test,
123 for (a = 0; a < 3; a++) {
128 case 0: block1++; block2++;
break;
129 case 1: block2++;
break;
133 int r = run_single_test(test, b1,
W1, b2,
W2, a, i);
148 if (!buf1 || !buf2) {
149 fprintf(stderr,
"malloc failure\n");
154 #define RANDOM_INIT(buf, size) do { \
156 for (k = 0; k < size; k++) { \
157 state = state * 1664525 + 1013904223; \
158 buf[k] = state>>24; \
163 RANDOM_INIT(buf1,
W1*H1);
164 RANDOM_INIT(buf2,
W2*H2);
165 ret = run_test(
"random", buf1, buf2);
170 memset(buf1, 0xff,
W1*H1);
171 memset(buf2, 0x00,
W2*H2);
172 ret = run_test(
"max", buf1, buf2);
177 memset(buf1, 0x90,
W1*H1);
178 memset(buf2, 0x90,
W2*H2);
179 ret = run_test(
"min", buf1, buf2);
184 for (i = 1; i <= 4; i++) {
185 for (align = 0; align < 3; align++) {
191 size1 = size2 = 1 << (i << 1);
194 case 0: size1++; size2++;
break;
195 case 1: size2++;
break;
201 if (!buf1 || !buf2) {
202 fprintf(stderr,
"malloc failure\n");
206 RANDOM_INIT(buf1, size1);
207 RANDOM_INIT(buf2, size2);
208 ret = run_single_test(
"small", buf1, 1<<i, buf2, 1<<i, align, i);