Made CZ0 offset optional

This commit is contained in:
G2-Games 2024-05-01 16:38:50 -05:00
parent c93419439f
commit 7391f3797f
3 changed files with 12 additions and 5 deletions

View file

@ -18,10 +18,10 @@ pub struct Cz0Header {
bounds_height: u16, bounds_height: u16,
/// Offset width /// Offset width
offset_width: u16, offset_width: Option<u16>,
/// Offset height /// Offset height
offset_height: u16, offset_height: Option<u16>,
} }
#[derive(Debug)] #[derive(Debug)]
@ -38,6 +38,13 @@ impl CzHeader for Cz0Header {
return Err(CzError::VersionMismatch) return Err(CzError::VersionMismatch)
} }
let mut offset_width = None;
let mut offset_height = None;
if common.length < 28 {
offset_width = Some(u16::from_le_bytes(bytes[28..30].try_into().unwrap()));
offset_height = Some(u16::from_le_bytes(bytes[30..32].try_into().unwrap()));
}
Ok(Self { Ok(Self {
common, common,
@ -47,8 +54,8 @@ impl CzHeader for Cz0Header {
bounds_width: u16::from_le_bytes(bytes[24..26].try_into().unwrap()), bounds_width: u16::from_le_bytes(bytes[24..26].try_into().unwrap()),
bounds_height: u16::from_le_bytes(bytes[26..28].try_into().unwrap()), bounds_height: u16::from_le_bytes(bytes[26..28].try_into().unwrap()),
offset_width: u16::from_le_bytes(bytes[28..30].try_into().unwrap()), offset_width,
offset_height: u16::from_le_bytes(bytes[30..32].try_into().unwrap()), offset_height,
}) })
} }

View file

@ -9,7 +9,7 @@ use std::fs;
use crate::{cz_common::CzImage, formats::cz0::Cz0Image}; use crate::{cz_common::CzImage, formats::cz0::Cz0Image};
fn main() { fn main() {
let input = fs::read("../test_files/Old_TestFiles/LOGO0.CZ0").expect("Error, could not open image"); let input = fs::read("../test_files/Old_TestFiles/EX_PT.CZ0").expect("Error, could not open image");
let cz0_file = Cz0Image::decode(&input).unwrap(); let cz0_file = Cz0Image::decode(&input).unwrap();
println!("{:#?}", cz0_file.header()); println!("{:#?}", cz0_file.header());

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

After

Width:  |  Height:  |  Size: 54 KiB