source: gs2-extensions/parallel-building/trunk/src/perllib/cpan/Image/ExifTool/BMP.pm@ 24626

Last change on this file since 24626 was 24626, checked in by jmt12, 13 years ago

An (almost) complete copy of the perllib directory from a (circa SEP2011) head checkout from Greenstone 2 trunk - in order to try and make merging in this extension a little easier later on (as there have been some major changes to buildcol.pl commited in the main trunk but not in the x64 branch)

File size: 4.9 KB
Line 
1#------------------------------------------------------------------------------
2# File: BMP.pm
3#
4# Description: Read BMP meta information
5#
6# Revisions: 07/16/2005 - P. Harvey Created
7#
8# References: 1) http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html
9# 2) http://www.fourcc.org/rgb.php
10#------------------------------------------------------------------------------
11
12package Image::ExifTool::BMP;
13
14use strict;
15use vars qw($VERSION);
16use Image::ExifTool qw(:DataAccess :Utils);
17
18$VERSION = '1.07';
19
20# BMP chunks
21%Image::ExifTool::BMP::Main = (
22 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
23 GROUPS => { 0 => 'File', 1 => 'File', 2 => 'Image' },
24 NOTES => q{
25 There really isn't much meta information in a BMP file as such, just a bit
26 of image related information.
27 },
28 # 0 => size of bitmap structure:
29 # 12 bytes => 'OS/2 V1',
30 # 40 bytes => 'Windows V3',
31 # 64 bytes => 'OS/2 V2',
32 # 68 bytes => some bitmap structure in AVI videos
33 # 108 bytes => 'Windows V4',
34 # 124 bytes => 'Windows V5',
35 4 => {
36 Name => 'ImageWidth',
37 Format => 'int32u',
38 },
39 8 => {
40 Name => 'ImageHeight',
41 Format => 'int32s', # (negative when stored in top-to-bottom order)
42 ValueConv => 'abs($val)',
43 },
44 12 => {
45 Name => 'Planes',
46 Format => 'int16u',
47 },
48 14 => {
49 Name => 'BitDepth',
50 Format => 'int16u',
51 },
52 16 => {
53 Name => 'Compression',
54 Format => 'int32u',
55 # (formatted as string[4] for some values in AVI images)
56 ValueConv => '$val > 256 ? unpack("A4",pack("V",$val)) : $val',
57 PrintConv => {
58 0 => 'None',
59 1 => '8-Bit RLE',
60 2 => '4-Bit RLE',
61 3 => 'Bitfields',
62 4 => 'JPEG', #2
63 5 => 'PNG', #2
64 # pass through ASCII video compression codec ID's
65 OTHER => sub {
66 my $val = shift;
67 # convert non-ascii characters
68 $val =~ s/([\0-\x1f\x7f-\xff])/sprintf('\\x%.2x',ord $1)/eg;
69 return $val;
70 },
71 },
72 },
73 20 => {
74 Name => 'ImageLength',
75 Format => 'int32u',
76 },
77 24 => {
78 Name => 'PixelsPerMeterX',
79 Format => 'int32u',
80 },
81 28 => {
82 Name => 'PixelsPerMeterY',
83 Format => 'int32u',
84 },
85 32 => {
86 Name => 'NumColors',
87 Format => 'int32u',
88 PrintConv => '$val ? $val : "Use BitDepth"',
89 },
90 36 => {
91 Name => 'NumImportantColors',
92 Format => 'int32u',
93 PrintConv => '$val ? $val : "All"',
94 },
95);
96
97# OS/2 12-byte bitmap header (ref http://www.fileformat.info/format/bmp/egff.htm)
98%Image::ExifTool::BMP::OS2 = (
99 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
100 GROUPS => { 0 => 'File', 1 => 'File', 2 => 'Image' },
101 NOTES => 'Information extracted from OS/2-format BMP images.',
102 # 0 => size of bitmap structure (12)
103 4 => { Name => 'ImageWidth', Format => 'int16u' },
104 6 => { Name => 'ImageHeight', Format => 'int16u' },
105 8 => { Name => 'Planes', Format => 'int16u' },
106 10 => { Name => 'BitDepth', Format => 'int16u' },
107);
108
109#------------------------------------------------------------------------------
110# Extract EXIF information from a BMP image
111# Inputs: 0) ExifTool object reference, 1) dirInfo reference
112# Returns: 1 on success, 0 if this wasn't a valid BMP file
113sub ProcessBMP($$)
114{
115 my ($exifTool, $dirInfo) = @_;
116 my $raf = $$dirInfo{RAF};
117 my ($buff, $tagTablePtr);
118
119 # verify this is a valid BMP file
120 return 0 unless $raf->Read($buff, 18) == 18;
121 return 0 unless $buff =~ /^BM/;
122 SetByteOrder('II');
123 my $len = Get32u(\$buff, 14);
124 return 0 unless $len == 12 or $len >= 40;
125 return 0 unless $raf->Seek(-4, 1) and $raf->Read($buff, $len) == $len;
126 $exifTool->SetFileType(); # set the FileType tag
127 my %dirInfo = (
128 DataPt => \$buff,
129 DirStart => 0,
130 DirLen => length($buff),
131 );
132 if ($len == 12) { # old OS/2 format BMP
133 $tagTablePtr = GetTagTable('Image::ExifTool::BMP::OS2');
134 } else {
135 $tagTablePtr = GetTagTable('Image::ExifTool::BMP::Main');
136 }
137 $exifTool->ProcessDirectory(\%dirInfo, $tagTablePtr);
138 return 1;
139}
140
1411; # end
142
143__END__
144
145=head1 NAME
146
147Image::ExifTool::BMP - Read BMP meta information
148
149=head1 SYNOPSIS
150
151This module is used by Image::ExifTool
152
153=head1 DESCRIPTION
154
155This module contains definitions required by Image::ExifTool to read BMP
156(Windows Bitmap) images.
157
158=head1 AUTHOR
159
160Copyright 2003-2011, Phil Harvey (phil at owl.phy.queensu.ca)
161
162This library is free software; you can redistribute it and/or modify it
163under the same terms as Perl itself.
164
165=head1 REFERENCES
166
167=over 4
168
169=item L<http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html>
170
171=back
172
173=head1 SEE ALSO
174
175L<Image::ExifTool::TagNames/BMP Tags>,
176L<Image::ExifTool(3pm)|Image::ExifTool>
177
178=cut
179
Note: See TracBrowser for help on using the repository browser.