Entfernung nicht ausgeführten Codes und Dokumentation der Wertebereiche zur besseren Darstellung der möglichen Risiken. #2
@@ -74,7 +74,9 @@ class CyanMagentaYellowKeyToHueSaturationValue
|
||||
|
||||
protected function buildHueAmount(): float
|
||||
{
|
||||
if ($this->maxCmyProperty === 0.0) {
|
||||
// Wenn beide Werte gleich sind, ist die Endfarbe Grau.
|
||||
// Damit wird auch in {@sse hueAmount()} eine Division durch Null verhindert.
|
||||
if ($this->maxCmyProperty === $this->minCmyProperty) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@@ -91,30 +93,32 @@ class CyanMagentaYellowKeyToHueSaturationValue
|
||||
*/
|
||||
private function hueAmount(string $property): float
|
||||
{
|
||||
static $amount_share = 2.0;
|
||||
|
||||
// Wertebereich: [0.0, 1.0]
|
||||
$divisor = $this->maxCmyProperty - $this->minCmyProperty;
|
||||
// Wertebereich: [1.0, 5.0]
|
||||
$amount = 0.0;
|
||||
// Wertebereich: [-1.0, +1.0]
|
||||
$dividend = 0.0;
|
||||
|
||||
switch ($property) {
|
||||
case self::PROPERTY_YELLOW:
|
||||
$amount = 0; // 0.167
|
||||
$amount = 1.0; // 0.167
|
||||
$dividend = $this->cyan - $this->magenta;
|
||||
break;
|
||||
case self::PROPERTY_CYAN:
|
||||
$amount = 1; // 0.500
|
||||
$amount = 3.0; // 0.500
|
||||
$dividend = $this->magenta -$this->yellow;
|
||||
break;
|
||||
case self::PROPERTY_MAGENTA:
|
||||
$amount = 2; // 0.833
|
||||
$amount = 5.0; // 0.833
|
||||
$dividend = $this->yellow - $this->cyan;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
$start_amount = ($amount * $amount_share) + 1.0;
|
||||
// Wertebereich: [-1.0, +1.0]
|
||||
$expansion_amount = $dividend / $divisor;
|
||||
return ($start_amount + $expansion_amount) / 6.0;
|
||||
// Wertebereich: [+0.0, +6.0]
|
||||
return ($amount + $expansion_amount) / 6.0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -58,10 +58,6 @@ class RedGreenBlueToHueSaturationValue
|
||||
while($this->hue < 0.0) {
|
||||
$this->hue += 1.0;
|
||||
}
|
||||
|
||||
while($this->hue > 1.0) {
|
||||
$this->hue -= 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
public function convert(): HueSaturationValue
|
||||
@@ -76,6 +72,8 @@ class RedGreenBlueToHueSaturationValue
|
||||
|
||||
protected function buildHueAmount(): float
|
||||
{
|
||||
// Wenn beide Werte gleich sind, ist die Endfarbe Grau.
|
||||
// Damit wird auch in {@sse hueAmount()} eine Division durch Null verhindert.
|
||||
if ($this->maxRgbProperty === $this->minRgbProperty) {
|
||||
return 0.0;
|
||||
}
|
||||
@@ -105,30 +103,32 @@ class RedGreenBlueToHueSaturationValue
|
||||
*/
|
||||
private function hueAmount(string $property): float
|
||||
{
|
||||
static $amount_share = 2.0;
|
||||
|
||||
// Wertebereich: [0.0, 1.0]
|
||||
$divisor = $this->maxRgbProperty - $this->minRgbProperty;
|
||||
// Wertebereich: [1.0, 5.0]
|
||||
$amount = 0.0;
|
||||
// Wertebereich: [-1.0, +1.0]
|
||||
$dividend = 0.0;
|
||||
|
||||
switch ($property) {
|
||||
case self::PROPERTY_RED:
|
||||
$amount = 0; // 0.0
|
||||
$amount = 0.0; // 0.0
|
||||
$dividend = $this->green - $this->blu;
|
||||
break;
|
||||
case self::PROPERTY_GREEN:
|
||||
$amount = 1; // 0.333
|
||||
$amount = 2.0; // 0.333
|
||||
$dividend = $this->blu -$this->red;
|
||||
break;
|
||||
case self::PROPERTY_BLUE:
|
||||
$amount = 2; // 0.999
|
||||
$amount = 4.0; // 0.999
|
||||
$dividend = $this->red - $this->green;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
$start_amount = $amount * $amount_share;
|
||||
// Wertebereich: [-1.0, +1.0]
|
||||
$expansion_amount = $dividend / $divisor;
|
||||
return ($start_amount + $expansion_amount) / 6.0;
|
||||
// Wertebereich: [-1.0, +5.0]
|
||||
return ($amount + $expansion_amount) / 6.0;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user