/usr/share/perl5/Image/ExifTool/BMP.pm is in libimage-exiftool-perl 10.40-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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | #------------------------------------------------------------------------------
# File: BMP.pm
#
# Description: Read BMP meta information
#
# Revisions: 07/16/2005 - P. Harvey Created
#
# References: 1) http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html
# 2) http://www.fourcc.org/rgb.php
# 3) https://msdn.microsoft.com/en-us/library/dd183381(v=vs.85).aspx
#------------------------------------------------------------------------------
package Image::ExifTool::BMP;
use strict;
use vars qw($VERSION);
use Image::ExifTool qw(:DataAccess :Utils);
$VERSION = '1.09';
# conversions for fixed-point 2.30 format values
my %fixed2_30 = (
ValueConv => q{
my @a = split ' ', $val;
$_ /= 0x40000000 foreach @a;
"@a";
},
PrintConv => q{
my @a = split ' ', $val;
$_ = sprintf('%.6f', $_) foreach @a;
"@a";
},
);
# BMP chunks
%Image::ExifTool::BMP::Main = (
PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
GROUPS => { 0 => 'File', 1 => 'File', 2 => 'Image' },
NOTES => q{
There really isn't much meta information in a BMP file as such, just a bit
of image related information.
},
0 => {
Name => 'BMPVersion',
Format => 'int32u',
Notes => q{
this is actually the size of the BMP header, but used to determine the BMP
version
},
RawConv => '$$self{BMPVersion} = $val',
PrintConv => {
40 => 'Windows V3',
68 => 'AVI BMP structure?', #PH (seen in AVI movies from some Casio and Nikon cameras)
108 => 'Windows V4',
124 => 'Windows V5',
},
},
4 => {
Name => 'ImageWidth',
Format => 'int32u',
},
8 => {
Name => 'ImageHeight',
Format => 'int32s', # (negative when stored in top-to-bottom order)
ValueConv => 'abs($val)',
},
12 => {
Name => 'Planes',
Format => 'int16u',
# values: 0,1,4,8,16,24,32
},
14 => {
Name => 'BitDepth',
Format => 'int16u',
},
16 => {
Name => 'Compression',
Format => 'int32u',
RawConv => '$$self{BMPCompression} = $val',
# (formatted as string[4] for some values in AVI images)
ValueConv => '$val > 256 ? unpack("A4",pack("V",$val)) : $val',
PrintConv => {
0 => 'None',
1 => '8-Bit RLE',
2 => '4-Bit RLE',
3 => 'Bitfields',
4 => 'JPEG', #2
5 => 'PNG', #2
# pass through ASCII video compression codec ID's
OTHER => sub {
my $val = shift;
# convert non-ascii characters
$val =~ s/([\0-\x1f\x7f-\xff])/sprintf('\\x%.2x',ord $1)/eg;
return $val;
},
},
},
20 => {
Name => 'ImageLength',
Format => 'int32u',
RawConv => '$$self{BMPImageLength} = $val',
},
24 => {
Name => 'PixelsPerMeterX',
Format => 'int32u',
},
28 => {
Name => 'PixelsPerMeterY',
Format => 'int32u',
},
32 => {
Name => 'NumColors',
Format => 'int32u',
PrintConv => '$val ? $val : "Use BitDepth"',
},
36 => {
Name => 'NumImportantColors',
Format => 'int32u',
Hook => '$varSize += $size if $$self{BMPVersion} == 68', # (the rest is invalid for AVI BMP's)
PrintConv => '$val ? $val : "All"',
},
40 => {
Name => 'RedMask',
Format => 'int32u',
PrintConv => 'sprintf("0x%.8x",$val)',
},
44 => {
Name => 'GreenMask',
Format => 'int32u',
PrintConv => 'sprintf("0x%.8x",$val)',
},
48 => {
Name => 'BlueMask',
Format => 'int32u',
PrintConv => 'sprintf("0x%.8x",$val)',
},
52 => {
Name => 'AlphaMask',
Format => 'int32u',
PrintConv => 'sprintf("0x%.8x",$val)',
},
56 => {
Name => 'ColorSpace',
Format => 'undef[4]',
RawConv => '$$self{BMPColorSpace} = $val =~ /\0/ ? Get32u(\$val, 0) : pack("N",unpack("V",$val))',
PrintConv => {
0 => 'Calibrated RGB',
1 => 'Device RGB',
2 => 'Device CMYK',
LINK => 'Linked Color Profile',
MBED => 'Embedded Color Profile',
sRGB => 'sRGB',
'Win ' => 'Windows Color Space',
},
},
60 => {
Name => 'RedEndpoint',
Condition => '$$self{BMPColorSpace} eq "0"',
Format => 'int32u[3]',
%fixed2_30,
},
72 => {
Name => 'GreenEndpoint',
Condition => '$$self{BMPColorSpace} eq "0"',
Format => 'int32u[3]',
%fixed2_30,
},
84 => {
Name => 'BlueEndpoint',
Condition => '$$self{BMPColorSpace} eq "0"',
Format => 'int32u[3]',
%fixed2_30,
},
96 => {
Name => 'GammaRed',
Condition => '$$self{BMPColorSpace} eq "0"',
Format => 'fixed32u',
},
100 => {
Name => 'GammaGreen',
Condition => '$$self{BMPColorSpace} eq "0"',
Format => 'fixed32u',
},
104 => {
Name => 'GammaBlue',
Condition => '$$self{BMPColorSpace} eq "0"',
Format => 'fixed32u',
},
108 => {
Name => 'RenderingIntent',
Format => 'int32u',
PrintConv => {
1 => 'Graphic (LCS_GM_BUSINESS)',
2 => 'Proof (LCS_GM_GRAPHICS)',
4 => 'Picture (LCS_GM_IMAGES)',
8 => 'Absolute Colorimetric (LCS_GM_ABS_COLORIMETRIC)',
},
},
112 => {
Name => 'ProfileDataOffset',
Condition => '$$self{BMPColorSpace} eq "LINK" or $$self{BMPColorSpace} eq "MBED"',
Format => 'int32u',
RawConv => '$$self{BMPProfileOffset} = $val',
},
116 => {
Name => 'ProfileSize',
Condition => '$$self{BMPColorSpace} eq "LINK" or $$self{BMPColorSpace} eq "MBED"',
Format => 'int32u',
RawConv => '$$self{BMPProfileSize} = $val',
},
# 120 - reserved
);
# OS/2 12-byte bitmap header (ref http://www.fileformat.info/format/bmp/egff.htm)
%Image::ExifTool::BMP::OS2 = (
PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
GROUPS => { 0 => 'File', 1 => 'File', 2 => 'Image' },
NOTES => 'Information extracted from OS/2-format BMP images.',
0 => {
Name => 'BMPVersion',
Format => 'int32u',
Notes => 'again, the header size is used to determine the BMP version',
PrintConv => {
12 => 'OS/2 V1',
64 => 'OS/2 V2',
},
},
4 => { Name => 'ImageWidth', Format => 'int16u' },
6 => { Name => 'ImageHeight', Format => 'int16u' },
8 => { Name => 'Planes', Format => 'int16u' },
10 => { Name => 'BitDepth', Format => 'int16u' },
);
%Image::ExifTool::BMP::Extra = (
GROUPS => { 0 => 'File', 1 => 'File', 2 => 'Image' },
NOTES => 'Extra information extracted from some BMP images.',
VARS => { NO_ID => 1 },
LinkedProfileName => { },
ICC_Profile => { SubDirectory => { TagTable => 'Image::ExifTool::ICC_Profile::Main' } },
EmbeddedJPG => {
Groups => { 2 => 'Preview' },
Binary => 1,
},
EmbeddedPNG => {
Groups => { 2 => 'Preview' },
Binary => 1,
},
);
#------------------------------------------------------------------------------
# Extract EXIF information from a BMP image
# Inputs: 0) ExifTool object reference, 1) dirInfo reference
# Returns: 1 on success, 0 if this wasn't a valid BMP file
sub ProcessBMP($$)
{
my ($et, $dirInfo) = @_;
my $raf = $$dirInfo{RAF};
my ($buff, $tagTablePtr);
# verify this is a valid BMP file
return 0 unless $raf->Read($buff, 18) == 18;
return 0 unless $buff =~ /^BM/;
SetByteOrder('II');
my $len = Get32u(\$buff, 14);
# len = v1:12, v4:108, v5:124
return 0 unless $len == 12 or $len == 16 or ($len >= 40 and $len < 1000000);
return 0 unless $raf->Seek(-4, 1) and $raf->Read($buff, $len) == $len;
$et->SetFileType(); # set the FileType tag
#
# process the BMP header
#
my %dirInfo = (
DataPt => \$buff,
DirStart => 0,
DirLen => length($buff),
);
if ($len == 12 or $len == 16 or $len == 64) { # old OS/2 format BMP
$tagTablePtr = GetTagTable('Image::ExifTool::BMP::OS2');
} else {
$tagTablePtr = GetTagTable('Image::ExifTool::BMP::Main');
}
$et->ProcessDirectory(\%dirInfo, $tagTablePtr);
#
# extract any embedded images
#
my $extraTable = GetTagTable('Image::ExifTool::BMP::Extra');
if ($$et{BMPCompression} and $$et{BMPImageLength} and
($$et{BMPCompression} == 4 or $$et{BMPCompression} == 5))
{
my $tag = $$et{BMPCompression} == 4 ? 'EmbeddedJPG' : 'EmbeddedPNG';
my $val = $et->ExtractBinary($raf->Tell(), $$et{BMPImageLength}, $tag);
if ($val) {
$et->HandleTag($extraTable, $tag, $val);
}
}
#
# process profile data if it exists (v5 header only)
#
if ($len == 124 and $$et{BMPProfileOffset}) {
my $pos = $$et{BMPProfileOffset} + 14; # (note the 14-byte shift!)
my $size = $$et{BMPProfileSize};
if ($raf->Seek($pos, 0) and $raf->Read($buff, $size) == $size) {
my $tag;
if ($$et{BMPColorSpace} eq 'LINK') {
$buff =~ s/\0+$//; # remove null terminator(s)
$buff = $et->Decode($buff, 'Latin'); # convert from Latin
$tag = 'LinkedProfileName';
} else {
$tag = 'ICC_Profile';
}
$et->HandleTag($extraTable, $tag => $buff, Size => $size, DataPos => $pos);
} else {
$et->Warn('Error loading profile data', 1);
}
}
return 1;
}
1; # end
__END__
=head1 NAME
Image::ExifTool::BMP - Read BMP meta information
=head1 SYNOPSIS
This module is used by Image::ExifTool
=head1 DESCRIPTION
This module contains definitions required by Image::ExifTool to read BMP
(Windows Bitmap) images.
=head1 AUTHOR
Copyright 2003-2017, Phil Harvey (phil at owl.phy.queensu.ca)
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=head1 REFERENCES
=over 4
=item L<http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html>
=item L<http://www.fourcc.org/rgb.php>
=item L<https://msdn.microsoft.com/en-us/library/dd183381(v=vs.85).aspx>
=back
=head1 SEE ALSO
L<Image::ExifTool::TagNames/BMP Tags>,
L<Image::ExifTool(3pm)|Image::ExifTool>
=cut
|