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,197 @@
|
|
|
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 {getCompressionMethod} from '../utils.js';
|
|
6
|
+
import ByteOrder from '../byte-order.js';
|
|
7
|
+
import {getTiffHeaderOffset} from '../image-header-iso-bmff.js';
|
|
8
|
+
import Tags from '../tags.js';
|
|
9
|
+
import {IFD_TYPE_0TH, IFD_TYPE_1ST, IFD_TYPE_EXIF, IFD_TYPE_GPS, IFD_TYPE_INTEROPERABILITY} from '../ifd-types.js';
|
|
10
|
+
import {addDecompressedValueAllowance} from '../tags-helpers.js';
|
|
11
|
+
import {filterTagsForParse} from '../tag-filter.js';
|
|
12
|
+
import {EXIF_POINTER_TAGS} from '../tag-filter-config.js';
|
|
13
|
+
import {getBlockDataView, getBrobDataView} from './group-helpers.js';
|
|
14
|
+
import {getSharedValueBudget} from './value-budget.js';
|
|
15
|
+
import {GROUP_BRAND} from './brand.js';
|
|
16
|
+
|
|
17
|
+
export const EXIF_EMITTED_KINDS = ['iptc', 'xmp', 'photoshop', 'icc', 'makerNote', 'thumbnail'];
|
|
18
|
+
const EXIF_DICTIONARIES = [IFD_TYPE_0TH, IFD_TYPE_EXIF, IFD_TYPE_GPS, IFD_TYPE_INTEROPERABILITY];
|
|
19
|
+
|
|
20
|
+
// The generated Exif tag descriptors link to this, so a createReader bundle
|
|
21
|
+
// carries Exif parsing only when it composes one.
|
|
22
|
+
export const exifBlockReader = {createParseOnlyGroup, isDescriptor};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* An Exif group that reads with dictionaries of the given descriptors only.
|
|
26
|
+
*
|
|
27
|
+
* @param {Array<object>} descriptors Generated Exif tag descriptors.
|
|
28
|
+
* @param {(object|undefined)} ifd1TagNames The dictionary of the thumbnail IFD,
|
|
29
|
+
* when the thumbnail group is composed.
|
|
30
|
+
* @returns {object} An engine group keyed exif.
|
|
31
|
+
*/
|
|
32
|
+
function createParseOnlyGroup(descriptors, ifd1TagNames) {
|
|
33
|
+
const tagNames = getTagNames(descriptors, ifd1TagNames);
|
|
34
|
+
return {
|
|
35
|
+
key: 'exif',
|
|
36
|
+
consumes: ['exif'],
|
|
37
|
+
emits: EXIF_EMITTED_KINDS,
|
|
38
|
+
read: (block, ctx) => readExifBlock(block, ctx, tagNames),
|
|
39
|
+
merge: getExifMergeDescriptor,
|
|
40
|
+
brand: GROUP_BRAND,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Every bucket Tags.read walks must exist, as reading an IFD without its
|
|
45
|
+
// dictionary throws. A descriptor's dictionary key is its IFD type, and
|
|
46
|
+
// src/tags.js follows the sub-IFDs by the pointer names.
|
|
47
|
+
function getTagNames(descriptors, ifd1TagNames) {
|
|
48
|
+
const tagNames0thAndExifIfds = {};
|
|
49
|
+
tagNames0thAndExifIfds[0x8769] = EXIF_POINTER_TAGS.exifIfdPointer;
|
|
50
|
+
tagNames0thAndExifIfds[0x8825] = EXIF_POINTER_TAGS.gpsInfoIfdPointer;
|
|
51
|
+
tagNames0thAndExifIfds[0xa005] = EXIF_POINTER_TAGS.interoperabilityIfdPointer;
|
|
52
|
+
|
|
53
|
+
// Assigned rather than computed keys, which Babel compiles to a helper call each.
|
|
54
|
+
const tagNames = {};
|
|
55
|
+
tagNames[IFD_TYPE_0TH] = tagNames0thAndExifIfds;
|
|
56
|
+
tagNames[IFD_TYPE_EXIF] = tagNames0thAndExifIfds;
|
|
57
|
+
tagNames[IFD_TYPE_GPS] = {};
|
|
58
|
+
tagNames[IFD_TYPE_INTEROPERABILITY] = {};
|
|
59
|
+
// Indexed by the reader's own names only: another reader may have accepted
|
|
60
|
+
// a descriptor, and its dictionary could name what every object inherits.
|
|
61
|
+
for (let i = 0; i < EXIF_DICTIONARIES.length; i++) {
|
|
62
|
+
for (let j = 0; j < descriptors.length; j++) {
|
|
63
|
+
if (descriptors[j].dictionary === EXIF_DICTIONARIES[i]) {
|
|
64
|
+
addEntries(tagNames[EXIF_DICTIONARIES[i]], descriptors[j]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (ifd1TagNames) {
|
|
69
|
+
tagNames[IFD_TYPE_1ST] = ifd1TagNames;
|
|
70
|
+
}
|
|
71
|
+
return tagNames;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// In the dictionaries' own shape. An id the descriptor's describedIds leaves
|
|
75
|
+
// out has no description in its dictionary.
|
|
76
|
+
function addEntries(dictionary, descriptor) {
|
|
77
|
+
for (let i = 0; i < descriptor.ids.length; i++) {
|
|
78
|
+
const id = descriptor.ids[i];
|
|
79
|
+
if (descriptor.description && (!descriptor.describedIds || descriptor.describedIds.indexOf(id) !== -1)) {
|
|
80
|
+
dictionary[id] = {name: descriptor.name, description: descriptor.description};
|
|
81
|
+
} else {
|
|
82
|
+
dictionary[id] = descriptor.name;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function isDescriptor(tag) {
|
|
88
|
+
return tag.group === 'exif' && EXIF_DICTIONARIES.indexOf(tag.dictionary) !== -1;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Reads an Exif block with the given dictionaries.
|
|
93
|
+
*
|
|
94
|
+
* A brob Exif box decompresses through the pool; a decompression failure or a
|
|
95
|
+
* bad header rejects, which drops the block. Only the JPEG XL finder makes one.
|
|
96
|
+
* A JXL Exif box too short for its header has no tiffHeaderOffset and reads
|
|
97
|
+
* nothing.
|
|
98
|
+
*
|
|
99
|
+
* @param {object} block
|
|
100
|
+
* @param {object} ctx The engine context.
|
|
101
|
+
* @param {Object<string, object>} tagNames The dictionaries keyed by IFD type.
|
|
102
|
+
* @returns {({tags: (object|undefined), blocks: Array<object>}|Promise|undefined)}
|
|
103
|
+
*/
|
|
104
|
+
export function readExifBlock(block, ctx, tagNames) {
|
|
105
|
+
if (block.compression !== undefined) {
|
|
106
|
+
if (!ctx.composed.formats.jxl) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
return ctx.decompress(getBrobDataView(ctx.dataView, block), getCompressionMethod(block.compression), undefined, 'dataview')
|
|
110
|
+
.then((view) => readExifView(view, getTiffHeaderOffset(view, 0), ctx, {carried: 'brob', decompressed: true}, tagNames));
|
|
111
|
+
}
|
|
112
|
+
if (block.tiffHeaderOffset === undefined) {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
return readExifView(getBlockDataView(block, ctx), block.tiffHeaderOffset, ctx, {
|
|
116
|
+
carried: block.origin || 'main',
|
|
117
|
+
decompressed: block.decompressed === true,
|
|
118
|
+
}, tagNames);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// The main block creates the value budget from its view; an embedded block
|
|
122
|
+
// draws from the shared one and, when decompressed, adds its allowance.
|
|
123
|
+
function readExifView(view, tiffHeaderOffset, ctx, {carried, decompressed}, tagNames) {
|
|
124
|
+
const isMain = carried === 'main';
|
|
125
|
+
const valueBudget = isMain ? getSharedValueBudget(ctx, view) : getSharedValueBudget(ctx);
|
|
126
|
+
if (decompressed) {
|
|
127
|
+
addDecompressedValueAllowance(valueBudget, view.byteLength);
|
|
128
|
+
}
|
|
129
|
+
const read = isMain ? readExifTagsSafely : readExifTags;
|
|
130
|
+
const {tags, byteOrder, makerNoteOffset} = read(view, tiffHeaderOffset, ctx, valueBudget, tagNames);
|
|
131
|
+
const thumbnailIfdTags = tags.Thumbnail;
|
|
132
|
+
delete tags.Thumbnail;
|
|
133
|
+
|
|
134
|
+
const parsed = filterTagsForParse('exif', tags, ctx.tagFilter);
|
|
135
|
+
const blocks = getExifEmittedBlocks(ctx.composed.fromExif, parsed, {view, tiffHeaderOffset, byteOrder, makerNoteOffset, thumbnailIfdTags, carried, decompressed});
|
|
136
|
+
if (carried === 'brob' && Object.keys(parsed).length === 0) {
|
|
137
|
+
return {tags: undefined, blocks};
|
|
138
|
+
}
|
|
139
|
+
return {tags: parsed, blocks};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function readExifTagsSafely(dataView, tiffHeaderOffset, ctx, valueBudget, tagNames) {
|
|
143
|
+
try {
|
|
144
|
+
return readExifTags(dataView, tiffHeaderOffset, ctx, valueBudget, tagNames);
|
|
145
|
+
} catch (error) {
|
|
146
|
+
// A malformed TIFF header (an out-of-bounds offset or an invalid byte
|
|
147
|
+
// order marker, e.g. from a HEIC/AVIF iloc that does not point at real
|
|
148
|
+
// Exif) must not abort the whole parse. Skip Exif instead, but keep the
|
|
149
|
+
// same shape so callers can destructure safely.
|
|
150
|
+
return {tags: {}, byteOrder: ByteOrder.BIG_ENDIAN, makerNoteOffset: undefined};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function readExifTags(dataView, tiffHeaderOffset, ctx, valueBudget, tagNames) {
|
|
155
|
+
return Tags.read(
|
|
156
|
+
dataView,
|
|
157
|
+
tiffHeaderOffset,
|
|
158
|
+
ctx.options.includeUnknown,
|
|
159
|
+
ctx.options.computed,
|
|
160
|
+
ctx.tagFilter,
|
|
161
|
+
valueBudget,
|
|
162
|
+
tagNames,
|
|
163
|
+
shouldReadThumbnailIfd(ctx)
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function shouldReadThumbnailIfd(ctx) {
|
|
168
|
+
return ctx.composed.groups.thumbnail === true && ctx.tagFilter.shouldParseGroup('thumbnail');
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Each composed group consuming an emitted kind brings its block's extractor.
|
|
172
|
+
// The blocks follow EXIF_EMITTED_KINDS, not the groups' order: they dispatch in
|
|
173
|
+
// emission order and their readers draw from one value budget.
|
|
174
|
+
function getExifEmittedBlocks(fromExif, parsed, exif) {
|
|
175
|
+
const blocks = [];
|
|
176
|
+
for (let i = 0; i < EXIF_EMITTED_KINDS.length; i++) {
|
|
177
|
+
const getBlock = fromExif[EXIF_EMITTED_KINDS[i]];
|
|
178
|
+
const block = getBlock && getBlock(parsed, exif);
|
|
179
|
+
if (block) {
|
|
180
|
+
blocks.push(block);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return blocks;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Where an Exif block's tags go in the result.
|
|
188
|
+
*
|
|
189
|
+
* @param {object} block
|
|
190
|
+
* @returns {{slot: string, mode: string, outerSlot: (string|undefined)}}
|
|
191
|
+
*/
|
|
192
|
+
export function getExifMergeDescriptor(block) {
|
|
193
|
+
if (block.compression !== undefined) {
|
|
194
|
+
return {slot: 'exif', mode: 'merge', outerSlot: 'brobExif'};
|
|
195
|
+
}
|
|
196
|
+
return {slot: 'exif', mode: block.origin !== undefined ? 'merge' : 'assign'};
|
|
197
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 Avif from '../../image-header-avif.js';
|
|
6
|
+
import {isoBmffFile} from './iso-bmff-file-reader.js';
|
|
7
|
+
import {FORMAT_BRAND} from '../brand.js';
|
|
8
|
+
|
|
9
|
+
export const avifHeader = {
|
|
10
|
+
fileType: {value: 'avif', description: 'AVIF'},
|
|
11
|
+
detect: (dataView) => Avif.isAvifFile(dataView),
|
|
12
|
+
find: (dataView, ranges) => Avif.findAvifOffsets(dataView, ranges),
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const avif = {
|
|
16
|
+
header: avifHeader,
|
|
17
|
+
readers: [isoBmffFile],
|
|
18
|
+
brand: FORMAT_BRAND,
|
|
19
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
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 Gif from '../../image-header-gif.js';
|
|
6
|
+
import GifFileTags from '../../gif-file-tags.js';
|
|
7
|
+
import {parsedTags} from '../group-helpers.js';
|
|
8
|
+
import {FORMAT_BRAND} from '../brand.js';
|
|
9
|
+
|
|
10
|
+
export const gifHeader = {
|
|
11
|
+
fileType: {value: 'gif', description: 'GIF'},
|
|
12
|
+
detect: (dataView) => Gif.isGifFile(dataView),
|
|
13
|
+
find: (dataView, ranges) => Gif.findOffsets(dataView, ranges),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const gifReader = {
|
|
17
|
+
key: 'gif',
|
|
18
|
+
consumes: ['gif'],
|
|
19
|
+
emits: [],
|
|
20
|
+
read: (block, ctx) => parsedTags('gif', GifFileTags.read(ctx.dataView, block.dataOffset), ctx),
|
|
21
|
+
merge: () => ({slot: 'gif', mode: 'merge'}),
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const gif = {
|
|
25
|
+
header: gifHeader,
|
|
26
|
+
readers: [gifReader],
|
|
27
|
+
brand: FORMAT_BRAND,
|
|
28
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
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 Heic from '../../image-header-heic.js';
|
|
6
|
+
import {isoBmffFile} from './iso-bmff-file-reader.js';
|
|
7
|
+
import {FORMAT_BRAND} from '../brand.js';
|
|
8
|
+
|
|
9
|
+
export const heicHeader = {
|
|
10
|
+
fileType: {value: 'heic', description: 'HEIC'},
|
|
11
|
+
detect: (dataView) => Heic.isHeicFile(dataView),
|
|
12
|
+
find: (dataView, ranges) => Heic.findHeicOffsets(dataView, ranges),
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const heic = {
|
|
16
|
+
header: heicHeader,
|
|
17
|
+
readers: [isoBmffFile],
|
|
18
|
+
brand: FORMAT_BRAND,
|
|
19
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
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 IsoBmffFileTags from '../../iso-bmff-file-tags.js';
|
|
6
|
+
import {parsedTags} from '../group-helpers.js';
|
|
7
|
+
|
|
8
|
+
export const isoBmffFile = {
|
|
9
|
+
key: 'file',
|
|
10
|
+
consumes: ['isoBmffFile'],
|
|
11
|
+
emits: [],
|
|
12
|
+
read: (block, ctx) => parsedTags('file', IsoBmffFileTags.read(ctx.dataView, block.imageDimensionsOffset, block.pixelInformationOffset), ctx),
|
|
13
|
+
merge: () => ({slot: 'isoBmffFile', mode: 'assign'}),
|
|
14
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
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 Jpeg from '../../image-header-jpeg.js';
|
|
6
|
+
import FileTags from '../../file-tags.js';
|
|
7
|
+
import JfifTags from '../../jfif-tags.js';
|
|
8
|
+
import {parsedTags} from '../group-helpers.js';
|
|
9
|
+
import {FORMAT_BRAND} from '../brand.js';
|
|
10
|
+
|
|
11
|
+
export const jpegHeader = {
|
|
12
|
+
fileType: {value: 'jpeg', description: 'JPEG'},
|
|
13
|
+
detect: (dataView) => Jpeg.isJpegFile(dataView),
|
|
14
|
+
find: (dataView, ranges) => Jpeg.findJpegOffsets(dataView, ranges),
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const file = {
|
|
18
|
+
key: 'file',
|
|
19
|
+
consumes: ['file'],
|
|
20
|
+
emits: [],
|
|
21
|
+
read: readFileBlock,
|
|
22
|
+
merge: () => ({slot: 'file', mode: 'assign'}),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const jfif = {
|
|
26
|
+
key: 'jfif',
|
|
27
|
+
consumes: ['jfif'],
|
|
28
|
+
emits: [],
|
|
29
|
+
read: (block, ctx) => parsedTags('jfif', JfifTags.read(ctx.dataView, block.dataOffset), ctx),
|
|
30
|
+
merge: () => ({slot: 'jfif', mode: 'assign'}),
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const jpeg = {
|
|
34
|
+
header: jpegHeader,
|
|
35
|
+
readers: [file, jfif],
|
|
36
|
+
brand: FORMAT_BRAND,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
function readFileBlock(block, ctx) {
|
|
40
|
+
if (!shouldReadFileTagsForFileTypeOnlyOptimization(ctx.options.includeTags)) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
return parsedTags('file', FileTags.read(ctx.dataView, block.dataOffset), ctx);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function shouldReadFileTagsForFileTypeOnlyOptimization(includeTagsOptions) {
|
|
47
|
+
if (!includeTagsOptions) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
const {composite, file: fileTagNames} = includeTagsOptions;
|
|
51
|
+
if (composite === true || (Array.isArray(composite) && composite.length > 0)) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return !(Array.isArray(fileTagNames) && fileTagNames.length === 1 && fileTagNames[0] === 'FileType');
|
|
55
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 Jxl from '../../image-header-jxl.js';
|
|
6
|
+
import JxlFileTags from '../../jxl-file-tags.js';
|
|
7
|
+
import {parsedTags} from '../group-helpers.js';
|
|
8
|
+
import {FORMAT_BRAND} from '../brand.js';
|
|
9
|
+
import {decompression} from '../../decompression.js';
|
|
10
|
+
|
|
11
|
+
export const jxlHeader = {
|
|
12
|
+
fileType: {value: 'jxl', description: 'JPEG XL'},
|
|
13
|
+
detect: (dataView) => Jxl.isJxlFile(dataView),
|
|
14
|
+
find: (dataView, ranges) => Jxl.findJxlOffsets(dataView, ranges),
|
|
15
|
+
decompression,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const jxlFile = {
|
|
19
|
+
key: 'file',
|
|
20
|
+
consumes: ['jxlFile'],
|
|
21
|
+
emits: [],
|
|
22
|
+
read: (block, ctx) => parsedTags('file', JxlFileTags.read(ctx.dataView, block.codestreamOffset), ctx),
|
|
23
|
+
merge: () => ({slot: 'jxlFile', mode: 'assign'}),
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const jxl = {
|
|
27
|
+
header: jxlHeader,
|
|
28
|
+
readers: [jxlFile],
|
|
29
|
+
brand: FORMAT_BRAND,
|
|
30
|
+
};
|
|
@@ -0,0 +1,187 @@
|
|
|
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 Png, {TYPE_ZTXT} from '../../image-header-png.js';
|
|
6
|
+
import PngFileTags from '../../png-file-tags.js';
|
|
7
|
+
import PngTextTags, {hasRawIptcProfile} from '../../png-text-tags.js';
|
|
8
|
+
import PngTags from '../../png-tags.js';
|
|
9
|
+
import {parsedTags, isPngTextChunkBlock} from '../group-helpers.js';
|
|
10
|
+
import {FORMAT_BRAND} from '../brand.js';
|
|
11
|
+
import {decompression} from '../../decompression.js';
|
|
12
|
+
import {objectAssign} from '../../utils.js';
|
|
13
|
+
import {addToCompositeInput} from '../../loadview-pipeline.js';
|
|
14
|
+
|
|
15
|
+
export const pngHeader = {
|
|
16
|
+
fileType: {value: 'png', description: 'PNG'},
|
|
17
|
+
detect: (dataView) => Png.isPngFile(dataView),
|
|
18
|
+
find: (dataView, ranges) => Png.findPngOffsets(dataView, ranges),
|
|
19
|
+
isHiddenInSyncMode: isCompressedTextChunkTypeBlock,
|
|
20
|
+
decompression,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const pngFile = {
|
|
24
|
+
key: 'png',
|
|
25
|
+
consumes: ['pngFile'],
|
|
26
|
+
emits: [],
|
|
27
|
+
read: (block, ctx) => parsedTags('png', PngFileTags.read(ctx.dataView, block.dataOffset), ctx),
|
|
28
|
+
merge: () => ({slot: 'pngFile', mode: 'pngFile'}),
|
|
29
|
+
mergeModes: {pngFile: mergePngFileTags},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const pngText = {
|
|
33
|
+
key: 'png',
|
|
34
|
+
consumes: ['pngText'],
|
|
35
|
+
emits: ['exif', 'iptc'],
|
|
36
|
+
read: (block, ctx) => PngTextTags.read(block, ctx),
|
|
37
|
+
merge: (block) => ({slot: block.compression !== undefined ? 'deferredPngText' : 'pngText', mode: 'pngTextTags'}),
|
|
38
|
+
suppressions: [{kind: 'iptc', isSuppressed: isRawProfileIptcSuppressed}],
|
|
39
|
+
mergeModes: {pngTextTags: mergePngTextTags},
|
|
40
|
+
prepareMergeBlocks: combineUncompressedPngTextBlocks,
|
|
41
|
+
finishTags: addPngTextCopyOfPng,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const pngChunk = {
|
|
45
|
+
key: 'png',
|
|
46
|
+
consumes: ['pngChunk'],
|
|
47
|
+
emits: [],
|
|
48
|
+
read: (block, ctx) => parsedTags('png', PngTags.read(ctx.dataView, [block.dataOffset]), ctx),
|
|
49
|
+
merge: () => ({slot: 'pngChunk', mode: 'merge'}),
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const png = {
|
|
53
|
+
header: pngHeader,
|
|
54
|
+
readers: [pngFile, pngText, pngChunk],
|
|
55
|
+
brand: FORMAT_BRAND,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Sync mode leaves the compressed-text chunk type out,
|
|
59
|
+
// whatever its header says (see isHiddenInSyncMode in composition.js).
|
|
60
|
+
function isCompressedTextChunkTypeBlock(block) {
|
|
61
|
+
return isPngTextChunkBlock(block) && block.text.chunkType === TYPE_ZTXT;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// The png group gathers the file, text and chunk tags; pngFile keeps the file
|
|
65
|
+
// tags alone.
|
|
66
|
+
function mergePngFileTags(tags, block, context) {
|
|
67
|
+
context.parsedGroups.pngFile = block.tags;
|
|
68
|
+
addToCompositeInput(block.tags, context);
|
|
69
|
+
if (!context.tagFilter.shouldReturnGroup('png')) {
|
|
70
|
+
return tags;
|
|
71
|
+
}
|
|
72
|
+
const returnedTags = context.deps.filterTagsForReturn('png', block.tags, context.tagFilter);
|
|
73
|
+
|
|
74
|
+
if (context.expanded) {
|
|
75
|
+
context.merge.group(tags, 'png', returnedTags);
|
|
76
|
+
tags.pngFile = returnedTags;
|
|
77
|
+
|
|
78
|
+
return tags;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return context.merge.topLevel(tags, returnedTags);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// A raw profile's IPTC-NAA gives way to a raw IPTC chunk the text reader will
|
|
85
|
+
// read, compressed or not. The raw IPTC scan decodes text chunks, so its
|
|
86
|
+
// verdict is kept on the context: the finder blocks do not change within a
|
|
87
|
+
// load, and a PNG can hold thousands of raw profiles.
|
|
88
|
+
function isRawProfileIptcSuppressed(block, finderBlocks, ctx) {
|
|
89
|
+
if (block.carried !== 'rawProfile') {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
if (ctx.hasRawIptcProfile === undefined) {
|
|
93
|
+
ctx.hasRawIptcProfile = hasRawIptcProfile(finderBlocks, ctx.dataView);
|
|
94
|
+
}
|
|
95
|
+
return ctx.hasRawIptcProfile;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// pngText holds the text tags only when there are any; otherwise
|
|
99
|
+
// addPngTextCopyOfPng may fill it with a copy of png.
|
|
100
|
+
function mergePngTextTags(tags, block, context) {
|
|
101
|
+
addToCompositeInput(block.tags, context);
|
|
102
|
+
if (!context.tagFilter.shouldReturnGroup('png')) {
|
|
103
|
+
return tags;
|
|
104
|
+
}
|
|
105
|
+
const returnedTags = context.deps.filterTagsForReturn('png', block.tags, context.tagFilter);
|
|
106
|
+
|
|
107
|
+
if (context.expanded) {
|
|
108
|
+
context.merge.group(tags, 'png', returnedTags);
|
|
109
|
+
if (Object.keys(returnedTags).length > 0) {
|
|
110
|
+
context.merge.group(tags, 'pngText', returnedTags);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return tags;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return context.merge.topLevel(tags, returnedTags);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Every uncompressed text chunk of a PNG merges as one tier, so that the text
|
|
120
|
+
// tags sort after an uncompressed raw-profile Exif whatever the chunk order and
|
|
121
|
+
// two raw profiles merge group by group. A compressed chunk stays its own tier.
|
|
122
|
+
function combineUncompressedPngTextBlocks(mergeBlocks) {
|
|
123
|
+
const combined = [];
|
|
124
|
+
const leaves = [];
|
|
125
|
+
let tierIndex = -1;
|
|
126
|
+
|
|
127
|
+
for (let i = 0; i < mergeBlocks.length; i++) {
|
|
128
|
+
if (mergeBlocks[i].slot !== 'pngText') {
|
|
129
|
+
combined.push(mergeBlocks[i]);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (tierIndex === -1) {
|
|
133
|
+
tierIndex = combined.length;
|
|
134
|
+
combined.push(undefined);
|
|
135
|
+
}
|
|
136
|
+
collectLeafBlocks(mergeBlocks[i], leaves);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (tierIndex !== -1) {
|
|
140
|
+
combined[tierIndex] = {slot: 'pngText', mode: 'nested', blocks: leaves};
|
|
141
|
+
}
|
|
142
|
+
return combined;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function collectLeafBlocks(block, leaves) {
|
|
146
|
+
if (block.mode !== 'nested') {
|
|
147
|
+
leaves.push(block);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
for (let i = 0; i < block.blocks.length; i++) {
|
|
151
|
+
collectLeafBlocks(block.blocks[i], leaves);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Expanded output gets a pngText group that copies png when the text chunks
|
|
156
|
+
// are read asynchronously, or when there are text chunks (raw profiles
|
|
157
|
+
// included) but none of them gave PNG text tags. `blocks` are the finder
|
|
158
|
+
// blocks the load reads, so in sync mode without the compressed-text chunks.
|
|
159
|
+
function addPngTextCopyOfPng(tags, {expanded, async, tagFilter, blocks}) {
|
|
160
|
+
const pngTextBlocks = blocks.filter(isPngTextChunkBlock);
|
|
161
|
+
|
|
162
|
+
if (
|
|
163
|
+
expanded
|
|
164
|
+
&& async
|
|
165
|
+
&& pngTextBlocks.some(isNamedCompressedPngTextChunk)
|
|
166
|
+
&& tagFilter.shouldReturnGroup('png')
|
|
167
|
+
&& tags.png
|
|
168
|
+
) {
|
|
169
|
+
tags.pngText = objectAssign({}, tags.png);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (
|
|
173
|
+
expanded
|
|
174
|
+
&& tagFilter.shouldReturnGroup('png')
|
|
175
|
+
&& pngTextBlocks.length > 0
|
|
176
|
+
&& tags.png
|
|
177
|
+
&& !tags.pngText
|
|
178
|
+
) {
|
|
179
|
+
tags.pngText = objectAssign({}, tags.png);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return tags;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function isNamedCompressedPngTextChunk(block) {
|
|
186
|
+
return block.compression !== undefined && block.text.name !== undefined;
|
|
187
|
+
}
|
|
@@ -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 Tiff from '../../image-header-tiff.js';
|
|
6
|
+
import {FORMAT_BRAND} from '../brand.js';
|
|
7
|
+
|
|
8
|
+
export const tiffHeader = {
|
|
9
|
+
fileType: {value: 'tiff', description: 'TIFF'},
|
|
10
|
+
detect: (dataView) => Tiff.isTiffFile(dataView),
|
|
11
|
+
find: () => Tiff.findTiffOffsets(),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const tiff = {
|
|
15
|
+
header: tiffHeader,
|
|
16
|
+
readers: [],
|
|
17
|
+
brand: FORMAT_BRAND,
|
|
18
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
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 Webp from '../../image-header-webp.js';
|
|
6
|
+
import Vp8xTags from '../../vp8x-tags.js';
|
|
7
|
+
import {parsedTags} from '../group-helpers.js';
|
|
8
|
+
import {FORMAT_BRAND} from '../brand.js';
|
|
9
|
+
|
|
10
|
+
export const webpHeader = {
|
|
11
|
+
fileType: {value: 'webp', description: 'WebP'},
|
|
12
|
+
detect: (dataView) => Webp.isWebpFile(dataView),
|
|
13
|
+
find: (dataView, ranges) => Webp.findOffsets(dataView, ranges),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const riff = {
|
|
17
|
+
key: 'riff',
|
|
18
|
+
consumes: ['riff'],
|
|
19
|
+
emits: [],
|
|
20
|
+
read: (block, ctx) => parsedTags('riff', Vp8xTags.read(ctx.dataView, block.dataOffset), ctx),
|
|
21
|
+
merge: () => ({slot: 'riff', mode: 'merge'}),
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const webp = {
|
|
25
|
+
header: webpHeader,
|
|
26
|
+
readers: [riff],
|
|
27
|
+
brand: FORMAT_BRAND,
|
|
28
|
+
};
|
|
@@ -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 Xml from '../../xml.js';
|
|
6
|
+
import {FORMAT_BRAND} from '../brand.js';
|
|
7
|
+
|
|
8
|
+
export const xmlHeader = {
|
|
9
|
+
fileType: {value: 'xml', description: 'XML'},
|
|
10
|
+
detect: (dataView) => Xml.isXMLFile(dataView),
|
|
11
|
+
find: (dataView, ranges) => Xml.findOffsets(dataView, ranges),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const xml = {
|
|
15
|
+
header: xmlHeader,
|
|
16
|
+
readers: [],
|
|
17
|
+
brand: FORMAT_BRAND,
|
|
18
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
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 type {Format} from './core.js';
|
|
6
|
+
|
|
7
|
+
export declare const tiff: Format<'file'>;
|
|
8
|
+
export declare const jpeg: Format<'file' | 'jfif'>;
|
|
9
|
+
export declare const png: Format<'file' | 'png'>;
|
|
10
|
+
export declare const heic: Format<'file'>;
|
|
11
|
+
export declare const avif: Format<'file'>;
|
|
12
|
+
export declare const jxl: Format<'file'>;
|
|
13
|
+
export declare const webp: Format<'file' | 'riff'>;
|
|
14
|
+
export declare const gif: Format<'file' | 'gif'>;
|
|
15
|
+
export declare const xml: Format<'file'>;
|
|
16
|
+
|
|
17
|
+
export declare const allFormats: readonly Format[];
|
|
@@ -0,0 +1,17 @@
|
|
|
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 {tiff} from './formats/tiff.js';
|
|
6
|
+
import {jpeg} from './formats/jpeg.js';
|
|
7
|
+
import {png} from './formats/png.js';
|
|
8
|
+
import {heic} from './formats/heic.js';
|
|
9
|
+
import {avif} from './formats/avif.js';
|
|
10
|
+
import {jxl} from './formats/jxl.js';
|
|
11
|
+
import {webp} from './formats/webp.js';
|
|
12
|
+
import {gif} from './formats/gif.js';
|
|
13
|
+
import {xml} from './formats/xml.js';
|
|
14
|
+
|
|
15
|
+
export {tiff, jpeg, png, heic, avif, jxl, webp, gif, xml};
|
|
16
|
+
|
|
17
|
+
export const allFormats = [tiff, jpeg, png, heic, avif, jxl, webp, gif, xml];
|