[csswg-drafts] [css-color-4] extend rgb() for HDR

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

== [css-color-4] extend rgb() for HDR ==
We should extend rgb() and rgba() to accept values outside of 0-255, and values outside of 0-100%. This would allow you to specify colors outside of the sRGB gamut using extended sRGB.

In order to get sufficient precision for some colors, we should also allow floating-point values, with the assumption that the decimals may be ignored on some platforms.

It's worth noting that it's not easy to extend hsl() in the same way, since the definition of hsl() automatically keeps all values within the RGB cube.

Here is a description of how extended sRGB works:

**Extended sRGB**
So what does it mean to specify rgb(510, 510, -100) ? While 510 is twice as much as 255, it doesn’t actually mean “twice as much red” or “twice as much blue”. To understand we first look at the sRGB transfer function:

    sRGB2Linear(x) = x <= 0.04045 ? x / 12.92 : ((x + 0.055) / 1.055) ^ 2.4  {  0 <= x <= 1 }

Normally, sRGB only uses x values between 0 and 1, but it’s easy to see that the function can handle any value greater than zero. Negative values is a little trickier, but we can get around that by mirroring the srgb function into the negative range. This gives us the extended sRGB (xsRGB) function:

    xsRGB2Linear(x) = x < 0 : -sRGB2Linear(-x) : sRGB2Linear(x)  { -∞ <= x <= ∞  }

Now we can easily compute that xsRGB2Linear(511/255) = 4.97, or nearly 5x brighter than the value 255. 

For -100, the RGB the transfer function gives us:
  xsRGB2Linear(-100/255) = -xsRGB2Linear(100/255) = -0.1274


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

Received on Thursday, 25 October 2018 23:31:23 UTC