avutil/pixelutils: add small buffers tests

This commit is contained in:
Clément Bœsch 2014-08-31 17:11:22 +02:00
parent 6abeaf2781
commit e6b125e3be
2 changed files with 87 additions and 19 deletions

View File

@ -91,6 +91,30 @@ av_pixelutils_sad_fn av_pixelutils_get_sad_fn(int w_bits, int h_bits, int aligne
#define W2 640
#define H2 480
static int run_single_test(const char *test,
const uint8_t *block1, ptrdiff_t stride1,
const uint8_t *block2, ptrdiff_t stride2,
int align, int n)
{
int out, ref;
av_pixelutils_sad_fn f_ref = sad_c[n - 1];
av_pixelutils_sad_fn f_out = av_pixelutils_get_sad_fn(n, n, align, NULL);
switch (align) {
case 0: block1++; block2++; break;
case 1: block2++; break;
case 2: break;
}
out = f_out(block1, stride1, block2, stride2);
ref = f_ref(block1, stride1, block2, stride2);
printf("[%s] [%c%c] SAD [%s] %dx%d=%d ref=%d\n",
out == ref ? "OK" : "FAIL",
align ? 'A' : 'U', align == 2 ? 'A' : 'U',
test, 1<<n, 1<<n, out, ref);
return out != ref;
}
static int run_test(const char *test,
const uint8_t *b1, const uint8_t *b2)
{
@ -106,16 +130,9 @@ static int run_test(const char *test,
case 2: break;
}
for (i = 1; i <= FF_ARRAY_ELEMS(sad_c); i++) {
av_pixelutils_sad_fn f_ref = sad_c[i - 1];
av_pixelutils_sad_fn f_out = av_pixelutils_get_sad_fn(i, i, a, NULL);
const int out = f_out(block1, W1, block2, W2);
const int ref = f_ref(block1, W1, block2, W2);
printf("[%s] [%c%c] SAD [%s] %dx%d=%d ref=%d\n",
out == ref ? "OK" : "FAIL",
a ? 'A' : 'U', a == 2 ? 'A' : 'U',
test, 1<<i, 1<<i, out, ref);
if (out != ref)
ret = 1;
int r = run_single_test(test, b1, W1, b2, W2, a, i);
if (r)
ret = r;
}
}
return ret;
@ -123,7 +140,7 @@ static int run_test(const char *test,
int main(void)
{
int i, ret;
int i, align, ret;
uint8_t *buf1 = av_malloc(W1*H1);
uint8_t *buf2 = av_malloc(W2*H2);
uint32_t state = 0;
@ -134,27 +151,66 @@ int main(void)
goto end;
}
for (i = 0; i < W1*H1; i++) {
state = state * 1664525 + 1013904223;
buf1[i] = state>>24;
}
for (i = 0; i < W2*H2; i++) {
state = state * 1664525 + 1013904223;
buf2[i] = state>>24;
}
#define RANDOM_INIT(buf, size) do { \
int k; \
for (k = 0; k < size; k++) { \
state = state * 1664525 + 1013904223; \
buf[k] = state>>24; \
} \
} while (0)
/* Normal test with different strides */
RANDOM_INIT(buf1, W1*H1);
RANDOM_INIT(buf2, W2*H2);
ret = run_test("random", buf1, buf2);
if (ret < 0)
goto end;
/* Check for maximum SAD */
memset(buf1, 0xff, W1*H1);
memset(buf2, 0x00, W2*H2);
ret = run_test("max", buf1, buf2);
if (ret < 0)
goto end;
/* Check for minimum SAD */
memset(buf1, 0x90, W1*H1);
memset(buf2, 0x90, W2*H2);
ret = run_test("min", buf1, buf2);
if (ret < 0)
goto end;
/* Exact buffer sizes, to check for overreads */
for (i = 1; i <= 4; i++) {
for (align = 0; align < 3; align++) {
int size1, size2;
av_freep(&buf1);
av_freep(&buf2);
size1 = size2 = 1 << (i << 1);
switch (align) {
case 0: size1++; size2++; break;
case 1: size2++; break;
case 2: break;
}
buf1 = av_malloc(size1);
buf2 = av_malloc(size2);
if (!buf1 || !buf2) {
fprintf(stderr, "malloc failure\n");
ret = 1;
goto end;
}
RANDOM_INIT(buf1, size1);
RANDOM_INIT(buf2, size2);
ret = run_single_test("small", buf1, 1<<i, buf2, 1<<i, align, i);
if (ret < 0)
goto end;
}
}
end:
av_free(buf1);
av_free(buf2);

View File

@ -34,3 +34,15 @@
[OK] [AA] SAD [min] 4x4=0 ref=0
[OK] [AA] SAD [min] 8x8=0 ref=0
[OK] [AA] SAD [min] 16x16=0 ref=0
[OK] [UU] SAD [small] 2x2=400 ref=400
[OK] [AU] SAD [small] 2x2=384 ref=384
[OK] [AA] SAD [small] 2x2=409 ref=409
[OK] [UU] SAD [small] 4x4=1144 ref=1144
[OK] [AU] SAD [small] 4x4=1156 ref=1156
[OK] [AA] SAD [small] 4x4=1086 ref=1086
[OK] [UU] SAD [small] 8x8=6510 ref=6510
[OK] [AU] SAD [small] 8x8=5755 ref=5755
[OK] [AA] SAD [small] 8x8=6156 ref=6156
[OK] [UU] SAD [small] 16x16=19490 ref=19490
[OK] [AU] SAD [small] 16x16=21037 ref=21037
[OK] [AA] SAD [small] 16x16=22986 ref=22986