mirror of
https://github.com/CeeWeasel/fresh-home.git
synced 2026-08-09 10:30:14 -04:00
46 lines
1.1 KiB
PowerShell
46 lines
1.1 KiB
PowerShell
function Get-ColorXY ([int]$Red=0, [int]$Green=0, [int]$Blue=0, [int]$Decimals=4)
|
|
{
|
|
$redC = ($red / 255)
|
|
$greenC = ($green / 255)
|
|
$blueC = ($blue / 255)
|
|
|
|
if ($redC -gt 0.04045) {
|
|
$redN = [math]::pow(($redC + .055) / (1 + .055),2.4)
|
|
} else {
|
|
$redN = $redC / 12.92
|
|
}
|
|
|
|
if ($greenC -gt 0.04045) {
|
|
$greenN = [math]::pow(($greenC + .055) / (1 + .055),2.4)
|
|
} else {
|
|
$greenN = $greenC / 12.92
|
|
}
|
|
|
|
if ($blueC -gt 0.04045) {
|
|
$blueN = [math]::pow(($blueC + .055) / (1 + .055),2.4)
|
|
} else {
|
|
$blueN = $blueC / 12.92
|
|
}
|
|
|
|
$X = $redN * 0.664511 + $greenN * 0.154324 + $blueN * 0.162028;
|
|
|
|
$Y = $redN * 0.283881 + $greenN * 0.668433 + $blueN * 0.047685;
|
|
|
|
$Z = $redN * 0.000088 + $greenN * 0.072310 + $blueN * 0.986039;
|
|
|
|
if (($X+$Y+$Z) -gt 0) {
|
|
$x2 = $X / ($X + $Y + $Z)
|
|
$y2 = $Y / ($X + $Y + $Z)
|
|
} else {
|
|
$x2 = 0
|
|
$y2 = 0
|
|
}
|
|
|
|
[pscustomobject]@{
|
|
color_x = [math]::Round($x2,$Decimals)
|
|
color_y = [math]::Round($y2,$Decimals)
|
|
}
|
|
|
|
#$x2, $y2
|
|
|
|
} |