exifreader 4.50.0 → 4.51.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.
@@ -3,7 +3,6 @@
3
3
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
4
 
5
5
  import ByteOrder from './byte-order.js';
6
- import Constants from './constants.js';
7
6
  import {TIFF_ID, TIFF_ID_OFFSET} from './tiff-constants.js';
8
7
 
9
8
  export default {
@@ -25,11 +24,8 @@ function hasTiffMarker(dataView) {
25
24
  function findTiffOffsets() {
26
25
  const TIFF_FILE_HEADER_OFFSET = 0;
27
26
 
28
- if (Constants.USE_EXIF) {
29
- return {
30
- hasAppMarkers: true,
31
- tiffHeaderOffset: TIFF_FILE_HEADER_OFFSET
32
- };
33
- }
34
- return {};
27
+ return {
28
+ hasAppMarkers: true,
29
+ tiffHeaderOffset: TIFF_FILE_HEADER_OFFSET
30
+ };
35
31
  }
@@ -3,7 +3,6 @@
3
3
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
4
 
5
5
  import {getStringFromDataView, pushMetadataBlock} from './utils.js';
6
- import Constants from './constants.js';
7
6
 
8
7
  export default {
9
8
  isWebpFile,
@@ -53,7 +52,7 @@ function findOffsets(dataView, metadataBlocks) {
53
52
  const chunkSize = dataView.getUint32(offset + CHUNK_SIZE_OFFSET, true);
54
53
  let blockType;
55
54
 
56
- if (Constants.USE_EXIF && (chunkId === 'EXIF')) {
55
+ if (chunkId === 'EXIF') {
57
56
  hasAppMarkers = true;
58
57
  if (getStringFromDataView(dataView, offset + CHUNK_HEADER_SIZE, EXIF_IDENTIFIER.length) === EXIF_IDENTIFIER) {
59
58
  tiffHeaderOffset = offset + CHUNK_HEADER_SIZE + EXIF_IDENTIFIER.length;
@@ -61,14 +60,14 @@ function findOffsets(dataView, metadataBlocks) {
61
60
  tiffHeaderOffset = offset + CHUNK_HEADER_SIZE;
62
61
  }
63
62
  blockType = 'exif';
64
- } else if (Constants.USE_XMP && (chunkId === 'XMP ')) {
63
+ } else if (chunkId === 'XMP ') {
65
64
  hasAppMarkers = true;
66
65
  xmpChunks = [{
67
66
  dataOffset: offset + CHUNK_HEADER_SIZE,
68
67
  length: chunkSize
69
68
  }];
70
69
  blockType = 'xmp';
71
- } else if (Constants.USE_ICC && (chunkId === 'ICCP')) {
70
+ } else if (chunkId === 'ICCP') {
72
71
  hasAppMarkers = true;
73
72
  iccChunks = [{
74
73
  offset: offset + CHUNK_HEADER_SIZE,
package/src/jfif-tags.js CHANGED
@@ -153,7 +153,7 @@ function getThumbnail(dataView, jfifDataOffset, thumbnailLength, length) {
153
153
  return undefined;
154
154
  }
155
155
 
156
- const byteOffset = dataView.byteOffset || 0;
156
+ const byteOffset = dataView.byteOffset;
157
157
  const value = dataView.buffer.slice(byteOffset + jfifDataOffset + OFFSET, byteOffset + jfifDataOffset + OFFSET + thumbnailLength);
158
158
  return {
159
159
  value,
package/src/load-auto.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  concatBuffers, isFilePathOrURL, isBrowserFileObject, isDataUri,
10
10
  HTTP_STATUS_OK, HTTP_STATUS_RANGE_NOT_SATISFIABLE,
11
11
  } from './file-loaders.js';
12
- import {objectAssign, dataUriToBuffer, assertPromiseSupport} from './utils.js';
12
+ import {objectAssign, dataUriToBuffer, assertPromiseSupport, isArrayBufferViewLike} from './utils.js';
13
13
 
14
14
  const AUTO_INITIAL_LENGTH = 128 * 1024;
15
15
  const AUTO_MAX_ITERATIONS = 4;
@@ -286,7 +286,7 @@ function sliceInputBuffer(data, end) {
286
286
  if (typeof SharedArrayBuffer !== 'undefined' && data instanceof SharedArrayBuffer) {
287
287
  return data.slice(0, end);
288
288
  }
289
- if (ArrayBuffer.isView(data)) {
289
+ if (isArrayBufferViewLike(data)) {
290
290
  const viewEnd = Math.max(0, Math.min(end, data.byteLength));
291
291
  return data.buffer.slice(data.byteOffset, data.byteOffset + viewEnd);
292
292
  }
package/src/mpf-tags.js CHANGED
@@ -4,7 +4,8 @@
4
4
 
5
5
  import ByteOrder from './byte-order.js';
6
6
  import Types from './types.js';
7
- import {IFD_TYPE_MPF} from './tag-names.js';
7
+ import TagNamesMpfIfd from './tag-names-mpf-ifd.js';
8
+ import {IFD_TYPE_MPF} from './ifd-types.js';
8
9
  import {deferInit, getBase64Image} from './utils.js';
9
10
  import {readIfd, get0thIfdOffset} from './tags-helpers.js';
10
11
 
@@ -48,7 +49,8 @@ function read(
48
49
  computed,
49
50
  tagFilter,
50
51
  'mpf',
51
- valueBudget
52
+ valueBudget,
53
+ getTagNames()
52
54
  );
53
55
  return addMpfImages(dataView, dataOffset, tags, byteOrder);
54
56
  } catch (error) {
@@ -56,6 +58,13 @@ function read(
56
58
  }
57
59
  }
58
60
 
61
+ // Assigned rather than a computed key, which Babel compiles to a helper call.
62
+ function getTagNames() {
63
+ const tagNames = {};
64
+ tagNames[IFD_TYPE_MPF] = TagNamesMpfIfd;
65
+ return tagNames;
66
+ }
67
+
59
68
  function addMpfImages(dataView, dataOffset, tags, byteOrder) {
60
69
  if (!tags['MPEntry']) {
61
70
  return tags;
@@ -64,7 +73,7 @@ function addMpfImages(dataView, dataOffset, tags, byteOrder) {
64
73
  // The bound is the view's own extent, not the buffer's, since the slice
65
74
  // starts at the view's byteOffset.
66
75
  const bufferLength = dataView.byteLength;
67
- const byteOffset = dataView.byteOffset || 0;
76
+ const byteOffset = dataView.byteOffset;
68
77
  let remainingImageBytes = bufferLength * MAX_IMAGE_SIZE_PER_BUFFER_SIZE;
69
78
  const images = [];
70
79
  const imageCount = Math.min(Math.ceil(tags['MPEntry'].value.length / ENTRY_SIZE), MAX_IMAGES);
@@ -10,7 +10,8 @@
10
10
  import ByteOrder from './byte-order.js';
11
11
  import {objectAssign} from './utils.js';
12
12
  import {readIfd} from './tags-helpers.js';
13
- import {IFD_TYPE_PENTAX} from './tag-names.js';
13
+ import TagNamesPentaxIfd from './tag-names-pentax-ifd.js';
14
+ import {IFD_TYPE_PENTAX} from './ifd-types.js';
14
15
 
15
16
  const BYTE_ORDER_OFFSET = 8; // Pentax5: https://exiftool.org/makernote_types.html
16
17
  const PENTAX_IFD_OFFSET = BYTE_ORDER_OFFSET + 2; // https://exiftool.org/makernote_types.html
@@ -58,7 +59,8 @@ function read(
58
59
  computed,
59
60
  tagFilter,
60
61
  'makerNotes',
61
- valueBudget
62
+ valueBudget,
63
+ getTagNames()
62
64
  );
63
65
 
64
66
  if (hasLevelInfoK3III(tags)) {
@@ -79,6 +81,13 @@ function read(
79
81
  }
80
82
  }
81
83
 
84
+ // Assigned rather than a computed key, which Babel compiles to a helper call.
85
+ function getTagNames() {
86
+ const tagNames = {};
87
+ tagNames[IFD_TYPE_PENTAX] = TagNamesPentaxIfd;
88
+ return tagNames;
89
+ }
90
+
82
91
  function hasLevelInfoK3III(tags) {
83
92
  return tags['PentaxModelID'] && tags['PentaxModelID'].value === MODEL_ID.K3_III && tags['LevelInfo'];
84
93
  }
@@ -7,9 +7,6 @@
7
7
  import {getStringValueFromArray, getStringFromDataView, decompress, setProperty, getTagKey, objectAssign, COMPRESSION_METHOD_NONE, getHexDigitValue} from './utils.js';
8
8
  import TagDecoder from './tag-decoder.js';
9
9
  import {PNG_CHUNK_LENGTH_OFFSET, PNG_CHUNK_TYPE_OFFSET, PNG_CHUNK_DATA_OFFSET, PNG_CHUNK_TYPE_SIZE, TYPE_TEXT, TYPE_ITXT, TYPE_ZTXT} from './image-header-png.js';
10
- import Tags from './tags.js';
11
- import IptcTags from './iptc-tags.js';
12
- import Constants from './constants.js';
13
10
  import {NOOP_TAG_FILTER} from './tag-filter.js';
14
11
  import {addDecompressedValueAllowance, addDecompressedIptcAllowance, takeEmbeddedExifThumbnail} from './tags-helpers.js';
15
12
 
@@ -45,6 +42,12 @@ const MAX_LANGUAGE_TAG_LENGTH = 79;
45
42
  * from: `decompressed` when the chunk was compressed, `hasIptcBlock` when the
46
43
  * file has a `Raw profile type iptc` chunk. Returns the parsed groups the Exif
47
44
  * carries, keyed by group name. No groups are read when it is not passed.
45
+ * @param {{exif?: function(DataView, number, boolean, boolean, object, object): {tags: object, byteOrder: number}, iptc?: function(DataView, number, boolean, object, object): object}} [rawProfileReaders]
46
+ * Read the decoded `Raw profile type exif` and `Raw profile type iptc`
47
+ * profiles: `exif(dataView, tiffHeaderOffset, includeUnknown, computed,
48
+ * tagFilter, valueBudget)` as Tags.read and `iptc(dataView, offset,
49
+ * includeUnknown, tagFilter, valueBudget)` as IptcTags.read. A profile
50
+ * whose reader is missing is neither decoded nor read.
48
51
  * @returns {{readTags: object, embeddedExifTags: object|undefined, embeddedIptcTags: object|undefined, embeddedExifThumbnail: object|undefined, exifCarriedGroups: object|undefined, readTagsPromise: Promise<object[]>|undefined}}
49
52
  * `readTags`, the two embedded groups, `exifCarriedGroups` and
50
53
  * `embeddedExifThumbnail` come from uncompressed chunks and are ready at
@@ -65,7 +68,8 @@ function read(
65
68
  decompressConfig,
66
69
  valueBudget,
67
70
  getThumbnail,
68
- readCarriedGroups
71
+ readCarriedGroups,
72
+ rawProfileReaders = {}
69
73
  ) {
70
74
  const tags = {};
71
75
  let embeddedExifTags;
@@ -111,7 +115,8 @@ function read(
111
115
  embeddedExifThumbnail ? undefined : getThumbnail,
112
116
  readCarriedGroups,
113
117
  false,
114
- hasIptcProfile
118
+ hasIptcProfile,
119
+ rawProfileReaders
115
120
  );
116
121
  if (rawProfileTags.embeddedExifTags) {
117
122
  embeddedExifTags = objectAssign(embeddedExifTags || {}, rawProfileTags.embeddedExifTags);
@@ -138,7 +143,8 @@ function read(
138
143
  compressedThumbnailReader,
139
144
  readCarriedGroups,
140
145
  true,
141
- hasIptcProfile
146
+ hasIptcProfile,
147
+ rawProfileReaders
142
148
  )));
143
149
 
144
150
  return {
@@ -170,7 +176,7 @@ function parseTextChunk(dataView, offset, length, type) {
170
176
  let valueChars;
171
177
  let parsingState = STATE_KEYWORD;
172
178
  let compressionMethod = COMPRESSION_METHOD_NONE;
173
- const byteOffset = dataView.byteOffset || 0;
179
+ const byteOffset = dataView.byteOffset;
174
180
  const chunkEnd = Math.min(offset + length, dataView.byteLength);
175
181
 
176
182
  for (let i = 0; i < length && offset + i < dataView.byteLength; i++) {
@@ -183,9 +189,7 @@ function parseTextChunk(dataView, offset, length, type) {
183
189
  continue;
184
190
  } else if (parsingState === STATE_TEXT) {
185
191
  const slice = dataView.buffer.slice(byteOffset + offset + i, byteOffset + offset + length);
186
- // On the Node Buffer wrapper, slice() returns a Buffer, which DataView
187
- // rejects. Uint8Array copies a Buffer and leaves an ArrayBuffer as is.
188
- valueChars = new DataView(new Uint8Array(slice).buffer);
192
+ valueChars = new DataView(slice);
189
193
  break;
190
194
  }
191
195
  const byte = dataView.getUint8(offset + i);
@@ -216,17 +220,17 @@ function isRawProfileTag({name, value}) {
216
220
  return isExifGroupTag(name, value) || isIptcGroupTag(name, value);
217
221
  }
218
222
 
219
- function getTagsFromTextTag({name, value, description}, includeUnknown, computed, tagFilter, valueBudget, getThumbnail, readCarriedGroups, isDecompressed, hasIptcProfile) {
223
+ function getTagsFromTextTag({name, value, description}, includeUnknown, computed, tagFilter, valueBudget, getThumbnail, readCarriedGroups, isDecompressed, hasIptcProfile, rawProfileReaders) {
220
224
  try {
221
- if (Constants.USE_EXIF && isExifGroupTag(name, value)) {
222
- if (!tagFilter.shouldParseGroup('exif')) {
225
+ if (isExifGroupTag(name, value)) {
226
+ if (!rawProfileReaders.exif || !tagFilter.shouldParseGroup('exif')) {
223
227
  return {};
224
228
  }
225
229
  const exifDataView = decodeRawData(value);
226
230
  if (isDecompressed) {
227
231
  addDecompressedValueAllowance(valueBudget, exifDataView.byteLength);
228
232
  }
229
- const {tags: embeddedExifTags, byteOrder} = Tags.read(
233
+ const {tags: embeddedExifTags, byteOrder} = rawProfileReaders.exif(
230
234
  exifDataView,
231
235
  EXIF_OFFSET,
232
236
  includeUnknown,
@@ -253,8 +257,8 @@ function getTagsFromTextTag({name, value, description}, includeUnknown, computed
253
257
  result.embeddedExifThumbnail = thumbnail;
254
258
  }
255
259
  return result;
256
- } else if (Constants.USE_IPTC && isIptcGroupTag(name, value)) {
257
- if (!tagFilter.shouldParseGroup('iptc')) {
260
+ } else if (isIptcGroupTag(name, value)) {
261
+ if (!rawProfileReaders.iptc || !tagFilter.shouldParseGroup('iptc')) {
258
262
  return {};
259
263
  }
260
264
  const iptcDataView = decodeRawData(value);
@@ -262,7 +266,7 @@ function getTagsFromTextTag({name, value, description}, includeUnknown, computed
262
266
  addDecompressedIptcAllowance(valueBudget, iptcDataView.byteLength);
263
267
  }
264
268
  return {
265
- embeddedIptcTags: IptcTags.read(
269
+ embeddedIptcTags: rawProfileReaders.iptc(
266
270
  iptcDataView,
267
271
  0,
268
272
  includeUnknown,
@@ -270,7 +274,7 @@ function getTagsFromTextTag({name, value, description}, includeUnknown, computed
270
274
  valueBudget
271
275
  )
272
276
  };
273
- } else if (name && !isExifGroupTag(name, value) && !isIptcGroupTag(name, value)) {
277
+ } else if (name) {
274
278
  if (!tagFilter.shouldParseGroup('png')) {
275
279
  return {};
276
280
  }
@@ -175,12 +175,7 @@ export default {
175
175
  }
176
176
  return 'Unknown';
177
177
  },
178
- FocalLengthIn35mmFilm(value) {
179
- if (value === 0) {
180
- return 'Unknown';
181
- }
182
- return value + ' mm';
183
- },
178
+ FocalLengthIn35mmFilm,
184
179
  SceneCaptureType(value) {
185
180
  if (value === 0) {
186
181
  return 'Standard';
@@ -237,3 +232,10 @@ function getComponentText(component) {
237
232
  return 'B';
238
233
  }
239
234
  }
235
+
236
+ export function FocalLengthIn35mmFilm(value) {
237
+ if (value === 0) {
238
+ return 'Unknown';
239
+ }
240
+ return value + ' mm';
241
+ }
package/src/tag-names.js CHANGED
@@ -3,7 +3,6 @@
3
3
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
4
 
5
5
  import {objectAssign} from './utils.js';
6
- import Constants from './constants.js';
7
6
  import TagNames0thIfd from './tag-names-0th-ifd.js';
8
7
  import TagNamesExifIfd from './tag-names-exif-ifd.js';
9
8
  import TagNamesGpsIfd from './tag-names-gps-ifd.js';
@@ -11,25 +10,37 @@ import TagNamesInteroperabilityIfd from './tag-names-interoperability-ifd.js';
11
10
  import TagNamesMpfIfd from './tag-names-mpf-ifd.js';
12
11
  import TagNamesCanonIfd from './tag-names-canon-ifd.js';
13
12
  import TagNamesPentaxIfd from './tag-names-pentax-ifd.js';
13
+ import {
14
+ IFD_TYPE_0TH,
15
+ IFD_TYPE_1ST,
16
+ IFD_TYPE_EXIF,
17
+ IFD_TYPE_GPS,
18
+ IFD_TYPE_INTEROPERABILITY,
19
+ IFD_TYPE_MPF,
20
+ IFD_TYPE_CANON,
21
+ IFD_TYPE_PENTAX
22
+ } from './ifd-types.js';
14
23
 
15
- const tagNames0thExifIfds = Constants.USE_EXIF ? objectAssign({}, TagNames0thIfd, TagNamesExifIfd) : {};
24
+ const tagNames0thExifIfds = objectAssign({}, TagNames0thIfd, TagNamesExifIfd);
16
25
 
17
- export const IFD_TYPE_0TH = '0th';
18
- export const IFD_TYPE_1ST = '1st';
19
- export const IFD_TYPE_EXIF = 'exif';
20
- export const IFD_TYPE_GPS = 'gps';
21
- export const IFD_TYPE_INTEROPERABILITY = 'interoperability';
22
- export const IFD_TYPE_MPF = 'mpf';
23
- export const IFD_TYPE_CANON = 'canon';
24
- export const IFD_TYPE_PENTAX = 'pentax';
26
+ export {
27
+ IFD_TYPE_0TH,
28
+ IFD_TYPE_1ST,
29
+ IFD_TYPE_EXIF,
30
+ IFD_TYPE_GPS,
31
+ IFD_TYPE_INTEROPERABILITY,
32
+ IFD_TYPE_MPF,
33
+ IFD_TYPE_CANON,
34
+ IFD_TYPE_PENTAX
35
+ };
25
36
 
26
37
  export default {
27
38
  [IFD_TYPE_0TH]: tagNames0thExifIfds,
28
- [IFD_TYPE_1ST]: Constants.USE_EXIF ? TagNames0thIfd : {},
39
+ [IFD_TYPE_1ST]: TagNames0thIfd,
29
40
  [IFD_TYPE_EXIF]: tagNames0thExifIfds,
30
- [IFD_TYPE_GPS]: Constants.USE_EXIF ? TagNamesGpsIfd : {},
31
- [IFD_TYPE_INTEROPERABILITY]: Constants.USE_EXIF ? TagNamesInteroperabilityIfd : {},
32
- [IFD_TYPE_MPF]: Constants.USE_MPF ? TagNamesMpfIfd : {},
33
- [IFD_TYPE_CANON]: Constants.USE_MAKER_NOTES ? TagNamesCanonIfd : {},
34
- [IFD_TYPE_PENTAX]: Constants.USE_MAKER_NOTES ? TagNamesPentaxIfd : {},
41
+ [IFD_TYPE_GPS]: TagNamesGpsIfd,
42
+ [IFD_TYPE_INTEROPERABILITY]: TagNamesInteroperabilityIfd,
43
+ [IFD_TYPE_MPF]: TagNamesMpfIfd,
44
+ [IFD_TYPE_CANON]: TagNamesCanonIfd,
45
+ [IFD_TYPE_PENTAX]: TagNamesPentaxIfd,
35
46
  };
@@ -2,9 +2,8 @@
2
2
  * License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
4
 
5
- import Constants from './constants.js';
6
5
  import Types from './types.js';
7
- import TagNames, {IFD_TYPE_0TH, IFD_TYPE_1ST, IFD_TYPE_PENTAX} from './tag-names.js';
6
+ import {IFD_TYPE_0TH, IFD_TYPE_1ST, IFD_TYPE_PENTAX} from './ifd-types.js';
8
7
  import {IFD_ENTRY_LENGTH, TIFF_HEADER_LENGTH, TIFF_IFD_OFFSET_OFFSET} from './tiff-constants.js';
9
8
  import {NOOP_TAG_FILTER} from './tag-filter.js';
10
9
  import {decodeUtf8ByteString, getByteString} from './utils.js';
@@ -86,7 +85,7 @@ export function get0thIfdOffset(dataView, tiffHeaderOffset, byteOrder) {
86
85
 
87
86
  /**
88
87
  * Reads the tags of an IFD, and for a 0th IFD also those of the thumbnail IFD
89
- * it points to.
88
+ * it points to when readThumbnailIfd is set.
90
89
  *
91
90
  * @param {{remaining: number, ifdEntriesRemaining: number, decompressedAllowanceRemaining: number}} [valueBudget] -
92
91
  * Caps the total size of the decoded tag values and the number of IFD entries
@@ -95,6 +94,13 @@ export function get0thIfdOffset(dataView, tiffHeaderOffset, byteOrder) {
95
94
  * out, later entries and IFDs are not read, so their tags are absent rather than
96
95
  * empty, and an IFD cut short does not follow its next-IFD offset. Nor does one
97
96
  * whose next-IFD offset points into the TIFF header.
97
+ * @param {Object} tagNames - Tag dictionaries keyed by IFD type, then by tag code,
98
+ * passed in so that a caller composing its own does not bundle every dictionary.
99
+ * Every IFD type read needs a dictionary, `{}` if empty; a missing one throws.
100
+ * @param {boolean} [readThumbnailIfd] - Whether a 0th IFD follows its next-IFD
101
+ * offset into the thumbnail IFD, whose entries are otherwise not charged to the
102
+ * value budget. Defaults to whether tagNames has an IFD_TYPE_1ST dictionary and
103
+ * tagFilter parses the thumbnail group.
98
104
  * @returns {Object} The read tags, keyed by tag name.
99
105
  */
100
106
  export function readIfd(
@@ -107,7 +113,9 @@ export function readIfd(
107
113
  computed = false,
108
114
  tagFilter = NOOP_TAG_FILTER,
109
115
  groupKey = 'exif',
110
- valueBudget = getValueBudget(dataView)
116
+ valueBudget = getValueBudget(dataView),
117
+ tagNames,
118
+ readThumbnailIfd = tagNames[IFD_TYPE_1ST] !== undefined && tagFilter.shouldParseGroup('thumbnail')
111
119
  ) {
112
120
  const FIELD_COUNT_SIZE = Types.getTypeSize('SHORT');
113
121
  const FIELD_SIZE = IFD_ENTRY_LENGTH;
@@ -136,7 +144,8 @@ export function readIfd(
136
144
  includeUnknown,
137
145
  tagFilter,
138
146
  groupKey,
139
- valueBudget
147
+ valueBudget,
148
+ tagNames
140
149
  );
141
150
  if (tag !== undefined) {
142
151
  tags[tag.name] = {
@@ -155,23 +164,22 @@ export function readIfd(
155
164
  offset += FIELD_SIZE;
156
165
  }
157
166
 
158
- if (Constants.USE_THUMBNAIL && !ranOutOfIfdEntries && (offset + Types.getTypeSize('LONG') <= dataView.byteLength)) {
167
+ if (readThumbnailIfd && !ranOutOfIfdEntries && (offset + Types.getTypeSize('LONG') <= dataView.byteLength)) {
159
168
  const nextIfdOffset = Types.getLongAt(dataView, offset, byteOrder);
160
169
  if (nextIfdOffset >= TIFF_HEADER_LENGTH && ifdType === IFD_TYPE_0TH) {
161
- if (tagFilter.shouldParseGroup('thumbnail')) {
162
- tags['Thumbnail'] = readIfd(
163
- dataView,
164
- IFD_TYPE_1ST,
165
- offsetOrigin,
166
- offsetOrigin + nextIfdOffset,
167
- byteOrder,
168
- includeUnknown,
169
- computed,
170
- tagFilter,
171
- 'thumbnail',
172
- valueBudget
173
- );
174
- }
170
+ tags['Thumbnail'] = readIfd(
171
+ dataView,
172
+ IFD_TYPE_1ST,
173
+ offsetOrigin,
174
+ offsetOrigin + nextIfdOffset,
175
+ byteOrder,
176
+ includeUnknown,
177
+ computed,
178
+ tagFilter,
179
+ 'thumbnail',
180
+ valueBudget,
181
+ tagNames
182
+ );
175
183
  }
176
184
  }
177
185
 
@@ -293,7 +301,8 @@ function readTag(
293
301
  includeUnknown = false,
294
302
  tagFilter = NOOP_TAG_FILTER,
295
303
  groupKey = 'exif',
296
- valueBudget
304
+ valueBudget,
305
+ tagNames
297
306
  ) {
298
307
  const TAG_CODE_IPTC_NAA = 0x83bb;
299
308
  const TAG_TYPE_OFFSET = Types.getTypeSize('SHORT');
@@ -307,11 +316,11 @@ function readTag(
307
316
  let tagValueOffset;
308
317
  let stringBudget;
309
318
 
310
- if (Types.typeSizes[tagType] === undefined || (!includeUnknown && TagNames[ifdType][tagCode] === undefined)) {
319
+ if (Types.typeSizes[tagType] === undefined || (!includeUnknown && tagNames[ifdType][tagCode] === undefined)) {
311
320
  return undefined;
312
321
  }
313
322
 
314
- const tagName = getTagName(ifdType, tagCode);
323
+ const tagName = getTagName(ifdType, tagCode, tagNames);
315
324
  if (!tagFilter.shouldParseTag(groupKey, tagName, tagCode)) {
316
325
  return undefined;
317
326
  }
@@ -338,10 +347,10 @@ function readTag(
338
347
 
339
348
  let tagDescription = tagValue;
340
349
 
341
- if (TagNames[ifdType][tagCode] !== undefined) {
342
- if ((TagNames[ifdType][tagCode]['name'] !== undefined) && (TagNames[ifdType][tagCode]['description'] !== undefined)) {
350
+ if (tagNames[ifdType][tagCode] !== undefined) {
351
+ if ((tagNames[ifdType][tagCode]['name'] !== undefined) && (tagNames[ifdType][tagCode]['description'] !== undefined)) {
343
352
  try {
344
- tagDescription = TagNames[ifdType][tagCode]['description'](tagValue);
353
+ tagDescription = tagNames[ifdType][tagCode]['description'](tagValue);
345
354
  } catch (error) {
346
355
  tagDescription = getDescriptionFromTagValue(tagValue);
347
356
  }
@@ -362,13 +371,13 @@ function readTag(
362
371
  };
363
372
  }
364
373
 
365
- function getTagName(ifdType, tagCode) {
366
- if (TagNames[ifdType][tagCode] !== undefined) {
367
- if (typeof TagNames[ifdType][tagCode] === 'string') {
368
- return TagNames[ifdType][tagCode];
374
+ function getTagName(ifdType, tagCode, tagNames) {
375
+ if (tagNames[ifdType][tagCode] !== undefined) {
376
+ if (typeof tagNames[ifdType][tagCode] === 'string') {
377
+ return tagNames[ifdType][tagCode];
369
378
  }
370
- if (TagNames[ifdType][tagCode].name) {
371
- return TagNames[ifdType][tagCode].name;
379
+ if (tagNames[ifdType][tagCode].name) {
380
+ return tagNames[ifdType][tagCode].name;
372
381
  }
373
382
  }
374
383
 
package/src/tags.js CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  import {objectAssign} from './utils.js';
6
6
  import ByteOrder from './byte-order.js';
7
- import {IFD_TYPE_0TH, IFD_TYPE_EXIF, IFD_TYPE_GPS, IFD_TYPE_INTEROPERABILITY} from './tag-names.js';
7
+ import {IFD_TYPE_0TH, IFD_TYPE_EXIF, IFD_TYPE_GPS, IFD_TYPE_INTEROPERABILITY} from './ifd-types.js';
8
8
  import {readIfd, get0thIfdOffset, getValueBudget} from './tags-helpers.js';
9
9
  import {TIFF_HEADER_LENGTH} from './tiff-constants.js';
10
10
 
@@ -28,18 +28,20 @@ function read(
28
28
  includeUnknown,
29
29
  computed = false,
30
30
  tagFilter = undefined,
31
- valueBudget = getValueBudget(dataView)
31
+ valueBudget = getValueBudget(dataView),
32
+ tagNames = undefined,
33
+ readThumbnailIfd = undefined
32
34
  ) {
33
35
  const byteOrder = ByteOrder.getByteOrder(dataView, tiffHeaderOffset);
34
- let tags = read0thIfd(dataView, tiffHeaderOffset, byteOrder, includeUnknown, computed, tagFilter, valueBudget);
36
+ let tags = read0thIfd(dataView, tiffHeaderOffset, byteOrder, includeUnknown, computed, tagFilter, valueBudget, tagNames, readThumbnailIfd);
35
37
  for (let i = 0; i < SUB_IFDS.length; i++) {
36
- tags = readSubIfd(SUB_IFDS[i], tags, dataView, tiffHeaderOffset, byteOrder, includeUnknown, computed, tagFilter, valueBudget);
38
+ tags = readSubIfd(SUB_IFDS[i], tags, dataView, tiffHeaderOffset, byteOrder, includeUnknown, computed, tagFilter, valueBudget, tagNames);
37
39
  }
38
40
 
39
41
  return {tags, byteOrder};
40
42
  }
41
43
 
42
- function read0thIfd(dataView, tiffHeaderOffset, byteOrder, includeUnknown, computed, tagFilter, valueBudget) {
44
+ function read0thIfd(dataView, tiffHeaderOffset, byteOrder, includeUnknown, computed, tagFilter, valueBudget, tagNames, readThumbnailIfd) {
43
45
  const ifdOffset = get0thIfdOffset(dataView, tiffHeaderOffset, byteOrder);
44
46
  if (ifdOffset === undefined) {
45
47
  return {};
@@ -54,11 +56,13 @@ function read0thIfd(dataView, tiffHeaderOffset, byteOrder, includeUnknown, compu
54
56
  computed,
55
57
  tagFilter,
56
58
  'exif',
57
- valueBudget
59
+ valueBudget,
60
+ tagNames,
61
+ readThumbnailIfd
58
62
  );
59
63
  }
60
64
 
61
- function readSubIfd(subIfd, tags, dataView, tiffHeaderOffset, byteOrder, includeUnknown, computed, tagFilter, valueBudget) {
65
+ function readSubIfd(subIfd, tags, dataView, tiffHeaderOffset, byteOrder, includeUnknown, computed, tagFilter, valueBudget, tagNames) {
62
66
  const pointerTag = tags[subIfd.pointerKey];
63
67
  if (pointerTag === undefined) {
64
68
  return tags;
@@ -81,7 +85,8 @@ function readSubIfd(subIfd, tags, dataView, tiffHeaderOffset, byteOrder, include
81
85
  computed,
82
86
  tagFilter,
83
87
  'exif',
84
- valueBudget
88
+ valueBudget,
89
+ tagNames
85
90
  )
86
91
  );
87
92
  }
package/src/thumbnail.js CHANGED
@@ -18,7 +18,7 @@ function get(dataView, thumbnailTags, tiffHeaderOffset) {
18
18
 
19
19
  if (fitsInDataView(dataView, offset, length)) {
20
20
  thumbnailTags.type = 'image/jpeg';
21
- const byteOffset = dataView.byteOffset || 0;
21
+ const byteOffset = dataView.byteOffset;
22
22
  thumbnailTags.image = dataView.buffer.slice(byteOffset + offset, byteOffset + offset + length);
23
23
  deferInit(thumbnailTags, 'base64', function () {
24
24
  return getBase64Image(this.image);
package/src/utils.js CHANGED
@@ -2,16 +2,38 @@
2
2
  * License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
4
 
5
- import DataViewWrapper from './dataview.js';
6
-
7
5
  export function getDataView(data, byteOffset, byteLength) {
6
+ return new DataView(data, byteOffset, byteLength);
7
+ }
8
+
9
+ /**
10
+ * Views the bytes of an ArrayBuffer, a SharedArrayBuffer, any typed array (a
11
+ * Node Buffer included) or a DataView, without copying them.
12
+ * @param {ArrayBuffer|SharedArrayBuffer|ArrayBufferView} data
13
+ * @returns {DataView} A view over the same bytes as `data`.
14
+ * @throws {TypeError} If `data` is none of the accepted types.
15
+ */
16
+ export function getDataViewFromBytes(data) {
17
+ if (isArrayBufferViewLike(data)) {
18
+ return new DataView(data.buffer, data.byteOffset, data.byteLength);
19
+ }
8
20
  try {
9
- return new DataView(data, byteOffset, byteLength);
21
+ return new DataView(data);
10
22
  } catch (error) {
11
- return new DataViewWrapper(data, byteOffset, byteLength);
23
+ throw new TypeError('Passed data type is unsupported. Pass an ArrayBuffer, SharedArrayBuffer, DataView, a typed array such as a Uint8Array or Node Buffer, or a File.');
12
24
  }
13
25
  }
14
26
 
27
+ /**
28
+ * Tells a typed array or DataView by its shape: older runtimes lack the native check.
29
+ */
30
+ export function isArrayBufferViewLike(data) {
31
+ return !!data
32
+ && !!data.buffer
33
+ && (typeof data.byteOffset === 'number')
34
+ && (typeof data.byteLength === 'number');
35
+ }
36
+
15
37
  export function getStringFromDataView(dataView, offset, length) {
16
38
  const chars = [];
17
39
  for (let i = 0; i < length && offset + i < dataView.byteLength; i++) {
package/src/xmp-tags.js CHANGED
@@ -109,15 +109,13 @@ function combineChunks(dataView, chunks) {
109
109
  // A chunk length comes verbatim from the image and is not trusted. Bound it to
110
110
  // the bytes actually present so a crafted length cannot force a huge allocation.
111
111
  function getBoundedChunkBytes(dataView, chunk) {
112
- // The bound is the view's own extent, not the buffer's, since the slice
113
- // starts at the view's byteOffset.
114
- // dataView can be a DataViewWrapper whose buffer is a Buffer, which a
115
- // Uint8Array view constructor would copy whole, so the bytes come from slice.
112
+ // The bound is the view's own extent, not the buffer's, since the bytes
113
+ // start at the view's byteOffset.
116
114
  const bufferLength = dataView.byteLength;
117
- const byteOffset = dataView.byteOffset || 0;
115
+ const byteOffset = dataView.byteOffset;
118
116
  const start = Math.min(Math.max(chunk.dataOffset, 0), bufferLength);
119
117
  const end = Math.min(start + Math.max(chunk.length, 0), bufferLength);
120
- return new Uint8Array(dataView.buffer.slice(byteOffset + start, byteOffset + end));
118
+ return new Uint8Array(dataView.buffer, byteOffset + start, end - start);
121
119
  }
122
120
 
123
121
  function readTags(tags, chunkDataView, domParser) {
package/webpack.config.js CHANGED
@@ -83,7 +83,7 @@ module.exports = {
83
83
  }
84
84
  },
85
85
  {
86
- test: /[/\\](exif-reader|image-header-?(tiff|jpeg|png|heic|avif|jxl|iso-bmff|webp|gif)?|tags|tag-names|tags-helpers|png-text-tags|loadview-pipeline)\.js$/,
86
+ test: /[/\\](exif-reader|image-header|loadview-pipeline)\.js$/,
87
87
  loader: 'string-replace-loader',
88
88
  options: {
89
89
  multiple: getConstantReplacements(includedModules)