/**************************************************************************** * Func: rotate_90 * * * * Desc: rotates an image clockwise by simply transposing rows. * * No interpolation * * * * Params: buffer - pointer to image in memory * * fileout - output file name * * rows - number of rows in source image * * cols - number of cols in source image * * type - file type (5 = PGM 6 = PPM) * ****************************************************************************/ void rotate_90(image_ptr buffer, char *fileout, int rows, int cols, int type) { unsigned long x,y; /* x and y indices to source image */ unsigned long index; /* index to output line buffer */ unsigned long source_index; /* index into source image */ unsigned char *line_buff; /* line buffer */ unsigned line; /* size of line in pixels */ FILE *fp; /* output file pointer */ int temp; /* temp variable */ pixel_ptr color_buff; /* pointer to a color image */ /* open new output file */ if((fp=fopen(fileout, "wb")) == NULL) { printf("Unable to open %s for output\n",fileout); exit(1); } /* swap rows and cols */ temp = rows; rows = cols; cols = temp; /* print out the portable bitmap header */ fprintf(fp, "P%d\n%d %d\n255\n", type, cols, rows); if(type == 5) /* PGM file */ line = cols; else /* PPM file */ { line = cols * 3; color_buff = (pixel_ptr) buffer; } line_buff = (unsigned char *) malloc(line); for(y=0; y