1 /* test of shrtdct.c */
2
3 #include <math.h>
4 #include <stdio.h>
5 #define MAX(x,y) ((x) > (y) ? (x) : (y))
6
7 /* random number generator, 0 <= RND < 1 */
8 #define RND(p) ((*(p) = (*(p) * 7141 + 54773) % 259200) * (1.0 / 259200))
9
10 #define NMAX 16
11
main()12 int main()
13 {
14 void ddct8x8s(int isgn, double **a);
15 void ddct16x16s(int isgn, double **a);
16 void putdata2d(int n1, int n2, double **a);
17 double errorcheck2d(int n1, int n2, double scale, double **a);
18 double err;
19
20 int i;
21 double aarr[NMAX][NMAX], *a[NMAX], barr[NMAX][NMAX], *b[NMAX];
22 for (i = 0; i < NMAX; i++) a[i] = aarr[i];
23 for (i = 0; i < NMAX; i++) b[i] = barr[i];
24
25 /* check of 8x8 DCT */
26 putdata2d(8, 8, a);
27 ddct8x8s(-1, a);
28 ddct8x8s(1, a);
29 err = errorcheck2d(8, 8, 1.0, a);
30 printf("ddct8x8s err= %g\n", err);
31
32 /* check of 16x16 DCT */
33 putdata2d(16, 16, a);
34 ddct16x16s(-1, a);
35 ddct16x16s(1, a);
36 err = errorcheck2d(16, 16, 1.0, a);
37 printf("ddct16x16s err= %g\n", err);
38
39 return 0;
40 }
41
42
putdata2d(int n1,int n2,double ** a)43 void putdata2d(int n1, int n2, double **a)
44 {
45 int j1, j2, seed = 0;
46
47 for (j1 = 0; j1 <= n1 - 1; j1++) {
48 for (j2 = 0; j2 <= n2 - 1; j2++) {
49 a[j1][j2] = RND(&seed);
50 }
51 }
52 }
53
54
errorcheck2d(int n1,int n2,double scale,double ** a)55 double errorcheck2d(int n1, int n2, double scale, double **a)
56 {
57 int j1, j2, seed = 0;
58 double err = 0, e;
59
60 for (j1 = 0; j1 <= n1 - 1; j1++) {
61 for (j2 = 0; j2 <= n2 - 1; j2++) {
62 e = RND(&seed) - a[j1][j2] * scale;
63 err = MAX(err, fabs(e));
64 }
65 }
66 return err;
67 }
68
69