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.
- package/README.md +404 -33
- package/bin/analyze.js +139 -9
- package/bin/build-pages.js +21 -35
- package/bin/cli.js +81 -13
- package/bin/generate-tag-modules.js +287 -0
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +213 -38
- package/package.json +71 -11
- package/src/base64-image.js +27 -0
- package/src/composable/brand.js +10 -0
- package/src/composable/composition-tag-filter.js +97 -0
- package/src/composable/composition.js +195 -0
- package/src/composable/core.d.ts +148 -0
- package/src/composable/core.js +526 -0
- package/src/composable/exif-block-reader.js +197 -0
- package/src/composable/formats/avif.js +19 -0
- package/src/composable/formats/gif.js +28 -0
- package/src/composable/formats/heic.js +19 -0
- package/src/composable/formats/iso-bmff-file-reader.js +14 -0
- package/src/composable/formats/jpeg.js +55 -0
- package/src/composable/formats/jxl.js +30 -0
- package/src/composable/formats/png.js +187 -0
- package/src/composable/formats/tiff.js +18 -0
- package/src/composable/formats/webp.js +28 -0
- package/src/composable/formats/xml.js +18 -0
- package/src/composable/formats.d.ts +17 -0
- package/src/composable/formats.js +17 -0
- package/src/composable/group-helpers.js +129 -0
- package/src/composable/groups/canon.js +26 -0
- package/src/composable/groups/composite.js +43 -0
- package/src/composable/groups/exif.js +48 -0
- package/src/composable/groups/gps.js +75 -0
- package/src/composable/groups/icc.js +52 -0
- package/src/composable/groups/iptc.js +86 -0
- package/src/composable/groups/maker-notes.js +21 -0
- package/src/composable/groups/mpf.js +25 -0
- package/src/composable/groups/pentax.js +34 -0
- package/src/composable/groups/photoshop.js +18 -0
- package/src/composable/groups/thumbnail.js +131 -0
- package/src/composable/groups/xmp.js +118 -0
- package/src/composable/groups.d.ts +20 -0
- package/src/composable/groups.js +105 -0
- package/src/composable/iptc-block-reader.js +44 -0
- package/src/composable/read-view.js +165 -0
- package/src/composable/tag-binding-name.js +17 -0
- package/src/composable/tags/exif.d.ts +295 -0
- package/src/composable/tags/exif.js +396 -0
- package/src/composable/tags/iptc.d.ts +84 -0
- package/src/composable/tags/iptc.js +109 -0
- package/src/composable/value-budget.js +24 -0
- package/src/composite.js +2 -2
- package/src/decompression.js +60 -0
- package/src/dom-parser.js +5 -6
- package/src/engine.js +332 -0
- package/src/errors.js +8 -2
- package/src/exif-reader.d.ts +8 -0
- package/src/exif-reader.js +118 -1121
- package/src/file-loaders.js +74 -1
- package/src/file-tags.js +9 -9
- 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 +25 -59
- package/src/iptc-tag-names-descriptions.js +334 -0
- package/src/iptc-tag-names.js +50 -306
- package/src/iptc-tags.js +41 -27
- package/src/jfif-tags.js +9 -9
- package/src/load-auto.js +2 -2
- package/src/loadview-pipeline.js +197 -498
- package/src/mpf-tags.js +10 -7
- package/src/node-require.js +15 -2
- package/src/png-text-tags.js +90 -327
- package/src/tag-filter-config.js +24 -15
- package/src/tag-filter.js +67 -3
- package/src/tag-names-0th-ifd-descriptions.js +232 -0
- package/src/tag-names-0th-ifd.js +49 -173
- package/src/tag-names-common.js +263 -211
- package/src/tag-names-exif-ifd-descriptions.js +249 -0
- package/src/tag-names-exif-ifd.js +55 -187
- package/src/tag-names-gps-ifd-descriptions.js +156 -0
- package/src/tag-names-gps-ifd.js +39 -146
- package/src/tag-names-utils.js +33 -10
- package/src/tags-helpers.js +14 -24
- package/src/tags.js +23 -11
- package/src/thumbnail.js +7 -5
- package/src/types.js +2 -0
- package/src/unsupported-format-error.js +21 -0
- package/src/utils.js +64 -119
- package/src/writer/exif-tag-table.js +321 -0
- package/src/xml.js +12 -15
- package/src/xmp-tag-names.js +42 -21
- package/src/xmp-tags.js +9 -10
- package/webpack.config.js +1 -1
package/src/file-loaders.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
/* global Buffer */
|
|
10
10
|
|
|
11
|
-
import {
|
|
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
|
|
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(
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
getByteAt(dataView, componentOffset),
|
|
102
|
+
getByteAt(dataView, componentOffset + 1),
|
|
103
|
+
getByteAt(dataView, componentOffset + 2)
|
|
104
104
|
]);
|
|
105
105
|
}
|
|
106
106
|
|
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.
|