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

weight hue by chroma in mix() #76

Closed
wants to merge 2 commits into from
Closed

weight hue by chroma in mix() #76

wants to merge 2 commits into from

Conversation

xi
Copy link

@xi xi commented Aug 29, 2019

For unsaturated colors, the hue is not as relevant. Consider mixing black and blue:

$ pastel mix -s hsl black blue
#602060

As black does not have a meaningful hue, it is assumed to be 0 (red). So the result is a dark purple instead of a dark blue.

My proposal is to weight the hues by saturation. So in the example above, the red hue of black would be ignored because it has a saturation of 0. I understad this is more complex but does ultimately lead to less unexpected results.

(I did not do anything special to prevent devision by zero. rust seems to be smart enough to handle that itself, but I am not proficient enough to know exactly how.)

@sharkdp
Copy link
Owner

sharkdp commented Aug 29, 2019

Interesting! Thank you for the feedback and the contribution.

This does not happen in RGB and Lab space, but appears in both HSL and LCh, which have angular Hue values.

If I understand it correctly, your solution would have an impact on all mixing results and it would not be the same interpolation between two colors. What if, instead, we just add a special case for pure black and pure white (this issue should not appear for any other colors?). In this case, we could just select the hue from the "other" color. So mix blue black would mix "blue" with a "black" that has a hue of 240°. What do you think?

@xi
Copy link
Author

xi commented Aug 29, 2019

Consider this case:

$ pastel mix -s hsl 100 blue
#880088
$ pasel mix -s hsl 010 blue
#008888

These colors are practically black, so they should have a similar effect as pure black.

This might be personal taste, but I find this approach produces less unexpected results in general.

@xi xi changed the title weight hue by saturation in mix() weight hue by chroma in mix() Aug 29, 2019
@sharkdp
Copy link
Owner

sharkdp commented Aug 29, 2019

The mix function is also used to create gradients. If a user explicitly chooses the HSL space (and a start color with a "red hue"), I think it is expected that the hue rotates from red to blue:

pastel gradient -n 20 -s hsl 100 blue | pastel format

If you don't want that rotation along the hue axis, you can always choose a different color space (RGB, if you want to be similar to HSL; Lab if you want to be similar to LCh).

That being said, I agree that the behavior of pure black and pure white could definitely be surprising 👍

@sharkdp sharkdp closed this in 4305363 Sep 1, 2019
@sharkdp
Copy link
Owner

sharkdp commented Sep 1, 2019

@xi I have pushed an update which fixes the original issue when we mix with saturation-less / gray colors. See 4305363.

Thank you very much for bringing this up.

@sharkdp
Copy link
Owner

sharkdp commented Sep 19, 2019

Fix released in v0.6.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants