I was trying to code up some color manipulation code and was stuck for a long time with alpha, then I (2 hours later) realized browsers render rgba differently.
I created this test: http://jsbin.com/adekez/2/ add /edit to look at the code
Here are the results in 4 browsers in OSX Lion: https://i.sstatic.net/i9wSw.jpg
That is an element with a background of rgba(0,0,0,0.5) on top of white.
My hex calculator says: FF÷2 = 7F.8 which means
Safari at #808080 is correct Firefox at #7F7F7F is off by 1 Opera at #7E7E7E is off by 2 Chrome at #929292 is way off
What's going here, is this a bug in Chrome or do I just not know about colors (true)?
Well, actually Safari and Firefox are both correct:
0xFF = 255
, 255 / 2 = 127.5
. So 128
may be correct (0x80
), but also 127
(0x7F
) - depending on the rounding convention of the browser.
These are rounding issues. I don't quite get why there are rounding issues, since 0.5 is representable in binary numbers without precision loss, but there are, in fact rounding issues:
Opera:
Chrome: