TextMode/Writer/ADF.pm

filter: Statementstmt 100% 32 / 32 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 36 / 36 CC 3 SCAR 5.1
CC
3
Cov
100%
_write
2.0
_pack_pal
2.0
BEGIN
1.0
CRAP 1.7
« TextMode/Writer/PCBoard.pm ↑ Summary TextMode/Writer/Bin.pm »
1 package Image::TextMode::Writer::ADF;
2  
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 extends 'Image::TextMode::Writer';
6  
7 # generates a 64 color palette
8 ## no critic (BuiltinFunctions::ProhibitComplexMappings)
9 my $default_pal = [
10 map {
11 1 my @d = split( //s, sprintf( '%06b', $_ ) );
12 {
13 64 [ 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 ▶ my ( $self, $image, $fh, $options ) = @_;
Subroutine _write: called CC=2 SCAR=6.9
24  
25 1 print $fh pack( 'C', $image->header->{ version } );
26  
27 1 print $fh _pack_pal( $image->palette );
28 1 print $fh _pack_font( $image->font );
29  
30 1 for my $row ( @{ $image->pixeldata } ) {
31 print $fh
32 join( '',
33 1 map { pack( 'aC', @{ $_ }{ qw( char attr ) } ) } @$row );
34 }
35 }
36  
37 sub _pack_font {
38 1 ▶ my $font = shift;
Subroutine _pack_font: called CC=1 SCAR=0.0
39 1 return pack( 'C*', map { @$_ } @{ $font->chars } );
40 }
41  
42 sub _pack_pal {
43 1 ▶ my $pal = shift;
Subroutine _pack_pal: called CC=2 SCAR=6.9
44  
45 1 my @full_pal = @$default_pal;
46 1 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 for ( 0 .. 15 ) {
50 16 my @p = map { $_ >> 2 } @{ $pal->colors->[ $_ ] };
51 16 $full_pal[ $pal_map[ $_ ] ] = \@p;
52 }
53  
54 1 return pack( 'C*', map { @$_ } @full_pal );
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 E<lt>bricas@cpan.orgE<gt>
68  
69 =head1 COPYRIGHT AND LICENSE
70  
71 Copyright 2008-2015 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 1;
« TextMode/Writer/PCBoard.pm ↑ Summary TextMode/Writer/Bin.pm »