[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 649, Sat Nov 16 23:51:58 2002 UTC revision 1382, Mon Mar 22 22:36:25 2004 UTC
# Line 1  Line 1 
1  /*****************************************************************************  /*****************************************************************************
2   *   *
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  - inverse fast disrete cosine transformation - integer C version   *  - Inverse DCT  -
5   *   *
6   *  These routines are from Independent JPEG Group's free JPEG software   *  These routines are from Independent JPEG Group's free JPEG software
7   *  Copyright (C) 1991-1998, Thomas G. Lane (see the file README.IJG)   *  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   *  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
  *  XviD is free software; you can redistribute it and/or modify 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   *  the Free Software Foundation; either version 2 of the License, or
12   *  (at your option) any later version.   *  (at your option) any later version.
13   *   *
# Line 22  Line 20 
20   *  along with this program; if not, write to the Free Software   *  along with this program; if not, write to the Free Software
21   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   *   *
23   *  Under section 8 of the GNU General Public License, the copyright   * $Id: idct.c,v 1.7 2004-03-22 22:36:23 edgomez Exp $
24   *  holders of XVID explicitly forbid distribution in the following   *
25   *  countries:   ****************************************************************************/
26   *  
27   *    - Japan  /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
28   *    - United States of America  
29   *  /*
30   *  Linking XviD statically or dynamically with other modules is making a   * Disclaimer of Warranty
  *  combined work based on XviD.  Thus, the terms and conditions of the  
  *  GNU General Public License cover the whole combination.  
  *  
  *  As a special exception, the copyright holders of XviD give you  
  *  permission to link XviD with independent modules that communicate with  
  *  XviD solely through the VFW1.1 and DShow interfaces, regardless of the  
  *  license terms of these independent modules, and to copy and distribute  
  *  the resulting combined work under terms of your choice, provided that  
  *  every copy of the combined work is accompanied by a complete copy of  
  *  the source code of XviD (the version of XviD used to produce the  
  *  combined work), being distributed under the terms of the GNU General  
  *  Public License plus this exception.  An independent module is a module  
  *  which is not derived from or based on XviD.  
  *  
  *  Note that people who make modified versions of XviD are not obligated  
  *  to grant this special exception for their modified versions; it is  
  *  their choice whether to do so.  The GNU General Public License gives  
  *  permission to release a modified version without this exception; this  
  *  exception also makes it possible to release a modified version which  
  *  carries forward this exception.  
31   *   *
32   * $Id: idct.c,v 1.4 2002-11-16 23:51:58 edgomez Exp $   * These software programs are available to the user without any license fee or
33     * royalty on an "as is" basis.  The MPEG Software Simulation Group disclaims
34     * any and all warranties, whether express, implied, or statuary, including any
35     * implied warranties or merchantability or of fitness for a particular
36     * purpose.  In no event shall the copyright-holder be liable for any
37     * incidental, punitive, or consequential damages of any kind whatsoever
38     * arising from the use of these programs.
39     *
40     * This disclaimer of warranty extends to the user of these programs and user's
41     * customers, employees, agents, transferees, successors, and assigns.
42     *
43     * The MPEG Software Simulation Group does not represent or warrant that the
44     * programs furnished hereunder are free of infringement of any third-party
45     * patents.
46     *
47     * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
48     * are subject to royalty fees to patent holders.  Many of these patents are
49     * general enough such that they are unavoidable regardless of implementation
50     * design.
51     *
52     * MPEG2AVI
53     * --------
54     * v0.16B33 renamed the initialization function to init_idct_int32()
55     * v0.16B32 removed the unused idct_row() and idct_col() functions
56     * v0.16B3  changed var declarations to static, to enforce data align
57     * v0.16B22  idct_FAST() renamed to idct_int32()
58     *        also merged idct_FAST() into a single function, to help VC++
59     *        optimize it.
60   *   *
61   *************************************************************************/   * v0.14  changed int to long, to avoid confusion when compiling on x86
62     *        platform ( in VC++ "int" -> 32bits )
63     */
64    
65  /**********************************************************/  /**********************************************************/
66  /* inverse two dimensional DCT, Chen-Wang algorithm       */  /* inverse two dimensional DCT, Chen-Wang algorithm       */
# Line 78  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    
   
 /* global declarations */  
 //void init_idct_int32 (void);  
 //void idct_int32 (short *block);  
   
88  /* private data */  /* private data */
89  static short iclip[1024];               /* clipping table */  static short iclip[1024];               /* clipping table */
90  static short *iclp;  static short *iclp;
91    
92  /* private prototypes */  /* private prototypes */
 //static void idctrow _ANSI_ARGS_((short *blk));  
 //static void idctcol _ANSI_ARGS_((short *blk));  
93    
94  /* row (horizontal) IDCT  /* row (horizontal) IDCT
95   *   *
# Line 101  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 115  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 125  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 136  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 144  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 153  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 164  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  /*  
169    #if 0
170  static void idctcol(blk)  static void idctcol(blk)
171  short *blk;  short *blk;
172  {  {
173    int X0, X1, X2, X3, X4, X5, X6, X7, X8;    int X0, X1, X2, X3, X4, X5, X6, X7, X8;
174    
175    // shortcut    /* shortcut  */
176    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]) |
177          (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])))
178    {    {
# Line 181  Line 183 
183    
184    X0 = (blk[8*0]<<8) + 8192;    X0 = (blk[8*0]<<8) + 8192;
185    
186    // first stage    /* first stage  */
187    X8 = W7*(X4+X5) + 4;    X8 = W7*(X4+X5) + 4;
188    X4 = (X8+(W1-W7)*X4)>>3;    X4 = (X8+(W1-W7)*X4)>>3;
189    X5 = (X8-(W1+W7)*X5)>>3;    X5 = (X8-(W1+W7)*X5)>>3;
# Line 189  Line 191 
191    X6 = (X8-(W3-W5)*X6)>>3;    X6 = (X8-(W3-W5)*X6)>>3;
192    X7 = (X8-(W3+W5)*X7)>>3;    X7 = (X8-(W3+W5)*X7)>>3;
193    
194    // second stage    /* second stage */
195    X8 = X0 + X1;    X8 = X0 + X1;
196    X0 -= X1;    X0 -= X1;
197    X1 = W6*(X3+X2) + 4;    X1 = W6*(X3+X2) + 4;
# Line 200  Line 202 
202    X6 = X5 + X7;    X6 = X5 + X7;
203    X5 -= X7;    X5 -= X7;
204    
205    // third stage    /* third stage  */
206    X7 = X8 + X3;    X7 = X8 + X3;
207    X8 -= X3;    X8 -= X3;
208    X3 = X0 + X2;    X3 = X0 + X2;
# Line 208  Line 210 
210    X2 = (181*(X4+X5)+128)>>8;    X2 = (181*(X4+X5)+128)>>8;
211    X4 = (181*(X4-X5)+128)>>8;    X4 = (181*(X4-X5)+128)>>8;
212    
213    // fourth stage    /* fourth stage */
214    blk[8*0] = iclp[(X7+X1)>>14];    blk[8*0] = iclp[(X7+X1)>>14];
215    blk[8*1] = iclp[(X3+X2)>>14];    blk[8*1] = iclp[(X3+X2)>>14];
216    blk[8*2] = iclp[(X0+X4)>>14];    blk[8*2] = iclp[(X0+X4)>>14];
# Line 217  Line 219 
219    blk[8*5] = iclp[(X0-X4)>>14];    blk[8*5] = iclp[(X0-X4)>>14];
220    blk[8*6] = iclp[(X3-X2)>>14];    blk[8*6] = iclp[(X3-X2)>>14];
221    blk[8*7] = iclp[(X7-X1)>>14];    blk[8*7] = iclp[(X7-X1)>>14];
222  }*/  }
223    #endif
224    
225  // function pointer  /* function pointer */
226  idctFuncPtr idct;  idctFuncPtr idct;
227    
228  /* two dimensional inverse discrete cosine transform */  /* two dimensional inverse discrete cosine transform */
 //void j_rev_dct(block)  
 //short *block;  
229  void  void
230  idct_int32(short *const block)  idct_int32(short *const block)
231  {  {
232    
233          // idct_int32_init() must be called before the first call to this function!          /*
234             * idct_int32_init() must be called before the first call to this
235             * function!
236             */
237    
238    
239          /*int i;  #if 0
240            int i;
241             long i;             long i;
242    
243             for (i=0; i<8; i++)             for (i=0; i<8; i++)
244             idctrow(block+8*i);             idctrow(block+8*i);
245    
246             for (i=0; i<8; i++)             for (i=0; i<8; i++)
247             idctcol(block+i); */                  idctcol(block+i);
248    #endif
249    
250          static short *blk;          static short *blk;
251          static long i;          static long i;
252          static long X0, X1, X2, X3, X4, X5, X6, X7, X8;          static long X0, X1, X2, X3, X4, X5, X6, X7, X8;
253    
254    
255          for (i = 0; i < 8; i++)         // idct rows          for (i = 0; i < 8; i++)         /* idct rows */
256          {          {
257                  blk = block + (i << 3);                  blk = block + (i << 3);
258                  if (!                  if (!
# Line 257  Line 264 
264                          continue;                          continue;
265                  }                  }
266    
267                  X0 = (blk[0] << 11) + 128;      // for proper rounding in the fourth stage                  X0 = (blk[0] << 11) + 128;      /* for proper rounding in the fourth stage  */
268    
269                  // first stage                  /* first stage  */
270                  X8 = W7 * (X4 + X5);                  X8 = W7 * (X4 + X5);
271                  X4 = X8 + (W1 - W7) * X4;                  X4 = X8 + (W1 - W7) * X4;
272                  X5 = X8 - (W1 + W7) * X5;                  X5 = X8 - (W1 + W7) * X5;
# Line 267  Line 274 
274                  X6 = X8 - (W3 - W5) * X6;                  X6 = X8 - (W3 - W5) * X6;
275                  X7 = X8 - (W3 + W5) * X7;                  X7 = X8 - (W3 + W5) * X7;
276    
277                  // second stage                  /* second stage  */
278                  X8 = X0 + X1;                  X8 = X0 + X1;
279                  X0 -= X1;                  X0 -= X1;
280                  X1 = W6 * (X3 + X2);                  X1 = W6 * (X3 + X2);
# Line 278  Line 285 
285                  X6 = X5 + X7;                  X6 = X5 + X7;
286                  X5 -= X7;                  X5 -= X7;
287    
288                  // third stage                  /* third stage  */
289                  X7 = X8 + X3;                  X7 = X8 + X3;
290                  X8 -= X3;                  X8 -= X3;
291                  X3 = X0 + X2;                  X3 = X0 + X2;
# Line 286  Line 293 
293                  X2 = (181 * (X4 + X5) + 128) >> 8;                  X2 = (181 * (X4 + X5) + 128) >> 8;
294                  X4 = (181 * (X4 - X5) + 128) >> 8;                  X4 = (181 * (X4 - X5) + 128) >> 8;
295    
296                  // fourth stage                  /* fourth stage  */
297    
298                  blk[0] = (short) ((X7 + X1) >> 8);                  blk[0] = (short) ((X7 + X1) >> 8);
299                  blk[1] = (short) ((X3 + X2) >> 8);                  blk[1] = (short) ((X3 + X2) >> 8);
# Line 297  Line 304 
304                  blk[6] = (short) ((X3 - X2) >> 8);                  blk[6] = (short) ((X3 - X2) >> 8);
305                  blk[7] = (short) ((X7 - X1) >> 8);                  blk[7] = (short) ((X7 - X1) >> 8);
306    
307          }                                                       // end for ( i = 0; i < 8; ++i ) IDCT-rows          }                                                       /* end for ( i = 0; i < 8; ++i ) IDCT-rows */
308    
309    
310    
311          for (i = 0; i < 8; i++)         // idct columns          for (i = 0; i < 8; i++)         /* idct columns */
312          {          {
313                  blk = block + i;                  blk = block + i;
314                  // shortcut                  /* shortcut  */
315                  if (!                  if (!
316                          ((X1 = (blk[8 * 4] << 8)) | (X2 = blk[8 * 6]) | (X3 =                          ((X1 = (blk[8 * 4] << 8)) | (X2 = blk[8 * 6]) | (X3 =
317                                                                                                                           blk[8 *                                                                                                                           blk[8 *
# Line 320  Line 327 
327    
328                  X0 = (blk[8 * 0] << 8) + 8192;                  X0 = (blk[8 * 0] << 8) + 8192;
329    
330                  // first stage                  /* first stage  */
331                  X8 = W7 * (X4 + X5) + 4;                  X8 = W7 * (X4 + X5) + 4;
332                  X4 = (X8 + (W1 - W7) * X4) >> 3;                  X4 = (X8 + (W1 - W7) * X4) >> 3;
333                  X5 = (X8 - (W1 + W7) * X5) >> 3;                  X5 = (X8 - (W1 + W7) * X5) >> 3;
# Line 328  Line 335 
335                  X6 = (X8 - (W3 - W5) * X6) >> 3;                  X6 = (X8 - (W3 - W5) * X6) >> 3;
336                  X7 = (X8 - (W3 + W5) * X7) >> 3;                  X7 = (X8 - (W3 + W5) * X7) >> 3;
337    
338                  // second stage                  /* second stage  */
339                  X8 = X0 + X1;                  X8 = X0 + X1;
340                  X0 -= X1;                  X0 -= X1;
341                  X1 = W6 * (X3 + X2) + 4;                  X1 = W6 * (X3 + X2) + 4;
# Line 339  Line 346 
346                  X6 = X5 + X7;                  X6 = X5 + X7;
347                  X5 -= X7;                  X5 -= X7;
348    
349                  // third stage                  /* third stage  */
350                  X7 = X8 + X3;                  X7 = X8 + X3;
351                  X8 -= X3;                  X8 -= X3;
352                  X3 = X0 + X2;                  X3 = X0 + X2;
# Line 347  Line 354 
354                  X2 = (181 * (X4 + X5) + 128) >> 8;                  X2 = (181 * (X4 + X5) + 128) >> 8;
355                  X4 = (181 * (X4 - X5) + 128) >> 8;                  X4 = (181 * (X4 - X5) + 128) >> 8;
356    
357                  // fourth stage                  /* fourth stage  */
358                  blk[8 * 0] = iclp[(X7 + X1) >> 14];                  blk[8 * 0] = iclp[(X7 + X1) >> 14];
359                  blk[8 * 1] = iclp[(X3 + X2) >> 14];                  blk[8 * 1] = iclp[(X3 + X2) >> 14];
360                  blk[8 * 2] = iclp[(X0 + X4) >> 14];                  blk[8 * 2] = iclp[(X0 + X4) >> 14];
# Line 358  Line 365 
365                  blk[8 * 7] = iclp[(X7 - X1) >> 14];                  blk[8 * 7] = iclp[(X7 - X1) >> 14];
366          }          }
367    
368  }                                                               // end function idct_int32(block)  }                                                               /* end function idct_int32(block) */
369    
370    
 //void  
 //idct_int32_init()  
371  void  void
372  idct_int32_init()  idct_int32_init()
373  {  {

Legend:
Removed from v.649  
changed lines
  Added in v.1382

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