W3C home > Mailing lists > Public > www-style@w3.org > May 2010

Re: [css3-color] #rrggbbaa annotation

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Tue, 18 May 2010 23:55:04 -0400
Message-ID: <4BF36118.9090706@mit.edu>
To: Alex Meiburg <timeroot.alex@gmail.com>
CC: www-style@w3.org
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 

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.

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

This archive was generated by hypermail 2.3.1 : Wednesday, 11 February 2015 12:34:37 UTC