Do not accept images that have wrong sizes
This commit is contained in:
parent
6d4916178c
commit
cb1b177d2a
|
@ -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 width = image.width();
|
||||||
let height = image.height();
|
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 {
|
||||||
|
|
Loading…
Reference in New Issue