博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Converting Between YUV and RGB
阅读量:6293 次
发布时间:2019-06-22

本文共 2145 字,大约阅读时间需要 7 分钟。

It is frequently necessary to convert between YUV pixel formats (used by the JPEG and MPEG compression methods) and RGB format (used by many hardware manufacturers.) The following formulas show how to compute a pixel's value in one format from the pixel value in the other format.

YUV format allows for higher compression rates without a proportionately high loss of data, as the U and V portions can be highly compressed and computed from the non- or lowly-compressed Y portion.

Computer RGB888, or full-scale RGB, uses 8 bits each for the red, green, and blue channels. Black is represented by R = G = B = 0, and white is represented by R = G = B = 255. The 4:4:4 YUV format uses 8 bits each for the Y, U, and V channels.

Converting RGB888 to YUV

The following formulas define the conversion from RGB to YUV:

Y = ( (  66 * R + 129 * G +  25 * B + 128) >> 8) +  16U = ( ( -38 * R -  74 * G + 112 * B + 128) >> 8) + 128V = ( ( 112 * R -  94 * G -  18 * B + 128) >> 8) + 128

These formulas produce 8-bit results using coefficients that require no more than 8 bits of (unsigned) precision. Intermediate results require up to 16 bits of precision.

Converting 8-bit YUV to RGB888

The following coefficients are used in conversion process:

C = Y - 16D = U - 128E = V - 128

Using the previous coefficients and noting that clip() denotes clipping a value to the range of 0 to 255, the following formulas provide the conversion from YUV to RGB:

R = clip(( 298 * C           + 409 * E + 128) >> 8)G = clip(( 298 * C - 100 * D - 208 * E + 128) >> 8)B = clip(( 298 * C + 516 * D           + 128) >> 8)

These formulas use some coefficients that require more than 8 bits of precision to produce each 8-bit result, and intermediate results require more than 16 bits of precision.

Note   All units range from 0 (zero) to 1.0 (one). In DirectDraw, they range from 0 to 255. Overflow and underflow can (and does) occur, and the results must be saturated.

To convert 4:2:0 or 4:2:2 YUV to RGB, convert the YUV data to 4:4:4 YUV, and then convert from 4:4:4 YUV to RGB.


 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.

转载地址:http://eijta.baihongyu.com/

你可能感兴趣的文章
ART世界探险(19) - 优化编译器的编译流程
查看>>
玩转Edas应用部署
查看>>
music-音符与常用记号
查看>>
sql操作命令
查看>>
zip 数据压缩
查看>>
Python爬虫学习系列教程
查看>>
【数据库优化专题】MySQL视图优化(二)
查看>>
【转载】每个程序员都应该学习使用Python或Ruby
查看>>
PHP高级编程之守护进程,实现优雅重启
查看>>
PHP字符编码转换类3
查看>>
rsync同步服务配置手记
查看>>
http缓存知识
查看>>
Go 时间交并集小工具
查看>>
iOS 多线程总结
查看>>
webpack是如何实现前端模块化的
查看>>
TCP的三次握手四次挥手
查看>>
关于redis的几件小事(六)redis的持久化
查看>>
webpack4+babel7+eslint+editorconfig+react-hot-loader 搭建react开发环境
查看>>
Maven 插件
查看>>
初探Angular6.x---进入用户编辑模块
查看>>