@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,332 +1,305 @@
1
- import { etc1s_block_colors } from "../etc1s/etc1s_block_colors.js";
2
-
3
- /**
4
- * Bytes in one ETC2 RGB block, and in one EAC alpha block.
5
- *
6
- * @readonly
7
- * @type {number}
8
- */
9
- const ETC_BLOCK_BYTES = 8;
10
-
11
- /**
12
- * Where an ETC1S selector lands in ETC1's own index space.
13
- *
14
- * **The one place these two disagree.** `INTENSITY_MODIFIER` is ordered darkest to brightest, which
15
- * is the order a Basis selector indexes it in. ETC1 stores the same four modifiers as two magnitudes
16
- * with their signs, indexed `+a, +b, -a, -b`. So a selector of 0 — the darkest, `-b` — is ETC1's
17
- * index 3, and writing the selector through unchanged mirrors every block through its own mid-grey.
18
- *
19
- * @readonly
20
- * @type {Uint8Array}
21
- */
22
- const SELECTOR_TO_ETC1_INDEX = new Uint8Array([3, 2, 0, 1]);
23
-
24
- /**
25
- * EAC's modifier table: sixteen rows of eight, indexed by a block's table field and a texel's index.
26
- *
27
- * Row 13 is the one this file depends on. It is the only row containing zero, which is what lets a
28
- * block encode a single alpha value *exactly* — base codeword, multiplier one, every index pointing
29
- * at the zero. An opaque block has to come back as 255 and not 254.
30
- *
31
- * @readonly
32
- * @type {Int32Array}
33
- * @see the ETC2/EAC specification, table "Intensity modifier sets for alpha component"
34
- */
35
- const EAC_MODIFIER = new Int32Array([
36
- -3, -6, -9, -15, 2, 5, 8, 14,
37
- -3, -7, -10, -13, 2, 5, 9, 13,
38
- -2, -5, -8, -13, 1, 4, 7, 12,
39
- -2, -4, -6, -13, 1, 3, 5, 12,
40
- -3, -6, -8, -12, 2, 5, 7, 11,
41
- -3, -7, -9, -11, 2, 5, 8, 10,
42
- -4, -7, -8, -11, 3, 6, 7, 10,
43
- -3, -5, -8, -11, 2, 4, 7, 10,
44
- -2, -6, -8, -10, 1, 5, 7, 9,
45
- -2, -5, -8, -10, 1, 4, 7, 9,
46
- -2, -4, -8, -10, 1, 3, 7, 9,
47
- -2, -5, -7, -10, 1, 4, 6, 9,
48
- -3, -4, -7, -10, 2, 3, 6, 9,
49
- -1, -2, -3, -10, 0, 1, 2, 9,
50
- -4, -6, -8, -9, 3, 5, 7, 8,
51
- -3, -5, -7, -9, 2, 4, 6, 8,
52
- ]);
53
-
54
- /**
55
- * The EAC table row holding a zero modifier, and the index of that zero within it.
56
- *
57
- * @readonly
58
- * @type {number}
59
- */
60
- const EAC_EXACT_TABLE = 13;
61
- const EAC_EXACT_INDEX = 4;
62
-
63
- /**
64
- * Transcode ETC1S to ETC2, which for these blocks is a repack rather than a re-encode.
65
- *
66
- * **ETC1S is a constrained ETC1, and ETC1 is a subset of ETC2.** A Basis block is one base colour
67
- * with one intensity table and sixteen two-bit selectors, which is precisely ETC1's differential
68
- * mode with both subblocks given the same colour — the deltas are zero and the two table codewords
69
- * are equal. So nothing is fitted, nothing is searched, and nothing is lost: the RGB half of the
70
- * output decodes bit-identically to what {@link etc1s_to_rgba8} produces, on any ETC2 hardware.
71
- *
72
- * That is what makes this worth having over the uncompressed floor on a device with no BC. It is
73
- * eight bits a texel against thirty-two, at no cost in quality at all.
74
- *
75
- * **Alpha is the part that is actually encoded.** ETC2's RGBA8 block is an EAC alpha block followed
76
- * by the RGB one, and EAC is a different scheme — a base value, a multiplier and a table, with three
77
- * bits a texel. A payload with no alpha slice is written exactly opaque through the one table row
78
- * containing a zero; a payload that carries alpha is fitted, which is the only lossy step here.
79
- *
80
- * @param {Etc1sSlice} slice
81
- * @param {Etc1sSlice|undefined} alpha_slice
82
- * @param {Etc1sEndpointCodebook} endpoints
83
- * @param {Etc1sSelectorCodebook} selectors
84
- * @param {number} _width unused: an ETC2 level is a whole number of blocks, like every block format
85
- * @param {number} _height
86
- * @param {boolean} [with_alpha] write the 16-byte RGBA8 block rather than the 8-byte RGB8 one
87
- * @returns {Uint8Array} tightly packed blocks, in raster order
88
- *
89
- * @author Alex Goldring
90
- * @copyright Company Named Limited (c) 2026
91
- */
92
- export function etc1s_to_etc2(slice, alpha_slice, endpoints, selectors, _width, _height, with_alpha = false) {
93
- const block_count = slice.blocks_x * slice.blocks_y;
94
-
95
- const block_bytes = with_alpha ? ETC_BLOCK_BYTES * 2 : ETC_BLOCK_BYTES;
96
-
97
- const out = new Uint8Array(block_count * block_bytes);
98
-
99
- const alpha_palette = new Uint8Array(12);
100
- const alpha_values = new Uint8Array(16);
101
-
102
- for (let block = 0; block < block_count; block++) {
103
- let offset = block * block_bytes;
104
-
105
- if (with_alpha) {
106
- if (alpha_slice === undefined) {
107
- write_eac_constant(out, offset, 255);
108
- } else {
109
- etc1s_block_colors(
110
- alpha_palette, 0, endpoints.color5, endpoints.intensity,
111
- alpha_slice.endpoint_index[block]
112
- );
113
-
114
- const base = alpha_slice.selector_index[block] * 16;
115
-
116
- for (let texel = 0; texel < 16; texel++) {
117
- // green, for the reason etc1s_to_rgba8 gives: an alpha slice is greyscale
118
- alpha_values[texel] = alpha_palette[selectors.selectors[base + texel] * 3 + 1];
119
- }
120
-
121
- write_eac(out, offset, alpha_values);
122
- }
123
-
124
- offset += ETC_BLOCK_BYTES;
125
- }
126
-
127
- write_etc1(
128
- out, offset,
129
- endpoints.color5, endpoints.intensity, slice.endpoint_index[block],
130
- selectors.selectors, slice.selector_index[block] * 16
131
- );
132
- }
133
-
134
- return out;
135
- }
136
-
137
- /**
138
- * Write one ETC1 block in differential mode, both subblocks sharing the ETC1S block's colour.
139
- *
140
- * @param {Uint8Array} out
141
- * @param {number} offset
142
- * @param {Uint8Array} color5 endpoint codebook channels
143
- * @param {Uint8Array} intensity endpoint codebook intensity indices
144
- * @param {number} endpoint_index
145
- * @param {Uint8Array} selector_values the selector codebook's array
146
- * @param {number} selector_base where this block's sixteen selectors start
147
- */
148
- function write_etc1(out, offset, color5, intensity, endpoint_index, selector_values, selector_base) {
149
- const r = color5[endpoint_index * 3];
150
- const g = color5[endpoint_index * 3 + 1];
151
- const b = color5[endpoint_index * 3 + 2];
152
-
153
- const table = intensity[endpoint_index];
154
-
155
- /*
156
- Differential mode with all three deltas zero. The alternative — individual mode, two 4-bit
157
- colours — would have to quantise the five-bit channel down to four and lose a bit per channel
158
- for nothing, since the two subblocks hold the same colour either way.
159
- */
160
- out[offset] = (r << 3);
161
- out[offset + 1] = (g << 3);
162
- out[offset + 2] = (b << 3);
163
-
164
- // table codeword 0 and 1 both the block's intensity, diffbit set, flipbit clear
165
- out[offset + 3] = (table << 5) | (table << 2) | 0b10;
166
-
167
- let msb = 0;
168
- let lsb = 0;
169
-
170
- for (let y = 0; y < 4; y++) {
171
- for (let x = 0; x < 4; x++) {
172
- const index = SELECTOR_TO_ETC1_INDEX[selector_values[selector_base + y * 4 + x]];
173
-
174
- /*
175
- ETC1 numbers its texels down each column and then across, where every other block
176
- format here runs along the rows — so this is the one place a raster loop has to be
177
- transposed rather than followed.
178
- */
179
- const bit = x * 4 + y;
180
-
181
- msb |= (index >> 1) << bit;
182
- lsb |= (index & 1) << bit;
183
- }
184
- }
185
-
186
- out[offset + 4] = (msb >> 8) & 0xFF;
187
- out[offset + 5] = msb & 0xFF;
188
- out[offset + 6] = (lsb >> 8) & 0xFF;
189
- out[offset + 7] = lsb & 0xFF;
190
- }
191
-
192
- /**
193
- * Write an EAC alpha block holding one value in all sixteen texels, exactly.
194
- *
195
- * @param {Uint8Array} out
196
- * @param {number} offset
197
- * @param {number} value
198
- */
199
- function write_eac_constant(out, offset, value) {
200
- out[offset] = value;
201
-
202
- // multiplier 1, and the table row whose fifth entry is zero
203
- out[offset + 1] = (1 << 4) | EAC_EXACT_TABLE;
204
-
205
- // every texel takes that zero, so every texel decodes to the base value
206
- let bits = 0n;
207
-
208
- for (let texel = 0; texel < 16; texel++) {
209
- bits |= BigInt(EAC_EXACT_INDEX) << BigInt(45 - texel * 3);
210
- }
211
-
212
- for (let i = 0; i < 6; i++) {
213
- out[offset + 2 + i] = Number((bits >> BigInt(40 - i * 8)) & 0xFFn);
214
- }
215
- }
216
-
217
- /**
218
- * Fit and write an EAC alpha block for sixteen values.
219
- *
220
- * **Searched rather than derived.** EAC's sixteen table rows are not scalings of one another — they
221
- * differ in how their eight modifiers are distributed, so which row fits a block depends on the
222
- * shape of its values and not only on their range. Sixteen rows against sixteen multipliers is 256
223
- * candidates and each is sixteen nearest-value lookups, which is small enough to simply try.
224
- *
225
- * The base is fixed at the midpoint rather than searched with them. It is the one parameter that
226
- * shifts every reachable value together, so the midpoint is optimal for a symmetric row and close
227
- * for the rest, and adding it to the search would multiply the cost by 256 for a fraction of a
228
- * level.
229
- *
230
- * @param {Uint8Array} out
231
- * @param {number} offset
232
- * @param {Uint8Array} values sixteen
233
- */
234
- function write_eac(out, offset, values) {
235
- let low = 255;
236
- let high = 0;
237
-
238
- for (let i = 0; i < 16; i++) {
239
- if (values[i] < low) {
240
- low = values[i];
241
- }
242
-
243
- if (values[i] > high) {
244
- high = values[i];
245
- }
246
- }
247
-
248
- if (low === high) {
249
- // exact, and the common case: an alpha slice is mostly flat regions
250
- write_eac_constant(out, offset, low);
251
-
252
- return;
253
- }
254
-
255
- const base = (low + high) >> 1;
256
-
257
- let best_table = 0;
258
- let best_multiplier = 1;
259
- let best_error = Infinity;
260
-
261
- for (let table = 0; table < 16; table++) {
262
- for (let multiplier = 1; multiplier < 16; multiplier++) {
263
- let error = 0;
264
-
265
- for (let texel = 0; texel < 16; texel++) {
266
- error += nearest(values[texel], base, table, multiplier).error;
267
-
268
- if (error >= best_error) {
269
- break;
270
- }
271
- }
272
-
273
- if (error < best_error) {
274
- best_error = error;
275
- best_table = table;
276
- best_multiplier = multiplier;
277
- }
278
- }
279
- }
280
-
281
- out[offset] = base;
282
- out[offset + 1] = (best_multiplier << 4) | best_table;
283
-
284
- let bits = 0n;
285
-
286
- /*
287
- EAC numbers its texels down each column, exactly as ETC1 does — so a raster-ordered array has to
288
- be transposed on the way in. A constant block hides this completely, which is why the opaque
289
- path above can ignore it and why this was worth checking against a block that is not constant.
290
- */
291
- for (let y = 0; y < 4; y++) {
292
- for (let x = 0; x < 4; x++) {
293
- const index = nearest(values[y * 4 + x], base, best_table, best_multiplier).index;
294
-
295
- bits |= BigInt(index) << BigInt(45 - (x * 4 + y) * 3);
296
- }
297
- }
298
-
299
- for (let i = 0; i < 6; i++) {
300
- out[offset + 2 + i] = Number((bits >> BigInt(40 - i * 8)) & 0xFFn);
301
- }
302
- }
303
-
304
- /**
305
- * The index whose decoded alpha is closest to `value`, and the squared error it leaves.
306
- *
307
- * @param {number} value
308
- * @param {number} base
309
- * @param {number} table
310
- * @param {number} multiplier
311
- * @returns {{index: number, error: number}}
312
- */
313
- function nearest(value, base, table, multiplier) {
314
- let best = 0;
315
- let best_error = Infinity;
316
-
317
- for (let index = 0; index < 8; index++) {
318
- let decoded = base + EAC_MODIFIER[table * 8 + index] * multiplier;
319
-
320
- decoded = decoded < 0 ? 0 : decoded > 255 ? 255 : decoded;
321
-
322
- const delta = decoded - value;
323
- const error = delta * delta;
324
-
325
- if (error < best_error) {
326
- best_error = error;
327
- best = index;
328
- }
329
- }
330
-
331
- return { index: best, error: best_error };
332
- }
1
+ import { EAC_MODIFIERS } from "../../etc/eac_modifiers.js";
2
+ import { etc1s_block_colors } from "../etc1s/etc1s_block_colors.js";
3
+
4
+ /**
5
+ * Bytes in one ETC2 RGB block, and in one EAC alpha block.
6
+ *
7
+ * @readonly
8
+ * @type {number}
9
+ */
10
+ const ETC_BLOCK_BYTES = 8;
11
+
12
+ /**
13
+ * Where an ETC1S selector lands in ETC1's own index space.
14
+ *
15
+ * **The one place these two disagree.** `INTENSITY_MODIFIER` is ordered darkest to brightest, which
16
+ * is the order a Basis selector indexes it in. ETC1 stores the same four modifiers as two magnitudes
17
+ * with their signs, indexed `+a, +b, -a, -b`. So a selector of 0 — the darkest, `-b` — is ETC1's
18
+ * index 3, and writing the selector through unchanged mirrors every block through its own mid-grey.
19
+ *
20
+ * @readonly
21
+ * @type {Uint8Array}
22
+ */
23
+ const SELECTOR_TO_ETC1_INDEX = new Uint8Array([3, 2, 0, 1]);
24
+
25
+ /**
26
+ * The EAC table row holding a zero modifier ({@link EAC_MODIFIERS}), and the index of that zero within it: what
27
+ * lets a block encode a single alpha value exactly — base codeword, multiplier one, every index pointing at the
28
+ * zero. An opaque block has to come back as 255 and not 254.
29
+ *
30
+ * @readonly
31
+ * @type {number}
32
+ */
33
+ const EAC_EXACT_TABLE = 13;
34
+ const EAC_EXACT_INDEX = 4;
35
+
36
+ /**
37
+ * Transcode ETC1S to ETC2, which for these blocks is a repack rather than a re-encode.
38
+ *
39
+ * **ETC1S is a constrained ETC1, and ETC1 is a subset of ETC2.** A Basis block is one base colour
40
+ * with one intensity table and sixteen two-bit selectors, which is precisely ETC1's differential
41
+ * mode with both subblocks given the same colour — the deltas are zero and the two table codewords
42
+ * are equal. So nothing is fitted, nothing is searched, and nothing is lost: the RGB half of the
43
+ * output decodes bit-identically to what {@link etc1s_to_rgba8} produces, on any ETC2 hardware.
44
+ *
45
+ * That is what makes this worth having over the uncompressed floor on a device with no BC. It is
46
+ * eight bits a texel against thirty-two, at no cost in quality at all.
47
+ *
48
+ * **Alpha is the part that is actually encoded.** ETC2's RGBA8 block is an EAC alpha block followed
49
+ * by the RGB one, and EAC is a different scheme — a base value, a multiplier and a table, with three
50
+ * bits a texel. A payload with no alpha slice is written exactly opaque through the one table row
51
+ * containing a zero; a payload that carries alpha is fitted, which is the only lossy step here.
52
+ *
53
+ * @param {Etc1sSlice} slice
54
+ * @param {Etc1sSlice|undefined} alpha_slice
55
+ * @param {Etc1sEndpointCodebook} endpoints
56
+ * @param {Etc1sSelectorCodebook} selectors
57
+ * @param {number} _width unused: an ETC2 level is a whole number of blocks, like every block format
58
+ * @param {number} _height
59
+ * @param {boolean} [with_alpha] write the 16-byte RGBA8 block rather than the 8-byte RGB8 one
60
+ * @returns {Uint8Array} tightly packed blocks, in raster order
61
+ *
62
+ * @author Alex Goldring
63
+ * @copyright Company Named Limited (c) 2026
64
+ */
65
+ export function etc1s_to_etc2(slice, alpha_slice, endpoints, selectors, _width, _height, with_alpha = false) {
66
+ const block_count = slice.blocks_x * slice.blocks_y;
67
+
68
+ const block_bytes = with_alpha ? ETC_BLOCK_BYTES * 2 : ETC_BLOCK_BYTES;
69
+
70
+ const out = new Uint8Array(block_count * block_bytes);
71
+
72
+ const alpha_palette = new Uint8Array(12);
73
+ const alpha_values = new Uint8Array(16);
74
+
75
+ for (let block = 0; block < block_count; block++) {
76
+ let offset = block * block_bytes;
77
+
78
+ if (with_alpha) {
79
+ if (alpha_slice === undefined) {
80
+ write_eac_constant(out, offset, 255);
81
+ } else {
82
+ etc1s_block_colors(
83
+ alpha_palette, 0, endpoints.color5, endpoints.intensity,
84
+ alpha_slice.endpoint_index[block]
85
+ );
86
+
87
+ const base = alpha_slice.selector_index[block] * 16;
88
+
89
+ for (let texel = 0; texel < 16; texel++) {
90
+ // green, for the reason etc1s_to_rgba8 gives: an alpha slice is greyscale
91
+ alpha_values[texel] = alpha_palette[selectors.selectors[base + texel] * 3 + 1];
92
+ }
93
+
94
+ write_eac(out, offset, alpha_values);
95
+ }
96
+
97
+ offset += ETC_BLOCK_BYTES;
98
+ }
99
+
100
+ write_etc1(
101
+ out, offset,
102
+ endpoints.color5, endpoints.intensity, slice.endpoint_index[block],
103
+ selectors.selectors, slice.selector_index[block] * 16
104
+ );
105
+ }
106
+
107
+ return out;
108
+ }
109
+
110
+ /**
111
+ * Write one ETC1 block in differential mode, both subblocks sharing the ETC1S block's colour.
112
+ *
113
+ * @param {Uint8Array} out
114
+ * @param {number} offset
115
+ * @param {Uint8Array} color5 endpoint codebook channels
116
+ * @param {Uint8Array} intensity endpoint codebook intensity indices
117
+ * @param {number} endpoint_index
118
+ * @param {Uint8Array} selector_values the selector codebook's array
119
+ * @param {number} selector_base where this block's sixteen selectors start
120
+ */
121
+ function write_etc1(out, offset, color5, intensity, endpoint_index, selector_values, selector_base) {
122
+ const r = color5[endpoint_index * 3];
123
+ const g = color5[endpoint_index * 3 + 1];
124
+ const b = color5[endpoint_index * 3 + 2];
125
+
126
+ const table = intensity[endpoint_index];
127
+
128
+ /*
129
+ Differential mode with all three deltas zero. The alternative — individual mode, two 4-bit
130
+ colours — would have to quantise the five-bit channel down to four and lose a bit per channel
131
+ for nothing, since the two subblocks hold the same colour either way.
132
+ */
133
+ out[offset] = (r << 3);
134
+ out[offset + 1] = (g << 3);
135
+ out[offset + 2] = (b << 3);
136
+
137
+ // table codeword 0 and 1 both the block's intensity, diffbit set, flipbit clear
138
+ out[offset + 3] = (table << 5) | (table << 2) | 0b10;
139
+
140
+ let msb = 0;
141
+ let lsb = 0;
142
+
143
+ for (let y = 0; y < 4; y++) {
144
+ for (let x = 0; x < 4; x++) {
145
+ const index = SELECTOR_TO_ETC1_INDEX[selector_values[selector_base + y * 4 + x]];
146
+
147
+ /*
148
+ ETC1 numbers its texels down each column and then across, where every other block
149
+ format here runs along the rows — so this is the one place a raster loop has to be
150
+ transposed rather than followed.
151
+ */
152
+ const bit = x * 4 + y;
153
+
154
+ msb |= (index >> 1) << bit;
155
+ lsb |= (index & 1) << bit;
156
+ }
157
+ }
158
+
159
+ out[offset + 4] = (msb >> 8) & 0xFF;
160
+ out[offset + 5] = msb & 0xFF;
161
+ out[offset + 6] = (lsb >> 8) & 0xFF;
162
+ out[offset + 7] = lsb & 0xFF;
163
+ }
164
+
165
+ /**
166
+ * Write an EAC alpha block holding one value in all sixteen texels, exactly.
167
+ *
168
+ * @param {Uint8Array} out
169
+ * @param {number} offset
170
+ * @param {number} value
171
+ */
172
+ function write_eac_constant(out, offset, value) {
173
+ out[offset] = value;
174
+
175
+ // multiplier 1, and the table row whose fifth entry is zero
176
+ out[offset + 1] = (1 << 4) | EAC_EXACT_TABLE;
177
+
178
+ // every texel takes that zero, so every texel decodes to the base value
179
+ let bits = 0n;
180
+
181
+ for (let texel = 0; texel < 16; texel++) {
182
+ bits |= BigInt(EAC_EXACT_INDEX) << BigInt(45 - texel * 3);
183
+ }
184
+
185
+ for (let i = 0; i < 6; i++) {
186
+ out[offset + 2 + i] = Number((bits >> BigInt(40 - i * 8)) & 0xFFn);
187
+ }
188
+ }
189
+
190
+ /**
191
+ * Fit and write an EAC alpha block for sixteen values.
192
+ *
193
+ * **Searched rather than derived.** EAC's sixteen table rows are not scalings of one another — they
194
+ * differ in how their eight modifiers are distributed, so which row fits a block depends on the
195
+ * shape of its values and not only on their range. Sixteen rows against sixteen multipliers is 256
196
+ * candidates and each is sixteen nearest-value lookups, which is small enough to simply try.
197
+ *
198
+ * The base is fixed at the midpoint rather than searched with them. It is the one parameter that
199
+ * shifts every reachable value together, so the midpoint is optimal for a symmetric row and close
200
+ * for the rest, and adding it to the search would multiply the cost by 256 for a fraction of a
201
+ * level.
202
+ *
203
+ * @param {Uint8Array} out
204
+ * @param {number} offset
205
+ * @param {Uint8Array} values sixteen
206
+ */
207
+ function write_eac(out, offset, values) {
208
+ let low = 255;
209
+ let high = 0;
210
+
211
+ for (let i = 0; i < 16; i++) {
212
+ if (values[i] < low) {
213
+ low = values[i];
214
+ }
215
+
216
+ if (values[i] > high) {
217
+ high = values[i];
218
+ }
219
+ }
220
+
221
+ if (low === high) {
222
+ // exact, and the common case: an alpha slice is mostly flat regions
223
+ write_eac_constant(out, offset, low);
224
+
225
+ return;
226
+ }
227
+
228
+ const base = (low + high) >> 1;
229
+
230
+ let best_table = 0;
231
+ let best_multiplier = 1;
232
+ let best_error = Infinity;
233
+
234
+ for (let table = 0; table < 16; table++) {
235
+ for (let multiplier = 1; multiplier < 16; multiplier++) {
236
+ let error = 0;
237
+
238
+ for (let texel = 0; texel < 16; texel++) {
239
+ error += nearest(values[texel], base, table, multiplier).error;
240
+
241
+ if (error >= best_error) {
242
+ break;
243
+ }
244
+ }
245
+
246
+ if (error < best_error) {
247
+ best_error = error;
248
+ best_table = table;
249
+ best_multiplier = multiplier;
250
+ }
251
+ }
252
+ }
253
+
254
+ out[offset] = base;
255
+ out[offset + 1] = (best_multiplier << 4) | best_table;
256
+
257
+ let bits = 0n;
258
+
259
+ /*
260
+ EAC numbers its texels down each column, exactly as ETC1 does — so a raster-ordered array has to
261
+ be transposed on the way in. A constant block hides this completely, which is why the opaque
262
+ path above can ignore it and why this was worth checking against a block that is not constant.
263
+ */
264
+ for (let y = 0; y < 4; y++) {
265
+ for (let x = 0; x < 4; x++) {
266
+ const index = nearest(values[y * 4 + x], base, best_table, best_multiplier).index;
267
+
268
+ bits |= BigInt(index) << BigInt(45 - (x * 4 + y) * 3);
269
+ }
270
+ }
271
+
272
+ for (let i = 0; i < 6; i++) {
273
+ out[offset + 2 + i] = Number((bits >> BigInt(40 - i * 8)) & 0xFFn);
274
+ }
275
+ }
276
+
277
+ /**
278
+ * The index whose decoded alpha is closest to `value`, and the squared error it leaves.
279
+ *
280
+ * @param {number} value
281
+ * @param {number} base
282
+ * @param {number} table
283
+ * @param {number} multiplier
284
+ * @returns {{index: number, error: number}}
285
+ */
286
+ function nearest(value, base, table, multiplier) {
287
+ let best = 0;
288
+ let best_error = Infinity;
289
+
290
+ for (let index = 0; index < 8; index++) {
291
+ let decoded = base + EAC_MODIFIERS[table * 8 + index] * multiplier;
292
+
293
+ decoded = decoded < 0 ? 0 : decoded > 255 ? 255 : decoded;
294
+
295
+ const delta = decoded - value;
296
+ const error = delta * delta;
297
+
298
+ if (error < best_error) {
299
+ best_error = error;
300
+ best = index;
301
+ }
302
+ }
303
+
304
+ return { index: best, error: best_error };
305
+ }