exifreader 4.46.0 → 4.48.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 +100 -34
- package/bin/TagFilterPlugin.js +23 -14
- package/bin/analyze.js +345 -0
- package/bin/build.js +13 -2
- package/bin/cli.js +449 -23
- package/bin/custom-build-marker.js +78 -0
- package/bin/unshare-file.js +29 -0
- package/bin/verify-build.js +147 -0
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/package.json +3 -3
- package/src/canon-tags.js +4 -2
- package/src/composite.js +94 -47
- package/src/exif-reader.js +81 -16
- package/src/file-loaders.js +204 -30
- package/src/image-header-iso-bmff-iloc.js +5 -2
- package/src/image-header-iso-bmff.js +41 -10
- package/src/image-header-jpeg.js +9 -2
- package/src/image-header-png.js +33 -21
- package/src/iptc-tags.js +46 -11
- package/src/load-auto.js +6 -3
- package/src/loadview-pipeline.js +111 -61
- package/src/mpf-tags.js +10 -3
- package/src/pentax-tags.js +49 -23
- package/src/photoshop-tag-names.js +6 -2
- package/src/photoshop-tags.js +15 -22
- package/src/png-text-tags.js +237 -77
- package/src/tag-decoder.js +10 -10
- package/src/tag-filter-config.js +2 -0
- package/src/tag-filter.js +2 -0
- package/src/tag-names-0th-ifd.js +13 -1
- package/src/tags-helpers.js +220 -44
- package/src/tags.js +22 -4
- package/src/types.js +0 -5
- package/src/utils.js +260 -32
- package/src/xml.js +19 -2
- package/src/xmp-element-depth.js +226 -0
- package/src/xmp-namespaces.js +22 -7
- package/src/xmp-tags.js +285 -165
package/src/iptc-tags.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import IptcTagNames from './iptc-tag-names.js';
|
|
6
6
|
import TagDecoder from './tag-decoder.js';
|
|
7
7
|
import {NOOP_TAG_FILTER} from './tag-filter.js';
|
|
8
|
+
import {getValueBudget, BYTES_PER_IPTC_DATASET, IPTC_DATASET_HEADER_SIZE} from './tags-helpers.js';
|
|
8
9
|
|
|
9
10
|
const BYTES_8BIM = 0x3842494d;
|
|
10
11
|
const BYTES_8BIM_SIZE = 4;
|
|
@@ -14,25 +15,36 @@ const RESOURCE_NAME_MIN_SIZE = 2;
|
|
|
14
15
|
const RESOURCE_SIZE_SIZE = 4;
|
|
15
16
|
const RESOURCE_BLOCK_MIN_HEADER_SIZE = BYTES_8BIM_SIZE + RESOURCE_ID_SIZE + RESOURCE_NAME_MIN_SIZE + RESOURCE_SIZE_SIZE;
|
|
16
17
|
const NAA_RESOURCE_BLOCK_TYPE = 0x0404; // Sometimes called resource ID.
|
|
17
|
-
const TAG_HEADER_SIZE = 5;
|
|
18
18
|
|
|
19
19
|
export default {
|
|
20
20
|
read
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Reads the IPTC datasets of an NAA resource block, or of a naked IPTC block
|
|
25
|
+
* given as an array of bytes.
|
|
26
|
+
*
|
|
27
|
+
* @param {{iptcDatasetsRemaining: number}} [valueBudget] - The per-load budget
|
|
28
|
+
* from getValueBudget. Each dataset header read draws from its
|
|
29
|
+
* iptcDatasetsRemaining, and reading stops when it runs out, returning the
|
|
30
|
+
* tags read so far. Omitted, a budget is sized from the data read.
|
|
31
|
+
* @returns {Object} The read tags, keyed by tag name.
|
|
32
|
+
*/
|
|
33
|
+
function read(dataView, dataOffset, includeUnknown, tagFilter = NOOP_TAG_FILTER, valueBudget) {
|
|
24
34
|
try {
|
|
25
35
|
if (Array.isArray(dataView)) {
|
|
36
|
+
const arrayDataView = new DataView(Uint8Array.from(dataView).buffer);
|
|
26
37
|
return parseTags(
|
|
27
|
-
|
|
38
|
+
arrayDataView,
|
|
28
39
|
{size: dataView.length},
|
|
29
40
|
0,
|
|
30
41
|
includeUnknown,
|
|
31
|
-
tagFilter
|
|
42
|
+
tagFilter,
|
|
43
|
+
valueBudget || getValueBudget(arrayDataView)
|
|
32
44
|
);
|
|
33
45
|
}
|
|
34
46
|
const {naaBlock, dataOffset: newDataOffset} = getNaaResourceBlock(dataView, dataOffset);
|
|
35
|
-
return parseTags(dataView, naaBlock, newDataOffset, includeUnknown, tagFilter);
|
|
47
|
+
return parseTags(dataView, naaBlock, newDataOffset, includeUnknown, tagFilter, valueBudget || getValueBudget(dataView));
|
|
36
48
|
} catch (error) {
|
|
37
49
|
return {};
|
|
38
50
|
}
|
|
@@ -76,7 +88,7 @@ function getBlockPadding(resourceBlock) {
|
|
|
76
88
|
return 0;
|
|
77
89
|
}
|
|
78
90
|
|
|
79
|
-
function parseTags(dataView, naaBlock, dataOffset, includeUnknown, tagFilter) {
|
|
91
|
+
function parseTags(dataView, naaBlock, dataOffset, includeUnknown, tagFilter, valueBudget) {
|
|
80
92
|
const tags = {};
|
|
81
93
|
let encoding = undefined;
|
|
82
94
|
|
|
@@ -89,7 +101,8 @@ function parseTags(dataView, naaBlock, dataOffset, includeUnknown, tagFilter) {
|
|
|
89
101
|
tags,
|
|
90
102
|
encoding,
|
|
91
103
|
includeUnknown,
|
|
92
|
-
tagFilter
|
|
104
|
+
tagFilter,
|
|
105
|
+
valueBudget
|
|
93
106
|
);
|
|
94
107
|
|
|
95
108
|
if (tag === null) {
|
|
@@ -123,7 +136,7 @@ function parseTags(dataView, naaBlock, dataOffset, includeUnknown, tagFilter) {
|
|
|
123
136
|
}
|
|
124
137
|
}
|
|
125
138
|
|
|
126
|
-
dataOffset +=
|
|
139
|
+
dataOffset += IPTC_DATASET_HEADER_SIZE + tagSize;
|
|
127
140
|
}
|
|
128
141
|
|
|
129
142
|
return tags;
|
|
@@ -135,18 +148,23 @@ function readTag(
|
|
|
135
148
|
tags = {},
|
|
136
149
|
encoding = undefined,
|
|
137
150
|
includeUnknown = false,
|
|
138
|
-
tagFilter = NOOP_TAG_FILTER
|
|
151
|
+
tagFilter = NOOP_TAG_FILTER,
|
|
152
|
+
valueBudget
|
|
139
153
|
) {
|
|
140
154
|
const TAG_CODE_OFFSET = 1;
|
|
141
155
|
const TAG_SIZE_OFFSET = 3;
|
|
142
156
|
|
|
143
|
-
if (leadByteIsMissing(dataView, dataOffset)) {
|
|
157
|
+
if (leadByteIsMissing(dataView, dataOffset) || headerIsTruncated(dataView, dataOffset)) {
|
|
144
158
|
return {tag: null, tagSize: 0};
|
|
145
159
|
}
|
|
146
160
|
|
|
147
161
|
const tagCode = dataView.getUint16(dataOffset + TAG_CODE_OFFSET);
|
|
148
162
|
const tagSize = dataView.getUint16(dataOffset + TAG_SIZE_OFFSET);
|
|
149
163
|
|
|
164
|
+
if (valueIsTruncated(dataView, dataOffset, tagSize) || !takeDatasetUnits(valueBudget, tagSize)) {
|
|
165
|
+
return {tag: null, tagSize: 0};
|
|
166
|
+
}
|
|
167
|
+
|
|
150
168
|
if (!includeUnknown && !IptcTagNames['iptc'][tagCode]) {
|
|
151
169
|
return {tag: undefined, tagSize};
|
|
152
170
|
}
|
|
@@ -159,7 +177,7 @@ function readTag(
|
|
|
159
177
|
return {tag: undefined, tagSize};
|
|
160
178
|
}
|
|
161
179
|
|
|
162
|
-
const tagValue = getTagValue(dataView, dataOffset +
|
|
180
|
+
const tagValue = getTagValue(dataView, dataOffset + IPTC_DATASET_HEADER_SIZE, tagSize);
|
|
163
181
|
|
|
164
182
|
const tag = {
|
|
165
183
|
id: tagCode,
|
|
@@ -177,6 +195,15 @@ function readTag(
|
|
|
177
195
|
return {tag, tagSize};
|
|
178
196
|
}
|
|
179
197
|
|
|
198
|
+
function takeDatasetUnits(valueBudget, tagSize) {
|
|
199
|
+
const units = Math.ceil((IPTC_DATASET_HEADER_SIZE + tagSize) / BYTES_PER_IPTC_DATASET);
|
|
200
|
+
if (valueBudget.iptcDatasetsRemaining >= units) {
|
|
201
|
+
valueBudget.iptcDatasetsRemaining -= units;
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
|
|
180
207
|
function getIptcTagNameForFiltering(tagCode, includeUnknown) {
|
|
181
208
|
const tag = IptcTagNames['iptc'][tagCode];
|
|
182
209
|
if (!tag) {
|
|
@@ -203,6 +230,14 @@ function leadByteIsMissing(dataView, dataOffset) {
|
|
|
203
230
|
return dataView.getUint8(dataOffset) !== TAG_LEAD_BYTE;
|
|
204
231
|
}
|
|
205
232
|
|
|
233
|
+
function headerIsTruncated(dataView, dataOffset) {
|
|
234
|
+
return dataOffset + IPTC_DATASET_HEADER_SIZE > dataView.byteLength;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function valueIsTruncated(dataView, dataOffset, tagSize) {
|
|
238
|
+
return dataOffset + IPTC_DATASET_HEADER_SIZE + tagSize > dataView.byteLength;
|
|
239
|
+
}
|
|
240
|
+
|
|
206
241
|
function getTagValue(dataView, offset, size) {
|
|
207
242
|
const value = [];
|
|
208
243
|
|
package/src/load-auto.js
CHANGED
|
@@ -55,19 +55,22 @@ export function makeLoadAuto(loadFromData) {
|
|
|
55
55
|
|
|
56
56
|
function loadAdaptiveFromFilenameOrUrl(filename, options) {
|
|
57
57
|
if (/^\w+:\/\//.test(filename)) {
|
|
58
|
+
// Cap at `end`, not `end - start`: a 200 replaces the buffer from byte 0.
|
|
58
59
|
if (typeof fetch !== 'undefined') {
|
|
59
60
|
return adaptiveLoop({
|
|
60
|
-
readRange: (start, end) => fetchRange(filename, {start, end}),
|
|
61
|
+
readRange: (start, end) => fetchRange(filename, {start, end, maxBytes: end}),
|
|
61
62
|
options,
|
|
62
63
|
});
|
|
63
64
|
}
|
|
64
65
|
return adaptiveLoop({
|
|
65
|
-
readRange: (start, end) => nodeGetRange(filename, {start, end}),
|
|
66
|
+
readRange: (start, end) => nodeGetRange(filename, {start, end, maxBytes: end}),
|
|
66
67
|
options,
|
|
67
68
|
});
|
|
68
69
|
}
|
|
69
70
|
if (isDataUri(filename)) {
|
|
70
|
-
return
|
|
71
|
+
return Promise.resolve()
|
|
72
|
+
.then(() => dataUriToBuffer(filename))
|
|
73
|
+
.then((buffer) => loadAdaptiveFromMemory(buffer, options));
|
|
71
74
|
}
|
|
72
75
|
return adaptiveLoop({
|
|
73
76
|
readRange: (start, end, ctx) => readLocalFileRange(filename, {
|
package/src/loadview-pipeline.js
CHANGED
|
@@ -20,6 +20,7 @@ export function buildTagsFromMergeSteps({
|
|
|
20
20
|
deps,
|
|
21
21
|
}) {
|
|
22
22
|
let tags = {};
|
|
23
|
+
const embeddedExifThumbnails = [];
|
|
23
24
|
|
|
24
25
|
for (let i = 0; i < mergeSteps.length; i++) {
|
|
25
26
|
tags = applyMergeStep({
|
|
@@ -33,6 +34,7 @@ export function buildTagsFromMergeSteps({
|
|
|
33
34
|
exifDataView,
|
|
34
35
|
fileType,
|
|
35
36
|
thumbnailIfdTags,
|
|
37
|
+
embeddedExifThumbnails,
|
|
36
38
|
tags,
|
|
37
39
|
deps,
|
|
38
40
|
});
|
|
@@ -73,6 +75,7 @@ export function applyMergeStep({
|
|
|
73
75
|
exifDataView,
|
|
74
76
|
fileType,
|
|
75
77
|
thumbnailIfdTags,
|
|
78
|
+
embeddedExifThumbnails = [],
|
|
76
79
|
tags,
|
|
77
80
|
deps,
|
|
78
81
|
}) {
|
|
@@ -195,8 +198,11 @@ export function applyMergeStep({
|
|
|
195
198
|
}
|
|
196
199
|
|
|
197
200
|
if (Constants.USE_PNG && step.type === 'processPngTextReadTags') {
|
|
201
|
+
addEmbeddedExifThumbnail(embeddedExifThumbnails, step.embeddedExifThumbnail);
|
|
198
202
|
return addPngTextReadTagsToTagsAndGroups({
|
|
199
203
|
readTags: step.readTags,
|
|
204
|
+
embeddedExifTags: step.embeddedExifTags,
|
|
205
|
+
embeddedIptcTags: step.embeddedIptcTags,
|
|
200
206
|
parsedGroups,
|
|
201
207
|
expanded,
|
|
202
208
|
tagFilter,
|
|
@@ -207,15 +213,21 @@ export function applyMergeStep({
|
|
|
207
213
|
|
|
208
214
|
if (Constants.USE_PNG && step.type === 'processPngTextReadTagsDeferredList') {
|
|
209
215
|
const tagList = deferredResults[step.deferredKey] || [];
|
|
216
|
+
const merge = createInPlaceMerge(deps);
|
|
210
217
|
|
|
211
218
|
for (let i = 0; i < tagList.length; i++) {
|
|
219
|
+
const entry = tagList[i];
|
|
220
|
+
addEmbeddedExifThumbnail(embeddedExifThumbnails, entry.embeddedExifThumbnail);
|
|
212
221
|
tags = addPngTextReadTagsToTagsAndGroups({
|
|
213
|
-
readTags:
|
|
222
|
+
readTags: entry.readTags || {},
|
|
223
|
+
embeddedExifTags: entry.embeddedExifTags,
|
|
224
|
+
embeddedIptcTags: entry.embeddedIptcTags,
|
|
214
225
|
parsedGroups,
|
|
215
226
|
expanded,
|
|
216
227
|
tagFilter,
|
|
217
228
|
tags,
|
|
218
229
|
deps,
|
|
230
|
+
merge,
|
|
219
231
|
});
|
|
220
232
|
}
|
|
221
233
|
|
|
@@ -269,32 +281,30 @@ export function applyMergeStep({
|
|
|
269
281
|
}
|
|
270
282
|
|
|
271
283
|
if (step.type === 'thumbnail') {
|
|
284
|
+
// Flat output can already hold an XMP or PNG text tag named Thumbnail.
|
|
285
|
+
delete tags.Thumbnail;
|
|
286
|
+
|
|
272
287
|
if (
|
|
273
288
|
!tagFilter.shouldReturnGroup('thumbnail')
|
|
274
289
|
|| !tagFilter.shouldReturnTag('thumbnail', 'Thumbnail')
|
|
275
290
|
) {
|
|
276
|
-
delete tags.Thumbnail;
|
|
277
|
-
|
|
278
|
-
return tags;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
if (!thumbnailIfdTags) {
|
|
282
291
|
return tags;
|
|
283
292
|
}
|
|
284
293
|
|
|
285
|
-
const
|
|
286
|
-
'thumbnail',
|
|
294
|
+
const mainThumbnail = getMainThumbnail({
|
|
287
295
|
thumbnailIfdTags,
|
|
288
|
-
tagFilter
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
296
|
+
tagFilter,
|
|
297
|
+
dataView,
|
|
298
|
+
exifDataView,
|
|
299
|
+
tiffHeaderOffset,
|
|
300
|
+
deps,
|
|
301
|
+
});
|
|
302
|
+
let thumbnail = mainThumbnail;
|
|
303
|
+
if (!hasImage(mainThumbnail)) {
|
|
304
|
+
thumbnail = getFirstEmbeddedExifThumbnailWithImage(embeddedExifThumbnails) || mainThumbnail;
|
|
305
|
+
}
|
|
294
306
|
if (thumbnail) {
|
|
295
307
|
tags.Thumbnail = thumbnail;
|
|
296
|
-
} else {
|
|
297
|
-
delete tags.Thumbnail;
|
|
298
308
|
}
|
|
299
309
|
|
|
300
310
|
return tags;
|
|
@@ -317,6 +327,9 @@ export function applyMergeStep({
|
|
|
317
327
|
}
|
|
318
328
|
|
|
319
329
|
if (step.type === 'fileType') {
|
|
330
|
+
// Flat output can already hold an XMP or PNG text tag named FileType.
|
|
331
|
+
delete tags.FileType;
|
|
332
|
+
|
|
320
333
|
if (
|
|
321
334
|
fileType
|
|
322
335
|
&& tagFilter.shouldReturnGroup('file')
|
|
@@ -338,6 +351,39 @@ export function applyMergeStep({
|
|
|
338
351
|
return tags;
|
|
339
352
|
}
|
|
340
353
|
|
|
354
|
+
function addEmbeddedExifThumbnail(embeddedExifThumbnails, embeddedExifThumbnail) {
|
|
355
|
+
if (embeddedExifThumbnail) {
|
|
356
|
+
embeddedExifThumbnails.push(embeddedExifThumbnail);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function getMainThumbnail({thumbnailIfdTags, tagFilter, dataView, exifDataView, tiffHeaderOffset, deps}) {
|
|
361
|
+
if (!thumbnailIfdTags) {
|
|
362
|
+
return undefined;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const parsedThumbnailIfdTags = deps.filterTagsForParse(
|
|
366
|
+
'thumbnail',
|
|
367
|
+
thumbnailIfdTags,
|
|
368
|
+
tagFilter
|
|
369
|
+
);
|
|
370
|
+
|
|
371
|
+
return Constants.USE_EXIF
|
|
372
|
+
&& Constants.USE_THUMBNAIL
|
|
373
|
+
&& deps.Thumbnail.get(exifDataView || dataView, parsedThumbnailIfdTags, tiffHeaderOffset);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function hasImage(thumbnail) {
|
|
377
|
+
return !!thumbnail && !!thumbnail.image;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function getFirstEmbeddedExifThumbnailWithImage(embeddedExifThumbnails) {
|
|
381
|
+
if (!(Constants.USE_PNG && Constants.USE_EXIF && Constants.USE_THUMBNAIL)) {
|
|
382
|
+
return undefined;
|
|
383
|
+
}
|
|
384
|
+
return embeddedExifThumbnails.filter(hasImage)[0];
|
|
385
|
+
}
|
|
386
|
+
|
|
341
387
|
export function mergeAssignGroup(tags, groupKey, returnedTags, expanded, deps) {
|
|
342
388
|
if (expanded) {
|
|
343
389
|
tags[groupKey] = returnedTags;
|
|
@@ -377,25 +423,19 @@ export function mergeMergeGroup(tags, groupKey, returnedTags, expanded, deps) {
|
|
|
377
423
|
|
|
378
424
|
export function addPngTextReadTagsToTagsAndGroups({
|
|
379
425
|
readTags,
|
|
426
|
+
embeddedExifTags,
|
|
427
|
+
embeddedIptcTags,
|
|
380
428
|
parsedGroups,
|
|
381
429
|
expanded,
|
|
382
430
|
tagFilter,
|
|
383
431
|
tags,
|
|
384
432
|
deps,
|
|
433
|
+
merge = createCopyingMerge(deps),
|
|
385
434
|
}) {
|
|
386
|
-
const embeddedExifTags = readTags.__exif;
|
|
387
|
-
const embeddedIptcTags = readTags.__iptc;
|
|
388
|
-
delete readTags.__exif;
|
|
389
|
-
delete readTags.__iptc;
|
|
390
|
-
|
|
391
435
|
if (embeddedExifTags) {
|
|
392
436
|
const parsedEmbeddedExifTags =
|
|
393
437
|
deps.filterTagsForParse('exif', embeddedExifTags, tagFilter);
|
|
394
|
-
parsedGroups
|
|
395
|
-
{},
|
|
396
|
-
parsedGroups.exif,
|
|
397
|
-
parsedEmbeddedExifTags
|
|
398
|
-
);
|
|
438
|
+
merge.group(parsedGroups, 'exif', parsedEmbeddedExifTags);
|
|
399
439
|
|
|
400
440
|
if (tagFilter.shouldReturnGroup('exif')) {
|
|
401
441
|
const returnedEmbeddedExifTags = deps.filterTagsForReturn(
|
|
@@ -404,19 +444,9 @@ export function addPngTextReadTagsToTagsAndGroups({
|
|
|
404
444
|
tagFilter
|
|
405
445
|
);
|
|
406
446
|
if (expanded) {
|
|
407
|
-
tags
|
|
408
|
-
{},
|
|
409
|
-
tags.exif,
|
|
410
|
-
returnedEmbeddedExifTags
|
|
411
|
-
);
|
|
447
|
+
merge.group(tags, 'exif', returnedEmbeddedExifTags);
|
|
412
448
|
} else {
|
|
413
|
-
|
|
414
|
-
// thumbnail IFD would land at the top level with no image.
|
|
415
|
-
const returnedEmbeddedExifTagsForFlat =
|
|
416
|
-
deps.objectAssign({}, returnedEmbeddedExifTags);
|
|
417
|
-
delete returnedEmbeddedExifTagsForFlat.Thumbnail;
|
|
418
|
-
|
|
419
|
-
tags = deps.objectAssign({}, tags, returnedEmbeddedExifTagsForFlat);
|
|
449
|
+
tags = merge.topLevel(tags, returnedEmbeddedExifTags);
|
|
420
450
|
}
|
|
421
451
|
}
|
|
422
452
|
}
|
|
@@ -424,11 +454,7 @@ export function addPngTextReadTagsToTagsAndGroups({
|
|
|
424
454
|
if (embeddedIptcTags) {
|
|
425
455
|
const parsedEmbeddedIptcTags =
|
|
426
456
|
deps.filterTagsForParse('iptc', embeddedIptcTags, tagFilter);
|
|
427
|
-
parsedGroups
|
|
428
|
-
{},
|
|
429
|
-
parsedGroups.iptc,
|
|
430
|
-
parsedEmbeddedIptcTags
|
|
431
|
-
);
|
|
457
|
+
merge.group(parsedGroups, 'iptc', parsedEmbeddedIptcTags);
|
|
432
458
|
|
|
433
459
|
if (tagFilter.shouldReturnGroup('iptc')) {
|
|
434
460
|
const returnedEmbeddedIptcTags = deps.filterTagsForReturn(
|
|
@@ -437,13 +463,9 @@ export function addPngTextReadTagsToTagsAndGroups({
|
|
|
437
463
|
tagFilter
|
|
438
464
|
);
|
|
439
465
|
if (expanded) {
|
|
440
|
-
tags
|
|
441
|
-
{},
|
|
442
|
-
tags.iptc,
|
|
443
|
-
returnedEmbeddedIptcTags
|
|
444
|
-
);
|
|
466
|
+
merge.group(tags, 'iptc', returnedEmbeddedIptcTags);
|
|
445
467
|
} else {
|
|
446
|
-
tags =
|
|
468
|
+
tags = merge.topLevel(tags, returnedEmbeddedIptcTags);
|
|
447
469
|
}
|
|
448
470
|
}
|
|
449
471
|
}
|
|
@@ -455,30 +477,58 @@ export function addPngTextReadTagsToTagsAndGroups({
|
|
|
455
477
|
parsedGroups.pngText = parsedPngTextTags;
|
|
456
478
|
|
|
457
479
|
if (expanded) {
|
|
458
|
-
tags
|
|
459
|
-
{},
|
|
460
|
-
tags.png,
|
|
461
|
-
returnedPngTextTags
|
|
462
|
-
);
|
|
480
|
+
merge.group(tags, 'png', returnedPngTextTags);
|
|
463
481
|
// Historical behavior in build fixtures:
|
|
464
482
|
// - if PNG text chunks yield actual "png" tags, `pngText` should contain only those
|
|
465
483
|
// - otherwise (e.g. only embedded Exif/IPTC), `pngText` should represent the full `png` group
|
|
466
484
|
// and will be filled in later as a fallback from `tags.png`
|
|
467
485
|
if (returnedPngTextTags && Object.keys(returnedPngTextTags).length > 0) {
|
|
468
|
-
tags
|
|
469
|
-
{},
|
|
470
|
-
tags.pngText,
|
|
471
|
-
returnedPngTextTags
|
|
472
|
-
);
|
|
486
|
+
merge.group(tags, 'pngText', returnedPngTextTags);
|
|
473
487
|
}
|
|
474
488
|
} else {
|
|
475
|
-
tags =
|
|
489
|
+
tags = merge.topLevel(tags, returnedPngTextTags);
|
|
476
490
|
}
|
|
477
491
|
}
|
|
478
492
|
|
|
479
493
|
return tags;
|
|
480
494
|
}
|
|
481
495
|
|
|
496
|
+
function createCopyingMerge(deps) {
|
|
497
|
+
return {
|
|
498
|
+
group(holder, key, source) {
|
|
499
|
+
holder[key] = !holder[key] ? source : deps.objectAssign({}, holder[key], source);
|
|
500
|
+
},
|
|
501
|
+
topLevel(tags, source) {
|
|
502
|
+
return deps.objectAssign({}, tags, source);
|
|
503
|
+
},
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function createInPlaceMerge(deps) {
|
|
508
|
+
const ownedContainers = [];
|
|
509
|
+
|
|
510
|
+
return {
|
|
511
|
+
group(holder, key, source) {
|
|
512
|
+
holder[key] = own(holder[key]);
|
|
513
|
+
deps.objectAssign(holder[key], source);
|
|
514
|
+
},
|
|
515
|
+
topLevel(tags, source) {
|
|
516
|
+
return deps.objectAssign(own(tags), source);
|
|
517
|
+
},
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
// Earlier steps can share these containers (tags.png can be tags.pngFile or the
|
|
521
|
+
// synchronous text chunks' tags), so each is copied once before merging in place.
|
|
522
|
+
function own(container) {
|
|
523
|
+
if (ownedContainers.indexOf(container) !== -1) {
|
|
524
|
+
return container;
|
|
525
|
+
}
|
|
526
|
+
const copy = deps.objectAssign({}, container);
|
|
527
|
+
ownedContainers.push(copy);
|
|
528
|
+
return copy;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
482
532
|
export function isThenable(value) {
|
|
483
533
|
return !!value && typeof value.then === 'function';
|
|
484
534
|
}
|
package/src/mpf-tags.js
CHANGED
|
@@ -20,12 +20,17 @@ const ENTRY_SIZE = 16;
|
|
|
20
20
|
// proportional to its size instead of n^2.
|
|
21
21
|
const MAX_IMAGE_SIZE_PER_BUFFER_SIZE = 8;
|
|
22
22
|
|
|
23
|
+
// Real MPF files carry a handful of images (the corpus maximum is 2). The cap
|
|
24
|
+
// keeps a crafted entry table from building an object per 16 bytes of the file.
|
|
25
|
+
const MAX_IMAGES = 256;
|
|
26
|
+
|
|
23
27
|
function read(
|
|
24
28
|
dataView,
|
|
25
29
|
dataOffset,
|
|
26
30
|
includeUnknown,
|
|
27
31
|
computed = false,
|
|
28
|
-
tagFilter = undefined
|
|
32
|
+
tagFilter = undefined,
|
|
33
|
+
valueBudget = undefined
|
|
29
34
|
) {
|
|
30
35
|
try {
|
|
31
36
|
const byteOrder = ByteOrder.getByteOrder(dataView, dataOffset);
|
|
@@ -42,7 +47,8 @@ function read(
|
|
|
42
47
|
includeUnknown,
|
|
43
48
|
computed,
|
|
44
49
|
tagFilter,
|
|
45
|
-
'mpf'
|
|
50
|
+
'mpf',
|
|
51
|
+
valueBudget
|
|
46
52
|
);
|
|
47
53
|
return addMpfImages(dataView, dataOffset, tags, byteOrder);
|
|
48
54
|
} catch (error) {
|
|
@@ -61,7 +67,8 @@ function addMpfImages(dataView, dataOffset, tags, byteOrder) {
|
|
|
61
67
|
const byteOffset = dataView.byteOffset || 0;
|
|
62
68
|
let remainingImageBytes = bufferLength * MAX_IMAGE_SIZE_PER_BUFFER_SIZE;
|
|
63
69
|
const images = [];
|
|
64
|
-
|
|
70
|
+
const imageCount = Math.min(Math.ceil(tags['MPEntry'].value.length / ENTRY_SIZE), MAX_IMAGES);
|
|
71
|
+
for (let i = 0; i < imageCount; i++) {
|
|
65
72
|
images[i] = {};
|
|
66
73
|
|
|
67
74
|
const attributes = getImageNumberValue(tags['MPEntry'].value, i * ENTRY_SIZE, Types.getTypeSize('LONG'), byteOrder);
|
package/src/pentax-tags.js
CHANGED
|
@@ -23,6 +23,8 @@ const LIK3III = {
|
|
|
23
23
|
ROLL_ANGLE: 3,
|
|
24
24
|
PITCH_ANGLE: 5
|
|
25
25
|
};
|
|
26
|
+
const INT8_SIZE = 1;
|
|
27
|
+
const INT16_SIZE = 2;
|
|
26
28
|
|
|
27
29
|
export default {
|
|
28
30
|
read,
|
|
@@ -37,7 +39,8 @@ function read(
|
|
|
37
39
|
offset,
|
|
38
40
|
includeUnknown,
|
|
39
41
|
computed = false,
|
|
40
|
-
tagFilter = undefined
|
|
42
|
+
tagFilter = undefined,
|
|
43
|
+
valueBudget = undefined
|
|
41
44
|
) {
|
|
42
45
|
try {
|
|
43
46
|
// Pentax does not use the standard TIFF header offset as base for tag
|
|
@@ -54,12 +57,20 @@ function read(
|
|
|
54
57
|
includeUnknown,
|
|
55
58
|
computed,
|
|
56
59
|
tagFilter,
|
|
57
|
-
'makerNotes'
|
|
60
|
+
'makerNotes',
|
|
61
|
+
valueBudget
|
|
58
62
|
);
|
|
59
63
|
|
|
60
64
|
if (hasLevelInfoK3III(tags)) {
|
|
61
|
-
tags = objectAssign({}, tags, parseLevelInfoK3III(
|
|
65
|
+
tags = objectAssign({}, tags, parseLevelInfoK3III(
|
|
66
|
+
dataView,
|
|
67
|
+
originOffset + tags['LevelInfo'].__offset,
|
|
68
|
+
getLevelInfoLength(tags['LevelInfo'].value),
|
|
69
|
+
byteOrder
|
|
70
|
+
));
|
|
62
71
|
delete tags['LevelInfo'];
|
|
72
|
+
} else if (tags['LevelInfo']) {
|
|
73
|
+
delete tags['LevelInfo'].__offset;
|
|
63
74
|
}
|
|
64
75
|
|
|
65
76
|
return tags;
|
|
@@ -72,34 +83,49 @@ function hasLevelInfoK3III(tags) {
|
|
|
72
83
|
return tags['PentaxModelID'] && tags['PentaxModelID'].value === MODEL_ID.K3_III && tags['LevelInfo'];
|
|
73
84
|
}
|
|
74
85
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return tags;
|
|
86
|
+
// A value of numbers holds at least as many bytes as elements, whatever its TIFF type.
|
|
87
|
+
function getLevelInfoLength(levelInfoValue) {
|
|
88
|
+
if (Array.isArray(levelInfoValue) && typeof levelInfoValue[0] === 'number') {
|
|
89
|
+
return levelInfoValue.length;
|
|
80
90
|
}
|
|
91
|
+
return 0;
|
|
92
|
+
}
|
|
81
93
|
|
|
82
|
-
|
|
83
|
-
tags
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
94
|
+
function parseLevelInfoK3III(dataView, levelInfoOffset, levelInfoLength, byteOrder) {
|
|
95
|
+
const tags = {};
|
|
96
|
+
const littleEndian = byteOrder === ByteOrder.LITTLE_ENDIAN;
|
|
97
|
+
|
|
98
|
+
if (fieldFitsInLevelInfo(LIK3III.CAMERA_ORIENTATION, INT8_SIZE, levelInfoLength)) {
|
|
99
|
+
const cameraOrientation = dataView.getInt8(levelInfoOffset + LIK3III.CAMERA_ORIENTATION);
|
|
100
|
+
tags['CameraOrientation'] = {
|
|
101
|
+
value: cameraOrientation,
|
|
102
|
+
description: getOrientationDescription(cameraOrientation)
|
|
103
|
+
};
|
|
104
|
+
}
|
|
87
105
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
106
|
+
if (fieldFitsInLevelInfo(LIK3III.ROLL_ANGLE, INT16_SIZE, levelInfoLength)) {
|
|
107
|
+
const rollAngle = dataView.getInt16(levelInfoOffset + LIK3III.ROLL_ANGLE, littleEndian);
|
|
108
|
+
tags['RollAngle'] = {
|
|
109
|
+
value: rollAngle,
|
|
110
|
+
description: getRollAngleDescription(rollAngle)
|
|
111
|
+
};
|
|
112
|
+
}
|
|
93
113
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
114
|
+
if (fieldFitsInLevelInfo(LIK3III.PITCH_ANGLE, INT16_SIZE, levelInfoLength)) {
|
|
115
|
+
const pitchAngle = dataView.getInt16(levelInfoOffset + LIK3III.PITCH_ANGLE, littleEndian);
|
|
116
|
+
tags['PitchAngle'] = {
|
|
117
|
+
value: pitchAngle,
|
|
118
|
+
description: getPitchAngleDescription(pitchAngle)
|
|
119
|
+
};
|
|
120
|
+
}
|
|
99
121
|
|
|
100
122
|
return tags;
|
|
101
123
|
}
|
|
102
124
|
|
|
125
|
+
function fieldFitsInLevelInfo(fieldOffset, fieldSize, levelInfoLength) {
|
|
126
|
+
return fieldOffset + fieldSize <= levelInfoLength;
|
|
127
|
+
}
|
|
128
|
+
|
|
103
129
|
function getOrientationDescription(orientation) {
|
|
104
130
|
if (orientation === 0) {
|
|
105
131
|
return 'Horizontal (normal)';
|
|
@@ -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});
|