Image blending modes (Porter-Duff)

I am in the process of writing a function that will blend two images using different blending modes. I have so far managed to implement overwrite (where i simply copy the source to the destination, including overwriting the alpha channel) and the Porter-Duff OVER mode (src OVER dst). It took quite a bit of searching but i finally found a reasonable algoritm:

1
2
3
4
5
6
//s = src, d = dst, f = final
//rgb = color, a = alpha
af = as + ad - asad;
rgb's = rgbsas; rgb'd = rgbdad;
rgb'f = rgb's + rgb'd(1-as); //src OVER dst
rgbf = rgb'f / af

I am looking for a similar algorithm for other Porter-Duff functions -- essentially, a replacement for line 5 above. I have read the original paper and some other literature on the subject but have not found an actual formula. I am particularly interested in the XOR mode and naively tried doing something like rgbf = rgbs ^ rgbd but that did not work at all.
Last edited on
I had already read this article ... but i re-read it just now; turns out i had missed a critical section where they had explained the "areas" concept. Thanks!
Topic archived. No new replies allowed.