exifreader 4.41.1 → 4.41.2
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/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/package.json +1 -1
- package/src/exif-reader.js +32 -123
- package/src/file-loaders.js +5 -17
- package/src/gif-file-tags.js +20 -92
- package/src/icc-tag-names.js +1 -1
- package/src/icc-tags.js +1 -5
- package/src/image-header-avif.js +4 -11
- package/src/image-header-gif.js +2 -4
- package/src/image-header-heic.js +4 -13
- package/src/image-header-iso-bmff-iloc.js +7 -2
- package/src/image-header-iso-bmff.js +31 -34
- package/src/image-header-jpeg.js +25 -39
- package/src/image-header-jxl.js +5 -12
- package/src/image-header-png.js +2 -8
- package/src/image-header-webp.js +2 -8
- package/src/load-auto.js +2 -4
- package/src/loadview-pipeline.js +15 -19
- package/src/png-file-tags.js +29 -114
- package/src/tag-names-utils.js +3 -3
- package/src/tags.js +26 -65
- package/src/utils.js +12 -0
- package/src/xml.js +2 -2
package/package.json
CHANGED
package/src/exif-reader.js
CHANGED
|
@@ -8,12 +8,10 @@
|
|
|
8
8
|
*/
|
|
9
9
|
/* global Buffer */
|
|
10
10
|
|
|
11
|
-
import {objectAssign, decompress, COMPRESSION_METHOD_BROTLI} from './utils.js';
|
|
11
|
+
import {objectAssign, decompress, COMPRESSION_METHOD_BROTLI, getDataView, getStringValueFromArray, assertPromiseSupport} from './utils.js';
|
|
12
12
|
import {isFilePathOrURL, isBrowserFileObject, loadFile, loadFileObject} from './file-loaders.js';
|
|
13
13
|
import {makeLoadAuto, validateAutoOptions} from './load-auto.js';
|
|
14
|
-
import DataViewWrapper from './dataview.js';
|
|
15
14
|
import Constants from './constants.js';
|
|
16
|
-
import {getStringValueFromArray} from './utils.js';
|
|
17
15
|
import {getCalculatedGpsValue} from './tag-names-utils.js';
|
|
18
16
|
import ByteOrder from './byte-order.js';
|
|
19
17
|
import {getTiffHeaderOffset} from './image-header-iso-bmff.js';
|
|
@@ -53,21 +51,12 @@ export function load(data, options = {}) {
|
|
|
53
51
|
validateAutoOptions(options);
|
|
54
52
|
return makeLoadAuto(loadFromData)(data, options);
|
|
55
53
|
}
|
|
56
|
-
if (isFilePathOrURL(data)) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
const asyncOptions = objectAssign({}, options, {async: true});
|
|
61
|
-
|
|
62
|
-
return loadFile(data, asyncOptions).then((fileContents) => loadFromData(fileContents, asyncOptions));
|
|
63
|
-
}
|
|
64
|
-
if (isBrowserFileObject(data)) {
|
|
65
|
-
if (typeof Promise === 'undefined') {
|
|
66
|
-
throw new Error('Promise is required when async mode is enabled.');
|
|
67
|
-
}
|
|
54
|
+
if (isFilePathOrURL(data) || isBrowserFileObject(data)) {
|
|
55
|
+
assertPromiseSupport();
|
|
56
|
+
const loadFileFunction = isFilePathOrURL(data) ? loadFile : loadFileObject;
|
|
68
57
|
const asyncOptions = objectAssign({}, options, {async: true});
|
|
69
58
|
|
|
70
|
-
return
|
|
59
|
+
return loadFileFunction(data, asyncOptions).then((fileContents) => loadFromData(fileContents, asyncOptions));
|
|
71
60
|
}
|
|
72
61
|
return loadFromData(data, options);
|
|
73
62
|
}
|
|
@@ -89,14 +78,6 @@ function isNodeBuffer(data) {
|
|
|
89
78
|
}
|
|
90
79
|
}
|
|
91
80
|
|
|
92
|
-
function getDataView(data) {
|
|
93
|
-
try {
|
|
94
|
-
return new DataView(data);
|
|
95
|
-
} catch (error) {
|
|
96
|
-
return new DataViewWrapper(data);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
81
|
export function loadView(
|
|
101
82
|
dataView,
|
|
102
83
|
{
|
|
@@ -109,17 +90,7 @@ export function loadView(
|
|
|
109
90
|
includeTags = undefined,
|
|
110
91
|
excludeTags = undefined,
|
|
111
92
|
decompress: decompressConfig = undefined
|
|
112
|
-
} = {
|
|
113
|
-
expanded: false,
|
|
114
|
-
async: false,
|
|
115
|
-
computed: false,
|
|
116
|
-
includeUnknown: false,
|
|
117
|
-
includeOffsets: false,
|
|
118
|
-
domParser: undefined,
|
|
119
|
-
includeTags: undefined,
|
|
120
|
-
excludeTags: undefined,
|
|
121
|
-
decompress: undefined
|
|
122
|
-
}
|
|
93
|
+
} = {}
|
|
123
94
|
) {
|
|
124
95
|
const tagFilter = createTagFilter({includeTags, excludeTags});
|
|
125
96
|
const parsedGroups = Object.create(null);
|
|
@@ -173,7 +144,7 @@ export function loadView(
|
|
|
173
144
|
if (
|
|
174
145
|
Constants.USE_JPEG
|
|
175
146
|
&& Constants.USE_FILE
|
|
176
|
-
&&
|
|
147
|
+
&& fileDataOffset !== undefined
|
|
177
148
|
&& tagFilter.shouldParseGroup('file')
|
|
178
149
|
&& shouldReadFileTagsForFileTypeOnlyOptimization(includeTags)
|
|
179
150
|
) {
|
|
@@ -193,7 +164,7 @@ export function loadView(
|
|
|
193
164
|
if (
|
|
194
165
|
Constants.USE_JPEG
|
|
195
166
|
&& Constants.USE_JFIF
|
|
196
|
-
&&
|
|
167
|
+
&& jfifDataOffset !== undefined
|
|
197
168
|
&& tagFilter.shouldParseGroup('jfif')
|
|
198
169
|
) {
|
|
199
170
|
const readTags = JfifTags.read(dataView, jfifDataOffset);
|
|
@@ -211,7 +182,7 @@ export function loadView(
|
|
|
211
182
|
|
|
212
183
|
if (
|
|
213
184
|
Constants.USE_EXIF
|
|
214
|
-
&&
|
|
185
|
+
&& tiffHeaderOffset !== undefined
|
|
215
186
|
&& tagFilter.shouldParseGroup('exif')
|
|
216
187
|
) {
|
|
217
188
|
const {tags: readTags, byteOrder} = readExifTagsSafely(
|
|
@@ -233,7 +204,7 @@ export function loadView(
|
|
|
233
204
|
Constants.USE_TIFF
|
|
234
205
|
&& Constants.USE_IPTC
|
|
235
206
|
&& parsedExifTags['IPTC-NAA']
|
|
236
|
-
&&
|
|
207
|
+
&& iptcDataOffset === undefined
|
|
237
208
|
&& tagFilter.shouldParseGroup('iptc')
|
|
238
209
|
) {
|
|
239
210
|
const readIptcTags = IptcTags.read(
|
|
@@ -400,7 +371,7 @@ export function loadView(
|
|
|
400
371
|
if (
|
|
401
372
|
Constants.USE_JPEG
|
|
402
373
|
&& Constants.USE_IPTC
|
|
403
|
-
&&
|
|
374
|
+
&& iptcDataOffset !== undefined
|
|
404
375
|
&& tagFilter.shouldParseGroup('iptc')
|
|
405
376
|
) {
|
|
406
377
|
const readTags = IptcTags.read(dataView, iptcDataOffset, includeUnknown, tagFilter);
|
|
@@ -437,7 +408,7 @@ export function loadView(
|
|
|
437
408
|
Constants.USE_JXL
|
|
438
409
|
&& Constants.USE_EXIF
|
|
439
410
|
&& brobExifChunk
|
|
440
|
-
&&
|
|
411
|
+
&& tiffHeaderOffset === undefined
|
|
441
412
|
&& tagFilter.shouldParseGroup('exif')
|
|
442
413
|
&& async
|
|
443
414
|
) {
|
|
@@ -538,7 +509,7 @@ export function loadView(
|
|
|
538
509
|
|
|
539
510
|
if (
|
|
540
511
|
Constants.USE_MPF
|
|
541
|
-
&&
|
|
512
|
+
&& mpfDataOffset !== undefined
|
|
542
513
|
&& tagFilter.shouldParseGroup('mpf')
|
|
543
514
|
) {
|
|
544
515
|
const readMpfTags = MpfTags.read(
|
|
@@ -563,7 +534,7 @@ export function loadView(
|
|
|
563
534
|
if (
|
|
564
535
|
Constants.USE_PNG
|
|
565
536
|
&& Constants.USE_PNG_FILE
|
|
566
|
-
&&
|
|
537
|
+
&& pngHeaderOffset !== undefined
|
|
567
538
|
&& tagFilter.shouldParseGroup('png')
|
|
568
539
|
) {
|
|
569
540
|
const readTags = PngFileTags.read(dataView, pngHeaderOffset);
|
|
@@ -616,7 +587,7 @@ export function loadView(
|
|
|
616
587
|
|
|
617
588
|
if (
|
|
618
589
|
Constants.USE_PNG
|
|
619
|
-
&&
|
|
590
|
+
&& pngChunkOffsets !== undefined
|
|
620
591
|
&& tagFilter.shouldParseGroup('png')
|
|
621
592
|
) {
|
|
622
593
|
const readTags = PngTags.read(dataView, pngChunkOffsets);
|
|
@@ -633,7 +604,7 @@ export function loadView(
|
|
|
633
604
|
|
|
634
605
|
if (
|
|
635
606
|
Constants.USE_WEBP
|
|
636
|
-
&&
|
|
607
|
+
&& vp8xChunkOffset !== undefined
|
|
637
608
|
&& tagFilter.shouldParseGroup('riff')
|
|
638
609
|
) {
|
|
639
610
|
const readTags = Vp8xTags.read(dataView, vp8xChunkOffset);
|
|
@@ -651,7 +622,7 @@ export function loadView(
|
|
|
651
622
|
|
|
652
623
|
if (
|
|
653
624
|
Constants.USE_GIF
|
|
654
|
-
&&
|
|
625
|
+
&& gifHeaderOffset !== undefined
|
|
655
626
|
&& tagFilter.shouldParseGroup('gif')
|
|
656
627
|
) {
|
|
657
628
|
const readTags = GifFileTags.read(dataView, gifHeaderOffset);
|
|
@@ -669,7 +640,7 @@ export function loadView(
|
|
|
669
640
|
|
|
670
641
|
if (
|
|
671
642
|
Constants.USE_JXL
|
|
672
|
-
&&
|
|
643
|
+
&& jxlCodestreamOffset !== undefined
|
|
673
644
|
&& tagFilter.shouldParseGroup('file')
|
|
674
645
|
) {
|
|
675
646
|
const readTags = JxlFileTags.read(dataView, jxlCodestreamOffset);
|
|
@@ -713,9 +684,7 @@ export function loadView(
|
|
|
713
684
|
};
|
|
714
685
|
|
|
715
686
|
if (async) {
|
|
716
|
-
|
|
717
|
-
throw new Error('Promise is required when async mode is enabled.');
|
|
718
|
-
}
|
|
687
|
+
assertPromiseSupport();
|
|
719
688
|
|
|
720
689
|
return Promise.all(deferredPromises).then(() => {
|
|
721
690
|
const tags = buildTagsFromMergeSteps({
|
|
@@ -758,31 +727,11 @@ export function loadView(
|
|
|
758
727
|
if (!includeTagsOptions) {
|
|
759
728
|
return true;
|
|
760
729
|
}
|
|
761
|
-
|
|
762
|
-
if (
|
|
763
|
-
return true;
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
if (
|
|
767
|
-
Array.isArray(includeTagsOptions.composite)
|
|
768
|
-
&& includeTagsOptions.composite.length > 0
|
|
769
|
-
) {
|
|
770
|
-
return true;
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
if (!includeTagsOptions.file || includeTagsOptions.file === true) {
|
|
774
|
-
return true;
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
if (!Array.isArray(includeTagsOptions.file)) {
|
|
730
|
+
const {composite, file} = includeTagsOptions;
|
|
731
|
+
if (composite === true || (Array.isArray(composite) && composite.length > 0)) {
|
|
778
732
|
return true;
|
|
779
733
|
}
|
|
780
|
-
|
|
781
|
-
const isFileTypeOnly =
|
|
782
|
-
includeTagsOptions.file.length === 1
|
|
783
|
-
&& includeTagsOptions.file[0] === 'FileType';
|
|
784
|
-
|
|
785
|
-
return !isFileTypeOnly;
|
|
734
|
+
return !(Array.isArray(file) && file.length === 1 && file[0] === 'FileType');
|
|
786
735
|
}
|
|
787
736
|
}
|
|
788
737
|
|
|
@@ -869,21 +818,21 @@ function hasPotentialMetaData({
|
|
|
869
818
|
|| (
|
|
870
819
|
Constants.USE_JPEG
|
|
871
820
|
&& Constants.USE_FILE
|
|
872
|
-
&&
|
|
821
|
+
&& fileDataOffset !== undefined
|
|
873
822
|
)
|
|
874
823
|
|| (
|
|
875
824
|
Constants.USE_JPEG
|
|
876
825
|
&& Constants.USE_JFIF
|
|
877
|
-
&&
|
|
826
|
+
&& jfifDataOffset !== undefined
|
|
878
827
|
)
|
|
879
828
|
|| (
|
|
880
829
|
Constants.USE_EXIF
|
|
881
|
-
&&
|
|
830
|
+
&& tiffHeaderOffset !== undefined
|
|
882
831
|
)
|
|
883
832
|
|| (
|
|
884
833
|
Constants.USE_JPEG
|
|
885
834
|
&& Constants.USE_IPTC
|
|
886
|
-
&&
|
|
835
|
+
&& iptcDataOffset !== undefined
|
|
887
836
|
)
|
|
888
837
|
|| (
|
|
889
838
|
Constants.USE_XMP
|
|
@@ -896,12 +845,12 @@ function hasPotentialMetaData({
|
|
|
896
845
|
)
|
|
897
846
|
|| (
|
|
898
847
|
Constants.USE_MPF
|
|
899
|
-
&&
|
|
848
|
+
&& mpfDataOffset !== undefined
|
|
900
849
|
)
|
|
901
850
|
|| (
|
|
902
851
|
Constants.USE_PNG
|
|
903
852
|
&& Constants.USE_PNG_FILE
|
|
904
|
-
&&
|
|
853
|
+
&& pngHeaderOffset !== undefined
|
|
905
854
|
)
|
|
906
855
|
|| (
|
|
907
856
|
Constants.USE_PNG
|
|
@@ -909,19 +858,19 @@ function hasPotentialMetaData({
|
|
|
909
858
|
)
|
|
910
859
|
|| (
|
|
911
860
|
Constants.USE_PNG
|
|
912
|
-
&&
|
|
861
|
+
&& pngChunkOffsets !== undefined
|
|
913
862
|
)
|
|
914
863
|
|| (
|
|
915
864
|
Constants.USE_WEBP
|
|
916
|
-
&&
|
|
865
|
+
&& vp8xChunkOffset !== undefined
|
|
917
866
|
)
|
|
918
867
|
|| (
|
|
919
868
|
Constants.USE_GIF
|
|
920
|
-
&&
|
|
869
|
+
&& gifHeaderOffset !== undefined
|
|
921
870
|
)
|
|
922
871
|
|| (
|
|
923
872
|
Constants.USE_JXL
|
|
924
|
-
&&
|
|
873
|
+
&& jxlCodestreamOffset !== undefined
|
|
925
874
|
);
|
|
926
875
|
}
|
|
927
876
|
|
|
@@ -972,22 +921,6 @@ function getGpsGroupFromExifTags(exifTags) {
|
|
|
972
921
|
return gps;
|
|
973
922
|
}
|
|
974
923
|
|
|
975
|
-
function hasFileData(fileDataOffset) {
|
|
976
|
-
return fileDataOffset !== undefined;
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
function hasJfifData(jfifDataOffset) {
|
|
980
|
-
return jfifDataOffset !== undefined;
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
function hasExifData(tiffHeaderOffset) {
|
|
984
|
-
return tiffHeaderOffset !== undefined;
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
function hasIptcData(iptcDataOffset) {
|
|
988
|
-
return iptcDataOffset !== undefined;
|
|
989
|
-
}
|
|
990
|
-
|
|
991
924
|
function hasXmpData(xmpChunks) {
|
|
992
925
|
return Array.isArray(xmpChunks) && xmpChunks.length > 0;
|
|
993
926
|
}
|
|
@@ -1008,30 +941,6 @@ function hasPentaxType1Data(tags) {
|
|
|
1008
941
|
&& tags['MakerNote'].__offset;
|
|
1009
942
|
}
|
|
1010
943
|
|
|
1011
|
-
function hasMpfData(mpfDataOffset) {
|
|
1012
|
-
return mpfDataOffset !== undefined;
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
function hasPngFileData(pngFileDataOffset) {
|
|
1016
|
-
return pngFileDataOffset !== undefined;
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
944
|
function hasPngTextData(pngTextChunks) {
|
|
1020
945
|
return Array.isArray(pngTextChunks) && pngTextChunks.length > 0;
|
|
1021
946
|
}
|
|
1022
|
-
|
|
1023
|
-
function hasPngData(pngChunkOffsets) {
|
|
1024
|
-
return pngChunkOffsets !== undefined;
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
function hasVp8xData(vp8xChunkOffset) {
|
|
1028
|
-
return vp8xChunkOffset !== undefined;
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
function hasGifFileData(gifHeaderOffset) {
|
|
1032
|
-
return gifHeaderOffset !== undefined;
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
function hasJxlCodestreamData(jxlCodestreamOffset) {
|
|
1036
|
-
return jxlCodestreamOffset !== undefined;
|
|
1037
|
-
}
|
package/src/file-loaders.js
CHANGED
|
@@ -108,21 +108,7 @@ function totalSizeFromFetchResponse(response) {
|
|
|
108
108
|
if (!response || !response.headers || typeof response.headers.get !== 'function') {
|
|
109
109
|
return undefined;
|
|
110
110
|
}
|
|
111
|
-
|
|
112
|
-
if (contentRange) {
|
|
113
|
-
const match = /\/(\d+|\*)$/.exec(contentRange);
|
|
114
|
-
if (match && match[1] !== '*') {
|
|
115
|
-
return parseInt(match[1], 10);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
const contentLength = response.headers.get('Content-Length');
|
|
119
|
-
if (contentLength) {
|
|
120
|
-
const n = parseInt(contentLength, 10);
|
|
121
|
-
if (Number.isFinite(n)) {
|
|
122
|
-
return n;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return undefined;
|
|
111
|
+
return totalSizeFromRangeHeaders(response.headers.get('Content-Range'), response.headers.get('Content-Length'));
|
|
126
112
|
}
|
|
127
113
|
|
|
128
114
|
function isAcceptableFetchStatus(status) {
|
|
@@ -178,14 +164,16 @@ function totalSizeFromNodeResponse(response) {
|
|
|
178
164
|
if (!response || !response.headers) {
|
|
179
165
|
return undefined;
|
|
180
166
|
}
|
|
181
|
-
|
|
167
|
+
return totalSizeFromRangeHeaders(response.headers['content-range'], response.headers['content-length']);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function totalSizeFromRangeHeaders(contentRange, contentLength) {
|
|
182
171
|
if (contentRange) {
|
|
183
172
|
const match = /\/(\d+|\*)$/.exec(contentRange);
|
|
184
173
|
if (match && match[1] !== '*') {
|
|
185
174
|
return parseInt(match[1], 10);
|
|
186
175
|
}
|
|
187
176
|
}
|
|
188
|
-
const contentLength = response.headers['content-length'];
|
|
189
177
|
if (contentLength) {
|
|
190
178
|
const n = parseInt(contentLength, 10);
|
|
191
179
|
if (Number.isFinite(n)) {
|
package/src/gif-file-tags.js
CHANGED
|
@@ -11,106 +11,34 @@ export default {
|
|
|
11
11
|
read
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function getGifVersion(dataView) {
|
|
26
|
-
const OFFSET = 3;
|
|
27
|
-
const SIZE = 3;
|
|
28
|
-
|
|
29
|
-
if (OFFSET + SIZE > dataView.byteLength) {
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const value = getStringFromDataView(dataView, OFFSET, SIZE);
|
|
34
|
-
return {
|
|
35
|
-
value,
|
|
36
|
-
description: value
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function getImageWidth(dataView) {
|
|
41
|
-
const OFFSET = 6;
|
|
42
|
-
const SIZE = 2;
|
|
43
|
-
|
|
44
|
-
if (OFFSET + SIZE > dataView.byteLength) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const value = dataView.getUint16(OFFSET, true);
|
|
49
|
-
return {
|
|
50
|
-
value,
|
|
51
|
-
description: `${value}px`
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function getImageHeight(dataView) {
|
|
56
|
-
const OFFSET = 8;
|
|
57
|
-
const SIZE = 2;
|
|
58
|
-
|
|
59
|
-
if (OFFSET + SIZE > dataView.byteLength) {
|
|
60
|
-
return undefined;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const value = dataView.getUint16(OFFSET, true);
|
|
64
|
-
return {
|
|
65
|
-
value,
|
|
66
|
-
description: `${value}px`
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function getGlobalColorMap(dataView) {
|
|
71
|
-
const OFFSET = 10;
|
|
72
|
-
const SIZE = 1;
|
|
73
|
-
|
|
74
|
-
if (OFFSET + SIZE > dataView.byteLength) {
|
|
75
|
-
return undefined;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const byteValue = dataView.getUint8(OFFSET);
|
|
79
|
-
const value = (byteValue & 0b10000000) >>> 7;
|
|
80
|
-
return {
|
|
81
|
-
value,
|
|
82
|
-
description: value === 1 ? 'Yes' : 'No'
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function getColorResolution(dataView) {
|
|
87
|
-
const OFFSET = 10;
|
|
88
|
-
const SIZE = 1;
|
|
14
|
+
const bitsDescription = (value) => `${value} ${value === 1 ? 'bit' : 'bits'}`;
|
|
15
|
+
|
|
16
|
+
// The bit-field values in byte 10 are zero-based, hence the + 1.
|
|
17
|
+
const FIELDS = [
|
|
18
|
+
{name: 'GIF Version', offset: 3, size: 3, getValue: (dataView, offset) => getStringFromDataView(dataView, offset, 3), description: (value) => value},
|
|
19
|
+
{name: 'Image Width', offset: 6, size: 2, getValue: (dataView, offset) => dataView.getUint16(offset, true), description: (value) => `${value}px`},
|
|
20
|
+
{name: 'Image Height', offset: 8, size: 2, getValue: (dataView, offset) => dataView.getUint16(offset, true), description: (value) => `${value}px`},
|
|
21
|
+
{name: 'Global Color Map', offset: 10, size: 1, getValue: (dataView, offset) => (dataView.getUint8(offset) & 0b10000000) >>> 7, description: (value) => value === 1 ? 'Yes' : 'No'},
|
|
22
|
+
{name: 'Bits Per Pixel', offset: 10, size: 1, getValue: (dataView, offset) => (dataView.getUint8(offset) & 0b00000111) + 1, description: bitsDescription},
|
|
23
|
+
{name: 'Color Resolution Depth', offset: 10, size: 1, getValue: (dataView, offset) => ((dataView.getUint8(offset) & 0b01110000) >>> 4) + 1, description: bitsDescription}
|
|
24
|
+
];
|
|
89
25
|
|
|
90
|
-
|
|
91
|
-
|
|
26
|
+
function read(dataView) {
|
|
27
|
+
const tags = {};
|
|
28
|
+
for (let i = 0; i < FIELDS.length; i++) {
|
|
29
|
+
tags[FIELDS[i].name] = getFieldTag(dataView, FIELDS[i]);
|
|
92
30
|
}
|
|
93
|
-
|
|
94
|
-
const byteValue = dataView.getUint8(OFFSET);
|
|
95
|
-
const value = ((byteValue & 0b01110000) >>> 4) + 1; // Zero-based.
|
|
96
|
-
return {
|
|
97
|
-
value,
|
|
98
|
-
description: `${value} ${value === 1 ? 'bit' : 'bits'}`
|
|
99
|
-
};
|
|
31
|
+
return tags;
|
|
100
32
|
}
|
|
101
33
|
|
|
102
|
-
function
|
|
103
|
-
|
|
104
|
-
const SIZE = 1;
|
|
105
|
-
|
|
106
|
-
if (OFFSET + SIZE > dataView.byteLength) {
|
|
34
|
+
function getFieldTag(dataView, field) {
|
|
35
|
+
if (field.offset + field.size > dataView.byteLength) {
|
|
107
36
|
return undefined;
|
|
108
37
|
}
|
|
109
38
|
|
|
110
|
-
const
|
|
111
|
-
const value = (byteValue & 0b00000111) + 1; // Zero-based.
|
|
39
|
+
const value = field.getValue(dataView, field.offset);
|
|
112
40
|
return {
|
|
113
41
|
value,
|
|
114
|
-
description:
|
|
42
|
+
description: field.description(value)
|
|
115
43
|
};
|
|
116
44
|
}
|
package/src/icc-tag-names.js
CHANGED
|
@@ -119,7 +119,7 @@ function parseDate(dataView, offset) {
|
|
|
119
119
|
return new Date(Date.UTC(year, month, day, hours, minutes, seconds));
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
function sliceToString(slice) {
|
|
122
|
+
export function sliceToString(slice) {
|
|
123
123
|
return String.fromCharCode.apply(null, new Uint8Array(slice));
|
|
124
124
|
}
|
|
125
125
|
|
package/src/icc-tags.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
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
|
-
import {iccTags, iccProfile} from './icc-tag-names.js';
|
|
4
|
+
import {iccTags, iccProfile, sliceToString} from './icc-tag-names.js';
|
|
5
5
|
import {getStringFromDataView, getUnicodeStringFromDataView, decompress, COMPRESSION_METHOD_NONE, COMPRESSION_METHOD_DEFLATE} from './utils.js';
|
|
6
6
|
|
|
7
7
|
export default {
|
|
@@ -217,10 +217,6 @@ export function parseTags(dataView) {
|
|
|
217
217
|
return tags;
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
-
function sliceToString(slice) {
|
|
221
|
-
return String.fromCharCode.apply(null, new Uint8Array(slice));
|
|
222
|
-
}
|
|
223
|
-
|
|
224
220
|
function addTag(tags, tagSignature, value) {
|
|
225
221
|
if (iccTags[tagSignature]) {
|
|
226
222
|
tags[iccTags[tagSignature].name] = {value, description: value};
|
package/src/image-header-avif.js
CHANGED
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
// Specification:
|
|
6
6
|
// https://aomediacodec.github.io/av1-avif
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {hasMajorBrand, findOffsets} from './image-header-iso-bmff.js';
|
|
9
9
|
|
|
10
10
|
export default {
|
|
11
11
|
isAvifFile,
|
|
12
12
|
findAvifOffsets
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
const AVIF_MAJOR_BRANDS = ['avif'];
|
|
16
|
+
|
|
15
17
|
/**
|
|
16
18
|
* Checks if the provided data view represents an AVIF file.
|
|
17
19
|
*
|
|
@@ -19,16 +21,7 @@ export default {
|
|
|
19
21
|
* @returns {boolean} True if the data view represents an AVIF file, false otherwise.
|
|
20
22
|
*/
|
|
21
23
|
function isAvifFile(dataView) {
|
|
22
|
-
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
const headerBox = parseBox(dataView, 0);
|
|
28
|
-
return headerBox !== undefined && headerBox.majorBrand === 'avif';
|
|
29
|
-
} catch (error) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
24
|
+
return hasMajorBrand(dataView, AVIF_MAJOR_BRANDS);
|
|
32
25
|
}
|
|
33
26
|
|
|
34
27
|
/**
|
package/src/image-header-gif.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 {getStringFromDataView} from './utils.js';
|
|
5
|
+
import {getStringFromDataView, pushMetadataBlock} from './utils.js';
|
|
6
6
|
|
|
7
7
|
export default {
|
|
8
8
|
isGifFile,
|
|
@@ -34,9 +34,7 @@ function isGifFile(dataView) {
|
|
|
34
34
|
* @returns {{gifHeaderOffset: number}}
|
|
35
35
|
*/
|
|
36
36
|
function findOffsets(_dataView, metadataBlocks) {
|
|
37
|
-
|
|
38
|
-
metadataBlocks.push({type: 'gif', start: 0, end: GIF_HEADER_SIZE});
|
|
39
|
-
}
|
|
37
|
+
pushMetadataBlock(metadataBlocks, 'gif', 0, GIF_HEADER_SIZE);
|
|
40
38
|
return {
|
|
41
39
|
gifHeaderOffset: 0
|
|
42
40
|
};
|
package/src/image-header-heic.js
CHANGED
|
@@ -2,13 +2,15 @@
|
|
|
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 {hasMajorBrand, findOffsets} from './image-header-iso-bmff.js';
|
|
6
6
|
|
|
7
7
|
export default {
|
|
8
8
|
isHeicFile,
|
|
9
9
|
findHeicOffsets
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
+
const HEIC_MAJOR_BRANDS = ['heic', 'heix', 'hevc', 'hevx', 'heim', 'heis', 'hevm', 'hevs', 'mif1'];
|
|
13
|
+
|
|
12
14
|
/**
|
|
13
15
|
* Checks if the provided data view represents a HEIC/HEIF file.
|
|
14
16
|
*
|
|
@@ -16,18 +18,7 @@ export default {
|
|
|
16
18
|
* @returns {boolean} True if the data view represents a HEIC/HEIF file, false otherwise.
|
|
17
19
|
*/
|
|
18
20
|
function isHeicFile(dataView) {
|
|
19
|
-
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const HEIC_MAJOR_BRANDS = ['heic', 'heix', 'hevc', 'hevx', 'heim', 'heis', 'hevm', 'hevs', 'mif1'];
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
const headerBox = parseBox(dataView, 0);
|
|
27
|
-
return headerBox !== undefined && HEIC_MAJOR_BRANDS.indexOf(headerBox.majorBrand) !== -1;
|
|
28
|
-
} catch (error) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
21
|
+
return hasMajorBrand(dataView, HEIC_MAJOR_BRANDS);
|
|
31
22
|
}
|
|
32
23
|
|
|
33
24
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {get64BitValue} from './image-header-iso-bmff-utils.js';
|
|
1
|
+
import {get64BitValue, hasBytes} from './image-header-iso-bmff-utils.js';
|
|
2
2
|
|
|
3
3
|
// Absolute backstop on the number of extent objects a single iloc box may
|
|
4
4
|
// allocate, guarding against memory exhaustion from a crafted file
|
|
@@ -89,10 +89,15 @@ function getItems(dataView, version, offsets, sizes, offsetSize, lengthSize, ind
|
|
|
89
89
|
const items = [];
|
|
90
90
|
let offset = offsets.items;
|
|
91
91
|
const extentByteSize = sizes.item.extent.extentIndex + sizes.item.extent.extentOffset + sizes.item.extent.extentLength;
|
|
92
|
+
const itemHeaderByteSize = sizes.item.itemId
|
|
93
|
+
+ sizes.item.constructionMethod
|
|
94
|
+
+ sizes.item.dataReferenceIndex
|
|
95
|
+
+ sizes.item.baseOffset
|
|
96
|
+
+ sizes.item.extentCount;
|
|
92
97
|
let totalExtents = 0;
|
|
93
98
|
|
|
94
99
|
for (let i = 0; i < itemCount; i++) {
|
|
95
|
-
if (offset
|
|
100
|
+
if (!hasBytes(dataView, offset, itemHeaderByteSize)) {
|
|
96
101
|
break;
|
|
97
102
|
}
|
|
98
103
|
const item = {extents: []};
|