[cvs] / xvidcore / src / dct / idct.c Repository:
ViewVC logotype

Diff of /xvidcore/src/dct/idct.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6, Sat Feb 15 15:22:18 2003 UTC revision 1.6.2.1, Mon Jun 9 01:19:37 2003 UTC
# Line 52  Line 52 
52  /* this code assumes >> to be a two's-complement arithmetic */  /* this code assumes >> to be a two's-complement arithmetic */
53  /* right shift: (-2)>>1 == -1 , (-3)>>1 == -2               */  /* right shift: (-2)>>1 == -1 , (-3)>>1 == -2               */
54    
 //#include <windows.h>  
55  #include "idct.h"  #include "idct.h"
56    
57  #define W1 2841                                 /* 2048*sqrt(2)*cos(1*pi/16) */  #define W1 2841                                 /* 2048*sqrt(2)*cos(1*pi/16) */
# Line 62  Line 61 
61  #define W6 1108                                 /* 2048*sqrt(2)*cos(6*pi/16) */  #define W6 1108                                 /* 2048*sqrt(2)*cos(6*pi/16) */
62  #define W7 565                                  /* 2048*sqrt(2)*cos(7*pi/16) */  #define W7 565                                  /* 2048*sqrt(2)*cos(7*pi/16) */
63    
   
 /* global declarations */  
 //void init_idct_int32 (void);  
 //void idct_int32 (short *block);  
   
64  /* private data */  /* private data */
65  static short iclip[1024];               /* clipping table */  static short iclip[1024];               /* clipping table */
66  static short *iclp;  static short *iclp;
67    
68  /* private prototypes */  /* private prototypes */
 //static void idctrow _ANSI_ARGS_((short *blk));  
 //static void idctcol _ANSI_ARGS_((short *blk));  
69    
70  /* row (horizontal) IDCT  /* row (horizontal) IDCT
71   *   *
# Line 85  Line 77 
77   *        c[1..7] = 128*sqrt(2)   *        c[1..7] = 128*sqrt(2)
78   */   */
79    
80  /*  #if 0
81  static void idctrow(blk)  static void idctrow(blk)
82  short *blk;  short *blk;
83  {  {
84    int X0, X1, X2, X3, X4, X5, X6, X7, X8;    int X0, X1, X2, X3, X4, X5, X6, X7, X8;
85    
86    // shortcut    /* shortcut  */
87    if (!((X1 = blk[4]<<11) | (X2 = blk[6]) | (X3 = blk[2]) |    if (!((X1 = blk[4]<<11) | (X2 = blk[6]) | (X3 = blk[2]) |
88          (X4 = blk[1]) | (X5 = blk[7]) | (X6 = blk[5]) | (X7 = blk[3])))          (X4 = blk[1]) | (X5 = blk[7]) | (X6 = blk[5]) | (X7 = blk[3])))
89    {    {
# Line 99  Line 91 
91      return;      return;
92    }    }
93    
94    X0 = (blk[0]<<11) + 128; // for proper rounding in the fourth stage    X0 = (blk[0]<<11) + 128; /* for proper rounding in the fourth stage  */
95    
96    // first stage    /* first stage  */
97    X8 = W7*(X4+X5);    X8 = W7*(X4+X5);
98    X4 = X8 + (W1-W7)*X4;    X4 = X8 + (W1-W7)*X4;
99    X5 = X8 - (W1+W7)*X5;    X5 = X8 - (W1+W7)*X5;
# Line 109  Line 101 
101    X6 = X8 - (W3-W5)*X6;    X6 = X8 - (W3-W5)*X6;
102    X7 = X8 - (W3+W5)*X7;    X7 = X8 - (W3+W5)*X7;
103    
104    // second stage    /* second stage  */
105    X8 = X0 + X1;    X8 = X0 + X1;
106    X0 -= X1;    X0 -= X1;
107    X1 = W6*(X3+X2);    X1 = W6*(X3+X2);
# Line 120  Line 112 
112    X6 = X5 + X7;    X6 = X5 + X7;
113    X5 -= X7;    X5 -= X7;
114    
115    // third stage    /* third stage  */
116    X7 = X8 + X3;    X7 = X8 + X3;
117    X8 -= X3;    X8 -= X3;
118    X3 = X0 + X2;    X3 = X0 + X2;
# Line 128  Line 120 
120    X2 = (181*(X4+X5)+128)>>8;    X2 = (181*(X4+X5)+128)>>8;
121    X4 = (181*(X4-X5)+128)>>8;    X4 = (181*(X4-X5)+128)>>8;
122    
123    // fourth stage    /* fourth stage  */
124    blk[0] = (X7+X1)>>8;    blk[0] = (X7+X1)>>8;
125    blk[1] = (X3+X2)>>8;    blk[1] = (X3+X2)>>8;
126    blk[2] = (X0+X4)>>8;    blk[2] = (X0+X4)>>8;
# Line 137  Line 129 
129    blk[5] = (X0-X4)>>8;    blk[5] = (X0-X4)>>8;
130    blk[6] = (X3-X2)>>8;    blk[6] = (X3-X2)>>8;
131    blk[7] = (X7-X1)>>8;    blk[7] = (X7-X1)>>8;
132  }*/  }
133    #endif
134    
135  /* column (vertical) IDCT  /* column (vertical) IDCT
136   *   *
# Line 148  Line 141 
141   * where: c[0]    = 1/1024   * where: c[0]    = 1/1024
142   *        c[1..7] = (1/1024)*sqrt(2)   *        c[1..7] = (1/1024)*sqrt(2)
143   */   */
144  /*  
145    #if 0
146  static void idctcol(blk)  static void idctcol(blk)
147  short *blk;  short *blk;
148  {  {
149    int X0, X1, X2, X3, X4, X5, X6, X7, X8;    int X0, X1, X2, X3, X4, X5, X6, X7, X8;
150    
151    // shortcut    /* shortcut  */
152    if (!((X1 = (blk[8*4]<<8)) | (X2 = blk[8*6]) | (X3 = blk[8*2]) |    if (!((X1 = (blk[8*4]<<8)) | (X2 = blk[8*6]) | (X3 = blk[8*2]) |
153          (X4 = blk[8*1]) | (X5 = blk[8*7]) | (X6 = blk[8*5]) | (X7 = blk[8*3])))          (X4 = blk[8*1]) | (X5 = blk[8*7]) | (X6 = blk[8*5]) | (X7 = blk[8*3])))
154    {    {
# Line 165  Line 159 
159    
160    X0 = (blk[8*0]<<8) + 8192;    X0 = (blk[8*0]<<8) + 8192;
161    
162    // first stage    /* first stage  */
163    X8 = W7*(X4+X5) + 4;    X8 = W7*(X4+X5) + 4;
164    X4 = (X8+(W1-W7)*X4)>>3;    X4 = (X8+(W1-W7)*X4)>>3;
165    X5 = (X8-(W1+W7)*X5)>>3;    X5 = (X8-(W1+W7)*X5)>>3;
# Line 173  Line 167 
167    X6 = (X8-(W3-W5)*X6)>>3;    X6 = (X8-(W3-W5)*X6)>>3;
168    X7 = (X8-(W3+W5)*X7)>>3;    X7 = (X8-(W3+W5)*X7)>>3;
169    
170    // second stage    /* second stage */
171    X8 = X0 + X1;    X8 = X0 + X1;
172    X0 -= X1;    X0 -= X1;
173    X1 = W6*(X3+X2) + 4;    X1 = W6*(X3+X2) + 4;
# Line 184  Line 178 
178    X6 = X5 + X7;    X6 = X5 + X7;
179    X5 -= X7;    X5 -= X7;
180    
181    // third stage    /* third stage  */
182    X7 = X8 + X3;    X7 = X8 + X3;
183    X8 -= X3;    X8 -= X3;
184    X3 = X0 + X2;    X3 = X0 + X2;
# Line 192  Line 186 
186    X2 = (181*(X4+X5)+128)>>8;    X2 = (181*(X4+X5)+128)>>8;
187    X4 = (181*(X4-X5)+128)>>8;    X4 = (181*(X4-X5)+128)>>8;
188    
189    // fourth stage    /* fourth stage */
190    blk[8*0] = iclp[(X7+X1)>>14];    blk[8*0] = iclp[(X7+X1)>>14];
191    blk[8*1] = iclp[(X3+X2)>>14];    blk[8*1] = iclp[(X3+X2)>>14];
192    blk[8*2] = iclp[(X0+X4)>>14];    blk[8*2] = iclp[(X0+X4)>>14];
# Line 201  Line 195 
195    blk[8*5] = iclp[(X0-X4)>>14];    blk[8*5] = iclp[(X0-X4)>>14];
196    blk[8*6] = iclp[(X3-X2)>>14];    blk[8*6] = iclp[(X3-X2)>>14];
197    blk[8*7] = iclp[(X7-X1)>>14];    blk[8*7] = iclp[(X7-X1)>>14];
198  }*/  }
199    #endif
200    
201  // function pointer  /* function pointer */
202  idctFuncPtr idct;  idctFuncPtr idct;
203    
204  /* two dimensional inverse discrete cosine transform */  /* two dimensional inverse discrete cosine transform */
 //void j_rev_dct(block)  
 //short *block;  
205  void  void
206  idct_int32(short *const block)  idct_int32(short *const block)
207  {  {
208    
209          // idct_int32_init() must be called before the first call to this function!          /*
210             * idct_int32_init() must be called before the first call to this
211             * function!
212             */
213    
214    
215          /*int i;  #if 0
216            int i;
217             long i;             long i;
218    
219             for (i=0; i<8; i++)             for (i=0; i<8; i++)
220             idctrow(block+8*i);             idctrow(block+8*i);
221    
222             for (i=0; i<8; i++)             for (i=0; i<8; i++)
223             idctcol(block+i); */                  idctcol(block+i);
224    #endif
225    
226          static short *blk;          static short *blk;
227          static long i;          static long i;
228          static long X0, X1, X2, X3, X4, X5, X6, X7, X8;          static long X0, X1, X2, X3, X4, X5, X6, X7, X8;
229    
230    
231          for (i = 0; i < 8; i++)         // idct rows          for (i = 0; i < 8; i++)         /* idct rows */
232          {          {
233                  blk = block + (i << 3);                  blk = block + (i << 3);
234                  if (!                  if (!
# Line 241  Line 240 
240                          continue;                          continue;
241                  }                  }
242    
243                  X0 = (blk[0] << 11) + 128;      // for proper rounding in the fourth stage                  X0 = (blk[0] << 11) + 128;      /* for proper rounding in the fourth stage  */
244    
245                  // first stage                  /* first stage  */
246                  X8 = W7 * (X4 + X5);                  X8 = W7 * (X4 + X5);
247                  X4 = X8 + (W1 - W7) * X4;                  X4 = X8 + (W1 - W7) * X4;
248                  X5 = X8 - (W1 + W7) * X5;                  X5 = X8 - (W1 + W7) * X5;
# Line 251  Line 250 
250                  X6 = X8 - (W3 - W5) * X6;                  X6 = X8 - (W3 - W5) * X6;
251                  X7 = X8 - (W3 + W5) * X7;                  X7 = X8 - (W3 + W5) * X7;
252    
253                  // second stage                  /* second stage  */
254                  X8 = X0 + X1;                  X8 = X0 + X1;
255                  X0 -= X1;                  X0 -= X1;
256                  X1 = W6 * (X3 + X2);                  X1 = W6 * (X3 + X2);
# Line 262  Line 261 
261                  X6 = X5 + X7;                  X6 = X5 + X7;
262                  X5 -= X7;                  X5 -= X7;
263    
264                  // third stage                  /* third stage  */
265                  X7 = X8 + X3;                  X7 = X8 + X3;
266                  X8 -= X3;                  X8 -= X3;
267                  X3 = X0 + X2;                  X3 = X0 + X2;
# Line 270  Line 269 
269                  X2 = (181 * (X4 + X5) + 128) >> 8;                  X2 = (181 * (X4 + X5) + 128) >> 8;
270                  X4 = (181 * (X4 - X5) + 128) >> 8;                  X4 = (181 * (X4 - X5) + 128) >> 8;
271    
272                  // fourth stage                  /* fourth stage  */
273    
274                  blk[0] = (short) ((X7 + X1) >> 8);                  blk[0] = (short) ((X7 + X1) >> 8);
275                  blk[1] = (short) ((X3 + X2) >> 8);                  blk[1] = (short) ((X3 + X2) >> 8);
# Line 281  Line 280 
280                  blk[6] = (short) ((X3 - X2) >> 8);                  blk[6] = (short) ((X3 - X2) >> 8);
281                  blk[7] = (short) ((X7 - X1) >> 8);                  blk[7] = (short) ((X7 - X1) >> 8);
282    
283          }                                                       // end for ( i = 0; i < 8; ++i ) IDCT-rows          }                                                       /* end for ( i = 0; i < 8; ++i ) IDCT-rows */
284    
285    
286    
287          for (i = 0; i < 8; i++)         // idct columns          for (i = 0; i < 8; i++)         /* idct columns */
288          {          {
289                  blk = block + i;                  blk = block + i;
290                  // shortcut                  /* shortcut  */
291                  if (!                  if (!
292                          ((X1 = (blk[8 * 4] << 8)) | (X2 = blk[8 * 6]) | (X3 =                          ((X1 = (blk[8 * 4] << 8)) | (X2 = blk[8 * 6]) | (X3 =
293                                                                                                                           blk[8 *                                                                                                                           blk[8 *
# Line 304  Line 303 
303    
304                  X0 = (blk[8 * 0] << 8) + 8192;                  X0 = (blk[8 * 0] << 8) + 8192;
305    
306                  // first stage                  /* first stage  */
307                  X8 = W7 * (X4 + X5) + 4;                  X8 = W7 * (X4 + X5) + 4;
308                  X4 = (X8 + (W1 - W7) * X4) >> 3;                  X4 = (X8 + (W1 - W7) * X4) >> 3;
309                  X5 = (X8 - (W1 + W7) * X5) >> 3;                  X5 = (X8 - (W1 + W7) * X5) >> 3;
# Line 312  Line 311 
311                  X6 = (X8 - (W3 - W5) * X6) >> 3;                  X6 = (X8 - (W3 - W5) * X6) >> 3;
312                  X7 = (X8 - (W3 + W5) * X7) >> 3;                  X7 = (X8 - (W3 + W5) * X7) >> 3;
313    
314                  // second stage                  /* second stage  */
315                  X8 = X0 + X1;                  X8 = X0 + X1;
316                  X0 -= X1;                  X0 -= X1;
317                  X1 = W6 * (X3 + X2) + 4;                  X1 = W6 * (X3 + X2) + 4;
# Line 323  Line 322 
322                  X6 = X5 + X7;                  X6 = X5 + X7;
323                  X5 -= X7;                  X5 -= X7;
324    
325                  // third stage                  /* third stage  */
326                  X7 = X8 + X3;                  X7 = X8 + X3;
327                  X8 -= X3;                  X8 -= X3;
328                  X3 = X0 + X2;                  X3 = X0 + X2;
# Line 331  Line 330 
330                  X2 = (181 * (X4 + X5) + 128) >> 8;                  X2 = (181 * (X4 + X5) + 128) >> 8;
331                  X4 = (181 * (X4 - X5) + 128) >> 8;                  X4 = (181 * (X4 - X5) + 128) >> 8;
332    
333                  // fourth stage                  /* fourth stage  */
334                  blk[8 * 0] = iclp[(X7 + X1) >> 14];                  blk[8 * 0] = iclp[(X7 + X1) >> 14];
335                  blk[8 * 1] = iclp[(X3 + X2) >> 14];                  blk[8 * 1] = iclp[(X3 + X2) >> 14];
336                  blk[8 * 2] = iclp[(X0 + X4) >> 14];                  blk[8 * 2] = iclp[(X0 + X4) >> 14];
# Line 342  Line 341 
341                  blk[8 * 7] = iclp[(X7 - X1) >> 14];                  blk[8 * 7] = iclp[(X7 - X1) >> 14];
342          }          }
343    
344  }                                                               // end function idct_int32(block)  }                                                               /* end function idct_int32(block) */
345    
346    
 //void  
 //idct_int32_init()  
347  void  void
348  idct_int32_init()  idct_int32_init()
349  {  {

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.6.2.1

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4