1、顺时针旋转90度:
void RGB32RotateClockwise90(uint8_t* src,uint8_t* dst, int width, int height)
{
int w;
int h;
int src_row_bytes;
uint8_t* img;
uint8_t* ptr;
int i, j;
unsigned int off1;
unsigned int off2;
int dst_row_bytes;
w = height;
h = width;
src_row_bytes = width << 2;
dst_row_bytes = w << 2;
off1 = 0;
off2 = (w - 1) << 2;
for(i = 0; i < height; i++)
{
ptr = dst + off2;
img = src + off1;
for(j = 0; j < width; j++)
{
*((uint32_t*)ptr) = *((uint32_t*)img);
img += 4;
ptr += dst_row_bytes;
}
off1 += src_row_bytes;
off2 = (w - i - 1) * 4;
}
}
2、逆时针旋转90度:
void RGB32RotateAntiClockwise90(uint8_t* src,uint8_t* dst, int width, int height)
{
int w;
int h;
int src_row_bytes;
uint8_t* img;
uint8_t* ptr;
int i, j;
unsigned int off1;
unsigned int off2;
int dst_row_bytes;
w = height;
h = width;
src_row_bytes = width << 2;
dst_row_bytes = w << 2;
off1 = (width-1) << 2;
off2 = 0;
for(i = 0; i < height; i++)
{
ptr = dst + off2;
img = src + off1;
for(j = 0; j < width; j++)
{
*((uint32_t*)ptr) = *((uint32_t*)img);
img -= 4;
ptr += dst_row_bytes;
}
off1 += src_row_bytes;
off2 = i * 4;
}
}
32位位图没有字节对齐问题,处理相对简单。