X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=bin%2Frgb_hsv.php;fp=bin%2Frgb_hsv.php;h=d081972a277f34686f8e9e408449bb1d0985cbd5;hb=a7c27731c76675c8b96af91501dba188ba4c506f;hp=0000000000000000000000000000000000000000;hpb=756db36445a1f56b262e54f1c6343c2b57b8fa5b;p=brisk.git diff --git a/bin/rgb_hsv.php b/bin/rgb_hsv.php new file mode 100755 index 0000000..d081972 --- /dev/null +++ b/bin/rgb_hsv.php @@ -0,0 +1,108 @@ +#!/usr/bin/php +1) $H--; + } + + $HSL = array($H * $norm, $S * $norm, $V * $norm); + + return $HSL; +} + +function HSV_to_RGB($norm, $H, $S, $V) { + $H /= $norm; + $S /= $norm; + $V /= $norm; + //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 array($R * $norm, $G * $norm, $B * $norm); +} + +function main() +{ + GLOBAL $argv; + + if ($argv[1] == "-tohsv" || $argv[1] == "-toxhsv") { + $a = RGB_to_HSV($argv[2], $argv[3], $argv[4], $argv[5]); + if ($argv[1] == "-tohsv") { + printf("%f,%f,%f\n", $a[0], $a[1], $a[2]); + } + else { + printf("%02x%02x%02x\n", (int)$a[0], (int)$a[1], (int)$a[2]); + } + } + + if ($argv[1] == "-torgb" || $argv[1] == "-toxrgb") { + $a = HSV_to_RGB($argv[2], $argv[3], $argv[4], $argv[5]); + if ($argv[1] == "-torgb") { + printf("%f,%f,%f\n", $a[0], $a[1], $a[2]); + } + else { + printf("%02x%02x%02x\n", (int)$a[0], (int)$a[1], (int)$a[2]); + } + } +} + +main(); + +?> \ No newline at end of file