annotate libmpeg2/idct.c @ 8688:28ab58268c35

sync
author nicolas
date Tue, 31 Dec 2002 18:47:43 +0000
parents 10130917f37b
children 47984e3f54ce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2 * idct.c
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
3 * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 * Portions of this code are from the MPEG software simulation group
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 * idct implementation. This code will be replaced with a new
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7 * implementation soon.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 * mpeg2dec is free software; you can redistribute it and/or modify
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 * (at your option) any later version.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 * mpeg2dec is distributed in the hope that it will be useful,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 * GNU General Public License for more details.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 /**********************************************************/
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 /* inverse two dimensional DCT, Chen-Wang algorithm */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 /* (cf. IEEE ASSP-32, pp. 803-816, Aug. 1984) */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 /* 32-bit integer arithmetic (8 bit coefficients) */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 /* 11 mults, 29 adds per DCT */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 /* sE, 18.8.91 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 /**********************************************************/
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 /* coefficients extended to 12 bit for IEEE1180-1990 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 /* compliance sE, 2.1.94 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 /**********************************************************/
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 /* this code assumes >> to be a two's-complement arithmetic */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 /* right shift: (-2)>>1 == -1 , (-3)>>1 == -2 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 #include "config.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 #include <stdio.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 #include <inttypes.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 #include "mpeg2_internal.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 #include "mm_accel.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 #define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 #define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 #define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 #define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 #define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 #define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
55 /* idct main entry point */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 void (*idct_block_copy) (int16_t * block, uint8_t * dest, int stride);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 void (*idct_block_add) (int16_t * block, uint8_t * dest, int stride);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 static void idct_block_copy_c (int16_t *block, uint8_t * dest, int stride);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 static void idct_block_add_c (int16_t *block, uint8_t * dest, int stride);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 static uint8_t clip_lut[1024];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 #define CLIP(i) ((clip_lut+384)[ (i)])
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 void idct_init (void)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 #ifdef ARCH_X86
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 if (config.flags & MM_ACCEL_X86_MMXEXT) {
1216
4059e05c480a some info printfs moved stderr->stdout
arpi_esp
parents: 36
diff changeset
69 printf ("libmpeg2: Using MMXEXT for IDCT transform\n");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 idct_block_copy = idct_block_copy_mmxext;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 idct_block_add = idct_block_add_mmxext;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 idct_mmx_init ();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 } else if (config.flags & MM_ACCEL_X86_MMX) {
1216
4059e05c480a some info printfs moved stderr->stdout
arpi_esp
parents: 36
diff changeset
74 printf ("libmpeg2: Using MMX for IDCT transform\n");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 idct_block_copy = idct_block_copy_mmx;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 idct_block_add = idct_block_add_mmx;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 idct_mmx_init ();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 #ifdef LIBMPEG2_MLIB
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 if (config.flags & MM_ACCEL_MLIB) {
1216
4059e05c480a some info printfs moved stderr->stdout
arpi_esp
parents: 36
diff changeset
82 printf ("libmpeg2: Using mlib for IDCT transform\n");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 idct_block_copy = idct_block_copy_mlib;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 idct_block_add = idct_block_add_mlib;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89
1216
4059e05c480a some info printfs moved stderr->stdout
arpi_esp
parents: 36
diff changeset
90 printf ("libmpeg2: No accelerated IDCT transform found\n");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 idct_block_copy = idct_block_copy_c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 idct_block_add = idct_block_add_c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 for (i = -384; i < 640; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 clip_lut[i+384] = (i < 0) ? 0 : ((i > 255) ? 255 : i);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 /* row (horizontal) IDCT
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 * 7 pi 1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 * dst[k] = sum c[l] * src[l] * cos ( -- * ( k + - ) * l )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 * l=0 8 2
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 * where: c[0] = 128
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 * c[1..7] = 128*sqrt (2)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107
3731
10130917f37b warning fix
pl
parents: 1216
diff changeset
108 static inline void idct_row (int16_t * block)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 int x0, x1, x2, x3, x4, x5, x6, x7, x8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 x1 = block[4] << 11;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 x2 = block[6];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 x3 = block[2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 x4 = block[1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 x5 = block[7];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 x6 = block[5];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 x7 = block[3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 /* shortcut */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 if (! (x1 | x2 | x3 | x4 | x5 | x6 | x7 )) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122 block[0] = block[1] = block[2] = block[3] = block[4] =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 block[5] = block[6] = block[7] = block[0]<<3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127 x0 = (block[0] << 11) + 128; /* for proper rounding in the fourth stage */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129 /* first stage */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130 x8 = W7 * (x4 + x5);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 x4 = x8 + (W1 - W7) * x4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 x5 = x8 - (W1 + W7) * x5;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 x8 = W3 * (x6 + x7);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 x6 = x8 - (W3 - W5) * x6;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 x7 = x8 - (W3 + W5) * x7;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 /* second stage */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 x8 = x0 + x1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 x0 -= x1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 x1 = W6 * (x3 + x2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 x2 = x1 - (W2 + W6) * x2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142 x3 = x1 + (W2 - W6) * x3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143 x1 = x4 + x6;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144 x4 -= x6;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145 x6 = x5 + x7;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146 x5 -= x7;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 /* third stage */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 x7 = x8 + x3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 x8 -= x3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 x3 = x0 + x2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 x0 -= x2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 x2 = (181 * (x4 + x5) + 128) >> 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154 x4 = (181 * (x4 - x5) + 128) >> 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
156 /* fourth stage */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157 block[0] = (x7 + x1) >> 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158 block[1] = (x3 + x2) >> 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159 block[2] = (x0 + x4) >> 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 block[3] = (x8 + x6) >> 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161 block[4] = (x8 - x6) >> 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162 block[5] = (x0 - x4) >> 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 block[6] = (x3 - x2) >> 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164 block[7] = (x7 - x1) >> 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
165 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
166
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167 /* column (vertical) IDCT
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
169 * 7 pi 1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 * dst[8*k] = sum c[l] * src[8*l] * cos ( -- * ( k + - ) * l )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
171 * l=0 8 2
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173 * where: c[0] = 1/1024
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174 * c[1..7] = (1/1024)*sqrt (2)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
176
3731
10130917f37b warning fix
pl
parents: 1216
diff changeset
177 static inline void idct_col (int16_t *block)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179 int x0, x1, x2, x3, x4, x5, x6, x7, x8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181 /* shortcut */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 x1 = block [8*4] << 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
183 x2 = block [8*6];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
184 x3 = block [8*2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
185 x4 = block [8*1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
186 x5 = block [8*7];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187 x6 = block [8*5];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188 x7 = block [8*3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
189
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
190 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
191 if (! (x1 | x2 | x3 | x4 | x5 | x6 | x7 )) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
192 block[8*0] = block[8*1] = block[8*2] = block[8*3] = block[8*4] =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
193 block[8*5] = block[8*6] = block[8*7] = (block[8*0] + 32) >> 6;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
194 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
195 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
196 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
197
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
198 x0 = (block[8*0] << 8) + 8192;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
199
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
200 /* first stage */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
201 x8 = W7 * (x4 + x5) + 4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
202 x4 = (x8 + (W1 - W7) * x4) >> 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
203 x5 = (x8 - (W1 + W7) * x5) >> 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
204 x8 = W3 * (x6 + x7) + 4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
205 x6 = (x8 - (W3 - W5) * x6) >> 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
206 x7 = (x8 - (W3 + W5) * x7) >> 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
207
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
208 /* second stage */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209 x8 = x0 + x1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
210 x0 -= x1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211 x1 = W6 * (x3 + x2) + 4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
212 x2 = (x1 - (W2 + W6) * x2) >> 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
213 x3 = (x1 + (W2 - W6) * x3) >> 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
214 x1 = x4 + x6;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
215 x4 -= x6;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
216 x6 = x5 + x7;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
217 x5 -= x7;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
218
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
219 /* third stage */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
220 x7 = x8 + x3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
221 x8 -= x3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
222 x3 = x0 + x2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
223 x0 -= x2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
224 x2 = (181 * (x4 + x5) + 128) >> 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
225 x4 = (181 * (x4 - x5) + 128) >> 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
226
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
227 /* fourth stage */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
228 block[8*0] = (x7 + x1) >> 14;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
229 block[8*1] = (x3 + x2) >> 14;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
230 block[8*2] = (x0 + x4) >> 14;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
231 block[8*3] = (x8 + x6) >> 14;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
232 block[8*4] = (x8 - x6) >> 14;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
233 block[8*5] = (x0 - x4) >> 14;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
234 block[8*6] = (x3 - x2) >> 14;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
235 block[8*7] = (x7 - x1) >> 14;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
236 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
237
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
238 void idct_block_copy_c (int16_t * block, uint8_t * dest, int stride)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
239 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
240 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
241
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
242 for (i = 0; i < 8; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
243 idct_row (block + 8 * i);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
244
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
245 for (i = 0; i < 8; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
246 idct_col (block + i);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
247
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
248 i = 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
249 do {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
250 dest[0] = CLIP (block[0]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
251 dest[1] = CLIP (block[1]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
252 dest[2] = CLIP (block[2]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
253 dest[3] = CLIP (block[3]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
254 dest[4] = CLIP (block[4]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
255 dest[5] = CLIP (block[5]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
256 dest[6] = CLIP (block[6]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
257 dest[7] = CLIP (block[7]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
258
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
259 dest += stride;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
260 block += 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
261 } while (--i);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
262 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
263
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
264 void idct_block_add_c (int16_t * block, uint8_t * dest, int stride)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
265 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
266 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
267
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
268 for (i = 0; i < 8; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
269 idct_row (block + 8 * i);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
270
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
271 for (i = 0; i < 8; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
272 idct_col (block + i);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
273
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
274 i = 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
275 do {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
276 dest[0] = CLIP (block[0] + dest[0]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
277 dest[1] = CLIP (block[1] + dest[1]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
278 dest[2] = CLIP (block[2] + dest[2]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
279 dest[3] = CLIP (block[3] + dest[3]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
280 dest[4] = CLIP (block[4] + dest[4]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
281 dest[5] = CLIP (block[5] + dest[5]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
282 dest[6] = CLIP (block[6] + dest[6]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
283 dest[7] = CLIP (block[7] + dest[7]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
284
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
285 dest += stride;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
286 block += 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
287 } while (--i);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
288 }