1
/* idct.c, inverse fast discrete cosine transform */
3
/* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
6
* Disclaimer of Warranty
8
* These software programs are available to the user without any license fee or
9
* royalty on an "as is" basis. The MPEG Software Simulation Group disclaims
10
* any and all warranties, whether express, implied, or statuary, including any
11
* implied warranties or merchantability or of fitness for a particular
12
* purpose. In no event shall the copyright-holder be liable for any
13
* incidental, punitive, or consequential damages of any kind whatsoever
14
* arising from the use of these programs.
16
* This disclaimer of warranty extends to the user of these programs and user's
17
* customers, employees, agents, transferees, successors, and assigns.
19
* The MPEG Software Simulation Group does not represent or warrant that the
20
* programs furnished hereunder are free of infringement of any third-party
23
* Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
24
* are subject to royalty fees to patent holders. Many of these patents are
25
* general enough such that they are unavoidable regardless of implementation
30
/**********************************************************/
31
/* inverse two dimensional DCT, Chen-Wang algorithm */
32
/* (cf. IEEE ASSP-32, pp. 803-816, Aug. 1984) */
33
/* 32-bit integer arithmetic (8 bit coefficients) */
34
/* 11 mults, 29 adds per DCT */
36
/**********************************************************/
37
/* coefficients extended to 12 bit for IEEE1180-1990 */
38
/* compliance sE, 2.1.94 */
39
/**********************************************************/
41
/* this code assumes >> to be a two's-complement arithmetic */
42
/* right shift: (-2)>>1 == -1 , (-3)>>1 == -2 */
45
#include "mpeg2enc_config.h"
46
#include "mpeg2enc_global.h"
48
#define W1 2841 /* 2048*sqrt(2)*cos(1*pi/16) */
49
#define W2 2676 /* 2048*sqrt(2)*cos(2*pi/16) */
50
#define W3 2408 /* 2048*sqrt(2)*cos(3*pi/16) */
51
#define W5 1609 /* 2048*sqrt(2)*cos(5*pi/16) */
52
#define W6 1108 /* 2048*sqrt(2)*cos(6*pi/16) */
53
#define W7 565 /* 2048*sqrt(2)*cos(7*pi/16) */
55
/* global declarations */
56
void MPEG2_idct _ANSI_ARGS_((short *block));
59
static short iclip[1024]; /* clipping table */
62
/* private prototypes */
63
static void MPEG2_idctrow _ANSI_ARGS_((short *blk));
64
static void MPEG2_idctcol _ANSI_ARGS_((short *blk));
66
/* row (horizontal) IDCT
69
* dst[k] = sum c[l] * src[l] * cos( -- * ( k + - ) * l )
73
* c[1..7] = 128*sqrt(2)
76
static void MPEG2_idctrow(blk)
79
int x0, x1, x2, x3, x4, x5, x6, x7, x8;
82
if (!((x1 = blk[4]<<11) | (x2 = blk[6]) | (x3 = blk[2]) |
83
(x4 = blk[1]) | (x5 = blk[7]) | (x6 = blk[5]) | (x7 = blk[3])))
85
blk[0]=blk[1]=blk[2]=blk[3]=blk[4]=blk[5]=blk[6]=blk[7]=blk[0]<<3;
89
x0 = (blk[0]<<11) + 128; /* for proper rounding in the fourth stage */
103
x2 = x1 - (W2+W6)*x2;
104
x3 = x1 + (W2-W6)*x3;
115
x2 = (181*(x4+x5)+128)>>8;
116
x4 = (181*(x4-x5)+128)>>8;
129
/* column (vertical) IDCT
132
* dst[8*k] = sum c[l] * src[8*l] * cos( -- * ( k + - ) * l )
135
* where: c[0] = 1/1024
136
* c[1..7] = (1/1024)*sqrt(2)
138
static void MPEG2_idctcol(blk)
141
int x0, x1, x2, x3, x4, x5, x6, x7, x8;
144
if (!((x1 = (blk[8*4]<<8)) | (x2 = blk[8*6]) | (x3 = blk[8*2]) |
145
(x4 = blk[8*1]) | (x5 = blk[8*7]) | (x6 = blk[8*5]) | (x7 = blk[8*3])))
147
blk[8*0]=blk[8*1]=blk[8*2]=blk[8*3]=blk[8*4]=blk[8*5]=blk[8*6]=blk[8*7]=
148
iclp[(blk[8*0]+32)>>6];
152
x0 = (blk[8*0]<<8) + 8192;
156
x4 = (x8+(W1-W7)*x4)>>3;
157
x5 = (x8-(W1+W7)*x5)>>3;
159
x6 = (x8-(W3-W5)*x6)>>3;
160
x7 = (x8-(W3+W5)*x7)>>3;
166
x2 = (x1-(W2+W6)*x2)>>3;
167
x3 = (x1+(W2-W6)*x3)>>3;
178
x2 = (181*(x4+x5)+128)>>8;
179
x4 = (181*(x4-x5)+128)>>8;
182
blk[8*0] = iclp[(x7+x1)>>14];
183
blk[8*1] = iclp[(x3+x2)>>14];
184
blk[8*2] = iclp[(x0+x4)>>14];
185
blk[8*3] = iclp[(x8+x6)>>14];
186
blk[8*4] = iclp[(x8-x6)>>14];
187
blk[8*5] = iclp[(x0-x4)>>14];
188
blk[8*6] = iclp[(x3-x2)>>14];
189
blk[8*7] = iclp[(x7-x1)>>14];
192
/* two dimensional inverse discrete cosine transform */
193
void MPEG2_idct(block)
199
MPEG2_idctrow(block+8*i);
202
MPEG2_idctcol(block+i);
205
VTK_MPEG2ENC_EXPORT void MPEG2_init_idct()
210
for (i= -512; i<512; i++)
211
iclp[i] = (i<-256) ? -256 : ((i>255) ? 255 : i);