exifreader 4.21.1 → 4.22.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 +5 -3
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +1 -0
- package/package.json +6 -6
- package/src/constants.js +1 -0
- package/src/exif-reader.js +1 -0
- package/src/image-header-avif.js +42 -0
- package/src/image-header-heic.js +20 -167
- package/src/image-header-iso-bmff-iloc.js +142 -0
- package/src/image-header-iso-bmff-utils.js +5 -0
- package/src/image-header-iso-bmff.js +460 -0
- package/src/image-header.js +5 -0
- package/webpack.config.js +2 -1
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
import Constants from './constants.js';
|
|
2
|
+
import {getNullTerminatedStringFromDataView, getStringFromDataView} from './utils.js';
|
|
3
|
+
// import {get64BitValue} from './image-header-iso-bmff-utils.js';
|
|
4
|
+
import {parseItemLocationBox} from './image-header-iso-bmff-iloc.js';
|
|
5
|
+
|
|
6
|
+
// HEIC and AVIF files are based on the ISO-BMFF format. This file format is
|
|
7
|
+
// built up by boxes. There are boxes and full boxes. All box types have a
|
|
8
|
+
// length (4 or 8 bytes) and a type (4 bytes). Full boxes also have a version
|
|
9
|
+
// (1 byte) and flags (3 bytes). The boxes can be nested. Each box type has its
|
|
10
|
+
// own structure that can be seen in the specification.
|
|
11
|
+
//
|
|
12
|
+
// For metadata we are interested in the meta box. The meta box contains sub
|
|
13
|
+
// boxes. The sub box type iinf has info about which types of metadata are
|
|
14
|
+
// present in the file. The item ID we get from there we then look up in the
|
|
15
|
+
// iloc sub box to get the offset to the real location of the metadata.
|
|
16
|
+
//
|
|
17
|
+
// The ICC profiles is a bit more nested. We have to look in
|
|
18
|
+
// meta > iprp > ipco > colr, and then the whole profile is stored there.
|
|
19
|
+
|
|
20
|
+
// These are actually 32-bit strings, not random IDs, e.g. "ftyp" and "meta".
|
|
21
|
+
const TYPE_FTYP = 0x66747970;
|
|
22
|
+
const TYPE_IPRP = 0x69707270;
|
|
23
|
+
const TYPE_META = 0x6d657461;
|
|
24
|
+
const TYPE_ILOC = 0x696c6f63;
|
|
25
|
+
const TYPE_IINF = 0x69696e66;
|
|
26
|
+
const TYPE_INFE = 0x696e6665;
|
|
27
|
+
const TYPE_IPCO = 0x6970636f;
|
|
28
|
+
const TYPE_COLR = 0x636f6c72;
|
|
29
|
+
|
|
30
|
+
// const EXTENSION_TYPE_FDEL = 0x6664656c;
|
|
31
|
+
|
|
32
|
+
export const ITEM_INFO_TYPE_EXIF = 0x45786966;
|
|
33
|
+
export const ITEM_INFO_TYPE_MIME = 0x6d696d65;
|
|
34
|
+
const ITEM_INFO_TYPE_URI = 0x75726920;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Parses a ISO-BMFF box from the provided data view starting at the given offset.
|
|
38
|
+
*
|
|
39
|
+
* @param {DataView} dataView - The DataView to parse.
|
|
40
|
+
* @param {number} offset - The offset at which to start parsing.
|
|
41
|
+
* @returns {Object} The parsed box.
|
|
42
|
+
*/
|
|
43
|
+
export function parseBox(dataView, offset) {
|
|
44
|
+
const BOX_TYPE_OFFSET = 4;
|
|
45
|
+
const BOX_MIN_LENGTH = 8;
|
|
46
|
+
const VERSION_SIZE = 1;
|
|
47
|
+
|
|
48
|
+
const {length, contentOffset} = getBoxLength(dataView, offset);
|
|
49
|
+
if (length < BOX_MIN_LENGTH) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const type = dataView.getUint32(offset + BOX_TYPE_OFFSET);
|
|
54
|
+
|
|
55
|
+
if (type === TYPE_FTYP) {
|
|
56
|
+
return parseFileTypeBox(dataView, contentOffset, length);
|
|
57
|
+
}
|
|
58
|
+
if (type === TYPE_IPRP) {
|
|
59
|
+
return parseItemPropertiesBox(dataView, offset, contentOffset, length);
|
|
60
|
+
}
|
|
61
|
+
if (type === TYPE_IPCO) {
|
|
62
|
+
return parseItemPropertyContainerBox(dataView, offset, contentOffset, length);
|
|
63
|
+
}
|
|
64
|
+
if (type === TYPE_COLR) {
|
|
65
|
+
return parseColorInformationBox(dataView, contentOffset, length);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// The following are full boxes, also containing version and flags.
|
|
69
|
+
const version = dataView.getUint8(contentOffset);
|
|
70
|
+
|
|
71
|
+
if (type === TYPE_META) {
|
|
72
|
+
return parseMetadataBox(dataView, offset, contentOffset + VERSION_SIZE, length);
|
|
73
|
+
}
|
|
74
|
+
if (type === TYPE_ILOC) {
|
|
75
|
+
return parseItemLocationBox(dataView, version, contentOffset + VERSION_SIZE, length);
|
|
76
|
+
}
|
|
77
|
+
if (type === TYPE_IINF) {
|
|
78
|
+
return parseItemInformationBox(dataView, offset, version, contentOffset + VERSION_SIZE, length);
|
|
79
|
+
}
|
|
80
|
+
if (type === TYPE_INFE) {
|
|
81
|
+
return parseItemInformationEntryBox(dataView, offset, version, contentOffset + VERSION_SIZE, length);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
// type: getStringFromDataView(dataView, offset + BOX_TYPE_OFFSET, 4),
|
|
86
|
+
type: undefined,
|
|
87
|
+
length
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @typedef {Object} BoxLength
|
|
93
|
+
* @property {number} length The length of the box including length and type.
|
|
94
|
+
* @property {number} contentOffset
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @param {DataView} dataView
|
|
99
|
+
* @param {number} offset
|
|
100
|
+
* @returns {BoxLength}
|
|
101
|
+
*/
|
|
102
|
+
function getBoxLength(dataView, offset) {
|
|
103
|
+
const BOX_LENGTH_SIZE = 4;
|
|
104
|
+
const BOX_TYPE_SIZE = 4;
|
|
105
|
+
const BOX_EXTENDED_SIZE = 8;
|
|
106
|
+
const BOX_EXTENDED_SIZE_LOW_OFFSET = 12;
|
|
107
|
+
|
|
108
|
+
const boxLength = dataView.getUint32(offset);
|
|
109
|
+
if (extendsToEndOfFile(boxLength)) {
|
|
110
|
+
return {
|
|
111
|
+
length: dataView.byteLength - offset,
|
|
112
|
+
contentOffset: offset + BOX_LENGTH_SIZE + BOX_TYPE_SIZE,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
if (hasExtendedSize(boxLength)) {
|
|
116
|
+
if (hasEmptyHighBits(dataView, offset)) {
|
|
117
|
+
// It's a bit tricky to handle 64 bit numbers in JavaScript. Let's
|
|
118
|
+
// wait until there are real-world examples where it is necessary.
|
|
119
|
+
return {
|
|
120
|
+
length: dataView.getUint32(offset + BOX_EXTENDED_SIZE_LOW_OFFSET),
|
|
121
|
+
contentOffset: offset + BOX_LENGTH_SIZE + BOX_TYPE_SIZE + BOX_EXTENDED_SIZE,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
length: boxLength,
|
|
128
|
+
contentOffset: offset + BOX_LENGTH_SIZE + BOX_TYPE_SIZE,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function extendsToEndOfFile(boxLength) {
|
|
133
|
+
return boxLength === 0;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function hasExtendedSize(boxLength) {
|
|
137
|
+
return boxLength === 1;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function hasEmptyHighBits(dataView, offset) {
|
|
141
|
+
const BOX_EXTENDED_SIZE_OFFSET = 8;
|
|
142
|
+
return dataView.getUint32(offset + BOX_EXTENDED_SIZE_OFFSET) === 0;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @typedef {Object} Offsets
|
|
147
|
+
* @property {number} tiffHeaderOffset
|
|
148
|
+
* @property {Array<Object>} xmpChunks
|
|
149
|
+
* @property {Array<Object>} iccChunks
|
|
150
|
+
* @property {boolean} hasAppMarkers
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Finds the offsets of ISO-BMFF-structued data in the provided data view.
|
|
155
|
+
*
|
|
156
|
+
* @param {DataView} dataView - The data view to find offsets in.
|
|
157
|
+
* @returns {Offsets} An object containing the offsets of the TIFF header, XMP chunks, ICC chunks, and a boolean indicating if any of these exist.
|
|
158
|
+
*/
|
|
159
|
+
export function findOffsets(dataView) {
|
|
160
|
+
if (Constants.USE_EXIF || Constants.USE_XMP || Constants.USE_ICC) {
|
|
161
|
+
const offsets = {};
|
|
162
|
+
const metaBox = findMetaBox(dataView);
|
|
163
|
+
|
|
164
|
+
if (!metaBox) {
|
|
165
|
+
return {hasAppMarkers: false};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (Constants.USE_EXIF) {
|
|
169
|
+
offsets.tiffHeaderOffset = findExifOffset(dataView, metaBox);
|
|
170
|
+
}
|
|
171
|
+
if (Constants.USE_XMP) {
|
|
172
|
+
offsets.xmpChunks = findXmpChunks(metaBox);
|
|
173
|
+
}
|
|
174
|
+
if (Constants.USE_ICC) {
|
|
175
|
+
offsets.iccChunks = findIccChunks(metaBox);
|
|
176
|
+
}
|
|
177
|
+
offsets.hasAppMarkers = (offsets.tiffHeaderOffset !== undefined) || (offsets.xmpChunks !== undefined) || (offsets.iccChunks !== undefined);
|
|
178
|
+
return offsets;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return {};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function findMetaBox(dataView) {
|
|
185
|
+
const BOX_LENGTH_SIZE = 4;
|
|
186
|
+
const BOX_TYPE_SIZE = 4;
|
|
187
|
+
|
|
188
|
+
let offset = 0;
|
|
189
|
+
|
|
190
|
+
while (offset + BOX_LENGTH_SIZE + BOX_TYPE_SIZE <= dataView.byteLength) {
|
|
191
|
+
const box = parseBox(dataView, offset);
|
|
192
|
+
|
|
193
|
+
if (box === undefined) {
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (box.type === 'meta') {
|
|
198
|
+
return box;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
offset += box.length;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function findExifOffset(dataView, metaBox) {
|
|
208
|
+
try {
|
|
209
|
+
const exifItemId = findIinfExifItemId(metaBox).itemId;
|
|
210
|
+
const exifOffset = findIlocItem(metaBox, exifItemId).extents[0].extentOffset;
|
|
211
|
+
return getTiffHeaderOffset(dataView, exifOffset);
|
|
212
|
+
} catch (error) {
|
|
213
|
+
return undefined;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function findIinfExifItemId(metaBox) {
|
|
218
|
+
return metaBox.subBoxes.find((box) => box.type === 'iinf').itemInfos.find((itemInfo) => itemInfo.itemType === ITEM_INFO_TYPE_EXIF);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function findIlocItem(metaBox, itemId) {
|
|
222
|
+
return metaBox.subBoxes.find((box) => box.type === 'iloc').items.find((item) => item.itemId === itemId);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function getTiffHeaderOffset(dataView, exifOffset) {
|
|
226
|
+
// ISO-BMFF formatted files store the Exif data as an "Exif block" where the
|
|
227
|
+
// first 32 bits is the TIFF header offset.
|
|
228
|
+
const TIFF_HEADER_OFFSET_SIZE = 4;
|
|
229
|
+
return exifOffset + TIFF_HEADER_OFFSET_SIZE + dataView.getUint32(exifOffset);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function findXmpChunks(metaBox) {
|
|
233
|
+
try {
|
|
234
|
+
const xmpItemId = findIinfXmpItemId(metaBox).itemId;
|
|
235
|
+
const ilocItem = findIlocItem(metaBox, xmpItemId).extents[0];
|
|
236
|
+
return [
|
|
237
|
+
{
|
|
238
|
+
dataOffset: ilocItem.extentOffset,
|
|
239
|
+
length: ilocItem.extentLength,
|
|
240
|
+
}
|
|
241
|
+
];
|
|
242
|
+
} catch (error) {
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function findIinfXmpItemId(metaBox) {
|
|
248
|
+
return metaBox.subBoxes.find((box) => box.type === 'iinf')
|
|
249
|
+
.itemInfos.find((itemInfo) => itemInfo.itemType === ITEM_INFO_TYPE_MIME && itemInfo.contentType === 'application/rdf+xml');
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function findIccChunks(metaBox) {
|
|
253
|
+
// This finds the first ICC chunk, but there could be one for each image
|
|
254
|
+
// that is embedded in the file. If it turns out we need to match the ICC
|
|
255
|
+
// chunk to a specific image, we need to check the "ipma" in addition to the
|
|
256
|
+
// "ipco" (currently we only extract the "ipco" so more code would be
|
|
257
|
+
// needed).
|
|
258
|
+
try {
|
|
259
|
+
const icc = metaBox.subBoxes.find((box) => box.type === 'iprp')
|
|
260
|
+
.subBoxes.find((box) => box.type === 'ipco')
|
|
261
|
+
.properties.find((box) => box.type === 'colr')
|
|
262
|
+
.icc;
|
|
263
|
+
if (icc) {
|
|
264
|
+
return [icc];
|
|
265
|
+
}
|
|
266
|
+
} catch (error) {
|
|
267
|
+
// Let it pass through.
|
|
268
|
+
}
|
|
269
|
+
return undefined;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function parseFileTypeBox(dataView, contentOffset, boxLength) {
|
|
273
|
+
const MAJOR_BRAND_SIZE = 4;
|
|
274
|
+
const majorBrand = getStringFromDataView(dataView, contentOffset, MAJOR_BRAND_SIZE);
|
|
275
|
+
|
|
276
|
+
return {
|
|
277
|
+
type: 'ftyp',
|
|
278
|
+
majorBrand,
|
|
279
|
+
length: boxLength
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function parseItemPropertiesBox(dataView, startOffset, contentOffset, length) {
|
|
284
|
+
return {
|
|
285
|
+
type: 'iprp',
|
|
286
|
+
subBoxes: parseSubBoxes(dataView, contentOffset, length - (contentOffset - startOffset)),
|
|
287
|
+
length,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function parseItemPropertyContainerBox(dataView, startOffset, contentOffset, length) {
|
|
292
|
+
return {
|
|
293
|
+
type: 'ipco',
|
|
294
|
+
properties: parseSubBoxes(dataView, contentOffset, length - (contentOffset - startOffset)),
|
|
295
|
+
length,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function parseColorInformationBox(dataView, contentOffset, length) {
|
|
300
|
+
return {
|
|
301
|
+
type: 'colr',
|
|
302
|
+
icc: parseIcc(dataView, contentOffset),
|
|
303
|
+
length,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function parseIcc(dataView, contentOffset) {
|
|
308
|
+
const COLOR_TYPE_SIZE = 4;
|
|
309
|
+
|
|
310
|
+
const colorType = getStringFromDataView(dataView, contentOffset, COLOR_TYPE_SIZE);
|
|
311
|
+
if (colorType !== 'prof' && colorType !== 'rICC') {
|
|
312
|
+
// Support for nclx would require some restructuring for ICC handling.
|
|
313
|
+
// Probably do it as a separate feature instead of combining with ICC.
|
|
314
|
+
// Exiftool groups it under QuickTime. The test file test.avif has nclx.
|
|
315
|
+
return undefined;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return {
|
|
319
|
+
offset: contentOffset + COLOR_TYPE_SIZE,
|
|
320
|
+
length: dataView.getUint32(contentOffset + COLOR_TYPE_SIZE),
|
|
321
|
+
chunkNumber: 1,
|
|
322
|
+
chunksTotal: 1
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function parseMetadataBox(dataView, startOffset, contentOffset, length) {
|
|
327
|
+
const FLAGS_SIZE = 3;
|
|
328
|
+
|
|
329
|
+
return {
|
|
330
|
+
type: 'meta',
|
|
331
|
+
subBoxes: parseSubBoxes(dataView, contentOffset + FLAGS_SIZE, length - (contentOffset + FLAGS_SIZE - startOffset)),
|
|
332
|
+
length
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* @param {DataView} dataView
|
|
338
|
+
* @param {number} offset The offset to start parsing from.
|
|
339
|
+
* @param {number} length The length of all sub boxes combined.
|
|
340
|
+
* @return {Array<Object>}
|
|
341
|
+
*/
|
|
342
|
+
function parseSubBoxes(dataView, offset, length) {
|
|
343
|
+
const ACCEPTED_ITEM_INFO_TYPES = [
|
|
344
|
+
ITEM_INFO_TYPE_EXIF,
|
|
345
|
+
ITEM_INFO_TYPE_MIME,
|
|
346
|
+
];
|
|
347
|
+
|
|
348
|
+
const subBoxes = [];
|
|
349
|
+
let currentOffset = offset;
|
|
350
|
+
while (currentOffset < offset + length) {
|
|
351
|
+
const box = parseBox(dataView, currentOffset);
|
|
352
|
+
if (box === undefined) {
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
if (box.type !== undefined && (box.itemType === undefined || ACCEPTED_ITEM_INFO_TYPES.indexOf(box.itemType) !== -1)) {
|
|
356
|
+
subBoxes.push(box);
|
|
357
|
+
}
|
|
358
|
+
currentOffset += box.length;
|
|
359
|
+
}
|
|
360
|
+
return subBoxes;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function parseItemInformationBox(dataView, startOffset, version, contentOffset, length) {
|
|
364
|
+
const {offsets} = getItemInformationBoxOffsetsAndSizes(version, contentOffset);
|
|
365
|
+
|
|
366
|
+
return {
|
|
367
|
+
type: 'iinf',
|
|
368
|
+
itemInfos: parseSubBoxes(dataView, offsets.itemInfos, length - (offsets.itemInfos - startOffset)),
|
|
369
|
+
length
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function getItemInformationBoxOffsetsAndSizes(version, contentOffset) {
|
|
374
|
+
const FLAGS_SIZE = 3;
|
|
375
|
+
|
|
376
|
+
const offsets = {entryCount: contentOffset + FLAGS_SIZE};
|
|
377
|
+
const sizes = {};
|
|
378
|
+
|
|
379
|
+
if (version === 0) {
|
|
380
|
+
sizes.entryCount = 2;
|
|
381
|
+
} else {
|
|
382
|
+
sizes.entryCount = 4;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
offsets.itemInfos = offsets.entryCount + sizes.entryCount;
|
|
386
|
+
|
|
387
|
+
return {offsets};
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function parseItemInformationEntryBox(dataView, startOffset, version, contentOffset, length) {
|
|
391
|
+
const FLAGS_SIZE = 3;
|
|
392
|
+
|
|
393
|
+
contentOffset += FLAGS_SIZE;
|
|
394
|
+
const entry = {type: 'infe', length};
|
|
395
|
+
|
|
396
|
+
if (version === 0 || version === 1) {
|
|
397
|
+
entry.itemId = dataView.getUint16(contentOffset);
|
|
398
|
+
contentOffset += 2;
|
|
399
|
+
entry.itemProtectionIndex = dataView.getUint16(contentOffset);
|
|
400
|
+
contentOffset += 2;
|
|
401
|
+
entry.itemName = getNullTerminatedStringFromDataView(dataView, contentOffset);
|
|
402
|
+
contentOffset += entry.itemName.length + 1;
|
|
403
|
+
// entry.contentType = getNullTerminatedStringFromDataView(dataView, offset);
|
|
404
|
+
// offset += entry.contentType.length + 1;
|
|
405
|
+
// Since contentEncoding is optional we need to check the offset against length here.
|
|
406
|
+
// entry.contentEncoding = getNullTerminatedStringFromDataView(dataView, offset);
|
|
407
|
+
// offset += entry.contentEncoding.length + 1;
|
|
408
|
+
}
|
|
409
|
+
// The following code should be correct but we currently don't need it.
|
|
410
|
+
// if (version === 1) {
|
|
411
|
+
// // Everything here is optional, check the offset against length.
|
|
412
|
+
// entry.extensionType = dataView.getUint32(contentOffset);
|
|
413
|
+
// contentOffset += 4;
|
|
414
|
+
// if (entry.extensionType === EXTENSION_TYPE_FDEL) {
|
|
415
|
+
// entry.contentLocation = getNullTerminatedStringFromDataView(dataView, contentOffset);
|
|
416
|
+
// contentOffset += entry.contentLocation.length + 1;
|
|
417
|
+
// entry.contentMd5 = getNullTerminatedStringFromDataView(dataView, contentOffset);
|
|
418
|
+
// contentOffset += entry.contentMd5.length + 1;
|
|
419
|
+
// entry.contentLength = get64BitValue(dataView, contentOffset);
|
|
420
|
+
// contentOffset += 8;
|
|
421
|
+
// entry.transferLength = get64BitValue(dataView, contentOffset);
|
|
422
|
+
// contentOffset += 8;
|
|
423
|
+
// entry.entryCount = dataView.getUint8(contentOffset);
|
|
424
|
+
// contentOffset += 1;
|
|
425
|
+
// entry.entries = [];
|
|
426
|
+
// for (let i = 0; i < entry.entryCount; i++) {
|
|
427
|
+
// entry.entries.push({groupId: dataView.getUint32(contentOffset)});
|
|
428
|
+
// contentOffset += 4;
|
|
429
|
+
// }
|
|
430
|
+
// }
|
|
431
|
+
// }
|
|
432
|
+
if (version >= 2) {
|
|
433
|
+
if (version === 2) {
|
|
434
|
+
entry.itemId = dataView.getUint16(contentOffset);
|
|
435
|
+
contentOffset += 2;
|
|
436
|
+
} else if (version === 3) {
|
|
437
|
+
entry.itemId = dataView.getUint32(contentOffset);
|
|
438
|
+
contentOffset += 4;
|
|
439
|
+
}
|
|
440
|
+
entry.itemProtectionIndex = dataView.getUint16(contentOffset);
|
|
441
|
+
contentOffset += 2;
|
|
442
|
+
// entry.itemTypeAscii = getStringFromDataView(dataView, offset, 4); // For testing.
|
|
443
|
+
entry.itemType = dataView.getUint32(contentOffset);
|
|
444
|
+
contentOffset += 4;
|
|
445
|
+
entry.itemName = getNullTerminatedStringFromDataView(dataView, contentOffset);
|
|
446
|
+
contentOffset += entry.itemName.length + 1;
|
|
447
|
+
if (entry.itemType === ITEM_INFO_TYPE_MIME) {
|
|
448
|
+
entry.contentType = getNullTerminatedStringFromDataView(dataView, contentOffset);
|
|
449
|
+
contentOffset += entry.contentType.length + 1;
|
|
450
|
+
if (startOffset + length > contentOffset) {
|
|
451
|
+
entry.contentEncoding = getNullTerminatedStringFromDataView(dataView, contentOffset);
|
|
452
|
+
contentOffset += entry.contentEncoding.length + 1;
|
|
453
|
+
}
|
|
454
|
+
} else if (entry.itemType === ITEM_INFO_TYPE_URI) {
|
|
455
|
+
entry.itemUri = getNullTerminatedStringFromDataView(dataView, contentOffset);
|
|
456
|
+
contentOffset += entry.itemUri.length + 1;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return entry;
|
|
460
|
+
}
|
package/src/image-header.js
CHANGED
|
@@ -7,6 +7,7 @@ import Tiff from './image-header-tiff.js';
|
|
|
7
7
|
import Jpeg from './image-header-jpeg.js';
|
|
8
8
|
import Png from './image-header-png.js';
|
|
9
9
|
import Heic from './image-header-heic.js';
|
|
10
|
+
import Avif from './image-header-avif.js';
|
|
10
11
|
import Webp from './image-header-webp.js';
|
|
11
12
|
import Gif from './image-header-gif.js';
|
|
12
13
|
import {objectAssign} from './utils.js';
|
|
@@ -32,6 +33,10 @@ function parseAppMarkers(dataView, async) {
|
|
|
32
33
|
return addFileType(Heic.findHeicOffsets(dataView), 'heic', 'HEIC');
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
if (Constants.USE_AVIF && Avif.isAvifFile(dataView)) {
|
|
37
|
+
return addFileType(Avif.findAvifOffsets(dataView), 'avif', 'AVIF');
|
|
38
|
+
}
|
|
39
|
+
|
|
35
40
|
if (Constants.USE_WEBP && Webp.isWebpFile(dataView)) {
|
|
36
41
|
return addFileType(Webp.findOffsets(dataView), 'webp', 'WebP');
|
|
37
42
|
}
|
package/webpack.config.js
CHANGED
|
@@ -81,7 +81,7 @@ module.exports = {
|
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
83
|
{
|
|
84
|
-
test: /\/(exif-reader|image-header-?(tiff|jpeg|png|heic|webp|gif)?|tags|tag-names)\.js$/,
|
|
84
|
+
test: /\/(exif-reader|image-header-?(tiff|jpeg|png|heic|avif|iso-bmff|webp|gif)?|tags|tag-names)\.js$/,
|
|
85
85
|
loader: 'string-replace-loader',
|
|
86
86
|
options: {
|
|
87
87
|
multiple: getConstantReplacements(includedModules)
|
|
@@ -106,6 +106,7 @@ function parseConfig({include: includesConfig, exclude: excludesConfig}) {
|
|
|
106
106
|
'jpeg',
|
|
107
107
|
'png',
|
|
108
108
|
'heic',
|
|
109
|
+
'avif',
|
|
109
110
|
'webp',
|
|
110
111
|
'gif'
|
|
111
112
|
];
|