#include #include #include #include #include template int ReadImage(char* fileName,SquareGrid& red,SquareGrid& green,SquareGrid& blue){ char* ext=GetFileExtension(fileName); Image32 img; if(!strcasecmp(ext,"bmp")){BMPReadImage(fileName,img);} else if(!strcasecmp(ext,"jpg") || !strcasecmp(ext,"jpeg")){JPEGReadImage(fileName,img);} else{ fprintf(stderr,"Unsupported image extension: %s\n",ext); delete[] ext; return 0; } delete[] ext; int w,h,r; w=img.width(); h=img.height(); r=(w>h)?w:h; red.resize(r); green.resize(r); blue.resize(r); for(int i=0;i int WriteImage(SquareGrid& red,SquareGrid& green,SquareGrid& blue,char* fileName){ if(red.resolution()!=green.resolution() || red.resolution()!=blue.resolution()){ fprintf(stderr,"Resolutions differ: red[%d] green[%d] blue[%d]\n",red.resolution(),green.resolution(),blue.resolution()); return 0; } Image32 img; int r=red.resolution(); img.setSize(r,r); for(int i=0;i1){r=1;} if(g<0){g=0;} if(g>1){g=1;} if(b<0){b=0;} if(b>1){b=1;} p.r=(unsigned char)(r*255.0); p.g=(unsigned char)(g*255.0); p.b=(unsigned char)(b*255.0); img(i,j)=p; } } char* ext=GetFileExtension(fileName); if(!strcasecmp(ext,"bmp")){BMPWriteImage(img,fileName);} else if(!strcasecmp(ext,"jpg") || !strcasecmp(ext,"jpeg")){JPEGWriteImage(img,fileName);} else{ fprintf(stderr,"Unsupported image extension: %s\n",ext); delete[] ext; return 0; } delete[] ext; return 1; } int main(int argc,char* argv[]){ // Read the parameters in from the command line cmdLineString In,Out,Extension; cmdLineInt Steps; cmdLineFloat Duration; char* paramNames[]={"in","out","steps","duration","extension"}; cmdLineReadable* params[]={&In,&Out,&Steps,&Duration,&Extension}; cmdLineParse(argc-1,&argv[1],paramNames,sizeof(paramNames)/sizeof(char*),params); if(!In.set || !Out.set || !Steps.set || !Duration.set || !Extension.set){ fprintf(stderr,"Usage %s:\n",argv[0]); fprintf(stderr,"\t--in \n"); fprintf(stderr,"\t--out \n"); fprintf(stderr,"\t--duration \n"); fprintf(stderr,"\t--steps \n"); fprintf(stderr,"\t--extension \n"); return EXIT_FAILURE; } SquareGrid<> rGrid,bGrid,gGrid; FourierKey2D<> rKey,gKey,bKey,rTemp,bTemp,gTemp; FourierTransform<> xForm; // Read in the image and compute the Fourier transform of the different channels ReadImage(In.value,rGrid,gGrid,bGrid); xForm.ForwardFourier(rGrid,rKey); xForm.ForwardFourier(gGrid,gKey); xForm.ForwardFourier(bGrid,bKey); // Allocate space for the temporary Fourier coefficients rTemp.resize(rKey.resolution()); gTemp.resize(gKey.resolution()); bTemp.resize(bKey.resolution()); for(int i=0;i