exifreader 4.53.0 → 4.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/package.json +1 -1
- package/src/base64-image.js +27 -0
- package/src/dom-parser.js +5 -6
- package/src/engine.js +388 -0
- package/src/exif-reader.js +540 -892
- package/src/image-header-avif.js +7 -8
- package/src/image-header-gif.js +9 -10
- package/src/image-header-heic.js +7 -8
- package/src/image-header-iso-bmff.js +71 -92
- package/src/image-header-jpeg.js +60 -59
- package/src/image-header-jxl.js +59 -65
- package/src/image-header-png.js +199 -76
- package/src/image-header-tiff.js +7 -4
- package/src/image-header-webp.js +29 -35
- package/src/image-header.js +22 -22
- package/src/loadview-pipeline.js +285 -446
- package/src/mpf-tags.js +10 -7
- package/src/png-text-tags.js +88 -327
- package/src/tag-filter.js +52 -0
- package/src/tag-names-0th-ifd.js +2 -2
- package/src/tag-names-utils.js +5 -7
- package/src/tags-helpers.js +8 -22
- package/src/tags.js +23 -11
- package/src/thumbnail.js +7 -5
- package/src/utils.js +42 -34
- package/src/writer/exif-tag-table.js +321 -0
- package/src/xml.js +12 -15
- package/src/xmp-tags.js +9 -10
package/src/mpf-tags.js
CHANGED
|
@@ -6,7 +6,7 @@ import ByteOrder from './byte-order.js';
|
|
|
6
6
|
import Types from './types.js';
|
|
7
7
|
import TagNamesMpfIfd from './tag-names-mpf-ifd.js';
|
|
8
8
|
import {IFD_TYPE_MPF} from './ifd-types.js';
|
|
9
|
-
import {deferInit
|
|
9
|
+
import {deferInit} from './utils.js';
|
|
10
10
|
import {readIfd, get0thIfdOffset} from './tags-helpers.js';
|
|
11
11
|
|
|
12
12
|
export default {
|
|
@@ -31,7 +31,8 @@ function read(
|
|
|
31
31
|
includeUnknown,
|
|
32
32
|
computed = false,
|
|
33
33
|
tagFilter = undefined,
|
|
34
|
-
valueBudget = undefined
|
|
34
|
+
valueBudget = undefined,
|
|
35
|
+
getBase64Image = undefined
|
|
35
36
|
) {
|
|
36
37
|
try {
|
|
37
38
|
const byteOrder = ByteOrder.getByteOrder(dataView, dataOffset);
|
|
@@ -52,7 +53,7 @@ function read(
|
|
|
52
53
|
valueBudget,
|
|
53
54
|
getTagNames()
|
|
54
55
|
);
|
|
55
|
-
return addMpfImages(dataView, dataOffset, tags, byteOrder);
|
|
56
|
+
return addMpfImages(dataView, dataOffset, tags, byteOrder, getBase64Image);
|
|
56
57
|
} catch (error) {
|
|
57
58
|
return {};
|
|
58
59
|
}
|
|
@@ -65,7 +66,7 @@ function getTagNames() {
|
|
|
65
66
|
return tagNames;
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
function addMpfImages(dataView, dataOffset, tags, byteOrder) {
|
|
69
|
+
function addMpfImages(dataView, dataOffset, tags, byteOrder, getBase64Image) {
|
|
69
70
|
if (!tags['MPEntry']) {
|
|
70
71
|
return tags;
|
|
71
72
|
}
|
|
@@ -115,9 +116,11 @@ function addMpfImages(dataView, dataOffset, tags, byteOrder) {
|
|
|
115
116
|
const end = Math.min(start + Math.max(imageSize, 0), bufferLength, start + remainingImageBytes);
|
|
116
117
|
images[i].image = dataView.buffer.slice(byteOffset + start, byteOffset + end);
|
|
117
118
|
remainingImageBytes -= end - start;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
if (getBase64Image) {
|
|
120
|
+
deferInit(images[i], 'base64', function () {
|
|
121
|
+
return getBase64Image(this.image);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
121
124
|
}
|
|
122
125
|
|
|
123
126
|
tags['Images'] = images;
|
package/src/png-text-tags.js
CHANGED
|
@@ -4,355 +4,125 @@
|
|
|
4
4
|
|
|
5
5
|
// Specification: http://www.libpng.org/pub/png/spec/1.2/
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {getStringFromDataView, decompress, getCompressionMethod, setProperty, getTagKey, COMPRESSION_METHOD_NONE, getHexDigitValue} from './utils.js';
|
|
8
8
|
import TagDecoder from './tag-decoder.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {addDecompressedValueAllowance, addDecompressedIptcAllowance, takeEmbeddedExifThumbnail} from './tags-helpers.js';
|
|
9
|
+
import {TYPE_TEXT, TYPE_ITXT, TYPE_ZTXT, EXIF_PROFILE_NAME, IPTC_PROFILE_NAME} from './image-header-png.js';
|
|
10
|
+
import {filterTagsForParse} from './tag-filter.js';
|
|
12
11
|
|
|
13
12
|
export default {
|
|
14
13
|
read
|
|
15
14
|
};
|
|
16
15
|
|
|
17
|
-
const STATE_KEYWORD = 'STATE_KEYWORD';
|
|
18
|
-
const STATE_COMPRESSION = 'STATE_COMPRESSION';
|
|
19
|
-
const STATE_LANG = 'STATE_LANG';
|
|
20
|
-
const STATE_TRANSLATED_KEYWORD = 'STATE_TRANSLATED_KEYWORD';
|
|
21
|
-
const STATE_TEXT = 'STATE_TEXT';
|
|
22
|
-
const COMPRESSION_SECTION_ITXT_EXTRA_BYTE = 1;
|
|
23
|
-
const COMPRESSION_FLAG_COMPRESSED = 1;
|
|
24
16
|
const EXIF_OFFSET = 6;
|
|
25
17
|
const MAX_COMPRESSED_TEXT_CHUNKS = 255;
|
|
26
|
-
const MAX_DECOMPRESSIONS_IN_FLIGHT = 4;
|
|
27
|
-
// PNG spec: a keyword is 1-79 bytes.
|
|
28
|
-
const MAX_KEYWORD_LENGTH = 79;
|
|
29
|
-
const IPTC_PROFILE_NAME = 'raw profile type iptc';
|
|
30
|
-
// Our own bound: BCP 47 sets no maximum, but real tags are far shorter.
|
|
31
|
-
const MAX_LANGUAGE_TAG_LENGTH = 79;
|
|
32
18
|
|
|
33
19
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @param {
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* profiles: `exif(dataView, tiffHeaderOffset, includeUnknown, computed,
|
|
48
|
-
* tagFilter, valueBudget)` as Tags.read and `iptc(dataView, offset,
|
|
49
|
-
* includeUnknown, tagFilter, valueBudget)` as IptcTags.read. A profile
|
|
50
|
-
* whose reader is missing is neither decoded nor read.
|
|
51
|
-
* @returns {{readTags: object, embeddedExifTags: object|undefined, embeddedIptcTags: object|undefined, embeddedExifThumbnail: object|undefined, exifCarriedGroups: object|undefined, readTagsPromise: Promise<object[]>|undefined}}
|
|
52
|
-
* `readTags`, the two embedded groups, `exifCarriedGroups` and
|
|
53
|
-
* `embeddedExifThumbnail` come from uncompressed chunks and are ready at
|
|
54
|
-
* once; the embedded groups and `exifCarriedGroups` are undefined when no
|
|
55
|
-
* uncompressed raw profile was parsed, and `embeddedExifThumbnail` is the
|
|
56
|
-
* first thumbnail with an image. `readTagsPromise` resolves to one result per
|
|
57
|
-
* compressed chunk, in chunk order, each with its own `exifCarriedGroups`, and
|
|
58
|
-
* its own `embeddedExifThumbnail` when it has one and no uncompressed chunk
|
|
59
|
-
* had one, and is undefined when none is read.
|
|
20
|
+
* Reads one PNG text-chunk block: `{kind, compression?, text: {chunkType, name,
|
|
21
|
+
* valueOffset, valueLength}}`. A block whose `text.name` is undefined (a
|
|
22
|
+
* keyword or language tag over 79 bytes) is skipped, and so is a compressed
|
|
23
|
+
* chunk past the first MAX_COMPRESSED_TEXT_CHUNKS of a load.
|
|
24
|
+
*
|
|
25
|
+
* @param {object} block The finder's block.
|
|
26
|
+
* @param {object} context The load context: `dataView`, `tagFilter` and the
|
|
27
|
+
* pooled `decompress`.
|
|
28
|
+
* @returns {{tags: object, blocks?: Array<object>}|Promise<{tags: object, blocks?: Array<object>}>|undefined}
|
|
29
|
+
* The text tag, parse-filtered, or for a raw profile no tags and an emitted
|
|
30
|
+
* exif or iptc block whose `getDataView()` decodes the profile on demand
|
|
31
|
+
* (and throws on a bad one). A compressed chunk gives a promise; a
|
|
32
|
+
* decompression failure gives a placeholder text tag.
|
|
60
33
|
*/
|
|
61
|
-
function read(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
async,
|
|
65
|
-
includeUnknown,
|
|
66
|
-
computed = false,
|
|
67
|
-
tagFilter = NOOP_TAG_FILTER,
|
|
68
|
-
decompressConfig,
|
|
69
|
-
valueBudget,
|
|
70
|
-
getThumbnail,
|
|
71
|
-
readCarriedGroups,
|
|
72
|
-
rawProfileReaders = {}
|
|
73
|
-
) {
|
|
74
|
-
const tags = {};
|
|
75
|
-
let embeddedExifTags;
|
|
76
|
-
let embeddedIptcTags;
|
|
77
|
-
let embeddedExifThumbnail;
|
|
78
|
-
let exifCarriedGroups;
|
|
79
|
-
const uncompressedRawProfiles = [];
|
|
80
|
-
const compressedChunks = [];
|
|
81
|
-
|
|
82
|
-
for (let i = 0; i < pngTextChunks.length; i++) {
|
|
83
|
-
const chunkOffset = pngTextChunks[i];
|
|
84
|
-
const length = dataView.getUint32(chunkOffset + PNG_CHUNK_LENGTH_OFFSET);
|
|
85
|
-
const type = getStringFromDataView(dataView, chunkOffset + PNG_CHUNK_TYPE_OFFSET, PNG_CHUNK_TYPE_SIZE);
|
|
86
|
-
const textChunk = parseTextChunk(dataView, chunkOffset + PNG_CHUNK_DATA_OFFSET, length, type);
|
|
87
|
-
if (!textChunk) {
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
if (textChunk.compressionMethod === COMPRESSION_METHOD_NONE) {
|
|
91
|
-
const tag = getUncompressedTag(textChunk);
|
|
92
|
-
if (isRawProfileTag(tag)) {
|
|
93
|
-
uncompressedRawProfiles.push(tag);
|
|
94
|
-
} else if (tag.name && tagFilter.shouldParseGroup('png')) {
|
|
95
|
-
setProperty(tags, getTagKey(tag.name), {
|
|
96
|
-
value: tag.value,
|
|
97
|
-
description: tag.description
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
} else if (async && compressedChunks.length < MAX_COMPRESSED_TEXT_CHUNKS) {
|
|
101
|
-
compressedChunks.push(textChunk);
|
|
102
|
-
}
|
|
34
|
+
function read(block, context) {
|
|
35
|
+
if (block.text.name === undefined) {
|
|
36
|
+
return undefined;
|
|
103
37
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|| compressedChunks.some(isCompressedIptcProfile);
|
|
107
|
-
|
|
108
|
-
for (let i = 0; i < uncompressedRawProfiles.length; i++) {
|
|
109
|
-
const rawProfileTags = getTagsFromTextTag(
|
|
110
|
-
uncompressedRawProfiles[i],
|
|
111
|
-
includeUnknown,
|
|
112
|
-
computed,
|
|
113
|
-
tagFilter,
|
|
114
|
-
valueBudget,
|
|
115
|
-
embeddedExifThumbnail ? undefined : getThumbnail,
|
|
116
|
-
readCarriedGroups,
|
|
117
|
-
false,
|
|
118
|
-
hasIptcProfile,
|
|
119
|
-
rawProfileReaders
|
|
120
|
-
);
|
|
121
|
-
if (rawProfileTags.embeddedExifTags) {
|
|
122
|
-
embeddedExifTags = objectAssign(embeddedExifTags || {}, rawProfileTags.embeddedExifTags);
|
|
123
|
-
}
|
|
124
|
-
if (rawProfileTags.exifCarriedGroups) {
|
|
125
|
-
exifCarriedGroups = mergeCarriedGroups(exifCarriedGroups || {}, rawProfileTags.exifCarriedGroups);
|
|
126
|
-
}
|
|
127
|
-
if (rawProfileTags.embeddedExifThumbnail) {
|
|
128
|
-
embeddedExifThumbnail = rawProfileTags.embeddedExifThumbnail;
|
|
129
|
-
}
|
|
130
|
-
if (rawProfileTags.embeddedIptcTags) {
|
|
131
|
-
embeddedIptcTags = objectAssign(embeddedIptcTags || {}, rawProfileTags.embeddedIptcTags);
|
|
132
|
-
}
|
|
38
|
+
if (block.compression === undefined) {
|
|
39
|
+
return classify(getUncompressedTag(context.dataView, block.text), context, false);
|
|
133
40
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
includeUnknown,
|
|
140
|
-
computed,
|
|
141
|
-
tagFilter,
|
|
142
|
-
valueBudget,
|
|
143
|
-
compressedThumbnailReader,
|
|
144
|
-
readCarriedGroups,
|
|
145
|
-
true,
|
|
146
|
-
hasIptcProfile,
|
|
147
|
-
rawProfileReaders
|
|
148
|
-
)));
|
|
149
|
-
|
|
150
|
-
return {
|
|
151
|
-
readTags: tags,
|
|
152
|
-
embeddedExifTags,
|
|
153
|
-
embeddedIptcTags,
|
|
154
|
-
embeddedExifThumbnail,
|
|
155
|
-
exifCarriedGroups,
|
|
156
|
-
readTagsPromise: decompressionTasks.length > 0 ? runTasksInOrder(decompressionTasks, MAX_DECOMPRESSIONS_IN_FLIGHT) : undefined
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// A compressed profile counts before its value can be checked.
|
|
161
|
-
function isCompressedIptcProfile({type, langChars, keywordChars}) {
|
|
162
|
-
return getName(type, langChars, keywordChars).toLowerCase() === IPTC_PROFILE_NAME;
|
|
41
|
+
if (context.compressedPngTextChunks >= MAX_COMPRESSED_TEXT_CHUNKS) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
context.compressedPngTextChunks++;
|
|
45
|
+
return decompressTextChunk(context, block).then((tag) => classify(tag, context, true));
|
|
163
46
|
}
|
|
164
47
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
48
|
+
// The payload check keeps a chunk whose keyword says profile but whose payload
|
|
49
|
+
// does not as a plain text tag.
|
|
50
|
+
function classify({name, value, description}, context, decompressed) {
|
|
51
|
+
if (isExifGroupTag(name, value)) {
|
|
52
|
+
return {tags: {}, blocks: [{kind: 'exif', tiffHeaderOffset: EXIF_OFFSET, origin: 'rawProfile', decompressed, getDataView: () => decodeRawData(value)}]};
|
|
53
|
+
}
|
|
54
|
+
if (isIptcGroupTag(name, value)) {
|
|
55
|
+
return {tags: {}, blocks: [{kind: 'iptc', dataOffset: 0, origin: 'rawProfile', decompressed, getDataView: () => decodeRawData(value)}]};
|
|
169
56
|
}
|
|
170
|
-
|
|
57
|
+
if (name && context.tagFilter.shouldParseGroup('png')) {
|
|
58
|
+
const tags = {};
|
|
59
|
+
setProperty(tags, getTagKey(name), {value, description});
|
|
60
|
+
return {tags: filterTagsForParse('png', tags, context.tagFilter)};
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
171
63
|
}
|
|
172
64
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
parsingState = moveToNextState(type, parsingState);
|
|
65
|
+
/**
|
|
66
|
+
* Whether the finder blocks hold a `Raw profile type iptc` text chunk that
|
|
67
|
+
* `read` will read: by payload for an uncompressed chunk, by keyword alone for
|
|
68
|
+
* a compressed one among the first MAX_COMPRESSED_TEXT_CHUNKS named compressed
|
|
69
|
+
* chunks, the ones `read` decompresses.
|
|
70
|
+
*
|
|
71
|
+
* @param {Array<object>} finderBlocks In dispatch order.
|
|
72
|
+
* @param {DataView} dataView The file.
|
|
73
|
+
* @returns {boolean}
|
|
74
|
+
*/
|
|
75
|
+
export function hasRawIptcProfile(finderBlocks, dataView) {
|
|
76
|
+
let compressedChunks = 0;
|
|
77
|
+
for (let i = 0; i < finderBlocks.length; i++) {
|
|
78
|
+
const block = finderBlocks[i];
|
|
79
|
+
if (block.text === undefined || block.text.name === undefined) {
|
|
189
80
|
continue;
|
|
190
|
-
} else if (parsingState === STATE_TEXT) {
|
|
191
|
-
const slice = dataView.buffer.slice(byteOffset + offset + i, byteOffset + offset + length);
|
|
192
|
-
valueChars = new DataView(slice);
|
|
193
|
-
break;
|
|
194
81
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (keywordChars.length >= MAX_KEYWORD_LENGTH) {
|
|
200
|
-
return undefined;
|
|
201
|
-
}
|
|
202
|
-
keywordChars.push(byte);
|
|
203
|
-
} else if (parsingState === STATE_LANG) {
|
|
204
|
-
if (langChars.length >= MAX_LANGUAGE_TAG_LENGTH) {
|
|
205
|
-
return undefined;
|
|
82
|
+
if (block.compression !== undefined) {
|
|
83
|
+
compressedChunks++;
|
|
84
|
+
if (block.kind === 'iptc' && compressedChunks <= MAX_COMPRESSED_TEXT_CHUNKS) {
|
|
85
|
+
return true;
|
|
206
86
|
}
|
|
207
|
-
|
|
87
|
+
} else if (block.kind === 'iptc' && isUncompressedIptcProfile(block, dataView)) {
|
|
88
|
+
return true;
|
|
208
89
|
}
|
|
209
90
|
}
|
|
210
|
-
|
|
211
|
-
return {type, keywordChars, langChars, compressionMethod, valueChars};
|
|
91
|
+
return false;
|
|
212
92
|
}
|
|
213
93
|
|
|
214
|
-
function
|
|
215
|
-
const
|
|
216
|
-
return
|
|
94
|
+
function isUncompressedIptcProfile(block, dataView) {
|
|
95
|
+
const tag = getUncompressedTag(dataView, block.text);
|
|
96
|
+
return isIptcGroupTag(tag.name, tag.value);
|
|
217
97
|
}
|
|
218
98
|
|
|
219
|
-
function
|
|
220
|
-
|
|
99
|
+
function getUncompressedTag(dataView, text) {
|
|
100
|
+
const decodedValueChars = decompress(getValueView(dataView, text), COMPRESSION_METHOD_NONE, getEncodingFromType(text.chunkType), 'string');
|
|
101
|
+
return constructTag(decodedValueChars, text.chunkType, text.name);
|
|
221
102
|
}
|
|
222
103
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
const exifDataView = decodeRawData(value);
|
|
230
|
-
if (isDecompressed) {
|
|
231
|
-
addDecompressedValueAllowance(valueBudget, exifDataView.byteLength);
|
|
232
|
-
}
|
|
233
|
-
const {tags: embeddedExifTags, byteOrder} = rawProfileReaders.exif(
|
|
234
|
-
exifDataView,
|
|
235
|
-
EXIF_OFFSET,
|
|
236
|
-
includeUnknown,
|
|
237
|
-
computed,
|
|
238
|
-
tagFilter,
|
|
239
|
-
valueBudget
|
|
240
|
-
);
|
|
241
|
-
const result = {embeddedExifTags};
|
|
242
|
-
if (readCarriedGroups) {
|
|
243
|
-
result.exifCarriedGroups = readCarriedGroups(
|
|
244
|
-
exifDataView,
|
|
245
|
-
embeddedExifTags,
|
|
246
|
-
EXIF_OFFSET,
|
|
247
|
-
byteOrder,
|
|
248
|
-
valueBudget,
|
|
249
|
-
{decompressed: isDecompressed, hasIptcBlock: hasIptcProfile}
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
if (embeddedExifTags['MakerNote']) {
|
|
253
|
-
delete embeddedExifTags['MakerNote'].__offset;
|
|
254
|
-
}
|
|
255
|
-
const thumbnail = takeEmbeddedExifThumbnail(embeddedExifTags, exifDataView, EXIF_OFFSET, getThumbnail);
|
|
256
|
-
if (thumbnail) {
|
|
257
|
-
result.embeddedExifThumbnail = thumbnail;
|
|
258
|
-
}
|
|
259
|
-
return result;
|
|
260
|
-
} else if (isIptcGroupTag(name, value)) {
|
|
261
|
-
if (!rawProfileReaders.iptc || !tagFilter.shouldParseGroup('iptc')) {
|
|
262
|
-
return {};
|
|
263
|
-
}
|
|
264
|
-
const iptcDataView = decodeRawData(value);
|
|
265
|
-
if (isDecompressed) {
|
|
266
|
-
addDecompressedIptcAllowance(valueBudget, iptcDataView.byteLength);
|
|
267
|
-
}
|
|
268
|
-
return {
|
|
269
|
-
embeddedIptcTags: rawProfileReaders.iptc(
|
|
270
|
-
iptcDataView,
|
|
271
|
-
0,
|
|
272
|
-
includeUnknown,
|
|
273
|
-
tagFilter,
|
|
274
|
-
valueBudget
|
|
275
|
-
)
|
|
276
|
-
};
|
|
277
|
-
} else if (name) {
|
|
278
|
-
if (!tagFilter.shouldParseGroup('png')) {
|
|
279
|
-
return {};
|
|
280
|
-
}
|
|
281
|
-
const readTags = {};
|
|
282
|
-
setProperty(readTags, getTagKey(name), {
|
|
283
|
-
value,
|
|
284
|
-
description
|
|
285
|
-
});
|
|
286
|
-
return {readTags};
|
|
287
|
-
}
|
|
288
|
-
} catch (error) {
|
|
289
|
-
// Ignore the broken tag.
|
|
290
|
-
}
|
|
291
|
-
return {};
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
function decompressTextChunk({type, keywordChars, langChars, compressionMethod, valueChars}, decompressConfig) {
|
|
295
|
-
if (valueChars === undefined) {
|
|
296
|
-
return Promise.resolve(constructPlaceholderTag(type, langChars, keywordChars));
|
|
297
|
-
}
|
|
298
|
-
return decompress(valueChars, compressionMethod, getEncodingFromType(type), 'string', decompressConfig)
|
|
299
|
-
.then((decompressedValueChars) => constructTag(decompressedValueChars, type, langChars, keywordChars))
|
|
300
|
-
.catch(() => constructPlaceholderTag(type, langChars, keywordChars));
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
function constructPlaceholderTag(type, langChars, keywordChars) {
|
|
304
|
-
return constructTag('<text using unknown compression>', type, langChars, keywordChars);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
function runTasksInOrder(tasks, limit) {
|
|
308
|
-
const results = [];
|
|
309
|
-
const workers = [];
|
|
310
|
-
let nextIndex = 0;
|
|
311
|
-
|
|
312
|
-
for (let i = 0; i < Math.min(limit, tasks.length); i++) {
|
|
313
|
-
workers.push(runNext());
|
|
314
|
-
}
|
|
315
|
-
return Promise.all(workers).then(() => results);
|
|
316
|
-
|
|
317
|
-
function runNext() {
|
|
318
|
-
if (nextIndex >= tasks.length) {
|
|
319
|
-
return Promise.resolve();
|
|
320
|
-
}
|
|
321
|
-
const index = nextIndex++;
|
|
322
|
-
// The wrapper turns a synchronous throw from a task into a rejection
|
|
323
|
-
// that Promise.all observes, instead of an exception out of read().
|
|
324
|
-
return new Promise((resolve) => resolve(tasks[index]())).then((result) => {
|
|
325
|
-
results[index] = result;
|
|
326
|
-
return runNext();
|
|
327
|
-
});
|
|
104
|
+
// The same slice the parser made while it copied the value: the chunk's declared
|
|
105
|
+
// end, clamped to the buffer by slice itself.
|
|
106
|
+
function getValueView(dataView, {valueOffset, valueLength}) {
|
|
107
|
+
if (valueOffset === undefined) {
|
|
108
|
+
return undefined;
|
|
328
109
|
}
|
|
110
|
+
const byteOffset = dataView.byteOffset;
|
|
111
|
+
return new DataView(dataView.buffer.slice(byteOffset + valueOffset, byteOffset + valueOffset + valueLength));
|
|
329
112
|
}
|
|
330
113
|
|
|
331
|
-
function
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
336
|
-
} else if (type === TYPE_ZTXT) {
|
|
337
|
-
return dataView.getUint8(offset);
|
|
114
|
+
function decompressTextChunk(context, {compression, text}) {
|
|
115
|
+
const valueView = getValueView(context.dataView, text);
|
|
116
|
+
if (valueView === undefined) {
|
|
117
|
+
return Promise.resolve(constructPlaceholderTag(text));
|
|
338
118
|
}
|
|
339
|
-
return
|
|
119
|
+
return context.decompress(valueView, getCompressionMethod(compression), getEncodingFromType(text.chunkType), 'string')
|
|
120
|
+
.then((decompressedValueChars) => constructTag(decompressedValueChars, text.chunkType, text.name))
|
|
121
|
+
.catch(() => constructPlaceholderTag(text));
|
|
340
122
|
}
|
|
341
123
|
|
|
342
|
-
function
|
|
343
|
-
|
|
344
|
-
return STATE_COMPRESSION;
|
|
345
|
-
}
|
|
346
|
-
if (parsingState === STATE_COMPRESSION) {
|
|
347
|
-
if (type === TYPE_ITXT) {
|
|
348
|
-
return STATE_LANG;
|
|
349
|
-
}
|
|
350
|
-
return STATE_TEXT;
|
|
351
|
-
}
|
|
352
|
-
if (parsingState === STATE_LANG) {
|
|
353
|
-
return STATE_TRANSLATED_KEYWORD;
|
|
354
|
-
}
|
|
355
|
-
return STATE_TEXT;
|
|
124
|
+
function constructPlaceholderTag({chunkType, name}) {
|
|
125
|
+
return constructTag('<text using unknown compression>', chunkType, name);
|
|
356
126
|
}
|
|
357
127
|
|
|
358
128
|
function getEncodingFromType(type) {
|
|
@@ -362,25 +132,16 @@ function getEncodingFromType(type) {
|
|
|
362
132
|
return 'utf-8';
|
|
363
133
|
}
|
|
364
134
|
|
|
365
|
-
function constructTag(valueChars,
|
|
135
|
+
function constructTag(valueChars, chunkType, name) {
|
|
366
136
|
const value = getValue(valueChars);
|
|
367
137
|
|
|
368
138
|
return {
|
|
369
|
-
name
|
|
139
|
+
name,
|
|
370
140
|
value,
|
|
371
|
-
description:
|
|
141
|
+
description: chunkType === TYPE_ITXT ? getDescription(valueChars) : value
|
|
372
142
|
};
|
|
373
143
|
}
|
|
374
144
|
|
|
375
|
-
function getName(type, langChars, keywordChars) {
|
|
376
|
-
const name = getStringValueFromArray(keywordChars);
|
|
377
|
-
if (type === TYPE_TEXT || langChars.length === 0) {
|
|
378
|
-
return name;
|
|
379
|
-
}
|
|
380
|
-
const lang = getStringValueFromArray(langChars);
|
|
381
|
-
return `${name} (${lang})`;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
145
|
function getValue(valueChars) {
|
|
385
146
|
if (valueChars instanceof DataView) {
|
|
386
147
|
return getStringFromDataView(valueChars, 0, valueChars.byteLength);
|
|
@@ -393,7 +154,7 @@ function getDescription(valueChars) {
|
|
|
393
154
|
}
|
|
394
155
|
|
|
395
156
|
function isExifGroupTag(name, value) {
|
|
396
|
-
return name.toLowerCase() ===
|
|
157
|
+
return name.toLowerCase() === EXIF_PROFILE_NAME && value.substring(1, 5) === 'exif';
|
|
397
158
|
}
|
|
398
159
|
|
|
399
160
|
function isIptcGroupTag(name, value) {
|
package/src/tag-filter.js
CHANGED
|
@@ -2,6 +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 {setProperty} from './utils.js';
|
|
5
6
|
import {
|
|
6
7
|
FILTER_GROUPS,
|
|
7
8
|
ID_CAPABLE_GROUPS,
|
|
@@ -409,3 +410,54 @@ function addRequiredTags(requiredTags, tags) {
|
|
|
409
410
|
requiredTags[tags[i]] = true;
|
|
410
411
|
}
|
|
411
412
|
}
|
|
413
|
+
|
|
414
|
+
export function filterTagsForParse(groupKey, readTags, tagFilter) {
|
|
415
|
+
if (!tagFilter.isActive) {
|
|
416
|
+
return readTags;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
return filterTags(groupKey, readTags, tagFilter.shouldParseTag);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
export function filterTagsForReturn(groupKey, readTags, tagFilter) {
|
|
423
|
+
if (!tagFilter.isActive) {
|
|
424
|
+
return readTags;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return filterTags(groupKey, readTags, tagFilter.shouldReturnTag);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
export function filterTags(groupKey, readTags, matchesTag) {
|
|
431
|
+
if (!readTags) {
|
|
432
|
+
return readTags;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
const filteredTags = {};
|
|
436
|
+
|
|
437
|
+
for (const tagName in readTags) {
|
|
438
|
+
const tagValue = readTags[tagName];
|
|
439
|
+
const tagId = getTagId(tagValue);
|
|
440
|
+
|
|
441
|
+
if (matchesTag(groupKey, tagName, tagId)) {
|
|
442
|
+
setProperty(filteredTags, tagName, tagValue);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
return filteredTags;
|
|
447
|
+
|
|
448
|
+
function getTagId(tagValue) {
|
|
449
|
+
if (!tagValue) {
|
|
450
|
+
return undefined;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
if (Array.isArray(tagValue)) {
|
|
454
|
+
if (tagValue.length === 0) {
|
|
455
|
+
return undefined;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
return tagValue[0].id;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
return tagValue.id;
|
|
462
|
+
}
|
|
463
|
+
}
|
package/src/tag-names-0th-ifd.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import TagNamesCommon from './tag-names-common.js';
|
|
6
6
|
import {joinMapped} from './utils.js';
|
|
7
|
-
import {getTableDescription,
|
|
7
|
+
import {getTableDescription, isArrayWithoutCharacterCodes, getStringsText} from './tag-names-utils.js';
|
|
8
8
|
|
|
9
9
|
export default {
|
|
10
10
|
0x000b: 'ProcessingSoftware',
|
|
@@ -385,7 +385,7 @@ function decodeXPValue(value) {
|
|
|
385
385
|
// A one-element value arrives as a bare number, which Uint8Array would take as a length.
|
|
386
386
|
return '';
|
|
387
387
|
}
|
|
388
|
-
if (
|
|
388
|
+
if (isArrayWithoutCharacterCodes(value)) {
|
|
389
389
|
// An ASCII-typed value holds strings, not UCS-2 bytes.
|
|
390
390
|
return getStringsText(value);
|
|
391
391
|
}
|
package/src/tag-names-utils.js
CHANGED
|
@@ -7,7 +7,7 @@ import {getStringValueFromArray as getStringValue, getByteString} from './utils.
|
|
|
7
7
|
export {getStringValue};
|
|
8
8
|
|
|
9
9
|
export function getEncodedString(value) {
|
|
10
|
-
if (
|
|
10
|
+
if (isArrayWithoutCharacterCodes(value)) {
|
|
11
11
|
return getStringsText(value) || 'Undefined';
|
|
12
12
|
}
|
|
13
13
|
if (value.length >= 8) {
|
|
@@ -41,7 +41,7 @@ export function getEncodedString(value) {
|
|
|
41
41
|
*/
|
|
42
42
|
export function getVersionString(value) {
|
|
43
43
|
if (Array.isArray(value)) {
|
|
44
|
-
if (
|
|
44
|
+
if (isArrayWithoutCharacterCodes(value)) {
|
|
45
45
|
return getStringsText(value);
|
|
46
46
|
}
|
|
47
47
|
return getByteString(value);
|
|
@@ -50,14 +50,12 @@ export function getVersionString(value) {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* piece was, index 0 included; a rational value holds number pairs. Neither
|
|
56
|
-
* has character codes to convert, and an empty array has none either.
|
|
53
|
+
* An ASCII-typed value holds strings, with a hole where an empty piece was,
|
|
54
|
+
* index 0 included, and a rational value holds number pairs.
|
|
57
55
|
* @param {*} value
|
|
58
56
|
* @returns {boolean} True for an array whose element 0 is not a number.
|
|
59
57
|
*/
|
|
60
|
-
export function
|
|
58
|
+
export function isArrayWithoutCharacterCodes(value) {
|
|
61
59
|
return Array.isArray(value) && typeof value[0] !== 'number';
|
|
62
60
|
}
|
|
63
61
|
|