An uncompressed 24-bit .bmp file
I need to rotate a .bmp file given a rotation multiple of 90. For example, i have an image and im given a +90 or -90 rotation factor. my image will rotate 90 degrees to the left or to the right according to the rotation factor. my program works fine when the dimensions of the file are equal, meaning height & width are equal, but when i do it with an image thats not a square i get seg errors.
this is the code that i have so far.
if(rotation == 90 || rotation == -270 )
{
/* 90 = -270 */
for(row = 0; row < rows; row++)
{
for(col = 0; col < cols; col++ )
{
PIXEL* o = original+ (row*cols) + col;
PIXEL* n = (*new)+((cols-col-1)*cols) + row;
*n = *o;
}
}
*newcols = cols;
*newrows = rows;
the header of this method is:
int rotate(PIXEL* original, int rows, int cols, int rotation,
PIXEL** new, int* newrows, int* newcols)
where PIXEL* original contains the original .bmp file
rows and cols are obtained by a call to the method that read the .bmp file
rotation = is the rotation factor given by the user