diff --git a/basisu_tool.cpp b/basisu_tool.cpp index 7f0ae6e..df39f86 100644 --- a/basisu_tool.cpp +++ b/basisu_tool.cpp @@ -457,10 +457,10 @@ class command_line_params else if (opt_match(pArg, {"-xuastc_weights", "-xuastc_ldr_weights", "-weights"})) { REMAINING_ARGS_CHECK(4); - m_comp_params.m_xuastc_ldr_channel_weights[0] = (uint32_t)clamp((float)atof(arg_v[arg_index + 1]), 1.0f, 1024.0f); - m_comp_params.m_xuastc_ldr_channel_weights[1] = (uint32_t)clamp((float)atof(arg_v[arg_index + 2]), 1.0f, 1024.0f); - m_comp_params.m_xuastc_ldr_channel_weights[2] = (uint32_t)clamp((float)atof(arg_v[arg_index + 3]), 1.0f, 1024.0f); - m_comp_params.m_xuastc_ldr_channel_weights[3] = (uint32_t)clamp((float)atof(arg_v[arg_index + 4]), 1.0f, 1024.0f); + m_comp_params.m_ldr_channel_weights[0] = (uint32_t)clamp((float)atof(arg_v[arg_index + 1]), 1.0f, 1024.0f); + m_comp_params.m_ldr_channel_weights[1] = (uint32_t)clamp((float)atof(arg_v[arg_index + 2]), 1.0f, 1024.0f); + m_comp_params.m_ldr_channel_weights[2] = (uint32_t)clamp((float)atof(arg_v[arg_index + 3]), 1.0f, 1024.0f); + m_comp_params.m_ldr_channel_weights[3] = (uint32_t)clamp((float)atof(arg_v[arg_index + 4]), 1.0f, 1024.0f); arg_count += 4; return true; } @@ -1770,7 +1770,7 @@ public: m_comp_params.m_no_selector_rdo = true; m_comp_params.m_no_endpoint_rdo = true; - m_comp_params.set_xuastc_ldr_srgb_channel_weights(false); + m_comp_params.set_ldr_srgb_channel_weights(false); m_comp_params.m_xuastc_ldr_sharpen_mode = (int)xuastc_ldr_sharpen_mode::cDisabled; m_comp_params.m_xuastc_ldr_deblocking_mode = (int)xuastc_ldr_deblocking_mode::cDisabled; @@ -1786,7 +1786,7 @@ public: m_comp_params.m_no_selector_rdo = false; m_comp_params.m_no_endpoint_rdo = false; - m_comp_params.set_xuastc_ldr_srgb_channel_weights(true); + m_comp_params.set_ldr_srgb_channel_weights(true); m_comp_params.m_xuastc_ldr_sharpen_mode = (int)xuastc_ldr_sharpen_mode::cDisabled; m_comp_params.m_xuastc_ldr_deblocking_mode = (int)xuastc_ldr_deblocking_mode::cUseSCDAndFilteringOnlyLargestBlocks; @@ -1796,14 +1796,14 @@ public: // linear preset (opposite of -srgb) m_comp_params.set_srgb_options(false); - m_comp_params.set_xuastc_ldr_srgb_channel_weights(false); + m_comp_params.set_ldr_srgb_channel_weights(false); } else if (opt_match(pArg, "-srgb")) { // sRGB preset (opposite of -linear) m_comp_params.set_srgb_options(true); - m_comp_params.set_xuastc_ldr_srgb_channel_weights(true); + m_comp_params.set_ldr_srgb_channel_weights(true); } else if (opt_match(pArg, "-no_alpha")) m_comp_params.m_check_for_alpha = false; diff --git a/bin/basisu_mt.wasm b/bin/basisu_mt.wasm index b272d11..77e846e 100644 Binary files a/bin/basisu_mt.wasm and b/bin/basisu_mt.wasm differ diff --git a/bin/basisu_st.wasm b/bin/basisu_st.wasm index c5a5e2a..0895b3b 100644 Binary files a/bin/basisu_st.wasm and b/bin/basisu_st.wasm differ diff --git a/bin/example_capi_mt.wasm b/bin/example_capi_mt.wasm index 684ec9b..6b1fabe 100644 Binary files a/bin/example_capi_mt.wasm and b/bin/example_capi_mt.wasm differ diff --git a/bin/example_capi_st.wasm b/bin/example_capi_st.wasm index c8b6469..4307b28 100644 Binary files a/bin/example_capi_st.wasm and b/bin/example_capi_st.wasm differ diff --git a/bin/example_mt.wasm b/bin/example_mt.wasm index ccf5967..674d845 100644 Binary files a/bin/example_mt.wasm and b/bin/example_mt.wasm differ diff --git a/bin/example_st.wasm b/bin/example_st.wasm index fcdbe6e..fb0a4db 100644 Binary files a/bin/example_st.wasm and b/bin/example_st.wasm differ diff --git a/encoder/basisu_comp.cpp b/encoder/basisu_comp.cpp index 6d972d1..37ecd49 100644 --- a/encoder/basisu_comp.cpp +++ b/encoder/basisu_comp.cpp @@ -631,9 +631,9 @@ namespace basisu PRINT_BOOL_VALUE(m_xuastc_ldr_force_disable_rgb_dual_plane); PRINT_INT_VALUE(m_xuastc_ldr_syntax); - debug_printf("XUASTC LDR channel weights: "); + debug_printf("LDR channel weights: "); for (uint32_t i = 0; i < 4; i++) - fmt_debug_printf("{} ", m_params.m_xuastc_ldr_channel_weights[i]); + fmt_debug_printf("{} ", m_params.m_ldr_channel_weights[i]); debug_printf("\n"); PRINT_FLOAT_VALUE(m_ls_min_psnr); @@ -929,7 +929,7 @@ namespace basisu (bool)m_params.m_xuastc_ldr_use_lossy_supercompression, (bool)m_params.m_ktx2_and_basis_srgb_transfer_function, (int)m_params.m_xuastc_ldr_syntax, - m_params.m_xuastc_ldr_channel_weights[0], m_params.m_xuastc_ldr_channel_weights[1], m_params.m_xuastc_ldr_channel_weights[2], m_params.m_xuastc_ldr_channel_weights[3]); + m_params.m_ldr_channel_weights[0], m_params.m_ldr_channel_weights[1], m_params.m_ldr_channel_weights[2], m_params.m_ldr_channel_weights[3]); } else { @@ -938,7 +938,7 @@ namespace basisu (int)m_params.m_xuastc_ldr_effort_level, (bool)m_params.m_xuastc_ldr_force_disable_subsets, (bool)m_params.m_xuastc_ldr_force_disable_rgb_dual_plane, (bool)m_params.m_ktx2_and_basis_srgb_transfer_function, (int)m_params.m_xuastc_ldr_syntax, - m_params.m_xuastc_ldr_channel_weights[0], m_params.m_xuastc_ldr_channel_weights[1], m_params.m_xuastc_ldr_channel_weights[2], m_params.m_xuastc_ldr_channel_weights[3]); + m_params.m_ldr_channel_weights[0], m_params.m_ldr_channel_weights[1], m_params.m_ldr_channel_weights[2], m_params.m_ldr_channel_weights[3]); } } @@ -1634,7 +1634,7 @@ namespace basisu cfg.m_lossy_supercompression = m_params.m_xuastc_ldr_use_lossy_supercompression; for (uint32_t i = 0; i < 4; i++) - cfg.m_comp_weights[i] = m_params.m_xuastc_ldr_channel_weights[i]; + cfg.m_comp_weights[i] = m_params.m_ldr_channel_weights[i]; cfg.m_replacement_min_psnr = m_params.m_ls_min_psnr; cfg.m_psnr_trial_diff_thresh = m_params.m_ls_thresh_psnr; @@ -1852,10 +1852,10 @@ namespace basisu options.m_dct_q = (m_params.m_quality_level < 0) ? 100 : clamp(m_params.m_quality_level, 1, 100); options.set_rdo_level(m_params.m_xubc7_rdo_level); - options.m_weights[0] = m_params.m_xuastc_ldr_channel_weights[0]; - options.m_weights[1] = m_params.m_xuastc_ldr_channel_weights[1]; - options.m_weights[2] = m_params.m_xuastc_ldr_channel_weights[2]; - options.m_weights[3] = m_params.m_xuastc_ldr_channel_weights[3]; + options.m_weights[0] = m_params.m_ldr_channel_weights[0]; + options.m_weights[1] = m_params.m_ldr_channel_weights[1]; + options.m_weights[2] = m_params.m_ldr_channel_weights[2]; + options.m_weights[3] = m_params.m_ldr_channel_weights[3]; if ((options.m_dct_q >= 90) && (m_params.m_xubc7_effort_level >= 3)) { @@ -1889,9 +1889,10 @@ namespace basisu if (m_params.m_status_output) { - fmt_printf("XUBC7 encoder: {} (bc7e_scalar level: {}), effort: {}, RDO level [0,100]: {}, Desired stripes [1,16]: {}\n", + fmt_printf("XUBC7 encoder: {} (bc7e_scalar level: {}), effort: {}, RDO level [0,100]: {}, Desired stripes [1,16]: {}, Channel weights: {}, {}, {}, {}\n", (options.m_bc7_encoder == xbc7::bc7_encoder_type::cBC7E_Scalar) ? "bc7e_scalar" : "bc7f", options.m_bc7e_scalar_level, - m_params.m_xubc7_effort_level, m_params.m_xubc7_rdo_level, desired_num_stripes); + m_params.m_xubc7_effort_level, m_params.m_xubc7_rdo_level, desired_num_stripes, + m_params.m_ldr_channel_weights[0], m_params.m_ldr_channel_weights[1], m_params.m_ldr_channel_weights[2], m_params.m_ldr_channel_weights[3]); } for (uint32_t slice_index = 0; slice_index < m_slice_descs.size(); slice_index++) @@ -5710,8 +5711,8 @@ namespace basisu // Correct for sRGB transfer function during mipmapping comp_params.m_mip_srgb = srgb_flag; - // Set linear or Rec 709 weights (we assume Rec 709 weights if content is sRGB) - comp_params.set_xuastc_ldr_srgb_channel_weights(srgb_flag); + // Set linear or Rec 709 weights (we assume Rec 709 weights if content is sRGB) - ASTC/XUASTC/XUBC7 + comp_params.set_ldr_srgb_channel_weights(srgb_flag); comp_params.m_mip_gen = (flags_and_quality & (cFlagGenMipsWrap | cFlagGenMipsClamp)) != 0; comp_params.m_mip_wrapping = (flags_and_quality & cFlagGenMipsWrap) != 0; diff --git a/encoder/basisu_comp.h b/encoder/basisu_comp.h index 145a25b..0e29655 100644 --- a/encoder/basisu_comp.h +++ b/encoder/basisu_comp.h @@ -597,7 +597,7 @@ namespace basisu // Sets all the sRGB-related options (m_perceptual, m_mip_srgb, m_ktx2_and_basis_srgb_transfer_function) to the specified value. // If m_perceptual is true, the encoder assumes the input is sRGB photographic-like data and optimizes for perceptual quality. If false, the encoder assumes the input is linear data and optimizes for PSNR. - // For ASTC/XUASTC LDR, also see the channel weights below: m_xuastc_ldr_channel_weights. They default to 9,11,1,11. + // For ASTC/XUASTC LDR and XUBC7, also see the channel weights below: m_ldr_channel_weights. They default to 9,11,1,11. void set_srgb_options(bool srgb_flag) { m_perceptual = srgb_flag; @@ -862,12 +862,12 @@ namespace basisu // Entropy coding syntax: Default is basist::astc_ldr_t::xuastc_ldr_syntax::cFullZstd (fastest transcoding but lower ratio). param m_xuastc_ldr_syntax; - // XUASTC/XUBC7 weights (TODO: rename to make it clear these are shared now) + // XUASTC/XUBC7 weights (TODO: rename to make it clear these are shared between different codecs now) // Each component channel weight must be >= 1 (no 0 weights allowed). // Important: Default channel weights are 9,11,1,11. // For best photo quality, especially on the largest block sizes, the RGB weights should be set to roughly 9,11,1, and alpha set to ~G, so 11. // For non-photographic, non-sRGB or linear (normal map) content, this should be set to 1,1,1,1. - uint32_t m_xuastc_ldr_channel_weights[4]; + uint32_t m_ldr_channel_weights[4]; // Set ASTC/XUASTC/XUBC7 LDR linear or Rec 709-like channel weights. On larger ASTC/XUASTC LDR block sizes, 709-like weights make a noticeable difference in quality. void set_ldr_srgb_channel_weights(bool srgb_flag) @@ -875,17 +875,17 @@ namespace basisu if (srgb_flag) { // 9,11,1,11 - m_xuastc_ldr_channel_weights[0] = 9; - m_xuastc_ldr_channel_weights[1] = 11; - m_xuastc_ldr_channel_weights[2] = 1; - m_xuastc_ldr_channel_weights[3] = 11; + m_ldr_channel_weights[0] = 9; + m_ldr_channel_weights[1] = 11; + m_ldr_channel_weights[2] = 1; + m_ldr_channel_weights[3] = 11; } else { - m_xuastc_ldr_channel_weights[0] = 1; - m_xuastc_ldr_channel_weights[1] = 1; - m_xuastc_ldr_channel_weights[2] = 1; - m_xuastc_ldr_channel_weights[3] = 1; + m_ldr_channel_weights[0] = 1; + m_ldr_channel_weights[1] = 1; + m_ldr_channel_weights[2] = 1; + m_ldr_channel_weights[3] = 1; } } diff --git a/encoder/basisu_dds_export.cpp b/encoder/basisu_dds_export.cpp index 22663eb..395838d 100644 --- a/encoder/basisu_dds_export.cpp +++ b/encoder/basisu_dds_export.cpp @@ -483,7 +483,7 @@ namespace basisu if (!perceptual) { for (uint32_t i = 0; i < 4; i++) - bc7ctx.m_bc7e_params.m_weights[i] = comp.get_params().m_xuastc_ldr_channel_weights[i]; + bc7ctx.m_bc7e_params.m_weights[i] = comp.get_params().m_ldr_channel_weights[i]; } } @@ -513,7 +513,7 @@ namespace basisu const int bc7e_lvl = clamp(params.m_bc7e_scalar_level, 0, 6); const bool perceptual = comp.get_params().m_perceptual; - const uint32_t* pW = comp.get_params().m_xuastc_ldr_channel_weights; + const uint32_t* pW = comp.get_params().m_ldr_channel_weights; debug_printf("DDS export: BC7 encoder=%s\n", using_bc7e ? "bc7e_scalar" : "bc7f"); debug_printf("DDS export: bc7f level=%d (%s), pack flags=0x%X%s\n", diff --git a/python/basisu_py/basisu_python.cpython-312-x86_64-linux-gnu.so b/python/basisu_py/basisu_python.cpython-312-x86_64-linux-gnu.so index a166085..559507e 100644 Binary files a/python/basisu_py/basisu_python.cpython-312-x86_64-linux-gnu.so and b/python/basisu_py/basisu_python.cpython-312-x86_64-linux-gnu.so differ diff --git a/python/basisu_py/basisu_python.pyd b/python/basisu_py/basisu_python.pyd index 4cafc4b..2d77a82 100644 Binary files a/python/basisu_py/basisu_python.pyd and b/python/basisu_py/basisu_python.pyd differ diff --git a/python/basisu_py/wasm/basisu_module_mt.wasm b/python/basisu_py/wasm/basisu_module_mt.wasm index 68b63c1..07b05b8 100644 Binary files a/python/basisu_py/wasm/basisu_module_mt.wasm and b/python/basisu_py/wasm/basisu_module_mt.wasm differ diff --git a/python/basisu_py/wasm/basisu_module_st.wasm b/python/basisu_py/wasm/basisu_module_st.wasm index d2ef366..6d9985b 100644 Binary files a/python/basisu_py/wasm/basisu_module_st.wasm and b/python/basisu_py/wasm/basisu_module_st.wasm differ diff --git a/webgl/encoder/build/basis_encoder.wasm b/webgl/encoder/build/basis_encoder.wasm index f749619..cac3ac6 100644 Binary files a/webgl/encoder/build/basis_encoder.wasm and b/webgl/encoder/build/basis_encoder.wasm differ diff --git a/webgl/encoder/build/basis_encoder_threads.wasm b/webgl/encoder/build/basis_encoder_threads.wasm index d49f189..5eb5a4e 100644 Binary files a/webgl/encoder/build/basis_encoder_threads.wasm and b/webgl/encoder/build/basis_encoder_threads.wasm differ diff --git a/webgl/encoder/build/basis_encoder_threads_wasm64.wasm b/webgl/encoder/build/basis_encoder_threads_wasm64.wasm index d61e59a..10e4c59 100644 Binary files a/webgl/encoder/build/basis_encoder_threads_wasm64.wasm and b/webgl/encoder/build/basis_encoder_threads_wasm64.wasm differ diff --git a/webgl/transcoder/basis_wrappers.cpp b/webgl/transcoder/basis_wrappers.cpp index 86b832f..c80d4df 100644 --- a/webgl/transcoder/basis_wrappers.cpp +++ b/webgl/transcoder/basis_wrappers.cpp @@ -3740,7 +3740,6 @@ EMSCRIPTEN_BINDINGS(basis_codec) { })) // setNormalMapMode is the same as the basisu.exe "-normal_map" option. It tunes several codec parameters so compression works better on normal maps. - // ETC1S/UASTC LDR 4x4/UASTC HDR 4x4 .function("setNormalMapPreset", optional_override([](basis_encoder& self) { self.m_params.set_srgb_options(false); @@ -3748,7 +3747,7 @@ EMSCRIPTEN_BINDINGS(basis_codec) { self.m_params.m_no_selector_rdo = true; self.m_params.m_no_endpoint_rdo = true; - self.m_params.set_xuastc_ldr_srgb_channel_weights(false); + self.m_params.set_ldr_srgb_channel_weights(false); self.m_params.m_xuastc_ldr_sharpen_mode = (int)xuastc_ldr_sharpen_mode::cDisabled; self.m_params.m_xuastc_ldr_deblocking_mode = (int)xuastc_ldr_deblocking_mode::cDisabled; @@ -3762,7 +3761,7 @@ EMSCRIPTEN_BINDINGS(basis_codec) { self.m_params.m_no_selector_rdo = false; self.m_params.m_no_endpoint_rdo = false; - self.m_params.set_xuastc_ldr_srgb_channel_weights(true); + self.m_params.set_ldr_srgb_channel_weights(true); self.m_params.m_xuastc_ldr_sharpen_mode = (int)xuastc_ldr_sharpen_mode::cDisabled; self.m_params.m_xuastc_ldr_deblocking_mode = (int)xuastc_ldr_deblocking_mode::cUseSCDAndFilteringOnlyLargestBlocks; @@ -3773,7 +3772,7 @@ EMSCRIPTEN_BINDINGS(basis_codec) { self.m_params.set_srgb_options(false); - self.m_params.set_xuastc_ldr_srgb_channel_weights(false); + self.m_params.set_ldr_srgb_channel_weights(false); })) // -srgb option @@ -3781,7 +3780,7 @@ EMSCRIPTEN_BINDINGS(basis_codec) { self.m_params.set_srgb_options(true); - self.m_params.set_xuastc_ldr_srgb_channel_weights(true); + self.m_params.set_ldr_srgb_channel_weights(true); })) // Sets ETC1S selector RDO threshold @@ -3823,7 +3822,7 @@ EMSCRIPTEN_BINDINGS(basis_codec) { })) // Sets all the sRGB-related options (m_perceptual, m_mip_srgb, m_ktx2_and_basis_srgb_transfer_function) to the specified value, ensuring they are all kept in sync. - // For ASTC/XUASTC LDR, also see the channel weights below: m_xuastc_ldr_channel_weights. They default to 3,11,1,11. + // For ASTC/XUASTC LDR and XUBC7, also see the channel weights below: m_ldr_channel_weights. They default to 9,11,1,11. .function("setSRGBOptions", optional_override([](basis_encoder& self, bool srgb_flag) { self.m_params.set_srgb_options(srgb_flag); })) @@ -3967,13 +3966,22 @@ EMSCRIPTEN_BINDINGS(basis_codec) { self.m_params.m_xuastc_ldr_effort_level = effort_level; })) - // Sets the ASTC/XUASTC LDR channel weights - // The default channel weights are 3,11,1,11 - so override them for linear content (like normal maps or non-sRGB content). + // Sets the ASTC/XUASTC/XUBC7 LDR channel weights + // The default channel weights are 9,11,1,11 - so override them for linear content (like normal maps or non-sRGB content). .function("setASTCOrXUASTCLDRWeights", optional_override([](basis_encoder& self, uint32_t x, uint32_t y, uint32_t z, uint32_t w) { - self.m_params.m_xuastc_ldr_channel_weights[0] = x; - self.m_params.m_xuastc_ldr_channel_weights[1] = y; - self.m_params.m_xuastc_ldr_channel_weights[2] = z; - self.m_params.m_xuastc_ldr_channel_weights[3] = w; + self.m_params.m_ldr_channel_weights[0] = x; + self.m_params.m_ldr_channel_weights[1] = y; + self.m_params.m_ldr_channel_weights[2] = z; + self.m_params.m_ldr_channel_weights[3] = w; + })) + + // Sets the ASTC/XUASTC/XUBC7 LDR channel weights + // The default channel weights are 9,11,1,11 - so override them for linear content (like normal maps or non-sRGB content). + .function("setLDRChannelWeights", optional_override([](basis_encoder& self, uint32_t x, uint32_t y, uint32_t z, uint32_t w) { + self.m_params.m_ldr_channel_weights[0] = x; + self.m_params.m_ldr_channel_weights[1] = y; + self.m_params.m_ldr_channel_weights[2] = z; + self.m_params.m_ldr_channel_weights[3] = w; })) // Sets XUASTC LDR lossy supercompression (bounded/windows RDO) parameters.