/* testImage.c This program converts an input image to gray scale or sepia depending on the provided command line inputs. Compile: cc testImage.c imageUtils.c -o testImage -std=c99 -lm Run: ./testImage sugarbear.jpg test.jpg 2 */ #include #include #include "colorUtils.h" #include "imageUtils.h" void DumpImage( Pixel **image, int height, int width ); int main(int argc, char **argv) { char *inputFile = NULL; char *outputFile = NULL; int mode = 1; if( argc == 3 || argc == 4 ) { inputFile = argv[1]; outputFile = argv[2]; if( argc == 4 ) { mode = atoi(argv[3]); } } else { fprintf(stderr, "Usage:" ); fprintf(stderr, " %s inputFileName outputFileName [mode]\n", argv[0]); fprintf(stderr, " [mode: 1 = Average (default), 2 = Red,\n" ); fprintf(stderr, " 3 = Luminosity, 4 = Sepia]\n" ); exit(1); } int h, w; Pixel **image = LoadImage(inputFile, &h, &w); if( mode == 1 ) { ImageToGrayScale( image, h, w, AVERAGE ); } else if( mode == 2 ) { ExtractRGB( image, h, w, RED ); /* other options */ } else { fprintf(stderr, "Invalid mode\n"); } // show numerical values DumpImage( image, h, w ); SaveImage(outputFile, image, h, w); return 0; } /* should probably be in imageUtils.c */ void DumpImage( Pixel **image, int height, int width ) { printf( "%d %d\n", height, width ); for(int i = 0; i