From a4fdefae72afac5a4ad02eabcc23fe762903ad89 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sun, 1 Nov 2015 03:12:48 +0100 Subject: [PATCH] termcol: use rgb index instead of value for hsv calculation Final colour value may not map well to table position; prefer original coordinates to prevent outrageous transforms from breaking grouping at the cost of adjusting for cumulative exceptions. --- termcol.plp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/termcol.plp b/termcol.plp index a930698..fd2bc9b 100644 --- a/termcol.plp +++ b/termcol.plp @@ -243,7 +243,7 @@ print coltable_hsv(4, sub coltable_hsv { my ($dim, $rgbval, $greyramp) = @_; - my $hmax = ($dim + $dim - 1) * 2 + ($dim - 2) * 2 + 3; + my $hmax = 2 * $dim * 3; # each face of the rgb cube my $vmax = $dim - 1; my $smax = $dim - 1; @@ -255,21 +255,21 @@ sub coltable_hsv { for my $g (0 .. $dim - 1) { for my $b (0 .. $dim - 1) { my $index = $r*$dim*$dim + $g*$dim + $b + $offset; - my @rgb = map { $rgbval->($_) } $r, $g, $b; + my @rgb = ($r, $g, $b); my $h = Shiar_Sheet::Colour->new(@rgb)->hue * $hmax; - my $v = int(max(@rgb) / 255 * $vmax); - my $s = abs(min(@rgb) - max(@rgb)) / 255 * $smax; + my $v = max(@rgb); + my $s = abs(min(@rgb) - max(@rgb)); if (!$s) { - $greymap{$index} = $rgb[0]; + $greymap{$index} = $rgbval->($r); next; } $v = $vmax - $v; $s = $smax - $s - $v; - $colmap[$s][$v][$h] = [$index, @rgb]; + $colmap[$s][$v][$h] = [$index, map { $rgbval->($_) } @rgb]; } } } -- 2.30.0