@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.
- 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
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BC7_ANCHOR_2,
|
|
3
|
+
BC7_ANCHOR_3_SECOND,
|
|
4
|
+
BC7_ANCHOR_3_THIRD,
|
|
5
|
+
BC7_MODES,
|
|
6
|
+
BC7_PARTITIONS_2,
|
|
7
|
+
BC7_PARTITIONS_3,
|
|
8
|
+
bc7_interpolate,
|
|
9
|
+
bc7_weights
|
|
10
|
+
} from "./bc7_tables.js";
|
|
11
|
+
import { bc7_expand_endpoint } from "./bc7_write_block.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The block being decoded, with a zero byte past its end so a field read never leaves the array.
|
|
15
|
+
*
|
|
16
|
+
* @type {Uint8Array}
|
|
17
|
+
*/
|
|
18
|
+
const BLOCK = new Uint8Array(17);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Up to six endpoints, RGBA, first as stored and then widened to eight bits.
|
|
22
|
+
*
|
|
23
|
+
* @type {Uint8Array}
|
|
24
|
+
*/
|
|
25
|
+
const ENDPOINTS = new Uint8Array(24);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* One parity bit per endpoint.
|
|
29
|
+
*
|
|
30
|
+
* @type {Uint8Array}
|
|
31
|
+
*/
|
|
32
|
+
const PARITY = new Uint8Array(6);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @type {Uint8Array}
|
|
36
|
+
*/
|
|
37
|
+
const PRIMARY = new Uint8Array(16);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @type {Uint8Array}
|
|
41
|
+
*/
|
|
42
|
+
const SECONDARY = new Uint8Array(16);
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A field of at most eight bits of {@link BLOCK}, the block's bits counted little-endian.
|
|
46
|
+
*
|
|
47
|
+
* @param {number} position of the field's lowest bit
|
|
48
|
+
* @param {number} count
|
|
49
|
+
* @returns {number}
|
|
50
|
+
*/
|
|
51
|
+
function bits_at(position, count) {
|
|
52
|
+
const byte = position >> 3;
|
|
53
|
+
|
|
54
|
+
return ((BLOCK[byte] | (BLOCK[byte + 1] << 8)) >> (position & 7)) & ((1 << count) - 1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Decode one BC7 block (`bc7-rgba-unorm`, and its `-srgb` twin, whose bytes are the same) into
|
|
59
|
+
* sixteen RGBA texels.
|
|
60
|
+
*
|
|
61
|
+
* All eight modes of the BPTC specification, read from its Table.M: the mode is the position of the
|
|
62
|
+
* lowest set bit of the first byte, and the fields follow in the order every mode shares —
|
|
63
|
+
* partition, rotation, index selection, colour, alpha, per-endpoint parity, shared parity, primary
|
|
64
|
+
* indices, secondary indices. A parity bit sits below its endpoint's stored bits; the result widens
|
|
65
|
+
* to eight bits by replicating its top bits, and a mode without alpha has alpha 255. Each subset's
|
|
66
|
+
* anchor index — texel 0 for the first, the partition's entry in Table.A2, A3a or A3b for the others
|
|
67
|
+
* — is stored one bit short, its top bit zero. Texels interpolate as
|
|
68
|
+
* `((64 - w) * e0 + w * e1 + 32) >> 6` with the factor `w` for their index's width. With an index
|
|
69
|
+
* selection bit of 1 (mode 4) colour takes the secondary indices and alpha the primary ones;
|
|
70
|
+
* otherwise colour takes the primary indices and alpha the secondary ones where there are any. The
|
|
71
|
+
* rotation then swaps alpha with red (1), green (2) or blue (3).
|
|
72
|
+
*
|
|
73
|
+
* A block whose first byte is zero names no mode, which the specification reserves: it decodes to
|
|
74
|
+
* zero in every channel of every texel. Any other sixteen bytes are a valid block.
|
|
75
|
+
*
|
|
76
|
+
* @param {Uint8Array} source
|
|
77
|
+
* @param {number} offset of the sixteen-byte block in `source`
|
|
78
|
+
* @param {Uint8Array} out sixteen RGBA texels, raster order, written from index 0
|
|
79
|
+
*
|
|
80
|
+
* @see the BPTC specification (ARB_texture_compression_bptc), and the BPTC section of the Khronos
|
|
81
|
+
* Data Format Specification
|
|
82
|
+
* @author Alex Goldring
|
|
83
|
+
* @copyright Company Named Limited (c) 2026
|
|
84
|
+
*/
|
|
85
|
+
export function bc7_decode_block(source, offset, out) {
|
|
86
|
+
const first = source[offset];
|
|
87
|
+
|
|
88
|
+
if (first === 0) {
|
|
89
|
+
out.fill(0, 0, 64);
|
|
90
|
+
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
for (let i = 0; i < 16; i++) {
|
|
95
|
+
BLOCK[i] = source[offset + i];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const mode = 31 - Math.clz32(first & -first);
|
|
99
|
+
|
|
100
|
+
const spec = BC7_MODES[mode];
|
|
101
|
+
|
|
102
|
+
const subsets = spec.subsets;
|
|
103
|
+
const partition_bits = spec.partition_bits;
|
|
104
|
+
const rotation_bits = spec.rotation_bits;
|
|
105
|
+
const selection_bits = spec.index_selection_bits;
|
|
106
|
+
const color_bits = spec.color_bits;
|
|
107
|
+
const alpha_bits = spec.alpha_bits;
|
|
108
|
+
const endpoint_parity = spec.endpoint_parity_bits;
|
|
109
|
+
const shared_parity = spec.shared_parity_bits;
|
|
110
|
+
const index_bits = spec.index_bits;
|
|
111
|
+
const secondary_bits = spec.secondary_index_bits;
|
|
112
|
+
|
|
113
|
+
let bit = mode + 1;
|
|
114
|
+
|
|
115
|
+
const partition = bits_at(bit, partition_bits);
|
|
116
|
+
bit += partition_bits;
|
|
117
|
+
|
|
118
|
+
const rotation = bits_at(bit, rotation_bits);
|
|
119
|
+
bit += rotation_bits;
|
|
120
|
+
|
|
121
|
+
const selection = bits_at(bit, selection_bits);
|
|
122
|
+
bit += selection_bits;
|
|
123
|
+
|
|
124
|
+
const endpoint_count = subsets * 2;
|
|
125
|
+
|
|
126
|
+
// by channel, then by subset, then by endpoint
|
|
127
|
+
for (let channel = 0; channel < 3; channel++) {
|
|
128
|
+
for (let e = 0; e < endpoint_count; e++) {
|
|
129
|
+
ENDPOINTS[e * 4 + channel] = bits_at(bit, color_bits);
|
|
130
|
+
bit += color_bits;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
for (let e = 0; e < endpoint_count && alpha_bits > 0; e++) {
|
|
135
|
+
ENDPOINTS[e * 4 + 3] = bits_at(bit, alpha_bits);
|
|
136
|
+
bit += alpha_bits;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (endpoint_parity !== 0) {
|
|
140
|
+
for (let e = 0; e < endpoint_count; e++) {
|
|
141
|
+
PARITY[e] = bits_at(bit, 1);
|
|
142
|
+
bit += 1;
|
|
143
|
+
}
|
|
144
|
+
} else if (shared_parity !== 0) {
|
|
145
|
+
for (let s = 0; s < subsets; s++) {
|
|
146
|
+
const parity = bits_at(bit, 1);
|
|
147
|
+
bit += 1;
|
|
148
|
+
|
|
149
|
+
PARITY[s * 2] = parity;
|
|
150
|
+
PARITY[s * 2 + 1] = parity;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const parity_bits = endpoint_parity | shared_parity;
|
|
155
|
+
|
|
156
|
+
for (let e = 0; e < endpoint_count; e++) {
|
|
157
|
+
const parity = parity_bits !== 0 ? PARITY[e] : 0;
|
|
158
|
+
|
|
159
|
+
for (let channel = 0; channel < 3; channel++) {
|
|
160
|
+
const at = e * 4 + channel;
|
|
161
|
+
|
|
162
|
+
ENDPOINTS[at] = bc7_expand_endpoint((ENDPOINTS[at] << parity_bits) | parity, color_bits + parity_bits);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
ENDPOINTS[e * 4 + 3] = alpha_bits > 0
|
|
166
|
+
? bc7_expand_endpoint((ENDPOINTS[e * 4 + 3] << parity_bits) | parity, alpha_bits + parity_bits)
|
|
167
|
+
: 255;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// texel 0 anchors the first subset; a mode with fewer subsets repeats it in the unused slots
|
|
171
|
+
const anchor_1 = subsets === 2 ? BC7_ANCHOR_2[partition] : subsets === 3 ? BC7_ANCHOR_3_SECOND[partition] : 0;
|
|
172
|
+
const anchor_2 = subsets === 3 ? BC7_ANCHOR_3_THIRD[partition] : 0;
|
|
173
|
+
|
|
174
|
+
for (let t = 0; t < 16; t++) {
|
|
175
|
+
const count = t === 0 || t === anchor_1 || t === anchor_2 ? index_bits - 1 : index_bits;
|
|
176
|
+
|
|
177
|
+
PRIMARY[t] = bits_at(bit, count);
|
|
178
|
+
bit += count;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
for (let t = 0; t < 16 && secondary_bits > 0; t++) {
|
|
182
|
+
const count = t === 0 || t === anchor_1 || t === anchor_2 ? secondary_bits - 1 : secondary_bits;
|
|
183
|
+
|
|
184
|
+
SECONDARY[t] = bits_at(bit, count);
|
|
185
|
+
bit += count;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const color_indices = selection !== 0 ? SECONDARY : PRIMARY;
|
|
189
|
+
const color_weights = bc7_weights(selection !== 0 ? secondary_bits : index_bits);
|
|
190
|
+
|
|
191
|
+
const alpha_secondary = secondary_bits > 0 && selection === 0;
|
|
192
|
+
|
|
193
|
+
const alpha_indices = alpha_secondary ? SECONDARY : PRIMARY;
|
|
194
|
+
const alpha_weights = bc7_weights(alpha_secondary ? secondary_bits : index_bits);
|
|
195
|
+
|
|
196
|
+
const partitions = subsets === 3 ? BC7_PARTITIONS_3 : BC7_PARTITIONS_2;
|
|
197
|
+
const pattern = partition * 16;
|
|
198
|
+
|
|
199
|
+
for (let t = 0; t < 16; t++) {
|
|
200
|
+
const low = (subsets === 1 ? 0 : partitions[pattern + t]) * 8;
|
|
201
|
+
const high = low + 4;
|
|
202
|
+
|
|
203
|
+
const wc = color_weights[color_indices[t]];
|
|
204
|
+
const wa = alpha_weights[alpha_indices[t]];
|
|
205
|
+
|
|
206
|
+
let r = bc7_interpolate(ENDPOINTS[low], ENDPOINTS[high], wc);
|
|
207
|
+
let g = bc7_interpolate(ENDPOINTS[low + 1], ENDPOINTS[high + 1], wc);
|
|
208
|
+
let b = bc7_interpolate(ENDPOINTS[low + 2], ENDPOINTS[high + 2], wc);
|
|
209
|
+
let a = bc7_interpolate(ENDPOINTS[low + 3], ENDPOINTS[high + 3], wa);
|
|
210
|
+
|
|
211
|
+
if (rotation === 1) {
|
|
212
|
+
const swap = r;
|
|
213
|
+
r = a;
|
|
214
|
+
a = swap;
|
|
215
|
+
} else if (rotation === 2) {
|
|
216
|
+
const swap = g;
|
|
217
|
+
g = a;
|
|
218
|
+
a = swap;
|
|
219
|
+
} else if (rotation === 3) {
|
|
220
|
+
const swap = b;
|
|
221
|
+
b = a;
|
|
222
|
+
a = swap;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const at = t * 4;
|
|
226
|
+
|
|
227
|
+
out[at] = r;
|
|
228
|
+
out[at + 1] = g;
|
|
229
|
+
out[at + 2] = b;
|
|
230
|
+
out[at + 3] = a;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encode sixteen RGBA texels as one `bc7-rgba-unorm` block, in mode 6 or mode 1.
|
|
3
|
+
*
|
|
4
|
+
* - **Mode 6** is one line through all four channels: the texels' principal direction, its ends refined by least
|
|
5
|
+
* squares at the mode's sixteen levels, then each end's parity bit — shared by its four channels — chosen by the
|
|
6
|
+
* error it leaves.
|
|
7
|
+
* - **Mode 1** is two lines through the colour, at the partition whose subsets lie closest to a line each, fitted
|
|
8
|
+
* the same way at eight levels. It holds no alpha and decodes opaque; its error counts each texel's distance
|
|
9
|
+
* from opaque.
|
|
10
|
+
*
|
|
11
|
+
* The one with the smaller squared error, over all four channels, is written. A block whose alpha is the same
|
|
12
|
+
* throughout keeps it exactly: mode 6's ends both take that alpha's parity, and mode 1 is not tried unless that
|
|
13
|
+
* alpha is opaque. An `-srgb` texture holds the same bytes; nothing here converts. For a block whose alpha nobody
|
|
14
|
+
* reads, {@link bc7_encode_block_rgb}.
|
|
15
|
+
*
|
|
16
|
+
* @param {Uint8Array} texels sixty-four bytes: sixteen RGBA texels in raster order
|
|
17
|
+
* @param {Uint8Array} out
|
|
18
|
+
* @param {number} offset of the block's sixteen bytes in `out`
|
|
19
|
+
*
|
|
20
|
+
* @author Alex Goldring
|
|
21
|
+
* @copyright Company Named Limited (c) 2026
|
|
22
|
+
*/
|
|
23
|
+
export function bc7_encode_block(texels: Uint8Array, out: Uint8Array, offset: number): void;
|
|
24
|
+
/**
|
|
25
|
+
* Encode sixteen texels' colour as one `bc7-rgba-unorm` block whose alpha nobody reads, in mode 6 or mode 1.
|
|
26
|
+
*
|
|
27
|
+
* As {@link bc7_encode_block}, with alpha left out: the texels' alpha is not read, mode 6's parity bits serve the
|
|
28
|
+
* colour alone and its alpha decodes 254 or 255, and mode 1, which decodes opaque, is always tried. The one with the
|
|
29
|
+
* smaller squared error over the colour is written.
|
|
30
|
+
*
|
|
31
|
+
* @param {Uint8Array} texels sixty-four bytes: sixteen RGBA texels in raster order; alpha is not read
|
|
32
|
+
* @param {Uint8Array} out
|
|
33
|
+
* @param {number} offset of the block's sixteen bytes in `out`
|
|
34
|
+
*
|
|
35
|
+
* @author Alex Goldring
|
|
36
|
+
* @copyright Company Named Limited (c) 2026
|
|
37
|
+
*/
|
|
38
|
+
export function bc7_encode_block_rgb(texels: Uint8Array, out: Uint8Array, offset: number): void;
|
|
39
|
+
//# sourceMappingURL=bc7_encode_block.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bc7_encode_block.d.ts","sourceRoot":"","sources":["../../../../../src/format/texture/bc/bc7_encode_block.js"],"names":[],"mappings":"AAyVA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,yCAPW,UAAU,OACV,UAAU,UACV,MAAM,QA8BhB;AAED;;;;;;;;;;;;;GAaG;AACH,6CAPW,UAAU,OACV,UAAU,UACV,MAAM,QAmBhB"}
|
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
import { fit_line } from "../fit/fit_line.js";
|
|
2
|
+
import { fit_line_refine } from "../fit/fit_line_refine.js";
|
|
3
|
+
import { BC7_ANCHOR_2, BC7_PARTITIONS_2, bc7_interpolate, bc7_weights } from "./bc7_tables.js";
|
|
4
|
+
import { bc7_expand_endpoint, bc7_quantise_endpoint, bc7_write_block } from "./bc7_write_block.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Where along a line each index width can put a texel, `0` to `1`.
|
|
8
|
+
*
|
|
9
|
+
* @readonly
|
|
10
|
+
* @type {Float64Array}
|
|
11
|
+
*/
|
|
12
|
+
const LEVELS_3 = Float64Array.from(bc7_weights(3), w => w / 64);
|
|
13
|
+
const LEVELS_4 = Float64Array.from(bc7_weights(4), w => w / 64);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The block's texels as reals: RGBA for mode 6's one line, or each mode 1 subset's colours gathered in turn.
|
|
17
|
+
*
|
|
18
|
+
* @type {Float64Array}
|
|
19
|
+
*/
|
|
20
|
+
const points = new Float64Array(64);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* For mode 1, which texel each gathered point is.
|
|
24
|
+
*
|
|
25
|
+
* @type {Uint8Array}
|
|
26
|
+
*/
|
|
27
|
+
const gathered_texel = new Uint8Array(16);
|
|
28
|
+
|
|
29
|
+
const line_low = new Float64Array(4);
|
|
30
|
+
const line_high = new Float64Array(4);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A fitted mode's result, as the writer takes it, and its squared error.
|
|
34
|
+
*/
|
|
35
|
+
class Bc7Candidate {
|
|
36
|
+
mode = 6;
|
|
37
|
+
partition = 0;
|
|
38
|
+
error = Infinity;
|
|
39
|
+
|
|
40
|
+
/** eight-bit endpoint values, RGBA, low then high per subset */
|
|
41
|
+
ends = new Uint8Array(16);
|
|
42
|
+
|
|
43
|
+
/** the fields the writer stores: the values less their parity bit */
|
|
44
|
+
endpoints = new Uint8Array(16);
|
|
45
|
+
|
|
46
|
+
/** per endpoint for mode 6, per subset for mode 1 */
|
|
47
|
+
parity = new Int8Array(4);
|
|
48
|
+
|
|
49
|
+
indices = new Uint8Array(16);
|
|
50
|
+
anchors = new Uint8Array(2);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const mode6 = new Bc7Candidate();
|
|
54
|
+
const mode1 = new Bc7Candidate();
|
|
55
|
+
|
|
56
|
+
const trial_ends = new Uint8Array(8);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A block whose alpha nobody reads, as the fit sees it: its colour, opaque.
|
|
60
|
+
*
|
|
61
|
+
* @type {Uint8Array}
|
|
62
|
+
*/
|
|
63
|
+
const opaque_texels = new Uint8Array(64);
|
|
64
|
+
const trial_indices = new Uint8Array(16);
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The squared error, over RGBA, of texels against the palette between two ends, each texel at its nearest entry,
|
|
68
|
+
* written to {@link trial_indices} by texel.
|
|
69
|
+
*
|
|
70
|
+
* @param {Uint8Array} texels the block, RGBA bytes
|
|
71
|
+
* @param {Uint8Array} weights the index width's interpolation factors
|
|
72
|
+
* @param {number} from the first gathered point scored
|
|
73
|
+
* @param {number} count how many
|
|
74
|
+
* @returns {number}
|
|
75
|
+
*/
|
|
76
|
+
function score(texels, weights, from, count) {
|
|
77
|
+
let error = 0;
|
|
78
|
+
|
|
79
|
+
for (let n = from; n < from + count; n++) {
|
|
80
|
+
const t = gathered_texel[n];
|
|
81
|
+
|
|
82
|
+
let nearest = 0;
|
|
83
|
+
let nearest_error = Infinity;
|
|
84
|
+
|
|
85
|
+
for (let k = 0; k < weights.length; k++) {
|
|
86
|
+
const w = weights[k];
|
|
87
|
+
|
|
88
|
+
let e = 0;
|
|
89
|
+
|
|
90
|
+
for (let c = 0; c < 4; c++) {
|
|
91
|
+
const d = bc7_interpolate(trial_ends[c], trial_ends[4 + c], w) - texels[t * 4 + c];
|
|
92
|
+
|
|
93
|
+
e += d * d;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (e < nearest_error) {
|
|
97
|
+
nearest_error = e;
|
|
98
|
+
nearest = k;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
trial_indices[t] = nearest;
|
|
103
|
+
error += nearest_error;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return error;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @param {number} v
|
|
111
|
+
* @returns {number} in `[0, 255]`
|
|
112
|
+
*/
|
|
113
|
+
function clamp_byte(v) {
|
|
114
|
+
return v < 0 ? 0 : v > 255 ? 255 : v;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* An anchor texel's index is stored a bit short, its top bit zero: a subset whose anchor lands in the upper half is
|
|
119
|
+
* written the other way up, its ends swapped and its indices inverted, which decodes identically.
|
|
120
|
+
*
|
|
121
|
+
* @param {Bc7Candidate} candidate
|
|
122
|
+
* @param {number} subset
|
|
123
|
+
* @param {number} anchor the subset's anchor texel
|
|
124
|
+
* @param {number} top the highest index
|
|
125
|
+
*/
|
|
126
|
+
function honour_anchor(candidate, subset, anchor, top) {
|
|
127
|
+
if (candidate.indices[anchor] <= (top >> 1)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
for (let c = 0; c < 4; c++) {
|
|
132
|
+
const at = subset * 8 + c;
|
|
133
|
+
const swap = candidate.ends[at];
|
|
134
|
+
|
|
135
|
+
candidate.ends[at] = candidate.ends[at + 4];
|
|
136
|
+
candidate.ends[at + 4] = swap;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
for (let t = 0; t < 16; t++) {
|
|
140
|
+
if (candidate.mode === 6 || BC7_PARTITIONS_2[candidate.partition * 16 + t] === subset) {
|
|
141
|
+
candidate.indices[t] = top - candidate.indices[t];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Fit mode 6: one line through all four channels, sixteen levels on it, eight-bit ends whose lowest bit is a parity
|
|
148
|
+
* the end's four channels share.
|
|
149
|
+
*
|
|
150
|
+
* @param {Uint8Array} texels
|
|
151
|
+
* @param {number} alpha_parity the parity both ends must have to keep an alpha the same throughout the block, or `2`
|
|
152
|
+
* when it varies or is not read
|
|
153
|
+
* @param {boolean} alpha_read false for a block whose alpha nobody reads, whose texels are opaque here: the ends'
|
|
154
|
+
* alpha is scored as opaque whatever parity the colour takes, so the parities serve the colour alone
|
|
155
|
+
*/
|
|
156
|
+
function fit_mode6(texels, alpha_parity, alpha_read) {
|
|
157
|
+
for (let i = 0; i < 64; i++) {
|
|
158
|
+
points[i] = texels[i];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
for (let t = 0; t < 16; t++) {
|
|
162
|
+
gathered_texel[t] = t;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
fit_line(points, 4, 0, 16, line_low, line_high);
|
|
166
|
+
|
|
167
|
+
for (let round = 0; round < 2; round++) {
|
|
168
|
+
if (!fit_line_refine(points, 4, 0, 16, LEVELS_4, line_low, line_high)) {
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const weights = bc7_weights(4);
|
|
174
|
+
|
|
175
|
+
mode6.mode = 6;
|
|
176
|
+
mode6.partition = 0;
|
|
177
|
+
mode6.error = Infinity;
|
|
178
|
+
|
|
179
|
+
for (let p0 = 0; p0 < 2; p0++) {
|
|
180
|
+
for (let p1 = 0; p1 < 2; p1++) {
|
|
181
|
+
if (alpha_parity < 2 && (p0 !== alpha_parity || p1 !== alpha_parity)) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
for (let c = 0; c < 4; c++) {
|
|
186
|
+
trial_ends[c] = bc7_quantise_endpoint(clamp_byte(line_low[c]), 8, p0);
|
|
187
|
+
trial_ends[4 + c] = bc7_quantise_endpoint(clamp_byte(line_high[c]), 8, p1);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (!alpha_read) {
|
|
191
|
+
// stored as 127 and the parity: 254 or 255, which nobody reads
|
|
192
|
+
trial_ends[3] = 255;
|
|
193
|
+
trial_ends[7] = 255;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const error = score(texels, weights, 0, 16);
|
|
197
|
+
|
|
198
|
+
if (error < mode6.error) {
|
|
199
|
+
mode6.error = error;
|
|
200
|
+
mode6.ends.set(trial_ends);
|
|
201
|
+
mode6.indices.set(trial_indices);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
mode6.anchors[0] = 0;
|
|
207
|
+
|
|
208
|
+
honour_anchor(mode6, 0, 0, 15);
|
|
209
|
+
|
|
210
|
+
for (let e = 0; e < 2; e++) {
|
|
211
|
+
mode6.parity[e] = mode6.ends[e * 4] & 1;
|
|
212
|
+
|
|
213
|
+
for (let c = 0; c < 4; c++) {
|
|
214
|
+
mode6.endpoints[e * 4 + c] = mode6.ends[e * 4 + c] >> 1;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Gather each subset's colours of a two-subset partition into {@link points}, the first subset's first.
|
|
221
|
+
*
|
|
222
|
+
* @param {Uint8Array} texels
|
|
223
|
+
* @param {number} partition
|
|
224
|
+
* @returns {number} how many texels the first subset holds
|
|
225
|
+
*/
|
|
226
|
+
function gather(texels, partition) {
|
|
227
|
+
let n = 0;
|
|
228
|
+
let first = 0;
|
|
229
|
+
|
|
230
|
+
for (let subset = 0; subset < 2; subset++) {
|
|
231
|
+
for (let t = 0; t < 16; t++) {
|
|
232
|
+
if (BC7_PARTITIONS_2[partition * 16 + t] === subset) {
|
|
233
|
+
points[n * 3] = texels[t * 4];
|
|
234
|
+
points[n * 3 + 1] = texels[t * 4 + 1];
|
|
235
|
+
points[n * 3 + 2] = texels[t * 4 + 2];
|
|
236
|
+
|
|
237
|
+
gathered_texel[n] = t;
|
|
238
|
+
n++;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (subset === 0) {
|
|
243
|
+
first = n;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return first;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* The partition whose two subsets lie closest to a line each: the least sum of the subsets' squared distances from
|
|
252
|
+
* their own lines.
|
|
253
|
+
*
|
|
254
|
+
* @param {Uint8Array} texels
|
|
255
|
+
* @returns {number}
|
|
256
|
+
*/
|
|
257
|
+
function best_partition(texels) {
|
|
258
|
+
let best = 0;
|
|
259
|
+
let best_residual = Infinity;
|
|
260
|
+
|
|
261
|
+
for (let partition = 0; partition < 64; partition++) {
|
|
262
|
+
const first = gather(texels, partition);
|
|
263
|
+
|
|
264
|
+
const residual = fit_line(points, 3, 0, first, line_low, line_high)
|
|
265
|
+
+ fit_line(points, 3, first, 16 - first, line_low, line_high);
|
|
266
|
+
|
|
267
|
+
if (residual < best_residual) {
|
|
268
|
+
best_residual = residual;
|
|
269
|
+
best = partition;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return best;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Fit mode 1 at a partition: two lines through the colour, eight levels on each, six-bit ends with a parity bit a
|
|
278
|
+
* subset's two ends share. The block decodes opaque.
|
|
279
|
+
*
|
|
280
|
+
* @param {Uint8Array} texels
|
|
281
|
+
* @param {number} partition
|
|
282
|
+
*/
|
|
283
|
+
function fit_mode1(texels, partition) {
|
|
284
|
+
const first = gather(texels, partition);
|
|
285
|
+
const weights = bc7_weights(3);
|
|
286
|
+
|
|
287
|
+
mode1.mode = 1;
|
|
288
|
+
mode1.partition = partition;
|
|
289
|
+
mode1.error = 0;
|
|
290
|
+
|
|
291
|
+
for (let subset = 0; subset < 2; subset++) {
|
|
292
|
+
const from = subset === 0 ? 0 : first;
|
|
293
|
+
const count = subset === 0 ? first : 16 - first;
|
|
294
|
+
|
|
295
|
+
fit_line(points, 3, from, count, line_low, line_high);
|
|
296
|
+
|
|
297
|
+
for (let round = 0; round < 2; round++) {
|
|
298
|
+
if (!fit_line_refine(points, 3, from, count, LEVELS_3, line_low, line_high)) {
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
let best = Infinity;
|
|
304
|
+
|
|
305
|
+
for (let parity = 0; parity < 2; parity++) {
|
|
306
|
+
for (let c = 0; c < 3; c++) {
|
|
307
|
+
trial_ends[c] = bc7_expand_endpoint(bc7_quantise_endpoint(clamp_byte(line_low[c]), 7, parity), 7);
|
|
308
|
+
trial_ends[4 + c] = bc7_expand_endpoint(bc7_quantise_endpoint(clamp_byte(line_high[c]), 7, parity), 7);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
trial_ends[3] = 255;
|
|
312
|
+
trial_ends[7] = 255;
|
|
313
|
+
|
|
314
|
+
const error = score(texels, weights, from, count);
|
|
315
|
+
|
|
316
|
+
if (error < best) {
|
|
317
|
+
best = error;
|
|
318
|
+
|
|
319
|
+
mode1.ends.set(trial_ends, subset * 8);
|
|
320
|
+
mode1.parity[subset] = parity;
|
|
321
|
+
|
|
322
|
+
for (let n = from; n < from + count; n++) {
|
|
323
|
+
mode1.indices[gathered_texel[n]] = trial_indices[gathered_texel[n]];
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
mode1.error += best;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
mode1.anchors[0] = 0;
|
|
332
|
+
mode1.anchors[1] = BC7_ANCHOR_2[partition];
|
|
333
|
+
|
|
334
|
+
for (let subset = 0; subset < 2; subset++) {
|
|
335
|
+
honour_anchor(mode1, subset, mode1.anchors[subset], 7);
|
|
336
|
+
|
|
337
|
+
for (let e = 0; e < 2; e++) {
|
|
338
|
+
for (let c = 0; c < 3; c++) {
|
|
339
|
+
// six stored bits above the subset's parity bit
|
|
340
|
+
mode1.endpoints[(subset * 2 + e) * 4 + c] = mode1.ends[(subset * 2 + e) * 4 + c] >> 2;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Encode sixteen RGBA texels as one `bc7-rgba-unorm` block, in mode 6 or mode 1.
|
|
348
|
+
*
|
|
349
|
+
* - **Mode 6** is one line through all four channels: the texels' principal direction, its ends refined by least
|
|
350
|
+
* squares at the mode's sixteen levels, then each end's parity bit — shared by its four channels — chosen by the
|
|
351
|
+
* error it leaves.
|
|
352
|
+
* - **Mode 1** is two lines through the colour, at the partition whose subsets lie closest to a line each, fitted
|
|
353
|
+
* the same way at eight levels. It holds no alpha and decodes opaque; its error counts each texel's distance
|
|
354
|
+
* from opaque.
|
|
355
|
+
*
|
|
356
|
+
* The one with the smaller squared error, over all four channels, is written. A block whose alpha is the same
|
|
357
|
+
* throughout keeps it exactly: mode 6's ends both take that alpha's parity, and mode 1 is not tried unless that
|
|
358
|
+
* alpha is opaque. An `-srgb` texture holds the same bytes; nothing here converts. For a block whose alpha nobody
|
|
359
|
+
* reads, {@link bc7_encode_block_rgb}.
|
|
360
|
+
*
|
|
361
|
+
* @param {Uint8Array} texels sixty-four bytes: sixteen RGBA texels in raster order
|
|
362
|
+
* @param {Uint8Array} out
|
|
363
|
+
* @param {number} offset of the block's sixteen bytes in `out`
|
|
364
|
+
*
|
|
365
|
+
* @author Alex Goldring
|
|
366
|
+
* @copyright Company Named Limited (c) 2026
|
|
367
|
+
*/
|
|
368
|
+
export function bc7_encode_block(texels, out, offset) {
|
|
369
|
+
let alpha_low = 255;
|
|
370
|
+
let alpha_high = 0;
|
|
371
|
+
|
|
372
|
+
for (let t = 0; t < 16; t++) {
|
|
373
|
+
const a = texels[t * 4 + 3];
|
|
374
|
+
|
|
375
|
+
alpha_low = Math.min(alpha_low, a);
|
|
376
|
+
alpha_high = Math.max(alpha_high, a);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
fit_mode6(texels, alpha_low === alpha_high ? alpha_low & 1 : 2, true);
|
|
380
|
+
|
|
381
|
+
let chosen = mode6;
|
|
382
|
+
|
|
383
|
+
// mode 1 decodes opaque, which changes an alpha that is one value other than opaque throughout
|
|
384
|
+
if (alpha_low === 255 || alpha_low !== alpha_high) {
|
|
385
|
+
fit_mode1(texels, best_partition(texels));
|
|
386
|
+
|
|
387
|
+
if (mode1.error < mode6.error) {
|
|
388
|
+
chosen = mode1;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
bc7_write_block(out, offset, chosen.mode, chosen);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Encode sixteen texels' colour as one `bc7-rgba-unorm` block whose alpha nobody reads, in mode 6 or mode 1.
|
|
397
|
+
*
|
|
398
|
+
* As {@link bc7_encode_block}, with alpha left out: the texels' alpha is not read, mode 6's parity bits serve the
|
|
399
|
+
* colour alone and its alpha decodes 254 or 255, and mode 1, which decodes opaque, is always tried. The one with the
|
|
400
|
+
* smaller squared error over the colour is written.
|
|
401
|
+
*
|
|
402
|
+
* @param {Uint8Array} texels sixty-four bytes: sixteen RGBA texels in raster order; alpha is not read
|
|
403
|
+
* @param {Uint8Array} out
|
|
404
|
+
* @param {number} offset of the block's sixteen bytes in `out`
|
|
405
|
+
*
|
|
406
|
+
* @author Alex Goldring
|
|
407
|
+
* @copyright Company Named Limited (c) 2026
|
|
408
|
+
*/
|
|
409
|
+
export function bc7_encode_block_rgb(texels, out, offset) {
|
|
410
|
+
for (let t = 0; t < 16; t++) {
|
|
411
|
+
opaque_texels[t * 4] = texels[t * 4];
|
|
412
|
+
opaque_texels[t * 4 + 1] = texels[t * 4 + 1];
|
|
413
|
+
opaque_texels[t * 4 + 2] = texels[t * 4 + 2];
|
|
414
|
+
opaque_texels[t * 4 + 3] = 255;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
fit_mode6(opaque_texels, 2, false);
|
|
418
|
+
fit_mode1(opaque_texels, best_partition(opaque_texels));
|
|
419
|
+
|
|
420
|
+
const chosen = mode1.error < mode6.error ? mode1 : mode6;
|
|
421
|
+
|
|
422
|
+
bc7_write_block(out, offset, chosen.mode, chosen);
|
|
423
|
+
}
|