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
@@ -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, addBlock, pushRange} from './utils.js';
6
6
  import ByteOrder from './byte-order.js';
7
7
  import {
8
8
  IFD_ENTRY_COUNT_LENGTH,
@@ -81,32 +81,38 @@ function isJpegFile(dataView) {
81
81
  }
82
82
 
83
83
  /**
84
- * Walks the JPEG APP/SOF markers and reports the offsets ExifReader needs.
84
+ * Walks the JPEG APP/SOF markers and reports the blocks ExifReader reads.
85
85
  *
86
- * @param {DataView} dataView The data view to find offsets in.
87
- * @param {Array<Object>=} metadataBlocks Optional out-array. When provided,
88
- * receives one block per recognized segment (Exif/XMP/IPTC/ICC/MPF/JFIF
89
- * and SOF for file tags) and gets `truncated` set to true if the loop
90
- * never saw the SOS marker.
91
- * @returns {Object} Per-segment offsets plus `hasAppMarkers`.
86
+ * Duplicates resolve inside the walk: the best-scored APP1 Exif segment wins,
87
+ * the last SOF0 (or, without one, the last SOF2), JFIF, IPTC and MPF segment
88
+ * wins, and the XMP and ICC segments form one block each with their chunks
89
+ * capped at MAX_XMP_CHUNKS and MAX_ICC_CHUNKS.
90
+ *
91
+ * @param {DataView} dataView The data view to find blocks in.
92
+ * @param {Array<Object>=} ranges Optional out-array. When provided, receives
93
+ * one `{block, start, end}` span per recognized segment, capped by
94
+ * neither chunk cap, and gets `truncated` set to true if the loop never
95
+ * saw the SOS marker.
96
+ * @returns {Array<Object>} The blocks, in the order their first segment was met.
92
97
  */
93
- function findJpegOffsets(dataView, metadataBlocks) {
98
+ function findJpegOffsets(dataView, ranges) {
99
+ const blocks = [];
94
100
  let appMarkerPosition = JPEG_ID_SIZE;
95
101
  let fieldLength;
96
102
  let sof0DataOffset;
97
- let sof2DataOffset;
98
- let jfifDataOffset;
99
- let tiffHeaderOffset;
100
- let iptcDataOffset;
101
- let xmpChunks;
102
- let iccChunks;
103
- let mpfDataOffset;
103
+ let fileBlock;
104
+ let jfifBlock;
105
+ let exifBlock;
106
+ let iptcBlock;
107
+ let xmpBlock;
108
+ let iccBlock;
109
+ let mpfBlock;
104
110
  let exifSegmentCount = 0;
105
111
  let bestExifSegment;
106
112
  let sawSos = false;
107
113
 
108
114
  while (appMarkerPosition + APP_ID_OFFSET + 5 <= dataView.byteLength) {
109
- let blockType;
115
+ let block;
110
116
  if (dataView.getUint16(appMarkerPosition) === SOS_MARKER) {
111
117
  // Reaching SOS means the metadata region is closed.
112
118
  sawSos = true;
@@ -114,15 +120,22 @@ function findJpegOffsets(dataView, metadataBlocks) {
114
120
  if (isSOF0Marker(dataView, appMarkerPosition)) {
115
121
  fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
116
122
  sof0DataOffset = appMarkerPosition + APP_MARKER_SIZE;
117
- blockType = 'file';
123
+ fileBlock = fileBlock || addBlock(blocks, {kind: 'file'});
124
+ fileBlock.dataOffset = sof0DataOffset;
125
+ block = fileBlock;
118
126
  } else if (isSOF2Marker(dataView, appMarkerPosition)) {
119
127
  fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
120
- sof2DataOffset = appMarkerPosition + APP_MARKER_SIZE;
121
- blockType = 'file';
128
+ fileBlock = fileBlock || addBlock(blocks, {kind: 'file'});
129
+ // A SOF0 segment wins over any SOF2 segment.
130
+ if (sof0DataOffset === undefined) {
131
+ fileBlock.dataOffset = appMarkerPosition + APP_MARKER_SIZE;
132
+ }
133
+ block = fileBlock;
122
134
  } else if (isApp0JfifMarker(dataView, appMarkerPosition)) {
123
135
  fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
124
- jfifDataOffset = appMarkerPosition + JFIF_DATA_OFFSET;
125
- blockType = 'jfif';
136
+ jfifBlock = jfifBlock || addBlock(blocks, {kind: 'jfif'});
137
+ jfifBlock.dataOffset = appMarkerPosition + JFIF_DATA_OFFSET;
138
+ block = jfifBlock;
126
139
  } else if (isApp1ExifMarker(dataView, appMarkerPosition)) {
127
140
  fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
128
141
  exifSegmentCount++;
@@ -163,48 +176,45 @@ function findJpegOffsets(dataView, metadataBlocks) {
163
176
  }
164
177
  }
165
178
 
166
- tiffHeaderOffset = bestExifSegment.tiffHeaderOffset;
167
- blockType = 'exif';
179
+ exifBlock = exifBlock || addBlock(blocks, {kind: 'exif'});
180
+ exifBlock.tiffHeaderOffset = bestExifSegment.tiffHeaderOffset;
181
+ block = exifBlock;
168
182
  } else if (isApp1XmpMarker(dataView, appMarkerPosition)) {
169
- if (!xmpChunks) {
170
- xmpChunks = [];
171
- }
183
+ xmpBlock = xmpBlock || addBlock(blocks, {kind: 'xmp', chunks: []});
172
184
  fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
173
- if (xmpChunks.length < MAX_XMP_CHUNKS) {
174
- xmpChunks.push(getXmpChunkDetails(appMarkerPosition, fieldLength));
185
+ if (xmpBlock.chunks.length < MAX_XMP_CHUNKS) {
186
+ xmpBlock.chunks.push(getXmpChunkDetails(appMarkerPosition, fieldLength));
175
187
  }
176
- blockType = 'xmp';
188
+ block = xmpBlock;
177
189
  } else if (isApp1ExtendedXmpMarker(dataView, appMarkerPosition)) {
178
- if (!xmpChunks) {
179
- xmpChunks = [];
180
- }
190
+ xmpBlock = xmpBlock || addBlock(blocks, {kind: 'xmp', chunks: []});
181
191
  fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
182
- if (xmpChunks.length < MAX_XMP_CHUNKS) {
183
- xmpChunks.push(getExtendedXmpChunkDetails(appMarkerPosition, fieldLength));
192
+ if (xmpBlock.chunks.length < MAX_XMP_CHUNKS) {
193
+ xmpBlock.chunks.push(getExtendedXmpChunkDetails(appMarkerPosition, fieldLength));
184
194
  }
185
- blockType = 'xmp';
195
+ block = xmpBlock;
186
196
  } else if (isApp13PhotoshopMarker(dataView, appMarkerPosition)) {
187
197
  fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
188
- iptcDataOffset = appMarkerPosition + IPTC_DATA_OFFSET;
189
- blockType = 'iptc';
198
+ iptcBlock = iptcBlock || addBlock(blocks, {kind: 'iptc'});
199
+ iptcBlock.dataOffset = appMarkerPosition + IPTC_DATA_OFFSET;
200
+ block = iptcBlock;
190
201
  } else if (isApp2ICCMarker(dataView, appMarkerPosition)) {
191
202
  fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
192
- if (!iccChunks) {
193
- iccChunks = [];
194
- }
195
- if (iccChunks.length < MAX_ICC_CHUNKS) {
203
+ iccBlock = iccBlock || addBlock(blocks, {kind: 'icc', chunks: []});
204
+ if (iccBlock.chunks.length < MAX_ICC_CHUNKS) {
196
205
  const iccDataOffset = appMarkerPosition + APP2_ICC_DATA_OFFSET;
197
206
  const iccDataLength = fieldLength - (APP2_ICC_DATA_OFFSET - APP_MARKER_SIZE);
198
207
 
199
208
  const iccChunkNumber = dataView.getUint8(appMarkerPosition + ICC_CHUNK_NUMBER_OFFSET);
200
209
  const iccChunksTotal = dataView.getUint8(appMarkerPosition + ICC_TOTAL_CHUNKS_OFFSET);
201
- iccChunks.push({offset: iccDataOffset, length: iccDataLength, chunkNumber: iccChunkNumber, chunksTotal: iccChunksTotal});
210
+ iccBlock.chunks.push({offset: iccDataOffset, length: iccDataLength, chunkNumber: iccChunkNumber, chunksTotal: iccChunksTotal});
202
211
  }
203
- blockType = 'icc';
212
+ block = iccBlock;
204
213
  } else if (isApp2MPFMarker(dataView, appMarkerPosition)) {
205
214
  fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
206
- mpfDataOffset = appMarkerPosition + MPF_DATA_OFFSET;
207
- blockType = 'mpf';
215
+ mpfBlock = mpfBlock || addBlock(blocks, {kind: 'mpf'});
216
+ mpfBlock.dataOffset = appMarkerPosition + MPF_DATA_OFFSET;
217
+ block = mpfBlock;
208
218
  } else if (isAppMarker(dataView, appMarkerPosition)) {
209
219
  fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
210
220
  } else if (isFillByte(dataView, appMarkerPosition)) {
@@ -213,7 +223,7 @@ function findJpegOffsets(dataView, metadataBlocks) {
213
223
  } else {
214
224
  break;
215
225
  }
216
- pushMetadataBlock(metadataBlocks, blockType, appMarkerPosition, appMarkerPosition + APP_MARKER_SIZE + fieldLength);
226
+ pushRange(ranges, block, appMarkerPosition, appMarkerPosition + APP_MARKER_SIZE + fieldLength);
217
227
  appMarkerPosition += APP_MARKER_SIZE + fieldLength;
218
228
  }
219
229
 
@@ -221,7 +231,7 @@ function findJpegOffsets(dataView, metadataBlocks) {
221
231
  warnAboutMultipleExifSegments(exifSegmentCount);
222
232
  }
223
233
 
224
- if (metadataBlocks) {
234
+ if (ranges) {
225
235
  // The while-condition requires +5 bytes to enter, so the SOS marker
226
236
  // can sit right at the boundary where the loop exits without
227
237
  // entering. Catch that here.
@@ -232,19 +242,10 @@ function findJpegOffsets(dataView, metadataBlocks) {
232
242
  }
233
243
  // The pipeline combines this with the per-block end <= byteLength
234
244
  // check to compute the overall `complete` flag.
235
- metadataBlocks.truncated = !sawSos;
245
+ ranges.truncated = !sawSos;
236
246
  }
237
247
 
238
- return {
239
- hasAppMarkers: appMarkerPosition > JPEG_ID_SIZE,
240
- fileDataOffset: sof0DataOffset || sof2DataOffset,
241
- jfifDataOffset,
242
- tiffHeaderOffset,
243
- iptcDataOffset,
244
- xmpChunks,
245
- iccChunks,
246
- mpfDataOffset
247
- };
248
+ return blocks;
248
249
  }
249
250
 
250
251
  function isSOF0Marker(dataView, appMarkerPosition) {
@@ -3,7 +3,7 @@
3
3
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
4
 
5
5
  import {getBoxLength, getTiffHeaderOffset, BOX_TYPE_OFFSET, BOX_MIN_LENGTH} from './image-header-iso-bmff.js';
6
- import {pushMetadataBlock} from './utils.js';
6
+ import {pushRange} from './utils.js';
7
7
 
8
8
  export default {
9
9
  isJxlFile,
@@ -66,34 +66,36 @@ function isJxlCodestream(dataView) {
66
66
  }
67
67
 
68
68
  /**
69
- * Walks the JPEG XL box list and reports the offsets ExifReader needs.
69
+ * Walks the JPEG XL box list and reports the blocks ExifReader reads.
70
70
  *
71
- * @param {DataView} dataView The data view to find offsets in.
72
- * @param {Array<Object>=} metadataBlocks Optional out-array. When provided,
73
- * receives one block per recognized box (Exif, xml, brob with Exif or
74
- * xml original type). The codestream box (`jxlc`/`jxlp`) does not emit
75
- * a block because it wraps the encoded image, not metadata.
76
- * @returns {Object} hasAppMarkers and the per-section offsets.
71
+ * An Exif box that holds its TIFF header offset wins over any brob(Exif) box,
72
+ * otherwise the first brob(Exif) is reported; the same goes for the xml box
73
+ * and brob(xml). The last Exif or xml box wins among its own kind. The
74
+ * `jxlFile` block points at the codestream: the first jxlc box, or the first
75
+ * jxlp box with sequence number 0. A bare codestream is only a `jxlFile`
76
+ * block at offset 0.
77
+ *
78
+ * @param {DataView} dataView The data view to find blocks in.
79
+ * @param {Array<Object>=} ranges Optional out-array. When provided, receives
80
+ * one `{block, start, end}` span per recognized box (Exif, xml, brob with
81
+ * Exif or xml original type), a brob box's span linked to its own block
82
+ * even when another box wins. The codestream box (`jxlc`/`jxlp`) gets no
83
+ * span because it wraps the encoded image, not metadata.
84
+ * @returns {Array<Object>} The blocks: exif, xmp and jxlFile, each when found.
77
85
  */
78
- function findJxlOffsets(dataView, metadataBlocks) {
86
+ function findJxlOffsets(dataView, ranges) {
87
+ const blocks = [];
79
88
  let offset = 0;
80
- let tiffHeaderOffset;
81
- let xmpChunks;
82
- let brobExifChunk;
83
- let brobXmpChunk;
84
- let jxlCodestreamOffset;
89
+ let exifBoxBlock;
90
+ let brobExifBlock;
91
+ let xmlBoxBlock;
92
+ let brobXmpBlock;
93
+ let jxlFileBlock;
85
94
 
86
95
  if (isJxlCodestream(dataView)) {
87
96
  // A bare codestream has no box structure, so the box walk below
88
97
  // would only ever misinterpret codestream bytes as box headers.
89
- return {
90
- hasAppMarkers: true,
91
- tiffHeaderOffset: undefined,
92
- xmpChunks: undefined,
93
- brobExifChunk: undefined,
94
- brobXmpChunk: undefined,
95
- jxlCodestreamOffset: 0,
96
- };
98
+ return [{kind: 'jxlFile', codestreamOffset: 0}];
97
99
  }
98
100
 
99
101
  while (offset + BOX_MIN_LENGTH <= dataView.byteLength) {
@@ -104,34 +106,40 @@ function findJxlOffsets(dataView, metadataBlocks) {
104
106
  const contentEnd = Math.min(offset + length, dataView.byteLength);
105
107
 
106
108
  const boxType = dataView.getUint32(offset + BOX_TYPE_OFFSET);
107
- let blockType;
109
+ let block;
108
110
 
109
111
  if (boxType === TYPE_EXIF) {
110
112
  if (contentOffset + EXIF_TIFF_HEADER_OFFSET_SIZE <= contentEnd) {
111
- tiffHeaderOffset = getTiffHeaderOffset(dataView, contentOffset);
113
+ exifBoxBlock = exifBoxBlock || {kind: 'exif'};
114
+ exifBoxBlock.tiffHeaderOffset = getTiffHeaderOffset(dataView, contentOffset);
115
+ block = exifBoxBlock;
116
+ } else {
117
+ // Too short to hold its TIFF header offset: listed, never read,
118
+ // and no bar to a brob(Exif) box.
119
+ block = {kind: 'exif'};
112
120
  }
113
- blockType = 'exif';
114
121
  }
115
122
 
116
123
  if (boxType === TYPE_XML) {
117
- xmpChunks = [{
124
+ xmlBoxBlock = xmlBoxBlock || {kind: 'xmp'};
125
+ xmlBoxBlock.chunks = [{
118
126
  dataOffset: contentOffset,
119
127
  length: length - (contentOffset - offset)
120
128
  }];
121
- blockType = 'xmp';
129
+ block = xmlBoxBlock;
122
130
  }
123
131
 
124
- if (boxType === TYPE_JXLC && jxlCodestreamOffset === undefined) {
125
- jxlCodestreamOffset = contentOffset;
126
- // No block emitted: the codestream box wraps the encoded image,
132
+ if (boxType === TYPE_JXLC && jxlFileBlock === undefined) {
133
+ jxlFileBlock = {kind: 'jxlFile', codestreamOffset: contentOffset};
134
+ // No span listed: the codestream box wraps the encoded image,
127
135
  // marking it would inflate metadataRange.end past pixel data.
128
136
  }
129
137
 
130
- if (boxType === TYPE_JXLP && jxlCodestreamOffset === undefined
138
+ if (boxType === TYPE_JXLP && jxlFileBlock === undefined
131
139
  && contentOffset + JXLP_SEQUENCE_NUMBER_SIZE <= contentEnd) {
132
140
  const sequenceNumber = dataView.getUint32(contentOffset) & 0x7FFFFFFF;
133
141
  if (sequenceNumber === 0) {
134
- jxlCodestreamOffset = contentOffset + JXLP_SEQUENCE_NUMBER_SIZE;
142
+ jxlFileBlock = {kind: 'jxlFile', codestreamOffset: contentOffset + JXLP_SEQUENCE_NUMBER_SIZE};
135
143
  // Same reason as TYPE_JXLC above.
136
144
  }
137
145
  }
@@ -141,47 +149,33 @@ function findJxlOffsets(dataView, metadataBlocks) {
141
149
  const compressedDataOffset = contentOffset + BROB_ORIGINAL_TYPE_SIZE;
142
150
  const compressedDataLength = length - (compressedDataOffset - offset);
143
151
 
144
- // Decouple block emission from parsing-source selection. A
145
- // brob(Exif) box must surface as an `exif` block even if a
146
- // plain Exif box already won the parsing race. The brob*Chunk
147
- // variables stay guarded to avoid double-parsing.
152
+ // Every brob box gets its own block for its span, but only the
153
+ // first of a kind can be the one read, and only when no plain box
154
+ // of that kind holds the data.
148
155
  if (originalType === TYPE_EXIF) {
149
- blockType = 'exif';
150
- if (tiffHeaderOffset === undefined && !brobExifChunk) {
151
- brobExifChunk = {
152
- dataOffset: compressedDataOffset,
153
- length: compressedDataLength
154
- };
155
- }
156
+ block = {kind: 'exif', compression: 'brotli', dataOffset: compressedDataOffset, length: compressedDataLength};
157
+ brobExifBlock = brobExifBlock || block;
156
158
  }
157
159
  if (originalType === TYPE_XML) {
158
- blockType = 'xmp';
159
- if (!xmpChunks && !brobXmpChunk) {
160
- brobXmpChunk = {
161
- dataOffset: compressedDataOffset,
162
- length: compressedDataLength
163
- };
164
- }
160
+ block = {kind: 'xmp', compression: 'brotli', dataOffset: compressedDataOffset, length: compressedDataLength};
161
+ brobXmpBlock = brobXmpBlock || block;
165
162
  }
166
163
  }
167
164
 
168
- pushMetadataBlock(metadataBlocks, blockType, offset, offset + length);
165
+ pushRange(ranges, block, offset, offset + length);
169
166
 
170
167
  offset += length;
171
168
  }
172
169
 
173
- const hasAppMarkers = tiffHeaderOffset !== undefined
174
- || xmpChunks !== undefined
175
- || brobExifChunk !== undefined
176
- || brobXmpChunk !== undefined
177
- || jxlCodestreamOffset !== undefined;
178
-
179
- return {
180
- hasAppMarkers,
181
- tiffHeaderOffset,
182
- xmpChunks,
183
- brobExifChunk,
184
- brobXmpChunk,
185
- jxlCodestreamOffset
186
- };
170
+ pushDefinedBlock(blocks, exifBoxBlock || brobExifBlock);
171
+ pushDefinedBlock(blocks, xmlBoxBlock || brobXmpBlock);
172
+ pushDefinedBlock(blocks, jxlFileBlock);
173
+
174
+ return blocks;
175
+ }
176
+
177
+ function pushDefinedBlock(blocks, block) {
178
+ if (block !== undefined) {
179
+ blocks.push(block);
180
+ }
187
181
  }