1、旋转算法
void rotateYUV420Degree270(char* src, char* dest, int m_nWidth, int m_nHeight) {
// H264LOG("H264Encoder::rotateYUV420Degree270 enter m_nWidth = ", m_nWidth);
int srcImageWidth = m_nHeight;
int srcImageHeight = m_nWidth;
int imageSize = m_nWidth*m_nHeight;
// Rotate the Y luma
int i = 0;
for(int x = srcImageWidth-1;x >= 0;x--)
{
for(int y = 0;y < srcImageHeight;y++)
{
dest[i] = src[y*srcImageWidth+x];
i++;
}
}
// H264LOG("H264Encoder::rotateYUV420Degree270 rotate Y.");
// Rotate the U and V color components
i = imageSize;
for(int x = srcImageWidth-1;x > 0;x=x-2)
{
for(int y = 0;y < srcImageHeight/2;y++)
{
dest[i] = src[imageSize+(y*srcImageWidth)+(x-1)];
i++;
dest[i] = src[imageSize+(y*srcImageWidth)+x];
i++;
}
}
// H264LOG("H264Encoder::rotateYUV420Degree270 exit.");
}
void rotateYUV420Degree90(char *src, char *des, int m_nWidth, int m_nHeight)
{
int width = m_nHeight;
int height = m_nWidth;
int wh = width * height;
//旋转Y
int k = 0;
for(int i = 0; i < width; i++) {
for(int j = 0; j < height; j++)
{
des[k] = src[width * j + i];
k++;
}
}
for(int i = 0; i < width; i += 2) {
for(int j = 0; j < height / 2; j++)
{
des[k] = src[wh+ width * j + i];
des[k+1] = src[wh + width * j + i + 1];
k+=2;
}
}
}