avutil/pixelutils: avoid on stack arrays

The arrays are fairly large and could cause problems on some embedded systems
also they are not endian safe as they mix 32 and 8bit

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2014-08-06 01:27:38 +02:00
parent 1b168e3bcf
commit 84ac2f93ca
2 changed files with 30 additions and 26 deletions

View File

@ -92,13 +92,13 @@ av_pixelutils_sad_fn av_pixelutils_get_sad_fn(int w_bits, int h_bits, int aligne
#define H2 480 #define H2 480
static int run_test(const char *test, static int run_test(const char *test,
const uint32_t *b1, const uint32_t *b2) const uint8_t *b1, const uint8_t *b2)
{ {
int i, a, ret = 0; int i, a, ret = 0;
for (a = 0; a < 3; a++) { for (a = 0; a < 3; a++) {
const uint8_t *block1 = (const uint8_t *)b1; const uint8_t *block1 = b1;
const uint8_t *block2 = (const uint8_t *)b2; const uint8_t *block2 = b2;
switch (a) { switch (a) {
case 0: block1++; block2++; break; case 0: block1++; block2++; break;
@ -124,30 +124,34 @@ static int run_test(const char *test,
int main(void) int main(void)
{ {
int i, ret; int i, ret;
DECLARE_ALIGNED(32, uint32_t, buf1)[W1*H1]; uint8_t *buf1 = av_malloc(W1*H1);
DECLARE_ALIGNED(32, uint32_t, buf2)[W2*H2]; uint8_t *buf2 = av_malloc(W2*H2);
uint32_t state = 0; uint32_t state = 0;
for (i = 0; i < W1*H1; i++) { for (i = 0; i < W1*H1; i++) {
state = state * 1664525 + 1013904223; state = state * 1664525 + 1013904223;
buf1[i] = state; buf1[i] = state>>24;
} }
for (i = 0; i < W2*H2; i++) { for (i = 0; i < W2*H2; i++) {
state = state * 1664525 + 1013904223; state = state * 1664525 + 1013904223;
buf2[i] = state; buf2[i] = state>>24;
} }
ret = run_test("random", buf1, buf2); ret = run_test("random", buf1, buf2);
if (ret < 0) if (ret < 0)
return ret; goto end;
memset(buf1, 0xff, sizeof(buf1)); memset(buf1, 0xff, W1*H1);
memset(buf2, 0x00, sizeof(buf2)); memset(buf2, 0x00, W2*H2);
ret = run_test("max", buf1, buf2); ret = run_test("max", buf1, buf2);
if (ret < 0) if (ret < 0)
return ret; goto end;
memset(buf1, 0x90, sizeof(buf1)); memset(buf1, 0x90, W1*H1);
memset(buf2, 0x90, sizeof(buf2)); memset(buf2, 0x90, W2*H2);
return run_test("min", buf1, buf2); ret = run_test("min", buf1, buf2);
end:
av_free(buf1);
av_free(buf2);
return ret;
} }
#endif /* TEST */ #endif /* TEST */

View File

@ -1,15 +1,15 @@
[OK] [UU] SAD [random] 2x2=314 ref=314 [OK] [UU] SAD [random] 2x2=409 ref=409
[OK] [UU] SAD [random] 4x4=1129 ref=1129 [OK] [UU] SAD [random] 4x4=1370 ref=1370
[OK] [UU] SAD [random] 8x8=4936 ref=4936 [OK] [UU] SAD [random] 8x8=5178 ref=5178
[OK] [UU] SAD [random] 16x16=20704 ref=20704 [OK] [UU] SAD [random] 16x16=20946 ref=20946
[OK] [AU] SAD [random] 2x2=440 ref=440 [OK] [AU] SAD [random] 2x2=320 ref=320
[OK] [AU] SAD [random] 4x4=1317 ref=1317 [OK] [AU] SAD [random] 4x4=1522 ref=1522
[OK] [AU] SAD [random] 8x8=5262 ref=5262 [OK] [AU] SAD [random] 8x8=5821 ref=5821
[OK] [AU] SAD [random] 16x16=21040 ref=21040 [OK] [AU] SAD [random] 16x16=21951 ref=21951
[OK] [AA] SAD [random] 2x2=196 ref=196 [OK] [AA] SAD [random] 2x2=276 ref=276
[OK] [AA] SAD [random] 4x4=1225 ref=1225 [OK] [AA] SAD [random] 4x4=1521 ref=1521
[OK] [AA] SAD [random] 8x8=4712 ref=4712 [OK] [AA] SAD [random] 8x8=5130 ref=5130
[OK] [AA] SAD [random] 16x16=21184 ref=21184 [OK] [AA] SAD [random] 16x16=20775 ref=20775
[OK] [UU] SAD [max] 2x2=1020 ref=1020 [OK] [UU] SAD [max] 2x2=1020 ref=1020
[OK] [UU] SAD [max] 4x4=4080 ref=4080 [OK] [UU] SAD [max] 4x4=4080 ref=4080
[OK] [UU] SAD [max] 8x8=16320 ref=16320 [OK] [UU] SAD [max] 8x8=16320 ref=16320