Finding the alpha value of a pixel

GEC: Discuss gaming, computers and electronics and venture into the bizarre world of STGODs.

Moderator: Thanas

Post Reply
User avatar
Sarevok
The Fearless One
Posts: 10681
Joined: 2002-12-24 07:29am
Location: The Covenants last and final line of defense

Finding the alpha value of a pixel

Post by Sarevok »

If you know the red, green, blue components of a pixel is there a way to find the alpha value of that pixel ? One program I am working on needs to do that. My own alpha value extractor failed and I am not good with Photo editing software.
User avatar
Jawawithagun
Jedi Master
Posts: 1141
Joined: 2002-10-10 07:05pm
Location: Terra Secunda

Post by Jawawithagun »

From a pixel already drawn onscreen? Sorry, no can do.
From an image file? See where the Alpha Channel is stored.
"I said two shot to the head, not three." (Anonymous wiretap, Dallas, TX, 11/25/63)

Only one way to make a ferret let go of your nose - stick a fag up its arse!

there is no god - there is no devil - there is no heaven - there is no hell
live with it
- Lazarus Long
User avatar
Dooey Jo
Sith Devotee
Posts: 3127
Joined: 2002-08-09 01:09pm
Location: The land beyond the forest; Sweden.
Contact:

Post by Dooey Jo »

If you know the colour values of the underlying pixel, finding the alpha value would be trivial. Because R = R0 * (1 - a) + R1 * a.
So a = (R - R0) / (R1 - R0)

You might have to scale a (or the result), because it will probably range from 0 - 100 or 0 - 255, and not 0 - 1. R can be the any of the three colours, or all of them. Unless some fancy blending technique is in use, the result will be the same, no matter which you use. If there is some fancy blending technique, you will have to replace the formula, with that of the blending technique...

Of course, if you don't know the underlying pixel, then it gets a little harder... What exactly is it you are trying to do? Get the alpha value from a file, or from the screen?
Image
"Nippon ichi, bitches! Boing-boing."
Mai smote the demonic fires of heck...

Faker Ninjas invented ninjitsu
Post Reply