Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are CSS colors premultiplied or not?

Tags:

html

css

colors

Experimenting in Chrome indicates that rgba() colors are interpreted as non-premultiplied alpha. (I haven't tried #RRGGBBAA colors as they are not supported by default by Chrome.)

Is there an official spec about this?

like image 662
AndreKR Avatar asked Oct 29 '22 04:10

AndreKR


1 Answers

If CSS were to be using pre-multiplied alpha, that would mean e.g. rgb(255, 0, 0) at 50% opacity would have to be rgba(127.5, 0, 0, 0.5). And rgba(255, 0, 0, 0.5) would be invalid.

The latest version of the spec mentions for rgb and rgba:

The first three arguments specify the red, green, and blue channels of the color, respectively. 0% represents the minimum value for that color channel in the sRGB gamut, and 100% represents the maximum value. A is equivalent to a , but with a different range: 0 again represents the minimum value for the color channel, but 255 represents the maximum.

This defines non-premultiplied values. If values were, or could be, pre-multiplied this would've had to say something about the maximum value depending on the alpha-value.

The CSS3 spec k2snowman69 links to isn't as specific but likewise doesn't mention anything about RGB values depending on the alpha value and includes examples that would be invalid if they were pre-multiplied.

I don't think APIs ever use pre-multiplied alpha, unless those APIs are expected to be able to deal with image data that has already been partially processed in some way, such as in image processing libraries. Pre-multiplying the alpha channel is something that's done to simplify the color blending calculations. It's not really something that helps end-users.

like image 74
mercator Avatar answered Nov 11 '22 14:11

mercator