File Coverage

blib/lib/Image/TextMode/Writer/XBin.pm
Criterion Covered Total %
statement 21 21 100.0
branch 1 2 50.0
condition n/a
subroutine 2 2 100.0
pod n/a
total 24 25 96.0


line stmt bran cond sub pod time code
1             package Image::TextMode::Writer::XBin;
2              
3 1     1   507 use Moo;
  1         2  
  1         8  
4              
5             extends 'Image::TextMode::Writer';
6              
7             my $header_template = 'A4 C v v C C';
8              
9             sub _write {
10 1     1   1 my ( $self, $image, $fh, $options ) = @_;
11 1         9 my ( $width, $height ) = $image->dimensions;
12              
13 1         51 my $fontsize = $image->font->height;
14 1         558 my $flags
15             = 11; # has palette and font, is non-blink, everything else is false
16 1         20 $flags |= 16
17 1 50       1 if scalar @{ $image->font->chars } == 512; # check for large font
18 1         541 print $fh pack( $header_template,
19             'XBIN', 26, $width, $height, $fontsize, $flags );
20              
21 1         2 for my $color ( @{ $image->palette->colors } ) {
  1         26  
22 16         513 print $fh pack( 'C*', map { $_ >> 2 } @$color );
  48         54  
23             }
24              
25 1         2 for my $char ( @{ $image->font->chars } ) {
  1         19  
26 256         344 print $fh pack( 'C*', @$char );
27             }
28              
29             # No compression for now
30 1         4 for my $y ( 0 .. $height - 1 ) {
31 1         2 for my $x ( 0 .. $width - 1 ) {
32 80         143 my $pixel = $image->getpixel( $x, $y );
33 80         434 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-2014 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;