Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know if an image is "Premultiplied Alpha"?

I heard that only premultiplied alpha is needed when doing layer blending etc. How do I know if my original image is premultiplied alpha?

like image 231
Adam Lee Avatar asked Feb 05 '12 08:02

Adam Lee


Video Answer


1 Answers

You can't.

The only thing that you can check is if it's not premultiplied. To do it go over all the pixels and see if there is a color-value that has a higher value than the alpha would permit if(max(col.r,col.g,col.b) > 255*alpha)//not premul. Any other cases are ambiguous and could or could not be premultiplied. Your best guess is probably to assume that they aren't as that's the case for most PNGs.

Edit: actually, not even the code that I posted would work as there are a lot of PNGs out there with white matte, so the image would have to include parts that have an alpha of 0 to determine the matte color first.

like image 195
PeterT Avatar answered Oct 11 '22 22:10

PeterT