exifreader 4.53.0 → 4.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +404 -33
  2. package/bin/analyze.js +139 -9
  3. package/bin/build-pages.js +21 -35
  4. package/bin/cli.js +81 -13
  5. package/bin/generate-tag-modules.js +287 -0
  6. package/dist/exif-reader.js +1 -1
  7. package/dist/exif-reader.js.map +1 -1
  8. package/exif-reader.d.ts +213 -38
  9. package/package.json +71 -11
  10. package/src/base64-image.js +27 -0
  11. package/src/composable/brand.js +10 -0
  12. package/src/composable/composition-tag-filter.js +97 -0
  13. package/src/composable/composition.js +195 -0
  14. package/src/composable/core.d.ts +148 -0
  15. package/src/composable/core.js +526 -0
  16. package/src/composable/exif-block-reader.js +197 -0
  17. package/src/composable/formats/avif.js +19 -0
  18. package/src/composable/formats/gif.js +28 -0
  19. package/src/composable/formats/heic.js +19 -0
  20. package/src/composable/formats/iso-bmff-file-reader.js +14 -0
  21. package/src/composable/formats/jpeg.js +55 -0
  22. package/src/composable/formats/jxl.js +30 -0
  23. package/src/composable/formats/png.js +187 -0
  24. package/src/composable/formats/tiff.js +18 -0
  25. package/src/composable/formats/webp.js +28 -0
  26. package/src/composable/formats/xml.js +18 -0
  27. package/src/composable/formats.d.ts +17 -0
  28. package/src/composable/formats.js +17 -0
  29. package/src/composable/group-helpers.js +129 -0
  30. package/src/composable/groups/canon.js +26 -0
  31. package/src/composable/groups/composite.js +43 -0
  32. package/src/composable/groups/exif.js +48 -0
  33. package/src/composable/groups/gps.js +75 -0
  34. package/src/composable/groups/icc.js +52 -0
  35. package/src/composable/groups/iptc.js +86 -0
  36. package/src/composable/groups/maker-notes.js +21 -0
  37. package/src/composable/groups/mpf.js +25 -0
  38. package/src/composable/groups/pentax.js +34 -0
  39. package/src/composable/groups/photoshop.js +18 -0
  40. package/src/composable/groups/thumbnail.js +131 -0
  41. package/src/composable/groups/xmp.js +118 -0
  42. package/src/composable/groups.d.ts +20 -0
  43. package/src/composable/groups.js +105 -0
  44. package/src/composable/iptc-block-reader.js +44 -0
  45. package/src/composable/read-view.js +165 -0
  46. package/src/composable/tag-binding-name.js +17 -0
  47. package/src/composable/tags/exif.d.ts +295 -0
  48. package/src/composable/tags/exif.js +396 -0
  49. package/src/composable/tags/iptc.d.ts +84 -0
  50. package/src/composable/tags/iptc.js +109 -0
  51. package/src/composable/value-budget.js +24 -0
  52. package/src/composite.js +2 -2
  53. package/src/decompression.js +60 -0
  54. package/src/dom-parser.js +5 -6
  55. package/src/engine.js +332 -0
  56. package/src/errors.js +8 -2
  57. package/src/exif-reader.d.ts +8 -0
  58. package/src/exif-reader.js +118 -1121
  59. package/src/file-loaders.js +74 -1
  60. package/src/file-tags.js +9 -9
  61. package/src/image-header-avif.js +7 -8
  62. package/src/image-header-gif.js +9 -10
  63. package/src/image-header-heic.js +7 -8
  64. package/src/image-header-iso-bmff.js +71 -92
  65. package/src/image-header-jpeg.js +60 -59
  66. package/src/image-header-jxl.js +59 -65
  67. package/src/image-header-png.js +199 -76
  68. package/src/image-header-tiff.js +7 -4
  69. package/src/image-header-webp.js +29 -35
  70. package/src/image-header.js +25 -59
  71. package/src/iptc-tag-names-descriptions.js +334 -0
  72. package/src/iptc-tag-names.js +50 -306
  73. package/src/iptc-tags.js +41 -27
  74. package/src/jfif-tags.js +9 -9
  75. package/src/load-auto.js +2 -2
  76. package/src/loadview-pipeline.js +197 -498
  77. package/src/mpf-tags.js +10 -7
  78. package/src/node-require.js +15 -2
  79. package/src/png-text-tags.js +90 -327
  80. package/src/tag-filter-config.js +24 -15
  81. package/src/tag-filter.js +67 -3
  82. package/src/tag-names-0th-ifd-descriptions.js +232 -0
  83. package/src/tag-names-0th-ifd.js +49 -173
  84. package/src/tag-names-common.js +263 -211
  85. package/src/tag-names-exif-ifd-descriptions.js +249 -0
  86. package/src/tag-names-exif-ifd.js +55 -187
  87. package/src/tag-names-gps-ifd-descriptions.js +156 -0
  88. package/src/tag-names-gps-ifd.js +39 -146
  89. package/src/tag-names-utils.js +33 -10
  90. package/src/tags-helpers.js +14 -24
  91. package/src/tags.js +23 -11
  92. package/src/thumbnail.js +7 -5
  93. package/src/types.js +2 -0
  94. package/src/unsupported-format-error.js +21 -0
  95. package/src/utils.js +64 -119
  96. package/src/writer/exif-tag-table.js +321 -0
  97. package/src/xml.js +12 -15
  98. package/src/xmp-tag-names.js +42 -21
  99. package/src/xmp-tags.js +9 -10
  100. package/webpack.config.js +1 -1
package/src/mpf-tags.js CHANGED
@@ -6,7 +6,7 @@ import ByteOrder from './byte-order.js';
6
6
  import Types from './types.js';
7
7
  import TagNamesMpfIfd from './tag-names-mpf-ifd.js';
8
8
  import {IFD_TYPE_MPF} from './ifd-types.js';
9
- import {deferInit, getBase64Image} from './utils.js';
9
+ import {deferInit} from './utils.js';
10
10
  import {readIfd, get0thIfdOffset} from './tags-helpers.js';
11
11
 
12
12
  export default {
@@ -31,7 +31,8 @@ function read(
31
31
  includeUnknown,
32
32
  computed = false,
33
33
  tagFilter = undefined,
34
- valueBudget = undefined
34
+ valueBudget = undefined,
35
+ getBase64Image = undefined
35
36
  ) {
36
37
  try {
37
38
  const byteOrder = ByteOrder.getByteOrder(dataView, dataOffset);
@@ -52,7 +53,7 @@ function read(
52
53
  valueBudget,
53
54
  getTagNames()
54
55
  );
55
- return addMpfImages(dataView, dataOffset, tags, byteOrder);
56
+ return addMpfImages(dataView, dataOffset, tags, byteOrder, getBase64Image);
56
57
  } catch (error) {
57
58
  return {};
58
59
  }
@@ -65,7 +66,7 @@ function getTagNames() {
65
66
  return tagNames;
66
67
  }
67
68
 
68
- function addMpfImages(dataView, dataOffset, tags, byteOrder) {
69
+ function addMpfImages(dataView, dataOffset, tags, byteOrder, getBase64Image) {
69
70
  if (!tags['MPEntry']) {
70
71
  return tags;
71
72
  }
@@ -115,9 +116,11 @@ function addMpfImages(dataView, dataOffset, tags, byteOrder) {
115
116
  const end = Math.min(start + Math.max(imageSize, 0), bufferLength, start + remainingImageBytes);
116
117
  images[i].image = dataView.buffer.slice(byteOffset + start, byteOffset + end);
117
118
  remainingImageBytes -= end - start;
118
- deferInit(images[i], 'base64', function () {
119
- return getBase64Image(this.image);
120
- });
119
+ if (getBase64Image) {
120
+ deferInit(images[i], 'base64', function () {
121
+ return getBase64Image(this.image);
122
+ });
123
+ }
121
124
  }
122
125
 
123
126
  tags['Images'] = images;
@@ -35,11 +35,15 @@ function optionalPackage(name) {
35
35
  // A loader throws where its mechanism is missing (no process, no
36
36
  // getBuiltinModule, no mainModule), which moves on to the next one. process is
37
37
  // never named as a free variable: Parcel 2 and webpack 4 would then bundle a
38
- // process polyfill into browser builds of the source.
38
+ // process polyfill into browser builds of the source. The empty object a
39
+ // bundler gives for a module the browser field maps to false also moves on.
39
40
  function firstLoaded(name, loaders) {
40
41
  for (let i = 0; i < loaders.length; i++) {
41
42
  try {
42
- return loaders[i](name);
43
+ const loaded = loaders[i](name);
44
+ if (!isEmptyStub(loaded)) {
45
+ return loaded;
46
+ }
43
47
  } catch (error) {
44
48
  // Try the next loader.
45
49
  }
@@ -47,6 +51,15 @@ function firstLoaded(name, loaders) {
47
51
  return undefined;
48
52
  }
49
53
 
54
+ // Not typeof 'object': Babel would inline its _typeof helper into this module for that.
55
+ function isEmptyStub(loaded) {
56
+ if (Object(loaded) !== loaded) {
57
+ return false;
58
+ }
59
+ const prototype = Object.getPrototypeOf(loaded);
60
+ return (prototype === Object.prototype || prototype === null) && Object.keys(loaded).length === 0;
61
+ }
62
+
50
63
  // Literal names make webpack emit require('fs') and so on, which bundlers and
51
64
  // file tracers follow. No typeof guard: webpack may not rewrite the identifier there.
52
65
  // A try in this function makes bundlers treat fs, @xmldom/xmldom and its package.json as optional.
@@ -4,355 +4,127 @@
4
4
 
5
5
  // Specification: http://www.libpng.org/pub/png/spec/1.2/
6
6
 
7
- import {getStringValueFromArray, getStringFromDataView, decompress, setProperty, getTagKey, objectAssign, COMPRESSION_METHOD_NONE, getHexDigitValue} from './utils.js';
7
+ import {getStringFromDataView, decompress, getCompressionMethod, setProperty, getTagKey, COMPRESSION_METHOD_NONE, getHexDigitValue} from './utils.js';
8
8
  import TagDecoder from './tag-decoder.js';
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 {NOOP_TAG_FILTER} from './tag-filter.js';
11
- import {addDecompressedValueAllowance, addDecompressedIptcAllowance, takeEmbeddedExifThumbnail} from './tags-helpers.js';
9
+ import {TYPE_TEXT, TYPE_ITXT, TYPE_ZTXT, EXIF_PROFILE_NAME, IPTC_PROFILE_NAME} from './image-header-png.js';
10
+ import {filterTagsForParse} from './tag-filter.js';
12
11
 
13
12
  export default {
14
13
  read
15
14
  };
16
15
 
17
- const STATE_KEYWORD = 'STATE_KEYWORD';
18
- const STATE_COMPRESSION = 'STATE_COMPRESSION';
19
- const STATE_LANG = 'STATE_LANG';
20
- const STATE_TRANSLATED_KEYWORD = 'STATE_TRANSLATED_KEYWORD';
21
- const STATE_TEXT = 'STATE_TEXT';
22
- const COMPRESSION_SECTION_ITXT_EXTRA_BYTE = 1;
23
- const COMPRESSION_FLAG_COMPRESSED = 1;
24
16
  const EXIF_OFFSET = 6;
25
17
  const MAX_COMPRESSED_TEXT_CHUNKS = 255;
26
- const MAX_DECOMPRESSIONS_IN_FLIGHT = 4;
27
- // PNG spec: a keyword is 1-79 bytes.
28
- const MAX_KEYWORD_LENGTH = 79;
29
- const IPTC_PROFILE_NAME = 'raw profile type iptc';
30
- // Our own bound: BCP 47 sets no maximum, but real tags are far shorter.
31
- const MAX_LANGUAGE_TAG_LENGTH = 79;
32
18
 
33
19
  /**
34
- * @param {number[]} pngTextChunks Chunk start offsets, where each chunk's length field is.
35
- * @param {function(DataView, object, number): object} [getThumbnail] Called with a
36
- * decoded Exif raw profile, its thumbnail IFD tags and the TIFF header offset;
37
- * returns the thumbnail tags, with `image` set when the thumbnail was read.
38
- * No thumbnail is returned when it is not passed.
39
- * @param {function(DataView, object, number, number, object, {decompressed: boolean, hasIptcBlock: boolean}): object} [readCarriedGroups]
40
- * Called with a decoded Exif raw profile, the Exif tags read from it, the TIFF
41
- * header offset, the byte order, the value budget and where the profile came
42
- * from: `decompressed` when the chunk was compressed, `hasIptcBlock` when the
43
- * file has a `Raw profile type iptc` chunk. Returns the parsed groups the Exif
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.
51
- * @returns {{readTags: object, embeddedExifTags: object|undefined, embeddedIptcTags: object|undefined, embeddedExifThumbnail: object|undefined, exifCarriedGroups: object|undefined, readTagsPromise: Promise<object[]>|undefined}}
52
- * `readTags`, the two embedded groups, `exifCarriedGroups` and
53
- * `embeddedExifThumbnail` come from uncompressed chunks and are ready at
54
- * once; the embedded groups and `exifCarriedGroups` are undefined when no
55
- * uncompressed raw profile was parsed, and `embeddedExifThumbnail` is the
56
- * first thumbnail with an image. `readTagsPromise` resolves to one result per
57
- * compressed chunk, in chunk order, each with its own `exifCarriedGroups`, and
58
- * its own `embeddedExifThumbnail` when it has one and no uncompressed chunk
59
- * had one, and is undefined when none is read.
20
+ * Reads one PNG text-chunk block: `{kind, compression?, text: {chunkType, name,
21
+ * valueOffset, valueLength}}`. A block whose `text.name` is undefined (a
22
+ * keyword or language tag over 79 bytes) is skipped, and so is a compressed
23
+ * chunk past the first MAX_COMPRESSED_TEXT_CHUNKS of a load.
24
+ *
25
+ * @param {object} block The finder's block.
26
+ * @param {object} context The load context: `dataView`, `tagFilter` and the
27
+ * pooled `decompress`. `read` counts the load's compressed chunks on it as
28
+ * `compressedPngTextChunks`, created on first use.
29
+ * @returns {{tags: object, blocks?: Array<object>}|Promise<{tags: object, blocks?: Array<object>}>|undefined}
30
+ * The text tag, parse-filtered, or for a raw profile no tags and an emitted
31
+ * exif or iptc block whose `getDataView()` decodes the profile on demand
32
+ * (and throws on a bad one). A compressed chunk gives a promise; a
33
+ * decompression failure gives a placeholder text tag.
60
34
  */
61
- function read(
62
- dataView,
63
- pngTextChunks,
64
- async,
65
- includeUnknown,
66
- computed = false,
67
- tagFilter = NOOP_TAG_FILTER,
68
- decompressConfig,
69
- valueBudget,
70
- getThumbnail,
71
- readCarriedGroups,
72
- rawProfileReaders = {}
73
- ) {
74
- const tags = {};
75
- let embeddedExifTags;
76
- let embeddedIptcTags;
77
- let embeddedExifThumbnail;
78
- let exifCarriedGroups;
79
- const uncompressedRawProfiles = [];
80
- const compressedChunks = [];
81
-
82
- for (let i = 0; i < pngTextChunks.length; i++) {
83
- const chunkOffset = pngTextChunks[i];
84
- const length = dataView.getUint32(chunkOffset + PNG_CHUNK_LENGTH_OFFSET);
85
- const type = getStringFromDataView(dataView, chunkOffset + PNG_CHUNK_TYPE_OFFSET, PNG_CHUNK_TYPE_SIZE);
86
- const textChunk = parseTextChunk(dataView, chunkOffset + PNG_CHUNK_DATA_OFFSET, length, type);
87
- if (!textChunk) {
88
- continue;
89
- }
90
- if (textChunk.compressionMethod === COMPRESSION_METHOD_NONE) {
91
- const tag = getUncompressedTag(textChunk);
92
- if (isRawProfileTag(tag)) {
93
- uncompressedRawProfiles.push(tag);
94
- } else if (tag.name && tagFilter.shouldParseGroup('png')) {
95
- setProperty(tags, getTagKey(tag.name), {
96
- value: tag.value,
97
- description: tag.description
98
- });
99
- }
100
- } else if (async && compressedChunks.length < MAX_COMPRESSED_TEXT_CHUNKS) {
101
- compressedChunks.push(textChunk);
102
- }
35
+ function read(block, context) {
36
+ if (block.text.name === undefined) {
37
+ return undefined;
103
38
  }
104
-
105
- const hasIptcProfile = uncompressedRawProfiles.some((tag) => isIptcGroupTag(tag.name, tag.value))
106
- || compressedChunks.some(isCompressedIptcProfile);
107
-
108
- for (let i = 0; i < uncompressedRawProfiles.length; i++) {
109
- const rawProfileTags = getTagsFromTextTag(
110
- uncompressedRawProfiles[i],
111
- includeUnknown,
112
- computed,
113
- tagFilter,
114
- valueBudget,
115
- embeddedExifThumbnail ? undefined : getThumbnail,
116
- readCarriedGroups,
117
- false,
118
- hasIptcProfile,
119
- rawProfileReaders
120
- );
121
- if (rawProfileTags.embeddedExifTags) {
122
- embeddedExifTags = objectAssign(embeddedExifTags || {}, rawProfileTags.embeddedExifTags);
123
- }
124
- if (rawProfileTags.exifCarriedGroups) {
125
- exifCarriedGroups = mergeCarriedGroups(exifCarriedGroups || {}, rawProfileTags.exifCarriedGroups);
126
- }
127
- if (rawProfileTags.embeddedExifThumbnail) {
128
- embeddedExifThumbnail = rawProfileTags.embeddedExifThumbnail;
129
- }
130
- if (rawProfileTags.embeddedIptcTags) {
131
- embeddedIptcTags = objectAssign(embeddedIptcTags || {}, rawProfileTags.embeddedIptcTags);
132
- }
39
+ if (block.compression === undefined) {
40
+ return classify(getUncompressedTag(context.dataView, block.text), context, false);
133
41
  }
134
-
135
- const compressedThumbnailReader = embeddedExifThumbnail ? undefined : getThumbnail;
136
- const decompressionTasks = compressedChunks.map((textChunk) => () => decompressTextChunk(textChunk, decompressConfig)
137
- .then((tag) => getTagsFromTextTag(
138
- tag,
139
- includeUnknown,
140
- computed,
141
- tagFilter,
142
- valueBudget,
143
- compressedThumbnailReader,
144
- readCarriedGroups,
145
- true,
146
- hasIptcProfile,
147
- rawProfileReaders
148
- )));
149
-
150
- return {
151
- readTags: tags,
152
- embeddedExifTags,
153
- embeddedIptcTags,
154
- embeddedExifThumbnail,
155
- exifCarriedGroups,
156
- readTagsPromise: decompressionTasks.length > 0 ? runTasksInOrder(decompressionTasks, MAX_DECOMPRESSIONS_IN_FLIGHT) : undefined
157
- };
158
- }
159
-
160
- // A compressed profile counts before its value can be checked.
161
- function isCompressedIptcProfile({type, langChars, keywordChars}) {
162
- return getName(type, langChars, keywordChars).toLowerCase() === IPTC_PROFILE_NAME;
42
+ const count = context.compressedPngTextChunks || 0;
43
+ if (count >= MAX_COMPRESSED_TEXT_CHUNKS) {
44
+ return undefined;
45
+ }
46
+ context.compressedPngTextChunks = count + 1;
47
+ return decompressTextChunk(context, block).then((tag) => classify(tag, context, true));
163
48
  }
164
49
 
165
- function mergeCarriedGroups(target, source) {
166
- const groupKeys = Object.keys(source);
167
- for (let i = 0; i < groupKeys.length; i++) {
168
- target[groupKeys[i]] = objectAssign(target[groupKeys[i]] || {}, source[groupKeys[i]]);
50
+ // The payload check keeps a chunk whose keyword says profile but whose payload
51
+ // does not as a plain text tag.
52
+ function classify({name, value, description}, context, decompressed) {
53
+ if (isExifGroupTag(name, value)) {
54
+ return {tags: {}, blocks: [{kind: 'exif', tiffHeaderOffset: EXIF_OFFSET, origin: 'rawProfile', decompressed, getDataView: () => decodeRawData(value)}]};
55
+ }
56
+ if (isIptcGroupTag(name, value)) {
57
+ return {tags: {}, blocks: [{kind: 'iptc', dataOffset: 0, origin: 'rawProfile', decompressed, getDataView: () => decodeRawData(value)}]};
169
58
  }
170
- return target;
59
+ if (name && context.tagFilter.shouldParseGroup('png')) {
60
+ const tags = {};
61
+ setProperty(tags, getTagKey(name), {value, description});
62
+ return {tags: filterTagsForParse('png', tags, context.tagFilter)};
63
+ }
64
+ return undefined;
171
65
  }
172
66
 
173
- function parseTextChunk(dataView, offset, length, type) {
174
- const keywordChars = [];
175
- const langChars = [];
176
- let valueChars;
177
- let parsingState = STATE_KEYWORD;
178
- let compressionMethod = COMPRESSION_METHOD_NONE;
179
- const byteOffset = dataView.byteOffset;
180
- const chunkEnd = Math.min(offset + length, dataView.byteLength);
181
-
182
- for (let i = 0; i < length && offset + i < dataView.byteLength; i++) {
183
- if (parsingState === STATE_COMPRESSION) {
184
- compressionMethod = getCompressionMethod({type, dataView, offset: offset + i, chunkEnd});
185
- if (type === TYPE_ITXT) {
186
- i += COMPRESSION_SECTION_ITXT_EXTRA_BYTE;
187
- }
188
- parsingState = moveToNextState(type, parsingState);
67
+ /**
68
+ * Whether the finder blocks hold a `Raw profile type iptc` text chunk that
69
+ * `read` will read: by payload for an uncompressed chunk, by keyword alone for
70
+ * a compressed one among the first MAX_COMPRESSED_TEXT_CHUNKS named compressed
71
+ * chunks, the ones `read` decompresses.
72
+ *
73
+ * @param {Array<object>} finderBlocks In dispatch order.
74
+ * @param {DataView} dataView The file.
75
+ * @returns {boolean}
76
+ */
77
+ export function hasRawIptcProfile(finderBlocks, dataView) {
78
+ let compressedChunks = 0;
79
+ for (let i = 0; i < finderBlocks.length; i++) {
80
+ const block = finderBlocks[i];
81
+ if (block.text === undefined || block.text.name === undefined) {
189
82
  continue;
190
- } else if (parsingState === STATE_TEXT) {
191
- const slice = dataView.buffer.slice(byteOffset + offset + i, byteOffset + offset + length);
192
- valueChars = new DataView(slice);
193
- break;
194
83
  }
195
- const byte = dataView.getUint8(offset + i);
196
- if (byte === 0) {
197
- parsingState = moveToNextState(type, parsingState);
198
- } else if (parsingState === STATE_KEYWORD) {
199
- if (keywordChars.length >= MAX_KEYWORD_LENGTH) {
200
- return undefined;
201
- }
202
- keywordChars.push(byte);
203
- } else if (parsingState === STATE_LANG) {
204
- if (langChars.length >= MAX_LANGUAGE_TAG_LENGTH) {
205
- return undefined;
84
+ if (block.compression !== undefined) {
85
+ compressedChunks++;
86
+ if (block.kind === 'iptc' && compressedChunks <= MAX_COMPRESSED_TEXT_CHUNKS) {
87
+ return true;
206
88
  }
207
- langChars.push(byte);
89
+ } else if (block.kind === 'iptc' && isUncompressedIptcProfile(block, dataView)) {
90
+ return true;
208
91
  }
209
92
  }
210
-
211
- return {type, keywordChars, langChars, compressionMethod, valueChars};
93
+ return false;
212
94
  }
213
95
 
214
- function getUncompressedTag({type, keywordChars, langChars, valueChars}) {
215
- const decodedValueChars = decompress(valueChars, COMPRESSION_METHOD_NONE, getEncodingFromType(type), 'string');
216
- return constructTag(decodedValueChars, type, langChars, keywordChars);
96
+ function isUncompressedIptcProfile(block, dataView) {
97
+ const tag = getUncompressedTag(dataView, block.text);
98
+ return isIptcGroupTag(tag.name, tag.value);
217
99
  }
218
100
 
219
- function isRawProfileTag({name, value}) {
220
- return isExifGroupTag(name, value) || isIptcGroupTag(name, value);
101
+ function getUncompressedTag(dataView, text) {
102
+ const decodedValueChars = decompress(getValueView(dataView, text), COMPRESSION_METHOD_NONE, getEncodingFromType(text.chunkType), 'string');
103
+ return constructTag(decodedValueChars, text.chunkType, text.name);
221
104
  }
222
105
 
223
- function getTagsFromTextTag({name, value, description}, includeUnknown, computed, tagFilter, valueBudget, getThumbnail, readCarriedGroups, isDecompressed, hasIptcProfile, rawProfileReaders) {
224
- try {
225
- if (isExifGroupTag(name, value)) {
226
- if (!rawProfileReaders.exif || !tagFilter.shouldParseGroup('exif')) {
227
- return {};
228
- }
229
- const exifDataView = decodeRawData(value);
230
- if (isDecompressed) {
231
- addDecompressedValueAllowance(valueBudget, exifDataView.byteLength);
232
- }
233
- const {tags: embeddedExifTags, byteOrder} = rawProfileReaders.exif(
234
- exifDataView,
235
- EXIF_OFFSET,
236
- includeUnknown,
237
- computed,
238
- tagFilter,
239
- valueBudget
240
- );
241
- const result = {embeddedExifTags};
242
- if (readCarriedGroups) {
243
- result.exifCarriedGroups = readCarriedGroups(
244
- exifDataView,
245
- embeddedExifTags,
246
- EXIF_OFFSET,
247
- byteOrder,
248
- valueBudget,
249
- {decompressed: isDecompressed, hasIptcBlock: hasIptcProfile}
250
- );
251
- }
252
- if (embeddedExifTags['MakerNote']) {
253
- delete embeddedExifTags['MakerNote'].__offset;
254
- }
255
- const thumbnail = takeEmbeddedExifThumbnail(embeddedExifTags, exifDataView, EXIF_OFFSET, getThumbnail);
256
- if (thumbnail) {
257
- result.embeddedExifThumbnail = thumbnail;
258
- }
259
- return result;
260
- } else if (isIptcGroupTag(name, value)) {
261
- if (!rawProfileReaders.iptc || !tagFilter.shouldParseGroup('iptc')) {
262
- return {};
263
- }
264
- const iptcDataView = decodeRawData(value);
265
- if (isDecompressed) {
266
- addDecompressedIptcAllowance(valueBudget, iptcDataView.byteLength);
267
- }
268
- return {
269
- embeddedIptcTags: rawProfileReaders.iptc(
270
- iptcDataView,
271
- 0,
272
- includeUnknown,
273
- tagFilter,
274
- valueBudget
275
- )
276
- };
277
- } else if (name) {
278
- if (!tagFilter.shouldParseGroup('png')) {
279
- return {};
280
- }
281
- const readTags = {};
282
- setProperty(readTags, getTagKey(name), {
283
- value,
284
- description
285
- });
286
- return {readTags};
287
- }
288
- } catch (error) {
289
- // Ignore the broken tag.
290
- }
291
- return {};
292
- }
293
-
294
- function decompressTextChunk({type, keywordChars, langChars, compressionMethod, valueChars}, decompressConfig) {
295
- if (valueChars === undefined) {
296
- return Promise.resolve(constructPlaceholderTag(type, langChars, keywordChars));
297
- }
298
- return decompress(valueChars, compressionMethod, getEncodingFromType(type), 'string', decompressConfig)
299
- .then((decompressedValueChars) => constructTag(decompressedValueChars, type, langChars, keywordChars))
300
- .catch(() => constructPlaceholderTag(type, langChars, keywordChars));
301
- }
302
-
303
- function constructPlaceholderTag(type, langChars, keywordChars) {
304
- return constructTag('<text using unknown compression>', type, langChars, keywordChars);
305
- }
306
-
307
- function runTasksInOrder(tasks, limit) {
308
- const results = [];
309
- const workers = [];
310
- let nextIndex = 0;
311
-
312
- for (let i = 0; i < Math.min(limit, tasks.length); i++) {
313
- workers.push(runNext());
314
- }
315
- return Promise.all(workers).then(() => results);
316
-
317
- function runNext() {
318
- if (nextIndex >= tasks.length) {
319
- return Promise.resolve();
320
- }
321
- const index = nextIndex++;
322
- // The wrapper turns a synchronous throw from a task into a rejection
323
- // that Promise.all observes, instead of an exception out of read().
324
- return new Promise((resolve) => resolve(tasks[index]())).then((result) => {
325
- results[index] = result;
326
- return runNext();
327
- });
106
+ // The same slice the parser made while it copied the value: the chunk's declared
107
+ // end, clamped to the buffer by slice itself.
108
+ function getValueView(dataView, {valueOffset, valueLength}) {
109
+ if (valueOffset === undefined) {
110
+ return undefined;
328
111
  }
112
+ const byteOffset = dataView.byteOffset;
113
+ return new DataView(dataView.buffer.slice(byteOffset + valueOffset, byteOffset + valueOffset + valueLength));
329
114
  }
330
115
 
331
- function getCompressionMethod({type, dataView, offset, chunkEnd}) {
332
- if (type === TYPE_ITXT) {
333
- if (offset + 1 < chunkEnd && dataView.getUint8(offset) === COMPRESSION_FLAG_COMPRESSED) {
334
- return dataView.getUint8(offset + 1);
335
- }
336
- } else if (type === TYPE_ZTXT) {
337
- return dataView.getUint8(offset);
116
+ function decompressTextChunk(context, {compression, text}) {
117
+ const valueView = getValueView(context.dataView, text);
118
+ if (valueView === undefined) {
119
+ return Promise.resolve(constructPlaceholderTag(text));
338
120
  }
339
- return COMPRESSION_METHOD_NONE;
121
+ return context.decompress(valueView, getCompressionMethod(compression), getEncodingFromType(text.chunkType), 'string')
122
+ .then((decompressedValueChars) => constructTag(decompressedValueChars, text.chunkType, text.name))
123
+ .catch(() => constructPlaceholderTag(text));
340
124
  }
341
125
 
342
- function moveToNextState(type, parsingState) {
343
- if (parsingState === STATE_KEYWORD && [TYPE_ITXT, TYPE_ZTXT].includes(type)) {
344
- return STATE_COMPRESSION;
345
- }
346
- if (parsingState === STATE_COMPRESSION) {
347
- if (type === TYPE_ITXT) {
348
- return STATE_LANG;
349
- }
350
- return STATE_TEXT;
351
- }
352
- if (parsingState === STATE_LANG) {
353
- return STATE_TRANSLATED_KEYWORD;
354
- }
355
- return STATE_TEXT;
126
+ function constructPlaceholderTag({chunkType, name}) {
127
+ return constructTag('<text using unknown compression>', chunkType, name);
356
128
  }
357
129
 
358
130
  function getEncodingFromType(type) {
@@ -362,25 +134,16 @@ function getEncodingFromType(type) {
362
134
  return 'utf-8';
363
135
  }
364
136
 
365
- function constructTag(valueChars, type, langChars, keywordChars) {
137
+ function constructTag(valueChars, chunkType, name) {
366
138
  const value = getValue(valueChars);
367
139
 
368
140
  return {
369
- name: getName(type, langChars, keywordChars),
141
+ name,
370
142
  value,
371
- description: type === TYPE_ITXT ? getDescription(valueChars) : value
143
+ description: chunkType === TYPE_ITXT ? getDescription(valueChars) : value
372
144
  };
373
145
  }
374
146
 
375
- function getName(type, langChars, keywordChars) {
376
- const name = getStringValueFromArray(keywordChars);
377
- if (type === TYPE_TEXT || langChars.length === 0) {
378
- return name;
379
- }
380
- const lang = getStringValueFromArray(langChars);
381
- return `${name} (${lang})`;
382
- }
383
-
384
147
  function getValue(valueChars) {
385
148
  if (valueChars instanceof DataView) {
386
149
  return getStringFromDataView(valueChars, 0, valueChars.byteLength);
@@ -393,7 +156,7 @@ function getDescription(valueChars) {
393
156
  }
394
157
 
395
158
  function isExifGroupTag(name, value) {
396
- return name.toLowerCase() === 'raw profile type exif' && value.substring(1, 5) === 'exif';
159
+ return name.toLowerCase() === EXIF_PROFILE_NAME && value.substring(1, 5) === 'exif';
397
160
  }
398
161
 
399
162
  function isIptcGroupTag(name, value) {
@@ -36,8 +36,8 @@ export const EXIF_POINTER_TAGS = {
36
36
 
37
37
  // The two id sets mirror the keys of tag-names-gps-ifd.js and tag-names-interoperability-ifd.js.
38
38
  // Importing those files here instead would bring them into builds that leave Exif out.
39
- const GPS_IFD_TAG_IDS = getIdLookup([[0x0000, 0x001f]]);
40
- const INTEROPERABILITY_IFD_TAG_IDS = getIdLookup([[0x0001, 0x0002], [0x1000, 0x1002]]);
39
+ const GPS_IFD_TAG_IDS = /* #__PURE__ */ getIdLookup([[0x0000, 0x001f]]);
40
+ const INTEROPERABILITY_IFD_TAG_IDS = /* #__PURE__ */ getIdLookup([[0x0001, 0x0002], [0x1000, 0x1002]]);
41
41
 
42
42
  function getIdLookup(idRanges) {
43
43
  const lookup = Object.create(null);
@@ -122,24 +122,33 @@ export function getExifTagDependenciesForInclude(includeTags) {
122
122
  pointerSet[EXIF_POINTER_TAGS.interoperabilityIfdPointer] = true;
123
123
  }
124
124
  }
125
- if (typeof selector !== 'string') {
126
- continue;
127
- }
128
-
129
- const selectorLower = selector.toLowerCase();
130
- if (selectorLower.indexOf('gps') === 0) {
131
- pointerSet[EXIF_POINTER_TAGS.gpsInfoIfdPointer] = true;
132
- }
133
- if (
134
- selectorLower.indexOf('interoperability') === 0
135
- || selectorLower.indexOf('relatedimage') === 0
136
- ) {
137
- pointerSet[EXIF_POINTER_TAGS.interoperabilityIfdPointer] = true;
125
+ if (typeof selector === 'string') {
126
+ addExifTagNamePointers(pointerSet, selector);
138
127
  }
139
128
  }
140
129
  }
141
130
  }
142
131
 
132
+ /**
133
+ * Adds to pointerSet the sub-IFD pointer an Exif tag name needs, judged by the
134
+ * name's prefix.
135
+ *
136
+ * @param {object} pointerSet Pointer tag names, set to true.
137
+ * @param {string} name The tag name.
138
+ */
139
+ export function addExifTagNamePointers(pointerSet, name) {
140
+ const nameLower = name.toLowerCase();
141
+ if (nameLower.indexOf('gps') === 0) {
142
+ pointerSet[EXIF_POINTER_TAGS.gpsInfoIfdPointer] = true;
143
+ }
144
+ if (
145
+ nameLower.indexOf('interoperability') === 0
146
+ || nameLower.indexOf('relatedimage') === 0
147
+ ) {
148
+ pointerSet[EXIF_POINTER_TAGS.interoperabilityIfdPointer] = true;
149
+ }
150
+ }
151
+
143
152
  function isRequestedIncludeValue(includeValue) {
144
153
  if (includeValue === true) {
145
154
  return true;