YUV420只绘制Y通道

来源:互联网 发布:手机木马软件购买 编辑:程序博客网 时间:2024/06/06 11:38

前段时间整个一个yuv文件,格式为352x240,YUV420格式的,即YYYYUUVV,准备使用Qt进行重绘显示。不知道为什么转换为RGB显示出来乱乱的,

最近做只显示出Y通道的灰度图像,刚做成功。

灰度图像即RGB三颜色是一样的,需要建立一个8位的256级的灰度索引表,用0~255表示颜色的深度。

然后构建一个8位的QImage并设置它的颜色索引表,让它去颜色表中查颜色。

Qt中的QImage提供了对每一个像素的操作。

关键是setPixel这个函数。


void QImage::setPixel(const QPoint & position, uint index_or_rgb)
Sets the pixel index or color at the given position to index_or_rgb.

If the image's format is either monochrome or 8-bit, the given index_or_rgb value must be an index in the image's color table, otherwise the parameter must be a QRgb value.

If position is not a valid coordinate pair in the image, or if index_or_rgb >= colorCount() in the case of monochrome and 8-bit images, the result is undefined.

Warning: This function is expensive due to the call of the internal detach() function called within; if performance is a concern, we recommend the use of scanLine() to access pixel data directly.




上面的代码还是让人费解的。修改为下面的效果是一样的。从代码的理解上也是,从Y平面数组中查找了Y通道的每个像素点的数据

然后查灰度颜色表,再设置QImage每个像素点的颜色。(即灰度)



现在显示Y通道的图像成功了,下一步要加入U,V让图像显示出颜色来以加深根据YUV数据进行RGB图像重构的方法。

以及YUV数据存储跟实际像素的对应关系。


0 0
原创粉丝点击