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.
- package/README.md +398 -27
- package/bin/analyze.js +139 -9
- package/bin/build-pages.js +21 -35
- package/bin/cli.js +81 -13
- package/bin/generate-tag-modules.js +287 -0
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +213 -38
- package/package.json +71 -11
- package/src/composable/brand.js +10 -0
- package/src/composable/composition-tag-filter.js +97 -0
- package/src/composable/composition.js +195 -0
- package/src/composable/core.d.ts +148 -0
- package/src/composable/core.js +526 -0
- package/src/composable/exif-block-reader.js +197 -0
- package/src/composable/formats/avif.js +19 -0
- package/src/composable/formats/gif.js +28 -0
- package/src/composable/formats/heic.js +19 -0
- package/src/composable/formats/iso-bmff-file-reader.js +14 -0
- package/src/composable/formats/jpeg.js +55 -0
- package/src/composable/formats/jxl.js +30 -0
- package/src/composable/formats/png.js +187 -0
- package/src/composable/formats/tiff.js +18 -0
- package/src/composable/formats/webp.js +28 -0
- package/src/composable/formats/xml.js +18 -0
- package/src/composable/formats.d.ts +17 -0
- package/src/composable/formats.js +17 -0
- package/src/composable/group-helpers.js +129 -0
- package/src/composable/groups/canon.js +26 -0
- package/src/composable/groups/composite.js +43 -0
- package/src/composable/groups/exif.js +48 -0
- package/src/composable/groups/gps.js +75 -0
- package/src/composable/groups/icc.js +52 -0
- package/src/composable/groups/iptc.js +86 -0
- package/src/composable/groups/maker-notes.js +21 -0
- package/src/composable/groups/mpf.js +25 -0
- package/src/composable/groups/pentax.js +34 -0
- package/src/composable/groups/photoshop.js +18 -0
- package/src/composable/groups/thumbnail.js +131 -0
- package/src/composable/groups/xmp.js +118 -0
- package/src/composable/groups.d.ts +20 -0
- package/src/composable/groups.js +105 -0
- package/src/composable/iptc-block-reader.js +44 -0
- package/src/composable/read-view.js +165 -0
- package/src/composable/tag-binding-name.js +17 -0
- package/src/composable/tags/exif.d.ts +295 -0
- package/src/composable/tags/exif.js +396 -0
- package/src/composable/tags/iptc.d.ts +84 -0
- package/src/composable/tags/iptc.js +109 -0
- package/src/composable/value-budget.js +24 -0
- package/src/composite.js +2 -2
- package/src/decompression.js +60 -0
- package/src/engine.js +50 -106
- package/src/errors.js +8 -2
- package/src/exif-reader.d.ts +8 -0
- package/src/exif-reader.js +112 -763
- package/src/file-loaders.js +74 -1
- package/src/file-tags.js +9 -9
- package/src/image-header.js +13 -47
- package/src/iptc-tag-names-descriptions.js +334 -0
- package/src/iptc-tag-names.js +50 -306
- package/src/iptc-tags.js +41 -27
- package/src/jfif-tags.js +9 -9
- package/src/load-auto.js +2 -2
- package/src/loadview-pipeline.js +52 -192
- package/src/node-require.js +15 -2
- package/src/png-text-tags.js +5 -3
- package/src/tag-filter-config.js +24 -15
- package/src/tag-filter.js +15 -3
- package/src/tag-names-0th-ifd-descriptions.js +232 -0
- package/src/tag-names-0th-ifd.js +49 -173
- package/src/tag-names-common.js +263 -211
- package/src/tag-names-exif-ifd-descriptions.js +249 -0
- package/src/tag-names-exif-ifd.js +55 -187
- package/src/tag-names-gps-ifd-descriptions.js +156 -0
- package/src/tag-names-gps-ifd.js +39 -146
- package/src/tag-names-utils.js +28 -3
- package/src/tags-helpers.js +6 -2
- package/src/types.js +2 -0
- package/src/unsupported-format-error.js +21 -0
- package/src/utils.js +22 -85
- package/src/xmp-tag-names.js +42 -21
- package/webpack.config.js +1 -1
|
@@ -0,0 +1,109 @@
|
|
|
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
|
+
// Generated by bin/generate-tag-modules.js from the tag dictionaries; do not edit.
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
getARMIdentifierDescription,
|
|
9
|
+
getARMVersionDescription,
|
|
10
|
+
getActionAdvisedDescription,
|
|
11
|
+
getAudioDurationDescription,
|
|
12
|
+
getAudioSamplingRateDescription,
|
|
13
|
+
getAudioSamplingResolutionDescription,
|
|
14
|
+
getAudioTypeDescription,
|
|
15
|
+
getCreationDate,
|
|
16
|
+
getCreationTime,
|
|
17
|
+
getEditorialUpdateDescription,
|
|
18
|
+
getEncodingName,
|
|
19
|
+
getFileFormatDescription,
|
|
20
|
+
getFileFormatVersionDescription,
|
|
21
|
+
getImageOrientationDescription,
|
|
22
|
+
getMaxSubfileSizeDescription,
|
|
23
|
+
getMaximumObjectDataSizeDescription,
|
|
24
|
+
getModelVersionDescription,
|
|
25
|
+
getObjectCycleDescription,
|
|
26
|
+
getObjectDataSizeAnnouncedDescription,
|
|
27
|
+
getRasterizedCaptionDescription,
|
|
28
|
+
getRecordVersionDescription,
|
|
29
|
+
getSizeModeDescription,
|
|
30
|
+
getSubjectReferenceDescription
|
|
31
|
+
} from '../../iptc-tag-names-descriptions.js';
|
|
32
|
+
import {iptcBlockReader} from '../iptc-block-reader.js';
|
|
33
|
+
|
|
34
|
+
export const ModelVersion = {name: 'Model Version', ids: [0x0100], group: 'iptc', dictionary: 'iptc', description: getModelVersionDescription, reader: iptcBlockReader};
|
|
35
|
+
export const Destination = {name: 'Destination', ids: [0x0105], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
|
|
36
|
+
export const FileFormat = {name: 'File Format', ids: [0x0114], group: 'iptc', dictionary: 'iptc', description: getFileFormatDescription, reader: iptcBlockReader};
|
|
37
|
+
export const FileFormatVersion = {name: 'File Format Version', ids: [0x0116], group: 'iptc', dictionary: 'iptc', description: getFileFormatVersionDescription, reader: iptcBlockReader};
|
|
38
|
+
export const ServiceIdentifier = {name: 'Service Identifier', ids: [0x011e], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
39
|
+
export const EnvelopeNumber = {name: 'Envelope Number', ids: [0x0128], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
40
|
+
export const ProductID = {name: 'Product ID', ids: [0x0132], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
41
|
+
export const EnvelopePriority = {name: 'Envelope Priority', ids: [0x013c], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
42
|
+
export const DateSent = {name: 'Date Sent', ids: [0x0146], group: 'iptc', dictionary: 'iptc', description: getCreationDate, reader: iptcBlockReader};
|
|
43
|
+
export const TimeSent = {name: 'Time Sent', ids: [0x0150], group: 'iptc', dictionary: 'iptc', description: getCreationTime, reader: iptcBlockReader};
|
|
44
|
+
export const CodedCharacterSet = {name: 'Coded Character Set', ids: [0x015a], group: 'iptc', dictionary: 'iptc', description: getEncodingName, reader: iptcBlockReader};
|
|
45
|
+
export const UNO = {name: 'UNO', ids: [0x0164], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
46
|
+
export const ARMIdentifier = {name: 'ARM Identifier', ids: [0x0178], group: 'iptc', dictionary: 'iptc', description: getARMIdentifierDescription, reader: iptcBlockReader};
|
|
47
|
+
export const ARMVersion = {name: 'ARM Version', ids: [0x017a], group: 'iptc', dictionary: 'iptc', description: getARMVersionDescription, reader: iptcBlockReader};
|
|
48
|
+
export const RecordVersion = {name: 'Record Version', ids: [0x0200], group: 'iptc', dictionary: 'iptc', description: getRecordVersionDescription, reader: iptcBlockReader};
|
|
49
|
+
export const ObjectTypeReference = {name: 'Object Type Reference', ids: [0x0203], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
50
|
+
export const ObjectAttributeReference = {name: 'Object Attribute Reference', ids: [0x0204], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
51
|
+
export const ObjectName = {name: 'Object Name', ids: [0x0205], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
52
|
+
export const EditStatus = {name: 'Edit Status', ids: [0x0207], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
53
|
+
export const EditorialUpdate = {name: 'Editorial Update', ids: [0x0208], group: 'iptc', dictionary: 'iptc', description: getEditorialUpdateDescription, reader: iptcBlockReader};
|
|
54
|
+
export const Urgency = {name: 'Urgency', ids: [0x020a], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
55
|
+
export const SubjectReference = {name: 'Subject Reference', ids: [0x020c], group: 'iptc', dictionary: 'iptc', description: getSubjectReferenceDescription, repeatable: true, reader: iptcBlockReader};
|
|
56
|
+
export const Category = {name: 'Category', ids: [0x020f], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
57
|
+
export const SupplementalCategory = {name: 'Supplemental Category', ids: [0x0214], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
|
|
58
|
+
export const FixtureIdentifier = {name: 'Fixture Identifier', ids: [0x0216], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
59
|
+
export const Keywords = {name: 'Keywords', ids: [0x0219], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
|
|
60
|
+
export const ContentLocationCode = {name: 'Content Location Code', ids: [0x021a], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
|
|
61
|
+
export const ContentLocationName = {name: 'Content Location Name', ids: [0x021b], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
|
|
62
|
+
export const ReleaseDate = {name: 'Release Date', ids: [0x021e], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
63
|
+
export const ReleaseTime = {name: 'Release Time', ids: [0x0223], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
64
|
+
export const ExpirationDate = {name: 'Expiration Date', ids: [0x0225], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
65
|
+
export const ExpirationTime = {name: 'Expiration Time', ids: [0x0226], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
66
|
+
export const SpecialInstructions = {name: 'Special Instructions', ids: [0x0228], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
67
|
+
export const ActionAdvised = {name: 'Action Advised', ids: [0x022a], group: 'iptc', dictionary: 'iptc', description: getActionAdvisedDescription, reader: iptcBlockReader};
|
|
68
|
+
export const ReferenceService = {name: 'Reference Service', ids: [0x022d], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
|
|
69
|
+
export const ReferenceDate = {name: 'Reference Date', ids: [0x022f], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
|
|
70
|
+
export const ReferenceNumber = {name: 'Reference Number', ids: [0x0232], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
|
|
71
|
+
export const DateCreated = {name: 'Date Created', ids: [0x0237], group: 'iptc', dictionary: 'iptc', description: getCreationDate, reader: iptcBlockReader};
|
|
72
|
+
export const TimeCreated = {name: 'Time Created', ids: [0x023c], group: 'iptc', dictionary: 'iptc', description: getCreationTime, reader: iptcBlockReader};
|
|
73
|
+
export const DigitalCreationDate = {name: 'Digital Creation Date', ids: [0x023e], group: 'iptc', dictionary: 'iptc', description: getCreationDate, reader: iptcBlockReader};
|
|
74
|
+
export const DigitalCreationTime = {name: 'Digital Creation Time', ids: [0x023f], group: 'iptc', dictionary: 'iptc', description: getCreationTime, reader: iptcBlockReader};
|
|
75
|
+
export const OriginatingProgram = {name: 'Originating Program', ids: [0x0241], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
76
|
+
export const ProgramVersion = {name: 'Program Version', ids: [0x0246], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
77
|
+
export const ObjectCycle = {name: 'Object Cycle', ids: [0x024b], group: 'iptc', dictionary: 'iptc', description: getObjectCycleDescription, reader: iptcBlockReader};
|
|
78
|
+
export const ByLine = {name: 'By-line', ids: [0x0250], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
|
|
79
|
+
export const ByLineTitle = {name: 'By-line Title', ids: [0x0255], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
|
|
80
|
+
export const City = {name: 'City', ids: [0x025a], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
81
|
+
export const SubLocation = {name: 'Sub-location', ids: [0x025c], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
82
|
+
export const ProvinceState = {name: 'Province/State', ids: [0x025f], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
83
|
+
export const CountryPrimaryLocationCode = {name: 'Country/Primary Location Code', ids: [0x0264], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
84
|
+
export const CountryPrimaryLocationName = {name: 'Country/Primary Location Name', ids: [0x0265], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
85
|
+
export const OriginalTransmissionReference = {name: 'Original Transmission Reference', ids: [0x0267], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
86
|
+
export const Headline = {name: 'Headline', ids: [0x0269], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
87
|
+
export const Credit = {name: 'Credit', ids: [0x026e], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
88
|
+
export const Source = {name: 'Source', ids: [0x0273], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
89
|
+
export const CopyrightNotice = {name: 'Copyright Notice', ids: [0x0274], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
90
|
+
export const Contact = {name: 'Contact', ids: [0x0276], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
|
|
91
|
+
export const CaptionAbstract = {name: 'Caption/Abstract', ids: [0x0278], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
92
|
+
export const WriterEditor = {name: 'Writer/Editor', ids: [0x027a], group: 'iptc', dictionary: 'iptc', repeatable: true, reader: iptcBlockReader};
|
|
93
|
+
export const RasterizedCaption = {name: 'Rasterized Caption', ids: [0x027d], group: 'iptc', dictionary: 'iptc', description: getRasterizedCaptionDescription, reader: iptcBlockReader};
|
|
94
|
+
export const ImageType = {name: 'Image Type', ids: [0x0282], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
95
|
+
export const ImageOrientation = {name: 'Image Orientation', ids: [0x0283], group: 'iptc', dictionary: 'iptc', description: getImageOrientationDescription, reader: iptcBlockReader};
|
|
96
|
+
export const LanguageIdentifier = {name: 'Language Identifier', ids: [0x0287], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
97
|
+
export const AudioType = {name: 'Audio Type', ids: [0x0296], group: 'iptc', dictionary: 'iptc', description: getAudioTypeDescription, reader: iptcBlockReader};
|
|
98
|
+
export const AudioSamplingRate = {name: 'Audio Sampling Rate', ids: [0x0297], group: 'iptc', dictionary: 'iptc', description: getAudioSamplingRateDescription, reader: iptcBlockReader};
|
|
99
|
+
export const AudioSamplingResolution = {name: 'Audio Sampling Resolution', ids: [0x0298], group: 'iptc', dictionary: 'iptc', description: getAudioSamplingResolutionDescription, reader: iptcBlockReader};
|
|
100
|
+
export const AudioDuration = {name: 'Audio Duration', ids: [0x0299], group: 'iptc', dictionary: 'iptc', description: getAudioDurationDescription, reader: iptcBlockReader};
|
|
101
|
+
export const AudioOutcue = {name: 'Audio Outcue', ids: [0x029a], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
102
|
+
export const ShortDocumentID = {name: 'Short Document ID', ids: [0x02ba], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
103
|
+
export const UniqueDocumentID = {name: 'Unique Document ID', ids: [0x02bb], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
104
|
+
export const OwnerID = {name: 'Owner ID', ids: [0x02bc], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
105
|
+
export const ObjectDataPreviewData = {name: 'ObjectData Preview Data', ids: [0x02ca], group: 'iptc', dictionary: 'iptc', reader: iptcBlockReader};
|
|
106
|
+
export const SizeMode = {name: 'Size Mode', ids: [0x070a], group: 'iptc', dictionary: 'iptc', description: getSizeModeDescription, reader: iptcBlockReader};
|
|
107
|
+
export const MaxSubfileSize = {name: 'Max Subfile Size', ids: [0x0714], group: 'iptc', dictionary: 'iptc', description: getMaxSubfileSizeDescription, reader: iptcBlockReader};
|
|
108
|
+
export const ObjectDataSizeAnnounced = {name: 'ObjectData Size Announced', ids: [0x075a], group: 'iptc', dictionary: 'iptc', description: getObjectDataSizeAnnouncedDescription, reader: iptcBlockReader};
|
|
109
|
+
export const MaximumObjectDataSize = {name: 'Maximum ObjectData Size', ids: [0x075f], group: 'iptc', dictionary: 'iptc', description: getMaximumObjectDataSizeDescription, reader: iptcBlockReader};
|
|
@@ -0,0 +1,24 @@
|
|
|
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 {getValueBudget} from '../tags-helpers.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns the load's one value budget, creating it on the first call from
|
|
9
|
+
* `view`, or from `ctx.dataView` when no view is given. Later calls return the
|
|
10
|
+
* same object whatever view they pass. Undefined when there is no view at all.
|
|
11
|
+
*
|
|
12
|
+
* @param {object} ctx The load's engine context.
|
|
13
|
+
* @param {DataView} [view] The view to size the budget from on the first call.
|
|
14
|
+
* @returns {(object|undefined)} The shared budget.
|
|
15
|
+
*/
|
|
16
|
+
export function getSharedValueBudget(ctx, view) {
|
|
17
|
+
if (ctx.valueBudget === undefined) {
|
|
18
|
+
const budgetView = view || ctx.dataView;
|
|
19
|
+
if (budgetView !== undefined) {
|
|
20
|
+
ctx.valueBudget = getValueBudget(budgetView);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return ctx.valueBudget;
|
|
24
|
+
}
|
package/src/composite.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 {
|
|
5
|
+
import {getFocalLengthIn35mmFilmDescription} from './tag-names-common.js';
|
|
6
6
|
|
|
7
7
|
const FOCAL_PLANE_RESOLUTION_UNIT = {
|
|
8
8
|
INCHES: 2,
|
|
@@ -37,7 +37,7 @@ function get(tags, expanded) {
|
|
|
37
37
|
if (focalLengthIn35mmFilm) {
|
|
38
38
|
compositeTags.FocalLength35efl = {
|
|
39
39
|
value: focalLengthIn35mmFilm,
|
|
40
|
-
description:
|
|
40
|
+
description: getFocalLengthIn35mmFilmDescription(focalLengthIn35mmFilm)
|
|
41
41
|
};
|
|
42
42
|
hasCompositeTags = true;
|
|
43
43
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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 {decompress, withDecompressBudget} from './utils.js';
|
|
6
|
+
|
|
7
|
+
const MAX_DECOMPRESSIONS_IN_FLIGHT = 4;
|
|
8
|
+
|
|
9
|
+
export const decompression = {
|
|
10
|
+
withDecompressBudget,
|
|
11
|
+
createPooledDecompress,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Makes a decompress function for one load whose calls share a pool of at
|
|
16
|
+
* most MAX_DECOMPRESSIONS_IN_FLIGHT tasks.
|
|
17
|
+
*
|
|
18
|
+
* @param {object|undefined} decompressConfig Given to every call of decompress
|
|
19
|
+
* in utils.js, normally the load's config from withDecompressBudget.
|
|
20
|
+
* @returns {function(DataView, (number|string), string, string): Promise}
|
|
21
|
+
* `(view, compressionMethod, encoding, returnType)`.
|
|
22
|
+
*/
|
|
23
|
+
function createPooledDecompress(decompressConfig) {
|
|
24
|
+
const pool = createPool(MAX_DECOMPRESSIONS_IN_FLIGHT);
|
|
25
|
+
return (view, compressionMethod, encoding, returnType) => pool.run(() => decompress(view, compressionMethod, encoding, returnType, decompressConfig));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Starts a task when fewer than `limit` are running, else queues it until one
|
|
29
|
+
// settles. Promise is only referenced once a task is given, in async mode.
|
|
30
|
+
function createPool(limit) {
|
|
31
|
+
const queue = [];
|
|
32
|
+
let running = 0;
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
run(task) {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
queue.push({task, resolve, reject});
|
|
38
|
+
startNext();
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function startNext() {
|
|
44
|
+
if (running >= limit || queue.length === 0) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const {task, resolve, reject} = queue.shift();
|
|
48
|
+
running++;
|
|
49
|
+
// The wrapper turns a synchronous throw from a task into a rejection.
|
|
50
|
+
new Promise((start) => start(task())).then((result) => {
|
|
51
|
+
running--;
|
|
52
|
+
startNext();
|
|
53
|
+
resolve(result);
|
|
54
|
+
}, (error) => {
|
|
55
|
+
running--;
|
|
56
|
+
startNext();
|
|
57
|
+
reject(error);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
package/src/engine.js
CHANGED
|
@@ -2,23 +2,10 @@
|
|
|
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 {
|
|
6
|
-
import {getValueBudget} from './tags-helpers.js';
|
|
5
|
+
import {isThenable, objectAssign} from './utils.js';
|
|
7
6
|
|
|
8
7
|
// A finder block, a block it emits and a block emitted by that one.
|
|
9
8
|
export const MAX_BLOCK_DEPTH = 3;
|
|
10
|
-
export const MAX_DECOMPRESSIONS_IN_FLIGHT = 4;
|
|
11
|
-
|
|
12
|
-
// Brob XMP is bounded by the file size, as brob Exif is, plus room for one JPEG
|
|
13
|
-
// standard XMP segment so that a small file can still carry a typical packet.
|
|
14
|
-
const BROB_XMP_SIZE_PER_INPUT_SIZE = 4;
|
|
15
|
-
const BROB_XMP_SIZE_ALLOWANCE = 64 * 1024;
|
|
16
|
-
// An embedded thumbnail is sliced from a decoded or decompressed view that can be
|
|
17
|
-
// far larger than the file. A real JPEG thumbnail shrinks only a little when
|
|
18
|
-
// compressed, so bound the embedded thumbnails of a file by twice its size in
|
|
19
|
-
// total, plus room for a typical thumbnail.
|
|
20
|
-
const EMBEDDED_THUMBNAIL_SIZE_PER_INPUT_SIZE = 2;
|
|
21
|
-
const EMBEDDED_THUMBNAIL_SIZE_ALLOWANCE = 64 * 1024;
|
|
22
9
|
|
|
23
10
|
/**
|
|
24
11
|
* Runs the composition's groups over the finder's blocks and the blocks the
|
|
@@ -79,8 +66,8 @@ function createDispatchPlan(composition, blocks, context) {
|
|
|
79
66
|
}
|
|
80
67
|
|
|
81
68
|
// A group dispatches when the filter parses its key, or a group that consumes
|
|
82
|
-
// a kind it emits does. A cycle counts as false
|
|
83
|
-
//
|
|
69
|
+
// a kind it emits does. A cycle counts as false, so a forged cyclic group
|
|
70
|
+
// cannot recurse forever.
|
|
84
71
|
function createShouldDispatch(groups, consumersOf, tagFilter) {
|
|
85
72
|
const verdicts = [];
|
|
86
73
|
|
|
@@ -256,103 +243,42 @@ function getNodeMergeBlocks(node) {
|
|
|
256
243
|
|
|
257
244
|
/**
|
|
258
245
|
* Builds the per-load state the groups share: the input, the options, the
|
|
259
|
-
*
|
|
246
|
+
* value budget, the entry's helpers and the facts about what is composed. A
|
|
247
|
+
* group keeps any state of its own on the context, created when it first needs
|
|
248
|
+
* it.
|
|
260
249
|
*
|
|
261
|
-
* @param {{dataView: DataView, options: object, tagFilter: object, decompressConfig: object, getBase64Image: function, getDomParser: function}} parts
|
|
250
|
+
* @param {{dataView: DataView, options: object, tagFilter: object, decompressConfig: (object|undefined), getBase64Image: function, getDomParser: function, composed: object, decompression: (object|undefined)}} parts
|
|
251
|
+
* `composed` is the composition's `{formats, groups, kinds}` maps and its
|
|
252
|
+
* `fromExif` extractors, which the readers consult instead of the build
|
|
253
|
+
* flags. `decompression` is the pooled decompression the png and jxl
|
|
254
|
+
* formats bring; without it `decompressConfig` is undefined too.
|
|
262
255
|
* @returns {object} The context, with `decompress` running through a pool of at
|
|
263
|
-
* most
|
|
264
|
-
*
|
|
256
|
+
* most four tasks when `decompression` is given, else undefined, and
|
|
257
|
+
* `valueBudget` holding the load's one value budget, which
|
|
258
|
+
* `getSharedValueBudget` in `composable/value-budget.js` creates on first
|
|
259
|
+
* use.
|
|
265
260
|
*/
|
|
266
|
-
export function createContext({dataView, options, tagFilter, decompressConfig, getBase64Image, getDomParser}) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
const context =
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
hasEmbeddedThumbnailImage: false,
|
|
280
|
-
compressedPngTextChunks: 0,
|
|
281
|
-
hasRawIptcProfile: undefined,
|
|
282
|
-
embeddedThumbnailSizeBound: EMBEDDED_THUMBNAIL_SIZE_PER_INPUT_SIZE * inputByteLength + EMBEDDED_THUMBNAIL_SIZE_ALLOWANCE,
|
|
283
|
-
decompress(view, compressionMethod, encoding, returnType) {
|
|
284
|
-
return pool.run(() => decompress(view, compressionMethod, encoding, returnType, decompressConfig));
|
|
285
|
-
},
|
|
286
|
-
// The main Exif block creates the budget from its view; later callers
|
|
287
|
-
// get the same object, whatever view they pass. The view is only
|
|
288
|
-
// missing in unit tests that fake the readers.
|
|
289
|
-
getValueBudget(view) {
|
|
290
|
-
if (context.valueBudget === undefined) {
|
|
291
|
-
const budgetView = view || dataView;
|
|
292
|
-
if (budgetView !== undefined) {
|
|
293
|
-
context.valueBudget = getValueBudget(budgetView);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
return context.valueBudget;
|
|
297
|
-
},
|
|
298
|
-
// The brob XMP bound covers the decompressed Exif blocks of a file
|
|
299
|
-
// together, so that several cannot each pass it.
|
|
300
|
-
takeDecompressedApplicationNotesAllowance(byteLength) {
|
|
301
|
-
if (context.exceedsBrobXmpSizeBound(context.decompressedApplicationNotesSize + byteLength)) {
|
|
302
|
-
return false;
|
|
303
|
-
}
|
|
304
|
-
context.decompressedApplicationNotesSize += byteLength;
|
|
305
|
-
return true;
|
|
306
|
-
},
|
|
307
|
-
exceedsBrobXmpSizeBound(byteLength) {
|
|
308
|
-
return byteLength > BROB_XMP_SIZE_PER_INPUT_SIZE * inputByteLength + BROB_XMP_SIZE_ALLOWANCE;
|
|
309
|
-
},
|
|
310
|
-
};
|
|
311
|
-
|
|
261
|
+
export function createContext({dataView, options, tagFilter, decompressConfig, getBase64Image, getDomParser, composed, decompression}) {
|
|
262
|
+
// No prototype, so a group's state is absent until the group sets it even if
|
|
263
|
+
// Object.prototype has that property; objectAssign would copy it from there.
|
|
264
|
+
const context = Object.create(null);
|
|
265
|
+
context.dataView = dataView;
|
|
266
|
+
context.options = options;
|
|
267
|
+
context.tagFilter = tagFilter;
|
|
268
|
+
context.decompressConfig = decompressConfig;
|
|
269
|
+
context.getBase64Image = getBase64Image;
|
|
270
|
+
context.getDomParser = getDomParser;
|
|
271
|
+
context.composed = composed;
|
|
272
|
+
context.valueBudget = undefined;
|
|
273
|
+
context.decompress = decompression ? decompression.createPooledDecompress(decompressConfig) : undefined;
|
|
312
274
|
return context;
|
|
313
275
|
}
|
|
314
276
|
|
|
315
|
-
function getInputByteLength(dataView) {
|
|
316
|
-
return dataView !== undefined && typeof dataView.byteLength === 'number' ? dataView.byteLength : 0;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// Starts a task when fewer than `limit` are running, else queues it until one
|
|
320
|
-
// settles. Promise is only referenced once a task is given, in async mode.
|
|
321
|
-
function createPool(limit) {
|
|
322
|
-
const queue = [];
|
|
323
|
-
let running = 0;
|
|
324
|
-
|
|
325
|
-
return {
|
|
326
|
-
run(task) {
|
|
327
|
-
return new Promise((resolve, reject) => {
|
|
328
|
-
queue.push({task, resolve, reject});
|
|
329
|
-
startNext();
|
|
330
|
-
});
|
|
331
|
-
},
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
function startNext() {
|
|
335
|
-
if (running >= limit || queue.length === 0) {
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
const {task, resolve, reject} = queue.shift();
|
|
339
|
-
running++;
|
|
340
|
-
// The wrapper turns a synchronous throw from a task into a rejection.
|
|
341
|
-
new Promise((start) => start(task())).then((result) => {
|
|
342
|
-
running--;
|
|
343
|
-
startNext();
|
|
344
|
-
resolve(result);
|
|
345
|
-
}, (error) => {
|
|
346
|
-
running--;
|
|
347
|
-
startNext();
|
|
348
|
-
reject(error);
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
277
|
/**
|
|
354
|
-
* Throws when the groups' static emission graph has a cycle
|
|
355
|
-
* through the groups consuming it and what they emit, leads back to itself
|
|
278
|
+
* Throws when the groups' static emission graph has a cycle (a kind that,
|
|
279
|
+
* through the groups consuming it and what they emit, leads back to itself) or
|
|
280
|
+
* a chain of consumed kinds longer than MAX_BLOCK_DEPTH. Only the unit tests
|
|
281
|
+
* call it, over every format and group, the union of every composition.
|
|
356
282
|
*
|
|
357
283
|
* @param {{groups: Array<object>}} composition
|
|
358
284
|
*/
|
|
@@ -371,6 +297,14 @@ export function validateComposition(composition) {
|
|
|
371
297
|
visit(kind);
|
|
372
298
|
}
|
|
373
299
|
|
|
300
|
+
// Runs after the cycle check, so the recursion ends.
|
|
301
|
+
const depths = Object.create(null);
|
|
302
|
+
for (const kind in edges) {
|
|
303
|
+
if (getDepth(kind) > MAX_BLOCK_DEPTH) {
|
|
304
|
+
throw new Error('The group emission graph is deeper than ' + MAX_BLOCK_DEPTH + ' blocks through ' + kind);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
374
308
|
function visit(kind) {
|
|
375
309
|
if (states[kind] === 'done') {
|
|
376
310
|
return;
|
|
@@ -385,4 +319,14 @@ export function validateComposition(composition) {
|
|
|
385
319
|
}
|
|
386
320
|
states[kind] = 'done';
|
|
387
321
|
}
|
|
322
|
+
|
|
323
|
+
// A kind no group consumes is dropped at run time, so it adds no depth.
|
|
324
|
+
function getDepth(kind) {
|
|
325
|
+
if (depths[kind] === undefined) {
|
|
326
|
+
depths[kind] = 1 + edges[kind].reduce((deepest, emitted) => (
|
|
327
|
+
edges[emitted] === undefined ? deepest : Math.max(deepest, getDepth(emitted))
|
|
328
|
+
), 0);
|
|
329
|
+
}
|
|
330
|
+
return depths[kind];
|
|
331
|
+
}
|
|
388
332
|
}
|
package/src/errors.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 {UnsupportedFormatError} from './unsupported-format-error.js';
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* Thrown when no Exif metadata was found for the given image.
|
|
7
9
|
*
|
|
@@ -10,11 +12,15 @@
|
|
|
10
12
|
function MetadataMissingError(message) {
|
|
11
13
|
this.name = 'MetadataMissingError';
|
|
12
14
|
this.message = message || 'No Exif data';
|
|
13
|
-
|
|
15
|
+
// Defined, not assigned, to keep stack out of the enumerable keys.
|
|
16
|
+
Object.defineProperty(this, 'stack', {value: (new Error()).stack, writable: true, configurable: true});
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
MetadataMissingError.prototype =
|
|
19
|
+
MetadataMissingError.prototype = Object.create(Error.prototype, {
|
|
20
|
+
constructor: {value: MetadataMissingError, writable: true, configurable: true}
|
|
21
|
+
});
|
|
17
22
|
|
|
18
23
|
export default {
|
|
19
24
|
MetadataMissingError,
|
|
25
|
+
UnsupportedFormatError,
|
|
20
26
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
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 * as ExifReader from '../exif-reader.js';
|
|
6
|
+
|
|
7
|
+
export * from '../exif-reader.js';
|
|
8
|
+
export default ExifReader;
|