From 921b9cb3d915e577c7af308c684e77cf735401e3 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Tue, 12 Nov 2024 18:53:02 +0900 Subject: [PATCH] Remove not used Color Coordinate classes and old oklab convert class --- .../Convert/Color/Coordinates/XYZD50.php | 128 ------------------ .../Convert/Color/Coordinates/XYZD65.php | 128 ------------------ www/lib/CoreLibs/Convert/Color/OkLab.php | 80 ----------- 3 files changed, 336 deletions(-) delete mode 100644 www/lib/CoreLibs/Convert/Color/Coordinates/XYZD50.php delete mode 100644 www/lib/CoreLibs/Convert/Color/Coordinates/XYZD65.php delete mode 100644 www/lib/CoreLibs/Convert/Color/OkLab.php diff --git a/www/lib/CoreLibs/Convert/Color/Coordinates/XYZD50.php b/www/lib/CoreLibs/Convert/Color/Coordinates/XYZD50.php deleted file mode 100644 index 349bb5cd..00000000 --- a/www/lib/CoreLibs/Convert/Color/Coordinates/XYZD50.php +++ /dev/null @@ -1,128 +0,0 @@ - allowed colorspaces */ - private const COLORSPACES = ['CIEXYZ']; - - /** @var float X coordinate */ - private float $X = 0.0; - /** @var float Y coordinate (Luminance) */ - private float $Y = 0.0; - /** @var float Z coordinate (blue) */ - private float $Z = 0.0; - - /** @var string color space: either ok or cie */ - private string $colorspace = ''; - - /** - * Color Coordinate Lch - * for oklch - */ - public function __construct() - { - } - - /** - * set from array - * where 0: X, 1: Y, 2: Z - * - * @param array{0:float,1:float,2:float} $colors - * @param string $colorspace - * @return self - */ - public static function __constructFromArray(array $colors, string $colorspace = 'CieXYZ'): self - { - return (new XYZD50())->setColorspace($colorspace)->setFromArray($colors); - } - - /** - * set color - * - * @param string $name - * @param float $value - * @return void - */ - public function __set(string $name, float $value): void - { - if (!property_exists($this, $name)) { - throw new \ErrorException('Creation of dynamic property is not allowed', 0); - } - // if ($value < 0 || $value > 255) { - // throw new \LengthException('Argument value ' . $value . ' for color ' . $name - // . ' is not in the range of 0 to 255', 1); - // } - $this->$name = $value; - } - - /** - * get color - * - * @param string $name - * @return float - */ - public function __get(string $name): float - { - if (!property_exists($this, $name)) { - throw new \ErrorException('Creation of dynamic property is not allowed', 0); - } - return $this->$name; - } - - /** - * set the colorspace - * - * @param string $colorspace - * @return self - */ - private function setColorspace(string $colorspace): self - { - if (!in_array($colorspace, $this::COLORSPACES)) { - throw new \InvalidArgumentException('Not allowed colorspace', 0); - } - $this->colorspace = $colorspace; - return $this; - } - - /** - * Returns the color as array - * where 0: X, 1: Y, 2: Z - * - * @return array{0:float,1:float,2:float} - */ - public function returnAsArray(): array - { - return [$this->X, $this->Y, $this->Z]; - } - - /** - * set color as array - * where 0: X, 1: Y, 2: Z - * - * @param array{0:float,1:float,2:float} $colors - * @return self - */ - public function setFromArray(array $colors): self - { - $this->__set('X', $colors[0]); - $this->__set('Y', $colors[1]); - $this->__set('Z', $colors[2]); - return $this; - } -} - -// __END__ diff --git a/www/lib/CoreLibs/Convert/Color/Coordinates/XYZD65.php b/www/lib/CoreLibs/Convert/Color/Coordinates/XYZD65.php deleted file mode 100644 index 76c96e00..00000000 --- a/www/lib/CoreLibs/Convert/Color/Coordinates/XYZD65.php +++ /dev/null @@ -1,128 +0,0 @@ - allowed colorspaces */ - private const COLORSPACES = ['XYZ']; - - /** @var float X coordinate */ - private float $X = 0.0; - /** @var float Y coordinate */ - private float $Y = 0.0; - /** @var float Y coordinate */ - private float $Z = 0.0; - - /** @var string color space: either ok or cie */ - private string $colorspace = ''; - - /** - * Color Coordinate Lch - * for oklch - */ - public function __construct() - { - } - - /** - * set from array - * where 0: X, 1: Y, 2: Z - * - * @param array{0:float,1:float,2:float} $colors - * @param string $colorspace - * @return self - */ - public static function __constructFromArray(array $colors, string $colorspace = 'XYZ'): self - { - return (new XYZD65())->setColorspace($colorspace)->setFromArray($colors); - } - - /** - * set color - * - * @param string $name - * @param float $value - * @return void - */ - public function __set(string $name, float $value): void - { - if (!property_exists($this, $name)) { - throw new \ErrorException('Creation of dynamic property is not allowed', 0); - } - // if ($value < 0 || $value > 255) { - // throw new \LengthException('Argument value ' . $value . ' for color ' . $name - // . ' is not in the range of 0 to 255', 1); - // } - $this->$name = $value; - } - - /** - * get color - * - * @param string $name - * @return float - */ - public function __get(string $name): float - { - if (!property_exists($this, $name)) { - throw new \ErrorException('Creation of dynamic property is not allowed', 0); - } - return $this->$name; - } - - /** - * set the colorspace - * - * @param string $colorspace - * @return self - */ - private function setColorspace(string $colorspace): self - { - if (!in_array($colorspace, $this::COLORSPACES)) { - throw new \InvalidArgumentException('Not allowed colorspace', 0); - } - $this->colorspace = $colorspace; - return $this; - } - - /** - * Returns the color as array - * where 0: X, 1: Y, 2: Z - * - * @return array{0:float,1:float,2:float} - */ - public function returnAsArray(): array - { - return [$this->X, $this->Y, $this->Z]; - } - - /** - * set color as array - * where 0: X, 1: Y, 2: Z - * - * @param array{0:float,1:float,2:float} $colors - * @return self - */ - public function setFromArray(array $colors): self - { - $this->__set('X', $colors[0]); - $this->__set('Y', $colors[1]); - $this->__set('Z', $colors[2]); - return $this; - } -} - -// __END__ diff --git a/www/lib/CoreLibs/Convert/Color/OkLab.php b/www/lib/CoreLibs/Convert/Color/OkLab.php deleted file mode 100644 index 2bbdbbc2..00000000 --- a/www/lib/CoreLibs/Convert/Color/OkLab.php +++ /dev/null @@ -1,80 +0,0 @@ - oklab - * oklab -> rgb - * rgb -> okhsl - * okshl -> rgb - * rgb -> okhsv - * okhsv -> rgb -*/ - -declare(strict_types=1); - -namespace CoreLibs\Convert\Color; - -class OkLab -{ - /** - * lines sRGB to oklab - * - * @param int $red - * @param int $green - * @param int $blue - * @return array - */ - public static function srgb2okLab(int $red, int $green, int $blue): array - { - $l = (float)0.4122214708 * (float)$red + - (float)0.5363325363 * (float)$green + - (float)0.0514459929 * (float)$blue; - $m = (float)0.2119034982 * (float)$red + - (float)0.6806995451 * (float)$green + - (float)0.1073969566 * (float)$blue; - $s = (float)0.0883024619 * (float)$red + - (float)0.2817188376 * (float)$green + - (float)0.6299787005 * (float)$blue; - - // cbrtf = 3 root (val) - $l_ = pow($l, 1.0 / 3); - $m_ = pow($m, 1.0 / 3); - $s_ = pow($s, 1.0 / 3); - - return [ - (float)0.2104542553 * $l_ + (float)0.7936177850 * $m_ - (float)0.0040720468 * $s_, - (float)1.9779984951 * $l_ - (float)2.4285922050 * $m_ + (float)0.4505937099 * $s_, - (float)0.0259040371 * $l_ + (float)0.7827717662 * $m_ - (float)0.8086757660 * $s_, - ]; - } - - /** - * convert okLab to linear sRGB - * - * @param float $L - * @param float $a - * @param float $b - * @return array - */ - public static function okLab2srgb(float $L, float $a, float $b): array - { - $l_ = $L + (float)0.3963377774 * $a + (float)0.2158037573 * $b; - $m_ = $L - (float)0.1055613458 * $a - (float)0.0638541728 * $b; - $s_ = $L - (float)0.0894841775 * $a - (float)1.2914855480 * $b; - - $l = $l_ * $l_ * $l_; - $m = $m_ * $m_ * $m_; - $s = $s_ * $s_ * $s_; - - return [ - (int)round(+(float)4.0767416621 * $l - (float)3.3077115913 * $m + (float)0.2309699292 * $s), - (int)round(-(float)1.2684380046 * $l + (float)2.6097574011 * $m - (float)0.3413193965 * $s), - (int)round(-(float)0.0041960863 * $l - (float)0.7034186147 * $m + (float)1.7076147010 * $s), - ]; - } -} - -// __END__