From 933b324dfc4cfa2c7d37a39f1fed771c26b12060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9tro?= <yann.roberge@polymtl.ca> Date: Sat, 29 May 2021 15:38:39 -0400 Subject: [PATCH] =?UTF-8?q?Corrig=C3=A9=20les=20valeurs=20min=20et=20max?= =?UTF-8?q?=20de=20saturation=20et=20valeurs=20atteignables=20pour=20?= =?UTF-8?q?=C3=A9viter=20les=20overflows=20d'entiers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 6643c0d..33ae36c 100644 --- a/main.c +++ b/main.c @@ -51,6 +51,7 @@ int writeFrameToDisk(const PixelRGB8* imageRGB, int index) { int correctPixelColor(PixelRGB8* pixel, int deltaHue, float deltaSaturation, int deltaValue) { static PixelHSV tempHSV[1]; + int tempValue; // TODO: Implémenter printf("Pixel: %d %d %d\n", pixel->red, pixel->green, pixel->blue); @@ -63,10 +64,25 @@ int correctPixelColor(PixelRGB8* pixel, int deltaHue, float deltaSaturation, int // Add corrections tempHSV->hue = (tempHSV->hue + deltaHue) % 384; // max hue where 64 = 60degrees - tempHSV->sat = tempHSV->sat + deltaSaturation > 1.0 ? - 1.0 : tempHSV->sat + deltaSaturation; - tempHSV->value = (int)tempHSV->value + deltaValue > 255 ? - 255 : tempHSV->value + deltaValue; + + tempHSV->sat = tempHSV->sat + deltaSaturation; + if (tempHSV->sat > 1.0) { + tempHSV->sat = 1.0; + } + else if (tempHSV->sat < -1.0) { + tempHSV->sat = -1.0; + } + + tempValue = (int)tempHSV->value + deltaValue; + if (tempValue > 255) { + tempHSV->value = 255; + } + else if (tempValue < 0) { + tempHSV->value = 0; + } + else { + tempHSV->value = tempValue; + } // DEBUG //printf("PixelHSV: %d %.4f %d\n", tempHSV->hue, tempHSV->sat, tempHSV->value); @@ -74,6 +90,9 @@ int correctPixelColor(PixelRGB8* pixel, int deltaHue, float deltaSaturation, int // Convert back to RGB hsv2rgb(pixel, tempHSV); + //DEBUG + printf("Pixel reconverti: %d %d %d\n\n", pixel->red, pixel->green, pixel->blue); + return 0; } -- GitLab