TextMode/Writer/XBin.pm

filter: Statementstmt 100% 24 / 24 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 96.4% 27 / 28 CC 6 SCAR 16.7
CC
6
Cov
96%
_write
6.0
BEGIN
1.0
CRAP 5.3
« TextMode/Writer/ANSI.pm ↑ Summary TextMode/Reader/IDF.pm »
1 package Image::TextMode::Writer::XBin;
2  
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 extends 'Image::TextMode::Writer';
6  
7 1 my $header_template = 'A4 C v v C C';
8  
9 sub _write {
10 1 ▶ my ( $self, $image, $fh, $options ) = @_;
Subroutine _write: called CC=6 SCAR=17.9
11 1 my ( $width, $height ) = $image->dimensions;
12  
13 1 my $fontsize = $image->font->height;
14 1 my $flags
15 = 11; # has palette and font, is non-blink, everything else is false
16 $flags |= 16
17 1 ▶ if scalar @{ $image->font->chars } == 512; # check for large font
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$image->font->chars;} == 512 0 1 1
18 1 print $fh pack( $header_template,
19 'XBIN', 26, $width, $height, $fontsize, $flags );
20  
21 1 for my $color ( @{ $image->palette->colors } ) {
22 16 print $fh pack( 'C*', map { $_ >> 2 } @$color );
23 }
24  
25 1 for my $char ( @{ $image->font->chars } ) {
26 256 print $fh pack( 'C*', @$char );
27 }
28  
29 # No compression for now
30 1 for my $y ( 0 .. $height - 1 ) {
31 1 for my $x ( 0 .. $width - 1 ) {
32 80 my $pixel = $image->getpixel( $x, $y );
33 80 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 E<lt>bricas@cpan.orgE<gt>
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 1;
« TextMode/Writer/ANSI.pm ↑ Summary TextMode/Reader/IDF.pm »