Fix fconv for clut images

This commit is contained in:
Jaby Blubb 2023-05-01 11:02:07 +02:00
parent 04ec3f89f1
commit 958ce0e7fd
2 changed files with 13 additions and 6 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "jaby_engine_fconv"
version = "0.1.3"
version = "0.1.4"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -33,8 +33,15 @@ pub struct Arguments {
clut_align: ClutAlignment
}
fn encode<T: PSXImageConverter>(image: T, clut_align: ClutAlignment, output: &mut dyn Write) -> Result<(), Error> {
let width = image.width();
fn encode<T: PSXImageConverter>(image: T, color_depth: ColorType, clut_align: ClutAlignment, output: &mut dyn Write) -> Result<(), Error> {
let width = {
let width = image.width();
match color_depth {
ColorType::Clut4 => width/4,
ColorType::Clut8 => width/2,
ColorType::Full16 => width
}
};
let height = image.height();
let palette = image.get_palette();
let (pal_width, pal_height) = {
@ -78,8 +85,8 @@ fn convert_full16(input: Input, output: &mut dyn Write) -> Result<(), Error> {
match ImageReader::new(Cursor::new(tool_helper::input_to_vec(input)?)).with_guessed_format()?.decode() {
Ok(image) => {
match image {
DynamicImage::ImageRgb8(image) => encode(RgbImage::new(image), ClutAlignment::None, output),
DynamicImage::ImageRgba8(image) => encode(RgbaImage::new(image), ClutAlignment::None, output),
DynamicImage::ImageRgb8(image) => encode(RgbImage::new(image), ColorType::Full16, ClutAlignment::None, output),
DynamicImage::ImageRgba8(image) => encode(RgbaImage::new(image), ColorType::Full16, ClutAlignment::None, output),
_ => Err(Error::from_str("Only RGB and RGBA images are supported for 16bit encoding"))
}
@ -98,7 +105,7 @@ fn convert_palette_based(input: Input, output: &mut dyn Write, color_type: Color
_ => return Err(Error::from_str("ColorType not supported"))
}
};
encode(IndexedImage::new(reader, output_type)?, clut_align, output)
encode(IndexedImage::new(reader, output_type)?, color_type, clut_align, output)
},
Err(error) => Err(Error::from_error(error))
}