blob: f59c2217501fb484e13ab1ce0a545a1147d67756 (
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
implement IDCT;
include "sys.m";
include "mpegio.m";
init()
{
}
# Scaled integer implementation.
# inverse two dimensional DCT, Chen-Wang algorithm
# (IEEE ASSP-32, pp. 803-816, Aug. 1984)
# 32-bit integer arithmetic (8 bit coefficients)
# 11 mults, 29 adds per DCT
#
# coefficients extended to 12 bit for IEEE1180-1990
# compliance
W1: con 2841; # 2048*sqrt(2)*cos(1*pi/16)
W2: con 2676; # 2048*sqrt(2)*cos(2*pi/16)
W3: con 2408; # 2048*sqrt(2)*cos(3*pi/16)
W5: con 1609; # 2048*sqrt(2)*cos(5*pi/16)
W6: con 1108; # 2048*sqrt(2)*cos(6*pi/16)
W7: con 565; # 2048*sqrt(2)*cos(7*pi/16)
W1pW7: con 3406; # W1+W7
W1mW7: con 2276; # W1-W7
W3pW5: con 4017; # W3+W5
W3mW5: con 799; # W3-W5
W2pW6: con 3784; # W2+W6
W2mW6: con 1567; # W2-W6
R2: con 181; # 256/sqrt(2)
idct(b: array of int)
{
# transform horizontally
for(y:=0; y<8; y++){
eighty := y<<3;
# if all non-DC components are zero, just propagate the DC term
if(b[eighty+1]==0)
if(b[eighty+2]==0 && b[eighty+3]==0)
if(b[eighty+4]==0 && b[eighty+5]==0)
if(b[eighty+6]==0 && b[eighty+7]==0){
v := b[eighty]<<3;
b[eighty+0] = v;
b[eighty+1] = v;
b[eighty+2] = v;
b[eighty+3] = v;
b[eighty+4] = v;
b[eighty+5] = v;
b[eighty+6] = v;
b[eighty+7] = v;
continue;
}
# prescale
x0 := (b[eighty+0]<<11)+128;
x1 := b[eighty+4]<<11;
x2 := b[eighty+6];
x3 := b[eighty+2];
x4 := b[eighty+1];
x5 := b[eighty+7];
x6 := b[eighty+5];
x7 := b[eighty+3];
# first stage
x8 := W7*(x4+x5);
x4 = x8 + W1mW7*x4;
x5 = x8 - W1pW7*x5;
x8 = W3*(x6+x7);
x6 = x8 - W3mW5*x6;
x7 = x8 - W3pW5*x7;
# second stage
x8 = x0 + x1;
x0 -= x1;
x1 = W6*(x3+x2);
x2 = x1 - W2pW6*x2;
x3 = x1 + W2mW6*x3;
x1 = x4 + x6;
x4 -= x6;
x6 = x5 + x7;
x5 -= x7;
# third stage
x7 = x8 + x3;
x8 -= x3;
x3 = x0 + x2;
x0 -= x2;
x2 = (R2*(x4+x5)+128)>>8;
x4 = (R2*(x4-x5)+128)>>8;
# fourth stage
b[eighty+0] = (x7+x1)>>8;
b[eighty+1] = (x3+x2)>>8;
b[eighty+2] = (x0+x4)>>8;
b[eighty+3] = (x8+x6)>>8;
b[eighty+4] = (x8-x6)>>8;
b[eighty+5] = (x0-x4)>>8;
b[eighty+6] = (x3-x2)>>8;
b[eighty+7] = (x7-x1)>>8;
}
# transform vertically
for(x:=0; x<8; x++){
# if all non-DC components are zero, just propagate the DC term
if(b[x+8*1]==0)
if(b[x+8*2]==0 && b[x+8*3]==0)
if(b[x+8*4]==0 && b[x+8*5]==0)
if(b[x+8*6]==0 && b[x+8*7]==0){
v := (b[x+8*0]+32)>>6;
b[x+8*0] = v;
b[x+8*1] = v;
b[x+8*2] = v;
b[x+8*3] = v;
b[x+8*4] = v;
b[x+8*5] = v;
b[x+8*6] = v;
b[x+8*7] = v;
continue;
}
# prescale
x0 := (b[x+8*0]<<8)+8192;
x1 := b[x+8*4]<<8;
x2 := b[x+8*6];
x3 := b[x+8*2];
x4 := b[x+8*1];
x5 := b[x+8*7];
x6 := b[x+8*5];
x7 := b[x+8*3];
# first stage
x8 := W7*(x4+x5) + 4;
x4 = (x8+W1mW7*x4)>>3;
x5 = (x8-W1pW7*x5)>>3;
x8 = W3*(x6+x7) + 4;
x6 = (x8-W3mW5*x6)>>3;
x7 = (x8-W3pW5*x7)>>3;
# second stage
x8 = x0 + x1;
x0 -= x1;
x1 = W6*(x3+x2) + 4;
x2 = (x1-W2pW6*x2)>>3;
x3 = (x1+W2mW6*x3)>>3;
x1 = x4 + x6;
x4 -= x6;
x6 = x5 + x7;
x5 -= x7;
# third stage
x7 = x8 + x3;
x8 -= x3;
x3 = x0 + x2;
x0 -= x2;
x2 = (R2*(x4+x5)+128)>>8;
x4 = (R2*(x4-x5)+128)>>8;
# fourth stage
b[x+8*0] = (x7+x1)>>14;
b[x+8*1] = (x3+x2)>>14;
b[x+8*2] = (x0+x4)>>14;
b[x+8*3] = (x8+x6)>>14;
b[x+8*4] = (x8-x6)>>14;
b[x+8*5] = (x0-x4)>>14;
b[x+8*6] = (x3-x2)>>14;
b[x+8*7] = (x7-x1)>>14;
}
}
|