1、顺时针旋转90度
void RGB24RotateClockwise90(uint8_t* src,uint8_t* dst, int width, int height)
{
int w;
int h;
int src_row_bytes;
int dst_row_bytes;
uint8_t* img;
uint8_t* ptr;
int i, j;
unsigned int size;
unsigned int off1;
unsigned int off2;
int off;
w = height;
h = width;
src_row_bytes = (width * 3 + 3) & ~3;
dst_row_bytes = (w * 3 + 3) & ~3;
off1 = 0;
off2 = (w - 1) * 3;
for(i = 0; i < height; i++)
{
img = src + off1;
ptr = dst + off2;
for(j = 0; j < width; j++)
{
ptr[0] = img[0];
ptr[1] = img[1];
ptr[2] = img[2];
img += 3;
ptr += dst_row_bytes;
}
off1 += src_row_bytes;
off2 = (w - i - 1) * 3;
}
}
2、逆时针旋转90度:
void RGB24RotateAnticlockwise90(uint8_t* src,uint8_t* dst, int width, int height)
{
int w;
int h;
int src_row_bytes;
int dst_row_bytes;
unsigned char* img;
unsigned char* ptr;
int i, j;
unsigned int off1;
unsigned int off2;
w = height;
h = width;
src_row_bytes = (width * 3 + 3) & ~3;
dst_row_bytes = (w * 3 + 3) & ~3;
off1 = (width - 1) * 3;
off2 = 0;;
for(i = 0; i < height; i++)
{
img = src + off1;
ptr = dst + off2;
for(j = 0; j < width; j++)
{
ptr[0] = img[0];
ptr[1] = img[1];
ptr[2] = img[2];
img -= 3;
ptr += dst_row_bytes;
}
off1 += src_row_bytes;
off2 = i * 3;
}
}