/*********************************************************************/ /* PhotoLab.c: final assignment for EECS 10 in Summer 2013 */ /* */ /* modifications: (most recent first) */ /* 09/02/13 RD adjusted for lecture usage */ /*********************************************************************/ /*** header files ***/ #include #include /*** global definitions ***/ #define WIDTH 640 /* image width */ #define HEIGHT 410 /* image height */ #define SLEN 80 /* max. string length */ /*** function declarations ***/ int WriteImage(char Filename[SLEN], unsigned char R[WIDTH][HEIGHT], unsigned char G[WIDTH][HEIGHT], unsigned char B[WIDTH][HEIGHT]); int ReadImage(char Filename[SLEN], unsigned char R[WIDTH][HEIGHT], unsigned char G[WIDTH][HEIGHT], unsigned char B[WIDTH][HEIGHT]); void ModifyImage(unsigned char R[WIDTH][HEIGHT], unsigned char G[WIDTH][HEIGHT], unsigned char B[WIDTH][HEIGHT]); /*** function definitions ***/ /* write the RGB image to a PPM file */ /* (return 0 for success, >0 for error) */ int WriteImage( char Filename[SLEN], unsigned char R[WIDTH][HEIGHT], unsigned char G[WIDTH][HEIGHT], unsigned char B[WIDTH][HEIGHT]) { FILE *File; int x, y; File = fopen(Filename, "w"); if (!File) { printf("\nCannot open file \"%s\" for writing!\n", Filename); return(1); } fprintf(File, "P6\n"); fprintf(File, "%d %d\n", WIDTH, HEIGHT); fprintf(File, "255\n"); for(y=0; y0 for error) */ int ReadImage( char Filename[SLEN], unsigned char R[WIDTH][HEIGHT], unsigned char G[WIDTH][HEIGHT], unsigned char B[WIDTH][HEIGHT]) { FILE *File; char Type[SLEN]; int Width, Height, MaxValue; int x, y; File = fopen(Filename, "r"); if (!File) { printf("\nCannot open file \"%s\" for reading!\n", Filename); return(1); } fscanf(File, "%79s", Type); if (Type[0] != 'P' || Type[1] != '6' || Type[2] != 0) { printf("\nUnsupported file format!\n"); return(2); } fscanf(File, "%d", &Width); if (Width != WIDTH) { printf("\nUnsupported image width %d!\n", Width); return(3); } fscanf(File, "%d", &Height); if (Height != HEIGHT) { printf("\nUnsupported image height %d!\n", Height); return(4); } fscanf(File, "%d", &MaxValue); if (MaxValue != 255) { printf("\nUnsupported image maximum value %d!\n", MaxValue); return(5); } if ('\n' != fgetc(File)) { printf("\nCarriage return expected!\n"); return(6); } for(y=0; y