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 |
|
---|
12 | package Image::ExifTool::BMP;
|
---|
13 |
|
---|
14 | use strict;
|
---|
15 | use vars qw($VERSION);
|
---|
16 | use Image::ExifTool qw(:DataAccess :Utils);
|
---|
17 |
|
---|
18 | $VERSION = '1.02';
|
---|
19 |
|
---|
20 | # BMP chunks
|
---|
21 | %Image::ExifTool::BMP::Main = (
|
---|
22 | PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
|
---|
23 | GROUPS => { 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 | 4 => {
|
---|
29 | Name => 'ImageWidth',
|
---|
30 | Format => 'int32u',
|
---|
31 | },
|
---|
32 | 8 => {
|
---|
33 | Name => 'ImageHeight',
|
---|
34 | Format => 'int32u',
|
---|
35 | },
|
---|
36 | 12 => {
|
---|
37 | Name => 'Planes',
|
---|
38 | Format => 'int16u',
|
---|
39 | },
|
---|
40 | 14 => {
|
---|
41 | Name => 'BitDepth',
|
---|
42 | Format => 'int16u',
|
---|
43 | },
|
---|
44 | 16 => {
|
---|
45 | Name => 'Compression',
|
---|
46 | Format => 'int32u',
|
---|
47 | # (formatted as string[4] for some values in AVI images)
|
---|
48 | ValueConv => '$val > 256 ? unpack("A4",pack("V",$val)) : $val',
|
---|
49 | PrintConv => {
|
---|
50 | 0 => 'None',
|
---|
51 | 1 => '8-Bit RLE',
|
---|
52 | 2 => '4-Bit RLE',
|
---|
53 | 3 => 'Bitfields',
|
---|
54 | 4 => 'JPEG', #2
|
---|
55 | 5 => 'PNG', #2
|
---|
56 | },
|
---|
57 | },
|
---|
58 | 20 => {
|
---|
59 | Name => 'ImageLength',
|
---|
60 | Format => 'int32u',
|
---|
61 | },
|
---|
62 | 24 => {
|
---|
63 | Name => 'PixelsPerMeterX',
|
---|
64 | Format => 'int32u',
|
---|
65 | },
|
---|
66 | 28 => {
|
---|
67 | Name => 'PixelsPerMeterY',
|
---|
68 | Format => 'int32u',
|
---|
69 | },
|
---|
70 | 32 => {
|
---|
71 | Name => 'NumColors',
|
---|
72 | Format => 'int32u',
|
---|
73 | PrintConv => '$val ? $val : "Use BitDepth"',
|
---|
74 | },
|
---|
75 | 36 => {
|
---|
76 | Name => 'NumImportantColors',
|
---|
77 | Format => 'int32u',
|
---|
78 | PrintConv => '$val ? $val : "All"',
|
---|
79 | },
|
---|
80 | );
|
---|
81 |
|
---|
82 | #------------------------------------------------------------------------------
|
---|
83 | # Extract EXIF information from a BMP image
|
---|
84 | # Inputs: 0) ExifTool object reference, 1) dirInfo reference
|
---|
85 | # Returns: 1 on success, 0 if this wasn't a valid BMP file
|
---|
86 | sub ProcessBMP($$)
|
---|
87 | {
|
---|
88 | my ($exifTool, $dirInfo) = @_;
|
---|
89 | my $raf = $$dirInfo{RAF};
|
---|
90 | my $buff;
|
---|
91 |
|
---|
92 | # verify this is a valid BMP file
|
---|
93 | return 0 unless $raf->Read($buff, 14) == 14;
|
---|
94 | return 0 unless $buff =~ /^BM/;
|
---|
95 | return 0 unless $raf->Read($buff, 40) == 40;
|
---|
96 | SetByteOrder('II');
|
---|
97 | return 0 unless Get32u(\$buff, 0) >= 40; # make sure info is at least 40 bytes
|
---|
98 | $exifTool->SetFileType(); # set the FileType tag
|
---|
99 | my %dirInfo = (
|
---|
100 | DataPt => \$buff,
|
---|
101 | DirStart => 0,
|
---|
102 | DirLen => length($buff),
|
---|
103 | );
|
---|
104 | my $tagTablePtr = GetTagTable('Image::ExifTool::BMP::Main');
|
---|
105 | $exifTool->ProcessDirectory(\%dirInfo, $tagTablePtr);
|
---|
106 | return 1;
|
---|
107 | }
|
---|
108 |
|
---|
109 | 1; # end
|
---|
110 |
|
---|
111 | __END__
|
---|
112 |
|
---|
113 | =head1 NAME
|
---|
114 |
|
---|
115 | Image::ExifTool::BMP - Read BMP meta information
|
---|
116 |
|
---|
117 | =head1 SYNOPSIS
|
---|
118 |
|
---|
119 | This module is used by Image::ExifTool
|
---|
120 |
|
---|
121 | =head1 DESCRIPTION
|
---|
122 |
|
---|
123 | This module contains definitions required by Image::ExifTool to read BMP
|
---|
124 | (Windows Bitmap) images.
|
---|
125 |
|
---|
126 | =head1 AUTHOR
|
---|
127 |
|
---|
128 | Copyright 2003-2007, Phil Harvey (phil at owl.phy.queensu.ca)
|
---|
129 |
|
---|
130 | This library is free software; you can redistribute it and/or modify it
|
---|
131 | under the same terms as Perl itself.
|
---|
132 |
|
---|
133 | =head1 REFERENCES
|
---|
134 |
|
---|
135 | =over 4
|
---|
136 |
|
---|
137 | =item L<http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html>
|
---|
138 |
|
---|
139 | =back
|
---|
140 |
|
---|
141 | =head1 SEE ALSO
|
---|
142 |
|
---|
143 | L<Image::ExifTool::TagNames/BMP Tags>,
|
---|
144 | L<Image::ExifTool(3pm)|Image::ExifTool>
|
---|
145 |
|
---|
146 | =cut
|
---|
147 |
|
---|