Re: [css3-color] #rrggbbaa annotation

On 5/18/10 7:09 PM, Alex Meiburg wrote:
> As for the mapping (from 0-255 to 0-1 float), this might be well based
> in part off how UA's currently store the Alpha value. If a decimal is
> actually rounded to a hex value and used like that.... great. I think
> 0x80 should map to 0.50196078431372548 then.

Gecko stores alpha values as unsigned bytes (so integers in the range 
0-255).

The only time this needs to be converted to decimal is for 
serialization.  I the alpha is 255, it's not serialized at all (that is, 
rgb() is used instead of rgba()).  Otherwise, the alpha value is 
serialized as either a two-digit decimal if that would round-trip 
correctly and as a three-digit decimal otherwise (though in practice 
it's possible that even the second digit is dropped in the two-digit 
case if it's 0; I didn't dig deep enough to make sure of that behavior).

So for example, for 0x80 == 128, the two-digit representation would be 
0.50.  Since 0.50*255 = 127.5 and 127.5 gets rounded to 128, that means 
that we'll parse 0.50 as 0x80, and hence it's OK to serialize the 
opacity as 0.50.

-Boris

Received on Wednesday, 19 May 2010 03:55:39 UTC