I found this function on the web that I apply on every pixel of two bitmaps, for blending:
private static int hardlight(int in1, int in2) {
float image = (float)in2;
float mask = (float)in1;
return ((int)((image < 128) ? (2 * mask * image / 255):(255 - 2 * (255 - mask) * (255 - image) / 255)));
}
But I also need to adjust the intensity of the blending mask, so I need to apply alpha to it, but I have no idea on how to do it.
I tried this method on http://www.pegtop.net/delphi/articles/blendmodes/opacity.htm, that I translated to Java like this:
private static int opacity(int a, int b, float o) {
return (int) (o * hardlight(a,b) + (255 - o) * a);
}
But the result was garbage with all weird colors. I don't have much experience in bitmap manipulation, so can anyone help me?