Skip to content
This repository has been archived by the owner on Jan 3, 2025. It is now read-only.

Commit

Permalink
Update phpcsfixer and php parser (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkniest authored Jan 20, 2024
1 parent 98e79b0 commit 4f62944
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated php cs fixer
- Allow illuminate/collections v10
- Allow phpunit/php-code-coverage v10
- Dev only: Use nikic/php-parser v5
- Allow symfony/http-client v7

## [0.3.0] - 2022-12-18
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"friends-of-phpspec/phpspec-code-coverage": "^6.0.0",
"phpunit/php-code-coverage": "^9.2.5|^10.0.2",
"jkniest/linting": ">=1.10.0",
"friendsofphp/php-cs-fixer": "3.46.0",
"nikic/php-parser": "^4.13.2",
"friendsofphp/php-cs-fixer": "3.48.0",
"nikic/php-parser": "^5.0",
"webmozart/assert": "^1.11.0"
},
"prefer-stable": true,
Expand Down
10 changes: 5 additions & 5 deletions src/DemoConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class DemoConstants
'sat' => 77,
'effect' => 'none',
'xy' => [
0.1234,
0.5678,
0.123_4,
0.567_8,
],
'ct' => 380,
'colormode' => 'xy',
Expand Down Expand Up @@ -68,12 +68,12 @@ class DemoConstants
'action' => [
'on' => false,
'bri' => 123,
'hue' => 23804,
'hue' => 23_804,
'sat' => 254,
'effect' => 'none',
'xy' => [
0.2066,
0.6725,
0.206_6,
0.672_5,
],
'ct' => 153,
'alert' => 'lselect',
Expand Down
24 changes: 12 additions & 12 deletions src/Helper/ColorConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public static function fromXYToRGB(float $x, float $y, int $brightness): array
$X = ($Y / $y) * $x;
$Z = ($Y / $y) * $z;

$red = $X * 1.656492 - $Y * 0.354851 - $Z * 0.255038;
$green = -$X * 0.707196 + $Y * 1.655397 + $Z * 0.036152;
$blue = $X * 0.051713 - $Y * 0.121364 + $Z * 1.011530;
$red = $X * 1.656_492 - $Y * 0.354_851 - $Z * 0.255_038;
$green = -$X * 0.707_196 + $Y * 1.655_397 + $Z * 0.036_152;
$blue = $X * 0.051_713 - $Y * 0.121_364 + $Z * 1.011_530;

$red = $red <= 0.0031308 ? 12.92 * $red : (1.0 + 0.055) * ($red ** (1.0 / 2.4)) - 0.055;
$green = $green <= 0.0031308 ? 12.92 * $green : (1.0 + 0.055) * ($green ** (1.0 / 2.4)) - 0.055;
$blue = $blue <= 0.0031308 ? 12.92 * $blue : (1.0 + 0.055) * ($blue ** (1.0 / 2.4)) - 0.055;
$red = $red <= 0.003_130_8 ? 12.92 * $red : (1.0 + 0.055) * ($red ** (1.0 / 2.4)) - 0.055;
$green = $green <= 0.003_130_8 ? 12.92 * $green : (1.0 + 0.055) * ($green ** (1.0 / 2.4)) - 0.055;
$blue = $blue <= 0.003_130_8 ? 12.92 * $blue : (1.0 + 0.055) * ($blue ** (1.0 / 2.4)) - 0.055;

// This converts these numbers to ranges of 0-255 and ensures numbers are never smaller or higher
$red = (int) round(min(255, max(0, $red * 255)));
Expand All @@ -45,13 +45,13 @@ public static function fromRGBToXY(int $red, int $green, int $blue): array
$green /= 255.0;
$blue /= 255.0;

$r = ($red > 0.04045) ? (($red + 0.055) / (1.0 + 0.055)) ** 2.4 : ($red / 12.920);
$g = ($green > 0.04045) ? (($green + 0.055) / (1.0 + 0.055)) ** 2.4 : ($green / 12.92);
$b = ($blue > 0.04045) ? (($blue + 0.055) / (1.0 + 0.055)) ** 2.4 : ($blue / 12.92);
$r = ($red > 0.040_45) ? (($red + 0.055) / (1.0 + 0.055)) ** 2.4 : ($red / 12.920);
$g = ($green > 0.040_45) ? (($green + 0.055) / (1.0 + 0.055)) ** 2.4 : ($green / 12.92);
$b = ($blue > 0.040_45) ? (($blue + 0.055) / (1.0 + 0.055)) ** 2.4 : ($blue / 12.92);

$X = $r * 0.649926 + $g * 0.103455 + $b * 0.197109;
$Y = $r * 0.234327 + $g * 0.743075 + $b * 0.022598;
$Z = $r * 0.0000000 + $g * 0.053077 + $b * 1.035763;
$X = $r * 0.649_926 + $g * 0.103_455 + $b * 0.197_109;
$Y = $r * 0.234_327 + $g * 0.743_075 + $b * 0.022_598;
$Z = $r * 0.000_000_0 + $g * 0.053_077 + $b * 1.035_763;

$x = $X / ($X + $Y + $Z);
$y = $Y / ($X + $Y + $Z);
Expand Down

1 comment on commit 4f62944

@vercel
Copy link

@vercel vercel bot commented on 4f62944 Jan 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.