@woosh/meep-engine 3.78.4 → 3.80.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +93 -0
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/engine/asset/GameAssetType.d.ts +2 -0
- package/src/engine/asset/GameAssetType.js +10 -0
- package/src/engine/asset/guessAssetType.d.ts.map +1 -1
- package/src/engine/asset/guessAssetType.js +4 -0
- package/src/engine/asset/load_model_scene_bundle.d.ts +1 -1
- package/src/engine/asset/load_model_scene_bundle.js +2 -2
- package/src/engine/asset/loaders/MTFSceneBundleAssetLoader.d.ts +42 -0
- package/src/engine/asset/loaders/MTFSceneBundleAssetLoader.d.ts.map +1 -0
- package/src/engine/asset/loaders/MTFSceneBundleAssetLoader.js +83 -0
- package/src/engine/asset/loaders/MTFTextureAssetLoader.d.ts +36 -0
- package/src/engine/asset/loaders/MTFTextureAssetLoader.d.ts.map +1 -0
- package/src/engine/asset/loaders/MTFTextureAssetLoader.js +78 -0
- package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.d.ts +6 -1
- package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.d.ts.map +1 -1
- package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +8 -2
- package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
- 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/GPUAcousticProbes.d.ts +1 -1
- package/src/shade/renderer/acoustics/GPUAcoustics.d.ts +1 -1
- package/src/shade/renderer/animation/ShadeAnimationClipSerializationAdapter.d.ts +33 -0
- package/src/shade/renderer/animation/ShadeAnimationClipSerializationAdapter.d.ts.map +1 -0
- package/src/shade/renderer/animation/ShadeAnimationClipSerializationAdapter.js +196 -0
- package/src/shade/renderer/animation/SkinSerializationAdapter.d.ts +25 -0
- package/src/shade/renderer/animation/SkinSerializationAdapter.d.ts.map +1 -0
- package/src/shade/renderer/animation/SkinSerializationAdapter.js +85 -0
- package/src/shade/renderer/hair/GPUHairSystem.d.ts.map +1 -1
- package/src/shade/renderer/hair/GPUHairSystem.js +16 -7
- package/src/shade/renderer/hair/HAIR.d.ts +5 -3
- package/src/shade/renderer/hair/HAIR.d.ts.map +1 -1
- package/src/shade/renderer/hair/HAIR.js +6 -4
- package/src/shade/renderer/hair/hair_shadow_draw.d.ts +10 -10
- package/src/shade/renderer/hair/hair_shadow_draw.d.ts.map +1 -1
- package/src/shade/renderer/hair/hair_shadow_draw.js +21 -17
- package/src/shade/renderer/hair/shader_hair_cull.d.ts.map +1 -1
- package/src/shade/renderer/hair/shader_hair_cull.js +6 -2
- package/src/shade/renderer/hair/shader_hair_shadow_list.d.ts +5 -4
- package/src/shade/renderer/hair/shader_hair_shadow_list.d.ts.map +1 -1
- package/src/shade/renderer/hair/shader_hair_shadow_list.js +10 -12
- package/src/shade/renderer/loader/SceneNodeSerializationAdapter.d.ts +38 -0
- package/src/shade/renderer/loader/SceneNodeSerializationAdapter.d.ts.map +1 -0
- package/src/shade/renderer/loader/SceneNodeSerializationAdapter.js +198 -0
- package/src/shade/renderer/loader/mtf/MTFTexture.d.ts +88 -0
- package/src/shade/renderer/loader/mtf/MTFTexture.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/MTFTexture.js +159 -0
- package/src/shade/renderer/loader/mtf/MTFTextureSerializationAdapter.d.ts +30 -0
- package/src/shade/renderer/loader/mtf/MTFTextureSerializationAdapter.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/MTFTextureSerializationAdapter.js +136 -0
- package/src/shade/renderer/loader/mtf/MTF_PACKAGE_MAGIC.d.ts +7 -0
- package/src/shade/renderer/loader/mtf/MTF_PACKAGE_MAGIC.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/MTF_PACKAGE_MAGIC.js +6 -0
- package/src/shade/renderer/loader/mtf/MTF_PACKAGE_VERSION.d.ts +8 -0
- package/src/shade/renderer/loader/mtf/MTF_PACKAGE_VERSION.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/MTF_PACKAGE_VERSION.js +7 -0
- package/src/shade/renderer/loader/mtf/MTF_TEXTURE_MAGIC.d.ts +7 -0
- package/src/shade/renderer/loader/mtf/MTF_TEXTURE_MAGIC.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/MTF_TEXTURE_MAGIC.js +6 -0
- package/src/shade/renderer/loader/mtf/MTF_TEXTURE_VERSION.d.ts +7 -0
- package/src/shade/renderer/loader/mtf/MTF_TEXTURE_VERSION.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/MTF_TEXTURE_VERSION.js +6 -0
- package/src/shade/renderer/loader/mtf/load_mtf.d.ts +41 -0
- package/src/shade/renderer/loader/mtf/load_mtf.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/load_mtf.js +73 -0
- package/src/shade/renderer/loader/mtf/mtf_bundle_textures.d.ts +19 -0
- package/src/shade/renderer/loader/mtf/mtf_bundle_textures.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/mtf_bundle_textures.js +57 -0
- package/src/shade/renderer/loader/mtf/mtf_encode_texture.d.ts +10 -0
- package/src/shade/renderer/loader/mtf/mtf_encode_texture.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/mtf_encode_texture.js +152 -0
- package/src/shade/renderer/loader/mtf/mtf_export.d.ts +45 -0
- package/src/shade/renderer/loader/mtf/mtf_export.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/mtf_export.js +161 -0
- package/src/shade/renderer/loader/mtf/mtf_is_texture.d.ts +9 -0
- package/src/shade/renderer/loader/mtf/mtf_is_texture.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/mtf_is_texture.js +12 -0
- package/src/shade/renderer/loader/mtf/mtf_read_collection.d.ts +24 -0
- package/src/shade/renderer/loader/mtf/mtf_read_collection.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/mtf_read_collection.js +37 -0
- package/src/shade/renderer/loader/mtf/mtf_read_scene.d.ts +27 -0
- package/src/shade/renderer/loader/mtf/mtf_read_scene.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/mtf_read_scene.js +121 -0
- package/src/shade/renderer/loader/mtf/mtf_read_textures.d.ts +18 -0
- package/src/shade/renderer/loader/mtf/mtf_read_textures.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/mtf_read_textures.js +51 -0
- 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_resolve_uri.d.ts +21 -0
- package/src/shade/renderer/loader/mtf/mtf_resolve_uri.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/mtf_resolve_uri.js +98 -0
- package/src/shade/renderer/loader/mtf/mtf_serialization_registry.d.ts +25 -0
- package/src/shade/renderer/loader/mtf/mtf_serialization_registry.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/mtf_serialization_registry.js +51 -0
- package/src/shade/renderer/loader/mtf/mtf_texture_read.d.ts +20 -0
- package/src/shade/renderer/loader/mtf/mtf_texture_read.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/mtf_texture_read.js +80 -0
- package/src/shade/renderer/loader/mtf/mtf_texture_select.d.ts +24 -0
- package/src/shade/renderer/loader/mtf/mtf_texture_select.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/mtf_texture_select.js +42 -0
- package/src/shade/renderer/loader/mtf/mtf_texture_write.d.ts +31 -0
- package/src/shade/renderer/loader/mtf/mtf_texture_write.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/mtf_texture_write.js +87 -0
- package/src/shade/renderer/loader/mtf/mtf_write.d.ts +36 -0
- package/src/shade/renderer/loader/mtf/mtf_write.d.ts.map +1 -0
- package/src/shade/renderer/loader/mtf/mtf_write.js +137 -0
- 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/material/StandardShadeMaterialSerializationAdapter.d.ts +39 -0
- package/src/shade/renderer/material/StandardShadeMaterialSerializationAdapter.d.ts.map +1 -0
- package/src/shade/renderer/material/StandardShadeMaterialSerializationAdapter.js +207 -0
- package/src/shade/renderer/scene/optimization/source_to_sampler2d.d.ts.map +1 -1
- package/src/shade/renderer/scene/optimization/source_to_sampler2d.js +3 -1
- package/src/shade/renderer/scene/serialization/STANDARD_MATERIAL_SERIALIZED_BYTE_SIZE.d.ts +5 -5
- package/src/shade/renderer/scene/serialization/STANDARD_MATERIAL_SERIALIZED_BYTE_SIZE.js +5 -5
- package/src/shade/renderer/scene/serialization/deserialize_scene.d.ts.map +1 -1
- package/src/shade/renderer/scene/serialization/deserialize_scene.js +491 -528
- package/src/shade/renderer/scene/serialization/serialize_scene.d.ts +0 -10
- package/src/shade/renderer/scene/serialization/serialize_scene.d.ts.map +1 -1
- package/src/shade/renderer/scene/serialization/serialize_scene.js +15 -71
- 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/gpu_texture_format_without_srgb.d.ts +11 -0
- package/src/shade/renderer/texture/format/gpu_texture_format_without_srgb.d.ts.map +1 -0
- package/src/shade/renderer/texture/format/gpu_texture_format_without_srgb.js +14 -0
- 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/shade/renderer/texture/texture_role_image_quality.d.ts +10 -0
- package/src/shade/renderer/texture/texture_role_image_quality.d.ts.map +1 -0
- package/src/shade/renderer/texture/texture_role_image_quality.js +29 -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,463 +1,463 @@
|
|
|
1
|
-
import { astc_interpolate } from "
|
|
2
|
-
import {
|
|
3
|
-
UASTC_ANCHORS_2,
|
|
4
|
-
UASTC_ANCHORS_2_BC7_3,
|
|
5
|
-
UASTC_ANCHORS_3,
|
|
6
|
-
UASTC_DEQUANT,
|
|
7
|
-
UASTC_MODE_BY_INDEX,
|
|
8
|
-
UASTC_MODE_OF_PREFIX,
|
|
9
|
-
UASTC_MODE_RESERVED,
|
|
10
|
-
UASTC_MODE_SOLID,
|
|
11
|
-
UASTC_PATTERNS_2,
|
|
12
|
-
UASTC_PATTERNS_2_BC7_3,
|
|
13
|
-
UASTC_PATTERNS_3,
|
|
14
|
-
UASTC_WEIGHT_VALUE,
|
|
15
|
-
} from "./uastc_tables.js";
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Bytes one UASTC block occupies.
|
|
19
|
-
*
|
|
20
|
-
* @readonly
|
|
21
|
-
* @type {number}
|
|
22
|
-
*/
|
|
23
|
-
export const UASTC_BLOCK_BYTES = 16;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Texels one block covers.
|
|
27
|
-
*
|
|
28
|
-
* @readonly
|
|
29
|
-
* @type {number}
|
|
30
|
-
*/
|
|
31
|
-
const TEXELS = 16;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* The mode that uses the 2-subset patterns which are 3-subset in BC7. Its subset count says two and
|
|
35
|
-
* its pattern table is not the ordinary two-subset one, which is the only thing that separates it
|
|
36
|
-
* from mode 4.
|
|
37
|
-
*
|
|
38
|
-
* @readonly
|
|
39
|
-
* @type {number}
|
|
40
|
-
*/
|
|
41
|
-
const MODE_BC7_3_SUBSET_PATTERNS = 7;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Read `count` bits from a block, least significant first, starting `offset` bits into it.
|
|
45
|
-
*
|
|
46
|
-
* The specification prints every field as "name: bit_offset num_bits", so reading one is this call
|
|
47
|
-
* with those two numbers — which is why this is random access rather than a cursor. A cursor would
|
|
48
|
-
* mean tracking a position through fields the decoder skips, and the offsets are already known.
|
|
49
|
-
*
|
|
50
|
-
* @param {Uint8Array} bytes
|
|
51
|
-
* @param {number} base byte offset of the block
|
|
52
|
-
* @param {number} offset bits into the block
|
|
53
|
-
* @param {number} count at most 24
|
|
54
|
-
* @returns {number}
|
|
55
|
-
*/
|
|
56
|
-
function read_bits(bytes, base, offset, count) {
|
|
57
|
-
let value = 0;
|
|
58
|
-
|
|
59
|
-
for (let i = 0; i < count; i++) {
|
|
60
|
-
const bit = offset + i;
|
|
61
|
-
|
|
62
|
-
value |= ((bytes[base + (bit >> 3)] >> (bit & 7)) & 1) << i;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return value;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* How many colour components a Colour Endpoint Mode describes.
|
|
70
|
-
*
|
|
71
|
-
* @param {number} cem 4 luminance-alpha, 8 RGB, 12 RGBA — all "direct"
|
|
72
|
-
* @returns {number}
|
|
73
|
-
*/
|
|
74
|
-
function components_of(cem) {
|
|
75
|
-
return cem === 4 ? 2 : cem === 8 ? 3 : 4;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Dequantise one encoded endpoint integer to eight bits.
|
|
81
|
-
*
|
|
82
|
-
* @param {UastcEndpointRange|undefined} range `undefined` for a plain bit range
|
|
83
|
-
* @param {number} bits width of a plain bit range
|
|
84
|
-
* @param {number} encoded
|
|
85
|
-
* @returns {number}
|
|
86
|
-
*/
|
|
87
|
-
function dequantise(range, bits, encoded) {
|
|
88
|
-
if (range !== undefined) {
|
|
89
|
-
return range.value[encoded];
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/*
|
|
93
|
-
A plain bit range dequantises by replicating the value's top bits downward until eight are
|
|
94
|
-
filled — the same rule that takes a five-bit channel to eight everywhere else in this tree.
|
|
95
|
-
*/
|
|
96
|
-
let value = encoded;
|
|
97
|
-
let filled = bits;
|
|
98
|
-
|
|
99
|
-
while (filled < 8) {
|
|
100
|
-
value = (value << bits) | encoded;
|
|
101
|
-
filled += bits;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return (value >> (filled - 8)) & 255;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* The partition pattern table a mode draws on, and the anchor table beside it.
|
|
109
|
-
*
|
|
110
|
-
* @param {UastcMode} mode
|
|
111
|
-
* @returns {{patterns: Uint8Array, anchors: Uint8Array, anchor_stride: number}}
|
|
112
|
-
*/
|
|
113
|
-
function pattern_tables(mode) {
|
|
114
|
-
if (mode.subsets === 3) {
|
|
115
|
-
return { patterns: UASTC_PATTERNS_3, anchors: UASTC_ANCHORS_3, anchor_stride: 3 };
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (mode.mode === MODE_BC7_3_SUBSET_PATTERNS) {
|
|
119
|
-
return {
|
|
120
|
-
patterns: UASTC_PATTERNS_2_BC7_3,
|
|
121
|
-
anchors: UASTC_ANCHORS_2_BC7_3,
|
|
122
|
-
anchor_stride: 2,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return { patterns: UASTC_PATTERNS_2, anchors: UASTC_ANCHORS_2, anchor_stride: 2 };
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* One decoded UASTC block, in the terms the format states it rather than as texels.
|
|
131
|
-
*
|
|
132
|
-
* Kept in this form because a transcoder wants it: the partition and the per-subset endpoints are
|
|
133
|
-
* what map onto BC7's and ASTC's own, and going through RGBA would throw away the structure that
|
|
134
|
-
* makes those mappings cheap and nearly lossless.
|
|
135
|
-
*
|
|
136
|
-
* @typedef {object} UastcBlock
|
|
137
|
-
* @property {number} mode
|
|
138
|
-
* @property {number} subsets
|
|
139
|
-
* @property {boolean} has_alpha whether the source carried an alpha channel, as opposed to the
|
|
140
|
-
* opaque one an RGB colour endpoint mode implies
|
|
141
|
-
* @property {number} pattern index into the mode's partition pattern table, `0` for one subset
|
|
142
|
-
* @property {Uint8Array} partition one subset index per texel, all zero for a single subset
|
|
143
|
-
* @property {Uint8Array} endpoints `subsets * 2 * 4` bytes: low then high RGBA, per subset
|
|
144
|
-
* @property {Uint8Array} weights one `[0, 64]` interpolant per texel per plane, plane 0 first
|
|
145
|
-
* @property {Uint8Array} weight_indices the same, before unquantisation — what a transcoder maps to
|
|
146
|
-
* its own index space, since going via the interpolant would round twice
|
|
147
|
-
* @property {number} weight_range index into `UASTC_WEIGHT_VALUE`
|
|
148
|
-
* @property {boolean} dual_plane
|
|
149
|
-
* @property {number} component_selector which channel reads plane 1, when `dual_plane`
|
|
150
|
-
*/
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Decode one UASTC LDR 4x4 block.
|
|
154
|
-
*
|
|
155
|
-
* **The whole of the format's complexity is here**, and it is why UASTC is a second bitstream rather
|
|
156
|
-
* than a variation on ETC1S: nineteen modes differing in subset count, endpoint precision, weight
|
|
157
|
-
* precision and whether one channel is interpolated separately, with the endpoints trit- or
|
|
158
|
-
* quint-coded in most modes and the weights packed a bit short at each subset's anchor texel.
|
|
159
|
-
*
|
|
160
|
-
* @param {Uint8Array} bytes
|
|
161
|
-
* @param {number} base byte offset of the block
|
|
162
|
-
* @returns {UastcBlock}
|
|
163
|
-
* @throws {Error} for the reserved mode, which no encoder emits
|
|
164
|
-
*
|
|
165
|
-
* @see the UASTC LDR 4x4 specification
|
|
166
|
-
* @author Alex Goldring
|
|
167
|
-
* @copyright Company Named Limited (c) 2026
|
|
168
|
-
*/
|
|
169
|
-
export function uastc_decode_block(bytes, base) {
|
|
170
|
-
const mode_index = UASTC_MODE_OF_PREFIX[bytes[base] & 0x7F];
|
|
171
|
-
|
|
172
|
-
if (mode_index === UASTC_MODE_RESERVED) {
|
|
173
|
-
throw new Error(
|
|
174
|
-
`UASTC: block mode ${UASTC_MODE_RESERVED} is reserved by the specification for a future`
|
|
175
|
-
+ ` revision, and nothing defines what its bits mean`
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (mode_index === UASTC_MODE_SOLID) {
|
|
180
|
-
return solid_block(bytes, base);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const mode = UASTC_MODE_BY_INDEX[mode_index];
|
|
184
|
-
|
|
185
|
-
const { patterns, anchors, anchor_stride } = mode.subsets > 1
|
|
186
|
-
? pattern_tables(mode)
|
|
187
|
-
: { patterns: undefined, anchors: undefined, anchor_stride: 0 };
|
|
188
|
-
|
|
189
|
-
const pattern_index = mode.subsets > 1
|
|
190
|
-
? read_bits(bytes, base, mode.pat_offset, mode.pat_bits)
|
|
191
|
-
: 0;
|
|
192
|
-
|
|
193
|
-
const partition = new Uint8Array(TEXELS);
|
|
194
|
-
|
|
195
|
-
if (mode.subsets > 1) {
|
|
196
|
-
partition.set(patterns.subarray(pattern_index * TEXELS, (pattern_index + 1) * TEXELS));
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/*
|
|
200
|
-
The quantised values as well as the dequantised ones. A transcoder that re-encodes needs the
|
|
201
|
-
colours; one that repacks into ASTC needs the numbers the file actually stored, because they are
|
|
202
|
-
already in ASTC's quantised space and requantising them would lose what the format went to the
|
|
203
|
-
trouble of preserving.
|
|
204
|
-
*/
|
|
205
|
-
const endpoints_quantised = [];
|
|
206
|
-
|
|
207
|
-
const endpoints = read_endpoints(bytes, base, mode, endpoints_quantised);
|
|
208
|
-
|
|
209
|
-
const { weights, indices } = read_weights(
|
|
210
|
-
bytes, base, mode, partition, anchors, anchor_stride, pattern_index
|
|
211
|
-
);
|
|
212
|
-
|
|
213
|
-
return {
|
|
214
|
-
mode: mode_index,
|
|
215
|
-
endpoints_quantised,
|
|
216
|
-
subsets: mode.subsets,
|
|
217
|
-
pattern: pattern_index,
|
|
218
|
-
has_alpha: mode.cem !== 8,
|
|
219
|
-
partition,
|
|
220
|
-
endpoints,
|
|
221
|
-
weights,
|
|
222
|
-
weight_indices: indices,
|
|
223
|
-
weight_range: mode.weight_range,
|
|
224
|
-
dual_plane: mode.dual_plane,
|
|
225
|
-
component_selector: mode.dual_plane
|
|
226
|
-
? (mode.comp_offset < 0 ? 3 : read_bits(bytes, base, mode.comp_offset, 2))
|
|
227
|
-
: 0,
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Mode 8: one colour over the whole block, stored outright.
|
|
233
|
-
*
|
|
234
|
-
* @param {Uint8Array} bytes
|
|
235
|
-
* @param {number} base
|
|
236
|
-
* @returns {UastcBlock}
|
|
237
|
-
*/
|
|
238
|
-
function solid_block(bytes, base) {
|
|
239
|
-
const endpoints = new Uint8Array(8);
|
|
240
|
-
|
|
241
|
-
for (let c = 0; c < 4; c++) {
|
|
242
|
-
const value = read_bits(bytes, base, 5 + c * 8, 8);
|
|
243
|
-
|
|
244
|
-
endpoints[c] = value;
|
|
245
|
-
endpoints[4 + c] = value;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return {
|
|
249
|
-
mode: UASTC_MODE_SOLID,
|
|
250
|
-
subsets: 1,
|
|
251
|
-
pattern: 0,
|
|
252
|
-
has_alpha: true,
|
|
253
|
-
partition: new Uint8Array(TEXELS),
|
|
254
|
-
endpoints,
|
|
255
|
-
// both endpoints are the colour, so every weight gives it back
|
|
256
|
-
weights: new Uint8Array(TEXELS),
|
|
257
|
-
weight_indices: new Uint8Array(TEXELS),
|
|
258
|
-
weight_range: 0,
|
|
259
|
-
dual_plane: false,
|
|
260
|
-
component_selector: 0,
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Read and dequantise a block's endpoints into `subsets * 2 * 4` RGBA bytes.
|
|
266
|
-
*
|
|
267
|
-
* @param {Uint8Array} bytes
|
|
268
|
-
* @param {number} base
|
|
269
|
-
* @param {UastcMode} mode
|
|
270
|
-
* @returns {Uint8Array}
|
|
271
|
-
*/
|
|
272
|
-
function read_endpoints(bytes, base, mode, quantised_out) {
|
|
273
|
-
const range = UASTC_DEQUANT[mode.endpoint_range];
|
|
274
|
-
|
|
275
|
-
const component_count = components_of(mode.cem);
|
|
276
|
-
const value_count = component_count * 2 * mode.subsets;
|
|
277
|
-
|
|
278
|
-
/*
|
|
279
|
-
The trits or quints come first, all of them, and the values' bit portions follow — which is
|
|
280
|
-
UASTC's simplification of ASTC's interleaving, and the reason a decoder can read them with two
|
|
281
|
-
plain loops instead of ASTC's bit-shuffling procedure.
|
|
282
|
-
*/
|
|
283
|
-
const extra = new Uint8Array(value_count);
|
|
284
|
-
|
|
285
|
-
let offset = mode.value_offset;
|
|
286
|
-
|
|
287
|
-
if (range !== undefined && (range.trits === 1 || range.quints === 1)) {
|
|
288
|
-
const per_group = range.trits === 1 ? 5 : 3;
|
|
289
|
-
const radix = range.trits === 1 ? 3 : 5;
|
|
290
|
-
|
|
291
|
-
let value_index = 0;
|
|
292
|
-
|
|
293
|
-
for (const group_bits of mode.etq_bits) {
|
|
294
|
-
let packed = read_bits(bytes, base, offset, group_bits);
|
|
295
|
-
|
|
296
|
-
offset += group_bits;
|
|
297
|
-
|
|
298
|
-
// the group is the digits of one integer in base three or base five, least significant
|
|
299
|
-
// digit first
|
|
300
|
-
for (let i = 0; i < per_group && value_index < value_count; i++) {
|
|
301
|
-
extra[value_index++] = packed % radix;
|
|
302
|
-
packed = (packed / radix) | 0;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
const bits = range !== undefined ? range.bits : mode.endpoint_bits[0];
|
|
308
|
-
|
|
309
|
-
const endpoints = new Uint8Array(mode.subsets * 2 * 4);
|
|
310
|
-
|
|
311
|
-
for (let i = 0; i < value_count; i++) {
|
|
312
|
-
const width = mode.endpoint_bits[i];
|
|
313
|
-
|
|
314
|
-
const raw = read_bits(bytes, base, offset, width);
|
|
315
|
-
|
|
316
|
-
offset += width;
|
|
317
|
-
|
|
318
|
-
const encoded = range !== undefined ? ((extra[i] << bits) | raw) : raw;
|
|
319
|
-
|
|
320
|
-
if (quantised_out !== undefined) {
|
|
321
|
-
quantised_out.push(encoded);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
const value = dequantise(range, width, encoded);
|
|
325
|
-
|
|
326
|
-
place_endpoint(endpoints, mode.cem, component_count, i, value);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
return endpoints;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Write one decoded endpoint value into its RGBA slot.
|
|
334
|
-
*
|
|
335
|
-
* The format's ordering is ASTC's — low then high, per component, per subset — and the two modes
|
|
336
|
-
* that are not RGBA have to be widened into one: an RGB mode's alpha is opaque, and a
|
|
337
|
-
* luminance-alpha mode's luminance goes to all three colour channels.
|
|
338
|
-
*
|
|
339
|
-
* @param {Uint8Array} endpoints
|
|
340
|
-
* @param {number} cem
|
|
341
|
-
* @param {number} component_count
|
|
342
|
-
* @param {number} index into the format's value ordering
|
|
343
|
-
* @param {number} value eight bits
|
|
344
|
-
*/
|
|
345
|
-
function place_endpoint(endpoints, cem, component_count, index, value) {
|
|
346
|
-
const subset = (index / (component_count * 2)) | 0;
|
|
347
|
-
const within = index % (component_count * 2);
|
|
348
|
-
const component = (within / 2) | 0;
|
|
349
|
-
const half = within % 2;
|
|
350
|
-
|
|
351
|
-
const slot = (subset * 2 + half) * 4;
|
|
352
|
-
|
|
353
|
-
if (cem === 4) {
|
|
354
|
-
// luminance then alpha: LL LH AL AH
|
|
355
|
-
if (component === 0) {
|
|
356
|
-
endpoints[slot] = value;
|
|
357
|
-
endpoints[slot + 1] = value;
|
|
358
|
-
endpoints[slot + 2] = value;
|
|
359
|
-
} else {
|
|
360
|
-
endpoints[slot + 3] = value;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
endpoints[slot + component] = value;
|
|
367
|
-
|
|
368
|
-
if (cem === 8) {
|
|
369
|
-
endpoints[slot + 3] = 255;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* Read a block's weights, unquantised to `[0, 64]`.
|
|
375
|
-
*
|
|
376
|
-
* @param {Uint8Array} bytes
|
|
377
|
-
* @param {number} base
|
|
378
|
-
* @param {UastcMode} mode
|
|
379
|
-
* @param {Uint8Array} partition
|
|
380
|
-
* @param {Uint8Array|undefined} anchors
|
|
381
|
-
* @param {number} anchor_stride
|
|
382
|
-
* @param {number} pattern_index
|
|
383
|
-
* @returns {Uint8Array} one entry per texel per plane, plane 0 first
|
|
384
|
-
*/
|
|
385
|
-
function read_weights(bytes, base, mode, partition, anchors, anchor_stride, pattern_index) {
|
|
386
|
-
const table = UASTC_WEIGHT_VALUE[mode.weight_range];
|
|
387
|
-
|
|
388
|
-
const width = Math.log2(table.length);
|
|
389
|
-
|
|
390
|
-
const planes = mode.dual_plane ? 2 : 1;
|
|
391
|
-
|
|
392
|
-
/*
|
|
393
|
-
One texel per subset has its weight stored a bit short, because the block is written so that
|
|
394
|
-
weight's top bit is zero — the same trick BC7 plays, and what lets some of these modes fit in
|
|
395
|
-
128 bits at all. For a single subset that texel is the first; otherwise the anchor table says
|
|
396
|
-
which, and in a dual plane mode both of the first texel's planes are short.
|
|
397
|
-
*/
|
|
398
|
-
const short_at = new Uint8Array(TEXELS * planes);
|
|
399
|
-
|
|
400
|
-
if (mode.subsets === 1) {
|
|
401
|
-
for (let plane = 0; plane < planes; plane++) {
|
|
402
|
-
short_at[plane] = 1;
|
|
403
|
-
}
|
|
404
|
-
} else {
|
|
405
|
-
for (let subset = 0; subset < mode.subsets; subset++) {
|
|
406
|
-
short_at[anchors[pattern_index * anchor_stride + subset] * planes] = 1;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
const weights = new Uint8Array(TEXELS * planes);
|
|
411
|
-
const indices = new Uint8Array(TEXELS * planes);
|
|
412
|
-
|
|
413
|
-
let offset = mode.weights_offset;
|
|
414
|
-
|
|
415
|
-
for (let i = 0; i < TEXELS * planes; i++) {
|
|
416
|
-
const count = width - short_at[i];
|
|
417
|
-
|
|
418
|
-
const index = read_bits(bytes, base, offset, count);
|
|
419
|
-
|
|
420
|
-
indices[i] = index;
|
|
421
|
-
weights[i] = table[index];
|
|
422
|
-
|
|
423
|
-
offset += count;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
return { weights, indices };
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
/**
|
|
430
|
-
* Turn a decoded block into its sixteen RGBA texels.
|
|
431
|
-
*
|
|
432
|
-
* @param {UastcBlock} block
|
|
433
|
-
* @param {Uint8Array} out at least 64 bytes
|
|
434
|
-
* @param {number} [out_offset]
|
|
435
|
-
*
|
|
436
|
-
* @author Alex Goldring
|
|
437
|
-
* @copyright Company Named Limited (c) 2026
|
|
438
|
-
*/
|
|
439
|
-
export function uastc_block_texels(block, out, out_offset = 0) {
|
|
440
|
-
const planes = block.dual_plane ? 2 : 1;
|
|
441
|
-
|
|
442
|
-
for (let texel = 0; texel < TEXELS; texel++) {
|
|
443
|
-
const subset = block.partition[texel];
|
|
444
|
-
|
|
445
|
-
const low = subset * 8;
|
|
446
|
-
const high = low + 4;
|
|
447
|
-
|
|
448
|
-
for (let c = 0; c < 4; c++) {
|
|
449
|
-
/*
|
|
450
|
-
In a dual plane block one channel is interpolated with its own weight. Which channel is
|
|
451
|
-
the component selector's, and it is the ASTC field rather than BC7's rotation — the
|
|
452
|
-
components are not reordered here.
|
|
453
|
-
*/
|
|
454
|
-
const plane = (block.dual_plane && c === block.component_selector) ? 1 : 0;
|
|
455
|
-
|
|
456
|
-
const weight = block.weights[texel * planes + plane];
|
|
457
|
-
|
|
458
|
-
out[out_offset + texel * 4 + c] = astc_interpolate(
|
|
459
|
-
block.endpoints[low + c], block.endpoints[high + c], weight
|
|
460
|
-
);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
|
1
|
+
import { astc_interpolate } from "../../astc/astc_block.js";
|
|
2
|
+
import {
|
|
3
|
+
UASTC_ANCHORS_2,
|
|
4
|
+
UASTC_ANCHORS_2_BC7_3,
|
|
5
|
+
UASTC_ANCHORS_3,
|
|
6
|
+
UASTC_DEQUANT,
|
|
7
|
+
UASTC_MODE_BY_INDEX,
|
|
8
|
+
UASTC_MODE_OF_PREFIX,
|
|
9
|
+
UASTC_MODE_RESERVED,
|
|
10
|
+
UASTC_MODE_SOLID,
|
|
11
|
+
UASTC_PATTERNS_2,
|
|
12
|
+
UASTC_PATTERNS_2_BC7_3,
|
|
13
|
+
UASTC_PATTERNS_3,
|
|
14
|
+
UASTC_WEIGHT_VALUE,
|
|
15
|
+
} from "./uastc_tables.js";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Bytes one UASTC block occupies.
|
|
19
|
+
*
|
|
20
|
+
* @readonly
|
|
21
|
+
* @type {number}
|
|
22
|
+
*/
|
|
23
|
+
export const UASTC_BLOCK_BYTES = 16;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Texels one block covers.
|
|
27
|
+
*
|
|
28
|
+
* @readonly
|
|
29
|
+
* @type {number}
|
|
30
|
+
*/
|
|
31
|
+
const TEXELS = 16;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The mode that uses the 2-subset patterns which are 3-subset in BC7. Its subset count says two and
|
|
35
|
+
* its pattern table is not the ordinary two-subset one, which is the only thing that separates it
|
|
36
|
+
* from mode 4.
|
|
37
|
+
*
|
|
38
|
+
* @readonly
|
|
39
|
+
* @type {number}
|
|
40
|
+
*/
|
|
41
|
+
const MODE_BC7_3_SUBSET_PATTERNS = 7;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Read `count` bits from a block, least significant first, starting `offset` bits into it.
|
|
45
|
+
*
|
|
46
|
+
* The specification prints every field as "name: bit_offset num_bits", so reading one is this call
|
|
47
|
+
* with those two numbers — which is why this is random access rather than a cursor. A cursor would
|
|
48
|
+
* mean tracking a position through fields the decoder skips, and the offsets are already known.
|
|
49
|
+
*
|
|
50
|
+
* @param {Uint8Array} bytes
|
|
51
|
+
* @param {number} base byte offset of the block
|
|
52
|
+
* @param {number} offset bits into the block
|
|
53
|
+
* @param {number} count at most 24
|
|
54
|
+
* @returns {number}
|
|
55
|
+
*/
|
|
56
|
+
function read_bits(bytes, base, offset, count) {
|
|
57
|
+
let value = 0;
|
|
58
|
+
|
|
59
|
+
for (let i = 0; i < count; i++) {
|
|
60
|
+
const bit = offset + i;
|
|
61
|
+
|
|
62
|
+
value |= ((bytes[base + (bit >> 3)] >> (bit & 7)) & 1) << i;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* How many colour components a Colour Endpoint Mode describes.
|
|
70
|
+
*
|
|
71
|
+
* @param {number} cem 4 luminance-alpha, 8 RGB, 12 RGBA — all "direct"
|
|
72
|
+
* @returns {number}
|
|
73
|
+
*/
|
|
74
|
+
function components_of(cem) {
|
|
75
|
+
return cem === 4 ? 2 : cem === 8 ? 3 : 4;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Dequantise one encoded endpoint integer to eight bits.
|
|
81
|
+
*
|
|
82
|
+
* @param {UastcEndpointRange|undefined} range `undefined` for a plain bit range
|
|
83
|
+
* @param {number} bits width of a plain bit range
|
|
84
|
+
* @param {number} encoded
|
|
85
|
+
* @returns {number}
|
|
86
|
+
*/
|
|
87
|
+
function dequantise(range, bits, encoded) {
|
|
88
|
+
if (range !== undefined) {
|
|
89
|
+
return range.value[encoded];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/*
|
|
93
|
+
A plain bit range dequantises by replicating the value's top bits downward until eight are
|
|
94
|
+
filled — the same rule that takes a five-bit channel to eight everywhere else in this tree.
|
|
95
|
+
*/
|
|
96
|
+
let value = encoded;
|
|
97
|
+
let filled = bits;
|
|
98
|
+
|
|
99
|
+
while (filled < 8) {
|
|
100
|
+
value = (value << bits) | encoded;
|
|
101
|
+
filled += bits;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return (value >> (filled - 8)) & 255;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The partition pattern table a mode draws on, and the anchor table beside it.
|
|
109
|
+
*
|
|
110
|
+
* @param {UastcMode} mode
|
|
111
|
+
* @returns {{patterns: Uint8Array, anchors: Uint8Array, anchor_stride: number}}
|
|
112
|
+
*/
|
|
113
|
+
function pattern_tables(mode) {
|
|
114
|
+
if (mode.subsets === 3) {
|
|
115
|
+
return { patterns: UASTC_PATTERNS_3, anchors: UASTC_ANCHORS_3, anchor_stride: 3 };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (mode.mode === MODE_BC7_3_SUBSET_PATTERNS) {
|
|
119
|
+
return {
|
|
120
|
+
patterns: UASTC_PATTERNS_2_BC7_3,
|
|
121
|
+
anchors: UASTC_ANCHORS_2_BC7_3,
|
|
122
|
+
anchor_stride: 2,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return { patterns: UASTC_PATTERNS_2, anchors: UASTC_ANCHORS_2, anchor_stride: 2 };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* One decoded UASTC block, in the terms the format states it rather than as texels.
|
|
131
|
+
*
|
|
132
|
+
* Kept in this form because a transcoder wants it: the partition and the per-subset endpoints are
|
|
133
|
+
* what map onto BC7's and ASTC's own, and going through RGBA would throw away the structure that
|
|
134
|
+
* makes those mappings cheap and nearly lossless.
|
|
135
|
+
*
|
|
136
|
+
* @typedef {object} UastcBlock
|
|
137
|
+
* @property {number} mode
|
|
138
|
+
* @property {number} subsets
|
|
139
|
+
* @property {boolean} has_alpha whether the source carried an alpha channel, as opposed to the
|
|
140
|
+
* opaque one an RGB colour endpoint mode implies
|
|
141
|
+
* @property {number} pattern index into the mode's partition pattern table, `0` for one subset
|
|
142
|
+
* @property {Uint8Array} partition one subset index per texel, all zero for a single subset
|
|
143
|
+
* @property {Uint8Array} endpoints `subsets * 2 * 4` bytes: low then high RGBA, per subset
|
|
144
|
+
* @property {Uint8Array} weights one `[0, 64]` interpolant per texel per plane, plane 0 first
|
|
145
|
+
* @property {Uint8Array} weight_indices the same, before unquantisation — what a transcoder maps to
|
|
146
|
+
* its own index space, since going via the interpolant would round twice
|
|
147
|
+
* @property {number} weight_range index into `UASTC_WEIGHT_VALUE`
|
|
148
|
+
* @property {boolean} dual_plane
|
|
149
|
+
* @property {number} component_selector which channel reads plane 1, when `dual_plane`
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Decode one UASTC LDR 4x4 block.
|
|
154
|
+
*
|
|
155
|
+
* **The whole of the format's complexity is here**, and it is why UASTC is a second bitstream rather
|
|
156
|
+
* than a variation on ETC1S: nineteen modes differing in subset count, endpoint precision, weight
|
|
157
|
+
* precision and whether one channel is interpolated separately, with the endpoints trit- or
|
|
158
|
+
* quint-coded in most modes and the weights packed a bit short at each subset's anchor texel.
|
|
159
|
+
*
|
|
160
|
+
* @param {Uint8Array} bytes
|
|
161
|
+
* @param {number} base byte offset of the block
|
|
162
|
+
* @returns {UastcBlock}
|
|
163
|
+
* @throws {Error} for the reserved mode, which no encoder emits
|
|
164
|
+
*
|
|
165
|
+
* @see the UASTC LDR 4x4 specification
|
|
166
|
+
* @author Alex Goldring
|
|
167
|
+
* @copyright Company Named Limited (c) 2026
|
|
168
|
+
*/
|
|
169
|
+
export function uastc_decode_block(bytes, base) {
|
|
170
|
+
const mode_index = UASTC_MODE_OF_PREFIX[bytes[base] & 0x7F];
|
|
171
|
+
|
|
172
|
+
if (mode_index === UASTC_MODE_RESERVED) {
|
|
173
|
+
throw new Error(
|
|
174
|
+
`UASTC: block mode ${UASTC_MODE_RESERVED} is reserved by the specification for a future`
|
|
175
|
+
+ ` revision, and nothing defines what its bits mean`
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (mode_index === UASTC_MODE_SOLID) {
|
|
180
|
+
return solid_block(bytes, base);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const mode = UASTC_MODE_BY_INDEX[mode_index];
|
|
184
|
+
|
|
185
|
+
const { patterns, anchors, anchor_stride } = mode.subsets > 1
|
|
186
|
+
? pattern_tables(mode)
|
|
187
|
+
: { patterns: undefined, anchors: undefined, anchor_stride: 0 };
|
|
188
|
+
|
|
189
|
+
const pattern_index = mode.subsets > 1
|
|
190
|
+
? read_bits(bytes, base, mode.pat_offset, mode.pat_bits)
|
|
191
|
+
: 0;
|
|
192
|
+
|
|
193
|
+
const partition = new Uint8Array(TEXELS);
|
|
194
|
+
|
|
195
|
+
if (mode.subsets > 1) {
|
|
196
|
+
partition.set(patterns.subarray(pattern_index * TEXELS, (pattern_index + 1) * TEXELS));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/*
|
|
200
|
+
The quantised values as well as the dequantised ones. A transcoder that re-encodes needs the
|
|
201
|
+
colours; one that repacks into ASTC needs the numbers the file actually stored, because they are
|
|
202
|
+
already in ASTC's quantised space and requantising them would lose what the format went to the
|
|
203
|
+
trouble of preserving.
|
|
204
|
+
*/
|
|
205
|
+
const endpoints_quantised = [];
|
|
206
|
+
|
|
207
|
+
const endpoints = read_endpoints(bytes, base, mode, endpoints_quantised);
|
|
208
|
+
|
|
209
|
+
const { weights, indices } = read_weights(
|
|
210
|
+
bytes, base, mode, partition, anchors, anchor_stride, pattern_index
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
return {
|
|
214
|
+
mode: mode_index,
|
|
215
|
+
endpoints_quantised,
|
|
216
|
+
subsets: mode.subsets,
|
|
217
|
+
pattern: pattern_index,
|
|
218
|
+
has_alpha: mode.cem !== 8,
|
|
219
|
+
partition,
|
|
220
|
+
endpoints,
|
|
221
|
+
weights,
|
|
222
|
+
weight_indices: indices,
|
|
223
|
+
weight_range: mode.weight_range,
|
|
224
|
+
dual_plane: mode.dual_plane,
|
|
225
|
+
component_selector: mode.dual_plane
|
|
226
|
+
? (mode.comp_offset < 0 ? 3 : read_bits(bytes, base, mode.comp_offset, 2))
|
|
227
|
+
: 0,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Mode 8: one colour over the whole block, stored outright.
|
|
233
|
+
*
|
|
234
|
+
* @param {Uint8Array} bytes
|
|
235
|
+
* @param {number} base
|
|
236
|
+
* @returns {UastcBlock}
|
|
237
|
+
*/
|
|
238
|
+
function solid_block(bytes, base) {
|
|
239
|
+
const endpoints = new Uint8Array(8);
|
|
240
|
+
|
|
241
|
+
for (let c = 0; c < 4; c++) {
|
|
242
|
+
const value = read_bits(bytes, base, 5 + c * 8, 8);
|
|
243
|
+
|
|
244
|
+
endpoints[c] = value;
|
|
245
|
+
endpoints[4 + c] = value;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return {
|
|
249
|
+
mode: UASTC_MODE_SOLID,
|
|
250
|
+
subsets: 1,
|
|
251
|
+
pattern: 0,
|
|
252
|
+
has_alpha: true,
|
|
253
|
+
partition: new Uint8Array(TEXELS),
|
|
254
|
+
endpoints,
|
|
255
|
+
// both endpoints are the colour, so every weight gives it back
|
|
256
|
+
weights: new Uint8Array(TEXELS),
|
|
257
|
+
weight_indices: new Uint8Array(TEXELS),
|
|
258
|
+
weight_range: 0,
|
|
259
|
+
dual_plane: false,
|
|
260
|
+
component_selector: 0,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Read and dequantise a block's endpoints into `subsets * 2 * 4` RGBA bytes.
|
|
266
|
+
*
|
|
267
|
+
* @param {Uint8Array} bytes
|
|
268
|
+
* @param {number} base
|
|
269
|
+
* @param {UastcMode} mode
|
|
270
|
+
* @returns {Uint8Array}
|
|
271
|
+
*/
|
|
272
|
+
function read_endpoints(bytes, base, mode, quantised_out) {
|
|
273
|
+
const range = UASTC_DEQUANT[mode.endpoint_range];
|
|
274
|
+
|
|
275
|
+
const component_count = components_of(mode.cem);
|
|
276
|
+
const value_count = component_count * 2 * mode.subsets;
|
|
277
|
+
|
|
278
|
+
/*
|
|
279
|
+
The trits or quints come first, all of them, and the values' bit portions follow — which is
|
|
280
|
+
UASTC's simplification of ASTC's interleaving, and the reason a decoder can read them with two
|
|
281
|
+
plain loops instead of ASTC's bit-shuffling procedure.
|
|
282
|
+
*/
|
|
283
|
+
const extra = new Uint8Array(value_count);
|
|
284
|
+
|
|
285
|
+
let offset = mode.value_offset;
|
|
286
|
+
|
|
287
|
+
if (range !== undefined && (range.trits === 1 || range.quints === 1)) {
|
|
288
|
+
const per_group = range.trits === 1 ? 5 : 3;
|
|
289
|
+
const radix = range.trits === 1 ? 3 : 5;
|
|
290
|
+
|
|
291
|
+
let value_index = 0;
|
|
292
|
+
|
|
293
|
+
for (const group_bits of mode.etq_bits) {
|
|
294
|
+
let packed = read_bits(bytes, base, offset, group_bits);
|
|
295
|
+
|
|
296
|
+
offset += group_bits;
|
|
297
|
+
|
|
298
|
+
// the group is the digits of one integer in base three or base five, least significant
|
|
299
|
+
// digit first
|
|
300
|
+
for (let i = 0; i < per_group && value_index < value_count; i++) {
|
|
301
|
+
extra[value_index++] = packed % radix;
|
|
302
|
+
packed = (packed / radix) | 0;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const bits = range !== undefined ? range.bits : mode.endpoint_bits[0];
|
|
308
|
+
|
|
309
|
+
const endpoints = new Uint8Array(mode.subsets * 2 * 4);
|
|
310
|
+
|
|
311
|
+
for (let i = 0; i < value_count; i++) {
|
|
312
|
+
const width = mode.endpoint_bits[i];
|
|
313
|
+
|
|
314
|
+
const raw = read_bits(bytes, base, offset, width);
|
|
315
|
+
|
|
316
|
+
offset += width;
|
|
317
|
+
|
|
318
|
+
const encoded = range !== undefined ? ((extra[i] << bits) | raw) : raw;
|
|
319
|
+
|
|
320
|
+
if (quantised_out !== undefined) {
|
|
321
|
+
quantised_out.push(encoded);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const value = dequantise(range, width, encoded);
|
|
325
|
+
|
|
326
|
+
place_endpoint(endpoints, mode.cem, component_count, i, value);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return endpoints;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Write one decoded endpoint value into its RGBA slot.
|
|
334
|
+
*
|
|
335
|
+
* The format's ordering is ASTC's — low then high, per component, per subset — and the two modes
|
|
336
|
+
* that are not RGBA have to be widened into one: an RGB mode's alpha is opaque, and a
|
|
337
|
+
* luminance-alpha mode's luminance goes to all three colour channels.
|
|
338
|
+
*
|
|
339
|
+
* @param {Uint8Array} endpoints
|
|
340
|
+
* @param {number} cem
|
|
341
|
+
* @param {number} component_count
|
|
342
|
+
* @param {number} index into the format's value ordering
|
|
343
|
+
* @param {number} value eight bits
|
|
344
|
+
*/
|
|
345
|
+
function place_endpoint(endpoints, cem, component_count, index, value) {
|
|
346
|
+
const subset = (index / (component_count * 2)) | 0;
|
|
347
|
+
const within = index % (component_count * 2);
|
|
348
|
+
const component = (within / 2) | 0;
|
|
349
|
+
const half = within % 2;
|
|
350
|
+
|
|
351
|
+
const slot = (subset * 2 + half) * 4;
|
|
352
|
+
|
|
353
|
+
if (cem === 4) {
|
|
354
|
+
// luminance then alpha: LL LH AL AH
|
|
355
|
+
if (component === 0) {
|
|
356
|
+
endpoints[slot] = value;
|
|
357
|
+
endpoints[slot + 1] = value;
|
|
358
|
+
endpoints[slot + 2] = value;
|
|
359
|
+
} else {
|
|
360
|
+
endpoints[slot + 3] = value;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
endpoints[slot + component] = value;
|
|
367
|
+
|
|
368
|
+
if (cem === 8) {
|
|
369
|
+
endpoints[slot + 3] = 255;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Read a block's weights, unquantised to `[0, 64]`.
|
|
375
|
+
*
|
|
376
|
+
* @param {Uint8Array} bytes
|
|
377
|
+
* @param {number} base
|
|
378
|
+
* @param {UastcMode} mode
|
|
379
|
+
* @param {Uint8Array} partition
|
|
380
|
+
* @param {Uint8Array|undefined} anchors
|
|
381
|
+
* @param {number} anchor_stride
|
|
382
|
+
* @param {number} pattern_index
|
|
383
|
+
* @returns {Uint8Array} one entry per texel per plane, plane 0 first
|
|
384
|
+
*/
|
|
385
|
+
function read_weights(bytes, base, mode, partition, anchors, anchor_stride, pattern_index) {
|
|
386
|
+
const table = UASTC_WEIGHT_VALUE[mode.weight_range];
|
|
387
|
+
|
|
388
|
+
const width = Math.log2(table.length);
|
|
389
|
+
|
|
390
|
+
const planes = mode.dual_plane ? 2 : 1;
|
|
391
|
+
|
|
392
|
+
/*
|
|
393
|
+
One texel per subset has its weight stored a bit short, because the block is written so that
|
|
394
|
+
weight's top bit is zero — the same trick BC7 plays, and what lets some of these modes fit in
|
|
395
|
+
128 bits at all. For a single subset that texel is the first; otherwise the anchor table says
|
|
396
|
+
which, and in a dual plane mode both of the first texel's planes are short.
|
|
397
|
+
*/
|
|
398
|
+
const short_at = new Uint8Array(TEXELS * planes);
|
|
399
|
+
|
|
400
|
+
if (mode.subsets === 1) {
|
|
401
|
+
for (let plane = 0; plane < planes; plane++) {
|
|
402
|
+
short_at[plane] = 1;
|
|
403
|
+
}
|
|
404
|
+
} else {
|
|
405
|
+
for (let subset = 0; subset < mode.subsets; subset++) {
|
|
406
|
+
short_at[anchors[pattern_index * anchor_stride + subset] * planes] = 1;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const weights = new Uint8Array(TEXELS * planes);
|
|
411
|
+
const indices = new Uint8Array(TEXELS * planes);
|
|
412
|
+
|
|
413
|
+
let offset = mode.weights_offset;
|
|
414
|
+
|
|
415
|
+
for (let i = 0; i < TEXELS * planes; i++) {
|
|
416
|
+
const count = width - short_at[i];
|
|
417
|
+
|
|
418
|
+
const index = read_bits(bytes, base, offset, count);
|
|
419
|
+
|
|
420
|
+
indices[i] = index;
|
|
421
|
+
weights[i] = table[index];
|
|
422
|
+
|
|
423
|
+
offset += count;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
return { weights, indices };
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Turn a decoded block into its sixteen RGBA texels.
|
|
431
|
+
*
|
|
432
|
+
* @param {UastcBlock} block
|
|
433
|
+
* @param {Uint8Array} out at least 64 bytes
|
|
434
|
+
* @param {number} [out_offset]
|
|
435
|
+
*
|
|
436
|
+
* @author Alex Goldring
|
|
437
|
+
* @copyright Company Named Limited (c) 2026
|
|
438
|
+
*/
|
|
439
|
+
export function uastc_block_texels(block, out, out_offset = 0) {
|
|
440
|
+
const planes = block.dual_plane ? 2 : 1;
|
|
441
|
+
|
|
442
|
+
for (let texel = 0; texel < TEXELS; texel++) {
|
|
443
|
+
const subset = block.partition[texel];
|
|
444
|
+
|
|
445
|
+
const low = subset * 8;
|
|
446
|
+
const high = low + 4;
|
|
447
|
+
|
|
448
|
+
for (let c = 0; c < 4; c++) {
|
|
449
|
+
/*
|
|
450
|
+
In a dual plane block one channel is interpolated with its own weight. Which channel is
|
|
451
|
+
the component selector's, and it is the ASTC field rather than BC7's rotation — the
|
|
452
|
+
components are not reordered here.
|
|
453
|
+
*/
|
|
454
|
+
const plane = (block.dual_plane && c === block.component_selector) ? 1 : 0;
|
|
455
|
+
|
|
456
|
+
const weight = block.weights[texel * planes + plane];
|
|
457
|
+
|
|
458
|
+
out[out_offset + texel * 4 + c] = astc_interpolate(
|
|
459
|
+
block.endpoints[low + c], block.endpoints[high + c], weight
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|