| 1 | package Acme::PrettyCure::Image::PNG; | ||||||||||
| 2 | 1 | ▶ | use v5.44; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | # A PNG of an image, made here with Compress::Zlib rather than by Imager, for the iTerm2 protocol: the | ||||||||||
| 5 | # same bytes on every system (Imager's PNG support depends on the libpng it was built with), and no | ||||||||||
| 6 | # need for that support at all. | ||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Compress::Zlib qw(compress crc32); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | # PNG of 8-bit RGB rows. $rows is an array of rows, each a string of R G B bytes. | ||||||||||
| 11 | 1 | ▶ | sub encode ($class, $width, $height, $rows) { | ||||||||
|
Subroutine
encode: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 12 | 1 | ▶ | die "PNG: $height rows expected\n" unless @$rows == $height; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | |||||||||||
| 14 | # Each row starts with its filter type: 0, none. | ||||||||||
| 15 | 1 | my $raw = join '', map { "\0" . $_ } @$rows; | |||||||||
| 16 | return | ||||||||||
| 17 | 1 | "\x89PNG\r\n\x1a\n" | |||||||||
| 18 | . chunk(IHDR => pack('NNCCCCC', $width, $height, 8, 2, 0, 0, 0)) | ||||||||||
| 19 | . chunk(IDAT => compress($raw, 9)) | ||||||||||
| 20 | . chunk(IEND => ''); | ||||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | 3 | ▶ | sub chunk ($type, $data) { | ||||||||
|
Subroutine
chunk: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 24 | 3 | return pack('N', length $data) . $type . $data . pack('N', crc32($type . $data)); | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 1 | 1; | |||||||||