remove common

This commit is contained in:
Quaternions 2025-02-04 09:04:40 -08:00
parent a5079f21d7
commit 6522c255cd
2 changed files with 0 additions and 78 deletions

@ -1,75 +0,0 @@
use std::path::PathBuf;
use std::io::{Read,Seek};
use anyhow::Result as AResult;
fn load_image<R:Read+Seek+std::io::BufRead>(input:&mut R)->AResult<image::DynamicImage>{
let mut fourcc=[0u8;4];
input.read_exact(&mut fourcc)?;
input.rewind()?;
match &fourcc{
b"\x89PNG"=>Ok(image::load(input,image::ImageFormat::Png)?),
b"\xFF\xD8\xFF\xE0"=>Ok(image::load(input,image::ImageFormat::Jpeg)?),//JFIF
b"<rob"=>Err(anyhow::Error::msg("Roblox xml garbage is not supported yet")),
other=>Err(anyhow::Error::msg(format!("Unknown texture format {:?}",other))),
}
}
fn convert(file_thing:std::fs::DirEntry) -> AResult<()>{
let mut input = std::io::BufReader::new(std::fs::File::open(file_thing.path())?);
let image=load_image(&mut input)?.to_rgba8();//this sets a=255, arcane is actually supposed to look like that
let format=if image.width()%4!=0||image.height()%4!=0{
image_dds::ImageFormat::Rgba8UnormSrgb
}else{
image_dds::ImageFormat::BC7RgbaUnormSrgb
};
//this fails if the image dimensions are not a multiple of 4
let dds = image_dds::dds_from_image(
&image,
format,
image_dds::Quality::Slow,
image_dds::Mipmaps::GeneratedAutomatic,
)?;
//write dds
let mut dest=PathBuf::from("textures");
dest.push(file_thing.file_name());
dest.set_extension("dds");
let mut writer = std::io::BufWriter::new(std::fs::File::create(dest)?);
dds.write(&mut writer)?;
//move file to processed
let mut dest=PathBuf::from("textures/processed");
dest.push(file_thing.file_name());
std::fs::rename(file_thing.path(), dest)?;
Ok(())
}
pub fn convert_textures() -> AResult<()>{
std::fs::create_dir_all("textures/unprocessed")?;
std::fs::create_dir_all("textures/processed")?;
let start = std::time::Instant::now();
let mut threads=Vec::new();
for entry in std::fs::read_dir("textures/unprocessed")? {
let file_thing=entry?;
threads.push(std::thread::spawn(move ||{
let file_name=format!("{:?}",file_thing);
let result=convert(file_thing);
if let Err(e)=result{
println!("error processing file:{:?} error message:{:?}",file_name,e);
}
}));
}
let mut i=0;
let n_threads=threads.len();
for thread in threads{
i+=1;
if let Err(e)=thread.join(){
println!("thread error: {:?}",e);
}else{
println!("{}/{}",i,n_threads);
}
}
println!("{:?}", start.elapsed());
Ok(())
}

@ -1,4 +1,3 @@
mod common;
mod roblox;
mod source;
@ -19,7 +18,6 @@ enum Commands{
Roblox(roblox::Commands),
#[command(flatten)]
Source(source::Commands),
ConvertTextures,
}
fn main() -> AResult<()> {
@ -27,6 +25,5 @@ fn main() -> AResult<()> {
match cli.command{
Commands::Roblox(commands)=>commands.run(),
Commands::Source(commands)=>commands.run(),
Commands::ConvertTextures=>common::convert_textures(),
}
}