Skip to content

Commit

Permalink
simplify rgb2hsv hue calculation
Browse files Browse the repository at this point in the history
"fmod(x, y)" was replaced by "x - (int)(x / y) * y", and then simplified.

h = fmod((h / 6.0 + 1.0), 1.0);
h = (h / 6.0 + 1.0) - (int)((h / 6.0 + 1.0) / 1.0) * 1.0;
h = (h / 6.0 + 1.0) - (int)(h / 6.0 + 1.0);
  • Loading branch information
Yay295 committed Sep 22, 2024
1 parent e5948bb commit 686f5ae
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/libImaging/Convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ rgb2bgr24(UINT8 *out, const UINT8 *in, int xsize) {

static void
rgb2hsv_row(UINT8 *out, const UINT8 *in) { // following colorsys.py
float h, s, rc, gc, bc, cr;
double h;
float s, rc, gc, bc, cr;
UINT8 maxc, minc;
UINT8 r, g, b;
UINT8 uh, us, uv;
Expand Down Expand Up @@ -340,6 +341,8 @@ rgb2hsv_row(UINT8 *out, const UINT8 *in) { // following colorsys.py
}
// incorrect hue happens if h/6 is negative.
h = fmod((h / 6.0 + 1.0), 1.0);
//h = h / 6.0 + 1.0;
//h = h - (int)h;

uh = (UINT8)CLIP8((int)(h * 255.0));
us = (UINT8)CLIP8((int)(s * 255.0));
Expand Down

0 comments on commit 686f5ae

Please sign in to comment.