将 YCbCr 转换为 RGB 的函数?
我有 Y、Cb 和 Cr 值,每个值的大小均为 8 位。可以将这些值转换为 R、G、B(每个值均为 8 位)的简单 C 函数是什么?
这是我正在寻找的函数的原型:
void convertYCbCrToRGB(
unsigned char Y,
unsigned char cg,
unsigned char cb,
unsigned char &r,
unsigned char &g,
unsigned char &b);
PS 我只是在寻找正确的转换公式,因为我到处都找到了它的不同版本。我非常精通 C/C++。
I have Y, Cb and Cr values, each with a size of 8 bits. What would be a simple C function which can convert these values to R,G,B (each with a size of 8 bits)?
Here is a prototype of the function I am looking for:
void convertYCbCrToRGB(
unsigned char Y,
unsigned char cg,
unsigned char cb,
unsigned char &r,
unsigned char &g,
unsigned char &b);
P.S.
I am looking for the correct conversion formula only, since I have found different versions of it everywhere. I am very well-versed in C/C++.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
问题来了,几乎每个人都混淆了 YCbCr YUV 和 YPbPr。所以你能找到的文学作品通常都是蹩脚的。首先你必须知道你是否真的有 YCbCr 或者是否有人对你撒谎:-)。
YPbPr 和 YCbCr 相关。以下是正确的公式:
https://web .archive.org/web/20180421030430/http://www.equasys.de/colorconversion.html
(添加 archive.org 是为了修复旧的、损坏的链接)。
The problem comes that nearly everybody confuses YCbCr YUV and YPbPr. So literature you can find is often crappy. First you have to know if you really have YCbCr or if someone lies to you :-).
YPbPr and YCbCr are related. Here are the right formulae:
https://web.archive.org/web/20180421030430/http://www.equasys.de/colorconversion.html
(the archive.org has been added to fix the old, broken link).
这是我对问题的解决方案。
这是全范围 YCbCr 到 RGB 转换例程。
Here is my solution to my question.
This one is Full Range YCbCr to RGB conversion routine.
YCbCr 的 ITU-R 标准的整数运算是(来自维基百科)
或等效但更简洁的:
不要忘记将 r、g 和 b 的值限制在 [0,255] 范围内。
Integer operation of ITU-R standard for YCbCr is (from Wikipedia)
or equivalently but more concisely to :
do not forget to clamp values of r, g and b within [0,255].
查看此页面。它包含有关转换公式的有用信息。
顺便说一句,您可以返回一个 unsigned int ,其中包含从最高有效字节到最低有效字节编码的 RGBA 值,即
Check out this page. It contains useful information on conversion formulae.
As an aside, you could return a unsigned int with the values for RGBA encoded from the most significant byte to least significant byte, i.e.