TextMode/Reader/ADF.pm

filter: Statementstmt 100% 42 / 42 Branchbran 83.3% 5 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 91.2% 52 / 57 CC 7 SCAR 12.3
CC
7
Cov
94%
_read
5.0
_parse_palette
2.0
_parse_font
2.0
CRAP 3.4
« TextMode/Writer/IDF.pm ↑ Summary TextMode/Pixel.pm »
1 package Image::TextMode::Reader::ADF;
2  
3 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 extends 'Image::TextMode::Reader';
6  
7 2 my @color_idx = ( 0, 1, 2, 3, 4, 5, 20, 7, 56, 57, 58, 59, 60, 61, 62, 63 );
8  
9 sub _read {
10 3 ▶ my ( $self, $image, $fh, $options ) = @_;
Subroutine _read: called CC=5 SCAR=16.1
11  
12 3 my $version;
13 3 read( $fh, $version, 1 );
14 3 $version = unpack( 'C', $version );
15 3 $image->header( { version => $version } );
16  
17 3 my $paldata;
18 3 read( $fh, $paldata, 192 );
19 3 _parse_palette( $image, $paldata );
20  
21 3 my $fontdata;
22 3 read( $fh, $fontdata, 4096 );
23 3 _parse_font( $image, $fontdata );
24  
25 3 my ( $x, $y ) = ( 0, 0 );
26 3 my $chardata;
27 3 ▶ while ( read( $fh, $chardata, 2 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (read $fh, $chardata, 2) 240 3 243
28 240 my @data = unpack( 'aC', $chardata );
29 240 ▶ last if tell( $fh ) > $options->{ filesize } || $data[ 0 ] eq chr( 26 );
Branch: 1 branch
BranchTrueFalseTotal
if tell $fh > $options->{"filesize"} or $data[0] eq "\32" 0 240 240
Condition33%1/3
tell $fh > $options->{"filesize"} or $data[0] eq "\32"
l!l&&r!l&&!r
00240
MC/DC0%0/2
tell $fh > $options->{"filesize"} or $data[0] eq "\32"
tell $fh > $options->{"filesize"} $data[0] eq "\32"
Truth table33%1/3
A or B
A= tell $fh > $options->{"filesize"}B= $data[0] eq "\32"
ABresult
1X1
011
000
30 240 $image->putpixel( { char => $data[ 0 ], attr => $data[ 1 ] }, $x,
31 $y );
32  
33 240 $x++;
34 240 ▶ if ( $x == 80 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x == 80) 3 237 240
35 3 $x = 0;
36 3 $y++;
37 }
38 }
39  
40 3 return $image;
41 }
42  
43 sub _parse_palette {
44 3 ▶ my ( $image, $data ) = @_;
Subroutine _parse_palette: called CC=2 SCAR=6.9
45  
46 3 my @pal = unpack( 'C*', $data );
47 3 my @colors;
48 3 for ( @color_idx ) {
49 48 my $offset = $_ * 3;
50 48 push @colors, [ map { $_ << 2 | $_ >> 4 } @pal[ $offset .. $offset + 2 ] ];
51 }
52  
53 $image->palette(
54 3 Image::TextMode::Palette->new( { colors => \@colors } ) );
55 }
56  
57 sub _parse_font {
58 3 ▶ my ( $image, $data ) = @_;
Subroutine _parse_font: called CC=2 SCAR=6.9
59 3 my $height = 16;
60 3 my @chars;
61  
62 3 for ( 0 .. ( length( $data ) / $height ) - 1 ) {
63 768 push @chars,
64 [ unpack( 'C*', substr( $data, $_ * $height, $height ) ) ];
65 }
66  
67 $image->font(
68 3 Image::TextMode::Font->new(
69 { width => 8,
70 height => $height,
71 chars => \@chars,
72 }
73 )
74 );
75 }
76  
77 =head1 NAME
78  
79 Image::TextMode::Reader::ADF - Reads ADF files
80  
81 =head1 DESCRIPTION
82  
83 Provides reading capabilities for the ADF format.
84  
85 =head1 AUTHOR
86  
87 Brian Cassidy E<lt>bricas@cpan.orgE<gt>
88  
89 =head1 COPYRIGHT AND LICENSE
90  
91 Copyright 2008-2014 by Brian Cassidy
92  
93 This library is free software; you can redistribute it and/or modify
94 it under the same terms as Perl itself.
95  
96 =cut
97  
98 2 1;
« TextMode/Writer/IDF.pm ↑ Summary TextMode/Pixel.pm »