exifreader 4.53.0 → 4.55.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 +404 -33
- package/bin/analyze.js +139 -9
- package/bin/build-pages.js +21 -35
- package/bin/cli.js +81 -13
- package/bin/generate-tag-modules.js +287 -0
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +213 -38
- package/package.json +71 -11
- package/src/base64-image.js +27 -0
- package/src/composable/brand.js +10 -0
- package/src/composable/composition-tag-filter.js +97 -0
- package/src/composable/composition.js +195 -0
- package/src/composable/core.d.ts +148 -0
- package/src/composable/core.js +526 -0
- package/src/composable/exif-block-reader.js +197 -0
- package/src/composable/formats/avif.js +19 -0
- package/src/composable/formats/gif.js +28 -0
- package/src/composable/formats/heic.js +19 -0
- package/src/composable/formats/iso-bmff-file-reader.js +14 -0
- package/src/composable/formats/jpeg.js +55 -0
- package/src/composable/formats/jxl.js +30 -0
- package/src/composable/formats/png.js +187 -0
- package/src/composable/formats/tiff.js +18 -0
- package/src/composable/formats/webp.js +28 -0
- package/src/composable/formats/xml.js +18 -0
- package/src/composable/formats.d.ts +17 -0
- package/src/composable/formats.js +17 -0
- package/src/composable/group-helpers.js +129 -0
- package/src/composable/groups/canon.js +26 -0
- package/src/composable/groups/composite.js +43 -0
- package/src/composable/groups/exif.js +48 -0
- package/src/composable/groups/gps.js +75 -0
- package/src/composable/groups/icc.js +52 -0
- package/src/composable/groups/iptc.js +86 -0
- package/src/composable/groups/maker-notes.js +21 -0
- package/src/composable/groups/mpf.js +25 -0
- package/src/composable/groups/pentax.js +34 -0
- package/src/composable/groups/photoshop.js +18 -0
- package/src/composable/groups/thumbnail.js +131 -0
- package/src/composable/groups/xmp.js +118 -0
- package/src/composable/groups.d.ts +20 -0
- package/src/composable/groups.js +105 -0
- package/src/composable/iptc-block-reader.js +44 -0
- package/src/composable/read-view.js +165 -0
- package/src/composable/tag-binding-name.js +17 -0
- package/src/composable/tags/exif.d.ts +295 -0
- package/src/composable/tags/exif.js +396 -0
- package/src/composable/tags/iptc.d.ts +84 -0
- package/src/composable/tags/iptc.js +109 -0
- package/src/composable/value-budget.js +24 -0
- package/src/composite.js +2 -2
- package/src/decompression.js +60 -0
- package/src/dom-parser.js +5 -6
- package/src/engine.js +332 -0
- package/src/errors.js +8 -2
- package/src/exif-reader.d.ts +8 -0
- package/src/exif-reader.js +118 -1121
- package/src/file-loaders.js +74 -1
- package/src/file-tags.js +9 -9
- 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 +25 -59
- package/src/iptc-tag-names-descriptions.js +334 -0
- package/src/iptc-tag-names.js +50 -306
- package/src/iptc-tags.js +41 -27
- package/src/jfif-tags.js +9 -9
- package/src/load-auto.js +2 -2
- package/src/loadview-pipeline.js +197 -498
- package/src/mpf-tags.js +10 -7
- package/src/node-require.js +15 -2
- package/src/png-text-tags.js +90 -327
- package/src/tag-filter-config.js +24 -15
- package/src/tag-filter.js +67 -3
- package/src/tag-names-0th-ifd-descriptions.js +232 -0
- package/src/tag-names-0th-ifd.js +49 -173
- package/src/tag-names-common.js +263 -211
- package/src/tag-names-exif-ifd-descriptions.js +249 -0
- package/src/tag-names-exif-ifd.js +55 -187
- package/src/tag-names-gps-ifd-descriptions.js +156 -0
- package/src/tag-names-gps-ifd.js +39 -146
- package/src/tag-names-utils.js +33 -10
- package/src/tags-helpers.js +14 -24
- package/src/tags.js +23 -11
- package/src/thumbnail.js +7 -5
- package/src/types.js +2 -0
- package/src/unsupported-format-error.js +21 -0
- package/src/utils.js +64 -119
- package/src/writer/exif-tag-table.js +321 -0
- package/src/xml.js +12 -15
- package/src/xmp-tag-names.js +42 -21
- package/src/xmp-tags.js +9 -10
- package/webpack.config.js +1 -1
package/src/loadview-pipeline.js
CHANGED
|
@@ -2,396 +2,168 @@
|
|
|
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
|
-
|
|
5
|
+
// A block's position in each mode is the index of its slot. Expanded output
|
|
6
|
+
// takes its key order from the first block of each group: discovery order,
|
|
7
|
+
// with the groups an Exif block carries just before it. In flat output a later
|
|
8
|
+
// block wins a key clash, so Exif wins over the groups it carries except an
|
|
9
|
+
// ApplicationNotes XMP packet.
|
|
10
|
+
export const MERGE_ORDER = {
|
|
11
|
+
expanded: [
|
|
12
|
+
'file', 'jfif',
|
|
13
|
+
'carriedIptc', 'carriedXmp', 'carriedPhotoshop', 'carriedIcc', 'carriedMakerNotes', 'exif',
|
|
14
|
+
'iptc', 'xmp', 'brobExif', 'brobXmp', 'icc', 'mpf',
|
|
15
|
+
'pngFile', 'pngText', 'deferredPngText', 'pngChunk', 'riff', 'gif', 'jxlFile', 'isoBmffFile',
|
|
16
|
+
'gps', 'composite', 'thumbnail', 'fileType', 'metadataRange',
|
|
17
|
+
],
|
|
18
|
+
flat: [
|
|
19
|
+
'file', 'jfif',
|
|
20
|
+
'carriedIptc', 'carriedPhotoshop', 'carriedIcc', 'carriedMakerNotes', 'exif', 'carriedXmp',
|
|
21
|
+
'iptc', 'xmp', 'brobExif', 'brobXmp', 'icc', 'mpf',
|
|
22
|
+
'pngFile', 'pngText', 'deferredPngText', 'pngChunk', 'riff', 'gif', 'jxlFile', 'isoBmffFile',
|
|
23
|
+
'gps', 'composite', 'thumbnail', 'fileType', 'metadataRange',
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const CORE_MERGE_MODES = {
|
|
28
|
+
assign: assignGroupTags,
|
|
29
|
+
merge: mergeGroupTags,
|
|
30
|
+
nested: mergeNestedBlocks,
|
|
31
|
+
thumbnail: removeThumbnailTag,
|
|
32
|
+
fileType: addFileType,
|
|
33
|
+
metadataRange: addMetadataRange,
|
|
34
|
+
};
|
|
6
35
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Merges the blocks into the returned tags, in the order MERGE_ORDER gives the
|
|
38
|
+
* current mode, whatever order they were pushed in.
|
|
39
|
+
*
|
|
40
|
+
* A block has a `slot` (its place in MERGE_ORDER) and a `mode` (a key of
|
|
41
|
+
* `modes` or of CORE_MERGE_MODES). A tag block also has the `group` it merges
|
|
42
|
+
* into and its parsed `tags`; a `nested` container has `blocks`, merged among
|
|
43
|
+
* themselves in slot order at the container's position. A metadataRange block
|
|
44
|
+
* carries `metadataBlocks` and `metadataTruncated`.
|
|
45
|
+
*
|
|
46
|
+
* `modes` holds the modes the composed formats and groups bring, each
|
|
47
|
+
* `(tags, block, context) => tags`; one of them wins over a core mode of the
|
|
48
|
+
* same name.
|
|
49
|
+
*
|
|
50
|
+
* The top level merges in place, so a PNG with thousands of text chunk blocks
|
|
51
|
+
* stays linear.
|
|
52
|
+
*
|
|
53
|
+
* `tagFilterIsReadCap` says the tag filter is active only because includeTags
|
|
54
|
+
* caps what is read; flat Composite then reads every parsed tag block, returned
|
|
55
|
+
* or not, merged in flat order as an unfiltered load merges them.
|
|
56
|
+
*
|
|
57
|
+
* @returns {object} The tags.
|
|
58
|
+
*/
|
|
59
|
+
export function buildTagsFromMergeBlocks({
|
|
60
|
+
mergeBlocks,
|
|
15
61
|
parsedGroups,
|
|
16
62
|
expanded,
|
|
17
63
|
tagFilter,
|
|
64
|
+
tagFilterIsReadCap,
|
|
18
65
|
dataView,
|
|
19
|
-
tiffHeaderOffset,
|
|
20
|
-
exifDataView,
|
|
21
66
|
fileType,
|
|
22
|
-
|
|
23
|
-
pngTextIsAsync,
|
|
24
|
-
thumbnailIfdTags,
|
|
67
|
+
modes = {},
|
|
25
68
|
deps,
|
|
26
69
|
}) {
|
|
70
|
+
const context = {
|
|
71
|
+
parsedGroups,
|
|
72
|
+
expanded,
|
|
73
|
+
tagFilter,
|
|
74
|
+
compositeInput: tagFilterIsReadCap && !expanded && tagFilter.shouldReturnGroup('composite') ? {} : undefined,
|
|
75
|
+
dataView,
|
|
76
|
+
fileType,
|
|
77
|
+
thumbnails: [],
|
|
78
|
+
modes,
|
|
79
|
+
deps,
|
|
80
|
+
merge: createInPlaceMerge(deps),
|
|
81
|
+
};
|
|
82
|
+
const orderedBlocks = getBlocksInMergeOrder(mergeBlocks, expanded);
|
|
27
83
|
let tags = {};
|
|
28
|
-
const embeddedExifThumbnails = [];
|
|
29
|
-
|
|
30
|
-
for (let i = 0; i < mergeSteps.length; i++) {
|
|
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
|
-
});
|
|
46
|
-
}
|
|
47
84
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
&& expanded
|
|
51
|
-
&& pngTextIsAsync
|
|
52
|
-
&& tagFilter.shouldReturnGroup('png')
|
|
53
|
-
&& tags.png
|
|
54
|
-
) {
|
|
55
|
-
tags.pngText = deps.objectAssign({}, tags.png);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
Constants.USE_PNG
|
|
60
|
-
&& expanded
|
|
61
|
-
&& tagFilter.shouldReturnGroup('png')
|
|
62
|
-
&& deps.hasPngTextData(pngTextChunks)
|
|
63
|
-
&& tags.png
|
|
64
|
-
&& !tags.pngText
|
|
65
|
-
) {
|
|
66
|
-
tags.pngText = deps.objectAssign({}, tags.png);
|
|
85
|
+
for (let i = 0; i < orderedBlocks.length; i++) {
|
|
86
|
+
tags = applyMergeMode(tags, orderedBlocks[i], context);
|
|
67
87
|
}
|
|
68
88
|
|
|
69
89
|
return tags;
|
|
70
90
|
}
|
|
71
91
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
92
|
+
// Sorts by position, then push order, without relying on a stable sort.
|
|
93
|
+
function getBlocksInMergeOrder(blocks, expanded) {
|
|
94
|
+
const order = expanded ? MERGE_ORDER.expanded : MERGE_ORDER.flat;
|
|
95
|
+
|
|
96
|
+
return blocks
|
|
97
|
+
.map((block, index) => ({block, index, position: order.indexOf(block.slot)}))
|
|
98
|
+
.sort((a, b) => (a.position - b.position) || (a.index - b.index))
|
|
99
|
+
.map((entry) => entry.block);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function applyMergeMode(tags, block, context) {
|
|
103
|
+
const mode = context.modes[block.mode] || CORE_MERGE_MODES[block.mode];
|
|
104
|
+
return mode(tags, block, context);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Merges one block into the tags with the function its mode names.
|
|
109
|
+
*
|
|
110
|
+
* @param {object} context The block, the tags so far and the merge state; see
|
|
111
|
+
* buildTagsFromMergeBlocks for the block shape and `modes`. `merge` defaults
|
|
112
|
+
* to a copying merge and `thumbnails` to a new list.
|
|
113
|
+
* @returns {object} The tags, which flat output replaces rather than mutates.
|
|
114
|
+
*/
|
|
115
|
+
export function mergeBlock({
|
|
116
|
+
block,
|
|
117
|
+
tags,
|
|
75
118
|
parsedGroups,
|
|
76
119
|
expanded,
|
|
77
120
|
tagFilter,
|
|
78
121
|
dataView,
|
|
79
|
-
tiffHeaderOffset,
|
|
80
|
-
exifDataView,
|
|
81
122
|
fileType,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
tags,
|
|
123
|
+
thumbnails = [],
|
|
124
|
+
modes = {},
|
|
85
125
|
deps,
|
|
126
|
+
merge = createCopyingMerge(deps),
|
|
86
127
|
}) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return mergeMergeGroup(tags, step.groupKey, returnedTags, expanded, deps);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (Constants.USE_XMP && step.type === 'mergeXmpGroupAssign') {
|
|
102
|
-
const returnedTags =
|
|
103
|
-
deps.filterTagsForReturn('xmp', step.parsedTags, tagFilter);
|
|
104
|
-
|
|
105
|
-
return mergeXmpGroup(tags, returnedTags, expanded, deps);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (Constants.USE_ICC && step.type === 'mergeIccDeferred') {
|
|
109
|
-
const resolvedReadTags = deferredResults[step.deferredKey];
|
|
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);
|
|
120
|
-
|
|
121
|
-
return mergeAssignGroup(tags, 'icc', returnedIccTags, expanded, deps);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (Constants.USE_JXL && step.type === 'mergeBrobExifDeferred') {
|
|
125
|
-
const resolved = deferredResults[step.deferredKey];
|
|
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);
|
|
161
|
-
|
|
162
|
-
return mergeXmpGroup(tags, returnedTags, expanded, deps);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (Constants.USE_PNG && step.type === 'mergePngFile') {
|
|
166
|
-
const returnedPngFileTags =
|
|
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;
|
|
180
|
-
|
|
181
|
-
return tags;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return deps.objectAssign({}, tags, returnedPngFileTags);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (Constants.USE_PNG && step.type === 'mergePngChunk') {
|
|
188
|
-
const returnedPngChunkTags =
|
|
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
|
-
}
|
|
243
|
-
|
|
244
|
-
return tags;
|
|
245
|
-
}
|
|
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
|
-
|
|
261
|
-
return tags;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if ((Constants.USE_EXIF || Constants.USE_XMP) && step.type === 'composite') {
|
|
265
|
-
if (!tagFilter.shouldReturnGroup('composite')) {
|
|
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
|
-
}
|
|
275
|
-
|
|
276
|
-
const composite = deps.Composite.get(compositeInput, compositeInputExpanded);
|
|
277
|
-
if (!composite) {
|
|
278
|
-
return tags;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const returnedCompositeTags =
|
|
282
|
-
deps.filterTagsForReturn('composite', composite, tagFilter);
|
|
283
|
-
|
|
284
|
-
return mergeAssignGroup(
|
|
285
|
-
tags,
|
|
286
|
-
'composite',
|
|
287
|
-
returnedCompositeTags,
|
|
288
|
-
expanded,
|
|
289
|
-
deps
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
if (step.type === 'thumbnail') {
|
|
294
|
-
// Flat output can already hold an XMP or PNG text tag named Thumbnail.
|
|
295
|
-
delete tags.Thumbnail;
|
|
296
|
-
|
|
297
|
-
if (
|
|
298
|
-
!tagFilter.shouldReturnGroup('thumbnail')
|
|
299
|
-
|| !tagFilter.shouldReturnTag('thumbnail', 'Thumbnail')
|
|
300
|
-
) {
|
|
301
|
-
return tags;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
const mainThumbnail = getMainThumbnail({
|
|
305
|
-
thumbnailIfdTags,
|
|
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
|
-
}
|
|
319
|
-
|
|
320
|
-
return tags;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
if (step.type === 'metadataRange') {
|
|
324
|
-
if (!expanded) {
|
|
325
|
-
return tags;
|
|
326
|
-
}
|
|
327
|
-
const metadataRange = buildMetadataRange(
|
|
328
|
-
step.metadataBlocks,
|
|
329
|
-
step.metadataTruncated,
|
|
330
|
-
dataView,
|
|
331
|
-
parsedGroups
|
|
332
|
-
);
|
|
333
|
-
if (metadataRange) {
|
|
334
|
-
tags.metadataRange = metadataRange;
|
|
335
|
-
}
|
|
336
|
-
return tags;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
if (step.type === 'fileType') {
|
|
340
|
-
// Flat output can already hold an XMP or PNG text tag named FileType.
|
|
341
|
-
delete tags.FileType;
|
|
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
|
-
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
return tags;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
return tags;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
function addEmbeddedExifThumbnail(embeddedExifThumbnails, embeddedExifThumbnail) {
|
|
365
|
-
if (embeddedExifThumbnail) {
|
|
366
|
-
embeddedExifThumbnails.push(embeddedExifThumbnail);
|
|
367
|
-
}
|
|
128
|
+
return applyMergeMode(tags, block, {
|
|
129
|
+
parsedGroups,
|
|
130
|
+
expanded,
|
|
131
|
+
tagFilter,
|
|
132
|
+
dataView,
|
|
133
|
+
fileType,
|
|
134
|
+
thumbnails,
|
|
135
|
+
modes,
|
|
136
|
+
deps,
|
|
137
|
+
merge,
|
|
138
|
+
});
|
|
368
139
|
}
|
|
369
140
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Merges a tag block by assigning its group: it writes the parsed group
|
|
143
|
+
* whether or not the group is returned, since gps, composite and metadataRange
|
|
144
|
+
* read it, adds the tags to the Composite input and merges the returned tags.
|
|
145
|
+
*
|
|
146
|
+
* @returns {object} The tags.
|
|
147
|
+
*/
|
|
148
|
+
export function assignGroupTags(tags, block, context) {
|
|
149
|
+
context.parsedGroups[block.group] = block.tags;
|
|
150
|
+
addToCompositeInput(block.tags, context);
|
|
151
|
+
if (!context.tagFilter.shouldReturnGroup(block.group)) {
|
|
152
|
+
return tags;
|
|
373
153
|
}
|
|
154
|
+
const returnedTags = context.deps.filterTagsForReturn(block.group, block.tags, context.tagFilter);
|
|
374
155
|
|
|
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;
|
|
156
|
+
return mergeAssignGroup(tags, block.group, returnedTags, context.expanded, context.deps);
|
|
388
157
|
}
|
|
389
158
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Adds a block's parsed tags to the flat Composite input, when the merge
|
|
161
|
+
* collects one (see tagFilterIsReadCap in buildTagsFromMergeBlocks).
|
|
162
|
+
*/
|
|
163
|
+
export function addToCompositeInput(blockTags, context) {
|
|
164
|
+
if (context.compositeInput) {
|
|
165
|
+
context.deps.objectAssign(context.compositeInput, blockTags);
|
|
393
166
|
}
|
|
394
|
-
return embeddedExifThumbnails.filter(hasImage)[0];
|
|
395
167
|
}
|
|
396
168
|
|
|
397
169
|
export function mergeAssignGroup(tags, groupKey, returnedTags, expanded, deps) {
|
|
@@ -401,174 +173,101 @@ export function mergeAssignGroup(tags, groupKey, returnedTags, expanded, deps) {
|
|
|
401
173
|
return tags;
|
|
402
174
|
}
|
|
403
175
|
|
|
404
|
-
return deps.objectAssign({}, tags, returnedTags);
|
|
176
|
+
return deps.objectAssign({}, tags, getTagsForFlat(groupKey, returnedTags, deps));
|
|
405
177
|
}
|
|
406
178
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
return tags;
|
|
179
|
+
// Every XMP block drops the raw packet in flat output.
|
|
180
|
+
function getTagsForFlat(groupKey, returnedTags, deps) {
|
|
181
|
+
if (groupKey !== 'xmp') {
|
|
182
|
+
return returnedTags;
|
|
412
183
|
}
|
|
184
|
+
const xmpTagsWithoutRaw = deps.objectAssign({}, returnedTags);
|
|
185
|
+
delete xmpTagsWithoutRaw._raw;
|
|
413
186
|
|
|
414
|
-
|
|
415
|
-
delete returnedTagsForFlat._raw;
|
|
416
|
-
|
|
417
|
-
return deps.objectAssign({}, tags, returnedTagsForFlat);
|
|
187
|
+
return xmpTagsWithoutRaw;
|
|
418
188
|
}
|
|
419
189
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
190
|
+
function mergeGroupTags(tags, block, context) {
|
|
191
|
+
context.merge.group(context.parsedGroups, block.group, block.tags);
|
|
192
|
+
addToCompositeInput(block.tags, context);
|
|
193
|
+
if (!context.tagFilter.shouldReturnGroup(block.group)) {
|
|
194
|
+
return tags;
|
|
195
|
+
}
|
|
196
|
+
const returnedTags = context.deps.filterTagsForReturn(block.group, block.tags, context.tagFilter);
|
|
197
|
+
|
|
198
|
+
if (context.expanded) {
|
|
199
|
+
context.merge.group(tags, block.group, returnedTags);
|
|
427
200
|
|
|
428
201
|
return tags;
|
|
429
202
|
}
|
|
430
203
|
|
|
431
|
-
return
|
|
204
|
+
return context.merge.topLevel(tags, getTagsForFlat(block.group, returnedTags, context.deps));
|
|
432
205
|
}
|
|
433
206
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
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
|
-
}
|
|
207
|
+
// The blocks of one container (an Exif block with the groups it carries, or
|
|
208
|
+
// the uncompressed text chunks of a PNG) merge among themselves in slot order.
|
|
209
|
+
function mergeNestedBlocks(tags, block, context) {
|
|
210
|
+
return mergeEmbeddedBlocks(tags, block.blocks, context);
|
|
211
|
+
}
|
|
458
212
|
|
|
459
|
-
|
|
460
|
-
|
|
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
|
-
}
|
|
213
|
+
function mergeEmbeddedBlocks(tags, blocks, context) {
|
|
214
|
+
const orderedBlocks = getBlocksInMergeOrder(blocks, context.expanded);
|
|
477
215
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
const returnedPngTextTags =
|
|
481
|
-
deps.filterTagsForReturn('png', parsedPngTextTags, tagFilter);
|
|
482
|
-
parsedGroups.pngText = parsedPngTextTags;
|
|
483
|
-
|
|
484
|
-
if (expanded) {
|
|
485
|
-
merge.group(tags, 'png', returnedPngTextTags);
|
|
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);
|
|
492
|
-
}
|
|
493
|
-
} else {
|
|
494
|
-
tags = merge.topLevel(tags, returnedPngTextTags);
|
|
495
|
-
}
|
|
216
|
+
for (let i = 0; i < orderedBlocks.length; i++) {
|
|
217
|
+
tags = applyMergeMode(tags, orderedBlocks[i], context);
|
|
496
218
|
}
|
|
497
219
|
|
|
498
220
|
return tags;
|
|
499
221
|
}
|
|
500
222
|
|
|
501
223
|
/**
|
|
502
|
-
*
|
|
503
|
-
* block merges them: the carried groups, then Exif, then in flat output the
|
|
504
|
-
* ApplicationNotes XMP. The carried groups arrive parsed and are not filtered
|
|
505
|
-
* for parse again.
|
|
224
|
+
* The core thumbnail mode, which the thumbnail group's mode also runs.
|
|
506
225
|
*
|
|
507
|
-
* @returns {object} The tags
|
|
226
|
+
* @returns {object} The tags without a top-level Thumbnail tag.
|
|
508
227
|
*/
|
|
509
|
-
export function
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
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
|
-
}
|
|
228
|
+
export function removeThumbnailTag(tags) {
|
|
229
|
+
// Flat output can already hold an XMP or PNG text tag named Thumbnail.
|
|
230
|
+
delete tags.Thumbnail;
|
|
231
|
+
return tags;
|
|
232
|
+
}
|
|
533
233
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
234
|
+
function addFileType(tags, block, context) {
|
|
235
|
+
// Flat output can already hold an XMP or PNG text tag named FileType.
|
|
236
|
+
delete tags.FileType;
|
|
537
237
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
238
|
+
if (
|
|
239
|
+
context.fileType
|
|
240
|
+
&& context.tagFilter.shouldReturnGroup('file')
|
|
241
|
+
&& context.tagFilter.shouldReturnTag('file', 'FileType')
|
|
242
|
+
) {
|
|
243
|
+
if (context.expanded) {
|
|
244
|
+
if (!tags.file) {
|
|
245
|
+
tags.file = {};
|
|
544
246
|
}
|
|
247
|
+
tags.file.FileType = context.fileType;
|
|
248
|
+
} else {
|
|
249
|
+
tags.FileType = context.fileType;
|
|
545
250
|
}
|
|
546
251
|
}
|
|
547
252
|
|
|
548
|
-
if (flatXmpGroup !== undefined) {
|
|
549
|
-
tags = addCarriedGroup('xmp', flatXmpGroup, true);
|
|
550
|
-
}
|
|
551
|
-
|
|
552
253
|
return tags;
|
|
254
|
+
}
|
|
553
255
|
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
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);
|
|
256
|
+
// Expanded output only.
|
|
257
|
+
function addMetadataRange(tags, block, context) {
|
|
258
|
+
if (!context.expanded) {
|
|
259
|
+
return tags;
|
|
565
260
|
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
261
|
+
const metadataRange = buildMetadataRange(
|
|
262
|
+
block.metadataBlocks,
|
|
263
|
+
block.metadataTruncated,
|
|
264
|
+
context.dataView,
|
|
265
|
+
context.parsedGroups
|
|
266
|
+
);
|
|
267
|
+
if (metadataRange) {
|
|
268
|
+
tags.metadataRange = metadataRange;
|
|
571
269
|
}
|
|
270
|
+
return tags;
|
|
572
271
|
}
|
|
573
272
|
|
|
574
273
|
function createCopyingMerge(deps) {
|
|
@@ -595,7 +294,7 @@ function createInPlaceMerge(deps) {
|
|
|
595
294
|
},
|
|
596
295
|
};
|
|
597
296
|
|
|
598
|
-
// Earlier
|
|
297
|
+
// Earlier blocks can share these containers (tags.png can be tags.pngFile or the
|
|
599
298
|
// synchronous text chunks' tags), so each is copied once before merging in place.
|
|
600
299
|
function own(container) {
|
|
601
300
|
if (ownedContainers.indexOf(container) !== -1) {
|