Main Page | Class List | File List | Class Members | File Members

vid_dct.c File Reference

#include "vid_macros.h"
#include "vid_sim.h"
#include <math.h>

Go to the source code of this file.

Defines

#define PI   3.14159265358979323846

Functions

int Dct (int *block, int *coeff)
void init_idctref ()
void idctref (int *coeff, int *block)

Variables

int zigzag [8][8]
double c [8][8]


Define Documentation

#define PI   3.14159265358979323846
 

Definition at line 60 of file vid_dct.c.

Referenced by init_idctref().


Function Documentation

int Dct int *  block,
int *  coeff
 

Definition at line 89 of file vid_dct.c.

References zigzag.

Referenced by MB_Encode().

00090 {
00091   int        j1, i, j, k;
00092   float b[8];
00093   float        b1[8];
00094   float        d[8][8];
00095   float f0=(float).7071068;
00096   float f1=(float).4903926;
00097   float f2=(float).4619398;
00098   float f3=(float).4157348;
00099   float f4=(float).3535534;
00100   float f5=(float).2777851;
00101   float f6=(float).1913417;
00102   float f7=(float).0975452;
00103 
00104   for (i = 0, k = 0; i < 8; i++, k += 8) {
00105     for (j = 0; j < 8; j++) {
00106       b[j] = (float)block[k+j];
00107     }
00108     /* Horizontal transform */
00109     for (j = 0; j < 4; j++) {
00110       j1 = 7 - j;
00111       b1[j] = b[j] + b[j1];
00112       b1[j1] = b[j] - b[j1];
00113     }
00114     b[0] = b1[0] + b1[3];
00115     b[1] = b1[1] + b1[2];
00116     b[2] = b1[1] - b1[2];
00117     b[3] = b1[0] - b1[3];
00118     b[4] = b1[4];
00119     b[5] = (b1[6] - b1[5]) * f0;
00120     b[6] = (b1[6] + b1[5]) * f0;
00121     b[7] = b1[7];
00122     d[i][0] = (b[0] + b[1]) * f4;
00123     d[i][4] = (b[0] - b[1]) * f4;
00124     d[i][2] = b[2] * f6 + b[3] * f2;
00125     d[i][6] = b[3] * f6 - b[2] * f2;
00126     b1[4] = b[4] + b[5];
00127     b1[7] = b[7] + b[6];
00128     b1[5] = b[4] - b[5];
00129     b1[6] = b[7] - b[6];
00130     d[i][1] = b1[4] * f7 + b1[7] * f1;
00131     d[i][5] = b1[5] * f3 + b1[6] * f5;
00132     d[i][7] = b1[7] * f7 - b1[4] * f1;
00133     d[i][3] = b1[6] * f3 - b1[5] * f5;
00134   }
00135   /* Vertical transform */
00136   for (i = 0; i < 8; i++) {
00137     for (j = 0; j < 4; j++) {
00138       j1 = 7 - j;
00139       b1[j] = d[j][i] + d[j1][i];
00140       b1[j1] = d[j][i] - d[j1][i];
00141     }
00142     b[0] = b1[0] + b1[3];
00143     b[1] = b1[1] + b1[2];
00144     b[2] = b1[1] - b1[2];
00145     b[3] = b1[0] - b1[3];
00146     b[4] = b1[4];
00147     b[5] = (b1[6] - b1[5]) * f0;
00148     b[6] = (b1[6] + b1[5]) * f0;
00149     b[7] = b1[7];
00150     d[0][i] = (b[0] + b[1]) * f4;
00151     d[4][i] = (b[0] - b[1]) * f4;
00152     d[2][i] = b[2] * f6 + b[3] * f2;
00153     d[6][i] = b[3] * f6 - b[2] * f2;
00154     b1[4] = b[4] + b[5];
00155     b1[7] = b[7] + b[6];
00156     b1[5] = b[4] - b[5];
00157     b1[6] = b[7] - b[6];
00158     d[1][i] = b1[4] * f7 + b1[7] * f1;
00159     d[5][i] = b1[5] * f3 + b1[6] * f5;
00160     d[7][i] = b1[7] * f7 - b1[4] * f1;
00161     d[3][i] = b1[6] * f3 - b1[5] * f5;
00162   }
00163   /* Zigzag - scanning */
00164   for (i = 0; i < 8; i++) {
00165     for (j = 0; j < 8; j++) {
00166       *(coeff + zigzag[i][j]) = (int)(d[i][j]);
00167     }
00168   }
00169   return 0;
00170 }

void idctref int *  coeff,
int *  block
 

Definition at line 313 of file vid_dct.c.

References c, and zigzag.

Referenced by MB_Decode().

00314 {
00315   int i, j, k, v;
00316   double partial_product;
00317   double tmp[64];
00318   int tmp2[64];
00319   extern int zigzag[8][8];
00320 
00321   for (i=0; i<8; i++)
00322     for (j=0; j<8; j++)
00323       tmp2[j+i*8] = *(coeff + zigzag[i][j]);
00324 
00325   for (i=0; i<8; i++)
00326     for (j=0; j<8; j++)
00327     {
00328       partial_product = 0.0;
00329 
00330       for (k=0; k<8; k++)
00331         partial_product+= c[k][j]*tmp2[8*i+k];
00332 
00333       tmp[8*i+j] = partial_product;
00334     }
00335 
00336   /* Transpose operation is integrated into address mapping by switching 
00337      loop order of i and j */
00338 
00339   for (j=0; j<8; j++)
00340     for (i=0; i<8; i++)
00341     {
00342       partial_product = 0.0;
00343 
00344       for (k=0; k<8; k++)
00345         partial_product+= c[k][i]*tmp[8*k+j];
00346 
00347       v = (int)floor(partial_product+0.5);
00348       block[8*i+j] = (v<-256) ? -256 : ((v>255) ? 255 : v);
00349     }
00350 
00351 
00352 }

void init_idctref void   ) 
 

Definition at line 298 of file vid_dct.c.

References c, and PI.

Referenced by new_video_codec().

00299 {
00300   int freq, time;
00301   double scale;
00302 
00303   for (freq=0; freq < 8; freq++)
00304   {
00305     scale = (freq == 0) ? sqrt(0.125) : 0.5;
00306     for (time=0; time<8; time++)
00307       c[freq][time] = scale*cos((PI/8.0)*freq*(time + 0.5));
00308   }
00309 }


Variable Documentation

double c[8][8] [static]
 

Definition at line 294 of file vid_dct.c.

Referenced by idctref(), and init_idctref().

int zigzag[8][8]
 

Initial value:

 {
  {0, 1, 5, 6,14,15,27,28},
  {2, 4, 7,13,16,26,29,42},
  {3, 8,12,17,25,30,41,43},
  {9,11,18,24,31,40,44,53},
  {10,19,23,32,39,45,52,54},
  {20,22,33,38,46,51,55,60},
  {21,34,37,47,50,56,59,61},
  {35,36,48,49,57,58,62,63},
}

Definition at line 64 of file vid_dct.c.

Referenced by Dct(), and idctref().


Generated on Sun Jul 16 16:27:47 2006 by  doxygen 1.3.9.1