@woosh/meep-engine 3.79.0 → 3.80.1
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.
- package/CHANGELOG.md +62 -3
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/format/image/webp/vp8/VP8BoolDecoder.d.ts +45 -0
- package/src/format/image/webp/vp8/VP8BoolDecoder.d.ts.map +1 -0
- package/src/format/image/webp/vp8/VP8BoolDecoder.js +137 -0
- package/src/format/image/webp/vp8/vp8_decode.d.ts +21 -0
- package/src/format/image/webp/vp8/vp8_decode.d.ts.map +1 -0
- package/src/format/image/webp/vp8/vp8_decode.js +756 -0
- package/src/format/image/webp/vp8/vp8_loop_filter.d.ts +31 -0
- package/src/format/image/webp/vp8/vp8_loop_filter.d.ts.map +1 -0
- package/src/format/image/webp/vp8/vp8_loop_filter.js +189 -0
- package/src/format/image/webp/vp8/vp8_predict.d.ts +48 -0
- package/src/format/image/webp/vp8/vp8_predict.d.ts.map +1 -0
- package/src/format/image/webp/vp8/vp8_predict.js +290 -0
- package/src/format/image/webp/vp8/vp8_tables.d.ts +34 -0
- package/src/format/image/webp/vp8/vp8_tables.d.ts.map +1 -0
- package/src/format/image/webp/vp8/vp8_tables.js +350 -0
- package/src/format/image/webp/vp8/vp8_transform.d.ts +22 -0
- package/src/format/image/webp/vp8/vp8_transform.d.ts.map +1 -0
- package/src/format/image/webp/vp8/vp8_transform.js +114 -0
- package/src/format/image/webp/vp8/vp8_yuv_to_rgba.d.ts +23 -0
- package/src/format/image/webp/vp8/vp8_yuv_to_rgba.d.ts.map +1 -0
- package/src/format/image/webp/vp8/vp8_yuv_to_rgba.js +133 -0
- package/src/format/image/webp/vp8l/VP8LBitReader.d.ts +47 -0
- package/src/format/image/webp/vp8l/VP8LBitReader.d.ts.map +1 -0
- package/src/format/image/webp/vp8l/VP8LBitReader.js +84 -0
- package/src/format/image/webp/vp8l/VP8LPrefixCode.d.ts +27 -0
- package/src/format/image/webp/vp8l/VP8LPrefixCode.d.ts.map +1 -0
- package/src/format/image/webp/vp8l/VP8LPrefixCode.js +184 -0
- package/src/format/image/webp/vp8l/vp8l_decode.d.ts +28 -0
- package/src/format/image/webp/vp8l/vp8l_decode.d.ts.map +1 -0
- package/src/format/image/webp/vp8l/vp8l_decode.js +261 -0
- package/src/format/image/webp/vp8l/vp8l_distance.d.ts +22 -0
- package/src/format/image/webp/vp8l/vp8l_distance.d.ts.map +1 -0
- package/src/format/image/webp/vp8l/vp8l_distance.js +62 -0
- package/src/format/image/webp/vp8l/vp8l_inverse_transforms.d.ts +50 -0
- package/src/format/image/webp/vp8l/vp8l_inverse_transforms.d.ts.map +1 -0
- package/src/format/image/webp/vp8l/vp8l_inverse_transforms.js +267 -0
- package/src/format/image/webp/vp8l/vp8l_read_prefix_code.d.ts +14 -0
- package/src/format/image/webp/vp8l/vp8l_read_prefix_code.d.ts.map +1 -0
- package/src/format/image/webp/vp8l/vp8l_read_prefix_code.js +99 -0
- package/src/format/image/webp/webp_decode.d.ts +23 -0
- package/src/format/image/webp/webp_decode.d.ts.map +1 -0
- package/src/format/image/webp/webp_decode.js +179 -0
- package/src/format/image/webp/webp_decode_alpha.d.ts +18 -0
- package/src/format/image/webp/webp_decode_alpha.d.ts.map +1 -0
- package/src/format/image/webp/webp_decode_alpha.js +84 -0
- package/src/format/texture/{basis → astc}/astc_block.d.ts +41 -0
- package/src/format/texture/astc/astc_block.d.ts.map +1 -0
- package/src/format/texture/{basis → astc}/astc_block.js +284 -164
- package/src/format/texture/astc/astc_decode_block.d.ts +68 -0
- package/src/format/texture/astc/astc_decode_block.d.ts.map +1 -0
- package/src/format/texture/astc/astc_decode_block.js +1119 -0
- package/src/format/texture/astc/astc_encode_block_4x4.d.ts +32 -0
- package/src/format/texture/astc/astc_encode_block_4x4.d.ts.map +1 -0
- package/src/format/texture/astc/astc_encode_block_4x4.js +181 -0
- package/src/format/texture/astc/astc_encode_block_4x4_rgba.d.ts +32 -0
- package/src/format/texture/astc/astc_encode_block_4x4_rgba.d.ts.map +1 -0
- package/src/format/texture/astc/astc_encode_block_4x4_rgba.js +337 -0
- package/src/format/texture/astc/astc_integer_sequence.d.ts.map +1 -0
- package/src/format/texture/{basis → astc}/astc_integer_sequence.js +251 -251
- package/src/format/texture/astc/astc_partition.d.ts.map +1 -0
- package/src/format/texture/{basis → astc}/astc_partition.js +199 -199
- package/src/format/texture/basis/transcode/etc1s_to_astc.js +329 -329
- package/src/format/texture/basis/transcode/etc1s_to_etc2.d.ts.map +1 -1
- package/src/format/texture/basis/transcode/etc1s_to_etc2.js +305 -332
- package/src/format/texture/basis/transcode/fit_endpoints.d.ts.map +1 -1
- package/src/format/texture/basis/transcode/fit_endpoints.js +14 -27
- package/src/format/texture/basis/uastc/uastc_bc7_tables.d.ts +66 -0
- package/src/format/texture/basis/uastc/uastc_bc7_tables.d.ts.map +1 -0
- package/src/format/texture/basis/uastc/uastc_bc7_tables.js +148 -0
- package/src/format/texture/basis/uastc/uastc_decode_block.js +463 -463
- package/src/format/texture/basis/uastc/uastc_to_astc.js +421 -421
- package/src/format/texture/basis/uastc/uastc_to_bc5.d.ts +1 -6
- package/src/format/texture/basis/uastc/uastc_to_bc5.d.ts.map +1 -1
- package/src/format/texture/basis/uastc/uastc_to_bc5.js +48 -115
- package/src/format/texture/basis/uastc/uastc_to_bc7.d.ts.map +1 -1
- package/src/format/texture/basis/uastc/uastc_to_bc7.js +604 -602
- package/src/format/texture/bc/bc1_decode_block.d.ts +19 -0
- package/src/format/texture/bc/bc1_decode_block.d.ts.map +1 -0
- package/src/format/texture/bc/bc1_decode_block.js +22 -0
- package/src/format/texture/bc/bc1_decode_colors.d.ts +27 -0
- package/src/format/texture/bc/bc1_decode_colors.d.ts.map +1 -0
- package/src/format/texture/bc/bc1_decode_colors.js +100 -0
- package/src/format/texture/bc/bc2_decode_block.d.ts +18 -0
- package/src/format/texture/bc/bc2_decode_block.d.ts.map +1 -0
- package/src/format/texture/bc/bc2_decode_block.js +28 -0
- package/src/format/texture/bc/bc3_decode_block.d.ts +18 -0
- package/src/format/texture/bc/bc3_decode_block.d.ts.map +1 -0
- package/src/format/texture/bc/bc3_decode_block.js +23 -0
- package/src/format/texture/bc/bc4_decode_channel.d.ts +56 -0
- package/src/format/texture/bc/bc4_decode_channel.d.ts.map +1 -0
- package/src/format/texture/bc/bc4_decode_channel.js +138 -0
- package/src/format/texture/bc/bc4_encode_block.d.ts +43 -0
- package/src/format/texture/bc/bc4_encode_block.d.ts.map +1 -0
- package/src/format/texture/bc/bc4_encode_block.js +324 -0
- package/src/format/texture/bc/bc4_snorm_decode_block.d.ts +18 -0
- package/src/format/texture/bc/bc4_snorm_decode_block.d.ts.map +1 -0
- package/src/format/texture/bc/bc4_snorm_decode_block.js +27 -0
- package/src/format/texture/bc/bc4_unorm_decode_block.d.ts +17 -0
- package/src/format/texture/bc/bc4_unorm_decode_block.d.ts.map +1 -0
- package/src/format/texture/bc/bc4_unorm_decode_block.js +26 -0
- package/src/format/texture/bc/bc5_encode_block.d.ts +25 -0
- package/src/format/texture/bc/bc5_encode_block.d.ts.map +1 -0
- package/src/format/texture/bc/bc5_encode_block.js +34 -0
- package/src/format/texture/bc/bc5_snorm_decode_block.d.ts +18 -0
- package/src/format/texture/bc/bc5_snorm_decode_block.d.ts.map +1 -0
- package/src/format/texture/bc/bc5_snorm_decode_block.js +27 -0
- package/src/format/texture/bc/bc5_unorm_decode_block.d.ts +17 -0
- package/src/format/texture/bc/bc5_unorm_decode_block.d.ts.map +1 -0
- package/src/format/texture/bc/bc5_unorm_decode_block.js +26 -0
- package/src/format/texture/bc/bc6h_decode_texels.d.ts +30 -0
- package/src/format/texture/bc/bc6h_decode_texels.d.ts.map +1 -0
- package/src/format/texture/bc/bc6h_decode_texels.js +430 -0
- package/src/format/texture/bc/bc6h_sfloat_decode_block.d.ts +20 -0
- package/src/format/texture/bc/bc6h_sfloat_decode_block.d.ts.map +1 -0
- package/src/format/texture/bc/bc6h_sfloat_decode_block.js +23 -0
- package/src/format/texture/bc/bc6h_ufloat_decode_block.d.ts +18 -0
- package/src/format/texture/bc/bc6h_ufloat_decode_block.d.ts.map +1 -0
- package/src/format/texture/bc/bc6h_ufloat_decode_block.js +21 -0
- package/src/format/texture/bc/bc7_decode_block.d.ts +30 -0
- package/src/format/texture/bc/bc7_decode_block.d.ts.map +1 -0
- package/src/format/texture/bc/bc7_decode_block.js +232 -0
- package/src/format/texture/bc/bc7_encode_block.d.ts +39 -0
- package/src/format/texture/bc/bc7_encode_block.d.ts.map +1 -0
- package/src/format/texture/bc/bc7_encode_block.js +423 -0
- package/src/format/texture/bc/bc7_tables.d.ts +126 -0
- package/src/format/texture/bc/bc7_tables.d.ts.map +1 -0
- package/src/format/texture/{basis/uastc → bc}/bc7_tables.js +225 -276
- package/src/format/texture/bc/bc7_write_block.d.ts +65 -0
- package/src/format/texture/bc/bc7_write_block.d.ts.map +1 -0
- package/src/format/texture/{basis/uastc → bc}/bc7_write_block.js +185 -227
- package/src/format/texture/etc/eac_decode_channel.d.ts +50 -0
- package/src/format/texture/etc/eac_decode_channel.d.ts.map +1 -0
- package/src/format/texture/etc/eac_decode_channel.js +142 -0
- package/src/format/texture/etc/eac_modifiers.d.ts +15 -0
- package/src/format/texture/etc/eac_modifiers.d.ts.map +1 -0
- package/src/format/texture/etc/eac_modifiers.js +31 -0
- package/src/format/texture/etc/eac_r11_snorm_decode_block.d.ts +21 -0
- package/src/format/texture/etc/eac_r11_snorm_decode_block.d.ts.map +1 -0
- package/src/format/texture/etc/eac_r11_snorm_decode_block.js +30 -0
- package/src/format/texture/etc/eac_r11_unorm_decode_block.d.ts +20 -0
- package/src/format/texture/etc/eac_r11_unorm_decode_block.d.ts.map +1 -0
- package/src/format/texture/etc/eac_r11_unorm_decode_block.js +29 -0
- package/src/format/texture/etc/eac_rg11_snorm_decode_block.d.ts +19 -0
- package/src/format/texture/etc/eac_rg11_snorm_decode_block.d.ts.map +1 -0
- package/src/format/texture/etc/eac_rg11_snorm_decode_block.js +28 -0
- package/src/format/texture/etc/eac_rg11_unorm_decode_block.d.ts +19 -0
- package/src/format/texture/etc/eac_rg11_unorm_decode_block.d.ts.map +1 -0
- package/src/format/texture/etc/eac_rg11_unorm_decode_block.js +28 -0
- package/src/format/texture/etc/etc2_decode_color.d.ts +25 -0
- package/src/format/texture/etc/etc2_decode_color.d.ts.map +1 -0
- package/src/format/texture/etc/etc2_decode_color.js +370 -0
- package/src/format/texture/etc/etc2_rgb8_decode_block.d.ts +18 -0
- package/src/format/texture/etc/etc2_rgb8_decode_block.d.ts.map +1 -0
- package/src/format/texture/etc/etc2_rgb8_decode_block.js +21 -0
- package/src/format/texture/etc/etc2_rgb8a1_decode_block.d.ts +21 -0
- package/src/format/texture/etc/etc2_rgb8a1_decode_block.d.ts.map +1 -0
- package/src/format/texture/etc/etc2_rgb8a1_decode_block.js +24 -0
- package/src/format/texture/etc/etc2_rgba8_decode_block.d.ts +18 -0
- package/src/format/texture/etc/etc2_rgba8_decode_block.d.ts.map +1 -0
- package/src/format/texture/etc/etc2_rgba8_decode_block.js +24 -0
- package/src/format/texture/fit/fit_line.d.ts +23 -0
- package/src/format/texture/fit/fit_line.d.ts.map +1 -0
- package/src/format/texture/fit/fit_line.js +123 -0
- package/src/format/texture/fit/fit_line_refine.d.ts +21 -0
- package/src/format/texture/fit/fit_line_refine.d.ts.map +1 -0
- package/src/format/texture/fit/fit_line_refine.js +69 -0
- package/src/format/texture/fit/fit_line_solve.d.ts +23 -0
- package/src/format/texture/fit/fit_line_solve.d.ts.map +1 -0
- package/src/format/texture/fit/fit_line_solve.js +71 -0
- package/src/format/texture/texel_decode_image.d.ts +44 -0
- package/src/format/texture/texel_decode_image.d.ts.map +1 -0
- package/src/format/texture/texel_decode_image.js +251 -0
- package/src/format/texture/texel_encode_image.d.ts +77 -0
- package/src/format/texture/texel_encode_image.d.ts.map +1 -0
- package/src/format/texture/texel_encode_image.js +187 -0
- package/src/shade/renderer/ShadeIndirectLightingMode.js +2 -0
- package/src/shade/renderer/acoustics/GPUAcousticLattice.d.ts +1 -1
- package/src/shade/renderer/acoustics/GPUAcoustics.d.ts +1 -1
- package/src/shade/renderer/loader/mtf/mtf_encode_texture.d.ts +1 -0
- package/src/shade/renderer/loader/mtf/mtf_encode_texture.d.ts.map +1 -1
- package/src/shade/renderer/loader/mtf/mtf_encode_texture.js +102 -28
- package/src/shade/renderer/loader/mtf/mtf_replace_textures.d.ts +19 -0
- package/src/shade/renderer/loader/mtf/mtf_replace_textures.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/mtf_replace_textures.js +60 -0
- package/src/shade/renderer/loader/mtf/mtf_write.d.ts.map +1 -1
- package/src/shade/renderer/loader/mtf/mtf_write.js +7 -31
- package/src/shade/renderer/loader/mtf/mtf_write_collection.d.ts +23 -0
- package/src/shade/renderer/loader/mtf/mtf_write_collection.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/mtf_write_collection.js +36 -0
- package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4.d.ts +13 -0
- package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4.d.ts.map +1 -0
- package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4.js +39 -0
- package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgb.d.ts +3 -2
- package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgb.d.ts.map +1 -1
- package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgb.js +6 -21
- package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgba.d.ts +42 -0
- package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgba.d.ts.map +1 -0
- package/src/shade/renderer/texture/encode/chunk_astc_encode_block_4x4_rgba.js +612 -0
- package/src/shade/renderer/texture/encode/chunk_bc1_encode_block.d.ts +5 -4
- package/src/shade/renderer/texture/encode/chunk_bc1_encode_block.d.ts.map +1 -1
- package/src/shade/renderer/texture/encode/chunk_bc1_encode_block.js +8 -25
- package/src/shade/renderer/texture/encode/chunk_bc6h_encode_block_mode11.d.ts.map +1 -1
- package/src/shade/renderer/texture/encode/chunk_bc6h_encode_block_mode11.js +3 -19
- package/src/shade/renderer/texture/encode/chunk_bc7_encode_block.d.ts +14 -4
- package/src/shade/renderer/texture/encode/chunk_bc7_encode_block.d.ts.map +1 -1
- package/src/shade/renderer/texture/encode/chunk_bc7_encode_block.js +65 -54
- package/src/shade/renderer/texture/encode/chunk_bc7_encode_block_mode6.d.ts +2 -2
- package/src/shade/renderer/texture/encode/chunk_bc7_encode_block_mode6.d.ts.map +1 -1
- package/src/shade/renderer/texture/encode/chunk_bc7_encode_block_mode6.js +5 -22
- package/src/shade/renderer/texture/encode/chunk_bc7_partition_2.js +1 -1
- package/src/shade/renderer/texture/encode/chunk_scatter_principal_axis.d.ts +27 -0
- package/src/shade/renderer/texture/encode/chunk_scatter_principal_axis.d.ts.map +1 -0
- package/src/shade/renderer/texture/encode/chunk_scatter_principal_axis.js +147 -0
- package/src/shade/renderer/texture/encode/shader_texture_encode_astc_4x4.d.ts +3 -4
- package/src/shade/renderer/texture/encode/shader_texture_encode_astc_4x4.d.ts.map +1 -1
- package/src/shade/renderer/texture/encode/shader_texture_encode_astc_4x4.js +6 -13
- package/src/shade/renderer/texture/encode/shader_texture_encode_bc7_rgb.d.ts +13 -0
- package/src/shade/renderer/texture/encode/shader_texture_encode_bc7_rgb.d.ts.map +1 -0
- package/src/shade/renderer/texture/encode/shader_texture_encode_bc7_rgb.js +66 -0
- package/src/shade/renderer/texture/encode/texture_encode.d.ts +28 -1
- package/src/shade/renderer/texture/encode/texture_encode.d.ts.map +1 -1
- package/src/shade/renderer/texture/encode/texture_encode.js +202 -168
- package/src/shade/renderer/texture/encode/texture_encode_shader.d.ts +13 -1
- package/src/shade/renderer/texture/encode/texture_encode_shader.d.ts.map +1 -1
- package/src/shade/renderer/texture/encode/texture_encode_shader.js +146 -108
- package/src/shade/renderer/texture/format/texture_formats_to_build.d.ts +20 -0
- package/src/shade/renderer/texture/format/texture_formats_to_build.d.ts.map +1 -0
- package/src/shade/renderer/texture/format/texture_formats_to_build.js +98 -0
- package/src/shade/renderer/texture/mipmaps/WebGPUMipmapGenerator.d.ts.map +1 -1
- package/src/shade/renderer/texture/mipmaps/WebGPUMipmapGenerator.js +4 -23
- package/src/shade/renderer/texture/mipmaps/cpu/MipmapBilinearAxis.d.ts +53 -0
- package/src/shade/renderer/texture/mipmaps/cpu/MipmapBilinearAxis.d.ts.map +1 -0
- package/src/shade/renderer/texture/mipmaps/cpu/MipmapBilinearAxis.js +76 -0
- package/src/shade/renderer/texture/mipmaps/cpu/MipmapKernelAxis.d.ts +40 -0
- package/src/shade/renderer/texture/mipmaps/cpu/MipmapKernelAxis.d.ts.map +1 -0
- package/src/shade/renderer/texture/mipmaps/cpu/MipmapKernelAxis.js +43 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_bilinear_centres.d.ts +17 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_bilinear_centres.d.ts.map +1 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_bilinear_centres.js +29 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_bilinear_sample.d.ts +21 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_bilinear_sample.d.ts.map +1 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_bilinear_sample.js +91 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_chain_cpu.d.ts +32 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_chain_cpu.d.ts.map +1 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_chain_cpu.js +216 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_cubic_filter_cpu.d.ts +30 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_cubic_filter_cpu.d.ts.map +1 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_cubic_filter_cpu.js +134 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_catmull_rom_cpu.d.ts +16 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_catmull_rom_cpu.d.ts.map +1 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_catmull_rom_cpu.js +33 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_linear_cpu.d.ts +18 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_linear_cpu.d.ts.map +1 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_linear_cpu.js +71 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_linear_normal_cpu.d.ts +20 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_linear_normal_cpu.d.ts.map +1 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_linear_normal_cpu.js +57 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_magic_kernel_cpu.d.ts +18 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_magic_kernel_cpu.d.ts.map +1 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_magic_kernel_cpu.js +111 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_mitchell_cpu.d.ts +16 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_mitchell_cpu.d.ts.map +1 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_mitchell_cpu.js +33 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_mks_cpu.d.ts +18 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_mks_cpu.d.ts.map +1 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_mks_cpu.js +128 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_wronski2021_cpu.d.ts +21 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_wronski2021_cpu.d.ts.map +1 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_filter_wronski2021_cpu.js +169 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_kernel_reduce.d.ts +21 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_kernel_reduce.d.ts.map +1 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_kernel_reduce.js +119 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_source_centre.d.ts +16 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_source_centre.d.ts.map +1 -0
- package/src/shade/renderer/texture/mipmaps/cpu/mipmap_source_centre.js +19 -0
- package/src/shade/renderer/texture/mipmaps/cpu/texels_f32_to_rgba8unorm.d.ts +24 -0
- package/src/shade/renderer/texture/mipmaps/cpu/texels_f32_to_rgba8unorm.d.ts.map +1 -0
- package/src/shade/renderer/texture/mipmaps/cpu/texels_f32_to_rgba8unorm.js +41 -0
- package/src/shade/renderer/texture/mipmaps/cpu/texels_f32_to_rgba8unorm_srgb.d.ts +24 -0
- package/src/shade/renderer/texture/mipmaps/cpu/texels_f32_to_rgba8unorm_srgb.d.ts.map +1 -0
- package/src/shade/renderer/texture/mipmaps/cpu/texels_f32_to_rgba8unorm_srgb.js +140 -0
- package/src/shade/renderer/texture/mipmaps/cpu/texels_rgba8unorm_srgb_to_f32.d.ts +21 -0
- package/src/shade/renderer/texture/mipmaps/cpu/texels_rgba8unorm_srgb_to_f32.d.ts.map +1 -0
- package/src/shade/renderer/texture/mipmaps/cpu/texels_rgba8unorm_srgb_to_f32.js +35 -0
- package/src/shade/renderer/texture/mipmaps/cpu/texels_rgba8unorm_to_f32.d.ts +19 -0
- package/src/shade/renderer/texture/mipmaps/cpu/texels_rgba8unorm_to_f32.d.ts.map +1 -0
- package/src/shade/renderer/texture/mipmaps/cpu/texels_rgba8unorm_to_f32.js +27 -0
- package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_catmull_rom.js +4 -4
- package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_linear.d.ts +13 -0
- package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_linear.d.ts.map +1 -1
- package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_linear.js +54 -4
- package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_mitchell.js +4 -4
- package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_mks.d.ts.map +1 -1
- package/src/shade/renderer/texture/mipmaps/filters/mipmap_shader_code_mks.js +9 -13
- package/src/shade/renderer/texture/texture_block_encodings.d.ts +33 -0
- package/src/shade/renderer/texture/texture_block_encodings.d.ts.map +1 -0
- package/src/shade/renderer/texture/texture_block_encodings.js +89 -0
- package/src/format/texture/basis/astc_block.d.ts.map +0 -1
- package/src/format/texture/basis/astc_integer_sequence.d.ts.map +0 -1
- package/src/format/texture/basis/astc_partition.d.ts.map +0 -1
- package/src/format/texture/basis/uastc/bc7_tables.d.ts +0 -111
- package/src/format/texture/basis/uastc/bc7_tables.d.ts.map +0 -1
- package/src/format/texture/basis/uastc/bc7_write_block.d.ts +0 -124
- package/src/format/texture/basis/uastc/bc7_write_block.d.ts.map +0 -1
- /package/src/format/texture/{basis → astc}/astc_integer_sequence.d.ts +0 -0
- /package/src/format/texture/{basis → astc}/astc_partition.d.ts +0 -0
|
@@ -1,421 +1,421 @@
|
|
|
1
|
-
import { ASTC_BLOCK_BYTES } from "
|
|
2
|
-
import { astc_write_integer_sequence } from "
|
|
3
|
-
import { astc_find_partition_seed } from "
|
|
4
|
-
import { uastc_decode_block, UASTC_BLOCK_BYTES } from "./uastc_decode_block.js";
|
|
5
|
-
import {
|
|
6
|
-
UASTC_MODE_BY_INDEX,
|
|
7
|
-
UASTC_MODE_SOLID,
|
|
8
|
-
UASTC_PATTERNS_2,
|
|
9
|
-
UASTC_PATTERNS_2_BC7_3,
|
|
10
|
-
UASTC_PATTERNS_3,
|
|
11
|
-
UASTC_WEIGHT_LEVELS
|
|
12
|
-
} from "./uastc_tables.js";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Where each field of an ASTC block begins, counting from the least significant bit.
|
|
16
|
-
*
|
|
17
|
-
* @readonly
|
|
18
|
-
*/
|
|
19
|
-
const BLOCK_MODE_BIT = 0;
|
|
20
|
-
const PARTITION_COUNT_BIT = 11;
|
|
21
|
-
const PARTITION_SEED_BIT = 13;
|
|
22
|
-
const CEM_SINGLE_BIT = 13;
|
|
23
|
-
const CEM_SELECTOR_BIT = 23;
|
|
24
|
-
const CEM_SHARED_BIT = 25;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* The one mode whose two subsets are indexed by the three-subset pattern table UASTC took from BC7.
|
|
28
|
-
*
|
|
29
|
-
* @readonly
|
|
30
|
-
* @type {number}
|
|
31
|
-
*/
|
|
32
|
-
const MODE_BC7_3_SUBSET_PATTERNS = 7;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* The ASTC weight-range field for a UASTC one, as `(R, H)`.
|
|
36
|
-
*
|
|
37
|
-
* A block mode names its weight range through a three-bit `R` and the high-precision flag `H`, with
|
|
38
|
-
* `R` running 2 to 7 over six ranges at each `H`. UASTC uses five of the twelve — 2, 4, 8, 16 and 32
|
|
39
|
-
* levels — and this is where each sits.
|
|
40
|
-
*
|
|
41
|
-
* @readonly
|
|
42
|
-
* @type {Object<number, {r: number, h: number}>}
|
|
43
|
-
*/
|
|
44
|
-
const WEIGHT_RANGE_FIELD = {
|
|
45
|
-
0: { r: 2, h: 0 }, // 2 levels
|
|
46
|
-
2: { r: 4, h: 0 }, // 4
|
|
47
|
-
5: { r: 7, h: 0 }, // 8
|
|
48
|
-
8: { r: 4, h: 1 }, // 16
|
|
49
|
-
11: { r: 7, h: 1 }, // 32
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* The 4x4 single-plane and dual-plane block modes, by UASTC weight range.
|
|
54
|
-
*
|
|
55
|
-
* **Assembled from the specification's layout rather than tabulated.** The low-precision row places
|
|
56
|
-
* `D` at bit 10, `H` at 9, the height term `B` at 8:7, the width term `A` at 6:5, `R0` at 4, two
|
|
57
|
-
* zero bits at 3:2, then `R2` and `R1` at 1:0 — with the grid `A+2` wide by `B+4` high. A 4x4 grid is
|
|
58
|
-
* therefore `A = 2, B = 0`, and everything else follows from the range.
|
|
59
|
-
*
|
|
60
|
-
* @param {number} weight_range UASTC's range index
|
|
61
|
-
* @param {boolean} dual_plane
|
|
62
|
-
* @returns {number} eleven bits
|
|
63
|
-
*/
|
|
64
|
-
function block_mode(weight_range, dual_plane) {
|
|
65
|
-
const { r, h } = WEIGHT_RANGE_FIELD[weight_range];
|
|
66
|
-
|
|
67
|
-
const a = 2;
|
|
68
|
-
const b = 0;
|
|
69
|
-
|
|
70
|
-
const r0 = r & 1;
|
|
71
|
-
const r1 = (r >> 1) & 1;
|
|
72
|
-
const r2 = (r >> 2) & 1;
|
|
73
|
-
|
|
74
|
-
return ((dual_plane ? 1 : 0) << 10)
|
|
75
|
-
| (h << 9)
|
|
76
|
-
| (b << 7)
|
|
77
|
-
| (a << 5)
|
|
78
|
-
| (r0 << 4)
|
|
79
|
-
| (r2 << 1)
|
|
80
|
-
| r1;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* The ASTC partition seed and subset relabelling for every UASTC pattern, worked out once.
|
|
85
|
-
*
|
|
86
|
-
* **Derived by search, not copied.** UASTC names a pattern by index into its own list and ASTC names
|
|
87
|
-
* one by a seed into a hash over 1024 possibilities; the correspondence is a table of numbers that
|
|
88
|
-
* exists in the reference transcoder. Searching for it here means a wrong entry cannot survive —
|
|
89
|
-
* there is no entry, only a seed whose pattern is required to agree texel for texel.
|
|
90
|
-
*
|
|
91
|
-
* Built lazily so the search is paid for once per process and only by a caller that transcodes.
|
|
92
|
-
*
|
|
93
|
-
* @param {Uint8Array} table the flat pattern list
|
|
94
|
-
* @param {number} count how many patterns it holds
|
|
95
|
-
* @param {number} partition_count
|
|
96
|
-
* @returns {{seed: number, permutation: number[]}[]}
|
|
97
|
-
*/
|
|
98
|
-
function seeds_for(table, count, partition_count) {
|
|
99
|
-
const out = [];
|
|
100
|
-
|
|
101
|
-
for (let pattern = 0; pattern < count; pattern++) {
|
|
102
|
-
const wanted = table.subarray(pattern * 16, pattern * 16 + 16);
|
|
103
|
-
|
|
104
|
-
const found = astc_find_partition_seed(wanted, partition_count);
|
|
105
|
-
|
|
106
|
-
if (found === undefined) {
|
|
107
|
-
throw new Error(
|
|
108
|
-
`UASTC: pattern ${pattern} of the ${partition_count}-subset table has no ASTC`
|
|
109
|
-
+ ` partition seed, which cannot happen for a pattern UASTC took from ASTC — the`
|
|
110
|
-
+ ` partition hash or the pattern table is wrong.`
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
out.push(found);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return out;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* @type {{seed: number, permutation: number[]}[][]}
|
|
122
|
-
*/
|
|
123
|
-
let seed_tables;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* @returns {{two: object[], three: object[], two_bc7_3: object[]}}
|
|
127
|
-
*/
|
|
128
|
-
function partition_seeds() {
|
|
129
|
-
if (seed_tables === undefined) {
|
|
130
|
-
seed_tables = {
|
|
131
|
-
two: seeds_for(UASTC_PATTERNS_2, 30, 2),
|
|
132
|
-
three: seeds_for(UASTC_PATTERNS_3, 11, 3),
|
|
133
|
-
two_bc7_3: seeds_for(UASTC_PATTERNS_2_BC7_3, 19, 2),
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return seed_tables;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Transcode UASTC to ASTC 4x4 by repacking, which is what the format was built for.
|
|
142
|
-
*
|
|
143
|
-
* **Nothing is fitted and nothing is lost.** UASTC's nineteen modes were laid out so that each one's
|
|
144
|
-
* fields *are* an ASTC block's fields: the endpoints are already in ASTC's quantized space at a range
|
|
145
|
-
* ASTC names, the weights are already ASTC weights, and the partition patterns were taken from
|
|
146
|
-
* ASTC's own hash. What is left is arithmetic on bit positions — ASTC interleaves its integer
|
|
147
|
-
* sequences where UASTC keeps them in two plain runs, and puts its weights at the far end of the
|
|
148
|
-
* block in reverse.
|
|
149
|
-
*
|
|
150
|
-
* That is the whole difference between this and the re-encode measured at 34.9 dB in §9.18. A
|
|
151
|
-
* re-encode has to choose one colour line for a block that may have three, which is exactly what a
|
|
152
|
-
* normal map is worst at; a repack keeps the three the file already had.
|
|
153
|
-
*
|
|
154
|
-
* **Endpoints may be swapped, which is lossless.** Colour endpoint modes 8 and 12 swap their pair and
|
|
155
|
-
* blue-contract when the second endpoint's channel sum falls below the first's. UASTC guarantees the
|
|
156
|
-
* order it needs for BC7's rules rather than ASTC's, so a subset that would trip the rule has its
|
|
157
|
-
* pair exchanged and its weights inverted — the same block, described the other way up.
|
|
158
|
-
*
|
|
159
|
-
* @param {Uint8Array} blocks UASTC blocks, tightly packed
|
|
160
|
-
* @param {number} block_count
|
|
161
|
-
* @returns {Uint8Array} tightly packed ASTC blocks, in raster order
|
|
162
|
-
* @throws {Error} for a mode this cannot express
|
|
163
|
-
*
|
|
164
|
-
* @see the UASTC LDR 4x4 specification, "Converting to ASTC"
|
|
165
|
-
* @author Alex Goldring
|
|
166
|
-
* @copyright Company Named Limited (c) 2026
|
|
167
|
-
*/
|
|
168
|
-
export function uastc_to_astc(blocks, block_count) {
|
|
169
|
-
const out = new Uint8Array(block_count * ASTC_BLOCK_BYTES);
|
|
170
|
-
|
|
171
|
-
const seeds = partition_seeds();
|
|
172
|
-
|
|
173
|
-
for (let block = 0; block < block_count; block++) {
|
|
174
|
-
const decoded = uastc_decode_block(blocks, block * UASTC_BLOCK_BYTES);
|
|
175
|
-
|
|
176
|
-
write_astc(out, block * ASTC_BLOCK_BYTES, decoded, seeds);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return out;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Compose one ASTC block from a decoded UASTC one.
|
|
184
|
-
*
|
|
185
|
-
* @param {Uint8Array} out
|
|
186
|
-
* @param {number} offset
|
|
187
|
-
* @param {object} decoded from {@link uastc_decode_block}
|
|
188
|
-
* @param {object} seeds
|
|
189
|
-
*/
|
|
190
|
-
function write_astc(out, offset, decoded, seeds) {
|
|
191
|
-
if (decoded.mode === UASTC_MODE_SOLID) {
|
|
192
|
-
write_void_extent(out, offset, decoded.endpoints);
|
|
193
|
-
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const mode = UASTC_MODE_BY_INDEX[decoded.mode];
|
|
198
|
-
|
|
199
|
-
const levels = UASTC_WEIGHT_LEVELS[mode.weight_range];
|
|
200
|
-
|
|
201
|
-
const weight_bits = Math.log2(levels);
|
|
202
|
-
|
|
203
|
-
const subsets = mode.subsets;
|
|
204
|
-
|
|
205
|
-
const endpoints = [...decoded.endpoints_quantised];
|
|
206
|
-
const weights = Uint8Array.from(decoded.weight_indices);
|
|
207
|
-
|
|
208
|
-
disable_blue_contraction(mode, decoded, endpoints, weights, levels);
|
|
209
|
-
|
|
210
|
-
let seed = 0;
|
|
211
|
-
let permutation = [0];
|
|
212
|
-
|
|
213
|
-
if (subsets > 1) {
|
|
214
|
-
/*
|
|
215
|
-
Three tables, and which one a mode reads is a property of the mode rather than of its subset
|
|
216
|
-
count alone: mode 7 has two subsets but indexes the nineteen patterns UASTC borrowed from
|
|
217
|
-
BC7's three-subset set, which it then folds down to two.
|
|
218
|
-
*/
|
|
219
|
-
const table = mode.mode === MODE_BC7_3_SUBSET_PATTERNS
|
|
220
|
-
? seeds.two_bc7_3
|
|
221
|
-
: (subsets === 3 ? seeds.three : seeds.two);
|
|
222
|
-
|
|
223
|
-
const chosen = table[decoded.pattern];
|
|
224
|
-
|
|
225
|
-
seed = chosen.seed;
|
|
226
|
-
permutation = chosen.permutation;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/*
|
|
230
|
-
**The two number their subsets the same way, and this is where that is checked.** A seed found
|
|
231
|
-
by search is only required to *group* the texels as UASTC does; which group it calls subset 0 is
|
|
232
|
-
the hash's business, and in general an encoder would have to reorder its endpoint pairs to
|
|
233
|
-
match. In fact no pattern ever needs it — all 60 across the three tables come back as the
|
|
234
|
-
identity, which follows from UASTC having taken its patterns from ASTC in the first place.
|
|
235
|
-
|
|
236
|
-
So there is no reordering code here, because code that never runs is code that is never right.
|
|
237
|
-
If a pattern ever did need it the block would be silently wrong, and this refuses instead.
|
|
238
|
-
|
|
239
|
-
**Deleting this will not fail a test, and it should still not be deleted.** It cannot fire while
|
|
240
|
-
the pattern tables and the partition hash both stay as they are, which is exactly the pair of
|
|
241
|
-
assumptions it exists to catch someone breaking.
|
|
242
|
-
*/
|
|
243
|
-
if (permutation.some((to, from) => to !== from)) {
|
|
244
|
-
throw new Error(
|
|
245
|
-
`UASTC: pattern ${decoded.pattern} maps to ASTC seed ${seed} with its subsets renumbered`
|
|
246
|
-
+ ` (${permutation.join(", ")}), which no UASTC pattern does. The endpoint pairs would`
|
|
247
|
-
+ ` have to be reordered to match, and nothing here does that.`
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
const ordered = endpoints;
|
|
252
|
-
|
|
253
|
-
let bits = 0n;
|
|
254
|
-
|
|
255
|
-
const put = (value, width, at) => {
|
|
256
|
-
bits |= (BigInt(value) & ((1n << BigInt(width)) - 1n)) << BigInt(at);
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
put(block_mode(mode.weight_range, mode.dual_plane), 11, BLOCK_MODE_BIT);
|
|
260
|
-
put(subsets - 1, 2, PARTITION_COUNT_BIT);
|
|
261
|
-
|
|
262
|
-
let cursor;
|
|
263
|
-
|
|
264
|
-
if (subsets === 1) {
|
|
265
|
-
put(mode.cem, 4, CEM_SINGLE_BIT);
|
|
266
|
-
cursor = 17;
|
|
267
|
-
} else {
|
|
268
|
-
put(seed, 10, PARTITION_SEED_BIT);
|
|
269
|
-
|
|
270
|
-
// selector 00 means every partition shares one mode, which is always true of a UASTC block
|
|
271
|
-
put(0, 2, CEM_SELECTOR_BIT);
|
|
272
|
-
put(mode.cem, 4, CEM_SHARED_BIT);
|
|
273
|
-
|
|
274
|
-
cursor = 29;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
astc_write_integer_sequence(
|
|
278
|
-
(value, width) => {
|
|
279
|
-
put(value, width, cursor);
|
|
280
|
-
cursor += width;
|
|
281
|
-
},
|
|
282
|
-
ordered,
|
|
283
|
-
mode.endpoint_range
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
if (mode.dual_plane) {
|
|
287
|
-
// the component selector sits immediately below the weights, at the top of the block
|
|
288
|
-
put(decoded.component_selector, 2, 128 - 16 * 2 * weight_bits - 2);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/*
|
|
292
|
-
The weights fill the top of the block with the whole field's bit order reversed, and a dual-plane
|
|
293
|
-
block interleaves its two planes texel by texel. Every range UASTC uses is a power of two, so
|
|
294
|
-
these are plain bits with no integer sequence to interleave.
|
|
295
|
-
*/
|
|
296
|
-
const plane_count = mode.dual_plane ? 2 : 1;
|
|
297
|
-
|
|
298
|
-
let field = 0n;
|
|
299
|
-
|
|
300
|
-
for (let i = 0; i < 16 * plane_count; i++) {
|
|
301
|
-
field |= BigInt(weights[i]) << BigInt(i * weight_bits);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
const width = 16 * plane_count * weight_bits;
|
|
305
|
-
|
|
306
|
-
for (let i = 0; i < width; i++) {
|
|
307
|
-
if ((field >> BigInt(i)) & 1n) {
|
|
308
|
-
bits |= 1n << BigInt(127 - i);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
for (let i = 0; i < ASTC_BLOCK_BYTES; i++) {
|
|
313
|
-
out[offset + i] = Number((bits >> BigInt(i * 8)) & 0xFFn);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Put each subset's endpoints the way round that stops a decoder blue-contracting them.
|
|
319
|
-
*
|
|
320
|
-
* **Colour endpoint modes 8 and 12 have a rule with no flag.** A decoder compares the two endpoints
|
|
321
|
-
* by the sum of their colour channels, and where the second falls below the first it swaps the pair
|
|
322
|
-
* *and* applies blue contraction — `r = (r + b) >> 1`, `g = (g + b) >> 1` — to both. That is a
|
|
323
|
-
* different picture rather than an inverted one, and nothing in the block records that it happened.
|
|
324
|
-
*
|
|
325
|
-
* UASTC orders its endpoints to suit BC7's rules, which are not these, so a subset can easily arrive
|
|
326
|
-
* the wrong way round. Exchanging the pair and inverting that subset's weights describes the same
|
|
327
|
-
* block the other way up, which is why the specification calls this lossless — and it has to be done
|
|
328
|
-
* per subset, since each has its own pair and its own texels.
|
|
329
|
-
*
|
|
330
|
-
* Modes 4 and 6 have no such rule and are left alone; comparing sums there would swap pairs for
|
|
331
|
-
* nothing and change what the block decodes to.
|
|
332
|
-
*
|
|
333
|
-
* @param {object} mode the UASTC mode descriptor
|
|
334
|
-
* @param {object} decoded
|
|
335
|
-
* @param {number[]} endpoints quantised values, modified in place
|
|
336
|
-
* @param {Uint8Array} weights modified in place
|
|
337
|
-
* @param {number} levels how many weight levels the mode has
|
|
338
|
-
*/
|
|
339
|
-
function disable_blue_contraction(mode, decoded, endpoints, weights, levels) {
|
|
340
|
-
if (mode.cem !== 8 && mode.cem !== 12) {
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
const values_per_subset = endpoints.length / mode.subsets;
|
|
345
|
-
|
|
346
|
-
const plane_count = mode.dual_plane ? 2 : 1;
|
|
347
|
-
|
|
348
|
-
for (let subset = 0; subset < mode.subsets; subset++) {
|
|
349
|
-
/*
|
|
350
|
-
The comparison is on the *decoded* colours, which is what the rule is written over. The
|
|
351
|
-
quantised values are monotonic in them per channel but not comparable across channels at
|
|
352
|
-
different ranges, so summing those instead would disagree on the blocks nearest the boundary
|
|
353
|
-
— the ones where getting it wrong is least visible and most likely.
|
|
354
|
-
*/
|
|
355
|
-
const base = subset * 8;
|
|
356
|
-
|
|
357
|
-
const first = decoded.endpoints[base] + decoded.endpoints[base + 1] + decoded.endpoints[base + 2];
|
|
358
|
-
const second = decoded.endpoints[base + 4] + decoded.endpoints[base + 5] + decoded.endpoints[base + 6];
|
|
359
|
-
|
|
360
|
-
if (second >= first) {
|
|
361
|
-
continue;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
for (let pair = 0; pair < values_per_subset; pair += 2) {
|
|
365
|
-
const at = subset * values_per_subset + pair;
|
|
366
|
-
|
|
367
|
-
const swap = endpoints[at];
|
|
368
|
-
|
|
369
|
-
endpoints[at] = endpoints[at + 1];
|
|
370
|
-
endpoints[at + 1] = swap;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
for (let texel = 0; texel < 16; texel++) {
|
|
374
|
-
if (decoded.partition[texel] !== subset) {
|
|
375
|
-
continue;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
for (let plane = 0; plane < plane_count; plane++) {
|
|
379
|
-
const at = texel * plane_count + plane;
|
|
380
|
-
|
|
381
|
-
weights[at] = levels - 1 - weights[at];
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* Write a void-extent block: one colour over the whole block, which is UASTC's solid mode.
|
|
389
|
-
*
|
|
390
|
-
* The magic `0x1FC` in the low bits is what marks a block void-extent rather than a weight grid, and
|
|
391
|
-
* the four `0x1FFF` coordinates are the "unused" extent that tells a decoder not to try to
|
|
392
|
-
* interpolate across neighbouring blocks. The colour is stored as four 16-bit channels, so an 8-bit
|
|
393
|
-
* value is replicated into both halves.
|
|
394
|
-
*
|
|
395
|
-
* @param {Uint8Array} out
|
|
396
|
-
* @param {number} offset
|
|
397
|
-
* @param {Uint8Array} endpoints the solid colour occupies the first four bytes
|
|
398
|
-
*/
|
|
399
|
-
function write_void_extent(out, offset, endpoints) {
|
|
400
|
-
/*
|
|
401
|
-
Bits 0 to 8 mark the block void-extent, bit 9 says the colour is LDR rather than HDR, and bits
|
|
402
|
-
10 and 11 are reserved and set. Leaving those two clear is a block a decoder is entitled to
|
|
403
|
-
reject, and it is the only thing that separated this from the reference's own solid blocks.
|
|
404
|
-
*/
|
|
405
|
-
let bits = 0x1FCn | (0b11n << 10n);
|
|
406
|
-
|
|
407
|
-
// the two dimensions' extents, all ones, meaning "no extent to speak of"
|
|
408
|
-
for (let i = 0; i < 4; i++) {
|
|
409
|
-
bits |= 0x1FFFn << BigInt(12 + i * 13);
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
for (let channel = 0; channel < 4; channel++) {
|
|
413
|
-
const value = endpoints[channel];
|
|
414
|
-
|
|
415
|
-
bits |= BigInt((value << 8) | value) << BigInt(64 + channel * 16);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
for (let i = 0; i < ASTC_BLOCK_BYTES; i++) {
|
|
419
|
-
out[offset + i] = Number((bits >> BigInt(i * 8)) & 0xFFn);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
1
|
+
import { ASTC_BLOCK_BYTES } from "../../astc/astc_block.js";
|
|
2
|
+
import { astc_write_integer_sequence } from "../../astc/astc_integer_sequence.js";
|
|
3
|
+
import { astc_find_partition_seed } from "../../astc/astc_partition.js";
|
|
4
|
+
import { uastc_decode_block, UASTC_BLOCK_BYTES } from "./uastc_decode_block.js";
|
|
5
|
+
import {
|
|
6
|
+
UASTC_MODE_BY_INDEX,
|
|
7
|
+
UASTC_MODE_SOLID,
|
|
8
|
+
UASTC_PATTERNS_2,
|
|
9
|
+
UASTC_PATTERNS_2_BC7_3,
|
|
10
|
+
UASTC_PATTERNS_3,
|
|
11
|
+
UASTC_WEIGHT_LEVELS
|
|
12
|
+
} from "./uastc_tables.js";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Where each field of an ASTC block begins, counting from the least significant bit.
|
|
16
|
+
*
|
|
17
|
+
* @readonly
|
|
18
|
+
*/
|
|
19
|
+
const BLOCK_MODE_BIT = 0;
|
|
20
|
+
const PARTITION_COUNT_BIT = 11;
|
|
21
|
+
const PARTITION_SEED_BIT = 13;
|
|
22
|
+
const CEM_SINGLE_BIT = 13;
|
|
23
|
+
const CEM_SELECTOR_BIT = 23;
|
|
24
|
+
const CEM_SHARED_BIT = 25;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The one mode whose two subsets are indexed by the three-subset pattern table UASTC took from BC7.
|
|
28
|
+
*
|
|
29
|
+
* @readonly
|
|
30
|
+
* @type {number}
|
|
31
|
+
*/
|
|
32
|
+
const MODE_BC7_3_SUBSET_PATTERNS = 7;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The ASTC weight-range field for a UASTC one, as `(R, H)`.
|
|
36
|
+
*
|
|
37
|
+
* A block mode names its weight range through a three-bit `R` and the high-precision flag `H`, with
|
|
38
|
+
* `R` running 2 to 7 over six ranges at each `H`. UASTC uses five of the twelve — 2, 4, 8, 16 and 32
|
|
39
|
+
* levels — and this is where each sits.
|
|
40
|
+
*
|
|
41
|
+
* @readonly
|
|
42
|
+
* @type {Object<number, {r: number, h: number}>}
|
|
43
|
+
*/
|
|
44
|
+
const WEIGHT_RANGE_FIELD = {
|
|
45
|
+
0: { r: 2, h: 0 }, // 2 levels
|
|
46
|
+
2: { r: 4, h: 0 }, // 4
|
|
47
|
+
5: { r: 7, h: 0 }, // 8
|
|
48
|
+
8: { r: 4, h: 1 }, // 16
|
|
49
|
+
11: { r: 7, h: 1 }, // 32
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The 4x4 single-plane and dual-plane block modes, by UASTC weight range.
|
|
54
|
+
*
|
|
55
|
+
* **Assembled from the specification's layout rather than tabulated.** The low-precision row places
|
|
56
|
+
* `D` at bit 10, `H` at 9, the height term `B` at 8:7, the width term `A` at 6:5, `R0` at 4, two
|
|
57
|
+
* zero bits at 3:2, then `R2` and `R1` at 1:0 — with the grid `A+2` wide by `B+4` high. A 4x4 grid is
|
|
58
|
+
* therefore `A = 2, B = 0`, and everything else follows from the range.
|
|
59
|
+
*
|
|
60
|
+
* @param {number} weight_range UASTC's range index
|
|
61
|
+
* @param {boolean} dual_plane
|
|
62
|
+
* @returns {number} eleven bits
|
|
63
|
+
*/
|
|
64
|
+
function block_mode(weight_range, dual_plane) {
|
|
65
|
+
const { r, h } = WEIGHT_RANGE_FIELD[weight_range];
|
|
66
|
+
|
|
67
|
+
const a = 2;
|
|
68
|
+
const b = 0;
|
|
69
|
+
|
|
70
|
+
const r0 = r & 1;
|
|
71
|
+
const r1 = (r >> 1) & 1;
|
|
72
|
+
const r2 = (r >> 2) & 1;
|
|
73
|
+
|
|
74
|
+
return ((dual_plane ? 1 : 0) << 10)
|
|
75
|
+
| (h << 9)
|
|
76
|
+
| (b << 7)
|
|
77
|
+
| (a << 5)
|
|
78
|
+
| (r0 << 4)
|
|
79
|
+
| (r2 << 1)
|
|
80
|
+
| r1;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The ASTC partition seed and subset relabelling for every UASTC pattern, worked out once.
|
|
85
|
+
*
|
|
86
|
+
* **Derived by search, not copied.** UASTC names a pattern by index into its own list and ASTC names
|
|
87
|
+
* one by a seed into a hash over 1024 possibilities; the correspondence is a table of numbers that
|
|
88
|
+
* exists in the reference transcoder. Searching for it here means a wrong entry cannot survive —
|
|
89
|
+
* there is no entry, only a seed whose pattern is required to agree texel for texel.
|
|
90
|
+
*
|
|
91
|
+
* Built lazily so the search is paid for once per process and only by a caller that transcodes.
|
|
92
|
+
*
|
|
93
|
+
* @param {Uint8Array} table the flat pattern list
|
|
94
|
+
* @param {number} count how many patterns it holds
|
|
95
|
+
* @param {number} partition_count
|
|
96
|
+
* @returns {{seed: number, permutation: number[]}[]}
|
|
97
|
+
*/
|
|
98
|
+
function seeds_for(table, count, partition_count) {
|
|
99
|
+
const out = [];
|
|
100
|
+
|
|
101
|
+
for (let pattern = 0; pattern < count; pattern++) {
|
|
102
|
+
const wanted = table.subarray(pattern * 16, pattern * 16 + 16);
|
|
103
|
+
|
|
104
|
+
const found = astc_find_partition_seed(wanted, partition_count);
|
|
105
|
+
|
|
106
|
+
if (found === undefined) {
|
|
107
|
+
throw new Error(
|
|
108
|
+
`UASTC: pattern ${pattern} of the ${partition_count}-subset table has no ASTC`
|
|
109
|
+
+ ` partition seed, which cannot happen for a pattern UASTC took from ASTC — the`
|
|
110
|
+
+ ` partition hash or the pattern table is wrong.`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
out.push(found);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @type {{seed: number, permutation: number[]}[][]}
|
|
122
|
+
*/
|
|
123
|
+
let seed_tables;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @returns {{two: object[], three: object[], two_bc7_3: object[]}}
|
|
127
|
+
*/
|
|
128
|
+
function partition_seeds() {
|
|
129
|
+
if (seed_tables === undefined) {
|
|
130
|
+
seed_tables = {
|
|
131
|
+
two: seeds_for(UASTC_PATTERNS_2, 30, 2),
|
|
132
|
+
three: seeds_for(UASTC_PATTERNS_3, 11, 3),
|
|
133
|
+
two_bc7_3: seeds_for(UASTC_PATTERNS_2_BC7_3, 19, 2),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return seed_tables;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Transcode UASTC to ASTC 4x4 by repacking, which is what the format was built for.
|
|
142
|
+
*
|
|
143
|
+
* **Nothing is fitted and nothing is lost.** UASTC's nineteen modes were laid out so that each one's
|
|
144
|
+
* fields *are* an ASTC block's fields: the endpoints are already in ASTC's quantized space at a range
|
|
145
|
+
* ASTC names, the weights are already ASTC weights, and the partition patterns were taken from
|
|
146
|
+
* ASTC's own hash. What is left is arithmetic on bit positions — ASTC interleaves its integer
|
|
147
|
+
* sequences where UASTC keeps them in two plain runs, and puts its weights at the far end of the
|
|
148
|
+
* block in reverse.
|
|
149
|
+
*
|
|
150
|
+
* That is the whole difference between this and the re-encode measured at 34.9 dB in §9.18. A
|
|
151
|
+
* re-encode has to choose one colour line for a block that may have three, which is exactly what a
|
|
152
|
+
* normal map is worst at; a repack keeps the three the file already had.
|
|
153
|
+
*
|
|
154
|
+
* **Endpoints may be swapped, which is lossless.** Colour endpoint modes 8 and 12 swap their pair and
|
|
155
|
+
* blue-contract when the second endpoint's channel sum falls below the first's. UASTC guarantees the
|
|
156
|
+
* order it needs for BC7's rules rather than ASTC's, so a subset that would trip the rule has its
|
|
157
|
+
* pair exchanged and its weights inverted — the same block, described the other way up.
|
|
158
|
+
*
|
|
159
|
+
* @param {Uint8Array} blocks UASTC blocks, tightly packed
|
|
160
|
+
* @param {number} block_count
|
|
161
|
+
* @returns {Uint8Array} tightly packed ASTC blocks, in raster order
|
|
162
|
+
* @throws {Error} for a mode this cannot express
|
|
163
|
+
*
|
|
164
|
+
* @see the UASTC LDR 4x4 specification, "Converting to ASTC"
|
|
165
|
+
* @author Alex Goldring
|
|
166
|
+
* @copyright Company Named Limited (c) 2026
|
|
167
|
+
*/
|
|
168
|
+
export function uastc_to_astc(blocks, block_count) {
|
|
169
|
+
const out = new Uint8Array(block_count * ASTC_BLOCK_BYTES);
|
|
170
|
+
|
|
171
|
+
const seeds = partition_seeds();
|
|
172
|
+
|
|
173
|
+
for (let block = 0; block < block_count; block++) {
|
|
174
|
+
const decoded = uastc_decode_block(blocks, block * UASTC_BLOCK_BYTES);
|
|
175
|
+
|
|
176
|
+
write_astc(out, block * ASTC_BLOCK_BYTES, decoded, seeds);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return out;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Compose one ASTC block from a decoded UASTC one.
|
|
184
|
+
*
|
|
185
|
+
* @param {Uint8Array} out
|
|
186
|
+
* @param {number} offset
|
|
187
|
+
* @param {object} decoded from {@link uastc_decode_block}
|
|
188
|
+
* @param {object} seeds
|
|
189
|
+
*/
|
|
190
|
+
function write_astc(out, offset, decoded, seeds) {
|
|
191
|
+
if (decoded.mode === UASTC_MODE_SOLID) {
|
|
192
|
+
write_void_extent(out, offset, decoded.endpoints);
|
|
193
|
+
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const mode = UASTC_MODE_BY_INDEX[decoded.mode];
|
|
198
|
+
|
|
199
|
+
const levels = UASTC_WEIGHT_LEVELS[mode.weight_range];
|
|
200
|
+
|
|
201
|
+
const weight_bits = Math.log2(levels);
|
|
202
|
+
|
|
203
|
+
const subsets = mode.subsets;
|
|
204
|
+
|
|
205
|
+
const endpoints = [...decoded.endpoints_quantised];
|
|
206
|
+
const weights = Uint8Array.from(decoded.weight_indices);
|
|
207
|
+
|
|
208
|
+
disable_blue_contraction(mode, decoded, endpoints, weights, levels);
|
|
209
|
+
|
|
210
|
+
let seed = 0;
|
|
211
|
+
let permutation = [0];
|
|
212
|
+
|
|
213
|
+
if (subsets > 1) {
|
|
214
|
+
/*
|
|
215
|
+
Three tables, and which one a mode reads is a property of the mode rather than of its subset
|
|
216
|
+
count alone: mode 7 has two subsets but indexes the nineteen patterns UASTC borrowed from
|
|
217
|
+
BC7's three-subset set, which it then folds down to two.
|
|
218
|
+
*/
|
|
219
|
+
const table = mode.mode === MODE_BC7_3_SUBSET_PATTERNS
|
|
220
|
+
? seeds.two_bc7_3
|
|
221
|
+
: (subsets === 3 ? seeds.three : seeds.two);
|
|
222
|
+
|
|
223
|
+
const chosen = table[decoded.pattern];
|
|
224
|
+
|
|
225
|
+
seed = chosen.seed;
|
|
226
|
+
permutation = chosen.permutation;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/*
|
|
230
|
+
**The two number their subsets the same way, and this is where that is checked.** A seed found
|
|
231
|
+
by search is only required to *group* the texels as UASTC does; which group it calls subset 0 is
|
|
232
|
+
the hash's business, and in general an encoder would have to reorder its endpoint pairs to
|
|
233
|
+
match. In fact no pattern ever needs it — all 60 across the three tables come back as the
|
|
234
|
+
identity, which follows from UASTC having taken its patterns from ASTC in the first place.
|
|
235
|
+
|
|
236
|
+
So there is no reordering code here, because code that never runs is code that is never right.
|
|
237
|
+
If a pattern ever did need it the block would be silently wrong, and this refuses instead.
|
|
238
|
+
|
|
239
|
+
**Deleting this will not fail a test, and it should still not be deleted.** It cannot fire while
|
|
240
|
+
the pattern tables and the partition hash both stay as they are, which is exactly the pair of
|
|
241
|
+
assumptions it exists to catch someone breaking.
|
|
242
|
+
*/
|
|
243
|
+
if (permutation.some((to, from) => to !== from)) {
|
|
244
|
+
throw new Error(
|
|
245
|
+
`UASTC: pattern ${decoded.pattern} maps to ASTC seed ${seed} with its subsets renumbered`
|
|
246
|
+
+ ` (${permutation.join(", ")}), which no UASTC pattern does. The endpoint pairs would`
|
|
247
|
+
+ ` have to be reordered to match, and nothing here does that.`
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const ordered = endpoints;
|
|
252
|
+
|
|
253
|
+
let bits = 0n;
|
|
254
|
+
|
|
255
|
+
const put = (value, width, at) => {
|
|
256
|
+
bits |= (BigInt(value) & ((1n << BigInt(width)) - 1n)) << BigInt(at);
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
put(block_mode(mode.weight_range, mode.dual_plane), 11, BLOCK_MODE_BIT);
|
|
260
|
+
put(subsets - 1, 2, PARTITION_COUNT_BIT);
|
|
261
|
+
|
|
262
|
+
let cursor;
|
|
263
|
+
|
|
264
|
+
if (subsets === 1) {
|
|
265
|
+
put(mode.cem, 4, CEM_SINGLE_BIT);
|
|
266
|
+
cursor = 17;
|
|
267
|
+
} else {
|
|
268
|
+
put(seed, 10, PARTITION_SEED_BIT);
|
|
269
|
+
|
|
270
|
+
// selector 00 means every partition shares one mode, which is always true of a UASTC block
|
|
271
|
+
put(0, 2, CEM_SELECTOR_BIT);
|
|
272
|
+
put(mode.cem, 4, CEM_SHARED_BIT);
|
|
273
|
+
|
|
274
|
+
cursor = 29;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
astc_write_integer_sequence(
|
|
278
|
+
(value, width) => {
|
|
279
|
+
put(value, width, cursor);
|
|
280
|
+
cursor += width;
|
|
281
|
+
},
|
|
282
|
+
ordered,
|
|
283
|
+
mode.endpoint_range
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
if (mode.dual_plane) {
|
|
287
|
+
// the component selector sits immediately below the weights, at the top of the block
|
|
288
|
+
put(decoded.component_selector, 2, 128 - 16 * 2 * weight_bits - 2);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/*
|
|
292
|
+
The weights fill the top of the block with the whole field's bit order reversed, and a dual-plane
|
|
293
|
+
block interleaves its two planes texel by texel. Every range UASTC uses is a power of two, so
|
|
294
|
+
these are plain bits with no integer sequence to interleave.
|
|
295
|
+
*/
|
|
296
|
+
const plane_count = mode.dual_plane ? 2 : 1;
|
|
297
|
+
|
|
298
|
+
let field = 0n;
|
|
299
|
+
|
|
300
|
+
for (let i = 0; i < 16 * plane_count; i++) {
|
|
301
|
+
field |= BigInt(weights[i]) << BigInt(i * weight_bits);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const width = 16 * plane_count * weight_bits;
|
|
305
|
+
|
|
306
|
+
for (let i = 0; i < width; i++) {
|
|
307
|
+
if ((field >> BigInt(i)) & 1n) {
|
|
308
|
+
bits |= 1n << BigInt(127 - i);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
for (let i = 0; i < ASTC_BLOCK_BYTES; i++) {
|
|
313
|
+
out[offset + i] = Number((bits >> BigInt(i * 8)) & 0xFFn);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Put each subset's endpoints the way round that stops a decoder blue-contracting them.
|
|
319
|
+
*
|
|
320
|
+
* **Colour endpoint modes 8 and 12 have a rule with no flag.** A decoder compares the two endpoints
|
|
321
|
+
* by the sum of their colour channels, and where the second falls below the first it swaps the pair
|
|
322
|
+
* *and* applies blue contraction — `r = (r + b) >> 1`, `g = (g + b) >> 1` — to both. That is a
|
|
323
|
+
* different picture rather than an inverted one, and nothing in the block records that it happened.
|
|
324
|
+
*
|
|
325
|
+
* UASTC orders its endpoints to suit BC7's rules, which are not these, so a subset can easily arrive
|
|
326
|
+
* the wrong way round. Exchanging the pair and inverting that subset's weights describes the same
|
|
327
|
+
* block the other way up, which is why the specification calls this lossless — and it has to be done
|
|
328
|
+
* per subset, since each has its own pair and its own texels.
|
|
329
|
+
*
|
|
330
|
+
* Modes 4 and 6 have no such rule and are left alone; comparing sums there would swap pairs for
|
|
331
|
+
* nothing and change what the block decodes to.
|
|
332
|
+
*
|
|
333
|
+
* @param {object} mode the UASTC mode descriptor
|
|
334
|
+
* @param {object} decoded
|
|
335
|
+
* @param {number[]} endpoints quantised values, modified in place
|
|
336
|
+
* @param {Uint8Array} weights modified in place
|
|
337
|
+
* @param {number} levels how many weight levels the mode has
|
|
338
|
+
*/
|
|
339
|
+
function disable_blue_contraction(mode, decoded, endpoints, weights, levels) {
|
|
340
|
+
if (mode.cem !== 8 && mode.cem !== 12) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const values_per_subset = endpoints.length / mode.subsets;
|
|
345
|
+
|
|
346
|
+
const plane_count = mode.dual_plane ? 2 : 1;
|
|
347
|
+
|
|
348
|
+
for (let subset = 0; subset < mode.subsets; subset++) {
|
|
349
|
+
/*
|
|
350
|
+
The comparison is on the *decoded* colours, which is what the rule is written over. The
|
|
351
|
+
quantised values are monotonic in them per channel but not comparable across channels at
|
|
352
|
+
different ranges, so summing those instead would disagree on the blocks nearest the boundary
|
|
353
|
+
— the ones where getting it wrong is least visible and most likely.
|
|
354
|
+
*/
|
|
355
|
+
const base = subset * 8;
|
|
356
|
+
|
|
357
|
+
const first = decoded.endpoints[base] + decoded.endpoints[base + 1] + decoded.endpoints[base + 2];
|
|
358
|
+
const second = decoded.endpoints[base + 4] + decoded.endpoints[base + 5] + decoded.endpoints[base + 6];
|
|
359
|
+
|
|
360
|
+
if (second >= first) {
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
for (let pair = 0; pair < values_per_subset; pair += 2) {
|
|
365
|
+
const at = subset * values_per_subset + pair;
|
|
366
|
+
|
|
367
|
+
const swap = endpoints[at];
|
|
368
|
+
|
|
369
|
+
endpoints[at] = endpoints[at + 1];
|
|
370
|
+
endpoints[at + 1] = swap;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
for (let texel = 0; texel < 16; texel++) {
|
|
374
|
+
if (decoded.partition[texel] !== subset) {
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
for (let plane = 0; plane < plane_count; plane++) {
|
|
379
|
+
const at = texel * plane_count + plane;
|
|
380
|
+
|
|
381
|
+
weights[at] = levels - 1 - weights[at];
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Write a void-extent block: one colour over the whole block, which is UASTC's solid mode.
|
|
389
|
+
*
|
|
390
|
+
* The magic `0x1FC` in the low bits is what marks a block void-extent rather than a weight grid, and
|
|
391
|
+
* the four `0x1FFF` coordinates are the "unused" extent that tells a decoder not to try to
|
|
392
|
+
* interpolate across neighbouring blocks. The colour is stored as four 16-bit channels, so an 8-bit
|
|
393
|
+
* value is replicated into both halves.
|
|
394
|
+
*
|
|
395
|
+
* @param {Uint8Array} out
|
|
396
|
+
* @param {number} offset
|
|
397
|
+
* @param {Uint8Array} endpoints the solid colour occupies the first four bytes
|
|
398
|
+
*/
|
|
399
|
+
function write_void_extent(out, offset, endpoints) {
|
|
400
|
+
/*
|
|
401
|
+
Bits 0 to 8 mark the block void-extent, bit 9 says the colour is LDR rather than HDR, and bits
|
|
402
|
+
10 and 11 are reserved and set. Leaving those two clear is a block a decoder is entitled to
|
|
403
|
+
reject, and it is the only thing that separated this from the reference's own solid blocks.
|
|
404
|
+
*/
|
|
405
|
+
let bits = 0x1FCn | (0b11n << 10n);
|
|
406
|
+
|
|
407
|
+
// the two dimensions' extents, all ones, meaning "no extent to speak of"
|
|
408
|
+
for (let i = 0; i < 4; i++) {
|
|
409
|
+
bits |= 0x1FFFn << BigInt(12 + i * 13);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
for (let channel = 0; channel < 4; channel++) {
|
|
413
|
+
const value = endpoints[channel];
|
|
414
|
+
|
|
415
|
+
bits |= BigInt((value << 8) | value) << BigInt(64 + channel * 16);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
for (let i = 0; i < ASTC_BLOCK_BYTES; i++) {
|
|
419
|
+
out[offset + i] = Number((bits >> BigInt(i * 8)) & 0xFFn);
|
|
420
|
+
}
|
|
421
|
+
}
|