exifreader 4.48.0 → 4.49.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.
- package/README.md +66 -46
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +6 -6
- package/package.json +5 -5
- package/src/canon-tags.js +4 -3
- package/src/exif-reader.js +247 -166
- package/src/icc-tag-names.js +2 -11
- package/src/image-header-iso-bmff.js +261 -39
- package/src/image-header-jxl.js +6 -6
- package/src/image-header-png.js +1 -6
- package/src/iptc-tag-names.js +35 -17
- package/src/iso-bmff-file-tags.js +86 -0
- package/src/loadview-pipeline.js +106 -28
- package/src/photoshop-tags.js +9 -1
- package/src/png-text-tags.js +94 -52
- package/src/tag-decoder.js +3 -3
- package/src/tag-filter-config.js +23 -0
- package/src/tag-names-0th-ifd.js +51 -42
- package/src/tag-names-common.js +19 -15
- package/src/tag-names-exif-ifd.js +38 -17
- package/src/tag-names-interoperability-ifd.js +2 -2
- package/src/tag-names-mpf-ifd.js +2 -2
- package/src/tag-names-utils.js +38 -3
- package/src/tags-helpers.js +20 -0
- package/src/utils.js +102 -16
- package/src/xmp-tag-names.js +1 -1
- package/src/xmp-tags.js +9 -6
package/src/tag-names-0th-ifd.js
CHANGED
|
@@ -3,12 +3,14 @@
|
|
|
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} from './tag-names-utils.js';
|
|
6
8
|
|
|
7
9
|
export default {
|
|
8
10
|
0x000b: 'ProcessingSoftware',
|
|
9
11
|
0x00fe: {
|
|
10
12
|
name: 'SubfileType',
|
|
11
|
-
description: (value) => ({
|
|
13
|
+
description: (value) => getTableDescription({
|
|
12
14
|
0x0: 'Full-resolution image',
|
|
13
15
|
0x1: 'Reduced-resolution image',
|
|
14
16
|
0x2: 'Single page of multi-page image',
|
|
@@ -19,15 +21,15 @@ export default {
|
|
|
19
21
|
0x7: 'Transparency mask of reduced-resolution multi-page image',
|
|
20
22
|
0x10001: 'Alternate reduced-resolution image',
|
|
21
23
|
0xffffffff: 'Invalid'
|
|
22
|
-
})
|
|
24
|
+
}, value)
|
|
23
25
|
},
|
|
24
26
|
0x00ff: {
|
|
25
27
|
name: 'OldSubfileType',
|
|
26
|
-
description: (value) => ({
|
|
28
|
+
description: (value) => getTableDescription({
|
|
27
29
|
0: 'Full-resolution image',
|
|
28
30
|
1: 'Reduced-resolution image',
|
|
29
31
|
2: 'Single page of multi-page image'
|
|
30
|
-
})
|
|
32
|
+
}, value)
|
|
31
33
|
},
|
|
32
34
|
0x0100: 'ImageWidth',
|
|
33
35
|
0x0101: 'ImageLength',
|
|
@@ -36,20 +38,20 @@ export default {
|
|
|
36
38
|
0x0106: 'PhotometricInterpretation',
|
|
37
39
|
0x0107: {
|
|
38
40
|
name: 'Thresholding',
|
|
39
|
-
description: (value) => ({
|
|
41
|
+
description: (value) => getTableDescription({
|
|
40
42
|
1: 'No dithering or halftoning',
|
|
41
43
|
2: 'Ordered dither or halfton',
|
|
42
44
|
3: 'Randomized dither'
|
|
43
|
-
})
|
|
45
|
+
}, value)
|
|
44
46
|
},
|
|
45
47
|
0x0108: 'CellWidth',
|
|
46
48
|
0x0109: 'CellLength',
|
|
47
49
|
0x010a: {
|
|
48
50
|
name: 'FillOrder',
|
|
49
|
-
description: (value) => ({
|
|
51
|
+
description: (value) => getTableDescription({
|
|
50
52
|
1: 'Normal',
|
|
51
53
|
2: 'Reversed'
|
|
52
|
-
})
|
|
54
|
+
}, value)
|
|
53
55
|
},
|
|
54
56
|
0x010d: 'DocumentName',
|
|
55
57
|
0x010e: 'ImageDescription',
|
|
@@ -115,13 +117,13 @@ export default {
|
|
|
115
117
|
},
|
|
116
118
|
0x0122: {
|
|
117
119
|
name: 'GrayResponseUnit',
|
|
118
|
-
description: (value) => ({
|
|
120
|
+
description: (value) => getTableDescription({
|
|
119
121
|
1: '0.1',
|
|
120
122
|
2: '0.001',
|
|
121
123
|
3: '0.0001',
|
|
122
124
|
4: '1e-05',
|
|
123
125
|
5: '1e-06'
|
|
124
|
-
})
|
|
126
|
+
}, value)
|
|
125
127
|
},
|
|
126
128
|
0x0128: {
|
|
127
129
|
name: 'ResolutionUnit',
|
|
@@ -136,15 +138,11 @@ export default {
|
|
|
136
138
|
0x013d: 'Predictor',
|
|
137
139
|
0x013e: {
|
|
138
140
|
'name': 'WhitePoint',
|
|
139
|
-
'description': (values) =>
|
|
140
|
-
return values.map((value) => `${value[0]}/${value[1]}`).join(', ');
|
|
141
|
-
}
|
|
141
|
+
'description': (values) => joinMapped(values, getRationalText, ', ')
|
|
142
142
|
},
|
|
143
143
|
0x013f: {
|
|
144
144
|
'name': 'PrimaryChromaticities',
|
|
145
|
-
'description': (values) =>
|
|
146
|
-
return values.map((value) => `${value[0]}/${value[1]}`).join(', ');
|
|
147
|
-
}
|
|
145
|
+
'description': (values) => joinMapped(values, getRationalText, ', ')
|
|
148
146
|
},
|
|
149
147
|
0x0141: 'HalftoneHints',
|
|
150
148
|
0x0142: 'TileWidth',
|
|
@@ -152,35 +150,27 @@ export default {
|
|
|
152
150
|
0x014a: 'A100DataOffset',
|
|
153
151
|
0x014c: {
|
|
154
152
|
name: 'InkSet',
|
|
155
|
-
description: (value) => ({
|
|
153
|
+
description: (value) => getTableDescription({
|
|
156
154
|
1: 'CMYK',
|
|
157
155
|
2: 'Not CMYK'
|
|
158
|
-
})
|
|
156
|
+
}, value)
|
|
159
157
|
},
|
|
160
158
|
0x0151: 'TargetPrinter',
|
|
161
159
|
0x0152: {
|
|
162
160
|
name: 'ExtraSamples',
|
|
163
|
-
description: (value) => ({
|
|
161
|
+
description: (value) => getTableDescription({
|
|
164
162
|
0: 'Unspecified',
|
|
165
163
|
1: 'Associated Alpha',
|
|
166
164
|
2: 'Unassociated Alpha',
|
|
167
|
-
})
|
|
165
|
+
}, value)
|
|
168
166
|
},
|
|
169
167
|
0x0153: {
|
|
170
168
|
name: 'SampleFormat',
|
|
171
169
|
description: (value) => {
|
|
172
|
-
const formats = {
|
|
173
|
-
1: 'Unsigned',
|
|
174
|
-
2: 'Signed',
|
|
175
|
-
3: 'Float',
|
|
176
|
-
4: 'Undefined',
|
|
177
|
-
5: 'Complex int',
|
|
178
|
-
6: 'Complex float',
|
|
179
|
-
};
|
|
180
170
|
if (!Array.isArray(value)) {
|
|
181
|
-
return
|
|
171
|
+
return getSampleFormatText(value);
|
|
182
172
|
}
|
|
183
|
-
return value.map(
|
|
173
|
+
return value.map(getSampleFormatText).join(', ');
|
|
184
174
|
}
|
|
185
175
|
},
|
|
186
176
|
0x0201: 'JPEGInterchangeFormat',
|
|
@@ -274,10 +264,10 @@ export default {
|
|
|
274
264
|
0xc633: 'ShadowScale',
|
|
275
265
|
0xc635: {
|
|
276
266
|
name: 'MakerNoteSafety',
|
|
277
|
-
description: (value) => ({
|
|
267
|
+
description: (value) => getTableDescription({
|
|
278
268
|
0: 'Unsafe',
|
|
279
269
|
1: 'Safe'
|
|
280
|
-
})
|
|
270
|
+
}, value)
|
|
281
271
|
},
|
|
282
272
|
0xc65a: {
|
|
283
273
|
name: 'CalibrationIlluminant1',
|
|
@@ -309,12 +299,12 @@ export default {
|
|
|
309
299
|
0xc6fc: 'ProfileToneCurve',
|
|
310
300
|
0xc6fd: {
|
|
311
301
|
name: 'ProfileEmbedPolicy',
|
|
312
|
-
description: (value) => ({
|
|
302
|
+
description: (value) => getTableDescription({
|
|
313
303
|
0: 'Allow Copying',
|
|
314
304
|
1: 'Embed if Used',
|
|
315
305
|
2: 'Never Embed',
|
|
316
306
|
3: 'No Restrictions'
|
|
317
|
-
})
|
|
307
|
+
}, value)
|
|
318
308
|
},
|
|
319
309
|
0xc6fe: 'ProfileCopyright',
|
|
320
310
|
0xc714: 'ForwardMatrix1',
|
|
@@ -325,12 +315,12 @@ export default {
|
|
|
325
315
|
0xc719: 'PreviewSettingsDigest',
|
|
326
316
|
0xc71a: {
|
|
327
317
|
name: 'PreviewColorSpace',
|
|
328
|
-
description: (value) => ({
|
|
318
|
+
description: (value) => getTableDescription({
|
|
329
319
|
1: 'Gray Gamma 2.2',
|
|
330
320
|
2: 'sRGB',
|
|
331
321
|
3: 'Adobe RGB',
|
|
332
322
|
4: 'ProPhoto RGB'
|
|
333
|
-
})
|
|
323
|
+
}, value)
|
|
334
324
|
},
|
|
335
325
|
0xc71b: 'PreviewDateTime',
|
|
336
326
|
0xc71c: 'RawImageDigest',
|
|
@@ -347,30 +337,49 @@ export default {
|
|
|
347
337
|
0xc7a1: 'CameraLabel',
|
|
348
338
|
0xc7a3: {
|
|
349
339
|
name: 'ProfileHueSatMapEncoding',
|
|
350
|
-
description: (value) => ({
|
|
340
|
+
description: (value) => getTableDescription({
|
|
351
341
|
0: 'Linear',
|
|
352
342
|
1: 'sRGB'
|
|
353
|
-
})
|
|
343
|
+
}, value)
|
|
354
344
|
},
|
|
355
345
|
0xc7a4: {
|
|
356
346
|
name: 'ProfileLookTableEncoding',
|
|
357
|
-
description: (value) => ({
|
|
347
|
+
description: (value) => getTableDescription({
|
|
358
348
|
0: 'Linear',
|
|
359
349
|
1: 'sRGB'
|
|
360
|
-
})
|
|
350
|
+
}, value)
|
|
361
351
|
},
|
|
362
352
|
0xc7a5: 'BaselineExposureOffset',
|
|
363
353
|
0xc7a6: {
|
|
364
354
|
name: 'DefaultBlackRender',
|
|
365
|
-
description: (value) => ({
|
|
355
|
+
description: (value) => getTableDescription({
|
|
366
356
|
0: 'Auto',
|
|
367
357
|
1: 'None'
|
|
368
|
-
})
|
|
358
|
+
}, value)
|
|
369
359
|
},
|
|
370
360
|
0xc7a7: 'NewRawImageDigest',
|
|
371
361
|
0xc7a8: 'RawToPreviewGain'
|
|
372
362
|
};
|
|
373
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
|
+
|
|
374
383
|
function decodeXPValue(value) {
|
|
375
384
|
if (!Array.isArray(value)) {
|
|
376
385
|
// A one-element value arrives as a bare number, which Uint8Array would take as a length.
|
package/src/tag-names-common.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
3
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
4
|
|
|
5
|
+
import {joinMapped} from './utils.js';
|
|
6
|
+
|
|
5
7
|
export default {
|
|
6
8
|
ApertureValue: (value) => Math.pow(Math.sqrt(2), value[0] / value[1]).toFixed(2),
|
|
7
9
|
ColorSpace(value) {
|
|
@@ -13,21 +15,7 @@ export default {
|
|
|
13
15
|
return 'Unknown';
|
|
14
16
|
},
|
|
15
17
|
ComponentsConfiguration(value) {
|
|
16
|
-
return value
|
|
17
|
-
if (character === 0x31) {
|
|
18
|
-
return 'Y';
|
|
19
|
-
} else if (character === 0x32) {
|
|
20
|
-
return 'Cb';
|
|
21
|
-
} else if (character === 0x33) {
|
|
22
|
-
return 'Cr';
|
|
23
|
-
} else if (character === 0x34) {
|
|
24
|
-
return 'R';
|
|
25
|
-
} else if (character === 0x35) {
|
|
26
|
-
return 'G';
|
|
27
|
-
} else if (character === 0x36) {
|
|
28
|
-
return 'B';
|
|
29
|
-
}
|
|
30
|
-
}).join('');
|
|
18
|
+
return joinMapped(value, getComponentText, '');
|
|
31
19
|
},
|
|
32
20
|
Contrast(value) {
|
|
33
21
|
if (value === 0) {
|
|
@@ -233,3 +221,19 @@ export default {
|
|
|
233
221
|
XResolution: (value) => '' + Math.round(value[0] / value[1]),
|
|
234
222
|
YResolution: (value) => '' + Math.round(value[0] / value[1])
|
|
235
223
|
};
|
|
224
|
+
|
|
225
|
+
function getComponentText(component) {
|
|
226
|
+
if (component === 1) {
|
|
227
|
+
return 'Y';
|
|
228
|
+
} else if (component === 2) {
|
|
229
|
+
return 'Cb';
|
|
230
|
+
} else if (component === 3) {
|
|
231
|
+
return 'Cr';
|
|
232
|
+
} else if (component === 4) {
|
|
233
|
+
return 'R';
|
|
234
|
+
} else if (component === 5) {
|
|
235
|
+
return 'G';
|
|
236
|
+
} else if (component === 6) {
|
|
237
|
+
return 'B';
|
|
238
|
+
}
|
|
239
|
+
}
|
|
@@ -2,7 +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 {
|
|
5
|
+
import {getEncodedString, getTableDescription, getVersionString} from './tag-names-utils.js';
|
|
6
6
|
import TagNamesCommon from './tag-names-common.js';
|
|
7
7
|
|
|
8
8
|
export default {
|
|
@@ -28,7 +28,7 @@ export default {
|
|
|
28
28
|
0x882b: 'SelfTimerMode',
|
|
29
29
|
0x8830: {
|
|
30
30
|
name: 'SensitivityType',
|
|
31
|
-
description: (value) => ({
|
|
31
|
+
description: (value) => getTableDescription({
|
|
32
32
|
1: 'Standard Output Sensitivity',
|
|
33
33
|
2: 'Recommended Exposure Index',
|
|
34
34
|
3: 'ISO Speed',
|
|
@@ -36,7 +36,7 @@ export default {
|
|
|
36
36
|
5: 'Standard Output Sensitivity and ISO Speed',
|
|
37
37
|
6: 'Recommended Exposure Index and ISO Speed',
|
|
38
38
|
7: 'Standard Output Sensitivity, Recommended Exposure Index and ISO Speed'
|
|
39
|
-
})
|
|
39
|
+
}, value)
|
|
40
40
|
},
|
|
41
41
|
0x8831: 'StandardOutputSensitivity',
|
|
42
42
|
0x8832: 'RecommendedExposureIndex',
|
|
@@ -45,7 +45,7 @@ export default {
|
|
|
45
45
|
0x8835: 'ISOSpeedLatitudezzz',
|
|
46
46
|
0x9000: {
|
|
47
47
|
'name': 'ExifVersion',
|
|
48
|
-
'description':
|
|
48
|
+
'description': getVersionString
|
|
49
49
|
},
|
|
50
50
|
0x9003: 'DateTimeOriginal',
|
|
51
51
|
0x9004: 'DateTimeDigitized',
|
|
@@ -144,13 +144,13 @@ export default {
|
|
|
144
144
|
0x9211: 'ImageNumber',
|
|
145
145
|
0x9212: {
|
|
146
146
|
name: 'SecurityClassification',
|
|
147
|
-
description: (value) => ({
|
|
147
|
+
description: (value) => getTableDescription({
|
|
148
148
|
'C': 'Confidential',
|
|
149
149
|
'R': 'Restricted',
|
|
150
150
|
'S': 'Secret',
|
|
151
151
|
'T': 'Top Secret',
|
|
152
152
|
'U': 'Unclassified'
|
|
153
|
-
})
|
|
153
|
+
}, value)
|
|
154
154
|
},
|
|
155
155
|
0x9213: 'ImageHistory',
|
|
156
156
|
0x9214: {
|
|
@@ -204,7 +204,7 @@ export default {
|
|
|
204
204
|
},
|
|
205
205
|
0xa000: {
|
|
206
206
|
'name': 'FlashpixVersion',
|
|
207
|
-
'description':
|
|
207
|
+
'description': getVersionString
|
|
208
208
|
},
|
|
209
209
|
0xa001: {
|
|
210
210
|
'name': 'ColorSpace',
|
|
@@ -354,14 +354,7 @@ export default {
|
|
|
354
354
|
0xa432: {
|
|
355
355
|
'name': 'LensSpecification',
|
|
356
356
|
'description': (value) => {
|
|
357
|
-
|
|
358
|
-
const focalLengthTo = parseFloat((value[1][0] / value[1][1]).toFixed(5));
|
|
359
|
-
const focalLengths = `${focalLengthFrom}-${focalLengthTo} mm`;
|
|
360
|
-
if (value[3][1] === 0) {
|
|
361
|
-
return `${focalLengths} f/?`;
|
|
362
|
-
}
|
|
363
|
-
const maxAperture = 1 / ((value[2][1] / value[2][1]) / (value[3][0] / value[3][1]));
|
|
364
|
-
return `${focalLengths} f/${parseFloat(maxAperture.toFixed(5))}`;
|
|
357
|
+
return `${getLensFocalLengths(value[0], value[1])} mm f/${getLensApertures(value[2], value[3])}`;
|
|
365
358
|
}
|
|
366
359
|
},
|
|
367
360
|
0xa433: 'LensMake',
|
|
@@ -369,11 +362,11 @@ export default {
|
|
|
369
362
|
0xa435: 'LensSerialNumber',
|
|
370
363
|
0xa460: {
|
|
371
364
|
name: 'CompositeImage',
|
|
372
|
-
description: (value) => ({
|
|
365
|
+
description: (value) => getTableDescription({
|
|
373
366
|
1: 'Not a Composite Image',
|
|
374
367
|
2: 'General Composite Image',
|
|
375
368
|
3: 'Composite Image Captured While Shooting',
|
|
376
|
-
})
|
|
369
|
+
}, value)
|
|
377
370
|
},
|
|
378
371
|
0xa461: 'SourceImageNumberOfCompositeImage',
|
|
379
372
|
0xa462: 'SourceExposureTimesOfCompositeImage',
|
|
@@ -395,3 +388,31 @@ export default {
|
|
|
395
388
|
0xfe57: 'Smoothness',
|
|
396
389
|
0xfe58: 'MoireFilter'
|
|
397
390
|
};
|
|
391
|
+
|
|
392
|
+
function getLensFocalLengths(from, to) {
|
|
393
|
+
const focalLengthFrom = getRoundedRational(from);
|
|
394
|
+
const focalLengthTo = getRoundedRational(to);
|
|
395
|
+
if (focalLengthTo === 0 || focalLengthTo === focalLengthFrom) {
|
|
396
|
+
return `${focalLengthFrom}`;
|
|
397
|
+
}
|
|
398
|
+
return `${focalLengthFrom}-${focalLengthTo}`;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function getLensApertures(wide, long) {
|
|
402
|
+
const apertures = [wide, long].filter(isKnownRational).map(getRoundedRational);
|
|
403
|
+
if (apertures.length === 0) {
|
|
404
|
+
return '?';
|
|
405
|
+
}
|
|
406
|
+
if (apertures.length === 1 || apertures[1] === 0 || apertures[1] === apertures[0]) {
|
|
407
|
+
return `${apertures[0]}`;
|
|
408
|
+
}
|
|
409
|
+
return `${apertures[0]}-${apertures[1]}`;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function getRoundedRational(rational) {
|
|
413
|
+
return parseFloat((rational[0] / rational[1]).toFixed(5));
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function isKnownRational(rational) {
|
|
417
|
+
return rational[1] !== 0;
|
|
418
|
+
}
|
|
@@ -2,13 +2,13 @@
|
|
|
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 {
|
|
5
|
+
import {getVersionString} from './tag-names-utils.js';
|
|
6
6
|
|
|
7
7
|
export default {
|
|
8
8
|
0x0001: 'InteroperabilityIndex',
|
|
9
9
|
0x0002: {
|
|
10
10
|
name: 'InteroperabilityVersion',
|
|
11
|
-
description:
|
|
11
|
+
description: getVersionString
|
|
12
12
|
},
|
|
13
13
|
0x1000: 'RelatedImageFileFormat',
|
|
14
14
|
0x1001: 'RelatedImageWidth',
|
package/src/tag-names-mpf-ifd.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
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 {
|
|
5
|
+
import {getVersionString} from './tag-names-utils.js';
|
|
6
6
|
|
|
7
7
|
export default {
|
|
8
8
|
0xb000: {
|
|
9
9
|
'name': 'MPFVersion',
|
|
10
|
-
'description':
|
|
10
|
+
'description': getVersionString
|
|
11
11
|
},
|
|
12
12
|
0xb001: 'NumberOfImages',
|
|
13
13
|
0xb002: 'MPEntry',
|
package/src/tag-names-utils.js
CHANGED
|
@@ -2,7 +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 {getStringValueFromArray as getStringValue} from './utils.js';
|
|
5
|
+
import {getStringValueFromArray as getStringValue, getByteString} from './utils.js';
|
|
6
6
|
|
|
7
7
|
export {getStringValue};
|
|
8
8
|
|
|
@@ -11,13 +11,13 @@ export function getEncodedString(value) {
|
|
|
11
11
|
const encoding = getStringValue(value.slice(0, 8));
|
|
12
12
|
|
|
13
13
|
if (encoding === 'ASCII\x00\x00\x00') {
|
|
14
|
-
return
|
|
14
|
+
return getByteString(value, 8);
|
|
15
15
|
} else if (encoding === 'JIS\x00\x00\x00\x00\x00') {
|
|
16
16
|
return '[JIS encoded text]';
|
|
17
17
|
} else if (encoding === 'UNICODE\x00') {
|
|
18
18
|
return '[Unicode encoded text]';
|
|
19
19
|
} else if (encoding === '\x00\x00\x00\x00\x00\x00\x00\x00') {
|
|
20
|
-
const text =
|
|
20
|
+
const text = getByteString(value, 8);
|
|
21
21
|
if (/[\x20-\x7e]/.test(text)) {
|
|
22
22
|
return text;
|
|
23
23
|
}
|
|
@@ -28,6 +28,41 @@ export function getEncodedString(value) {
|
|
|
28
28
|
return 'Undefined';
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Converts the bytes of a version tag, such as ExifVersion, to a string. A
|
|
33
|
+
* value of strings (an ASCII-typed tag) is returned as its strings joined
|
|
34
|
+
* with ', ', as for other ASCII tags. A value that is not an array (a single
|
|
35
|
+
* byte, or '<faulty value>') is returned as it is.
|
|
36
|
+
* @param {number[]|string[]|number|string} value
|
|
37
|
+
* @returns {string|number}
|
|
38
|
+
*/
|
|
39
|
+
export function getVersionString(value) {
|
|
40
|
+
if (Array.isArray(value)) {
|
|
41
|
+
if (value.some(isString)) {
|
|
42
|
+
return value.filter(isString).join(', ');
|
|
43
|
+
}
|
|
44
|
+
return getByteString(value);
|
|
45
|
+
}
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function isString(item) {
|
|
50
|
+
return typeof item === 'string';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Looks a tag value up in a table of descriptions, own properties only, so a
|
|
55
|
+
* value such as 'constructor' or ['__proto__'] does not find a member of
|
|
56
|
+
* Object.prototype.
|
|
57
|
+
* @param {Object} table Descriptions keyed by tag value.
|
|
58
|
+
* @param {*} value The tag value, used as a property key.
|
|
59
|
+
* @returns {string} The description, or 'Unknown' when the value is not a key.
|
|
60
|
+
*/
|
|
61
|
+
export function getTableDescription(table, value) {
|
|
62
|
+
const key = String(value);
|
|
63
|
+
return Object.prototype.hasOwnProperty.call(table, key) ? table[key] : 'Unknown';
|
|
64
|
+
}
|
|
65
|
+
|
|
31
66
|
export function getCalculatedGpsValue(value) {
|
|
32
67
|
return (value[0][0] / value[0][1]) + (value[1][0] / value[1][1]) / 60 + (value[2][0] / value[2][1]) / 3600;
|
|
33
68
|
}
|
package/src/tags-helpers.js
CHANGED
|
@@ -533,3 +533,23 @@ function getComputedRationalValue(rational) {
|
|
|
533
533
|
|
|
534
534
|
return numerator / denominator;
|
|
535
535
|
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Removes the thumbnail IFD from the tags of an embedded Exif block and reads
|
|
539
|
+
* its image with `readThumbnail`, when given.
|
|
540
|
+
*
|
|
541
|
+
* @returns {object|undefined} The thumbnail tags when an image was read.
|
|
542
|
+
*/
|
|
543
|
+
export function takeEmbeddedExifThumbnail(readTags, dataView, tiffHeaderOffset, readThumbnail) {
|
|
544
|
+
const thumbnailIfdTags = readTags.Thumbnail;
|
|
545
|
+
if (!thumbnailIfdTags) {
|
|
546
|
+
return undefined;
|
|
547
|
+
}
|
|
548
|
+
delete readTags.Thumbnail;
|
|
549
|
+
|
|
550
|
+
if (!readThumbnail) {
|
|
551
|
+
return undefined;
|
|
552
|
+
}
|
|
553
|
+
const thumbnail = readThumbnail(dataView, thumbnailIfdTags, tiffHeaderOffset);
|
|
554
|
+
return thumbnail.image ? thumbnail : undefined;
|
|
555
|
+
}
|