exifreader 4.47.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 +42 -28
- package/bin/build.js +3 -0
- package/bin/unshare-file.js +29 -0
- 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 +6 -6
- package/src/canon-tags.js +4 -3
- package/src/composite.js +94 -47
- package/src/exif-reader.js +61 -9
- package/src/file-loaders.js +64 -22
- package/src/icc-tag-names.js +2 -11
- package/src/image-header-iso-bmff.js +31 -10
- package/src/image-header-jpeg.js +9 -2
- package/src/image-header-png.js +34 -27
- package/src/iptc-tags.js +46 -11
- package/src/load-auto.js +6 -3
- package/src/loadview-pipeline.js +58 -23
- package/src/mpf-tags.js +6 -1
- package/src/pentax-tags.js +45 -21
- package/src/photoshop-tag-names.js +6 -2
- package/src/photoshop-tags.js +24 -23
- package/src/png-text-tags.js +175 -45
- package/src/tag-filter-config.js +25 -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/tags-helpers.js +177 -50
- package/src/tags.js +10 -0
- package/src/utils.js +185 -27
- package/src/xml.js +19 -2
- package/src/xmp-element-depth.js +226 -0
- package/src/xmp-namespaces.js +2 -2
- package/src/xmp-tags.js +38 -12
|
@@ -23,6 +23,9 @@ export const PathRecordTypes = {
|
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
const PATH_RECORD_SIZE = 24;
|
|
26
|
+
// Real clipping paths hold at most a few thousand records. The cap is shared by
|
|
27
|
+
// all PathInformation resources of one read so that splitting a path does not multiply it.
|
|
28
|
+
export const MAX_PATH_RECORDS = 32768;
|
|
26
29
|
|
|
27
30
|
export default {
|
|
28
31
|
0x07d0: {
|
|
@@ -38,12 +41,12 @@ export default {
|
|
|
38
41
|
},
|
|
39
42
|
};
|
|
40
43
|
|
|
41
|
-
function pathResource(dataView) {
|
|
44
|
+
function pathResource(dataView, recordBudget = {remaining: MAX_PATH_RECORDS}) {
|
|
42
45
|
const TYPE_SIZE = 2;
|
|
43
46
|
const types = {};
|
|
44
47
|
const paths = [];
|
|
45
48
|
|
|
46
|
-
for (let offset = 0; offset < dataView.byteLength; offset += TYPE_SIZE + PATH_RECORD_SIZE) {
|
|
49
|
+
for (let offset = 0; offset < dataView.byteLength && recordBudget.remaining > 0; offset += TYPE_SIZE + PATH_RECORD_SIZE) {
|
|
47
50
|
const type = Types.getShortAt(dataView, offset);
|
|
48
51
|
if (PATH_RECORD_TYPES[type]) {
|
|
49
52
|
if (!types[type]) {
|
|
@@ -53,6 +56,7 @@ function pathResource(dataView) {
|
|
|
53
56
|
type,
|
|
54
57
|
path: PATH_RECORD_TYPES[type].path(dataView, offset + TYPE_SIZE)
|
|
55
58
|
});
|
|
59
|
+
recordBudget.remaining--;
|
|
56
60
|
}
|
|
57
61
|
}
|
|
58
62
|
return JSON.stringify({types, paths});
|
package/src/photoshop-tags.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
// Specification: https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/
|
|
6
6
|
|
|
7
|
-
import {getDataView, getStringFromDataView, getPascalStringFromDataView, setProperty} from './utils.js';
|
|
7
|
+
import {getByteString, getDataView, getStringFromDataView, getPascalStringFromDataView, getTagKey, setProperty} from './utils.js';
|
|
8
8
|
import Types from './types.js';
|
|
9
|
-
import TagNames from './photoshop-tag-names.js';
|
|
9
|
+
import TagNames, {MAX_PATH_RECORDS} from './photoshop-tag-names.js';
|
|
10
10
|
import {NOOP_TAG_FILTER} from './tag-filter.js';
|
|
11
11
|
|
|
12
12
|
export default {
|
|
@@ -21,15 +21,25 @@ 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 {};
|
|
27
31
|
}
|
|
28
|
-
const
|
|
32
|
+
const byteArray = new Uint8Array(bytes);
|
|
33
|
+
const dataView = getDataView(byteArray.buffer);
|
|
34
|
+
const pathRecordBudget = {remaining: MAX_PATH_RECORDS};
|
|
29
35
|
const tags = {};
|
|
30
36
|
let offset = 0;
|
|
31
37
|
|
|
32
|
-
|
|
38
|
+
for (
|
|
39
|
+
let resourceCount = 0;
|
|
40
|
+
resourceCount < MAX_RESOURCES && offset + RESOURCE_BLOCK_MIN_HEADER_SIZE <= dataView.byteLength;
|
|
41
|
+
resourceCount++
|
|
42
|
+
) {
|
|
33
43
|
const signature = getStringFromDataView(dataView, offset, SIGNATURE_SIZE);
|
|
34
44
|
offset += SIGNATURE_SIZE;
|
|
35
45
|
const tagId = Types.getShortAt(dataView, offset);
|
|
@@ -45,8 +55,8 @@ function read(bytes, includeUnknown, tagFilter = NOOP_TAG_FILTER) {
|
|
|
45
55
|
// it by the bytes that are actually present.
|
|
46
56
|
const resourceSize = Math.min(declaredResourceSize, dataView.byteLength - offset);
|
|
47
57
|
if (signature === SIGNATURE) {
|
|
48
|
-
const
|
|
49
|
-
if (!tagFilter.shouldParseTag('photoshop',
|
|
58
|
+
const tagKey = getResourceTagKey(tagId, tagName);
|
|
59
|
+
if (!tagFilter.shouldParseTag('photoshop', tagKey, tagId)) {
|
|
50
60
|
offset += resourceSize + (resourceSize % 2);
|
|
51
61
|
continue;
|
|
52
62
|
}
|
|
@@ -54,17 +64,17 @@ function read(bytes, includeUnknown, tagFilter = NOOP_TAG_FILTER) {
|
|
|
54
64
|
const valueDataView = getDataView(dataView.buffer, offset, resourceSize);
|
|
55
65
|
const tag = {
|
|
56
66
|
id: tagId,
|
|
57
|
-
value:
|
|
67
|
+
value: getByteString(byteArray, offset, offset + resourceSize),
|
|
58
68
|
};
|
|
59
69
|
if (TagNames[tagId]) {
|
|
60
70
|
try {
|
|
61
|
-
tag.description = TagNames[tagId].description(valueDataView);
|
|
71
|
+
tag.description = TagNames[tagId].description(valueDataView, pathRecordBudget);
|
|
62
72
|
} catch (error) {
|
|
63
73
|
tag.description = '<no description formatter>';
|
|
64
74
|
}
|
|
65
|
-
setProperty(tags,
|
|
75
|
+
setProperty(tags, tagKey, tag);
|
|
66
76
|
} else if (includeUnknown) {
|
|
67
|
-
tags[
|
|
77
|
+
tags[tagKey] = tag;
|
|
68
78
|
}
|
|
69
79
|
}
|
|
70
80
|
offset += resourceSize + (resourceSize % 2);
|
|
@@ -73,20 +83,11 @@ function read(bytes, includeUnknown, tagFilter = NOOP_TAG_FILTER) {
|
|
|
73
83
|
return tags;
|
|
74
84
|
}
|
|
75
85
|
|
|
76
|
-
function
|
|
77
|
-
if (
|
|
78
|
-
return tagName;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (TagNames[tagId] && TagNames[tagId].name) {
|
|
82
|
-
return TagNames[tagId].name;
|
|
86
|
+
function getResourceTagKey(tagId, tagName) {
|
|
87
|
+
if (TagNames[tagId]) {
|
|
88
|
+
return getTagKey(tagName || TagNames[tagId].name);
|
|
83
89
|
}
|
|
84
|
-
|
|
85
|
-
if (includeUnknown) {
|
|
86
|
-
return `undefined-${tagId}`;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return undefined;
|
|
90
|
+
return `undefined-${tagId}`;
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
function getTagName(dataView, offset) {
|
package/src/png-text-tags.js
CHANGED
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
// Specification: http://www.libpng.org/pub/png/spec/1.2/
|
|
6
6
|
|
|
7
|
-
import {getStringValueFromArray, getStringFromDataView, decompress, setProperty, COMPRESSION_METHOD_NONE} from './utils.js';
|
|
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';
|
|
13
13
|
import {NOOP_TAG_FILTER} from './tag-filter.js';
|
|
14
|
+
import {addDecompressedValueAllowance, addDecompressedIptcAllowance} from './tags-helpers.js';
|
|
14
15
|
|
|
15
16
|
export default {
|
|
16
17
|
read
|
|
@@ -26,7 +27,26 @@ const COMPRESSION_FLAG_COMPRESSED = 1;
|
|
|
26
27
|
const EXIF_OFFSET = 6;
|
|
27
28
|
const MAX_COMPRESSED_TEXT_CHUNKS = 255;
|
|
28
29
|
const MAX_DECOMPRESSIONS_IN_FLIGHT = 4;
|
|
30
|
+
// PNG spec: a keyword is 1-79 bytes.
|
|
31
|
+
const MAX_KEYWORD_LENGTH = 79;
|
|
32
|
+
// Our own bound: BCP 47 sets no maximum, but real tags are far shorter.
|
|
33
|
+
const MAX_LANGUAGE_TAG_LENGTH = 79;
|
|
29
34
|
|
|
35
|
+
/**
|
|
36
|
+
* @param {number[]} pngTextChunks Chunk start offsets, where each chunk's length field is.
|
|
37
|
+
* @param {function(DataView, object, number): object} [getThumbnail] Called with a
|
|
38
|
+
* decoded Exif raw profile, its thumbnail IFD tags and the TIFF header offset;
|
|
39
|
+
* returns the thumbnail tags, with `image` set when the thumbnail was read.
|
|
40
|
+
* No thumbnail is returned when it is not passed.
|
|
41
|
+
* @returns {{readTags: object, embeddedExifTags: object|undefined, embeddedIptcTags: object|undefined, embeddedExifThumbnail: object|undefined, readTagsPromise: Promise<object[]>|undefined}}
|
|
42
|
+
* `readTags`, the two embedded groups and `embeddedExifThumbnail` come from
|
|
43
|
+
* uncompressed chunks and are ready at once; the embedded groups are undefined
|
|
44
|
+
* when no uncompressed raw profile was parsed, and `embeddedExifThumbnail` is
|
|
45
|
+
* the first thumbnail with an image. `readTagsPromise` resolves to one result
|
|
46
|
+
* per compressed chunk, in chunk order, each with its own
|
|
47
|
+
* `embeddedExifThumbnail` when it has one and no uncompressed chunk had one,
|
|
48
|
+
* and is undefined when none is read.
|
|
49
|
+
*/
|
|
30
50
|
function read(
|
|
31
51
|
dataView,
|
|
32
52
|
pngTextChunks,
|
|
@@ -35,30 +55,71 @@ function read(
|
|
|
35
55
|
computed = false,
|
|
36
56
|
tagFilter = NOOP_TAG_FILTER,
|
|
37
57
|
decompressConfig,
|
|
38
|
-
valueBudget
|
|
58
|
+
valueBudget,
|
|
59
|
+
getThumbnail
|
|
39
60
|
) {
|
|
40
61
|
const tags = {};
|
|
41
|
-
|
|
62
|
+
let embeddedExifTags;
|
|
63
|
+
let embeddedIptcTags;
|
|
64
|
+
let embeddedExifThumbnail;
|
|
65
|
+
const compressedChunks = [];
|
|
42
66
|
|
|
43
67
|
for (let i = 0; i < pngTextChunks.length; i++) {
|
|
44
|
-
const
|
|
45
|
-
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);
|
|
72
|
+
if (!textChunk) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
46
75
|
if (textChunk.compressionMethod === COMPRESSION_METHOD_NONE) {
|
|
47
|
-
const
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
76
|
+
const tag = getUncompressedTag(textChunk);
|
|
77
|
+
if (isRawProfileTag(tag)) {
|
|
78
|
+
const rawProfileTags = getTagsFromTextTag(
|
|
79
|
+
tag,
|
|
80
|
+
includeUnknown,
|
|
81
|
+
computed,
|
|
82
|
+
tagFilter,
|
|
83
|
+
valueBudget,
|
|
84
|
+
embeddedExifThumbnail ? undefined : getThumbnail
|
|
85
|
+
);
|
|
86
|
+
if (rawProfileTags.embeddedExifTags) {
|
|
87
|
+
embeddedExifTags = objectAssign(embeddedExifTags || {}, rawProfileTags.embeddedExifTags);
|
|
88
|
+
}
|
|
89
|
+
if (rawProfileTags.embeddedExifThumbnail) {
|
|
90
|
+
embeddedExifThumbnail = rawProfileTags.embeddedExifThumbnail;
|
|
91
|
+
}
|
|
92
|
+
if (rawProfileTags.embeddedIptcTags) {
|
|
93
|
+
embeddedIptcTags = objectAssign(embeddedIptcTags || {}, rawProfileTags.embeddedIptcTags);
|
|
94
|
+
}
|
|
95
|
+
} else if (tag.name && tagFilter.shouldParseGroup('png')) {
|
|
96
|
+
setProperty(tags, getTagKey(tag.name), {
|
|
97
|
+
value: tag.value,
|
|
98
|
+
description: tag.description
|
|
52
99
|
});
|
|
53
100
|
}
|
|
54
|
-
} else if (async &&
|
|
55
|
-
|
|
56
|
-
.then((tag) => getTagsFromDecompressedTag(tag, includeUnknown, computed, tagFilter, valueBudget)));
|
|
101
|
+
} else if (async && compressedChunks.length < MAX_COMPRESSED_TEXT_CHUNKS) {
|
|
102
|
+
compressedChunks.push(textChunk);
|
|
57
103
|
}
|
|
58
104
|
}
|
|
59
105
|
|
|
106
|
+
const compressedThumbnailReader = embeddedExifThumbnail ? undefined : getThumbnail;
|
|
107
|
+
const decompressionTasks = compressedChunks.map((textChunk) => () => decompressTextChunk(textChunk, decompressConfig)
|
|
108
|
+
.then((tag) => getTagsFromTextTag(
|
|
109
|
+
tag,
|
|
110
|
+
includeUnknown,
|
|
111
|
+
computed,
|
|
112
|
+
tagFilter,
|
|
113
|
+
valueBudget,
|
|
114
|
+
compressedThumbnailReader,
|
|
115
|
+
true
|
|
116
|
+
)));
|
|
117
|
+
|
|
60
118
|
return {
|
|
61
119
|
readTags: tags,
|
|
120
|
+
embeddedExifTags,
|
|
121
|
+
embeddedIptcTags,
|
|
122
|
+
embeddedExifThumbnail,
|
|
62
123
|
readTagsPromise: decompressionTasks.length > 0 ? runTasksInOrder(decompressionTasks, MAX_DECOMPRESSIONS_IN_FLIGHT) : undefined
|
|
63
124
|
};
|
|
64
125
|
}
|
|
@@ -66,15 +127,15 @@ function read(
|
|
|
66
127
|
function parseTextChunk(dataView, offset, length, type) {
|
|
67
128
|
const keywordChars = [];
|
|
68
129
|
const langChars = [];
|
|
69
|
-
const translatedKeywordChars = [];
|
|
70
130
|
let valueChars;
|
|
71
131
|
let parsingState = STATE_KEYWORD;
|
|
72
132
|
let compressionMethod = COMPRESSION_METHOD_NONE;
|
|
73
133
|
const byteOffset = dataView.byteOffset || 0;
|
|
134
|
+
const chunkEnd = Math.min(offset + length, dataView.byteLength);
|
|
74
135
|
|
|
75
136
|
for (let i = 0; i < length && offset + i < dataView.byteLength; i++) {
|
|
76
137
|
if (parsingState === STATE_COMPRESSION) {
|
|
77
|
-
compressionMethod = getCompressionMethod({type, dataView, offset: offset + i});
|
|
138
|
+
compressionMethod = getCompressionMethod({type, dataView, offset: offset + i, chunkEnd});
|
|
78
139
|
if (type === TYPE_ITXT) {
|
|
79
140
|
i += COMPRESSION_SECTION_ITXT_EXTRA_BYTE;
|
|
80
141
|
}
|
|
@@ -91,11 +152,15 @@ function parseTextChunk(dataView, offset, length, type) {
|
|
|
91
152
|
if (byte === 0) {
|
|
92
153
|
parsingState = moveToNextState(type, parsingState);
|
|
93
154
|
} else if (parsingState === STATE_KEYWORD) {
|
|
155
|
+
if (keywordChars.length >= MAX_KEYWORD_LENGTH) {
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
94
158
|
keywordChars.push(byte);
|
|
95
159
|
} else if (parsingState === STATE_LANG) {
|
|
160
|
+
if (langChars.length >= MAX_LANGUAGE_TAG_LENGTH) {
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
96
163
|
langChars.push(byte);
|
|
97
|
-
} else if (parsingState === STATE_TRANSLATED_KEYWORD) {
|
|
98
|
-
translatedKeywordChars.push(byte);
|
|
99
164
|
}
|
|
100
165
|
}
|
|
101
166
|
|
|
@@ -107,38 +172,47 @@ function getUncompressedTag({type, keywordChars, langChars, valueChars}) {
|
|
|
107
172
|
return constructTag(decodedValueChars, type, langChars, keywordChars);
|
|
108
173
|
}
|
|
109
174
|
|
|
110
|
-
function
|
|
111
|
-
return
|
|
112
|
-
.then((decompressedValueChars) => constructTag(decompressedValueChars, type, langChars, keywordChars))
|
|
113
|
-
.catch(() => constructTag('<text using unknown compression>'.split(''), type, langChars, keywordChars));
|
|
175
|
+
function isRawProfileTag({name, value}) {
|
|
176
|
+
return isExifGroupTag(name, value) || isIptcGroupTag(name, value);
|
|
114
177
|
}
|
|
115
178
|
|
|
116
|
-
function
|
|
179
|
+
function getTagsFromTextTag({name, value, description}, includeUnknown, computed, tagFilter, valueBudget, getThumbnail, isDecompressed) {
|
|
117
180
|
try {
|
|
118
181
|
if (Constants.USE_EXIF && isExifGroupTag(name, value)) {
|
|
119
182
|
if (!tagFilter.shouldParseGroup('exif')) {
|
|
120
183
|
return {};
|
|
121
184
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
185
|
+
const exifDataView = decodeRawData(value);
|
|
186
|
+
if (isDecompressed) {
|
|
187
|
+
addDecompressedValueAllowance(valueBudget, exifDataView.byteLength);
|
|
188
|
+
}
|
|
189
|
+
const embeddedExifTags = Tags.read(
|
|
190
|
+
exifDataView,
|
|
191
|
+
EXIF_OFFSET,
|
|
192
|
+
includeUnknown,
|
|
193
|
+
computed,
|
|
194
|
+
tagFilter,
|
|
195
|
+
valueBudget
|
|
196
|
+
).tags;
|
|
197
|
+
if (embeddedExifTags['MakerNote']) {
|
|
198
|
+
delete embeddedExifTags['MakerNote'].__offset;
|
|
199
|
+
}
|
|
200
|
+
return withEmbeddedExifThumbnail({embeddedExifTags}, exifDataView, getThumbnail);
|
|
132
201
|
} else if (Constants.USE_IPTC && isIptcGroupTag(name, value)) {
|
|
133
202
|
if (!tagFilter.shouldParseGroup('iptc')) {
|
|
134
203
|
return {};
|
|
135
204
|
}
|
|
205
|
+
const iptcDataView = decodeRawData(value);
|
|
206
|
+
if (isDecompressed) {
|
|
207
|
+
addDecompressedIptcAllowance(valueBudget, iptcDataView.byteLength);
|
|
208
|
+
}
|
|
136
209
|
return {
|
|
137
210
|
embeddedIptcTags: IptcTags.read(
|
|
138
|
-
|
|
211
|
+
iptcDataView,
|
|
139
212
|
0,
|
|
140
213
|
includeUnknown,
|
|
141
|
-
tagFilter
|
|
214
|
+
tagFilter,
|
|
215
|
+
valueBudget
|
|
142
216
|
)
|
|
143
217
|
};
|
|
144
218
|
} else if (name && !isExifGroupTag(name, value) && !isIptcGroupTag(name, value)) {
|
|
@@ -146,7 +220,7 @@ function getTagsFromDecompressedTag({name, value, description}, includeUnknown,
|
|
|
146
220
|
return {};
|
|
147
221
|
}
|
|
148
222
|
const readTags = {};
|
|
149
|
-
setProperty(readTags, name, {
|
|
223
|
+
setProperty(readTags, getTagKey(name), {
|
|
150
224
|
value,
|
|
151
225
|
description
|
|
152
226
|
});
|
|
@@ -158,6 +232,35 @@ function getTagsFromDecompressedTag({name, value, description}, includeUnknown,
|
|
|
158
232
|
return {};
|
|
159
233
|
}
|
|
160
234
|
|
|
235
|
+
function withEmbeddedExifThumbnail(result, exifDataView, getThumbnail) {
|
|
236
|
+
const thumbnailIfdTags = result.embeddedExifTags.Thumbnail;
|
|
237
|
+
if (!thumbnailIfdTags) {
|
|
238
|
+
return result;
|
|
239
|
+
}
|
|
240
|
+
delete result.embeddedExifTags.Thumbnail;
|
|
241
|
+
|
|
242
|
+
if (getThumbnail) {
|
|
243
|
+
const thumbnail = getThumbnail(exifDataView, thumbnailIfdTags, EXIF_OFFSET);
|
|
244
|
+
if (thumbnail.image) {
|
|
245
|
+
result.embeddedExifThumbnail = thumbnail;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function decompressTextChunk({type, keywordChars, langChars, compressionMethod, valueChars}, decompressConfig) {
|
|
252
|
+
if (valueChars === undefined) {
|
|
253
|
+
return Promise.resolve(constructPlaceholderTag(type, langChars, keywordChars));
|
|
254
|
+
}
|
|
255
|
+
return decompress(valueChars, compressionMethod, getEncodingFromType(type), 'string', decompressConfig)
|
|
256
|
+
.then((decompressedValueChars) => constructTag(decompressedValueChars, type, langChars, keywordChars))
|
|
257
|
+
.catch(() => constructPlaceholderTag(type, langChars, keywordChars));
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function constructPlaceholderTag(type, langChars, keywordChars) {
|
|
261
|
+
return constructTag('<text using unknown compression>', type, langChars, keywordChars);
|
|
262
|
+
}
|
|
263
|
+
|
|
161
264
|
function runTasksInOrder(tasks, limit) {
|
|
162
265
|
const results = [];
|
|
163
266
|
const workers = [];
|
|
@@ -182,9 +285,9 @@ function runTasksInOrder(tasks, limit) {
|
|
|
182
285
|
}
|
|
183
286
|
}
|
|
184
287
|
|
|
185
|
-
function getCompressionMethod({type, dataView, offset}) {
|
|
288
|
+
function getCompressionMethod({type, dataView, offset, chunkEnd}) {
|
|
186
289
|
if (type === TYPE_ITXT) {
|
|
187
|
-
if (offset + 1 <
|
|
290
|
+
if (offset + 1 < chunkEnd && dataView.getUint8(offset) === COMPRESSION_FLAG_COMPRESSED) {
|
|
188
291
|
return dataView.getUint8(offset + 1);
|
|
189
292
|
}
|
|
190
293
|
} else if (type === TYPE_ZTXT) {
|
|
@@ -255,14 +358,41 @@ function isIptcGroupTag(name, value) {
|
|
|
255
358
|
}
|
|
256
359
|
|
|
257
360
|
function decodeRawData(value) {
|
|
258
|
-
const
|
|
259
|
-
|
|
361
|
+
const header = /\n(exif|iptc)\n\s*\d+\n/.exec(value);
|
|
362
|
+
if (!header) {
|
|
363
|
+
throw new Error('Invalid raw profile header.');
|
|
364
|
+
}
|
|
365
|
+
const dataStart = header.index + header[0].length;
|
|
366
|
+
const digitCount = countHexDigits(value, dataStart);
|
|
367
|
+
if (digitCount % 2 !== 0) {
|
|
368
|
+
throw new Error('Odd number of hex digits in raw profile.');
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const bytes = new Uint8Array(digitCount / 2);
|
|
372
|
+
let byteIndex = 0;
|
|
373
|
+
let highNibble = -1;
|
|
374
|
+
for (let i = dataStart; i < value.length; i++) {
|
|
375
|
+
const nibble = getHexDigitValue(value.charCodeAt(i));
|
|
376
|
+
if (nibble < 0) {
|
|
377
|
+
// Newlines and any other non-hex character are skipped, as ImageMagick and exiv2 do.
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
if (highNibble < 0) {
|
|
381
|
+
highNibble = nibble;
|
|
382
|
+
} else {
|
|
383
|
+
bytes[byteIndex++] = (highNibble << 4) | nibble;
|
|
384
|
+
highNibble = -1;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return new DataView(bytes.buffer);
|
|
260
388
|
}
|
|
261
389
|
|
|
262
|
-
function
|
|
263
|
-
|
|
264
|
-
for (let i =
|
|
265
|
-
|
|
390
|
+
function countHexDigits(value, start) {
|
|
391
|
+
let count = 0;
|
|
392
|
+
for (let i = start; i < value.length; i++) {
|
|
393
|
+
if (getHexDigitValue(value.charCodeAt(i)) >= 0) {
|
|
394
|
+
count++;
|
|
395
|
+
}
|
|
266
396
|
}
|
|
267
|
-
return
|
|
397
|
+
return count;
|
|
268
398
|
}
|
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',
|
|
@@ -62,6 +77,8 @@ export const COMPOSITE_DEPENDENCY_TAGS = {
|
|
|
62
77
|
'FocalPlaneYResolution',
|
|
63
78
|
'FocalPlaneResolutionUnit',
|
|
64
79
|
'FocalLengthIn35mmFilm',
|
|
80
|
+
'PixelXDimension',
|
|
81
|
+
'PixelYDimension',
|
|
65
82
|
],
|
|
66
83
|
};
|
|
67
84
|
|
|
@@ -97,6 +114,14 @@ export function getExifTagDependenciesForInclude(includeTags) {
|
|
|
97
114
|
function addPointerDependenciesFromExifTagSelectors(pointerSet, selectors) {
|
|
98
115
|
for (let i = 0; i < selectors.length; i++) {
|
|
99
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
|
+
}
|
|
100
125
|
if (typeof selector !== 'string') {
|
|
101
126
|
continue;
|
|
102
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
|
}
|