MPF.pm 8.9 KB

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