exifreader 4.53.0 → 4.55.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 (100) hide show
  1. package/README.md +404 -33
  2. package/bin/analyze.js +139 -9
  3. package/bin/build-pages.js +21 -35
  4. package/bin/cli.js +81 -13
  5. package/bin/generate-tag-modules.js +287 -0
  6. package/dist/exif-reader.js +1 -1
  7. package/dist/exif-reader.js.map +1 -1
  8. package/exif-reader.d.ts +213 -38
  9. package/package.json +71 -11
  10. package/src/base64-image.js +27 -0
  11. package/src/composable/brand.js +10 -0
  12. package/src/composable/composition-tag-filter.js +97 -0
  13. package/src/composable/composition.js +195 -0
  14. package/src/composable/core.d.ts +148 -0
  15. package/src/composable/core.js +526 -0
  16. package/src/composable/exif-block-reader.js +197 -0
  17. package/src/composable/formats/avif.js +19 -0
  18. package/src/composable/formats/gif.js +28 -0
  19. package/src/composable/formats/heic.js +19 -0
  20. package/src/composable/formats/iso-bmff-file-reader.js +14 -0
  21. package/src/composable/formats/jpeg.js +55 -0
  22. package/src/composable/formats/jxl.js +30 -0
  23. package/src/composable/formats/png.js +187 -0
  24. package/src/composable/formats/tiff.js +18 -0
  25. package/src/composable/formats/webp.js +28 -0
  26. package/src/composable/formats/xml.js +18 -0
  27. package/src/composable/formats.d.ts +17 -0
  28. package/src/composable/formats.js +17 -0
  29. package/src/composable/group-helpers.js +129 -0
  30. package/src/composable/groups/canon.js +26 -0
  31. package/src/composable/groups/composite.js +43 -0
  32. package/src/composable/groups/exif.js +48 -0
  33. package/src/composable/groups/gps.js +75 -0
  34. package/src/composable/groups/icc.js +52 -0
  35. package/src/composable/groups/iptc.js +86 -0
  36. package/src/composable/groups/maker-notes.js +21 -0
  37. package/src/composable/groups/mpf.js +25 -0
  38. package/src/composable/groups/pentax.js +34 -0
  39. package/src/composable/groups/photoshop.js +18 -0
  40. package/src/composable/groups/thumbnail.js +131 -0
  41. package/src/composable/groups/xmp.js +118 -0
  42. package/src/composable/groups.d.ts +20 -0
  43. package/src/composable/groups.js +105 -0
  44. package/src/composable/iptc-block-reader.js +44 -0
  45. package/src/composable/read-view.js +165 -0
  46. package/src/composable/tag-binding-name.js +17 -0
  47. package/src/composable/tags/exif.d.ts +295 -0
  48. package/src/composable/tags/exif.js +396 -0
  49. package/src/composable/tags/iptc.d.ts +84 -0
  50. package/src/composable/tags/iptc.js +109 -0
  51. package/src/composable/value-budget.js +24 -0
  52. package/src/composite.js +2 -2
  53. package/src/decompression.js +60 -0
  54. package/src/dom-parser.js +5 -6
  55. package/src/engine.js +332 -0
  56. package/src/errors.js +8 -2
  57. package/src/exif-reader.d.ts +8 -0
  58. package/src/exif-reader.js +118 -1121
  59. package/src/file-loaders.js +74 -1
  60. package/src/file-tags.js +9 -9
  61. package/src/image-header-avif.js +7 -8
  62. package/src/image-header-gif.js +9 -10
  63. package/src/image-header-heic.js +7 -8
  64. package/src/image-header-iso-bmff.js +71 -92
  65. package/src/image-header-jpeg.js +60 -59
  66. package/src/image-header-jxl.js +59 -65
  67. package/src/image-header-png.js +199 -76
  68. package/src/image-header-tiff.js +7 -4
  69. package/src/image-header-webp.js +29 -35
  70. package/src/image-header.js +25 -59
  71. package/src/iptc-tag-names-descriptions.js +334 -0
  72. package/src/iptc-tag-names.js +50 -306
  73. package/src/iptc-tags.js +41 -27
  74. package/src/jfif-tags.js +9 -9
  75. package/src/load-auto.js +2 -2
  76. package/src/loadview-pipeline.js +197 -498
  77. package/src/mpf-tags.js +10 -7
  78. package/src/node-require.js +15 -2
  79. package/src/png-text-tags.js +90 -327
  80. package/src/tag-filter-config.js +24 -15
  81. package/src/tag-filter.js +67 -3
  82. package/src/tag-names-0th-ifd-descriptions.js +232 -0
  83. package/src/tag-names-0th-ifd.js +49 -173
  84. package/src/tag-names-common.js +263 -211
  85. package/src/tag-names-exif-ifd-descriptions.js +249 -0
  86. package/src/tag-names-exif-ifd.js +55 -187
  87. package/src/tag-names-gps-ifd-descriptions.js +156 -0
  88. package/src/tag-names-gps-ifd.js +39 -146
  89. package/src/tag-names-utils.js +33 -10
  90. package/src/tags-helpers.js +14 -24
  91. package/src/tags.js +23 -11
  92. package/src/thumbnail.js +7 -5
  93. package/src/types.js +2 -0
  94. package/src/unsupported-format-error.js +21 -0
  95. package/src/utils.js +64 -119
  96. package/src/writer/exif-tag-table.js +321 -0
  97. package/src/xml.js +12 -15
  98. package/src/xmp-tag-names.js +42 -21
  99. package/src/xmp-tags.js +9 -10
  100. package/webpack.config.js +1 -1
@@ -8,7 +8,7 @@
8
8
  */
9
9
  /* global Buffer */
10
10
 
11
- import {dataUriToBuffer, isArrayBufferViewLike} from './utils.js';
11
+ import {getByteString, getHexDigitValue, isArrayBufferViewLike} from './utils.js';
12
12
  import NodeRequire from './node-require.js';
13
13
 
14
14
  export const HTTP_STATUS_OK = 200;
@@ -59,6 +59,79 @@ export function loadFile(filename, options) {
59
59
  return readLocalFileRange(filename, range).then((r) => r.buffer);
60
60
  }
61
61
 
62
+ export function dataUriToBuffer(dataUri) {
63
+ const commaIndex = dataUri.indexOf(',');
64
+ const header = dataUri.substring(0, commaIndex);
65
+ const data = dataUri.substring(commaIndex + 1);
66
+
67
+ if (header.indexOf(';base64') !== -1) {
68
+ const base64 = percentDecodeBase64Payload(data);
69
+ if (typeof atob !== 'undefined') {
70
+ return binaryStringToArrayBuffer(atob(base64));
71
+ }
72
+ if (typeof Buffer === 'undefined') {
73
+ return undefined;
74
+ }
75
+ if (typeof Buffer.from !== 'undefined') {
76
+ return Buffer.from(base64, 'base64');
77
+ }
78
+ return new Buffer(base64, 'base64');
79
+ }
80
+
81
+ return percentDecodeToBytes(data).buffer;
82
+ }
83
+
84
+ // WHATWG data: URL processing percent-decodes the body before the forgiving-base64 decode.
85
+ // A non-ASCII payload can never be valid base64, so it goes to the decoder unchanged.
86
+ function percentDecodeBase64Payload(data) {
87
+ if (data.indexOf('%') === -1 || /[\u0080-\uffff]/.test(data)) {
88
+ return data;
89
+ }
90
+ return getByteString(percentDecodeToBytes(data));
91
+ }
92
+
93
+ function binaryStringToArrayBuffer(string) {
94
+ const bytes = new Uint8Array(string.length);
95
+ for (let i = 0; i < string.length; i++) {
96
+ bytes[i] = string.charCodeAt(i);
97
+ }
98
+ return bytes.buffer;
99
+ }
100
+
101
+ // WHATWG URL "string percent-decode" (used for data: URLs, RFC 2397): UTF-8 encode, then each %XX is one byte.
102
+ function percentDecodeToBytes(string) {
103
+ const byteString = /[\u0080-\uffff]/.test(string) ? unescape(encodeURIComponent(string)) : string;
104
+ const bytes = new Uint8Array(byteString.length - 2 * countPercentEscapes(byteString));
105
+ let byteIndex = 0;
106
+ for (let i = 0; i < byteString.length; i++) {
107
+ if (isPercentEscape(byteString, i)) {
108
+ bytes[byteIndex++] = getHexDigitValue(byteString.charCodeAt(i + 1)) * 16 + getHexDigitValue(byteString.charCodeAt(i + 2));
109
+ i += 2;
110
+ } else {
111
+ bytes[byteIndex++] = byteString.charCodeAt(i);
112
+ }
113
+ }
114
+ return bytes;
115
+ }
116
+
117
+ function countPercentEscapes(byteString) {
118
+ let count = 0;
119
+ for (let i = 0; i < byteString.length; i++) {
120
+ if (isPercentEscape(byteString, i)) {
121
+ count++;
122
+ i += 2;
123
+ }
124
+ }
125
+ return count;
126
+ }
127
+
128
+ function isPercentEscape(byteString, index) {
129
+ return byteString.charCodeAt(index) === 0x25
130
+ && index + 2 < byteString.length
131
+ && getHexDigitValue(byteString.charCodeAt(index + 1)) !== -1
132
+ && getHexDigitValue(byteString.charCodeAt(index + 2)) !== -1;
133
+ }
134
+
62
135
  /**
63
136
  * Browser `File` equivalent of `loadFile`. Used by the numeric-`length`
64
137
  * code path in `load()`.
package/src/file-tags.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
4
 
5
- import Types from './types.js';
5
+ import {getShortAt, getByteAt} from './types.js';
6
6
 
7
7
  export default {
8
8
  read
@@ -22,7 +22,7 @@ function read(dataView, fileDataOffset) {
22
22
 
23
23
  function getLength(dataView, fileDataOffset) {
24
24
  // The declared length is untrusted, so bound it by the bytes present.
25
- return Math.min(Types.getShortAt(dataView, fileDataOffset), dataView.byteLength - fileDataOffset);
25
+ return Math.min(getShortAt(dataView, fileDataOffset), dataView.byteLength - fileDataOffset);
26
26
  }
27
27
 
28
28
  function getDataPrecision(dataView, fileDataOffset, length) {
@@ -33,7 +33,7 @@ function getDataPrecision(dataView, fileDataOffset, length) {
33
33
  return undefined;
34
34
  }
35
35
 
36
- const value = Types.getByteAt(dataView, fileDataOffset + OFFSET);
36
+ const value = getByteAt(dataView, fileDataOffset + OFFSET);
37
37
  return {
38
38
  value,
39
39
  description: '' + value
@@ -48,7 +48,7 @@ function getImageHeight(dataView, fileDataOffset, length) {
48
48
  return undefined;
49
49
  }
50
50
 
51
- const value = Types.getShortAt(dataView, fileDataOffset + OFFSET);
51
+ const value = getShortAt(dataView, fileDataOffset + OFFSET);
52
52
  return {
53
53
  value,
54
54
  description: `${value}px`
@@ -63,7 +63,7 @@ function getImageWidth(dataView, fileDataOffset, length) {
63
63
  return undefined;
64
64
  }
65
65
 
66
- const value = Types.getShortAt(dataView, fileDataOffset + OFFSET);
66
+ const value = getShortAt(dataView, fileDataOffset + OFFSET);
67
67
  return {
68
68
  value,
69
69
  description: `${value}px`
@@ -78,7 +78,7 @@ function getNumberOfColorComponents(dataView, fileDataOffset, length) {
78
78
  return undefined;
79
79
  }
80
80
 
81
- const value = Types.getByteAt(dataView, fileDataOffset + OFFSET);
81
+ const value = getByteAt(dataView, fileDataOffset + OFFSET);
82
82
  return {
83
83
  value,
84
84
  description: '' + value
@@ -98,9 +98,9 @@ function getSubsampling(dataView, fileDataOffset, numberOfColorComponents, lengt
98
98
  for (let i = 0; i < numberOfColorComponents; i++) {
99
99
  const componentOffset = fileDataOffset + OFFSET + i * 3;
100
100
  components.push([
101
- Types.getByteAt(dataView, componentOffset),
102
- Types.getByteAt(dataView, componentOffset + 1),
103
- Types.getByteAt(dataView, componentOffset + 2)
101
+ getByteAt(dataView, componentOffset),
102
+ getByteAt(dataView, componentOffset + 1),
103
+ getByteAt(dataView, componentOffset + 2)
104
104
  ]);
105
105
  }
106
106
 
@@ -25,14 +25,13 @@ function isAvifFile(dataView) {
25
25
  }
26
26
 
27
27
  /**
28
- * Finds the offsets of an AVIF file in the provided data view.
28
+ * Finds the metadata blocks of an AVIF file in the provided data view.
29
29
  *
30
- * @param {DataView} dataView The data view to find offsets in.
31
- * @param {Array<Object>=} metadataBlocks Optional out-array. Forwarded to
32
- * the shared ISO-BMFF findOffsets.
33
- * @returns {Object} TIFF header offset, XMP chunks, ICC chunks, and whether
34
- * any were found.
30
+ * @param {DataView} dataView The data view to find blocks in.
31
+ * @param {Array<Object>=} ranges Optional out-array. Forwarded to the shared
32
+ * ISO-BMFF findOffsets.
33
+ * @returns {Array<Object>} The blocks the shared ISO-BMFF findOffsets reports.
35
34
  */
36
- function findAvifOffsets(dataView, metadataBlocks) {
37
- return findOffsets(dataView, metadataBlocks);
35
+ function findAvifOffsets(dataView, ranges) {
36
+ return findOffsets(dataView, ranges);
38
37
  }
@@ -2,7 +2,7 @@
2
2
  * License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
4
 
5
- import {getStringFromDataView, pushMetadataBlock} from './utils.js';
5
+ import {getStringFromDataView, pushRange} from './utils.js';
6
6
 
7
7
  export default {
8
8
  isGifFile,
@@ -26,16 +26,15 @@ function isGifFile(dataView) {
26
26
  }
27
27
 
28
28
  /**
29
- * Finds the GIF logical screen descriptor offset.
29
+ * Reports the GIF header, whose logical screen descriptor sits at offset 0.
30
30
  *
31
31
  * @param {DataView} _dataView The data view (unused).
32
- * @param {Array<Object>=} metadataBlocks Optional out-array. When provided,
33
- * receives one `gif` block covering the GIF header bytes.
34
- * @returns {{gifHeaderOffset: number}}
32
+ * @param {Array<Object>=} ranges Optional out-array. When provided, receives
33
+ * one span covering the GIF header bytes, linked to the gif block.
34
+ * @returns {Array<Object>} One gif block.
35
35
  */
36
- function findOffsets(_dataView, metadataBlocks) {
37
- pushMetadataBlock(metadataBlocks, 'gif', 0, GIF_HEADER_SIZE);
38
- return {
39
- gifHeaderOffset: 0
40
- };
36
+ function findOffsets(_dataView, ranges) {
37
+ const block = {kind: 'gif', dataOffset: 0};
38
+ pushRange(ranges, block, 0, GIF_HEADER_SIZE);
39
+ return [block];
41
40
  }
@@ -22,14 +22,13 @@ function isHeicFile(dataView) {
22
22
  }
23
23
 
24
24
  /**
25
- * Finds the offsets of a HEIC file in the provided data view.
25
+ * Finds the metadata blocks of a HEIC file in the provided data view.
26
26
  *
27
- * @param {DataView} dataView The data view to find offsets in.
28
- * @param {Array<Object>=} metadataBlocks Optional out-array. Forwarded to
29
- * the shared ISO-BMFF findOffsets.
30
- * @returns {Object} TIFF header offset, XMP chunks, ICC chunks, and whether
31
- * any were found.
27
+ * @param {DataView} dataView The data view to find blocks in.
28
+ * @param {Array<Object>=} ranges Optional out-array. Forwarded to the shared
29
+ * ISO-BMFF findOffsets.
30
+ * @returns {Array<Object>} The blocks the shared ISO-BMFF findOffsets reports.
32
31
  */
33
- function findHeicOffsets(dataView, metadataBlocks) {
34
- return findOffsets(dataView, metadataBlocks);
32
+ function findHeicOffsets(dataView, ranges) {
33
+ return findOffsets(dataView, ranges);
35
34
  }
@@ -2,7 +2,7 @@
2
2
  * License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
4
 
5
- import {getNullTerminatedStringFromDataView, getStringFromDataView, pushMetadataBlock} from './utils.js';
5
+ import {getNullTerminatedStringFromDataView, getStringFromDataView, pushRange} from './utils.js';
6
6
  // import {get64BitValue} from './image-header-iso-bmff-utils.js';
7
7
  import {parseItemLocationBox} from './image-header-iso-bmff-iloc.js';
8
8
  import {hasBytes} from './image-header-iso-bmff-utils.js';
@@ -219,47 +219,42 @@ function hasEmptyHighBits(dataView, offset) {
219
219
  }
220
220
 
221
221
  /**
222
- * @typedef {Object} Offsets
223
- * @property {number} tiffHeaderOffset
224
- * @property {Array<Object>} xmpChunks
225
- * @property {Array<Object>} iccChunks
226
- * @property {boolean} hasAppMarkers
227
- * @property {DataView=} exifDataView Synthetic buffer when an Exif item
228
- * spans multiple extents. tiffHeaderOffset then indexes into this view
229
- * rather than the source dataView.
230
- * @property {DataView=} xmpDataView Synthetic buffer when an XMP item
231
- * spans multiple extents. xmpChunks then references this view.
232
- * @property {number=} imageDimensionsOffset Offset of the primary item's
233
- * dimensions, the width and height fields of its ispe property; absent
234
- * when it cannot be resolved.
235
- * @property {number=} pixelInformationOffset Offset of the num_channels
236
- * field of the primary item's pixi property; the per-channel bit depths
237
- * follow it. Absent when it cannot be resolved.
238
- */
239
-
240
- /**
241
- * Finds the offsets of ISO-BMFF-structured data in the provided data view.
222
+ * Finds the metadata blocks of ISO-BMFF-structured data in the provided data view.
242
223
  *
243
- * @param {DataView} dataView The data view to find offsets in.
244
- * @param {Array<Object>=} metadataBlocks Optional out-array. When provided,
245
- * receives one block per iloc extent (Exif/XMP) at the resolved file
246
- * offset (cm 0 direct, cm 1 via the idat box) plus the ICC profile
247
- * bytes. cm 2 (item_offset) items are skipped.
248
- * @returns {Offsets} The TIFF header offset, XMP chunks, ICC chunks,
249
- * whether any of those were found, and the primary image's dimensions
250
- * and pixel information offsets.
224
+ * The blocks, in this order when present: `exif` with `tiffHeaderOffset`
225
+ * (and `dataView`, a synthetic buffer the offset indexes into, when the Exif
226
+ * item spans several extents), `xmp` with `chunks` (and `dataView` likewise),
227
+ * `icc` with the first colr profile as its one chunk, and `isoBmffFile` with
228
+ * the primary item's `imageDimensionsOffset` (the width and height fields of
229
+ * its ispe property) and `pixelInformationOffset` (the num_channels field of
230
+ * its pixi property), each present only when it resolves.
231
+ *
232
+ * @param {DataView} dataView The data view to find blocks in.
233
+ * @param {Array<Object>=} ranges Optional out-array. When provided, receives
234
+ * one `{block, start, end}` span per iloc extent (Exif/XMP) at the
235
+ * resolved file offset (cm 0 direct, cm 1 via the idat box) plus the
236
+ * ICC profile bytes, linked to the block of that item even when the
237
+ * item's extents cannot be assembled and no block is returned for it.
238
+ * cm 2 (item_offset) items are skipped.
239
+ * @returns {Array<Object>} The blocks.
251
240
  */
252
- export function findOffsets(dataView, metadataBlocks) {
241
+ export function findOffsets(dataView, ranges) {
242
+ const blocks = [];
253
243
  const metaBox = findMetaBox(dataView);
254
- const offsets = findMetadataOffsets(dataView, metaBox, metadataBlocks);
255
- const {imageDimensionsOffset, pixelInformationOffset} = findPrimaryItemPropertyOffsets(dataView, metaBox);
256
- if (imageDimensionsOffset !== undefined) {
257
- offsets.imageDimensionsOffset = imageDimensionsOffset;
244
+ if (metaBox) {
245
+ warnIfUnsupportedFieldSize(metaBox);
246
+ pushDefinedBlock(blocks, findExifBlock(dataView, metaBox, ranges));
247
+ pushDefinedBlock(blocks, findXmpBlock(dataView, metaBox, ranges));
248
+ pushDefinedBlock(blocks, findIccBlock(metaBox, ranges));
258
249
  }
259
- if (pixelInformationOffset !== undefined) {
260
- offsets.pixelInformationOffset = pixelInformationOffset;
250
+ pushDefinedBlock(blocks, findPrimaryItemPropertyBlock(dataView, metaBox));
251
+ return blocks;
252
+ }
253
+
254
+ function pushDefinedBlock(blocks, block) {
255
+ if (block !== undefined) {
256
+ blocks.push(block);
261
257
  }
262
- return offsets;
263
258
  }
264
259
 
265
260
  function findMetaBox(dataView) {
@@ -285,34 +280,6 @@ function findMetaBox(dataView) {
285
280
  return undefined;
286
281
  }
287
282
 
288
- function findMetadataOffsets(dataView, metaBox, metadataBlocks) {
289
- const offsets = {};
290
-
291
- if (!metaBox) {
292
- return {hasAppMarkers: false};
293
- }
294
-
295
- warnIfUnsupportedFieldSize(metaBox);
296
-
297
- const exif = findExifOffset(dataView, metaBox, metadataBlocks);
298
- if (exif !== undefined) {
299
- offsets.tiffHeaderOffset = exif.tiffHeaderOffset;
300
- if (exif.dataView !== undefined) {
301
- offsets.exifDataView = exif.dataView;
302
- }
303
- }
304
- const xmp = findXmpChunks(dataView, metaBox, metadataBlocks);
305
- if (xmp !== undefined) {
306
- offsets.xmpChunks = xmp.chunks;
307
- if (xmp.dataView !== undefined) {
308
- offsets.xmpDataView = xmp.dataView;
309
- }
310
- }
311
- offsets.iccChunks = findIccChunks(metaBox, metadataBlocks);
312
- offsets.hasAppMarkers = (offsets.tiffHeaderOffset !== undefined) || (offsets.xmpChunks !== undefined) || (offsets.iccChunks !== undefined);
313
- return offsets;
314
- }
315
-
316
283
  function warnIfUnsupportedFieldSize(metaBox) {
317
284
  const ilocBox = metaBox.subBoxes.find((box) => box.type === 'iloc');
318
285
  if (ilocBox && ilocBox.uses64BitFields) {
@@ -321,35 +288,37 @@ function warnIfUnsupportedFieldSize(metaBox) {
321
288
  }
322
289
  }
323
290
 
324
- function findExifOffset(dataView, metaBox, metadataBlocks) {
291
+ function findExifBlock(dataView, metaBox, ranges) {
325
292
  try {
326
293
  const exifItemId = findIinfExifItemId(metaBox).itemId;
327
294
  const ilocItem = findIlocItem(metaBox, exifItemId);
328
295
  warnIfUnsupportedConstructionMethod(ilocItem);
329
296
  const idatContentOffset = findIdatContentOffset(metaBox);
330
- pushIlocExtentBlocks(metadataBlocks, ilocItem, 'exif', idatContentOffset);
297
+ // The spans belong to the item whether or not it can be read.
298
+ const block = {kind: 'exif'};
299
+ pushIlocExtentRanges(ranges, ilocItem, block, idatContentOffset);
331
300
  if (ilocItem.extents.length > 1) {
332
301
  const assembled = assembleExtents(dataView, ilocItem, idatContentOffset);
333
302
  if (assembled === undefined) {
334
303
  return undefined;
335
304
  }
336
- return {
337
- tiffHeaderOffset: getTiffHeaderOffset(assembled, 0),
338
- dataView: assembled,
339
- };
305
+ block.tiffHeaderOffset = getTiffHeaderOffset(assembled, 0);
306
+ block.dataView = assembled;
307
+ return block;
340
308
  }
341
309
  const exifOffset = resolveExtentToFileOffset(ilocItem, ilocItem.extents[0], idatContentOffset);
342
310
  if (exifOffset === undefined) {
343
311
  return undefined;
344
312
  }
345
- return {tiffHeaderOffset: getTiffHeaderOffset(dataView, exifOffset)};
313
+ block.tiffHeaderOffset = getTiffHeaderOffset(dataView, exifOffset);
314
+ return block;
346
315
  } catch (error) {
347
316
  return undefined;
348
317
  }
349
318
  }
350
319
 
351
- function pushIlocExtentBlocks(metadataBlocks, ilocItem, blockType, idatContentOffset) {
352
- if (!metadataBlocks) {
320
+ function pushIlocExtentRanges(ranges, ilocItem, block, idatContentOffset) {
321
+ if (!ranges) {
353
322
  return;
354
323
  }
355
324
  for (let i = 0; i < ilocItem.extents.length; i++) {
@@ -358,7 +327,7 @@ function pushIlocExtentBlocks(metadataBlocks, ilocItem, blockType, idatContentOf
358
327
  if (start === undefined) {
359
328
  continue;
360
329
  }
361
- pushMetadataBlock(metadataBlocks, blockType, start, start + extent.extentLength);
330
+ pushRange(ranges, block, start, start + extent.extentLength);
362
331
  }
363
332
  }
364
333
 
@@ -437,36 +406,30 @@ export function getTiffHeaderOffset(dataView, exifOffset) {
437
406
  return exifOffset + TIFF_HEADER_OFFSET_SIZE + dataView.getUint32(exifOffset);
438
407
  }
439
408
 
440
- function findXmpChunks(dataView, metaBox, metadataBlocks) {
409
+ function findXmpBlock(dataView, metaBox, ranges) {
441
410
  try {
442
411
  const xmpItemId = findIinfXmpItemId(metaBox).itemId;
443
412
  const ilocItem = findIlocItem(metaBox, xmpItemId);
444
413
  warnIfUnsupportedConstructionMethod(ilocItem);
445
414
  const idatContentOffset = findIdatContentOffset(metaBox);
446
- pushIlocExtentBlocks(metadataBlocks, ilocItem, 'xmp', idatContentOffset);
415
+ const block = {kind: 'xmp'};
416
+ pushIlocExtentRanges(ranges, ilocItem, block, idatContentOffset);
447
417
  if (ilocItem.extents.length > 1) {
448
418
  const assembled = assembleExtents(dataView, ilocItem, idatContentOffset);
449
419
  if (assembled === undefined) {
450
420
  return undefined;
451
421
  }
452
- return {
453
- chunks: [{dataOffset: 0, length: assembled.byteLength}],
454
- dataView: assembled,
455
- };
422
+ block.chunks = [{dataOffset: 0, length: assembled.byteLength}];
423
+ block.dataView = assembled;
424
+ return block;
456
425
  }
457
426
  const ilocItemExtent = ilocItem.extents[0];
458
427
  const dataOffset = resolveExtentToFileOffset(ilocItem, ilocItemExtent, idatContentOffset);
459
428
  if (dataOffset === undefined) {
460
429
  return undefined;
461
430
  }
462
- return {
463
- chunks: [
464
- {
465
- dataOffset,
466
- length: ilocItemExtent.extentLength,
467
- }
468
- ],
469
- };
431
+ block.chunks = [{dataOffset, length: ilocItemExtent.extentLength}];
432
+ return block;
470
433
  } catch (error) {
471
434
  return undefined;
472
435
  }
@@ -477,7 +440,7 @@ function findIinfXmpItemId(metaBox) {
477
440
  .itemInfos.find((itemInfo) => itemInfo.itemType === ITEM_INFO_TYPE_MIME && itemInfo.contentType === 'application/rdf+xml');
478
441
  }
479
442
 
480
- function findIccChunks(metaBox, metadataBlocks) {
443
+ function findIccBlock(metaBox, ranges) {
481
444
  // This finds the first ICC chunk, but there could be one for each image
482
445
  // that is embedded in the file. If it turns out we need to match the ICC
483
446
  // chunk to a specific image, we need to check the "ipma" in addition to the
@@ -488,8 +451,9 @@ function findIccChunks(metaBox, metadataBlocks) {
488
451
  .properties.find((box) => box.type === 'colr')
489
452
  .icc;
490
453
  if (icc) {
491
- pushMetadataBlock(metadataBlocks, 'icc', icc.offset, icc.offset + icc.length);
492
- return [icc];
454
+ const block = {kind: 'icc', chunks: [icc]};
455
+ pushRange(ranges, block, icc.offset, icc.offset + icc.length);
456
+ return block;
493
457
  }
494
458
  } catch (error) {
495
459
  // Let it pass through.
@@ -499,6 +463,21 @@ function findIccChunks(metaBox, metadataBlocks) {
499
463
 
500
464
  // Resolves meta > pitm (the primary item) through meta > iprp > ipma (its
501
465
  // property indexes) to the ispe and pixi among meta > iprp > ipco's children.
466
+ function findPrimaryItemPropertyBlock(dataView, metaBox) {
467
+ const {imageDimensionsOffset, pixelInformationOffset} = findPrimaryItemPropertyOffsets(dataView, metaBox);
468
+ if (imageDimensionsOffset === undefined && pixelInformationOffset === undefined) {
469
+ return undefined;
470
+ }
471
+ const block = {kind: 'isoBmffFile'};
472
+ if (imageDimensionsOffset !== undefined) {
473
+ block.imageDimensionsOffset = imageDimensionsOffset;
474
+ }
475
+ if (pixelInformationOffset !== undefined) {
476
+ block.pixelInformationOffset = pixelInformationOffset;
477
+ }
478
+ return block;
479
+ }
480
+
502
481
  function findPrimaryItemPropertyOffsets(dataView, metaBox) {
503
482
  // Every read below is bounded at parse time; the catch keeps a malformed
504
483
  // box from failing the whole file when that bounding is ever wrong.