-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Simplify rgb to hsv conversion #8432
base: main
Are you sure you want to change the base?
Conversation
Python's `%` and C's `fmod` use a slightly different strategy. So to match Python, we need to implement it ourselves. It can also be simplified some due to the second parameter being 1. The starting hue calculation has also been simplified by inlining some values.
For the double fmod(double x, double y) {
return x - y * trunc(x / y);
} Since |
I've been trying to tweak this code for long enough that I forgot the |
From what I can see, there are four basic changes here.
|
re: 1., I think declarations at the start of a block was required by the C89 standard, but is no longer by modern compilers. And I find declaring on first use more readable, rather than have to refer back. |
Originally I did it because the existing comment confused me, thinking negative values weren't being handled correctly. But the new code does replace
Because of the
|
An incorrect hue was being calculated when "h/6 is negative" because Python's
%
and C'sfmod
use a slightly different strategy. So to match Python, we need to implement it ourselves. It can also be simplified some due to the second parameter being 1.The starting hue calculation has also been simplified by inlining some values. ex.: