blib/lib/Image/Info/WBMP.pm

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