dustinwilson/pigmentum

用于操作和转换CIE色彩空间的库

0.1.3 2022-01-18 22:49 UTC

This package is auto-updated.

Last update: 2024-09-19 04:39:51 UTC


README

PHP中操作颜色的库。这是我对色彩数学进行实验的结果。虽然市面上有其他色彩类,但它们要么不符合我的要求,要么数学计算有误。

使用前警告

此库是实验性的。代码还没有单元测试,但这项工作正在计划中。在单元测试存在之前,请将此软件视为beta或alpha软件。另外,公共API正在变化,因此如果您使用此库,请提前警告可能存在破坏性API更改。

需求

  • PHP 8.0.2或更高版本,并需要以下扩展
    • dom 扩展(用于调色板)
    • mbstring 扩展(用于调色板)
    • zip 扩展(用于调色板)
  • Composer 2.0或更高版本

文档

Pigmentum中的颜色表示为一个单独的颜色对象。所有色彩空间都内部转换为并表示为XYZ D50 2°。目前Pigmentum处理以下色彩空间

  1. CIEXYZ
    1. LMS
  2. CIELAB
  3. RGB
    1. HSB/V

在Pigmentum中支持任何色彩空间意味着可以在各个色彩空间之间进行转换。

dW\Pigmentum\Color

class dW\Pigmentum\Color {
    // Common illuminants used in color spaces
    const ILLUMINANT_D65 = [ 0.95047, 1, 1.08883 ];
    const ILLUMINANT_D50 = [ 0.96422, 1, 0.82521 ];

    const REFERENCE_WHITE = self::ILLUMINANT_D50;

    // Math constants
    const KAPPA = 903.296296296296296;
    const EPSILON = 0.008856451679036;

    // RGB color profiles
    const PROFILE_SRGB = 'dW\Pigmentum\Color\Profile\RGB\sRGB';
    const PROFILE_SIMPLE_SRGB = 'dW\Pigmentum\Color\Profile\RGB\Simple_sRGB';
    const PROFILE_ADOBERGB1998 = 'dW\Pigmentum\Color\Profile\RGB\AdobeRGB1998';
    const PROFILE_PROPHOTORGB = 'dW\Pigmentum\Color\Profile\RGB\ProPhoto';
    const PROFILE_DISPLAYP3 = 'dW\Pigmentum\Color\Profile\RGB\DisplayP3';

    public ?string $name = null;
    public static string $workingSpaceRGB = self::PROFILE_SRGB;


    public static function withLab(float $L, float $a, float $b, ?string $name = null): dW\Pigmentum\Color;
    public static function withLCHab(float $L, float $C, float $H, ?string $name = null): dW\Pigmentum\Color;
    public static function withRGB(float $R, float $G, float $B, ?string $name = null, ?string $profile = null): dW\Pigmentum\Color;
    public static function withRGBHex(string $hex, ?string $name = null, ?string $profile = null): dW\Pigmentum\Color;
    public static function withHSB(float $H, float $S, float $B, ?string $name = null, ?string $profile = null): dW\Pigmentum\Color;
    public static function withXYZ(float $X, float $Y, float $Z, string $name = null): dW\Pigmentum\Color;


    public function toLab(): dW\Pigmentum\ColorSpace\Lab;
    public function toRGB(?string $profile = null): dW\Pigmentum\ColorSpace\RGB;
    public function toXYZ(): dW\Pigmentum\ColorSpace\XYZ;


    public static function average(dW\Pigmentum\Color ...$colors): dW\Pigmentum\Color;
    public static function averageWithLab(dW\Pigmentum\Color ...$colors): dW\Pigmentum\Color;
    public static function averageWithLCHab(dW\Pigmentum\Color ...$colors): dW\Pigmentum\Color;
    public static function averageWithRGB(dW\Pigmentum\Color ...$colors): dW\Pigmentum\Color;
    public static function averageWithHSB(dW\Pigmentum\Color ...$colors): dW\Pigmentum\Color;

    public function mix(dW\Pigmentum\Color $color, float $percentage = 0.5): dW\Pigmentum\Color;
    public function mixWithLab(dW\Pigmentum\Color $color, float $percentage = 0.5): dW\Pigmentum\Color;
    public function mixWithLCHab(dW\Pigmentum\Color $color, float $percentage = 0.5): dW\Pigmentum\Color;
    public function mixWithRGB(dW\Pigmentum\Color $color, float $percentage = 0.5): dW\Pigmentum\Color;
    public function mixWithHSB(dW\Pigmentum\Color $color, float $percentage = 0.5): dW\Pigmentum\Color;


    public function apcaContrast(dW\Pigmentum\Color $backgroundColor): float;
    public function deltaE(dW\Pigmentum\Color $color): float;
    public function distance(dW\Pigmentum\Color $color): float;
    public function euclideanDistance(dW\Pigmentum\Color $color): float;
    public function wcag2Contrast(dW\Pigmentum\Color $color): float;
}

属性

  • name (?string): 用户提供的颜色名称。当制作调色板时很有用。
  • workingSpaceRGB (string): 当前RGB工作空间。

dW\Pigmentum\Color::withLab

从L*a*b*值创建一个新的dW\Pigmentum\Color对象。

public static function withLab(
    float $L,
    float $a,
    float $b,
    ?string $name = null
): dW\Pigmentum\Color;
  • L: 亮度通道值
  • a: a通道值
  • b: b通道值
  • name: 与颜色关联的可选名称
示例
namespace dW\Pigmentum\Color;

Color::withLab(57, 35, 38);

dW\Pigmentum\Color::withLCHab

从L*C*H* (L*a*b*)值创建一个新的dW\Pigmentum\Color对象。

public static function withLCHab(
    float $L,
    float $C,
    float $H,
    ?string $name = null
): dW\Pigmentum\Color;
  • L: 亮度通道值
  • C: 色彩通道值
  • H: 色调通道值
  • name: 与颜色关联的可选名称
示例
namespace dW\Pigmentum\Color;

Color::withLCHab(57, 51, 47);

dW\Pigmentum\Color::withRGB

从RGB值创建一个新的dW\Pigmentum\Color对象。

public static function withRGB(
    float $R,
    float $G,
    float $B,
    ?string $name = null,
    ?string $profile = null
): dW\Pigmentum\Color;
  • R: 红色通道值
  • G: 绿色通道值
  • B: 蓝色通道值
  • name: 与颜色关联的可选名称
  • profile: 颜色配置文件类名的字符串表示,默认为当前工作空间
示例
namespace dW\Pigmentum\Color;

$sRGBColor = Color::withRGB(202, 110, 72);
$adobeRGBColor = Color::withRGB(202, 110, 72, null, Color::PROFILE_ADOBERGB1998);
echo $sRGBColor->XYZ . "\n";
echo $adobeRGBColor->XYZ;

输出

xyz(0.32686782145478, 0.24712385141221, 0.069650535956488)
xyz(0.40672668489701, 0.28866272343639, 0.067355999640287)

dW\Pigmentum\Color::withRGBHex

从RGB十六进制字符串创建一个新的dW\Pigmentum\Color对象。

public static function withRGBHex(
    string $hex,
    ?string $name = null,
    ?string $profile = null
): dW\Pigmentum\Color;
  • hex: RGB十六进制字符串;可以前面有'#'或没有
  • name: 与颜色关联的可选名称
  • profile: 颜色配置文件类名的字符串表示,默认为当前工作空间
示例
namespace dW\Pigmentum\Color;

$sRGBColor = Color::withRGBHex('#ca6e48');
$adobeRGBColor = Color::withRGBHex('#ca6e48', null, Color::PROFILE_ADOBERGB1998);
echo $sRGBColor->XYZ . "\n";
echo $adobeRGBColor->XYZ;

输出

xyz(0.32686782145478, 0.24712385141221, 0.069650535956488)
xyz(0.40672668489701, 0.28866272343639, 0.067355999640287)

dW\Pigmentum\Color::withHSB

从RGB值创建一个新的dW\Pigmentum\Color对象。

public static function withHSB(
    float $H,
    float $S,
    float $B,
    ?string $name = null,
    ?string $profile = null
): dW\Pigmentum\Color;
  • H: 色调通道值
  • S: 饱和度通道值
  • B: 亮度通道值
  • name: 与颜色关联的可选名称
  • profile: 颜色配置文件类名的字符串表示,默认为当前工作空间
示例
namespace dW\Pigmentum\Color;

Color::withHSB(18, 64, 79);

dW\Pigmentum\Color::withXYZ

从XYZ值创建一个新的dW\Pigmentum\Color对象。

public static function withXYZ(
    float $X,
    float $Y,
    float $Z,
    ?string $name = null
): dW\Pigmentum\Color;
  • X: X通道值
  • Y: Y通道值
  • Z: Z通道值
  • name: 与颜色关联的可选名称
示例
namespace dW\Pigmentum\Color;

Color::withXYZ(0.3267, 0.2471, 0.0696);

dW\Pigmentum\Color::toLab

返回颜色的L*a*b*色彩空间。

public function toLab(): dW\Pigmentum\ColorSpace\Lab;
示例
namespace dW\Pigmentum\Color;

$color = Color::withHSB(18, 64, 79);
echo $color->toLab() . "\n";
echo $color->Lab;

输出

lab(56.977258534337, 34.064915293425, 37.682616197795)
lab(56.977258534337, 34.064915293425, 37.682616197795)

dW\Pigmentum\Color::toRGB

返回颜色的RGB色彩空间。

public function toRGB(
    ?string $profile = null
): dW\Pigmentum\ColorSpace\RGB;
  • profile: 颜色配置文件类名的字符串表示,默认为当前工作空间
示例
namespace dW\Pigmentum\Color;

$color = Color::withXYZ(0.3267, 0.2471, 0.0696);
echo $color->toRGB() . "\n";
echo $color->RGB;

输出

rgb(201.92948812963, 110.03872289405, 71.957047956757)
rgb(201.92948812963, 110.03872289405, 71.957047956757)

dW\Pigmentum\Color::toXYZ

返回颜色的XYZ色彩空间。

public function toXYZ(): dW\Pigmentum\ColorSpace\XYZ;
示例
namespace dW\Pigmentum\Color;

$color = Color::withRGBHex('#ca6e48');
echo $color->toXYZ() . "\n";
echo $color->XYZ;

输出

xyz(0.32686782145478, 0.24712385141221, 0.069650535956488)
xyz(0.32686782145478, 0.24712385141221, 0.069650535956488)

dW\Pigmentum\Color::average

在L*a*b*色彩空间中平均提供的颜色,并返回一个新的Color对象。等同于dW\Pigmentum\Color::averageWithLab

public static function average(
    dW\Pigmentum\Color ...$colors
): dW\Pigmentum\Color;
  • colors:要平均的一种或多种颜色。
示例
namespace dW\Pigmentum\Color;

$color = Color::average(Color::withRGBHex('#ca6e48'), Color::withXYZ(0.0864, 0.0868, 0.1409), Color::withLab(100, 0, 0));
echo $color->RGB->Hex;

输出

#b49393

dW\Pigmentum\Color::averageWithLab

在L*a*b*颜色空间中平均提供的颜色并返回一个新的Color对象。与dW\Pigmentum\Color::average相同。

public static function averageWithLab(
    dW\Pigmentum\Color ...$colors
): dW\Pigmentum\Color;
  • colors:要平均的一种或多种颜色。
示例
namespace dW\Pigmentum\Color;

$color = Color::averageWithLab(Color::withRGBHex('#ca6e48'), Color::withXYZ(0.0864, 0.0868, 0.1409), Color::withLab(100, 0, 0));
echo $color->RGB->Hex;

输出

#b49393

dW\Pigmentum\Color::averageWithLCHab

在LCH(L*a*b*)颜色空间中平均提供的颜色并返回一个新的Color对象。

public static function averageWithLCHab(
    dW\Pigmentum\Color ...$colors
): dW\Pigmentum\Color;
  • colors:要平均的一种或多种颜色。
示例
namespace dW\Pigmentum\Color;

$color = Color::averageWithLCHab(Color::withRGBHex('#ca6e48'), Color::withXYZ(0.0864, 0.0868, 0.1409), Color::withLab(100, 0, 0));
echo $color->RGB->Hex;

输出

#9a9f71

dW\Pigmentum\Color::averageWithRGB

在RGB颜色空间中平均提供的颜色并返回一个新的Color对象。

public static function averageWithRGB(
    dW\Pigmentum\Color ...$colors
): dW\Pigmentum\Color;
  • colors:要平均的一种或多种颜色。
示例
namespace dW\Pigmentum\Color;

$color = Color::averageWithRGB(Color::withRGBHex('#ca6e48'), Color::withXYZ(0.0864, 0.0868, 0.1409), Color::withLab(100, 0, 0));
echo $color->RGB->Hex;

输出

#b09595

dW\Pigmentum\Color::averageWithHSB

在HSB颜色空间中平均提供的颜色并返回一个新的Color对象。

public static function averageWithHSB(
    dW\Pigmentum\Color ...$colors
): dW\Pigmentum\Color;
  • colors:要平均的一种或多种颜色。
示例
namespace dW\Pigmentum\Color;

$color = Color::averageWithHSB(Color::withRGBHex('#ca6e48'), Color::withXYZ(0.0864, 0.0868, 0.1409), Color::withLab(100, 0, 0));
echo $color->RGB->Hex;

输出

#a9c07c

dW\Pigmentum\Color::mix

在L*a*b*颜色空间中将颜色与提供的颜色混合并返回一个新的Color对象。与dW\Pigmentum\Color::mixWithLab相同。

public function mix(
    dW\Pigmentum\Color $color,
    float $percentage = 0.5
): dW\Pigmentum\Color;
  • color:与$this混合的颜色。
  • percentage:与$this混合颜色的强度。
示例
namespace dW\Pigmentum\Color;

$color = Color::withRGBHex('#ca6e48')->mix(Color::withXYZ(0.0864, 0.0868, 0.1409), 0.625);
echo $color->RGB->Hex;

输出

#7e5e67

dW\Pigmentum\Color::mixWithLab

在L*a*b*颜色空间中将颜色与提供的颜色混合并返回一个新的Color对象。与dW\Pigmentum\Color::mix相同。

public function mixWithLab(
    dW\Pigmentum\Color $color,
    float $percentage = 0.5
): dW\Pigmentum\Color;
  • color:与$this混合的颜色。
  • percentage:与$this混合颜色的强度。
示例
namespace dW\Pigmentum\Color;

$color = Color::withRGBHex('#ca6e48')->mixWithLab(Color::withXYZ(0.0864, 0.0868, 0.1409), 0.625);
echo $color->RGB->Hex;

输出

#7e5e67

dW\Pigmentum\Color::mixWithLCHab

在LCH(L*a*b*)颜色空间中将颜色与提供的颜色混合并返回一个新的Color对象。

public function mixWithLab(
    dW\Pigmentum\Color $color,
    float $percentage = 0.5
): dW\Pigmentum\Color;
  • color:与$this混合的颜色。
  • percentage:与$this混合颜色的强度。
示例
namespace dW\Pigmentum\Color;

$color = Color::withRGBHex('#ca6e48')->mixWithLCHab(Color::withXYZ(0.0864, 0.0868, 0.1409), 0.625);
echo $color->RGB->Hex;

输出

#875587

dW\Pigmentum\Color::mixWithRGB

在RGB颜色空间中将颜色与提供的颜色混合并返回一个新的Color对象。

public function mixWithRGB(
    dW\Pigmentum\Color $color,
    float $percentage = 0.5
): dW\Pigmentum\Color;
  • color:与$this混合的颜色。
  • percentage:与$this混合颜色的强度。
示例
namespace dW\Pigmentum\Color;

$color = Color::withRGBHex('#ca6e48')->mixWithRGB(Color::withXYZ(0.0864, 0.0868, 0.1409), 0.625);
echo $color->RGB->Hex;

输出

#785d65

dW\Pigmentum\Color::mixWithHSB

在HSB颜色空间中将颜色与提供的颜色混合并返回一个新的Color对象。

public function mixWithHSB(
    dW\Pigmentum\Color $color,
    float $percentage = 0.5
): dW\Pigmentum\Color;
  • color:与$this混合的颜色。
  • percentage:与$this混合颜色的强度。
示例
namespace dW\Pigmentum\Color;

$color = Color::withRGBHex('#ca6e48')->mixWithHSB(Color::withXYZ(0.0864, 0.0868, 0.1409), 0.625);
echo $color->RGB->Hex;

输出

#7f4b96

dW\Pigmentum\Color::apcaContrast

计算文本颜色($this)和提供的背景颜色之间的APCA(用于未来WCAG 3)对比度。

注意:此算法正在变化,其结果可能会随着上游参考算法的更新而变化。

public function apcaContrast(
    dW\Pigmentum\Color $backgroundColor
): dW\Pigmentum\Color;
  • backgroundColor:计算对比度的颜色。
示例
namespace dW\Pigmentum\Color;

echo Color::withRGBHex('#ca6e48')->apcaContrast(Color::withXYZ(0.0864, 0.0868, 0.1409));

输出

-21.758825698145

dW\Pigmentum\Color::deltaE

计算$this和提供的颜色之间的CIE2000距离。与dW\Pigmentum\Color::distance相同。

public function deltaE(
    dW\Pigmentum\Color $color
): dW\Pigmentum\Color;
  • color:计算距离的颜色。
示例
namespace dW\Pigmentum\Color;

echo Color::withRGBHex('#ca6e48')->deltaE(Color::withXYZ(0.0864, 0.0868, 0.1409));

输出

41.674529389586

dW\Pigmentum\Color::distance

计算$this和提供的颜色之间的CIE2000距离。CIE2000距离公式在计算时考虑了感知。与dW\Pigmentum\Color::deltaE相同。

public function distance(
    dW\Pigmentum\Color $color
): dW\Pigmentum\Color;
  • color:计算距离的颜色。
示例
namespace dW\Pigmentum\Color;

echo Color::withRGBHex('#ca6e48')->distance(Color::withXYZ(0.0864, 0.0868, 0.1409));

输出

41.674529389586

dW\Pigmentum\Color::euclideanDistance

计算$this和提供的颜色之间的几何欧几里得距离。在计算时不考虑感知。有关感知距离,请参阅dW\Pigmentum\Color::deltaE

public function euclideanDistance(
    dW\Pigmentum\Color $color
): dW\Pigmentum\Color;
  • color:计算距离的颜色。
示例
namespace dW\Pigmentum\Color;

echo Color::withRGBHex('#ca6e48')->euclideanDistance(Color::withXYZ(0.0864, 0.0868, 0.1409));

输出

71.675682240739

dW\Pigmentum\Color::wcag2Contrast

计算$this和提供的颜色之间的WCAG2对比度。

注意:虽然这是目前的网络标准,但它并不非常准确,也不完全正确。只有在法律上必须这样做的情况下才使用。尽管APCA对比度算法正在变化,但它已经比WCAG2对比度比率高得多。

public function wcag2Contrast(
    dW\Pigmentum\Color $color
): dW\Pigmentum\Color;
  • color:计算对比度的颜色。
示例
namespace dW\Pigmentum\Color;

echo Color::withRGBHex('#ca6e48')->wcag2Contrast(Color::withXYZ(0.0864, 0.0868, 0.1409));

输出

2.1117359393426

dW\Pigmentum\ColorSpace\Lab

class dW\Pigmentum\ColorSpace\Lab implements \Stringable {
    public readonly float $L;
    public readonly float $a;
    public readonly float $b;


    public function toLCHab(): dW\Pigmentum\ColorSpace\Lab\LCHab;
}

属性

  • L(float):颜色空间的亮度通道。
  • a(float):颜色空间的a通道。
  • b(float):颜色空间的b通道。

dW\Pigmentum\ColorSpace\Lab::toLCHab

返回颜色的LCH(L*a*b*)颜色空间。

public function toLCHab(): dW\Pigmentum\ColorSpace\Lab\LCHab;
示例
namespace dW\Pigmentum\Color;

$color = Color::withRGBHex('#ca6e48');
echo $color->toLab()->toLCHab() . "\n";
echo $color->Lab->LCHab;

输出

lchab(56.794104953129, 51.406997165638, 47.294986435325)
lchab(56.794104953129, 51.406997165638, 47.294986435325)

dW\Pigmentum\ColorSpace\RGB

class dW\Pigmentum\ColorSpace\RGB implements \Stringable {
    public readonly float $R;
    public readonly float $G;
    public readonly float $B;
    public readonly float $unclampedR;
    public readonly float $unclampedG;
    public readonly float $unclampedB;
    public readonly string $profile;
    public readonly bool $outOfGamut;


    public function changeProfile(?string $profile = null): dW\Pigmentum\ColorSpace\RGB;
    public function convertToWorkingSpace(?string $profile = null): dW\Pigmentum\ColorSpace\RGB;

    public function toHex(): string;
    public function toHSB(): dW\Pigmentum\ColorSpace\RGB\HSB;
}

属性

  • R(float):颜色空间的R通道。
  • G(float):颜色空间的G通道。
  • B(float):颜色空间的B通道。
  • unclampedR(float):如果颜色超出了配置文件的范围,这将表示颜色空间的未限制R通道,否则与R相同。
  • unclampedG(float):如果颜色超出了配置文件的范围,这将表示颜色空间的未限制G通道,否则与G相同。
  • unclampedB (浮点型): 如果颜色超出配置文件的色彩范围,则此值表示该色彩空间未限制的B通道,否则与B通道相同
  • profile (字符串): 表示色彩空间中通道值所使用的色彩配置文件类名的字符串表示
  • outOfGamut (布尔型): 如果颜色超出配置文件的色彩范围则为True,否则为False

dW\Pigmentum\ColorSpace\RGB::changeProfile

将色彩配置文件转换为所提供的配置文件,并返回RGB色彩空间。

public function changeProfile(
    ?string $profile = null
): dW\Pigmentum\ColorSpace\RGB;
  • profile: 颜色配置文件类名的字符串表示,默认为当前工作空间
示例
namespace dW\Pigmentum\Color;

// sRGB is the default working space
$color = Color::withRGBHex('#ca6e48');
echo $color->RGB . "\n";
echo $color->RGB->changeProfile(Color::PROFILE_DISPLAYP3);

输出

rgb(202, 110, 72)
rgb(189.75848271875, 114.65981939776, 80.081758134176)

dW\Pigmentum\ColorSpace\RGB::toHex

返回该色彩的RGB十六进制字符串。

public function toRGBHex(): string;
示例
namespace dW\Pigmentum\Color;

$color = Color::withRGBHex('#ca6e48');
echo $color->toRGB()->toHex() . "\n";
echo $color->RGB->Hex;

输出

lchab(56.794104953129, 51.406997165638, 47.294986435325)
lchab(56.794104953129, 51.406997165638, 47.294986435325)

dW\Pigmentum\ColorSpace\RGB::toHSB

返回该色彩的HSB色彩空间。

public function toHSB(): dW\Pigmentum\ColorSpace\RGB\HSB;
示例
namespace dW\Pigmentum\Color;

$color = Color::withRGBHex('#ca6e48');
echo $color->toRGB()->toHSB() . "\n";
echo $color->RGB->HSB;

输出

hsb(17.538461538462, 64.356435643564, 79.21568627451)
hsb(17.538461538462, 64.356435643564, 79.21568627451)

dW\Pigmentum\ColorSpace\XYZ

class dW\Pigmentum\ColorSpace\XYZ implements \Stringable {
    public function toLMS(): dW\Pigmentum\ColorSpace\XYZ\LMS;
    public function chromaticAdaptation(array $new, array $old): dW\Pigmentum\ColorSpace\XYZ;
}

属性

  • X (浮点型): 该色彩空间的X通道。
  • Y (浮点型): 该色彩空间的Y通道。
  • Z (浮点型): 该色彩空间的Z通道。

dW\Pigmentum\ColorSpace\XYZ::toLMS

返回该色彩的LMS色彩空间。

public function toLMS(): dW\Pigmentum\ColorSpace\XYZ\LMS;
示例
namespace dW\Pigmentum\Color;

$color = Color::withRGBHex('#ca6e48');
echo $color->toXYZ()->toLMS() . "\n";
echo $color->XYZ->LMS;

输出

lms(0.34717158449701, 0.18078665440905, 0.067499366253654)
lms(0.34717158449701, 0.18078665440905, 0.067499366253654)

dW\Pigmentum\ColorSpace\XYZ::chromaticAdaptation

将XYZ色彩从一个光源转换为另一个光源。

public function chromaticAdaptation(array $new, array $old): dW\Pigmentum\ColorSpace\XYZ;
  • new: 转换为的新光源
  • old: 转换的旧光源
示例
namespace dW\Pigmentum\Color;

// XYZ D50
$color = Color::withRGBHex('#ca6e48')->XYZ;
echo $color . "\n";
// XYZ D65
echo $color->chromaticAdaptation(Color::ILLUMINANT_D65, Color::ILLUMINANT_D50);

输出

xyz(0.32686782145478, 0.24712385141221, 0.069650535956488)
xyz(0.31105305562791, 0.24179691491906, 0.091586962737883)

dW\Pigmentum\ColorSpace\Lab\LCHab

class dW\Pigmentum\ColorSpace\Lab\LCHab implements \Stringable {
    public readonly float $L;
    public readonly float $C;
    public readonly float $H;
}

属性

  • L(float):颜色空间的亮度通道。
  • C (浮点型): 该色彩空间的色度通道。
  • H (浮点型): 该色彩空间的色调通道。

dW\Pigmentum\ColorSpace\RGB\HSB

class dW\Pigmentum\ColorSpace\RGB\HSB implements \Stringable {
    public readonly float $H;
    public readonly float $S;
    public readonly float $B;
}

属性

  • H (浮点型): 该色彩空间的色调通道。
  • S (浮点型): 该色彩空间的饱和度通道。
  • B (浮点型): 该色彩空间的亮度通道。

dW\Pigmentum\ColorSpace\XYZ\LMS

class dW\Pigmentum\ColorSpace\XYZ\LMS implements \Stringable {
    public readonly float $rho;
    public readonly float $gamma;
    public readonly float $beta;
}

属性

  • rho (浮点型): 该色彩空间的ρ(L)通道。
  • gamma (浮点型): 该色彩空间的γ(M)通道。
  • beta (浮点型): 该色彩空间的β(S)通道。

dW\Pigmentum\Profile\RGB

这是基础抽象色彩配置文件类。所有RGB色彩配置文件都必须从该类继承。

abstract class dW\Pigmentum\Profile\RGB {
    const illuminant = dW\Pigmentum\Color::ILLUMINANT_D65;
    const chromaticity = [];
    const gamma = 2.2;
    const name = '';

    protected static array $xyzMatrix;
    protected static array $xyzMatrixInverse;


    public static function companding(float $channel): float;
    public static function inverseCompanding(float $channel): float;
    public static function getXYZMatrix(): MathPHP\LinearAlgebra\Matrix\Matrix;
}

dW\Pigmentum\Profile\RGB\AdobeRGB1998

class dW\Pigmentum\Profile\AdobeRGB1998 extends dW\Pigmentum\Profile\RGB {
    const name = 'Adobe RGB (1998)';

    const chromaticity = [
        [ 0.6400, 0.3300 ],
        [ 0.2100, 0.7100 ],
        [ 0.1500, 0.0600 ]
    ];

    protected static array $xyzMatrix = [
        [ 0.5767308871981477, 0.18555395071121408, 0.18818516209063843 ],
        [ 0.29737686371154487, 0.6273490714522, 0.07527406483625537 ],
        [ 0.027034260337413143, 0.0706872193185578, 0.9911085203440292 ]
    ];

    protected static array $xyzMatrixInverse = [
        [ 2.04136897926008, -0.5649463871751956, -0.34469438437784833 ],
        [ -0.9692660305051868, 1.8760108454466942, 0.041556017530349834 ],
        [ 0.013447387216170259, -0.11838974235412557, 1.0154095719504166 ]
    ];
}

dW\Pigmentum\Profile\RGB\DisplayP3

class dW\Pigmentum\Profile\AdobeRGB1998 extends dW\Pigmentum\Profile\RGB {
    const name = 'Display P3';

    const chromaticity = [
        [ 0.680, 0.320 ],
        [ 0.265, 0.690 ],
        [ 0.150, 0.060 ]
    ];

    protected static array $xyzMatrix = [
        [ 0.48663265, 0.2656631625, 0.1981741875 ],
        [ 0.2290036, 0.6917267249999999, 0.079269675 ],
        [ -3.972579210032023E-17, 0.04511261250000004, 1.0437173875 ]
    ];

    protected static array $xyzMatrixInverse = [
        [ 2.4931807553289667, -0.9312655254971397, -0.40265972375888165 ],
        [ -0.8295031158210787, 1.7626941211197922, 0.02362508874173958 ],
        [ 0.03585362578007169, -0.07618895478265217, 0.9570926215180212 ]
    ];
}

dW\Pigmentum\Profile\RGB\ProPhoto

class dW\Pigmentum\Profile\ProPhoto extends dW\Pigmentum\Profile\RGB {
    const name = 'ProPhoto RGB';

    const illuminant = Color::ILLUMINANT_D50;

    const chromaticity = [
        [ 0.7347, 0.2653 ],
        [ 0.1596, 0.8404 ],
        [ 0.0366, 0.0001 ]
    ];

    const gamma = 1.8;

    protected static array $xyzMatrix = [
        [ 0.7976749444306044, 0.13519170147409815, 0.031353354095297416 ],
        [ 0.2880402378623102, 0.7118740972357901, 8.566490189971971E-5 ],
        [ 0, 0, 0.82521 ]
    ];

    protected static array $xyzMatrixInverse = [
        [ 1.3459433009386654, -0.25560750931676696, -0.05111176587088495 ],
        [ -0.544598869458717, 1.508167317720767, 0.020535141586646915 ],
        [ 0, 0, 1.2118127506937628 ]
    ];
}

dW\Pigmentum\Profile\RGB\Simple_sRGB

class dW\Pigmentum\Profile\Simple_sRGB extends dW\Pigmentum\Profile\RGB {
    const name = 'Simple sRGB';

    const chromaticity = [
        [ 0.6400, 0.3300 ],
        [ 0.3000, 0.6000 ],
        [ 0.1500, 0.0600 ]
    ];

    protected static array $xyzMatrix = [
        [ 0.4124564390896922, 0.357576077643909, 0.18043748326639894 ],
        [ 0.21267285140562253, 0.715152155287818, 0.07217499330655958 ],
        [ 0.0193338955823293, 0.11919202588130297, 0.9503040785363679 ]
    ];

    protected static array $xyzMatrixInverse = [
        [ 3.2404541621141045, -1.5371385127977166, -0.498531409556016 ],
        [ -0.9692660305051868, 1.8760108454466942, 0.041556017530349834 ],
        [ 0.055643430959114726, -0.2040259135167538, 1.0572251882231791 ]
    ];
}

dW\Pigmentum\Profile\RGB\sRGB

class dW\Pigmentum\Profile\Simple_sRGB extends dW\Pigmentum\Profile\RGB {
    const name = 'sRGB IEC61966-2.1';

    const chromaticity = [
        [ 0.6400, 0.3300 ],
        [ 0.3000, 0.6000 ],
        [ 0.1500, 0.0600 ]
    ];

    protected static array $xyzMatrix = [
        [ 0.4124564390896922, 0.357576077643909, 0.18043748326639894 ],
        [ 0.21267285140562253, 0.715152155287818, 0.07217499330655958 ],
        [ 0.0193338955823293, 0.11919202588130297, 0.9503040785363679 ]
    ];

    protected static array $xyzMatrixInverse = [
        [ 3.2404541621141045, -1.5371385127977166, -0.498531409556016 ],
        [ -0.9692660305051868, 1.8760108454466942, 0.041556017530349834 ],
        [ 0.055643430959114726, -0.2040259135167538, 1.0572251882231791 ]
    ];
}