- Posts: 3
- Joined: Mon Nov 10, 2014 9:02 pm
2.7 Formulas
Color space Conversion Formulas
The following basic equations convert between gamma-corrected RGB and YUV colour spaces.
SD RGB to YUV conversion
Y = 0.257R + 0.504G + 0.098B + 16
Cb = -0.148R - 0.291G + 0.439B + 128
Cr = 0.439R - 0.368G - 0.071B + 128
HD RGB to YUV conversion
Y = 0.183R + 0.614G + 0.062B + 16
Cb = -0.101R - 0.338G + 0.439B + 128
Cr = 0.439R - 0.399G - 0.040B + 128
SD YUV to RGB conversion
R = 1.164(Y - 16) + 1.596 (Cr - 128)
G = 1.164(Y - 16) - 0.813 (Cr - 128) - 0.391 (Cb - 128)
B = 1.164(Y - 16) + 2.018(Cb - 128)
HD YUV to RGB conversion
R = 1.164(Y - 16) + 1.793(Cr - 128)
G = 1.164(Y - 16) - 0.534(Cr - 128) - 0.213(Cb - 128)
B = 1.164(Y - 16) + 2.115(Cb - 128)
Ensure that output values are clamped to keep them in the 0 - 255 range. The valid SMPTE ranges are Y: 16-240, Cb/ Cr: 16-235.
IDeckLinkOutput::DisplayVideoFrameSync or IDeckLinkOutput::ScheduleVideoFrame can convert RGB formatted frames to YUV for output.
I've also found external libraries like OpenCV and IPP helpful for things like this.
Hope that helps
James