comparison dct-test.c @ 0:986e461dc072 libavcodec

Initial revision
author glantau
date Sun, 22 Jul 2001 14:18:56 +0000
parents
children 7cf705a32d1c
comparison
equal deleted inserted replaced
-1:000000000000 0:986e461dc072
1 /* DCT test. (c) 2001 Gerard Lantau.
2 Started from sample code by Juan J. Sierralta P.
3 */
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <sys/time.h>
8 #include <unistd.h>
9
10 #include "dsputil.h"
11
12 extern void fdct(DCTELEM *block);
13 extern void init_fdct();
14
15 #define AANSCALE_BITS 12
16 static const unsigned short aanscales[64] = {
17 /* precomputed values scaled up by 14 bits */
18 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
19 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
20 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
21 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
22 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
23 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
24 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
25 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
26 };
27
28 INT64 gettime(void)
29 {
30 struct timeval tv;
31 gettimeofday(&tv,NULL);
32 return (INT64)tv.tv_sec * 1000000 + tv.tv_usec;
33 }
34
35 #define NB_ITS 20000
36 #define NB_ITS_SPEED 50000
37
38 void dct_error(const char *name,
39 void (*fdct_func)(DCTELEM *block))
40 {
41 int it, i, scale;
42 DCTELEM block[64], block1[64];
43 int err_inf, v;
44 INT64 err2, ti, ti1, it1;
45
46 srandom(0);
47
48 err_inf = 0;
49 err2 = 0;
50 for(it=0;it<NB_ITS;it++) {
51 for(i=0;i<64;i++)
52 block1[i] = random() % 256;
53 memcpy(block, block1, sizeof(DCTELEM) * 64);
54
55 fdct_func(block);
56 if (fdct_func == jpeg_fdct_ifast) {
57 for(i=0; i<64; i++) {
58 scale = (1 << (AANSCALE_BITS + 11)) / aanscales[i];
59 block[i] = (block[i] * scale) >> AANSCALE_BITS;
60 }
61 }
62
63 fdct(block1);
64
65 for(i=0;i<64;i++) {
66 v = abs(block[i] - block1[i]);
67 if (v > err_inf)
68 err_inf = v;
69 err2 += v * v;
70 }
71 }
72 printf("DCT %s: err_inf=%d err2=%0.2f\n",
73 name, err_inf, (double)err2 / NB_ITS / 64.0);
74
75 /* speed test */
76 for(i=0;i<64;i++)
77 block1[i] = 255 - 63 + i;
78
79 ti = gettime();
80 it1 = 0;
81 do {
82 for(it=0;it<NB_ITS_SPEED;it++) {
83 memcpy(block, block1, sizeof(DCTELEM) * 64);
84 fdct_func(block);
85 }
86 it1 += NB_ITS_SPEED;
87 ti1 = gettime() - ti;
88 } while (ti1 < 1000000);
89
90 printf("DCT %s: %0.1f kdct/s\n",
91 name, (double)it1 * 1000.0 / (double)ti1);
92 }
93
94 int main(int argc, char **argv)
95 {
96 init_fdct();
97
98 printf("ffmpeg DCT test\n");
99
100 dct_error("REF", fdct); /* only to verify code ! */
101 dct_error("AAN", jpeg_fdct_ifast);
102 dct_error("MMX", fdct_mmx);
103 return 0;
104 }
105