[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

revision 195, Wed Jun 12 20:38:41 2002 UTC revision 677, Tue Nov 26 23:44:11 2002 UTC
# Line 1  Line 1 
1  /* idct.c, inverse fast discrete cosine transform                           */  /*****************************************************************************
   
 /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */  
   
 /*  
  * Disclaimer of Warranty  
2   *   *
3   * These software programs are available to the user without any license fee or   *  XVID MPEG-4 VIDEO CODEC
4   * royalty on an "as is" basis.  The MPEG Software Simulation Group disclaims   *  - inverse fast disrete cosine transformation - integer C version
  * any and all warranties, whether express, implied, or statuary, including any  
  * implied warranties or merchantability or of fitness for a particular  
  * purpose.  In no event shall the copyright-holder be liable for any  
  * incidental, punitive, or consequential damages of any kind whatsoever  
  * arising from the use of these programs.  
  *  
  * This disclaimer of warranty extends to the user of these programs and user's  
  * customers, employees, agents, transferees, successors, and assigns.  
  *  
  * The MPEG Software Simulation Group does not represent or warrant that the  
  * programs furnished hereunder are free of infringement of any third-party  
  * patents.  
  *  
  * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,  
  * are subject to royalty fees to patent holders.  Many of these patents are  
  * general enough such that they are unavoidable regardless of implementation  
  * design.  
  *  
  * MPEG2AVI  
  * --------  
  * v0.16B33 renamed the initialization function to init_idct_int32()  
  * v0.16B32 removed the unused idct_row() and idct_col() functions  
  * v0.16B3  changed var declarations to static, to enforce data align  
  * v0.16B22  idct_FAST() renamed to idct_int32()  
  *        also merged idct_FAST() into a single function, to help VC++  
  *        optimize it.  
5   *   *
6   * v0.14  changed int to long, to avoid confusion when compiling on x86   *  These routines are from Independent JPEG Group's free JPEG software
7   *        platform ( in VC++ "int" -> 32bits )   *  Copyright (C) 1991-1998, Thomas G. Lane (see the file README.IJG)
8   */   *
9     *  This file is part of XviD, a free MPEG-4 video encoder/decoder
10     *
11     *  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     *  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     *
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: idct.c,v 1.5 2002-11-26 23:44:10 edgomez Exp $
55     *
56     *************************************************************************/
57    
58  /**********************************************************/  /**********************************************************/
59  /* inverse two dimensional DCT, Chen-Wang algorithm       */  /* inverse two dimensional DCT, Chen-Wang algorithm       */
# Line 52  Line 69 
69  /* this code assumes >> to be a two's-complement arithmetic */  /* this code assumes >> to be a two's-complement arithmetic */
70  /* right shift: (-2)>>1 == -1 , (-3)>>1 == -2               */  /* right shift: (-2)>>1 == -1 , (-3)>>1 == -2               */
71    
 //#include <windows.h>  
72  #include "idct.h"  #include "idct.h"
73    
74  #define W1 2841                                 /* 2048*sqrt(2)*cos(1*pi/16) */  #define W1 2841                                 /* 2048*sqrt(2)*cos(1*pi/16) */
# Line 64  Line 80 
80    
81    
82  /* global declarations */  /* global declarations */
83  //void init_idct_int32 (void);  /*void init_idct_int32 (void); */
84  //void idct_int32 (short *block);  /*void idct_int32 (short *block); */
85    
86  /* private data */  /* private data */
87  static short iclip[1024];               /* clipping table */  static short iclip[1024];               /* clipping table */
88  static short *iclp;  static short *iclp;
89    
90  /* private prototypes */  /* private prototypes */
91  //static void idctrow _ANSI_ARGS_((short *blk));  /*static void idctrow _ANSI_ARGS_((short *blk)); */
92  //static void idctcol _ANSI_ARGS_((short *blk));  /*static void idctcol _ANSI_ARGS_((short *blk)); */
93    
94  /* row (horizontal) IDCT  /* row (horizontal) IDCT
95   *   *
# Line 85  Line 101 
101   *        c[1..7] = 128*sqrt(2)   *        c[1..7] = 128*sqrt(2)
102   */   */
103    
104  /*  #if 0
105  static void idctrow(blk)  static void idctrow(blk)
106  short *blk;  short *blk;
107  {  {
108    int X0, X1, X2, X3, X4, X5, X6, X7, X8;    int X0, X1, X2, X3, X4, X5, X6, X7, X8;
109    
110    // shortcut    /* shortcut  */
111    if (!((X1 = blk[4]<<11) | (X2 = blk[6]) | (X3 = blk[2]) |    if (!((X1 = blk[4]<<11) | (X2 = blk[6]) | (X3 = blk[2]) |
112          (X4 = blk[1]) | (X5 = blk[7]) | (X6 = blk[5]) | (X7 = blk[3])))          (X4 = blk[1]) | (X5 = blk[7]) | (X6 = blk[5]) | (X7 = blk[3])))
113    {    {
# Line 99  Line 115 
115      return;      return;
116    }    }
117    
118    X0 = (blk[0]<<11) + 128; // for proper rounding in the fourth stage    X0 = (blk[0]<<11) + 128; /* for proper rounding in the fourth stage  */
119    
120    // first stage    /* first stage  */
121    X8 = W7*(X4+X5);    X8 = W7*(X4+X5);
122    X4 = X8 + (W1-W7)*X4;    X4 = X8 + (W1-W7)*X4;
123    X5 = X8 - (W1+W7)*X5;    X5 = X8 - (W1+W7)*X5;
# Line 109  Line 125 
125    X6 = X8 - (W3-W5)*X6;    X6 = X8 - (W3-W5)*X6;
126    X7 = X8 - (W3+W5)*X7;    X7 = X8 - (W3+W5)*X7;
127    
128    // second stage    /* second stage  */
129    X8 = X0 + X1;    X8 = X0 + X1;
130    X0 -= X1;    X0 -= X1;
131    X1 = W6*(X3+X2);    X1 = W6*(X3+X2);
# Line 120  Line 136 
136    X6 = X5 + X7;    X6 = X5 + X7;
137    X5 -= X7;    X5 -= X7;
138    
139    // third stage    /* third stage  */
140    X7 = X8 + X3;    X7 = X8 + X3;
141    X8 -= X3;    X8 -= X3;
142    X3 = X0 + X2;    X3 = X0 + X2;
# Line 128  Line 144 
144    X2 = (181*(X4+X5)+128)>>8;    X2 = (181*(X4+X5)+128)>>8;
145    X4 = (181*(X4-X5)+128)>>8;    X4 = (181*(X4-X5)+128)>>8;
146    
147    // fourth stage    /* fourth stage  */
148    blk[0] = (X7+X1)>>8;    blk[0] = (X7+X1)>>8;
149    blk[1] = (X3+X2)>>8;    blk[1] = (X3+X2)>>8;
150    blk[2] = (X0+X4)>>8;    blk[2] = (X0+X4)>>8;
# Line 137  Line 153 
153    blk[5] = (X0-X4)>>8;    blk[5] = (X0-X4)>>8;
154    blk[6] = (X3-X2)>>8;    blk[6] = (X3-X2)>>8;
155    blk[7] = (X7-X1)>>8;    blk[7] = (X7-X1)>>8;
156  }*/  }
157    #endif
158    
159  /* column (vertical) IDCT  /* column (vertical) IDCT
160   *   *
# Line 148  Line 165 
165   * where: c[0]    = 1/1024   * where: c[0]    = 1/1024
166   *        c[1..7] = (1/1024)*sqrt(2)   *        c[1..7] = (1/1024)*sqrt(2)
167   */   */
168  /*  #if     0
169  static void idctcol(blk)  static void idctcol(blk)
170  short *blk;  short *blk;
171  {  {
172    int X0, X1, X2, X3, X4, X5, X6, X7, X8;    int X0, X1, X2, X3, X4, X5, X6, X7, X8;
173    
174    // shortcut    /* shortcut  */
175    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]) |
176          (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])))
177    {    {
# Line 165  Line 182 
182    
183    X0 = (blk[8*0]<<8) + 8192;    X0 = (blk[8*0]<<8) + 8192;
184    
185    // first stage    /* first stage  */
186    X8 = W7*(X4+X5) + 4;    X8 = W7*(X4+X5) + 4;
187    X4 = (X8+(W1-W7)*X4)>>3;    X4 = (X8+(W1-W7)*X4)>>3;
188    X5 = (X8-(W1+W7)*X5)>>3;    X5 = (X8-(W1+W7)*X5)>>3;
# Line 173  Line 190 
190    X6 = (X8-(W3-W5)*X6)>>3;    X6 = (X8-(W3-W5)*X6)>>3;
191    X7 = (X8-(W3+W5)*X7)>>3;    X7 = (X8-(W3+W5)*X7)>>3;
192    
193    // second stage    /* second stage */
194    X8 = X0 + X1;    X8 = X0 + X1;
195    X0 -= X1;    X0 -= X1;
196    X1 = W6*(X3+X2) + 4;    X1 = W6*(X3+X2) + 4;
# Line 184  Line 201 
201    X6 = X5 + X7;    X6 = X5 + X7;
202    X5 -= X7;    X5 -= X7;
203    
204    // third stage    /* third stage  */
205    X7 = X8 + X3;    X7 = X8 + X3;
206    X8 -= X3;    X8 -= X3;
207    X3 = X0 + X2;    X3 = X0 + X2;
# Line 192  Line 209 
209    X2 = (181*(X4+X5)+128)>>8;    X2 = (181*(X4+X5)+128)>>8;
210    X4 = (181*(X4-X5)+128)>>8;    X4 = (181*(X4-X5)+128)>>8;
211    
212    // fourth stage    /* fourth stage */
213    blk[8*0] = iclp[(X7+X1)>>14];    blk[8*0] = iclp[(X7+X1)>>14];
214    blk[8*1] = iclp[(X3+X2)>>14];    blk[8*1] = iclp[(X3+X2)>>14];
215    blk[8*2] = iclp[(X0+X4)>>14];    blk[8*2] = iclp[(X0+X4)>>14];
# Line 201  Line 218 
218    blk[8*5] = iclp[(X0-X4)>>14];    blk[8*5] = iclp[(X0-X4)>>14];
219    blk[8*6] = iclp[(X3-X2)>>14];    blk[8*6] = iclp[(X3-X2)>>14];
220    blk[8*7] = iclp[(X7-X1)>>14];    blk[8*7] = iclp[(X7-X1)>>14];
221  }*/  }
222    #endif
223    
224  // function pointer  /* function pointer */
225  idctFuncPtr idct;  idctFuncPtr idct;
226    
227  /* two dimensional inverse discrete cosine transform */  /* two dimensional inverse discrete cosine transform */
228  //void j_rev_dct(block)  /*void j_rev_dct(block) */
229  //short *block;  /*short *block; */
230  void  void
231  idct_int32(short *const block)  idct_int32(short *const block)
232  {  {
233    
234          // idct_int32_init() must be called before the first call to this function!          /* idct_int32_init() must be called before the first call to this function! */
235    
236    
237          /*int i;          /*int i;
# Line 229  Line 247 
247          static long X0, X1, X2, X3, X4, X5, X6, X7, X8;          static long X0, X1, X2, X3, X4, X5, X6, X7, X8;
248    
249    
250          for (i = 0; i < 8; i++)         // idct rows          for (i = 0; i < 8; i++)         /* idct rows */
251          {          {
252                  blk = block + (i << 3);                  blk = block + (i << 3);
253                  if (!                  if (!
# Line 241  Line 259 
259                          continue;                          continue;
260                  }                  }
261    
262                  X0 = (blk[0] << 11) + 128;      // for proper rounding in the fourth stage                  X0 = (blk[0] << 11) + 128;      /* for proper rounding in the fourth stage  */
263    
264                  // first stage                  /* first stage  */
265                  X8 = W7 * (X4 + X5);                  X8 = W7 * (X4 + X5);
266                  X4 = X8 + (W1 - W7) * X4;                  X4 = X8 + (W1 - W7) * X4;
267                  X5 = X8 - (W1 + W7) * X5;                  X5 = X8 - (W1 + W7) * X5;
# Line 251  Line 269 
269                  X6 = X8 - (W3 - W5) * X6;                  X6 = X8 - (W3 - W5) * X6;
270                  X7 = X8 - (W3 + W5) * X7;                  X7 = X8 - (W3 + W5) * X7;
271    
272                  // second stage                  /* second stage  */
273                  X8 = X0 + X1;                  X8 = X0 + X1;
274                  X0 -= X1;                  X0 -= X1;
275                  X1 = W6 * (X3 + X2);                  X1 = W6 * (X3 + X2);
# Line 262  Line 280 
280                  X6 = X5 + X7;                  X6 = X5 + X7;
281                  X5 -= X7;                  X5 -= X7;
282    
283                  // third stage                  /* third stage  */
284                  X7 = X8 + X3;                  X7 = X8 + X3;
285                  X8 -= X3;                  X8 -= X3;
286                  X3 = X0 + X2;                  X3 = X0 + X2;
# Line 270  Line 288 
288                  X2 = (181 * (X4 + X5) + 128) >> 8;                  X2 = (181 * (X4 + X5) + 128) >> 8;
289                  X4 = (181 * (X4 - X5) + 128) >> 8;                  X4 = (181 * (X4 - X5) + 128) >> 8;
290    
291                  // fourth stage                  /* fourth stage  */
292    
293                  blk[0] = (short) ((X7 + X1) >> 8);                  blk[0] = (short) ((X7 + X1) >> 8);
294                  blk[1] = (short) ((X3 + X2) >> 8);                  blk[1] = (short) ((X3 + X2) >> 8);
# Line 281  Line 299 
299                  blk[6] = (short) ((X3 - X2) >> 8);                  blk[6] = (short) ((X3 - X2) >> 8);
300                  blk[7] = (short) ((X7 - X1) >> 8);                  blk[7] = (short) ((X7 - X1) >> 8);
301    
302          }                                                       // end for ( i = 0; i < 8; ++i ) IDCT-rows          }                                                       /* end for ( i = 0; i < 8; ++i ) IDCT-rows */
303    
304    
305    
306          for (i = 0; i < 8; i++)         // idct columns          for (i = 0; i < 8; i++)         /* idct columns */
307          {          {
308                  blk = block + i;                  blk = block + i;
309                  // shortcut                  /* shortcut  */
310                  if (!                  if (!
311                          ((X1 = (blk[8 * 4] << 8)) | (X2 = blk[8 * 6]) | (X3 =                          ((X1 = (blk[8 * 4] << 8)) | (X2 = blk[8 * 6]) | (X3 =
312                                                                                                                           blk[8 *                                                                                                                           blk[8 *
# Line 304  Line 322 
322    
323                  X0 = (blk[8 * 0] << 8) + 8192;                  X0 = (blk[8 * 0] << 8) + 8192;
324    
325                  // first stage                  /* first stage  */
326                  X8 = W7 * (X4 + X5) + 4;                  X8 = W7 * (X4 + X5) + 4;
327                  X4 = (X8 + (W1 - W7) * X4) >> 3;                  X4 = (X8 + (W1 - W7) * X4) >> 3;
328                  X5 = (X8 - (W1 + W7) * X5) >> 3;                  X5 = (X8 - (W1 + W7) * X5) >> 3;
# Line 312  Line 330 
330                  X6 = (X8 - (W3 - W5) * X6) >> 3;                  X6 = (X8 - (W3 - W5) * X6) >> 3;
331                  X7 = (X8 - (W3 + W5) * X7) >> 3;                  X7 = (X8 - (W3 + W5) * X7) >> 3;
332    
333                  // second stage                  /* second stage  */
334                  X8 = X0 + X1;                  X8 = X0 + X1;
335                  X0 -= X1;                  X0 -= X1;
336                  X1 = W6 * (X3 + X2) + 4;                  X1 = W6 * (X3 + X2) + 4;
# Line 323  Line 341 
341                  X6 = X5 + X7;                  X6 = X5 + X7;
342                  X5 -= X7;                  X5 -= X7;
343    
344                  // third stage                  /* third stage  */
345                  X7 = X8 + X3;                  X7 = X8 + X3;
346                  X8 -= X3;                  X8 -= X3;
347                  X3 = X0 + X2;                  X3 = X0 + X2;
# Line 331  Line 349 
349                  X2 = (181 * (X4 + X5) + 128) >> 8;                  X2 = (181 * (X4 + X5) + 128) >> 8;
350                  X4 = (181 * (X4 - X5) + 128) >> 8;                  X4 = (181 * (X4 - X5) + 128) >> 8;
351    
352                  // fourth stage                  /* fourth stage  */
353                  blk[8 * 0] = iclp[(X7 + X1) >> 14];                  blk[8 * 0] = iclp[(X7 + X1) >> 14];
354                  blk[8 * 1] = iclp[(X3 + X2) >> 14];                  blk[8 * 1] = iclp[(X3 + X2) >> 14];
355                  blk[8 * 2] = iclp[(X0 + X4) >> 14];                  blk[8 * 2] = iclp[(X0 + X4) >> 14];
# Line 342  Line 360 
360                  blk[8 * 7] = iclp[(X7 - X1) >> 14];                  blk[8 * 7] = iclp[(X7 - X1) >> 14];
361          }          }
362    
363  }                                                               // end function idct_int32(block)  }                                                               /* end function idct_int32(block) */
364    
365    
366  //void  /*void */
367  //idct_int32_init()  /*idct_int32_init() */
368  void  void
369  idct_int32_init()  idct_int32_init(void)
370  {  {
371          int i;          int i;
372    

Legend:
Removed from v.195  
changed lines
  Added in v.677

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