X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/721416af567c48d7963d771e2f282c390a2763ca..ce5eed3c2adf1c85ddd67d435e0dfac777723dc3:/termcol.plp diff --git a/termcol.plp b/termcol.plp index 0068acc..748625c 100644 --- a/termcol.plp +++ b/termcol.plp @@ -45,7 +45,7 @@ print
<: use 5.010; -use Shiar_Sheet::Colour '1.03'; +use Shiar_Sheet::Colour '1.04'; use List::Util qw( min max ); my $palettes = do 'termcol.inc.pl'; @@ -151,31 +151,28 @@ sub coltable_hsv { my $smax = $dim - 1; $rgbval ||= sub { join('', @_), map { int $_ * 255 / $vmax } @_ }; - my %greymap; # name => value + my @greymap = @{$greyramp || []}; # [name, r, g=l, b] my @colmap; # saturation => value => hue => [name, r,g,b] - my $offset = 16 * ($dim > 3); for my $r (0 .. $dim - 1) { for my $g (0 .. $dim - 1) { for my $b (0 .. $dim - 1) { my @rgb = ($r, $g, $b); - my $h = Shiar_Sheet::Colour->new(@rgb)->hue * $hmax; - my $v = max(@rgb); - my $s = abs(min(@rgb) - max(@rgb)); + my ($h, $s, $v) = Shiar_Sheet::Colour->new(@rgb)->hsv; if (!$s) { - if ($greyramp) { - my ($index, $l) = $rgbval->(@rgb); - $greymap{$index} = $l; + if (@greymap) { + push @greymap, [ $rgbval->(@rgb) ]; next; } - $h = $hmax; # greyscale hue + $h = 1; # greyscale hue $s = 1; # lowest saturation for other hues $v = $s = $vmax if !$v; # black at full saturation } + $h *= $hmax; $v = $vmax - $v; $s = $smax - $s - $v; @@ -192,23 +189,18 @@ sub coltable_hsv { $out .= colcell(@$_) for map { $_->[$h] } map { @{$_} } @colmap; } - if ($greyramp) { - $offset += $dim ** 3; - $greymap{$offset++} = $_ for @{$greyramp}; - } - - if (%greymap) { + if (@greymap) { $out .= ''; my $col = 0; my $colbreak = scalar map { @$_ } @colmap; # same width as hue rows - for my $num (sort { $greymap{$a} <=> $greymap{$b} } keys %greymap) { + for my $cell (sort { $a->[1] <=> $b->[1] || $a->[0] <=> $b->[0] } @greymap) { $out .= '' unless $col++ % $colbreak; - $out .= colcell($num, ($greymap{$num})); + $out .= colcell(@{$cell}); } } if ($imgfile) { - my @palette = map { [ @{$_}[1 .. 3] ] } map {@$_} map {@$_} @colmap; + my @palette = map { [ @{$_}[1 .. 3] ] } @greymap, map {@$_} map {@$_} @colmap; my $imgdata = img_egapal(\@palette); my $tablespan = scalar map { @$_ } @colmap; $out .= "$imgdata";