exifreader 4.54.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 +398 -27
- 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/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/engine.js +50 -106
- package/src/errors.js +8 -2
- package/src/exif-reader.d.ts +8 -0
- package/src/exif-reader.js +112 -763
- package/src/file-loaders.js +74 -1
- package/src/file-tags.js +9 -9
- package/src/image-header.js +13 -47
- 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 +52 -192
- package/src/node-require.js +15 -2
- package/src/png-text-tags.js +5 -3
- package/src/tag-filter-config.js +24 -15
- package/src/tag-filter.js +15 -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 +28 -3
- package/src/tags-helpers.js +6 -2
- package/src/types.js +2 -0
- package/src/unsupported-format-error.js +21 -0
- package/src/utils.js +22 -85
- package/src/xmp-tag-names.js +42 -21
- package/webpack.config.js +1 -1
package/src/exif-reader.js
CHANGED
|
@@ -7,49 +7,36 @@
|
|
|
7
7
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {objectAssign,
|
|
10
|
+
import {objectAssign, getDataViewFromBytes, assertPromiseSupport} from './utils.js';
|
|
11
11
|
import {isFilePathOrURL, isBrowserFileObject, loadFile, loadFileObject} from './file-loaders.js';
|
|
12
12
|
import {makeLoadAuto, validateAutoOptions} from './load-auto.js';
|
|
13
13
|
import Constants from './constants.js';
|
|
14
|
-
import {getCalculatedGpsValue} from './tag-names-utils.js';
|
|
15
|
-
import ByteOrder from './byte-order.js';
|
|
16
|
-
import {getTiffHeaderOffset} from './image-header-iso-bmff.js';
|
|
17
|
-
import ImageHeader from './image-header.js';
|
|
18
|
-
import {TYPE_ZTXT} from './image-header-png.js';
|
|
19
|
-
import Tags from './tags.js';
|
|
20
|
-
import TagNames0thIfd from './tag-names-0th-ifd.js';
|
|
21
|
-
import TagNamesExifIfd from './tag-names-exif-ifd.js';
|
|
22
|
-
import TagNamesGpsIfd from './tag-names-gps-ifd.js';
|
|
23
|
-
import TagNamesInteroperabilityIfd from './tag-names-interoperability-ifd.js';
|
|
24
|
-
import {IFD_TYPE_0TH, IFD_TYPE_1ST, IFD_TYPE_EXIF, IFD_TYPE_GPS, IFD_TYPE_INTEROPERABILITY} from './ifd-types.js';
|
|
25
|
-
import {addDecompressedValueAllowance, addDecompressedIptcAllowance} from './tags-helpers.js';
|
|
26
|
-
import MpfTags from './mpf-tags.js';
|
|
27
|
-
import FileTags from './file-tags.js';
|
|
28
|
-
import JxlFileTags from './jxl-file-tags.js';
|
|
29
|
-
import IsoBmffFileTags from './iso-bmff-file-tags.js';
|
|
30
|
-
import JfifTags from './jfif-tags.js';
|
|
31
|
-
import IptcTags from './iptc-tags.js';
|
|
32
|
-
import XmpTags from './xmp-tags.js';
|
|
33
|
-
import PhotoshopTags from './photoshop-tags.js';
|
|
34
|
-
import IccTags from './icc-tags.js';
|
|
35
|
-
import CanonTags from './canon-tags.js';
|
|
36
|
-
import PentaxTags from './pentax-tags.js';
|
|
37
|
-
import PngFileTags from './png-file-tags.js';
|
|
38
|
-
import PngTextTags, {hasRawIptcProfile} from './png-text-tags.js';
|
|
39
|
-
import PngTags from './png-tags.js';
|
|
40
|
-
import Vp8xTags from './vp8x-tags.js';
|
|
41
|
-
import GifFileTags from './gif-file-tags.js';
|
|
42
|
-
import Thumbnail from './thumbnail.js';
|
|
43
|
-
import Composite from './composite.js';
|
|
44
|
-
import {createTagFilter, filterTagsForParse, filterTagsForReturn} from './tag-filter.js';
|
|
45
14
|
import {getBase64Image} from './base64-image.js';
|
|
46
15
|
import DOMParser from './dom-parser.js';
|
|
47
|
-
import {buildTagsFromMergeBlocks} from './loadview-pipeline.js';
|
|
48
|
-
import {run, createContext, validateComposition} from './engine.js';
|
|
49
16
|
import exifErrors from './errors.js';
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
17
|
+
import Composition, {createIsHiddenInSyncMode} from './composable/composition.js';
|
|
18
|
+
import {readView} from './composable/read-view.js';
|
|
19
|
+
import {createTagFilter} from './tag-filter.js';
|
|
20
|
+
import {tiff} from './composable/formats/tiff.js';
|
|
21
|
+
import {jpegHeader, file, jfif} from './composable/formats/jpeg.js';
|
|
22
|
+
import {pngHeader, pngFile, pngText, pngChunk} from './composable/formats/png.js';
|
|
23
|
+
import {heic} from './composable/formats/heic.js';
|
|
24
|
+
import {avif} from './composable/formats/avif.js';
|
|
25
|
+
import {jxl} from './composable/formats/jxl.js';
|
|
26
|
+
import {webp} from './composable/formats/webp.js';
|
|
27
|
+
import {gif} from './composable/formats/gif.js';
|
|
28
|
+
import {xml} from './composable/formats/xml.js';
|
|
29
|
+
import {exif} from './composable/groups/exif.js';
|
|
30
|
+
import {iptc} from './composable/groups/iptc.js';
|
|
31
|
+
import {xmp} from './composable/groups/xmp.js';
|
|
32
|
+
import {icc} from './composable/groups/icc.js';
|
|
33
|
+
import {photoshop} from './composable/groups/photoshop.js';
|
|
34
|
+
import {mpf} from './composable/groups/mpf.js';
|
|
35
|
+
import {makerNotes} from './composable/groups/maker-notes.js';
|
|
36
|
+
import {gps} from './composable/groups/gps.js';
|
|
37
|
+
import {composite} from './composable/groups/composite.js';
|
|
38
|
+
import {thumbnail, getSelectedThumbnail} from './composable/groups/thumbnail.js';
|
|
39
|
+
import {removeThumbnailTag} from './loadview-pipeline.js';
|
|
53
40
|
|
|
54
41
|
export default {
|
|
55
42
|
load,
|
|
@@ -57,7 +44,10 @@ export default {
|
|
|
57
44
|
errors: exifErrors,
|
|
58
45
|
};
|
|
59
46
|
|
|
60
|
-
|
|
47
|
+
// Composing costs more than a small load, so the composition is kept until the
|
|
48
|
+
// tables change; they only do when the unit tests swap the Constants.
|
|
49
|
+
let defaultComposition;
|
|
50
|
+
let defaultCompositionEntries;
|
|
61
51
|
|
|
62
52
|
export const errors = exifErrors;
|
|
63
53
|
|
|
@@ -81,752 +71,111 @@ function loadFromData(data, options) {
|
|
|
81
71
|
}
|
|
82
72
|
|
|
83
73
|
export function loadView(dataView, options = {}) {
|
|
84
|
-
|
|
85
|
-
expanded = false,
|
|
86
|
-
async = false,
|
|
87
|
-
computed = false,
|
|
88
|
-
includeUnknown = false,
|
|
89
|
-
includeOffsets = false,
|
|
90
|
-
domParser = undefined,
|
|
91
|
-
includeTags = undefined,
|
|
92
|
-
excludeTags = undefined,
|
|
93
|
-
decompress: decompressConfig = undefined
|
|
94
|
-
} = options;
|
|
95
|
-
dataView = getSelfContainedDataView(dataView);
|
|
96
|
-
|
|
97
|
-
const {fileType, blocks: allBlocks, ranges, truncated} = ImageHeader.parseAppMarkers(dataView, expanded && includeOffsets);
|
|
98
|
-
if (async) {
|
|
99
|
-
assertPromiseSupport();
|
|
100
|
-
}
|
|
101
|
-
const blocks = async ? allBlocks : allBlocks.filter((block) => !isHiddenInSyncMode(block));
|
|
102
|
-
|
|
103
|
-
const tagFilter = createTagFilter({includeTags, excludeTags});
|
|
104
|
-
const context = createContext({
|
|
105
|
-
dataView,
|
|
106
|
-
options: {expanded, async, computed, includeUnknown, includeOffsets, domParser, includeTags, excludeTags},
|
|
107
|
-
tagFilter,
|
|
108
|
-
decompressConfig: withDecompressBudget(decompressConfig),
|
|
109
|
-
getBase64Image,
|
|
110
|
-
getDomParser: DOMParser.get,
|
|
111
|
-
});
|
|
112
|
-
// The pipeline copies png into pngText only when png is returned, so the
|
|
113
|
-
// filter needs no check here.
|
|
114
|
-
const pngTextBlocks = blocks.filter(isPngTextChunkBlock);
|
|
115
|
-
const pngTextIsAsync = async && Constants.USE_PNG && pngTextBlocks.some(isNamedCompressedPngTextChunk);
|
|
116
|
-
|
|
117
|
-
const result = run(getDefaultComposition(), blocks, context);
|
|
118
|
-
|
|
119
|
-
return async ? result.then(finish) : finish(result);
|
|
120
|
-
|
|
121
|
-
function finish({mergeBlocks}) {
|
|
122
|
-
return buildTagsFromMergeBlocks({
|
|
123
|
-
mergeBlocks: combineUncompressedPngTextBlocks(mergeBlocks).concat(getDerivedBlocks({expanded, includeOffsets, async, ranges, truncated})),
|
|
124
|
-
parsedGroups: Object.create(null),
|
|
125
|
-
expanded,
|
|
126
|
-
tagFilter,
|
|
127
|
-
dataView,
|
|
128
|
-
fileType,
|
|
129
|
-
pngTextBlocks,
|
|
130
|
-
pngTextIsAsync,
|
|
131
|
-
deps: {
|
|
132
|
-
objectAssign,
|
|
133
|
-
hasPngTextData,
|
|
134
|
-
filterTagsForReturn,
|
|
135
|
-
// A plain property here would keep the function alive for the bundler,
|
|
136
|
-
// so a build without Exif would still carry getGpsGroupFromExifTags.
|
|
137
|
-
getGpsGroupFromExifTags: Constants.USE_EXIF ? getGpsGroupFromExifTags : undefined,
|
|
138
|
-
// A plain property here would keep the import alive for the bundler, so
|
|
139
|
-
// a build with neither Exif nor XMP would still carry composite.js.
|
|
140
|
-
Composite: (Constants.USE_EXIF || Constants.USE_XMP) ? Composite : undefined,
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
}
|
|
74
|
+
return readView(getDefaultComposition(), dataView, options, getEnvironment());
|
|
144
75
|
}
|
|
145
76
|
|
|
146
|
-
function isNamedCompressedPngTextChunk(block) {
|
|
147
|
-
return block.compression !== undefined && block.text.name !== undefined;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// The groups in dispatch order, each inside its build gate so that a custom
|
|
151
|
-
// build folds the reader import away. Built per load, since the unit tests
|
|
152
|
-
// swap the Constants at runtime.
|
|
153
77
|
function getDefaultComposition() {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
merge: () => ({slot: 'file', mode: 'assign'}),
|
|
162
|
-
} : undefined,
|
|
163
|
-
Constants.USE_JPEG && Constants.USE_JFIF ? {
|
|
164
|
-
key: 'jfif',
|
|
165
|
-
consumes: ['jfif'],
|
|
166
|
-
emits: [],
|
|
167
|
-
read: (block, ctx) => parsedTags('jfif', JfifTags.read(ctx.dataView, block.dataOffset), ctx),
|
|
168
|
-
merge: () => ({slot: 'jfif', mode: 'assign'}),
|
|
169
|
-
} : undefined,
|
|
170
|
-
Constants.USE_EXIF ? {
|
|
171
|
-
key: 'exif',
|
|
172
|
-
consumes: ['exif'],
|
|
173
|
-
emits: ['iptc', 'xmp', 'photoshop', 'icc', 'makerNote', 'thumbnail'],
|
|
174
|
-
read: readExifBlock,
|
|
175
|
-
merge: getExifMergeDescriptor,
|
|
176
|
-
} : undefined,
|
|
177
|
-
Constants.USE_IPTC ? {
|
|
178
|
-
key: 'iptc',
|
|
179
|
-
consumes: ['iptc'],
|
|
180
|
-
emits: [],
|
|
181
|
-
read: readIptcBlock,
|
|
182
|
-
merge: (block) => getEmbeddableMergeDescriptor(block, 'iptc', 'carriedIptc'),
|
|
183
|
-
} : undefined,
|
|
184
|
-
Constants.USE_XMP ? {
|
|
185
|
-
key: 'xmp',
|
|
186
|
-
consumes: ['xmp'],
|
|
187
|
-
emits: [],
|
|
188
|
-
read: readXmpBlock,
|
|
189
|
-
merge: getXmpMergeDescriptor,
|
|
190
|
-
} : undefined,
|
|
191
|
-
Constants.USE_ICC ? {
|
|
192
|
-
key: 'icc',
|
|
193
|
-
consumes: ['icc'],
|
|
194
|
-
emits: [],
|
|
195
|
-
read: readIccBlock,
|
|
196
|
-
merge: (block) => getEmbeddableMergeDescriptor(block, 'icc', 'carriedIcc'),
|
|
197
|
-
} : undefined,
|
|
198
|
-
Constants.USE_MPF ? {
|
|
199
|
-
key: 'mpf',
|
|
200
|
-
consumes: ['mpf'],
|
|
201
|
-
emits: [],
|
|
202
|
-
read: (block, ctx) => parsedTags('mpf', MpfTags.read(
|
|
203
|
-
ctx.dataView,
|
|
204
|
-
block.dataOffset,
|
|
205
|
-
ctx.options.includeUnknown,
|
|
206
|
-
ctx.options.computed,
|
|
207
|
-
ctx.tagFilter,
|
|
208
|
-
ctx.getValueBudget(),
|
|
209
|
-
ctx.getBase64Image
|
|
210
|
-
), ctx),
|
|
211
|
-
merge: () => ({slot: 'mpf', mode: 'assign'}),
|
|
212
|
-
} : undefined,
|
|
213
|
-
Constants.USE_PNG && Constants.USE_PNG_FILE ? {
|
|
214
|
-
key: 'png',
|
|
215
|
-
consumes: ['pngFile'],
|
|
216
|
-
emits: [],
|
|
217
|
-
read: (block, ctx) => parsedTags('png', PngFileTags.read(ctx.dataView, block.dataOffset), ctx),
|
|
218
|
-
merge: () => ({slot: 'pngFile', mode: 'pngFile'}),
|
|
219
|
-
} : undefined,
|
|
220
|
-
Constants.USE_PNG ? {
|
|
221
|
-
key: 'png',
|
|
222
|
-
consumes: ['pngText'],
|
|
223
|
-
emits: ['exif', 'iptc'],
|
|
224
|
-
read: (block, ctx) => PngTextTags.read(block, ctx),
|
|
225
|
-
merge: (block) => ({slot: block.compression !== undefined ? 'deferredPngText' : 'pngText', mode: 'pngTextTags'}),
|
|
226
|
-
} : undefined,
|
|
227
|
-
Constants.USE_PNG ? {
|
|
228
|
-
key: 'png',
|
|
229
|
-
consumes: ['pngChunk'],
|
|
230
|
-
emits: [],
|
|
231
|
-
read: (block, ctx) => parsedTags('png', PngTags.read(ctx.dataView, [block.dataOffset]), ctx),
|
|
232
|
-
merge: () => ({slot: 'pngChunk', mode: 'merge'}),
|
|
233
|
-
} : undefined,
|
|
234
|
-
Constants.USE_WEBP ? {
|
|
235
|
-
key: 'riff',
|
|
236
|
-
consumes: ['riff'],
|
|
237
|
-
emits: [],
|
|
238
|
-
read: (block, ctx) => parsedTags('riff', Vp8xTags.read(ctx.dataView, block.dataOffset), ctx),
|
|
239
|
-
merge: () => ({slot: 'riff', mode: 'merge'}),
|
|
240
|
-
} : undefined,
|
|
241
|
-
Constants.USE_GIF ? {
|
|
242
|
-
key: 'gif',
|
|
243
|
-
consumes: ['gif'],
|
|
244
|
-
emits: [],
|
|
245
|
-
read: (block, ctx) => parsedTags('gif', GifFileTags.read(ctx.dataView, block.dataOffset), ctx),
|
|
246
|
-
merge: () => ({slot: 'gif', mode: 'merge'}),
|
|
247
|
-
} : undefined,
|
|
248
|
-
Constants.USE_JXL ? {
|
|
249
|
-
key: 'file',
|
|
250
|
-
consumes: ['jxlFile'],
|
|
251
|
-
emits: [],
|
|
252
|
-
read: (block, ctx) => parsedTags('file', JxlFileTags.read(ctx.dataView, block.codestreamOffset), ctx),
|
|
253
|
-
merge: () => ({slot: 'jxlFile', mode: 'assign'}),
|
|
254
|
-
} : undefined,
|
|
255
|
-
Constants.USE_HEIC || Constants.USE_AVIF ? {
|
|
256
|
-
key: 'file',
|
|
257
|
-
consumes: ['isoBmffFile'],
|
|
258
|
-
emits: [],
|
|
259
|
-
read: (block, ctx) => parsedTags('file', IsoBmffFileTags.read(ctx.dataView, block.imageDimensionsOffset, block.pixelInformationOffset), ctx),
|
|
260
|
-
merge: () => ({slot: 'isoBmffFile', mode: 'assign'}),
|
|
261
|
-
} : undefined,
|
|
262
|
-
Constants.USE_PHOTOSHOP ? {
|
|
263
|
-
key: 'photoshop',
|
|
264
|
-
consumes: ['photoshop'],
|
|
265
|
-
emits: [],
|
|
266
|
-
read: (block, ctx) => parsedTags('photoshop', PhotoshopTags.read(block.value, ctx.options.includeUnknown, ctx.tagFilter), ctx),
|
|
267
|
-
merge: (block) => getEmbeddableMergeDescriptor(block, 'photoshop', 'carriedPhotoshop'),
|
|
268
|
-
} : undefined,
|
|
269
|
-
Constants.USE_MAKER_NOTES ? {
|
|
270
|
-
key: 'makerNotes',
|
|
271
|
-
consumes: ['makerNote'],
|
|
272
|
-
emits: [],
|
|
273
|
-
read: readMakerNoteBlock,
|
|
274
|
-
merge: (block) => getEmbeddableMergeDescriptor(block, 'makerNotes', 'carriedMakerNotes'),
|
|
275
|
-
} : undefined,
|
|
276
|
-
Constants.USE_EXIF && Constants.USE_THUMBNAIL ? {
|
|
277
|
-
key: 'thumbnail',
|
|
278
|
-
consumes: ['thumbnail'],
|
|
279
|
-
emits: [],
|
|
280
|
-
read: readThumbnailBlock,
|
|
281
|
-
merge: (block) => ({slot: 'thumbnail', mode: 'thumbnailCandidate', rank: block.rank}),
|
|
282
|
-
} : undefined,
|
|
283
|
-
].filter(Boolean),
|
|
284
|
-
dispatchKind,
|
|
285
|
-
rank,
|
|
286
|
-
suppressions: [
|
|
287
|
-
{kind: 'iptc', isSuppressed: isCarriedIptcSuppressed},
|
|
288
|
-
{kind: 'xmp', isSuppressed: isCarriedXmpSuppressed},
|
|
289
|
-
{kind: 'icc', isSuppressed: isCarriedIccSuppressed},
|
|
290
|
-
],
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
function parsedTags(groupKey, readTags, ctx) {
|
|
295
|
-
return {tags: filterTagsForParse(groupKey, readTags, ctx.tagFilter)};
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
function readFileBlock(block, ctx) {
|
|
299
|
-
if (!shouldReadFileTagsForFileTypeOnlyOptimization(ctx.options.includeTags)) {
|
|
300
|
-
return undefined;
|
|
301
|
-
}
|
|
302
|
-
return parsedTags('file', FileTags.read(ctx.dataView, block.dataOffset), ctx);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
function shouldReadFileTagsForFileTypeOnlyOptimization(includeTagsOptions) {
|
|
306
|
-
if (!includeTagsOptions) {
|
|
307
|
-
return true;
|
|
308
|
-
}
|
|
309
|
-
const {composite, file} = includeTagsOptions;
|
|
310
|
-
if (composite === true || (Array.isArray(composite) && composite.length > 0)) {
|
|
311
|
-
return true;
|
|
312
|
-
}
|
|
313
|
-
return !(Array.isArray(file) && file.length === 1 && file[0] === 'FileType');
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// A raw-profile text chunk keeps its exif or iptc kind, which the suppression
|
|
317
|
-
// rules key on, but dispatches with the other text chunks.
|
|
318
|
-
function dispatchKind(block) {
|
|
319
|
-
return isPngTextChunkBlock(block) ? 'pngText' : block.kind;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// A brob Exif box ranks below an Exif box; a compressed raw-profile text chunk
|
|
323
|
-
// is not a brob, so it ranks with the eXIf chunk and the uncompressed profiles.
|
|
324
|
-
function rank(block) {
|
|
325
|
-
return block.kind === 'exif' && block.compression !== undefined && !isPngTextChunkBlock(block) ? 0 : 1;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
// The main block's IPTC-NAA gives way to an IPTC segment, a raw profile's to a
|
|
329
|
-
// raw IPTC chunk the text reader will read, compressed or not; a brob's never
|
|
330
|
-
// gives way. The USE_PNG gate keeps the text reader out of a build without PNG.
|
|
331
|
-
// The raw IPTC scan decodes text chunks, so its verdict is kept on the context:
|
|
332
|
-
// the finder blocks do not change within a load, and a PNG can hold thousands
|
|
333
|
-
// of raw profiles.
|
|
334
|
-
function isCarriedIptcSuppressed(block, finderBlocks, ctx) {
|
|
335
|
-
if (block.carried === 'main') {
|
|
336
|
-
return finderBlocks.some((finderBlock) => finderBlock.kind === 'iptc' && !isPngTextChunkBlock(finderBlock));
|
|
337
|
-
}
|
|
338
|
-
if (Constants.USE_PNG && block.carried === 'rawProfile') {
|
|
339
|
-
if (ctx.hasRawIptcProfile === undefined) {
|
|
340
|
-
ctx.hasRawIptcProfile = hasRawIptcProfile(finderBlocks, ctx.dataView);
|
|
341
|
-
}
|
|
342
|
-
return ctx.hasRawIptcProfile;
|
|
343
|
-
}
|
|
344
|
-
return false;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// A brob XMP box has no chunks, so it does not suppress.
|
|
348
|
-
function isCarriedXmpSuppressed(block, finderBlocks) {
|
|
349
|
-
return block.carried !== undefined && finderBlocks.some((finderBlock) => finderBlock.kind === 'xmp' && hasXmpData(finderBlock));
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
function isCarriedIccSuppressed(block, finderBlocks) {
|
|
353
|
-
return block.carried !== undefined && finderBlocks.some((finderBlock) => finderBlock.kind === 'icc' && hasIccData(finderBlock));
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
function getEmbeddableMergeDescriptor(block, slot, carriedSlot) {
|
|
357
|
-
if (block.carried !== undefined) {
|
|
358
|
-
return {slot: carriedSlot, mode: block.carried === 'main' ? 'assign' : 'merge'};
|
|
359
|
-
}
|
|
360
|
-
return {slot, mode: block.origin !== undefined ? 'merge' : 'assign'};
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
function getXmpMergeDescriptor(block) {
|
|
364
|
-
if (block.compression !== undefined) {
|
|
365
|
-
return {slot: 'brobXmp', mode: 'brobXmp'};
|
|
366
|
-
}
|
|
367
|
-
return getEmbeddableMergeDescriptor(block, 'xmp', 'carriedXmp');
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
function getExifMergeDescriptor(block) {
|
|
371
|
-
if (block.compression !== undefined) {
|
|
372
|
-
return {slot: 'exif', mode: 'merge', outerSlot: 'brobExif'};
|
|
373
|
-
}
|
|
374
|
-
return {slot: 'exif', mode: block.origin !== undefined ? 'merge' : 'assign'};
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
function getBlockDataView(block, ctx) {
|
|
378
|
-
if (block.getDataView) {
|
|
379
|
-
return block.getDataView();
|
|
380
|
-
}
|
|
381
|
-
return block.dataView || ctx.dataView;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
// A brob Exif box decompresses through the pool; a decompression failure or a
|
|
385
|
-
// bad header rejects, which drops the block. A JXL Exif box too short for its
|
|
386
|
-
// header has no tiffHeaderOffset and reads nothing.
|
|
387
|
-
function readExifBlock(block, ctx) {
|
|
388
|
-
if (block.compression !== undefined) {
|
|
389
|
-
if (!Constants.USE_JXL) {
|
|
390
|
-
return undefined;
|
|
391
|
-
}
|
|
392
|
-
return ctx.decompress(getBrobDataView(ctx.dataView, block), getCompressionMethod(block.compression), undefined, 'dataview')
|
|
393
|
-
.then((view) => readExifView(view, getTiffHeaderOffset(view, 0), ctx, {carried: 'brob', decompressed: true}));
|
|
394
|
-
}
|
|
395
|
-
if (block.tiffHeaderOffset === undefined) {
|
|
396
|
-
return undefined;
|
|
397
|
-
}
|
|
398
|
-
return readExifView(getBlockDataView(block, ctx), block.tiffHeaderOffset, ctx, {
|
|
399
|
-
carried: block.origin || 'main',
|
|
400
|
-
decompressed: block.decompressed === true,
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
// The main block creates the value budget from its view; an embedded block
|
|
405
|
-
// draws from the shared one and, when decompressed, adds its allowance.
|
|
406
|
-
function readExifView(view, tiffHeaderOffset, ctx, {carried, decompressed}) {
|
|
407
|
-
const isMain = carried === 'main';
|
|
408
|
-
const valueBudget = isMain ? ctx.getValueBudget(view) : ctx.getValueBudget();
|
|
409
|
-
if (decompressed) {
|
|
410
|
-
addDecompressedValueAllowance(valueBudget, view.byteLength);
|
|
411
|
-
}
|
|
412
|
-
const read = isMain ? readExifTagsSafely : readExifTags;
|
|
413
|
-
const {tags, byteOrder, makerNoteOffset} = read(view, tiffHeaderOffset, ctx, valueBudget);
|
|
414
|
-
const thumbnailIfdTags = tags.Thumbnail;
|
|
415
|
-
delete tags.Thumbnail;
|
|
416
|
-
|
|
417
|
-
const parsed = filterTagsForParse('exif', tags, ctx.tagFilter);
|
|
418
|
-
const blocks = getExifEmittedBlocks(parsed, {view, tiffHeaderOffset, byteOrder, makerNoteOffset, thumbnailIfdTags, carried, decompressed});
|
|
419
|
-
if (carried === 'brob' && Object.keys(parsed).length === 0) {
|
|
420
|
-
return {tags: undefined, blocks};
|
|
421
|
-
}
|
|
422
|
-
return {tags: parsed, blocks};
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
// In emission order; the engine drops a kind no composed group consumes.
|
|
426
|
-
function getExifEmittedBlocks(parsed, {view, tiffHeaderOffset, byteOrder, makerNoteOffset, thumbnailIfdTags, carried, decompressed}) {
|
|
427
|
-
const blocks = [];
|
|
428
|
-
|
|
429
|
-
if (parsed['IPTC-NAA']) {
|
|
430
|
-
blocks.push({kind: 'iptc', dataView: parsed['IPTC-NAA'].value, dataOffset: 0, carried});
|
|
431
|
-
}
|
|
432
|
-
if (parsed['ApplicationNotes'] && isNumberArray(parsed['ApplicationNotes'].value)) {
|
|
433
|
-
const applicationNotes = parsed['ApplicationNotes'].value;
|
|
434
|
-
blocks.push({kind: 'xmp', carried, decompressed, byteLength: applicationNotes.length, getDataView: () => getByteString(applicationNotes)});
|
|
435
|
-
}
|
|
436
|
-
if (parsed['ImageSourceData'] && parsed['PhotoshopSettings'] && Array.isArray(parsed['PhotoshopSettings'].value)) {
|
|
437
|
-
blocks.push({kind: 'photoshop', value: parsed['PhotoshopSettings'].value, carried});
|
|
438
|
-
}
|
|
439
|
-
if (parsed['ICC_Profile']) {
|
|
440
|
-
const profile = parsed['ICC_Profile'].value;
|
|
441
|
-
blocks.push({kind: 'icc', dataView: profile, chunks: [{offset: 0, length: profile.length, chunkNumber: 1, chunksTotal: 1}], carried});
|
|
442
|
-
}
|
|
443
|
-
if (parsed['MakerNote'] && makerNoteOffset !== undefined) {
|
|
444
|
-
blocks.push({
|
|
445
|
-
kind: 'makerNote',
|
|
446
|
-
tiffView: view,
|
|
447
|
-
tiffHeaderOffset,
|
|
448
|
-
makerNoteOffset,
|
|
449
|
-
byteOrder,
|
|
450
|
-
make: parsed['Make'] && parsed['Make'].value,
|
|
451
|
-
bytes: parsed['MakerNote'].value,
|
|
452
|
-
carried,
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
if (thumbnailIfdTags) {
|
|
456
|
-
blocks.push({kind: 'thumbnail', dataView: view, tiffHeaderOffset, ifd1Tags: thumbnailIfdTags, decompressed, rank: carried === 'main' ? 'main' : 'embedded'});
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
return blocks;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
// A carried IPTC-NAA draws no allowance; a decompressed raw profile does.
|
|
463
|
-
function readIptcBlock(block, ctx) {
|
|
464
|
-
const view = getBlockDataView(block, ctx);
|
|
465
|
-
const valueBudget = ctx.getValueBudget();
|
|
466
|
-
if (block.origin === 'rawProfile' && block.decompressed) {
|
|
467
|
-
addDecompressedIptcAllowance(valueBudget, view.byteLength);
|
|
468
|
-
}
|
|
469
|
-
return parsedTags('iptc', IptcTags.read(view, block.dataOffset, ctx.options.includeUnknown, ctx.tagFilter, valueBudget), ctx);
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
function readXmpBlock(block, ctx) {
|
|
473
|
-
const {domParser} = ctx.options;
|
|
474
|
-
if (block.compression !== undefined) {
|
|
475
|
-
if (!Constants.USE_JXL) {
|
|
476
|
-
return undefined;
|
|
477
|
-
}
|
|
478
|
-
return ctx.decompress(getBrobDataView(ctx.dataView, block), getCompressionMethod(block.compression), undefined, 'dataview')
|
|
479
|
-
.then((view) => readBrobXmpView(view, ctx));
|
|
480
|
-
}
|
|
481
|
-
if (block.carried !== undefined) {
|
|
482
|
-
if (block.decompressed && !ctx.takeDecompressedApplicationNotesAllowance(block.byteLength)) {
|
|
483
|
-
return undefined;
|
|
78
|
+
const tables = getDefaultTables();
|
|
79
|
+
const entries = getTableEntries(tables);
|
|
80
|
+
if (defaultComposition === undefined || !haveSameItems(entries, defaultCompositionEntries)) {
|
|
81
|
+
defaultComposition = Composition.createComposition(tables);
|
|
82
|
+
defaultComposition.isHiddenInSyncMode = createIsHiddenInSyncMode(tables.formats);
|
|
83
|
+
if (Constants.USE_EXIF && Constants.USE_THUMBNAIL) {
|
|
84
|
+
defaultComposition.mergeModes = objectAssign(Object.create(null), defaultComposition.mergeModes, {thumbnail: addThumbnailWithAlias});
|
|
484
85
|
}
|
|
485
|
-
|
|
486
|
-
}
|
|
487
|
-
if (!hasXmpData(block)) {
|
|
488
|
-
return undefined;
|
|
489
|
-
}
|
|
490
|
-
return parsedTags('xmp', XmpTags.read(block.dataView || ctx.dataView, block.chunks, domParser, ctx.getDomParser), ctx);
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
function readBrobXmpView(view, ctx) {
|
|
494
|
-
if (ctx.exceedsBrobXmpSizeBound(view.byteLength)) {
|
|
495
|
-
return parsedTags('xmp', {}, ctx);
|
|
496
|
-
}
|
|
497
|
-
return parsedTags('xmp', XmpTags.read(view, [{dataOffset: 0, length: view.byteLength}], ctx.options.domParser, ctx.getDomParser), ctx);
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
// A compressed iCCP gives a thenable in async mode, which defers the block.
|
|
501
|
-
function readIccBlock(block, ctx) {
|
|
502
|
-
if (!hasIccData(block)) {
|
|
503
|
-
return undefined;
|
|
504
|
-
}
|
|
505
|
-
const readTags = IccTags.read(block.dataView || ctx.dataView, block.chunks, ctx.options.async, ctx.decompressConfig);
|
|
506
|
-
if (isThenable(readTags)) {
|
|
507
|
-
return readTags.then((resolvedTags) => parsedTags('icc', resolvedTags, ctx));
|
|
508
|
-
}
|
|
509
|
-
return parsedTags('icc', readTags, ctx);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
// The maker note readers filter their own tags.
|
|
513
|
-
function readMakerNoteBlock(block, ctx) {
|
|
514
|
-
const {includeUnknown, computed} = ctx.options;
|
|
515
|
-
if (Array.isArray(block.make) && block.make[0] === 'Canon') {
|
|
516
|
-
return {tags: CanonTags.read(block.tiffView, block.tiffHeaderOffset, block.makerNoteOffset, block.byteOrder, includeUnknown, computed, ctx.tagFilter, ctx.getValueBudget())};
|
|
517
|
-
}
|
|
518
|
-
if (hasPentaxType1Prefix(block.bytes)) {
|
|
519
|
-
return {tags: PentaxTags.read(block.tiffView, block.tiffHeaderOffset, block.makerNoteOffset, includeUnknown, computed, ctx.tagFilter, ctx.getValueBudget())};
|
|
520
|
-
}
|
|
521
|
-
return undefined;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
function hasPentaxType1Prefix(makerNoteBytes) {
|
|
525
|
-
const PENTAX_ID_STRING = 'PENTAX ';
|
|
526
|
-
return Array.isArray(makerNoteBytes)
|
|
527
|
-
&& makerNoteBytes.length > PENTAX_ID_STRING.length
|
|
528
|
-
&& getStringValueFromArray(makerNoteBytes.slice(0, PENTAX_ID_STRING.length)) === PENTAX_ID_STRING;
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
// The main block's thumbnail is a candidate with or without an image. An
|
|
532
|
-
// embedded one is a candidate only with an image, within the copy bound, and
|
|
533
|
-
// not once an uncompressed block gave one; the decompressed blocks of a file
|
|
534
|
-
// all get to try, since they are read after the uncompressed ones.
|
|
535
|
-
function readThumbnailBlock(block, ctx) {
|
|
536
|
-
if (!ctx.tagFilter.shouldReturnTag('thumbnail', 'Thumbnail')) {
|
|
537
|
-
return undefined;
|
|
538
|
-
}
|
|
539
|
-
const parsed = filterTagsForParse('thumbnail', block.ifd1Tags, ctx.tagFilter);
|
|
540
|
-
if (block.rank === 'main') {
|
|
541
|
-
return {tags: Thumbnail.get(block.dataView, parsed, block.tiffHeaderOffset, ctx.getBase64Image)};
|
|
542
|
-
}
|
|
543
|
-
if (ctx.hasEmbeddedThumbnailImage) {
|
|
544
|
-
return undefined;
|
|
86
|
+
defaultCompositionEntries = entries;
|
|
545
87
|
}
|
|
546
|
-
|
|
547
|
-
if (!lengthTag || typeof lengthTag.value !== 'number' || lengthTag.value > ctx.embeddedThumbnailSizeBound - ctx.copiedThumbnailSize) {
|
|
548
|
-
return undefined;
|
|
549
|
-
}
|
|
550
|
-
const thumbnail = Thumbnail.get(block.dataView, parsed, block.tiffHeaderOffset, ctx.getBase64Image);
|
|
551
|
-
if (!thumbnail.image) {
|
|
552
|
-
return undefined;
|
|
553
|
-
}
|
|
554
|
-
ctx.copiedThumbnailSize += lengthTag.value;
|
|
555
|
-
if (!block.decompressed) {
|
|
556
|
-
ctx.hasEmbeddedThumbnailImage = true;
|
|
557
|
-
}
|
|
558
|
-
return {tags: thumbnail};
|
|
88
|
+
return defaultComposition;
|
|
559
89
|
}
|
|
560
90
|
|
|
561
|
-
//
|
|
562
|
-
//
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
const combined = [];
|
|
566
|
-
const leaves = [];
|
|
567
|
-
let tierIndex = -1;
|
|
91
|
+
// Thumbnail is the enumerable key existing code reads; thumbnail is the same
|
|
92
|
+
// object, left out of Object.keys and JSON.stringify so the output is unchanged.
|
|
93
|
+
function addThumbnailWithAlias(tags, block, context) {
|
|
94
|
+
removeThumbnailTag(tags);
|
|
568
95
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
96
|
+
const selected = getSelectedThumbnail(context);
|
|
97
|
+
if (selected) {
|
|
98
|
+
tags.Thumbnail = selected;
|
|
99
|
+
if (!Object.prototype.hasOwnProperty.call(tags, 'thumbnail')) {
|
|
100
|
+
Object.defineProperty(tags, 'thumbnail', {value: selected, writable: true, configurable: true});
|
|
573
101
|
}
|
|
574
|
-
if (tierIndex === -1) {
|
|
575
|
-
tierIndex = combined.length;
|
|
576
|
-
combined.push(undefined);
|
|
577
|
-
}
|
|
578
|
-
collectLeafBlocks(mergeBlocks[i], leaves);
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
if (tierIndex !== -1) {
|
|
582
|
-
combined[tierIndex] = {slot: 'pngText', mode: 'nested', blocks: leaves};
|
|
583
102
|
}
|
|
584
|
-
return combined;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
function collectLeafBlocks(block, leaves) {
|
|
588
|
-
if (block.mode !== 'nested') {
|
|
589
|
-
leaves.push(block);
|
|
590
|
-
return;
|
|
591
|
-
}
|
|
592
|
-
for (let i = 0; i < block.blocks.length; i++) {
|
|
593
|
-
collectLeafBlocks(block.blocks[i], leaves);
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
function getDerivedBlocks({expanded, includeOffsets, async, ranges, truncated}) {
|
|
598
|
-
const blocks = [];
|
|
599
|
-
if (Constants.USE_EXIF) {
|
|
600
|
-
blocks.push({slot: 'gps', mode: 'gps'});
|
|
601
|
-
}
|
|
602
|
-
if (Constants.USE_EXIF || Constants.USE_XMP) {
|
|
603
|
-
blocks.push({slot: 'composite', mode: 'composite'});
|
|
604
|
-
}
|
|
605
|
-
blocks.push({slot: 'thumbnail', mode: 'thumbnail'});
|
|
606
|
-
blocks.push({slot: 'fileType', mode: 'fileType'});
|
|
607
|
-
if (expanded && includeOffsets) {
|
|
608
|
-
blocks.push({
|
|
609
|
-
slot: 'metadataRange',
|
|
610
|
-
mode: 'metadataRange',
|
|
611
|
-
metadataBlocks: getMetadataRangeBlocks(ranges, async),
|
|
612
|
-
metadataTruncated: !!truncated,
|
|
613
|
-
});
|
|
614
|
-
}
|
|
615
|
-
return blocks;
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
// A caller-supplied DataView can be a window into a larger buffer. Extractors
|
|
619
|
-
// slice dataView.buffer, so copy the window out to keep them inside the image.
|
|
620
|
-
function getSelfContainedDataView(dataView) {
|
|
621
|
-
if (isWindowIntoLargerBuffer(dataView)) {
|
|
622
|
-
return getDataView(dataView.buffer.slice(dataView.byteOffset, dataView.byteOffset + dataView.byteLength));
|
|
623
|
-
}
|
|
624
|
-
return dataView;
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
function isWindowIntoLargerBuffer(dataView) {
|
|
628
|
-
return isDataViewLike(dataView)
|
|
629
|
-
&& ((dataView.byteOffset > 0) || (dataView.byteLength < dataView.buffer.byteLength));
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
// A DataView from another realm, an iframe for example, fails instanceof, so
|
|
633
|
-
// match on the shape instead. A typed array has no getUint8, so it is not
|
|
634
|
-
// treated as a window here.
|
|
635
|
-
function isDataViewLike(dataView) {
|
|
636
|
-
return !!dataView
|
|
637
|
-
&& (typeof dataView.getUint8 === 'function')
|
|
638
|
-
&& (typeof dataView.byteOffset === 'number')
|
|
639
|
-
&& (typeof dataView.byteLength === 'number')
|
|
640
|
-
&& !!dataView.buffer
|
|
641
|
-
&& (typeof dataView.buffer.slice === 'function');
|
|
642
|
-
}
|
|
643
103
|
|
|
644
|
-
|
|
645
|
-
// The box length is untrusted, so bound the view by the bytes present. The
|
|
646
|
-
// JXL header parser never reports a dataOffset past the end of the view.
|
|
647
|
-
const length = Math.max(0, Math.min(brobBlock.length, dataView.byteLength - brobBlock.dataOffset));
|
|
648
|
-
return new DataView(dataView.buffer, dataView.byteOffset + brobBlock.dataOffset, length);
|
|
104
|
+
return tags;
|
|
649
105
|
}
|
|
650
106
|
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
return {tags: {}, byteOrder: ByteOrder.BIG_ENDIAN, makerNoteOffset: undefined};
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
function readExifTags(dataView, tiffHeaderOffset, ctx, valueBudget) {
|
|
664
|
-
return Tags.read(
|
|
665
|
-
dataView,
|
|
666
|
-
tiffHeaderOffset,
|
|
667
|
-
ctx.options.includeUnknown,
|
|
668
|
-
ctx.options.computed,
|
|
669
|
-
ctx.tagFilter,
|
|
670
|
-
valueBudget,
|
|
671
|
-
getExifTagNames(),
|
|
672
|
-
shouldReadThumbnailIfd(ctx.tagFilter)
|
|
673
|
-
);
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
// Only the IFDs Tags.read walks; the MPF and maker note readers carry their own
|
|
677
|
-
// dictionaries. The thumbnail one must be there whenever shouldReadThumbnailIfd
|
|
678
|
-
// is true, since reading an IFD without its dictionary throws.
|
|
679
|
-
function getExifTagNames() {
|
|
680
|
-
// Assigned rather than computed keys, which Babel compiles to a helper call each.
|
|
681
|
-
const tagNames = {};
|
|
682
|
-
tagNames[IFD_TYPE_0TH] = TAG_NAMES_0TH_AND_EXIF_IFDS;
|
|
683
|
-
tagNames[IFD_TYPE_EXIF] = TAG_NAMES_0TH_AND_EXIF_IFDS;
|
|
684
|
-
tagNames[IFD_TYPE_GPS] = TagNamesGpsIfd;
|
|
685
|
-
tagNames[IFD_TYPE_INTEROPERABILITY] = TagNamesInteroperabilityIfd;
|
|
686
|
-
if (Constants.USE_THUMBNAIL) {
|
|
687
|
-
tagNames[IFD_TYPE_1ST] = TagNames0thIfd;
|
|
688
|
-
}
|
|
689
|
-
return tagNames;
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
function shouldReadThumbnailIfd(tagFilter) {
|
|
693
|
-
return Constants.USE_THUMBNAIL && tagFilter.shouldParseGroup('thumbnail');
|
|
107
|
+
// Each helper is behind the flags of the groups that read it, so that a
|
|
108
|
+
// custom build without them folds the helper's module away.
|
|
109
|
+
function getEnvironment() {
|
|
110
|
+
return {
|
|
111
|
+
getDomParser: Constants.USE_XMP ? DOMParser.get : undefined,
|
|
112
|
+
getBase64Image: (Constants.USE_EXIF && Constants.USE_THUMBNAIL) || Constants.USE_MPF ? getBase64Image : undefined,
|
|
113
|
+
createTagFilter,
|
|
114
|
+
};
|
|
694
115
|
}
|
|
695
116
|
|
|
696
|
-
//
|
|
697
|
-
//
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
117
|
+
// Every format and group, each inside its build gate so that a custom build
|
|
118
|
+
// folds the import away. A format-bound reader has its own gate, so the jpeg
|
|
119
|
+
// and png formats are listed by header and readers rather than whole.
|
|
120
|
+
function getDefaultTables() {
|
|
121
|
+
return {
|
|
122
|
+
formats: [
|
|
123
|
+
Constants.USE_TIFF ? tiff : undefined,
|
|
124
|
+
Constants.USE_JPEG ? {
|
|
125
|
+
header: jpegHeader,
|
|
126
|
+
readers: [
|
|
127
|
+
Constants.USE_FILE ? file : undefined,
|
|
128
|
+
Constants.USE_JFIF ? jfif : undefined,
|
|
129
|
+
],
|
|
130
|
+
} : undefined,
|
|
131
|
+
Constants.USE_PNG ? {
|
|
132
|
+
header: pngHeader,
|
|
133
|
+
readers: [
|
|
134
|
+
Constants.USE_PNG_FILE ? pngFile : undefined,
|
|
135
|
+
pngText,
|
|
136
|
+
pngChunk,
|
|
137
|
+
],
|
|
138
|
+
} : undefined,
|
|
139
|
+
Constants.USE_HEIC ? heic : undefined,
|
|
140
|
+
Constants.USE_AVIF ? avif : undefined,
|
|
141
|
+
Constants.USE_JXL ? jxl : undefined,
|
|
142
|
+
Constants.USE_WEBP ? webp : undefined,
|
|
143
|
+
Constants.USE_GIF ? gif : undefined,
|
|
144
|
+
Constants.USE_XMP ? xml : undefined,
|
|
145
|
+
].filter(Boolean),
|
|
146
|
+
groups: [
|
|
147
|
+
Constants.USE_EXIF ? exif : undefined,
|
|
148
|
+
Constants.USE_IPTC ? iptc : undefined,
|
|
149
|
+
Constants.USE_XMP ? xmp : undefined,
|
|
150
|
+
Constants.USE_ICC ? icc : undefined,
|
|
151
|
+
Constants.USE_MPF ? mpf : undefined,
|
|
152
|
+
Constants.USE_PHOTOSHOP ? photoshop : undefined,
|
|
153
|
+
Constants.USE_MAKER_NOTES ? makerNotes : undefined,
|
|
154
|
+
Constants.USE_EXIF && Constants.USE_THUMBNAIL ? thumbnail : undefined,
|
|
155
|
+
Constants.USE_EXIF ? gps : undefined,
|
|
156
|
+
Constants.USE_EXIF || Constants.USE_XMP ? composite : undefined,
|
|
157
|
+
].filter(Boolean),
|
|
158
|
+
};
|
|
713
159
|
}
|
|
714
160
|
|
|
715
|
-
// The
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
return 'file';
|
|
161
|
+
// The jpeg and png formats are new objects on every call, so they compare by
|
|
162
|
+
// header and readers.
|
|
163
|
+
function getTableEntries({formats, groups}) {
|
|
164
|
+
let entries = [];
|
|
165
|
+
for (let i = 0; i < formats.length; i++) {
|
|
166
|
+
entries = entries.concat([formats[i].header], formats[i].readers);
|
|
722
167
|
}
|
|
723
|
-
return
|
|
168
|
+
return entries.concat(groups);
|
|
724
169
|
}
|
|
725
170
|
|
|
726
|
-
function
|
|
727
|
-
if (
|
|
728
|
-
return
|
|
729
|
-
}
|
|
730
|
-
switch (block.kind) {
|
|
731
|
-
case 'file':
|
|
732
|
-
return Constants.USE_FILE;
|
|
733
|
-
case 'pngFile':
|
|
734
|
-
return Constants.USE_PNG_FILE;
|
|
735
|
-
case 'exif':
|
|
736
|
-
return Constants.USE_EXIF;
|
|
737
|
-
case 'jfif':
|
|
738
|
-
return Constants.USE_JFIF;
|
|
739
|
-
case 'xmp':
|
|
740
|
-
return Constants.USE_XMP;
|
|
741
|
-
case 'iptc':
|
|
742
|
-
return Constants.USE_IPTC;
|
|
743
|
-
case 'icc':
|
|
744
|
-
return Constants.USE_ICC;
|
|
745
|
-
case 'mpf':
|
|
746
|
-
return Constants.USE_MPF;
|
|
747
|
-
default:
|
|
748
|
-
return true;
|
|
171
|
+
function haveSameItems(items, otherItems) {
|
|
172
|
+
if (items.length !== otherItems.length) {
|
|
173
|
+
return false;
|
|
749
174
|
}
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
let gps = undefined;
|
|
754
|
-
|
|
755
|
-
if (exifTags.GPSLatitude && exifTags.GPSLatitudeRef) {
|
|
756
|
-
gps = gps || {};
|
|
757
|
-
try {
|
|
758
|
-
gps.Latitude = getCalculatedGpsValue(exifTags.GPSLatitude.value);
|
|
759
|
-
if (exifTags.GPSLatitudeRef.value.join('') === 'S') {
|
|
760
|
-
gps.Latitude = -gps.Latitude;
|
|
761
|
-
}
|
|
762
|
-
} catch (error) {
|
|
763
|
-
// Ignore.
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
if (exifTags.GPSLongitude && exifTags.GPSLongitudeRef) {
|
|
768
|
-
gps = gps || {};
|
|
769
|
-
try {
|
|
770
|
-
gps.Longitude = getCalculatedGpsValue(exifTags.GPSLongitude.value);
|
|
771
|
-
if (exifTags.GPSLongitudeRef.value.join('') === 'W') {
|
|
772
|
-
gps.Longitude = -gps.Longitude;
|
|
773
|
-
}
|
|
774
|
-
} catch (error) {
|
|
775
|
-
// Ignore.
|
|
175
|
+
for (let i = 0; i < items.length; i++) {
|
|
176
|
+
if (items[i] !== otherItems[i]) {
|
|
177
|
+
return false;
|
|
776
178
|
}
|
|
777
179
|
}
|
|
778
|
-
|
|
779
|
-
if (exifTags.GPSAltitude && exifTags.GPSAltitudeRef) {
|
|
780
|
-
gps = gps || {};
|
|
781
|
-
try {
|
|
782
|
-
gps.Altitude =
|
|
783
|
-
exifTags.GPSAltitude.value[0] / exifTags.GPSAltitude.value[1];
|
|
784
|
-
if (exifTags.GPSAltitudeRef.value === 1) {
|
|
785
|
-
gps.Altitude = -gps.Altitude;
|
|
786
|
-
}
|
|
787
|
-
} catch (error) {
|
|
788
|
-
// Ignore.
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
if (!gps) {
|
|
793
|
-
return undefined;
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
return gps;
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
// ASCII values hold strings and holes, values of two or more rationals hold
|
|
800
|
-
// number pairs: neither converts to the character codes of an XMP packet.
|
|
801
|
-
function isNumberArray(value) {
|
|
802
|
-
return Array.isArray(value) && typeof value[0] === 'number';
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
// A brob block carries compressed XMP, not chunks.
|
|
806
|
-
function hasXmpData(xmpBlock) {
|
|
807
|
-
return xmpBlock !== undefined && xmpBlock.compression === undefined && xmpBlock.chunks.length > 0;
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
function hasIccData(iccBlock) {
|
|
811
|
-
return iccBlock !== undefined && iccBlock.chunks.length > 0;
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
function hasPngTextData(pngTextBlocks) {
|
|
815
|
-
return Array.isArray(pngTextBlocks) && pngTextBlocks.length > 0;
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
function isPngTextChunkBlock(block) {
|
|
819
|
-
return block.text !== undefined;
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
// Decision 2026-10-21: sync mode keeps leaving PNG compressed-text chunks
|
|
823
|
-
// (TYPE_ZTXT, whatever their header says) and the iCCP chunk out of
|
|
824
|
-
// metadataRange, the potential-metadata check and the readers, as the PNG
|
|
825
|
-
// finder did while it took the async flag; the iCCP block is always
|
|
826
|
-
// compressed. A compressed iTXt and a brob box stay listed, and unread, in
|
|
827
|
-
// sync mode, as before. The USE_PNG gate keeps the PNG finder's constant out
|
|
828
|
-
// of a build without PNG.
|
|
829
|
-
function isHiddenInSyncMode(block) {
|
|
830
|
-
return (Constants.USE_PNG && isPngTextChunkBlock(block) && block.text.chunkType === TYPE_ZTXT)
|
|
831
|
-
|| (block.kind === 'icc' && block.compression !== undefined);
|
|
180
|
+
return true;
|
|
832
181
|
}
|