- require Digest::CRC;
-
- local $/;
- open my $img, '<:bytes', "data/$imgfile" or die "$!\n";
- my $imgdata = readline $img;
-
- my $offset = 0x29 - 4;
- my $len = 16 * 3;
- my $chunklen = $len + 4;
- substr($imgdata, $offset+4, $len) = pack 'H*', join '', @{$palette};
- my ($p, $crc) = unpack "x${offset}a${chunklen}N", $imgdata;
- substr($imgdata, $offset+4+$len, 4) = pack 'N', Digest::CRC::crc32($p);