Parent Directory
|
Revision Log
Revision 1.4 - (view) (download)
1 : | chl | 1.3 | /***************************************************************************** |
2 : | * | ||
3 : | * XVID MPEG-4 VIDEO CODEC | ||
4 : | * - inverse fast disrete cosine transformation - integer C version | ||
5 : | * | ||
6 : | * These routines are from Independent JPEG Group's free JPEG software | ||
7 : | * Copyright (C) 1991-1998, Thomas G. Lane (see the file README.IJG) | ||
8 : | * | ||
9 : | edgomez | 1.4 | * This file is part of XviD, a free MPEG-4 video encoder/decoder |
10 : | chl | 1.3 | * |
11 : | edgomez | 1.4 | * XviD is free software; you can redistribute it and/or modify it |
12 : | * under the terms of the GNU General Public License as published by | ||
13 : | chl | 1.3 | * the Free Software Foundation; either version 2 of the License, or |
14 : | * (at your option) any later version. | ||
15 : | * | ||
16 : | * This program is distributed in the hope that it will be useful, | ||
17 : | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 : | * GNU General Public License for more details. | ||
20 : | * | ||
21 : | * You should have received a copy of the GNU General Public License | ||
22 : | * along with this program; if not, write to the Free Software | ||
23 : | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
24 : | edgomez | 1.4 | * |
25 : | * Under section 8 of the GNU General Public License, the copyright | ||
26 : | * holders of XVID explicitly forbid distribution in the following | ||
27 : | * countries: | ||
28 : | * | ||
29 : | * - Japan | ||
30 : | * - United States of America | ||
31 : | * | ||
32 : | * Linking XviD statically or dynamically with other modules is making a | ||
33 : | * combined work based on XviD. Thus, the terms and conditions of the | ||
34 : | * GNU General Public License cover the whole combination. | ||
35 : | * | ||
36 : | * As a special exception, the copyright holders of XviD give you | ||
37 : | * permission to link XviD with independent modules that communicate with | ||
38 : | * XviD solely through the VFW1.1 and DShow interfaces, regardless of the | ||
39 : | * license terms of these independent modules, and to copy and distribute | ||
40 : | * the resulting combined work under terms of your choice, provided that | ||
41 : | * every copy of the combined work is accompanied by a complete copy of | ||
42 : | * the source code of XviD (the version of XviD used to produce the | ||
43 : | * combined work), being distributed under the terms of the GNU General | ||
44 : | * Public License plus this exception. An independent module is a module | ||
45 : | * which is not derived from or based on XviD. | ||
46 : | * | ||
47 : | * Note that people who make modified versions of XviD are not obligated | ||
48 : | * to grant this special exception for their modified versions; it is | ||
49 : | * their choice whether to do so. The GNU General Public License gives | ||
50 : | * permission to release a modified version without this exception; this | ||
51 : | * exception also makes it possible to release a modified version which | ||
52 : | * carries forward this exception. | ||
53 : | * | ||
54 : | * $Id$ | ||
55 : | Isibaar | 1.1 | * |
56 : | chl | 1.3 | *************************************************************************/ |
57 : | Isibaar | 1.1 | |
58 : | /**********************************************************/ | ||
59 : | /* inverse two dimensional DCT, Chen-Wang algorithm */ | ||
60 : | /* (cf. IEEE ASSP-32, pp. 803-816, Aug. 1984) */ | ||
61 : | /* 32-bit integer arithmetic (8 bit coefficients) */ | ||
62 : | /* 11 mults, 29 adds per DCT */ | ||
63 : | /* sE, 18.8.91 */ | ||
64 : | /**********************************************************/ | ||
65 : | /* coefficients extended to 12 bit for IEEE1180-1990 */ | ||
66 : | /* compliance sE, 2.1.94 */ | ||
67 : | /**********************************************************/ | ||
68 : | |||
69 : | /* this code assumes >> to be a two's-complement arithmetic */ | ||
70 : | /* right shift: (-2)>>1 == -1 , (-3)>>1 == -2 */ | ||
71 : | |||
72 : | #include "idct.h" | ||
73 : | |||
74 : | edgomez | 1.2 | #define W1 2841 /* 2048*sqrt(2)*cos(1*pi/16) */ |
75 : | #define W2 2676 /* 2048*sqrt(2)*cos(2*pi/16) */ | ||
76 : | #define W3 2408 /* 2048*sqrt(2)*cos(3*pi/16) */ | ||
77 : | #define W5 1609 /* 2048*sqrt(2)*cos(5*pi/16) */ | ||
78 : | #define W6 1108 /* 2048*sqrt(2)*cos(6*pi/16) */ | ||
79 : | #define W7 565 /* 2048*sqrt(2)*cos(7*pi/16) */ | ||
80 : | Isibaar | 1.1 | |
81 : | |||
82 : | /* global declarations */ | ||
83 : | //void init_idct_int32 (void); | ||
84 : | //void idct_int32 (short *block); | ||
85 : | |||
86 : | /* private data */ | ||
87 : | edgomez | 1.2 | static short iclip[1024]; /* clipping table */ |
88 : | Isibaar | 1.1 | static short *iclp; |
89 : | |||
90 : | /* private prototypes */ | ||
91 : | //static void idctrow _ANSI_ARGS_((short *blk)); | ||
92 : | //static void idctcol _ANSI_ARGS_((short *blk)); | ||
93 : | |||
94 : | /* row (horizontal) IDCT | ||
95 : | * | ||
96 : | * 7 pi 1 | ||
97 : | * dst[k] = sum c[l] * src[l] * cos( -- * ( k + - ) * l ) | ||
98 : | * l=0 8 2 | ||
99 : | * | ||
100 : | * where: c[0] = 128 | ||
101 : | * c[1..7] = 128*sqrt(2) | ||
102 : | */ | ||
103 : | |||
104 : | /* | ||
105 : | static void idctrow(blk) | ||
106 : | short *blk; | ||
107 : | { | ||
108 : | int X0, X1, X2, X3, X4, X5, X6, X7, X8; | ||
109 : | |||
110 : | // shortcut | ||
111 : | if (!((X1 = blk[4]<<11) | (X2 = blk[6]) | (X3 = blk[2]) | | ||
112 : | (X4 = blk[1]) | (X5 = blk[7]) | (X6 = blk[5]) | (X7 = blk[3]))) | ||
113 : | { | ||
114 : | blk[0]=blk[1]=blk[2]=blk[3]=blk[4]=blk[5]=blk[6]=blk[7]=blk[0]<<3; | ||
115 : | return; | ||
116 : | } | ||
117 : | |||
118 : | X0 = (blk[0]<<11) + 128; // for proper rounding in the fourth stage | ||
119 : | |||
120 : | // first stage | ||
121 : | X8 = W7*(X4+X5); | ||
122 : | X4 = X8 + (W1-W7)*X4; | ||
123 : | X5 = X8 - (W1+W7)*X5; | ||
124 : | X8 = W3*(X6+X7); | ||
125 : | X6 = X8 - (W3-W5)*X6; | ||
126 : | X7 = X8 - (W3+W5)*X7; | ||
127 : | |||
128 : | // second stage | ||
129 : | X8 = X0 + X1; | ||
130 : | X0 -= X1; | ||
131 : | X1 = W6*(X3+X2); | ||
132 : | X2 = X1 - (W2+W6)*X2; | ||
133 : | X3 = X1 + (W2-W6)*X3; | ||
134 : | X1 = X4 + X6; | ||
135 : | X4 -= X6; | ||
136 : | X6 = X5 + X7; | ||
137 : | X5 -= X7; | ||
138 : | |||
139 : | // third stage | ||
140 : | X7 = X8 + X3; | ||
141 : | X8 -= X3; | ||
142 : | X3 = X0 + X2; | ||
143 : | X0 -= X2; | ||
144 : | X2 = (181*(X4+X5)+128)>>8; | ||
145 : | X4 = (181*(X4-X5)+128)>>8; | ||
146 : | |||
147 : | // fourth stage | ||
148 : | blk[0] = (X7+X1)>>8; | ||
149 : | blk[1] = (X3+X2)>>8; | ||
150 : | blk[2] = (X0+X4)>>8; | ||
151 : | blk[3] = (X8+X6)>>8; | ||
152 : | blk[4] = (X8-X6)>>8; | ||
153 : | blk[5] = (X0-X4)>>8; | ||
154 : | blk[6] = (X3-X2)>>8; | ||
155 : | blk[7] = (X7-X1)>>8; | ||
156 : | }*/ | ||
157 : | |||
158 : | /* column (vertical) IDCT | ||
159 : | * | ||
160 : | * 7 pi 1 | ||
161 : | * dst[8*k] = sum c[l] * src[8*l] * cos( -- * ( k + - ) * l ) | ||
162 : | * l=0 8 2 | ||
163 : | * | ||
164 : | * where: c[0] = 1/1024 | ||
165 : | * c[1..7] = (1/1024)*sqrt(2) | ||
166 : | */ | ||
167 : | /* | ||
168 : | static void idctcol(blk) | ||
169 : | short *blk; | ||
170 : | { | ||
171 : | int X0, X1, X2, X3, X4, X5, X6, X7, X8; | ||
172 : | |||
173 : | // shortcut | ||
174 : | if (!((X1 = (blk[8*4]<<8)) | (X2 = blk[8*6]) | (X3 = blk[8*2]) | | ||
175 : | (X4 = blk[8*1]) | (X5 = blk[8*7]) | (X6 = blk[8*5]) | (X7 = blk[8*3]))) | ||
176 : | { | ||
177 : | blk[8*0]=blk[8*1]=blk[8*2]=blk[8*3]=blk[8*4]=blk[8*5]=blk[8*6]=blk[8*7]= | ||
178 : | iclp[(blk[8*0]+32)>>6]; | ||
179 : | return; | ||
180 : | } | ||
181 : | |||
182 : | X0 = (blk[8*0]<<8) + 8192; | ||
183 : | |||
184 : | // first stage | ||
185 : | X8 = W7*(X4+X5) + 4; | ||
186 : | X4 = (X8+(W1-W7)*X4)>>3; | ||
187 : | X5 = (X8-(W1+W7)*X5)>>3; | ||
188 : | X8 = W3*(X6+X7) + 4; | ||
189 : | X6 = (X8-(W3-W5)*X6)>>3; | ||
190 : | X7 = (X8-(W3+W5)*X7)>>3; | ||
191 : | |||
192 : | // second stage | ||
193 : | X8 = X0 + X1; | ||
194 : | X0 -= X1; | ||
195 : | X1 = W6*(X3+X2) + 4; | ||
196 : | X2 = (X1-(W2+W6)*X2)>>3; | ||
197 : | X3 = (X1+(W2-W6)*X3)>>3; | ||
198 : | X1 = X4 + X6; | ||
199 : | X4 -= X6; | ||
200 : | X6 = X5 + X7; | ||
201 : | X5 -= X7; | ||
202 : | |||
203 : | // third stage | ||
204 : | X7 = X8 + X3; | ||
205 : | X8 -= X3; | ||
206 : | X3 = X0 + X2; | ||
207 : | X0 -= X2; | ||
208 : | X2 = (181*(X4+X5)+128)>>8; | ||
209 : | X4 = (181*(X4-X5)+128)>>8; | ||
210 : | |||
211 : | // fourth stage | ||
212 : | blk[8*0] = iclp[(X7+X1)>>14]; | ||
213 : | blk[8*1] = iclp[(X3+X2)>>14]; | ||
214 : | blk[8*2] = iclp[(X0+X4)>>14]; | ||
215 : | blk[8*3] = iclp[(X8+X6)>>14]; | ||
216 : | blk[8*4] = iclp[(X8-X6)>>14]; | ||
217 : | blk[8*5] = iclp[(X0-X4)>>14]; | ||
218 : | blk[8*6] = iclp[(X3-X2)>>14]; | ||
219 : | blk[8*7] = iclp[(X7-X1)>>14]; | ||
220 : | }*/ | ||
221 : | |||
222 : | // function pointer | ||
223 : | idctFuncPtr idct; | ||
224 : | |||
225 : | /* two dimensional inverse discrete cosine transform */ | ||
226 : | //void j_rev_dct(block) | ||
227 : | //short *block; | ||
228 : | edgomez | 1.2 | void |
229 : | idct_int32(short *const block) | ||
230 : | Isibaar | 1.1 | { |
231 : | |||
232 : | edgomez | 1.2 | // idct_int32_init() must be called before the first call to this function! |
233 : | Isibaar | 1.1 | |
234 : | |||
235 : | edgomez | 1.2 | /*int i; |
236 : | long i; | ||
237 : | Isibaar | 1.1 | |
238 : | edgomez | 1.2 | for (i=0; i<8; i++) |
239 : | idctrow(block+8*i); | ||
240 : | Isibaar | 1.1 | |
241 : | edgomez | 1.2 | for (i=0; i<8; i++) |
242 : | idctcol(block+i); */ | ||
243 : | static short *blk; | ||
244 : | static long i; | ||
245 : | static long X0, X1, X2, X3, X4, X5, X6, X7, X8; | ||
246 : | Isibaar | 1.1 | |
247 : | |||
248 : | edgomez | 1.2 | for (i = 0; i < 8; i++) // idct rows |
249 : | Isibaar | 1.1 | { |
250 : | edgomez | 1.2 | blk = block + (i << 3); |
251 : | if (! | ||
252 : | ((X1 = blk[4] << 11) | (X2 = blk[6]) | (X3 = blk[2]) | (X4 = | ||
253 : | blk[1]) | | ||
254 : | (X5 = blk[7]) | (X6 = blk[5]) | (X7 = blk[3]))) { | ||
255 : | blk[0] = blk[1] = blk[2] = blk[3] = blk[4] = blk[5] = blk[6] = | ||
256 : | blk[7] = blk[0] << 3; | ||
257 : | continue; | ||
258 : | } | ||
259 : | |||
260 : | X0 = (blk[0] << 11) + 128; // for proper rounding in the fourth stage | ||
261 : | |||
262 : | // first stage | ||
263 : | X8 = W7 * (X4 + X5); | ||
264 : | X4 = X8 + (W1 - W7) * X4; | ||
265 : | X5 = X8 - (W1 + W7) * X5; | ||
266 : | X8 = W3 * (X6 + X7); | ||
267 : | X6 = X8 - (W3 - W5) * X6; | ||
268 : | X7 = X8 - (W3 + W5) * X7; | ||
269 : | |||
270 : | // second stage | ||
271 : | X8 = X0 + X1; | ||
272 : | X0 -= X1; | ||
273 : | X1 = W6 * (X3 + X2); | ||
274 : | X2 = X1 - (W2 + W6) * X2; | ||
275 : | X3 = X1 + (W2 - W6) * X3; | ||
276 : | X1 = X4 + X6; | ||
277 : | X4 -= X6; | ||
278 : | X6 = X5 + X7; | ||
279 : | X5 -= X7; | ||
280 : | |||
281 : | // third stage | ||
282 : | X7 = X8 + X3; | ||
283 : | X8 -= X3; | ||
284 : | X3 = X0 + X2; | ||
285 : | X0 -= X2; | ||
286 : | X2 = (181 * (X4 + X5) + 128) >> 8; | ||
287 : | X4 = (181 * (X4 - X5) + 128) >> 8; | ||
288 : | |||
289 : | // fourth stage | ||
290 : | |||
291 : | blk[0] = (short) ((X7 + X1) >> 8); | ||
292 : | blk[1] = (short) ((X3 + X2) >> 8); | ||
293 : | blk[2] = (short) ((X0 + X4) >> 8); | ||
294 : | blk[3] = (short) ((X8 + X6) >> 8); | ||
295 : | blk[4] = (short) ((X8 - X6) >> 8); | ||
296 : | blk[5] = (short) ((X0 - X4) >> 8); | ||
297 : | blk[6] = (short) ((X3 - X2) >> 8); | ||
298 : | blk[7] = (short) ((X7 - X1) >> 8); | ||
299 : | Isibaar | 1.1 | |
300 : | edgomez | 1.2 | } // end for ( i = 0; i < 8; ++i ) IDCT-rows |
301 : | Isibaar | 1.1 | |
302 : | |||
303 : | |||
304 : | edgomez | 1.2 | for (i = 0; i < 8; i++) // idct columns |
305 : | Isibaar | 1.1 | { |
306 : | edgomez | 1.2 | blk = block + i; |
307 : | // shortcut | ||
308 : | if (! | ||
309 : | ((X1 = (blk[8 * 4] << 8)) | (X2 = blk[8 * 6]) | (X3 = | ||
310 : | blk[8 * | ||
311 : | 2]) | (X4 = | ||
312 : | blk[8 * | ||
313 : | 1]) | ||
314 : | | (X5 = blk[8 * 7]) | (X6 = blk[8 * 5]) | (X7 = blk[8 * 3]))) { | ||
315 : | blk[8 * 0] = blk[8 * 1] = blk[8 * 2] = blk[8 * 3] = blk[8 * 4] = | ||
316 : | blk[8 * 5] = blk[8 * 6] = blk[8 * 7] = | ||
317 : | iclp[(blk[8 * 0] + 32) >> 6]; | ||
318 : | continue; | ||
319 : | } | ||
320 : | |||
321 : | X0 = (blk[8 * 0] << 8) + 8192; | ||
322 : | |||
323 : | // first stage | ||
324 : | X8 = W7 * (X4 + X5) + 4; | ||
325 : | X4 = (X8 + (W1 - W7) * X4) >> 3; | ||
326 : | X5 = (X8 - (W1 + W7) * X5) >> 3; | ||
327 : | X8 = W3 * (X6 + X7) + 4; | ||
328 : | X6 = (X8 - (W3 - W5) * X6) >> 3; | ||
329 : | X7 = (X8 - (W3 + W5) * X7) >> 3; | ||
330 : | |||
331 : | // second stage | ||
332 : | X8 = X0 + X1; | ||
333 : | X0 -= X1; | ||
334 : | X1 = W6 * (X3 + X2) + 4; | ||
335 : | X2 = (X1 - (W2 + W6) * X2) >> 3; | ||
336 : | X3 = (X1 + (W2 - W6) * X3) >> 3; | ||
337 : | X1 = X4 + X6; | ||
338 : | X4 -= X6; | ||
339 : | X6 = X5 + X7; | ||
340 : | X5 -= X7; | ||
341 : | |||
342 : | // third stage | ||
343 : | X7 = X8 + X3; | ||
344 : | X8 -= X3; | ||
345 : | X3 = X0 + X2; | ||
346 : | X0 -= X2; | ||
347 : | X2 = (181 * (X4 + X5) + 128) >> 8; | ||
348 : | X4 = (181 * (X4 - X5) + 128) >> 8; | ||
349 : | |||
350 : | // fourth stage | ||
351 : | blk[8 * 0] = iclp[(X7 + X1) >> 14]; | ||
352 : | blk[8 * 1] = iclp[(X3 + X2) >> 14]; | ||
353 : | blk[8 * 2] = iclp[(X0 + X4) >> 14]; | ||
354 : | blk[8 * 3] = iclp[(X8 + X6) >> 14]; | ||
355 : | blk[8 * 4] = iclp[(X8 - X6) >> 14]; | ||
356 : | blk[8 * 5] = iclp[(X0 - X4) >> 14]; | ||
357 : | blk[8 * 6] = iclp[(X3 - X2) >> 14]; | ||
358 : | blk[8 * 7] = iclp[(X7 - X1) >> 14]; | ||
359 : | Isibaar | 1.1 | } |
360 : | |||
361 : | edgomez | 1.2 | } // end function idct_int32(block) |
362 : | Isibaar | 1.1 | |
363 : | |||
364 : | //void | ||
365 : | //idct_int32_init() | ||
366 : | edgomez | 1.2 | void |
367 : | idct_int32_init() | ||
368 : | Isibaar | 1.1 | { |
369 : | edgomez | 1.2 | int i; |
370 : | Isibaar | 1.1 | |
371 : | edgomez | 1.2 | iclp = iclip + 512; |
372 : | for (i = -512; i < 512; i++) | ||
373 : | iclp[i] = (i < -256) ? -256 : ((i > 255) ? 255 : i); | ||
374 : | Isibaar | 1.1 | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |