YUV4:2:2 UYVY图像旋转
来源:互联网 发布:淘宝没有自然流量 编辑:程序博客网 时间:2024/05/20 06:54
原文:http://blog.csdn.net/zhangyonggen/article/details/48522593
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);psrc = source + offset;for (int j = 0; j < height; ++j){int k = j % 2;// 拷贝4个字节*((unsigned int *)pdst[k]) = *((unsigned int *)psrc); // Y分量交换,保证每个像素点的亮度不改变否则产生锯齿if(1 == k){unsigned char temp = *(pdst[0] - 1);*(pdst[0] - 1) = *(pdst[1] + 1);*(pdst[1] + 1) = temp;} pdst[k] += copyBytes;psrc -= bytesPerLine;}dest += step;source += copyBytes;} memcpy(src, dst, width * height * 2); delete[] dst; return true;}
2、旋转180度
旋转180度相对来说较为简单,从左上角开始与右下角相互交换,由于每两个像素点共享一对UV分量,所以交换的字节数为4字节,但是还需要保证Y分量的位置正确,所以还需要交换Y分量。
bool Rotate180(unsigned char *src, int width, int height){ const int copyBytes = 4;const int totalBytes = height * width << 1; const int end = totalBytes >> 1;unsigned char *dst = src + totalBytes - copyBytes;for (int i = 0; i < end; i += copyBytes){ unsigned int tmp = *((unsigned int *)dst);*((unsigned int *)dst) = *((unsigned int *)src); *((unsigned int *)src) = tmp; // 交换Y分量unsigned char temp = dst[1];dst[1] = dst[3];dst[3] = temp; temp = src[1];src[1] = src[3];src[3] = temp;dst -= copyBytes;src += copyBytes;} return true;}
3、旋转270度
与旋转90度相类似
bool Rotate270(unsigned char *src, int width, int height){ const int copyBytes = 4;const int bytesPerLine = width << 1;const int step = height << 2;const int offset = bytesPerLine - copyBytes; 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[1] = dest;pdst[0] = dest + (height << 1);psrc = source + offset;for (int j = 0; j < height; ++j){int k = j % 2;*((unsigned int *)pdst[k]) = *((unsigned int *)psrc);if(1 == k){unsigned char temp = *(pdst[1] + 1);*(pdst[1] + 1) = *(pdst[0] - 1);*(pdst[0] - 1) = temp;}pdst[k] += copyBytes;psrc += bytesPerLine;}dest += step;source -= copyBytes;} memcpy(src, dst, width * height * 2); delete[] dst; return true;}
阅读全文
0 0
- YUV4:2:2 UYVY图像旋转
- YUV4:2:2 UYVY图像旋转
- YUV4:2:2与YUV4:2:0区别
- YUV4:2:2和YUV4:2:0 区别
- yuv4:2:0 转成 IplImage
- 《图像处理》Part1 YUV4:2:2toYUV4:2:0、YUV420toYUV422、YUV422toRGB24、YUV420toRGB24算法
- YUV4:2:2格式压缩成JPEG
- YUV4:2:0 与色度采样
- YUV4:2:0格式的帧信息
- YUV4:2:2转换成RGB的代码
- YUV4:2:2转换成RGB的代码
- 2D图像中点的旋转
- 利用OpenCV旋转图像的摸索(2)
- 2D图像中点的旋转
- 视频YUV4:2:2转4:2:0的TI DSP源代码
- 视频YUV4:2:2转4:2:0的TI DSP源代码
- 视频YUV4:2:2转4:2:0的TI DSP源代码
- 视频YUV4:2:2转4:2:0的TI DSP源代码
- cleartool 基本操作
- 排序
- 加密工具之DES
- Kinect虚拟试衣
- Android并发网络请求,刚好碰到token失效的处理方案
- YUV4:2:2 UYVY图像旋转
- MD5加密算法
- Android 强大的spannableStringBuilder
- 对Handler机制的”粗“理解
- shell删除txt文档第一行
- 设计模式六大原则例子(五)-- 最少知识原则(LKP)/ 迪米特法则(LOD)例子
- PHPExcel学习记录(一)
- Codeforces 609D Gadgets for dollars and pounds【二分+贪心】
- 详细介绍Serializable的使用和注意事项