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
|
@@ -0,0 +1,287 @@
|
|
|
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
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const {getTagBindingName} = require('../src/composable/tag-binding-name.js');
|
|
8
|
+
const TagNames0thIfd = require('../src/tag-names-0th-ifd.js');
|
|
9
|
+
const TagNamesExifIfd = require('../src/tag-names-exif-ifd.js');
|
|
10
|
+
const TagNamesGpsIfd = require('../src/tag-names-gps-ifd.js');
|
|
11
|
+
const TagNamesInteroperabilityIfd = require('../src/tag-names-interoperability-ifd.js');
|
|
12
|
+
const IptcTagNames = require('../src/iptc-tag-names.js');
|
|
13
|
+
|
|
14
|
+
const MPL_HEADER = [
|
|
15
|
+
'/* This Source Code Form is subject to the terms of the Mozilla Public',
|
|
16
|
+
' * License, v. 2.0. If a copy of the MPL was not distributed with this',
|
|
17
|
+
' * file, You can obtain one at https://mozilla.org/MPL/2.0/. */'
|
|
18
|
+
];
|
|
19
|
+
const GENERATED_LINE = '// Generated by bin/generate-tag-modules.js from the tag dictionaries; do not edit.';
|
|
20
|
+
const TYPES_IMPORT = 'import type {TagDescriptor} from \'../core.js\';';
|
|
21
|
+
const COMMON_FILE = 'tag-names-common.js';
|
|
22
|
+
// In the order the imports are written and a function is looked up.
|
|
23
|
+
const DESCRIPTION_FILES = [
|
|
24
|
+
'tag-names-0th-ifd-descriptions.js',
|
|
25
|
+
'tag-names-exif-ifd-descriptions.js',
|
|
26
|
+
'tag-names-gps-ifd-descriptions.js',
|
|
27
|
+
'iptc-tag-names-descriptions.js',
|
|
28
|
+
'tag-names-utils.js',
|
|
29
|
+
COMMON_FILE
|
|
30
|
+
];
|
|
31
|
+
const DESCRIPTION_MODULES = DESCRIPTION_FILES.map((file) => require('../src/' + file));
|
|
32
|
+
|
|
33
|
+
module.exports = {generateTagModules, writeTagModules};
|
|
34
|
+
|
|
35
|
+
if (require.main === module) {
|
|
36
|
+
writeTagModules(path.join(__dirname, '..'));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Writes the generated modules under the given repository root.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} root
|
|
43
|
+
*/
|
|
44
|
+
function writeTagModules(root) {
|
|
45
|
+
const modules = generateTagModules();
|
|
46
|
+
for (const relativePath of Object.keys(modules)) {
|
|
47
|
+
const filePath = path.join(root, relativePath);
|
|
48
|
+
fs.mkdirSync(path.dirname(filePath), {recursive: true});
|
|
49
|
+
fs.writeFileSync(filePath, modules[relativePath]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The text of every per-tag module and its type definitions, keyed by its
|
|
55
|
+
* path from the repository root.
|
|
56
|
+
*
|
|
57
|
+
* @returns {Object<string, string>}
|
|
58
|
+
* @throws {Error} When a dictionary entry cannot be described by an import,
|
|
59
|
+
* a name cannot be given a single descriptor, or an entry not skipped has
|
|
60
|
+
* a function for a name.
|
|
61
|
+
*/
|
|
62
|
+
function generateTagModules() {
|
|
63
|
+
const descriptionExports = getDescriptionExports();
|
|
64
|
+
const modules = {};
|
|
65
|
+
for (const output of getOutputs()) {
|
|
66
|
+
const descriptors = getDescriptors(output);
|
|
67
|
+
modules[output.path] = getModuleText(output, descriptors, descriptionExports);
|
|
68
|
+
modules[output.typesPath] = getTypesText(descriptors, output.group);
|
|
69
|
+
}
|
|
70
|
+
return modules;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function getDescriptionExports() {
|
|
74
|
+
const descriptionExports = new Map();
|
|
75
|
+
DESCRIPTION_FILES.forEach((file, index) => {
|
|
76
|
+
const namespace = DESCRIPTION_MODULES[index];
|
|
77
|
+
for (const importName of Object.keys(namespace)) {
|
|
78
|
+
const value = namespace[importName];
|
|
79
|
+
if (importName !== 'default' && typeof value === 'function' && !descriptionExports.has(value)) {
|
|
80
|
+
descriptionExports.set(value, {file, importName});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return descriptionExports;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// No per-tag MPF module: its dictionary has five tags, so a per-tag reader
|
|
88
|
+
// would save almost nothing, and Images is computed from MPEntry, so no
|
|
89
|
+
// descriptor could select it.
|
|
90
|
+
function getOutputs() {
|
|
91
|
+
return [
|
|
92
|
+
{
|
|
93
|
+
path: 'src/composable/tags/exif.js',
|
|
94
|
+
typesPath: 'src/composable/tags/exif.d.ts',
|
|
95
|
+
group: 'exif',
|
|
96
|
+
dictionaries: [
|
|
97
|
+
['0th', TagNames0thIfd.default],
|
|
98
|
+
['exif', TagNamesExifIfd.default],
|
|
99
|
+
['gps', TagNamesGpsIfd.default],
|
|
100
|
+
['interoperability', TagNamesInteroperabilityIfd.default]
|
|
101
|
+
],
|
|
102
|
+
reader: {binding: 'exifBlockReader', file: '../exif-block-reader.js'}
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
path: 'src/composable/tags/iptc.js',
|
|
106
|
+
typesPath: 'src/composable/tags/iptc.d.ts',
|
|
107
|
+
group: 'iptc',
|
|
108
|
+
dictionaries: [['iptc', IptcTagNames.default.iptc]],
|
|
109
|
+
// 2:200 is named from its value length, so a name filter cannot
|
|
110
|
+
// select it, and 2:201 takes its description from 2:200. Both come
|
|
111
|
+
// only with the whole iptc group.
|
|
112
|
+
skippedIds: [0x02c8, 0x02c9],
|
|
113
|
+
reader: {binding: 'iptcBlockReader', file: '../iptc-block-reader.js'}
|
|
114
|
+
}
|
|
115
|
+
];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// In dictionary order, then by first id. A name seen again joins the
|
|
119
|
+
// descriptor it first appeared in.
|
|
120
|
+
function getDescriptors(output) {
|
|
121
|
+
const descriptors = [];
|
|
122
|
+
const descriptorsByName = new Map();
|
|
123
|
+
for (const [dictionary, entries] of output.dictionaries) {
|
|
124
|
+
for (const key of Object.keys(entries)) {
|
|
125
|
+
const id = Number(key);
|
|
126
|
+
if ((output.skippedIds || []).includes(id)) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const entry = entries[key];
|
|
130
|
+
const name = getEntryName(entry, id, dictionary);
|
|
131
|
+
const description = typeof entry === 'string' ? undefined : entry.description;
|
|
132
|
+
const descriptor = descriptorsByName.get(name);
|
|
133
|
+
if (descriptor) {
|
|
134
|
+
addId(descriptor, id, dictionary, description);
|
|
135
|
+
} else {
|
|
136
|
+
const newDescriptor = {
|
|
137
|
+
name,
|
|
138
|
+
binding: getTagBindingName(name),
|
|
139
|
+
ids: [id],
|
|
140
|
+
dictionary,
|
|
141
|
+
description,
|
|
142
|
+
describedIds: description ? [id] : [],
|
|
143
|
+
repeatable: entry.repeatable === true
|
|
144
|
+
};
|
|
145
|
+
descriptors.push(newDescriptor);
|
|
146
|
+
descriptorsByName.set(name, newDescriptor);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return descriptors;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// A function-valued name depends on the value, so no descriptor can select it.
|
|
154
|
+
function getEntryName(entry, id, dictionary) {
|
|
155
|
+
if (typeof entry === 'string') {
|
|
156
|
+
return entry;
|
|
157
|
+
}
|
|
158
|
+
if (typeof entry.name === 'function') {
|
|
159
|
+
throw new Error(`The tag ${getHex(id)} in the ${dictionary} dictionary has a function for a name: skip it in getOutputs`);
|
|
160
|
+
}
|
|
161
|
+
return entry.name;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function addId(descriptor, id, dictionary, description) {
|
|
165
|
+
if (dictionary !== descriptor.dictionary) {
|
|
166
|
+
throw new Error(`${describeTag(descriptor.name, id, dictionary)} is in two dictionaries: ${descriptor.dictionary} and ${dictionary}`);
|
|
167
|
+
}
|
|
168
|
+
if (description && descriptor.description && description !== descriptor.description) {
|
|
169
|
+
throw new Error(`${describeTag(descriptor.name, id, dictionary)} has two different descriptions`);
|
|
170
|
+
}
|
|
171
|
+
descriptor.ids.push(id);
|
|
172
|
+
if (description) {
|
|
173
|
+
descriptor.describedIds.push(id);
|
|
174
|
+
}
|
|
175
|
+
descriptor.description = descriptor.description || description;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function describeTag(name, id, dictionary) {
|
|
179
|
+
return `Tag '${name}' (${getHex(id)} in the ${dictionary} dictionary)`;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function getHex(id) {
|
|
183
|
+
return '0x' + id.toString(16).padStart(4, '0');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function getModuleText(output, descriptors, descriptionExports) {
|
|
187
|
+
const imports = getImports(descriptors, descriptionExports);
|
|
188
|
+
assertNamesAreDeclaredOnce(output, descriptors, imports);
|
|
189
|
+
|
|
190
|
+
const lines = MPL_HEADER.concat(['', GENERATED_LINE, '']);
|
|
191
|
+
const importLines = imports.map(getImportText);
|
|
192
|
+
importLines.push(`import {${output.reader.binding}} from '${output.reader.file}';`);
|
|
193
|
+
lines.push(...importLines, '');
|
|
194
|
+
for (const descriptor of descriptors) {
|
|
195
|
+
lines.push(getDescriptorText(descriptor, output, descriptionExports));
|
|
196
|
+
}
|
|
197
|
+
return lines.join('\n') + '\n';
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// One import per description module, in DESCRIPTION_FILES order.
|
|
201
|
+
function getImports(descriptors, descriptionExports) {
|
|
202
|
+
const importsByFile = new Map();
|
|
203
|
+
for (const descriptor of descriptors) {
|
|
204
|
+
if (descriptor.description) {
|
|
205
|
+
const source = descriptionExports.get(descriptor.description);
|
|
206
|
+
if (!source) {
|
|
207
|
+
throw new Error(`${describeTag(descriptor.name, descriptor.ids[0], descriptor.dictionary)} has a description that has no export in the description modules`);
|
|
208
|
+
}
|
|
209
|
+
const fileImport = getFileImport(importsByFile, source.file);
|
|
210
|
+
if (!fileImport.named.includes(source.importName)) {
|
|
211
|
+
fileImport.named.push(source.importName);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return DESCRIPTION_FILES.filter((file) => importsByFile.has(file)).map((file) => {
|
|
216
|
+
const fileImport = importsByFile.get(file);
|
|
217
|
+
fileImport.named.sort();
|
|
218
|
+
return fileImport;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function getFileImport(importsByFile, file) {
|
|
223
|
+
if (!importsByFile.has(file)) {
|
|
224
|
+
importsByFile.set(file, {file, named: []});
|
|
225
|
+
}
|
|
226
|
+
return importsByFile.get(file);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function assertNamesAreDeclaredOnce(output, descriptors, imports) {
|
|
230
|
+
const declarations = new Map();
|
|
231
|
+
const declare = (name, origin) => {
|
|
232
|
+
if (declarations.has(name)) {
|
|
233
|
+
throw new Error(`${name} is declared twice in ${output.path}: by ${declarations.get(name)} and by ${origin}`);
|
|
234
|
+
}
|
|
235
|
+
declarations.set(name, origin);
|
|
236
|
+
};
|
|
237
|
+
for (const fileImport of imports) {
|
|
238
|
+
for (const importName of fileImport.named) {
|
|
239
|
+
declare(importName, `the import of ${importName} from ${fileImport.file}`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
for (const descriptor of descriptors) {
|
|
243
|
+
declare(descriptor.binding, describeTag(descriptor.name, descriptor.ids[0], descriptor.dictionary));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function getImportText(fileImport) {
|
|
248
|
+
const names = fileImport.named;
|
|
249
|
+
if (names.length > 1) {
|
|
250
|
+
return `import {\n${names.map((name) => ' ' + name).join(',\n')}\n} from '../../${fileImport.file}';`;
|
|
251
|
+
}
|
|
252
|
+
return `import {${names[0]}} from '../../${fileImport.file}';`;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// describedIds only when some id's dictionary entry has no description, so a
|
|
256
|
+
// reader built from the descriptors describes each id as its dictionary does.
|
|
257
|
+
function getDescriptorText(descriptor, output, descriptionExports) {
|
|
258
|
+
const fields = [
|
|
259
|
+
`name: ${getStringLiteral(descriptor.name)}`,
|
|
260
|
+
`ids: [${descriptor.ids.map(getHex).join(', ')}]`,
|
|
261
|
+
`group: '${output.group}'`,
|
|
262
|
+
`dictionary: '${descriptor.dictionary}'`
|
|
263
|
+
];
|
|
264
|
+
if (descriptor.description) {
|
|
265
|
+
fields.push(`description: ${descriptionExports.get(descriptor.description).importName}`);
|
|
266
|
+
if (descriptor.describedIds.length < descriptor.ids.length) {
|
|
267
|
+
fields.push(`describedIds: [${descriptor.describedIds.map(getHex).join(', ')}]`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (descriptor.repeatable) {
|
|
271
|
+
fields.push('repeatable: true');
|
|
272
|
+
}
|
|
273
|
+
fields.push(`reader: ${output.reader.binding}`);
|
|
274
|
+
return `export const ${descriptor.binding} = {${fields.join(', ')}};`;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function getStringLiteral(text) {
|
|
278
|
+
return '\'' + text.replace(/\\/g, '\\\\').replace(/'/g, '\\\'') + '\'';
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function getTypesText(descriptors, group) {
|
|
282
|
+
const lines = MPL_HEADER.concat(['', GENERATED_LINE, '', TYPES_IMPORT, '']);
|
|
283
|
+
for (const descriptor of descriptors) {
|
|
284
|
+
lines.push(`export declare const ${descriptor.binding}: TagDescriptor<'${group}', ${getStringLiteral(descriptor.name)}>;`);
|
|
285
|
+
}
|
|
286
|
+
return lines.join('\n') + '\n';
|
|
287
|
+
}
|