Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » RGB to YUV to RGB

This thread is locked; no one can reply to it. rss feed Print
RGB to YUV to RGB
A J
Member #3,025
December 2002
avatar

i read somewhere that converting from RGB to YUV could be done with this

Y=.3R+.59G+.11B;
U=B-Y;
V=R-Y

but what is the conversion from YUV to RGB ?

___________________________
The more you talk, the more AJ is right. - ML

Krzysztof Kluczek
Member #4,191
January 2004
avatar

Just treat it as three equations and solve it. :)

B=Y+U;
R=Y+V;
G=(Y-.3R-.11B)/.59;

Kitty Cat
Member #2,815
October 2002
avatar

Actually:

  R = 1.164*(Y - 16)                 + crv*(V - 128)
  G = 1.164*(Y - 16) - cgu*(U - 128) - cgv*(V - 128)
  B = 1.164*(Y - 16) + cbu*(U - 128)
// where:
  /* For SMPTE 170M (NTSC;MPEG-1) */
  crv = 1.596f;
  cbu = 2.018f;
  cgu = 0.391f;
  cgv = 0.813f;

Assuming input and output is between 0 and 255. You also need to be warry over overflow/underflow and clamp accordingly.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

A J
Member #3,025
December 2002
avatar

Krzysztof Kluczek, i watch Shrek2 for the 1st time tonight..
nice avatar :)

___________________________
The more you talk, the more AJ is right. - ML

Go to: