| 1 | package Image::TextMode::Writer::IDF; | ||
| 2 | |||
| 3 | 1 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use charnames ':full'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | extends 'Image::TextMode::Writer'; | |
| 7 | |||
| 8 | 1 | my $header_template = 'A4 v v v v'; | |
| 9 | |||
| 10 | sub _write { | ||
| 11 | 1 | ▶ | my ( $self, $image, $fh, $options ) = @_; |
|
Subroutine
_write: called CC=5 SCAR=16.1
| |||
| 12 | |||
| 13 | 1 | my ( $max_x, $max_y ) = map { $_ - 1 } $image->dimensions; | |
| 14 | |||
| 15 | 1 | print $fh pack( $header_template, | |
| 16 | "\N{END OF TRANSMISSION}1.4", | ||
| 17 | 0, 0, $max_x, $max_y ); | ||
| 18 | |||
| 19 | # Don't bother with RLE compression for now | ||
| 20 | 1 | for my $y ( 0 .. $max_y ) { | |
| 21 | 1 | for my $x ( 0 .. $max_x ) { | |
| 22 | 80 | my $pixel = $image->getpixel( $x, $y ); | |
| 23 | 80 | print $fh pack( 'aC', $pixel->{ char }, $pixel->{ attr } ); | |
| 24 | } | ||
| 25 | } | ||
| 26 | |||
| 27 | 1 | for my $char ( @{ $image->font->chars } ) { | |
| 28 | 256 | print $fh pack( 'C*', @$char ); | |
| 29 | } | ||
| 30 | |||
| 31 | 1 | for my $color ( @{ $image->palette->colors } ) { | |
| 32 | 16 | print $fh pack( 'C*', map { $_ >> 2 } @$color ); | |
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | =head1 NAME | ||
| 37 | |||
| 38 | Image::TextMode::Writer::IDF - Writes IDF files | ||
| 39 | |||
| 40 | =head1 DESCRIPTION | ||
| 41 | |||
| 42 | Provides writing capabilities for the IDF format. It currently does not | ||
| 43 | support any RLE compression. | ||
| 44 | |||
| 45 | =head1 AUTHOR | ||
| 46 | |||
| 47 | Brian Cassidy E<lt>bricas@cpan.orgE<gt> | ||
| 48 | |||
| 49 | =head1 COPYRIGHT AND LICENSE | ||
| 50 | |||
| 51 | Copyright 2008-2014 by Brian Cassidy | ||
| 52 | |||
| 53 | This library is free software; you can redistribute it and/or modify | ||
| 54 | it under the same terms as Perl itself. | ||
| 55 | |||
| 56 | =cut | ||
| 57 | |||
| 58 | 1 | 1; | |