1 | #------------------------------------------------------------------------------
|
---|
2 | # File: MPF.pm
|
---|
3 | #
|
---|
4 | # Description: Read Multi-Picture Format information
|
---|
5 | #
|
---|
6 | # Revisions: 06/12/2009 - P. Harvey Created
|
---|
7 | #
|
---|
8 | # References: 1) http://www.cipa.jp/english/hyoujunka/kikaku/pdf/DC-007_E.pdf
|
---|
9 | #------------------------------------------------------------------------------
|
---|
10 |
|
---|
11 | package Image::ExifTool::MPF;
|
---|
12 |
|
---|
13 | use strict;
|
---|
14 | use vars qw($VERSION);
|
---|
15 | use Image::ExifTool qw(:DataAccess :Utils);
|
---|
16 | use Image::ExifTool::Exif;
|
---|
17 |
|
---|
18 | $VERSION = '1.05';
|
---|
19 |
|
---|
20 | sub ProcessMPImageList($$$);
|
---|
21 |
|
---|
22 | # Tags found in MPF APP2 segment in JPEG images
|
---|
23 | %Image::ExifTool::MPF::Main = (
|
---|
24 | GROUPS => { 0 => 'MPF', 1 => 'MPF0', 2 => 'Image'},
|
---|
25 | NOTES => q{
|
---|
26 | These tags are part of the CIPA Multi-Picture Format specification, and are
|
---|
27 | found in the APP2 "MPF" segment of JPEG images. See
|
---|
28 | L<http://www.cipa.jp/english/hyoujunka/kikaku/pdf/DC-007_E.pdf> for the
|
---|
29 | official specification.
|
---|
30 | },
|
---|
31 | 0xb000 => 'MPFVersion',
|
---|
32 | 0xb001 => 'NumberOfImages',
|
---|
33 | 0xb002 => {
|
---|
34 | Name => 'MPImageList',
|
---|
35 | SubDirectory => {
|
---|
36 | TagTable => 'Image::ExifTool::MPF::MPImage',
|
---|
37 | ProcessProc => \&ProcessMPImageList,
|
---|
38 | },
|
---|
39 | },
|
---|
40 | 0xb003 => {
|
---|
41 | Name => 'ImageUIDList',
|
---|
42 | Binary => 1,
|
---|
43 | },
|
---|
44 | 0xb004 => 'TotalFrames',
|
---|
45 | 0xb101 => 'MPIndividualNum',
|
---|
46 | 0xb201 => {
|
---|
47 | Name => 'PanOrientation',
|
---|
48 | PrintHex => 1,
|
---|
49 | Notes => 'long integer is split into 4 bytes',
|
---|
50 | ValueConv => 'join(" ",unpack("C*",pack("N",$val)))',
|
---|
51 | PrintConv => [
|
---|
52 | '"$val rows"',
|
---|
53 | '"$val columns"',
|
---|
54 | {
|
---|
55 | 0 => '[unused]',
|
---|
56 | 1 => 'Start at top right',
|
---|
57 | 2 => 'Start at top left',
|
---|
58 | 3 => 'Start at bottom left',
|
---|
59 | 4 => 'Start at bottom right',
|
---|
60 | },
|
---|
61 | {
|
---|
62 | 0x01 => 'Left to right',
|
---|
63 | 0x02 => 'Right to left',
|
---|
64 | 0x03 => 'Top to bottom',
|
---|
65 | 0x04 => 'Bottom to top',
|
---|
66 | 0x10 => 'Clockwise',
|
---|
67 | 0x20 => 'Counter clockwise',
|
---|
68 | 0x30 => 'Zigzag (row start)',
|
---|
69 | 0x40 => 'Zigzag (column start)',
|
---|
70 | },
|
---|
71 | ],
|
---|
72 | },
|
---|
73 | 0xb202 => 'PanOverlapH',
|
---|
74 | 0xb203 => 'PanOverlapV',
|
---|
75 | 0xb204 => 'BaseViewpointNum',
|
---|
76 | 0xb205 => 'ConvergenceAngle',
|
---|
77 | 0xb206 => 'BaselineLength',
|
---|
78 | 0xb207 => 'VerticalDivergence',
|
---|
79 | 0xb208 => 'AxisDistanceX',
|
---|
80 | 0xb209 => 'AxisDistanceY',
|
---|
81 | 0xb20a => 'AxisDistanceZ',
|
---|
82 | 0xb20b => 'YawAngle',
|
---|
83 | 0xb20c => 'PitchAngle',
|
---|
84 | 0xb20d => 'RollAngle',
|
---|
85 | );
|
---|
86 |
|
---|
87 | # Tags found in MPImage structure
|
---|
88 | %Image::ExifTool::MPF::MPImage = (
|
---|
89 | PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
|
---|
90 | #WRITE_PROC => \&Image::ExifTool::WriteBinaryData,
|
---|
91 | #CHECK_PROC => \&Image::ExifTool::CheckBinaryData,
|
---|
92 | #WRITABLE => 1,
|
---|
93 | GROUPS => { 0 => 'MPF', 1 => 'MPImage', 2 => 'Image'},
|
---|
94 | NOTES => q{
|
---|
95 | The first MPF "Large Thumbnail" image is extracted as PreviewImage, and the
|
---|
96 | rest of the embedded MPF images are extracted as MPImage#. The
|
---|
97 | ExtractEmbedded (-ee) option may be used to extract information from these
|
---|
98 | embedded images.
|
---|
99 | },
|
---|
100 | 0.1 => {
|
---|
101 | Name => 'MPImageFlags',
|
---|
102 | Format => 'int32u',
|
---|
103 | Mask => 0xf8000000,
|
---|
104 | PrintConv => { BITMASK => {
|
---|
105 | 29 => 'Representative image',
|
---|
106 | 30 => 'Dependent child image',
|
---|
107 | 31 => 'Dependent parent image',
|
---|
108 | }},
|
---|
109 | },
|
---|
110 | 0.2 => {
|
---|
111 | Name => 'MPImageFormat',
|
---|
112 | Format => 'int32u',
|
---|
113 | Mask => 0x07000000,
|
---|
114 | PrintConv => {
|
---|
115 | 0 => 'JPEG',
|
---|
116 | },
|
---|
117 | },
|
---|
118 | 0.3 => {
|
---|
119 | Name => 'MPImageType',
|
---|
120 | Format => 'int32u',
|
---|
121 | Mask => 0x00ffffff,
|
---|
122 | PrintHex => 1,
|
---|
123 | PrintConv => {
|
---|
124 | 0x000000 => 'Undefined',
|
---|
125 | 0x010001 => 'Large Thumbnail (VGA equivalent)',
|
---|
126 | 0x010002 => 'Large Thumbnail (full HD equivalent)',
|
---|
127 | 0x020001 => 'Multi-frame Panorama',
|
---|
128 | 0x020002 => 'Multi-frame Disparity',
|
---|
129 | 0x020003 => 'Multi-angle',
|
---|
130 | 0x030000 => 'Baseline MP Primary Image',
|
---|
131 | },
|
---|
132 | },
|
---|
133 | 4 => {
|
---|
134 | Name => 'MPImageLength',
|
---|
135 | Format => 'int32u',
|
---|
136 | },
|
---|
137 | 8 => {
|
---|
138 | Name => 'MPImageStart',
|
---|
139 | Format => 'int32u',
|
---|
140 | IsOffset => '$val',
|
---|
141 | },
|
---|
142 | 12 => {
|
---|
143 | Name => 'DependentImage1EntryNumber',
|
---|
144 | Format => 'int16u',
|
---|
145 | },
|
---|
146 | 14 => {
|
---|
147 | Name => 'DependentImage2EntryNumber',
|
---|
148 | Format => 'int16u',
|
---|
149 | },
|
---|
150 | );
|
---|
151 |
|
---|
152 | # extract MP Images as composite tags
|
---|
153 | %Image::ExifTool::MPF::Composite = (
|
---|
154 | GROUPS => { 2 => 'Image' },
|
---|
155 | MPImage => {
|
---|
156 | Require => {
|
---|
157 | 0 => 'MPImageStart',
|
---|
158 | 1 => 'MPImageLength',
|
---|
159 | 2 => 'MPImageType',
|
---|
160 | },
|
---|
161 | Notes => q{
|
---|
162 | the first MPF "Large Thumbnail" is extracted as PreviewImage, and the rest
|
---|
163 | of the embedded MPF images are extracted as MPImage#. The ExtractEmbedded
|
---|
164 | option may be used to extract information from these embedded images.
|
---|
165 | },
|
---|
166 | # extract all MPF images (not just one)
|
---|
167 | RawConv => q{
|
---|
168 | require Image::ExifTool::MPF;
|
---|
169 | Image::ExifTool::MPF::ExtractMPImages($self);
|
---|
170 | },
|
---|
171 | },
|
---|
172 | );
|
---|
173 |
|
---|
174 | # add our composite tags
|
---|
175 | Image::ExifTool::AddCompositeTags('Image::ExifTool::MPF');
|
---|
176 |
|
---|
177 | #------------------------------------------------------------------------------
|
---|
178 | # Extract all MP images
|
---|
179 | # Inputs: 0) ExifTool object ref
|
---|
180 | # Returns: undef
|
---|
181 | sub ExtractMPImages($)
|
---|
182 | {
|
---|
183 | my $exifTool = shift;
|
---|
184 | my $ee = $exifTool->Options('ExtractEmbedded');
|
---|
185 | my $saveBinary = $exifTool->Options('Binary');
|
---|
186 | my ($i, $didPreview, $xtra);
|
---|
187 |
|
---|
188 | for ($i=1; $xtra or not defined $xtra; ++$i) {
|
---|
189 | # run through MP images in the same order they were extracted
|
---|
190 | $xtra = defined $$exifTool{VALUE}{"MPImageStart ($i)"} ? " ($i)" : '';
|
---|
191 | my $off = $exifTool->GetValue("MPImageStart$xtra");
|
---|
192 | my $len = $exifTool->GetValue("MPImageLength$xtra");
|
---|
193 | if ($off and $len) {
|
---|
194 | my $type = $exifTool->GetValue("MPImageType$xtra", 'ValueConv');
|
---|
195 | my $tag = "MPImage$i";
|
---|
196 | # store first "Large Thumbnail" as a PreviewImage
|
---|
197 | if (not $didPreview and $type and ($type & 0x0f0000) == 0x010000) {
|
---|
198 | $tag = 'PreviewImage';
|
---|
199 | $didPreview = 1;
|
---|
200 | }
|
---|
201 | $exifTool->Options('Binary', 1) if $ee;
|
---|
202 | my $val = Image::ExifTool::Exif::ExtractImage($exifTool, $off, $len, $tag);
|
---|
203 | $exifTool->Options('Binary', $saveBinary) if $ee;
|
---|
204 | next unless defined $val;
|
---|
205 | unless ($Image::ExifTool::Extra{$tag}) {
|
---|
206 | Image::ExifTool::AddTagToTable(\%Image::ExifTool::Extra, $tag, {
|
---|
207 | Name => $tag,
|
---|
208 | Groups => { 0 => 'Composite', 1 => 'Composite', 2 => 'Image'},
|
---|
209 | });
|
---|
210 | }
|
---|
211 | my $key = $exifTool->FoundTag($tag, $val);
|
---|
212 | # set groups for PreviewImage
|
---|
213 | if ($tag eq 'PreviewImage') {
|
---|
214 | $exifTool->SetGroup($key, 'Composite', 0);
|
---|
215 | $exifTool->SetGroup($key, 'Composite');
|
---|
216 | }
|
---|
217 | # extract information from MP images if ExtractEmbedded option used
|
---|
218 | if ($ee) {
|
---|
219 | $$exifTool{DOC_NUM} = $i;
|
---|
220 | $exifTool->ExtractInfo($val, { ReEntry => 1 });
|
---|
221 | delete $$exifTool{DOC_NUM};
|
---|
222 | }
|
---|
223 | }
|
---|
224 | }
|
---|
225 | return undef;
|
---|
226 | }
|
---|
227 |
|
---|
228 | #------------------------------------------------------------------------------
|
---|
229 | # Process MP Entry list
|
---|
230 | # Inputs: 0) ExifTool object ref, 1) dirInfo ref, 2) tag table ref
|
---|
231 | # Returns: 1 on success
|
---|
232 | sub ProcessMPImageList($$$)
|
---|
233 | {
|
---|
234 | my ($exifTool, $dirInfo, $tagTablePtr) = @_;
|
---|
235 | my $num = int($$dirInfo{DirLen} / 16); # (16 bytes per MP Entry)
|
---|
236 | $$dirInfo{DirLen} = 16;
|
---|
237 | my ($i, $success);
|
---|
238 | my $oldG1 = $$exifTool{SET_GROUP1};
|
---|
239 | for ($i=0; $i<$num; ++$i) {
|
---|
240 | $$exifTool{SET_GROUP1} = '+' . ($i + 1);
|
---|
241 | $success = $exifTool->ProcessBinaryData($dirInfo, $tagTablePtr);
|
---|
242 | $$dirInfo{DirStart} += 16;
|
---|
243 | }
|
---|
244 | $$exifTool{SET_GROUP1} = $oldG1;
|
---|
245 | return $success;
|
---|
246 | }
|
---|
247 |
|
---|
248 | 1; # end
|
---|
249 |
|
---|
250 | __END__
|
---|
251 |
|
---|
252 | =head1 NAME
|
---|
253 |
|
---|
254 | Image::ExifTool::MPF - Read Multi-Picture Format information
|
---|
255 |
|
---|
256 | =head1 SYNOPSIS
|
---|
257 |
|
---|
258 | This module is used by Image::ExifTool
|
---|
259 |
|
---|
260 | =head1 DESCRIPTION
|
---|
261 |
|
---|
262 | This module contains tag definitions and routines to read Multi-Picture
|
---|
263 | Format (MPF) information from JPEG images.
|
---|
264 |
|
---|
265 | =head1 AUTHOR
|
---|
266 |
|
---|
267 | Copyright 2003-2011, Phil Harvey (phil at owl.phy.queensu.ca)
|
---|
268 |
|
---|
269 | This library is free software; you can redistribute it and/or modify it
|
---|
270 | under the same terms as Perl itself.
|
---|
271 |
|
---|
272 | =head1 REFERENCES
|
---|
273 |
|
---|
274 | =over 4
|
---|
275 |
|
---|
276 | =item L<http://www.cipa.jp/english/hyoujunka/kikaku/pdf/DC-007_E.pdf>
|
---|
277 |
|
---|
278 | =back
|
---|
279 |
|
---|
280 | =head1 SEE ALSO
|
---|
281 |
|
---|
282 | L<Image::ExifTool::TagNames/MPF Tags>,
|
---|
283 | L<Image::ExifTool(3pm)|Image::ExifTool>
|
---|
284 |
|
---|
285 | =cut
|
---|
286 |
|
---|