views:

41

answers:

1

I'm looking for a formula to convert them.

I know to convert a general transparency it is

alpha * new + ( 1 - alpha ) * old

I have:

Color A : RGB( 85, 113, 135 )
Color B : RGB( 43, 169, 225 )

Color A has 90% opacity and is laid on top of Color B, resulting in

Color C : RGB( 65, 119, 145 )

My question is, how does it get Color C? If I substitute Color B for another thing, how do I get Color C?

Here's another example, same base color:

Color A : RGB( 85, 113, 135 )
Color B : RGB( 45, 67, 82 )
--------
Color C : RGB( 65, 109, 131 )

Those are working examples done with images -- I'm trying to now calculate the remaining Color C so I can assign a background color.


UPDATE, please see the accepted answer. The red in the above examples is strange -- the accepted answer has the correct formula for all the colors, I tested it in Photoshop.

+1  A: 

It appears that your formula is precisely the formula used in your examples, calculated per component, and rounded up.

R_c := ceiling(R_a * alpha) + ceiling (R_b * (1 - alpha))

G_c := ceiling(G_a * alpha) + ceiling (G_b * (1 - alpha))
B_c := ceiling(B_a * alpha) + ceiling (B_b * (1 - alpha))

Strange, though, the R component doesn't appear to follow the rules. I'm inclined to wonder why.

kbrimington
`ceiling(85 * 0.9) = 77` (R-a * alpha) that's higher than 65, am I mising something?
Kerry
@Kerry: I'm not sure. I wrote a small program to test the equation and observed that in your test case, the green and blue values adhered to the formula, but R did not.
kbrimington
Your solution is correct -- I checked it in Photoshop, and it is working fine. It has to do with Firefox somehow.
Kerry