Microsoft's answer to Conversion between RGB and YUV
Converting RGB888 to YUV
The following formulas define the conversion from RGB to YUV:Y = ( ( 66 * R + 129 * G + 25 * B + 128) >> 8) + 16 U = ( ( -38 * R - 74 * G + 112 * B + 128) >> 8) + 128 V = ( ( 112 * R - 94 * G - 18 * B + 128) >> 8) + 128
Converting 8-bit YUV to RGB888
The following coefficients are used in conversion process:Using the previous coefficients and noting that
clip()
denotes clipping a value to the range of 0 to 255, the following formulas provide the conversion from YUV to RGB: