/*************************************************************************** * Func: average_shrink * * * * Desc: Reduces an image using pixel averages * * * * Params: source - pointer to image in memory * * cols - number of columns in image * * rows - number of rows in image * * filename - name of output file * * side - width of block * ***************************************************************************/ void average_shrink(image_ptr source, int cols, int rows, char *filename, int side) { int x, y, i; /* image loop variables */ int index; /* image index */ FILE *fp; /* output file pointer */ int *window; /* window for block samples */ int wsize; /* number of elements in block */ unsigned char *line_buff; /* storage for line */ unsigned long sourcebase; /* base address in source image */ unsigned long sourceadd; /* sourcebase plus a column offset */ int winx, winy; /* x and y indices in image window */ int new_rows; /* number of rows in new output image */ int new_cols; /* number of columns in new output image */ int new_pixel; /* newly generated pixel for output image */ int windex; /* image window index */ if((fp=fopen(filename, "wb")) == NULL) { printf("Unable to open %s for output\n",filename); exit(1); } wsize = side * side; new_rows = rows/side; new_cols = cols/side; /* allocate memory for storage */ window = malloc(wsize * sizeof(int)); line_buff = (unsigned char *) malloc(new_cols); fprintf(fp, "P5\n%d %d\n255\n", new_cols, new_rows); /* print out header */ for(y=0; y