File Coverage

blib/lib/Image/TextMode/Writer/ADF.pm
Criterion Covered Total %
statement 26 26 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 30 30 100.0


line stmt bran cond sub pod time code
1             package Image::TextMode::Writer::ADF;
2              
3 1     1   426 use Moo;
  1         1  
  1         7  
4              
5             extends 'Image::TextMode::Writer';
6              
7             # generates a 64 color palette
8             ## no critic (BuiltinFunctions::ProhibitComplexMappings)
9             my $default_pal = [
10             map {
11             my @d = split( //s, sprintf( '%06b', $_ ) );
12             {
13             [ oct( "0b$d[ 3 ]$d[ 0 ]" ) * 63,
14             oct( "0b$d[ 4 ]$d[ 1 ]" ) * 63,
15             oct( "0b$d[ 5 ]$d[ 2 ]" ) * 63,
16             ]
17             }
18             } 0 .. 63
19             ];
20             ## use critic
21              
22             sub _write {
23 1     1   2 my ( $self, $image, $fh, $options ) = @_;
24              
25 1         23 print $fh pack( 'C', $image->header->{ version } );
26              
27 1         50 print $fh _pack_pal( $image->palette );
28 1         34 print $fh _pack_font( $image->font );
29              
30 1         62 for my $row ( @{ $image->pixeldata } ) {
  1         34  
31 80         132 print $fh
32             join( '',
33 1         11 map { pack( 'aC', @{ $_ }{ qw( char attr ) } ) } @$row );
  80         65  
34             }
35             }
36              
37             sub _pack_font {
38 1     1   8 my $font = shift;
39 1         2 return pack( 'C*', map { @$_ } @{ $font->chars } );
  256         1083  
  1         5  
40             }
41              
42             sub _pack_pal {
43 1     1   7 my $pal = shift;
44              
45 1         17 my @full_pal = @$default_pal;
46 1         3 my @pal_map = qw( 0 1 2 3 4 5 20 7 56 57 58 59 60 61 62 63 );
47              
48             # insert our colors into the appropriate slots in the 64-color array
49 1         3 for ( 0 .. 15 ) {
50 16         5 my @p = map { $_ >> 2 } @{ $pal->colors->[ $_ ] };
  48         640  
  16         217  
51 16         31 $full_pal[ $pal_map[ $_ ] ] = \@p;
52             }
53              
54 1         3 return pack( 'C*', map { @$_ } @full_pal );
  64         67  
55             }
56              
57             =head1 NAME
58              
59             Image::TextMode::Writer::ADF - Writes ADF files
60              
61             =head1 DESCRIPTION
62              
63             Provides writing capabilities for the ADF format.
64              
65             =head1 AUTHOR
66              
67             Brian Cassidy Ebricas@cpan.orgE
68              
69             =head1 COPYRIGHT AND LICENSE
70              
71             Copyright 2008-2014 by Brian Cassidy
72              
73             This library is free software; you can redistribute it and/or modify
74             it under the same terms as Perl itself.
75              
76             =cut
77              
78             1;