Four years ago I wrote the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| public static void blend(int[] src, int[] dst) { int length = dst.length; for (int i = 0; i < length; ++i) { int srcval = src[i]; int dstval = dst[i]; int alpha = (srcval >>> 24) + 1; int srb = srcval & 0x00ff00ff; int drb = dstval & 0x00ff00ff; int rb = ((((srb - drb) * alpha) >>> 8) + drb) & 0x00ff00ff; int sag = (srcval & 0xff00ff00) >>> 8; int dag = (dstval & 0xff00ff00) >>> 8; int ag = (((((sag - dag) * alpha) >>> 8) + dag) << 8) & 0xff00ff00; dst[i] = ag | rb; } } |
This piece of code is from my own rasterizer (capable to draw antialiased lines with different colors at ends, blending and so on) written in Java 1.0. As far as I remember I'd spent several hours to optimize this function and algorithm so the final performance of it is quite good (for pure Java).

Hope this helps...