@loaders.gl/textures 3.1.0-alpha.5 → 3.1.0-beta.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 (231) hide show
  1. package/dist/basis-loader.d.ts +1 -0
  2. package/dist/basis-loader.d.ts.map +1 -0
  3. package/dist/basis-loader.js +40 -0
  4. package/dist/basis-worker.js +675 -2
  5. package/dist/bundle.d.ts +1 -0
  6. package/dist/bundle.d.ts.map +1 -0
  7. package/dist/bundle.js +2107 -0
  8. package/dist/compressed-texture-loader.d.ts +1 -0
  9. package/dist/compressed-texture-loader.d.ts.map +1 -0
  10. package/dist/compressed-texture-loader.js +64 -0
  11. package/dist/compressed-texture-worker.js +1179 -2
  12. package/dist/compressed-texture-writer.d.ts +1 -0
  13. package/dist/compressed-texture-writer.d.ts.map +1 -0
  14. package/dist/compressed-texture-writer.js +28 -0
  15. package/dist/crunch-loader.d.ts +1 -0
  16. package/dist/crunch-loader.d.ts.map +1 -0
  17. package/dist/crunch-loader.js +25 -0
  18. package/dist/crunch-worker.js +486 -2
  19. package/dist/es5/index.js +3 -3
  20. package/dist/es5/index.js.map +1 -1
  21. package/dist/es5/lib/{gl-constants.js → gl-extensions.js} +4 -4
  22. package/dist/es5/lib/gl-extensions.js.map +1 -0
  23. package/dist/es5/lib/parsers/basis-module-loader.js +1 -1
  24. package/dist/es5/lib/parsers/basis-module-loader.js.map +1 -1
  25. package/dist/es5/lib/parsers/crunch-module-loader.js.map +1 -1
  26. package/dist/es5/lib/parsers/parse-basis.js +9 -9
  27. package/dist/es5/lib/parsers/parse-basis.js.map +1 -1
  28. package/dist/es5/lib/parsers/parse-crunch.js +4 -4
  29. package/dist/es5/lib/parsers/parse-crunch.js.map +1 -1
  30. package/dist/es5/lib/parsers/parse-dds.js +23 -23
  31. package/dist/es5/lib/parsers/parse-dds.js.map +1 -1
  32. package/dist/es5/lib/parsers/parse-ktx.js +2 -2
  33. package/dist/es5/lib/parsers/parse-ktx.js.map +1 -1
  34. package/dist/es5/lib/parsers/parse-npy.js +3 -1
  35. package/dist/es5/lib/parsers/parse-npy.js.map +1 -1
  36. package/dist/es5/lib/parsers/parse-pvr.js +28 -28
  37. package/dist/es5/lib/parsers/parse-pvr.js.map +1 -1
  38. package/dist/es5/lib/texture-api/async-deep-map.js.map +1 -1
  39. package/dist/es5/lib/texture-api/deep-load.js.map +1 -1
  40. package/dist/es5/lib/texture-api/generate-url.js +4 -12
  41. package/dist/es5/lib/texture-api/generate-url.js.map +1 -1
  42. package/dist/es5/lib/texture-api/load-image-array.js.map +1 -1
  43. package/dist/es5/lib/texture-api/load-image-cube.js.map +1 -1
  44. package/dist/es5/lib/texture-api/load-image.js +2 -5
  45. package/dist/es5/lib/texture-api/load-image.js.map +1 -1
  46. package/dist/es5/lib/texture-api/texture-api-types.js +2 -0
  47. package/dist/es5/lib/texture-api/texture-api-types.js.map +1 -0
  48. package/dist/es5/lib/utils/extract-mipmap-images.js.map +1 -1
  49. package/dist/es5/lib/utils/ktx-format-helper.js +67 -67
  50. package/dist/es5/lib/utils/ktx-format-helper.js.map +1 -1
  51. package/dist/es5/lib/utils/version.js +1 -1
  52. package/dist/es5/lib/utils/version.js.map +1 -1
  53. package/dist/es5/libs/README.md +2 -2
  54. package/dist/es5/libs/basis_encoder.js +1 -1
  55. package/dist/es5/libs/basis_transcoder.js +1 -1
  56. package/dist/es5/libs/crunch.js +1 -0
  57. package/dist/es5/npy-loader.js.map +1 -1
  58. package/dist/esm/index.js +1 -1
  59. package/dist/esm/index.js.map +1 -1
  60. package/dist/esm/lib/{gl-constants.js → gl-extensions.js} +2 -2
  61. package/dist/esm/lib/gl-extensions.js.map +1 -0
  62. package/dist/esm/lib/parsers/basis-module-loader.js +1 -1
  63. package/dist/esm/lib/parsers/basis-module-loader.js.map +1 -1
  64. package/dist/esm/lib/parsers/crunch-module-loader.js.map +1 -1
  65. package/dist/esm/lib/parsers/parse-basis.js +8 -8
  66. package/dist/esm/lib/parsers/parse-basis.js.map +1 -1
  67. package/dist/esm/lib/parsers/parse-crunch.js +4 -4
  68. package/dist/esm/lib/parsers/parse-crunch.js.map +1 -1
  69. package/dist/esm/lib/parsers/parse-dds.js +23 -23
  70. package/dist/esm/lib/parsers/parse-dds.js.map +1 -1
  71. package/dist/esm/lib/parsers/parse-ktx.js +2 -2
  72. package/dist/esm/lib/parsers/parse-ktx.js.map +1 -1
  73. package/dist/esm/lib/parsers/parse-npy.js +3 -1
  74. package/dist/esm/lib/parsers/parse-npy.js.map +1 -1
  75. package/dist/esm/lib/parsers/parse-pvr.js +28 -28
  76. package/dist/esm/lib/parsers/parse-pvr.js.map +1 -1
  77. package/dist/esm/lib/texture-api/async-deep-map.js.map +1 -1
  78. package/dist/esm/lib/texture-api/deep-load.js.map +1 -1
  79. package/dist/esm/lib/texture-api/generate-url.js +5 -13
  80. package/dist/esm/lib/texture-api/generate-url.js.map +1 -1
  81. package/dist/esm/lib/texture-api/load-image-array.js.map +1 -1
  82. package/dist/esm/lib/texture-api/load-image-cube.js.map +1 -1
  83. package/dist/esm/lib/texture-api/load-image.js +2 -5
  84. package/dist/esm/lib/texture-api/load-image.js.map +1 -1
  85. package/dist/esm/lib/texture-api/texture-api-types.js +2 -0
  86. package/dist/esm/lib/texture-api/texture-api-types.js.map +1 -0
  87. package/dist/esm/lib/utils/extract-mipmap-images.js.map +1 -1
  88. package/dist/esm/lib/utils/ktx-format-helper.js +67 -67
  89. package/dist/esm/lib/utils/ktx-format-helper.js.map +1 -1
  90. package/dist/esm/lib/utils/version.js +1 -1
  91. package/dist/esm/lib/utils/version.js.map +1 -1
  92. package/dist/esm/libs/README.md +2 -2
  93. package/dist/esm/libs/basis_encoder.js +1 -1
  94. package/dist/esm/libs/basis_transcoder.js +1 -1
  95. package/dist/esm/libs/crunch.js +1 -0
  96. package/dist/esm/npy-loader.js.map +1 -1
  97. package/dist/index.d.ts +2 -1
  98. package/dist/index.d.ts.map +1 -0
  99. package/dist/index.js +37 -0
  100. package/dist/ktx2-basis-universal-texture-writer.d.ts +1 -0
  101. package/dist/ktx2-basis-universal-texture-writer.d.ts.map +1 -0
  102. package/dist/ktx2-basis-universal-texture-writer.js +25 -0
  103. package/dist/lib/encoders/encode-ktx.d.ts +1 -0
  104. package/dist/lib/encoders/encode-ktx.d.ts.map +1 -0
  105. package/dist/lib/encoders/encode-ktx.js +10 -0
  106. package/dist/lib/encoders/encode-ktx2-basis-texture.d.ts +1 -0
  107. package/dist/lib/encoders/encode-ktx2-basis-texture.d.ts.map +1 -0
  108. package/dist/lib/encoders/encode-ktx2-basis-texture.js +41 -0
  109. package/dist/lib/encoders/encode-texture.d.ts +1 -0
  110. package/dist/lib/encoders/encode-texture.d.ts.map +1 -0
  111. package/dist/lib/encoders/encode-texture.js +30 -0
  112. package/dist/lib/{gl-constants.d.ts → gl-extensions.d.ts} +2 -1
  113. package/dist/lib/gl-extensions.d.ts.map +1 -0
  114. package/dist/lib/gl-extensions.js +72 -0
  115. package/dist/lib/parsers/basis-module-loader.d.ts +1 -0
  116. package/dist/lib/parsers/basis-module-loader.d.ts.map +1 -0
  117. package/dist/lib/parsers/basis-module-loader.js +114 -0
  118. package/dist/lib/parsers/crunch-module-loader.d.ts +1 -0
  119. package/dist/lib/parsers/crunch-module-loader.d.ts.map +1 -0
  120. package/dist/lib/parsers/crunch-module-loader.js +35 -0
  121. package/dist/lib/parsers/parse-basis.d.ts +1 -0
  122. package/dist/lib/parsers/parse-basis.d.ts.map +1 -0
  123. package/dist/lib/parsers/parse-basis.js +245 -0
  124. package/dist/lib/parsers/parse-compressed-texture.d.ts +1 -0
  125. package/dist/lib/parsers/parse-compressed-texture.d.ts.map +1 -0
  126. package/dist/lib/parsers/parse-compressed-texture.js +26 -0
  127. package/dist/lib/parsers/parse-crunch.d.ts +1 -0
  128. package/dist/lib/parsers/parse-crunch.d.ts.map +1 -0
  129. package/dist/lib/parsers/parse-crunch.js +105 -0
  130. package/dist/lib/parsers/parse-dds.d.ts +1 -0
  131. package/dist/lib/parsers/parse-dds.d.ts.map +1 -0
  132. package/dist/lib/parsers/parse-dds.js +108 -0
  133. package/dist/lib/parsers/parse-ktx.d.ts +3 -2
  134. package/dist/lib/parsers/parse-ktx.d.ts.map +1 -0
  135. package/dist/lib/parsers/parse-ktx.js +46 -0
  136. package/dist/lib/parsers/parse-npy.d.ts +8 -2
  137. package/dist/lib/parsers/parse-npy.d.ts.map +1 -0
  138. package/dist/lib/parsers/parse-npy.js +85 -0
  139. package/dist/lib/parsers/parse-pvr.d.ts +1 -0
  140. package/dist/lib/parsers/parse-pvr.d.ts.map +1 -0
  141. package/dist/lib/parsers/parse-pvr.js +250 -0
  142. package/dist/lib/texture-api/async-deep-map.d.ts +5 -2
  143. package/dist/lib/texture-api/async-deep-map.d.ts.map +1 -0
  144. package/dist/lib/texture-api/async-deep-map.js +41 -0
  145. package/dist/lib/texture-api/deep-load.d.ts +5 -2
  146. package/dist/lib/texture-api/deep-load.d.ts.map +1 -0
  147. package/dist/lib/texture-api/deep-load.js +16 -0
  148. package/dist/lib/texture-api/generate-url.d.ts +3 -1
  149. package/dist/lib/texture-api/generate-url.d.ts.map +1 -0
  150. package/dist/lib/texture-api/generate-url.js +17 -0
  151. package/dist/lib/texture-api/load-image-array.d.ts +4 -2
  152. package/dist/lib/texture-api/load-image-array.d.ts.map +1 -0
  153. package/dist/lib/texture-api/load-image-array.js +21 -0
  154. package/dist/lib/texture-api/load-image-cube.d.ts +12 -2
  155. package/dist/lib/texture-api/load-image-cube.d.ts.map +1 -0
  156. package/dist/lib/texture-api/load-image-cube.js +47 -0
  157. package/dist/lib/texture-api/load-image.d.ts +7 -5
  158. package/dist/lib/texture-api/load-image.d.ts.map +1 -0
  159. package/dist/lib/texture-api/load-image.js +43 -0
  160. package/dist/lib/texture-api/texture-api-types.d.ts +10 -0
  161. package/dist/lib/texture-api/texture-api-types.d.ts.map +1 -0
  162. package/dist/lib/texture-api/texture-api-types.js +3 -0
  163. package/dist/lib/utils/extract-mipmap-images.d.ts +2 -1
  164. package/dist/lib/utils/extract-mipmap-images.d.ts.map +1 -0
  165. package/dist/lib/utils/extract-mipmap-images.js +50 -0
  166. package/dist/lib/utils/ktx-format-helper.d.ts +4 -3
  167. package/dist/lib/utils/ktx-format-helper.d.ts.map +1 -0
  168. package/dist/lib/utils/ktx-format-helper.js +125 -0
  169. package/dist/lib/utils/texture-formats.d.ts +1 -0
  170. package/dist/lib/utils/texture-formats.d.ts.map +1 -0
  171. package/dist/lib/utils/texture-formats.js +51 -0
  172. package/dist/lib/utils/version.d.ts +1 -0
  173. package/dist/lib/utils/version.d.ts.map +1 -0
  174. package/dist/lib/utils/version.js +8 -0
  175. package/dist/libs/README.md +2 -2
  176. package/dist/libs/basis_encoder.js +1 -1
  177. package/dist/libs/basis_transcoder.js +1 -1
  178. package/dist/libs/crunch.js +1 -0
  179. package/dist/npy-loader.d.ts +7 -3
  180. package/dist/npy-loader.d.ts.map +1 -0
  181. package/dist/npy-loader.js +34 -0
  182. package/dist/npy-worker.js +240 -2
  183. package/dist/types.d.ts +1 -0
  184. package/dist/types.d.ts.map +1 -0
  185. package/dist/types.js +2 -0
  186. package/dist/workers/basis-worker.d.ts +1 -0
  187. package/dist/workers/basis-worker.d.ts.map +1 -0
  188. package/dist/workers/basis-worker.js +5 -0
  189. package/dist/workers/compressed-texture-worker.d.ts +1 -0
  190. package/dist/workers/compressed-texture-worker.d.ts.map +1 -0
  191. package/dist/workers/compressed-texture-worker.js +5 -0
  192. package/dist/workers/crunch-worker.d.ts +1 -0
  193. package/dist/workers/crunch-worker.d.ts.map +1 -0
  194. package/dist/workers/crunch-worker.js +14 -0
  195. package/dist/workers/npy-worker.d.ts +1 -0
  196. package/dist/workers/npy-worker.d.ts.map +1 -0
  197. package/dist/workers/npy-worker.js +5 -0
  198. package/package.json +10 -11
  199. package/src/index.ts +1 -1
  200. package/src/lib/{gl-constants.ts → gl-extensions.ts} +1 -1
  201. package/src/lib/parsers/crunch-module-loader.ts +1 -0
  202. package/src/lib/parsers/parse-basis.js +32 -8
  203. package/src/lib/parsers/parse-crunch.ts +4 -4
  204. package/src/lib/parsers/parse-dds.ts +29 -26
  205. package/src/lib/parsers/parse-ktx.js +3 -6
  206. package/src/lib/parsers/parse-ktx.ts +47 -0
  207. package/src/lib/parsers/parse-npy.js +3 -17
  208. package/src/lib/parsers/parse-npy.ts +98 -0
  209. package/src/lib/parsers/parse-pvr.ts +90 -48
  210. package/src/lib/texture-api/async-deep-map.ts +15 -8
  211. package/src/lib/texture-api/deep-load.ts +7 -3
  212. package/src/lib/texture-api/generate-url.ts +10 -8
  213. package/src/lib/texture-api/load-image-array.ts +8 -2
  214. package/src/lib/texture-api/load-image-cube.ts +18 -4
  215. package/src/lib/texture-api/load-image.ts +15 -5
  216. package/src/lib/texture-api/texture-api-types.ts +12 -0
  217. package/src/lib/utils/extract-mipmap-images.ts +16 -3
  218. package/src/lib/utils/ktx-format-helper.ts +71 -71
  219. package/src/libs/README.md +2 -2
  220. package/src/libs/basis_encoder.js +1 -1
  221. package/src/libs/basis_transcoder.js +1 -1
  222. package/src/libs/crunch.js +1 -0
  223. package/src/npy-loader.ts +2 -2
  224. package/dist/basis-worker.js.map +0 -1
  225. package/dist/compressed-texture-worker.js.map +0 -1
  226. package/dist/crunch-worker.js.map +0 -1
  227. package/dist/dist.min.js +0 -2
  228. package/dist/dist.min.js.map +0 -1
  229. package/dist/es5/lib/gl-constants.js.map +0 -1
  230. package/dist/esm/lib/gl-constants.js.map +0 -1
  231. package/dist/npy-worker.js.map +0 -1
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const npy_loader_1 = require("../npy-loader");
4
+ const loader_utils_1 = require("@loaders.gl/loader-utils");
5
+ (0, loader_utils_1.createLoaderWorker)(npy_loader_1.NPYLoader);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/textures",
3
- "version": "3.1.0-alpha.5",
3
+ "version": "3.1.0-beta.5",
4
4
  "description": "Framework-independent loaders for compressed and super compressed (basis) textures ",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -33,21 +33,20 @@
33
33
  ],
34
34
  "scripts": {
35
35
  "pre-build": "npm run copy-libs && npm run build-worker && npm run build-bundle",
36
- "post-build": "tsc",
37
36
  "copy-libs": "cp -rf ./src/libs ./dist/libs",
38
- "build-bundle": "webpack --display=minimal --config ../../scripts/webpack/bundle.js",
37
+ "build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/bundle.js",
39
38
  "build-worker": "npm run build-basis-worker && npm run build-npy-worker && npm run build-compressed-texture-worker && npm run build-crunch-worker",
40
- "build-basis-worker": "webpack --entry ./src/workers/basis-worker.ts --output ./dist/basis-worker.js --config ../../scripts/webpack/worker.js",
41
- "build-npy-worker": "webpack --entry ./src/workers/npy-worker.ts --output ./dist/npy-worker.js --config ../../scripts/webpack/worker.js",
42
- "build-compressed-texture-worker": "webpack --entry ./src/workers/compressed-texture-worker.ts --output ./dist/compressed-texture-worker.js --config ../../scripts/webpack/worker.js",
43
- "build-crunch-worker": "webpack --entry ./src/workers/crunch-worker.ts --output ./dist/crunch-worker.js --config ../../scripts/webpack/worker.js"
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"
44
43
  },
45
44
  "dependencies": {
46
- "@loaders.gl/images": "3.1.0-alpha.5",
47
- "@loaders.gl/loader-utils": "3.1.0-alpha.5",
48
- "@loaders.gl/worker-utils": "3.1.0-alpha.5",
45
+ "@loaders.gl/images": "3.1.0-beta.5",
46
+ "@loaders.gl/loader-utils": "3.1.0-beta.5",
47
+ "@loaders.gl/worker-utils": "3.1.0-beta.5",
49
48
  "ktx-parse": "^0.0.4",
50
49
  "texture-compressor": "^1.0.2"
51
50
  },
52
- "gitHead": "352241dd910a8c6307a235dadbe154ca915b885b"
51
+ "gitHead": "5d66468457cc878d2dbff3d7807d737ceb181c9a"
53
52
  }
package/src/index.ts CHANGED
@@ -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
 
@@ -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,
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  import {loadLibrary} from '@loaders.gl/worker-utils';
2
3
 
3
4
  /**
@@ -1,20 +1,44 @@
1
1
  import {loadBasisEncoderModule, loadBasisTrascoderModule} from './basis-module-loader';
2
- import {GL} from '../gl-constants';
3
- import {getSupportedGPUTextureFormats} from '../..';
2
+ import {GL_EXTENSIONS_CONSTANTS} from '../gl-extensions';
3
+ import {getSupportedGPUTextureFormats} from '../utils/texture-formats';
4
4
  import {isKTX} from './parse-ktx';
5
5
 
6
6
  const OutputFormat = {
7
- etc1: {basisFormat: 0, compressed: true, format: GL.COMPRESSED_RGB_ETC1_WEBGL},
7
+ etc1: {
8
+ basisFormat: 0,
9
+ compressed: true,
10
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL
11
+ },
8
12
  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},
13
+ bc1: {
14
+ basisFormat: 2,
15
+ compressed: true,
16
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT
17
+ },
18
+ bc3: {
19
+ basisFormat: 3,
20
+ compressed: true,
21
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT
22
+ },
11
23
  bc4: {basisFormat: 4, compressed: true},
12
24
  bc5: {basisFormat: 5, compressed: true},
13
25
  'bc7-m6-opaque-only': {basisFormat: 6, compressed: true},
14
26
  '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},
27
+ 'pvrtc1-4-rgb': {
28
+ basisFormat: 8,
29
+ compressed: true,
30
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG
31
+ },
32
+ 'pvrtc1-4-rgba': {
33
+ basisFormat: 9,
34
+ compressed: true,
35
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
36
+ },
37
+ 'astc-4x4': {
38
+ basisFormat: 10,
39
+ compressed: true,
40
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR
41
+ },
18
42
  'atc-rgb': {basisFormat: 11, compressed: true},
19
43
  'atc-rgba-interpolated-alpha': {basisFormat: 12, compressed: true},
20
44
  rgba32: {basisFormat: 13, compressed: false},
@@ -1,6 +1,6 @@
1
1
  import type {TextureLevel} from '../../types';
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';
@@ -20,15 +20,15 @@ const CRN_FORMAT = {
20
20
  // Mapping of Crunch formats to DXT formats.
21
21
  const DXT_FORMAT_MAP = {};
22
22
  DXT_FORMAT_MAP[CRN_FORMAT.cCRNFmtDXT1] = {
23
- pixelFormat: GL.COMPRESSED_RGB_S3TC_DXT1_EXT,
23
+ pixelFormat: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT,
24
24
  sizeFunction: getDxt1LevelSize
25
25
  };
26
26
  DXT_FORMAT_MAP[CRN_FORMAT.cCRNFmtDXT3] = {
27
- pixelFormat: GL.COMPRESSED_RGBA_S3TC_DXT3_EXT,
27
+ pixelFormat: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT,
28
28
  sizeFunction: getDxtXLevelSize
29
29
  };
30
30
  DXT_FORMAT_MAP[CRN_FORMAT.cCRNFmtDXT5] = {
31
- pixelFormat: GL.COMPRESSED_RGBA_S3TC_DXT5_EXT,
31
+ pixelFormat: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
32
32
  sizeFunction: getDxtXLevelSize
33
33
  };
34
34
 
@@ -1,11 +1,8 @@
1
1
  import type {TextureLevel} from '../../types';
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
- const getATCLevelSize = getDxt1LevelSize;
7
- const getATCALevelSize = getDxtXLevelSize;
8
- const getATCILevelSize = getDxtXLevelSize;
9
6
  const DDS_CONSTANTS = {
10
7
  MAGIC_NUMBER: 0x20534444,
11
8
  HEADER_LENGTH: 31,
@@ -18,23 +15,29 @@ const DDS_CONSTANTS = {
18
15
  HEADER_PF_FLAGS_INDEX: 20,
19
16
  HEADER_PF_FOURCC_INDEX: 21,
20
17
  DDSD_MIPMAPCOUNT: 0x20000,
21
- DDPF_FOURCC: 0x4,
22
- PIXEL_FORMATS: {
23
- DXT1: GL.COMPRESSED_RGB_S3TC_DXT1_EXT,
24
- DXT3: GL.COMPRESSED_RGBA_S3TC_DXT3_EXT,
25
- DXT5: GL.COMPRESSED_RGBA_S3TC_DXT5_EXT,
26
- 'ATC ': GL.COMPRESSED_RGB_ATC_WEBGL,
27
- ATCA: GL.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL,
28
- ATCI: GL.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL
29
- },
30
- SIZE_FUNCTIONS: {
31
- DXT1: getDxt1LevelSize,
32
- DXT3: getDxtXLevelSize,
33
- DXT5: getDxtXLevelSize,
34
- 'ATC ': getATCLevelSize,
35
- ATCA: getATCALevelSize,
36
- ATCI: getATCILevelSize
37
- }
18
+ DDPF_FOURCC: 0x4
19
+ };
20
+
21
+ const DDS_PIXEL_FORMATS: Record<string, number> = {
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
+ };
29
+
30
+ const getATCLevelSize = getDxt1LevelSize;
31
+ const getATCALevelSize = getDxtXLevelSize;
32
+ const getATCILevelSize = getDxtXLevelSize;
33
+
34
+ const DDS_SIZE_FUNCTIONS: Record<string, (width: number, height: number) => number> = {
35
+ DXT1: getDxt1LevelSize,
36
+ DXT3: getDxtXLevelSize,
37
+ DXT5: getDxtXLevelSize,
38
+ 'ATC ': getATCLevelSize,
39
+ ATCA: getATCALevelSize,
40
+ ATCI: getATCILevelSize
38
41
  };
39
42
 
40
43
  /**
@@ -61,8 +64,8 @@ export function parseDDS(data: ArrayBuffer): TextureLevel[] {
61
64
  'DDS: Unsupported format, must contain a FourCC code'
62
65
  );
63
66
  const fourCC = int32ToFourCC(pixelFormatNumber);
64
- const internalFormat = DDS_CONSTANTS.PIXEL_FORMATS[fourCC];
65
- const sizeFunction = DDS_CONSTANTS.SIZE_FUNCTIONS[fourCC];
67
+ const internalFormat = DDS_PIXEL_FORMATS[fourCC];
68
+ const sizeFunction = DDS_SIZE_FUNCTIONS[fourCC];
66
69
  assert(internalFormat && sizeFunction, `DDS: Unknown pixel format ${pixelFormatNumber}`);
67
70
 
68
71
  let mipMapLevels = 1;
@@ -105,10 +108,10 @@ export function getDxtXLevelSize(width: number, height: number): number {
105
108
 
106
109
  /**
107
110
  * Convert every byte of Int32 value to char
108
- * @param {number} value - Int32 number
109
- * @returns {string} string of 4 characters
111
+ * @param value - Int32 number
112
+ * @returns string of 4 characters
110
113
  */
111
- function int32ToFourCC(value) {
114
+ function int32ToFourCC(value: number): string {
112
115
  return String.fromCharCode(
113
116
  value & 0xff,
114
117
  (value >> 8) & 0xff,
@@ -1,16 +1,16 @@
1
1
  import {read} from 'ktx-parse';
2
2
  import {extractMipmapImages} from '../utils/extract-mipmap-images';
3
3
  import {mapVkFormatToWebGL} from '../utils/ktx-format-helper';
4
-
5
4
  const KTX2_ID = [
6
5
  // '´', 'K', 'T', 'X', '2', '0', 'ª', '\r', '\n', '\x1A', '\n'
7
6
  0xab, 0x4b, 0x54, 0x58, 0x20, 0x32, 0x30, 0xbb, 0x0d, 0x0a, 0x1a, 0x0a
8
7
  ];
9
-
10
8
  // eslint-disable-next-line complexity
11
9
  export function isKTX(data) {
12
- const id = new Uint8Array(data.buffer || data, data.byteOffset || 0, KTX2_ID.length);
10
+ // const id = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
11
+ const id = new Uint8Array(data);
13
12
  const notKTX =
13
+ id.byteLength < KTX2_ID.length ||
14
14
  id[0] !== KTX2_ID[0] || // '´'
15
15
  id[1] !== KTX2_ID[1] || // 'K'
16
16
  id[2] !== KTX2_ID[2] || // 'T'
@@ -23,10 +23,8 @@ export function isKTX(data) {
23
23
  id[9] !== KTX2_ID[9] || // '\n'
24
24
  id[10] !== KTX2_ID[10] || // '\x1A'
25
25
  id[11] !== KTX2_ID[11]; // '\n'
26
-
27
26
  return !notKTX;
28
27
  }
29
-
30
28
  export function parseKTX(arrayBuffer) {
31
29
  const uint8Array = new Uint8Array(arrayBuffer);
32
30
  const ktx = read(uint8Array);
@@ -34,7 +32,6 @@ export function parseKTX(arrayBuffer) {
34
32
  const width = ktx.pixelWidth;
35
33
  const height = ktx.pixelHeight;
36
34
  const internalFormat = mapVkFormatToWebGL(ktx.vkFormat);
37
-
38
35
  return extractMipmapImages(ktx.levels, {
39
36
  mipMapLevels,
40
37
  width,
@@ -0,0 +1,47 @@
1
+ import {read} from 'ktx-parse';
2
+ import {extractMipmapImages} from '../utils/extract-mipmap-images';
3
+ import {mapVkFormatToWebGL} from '../utils/ktx-format-helper';
4
+
5
+ const KTX2_ID = [
6
+ // '´', 'K', 'T', 'X', '2', '0', 'ª', '\r', '\n', '\x1A', '\n'
7
+ 0xab, 0x4b, 0x54, 0x58, 0x20, 0x32, 0x30, 0xbb, 0x0d, 0x0a, 0x1a, 0x0a
8
+ ];
9
+
10
+ // eslint-disable-next-line complexity
11
+ export function isKTX(data: ArrayBuffer) {
12
+ // const id = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
13
+ const id = new Uint8Array(data);
14
+ const notKTX =
15
+ 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
+
29
+ return !notKTX;
30
+ }
31
+
32
+ export function parseKTX(arrayBuffer: ArrayBuffer) {
33
+ const uint8Array = new Uint8Array(arrayBuffer);
34
+ const ktx = read(uint8Array);
35
+ const mipMapLevels = Math.max(1, ktx.levels.length);
36
+ const width = ktx.pixelWidth;
37
+ const height = ktx.pixelHeight;
38
+ const internalFormat = mapVkFormatToWebGL(ktx.vkFormat);
39
+
40
+ return extractMipmapImages(ktx.levels, {
41
+ mipMapLevels,
42
+ width,
43
+ height,
44
+ sizeFunction: (level: any): number => level.uncompressedByteLength,
45
+ internalFormat
46
+ });
47
+ }
@@ -3,9 +3,7 @@ function systemIsLittleEndian() {
3
3
  const b = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
4
4
  return !(b[0] === 0x12);
5
5
  }
6
-
7
6
  const LITTLE_ENDIAN_OS = systemIsLittleEndian();
8
-
9
7
  // The basic string format consists of 3 characters:
10
8
  // 1. a character describing the byteorder of the data (<: little-endian, >: big-endian, |: not-relevant)
11
9
  // 2. a character code giving the basic type of the array
@@ -24,15 +22,12 @@ const DTYPES = {
24
22
  f4: Float32Array,
25
23
  f8: Float64Array
26
24
  };
27
-
28
25
  export function parseNPY(arrayBuffer, options) {
29
26
  if (!arrayBuffer) {
30
27
  return null;
31
28
  }
32
-
33
29
  const view = new DataView(arrayBuffer);
34
30
  const {header, headerEndOffset} = parseHeader(view);
35
-
36
31
  const numpyType = header.descr;
37
32
  const ArrayType = DTYPES[numpyType.slice(1, 3)];
38
33
  if (!ArrayType) {
@@ -40,34 +35,28 @@ export function parseNPY(arrayBuffer, options) {
40
35
  console.warn(`Decoding of npy dtype not implemented: ${numpyType}`);
41
36
  return null;
42
37
  }
43
-
44
- const nArrayElements = header.shape.reduce((a, b) => a * b);
38
+ const nArrayElements = header.shape?.reduce((a, b) => a * b);
45
39
  const arrayByteLength = nArrayElements * ArrayType.BYTES_PER_ELEMENT;
46
-
47
40
  const data = new ArrayType(arrayBuffer.slice(headerEndOffset, headerEndOffset + arrayByteLength));
48
-
49
41
  // Swap endianness if needed
50
42
  if ((numpyType[0] === '>' && LITTLE_ENDIAN_OS) || (numpyType[0] === '<' && !LITTLE_ENDIAN_OS)) {
51
43
  // eslint-disable-next-line no-console, no-undef
52
44
  console.warn('Data is wrong endianness, byte swapping not yet implemented.');
53
45
  }
54
-
55
46
  return {
56
47
  data,
57
48
  header
58
49
  };
59
50
  }
60
-
61
51
  /**
62
52
  * Parse NPY header
63
53
  *
64
- * @param {DataView} view
65
- * @return {Object}
54
+ * @param view
55
+ * @return
66
56
  */
67
57
  function parseHeader(view) {
68
58
  const majorVersion = view.getUint8(6);
69
59
  // const minorVersion = view.getUint8(7);
70
-
71
60
  let offset = 8;
72
61
  let headerLength;
73
62
  if (majorVersion >= 2) {
@@ -77,13 +66,11 @@ function parseHeader(view) {
77
66
  headerLength = view.getUint16(8, true);
78
67
  offset += 2;
79
68
  }
80
-
81
69
  const encoding = majorVersion <= 2 ? 'latin1' : 'utf-8';
82
70
  const decoder = new TextDecoder(encoding);
83
71
  const headerArray = new Uint8Array(view.buffer, offset, headerLength);
84
72
  const headerText = decoder.decode(headerArray);
85
73
  offset += headerLength;
86
-
87
74
  const header = JSON.parse(
88
75
  headerText
89
76
  .replace(/'/g, '"')
@@ -91,6 +78,5 @@ function parseHeader(view) {
91
78
  .replace('(', '[')
92
79
  .replace(/,*\),*/g, ']')
93
80
  );
94
-
95
81
  return {header, headerEndOffset: offset};
96
82
  }
@@ -0,0 +1,98 @@
1
+ type NumpyHeader = {descr: string; shape: number[]};
2
+
3
+ function systemIsLittleEndian() {
4
+ const a = new Uint32Array([0x12345678]);
5
+ const b = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
6
+ return !(b[0] === 0x12);
7
+ }
8
+
9
+ const LITTLE_ENDIAN_OS = systemIsLittleEndian();
10
+
11
+ // The basic string format consists of 3 characters:
12
+ // 1. a character describing the byteorder of the data (<: little-endian, >: big-endian, |: not-relevant)
13
+ // 2. a character code giving the basic type of the array
14
+ // 3. an integer providing the number of bytes the type uses.
15
+ // https://numpy.org/doc/stable/reference/arrays.interface.html
16
+ //
17
+ // Here I only include the second and third characters, and check endianness
18
+ // separately
19
+ const DTYPES: Record<string, any> = {
20
+ u1: Uint8Array,
21
+ i1: Int8Array,
22
+ u2: Uint16Array,
23
+ i2: Int16Array,
24
+ u4: Uint32Array,
25
+ i4: Int32Array,
26
+ f4: Float32Array,
27
+ f8: Float64Array
28
+ };
29
+
30
+ export function parseNPY(arrayBuffer: ArrayBuffer, options?: unknown) {
31
+ if (!arrayBuffer) {
32
+ return null;
33
+ }
34
+
35
+ const view = new DataView(arrayBuffer);
36
+ const {header, headerEndOffset} = parseHeader(view);
37
+
38
+ const numpyType = header.descr;
39
+ const ArrayType = DTYPES[numpyType.slice(1, 3)];
40
+ if (!ArrayType) {
41
+ // eslint-disable-next-line no-console, no-undef
42
+ console.warn(`Decoding of npy dtype not implemented: ${numpyType}`);
43
+ return null;
44
+ }
45
+
46
+ const nArrayElements = header.shape?.reduce((a: number, b: number): number => a * b);
47
+ const arrayByteLength = nArrayElements * ArrayType.BYTES_PER_ELEMENT;
48
+
49
+ const data = new ArrayType(arrayBuffer.slice(headerEndOffset, headerEndOffset + arrayByteLength));
50
+
51
+ // Swap endianness if needed
52
+ if ((numpyType[0] === '>' && LITTLE_ENDIAN_OS) || (numpyType[0] === '<' && !LITTLE_ENDIAN_OS)) {
53
+ // eslint-disable-next-line no-console, no-undef
54
+ console.warn('Data is wrong endianness, byte swapping not yet implemented.');
55
+ }
56
+
57
+ return {
58
+ data,
59
+ header
60
+ };
61
+ }
62
+
63
+ /**
64
+ * Parse NPY header
65
+ *
66
+ * @param view
67
+ * @return
68
+ */
69
+ function parseHeader(view: DataView): {header: NumpyHeader; headerEndOffset: number} {
70
+ const majorVersion = view.getUint8(6);
71
+ // const minorVersion = view.getUint8(7);
72
+
73
+ let offset = 8;
74
+ let headerLength;
75
+ if (majorVersion >= 2) {
76
+ headerLength = view.getUint32(8, true);
77
+ offset += 4;
78
+ } else {
79
+ headerLength = view.getUint16(8, true);
80
+ offset += 2;
81
+ }
82
+
83
+ const encoding = majorVersion <= 2 ? 'latin1' : 'utf-8';
84
+ const decoder = new TextDecoder(encoding);
85
+ const headerArray = new Uint8Array(view.buffer, offset, headerLength);
86
+ const headerText = decoder.decode(headerArray);
87
+ offset += headerLength;
88
+
89
+ const header = JSON.parse(
90
+ headerText
91
+ .replace(/'/g, '"')
92
+ .replace('False', 'false')
93
+ .replace('(', '[')
94
+ .replace(/,*\),*/g, ']')
95
+ );
96
+
97
+ return {header, headerEndOffset: offset};
98
+ }