exifreader 4.53.0 → 4.54.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.
- package/README.md +6 -6
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/package.json +1 -1
- package/src/base64-image.js +27 -0
- package/src/dom-parser.js +5 -6
- package/src/engine.js +388 -0
- package/src/exif-reader.js +540 -892
- package/src/image-header-avif.js +7 -8
- package/src/image-header-gif.js +9 -10
- package/src/image-header-heic.js +7 -8
- package/src/image-header-iso-bmff.js +71 -92
- package/src/image-header-jpeg.js +60 -59
- package/src/image-header-jxl.js +59 -65
- package/src/image-header-png.js +199 -76
- package/src/image-header-tiff.js +7 -4
- package/src/image-header-webp.js +29 -35
- package/src/image-header.js +22 -22
- package/src/loadview-pipeline.js +285 -446
- package/src/mpf-tags.js +10 -7
- package/src/png-text-tags.js +88 -327
- package/src/tag-filter.js +52 -0
- package/src/tag-names-0th-ifd.js +2 -2
- package/src/tag-names-utils.js +5 -7
- package/src/tags-helpers.js +8 -22
- package/src/tags.js +23 -11
- package/src/thumbnail.js +7 -5
- package/src/utils.js +42 -34
- package/src/writer/exif-tag-table.js +321 -0
- package/src/xml.js +12 -15
- package/src/xmp-tags.js +9 -10
package/src/image-header-avif.js
CHANGED
|
@@ -25,14 +25,13 @@ function isAvifFile(dataView) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* Finds the
|
|
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
|
|
31
|
-
* @param {Array<Object>=}
|
|
32
|
-
*
|
|
33
|
-
* @returns {Object}
|
|
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,
|
|
37
|
-
return findOffsets(dataView,
|
|
35
|
+
function findAvifOffsets(dataView, ranges) {
|
|
36
|
+
return findOffsets(dataView, ranges);
|
|
38
37
|
}
|
package/src/image-header-gif.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 {getStringFromDataView,
|
|
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
|
-
*
|
|
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>=}
|
|
33
|
-
*
|
|
34
|
-
* @returns {
|
|
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,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
}
|
package/src/image-header-heic.js
CHANGED
|
@@ -22,14 +22,13 @@ function isHeicFile(dataView) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* Finds the
|
|
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
|
|
28
|
-
* @param {Array<Object>=}
|
|
29
|
-
*
|
|
30
|
-
* @returns {Object}
|
|
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,
|
|
34
|
-
return findOffsets(dataView,
|
|
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,
|
|
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
|
-
*
|
|
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
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
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,
|
|
241
|
+
export function findOffsets(dataView, ranges) {
|
|
242
|
+
const blocks = [];
|
|
253
243
|
const metaBox = findMetaBox(dataView);
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
-
|
|
260
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
337
|
-
|
|
338
|
-
|
|
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
|
-
|
|
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
|
|
352
|
-
if (!
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
453
|
-
|
|
454
|
-
|
|
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
|
-
|
|
463
|
-
|
|
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
|
|
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
|
-
|
|
492
|
-
|
|
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.
|
package/src/image-header-jpeg.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 {getStringFromDataView,
|
|
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
|
|
84
|
+
* Walks the JPEG APP/SOF markers and reports the blocks ExifReader reads.
|
|
85
85
|
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* @
|
|
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,
|
|
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
|
|
98
|
-
let
|
|
99
|
-
let
|
|
100
|
-
let
|
|
101
|
-
let
|
|
102
|
-
let
|
|
103
|
-
let
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
121
|
-
|
|
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
|
-
|
|
125
|
-
|
|
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
|
-
|
|
167
|
-
|
|
179
|
+
exifBlock = exifBlock || addBlock(blocks, {kind: 'exif'});
|
|
180
|
+
exifBlock.tiffHeaderOffset = bestExifSegment.tiffHeaderOffset;
|
|
181
|
+
block = exifBlock;
|
|
168
182
|
} else if (isApp1XmpMarker(dataView, appMarkerPosition)) {
|
|
169
|
-
|
|
170
|
-
xmpChunks = [];
|
|
171
|
-
}
|
|
183
|
+
xmpBlock = xmpBlock || addBlock(blocks, {kind: 'xmp', chunks: []});
|
|
172
184
|
fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
|
|
173
|
-
if (
|
|
174
|
-
|
|
185
|
+
if (xmpBlock.chunks.length < MAX_XMP_CHUNKS) {
|
|
186
|
+
xmpBlock.chunks.push(getXmpChunkDetails(appMarkerPosition, fieldLength));
|
|
175
187
|
}
|
|
176
|
-
|
|
188
|
+
block = xmpBlock;
|
|
177
189
|
} else if (isApp1ExtendedXmpMarker(dataView, appMarkerPosition)) {
|
|
178
|
-
|
|
179
|
-
xmpChunks = [];
|
|
180
|
-
}
|
|
190
|
+
xmpBlock = xmpBlock || addBlock(blocks, {kind: 'xmp', chunks: []});
|
|
181
191
|
fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
|
|
182
|
-
if (
|
|
183
|
-
|
|
192
|
+
if (xmpBlock.chunks.length < MAX_XMP_CHUNKS) {
|
|
193
|
+
xmpBlock.chunks.push(getExtendedXmpChunkDetails(appMarkerPosition, fieldLength));
|
|
184
194
|
}
|
|
185
|
-
|
|
195
|
+
block = xmpBlock;
|
|
186
196
|
} else if (isApp13PhotoshopMarker(dataView, appMarkerPosition)) {
|
|
187
197
|
fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
|
|
188
|
-
|
|
189
|
-
|
|
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
|
-
|
|
193
|
-
|
|
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
|
-
|
|
210
|
+
iccBlock.chunks.push({offset: iccDataOffset, length: iccDataLength, chunkNumber: iccChunkNumber, chunksTotal: iccChunksTotal});
|
|
202
211
|
}
|
|
203
|
-
|
|
212
|
+
block = iccBlock;
|
|
204
213
|
} else if (isApp2MPFMarker(dataView, appMarkerPosition)) {
|
|
205
214
|
fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
|
|
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 (
|
|
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
|
-
|
|
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) {
|