/*********************************************************/ /* program 2: convert rgb to cym */ /*********************************************************/ #define MAX 255 #define XSIZE 640 #define YSIZE 480 unsigned char *ir,*ig,*ib; unsigned char *oc,*om,*oy; main() { long int x,y; /* allocate input and output memory buffers */ ir = (unsigned char *) malloc (XSIZE*YSIZE); ig = (unsigned char *) malloc (XSIZE*YSIZE); ib = (unsigned char *) malloc (XSIZE*YSIZE); oc = (unsigned char *) malloc (XSIZE*YSIZE); om = (unsigned char *) malloc (XSIZE*YSIZE); oy = (unsigned char *) malloc (XSIZE*YSIZE); /* read the rgb input image */ read_image("input",ir,ig,ib); /* convert each pixel to cym */ for (y = 0; y < YSIZE; y = y++) { for (x = 0; x < XSIZE; x = x++) { oc[(y*XSIZE)+x] = MAX - ir[(y*XSIZE)+x]; /* cyan */ om[(y*XSIZE)+x] = MAX - ig[(y*XSIZE)+x]; /* magenta */ oy[(y*XSIZE)+x] = MAX - ib[(y*XSIZE)+x]; /* yellow */ } } /* write the output image */ /* note: if the output image is displayed on an rgb monitor it will appear like a negative, but if it is printed on a cym printer it will appear correct. */ write_image("output",oc,oy,om); /* free memory buffers */ free (ir); free (ig); free (ib); free (oc); free (om); free (oy); }