Grundaufbau ist vorhanden. Tests laufen noch nicht durch.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace TorstenHettstedt\Colors\Transformer;
|
||||
|
||||
|
||||
use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey;
|
||||
use TorstenHettstedt\Colors\ColorModels\HueSaturationValue;
|
||||
use TorstenHettstedt\Colors\ColorModels\RedGreenBlue;
|
||||
|
||||
class HueSaturationValueTransformer implements ColorModelTransformInterface
|
||||
{
|
||||
|
||||
protected HueSaturationValue $color;
|
||||
|
||||
/**
|
||||
* @param HueSaturationValue $color
|
||||
*/
|
||||
public function __construct(HueSaturationValue $color)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace TorstenHettstedt\Colors\Transformer;
|
||||
|
||||
|
||||
use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey;
|
||||
use TorstenHettstedt\Colors\ColorModels\HueSaturationValue;
|
||||
use TorstenHettstedt\Colors\ColorModels\RedGreenBlue;
|
||||
|
||||
class RedGreenBlueTransformer implements ColorModelTransformInterface
|
||||
{
|
||||
|
||||
protected RedGreenBlue $color;
|
||||
|
||||
/**
|
||||
* @param RedGreenBlue $color
|
||||
*/
|
||||
public function __construct(RedGreenBlue $color)
|
||||
{
|
||||
$this->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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace TorstenHettstedt\Colors\Transformer\Utilities;
|
||||
|
||||
|
||||
use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey;
|
||||
use TorstenHettstedt\Colors\ColorModels\HueSaturationValue;
|
||||
|
||||
class HueSaturationValueToCyanMagentaYellowKey
|
||||
{
|
||||
/** @var int : Größe des Intervals in 1/100 Grad */
|
||||
protected const INTERVAL = 60 * 100;
|
||||
|
||||
// Daten für HSV
|
||||
/** @var float : Definition des Farbton als Anteil eines Vollkreises '$Hue * π' */
|
||||
protected float $hue;
|
||||
/** @var float : Definition der Sättigung der Farbe */
|
||||
protected float $saturation;
|
||||
/** @var float : Definition der Helligkeit der Farbe */
|
||||
protected float $value;
|
||||
|
||||
// Daten für CMYK
|
||||
/** @var float : Definition des Cyan-Anteil */
|
||||
protected float $cyan = 0.0;
|
||||
/** @var float : Definition des Magenta-Anteil */
|
||||
protected float $magenta = 0.0;
|
||||
/** @var float : Definition des Gelbanteil */
|
||||
protected float $yellow = 0.0;
|
||||
/** @var float : Definition des Schwarzanteil */
|
||||
protected float $key = 0.0;
|
||||
|
||||
/**
|
||||
* HueSaturationValueToRedGreenBlue constructor.
|
||||
* @param HueSaturationValue $from_color
|
||||
* @noinspection PhpPureAttributeCanBeAddedInspection
|
||||
*/
|
||||
public function __construct(HueSaturationValue $from_color)
|
||||
{
|
||||
$this->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;
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace TorstenHettstedt\Colors\Transformer\Utilities;
|
||||
|
||||
use TorstenHettstedt\Colors\ColorModels\HueSaturationValue;
|
||||
use TorstenHettstedt\Colors\ColorModels\RedGreenBlue;
|
||||
|
||||
class RedGreenBlueToHueSaturationValue
|
||||
{
|
||||
const PROPERTY_RED = 'red';
|
||||
const PROPERTY_GREEN = 'green';
|
||||
const PROPERTY_BLUE = 'blue';
|
||||
|
||||
// Daten für RGB
|
||||
/** @var float : Definition des Rotanteil */
|
||||
protected float $red;
|
||||
/** @var float : Definition des Grünanteil */
|
||||
protected float $green;
|
||||
/** @var float : Definition des Blauanteil */
|
||||
protected float $blu;
|
||||
|
||||
/** @var float : Der größte RGB-Farbwert */
|
||||
protected float $maxRgbProperty;
|
||||
/** @var float : Der kleinste RGB-Farbwert */
|
||||
protected float $minRgbProperty;
|
||||
|
||||
// Daten für HSV
|
||||
/** @var float : Definition des Farbton als Anteil eines Vollkreises '$Hue * π' */
|
||||
protected float $hue = 0.0;
|
||||
/** @var float : Definition der Sättigung der Farbe */
|
||||
protected float $saturation = 0.0;
|
||||
/** @var float : Definition der Helligkeit der Farbe */
|
||||
protected float $value = 1.0;
|
||||
|
||||
/**
|
||||
* CyanMagentaYellowKeyToHueSaturationValue constructor.
|
||||
*
|
||||
* @param RedGreenBlue $from_color
|
||||
*
|
||||
* @noinspection PhpPureAttributeCanBeAddedInspection
|
||||
*/
|
||||
public function __construct(RedGreenBlue $from_color)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user