Main Page | File List

IDCTREF.C

00001 /* idctref.c, Inverse Discrete Fourier Transform, double precision          */
00002 
00003 /*
00004  * tmndecode 
00005  * Copyright (C) 1995 Telenor R&D
00006  *                    Karl Olav Lillevold <kol@nta.no>                    
00007  *
00008  * based on mpeg2decode, (C) 1994, MPEG Software Simulation Group
00009  * and mpeg2play, (C) 1994 Stefan Eckart
00010  *                         <stefan@lis.e-technik.tu-muenchen.de>
00011  *
00012  */
00013 
00014 
00015 /*  Perform IEEE 1180 reference (64-bit floating point, separable 8x1
00016  *  direct matrix multiply) Inverse Discrete Cosine Transform
00017 */
00018 
00019 
00020 /* Here we use math.h to generate constants.  Compiler results may
00021    vary a little */
00022 
00023 #include <math.h>
00024 
00025 #include "config.h"
00026 
00027 #ifndef PI
00028 #  define PI 3.14159265358979323846
00029 #endif
00030 
00031 /* global declarations */
00032 void init_idctref _ANSI_ARGS_((void));
00033 void idctref _ANSI_ARGS_((short *block));
00034 
00035 /* private data */
00036 
00037 /* cosine transform matrix for 8x1 IDCT */
00038 static double c[8][8];
00039 
00040 /* initialize DCT coefficient matrix */
00041 
00042 void init_idctref()
00043 {
00044   int freq, time;
00045   double scale;
00046 
00047   for (freq=0; freq < 8; freq++)
00048   {
00049     scale = (freq == 0) ? sqrt(0.125) : 0.5;
00050     for (time=0; time<8; time++)
00051       c[freq][time] = scale*cos((PI/8.0)*freq*(time + 0.5));
00052   }
00053 }
00054 
00055 /* perform IDCT matrix multiply for 8x8 coefficient block */
00056 
00057 void idctref(block)
00058 short *block;
00059 {
00060   int i, j, k, v;
00061   double partial_product;
00062   double tmp[64];
00063 
00064   for (i=0; i<8; i++)
00065     for (j=0; j<8; j++)
00066     {
00067       partial_product = 0.0;
00068 
00069       for (k=0; k<8; k++)
00070         partial_product+= c[k][j]*block[8*i+k];
00071 
00072       tmp[8*i+j] = partial_product;
00073     }
00074 
00075   /* Transpose operation is integrated into address mapping by switching 
00076      loop order of i and j */
00077 
00078   for (j=0; j<8; j++)
00079     for (i=0; i<8; i++)
00080     {
00081       partial_product = 0.0;
00082 
00083       for (k=0; k<8; k++)
00084         partial_product+= c[k][i]*tmp[8*k+j];
00085 
00086       v = floor(partial_product+0.5);
00087       block[8*i+j] = (v<-256) ? -256 : ((v>255) ? 255 : v);
00088     }
00089 }

Generated on Mon May 8 22:27:08 2006 by  doxygen 1.3.9.1