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
@@ -0,0 +1,129 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+
5
+ import {filterTagsForParse} from '../tag-filter.js';
6
+
7
+ const DECODER_ORDER = ['canon', 'pentax'];
8
+
9
+ export function parsedTags(groupKey, readTags, ctx) {
10
+ return {tags: filterTagsForParse(groupKey, readTags, ctx.tagFilter)};
11
+ }
12
+
13
+ export function getBlockDataView(block, ctx) {
14
+ if (block.getDataView) {
15
+ return block.getDataView();
16
+ }
17
+ return block.dataView || ctx.dataView;
18
+ }
19
+
20
+ export function getBrobDataView(dataView, brobBlock) {
21
+ // The box length is untrusted, so bound the view by the bytes present. The
22
+ // JXL header parser never reports a dataOffset past the end of the view.
23
+ const length = Math.max(0, Math.min(brobBlock.length, dataView.byteLength - brobBlock.dataOffset));
24
+ return new DataView(dataView.buffer, dataView.byteOffset + brobBlock.dataOffset, length);
25
+ }
26
+
27
+ /**
28
+ * @param {DataView|undefined} dataView The input.
29
+ * @param {number} perInputSize What each byte of input allows.
30
+ * @param {number} allowance What any input allows.
31
+ * @returns {number} `perInputSize` times the input's byte length plus
32
+ * `allowance`, where an absent view or a non-number byte length counts as 0.
33
+ */
34
+ export function getInputSizeBound(dataView, perInputSize, allowance) {
35
+ const byteLength = dataView !== undefined && typeof dataView.byteLength === 'number' ? dataView.byteLength : 0;
36
+ return perInputSize * byteLength + allowance;
37
+ }
38
+
39
+ export function getEmbeddableMergeDescriptor(block, slot, carriedSlot) {
40
+ if (block.carried !== undefined) {
41
+ return {slot: carriedSlot, mode: block.carried === 'main' ? 'assign' : 'merge'};
42
+ }
43
+ return {slot, mode: block.origin !== undefined ? 'merge' : 'assign'};
44
+ }
45
+
46
+ export function isPngTextChunkBlock(block) {
47
+ return block.text !== undefined;
48
+ }
49
+
50
+ /**
51
+ * Merges the engine groups consuming maker notes into one with the union of
52
+ * their decoders, since two groups reading the same maker note would read it
53
+ * twice.
54
+ *
55
+ * @param {Array<object>} groups The engine groups, each listed once.
56
+ * @returns {Array<object>} The same array when fewer than two groups consume
57
+ * maker notes, otherwise the other groups in their order followed by the
58
+ * merged group, which has the first maker note group's key and `merge`.
59
+ */
60
+ export function mergeMakerNoteGroups(groups) {
61
+ const makerNoteGroups = groups.filter(consumesMakerNote);
62
+ if (makerNoteGroups.length < 2) {
63
+ return groups;
64
+ }
65
+
66
+ let decoders = [];
67
+ for (let i = 0; i < makerNoteGroups.length; i++) {
68
+ decoders = decoders.concat(makerNoteGroups[i].decoders);
69
+ }
70
+ decoders = decoders
71
+ .filter((decoder, index) => decoders.indexOf(decoder) === index)
72
+ .sort((a, b) => DECODER_ORDER.indexOf(a.name) - DECODER_ORDER.indexOf(b.name));
73
+
74
+ const merged = {
75
+ key: makerNoteGroups[0].key,
76
+ consumes: ['makerNote'],
77
+ emits: [],
78
+ decoders,
79
+ read: (block, ctx) => readMakerNoteWithDecoders(block, ctx, decoders),
80
+ merge: makerNoteGroups[0].merge,
81
+ fromExif: getMakerNoteBlockFromExif,
82
+ };
83
+ return groups.filter((group) => !consumesMakerNote(group)).concat([merged]);
84
+ }
85
+
86
+ function consumesMakerNote(group) {
87
+ return group.consumes.indexOf('makerNote') !== -1;
88
+ }
89
+
90
+ /**
91
+ * Reads a maker note block with the first decoder that recognizes it. The
92
+ * decoders filter their own tags.
93
+ *
94
+ * @param {object} block A makerNote block.
95
+ * @param {object} ctx The engine context.
96
+ * @param {Array<{name: string, matches: function, read: function}>} decoders
97
+ * In the order they are tried.
98
+ * @returns {{tags: object}|undefined} Undefined when no decoder matches.
99
+ */
100
+ export function readMakerNoteWithDecoders(block, ctx, decoders) {
101
+ for (let i = 0; i < decoders.length; i++) {
102
+ if (decoders[i].matches(block)) {
103
+ return {tags: decoders[i].read(block, ctx)};
104
+ }
105
+ }
106
+ return undefined;
107
+ }
108
+
109
+ /**
110
+ * Builds the makerNote block an Exif block carries.
111
+ *
112
+ * @param {Object<string, object>} parsed The Exif block's filtered tags.
113
+ * @param {object} exif The Exif block's facts: `view`, `tiffHeaderOffset`,
114
+ * `byteOrder`, `makerNoteOffset` and `carried`.
115
+ * @returns {(object|false|undefined)} The makerNote block, or a falsy value
116
+ * when there is no MakerNote tag or no maker note offset.
117
+ */
118
+ export function getMakerNoteBlockFromExif(parsed, exif) {
119
+ return parsed['MakerNote'] && exif.makerNoteOffset !== undefined && {
120
+ kind: 'makerNote',
121
+ tiffView: exif.view,
122
+ tiffHeaderOffset: exif.tiffHeaderOffset,
123
+ makerNoteOffset: exif.makerNoteOffset,
124
+ byteOrder: exif.byteOrder,
125
+ make: parsed['Make'] && parsed['Make'].value,
126
+ bytes: parsed['MakerNote'].value,
127
+ carried: exif.carried,
128
+ };
129
+ }
@@ -0,0 +1,26 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+
5
+ import CanonTags from '../../canon-tags.js';
6
+ import {getEmbeddableMergeDescriptor, mergeMakerNoteGroups, readMakerNoteWithDecoders, getMakerNoteBlockFromExif} from '../group-helpers.js';
7
+ import {getSharedValueBudget} from '../value-budget.js';
8
+ import {GROUP_BRAND} from '../brand.js';
9
+
10
+ export const canonDecoder = {
11
+ name: 'canon',
12
+ matches: (block) => Array.isArray(block.make) && block.make[0] === 'Canon',
13
+ read: (block, ctx) => CanonTags.read(block.tiffView, block.tiffHeaderOffset, block.makerNoteOffset, block.byteOrder, ctx.options.includeUnknown, ctx.options.computed, ctx.tagFilter, getSharedValueBudget(ctx)),
14
+ };
15
+
16
+ export const canon = {
17
+ key: 'makerNotes',
18
+ consumes: ['makerNote'],
19
+ emits: [],
20
+ decoders: [canonDecoder],
21
+ read: (block, ctx) => readMakerNoteWithDecoders(block, ctx, canon.decoders),
22
+ merge: (block) => getEmbeddableMergeDescriptor(block, 'makerNotes', 'carriedMakerNotes'),
23
+ combine: mergeMakerNoteGroups,
24
+ fromExif: getMakerNoteBlockFromExif,
25
+ brand: GROUP_BRAND,
26
+ };
@@ -0,0 +1,43 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+
5
+ import Composite from '../../composite.js';
6
+ import {GROUP_BRAND} from '../brand.js';
7
+ import {mergeAssignGroup} from '../../loadview-pipeline.js';
8
+
9
+ // Derived from the Exif and XMP tags, so it reads no block.
10
+ export const composite = {
11
+ key: 'composite',
12
+ consumes: [],
13
+ emits: [],
14
+ merge: () => ({slot: 'composite', mode: 'composite'}),
15
+ mergeModes: {composite: addCompositeGroup},
16
+ brand: GROUP_BRAND,
17
+ };
18
+
19
+ // Composite reads the merged tags, or with an active tag filter the parsed exif
20
+ // and file groups, or in a flat load under a read cap every parsed tag block.
21
+ function addCompositeGroup(tags, block, context) {
22
+ if (!context.tagFilter.shouldReturnGroup('composite')) {
23
+ return tags;
24
+ }
25
+
26
+ let compositeInput = tags;
27
+ let compositeInputExpanded = context.expanded;
28
+ if (context.compositeInput) {
29
+ compositeInput = context.compositeInput;
30
+ } else if (context.tagFilter.isActive) {
31
+ compositeInput = {exif: context.parsedGroups.exif, file: context.parsedGroups.file};
32
+ compositeInputExpanded = true;
33
+ }
34
+
35
+ const compositeTags = Composite.get(compositeInput, compositeInputExpanded);
36
+ if (!compositeTags) {
37
+ return tags;
38
+ }
39
+
40
+ const returnedCompositeTags = context.deps.filterTagsForReturn('composite', compositeTags, context.tagFilter);
41
+
42
+ return mergeAssignGroup(tags, 'composite', returnedCompositeTags, context.expanded, context.deps);
43
+ }
@@ -0,0 +1,48 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+
5
+ import {objectAssign} from '../../utils.js';
6
+ import TagNames0thIfd from '../../tag-names-0th-ifd.js';
7
+ import TagNamesExifIfd from '../../tag-names-exif-ifd.js';
8
+ import TagNamesGpsIfd from '../../tag-names-gps-ifd.js';
9
+ import TagNamesInteroperabilityIfd from '../../tag-names-interoperability-ifd.js';
10
+ import {IFD_TYPE_0TH, IFD_TYPE_1ST, IFD_TYPE_EXIF, IFD_TYPE_GPS, IFD_TYPE_INTEROPERABILITY} from '../../ifd-types.js';
11
+ import {EXIF_EMITTED_KINDS, readExifBlock, getExifMergeDescriptor} from '../exif-block-reader.js';
12
+ import {GROUP_BRAND} from '../brand.js';
13
+
14
+ // Merged on the first read rather than at import, so that a bundle without
15
+ // this group drops the dictionaries.
16
+ let tagNames0thAndExifIfds;
17
+
18
+ export const exif = {
19
+ key: 'exif',
20
+ consumes: ['exif'],
21
+ emits: EXIF_EMITTED_KINDS,
22
+ read: (block, ctx) => readExifBlock(block, ctx, getExifTagNames(ctx)),
23
+ merge: getExifMergeDescriptor,
24
+ brand: GROUP_BRAND,
25
+ };
26
+
27
+ // Only the IFDs Tags.read walks; the MPF and maker note readers carry their own
28
+ // dictionaries. The thumbnail one must be there whenever the thumbnail IFD is
29
+ // read, since reading an IFD without its dictionary throws.
30
+ function getExifTagNames(ctx) {
31
+ // Assigned rather than computed keys, which Babel compiles to a helper call each.
32
+ const tagNames = {};
33
+ tagNames[IFD_TYPE_0TH] = getTagNames0thAndExifIfds();
34
+ tagNames[IFD_TYPE_EXIF] = getTagNames0thAndExifIfds();
35
+ tagNames[IFD_TYPE_GPS] = TagNamesGpsIfd;
36
+ tagNames[IFD_TYPE_INTEROPERABILITY] = TagNamesInteroperabilityIfd;
37
+ if (ctx.composed.groups.thumbnail) {
38
+ tagNames[IFD_TYPE_1ST] = TagNames0thIfd;
39
+ }
40
+ return tagNames;
41
+ }
42
+
43
+ function getTagNames0thAndExifIfds() {
44
+ if (tagNames0thAndExifIfds === undefined) {
45
+ tagNames0thAndExifIfds = objectAssign({}, TagNames0thIfd, TagNamesExifIfd);
46
+ }
47
+ return tagNames0thAndExifIfds;
48
+ }
@@ -0,0 +1,75 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+
5
+ import {getCalculatedGpsValue} from '../../tag-names-utils.js';
6
+ import {GROUP_BRAND} from '../brand.js';
7
+
8
+ // Derived from the Exif tags, so it reads no block.
9
+ export const gps = {
10
+ key: 'gps',
11
+ consumes: [],
12
+ emits: [],
13
+ merge: () => ({slot: 'gps', mode: 'gps'}),
14
+ mergeModes: {gps: addGpsGroup},
15
+ brand: GROUP_BRAND,
16
+ };
17
+
18
+ // Expanded output only, derived from the parsed Exif group.
19
+ function addGpsGroup(tags, block, context) {
20
+ if (
21
+ context.expanded
22
+ && context.tagFilter.shouldReturnGroup('gps')
23
+ && context.parsedGroups.exif
24
+ ) {
25
+ const gpsGroup = getGpsGroupFromExifTags(context.parsedGroups.exif);
26
+ if (gpsGroup) {
27
+ tags.gps = context.deps.filterTagsForReturn('gps', gpsGroup, context.tagFilter);
28
+ }
29
+ }
30
+
31
+ return tags;
32
+ }
33
+
34
+ function getGpsGroupFromExifTags(exifTags) {
35
+ let gpsGroup = undefined;
36
+
37
+ if (exifTags.GPSLatitude && exifTags.GPSLatitudeRef) {
38
+ gpsGroup = gpsGroup || {};
39
+ try {
40
+ gpsGroup.Latitude = getCalculatedGpsValue(exifTags.GPSLatitude.value);
41
+ if (exifTags.GPSLatitudeRef.value.join('') === 'S') {
42
+ gpsGroup.Latitude = -gpsGroup.Latitude;
43
+ }
44
+ } catch (error) {
45
+ // Ignore.
46
+ }
47
+ }
48
+
49
+ if (exifTags.GPSLongitude && exifTags.GPSLongitudeRef) {
50
+ gpsGroup = gpsGroup || {};
51
+ try {
52
+ gpsGroup.Longitude = getCalculatedGpsValue(exifTags.GPSLongitude.value);
53
+ if (exifTags.GPSLongitudeRef.value.join('') === 'W') {
54
+ gpsGroup.Longitude = -gpsGroup.Longitude;
55
+ }
56
+ } catch (error) {
57
+ // Ignore.
58
+ }
59
+ }
60
+
61
+ if (exifTags.GPSAltitude && exifTags.GPSAltitudeRef) {
62
+ gpsGroup = gpsGroup || {};
63
+ try {
64
+ gpsGroup.Altitude =
65
+ exifTags.GPSAltitude.value[0] / exifTags.GPSAltitude.value[1];
66
+ if (exifTags.GPSAltitudeRef.value === 1) {
67
+ gpsGroup.Altitude = -gpsGroup.Altitude;
68
+ }
69
+ } catch (error) {
70
+ // Ignore.
71
+ }
72
+ }
73
+
74
+ return gpsGroup;
75
+ }
@@ -0,0 +1,52 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+
5
+ import {isThenable, COMPRESSION_METHOD_NONE} from '../../utils.js';
6
+ import IccTags from '../../icc-tags.js';
7
+ import {parsedTags, getEmbeddableMergeDescriptor} from '../group-helpers.js';
8
+ import {GROUP_BRAND} from '../brand.js';
9
+
10
+ export const icc = {
11
+ key: 'icc',
12
+ consumes: ['icc'],
13
+ emits: [],
14
+ read: readIccBlock,
15
+ merge: (block) => getEmbeddableMergeDescriptor(block, 'icc', 'carriedIcc'),
16
+ suppressions: [{kind: 'icc', isSuppressed: isCarriedIccSuppressed}],
17
+ fromExif: getIccBlockFromExif,
18
+ brand: GROUP_BRAND,
19
+ };
20
+
21
+ // A compressed iCCP gives a thenable in async mode, which defers the block.
22
+ function readIccBlock(block, ctx) {
23
+ if (!hasIccData(block)) {
24
+ return undefined;
25
+ }
26
+ // A compressed profile is read only with the load's budgeted decompression
27
+ // config, which only a png or jxl composition has.
28
+ if (block.chunks[0].compressionMethod !== COMPRESSION_METHOD_NONE && ctx.decompressConfig === undefined) {
29
+ return undefined;
30
+ }
31
+ const readTags = IccTags.read(block.dataView || ctx.dataView, block.chunks, ctx.options.async, ctx.decompressConfig);
32
+ if (isThenable(readTags)) {
33
+ return readTags.then((resolvedTags) => parsedTags('icc', resolvedTags, ctx));
34
+ }
35
+ return parsedTags('icc', readTags, ctx);
36
+ }
37
+
38
+ function isCarriedIccSuppressed(block, finderBlocks) {
39
+ return block.carried !== undefined && finderBlocks.some((finderBlock) => finderBlock.kind === 'icc' && hasIccData(finderBlock));
40
+ }
41
+
42
+ function hasIccData(iccBlock) {
43
+ return iccBlock !== undefined && iccBlock.chunks.length > 0;
44
+ }
45
+
46
+ function getIccBlockFromExif(parsed, exif) {
47
+ if (!parsed['ICC_Profile']) {
48
+ return undefined;
49
+ }
50
+ const profile = parsed['ICC_Profile'].value;
51
+ return {kind: 'icc', dataView: profile, chunks: [{offset: 0, length: profile.length, chunkNumber: 1, chunksTotal: 1}], carried: exif.carried};
52
+ }
@@ -0,0 +1,86 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+
5
+ import IptcTags from '../../iptc-tags.js';
6
+ import IptcTagNames from '../../iptc-tag-names.js';
7
+ import {addDecompressedIptcAllowance} from '../../tags-helpers.js';
8
+ import {parsedTags, getBlockDataView, getEmbeddableMergeDescriptor, isPngTextChunkBlock} from '../group-helpers.js';
9
+ import {getSharedValueBudget} from '../value-budget.js';
10
+ import {GROUP_BRAND} from '../brand.js';
11
+
12
+ export const iptc = /* #__PURE__ */ createIptcGroup(readWithFullDictionary);
13
+ // A composed reader gets a repeatable dataset as an array; the default entry keeps iptc.
14
+ export const composedIptc = /* #__PURE__ */ createIptcGroup(readWithFullDictionaryAsArrays);
15
+
16
+ /**
17
+ * An iptc group that reads its blocks' datasets with the given function.
18
+ *
19
+ * @param {function} readTags Called as IptcTags.read is, and returns the tags.
20
+ * @returns {object} An engine group keyed iptc.
21
+ */
22
+ export function createIptcGroup(readTags) {
23
+ return {
24
+ key: 'iptc',
25
+ consumes: ['iptc'],
26
+ emits: [],
27
+ read: (block, ctx) => readIptcBlock(block, ctx, readTags),
28
+ merge: getIptcMergeDescriptor,
29
+ suppressions: [{kind: 'iptc', isSuppressed: isMainIptcSuppressed}],
30
+ fromExif: getIptcBlockFromExif,
31
+ brand: GROUP_BRAND,
32
+ };
33
+ }
34
+
35
+ // Looked up at call time, so the default entry's reader can be swapped in tests.
36
+ function readWithFullDictionary(view, dataOffset, includeUnknown, tagFilter, valueBudget) {
37
+ return IptcTags.read(view, dataOffset, includeUnknown, tagFilter, valueBudget);
38
+ }
39
+
40
+ function readWithFullDictionaryAsArrays(view, dataOffset, includeUnknown, tagFilter, valueBudget) {
41
+ return withRepeatableAsArrays(IptcTags.read(view, dataOffset, includeUnknown, tagFilter, valueBudget), IptcTagNames['iptc']);
42
+ }
43
+
44
+ /**
45
+ * Turns each repeatable dataset that was read once into an array of its one
46
+ * tag, in place.
47
+ *
48
+ * @param {Object} tags The read tags, keyed by tag name.
49
+ * @param {Object<number, (string|object)>} tagNames The dictionary they were
50
+ * read with, keyed by dataset id.
51
+ * @returns {Object} The same tags.
52
+ */
53
+ export function withRepeatableAsArrays(tags, tagNames) {
54
+ Object.keys(tags).forEach((name) => {
55
+ const tag = tags[name];
56
+ if (!Array.isArray(tag) && tagNames[tag.id] && tagNames[tag.id].repeatable) {
57
+ tags[name] = [tag];
58
+ }
59
+ });
60
+ return tags;
61
+ }
62
+
63
+ // A carried IPTC-NAA draws no allowance; a decompressed raw profile does.
64
+ function readIptcBlock(block, ctx, readTags) {
65
+ const view = getBlockDataView(block, ctx);
66
+ const valueBudget = getSharedValueBudget(ctx);
67
+ if (block.origin === 'rawProfile' && block.decompressed) {
68
+ addDecompressedIptcAllowance(valueBudget, view.byteLength);
69
+ }
70
+ return parsedTags('iptc', readTags(view, block.dataOffset, ctx.options.includeUnknown, ctx.tagFilter, valueBudget), ctx);
71
+ }
72
+
73
+ function getIptcMergeDescriptor(block) {
74
+ return getEmbeddableMergeDescriptor(block, 'iptc', 'carriedIptc');
75
+ }
76
+
77
+ // The main block's IPTC-NAA gives way to an IPTC segment; a brob's never does.
78
+ // The raw-profile rule belongs to the PNG text reader.
79
+ function isMainIptcSuppressed(block, finderBlocks) {
80
+ return block.carried === 'main'
81
+ && finderBlocks.some((finderBlock) => finderBlock.kind === 'iptc' && !isPngTextChunkBlock(finderBlock));
82
+ }
83
+
84
+ function getIptcBlockFromExif(parsed, exif) {
85
+ return parsed['IPTC-NAA'] && {kind: 'iptc', dataView: parsed['IPTC-NAA'].value, dataOffset: 0, carried: exif.carried};
86
+ }
@@ -0,0 +1,21 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+
5
+ import {getEmbeddableMergeDescriptor, mergeMakerNoteGroups, readMakerNoteWithDecoders, getMakerNoteBlockFromExif} from '../group-helpers.js';
6
+ import {canonDecoder} from './canon.js';
7
+ import {pentaxDecoder} from './pentax.js';
8
+ import {GROUP_BRAND} from '../brand.js';
9
+
10
+ // Canon is recognized by Make before Pentax by its type-1 prefix.
11
+ export const makerNotes = {
12
+ key: 'makerNotes',
13
+ consumes: ['makerNote'],
14
+ emits: [],
15
+ decoders: [canonDecoder, pentaxDecoder],
16
+ read: (block, ctx) => readMakerNoteWithDecoders(block, ctx, makerNotes.decoders),
17
+ merge: (block) => getEmbeddableMergeDescriptor(block, 'makerNotes', 'carriedMakerNotes'),
18
+ combine: mergeMakerNoteGroups,
19
+ fromExif: getMakerNoteBlockFromExif,
20
+ brand: GROUP_BRAND,
21
+ };
@@ -0,0 +1,25 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+
5
+ import MpfTags from '../../mpf-tags.js';
6
+ import {parsedTags} from '../group-helpers.js';
7
+ import {getSharedValueBudget} from '../value-budget.js';
8
+ import {GROUP_BRAND} from '../brand.js';
9
+
10
+ export const mpf = {
11
+ key: 'mpf',
12
+ consumes: ['mpf'],
13
+ emits: [],
14
+ read: (block, ctx) => parsedTags('mpf', MpfTags.read(
15
+ ctx.dataView,
16
+ block.dataOffset,
17
+ ctx.options.includeUnknown,
18
+ ctx.options.computed,
19
+ ctx.tagFilter,
20
+ getSharedValueBudget(ctx),
21
+ ctx.getBase64Image
22
+ ), ctx),
23
+ merge: () => ({slot: 'mpf', mode: 'assign'}),
24
+ brand: GROUP_BRAND,
25
+ };
@@ -0,0 +1,34 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+
5
+ import {getStringValueFromArray} from '../../utils.js';
6
+ import PentaxTags from '../../pentax-tags.js';
7
+ import {getEmbeddableMergeDescriptor, mergeMakerNoteGroups, readMakerNoteWithDecoders, getMakerNoteBlockFromExif} from '../group-helpers.js';
8
+ import {getSharedValueBudget} from '../value-budget.js';
9
+ import {GROUP_BRAND} from '../brand.js';
10
+
11
+ export const pentaxDecoder = {
12
+ name: 'pentax',
13
+ matches: (block) => hasPentaxType1Prefix(block.bytes),
14
+ read: (block, ctx) => PentaxTags.read(block.tiffView, block.tiffHeaderOffset, block.makerNoteOffset, ctx.options.includeUnknown, ctx.options.computed, ctx.tagFilter, getSharedValueBudget(ctx)),
15
+ };
16
+
17
+ export const pentax = {
18
+ key: 'makerNotes',
19
+ consumes: ['makerNote'],
20
+ emits: [],
21
+ decoders: [pentaxDecoder],
22
+ read: (block, ctx) => readMakerNoteWithDecoders(block, ctx, pentax.decoders),
23
+ merge: (block) => getEmbeddableMergeDescriptor(block, 'makerNotes', 'carriedMakerNotes'),
24
+ combine: mergeMakerNoteGroups,
25
+ fromExif: getMakerNoteBlockFromExif,
26
+ brand: GROUP_BRAND,
27
+ };
28
+
29
+ function hasPentaxType1Prefix(makerNoteBytes) {
30
+ const PENTAX_ID_STRING = 'PENTAX ';
31
+ return Array.isArray(makerNoteBytes)
32
+ && makerNoteBytes.length > PENTAX_ID_STRING.length
33
+ && getStringValueFromArray(makerNoteBytes.slice(0, PENTAX_ID_STRING.length)) === PENTAX_ID_STRING;
34
+ }
@@ -0,0 +1,18 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+
5
+ import PhotoshopTags from '../../photoshop-tags.js';
6
+ import {parsedTags, getEmbeddableMergeDescriptor} from '../group-helpers.js';
7
+ import {GROUP_BRAND} from '../brand.js';
8
+
9
+ export const photoshop = {
10
+ key: 'photoshop',
11
+ consumes: ['photoshop'],
12
+ emits: [],
13
+ read: (block, ctx) => parsedTags('photoshop', PhotoshopTags.read(block.value, ctx.options.includeUnknown, ctx.tagFilter), ctx),
14
+ merge: (block) => getEmbeddableMergeDescriptor(block, 'photoshop', 'carriedPhotoshop'),
15
+ fromExif: (parsed, exif) => parsed['ImageSourceData'] && parsed['PhotoshopSettings'] && Array.isArray(parsed['PhotoshopSettings'].value)
16
+ && {kind: 'photoshop', value: parsed['PhotoshopSettings'].value, carried: exif.carried},
17
+ brand: GROUP_BRAND,
18
+ };