From 8e4e7638ab371be7769ed4631b9fb65e17b9825d Mon Sep 17 00:00:00 2001 From: Greg Date: Fri, 21 Jul 2017 15:04:19 +0200 Subject: [PATCH] Debut de correction de formule --- library/Phue/Helper/ColorConversion.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/library/Phue/Helper/ColorConversion.php b/library/Phue/Helper/ColorConversion.php index 4e0dde0..97529d6 100644 --- a/library/Phue/Helper/ColorConversion.php +++ b/library/Phue/Helper/ColorConversion.php @@ -82,6 +82,7 @@ public static function convertXYToRGB($x, $y, $bri = 255) $color['green'] = -$xyz['x'] * 0.707196 + $xyz['y'] * 1.655397 + $xyz['z'] * 0.036152; $color['blue'] = $xyz['x'] * 0.051713 - $xyz['y'] * 0.121364 + $xyz['z'] * 1.011530; + $maxValue = 0; foreach ($color as $key => $normalized) { // Apply reverse gamma correction if ($normalized <= 0.0031308) { @@ -89,7 +90,16 @@ public static function convertXYToRGB($x, $y, $bri = 255) } else { $color[$key] = (1.0 + 0.055) * pow($normalized, 1.0 / 2.4) - 0.055; } - + $color[$key] = max(0,$color[$key]); + if($maxValue < $color[$key]){ + $maxValue = $color[$key]; + } + + } + foreach ($color as $key => $normalized) { + if($maxValue > 1){ + $color[$key] /= $maxValue; + } // Scale back from a maximum of 1 to a maximum of 255 $color[$key] = round($color[$key] * 255); }