反转分割的反转颜色结果int

时间:2013-05-15 02:16:35

标签: java math

我正在使用RGB,我遇到了这个数学问题。除非我正在阅读下面的引文错误,否则我需要取一个看起来像0.01234的值并将其反转的结果。 bgc = bottom colorfgc = top color。我有问题反转结果。现在我的方式是Color Dodge效果,而不是Color Burn效果。我尝试过乘法,除法,加法,减法,似乎没有任何工作。我该怎么做才能反转结果?

(255f - (float)bgc[0]) / (fgc[0] << 8)

这是完整的方法:

public static int colorBurn(int bg, int fg){
    int[] bgc = Colors.getrgba(bg);
    int[] fgc = Colors.getrgba(fg);
    int r = (bgc[0] == 255 ? bgc[0] : (int)Math.min(0, (255f - (float)bgc[0]) / (fgc[0] << 8)));
    int g = (bgc[1] == 255 ? bgc[1] : (int)Math.min(0, (255f - (float)bgc[1]) / (fgc[1] << 8)));
    int b = (bgc[2] == 255 ? bgc[2] : (int)Math.min(0, (255f - (float)bgc[2]) / (fgc[2] << 8)));
    return Colors.rgba(r, g, b);
}

这是维基百科所说的:

  

Color Burn 模式将倒置的底层除以顶层,然后反转结果。这使顶层变暗,增加对比度以反映底层的颜色。底层越深,使用的颜色越多。与白色混合没有区别。

1 个答案:

答案 0 :(得分:1)

我明白了:

public static int colorBurn(int bg, int fg){
    int[] bgc = Colors.getrgba(bg);
    int[] fgc = Colors.getrgba(fg);
    int r = (int)Math.min(255, 255 * (1 - (1 - (bgc[0] / 255f)) / (fgc[0] / 255f)));
    int g = (int)Math.min(255, 255 * (1 - (1 - (bgc[1] / 255f)) / (fgc[1] / 255f)));
    int b = (int)Math.min(255, 255 * (1 - (1 - (bgc[2] / 255f)) / (fgc[2] / 255f)));
    r = r < 0 ? 0 : r;
    g = g < 0 ? 0 : g;
    b = b < 0 ? 0 : b;
    return Colors.rgba(r, g, b);
}