color balance on the iPhone

China☆狼群 提交于 2019-12-06 13:33:36

What you need to do is subtract the red and then correct the "lightness" to match the old color, for whatever measure of lightness you choose. Something like this should work:

// First, calculate the current lightness.
float oldL = r * 0.30 + g * 0.59 + b * 0.11;

// Adjust the color components. This changes lightness.
r = r - 30;
if (r < 0) r = 0;

// Now correct the color back to the old lightness.
float newL = r * 0.30 + g * 0.59 + b * 0.11;
if (newL > 0) {
    r = r * oldL / newL;
    g = g * oldL / newL;
    b = b * oldL / newL;
}

Note this behaves somewhat oddly when given pure red (it will leave it unchanged). OTOH, GIMP (version 2.6.11) does the same thing in its color balance tool so I'm not too worried about it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!