exifreader 4.52.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 +36 -15
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/package.json +4 -4
- package/src/base64-image.js +27 -0
- package/src/dom-parser.js +53 -4
- package/src/engine.js +388 -0
- package/src/exif-reader.js +541 -894
- 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/load-auto.js +11 -0
- package/src/loadview-pipeline.js +285 -446
- package/src/mpf-tags.js +10 -7
- package/src/node-require.js +8 -1
- package/src/png-text-tags.js +88 -327
- package/src/tag-filter.js +52 -0
- package/src/tag-names-0th-ifd.js +5 -1
- package/src/tag-names-utils.js +25 -2
- package/src/tags-helpers.js +23 -29
- package/src/tags.js +23 -11
- package/src/thumbnail.js +7 -5
- package/src/types.js +32 -2
- package/src/utils.js +42 -34
- package/src/writer/exif-tag-table.js +321 -0
- package/src/xml.js +12 -15
- package/src/xmp-element-depth.js +16 -26
- package/src/xmp-tags.js +11 -12
package/src/loadview-pipeline.js
CHANGED
|
@@ -4,47 +4,110 @@
|
|
|
4
4
|
|
|
5
5
|
import Constants from './constants.js';
|
|
6
6
|
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
// A block's position in each mode is the index of its slot. Expanded output
|
|
8
|
+
// takes its key order from the first block of each group: discovery order,
|
|
9
|
+
// with the groups an Exif block carries just before it. In flat output a later
|
|
10
|
+
// block wins a key clash, so Exif wins over the groups it carries except an
|
|
11
|
+
// ApplicationNotes XMP packet.
|
|
12
|
+
export const MERGE_ORDER = {
|
|
13
|
+
expanded: [
|
|
14
|
+
'file', 'jfif',
|
|
15
|
+
'carriedIptc', 'carriedXmp', 'carriedPhotoshop', 'carriedIcc', 'carriedMakerNotes', 'exif',
|
|
16
|
+
'iptc', 'xmp', 'brobExif', 'brobXmp', 'icc', 'mpf',
|
|
17
|
+
'pngFile', 'pngText', 'deferredPngText', 'pngChunk', 'riff', 'gif', 'jxlFile', 'isoBmffFile',
|
|
18
|
+
'gps', 'composite', 'thumbnail', 'fileType', 'metadataRange',
|
|
19
|
+
],
|
|
20
|
+
flat: [
|
|
21
|
+
'file', 'jfif',
|
|
22
|
+
'carriedIptc', 'carriedPhotoshop', 'carriedIcc', 'carriedMakerNotes', 'exif', 'carriedXmp',
|
|
23
|
+
'iptc', 'xmp', 'brobExif', 'brobXmp', 'icc', 'mpf',
|
|
24
|
+
'pngFile', 'pngText', 'deferredPngText', 'pngChunk', 'riff', 'gif', 'jxlFile', 'isoBmffFile',
|
|
25
|
+
'gps', 'composite', 'thumbnail', 'fileType', 'metadataRange',
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Every Constants.USE_* guard sits inside the function, since the table is
|
|
30
|
+
// built once at import.
|
|
31
|
+
const MERGE_MODES = {
|
|
32
|
+
assign: assignGroupTags,
|
|
33
|
+
merge: mergeGroupTags,
|
|
34
|
+
brobXmp: assignBrobXmpTags,
|
|
35
|
+
pngFile: mergePngFileTags,
|
|
36
|
+
pngTextTags: mergePngTextTags,
|
|
37
|
+
nested: mergeNestedBlocks,
|
|
38
|
+
thumbnailCandidate: addThumbnailCandidate,
|
|
39
|
+
gps: addGpsGroup,
|
|
40
|
+
composite: addCompositeGroup,
|
|
41
|
+
thumbnail: addThumbnail,
|
|
42
|
+
fileType: addFileType,
|
|
43
|
+
metadataRange: addMetadataRange,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Merges the blocks into the returned tags, in the order MERGE_ORDER gives the
|
|
48
|
+
* current mode, whatever order they were pushed in.
|
|
49
|
+
*
|
|
50
|
+
* A block has a `slot` (its place in MERGE_ORDER) and a `mode` (a key of
|
|
51
|
+
* MERGE_MODES). A tag block also has the `group` it merges into and its parsed
|
|
52
|
+
* `tags`; a `nested` container has `blocks`, merged among themselves in slot
|
|
53
|
+
* order at the container's position; a `thumbnailCandidate` has `rank` (main
|
|
54
|
+
* or embedded) and the thumbnail as `tags`. A metadataRange block carries
|
|
55
|
+
* `metadataBlocks` and `metadataTruncated`.
|
|
56
|
+
*
|
|
57
|
+
* The top level merges in place, so a PNG with thousands of text chunk blocks
|
|
58
|
+
* stays linear.
|
|
59
|
+
*
|
|
60
|
+
* @returns {object} The tags.
|
|
61
|
+
*/
|
|
62
|
+
export function buildTagsFromMergeBlocks({
|
|
63
|
+
mergeBlocks,
|
|
15
64
|
parsedGroups,
|
|
16
65
|
expanded,
|
|
17
66
|
tagFilter,
|
|
18
67
|
dataView,
|
|
19
|
-
tiffHeaderOffset,
|
|
20
|
-
exifDataView,
|
|
21
68
|
fileType,
|
|
22
|
-
|
|
69
|
+
pngTextBlocks,
|
|
23
70
|
pngTextIsAsync,
|
|
24
|
-
thumbnailIfdTags,
|
|
25
71
|
deps,
|
|
26
72
|
}) {
|
|
73
|
+
const context = {
|
|
74
|
+
parsedGroups,
|
|
75
|
+
expanded,
|
|
76
|
+
tagFilter,
|
|
77
|
+
dataView,
|
|
78
|
+
fileType,
|
|
79
|
+
thumbnails: [],
|
|
80
|
+
deps,
|
|
81
|
+
merge: createInPlaceMerge(deps),
|
|
82
|
+
};
|
|
83
|
+
const orderedBlocks = getBlocksInMergeOrder(mergeBlocks, expanded);
|
|
27
84
|
let tags = {};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
tags = applyMergeStep({
|
|
32
|
-
step: mergeSteps[i],
|
|
33
|
-
deferredResults,
|
|
34
|
-
parsedGroups,
|
|
35
|
-
expanded,
|
|
36
|
-
tagFilter,
|
|
37
|
-
dataView,
|
|
38
|
-
tiffHeaderOffset,
|
|
39
|
-
exifDataView,
|
|
40
|
-
fileType,
|
|
41
|
-
thumbnailIfdTags,
|
|
42
|
-
embeddedExifThumbnails,
|
|
43
|
-
tags,
|
|
44
|
-
deps,
|
|
45
|
-
});
|
|
85
|
+
|
|
86
|
+
for (let i = 0; i < orderedBlocks.length; i++) {
|
|
87
|
+
tags = applyMergeMode(tags, orderedBlocks[i], context);
|
|
46
88
|
}
|
|
47
89
|
|
|
90
|
+
return addPngTextCopyOfPng(tags, {expanded, tagFilter, pngTextBlocks, pngTextIsAsync, deps});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Sorts by position, then push order, without relying on a stable sort.
|
|
94
|
+
function getBlocksInMergeOrder(blocks, expanded) {
|
|
95
|
+
const order = expanded ? MERGE_ORDER.expanded : MERGE_ORDER.flat;
|
|
96
|
+
|
|
97
|
+
return blocks
|
|
98
|
+
.map((block, index) => ({block, index, position: order.indexOf(block.slot)}))
|
|
99
|
+
.sort((a, b) => (a.position - b.position) || (a.index - b.index))
|
|
100
|
+
.map((entry) => entry.block);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function applyMergeMode(tags, block, context) {
|
|
104
|
+
return MERGE_MODES[block.mode](tags, block, context);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Expanded output gets a pngText group that copies png when the text chunks
|
|
108
|
+
// are read asynchronously, or when there are text chunks (raw profiles
|
|
109
|
+
// included) but none of them gave PNG text tags.
|
|
110
|
+
function addPngTextCopyOfPng(tags, {expanded, tagFilter, pngTextBlocks, pngTextIsAsync, deps}) {
|
|
48
111
|
if (
|
|
49
112
|
Constants.USE_PNG
|
|
50
113
|
&& expanded
|
|
@@ -59,7 +122,7 @@ export function buildTagsFromMergeSteps({
|
|
|
59
122
|
Constants.USE_PNG
|
|
60
123
|
&& expanded
|
|
61
124
|
&& tagFilter.shouldReturnGroup('png')
|
|
62
|
-
&& deps.hasPngTextData(
|
|
125
|
+
&& deps.hasPngTextData(pngTextBlocks)
|
|
63
126
|
&& tags.png
|
|
64
127
|
&& !tags.pngText
|
|
65
128
|
) {
|
|
@@ -69,506 +132,282 @@ export function buildTagsFromMergeSteps({
|
|
|
69
132
|
return tags;
|
|
70
133
|
}
|
|
71
134
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Merges one block into the tags with the function its mode names.
|
|
137
|
+
*
|
|
138
|
+
* @param {object} context The block, the tags so far and the merge state; see
|
|
139
|
+
* buildTagsFromMergeBlocks for the block shape. `merge` defaults to a copying
|
|
140
|
+
* merge and `thumbnails` to a new list.
|
|
141
|
+
* @returns {object} The tags, which flat output replaces rather than mutates.
|
|
142
|
+
*/
|
|
143
|
+
export function mergeBlock({
|
|
144
|
+
block,
|
|
145
|
+
tags,
|
|
75
146
|
parsedGroups,
|
|
76
147
|
expanded,
|
|
77
148
|
tagFilter,
|
|
78
149
|
dataView,
|
|
79
|
-
tiffHeaderOffset,
|
|
80
|
-
exifDataView,
|
|
81
150
|
fileType,
|
|
82
|
-
|
|
83
|
-
embeddedExifThumbnails = [],
|
|
84
|
-
tags,
|
|
151
|
+
thumbnails = [],
|
|
85
152
|
deps,
|
|
153
|
+
merge = createCopyingMerge(deps),
|
|
86
154
|
}) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
155
|
+
return applyMergeMode(tags, block, {
|
|
156
|
+
parsedGroups,
|
|
157
|
+
expanded,
|
|
158
|
+
tagFilter,
|
|
159
|
+
dataView,
|
|
160
|
+
fileType,
|
|
161
|
+
thumbnails,
|
|
162
|
+
deps,
|
|
163
|
+
merge,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
90
166
|
|
|
91
|
-
|
|
167
|
+
// Every tag block writes its parsed group as it merges, since gps, composite
|
|
168
|
+
// and metadataRange read them, whether or not the group is returned.
|
|
169
|
+
function assignGroupTags(tags, block, context) {
|
|
170
|
+
context.parsedGroups[block.group] = block.tags;
|
|
171
|
+
if (!context.tagFilter.shouldReturnGroup(block.group)) {
|
|
172
|
+
return tags;
|
|
92
173
|
}
|
|
174
|
+
const returnedTags = context.deps.filterTagsForReturn(block.group, block.tags, context.tagFilter);
|
|
93
175
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
deps.filterTagsForReturn(step.groupKey, step.parsedTags, tagFilter);
|
|
97
|
-
|
|
98
|
-
return mergeMergeGroup(tags, step.groupKey, returnedTags, expanded, deps);
|
|
99
|
-
}
|
|
176
|
+
return mergeAssignGroup(tags, block.group, returnedTags, context.expanded, context.deps);
|
|
177
|
+
}
|
|
100
178
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
179
|
+
export function mergeAssignGroup(tags, groupKey, returnedTags, expanded, deps) {
|
|
180
|
+
if (expanded) {
|
|
181
|
+
tags[groupKey] = returnedTags;
|
|
104
182
|
|
|
105
|
-
return
|
|
183
|
+
return tags;
|
|
106
184
|
}
|
|
107
185
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const parsedIccTags =
|
|
111
|
-
deps.filterTagsForParse('icc', resolvedReadTags, tagFilter);
|
|
112
|
-
parsedGroups.icc = parsedIccTags;
|
|
113
|
-
|
|
114
|
-
if (!tagFilter.shouldReturnGroup('icc')) {
|
|
115
|
-
return tags;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const returnedIccTags =
|
|
119
|
-
deps.filterTagsForReturn('icc', parsedIccTags, tagFilter);
|
|
186
|
+
return deps.objectAssign({}, tags, getTagsForFlat(groupKey, returnedTags, deps));
|
|
187
|
+
}
|
|
120
188
|
|
|
121
|
-
|
|
189
|
+
// Every XMP block drops the raw packet in flat output.
|
|
190
|
+
function getTagsForFlat(groupKey, returnedTags, deps) {
|
|
191
|
+
if (!(Constants.USE_XMP && groupKey === 'xmp')) {
|
|
192
|
+
return returnedTags;
|
|
122
193
|
}
|
|
194
|
+
const xmpTagsWithoutRaw = deps.objectAssign({}, returnedTags);
|
|
195
|
+
delete xmpTagsWithoutRaw._raw;
|
|
123
196
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (!resolved) {
|
|
127
|
-
return tags;
|
|
128
|
-
}
|
|
129
|
-
addEmbeddedExifThumbnail(embeddedExifThumbnails, resolved.thumbnail);
|
|
130
|
-
if (Object.keys(resolved.exifTags).length === 0) {
|
|
131
|
-
return tags;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return addExifAndCarriedGroupsToTagsAndGroups({
|
|
135
|
-
exifTags: resolved.exifTags,
|
|
136
|
-
carriedGroups: resolved.carriedGroups,
|
|
137
|
-
parsedGroups,
|
|
138
|
-
expanded,
|
|
139
|
-
tagFilter,
|
|
140
|
-
tags,
|
|
141
|
-
deps,
|
|
142
|
-
merge: createCopyingMerge(deps),
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (Constants.USE_JXL && step.type === 'mergeBrobXmpDeferred') {
|
|
147
|
-
const resolvedReadTags = deferredResults[step.deferredKey];
|
|
148
|
-
if (!resolvedReadTags || Object.keys(resolvedReadTags).length === 0) {
|
|
149
|
-
return tags;
|
|
150
|
-
}
|
|
151
|
-
const parsedXmpTags =
|
|
152
|
-
deps.filterTagsForParse('xmp', resolvedReadTags, tagFilter);
|
|
153
|
-
parsedGroups.xmp = parsedXmpTags;
|
|
154
|
-
|
|
155
|
-
if (!tagFilter.shouldReturnGroup('xmp')) {
|
|
156
|
-
return tags;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const returnedTags =
|
|
160
|
-
deps.filterTagsForReturn('xmp', parsedXmpTags, tagFilter);
|
|
197
|
+
return xmpTagsWithoutRaw;
|
|
198
|
+
}
|
|
161
199
|
|
|
162
|
-
|
|
200
|
+
function mergeGroupTags(tags, block, context) {
|
|
201
|
+
context.merge.group(context.parsedGroups, block.group, block.tags);
|
|
202
|
+
if (!context.tagFilter.shouldReturnGroup(block.group)) {
|
|
203
|
+
return tags;
|
|
163
204
|
}
|
|
205
|
+
const returnedTags = context.deps.filterTagsForReturn(block.group, block.tags, context.tagFilter);
|
|
164
206
|
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
deps.filterTagsForReturn('png', step.parsedTags, tagFilter);
|
|
168
|
-
|
|
169
|
-
if (!tagFilter.shouldReturnGroup('png')) {
|
|
170
|
-
return tags;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (expanded) {
|
|
174
|
-
tags.png = !tags.png ? returnedPngFileTags : deps.objectAssign(
|
|
175
|
-
{},
|
|
176
|
-
tags.png,
|
|
177
|
-
returnedPngFileTags
|
|
178
|
-
);
|
|
179
|
-
tags.pngFile = returnedPngFileTags;
|
|
207
|
+
if (context.expanded) {
|
|
208
|
+
context.merge.group(tags, block.group, returnedTags);
|
|
180
209
|
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return deps.objectAssign({}, tags, returnedPngFileTags);
|
|
210
|
+
return tags;
|
|
185
211
|
}
|
|
186
212
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
deps.filterTagsForReturn('png', step.parsedTags, tagFilter);
|
|
190
|
-
|
|
191
|
-
if (!tagFilter.shouldReturnGroup('png')) {
|
|
192
|
-
return tags;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (expanded) {
|
|
196
|
-
tags.png = !tags.png ? returnedPngChunkTags : deps.objectAssign(
|
|
197
|
-
{},
|
|
198
|
-
tags.png,
|
|
199
|
-
returnedPngChunkTags
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
return tags;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return deps.objectAssign({}, tags, returnedPngChunkTags);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (Constants.USE_PNG && step.type === 'processPngTextReadTags') {
|
|
209
|
-
addEmbeddedExifThumbnail(embeddedExifThumbnails, step.embeddedExifThumbnail);
|
|
210
|
-
return addPngTextReadTagsToTagsAndGroups({
|
|
211
|
-
readTags: step.readTags,
|
|
212
|
-
embeddedExifTags: step.embeddedExifTags,
|
|
213
|
-
exifCarriedGroups: step.exifCarriedGroups,
|
|
214
|
-
embeddedIptcTags: step.embeddedIptcTags,
|
|
215
|
-
parsedGroups,
|
|
216
|
-
expanded,
|
|
217
|
-
tagFilter,
|
|
218
|
-
tags,
|
|
219
|
-
deps,
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (Constants.USE_PNG && step.type === 'processPngTextReadTagsDeferredList') {
|
|
224
|
-
const tagList = deferredResults[step.deferredKey] || [];
|
|
225
|
-
const merge = createInPlaceMerge(deps);
|
|
226
|
-
|
|
227
|
-
for (let i = 0; i < tagList.length; i++) {
|
|
228
|
-
const entry = tagList[i];
|
|
229
|
-
addEmbeddedExifThumbnail(embeddedExifThumbnails, entry.embeddedExifThumbnail);
|
|
230
|
-
tags = addPngTextReadTagsToTagsAndGroups({
|
|
231
|
-
readTags: entry.readTags || {},
|
|
232
|
-
embeddedExifTags: entry.embeddedExifTags,
|
|
233
|
-
exifCarriedGroups: entry.exifCarriedGroups,
|
|
234
|
-
embeddedIptcTags: entry.embeddedIptcTags,
|
|
235
|
-
parsedGroups,
|
|
236
|
-
expanded,
|
|
237
|
-
tagFilter,
|
|
238
|
-
tags,
|
|
239
|
-
deps,
|
|
240
|
-
merge,
|
|
241
|
-
});
|
|
242
|
-
}
|
|
213
|
+
return context.merge.topLevel(tags, getTagsForFlat(block.group, returnedTags, context.deps));
|
|
214
|
+
}
|
|
243
215
|
|
|
216
|
+
// In expanded output a brob XMP replaces the xmp group, in flat output it
|
|
217
|
+
// merges key by key, and an empty, failed or over-bound one leaves the earlier
|
|
218
|
+
// xmp group as it is.
|
|
219
|
+
function assignBrobXmpTags(tags, block, context) {
|
|
220
|
+
if (!Constants.USE_JXL) {
|
|
244
221
|
return tags;
|
|
245
222
|
}
|
|
246
|
-
|
|
247
|
-
if (Constants.USE_EXIF && step.type === 'gps') {
|
|
248
|
-
if (
|
|
249
|
-
expanded
|
|
250
|
-
&& tagFilter.shouldReturnGroup('gps')
|
|
251
|
-
&& parsedGroups.exif
|
|
252
|
-
) {
|
|
253
|
-
const gpsGroup = deps.getGpsGroupFromExifTags(parsedGroups.exif);
|
|
254
|
-
if (gpsGroup) {
|
|
255
|
-
const returnedGpsGroup =
|
|
256
|
-
deps.filterTagsForReturn('gps', gpsGroup, tagFilter);
|
|
257
|
-
tags.gps = returnedGpsGroup;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
223
|
+
if (!block.tags || Object.keys(block.tags).length === 0) {
|
|
261
224
|
return tags;
|
|
262
225
|
}
|
|
263
226
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
return tags;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
let compositeInput = tags;
|
|
270
|
-
let compositeInputExpanded = expanded;
|
|
271
|
-
if (tagFilter.isActive) {
|
|
272
|
-
compositeInput = {exif: parsedGroups.exif, file: parsedGroups.file};
|
|
273
|
-
compositeInputExpanded = true;
|
|
274
|
-
}
|
|
227
|
+
return assignGroupTags(tags, block, context);
|
|
228
|
+
}
|
|
275
229
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
230
|
+
// The png group gathers the file, text and chunk tags; pngFile keeps the file
|
|
231
|
+
// tags alone.
|
|
232
|
+
function mergePngFileTags(tags, block, context) {
|
|
233
|
+
if (!Constants.USE_PNG) {
|
|
234
|
+
return tags;
|
|
235
|
+
}
|
|
236
|
+
context.parsedGroups.pngFile = block.tags;
|
|
237
|
+
if (!context.tagFilter.shouldReturnGroup('png')) {
|
|
238
|
+
return tags;
|
|
239
|
+
}
|
|
240
|
+
const returnedTags = context.deps.filterTagsForReturn('png', block.tags, context.tagFilter);
|
|
280
241
|
|
|
281
|
-
|
|
282
|
-
|
|
242
|
+
if (context.expanded) {
|
|
243
|
+
context.merge.group(tags, 'png', returnedTags);
|
|
244
|
+
tags.pngFile = returnedTags;
|
|
283
245
|
|
|
284
|
-
return
|
|
285
|
-
tags,
|
|
286
|
-
'composite',
|
|
287
|
-
returnedCompositeTags,
|
|
288
|
-
expanded,
|
|
289
|
-
deps
|
|
290
|
-
);
|
|
246
|
+
return tags;
|
|
291
247
|
}
|
|
292
248
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
delete tags.Thumbnail;
|
|
249
|
+
return context.merge.topLevel(tags, returnedTags);
|
|
250
|
+
}
|
|
296
251
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
252
|
+
// The blocks of one container (an Exif block with the groups it carries, or
|
|
253
|
+
// the uncompressed text chunks of a PNG) merge among themselves in slot order.
|
|
254
|
+
function mergeNestedBlocks(tags, block, context) {
|
|
255
|
+
return mergeEmbeddedBlocks(tags, block.blocks, context);
|
|
256
|
+
}
|
|
303
257
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
tagFilter,
|
|
307
|
-
dataView,
|
|
308
|
-
exifDataView,
|
|
309
|
-
tiffHeaderOffset,
|
|
310
|
-
deps,
|
|
311
|
-
});
|
|
312
|
-
let thumbnail = mainThumbnail;
|
|
313
|
-
if (!hasImage(mainThumbnail)) {
|
|
314
|
-
thumbnail = getFirstEmbeddedExifThumbnailWithImage(embeddedExifThumbnails) || mainThumbnail;
|
|
315
|
-
}
|
|
316
|
-
if (thumbnail) {
|
|
317
|
-
tags.Thumbnail = thumbnail;
|
|
318
|
-
}
|
|
258
|
+
function mergeEmbeddedBlocks(tags, blocks, context) {
|
|
259
|
+
const orderedBlocks = getBlocksInMergeOrder(blocks, context.expanded);
|
|
319
260
|
|
|
320
|
-
|
|
261
|
+
for (let i = 0; i < orderedBlocks.length; i++) {
|
|
262
|
+
tags = applyMergeMode(tags, orderedBlocks[i], context);
|
|
321
263
|
}
|
|
322
264
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
dataView,
|
|
331
|
-
parsedGroups
|
|
332
|
-
);
|
|
333
|
-
if (metadataRange) {
|
|
334
|
-
tags.metadataRange = metadataRange;
|
|
335
|
-
}
|
|
265
|
+
return tags;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// pngText holds the text tags only when there are any; otherwise
|
|
269
|
+
// addPngTextCopyOfPng may fill it with a copy of png.
|
|
270
|
+
function mergePngTextTags(tags, block, context) {
|
|
271
|
+
if (!Constants.USE_PNG || !context.tagFilter.shouldReturnGroup('png')) {
|
|
336
272
|
return tags;
|
|
337
273
|
}
|
|
274
|
+
const returnedTags = context.deps.filterTagsForReturn('png', block.tags, context.tagFilter);
|
|
338
275
|
|
|
339
|
-
if (
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
if (
|
|
344
|
-
fileType
|
|
345
|
-
&& tagFilter.shouldReturnGroup('file')
|
|
346
|
-
&& tagFilter.shouldReturnTag('file', 'FileType')
|
|
347
|
-
) {
|
|
348
|
-
if (expanded) {
|
|
349
|
-
if (!tags.file) {
|
|
350
|
-
tags.file = {};
|
|
351
|
-
}
|
|
352
|
-
tags.file.FileType = fileType;
|
|
353
|
-
} else {
|
|
354
|
-
tags.FileType = fileType;
|
|
355
|
-
}
|
|
276
|
+
if (context.expanded) {
|
|
277
|
+
context.merge.group(tags, 'png', returnedTags);
|
|
278
|
+
if (Object.keys(returnedTags).length > 0) {
|
|
279
|
+
context.merge.group(tags, 'pngText', returnedTags);
|
|
356
280
|
}
|
|
357
281
|
|
|
358
282
|
return tags;
|
|
359
283
|
}
|
|
360
284
|
|
|
361
|
-
return tags;
|
|
285
|
+
return context.merge.topLevel(tags, returnedTags);
|
|
362
286
|
}
|
|
363
287
|
|
|
364
|
-
function
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
}
|
|
288
|
+
function addThumbnailCandidate(tags, block, context) {
|
|
289
|
+
context.thumbnails.push({rank: block.rank, thumbnail: block.tags});
|
|
290
|
+
return tags;
|
|
368
291
|
}
|
|
369
292
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
293
|
+
// Expanded output only, derived from the parsed Exif group.
|
|
294
|
+
function addGpsGroup(tags, block, context) {
|
|
295
|
+
if (
|
|
296
|
+
Constants.USE_EXIF
|
|
297
|
+
&& context.expanded
|
|
298
|
+
&& context.tagFilter.shouldReturnGroup('gps')
|
|
299
|
+
&& context.parsedGroups.exif
|
|
300
|
+
) {
|
|
301
|
+
const gpsGroup = context.deps.getGpsGroupFromExifTags(context.parsedGroups.exif);
|
|
302
|
+
if (gpsGroup) {
|
|
303
|
+
tags.gps = context.deps.filterTagsForReturn('gps', gpsGroup, context.tagFilter);
|
|
304
|
+
}
|
|
373
305
|
}
|
|
374
306
|
|
|
375
|
-
|
|
376
|
-
'thumbnail',
|
|
377
|
-
thumbnailIfdTags,
|
|
378
|
-
tagFilter
|
|
379
|
-
);
|
|
380
|
-
|
|
381
|
-
return Constants.USE_EXIF
|
|
382
|
-
&& Constants.USE_THUMBNAIL
|
|
383
|
-
&& deps.Thumbnail.get(exifDataView || dataView, parsedThumbnailIfdTags, tiffHeaderOffset);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
function hasImage(thumbnail) {
|
|
387
|
-
return !!thumbnail && !!thumbnail.image;
|
|
307
|
+
return tags;
|
|
388
308
|
}
|
|
389
309
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
310
|
+
// Composite reads the merged tags, or with an active tag filter the parsed exif
|
|
311
|
+
// and file groups.
|
|
312
|
+
function addCompositeGroup(tags, block, context) {
|
|
313
|
+
if (!(Constants.USE_EXIF || Constants.USE_XMP) || !context.tagFilter.shouldReturnGroup('composite')) {
|
|
314
|
+
return tags;
|
|
393
315
|
}
|
|
394
|
-
return embeddedExifThumbnails.filter(hasImage)[0];
|
|
395
|
-
}
|
|
396
316
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
317
|
+
let compositeInput = tags;
|
|
318
|
+
let compositeInputExpanded = context.expanded;
|
|
319
|
+
if (context.tagFilter.isActive) {
|
|
320
|
+
compositeInput = {exif: context.parsedGroups.exif, file: context.parsedGroups.file};
|
|
321
|
+
compositeInputExpanded = true;
|
|
322
|
+
}
|
|
400
323
|
|
|
324
|
+
const composite = context.deps.Composite.get(compositeInput, compositeInputExpanded);
|
|
325
|
+
if (!composite) {
|
|
401
326
|
return tags;
|
|
402
327
|
}
|
|
403
328
|
|
|
404
|
-
|
|
329
|
+
const returnedCompositeTags = context.deps.filterTagsForReturn('composite', composite, context.tagFilter);
|
|
330
|
+
|
|
331
|
+
return mergeAssignGroup(tags, 'composite', returnedCompositeTags, context.expanded, context.deps);
|
|
405
332
|
}
|
|
406
333
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
334
|
+
// The main thumbnail when it has an image, else the first embedded Exif
|
|
335
|
+
// thumbnail with one, else the main thumbnail without an image.
|
|
336
|
+
function addThumbnail(tags, block, context) {
|
|
337
|
+
// Flat output can already hold an XMP or PNG text tag named Thumbnail.
|
|
338
|
+
delete tags.Thumbnail;
|
|
410
339
|
|
|
340
|
+
if (
|
|
341
|
+
!context.tagFilter.shouldReturnGroup('thumbnail')
|
|
342
|
+
|| !context.tagFilter.shouldReturnTag('thumbnail', 'Thumbnail')
|
|
343
|
+
) {
|
|
411
344
|
return tags;
|
|
412
345
|
}
|
|
413
346
|
|
|
414
|
-
const
|
|
415
|
-
|
|
347
|
+
const thumbnail = selectThumbnail(context.thumbnails);
|
|
348
|
+
if (thumbnail) {
|
|
349
|
+
tags.Thumbnail = thumbnail;
|
|
350
|
+
}
|
|
416
351
|
|
|
417
|
-
return
|
|
352
|
+
return tags;
|
|
418
353
|
}
|
|
419
354
|
|
|
420
|
-
|
|
421
|
-
if (
|
|
422
|
-
|
|
423
|
-
tags[groupKey] = returnedTags;
|
|
424
|
-
} else {
|
|
425
|
-
tags[groupKey] = deps.objectAssign({}, tags[groupKey], returnedTags);
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
return tags;
|
|
355
|
+
function selectThumbnail(candidates) {
|
|
356
|
+
if (!(Constants.USE_EXIF && Constants.USE_THUMBNAIL)) {
|
|
357
|
+
return undefined;
|
|
429
358
|
}
|
|
359
|
+
const main = candidates.filter((candidate) => candidate.rank === 'main')[0];
|
|
360
|
+
if (main && hasImage(main.thumbnail)) {
|
|
361
|
+
return main.thumbnail;
|
|
362
|
+
}
|
|
363
|
+
const embedded = candidates.filter((candidate) => candidate.rank === 'embedded' && hasImage(candidate.thumbnail))[0];
|
|
364
|
+
if (embedded) {
|
|
365
|
+
return embedded.thumbnail;
|
|
366
|
+
}
|
|
367
|
+
return main ? main.thumbnail : undefined;
|
|
368
|
+
}
|
|
430
369
|
|
|
431
|
-
|
|
370
|
+
function hasImage(thumbnail) {
|
|
371
|
+
return !!thumbnail && !!thumbnail.image;
|
|
432
372
|
}
|
|
433
373
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
exifCarriedGroups,
|
|
438
|
-
embeddedIptcTags,
|
|
439
|
-
parsedGroups,
|
|
440
|
-
expanded,
|
|
441
|
-
tagFilter,
|
|
442
|
-
tags,
|
|
443
|
-
deps,
|
|
444
|
-
merge = createCopyingMerge(deps),
|
|
445
|
-
}) {
|
|
446
|
-
if (embeddedExifTags) {
|
|
447
|
-
tags = addExifAndCarriedGroupsToTagsAndGroups({
|
|
448
|
-
exifTags: embeddedExifTags,
|
|
449
|
-
carriedGroups: exifCarriedGroups || {},
|
|
450
|
-
parsedGroups,
|
|
451
|
-
expanded,
|
|
452
|
-
tagFilter,
|
|
453
|
-
tags,
|
|
454
|
-
deps,
|
|
455
|
-
merge,
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
if (embeddedIptcTags) {
|
|
460
|
-
const parsedEmbeddedIptcTags =
|
|
461
|
-
deps.filterTagsForParse('iptc', embeddedIptcTags, tagFilter);
|
|
462
|
-
merge.group(parsedGroups, 'iptc', parsedEmbeddedIptcTags);
|
|
463
|
-
|
|
464
|
-
if (tagFilter.shouldReturnGroup('iptc')) {
|
|
465
|
-
const returnedEmbeddedIptcTags = deps.filterTagsForReturn(
|
|
466
|
-
'iptc',
|
|
467
|
-
parsedEmbeddedIptcTags,
|
|
468
|
-
tagFilter
|
|
469
|
-
);
|
|
470
|
-
if (expanded) {
|
|
471
|
-
merge.group(tags, 'iptc', returnedEmbeddedIptcTags);
|
|
472
|
-
} else {
|
|
473
|
-
tags = merge.topLevel(tags, returnedEmbeddedIptcTags);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
}
|
|
374
|
+
function addFileType(tags, block, context) {
|
|
375
|
+
// Flat output can already hold an XMP or PNG text tag named FileType.
|
|
376
|
+
delete tags.FileType;
|
|
477
377
|
|
|
478
|
-
if (
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
// Historical behavior in build fixtures:
|
|
487
|
-
// - if PNG text chunks yield actual "png" tags, `pngText` should contain only those
|
|
488
|
-
// - otherwise (e.g. only embedded Exif/IPTC), `pngText` should represent the full `png` group
|
|
489
|
-
// and will be filled in later as a fallback from `tags.png`
|
|
490
|
-
if (returnedPngTextTags && Object.keys(returnedPngTextTags).length > 0) {
|
|
491
|
-
merge.group(tags, 'pngText', returnedPngTextTags);
|
|
378
|
+
if (
|
|
379
|
+
context.fileType
|
|
380
|
+
&& context.tagFilter.shouldReturnGroup('file')
|
|
381
|
+
&& context.tagFilter.shouldReturnTag('file', 'FileType')
|
|
382
|
+
) {
|
|
383
|
+
if (context.expanded) {
|
|
384
|
+
if (!tags.file) {
|
|
385
|
+
tags.file = {};
|
|
492
386
|
}
|
|
387
|
+
tags.file.FileType = context.fileType;
|
|
493
388
|
} else {
|
|
494
|
-
tags =
|
|
389
|
+
tags.FileType = context.fileType;
|
|
495
390
|
}
|
|
496
391
|
}
|
|
497
392
|
|
|
498
393
|
return tags;
|
|
499
394
|
}
|
|
500
395
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
* for parse again.
|
|
506
|
-
*
|
|
507
|
-
* @returns {object} The tags, which flat output replaces rather than mutates.
|
|
508
|
-
*/
|
|
509
|
-
export function addExifAndCarriedGroupsToTagsAndGroups({
|
|
510
|
-
exifTags,
|
|
511
|
-
carriedGroups,
|
|
512
|
-
parsedGroups,
|
|
513
|
-
expanded,
|
|
514
|
-
tagFilter,
|
|
515
|
-
tags,
|
|
516
|
-
deps,
|
|
517
|
-
merge,
|
|
518
|
-
}) {
|
|
519
|
-
let flatXmpGroup = undefined;
|
|
520
|
-
|
|
521
|
-
for (let i = 0; i < EXIF_CARRIED_GROUP_ORDER.length; i++) {
|
|
522
|
-
const groupKey = EXIF_CARRIED_GROUP_ORDER[i];
|
|
523
|
-
const group = carriedGroups[groupKey];
|
|
524
|
-
if (group === undefined) {
|
|
525
|
-
continue;
|
|
526
|
-
}
|
|
527
|
-
if (groupKey === 'xmp' && !expanded) {
|
|
528
|
-
flatXmpGroup = group;
|
|
529
|
-
continue;
|
|
530
|
-
}
|
|
531
|
-
tags = addCarriedGroup(groupKey, group);
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
if (exifTags) {
|
|
535
|
-
const parsedExifTags = deps.filterTagsForParse('exif', exifTags, tagFilter);
|
|
536
|
-
merge.group(parsedGroups, 'exif', parsedExifTags);
|
|
537
|
-
|
|
538
|
-
if (tagFilter.shouldReturnGroup('exif')) {
|
|
539
|
-
const returnedExifTags = deps.filterTagsForReturn('exif', parsedExifTags, tagFilter);
|
|
540
|
-
if (expanded) {
|
|
541
|
-
merge.group(tags, 'exif', returnedExifTags);
|
|
542
|
-
} else {
|
|
543
|
-
tags = merge.topLevel(tags, returnedExifTags);
|
|
544
|
-
}
|
|
545
|
-
}
|
|
396
|
+
// Expanded output only.
|
|
397
|
+
function addMetadataRange(tags, block, context) {
|
|
398
|
+
if (!context.expanded) {
|
|
399
|
+
return tags;
|
|
546
400
|
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
401
|
+
const metadataRange = buildMetadataRange(
|
|
402
|
+
block.metadataBlocks,
|
|
403
|
+
block.metadataTruncated,
|
|
404
|
+
context.dataView,
|
|
405
|
+
context.parsedGroups
|
|
406
|
+
);
|
|
407
|
+
if (metadataRange) {
|
|
408
|
+
tags.metadataRange = metadataRange;
|
|
550
409
|
}
|
|
551
|
-
|
|
552
410
|
return tags;
|
|
553
|
-
|
|
554
|
-
function addCarriedGroup(groupKey, group, isFlatXmp) {
|
|
555
|
-
merge.group(parsedGroups, groupKey, group);
|
|
556
|
-
if (!tagFilter.shouldReturnGroup(groupKey)) {
|
|
557
|
-
return tags;
|
|
558
|
-
}
|
|
559
|
-
const returnedTags = deps.filterTagsForReturn(groupKey, group, tagFilter);
|
|
560
|
-
if (expanded) {
|
|
561
|
-
merge.group(tags, groupKey, returnedTags);
|
|
562
|
-
return tags;
|
|
563
|
-
}
|
|
564
|
-
return merge.topLevel(tags, isFlatXmp ? getXmpTagsWithoutRaw(returnedTags) : returnedTags);
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
function getXmpTagsWithoutRaw(xmpTags) {
|
|
568
|
-
const xmpTagsWithoutRaw = deps.objectAssign({}, xmpTags);
|
|
569
|
-
delete xmpTagsWithoutRaw._raw;
|
|
570
|
-
return xmpTagsWithoutRaw;
|
|
571
|
-
}
|
|
572
411
|
}
|
|
573
412
|
|
|
574
413
|
function createCopyingMerge(deps) {
|
|
@@ -595,7 +434,7 @@ function createInPlaceMerge(deps) {
|
|
|
595
434
|
},
|
|
596
435
|
};
|
|
597
436
|
|
|
598
|
-
// Earlier
|
|
437
|
+
// Earlier blocks can share these containers (tags.png can be tags.pngFile or the
|
|
599
438
|
// synchronous text chunks' tags), so each is copied once before merging in place.
|
|
600
439
|
function own(container) {
|
|
601
440
|
if (ownedContainers.indexOf(container) !== -1) {
|