From f0cd021d19083c1a3b5e88523148579231c7e26b Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Mon, 2 Nov 2015 15:08:39 +0100 Subject: [PATCH] termcol: index greyscale ramp, include in image palette --- termcol.inc.pl | 4 ++-- termcol.plp | 21 +++++++-------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/termcol.inc.pl b/termcol.inc.pl index 0a71140..e14abcf 100644 --- a/termcol.inc.pl +++ b/termcol.inc.pl @@ -194,7 +194,7 @@ my @msxorder = ( 0,6,2,10,4,13,7,14 , 1,8,3,11,5,9,12,15 ); $_[2] + 4 * ($_[1] + 4 * $_[0]) + 16, map { (0, 139, 205, 255)[$_] } @_ }, - [ map { ($_ + 2 + ($_>0)) * 255/11 } 0 .. 7 ], + [ map { [80 + $_, (($_ + 2 + ($_>0)) * 255/11) x 3] } 0 .. 7 ], ], }, ansi256 => { @@ -206,7 +206,7 @@ my @msxorder = ( 0,6,2,10,4,13,7,14 , 1,8,3,11,5,9,12,15 ); $_[2] + 6 * ($_[1] + 6 * $_[0]) + 16, map { $_ && $_*40 + 55 } @_ }, - [ map { $_ * 10 + 8 } 0 .. 23 ], + [ map { [232 + $_, ($_ * 10 + 8) x 3] } 0 .. 23 ], ], }, 512 => { diff --git a/termcol.plp b/termcol.plp index 0068acc..267d5a7 100644 --- a/termcol.plp +++ b/termcol.plp @@ -151,9 +151,8 @@ 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) { @@ -165,9 +164,8 @@ sub coltable_hsv { my $s = abs(min(@rgb) - max(@rgb)); if (!$s) { - if ($greyramp) { - my ($index, $l) = $rgbval->(@rgb); - $greymap{$index} = $l; + if (@greymap) { + push @greymap, [ $rgbval->(@rgb) ]; next; } @@ -192,23 +190,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"; -- 2.30.0