#include #include #include typedef struct pixel_type { unsigned char r; unsigned char g; unsigned char b; } pixel_t; typedef struct image_type { char filename[64]; /* name of disk resident file */ char id[4]; /* P5 gray or P6 color */ int width; /* Width in pixel cols */ int height; /* depth in pixel rows */ pixel_t *pixels; /* Address of the pixel data */ } image_t; /* We can create a 5 x 4 pixel image for testing in this way */ /* Each {x, y, z} triple encodes the r, g, b components of */ /* a single pixel */ pixel_t pixmap[20] = { {33, 44, 51}, {31, 45, 11}, {23, 34, 41}, {53, 64, 71}, {23, 44, 31}, {33, 44, 51}, {32, 46, 21}, {23, 34, 41}, {53, 64, 71}, {23, 44, 31}, {33, 44, 51}, {33, 47, 31}, {23, 34, 41}, {53, 64, 71}, {23, 44, 31}, {33, 44, 51}, {34, 48, 41}, {23, 34, 41}, {53, 64, 71}, {23, 44, 31} }; /* We can initialize an image structure in this way */ /* By specifically enumerating the structure elements */ /* we wish to configure we don't have to initialize */ /* the entire structure */ /* Format is - element_name: element_vale, */ image_t image = { width: 5, height: 4, pixels: pixmap }; /* Read values into the 3 x 3 filter from the standard input */ int read_filter( double filt[3][3]) { ----------------------------------- } /* Print the values of the filter */ void print_filter( double filt[3][3]) { int i, j; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { fprintf(stdout, "%8.3lf ", filt[i][j]); } fprintf(stdout, "\n"); } } /* Apply fliter to the pixel and location (row, col) */ /* in the image.. Fill in and return the filtered */ /* pixel in "result" */ pixel_t apply_filter( image_t *image, double filt[3][3], int row, int col) { pixel_t result = {0, 0, 0}; int i, j, ndx; double rsum = 0.0; // Accumulate red, green and blue double gsum = 0.0; // channel sums here double bsum = 0.0; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { /* For each iteration of the inner loop add the product of */ /* filt[i][j] with the r, g, b components of the corresponding */ /* image pixel to rsum, gsum, and bsum */ -------------------------------------- } } /* Construct the result pixel and return it */ ------------------------------------- return(result); } int main() { pixel_t ans; int row, col; double filter[3][3]; read_filter(filter); print_filter(filter); /* Read in the location of the pixel to be filtered * / // fscanf(stdin, "%d %d", &row, &col); /* Apply the filter to the pixel */ // ans = apply_filter(&image, filter, row, col); /* Print out the value of the filtered pixel */ // fprintf(stdout, " R = %d G = %d B = %d \n", // ans.r, ans.g, ans.b); return(0); }