Alpha on alpha calculation

BlitzMax Forums/BlitzMax Programming/Alpha on alpha calculation

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Ok, my brain's exploding.

Has anyone of you done the following before:

- 2 pixmaps with alphas to merge and paste on an image to display in alphablend over a background

I feel like a perfect idiot (The forum allows labeling myself that way, does it?). I'm writing this painter/2d animation tool right now and decided to add layers.

My current process has the painting happening on a pixmap (static), which then after finishing a stroke will be merged with the layer within a for-loop. That layer then gets locked into an image which then gets drawn over a background (or other layers).

The for-loop's pseudo code kinda looks like this:
for y...
for x...
source = brush_pixmap
destination = layer_pixmap
...the problem area of color blending...
destination_alpha:+source_alpha*(1.0-destination_alpha)
layer_pixmap = result
next
next

For example, if the source is white and the destination is black, fading the source color to the destination color together with the alpha of the source will create a darkening rim around the white stroke. That's very common and no wonder. That means I have to take in account the alpha of the destination for the blending. And here's where my noodle cracks. Where the dest_alpha is 0, the source color should be 1.0, regardless to the source_alpha. But where the dest_alpha has a value, the source color needs to fade to the dest_color, while still behaving properly on top of the new blended alphas.

HELP! <lol> ... <kinda lol>

But, honestly, help!

little addon: IF THERE ONLY WAS A pixmap.paste that automatically takes the alpha in account!!!