exifreader 4.35.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/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 +63 -16
- package/src/tags.js +29 -13
- package/webpack.config.js +3 -0
|
@@ -0,0 +1,124 @@
|
|
|
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 const ID_CAPABLE_GROUPS = {
|
|
6
|
+
exif: true,
|
|
7
|
+
iptc: true,
|
|
8
|
+
photoshop: true,
|
|
9
|
+
mpf: true,
|
|
10
|
+
makerNotes: true,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const FILTER_GROUPS = {
|
|
14
|
+
exif: true,
|
|
15
|
+
iptc: true,
|
|
16
|
+
xmp: true,
|
|
17
|
+
icc: true,
|
|
18
|
+
photoshop: true,
|
|
19
|
+
makerNotes: true,
|
|
20
|
+
mpf: true,
|
|
21
|
+
file: true,
|
|
22
|
+
jfif: true,
|
|
23
|
+
png: true,
|
|
24
|
+
riff: true,
|
|
25
|
+
gif: true,
|
|
26
|
+
gps: true,
|
|
27
|
+
composite: true,
|
|
28
|
+
thumbnail: true,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const EXIF_POINTER_TAGS = {
|
|
32
|
+
exifIfdPointer: 'Exif IFD Pointer',
|
|
33
|
+
gpsInfoIfdPointer: 'GPS Info IFD Pointer',
|
|
34
|
+
interoperabilityIfdPointer: 'Interoperability IFD Pointer',
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const EXIF_DEPENDENCY_TAGS = {
|
|
38
|
+
thumbnail: [
|
|
39
|
+
'JPEGInterchangeFormat',
|
|
40
|
+
'JPEGInterchangeFormatLength',
|
|
41
|
+
],
|
|
42
|
+
iptc: ['IPTC-NAA'],
|
|
43
|
+
xmp: ['ApplicationNotes'],
|
|
44
|
+
icc: ['ICC_Profile'],
|
|
45
|
+
photoshop: ['ImageSourceData', 'PhotoshopSettings'],
|
|
46
|
+
makerNotes: ['MakerNote', 'Make'],
|
|
47
|
+
gps: [
|
|
48
|
+
'GPSLatitude',
|
|
49
|
+
'GPSLatitudeRef',
|
|
50
|
+
'GPSLongitude',
|
|
51
|
+
'GPSLongitudeRef',
|
|
52
|
+
'GPSAltitude',
|
|
53
|
+
'GPSAltitudeRef',
|
|
54
|
+
],
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const COMPOSITE_DEPENDENCY_TAGS = {
|
|
58
|
+
file: ['Image Width', 'Image Height'],
|
|
59
|
+
exif: [
|
|
60
|
+
'FocalLength',
|
|
61
|
+
'FocalPlaneXResolution',
|
|
62
|
+
'FocalPlaneYResolution',
|
|
63
|
+
'FocalPlaneResolutionUnit',
|
|
64
|
+
'FocalLengthIn35mmFilm',
|
|
65
|
+
],
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export function getExifTagDependenciesForInclude(includeTags) {
|
|
69
|
+
const requiredTags = Object.create(null);
|
|
70
|
+
|
|
71
|
+
if (!includeTags) {
|
|
72
|
+
return requiredTags;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (Array.isArray(includeTags.exif) && includeTags.exif.length > 0) {
|
|
76
|
+
requiredTags[EXIF_POINTER_TAGS.exifIfdPointer] = true;
|
|
77
|
+
addPointerDependenciesFromExifTagSelectors(requiredTags, includeTags.exif);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
for (const groupKey in EXIF_DEPENDENCY_TAGS) {
|
|
81
|
+
if (isRequestedIncludeValue(includeTags[groupKey])) {
|
|
82
|
+
const dependencyTags = EXIF_DEPENDENCY_TAGS[groupKey];
|
|
83
|
+
for (let i = 0; i < dependencyTags.length; i++) {
|
|
84
|
+
requiredTags[dependencyTags[i]] = true;
|
|
85
|
+
}
|
|
86
|
+
requiredTags[EXIF_POINTER_TAGS.exifIfdPointer] = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (isRequestedIncludeValue(includeTags.gps)) {
|
|
91
|
+
requiredTags[EXIF_POINTER_TAGS.gpsInfoIfdPointer] = true;
|
|
92
|
+
requiredTags[EXIF_POINTER_TAGS.exifIfdPointer] = true;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return requiredTags;
|
|
96
|
+
|
|
97
|
+
function addPointerDependenciesFromExifTagSelectors(pointerSet, selectors) {
|
|
98
|
+
for (let i = 0; i < selectors.length; i++) {
|
|
99
|
+
const selector = selectors[i];
|
|
100
|
+
if (typeof selector !== 'string') {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const selectorLower = selector.toLowerCase();
|
|
105
|
+
if (selectorLower.indexOf('gps') === 0) {
|
|
106
|
+
pointerSet[EXIF_POINTER_TAGS.gpsInfoIfdPointer] = true;
|
|
107
|
+
}
|
|
108
|
+
if (
|
|
109
|
+
selectorLower.indexOf('interoperability') === 0
|
|
110
|
+
|| selectorLower.indexOf('relatedimage') === 0
|
|
111
|
+
) {
|
|
112
|
+
pointerSet[EXIF_POINTER_TAGS.interoperabilityIfdPointer] = true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function isRequestedIncludeValue(includeValue) {
|
|
119
|
+
if (includeValue === true) {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return Array.isArray(includeValue) && includeValue.length > 0;
|
|
124
|
+
}
|
|
@@ -0,0 +1,409 @@
|
|
|
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
|
+
import {
|
|
6
|
+
FILTER_GROUPS,
|
|
7
|
+
ID_CAPABLE_GROUPS,
|
|
8
|
+
COMPOSITE_DEPENDENCY_TAGS,
|
|
9
|
+
getExifTagDependenciesForInclude,
|
|
10
|
+
} from './tag-filter-config.js';
|
|
11
|
+
|
|
12
|
+
export function createTagFilter({includeTags, excludeTags} = {}) {
|
|
13
|
+
const hasIncludeTags = Boolean(includeTags);
|
|
14
|
+
const hasExcludeTags = Boolean(excludeTags);
|
|
15
|
+
const isActive = hasIncludeTags || hasExcludeTags;
|
|
16
|
+
|
|
17
|
+
const shouldReturn = Object.create(null);
|
|
18
|
+
const returnSelections = Object.create(null);
|
|
19
|
+
const parseSelections = Object.create(null);
|
|
20
|
+
|
|
21
|
+
if (!isActive) {
|
|
22
|
+
return createNoopFilter();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const shouldParseExif = hasIncludeTags
|
|
26
|
+
&& (
|
|
27
|
+
isGroupRequested(includeTags, 'iptc')
|
|
28
|
+
|| isGroupRequested(includeTags, 'xmp')
|
|
29
|
+
|| isGroupRequested(includeTags, 'icc')
|
|
30
|
+
|| isGroupRequested(includeTags, 'photoshop')
|
|
31
|
+
|| isGroupRequested(includeTags, 'makerNotes')
|
|
32
|
+
|| isGroupRequested(includeTags, 'thumbnail')
|
|
33
|
+
|| isGroupRequested(includeTags, 'gps')
|
|
34
|
+
|| isGroupRequested(includeTags, 'composite')
|
|
35
|
+
);
|
|
36
|
+
const shouldParseFile = hasIncludeTags && isGroupRequested(includeTags, 'composite');
|
|
37
|
+
|
|
38
|
+
let exifIncludeDependencies = Object.create(null);
|
|
39
|
+
if (hasIncludeTags) {
|
|
40
|
+
exifIncludeDependencies = getExifIncludeDependencies(includeTags);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let fileIncludeDependencies = Object.create(null);
|
|
44
|
+
if (hasIncludeTags && shouldParseFile) {
|
|
45
|
+
fileIncludeDependencies = buildLowercasedNameMap(
|
|
46
|
+
COMPOSITE_DEPENDENCY_TAGS.file
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
for (const groupKey in FILTER_GROUPS) {
|
|
51
|
+
const hasIncludeEntry =
|
|
52
|
+
hasIncludeTags && Object.prototype.hasOwnProperty.call(includeTags, groupKey);
|
|
53
|
+
const hasExcludeEntry =
|
|
54
|
+
hasExcludeTags && Object.prototype.hasOwnProperty.call(excludeTags, groupKey);
|
|
55
|
+
|
|
56
|
+
let excludeValue = undefined;
|
|
57
|
+
if (hasExcludeEntry && !hasIncludeEntry) {
|
|
58
|
+
excludeValue = excludeTags[groupKey];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const returnSelection = buildSelection({
|
|
62
|
+
groupKey,
|
|
63
|
+
includeValue: hasIncludeEntry ? includeTags[groupKey] : undefined,
|
|
64
|
+
excludeValue,
|
|
65
|
+
extraIncludeNames: Object.create(null),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
shouldReturn[groupKey] = hasIncludeTags ? hasIncludeEntry : true;
|
|
69
|
+
if (hasIncludeEntry && isEmptyArray(includeTags[groupKey])) {
|
|
70
|
+
shouldReturn[groupKey] = false;
|
|
71
|
+
}
|
|
72
|
+
if (returnSelection.excludeAll) {
|
|
73
|
+
shouldReturn[groupKey] = false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
returnSelections[groupKey] = returnSelection;
|
|
77
|
+
|
|
78
|
+
const parseSelection = buildSelection({
|
|
79
|
+
groupKey,
|
|
80
|
+
includeValue: getParseIncludeValue({
|
|
81
|
+
groupKey,
|
|
82
|
+
hasIncludeTags,
|
|
83
|
+
hasIncludeEntry,
|
|
84
|
+
includeTags,
|
|
85
|
+
shouldParseExif,
|
|
86
|
+
shouldParseFile,
|
|
87
|
+
}),
|
|
88
|
+
excludeValue,
|
|
89
|
+
extraIncludeNames: getExtraParseIncludeNames({
|
|
90
|
+
groupKey,
|
|
91
|
+
hasIncludeTags,
|
|
92
|
+
hasIncludeEntry,
|
|
93
|
+
shouldParseExif,
|
|
94
|
+
shouldParseFile,
|
|
95
|
+
exifIncludeDependencies,
|
|
96
|
+
fileIncludeDependencies,
|
|
97
|
+
}),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
parseSelections[groupKey] = parseSelection;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
isActive,
|
|
105
|
+
shouldReturnGroup,
|
|
106
|
+
shouldParseGroup,
|
|
107
|
+
shouldReturnTag,
|
|
108
|
+
shouldParseTag,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
function shouldReturnGroup(groupKey) {
|
|
112
|
+
if (!FILTER_GROUPS[groupKey]) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return !!shouldReturn[groupKey];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function shouldParseGroup(groupKey) {
|
|
120
|
+
if (!FILTER_GROUPS[groupKey]) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (shouldReturnGroup(groupKey)) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (groupKey === 'exif') {
|
|
129
|
+
return shouldParseExif;
|
|
130
|
+
}
|
|
131
|
+
if (groupKey === 'file') {
|
|
132
|
+
return shouldParseFile;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function shouldReturnTag(groupKey, tagName, tagId) {
|
|
139
|
+
if (!FILTER_GROUPS[groupKey]) {
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (!shouldReturnGroup(groupKey)) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return matchesSelection(returnSelections[groupKey], tagName, tagId);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function shouldParseTag(groupKey, tagName, tagId) {
|
|
151
|
+
if (!FILTER_GROUPS[groupKey]) {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (!shouldParseGroup(groupKey)) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return matchesSelection(parseSelections[groupKey], tagName, tagId);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function createNoopFilter() {
|
|
164
|
+
return {
|
|
165
|
+
isActive: false,
|
|
166
|
+
shouldReturnGroup: alwaysTrue,
|
|
167
|
+
shouldParseGroup: alwaysTrue,
|
|
168
|
+
shouldReturnTag: alwaysTrue,
|
|
169
|
+
shouldParseTag: alwaysTrue,
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
function alwaysTrue() {
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export const NOOP_TAG_FILTER = createNoopFilter();
|
|
178
|
+
|
|
179
|
+
function getExifIncludeDependencies(includeTags) {
|
|
180
|
+
const requiredTags = getExifTagDependenciesForInclude(includeTags);
|
|
181
|
+
|
|
182
|
+
if (isGroupRequested(includeTags, 'composite')) {
|
|
183
|
+
addRequiredTags(requiredTags, COMPOSITE_DEPENDENCY_TAGS.exif);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return requiredTags;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function getParseIncludeValue({
|
|
190
|
+
groupKey,
|
|
191
|
+
hasIncludeTags,
|
|
192
|
+
hasIncludeEntry,
|
|
193
|
+
includeTags,
|
|
194
|
+
shouldParseExif,
|
|
195
|
+
shouldParseFile,
|
|
196
|
+
}) {
|
|
197
|
+
if (!hasIncludeTags) {
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (hasIncludeEntry) {
|
|
202
|
+
if (
|
|
203
|
+
groupKey === 'thumbnail'
|
|
204
|
+
&& Array.isArray(includeTags[groupKey])
|
|
205
|
+
) {
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return includeTags[groupKey];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (groupKey === 'exif' && shouldParseExif) {
|
|
213
|
+
return [];
|
|
214
|
+
}
|
|
215
|
+
if (groupKey === 'file' && shouldParseFile) {
|
|
216
|
+
return [];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function getExtraParseIncludeNames({
|
|
223
|
+
groupKey,
|
|
224
|
+
hasIncludeTags,
|
|
225
|
+
hasIncludeEntry,
|
|
226
|
+
shouldParseExif,
|
|
227
|
+
shouldParseFile,
|
|
228
|
+
exifIncludeDependencies,
|
|
229
|
+
fileIncludeDependencies,
|
|
230
|
+
}) {
|
|
231
|
+
if (!hasIncludeTags) {
|
|
232
|
+
return Object.create(null);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (groupKey === 'exif') {
|
|
236
|
+
if (shouldParseExif || (hasIncludeEntry && Object.keys(exifIncludeDependencies).length > 0)) {
|
|
237
|
+
return exifIncludeDependencies;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (groupKey === 'file' && shouldParseFile) {
|
|
242
|
+
return fileIncludeDependencies;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return Object.create(null);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function isGroupRequested(includeTags, groupKey) {
|
|
249
|
+
if (!includeTags || !Object.prototype.hasOwnProperty.call(includeTags, groupKey)) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const includeValue = includeTags[groupKey];
|
|
254
|
+
if (includeValue === true) {
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return Array.isArray(includeValue) && includeValue.length > 0;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function isEmptyArray(value) {
|
|
262
|
+
return Array.isArray(value) && value.length === 0;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function buildSelection({groupKey, includeValue, excludeValue, extraIncludeNames}) {
|
|
266
|
+
const isIdCapable = !!ID_CAPABLE_GROUPS[groupKey];
|
|
267
|
+
|
|
268
|
+
const selection = {
|
|
269
|
+
includeAll: false,
|
|
270
|
+
includeNames: undefined,
|
|
271
|
+
includeIds: undefined,
|
|
272
|
+
excludeAll: false,
|
|
273
|
+
excludeNames: undefined,
|
|
274
|
+
excludeIds: undefined,
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
if (includeValue === true) {
|
|
278
|
+
selection.includeAll = true;
|
|
279
|
+
} else if (Array.isArray(includeValue)) {
|
|
280
|
+
selection.includeNames = Object.create(null);
|
|
281
|
+
if (isIdCapable) {
|
|
282
|
+
selection.includeIds = Object.create(null);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
for (let i = 0; i < includeValue.length; i++) {
|
|
286
|
+
addSelector(selection, includeValue[i]);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
for (const extraName in extraIncludeNames) {
|
|
290
|
+
selection.includeNames[extraName.toLowerCase()] = true;
|
|
291
|
+
}
|
|
292
|
+
} else if (extraIncludeNames && Object.keys(extraIncludeNames).length > 0) {
|
|
293
|
+
selection.includeNames = Object.create(null);
|
|
294
|
+
for (const extraName in extraIncludeNames) {
|
|
295
|
+
selection.includeNames[extraName.toLowerCase()] = true;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (excludeValue === true) {
|
|
300
|
+
selection.excludeAll = true;
|
|
301
|
+
|
|
302
|
+
return selection;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (Array.isArray(excludeValue)) {
|
|
306
|
+
selection.excludeNames = Object.create(null);
|
|
307
|
+
if (isIdCapable) {
|
|
308
|
+
selection.excludeIds = Object.create(null);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
for (let i = 0; i < excludeValue.length; i++) {
|
|
312
|
+
addExcludeSelector(selection, excludeValue[i]);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return selection;
|
|
317
|
+
|
|
318
|
+
function addSelector(targetSelection, selector) {
|
|
319
|
+
if (typeof selector === 'number' && targetSelection.includeIds) {
|
|
320
|
+
targetSelection.includeIds[String(selector)] = true;
|
|
321
|
+
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (typeof selector === 'string') {
|
|
326
|
+
targetSelection.includeNames[selector.toLowerCase()] = true;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function addExcludeSelector(targetSelection, selector) {
|
|
331
|
+
if (typeof selector === 'number' && targetSelection.excludeIds) {
|
|
332
|
+
targetSelection.excludeIds[String(selector)] = true;
|
|
333
|
+
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (typeof selector === 'string') {
|
|
338
|
+
targetSelection.excludeNames[selector.toLowerCase()] = true;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function matchesSelection(selection, tagName, tagId) {
|
|
344
|
+
if (selection.excludeAll) {
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (selection.includeAll) {
|
|
349
|
+
return !isExcluded(selection, tagName, tagId);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (!selection.includeNames && !selection.includeIds) {
|
|
353
|
+
return !isExcluded(selection, tagName, tagId);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (isIncluded(selection, tagName, tagId)) {
|
|
357
|
+
return !isExcluded(selection, tagName, tagId);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function isIncluded(selection, tagName, tagId) {
|
|
364
|
+
if (tagId !== undefined && selection.includeIds) {
|
|
365
|
+
if (selection.includeIds[String(tagId)]) {
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (tagName && selection.includeNames) {
|
|
371
|
+
if (selection.includeNames[String(tagName).toLowerCase()]) {
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function isExcluded(selection, tagName, tagId) {
|
|
380
|
+
if (tagId !== undefined && selection.excludeIds) {
|
|
381
|
+
if (selection.excludeIds[String(tagId)]) {
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (tagName && selection.excludeNames) {
|
|
387
|
+
if (selection.excludeNames[String(tagName).toLowerCase()]) {
|
|
388
|
+
return true;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function buildLowercasedNameMap(names) {
|
|
396
|
+
const map = Object.create(null);
|
|
397
|
+
|
|
398
|
+
for (let i = 0; i < names.length; i++) {
|
|
399
|
+
map[names[i].toLowerCase()] = true;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
return map;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function addRequiredTags(requiredTags, tags) {
|
|
406
|
+
for (let i = 0; i < tags.length; i++) {
|
|
407
|
+
requiredTags[tags[i]] = true;
|
|
408
|
+
}
|
|
409
|
+
}
|
package/src/tags-helpers.js
CHANGED
|
@@ -6,6 +6,7 @@ import Constants from './constants.js';
|
|
|
6
6
|
import Types from './types.js';
|
|
7
7
|
import TagNames, {IFD_TYPE_0TH, IFD_TYPE_1ST, IFD_TYPE_PENTAX} from './tag-names.js';
|
|
8
8
|
import {IFD_ENTRY_LENGTH, TIFF_IFD_OFFSET_OFFSET} from './tiff-constants.js';
|
|
9
|
+
import {NOOP_TAG_FILTER} from './tag-filter.js';
|
|
9
10
|
|
|
10
11
|
const getTagValueAt = {
|
|
11
12
|
1: Types.getByteAt,
|
|
@@ -28,7 +29,17 @@ export function get0thIfdOffset(dataView, tiffHeaderOffset, byteOrder) {
|
|
|
28
29
|
);
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
export function readIfd(
|
|
32
|
+
export function readIfd(
|
|
33
|
+
dataView,
|
|
34
|
+
ifdType,
|
|
35
|
+
offsetOrigin,
|
|
36
|
+
offset,
|
|
37
|
+
byteOrder,
|
|
38
|
+
includeUnknown,
|
|
39
|
+
computed = false,
|
|
40
|
+
tagFilter = NOOP_TAG_FILTER,
|
|
41
|
+
groupKey = 'exif'
|
|
42
|
+
) {
|
|
32
43
|
const FIELD_COUNT_SIZE = Types.getTypeSize('SHORT');
|
|
33
44
|
const FIELD_SIZE = IFD_ENTRY_LENGTH;
|
|
34
45
|
|
|
@@ -41,7 +52,16 @@ export function readIfd(dataView, ifdType, offsetOrigin, offset, byteOrder, incl
|
|
|
41
52
|
break;
|
|
42
53
|
}
|
|
43
54
|
|
|
44
|
-
const tag = readTag(
|
|
55
|
+
const tag = readTag(
|
|
56
|
+
dataView,
|
|
57
|
+
ifdType,
|
|
58
|
+
offsetOrigin,
|
|
59
|
+
offset,
|
|
60
|
+
byteOrder,
|
|
61
|
+
includeUnknown,
|
|
62
|
+
tagFilter,
|
|
63
|
+
groupKey
|
|
64
|
+
);
|
|
45
65
|
if (tag !== undefined) {
|
|
46
66
|
tags[tag.name] = {
|
|
47
67
|
'id': tag.id,
|
|
@@ -62,15 +82,19 @@ export function readIfd(dataView, ifdType, offsetOrigin, offset, byteOrder, incl
|
|
|
62
82
|
if (Constants.USE_THUMBNAIL && (offset < dataView.byteLength - Types.getTypeSize('LONG'))) {
|
|
63
83
|
const nextIfdOffset = Types.getLongAt(dataView, offset, byteOrder);
|
|
64
84
|
if (nextIfdOffset !== 0 && ifdType === IFD_TYPE_0TH) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
85
|
+
if (tagFilter.shouldParseGroup('thumbnail')) {
|
|
86
|
+
tags['Thumbnail'] = readIfd(
|
|
87
|
+
dataView,
|
|
88
|
+
IFD_TYPE_1ST,
|
|
89
|
+
offsetOrigin,
|
|
90
|
+
offsetOrigin + nextIfdOffset,
|
|
91
|
+
byteOrder,
|
|
92
|
+
includeUnknown,
|
|
93
|
+
computed,
|
|
94
|
+
tagFilter,
|
|
95
|
+
'thumbnail'
|
|
96
|
+
);
|
|
97
|
+
}
|
|
74
98
|
}
|
|
75
99
|
}
|
|
76
100
|
|
|
@@ -84,7 +108,16 @@ function getNumberOfFields(dataView, offset, byteOrder) {
|
|
|
84
108
|
return 0;
|
|
85
109
|
}
|
|
86
110
|
|
|
87
|
-
function readTag(
|
|
111
|
+
function readTag(
|
|
112
|
+
dataView,
|
|
113
|
+
ifdType,
|
|
114
|
+
offsetOrigin,
|
|
115
|
+
offset,
|
|
116
|
+
byteOrder,
|
|
117
|
+
includeUnknown = false,
|
|
118
|
+
tagFilter = NOOP_TAG_FILTER,
|
|
119
|
+
groupKey = 'exif'
|
|
120
|
+
) {
|
|
88
121
|
const TAG_CODE_IPTC_NAA = 0x83bb;
|
|
89
122
|
const TAG_TYPE_OFFSET = Types.getTypeSize('SHORT');
|
|
90
123
|
const TAG_COUNT_OFFSET = TAG_TYPE_OFFSET + Types.getTypeSize('SHORT');
|
|
@@ -100,6 +133,11 @@ function readTag(dataView, ifdType, offsetOrigin, offset, byteOrder, includeUnkn
|
|
|
100
133
|
return undefined;
|
|
101
134
|
}
|
|
102
135
|
|
|
136
|
+
const tagName = getTagName(ifdType, tagCode);
|
|
137
|
+
if (!tagFilter.shouldParseTag(groupKey, tagName, tagCode)) {
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
|
|
103
141
|
if (tagValueFitsInOffsetSlot(tagType, tagCount)) {
|
|
104
142
|
tagValueOffset = offset + TAG_VALUE_OFFSET;
|
|
105
143
|
tagValue = getTagValue(dataView, tagValueOffset, tagType, tagCount, byteOrder);
|
|
@@ -118,22 +156,18 @@ function readTag(dataView, ifdType, offsetOrigin, offset, byteOrder, includeUnkn
|
|
|
118
156
|
tagValue = decodeAsciiValue(tagValue);
|
|
119
157
|
}
|
|
120
158
|
|
|
121
|
-
let tagName = `undefined-${tagCode}`;
|
|
122
159
|
let tagDescription = tagValue;
|
|
123
160
|
|
|
124
161
|
if (TagNames[ifdType][tagCode] !== undefined) {
|
|
125
162
|
if ((TagNames[ifdType][tagCode]['name'] !== undefined) && (TagNames[ifdType][tagCode]['description'] !== undefined)) {
|
|
126
|
-
tagName = TagNames[ifdType][tagCode]['name'];
|
|
127
163
|
try {
|
|
128
164
|
tagDescription = TagNames[ifdType][tagCode]['description'](tagValue);
|
|
129
165
|
} catch (error) {
|
|
130
166
|
tagDescription = getDescriptionFromTagValue(tagValue);
|
|
131
167
|
}
|
|
132
168
|
} else if ((tagType === Types.tagTypes['RATIONAL']) || (tagType === Types.tagTypes['SRATIONAL'])) {
|
|
133
|
-
tagName = TagNames[ifdType][tagCode];
|
|
134
169
|
tagDescription = '' + (tagValue[0] / tagValue[1]);
|
|
135
170
|
} else {
|
|
136
|
-
tagName = TagNames[ifdType][tagCode];
|
|
137
171
|
tagDescription = getDescriptionFromTagValue(tagValue);
|
|
138
172
|
}
|
|
139
173
|
}
|
|
@@ -148,6 +182,19 @@ function readTag(dataView, ifdType, offsetOrigin, offset, byteOrder, includeUnkn
|
|
|
148
182
|
};
|
|
149
183
|
}
|
|
150
184
|
|
|
185
|
+
function getTagName(ifdType, tagCode) {
|
|
186
|
+
if (TagNames[ifdType][tagCode] !== undefined) {
|
|
187
|
+
if (typeof TagNames[ifdType][tagCode] === 'string') {
|
|
188
|
+
return TagNames[ifdType][tagCode];
|
|
189
|
+
}
|
|
190
|
+
if (TagNames[ifdType][tagCode].name) {
|
|
191
|
+
return TagNames[ifdType][tagCode].name;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return `undefined-${tagCode}`;
|
|
196
|
+
}
|
|
197
|
+
|
|
151
198
|
function tagValueFitsInOffsetSlot(tagType, tagCount) {
|
|
152
199
|
return Types.typeSizes[tagType] * tagCount <= Types.getTypeSize('LONG');
|
|
153
200
|
}
|