Main Page   File List   File Members  

dct_trf.c

Go to the documentation of this file.
00001 //
00002 // Copyright Onur G. Guleryuz
00003 //
00004 //
00005 #include <math.h>
00006 #include <stdio.h>
00007 #include <stdlib.h>
00008 #include "support_routines.h"
00009 
00010 #if !defined(PI)
00011 
00012 #define PI 3.14159265358979
00013 #endif
00014 
00015 
00016 /* generate a 1-d dct
00017    rows of H are the 1-dct basis */
00018 
00019 float **gen_1d_dct(int N)
00020 
00021 {
00022    int i,j;
00023    float **H;
00024 
00025    H=allocate_2d_float(N,N,0);
00026    for(i=0;i<N;i++)
00027       for(j=0;j<N;j++)
00028          H[i][j]=(float)(sqrt(2.0/N)*cos(PI*i*(2.0*j+1)/(2.0*N)));
00029    for(j=0;j<N;j++)
00030       H[0][j]/=(float)sqrt(2.0);
00031    return(H);
00032    }
00033 
00034 #define BUFFER_SIZE (256)
00035 
00036 // Forward 2-d dct of one (bx X bx) block in the matrix starting at (pi,pj). 
00037 // Results are returned in trf starting at (si,sj).
00038 // bx is the block DCT size. H is the 1d DCT basis matrix 
00039 // (can be generated via gen_1d_dct()).
00040 void trf_one_block_dct_2d(float **matrix,int pi,int pj,float **trf,int si,int sj,
00041                         int bx,float **H)
00042 
00043 {
00044         int k,l,m;
00045         float tmp,buf[BUFFER_SIZE];
00046 
00047 
00048         if(bx>BUFFER_SIZE) {
00049 
00050                 printf("Large DCT_SIZE, please increase BUFFER_SIZE in code to match\n");
00051                 exit(1);
00052         }
00053 
00054         // Transform columns first.
00055         for(k=0;k<bx;k++)
00056                 for(l=0;l<bx;l++) {
00057 
00058                         tmp=0;
00059                         for(m=0;m<bx;m++)
00060                                 tmp+=H[k][m]*matrix[pi+m][pj+l];
00061                         trf[si+k][sj+l]=tmp;
00062                         }
00063 
00064         // Now transform rows.
00065         for(k=0;k<bx;k++) {
00066 
00067                 for(l=0;l<bx;l++) {
00068 
00069                         tmp=0;
00070                         for(m=0;m<bx;m++)
00071                                 tmp+=H[l][m]*trf[si+k][sj+m];
00072                         buf[l]=tmp;
00073                 }
00074                                 
00075                 for(l=0;l<bx;l++)
00076                         trf[si+k][sj+l]=buf[l];
00077         }
00078 
00079 }
00080 
00081 
00082 // Inverse 2-d dct of one (bx X bx) block in trf starting at (si,sj). 
00083 // Results are returned in matrix starting at (pi,pj).
00084 // bx is the block DCT size. H is the 1d DCT basis matrix 
00085 // (can be generated via gen_1d_dct()).
00086 
00087 void inv_trf_one_block_dct_2d(float **trf,int si,int sj,float **matrix,int pi,int pj,
00088                         int bx,float **H)
00089 
00090 {
00091         int k,l,m;
00092         float tmp,buf[BUFFER_SIZE];
00093 
00094 
00095         if(bx>BUFFER_SIZE) {
00096 
00097                 printf("Large DCT_SIZE, please increase BUFFER_SIZE in code to match\n");
00098                 exit(1);
00099         }
00100 
00101         // Inverse transform rows first.
00102         for(k=0;k<bx;k++)
00103                 for(l=0;l<bx;l++) {
00104 
00105                         tmp=0;
00106                         for(m=0;m<bx;m++)
00107                                 tmp+=H[m][l]*trf[si+k][sj+m];
00108                         matrix[pi+k][pj+l]=tmp;
00109                         }
00110 
00111         // Now inverse transform columns.
00112         for(l=0;l<bx;l++) {
00113                         
00114                 for(k=0;k<bx;k++) {
00115 
00116                         tmp=0;
00117                         for(m=0;m<bx;m++)
00118                                 tmp+=H[m][k]*matrix[pi+m][pj+l];
00119                         buf[k]=tmp;
00120                 }
00121                 for(k=0;k<bx;k++)
00122                         matrix[pi+k][pj+l]=buf[k];
00123         }
00124 }
00125 

Generated on Fri Jan 16 00:15:42 2004 for Image_Recovery_Proof_of_Concept_Code by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002