TextMode/Writer/Tundra.pm

filter: Statementstmt 100% 19 / 19 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 24 / 24 CC 4 SCAR 11.0
CC
4
Cov
100%
_write
4.0
BEGIN
1.0
_assemble_pal
1.0
CRAP 3.0
« TextMode/Reader.pm ↑ Summary TextMode/Writer.pm »
1 package Image::TextMode::Writer::Tundra;
2  
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 extends 'Image::TextMode::Writer';
6  
7 sub _write {
8 1 ▶ my ( $self, $image, $fh, $options ) = @_;
Subroutine _write: called CC=4 SCAR=13.9
9  
10 1 print $fh pack( 'C', 24 );
11 1 print $fh pack( 'A8', 'TUNDRA24' );
12  
13 1 my $pal = $image->palette;
14  
15 1 for my $y ( 0 .. $image->height - 1 ) {
16 1 for my $x ( 0 .. 79 ) {
17 80 my $pixel = $image->getpixel( $x, $y );
18  
19 80 ▶ if ( !defined $pixel ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pixel) 76 4 80
20 76 $pixel = { char => ' ', fg => 0, bg => 0 };
21 }
22  
23 80 my $fg = _assemble_pal( $pal->colors->[ $pixel->{ fg } ] );
24 80 my $bg = _assemble_pal( $pal->colors->[ $pixel->{ bg } ] );
25 80 print $fh chr( 6 ), $pixel->{ char }, pack( 'N*', $fg, $bg );
26 }
27 }
28 }
29  
30 sub _assemble_pal {
31 160 ▶ my ( $color ) = shift;
Subroutine _assemble_pal: called CC=1 SCAR=0.0
32 160 return ( $color->[ 0 ] << 16 ) | ( $color->[ 1 ] << 8 )
33 | ( $color->[ 2 ] );
34 }
35  
36 =head1 NAME
37  
38 Image::TextMode::Writer::Tundra - Writes Tundra files
39  
40 =head1 DESCRIPTION
41  
42 Provides writing capabilities for the Tundra 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;
« TextMode/Reader.pm ↑ Summary TextMode/Writer.pm »