255) { $rdec = 255; } if ($gdec < 0) { $gdec = 0; } elseif ($gdec > 255) { $gdec = 255; } if ($bdec < 0) { $bdec = 0; } elseif ($bdec > 255) { $bdec = 255; } } elseif ($_GET[mode] == 'hsb') { $h = $_GET[h]; $s = $_GET[s]; $l = $_GET[l]; if ($_GET[hm]) { $h--; } elseif ($_GET[hmm]) { $h-= 10; } elseif ($_GET[sm]) { $s--; } elseif ($_GET[smm]) { $s-= 5; } elseif ($_GET[lm]) { $l--; } elseif ($_GET[lmm]) { $l-= 5; } elseif ($_GET[hp]) { $h++; } elseif ($_GET[hpp]) { $h+= 10; } elseif ($_GET[sp]) { $s++; } elseif ($_GET[spp]) { $s+= 5; } elseif ($_GET[lp]) { $l++; } elseif ($_GET[lpp]) { $l+= 5; } # range checking while ($h < 0) { $h += 360; } while ($h > 360) { $h -= 360; } if ($s < 0) { $s = 0; } elseif ($s > 100) { $s = 100; } if ($l < 0) { $l = 0; } elseif ($l > 100) { $s = 100; } # convert HSB -> RGB, reverse-engineered from PhotoShop if ($s == 0) { $rdec = $gdec = $bdec = $l * 2.55; } else { $h60 = $h/60 - intval($h/60); if ($h < 60) { $rdec = 2.55 * $l; $bdec = $rdec * (1 - $s/100); $gdec = (1 - $h60) * $bdec + $h60 * $rdec; } elseif ($h < 120) { $gdec = 2.55 * $l; $bdec = $gdec * (1 - $s/100); $rdec = (1 - $h60) * $gdec + $h60 * $bdec; } elseif ($h < 180) { $gdec = 2.55 * $l; $rdec = $gdec * (1 - $s/100); $bdec = (1 - $h60) * $rdec + $h60 * $gdec; } elseif ($h < 240) { $bdec = 2.55 * $l; $rdec = $bdec * (1 - $s/100); $gdec = (1 - $h60) * $bdec + $h60 * $rdec; } elseif ($h < 300) { $bdec = 2.55 * $l; $gdec = $bdec * (1 - $s/100); $rdec = (1 - $h60) * $gdec + $h60 * $bdec; } else { $rdec = 2.55 * $l; $gdec = $rdec * (1 - $s/100); $bdec = (1 - $h60) * $rdec + $h60 * $gdec; } $rdec = intval($rdec + 0.50001); $gdec = intval($gdec + 0.50001); $bdec = intval($bdec + 0.50001); } } # RGB -> HSB, as per Photoshop $max_rgb = max($rdec, $gdec, $bdec); $min_rgb = min($rdec, $gdec, $bdec); $range = $max_rgb - $min_rgb; $l = intval(0.5 + $max_rgb / 2.55); $s = $max_rgb == 0 ? 0 : intval(0.5 + 100 * (1 - $min_rgb/$max_rgb)); if ($range == 0) { $h = 0; } else { if ($rdec == $max_rgb) { $h = 0 + ($gdec - $bdec) / $range; } elseif ($gdec == $max_rgb) { $h = 2 + ($bdec - $rdec) / $range; } elseif ($bdec == $max_rgb) { $h = 4 + ($rdec - $gdec) / $range; } $h *= 60; } $h = intval($h + 0.5); if ($h < 0) { $h += 360; } elseif ($h > 360) { $h -= 360; } # export RGB values $r = sprintf("%02x", $rdec); $g = sprintf("%02x", $gdec); $b = sprintf("%02x", $bdec); $rtext = hexdec($r) > 128 ? '00' : 'ff'; $gtext = hexdec($g) > 128 ? '00' : 'ff'; $btext = hexdec($b) > 128 ? '00' : 'ff'; $rgb = "$r$g$b"; print << EOF; ?>

iroiro

By John J. Chew, III <jjchew@math.utoronto.ca>

RGB:
R:
G:
B:
H:
S:
B:
EOF; ?>