// 顺时针90度
static void rotateYUV420Degree90(uint8_t * data, uint8_t * yuv, int imageWidth, int imageHeight) {
// Rotate the Y luma
int i = 0;
for (int x = 0; x < imageWidth; x++) {
for (int y = imageHeight - 1; y >= 0; y--) {
yuv[i] = data[y * imageWidth + x];
i++;
}
}
// Rotate the U and V color components
i = imageWidth * imageHeight * 3 / 2 - 1;
for (int x = imageWidth - 1; x > 0; x = x - 2) {
for (int y = 0; y < imageHeight / 2; y++) {
yuv[i] = data[(imageWidth * imageHeight) + (y * imageWidth) + x];
i--;
yuv[i] = data[(imageWidth * imageHeight) + (y * imageWidth) + (x - 1)];
i--;
}
}
}
// 顺时针180度
static void rotateYUV420Degree180(uint8_t * data, uint8_t * yuv, int imageWidth, int imageHeight) {
int i = 0;
int count = 0;
for (i = imageWidth * imageHeight - 1; i >= 0; i--) {
yuv[count] = data[i];
count++;
}
i = imageWidth * imageHeight * 3 / 2 - 1;
for (i = imageWidth * imageHeight * 3 / 2 - 1; i >= imageWidth
* imageHeight; i -= 2) {
yuv[count++] = data[i - 1];
yuv[count++] = data[i];
}
}
// 顺时针270度
static void rotateYUV420Degree270(uint8_t * data, uint8_t * out, int imageWidth, int imageHeight) {
uint8_t * yuv = new uint8_t[imageWidth * imageHeight * 3 / 2];
rotateYUV420Degree90(data, yuv, imageWidth, imageHeight);
rotateYUV420Degree180(yuv, out, imageHeight, imageWidth);
if( yuv != NULL )
delete [] yuv;
}
05-31