diff --git a/Cargo.toml b/Cargo.toml index 75ce05b..baa7ece 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,5 @@ -[package] -name = "lbee-utils" -version = "0.1.0" -edition = "2021" +[workspace] -[dependencies] -byteorder = "1.5.0" -image = "0.25" -thiserror = "1.0.59" +members = [ + "cz", +] diff --git a/cz/Cargo.toml b/cz/Cargo.toml new file mode 100644 index 0000000..890f027 --- /dev/null +++ b/cz/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "cz" +version = "0.1.0" +edition = "2021" + +[dependencies] +image = "0.25" +byteorder = "1.5.0" +thiserror = "1.0.59" diff --git a/src/common.rs b/cz/src/common.rs similarity index 100% rename from src/common.rs rename to cz/src/common.rs diff --git a/src/compression.rs b/cz/src/compression.rs similarity index 100% rename from src/compression.rs rename to cz/src/compression.rs diff --git a/src/formats/cz0.rs b/cz/src/formats/cz0.rs similarity index 98% rename from src/formats/cz0.rs rename to cz/src/formats/cz0.rs index 77db778..5f89247 100644 --- a/src/formats/cz0.rs +++ b/cz/src/formats/cz0.rs @@ -140,7 +140,7 @@ impl CzImage for Cz0Image { fn decode(bytes: &mut T) -> Result { // Get the header from the input let header = Cz0Header::new(bytes)?; - bytes.seek(io::SeekFrom::Start(header.length() as u64)); + bytes.seek(io::SeekFrom::Start(header.length() as u64))?; // Get the rest of the file, which is the bitmap let mut bitmap = vec![]; diff --git a/src/formats/cz1.rs b/cz/src/formats/cz1.rs similarity index 85% rename from src/formats/cz1.rs rename to cz/src/formats/cz1.rs index 154af5d..7e834f5 100644 --- a/src/formats/cz1.rs +++ b/cz/src/formats/cz1.rs @@ -1,6 +1,10 @@ use byteorder::ReadBytesExt; use image::{ImageFormat, Rgba}; -use std::{fs::File, io::{BufWriter, Cursor, Read, Seek, SeekFrom, Write}, path::PathBuf}; +use std::{ + fs::File, + io::{BufWriter, Read, Seek, SeekFrom, Write}, + path::PathBuf +}; use crate::compression::{decompress, parse_chunk_info}; use crate::common::{apply_palette, parse_colormap, CommonHeader, CzError, CzHeader, CzImage}; @@ -19,7 +23,7 @@ impl CzImage for Cz1Image { fn decode(bytes: &mut T) -> Result { // Get the header from the input let header = CommonHeader::new(bytes).unwrap(); - bytes.seek(SeekFrom::Start(header.length() as u64)); + bytes.seek(SeekFrom::Start(header.length() as u64))?; if header.version() != 1 { return Err(CzError::VersionMismatch) @@ -33,15 +37,6 @@ impl CzImage for Cz1Image { let chunk_info = parse_chunk_info(bytes)?; - /* - if chunk_info.total_size_compressed as usize > bytes. { - return Err(CzError::InvalidFormat { - expected: chunk_info.total_size_compressed, - got: bytes.len(), - }); - } - */ - let mut bitmap = decompress(bytes, &chunk_info).unwrap(); let mut raw_bitmap = None; @@ -92,8 +87,9 @@ impl CzImage for Cz1Image { output_file.write_all(&self.header.to_bytes()?)?; - output_file.flush()?; + + output_file.flush()?; Ok(()) } diff --git a/src/formats/cz3.rs b/cz/src/formats/cz3.rs similarity index 98% rename from src/formats/cz3.rs rename to cz/src/formats/cz3.rs index c1d9447..38be0a6 100644 --- a/src/formats/cz3.rs +++ b/cz/src/formats/cz3.rs @@ -110,7 +110,7 @@ impl CzImage for Cz3Image { fn decode(bytes: &mut T) -> Result { let header = Cz3Header::new(bytes)?; - bytes.seek(SeekFrom::Start(header.length() as u64)); + bytes.seek(SeekFrom::Start(header.length() as u64))?; let block_info = parse_chunk_info(bytes)?; diff --git a/cz/src/lib.rs b/cz/src/lib.rs new file mode 100644 index 0000000..c5d6250 --- /dev/null +++ b/cz/src/lib.rs @@ -0,0 +1,14 @@ +pub mod common; +pub mod compression; +pub mod formats { + pub mod cz0; + pub mod cz1; + pub mod cz3; +} + +pub use formats::cz0::Cz0Image; +pub use formats::cz1::Cz1Image; +pub use formats::cz3::Cz3Image; + +/// Traits for CZ# images +pub use common::CzImage; diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index bcdaa3d..0000000 --- a/src/main.rs +++ /dev/null @@ -1,23 +0,0 @@ -pub mod common; -pub mod compression; -pub mod formats { - pub mod cz0; - pub mod cz1; - pub mod cz3; -} - -use common::CzImage; -pub use formats::cz0::Cz0Image; -pub use formats::cz1::Cz1Image; -pub use formats::cz3::Cz3Image; - -// Generic tools -use std::fs; - -fn main() { - let mut input = fs::File::open("../test_files/font_files/24-style1.cz1").unwrap(); - let img_file = Cz1Image::decode(&mut input).unwrap(); - - img_file.save_as_cz("test1.cz1").unwrap(); - img_file.save_as_png("test1.png").unwrap(); -}