I am trying to rotate a bmp image 90 degrees clockwise. However, I am stuck on how. I've managed to make only a 180 degrees rotation. Here is my code for the 180 degrees rotation
int row_size = ((width * 3 + 3) / 4) * 4;
uint8_t* pixels = (uint8_t*)malloc(height * row_size);
fread(pixels, sizeof(uint8_t), height * row_size, input);
uint8_t* rotatedPixels = (uint8_t*)malloc(height * row_size);
for (uint32_t i = 0; i < width; ++i) {
for (uint32_t j = 0; j < height; ++j) {
uint32_t new_i = height - 1 - j;
uint32_t new_j = width - 1 - i;
rotatedPixels[(new_i * row_size) + (new_j * 3)] = pixels[(j * row_size) + (i * 3)];
rotatedPixels[(new_i * row_size) + (new_j * 3) + 1] = pixels[(j * row_size) + (i * 3) + 1];
rotatedPixels[(new_i * row_size) + (new_j * 3) + 2] = pixels[(j * row_size) + (i * 3) + 2];
}
}
fwrite(header, sizeof(uint8_t), 54, output);
fwrite(rotatedPixels, sizeof(uint8_t), height * row_size, output);
free(pixels);
free(rotatedPixels);
}