| Image-TextMode documentation | Contained in the Image-TextMode distribution. |
Image::TextMode::Writer::IDF - Writes IDF files
Provides writing capabilities for the IDF format. It currently does not support any RLE compression.
Brian Cassidy <bricas@cpan.org>
Copyright 2008-2011 by Brian Cassidy
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Image-TextMode documentation | Contained in the Image-TextMode distribution. |
package Image::TextMode::Writer::IDF; use Moose; use charnames ':full'; extends 'Image::TextMode::Writer'; my $header_template = 'A4 v v v v'; sub _write { my ( $self, $image, $fh, $options ) = @_; my ( $max_x, $max_y ) = map { $_ - 1 } $image->dimensions; print $fh pack( $header_template, "\N{END OF TRANSMISSION}1.4", 0, 0, $max_x, $max_y ); # Don't bother with RLE compression for now for my $y ( 0 .. $max_y ) { for my $x ( 0 .. $max_x ) { my $pixel = $image->getpixel( $x, $y ); print $fh pack( 'aC', $pixel->{ char }, $pixel->{ attr } ); } } for my $char ( @{ $image->font->chars } ) { print $fh pack( 'C*', @$char ); } for my $color ( @{ $image->palette->colors } ) { print $fh pack( 'C*', map { $_ >> 2 } @$color ); } } no Moose; __PACKAGE__->meta->make_immutable;
1;