[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 461, Tue Sep 10 20:38:24 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  /*****************************************************************************  /*****************************************************************************
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   *   *
  *  This program is an implementation of a part of one or more MPEG-4  
  *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending  
  *  to use this software module in hardware or software products are  
  *  advised that its use may infringe existing patents or copyrights, and  
  *  any such use would be at such party's own risk.  The original  
  *  developer of this software module and his/her company, and subsequent  
  *  editors and their companies, will have no liability for use of this  
  *  software or modifications or derivatives thereof.  
  *  
9   *  This program is free software; you can redistribute it and/or modify   *  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   *  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
# Line 29  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   *************************************************************************/   * $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. */
28    
29    /*
30     * Disclaimer of Warranty
31     *
32     * 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 54  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 77  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 91  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 101  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 112  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 120  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 129  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 140  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 157  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 165  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 176  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 184  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 193  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 */
 //void j_rev_dct(block)  
 //short *block;  
231  void  void
232  idct_int32(short *const block)  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 (!                  if (!
# Line 233  Line 266 
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 243  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 254  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 262  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 273  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 (!                  if (!
318                          ((X1 = (blk[8 * 4] << 8)) | (X2 = blk[8 * 6]) | (X3 =                          ((X1 = (blk[8 * 4] << 8)) | (X2 = blk[8 * 6]) | (X3 =
319                                                                                                                           blk[8 *                                                                                                                           blk[8 *
# Line 296  Line 329 
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    
 //void  
 //idct_int32_init()  
373  void  void
374  idct_int32_init()  idct_int32_init()
375  {  {

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

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