work under construction.
Should cover RGB->YUV conversions and lumarange scaling/preservation and when to use which conversion.
Color conversions
coefficients | Rec.601 | Rec.709 | FCC |
Kr : Red channel coefficient | 0.299 | 0.2125 | 0.3 |
Kg : Green channel coefficient | 0.587 | 0.7154 | 0.59 |
Kb : Blue channel coefficient | 0.114 | 0.0721 | 0.11 |
(0.0 <= [Y,R,G,B] <= 1.0) ; (-1.0 < [U,V] < 1.0)
Kg = 1 - Kr - Kb
Y = Kr*R + Kg*G + Kb*B
V = (R - Y)/(1-Kr) = R - G * Kg/(1-Kr) - B * Kb/(1-Kr)
U = (B - Y)/(1-Kb) = - R * Kr/(1-Kb) - G * Kg/(1-Kb) + B
R = Y + V*(1-Kr)
G = Y - U*(1-Kb)*Kb/Kg - V*(1-Kr)*Kr/Kg
B = Y + U*(1-Kb)
Converting to programming values
YUV [0,255] <-> RGB [0,255] (0 <= [r,g,b] <= 255, 0 <= y <= 255, -127.5 < [u,v] < 127.5)
y = Y * 255
v = V * 255
u = U * 255
r = R * 255
g = G * 255
b = B * 255
Since you can divide the factor 255 out, the equations above remain the same (where Y,V,U,R,G,B are replaced by y,v,u,r,g,b).
YUV [16,235] <-> RGB [0,255] (0 <= [r,g,b] <= 255, 16 <= y <= 235, 16 <= [u,v] <= 240)
y = Y * 219 + 16
u = U * 224 + 128
v = V * 224 + 128
r = R * 255
g = G * 255
b = B * 255
References:
http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html
ITU bt.601 ...
ITU bt.709 ...