exifreader 4.52.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 +36 -15
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/package.json +4 -4
- package/src/base64-image.js +27 -0
- package/src/dom-parser.js +53 -4
- package/src/engine.js +388 -0
- package/src/exif-reader.js +541 -894
- 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/load-auto.js +11 -0
- package/src/loadview-pipeline.js +285 -446
- package/src/mpf-tags.js +10 -7
- package/src/node-require.js +8 -1
- package/src/png-text-tags.js +88 -327
- package/src/tag-filter.js +52 -0
- package/src/tag-names-0th-ifd.js +5 -1
- package/src/tag-names-utils.js +25 -2
- package/src/tags-helpers.js +23 -29
- package/src/tags.js +23 -11
- package/src/thumbnail.js +7 -5
- package/src/types.js +32 -2
- package/src/utils.js +42 -34
- package/src/writer/exif-tag-table.js +321 -0
- package/src/xml.js +12 -15
- package/src/xmp-element-depth.js +16 -26
- package/src/xmp-tags.js +11 -12
package/src/image-header-webp.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
|
|
|
7
7
|
export default {
|
|
8
8
|
isWebpFile,
|
|
@@ -26,74 +26,68 @@ function isWebpFile(dataView) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
* Finds the
|
|
29
|
+
* Finds the metadata blocks of a WebP file. The last chunk of each id wins.
|
|
30
30
|
*
|
|
31
|
-
* @param {DataView} dataView The data view to find
|
|
32
|
-
* @param {Array<Object>=}
|
|
33
|
-
*
|
|
34
|
-
* `start` and `end` covering the full RIFF chunk header and content.
|
|
35
|
-
* @returns {Object}
|
|
31
|
+
* @param {DataView} dataView The data view to find blocks in.
|
|
32
|
+
* @param {Array<Object>=} ranges Optional out-array. When provided, receives
|
|
33
|
+
* one `{block, start, end}` span per recognized chunk (EXIF/XMP/ICCP/VP8X)
|
|
34
|
+
* with `start` and `end` covering the full RIFF chunk header and content.
|
|
35
|
+
* @returns {Array<Object>} The blocks, in the order their first chunk was met.
|
|
36
36
|
*/
|
|
37
|
-
function findOffsets(dataView,
|
|
37
|
+
function findOffsets(dataView, ranges) {
|
|
38
38
|
const SUB_CHUNK_START_OFFSET = 12;
|
|
39
39
|
const CHUNK_SIZE_OFFSET = 4;
|
|
40
40
|
const EXIF_IDENTIFIER = 'Exif\x00\x00';
|
|
41
41
|
const CHUNK_HEADER_SIZE = 8;
|
|
42
42
|
|
|
43
|
+
const blocks = [];
|
|
43
44
|
let offset = SUB_CHUNK_START_OFFSET;
|
|
44
|
-
let
|
|
45
|
-
let
|
|
46
|
-
let
|
|
47
|
-
let
|
|
48
|
-
let vp8xChunkOffset;
|
|
45
|
+
let exifBlock;
|
|
46
|
+
let xmpBlock;
|
|
47
|
+
let iccBlock;
|
|
48
|
+
let riffBlock;
|
|
49
49
|
|
|
50
50
|
while (offset + CHUNK_HEADER_SIZE < dataView.byteLength) {
|
|
51
51
|
const chunkId = getStringFromDataView(dataView, offset, 4);
|
|
52
52
|
const chunkSize = dataView.getUint32(offset + CHUNK_SIZE_OFFSET, true);
|
|
53
|
-
let
|
|
53
|
+
let block;
|
|
54
54
|
|
|
55
55
|
if (chunkId === 'EXIF') {
|
|
56
|
-
|
|
56
|
+
exifBlock = exifBlock || addBlock(blocks, {kind: 'exif'});
|
|
57
57
|
if (getStringFromDataView(dataView, offset + CHUNK_HEADER_SIZE, EXIF_IDENTIFIER.length) === EXIF_IDENTIFIER) {
|
|
58
|
-
tiffHeaderOffset = offset + CHUNK_HEADER_SIZE + EXIF_IDENTIFIER.length;
|
|
58
|
+
exifBlock.tiffHeaderOffset = offset + CHUNK_HEADER_SIZE + EXIF_IDENTIFIER.length;
|
|
59
59
|
} else {
|
|
60
|
-
tiffHeaderOffset = offset + CHUNK_HEADER_SIZE;
|
|
60
|
+
exifBlock.tiffHeaderOffset = offset + CHUNK_HEADER_SIZE;
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
block = exifBlock;
|
|
63
63
|
} else if (chunkId === 'XMP ') {
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
xmpBlock = xmpBlock || addBlock(blocks, {kind: 'xmp'});
|
|
65
|
+
xmpBlock.chunks = [{
|
|
66
66
|
dataOffset: offset + CHUNK_HEADER_SIZE,
|
|
67
67
|
length: chunkSize
|
|
68
68
|
}];
|
|
69
|
-
|
|
69
|
+
block = xmpBlock;
|
|
70
70
|
} else if (chunkId === 'ICCP') {
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
iccBlock = iccBlock || addBlock(blocks, {kind: 'icc'});
|
|
72
|
+
iccBlock.chunks = [{
|
|
73
73
|
offset: offset + CHUNK_HEADER_SIZE,
|
|
74
74
|
length: chunkSize,
|
|
75
75
|
chunkNumber: 1,
|
|
76
76
|
chunksTotal: 1
|
|
77
77
|
}];
|
|
78
|
-
|
|
78
|
+
block = iccBlock;
|
|
79
79
|
} else if (chunkId === 'VP8X') {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
riffBlock = riffBlock || addBlock(blocks, {kind: 'riff'});
|
|
81
|
+
riffBlock.dataOffset = offset + CHUNK_HEADER_SIZE;
|
|
82
|
+
block = riffBlock;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
const chunkTotalSize = CHUNK_HEADER_SIZE + (chunkSize % 2 === 0 ? chunkSize : chunkSize + 1);
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
pushRange(ranges, block, offset, offset + chunkTotalSize);
|
|
88
88
|
|
|
89
89
|
offset += chunkTotalSize;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
return
|
|
93
|
-
hasAppMarkers,
|
|
94
|
-
tiffHeaderOffset,
|
|
95
|
-
xmpChunks,
|
|
96
|
-
iccChunks,
|
|
97
|
-
vp8xChunkOffset
|
|
98
|
-
};
|
|
92
|
+
return blocks;
|
|
99
93
|
}
|
package/src/image-header.js
CHANGED
|
@@ -12,7 +12,6 @@ import Jxl from './image-header-jxl.js';
|
|
|
12
12
|
import Webp from './image-header-webp.js';
|
|
13
13
|
import Gif from './image-header-gif.js';
|
|
14
14
|
import Xml from './xml.js';
|
|
15
|
-
import {objectAssign} from './utils.js';
|
|
16
15
|
|
|
17
16
|
export default {
|
|
18
17
|
parseAppMarkers
|
|
@@ -22,62 +21,63 @@ export default {
|
|
|
22
21
|
* Detects the image format and delegates to the matching finder.
|
|
23
22
|
*
|
|
24
23
|
* @param {DataView} dataView The data view to inspect.
|
|
25
|
-
* @param {boolean=}
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* @returns {
|
|
24
|
+
* @param {boolean=} includeRanges When true, the finder also records where
|
|
25
|
+
* each block's bytes sit in the file. The result then gains `ranges`, a
|
|
26
|
+
* list of `{block, start, end}` in file order, and `truncated`, true when
|
|
27
|
+
* the finder never reached the end of the file's metadata.
|
|
28
|
+
* @returns {{fileType: {value: string, description: string}, blocks: Array<Object>, ranges: (Array<Object>|undefined), truncated: (boolean|undefined)}}
|
|
29
|
+
* The blocks the finder found, each `{kind, ...payload}`.
|
|
30
30
|
* @throws {Error} When the data view is not a recognized image format.
|
|
31
31
|
*/
|
|
32
|
-
function parseAppMarkers(dataView,
|
|
33
|
-
const
|
|
32
|
+
function parseAppMarkers(dataView, includeRanges) {
|
|
33
|
+
const ranges = includeRanges ? [] : undefined;
|
|
34
34
|
|
|
35
35
|
if (Constants.USE_TIFF && Tiff.isTiffFile(dataView)) {
|
|
36
|
-
return finalize(Tiff.findTiffOffsets(), 'tiff', 'TIFF',
|
|
36
|
+
return finalize(Tiff.findTiffOffsets(), 'tiff', 'TIFF', ranges);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
if (Constants.USE_JPEG && Jpeg.isJpegFile(dataView)) {
|
|
40
|
-
return finalize(Jpeg.findJpegOffsets(dataView,
|
|
40
|
+
return finalize(Jpeg.findJpegOffsets(dataView, ranges), 'jpeg', 'JPEG', ranges);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
if (Constants.USE_PNG && Png.isPngFile(dataView)) {
|
|
44
|
-
return finalize(Png.findPngOffsets(dataView,
|
|
44
|
+
return finalize(Png.findPngOffsets(dataView, ranges), 'png', 'PNG', ranges);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
if (Constants.USE_HEIC && Heic.isHeicFile(dataView)) {
|
|
48
|
-
return finalize(Heic.findHeicOffsets(dataView,
|
|
48
|
+
return finalize(Heic.findHeicOffsets(dataView, ranges), 'heic', 'HEIC', ranges);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
if (Constants.USE_AVIF && Avif.isAvifFile(dataView)) {
|
|
52
|
-
return finalize(Avif.findAvifOffsets(dataView,
|
|
52
|
+
return finalize(Avif.findAvifOffsets(dataView, ranges), 'avif', 'AVIF', ranges);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
if (Constants.USE_JXL && Jxl.isJxlFile(dataView)) {
|
|
56
|
-
return finalize(Jxl.findJxlOffsets(dataView,
|
|
56
|
+
return finalize(Jxl.findJxlOffsets(dataView, ranges), 'jxl', 'JPEG XL', ranges);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
if (Constants.USE_WEBP && Webp.isWebpFile(dataView)) {
|
|
60
|
-
return finalize(Webp.findOffsets(dataView,
|
|
60
|
+
return finalize(Webp.findOffsets(dataView, ranges), 'webp', 'WebP', ranges);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
if (Constants.USE_GIF && Gif.isGifFile(dataView)) {
|
|
64
|
-
return finalize(Gif.findOffsets(dataView,
|
|
64
|
+
return finalize(Gif.findOffsets(dataView, ranges), 'gif', 'GIF', ranges);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
if (Constants.USE_XMP && Xml.isXMLFile(dataView)) {
|
|
68
|
-
return finalize(Xml.findOffsets(dataView,
|
|
68
|
+
return finalize(Xml.findOffsets(dataView, ranges), 'xml', 'XML', ranges);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
throw new Error('Invalid image format');
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
function finalize(
|
|
75
|
-
const result =
|
|
76
|
-
if (
|
|
77
|
-
result.
|
|
74
|
+
function finalize(blocks, fileType, fileTypeDescription, ranges) {
|
|
75
|
+
const result = {fileType: {value: fileType, description: fileTypeDescription}, blocks};
|
|
76
|
+
if (ranges !== undefined) {
|
|
77
|
+
result.ranges = ranges;
|
|
78
78
|
// Surface the finder's .truncated array convention as a sibling
|
|
79
79
|
// field so consumers don't depend on properties on the array.
|
|
80
|
-
result.
|
|
80
|
+
result.truncated = !!ranges.truncated;
|
|
81
81
|
}
|
|
82
82
|
return result;
|
|
83
83
|
}
|
package/src/load-auto.js
CHANGED
|
@@ -290,9 +290,20 @@ function sliceInputBuffer(data, end) {
|
|
|
290
290
|
const viewEnd = Math.max(0, Math.min(end, data.byteLength));
|
|
291
291
|
return data.buffer.slice(data.byteOffset, data.byteOffset + viewEnd);
|
|
292
292
|
}
|
|
293
|
+
if (isArrayBufferLike(data)) {
|
|
294
|
+
return data.slice(0, end);
|
|
295
|
+
}
|
|
293
296
|
return data;
|
|
294
297
|
}
|
|
295
298
|
|
|
299
|
+
// Tells an ArrayBuffer or SharedArrayBuffer from another realm, where instanceof fails.
|
|
300
|
+
function isArrayBufferLike(data) {
|
|
301
|
+
return !!data
|
|
302
|
+
&& !data.buffer
|
|
303
|
+
&& (typeof data.slice === 'function')
|
|
304
|
+
&& (typeof data.byteLength === 'number');
|
|
305
|
+
}
|
|
306
|
+
|
|
296
307
|
function bufferByteLength(buffer) {
|
|
297
308
|
if (!buffer) {
|
|
298
309
|
return 0;
|