#include #include #include #include #include #include #include /* _____________________- things to store in file : 1. image size - x , y ( int ) 2. no of panels on each side - xpanels , ypanels ( int ) 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 { short int x,y; short int s; short int beta; }; struct sform { int a,b,c,d; double con; int xpixels[128]; int ypixels[128]; }; char infile[80],outfile[80]; double image[512][512]; double rimage[256][256]; int rows,cols; int panelsize; 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;x=rxpanels) x=rxpanels-1; if(y>=rypanels) y=rypanels-1; cout << "\nRefpanel no : " << x+y*rxpanels << " sform : " << 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;j1) val=1; //cout << "\ncalling setpixel..." << 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 { readimage(infile); compress(outfile); cout << "\nMain : succesfully returned from function compress " << flush; } if(choice==2) // decompress image { int i; // first read the square image int x,y; cout << "\n Enter xres , yres :" << flush; cin >> x,y; char buffer[80]; sprintf(buffer,"convert -scale %dx%d square.gif s.gif",x,y); system(buffer); 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<15;i++) { cout << "\nCalling iteration no : "<< i << flush; decompress(infile); 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; } } }