termcol: distinct image palette in cga order
[sheet.git] / termcol.plp
index 6cc6fea2b5c403cde6a67c05ddd09c876e0ce1ec..b3bb7b5f709fd819ab591696274328574aa1c10c 100644 (file)
@@ -127,13 +127,11 @@ for my $term (@termlist) {
                print "</table>\n\n";
        }
 
                print "</table>\n\n";
        }
 
-       if (my $colours = $info->{list}) {
-               if (my $reorder = $info->{ansiorder} and $get{v}) {
-                       $colours = [ map { $colours->[$_] =~ s/:|$/:$_/r } @{$reorder} ];
-               }
+       if (my $palette = $info->{list}) {
+               my $colours = colorder($palette, $get{v} && $info->{ansiorder});
 
                my $rows = 8;
 
                my $rows = 8;
-               my $columns = ceil(@{$colours} / $rows);
+               my $columns = ceil(@{$palette} / $rows);
 
                print '<table class=color>', "\n";
                printf "<caption>%s</caption>\n", $caption;
 
                print '<table class=color>', "\n";
                printf "<caption>%s</caption>\n", $caption;
@@ -149,11 +147,21 @@ for my $term (@termlist) {
                        }
                }
 
                        }
                }
 
-               print "<tr><td colspan=$columns>", img_egapal(\@{$colours}, @{$_}) for @draw;
+               for (@draw) {
+                       my $imgpal = colorder($palette, $info->{ansiorder});
+                       print "<tr><td colspan=$columns>", img_egapal($imgpal, @{$_});
+               }
                print "</table>\n\n";
        }
 }
 
                print "</table>\n\n";
        }
 }
 
+sub colorder {
+       my ($palette, $reorder) = @_;
+       return [ map { $palette->[$_] =~ s/:|$/:$_/r } @{$reorder} ];
+               if $reorder;
+       return $palette;
+}
+
 sub coltable_hsv {
        my ($dim, $rgbval, $greyramp) = @_;
 
 sub coltable_hsv {
        my ($dim, $rgbval, $greyramp) = @_;