File Coverage

blib/lib/Image/TextMode/Writer/Tundra.pm
Criterion Covered Total %
statement 17 17 100.0
branch 2 2 100.0
condition n/a
subroutine 3 3 100.0
pod n/a
total 22 22 100.0


line stmt bran cond sub pod time code
1             package Image::TextMode::Writer::Tundra;
2              
3 1     1   381 use Moo;
  1         1  
  1         6  
4              
5             extends 'Image::TextMode::Writer';
6              
7             sub _write {
8 1     1   2 my ( $self, $image, $fh, $options ) = @_;
9              
10 1         4 print $fh pack( 'C', 24 );
11 1         1 print $fh pack( 'A8', 'TUNDRA24' );
12              
13 1         34 my $pal = $image->palette;
14              
15 1         39 for my $y ( 0 .. $image->height - 1 ) {
16 1         12 for my $x ( 0 .. 79 ) {
17 80         260 my $pixel = $image->getpixel( $x, $y );
18              
19 80 100       698 if ( !defined $pixel ) {
20 76         245 $pixel = { char => ' ', fg => 0, bg => 0 };
21             }
22              
23 80         2062 my $fg = _assemble_pal( $pal->colors->[ $pixel->{ fg } ] );
24 80         1972 my $bg = _assemble_pal( $pal->colors->[ $pixel->{ bg } ] );
25 80         528 print $fh chr( 6 ), $pixel->{ char }, pack( 'N*', $fg, $bg );
26             }
27             }
28             }
29              
30             sub _assemble_pal {
31 160     160   1084 my ( $color ) = shift;
32 160         382 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 Ebricas@cpan.orgE
48              
49             =head1 COPYRIGHT AND LICENSE
50              
51             Copyright 2008-2015 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;