I am working with RGB
, and I am having problems with this math. Unless I am reading the quote below wrong, I need to take the result of this which is a value that looks like 0.01234
and invert it. bgc = bottom color
and fgc = top color
. I am having issues inverting the result. The way it is now I get a Color Dodge
effect and not a Color Burn
effect. I have tried multiplying, dividing, adding, subtracting, and nothing seems to be working. What can I do to invert the result?
(255f - (float)bgc[0]) / (fgc[0] << 8)
This is the full method:
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);
}
Here is what Wikipedia says to do:
The Color Burn mode divides the inverted bottom layer by the top layer, and then inverts the result. This darkens the top layer increasing the contrast to reflect the color of the bottom layer. The darker the bottom layer, the more its color is used. Blending with white produces no difference.