Closed Bug 1359248 Opened 7 years ago Closed 7 years ago

Float/percentage color rounding is unfairly distributed/wrong

Categories

(Core :: CSS Parsing and Computation, defect)

defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 1340484

People

(Reporter: manishearth, Unassigned)

References

Details

Attachments

(1 file, 1 obsolete file)

Attached image plot.png
When parsing colors like rgb(10%, 10%, 10%), or `rgba(0,0,0,0.1)`, Gecko multiplies by 255 and rounds.

http://searchfox.org/mozilla-central/rev/313e5199bf58200f158c6fcbe193e41b88ed58a6/layout/style/nsCSSValue.cpp#3189

Servo and Chrome multiply by 256 and floor (and then clamp to 255, so that the input of 1.0 produces a result within bounds). This is more correct: The function has an equal distribution of values in the range to the domain. On the other hand, Gecko's function has fewer numbers mapping to 0 and 255 and the numbers in between get a larger domain each.

This means that `rgb(10%, 10%, 10%)` is `rgb(25,25,25)` in servo and chrome, but `rgb(26, 26,26)` in gecko. Similarly, `rgba(0,0,0,0.1)` maps to different alpha values. (As a result, in Stylo, `rgba(0,0,0,0.1)` computes to `rgba(0,0,0,0.098)` since we still use nscolor but map the correct values into it, but Gecko's serialization assumes the flawed mapping)

Try at https://treeherder.mozilla.org/#/jobs?repo=try&revision=4708b2339447d70af11f20d7e4bca3369df82380

This is a behavioral change, not sure if I should email dev.tech.layout.
Interestingly, Chrome serializes without truncation here. 0.0980392, instead of trying to reproduce 0.1, which is what gecko does.

<div id=f style="background-color: rgba(10%, 10%, 10%, 0.1)">aaa</div>

<script type="text/javascript">
  document.write( getComputedStyle(document.getElementById('f')).backgroundColor)
</script>
Summary: Float/percentage color rounding is unfair and wrong → Float/percentage color rounding is unfairly distributed/wrong
Manish, could you move your patch to Bug 1340484? Thanks.
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → DUPLICATE
Attachment #8861210 - Attachment is obsolete: true
Attachment #8861210 - Flags: review?(cam)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: