A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/w3c/csswg-drafts/issues/3088 below:

[css-color-3] HSL examples show incorrect RGB values · Issue #3088 · w3c/csswg-drafts · GitHub

Section 4.2.4. HSL color values provides an algorithm for translating HSL to RGB, and states that the tables in section 4.2.4.1. 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).

ABC program
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)

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?


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.3