@loaders.gl/textures 4.0.0-alpha.4 → 4.0.0-alpha.5

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 (144) hide show
  1. package/dist/basis-loader.d.ts +50 -0
  2. package/dist/basis-loader.d.ts.map +1 -0
  3. package/dist/basis-worker.js +116 -60
  4. package/dist/bundle.d.ts +2 -0
  5. package/dist/bundle.d.ts.map +1 -0
  6. package/dist/compressed-texture-loader.d.ts +49 -0
  7. package/dist/compressed-texture-loader.d.ts.map +1 -0
  8. package/dist/compressed-texture-loader.js +1 -1
  9. package/dist/compressed-texture-loader.js.map +1 -1
  10. package/dist/compressed-texture-worker.js +221 -123
  11. package/dist/compressed-texture-writer.d.ts +25 -0
  12. package/dist/compressed-texture-writer.d.ts.map +1 -0
  13. package/dist/crunch-loader.d.ts +21 -0
  14. package/dist/crunch-loader.d.ts.map +1 -0
  15. package/dist/crunch-worker.js +59 -26
  16. package/dist/dist.min.js +2123 -0
  17. package/dist/index.d.ts +16 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +1 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/ktx2-basis-universal-texture-writer.d.ts +22 -0
  22. package/dist/ktx2-basis-universal-texture-writer.d.ts.map +1 -0
  23. package/dist/lib/encoders/encode-ktx.d.ts +2 -0
  24. package/dist/lib/encoders/encode-ktx.d.ts.map +1 -0
  25. package/dist/lib/encoders/encode-ktx2-basis-texture.d.ts +10 -0
  26. package/dist/lib/encoders/encode-ktx2-basis-texture.d.ts.map +1 -0
  27. package/dist/lib/encoders/encode-ktx2-basis-texture.js +1 -1
  28. package/dist/lib/encoders/encode-ktx2-basis-texture.js.map +1 -1
  29. package/dist/lib/encoders/encode-texture.d.ts +4 -0
  30. package/dist/lib/encoders/encode-texture.d.ts.map +1 -0
  31. package/dist/lib/encoders/encode-texture.js +2 -5
  32. package/dist/lib/encoders/encode-texture.js.map +1 -1
  33. package/dist/lib/gl-extensions.d.ts +61 -0
  34. package/dist/lib/gl-extensions.d.ts.map +1 -0
  35. package/dist/lib/{gl-constants.js → gl-extensions.js} +2 -2
  36. package/dist/lib/gl-extensions.js.map +1 -0
  37. package/dist/lib/parsers/basis-module-loader.d.ts +13 -0
  38. package/dist/lib/parsers/basis-module-loader.d.ts.map +1 -0
  39. package/dist/lib/parsers/basis-module-loader.js +1 -1
  40. package/dist/lib/parsers/crunch-module-loader.d.ts +7 -0
  41. package/dist/lib/parsers/crunch-module-loader.d.ts.map +1 -0
  42. package/dist/lib/parsers/crunch-module-loader.js +1 -1
  43. package/dist/lib/parsers/crunch-module-loader.js.map +1 -1
  44. package/dist/lib/parsers/parse-basis.d.ts +18 -0
  45. package/dist/lib/parsers/parse-basis.d.ts.map +1 -0
  46. package/dist/lib/parsers/parse-basis.js +16 -16
  47. package/dist/lib/parsers/parse-basis.js.map +1 -1
  48. package/dist/lib/parsers/parse-compressed-texture.d.ts +8 -0
  49. package/dist/lib/parsers/parse-compressed-texture.d.ts.map +1 -0
  50. package/dist/lib/parsers/parse-compressed-texture.js.map +1 -1
  51. package/dist/lib/parsers/parse-crunch.d.ts +9 -0
  52. package/dist/lib/parsers/parse-crunch.d.ts.map +1 -0
  53. package/dist/lib/parsers/parse-crunch.js +14 -13
  54. package/dist/lib/parsers/parse-crunch.js.map +1 -1
  55. package/dist/lib/parsers/parse-dds.d.ts +28 -0
  56. package/dist/lib/parsers/parse-dds.d.ts.map +1 -0
  57. package/dist/lib/parsers/parse-dds.js +7 -7
  58. package/dist/lib/parsers/parse-dds.js.map +1 -1
  59. package/dist/lib/parsers/parse-ktx.d.ts +4 -0
  60. package/dist/lib/parsers/parse-ktx.d.ts.map +1 -0
  61. package/dist/lib/parsers/parse-ktx.js.map +1 -1
  62. package/dist/lib/parsers/parse-npy.d.ts +10 -0
  63. package/dist/lib/parsers/parse-npy.d.ts.map +1 -0
  64. package/dist/lib/parsers/parse-npy.js.map +1 -1
  65. package/dist/lib/parsers/parse-pvr.d.ts +15 -0
  66. package/dist/lib/parsers/parse-pvr.d.ts.map +1 -0
  67. package/dist/lib/parsers/parse-pvr.js +28 -28
  68. package/dist/lib/parsers/parse-pvr.js.map +1 -1
  69. package/dist/lib/texture-api/async-deep-map.d.ts +5 -0
  70. package/dist/lib/texture-api/async-deep-map.d.ts.map +1 -0
  71. package/dist/lib/texture-api/deep-load.d.ts +5 -0
  72. package/dist/lib/texture-api/deep-load.d.ts.map +1 -0
  73. package/dist/lib/texture-api/generate-url.d.ts +3 -0
  74. package/dist/lib/texture-api/generate-url.d.ts.map +1 -0
  75. package/dist/lib/texture-api/load-image-array.d.ts +4 -0
  76. package/dist/lib/texture-api/load-image-array.d.ts.map +1 -0
  77. package/dist/lib/texture-api/load-image-cube.d.ts +12 -0
  78. package/dist/lib/texture-api/load-image-cube.d.ts.map +1 -0
  79. package/dist/lib/texture-api/load-image.d.ts +8 -0
  80. package/dist/lib/texture-api/load-image.d.ts.map +1 -0
  81. package/dist/lib/texture-api/texture-api-types.d.ts +10 -0
  82. package/dist/lib/texture-api/texture-api-types.d.ts.map +1 -0
  83. package/dist/lib/utils/extract-mipmap-images.d.ts +20 -0
  84. package/dist/lib/utils/extract-mipmap-images.d.ts.map +1 -0
  85. package/dist/lib/utils/extract-mipmap-images.js.map +1 -1
  86. package/dist/lib/utils/ktx-format-helper.d.ts +9 -0
  87. package/dist/lib/utils/ktx-format-helper.d.ts.map +1 -0
  88. package/dist/lib/utils/ktx-format-helper.js +67 -67
  89. package/dist/lib/utils/ktx-format-helper.js.map +1 -1
  90. package/dist/lib/utils/texture-formats.d.ts +8 -0
  91. package/dist/lib/utils/texture-formats.d.ts.map +1 -0
  92. package/dist/lib/utils/texture-formats.js.map +1 -1
  93. package/dist/lib/utils/version.d.ts +2 -0
  94. package/dist/lib/utils/version.d.ts.map +1 -0
  95. package/dist/lib/utils/version.js +1 -1
  96. package/dist/libs/README.md +2 -2
  97. package/dist/libs/basis_encoder.js +1 -1
  98. package/dist/libs/basis_transcoder.js +1 -1
  99. package/dist/libs/crunch.js +1 -0
  100. package/dist/libs/libs/README.md +9 -0
  101. package/dist/libs/libs/basis_encoder.js +22 -0
  102. package/dist/libs/libs/basis_encoder.wasm +0 -0
  103. package/dist/libs/libs/basis_transcoder.js +21 -0
  104. package/dist/libs/libs/basis_transcoder.wasm +0 -0
  105. package/dist/libs/libs/crunch.js +136 -0
  106. package/dist/npy-loader.d.ts +45 -0
  107. package/dist/npy-loader.d.ts.map +1 -0
  108. package/dist/npy-worker.js +1 -1
  109. package/dist/types.d.ts +1 -0
  110. package/dist/types.d.ts.map +1 -0
  111. package/dist/types.js +1 -1
  112. package/dist/workers/basis-worker.d.ts +2 -0
  113. package/dist/workers/basis-worker.d.ts.map +1 -0
  114. package/dist/workers/compressed-texture-worker.d.ts +2 -0
  115. package/dist/workers/compressed-texture-worker.d.ts.map +1 -0
  116. package/dist/workers/crunch-worker.d.ts +21 -0
  117. package/dist/workers/crunch-worker.d.ts.map +1 -0
  118. package/dist/workers/npy-worker.d.ts +2 -0
  119. package/dist/workers/npy-worker.d.ts.map +1 -0
  120. package/package.json +12 -11
  121. package/src/compressed-texture-loader.ts +1 -1
  122. package/src/index.ts +2 -2
  123. package/src/lib/encoders/encode-ktx2-basis-texture.ts +2 -2
  124. package/src/lib/encoders/encode-texture.ts +6 -6
  125. package/src/lib/{gl-constants.ts → gl-extensions.ts} +1 -1
  126. package/src/lib/parsers/crunch-module-loader.ts +1 -1
  127. package/src/lib/parsers/{parse-basis.js → parse-basis.ts} +100 -44
  128. package/src/lib/parsers/parse-compressed-texture.ts +1 -1
  129. package/src/lib/parsers/parse-crunch.ts +16 -15
  130. package/src/lib/parsers/parse-dds.ts +8 -8
  131. package/src/lib/parsers/parse-ktx.ts +2 -1
  132. package/src/lib/parsers/parse-npy.ts +2 -0
  133. package/src/lib/parsers/parse-pvr.ts +72 -29
  134. package/src/lib/utils/extract-mipmap-images.ts +9 -1
  135. package/src/lib/utils/ktx-format-helper.ts +67 -67
  136. package/src/lib/utils/texture-formats.ts +1 -1
  137. package/src/libs/README.md +2 -2
  138. package/src/libs/basis_encoder.js +1 -1
  139. package/src/libs/basis_transcoder.js +1 -1
  140. package/src/libs/crunch.js +1 -0
  141. package/src/types.ts +0 -30
  142. package/dist/lib/gl-constants.js.map +0 -1
  143. package/src/lib/parsers/parse-ktx.js +0 -45
  144. package/src/lib/parsers/parse-npy.js +0 -96
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/textures",
3
- "version": "4.0.0-alpha.4",
3
+ "version": "4.0.0-alpha.5",
4
4
  "description": "Framework-independent loaders for compressed and super compressed (basis) textures ",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -21,7 +21,7 @@
21
21
  "ETC",
22
22
  "basis"
23
23
  ],
24
- "types": "src/index.ts",
24
+ "types": "dist/index.d.ts",
25
25
  "main": "dist/index.js",
26
26
  "module": "dist/index.js",
27
27
  "sideEffects": false,
@@ -34,19 +34,20 @@
34
34
  "scripts": {
35
35
  "pre-build": "npm run copy-libs && npm run build-worker && npm run build-bundle",
36
36
  "copy-libs": "cp -rf ./src/libs ./dist/libs",
37
- "build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/bundle.js",
37
+ "build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/dist.min.js",
38
38
  "build-worker": "npm run build-basis-worker && npm run build-npy-worker && npm run build-compressed-texture-worker && npm run build-crunch-worker",
39
- "build-basis-worker": "esbuild src/workers/basis-worker.ts --bundle --outfile=dist/basis-worker.js",
40
- "build-npy-worker": "esbuild src/workers/npy-worker.ts --bundle --outfile=dist/npy-worker.js",
41
- "build-compressed-texture-worker": "esbuild src/workers/compressed-texture-worker.ts --bundle --outfile=dist/compressed-texture-worker.js",
42
- "build-crunch-worker": "esbuild src/workers/crunch-worker.ts --bundle --outfile=dist/crunch-worker.js"
39
+ "build-basis-worker": "esbuild src/workers/basis-worker.ts --bundle --outfile=dist/basis-worker.js --define:__VERSION__=\\\"$npm_package_version\\\"",
40
+ "build-npy-worker": "esbuild src/workers/npy-worker.ts --bundle --outfile=dist/npy-worker.js --define:__VERSION__=\\\"$npm_package_version\\\"",
41
+ "build-compressed-texture-worker": "esbuild src/workers/compressed-texture-worker.ts --bundle --outfile=dist/compressed-texture-worker.js --define:__VERSION__=\\\"$npm_package_version\\\"",
42
+ "build-crunch-worker": "esbuild src/workers/crunch-worker.ts --bundle --outfile=dist/crunch-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
43
43
  },
44
44
  "dependencies": {
45
- "@loaders.gl/images": "4.0.0-alpha.4",
46
- "@loaders.gl/loader-utils": "4.0.0-alpha.4",
47
- "@loaders.gl/worker-utils": "4.0.0-alpha.4",
45
+ "@loaders.gl/images": "4.0.0-alpha.5",
46
+ "@loaders.gl/loader-utils": "4.0.0-alpha.5",
47
+ "@loaders.gl/schema": "4.0.0-alpha.5",
48
+ "@loaders.gl/worker-utils": "4.0.0-alpha.5",
48
49
  "ktx-parse": "^0.0.4",
49
50
  "texture-compressor": "^1.0.2"
50
51
  },
51
- "gitHead": "53026061b3c8871f7e96d3a5826125cc6613bddc"
52
+ "gitHead": "7a71a54bdf1ddf985cc3af3db90b82e7fa97d025"
52
53
  }
@@ -59,7 +59,7 @@ export const CompressedTextureLoader = {
59
59
  containerFormat: 'ktx2',
60
60
  module: 'encoder'
61
61
  };
62
- return await parseBasis(arrayBuffer, options);
62
+ return (await parseBasis(arrayBuffer, options))[0];
63
63
  }
64
64
  return parseCompressedTexture(arrayBuffer);
65
65
  }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // Types
2
- export type {GPUTextureFormat} from './types';
2
+ export type {GPUTextureFormat} from '@loaders.gl/schema';
3
3
  export type {TextureLoaderOptions} from './compressed-texture-loader';
4
4
 
5
5
  // Loaders
@@ -18,7 +18,7 @@ export {loadImageTextureArray} from './lib/texture-api/load-image-array';
18
18
  export {loadImageTextureCube} from './lib/texture-api/load-image-cube';
19
19
 
20
20
  // Utilities
21
- export {GL as GL_CONSTANTS} from './lib/gl-constants';
21
+ export {GL_EXTENSIONS_CONSTANTS} from './lib/gl-extensions';
22
22
  export {selectSupportedBasisFormat} from './lib/parsers/parse-basis';
23
23
  export {getSupportedGPUTextureFormats} from './lib/utils/texture-formats';
24
24
 
@@ -11,7 +11,7 @@ import {loadBasisEncoderModule} from '../parsers/basis-module-loader';
11
11
  export async function encodeKTX2BasisTexture(
12
12
  image: ImageDataType,
13
13
  options: any = {}
14
- ): Promise<Uint8Array> {
14
+ ): Promise<ArrayBuffer> {
15
15
  // TODO remove default values after writer options will be normalized like it done in load module.
16
16
  const {useSRGB = false, qualityLevel = 10, encodeUASTC = false, mipmaps = false} = options;
17
17
  const {BasisEncoder} = await loadBasisEncoderModule(options);
@@ -32,7 +32,7 @@ export async function encodeKTX2BasisTexture(
32
32
 
33
33
  const numOutputBytes = basisEncoder.encode(basisFileData);
34
34
 
35
- const actualKTX2FileData = new Uint8Array(basisFileData.buffer, 0, numOutputBytes);
35
+ const actualKTX2FileData = basisFileData.subarray(0, numOutputBytes).buffer;
36
36
  return actualKTX2FileData;
37
37
  } catch (error) {
38
38
  // eslint-disable-next-line no-console
@@ -1,11 +1,13 @@
1
1
  import {ChildProcessProxy} from '@loaders.gl/worker-utils';
2
2
 
3
- const MODULE_ROOT = `${__dirname}/../../..`;
4
-
5
3
  /*
6
4
  * @see https://github.com/TimvanScherpenzeel/texture-compressor
7
5
  */
8
- export async function encodeImageURLToCompressedTextureURL(inputUrl, outputUrl) {
6
+ export async function encodeImageURLToCompressedTextureURL(
7
+ inputUrl: string,
8
+ outputUrl: string,
9
+ options?: {cwd?: string}
10
+ ): Promise<string> {
9
11
  // prettier-ignore
10
12
  const args = [
11
13
  // Note: our actual executable is `npx`, so `texture-compressor` is an argument
@@ -20,9 +22,7 @@ export async function encodeImageURLToCompressedTextureURL(inputUrl, outputUrl)
20
22
  await childProcess.start({
21
23
  command: 'npx',
22
24
  arguments: args,
23
- spawn: {
24
- cwd: MODULE_ROOT
25
- }
25
+ spawn: options
26
26
  });
27
27
  return outputUrl;
28
28
  }
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable camelcase */
2
- export const GL = {
2
+ export const GL_EXTENSIONS_CONSTANTS = {
3
3
  // WEBGL_compressed_texture_s3tc
4
4
 
5
5
  COMPRESSED_RGB_S3TC_DXT1_EXT: 0x83f0,
@@ -31,7 +31,7 @@ async function loadCrunch(options) {
31
31
 
32
32
  // Depends on how import happened...
33
33
  // @ts-ignore TS2339: Property does not exist on type
34
- loadCrunchDecoder = loadCrunchDecoder || globalThis.loadCrunchDecoder;
34
+ loadCrunchDecoder = loadCrunchDecoder || globalThis.LoadCrunchDecoder;
35
35
  crunchModule = loadCrunchDecoder();
36
36
  return crunchModule;
37
37
  }
@@ -1,20 +1,71 @@
1
+ /* eslint-disable indent */
2
+ import type {TextureLevel} from '@loaders.gl/schema';
1
3
  import {loadBasisEncoderModule, loadBasisTrascoderModule} from './basis-module-loader';
2
- import {GL} from '../gl-constants';
3
- import {getSupportedGPUTextureFormats} from '../..';
4
+ import {GL_EXTENSIONS_CONSTANTS} from '../gl-extensions';
5
+ import {getSupportedGPUTextureFormats} from '../utils/texture-formats';
4
6
  import {isKTX} from './parse-ktx';
5
7
 
6
- const OutputFormat = {
7
- etc1: {basisFormat: 0, compressed: true, format: GL.COMPRESSED_RGB_ETC1_WEBGL},
8
+ export type BasisFormat =
9
+ | 'etc1'
10
+ | 'etc2'
11
+ | 'bc1'
12
+ | 'bc3'
13
+ | 'bc4'
14
+ | 'bc5'
15
+ | 'bc7-m6-opaque-only'
16
+ | 'bc7-m5'
17
+ | 'pvrtc1-4-rgb'
18
+ | 'pvrtc1-4-rgba'
19
+ | 'astc-4x4'
20
+ | 'atc-rgb'
21
+ | 'atc-rgba-interpolated-alpha'
22
+ | 'rgba32'
23
+ | 'rgb565'
24
+ | 'bgr565'
25
+ | 'rgba4444';
26
+
27
+ type BasisOutputOptions = {
28
+ basisFormat: number;
29
+ compressed: boolean;
30
+ format?: number;
31
+ };
32
+
33
+ const OutputFormat: Record<string, BasisOutputOptions> = {
34
+ etc1: {
35
+ basisFormat: 0,
36
+ compressed: true,
37
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL
38
+ },
8
39
  etc2: {basisFormat: 1, compressed: true},
9
- bc1: {basisFormat: 2, compressed: true, format: GL.COMPRESSED_RGB_S3TC_DXT1_EXT},
10
- bc3: {basisFormat: 3, compressed: true, format: GL.COMPRESSED_RGBA_S3TC_DXT5_EXT},
40
+ bc1: {
41
+ basisFormat: 2,
42
+ compressed: true,
43
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT
44
+ },
45
+ bc3: {
46
+ basisFormat: 3,
47
+ compressed: true,
48
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT
49
+ },
11
50
  bc4: {basisFormat: 4, compressed: true},
12
51
  bc5: {basisFormat: 5, compressed: true},
13
52
  'bc7-m6-opaque-only': {basisFormat: 6, compressed: true},
14
53
  'bc7-m5': {basisFormat: 7, compressed: true},
15
- 'pvrtc1-4-rgb': {basisFormat: 8, compressed: true, format: GL.COMPRESSED_RGB_PVRTC_4BPPV1_IMG},
16
- 'pvrtc1-4-rgba': {basisFormat: 9, compressed: true, format: GL.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG},
17
- 'astc-4x4': {basisFormat: 10, compressed: true, format: GL.COMPRESSED_RGBA_ASTC_4X4_KHR},
54
+ 'pvrtc1-4-rgb': {
55
+ basisFormat: 8,
56
+ compressed: true,
57
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG
58
+ },
59
+ 'pvrtc1-4-rgba': {
60
+ basisFormat: 9,
61
+ compressed: true,
62
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
63
+ },
64
+ 'astc-4x4': {
65
+ basisFormat: 10,
66
+ compressed: true,
67
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR
68
+ },
18
69
  'atc-rgb': {basisFormat: 11, compressed: true},
19
70
  'atc-rgba-interpolated-alpha': {basisFormat: 12, compressed: true},
20
71
  rgba32: {basisFormat: 13, compressed: false},
@@ -25,11 +76,11 @@ const OutputFormat = {
25
76
 
26
77
  /**
27
78
  * parse data with a Binomial Basis_Universal module
28
- * @param {ArrayBuffer} data
29
- * @param {*} options
79
+ * @param data
80
+ * @param options
30
81
  * @returns compressed texture data
31
82
  */
32
- export default async function parseBasis(data, options) {
83
+ export default async function parseBasis(data: ArrayBuffer, options): Promise<TextureLevel[][]> {
33
84
  if (options.basis.containerFormat === 'auto') {
34
85
  if (isKTX(data)) {
35
86
  const fileConstructors = await loadBasisEncoderModule(options);
@@ -57,25 +108,25 @@ export default async function parseBasis(data, options) {
57
108
 
58
109
  /**
59
110
  * Parse *.basis file data
60
- * @param {*} BasisFile - initialized transcoder module
61
- * @param {*} data
62
- * @param {*} options
111
+ * @param BasisFile - initialized transcoder module
112
+ * @param data
113
+ * @param options
63
114
  * @returns compressed texture data
64
115
  */
65
- function parseBasisFile(BasisFile, data, options) {
116
+ function parseBasisFile(BasisFile, data, options): TextureLevel[][] {
66
117
  const basisFile = new BasisFile(new Uint8Array(data));
67
118
 
68
119
  try {
69
120
  if (!basisFile.startTranscoding()) {
70
- return null;
121
+ throw new Error('Failed to start basis transcoding');
71
122
  }
72
123
 
73
124
  const imageCount = basisFile.getNumImages();
74
- const images = [];
125
+ const images: TextureLevel[][] = [];
75
126
 
76
127
  for (let imageIndex = 0; imageIndex < imageCount; imageIndex++) {
77
128
  const levelsCount = basisFile.getNumLevels(imageIndex);
78
- const levels = [];
129
+ const levels: TextureLevel[] = [];
79
130
 
80
131
  for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {
81
132
  levels.push(transcodeImage(basisFile, imageIndex, levelIndex, options));
@@ -93,13 +144,13 @@ function parseBasisFile(BasisFile, data, options) {
93
144
 
94
145
  /**
95
146
  * Parse the particular level image of a basis file
96
- * @param {*} basisFile
97
- * @param {*} imageIndex
98
- * @param {*} levelIndex
99
- * @param {*} options
147
+ * @param basisFile
148
+ * @param imageIndex
149
+ * @param levelIndex
150
+ * @param options
100
151
  * @returns compressed texture data
101
152
  */
102
- function transcodeImage(basisFile, imageIndex, levelIndex, options) {
153
+ function transcodeImage(basisFile, imageIndex, levelIndex, options): TextureLevel {
103
154
  const width = basisFile.getImageWidth(imageIndex, levelIndex);
104
155
  const height = basisFile.getImageHeight(imageIndex, levelIndex);
105
156
 
@@ -113,7 +164,7 @@ function transcodeImage(basisFile, imageIndex, levelIndex, options) {
113
164
  const decodedData = new Uint8Array(decodedSize);
114
165
 
115
166
  if (!basisFile.transcodeImage(decodedData, imageIndex, levelIndex, basisFormat, 0, 0)) {
116
- return null;
167
+ throw new Error('failed to start Basis transcoding');
117
168
  }
118
169
 
119
170
  return {
@@ -122,37 +173,37 @@ function transcodeImage(basisFile, imageIndex, levelIndex, options) {
122
173
  height,
123
174
  data: decodedData,
124
175
  compressed,
176
+ format,
125
177
 
126
178
  // Additional fields
127
179
  // Add levelSize field.
128
- hasAlpha,
129
- format
180
+ hasAlpha
130
181
  };
131
182
  }
132
183
 
133
184
  /**
134
185
  * Parse *.ktx2 file data
135
- * @param {*} KTX2File
136
- * @param {*} data
137
- * @param {*} options
186
+ * @param KTX2File
187
+ * @param data
188
+ * @param options
138
189
  * @returns compressed texture data
139
190
  */
140
- function parseKTX2File(KTX2File, data, options) {
191
+ function parseKTX2File(KTX2File, data: ArrayBuffer, options): TextureLevel[][] {
141
192
  const ktx2File = new KTX2File(new Uint8Array(data));
142
193
 
143
194
  try {
144
195
  if (!ktx2File.startTranscoding()) {
145
- return null;
196
+ throw new Error('failed to start KTX2 transcoding');
146
197
  }
147
198
  const levelsCount = ktx2File.getLevels();
148
- const levels = [];
199
+ const levels: TextureLevel[] = [];
149
200
 
150
201
  for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {
151
202
  levels.push(transcodeKTX2Image(ktx2File, levelIndex, options));
152
203
  break; // texture app can only show one level for some reason
153
204
  }
154
205
 
155
- return levels;
206
+ return [levels];
156
207
  } finally {
157
208
  ktx2File.close();
158
209
  ktx2File.delete();
@@ -161,12 +212,12 @@ function parseKTX2File(KTX2File, data, options) {
161
212
 
162
213
  /**
163
214
  * Parse the particular level image of a ktx2 file
164
- * @param {*} ktx2File
165
- * @param {*} levelIndex
166
- * @param {*} options
215
+ * @param ktx2File
216
+ * @param levelIndex
217
+ * @param options
167
218
  * @returns
168
219
  */
169
- function transcodeKTX2Image(ktx2File, levelIndex, options) {
220
+ function transcodeKTX2Image(ktx2File, levelIndex: number, options): TextureLevel {
170
221
  const {alphaFlag, height, width} = ktx2File.getImageLevelInfo(levelIndex, 0, 0);
171
222
 
172
223
  // Check options for output format etc
@@ -192,7 +243,7 @@ function transcodeKTX2Image(ktx2File, levelIndex, options) {
192
243
  -1 /* channel1 */
193
244
  )
194
245
  ) {
195
- return null;
246
+ throw new Error('Failed to transcode KTX2 image');
196
247
  }
197
248
 
198
249
  return {
@@ -204,18 +255,18 @@ function transcodeKTX2Image(ktx2File, levelIndex, options) {
204
255
 
205
256
  // Additional fields
206
257
  // Add levelSize field.
207
- alphaFlag,
258
+ hasAlpha: alphaFlag,
208
259
  format
209
260
  };
210
261
  }
211
262
 
212
263
  /**
213
264
  * Get BasisFormat by loader format option
214
- * @param {*} options
215
- * @param {*} hasAlpha
265
+ * @param options
266
+ * @param hasAlpha
216
267
  * @returns BasisFormat data
217
268
  */
218
- function getBasisOptions(options, hasAlpha) {
269
+ function getBasisOptions(options, hasAlpha: boolean): BasisOutputOptions {
219
270
  let format = options && options.basis && options.basis.format;
220
271
  if (format === 'auto') {
221
272
  format = selectSupportedBasisFormat();
@@ -231,7 +282,12 @@ function getBasisOptions(options, hasAlpha) {
231
282
  * Select transcode format from the list of supported formats
232
283
  * @returns key for OutputFormat map
233
284
  */
234
- export function selectSupportedBasisFormat() {
285
+ export function selectSupportedBasisFormat():
286
+ | BasisFormat
287
+ | {
288
+ alpha: BasisFormat;
289
+ noAlpha: BasisFormat;
290
+ } {
235
291
  const supportedFormats = getSupportedGPUTextureFormats();
236
292
  if (supportedFormats.has('astc')) {
237
293
  return 'astc-4x4';
@@ -1,4 +1,4 @@
1
- import type {TextureLevel} from '../../types';
1
+ import type {TextureLevel} from '@loaders.gl/schema';
2
2
  import {isKTX, parseKTX} from './parse-ktx';
3
3
  import {isDDS, parseDDS} from './parse-dds';
4
4
  import {isPVR, parsePVR} from './parse-pvr';
@@ -1,6 +1,6 @@
1
- import type {TextureLevel} from '../../types';
1
+ import type {TextureLevel} from '@loaders.gl/schema';
2
2
  import {loadCrunchModule} from './crunch-module-loader';
3
- import {GL} from '../gl-constants';
3
+ import {GL_EXTENSIONS_CONSTANTS} from '../gl-extensions';
4
4
  import {assert} from '@loaders.gl/loader-utils';
5
5
  import {getDxt1LevelSize, getDxtXLevelSize} from './parse-dds';
6
6
  import {extractMipmapImages} from '../utils/extract-mipmap-images';
@@ -17,19 +17,20 @@ const CRN_FORMAT = {
17
17
  // Crunch supports more formats than this.
18
18
  };
19
19
 
20
- // Mapping of Crunch formats to DXT formats.
21
- const DXT_FORMAT_MAP = {};
22
- DXT_FORMAT_MAP[CRN_FORMAT.cCRNFmtDXT1] = {
23
- pixelFormat: GL.COMPRESSED_RGB_S3TC_DXT1_EXT,
24
- sizeFunction: getDxt1LevelSize
25
- };
26
- DXT_FORMAT_MAP[CRN_FORMAT.cCRNFmtDXT3] = {
27
- pixelFormat: GL.COMPRESSED_RGBA_S3TC_DXT3_EXT,
28
- sizeFunction: getDxtXLevelSize
29
- };
30
- DXT_FORMAT_MAP[CRN_FORMAT.cCRNFmtDXT5] = {
31
- pixelFormat: GL.COMPRESSED_RGBA_S3TC_DXT5_EXT,
32
- sizeFunction: getDxtXLevelSize
20
+ /** Mapping of Crunch formats to DXT formats. */
21
+ const DXT_FORMAT_MAP = {
22
+ [CRN_FORMAT.cCRNFmtDXT1]: {
23
+ pixelFormat: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT,
24
+ sizeFunction: getDxt1LevelSize
25
+ },
26
+ [CRN_FORMAT.cCRNFmtDXT3]: {
27
+ pixelFormat: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT,
28
+ sizeFunction: getDxtXLevelSize
29
+ },
30
+ [CRN_FORMAT.cCRNFmtDXT5]: {
31
+ pixelFormat: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
32
+ sizeFunction: getDxtXLevelSize
33
+ }
33
34
  };
34
35
 
35
36
  let cachedDstSize = 0;
@@ -1,6 +1,6 @@
1
- import type {TextureLevel} from '../../types';
1
+ import type {TextureLevel} from '@loaders.gl/schema';
2
2
  import {assert} from '@loaders.gl/loader-utils';
3
- import {GL} from '../gl-constants';
3
+ import {GL_EXTENSIONS_CONSTANTS} from '../gl-extensions';
4
4
  import {extractMipmapImages} from '../utils/extract-mipmap-images';
5
5
 
6
6
  const DDS_CONSTANTS = {
@@ -19,12 +19,12 @@ const DDS_CONSTANTS = {
19
19
  };
20
20
 
21
21
  const DDS_PIXEL_FORMATS: Record<string, number> = {
22
- DXT1: GL.COMPRESSED_RGB_S3TC_DXT1_EXT,
23
- DXT3: GL.COMPRESSED_RGBA_S3TC_DXT3_EXT,
24
- DXT5: GL.COMPRESSED_RGBA_S3TC_DXT5_EXT,
25
- 'ATC ': GL.COMPRESSED_RGB_ATC_WEBGL,
26
- ATCA: GL.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL,
27
- ATCI: GL.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL
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
28
28
  };
29
29
 
30
30
  const getATCLevelSize = getDxt1LevelSize;
@@ -1,3 +1,4 @@
1
+ import type {TextureLevel} from '@loaders.gl/schema';
1
2
  import {read} from 'ktx-parse';
2
3
  import {extractMipmapImages} from '../utils/extract-mipmap-images';
3
4
  import {mapVkFormatToWebGL} from '../utils/ktx-format-helper';
@@ -29,7 +30,7 @@ export function isKTX(data: ArrayBuffer) {
29
30
  return !notKTX;
30
31
  }
31
32
 
32
- export function parseKTX(arrayBuffer: ArrayBuffer) {
33
+ export function parseKTX(arrayBuffer: ArrayBuffer): TextureLevel[] {
33
34
  const uint8Array = new Uint8Array(arrayBuffer);
34
35
  const ktx = read(uint8Array);
35
36
  const mipMapLevels = Math.max(1, ktx.levels.length);
@@ -1,3 +1,5 @@
1
+ // import type {TextureLevel} from '@loaders.gl/schema';
2
+
1
3
  type NumpyHeader = {descr: string; shape: number[]};
2
4
 
3
5
  function systemIsLittleEndian() {
@@ -1,8 +1,9 @@
1
- import {TextureLevel} from '../../types';
2
1
  /* eslint-disable camelcase */
3
2
  // Forked from PicoGL: https://github.com/tsherif/picogl.js/blob/master/examples/utils/utils.js
4
3
  // Copyright (c) 2017 Tarek Sherif, The MIT License (MIT)
5
- import {GL} from '../gl-constants';
4
+
5
+ import type {TextureLevel} from '@loaders.gl/schema';
6
+ import {GL_EXTENSIONS_CONSTANTS} from '../gl-extensions';
6
7
  import {extractMipmapImages} from '../utils/extract-mipmap-images';
7
8
 
8
9
  const PVR_CONSTANTS: Record<string, number> = {
@@ -20,33 +21,75 @@ const PVR_CONSTANTS: Record<string, number> = {
20
21
  };
21
22
 
22
23
  const PVR_PIXEL_FORMATS: Record<number, number[]> = {
23
- 0: [GL.COMPRESSED_RGB_PVRTC_2BPPV1_IMG],
24
- 1: [GL.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG],
25
- 2: [GL.COMPRESSED_RGB_PVRTC_4BPPV1_IMG],
26
- 3: [GL.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG],
27
- 6: [GL.COMPRESSED_RGB_ETC1_WEBGL],
28
- 7: [GL.COMPRESSED_RGB_S3TC_DXT1_EXT],
29
- 9: [GL.COMPRESSED_RGBA_S3TC_DXT3_EXT],
30
- 11: [GL.COMPRESSED_RGBA_S3TC_DXT5_EXT],
31
- 22: [GL.COMPRESSED_RGB8_ETC2],
32
- 23: [GL.COMPRESSED_RGBA8_ETC2_EAC],
33
- 24: [GL.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2],
34
- 25: [GL.COMPRESSED_R11_EAC],
35
- 26: [GL.COMPRESSED_RG11_EAC],
36
- 27: [GL.COMPRESSED_RGBA_ASTC_4X4_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR],
37
- 28: [GL.COMPRESSED_RGBA_ASTC_5X4_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR],
38
- 29: [GL.COMPRESSED_RGBA_ASTC_5X5_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR],
39
- 30: [GL.COMPRESSED_RGBA_ASTC_6X5_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR],
40
- 31: [GL.COMPRESSED_RGBA_ASTC_6X6_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR],
41
- 32: [GL.COMPRESSED_RGBA_ASTC_8X5_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR],
42
- 33: [GL.COMPRESSED_RGBA_ASTC_8X6_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR],
43
- 34: [GL.COMPRESSED_RGBA_ASTC_8X8_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR],
44
- 35: [GL.COMPRESSED_RGBA_ASTC_10X5_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR],
45
- 36: [GL.COMPRESSED_RGBA_ASTC_10X6_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR],
46
- 37: [GL.COMPRESSED_RGBA_ASTC_10X8_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR],
47
- 38: [GL.COMPRESSED_RGBA_ASTC_10X10_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR],
48
- 39: [GL.COMPRESSED_RGBA_ASTC_12X10_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR],
49
- 40: [GL.COMPRESSED_RGBA_ASTC_12X12_KHR, GL.COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR]
24
+ 0: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_2BPPV1_IMG],
25
+ 1: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG],
26
+ 2: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG],
27
+ 3: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG],
28
+ 6: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL],
29
+ 7: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT],
30
+ 9: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT],
31
+ 11: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT],
32
+ 22: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_ETC2],
33
+ 23: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA8_ETC2_EAC],
34
+ 24: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2],
35
+ 25: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_R11_EAC],
36
+ 26: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RG11_EAC],
37
+ 27: [
38
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR,
39
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR
40
+ ],
41
+ 28: [
42
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5X4_KHR,
43
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR
44
+ ],
45
+ 29: [
46
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5X5_KHR,
47
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR
48
+ ],
49
+ 30: [
50
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6X5_KHR,
51
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR
52
+ ],
53
+ 31: [
54
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6X6_KHR,
55
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR
56
+ ],
57
+ 32: [
58
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X5_KHR,
59
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR
60
+ ],
61
+ 33: [
62
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X6_KHR,
63
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR
64
+ ],
65
+ 34: [
66
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X8_KHR,
67
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR
68
+ ],
69
+ 35: [
70
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X5_KHR,
71
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR
72
+ ],
73
+ 36: [
74
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X6_KHR,
75
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR
76
+ ],
77
+ 37: [
78
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X8_KHR,
79
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR
80
+ ],
81
+ 38: [
82
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X10_KHR,
83
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR
84
+ ],
85
+ 39: [
86
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12X10_KHR,
87
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR
88
+ ],
89
+ 40: [
90
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12X12_KHR,
91
+ GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR
92
+ ]
50
93
  };
51
94
 
52
95
  const PVR_SIZE_FUNCTIONS: Record<number, (width: number, height: number) => number> = {
@@ -1,4 +1,12 @@
1
- import {CompressedTextureExtractOptions, TextureLevel} from '../../types';
1
+ import type {TextureLevel} from '@loaders.gl/schema';
2
+
3
+ export type CompressedTextureExtractOptions = {
4
+ mipMapLevels: number;
5
+ width: number;
6
+ height: number;
7
+ sizeFunction: Function;
8
+ internalFormat: number;
9
+ };
2
10
 
3
11
  /**
4
12
  * Extract mipmap images from compressed texture buffer