@loaders.gl/textures 3.1.0-alpha.4 → 3.1.0-beta.3

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 (271) 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-loader.js +40 -0
  4. package/dist/basis-worker.js +675 -2
  5. package/dist/bundle.d.ts +2 -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 +63 -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 +25 -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 +21 -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/basis-loader.js +5 -13
  20. package/dist/es5/basis-loader.js.map +1 -1
  21. package/dist/es5/bundle.js +1 -1
  22. package/dist/es5/bundle.js.map +1 -1
  23. package/dist/es5/compressed-texture-loader.js +20 -59
  24. package/dist/es5/compressed-texture-loader.js.map +1 -1
  25. package/dist/es5/compressed-texture-writer.js +2 -2
  26. package/dist/es5/compressed-texture-writer.js.map +1 -1
  27. package/dist/es5/crunch-loader.js +2 -2
  28. package/dist/es5/crunch-loader.js.map +1 -1
  29. package/dist/es5/index.js +26 -18
  30. package/dist/es5/index.js.map +1 -1
  31. package/dist/es5/ktx2-basis-universal-texture-writer.js +29 -0
  32. package/dist/es5/ktx2-basis-universal-texture-writer.js.map +1 -0
  33. package/dist/es5/lib/encoders/encode-ktx.js +1 -1
  34. package/dist/es5/lib/encoders/encode-ktx.js.map +1 -1
  35. package/dist/es5/lib/encoders/encode-ktx2-basis-texture.js +43 -0
  36. package/dist/es5/lib/encoders/encode-ktx2-basis-texture.js.map +1 -0
  37. package/dist/es5/lib/encoders/encode-texture.js +13 -41
  38. package/dist/es5/lib/encoders/encode-texture.js.map +1 -1
  39. package/dist/es5/lib/{gl-constants.js → gl-extensions.js} +4 -4
  40. package/dist/es5/lib/gl-extensions.js.map +1 -0
  41. package/dist/es5/lib/parsers/basis-module-loader.js +51 -190
  42. package/dist/es5/lib/parsers/basis-module-loader.js.map +1 -1
  43. package/dist/es5/lib/parsers/crunch-module-loader.js +15 -71
  44. package/dist/es5/lib/parsers/crunch-module-loader.js.map +1 -1
  45. package/dist/es5/lib/parsers/parse-basis.js +86 -138
  46. package/dist/es5/lib/parsers/parse-basis.js.map +1 -1
  47. package/dist/es5/lib/parsers/parse-crunch.js +59 -80
  48. package/dist/es5/lib/parsers/parse-crunch.js.map +1 -1
  49. package/dist/es5/lib/parsers/parse-dds.js +39 -39
  50. package/dist/es5/lib/parsers/parse-dds.js.map +1 -1
  51. package/dist/es5/lib/parsers/parse-ktx.js +14 -16
  52. package/dist/es5/lib/parsers/parse-ktx.js.map +1 -1
  53. package/dist/es5/lib/parsers/parse-npy.js +27 -28
  54. package/dist/es5/lib/parsers/parse-npy.js.map +1 -1
  55. package/dist/es5/lib/parsers/parse-pvr.js +49 -49
  56. package/dist/es5/lib/parsers/parse-pvr.js.map +1 -1
  57. package/dist/es5/lib/texture-api/async-deep-map.js +27 -156
  58. package/dist/es5/lib/texture-api/async-deep-map.js.map +1 -1
  59. package/dist/es5/lib/texture-api/deep-load.js +6 -67
  60. package/dist/es5/lib/texture-api/deep-load.js.map +1 -1
  61. package/dist/es5/lib/texture-api/generate-url.js +4 -16
  62. package/dist/es5/lib/texture-api/generate-url.js.map +1 -1
  63. package/dist/es5/lib/texture-api/load-image-array.js +12 -76
  64. package/dist/es5/lib/texture-api/load-image-array.js.map +1 -1
  65. package/dist/es5/lib/texture-api/load-image-cube.js +27 -96
  66. package/dist/es5/lib/texture-api/load-image-cube.js.map +1 -1
  67. package/dist/es5/lib/texture-api/load-image.js +37 -146
  68. package/dist/es5/lib/texture-api/load-image.js.map +1 -1
  69. package/dist/es5/lib/texture-api/texture-api-types.js +2 -0
  70. package/dist/es5/lib/texture-api/texture-api-types.js.map +1 -0
  71. package/dist/es5/lib/utils/extract-mipmap-images.js +9 -9
  72. package/dist/es5/lib/utils/extract-mipmap-images.js.map +1 -1
  73. package/dist/es5/lib/utils/ktx-format-helper.js +68 -68
  74. package/dist/es5/lib/utils/ktx-format-helper.js.map +1 -1
  75. package/dist/es5/lib/utils/texture-formats.js +9 -27
  76. package/dist/es5/lib/utils/texture-formats.js.map +1 -1
  77. package/dist/es5/lib/utils/version.js +1 -1
  78. package/dist/es5/lib/utils/version.js.map +1 -1
  79. package/dist/es5/libs/README.md +2 -2
  80. package/dist/es5/libs/basis_encoder.js +1 -1
  81. package/dist/es5/libs/basis_transcoder.js +1 -1
  82. package/dist/es5/libs/crunch.js +1 -0
  83. package/dist/es5/npy-loader.js +7 -42
  84. package/dist/es5/npy-loader.js.map +1 -1
  85. package/dist/es5/workers/crunch-worker.js +2 -11
  86. package/dist/es5/workers/crunch-worker.js.map +1 -1
  87. package/dist/esm/index.js +2 -1
  88. package/dist/esm/index.js.map +1 -1
  89. package/dist/esm/ktx2-basis-universal-texture-writer.js +18 -0
  90. package/dist/esm/ktx2-basis-universal-texture-writer.js.map +1 -0
  91. package/dist/esm/lib/encoders/encode-ktx2-basis-texture.js +35 -0
  92. package/dist/esm/lib/encoders/encode-ktx2-basis-texture.js.map +1 -0
  93. package/dist/esm/lib/encoders/encode-texture.js +1 -1
  94. package/dist/esm/lib/encoders/encode-texture.js.map +1 -1
  95. package/dist/esm/lib/{gl-constants.js → gl-extensions.js} +2 -2
  96. package/dist/esm/lib/gl-extensions.js.map +1 -0
  97. package/dist/esm/lib/parsers/basis-module-loader.js +8 -3
  98. package/dist/esm/lib/parsers/basis-module-loader.js.map +1 -1
  99. package/dist/esm/lib/parsers/crunch-module-loader.js.map +1 -1
  100. package/dist/esm/lib/parsers/parse-basis.js +8 -8
  101. package/dist/esm/lib/parsers/parse-basis.js.map +1 -1
  102. package/dist/esm/lib/parsers/parse-crunch.js +4 -4
  103. package/dist/esm/lib/parsers/parse-crunch.js.map +1 -1
  104. package/dist/esm/lib/parsers/parse-dds.js +24 -24
  105. package/dist/esm/lib/parsers/parse-dds.js.map +1 -1
  106. package/dist/esm/lib/parsers/parse-ktx.js +2 -2
  107. package/dist/esm/lib/parsers/parse-ktx.js.map +1 -1
  108. package/dist/esm/lib/parsers/parse-npy.js +4 -2
  109. package/dist/esm/lib/parsers/parse-npy.js.map +1 -1
  110. package/dist/esm/lib/parsers/parse-pvr.js +28 -28
  111. package/dist/esm/lib/parsers/parse-pvr.js.map +1 -1
  112. package/dist/esm/lib/texture-api/async-deep-map.js.map +1 -1
  113. package/dist/esm/lib/texture-api/deep-load.js.map +1 -1
  114. package/dist/esm/lib/texture-api/generate-url.js +6 -14
  115. package/dist/esm/lib/texture-api/generate-url.js.map +1 -1
  116. package/dist/esm/lib/texture-api/load-image-array.js.map +1 -1
  117. package/dist/esm/lib/texture-api/load-image-cube.js.map +1 -1
  118. package/dist/esm/lib/texture-api/load-image.js +2 -5
  119. package/dist/esm/lib/texture-api/load-image.js.map +1 -1
  120. package/dist/esm/lib/texture-api/texture-api-types.js +2 -0
  121. package/dist/esm/lib/texture-api/texture-api-types.js.map +1 -0
  122. package/dist/esm/lib/utils/extract-mipmap-images.js.map +1 -1
  123. package/dist/esm/lib/utils/ktx-format-helper.js +67 -67
  124. package/dist/esm/lib/utils/ktx-format-helper.js.map +1 -1
  125. package/dist/esm/lib/utils/texture-formats.js +1 -1
  126. package/dist/esm/lib/utils/texture-formats.js.map +1 -1
  127. package/dist/esm/lib/utils/version.js +1 -1
  128. package/dist/esm/lib/utils/version.js.map +1 -1
  129. package/dist/esm/libs/README.md +2 -2
  130. package/dist/esm/libs/basis_encoder.js +1 -1
  131. package/dist/esm/libs/basis_transcoder.js +1 -1
  132. package/dist/esm/libs/crunch.js +1 -0
  133. package/dist/esm/npy-loader.js.map +1 -1
  134. package/dist/index.d.ts +16 -0
  135. package/dist/index.d.ts.map +1 -0
  136. package/dist/index.js +37 -0
  137. package/dist/ktx2-basis-universal-texture-writer.d.ts +22 -0
  138. package/dist/ktx2-basis-universal-texture-writer.d.ts.map +1 -0
  139. package/dist/ktx2-basis-universal-texture-writer.js +25 -0
  140. package/dist/lib/encoders/encode-ktx.d.ts +2 -0
  141. package/dist/lib/encoders/encode-ktx.d.ts.map +1 -0
  142. package/dist/lib/encoders/encode-ktx.js +10 -0
  143. package/dist/lib/encoders/encode-ktx2-basis-texture.d.ts +10 -0
  144. package/dist/lib/encoders/encode-ktx2-basis-texture.d.ts.map +1 -0
  145. package/dist/lib/encoders/encode-ktx2-basis-texture.js +41 -0
  146. package/dist/lib/encoders/encode-texture.d.ts +2 -0
  147. package/dist/lib/encoders/encode-texture.d.ts.map +1 -0
  148. package/dist/lib/encoders/encode-texture.js +30 -0
  149. package/dist/lib/gl-extensions.d.ts +61 -0
  150. package/dist/lib/gl-extensions.d.ts.map +1 -0
  151. package/dist/lib/gl-extensions.js +72 -0
  152. package/dist/lib/parsers/basis-module-loader.d.ts +13 -0
  153. package/dist/lib/parsers/basis-module-loader.d.ts.map +1 -0
  154. package/dist/lib/parsers/basis-module-loader.js +114 -0
  155. package/dist/lib/parsers/crunch-module-loader.d.ts +7 -0
  156. package/dist/lib/parsers/crunch-module-loader.d.ts.map +1 -0
  157. package/dist/lib/parsers/crunch-module-loader.js +35 -0
  158. package/dist/lib/parsers/parse-basis.d.ts +30 -0
  159. package/dist/lib/parsers/parse-basis.d.ts.map +1 -0
  160. package/dist/lib/parsers/parse-basis.js +245 -0
  161. package/dist/lib/parsers/parse-compressed-texture.d.ts +8 -0
  162. package/dist/lib/parsers/parse-compressed-texture.d.ts.map +1 -0
  163. package/dist/lib/parsers/parse-compressed-texture.js +26 -0
  164. package/dist/lib/parsers/parse-crunch.d.ts +9 -0
  165. package/dist/lib/parsers/parse-crunch.d.ts.map +1 -0
  166. package/dist/lib/parsers/parse-crunch.js +105 -0
  167. package/dist/lib/parsers/parse-dds.d.ts +28 -0
  168. package/dist/lib/parsers/parse-dds.d.ts.map +1 -0
  169. package/dist/lib/parsers/parse-dds.js +108 -0
  170. package/dist/lib/parsers/parse-ktx.d.ts +3 -0
  171. package/dist/lib/parsers/parse-ktx.d.ts.map +1 -0
  172. package/dist/lib/parsers/parse-ktx.js +46 -0
  173. package/dist/lib/parsers/parse-npy.d.ts +10 -0
  174. package/dist/lib/parsers/parse-npy.d.ts.map +1 -0
  175. package/dist/lib/parsers/parse-npy.js +85 -0
  176. package/dist/lib/parsers/parse-pvr.d.ts +15 -0
  177. package/dist/lib/parsers/parse-pvr.d.ts.map +1 -0
  178. package/dist/lib/parsers/parse-pvr.js +250 -0
  179. package/dist/lib/texture-api/async-deep-map.d.ts +5 -0
  180. package/dist/lib/texture-api/async-deep-map.d.ts.map +1 -0
  181. package/dist/lib/texture-api/async-deep-map.js +41 -0
  182. package/dist/lib/texture-api/deep-load.d.ts +5 -0
  183. package/dist/lib/texture-api/deep-load.d.ts.map +1 -0
  184. package/dist/lib/texture-api/deep-load.js +16 -0
  185. package/dist/lib/texture-api/generate-url.d.ts +3 -0
  186. package/dist/lib/texture-api/generate-url.d.ts.map +1 -0
  187. package/dist/lib/texture-api/generate-url.js +17 -0
  188. package/dist/lib/texture-api/load-image-array.d.ts +4 -0
  189. package/dist/lib/texture-api/load-image-array.d.ts.map +1 -0
  190. package/dist/lib/texture-api/load-image-array.js +21 -0
  191. package/dist/lib/texture-api/load-image-cube.d.ts +12 -0
  192. package/dist/lib/texture-api/load-image-cube.d.ts.map +1 -0
  193. package/dist/lib/texture-api/load-image-cube.js +47 -0
  194. package/dist/lib/texture-api/load-image.d.ts +8 -0
  195. package/dist/lib/texture-api/load-image.d.ts.map +1 -0
  196. package/dist/lib/texture-api/load-image.js +43 -0
  197. package/dist/lib/texture-api/texture-api-types.d.ts +10 -0
  198. package/dist/lib/texture-api/texture-api-types.d.ts.map +1 -0
  199. package/dist/lib/texture-api/texture-api-types.js +3 -0
  200. package/dist/lib/utils/extract-mipmap-images.d.ts +13 -0
  201. package/dist/lib/utils/extract-mipmap-images.d.ts.map +1 -0
  202. package/dist/lib/utils/extract-mipmap-images.js +50 -0
  203. package/dist/lib/utils/ktx-format-helper.d.ts +9 -0
  204. package/dist/lib/utils/ktx-format-helper.d.ts.map +1 -0
  205. package/dist/lib/utils/ktx-format-helper.js +125 -0
  206. package/dist/lib/utils/texture-formats.d.ts +8 -0
  207. package/dist/lib/utils/texture-formats.d.ts.map +1 -0
  208. package/dist/lib/utils/texture-formats.js +51 -0
  209. package/dist/lib/utils/version.d.ts +2 -0
  210. package/dist/lib/utils/version.d.ts.map +1 -0
  211. package/dist/lib/utils/version.js +8 -0
  212. package/dist/libs/README.md +2 -2
  213. package/dist/libs/basis_encoder.js +1 -1
  214. package/dist/libs/basis_transcoder.js +1 -1
  215. package/dist/libs/crunch.js +1 -0
  216. package/dist/npy-loader.d.ts +45 -0
  217. package/dist/npy-loader.d.ts.map +1 -0
  218. package/dist/npy-loader.js +34 -0
  219. package/dist/npy-worker.js +240 -2
  220. package/dist/types.d.ts +21 -0
  221. package/dist/types.d.ts.map +1 -0
  222. package/dist/types.js +2 -0
  223. package/dist/workers/basis-worker.d.ts +2 -0
  224. package/dist/workers/basis-worker.d.ts.map +1 -0
  225. package/dist/workers/basis-worker.js +5 -0
  226. package/dist/workers/compressed-texture-worker.d.ts +2 -0
  227. package/dist/workers/compressed-texture-worker.d.ts.map +1 -0
  228. package/dist/workers/compressed-texture-worker.js +5 -0
  229. package/dist/workers/crunch-worker.d.ts +21 -0
  230. package/dist/workers/crunch-worker.d.ts.map +1 -0
  231. package/dist/workers/crunch-worker.js +14 -0
  232. package/dist/workers/npy-worker.d.ts +2 -0
  233. package/dist/workers/npy-worker.d.ts.map +1 -0
  234. package/dist/workers/npy-worker.js +5 -0
  235. package/package.json +11 -11
  236. package/src/index.ts +2 -1
  237. package/src/ktx2-basis-universal-texture-writer.ts +27 -0
  238. package/src/lib/encoders/encode-ktx2-basis-texture.ts +44 -0
  239. package/src/lib/{gl-constants.ts → gl-extensions.ts} +1 -1
  240. package/src/lib/parsers/basis-module-loader.ts +12 -4
  241. package/src/lib/parsers/crunch-module-loader.ts +1 -0
  242. package/src/lib/parsers/parse-basis.js +32 -8
  243. package/src/lib/parsers/parse-crunch.ts +4 -4
  244. package/src/lib/parsers/parse-dds.ts +29 -26
  245. package/src/lib/parsers/parse-ktx.js +3 -6
  246. package/src/lib/parsers/parse-ktx.ts +47 -0
  247. package/src/lib/parsers/parse-npy.js +3 -17
  248. package/src/lib/parsers/parse-npy.ts +98 -0
  249. package/src/lib/parsers/parse-pvr.ts +90 -48
  250. package/src/lib/texture-api/async-deep-map.ts +15 -8
  251. package/src/lib/texture-api/deep-load.ts +7 -3
  252. package/src/lib/texture-api/generate-url.ts +10 -8
  253. package/src/lib/texture-api/load-image-array.ts +8 -2
  254. package/src/lib/texture-api/load-image-cube.ts +18 -4
  255. package/src/lib/texture-api/load-image.ts +15 -5
  256. package/src/lib/texture-api/texture-api-types.ts +12 -0
  257. package/src/lib/utils/extract-mipmap-images.ts +16 -3
  258. package/src/lib/utils/ktx-format-helper.ts +71 -71
  259. package/src/libs/README.md +2 -2
  260. package/src/libs/basis_encoder.js +1 -1
  261. package/src/libs/basis_transcoder.js +1 -1
  262. package/src/libs/crunch.js +1 -0
  263. package/src/npy-loader.ts +2 -2
  264. package/dist/basis-worker.js.map +0 -1
  265. package/dist/compressed-texture-worker.js.map +0 -1
  266. package/dist/crunch-worker.js.map +0 -1
  267. package/dist/dist.min.js +0 -2
  268. package/dist/dist.min.js.map +0 -1
  269. package/dist/es5/lib/gl-constants.js.map +0 -1
  270. package/dist/esm/lib/gl-constants.js.map +0 -1
  271. package/dist/npy-worker.js.map +0 -1
@@ -0,0 +1,105 @@
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
+ DXT_FORMAT_MAP[CRN_FORMAT.cCRNFmtDXT1] = {
21
+ pixelFormat: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT,
22
+ sizeFunction: parse_dds_1.getDxt1LevelSize
23
+ };
24
+ DXT_FORMAT_MAP[CRN_FORMAT.cCRNFmtDXT3] = {
25
+ pixelFormat: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT,
26
+ sizeFunction: parse_dds_1.getDxtXLevelSize
27
+ };
28
+ DXT_FORMAT_MAP[CRN_FORMAT.cCRNFmtDXT5] = {
29
+ pixelFormat: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
30
+ sizeFunction: parse_dds_1.getDxtXLevelSize
31
+ };
32
+ let cachedDstSize = 0;
33
+ let dst;
34
+ /**
35
+ * Parse texture data as "CRN" format.
36
+ * Function is "async" as emscriptified decoder module is loaded asyncronously
37
+ * @param data - binary data of compressed texture
38
+ * @returns Promise of Array of the texture levels
39
+ */
40
+ async function parseCrunch(data, options) {
41
+ const crunchModule = await (0, crunch_module_loader_1.loadCrunchModule)(options);
42
+ // Copy the contents of the arrayBuffer into emscriptens heap.
43
+ const srcSize = data.byteLength;
44
+ const bytes = new Uint8Array(data);
45
+ const src = crunchModule._malloc(srcSize);
46
+ arrayBufferCopy(bytes, crunchModule.HEAPU8, src, srcSize);
47
+ // Determine what type of compressed data the file contains.
48
+ const format = crunchModule._crn_get_dxt_format(src, srcSize);
49
+ (0, loader_utils_1.assert)(Boolean(DXT_FORMAT_MAP[format]), 'Unsupported format');
50
+ // Gather basic metrics about the DXT data.
51
+ const mipMapLevels = crunchModule._crn_get_levels(src, srcSize);
52
+ const width = crunchModule._crn_get_width(src, srcSize);
53
+ const height = crunchModule._crn_get_height(src, srcSize);
54
+ // const bytesPerBlock = crunchModule._crn_get_bytes_per_block(src, srcSize);
55
+ // Determine the size of the decoded DXT data.
56
+ const sizeFunction = DXT_FORMAT_MAP[format].sizeFunction;
57
+ let dstSize = 0;
58
+ for (let i = 0; i < mipMapLevels; ++i) {
59
+ dstSize += sizeFunction(width >> i, height >> i);
60
+ }
61
+ // Allocate enough space on the emscripten heap to hold the decoded DXT data
62
+ // or reuse the existing allocation if a previous call to this function has
63
+ // already acquired a large enough buffer.
64
+ if (cachedDstSize < dstSize) {
65
+ if (dst) {
66
+ crunchModule._free(dst);
67
+ }
68
+ dst = crunchModule._malloc(dstSize);
69
+ cachedDstSize = dstSize;
70
+ }
71
+ // Decompress the DXT data from the Crunch file into the allocated space.
72
+ crunchModule._crn_decompress(src, srcSize, dst, dstSize, 0, mipMapLevels);
73
+ // Release the crunch file data from the emscripten heap.
74
+ crunchModule._free(src);
75
+ const image = new Uint8Array(crunchModule.HEAPU8.buffer, dst, dstSize).slice();
76
+ return (0, extract_mipmap_images_1.extractMipmapImages)(image, {
77
+ mipMapLevels,
78
+ width,
79
+ height,
80
+ sizeFunction,
81
+ internalFormat: DXT_FORMAT_MAP[format].pixelFormat
82
+ });
83
+ }
84
+ exports.parseCrunch = parseCrunch;
85
+ /**
86
+ * Copy an array of bytes into or out of the emscripten heap
87
+ * @param {Uint8Array} srcData - Source data array
88
+ * @param {Uint8Array} dstData - Destination data array
89
+ * @param {number} dstByteOffset - Destination data offset
90
+ * @param {number} numBytes - number of bytes to copy
91
+ * @returns {void}
92
+ */
93
+ function arrayBufferCopy(srcData, dstData, dstByteOffset, numBytes) {
94
+ let i;
95
+ const dst32Offset = dstByteOffset / 4;
96
+ const tail = numBytes % 4;
97
+ const src32 = new Uint32Array(srcData.buffer, 0, (numBytes - tail) / 4);
98
+ const dst32 = new Uint32Array(dstData.buffer);
99
+ for (i = 0; i < src32.length; i++) {
100
+ dst32[dst32Offset + i] = src32[i];
101
+ }
102
+ for (i = numBytes - tail; i < numBytes; i++) {
103
+ dstData[dstByteOffset + i] = srcData[i];
104
+ }
105
+ }
@@ -0,0 +1,28 @@
1
+ import type { TextureLevel } from '../../types';
2
+ /**
3
+ * Check if data is in "DDS" format by its magic number
4
+ * @param data - binary data of compressed texture
5
+ * @returns true - data in "DDS" format, else - false
6
+ */
7
+ export declare function isDDS(data: ArrayBuffer): boolean;
8
+ /**
9
+ * Parse texture data as "DDS" format
10
+ * @param data - binary data of compressed texture
11
+ * @returns Array of the texture levels
12
+ */
13
+ export declare function parseDDS(data: ArrayBuffer): TextureLevel[];
14
+ /**
15
+ * DXT1 applicable function to calculate level size
16
+ * @param width - level width
17
+ * @param height - level height
18
+ * @returns level size in bytes
19
+ */
20
+ export declare function getDxt1LevelSize(width: number, height: number): number;
21
+ /**
22
+ * DXT3 & DXT5 applicable function to calculate level size
23
+ * @param width - level width
24
+ * @param height - level height
25
+ * @returns level size in bytes
26
+ */
27
+ export declare function getDxtXLevelSize(width: number, height: number): number;
28
+ //# sourceMappingURL=parse-dds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-dds.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-dds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AA0C9C;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAIhD;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,YAAY,EAAE,CA4B1D;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEtE"}
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDxtXLevelSize = exports.getDxt1LevelSize = exports.parseDDS = exports.isDDS = void 0;
4
+ const loader_utils_1 = require("@loaders.gl/loader-utils");
5
+ const gl_extensions_1 = require("../gl-extensions");
6
+ const extract_mipmap_images_1 = require("../utils/extract-mipmap-images");
7
+ const DDS_CONSTANTS = {
8
+ MAGIC_NUMBER: 0x20534444,
9
+ HEADER_LENGTH: 31,
10
+ MAGIC_NUMBER_INDEX: 0,
11
+ HEADER_SIZE_INDEX: 1,
12
+ HEADER_FLAGS_INDEX: 2,
13
+ HEADER_HEIGHT_INDEX: 3,
14
+ HEADER_WIDTH_INDEX: 4,
15
+ MIPMAPCOUNT_INDEX: 7,
16
+ HEADER_PF_FLAGS_INDEX: 20,
17
+ HEADER_PF_FOURCC_INDEX: 21,
18
+ DDSD_MIPMAPCOUNT: 0x20000,
19
+ DDPF_FOURCC: 0x4
20
+ };
21
+ const DDS_PIXEL_FORMATS = {
22
+ DXT1: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT,
23
+ DXT3: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT,
24
+ DXT5: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
25
+ 'ATC ': gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ATC_WEBGL,
26
+ ATCA: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL,
27
+ ATCI: gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL
28
+ };
29
+ const getATCLevelSize = getDxt1LevelSize;
30
+ const getATCALevelSize = getDxtXLevelSize;
31
+ const getATCILevelSize = getDxtXLevelSize;
32
+ const DDS_SIZE_FUNCTIONS = {
33
+ DXT1: getDxt1LevelSize,
34
+ DXT3: getDxtXLevelSize,
35
+ DXT5: getDxtXLevelSize,
36
+ 'ATC ': getATCLevelSize,
37
+ ATCA: getATCALevelSize,
38
+ ATCI: getATCILevelSize
39
+ };
40
+ /**
41
+ * Check if data is in "DDS" format by its magic number
42
+ * @param data - binary data of compressed texture
43
+ * @returns true - data in "DDS" format, else - false
44
+ */
45
+ function isDDS(data) {
46
+ const header = new Uint32Array(data, 0, DDS_CONSTANTS.HEADER_LENGTH);
47
+ const magic = header[DDS_CONSTANTS.MAGIC_NUMBER_INDEX];
48
+ return magic === DDS_CONSTANTS.MAGIC_NUMBER;
49
+ }
50
+ exports.isDDS = isDDS;
51
+ /**
52
+ * Parse texture data as "DDS" format
53
+ * @param data - binary data of compressed texture
54
+ * @returns Array of the texture levels
55
+ */
56
+ function parseDDS(data) {
57
+ const header = new Int32Array(data, 0, DDS_CONSTANTS.HEADER_LENGTH);
58
+ const pixelFormatNumber = header[DDS_CONSTANTS.HEADER_PF_FOURCC_INDEX];
59
+ (0, loader_utils_1.assert)(Boolean(header[DDS_CONSTANTS.HEADER_PF_FLAGS_INDEX] & DDS_CONSTANTS.DDPF_FOURCC), 'DDS: Unsupported format, must contain a FourCC code');
60
+ const fourCC = int32ToFourCC(pixelFormatNumber);
61
+ const internalFormat = DDS_PIXEL_FORMATS[fourCC];
62
+ const sizeFunction = DDS_SIZE_FUNCTIONS[fourCC];
63
+ (0, loader_utils_1.assert)(internalFormat && sizeFunction, `DDS: Unknown pixel format ${pixelFormatNumber}`);
64
+ let mipMapLevels = 1;
65
+ if (header[DDS_CONSTANTS.HEADER_FLAGS_INDEX] & DDS_CONSTANTS.DDSD_MIPMAPCOUNT) {
66
+ mipMapLevels = Math.max(1, header[DDS_CONSTANTS.MIPMAPCOUNT_INDEX]);
67
+ }
68
+ const width = header[DDS_CONSTANTS.HEADER_WIDTH_INDEX];
69
+ const height = header[DDS_CONSTANTS.HEADER_HEIGHT_INDEX];
70
+ const dataOffset = header[DDS_CONSTANTS.HEADER_SIZE_INDEX] + 4;
71
+ const image = new Uint8Array(data, dataOffset);
72
+ return (0, extract_mipmap_images_1.extractMipmapImages)(image, {
73
+ mipMapLevels,
74
+ width,
75
+ height,
76
+ sizeFunction,
77
+ internalFormat
78
+ });
79
+ }
80
+ exports.parseDDS = parseDDS;
81
+ /**
82
+ * DXT1 applicable function to calculate level size
83
+ * @param width - level width
84
+ * @param height - level height
85
+ * @returns level size in bytes
86
+ */
87
+ function getDxt1LevelSize(width, height) {
88
+ return ((width + 3) >> 2) * ((height + 3) >> 2) * 8;
89
+ }
90
+ exports.getDxt1LevelSize = getDxt1LevelSize;
91
+ /**
92
+ * DXT3 & DXT5 applicable function to calculate level size
93
+ * @param width - level width
94
+ * @param height - level height
95
+ * @returns level size in bytes
96
+ */
97
+ function getDxtXLevelSize(width, height) {
98
+ return ((width + 3) >> 2) * ((height + 3) >> 2) * 16;
99
+ }
100
+ exports.getDxtXLevelSize = getDxtXLevelSize;
101
+ /**
102
+ * Convert every byte of Int32 value to char
103
+ * @param value - Int32 number
104
+ * @returns string of 4 characters
105
+ */
106
+ function int32ToFourCC(value) {
107
+ return String.fromCharCode(value & 0xff, (value >> 8) & 0xff, (value >> 16) & 0xff, (value >> 24) & 0xff);
108
+ }
@@ -0,0 +1,3 @@
1
+ export declare function isKTX(data: ArrayBuffer): boolean;
2
+ export declare function parseKTX(arrayBuffer: ArrayBuffer): import("../../types").TextureLevel[];
3
+ //# sourceMappingURL=parse-ktx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-ktx.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-ktx.ts"],"names":[],"mappings":"AAUA,wBAAgB,KAAK,CAAC,IAAI,EAAE,WAAW,WAmBtC;AAED,wBAAgB,QAAQ,CAAC,WAAW,EAAE,WAAW,wCAehD"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseKTX = exports.isKTX = void 0;
4
+ const ktx_parse_1 = require("ktx-parse");
5
+ const extract_mipmap_images_1 = require("../utils/extract-mipmap-images");
6
+ const ktx_format_helper_1 = require("../utils/ktx-format-helper");
7
+ const KTX2_ID = [
8
+ // '´', 'K', 'T', 'X', '2', '0', 'ª', '\r', '\n', '\x1A', '\n'
9
+ 0xab, 0x4b, 0x54, 0x58, 0x20, 0x32, 0x30, 0xbb, 0x0d, 0x0a, 0x1a, 0x0a
10
+ ];
11
+ // eslint-disable-next-line complexity
12
+ function isKTX(data) {
13
+ // const id = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
14
+ const id = new Uint8Array(data);
15
+ const notKTX = id.byteLength < KTX2_ID.length ||
16
+ id[0] !== KTX2_ID[0] || // '´'
17
+ id[1] !== KTX2_ID[1] || // 'K'
18
+ id[2] !== KTX2_ID[2] || // 'T'
19
+ id[3] !== KTX2_ID[3] || // 'X'
20
+ id[4] !== KTX2_ID[4] || // ' '
21
+ id[5] !== KTX2_ID[5] || // '2'
22
+ id[6] !== KTX2_ID[6] || // '0'
23
+ id[7] !== KTX2_ID[7] || // 'ª'
24
+ id[8] !== KTX2_ID[8] || // '\r'
25
+ id[9] !== KTX2_ID[9] || // '\n'
26
+ id[10] !== KTX2_ID[10] || // '\x1A'
27
+ id[11] !== KTX2_ID[11]; // '\n'
28
+ return !notKTX;
29
+ }
30
+ exports.isKTX = isKTX;
31
+ function parseKTX(arrayBuffer) {
32
+ const uint8Array = new Uint8Array(arrayBuffer);
33
+ const ktx = (0, ktx_parse_1.read)(uint8Array);
34
+ const mipMapLevels = Math.max(1, ktx.levels.length);
35
+ const width = ktx.pixelWidth;
36
+ const height = ktx.pixelHeight;
37
+ const internalFormat = (0, ktx_format_helper_1.mapVkFormatToWebGL)(ktx.vkFormat);
38
+ return (0, extract_mipmap_images_1.extractMipmapImages)(ktx.levels, {
39
+ mipMapLevels,
40
+ width,
41
+ height,
42
+ sizeFunction: (level) => level.uncompressedByteLength,
43
+ internalFormat
44
+ });
45
+ }
46
+ exports.parseKTX = parseKTX;
@@ -0,0 +1,10 @@
1
+ declare type NumpyHeader = {
2
+ descr: string;
3
+ shape: number[];
4
+ };
5
+ export declare function parseNPY(arrayBuffer: ArrayBuffer, options?: unknown): {
6
+ data: any;
7
+ header: NumpyHeader;
8
+ } | null;
9
+ export {};
10
+ //# sourceMappingURL=parse-npy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-npy.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-npy.ts"],"names":[],"mappings":"AAAA,aAAK,WAAW,GAAG;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAC,CAAC;AA6BpD,wBAAgB,QAAQ,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,OAAO;;;SA+BnE"}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseNPY = void 0;
4
+ function systemIsLittleEndian() {
5
+ const a = new Uint32Array([0x12345678]);
6
+ const b = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
7
+ return !(b[0] === 0x12);
8
+ }
9
+ const LITTLE_ENDIAN_OS = systemIsLittleEndian();
10
+ // The basic string format consists of 3 characters:
11
+ // 1. a character describing the byteorder of the data (<: little-endian, >: big-endian, |: not-relevant)
12
+ // 2. a character code giving the basic type of the array
13
+ // 3. an integer providing the number of bytes the type uses.
14
+ // https://numpy.org/doc/stable/reference/arrays.interface.html
15
+ //
16
+ // Here I only include the second and third characters, and check endianness
17
+ // separately
18
+ const DTYPES = {
19
+ u1: Uint8Array,
20
+ i1: Int8Array,
21
+ u2: Uint16Array,
22
+ i2: Int16Array,
23
+ u4: Uint32Array,
24
+ i4: Int32Array,
25
+ f4: Float32Array,
26
+ f8: Float64Array
27
+ };
28
+ function parseNPY(arrayBuffer, options) {
29
+ if (!arrayBuffer) {
30
+ return null;
31
+ }
32
+ const view = new DataView(arrayBuffer);
33
+ const { header, headerEndOffset } = parseHeader(view);
34
+ const numpyType = header.descr;
35
+ const ArrayType = DTYPES[numpyType.slice(1, 3)];
36
+ if (!ArrayType) {
37
+ // eslint-disable-next-line no-console, no-undef
38
+ console.warn(`Decoding of npy dtype not implemented: ${numpyType}`);
39
+ return null;
40
+ }
41
+ const nArrayElements = header.shape?.reduce((a, b) => a * b);
42
+ const arrayByteLength = nArrayElements * ArrayType.BYTES_PER_ELEMENT;
43
+ const data = new ArrayType(arrayBuffer.slice(headerEndOffset, headerEndOffset + arrayByteLength));
44
+ // Swap endianness if needed
45
+ if ((numpyType[0] === '>' && LITTLE_ENDIAN_OS) || (numpyType[0] === '<' && !LITTLE_ENDIAN_OS)) {
46
+ // eslint-disable-next-line no-console, no-undef
47
+ console.warn('Data is wrong endianness, byte swapping not yet implemented.');
48
+ }
49
+ return {
50
+ data,
51
+ header
52
+ };
53
+ }
54
+ exports.parseNPY = parseNPY;
55
+ /**
56
+ * Parse NPY header
57
+ *
58
+ * @param view
59
+ * @return
60
+ */
61
+ function parseHeader(view) {
62
+ const majorVersion = view.getUint8(6);
63
+ // const minorVersion = view.getUint8(7);
64
+ let offset = 8;
65
+ let headerLength;
66
+ if (majorVersion >= 2) {
67
+ headerLength = view.getUint32(8, true);
68
+ offset += 4;
69
+ }
70
+ else {
71
+ headerLength = view.getUint16(8, true);
72
+ offset += 2;
73
+ }
74
+ const encoding = majorVersion <= 2 ? 'latin1' : 'utf-8';
75
+ const decoder = new TextDecoder(encoding);
76
+ const headerArray = new Uint8Array(view.buffer, offset, headerLength);
77
+ const headerText = decoder.decode(headerArray);
78
+ offset += headerLength;
79
+ const header = JSON.parse(headerText
80
+ .replace(/'/g, '"')
81
+ .replace('False', 'false')
82
+ .replace('(', '[')
83
+ .replace(/,*\),*/g, ']'));
84
+ return { header, headerEndOffset: offset };
85
+ }
@@ -0,0 +1,15 @@
1
+ import { TextureLevel } from '../../types';
2
+ /**
3
+ * Check if data is in "PVR" format by its magic number
4
+ * @param data - binary data of compressed texture
5
+ * @returns true - data in "PVR" format, else - false
6
+ */
7
+ export declare function isPVR(data: ArrayBuffer): boolean;
8
+ /**
9
+ * Parse texture data as "PVR" format
10
+ * @param data - binary data of compressed texture
11
+ * @returns Array of the texture levels
12
+ * @see http://cdn.imgtec.com/sdk-documentation/PVR+File+Format.Specification.pdf
13
+ */
14
+ export declare function parsePVR(data: ArrayBuffer): TextureLevel[];
15
+ //# sourceMappingURL=parse-pvr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-pvr.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-pvr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AA2HzC;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAKhD;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,YAAY,EAAE,CA0B1D"}
@@ -0,0 +1,250 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parsePVR = exports.isPVR = void 0;
4
+ /* eslint-disable camelcase */
5
+ // Forked from PicoGL: https://github.com/tsherif/picogl.js/blob/master/examples/utils/utils.js
6
+ // Copyright (c) 2017 Tarek Sherif, The MIT License (MIT)
7
+ const gl_extensions_1 = require("../gl-extensions");
8
+ const extract_mipmap_images_1 = require("../utils/extract-mipmap-images");
9
+ const PVR_CONSTANTS = {
10
+ MAGIC_NUMBER: 0x03525650,
11
+ MAGIC_NUMBER_EXTRA: 0x50565203,
12
+ HEADER_LENGTH: 13,
13
+ HEADER_SIZE: 52,
14
+ MAGIC_NUMBER_INDEX: 0,
15
+ PIXEL_FORMAT_INDEX: 2,
16
+ COLOUR_SPACE_INDEX: 4,
17
+ HEIGHT_INDEX: 6,
18
+ WIDTH_INDEX: 7,
19
+ MIPMAPCOUNT_INDEX: 11,
20
+ METADATA_SIZE_INDEX: 12
21
+ };
22
+ const PVR_PIXEL_FORMATS = {
23
+ 0: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_2BPPV1_IMG],
24
+ 1: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG],
25
+ 2: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG],
26
+ 3: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG],
27
+ 6: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL],
28
+ 7: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT],
29
+ 9: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT],
30
+ 11: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT],
31
+ 22: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_ETC2],
32
+ 23: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA8_ETC2_EAC],
33
+ 24: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2],
34
+ 25: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_R11_EAC],
35
+ 26: [gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RG11_EAC],
36
+ 27: [
37
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR,
38
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR
39
+ ],
40
+ 28: [
41
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5X4_KHR,
42
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR
43
+ ],
44
+ 29: [
45
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5X5_KHR,
46
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR
47
+ ],
48
+ 30: [
49
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6X5_KHR,
50
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR
51
+ ],
52
+ 31: [
53
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6X6_KHR,
54
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR
55
+ ],
56
+ 32: [
57
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X5_KHR,
58
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR
59
+ ],
60
+ 33: [
61
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X6_KHR,
62
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR
63
+ ],
64
+ 34: [
65
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X8_KHR,
66
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR
67
+ ],
68
+ 35: [
69
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X5_KHR,
70
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR
71
+ ],
72
+ 36: [
73
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X6_KHR,
74
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR
75
+ ],
76
+ 37: [
77
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X8_KHR,
78
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR
79
+ ],
80
+ 38: [
81
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X10_KHR,
82
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR
83
+ ],
84
+ 39: [
85
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12X10_KHR,
86
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR
87
+ ],
88
+ 40: [
89
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12X12_KHR,
90
+ gl_extensions_1.GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR
91
+ ]
92
+ };
93
+ const PVR_SIZE_FUNCTIONS = {
94
+ 0: pvrtc2bppSize,
95
+ 1: pvrtc2bppSize,
96
+ 2: pvrtc4bppSize,
97
+ 3: pvrtc4bppSize,
98
+ 6: dxtEtcSmallSize,
99
+ 7: dxtEtcSmallSize,
100
+ 9: dxtEtcAstcBigSize,
101
+ 11: dxtEtcAstcBigSize,
102
+ 22: dxtEtcSmallSize,
103
+ 23: dxtEtcAstcBigSize,
104
+ 24: dxtEtcSmallSize,
105
+ 25: dxtEtcSmallSize,
106
+ 26: dxtEtcAstcBigSize,
107
+ 27: dxtEtcAstcBigSize,
108
+ 28: atc5x4Size,
109
+ 29: atc5x5Size,
110
+ 30: atc6x5Size,
111
+ 31: atc6x6Size,
112
+ 32: atc8x5Size,
113
+ 33: atc8x6Size,
114
+ 34: atc8x8Size,
115
+ 35: atc10x5Size,
116
+ 36: atc10x6Size,
117
+ 37: atc10x8Size,
118
+ 38: atc10x10Size,
119
+ 39: atc12x10Size,
120
+ 40: atc12x12Size
121
+ };
122
+ /**
123
+ * Check if data is in "PVR" format by its magic number
124
+ * @param data - binary data of compressed texture
125
+ * @returns true - data in "PVR" format, else - false
126
+ */
127
+ function isPVR(data) {
128
+ const header = new Uint32Array(data, 0, PVR_CONSTANTS.HEADER_LENGTH);
129
+ const version = header[PVR_CONSTANTS.MAGIC_NUMBER_INDEX];
130
+ return version === PVR_CONSTANTS.MAGIC_NUMBER || version === PVR_CONSTANTS.MAGIC_NUMBER_EXTRA;
131
+ }
132
+ exports.isPVR = isPVR;
133
+ /**
134
+ * Parse texture data as "PVR" format
135
+ * @param data - binary data of compressed texture
136
+ * @returns Array of the texture levels
137
+ * @see http://cdn.imgtec.com/sdk-documentation/PVR+File+Format.Specification.pdf
138
+ */
139
+ function parsePVR(data) {
140
+ const header = new Uint32Array(data, 0, PVR_CONSTANTS.HEADER_LENGTH);
141
+ const pvrFormat = header[PVR_CONSTANTS.PIXEL_FORMAT_INDEX];
142
+ const colourSpace = header[PVR_CONSTANTS.COLOUR_SPACE_INDEX];
143
+ const pixelFormats = PVR_PIXEL_FORMATS[pvrFormat] || [];
144
+ const internalFormat = pixelFormats.length > 1 && colourSpace ? pixelFormats[1] : pixelFormats[0];
145
+ const sizeFunction = PVR_SIZE_FUNCTIONS[pvrFormat];
146
+ const mipMapLevels = header[PVR_CONSTANTS.MIPMAPCOUNT_INDEX];
147
+ const width = header[PVR_CONSTANTS.WIDTH_INDEX];
148
+ const height = header[PVR_CONSTANTS.HEIGHT_INDEX];
149
+ const dataOffset = PVR_CONSTANTS.HEADER_SIZE + header[PVR_CONSTANTS.METADATA_SIZE_INDEX];
150
+ const image = new Uint8Array(data, dataOffset);
151
+ return (0, extract_mipmap_images_1.extractMipmapImages)(image, {
152
+ mipMapLevels,
153
+ width,
154
+ height,
155
+ sizeFunction,
156
+ internalFormat
157
+ });
158
+ }
159
+ exports.parsePVR = parsePVR;
160
+ // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_pvrtc/
161
+ function pvrtc2bppSize(width, height) {
162
+ width = Math.max(width, 16);
163
+ height = Math.max(height, 8);
164
+ return (width * height) / 4;
165
+ }
166
+ // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_pvrtc/
167
+ function pvrtc4bppSize(width, height) {
168
+ width = Math.max(width, 8);
169
+ height = Math.max(height, 8);
170
+ return (width * height) / 2;
171
+ }
172
+ // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_s3tc/
173
+ // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_etc/
174
+ // Size for:
175
+ // COMPRESSED_RGB_S3TC_DXT1_EXT
176
+ // COMPRESSED_R11_EAC
177
+ // COMPRESSED_SIGNED_R11_EAC
178
+ // COMPRESSED_RGB8_ETC2
179
+ // COMPRESSED_SRGB8_ETC2
180
+ // COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
181
+ // COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
182
+ function dxtEtcSmallSize(width, height) {
183
+ return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 8;
184
+ }
185
+ // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_s3tc/
186
+ // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_etc/
187
+ // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
188
+ // Size for:
189
+ // COMPRESSED_RGBA_S3TC_DXT3_EXT
190
+ // COMPRESSED_RGBA_S3TC_DXT5_EXT
191
+ // COMPRESSED_RG11_EAC
192
+ // COMPRESSED_SIGNED_RG11_EAC
193
+ // COMPRESSED_RGBA8_ETC2_EAC
194
+ // COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
195
+ // COMPRESSED_RGBA_ASTC_4x4_KHR
196
+ function dxtEtcAstcBigSize(width, height) {
197
+ return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 16;
198
+ }
199
+ // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
200
+ function atc5x4Size(width, height) {
201
+ return Math.floor((width + 4) / 5) * Math.floor((height + 3) / 4) * 16;
202
+ }
203
+ // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
204
+ function atc5x5Size(width, height) {
205
+ return Math.floor((width + 4) / 5) * Math.floor((height + 4) / 5) * 16;
206
+ }
207
+ // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
208
+ function atc6x5Size(width, height) {
209
+ return Math.floor((width + 5) / 6) * Math.floor((height + 4) / 5) * 16;
210
+ }
211
+ // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
212
+ function atc6x6Size(width, height) {
213
+ return Math.floor((width + 5) / 6) * Math.floor((height + 5) / 6) * 16;
214
+ }
215
+ // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
216
+ function atc8x5Size(width, height) {
217
+ return Math.floor((width + 7) / 8) * Math.floor((height + 4) / 5) * 16;
218
+ }
219
+ // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
220
+ function atc8x6Size(width, height) {
221
+ return Math.floor((width + 7) / 8) * Math.floor((height + 5) / 6) * 16;
222
+ }
223
+ // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
224
+ function atc8x8Size(width, height) {
225
+ return Math.floor((width + 7) / 8) * Math.floor((height + 7) / 8) * 16;
226
+ }
227
+ // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
228
+ function atc10x5Size(width, height) {
229
+ return Math.floor((width + 9) / 10) * Math.floor((height + 4) / 5) * 16;
230
+ }
231
+ // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
232
+ function atc10x6Size(width, height) {
233
+ return Math.floor((width + 9) / 10) * Math.floor((height + 5) / 6) * 16;
234
+ }
235
+ // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
236
+ function atc10x8Size(width, height) {
237
+ return Math.floor((width + 9) / 10) * Math.floor((height + 7) / 8) * 16;
238
+ }
239
+ // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
240
+ function atc10x10Size(width, height) {
241
+ return Math.floor((width + 9) / 10) * Math.floor((height + 9) / 10) * 16;
242
+ }
243
+ // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
244
+ function atc12x10Size(width, height) {
245
+ return Math.floor((width + 11) / 12) * Math.floor((height + 9) / 10) * 16;
246
+ }
247
+ // https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
248
+ function atc12x12Size(width, height) {
249
+ return Math.floor((width + 11) / 12) * Math.floor((height + 11) / 12) * 16;
250
+ }