Re: [csswg-drafts] [css-color-4] HWB with negative white or black (#9248)

Wouldn't such colors not naturally occur? Any non-achromatic color converting to HWB will never convert to a perfect 100 for black with a negative white. It would always be some non-100% black and a negative white.

HWB has a close relation to HSV, and you only get a perfect 100 for black when V is zero (achromatic black). Saturation for HSV in this case doesn't matter since V is 0. I understand that CSS defined HWB in terms of HSL (which I assume is so it didn't also have to include HSV in the spec), but algorithmically, this case wouldn't occur with any normal color.

Looking at the CSS HWB algorithm that uses HSL to calculate HWB, you could contrive a solution that creates such an HWB color with 100% black and a negative white by using something like `color(srgb 0 -0.01 -0.01)`, but it's an imaginary color with negative lightness. It's not a color with any real application.

```js
> new Color("color(srgb 0 -0.01 -0.01)").to('lab');
Color {
  coords: [ -0.543590598185336, 0.6922703323236079, 0.24785653090937942 ],
  alpha: 1
}
```

It may make sense to make the HWB conversion, which goes through HSL for CSS, mimic the actual HSV algorithm in this sense and say if black is 100, then white is zero. Then at least such colors won't occur naturally through conversion and it matches the behavior of the HSV -> HWB conversion.

```js
function rgbToHwb(red, green, blue) {
    var hsl = rgbToHsl(red, green, blue);
    var black = 1 - Math.max(red, green, blue);
    var white = (black === 1) ? 0 : Math.min(red, green, blue);
    return([hsl[0], white*100, black*100]);
}
```

I guess something could also be done in the reverse for HWB to RGB. If black is equal to 100 and white is negative, then just return black as you cannot have negative lightness.

Then you can just explain them away with if black is equal to 100 and white is negative, the color is black because you can't have a negative lightness color.

HWB isn't the only color space that simply doesn't allow for negative lightness colors, Jzazbz will also convert similar colors as just black. It's just the limits of the algorithm.

```js
> new Color("color(srgb 0 -0.01 -0.01)").to('jzazbz');
Color { coords: [ 0, 0, 0 ], alpha: 1 }
```

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


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

Received on Sunday, 27 August 2023 21:45:11 UTC