diff --git a/src/Color.php b/src/Color.php index 8f92069..13e5b3e 100644 --- a/src/Color.php +++ b/src/Color.php @@ -12,8 +12,9 @@ public static function toLinear(int $value): float { public static function tosRGB(float $value): int { $normalized = max(0, min(1, $value)); - return ($normalized <= 0.0031308) + $result = ($normalized <= 0.0031308) ? (int) round($normalized * 12.92 * 255 + 0.5) : (int) round((1.055 * pow($normalized, 1 / 2.4) - 0.055) * 255 + 0.5); + return max(0, min($result, 255)); } } \ No newline at end of file diff --git a/test/DCTest.php b/test/DCTest.php index 850cbf9..55d9faf 100644 --- a/test/DCTest.php +++ b/test/DCTest.php @@ -8,7 +8,7 @@ class DCTest extends TestCase { public function testEncode () { $this->assertSame (65793, DC::encode ([0, 0, 0], 1)); - $this->assertSame (16843008, DC::encode ([255, 255, 255], 1)); + $this->assertSame (16777215, DC::encode ([255, 255, 255], 1)); $this->assertSame (65793, DC::encode ([-1, -1, -1], 1)); }