From f103b313a163c4554806a57248ac7d897cac28e8 Mon Sep 17 00:00:00 2001 From: lifegpc Date: Wed, 25 Mar 2026 12:54:26 +0800 Subject: [PATCH] Add support to modify bc7 compression settings --- src/args.rs | 4 ++++ src/main.rs | 2 ++ src/scripts/emote/psb.rs | 32 ++++++++++++++++++++++++++------ src/types.rs | 3 +++ 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/args.rs b/src/args.rs index 02742fc..beda2d2 100644 --- a/src/args.rs +++ b/src/args.rs @@ -683,6 +683,10 @@ pub struct Arg { #[arg(long, global = true)] /// Specifiy BOM type when creating new Kirikiri ks script. If not specified, detect from original script. pub kirikiri_ks_bom: Option, + #[cfg(feature = "emote-img")] + #[arg(long, global = true, value_enum, default_value_t = crate::scripts::emote::psb::BC7Config::default())] + /// BC7 compress configuration + pub bc7: crate::scripts::emote::psb::BC7Config, #[command(subcommand)] /// Command pub command: Command, diff --git a/src/main.rs b/src/main.rs index 8d19b8c..92b34ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3385,6 +3385,8 @@ fn main() { )), #[cfg(feature = "kirikiri")] kirikiri_ks_bom: arg.kirikiri_ks_bom, + #[cfg(feature = "emote-img")] + bc7: arg.bc7, }); match &arg.command { args::Command::Export { input, output } => { diff --git a/src/scripts/emote/psb.rs b/src/scripts/emote/psb.rs index 3fac62d..211fe0c 100644 --- a/src/scripts/emote/psb.rs +++ b/src/scripts/emote/psb.rs @@ -99,9 +99,9 @@ impl ScriptBuilder for PsbBuilder { writer: Box, encoding: Encoding, file_encoding: Encoding, - _config: &ExtraConfig, + config: &ExtraConfig, ) -> Result<()> { - create_file(filename, writer, encoding, file_encoding) + create_file(filename, writer, encoding, file_encoding, config) } } @@ -125,6 +125,18 @@ impl Default for BC7Config { } } +impl Into for BC7Config { + fn into(self) -> BC7Settings { + match self { + Self::UltraFast => BC7Settings::alpha_ultrafast(), + Self::VeryFast => BC7Settings::alpha_very_fast(), + Self::Fast => BC7Settings::alpha_fast(), + Self::Basic => BC7Settings::alpha_basic(), + Self::Slow => BC7Settings::alpha_slow(), + } + } +} + #[derive(Debug)] pub struct Psb { psb: VirtualPsbFixed, @@ -467,7 +479,13 @@ impl Script for Psb { encoding: Encoding, output_encoding: Encoding, ) -> Result<()> { - create_file(custom_filename, file, encoding, output_encoding) + create_file( + custom_filename, + file, + encoding, + output_encoding, + &self.config, + ) } } @@ -475,6 +493,7 @@ fn read_resource( folder_path: &std::path::PathBuf, res: &Resource, encoding: Encoding, + cfg: &ExtraConfig, ) -> Result> { if let Some(tlg) = &res.tlg { let path = folder_path.join(&res.path); @@ -578,7 +597,7 @@ fn read_resource( crate::COUNTER.inc_warning(); } convert_to_rgba(&mut img)?; - let variant = block_compression::CompressionVariant::BC7(BC7Settings::alpha_basic()); + let variant = block_compression::CompressionVariant::BC7(cfg.bc7.into()); let dst_size = variant.blocks_byte_size(img.width, img.height); let mut compressed = vec![0u8; dst_size as usize]; block_compression::encode::compress_rgba8( @@ -601,6 +620,7 @@ fn create_file<'a>( mut writer: Box, encoding: Encoding, output_encoding: Encoding, + cfg: &ExtraConfig, ) -> Result<()> { let input = read_file(custom_filename)?; let s = decode_to_string(output_encoding, &input, true)?; @@ -623,11 +643,11 @@ fn create_file<'a>( pb }; for res in resources { - let res = read_resource(&folder_path, &res, encoding)?; + let res = read_resource(&folder_path, &res, encoding, cfg)?; psb.resources_mut().push(res); } for res in extra_resources { - let res = read_resource(&folder_path, &res, encoding)?; + let res = read_resource(&folder_path, &res, encoding, cfg)?; psb.extra_mut().push(res); } let psb = psb.to_psb(false); diff --git a/src/types.rs b/src/types.rs index 7845725..e691435 100644 --- a/src/types.rs +++ b/src/types.rs @@ -628,6 +628,9 @@ pub struct ExtraConfig { #[cfg(feature = "kirikiri")] /// Specifiy BOM type when creating new Kirikiri ks script. If not specified, detect from original script. pub kirikiri_ks_bom: Option, + #[cfg(feature = "emote-img")] + /// BC7 compress configuration + pub bc7: crate::scripts::emote::psb::BC7Config, } #[derive(Clone, Copy, Debug, ValueEnum, PartialEq, Eq, PartialOrd, Ord)]