/*************************************************************************** * Func: median_shrink * * * * Desc: reduces an image using median representation * * * * 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 median_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; /* source base address */ unsigned long sourceadd; /* source address = source base + offset */ int winx, winy; /* x and y window indices */ int new_rows; /* number of rows in new image */ int new_cols; /* number of columns in new image */ int new_pixel; /* new output pixel */ int windex; /* 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; 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