w3c/css-houdini-drafts

[css-typed-om] define `toRGB()` method

Closed this issue · 4 comments

In 4.6 CSSColorValue objects, the method toRGB() is insufficiently defined:

The toRGB() method of CSSColorValue objects must, when called on this, convert this into an sRGB color, and return a new CSSRGB object with its r, g, b, and alpha internal slots set appropriately to represent that color.

First, it is good that the colorspace for the method is stated (sRGB). However there is no reference given for sRGB.

There is no reference for the steps needed for convert this into an sRGB color

It is probably assumed that if this has no alpha, the alpha slot is set to 1.0 but this should be explicitly stated.

In general, a normative reference to the appropriate sections of CSS Color 4 would suffice to correct this:

sRGB
convert this into an sRGB color

In several spots in this section, I'm assuming that the CSS Color spec is in mind for these things. I'm happy to provide more explicit references, tho. I presume I'd have to add these for all the color space refs.

Your link with the text "convert this into an sRGB color" is just for the "lab to sRGB" conversion - do you consider that a reasonable ref for this, since it can come from any space? I'm inclined to just drop a ref to CSS Color in general here and assume it's obvious which algorithms are invoked in each particular case.

It is probably assumed that if this has no alpha, the alpha slot is set to 1.0 but this should be explicitly stated.

Colors always have an alpha in our data model, right? The Color spec is pretty clear about defaulting the alpha (to 1) when it's omitted.

Your link with the text "convert this into an sRGB color" is just for the "lab to sRGB" conversion - do you consider that a reasonable ref for this,

I thought so but, on reflection, it wasn't. It assumes that people can extract out the relevant steps from xxx to Lab and Lab to yy to construct xxx to yy.

So I added an explicit Converting between predefined RGB color spaces; firstly because it is clearer and secondly so you can link to it for that conversion. It will work with any of the RGB spaces, including sRGB.

Yes, colors can always have an alpha, it is optional in the syntax and if omitted is 1. So the Typed OM should always have an alpha slot and it should always have a value when read.

not clear what still needs done here, given toRGB was removed in 5a1663d?

Good catch, and .to(colorSpace) also seems to have gone. So this can be closed.