lib/Image/Info/BMP.pm

filter: Statementstmt 63.1% 36 / 57 Branchbran 60.0% 12 / 20 Conditioncond 66.6% 6 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 3 / 3 Podpod 100% 1 / 1 totaltotal 62.5% 60 / 96 CC 16 SCAR 34.0
CC
16
Cov
63%
process_file
33.7
BEGIN
1.0
BEGIN
1.0
CRAP 30.0
« lib/Image/Info/PNG.pm ↑ Summary lib/Image/Info/SVG/XMLLibXMLReader.pm »
1 package Image::Info::BMP;
2 3 $VERSION = '1.04';
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use constant _CAN_LITTLE_ENDIAN_PACK => $] >= 5.009002;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 sub process_file {
8 4 ▶ my($info, $source, $opts) = @_;
Subroutine process_file: called CC=16 SCAR=35.2
Pod documented
9 4 my(@comments, @warnings, @header, %info, $buf, $total);
10  
11 4 ▶ read($source, $buf, 54) == 54 or die "Can't reread BMP header: $!";
Branch: 1 branch
BranchTrueFalseTotal
read($source, $buf, 54) == 54 or die "Can't reread BMP header: $!" 0 4 4
12 4 @header = unpack((_CAN_LITTLE_ENDIAN_PACK
13 ? "vVv2V2Vl<v2V2V2V2"
14 : "vVv2V2V2v2V2V2V2"
15 ), $buf);
16 4 $total += length($buf);
17  
18 4 ▶ if( $header[9] && $header[9] < 24 ){
Branch: 1 branch
BranchTrueFalseTotal
if ($header[9] and $header[9] < 24) { } 3 1 4
Condition66%2/3
$header[9] and $header[9] < 24
!ll&&!rl&&r
013
MC/DC50%1/2
$header[9] and $header[9] < 24
$header[9] $header[9] < 24
Truth table66%2/3
A and B
A= $header[9]B= $header[9] < 24
ABresult
0X0
100
111
19 3 $info->push_info(0, "color_type" => "Indexed-RGB");
20 }
21 else{
22 1 $info->push_info(0, "color_type" => "RGB");
23 }
24 4 $info->push_info(0, "file_media_type" => "image/bmp");
25 4 ▶ if( $header[10] == 1 || $header[10] == 2){
Branch: 1 branch
BranchTrueFalseTotal
if ($header[10] == 1 or $header[10] == 2) { } 3 1 4
Condition66%2/3
$header[10] == 1 or $header[10] == 2
l!l&&r!l&&!r
301
MC/DC50%1/2
$header[10] == 1 or $header[10] == 2
$header[10] == 1 $header[10] == 2
Truth table66%2/3
A or B
A= $header[10] == 1B= $header[10] == 2
ABresult
1X1
011
000
26 3 $info->push_info(0, "file_ext" => "rle");
27 }
28 else{
29 1 $info->push_info(0, "file_ext" => "bmp"); # || dib
30 }
31  
32 4 $info->push_info(0, "height", (_CAN_LITTLE_ENDIAN_PACK
33 ? abs($header[7])
34 : ($header[7] >= 2**31 ? 2**32 - $header[7] : $header[7])
35 ));
36 4 $info->push_info(0, "resolution", "$header[12]/$header[13]");
37 4 $info->push_info(0, "width", $header[6]);
38 4 $info->push_info(0, "BitsPerSample" => $header[9]);
39 4 $info->push_info(0, "SamplesPerPixel", $header[8]);
40  
41 4 $info->push_info(0, "BMP_ColorsImportant", $header[15]);
42 4 ▶ $info->push_info(0, "BMP_Origin",
Branch: 1 branch
BranchTrueFalseTotal
$header[7] > 1 ? : 3 1 4
43 $header[7]>1 ? 1 : 0 );
44 4 $info->push_info(0, "ColorTableSize", $header[14]);
45 4 $info->push_info(0, "Compression", [
46 'none',
47 'RLE8',
48 'RLE4',
49 'BITFIELDS', #V4
50 'JPEG', #V5
51 'PNG', #V5
52 ]->[$header[10]]);
53 #Version 5 Header amendments
54 # XXX Discard for now, need a test image
55 4 ▶ if( $header[5] > 40 ){
Branch: 1 branch
BranchTrueFalseTotal
if ($header[5] > 40) 0 4 4
56 0 read($source, $buf, $header[5]-40); # XXX test
57 0 $total += length($buf);
58 0 my @v5 = unpack("V38", $buf);
59 0 splice(@v5, 5, 27);
60 0 $info->push_info(0, "BMP_MaskRed", $v5[0]);
61 0 $info->push_info(0, "BMP_MaskGreen", $v5[1]);
62 0 $info->push_info(0, "BMP_MaskBlue", $v5[2]);
63 0 $info->push_info(0, "BMP_MaskAlpha", $v5[3]);
64 # $info->push_info(0, "BMP_color_type", $v5[4]);
65 0 $info->push_info(0, "BMP_GammaRed", $v5[5]);
66 0 $info->push_info(0, "BMP_GammaGreen", $v5[6]);
67 0 $info->push_info(0, "BMP_GammaBlue", $v5[7]);
68 }
69 4 ▶ if( $header[9] < 24 && $opts->{ColorPalette} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($header[9] < 24 and $opts->{"ColorPalette"}) 0 4 4
Condition66%2/3
$header[9] < 24 and $opts->{"ColorPalette"}
!ll&&!rl&&r
130
MC/DC0%0/2
$header[9] < 24 and $opts->{"ColorPalette"}
$header[9] < 24 $opts->{"ColorPalette"}
Truth table66%2/3
A and B
A= $header[9] < 24B= $opts->{"ColorPalette"}
ABresult
0X0
100
111
70 0 my(@color, @palette);
71 0 ▶ for(my $i=0; $i<$header[14]; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $header[14]) 0 0 0
72 0 ▶ read($source, $buf, 4) == 4 or die "Can't read: $!";
Branch: 1 branch
BranchTrueFalseTotal
read($source, $buf, 4) == 4 or die "Can't read: $!" 0 0 0
73 0 $total += length($buf);
74 0 @color = unpack("C3", $buf);
75 # Damn M$, BGR instead of RGB
76 0 push @palette, sprintf("#%02x%02x%02x",
77 $color[2], $color[1], $color[0]);
78 }
79 0 $info->push_info(0, "ColorPalette", @palette);
80 }
81  
82 #Verify size # XXX Cheat and do -s if it's an actual file?
83 4 ▶ while( read($source, $buf, 1024) ){
Branch: 1 branch
BranchTrueFalseTotal
if (read $source, $buf, 1024) 16 4 20
84 16 $total += length($buf);
85 }
86 4 ▶ if( $header[1] != $total ){
Branch: 1 branch
BranchTrueFalseTotal
if ($header[1] != $total) 0 4 4
87 0 push @warnings, "Size mismatch."
88 }
89  
90 4 for (@comments) {
91 0 $info->push_info(0, "Comment", $_);
92 }
93  
94 4 for (@warnings) {
95 0 $info->push_info(0, "Warn", $_);
96 }
97 }
98 3 1;
99 __END__
« lib/Image/Info/PNG.pm ↑ Summary lib/Image/Info/SVG/XMLLibXMLReader.pm »