#!/usr/local/bin/perl use CGI ':standard'; print header; print "
\n", "\n"; sub scale { my ($v, $max) = @_; my $r = $v * 255.0 / ($max - 1); my $i = sprintf("%d", $r); return $i; } sub hexcolor { my ($r, $g, $b) = @_; my $s = sprintf("%02x%02x%02x", $r, $g, $b); return $s; } sub min { my $x = undef; foreach $y (@_){ if(!defined($x) || $y < $x){ $x = $y; } } return $x; } sub max { my $x = undef; foreach $y (@_){ if(!defined($x) || $y > $x){ $x = $y; } } return $x; } # # adapted from C source code included in # Alvy Ray Smith and Eric Ray Lyons. # HWB - A more intuitive hue-based color model. # Journal of Graphics Tools, 1(1):3-17, 1996 # sub rgb_to_hwb { my ($R, $G, $B) = @_; my $w = min($R, $G, $B); my $v = max($R, $G, $B); my $b = 1.0-$v; if($v == $w) { return (-1, $w, $b); } my $f = ($R == $w) ? $G - $B : (($G == $w) ? $B - $R : $R - $G); my $i = ($R == $w) ? 3 : (($G == $w) ? 5 : 1); return ($i - $f / ($v - $w), $w, $b); } sub param_default { my ($p, $d) = @_; my $v = param($p); if(defined $v) { return $v; } else { return $d; } } if(param('resolution_r')){ my $resolution_r = param('resolution_r'); my $resolution_g = param('resolution_g'); my $resolution_b = param('resolution_b'); if($resolution_r < 2){ $resolution_r = 2; } if($resolution_g < 2){ $resolution_g = 2; } if($resolution_b < 2){ $resolution_b = 2; } my $max_brightness = param_default('max_brightness', 1.0); my $min_brightness = param_default('min_brightness', 0.0); my $max_saturation = param_default('max_saturation', 1.0); my $min_saturation = param_default('min_saturation', 0.0); my $max_hue = param_default('max_hue' , 6.0); my $min_hue = param_default('min_hue' , -1.0); my $max_white= param_default('max_white', 1.0); my $min_white= param_default('min_white', 0.0); my $max_black= param_default('max_black', 1.0); my $min_black= param_default('min_black', 0.0); my $physiological_correction = param_default('physiological_correction', 0); my $weight_r = 0.8; my $weight_g = 1; my $weight_b = 0.6; my $display_brightness = param('display_brightness'); my $display_saturation = param('display_saturation'); my $display_hue = param('display_hue'); my $display_white = param('display_white'); my $display_black = param('display_black'); my $compare_case = param('compare_case'); if(!$physiological_correction){ $weight_r = $weight_g = $weight_b = 1.0; } my $weight_sum = $weight_r + $weight_g + $weight_b; my $numc = $resolution_r * $resolution_g * $resolution_b; print ""; } } else { print ' | ', $hexcolor, ' | '; if($compare_case) { print '', $hexcolor2, ' | '; } } if($display_brightness){ print '', sprintf("%.3f",$brightness), " | "; } if($display_saturation){ print '', sprintf("%.1f",$saturation), " | "; } if($display_hue){ print '', sprintf("%.1f",$hue), " | "; } if($display_white){ print '', sprintf("%.1f",$white), " | "; } if($display_black){ print '', sprintf("%.1f",$black), " | "; } } print "
Resolution | ||
Resolution Red: | ",textfield(-name => 'resolution_r', -default => 6, -size=>2, -maxlength=>2)," | |
Resolution Green: | ",textfield(-name => 'resolution_g', -default => 6, -size=>2, -maxlength=>2)," | |
Resolution Blue: | ",textfield(-name => 'resolution_b', -default => 6, -size=>2, -maxlength=>2)," | |
Filters | Display Extra Information | |
Brightness: | ", textfield(-name => 'min_brightness', -default => '0.0', -size=>5, -maxlength=>10), " ... ", textfield(-name => 'max_brightness', -default => '1.0', -size=>5, -maxlength=>10)," | ", checkbox(-name => 'display_brightness', -checked => 0, -label => "Display Brightness ", ), checkbox(-name => 'physiological_correction', -checked => 0, -label => "Physiological Correction ", ), " |
Saturation: | ", textfield(-name => 'min_saturation', -default => '0.0', -size=>5, -maxlength=>10), " ... ", textfield(-name => 'max_saturation', -default => '1.0', -size=>5, -maxlength=>10)," | ", checkbox(-name => 'display_saturation', -checked => 0, -label => "Display", ), " |
Hue | ", textfield(-name => 'min_hue', -default => '-1.0', -size=>5, -maxlength=>10), " ... ", textfield(-name => 'max_hue', -default => '6.0', -size=>5, -maxlength=>10)," | ", checkbox(-name => 'display_hue', -checked => 0, -label => "Display", ), " (1=yellow, 2=green, 3=cyan, 4=blue, 5=magenta, 6=0=red. gray= -1) |
Whiteness | ", textfield(-name => 'min_white', -default => '0.0', -size=>5, -maxlength=>10), " ... ", textfield(-name => 'max_white', -default => '1.0', -size=>5, -maxlength=>10)," | ", checkbox(-name => 'display_white', -checked => 0, -label => "Display", ), " |
Blackness | ", textfield(-name => 'min_black', -default => '0.0', -size=>5, -maxlength=>10), " ... ", textfield(-name => 'max_black', -default => '1.0', -size=>5, -maxlength=>10)," | ", checkbox(-name => 'display_black', -checked => 0, -label => "Display", ), " |
Bugs | ", checkbox(-name => 'compare_case', -checked => 0, -label => "Compare Upper/Lowercase (presumably, some browsers make a difference)", ), " |