RGB -> YCbCr conversion: most common case YCbCr is defined per CCIR 601-1, except that Cb and Cr are normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. The conversion equations to be implemented are therefore Y = 0.29900 * R + 0.58700 * G + 0.11400 * B Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) To avoid floating-point arithmetic, we represent the fractional constants as integers scaled up by 2^16 (about 4 digits precision); we have to divide the products by 2^16, with appropriate rounding, to get the correct answer. For even more speed, we avoid doing any multiplications in the inner loop by precalculating the constants times R,G,B for all possible values. For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table); for 12-bit samples it is still acceptable. It's not very reasonable for 16-bit samples, but if you want lossless storage you shouldn't be changing colorspace anyway. The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included in the tables to save adding them separately in the inner loop.