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

Fix CMYK from-conversion and add it as possible color function #200

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Betelgeuse1
Copy link

I stumbled across this project yesterday, and it's a really cool tool :)

I'm trying to create a colorscheme for my text editor base on some design book I own, in which all colors are specified using the CMYK format.
Using pastel to convert from CMYK to hex, so my editor would understand it, seemed like a no-brainer, but even though the Self::from(CMYK) function exists, it is never used anywhere in the project.
Also, I've noticed the calculation were wrong in that function, so I fixed those and add the corresponding parse_cmyk function, so it can be used as a color value in commands.

This is my first time "writing" rust code, please feel free to report any mistake I've made :)
I would understand if this is rejected because it's too niche of a usage.

@sharkdp
Copy link
Owner

sharkdp commented Nov 1, 2023

but even though the Self::from(CMYK) function exists, it is never used anywhere in the project.

Strange…

Also, I've noticed the calculation were wrong in that function, so I fixed those and add the corresponding parse_cmyk function, so it can be used as a color value in commands.

Thank you!

Comment on lines +963 to +965
let r = Scalar::round(255.0 * (1.0 - color.c / 100.0) * (1.0 - color.k / 100.0)) as u8;
let g = Scalar::round(255.0 * (1.0 - color.m / 100.0) * (1.0 - color.k / 100.0)) as u8;
let b = Scalar::round(255.0 * (1.0 - color.y / 100.0) * (1.0 - color.k / 100.0)) as u8;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the other color spaces, we have tests that make sure that we can convert e.g. HSL -> Lab -> HSL and get the same color back. You can search for roundtrip in this file to see some examples. It would be great if we could add tests for CMYK, too.

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.

None yet

2 participants