#include #include #include #include #include "paulslib.h" #include "bitmaplib.h" /* Proof of concept code to turn lens distorted (No really a distortion) into idealis perspective projections (aka pinhole camera) */ void GiveUsage(char *); /* Alpha1 and alpha2 are constants for the transformation equations, they will be small positive numbers Determined for a particular lens by trial and error If the lines are bowed inwards (concave) then increase the appropriate constant. If they are bowed out (convex) then decrease the corresponding constant. eg: for test image seen so far Lens alphax alphay 35mm 0.02 0.075 40mm 0.016 0.059 50mm 0.006 0.03 */ double alphax = 0.02, alphay = 0.08; /* Level of antialiasing */ int aa = 3; /* Size of the output image */ int nxout,nyout; int main(int argc,char **argv) { int nx,ny,depth; int i,j,i2,j2,ii,jj,aacount; double x,y,x2,x3,y2,y3,r; COLOUR csum; BITMAP4 *image,*output1,*output2; BITMAP4 c,grey = {128,128,128,255}; FILE *fptr; /* If there are any arguments assume alphx and alphay */ if (argc < 2) GiveUsage(argv[0]); /* Parse command line */ for (i=1;i= 0 && i2 < nx && j2 >= 0 && j2 < ny) { c = Get_Pixel(image,nx,ny,i2,j2); csum.r += c.r; csum.g += c.g; csum.b += c.b; aacount++; } } } if (aacount > 0) { c.r = csum.r / aacount; c.g = csum.g / aacount; c.b = csum.b / aacount; c.a = 0; Draw_Pixel(output1,nxout,nyout,i,j,c); } } } /* Write the first image */ if ((fptr = fopen("1.tga","wb")) != NULL) { Write_Bitmap(fptr,output1,nxout,nyout,12); fclose(fptr); } /* Create the secnd image */ output2 = Create_Bitmap(nxout,nyout); for (i=0;i= 0 && i2 < nxout && j2 >= 0 && j2 < nyout) { c = Get_Pixel(output1,nxout,nyout,i2,j2); csum.r += c.r; csum.g += c.g; csum.b += c.b; aacount++; } } } if (aacount > 0) { c.r = csum.r / aacount; c.g = csum.g / aacount; c.b = csum.b / aacount; c.a = 0; Draw_Pixel(output2,nxout,nyout,i,j,c); } } } if ((fptr = fopen("2.tga","wb")) != NULL) { Write_Bitmap(fptr,output2,nxout,nyout,12); fclose(fptr); } exit(0); } void GiveUsage(char *s) { fprintf(stderr,"Usage: %s [-k n1 n2] [-a n] [-h] tgafilename\n",s); exit(-1); }