YUV4:2:2 UYVY 格式在内存中的存储方式为交织类型,内存中的存储方式为:UYVY UYVY UYVY...........,Y为亮度信息,UV为色度信息,YUV4:2:2是每两个像素点共用一对UV分量,每个像素点的Y分量是独立的,UV分量是共享的,所以一幅图像的总的字节数totalBytes = width × height + width * height / 2 + width * height / 2 = width * height * 2;在进行旋转操作是必须满足UYVY的结构不变即4个字节为一组,否则会产生颜色不对、锯齿等,也必须保证Y分量在相应的位置上:
1、旋转90度
bool Rotate90(unsigned char *src, int width, int height)
{
const int copyBytes = 4;
const int bytesPerLine = width << 1;
const int step = height << 2;
const int offset = (height - 1) * bytesPerLine;
unsigned char *dst = new (std::nothrow)BYTE[bytesPerLine * height];
if(NULL == dst)
{
return false;
}
unsigned char * dest = dst;
unsigned char * source = src;
unsigned char * psrc = NULL;
unsigned char * pdst[2] = {NULL, NULL};
for (int i = 0; i < bytesPerLine; i += copyBytes)
{
pdst[0] = dest;
pdst[1] = dest + (height << 1);
</