X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/54ea9d7c62215933a9b77f16b28717ea65a178ad..9c63114c622c6ef782de884c5788ef2bdd27c4db:/termcol.plp diff --git a/termcol.plp b/termcol.plp index 73bf0d2..7a51fbd 100644 --- a/termcol.plp +++ b/termcol.plp @@ -79,12 +79,24 @@ sub img_egapal { 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 '', MIME::Base64::encode_base64($imgdata); } || $@;