my %termgroup = (
default => [qw( ansi xkcd ansi88 )],
- more => [qw( ansi legacy ansi256 )],
+ more => [qw( ansi mirc legacy ansi256 )],
msx => [qw( msx1 msx2 arnejmp )],
ansi => [qw( cga xterm tango app html )],
legacy => [qw( c64 msx2 mac2 risc arnegame cpc )],
require MIME::Base64;
my @imgpal = map { Imager::Color->new(ref $_ ? @$_ : $_) } @{$palette};
- state $img = Imager->new(file => "data/$imgfile")
+ state $reindex = $imgfile =~ s/!$//;
+ state $img = Imager->new(file => "data/palimage/$imgfile")
or die Imager->errstr.$/;
- @{[ $img->getcolors ]} == @imgpal
- or die "incompatible palette size\n";
- $img->setcolors(colors => \@imgpal);
- $img->write(data => \my $imgdata, type => 'png');
+ do {
+ if ($reindex) {
+ $img->to_paletted({
+ make_colors => 'none',
+ colors => \@imgpal,
+ translate => 'closest',
+ });
+ }
+ else {
+ @{[ $img->getcolors ]} == @imgpal
+ or die "incompatible palette size\n";
+ $img->setcolors(colors => \@imgpal);
+ $img;
+ }
+ }->write(data => \my $imgdata, type => 'png');
return sprintf '<img src="data:image/png;base64,%s">',
MIME::Base64::encode_base64($imgdata);
} || $@;
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) {
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;
}
$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
- 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 .= 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 .= "<tr><td colspan=$tablespan>$imgdata";