From ba110506f6e03c326667596c05dd7d3ceb74004b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9tro?= <yann.roberge@polymtl.ca> Date: Fri, 28 May 2021 19:08:55 -0400 Subject: [PATCH] =?UTF-8?q?Correctif=20du=20offset=20appliqu=C3=A9=20?= =?UTF-8?q?=C3=A0=20la=20teinte?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rgb2hsv.c | 9 ++++----- rgb2hsv.h | 3 +++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/rgb2hsv.c b/rgb2hsv.c index 20a9bcb..60b175e 100644 --- a/rgb2hsv.c +++ b/rgb2hsv.c @@ -17,13 +17,13 @@ // Pass hue, saturation and value (lightness / 2) corrections to args void rgb2hsv(PixelHSV* hsv, PixelRGB8* rgb) { - //TODO: Implémenter int r = (int) rgb->red; int g = (int) rgb->green; int b = (int) rgb->blue; int minComp, maxComp; - int tempSubtract, offset, ampl; + int tempSubtract, ampl; + int offset = 64; // Min and Max color components if (r == 0 && g == 0 && b == 0) { @@ -41,7 +41,6 @@ void rgb2hsv(PixelHSV* hsv, PixelRGB8* rgb) { minComp = b; } tempSubtract = g - b; - offset = 64; } else if (g >= b) { maxComp = g; @@ -52,7 +51,7 @@ void rgb2hsv(PixelHSV* hsv, PixelRGB8* rgb) { minComp = r; } tempSubtract = b - r; - offset = 128; + offset += 128; } else { maxComp = b; @@ -63,7 +62,7 @@ void rgb2hsv(PixelHSV* hsv, PixelRGB8* rgb) { minComp = r; } tempSubtract = r - g; - offset = 256; + offset += 256; } //H diff --git a/rgb2hsv.h b/rgb2hsv.h index 4bde927..74f079b 100644 --- a/rgb2hsv.h +++ b/rgb2hsv.h @@ -14,6 +14,9 @@ // Pixel struct unpacked for processing typedef struct { + // 9-bit hue: 0 to 360 degrees encoded with 60deg = 64 + // on a chromatic circle starting at 60deg (magenta) + // which avoids modulo operations on some colors uint16_t hue; float sat; uint8_t value; -- GitLab