Doxygen Source Code Documentation
dct8.c File Reference
#include <stdio.h>#include <stdlib.h>#include <math.h>Go to the source code of this file.
| Defines | |
| #define | C1 0.980785 | 
| #define | S1 0.19509 | 
| #define | C3 0.83147 | 
| #define | S3 0.55557 | 
| #define | R2C6 0.541196 | 
| #define | R2S6 1.30656 | 
| #define | R2 1.41421 | 
| Functions | |
| void | dct8_ref (int *data) | 
| void | idct8_ref (int *data) | 
| void | dct8 (int *dctBlock) | 
| void | idct8 (int *dctBlock) | 
| void | fdct8 (float *vv) | 
| void | ifdct8 (float *vv) | 
| int | main (int argc, char *argv[]) | 
| Variables | |
| const double | PI = 3.14159265358979323 | 
Define Documentation
| 
 | 
| 
 | 
| 
 | 
| 
 | 
| 
 | 
| 
 | 
| 
 | 
| 
 | 
| 
 | 
| 
 | 
| 
 | 
| 
 | 
| 
 | 
| 
 | 
Function Documentation
| 
 | 
| 
 Definition at line 72 of file dct8.c. Referenced by main(). 
 00073 {
00074   static const int c1=1004 ; /* cos(pi/16)<<10 */
00075   static const int s1=200  ; /* sin(pi/16)<<10 */
00076   static const int c3=851  ; /* cos(3pi/16)<<10 */
00077   static const int s3=569  ; /* sin(3pi/16)<<10 */
00078   static const int r2c6=554; /* sqrt(2)*cos(6pi/16)<<10 */
00079   static const int r2s6=1337;
00080   static const int r2=181;   /* sqrt(2)<<7 */
00081   int x0=dctBlock[0], x1=dctBlock[1], x2=dctBlock[2], x3=dctBlock[3],
00082     x4=dctBlock[4], x5=dctBlock[5], x6=dctBlock[6], x7=dctBlock[7];
00083   int x8;
00084 
00085   /* Stage 1 */
00086   x8=x7+x0; x0-=x7;  x7=x1+x6; x1-=x6;
00087   x6=x2+x5; x2-=x5;  x5=x3+x4; x3-=x4;
00088 
00089   /* Stage 2 */
00090   x4=x8+x5; x8-=x5;  x5=x7+x6; x7-=x6;
00091   x6=c1*(x1+x2); x2=(-s1-c1)*x2+x6; x1=(s1-c1)*x1+x6;
00092   x6=c3*(x0+x3); x3=(-s3-c3)*x3+x6; x0=(s3-c3)*x0+x6;
00093 
00094   /* Stage 3 */
00095   x6=x4+x5; x4-=x5;
00096   x5=r2c6*(x7+x8); x7=(-r2s6-r2c6)*x7+x5; x8=(r2s6-r2c6)*x8+x5;
00097   x5=x0+x2;x0-=x2; x2=x3+x1; x3-=x1;
00098 
00099   /* Stage 4, round, and output */
00100   dctBlock[0]=x6;  dctBlock[4]=x4;
00101   dctBlock[2]=(x8+512)>>10; dctBlock[6] = (x7+512)>>10;
00102   dctBlock[7]=(x2-x5+512)>>10; dctBlock[1]=(x2+x5+512)>>10;
00103   dctBlock[3]=(x3*r2+65536)>>17; dctBlock[5]=(x0*r2+65536)>>17;
00104 }
 | 
| 
 | 
| 
 Definition at line 14 of file dct8.c. References PI. Referenced by main(). 
 00015 {
00016   double output[8] = {0};
00017   short x,n;
00018   for(x=0;x<8;x++) {
00019     for(n=0;n<8;n++)
00020       output[x] += data[n] * cos(PI * x * (2*n+1)/16.0);
00021   }
00022   for(x=0;x<8;x++) {
00023     output[x] /= 4.0;  /* Apply typical weighting to output */
00024     if(x==0) output[x] /= sqrt(2.0);
00025 
00026     output[x] *= 4.0 * sqrt(2);    /* Scale by sqrt(2)*4 */
00027 
00028     data[x] = floor(output[x] + 0.5); /* Round accurately */
00029   }
00030 }
 | 
| 
 | 
| 
 Definition at line 161 of file dct8.c. References C1, C3, R2, R2C6, R2S6, S1, S3, x0, and x2. Referenced by main(). 
 00162 {
00163   float x0=vv[0], x1=vv[1], x2=vv[2], x3=vv[3],
00164         x4=vv[4], x5=vv[5], x6=vv[6], x7=vv[7], x8 ;
00165 
00166   x8=x7+x0; x0-=x7;  x7=x1+x6; x1-=x6;
00167   x6=x2+x5; x2-=x5;  x5=x3+x4; x3-=x4;
00168 
00169   x4=x8+x5; x8-=x5;  x5=x7+x6; x7-=x6;
00170   x6=C1*(x1+x2); x2=(-S1-C1)*x2+x6; x1=(S1-C1)*x1+x6;
00171   x6=C3*(x0+x3); x3=(-S3-C3)*x3+x6; x0=(S3-C3)*x0+x6;
00172 
00173   x6=x4+x5; x4-=x5;
00174   x5=R2C6*(x7+x8); x7=(-R2S6-R2C6)*x7+x5; x8=(R2S6-R2C6)*x8+x5;
00175   x5=x0+x2;x0-=x2; x2=x3+x1; x3-=x1;
00176 
00177   vv[0]=x6     ; vv[4]=x4     ;
00178   vv[2]=x8     ; vv[6]=x7     ;
00179   vv[7]=(x2-x5); vv[1]=(x2+x5);
00180   vv[3]=x3*R2  ; vv[5]=x0*R2  ;
00181 }
 | 
| 
 | 
| 
 Definition at line 118 of file dct8.c. Referenced by main(). 
 00119 {
00120   static const int c1=251 ; /* cos(pi/16)<<8 */
00121   static const int s1=50  ; /* sin(pi/16)<<8 */
00122   static const int c3=213 ; /* cos(3pi/16)<<8 */
00123   static const int s3=142 ; /* sin(3pi/16)<<8 */
00124   static const int r2c6=277; /* cos(6pi/16)*sqrt(2)<<9 */
00125   static const int r2s6=669;
00126   static const int r2=181; /* sqrt(2)<<7 */
00127 
00128   /* Stage 4 */
00129   int x0=dctBlock[0]<<9, x1=dctBlock[1]<<7, x2=dctBlock[2],
00130     x3=dctBlock[3]*r2, x4=dctBlock[4]<<9, x5=dctBlock[5]*r2,
00131     x6=dctBlock[6], x7=dctBlock[7]<<7;
00132   int x8=x7+x1; x1 -= x7;
00133 
00134   /* Stage 3 */
00135   x7=x0+x4; x0-=x4; x4=x1+x5; x1-=x5; x5=x3+x8; x8-=x3;
00136   x3=r2c6*(x2+x6);x6=x3+(-r2c6-r2s6)*x6;x2=x3+(-r2c6+r2s6)*x2;
00137 
00138   /* Stage 2 */
00139   x3=x7+x2; x7-=x2; x2=x0+x6; x0-= x6;
00140   x6=c3*(x4+x5);x5=(x6+(-c3-s3)*x5)>>6;x4=(x6+(-c3+s3)*x4)>>6;
00141   x6=c1*(x1+x8);x1=(x6+(-c1-s1)*x1)>>6;x8=(x6+(-c1+s1)*x8)>>6;
00142 
00143   /* Stage 1, rounding and output */
00144   x7+=512; x2+=512;x0+=512;x3+=512;
00145   dctBlock[0]=(x3+x4)>>10;  dctBlock[1]=(x2+x8)>>10;
00146   dctBlock[2]=(x0+x1)>>10;  dctBlock[3]=(x7+x5)>>10;
00147   dctBlock[4]=(x7-x5)>>10;  dctBlock[5]=(x0-x1)>>10;
00148   dctBlock[6]=(x2-x8)>>10;  dctBlock[7]=(x3-x4)>>10;
00149 }
 | 
| 
 | 
| 
 Definition at line 39 of file dct8.c. References PI. Referenced by main(). 
 00040 {
00041   double output[8] = {0};
00042   short x,n;
00043   for(x=0;x<8;x++) {
00044     output[x]= data[0] / sqrt(2.0);
00045     for(n=1;n<8;n++)
00046       output[x] += data[n] * cos(PI * n * (2*x+1)/16.0);
00047   }
00048   for(x=0;x<8;x++) {
00049     output[x] /= 2.0;
00050     output[x] *= sqrt(2.0);
00051     data[x] = floor(output[x] + 0.5); /* Round accurately */
00052   }
00053 }
 | 
| 
 | 
| 
 Definition at line 182 of file dct8.c. References C1, C3, R2, R2C6, R2S6, S1, S3, x0, and x2. Referenced by main(). 
 00183 {
00184   float x0=vv[0]   , x1=vv[1], x2=vv[2]   ,
00185         x3=vv[3]*R2, x4=vv[4], x5=vv[5]*R2,
00186         x6=vv[6]   , x7=vv[7], x8=x7+x1    ;
00187 
00188   x1 -= x7;
00189 
00190   x7=x0+x4; x0-=x4; x4=x1+x5; x1-=x5; x5=x3+x8; x8-=x3;
00191   x3=R2C6*(x2+x6);x6=x3+(-R2C6-R2S6)*x6;x2=x3+(-R2C6+R2S6)*x2;
00192 
00193   x3=x7+x2; x7-=x2; x2=x0+x6; x0-= x6;
00194   x6=C3*(x4+x5);x5=(x6+(-C3-S3)*x5);x4=(x6+(-C3+S3)*x4);
00195   x6=C1*(x1+x8);x1=(x6+(-C1-S1)*x1);x8=(x6+(-C1+S1)*x8);
00196 
00197   vv[0]=(x3+x4)/8.0;  vv[1]=(x2+x8)/8.0;
00198   vv[2]=(x0+x1)/8.0;  vv[3]=(x7+x5)/8.0;
00199   vv[4]=(x7-x5)/8.0;  vv[5]=(x0-x1)/8.0;
00200   vv[6]=(x2-x8)/8.0;  vv[7]=(x3-x4)/8.0;
00201 }
 | 
| 
 | ||||||||||||
| convert DTIStudio fiber format data to SUMA segment data Definition at line 203 of file dct8.c. References argc, dct8(), dct8_ref(), fdct8(), idct8(), idct8_ref(), and ifdct8(). 
 00204 {
00205    int xx[8] = { 1,2,3,4,4,4,3,2 } ;
00206    int yy[8] ; float zz[8] ; int ii ;
00207 
00208    for( ii=0 ;ii < 8 ; ii++ ) zz[ii] = xx[ii] ;
00209 
00210    memcpy(yy,xx,sizeof(int)*8) ;
00211    printf("y = %d %d %d %d %d %d %d %d\n",
00212           yy[0],yy[1],yy[2],yy[3],yy[4],yy[5],yy[6],yy[7]) ;
00213    dct8_ref(yy) ;
00214    printf("dct8_ref = %d %d %d %d %d %d %d %d\n",
00215           yy[0],yy[1],yy[2],yy[3],yy[4],yy[5],yy[6],yy[7]) ;
00216    idct8_ref(yy) ;
00217    printf("idct8_ref = %d %d %d %d %d %d %d %d\n",
00218           yy[0],yy[1],yy[2],yy[3],yy[4],yy[5],yy[6],yy[7]) ;
00219 
00220    memcpy(yy,xx,sizeof(int)*8) ;
00221    dct8(yy) ;
00222    printf("dct8 = %d %d %d %d %d %d %d %d\n",
00223           yy[0],yy[1],yy[2],yy[3],yy[4],yy[5],yy[6],yy[7]) ;
00224    idct8(yy) ;
00225    printf("idct8 = %d %d %d %d %d %d %d %d\n",
00226           yy[0],yy[1],yy[2],yy[3],yy[4],yy[5],yy[6],yy[7]) ;
00227 
00228    fdct8(zz) ;
00229    printf("fdct8 = %g %g %g %g %g %g %g %g\n",
00230           zz[0],zz[1],zz[2],zz[3],zz[4],zz[5],zz[6],zz[7]) ;
00231    ifdct8(zz) ;
00232    printf("ifdct8 = %g %g %g %g %g %g %g %g\n",
00233           zz[0],zz[1],zz[2],zz[3],zz[4],zz[5],zz[6],zz[7]) ;
00234 
00235    exit(0) ;
00236 }
 | 
Variable Documentation
| 
 | 
| 
 Definition at line 5 of file dct8.c. Referenced by dct8_ref(), and idct8_ref(). | 
 
                             
                             
                             
                             
                             
                             
                             
                             
                             
                             
                             
                             
 
 
 
 
       
	   
	   
	   
	  