对图像进行离散余弦变换(DCT)处理(图像变换)的源代码#defineEXTRA_NAME@dcttransform.#includeloadbmp.h#definePoint(x,y)lpPoints[(x)+(y)*nWidth]voidFFT(COMPLEX*TD,COMPLEX*FD,intpower){intcount;inti,j,k,bfsize,p;doubleangle;COMPLEX*W,*X1,*X2,*X;count=1power;W=(COMPLEX*)malloc(sizeof(COMPLEX)*count/2);X1=(COMPLEX*)malloc(sizeof(COMPLEX)*count);X2=(COMPLEX*)malloc(sizeof(COMPLEX)*count);for(i=0;icount/2;i++){angle=-i*pi*2/count;W[i].re=cos(angle);W[i].im=sin(angle);}memcpy(X1,TD,sizeof(COMPLEX)*count);for(k=0;kpower;k++){for(j=0;j1k;j++){bfsize=1(power-k);for(i=0;ibfsize/2;i++){p=j*bfsize;X2[i+p]=Add(X1[i+p],X1[i+p+bfsize/2]);X2[i+p+bfsize/2]=Mul(Sub(X1[i+p],X1[i+p+bfsize/2]),W[i*(1k)]);}}X=X1;X1=X2;X2=X;}for(j=0;jcount;j++){p=0;for(i=0;ipower;i++){if(j&(1i))p+=1(power-i-1);}FD[j]=X1[p];}free(W);free(X1);free(X2);}voidDCT_Pre(double*f,double*F,intpower){inti,count;COMPLEX*X;doubles;count=1power;X=(COMPLEX*)malloc(sizeof(COMPLEX)*count*2);memset(X,0,sizeof(COMPLEX)*count*2);for(i=0;icount;i++){X[i].re=f[i];}FFT(X,X,power+1);s=1/sqrt(count);F[0]=X[0].re*s;s*=sqrt(2);for(i=1;icount;i++){F[i]=(X[i].re*cos(i*pi/(count*2))+X[i].im*sin(i*pi/(count*2)))*s;}free(X);}voidDct(){intw=1,h=1,wp=0,hp=0;while(w*2=nWidth){w*=2;wp++;}while(h*2=nHeight){h*=2;hp++;}intx,y;BYTE*lpPoints=newBYTE[nWidth*nHeight];GetPoints(lpPoints);double*f=newdouble[w*h];double*W=newdouble[w*h];for(y=0;yh;y++){for(x=0;xw;x++){f[x+y*w]=Point(x,y);}}for(y=0;yh;y++){DCT_Pre(&f[w*y],&W[w*y],wp);}for(y=0;yh;y++){for(x=0;xw;x++){f[x*h+y]=W[x+w*y];}}for(x=0;xw;x++){DCT_Pre(&f[x*h],&W[x*h],hp);}doublea;memset(lpPoints,0,nWidth*nHeight);for(y=0;yh;y++){for(x=0;xw;x++){a=fabs(W[x*h+y]);if(a255)a=255;Point(x,nHeight-y-1)=(BYTE)(a);}}deletef;deleteW;PutPoints(lpPoints);deletelpPoints;}voidmain(intargc,char*argv[]){if(argc==2)FileName=argv[1];elsereturn;OpenFile();Dct();SaveAs();}