java - Invert color result int of inverted division -
i working rgb
, , having problems math. unless reading quote below wrong, need take result of value looks 0.01234
, invert it. bgc = bottom color
, fgc = top color
. having issues inverting result. way color dodge
effect , not color burn
effect. have tried multiplying, dividing, adding, subtracting, , nothing seems working. can invert result?
(255f - (float)bgc[0]) / (fgc[0] << 8)
this 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 wikipedia says do:
the color burn mode divides inverted bottom layer top layer, , inverts result. darkens top layer increasing contrast reflect color of bottom layer. darker bottom layer, more color used. blending white produces no difference.
i got it:
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); }
Comments
Post a Comment