Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting lab lightness value does not work as expected? #108

Open
JuanPotato opened this issue Oct 27, 2019 · 3 comments
Open

Setting lab lightness value does not work as expected? #108

JuanPotato opened this issue Oct 27, 2019 · 3 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@JuanPotato
Copy link

JuanPotato commented Oct 27, 2019

I would expect pastel set lightness 100 to set a color's lab lightness to 100. The code does seem to try and set lab.l = value but it doesn't actually result in a lab lightness value of 100. Which seemed odd.

 % pastel format lab orange
Lab(75, 24, 79)
 % pastel set lightness 100 orange | pastel format lab
Lab(92, -8, 68)

I have no idea if this is an issue with converting between colorspaces or just unavoidable.

At 149, the lab lightness value seems to be shown as 100, but it isn't pure white.

 % pastel set lightness 149 orange | pastel format lab
Lab(100, -3, 9)

At 156, it finally reaches pure white.

 % pastel set lightness 156 orange | pastel format lab
Lab(100, 0, -0)

You can keep try setting it to 100 lightness and it will increase slightly which is odd

 % pastel set lightness 100 orange | pastel format lab
Lab(92, -8, 68)
 % pastel set lightness 100 orange | pastel set lightness 100 | pastel format lab
Lab(98, -17, 65)
 % pastel set lightness 100 orange | pastel set lightness 100 | pastel set lightness 100 | pastel format lab
Lab(98, -17, 63)
@sharkdp
Copy link
Owner

sharkdp commented Oct 29, 2019

Thank you for the detailed bug report.

I have no idea if this is an issue with converting between colorspaces ...

It probably is. Either with the precision of the conversion (hopefully not) or with the sRGB gamut boundary limitations.

... or just unavoidable.

I'm not sure. We should look into it.

@sharkdp sharkdp added bug Something isn't working help wanted Extra attention is needed labels Oct 29, 2019
@sigprof
Copy link

sigprof commented Jul 30, 2020

The problem is that an attempt to set the color to Lab(100, 24, 79) results in a color which is out of the sRGB gamut, and the method of bringing the color into gamut used by pastel is very simple — just clamp R, G, and B components into the [0.0, 1.0] range. This method does not preserve the Lab lightness value.

Maybe you expected some other method of bringing the color into gamut (e.g., keeping the LCh hue constant and adjusting the LCh chroma if needed — this would give pure white when setting lightness to 100), but currently no other methods except clamping the RGB values are implemented.

There is also another issue — rounding of the printed Lab values loses some information (as you noticed when comparing results for pastel set lightness 149 and pastel set lightness 156). Actually the first color is rgb(255, 255, 235), which has Lab lightness ≈ 99.6, but pastel prints that lightness as 100, and reading that Lab value back gives rgb(255, 255, 255). Maybe Lab and LCh values should be printed with at least 1 digit after the decimal point, so that reading that representation would not result in a different RGB color (but I'm not 100% sure that 1 digit would be enough in all cases).

@sharkdp
Copy link
Owner

sharkdp commented Aug 1, 2020

@sigprof Thank you for the insights and thoughts. I currently don't find the time to work on this myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants