公式:
Y = 0.299 R + 0.587 G + 0.114 B Cb = - 0.1687 R - 0.3313 G + 0.5 B + 128 Cr = 0.5 R - 0.4187 G - 0.0813 B + 128 反推: R = Y + 1.402 (Cr-128) G = Y - 0.34414 (Cb-128) - 0.71414 (Cr-128) B = Y + 1.772 (Cb-128)
手机上可以这样实现,高效一些
r = y + (1 + 13 / 32) * cr = y + 1.40625*cr 【R = Y + 1.402 (Cr-128)】
r = y + cr + (cr >> 2) + (cr >> 3) + (cr >> 5);
// = y - 11/32 * cb - 23/32*cr = y - 0.34375*cb - 0.71875 * cr 【G = Y - 0.34414 (Cb-128) - 0.71414 (Cr-128)】
g = y - ((cb >> 2) + (cb >> 4) + (cb >> 5)) - ((cr >> 1) + (cr >> 3) + (cr >> 4) + (cr >> 5));
// b = y + (1 + 49/64) * cb = y + 1.765625 * cb 【B = Y + 1.772 (Cb-128)】
b = y + cb + (cb >> 1) + (cb >> 2) + (cb >> 6);