本文主要是介绍NV21图像旋转,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
// 顺时针90度
static void rotateYUV420Degree90(uint8_t * data, uint8_t * yuv, int imageWidth, int imageHeight) {// Rotate the Y lumaint 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 componentsi = 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;
}
这篇关于NV21图像旋转的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!