Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function to convert YCbCr to RGB?

Tags:

c

rgb

graphics

I have Y,Cb,Cr values each of 8 bit, can you give me simple C function which converts it to R,G,B each of 8 bit.

Here is a prototype of it.

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 correct conversion formula only. Because I am finding it different everywhere. Even I am also expert in C,C++

like image 268
SunnyShah Avatar asked Oct 28 '10 10:10

SunnyShah


1 Answers

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 :-).

  • YUV coded data comes from analog sources (PAL video decoder, S-Video, ...)
  • YPbPr coded data also comes from analog sources but produces better color results as YUV (Component Video)
  • YCbCr coded data comes from digital sources (DVB, HDMI, ...)

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).

like image 121
jdehaan Avatar answered Oct 05 '22 06:10

jdehaan