Integrate all the progress into master #6

Merged
jaby merged 595 commits from ToolBox into main 2025-01-01 13:17:44 +00:00
1 changed files with 171 additions and 147 deletions
Showing only changes of commit 7ceb13863e - Show all commits

View File

@ -62,15 +62,39 @@ fn modify_palette(mut image: IndexedImage, clut_align: ClutAlignment, semi_trans
} }
fn encode<T: PSXImageConverter>(image: T, color_depth: ColorType, clut_align: ClutAlignment, output: &mut dyn Write) -> Result<(), Error> { fn encode<T: PSXImageConverter>(image: T, color_depth: ColorType, clut_align: ClutAlignment, output: &mut dyn Write) -> Result<(), Error> {
let width = { let (width, height) = {
let width = image.width(); fn return_error(clut_type: u32, div: u32, width: u16, height: u16) -> Result<(u16, u16), Error> {
match color_depth { return Err(Error::from_callback(|| {format!("CLUT {} images require a width divideable by {} (found width: {}/{}={}, height: {}/{}={})", clut_type, div,
ColorType::Clut4 => width/4, width, div, (width as f32/div as f32),
ColorType::Clut8 => width/2, height, div, (height as f32/div as f32))}));
ColorType::Full16 => width
} }
};
let height = image.height(); let width = image.width();
let height = image.height();
match color_depth {
ColorType::Clut4 => {
if width & 3 == 0 {
Ok((width/4, height))
}
else {
return_error(4, 4, width, height)
}
},
ColorType::Clut8 => {
if width & 1 == 0 {
Ok((width/2, height))
}
else {
return_error(8, 2, width, height)
}
},
ColorType::Full16 => {
Ok((width, height))
}
}
}?;
let palette = image.get_palette(); let palette = image.get_palette();
let (pal_width, pal_height) = { let (pal_width, pal_height) = {
if let Some(palette) = &palette { if let Some(palette) = &palette {