From 435dff067fcd02d3463a215cdf8a26051f0b5ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Tue, 9 Mar 2021 14:26:19 +0100 Subject: [PATCH] Grundaufbau ist vorhanden. Tests laufen noch nicht durch. --- .../HueSaturationValueTransformer.php | 41 ++++++ src/Transformer/RedGreenBlueTransformer.php | 42 ++++++ ...eSaturationValueToCyanMagentaYellowKey.php | 114 +++++++++++++++++ .../RedGreenBlueToHueSaturationValue.php | 120 ++++++++++++++++++ 4 files changed, 317 insertions(+) create mode 100644 src/Transformer/HueSaturationValueTransformer.php create mode 100644 src/Transformer/RedGreenBlueTransformer.php create mode 100644 src/Transformer/Utilities/HueSaturationValueToCyanMagentaYellowKey.php create mode 100644 src/Transformer/Utilities/RedGreenBlueToHueSaturationValue.php diff --git a/src/Transformer/HueSaturationValueTransformer.php b/src/Transformer/HueSaturationValueTransformer.php new file mode 100644 index 0000000..8147e30 --- /dev/null +++ b/src/Transformer/HueSaturationValueTransformer.php @@ -0,0 +1,41 @@ +color = $color; + } + + + public function toRedGreenBlue(): RedGreenBlue + { + $utility = new Utilities\HueSaturationValueToRedGreenBlue($this->color); + return $utility->convert(); + } + + public function toCyanMagentaYellowKey(): CyanMagentaYellowKey + { + $utility = new Utilities\HueSaturationValueToCyanMagentaYellowKey($this->color); + return $utility->convert(); + } + + public function toHueSaturationValue(): HueSaturationValue + { + return clone $this->color; + } +} \ No newline at end of file diff --git a/src/Transformer/RedGreenBlueTransformer.php b/src/Transformer/RedGreenBlueTransformer.php new file mode 100644 index 0000000..062256d --- /dev/null +++ b/src/Transformer/RedGreenBlueTransformer.php @@ -0,0 +1,42 @@ +color = $color; + } + + + public function toRedGreenBlue(): RedGreenBlue + { + return clone $this->color; + } + + public function toCyanMagentaYellowKey(): CyanMagentaYellowKey + { + $hsv_color = (new Utilities\RedGreenBlueToHueSaturationValue($this->color))->convert(); + $utility = new Utilities\HueSaturationValueToCyanMagentaYellowKey($hsv_color); + return $utility->convert(); + } + + public function toHueSaturationValue(): HueSaturationValue + { + $utility = new Utilities\RedGreenBlueToHueSaturationValue($this->color); + return $utility->convert(); + } +} \ No newline at end of file diff --git a/src/Transformer/Utilities/HueSaturationValueToCyanMagentaYellowKey.php b/src/Transformer/Utilities/HueSaturationValueToCyanMagentaYellowKey.php new file mode 100644 index 0000000..eb9bac5 --- /dev/null +++ b/src/Transformer/Utilities/HueSaturationValueToCyanMagentaYellowKey.php @@ -0,0 +1,114 @@ +hue = $from_color->getHue(); + $this->saturation = $from_color->getSaturation(); + $this->value = $from_color->getValue(); + } + + public function convert(): CyanMagentaYellowKey + { + $this->processConvert(); + + return (new CyanMagentaYellowKey()) + ->setCyan($this->cyan) + ->setMagenta($this->magenta) + ->setYellow($this->yellow) + ->setKey($this->key); + } + + + protected function processConvert(): void + { + if ($this->saturation === 0.0) { + $this->key = $this->value; + } else { + $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; +// } + } + +} \ No newline at end of file diff --git a/src/Transformer/Utilities/RedGreenBlueToHueSaturationValue.php b/src/Transformer/Utilities/RedGreenBlueToHueSaturationValue.php new file mode 100644 index 0000000..865b36b --- /dev/null +++ b/src/Transformer/Utilities/RedGreenBlueToHueSaturationValue.php @@ -0,0 +1,120 @@ +red = $from_color->getRed(); + $this->green = $from_color->getGreen(); + $this->blu = $from_color->getBlue(); + } + + protected function processConvert(): void + { +// $this->maxCmyProperty = max($this->cyan, $this->magenta, $this->yellow); +// $this->minCmyProperty = min($this->cyan, $this->magenta, $this->yellow); +// +// $this->hue = $this->buildHueAmount(); +// $this->saturation = $this->maxCmyProperty; +// $this->value = 1 - $this->key; + } + + public function convert(): HueSaturationValue + { + $this->processConvert(); + + return (new HueSaturationValue()) + ->setHue($this->hue) + ->setSaturation($this->saturation) + ->setValue($this->value); + } + + protected function buildHueAmount(): float + { + return 0.0; +// if ($this->maxCmyProperty === 0) { +// return 0.0; +// } +// +// return match ($this->maxCmyProperty) { +// $this->cyan => $this->hueAmount(self::PROPERTY_CYAN), +// $this->magenta => $this->hueAmount(self::PROPERTY_MAGENTA), +// default => $this->hueAmount(self::PROPERTY_YELLOW), +// }; + } + + /** + * @param string $property : Name der CMYK-Eigenschaft + * + * @return float + */ + private function hueAmount(string $property): float + { +// if ($this->maxCmyProperty === 0.0) { +// return 0.0; +// } +// +// static $amount_share = 2.0; +// +// $divisor = $this->maxCmyProperty - $this->minCmyProperty; +// +// switch ($property) { +// case self::PROPERTY_YELLOW: +// $amount = 0; // 0.167 +// $dividend = $this->cyan - $this->magenta; +// break; +// case self::PROPERTY_CYAN: +// $amount = 1; // 0.500 +// $dividend = $this->magenta -$this->yellow; +// break; +// case self::PROPERTY_MAGENTA: +// $amount = 2; // 0.833 +// $dividend = $this->yellow - $this->cyan; +// break; +// default: +// return 0; +// } +// +// $start_amount = ($amount * $amount_share) + 1.0; +// $expansion_amount = $dividend / $divisor; +// return ($start_amount + $expansion_amount) / 6.0; + } + +} \ No newline at end of file