Re: [csswg-drafts] [css-color] Fallback color in @color-profile that uses RCS (#6767)

I had another look at this one to see how hard it would be to implement.

One issue is that it requires a reworking of `calc()` expressions to take custom idents, which is a new thing (I know we have pi and e, but constants are different).

Given the proposed syntax allows a constant color but we all agree it's a pretty useless thing to do, how about: any constant component in the supplied color is multiplied by the corresponding component in the input color, mod the number of input components.

So for any RGB colorspace you can just do:

```css
@color-profile --fancyrgb {
 src: url('...');
 components: r, g, b;
        fallback-color: white;
 fallback-color: color(display-p3 1 1 1); /* if you really want P3 */
}
```
for any CMYK colorspace:

```css
@color-profile --cmyk {
 src: url('...');
 components: c, m, y, k;
        fallback-color: device-cmyk(1 1 1 1)
}
```

or any gray colorspace:

```css
@color-profile --gray {
 src: url('...');
 components: g
        fallback-color: device-cmyk(0 0 0 1);    /* if gray(0) is white, gray(1) is black */
        fallback-color: lab(1 0 0);    /* if gray(0) is black, gray(1) is white */
}
```


The "gray" example is the reason for that _mod the number of input components_ - this also ensures that this works even if the number of components between the two spaces differ. It also very neatly solves my desire to define spot colors for print:

```css
@color-profile --brand-blue {
        components: x "PANTONE Reflex Blue C";
        fallback: device-cmyk(1 0.723 0 0.02);
}
```

My pitch:

* No changes required to calc() or color parsing - `fallback` is now a regular color, parsed with the spec as it is now.
* It works without the `components` property being required.
* It gives a simple syntax that can be used for spot colors, including defining exactly how they're rendered on screen - the last example has no `src`, we can just just treat that the same as an ICC profile that is 404
* It doesn't close any doors for implementing component-names in calc later if they're needed, although the more I think about the less likely it seems they'd be required, because...
* ICC profiles will almost always be Gray, RGB or CMYK profiles, which fallback easily as shown above. Lab profiles are very rare, but also fallback to either CSS Lab function if required. Anything more exotic, the maths to fallback, eg, YCbCr or FOGRA55 to an existing CSS color is not something you could represent with calc() anyway. In all realistic situations, every component would be used in the same order, possibly multiplied by a constant.



-- 
GitHub Notification of comment by faceless2
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/6767#issuecomment-1138273192 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 26 May 2022 08:02:32 UTC