@loaders.gl/textures 4.0.0-alpha.23 → 4.0.0-alpha.24

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.
Files changed (56) hide show
  1. package/dist/basis-worker-node.js +2 -2
  2. package/dist/basis-worker.js +2 -2
  3. package/dist/compressed-texture-worker.js +2 -2
  4. package/dist/crunch-loader.d.ts +9 -2
  5. package/dist/crunch-loader.d.ts.map +1 -1
  6. package/dist/crunch-worker.js +2 -2
  7. package/dist/es5/crunch-loader.js.map +1 -1
  8. package/dist/es5/lib/utils/version.js +1 -1
  9. package/dist/esm/crunch-loader.js.map +1 -1
  10. package/dist/esm/lib/utils/version.js +1 -1
  11. package/dist/ktx2-basis-writer-worker-node.js +2 -2
  12. package/dist/ktx2-basis-writer-worker.js +2 -2
  13. package/dist/npy-worker.js +1 -1
  14. package/dist/workers/crunch-worker.d.ts +3 -3
  15. package/package.json +7 -7
  16. package/src/crunch-loader.ts +10 -4
  17. package/dist/basis-loader.js +0 -37
  18. package/dist/bundle.js +0 -5
  19. package/dist/compressed-texture-loader.js +0 -63
  20. package/dist/compressed-texture-writer.js +0 -34
  21. package/dist/crunch-loader.js +0 -23
  22. package/dist/index.js +0 -57
  23. package/dist/ktx2-basis-writer.js +0 -28
  24. package/dist/lib/encoders/encode-ktx.js +0 -10
  25. package/dist/lib/encoders/encode-ktx2-basis-texture.js +0 -41
  26. package/dist/lib/encoders/encode-texture.js +0 -27
  27. package/dist/lib/gl-extensions.js +0 -72
  28. package/dist/lib/parsers/basis-module-loader.js +0 -118
  29. package/dist/lib/parsers/crunch-module-loader.js +0 -39
  30. package/dist/lib/parsers/parse-basis.js +0 -245
  31. package/dist/lib/parsers/parse-compressed-texture.js +0 -26
  32. package/dist/lib/parsers/parse-crunch.js +0 -106
  33. package/dist/lib/parsers/parse-dds.js +0 -108
  34. package/dist/lib/parsers/parse-ktx.js +0 -46
  35. package/dist/lib/parsers/parse-npy.js +0 -81
  36. package/dist/lib/parsers/parse-pvr.js +0 -250
  37. package/dist/lib/texture-api/async-deep-map.js +0 -41
  38. package/dist/lib/texture-api/deep-load.js +0 -15
  39. package/dist/lib/texture-api/generate-url.js +0 -17
  40. package/dist/lib/texture-api/load-image-array.js +0 -21
  41. package/dist/lib/texture-api/load-image-cube.js +0 -47
  42. package/dist/lib/texture-api/load-image.js +0 -43
  43. package/dist/lib/texture-api/texture-api-types.js +0 -3
  44. package/dist/lib/utils/extract-mipmap-images.js +0 -50
  45. package/dist/lib/utils/ktx-format-helper.js +0 -125
  46. package/dist/lib/utils/texture-formats.js +0 -51
  47. package/dist/lib/utils/version.js +0 -8
  48. package/dist/npy-loader.js +0 -31
  49. package/dist/types.js +0 -1
  50. package/dist/workers/basis-worker-node.js +0 -7
  51. package/dist/workers/basis-worker.js +0 -5
  52. package/dist/workers/compressed-texture-worker.js +0 -6
  53. package/dist/workers/crunch-worker.js +0 -14
  54. package/dist/workers/ktx2-basis-writer-worker-node.js +0 -28
  55. package/dist/workers/ktx2-basis-writer-worker.js +0 -26
  56. package/dist/workers/npy-worker.js +0 -5
@@ -1,72 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GL_EXTENSIONS_CONSTANTS = void 0;
4
- /* eslint-disable camelcase */
5
- exports.GL_EXTENSIONS_CONSTANTS = {
6
- // WEBGL_compressed_texture_s3tc
7
- COMPRESSED_RGB_S3TC_DXT1_EXT: 0x83f0,
8
- COMPRESSED_RGBA_S3TC_DXT1_EXT: 0x83f1,
9
- COMPRESSED_RGBA_S3TC_DXT3_EXT: 0x83f2,
10
- COMPRESSED_RGBA_S3TC_DXT5_EXT: 0x83f3,
11
- // WEBGL_compressed_texture_es3
12
- COMPRESSED_R11_EAC: 0x9270,
13
- COMPRESSED_SIGNED_R11_EAC: 0x9271,
14
- COMPRESSED_RG11_EAC: 0x9272,
15
- COMPRESSED_SIGNED_RG11_EAC: 0x9273,
16
- COMPRESSED_RGB8_ETC2: 0x9274,
17
- COMPRESSED_RGBA8_ETC2_EAC: 0x9275,
18
- COMPRESSED_SRGB8_ETC2: 0x9276,
19
- COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: 0x9277,
20
- COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: 0x9278,
21
- COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: 0x9279,
22
- // WEBGL_compressed_texture_pvrtc
23
- COMPRESSED_RGB_PVRTC_4BPPV1_IMG: 0x8c00,
24
- COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: 0x8c02,
25
- COMPRESSED_RGB_PVRTC_2BPPV1_IMG: 0x8c01,
26
- COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: 0x8c03,
27
- // WEBGL_compressed_texture_etc1
28
- COMPRESSED_RGB_ETC1_WEBGL: 0x8d64,
29
- // WEBGL_compressed_texture_atc
30
- COMPRESSED_RGB_ATC_WEBGL: 0x8c92,
31
- COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL: 0x8c93,
32
- COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL: 0x87ee,
33
- // WEBGL_compressed_texture_astc
34
- COMPRESSED_RGBA_ASTC_4X4_KHR: 0x93b0,
35
- COMPRESSED_RGBA_ASTC_5X4_KHR: 0x93b1,
36
- COMPRESSED_RGBA_ASTC_5X5_KHR: 0x93b2,
37
- COMPRESSED_RGBA_ASTC_6X5_KHR: 0x93b3,
38
- COMPRESSED_RGBA_ASTC_6X6_KHR: 0x93b4,
39
- COMPRESSED_RGBA_ASTC_8X5_KHR: 0x93b5,
40
- COMPRESSED_RGBA_ASTC_8X6_KHR: 0x93b6,
41
- COMPRESSED_RGBA_ASTC_8X8_KHR: 0x93b7,
42
- COMPRESSED_RGBA_ASTC_10X5_KHR: 0x93b8,
43
- COMPRESSED_RGBA_ASTC_10X6_KHR: 0x93b9,
44
- COMPRESSED_RGBA_ASTC_10X8_KHR: 0x93ba,
45
- COMPRESSED_RGBA_ASTC_10X10_KHR: 0x93bb,
46
- COMPRESSED_RGBA_ASTC_12X10_KHR: 0x93bc,
47
- COMPRESSED_RGBA_ASTC_12X12_KHR: 0x93bd,
48
- COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR: 0x93d0,
49
- COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR: 0x93d1,
50
- COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR: 0x93d2,
51
- COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR: 0x93d3,
52
- COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR: 0x93d4,
53
- COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR: 0x93d5,
54
- COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR: 0x93d6,
55
- COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR: 0x93d7,
56
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR: 0x93d8,
57
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR: 0x93d9,
58
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR: 0x93da,
59
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR: 0x93db,
60
- COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR: 0x93dc,
61
- COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR: 0x93dd,
62
- // EXT_texture_compression_rgtc
63
- COMPRESSED_RED_RGTC1_EXT: 0x8dbb,
64
- COMPRESSED_SIGNED_RED_RGTC1_EXT: 0x8dbc,
65
- COMPRESSED_RED_GREEN_RGTC2_EXT: 0x8dbd,
66
- COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT: 0x8dbe,
67
- // WEBGL_compressed_texture_s3tc_srgb
68
- COMPRESSED_SRGB_S3TC_DXT1_EXT: 0x8c4c,
69
- COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 0x8c4d,
70
- COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 0x8c4e,
71
- COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 0x8c4f
72
- };
@@ -1,118 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadBasisEncoderModule = exports.loadBasisTranscoderModule = exports.BASIS_EXTERNAL_LIBRARIES = void 0;
4
- const worker_utils_1 = require("@loaders.gl/worker-utils");
5
- exports.BASIS_EXTERNAL_LIBRARIES = {
6
- /** Basis transcoder, javascript wrapper part */
7
- TRANSCODER: 'basis_transcoder.js',
8
- /** Basis transcoder, compiled web assembly part */
9
- TRANSCODER_WASM: 'basis_transcoder.wasm',
10
- /** Basis encoder, javascript wrapper part */
11
- ENCODER: 'basis_encoder.js',
12
- /** Basis encoder, compiled web assembly part */
13
- ENCODER_WASM: 'basis_encoder.wasm'
14
- };
15
- let loadBasisTranscoderPromise;
16
- /**
17
- * Loads wasm transcoder module
18
- * @param options
19
- * @returns {BasisFile} promise
20
- */
21
- async function loadBasisTranscoderModule(options) {
22
- const modules = options.modules || {};
23
- if (modules.basis) {
24
- return modules.basis;
25
- }
26
- loadBasisTranscoderPromise = loadBasisTranscoderPromise || loadBasisTranscoder(options);
27
- return await loadBasisTranscoderPromise;
28
- }
29
- exports.loadBasisTranscoderModule = loadBasisTranscoderModule;
30
- /**
31
- * Loads wasm transcoder module
32
- * @param options
33
- * @returns {BasisFile} promise
34
- */
35
- async function loadBasisTranscoder(options) {
36
- let BASIS = null;
37
- let wasmBinary = null;
38
- [BASIS, wasmBinary] = await Promise.all([
39
- await (0, worker_utils_1.loadLibrary)(exports.BASIS_EXTERNAL_LIBRARIES.TRANSCODER, 'textures', options),
40
- await (0, worker_utils_1.loadLibrary)(exports.BASIS_EXTERNAL_LIBRARIES.TRANSCODER_WASM, 'textures', options)
41
- ]);
42
- // Depends on how import happened...
43
- // @ts-ignore TS2339: Property does not exist on type
44
- BASIS = BASIS || globalThis.BASIS;
45
- return await initializeBasisTranscoderModule(BASIS, wasmBinary);
46
- }
47
- /**
48
- * Initialize wasm transcoder module
49
- * @param BasisModule - js part of the module
50
- * @param wasmBinary - wasm part of the module
51
- * @returns {BasisFile} promise
52
- */
53
- function initializeBasisTranscoderModule(BasisModule, wasmBinary) {
54
- const options = {};
55
- if (wasmBinary) {
56
- options.wasmBinary = wasmBinary;
57
- }
58
- return new Promise((resolve) => {
59
- // if you try to return BasisModule the browser crashes!
60
- BasisModule(options).then((module) => {
61
- const { BasisFile, initializeBasis } = module;
62
- initializeBasis();
63
- resolve({ BasisFile });
64
- });
65
- });
66
- }
67
- let loadBasisEncoderPromise;
68
- /**
69
- * Loads wasm encoder module
70
- * @param options
71
- * @returns {BasisFile, KTX2File} promise
72
- */
73
- async function loadBasisEncoderModule(options) {
74
- const modules = options.modules || {};
75
- if (modules.basisEncoder) {
76
- return modules.basisEncoder;
77
- }
78
- loadBasisEncoderPromise = loadBasisEncoderPromise || loadBasisEncoder(options);
79
- return await loadBasisEncoderPromise;
80
- }
81
- exports.loadBasisEncoderModule = loadBasisEncoderModule;
82
- /**
83
- * Loads wasm encoder module
84
- * @param options
85
- * @returns {BasisFile, KTX2File} promise
86
- */
87
- async function loadBasisEncoder(options) {
88
- let BASIS_ENCODER = null;
89
- let wasmBinary = null;
90
- [BASIS_ENCODER, wasmBinary] = await Promise.all([
91
- await (0, worker_utils_1.loadLibrary)(exports.BASIS_EXTERNAL_LIBRARIES.ENCODER, 'textures', options),
92
- await (0, worker_utils_1.loadLibrary)(exports.BASIS_EXTERNAL_LIBRARIES.ENCODER_WASM, 'textures', options)
93
- ]);
94
- // Depends on how import happened...
95
- // @ts-ignore TS2339: Property does not exist on type
96
- BASIS_ENCODER = BASIS_ENCODER || globalThis.BASIS;
97
- return await initializeBasisEncoderModule(BASIS_ENCODER, wasmBinary);
98
- }
99
- /**
100
- * Initialize wasm transcoder module
101
- * @param BasisEncoderModule - js part of the module
102
- * @param wasmBinary - wasm part of the module
103
- * @returns {BasisFile, KTX2File} promise
104
- */
105
- function initializeBasisEncoderModule(BasisEncoderModule, wasmBinary) {
106
- const options = {};
107
- if (wasmBinary) {
108
- options.wasmBinary = wasmBinary;
109
- }
110
- return new Promise((resolve) => {
111
- // if you try to return BasisModule the browser crashes!
112
- BasisEncoderModule(options).then((module) => {
113
- const { BasisFile, KTX2File, initializeBasis, BasisEncoder } = module;
114
- initializeBasis();
115
- resolve({ BasisFile, KTX2File, BasisEncoder });
116
- });
117
- });
118
- }
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadCrunchModule = exports.CRUNCH_EXTERNAL_LIBRARIES = void 0;
4
- // @ts-nocheck
5
- const worker_utils_1 = require("@loaders.gl/worker-utils");
6
- exports.CRUNCH_EXTERNAL_LIBRARIES = {
7
- /** Crunch decoder library. It is used as dynamically imported script */
8
- DECODER: 'crunch.js'
9
- };
10
- /**
11
- * Load crunch decoder module
12
- * @param options - loader options
13
- * @returns Promise of module object
14
- */
15
- async function loadCrunchModule(options) {
16
- const modules = options.modules || {};
17
- if (modules.crunch) {
18
- return modules.crunch;
19
- }
20
- return loadCrunch(options);
21
- }
22
- exports.loadCrunchModule = loadCrunchModule;
23
- let crunchModule;
24
- /**
25
- * Load crunch decoder module
26
- * @param {any} options - Loader options
27
- * @returns {Promise<any>} Promise of Module object
28
- */
29
- async function loadCrunch(options) {
30
- if (crunchModule) {
31
- return crunchModule;
32
- }
33
- let loadCrunchDecoder = await (0, worker_utils_1.loadLibrary)(exports.CRUNCH_EXTERNAL_LIBRARIES.DECODER, 'textures', options);
34
- // Depends on how import happened...
35
- // @ts-ignore TS2339: Property does not exist on type
36
- loadCrunchDecoder = loadCrunchDecoder || globalThis.LoadCrunchDecoder;
37
- crunchModule = loadCrunchDecoder();
38
- return crunchModule;
39
- }
@@ -1,245 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.selectSupportedBasisFormat = void 0;
4
- const basis_module_loader_1 = require("./basis-module-loader");
5
- const gl_extensions_1 = require("../gl-extensions");
6
- const texture_formats_1 = require("../utils/texture-formats");
7
- const parse_ktx_1 = require("./parse-ktx");
8
- const OutputFormat = {
9
- etc1: {
10
- basisFormat: 0,
11
- compressed: true,
12
- format: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL
13
- },
14
- etc2: { basisFormat: 1, compressed: true },
15
- bc1: {
16
- basisFormat: 2,
17
- compressed: true,
18
- format: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT
19
- },
20
- bc3: {
21
- basisFormat: 3,
22
- compressed: true,
23
- format: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT
24
- },
25
- bc4: { basisFormat: 4, compressed: true },
26
- bc5: { basisFormat: 5, compressed: true },
27
- 'bc7-m6-opaque-only': { basisFormat: 6, compressed: true },
28
- 'bc7-m5': { basisFormat: 7, compressed: true },
29
- 'pvrtc1-4-rgb': {
30
- basisFormat: 8,
31
- compressed: true,
32
- format: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG
33
- },
34
- 'pvrtc1-4-rgba': {
35
- basisFormat: 9,
36
- compressed: true,
37
- format: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
38
- },
39
- 'astc-4x4': {
40
- basisFormat: 10,
41
- compressed: true,
42
- format: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR
43
- },
44
- 'atc-rgb': { basisFormat: 11, compressed: true },
45
- 'atc-rgba-interpolated-alpha': { basisFormat: 12, compressed: true },
46
- rgba32: { basisFormat: 13, compressed: false },
47
- rgb565: { basisFormat: 14, compressed: false },
48
- bgr565: { basisFormat: 15, compressed: false },
49
- rgba4444: { basisFormat: 16, compressed: false }
50
- };
51
- /**
52
- * parse data with a Binomial Basis_Universal module
53
- * @param data
54
- * @param options
55
- * @returns compressed texture data
56
- */
57
- async function parseBasis(data, options) {
58
- if (options.basis.containerFormat === 'auto') {
59
- if ((0, parse_ktx_1.isKTX)(data)) {
60
- const fileConstructors = await (0, basis_module_loader_1.loadBasisEncoderModule)(options);
61
- return parseKTX2File(fileConstructors.KTX2File, data, options);
62
- }
63
- const { BasisFile } = await (0, basis_module_loader_1.loadBasisTranscoderModule)(options);
64
- return parseBasisFile(BasisFile, data, options);
65
- }
66
- switch (options.basis.module) {
67
- case 'encoder':
68
- const fileConstructors = await (0, basis_module_loader_1.loadBasisEncoderModule)(options);
69
- switch (options.basis.containerFormat) {
70
- case 'ktx2':
71
- return parseKTX2File(fileConstructors.KTX2File, data, options);
72
- case 'basis':
73
- default:
74
- return parseBasisFile(fileConstructors.BasisFile, data, options);
75
- }
76
- case 'transcoder':
77
- default:
78
- const { BasisFile } = await (0, basis_module_loader_1.loadBasisTranscoderModule)(options);
79
- return parseBasisFile(BasisFile, data, options);
80
- }
81
- }
82
- exports.default = parseBasis;
83
- /**
84
- * Parse *.basis file data
85
- * @param BasisFile - initialized transcoder module
86
- * @param data
87
- * @param options
88
- * @returns compressed texture data
89
- */
90
- function parseBasisFile(BasisFile, data, options) {
91
- const basisFile = new BasisFile(new Uint8Array(data));
92
- try {
93
- if (!basisFile.startTranscoding()) {
94
- throw new Error('Failed to start basis transcoding');
95
- }
96
- const imageCount = basisFile.getNumImages();
97
- const images = [];
98
- for (let imageIndex = 0; imageIndex < imageCount; imageIndex++) {
99
- const levelsCount = basisFile.getNumLevels(imageIndex);
100
- const levels = [];
101
- for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {
102
- levels.push(transcodeImage(basisFile, imageIndex, levelIndex, options));
103
- }
104
- images.push(levels);
105
- }
106
- return images;
107
- }
108
- finally {
109
- basisFile.close();
110
- basisFile.delete();
111
- }
112
- }
113
- /**
114
- * Parse the particular level image of a basis file
115
- * @param basisFile
116
- * @param imageIndex
117
- * @param levelIndex
118
- * @param options
119
- * @returns compressed texture data
120
- */
121
- function transcodeImage(basisFile, imageIndex, levelIndex, options) {
122
- const width = basisFile.getImageWidth(imageIndex, levelIndex);
123
- const height = basisFile.getImageHeight(imageIndex, levelIndex);
124
- // See https://github.com/BinomialLLC/basis_universal/pull/83
125
- const hasAlpha = basisFile.getHasAlpha( /* imageIndex, levelIndex */);
126
- // Check options for output format etc
127
- const { compressed, format, basisFormat } = getBasisOptions(options, hasAlpha);
128
- const decodedSize = basisFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, basisFormat);
129
- const decodedData = new Uint8Array(decodedSize);
130
- if (!basisFile.transcodeImage(decodedData, imageIndex, levelIndex, basisFormat, 0, 0)) {
131
- throw new Error('failed to start Basis transcoding');
132
- }
133
- return {
134
- // standard loaders.gl image category payload
135
- width,
136
- height,
137
- data: decodedData,
138
- compressed,
139
- format,
140
- // Additional fields
141
- // Add levelSize field.
142
- hasAlpha
143
- };
144
- }
145
- /**
146
- * Parse *.ktx2 file data
147
- * @param KTX2File
148
- * @param data
149
- * @param options
150
- * @returns compressed texture data
151
- */
152
- function parseKTX2File(KTX2File, data, options) {
153
- const ktx2File = new KTX2File(new Uint8Array(data));
154
- try {
155
- if (!ktx2File.startTranscoding()) {
156
- throw new Error('failed to start KTX2 transcoding');
157
- }
158
- const levelsCount = ktx2File.getLevels();
159
- const levels = [];
160
- for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {
161
- levels.push(transcodeKTX2Image(ktx2File, levelIndex, options));
162
- break; // texture app can only show one level for some reason
163
- }
164
- return [levels];
165
- }
166
- finally {
167
- ktx2File.close();
168
- ktx2File.delete();
169
- }
170
- }
171
- /**
172
- * Parse the particular level image of a ktx2 file
173
- * @param ktx2File
174
- * @param levelIndex
175
- * @param options
176
- * @returns
177
- */
178
- function transcodeKTX2Image(ktx2File, levelIndex, options) {
179
- const { alphaFlag, height, width } = ktx2File.getImageLevelInfo(levelIndex, 0, 0);
180
- // Check options for output format etc
181
- const { compressed, format, basisFormat } = getBasisOptions(options, alphaFlag);
182
- const decodedSize = ktx2File.getImageTranscodedSizeInBytes(levelIndex, 0 /* layerIndex */, 0 /* faceIndex */, basisFormat);
183
- const decodedData = new Uint8Array(decodedSize);
184
- if (!ktx2File.transcodeImage(decodedData, levelIndex, 0 /* layerIndex */, 0 /* faceIndex */, basisFormat, 0, -1 /* channel0 */, -1 /* channel1 */)) {
185
- throw new Error('Failed to transcode KTX2 image');
186
- }
187
- return {
188
- // standard loaders.gl image category payload
189
- width,
190
- height,
191
- data: decodedData,
192
- compressed,
193
- // Additional fields
194
- levelSize: decodedSize,
195
- hasAlpha: alphaFlag,
196
- format
197
- };
198
- }
199
- /**
200
- * Get BasisFormat by loader format option
201
- * @param options
202
- * @param hasAlpha
203
- * @returns BasisFormat data
204
- */
205
- function getBasisOptions(options, hasAlpha) {
206
- let format = options && options.basis && options.basis.format;
207
- if (format === 'auto') {
208
- format = selectSupportedBasisFormat();
209
- }
210
- if (typeof format === 'object') {
211
- format = hasAlpha ? format.alpha : format.noAlpha;
212
- }
213
- format = format.toLowerCase();
214
- return OutputFormat[format];
215
- }
216
- /**
217
- * Select transcode format from the list of supported formats
218
- * @returns key for OutputFormat map
219
- */
220
- function selectSupportedBasisFormat() {
221
- const supportedFormats = (0, texture_formats_1.getSupportedGPUTextureFormats)();
222
- if (supportedFormats.has('astc')) {
223
- return 'astc-4x4';
224
- }
225
- else if (supportedFormats.has('dxt')) {
226
- return {
227
- alpha: 'bc3',
228
- noAlpha: 'bc1'
229
- };
230
- }
231
- else if (supportedFormats.has('pvrtc')) {
232
- return {
233
- alpha: 'pvrtc1-4-rgba',
234
- noAlpha: 'pvrtc1-4-rgb'
235
- };
236
- }
237
- else if (supportedFormats.has('etc1')) {
238
- return 'etc1';
239
- }
240
- else if (supportedFormats.has('etc2')) {
241
- return 'etc2';
242
- }
243
- return 'rgb565';
244
- }
245
- exports.selectSupportedBasisFormat = selectSupportedBasisFormat;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseCompressedTexture = void 0;
4
- const parse_ktx_1 = require("./parse-ktx");
5
- const parse_dds_1 = require("./parse-dds");
6
- const parse_pvr_1 = require("./parse-pvr");
7
- /**
8
- * Deduces format and parses compressed texture loaded in ArrayBuffer
9
- * @param data - binary data of compressed texture
10
- * @returns Array of the texture levels
11
- */
12
- function parseCompressedTexture(data) {
13
- if ((0, parse_ktx_1.isKTX)(data)) {
14
- // TODO: remove @ts-ignore when `parseKTX` output is normalized to loaders.gl texture format
15
- // @ts-ignore
16
- return (0, parse_ktx_1.parseKTX)(data);
17
- }
18
- if ((0, parse_dds_1.isDDS)(data)) {
19
- return (0, parse_dds_1.parseDDS)(data);
20
- }
21
- if ((0, parse_pvr_1.isPVR)(data)) {
22
- return (0, parse_pvr_1.parsePVR)(data);
23
- }
24
- throw new Error('Texture container format not recognized');
25
- }
26
- exports.parseCompressedTexture = parseCompressedTexture;
@@ -1,106 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseCrunch = void 0;
4
- const crunch_module_loader_1 = require("./crunch-module-loader");
5
- const gl_extensions_1 = require("../gl-extensions");
6
- const loader_utils_1 = require("@loaders.gl/loader-utils");
7
- const parse_dds_1 = require("./parse-dds");
8
- const extract_mipmap_images_1 = require("../utils/extract-mipmap-images");
9
- // Taken from crnlib.h
10
- const CRN_FORMAT = {
11
- cCRNFmtInvalid: -1,
12
- cCRNFmtDXT1: 0,
13
- // cCRNFmtDXT3 is not currently supported when writing to CRN - only DDS.
14
- cCRNFmtDXT3: 1,
15
- cCRNFmtDXT5: 2
16
- // Crunch supports more formats than this.
17
- };
18
- /** Mapping of Crunch formats to DXT formats. */
19
- const DXT_FORMAT_MAP = {
20
- [CRN_FORMAT.cCRNFmtDXT1]: {
21
- pixelFormat: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT,
22
- sizeFunction: parse_dds_1.getDxt1LevelSize
23
- },
24
- [CRN_FORMAT.cCRNFmtDXT3]: {
25
- pixelFormat: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT,
26
- sizeFunction: parse_dds_1.getDxtXLevelSize
27
- },
28
- [CRN_FORMAT.cCRNFmtDXT5]: {
29
- pixelFormat: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
30
- sizeFunction: parse_dds_1.getDxtXLevelSize
31
- }
32
- };
33
- let cachedDstSize = 0;
34
- let dst;
35
- /**
36
- * Parse texture data as "CRN" format.
37
- * Function is "async" as emscriptified decoder module is loaded asyncronously
38
- * @param data - binary data of compressed texture
39
- * @returns Promise of Array of the texture levels
40
- */
41
- async function parseCrunch(data, options) {
42
- const crunchModule = await (0, crunch_module_loader_1.loadCrunchModule)(options);
43
- // Copy the contents of the arrayBuffer into emscriptens heap.
44
- const srcSize = data.byteLength;
45
- const bytes = new Uint8Array(data);
46
- const src = crunchModule._malloc(srcSize);
47
- arrayBufferCopy(bytes, crunchModule.HEAPU8, src, srcSize);
48
- // Determine what type of compressed data the file contains.
49
- const format = crunchModule._crn_get_dxt_format(src, srcSize);
50
- (0, loader_utils_1.assert)(Boolean(DXT_FORMAT_MAP[format]), 'Unsupported format');
51
- // Gather basic metrics about the DXT data.
52
- const mipMapLevels = crunchModule._crn_get_levels(src, srcSize);
53
- const width = crunchModule._crn_get_width(src, srcSize);
54
- const height = crunchModule._crn_get_height(src, srcSize);
55
- // const bytesPerBlock = crunchModule._crn_get_bytes_per_block(src, srcSize);
56
- // Determine the size of the decoded DXT data.
57
- const sizeFunction = DXT_FORMAT_MAP[format].sizeFunction;
58
- let dstSize = 0;
59
- for (let i = 0; i < mipMapLevels; ++i) {
60
- dstSize += sizeFunction(width >> i, height >> i);
61
- }
62
- // Allocate enough space on the emscripten heap to hold the decoded DXT data
63
- // or reuse the existing allocation if a previous call to this function has
64
- // already acquired a large enough buffer.
65
- if (cachedDstSize < dstSize) {
66
- if (dst) {
67
- crunchModule._free(dst);
68
- }
69
- dst = crunchModule._malloc(dstSize);
70
- cachedDstSize = dstSize;
71
- }
72
- // Decompress the DXT data from the Crunch file into the allocated space.
73
- crunchModule._crn_decompress(src, srcSize, dst, dstSize, 0, mipMapLevels);
74
- // Release the crunch file data from the emscripten heap.
75
- crunchModule._free(src);
76
- const image = new Uint8Array(crunchModule.HEAPU8.buffer, dst, dstSize).slice();
77
- return (0, extract_mipmap_images_1.extractMipmapImages)(image, {
78
- mipMapLevels,
79
- width,
80
- height,
81
- sizeFunction,
82
- internalFormat: DXT_FORMAT_MAP[format].pixelFormat
83
- });
84
- }
85
- exports.parseCrunch = parseCrunch;
86
- /**
87
- * Copy an array of bytes into or out of the emscripten heap
88
- * @param {Uint8Array} srcData - Source data array
89
- * @param {Uint8Array} dstData - Destination data array
90
- * @param {number} dstByteOffset - Destination data offset
91
- * @param {number} numBytes - number of bytes to copy
92
- * @returns {void}
93
- */
94
- function arrayBufferCopy(srcData, dstData, dstByteOffset, numBytes) {
95
- let i;
96
- const dst32Offset = dstByteOffset / 4;
97
- const tail = numBytes % 4;
98
- const src32 = new Uint32Array(srcData.buffer, 0, (numBytes - tail) / 4);
99
- const dst32 = new Uint32Array(dstData.buffer);
100
- for (i = 0; i < src32.length; i++) {
101
- dst32[dst32Offset + i] = src32[i];
102
- }
103
- for (i = numBytes - tail; i < numBytes; i++) {
104
- dstData[dstByteOffset + i] = srcData[i];
105
- }
106
- }