@woosh/meep-engine 3.78.4 → 3.80.0

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 (421) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/README.md +1 -1
  3. package/package.json +1 -1
  4. package/src/engine/asset/GameAssetType.d.ts +2 -0
  5. package/src/engine/asset/GameAssetType.js +10 -0
  6. package/src/engine/asset/guessAssetType.d.ts.map +1 -1
  7. package/src/engine/asset/guessAssetType.js +4 -0
  8. package/src/engine/asset/load_model_scene_bundle.d.ts +1 -1
  9. package/src/engine/asset/load_model_scene_bundle.js +2 -2
  10. package/src/engine/asset/loaders/MTFSceneBundleAssetLoader.d.ts +42 -0
  11. package/src/engine/asset/loaders/MTFSceneBundleAssetLoader.d.ts.map +1 -0
  12. package/src/engine/asset/loaders/MTFSceneBundleAssetLoader.js +83 -0
  13. package/src/engine/asset/loaders/MTFTextureAssetLoader.d.ts +36 -0
  14. package/src/engine/asset/loaders/MTFTextureAssetLoader.d.ts.map +1 -0
  15. package/src/engine/asset/loaders/MTFTextureAssetLoader.js +78 -0
  16. package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.d.ts +6 -1
  17. package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.d.ts.map +1 -1
  18. package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +8 -2
  19. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  20. package/src/format/image/webp/vp8/VP8BoolDecoder.d.ts +45 -0
  21. package/src/format/image/webp/vp8/VP8BoolDecoder.d.ts.map +1 -0
  22. package/src/format/image/webp/vp8/VP8BoolDecoder.js +137 -0
  23. package/src/format/image/webp/vp8/vp8_decode.d.ts +21 -0
  24. package/src/format/image/webp/vp8/vp8_decode.d.ts.map +1 -0
  25. package/src/format/image/webp/vp8/vp8_decode.js +756 -0
  26. package/src/format/image/webp/vp8/vp8_loop_filter.d.ts +31 -0
  27. package/src/format/image/webp/vp8/vp8_loop_filter.d.ts.map +1 -0
  28. package/src/format/image/webp/vp8/vp8_loop_filter.js +189 -0
  29. package/src/format/image/webp/vp8/vp8_predict.d.ts +48 -0
  30. package/src/format/image/webp/vp8/vp8_predict.d.ts.map +1 -0
  31. package/src/format/image/webp/vp8/vp8_predict.js +290 -0
  32. package/src/format/image/webp/vp8/vp8_tables.d.ts +34 -0
  33. package/src/format/image/webp/vp8/vp8_tables.d.ts.map +1 -0
  34. package/src/format/image/webp/vp8/vp8_tables.js +350 -0
  35. package/src/format/image/webp/vp8/vp8_transform.d.ts +22 -0
  36. package/src/format/image/webp/vp8/vp8_transform.d.ts.map +1 -0
  37. package/src/format/image/webp/vp8/vp8_transform.js +114 -0
  38. package/src/format/image/webp/vp8/vp8_yuv_to_rgba.d.ts +23 -0
  39. package/src/format/image/webp/vp8/vp8_yuv_to_rgba.d.ts.map +1 -0
  40. package/src/format/image/webp/vp8/vp8_yuv_to_rgba.js +133 -0
  41. package/src/format/image/webp/vp8l/VP8LBitReader.d.ts +47 -0
  42. package/src/format/image/webp/vp8l/VP8LBitReader.d.ts.map +1 -0
  43. package/src/format/image/webp/vp8l/VP8LBitReader.js +84 -0
  44. package/src/format/image/webp/vp8l/VP8LPrefixCode.d.ts +27 -0
  45. package/src/format/image/webp/vp8l/VP8LPrefixCode.d.ts.map +1 -0
  46. package/src/format/image/webp/vp8l/VP8LPrefixCode.js +184 -0
  47. package/src/format/image/webp/vp8l/vp8l_decode.d.ts +28 -0
  48. package/src/format/image/webp/vp8l/vp8l_decode.d.ts.map +1 -0
  49. package/src/format/image/webp/vp8l/vp8l_decode.js +261 -0
  50. package/src/format/image/webp/vp8l/vp8l_distance.d.ts +22 -0
  51. package/src/format/image/webp/vp8l/vp8l_distance.d.ts.map +1 -0
  52. package/src/format/image/webp/vp8l/vp8l_distance.js +62 -0
  53. package/src/format/image/webp/vp8l/vp8l_inverse_transforms.d.ts +50 -0
  54. package/src/format/image/webp/vp8l/vp8l_inverse_transforms.d.ts.map +1 -0
  55. package/src/format/image/webp/vp8l/vp8l_inverse_transforms.js +267 -0
  56. package/src/format/image/webp/vp8l/vp8l_read_prefix_code.d.ts +14 -0
  57. package/src/format/image/webp/vp8l/vp8l_read_prefix_code.d.ts.map +1 -0
  58. package/src/format/image/webp/vp8l/vp8l_read_prefix_code.js +99 -0
  59. package/src/format/image/webp/webp_decode.d.ts +23 -0
  60. package/src/format/image/webp/webp_decode.d.ts.map +1 -0
  61. package/src/format/image/webp/webp_decode.js +179 -0
  62. package/src/format/image/webp/webp_decode_alpha.d.ts +18 -0
  63. package/src/format/image/webp/webp_decode_alpha.d.ts.map +1 -0
  64. package/src/format/image/webp/webp_decode_alpha.js +84 -0
  65. package/src/format/texture/{basis → astc}/astc_block.d.ts +41 -0
  66. package/src/format/texture/astc/astc_block.d.ts.map +1 -0
  67. package/src/format/texture/{basis → astc}/astc_block.js +284 -164
  68. package/src/format/texture/astc/astc_decode_block.d.ts +68 -0
  69. package/src/format/texture/astc/astc_decode_block.d.ts.map +1 -0
  70. package/src/format/texture/astc/astc_decode_block.js +1119 -0
  71. package/src/format/texture/astc/astc_encode_block_4x4.d.ts +32 -0
  72. package/src/format/texture/astc/astc_encode_block_4x4.d.ts.map +1 -0
  73. package/src/format/texture/astc/astc_encode_block_4x4.js +181 -0
  74. package/src/format/texture/astc/astc_encode_block_4x4_rgba.d.ts +32 -0
  75. package/src/format/texture/astc/astc_encode_block_4x4_rgba.d.ts.map +1 -0
  76. package/src/format/texture/astc/astc_encode_block_4x4_rgba.js +337 -0
  77. package/src/format/texture/astc/astc_integer_sequence.d.ts.map +1 -0
  78. package/src/format/texture/{basis → astc}/astc_integer_sequence.js +251 -251
  79. package/src/format/texture/astc/astc_partition.d.ts.map +1 -0
  80. package/src/format/texture/{basis → astc}/astc_partition.js +199 -199
  81. package/src/format/texture/basis/transcode/etc1s_to_astc.js +329 -329
  82. package/src/format/texture/basis/transcode/etc1s_to_etc2.d.ts.map +1 -1
  83. package/src/format/texture/basis/transcode/etc1s_to_etc2.js +305 -332
  84. package/src/format/texture/basis/transcode/fit_endpoints.d.ts.map +1 -1
  85. package/src/format/texture/basis/transcode/fit_endpoints.js +14 -27
  86. package/src/format/texture/basis/uastc/uastc_bc7_tables.d.ts +66 -0
  87. package/src/format/texture/basis/uastc/uastc_bc7_tables.d.ts.map +1 -0
  88. package/src/format/texture/basis/uastc/uastc_bc7_tables.js +148 -0
  89. package/src/format/texture/basis/uastc/uastc_decode_block.js +463 -463
  90. package/src/format/texture/basis/uastc/uastc_to_astc.js +421 -421
  91. package/src/format/texture/basis/uastc/uastc_to_bc5.d.ts +1 -6
  92. package/src/format/texture/basis/uastc/uastc_to_bc5.d.ts.map +1 -1
  93. package/src/format/texture/basis/uastc/uastc_to_bc5.js +48 -115
  94. package/src/format/texture/basis/uastc/uastc_to_bc7.d.ts.map +1 -1
  95. package/src/format/texture/basis/uastc/uastc_to_bc7.js +604 -602
  96. package/src/format/texture/bc/bc1_decode_block.d.ts +19 -0
  97. package/src/format/texture/bc/bc1_decode_block.d.ts.map +1 -0
  98. package/src/format/texture/bc/bc1_decode_block.js +22 -0
  99. package/src/format/texture/bc/bc1_decode_colors.d.ts +27 -0
  100. package/src/format/texture/bc/bc1_decode_colors.d.ts.map +1 -0
  101. package/src/format/texture/bc/bc1_decode_colors.js +100 -0
  102. package/src/format/texture/bc/bc2_decode_block.d.ts +18 -0
  103. package/src/format/texture/bc/bc2_decode_block.d.ts.map +1 -0
  104. package/src/format/texture/bc/bc2_decode_block.js +28 -0
  105. package/src/format/texture/bc/bc3_decode_block.d.ts +18 -0
  106. package/src/format/texture/bc/bc3_decode_block.d.ts.map +1 -0
  107. package/src/format/texture/bc/bc3_decode_block.js +23 -0
  108. package/src/format/texture/bc/bc4_decode_channel.d.ts +56 -0
  109. package/src/format/texture/bc/bc4_decode_channel.d.ts.map +1 -0
  110. package/src/format/texture/bc/bc4_decode_channel.js +138 -0
  111. package/src/format/texture/bc/bc4_encode_block.d.ts +43 -0
  112. package/src/format/texture/bc/bc4_encode_block.d.ts.map +1 -0
  113. package/src/format/texture/bc/bc4_encode_block.js +324 -0
  114. package/src/format/texture/bc/bc4_snorm_decode_block.d.ts +18 -0
  115. package/src/format/texture/bc/bc4_snorm_decode_block.d.ts.map +1 -0
  116. package/src/format/texture/bc/bc4_snorm_decode_block.js +27 -0
  117. package/src/format/texture/bc/bc4_unorm_decode_block.d.ts +17 -0
  118. package/src/format/texture/bc/bc4_unorm_decode_block.d.ts.map +1 -0
  119. package/src/format/texture/bc/bc4_unorm_decode_block.js +26 -0
  120. package/src/format/texture/bc/bc5_encode_block.d.ts +25 -0
  121. package/src/format/texture/bc/bc5_encode_block.d.ts.map +1 -0
  122. package/src/format/texture/bc/bc5_encode_block.js +34 -0
  123. package/src/format/texture/bc/bc5_snorm_decode_block.d.ts +18 -0
  124. package/src/format/texture/bc/bc5_snorm_decode_block.d.ts.map +1 -0
  125. package/src/format/texture/bc/bc5_snorm_decode_block.js +27 -0
  126. package/src/format/texture/bc/bc5_unorm_decode_block.d.ts +17 -0
  127. package/src/format/texture/bc/bc5_unorm_decode_block.d.ts.map +1 -0
  128. package/src/format/texture/bc/bc5_unorm_decode_block.js +26 -0
  129. package/src/format/texture/bc/bc6h_decode_texels.d.ts +30 -0
  130. package/src/format/texture/bc/bc6h_decode_texels.d.ts.map +1 -0
  131. package/src/format/texture/bc/bc6h_decode_texels.js +430 -0
  132. package/src/format/texture/bc/bc6h_sfloat_decode_block.d.ts +20 -0
  133. package/src/format/texture/bc/bc6h_sfloat_decode_block.d.ts.map +1 -0
  134. package/src/format/texture/bc/bc6h_sfloat_decode_block.js +23 -0
  135. package/src/format/texture/bc/bc6h_ufloat_decode_block.d.ts +18 -0
  136. package/src/format/texture/bc/bc6h_ufloat_decode_block.d.ts.map +1 -0
  137. package/src/format/texture/bc/bc6h_ufloat_decode_block.js +21 -0
  138. package/src/format/texture/bc/bc7_decode_block.d.ts +30 -0
  139. package/src/format/texture/bc/bc7_decode_block.d.ts.map +1 -0
  140. package/src/format/texture/bc/bc7_decode_block.js +232 -0
  141. package/src/format/texture/bc/bc7_encode_block.d.ts +39 -0
  142. package/src/format/texture/bc/bc7_encode_block.d.ts.map +1 -0
  143. package/src/format/texture/bc/bc7_encode_block.js +423 -0
  144. package/src/format/texture/bc/bc7_tables.d.ts +126 -0
  145. package/src/format/texture/bc/bc7_tables.d.ts.map +1 -0
  146. package/src/format/texture/{basis/uastc → bc}/bc7_tables.js +225 -276
  147. package/src/format/texture/bc/bc7_write_block.d.ts +65 -0
  148. package/src/format/texture/bc/bc7_write_block.d.ts.map +1 -0
  149. package/src/format/texture/{basis/uastc → bc}/bc7_write_block.js +185 -227
  150. package/src/format/texture/etc/eac_decode_channel.d.ts +50 -0
  151. package/src/format/texture/etc/eac_decode_channel.d.ts.map +1 -0
  152. package/src/format/texture/etc/eac_decode_channel.js +142 -0
  153. package/src/format/texture/etc/eac_modifiers.d.ts +15 -0
  154. package/src/format/texture/etc/eac_modifiers.d.ts.map +1 -0
  155. package/src/format/texture/etc/eac_modifiers.js +31 -0
  156. package/src/format/texture/etc/eac_r11_snorm_decode_block.d.ts +21 -0
  157. package/src/format/texture/etc/eac_r11_snorm_decode_block.d.ts.map +1 -0
  158. package/src/format/texture/etc/eac_r11_snorm_decode_block.js +30 -0
  159. package/src/format/texture/etc/eac_r11_unorm_decode_block.d.ts +20 -0
  160. package/src/format/texture/etc/eac_r11_unorm_decode_block.d.ts.map +1 -0
  161. package/src/format/texture/etc/eac_r11_unorm_decode_block.js +29 -0
  162. package/src/format/texture/etc/eac_rg11_snorm_decode_block.d.ts +19 -0
  163. package/src/format/texture/etc/eac_rg11_snorm_decode_block.d.ts.map +1 -0
  164. package/src/format/texture/etc/eac_rg11_snorm_decode_block.js +28 -0
  165. package/src/format/texture/etc/eac_rg11_unorm_decode_block.d.ts +19 -0
  166. package/src/format/texture/etc/eac_rg11_unorm_decode_block.d.ts.map +1 -0
  167. package/src/format/texture/etc/eac_rg11_unorm_decode_block.js +28 -0
  168. package/src/format/texture/etc/etc2_decode_color.d.ts +25 -0
  169. package/src/format/texture/etc/etc2_decode_color.d.ts.map +1 -0
  170. package/src/format/texture/etc/etc2_decode_color.js +370 -0
  171. package/src/format/texture/etc/etc2_rgb8_decode_block.d.ts +18 -0
  172. package/src/format/texture/etc/etc2_rgb8_decode_block.d.ts.map +1 -0
  173. package/src/format/texture/etc/etc2_rgb8_decode_block.js +21 -0
  174. package/src/format/texture/etc/etc2_rgb8a1_decode_block.d.ts +21 -0
  175. package/src/format/texture/etc/etc2_rgb8a1_decode_block.d.ts.map +1 -0
  176. package/src/format/texture/etc/etc2_rgb8a1_decode_block.js +24 -0
  177. package/src/format/texture/etc/etc2_rgba8_decode_block.d.ts +18 -0
  178. package/src/format/texture/etc/etc2_rgba8_decode_block.d.ts.map +1 -0
  179. package/src/format/texture/etc/etc2_rgba8_decode_block.js +24 -0
  180. package/src/format/texture/fit/fit_line.d.ts +23 -0
  181. package/src/format/texture/fit/fit_line.d.ts.map +1 -0
  182. package/src/format/texture/fit/fit_line.js +123 -0
  183. package/src/format/texture/fit/fit_line_refine.d.ts +21 -0
  184. package/src/format/texture/fit/fit_line_refine.d.ts.map +1 -0
  185. package/src/format/texture/fit/fit_line_refine.js +69 -0
  186. package/src/format/texture/fit/fit_line_solve.d.ts +23 -0
  187. package/src/format/texture/fit/fit_line_solve.d.ts.map +1 -0
  188. package/src/format/texture/fit/fit_line_solve.js +71 -0
  189. package/src/format/texture/texel_decode_image.d.ts +44 -0
  190. package/src/format/texture/texel_decode_image.d.ts.map +1 -0
  191. package/src/format/texture/texel_decode_image.js +251 -0
  192. package/src/format/texture/texel_encode_image.d.ts +77 -0
  193. package/src/format/texture/texel_encode_image.d.ts.map +1 -0
  194. package/src/format/texture/texel_encode_image.js +187 -0
  195. package/src/shade/renderer/ShadeIndirectLightingMode.js +2 -0
  196. package/src/shade/renderer/acoustics/GPUAcousticLattice.d.ts +1 -1
  197. package/src/shade/renderer/acoustics/GPUAcousticProbes.d.ts +1 -1
  198. package/src/shade/renderer/acoustics/GPUAcoustics.d.ts +1 -1
  199. package/src/shade/renderer/animation/ShadeAnimationClipSerializationAdapter.d.ts +33 -0
  200. package/src/shade/renderer/animation/ShadeAnimationClipSerializationAdapter.d.ts.map +1 -0
  201. package/src/shade/renderer/animation/ShadeAnimationClipSerializationAdapter.js +196 -0
  202. package/src/shade/renderer/animation/SkinSerializationAdapter.d.ts +25 -0
  203. package/src/shade/renderer/animation/SkinSerializationAdapter.d.ts.map +1 -0
  204. package/src/shade/renderer/animation/SkinSerializationAdapter.js +85 -0
  205. package/src/shade/renderer/hair/GPUHairSystem.d.ts.map +1 -1
  206. package/src/shade/renderer/hair/GPUHairSystem.js +16 -7
  207. package/src/shade/renderer/hair/HAIR.d.ts +5 -3
  208. package/src/shade/renderer/hair/HAIR.d.ts.map +1 -1
  209. package/src/shade/renderer/hair/HAIR.js +6 -4
  210. package/src/shade/renderer/hair/hair_shadow_draw.d.ts +10 -10
  211. package/src/shade/renderer/hair/hair_shadow_draw.d.ts.map +1 -1
  212. package/src/shade/renderer/hair/hair_shadow_draw.js +21 -17
  213. package/src/shade/renderer/hair/shader_hair_cull.d.ts.map +1 -1
  214. package/src/shade/renderer/hair/shader_hair_cull.js +6 -2
  215. package/src/shade/renderer/hair/shader_hair_shadow_list.d.ts +5 -4
  216. package/src/shade/renderer/hair/shader_hair_shadow_list.d.ts.map +1 -1
  217. package/src/shade/renderer/hair/shader_hair_shadow_list.js +10 -12
  218. package/src/shade/renderer/loader/SceneNodeSerializationAdapter.d.ts +38 -0
  219. package/src/shade/renderer/loader/SceneNodeSerializationAdapter.d.ts.map +1 -0
  220. package/src/shade/renderer/loader/SceneNodeSerializationAdapter.js +198 -0
  221. package/src/shade/renderer/loader/mtf/MTFTexture.d.ts +88 -0
  222. package/src/shade/renderer/loader/mtf/MTFTexture.d.ts.map +1 -0
  223. package/src/shade/renderer/loader/mtf/MTFTexture.js +159 -0
  224. package/src/shade/renderer/loader/mtf/MTFTextureSerializationAdapter.d.ts +30 -0
  225. package/src/shade/renderer/loader/mtf/MTFTextureSerializationAdapter.d.ts.map +1 -0
  226. package/src/shade/renderer/loader/mtf/MTFTextureSerializationAdapter.js +136 -0
  227. package/src/shade/renderer/loader/mtf/MTF_PACKAGE_MAGIC.d.ts +7 -0
  228. package/src/shade/renderer/loader/mtf/MTF_PACKAGE_MAGIC.d.ts.map +1 -0
  229. package/src/shade/renderer/loader/mtf/MTF_PACKAGE_MAGIC.js +6 -0
  230. package/src/shade/renderer/loader/mtf/MTF_PACKAGE_VERSION.d.ts +8 -0
  231. package/src/shade/renderer/loader/mtf/MTF_PACKAGE_VERSION.d.ts.map +1 -0
  232. package/src/shade/renderer/loader/mtf/MTF_PACKAGE_VERSION.js +7 -0
  233. package/src/shade/renderer/loader/mtf/MTF_TEXTURE_MAGIC.d.ts +7 -0
  234. package/src/shade/renderer/loader/mtf/MTF_TEXTURE_MAGIC.d.ts.map +1 -0
  235. package/src/shade/renderer/loader/mtf/MTF_TEXTURE_MAGIC.js +6 -0
  236. package/src/shade/renderer/loader/mtf/MTF_TEXTURE_VERSION.d.ts +7 -0
  237. package/src/shade/renderer/loader/mtf/MTF_TEXTURE_VERSION.d.ts.map +1 -0
  238. package/src/shade/renderer/loader/mtf/MTF_TEXTURE_VERSION.js +6 -0
  239. package/src/shade/renderer/loader/mtf/load_mtf.d.ts +41 -0
  240. package/src/shade/renderer/loader/mtf/load_mtf.d.ts.map +1 -0
  241. package/src/shade/renderer/loader/mtf/load_mtf.js +73 -0
  242. package/src/shade/renderer/loader/mtf/mtf_bundle_textures.d.ts +19 -0
  243. package/src/shade/renderer/loader/mtf/mtf_bundle_textures.d.ts.map +1 -0
  244. package/src/shade/renderer/loader/mtf/mtf_bundle_textures.js +57 -0
  245. package/src/shade/renderer/loader/mtf/mtf_encode_texture.d.ts +10 -0
  246. package/src/shade/renderer/loader/mtf/mtf_encode_texture.d.ts.map +1 -0
  247. package/src/shade/renderer/loader/mtf/mtf_encode_texture.js +152 -0
  248. package/src/shade/renderer/loader/mtf/mtf_export.d.ts +45 -0
  249. package/src/shade/renderer/loader/mtf/mtf_export.d.ts.map +1 -0
  250. package/src/shade/renderer/loader/mtf/mtf_export.js +161 -0
  251. package/src/shade/renderer/loader/mtf/mtf_is_texture.d.ts +9 -0
  252. package/src/shade/renderer/loader/mtf/mtf_is_texture.d.ts.map +1 -0
  253. package/src/shade/renderer/loader/mtf/mtf_is_texture.js +12 -0
  254. package/src/shade/renderer/loader/mtf/mtf_read_collection.d.ts +24 -0
  255. package/src/shade/renderer/loader/mtf/mtf_read_collection.d.ts.map +1 -0
  256. package/src/shade/renderer/loader/mtf/mtf_read_collection.js +37 -0
  257. package/src/shade/renderer/loader/mtf/mtf_read_scene.d.ts +27 -0
  258. package/src/shade/renderer/loader/mtf/mtf_read_scene.d.ts.map +1 -0
  259. package/src/shade/renderer/loader/mtf/mtf_read_scene.js +121 -0
  260. package/src/shade/renderer/loader/mtf/mtf_read_textures.d.ts +18 -0
  261. package/src/shade/renderer/loader/mtf/mtf_read_textures.d.ts.map +1 -0
  262. package/src/shade/renderer/loader/mtf/mtf_read_textures.js +51 -0
  263. package/src/shade/renderer/loader/mtf/mtf_replace_textures.d.ts +19 -0
  264. package/src/shade/renderer/loader/mtf/mtf_replace_textures.d.ts.map +1 -0
  265. package/src/shade/renderer/loader/mtf/mtf_replace_textures.js +60 -0
  266. package/src/shade/renderer/loader/mtf/mtf_resolve_uri.d.ts +21 -0
  267. package/src/shade/renderer/loader/mtf/mtf_resolve_uri.d.ts.map +1 -0
  268. package/src/shade/renderer/loader/mtf/mtf_resolve_uri.js +98 -0
  269. package/src/shade/renderer/loader/mtf/mtf_serialization_registry.d.ts +25 -0
  270. package/src/shade/renderer/loader/mtf/mtf_serialization_registry.d.ts.map +1 -0
  271. package/src/shade/renderer/loader/mtf/mtf_serialization_registry.js +51 -0
  272. package/src/shade/renderer/loader/mtf/mtf_texture_read.d.ts +20 -0
  273. package/src/shade/renderer/loader/mtf/mtf_texture_read.d.ts.map +1 -0
  274. package/src/shade/renderer/loader/mtf/mtf_texture_read.js +80 -0
  275. package/src/shade/renderer/loader/mtf/mtf_texture_select.d.ts +24 -0
  276. package/src/shade/renderer/loader/mtf/mtf_texture_select.d.ts.map +1 -0
  277. package/src/shade/renderer/loader/mtf/mtf_texture_select.js +42 -0
  278. package/src/shade/renderer/loader/mtf/mtf_texture_write.d.ts +31 -0
  279. package/src/shade/renderer/loader/mtf/mtf_texture_write.d.ts.map +1 -0
  280. package/src/shade/renderer/loader/mtf/mtf_texture_write.js +87 -0
  281. package/src/shade/renderer/loader/mtf/mtf_write.d.ts +36 -0
  282. package/src/shade/renderer/loader/mtf/mtf_write.d.ts.map +1 -0
  283. package/src/shade/renderer/loader/mtf/mtf_write.js +137 -0
  284. package/src/shade/renderer/loader/mtf/mtf_write_collection.d.ts +23 -0
  285. package/src/shade/renderer/loader/mtf/mtf_write_collection.d.ts.map +1 -0
  286. package/src/shade/renderer/loader/mtf/mtf_write_collection.js +36 -0
  287. package/src/shade/renderer/material/StandardShadeMaterialSerializationAdapter.d.ts +39 -0
  288. package/src/shade/renderer/material/StandardShadeMaterialSerializationAdapter.d.ts.map +1 -0
  289. package/src/shade/renderer/material/StandardShadeMaterialSerializationAdapter.js +207 -0
  290. package/src/shade/renderer/scene/optimization/source_to_sampler2d.d.ts.map +1 -1
  291. package/src/shade/renderer/scene/optimization/source_to_sampler2d.js +3 -1
  292. package/src/shade/renderer/scene/serialization/STANDARD_MATERIAL_SERIALIZED_BYTE_SIZE.d.ts +5 -5
  293. package/src/shade/renderer/scene/serialization/STANDARD_MATERIAL_SERIALIZED_BYTE_SIZE.js +5 -5
  294. package/src/shade/renderer/scene/serialization/deserialize_scene.d.ts.map +1 -1
  295. package/src/shade/renderer/scene/serialization/deserialize_scene.js +491 -528
  296. package/src/shade/renderer/scene/serialization/serialize_scene.d.ts +0 -10
  297. package/src/shade/renderer/scene/serialization/serialize_scene.d.ts.map +1 -1
  298. package/src/shade/renderer/scene/serialization/serialize_scene.js +15 -71
  299. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4.d.ts +13 -0
  300. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4.d.ts.map +1 -0
  301. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4.js +39 -0
  302. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgb.d.ts +3 -2
  303. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgb.d.ts.map +1 -1
  304. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgb.js +6 -21
  305. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgba.d.ts +42 -0
  306. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgba.d.ts.map +1 -0
  307. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgba.js +612 -0
  308. package/src/shade/renderer/texture/encode/chunk_bc1_encode_block.d.ts +5 -4
  309. package/src/shade/renderer/texture/encode/chunk_bc1_encode_block.d.ts.map +1 -1
  310. package/src/shade/renderer/texture/encode/chunk_bc1_encode_block.js +8 -25
  311. package/src/shade/renderer/texture/encode/chunk_bc6h_encode_block_mode11.d.ts.map +1 -1
  312. package/src/shade/renderer/texture/encode/chunk_bc6h_encode_block_mode11.js +3 -19
  313. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block.d.ts +14 -4
  314. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block.d.ts.map +1 -1
  315. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block.js +65 -54
  316. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block_mode6.d.ts +2 -2
  317. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block_mode6.d.ts.map +1 -1
  318. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block_mode6.js +5 -22
  319. package/src/shade/renderer/texture/encode/chunk_bc7_partition_2.js +1 -1
  320. package/src/shade/renderer/texture/encode/chunk_scatter_principal_axis.d.ts +27 -0
  321. package/src/shade/renderer/texture/encode/chunk_scatter_principal_axis.d.ts.map +1 -0
  322. package/src/shade/renderer/texture/encode/chunk_scatter_principal_axis.js +147 -0
  323. package/src/shade/renderer/texture/encode/shader_texture_encode_astc_4x4.d.ts +3 -4
  324. package/src/shade/renderer/texture/encode/shader_texture_encode_astc_4x4.d.ts.map +1 -1
  325. package/src/shade/renderer/texture/encode/shader_texture_encode_astc_4x4.js +6 -13
  326. package/src/shade/renderer/texture/encode/shader_texture_encode_bc7_rgb.d.ts +13 -0
  327. package/src/shade/renderer/texture/encode/shader_texture_encode_bc7_rgb.d.ts.map +1 -0
  328. package/src/shade/renderer/texture/encode/shader_texture_encode_bc7_rgb.js +66 -0
  329. package/src/shade/renderer/texture/encode/texture_encode.d.ts +28 -1
  330. package/src/shade/renderer/texture/encode/texture_encode.d.ts.map +1 -1
  331. package/src/shade/renderer/texture/encode/texture_encode.js +202 -168
  332. package/src/shade/renderer/texture/encode/texture_encode_shader.d.ts +13 -1
  333. package/src/shade/renderer/texture/encode/texture_encode_shader.d.ts.map +1 -1
  334. package/src/shade/renderer/texture/encode/texture_encode_shader.js +146 -108
  335. package/src/shade/renderer/texture/format/gpu_texture_format_without_srgb.d.ts +11 -0
  336. package/src/shade/renderer/texture/format/gpu_texture_format_without_srgb.d.ts.map +1 -0
  337. package/src/shade/renderer/texture/format/gpu_texture_format_without_srgb.js +14 -0
  338. package/src/shade/renderer/texture/format/texture_formats_to_build.d.ts +20 -0
  339. package/src/shade/renderer/texture/format/texture_formats_to_build.d.ts.map +1 -0
  340. package/src/shade/renderer/texture/format/texture_formats_to_build.js +98 -0
  341. package/src/shade/renderer/texture/mipmaps/WebGPUMipmapGenerator.d.ts.map +1 -1
  342. package/src/shade/renderer/texture/mipmaps/WebGPUMipmapGenerator.js +4 -23
  343. package/src/shade/renderer/texture/mipmaps/cpu/MipmapBilinearAxis.d.ts +53 -0
  344. package/src/shade/renderer/texture/mipmaps/cpu/MipmapBilinearAxis.d.ts.map +1 -0
  345. package/src/shade/renderer/texture/mipmaps/cpu/MipmapBilinearAxis.js +76 -0
  346. package/src/shade/renderer/texture/mipmaps/cpu/MipmapKernelAxis.d.ts +40 -0
  347. package/src/shade/renderer/texture/mipmaps/cpu/MipmapKernelAxis.d.ts.map +1 -0
  348. package/src/shade/renderer/texture/mipmaps/cpu/MipmapKernelAxis.js +43 -0
  349. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_bilinear_centres.d.ts +17 -0
  350. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_bilinear_centres.d.ts.map +1 -0
  351. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_bilinear_centres.js +29 -0
  352. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_bilinear_sample.d.ts +21 -0
  353. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_bilinear_sample.d.ts.map +1 -0
  354. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_bilinear_sample.js +91 -0
  355. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_chain_cpu.d.ts +32 -0
  356. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_chain_cpu.d.ts.map +1 -0
  357. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_chain_cpu.js +216 -0
  358. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_cubic_filter_cpu.d.ts +30 -0
  359. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_cubic_filter_cpu.d.ts.map +1 -0
  360. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_cubic_filter_cpu.js +134 -0
  361. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_catmull_rom_cpu.d.ts +16 -0
  362. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_catmull_rom_cpu.d.ts.map +1 -0
  363. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_catmull_rom_cpu.js +33 -0
  364. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_linear_cpu.d.ts +18 -0
  365. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_linear_cpu.d.ts.map +1 -0
  366. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_linear_cpu.js +71 -0
  367. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_linear_normal_cpu.d.ts +20 -0
  368. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_linear_normal_cpu.d.ts.map +1 -0
  369. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_linear_normal_cpu.js +57 -0
  370. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_magic_kernel_cpu.d.ts +18 -0
  371. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_magic_kernel_cpu.d.ts.map +1 -0
  372. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_magic_kernel_cpu.js +111 -0
  373. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_mitchell_cpu.d.ts +16 -0
  374. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_mitchell_cpu.d.ts.map +1 -0
  375. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_mitchell_cpu.js +33 -0
  376. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_mks_cpu.d.ts +18 -0
  377. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_mks_cpu.d.ts.map +1 -0
  378. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_mks_cpu.js +128 -0
  379. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_wronski2021_cpu.d.ts +21 -0
  380. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_wronski2021_cpu.d.ts.map +1 -0
  381. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_wronski2021_cpu.js +169 -0
  382. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_kernel_reduce.d.ts +21 -0
  383. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_kernel_reduce.d.ts.map +1 -0
  384. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_kernel_reduce.js +119 -0
  385. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_source_centre.d.ts +16 -0
  386. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_source_centre.d.ts.map +1 -0
  387. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_source_centre.js +19 -0
  388. package/src/shade/renderer/texture/mipmaps/cpu/texels_f32_to_rgba8unorm.d.ts +24 -0
  389. package/src/shade/renderer/texture/mipmaps/cpu/texels_f32_to_rgba8unorm.d.ts.map +1 -0
  390. package/src/shade/renderer/texture/mipmaps/cpu/texels_f32_to_rgba8unorm.js +41 -0
  391. package/src/shade/renderer/texture/mipmaps/cpu/texels_f32_to_rgba8unorm_srgb.d.ts +24 -0
  392. package/src/shade/renderer/texture/mipmaps/cpu/texels_f32_to_rgba8unorm_srgb.d.ts.map +1 -0
  393. package/src/shade/renderer/texture/mipmaps/cpu/texels_f32_to_rgba8unorm_srgb.js +140 -0
  394. package/src/shade/renderer/texture/mipmaps/cpu/texels_rgba8unorm_srgb_to_f32.d.ts +21 -0
  395. package/src/shade/renderer/texture/mipmaps/cpu/texels_rgba8unorm_srgb_to_f32.d.ts.map +1 -0
  396. package/src/shade/renderer/texture/mipmaps/cpu/texels_rgba8unorm_srgb_to_f32.js +35 -0
  397. package/src/shade/renderer/texture/mipmaps/cpu/texels_rgba8unorm_to_f32.d.ts +19 -0
  398. package/src/shade/renderer/texture/mipmaps/cpu/texels_rgba8unorm_to_f32.d.ts.map +1 -0
  399. package/src/shade/renderer/texture/mipmaps/cpu/texels_rgba8unorm_to_f32.js +27 -0
  400. package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_catmull_rom.js +4 -4
  401. package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_linear.d.ts +13 -0
  402. package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_linear.d.ts.map +1 -1
  403. package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_linear.js +54 -4
  404. package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_mitchell.js +4 -4
  405. package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_mks.d.ts.map +1 -1
  406. package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_mks.js +9 -13
  407. package/src/shade/renderer/texture/texture_block_encodings.d.ts +33 -0
  408. package/src/shade/renderer/texture/texture_block_encodings.d.ts.map +1 -0
  409. package/src/shade/renderer/texture/texture_block_encodings.js +89 -0
  410. package/src/shade/renderer/texture/texture_role_image_quality.d.ts +10 -0
  411. package/src/shade/renderer/texture/texture_role_image_quality.d.ts.map +1 -0
  412. package/src/shade/renderer/texture/texture_role_image_quality.js +29 -0
  413. package/src/format/texture/basis/astc_block.d.ts.map +0 -1
  414. package/src/format/texture/basis/astc_integer_sequence.d.ts.map +0 -1
  415. package/src/format/texture/basis/astc_partition.d.ts.map +0 -1
  416. package/src/format/texture/basis/uastc/bc7_tables.d.ts +0 -111
  417. package/src/format/texture/basis/uastc/bc7_tables.d.ts.map +0 -1
  418. package/src/format/texture/basis/uastc/bc7_write_block.d.ts +0 -124
  419. package/src/format/texture/basis/uastc/bc7_write_block.d.ts.map +0 -1
  420. /package/src/format/texture/{basis → astc}/astc_integer_sequence.d.ts +0 -0
  421. /package/src/format/texture/{basis → astc}/astc_partition.d.ts +0 -0
@@ -0,0 +1,1119 @@
1
+ import { ASTC_RANGE, astc_unpack_quints, astc_unpack_trits } from "./astc_integer_sequence.js";
2
+
3
+ /**
4
+ * Bytes in one ASTC block, whatever its footprint.
5
+ *
6
+ * @readonly
7
+ * @type {number}
8
+ */
9
+ const BLOCK_BYTES = 16;
10
+
11
+ /**
12
+ * The LDR profile's error colour, opaque magenta, as eight-bit channels.
13
+ *
14
+ * @readonly
15
+ */
16
+ const ERROR_R = 0xFF;
17
+ const ERROR_G = 0x00;
18
+ const ERROR_B = 0xFF;
19
+ const ERROR_A = 0xFF;
20
+
21
+ /**
22
+ * Plain bits, trit flag and quint flag of each quantization range, by range index.
23
+ *
24
+ * @readonly
25
+ * @type {Uint8Array}
26
+ */
27
+ const RANGE_BITS = Uint8Array.from(ASTC_RANGE, range => range.bits);
28
+ const RANGE_TRITS = Uint8Array.from(ASTC_RANGE, range => range.trits);
29
+ const RANGE_QUINTS = Uint8Array.from(ASTC_RANGE, range => range.quints);
30
+
31
+ /**
32
+ * How many bits an integer sequence of `count` values takes at a range: the plain bits, plus eight
33
+ * bits per five trits and seven per three quints, each rounded up — a final partial group stores only
34
+ * the bits that follow its last value.
35
+ *
36
+ * @param {number} count
37
+ * @param {number} range index into {@link ASTC_RANGE}
38
+ * @returns {number}
39
+ */
40
+ function sequence_bits(count, range) {
41
+ return count * RANGE_BITS[range]
42
+ + Math.ceil(count * 8 * RANGE_TRITS[range] / 5)
43
+ + Math.ceil(count * 7 * RANGE_QUINTS[range] / 3);
44
+ }
45
+
46
+ /**
47
+ * The five trits each packed eight-bit group decodes to, `[group * 5 + i]`.
48
+ *
49
+ * @readonly
50
+ * @type {Uint8Array}
51
+ */
52
+ const TRIT_DIGITS = new Uint8Array(256 * 5);
53
+
54
+ for (let packed = 0; packed < 256; packed++) {
55
+ TRIT_DIGITS.set(astc_unpack_trits(packed), packed * 5);
56
+ }
57
+
58
+ /**
59
+ * The three quints each packed seven-bit group decodes to, `[group * 3 + i]`.
60
+ *
61
+ * @readonly
62
+ * @type {Uint8Array}
63
+ */
64
+ const QUINT_DIGITS = new Uint8Array(128 * 3);
65
+
66
+ for (let packed = 0; packed < 128; packed++) {
67
+ QUINT_DIGITS.set(astc_unpack_quints(packed), packed * 3);
68
+ }
69
+
70
+ /**
71
+ * How a trit group's eight bits are cut and threaded after each of its five values: piece widths,
72
+ * and where each piece lands in the packed group.
73
+ *
74
+ * @readonly
75
+ * @type {Uint8Array}
76
+ */
77
+ const TRIT_PIECE_BITS = new Uint8Array([2, 2, 1, 2, 1]);
78
+ const TRIT_PIECE_SHIFT = new Uint8Array([0, 2, 4, 5, 7]);
79
+
80
+ /**
81
+ * The same for a quint group's seven bits after each of its three values.
82
+ *
83
+ * @readonly
84
+ * @type {Uint8Array}
85
+ */
86
+ const QUINT_PIECE_BITS = new Uint8Array([3, 2, 2]);
87
+ const QUINT_PIECE_SHIFT = new Uint8Array([0, 3, 5]);
88
+
89
+ /**
90
+ * Replicate a `bits`-bit value downward until `width` bits are filled, most significant bit first.
91
+ *
92
+ * @param {number} value
93
+ * @param {number} bits
94
+ * @param {number} width
95
+ * @returns {number}
96
+ */
97
+ function replicate(value, bits, width) {
98
+ let out = 0;
99
+
100
+ for (let i = 0; i < width; i++) {
101
+ out = (out << 1) | ((value >> (bits - 1 - (i % bits))) & 1);
102
+ }
103
+
104
+ return out;
105
+ }
106
+
107
+ /**
108
+ * The value of a bit pattern from the specification's unquantization tables: written most
109
+ * significant bit first, `0` a zero bit and a letter one of the value's plain bits (`a` the lowest).
110
+ *
111
+ * @param {string} pattern
112
+ * @param {number} plain
113
+ * @returns {number}
114
+ */
115
+ function pattern_value(pattern, plain) {
116
+ let out = 0;
117
+
118
+ for (let i = 0; i < pattern.length; i++) {
119
+ const character = pattern.charCodeAt(i);
120
+
121
+ out = (out << 1) | (character === 48 ? 0 : (plain >> (character - 97)) & 1);
122
+ }
123
+
124
+ return out;
125
+ }
126
+
127
+ /**
128
+ * Colour endpoint unquantization parameters of the trit and quint ranges: `[range, B, C]`.
129
+ *
130
+ * @readonly
131
+ * @type {Array<[number, string, number]>}
132
+ */
133
+ const ENDPOINT_TRIT_QUINT = [
134
+ [4, "000000000", 204],
135
+ [6, "000000000", 113],
136
+ [7, "b000b0bb0", 93],
137
+ [9, "b0000bb00", 54],
138
+ [10, "cb000cbcb", 44],
139
+ [12, "cb0000cbc", 26],
140
+ [13, "dcb000dcb", 22],
141
+ [15, "dcb0000dc", 13],
142
+ [16, "edcb000ed", 11],
143
+ [18, "edcb0000e", 6],
144
+ [19, "fedcb000f", 5],
145
+ ];
146
+
147
+ /**
148
+ * Every endpoint integer unquantized to eight bits, `[range * 256 + integer]`, for the ranges an
149
+ * endpoint can take (`0..5` upward). A plain range replicates its bits; a trit or quint range
150
+ * computes `T = D * C + B`, flips it by the lowest plain bit, and keeps `(A & 0x80) | (T >> 2)`.
151
+ *
152
+ * @readonly
153
+ * @type {Uint8Array}
154
+ */
155
+ const ENDPOINT_UNQUANTIZED = new Uint8Array(ASTC_RANGE.length * 256);
156
+
157
+ for (let range = 4; range < ASTC_RANGE.length; range++) {
158
+ if (RANGE_TRITS[range] === 0 && RANGE_QUINTS[range] === 0) {
159
+ for (let q = 0; q < ASTC_RANGE[range].levels; q++) {
160
+ ENDPOINT_UNQUANTIZED[range * 256 + q] = replicate(q, RANGE_BITS[range], 8);
161
+ }
162
+ }
163
+ }
164
+
165
+ for (const [range, pattern, c] of ENDPOINT_TRIT_QUINT) {
166
+ const bits = RANGE_BITS[range];
167
+
168
+ for (let q = 0; q < ASTC_RANGE[range].levels; q++) {
169
+ const plain = q & ((1 << bits) - 1);
170
+ const a = (plain & 1) ? 0x1FF : 0;
171
+
172
+ let t = (q >> bits) * c + pattern_value(pattern, plain);
173
+
174
+ t ^= a;
175
+
176
+ ENDPOINT_UNQUANTIZED[range * 256 + q] = (a & 0x80) | (t >> 2);
177
+ }
178
+ }
179
+
180
+ /**
181
+ * Weight unquantization parameters of the trit and quint ranges: the two with no plain bits list
182
+ * their values, the others give `B` and `C`.
183
+ *
184
+ * @readonly
185
+ */
186
+ const WEIGHT_TRIT_QUINT = [
187
+ { range: 1, list: [0, 32, 63] },
188
+ { range: 3, list: [0, 16, 32, 47, 63] },
189
+ { range: 4, pattern: "0000000", c: 50 },
190
+ { range: 6, pattern: "0000000", c: 28 },
191
+ { range: 7, pattern: "b000b0b", c: 23 },
192
+ { range: 9, pattern: "b0000b0", c: 13 },
193
+ { range: 10, pattern: "cb000cb", c: 11 },
194
+ ];
195
+
196
+ /**
197
+ * Every weight integer unquantized to `[0, 64]`, `[range * 32 + integer]`: to `[0, 63]` by bit
198
+ * replication or the trit/quint formula (`(A & 0x20) | (T >> 2)`), then moved up by one above 32.
199
+ *
200
+ * @readonly
201
+ * @type {Uint8Array}
202
+ */
203
+ const WEIGHT_UNQUANTIZED = new Uint8Array(12 * 32);
204
+
205
+ for (let range = 0; range < 12; range++) {
206
+ if (RANGE_TRITS[range] === 0 && RANGE_QUINTS[range] === 0) {
207
+ for (let q = 0; q < ASTC_RANGE[range].levels; q++) {
208
+ WEIGHT_UNQUANTIZED[range * 32 + q] = replicate(q, RANGE_BITS[range], 6);
209
+ }
210
+ }
211
+ }
212
+
213
+ for (const { range, list, pattern, c } of WEIGHT_TRIT_QUINT) {
214
+ const bits = RANGE_BITS[range];
215
+
216
+ for (let q = 0; q < ASTC_RANGE[range].levels; q++) {
217
+ const digit = q >> bits;
218
+
219
+ if (list !== undefined) {
220
+ WEIGHT_UNQUANTIZED[range * 32 + q] = list[digit];
221
+
222
+ continue;
223
+ }
224
+
225
+ const plain = q & ((1 << bits) - 1);
226
+ const a = (plain & 1) ? 0x7F : 0;
227
+
228
+ let t = digit * c + pattern_value(pattern, plain);
229
+
230
+ t ^= a;
231
+
232
+ WEIGHT_UNQUANTIZED[range * 32 + q] = (a & 0x20) | (t >> 2);
233
+ }
234
+ }
235
+
236
+ for (let i = 0; i < WEIGHT_UNQUANTIZED.length; i++) {
237
+ if (WEIGHT_UNQUANTIZED[i] > 32) {
238
+ WEIGHT_UNQUANTIZED[i] += 1;
239
+ }
240
+ }
241
+
242
+ /**
243
+ * What a colour endpoint integer unquantizes to, by the decoder's own table.
244
+ *
245
+ * @param {number} range an index into {@link ASTC_RANGE} an endpoint can take, `4` upward
246
+ * @param {number} integer below the range's level count
247
+ * @returns {number} eight bits
248
+ */
249
+ export function astc_unquantize_endpoint(range, integer) {
250
+ return ENDPOINT_UNQUANTIZED[range * 256 + integer];
251
+ }
252
+
253
+ /**
254
+ * What a weight integer unquantizes to, by the decoder's own table.
255
+ *
256
+ * @param {number} range an index into {@link ASTC_RANGE} a weight can take, `0..11`
257
+ * @param {number} integer below the range's level count
258
+ * @returns {number} `0..64`
259
+ */
260
+ export function astc_unquantize_weight(range, integer) {
261
+ return WEIGHT_UNQUANTIZED[range * 32 + integer];
262
+ }
263
+
264
+ /**
265
+ * What each of the 2048 block modes says, by the specification's 2D block mode layout: weight grid
266
+ * width and height, dual plane, weight range, and the weight sequence's length in bits. A length of
267
+ * zero marks a mode that is reserved, or illegal whatever the footprint (more than 64 weights, or a
268
+ * sequence outside 24 to 96 bits). Void-extent blocks are recognised before this is consulted.
269
+ *
270
+ * @readonly
271
+ * @type {Uint8Array}
272
+ */
273
+ const MODE_GRID_WIDTH = new Uint8Array(2048);
274
+ const MODE_GRID_HEIGHT = new Uint8Array(2048);
275
+ const MODE_DUAL = new Uint8Array(2048);
276
+ const MODE_WEIGHT_RANGE = new Uint8Array(2048);
277
+ const MODE_WEIGHT_BITS = new Uint8Array(2048);
278
+
279
+ for (let mode = 0; mode < 2048; mode++) {
280
+ const a = (mode >> 5) & 3;
281
+
282
+ let width;
283
+ let height;
284
+ let r;
285
+ let dual = (mode >> 10) & 1;
286
+ let high = (mode >> 9) & 1;
287
+
288
+ if ((mode & 3) !== 0) {
289
+ // the rows that keep R2 R1 in bits 1:0
290
+ r = ((mode & 3) << 1) | ((mode >> 4) & 1);
291
+
292
+ const b = (mode >> 7) & 3;
293
+
294
+ switch ((mode >> 2) & 3) {
295
+ case 0:
296
+ width = b + 4;
297
+ height = a + 2;
298
+ break;
299
+ case 1:
300
+ width = b + 8;
301
+ height = a + 2;
302
+ break;
303
+ case 2:
304
+ width = a + 2;
305
+ height = b + 8;
306
+ break;
307
+ default:
308
+ if ((mode >> 8) & 1) {
309
+ width = (b & 1) + 2;
310
+ height = a + 2;
311
+ } else {
312
+ width = a + 2;
313
+ height = (b & 1) + 6;
314
+ }
315
+ }
316
+ } else {
317
+ // the rows that keep R2 R1 in bits 3:2; both clear is reserved
318
+ if (((mode >> 2) & 3) === 0) {
319
+ continue;
320
+ }
321
+
322
+ r = (((mode >> 2) & 3) << 1) | ((mode >> 4) & 1);
323
+
324
+ switch ((mode >> 7) & 3) {
325
+ case 0:
326
+ width = 12;
327
+ height = a + 2;
328
+ break;
329
+ case 1:
330
+ width = a + 2;
331
+ height = 12;
332
+ break;
333
+ case 2:
334
+ width = a + 6;
335
+ height = ((mode >> 9) & 3) + 6;
336
+ dual = 0;
337
+ high = 0;
338
+ break;
339
+ default:
340
+ if ((mode >> 6) & 1) {
341
+ continue;
342
+ }
343
+
344
+ width = (mode >> 5) & 1 ? 10 : 6;
345
+ height = (mode >> 5) & 1 ? 6 : 10;
346
+ }
347
+ }
348
+
349
+ const range = r - 2 + 6 * high;
350
+ const count = width * height * (dual + 1);
351
+ const bits = sequence_bits(count, range);
352
+
353
+ if (count > 64 || bits < 24 || bits > 96) {
354
+ continue;
355
+ }
356
+
357
+ MODE_GRID_WIDTH[mode] = width;
358
+ MODE_GRID_HEIGHT[mode] = height;
359
+ MODE_DUAL[mode] = dual;
360
+ MODE_WEIGHT_RANGE[mode] = range;
361
+ MODE_WEIGHT_BITS[mode] = bits;
362
+ }
363
+
364
+ /**
365
+ * The colour endpoint range for a number of endpoint integers and the bits left for them: the
366
+ * highest range whose sequence fits, `[(count / 2) * 128 + available]`, or `-1` where even `0..5`
367
+ * does not (fewer than `ceil(13 * count / 5)` bits), which is an illegal encoding.
368
+ *
369
+ * @readonly
370
+ * @type {Int8Array}
371
+ */
372
+ const ENDPOINT_RANGE = new Int8Array(10 * 128).fill(-1);
373
+
374
+ for (let pairs = 1; pairs <= 9; pairs++) {
375
+ for (let available = 0; available < 128; available++) {
376
+ for (let range = ASTC_RANGE.length - 1; range >= 4; range--) {
377
+ if (sequence_bits(pairs * 2, range) <= available) {
378
+ ENDPOINT_RANGE[pairs * 128 + available] = range;
379
+
380
+ break;
381
+ }
382
+ }
383
+ }
384
+ }
385
+
386
+ /**
387
+ * Each byte with its bit order reversed.
388
+ *
389
+ * @readonly
390
+ * @type {Uint8Array}
391
+ */
392
+ const REVERSED_BYTE = new Uint8Array(256);
393
+
394
+ for (let i = 0; i < 256; i++) {
395
+ let reversed = 0;
396
+
397
+ for (let bit = 0; bit < 8; bit++) {
398
+ reversed |= ((i >> bit) & 1) << (7 - bit);
399
+ }
400
+
401
+ REVERSED_BYTE[i] = reversed;
402
+ }
403
+
404
+ /*
405
+ Scratch for one block. The block arrays carry four zero bytes past the sixteen, so a read that runs
406
+ past bit 127 reads zeros. The weight planes are larger than any grid (at most 64 weights) by a row
407
+ and a column, so the infill's neighbour reads at the grid's far edge, which always carry a factor of
408
+ zero, stay inside them.
409
+ */
410
+ const BLOCK = new Uint8Array(BLOCK_BYTES + 4);
411
+ const REVERSED = new Uint8Array(BLOCK_BYTES + 4);
412
+ const VALUES = new Uint8Array(64);
413
+ const PLANE_0 = new Uint8Array(96);
414
+ const PLANE_1 = new Uint8Array(96);
415
+ const ENDPOINTS = new Int32Array(4 * 8);
416
+ const PARTITION_HDR = new Uint8Array(4);
417
+ const PARTITION_CEM = new Uint8Array(4);
418
+ const TEXEL_PARTITION = new Uint8Array(144);
419
+ const COLUMN_INDEX = new Int32Array(12);
420
+ const COLUMN_FRACTION = new Int32Array(12);
421
+ const ROW_OFFSET = new Int32Array(12);
422
+ const ROW_FRACTION = new Int32Array(12);
423
+
424
+ /**
425
+ * Read `count` bits, least significant first, from bit `bit` of a padded block array.
426
+ *
427
+ * @param {Uint8Array} bytes
428
+ * @param {number} bit
429
+ * @param {number} count at most 24
430
+ * @returns {number}
431
+ */
432
+ function read_bits(bytes, bit, count) {
433
+ const i = bit >> 3;
434
+
435
+ const word = bytes[i] | (bytes[i + 1] << 8) | (bytes[i + 2] << 16) | (bytes[i + 3] << 24);
436
+
437
+ return (word >>> (bit & 7)) & ((1 << count) - 1);
438
+ }
439
+
440
+ /**
441
+ * Decode an integer sequence: `count` values at a range, from bit `bit` upward.
442
+ *
443
+ * Trits go five values to a group and quints three, each group's packed bits cut into pieces that
444
+ * follow the values' plain bits. A final partial group reads only the pieces after its own values;
445
+ * the rest of its packed bits are zero.
446
+ *
447
+ * @param {Uint8Array} bytes padded block array
448
+ * @param {number} bit
449
+ * @param {number} count
450
+ * @param {number} range index into {@link ASTC_RANGE}
451
+ * @param {Uint8Array} out
452
+ */
453
+ function decode_sequence(bytes, bit, count, range, out) {
454
+ const bits = RANGE_BITS[range];
455
+
456
+ if (RANGE_TRITS[range] !== 0) {
457
+ for (let start = 0; start < count; start += 5) {
458
+ const present = count - start < 5 ? count - start : 5;
459
+
460
+ let packed = 0;
461
+
462
+ for (let j = 0; j < present; j++) {
463
+ out[start + j] = read_bits(bytes, bit, bits);
464
+ bit += bits;
465
+
466
+ packed |= read_bits(bytes, bit, TRIT_PIECE_BITS[j]) << TRIT_PIECE_SHIFT[j];
467
+ bit += TRIT_PIECE_BITS[j];
468
+ }
469
+
470
+ for (let j = 0; j < present; j++) {
471
+ out[start + j] |= TRIT_DIGITS[packed * 5 + j] << bits;
472
+ }
473
+ }
474
+ } else if (RANGE_QUINTS[range] !== 0) {
475
+ for (let start = 0; start < count; start += 3) {
476
+ const present = count - start < 3 ? count - start : 3;
477
+
478
+ let packed = 0;
479
+
480
+ for (let j = 0; j < present; j++) {
481
+ out[start + j] = read_bits(bytes, bit, bits);
482
+ bit += bits;
483
+
484
+ packed |= read_bits(bytes, bit, QUINT_PIECE_BITS[j]) << QUINT_PIECE_SHIFT[j];
485
+ bit += QUINT_PIECE_BITS[j];
486
+ }
487
+
488
+ for (let j = 0; j < present; j++) {
489
+ out[start + j] |= QUINT_DIGITS[packed * 3 + j] << bits;
490
+ }
491
+ }
492
+ } else {
493
+ for (let i = 0; i < count; i++) {
494
+ out[i] = read_bits(bytes, bit, bits);
495
+ bit += bits;
496
+ }
497
+ }
498
+ }
499
+
500
+ /**
501
+ * @param {number} x
502
+ * @returns {number} `x` clamped to `[0, 255]`
503
+ */
504
+ function clamp_unorm8(x) {
505
+ return x < 0 ? 0 : x > 255 ? 255 : x;
506
+ }
507
+
508
+ /**
509
+ * The offset half of the specification's `bit_transfer_signed`: bits 6..1 of an unquantized value,
510
+ * read as a six-bit two's-complement number.
511
+ *
512
+ * @param {number} v eight bits
513
+ * @returns {number} in `[-32, 31]`
514
+ */
515
+ function signed_offset(v) {
516
+ const a = (v >> 1) & 0x3F;
517
+
518
+ return (a & 0x20) !== 0 ? a - 0x40 : a;
519
+ }
520
+
521
+ /**
522
+ * Store a partition's two eight-bit endpoints widened to sixteen bits: by bit replication for the
523
+ * linear arithmetic, and for sRGB by `(e << 8) | 0x80` in R, G and B with alpha replicated, as
524
+ * KHR_texture_compression_astc_hdr's "Weight Application" gives it.
525
+ *
526
+ * @param {number} at first slot in {@link ENDPOINTS}
527
+ * @param {boolean} srgb
528
+ * @param {number} r0 first endpoint, eight bits a channel
529
+ * @param {number} g0
530
+ * @param {number} b0
531
+ * @param {number} a0
532
+ * @param {number} r1 second endpoint, eight bits a channel
533
+ * @param {number} g1
534
+ * @param {number} b1
535
+ * @param {number} a1
536
+ */
537
+ function set_endpoints(at, srgb, r0, g0, b0, a0, r1, g1, b1, a1) {
538
+ if (srgb) {
539
+ ENDPOINTS[at] = (r0 << 8) | 0x80;
540
+ ENDPOINTS[at + 1] = (g0 << 8) | 0x80;
541
+ ENDPOINTS[at + 2] = (b0 << 8) | 0x80;
542
+ ENDPOINTS[at + 3] = a0 * 257;
543
+ ENDPOINTS[at + 4] = (r1 << 8) | 0x80;
544
+ ENDPOINTS[at + 5] = (g1 << 8) | 0x80;
545
+ ENDPOINTS[at + 6] = (b1 << 8) | 0x80;
546
+ ENDPOINTS[at + 7] = a1 * 257;
547
+ } else {
548
+ ENDPOINTS[at] = r0 * 257;
549
+ ENDPOINTS[at + 1] = g0 * 257;
550
+ ENDPOINTS[at + 2] = b0 * 257;
551
+ ENDPOINTS[at + 3] = a0 * 257;
552
+ ENDPOINTS[at + 4] = r1 * 257;
553
+ ENDPOINTS[at + 5] = g1 * 257;
554
+ ENDPOINTS[at + 6] = b1 * 257;
555
+ ENDPOINTS[at + 7] = a1 * 257;
556
+ }
557
+ }
558
+
559
+ /**
560
+ * Decode one partition's endpoints from its unquantized integers, by the specification's LDR
561
+ * endpoint decoding, into {@link ENDPOINTS}.
562
+ *
563
+ * @param {number} cem colour endpoint mode
564
+ * @param {number} first index of the partition's first integer in {@link VALUES}
565
+ * @param {number} table `range * 256`, the row of {@link ENDPOINT_UNQUANTIZED} to read
566
+ * @param {number} at first slot in {@link ENDPOINTS}
567
+ * @param {boolean} srgb
568
+ * @returns {boolean} false for an HDR mode, which the LDR profile does not decode
569
+ */
570
+ function decode_endpoints(cem, first, table, at, srgb) {
571
+ const v0 = ENDPOINT_UNQUANTIZED[table + VALUES[first]];
572
+ const v1 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 1]];
573
+
574
+ switch (cem) {
575
+ case 0:
576
+ set_endpoints(at, srgb, v0, v0, v0, 255, v1, v1, v1, 255);
577
+
578
+ return true;
579
+
580
+ case 1: {
581
+ const l0 = (v0 >> 2) | (v1 & 0xC0);
582
+ const l1 = clamp_unorm8(l0 + (v1 & 0x3F));
583
+
584
+ set_endpoints(at, srgb, l0, l0, l0, 255, l1, l1, l1, 255);
585
+
586
+ return true;
587
+ }
588
+
589
+ case 4: {
590
+ const v2 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 2]];
591
+ const v3 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 3]];
592
+
593
+ set_endpoints(at, srgb, v0, v0, v0, v2, v1, v1, v1, v3);
594
+
595
+ return true;
596
+ }
597
+
598
+ case 5: {
599
+ const v2 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 2]];
600
+ const v3 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 3]];
601
+
602
+ // bit_transfer_signed: each base takes its offset's top bit, each offset becomes six signed bits
603
+ const l = (v0 >> 1) | (v1 & 0x80);
604
+ const a = (v2 >> 1) | (v3 & 0x80);
605
+ const dl = signed_offset(v1);
606
+ const da = signed_offset(v3);
607
+
608
+ const l1 = clamp_unorm8(l + dl);
609
+
610
+ set_endpoints(at, srgb, l, l, l, a, l1, l1, l1, clamp_unorm8(a + da));
611
+
612
+ return true;
613
+ }
614
+
615
+ case 6: {
616
+ const v2 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 2]];
617
+ const v3 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 3]];
618
+
619
+ set_endpoints(at, srgb,
620
+ (v0 * v3) >> 8, (v1 * v3) >> 8, (v2 * v3) >> 8, 255,
621
+ v0, v1, v2, 255
622
+ );
623
+
624
+ return true;
625
+ }
626
+
627
+ case 8:
628
+ case 12: {
629
+ const v2 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 2]];
630
+ const v3 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 3]];
631
+ const v4 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 4]];
632
+ const v5 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 5]];
633
+
634
+ const v6 = cem === 12 ? ENDPOINT_UNQUANTIZED[table + VALUES[first + 6]] : 255;
635
+ const v7 = cem === 12 ? ENDPOINT_UNQUANTIZED[table + VALUES[first + 7]] : 255;
636
+
637
+ if (v1 + v3 + v5 >= v0 + v2 + v4) {
638
+ set_endpoints(at, srgb, v0, v2, v4, v6, v1, v3, v5, v7);
639
+ } else {
640
+ // swapped, and blue-contracted
641
+ set_endpoints(at, srgb,
642
+ (v1 + v5) >> 1, (v3 + v5) >> 1, v5, v7,
643
+ (v0 + v4) >> 1, (v2 + v4) >> 1, v4, v6
644
+ );
645
+ }
646
+
647
+ return true;
648
+ }
649
+
650
+ case 9:
651
+ case 13: {
652
+ const v2 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 2]];
653
+ const v3 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 3]];
654
+ const v4 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 4]];
655
+ const v5 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 5]];
656
+
657
+ // bit_transfer_signed on each pair: base and six-bit signed offset
658
+ const r = (v0 >> 1) | (v1 & 0x80);
659
+ const g = (v2 >> 1) | (v3 & 0x80);
660
+ const b = (v4 >> 1) | (v5 & 0x80);
661
+ const dr = signed_offset(v1);
662
+ const dg = signed_offset(v3);
663
+ const db = signed_offset(v5);
664
+
665
+ let a0 = 255;
666
+ let a1 = 255;
667
+
668
+ if (cem === 13) {
669
+ const v6 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 6]];
670
+ const v7 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 7]];
671
+
672
+ a0 = (v6 >> 1) | (v7 & 0x80);
673
+ a1 = a0 + signed_offset(v7);
674
+ }
675
+
676
+ if (dr + dg + db >= 0) {
677
+ set_endpoints(at, srgb,
678
+ r, g, b, a0,
679
+ clamp_unorm8(r + dr), clamp_unorm8(g + dg), clamp_unorm8(b + db), clamp_unorm8(a1)
680
+ );
681
+ } else {
682
+ // swapped and blue-contracted, then clamped
683
+ set_endpoints(at, srgb,
684
+ clamp_unorm8((r + dr + b + db) >> 1), clamp_unorm8((g + dg + b + db) >> 1),
685
+ clamp_unorm8(b + db), clamp_unorm8(a1),
686
+ (r + b) >> 1, (g + b) >> 1, b, a0
687
+ );
688
+ }
689
+
690
+ return true;
691
+ }
692
+
693
+ case 10: {
694
+ const v2 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 2]];
695
+ const v3 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 3]];
696
+ const v4 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 4]];
697
+ const v5 = ENDPOINT_UNQUANTIZED[table + VALUES[first + 5]];
698
+
699
+ set_endpoints(at, srgb,
700
+ (v0 * v3) >> 8, (v1 * v3) >> 8, (v2 * v3) >> 8, v4,
701
+ v0, v1, v2, v5
702
+ );
703
+
704
+ return true;
705
+ }
706
+
707
+ default:
708
+ return false;
709
+ }
710
+ }
711
+
712
+ /**
713
+ * The specification's partition hash, `hash52`, in unsigned 32-bit arithmetic.
714
+ *
715
+ * @param {number} p
716
+ * @returns {number}
717
+ */
718
+ function hash52(p) {
719
+ p >>>= 0;
720
+ p = (p ^ (p >>> 15)) >>> 0;
721
+ p = (p - (p << 17)) >>> 0;
722
+ p = (p + (p << 7)) >>> 0;
723
+ p = (p + (p << 4)) >>> 0;
724
+ p = (p ^ (p >>> 5)) >>> 0;
725
+ p = (p + (p << 16)) >>> 0;
726
+ p = (p ^ (p >>> 7)) >>> 0;
727
+ p = (p ^ (p >>> 3)) >>> 0;
728
+ p = (p ^ (p << 6)) >>> 0;
729
+ p = (p ^ (p >>> 17)) >>> 0;
730
+
731
+ return p;
732
+ }
733
+
734
+ /**
735
+ * Fill {@link TEXEL_PARTITION} with the partition of every texel, by the specification's
736
+ * `select_partition` for a 2D block: coordinates doubled in a block of fewer than 31 texels.
737
+ *
738
+ * @param {number} seed ten bits
739
+ * @param {number} partitions 2, 3 or 4
740
+ * @param {number} width
741
+ * @param {number} height
742
+ */
743
+ function assign_partitions(seed, partitions, width, height) {
744
+ const full = seed + (partitions - 1) * 1024;
745
+
746
+ const rnum = hash52(full);
747
+
748
+ let s1 = rnum & 0xF;
749
+ let s2 = (rnum >>> 4) & 0xF;
750
+ let s3 = (rnum >>> 8) & 0xF;
751
+ let s4 = (rnum >>> 12) & 0xF;
752
+ let s5 = (rnum >>> 16) & 0xF;
753
+ let s6 = (rnum >>> 20) & 0xF;
754
+ let s7 = (rnum >>> 24) & 0xF;
755
+ let s8 = (rnum >>> 28) & 0xF;
756
+
757
+ s1 *= s1;
758
+ s2 *= s2;
759
+ s3 *= s3;
760
+ s4 *= s4;
761
+ s5 *= s5;
762
+ s6 *= s6;
763
+ s7 *= s7;
764
+ s8 *= s8;
765
+
766
+ let sh1;
767
+ let sh2;
768
+
769
+ if (full & 1) {
770
+ sh1 = (full & 2) ? 4 : 5;
771
+ sh2 = partitions === 3 ? 6 : 5;
772
+ } else {
773
+ sh1 = partitions === 3 ? 6 : 5;
774
+ sh2 = (full & 2) ? 4 : 5;
775
+ }
776
+
777
+ // seeds 9 to 12 and the third shift weigh only the z coordinate, which is zero here
778
+ s1 >>= sh1;
779
+ s2 >>= sh2;
780
+ s3 >>= sh1;
781
+ s4 >>= sh2;
782
+ s5 >>= sh1;
783
+ s6 >>= sh2;
784
+ s7 >>= sh1;
785
+ s8 >>= sh2;
786
+
787
+ const step = width * height < 31 ? 2 : 1;
788
+
789
+ const ca = rnum >>> 14;
790
+ const cb = rnum >>> 10;
791
+ const cc = rnum >>> 6;
792
+ const cd = rnum >>> 2;
793
+
794
+ let texel = 0;
795
+
796
+ for (let y = 0; y < height; y++) {
797
+ const ty = y * step;
798
+
799
+ for (let x = 0; x < width; x++, texel++) {
800
+ const tx = x * step;
801
+
802
+ const a = (s1 * tx + s2 * ty + ca) & 0x3F;
803
+ const b = (s3 * tx + s4 * ty + cb) & 0x3F;
804
+ const c = partitions < 3 ? 0 : (s5 * tx + s6 * ty + cc) & 0x3F;
805
+ const d = partitions < 4 ? 0 : (s7 * tx + s8 * ty + cd) & 0x3F;
806
+
807
+ TEXEL_PARTITION[texel] = (a >= b && a >= c && a >= d) ? 0
808
+ : (b >= c && b >= d) ? 1
809
+ : (c >= d) ? 2
810
+ : 3;
811
+ }
812
+ }
813
+ }
814
+
815
+ /**
816
+ * Write one colour into every texel.
817
+ *
818
+ * @param {Uint8Array} out
819
+ * @param {number} texels
820
+ * @param {number} r eight bits
821
+ * @param {number} g
822
+ * @param {number} b
823
+ * @param {number} a
824
+ */
825
+ function fill(out, texels, r, g, b, a) {
826
+ for (let i = 0, o = 0; i < texels; i++, o += 4) {
827
+ out[o] = r;
828
+ out[o + 1] = g;
829
+ out[o + 2] = b;
830
+ out[o + 3] = a;
831
+ }
832
+ }
833
+
834
+ /**
835
+ * A 2D void-extent block (block mode bits 8..0 are `0x1FC`), from {@link BLOCK}: one UNORM16 colour
836
+ * over the whole block, of which the result is the top eight bits in each channel.
837
+ *
838
+ * It is the error colour if the reserved bits 10 and 11 are not both set, if a low extent coordinate
839
+ * is not below its high one (unless all four are all ones, which says no extent is given), or if the
840
+ * colour is marked HDR (bit 9), which the LDR profile does not decode.
841
+ *
842
+ * @param {Uint8Array} out
843
+ * @param {number} texels
844
+ */
845
+ function decode_void_extent(out, texels) {
846
+ const hdr = (BLOCK[1] >> 1) & 1;
847
+ const reserved = (BLOCK[1] >> 2) & 3;
848
+
849
+ const low_s = read_bits(BLOCK, 12, 13);
850
+ const high_s = read_bits(BLOCK, 25, 13);
851
+ const low_t = read_bits(BLOCK, 38, 13);
852
+ const high_t = read_bits(BLOCK, 51, 13);
853
+
854
+ const no_extent = low_s === 0x1FFF && high_s === 0x1FFF && low_t === 0x1FFF && high_t === 0x1FFF;
855
+
856
+ if (hdr !== 0 || reserved !== 3 || (!no_extent && (low_s >= high_s || low_t >= high_t))) {
857
+ fill(out, texels, ERROR_R, ERROR_G, ERROR_B, ERROR_A);
858
+
859
+ return;
860
+ }
861
+
862
+ // the high byte of each little-endian sixteen-bit channel, R G B A from bit 64
863
+ fill(out, texels, BLOCK[9], BLOCK[11], BLOCK[13], BLOCK[15]);
864
+ }
865
+
866
+ /**
867
+ * Decode one block of any 2D footprint, in the LDR profile, with either arithmetic.
868
+ *
869
+ * @param {Uint8Array} source
870
+ * @param {number} offset
871
+ * @param {number} width
872
+ * @param {number} height
873
+ * @param {Uint8Array} out
874
+ * @param {boolean} srgb
875
+ */
876
+ function decode_block(source, offset, width, height, out, srgb) {
877
+ const texels = width * height;
878
+
879
+ for (let i = 0; i < BLOCK_BYTES; i++) {
880
+ BLOCK[i] = source[offset + i];
881
+ }
882
+
883
+ const mode = BLOCK[0] | ((BLOCK[1] & 7) << 8);
884
+
885
+ if ((mode & 0x1FF) === 0x1FC) {
886
+ decode_void_extent(out, texels);
887
+
888
+ return;
889
+ }
890
+
891
+ const weight_bits = MODE_WEIGHT_BITS[mode];
892
+ const grid_width = MODE_GRID_WIDTH[mode];
893
+ const grid_height = MODE_GRID_HEIGHT[mode];
894
+ const dual = MODE_DUAL[mode];
895
+
896
+ const partitions = ((BLOCK[1] >> 3) & 3) + 1;
897
+
898
+ if (weight_bits === 0 || grid_width > width || grid_height > height || (dual !== 0 && partitions === 4)) {
899
+ fill(out, texels, ERROR_R, ERROR_G, ERROR_B, ERROR_A);
900
+
901
+ return;
902
+ }
903
+
904
+ /*
905
+ The configuration: endpoint modes, and the bits each part takes. A multi-partition block whose
906
+ mode selector is non-zero gives each partition a class offset and a mode of its own; four of
907
+ those bits sit at 25..28 and the rest immediately below the weights. A dual-plane block's
908
+ channel selector sits below those.
909
+ */
910
+ let extra = 0;
911
+ let endpoint_start;
912
+
913
+ if (partitions === 1) {
914
+ PARTITION_CEM[0] = read_bits(BLOCK, 13, 4);
915
+ endpoint_start = 17;
916
+ } else {
917
+ const field = read_bits(BLOCK, 23, 6);
918
+ const selector = field & 3;
919
+
920
+ if (selector === 0) {
921
+ for (let p = 0; p < partitions; p++) {
922
+ PARTITION_CEM[p] = field >> 2;
923
+ }
924
+ } else {
925
+ extra = 3 * partitions - 4;
926
+
927
+ const all = field | (read_bits(BLOCK, 128 - weight_bits - extra, extra) << 6);
928
+
929
+ const base = selector - 1;
930
+
931
+ for (let p = 0; p < partitions; p++) {
932
+ const cls = base + ((all >> (2 + p)) & 1);
933
+
934
+ PARTITION_CEM[p] = (cls << 2) | ((all >> (2 + partitions + 2 * p)) & 3);
935
+ }
936
+ }
937
+
938
+ endpoint_start = 29;
939
+ }
940
+
941
+ const below = 128 - weight_bits - extra - (dual !== 0 ? 2 : 0);
942
+
943
+ // the channel the second plane drives; -1 matches none
944
+ const ccs = dual !== 0 ? read_bits(BLOCK, below, 2) : -1;
945
+
946
+ let value_count = 0;
947
+
948
+ for (let p = 0; p < partitions; p++) {
949
+ value_count += ((PARTITION_CEM[p] >> 2) + 1) * 2;
950
+ }
951
+
952
+ const available = below - endpoint_start;
953
+
954
+ const endpoint_range = value_count > 18 || available < 0
955
+ ? -1
956
+ : ENDPOINT_RANGE[(value_count >> 1) * 128 + available];
957
+
958
+ if (endpoint_range < 0) {
959
+ fill(out, texels, ERROR_R, ERROR_G, ERROR_B, ERROR_A);
960
+
961
+ return;
962
+ }
963
+
964
+ // endpoints: integers in partition order, unquantized and decoded per partition
965
+ decode_sequence(BLOCK, endpoint_start, value_count, endpoint_range, VALUES);
966
+
967
+ for (let p = 0, first = 0; p < partitions; p++) {
968
+ const cem = PARTITION_CEM[p];
969
+
970
+ PARTITION_HDR[p] = decode_endpoints(cem, first, endpoint_range * 256, p * 8, srgb) ? 0 : 1;
971
+
972
+ first += ((cem >> 2) + 1) * 2;
973
+ }
974
+
975
+ // weights: stored from bit 127 downward, planes interleaved
976
+ for (let i = 0; i < BLOCK_BYTES; i++) {
977
+ REVERSED[i] = REVERSED_BYTE[BLOCK[BLOCK_BYTES - 1 - i]];
978
+ }
979
+
980
+ const grid_count = grid_width * grid_height;
981
+ const weight_table = MODE_WEIGHT_RANGE[mode] * 32;
982
+
983
+ decode_sequence(REVERSED, 0, grid_count * (dual + 1), MODE_WEIGHT_RANGE[mode], VALUES);
984
+
985
+ if (dual !== 0) {
986
+ for (let i = 0; i < grid_count; i++) {
987
+ PLANE_0[i] = WEIGHT_UNQUANTIZED[weight_table + VALUES[2 * i]];
988
+ PLANE_1[i] = WEIGHT_UNQUANTIZED[weight_table + VALUES[2 * i + 1]];
989
+ }
990
+ } else {
991
+ for (let i = 0; i < grid_count; i++) {
992
+ PLANE_0[i] = WEIGHT_UNQUANTIZED[weight_table + VALUES[i]];
993
+ }
994
+ }
995
+
996
+ // the infill's grid coordinates, in 4.4 fixed point, per column and per row
997
+ const ds = ((1024 + (width >> 1)) / (width - 1)) | 0;
998
+ const dt = ((1024 + (height >> 1)) / (height - 1)) | 0;
999
+
1000
+ for (let x = 0; x < width; x++) {
1001
+ const gs = (ds * x * (grid_width - 1) + 32) >> 6;
1002
+
1003
+ COLUMN_INDEX[x] = gs >> 4;
1004
+ COLUMN_FRACTION[x] = gs & 0xF;
1005
+ }
1006
+
1007
+ for (let y = 0; y < height; y++) {
1008
+ const gt = (dt * y * (grid_height - 1) + 32) >> 6;
1009
+
1010
+ ROW_OFFSET[y] = (gt >> 4) * grid_width;
1011
+ ROW_FRACTION[y] = gt & 0xF;
1012
+ }
1013
+
1014
+ if (partitions > 1) {
1015
+ assign_partitions(read_bits(BLOCK, 13, 10), partitions, width, height);
1016
+ }
1017
+
1018
+ for (let y = 0, texel = 0, o = 0; y < height; y++) {
1019
+ const row = ROW_OFFSET[y];
1020
+ const ft = ROW_FRACTION[y];
1021
+
1022
+ for (let x = 0; x < width; x++, texel++, o += 4) {
1023
+ const p = partitions > 1 ? TEXEL_PARTITION[texel] : 0;
1024
+
1025
+ if (PARTITION_HDR[p] !== 0) {
1026
+ out[o] = ERROR_R;
1027
+ out[o + 1] = ERROR_G;
1028
+ out[o + 2] = ERROR_B;
1029
+ out[o + 3] = ERROR_A;
1030
+
1031
+ continue;
1032
+ }
1033
+
1034
+ const fs = COLUMN_FRACTION[x];
1035
+ const v0 = row + COLUMN_INDEX[x];
1036
+
1037
+ const w11 = (fs * ft + 8) >> 4;
1038
+ const w10 = ft - w11;
1039
+ const w01 = fs - w11;
1040
+ const w00 = 16 - fs - ft + w11;
1041
+
1042
+ const plane_0 = (PLANE_0[v0] * w00 + PLANE_0[v0 + 1] * w01
1043
+ + PLANE_0[v0 + grid_width] * w10 + PLANE_0[v0 + grid_width + 1] * w11 + 8) >> 4;
1044
+
1045
+ const plane_1 = dual === 0 ? plane_0 : (PLANE_1[v0] * w00 + PLANE_1[v0 + 1] * w01
1046
+ + PLANE_1[v0 + grid_width] * w10 + PLANE_1[v0 + grid_width + 1] * w11 + 8) >> 4;
1047
+
1048
+ const e = p * 8;
1049
+
1050
+ const wr = ccs === 0 ? plane_1 : plane_0;
1051
+ const wg = ccs === 1 ? plane_1 : plane_0;
1052
+ const wb = ccs === 2 ? plane_1 : plane_0;
1053
+ const wa = ccs === 3 ? plane_1 : plane_0;
1054
+
1055
+ // the interpolation's floor((... + 32) / 64), then its top eight bits: one shift by 14
1056
+ out[o] = (ENDPOINTS[e] * (64 - wr) + ENDPOINTS[e + 4] * wr + 32) >> 14;
1057
+ out[o + 1] = (ENDPOINTS[e + 1] * (64 - wg) + ENDPOINTS[e + 5] * wg + 32) >> 14;
1058
+ out[o + 2] = (ENDPOINTS[e + 2] * (64 - wb) + ENDPOINTS[e + 6] * wb + 32) >> 14;
1059
+ out[o + 3] = (ENDPOINTS[e + 3] * (64 - wa) + ENDPOINTS[e + 7] * wa + 32) >> 14;
1060
+ }
1061
+ }
1062
+ }
1063
+
1064
+ /**
1065
+ * Decode one ASTC block of a linear (`astc-*-unorm`) texture, in the LDR profile.
1066
+ *
1067
+ * Complete for the 2D format: every block mode (dual plane included), one to four partitions by the
1068
+ * partition hash, every LDR colour endpoint mode with its unquantization and its endpoint-swap and
1069
+ * blue-contraction rules, integer sequences at every range, weight unquantization and the bilinear
1070
+ * infill of a grid smaller than the block, and void-extent blocks.
1071
+ *
1072
+ * Endpoints widen to sixteen bits by bit replication and interpolate there; the eight-bit result is
1073
+ * the top eight bits of that sixteen-bit value, which is the specification's rule for an eight-bit
1074
+ * (`decode_unorm8`) result.
1075
+ *
1076
+ * Every illegal encoding — a reserved block mode, a weight grid larger than the footprint, more than
1077
+ * 64 weights, a weight sequence outside 24 to 96 bits, dual plane with four partitions, more than 18
1078
+ * endpoint integers or too few bits for them, a void-extent block breaking its rules — decodes to
1079
+ * the error colour, opaque magenta, in every texel. An HDR endpoint mode, or an HDR void-extent
1080
+ * block, is outside the LDR profile and decodes to the error colour too: for an endpoint mode, only
1081
+ * in the texels of the partition that uses it.
1082
+ *
1083
+ * @param {Uint8Array} source
1084
+ * @param {number} offset byte offset of the block in `source`
1085
+ * @param {number} block_width the footprint: 4, 5, 6, 8, 10 or 12
1086
+ * @param {number} block_height 4, 5, 6, 8, 10 or 12
1087
+ * @param {Uint8Array} out receives `block_width * block_height` texels, RGBA, raster order, from index 0
1088
+ *
1089
+ * @see Khronos Data Format Specification, "ASTC Compressed Texture Image Formats"
1090
+ * @author Alex Goldring
1091
+ * @copyright Company Named Limited (c) 2026
1092
+ */
1093
+ export function astc_decode_block(source, offset, block_width, block_height, out) {
1094
+ decode_block(source, offset, block_width, block_height, out, false);
1095
+ }
1096
+
1097
+ /**
1098
+ * Decode one ASTC block of an sRGB (`astc-*-unorm-srgb`) texture, in the LDR profile, to the
1099
+ * sRGB-encoded bytes such a texture holds.
1100
+ *
1101
+ * Everything as {@link astc_decode_block} except the arithmetic: each eight-bit R, G and B endpoint
1102
+ * widens to sixteen bits as `(e << 8) | 0x80` rather than by replication, while alpha is replicated
1103
+ * as in the linear arithmetic (KHR_texture_compression_astc_hdr, "Weight Application"), and the result
1104
+ * is the top eight bits of the interpolation: the value passed to the sRGB conversion for R, G and B,
1105
+ * and used directly for alpha. A void-extent colour is its top eight bits, as for the linear arithmetic.
1106
+ *
1107
+ * @param {Uint8Array} source
1108
+ * @param {number} offset byte offset of the block in `source`
1109
+ * @param {number} block_width the footprint: 4, 5, 6, 8, 10 or 12
1110
+ * @param {number} block_height 4, 5, 6, 8, 10 or 12
1111
+ * @param {Uint8Array} out receives `block_width * block_height` texels, RGBA, raster order, from index 0
1112
+ *
1113
+ * @see Khronos Data Format Specification, "ASTC Compressed Texture Image Formats"
1114
+ * @author Alex Goldring
1115
+ * @copyright Company Named Limited (c) 2026
1116
+ */
1117
+ export function astc_srgb_decode_block(source, offset, block_width, block_height, out) {
1118
+ decode_block(source, offset, block_width, block_height, out, true);
1119
+ }