1 #include "../libzmpeg3.h"
3 /**********************************************************/
4 /* inverse two dimensional DCT, Chen-Wang algorithm */
5 /* (cf. IEEE ASSP-32, pp. 803-816, Aug. 1984) */
6 /* 32-bit integer arithmetic (8 bit coefficients) */
7 /* 11 mults, 29 adds per DCT */
9 /**********************************************************/
10 /* coefficients extended to 12 bit for IEEE1180-1990 */
11 /* compliance sE, 2.1.94 */
12 /**********************************************************/
14 /* this code assumes >> to be a two's-complement arithmetic */
15 /* right shift: (-2)>>1 == -1 , (-3)>>1 == -2 */
17 #define W1 2841 /* 2048*sqrt(2)*cos(1*pi/16) */
18 #define W2 2676 /* 2048*sqrt(2)*cos(2*pi/16) */
19 #define W3 2408 /* 2048*sqrt(2)*cos(3*pi/16) */
20 #define W5 1609 /* 2048*sqrt(2)*cos(5*pi/16) */
21 #define W6 1108 /* 2048*sqrt(2)*cos(6*pi/16) */
22 #define W7 565 /* 2048*sqrt(2)*cos(7*pi/16) */
24 /* row (horizontal) IDCT
27 * dst[k] = sum c[l] * src[l] * cos( -- * ( k + - ) * l )
31 * c[1..7] = 128*sqrt(2)
34 static int idct_row(short *blk)
36 int x0, x1, x2, x3, x4, x5, x6, x7, x8;
39 if( !((x1 = blk[4]<<11) | (x2 = blk[6]) | (x3 = blk[2]) |
40 (x4 = blk[1]) | (x5 = blk[7]) | (x6 = blk[5]) | (x7 = blk[3])) ) {
41 blk[0]=blk[1]=blk[2]=blk[3]=blk[4]=blk[5]=blk[6]=blk[7]=blk[0]<<3;
45 x0 = (blk[0]<<11) + 128; /* for proper rounding in the fourth stage */
47 x8 = W7*(x4+x5); /* first stage */
54 x8 = x0 + x1; /* second stage */
64 x7 = x8 + x3; /* third stage */
68 x2 = (181*(x4+x5)+128)>>8;
69 x4 = (181*(x4-x5)+128)>>8;
71 blk[0] = (x7+x1)>>8; /* fourth stage */
82 /* column (vertical) IDCT
85 * dst[8*k] = sum c[l] * src[8*l] * cos( -- * ( k + - ) * l )
88 * where: c[0] = 1/1024
89 * c[1..7] = (1/1024)*sqrt(2)
92 static int idct_col(short *blk)
94 int x0, x1, x2, x3, x4, x5, x6, x7, x8;
97 if( !((x1 = (blk[8*4]<<8)) | (x2 = blk[8*6]) | (x3 = blk[8*2]) |
98 (x4 = blk[8*1]) | (x5 = blk[8*7]) | (x6 = blk[8*5]) |
99 (x7 = blk[8 * 3])) ) {
100 blk[8*0] = blk[8*1] = blk[8*2] = blk[8*3] =
101 blk[8*4] = blk[8*5] = blk[8*6] = blk[8*7] = (blk[8*0]+32)>>6;
105 x0 = (blk[8*0]<<8) + 8192;
107 x8 = W7*(x4+x5) + 4; /* first stage */
108 x4 = (x8+(W1-W7)*x4)>>3;
109 x5 = (x8-(W1+W7)*x5)>>3;
111 x6 = (x8-(W3-W5)*x6)>>3;
112 x7 = (x8-(W3+W5)*x7)>>3;
114 x8 = x0 + x1; /* second stage */
117 x2 = (x1-(W2+W6)*x2)>>3;
118 x3 = (x1+(W2-W6)*x3)>>3;
124 x7 = x8 + x3; /* third stage */
128 x2 = (181 * (x4+x5) + 128) >> 8;
129 x4 = (181 * (x4-x5) + 128) >> 8;
131 blk[8 * 0] = (x7+x1) >> 14; /* fourth stage */
132 blk[8 * 1] = (x3+x2) >> 14;
133 blk[8 * 2] = (x0+x4) >> 14;
134 blk[8 * 3] = (x8+x6) >> 14;
135 blk[8 * 4] = (x8-x6) >> 14;
136 blk[8 * 5] = (x0-x4) >> 14;
137 blk[8 * 6] = (x3-x2) >> 14;
138 blk[8 * 7] = (x7-x1) >> 14;
143 /* two dimensional inverse discrete cosine transform */
144 void zslice_decoder_t::
145 idct_conversion(short* block)
149 idct_row(block + 8*i);