@loaders.gl/textures 4.2.0-alpha.4 → 4.2.0-alpha.6
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/basis-loader.js +27 -19
- package/dist/basis-worker-node.js +183 -127
- package/dist/basis-worker.js +5 -3
- package/dist/compressed-texture-loader.js +51 -31
- package/dist/compressed-texture-worker.js +5 -3
- package/dist/compressed-texture-writer.js +32 -19
- package/dist/crunch-loader.js +19 -13
- package/dist/crunch-worker.js +5 -3
- package/dist/dist.dev.js +326 -212
- package/dist/dist.min.js +10 -0
- package/dist/index.cjs +41 -60
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +16 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -13
- package/dist/ktx2-basis-writer-worker-node.js +183 -127
- package/dist/ktx2-basis-writer-worker.js +5 -3
- package/dist/ktx2-basis-writer.js +21 -15
- package/dist/lib/encoders/encode-ktx.js +6 -3
- package/dist/lib/encoders/encode-ktx2-basis-texture.js +38 -33
- package/dist/lib/encoders/encode-texture.d.ts +1 -1
- package/dist/lib/encoders/encode-texture.d.ts.map +1 -1
- package/dist/lib/encoders/encode-texture.js +23 -9
- package/dist/lib/gl-extensions.js +70 -59
- package/dist/lib/parsers/basis-module-loader.js +97 -61
- package/dist/lib/parsers/crunch-module-loader.js +29 -13
- package/dist/lib/parsers/parse-basis.js +217 -205
- package/dist/lib/parsers/parse-compressed-texture.js +20 -11
- package/dist/lib/parsers/parse-crunch.js +89 -59
- package/dist/lib/parsers/parse-dds.js +82 -53
- package/dist/lib/parsers/parse-ktx.js +37 -18
- package/dist/lib/parsers/parse-npy.js +70 -53
- package/dist/lib/parsers/parse-pvr.js +203 -112
- package/dist/lib/texture-api/async-deep-map.js +33 -28
- package/dist/lib/texture-api/deep-load.js +7 -5
- package/dist/lib/texture-api/generate-url.d.ts +1 -1
- package/dist/lib/texture-api/generate-url.d.ts.map +1 -1
- package/dist/lib/texture-api/generate-url.js +12 -10
- package/dist/lib/texture-api/load-image-array.d.ts +1 -1
- package/dist/lib/texture-api/load-image-array.d.ts.map +1 -1
- package/dist/lib/texture-api/load-image-array.js +13 -15
- package/dist/lib/texture-api/load-image-cube.d.ts +1 -1
- package/dist/lib/texture-api/load-image-cube.d.ts.map +1 -1
- package/dist/lib/texture-api/load-image-cube.js +32 -51
- package/dist/lib/texture-api/load-image.d.ts +1 -1
- package/dist/lib/texture-api/load-image.d.ts.map +1 -1
- package/dist/lib/texture-api/load-image.js +30 -36
- package/dist/lib/texture-api/texture-api-types.js +3 -1
- package/dist/lib/utils/extract-mipmap-images.js +43 -29
- package/dist/lib/utils/ktx-format-helper.js +119 -68
- package/dist/lib/utils/texture-formats.js +40 -26
- package/dist/lib/utils/version.js +7 -2
- package/dist/npy-loader.d.ts +1 -1
- package/dist/npy-loader.d.ts.map +1 -1
- package/dist/npy-loader.js +24 -15
- package/dist/npy-worker.js +4 -2
- package/dist/workers/basis-worker-node.js +4 -1
- package/dist/workers/basis-worker.js +3 -1
- package/dist/workers/compressed-texture-worker.js +4 -1
- package/dist/workers/crunch-worker.d.ts +1 -1
- package/dist/workers/crunch-worker.d.ts.map +1 -1
- package/dist/workers/crunch-worker.js +8 -3
- package/dist/workers/ktx2-basis-writer-worker-node.js +23 -26
- package/dist/workers/ktx2-basis-writer-worker.js +22 -26
- package/dist/workers/npy-worker.js +3 -1
- package/package.json +12 -10
- package/dist/basis-loader.js.map +0 -1
- package/dist/compressed-texture-loader.js.map +0 -1
- package/dist/compressed-texture-writer.js.map +0 -1
- package/dist/crunch-loader.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/ktx2-basis-writer.js.map +0 -1
- package/dist/lib/encoders/encode-ktx.js.map +0 -1
- package/dist/lib/encoders/encode-ktx2-basis-texture.js.map +0 -1
- package/dist/lib/encoders/encode-texture.js.map +0 -1
- package/dist/lib/gl-extensions.js.map +0 -1
- package/dist/lib/parsers/basis-module-loader.js.map +0 -1
- package/dist/lib/parsers/crunch-module-loader.js.map +0 -1
- package/dist/lib/parsers/parse-basis.js.map +0 -1
- package/dist/lib/parsers/parse-compressed-texture.js.map +0 -1
- package/dist/lib/parsers/parse-crunch.js.map +0 -1
- package/dist/lib/parsers/parse-dds.js.map +0 -1
- package/dist/lib/parsers/parse-ktx.js.map +0 -1
- package/dist/lib/parsers/parse-npy.js.map +0 -1
- package/dist/lib/parsers/parse-pvr.js.map +0 -1
- package/dist/lib/texture-api/async-deep-map.js.map +0 -1
- package/dist/lib/texture-api/deep-load.js.map +0 -1
- package/dist/lib/texture-api/generate-url.js.map +0 -1
- package/dist/lib/texture-api/load-image-array.js.map +0 -1
- package/dist/lib/texture-api/load-image-cube.js.map +0 -1
- package/dist/lib/texture-api/load-image.js.map +0 -1
- package/dist/lib/texture-api/texture-api-types.js.map +0 -1
- package/dist/lib/utils/extract-mipmap-images.js.map +0 -1
- package/dist/lib/utils/ktx-format-helper.js.map +0 -1
- package/dist/lib/utils/texture-formats.js.map +0 -1
- package/dist/lib/utils/version.js.map +0 -1
- package/dist/libs/libs/README.md +0 -9
- package/dist/libs/libs/basis_encoder.js +0 -21
- package/dist/libs/libs/basis_encoder.wasm +0 -0
- package/dist/libs/libs/basis_transcoder.js +0 -22
- package/dist/libs/libs/basis_transcoder.wasm +0 -0
- package/dist/libs/libs/crunch.js +0 -136
- package/dist/npy-loader.js.map +0 -1
- package/dist/workers/basis-worker-node.js.map +0 -1
- package/dist/workers/basis-worker.js.map +0 -1
- package/dist/workers/compressed-texture-worker.js.map +0 -1
- package/dist/workers/crunch-worker.js.map +0 -1
- package/dist/workers/ktx2-basis-writer-worker-node.js.map +0 -1
- package/dist/workers/ktx2-basis-writer-worker.js.map +0 -1
- package/dist/workers/npy-worker.js.map +0 -1
|
@@ -1,75 +1,104 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { assert } from '@loaders.gl/loader-utils';
|
|
2
5
|
import { GL_EXTENSIONS_CONSTANTS } from "../gl-extensions.js";
|
|
3
6
|
import { extractMipmapImages } from "../utils/extract-mipmap-images.js";
|
|
4
7
|
const DDS_CONSTANTS = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
MAGIC_NUMBER: 0x20534444,
|
|
9
|
+
HEADER_LENGTH: 31,
|
|
10
|
+
MAGIC_NUMBER_INDEX: 0,
|
|
11
|
+
HEADER_SIZE_INDEX: 1,
|
|
12
|
+
HEADER_FLAGS_INDEX: 2,
|
|
13
|
+
HEADER_HEIGHT_INDEX: 3,
|
|
14
|
+
HEADER_WIDTH_INDEX: 4,
|
|
15
|
+
MIPMAPCOUNT_INDEX: 7,
|
|
16
|
+
HEADER_PF_FLAGS_INDEX: 20,
|
|
17
|
+
HEADER_PF_FOURCC_INDEX: 21,
|
|
18
|
+
DDSD_MIPMAPCOUNT: 0x20000,
|
|
19
|
+
DDPF_FOURCC: 0x4
|
|
17
20
|
};
|
|
18
21
|
const DDS_PIXEL_FORMATS = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
DXT1: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT,
|
|
23
|
+
DXT3: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT,
|
|
24
|
+
DXT5: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
|
|
25
|
+
'ATC ': GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ATC_WEBGL,
|
|
26
|
+
ATCA: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL,
|
|
27
|
+
ATCI: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL
|
|
25
28
|
};
|
|
26
29
|
const getATCLevelSize = getDxt1LevelSize;
|
|
27
30
|
const getATCALevelSize = getDxtXLevelSize;
|
|
28
31
|
const getATCILevelSize = getDxtXLevelSize;
|
|
29
32
|
const DDS_SIZE_FUNCTIONS = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
DXT1: getDxt1LevelSize,
|
|
34
|
+
DXT3: getDxtXLevelSize,
|
|
35
|
+
DXT5: getDxtXLevelSize,
|
|
36
|
+
'ATC ': getATCLevelSize,
|
|
37
|
+
ATCA: getATCALevelSize,
|
|
38
|
+
ATCI: getATCILevelSize
|
|
36
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Check if data is in "DDS" format by its magic number
|
|
42
|
+
* @param data - binary data of compressed texture
|
|
43
|
+
* @returns true - data in "DDS" format, else - false
|
|
44
|
+
*/
|
|
37
45
|
export function isDDS(data) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
const header = new Uint32Array(data, 0, DDS_CONSTANTS.HEADER_LENGTH);
|
|
47
|
+
const magic = header[DDS_CONSTANTS.MAGIC_NUMBER_INDEX];
|
|
48
|
+
return magic === DDS_CONSTANTS.MAGIC_NUMBER;
|
|
41
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Parse texture data as "DDS" format
|
|
52
|
+
* @param data - binary data of compressed texture
|
|
53
|
+
* @returns Array of the texture levels
|
|
54
|
+
*/
|
|
42
55
|
export function parseDDS(data) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
const header = new Int32Array(data, 0, DDS_CONSTANTS.HEADER_LENGTH);
|
|
57
|
+
const pixelFormatNumber = header[DDS_CONSTANTS.HEADER_PF_FOURCC_INDEX];
|
|
58
|
+
assert(Boolean(header[DDS_CONSTANTS.HEADER_PF_FLAGS_INDEX] & DDS_CONSTANTS.DDPF_FOURCC), 'DDS: Unsupported format, must contain a FourCC code');
|
|
59
|
+
const fourCC = int32ToFourCC(pixelFormatNumber);
|
|
60
|
+
const internalFormat = DDS_PIXEL_FORMATS[fourCC];
|
|
61
|
+
const sizeFunction = DDS_SIZE_FUNCTIONS[fourCC];
|
|
62
|
+
assert(internalFormat && sizeFunction, `DDS: Unknown pixel format ${pixelFormatNumber}`);
|
|
63
|
+
let mipMapLevels = 1;
|
|
64
|
+
if (header[DDS_CONSTANTS.HEADER_FLAGS_INDEX] & DDS_CONSTANTS.DDSD_MIPMAPCOUNT) {
|
|
65
|
+
mipMapLevels = Math.max(1, header[DDS_CONSTANTS.MIPMAPCOUNT_INDEX]);
|
|
66
|
+
}
|
|
67
|
+
const width = header[DDS_CONSTANTS.HEADER_WIDTH_INDEX];
|
|
68
|
+
const height = header[DDS_CONSTANTS.HEADER_HEIGHT_INDEX];
|
|
69
|
+
const dataOffset = header[DDS_CONSTANTS.HEADER_SIZE_INDEX] + 4;
|
|
70
|
+
const image = new Uint8Array(data, dataOffset);
|
|
71
|
+
return extractMipmapImages(image, {
|
|
72
|
+
mipMapLevels,
|
|
73
|
+
width,
|
|
74
|
+
height,
|
|
75
|
+
sizeFunction,
|
|
76
|
+
internalFormat
|
|
77
|
+
});
|
|
65
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* DXT1 applicable function to calculate level size
|
|
81
|
+
* @param width - level width
|
|
82
|
+
* @param height - level height
|
|
83
|
+
* @returns level size in bytes
|
|
84
|
+
*/
|
|
66
85
|
export function getDxt1LevelSize(width, height) {
|
|
67
|
-
|
|
86
|
+
return ((width + 3) >> 2) * ((height + 3) >> 2) * 8;
|
|
68
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* DXT3 & DXT5 applicable function to calculate level size
|
|
90
|
+
* @param width - level width
|
|
91
|
+
* @param height - level height
|
|
92
|
+
* @returns level size in bytes
|
|
93
|
+
*/
|
|
69
94
|
export function getDxtXLevelSize(width, height) {
|
|
70
|
-
|
|
95
|
+
return ((width + 3) >> 2) * ((height + 3) >> 2) * 16;
|
|
71
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Convert every byte of Int32 value to char
|
|
99
|
+
* @param value - Int32 number
|
|
100
|
+
* @returns string of 4 characters
|
|
101
|
+
*/
|
|
72
102
|
function int32ToFourCC(value) {
|
|
73
|
-
|
|
103
|
+
return String.fromCharCode(value & 0xff, (value >> 8) & 0xff, (value >> 16) & 0xff, (value >> 24) & 0xff);
|
|
74
104
|
}
|
|
75
|
-
//# sourceMappingURL=parse-dds.js.map
|
|
@@ -1,25 +1,44 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { read } from 'ktx-parse';
|
|
2
5
|
import { extractMipmapImages } from "../utils/extract-mipmap-images.js";
|
|
3
6
|
import { mapVkFormatToWebGL } from "../utils/ktx-format-helper.js";
|
|
4
|
-
const KTX2_ID = [
|
|
7
|
+
const KTX2_ID = [
|
|
8
|
+
// '´', 'K', 'T', 'X', '2', '0', 'ª', '\r', '\n', '\x1A', '\n'
|
|
9
|
+
0xab, 0x4b, 0x54, 0x58, 0x20, 0x32, 0x30, 0xbb, 0x0d, 0x0a, 0x1a, 0x0a
|
|
10
|
+
];
|
|
11
|
+
// eslint-disable-next-line complexity
|
|
5
12
|
export function isKTX(data) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
// const id = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
14
|
+
const id = new Uint8Array(data);
|
|
15
|
+
const notKTX = id.byteLength < KTX2_ID.length ||
|
|
16
|
+
id[0] !== KTX2_ID[0] || // '´'
|
|
17
|
+
id[1] !== KTX2_ID[1] || // 'K'
|
|
18
|
+
id[2] !== KTX2_ID[2] || // 'T'
|
|
19
|
+
id[3] !== KTX2_ID[3] || // 'X'
|
|
20
|
+
id[4] !== KTX2_ID[4] || // ' '
|
|
21
|
+
id[5] !== KTX2_ID[5] || // '2'
|
|
22
|
+
id[6] !== KTX2_ID[6] || // '0'
|
|
23
|
+
id[7] !== KTX2_ID[7] || // 'ª'
|
|
24
|
+
id[8] !== KTX2_ID[8] || // '\r'
|
|
25
|
+
id[9] !== KTX2_ID[9] || // '\n'
|
|
26
|
+
id[10] !== KTX2_ID[10] || // '\x1A'
|
|
27
|
+
id[11] !== KTX2_ID[11]; // '\n'
|
|
28
|
+
return !notKTX;
|
|
9
29
|
}
|
|
10
30
|
export function parseKTX(arrayBuffer) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
|
32
|
+
const ktx = read(uint8Array);
|
|
33
|
+
const mipMapLevels = Math.max(1, ktx.levels.length);
|
|
34
|
+
const width = ktx.pixelWidth;
|
|
35
|
+
const height = ktx.pixelHeight;
|
|
36
|
+
const internalFormat = mapVkFormatToWebGL(ktx.vkFormat);
|
|
37
|
+
return extractMipmapImages(ktx.levels, {
|
|
38
|
+
mipMapLevels,
|
|
39
|
+
width,
|
|
40
|
+
height,
|
|
41
|
+
sizeFunction: (level) => level.uncompressedByteLength,
|
|
42
|
+
internalFormat
|
|
43
|
+
});
|
|
24
44
|
}
|
|
25
|
-
//# sourceMappingURL=parse-ktx.js.map
|
|
@@ -1,63 +1,80 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
const a = new Uint32Array([0x12345678]);
|
|
2
5
|
const b = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
|
|
3
6
|
const isLittleEndian = !(b[0] === 0x12);
|
|
4
7
|
const LITTLE_ENDIAN_OS = isLittleEndian;
|
|
8
|
+
/**
|
|
9
|
+
* The basic string format consists of 3 characters:
|
|
10
|
+
* 1. a character describing the byteorder of the data (<: little-endian, >: big-endian, |: not-relevant)
|
|
11
|
+
* 2. a character code giving the basic type of the array
|
|
12
|
+
* 3. an integer providing the number of bytes the type uses.
|
|
13
|
+
* https://numpy.org/doc/stable/reference/arrays.interface.html
|
|
14
|
+
*
|
|
15
|
+
* Here I only include the second and third characters, and check endianness separately
|
|
16
|
+
*/
|
|
5
17
|
const DTYPES = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
u1: Uint8Array,
|
|
19
|
+
i1: Int8Array,
|
|
20
|
+
u2: Uint16Array,
|
|
21
|
+
i2: Int16Array,
|
|
22
|
+
u4: Uint32Array,
|
|
23
|
+
i4: Int32Array,
|
|
24
|
+
f4: Float32Array,
|
|
25
|
+
f8: Float64Array
|
|
14
26
|
};
|
|
15
27
|
export function parseNPY(arrayBuffer, options) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
data,
|
|
38
|
-
header
|
|
39
|
-
};
|
|
28
|
+
const view = new DataView(arrayBuffer);
|
|
29
|
+
const { header, headerEndOffset } = parseHeader(view);
|
|
30
|
+
const numpyType = header.descr;
|
|
31
|
+
const ArrayType = DTYPES[numpyType.slice(1, 3)];
|
|
32
|
+
if (!ArrayType) {
|
|
33
|
+
throw new Error(`Unimplemented type ${numpyType}`);
|
|
34
|
+
}
|
|
35
|
+
const nArrayElements = header.shape?.reduce((a, b) => a * b);
|
|
36
|
+
const arrayByteLength = nArrayElements * ArrayType.BYTES_PER_ELEMENT;
|
|
37
|
+
if (arrayBuffer.byteLength < headerEndOffset + arrayByteLength) {
|
|
38
|
+
throw new Error('Buffer overflow');
|
|
39
|
+
}
|
|
40
|
+
const data = new ArrayType(arrayBuffer.slice(headerEndOffset, headerEndOffset + arrayByteLength));
|
|
41
|
+
// Swap endianness if needed
|
|
42
|
+
if ((numpyType[0] === '>' && LITTLE_ENDIAN_OS) || (numpyType[0] === '<' && !LITTLE_ENDIAN_OS)) {
|
|
43
|
+
throw new Error('Incorrect endianness');
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
data,
|
|
47
|
+
header
|
|
48
|
+
};
|
|
40
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Parse NPY header
|
|
52
|
+
*
|
|
53
|
+
* @param view
|
|
54
|
+
* @return
|
|
55
|
+
*/
|
|
41
56
|
function parseHeader(view) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
header
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
const majorVersion = view.getUint8(6);
|
|
58
|
+
// const minorVersion = view.getUint8(7);
|
|
59
|
+
let offset = 8;
|
|
60
|
+
let headerLength;
|
|
61
|
+
if (majorVersion >= 2) {
|
|
62
|
+
headerLength = view.getUint32(offset, true);
|
|
63
|
+
offset += 4;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
headerLength = view.getUint16(offset, true);
|
|
67
|
+
offset += 2;
|
|
68
|
+
}
|
|
69
|
+
const encoding = majorVersion <= 2 ? 'latin1' : 'utf-8';
|
|
70
|
+
const decoder = new TextDecoder(encoding);
|
|
71
|
+
const headerArray = new Uint8Array(view.buffer, offset, headerLength);
|
|
72
|
+
const headerText = decoder.decode(headerArray);
|
|
73
|
+
offset += headerLength;
|
|
74
|
+
const header = JSON.parse(headerText
|
|
75
|
+
.replace(/'/g, '"')
|
|
76
|
+
.replace('False', 'false')
|
|
77
|
+
.replace('(', '[')
|
|
78
|
+
.replace(/,*\),*/g, ']'));
|
|
79
|
+
return { header, headerEndOffset: offset };
|
|
62
80
|
}
|
|
63
|
-
//# sourceMappingURL=parse-npy.js.map
|