lib/Image/Info/XPM.pm

filter: Statementstmt 41.6% 30 / 72 Branchbran 8.3% 3 / 36 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 3 / 5 Podpod 100% 1 / 1 totaltotal 32.4% 37 / 114 CC 21 SCAR 46.5
CC
21
Cov
31%
process_file
140.1
_get_rgb_txt
20.0
__ANON__
2.0
CRAP 104.2
↑ Summary lib/Image/Info/AVIF.pm »
1 package Image::Info::XPM;
2 3 $VERSION = '1.09';
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Image::Xpm 1.09;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 3 ▶sub process_file{
Subroutine process_file: called CC=18 SCAR=49.4
Pod documented
8 3 my($info, $source, $opts) = @_;
9  
10 0 ▶ local $SIG{__WARN__} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
11 0 $info->push_info(0, "Warn", shift);
12 3 };
13  
14 3 my $i = Image::Xpm->new(-width => 0, -height => 0);
15 # loading the file as a separate step avoids a "-r" test, this would
16 # file with in-memory strings (aka fake files)
17 3 $i->load($source);
18  
19 3 $info->push_info(0, "color_type" => "Indexed-RGB");
20 3 $info->push_info(0, "file_ext" => "xpm");
21 3 $info->push_info(0, "file_media_type" => "image/x-xpixmap");
22 3 $info->push_info(0, "height", $i->get(-height));
23 3 $info->push_info(0, "resolution", "1/1");
24 3 $info->push_info(0, "width", $i->get(-width));
25 3 $info->push_info(0, "BitsPerSample" => 8);
26 3 $info->push_info(0, "SamplesPerPixel", 1);
27  
28 3 $info->push_info(0, "XPM_CharactersPerPixel" => $i->get(-cpp) );
29 # XXX is this always?
30 3 $info->push_info(0, "ColorResolution", 8);
31 3 $info->push_info(0, "ColorTableSize" => $i->get(-ncolours) );
32 3 ▶ if( $opts->{ColorPalette} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"ColorPalette"}) 0 3 3
33 0 $info->push_info(0, "ColorPalette" => [keys %{$i->get(-cindex)}] );
34 }
35 3 ▶ if( $opts->{L1D_Histogram} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"L1D_Histogram"}) 0 3 3
36 #Do Histograms
37 0 my(%RGB, @l1dhist, $R, $G, $B, $color);
38 0 ▶ for(my $y=0; $y<$i->get(-height); $y++){
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $i->get("-height")) 0 0 0
39 0 ▶ for(my $x=0; $x<$i->get(-width); $x++){
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $i->get("-width")) 0 0 0
40 0 $color = $i->xy($x, $y);
41 0 ▶ if( $color =~ /^(none|opaque)$/i ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($color =~ /^(none|opaque)$/i) { } 0 0 0
elsif (not $color =~ /^#/) { } 0 0 0
elsif (length $color == 7) { } 0 0 0
elsif (length $color == 13) { } 0 0 0
elsif (length $color == 4) { } 0 0 0
42 0 next;
43 } elsif( $color !~ /^#/ ){
44 0 ▶ unless( exists($RGB{white}) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $RGB{"white"}) 0 0 0
45 0 local $_;
46 0 ▶ if( open(RGB, _get_rgb_txt()) ){
Branch: 1 branch
BranchTrueFalseTotal
if (open RGB, _get_rgb_txt()) { } 0 0 0
47 0 ▶ while(<RGB>){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline RGB)) 0 0 0
48 0 ▶ next if /^\s*!/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*!/ 0 0 0
49 0 /(\d+)\s+(\d+)\s+(\d+)\s+(.*)/;
50 0 $RGB{$4}=[$1,$2,$3];
51 }
52 }
53 else{
54 0 $RGB{white} = "0 but true";
55 0 $info->push_info(0, "Warn", "Unable to open RGB database, you may need to set \$Image::Info::XPM::RGBLIB");
56 }
57 }
58 0 $R = $RGB{$color}->[0];
59 0 $G = $RGB{$color}->[1];
60 0 $B = $RGB{$color}->[2];
61 }
62 elsif (length $color == 7) {
63 0 $R = hex(substr($color,1,2));
64 0 $G = hex(substr($color,3,2));
65 0 $B = hex(substr($color,5,2));
66 }
67 elsif (length $color == 13) {
68 0 $R = hex(substr($color,1,2));
69 0 $G = hex(substr($color,5,2));
70 0 $B = hex(substr($color,9,2));
71 }
72 elsif (length $color == 4) {
73 0 $R = hex(substr($color,1,1))*16;
74 0 $G = hex(substr($color,2,1))*16;
75 0 $B = hex(substr($color,3,1))*16;
76 }
77 else {
78 0 warn "Unexpected length in color specification '$color'";
79 }
80 0 ▶ if( $opts->{L1D_Histogram} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"L1D_Histogram"}) 0 0 0
81 0 $l1dhist[(.3*$R + .59*$G + .11*$B)]++;
82 }
83 }
84 }
85 0 ▶ if( $opts->{L1D_Histogram} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"L1D_Histogram"}) 0 0 0
86 0 $info->push_info(0, "L1D_Histogram", [@l1dhist]);
87 }
88 }
89 3 $info->push_info(0, "HotSpotX" => $i->get(-hotx) );
90 3 $info->push_info(0, "HotSpotY" => $i->get(-hoty) );
91 3 ▶ $info->push_info(0, 'XPM_Extension-'.ucfirst($i->get(-extname)) => $i->get(-extlines)) if
Branch: 1 branch
BranchTrueFalseTotal
if $i->get("-extname") 0 3 3
92 $i->get(-extname);
93  
94 3 for (@{$i->get(-comments)}) {
95 0 $info->push_info(0, "Comment", $_);
96 }
97 }
98  
99 0 ▶sub _get_rgb_txt{
Subroutine _get_rgb_txt: not called CC=4 SCAR=30.0
100 0 ▶ return $Image::Info::XPM::RGBLIB if defined $Image::Info::XPM::RGBLIB;
Branch: 1 branch
BranchTrueFalseTotal
if defined $Image::Info::XPM::RGBLIB 0 0 0
101 # list taken from Tk::ColorEditor
102 0 for my $try(
103 '/usr/local/lib/X11/rgb.txt',
104 '/usr/lib/X11/rgb.txt',
105 '/usr/X11R6/lib/X11/rgb.txt',
106 '/usr/local/X11R5/lib/X11/rgb.txt',
107 '/X11/R5/lib/X11/rgb.txt',
108 '/X11/R4/lib/rgb/rgb.txt',
109 '/usr/openwin/lib/X11/rgb.txt',
110 '/usr/share/X11/rgb.txt', # This is the Debian and RH5 location
111 '/usr/X11/share/X11/rgb.txt', # seen on a Mac OS X 10.5.1 system
112 '/usr/X11R6/share/X11/rgb.txt', # seen on a OpenBSD 4.2 system
113 '/etc/X11R6/rgb.txt',
114 '/etc/X11/rgb.txt', # seen on HP-UX 11.31
115 ){
116 0 ▶ if( -r $try ){
Branch: 1 branch
BranchTrueFalseTotal
if (-r $try) 0 0 0
117 0 $Image::Info::XPM::RGBLIB = $try;
118 0 return $try;
119 }
120 }
121 0 undef;
122 }
123  
124 3 1;
125 __END__
↑ Summary lib/Image/Info/AVIF.pm »