Die Umwandlung von HSV zu CMYK ist erfolgreich.

This commit is contained in:
2021-03-18 08:34:54 +01:00
parent c949643d26
commit ad2a7ddd16
@@ -10,11 +10,13 @@ use TorstenHettstedt\Colors\ColorModels\HueSaturationValue;
class HueSaturationValueToCyanMagentaYellowKey
{
/** @var int : Größe des Intervals in 1/100 Grad */
protected const INTERVAL = 60 * 100;
protected const INTERVAL = 60.0 * 100.0;
// Daten für HSV
/** @var float : Definition des Farbton als Anteil eines Vollkreises '$Hue * π' */
protected float $hue;
/** @var float : Anteil am Vollkreis in 1/100 Grad */
protected float $hueAsPercentGrad;
/** @var float : Definition der Sättigung der Farbe */
protected float $saturation;
/** @var float : Definition der Helligkeit der Farbe */
@@ -38,6 +40,7 @@ class HueSaturationValueToCyanMagentaYellowKey
public function __construct(HueSaturationValue $from_color)
{
$this->hue = $from_color->getHue();
$this->hueAsPercentGrad = intval($this->hue * self::INTERVAL * 6);
$this->saturation = $from_color->getSaturation();
$this->value = $from_color->getValue();
}
@@ -56,59 +59,52 @@ class HueSaturationValueToCyanMagentaYellowKey
protected function processConvert(): void
{
if ($this->saturation === 0.0) {
$this->key = $this->value;
} else {
$this->key = 1 - $this->value;
if ($this->saturation !== 0.0) {
$this->splitColor();
}
}
protected function splitColor(): void
{
// // Anteil am Vollkreis in 1/100 Grad
// $percent_grad = intval($this->hue * 360 * 100);
// // ID des zu nutzenden Interval
// $interval_id = intdiv($percent_grad , self::INTERVAL);
// // Rest-Anteil am Vollkreis des aktuellen Intervals als Wert '[0,1]'
// $remainder = (($percent_grad % self::INTERVAL) / self::INTERVAL);
// $help_values = [
// $this->value,
// $this->value * ( 1 - $this->saturation),
// $this->value * ( 1 - $this->saturation * $remainder),
// $this->value * ( 1 - $this->saturation * (1 - $remainder)),
// ];
// switch ($interval_id) {
// case 1:
// $this->red = $help_values[2];
// $this->green = $help_values[0];
// $this->blu = $help_values[1];
// break;
// case 2:
// $this->red = $help_values[1];
// $this->green = $help_values[0];
// $this->blu = $help_values[3];
// break;
// case 3:
// $this->red = $help_values[1];
// $this->green = $help_values[2];
// $this->blu = $help_values[0];
// break;
// case 4:
// $this->red = $help_values[3];
// $this->green = $help_values[1];
// $this->blu = $help_values[0];
// break;
// case 5:
// $this->red = $help_values[0];
// $this->green = $help_values[1];
// $this->blu = $help_values[2];
// break;
// default:
// $this->red = $help_values[0];
// $this->green = $help_values[3];
// $this->blu = $help_values[1];
// break;
// }
// ID des zu nutzenden Interval
$interval_id = intdiv($this->hueAsPercentGrad , self::INTERVAL);
switch ($interval_id) {
case 1: // Yellow
$this->cyan = $this->calcRemainder();
$this->yellow = $this->saturation;
break;
case 2:
$this->cyan = $this->saturation;
$this->yellow = $this->calcRemainder(true);
break;
case 3: // Cyan
$this->cyan = $this->saturation;
$this->magenta = $this->calcRemainder();
break;
case 4:
$this->cyan = $this->calcRemainder(true);
$this->magenta = $this->saturation;
break;
case 5: // Magenta
$this->magenta = $this->saturation;
$this->yellow = $this->calcRemainder();
break;
default:
$this->magenta = $this->calcRemainder(true);
$this->yellow = $this->saturation;
break;
}
}
protected function calcRemainder($reciprocal = false): float
{
// Rest-Anteil am Vollkreis des aktuellen Intervals als Wert '[0,1]'
$remainder_grad = $this->hueAsPercentGrad % self::INTERVAL;
// Rest-Anteil am Vollkreis des aktuellen Intervals als Wert '[0,1]'
$remainder = $remainder_grad / self::INTERVAL;
return $this->saturation * ($reciprocal ? (1 - $remainder) : $remainder);
}
}