Jump to content

How is calculated the resulting color's alpha?


Recommended Posts

Hello all, sorry I am new and need some help, it's not really related to Paint.NET usage, but how it calculate the resulting color:

 

For example I make red background, call it C1:

 

RGBA = 255, 0, 0, 255

 

Then I place a yellow pixel, call it C2:

 

RGBA: 220, 216, 0, 200

 

Then I use the Color Picker tool on this pixel, I get C3:

 

RGBA: 227, 169, 0, 255

 

 

I already know how to calculate R, G, and B of C3

 

R = ( (C2.A / 255) * C2.R ) + ( (1 - (C2.A / 255)) * C1.R ) = 227

G = ( (C2.A / 255) * C2.G ) + ( (1 - (C2.A / 255)) * C1.G ) = 169

B = ( (C2.A / 255) * C2.B ) + ( (1 - (C2.A / 255)) * C1.B ) = 0

 

 

But for the Alpha channel, it is different and I can't find how to calculate it!

 

Thanks for any help :)

 

Link to comment
Share on other sites

Of course, that was a bad example then... Ok another example.

 

C1 alpha is 128, C2 alpha is also 128, the resulting alpha is 192.

 

Another

 

C1 alpha is 250, C2 alpha is 200, the resulting alpha is 254.

 

How to calculate this?

 

 

Edit: is this correct:

 

floor( 255 - ( ((255 / C1.A) * C2.A) + ((1 - (C2.A / 255)) * C1.A) ) )

 

But now I realized the other calcualtions are wrong...

 

Edit again: solved.

Edited by guix
Link to comment
Share on other sites

Of course, that was a bad example then... Ok another example.

 

C1 alpha is 128, C2 alpha is also 128, the resulting alpha is 192.

Alpha 128 is half opaque.

So, half opaque plus another half (of what's left) is three quarters opaque. 192 is three quarters of 255.

Clear?

Click to play:
j.pngs.pngd.pnga.pngp.png
Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...