1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18 /*
19 ------------------------------------------------------------------------------
20 INPUT AND OUTPUT DEFINITIONS
21
22 Inputs:
23 [input_variable_name] = [description of the input to module, its type
24 definition, and length (when applicable)]
25
26 Local Stores/Buffers/Pointers Needed:
27 [local_store_name] = [description of the local store, its type
28 definition, and length (when applicable)]
29 [local_buffer_name] = [description of the local buffer, its type
30 definition, and length (when applicable)]
31 [local_ptr_name] = [description of the local pointer, its type
32 definition, and length (when applicable)]
33
34 Global Stores/Buffers/Pointers Needed:
35 [global_store_name] = [description of the global store, its type
36 definition, and length (when applicable)]
37 [global_buffer_name] = [description of the global buffer, its type
38 definition, and length (when applicable)]
39 [global_ptr_name] = [description of the global pointer, its type
40 definition, and length (when applicable)]
41
42 Outputs:
43 [return_variable_name] = [description of data/pointer returned
44 by module, its type definition, and length
45 (when applicable)]
46
47 Pointers and Buffers Modified:
48 [variable_bfr_ptr] points to the [describe where the
49 variable_bfr_ptr points to, its type definition, and length
50 (when applicable)]
51 [variable_bfr] contents are [describe the new contents of
52 variable_bfr]
53
54 Local Stores Modified:
55 [local_store_name] = [describe new contents, its type
56 definition, and length (when applicable)]
57
58 Global Stores Modified:
59 [global_store_name] = [describe new contents, its type
60 definition, and length (when applicable)]
61
62 ------------------------------------------------------------------------------
63 FUNCTION DESCRIPTION
64
65 ------------------------------------------------------------------------------
66 REQUIREMENTS
67
68 ------------------------------------------------------------------------------
69 REFERENCES
70
71 ------------------------------------------------------------------------------
72 PSEUDO-CODE
73
74 ------------------------------------------------------------------------------
75 RESOURCES USED
76 When the code is written for a specific target processor the
77 the resources used should be documented below.
78
79 STACK USAGE: [stack count for this module] + [variable to represent
80 stack usage for each subroutine called]
81
82 where: [stack usage variable] = stack usage for [subroutine
83 name] (see [filename].ext)
84
85 DATA MEMORY USED: x words
86
87 PROGRAM MEMORY USED: x words
88
89 CLOCK CYCLES: [cycle count equation for this module] + [variable
90 used to represent cycle count for each subroutine
91 called]
92
93 where: [cycle count variable] = cycle count for [subroutine
94 name] (see [filename].ext)
95
96 ------------------------------------------------------------------------------
97 */
98
99 /*----------------------------------------------------------------------------
100 ; INCLUDES
101 ----------------------------------------------------------------------------*/
102 #include "mp4dec_lib.h"
103 #include "idct.h"
104 #include "motion_comp.h"
105
106 #define OSCL_DISABLE_WARNING_CONV_POSSIBLE_LOSS_OF_DATA
107 #include "osclconfig_compiler_warnings.h"
108 /*----------------------------------------------------------------------------
109 ; MACROS
110 ; Define module specific macros here
111 ----------------------------------------------------------------------------*/
112
113 /*----------------------------------------------------------------------------
114 ; DEFINES
115 ; Include all pre-processor statements here. Include conditional
116 ; compile variables also.
117 ----------------------------------------------------------------------------*/
118
119 /*----------------------------------------------------------------------------
120 ; LOCAL FUNCTION DEFINITIONS
121 ; Function Prototype declaration
122 ----------------------------------------------------------------------------*/
123 /* private prototypes */
124 static void idctrow(int16 *blk, uint8 *pred, uint8 *dst, int width);
125 static void idctrow_intra(int16 *blk, PIXEL *, int width);
126 static void idctcol(int16 *blk);
127
128 #ifdef FAST_IDCT
129 // mapping from nz_coefs to functions to be used
130
131
132 // ARM4 does not allow global data when they are not constant hence
133 // an array of function pointers cannot be considered as array of constants
134 // (actual addresses are only known when the dll is loaded).
135 // So instead of arrays of function pointers, we'll store here
136 // arrays of rows or columns and then call the idct function
137 // corresponding to such the row/column number:
138
139
140 static void (*const idctcolVCA[10][4])(int16*) =
141 {
142 {&idctcol1, &idctcol0, &idctcol0, &idctcol0},
143 {&idctcol1, &idctcol1, &idctcol0, &idctcol0},
144 {&idctcol2, &idctcol1, &idctcol0, &idctcol0},
145 {&idctcol3, &idctcol1, &idctcol0, &idctcol0},
146 {&idctcol3, &idctcol2, &idctcol0, &idctcol0},
147 {&idctcol3, &idctcol2, &idctcol1, &idctcol0},
148 {&idctcol3, &idctcol2, &idctcol1, &idctcol1},
149 {&idctcol3, &idctcol2, &idctcol2, &idctcol1},
150 {&idctcol3, &idctcol3, &idctcol2, &idctcol1},
151 {&idctcol4, &idctcol3, &idctcol2, &idctcol1}
152 };
153
154
155 static void (*const idctrowVCA[10])(int16*, uint8*, uint8*, int) =
156 {
157 &idctrow1,
158 &idctrow2,
159 &idctrow2,
160 &idctrow2,
161 &idctrow2,
162 &idctrow3,
163 &idctrow4,
164 &idctrow4,
165 &idctrow4,
166 &idctrow4
167 };
168
169
170 static void (*const idctcolVCA2[16])(int16*) =
171 {
172 &idctcol0, &idctcol4, &idctcol3, &idctcol4,
173 &idctcol2, &idctcol4, &idctcol3, &idctcol4,
174 &idctcol1, &idctcol4, &idctcol3, &idctcol4,
175 &idctcol2, &idctcol4, &idctcol3, &idctcol4
176 };
177
178 static void (*const idctrowVCA2[8])(int16*, uint8*, uint8*, int) =
179 {
180 &idctrow1, &idctrow4, &idctrow3, &idctrow4,
181 &idctrow2, &idctrow4, &idctrow3, &idctrow4
182 };
183
184 static void (*const idctrowVCA_intra[10])(int16*, PIXEL *, int) =
185 {
186 &idctrow1_intra,
187 &idctrow2_intra,
188 &idctrow2_intra,
189 &idctrow2_intra,
190 &idctrow2_intra,
191 &idctrow3_intra,
192 &idctrow4_intra,
193 &idctrow4_intra,
194 &idctrow4_intra,
195 &idctrow4_intra
196 };
197
198 static void (*const idctrowVCA2_intra[8])(int16*, PIXEL *, int) =
199 {
200 &idctrow1_intra, &idctrow4_intra, &idctrow3_intra, &idctrow4_intra,
201 &idctrow2_intra, &idctrow4_intra, &idctrow3_intra, &idctrow4_intra
202 };
203 #endif
204
205 /*----------------------------------------------------------------------------
206 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
207 ; Variable declaration - defined here and used outside this module
208 ----------------------------------------------------------------------------*/
209
210 /*----------------------------------------------------------------------------
211 ; EXTERNAL FUNCTION REFERENCES
212 ; Declare functions defined elsewhere and referenced in this module
213 ----------------------------------------------------------------------------*/
214
215 /*----------------------------------------------------------------------------
216 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
217 ; Declare variables used in this module but defined elsewhere
218 ----------------------------------------------------------------------------*/
219
220 /*----------------------------------------------------------------------------
221 ; FUNCTION CODE
222 ----------------------------------------------------------------------------*/
MBlockIDCT(VideoDecData * video)223 void MBlockIDCT(VideoDecData *video)
224 {
225 Vop *currVop = video->currVop;
226 MacroBlock *mblock = video->mblock;
227 PIXEL *c_comp;
228 PIXEL *cu_comp;
229 PIXEL *cv_comp;
230 int x_pos = video->mbnum_col;
231 int y_pos = video->mbnum_row;
232 int width, width_uv;
233 int32 offset;
234 width = video->width;
235 width_uv = width >> 1;
236 offset = (int32)(y_pos << 4) * width + (x_pos << 4);
237
238 c_comp = currVop->yChan + offset;
239 cu_comp = currVop->uChan + (offset >> 2) + (x_pos << 2);
240 cv_comp = currVop->vChan + (offset >> 2) + (x_pos << 2);
241
242 BlockIDCT_intra(mblock, c_comp, 0, width);
243 BlockIDCT_intra(mblock, c_comp + 8, 1, width);
244 BlockIDCT_intra(mblock, c_comp + (width << 3), 2, width);
245 BlockIDCT_intra(mblock, c_comp + (width << 3) + 8, 3, width);
246 BlockIDCT_intra(mblock, cu_comp, 4, width_uv);
247 BlockIDCT_intra(mblock, cv_comp, 5, width_uv);
248 }
249
250
BlockIDCT_intra(MacroBlock * mblock,PIXEL * c_comp,int comp,int width)251 void BlockIDCT_intra(
252 MacroBlock *mblock, PIXEL *c_comp, int comp, int width)
253 {
254 /*----------------------------------------------------------------------------
255 ; Define all local variables
256 ----------------------------------------------------------------------------*/
257 int16 *coeff_in = mblock->block[comp];
258 #ifdef INTEGER_IDCT
259 #ifdef FAST_IDCT /* VCA IDCT using nzcoefs and bitmaps*/
260 int i, bmapr;
261 int nz_coefs = mblock->no_coeff[comp];
262 uint8 *bitmapcol = mblock->bitmapcol[comp];
263 uint8 bitmaprow = mblock->bitmaprow[comp];
264
265 /*----------------------------------------------------------------------------
266 ; Function body here
267 ----------------------------------------------------------------------------*/
268 if (nz_coefs <= 10)
269 {
270 bmapr = (nz_coefs - 1);
271
272 (*(idctcolVCA[bmapr]))(coeff_in);
273 (*(idctcolVCA[bmapr][1]))(coeff_in + 1);
274 (*(idctcolVCA[bmapr][2]))(coeff_in + 2);
275 (*(idctcolVCA[bmapr][3]))(coeff_in + 3);
276
277 (*idctrowVCA_intra[nz_coefs-1])(coeff_in, c_comp, width);
278 }
279 else
280 {
281 i = 8;
282 while (i--)
283 {
284 bmapr = (int)bitmapcol[i];
285 if (bmapr)
286 {
287 if ((bmapr&0xf) == 0) /* 07/18/01 */
288 {
289 (*(idctcolVCA2[bmapr>>4]))(coeff_in + i);
290 }
291 else
292 {
293 idctcol(coeff_in + i);
294 }
295 }
296 }
297 if ((bitmapcol[4] | bitmapcol[5] | bitmapcol[6] | bitmapcol[7]) == 0)
298 {
299 bitmaprow >>= 4;
300 (*(idctrowVCA2_intra[(int)bitmaprow]))(coeff_in, c_comp, width);
301 }
302 else
303 {
304 idctrow_intra(coeff_in, c_comp, width);
305 }
306 }
307 #else
308 void idct_intra(int *block, uint8 *comp, int width);
309 idct_intra(coeff_in, c_comp, width);
310 #endif
311 #else
312 void idctref_intra(int *block, uint8 *comp, int width);
313 idctref_intra(coeff_in, c_comp, width);
314 #endif
315
316
317 /*----------------------------------------------------------------------------
318 ; Return nothing or data or data pointer
319 ----------------------------------------------------------------------------*/
320 return;
321 }
322
323 /* 08/04/05, no residue, just copy from pred to output */
Copy_Blk_to_Vop(uint8 * dst,uint8 * pred,int width)324 void Copy_Blk_to_Vop(uint8 *dst, uint8 *pred, int width)
325 {
326 /* copy 4 bytes at a time */
327 width -= 4;
328 *((uint32*)dst) = *((uint32*)pred);
329 *((uint32*)(dst += 4)) = *((uint32*)(pred += 4));
330 *((uint32*)(dst += width)) = *((uint32*)(pred += 12));
331 *((uint32*)(dst += 4)) = *((uint32*)(pred += 4));
332 *((uint32*)(dst += width)) = *((uint32*)(pred += 12));
333 *((uint32*)(dst += 4)) = *((uint32*)(pred += 4));
334 *((uint32*)(dst += width)) = *((uint32*)(pred += 12));
335 *((uint32*)(dst += 4)) = *((uint32*)(pred += 4));
336 *((uint32*)(dst += width)) = *((uint32*)(pred += 12));
337 *((uint32*)(dst += 4)) = *((uint32*)(pred += 4));
338 *((uint32*)(dst += width)) = *((uint32*)(pred += 12));
339 *((uint32*)(dst += 4)) = *((uint32*)(pred += 4));
340 *((uint32*)(dst += width)) = *((uint32*)(pred += 12));
341 *((uint32*)(dst += 4)) = *((uint32*)(pred += 4));
342 *((uint32*)(dst += width)) = *((uint32*)(pred += 12));
343 *((uint32*)(dst += 4)) = *((uint32*)(pred += 4));
344
345 return ;
346 }
347
348 /* 08/04/05 compute IDCT and add prediction at the end */
BlockIDCT(uint8 * dst,uint8 * pred,int16 * coeff_in,int width,int nz_coefs,uint8 * bitmapcol,uint8 bitmaprow)349 void BlockIDCT(
350 uint8 *dst, /* destination */
351 uint8 *pred, /* prediction block, pitch 16 */
352 int16 *coeff_in, /* DCT data, size 64 */
353 int width, /* width of dst */
354 int nz_coefs,
355 uint8 *bitmapcol,
356 uint8 bitmaprow
357 )
358 {
359 #ifdef INTEGER_IDCT
360 #ifdef FAST_IDCT /* VCA IDCT using nzcoefs and bitmaps*/
361 int i, bmapr;
362 /*----------------------------------------------------------------------------
363 ; Function body here
364 ----------------------------------------------------------------------------*/
365 if (nz_coefs <= 10)
366 {
367 bmapr = (nz_coefs - 1);
368 (*(idctcolVCA[bmapr]))(coeff_in);
369 (*(idctcolVCA[bmapr][1]))(coeff_in + 1);
370 (*(idctcolVCA[bmapr][2]))(coeff_in + 2);
371 (*(idctcolVCA[bmapr][3]))(coeff_in + 3);
372
373 (*idctrowVCA[nz_coefs-1])(coeff_in, pred, dst, width);
374 return ;
375 }
376 else
377 {
378 i = 8;
379
380 while (i--)
381 {
382 bmapr = (int)bitmapcol[i];
383 if (bmapr)
384 {
385 if ((bmapr&0xf) == 0) /* 07/18/01 */
386 {
387 (*(idctcolVCA2[bmapr>>4]))(coeff_in + i);
388 }
389 else
390 {
391 idctcol(coeff_in + i);
392 }
393 }
394 }
395 if ((bitmapcol[4] | bitmapcol[5] | bitmapcol[6] | bitmapcol[7]) == 0)
396 {
397 (*(idctrowVCA2[bitmaprow>>4]))(coeff_in, pred, dst, width);
398 }
399 else
400 {
401 idctrow(coeff_in, pred, dst, width);
402 }
403 return ;
404 }
405 #else // FAST_IDCT
406 void idct(int *block, uint8 *pred, uint8 *dst, int width);
407 idct(coeff_in, pred, dst, width);
408 return;
409 #endif // FAST_IDCT
410 #else // INTEGER_IDCT
411 void idctref(int *block, uint8 *pred, uint8 *dst, int width);
412 idctref(coeff_in, pred, dst, width);
413 return;
414 #endif // INTEGER_IDCT
415
416 }
417 /*----------------------------------------------------------------------------
418 ; End Function: block_idct
419 ----------------------------------------------------------------------------*/
420
421
422 /****************************************************************************/
423
424 /*
425 ------------------------------------------------------------------------------
426 FUNCTION NAME: idctrow
427 ------------------------------------------------------------------------------
428 INPUT AND OUTPUT DEFINITIONS FOR idctrow
429
430 Inputs:
431 [input_variable_name] = [description of the input to module, its type
432 definition, and length (when applicable)]
433
434 Local Stores/Buffers/Pointers Needed:
435 [local_store_name] = [description of the local store, its type
436 definition, and length (when applicable)]
437 [local_buffer_name] = [description of the local buffer, its type
438 definition, and length (when applicable)]
439 [local_ptr_name] = [description of the local pointer, its type
440 definition, and length (when applicable)]
441
442 Global Stores/Buffers/Pointers Needed:
443 [global_store_name] = [description of the global store, its type
444 definition, and length (when applicable)]
445 [global_buffer_name] = [description of the global buffer, its type
446 definition, and length (when applicable)]
447 [global_ptr_name] = [description of the global pointer, its type
448 definition, and length (when applicable)]
449
450 Outputs:
451 [return_variable_name] = [description of data/pointer returned
452 by module, its type definition, and length
453 (when applicable)]
454
455 Pointers and Buffers Modified:
456 [variable_bfr_ptr] points to the [describe where the
457 variable_bfr_ptr points to, its type definition, and length
458 (when applicable)]
459 [variable_bfr] contents are [describe the new contents of
460 variable_bfr]
461
462 Local Stores Modified:
463 [local_store_name] = [describe new contents, its type
464 definition, and length (when applicable)]
465
466 Global Stores Modified:
467 [global_store_name] = [describe new contents, its type
468 definition, and length (when applicable)]
469
470 ------------------------------------------------------------------------------
471 FUNCTION DESCRIPTION FOR idctrow
472
473 ------------------------------------------------------------------------------
474 REQUIREMENTS FOR idctrow
475
476 ------------------------------------------------------------------------------
477 REFERENCES FOR idctrow
478
479 ------------------------------------------------------------------------------
480 PSEUDO-CODE FOR idctrow
481
482 ------------------------------------------------------------------------------
483 RESOURCES USED FOR idctrow
484 When the code is written for a specific target processor the
485 the resources used should be documented below.
486
487 STACK USAGE: [stack count for this module] + [variable to represent
488 stack usage for each subroutine called]
489
490 where: [stack usage variable] = stack usage for [subroutine
491 name] (see [filename].ext)
492
493 DATA MEMORY USED: x words
494
495 PROGRAM MEMORY USED: x words
496
497 CLOCK CYCLES: [cycle count equation for this module] + [variable
498 used to represent cycle count for each subroutine
499 called]
500
501 where: [cycle count variable] = cycle count for [subroutine
502 name] (see [filename].ext)
503
504 ------------------------------------------------------------------------------
505 */
506
507 /*----------------------------------------------------------------------------
508 ; Function Code FOR idctrow
509 ----------------------------------------------------------------------------*/
idctrow(int16 * blk,uint8 * pred,uint8 * dst,int width)510 void idctrow(
511 int16 *blk, uint8 *pred, uint8 *dst, int width
512 )
513 {
514 /*----------------------------------------------------------------------------
515 ; Define all local variables
516 ----------------------------------------------------------------------------*/
517 int32 x0, x1, x2, x3, x4, x5, x6, x7, x8;
518 int i = 8;
519 uint32 pred_word, dst_word;
520 int res, res2;
521
522 /*----------------------------------------------------------------------------
523 ; Function body here
524 ----------------------------------------------------------------------------*/
525 /* row (horizontal) IDCT
526 *
527 * 7 pi 1 dst[k] = sum c[l] * src[l] * cos( -- *
528 * ( k + - ) * l ) l=0 8 2
529 *
530 * where: c[0] = 128 c[1..7] = 128*sqrt(2) */
531
532 /* preset the offset, such that we can take advantage pre-offset addressing mode */
533 width -= 4;
534 dst -= width;
535 pred -= 12;
536 blk -= 8;
537
538 while (i--)
539 {
540 x1 = (int32)blk[12] << 8;
541 blk[12] = 0;
542 x2 = blk[14];
543 blk[14] = 0;
544 x3 = blk[10];
545 blk[10] = 0;
546 x4 = blk[9];
547 blk[9] = 0;
548 x5 = blk[15];
549 blk[15] = 0;
550 x6 = blk[13];
551 blk[13] = 0;
552 x7 = blk[11];
553 blk[11] = 0;
554 x0 = ((*(blk += 8)) << 8) + 8192;
555 blk[0] = 0; /* for proper rounding in the fourth stage */
556
557 /* first stage */
558 x8 = W7 * (x4 + x5) + 4;
559 x4 = (x8 + (W1 - W7) * x4) >> 3;
560 x5 = (x8 - (W1 + W7) * x5) >> 3;
561 x8 = W3 * (x6 + x7) + 4;
562 x6 = (x8 - (W3 - W5) * x6) >> 3;
563 x7 = (x8 - (W3 + W5) * x7) >> 3;
564
565 /* second stage */
566 x8 = x0 + x1;
567 x0 -= x1;
568 x1 = W6 * (x3 + x2) + 4;
569 x2 = (x1 - (W2 + W6) * x2) >> 3;
570 x3 = (x1 + (W2 - W6) * x3) >> 3;
571 x1 = x4 + x6;
572 x4 -= x6;
573 x6 = x5 + x7;
574 x5 -= x7;
575
576 /* third stage */
577 x7 = x8 + x3;
578 x8 -= x3;
579 x3 = x0 + x2;
580 x0 -= x2;
581 x2 = (181 * (x4 + x5) + 128) >> 8;
582 x4 = (181 * (x4 - x5) + 128) >> 8;
583
584 /* fourth stage */
585 pred_word = *((uint32*)(pred += 12)); /* read 4 bytes from pred */
586
587 res = (x7 + x1) >> 14;
588 ADD_AND_CLIP1(res);
589 res2 = (x3 + x2) >> 14;
590 ADD_AND_CLIP2(res2);
591 dst_word = (res2 << 8) | res;
592 res = (x0 + x4) >> 14;
593 ADD_AND_CLIP3(res);
594 dst_word |= (res << 16);
595 res = (x8 + x6) >> 14;
596 ADD_AND_CLIP4(res);
597 dst_word |= (res << 24);
598 *((uint32*)(dst += width)) = dst_word; /* save 4 bytes to dst */
599
600 pred_word = *((uint32*)(pred += 4)); /* read 4 bytes from pred */
601
602 res = (x8 - x6) >> 14;
603 ADD_AND_CLIP1(res);
604 res2 = (x0 - x4) >> 14;
605 ADD_AND_CLIP2(res2);
606 dst_word = (res2 << 8) | res;
607 res = (x3 - x2) >> 14;
608 ADD_AND_CLIP3(res);
609 dst_word |= (res << 16);
610 res = (x7 - x1) >> 14;
611 ADD_AND_CLIP4(res);
612 dst_word |= (res << 24);
613 *((uint32*)(dst += 4)) = dst_word; /* save 4 bytes to dst */
614 }
615 /*----------------------------------------------------------------------------
616 ; Return nothing or data or data pointer
617 ----------------------------------------------------------------------------*/
618 return;
619 }
620
idctrow_intra(int16 * blk,PIXEL * comp,int width)621 void idctrow_intra(
622 int16 *blk, PIXEL *comp, int width
623 )
624 {
625 /*----------------------------------------------------------------------------
626 ; Define all local variables
627 ----------------------------------------------------------------------------*/
628 int32 x0, x1, x2, x3, x4, x5, x6, x7, x8, temp;
629 int i = 8;
630 int offset = width;
631 int32 word;
632
633 /*----------------------------------------------------------------------------
634 ; Function body here
635 ----------------------------------------------------------------------------*/
636 /* row (horizontal) IDCT
637 *
638 * 7 pi 1 dst[k] = sum c[l] * src[l] * cos( -- *
639 * ( k + - ) * l ) l=0 8 2
640 *
641 * where: c[0] = 128 c[1..7] = 128*sqrt(2) */
642 while (i--)
643 {
644 x1 = (int32)blk[4] << 8;
645 blk[4] = 0;
646 x2 = blk[6];
647 blk[6] = 0;
648 x3 = blk[2];
649 blk[2] = 0;
650 x4 = blk[1];
651 blk[1] = 0;
652 x5 = blk[7];
653 blk[7] = 0;
654 x6 = blk[5];
655 blk[5] = 0;
656 x7 = blk[3];
657 blk[3] = 0;
658 #ifndef FAST_IDCT
659 /* shortcut */ /* covered by idctrow1 01/9/2001 */
660 if (!(x1 | x2 | x3 | x4 | x5 | x6 | x7))
661 {
662 blk[0] = blk[1] = blk[2] = blk[3] = blk[4] = blk[5] = blk[6] = blk[7] = (blk[0] + 32) >> 6;
663 return;
664 }
665 #endif
666 x0 = ((int32)blk[0] << 8) + 8192;
667 blk[0] = 0; /* for proper rounding in the fourth stage */
668
669 /* first stage */
670 x8 = W7 * (x4 + x5) + 4;
671 x4 = (x8 + (W1 - W7) * x4) >> 3;
672 x5 = (x8 - (W1 + W7) * x5) >> 3;
673 x8 = W3 * (x6 + x7) + 4;
674 x6 = (x8 - (W3 - W5) * x6) >> 3;
675 x7 = (x8 - (W3 + W5) * x7) >> 3;
676
677 /* second stage */
678 x8 = x0 + x1;
679 x0 -= x1;
680 x1 = W6 * (x3 + x2) + 4;
681 x2 = (x1 - (W2 + W6) * x2) >> 3;
682 x3 = (x1 + (W2 - W6) * x3) >> 3;
683 x1 = x4 + x6;
684 x4 -= x6;
685 x6 = x5 + x7;
686 x5 -= x7;
687
688 /* third stage */
689 x7 = x8 + x3;
690 x8 -= x3;
691 x3 = x0 + x2;
692 x0 -= x2;
693 x2 = (181 * (x4 + x5) + 128) >> 8;
694 x4 = (181 * (x4 - x5) + 128) >> 8;
695
696 /* fourth stage */
697 word = ((x7 + x1) >> 14);
698 CLIP_RESULT(word)
699
700 temp = ((x3 + x2) >> 14);
701 CLIP_RESULT(temp)
702 word = word | (temp << 8);
703
704 temp = ((x0 + x4) >> 14);
705 CLIP_RESULT(temp)
706 word = word | (temp << 16);
707
708 temp = ((x8 + x6) >> 14);
709 CLIP_RESULT(temp)
710 word = word | (temp << 24);
711 *((int32*)(comp)) = word;
712
713 word = ((x8 - x6) >> 14);
714 CLIP_RESULT(word)
715
716 temp = ((x0 - x4) >> 14);
717 CLIP_RESULT(temp)
718 word = word | (temp << 8);
719
720 temp = ((x3 - x2) >> 14);
721 CLIP_RESULT(temp)
722 word = word | (temp << 16);
723
724 temp = ((x7 - x1) >> 14);
725 CLIP_RESULT(temp)
726 word = word | (temp << 24);
727 *((int32*)(comp + 4)) = word;
728 comp += offset;
729
730 blk += B_SIZE;
731 }
732 /*----------------------------------------------------------------------------
733 ; Return nothing or data or data pointer
734 ----------------------------------------------------------------------------*/
735 return;
736 }
737
738 /*----------------------------------------------------------------------------
739 ; End Function: idctrow
740 ----------------------------------------------------------------------------*/
741
742
743 /****************************************************************************/
744
745 /*
746 ------------------------------------------------------------------------------
747 FUNCTION NAME: idctcol
748 ------------------------------------------------------------------------------
749 INPUT AND OUTPUT DEFINITIONS FOR idctcol
750
751 Inputs:
752 [input_variable_name] = [description of the input to module, its type
753 definition, and length (when applicable)]
754
755 Local Stores/Buffers/Pointers Needed:
756 [local_store_name] = [description of the local store, its type
757 definition, and length (when applicable)]
758 [local_buffer_name] = [description of the local buffer, its type
759 definition, and length (when applicable)]
760 [local_ptr_name] = [description of the local pointer, its type
761 definition, and length (when applicable)]
762
763 Global Stores/Buffers/Pointers Needed:
764 [global_store_name] = [description of the global store, its type
765 definition, and length (when applicable)]
766 [global_buffer_name] = [description of the global buffer, its type
767 definition, and length (when applicable)]
768 [global_ptr_name] = [description of the global pointer, its type
769 definition, and length (when applicable)]
770
771 Outputs:
772 [return_variable_name] = [description of data/pointer returned
773 by module, its type definition, and length
774 (when applicable)]
775
776 Pointers and Buffers Modified:
777 [variable_bfr_ptr] points to the [describe where the
778 variable_bfr_ptr points to, its type definition, and length
779 (when applicable)]
780 [variable_bfr] contents are [describe the new contents of
781 variable_bfr]
782
783 Local Stores Modified:
784 [local_store_name] = [describe new contents, its type
785 definition, and length (when applicable)]
786
787 Global Stores Modified:
788 [global_store_name] = [describe new contents, its type
789 definition, and length (when applicable)]
790
791 ------------------------------------------------------------------------------
792 FUNCTION DESCRIPTION FOR idctcol
793
794 ------------------------------------------------------------------------------
795 REQUIREMENTS FOR idctcol
796
797 ------------------------------------------------------------------------------
798 REFERENCES FOR idctcol
799
800 ------------------------------------------------------------------------------
801 PSEUDO-CODE FOR idctcol
802
803 ------------------------------------------------------------------------------
804 RESOURCES USED FOR idctcol
805 When the code is written for a specific target processor the
806 the resources used should be documented below.
807
808 STACK USAGE: [stack count for this module] + [variable to represent
809 stack usage for each subroutine called]
810
811 where: [stack usage variable] = stack usage for [subroutine
812 name] (see [filename].ext)
813
814 DATA MEMORY USED: x words
815
816 PROGRAM MEMORY USED: x words
817
818 CLOCK CYCLES: [cycle count equation for this module] + [variable
819 used to represent cycle count for each subroutine
820 called]
821
822 where: [cycle count variable] = cycle count for [subroutine
823 name] (see [filename].ext)
824
825 ------------------------------------------------------------------------------
826 */
827
828 /*----------------------------------------------------------------------------
829 ; Function Code FOR idctcol
830 ----------------------------------------------------------------------------*/
idctcol(int16 * blk)831 void idctcol(
832 int16 *blk
833 )
834 {
835 /*----------------------------------------------------------------------------
836 ; Define all local variables
837 ----------------------------------------------------------------------------*/
838 int32 x0, x1, x2, x3, x4, x5, x6, x7, x8;
839
840 /*----------------------------------------------------------------------------
841 ; Function body here
842 ----------------------------------------------------------------------------*/
843 /* column (vertical) IDCT
844 *
845 * 7 pi 1 dst[8*k] = sum c[l] * src[8*l] *
846 * cos( -- * ( k + - ) * l ) l=0 8 2
847 *
848 * where: c[0] = 1/1024 c[1..7] = (1/1024)*sqrt(2) */
849 x1 = (int32)blk[32] << 11;
850 x2 = blk[48];
851 x3 = blk[16];
852 x4 = blk[8];
853 x5 = blk[56];
854 x6 = blk[40];
855 x7 = blk[24];
856 #ifndef FAST_IDCT
857 /* shortcut */ /* covered by idctcolumn1 01/9/2001 */
858 if (!(x1 | x2 | x3 | x4 | x5 | x6 | x7))
859 {
860 blk[0] = blk[8] = blk[16] = blk[24] = blk[32] = blk[40] = blk[48] = blk[56]
861 = blk[0] << 3;
862 return;
863 }
864 #endif
865
866 x0 = ((int32)blk[0] << 11) + 128;
867
868 /* first stage */
869 x8 = W7 * (x4 + x5);
870 x4 = x8 + (W1 - W7) * x4;
871 x5 = x8 - (W1 + W7) * x5;
872 x8 = W3 * (x6 + x7);
873 x6 = x8 - (W3 - W5) * x6;
874 x7 = x8 - (W3 + W5) * x7;
875
876 /* second stage */
877 x8 = x0 + x1;
878 x0 -= x1;
879 x1 = W6 * (x3 + x2);
880 x2 = x1 - (W2 + W6) * x2;
881 x3 = x1 + (W2 - W6) * x3;
882 x1 = x4 + x6;
883 x4 -= x6;
884 x6 = x5 + x7;
885 x5 -= x7;
886
887 /* third stage */
888 x7 = x8 + x3;
889 x8 -= x3;
890 x3 = x0 + x2;
891 x0 -= x2;
892 x2 = (181 * (x4 + x5) + 128) >> 8;
893 x4 = (181 * (x4 - x5) + 128) >> 8;
894
895 /* fourth stage */
896 blk[0] = (x7 + x1) >> 8;
897 blk[8] = (x3 + x2) >> 8;
898 blk[16] = (x0 + x4) >> 8;
899 blk[24] = (x8 + x6) >> 8;
900 blk[32] = (x8 - x6) >> 8;
901 blk[40] = (x0 - x4) >> 8;
902 blk[48] = (x3 - x2) >> 8;
903 blk[56] = (x7 - x1) >> 8;
904 /*----------------------------------------------------------------------------
905 ; Return nothing or data or data pointer
906 ----------------------------------------------------------------------------*/
907 return;
908 }
909 /*----------------------------------------------------------------------------
910 ; End Function: idctcol
911 ----------------------------------------------------------------------------*/
912
913