sharkdp / pastel

A command-line tool to generate, analyze, convert and manipulate colors
Apache License 2.0
5k stars 97 forks source link

Add set luminance using a binary search #105

Closed JuanPotato closed 2 years ago

JuanPotato commented 4 years ago

Closes #89

sharkdp commented 4 years ago

Thank you very much for your contribution!

I would prefer if we extract the binary search code into a separate function and add some tests for it.

Without having looked at the code in detail: if we modify a color in Lab space (which is what we should do for this problem :+1:), we have to make sure not to leave the sRGB gamut. The library will handle this for us but one often ends up with strangely saturated colors. Maybe this is not a problem here, since we are only modifying the lightness channel here which probable means that the sRGB gamut surface will be reached when the color is completely white or black.

JuanPotato commented 4 years ago

Should I put the function in the same file when extracting it?

sharkdp commented 4 years ago

Should I put the function in the same file when extracting it?

yes, I think that's fine.

JuanPotato commented 4 years ago

Well, there's a small issue with the binary search. It never manages to get all the way to #FFFFFF white or #000000 black. If I change the min and max range for the binary search to a past 0 and 100, so -1 and 101. It will get to pure white and black

sharkdp commented 4 years ago

Well, there's a small issue with the binary search. It never manages to get all the way to #FFFFFF white or #000000 black. If I change the min and max range for the binary search to a past 0 and 100, so -1 and 101. It will get to pure white and black

Do you think this could be related to #108?

JuanPotato commented 4 years ago

I know the lab = lab.into_color().to_lab(); line is due to that issue. Fixing it would definitely help.

sharkdp commented 2 years ago

Closing for now since this is rather old. We can always resurrect it later.