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.
Files changed (83) hide show
  1. package/README.md +398 -27
  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/composable/brand.js +10 -0
  11. package/src/composable/composition-tag-filter.js +97 -0
  12. package/src/composable/composition.js +195 -0
  13. package/src/composable/core.d.ts +148 -0
  14. package/src/composable/core.js +526 -0
  15. package/src/composable/exif-block-reader.js +197 -0
  16. package/src/composable/formats/avif.js +19 -0
  17. package/src/composable/formats/gif.js +28 -0
  18. package/src/composable/formats/heic.js +19 -0
  19. package/src/composable/formats/iso-bmff-file-reader.js +14 -0
  20. package/src/composable/formats/jpeg.js +55 -0
  21. package/src/composable/formats/jxl.js +30 -0
  22. package/src/composable/formats/png.js +187 -0
  23. package/src/composable/formats/tiff.js +18 -0
  24. package/src/composable/formats/webp.js +28 -0
  25. package/src/composable/formats/xml.js +18 -0
  26. package/src/composable/formats.d.ts +17 -0
  27. package/src/composable/formats.js +17 -0
  28. package/src/composable/group-helpers.js +129 -0
  29. package/src/composable/groups/canon.js +26 -0
  30. package/src/composable/groups/composite.js +43 -0
  31. package/src/composable/groups/exif.js +48 -0
  32. package/src/composable/groups/gps.js +75 -0
  33. package/src/composable/groups/icc.js +52 -0
  34. package/src/composable/groups/iptc.js +86 -0
  35. package/src/composable/groups/maker-notes.js +21 -0
  36. package/src/composable/groups/mpf.js +25 -0
  37. package/src/composable/groups/pentax.js +34 -0
  38. package/src/composable/groups/photoshop.js +18 -0
  39. package/src/composable/groups/thumbnail.js +131 -0
  40. package/src/composable/groups/xmp.js +118 -0
  41. package/src/composable/groups.d.ts +20 -0
  42. package/src/composable/groups.js +105 -0
  43. package/src/composable/iptc-block-reader.js +44 -0
  44. package/src/composable/read-view.js +165 -0
  45. package/src/composable/tag-binding-name.js +17 -0
  46. package/src/composable/tags/exif.d.ts +295 -0
  47. package/src/composable/tags/exif.js +396 -0
  48. package/src/composable/tags/iptc.d.ts +84 -0
  49. package/src/composable/tags/iptc.js +109 -0
  50. package/src/composable/value-budget.js +24 -0
  51. package/src/composite.js +2 -2
  52. package/src/decompression.js +60 -0
  53. package/src/engine.js +50 -106
  54. package/src/errors.js +8 -2
  55. package/src/exif-reader.d.ts +8 -0
  56. package/src/exif-reader.js +112 -763
  57. package/src/file-loaders.js +74 -1
  58. package/src/file-tags.js +9 -9
  59. package/src/image-header.js +13 -47
  60. package/src/iptc-tag-names-descriptions.js +334 -0
  61. package/src/iptc-tag-names.js +50 -306
  62. package/src/iptc-tags.js +41 -27
  63. package/src/jfif-tags.js +9 -9
  64. package/src/load-auto.js +2 -2
  65. package/src/loadview-pipeline.js +52 -192
  66. package/src/node-require.js +15 -2
  67. package/src/png-text-tags.js +5 -3
  68. package/src/tag-filter-config.js +24 -15
  69. package/src/tag-filter.js +15 -3
  70. package/src/tag-names-0th-ifd-descriptions.js +232 -0
  71. package/src/tag-names-0th-ifd.js +49 -173
  72. package/src/tag-names-common.js +263 -211
  73. package/src/tag-names-exif-ifd-descriptions.js +249 -0
  74. package/src/tag-names-exif-ifd.js +55 -187
  75. package/src/tag-names-gps-ifd-descriptions.js +156 -0
  76. package/src/tag-names-gps-ifd.js +39 -146
  77. package/src/tag-names-utils.js +28 -3
  78. package/src/tags-helpers.js +6 -2
  79. package/src/types.js +2 -0
  80. package/src/unsupported-format-error.js +21 -0
  81. package/src/utils.js +22 -85
  82. package/src/xmp-tag-names.js +42 -21
  83. package/webpack.config.js +1 -1
@@ -2,15 +2,39 @@
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 {getStringValue} from './tag-names-utils.js';
5
+ import {
6
+ getModelVersionDescription,
7
+ getFileFormatDescription,
8
+ getFileFormatVersionDescription,
9
+ getCreationDate,
10
+ getCreationTime,
11
+ getEncodingName,
12
+ getARMIdentifierDescription,
13
+ getARMVersionDescription,
14
+ getRecordVersionDescription,
15
+ getEditorialUpdateDescription,
16
+ getSubjectReferenceDescription,
17
+ getActionAdvisedDescription,
18
+ getObjectCycleDescription,
19
+ getRasterizedCaptionDescription,
20
+ getImageOrientationDescription,
21
+ getAudioTypeDescription,
22
+ getAudioSamplingRateDescription,
23
+ getAudioSamplingResolutionDescription,
24
+ getAudioDurationDescription,
25
+ getRecord2DestinationDescription,
26
+ getObjectDataPreviewFileFormatVersionDescription,
27
+ getSizeModeDescription,
28
+ getMaxSubfileSizeDescription,
29
+ getObjectDataSizeAnnouncedDescription,
30
+ getMaximumObjectDataSizeDescription
31
+ } from './iptc-tag-names-descriptions.js';
6
32
 
7
33
  export default {
8
34
  'iptc': {
9
35
  0x0100: {
10
36
  'name': 'Model Version',
11
- 'description': (value) => {
12
- return ((value[0] << 8) + value[1]).toString();
13
- }
37
+ 'description': getModelVersionDescription
14
38
  },
15
39
  0x0105: {
16
40
  'name': 'Destination',
@@ -18,15 +42,11 @@ export default {
18
42
  },
19
43
  0x0114: {
20
44
  'name': 'File Format',
21
- 'description': (value) => {
22
- return ((value[0] << 8) + value[1]).toString();
23
- }
45
+ 'description': getFileFormatDescription
24
46
  },
25
47
  0x0116: {
26
48
  'name': 'File Format Version',
27
- 'description': (value) => {
28
- return ((value[0] << 8) + value[1]).toString();
29
- }
49
+ 'description': getFileFormatVersionDescription
30
50
  },
31
51
  0x011e: 'Service Identifier',
32
52
  0x0128: 'Envelope Number',
@@ -42,27 +62,20 @@ export default {
42
62
  },
43
63
  0x015a: {
44
64
  'name': 'Coded Character Set',
45
- 'description': getEncodingName,
46
- 'encoding_name': getEncodingName,
65
+ 'description': getEncodingName
47
66
  },
48
67
  0x0164: 'UNO',
49
68
  0x0178: {
50
69
  'name': 'ARM Identifier',
51
- 'description': (value) => {
52
- return ((value[0] << 8) + value[1]).toString();
53
- }
70
+ 'description': getARMIdentifierDescription
54
71
  },
55
72
  0x017a: {
56
73
  'name': 'ARM Version',
57
- 'description': (value) => {
58
- return ((value[0] << 8) + value[1]).toString();
59
- }
74
+ 'description': getARMVersionDescription
60
75
  },
61
76
  0x0200: {
62
77
  'name': 'Record Version',
63
- 'description': (value) => {
64
- return ((value[0] << 8) + value[1]).toString();
65
- }
78
+ 'description': getRecordVersionDescription
66
79
  },
67
80
  0x0203: 'Object Type Reference',
68
81
  0x0204: 'Object Attribute Reference',
@@ -70,21 +83,13 @@ export default {
70
83
  0x0207: 'Edit Status',
71
84
  0x0208: {
72
85
  'name': 'Editorial Update',
73
- 'description': (value) => {
74
- if (getStringValue(value) === '01') {
75
- return 'Additional Language';
76
- }
77
- return 'Unknown';
78
- }
86
+ 'description': getEditorialUpdateDescription
79
87
  },
80
88
  0x020a: 'Urgency',
81
89
  0x020c: {
82
90
  'name': 'Subject Reference',
83
91
  'repeatable': true,
84
- 'description': (value) => {
85
- const parts = getStringValue(value).split(':');
86
- return parts[2] + (parts[3] ? '/' + parts[3] : '') + (parts[4] ? '/' + parts[4] : '');
87
- }
92
+ 'description': getSubjectReferenceDescription
88
93
  },
89
94
  0x020f: 'Category',
90
95
  0x0214: {
@@ -111,19 +116,7 @@ export default {
111
116
  0x0228: 'Special Instructions',
112
117
  0x022a: {
113
118
  'name': 'Action Advised',
114
- 'description': (value) => {
115
- const string = getStringValue(value);
116
- if (string === '01') {
117
- return 'Object Kill';
118
- } else if (string === '02') {
119
- return 'Object Replace';
120
- } else if (string === '03') {
121
- return 'Object Append';
122
- } else if (string === '04') {
123
- return 'Object Reference';
124
- }
125
- return 'Unknown';
126
- }
119
+ 'description': getActionAdvisedDescription
127
120
  },
128
121
  0x022d: {
129
122
  'name': 'Reference Service',
@@ -157,17 +150,7 @@ export default {
157
150
  0x0246: 'Program Version',
158
151
  0x024b: {
159
152
  'name': 'Object Cycle',
160
- 'description': (value) => {
161
- const string = getStringValue(value);
162
- if (string === 'a') {
163
- return 'morning';
164
- } else if (string === 'p') {
165
- return 'evening';
166
- } else if (string === 'b') {
167
- return 'both';
168
- }
169
- return 'Unknown';
170
- }
153
+ 'description': getObjectCycleDescription
171
154
  },
172
155
  0x0250: {
173
156
  'name': 'By-line',
@@ -198,82 +181,29 @@ export default {
198
181
  },
199
182
  0x027d: {
200
183
  'name': 'Rasterized Caption',
201
- 'description': (value) => value
184
+ 'description': getRasterizedCaptionDescription
202
185
  },
203
186
  0x0282: 'Image Type',
204
187
  0x0283: {
205
188
  'name': 'Image Orientation',
206
- 'description': (value) => {
207
- const string = getStringValue(value);
208
- if (string === 'P') {
209
- return 'Portrait';
210
- } else if (string === 'L') {
211
- return 'Landscape';
212
- } else if (string === 'S') {
213
- return 'Square';
214
- }
215
- return 'Unknown';
216
- }
189
+ 'description': getImageOrientationDescription
217
190
  },
218
191
  0x0287: 'Language Identifier',
219
192
  0x0296: {
220
193
  'name': 'Audio Type',
221
- 'description': (value) => {
222
- const stringValue = getStringValue(value);
223
- const character0 = stringValue.charAt(0);
224
- const character1 = stringValue.charAt(1);
225
- let description = '';
226
-
227
- if (character0 === '1') {
228
- description += 'Mono';
229
- } else if (character0 === '2') {
230
- description += 'Stereo';
231
- }
232
-
233
- if (character1 === 'A') {
234
- description += ', actuality';
235
- } else if (character1 === 'C') {
236
- description += ', question and answer session';
237
- } else if (character1 === 'M') {
238
- description += ', music, transmitted by itself';
239
- } else if (character1 === 'Q') {
240
- description += ', response to a question';
241
- } else if (character1 === 'R') {
242
- description += ', raw sound';
243
- } else if (character1 === 'S') {
244
- description += ', scener';
245
- } else if (character1 === 'V') {
246
- description += ', voicer';
247
- } else if (character1 === 'W') {
248
- description += ', wrap';
249
- }
250
-
251
- if (description !== '') {
252
- return description;
253
- }
254
- return stringValue;
255
- }
194
+ 'description': getAudioTypeDescription
256
195
  },
257
196
  0x0297: {
258
197
  'name': 'Audio Sampling Rate',
259
- 'description': (value) => parseInt(getStringValue(value), 10) + ' Hz'
198
+ 'description': getAudioSamplingRateDescription
260
199
  },
261
200
  0x0298: {
262
201
  'name': 'Audio Sampling Resolution',
263
- 'description': (value) => {
264
- const bits = parseInt(getStringValue(value), 10);
265
- return bits + (bits === 1 ? ' bit' : ' bits');
266
- }
202
+ 'description': getAudioSamplingResolutionDescription
267
203
  },
268
204
  0x0299: {
269
205
  'name': 'Audio Duration',
270
- 'description': (value) => {
271
- const duration = getStringValue(value);
272
- if (duration.length >= 6) {
273
- return duration.substr(0, 2) + ':' + duration.substr(2, 2) + ':' + duration.substr(4, 2);
274
- }
275
- return duration;
276
- }
206
+ 'description': getAudioDurationDescription
277
207
  },
278
208
  0x029a: 'Audio Outcue',
279
209
  0x02ba: 'Short Document ID',
@@ -286,214 +216,28 @@ export default {
286
216
  }
287
217
  return 'Record 2 destination';
288
218
  },
289
- 'description': (value) => {
290
- if (value.length === 2) {
291
- const intValue = getPreviewNumber(value);
292
- if (intValue === 0) {
293
- return 'No ObjectData';
294
- } else if (intValue === 1) {
295
- return 'IPTC-NAA Digital Newsphoto Parameter Record';
296
- } else if (intValue === 2) {
297
- return 'IPTC7901 Recommended Message Format';
298
- } else if (intValue === 3) {
299
- return 'Tagged Image File Format (Adobe/Aldus Image data)';
300
- } else if (intValue === 4) {
301
- return 'Illustrator (Adobe Graphics data)';
302
- } else if (intValue === 5) {
303
- return 'AppleSingle (Apple Computer Inc)';
304
- } else if (intValue === 6) {
305
- return 'NAA 89-3 (ANPA 1312)';
306
- } else if (intValue === 7) {
307
- return 'MacBinary II';
308
- } else if (intValue === 8) {
309
- return 'IPTC Unstructured Character Oriented File Format (UCOFF)';
310
- } else if (intValue === 9) {
311
- return 'United Press International ANPA 1312 variant';
312
- } else if (intValue === 10) {
313
- return 'United Press International Down-Load Message';
314
- } else if (intValue === 11) {
315
- return 'JPEG File Interchange (JFIF)';
316
- } else if (intValue === 12) {
317
- return 'Photo-CD Image-Pac (Eastman Kodak)';
318
- } else if (intValue === 13) {
319
- return 'Microsoft Bit Mapped Graphics File [*.BMP]';
320
- } else if (intValue === 14) {
321
- return 'Digital Audio File [*.WAV] (Microsoft & Creative Labs)';
322
- } else if (intValue === 15) {
323
- return 'Audio plus Moving Video [*.AVI] (Microsoft)';
324
- } else if (intValue === 16) {
325
- return 'PC DOS/Windows Executable Files [*.COM][*.EXE]';
326
- } else if (intValue === 17) {
327
- return 'Compressed Binary File [*.ZIP] (PKWare Inc)';
328
- } else if (intValue === 18) {
329
- return 'Audio Interchange File Format AIFF (Apple Computer Inc)';
330
- } else if (intValue === 19) {
331
- return 'RIFF Wave (Microsoft Corporation)';
332
- } else if (intValue === 20) {
333
- return 'Freehand (Macromedia/Aldus)';
334
- } else if (intValue === 21) {
335
- return 'Hypertext Markup Language "HTML" (The Internet Society)';
336
- } else if (intValue === 22) {
337
- return 'MPEG 2 Audio Layer 2 (Musicom), ISO/IEC';
338
- } else if (intValue === 23) {
339
- return 'MPEG 2 Audio Layer 3, ISO/IEC';
340
- } else if (intValue === 24) {
341
- return 'Portable Document File (*.PDF) Adobe';
342
- } else if (intValue === 25) {
343
- return 'News Industry Text Format (NITF)';
344
- } else if (intValue === 26) {
345
- return 'Tape Archive (*.TAR)';
346
- } else if (intValue === 27) {
347
- return 'Tidningarnas Telegrambyrå NITF version (TTNITF DTD)';
348
- } else if (intValue === 28) {
349
- return 'Ritzaus Bureau NITF version (RBNITF DTD)';
350
- } else if (intValue === 29) {
351
- return 'Corel Draw [*.CDR]';
352
- }
353
- return `Unknown format ${intValue}`;
354
- }
355
- return getStringValue(value);
356
- }
219
+ 'description': getRecord2DestinationDescription
357
220
  },
358
221
  0x02c9: {
359
222
  'name': 'ObjectData Preview File Format Version',
360
- 'description': (value, tags) => {
361
- // Format ID, Version ID, Version Description
362
- const formatVersions = {
363
- 0: {0: '1'},
364
- 1: {1: '1', 2: '2', 3: '3', 4: '4'},
365
- 2: {4: '4'},
366
- 3: {1: '5.0', 2: '6.0'},
367
- 4: {1: '1.40'},
368
- 5: {1: '2'},
369
- 6: {1: '1'},
370
- 11: {1: '1.02'},
371
- 20: {1: '3.1', 2: '4.0', 3: '5.0', 4: '5.5'},
372
- 21: {2: '2.0'}
373
- };
374
- const version = getPreviewNumber(value);
375
-
376
- if (tags['ObjectData Preview File Format']) {
377
- const format = getPreviewNumber(tags['ObjectData Preview File Format'].value);
378
- if (Object.prototype.hasOwnProperty.call(formatVersions, format)
379
- && Object.prototype.hasOwnProperty.call(formatVersions[format], version)) {
380
- return formatVersions[format][version];
381
- }
382
- }
383
-
384
- const versionNumber = getBinaryNumber(value);
385
- return versionNumber === null ? getStringValue(value) : String(versionNumber);
386
- }
223
+ 'description': getObjectDataPreviewFileFormatVersionDescription
387
224
  },
388
225
  0x02ca: 'ObjectData Preview Data',
389
226
  0x070a: {
390
227
  'name': 'Size Mode',
391
- 'description': (value) => {
392
- return (value[0]).toString();
393
- }
228
+ 'description': getSizeModeDescription
394
229
  },
395
230
  0x0714: {
396
231
  'name': 'Max Subfile Size',
397
- 'description': (value) => {
398
- let n = 0;
399
- for (let i = 0; i < value.length; i++) {
400
- n = (n << 8) + value[i];
401
- }
402
- return n.toString();
403
- }
232
+ 'description': getMaxSubfileSizeDescription
404
233
  },
405
234
  0x075a: {
406
235
  'name': 'ObjectData Size Announced',
407
- 'description': (value) => {
408
- let n = 0;
409
- for (let i = 0; i < value.length; i++) {
410
- n = (n << 8) + value[i];
411
- }
412
- return n.toString();
413
- }
236
+ 'description': getObjectDataSizeAnnouncedDescription
414
237
  },
415
238
  0x075f: {
416
239
  'name': 'Maximum ObjectData Size',
417
- 'description': (value) => {
418
- let n = 0;
419
- for (let i = 0; i < value.length; i++) {
420
- n = (n << 8) + value[i];
421
- }
422
- return n.toString();
423
- }
240
+ 'description': getMaximumObjectDataSizeDescription
424
241
  }
425
242
  }
426
243
  };
427
-
428
- function getCreationDate(value) {
429
- const date = getStringValue(value);
430
-
431
- if (date.length >= 8) {
432
- return date.substr(0, 4) + '-' + date.substr(4, 2) + '-' + date.substr(6, 2);
433
- }
434
-
435
- return date;
436
- }
437
-
438
- function getCreationTime(value) {
439
- const time = getStringValue(value);
440
- let parsedTime = time;
441
-
442
- if (time.length >= 6) {
443
- parsedTime = time.substr(0, 2) + ':' + time.substr(2, 2) + ':' + time.substr(4, 2);
444
- if (time.length === 11) {
445
- parsedTime += time.substr(6, 1) + time.substr(7, 2) + ':' + time.substr(9, 2);
446
- }
447
- }
448
-
449
- return parsedTime;
450
- }
451
-
452
- function getEncodingName(value) {
453
- const string = getStringValue(value);
454
- if (string === '\x1b%G') {
455
- return 'UTF-8';
456
- } else if (string === '\x1b%5') {
457
- return 'Windows-1252';
458
- } else if (string === '\x1b%/G') {
459
- return 'UTF-8 Level 1';
460
- } else if (string === '\x1b%/H') {
461
- return 'UTF-8 Level 2';
462
- } else if (string === '\x1b%/I') {
463
- return 'UTF-8 Level 3';
464
- } else if (string === '\x1B/A') {
465
- return 'ISO-8859-1';
466
- } else if (string === '\x1B/B') {
467
- return 'ISO-8859-2';
468
- } else if (string === '\x1B/C') {
469
- return 'ISO-8859-3';
470
- } else if (string === '\x1B/D') {
471
- return 'ISO-8859-4';
472
- } else if (string === '\x1B/@') {
473
- return 'ISO-8859-5';
474
- } else if (string === '\x1B/G') {
475
- return 'ISO-8859-6';
476
- } else if (string === '\x1B/F') {
477
- return 'ISO-8859-7';
478
- } else if (string === '\x1B/H') {
479
- return 'ISO-8859-8';
480
- }
481
- return 'Unknown';
482
- }
483
-
484
- // IIM stores 2:200 and 2:201 as 2-octet binary; two ASCII digits are the text form.
485
- function getPreviewNumber(value) {
486
- const number = getBinaryNumber(value);
487
- return number === null ? parseInt(getStringValue(value), 10) : number;
488
- }
489
-
490
- function getBinaryNumber(value) {
491
- if (value.length !== 2 || (isAsciiDigit(value[0]) && isAsciiDigit(value[1]))) {
492
- return null;
493
- }
494
- return (value[0] << 8) + value[1];
495
- }
496
-
497
- function isAsciiDigit(octet) {
498
- return octet >= 0x30 && octet <= 0x39;
499
- }
package/src/iptc-tags.js CHANGED
@@ -3,6 +3,7 @@
3
3
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
4
 
5
5
  import IptcTagNames from './iptc-tag-names.js';
6
+ import {getEncodingName} from './iptc-tag-names-descriptions.js';
6
7
  import TagDecoder from './tag-decoder.js';
7
8
  import {NOOP_TAG_FILTER} from './tag-filter.js';
8
9
  import {getValueBudget, BYTES_PER_IPTC_DATASET, IPTC_DATASET_HEADER_SIZE} from './tags-helpers.js';
@@ -15,22 +16,29 @@ const RESOURCE_NAME_MIN_SIZE = 2;
15
16
  const RESOURCE_SIZE_SIZE = 4;
16
17
  const RESOURCE_BLOCK_MIN_HEADER_SIZE = BYTES_8BIM_SIZE + RESOURCE_ID_SIZE + RESOURCE_NAME_MIN_SIZE + RESOURCE_SIZE_SIZE;
17
18
  const NAA_RESOURCE_BLOCK_TYPE = 0x0404; // Sometimes called resource ID.
19
+ const CODED_CHARACTER_SET = 0x015a;
18
20
 
19
21
  export default {
20
22
  read
21
23
  };
22
24
 
25
+ function read(dataView, dataOffset, includeUnknown, tagFilter, valueBudget) {
26
+ return readIptcTags(dataView, dataOffset, IptcTagNames['iptc'], includeUnknown, tagFilter, valueBudget);
27
+ }
28
+
23
29
  /**
24
30
  * Reads the IPTC datasets of an NAA resource block, or of a naked IPTC block
25
31
  * given as an array of bytes.
26
32
  *
33
+ * @param {Object<number, (string|object)>} tagNames The datasets to read,
34
+ * keyed by dataset id, in the shape of the iptc dictionary.
27
35
  * @param {{iptcDatasetsRemaining: number}} [valueBudget] - The per-load budget
28
36
  * from getValueBudget. Each dataset header read draws from its
29
37
  * iptcDatasetsRemaining, and reading stops when it runs out, returning the
30
38
  * tags read so far. Omitted, a budget is sized from the data read.
31
39
  * @returns {Object} The read tags, keyed by tag name.
32
40
  */
33
- function read(dataView, dataOffset, includeUnknown, tagFilter = NOOP_TAG_FILTER, valueBudget) {
41
+ export function readIptcTags(dataView, dataOffset, tagNames, includeUnknown, tagFilter = NOOP_TAG_FILTER, valueBudget) {
34
42
  try {
35
43
  if (Array.isArray(dataView)) {
36
44
  const arrayDataView = new DataView(Uint8Array.from(dataView).buffer);
@@ -38,13 +46,14 @@ function read(dataView, dataOffset, includeUnknown, tagFilter = NOOP_TAG_FILTER,
38
46
  arrayDataView,
39
47
  {size: dataView.length},
40
48
  0,
49
+ tagNames,
41
50
  includeUnknown,
42
51
  tagFilter,
43
52
  valueBudget || getValueBudget(arrayDataView)
44
53
  );
45
54
  }
46
55
  const {naaBlock, dataOffset: newDataOffset} = getNaaResourceBlock(dataView, dataOffset);
47
- return parseTags(dataView, naaBlock, newDataOffset, includeUnknown, tagFilter, valueBudget || getValueBudget(dataView));
56
+ return parseTags(dataView, naaBlock, newDataOffset, tagNames, includeUnknown, tagFilter, valueBudget || getValueBudget(dataView));
48
57
  } catch (error) {
49
58
  return {};
50
59
  }
@@ -88,16 +97,17 @@ function getBlockPadding(resourceBlock) {
88
97
  return 0;
89
98
  }
90
99
 
91
- function parseTags(dataView, naaBlock, dataOffset, includeUnknown, tagFilter, valueBudget) {
100
+ function parseTags(dataView, naaBlock, dataOffset, tagNames, includeUnknown, tagFilter, valueBudget) {
92
101
  const tags = {};
93
102
  let encoding = undefined;
94
103
 
95
104
  const endOfBlockOffset = dataOffset + naaBlock['size'];
96
105
 
97
106
  while ((dataOffset < endOfBlockOffset) && (dataOffset < dataView.byteLength)) {
98
- const {tag, tagSize} = readTag(
107
+ const {tag, tagSize, encoding: datasetEncoding} = readTag(
99
108
  dataView,
100
109
  dataOffset,
110
+ tagNames,
101
111
  tags,
102
112
  encoding,
103
113
  includeUnknown,
@@ -109,11 +119,11 @@ function parseTags(dataView, naaBlock, dataOffset, includeUnknown, tagFilter, va
109
119
  break;
110
120
  }
111
121
 
112
- if (tag) {
113
- if ('encoding' in tag) {
114
- encoding = tag.encoding;
115
- }
122
+ if (datasetEncoding !== undefined) {
123
+ encoding = datasetEncoding;
124
+ }
116
125
 
126
+ if (tag) {
117
127
  if ((tags[tag.name] === undefined) || (tag['repeatable'] === undefined)) {
118
128
  tags[tag.name] = {
119
129
  id: tag.id,
@@ -145,6 +155,7 @@ function parseTags(dataView, naaBlock, dataOffset, includeUnknown, tagFilter, va
145
155
  function readTag(
146
156
  dataView,
147
157
  dataOffset,
158
+ tagNames,
148
159
  tags = {},
149
160
  encoding = undefined,
150
161
  includeUnknown = false,
@@ -165,34 +176,35 @@ function readTag(
165
176
  return {tag: null, tagSize: 0};
166
177
  }
167
178
 
168
- if (!includeUnknown && !IptcTagNames['iptc'][tagCode]) {
169
- return {tag: undefined, tagSize};
179
+ // Read even when the tag itself is left out, since the text datasets after it depend on it.
180
+ const datasetEncoding = getDatasetEncoding(dataView, dataOffset, tagCode, tagSize);
181
+
182
+ const tagEntry = tagNames[tagCode];
183
+ if (!includeUnknown && !tagEntry) {
184
+ return {tag: undefined, tagSize, encoding: datasetEncoding};
170
185
  }
171
186
 
172
187
  if (!tagFilter.shouldParseTag(
173
188
  'iptc',
174
- getIptcTagNameForFiltering(tagCode, includeUnknown),
189
+ getIptcTagNameForFiltering(tagEntry, tagCode, includeUnknown),
175
190
  tagCode
176
191
  )) {
177
- return {tag: undefined, tagSize};
192
+ return {tag: undefined, tagSize, encoding: datasetEncoding};
178
193
  }
179
194
 
180
195
  const tagValue = getTagValue(dataView, dataOffset + IPTC_DATASET_HEADER_SIZE, tagSize);
181
196
 
182
197
  const tag = {
183
198
  id: tagCode,
184
- name: getTagName(IptcTagNames['iptc'][tagCode], tagCode, tagValue),
199
+ name: getTagName(tagEntry, tagCode, tagValue),
185
200
  value: tagValue,
186
- description: getTagDescription(IptcTagNames['iptc'][tagCode], tagValue, tags, encoding)
201
+ description: getTagDescription(tagEntry, tagValue, tags, encoding)
187
202
  };
188
- if (tagIsRepeatable(tagCode)) {
203
+ if (tagIsRepeatable(tagEntry)) {
189
204
  tag['repeatable'] = true;
190
205
  }
191
- if (tagContainsEncoding(tagCode)) {
192
- tag['encoding'] = IptcTagNames['iptc'][tagCode]['encoding_name'](tagValue);
193
- }
194
206
 
195
- return {tag, tagSize};
207
+ return {tag, tagSize, encoding: datasetEncoding};
196
208
  }
197
209
 
198
210
  function takeDatasetUnits(valueBudget, tagSize) {
@@ -204,8 +216,14 @@ function takeDatasetUnits(valueBudget, tagSize) {
204
216
  return false;
205
217
  }
206
218
 
207
- function getIptcTagNameForFiltering(tagCode, includeUnknown) {
208
- const tag = IptcTagNames['iptc'][tagCode];
219
+ function getDatasetEncoding(dataView, dataOffset, tagCode, tagSize) {
220
+ if (tagCode === CODED_CHARACTER_SET) {
221
+ return getEncodingName(getTagValue(dataView, dataOffset + IPTC_DATASET_HEADER_SIZE, tagSize));
222
+ }
223
+ return undefined;
224
+ }
225
+
226
+ function getIptcTagNameForFiltering(tag, tagCode, includeUnknown) {
209
227
  if (!tag) {
210
228
  if (includeUnknown) {
211
229
  return `undefined-${tagCode}`;
@@ -291,10 +309,6 @@ function hasDescriptionProperty(tag) {
291
309
  return tag && tag['description'] !== undefined;
292
310
  }
293
311
 
294
- function tagIsRepeatable(tagCode) {
295
- return IptcTagNames['iptc'][tagCode] && IptcTagNames['iptc'][tagCode]['repeatable'];
296
- }
297
-
298
- function tagContainsEncoding(tagCode) {
299
- return IptcTagNames['iptc'][tagCode] && IptcTagNames['iptc'][tagCode]['encoding_name'] !== undefined;
312
+ function tagIsRepeatable(tag) {
313
+ return tag && tag['repeatable'];
300
314
  }