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

HSL color incorrectly translates to RGB color #786

Open
woodroof opened this issue Jul 3, 2024 · 4 comments
Open

HSL color incorrectly translates to RGB color #786

woodroof opened this issue Jul 3, 2024 · 4 comments

Comments

@woodroof
Copy link

woodroof commented Jul 3, 2024

For example, hsl(230, 57%, 54%) should be translated to #475dcd, but usvg returns #465dcc.
r component value is 70.839, so it should be rounded to 71 (0x47).

@RazrFalcon
Copy link
Collaborator

I'm not sure I would call it "incorrectly". Just a different rounding to what you're expecting.
It's not a lossless operation to begin with.

@woodroof
Copy link
Author

woodroof commented Jul 3, 2024

Maybe "incorrectly" is not a right word, but still usvg selects not a closest rgb color, and that can be improved.

@woodroof
Copy link
Author

woodroof commented Jul 3, 2024

I can make a PR if you show me a place where this transformation is happening.

@RazrFalcon
Copy link
Collaborator

+/-1 difference is perfectly normal. But Chrome seems to be rounding up, so should we.
Will fix in the next update.

github-merge-queue bot pushed a commit to linebender/svgtypes that referenced this issue Dec 3, 2024
The current float to integer cast truncates the hues when converting
from HSL to RGB. This PR rounds to the nearest integer before the cast.

See linebender/resvg#786 for discussion.

Modifies tests with `hsl(120, 100%, 75%, 0.5)` to match with `rgb(128,
255, 128)` and adds one new test case.

Chrome developer tools:
<img width="485" alt="Screenshot 2024-12-02 at 11 00 54 PM"
src="https://github.com/user-attachments/assets/bddba238-3ed5-4b76-bbc6-d3823e205d57">

Safari developer tools:
<img width="659" alt="Screenshot 2024-12-02 at 11 06 15 PM"
src="https://github.com/user-attachments/assets/32055547-0c12-4bd8-a917-20574dcb1ac2">
github-merge-queue bot pushed a commit to linebender/svgtypes that referenced this issue Dec 3, 2024
The current float to integer cast truncates the hues when converting
from HSL to RGB. This PR rounds to the nearest integer before the cast.

See linebender/resvg#786 for discussion.

Modifies tests with `hsl(120, 100%, 75%, 0.5)` to match with `rgb(128,
255, 128)` and adds one new test case.

Chrome developer tools:
<img width="485" alt="Screenshot 2024-12-02 at 11 00 54 PM"
src="https://github.com/user-attachments/assets/bddba238-3ed5-4b76-bbc6-d3823e205d57">

Safari developer tools:
<img width="659" alt="Screenshot 2024-12-02 at 11 06 15 PM"
src="https://github.com/user-attachments/assets/32055547-0c12-4bd8-a917-20574dcb1ac2">
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

No branches or pull requests

2 participants