[csswg-drafts] [css-color-3] HSL examples show incorrect RGB values

avh4 has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-color-3] HSL examples show incorrect RGB values ==

Section [4.2.4. HSL color values](https://www.w3.org/TR/css-color-3/#hsl-color) provides an algorithm for translating HSL to RGB, and states that the tables in section [4.2.4.1. HSL examples](https://www.w3.org/TR/css-color-3/#hsl-examples) are generated using this algorithm.

> The algorithm to translate HSL to RGB is simple (here expressed in ABC [ABC] which was used to generate the tables.)

However, the RGB values in the example tables do not match the output of the algorithm.

---

For example, in the "0° Reds" example table, Saturation=100% and Lightness=88 is shown to have the RGB value `#FFBFBF`.

However, running the following ABC program (the algorithm from the spec plus the additional line `WRITE hsl.to.rgb(0/360, 1.00, 0.88)` produces the output `(1.00, 0.76, 0.76)`, which converts to the [0,255] range as `(255.0, 193.8, 193.8)`, which is the hex RGB value `#FFC2C2` (if rounded) (or `#FFC1C1`, if floored).

<details>
<summary>ABC program</summary>

```abc
HOW TO RETURN hsl.to.rgb(h, s, l):
    SELECT:
        l<=0.5: PUT l*(s+1) IN m2
        ELSE: PUT l+s-l*s IN m2
    PUT l*2-m2 IN m1
    PUT hue.to.rgb(m1, m2, h+1/3) IN r
    PUT hue.to.rgb(m1, m2, h    ) IN g
    PUT hue.to.rgb(m1, m2, h-1/3) IN b
    RETURN (r, g, b)

HOW TO RETURN hue.to.rgb(m1, m2, h):
    IF h<0: PUT h+1 IN h
    IF h>1: PUT h-1 IN h
    IF h*6<1: RETURN m1+(m2-m1)*h*6
    IF h*2<1: RETURN m2
    IF h*3<2: RETURN m1+(m2-m1)*(2/3-h)*6
    RETURN m1

WRITE hsl.to.rgb(0/360, 1.00, 0.88)
```

</details>

Of the 540 examples, 251 of them appear not to match the reference algorithm.  

---

I'm assuming the given algorithm is meant to be considered authoritative and the example tables are not--is that a correct assumption?

If so, can the example tables be fixed to have correct RGB values?  Or alternatively, at least add a note that the example tables only provide "close" and not accurate values for the purposes of illustration?


Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/3088 using your GitHub account

Received on Sunday, 9 September 2018 18:31:44 UTC