if (isset($matches[5])) {
$this->_alpha = $matches[5];
}
+ } else if (preg_match('/hsv\(\s*(\d+)\s*,\s*(\d+)%?\s*,\s*(\d+)%?\s*\)/', $input, $matches)) {
+ $this->_processComposantes(self::HSVtoRGB($matches[1], $matches[2], $matches[3]));
} else {
- if (strlen($input) == 6) {
- $s = 0;
- } elseif (strlen($input) >= 8) {
- $s = 2;
- $c['alpha'] = substr($input, 0, 2);
+ if (strlen($input) == 3) {
+ $c['red'] = str_repeat(substr($input, 0, 1), 2);
+ $c['green'] = str_repeat(substr($input, 1, 1), 2);
+ $c['blue'] = str_repeat(substr($input, 2, 1), 2);
+ } else {
+ if (strlen($input) == 6) {
+ $s = 0;
+ } elseif (strlen($input) >= 8) {
+ $s = 2;
+ $c['alpha'] = substr($input, 0, 2);
+ }
+ $c['red'] = substr($input, $s + 0, 2);
+ $c['green'] = substr($input, $s + 2, 2);
+ $c['blue'] = substr($input, $s + 4, 2);
}
- $c['red'] = substr($input, $s + 0, 2);
- $c['green'] = substr($input, $s + 2, 2);
- $c['blue'] = substr($input, $s + 4, 2);
$this->_processComposantes($c);
}
return round($c * self::NORM);
}
+
+ public static function HSVtoRGB($h, $s, $v)
+ {
+ //1
+ $h *= 6;
+ //2
+ $i = floor($h);
+ $f = $h - $i;
+ //3
+ $m = $v * (1 - $s);
+ $n = $v * (1 - $s * $f);
+ $k = $v * (1 - $s * (1 - $f));
+ //4
+ switch ($i) {
+ case 0:
+ list($r, $g, $b) = array($v, $k, $m);
+ break;
+ case 1:
+ list($r, $g, $b) = array($n, $v, $m);
+ break;
+ case 2:
+ list($r, $g, $b) = array($m, $v, $k);
+ break;
+ case 3:
+ list($r, $g, $b) = array($m, $n, $v);
+ break;
+ case 4:
+ list($r, $g, $b) = array($k, $m, $v);
+ break;
+ case 5:
+ case 6: //for when $h=1 is given
+ list($r, $g, $b) = array($v, $m, $n);
+ break;
+ }
+ return ['red' => $r, 'green' => $g, 'blue' => $b,];
+ }
}