summaryrefslogtreecommitdiff
path: root/src/fft2d/fft2d/sample2d/shrtdctt.c
blob: 70d665f1d8d570a80e04cfca45e17cf26ba3f483 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* test of shrtdct.c */

#include <math.h>
#include <stdio.h>
#define MAX(x,y) ((x) > (y) ? (x) : (y))

/* random number generator, 0 <= RND < 1 */
#define RND(p) ((*(p) = (*(p) * 7141 + 54773) % 259200) * (1.0 / 259200))

#define NMAX 16

int main()
{
    void ddct8x8s(int isgn, double **a);
    void ddct16x16s(int isgn, double **a);
    void putdata2d(int n1, int n2, double **a);
    double errorcheck2d(int n1, int n2, double scale, double **a);
    double err;
    
    int i;
    double aarr[NMAX][NMAX], *a[NMAX], barr[NMAX][NMAX], *b[NMAX];
    for (i = 0; i < NMAX; i++) a[i] = aarr[i];
    for (i = 0; i < NMAX; i++) b[i] = barr[i];

    /* check of 8x8 DCT */
    putdata2d(8, 8, a);
    ddct8x8s(-1, a);
    ddct8x8s(1, a);
    err = errorcheck2d(8, 8, 1.0, a);
    printf("ddct8x8s   err= %g\n", err);

    /* check of 16x16 DCT */
    putdata2d(16, 16, a);
    ddct16x16s(-1, a);
    ddct16x16s(1, a);
    err = errorcheck2d(16, 16, 1.0, a);
    printf("ddct16x16s err= %g\n", err);

    return 0;
}


void putdata2d(int n1, int n2, double **a)
{
    int j1, j2, seed = 0;

    for (j1 = 0; j1 <= n1 - 1; j1++) {
        for (j2 = 0; j2 <= n2 - 1; j2++) {
            a[j1][j2] = RND(&seed);
        }
    }
}


double errorcheck2d(int n1, int n2, double scale, double **a)
{
    int j1, j2, seed = 0;
    double err = 0, e;

    for (j1 = 0; j1 <= n1 - 1; j1++) {
        for (j2 = 0; j2 <= n2 - 1; j2++) {
            e = RND(&seed) - a[j1][j2] * scale;
            err = MAX(err, fabs(e));
        }
    }
    return err;
}