/usr/share/perl5/Image/Info/XPM.pm is in libimage-info-perl 1.41-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | package Image::Info::XPM;
$VERSION = '1.09';
use strict;
use Image::Xpm 1.09;
sub process_file{
my($info, $source, $opts) = @_;
local $SIG{__WARN__} = sub {
$info->push_info(0, "Warn", shift);
};
my $i = Image::Xpm->new(-width => 0, -height => 0);
# loading the file as a separate step avoids a "-r" test, this would
# file with in-memory strings (aka fake files)
$i->load($source);
$info->push_info(0, "color_type" => "Indexed-RGB");
$info->push_info(0, "file_ext" => "xpm");
$info->push_info(0, "file_media_type" => "image/x-xpixmap");
$info->push_info(0, "height", $i->get(-height));
$info->push_info(0, "resolution", "1/1");
$info->push_info(0, "width", $i->get(-width));
$info->push_info(0, "BitsPerSample" => 8);
$info->push_info(0, "SamplesPerPixel", 1);
$info->push_info(0, "XPM_CharactersPerPixel" => $i->get(-cpp) );
# XXX is this always?
$info->push_info(0, "ColorResolution", 8);
$info->push_info(0, "ColorTableSize" => $i->get(-ncolours) );
if( $opts->{ColorPalette} ){
$info->push_info(0, "ColorPalette" => [keys %{$i->get(-cindex)}] );
}
if( $opts->{L1D_Histogram} ){
#Do Histograms
my(%RGB, @l1dhist, $R, $G, $B, $color);
for(my $y=0; $y<$i->get(-height); $y++){
for(my $x=0; $x<$i->get(-width); $x++){
$color = $i->xy($x, $y);
if( $color =~ /^(none|opaque)$/i ) {
next;
} elsif( $color !~ /^#/ ){
unless( exists($RGB{white}) ){
local $_;
if( open(RGB, _get_rgb_txt()) ){
while(<RGB>){
next if /^\s*!/;
/(\d+)\s+(\d+)\s+(\d+)\s+(.*)/;
$RGB{$4}=[$1,$2,$3];
}
}
else{
$RGB{white} = "0 but true";
$info->push_info(0, "Warn", "Unable to open RGB database, you may need to set \$Image::Info::XPM::RGBLIB");
}
}
$R = $RGB{$color}->[0];
$G = $RGB{$color}->[1];
$B = $RGB{$color}->[2];
}
elsif (length $color == 7) {
$R = hex(substr($color,1,2));
$G = hex(substr($color,3,2));
$B = hex(substr($color,5,2));
}
elsif (length $color == 13) {
$R = hex(substr($color,1,2));
$G = hex(substr($color,5,2));
$B = hex(substr($color,9,2));
}
elsif (length $color == 4) {
$R = hex(substr($color,1,1))*16;
$G = hex(substr($color,2,1))*16;
$B = hex(substr($color,3,1))*16;
}
else {
warn "Unexpected length in color specification '$color'";
}
if( $opts->{L1D_Histogram} ){
$l1dhist[(.3*$R + .59*$G + .11*$B)]++;
}
}
}
if( $opts->{L1D_Histogram} ){
$info->push_info(0, "L1D_Histogram", [@l1dhist]);
}
}
$info->push_info(0, "HotSpotX" => $i->get(-hotx) );
$info->push_info(0, "HotSpotY" => $i->get(-hoty) );
$info->push_info(0, 'XPM_Extension-'.ucfirst($i->get(-extname)) => $i->get(-extlines)) if
$i->get(-extname);
for (@{$i->get(-comments)}) {
$info->push_info(0, "Comment", $_);
}
}
sub _get_rgb_txt{
return $Image::Info::XPM::RGBLIB if defined $Image::Info::XPM::RGBLIB;
# list taken from Tk::ColorEditor
for my $try(
'/usr/local/lib/X11/rgb.txt',
'/usr/lib/X11/rgb.txt',
'/usr/X11R6/lib/X11/rgb.txt',
'/usr/local/X11R5/lib/X11/rgb.txt',
'/X11/R5/lib/X11/rgb.txt',
'/X11/R4/lib/rgb/rgb.txt',
'/usr/openwin/lib/X11/rgb.txt',
'/usr/share/X11/rgb.txt', # This is the Debian and RH5 location
'/usr/X11/share/X11/rgb.txt', # seen on a Mac OS X 10.5.1 system
'/usr/X11R6/share/X11/rgb.txt', # seen on a OpenBSD 4.2 system
'/etc/X11R6/rgb.txt',
'/etc/X11/rgb.txt', # seen on HP-UX 11.31
){
if( -r $try ){
$Image::Info::XPM::RGBLIB = $try;
return $try;
}
}
undef;
}
1;
__END__
=head1 NAME
Image::Info::XPM - XPM support for Image::Info
=head1 SYNOPSIS
use Image::Info qw(image_info dim);
my $info = image_info("image.xpm");
if (my $error = $info->{error}) {
die "Can't parse image info: $error\n";
}
my $color = $info->{color_type};
my($w, $h) = dim($info);
=head1 DESCRIPTION
This modules supplies the standard key names
except for Compression, Gamma, Interlace, LastModificationTime, as well as:
=over
=item ColorPalette
Reference to an array of all colors used.
This key is only present if C<image_info> is invoked
as C<image_info($file, ColorPaletteE<gt>=1)>.
=item ColorTableSize
The number of colors the image uses.
=item HotSpotX
The x-coord of the image's hotspot.
Set to -1 if there is no hotspot.
=item HotSpotY
The y-coord of the image's hotspot.
Set to -1 if there is no hotspot.
=item L1D_Histogram
Reference to an array representing a one dimensional luminance
histogram. This key is only present if C<image_info> is invoked
as C<image_info($file, L1D_Histogram=E<gt>1)>. The range is from 0 to 255,
however auto-vivification is used so a null field is also 0,
and the array may not actually contain 255 fields.
=item XPM_CharactersPerPixel
This is typically 1 or 2. See L<Image::Xpm>.
=item XPM_Extension-.*
XPM Extensions (the most common is XPMEXT) if present.
=back
=head1 METHODS
=head2 process_file()
$info->process_file($source, $options);
Processes one file and sets the found info fields in the C<$info> object.
=head1 FILES
This module requires L<Image::Xpm>
I<$Image::Info::XPM::RGBLIB> is set to F</usr/X11R6/lib/X11/rgb.txt>
or an equivalent path (see the C<_get_rgb_txt> function for the
complete list) by default, this is used to resolve textual color names
to their RGB counterparts.
=head1 SEE ALSO
L<Image::Info>, L<Image::Xpm>
=head1 NOTES
For more information about XPM see
L<ftp://ftp.x.org/contrib/libraries/xpm-README.html>
=head1 CAVEATS
While the module attempts to be as robust as possible, it may not recognize
older XPMs (Versions 1-3), if this is the case try inserting S</* XPM */>
as the first line.
=head1 AUTHOR
Jerrad Pierce <belg4mit@mit.edu>/<webmaster@pthbb.org>
Tels - (c) 2006.
Now maintained by Slaven Rezic <srezic@cpan.org>.
This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
=begin register
MAGIC: /(^\/\* XPM \*\/)|(static\s+char\s+\*\w+\[\]\s*=\s*{\s*"\d+)/
See L<Image::Info::XPM> for details.
=end register
=cut
|