exifreader 4.34.0 → 4.36.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 +88 -0
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +56 -3
- package/package.json +7 -5
- package/src/canon-tags.js +20 -2
- package/src/exif-reader.js +617 -220
- package/src/image-header-jpeg.js +135 -1
- package/src/image-header-tiff.js +1 -3
- package/src/iptc-tags.js +56 -6
- package/src/loadview-pipeline.js +417 -0
- package/src/mpf-tags.js +10 -2
- package/src/pentax-tags.js +11 -2
- package/src/photoshop-tags.js +24 -1
- package/src/png-text-tags.js +28 -4
- package/src/tag-filter-config.js +124 -0
- package/src/tag-filter.js +409 -0
- package/src/tags-helpers.js +71 -18
- package/src/tags.js +29 -13
- package/src/tiff-constants.js +25 -0
- package/webpack.config.js +3 -0
package/src/image-header-jpeg.js
CHANGED
|
@@ -4,6 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
import {getStringFromDataView} from './utils.js';
|
|
6
6
|
import Constants from './constants.js';
|
|
7
|
+
import ByteOrder from './byte-order.js';
|
|
8
|
+
import {
|
|
9
|
+
IFD_ENTRY_COUNT_LENGTH,
|
|
10
|
+
IFD_ENTRY_LENGTH,
|
|
11
|
+
NEXT_IFD_POINTER_LENGTH,
|
|
12
|
+
TIFF_BYTE_ORDER_OFFSET,
|
|
13
|
+
TIFF_HEADER_LENGTH,
|
|
14
|
+
TIFF_ID,
|
|
15
|
+
TIFF_ID_OFFSET,
|
|
16
|
+
TIFF_IFD_OFFSET_OFFSET,
|
|
17
|
+
} from './tiff-constants.js';
|
|
7
18
|
|
|
8
19
|
export default {
|
|
9
20
|
isJpegFile,
|
|
@@ -68,6 +79,11 @@ function findJpegOffsets(dataView) {
|
|
|
68
79
|
let xmpChunks;
|
|
69
80
|
let iccChunks;
|
|
70
81
|
let mpfDataOffset;
|
|
82
|
+
let exifSegmentCount = 0;
|
|
83
|
+
let bestExifSegmentScore;
|
|
84
|
+
let bestExifSegmentTiffHeaderOffset;
|
|
85
|
+
let bestExifSegmentAppMarkerPosition;
|
|
86
|
+
let bestExifSegmentFieldLength;
|
|
71
87
|
|
|
72
88
|
while (appMarkerPosition + APP_ID_OFFSET + 5 <= dataView.byteLength) {
|
|
73
89
|
if (Constants.USE_FILE && isSOF0Marker(dataView, appMarkerPosition)) {
|
|
@@ -81,7 +97,50 @@ function findJpegOffsets(dataView) {
|
|
|
81
97
|
jfifDataOffset = appMarkerPosition + JFIF_DATA_OFFSET;
|
|
82
98
|
} else if (Constants.USE_EXIF && isApp1ExifMarker(dataView, appMarkerPosition)) {
|
|
83
99
|
fieldLength = dataView.getUint16(appMarkerPosition + APP_MARKER_SIZE);
|
|
84
|
-
|
|
100
|
+
exifSegmentCount++;
|
|
101
|
+
|
|
102
|
+
const currentTiffHeaderOffset = appMarkerPosition + TIFF_HEADER_OFFSET;
|
|
103
|
+
|
|
104
|
+
if (exifSegmentCount === 1) {
|
|
105
|
+
bestExifSegmentTiffHeaderOffset = currentTiffHeaderOffset;
|
|
106
|
+
bestExifSegmentAppMarkerPosition = appMarkerPosition;
|
|
107
|
+
bestExifSegmentFieldLength = fieldLength;
|
|
108
|
+
} else if (exifSegmentCount === 2) {
|
|
109
|
+
bestExifSegmentScore = getExifMarkerScore(
|
|
110
|
+
dataView,
|
|
111
|
+
bestExifSegmentAppMarkerPosition,
|
|
112
|
+
bestExifSegmentFieldLength,
|
|
113
|
+
bestExifSegmentTiffHeaderOffset
|
|
114
|
+
);
|
|
115
|
+
const currentExifSegmentScore = getExifMarkerScore(
|
|
116
|
+
dataView,
|
|
117
|
+
appMarkerPosition,
|
|
118
|
+
fieldLength,
|
|
119
|
+
currentTiffHeaderOffset
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
if (currentExifSegmentScore > bestExifSegmentScore) {
|
|
123
|
+
bestExifSegmentScore = currentExifSegmentScore;
|
|
124
|
+
bestExifSegmentTiffHeaderOffset = currentTiffHeaderOffset;
|
|
125
|
+
bestExifSegmentAppMarkerPosition = appMarkerPosition;
|
|
126
|
+
bestExifSegmentFieldLength = fieldLength;
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
const currentExifSegmentScore = getExifMarkerScore(
|
|
130
|
+
dataView,
|
|
131
|
+
appMarkerPosition,
|
|
132
|
+
fieldLength,
|
|
133
|
+
currentTiffHeaderOffset
|
|
134
|
+
);
|
|
135
|
+
if (currentExifSegmentScore > bestExifSegmentScore) {
|
|
136
|
+
bestExifSegmentScore = currentExifSegmentScore;
|
|
137
|
+
bestExifSegmentTiffHeaderOffset = currentTiffHeaderOffset;
|
|
138
|
+
bestExifSegmentAppMarkerPosition = appMarkerPosition;
|
|
139
|
+
bestExifSegmentFieldLength = fieldLength;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
tiffHeaderOffset = bestExifSegmentTiffHeaderOffset;
|
|
85
144
|
} else if (Constants.USE_XMP && isApp1XmpMarker(dataView, appMarkerPosition)) {
|
|
86
145
|
if (!xmpChunks) {
|
|
87
146
|
xmpChunks = [];
|
|
@@ -122,6 +181,10 @@ function findJpegOffsets(dataView) {
|
|
|
122
181
|
appMarkerPosition += APP_MARKER_SIZE + fieldLength;
|
|
123
182
|
}
|
|
124
183
|
|
|
184
|
+
if (exifSegmentCount > 1) {
|
|
185
|
+
warnAboutMultipleExifSegments(exifSegmentCount);
|
|
186
|
+
}
|
|
187
|
+
|
|
125
188
|
return {
|
|
126
189
|
hasAppMarkers: appMarkerPosition > JPEG_ID_SIZE,
|
|
127
190
|
fileDataOffset: sof0DataOffset || sof2DataOffset,
|
|
@@ -229,3 +292,74 @@ function isAppMarker(dataView, appMarkerPosition) {
|
|
|
229
292
|
function isFillByte(dataView, appMarkerPosition) {
|
|
230
293
|
return dataView.getUint16(appMarkerPosition) === FILL_BYTE;
|
|
231
294
|
}
|
|
295
|
+
|
|
296
|
+
function getExifMarkerScore(dataView, appMarkerPosition, fieldLength, tiffHeaderOffset) {
|
|
297
|
+
const segmentEnd = appMarkerPosition + APP_MARKER_SIZE + fieldLength;
|
|
298
|
+
const details = getExifTiffHeaderDetails(dataView, tiffHeaderOffset, segmentEnd);
|
|
299
|
+
if (!details) {
|
|
300
|
+
return 0;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const ifdEntriesScore = Number.isInteger(details.ifdEntries) ? details.ifdEntries : 0;
|
|
304
|
+
|
|
305
|
+
return (details.isValid ? 1000000000 : 0)
|
|
306
|
+
+ (ifdEntriesScore * 1000000)
|
|
307
|
+
+ fieldLength;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function getExifTiffHeaderDetails(dataView, tiffHeaderOffset, segmentEnd) {
|
|
311
|
+
try {
|
|
312
|
+
if (tiffHeaderOffset + TIFF_HEADER_LENGTH > segmentEnd) {
|
|
313
|
+
return undefined;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const byteOrderRaw = dataView.getUint16(
|
|
317
|
+
tiffHeaderOffset + TIFF_BYTE_ORDER_OFFSET
|
|
318
|
+
);
|
|
319
|
+
const isLittleEndian = byteOrderRaw === ByteOrder.LITTLE_ENDIAN;
|
|
320
|
+
if (!isLittleEndian && (byteOrderRaw !== ByteOrder.BIG_ENDIAN)) {
|
|
321
|
+
return undefined;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const tiffId = dataView.getUint16(
|
|
325
|
+
tiffHeaderOffset + TIFF_ID_OFFSET,
|
|
326
|
+
isLittleEndian
|
|
327
|
+
);
|
|
328
|
+
if (tiffId !== TIFF_ID) {
|
|
329
|
+
return undefined;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const ifdOffset = dataView.getUint32(
|
|
333
|
+
tiffHeaderOffset + TIFF_IFD_OFFSET_OFFSET,
|
|
334
|
+
isLittleEndian
|
|
335
|
+
);
|
|
336
|
+
const ifdEntryCountOffset = tiffHeaderOffset + ifdOffset;
|
|
337
|
+
if (ifdEntryCountOffset + IFD_ENTRY_COUNT_LENGTH > segmentEnd) {
|
|
338
|
+
return undefined;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const ifdEntries = dataView.getUint16(ifdEntryCountOffset, isLittleEndian);
|
|
342
|
+
const ifdTotalLength = IFD_ENTRY_COUNT_LENGTH
|
|
343
|
+
+ (ifdEntries * IFD_ENTRY_LENGTH)
|
|
344
|
+
+ NEXT_IFD_POINTER_LENGTH;
|
|
345
|
+
const hasFullIfd = (ifdEntryCountOffset + ifdTotalLength) <= segmentEnd;
|
|
346
|
+
const isValid = hasFullIfd && (ifdEntries > 0);
|
|
347
|
+
|
|
348
|
+
return {ifdEntries, isValid};
|
|
349
|
+
} catch (error) {
|
|
350
|
+
return undefined;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function warnAboutMultipleExifSegments(exifSegmentCount) {
|
|
355
|
+
/* eslint-disable no-console */
|
|
356
|
+
if (typeof console === 'undefined' || typeof console.warn !== 'function') {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
console.warn(
|
|
361
|
+
`ExifReader: Found ${exifSegmentCount} Exif segments (APP1). `
|
|
362
|
+
+ 'Will pick the best candidate segment.'
|
|
363
|
+
);
|
|
364
|
+
/* eslint-enable no-console */
|
|
365
|
+
}
|
package/src/image-header-tiff.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import ByteOrder from './byte-order.js';
|
|
6
6
|
import Constants from './constants.js';
|
|
7
|
+
import {TIFF_ID, TIFF_ID_OFFSET} from './tiff-constants.js';
|
|
7
8
|
|
|
8
9
|
export default {
|
|
9
10
|
isTiffFile,
|
|
@@ -17,9 +18,6 @@ function isTiffFile(dataView) {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
function hasTiffMarker(dataView) {
|
|
20
|
-
const TIFF_ID = 0x2a;
|
|
21
|
-
const TIFF_ID_OFFSET = 2;
|
|
22
|
-
|
|
23
21
|
const littleEndian = dataView.getUint16(0) === ByteOrder.LITTLE_ENDIAN;
|
|
24
22
|
return dataView.getUint16(TIFF_ID_OFFSET, littleEndian) === TIFF_ID;
|
|
25
23
|
}
|
package/src/iptc-tags.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import IptcTagNames from './iptc-tag-names.js';
|
|
6
6
|
import TagDecoder from './tag-decoder.js';
|
|
7
|
+
import {NOOP_TAG_FILTER} from './tag-filter.js';
|
|
7
8
|
|
|
8
9
|
const BYTES_8BIM = 0x3842494d;
|
|
9
10
|
const BYTES_8BIM_SIZE = 4;
|
|
@@ -19,13 +20,19 @@ export default {
|
|
|
19
20
|
read
|
|
20
21
|
};
|
|
21
22
|
|
|
22
|
-
function read(dataView, dataOffset, includeUnknown) {
|
|
23
|
+
function read(dataView, dataOffset, includeUnknown, tagFilter = NOOP_TAG_FILTER) {
|
|
23
24
|
try {
|
|
24
25
|
if (Array.isArray(dataView)) {
|
|
25
|
-
return parseTags(
|
|
26
|
+
return parseTags(
|
|
27
|
+
new DataView(Uint8Array.from(dataView).buffer),
|
|
28
|
+
{size: dataView.length},
|
|
29
|
+
0,
|
|
30
|
+
includeUnknown,
|
|
31
|
+
tagFilter
|
|
32
|
+
);
|
|
26
33
|
}
|
|
27
34
|
const {naaBlock, dataOffset: newDataOffset} = getNaaResourceBlock(dataView, dataOffset);
|
|
28
|
-
return parseTags(dataView, naaBlock, newDataOffset, includeUnknown);
|
|
35
|
+
return parseTags(dataView, naaBlock, newDataOffset, includeUnknown, tagFilter);
|
|
29
36
|
} catch (error) {
|
|
30
37
|
return {};
|
|
31
38
|
}
|
|
@@ -69,14 +76,21 @@ function getBlockPadding(resourceBlock) {
|
|
|
69
76
|
return 0;
|
|
70
77
|
}
|
|
71
78
|
|
|
72
|
-
function parseTags(dataView, naaBlock, dataOffset, includeUnknown) {
|
|
79
|
+
function parseTags(dataView, naaBlock, dataOffset, includeUnknown, tagFilter) {
|
|
73
80
|
const tags = {};
|
|
74
81
|
let encoding = undefined;
|
|
75
82
|
|
|
76
83
|
const endOfBlockOffset = dataOffset + naaBlock['size'];
|
|
77
84
|
|
|
78
85
|
while ((dataOffset < endOfBlockOffset) && (dataOffset < dataView.byteLength)) {
|
|
79
|
-
const {tag, tagSize} = readTag(
|
|
86
|
+
const {tag, tagSize} = readTag(
|
|
87
|
+
dataView,
|
|
88
|
+
dataOffset,
|
|
89
|
+
tags,
|
|
90
|
+
encoding,
|
|
91
|
+
includeUnknown,
|
|
92
|
+
tagFilter
|
|
93
|
+
);
|
|
80
94
|
|
|
81
95
|
if (tag === null) {
|
|
82
96
|
break;
|
|
@@ -115,7 +129,14 @@ function parseTags(dataView, naaBlock, dataOffset, includeUnknown) {
|
|
|
115
129
|
return tags;
|
|
116
130
|
}
|
|
117
131
|
|
|
118
|
-
function readTag(
|
|
132
|
+
function readTag(
|
|
133
|
+
dataView,
|
|
134
|
+
dataOffset,
|
|
135
|
+
tags = {},
|
|
136
|
+
encoding = undefined,
|
|
137
|
+
includeUnknown = false,
|
|
138
|
+
tagFilter = NOOP_TAG_FILTER
|
|
139
|
+
) {
|
|
119
140
|
const TAG_CODE_OFFSET = 1;
|
|
120
141
|
const TAG_SIZE_OFFSET = 3;
|
|
121
142
|
|
|
@@ -130,6 +151,14 @@ function readTag(dataView, dataOffset, tags, encoding, includeUnknown) {
|
|
|
130
151
|
return {tag: undefined, tagSize};
|
|
131
152
|
}
|
|
132
153
|
|
|
154
|
+
if (!tagFilter.shouldParseTag(
|
|
155
|
+
'iptc',
|
|
156
|
+
getIptcTagNameForFiltering(tagCode, includeUnknown),
|
|
157
|
+
tagCode
|
|
158
|
+
)) {
|
|
159
|
+
return {tag: undefined, tagSize};
|
|
160
|
+
}
|
|
161
|
+
|
|
133
162
|
const tagValue = getTagValue(dataView, dataOffset + TAG_HEADER_SIZE, tagSize);
|
|
134
163
|
|
|
135
164
|
const tag = {
|
|
@@ -148,6 +177,27 @@ function readTag(dataView, dataOffset, tags, encoding, includeUnknown) {
|
|
|
148
177
|
return {tag, tagSize};
|
|
149
178
|
}
|
|
150
179
|
|
|
180
|
+
function getIptcTagNameForFiltering(tagCode, includeUnknown) {
|
|
181
|
+
const tag = IptcTagNames['iptc'][tagCode];
|
|
182
|
+
if (!tag) {
|
|
183
|
+
if (includeUnknown) {
|
|
184
|
+
return `undefined-${tagCode}`;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (typeof tag === 'string') {
|
|
191
|
+
return tag;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (tag && typeof tag.name === 'string') {
|
|
195
|
+
return tag.name;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
|
|
151
201
|
function leadByteIsMissing(dataView, dataOffset) {
|
|
152
202
|
const TAG_LEAD_BYTE = 0x1c;
|
|
153
203
|
return dataView.getUint8(dataOffset) !== TAG_LEAD_BYTE;
|
|
@@ -0,0 +1,417 @@
|
|
|
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
|
+
export function buildTagsFromMergeSteps({
|
|
6
|
+
mergeSteps,
|
|
7
|
+
deferredResults,
|
|
8
|
+
parsedGroups,
|
|
9
|
+
expanded,
|
|
10
|
+
tagFilter,
|
|
11
|
+
dataView,
|
|
12
|
+
tiffHeaderOffset,
|
|
13
|
+
fileType,
|
|
14
|
+
pngTextChunks,
|
|
15
|
+
pngTextIsAsync,
|
|
16
|
+
thumbnailIfdTags,
|
|
17
|
+
deps,
|
|
18
|
+
}) {
|
|
19
|
+
let tags = {};
|
|
20
|
+
|
|
21
|
+
for (let i = 0; i < mergeSteps.length; i++) {
|
|
22
|
+
tags = applyMergeStep({
|
|
23
|
+
step: mergeSteps[i],
|
|
24
|
+
deferredResults,
|
|
25
|
+
parsedGroups,
|
|
26
|
+
expanded,
|
|
27
|
+
tagFilter,
|
|
28
|
+
dataView,
|
|
29
|
+
tiffHeaderOffset,
|
|
30
|
+
fileType,
|
|
31
|
+
thumbnailIfdTags,
|
|
32
|
+
tags,
|
|
33
|
+
deps,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (
|
|
38
|
+
expanded
|
|
39
|
+
&& pngTextIsAsync
|
|
40
|
+
&& tagFilter.shouldReturnGroup('png')
|
|
41
|
+
&& tags.png
|
|
42
|
+
) {
|
|
43
|
+
tags.pngText = deps.objectAssign({}, tags.png);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (
|
|
47
|
+
expanded
|
|
48
|
+
&& tagFilter.shouldReturnGroup('png')
|
|
49
|
+
&& deps.hasPngTextData(pngTextChunks)
|
|
50
|
+
&& tags.png
|
|
51
|
+
&& !tags.pngText
|
|
52
|
+
) {
|
|
53
|
+
tags.pngText = deps.objectAssign({}, tags.png);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return tags;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function applyMergeStep({
|
|
60
|
+
step,
|
|
61
|
+
deferredResults,
|
|
62
|
+
parsedGroups,
|
|
63
|
+
expanded,
|
|
64
|
+
tagFilter,
|
|
65
|
+
dataView,
|
|
66
|
+
tiffHeaderOffset,
|
|
67
|
+
fileType,
|
|
68
|
+
thumbnailIfdTags,
|
|
69
|
+
tags,
|
|
70
|
+
deps,
|
|
71
|
+
}) {
|
|
72
|
+
if (step.type === 'mergeGroupAssign') {
|
|
73
|
+
const returnedTags =
|
|
74
|
+
deps.filterTagsForReturn(step.groupKey, step.parsedTags, tagFilter);
|
|
75
|
+
|
|
76
|
+
return mergeAssignGroup(tags, step.groupKey, returnedTags, expanded, deps);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (step.type === 'mergeGroupMerge') {
|
|
80
|
+
const returnedTags =
|
|
81
|
+
deps.filterTagsForReturn(step.groupKey, step.parsedTags, tagFilter);
|
|
82
|
+
|
|
83
|
+
return mergeMergeGroup(tags, step.groupKey, returnedTags, expanded, deps);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (step.type === 'mergeXmpGroupAssign') {
|
|
87
|
+
const returnedTags =
|
|
88
|
+
deps.filterTagsForReturn('xmp', step.parsedTags, tagFilter);
|
|
89
|
+
|
|
90
|
+
if (expanded) {
|
|
91
|
+
tags.xmp = returnedTags;
|
|
92
|
+
|
|
93
|
+
return tags;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const returnedTagsForFlat = deps.objectAssign({}, returnedTags);
|
|
97
|
+
delete returnedTagsForFlat._raw;
|
|
98
|
+
|
|
99
|
+
return deps.objectAssign({}, tags, returnedTagsForFlat);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (step.type === 'mergeIccDeferred') {
|
|
103
|
+
const resolvedReadTags = deferredResults[step.deferredKey];
|
|
104
|
+
const parsedIccTags =
|
|
105
|
+
deps.filterTagsForParse('icc', resolvedReadTags, tagFilter);
|
|
106
|
+
parsedGroups.icc = parsedIccTags;
|
|
107
|
+
|
|
108
|
+
if (!tagFilter.shouldReturnGroup('icc')) {
|
|
109
|
+
return tags;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const returnedIccTags =
|
|
113
|
+
deps.filterTagsForReturn('icc', parsedIccTags, tagFilter);
|
|
114
|
+
|
|
115
|
+
return mergeAssignGroup(tags, 'icc', returnedIccTags, expanded, deps);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (step.type === 'mergePngFile') {
|
|
119
|
+
const returnedPngFileTags =
|
|
120
|
+
deps.filterTagsForReturn('png', step.parsedTags, tagFilter);
|
|
121
|
+
|
|
122
|
+
if (!tagFilter.shouldReturnGroup('png')) {
|
|
123
|
+
return tags;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (expanded) {
|
|
127
|
+
tags.png = !tags.png ? returnedPngFileTags : deps.objectAssign(
|
|
128
|
+
{},
|
|
129
|
+
tags.png,
|
|
130
|
+
returnedPngFileTags
|
|
131
|
+
);
|
|
132
|
+
tags.pngFile = returnedPngFileTags;
|
|
133
|
+
|
|
134
|
+
return tags;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return deps.objectAssign({}, tags, returnedPngFileTags);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (step.type === 'mergePngChunk') {
|
|
141
|
+
const returnedPngChunkTags =
|
|
142
|
+
deps.filterTagsForReturn('png', step.parsedTags, tagFilter);
|
|
143
|
+
|
|
144
|
+
if (!tagFilter.shouldReturnGroup('png')) {
|
|
145
|
+
return tags;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (expanded) {
|
|
149
|
+
tags.png = !tags.png ? returnedPngChunkTags : deps.objectAssign(
|
|
150
|
+
{},
|
|
151
|
+
tags.png,
|
|
152
|
+
returnedPngChunkTags
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
return tags;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return deps.objectAssign({}, tags, returnedPngChunkTags);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (step.type === 'processPngTextReadTags') {
|
|
162
|
+
return addPngTextReadTagsToTagsAndGroups({
|
|
163
|
+
readTags: step.readTags,
|
|
164
|
+
parsedGroups,
|
|
165
|
+
expanded,
|
|
166
|
+
tagFilter,
|
|
167
|
+
tags,
|
|
168
|
+
deps,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (step.type === 'processPngTextReadTagsDeferredList') {
|
|
173
|
+
const tagList = deferredResults[step.deferredKey] || [];
|
|
174
|
+
|
|
175
|
+
for (let i = 0; i < tagList.length; i++) {
|
|
176
|
+
tags = addPngTextReadTagsToTagsAndGroups({
|
|
177
|
+
readTags: tagList[i],
|
|
178
|
+
parsedGroups,
|
|
179
|
+
expanded,
|
|
180
|
+
tagFilter,
|
|
181
|
+
tags,
|
|
182
|
+
deps,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return tags;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (step.type === 'gps') {
|
|
190
|
+
if (
|
|
191
|
+
expanded
|
|
192
|
+
&& tagFilter.shouldReturnGroup('gps')
|
|
193
|
+
&& parsedGroups.exif
|
|
194
|
+
) {
|
|
195
|
+
const gpsGroup = deps.getGpsGroupFromExifTags(parsedGroups.exif);
|
|
196
|
+
if (gpsGroup) {
|
|
197
|
+
const returnedGpsGroup =
|
|
198
|
+
deps.filterTagsForReturn('gps', gpsGroup, tagFilter);
|
|
199
|
+
tags.gps = returnedGpsGroup;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return tags;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (step.type === 'composite') {
|
|
207
|
+
if (!tagFilter.shouldReturnGroup('composite')) {
|
|
208
|
+
return tags;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
let compositeInput = tags;
|
|
212
|
+
let compositeInputExpanded = expanded;
|
|
213
|
+
if (tagFilter.isActive) {
|
|
214
|
+
compositeInput = {exif: parsedGroups.exif, file: parsedGroups.file};
|
|
215
|
+
compositeInputExpanded = true;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const composite = deps.Composite.get(compositeInput, compositeInputExpanded);
|
|
219
|
+
if (!composite) {
|
|
220
|
+
return tags;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const returnedCompositeTags =
|
|
224
|
+
deps.filterTagsForReturn('composite', composite, tagFilter);
|
|
225
|
+
|
|
226
|
+
return mergeAssignGroup(
|
|
227
|
+
tags,
|
|
228
|
+
'composite',
|
|
229
|
+
returnedCompositeTags,
|
|
230
|
+
expanded,
|
|
231
|
+
deps
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (step.type === 'thumbnail') {
|
|
236
|
+
if (
|
|
237
|
+
!tagFilter.shouldReturnGroup('thumbnail')
|
|
238
|
+
|| !tagFilter.shouldReturnTag('thumbnail', 'Thumbnail')
|
|
239
|
+
) {
|
|
240
|
+
delete tags.Thumbnail;
|
|
241
|
+
|
|
242
|
+
return tags;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (!thumbnailIfdTags) {
|
|
246
|
+
return tags;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const parsedThumbnailIfdTags = thumbnailIfdTags ? deps.filterTagsForParse(
|
|
250
|
+
'thumbnail',
|
|
251
|
+
thumbnailIfdTags,
|
|
252
|
+
tagFilter
|
|
253
|
+
) : undefined;
|
|
254
|
+
if (parsedThumbnailIfdTags) {
|
|
255
|
+
parsedGroups.thumbnail = parsedThumbnailIfdTags;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const thumbnail = (deps.Constants.USE_JPEG || deps.Constants.USE_WEBP)
|
|
259
|
+
&& deps.Constants.USE_EXIF
|
|
260
|
+
&& deps.Constants.USE_THUMBNAIL
|
|
261
|
+
&& deps.Thumbnail.get(dataView, parsedThumbnailIfdTags, tiffHeaderOffset);
|
|
262
|
+
if (thumbnail) {
|
|
263
|
+
tags.Thumbnail = thumbnail;
|
|
264
|
+
} else {
|
|
265
|
+
delete tags.Thumbnail;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return tags;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (step.type === 'fileType') {
|
|
272
|
+
if (
|
|
273
|
+
fileType
|
|
274
|
+
&& tagFilter.shouldReturnGroup('file')
|
|
275
|
+
&& tagFilter.shouldReturnTag('file', 'FileType')
|
|
276
|
+
) {
|
|
277
|
+
if (expanded) {
|
|
278
|
+
if (!tags.file) {
|
|
279
|
+
tags.file = {};
|
|
280
|
+
}
|
|
281
|
+
tags.file.FileType = fileType;
|
|
282
|
+
} else {
|
|
283
|
+
tags.FileType = fileType;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return tags;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return tags;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export function mergeAssignGroup(tags, groupKey, returnedTags, expanded, deps) {
|
|
294
|
+
if (expanded) {
|
|
295
|
+
tags[groupKey] = returnedTags;
|
|
296
|
+
|
|
297
|
+
return tags;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return deps.objectAssign({}, tags, returnedTags);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export function mergeMergeGroup(tags, groupKey, returnedTags, expanded, deps) {
|
|
304
|
+
if (expanded) {
|
|
305
|
+
if (!tags[groupKey]) {
|
|
306
|
+
tags[groupKey] = returnedTags;
|
|
307
|
+
} else {
|
|
308
|
+
tags[groupKey] = deps.objectAssign({}, tags[groupKey], returnedTags);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return tags;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return deps.objectAssign({}, tags, returnedTags);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export function addPngTextReadTagsToTagsAndGroups({
|
|
318
|
+
readTags,
|
|
319
|
+
parsedGroups,
|
|
320
|
+
expanded,
|
|
321
|
+
tagFilter,
|
|
322
|
+
tags,
|
|
323
|
+
deps,
|
|
324
|
+
}) {
|
|
325
|
+
const embeddedExifTags = readTags.__exif;
|
|
326
|
+
const embeddedIptcTags = readTags.__iptc;
|
|
327
|
+
delete readTags.__exif;
|
|
328
|
+
delete readTags.__iptc;
|
|
329
|
+
|
|
330
|
+
if (embeddedExifTags) {
|
|
331
|
+
const parsedEmbeddedExifTags =
|
|
332
|
+
deps.filterTagsForParse('exif', embeddedExifTags, tagFilter);
|
|
333
|
+
parsedGroups.exif = !parsedGroups.exif ? parsedEmbeddedExifTags : deps.objectAssign(
|
|
334
|
+
{},
|
|
335
|
+
parsedGroups.exif,
|
|
336
|
+
parsedEmbeddedExifTags
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
if (tagFilter.shouldReturnGroup('exif')) {
|
|
340
|
+
const returnedEmbeddedExifTags = deps.filterTagsForReturn(
|
|
341
|
+
'exif',
|
|
342
|
+
parsedEmbeddedExifTags,
|
|
343
|
+
tagFilter
|
|
344
|
+
);
|
|
345
|
+
if (expanded) {
|
|
346
|
+
tags.exif = !tags.exif ? returnedEmbeddedExifTags : deps.objectAssign(
|
|
347
|
+
{},
|
|
348
|
+
tags.exif,
|
|
349
|
+
returnedEmbeddedExifTags
|
|
350
|
+
);
|
|
351
|
+
} else {
|
|
352
|
+
tags = deps.objectAssign({}, tags, returnedEmbeddedExifTags);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (embeddedIptcTags) {
|
|
358
|
+
const parsedEmbeddedIptcTags =
|
|
359
|
+
deps.filterTagsForParse('iptc', embeddedIptcTags, tagFilter);
|
|
360
|
+
parsedGroups.iptc = !parsedGroups.iptc ? parsedEmbeddedIptcTags : deps.objectAssign(
|
|
361
|
+
{},
|
|
362
|
+
parsedGroups.iptc,
|
|
363
|
+
parsedEmbeddedIptcTags
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
if (tagFilter.shouldReturnGroup('iptc')) {
|
|
367
|
+
const returnedEmbeddedIptcTags = deps.filterTagsForReturn(
|
|
368
|
+
'iptc',
|
|
369
|
+
parsedEmbeddedIptcTags,
|
|
370
|
+
tagFilter
|
|
371
|
+
);
|
|
372
|
+
if (expanded) {
|
|
373
|
+
tags.iptc = !tags.iptc ? returnedEmbeddedIptcTags : deps.objectAssign(
|
|
374
|
+
{},
|
|
375
|
+
tags.iptc,
|
|
376
|
+
returnedEmbeddedIptcTags
|
|
377
|
+
);
|
|
378
|
+
} else {
|
|
379
|
+
tags = deps.objectAssign({}, tags, returnedEmbeddedIptcTags);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (tagFilter.shouldReturnGroup('png')) {
|
|
385
|
+
const parsedPngTextTags = deps.filterTagsForParse('png', readTags, tagFilter);
|
|
386
|
+
const returnedPngTextTags =
|
|
387
|
+
deps.filterTagsForReturn('png', parsedPngTextTags, tagFilter);
|
|
388
|
+
parsedGroups.pngText = parsedPngTextTags;
|
|
389
|
+
|
|
390
|
+
if (expanded) {
|
|
391
|
+
tags.png = !tags.png ? returnedPngTextTags : deps.objectAssign(
|
|
392
|
+
{},
|
|
393
|
+
tags.png,
|
|
394
|
+
returnedPngTextTags
|
|
395
|
+
);
|
|
396
|
+
// Historical behavior in build fixtures:
|
|
397
|
+
// - if PNG text chunks yield actual "png" tags, `pngText` should contain only those
|
|
398
|
+
// - otherwise (e.g. only embedded Exif/IPTC), `pngText` should represent the full `png` group
|
|
399
|
+
// and will be filled in later as a fallback from `tags.png`
|
|
400
|
+
if (returnedPngTextTags && Object.keys(returnedPngTextTags).length > 0) {
|
|
401
|
+
tags.pngText = !tags.pngText ? returnedPngTextTags : deps.objectAssign(
|
|
402
|
+
{},
|
|
403
|
+
tags.pngText,
|
|
404
|
+
returnedPngTextTags
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
} else {
|
|
408
|
+
tags = deps.objectAssign({}, tags, returnedPngTextTags);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
return tags;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export function isThenable(value) {
|
|
416
|
+
return !!value && typeof value.then === 'function';
|
|
417
|
+
}
|