summaryrefslogtreecommitdiff
path: root/appl/wm/mpeg/refidct.b
blob: e02ab1f76db4ea7b74b726a10f3e26b4a56f0ce8 (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
implement IDCT;

include "sys.m";
include "math.m";
include "mpegio.m";

sys: Sys;
math: Math;

#
#	Reference IDCT.  Full expanded 2-d IDCT.
#

coeff: array of array of real;

init()
{
	sys = load Sys Sys->PATH;
	math = load Math Math->PATH;
	if (math == nil) {
		sys->fprint(sys->fildes(2), "could not load %s: %r\n", Math->PATH);
		exit;
	}
	init_idct();
}

init_idct()
{
	coeff = array[8] of array of real;
	for (f := 0; f < 8; f++) {
		coeff[f] = array[8] of real;
		s := 0.5;
		if (f == 0)
			s = math->sqrt(0.125);
		a := real f * (Math->Pi / 8.0);
		for (t := 0; t < 8; t++) 
			coeff[f][t] = s * math->cos(a * (real t + 0.5));
	}
}

idct(block: array of int)
{
	tmp := array[64] of real;
	for (i := 0; i < 8; i++)
		for (j := 0; j < 8; j++) {
			p := 0.0;
			for (k := 0; k < 8; k++)
				p += coeff[k][j] * real block[8 * i + k];
			tmp[8 * i + j] = p;
		}
	for (j = 0; j < 8; j++)
		for (i = 0; i < 8; i++) {
			p := 0.0;
			for (k := 0; k < 8; k++)
				p += coeff[k][i] * tmp[8 * k + j];
			block[8 * i + j] = int p;
		}
}