| 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 | sub process_file{ | ||||||||||||||||||||||||||
| 8 | 3 | ▶ | my($info, $source, $opts) = @_; | ||||||||||||||||||||||||
|
Subroutine
process_file: called CC=18 SCAR=49.4
Pod
documented
| |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||
| 10 | local $SIG{__WARN__} = sub { | ||||||||||||||||||||||||||
| 11 | 0 | ▶ | $info->push_info(0, "Warn", shift); | ||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||
| 33 | 0 | $info->push_info(0, "ColorPalette" => [keys %{$i->get(-cindex)}] ); | |||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||
| 35 | 3 | ▶ | if( $opts->{L1D_Histogram} ){ | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||
| 39 | 0 | ▶ | for(my $x=0; $x<$i->get(-width); $x++){ | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 40 | 0 | $color = $i->xy($x, $y); | |||||||||||||||||||||||||
| 41 | 0 | ▶ | if( $color =~ /^(none|opaque)$/i ) { | ||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||
| 42 | 0 | next; | |||||||||||||||||||||||||
| 43 | } elsif( $color !~ /^#/ ){ | ||||||||||||||||||||||||||
| 44 | 0 | ▶ | unless( exists($RGB{white}) ){ | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 45 | 0 | local $_; | |||||||||||||||||||||||||
| 46 | 0 | ▶ | if( open(RGB, _get_rgb_txt()) ){ | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 47 | 0 | ▶ | while(<RGB>){ | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 48 | 0 | ▶ | next if /^\s*!/; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||
| 81 | 0 | $l1dhist[(.3*$R + .59*$G + .11*$B)]++; | |||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||
| 85 | 0 | ▶ | if( $opts->{L1D_Histogram} ){ | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||
| 92 | $i->get(-extname); | ||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||
| 94 | 3 | for (@{$i->get(-comments)}) { | |||||||||||||||||||||||||
| 95 | 0 | $info->push_info(0, "Comment", $_); | |||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||
| 99 | sub _get_rgb_txt{ | ||||||||||||||||||||||||||
| 100 | 0 | ▶ | return $Image::Info::XPM::RGBLIB if defined $Image::Info::XPM::RGBLIB; | ||||||||||||||||||||||||
|
Subroutine
_get_rgb_txt: not called CC=4 SCAR=30.0
Branch: 1 branch
| |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||
| 117 | 0 | $Image::Info::XPM::RGBLIB = $try; | |||||||||||||||||||||||||
| 118 | 0 | return $try; | |||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||
| 121 | 0 | undef; | |||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||
| 124 | 3 | 1; | |||||||||||||||||||||||||
| 125 | __END__ | ||||||||||||||||||||||||||