views:

186

answers:

2

How can I mix two ARGB pixels ?

Example

alt text

Here A is (Red with Alpha) and B is ( Blue with Alpha ).

+1  A: 

It seems like this is what you want: http://en.wikipedia.org/wiki/Alpha%5Fcompositing#Alpha%5Fblending, but I'm a little confused by your notation since wikipedia says that argb values should range from 0.0 to 1.0. So I don't think this formula will give you FA=19. Can you clarify?

Edit: now that you took out the business about FA=19, I'm inclined to go with that formula.

danben
You can use also values from 0 to 255 for the RGB components; if you need to use the values to calculate something, then it's probably better to use values between 0, and 255. The formula can be changed to work with values between 0 and 255, though.
kiamlaluno
I think the formula expects each value to be a percentage, so you could use 0.0-1.0 for the formula and then multiply by 255 afterward.
danben
+1 for Alpha Blending. This seems like the required method.
keyboardP
Thanks danben, I will take care to convert this formula from (0 to 1.0) to ( 0 to 255 ).
Sunny
+4  A: 

Taken from the same Wikipedia article where you got the image:

C_o = C_a \alpha_a + C_b \alpha_b \left(1 - \alpha_a\right)

Translating to values which range from 0 to 255:

rOut = (rA * aA / 255) + (rB * aB * (255 - aA) / (255*255))
gOut = (gA * aA / 255) + (gB * aB * (255 - aA) / (255*255))
bOut = (bA * aA / 255) + (bB * aB * (255 - aA) / (255*255))
aOut = aA + (aB * (255 - aA) / 255)
Mark Ransom

related questions