exifreader 4.14.1 → 4.16.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 +34 -30
- package/bin/build.js +8 -8
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.gz +0 -0
- package/dist/exif-reader.js.map +1 -1
- package/package.json +27 -31
- package/src/exif-reader.js +7 -6
- package/src/mpf-tags.js +150 -0
- package/src/tags-helpers.js +187 -0
- package/src/tags.js +2 -315
- package/src/utils.js +3 -3
- package/src/xmp-tags.js +36 -8
- package/webpack.config.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exifreader",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.16.0",
|
|
4
4
|
"description": "Library that parses Exif metadata in images.",
|
|
5
5
|
"author": "Mattias Wallander <mattias@wallander.eu>",
|
|
6
6
|
"repository": {
|
|
@@ -22,38 +22,37 @@
|
|
|
22
22
|
],
|
|
23
23
|
"types": "./exif-reader.d.ts",
|
|
24
24
|
"optionalDependencies": {
|
|
25
|
-
"@xmldom/xmldom": "^0.8.
|
|
25
|
+
"@xmldom/xmldom": "^0.8.10"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@babel/core": "^7.
|
|
29
|
-
"@babel/preset-env": "^7.
|
|
30
|
-
"@babel/register": "^7.15
|
|
31
|
-
"@types/node": "^
|
|
32
|
-
"babel-loader": "^8.2.
|
|
28
|
+
"@babel/core": "^7.23.2",
|
|
29
|
+
"@babel/preset-env": "^7.23.2",
|
|
30
|
+
"@babel/register": "^7.22.15",
|
|
31
|
+
"@types/node": "^18.11.9",
|
|
32
|
+
"babel-loader": "^8.2.5",
|
|
33
33
|
"babel-plugin-rewire": "^1.2.0",
|
|
34
|
-
"chai": "^4.3.
|
|
34
|
+
"chai": "^4.3.10",
|
|
35
35
|
"cross-env": "^7.0.3",
|
|
36
|
-
"cypress": "^
|
|
37
|
-
"
|
|
38
|
-
"eslint": "^
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"mocha": "^9.1.2",
|
|
36
|
+
"cypress": "^13.3.2",
|
|
37
|
+
"eslint": "^8.52.0",
|
|
38
|
+
"eslint-plugin-cypress": "^2.15.1",
|
|
39
|
+
"husky": "^8.0.0",
|
|
40
|
+
"mocha": "^10.2.0",
|
|
42
41
|
"npm-run-all": "^4.1.5",
|
|
43
42
|
"nyc": "^15.1.0",
|
|
44
|
-
"rimraf": "^
|
|
45
|
-
"string-replace-loader": "^3.0
|
|
46
|
-
"terser-webpack-plugin": "^5.
|
|
47
|
-
"typescript": "^5.
|
|
48
|
-
"webpack": "^5.
|
|
49
|
-
"webpack-cli": "^
|
|
50
|
-
"webpack-dev-server": "^4.
|
|
43
|
+
"rimraf": "^5.0.5",
|
|
44
|
+
"string-replace-loader": "^3.1.0",
|
|
45
|
+
"terser-webpack-plugin": "^5.3.9",
|
|
46
|
+
"typescript": "^5.2.2",
|
|
47
|
+
"webpack": "^5.89.0",
|
|
48
|
+
"webpack-cli": "^5.1.4",
|
|
49
|
+
"webpack-dev-server": "^4.15.1"
|
|
51
50
|
},
|
|
52
51
|
"scripts": {
|
|
53
52
|
"build": "node bin/build.js",
|
|
54
53
|
"build:pages": "node bin/build-pages.js",
|
|
55
54
|
"coverage": "nyc npm test",
|
|
56
|
-
"cypress:open": "cypress open",
|
|
55
|
+
"cypress:open": "cypress open --e2e",
|
|
57
56
|
"lint": "eslint .",
|
|
58
57
|
"start": "cross-env NODE_ENV=development webpack serve",
|
|
59
58
|
"test": "cross-env BABEL_ENV=test mocha --require @babel/register --recursive \"test/unit/\"",
|
|
@@ -62,13 +61,15 @@
|
|
|
62
61
|
"test:build:update": "node test/build/update.js",
|
|
63
62
|
"test:e2e": "cypress run",
|
|
64
63
|
"test:types": "tsc --noEmit --project test/types",
|
|
65
|
-
"test:all": "npm-run-all lint coverage test:e2e test:build test:build:custom
|
|
66
|
-
"
|
|
64
|
+
"test:all": "npm-run-all lint test:types coverage test:e2e test:build test:build:custom",
|
|
65
|
+
"pre-commit": "npm-run-all lint test test:build",
|
|
66
|
+
"postinstall": "node bin/build.js --only-with-config",
|
|
67
|
+
"prepare": "husky install"
|
|
67
68
|
},
|
|
68
69
|
"nyc": {
|
|
69
70
|
"check-coverage": true,
|
|
70
71
|
"statements": 95,
|
|
71
|
-
"branches":
|
|
72
|
+
"branches": 91,
|
|
72
73
|
"functions": 98,
|
|
73
74
|
"lines": 95,
|
|
74
75
|
"reporter": [
|
|
@@ -90,10 +91,5 @@
|
|
|
90
91
|
"Edge >= 12",
|
|
91
92
|
"Safari >= 5.1",
|
|
92
93
|
"Opera >= 12.1"
|
|
93
|
-
]
|
|
94
|
-
"husky": {
|
|
95
|
-
"hooks": {
|
|
96
|
-
"pre-commit": "npm-run-all lint test test:build"
|
|
97
|
-
}
|
|
98
|
-
}
|
|
94
|
+
]
|
|
99
95
|
}
|
package/src/exif-reader.js
CHANGED
|
@@ -15,6 +15,7 @@ import {getStringValueFromArray} from './utils.js';
|
|
|
15
15
|
import {getCalculatedGpsValue} from './tag-names-utils.js';
|
|
16
16
|
import ImageHeader from './image-header.js';
|
|
17
17
|
import Tags from './tags.js';
|
|
18
|
+
import MpfTags from './mpf-tags.js';
|
|
18
19
|
import FileTags from './file-tags.js';
|
|
19
20
|
import JfifTags from './jfif-tags.js';
|
|
20
21
|
import IptcTags from './iptc-tags.js';
|
|
@@ -50,12 +51,12 @@ function isFilePathOrURL(data) {
|
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
function loadFile(filename, options) {
|
|
53
|
-
if (
|
|
54
|
+
if (/^\w+:\/\//.test(filename)) {
|
|
54
55
|
if (typeof fetch !== 'undefined') {
|
|
55
|
-
return
|
|
56
|
+
return fetchRemoteFile(filename, options);
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
return
|
|
59
|
+
return nodeGetRemoteFile(filename, options);
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
if (isDataUri(filename)) {
|
|
@@ -65,7 +66,7 @@ function loadFile(filename, options) {
|
|
|
65
66
|
return loadLocalFile(filename, options);
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
function
|
|
69
|
+
function fetchRemoteFile(url, {length} = {}) {
|
|
69
70
|
const options = {method: 'GET'};
|
|
70
71
|
if (Number.isInteger(length) && length >= 0) {
|
|
71
72
|
options.headers = {
|
|
@@ -75,7 +76,7 @@ function browserFetchRemoteFile(url, {length} = {}) {
|
|
|
75
76
|
return fetch(url, options).then((response) => response.arrayBuffer());
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
function
|
|
79
|
+
function nodeGetRemoteFile(url, {length} = {}) {
|
|
79
80
|
return new Promise((resolve, reject) => {
|
|
80
81
|
const options = {};
|
|
81
82
|
if (Number.isInteger(length) && length >= 0) {
|
|
@@ -316,7 +317,7 @@ export function loadView(dataView, {expanded = false, includeUnknown = false} =
|
|
|
316
317
|
|
|
317
318
|
if (Constants.USE_MPF && hasMpfData(mpfDataOffset)) {
|
|
318
319
|
foundMetaData = true;
|
|
319
|
-
const readMpfTags =
|
|
320
|
+
const readMpfTags = MpfTags.read(dataView, mpfDataOffset, includeUnknown);
|
|
320
321
|
if (expanded) {
|
|
321
322
|
tags.mpf = readMpfTags;
|
|
322
323
|
} else {
|
package/src/mpf-tags.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
|
+
|
|
5
|
+
import ByteOrder from './byte-order.js';
|
|
6
|
+
import Types from './types.js';
|
|
7
|
+
import {IFD_TYPE_MPF} from './tag-names.js';
|
|
8
|
+
import {deferInit, getBase64Image} from './utils.js';
|
|
9
|
+
import {readIfd, get0thIfdOffset} from './tags-helpers.js';
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
read
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const ENTRY_SIZE = 16;
|
|
16
|
+
|
|
17
|
+
function read(dataView, dataOffset, includeUnknown) {
|
|
18
|
+
const byteOrder = ByteOrder.getByteOrder(dataView, dataOffset);
|
|
19
|
+
const tags = readIfd(dataView, IFD_TYPE_MPF, dataOffset, get0thIfdOffset(dataView, dataOffset, byteOrder), byteOrder, includeUnknown);
|
|
20
|
+
return addMpfImages(dataView, dataOffset, tags, byteOrder);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function addMpfImages(dataView, dataOffset, tags, byteOrder) {
|
|
24
|
+
if (!tags['MPEntry']) {
|
|
25
|
+
return tags;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const images = [];
|
|
29
|
+
for (let i = 0; i < Math.ceil(tags['MPEntry'].value.length / ENTRY_SIZE); i++) {
|
|
30
|
+
images[i] = {};
|
|
31
|
+
|
|
32
|
+
const attributes = getImageNumberValue(tags['MPEntry'].value, i * ENTRY_SIZE, Types.getTypeSize('LONG'), byteOrder);
|
|
33
|
+
images[i]['ImageFlags'] = getImageFlags(attributes);
|
|
34
|
+
images[i]['ImageFormat'] = getImageFormat(attributes);
|
|
35
|
+
images[i]['ImageType'] = getImageType(attributes);
|
|
36
|
+
|
|
37
|
+
const imageSize = getImageNumberValue(tags['MPEntry'].value, i * ENTRY_SIZE + 4, Types.getTypeSize('LONG'), byteOrder);
|
|
38
|
+
images[i]['ImageSize'] = {
|
|
39
|
+
value: imageSize,
|
|
40
|
+
description: '' + imageSize
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const imageOffset = getImageOffset(i, tags['MPEntry'], byteOrder, dataOffset);
|
|
44
|
+
images[i]['ImageOffset'] = {
|
|
45
|
+
value: imageOffset,
|
|
46
|
+
description: '' + imageOffset
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const dependentImage1EntryNumber =
|
|
50
|
+
getImageNumberValue(tags['MPEntry'].value, i * ENTRY_SIZE + 12, Types.getTypeSize('SHORT'), byteOrder);
|
|
51
|
+
images[i]['DependentImage1EntryNumber'] = {
|
|
52
|
+
value: dependentImage1EntryNumber,
|
|
53
|
+
description: '' + dependentImage1EntryNumber
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const dependentImage2EntryNumber =
|
|
57
|
+
getImageNumberValue(tags['MPEntry'].value, i * ENTRY_SIZE + 14, Types.getTypeSize('SHORT'), byteOrder);
|
|
58
|
+
images[i]['DependentImage2EntryNumber'] = {
|
|
59
|
+
value: dependentImage2EntryNumber,
|
|
60
|
+
description: '' + dependentImage2EntryNumber
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
images[i].image = dataView.buffer.slice(imageOffset, imageOffset + imageSize);
|
|
64
|
+
deferInit(images[i], 'base64', function () {
|
|
65
|
+
return getBase64Image(this.image);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
tags['Images'] = images;
|
|
70
|
+
|
|
71
|
+
return tags;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getImageNumberValue(entries, offset, size, byteOrder) {
|
|
75
|
+
if (byteOrder === ByteOrder.LITTLE_ENDIAN) {
|
|
76
|
+
let value = 0;
|
|
77
|
+
for (let i = 0; i < size; i++) {
|
|
78
|
+
value += entries[offset + i] << (8 * i);
|
|
79
|
+
}
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let value = 0;
|
|
84
|
+
for (let i = 0; i < size; i++) {
|
|
85
|
+
value += entries[offset + i] << (8 * (size - 1 - i));
|
|
86
|
+
}
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function getImageFlags(attributes) {
|
|
91
|
+
const flags = [
|
|
92
|
+
(attributes >> 31) & 0x1,
|
|
93
|
+
(attributes >> 30) & 0x1,
|
|
94
|
+
(attributes >> 29) & 0x1
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
const flagsDescription = [];
|
|
98
|
+
|
|
99
|
+
if (flags[0]) {
|
|
100
|
+
flagsDescription.push('Dependent Parent Image');
|
|
101
|
+
}
|
|
102
|
+
if (flags[1]) {
|
|
103
|
+
flagsDescription.push('Dependent Child Image');
|
|
104
|
+
}
|
|
105
|
+
if (flags[2]) {
|
|
106
|
+
flagsDescription.push('Representative Image');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
value: flags,
|
|
111
|
+
description: flagsDescription.join(', ') || 'None'
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function getImageFormat(attributes) {
|
|
116
|
+
const imageFormat = attributes >> 24 & 0x7;
|
|
117
|
+
return {
|
|
118
|
+
value: imageFormat,
|
|
119
|
+
description: imageFormat === 0 ? 'JPEG' : 'Unknown'
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function getImageType(attributes) {
|
|
124
|
+
const type = attributes & 0xffffff;
|
|
125
|
+
const descriptions = {
|
|
126
|
+
0x30000: 'Baseline MP Primary Image',
|
|
127
|
+
0x10001: 'Large Thumbnail (VGA equivalent)',
|
|
128
|
+
0x10002: 'Large Thumbnail (Full HD equivalent)',
|
|
129
|
+
0x20001: 'Multi-Frame Image (Panorama)',
|
|
130
|
+
0x20002: 'Multi-Frame Image (Disparity)',
|
|
131
|
+
0x20003: 'Multi-Frame Image (Multi-Angle)',
|
|
132
|
+
0x0: 'Undefined',
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
value: type,
|
|
137
|
+
description: descriptions[type] || 'Unknown'
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function getImageOffset(imageIndex, mpEntry, byteOrder, dataOffset) {
|
|
142
|
+
if (isFirstIndividualImage(imageIndex)) {
|
|
143
|
+
return 0;
|
|
144
|
+
}
|
|
145
|
+
return getImageNumberValue(mpEntry.value, imageIndex * ENTRY_SIZE + 8, Types.getTypeSize('LONG'), byteOrder) + dataOffset;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function isFirstIndividualImage(imageIndex) {
|
|
149
|
+
return imageIndex === 0;
|
|
150
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
|
+
|
|
5
|
+
import Constants from './constants.js';
|
|
6
|
+
import Types from './types.js';
|
|
7
|
+
import TagNames, {IFD_TYPE_0TH, IFD_TYPE_1ST} from './tag-names.js';
|
|
8
|
+
|
|
9
|
+
const getTagValueAt = {
|
|
10
|
+
1: Types.getByteAt,
|
|
11
|
+
2: Types.getAsciiAt,
|
|
12
|
+
3: Types.getShortAt,
|
|
13
|
+
4: Types.getLongAt,
|
|
14
|
+
5: Types.getRationalAt,
|
|
15
|
+
7: Types.getUndefinedAt,
|
|
16
|
+
9: Types.getSlongAt,
|
|
17
|
+
10: Types.getSrationalAt,
|
|
18
|
+
13: Types.getIfdPointerAt
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function get0thIfdOffset(dataView, tiffHeaderOffset, byteOrder) {
|
|
22
|
+
return tiffHeaderOffset + Types.getLongAt(dataView, tiffHeaderOffset + 4, byteOrder);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function readIfd(dataView, ifdType, tiffHeaderOffset, offset, byteOrder, includeUnknown) {
|
|
26
|
+
const FIELD_COUNT_SIZE = Types.getTypeSize('SHORT');
|
|
27
|
+
const FIELD_SIZE = 12;
|
|
28
|
+
|
|
29
|
+
const tags = {};
|
|
30
|
+
const numberOfFields = getNumberOfFields(dataView, offset, byteOrder);
|
|
31
|
+
|
|
32
|
+
offset += FIELD_COUNT_SIZE;
|
|
33
|
+
for (let fieldIndex = 0; fieldIndex < numberOfFields; fieldIndex++) {
|
|
34
|
+
if (offset + FIELD_SIZE > dataView.byteLength) {
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const tag = readTag(dataView, ifdType, tiffHeaderOffset, offset, byteOrder, includeUnknown);
|
|
39
|
+
if (tag !== undefined) {
|
|
40
|
+
tags[tag.name] = {
|
|
41
|
+
'id': tag.id,
|
|
42
|
+
'value': tag.value,
|
|
43
|
+
'description': tag.description
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
offset += FIELD_SIZE;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (Constants.USE_THUMBNAIL && (offset < dataView.byteLength - Types.getTypeSize('LONG'))) {
|
|
51
|
+
const nextIfdOffset = Types.getLongAt(dataView, offset, byteOrder);
|
|
52
|
+
if (nextIfdOffset !== 0 && ifdType === IFD_TYPE_0TH) {
|
|
53
|
+
tags['Thumbnail'] = readIfd(dataView, IFD_TYPE_1ST, tiffHeaderOffset, tiffHeaderOffset + nextIfdOffset, byteOrder, true);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return tags;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function getNumberOfFields(dataView, offset, byteOrder) {
|
|
61
|
+
if (offset + Types.getTypeSize('SHORT') <= dataView.byteLength) {
|
|
62
|
+
return Types.getShortAt(dataView, offset, byteOrder);
|
|
63
|
+
}
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function readTag(dataView, ifdType, tiffHeaderOffset, offset, byteOrder, includeUnknown) {
|
|
68
|
+
const TAG_CODE_IPTC_NAA = 0x83bb;
|
|
69
|
+
const TAG_TYPE_OFFSET = Types.getTypeSize('SHORT');
|
|
70
|
+
const TAG_COUNT_OFFSET = TAG_TYPE_OFFSET + Types.getTypeSize('SHORT');
|
|
71
|
+
const TAG_VALUE_OFFSET = TAG_COUNT_OFFSET + Types.getTypeSize('LONG');
|
|
72
|
+
|
|
73
|
+
const tagCode = Types.getShortAt(dataView, offset, byteOrder);
|
|
74
|
+
const tagType = Types.getShortAt(dataView, offset + TAG_TYPE_OFFSET, byteOrder);
|
|
75
|
+
const tagCount = Types.getLongAt(dataView, offset + TAG_COUNT_OFFSET, byteOrder);
|
|
76
|
+
let tagValue;
|
|
77
|
+
|
|
78
|
+
if (Types.typeSizes[tagType] === undefined || (!includeUnknown && TagNames[ifdType][tagCode] === undefined)) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (tagValueFitsInOffsetSlot(tagType, tagCount)) {
|
|
83
|
+
tagValue = getTagValue(dataView, offset + TAG_VALUE_OFFSET, tagType, tagCount, byteOrder);
|
|
84
|
+
} else {
|
|
85
|
+
const tagValueOffset = Types.getLongAt(dataView, offset + TAG_VALUE_OFFSET, byteOrder);
|
|
86
|
+
if (tagValueFitsInDataView(dataView, tiffHeaderOffset, tagValueOffset, tagType, tagCount)) {
|
|
87
|
+
const forceByteType = tagCode === TAG_CODE_IPTC_NAA;
|
|
88
|
+
tagValue = getTagValue(dataView, tiffHeaderOffset + tagValueOffset, tagType, tagCount, byteOrder, forceByteType);
|
|
89
|
+
} else {
|
|
90
|
+
tagValue = '<faulty value>';
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (tagType === Types.tagTypes['ASCII']) {
|
|
95
|
+
tagValue = splitNullSeparatedAsciiString(tagValue);
|
|
96
|
+
tagValue = decodeAsciiValue(tagValue);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
let tagName = `undefined-${tagCode}`;
|
|
100
|
+
let tagDescription = tagValue;
|
|
101
|
+
|
|
102
|
+
if (TagNames[ifdType][tagCode] !== undefined) {
|
|
103
|
+
if ((TagNames[ifdType][tagCode]['name'] !== undefined) && (TagNames[ifdType][tagCode]['description'] !== undefined)) {
|
|
104
|
+
tagName = TagNames[ifdType][tagCode]['name'];
|
|
105
|
+
try {
|
|
106
|
+
tagDescription = TagNames[ifdType][tagCode]['description'](tagValue);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
tagDescription = getDescriptionFromTagValue(tagValue);
|
|
109
|
+
}
|
|
110
|
+
} else if ((tagType === Types.tagTypes['RATIONAL']) || (tagType === Types.tagTypes['SRATIONAL'])) {
|
|
111
|
+
tagName = TagNames[ifdType][tagCode];
|
|
112
|
+
tagDescription = '' + (tagValue[0] / tagValue[1]);
|
|
113
|
+
} else {
|
|
114
|
+
tagName = TagNames[ifdType][tagCode];
|
|
115
|
+
tagDescription = getDescriptionFromTagValue(tagValue);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
id: tagCode,
|
|
121
|
+
name: tagName,
|
|
122
|
+
value: tagValue,
|
|
123
|
+
description: tagDescription
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function tagValueFitsInOffsetSlot(tagType, tagCount) {
|
|
128
|
+
return Types.typeSizes[tagType] * tagCount <= Types.getTypeSize('LONG');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function getTagValue(dataView, offset, type, count, byteOrder, forceByteType = false) {
|
|
132
|
+
let value = [];
|
|
133
|
+
|
|
134
|
+
if (forceByteType) {
|
|
135
|
+
count = count * Types.typeSizes[type];
|
|
136
|
+
type = Types.tagTypes['BYTE'];
|
|
137
|
+
}
|
|
138
|
+
for (let valueIndex = 0; valueIndex < count; valueIndex++) {
|
|
139
|
+
value.push(getTagValueAt[type](dataView, offset, byteOrder));
|
|
140
|
+
offset += Types.typeSizes[type];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (type === Types.tagTypes['ASCII']) {
|
|
144
|
+
value = Types.getAsciiValue(value);
|
|
145
|
+
} else if (value.length === 1) {
|
|
146
|
+
value = value[0];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return value;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function tagValueFitsInDataView(dataView, tiffHeaderOffset, tagValueOffset, tagType, tagCount) {
|
|
153
|
+
return tiffHeaderOffset + tagValueOffset + Types.typeSizes[tagType] * tagCount <= dataView.byteLength;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function splitNullSeparatedAsciiString(string) {
|
|
157
|
+
const tagValue = [];
|
|
158
|
+
let i = 0;
|
|
159
|
+
|
|
160
|
+
for (let j = 0; j < string.length; j++) {
|
|
161
|
+
if (string[j] === '\x00') {
|
|
162
|
+
i++;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (tagValue[i] === undefined) {
|
|
166
|
+
tagValue[i] = '';
|
|
167
|
+
}
|
|
168
|
+
tagValue[i] += string[j];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return tagValue;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function decodeAsciiValue(asciiValue) {
|
|
175
|
+
try {
|
|
176
|
+
return asciiValue.map((value) => decodeURIComponent(escape(value)));
|
|
177
|
+
} catch (error) {
|
|
178
|
+
return asciiValue;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function getDescriptionFromTagValue(tagValue) {
|
|
183
|
+
if (tagValue instanceof Array) {
|
|
184
|
+
return tagValue.join(', ');
|
|
185
|
+
}
|
|
186
|
+
return tagValue;
|
|
187
|
+
}
|