mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-06-14 17:04:18 +08:00
Add support to modify bc7 compression settings
This commit is contained in:
@@ -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<BomType>,
|
||||
#[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,
|
||||
|
||||
@@ -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 } => {
|
||||
|
||||
@@ -99,9 +99,9 @@ impl ScriptBuilder for PsbBuilder {
|
||||
writer: Box<dyn WriteSeek + 'a>,
|
||||
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<BC7Settings> 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<Vec<u8>> {
|
||||
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<dyn WriteSeek + 'a>,
|
||||
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);
|
||||
|
||||
@@ -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<BomType>,
|
||||
#[cfg(feature = "emote-img")]
|
||||
/// BC7 compress configuration
|
||||
pub bc7: crate::scripts::emote::psb::BC7Config,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, ValueEnum, PartialEq, Eq, PartialOrd, Ord)]
|
||||
|
||||
Reference in New Issue
Block a user