/* This is an example of reading and writing an image using the ppmIO.c routines. To manipulate the image, change the pixel color values. */ #include #include #include "ppmIO.h" #define USECPP 0 int main(int argc, char *argv[]) { Pixel *image; int rows, cols, colors; long imagesize; long i, j; if(argc < 3) { printf("Usage: ppmtest \n"); exit(-1); } /* read in the image */ image = readPPM(&rows, &cols, &colors, argv[1]); if(!image) { fprintf(stderr, "Unable to read %s\n", argv[1]); exit(-1); } /* calculate the image size */ imagesize = (long)rows * (long)cols; /* mess with the image here */ for(i=0;i 0 ? j < 128 ? j*2 : j : 0; image[i].g = image[i].b = 0; } /* write out the resulting image */ writePPM(image, rows, cols, colors /* s/b 255 */, argv[2]); /* free the image memory */ #if USECPP delete[] image; #else free(image); #endif return(0); }