#include #include #include #include #include "paulslib.h" #include "bitmaplib.h" /* Turn a perspective image into a lens affected one. */ void GiveUsage(char *); /* Alpha1 and alpha2 are constants for the transformation equations, they will be small positive numbers */ double alphax = 0.02, alphay = 0.08; /* Level of antialiasing */ int aa = 3; 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,nx,ny,i,j,c); } } } /* Write the first image */ if ((fptr = fopen("1.tga","wb")) != NULL) { Write_Bitmap(fptr,output1,nx,ny,12); fclose(fptr); } /* Create the secnd image */ output2 = Create_Bitmap(nx,ny); for (i=0;i= 0 && i2 < nx && j2 >= 0 && j2 < ny) { c = Get_Pixel(output1,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(output2,nx,ny,i,j,c); } } } if ((fptr = fopen("2.tga","wb")) != NULL) { Write_Bitmap(fptr,output2,nx,ny,12); fclose(fptr); } exit(0); } void GiveUsage(char *s) { fprintf(stderr,"Usage: %s [-k n1 n2] [-a n] [-h] tgafilename\n",s); exit(-1); }