exiftool-vendored.pl 12.31.0 → 12.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/LICENSE +10 -3
  2. package/bin/Changes +130 -4
  3. package/bin/MANIFEST +3 -0
  4. package/bin/META.json +1 -1
  5. package/bin/META.yml +1 -1
  6. package/bin/README +45 -45
  7. package/bin/arg_files/xmp2exif.args +2 -1
  8. package/bin/exiftool +128 -96
  9. package/bin/lib/File/RandomAccess.pm +1 -1
  10. package/bin/lib/File/RandomAccess.pod +2 -2
  11. package/bin/lib/Image/ExifTool/AES.pm +1 -1
  12. package/bin/lib/Image/ExifTool/AFCP.pm +1 -1
  13. package/bin/lib/Image/ExifTool/AIFF.pm +1 -1
  14. package/bin/lib/Image/ExifTool/APE.pm +1 -1
  15. package/bin/lib/Image/ExifTool/APP12.pm +1 -1
  16. package/bin/lib/Image/ExifTool/ASF.pm +1 -1
  17. package/bin/lib/Image/ExifTool/Apple.pm +1 -1
  18. package/bin/lib/Image/ExifTool/Audible.pm +1 -1
  19. package/bin/lib/Image/ExifTool/BMP.pm +1 -1
  20. package/bin/lib/Image/ExifTool/BPG.pm +1 -1
  21. package/bin/lib/Image/ExifTool/BZZ.pm +1 -1
  22. package/bin/lib/Image/ExifTool/BigTIFF.pm +1 -1
  23. package/bin/lib/Image/ExifTool/BuildTagLookup.pm +17 -5
  24. package/bin/lib/Image/ExifTool/CBOR.pm +331 -0
  25. package/bin/lib/Image/ExifTool/Canon.pm +171 -13
  26. package/bin/lib/Image/ExifTool/CanonCustom.pm +13 -3
  27. package/bin/lib/Image/ExifTool/CanonRaw.pm +1 -1
  28. package/bin/lib/Image/ExifTool/CanonVRD.pm +1 -1
  29. package/bin/lib/Image/ExifTool/CaptureOne.pm +1 -1
  30. package/bin/lib/Image/ExifTool/Casio.pm +1 -1
  31. package/bin/lib/Image/ExifTool/Charset.pm +3 -1
  32. package/bin/lib/Image/ExifTool/DICOM.pm +1 -1
  33. package/bin/lib/Image/ExifTool/DJI.pm +1 -1
  34. package/bin/lib/Image/ExifTool/DNG.pm +1 -1
  35. package/bin/lib/Image/ExifTool/DPX.pm +1 -1
  36. package/bin/lib/Image/ExifTool/DV.pm +1 -1
  37. package/bin/lib/Image/ExifTool/DarwinCore.pm +3 -3
  38. package/bin/lib/Image/ExifTool/DjVu.pm +1 -1
  39. package/bin/lib/Image/ExifTool/EXE.pm +1 -1
  40. package/bin/lib/Image/ExifTool/Exif.pm +118 -4
  41. package/bin/lib/Image/ExifTool/FITS.pm +1 -1
  42. package/bin/lib/Image/ExifTool/FLAC.pm +1 -1
  43. package/bin/lib/Image/ExifTool/FLIF.pm +1 -1
  44. package/bin/lib/Image/ExifTool/FLIR.pm +48 -11
  45. package/bin/lib/Image/ExifTool/Fixup.pm +1 -1
  46. package/bin/lib/Image/ExifTool/Flash.pm +1 -1
  47. package/bin/lib/Image/ExifTool/FlashPix.pm +1 -1
  48. package/bin/lib/Image/ExifTool/Font.pm +1 -1
  49. package/bin/lib/Image/ExifTool/FotoStation.pm +1 -1
  50. package/bin/lib/Image/ExifTool/FujiFilm.pm +1 -1
  51. package/bin/lib/Image/ExifTool/GE.pm +1 -1
  52. package/bin/lib/Image/ExifTool/GIF.pm +6 -2
  53. package/bin/lib/Image/ExifTool/GIMP.pm +1 -1
  54. package/bin/lib/Image/ExifTool/GPS.pm +15 -11
  55. package/bin/lib/Image/ExifTool/GeoTiff.pm +1 -1
  56. package/bin/lib/Image/ExifTool/Geotag.pm +14 -3
  57. package/bin/lib/Image/ExifTool/GoPro.pm +1 -1
  58. package/bin/lib/Image/ExifTool/H264.pm +1 -1
  59. package/bin/lib/Image/ExifTool/HP.pm +1 -1
  60. package/bin/lib/Image/ExifTool/HTML.pm +1 -1
  61. package/bin/lib/Image/ExifTool/HtmlDump.pm +1 -1
  62. package/bin/lib/Image/ExifTool/ICC_Profile.pm +97 -5
  63. package/bin/lib/Image/ExifTool/ID3.pm +1 -1
  64. package/bin/lib/Image/ExifTool/IPTC.pm +1 -1
  65. package/bin/lib/Image/ExifTool/ISO.pm +1 -1
  66. package/bin/lib/Image/ExifTool/ITC.pm +1 -1
  67. package/bin/lib/Image/ExifTool/Import.pm +1 -1
  68. package/bin/lib/Image/ExifTool/InDesign.pm +1 -1
  69. package/bin/lib/Image/ExifTool/JPEG.pm +6 -2
  70. package/bin/lib/Image/ExifTool/JPEGDigest.pm +1 -1
  71. package/bin/lib/Image/ExifTool/JSON.pm +8 -4
  72. package/bin/lib/Image/ExifTool/JVC.pm +1 -1
  73. package/bin/lib/Image/ExifTool/Jpeg2000.pm +155 -25
  74. package/bin/lib/Image/ExifTool/Kodak.pm +1 -1
  75. package/bin/lib/Image/ExifTool/KyoceraRaw.pm +1 -1
  76. package/bin/lib/Image/ExifTool/LIF.pm +1 -1
  77. package/bin/lib/Image/ExifTool/LNK.pm +1 -1
  78. package/bin/lib/Image/ExifTool/Lang/cs.pm +1 -1
  79. package/bin/lib/Image/ExifTool/Lang/de.pm +1 -1
  80. package/bin/lib/Image/ExifTool/Lang/en_ca.pm +1 -1
  81. package/bin/lib/Image/ExifTool/Lang/en_gb.pm +1 -1
  82. package/bin/lib/Image/ExifTool/Lang/es.pm +1 -1
  83. package/bin/lib/Image/ExifTool/Lang/fi.pm +1 -1
  84. package/bin/lib/Image/ExifTool/Lang/fr.pm +1 -1
  85. package/bin/lib/Image/ExifTool/Lang/it.pm +1 -1
  86. package/bin/lib/Image/ExifTool/Lang/ja.pm +1 -1
  87. package/bin/lib/Image/ExifTool/Lang/ko.pm +1 -1
  88. package/bin/lib/Image/ExifTool/Lang/nl.pm +1 -1
  89. package/bin/lib/Image/ExifTool/Lang/pl.pm +1 -1
  90. package/bin/lib/Image/ExifTool/Lang/ru.pm +1 -1
  91. package/bin/lib/Image/ExifTool/Lang/sv.pm +1 -1
  92. package/bin/lib/Image/ExifTool/Lang/tr.pm +1 -1
  93. package/bin/lib/Image/ExifTool/Lang/zh_cn.pm +1 -1
  94. package/bin/lib/Image/ExifTool/Lang/zh_tw.pm +1 -1
  95. package/bin/lib/Image/ExifTool/Leaf.pm +1 -1
  96. package/bin/lib/Image/ExifTool/Lytro.pm +1 -1
  97. package/bin/lib/Image/ExifTool/M2TS.pm +1 -1
  98. package/bin/lib/Image/ExifTool/MIE.pm +1 -1
  99. package/bin/lib/Image/ExifTool/MIEUnits.pod +1 -1
  100. package/bin/lib/Image/ExifTool/MIFF.pm +1 -1
  101. package/bin/lib/Image/ExifTool/MNG.pm +1 -1
  102. package/bin/lib/Image/ExifTool/MOI.pm +1 -1
  103. package/bin/lib/Image/ExifTool/MPC.pm +1 -1
  104. package/bin/lib/Image/ExifTool/MPEG.pm +1 -1
  105. package/bin/lib/Image/ExifTool/MPF.pm +1 -1
  106. package/bin/lib/Image/ExifTool/MRC.pm +1 -1
  107. package/bin/lib/Image/ExifTool/MWG.pm +1 -1
  108. package/bin/lib/Image/ExifTool/MXF.pm +1 -1
  109. package/bin/lib/Image/ExifTool/MacOS.pm +3 -3
  110. package/bin/lib/Image/ExifTool/MakerNotes.pm +1 -1
  111. package/bin/lib/Image/ExifTool/Matroska.pm +9 -5
  112. package/bin/lib/Image/ExifTool/Microsoft.pm +1 -1
  113. package/bin/lib/Image/ExifTool/Minolta.pm +1 -1
  114. package/bin/lib/Image/ExifTool/MinoltaRaw.pm +1 -1
  115. package/bin/lib/Image/ExifTool/Motorola.pm +1 -1
  116. package/bin/lib/Image/ExifTool/Nikon.pm +1895 -74
  117. package/bin/lib/Image/ExifTool/NikonCapture.pm +1 -1
  118. package/bin/lib/Image/ExifTool/NikonCustom.pm +523 -6
  119. package/bin/lib/Image/ExifTool/NikonSettings.pm +150 -87
  120. package/bin/lib/Image/ExifTool/Nintendo.pm +1 -1
  121. package/bin/lib/Image/ExifTool/OOXML.pm +1 -1
  122. package/bin/lib/Image/ExifTool/Ogg.pm +1 -1
  123. package/bin/lib/Image/ExifTool/Olympus.pm +6 -2
  124. package/bin/lib/Image/ExifTool/OpenEXR.pm +5 -3
  125. package/bin/lib/Image/ExifTool/Opus.pm +1 -1
  126. package/bin/lib/Image/ExifTool/Other.pm +1 -1
  127. package/bin/lib/Image/ExifTool/PCX.pm +1 -1
  128. package/bin/lib/Image/ExifTool/PDF.pm +6 -4
  129. package/bin/lib/Image/ExifTool/PGF.pm +1 -1
  130. package/bin/lib/Image/ExifTool/PICT.pm +1 -1
  131. package/bin/lib/Image/ExifTool/PLIST.pm +1 -1
  132. package/bin/lib/Image/ExifTool/PLUS.pm +1 -1
  133. package/bin/lib/Image/ExifTool/PNG.pm +29 -8
  134. package/bin/lib/Image/ExifTool/PPM.pm +1 -1
  135. package/bin/lib/Image/ExifTool/PSP.pm +1 -1
  136. package/bin/lib/Image/ExifTool/Palm.pm +1 -1
  137. package/bin/lib/Image/ExifTool/Panasonic.pm +3 -3
  138. package/bin/lib/Image/ExifTool/PanasonicRaw.pm +1 -1
  139. package/bin/lib/Image/ExifTool/Parrot.pm +1 -1
  140. package/bin/lib/Image/ExifTool/Pentax.pm +4 -2
  141. package/bin/lib/Image/ExifTool/PhaseOne.pm +1 -1
  142. package/bin/lib/Image/ExifTool/PhotoCD.pm +1 -1
  143. package/bin/lib/Image/ExifTool/PhotoMechanic.pm +1 -1
  144. package/bin/lib/Image/ExifTool/Photoshop.pm +1 -1
  145. package/bin/lib/Image/ExifTool/PostScript.pm +1 -1
  146. package/bin/lib/Image/ExifTool/PrintIM.pm +1 -1
  147. package/bin/lib/Image/ExifTool/Qualcomm.pm +1 -1
  148. package/bin/lib/Image/ExifTool/QuickTime.pm +25 -4
  149. package/bin/lib/Image/ExifTool/QuickTimeStream.pl +125 -81
  150. package/bin/lib/Image/ExifTool/README +9 -2
  151. package/bin/lib/Image/ExifTool/RIFF.pm +1 -1
  152. package/bin/lib/Image/ExifTool/RSRC.pm +1 -1
  153. package/bin/lib/Image/ExifTool/RTF.pm +1 -1
  154. package/bin/lib/Image/ExifTool/Radiance.pm +1 -1
  155. package/bin/lib/Image/ExifTool/Rawzor.pm +1 -1
  156. package/bin/lib/Image/ExifTool/Real.pm +1 -1
  157. package/bin/lib/Image/ExifTool/Reconyx.pm +1 -1
  158. package/bin/lib/Image/ExifTool/Red.pm +1 -1
  159. package/bin/lib/Image/ExifTool/Ricoh.pm +1 -1
  160. package/bin/lib/Image/ExifTool/Samsung.pm +1 -1
  161. package/bin/lib/Image/ExifTool/Sanyo.pm +1 -1
  162. package/bin/lib/Image/ExifTool/Scalado.pm +1 -1
  163. package/bin/lib/Image/ExifTool/Shift.pl +3 -1
  164. package/bin/lib/Image/ExifTool/Shortcuts.pm +1 -1
  165. package/bin/lib/Image/ExifTool/Sigma.pm +1 -1
  166. package/bin/lib/Image/ExifTool/SigmaRaw.pm +1 -1
  167. package/bin/lib/Image/ExifTool/Sony.pm +34 -14
  168. package/bin/lib/Image/ExifTool/SonyIDC.pm +1 -1
  169. package/bin/lib/Image/ExifTool/Stim.pm +1 -1
  170. package/bin/lib/Image/ExifTool/TagInfoXML.pm +11 -6
  171. package/bin/lib/Image/ExifTool/TagLookup.pm +6589 -5877
  172. package/bin/lib/Image/ExifTool/TagNames.pod +1681 -65
  173. package/bin/lib/Image/ExifTool/Text.pm +1 -1
  174. package/bin/lib/Image/ExifTool/Theora.pm +1 -1
  175. package/bin/lib/Image/ExifTool/Torrent.pm +1 -1
  176. package/bin/lib/Image/ExifTool/Unknown.pm +1 -1
  177. package/bin/lib/Image/ExifTool/VCard.pm +1 -1
  178. package/bin/lib/Image/ExifTool/Validate.pm +1 -1
  179. package/bin/lib/Image/ExifTool/Vorbis.pm +1 -1
  180. package/bin/lib/Image/ExifTool/WTV.pm +1 -1
  181. package/bin/lib/Image/ExifTool/WriteCanonRaw.pl +1 -1
  182. package/bin/lib/Image/ExifTool/WriteExif.pl +1 -1
  183. package/bin/lib/Image/ExifTool/WriteIPTC.pl +1 -1
  184. package/bin/lib/Image/ExifTool/WritePDF.pl +1 -1
  185. package/bin/lib/Image/ExifTool/WritePNG.pl +30 -10
  186. package/bin/lib/Image/ExifTool/WritePhotoshop.pl +1 -1
  187. package/bin/lib/Image/ExifTool/WritePostScript.pl +1 -1
  188. package/bin/lib/Image/ExifTool/WriteQuickTime.pl +12 -1
  189. package/bin/lib/Image/ExifTool/WriteXMP.pl +11 -12
  190. package/bin/lib/Image/ExifTool/Writer.pl +56 -10
  191. package/bin/lib/Image/ExifTool/XMP.pm +164 -52
  192. package/bin/lib/Image/ExifTool/XMP2.pl +6 -3
  193. package/bin/lib/Image/ExifTool/XMPStruct.pl +4 -2
  194. package/bin/lib/Image/ExifTool/ZIP.pm +10 -2
  195. package/bin/lib/Image/ExifTool/ZISRAW.pm +1 -1
  196. package/bin/lib/Image/ExifTool/iWork.pm +1 -1
  197. package/bin/lib/Image/ExifTool.pm +98 -23
  198. package/bin/lib/Image/ExifTool.pod +76 -67
  199. package/bin/perl-Image-ExifTool.spec +43 -43
  200. package/bin/pp_build_exe.args +6 -5
  201. package/package.json +3 -3
@@ -35,7 +35,7 @@ use Image::ExifTool::Sony;
35
35
  use Image::ExifTool::Validate;
36
36
  use Image::ExifTool::MacOS;
37
37
 
38
- $VERSION = '3.45';
38
+ $VERSION = '3.47';
39
39
  @ISA = qw(Exporter);
40
40
 
41
41
  sub NumbersFirst($$);
@@ -68,6 +68,7 @@ my %tweakOrder = (
68
68
  IPTC => 'Exif', # put IPTC after EXIF,
69
69
  GPS => 'XMP', # etc...
70
70
  Composite => 'Extra',
71
+ CBOR => 'JSON',
71
72
  GeoTiff => 'GPS',
72
73
  CanonVRD=> 'CanonCustom',
73
74
  DJI => 'Casio',
@@ -459,7 +460,7 @@ According to the specification, integer-format QuickTime date/time tags
459
460
  should be stored as UTC. Unfortunately, digital cameras often store local
460
461
  time values instead (presumably because they don't know the time zone). For
461
462
  this reason, by default ExifTool does not assume a time zone for these
462
- values. However, if the L<QuickTimeUTC|../ExifTool.html#QuickTimeUTC> API option is set, then ExifTool will
463
+ values. However, if the API L<QuickTimeUTC|../ExifTool.html#QuickTimeUTC> option is set, then ExifTool will
463
464
  assume these values are properly stored as UTC, and will convert them to
464
465
  local time when extracting.
465
466
 
@@ -468,6 +469,11 @@ the PrintConv option is enabled and no time zone is specified. This is
468
469
  because Apple software may display crazy values if the time zone is missing
469
470
  for some tags.
470
471
 
472
+ By default ExifTool will remove null padding from some QuickTime containers
473
+ in Canon CR3 files when writing, but the
474
+ L<QuickTimePad|../ExifTool.html#QuickTimePad> option may be used to preserve
475
+ the original size by padding with nulls if necessary.
476
+
471
477
  See
472
478
  L<https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/>
473
479
  for the official specification.
@@ -663,7 +669,7 @@ L<Image::ExifTool::BuildTagLookup|Image::ExifTool::BuildTagLookup>.
663
669
 
664
670
  ~head1 AUTHOR
665
671
 
666
- Copyright 2003-2021, Phil Harvey (philharvey66 at gmail.com)
672
+ Copyright 2003-2022, Phil Harvey (philharvey66 at gmail.com)
667
673
 
668
674
  This library is free software; you can redistribute it and/or modify it
669
675
  under the same terms as Perl itself.
@@ -751,7 +757,7 @@ sub new
751
757
  my (%tagNameInfo, %id, %longID, %longName, %shortName, %tableNum,
752
758
  %tagLookup, %tagExists, %noLookup, %tableWritable, %sepTable, %case,
753
759
  %structs, %compositeModules, %isPlugin, %flattened, %structLookup,
754
- @writePseudo);
760
+ @writePseudo, %dupXmpTag);
755
761
  $self->{TAG_NAME_INFO} = \%tagNameInfo;
756
762
  $self->{ID_LOOKUP} = \%id;
757
763
  $self->{LONG_ID} = \%longID;
@@ -899,6 +905,12 @@ TagID: foreach $tagID (@keys) {
899
905
  foreach (@grps) {
900
906
  warn "Group name starts with 'ID-' for $short $name\n" if /^ID-/i;
901
907
  }
908
+ if ($isXMP and not $$tagInfo{Avoid} and not $$tagInfo{Struct} and
909
+ ($$tagInfo{Writable} or $$table{WRITABLE}))
910
+ {
911
+ $dupXmpTag{$name} and warn "Duplicate writable XMP tag $name\n";
912
+ $dupXmpTag{$name} = 1;
913
+ }
902
914
  # validate Name (must not start with a digit or else XML output will not be valid;
903
915
  # must not start with a dash or exiftool command line may get confused)
904
916
  if ($name !~ /^[_A-Za-z][-\w]+$/ and
@@ -2750,7 +2762,7 @@ Returned list of writable pseudo tags.
2750
2762
 
2751
2763
  =head1 AUTHOR
2752
2764
 
2753
- Copyright 2003-2021, Phil Harvey (philharvey66 at gmail.com)
2765
+ Copyright 2003-2022, Phil Harvey (philharvey66 at gmail.com)
2754
2766
 
2755
2767
  This library is free software; you can redistribute it and/or modify it
2756
2768
  under the same terms as Perl itself.
@@ -0,0 +1,331 @@
1
+ #------------------------------------------------------------------------------
2
+ # File: CBOR.pm
3
+ #
4
+ # Description: Read CBOR format metadata
5
+ #
6
+ # Revisions: 2021-09-30 - P. Harvey Created
7
+ #
8
+ # References: 1) https://c2pa.org/public-draft/
9
+ # 2) https://datatracker.ietf.org/doc/html/rfc7049
10
+ #------------------------------------------------------------------------------
11
+
12
+ package Image::ExifTool::CBOR;
13
+ use strict;
14
+ use vars qw($VERSION);
15
+ use Image::ExifTool qw(:DataAccess :Utils);
16
+ use Image::ExifTool::JSON;
17
+
18
+ $VERSION = '1.01';
19
+
20
+ sub ProcessCBOR($$$);
21
+ sub ReadCBORValue($$$$);
22
+
23
+ # optional CBOR type code
24
+ my %cborType6 = (
25
+ 0 => 'date/time string',
26
+ 1 => 'epoch-based date/time',
27
+ 2 => 'positive bignum',
28
+ 3 => 'negative bignum',
29
+ 4 => 'decimal fraction',
30
+ 5 => 'bigfloat',
31
+ 21 => 'expected base64url encoding',
32
+ 22 => 'expected base64 encoding',
33
+ 23 => 'expected base16 encoding',
34
+ 24 => 'encoded CBOR data',
35
+ 32 => 'URI',
36
+ 33 => 'base64url',
37
+ 34 => 'base64',
38
+ 35 => 'regular expression',
39
+ 36 => 'MIME message',
40
+ 55799 => 'CBOR magic number',
41
+ );
42
+
43
+ my %cborType7 = (
44
+ 20 => 'False',
45
+ 21 => 'True',
46
+ 22 => 'null',
47
+ 23 => 'undef',
48
+ );
49
+
50
+ %Image::ExifTool::CBOR::Main = (
51
+ GROUPS => { 0 => 'JUMBF', 1 => 'CBOR', 2 => 'Other' },
52
+ VARS => { NO_ID => 1 },
53
+ PROCESS_PROC => \&ProcessCBOR,
54
+ NOTES => q{
55
+ The tags below are extracted from CBOR (Concise Binary Object
56
+ Representation) metadata. The C2PA specification uses this format for some
57
+ metadata. As well as these tags, ExifTool will read any existing tags.
58
+ },
59
+ 'dc:title' => 'Title',
60
+ 'dc:format' => 'Format',
61
+ # my sample file has the following 2 tags in CBOR, but they should be JSON
62
+ authorName => { Name => 'AuthorName', Groups => { 2 => 'Author' } },
63
+ authorIdentifier=> { Name => 'AuthorIdentifier', Groups => { 2 => 'Author' } },
64
+ documentID => { },
65
+ instanceID => { },
66
+ thumbnailHash => { List => 1 },
67
+ thumbnailUrl => { Name => 'ThumbnailURL' },
68
+ relationship => { }
69
+ );
70
+
71
+ #------------------------------------------------------------------------------
72
+ # Read CBOR value
73
+ # Inputs: 0) ExifTool ref, 1) data ref, 2) position in data, 3) data end
74
+ # Returns: 0) value, 1) error string, 2) new data position
75
+ sub ReadCBORValue($$$$)
76
+ {
77
+ my ($et, $dataPt, $pos, $end) = @_;
78
+ return(undef, 'Truncated CBOR data', $pos) if $pos >= $end;
79
+ my $verbose = $$et{OPTIONS}{Verbose};
80
+ my $indent = $$et{INDENT};
81
+ my $dumpStart = $pos;
82
+ my $fmt = Get8u($dataPt, $pos++);
83
+ my $dat = $fmt & 0x1f;
84
+ my ($num, $val, $err, $size);
85
+ $fmt >>= 5;
86
+ if ($dat < 24) {
87
+ $num = $dat;
88
+ } elsif ($dat == 31) { # indefinite count (not used in C2PA)
89
+ $num = -1; # (flag for indefinite count)
90
+ $et->VPrint(1, "$$et{INDENT} (indefinite count):\n");
91
+ } else {
92
+ my $format = { 24 => 'int8u', 25 => 'int16u', 26 => 'int32u', 27 => 'int64u' }->{$dat};
93
+ return(undef, "Invalid CBOR integer type $dat", $pos) unless $format;
94
+ $size = Image::ExifTool::FormatSize($format);
95
+ return(undef, 'Truncated CBOR integer value', $pos) if $pos + $size > $end;
96
+ $num = ReadValue($dataPt, $pos, $format, 1, $size);
97
+ $pos += $size;
98
+ }
99
+ my $pre = '';
100
+ if (defined $$et{cbor_pre} and $fmt != 6) {
101
+ $pre = $$et{cbor_pre};
102
+ delete $$et{cbor_pre};
103
+ }
104
+ if ($fmt == 0) { # positive integer
105
+ $val = $num;
106
+ $et->VPrint(1, "$$et{INDENT} ${pre}int+: $val\n");
107
+ } elsif ($fmt == 1) { # negative integer
108
+ $val = -1 * $num;
109
+ $et->VPrint(1, "$$et{INDENT} ${pre}int-: $val\n");
110
+ } elsif ($fmt == 2 or $fmt == 3) { # byte/UTF8 string
111
+ return(undef, 'Truncated CBOR string value', $pos) if $pos + $num > $end;
112
+ if ($num < 0) { # (should not happen in C2PA)
113
+ my $string = '';
114
+ $$et{INDENT} .= ' ';
115
+ for (;;) {
116
+ ($val, $err, $pos) = ReadCBORValue($et, $dataPt, $pos, $end);
117
+ return(undef, $err, $pos) if $err;
118
+ last if not defined $val; # hit the break?
119
+ # (note: strictly we should be checking that this was a string we read)
120
+ $string .= $val;
121
+ }
122
+ $$et{INDENT} = $indent;
123
+ return($string, undef, $pos); # return concatenated byte/text string
124
+ } else {
125
+ $val = substr($$dataPt, $pos, $num);
126
+ }
127
+ $pos += $num;
128
+ if ($fmt == 2) { # (byte string)
129
+ $et->VPrint(1, "$$et{INDENT} ${pre}byte: <binary data ".length($val)." bytes>\n");
130
+ my $dat = $val;
131
+ $val = \$dat; # use scalar reference for binary data
132
+ } else { # (text string)
133
+ $val = $et->Decode($val, 'UTF8');
134
+ $et->VPrint(1, "$$et{INDENT} ${pre}text: '${val}'\n");
135
+ }
136
+ } elsif ($fmt == 4 or $fmt == 5) { # list/hash
137
+ if ($fmt == 4) {
138
+ $et->VPrint(1, "$$et{INDENT} ${pre}list: <$num elements>\n");
139
+ } else {
140
+ $et->VPrint(1, "$$et{INDENT} ${pre}hash: <$num pairs>\n");
141
+ $num *= 2;
142
+ }
143
+ $$et{INDENT} .= ' ';
144
+ my $i = 0;
145
+ my @list;
146
+ Image::ExifTool::HexDump($dataPt, $pos - $dumpStart,
147
+ Start => $dumpStart,
148
+ DataPos => $$et{cbor_datapos},
149
+ Prefix => $$et{INDENT},
150
+ ) if $verbose > 2;
151
+ while ($num) {
152
+ $$et{cbor_pre} = "$i) ";
153
+ if ($fmt == 4) {
154
+ ++$i;
155
+ } elsif ($num & 0x01) {
156
+ $$et{cbor_pre} = ' ' x length($$et{cbor_pre});
157
+ ++$i;
158
+ }
159
+ ($val, $err, $pos) = ReadCBORValue($et, $dataPt, $pos, $end);
160
+ return(undef, $err, $pos) if $err;
161
+ if (not defined $val) {
162
+ return(undef, 'Unexpected list terminator', $pos) unless $num < 0;
163
+ last;
164
+ }
165
+ push @list, $val;
166
+ --$num;
167
+ }
168
+ $dumpStart = $pos;
169
+ $$et{INDENT} = $indent;
170
+ if ($fmt == 5) {
171
+ my ($i, @keys);
172
+ my %hash = ( _ordered_keys_ => \@keys );
173
+ for ($i=0; $i<@list-1; $i+=2) {
174
+ $hash{$list[$i]} = $list[$i+1];
175
+ push @keys, $list[$i]; # save ordered list of keys
176
+ }
177
+ $val = \%hash;
178
+ } else {
179
+ $val = \@list;
180
+ }
181
+ } elsif ($fmt == 6) { # optional tag
182
+ if ($verbose) {
183
+ my $str = "$num (" . ($cborType6{$num} || 'unknown') . ')';
184
+ my $spc = $$et{cbor_pre} ? (' ' x length $$et{cbor_pre}) : '';
185
+ $et->VPrint(1, "$$et{INDENT} $spc<CBOR optional type $str>\n");
186
+ Image::ExifTool::HexDump($dataPt, $pos - $dumpStart,
187
+ Start => $dumpStart,
188
+ DataPos => $$et{cbor_datapos},
189
+ Prefix => $$et{INDENT} . ' ',
190
+ ) if $verbose > 2;
191
+ }
192
+ # read next value (note: in the case of multiple tags,
193
+ # this nesting will apply the tags in the correct order)
194
+ ($val, $err, $pos) = ReadCBORValue($et, $dataPt, $pos, $end);
195
+ $dumpStart = $pos;
196
+ # convert some values according to the optional tag number (untested)
197
+ if ($num == 0 and not ref $val) { # date/time string
198
+ require Image::ExifTool::XMP;
199
+ $val = Image::ExifTool::XMP::ConvertXMPDate($val);
200
+ } elsif ($num == 1 and not ref $val) { # epoch-based date/time
201
+ if (Image::ExifTool::IsFloat($val)) {
202
+ my $dec = ($val == int($val)) ? undef : 6;
203
+ $val = Image::ExifTool::ConvertUnixTime($val, 1, $dec);
204
+ }
205
+ } elsif (($num == 2 or $num == 3) and ref($val) eq 'SCALAR') { # pos/neg bignum
206
+ my $big = 0;
207
+ $big = 256 * $big + Get8u($val,$_) foreach 0..(length($$val) - 1);
208
+ $val = $num==2 ? $big : -$big;
209
+ } elsif (($num == 4 or $num == 5) and # decimal fraction or bigfloat
210
+ ref($val) eq 'ARRAY' and @$val == 2 and
211
+ Image::ExifTool::IsInt($$val[0]) and Image::ExifTool::IsInt($$val[1]))
212
+ {
213
+ $val = $$val[1] * ($num == 4 ? 10 : 2) ** $$val[0];
214
+ }
215
+ } elsif ($fmt == 7) {
216
+ if ($dat == 31) {
217
+ undef $val; # "break" = end of indefinite array/hash (not used in C2PA)
218
+ } elsif ($dat < 24) {
219
+ $val = $cborType7{$num};
220
+ $val = "Unknown ($val)" unless defined $val;
221
+ } elsif ($dat == 25) { # half-precision float
222
+ my $exp = ($num >> 10) & 0x1f;
223
+ my $mant = $num & 0x3ff;
224
+ if ($exp == 0) {
225
+ $val = $mant ** -24;
226
+ $val *= -1 if $num & 0x8000;
227
+ } elsif (exp != 31) {
228
+ $val = ($mant + 1024) ** ($exp - 25);
229
+ $val *= -1 if $num & 0x8000;
230
+ } else {
231
+ $val = $mant == 0 ? '<inf>' : '<nan>';
232
+ }
233
+ } elsif ($dat == 26) { # float
234
+ $val = GetFloat($dataPt, $pos - $size);
235
+ } elsif ($dat == 27) { # double
236
+ $val = GetDouble($dataPt, $pos - $size);
237
+ } else {
238
+ return(undef, "Invalid CBOR type 7 variant $num", $pos);
239
+ }
240
+ $et->VPrint(1, "$$et{INDENT} ${pre}typ7: ".(defined $val ? $val : '<break>')."\n");
241
+ } else {
242
+ return(undef, "Unknown CBOR format $fmt", $pos);
243
+ }
244
+ Image::ExifTool::HexDump($dataPt, $pos - $dumpStart,
245
+ Start => $dumpStart,
246
+ DataPos => $$et{cbor_datapos},
247
+ Prefix => $$et{INDENT} . ' ',
248
+ MaxLen => $verbose < 5 ? ($verbose == 3 ? 96 : 2048) : undef,
249
+ ) if $verbose > 2;
250
+ return($val, $err, $pos);
251
+ }
252
+
253
+ #------------------------------------------------------------------------------
254
+ # Read CBOR box
255
+ # Inputs: 0) ExifTool ref, 1) dirInfo ref, 2) tag table ref
256
+ # Returns: 1 on success
257
+ sub ProcessCBOR($$$)
258
+ {
259
+ my ($et, $dirInfo, $tagTablePtr) = @_;
260
+ my $dataPt = $$dirInfo{DataPt};
261
+ my $pos = $$dirInfo{DirStart};
262
+ my $end = $pos + $$dirInfo{DirLen};
263
+ my ($val, $err, $tag, $i);
264
+
265
+ $et->VerboseDir('CBOR', undef, $$dirInfo{DirLen});
266
+
267
+ $$et{cbor_datapos} = $$dirInfo{DataPos} + $$dirInfo{Base};
268
+
269
+ while ($pos < $end) {
270
+ ($val, $err, $pos) = ReadCBORValue($et, $dataPt, $pos, $end);
271
+ $err and $et->Warn($err), last;
272
+ if (ref $val eq 'HASH') {
273
+ foreach $tag (@{$$val{_ordered_keys_}}) {
274
+ Image::ExifTool::JSON::ProcessTag($et, $tagTablePtr, $tag, $$val{$tag});
275
+ }
276
+ } elsif (ref $val eq 'ARRAY') {
277
+ for ($i=0; $i<@$val; ++$i) {
278
+ Image::ExifTool::JSON::ProcessTag($et, $tagTablePtr, "Item$i", $$val[$i]);
279
+ }
280
+ } elsif ($val eq '0') {
281
+ $et->VPrint(1, "$$et{INDENT} <CBOR end>\n");
282
+ last; # (treat as padding)
283
+ } else {
284
+ $et->VPrint(1, "$$et{INDENT} Unknown value: $val\n");
285
+ }
286
+ }
287
+ return 1;
288
+ }
289
+
290
+ 1; # end
291
+
292
+ __END__
293
+
294
+ =head1 NAME
295
+
296
+ Image::ExifTool::CBOR - Read CBOR format metadata
297
+
298
+ =head1 SYNOPSIS
299
+
300
+ This module is used by Image::ExifTool
301
+
302
+ =head1 DESCRIPTION
303
+
304
+ This module contains definitions required by Image::ExifTool read Concise
305
+ Binary Object Representation (CBOR) formatted metadata, used by the C2PA
306
+ specification.
307
+
308
+ =head1 AUTHOR
309
+
310
+ Copyright 2003-2022, Phil Harvey (philharvey66 at gmail.com)
311
+
312
+ This library is free software; you can redistribute it and/or modify it
313
+ under the same terms as Perl itself.
314
+
315
+ =head1 REFERENCES
316
+
317
+ =over 4
318
+
319
+ =item L<https://c2pa.org/public-draft/>
320
+
321
+ =item L<https://datatracker.ietf.org/doc/html/rfc7049>
322
+
323
+ =back
324
+
325
+ =head1 SEE ALSO
326
+
327
+ L<Image::ExifTool::TagNames/CBOR Tags>,
328
+ L<Image::ExifTool(3pm)|Image::ExifTool>
329
+
330
+ =cut
331
+