Do you mean standard blending that looks like this?

(Where the foreground image is at 75% opacity)
Typically we use SRC_ALPHA, ONE_MINUS_SRC_ALPHA:
1
| {foreground}*sourceAlpha + {background}*(1-sourceAlpha) |
Looks roughly like this: (you don't need to use floats)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
int dstValue = pixels[dstPos]; float dstA = ((dstValue & 0xff000000) >>> 24) / 255f; float dstR = ((dstValue & 0x00ff0000) >>> 16) / 255f; float dstG = ((dstValue & 0x0000ff00) >>> 8) / 255f; float dstB = ((dstValue & 0x000000ff)) / 255f;
int srcValue = pixels[srcPos]; float srcA = ((srcValue & 0xff000000) >>> 24) / 255f; float srcR = ((srcValue & 0x00ff0000) >>> 16) / 255f; float srcG = ((srcValue & 0x0000ff00) >>> 8) / 255f; float srcB = ((srcValue & 0x000000ff)) / 255f;
srcR *= srcA; srcG *= srcA; srcB *= srcA;
float R = srcR + dstR*(1-srcA); float G = srcG + dstG*(1-srcA); float B = srcB + dstB*(1-srcA);
pixels[dstPos] = (255 << 24) | ((int)(R * 255) << 16) | ((int)(G * 255) << 8) | (int)(B * 255);
|