my
$header_template
=
'A4 C v v C C'
;
sub
_write {
my
(
$self
,
$image
,
$fh
,
$options
) =
@_
;
my
(
$width
,
$height
) =
$image
->dimensions;
my
$fontsize
=
$image
->font->height;
my
$flags
= 11;
$flags
|= 16
if
scalar
@{
$image
->font->chars } == 512;
print
$fh
pack
(
$header_template
,
'XBIN'
, 26,
$width
,
$height
,
$fontsize
,
$flags
);
for
my
$color
( @{
$image
->palette->colors } ) {
print
$fh
pack
(
'C*'
,
map
{
$_
>> 2 }
@$color
);
}
for
my
$char
( @{
$image
->font->chars } ) {
print
$fh
pack
(
'C*'
,
@$char
);
}
for
my
$y
( 0 ..
$height
- 1 ) {
for
my
$x
( 0 ..
$width
- 1 ) {
my
$pixel
=
$image
->getpixel(
$x
,
$y
);
print
$fh
pack
(
'aC'
,
$pixel
->{ char },
$pixel
->{ attr } );
}
}
}
1;