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/tag-filter.js CHANGED
@@ -2,6 +2,7 @@
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 {setProperty} from './utils.js';
5
6
  import {
6
7
  FILTER_GROUPS,
7
8
  ID_CAPABLE_GROUPS,
@@ -10,7 +11,17 @@ import {
10
11
  getExifTagDependenciesForInclude,
11
12
  } from './tag-filter-config.js';
12
13
 
13
- export function createTagFilter({includeTags, excludeTags} = {}) {
14
+ /**
15
+ * Builds the filter the readers and the merge consult for includeTags and
16
+ * excludeTags.
17
+ *
18
+ * @param {{includeTags: (object|undefined), excludeTags: (object|undefined), includeTagsIsLimit: (boolean|undefined)}} options
19
+ * With `includeTagsIsLimit`, includeTags only caps what is read and
20
+ * excludeTags applies to every group; without it a group listed in both
21
+ * ignores its excludeTags entry.
22
+ * @returns {object} The filter.
23
+ */
24
+ export function createTagFilter({includeTags, excludeTags, includeTagsIsLimit} = {}) {
14
25
  const hasIncludeTags = Boolean(includeTags);
15
26
  const hasExcludeTags = Boolean(excludeTags);
16
27
  const isActive = hasIncludeTags || hasExcludeTags;
@@ -50,12 +61,14 @@ export function createTagFilter({includeTags, excludeTags} = {}) {
50
61
 
51
62
  for (const groupKey in FILTER_GROUPS) {
52
63
  const hasIncludeEntry =
53
- hasIncludeTags && Object.prototype.hasOwnProperty.call(includeTags, groupKey);
64
+ hasIncludeTags
65
+ && Object.prototype.hasOwnProperty.call(includeTags, groupKey)
66
+ && !!includeTags[groupKey];
54
67
  const hasExcludeEntry =
55
68
  hasExcludeTags && Object.prototype.hasOwnProperty.call(excludeTags, groupKey);
56
69
 
57
70
  let excludeValue = undefined;
58
- if (hasExcludeEntry && !hasIncludeEntry) {
71
+ if (hasExcludeEntry && (!hasIncludeEntry || includeTagsIsLimit)) {
59
72
  excludeValue = excludeTags[groupKey];
60
73
  }
61
74
 
@@ -409,3 +422,54 @@ function addRequiredTags(requiredTags, tags) {
409
422
  requiredTags[tags[i]] = true;
410
423
  }
411
424
  }
425
+
426
+ export function filterTagsForParse(groupKey, readTags, tagFilter) {
427
+ if (!tagFilter.isActive) {
428
+ return readTags;
429
+ }
430
+
431
+ return filterTags(groupKey, readTags, tagFilter.shouldParseTag);
432
+ }
433
+
434
+ export function filterTagsForReturn(groupKey, readTags, tagFilter) {
435
+ if (!tagFilter.isActive) {
436
+ return readTags;
437
+ }
438
+
439
+ return filterTags(groupKey, readTags, tagFilter.shouldReturnTag);
440
+ }
441
+
442
+ export function filterTags(groupKey, readTags, matchesTag) {
443
+ if (!readTags) {
444
+ return readTags;
445
+ }
446
+
447
+ const filteredTags = {};
448
+
449
+ for (const tagName in readTags) {
450
+ const tagValue = readTags[tagName];
451
+ const tagId = getTagId(tagValue);
452
+
453
+ if (matchesTag(groupKey, tagName, tagId)) {
454
+ setProperty(filteredTags, tagName, tagValue);
455
+ }
456
+ }
457
+
458
+ return filteredTags;
459
+
460
+ function getTagId(tagValue) {
461
+ if (!tagValue) {
462
+ return undefined;
463
+ }
464
+
465
+ if (Array.isArray(tagValue)) {
466
+ if (tagValue.length === 0) {
467
+ return undefined;
468
+ }
469
+
470
+ return tagValue[0].id;
471
+ }
472
+
473
+ return tagValue.id;
474
+ }
475
+ }
@@ -0,0 +1,232 @@
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 {joinMapped} from './utils.js';
6
+ import {getTableDescription, isArrayWithoutCharacterCodes, getStringsText} from './tag-names-utils.js';
7
+
8
+ export function getSubfileTypeDescription(value) {
9
+ return getTableDescription({
10
+ 0x0: 'Full-resolution image',
11
+ 0x1: 'Reduced-resolution image',
12
+ 0x2: 'Single page of multi-page image',
13
+ 0x3: 'Single page of multi-page reduced-resolution image',
14
+ 0x4: 'Transparency mask',
15
+ 0x5: 'Transparency mask of reduced-resolution image',
16
+ 0x6: 'Transparency mask of multi-page image',
17
+ 0x7: 'Transparency mask of reduced-resolution multi-page image',
18
+ 0x10001: 'Alternate reduced-resolution image',
19
+ 0xffffffff: 'Invalid'
20
+ }, value);
21
+ }
22
+
23
+ export function getOldSubfileTypeDescription(value) {
24
+ return getTableDescription({
25
+ 0: 'Full-resolution image',
26
+ 1: 'Reduced-resolution image',
27
+ 2: 'Single page of multi-page image'
28
+ }, value);
29
+ }
30
+
31
+ export function getThresholdingDescription(value) {
32
+ return getTableDescription({
33
+ 1: 'No dithering or halftoning',
34
+ 2: 'Ordered dither or halfton',
35
+ 3: 'Randomized dither'
36
+ }, value);
37
+ }
38
+
39
+ export function getFillOrderDescription(value) {
40
+ return getTableDescription({
41
+ 1: 'Normal',
42
+ 2: 'Reversed'
43
+ }, value);
44
+ }
45
+
46
+ export function getOrientationDescription(value) {
47
+ if (value === 1) {
48
+ return 'top-left';
49
+ }
50
+ if (value === 2) {
51
+ return 'top-right';
52
+ }
53
+ if (value === 3) {
54
+ return 'bottom-right';
55
+ }
56
+ if (value === 4) {
57
+ return 'bottom-left';
58
+ }
59
+ if (value === 5) {
60
+ return 'left-top';
61
+ }
62
+ if (value === 6) {
63
+ return 'right-top';
64
+ }
65
+ if (value === 7) {
66
+ return 'right-bottom';
67
+ }
68
+ if (value === 8) {
69
+ return 'left-bottom';
70
+ }
71
+ return 'Undefined';
72
+ }
73
+
74
+ export function getXPositionDescription(value) {
75
+ return '' + Math.round(value[0] / value[1]);
76
+ }
77
+
78
+ export function getYPositionDescription(value) {
79
+ return '' + Math.round(value[0] / value[1]);
80
+ }
81
+
82
+ export function getGrayResponseUnitDescription(value) {
83
+ return getTableDescription({
84
+ 1: '0.1',
85
+ 2: '0.001',
86
+ 3: '0.0001',
87
+ 4: '1e-05',
88
+ 5: '1e-06'
89
+ }, value);
90
+ }
91
+
92
+ export function getWhitePointDescription(values) {
93
+ return joinMapped(values, getRationalText, ', ');
94
+ }
95
+
96
+ export function getPrimaryChromaticitiesDescription(values) {
97
+ return joinMapped(values, getRationalText, ', ');
98
+ }
99
+
100
+ export function getInkSetDescription(value) {
101
+ return getTableDescription({
102
+ 1: 'CMYK',
103
+ 2: 'Not CMYK'
104
+ }, value);
105
+ }
106
+
107
+ export function getExtraSamplesDescription(value) {
108
+ return getTableDescription({
109
+ 0: 'Unspecified',
110
+ 1: 'Associated Alpha',
111
+ 2: 'Unassociated Alpha',
112
+ }, value);
113
+ }
114
+
115
+ export function getSampleFormatDescription(value) {
116
+ if (!Array.isArray(value)) {
117
+ return getSampleFormatText(value);
118
+ }
119
+ return value.map(getSampleFormatText).join(', ');
120
+ }
121
+
122
+ export function getYCbCrCoefficientsDescription(values) {
123
+ return values.map((value) => '' + value[0] / value[1]).join('/');
124
+ }
125
+
126
+ export function getYCbCrPositioningDescription(value) {
127
+ if (value === 1) {
128
+ return 'centered';
129
+ }
130
+ if (value === 2) {
131
+ return 'co-sited';
132
+ }
133
+ return 'undefined ' + value;
134
+ }
135
+
136
+ export function getReferenceBlackWhiteDescription(values) {
137
+ return values.map((value) => '' + value[0] / value[1]).join(', ');
138
+ }
139
+
140
+ export function getCopyrightDescription(value) {
141
+ return value.join('; ');
142
+ }
143
+
144
+ export function getMakerNoteSafetyDescription(value) {
145
+ return getTableDescription({
146
+ 0: 'Unsafe',
147
+ 1: 'Safe'
148
+ }, value);
149
+ }
150
+
151
+ export function getProfileEmbedPolicyDescription(value) {
152
+ return getTableDescription({
153
+ 0: 'Allow Copying',
154
+ 1: 'Embed if Used',
155
+ 2: 'Never Embed',
156
+ 3: 'No Restrictions'
157
+ }, value);
158
+ }
159
+
160
+ export function getPreviewColorSpaceDescription(value) {
161
+ return getTableDescription({
162
+ 1: 'Gray Gamma 2.2',
163
+ 2: 'sRGB',
164
+ 3: 'Adobe RGB',
165
+ 4: 'ProPhoto RGB'
166
+ }, value);
167
+ }
168
+
169
+ export function getProfileHueSatMapEncodingDescription(value) {
170
+ return getTableDescription({
171
+ 0: 'Linear',
172
+ 1: 'sRGB'
173
+ }, value);
174
+ }
175
+
176
+ export function getProfileLookTableEncodingDescription(value) {
177
+ return getTableDescription({
178
+ 0: 'Linear',
179
+ 1: 'sRGB'
180
+ }, value);
181
+ }
182
+
183
+ export function getDefaultBlackRenderDescription(value) {
184
+ return getTableDescription({
185
+ 0: 'Auto',
186
+ 1: 'None'
187
+ }, value);
188
+ }
189
+
190
+ function getRationalText(value) {
191
+ if (!Array.isArray(value)) {
192
+ throw new TypeError('Expected a rational.');
193
+ }
194
+ return `${value[0]}/${value[1]}`;
195
+ }
196
+
197
+ function getSampleFormatText(sample) {
198
+ const formats = {
199
+ 1: 'Unsigned',
200
+ 2: 'Signed',
201
+ 3: 'Float',
202
+ 4: 'Undefined',
203
+ 5: 'Complex int',
204
+ 6: 'Complex float',
205
+ };
206
+ return getTableDescription(formats, sample);
207
+ }
208
+
209
+ export function decodeXPValue(value) {
210
+ if (!Array.isArray(value)) {
211
+ // A one-element value arrives as a bare number, which Uint8Array would take as a length.
212
+ return '';
213
+ }
214
+ if (isArrayWithoutCharacterCodes(value)) {
215
+ // An ASCII-typed value holds strings, not UCS-2 bytes.
216
+ return getStringsText(value);
217
+ }
218
+ // The XP tags are encoded as UCS-2 which uses two bytes per character but
219
+ // it's close to UTF-16 so we can use that to decode them.
220
+ // https://www.loc.gov/preservation/digital/formats/content/tiff_tags.shtml
221
+ const decodedValue = new TextDecoder('utf-16').decode(new Uint8Array(value));
222
+ // Some softwares pad the string with null characters so we remove them.
223
+ return removeTrailingNulls(decodedValue);
224
+ }
225
+
226
+ function removeTrailingNulls(text) {
227
+ let end = text.length;
228
+ while (end > 0 && text.charCodeAt(end - 1) === 0) {
229
+ end--;
230
+ }
231
+ return text.slice(0, end);
232
+ }
@@ -3,33 +3,42 @@
3
3
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
4
 
5
5
  import TagNamesCommon from './tag-names-common.js';
6
- import {joinMapped} from './utils.js';
7
- import {getTableDescription, isStringValue, getStringsText} from './tag-names-utils.js';
6
+ import {
7
+ getSubfileTypeDescription,
8
+ getOldSubfileTypeDescription,
9
+ getThresholdingDescription,
10
+ getFillOrderDescription,
11
+ getOrientationDescription,
12
+ getXPositionDescription,
13
+ getYPositionDescription,
14
+ getGrayResponseUnitDescription,
15
+ getWhitePointDescription,
16
+ getPrimaryChromaticitiesDescription,
17
+ getInkSetDescription,
18
+ getExtraSamplesDescription,
19
+ getSampleFormatDescription,
20
+ getYCbCrCoefficientsDescription,
21
+ getYCbCrPositioningDescription,
22
+ getReferenceBlackWhiteDescription,
23
+ getCopyrightDescription,
24
+ decodeXPValue,
25
+ getMakerNoteSafetyDescription,
26
+ getProfileEmbedPolicyDescription,
27
+ getPreviewColorSpaceDescription,
28
+ getProfileHueSatMapEncodingDescription,
29
+ getProfileLookTableEncodingDescription,
30
+ getDefaultBlackRenderDescription
31
+ } from './tag-names-0th-ifd-descriptions.js';
8
32
 
9
33
  export default {
10
34
  0x000b: 'ProcessingSoftware',
11
35
  0x00fe: {
12
36
  name: 'SubfileType',
13
- description: (value) => getTableDescription({
14
- 0x0: 'Full-resolution image',
15
- 0x1: 'Reduced-resolution image',
16
- 0x2: 'Single page of multi-page image',
17
- 0x3: 'Single page of multi-page reduced-resolution image',
18
- 0x4: 'Transparency mask',
19
- 0x5: 'Transparency mask of reduced-resolution image',
20
- 0x6: 'Transparency mask of multi-page image',
21
- 0x7: 'Transparency mask of reduced-resolution multi-page image',
22
- 0x10001: 'Alternate reduced-resolution image',
23
- 0xffffffff: 'Invalid'
24
- }, value)
37
+ description: getSubfileTypeDescription
25
38
  },
26
39
  0x00ff: {
27
40
  name: 'OldSubfileType',
28
- description: (value) => getTableDescription({
29
- 0: 'Full-resolution image',
30
- 1: 'Reduced-resolution image',
31
- 2: 'Single page of multi-page image'
32
- }, value)
41
+ description: getOldSubfileTypeDescription
33
42
  },
34
43
  0x0100: 'ImageWidth',
35
44
  0x0101: 'ImageLength',
@@ -38,20 +47,13 @@ export default {
38
47
  0x0106: 'PhotometricInterpretation',
39
48
  0x0107: {
40
49
  name: 'Thresholding',
41
- description: (value) => getTableDescription({
42
- 1: 'No dithering or halftoning',
43
- 2: 'Ordered dither or halfton',
44
- 3: 'Randomized dither'
45
- }, value)
50
+ description: getThresholdingDescription
46
51
  },
47
52
  0x0108: 'CellWidth',
48
53
  0x0109: 'CellLength',
49
54
  0x010a: {
50
55
  name: 'FillOrder',
51
- description: (value) => getTableDescription({
52
- 1: 'Normal',
53
- 2: 'Reversed'
54
- }, value)
56
+ description: getFillOrderDescription
55
57
  },
56
58
  0x010d: 'DocumentName',
57
59
  0x010e: 'ImageDescription',
@@ -60,33 +62,7 @@ export default {
60
62
  0x0111: 'StripOffsets',
61
63
  0x0112: {
62
64
  name: 'Orientation',
63
- description: (value) => {
64
- if (value === 1) {
65
- return 'top-left';
66
- }
67
- if (value === 2) {
68
- return 'top-right';
69
- }
70
- if (value === 3) {
71
- return 'bottom-right';
72
- }
73
- if (value === 4) {
74
- return 'bottom-left';
75
- }
76
- if (value === 5) {
77
- return 'left-top';
78
- }
79
- if (value === 6) {
80
- return 'right-top';
81
- }
82
- if (value === 7) {
83
- return 'right-bottom';
84
- }
85
- if (value === 8) {
86
- return 'left-bottom';
87
- }
88
- return 'Undefined';
89
- }
65
+ description: getOrientationDescription
90
66
  },
91
67
  0x0115: 'SamplesPerPixel',
92
68
  0x0116: 'RowsPerStrip',
@@ -105,25 +81,15 @@ export default {
105
81
  0x011d: 'PageName',
106
82
  0x011e: {
107
83
  'name': 'XPosition',
108
- 'description': (value) => {
109
- return '' + Math.round(value[0] / value[1]);
110
- }
84
+ 'description': getXPositionDescription
111
85
  },
112
86
  0x011f: {
113
87
  'name': 'YPosition',
114
- 'description': (value) => {
115
- return '' + Math.round(value[0] / value[1]);
116
- }
88
+ 'description': getYPositionDescription
117
89
  },
118
90
  0x0122: {
119
91
  name: 'GrayResponseUnit',
120
- description: (value) => getTableDescription({
121
- 1: '0.1',
122
- 2: '0.001',
123
- 3: '0.0001',
124
- 4: '1e-05',
125
- 5: '1e-06'
126
- }, value)
92
+ description: getGrayResponseUnitDescription
127
93
  },
128
94
  0x0128: {
129
95
  name: 'ResolutionUnit',
@@ -138,11 +104,11 @@ export default {
138
104
  0x013d: 'Predictor',
139
105
  0x013e: {
140
106
  'name': 'WhitePoint',
141
- 'description': (values) => joinMapped(values, getRationalText, ', ')
107
+ 'description': getWhitePointDescription
142
108
  },
143
109
  0x013f: {
144
110
  'name': 'PrimaryChromaticities',
145
- 'description': (values) => joinMapped(values, getRationalText, ', ')
111
+ 'description': getPrimaryChromaticitiesDescription
146
112
  },
147
113
  0x0141: 'HalftoneHints',
148
114
  0x0142: 'TileWidth',
@@ -150,62 +116,38 @@ export default {
150
116
  0x014a: 'A100DataOffset',
151
117
  0x014c: {
152
118
  name: 'InkSet',
153
- description: (value) => getTableDescription({
154
- 1: 'CMYK',
155
- 2: 'Not CMYK'
156
- }, value)
119
+ description: getInkSetDescription
157
120
  },
158
121
  0x0151: 'TargetPrinter',
159
122
  0x0152: {
160
123
  name: 'ExtraSamples',
161
- description: (value) => getTableDescription({
162
- 0: 'Unspecified',
163
- 1: 'Associated Alpha',
164
- 2: 'Unassociated Alpha',
165
- }, value)
124
+ description: getExtraSamplesDescription
166
125
  },
167
126
  0x0153: {
168
127
  name: 'SampleFormat',
169
- description: (value) => {
170
- if (!Array.isArray(value)) {
171
- return getSampleFormatText(value);
172
- }
173
- return value.map(getSampleFormatText).join(', ');
174
- }
128
+ description: getSampleFormatDescription
175
129
  },
176
130
  0x0201: 'JPEGInterchangeFormat',
177
131
  0x0202: 'JPEGInterchangeFormatLength',
178
132
  0x0211: {
179
133
  'name': 'YCbCrCoefficients',
180
- 'description': (values) => {
181
- return values.map((value) => '' + value[0] / value[1]).join('/');
182
- }
134
+ 'description': getYCbCrCoefficientsDescription
183
135
  },
184
136
  0x0212: 'YCbCrSubSampling',
185
137
  0x0213: {
186
138
  name: 'YCbCrPositioning',
187
- description: (value) => {
188
- if (value === 1) {
189
- return 'centered';
190
- }
191
- if (value === 2) {
192
- return 'co-sited';
193
- }
194
- return 'undefined ' + value;
195
- }
139
+ description: getYCbCrPositioningDescription
196
140
  },
197
141
  0x0214: {
198
142
  'name': 'ReferenceBlackWhite',
199
- 'description': (values) => {
200
- return values.map((value) => '' + value[0] / value[1]).join(', ');
201
- }
143
+ 'description': getReferenceBlackWhiteDescription
202
144
  },
203
145
  0x02bc: 'ApplicationNotes',
204
146
  0x4746: 'Rating',
205
147
  0x4749: 'RatingPercent',
206
148
  0x8298: {
207
149
  name: 'Copyright',
208
- description: (value) => value.join('; ')
150
+ description: getCopyrightDescription
209
151
  },
210
152
  0x830e: 'PixelScale',
211
153
  0x83bb: 'IPTC-NAA',
@@ -264,10 +206,7 @@ export default {
264
206
  0xc633: 'ShadowScale',
265
207
  0xc635: {
266
208
  name: 'MakerNoteSafety',
267
- description: (value) => getTableDescription({
268
- 0: 'Unsafe',
269
- 1: 'Safe'
270
- }, value)
209
+ description: getMakerNoteSafetyDescription
271
210
  },
272
211
  0xc65a: {
273
212
  name: 'CalibrationIlluminant1',
@@ -299,12 +238,7 @@ export default {
299
238
  0xc6fc: 'ProfileToneCurve',
300
239
  0xc6fd: {
301
240
  name: 'ProfileEmbedPolicy',
302
- description: (value) => getTableDescription({
303
- 0: 'Allow Copying',
304
- 1: 'Embed if Used',
305
- 2: 'Never Embed',
306
- 3: 'No Restrictions'
307
- }, value)
241
+ description: getProfileEmbedPolicyDescription
308
242
  },
309
243
  0xc6fe: 'ProfileCopyright',
310
244
  0xc714: 'ForwardMatrix1',
@@ -315,12 +249,7 @@ export default {
315
249
  0xc719: 'PreviewSettingsDigest',
316
250
  0xc71a: {
317
251
  name: 'PreviewColorSpace',
318
- description: (value) => getTableDescription({
319
- 1: 'Gray Gamma 2.2',
320
- 2: 'sRGB',
321
- 3: 'Adobe RGB',
322
- 4: 'ProPhoto RGB'
323
- }, value)
252
+ description: getPreviewColorSpaceDescription
324
253
  },
325
254
  0xc71b: 'PreviewDateTime',
326
255
  0xc71c: 'RawImageDigest',
@@ -337,70 +266,17 @@ export default {
337
266
  0xc7a1: 'CameraLabel',
338
267
  0xc7a3: {
339
268
  name: 'ProfileHueSatMapEncoding',
340
- description: (value) => getTableDescription({
341
- 0: 'Linear',
342
- 1: 'sRGB'
343
- }, value)
269
+ description: getProfileHueSatMapEncodingDescription
344
270
  },
345
271
  0xc7a4: {
346
272
  name: 'ProfileLookTableEncoding',
347
- description: (value) => getTableDescription({
348
- 0: 'Linear',
349
- 1: 'sRGB'
350
- }, value)
273
+ description: getProfileLookTableEncodingDescription
351
274
  },
352
275
  0xc7a5: 'BaselineExposureOffset',
353
276
  0xc7a6: {
354
277
  name: 'DefaultBlackRender',
355
- description: (value) => getTableDescription({
356
- 0: 'Auto',
357
- 1: 'None'
358
- }, value)
278
+ description: getDefaultBlackRenderDescription
359
279
  },
360
280
  0xc7a7: 'NewRawImageDigest',
361
281
  0xc7a8: 'RawToPreviewGain'
362
282
  };
363
-
364
- function getRationalText(value) {
365
- if (!Array.isArray(value)) {
366
- throw new TypeError('Expected a rational.');
367
- }
368
- return `${value[0]}/${value[1]}`;
369
- }
370
-
371
- function getSampleFormatText(sample) {
372
- const formats = {
373
- 1: 'Unsigned',
374
- 2: 'Signed',
375
- 3: 'Float',
376
- 4: 'Undefined',
377
- 5: 'Complex int',
378
- 6: 'Complex float',
379
- };
380
- return getTableDescription(formats, sample);
381
- }
382
-
383
- function decodeXPValue(value) {
384
- if (!Array.isArray(value)) {
385
- // A one-element value arrives as a bare number, which Uint8Array would take as a length.
386
- return '';
387
- }
388
- if (isStringValue(value)) {
389
- // An ASCII-typed value holds strings, not UCS-2 bytes.
390
- return getStringsText(value);
391
- }
392
- // The XP tags are encoded as UCS-2 which uses two bytes per character but
393
- // it's close to UTF-16 so we can use that to decode them.
394
- // https://www.loc.gov/preservation/digital/formats/content/tiff_tags.shtml
395
- const decodedValue = new TextDecoder('utf-16').decode(new Uint8Array(value));
396
- // Some softwares pad the string with null characters so we remove them.
397
- return removeTrailingNulls(decodedValue);
398
- }
399
-
400
- function removeTrailingNulls(text) {
401
- let end = text.length;
402
- while (end > 0 && text.charCodeAt(end - 1) === 0) {
403
- end--;
404
- }
405
- return text.slice(0, end);
406
- }