Restructured repository as workspace

This commit is contained in:
G2-Games 2024-05-04 15:57:11 -05:00
parent d5ae80005e
commit 64c1ee6e91
9 changed files with 37 additions and 45 deletions

View file

@ -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",
]

9
cz/Cargo.toml Normal file
View file

@ -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"

View file

@ -140,7 +140,7 @@ impl CzImage for Cz0Image {
fn decode<T: Seek + ReadBytesExt + Read>(bytes: &mut T) -> Result<Self, CzError> {
// 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![];

View file

@ -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<T: Seek + ReadBytesExt + Read>(bytes: &mut T) -> Result<Self, CzError> {
// 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(())
}

View file

@ -110,7 +110,7 @@ impl CzImage for Cz3Image {
fn decode<T: Seek + ReadBytesExt + Read>(bytes: &mut T) -> Result<Self, CzError> {
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)?;

14
cz/src/lib.rs Normal file
View file

@ -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;

View file

@ -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();
}