File Coverage

lib/Image/Info/XPM.pm
Criterion Covered Total %
statement 28 70 40.0
branch 3 30 10.0
condition n/a
subroutine 3 5 60.0
pod 1 1 100.0
total 35 106 33.0


line stmt bran cond sub pod time code
1             package Image::Info::XPM;
2             $VERSION = '1.09';
3 2     2   15 use strict;
  2         2  
  2         104  
4 2     2   13 use Image::Xpm 1.09;
  2         40  
  2         1836  
5              
6              
7             sub process_file{
8 3     3 1 7 my($info, $source, $opts) = @_;
9              
10             local $SIG{__WARN__} = sub {
11 0     0   0 $info->push_info(0, "Warn", shift);
12 3         21 };
13              
14 3         18 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         396 $i->load($source);
18              
19 3         1798 $info->push_info(0, "color_type" => "Indexed-RGB");
20 3         7 $info->push_info(0, "file_ext" => "xpm");
21 3         7 $info->push_info(0, "file_media_type" => "image/x-xpixmap");
22 3         9 $info->push_info(0, "height", $i->get(-height));
23 3         14 $info->push_info(0, "resolution", "1/1");
24 3         8 $info->push_info(0, "width", $i->get(-width));
25 3         8 $info->push_info(0, "BitsPerSample" => 8);
26 3         6 $info->push_info(0, "SamplesPerPixel", 1);
27              
28 3         8 $info->push_info(0, "XPM_CharactersPerPixel" => $i->get(-cpp) );
29             # XXX is this always?
30 3         7 $info->push_info(0, "ColorResolution", 8);
31 3         6 $info->push_info(0, "ColorTableSize" => $i->get(-ncolours) );
32 3 50       11 if( $opts->{ColorPalette} ){
33 0         0 $info->push_info(0, "ColorPalette" => [keys %{$i->get(-cindex)}] );
  0         0  
34             }
35 3 50       5 if( $opts->{L1D_Histogram} ){
36             #Do Histograms
37 0         0 my(%RGB, @l1dhist, $R, $G, $B, $color);
38 0         0 for(my $y=0; $y<$i->get(-height); $y++){
39 0         0 for(my $x=0; $x<$i->get(-width); $x++){
40 0         0 $color = $i->xy($x, $y);
41 0 0       0 if( $color =~ /^(none|opaque)$/i ) {
    0          
    0          
    0          
    0          
42 0         0 next;
43             } elsif( $color !~ /^#/ ){
44 0 0       0 unless( exists($RGB{white}) ){
45 0         0 local $_;
46 0 0       0 if( open(RGB, _get_rgb_txt()) ){
47 0         0 while(){
48 0 0       0 next if /^\s*!/;
49 0         0 /(\d+)\s+(\d+)\s+(\d+)\s+(.*)/;
50 0         0 $RGB{$4}=[$1,$2,$3];
51             }
52             }
53             else{
54 0         0 $RGB{white} = "0 but true";
55 0         0 $info->push_info(0, "Warn", "Unable to open RGB database, you may need to set \$Image::Info::XPM::RGBLIB");
56             }
57             }
58 0         0 $R = $RGB{$color}->[0];
59 0         0 $G = $RGB{$color}->[1];
60 0         0 $B = $RGB{$color}->[2];
61             }
62             elsif (length $color == 7) {
63 0         0 $R = hex(substr($color,1,2));
64 0         0 $G = hex(substr($color,3,2));
65 0         0 $B = hex(substr($color,5,2));
66             }
67             elsif (length $color == 13) {
68 0         0 $R = hex(substr($color,1,2));
69 0         0 $G = hex(substr($color,5,2));
70 0         0 $B = hex(substr($color,9,2));
71             }
72             elsif (length $color == 4) {
73 0         0 $R = hex(substr($color,1,1))*16;
74 0         0 $G = hex(substr($color,2,1))*16;
75 0         0 $B = hex(substr($color,3,1))*16;
76             }
77             else {
78 0         0 warn "Unexpected length in color specification '$color'";
79             }
80 0 0       0 if( $opts->{L1D_Histogram} ){
81 0         0 $l1dhist[(.3*$R + .59*$G + .11*$B)]++;
82             }
83             }
84             }
85 0 0       0 if( $opts->{L1D_Histogram} ){
86 0         0 $info->push_info(0, "L1D_Histogram", [@l1dhist]);
87             }
88             }
89 3         8 $info->push_info(0, "HotSpotX" => $i->get(-hotx) );
90 3         8 $info->push_info(0, "HotSpotY" => $i->get(-hoty) );
91 3 50       7 $info->push_info(0, 'XPM_Extension-'.ucfirst($i->get(-extname)) => $i->get(-extlines)) if
92             $i->get(-extname);
93              
94 3         31 for (@{$i->get(-comments)}) {
  3         7  
95 0           $info->push_info(0, "Comment", $_);
96             }
97             }
98              
99             sub _get_rgb_txt{
100 0 0   0     return $Image::Info::XPM::RGBLIB if defined $Image::Info::XPM::RGBLIB;
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 0         if( -r $try ){
117 0           $Image::Info::XPM::RGBLIB = $try;
118 0           return $try;
119             }
120             }
121 0           undef;
122             }
123              
124             1;
125             __END__