/*********************************************************/ /* program 10: apply look-up table */ /*********************************************************/ #define XSIZE 640 #define YSIZE 480 unsigned char *ir,*ig,*ib; unsigned char *or,*og,*ob; main() { long int x,y,i; unsigned char lut[256]; /* allocate input and output memory buffers */ ir = (unsigned char *)malloc(XSIZE*YSIZE); ig = (unsigned char *)malloc(XSIZE*YSIZE); ib = (unsigned char *)malloc(XSIZE*YSIZE); or = (unsigned char *)malloc(XSIZE*YSIZE); og = (unsigned char *)malloc(XSIZE*YSIZE); ob = (unsigned char *)malloc(XSIZE*YSIZE); /* read the input image */ read_image("input",ir,ig,ib); /* initialize look-up table (invert, for this example) */ for (i = 0; i <= 255; i++) lut[i] = 255 - i; /* apply look-up table to each pixel in image */ for (y = 0; y < YSIZE; y++) { for (x = 0; x < XSIZE; x++) { or[(y*XSIZE)+x] = lut[ir[(y*XSIZE)+x]]; og[(y*XSIZE)+x] = lut[ig[(y*XSIZE)+x]]; ob[(y*XSIZE)+x] = lut[ib[(y*XSIZE)+x]]; } } /* write the output image */ write_image("output",or,og,ob); /* free memory buffers */ free(ir); free(ig); free(ib); free(or); free(og); free(ob); }