| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Image::TextMode::Writer::XBin; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 465 | use Moo; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 9 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | extends 'Image::TextMode::Writer'; | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | my $header_template = 'A4 C v v C C'; | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | sub _write { | 
| 10 | 1 |  |  | 1 |  | 2 | my ( $self, $image, $fh, $options ) = @_; | 
| 11 | 1 |  |  |  |  | 10 | my ( $width, $height ) = $image->dimensions; | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 1 |  |  |  |  | 74 | my $fontsize = $image->font->height; | 
| 14 | 1 |  |  |  |  | 695 | my $flags | 
| 15 |  |  |  |  |  |  | = 11;   # has palette and font, is non-blink, everything else is false | 
| 16 | 1 |  |  |  |  | 16 | $flags |= 16 | 
| 17 | 1 | 50 |  |  |  | 3 | if scalar @{ $image->font->chars } == 512;    # check for large font | 
| 18 | 1 |  |  |  |  | 572 | print $fh pack( $header_template, | 
| 19 |  |  |  |  |  |  | 'XBIN', 26, $width, $height, $fontsize, $flags ); | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 1 |  |  |  |  | 1 | for my $color ( @{ $image->palette->colors } ) { | 
|  | 1 |  |  |  |  | 27 |  | 
| 22 | 16 |  |  |  |  | 516 | print $fh pack( 'C*', map { $_ >> 2 } @$color ); | 
|  | 48 |  |  |  |  | 82 |  | 
| 23 |  |  |  |  |  |  | } | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 1 |  |  |  |  | 5 | for my $char ( @{ $image->font->chars } ) { | 
|  | 1 |  |  |  |  | 35 |  | 
| 26 | 256 |  |  |  |  | 516 | print $fh pack( 'C*', @$char ); | 
| 27 |  |  |  |  |  |  | } | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | # No compression for now | 
| 30 | 1 |  |  |  |  | 7 | for my $y ( 0 .. $height - 1 ) { | 
| 31 | 1 |  |  |  |  | 3 | for my $x ( 0 .. $width - 1 ) { | 
| 32 | 80 |  |  |  |  | 183 | my $pixel = $image->getpixel( $x, $y ); | 
| 33 | 80 |  |  |  |  | 555 | print $fh pack( 'aC', $pixel->{ char }, $pixel->{ attr } ); | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  | } | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | =head1 NAME | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | Image::TextMode::Writer::XBin - Writes XBin files | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | Provides writing capabilities for the XBin format. It currently only | 
| 45 |  |  |  |  |  |  | supports uncompressed XBin files. | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | =head1 AUTHOR | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | Brian Cassidy Ebricas@cpan.orgE | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | Copyright 2008-2015 by Brian Cassidy | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | This library is free software; you can redistribute it and/or modify | 
| 56 |  |  |  |  |  |  | it under the same terms as Perl itself. | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | =cut | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | 1; |