exifreader 4.48.0 → 4.48.1
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 +28 -14
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +6 -6
- package/package.json +5 -5
- package/src/canon-tags.js +4 -3
- package/src/exif-reader.js +7 -1
- package/src/icc-tag-names.js +2 -11
- package/src/image-header-png.js +1 -6
- package/src/photoshop-tags.js +9 -1
- package/src/png-text-tags.js +6 -3
- package/src/tag-filter-config.js +23 -0
- package/src/tag-names-exif-ifd.js +32 -11
- package/src/tag-names-interoperability-ifd.js +2 -2
- package/src/tag-names-mpf-ifd.js +2 -2
- package/src/tag-names-utils.js +17 -3
- package/src/utils.js +36 -12
- package/src/xmp-tags.js +9 -6
package/exif-reader.d.ts
CHANGED
|
@@ -329,7 +329,7 @@ interface PhotoshopTags {
|
|
|
329
329
|
}
|
|
330
330
|
|
|
331
331
|
interface CanonTags {
|
|
332
|
-
AutoRotate
|
|
332
|
+
AutoRotate?: {
|
|
333
333
|
value: number;
|
|
334
334
|
description: 'None' | 'Rotate 90 CW' | 'Rotate 180' | 'Rotate 270 CW' | 'Unknown';
|
|
335
335
|
};
|
|
@@ -344,23 +344,23 @@ interface CanonTags {
|
|
|
344
344
|
}
|
|
345
345
|
|
|
346
346
|
interface PentaxTags {
|
|
347
|
-
PentaxVersion
|
|
347
|
+
PentaxVersion?: {
|
|
348
348
|
value: number[];
|
|
349
349
|
description: string;
|
|
350
350
|
};
|
|
351
|
-
PentaxModelID
|
|
351
|
+
PentaxModelID?: {
|
|
352
352
|
value: number;
|
|
353
353
|
description: string;
|
|
354
354
|
};
|
|
355
|
-
|
|
355
|
+
CameraOrientation?: {
|
|
356
356
|
value: number;
|
|
357
357
|
description: 'Horizontal (normal)' | 'Rotate 270 CW' | 'Rotate 180' | 'Rotate 90 CW' | 'Upwards' | 'Downwards' | 'Unknown';
|
|
358
358
|
};
|
|
359
|
-
RollAngle
|
|
359
|
+
RollAngle?: {
|
|
360
360
|
value: number;
|
|
361
361
|
description: string;
|
|
362
362
|
};
|
|
363
|
-
PitchAngle
|
|
363
|
+
PitchAngle?: {
|
|
364
364
|
value: number;
|
|
365
365
|
description: string;
|
|
366
366
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exifreader",
|
|
3
|
-
"version": "4.48.
|
|
3
|
+
"version": "4.48.1",
|
|
4
4
|
"description": "Library that parses Exif metadata in images.",
|
|
5
5
|
"author": "Mattias Wallander <mattias@wallander.eu>",
|
|
6
6
|
"repository": {
|
|
@@ -32,18 +32,18 @@
|
|
|
32
32
|
"@babel/preset-env": "^7.29.7",
|
|
33
33
|
"@cypress/webpack-preprocessor": "^8.0.0",
|
|
34
34
|
"@eslint/js": "^9.39.5",
|
|
35
|
-
"@types/node": "^26.6.
|
|
35
|
+
"@types/node": "^26.6.4",
|
|
36
36
|
"babel-loader": "^10.0.0",
|
|
37
37
|
"c8": "^12.0.0",
|
|
38
38
|
"chai": "^6.2.2",
|
|
39
39
|
"cross-env": "^10.0.0",
|
|
40
|
-
"cypress": "^16.1.
|
|
40
|
+
"cypress": "^16.1.1",
|
|
41
41
|
"eslint": "^9.39.4",
|
|
42
42
|
"eslint-plugin-cypress": "^6.4.4",
|
|
43
|
-
"globals": "^17.
|
|
43
|
+
"globals": "^17.13.0",
|
|
44
44
|
"husky": "^9.0.11",
|
|
45
45
|
"linkedom": "^0.18.13",
|
|
46
|
-
"mocha": "^12.0.
|
|
46
|
+
"mocha": "^12.0.3",
|
|
47
47
|
"npm-run-all2": "^9.0.3",
|
|
48
48
|
"rimraf": "^5.0.5",
|
|
49
49
|
"string-replace-loader": "^3.1.0",
|
package/src/canon-tags.js
CHANGED
|
@@ -60,10 +60,11 @@ function read(
|
|
|
60
60
|
function parseShotInfo(shotInfoData) {
|
|
61
61
|
const tags = {};
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
const autoRotate = shotInfoData[SHOT_INFO_AUTO_ROTATE];
|
|
64
|
+
if (Number.isFinite(autoRotate)) {
|
|
64
65
|
tags['AutoRotate'] = {
|
|
65
|
-
value:
|
|
66
|
-
description: getAutoRotateDescription(
|
|
66
|
+
value: autoRotate,
|
|
67
|
+
description: getAutoRotateDescription(autoRotate)
|
|
67
68
|
};
|
|
68
69
|
}
|
|
69
70
|
|
package/src/exif-reader.js
CHANGED
|
@@ -240,7 +240,7 @@ export function loadView(
|
|
|
240
240
|
if (
|
|
241
241
|
Constants.USE_XMP
|
|
242
242
|
&& parsedExifTags['ApplicationNotes']
|
|
243
|
-
&&
|
|
243
|
+
&& isNumberArray(parsedExifTags['ApplicationNotes'].value)
|
|
244
244
|
&& !hasXmpData(xmpChunks)
|
|
245
245
|
&& tagFilter.shouldParseGroup('xmp')
|
|
246
246
|
) {
|
|
@@ -1019,6 +1019,12 @@ function getGpsGroupFromExifTags(exifTags) {
|
|
|
1019
1019
|
return gps;
|
|
1020
1020
|
}
|
|
1021
1021
|
|
|
1022
|
+
// ASCII values hold strings and holes, values of two or more rationals hold
|
|
1023
|
+
// number pairs: neither converts to the character codes of an XMP packet.
|
|
1024
|
+
function isNumberArray(value) {
|
|
1025
|
+
return Array.isArray(value) && typeof value[0] === 'number';
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1022
1028
|
function hasXmpData(xmpChunks) {
|
|
1023
1029
|
return Array.isArray(xmpChunks) && xmpChunks.length > 0;
|
|
1024
1030
|
}
|
package/src/icc-tag-names.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} from './utils.js';
|
|
5
|
+
import {getByteString, getStringFromDataView} from './utils.js';
|
|
6
6
|
|
|
7
7
|
export const iccTags = {
|
|
8
8
|
'desc': {
|
|
@@ -119,17 +119,8 @@ function parseDate(dataView, offset) {
|
|
|
119
119
|
return new Date(Date.UTC(year, month, day, hours, minutes, seconds));
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
// Engines cap the number of arguments Function.prototype.apply can pass
|
|
123
|
-
// through, so a large slice is converted in fixed-size chunks.
|
|
124
|
-
const MAX_CHARS_PER_CALL = 8192;
|
|
125
|
-
|
|
126
122
|
export function sliceToString(slice) {
|
|
127
|
-
|
|
128
|
-
const chunks = [];
|
|
129
|
-
for (let offset = 0; offset < bytes.length; offset += MAX_CHARS_PER_CALL) {
|
|
130
|
-
chunks.push(String.fromCharCode.apply(null, bytes.subarray(offset, offset + MAX_CHARS_PER_CALL)));
|
|
131
|
-
}
|
|
132
|
-
return chunks.join('');
|
|
123
|
+
return getByteString(new Uint8Array(slice));
|
|
133
124
|
}
|
|
134
125
|
|
|
135
126
|
function toCompany(value) {
|
package/src/image-header-png.js
CHANGED
|
@@ -86,15 +86,10 @@ function findPngOffsets(dataView, async, metadataBlocks) {
|
|
|
86
86
|
}
|
|
87
87
|
} else if (isPngTextChunk(dataView, offset, async)) {
|
|
88
88
|
offsets.hasAppMarkers = true;
|
|
89
|
-
const chunkType = getStringFromDataView(dataView, offset + PNG_CHUNK_TYPE_OFFSET, PNG_CHUNK_TYPE_SIZE);
|
|
90
89
|
if (!offsets.pngTextChunks) {
|
|
91
90
|
offsets.pngTextChunks = [];
|
|
92
91
|
}
|
|
93
|
-
offsets.pngTextChunks.push(
|
|
94
|
-
length: chunkDataLength,
|
|
95
|
-
type: chunkType,
|
|
96
|
-
offset: offset + PNG_CHUNK_DATA_OFFSET
|
|
97
|
-
});
|
|
92
|
+
offsets.pngTextChunks.push(offset + PNG_CHUNK_LENGTH_OFFSET);
|
|
98
93
|
blockType = 'png';
|
|
99
94
|
} else if (isPngExifChunk(dataView, offset)) {
|
|
100
95
|
offsets.hasAppMarkers = true;
|
package/src/photoshop-tags.js
CHANGED
|
@@ -21,6 +21,10 @@ const SIGNATURE_SIZE = SIGNATURE.length;
|
|
|
21
21
|
const TAG_NAME_MIN_SIZE = 2;
|
|
22
22
|
const RESOURCE_BLOCK_MIN_HEADER_SIZE = SIGNATURE_SIZE + TAG_ID_SIZE + TAG_NAME_MIN_SIZE + RESOURCE_LENGTH_SIZE;
|
|
23
23
|
|
|
24
|
+
// Photoshop defines about 2,100 resource ids and real files carry a few dozen,
|
|
25
|
+
// so the cap never cuts a genuine file.
|
|
26
|
+
export const MAX_RESOURCES = 4096;
|
|
27
|
+
|
|
24
28
|
function read(bytes, includeUnknown, tagFilter = NOOP_TAG_FILTER) {
|
|
25
29
|
if (!Array.isArray(bytes)) {
|
|
26
30
|
return {};
|
|
@@ -31,7 +35,11 @@ function read(bytes, includeUnknown, tagFilter = NOOP_TAG_FILTER) {
|
|
|
31
35
|
const tags = {};
|
|
32
36
|
let offset = 0;
|
|
33
37
|
|
|
34
|
-
|
|
38
|
+
for (
|
|
39
|
+
let resourceCount = 0;
|
|
40
|
+
resourceCount < MAX_RESOURCES && offset + RESOURCE_BLOCK_MIN_HEADER_SIZE <= dataView.byteLength;
|
|
41
|
+
resourceCount++
|
|
42
|
+
) {
|
|
35
43
|
const signature = getStringFromDataView(dataView, offset, SIGNATURE_SIZE);
|
|
36
44
|
offset += SIGNATURE_SIZE;
|
|
37
45
|
const tagId = Types.getShortAt(dataView, offset);
|
package/src/png-text-tags.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import {getStringValueFromArray, getStringFromDataView, decompress, setProperty, getTagKey, objectAssign, COMPRESSION_METHOD_NONE, getHexDigitValue} from './utils.js';
|
|
8
8
|
import TagDecoder from './tag-decoder.js';
|
|
9
|
-
import {TYPE_TEXT, TYPE_ITXT, TYPE_ZTXT} from './image-header-png.js';
|
|
9
|
+
import {PNG_CHUNK_LENGTH_OFFSET, PNG_CHUNK_TYPE_OFFSET, PNG_CHUNK_DATA_OFFSET, PNG_CHUNK_TYPE_SIZE, TYPE_TEXT, TYPE_ITXT, TYPE_ZTXT} from './image-header-png.js';
|
|
10
10
|
import Tags from './tags.js';
|
|
11
11
|
import IptcTags from './iptc-tags.js';
|
|
12
12
|
import Constants from './constants.js';
|
|
@@ -33,6 +33,7 @@ const MAX_KEYWORD_LENGTH = 79;
|
|
|
33
33
|
const MAX_LANGUAGE_TAG_LENGTH = 79;
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
+
* @param {number[]} pngTextChunks Chunk start offsets, where each chunk's length field is.
|
|
36
37
|
* @param {function(DataView, object, number): object} [getThumbnail] Called with a
|
|
37
38
|
* decoded Exif raw profile, its thumbnail IFD tags and the TIFF header offset;
|
|
38
39
|
* returns the thumbnail tags, with `image` set when the thumbnail was read.
|
|
@@ -64,8 +65,10 @@ function read(
|
|
|
64
65
|
const compressedChunks = [];
|
|
65
66
|
|
|
66
67
|
for (let i = 0; i < pngTextChunks.length; i++) {
|
|
67
|
-
const
|
|
68
|
-
const
|
|
68
|
+
const chunkOffset = pngTextChunks[i];
|
|
69
|
+
const length = dataView.getUint32(chunkOffset + PNG_CHUNK_LENGTH_OFFSET);
|
|
70
|
+
const type = getStringFromDataView(dataView, chunkOffset + PNG_CHUNK_TYPE_OFFSET, PNG_CHUNK_TYPE_SIZE);
|
|
71
|
+
const textChunk = parseTextChunk(dataView, chunkOffset + PNG_CHUNK_DATA_OFFSET, length, type);
|
|
69
72
|
if (!textChunk) {
|
|
70
73
|
continue;
|
|
71
74
|
}
|
package/src/tag-filter-config.js
CHANGED
|
@@ -34,6 +34,21 @@ export const EXIF_POINTER_TAGS = {
|
|
|
34
34
|
interoperabilityIfdPointer: 'Interoperability IFD Pointer',
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
// The two id sets mirror the keys of tag-names-gps-ifd.js and tag-names-interoperability-ifd.js.
|
|
38
|
+
// Importing those files here instead would bring them into builds that leave Exif out.
|
|
39
|
+
const GPS_IFD_TAG_IDS = getIdLookup([[0x0000, 0x001f]]);
|
|
40
|
+
const INTEROPERABILITY_IFD_TAG_IDS = getIdLookup([[0x0001, 0x0002], [0x1000, 0x1002]]);
|
|
41
|
+
|
|
42
|
+
function getIdLookup(idRanges) {
|
|
43
|
+
const lookup = Object.create(null);
|
|
44
|
+
for (let i = 0; i < idRanges.length; i++) {
|
|
45
|
+
for (let id = idRanges[i][0]; id <= idRanges[i][1]; id++) {
|
|
46
|
+
lookup[id] = true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return lookup;
|
|
50
|
+
}
|
|
51
|
+
|
|
37
52
|
export const EXIF_DEPENDENCY_TAGS = {
|
|
38
53
|
thumbnail: [
|
|
39
54
|
'JPEGInterchangeFormat',
|
|
@@ -99,6 +114,14 @@ export function getExifTagDependenciesForInclude(includeTags) {
|
|
|
99
114
|
function addPointerDependenciesFromExifTagSelectors(pointerSet, selectors) {
|
|
100
115
|
for (let i = 0; i < selectors.length; i++) {
|
|
101
116
|
const selector = selectors[i];
|
|
117
|
+
if (typeof selector === 'number') {
|
|
118
|
+
if (GPS_IFD_TAG_IDS[selector]) {
|
|
119
|
+
pointerSet[EXIF_POINTER_TAGS.gpsInfoIfdPointer] = true;
|
|
120
|
+
}
|
|
121
|
+
if (INTEROPERABILITY_IFD_TAG_IDS[selector]) {
|
|
122
|
+
pointerSet[EXIF_POINTER_TAGS.interoperabilityIfdPointer] = true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
102
125
|
if (typeof selector !== 'string') {
|
|
103
126
|
continue;
|
|
104
127
|
}
|
|
@@ -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 {getEncodedString, getVersionString} from './tag-names-utils.js';
|
|
6
6
|
import TagNamesCommon from './tag-names-common.js';
|
|
7
7
|
|
|
8
8
|
export default {
|
|
@@ -45,7 +45,7 @@ export default {
|
|
|
45
45
|
0x8835: 'ISOSpeedLatitudezzz',
|
|
46
46
|
0x9000: {
|
|
47
47
|
'name': 'ExifVersion',
|
|
48
|
-
'description':
|
|
48
|
+
'description': getVersionString
|
|
49
49
|
},
|
|
50
50
|
0x9003: 'DateTimeOriginal',
|
|
51
51
|
0x9004: 'DateTimeDigitized',
|
|
@@ -204,7 +204,7 @@ export default {
|
|
|
204
204
|
},
|
|
205
205
|
0xa000: {
|
|
206
206
|
'name': 'FlashpixVersion',
|
|
207
|
-
'description':
|
|
207
|
+
'description': getVersionString
|
|
208
208
|
},
|
|
209
209
|
0xa001: {
|
|
210
210
|
'name': 'ColorSpace',
|
|
@@ -354,14 +354,7 @@ export default {
|
|
|
354
354
|
0xa432: {
|
|
355
355
|
'name': 'LensSpecification',
|
|
356
356
|
'description': (value) => {
|
|
357
|
-
|
|
358
|
-
const focalLengthTo = parseFloat((value[1][0] / value[1][1]).toFixed(5));
|
|
359
|
-
const focalLengths = `${focalLengthFrom}-${focalLengthTo} mm`;
|
|
360
|
-
if (value[3][1] === 0) {
|
|
361
|
-
return `${focalLengths} f/?`;
|
|
362
|
-
}
|
|
363
|
-
const maxAperture = 1 / ((value[2][1] / value[2][1]) / (value[3][0] / value[3][1]));
|
|
364
|
-
return `${focalLengths} f/${parseFloat(maxAperture.toFixed(5))}`;
|
|
357
|
+
return `${getLensFocalLengths(value[0], value[1])} mm f/${getLensApertures(value[2], value[3])}`;
|
|
365
358
|
}
|
|
366
359
|
},
|
|
367
360
|
0xa433: 'LensMake',
|
|
@@ -395,3 +388,31 @@ export default {
|
|
|
395
388
|
0xfe57: 'Smoothness',
|
|
396
389
|
0xfe58: 'MoireFilter'
|
|
397
390
|
};
|
|
391
|
+
|
|
392
|
+
function getLensFocalLengths(from, to) {
|
|
393
|
+
const focalLengthFrom = getRoundedRational(from);
|
|
394
|
+
const focalLengthTo = getRoundedRational(to);
|
|
395
|
+
if (focalLengthTo === 0 || focalLengthTo === focalLengthFrom) {
|
|
396
|
+
return `${focalLengthFrom}`;
|
|
397
|
+
}
|
|
398
|
+
return `${focalLengthFrom}-${focalLengthTo}`;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function getLensApertures(wide, long) {
|
|
402
|
+
const apertures = [wide, long].filter(isKnownRational).map(getRoundedRational);
|
|
403
|
+
if (apertures.length === 0) {
|
|
404
|
+
return '?';
|
|
405
|
+
}
|
|
406
|
+
if (apertures.length === 1 || apertures[1] === 0 || apertures[1] === apertures[0]) {
|
|
407
|
+
return `${apertures[0]}`;
|
|
408
|
+
}
|
|
409
|
+
return `${apertures[0]}-${apertures[1]}`;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function getRoundedRational(rational) {
|
|
413
|
+
return parseFloat((rational[0] / rational[1]).toFixed(5));
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function isKnownRational(rational) {
|
|
417
|
+
return rational[1] !== 0;
|
|
418
|
+
}
|
|
@@ -2,13 +2,13 @@
|
|
|
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 {getVersionString} from './tag-names-utils.js';
|
|
6
6
|
|
|
7
7
|
export default {
|
|
8
8
|
0x0001: 'InteroperabilityIndex',
|
|
9
9
|
0x0002: {
|
|
10
10
|
name: 'InteroperabilityVersion',
|
|
11
|
-
description:
|
|
11
|
+
description: getVersionString
|
|
12
12
|
},
|
|
13
13
|
0x1000: 'RelatedImageFileFormat',
|
|
14
14
|
0x1001: 'RelatedImageWidth',
|
package/src/tag-names-mpf-ifd.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
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 {getVersionString} from './tag-names-utils.js';
|
|
6
6
|
|
|
7
7
|
export default {
|
|
8
8
|
0xb000: {
|
|
9
9
|
'name': 'MPFVersion',
|
|
10
|
-
'description':
|
|
10
|
+
'description': getVersionString
|
|
11
11
|
},
|
|
12
12
|
0xb001: 'NumberOfImages',
|
|
13
13
|
0xb002: 'MPEntry',
|
package/src/tag-names-utils.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 {getStringValueFromArray as getStringValue} from './utils.js';
|
|
5
|
+
import {getStringValueFromArray as getStringValue, getByteString} from './utils.js';
|
|
6
6
|
|
|
7
7
|
export {getStringValue};
|
|
8
8
|
|
|
@@ -11,13 +11,13 @@ export function getEncodedString(value) {
|
|
|
11
11
|
const encoding = getStringValue(value.slice(0, 8));
|
|
12
12
|
|
|
13
13
|
if (encoding === 'ASCII\x00\x00\x00') {
|
|
14
|
-
return
|
|
14
|
+
return getByteString(value, 8);
|
|
15
15
|
} else if (encoding === 'JIS\x00\x00\x00\x00\x00') {
|
|
16
16
|
return '[JIS encoded text]';
|
|
17
17
|
} else if (encoding === 'UNICODE\x00') {
|
|
18
18
|
return '[Unicode encoded text]';
|
|
19
19
|
} else if (encoding === '\x00\x00\x00\x00\x00\x00\x00\x00') {
|
|
20
|
-
const text =
|
|
20
|
+
const text = getByteString(value, 8);
|
|
21
21
|
if (/[\x20-\x7e]/.test(text)) {
|
|
22
22
|
return text;
|
|
23
23
|
}
|
|
@@ -28,6 +28,20 @@ export function getEncodedString(value) {
|
|
|
28
28
|
return 'Undefined';
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Converts the bytes of a version tag, such as ExifVersion, to a string. A
|
|
33
|
+
* value that is not an array (a single byte, or '<faulty value>') is returned
|
|
34
|
+
* as it is.
|
|
35
|
+
* @param {number[]|number|string} value
|
|
36
|
+
* @returns {string|number}
|
|
37
|
+
*/
|
|
38
|
+
export function getVersionString(value) {
|
|
39
|
+
if (Array.isArray(value)) {
|
|
40
|
+
return getByteString(value);
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
|
|
31
45
|
export function getCalculatedGpsValue(value) {
|
|
32
46
|
return (value[0][0] / value[0][1]) + (value[1][0] / value[1][1]) / 60 + (value[2][0] / value[2][1]) / 3600;
|
|
33
47
|
}
|
package/src/utils.js
CHANGED
|
@@ -191,9 +191,29 @@ export function getCharacterArray(string) {
|
|
|
191
191
|
return string.split('').map((character) => character.charCodeAt(0));
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
// Guards against memory exhaustion from a crafted file. A real JPEG has at most 255 ICC
|
|
195
|
+
// segments, ExifReader reads at most 1024 XMP ones, and other containers are few.
|
|
196
|
+
export const MAX_METADATA_BLOCKS = 4096;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Records one metadata block. The list holds at most MAX_METADATA_BLOCKS
|
|
200
|
+
* entries; past that, the last entry is widened to cover each further block
|
|
201
|
+
* and keeps its own type. Does nothing without a list or a type.
|
|
202
|
+
* @param {Array<{type: string, start: number, end: number}>|undefined} metadataBlocks
|
|
203
|
+
* @param {string|undefined} type
|
|
204
|
+
* @param {number} start
|
|
205
|
+
* @param {number} end Exclusive.
|
|
206
|
+
*/
|
|
194
207
|
export function pushMetadataBlock(metadataBlocks, type, start, end) {
|
|
195
|
-
if (metadataBlocks
|
|
208
|
+
if (!metadataBlocks || !type) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (metadataBlocks.length < MAX_METADATA_BLOCKS) {
|
|
196
212
|
metadataBlocks.push({type, start, end});
|
|
213
|
+
} else {
|
|
214
|
+
const lastBlock = metadataBlocks[metadataBlocks.length - 1];
|
|
215
|
+
lastBlock.start = Math.min(lastBlock.start, start);
|
|
216
|
+
lastBlock.end = Math.max(lastBlock.end, end);
|
|
197
217
|
}
|
|
198
218
|
}
|
|
199
219
|
|
|
@@ -267,23 +287,27 @@ export function deferInit(object, key, initializer) {
|
|
|
267
287
|
}
|
|
268
288
|
|
|
269
289
|
export function getBase64Image(image) {
|
|
290
|
+
if (typeof image === 'string' && typeof btoa !== 'undefined') {
|
|
291
|
+
// Only tests pass a string. btoa reads it as Latin-1, Buffer.from would use UTF-8.
|
|
292
|
+
return btoa(image);
|
|
293
|
+
}
|
|
294
|
+
if (hasBufferFrom()) {
|
|
295
|
+
return Buffer.from(image).toString('base64'); // eslint-disable-line no-undef
|
|
296
|
+
}
|
|
270
297
|
if (typeof btoa !== 'undefined') {
|
|
271
|
-
|
|
272
|
-
// This only happens during the build tests using Node 16+ (npm run test:build).
|
|
273
|
-
return btoa(image);
|
|
274
|
-
}
|
|
275
|
-
// IE11- does not implement reduce on the Uint8Array prototype.
|
|
276
|
-
return btoa(Array.prototype.reduce.call(new Uint8Array(image), (data, byte) => data + String.fromCharCode(byte), ''));
|
|
298
|
+
return btoa(getByteString(new Uint8Array(image)));
|
|
277
299
|
}
|
|
278
300
|
if (typeof Buffer === 'undefined') {
|
|
279
301
|
return undefined;
|
|
280
302
|
}
|
|
281
|
-
if (typeof Buffer.from !== 'undefined') { // eslint-disable-line no-undef
|
|
282
|
-
return Buffer.from(image).toString('base64'); // eslint-disable-line no-undef
|
|
283
|
-
}
|
|
284
303
|
return (new Buffer(image)).toString('base64'); // eslint-disable-line no-undef
|
|
285
304
|
}
|
|
286
305
|
|
|
306
|
+
function hasBufferFrom() {
|
|
307
|
+
// Buffer polyfills before buffer@4.6.0 inherit Uint8Array.from, which returns an empty array for an ArrayBuffer.
|
|
308
|
+
return typeof Buffer !== 'undefined' && typeof Buffer.from !== 'undefined' && Buffer.from !== Uint8Array.from; // eslint-disable-line no-undef
|
|
309
|
+
}
|
|
310
|
+
|
|
287
311
|
export function dataUriToBuffer(dataUri) {
|
|
288
312
|
const commaIndex = dataUri.indexOf(',');
|
|
289
313
|
const header = dataUri.substring(0, commaIndex);
|
|
@@ -472,8 +496,8 @@ export function decompress(dataView, compressionMethod, encoding, returnType = '
|
|
|
472
496
|
try {
|
|
473
497
|
return new TextDecoder(encoding).decode(dataView);
|
|
474
498
|
} catch (error) {
|
|
475
|
-
|
|
476
|
-
return
|
|
499
|
+
// Like TextDecoder's decode(), read a missing view as no bytes.
|
|
500
|
+
return dataView ? getByteString(getUint8View(dataView)) : '';
|
|
477
501
|
}
|
|
478
502
|
}
|
|
479
503
|
return dataView;
|
package/src/xmp-tags.js
CHANGED
|
@@ -132,7 +132,7 @@ function readTags(tags, chunkDataView, domParser) {
|
|
|
132
132
|
delete xmpTags._raw;
|
|
133
133
|
const names = Object.keys(xmpTags);
|
|
134
134
|
for (let i = 0; i < names.length; i++) {
|
|
135
|
-
setProperty(tags,
|
|
135
|
+
setProperty(tags, names[i], xmpTags[names[i]]);
|
|
136
136
|
}
|
|
137
137
|
return true;
|
|
138
138
|
} catch (error) {
|
|
@@ -335,7 +335,9 @@ function getElementFromNode(node, decodeValue) {
|
|
|
335
335
|
|
|
336
336
|
function getAttributes(element, decodeValue) {
|
|
337
337
|
const elementAttributes = element.attributes;
|
|
338
|
-
|
|
338
|
+
// A qualifier with element content returns these unchanged in its element
|
|
339
|
+
// tree, so like the elements object they must not have a prototype.
|
|
340
|
+
const attributes = Object.create(null);
|
|
339
341
|
|
|
340
342
|
for (let i = 0; i < elementAttributes.length; i++) {
|
|
341
343
|
setProperty(attributes, elementAttributes[i].nodeName, decodeValue(elementAttributes[i].value));
|
|
@@ -382,8 +384,9 @@ function isNamespaceDefinition(name) {
|
|
|
382
384
|
}
|
|
383
385
|
|
|
384
386
|
function setParsedTag(tags, plainDescriptions, name, parsedTag) {
|
|
385
|
-
|
|
386
|
-
setProperty(
|
|
387
|
+
const key = getTagKey(name);
|
|
388
|
+
setProperty(tags, key, parsedTag.tag);
|
|
389
|
+
setProperty(plainDescriptions, key, parsedTag.plainDescription);
|
|
387
390
|
}
|
|
388
391
|
|
|
389
392
|
function getLocalName(name) {
|
|
@@ -531,7 +534,7 @@ function parseNodeAttributes(node) {
|
|
|
531
534
|
|
|
532
535
|
for (const name in node.attributes) {
|
|
533
536
|
if ((name !== 'rdf:parseType') && (name !== 'rdf:resource') && (!isNamespaceDefinition(name))) {
|
|
534
|
-
setProperty(attributes, getLocalName(name), node.attributes[name]);
|
|
537
|
+
setProperty(attributes, getTagKey(getLocalName(name)), node.attributes[name]);
|
|
535
538
|
}
|
|
536
539
|
}
|
|
537
540
|
|
|
@@ -547,7 +550,7 @@ function parseNodeChildrenAsAttributes(node) {
|
|
|
547
550
|
|
|
548
551
|
for (const name in node.value) {
|
|
549
552
|
if ((name !== 'rdf:value') && (!isNamespaceDefinition(name))) {
|
|
550
|
-
setProperty(attributes, getLocalName(name), node.value[name].value);
|
|
553
|
+
setProperty(attributes, getTagKey(getLocalName(name)), node.value[name].value);
|
|
551
554
|
}
|
|
552
555
|
}
|
|
553
556
|
|