[svn] / branches / release-1_0-branch / xvidcore / src / dct / idct.c Repository:
ViewVC logotype

Diff of /branches/release-1_0-branch/xvidcore/src/dct/idct.c

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

trunk/xvidcore/src/dct/idct.c revision 3, Fri Mar 8 02:46:11 2002 UTC branches/release-1_0-branch/xvidcore/src/dct/idct.c revision 1537, Sun Aug 22 13:16:12 2004 UTC
# Line 1  Line 1 
1  /* idct.c, inverse fast discrete cosine transform                           */  /*****************************************************************************
2     *
3     *  XVID MPEG-4 VIDEO CODEC
4     *  - Inverse DCT  -
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     *  This program is free software ; you can redistribute it and/or modify
10     *  it under the terms of the GNU General Public License as published by
11     *  the Free Software Foundation ; either version 2 of the License, or
12     *  (at your option) any later version.
13     *
14     *  This program is distributed in the hope that it will be useful,
15     *  but WITHOUT ANY WARRANTY ; without even the implied warranty of
16     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     *  GNU General Public License for more details.
18     *
19     *  You should have received a copy of the GNU General Public License
20     *  along with this program ; if not, write to the Free Software
21     *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22     *
23     * $Id: idct.c,v 1.7.2.1 2004-08-22 13:15:15 edgomez Exp $
24     *
25     ****************************************************************************/
26    
27  /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */  /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
28    
# Line 52  Line 76 
76  /* this code assumes >> to be a two's-complement arithmetic */  /* this code assumes >> to be a two's-complement arithmetic */
77  /* right shift: (-2)>>1 == -1 , (-3)>>1 == -2               */  /* right shift: (-2)>>1 == -1 , (-3)>>1 == -2               */
78    
 //#include <windows.h>  
79  #include "idct.h"  #include "idct.h"
80    
81  #define W1 2841 /* 2048*sqrt(2)*cos(1*pi/16) */  #define W1 2841 /* 2048*sqrt(2)*cos(1*pi/16) */
# Line 62  Line 85 
85  #define W6 1108 /* 2048*sqrt(2)*cos(6*pi/16) */  #define W6 1108 /* 2048*sqrt(2)*cos(6*pi/16) */
86  #define W7 565  /* 2048*sqrt(2)*cos(7*pi/16) */  #define W7 565  /* 2048*sqrt(2)*cos(7*pi/16) */
87    
88    /* private data
89  /* global declarations */   * Initialized by idct_int32_init so it's mostly RO data,
90  //void init_idct_int32 (void);   * doesn't hurt thread safety */
 //void idct_int32 (short *block);  
   
 /* private data */  
91  static short iclip[1024]; /* clipping table */  static short iclip[1024]; /* clipping table */
92  static short *iclp;  static short *iclp;
93    
94  /* private prototypes */  /* private prototypes */
 //static void idctrow _ANSI_ARGS_((short *blk));  
 //static void idctcol _ANSI_ARGS_((short *blk));  
95    
96  /* row (horizontal) IDCT  /* row (horizontal) IDCT
97   *   *
# Line 85  Line 103 
103   *        c[1..7] = 128*sqrt(2)   *        c[1..7] = 128*sqrt(2)
104   */   */
105    
106  /*  #if 0
107  static void idctrow(blk)  static void idctrow(blk)
108  short *blk;  short *blk;
109  {  {
110    int X0, X1, X2, X3, X4, X5, X6, X7, X8;    int X0, X1, X2, X3, X4, X5, X6, X7, X8;
111    
112    // shortcut    /* shortcut  */
113    if (!((X1 = blk[4]<<11) | (X2 = blk[6]) | (X3 = blk[2]) |    if (!((X1 = blk[4]<<11) | (X2 = blk[6]) | (X3 = blk[2]) |
114          (X4 = blk[1]) | (X5 = blk[7]) | (X6 = blk[5]) | (X7 = blk[3])))          (X4 = blk[1]) | (X5 = blk[7]) | (X6 = blk[5]) | (X7 = blk[3])))
115    {    {
# Line 99  Line 117 
117      return;      return;
118    }    }
119    
120    X0 = (blk[0]<<11) + 128; // for proper rounding in the fourth stage    X0 = (blk[0]<<11) + 128; /* for proper rounding in the fourth stage  */
121    
122    // first stage    /* first stage  */
123    X8 = W7*(X4+X5);    X8 = W7*(X4+X5);
124    X4 = X8 + (W1-W7)*X4;    X4 = X8 + (W1-W7)*X4;
125    X5 = X8 - (W1+W7)*X5;    X5 = X8 - (W1+W7)*X5;
# Line 109  Line 127 
127    X6 = X8 - (W3-W5)*X6;    X6 = X8 - (W3-W5)*X6;
128    X7 = X8 - (W3+W5)*X7;    X7 = X8 - (W3+W5)*X7;
129    
130    // second stage    /* second stage  */
131    X8 = X0 + X1;    X8 = X0 + X1;
132    X0 -= X1;    X0 -= X1;
133    X1 = W6*(X3+X2);    X1 = W6*(X3+X2);
# Line 120  Line 138 
138    X6 = X5 + X7;    X6 = X5 + X7;
139    X5 -= X7;    X5 -= X7;
140    
141    // third stage    /* third stage  */
142    X7 = X8 + X3;    X7 = X8 + X3;
143    X8 -= X3;    X8 -= X3;
144    X3 = X0 + X2;    X3 = X0 + X2;
# Line 128  Line 146 
146    X2 = (181*(X4+X5)+128)>>8;    X2 = (181*(X4+X5)+128)>>8;
147    X4 = (181*(X4-X5)+128)>>8;    X4 = (181*(X4-X5)+128)>>8;
148    
149    // fourth stage    /* fourth stage  */
150    blk[0] = (X7+X1)>>8;    blk[0] = (X7+X1)>>8;
151    blk[1] = (X3+X2)>>8;    blk[1] = (X3+X2)>>8;
152    blk[2] = (X0+X4)>>8;    blk[2] = (X0+X4)>>8;
# Line 137  Line 155 
155    blk[5] = (X0-X4)>>8;    blk[5] = (X0-X4)>>8;
156    blk[6] = (X3-X2)>>8;    blk[6] = (X3-X2)>>8;
157    blk[7] = (X7-X1)>>8;    blk[7] = (X7-X1)>>8;
158  }*/  }
159    #endif
160    
161  /* column (vertical) IDCT  /* column (vertical) IDCT
162   *   *
# Line 148  Line 167 
167   * where: c[0]    = 1/1024   * where: c[0]    = 1/1024
168   *        c[1..7] = (1/1024)*sqrt(2)   *        c[1..7] = (1/1024)*sqrt(2)
169   */   */
170  /*  
171    #if 0
172  static void idctcol(blk)  static void idctcol(blk)
173  short *blk;  short *blk;
174  {  {
175    int X0, X1, X2, X3, X4, X5, X6, X7, X8;    int X0, X1, X2, X3, X4, X5, X6, X7, X8;
176    
177    // shortcut    /* shortcut  */
178    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]) |
179          (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])))
180    {    {
# Line 165  Line 185 
185    
186    X0 = (blk[8*0]<<8) + 8192;    X0 = (blk[8*0]<<8) + 8192;
187    
188    // first stage    /* first stage  */
189    X8 = W7*(X4+X5) + 4;    X8 = W7*(X4+X5) + 4;
190    X4 = (X8+(W1-W7)*X4)>>3;    X4 = (X8+(W1-W7)*X4)>>3;
191    X5 = (X8-(W1+W7)*X5)>>3;    X5 = (X8-(W1+W7)*X5)>>3;
# Line 173  Line 193 
193    X6 = (X8-(W3-W5)*X6)>>3;    X6 = (X8-(W3-W5)*X6)>>3;
194    X7 = (X8-(W3+W5)*X7)>>3;    X7 = (X8-(W3+W5)*X7)>>3;
195    
196    // second stage    /* second stage */
197    X8 = X0 + X1;    X8 = X0 + X1;
198    X0 -= X1;    X0 -= X1;
199    X1 = W6*(X3+X2) + 4;    X1 = W6*(X3+X2) + 4;
# Line 184  Line 204 
204    X6 = X5 + X7;    X6 = X5 + X7;
205    X5 -= X7;    X5 -= X7;
206    
207    // third stage    /* third stage  */
208    X7 = X8 + X3;    X7 = X8 + X3;
209    X8 -= X3;    X8 -= X3;
210    X3 = X0 + X2;    X3 = X0 + X2;
# Line 192  Line 212 
212    X2 = (181*(X4+X5)+128)>>8;    X2 = (181*(X4+X5)+128)>>8;
213    X4 = (181*(X4-X5)+128)>>8;    X4 = (181*(X4-X5)+128)>>8;
214    
215    // fourth stage    /* fourth stage */
216    blk[8*0] = iclp[(X7+X1)>>14];    blk[8*0] = iclp[(X7+X1)>>14];
217    blk[8*1] = iclp[(X3+X2)>>14];    blk[8*1] = iclp[(X3+X2)>>14];
218    blk[8*2] = iclp[(X0+X4)>>14];    blk[8*2] = iclp[(X0+X4)>>14];
# Line 201  Line 221 
221    blk[8*5] = iclp[(X0-X4)>>14];    blk[8*5] = iclp[(X0-X4)>>14];
222    blk[8*6] = iclp[(X3-X2)>>14];    blk[8*6] = iclp[(X3-X2)>>14];
223    blk[8*7] = iclp[(X7-X1)>>14];    blk[8*7] = iclp[(X7-X1)>>14];
224  }*/  }
225    #endif
226    
227  // function pointer  /* function pointer */
228  idctFuncPtr idct;  idctFuncPtr idct;
229    
230  /* two dimensional inverse discrete cosine transform */  /* two dimensional inverse discrete cosine transform */
231  //void j_rev_dct(block)  void
232  //short *block;  idct_int32(short *const block)
 void idct_int32(short * const block)  
233  {  {
234    
235    // idct_int32_init() must be called before the first call to this function!          /*
236             * idct_int32_init() must be called before the first call to this
237             * function!
238             */
239    
240    
241    /*int i;  #if 0
242            int i;
243    long i;    long i;
244    
245    for (i=0; i<8; i++)    for (i=0; i<8; i++)
246      idctrow(block+8*i);      idctrow(block+8*i);
247    
248    for (i=0; i<8; i++)    for (i=0; i<8; i++)
249      idctcol(block+i);*/                  idctcol(block+i);
250    static short *blk;  #endif
251    static long i;  
252    static long X0, X1, X2, X3, X4, X5, X6, X7, X8;          short *blk;
253            long i;
254            long X0, X1, X2, X3, X4, X5, X6, X7, X8;
255    
256    
257    for (i=0; i<8; i++)   // idct rows          for (i = 0; i < 8; i++)         /* idct rows */
258    {    {
259          blk = block+(i<<3);          blk = block+(i<<3);
260          if (!((X1 = blk[4]<<11) | (X2 = blk[6]) | (X3 = blk[2]) |                  if (!
261          (X4 = blk[1]) | (X5 = blk[7]) | (X6 = blk[5]) | (X7 = blk[3])))                          ((X1 = blk[4] << 11) | (X2 = blk[6]) | (X3 = blk[2]) | (X4 =
262          {                                                                                                                                          blk[1]) |
263                  blk[0]=blk[1]=blk[2]=blk[3]=blk[4]=blk[5]=blk[6]=blk[7]=blk[0]<<3;                           (X5 = blk[7]) | (X6 = blk[5]) | (X7 = blk[3]))) {
264                            blk[0] = blk[1] = blk[2] = blk[3] = blk[4] = blk[5] = blk[6] =
265                                    blk[7] = blk[0] << 3;
266                  continue;                  continue;
267          }          }
268    
269          X0 = (blk[0]<<11) + 128; // for proper rounding in the fourth stage                  X0 = (blk[0] << 11) + 128;      /* for proper rounding in the fourth stage  */
270    
271          // first stage                  /* first stage  */
272          X8 = W7*(X4+X5);          X8 = W7*(X4+X5);
273          X4 = X8 + (W1-W7)*X4;          X4 = X8 + (W1-W7)*X4;
274          X5 = X8 - (W1+W7)*X5;          X5 = X8 - (W1+W7)*X5;
# Line 248  Line 276 
276          X6 = X8 - (W3-W5)*X6;          X6 = X8 - (W3-W5)*X6;
277          X7 = X8 - (W3+W5)*X7;          X7 = X8 - (W3+W5)*X7;
278    
279          // second stage                  /* second stage  */
280          X8 = X0 + X1;          X8 = X0 + X1;
281          X0 -= X1;          X0 -= X1;
282          X1 = W6*(X3+X2);          X1 = W6*(X3+X2);
# Line 259  Line 287 
287          X6 = X5 + X7;          X6 = X5 + X7;
288          X5 -= X7;          X5 -= X7;
289    
290          // third stage                  /* third stage  */
291          X7 = X8 + X3;          X7 = X8 + X3;
292          X8 -= X3;          X8 -= X3;
293          X3 = X0 + X2;          X3 = X0 + X2;
# Line 267  Line 295 
295          X2 = (181*(X4+X5)+128)>>8;          X2 = (181*(X4+X5)+128)>>8;
296          X4 = (181*(X4-X5)+128)>>8;          X4 = (181*(X4-X5)+128)>>8;
297    
298          // fourth stage                  /* fourth stage  */
299    
300          blk[0] = (short)((X7+X1)>>8);          blk[0] = (short)((X7+X1)>>8);
301          blk[1] = (short)((X3+X2)>>8);          blk[1] = (short)((X3+X2)>>8);
# Line 278  Line 306 
306          blk[6] = (short)((X3-X2)>>8);          blk[6] = (short)((X3-X2)>>8);
307          blk[7] = (short)((X7-X1)>>8);          blk[7] = (short)((X7-X1)>>8);
308    
309    } // end for ( i = 0; i < 8; ++i ) IDCT-rows          }                                                       /* end for ( i = 0; i < 8; ++i ) IDCT-rows */
310    
311    
312    
313    for (i=0; i<8; i++)   // idct columns          for (i = 0; i < 8; i++)         /* idct columns */
314    {    {
315          blk = block + i;          blk = block + i;
316      // shortcut                  /* shortcut  */
317          if (!((X1 = (blk[8*4]<<8)) | (X2 = blk[8*6]) | (X3 = blk[8*2]) |                  if (!
318          (X4 = blk[8*1]) | (X5 = blk[8*7]) | (X6 = blk[8*5]) | (X7 = blk[8*3])))                          ((X1 = (blk[8 * 4] << 8)) | (X2 = blk[8 * 6]) | (X3 =
319          {                                                                                                                           blk[8 *
320                                                                                                                                     2]) | (X4 =
321                                                                                                                                                    blk[8 *
322                                                                                                                                                            1])
323                             | (X5 = blk[8 * 7]) | (X6 = blk[8 * 5]) | (X7 = blk[8 * 3]))) {
324                  blk[8*0]=blk[8*1]=blk[8*2]=blk[8*3]=blk[8*4]=                  blk[8*0]=blk[8*1]=blk[8*2]=blk[8*3]=blk[8*4]=
325                          blk[8*5]=blk[8*6]=blk[8*7]=iclp[(blk[8*0]+32)>>6];                                  blk[8 * 5] = blk[8 * 6] = blk[8 * 7] =
326                                    iclp[(blk[8 * 0] + 32) >> 6];
327                  continue;                  continue;
328          }          }
329    
330          X0 = (blk[8*0]<<8) + 8192;          X0 = (blk[8*0]<<8) + 8192;
331    
332          // first stage                  /* first stage  */
333          X8 = W7*(X4+X5) + 4;          X8 = W7*(X4+X5) + 4;
334          X4 = (X8+(W1-W7)*X4)>>3;          X4 = (X8+(W1-W7)*X4)>>3;
335          X5 = (X8-(W1+W7)*X5)>>3;          X5 = (X8-(W1+W7)*X5)>>3;
# Line 304  Line 337 
337          X6 = (X8-(W3-W5)*X6)>>3;          X6 = (X8-(W3-W5)*X6)>>3;
338          X7 = (X8-(W3+W5)*X7)>>3;          X7 = (X8-(W3+W5)*X7)>>3;
339    
340          // second stage                  /* second stage  */
341          X8 = X0 + X1;          X8 = X0 + X1;
342          X0 -= X1;          X0 -= X1;
343          X1 = W6*(X3+X2) + 4;          X1 = W6*(X3+X2) + 4;
# Line 315  Line 348 
348          X6 = X5 + X7;          X6 = X5 + X7;
349          X5 -= X7;          X5 -= X7;
350    
351          // third stage                  /* third stage  */
352          X7 = X8 + X3;          X7 = X8 + X3;
353          X8 -= X3;          X8 -= X3;
354          X3 = X0 + X2;          X3 = X0 + X2;
# Line 323  Line 356 
356          X2 = (181*(X4+X5)+128)>>8;          X2 = (181*(X4+X5)+128)>>8;
357          X4 = (181*(X4-X5)+128)>>8;          X4 = (181*(X4-X5)+128)>>8;
358    
359          // fourth stage                  /* fourth stage  */
360          blk[8*0] = iclp[(X7+X1)>>14];          blk[8*0] = iclp[(X7+X1)>>14];
361          blk[8*1] = iclp[(X3+X2)>>14];          blk[8*1] = iclp[(X3+X2)>>14];
362          blk[8*2] = iclp[(X0+X4)>>14];          blk[8*2] = iclp[(X0+X4)>>14];
# Line 334  Line 367 
367          blk[8*7] = iclp[(X7-X1)>>14];          blk[8*7] = iclp[(X7-X1)>>14];
368    }    }
369    
370  } // end function idct_int32(block)  }                                                               /* end function idct_int32(block) */
371    
372    
373  //void  void
374  //idct_int32_init()  idct_int32_init()
 void idct_int32_init()  
375  {  {
376    int i;    int i;
377    

Legend:
Removed from v.3  
changed lines
  Added in v.1537

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