Remove not used Color Coordinate classes and old oklab convert class

This commit is contained in:
Clemens Schwaighofer
2024-11-12 18:53:02 +09:00
parent 720b78b687
commit 921b9cb3d9
3 changed files with 0 additions and 336 deletions

View File

@@ -1,128 +0,0 @@
<?php
/**
* AUTHOR: Clemens Schwaighofer
* CREATED: 2024/11/11
* DESCRIPTION:
* Color Coordinate: XYZ (Cie)
* Note, this is only for the D50 whitepoint
* https://en.wikipedia.org/wiki/CIE_1931_color_space#Construction_of_the_CIE_XYZ_color_space_from_the_Wright%E2%80%93Guild_data
* https://en.wikipedia.org/wiki/Standard_illuminant#Illuminant_series_D
*/
declare(strict_types=1);
namespace CoreLibs\Convert\Color\Coordinates;
class XYZD50
{
/** @var array<string> 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__

View File

@@ -1,128 +0,0 @@
<?php
/**
* AUTHOR: Clemens Schwaighofer
* CREATED: 2024/11/11
* DESCRIPTION:
* Color Coordinate: XYZ (Cie)
* Note, this is only for the D65 whitepoint
* https://en.wikipedia.org/wiki/CIE_1931_color_space#Construction_of_the_CIE_XYZ_color_space_from_the_Wright%E2%80%93Guild_data
* https://en.wikipedia.org/wiki/Standard_illuminant#D65_values
*/
declare(strict_types=1);
namespace CoreLibs\Convert\Color\Coordinates;
class XYZD65
{
/** @var array<string> 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__

View File

@@ -1,80 +0,0 @@
<?php
/**
* AUTHOR: Clemens Schwaighofer
* CREATED: 2024/11/7
* DESCRIPTION:
* oklab conversions
* rgb -> 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<float>
*/
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<int>
*/
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__