blib/lib/Image/Info/WBMP.pm

filter: Statementstmt 79.5% 35 / 44 Branchbran 25.0% 4 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 2 totaltotal 64.7% 44 / 68 CC 9 SCAR 25.1
CC
9
Cov
65%
__ANON__
30.0
process_file
3.8
wbmp_image_info
2.0
CRAP 12.3
« lib/Image/Info/JPEG.pm ↑ Summary lib/Image/Info/TIFF.pm »
1 # -*- perl -*-
2  
3 #
4 # Copyright (C) 2013 Slaven Rezic. All rights reserved.
5 # This package is free software; you can redistribute it and/or
6 # modify it under the same terms as Perl itself.
7 #
8  
9 package Image::Info::WBMP;
10  
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use vars qw($VERSION @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 $VERSION = '0.01';
14  
15 1 require Exporter;
16 1 *import = \&Exporter::import;
17  
18 1 @EXPORT_OK = qw(wbmp_image_info);
19  
20 sub process_file {
21 1 ▶ my($info, $fh) = @_;
Subroutine process_file: called CC=3 SCAR=13.5
Pod undocumented
22  
23 # wbmp files have no magic, so no signature check
24  
25 1 $info->push_info(0, 'file_media_type' => 'image/vnd.wap.wbmp');
26 1 $info->push_info(0, 'file_ext' => 'wbmp');
27  
28 # logic taken from netpbm's wbmptopbm.c and adapted to perl
29  
30 my $readint = sub {
31 3 ▶ my $sum = 0;
Subroutine __ANON__: called CC=2 SCAR=7.0
32 3 my $pos = 0;
33 3 my $c;
34 3 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$c & 128 and do { do { $c = ord getc $fh; $sum = $sum << 7 * $pos++ | $c & 127 } } 0 3 3
35 3 $c = ord(getc $fh);
36 3 $sum = ($sum << 7*$pos++) | ($c & 0x7f);
37 } while($c & 0x80);
38 3 return $sum;
39 1 };
40  
41 my $readheader = sub {
42 0 ▶ my $h = shift;
Subroutine __ANON__: not called CC=5 SCAR=34.0
43 0 ▶ if ($h & 0x60 == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($h & !1) { } 0 0 0
elsif ($h & !0) { } 0 0 0
44 # type 00: read multi-byte bitfield
45 0 my $c;
46 0 ▶ do { $c = ord(getc $fh) } while($c & 0x80);
Branch: 1 branch
BranchTrueFalseTotal
$c & 128 and do { do { $c = ord getc $fh } } 0 0 0
47 } elsif ($h & 0x60 == 0x60) {
48 # type 11: read name/value pair
49 0 ▶ for(my $i=0; $i < (($h & 0x70) >> 4) + ($h & 0x0f); $i++) { getc $fh }
Branch: 1 branch
BranchTrueFalseTotal
if ($i < (($h & 112) >> 4) + ($h & 15)) 0 0 0
50 }
51 1 };
52  
53 1 my $c;
54 1 $c = $readint->();
55 1 ▶ $c == 0
Branch: 1 branch
BranchTrueFalseTotal
$c == 0 or die "Unrecognized WBMP type (got $c)" 0 1 1
56 or die "Unrecognized WBMP type (got $c)";
57 1 $c = ord(getc $fh); # FixHeaderField
58 1 ▶ while($c & 0x80) { # ExtheaderFields
Branch: 1 branch
BranchTrueFalseTotal
if ($c & 128) 0 1 1
59 0 $c = ord(getc $fh);
60 0 $readheader->($c);
61 }
62 1 my $w = $readint->();
63 1 my $h = $readint->();
64 1 $info->push_info(0, 'width', $w);
65 1 $info->push_info(0, 'height', $h);
66 }
67  
68 sub wbmp_image_info {
69 1 ▶ my $source = Image::Info::_source(shift);
Subroutine wbmp_image_info: called CC=2 SCAR=7.1
Pod undocumented
70 1 ▶ return $source if ref $source eq 'HASH'; # Pass on errors
Branch: 1 branch
BranchTrueFalseTotal
if ref $source eq "HASH" 0 1 1
71  
72 1 return Image::Info::_image_info_for_format('WBMP', $source);
73 }
74  
75 1 1;
76  
77 __END__
« lib/Image/Info/JPEG.pm ↑ Summary lib/Image/Info/TIFF.pm »