#include #include #include #include #include #include #include // always remeber , the no. of panels always remain the same in destination image , // only the panel size can vary /* _____________________- things to store in file : 1. image size - x , y ( int ) 2. panelsize 3. the Fractal codes for each destination panel */ using namespace std; using namespace Magick; const long MAXPANELS=200000; const int nsforms=8; const double _gamma=0.75; struct panel { int x,y; int panelsize; double mean; }; struct fractalcode { unsigned char x,y; char s; unsigned char gamma; short int beta; }; struct sform { int a,b,c,d; double con; int xpixels[1025]; int ypixels[1025]; }; char infile[80],outfile[80]; double image[1024][1024]; double rimage[1024][1024]; int rows,cols; int panelsize=4; // default int dxpanels,dypanels; panel destpanels[MAXPANELS]; int rxpanels,rypanels; panel refpanels[MAXPANELS]; int rrows,rcols; fractalcode fractalcodes[MAXPANELS]; sform sformlist[nsforms]={{1,0,0,1,0.5}, {-1,0,0,1,0.5}, {1,0,0,-1,0.5}, {-1,0,0,-1,0.5}, {0,1,1,0,0.5}, {0,-1,1,0,0.5}, {0,1,-1,0,0.5}, {0,-1,-1,0,0.5}}; //___fn. to get pixel for a panel inline double getpixel(panel p,int x,int y) { return image[p.y+y][p.x+x]; } //__fn to set pixel for a panel value inline void setpixel(panel p,int x,int y,double value) { image[p.y+y][p.x+x]=value; } void prepareall(int panelsize) { int i,j,k; int x,y; for(k=0;k<8;k++) { for(x=0;x> choice; if(choice!='y' && choice!='Y') return; cout << "Enter filename : " ; cin >> buffer; } Image fspectrum(Geometry(cols,rows),"white"); fspectrum.classType(DirectClass); fspectrum.quantizeColorSpace(GRAYColorspace); Pixels fview(fspectrum); PixelPacket *fpixels = fview.get(0,0,cols,rows); for(int x=0;x1.0) gamma=1.0; if(gamma<-1.0) gamma=-1.0; //beta=(d*d-r*r)/(panelsize*panelsize*d2-d*d); //cout << "\nGamma for refpanel : " << j << " = " << (panelsize*panelsize*dr-d*r) << " / " << (panelsize*panelsize*d2-d*d) << "=" << gamma; // calculate beta beta=0; for(x=0;x=rxpanels) {x=rxpanels-1;cout << "x>=rxpanels..." << flush;} if(y>=rypanels) {y=rypanels-1;cout << "y>=rypanels..." << flush;} //cout << "\nRefpanel no : " << x+y*rxpanels << " sform : " << int(fractalcodes[i].s) << "\ndestpanel no : " << i << flush; panel refpanel=refpanels[x+y*rxpanels]; panel destpanel=destpanels[i]; //cout << "\nStarting the double loop for transforming the doman to range block " << flush; for(j=0;j=1) {val=1; //cout << "\nval>1" << flush; } // cout << "\ncalling setpixel at ..." << j << "," << k << " Destpanel : " << destpanel.x << "," << destpanel.y << flush; setpixel(destpanel,j,k,val); } } // one iteration is finished here // repeat this many times to get the final image } void main() { while(1) { cout << endl << " MAIN MENU "; cout << endl << "---------------"; cout << endl << "1. Compress image"; cout << endl << "2. Decompress image"; cout << endl << "3. Exit"; cout << "\n\n\n"; cout << "Enter choice :"; char buffer[80]; fgets(buffer,79,stdin); int choice=atoi(buffer); if(choice==3) break; if(choice<1 || choice>>3) continue; cout << "\n\nEnter infile : "; cin >> infile; cout << "\nEnter outfile :"; cin >> outfile; if(choice==1) // compress file { cout << "\nPlease enter the panel size : "; cin >> panelsize; readimage(infile); if(cols%panelsize!=0 || rows%panelsize!=0) { cout << "\nImage resolution is not a multiple of panelsize. Re-enter." << flush; continue; } compress(outfile); cout << "\nMain : succesfully returned from function compress " << flush; } if(choice==2) // decompress image { int i,j; // first read the square image //int x,y; //cout << "\n Enter xres , yres :" << flush; //cin >> x,y; int xsize,ysize,psize; FILE* fp=fopen(infile,"rb"); fread(&xsize,sizeof(xsize),1,fp); fread(&ysize,sizeof(ysize),1,fp); fread(&psize,sizeof(psize),1,fp); int xpanels,ypanels; xpanels=xsize/psize; ypanels=ysize/psize; // always same int ncodes=xpanels*ypanels; fread(fractalcodes,sizeof(fractalcode),ncodes,fp); fclose(fp); cout << "\nCompression Panel size is " << psize << endl; cout << "\nEnter output panelsize : " << flush; cin >> panelsize; int x,y; x=(xsize/psize)*panelsize; y=(ysize/psize)*panelsize; cout << "\nInput resolution : " << xsize << "," << ysize ; cout << "\nOutput resolution : " << x << "," << y; /* char buffer[80]; sprintf(buffer,"convert -scale %dx%d square.gif s.gif",x,y); system(buffer); */ cols=x;rows=y; for(i=0;icols/2) image[i][j]=1; else image[i][j]=0; writeimage("s.gif"); cout << "\nReading s.gif ( the square image )..." << flush; readimage("s.gif"); // this has gone to image array // 8 iterations of decompress for(i=0;i<10;i++) { cout << "\nCalling iteration no : "<< i << flush; decompress(infile,xsize,ysize,psize); sprintf(buffer,"file%d.gif",i); writeimage(buffer); } // now image is in image cout << "\nWriting the image to : " << outfile << flush; writeimage(outfile); cout << "\nWritten the image to : " << outfile << flush; cout << "\nCheck it out..." << flush; } } }