termcol: index greyscale ramp, include in image palette
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 2 Nov 2015 14:08:39 +0000 (15:08 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 5 Jan 2016 00:05:07 +0000 (01:05 +0100)
termcol.inc.pl
termcol.plp

index 0a7114008293c5054938fade25e823103c83f8f2..e14abcf2c44afa5f1320622ee09d4327e10ff665 100644 (file)
@@ -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)[$_] } @_
                        },
                                $_[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 => {
                ],
        },
        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 } @_
                        },
                                $_[2] + 6 * ($_[1] + 6 * $_[0]) + 16,
                                map { $_ && $_*40 + 55 } @_
                        },
-                       [ map { $_ * 10 + 8 } 0 .. 23 ],
+                       [ map { [232 + $_, ($_ * 10 + 8) x 3] } 0 .. 23 ],
                ],
        },
        512 => {
                ],
        },
        512 => {
index 0068accf7edb69860d668058c3354980733a2819..267d5a74a7821f4bfd5a54aba6c420a0c2b55589 100644 (file)
@@ -151,9 +151,8 @@ sub coltable_hsv {
        my $smax = $dim - 1;
        $rgbval ||= sub { join('', @_), map { int $_ * 255 / $vmax } @_ };
 
        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 @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 $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) {
                                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;
                                        }
 
                                                next;
                                        }
 
@@ -192,23 +190,18 @@ sub coltable_hsv {
                $out .= colcell(@$_) for map { $_->[$h] } map { @{$_} } @colmap;
        }
 
                $out .= colcell(@$_) for map { $_->[$h] } map { @{$_} } @colmap;
        }
 
-       if ($greyramp) {
-               $offset += $dim ** 3;
-               $greymap{$offset++} = $_ for @{$greyramp};
-       }
-
-       if (%greymap) {
+       if (@greymap) {
                $out .= '<tbody>';
                my $col = 0;
                my $colbreak = scalar map { @$_ } @colmap;  # same width as hue rows
                $out .= '<tbody>';
                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 .= '<tr>' unless $col++ % $colbreak;
                        $out .= '<tr>' unless $col++ % $colbreak;
-                       $out .= colcell($num, ($greymap{$num}));
+                       $out .= colcell(@{$cell});
                }
        }
 
        if ($imgfile) {
                }
        }
 
        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 .= "<tr><td colspan=$tablespan>$imgdata";
                my $imgdata = img_egapal(\@palette);
                my $tablespan = scalar map { @$_ } @colmap;
                $out .= "<tr><td colspan=$tablespan>$imgdata";