@woosh/meep-engine 3.79.0 → 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 (309) hide show
  1. package/CHANGELOG.md +62 -3
  2. package/README.md +1 -1
  3. package/package.json +1 -1
  4. package/src/format/image/webp/vp8/VP8BoolDecoder.d.ts +45 -0
  5. package/src/format/image/webp/vp8/VP8BoolDecoder.d.ts.map +1 -0
  6. package/src/format/image/webp/vp8/VP8BoolDecoder.js +137 -0
  7. package/src/format/image/webp/vp8/vp8_decode.d.ts +21 -0
  8. package/src/format/image/webp/vp8/vp8_decode.d.ts.map +1 -0
  9. package/src/format/image/webp/vp8/vp8_decode.js +756 -0
  10. package/src/format/image/webp/vp8/vp8_loop_filter.d.ts +31 -0
  11. package/src/format/image/webp/vp8/vp8_loop_filter.d.ts.map +1 -0
  12. package/src/format/image/webp/vp8/vp8_loop_filter.js +189 -0
  13. package/src/format/image/webp/vp8/vp8_predict.d.ts +48 -0
  14. package/src/format/image/webp/vp8/vp8_predict.d.ts.map +1 -0
  15. package/src/format/image/webp/vp8/vp8_predict.js +290 -0
  16. package/src/format/image/webp/vp8/vp8_tables.d.ts +34 -0
  17. package/src/format/image/webp/vp8/vp8_tables.d.ts.map +1 -0
  18. package/src/format/image/webp/vp8/vp8_tables.js +350 -0
  19. package/src/format/image/webp/vp8/vp8_transform.d.ts +22 -0
  20. package/src/format/image/webp/vp8/vp8_transform.d.ts.map +1 -0
  21. package/src/format/image/webp/vp8/vp8_transform.js +114 -0
  22. package/src/format/image/webp/vp8/vp8_yuv_to_rgba.d.ts +23 -0
  23. package/src/format/image/webp/vp8/vp8_yuv_to_rgba.d.ts.map +1 -0
  24. package/src/format/image/webp/vp8/vp8_yuv_to_rgba.js +133 -0
  25. package/src/format/image/webp/vp8l/VP8LBitReader.d.ts +47 -0
  26. package/src/format/image/webp/vp8l/VP8LBitReader.d.ts.map +1 -0
  27. package/src/format/image/webp/vp8l/VP8LBitReader.js +84 -0
  28. package/src/format/image/webp/vp8l/VP8LPrefixCode.d.ts +27 -0
  29. package/src/format/image/webp/vp8l/VP8LPrefixCode.d.ts.map +1 -0
  30. package/src/format/image/webp/vp8l/VP8LPrefixCode.js +184 -0
  31. package/src/format/image/webp/vp8l/vp8l_decode.d.ts +28 -0
  32. package/src/format/image/webp/vp8l/vp8l_decode.d.ts.map +1 -0
  33. package/src/format/image/webp/vp8l/vp8l_decode.js +261 -0
  34. package/src/format/image/webp/vp8l/vp8l_distance.d.ts +22 -0
  35. package/src/format/image/webp/vp8l/vp8l_distance.d.ts.map +1 -0
  36. package/src/format/image/webp/vp8l/vp8l_distance.js +62 -0
  37. package/src/format/image/webp/vp8l/vp8l_inverse_transforms.d.ts +50 -0
  38. package/src/format/image/webp/vp8l/vp8l_inverse_transforms.d.ts.map +1 -0
  39. package/src/format/image/webp/vp8l/vp8l_inverse_transforms.js +267 -0
  40. package/src/format/image/webp/vp8l/vp8l_read_prefix_code.d.ts +14 -0
  41. package/src/format/image/webp/vp8l/vp8l_read_prefix_code.d.ts.map +1 -0
  42. package/src/format/image/webp/vp8l/vp8l_read_prefix_code.js +99 -0
  43. package/src/format/image/webp/webp_decode.d.ts +23 -0
  44. package/src/format/image/webp/webp_decode.d.ts.map +1 -0
  45. package/src/format/image/webp/webp_decode.js +179 -0
  46. package/src/format/image/webp/webp_decode_alpha.d.ts +18 -0
  47. package/src/format/image/webp/webp_decode_alpha.d.ts.map +1 -0
  48. package/src/format/image/webp/webp_decode_alpha.js +84 -0
  49. package/src/format/texture/{basis → astc}/astc_block.d.ts +41 -0
  50. package/src/format/texture/astc/astc_block.d.ts.map +1 -0
  51. package/src/format/texture/{basis → astc}/astc_block.js +284 -164
  52. package/src/format/texture/astc/astc_decode_block.d.ts +68 -0
  53. package/src/format/texture/astc/astc_decode_block.d.ts.map +1 -0
  54. package/src/format/texture/astc/astc_decode_block.js +1119 -0
  55. package/src/format/texture/astc/astc_encode_block_4x4.d.ts +32 -0
  56. package/src/format/texture/astc/astc_encode_block_4x4.d.ts.map +1 -0
  57. package/src/format/texture/astc/astc_encode_block_4x4.js +181 -0
  58. package/src/format/texture/astc/astc_encode_block_4x4_rgba.d.ts +32 -0
  59. package/src/format/texture/astc/astc_encode_block_4x4_rgba.d.ts.map +1 -0
  60. package/src/format/texture/astc/astc_encode_block_4x4_rgba.js +337 -0
  61. package/src/format/texture/astc/astc_integer_sequence.d.ts.map +1 -0
  62. package/src/format/texture/{basis → astc}/astc_integer_sequence.js +251 -251
  63. package/src/format/texture/astc/astc_partition.d.ts.map +1 -0
  64. package/src/format/texture/{basis → astc}/astc_partition.js +199 -199
  65. package/src/format/texture/basis/transcode/etc1s_to_astc.js +329 -329
  66. package/src/format/texture/basis/transcode/etc1s_to_etc2.d.ts.map +1 -1
  67. package/src/format/texture/basis/transcode/etc1s_to_etc2.js +305 -332
  68. package/src/format/texture/basis/transcode/fit_endpoints.d.ts.map +1 -1
  69. package/src/format/texture/basis/transcode/fit_endpoints.js +14 -27
  70. package/src/format/texture/basis/uastc/uastc_bc7_tables.d.ts +66 -0
  71. package/src/format/texture/basis/uastc/uastc_bc7_tables.d.ts.map +1 -0
  72. package/src/format/texture/basis/uastc/uastc_bc7_tables.js +148 -0
  73. package/src/format/texture/basis/uastc/uastc_decode_block.js +463 -463
  74. package/src/format/texture/basis/uastc/uastc_to_astc.js +421 -421
  75. package/src/format/texture/basis/uastc/uastc_to_bc5.d.ts +1 -6
  76. package/src/format/texture/basis/uastc/uastc_to_bc5.d.ts.map +1 -1
  77. package/src/format/texture/basis/uastc/uastc_to_bc5.js +48 -115
  78. package/src/format/texture/basis/uastc/uastc_to_bc7.d.ts.map +1 -1
  79. package/src/format/texture/basis/uastc/uastc_to_bc7.js +604 -602
  80. package/src/format/texture/bc/bc1_decode_block.d.ts +19 -0
  81. package/src/format/texture/bc/bc1_decode_block.d.ts.map +1 -0
  82. package/src/format/texture/bc/bc1_decode_block.js +22 -0
  83. package/src/format/texture/bc/bc1_decode_colors.d.ts +27 -0
  84. package/src/format/texture/bc/bc1_decode_colors.d.ts.map +1 -0
  85. package/src/format/texture/bc/bc1_decode_colors.js +100 -0
  86. package/src/format/texture/bc/bc2_decode_block.d.ts +18 -0
  87. package/src/format/texture/bc/bc2_decode_block.d.ts.map +1 -0
  88. package/src/format/texture/bc/bc2_decode_block.js +28 -0
  89. package/src/format/texture/bc/bc3_decode_block.d.ts +18 -0
  90. package/src/format/texture/bc/bc3_decode_block.d.ts.map +1 -0
  91. package/src/format/texture/bc/bc3_decode_block.js +23 -0
  92. package/src/format/texture/bc/bc4_decode_channel.d.ts +56 -0
  93. package/src/format/texture/bc/bc4_decode_channel.d.ts.map +1 -0
  94. package/src/format/texture/bc/bc4_decode_channel.js +138 -0
  95. package/src/format/texture/bc/bc4_encode_block.d.ts +43 -0
  96. package/src/format/texture/bc/bc4_encode_block.d.ts.map +1 -0
  97. package/src/format/texture/bc/bc4_encode_block.js +324 -0
  98. package/src/format/texture/bc/bc4_snorm_decode_block.d.ts +18 -0
  99. package/src/format/texture/bc/bc4_snorm_decode_block.d.ts.map +1 -0
  100. package/src/format/texture/bc/bc4_snorm_decode_block.js +27 -0
  101. package/src/format/texture/bc/bc4_unorm_decode_block.d.ts +17 -0
  102. package/src/format/texture/bc/bc4_unorm_decode_block.d.ts.map +1 -0
  103. package/src/format/texture/bc/bc4_unorm_decode_block.js +26 -0
  104. package/src/format/texture/bc/bc5_encode_block.d.ts +25 -0
  105. package/src/format/texture/bc/bc5_encode_block.d.ts.map +1 -0
  106. package/src/format/texture/bc/bc5_encode_block.js +34 -0
  107. package/src/format/texture/bc/bc5_snorm_decode_block.d.ts +18 -0
  108. package/src/format/texture/bc/bc5_snorm_decode_block.d.ts.map +1 -0
  109. package/src/format/texture/bc/bc5_snorm_decode_block.js +27 -0
  110. package/src/format/texture/bc/bc5_unorm_decode_block.d.ts +17 -0
  111. package/src/format/texture/bc/bc5_unorm_decode_block.d.ts.map +1 -0
  112. package/src/format/texture/bc/bc5_unorm_decode_block.js +26 -0
  113. package/src/format/texture/bc/bc6h_decode_texels.d.ts +30 -0
  114. package/src/format/texture/bc/bc6h_decode_texels.d.ts.map +1 -0
  115. package/src/format/texture/bc/bc6h_decode_texels.js +430 -0
  116. package/src/format/texture/bc/bc6h_sfloat_decode_block.d.ts +20 -0
  117. package/src/format/texture/bc/bc6h_sfloat_decode_block.d.ts.map +1 -0
  118. package/src/format/texture/bc/bc6h_sfloat_decode_block.js +23 -0
  119. package/src/format/texture/bc/bc6h_ufloat_decode_block.d.ts +18 -0
  120. package/src/format/texture/bc/bc6h_ufloat_decode_block.d.ts.map +1 -0
  121. package/src/format/texture/bc/bc6h_ufloat_decode_block.js +21 -0
  122. package/src/format/texture/bc/bc7_decode_block.d.ts +30 -0
  123. package/src/format/texture/bc/bc7_decode_block.d.ts.map +1 -0
  124. package/src/format/texture/bc/bc7_decode_block.js +232 -0
  125. package/src/format/texture/bc/bc7_encode_block.d.ts +39 -0
  126. package/src/format/texture/bc/bc7_encode_block.d.ts.map +1 -0
  127. package/src/format/texture/bc/bc7_encode_block.js +423 -0
  128. package/src/format/texture/bc/bc7_tables.d.ts +126 -0
  129. package/src/format/texture/bc/bc7_tables.d.ts.map +1 -0
  130. package/src/format/texture/{basis/uastc → bc}/bc7_tables.js +225 -276
  131. package/src/format/texture/bc/bc7_write_block.d.ts +65 -0
  132. package/src/format/texture/bc/bc7_write_block.d.ts.map +1 -0
  133. package/src/format/texture/{basis/uastc → bc}/bc7_write_block.js +185 -227
  134. package/src/format/texture/etc/eac_decode_channel.d.ts +50 -0
  135. package/src/format/texture/etc/eac_decode_channel.d.ts.map +1 -0
  136. package/src/format/texture/etc/eac_decode_channel.js +142 -0
  137. package/src/format/texture/etc/eac_modifiers.d.ts +15 -0
  138. package/src/format/texture/etc/eac_modifiers.d.ts.map +1 -0
  139. package/src/format/texture/etc/eac_modifiers.js +31 -0
  140. package/src/format/texture/etc/eac_r11_snorm_decode_block.d.ts +21 -0
  141. package/src/format/texture/etc/eac_r11_snorm_decode_block.d.ts.map +1 -0
  142. package/src/format/texture/etc/eac_r11_snorm_decode_block.js +30 -0
  143. package/src/format/texture/etc/eac_r11_unorm_decode_block.d.ts +20 -0
  144. package/src/format/texture/etc/eac_r11_unorm_decode_block.d.ts.map +1 -0
  145. package/src/format/texture/etc/eac_r11_unorm_decode_block.js +29 -0
  146. package/src/format/texture/etc/eac_rg11_snorm_decode_block.d.ts +19 -0
  147. package/src/format/texture/etc/eac_rg11_snorm_decode_block.d.ts.map +1 -0
  148. package/src/format/texture/etc/eac_rg11_snorm_decode_block.js +28 -0
  149. package/src/format/texture/etc/eac_rg11_unorm_decode_block.d.ts +19 -0
  150. package/src/format/texture/etc/eac_rg11_unorm_decode_block.d.ts.map +1 -0
  151. package/src/format/texture/etc/eac_rg11_unorm_decode_block.js +28 -0
  152. package/src/format/texture/etc/etc2_decode_color.d.ts +25 -0
  153. package/src/format/texture/etc/etc2_decode_color.d.ts.map +1 -0
  154. package/src/format/texture/etc/etc2_decode_color.js +370 -0
  155. package/src/format/texture/etc/etc2_rgb8_decode_block.d.ts +18 -0
  156. package/src/format/texture/etc/etc2_rgb8_decode_block.d.ts.map +1 -0
  157. package/src/format/texture/etc/etc2_rgb8_decode_block.js +21 -0
  158. package/src/format/texture/etc/etc2_rgb8a1_decode_block.d.ts +21 -0
  159. package/src/format/texture/etc/etc2_rgb8a1_decode_block.d.ts.map +1 -0
  160. package/src/format/texture/etc/etc2_rgb8a1_decode_block.js +24 -0
  161. package/src/format/texture/etc/etc2_rgba8_decode_block.d.ts +18 -0
  162. package/src/format/texture/etc/etc2_rgba8_decode_block.d.ts.map +1 -0
  163. package/src/format/texture/etc/etc2_rgba8_decode_block.js +24 -0
  164. package/src/format/texture/fit/fit_line.d.ts +23 -0
  165. package/src/format/texture/fit/fit_line.d.ts.map +1 -0
  166. package/src/format/texture/fit/fit_line.js +123 -0
  167. package/src/format/texture/fit/fit_line_refine.d.ts +21 -0
  168. package/src/format/texture/fit/fit_line_refine.d.ts.map +1 -0
  169. package/src/format/texture/fit/fit_line_refine.js +69 -0
  170. package/src/format/texture/fit/fit_line_solve.d.ts +23 -0
  171. package/src/format/texture/fit/fit_line_solve.d.ts.map +1 -0
  172. package/src/format/texture/fit/fit_line_solve.js +71 -0
  173. package/src/format/texture/texel_decode_image.d.ts +44 -0
  174. package/src/format/texture/texel_decode_image.d.ts.map +1 -0
  175. package/src/format/texture/texel_decode_image.js +251 -0
  176. package/src/format/texture/texel_encode_image.d.ts +77 -0
  177. package/src/format/texture/texel_encode_image.d.ts.map +1 -0
  178. package/src/format/texture/texel_encode_image.js +187 -0
  179. package/src/shade/renderer/ShadeIndirectLightingMode.js +2 -0
  180. package/src/shade/renderer/acoustics/GPUAcousticLattice.d.ts +1 -1
  181. package/src/shade/renderer/acoustics/GPUAcoustics.d.ts +1 -1
  182. package/src/shade/renderer/loader/mtf/mtf_encode_texture.d.ts +1 -0
  183. package/src/shade/renderer/loader/mtf/mtf_encode_texture.d.ts.map +1 -1
  184. package/src/shade/renderer/loader/mtf/mtf_encode_texture.js +102 -28
  185. package/src/shade/renderer/loader/mtf/mtf_replace_textures.d.ts +19 -0
  186. package/src/shade/renderer/loader/mtf/mtf_replace_textures.d.ts.map +1 -0
  187. package/src/shade/renderer/loader/mtf/mtf_replace_textures.js +60 -0
  188. package/src/shade/renderer/loader/mtf/mtf_write.d.ts.map +1 -1
  189. package/src/shade/renderer/loader/mtf/mtf_write.js +7 -31
  190. package/src/shade/renderer/loader/mtf/mtf_write_collection.d.ts +23 -0
  191. package/src/shade/renderer/loader/mtf/mtf_write_collection.d.ts.map +1 -0
  192. package/src/shade/renderer/loader/mtf/mtf_write_collection.js +36 -0
  193. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4.d.ts +13 -0
  194. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4.d.ts.map +1 -0
  195. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4.js +39 -0
  196. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgb.d.ts +3 -2
  197. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgb.d.ts.map +1 -1
  198. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgb.js +6 -21
  199. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgba.d.ts +42 -0
  200. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgba.d.ts.map +1 -0
  201. package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgba.js +612 -0
  202. package/src/shade/renderer/texture/encode/chunk_bc1_encode_block.d.ts +5 -4
  203. package/src/shade/renderer/texture/encode/chunk_bc1_encode_block.d.ts.map +1 -1
  204. package/src/shade/renderer/texture/encode/chunk_bc1_encode_block.js +8 -25
  205. package/src/shade/renderer/texture/encode/chunk_bc6h_encode_block_mode11.d.ts.map +1 -1
  206. package/src/shade/renderer/texture/encode/chunk_bc6h_encode_block_mode11.js +3 -19
  207. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block.d.ts +14 -4
  208. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block.d.ts.map +1 -1
  209. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block.js +65 -54
  210. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block_mode6.d.ts +2 -2
  211. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block_mode6.d.ts.map +1 -1
  212. package/src/shade/renderer/texture/encode/chunk_bc7_encode_block_mode6.js +5 -22
  213. package/src/shade/renderer/texture/encode/chunk_bc7_partition_2.js +1 -1
  214. package/src/shade/renderer/texture/encode/chunk_scatter_principal_axis.d.ts +27 -0
  215. package/src/shade/renderer/texture/encode/chunk_scatter_principal_axis.d.ts.map +1 -0
  216. package/src/shade/renderer/texture/encode/chunk_scatter_principal_axis.js +147 -0
  217. package/src/shade/renderer/texture/encode/shader_texture_encode_astc_4x4.d.ts +3 -4
  218. package/src/shade/renderer/texture/encode/shader_texture_encode_astc_4x4.d.ts.map +1 -1
  219. package/src/shade/renderer/texture/encode/shader_texture_encode_astc_4x4.js +6 -13
  220. package/src/shade/renderer/texture/encode/shader_texture_encode_bc7_rgb.d.ts +13 -0
  221. package/src/shade/renderer/texture/encode/shader_texture_encode_bc7_rgb.d.ts.map +1 -0
  222. package/src/shade/renderer/texture/encode/shader_texture_encode_bc7_rgb.js +66 -0
  223. package/src/shade/renderer/texture/encode/texture_encode.d.ts +28 -1
  224. package/src/shade/renderer/texture/encode/texture_encode.d.ts.map +1 -1
  225. package/src/shade/renderer/texture/encode/texture_encode.js +202 -168
  226. package/src/shade/renderer/texture/encode/texture_encode_shader.d.ts +13 -1
  227. package/src/shade/renderer/texture/encode/texture_encode_shader.d.ts.map +1 -1
  228. package/src/shade/renderer/texture/encode/texture_encode_shader.js +146 -108
  229. package/src/shade/renderer/texture/format/texture_formats_to_build.d.ts +20 -0
  230. package/src/shade/renderer/texture/format/texture_formats_to_build.d.ts.map +1 -0
  231. package/src/shade/renderer/texture/format/texture_formats_to_build.js +98 -0
  232. package/src/shade/renderer/texture/mipmaps/WebGPUMipmapGenerator.d.ts.map +1 -1
  233. package/src/shade/renderer/texture/mipmaps/WebGPUMipmapGenerator.js +4 -23
  234. package/src/shade/renderer/texture/mipmaps/cpu/MipmapBilinearAxis.d.ts +53 -0
  235. package/src/shade/renderer/texture/mipmaps/cpu/MipmapBilinearAxis.d.ts.map +1 -0
  236. package/src/shade/renderer/texture/mipmaps/cpu/MipmapBilinearAxis.js +76 -0
  237. package/src/shade/renderer/texture/mipmaps/cpu/MipmapKernelAxis.d.ts +40 -0
  238. package/src/shade/renderer/texture/mipmaps/cpu/MipmapKernelAxis.d.ts.map +1 -0
  239. package/src/shade/renderer/texture/mipmaps/cpu/MipmapKernelAxis.js +43 -0
  240. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_bilinear_centres.d.ts +17 -0
  241. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_bilinear_centres.d.ts.map +1 -0
  242. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_bilinear_centres.js +29 -0
  243. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_bilinear_sample.d.ts +21 -0
  244. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_bilinear_sample.d.ts.map +1 -0
  245. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_bilinear_sample.js +91 -0
  246. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_chain_cpu.d.ts +32 -0
  247. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_chain_cpu.d.ts.map +1 -0
  248. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_chain_cpu.js +216 -0
  249. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_cubic_filter_cpu.d.ts +30 -0
  250. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_cubic_filter_cpu.d.ts.map +1 -0
  251. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_cubic_filter_cpu.js +134 -0
  252. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_catmull_rom_cpu.d.ts +16 -0
  253. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_catmull_rom_cpu.d.ts.map +1 -0
  254. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_catmull_rom_cpu.js +33 -0
  255. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_linear_cpu.d.ts +18 -0
  256. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_linear_cpu.d.ts.map +1 -0
  257. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_linear_cpu.js +71 -0
  258. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_linear_normal_cpu.d.ts +20 -0
  259. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_linear_normal_cpu.d.ts.map +1 -0
  260. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_linear_normal_cpu.js +57 -0
  261. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_magic_kernel_cpu.d.ts +18 -0
  262. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_magic_kernel_cpu.d.ts.map +1 -0
  263. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_magic_kernel_cpu.js +111 -0
  264. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_mitchell_cpu.d.ts +16 -0
  265. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_mitchell_cpu.d.ts.map +1 -0
  266. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_mitchell_cpu.js +33 -0
  267. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_mks_cpu.d.ts +18 -0
  268. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_mks_cpu.d.ts.map +1 -0
  269. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_mks_cpu.js +128 -0
  270. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_wronski2021_cpu.d.ts +21 -0
  271. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_wronski2021_cpu.d.ts.map +1 -0
  272. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_wronski2021_cpu.js +169 -0
  273. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_kernel_reduce.d.ts +21 -0
  274. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_kernel_reduce.d.ts.map +1 -0
  275. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_kernel_reduce.js +119 -0
  276. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_source_centre.d.ts +16 -0
  277. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_source_centre.d.ts.map +1 -0
  278. package/src/shade/renderer/texture/mipmaps/cpu/mipmap_source_centre.js +19 -0
  279. package/src/shade/renderer/texture/mipmaps/cpu/texels_f32_to_rgba8unorm.d.ts +24 -0
  280. package/src/shade/renderer/texture/mipmaps/cpu/texels_f32_to_rgba8unorm.d.ts.map +1 -0
  281. package/src/shade/renderer/texture/mipmaps/cpu/texels_f32_to_rgba8unorm.js +41 -0
  282. package/src/shade/renderer/texture/mipmaps/cpu/texels_f32_to_rgba8unorm_srgb.d.ts +24 -0
  283. package/src/shade/renderer/texture/mipmaps/cpu/texels_f32_to_rgba8unorm_srgb.d.ts.map +1 -0
  284. package/src/shade/renderer/texture/mipmaps/cpu/texels_f32_to_rgba8unorm_srgb.js +140 -0
  285. package/src/shade/renderer/texture/mipmaps/cpu/texels_rgba8unorm_srgb_to_f32.d.ts +21 -0
  286. package/src/shade/renderer/texture/mipmaps/cpu/texels_rgba8unorm_srgb_to_f32.d.ts.map +1 -0
  287. package/src/shade/renderer/texture/mipmaps/cpu/texels_rgba8unorm_srgb_to_f32.js +35 -0
  288. package/src/shade/renderer/texture/mipmaps/cpu/texels_rgba8unorm_to_f32.d.ts +19 -0
  289. package/src/shade/renderer/texture/mipmaps/cpu/texels_rgba8unorm_to_f32.d.ts.map +1 -0
  290. package/src/shade/renderer/texture/mipmaps/cpu/texels_rgba8unorm_to_f32.js +27 -0
  291. package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_catmull_rom.js +4 -4
  292. package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_linear.d.ts +13 -0
  293. package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_linear.d.ts.map +1 -1
  294. package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_linear.js +54 -4
  295. package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_mitchell.js +4 -4
  296. package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_mks.d.ts.map +1 -1
  297. package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_mks.js +9 -13
  298. package/src/shade/renderer/texture/texture_block_encodings.d.ts +33 -0
  299. package/src/shade/renderer/texture/texture_block_encodings.d.ts.map +1 -0
  300. package/src/shade/renderer/texture/texture_block_encodings.js +89 -0
  301. package/src/format/texture/basis/astc_block.d.ts.map +0 -1
  302. package/src/format/texture/basis/astc_integer_sequence.d.ts.map +0 -1
  303. package/src/format/texture/basis/astc_partition.d.ts.map +0 -1
  304. package/src/format/texture/basis/uastc/bc7_tables.d.ts +0 -111
  305. package/src/format/texture/basis/uastc/bc7_tables.d.ts.map +0 -1
  306. package/src/format/texture/basis/uastc/bc7_write_block.d.ts +0 -124
  307. package/src/format/texture/basis/uastc/bc7_write_block.d.ts.map +0 -1
  308. /package/src/format/texture/{basis → astc}/astc_integer_sequence.d.ts +0 -0
  309. /package/src/format/texture/{basis → astc}/astc_partition.d.ts +0 -0
@@ -1,329 +1,329 @@
1
- import {
2
- ASTC_BLOCK_BYTES,
3
- ASTC_WEIGHT_UNQUANTIZED,
4
- astc_interpolate,
5
- astc_order_endpoints,
6
- astc_write_block
7
- } from "../astc_block.js";
8
- import { etc1s_block_colors } from "../etc1s/etc1s_block_colors.js";
9
- import { number_compare_ascending } from "../../../../core/primitives/numbers/number_compare_ascending.js";
10
-
11
- /**
12
- * Bits a weight takes in the blocks this writes, and the levels that follow from it.
13
- *
14
- * **Two, where {@link uastc_to_astc} takes three.** An ETC1S block holds four colours and no more,
15
- * so eight weight levels would spend half of them describing points the source never had — the
16
- * limit here is the source, not the container. Two bits is also what leaves room for the endpoints
17
- * a four-channel mode would need, should alpha ever be worth carrying this way.
18
- *
19
- * @readonly
20
- * @type {number}
21
- */
22
- const WEIGHT_BITS = 2;
23
-
24
- /**
25
- * @readonly
26
- * @type {number[]}
27
- */
28
- const LEVELS = ASTC_WEIGHT_UNQUANTIZED[WEIGHT_BITS];
29
-
30
- /**
31
- * Transcode ETC1S to ASTC 4x4.
32
- *
33
- * **The mobile counterpart to {@link etc1s_to_etc2}**, and the one compressed format that appears in
34
- * every role's preference list — every recent phone samples it, where ETC2 is the older floor. Both
35
- * are eight bits a texel.
36
- *
37
- * **A close fit, because an ETC1S block is already a line.** Its four colours are one base colour
38
- * plus the same offset in each channel, so they lie on a line parallel to the grey axis, which is
39
- * exactly what a single-partition ASTC block with two endpoints and an interpolant represents. What
40
- * is left is choosing where on that line the four weight levels sit, which {@link fit_block} searches.
41
- *
42
- * **Opaque only.** ASTC can carry alpha, but not with a shared weight plane: an ETC1S payload's
43
- * colour and alpha come from two independent slices with their own selectors, and forcing them onto
44
- * one set of weights would wreck both. The dual-plane block mode that would separate them cannot also
45
- * hold eight endpoints and thirty-two weight bits in 128 bits. So this declares no alpha and a
46
- * payload carrying some falls through to a target that has room — the mechanism BC1 has used since
47
- * step 9, and which `ktx2_read` now applies before a format is committed to rather than after.
48
- *
49
- * @param {Etc1sSlice} slice
50
- * @param {Etc1sSlice|undefined} _alpha_slice refused before this is called; see above
51
- * @param {Etc1sEndpointCodebook} endpoints
52
- * @param {Etc1sSelectorCodebook} selectors
53
- * @returns {Uint8Array} tightly packed ASTC blocks, in raster order
54
- *
55
- * @author Alex Goldring
56
- * @copyright Company Named Limited (c) 2026
57
- */
58
- export function etc1s_to_astc(slice, _alpha_slice, endpoints, selectors) {
59
- const block_count = slice.blocks_x * slice.blocks_y;
60
-
61
- const out = new Uint8Array(block_count * ASTC_BLOCK_BYTES);
62
-
63
- const palette = new Uint8Array(12);
64
- const fitted = new Int32Array(6);
65
- const weights = new Uint8Array(16);
66
-
67
- for (let block = 0; block < block_count; block++) {
68
- etc1s_block_colors(
69
- palette, 0, endpoints.color5, endpoints.intensity, slice.endpoint_index[block]
70
- );
71
-
72
- const selector_base = slice.selector_index[block] * 16;
73
-
74
- fit_block(fitted, weights, palette, selectors.selectors, selector_base);
75
-
76
- astc_order_endpoints(fitted, weights, LEVELS.length - 1);
77
-
78
- astc_write_block(out, block * ASTC_BLOCK_BYTES, fitted, weights, WEIGHT_BITS);
79
- }
80
-
81
- return out;
82
- }
83
-
84
- /**
85
- * Every strictly increasing choice of `count` of the four weight levels.
86
- *
87
- * Enumerated rather than reasoned about: fifteen in total across all four sizes, and the arithmetic
88
- * that would pick the right one directly is longer than the list.
89
- *
90
- * @readonly
91
- * @type {number[][][]}
92
- */
93
- const PLACEMENTS = [0, 1, 2, 3, 4].map(count => {
94
- const out = [];
95
-
96
- const walk = (start, chosen) => {
97
- if (chosen.length === count) {
98
- out.push(chosen.slice());
99
-
100
- return;
101
- }
102
-
103
- for (let level = start; level < 4; level++) {
104
- chosen.push(level);
105
- walk(level + 1, chosen);
106
- chosen.pop();
107
- }
108
- };
109
-
110
- walk(0, []);
111
-
112
- return out;
113
- });
114
-
115
- /**
116
- * Fit a block: which weight level each of its selectors takes, and the endpoints that follow.
117
- *
118
- * **The selectors are placed on the weight levels rather than used as them.** ETC1S's four colours
119
- * and ASTC's four weight levels are both ordered darkest to brightest, so the identity mapping is
120
- * available and is what a block using its whole palette is stuck with — but a block using only two
121
- * or three entries should spread those over all four levels instead, which costs nothing and is
122
- * exact for two. Skipping this is worth about nine decibels, and it is what the reference transcoder
123
- * does.
124
- *
125
- * The two orderings are not alike even when all four are used: ETC1S's middle pair sits at roughly
126
- * 0.37 and 0.63 of the range against ASTC's 21/64 and 43/64, so the identity mapping is a fit rather
127
- * than an equality. Nothing better is available at two bits a weight.
128
- *
129
- * @param {Int32Array} endpoints_out six values, `R0 R1 G0 G1 B0 B1`
130
- * @param {Uint8Array} weights_out sixteen weight levels, in raster order
131
- * @param {Uint8Array} palette twelve bytes, four RGB triples
132
- * @param {Uint8Array} selector_values
133
- * @param {number} selector_base
134
- */
135
- function fit_block(endpoints_out, weights_out, palette, selector_values, selector_base) {
136
- const used = [];
137
-
138
- for (let texel = 0; texel < 16; texel++) {
139
- const selector = selector_values[selector_base + texel];
140
-
141
- if (!used.includes(selector)) {
142
- used.push(selector);
143
- }
144
- }
145
-
146
- used.sort(number_compare_ascending);
147
-
148
- let best_error = Infinity;
149
-
150
- const level_of = new Int32Array(4);
151
- const candidate = new Int32Array(6);
152
-
153
- for (const placement of PLACEMENTS[used.length]) {
154
- for (let i = 0; i < used.length; i++) {
155
- level_of[used[i]] = placement[i];
156
- }
157
-
158
- const error = fit_endpoints(candidate, palette, selector_values, selector_base, level_of);
159
-
160
- if (error < best_error) {
161
- best_error = error;
162
-
163
- endpoints_out.set(candidate);
164
-
165
- for (let texel = 0; texel < 16; texel++) {
166
- weights_out[texel] = level_of[selector_values[selector_base + texel]];
167
- }
168
- }
169
- }
170
-
171
- refine(endpoints_out, palette, selector_values, selector_base, weights_out);
172
- }
173
-
174
- /**
175
- * Nudge each channel's endpoints to the best pair within a step or two of the least-squares one.
176
- *
177
- * **Least squares minimises the wrong thing by a little.** It fits real-valued endpoints against
178
- * real-valued targets; what gets written is the rounded pair, and what is read back is
179
- * {@link interpolate}'s integer arithmetic on it. Those two roundings do not commute, so the rounded
180
- * least-squares answer is usually but not always the best integer pair — a step in one direction
181
- * often trades a large error on one texel for small ones on several.
182
- *
183
- * Only the winning placement is refined, and only over a small window. The placement search above
184
- * runs first on the cheaper score, because refining all fifteen would multiply the cost of every
185
- * block by more than it buys: this closes the last level against the reference encoder, which is
186
- * worth a bounded pass and not an unbounded one.
187
- *
188
- * Channels are independent once the weights are fixed, so each is searched on its own — three
189
- * searches of twenty-five candidates rather than one of fifteen thousand.
190
- *
191
- * @param {Int32Array} endpoints six values, modified in place
192
- * @param {Uint8Array} palette
193
- * @param {Uint8Array} selector_values
194
- * @param {number} selector_base
195
- * @param {Uint8Array} weights the chosen weight level per texel
196
- */
197
- function refine(endpoints, palette, selector_values, selector_base, weights) {
198
- for (let channel = 0; channel < 3; channel++) {
199
- const start0 = endpoints[channel * 2];
200
- const start1 = endpoints[channel * 2 + 1];
201
-
202
- let best0 = start0;
203
- let best1 = start1;
204
- let best_error = Infinity;
205
-
206
- for (let d0 = -2; d0 <= 2; d0++) {
207
- for (let d1 = -2; d1 <= 2; d1++) {
208
- const q0 = clamp255(start0 + d0);
209
- const q1 = clamp255(start1 + d1);
210
-
211
- let error = 0;
212
-
213
- for (let texel = 0; texel < 16; texel++) {
214
- const decoded = astc_interpolate(q0, q1, LEVELS[weights[texel]]);
215
-
216
- const delta = decoded
217
- - palette[selector_values[selector_base + texel] * 3 + channel];
218
-
219
- error += delta * delta;
220
- }
221
-
222
- if (error < best_error) {
223
- best_error = error;
224
- best0 = q0;
225
- best1 = q1;
226
- }
227
- }
228
- }
229
-
230
- endpoints[channel * 2] = best0;
231
- endpoints[channel * 2 + 1] = best1;
232
- }
233
- }
234
-
235
- /**
236
- * Least-squares endpoints for one placement, and the squared error it leaves.
237
- *
238
- * A two-parameter linear fit per channel, sharing one set of `t` statistics because every channel's
239
- * texels sit at the same positions along the line. The fit is real-valued and the scoring is not:
240
- * what is compared is what {@link interpolate} will actually produce from the rounded, clamped
241
- * endpoints, so a placement is judged on the block that will be written.
242
- *
243
- * @param {Int32Array} out six values
244
- * @param {Uint8Array} palette
245
- * @param {Uint8Array} selector_values
246
- * @param {number} selector_base
247
- * @param {Int32Array} level_of weight level for each selector value
248
- * @returns {number} summed squared error over all sixteen texels and three channels
249
- */
250
- function fit_endpoints(out, palette, selector_values, selector_base, level_of) {
251
- let sum_t = 0;
252
- let sum_tt = 0;
253
-
254
- for (let texel = 0; texel < 16; texel++) {
255
- const t = LEVELS[level_of[selector_values[selector_base + texel]]] / 64;
256
-
257
- sum_t += t;
258
- sum_tt += t * t;
259
- }
260
-
261
- const n = 16;
262
-
263
- /*
264
- The normal equations for `value = e0 (1 - t) + e1 t`, written in terms of `e0` and `d = e1 - e0`
265
- so that the shared statistics fall out: `sum(v) = n e0 + d sum(t)` and
266
- `sum(v t) = e0 sum(t) + d sum(t t)`.
267
- */
268
- const determinant = n * sum_tt - sum_t * sum_t;
269
-
270
- let error = 0;
271
-
272
- for (let channel = 0; channel < 3; channel++) {
273
- let sum_v = 0;
274
- let sum_vt = 0;
275
-
276
- for (let texel = 0; texel < 16; texel++) {
277
- const selector = selector_values[selector_base + texel];
278
-
279
- const v = palette[selector * 3 + channel];
280
- const t = LEVELS[level_of[selector]] / 64;
281
-
282
- sum_v += v;
283
- sum_vt += v * t;
284
- }
285
-
286
- let e0;
287
- let d;
288
-
289
- if (determinant === 0) {
290
- /*
291
- Every texel at the same weight, so the line is a point and only one endpoint is
292
- determined. Both are set to it, which reproduces the block exactly whatever the weights
293
- then say.
294
- */
295
- e0 = sum_v / n;
296
- d = 0;
297
- } else {
298
- e0 = (sum_v * sum_tt - sum_vt * sum_t) / determinant;
299
- d = (n * sum_vt - sum_v * sum_t) / determinant;
300
- }
301
-
302
- const q0 = clamp255(Math.round(e0));
303
- const q1 = clamp255(Math.round(e0 + d));
304
-
305
- out[channel * 2] = q0;
306
- out[channel * 2 + 1] = q1;
307
-
308
- for (let texel = 0; texel < 16; texel++) {
309
- const selector = selector_values[selector_base + texel];
310
-
311
- const decoded = astc_interpolate(q0, q1, LEVELS[level_of[selector]]);
312
-
313
- const delta = decoded - palette[selector * 3 + channel];
314
-
315
- error += delta * delta;
316
- }
317
- }
318
-
319
- return error;
320
- }
321
-
322
- /**
323
- * @param {number} value
324
- * @returns {number} `value` brought into `[0, 255]`
325
- */
326
- function clamp255(value) {
327
- return value < 0 ? 0 : value > 255 ? 255 : value;
328
- }
329
-
1
+ import {
2
+ ASTC_BLOCK_BYTES,
3
+ ASTC_WEIGHT_UNQUANTIZED,
4
+ astc_interpolate,
5
+ astc_order_endpoints,
6
+ astc_write_block
7
+ } from "../../astc/astc_block.js";
8
+ import { etc1s_block_colors } from "../etc1s/etc1s_block_colors.js";
9
+ import { number_compare_ascending } from "../../../../core/primitives/numbers/number_compare_ascending.js";
10
+
11
+ /**
12
+ * Bits a weight takes in the blocks this writes, and the levels that follow from it.
13
+ *
14
+ * **Two, where {@link uastc_to_astc} takes three.** An ETC1S block holds four colours and no more,
15
+ * so eight weight levels would spend half of them describing points the source never had — the
16
+ * limit here is the source, not the container. Two bits is also what leaves room for the endpoints
17
+ * a four-channel mode would need, should alpha ever be worth carrying this way.
18
+ *
19
+ * @readonly
20
+ * @type {number}
21
+ */
22
+ const WEIGHT_BITS = 2;
23
+
24
+ /**
25
+ * @readonly
26
+ * @type {number[]}
27
+ */
28
+ const LEVELS = ASTC_WEIGHT_UNQUANTIZED[WEIGHT_BITS];
29
+
30
+ /**
31
+ * Transcode ETC1S to ASTC 4x4.
32
+ *
33
+ * **The mobile counterpart to {@link etc1s_to_etc2}**, and the one compressed format that appears in
34
+ * every role's preference list — every recent phone samples it, where ETC2 is the older floor. Both
35
+ * are eight bits a texel.
36
+ *
37
+ * **A close fit, because an ETC1S block is already a line.** Its four colours are one base colour
38
+ * plus the same offset in each channel, so they lie on a line parallel to the grey axis, which is
39
+ * exactly what a single-partition ASTC block with two endpoints and an interpolant represents. What
40
+ * is left is choosing where on that line the four weight levels sit, which {@link fit_block} searches.
41
+ *
42
+ * **Opaque only.** ASTC can carry alpha, but not with a shared weight plane: an ETC1S payload's
43
+ * colour and alpha come from two independent slices with their own selectors, and forcing them onto
44
+ * one set of weights would wreck both. The dual-plane block mode that would separate them cannot also
45
+ * hold eight endpoints and thirty-two weight bits in 128 bits. So this declares no alpha and a
46
+ * payload carrying some falls through to a target that has room — the mechanism BC1 has used since
47
+ * step 9, and which `ktx2_read` now applies before a format is committed to rather than after.
48
+ *
49
+ * @param {Etc1sSlice} slice
50
+ * @param {Etc1sSlice|undefined} _alpha_slice refused before this is called; see above
51
+ * @param {Etc1sEndpointCodebook} endpoints
52
+ * @param {Etc1sSelectorCodebook} selectors
53
+ * @returns {Uint8Array} tightly packed ASTC blocks, in raster order
54
+ *
55
+ * @author Alex Goldring
56
+ * @copyright Company Named Limited (c) 2026
57
+ */
58
+ export function etc1s_to_astc(slice, _alpha_slice, endpoints, selectors) {
59
+ const block_count = slice.blocks_x * slice.blocks_y;
60
+
61
+ const out = new Uint8Array(block_count * ASTC_BLOCK_BYTES);
62
+
63
+ const palette = new Uint8Array(12);
64
+ const fitted = new Int32Array(6);
65
+ const weights = new Uint8Array(16);
66
+
67
+ for (let block = 0; block < block_count; block++) {
68
+ etc1s_block_colors(
69
+ palette, 0, endpoints.color5, endpoints.intensity, slice.endpoint_index[block]
70
+ );
71
+
72
+ const selector_base = slice.selector_index[block] * 16;
73
+
74
+ fit_block(fitted, weights, palette, selectors.selectors, selector_base);
75
+
76
+ astc_order_endpoints(fitted, weights, LEVELS.length - 1);
77
+
78
+ astc_write_block(out, block * ASTC_BLOCK_BYTES, fitted, weights, WEIGHT_BITS);
79
+ }
80
+
81
+ return out;
82
+ }
83
+
84
+ /**
85
+ * Every strictly increasing choice of `count` of the four weight levels.
86
+ *
87
+ * Enumerated rather than reasoned about: fifteen in total across all four sizes, and the arithmetic
88
+ * that would pick the right one directly is longer than the list.
89
+ *
90
+ * @readonly
91
+ * @type {number[][][]}
92
+ */
93
+ const PLACEMENTS = [0, 1, 2, 3, 4].map(count => {
94
+ const out = [];
95
+
96
+ const walk = (start, chosen) => {
97
+ if (chosen.length === count) {
98
+ out.push(chosen.slice());
99
+
100
+ return;
101
+ }
102
+
103
+ for (let level = start; level < 4; level++) {
104
+ chosen.push(level);
105
+ walk(level + 1, chosen);
106
+ chosen.pop();
107
+ }
108
+ };
109
+
110
+ walk(0, []);
111
+
112
+ return out;
113
+ });
114
+
115
+ /**
116
+ * Fit a block: which weight level each of its selectors takes, and the endpoints that follow.
117
+ *
118
+ * **The selectors are placed on the weight levels rather than used as them.** ETC1S's four colours
119
+ * and ASTC's four weight levels are both ordered darkest to brightest, so the identity mapping is
120
+ * available and is what a block using its whole palette is stuck with — but a block using only two
121
+ * or three entries should spread those over all four levels instead, which costs nothing and is
122
+ * exact for two. Skipping this is worth about nine decibels, and it is what the reference transcoder
123
+ * does.
124
+ *
125
+ * The two orderings are not alike even when all four are used: ETC1S's middle pair sits at roughly
126
+ * 0.37 and 0.63 of the range against ASTC's 21/64 and 43/64, so the identity mapping is a fit rather
127
+ * than an equality. Nothing better is available at two bits a weight.
128
+ *
129
+ * @param {Int32Array} endpoints_out six values, `R0 R1 G0 G1 B0 B1`
130
+ * @param {Uint8Array} weights_out sixteen weight levels, in raster order
131
+ * @param {Uint8Array} palette twelve bytes, four RGB triples
132
+ * @param {Uint8Array} selector_values
133
+ * @param {number} selector_base
134
+ */
135
+ function fit_block(endpoints_out, weights_out, palette, selector_values, selector_base) {
136
+ const used = [];
137
+
138
+ for (let texel = 0; texel < 16; texel++) {
139
+ const selector = selector_values[selector_base + texel];
140
+
141
+ if (!used.includes(selector)) {
142
+ used.push(selector);
143
+ }
144
+ }
145
+
146
+ used.sort(number_compare_ascending);
147
+
148
+ let best_error = Infinity;
149
+
150
+ const level_of = new Int32Array(4);
151
+ const candidate = new Int32Array(6);
152
+
153
+ for (const placement of PLACEMENTS[used.length]) {
154
+ for (let i = 0; i < used.length; i++) {
155
+ level_of[used[i]] = placement[i];
156
+ }
157
+
158
+ const error = fit_endpoints(candidate, palette, selector_values, selector_base, level_of);
159
+
160
+ if (error < best_error) {
161
+ best_error = error;
162
+
163
+ endpoints_out.set(candidate);
164
+
165
+ for (let texel = 0; texel < 16; texel++) {
166
+ weights_out[texel] = level_of[selector_values[selector_base + texel]];
167
+ }
168
+ }
169
+ }
170
+
171
+ refine(endpoints_out, palette, selector_values, selector_base, weights_out);
172
+ }
173
+
174
+ /**
175
+ * Nudge each channel's endpoints to the best pair within a step or two of the least-squares one.
176
+ *
177
+ * **Least squares minimises the wrong thing by a little.** It fits real-valued endpoints against
178
+ * real-valued targets; what gets written is the rounded pair, and what is read back is
179
+ * {@link interpolate}'s integer arithmetic on it. Those two roundings do not commute, so the rounded
180
+ * least-squares answer is usually but not always the best integer pair — a step in one direction
181
+ * often trades a large error on one texel for small ones on several.
182
+ *
183
+ * Only the winning placement is refined, and only over a small window. The placement search above
184
+ * runs first on the cheaper score, because refining all fifteen would multiply the cost of every
185
+ * block by more than it buys: this closes the last level against the reference encoder, which is
186
+ * worth a bounded pass and not an unbounded one.
187
+ *
188
+ * Channels are independent once the weights are fixed, so each is searched on its own — three
189
+ * searches of twenty-five candidates rather than one of fifteen thousand.
190
+ *
191
+ * @param {Int32Array} endpoints six values, modified in place
192
+ * @param {Uint8Array} palette
193
+ * @param {Uint8Array} selector_values
194
+ * @param {number} selector_base
195
+ * @param {Uint8Array} weights the chosen weight level per texel
196
+ */
197
+ function refine(endpoints, palette, selector_values, selector_base, weights) {
198
+ for (let channel = 0; channel < 3; channel++) {
199
+ const start0 = endpoints[channel * 2];
200
+ const start1 = endpoints[channel * 2 + 1];
201
+
202
+ let best0 = start0;
203
+ let best1 = start1;
204
+ let best_error = Infinity;
205
+
206
+ for (let d0 = -2; d0 <= 2; d0++) {
207
+ for (let d1 = -2; d1 <= 2; d1++) {
208
+ const q0 = clamp255(start0 + d0);
209
+ const q1 = clamp255(start1 + d1);
210
+
211
+ let error = 0;
212
+
213
+ for (let texel = 0; texel < 16; texel++) {
214
+ const decoded = astc_interpolate(q0, q1, LEVELS[weights[texel]]);
215
+
216
+ const delta = decoded
217
+ - palette[selector_values[selector_base + texel] * 3 + channel];
218
+
219
+ error += delta * delta;
220
+ }
221
+
222
+ if (error < best_error) {
223
+ best_error = error;
224
+ best0 = q0;
225
+ best1 = q1;
226
+ }
227
+ }
228
+ }
229
+
230
+ endpoints[channel * 2] = best0;
231
+ endpoints[channel * 2 + 1] = best1;
232
+ }
233
+ }
234
+
235
+ /**
236
+ * Least-squares endpoints for one placement, and the squared error it leaves.
237
+ *
238
+ * A two-parameter linear fit per channel, sharing one set of `t` statistics because every channel's
239
+ * texels sit at the same positions along the line. The fit is real-valued and the scoring is not:
240
+ * what is compared is what {@link interpolate} will actually produce from the rounded, clamped
241
+ * endpoints, so a placement is judged on the block that will be written.
242
+ *
243
+ * @param {Int32Array} out six values
244
+ * @param {Uint8Array} palette
245
+ * @param {Uint8Array} selector_values
246
+ * @param {number} selector_base
247
+ * @param {Int32Array} level_of weight level for each selector value
248
+ * @returns {number} summed squared error over all sixteen texels and three channels
249
+ */
250
+ function fit_endpoints(out, palette, selector_values, selector_base, level_of) {
251
+ let sum_t = 0;
252
+ let sum_tt = 0;
253
+
254
+ for (let texel = 0; texel < 16; texel++) {
255
+ const t = LEVELS[level_of[selector_values[selector_base + texel]]] / 64;
256
+
257
+ sum_t += t;
258
+ sum_tt += t * t;
259
+ }
260
+
261
+ const n = 16;
262
+
263
+ /*
264
+ The normal equations for `value = e0 (1 - t) + e1 t`, written in terms of `e0` and `d = e1 - e0`
265
+ so that the shared statistics fall out: `sum(v) = n e0 + d sum(t)` and
266
+ `sum(v t) = e0 sum(t) + d sum(t t)`.
267
+ */
268
+ const determinant = n * sum_tt - sum_t * sum_t;
269
+
270
+ let error = 0;
271
+
272
+ for (let channel = 0; channel < 3; channel++) {
273
+ let sum_v = 0;
274
+ let sum_vt = 0;
275
+
276
+ for (let texel = 0; texel < 16; texel++) {
277
+ const selector = selector_values[selector_base + texel];
278
+
279
+ const v = palette[selector * 3 + channel];
280
+ const t = LEVELS[level_of[selector]] / 64;
281
+
282
+ sum_v += v;
283
+ sum_vt += v * t;
284
+ }
285
+
286
+ let e0;
287
+ let d;
288
+
289
+ if (determinant === 0) {
290
+ /*
291
+ Every texel at the same weight, so the line is a point and only one endpoint is
292
+ determined. Both are set to it, which reproduces the block exactly whatever the weights
293
+ then say.
294
+ */
295
+ e0 = sum_v / n;
296
+ d = 0;
297
+ } else {
298
+ e0 = (sum_v * sum_tt - sum_vt * sum_t) / determinant;
299
+ d = (n * sum_vt - sum_v * sum_t) / determinant;
300
+ }
301
+
302
+ const q0 = clamp255(Math.round(e0));
303
+ const q1 = clamp255(Math.round(e0 + d));
304
+
305
+ out[channel * 2] = q0;
306
+ out[channel * 2 + 1] = q1;
307
+
308
+ for (let texel = 0; texel < 16; texel++) {
309
+ const selector = selector_values[selector_base + texel];
310
+
311
+ const decoded = astc_interpolate(q0, q1, LEVELS[level_of[selector]]);
312
+
313
+ const delta = decoded - palette[selector * 3 + channel];
314
+
315
+ error += delta * delta;
316
+ }
317
+ }
318
+
319
+ return error;
320
+ }
321
+
322
+ /**
323
+ * @param {number} value
324
+ * @returns {number} `value` brought into `[0, 255]`
325
+ */
326
+ function clamp255(value) {
327
+ return value < 0 ? 0 : value > 255 ? 255 : value;
328
+ }
329
+
@@ -1 +1 @@
1
- {"version":3,"file":"etc1s_to_etc2.d.ts","sourceRoot":"","sources":["../../../../../../src/format/texture/basis/transcode/etc1s_to_etc2.js"],"names":[],"mappings":"AA8DA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,8DAXW,aAAW,SAAS,8EAGpB,MAAM,WACN,MAAM,eACN,OAAO,GACL,UAAU,CAgDtB"}
1
+ {"version":3,"file":"etc1s_to_etc2.d.ts","sourceRoot":"","sources":["../../../../../../src/format/texture/basis/transcode/etc1s_to_etc2.js"],"names":[],"mappings":"AAmCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,8DAXW,aAAW,SAAS,8EAGpB,MAAM,WACN,MAAM,eACN,OAAO,GACL,UAAU,CAgDtB"}