diff --git a/cz/Cargo.toml b/cz/Cargo.toml index 9ad7a88..4b68c79 100644 --- a/cz/Cargo.toml +++ b/cz/Cargo.toml @@ -13,7 +13,7 @@ authors.workspace = true png = ["dep:image"] [dependencies] -byteorder = "1.5" +byteorder-lite = "0.1.0" thiserror = "1.0" imagequant = "4.3" rgb = "0.8" diff --git a/cz/src/color.rs b/cz/src/color.rs index 0fc953e..c9fc227 100644 --- a/cz/src/color.rs +++ b/cz/src/color.rs @@ -1,4 +1,3 @@ -use byteorder::ReadBytesExt; use imagequant::Attributes; use rgb::{ComponentSlice, RGBA8}; use std::{ @@ -35,10 +34,7 @@ impl Palette { } /// Get a palette from the input stream, beginning where the palette starts. -pub fn get_palette( - input: &mut T, - num_colors: usize, -) -> Result { +pub fn get_palette(input: &mut T, num_colors: usize) -> Result { let mut colormap = Vec::with_capacity(num_colors); let mut rgba_buf = [0u8; 4]; diff --git a/cz/src/common.rs b/cz/src/common.rs index 1d8a0bb..e12ba67 100644 --- a/cz/src/common.rs +++ b/cz/src/common.rs @@ -2,7 +2,7 @@ use std::io::{self, Read, Seek, Write}; -use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; +use byteorder_lite::{ReadBytesExt, WriteBytesExt, LE}; use thiserror::Error; #[derive(Error, Debug)] @@ -132,10 +132,10 @@ impl CommonHeader { let mut header = Self { version, - length: bytes.read_u32::()?, - width: bytes.read_u16::()?, - height: bytes.read_u16::()?, - depth: bytes.read_u16::()?, + length: bytes.read_u32::()?, + width: bytes.read_u16::()?, + height: bytes.read_u16::()?, + depth: bytes.read_u16::()?, unknown: bytes.read_u8()?, }; @@ -204,10 +204,10 @@ impl CommonHeader { let magic_bytes = [b'C', b'Z', b'0' + self.version as u8, b'\0']; output.write_all(&magic_bytes)?; - output.write_u32::(self.length() as u32)?; - output.write_u16::(self.width())?; - output.write_u16::(self.height())?; - output.write_u16::(self.depth())?; + output.write_u32::(self.length() as u32)?; + output.write_u16::(self.width())?; + output.write_u16::(self.height())?; + output.write_u16::(self.depth())?; output.write_u8(self.color_block())?; Ok(()) @@ -282,27 +282,27 @@ impl ExtendedHeader { self } - pub fn from_bytes( + pub fn from_bytes( input: &mut T, common_header: &CommonHeader, ) -> Result { let mut unknown_1 = [0u8; 5]; input.read_exact(&mut unknown_1)?; - let crop_width = input.read_u16::()?; - let crop_height = input.read_u16::()?; + let crop_width = input.read_u16::()?; + let crop_height = input.read_u16::()?; - let bounds_width = input.read_u16::()?; - let bounds_height = input.read_u16::()?; + let bounds_width = input.read_u16::()?; + let bounds_height = input.read_u16::()?; let mut offset_width = None; let mut offset_height = None; let mut unknown_2 = None; if common_header.length() > 28 { - offset_width = Some(input.read_u16::()?); - offset_height = Some(input.read_u16::()?); + offset_width = Some(input.read_u16::()?); + offset_height = Some(input.read_u16::()?); - unknown_2 = Some(input.read_u32::()?); + unknown_2 = Some(input.read_u32::()?); } Ok(Self { @@ -321,17 +321,17 @@ impl ExtendedHeader { }) } - pub fn write_into(&self, output: &mut T) -> Result<(), io::Error> { + pub fn write_into(&self, output: &mut T) -> Result<(), io::Error> { output.write_all(&self.unknown_1)?; - output.write_u16::(self.crop_width)?; - output.write_u16::(self.crop_height)?; - output.write_u16::(self.bounds_width)?; - output.write_u16::(self.bounds_height)?; + output.write_u16::(self.crop_width)?; + output.write_u16::(self.crop_height)?; + output.write_u16::(self.bounds_width)?; + output.write_u16::(self.bounds_height)?; if self.offset_width.is_some() { - output.write_u16::(self.offset_width.unwrap())?; - output.write_u16::(self.offset_height.unwrap())?; - output.write_u32::(self.unknown_2.unwrap())?; + output.write_u16::(self.offset_width.unwrap())?; + output.write_u16::(self.offset_height.unwrap())?; + output.write_u32::(self.unknown_2.unwrap())?; } Ok(()) diff --git a/cz/src/compression.rs b/cz/src/compression.rs index 80cf2fd..87982dd 100644 --- a/cz/src/compression.rs +++ b/cz/src/compression.rs @@ -1,4 +1,3 @@ -use byteorder::{ReadBytesExt, WriteBytesExt, LE}; use std::{ collections::HashMap, io::{Read, Seek, Write}, @@ -6,6 +5,7 @@ use std::{ use crate::binio::BitIo; use crate::common::CzError; +use byteorder_lite::{ReadBytesExt, WriteBytesExt, LE}; /// The size of compressed data in each chunk #[derive(Debug, Clone, Copy)] @@ -37,10 +37,7 @@ pub struct CompressionInfo { } impl CompressionInfo { - pub fn write_into( - &self, - output: &mut T, - ) -> Result<(), std::io::Error> { + pub fn write_into(&self, output: &mut T) -> Result<(), std::io::Error> { output.write_u32::(self.chunk_count as u32)?; for chunk in &self.chunks { @@ -56,9 +53,7 @@ impl CompressionInfo { /// /// These are defined by a length value, followed by the number of data chunks /// that length value says split into compressed and original size u32 values -pub fn get_chunk_info( - bytes: &mut T, -) -> Result { +pub fn get_chunk_info(bytes: &mut T) -> Result { let parts_count = bytes.read_u32::()?; let mut part_sizes = vec![]; @@ -89,7 +84,7 @@ pub fn get_chunk_info( } /// Decompress an LZW compressed stream like CZ1 -pub fn decompress( +pub fn decompress( input: &mut T, chunk_info: &CompressionInfo, ) -> Result, CzError> { @@ -144,7 +139,7 @@ fn decompress_lzw(input_data: &[u16], size: usize) -> Vec { } /// Decompress an LZW compressed stream like CZ2 -pub fn decompress2( +pub fn decompress2( input: &mut T, chunk_info: &CompressionInfo, ) -> Result, CzError> { @@ -196,7 +191,11 @@ fn decompress_lzw2(input_data: &[u8], size: usize) -> Vec { entry = w.clone(); entry.push(w[0]) } else { - panic!("Bad compressed element {} at offset {}", element, bit_io.byte_offset()) + panic!( + "Bad compressed element {} at offset {}", + element, + bit_io.byte_offset() + ) } //println!("{}", element); diff --git a/cz/src/dynamic.rs b/cz/src/dynamic.rs index 3e37f89..ca9f759 100644 --- a/cz/src/dynamic.rs +++ b/cz/src/dynamic.rs @@ -1,4 +1,4 @@ -use byteorder::ReadBytesExt; +use byteorder_lite::ReadBytesExt; use rgb::ComponentSlice; use std::{ fs::File, diff --git a/cz/src/formats/cz0.rs b/cz/src/formats/cz0.rs index a836f61..69c70c3 100644 --- a/cz/src/formats/cz0.rs +++ b/cz/src/formats/cz0.rs @@ -1,9 +1,8 @@ -use byteorder::{ReadBytesExt, WriteBytesExt}; use std::io::{Read, Seek, Write}; use crate::common::CzError; -pub fn decode(input: &mut T) -> Result, CzError> { +pub fn decode(input: &mut T) -> Result, CzError> { // Get the rest of the file, which is the bitmap let mut bitmap = vec![]; input.read_to_end(&mut bitmap)?; @@ -11,7 +10,7 @@ pub fn decode(input: &mut T) -> Result, C Ok(bitmap) } -pub fn encode(output: &mut T, bitmap: &[u8]) -> Result<(), CzError> { +pub fn encode(output: &mut T, bitmap: &[u8]) -> Result<(), CzError> { output.write_all(bitmap)?; Ok(()) diff --git a/cz/src/formats/cz1.rs b/cz/src/formats/cz1.rs index 520b076..72de9d8 100644 --- a/cz/src/formats/cz1.rs +++ b/cz/src/formats/cz1.rs @@ -1,10 +1,9 @@ -use byteorder::{ReadBytesExt, WriteBytesExt}; use std::io::{Read, Seek, SeekFrom, Write}; use crate::common::CzError; use crate::compression::{compress, decompress, get_chunk_info}; -pub fn decode(bytes: &mut T) -> Result, CzError> { +pub fn decode(bytes: &mut T) -> Result, CzError> { // Get information about the compressed chunks let block_info = get_chunk_info(bytes)?; bytes.seek(SeekFrom::Start(block_info.length as u64))?; @@ -15,7 +14,7 @@ pub fn decode(bytes: &mut T) -> Result, C Ok(bitmap) } -pub fn encode(output: &mut T, bitmap: &[u8]) -> Result<(), CzError> { +pub fn encode(output: &mut T, bitmap: &[u8]) -> Result<(), CzError> { let (compressed_data, compressed_info) = compress(bitmap, 0xFEFD); compressed_info.write_into(output)?; diff --git a/cz/src/formats/cz2.rs b/cz/src/formats/cz2.rs index 047314c..451f79b 100644 --- a/cz/src/formats/cz2.rs +++ b/cz/src/formats/cz2.rs @@ -1,10 +1,9 @@ -use byteorder::{ReadBytesExt, WriteBytesExt}; use std::io::{Read, Seek, SeekFrom, Write}; use crate::common::CzError; use crate::compression::{compress2, decompress2, get_chunk_info}; -pub fn decode(bytes: &mut T) -> Result, CzError> { +pub fn decode(bytes: &mut T) -> Result, CzError> { // Get information about the compressed chunks let block_info = get_chunk_info(bytes)?; bytes.seek(SeekFrom::Start(block_info.length as u64))?; @@ -15,7 +14,7 @@ pub fn decode(bytes: &mut T) -> Result, C Ok(bitmap) } -pub fn encode(output: &mut T, bitmap: &[u8]) -> Result<(), CzError> { +pub fn encode(output: &mut T, bitmap: &[u8]) -> Result<(), CzError> { let (compressed_data, compressed_info) = compress2(&bitmap); compressed_info.write_into(output)?; diff --git a/cz/src/formats/cz3.rs b/cz/src/formats/cz3.rs index 7ca7038..55d789a 100644 --- a/cz/src/formats/cz3.rs +++ b/cz/src/formats/cz3.rs @@ -1,13 +1,9 @@ -use byteorder::{ReadBytesExt, WriteBytesExt}; use std::io::{Read, Seek, SeekFrom, Write}; use crate::common::{CommonHeader, CzError}; use crate::compression::{compress, decompress, get_chunk_info}; -pub fn decode( - bytes: &mut T, - header: &CommonHeader, -) -> Result, CzError> { +pub fn decode(bytes: &mut T, header: &CommonHeader) -> Result, CzError> { let block_info = get_chunk_info(bytes)?; bytes.seek(SeekFrom::Start(block_info.length as u64))?; @@ -18,7 +14,7 @@ pub fn decode( Ok(bitmap) } -pub fn encode( +pub fn encode( output: &mut T, bitmap: &[u8], header: &CommonHeader, diff --git a/cz/src/formats/cz4.rs b/cz/src/formats/cz4.rs index e3e6276..ad096c1 100644 --- a/cz/src/formats/cz4.rs +++ b/cz/src/formats/cz4.rs @@ -1,13 +1,9 @@ -use byteorder::{ReadBytesExt, WriteBytesExt}; use std::io::{Read, Seek, SeekFrom, Write}; use crate::common::{CommonHeader, CzError}; use crate::compression::{compress, decompress, get_chunk_info}; -pub fn decode( - bytes: &mut T, - header: &CommonHeader, -) -> Result, CzError> { +pub fn decode(bytes: &mut T, header: &CommonHeader) -> Result, CzError> { let block_info = get_chunk_info(bytes)?; bytes.seek(SeekFrom::Start(block_info.length as u64))?; @@ -18,7 +14,7 @@ pub fn decode( Ok(bitmap) } -pub fn encode( +pub fn encode( output: &mut T, bitmap: &[u8], header: &CommonHeader, diff --git a/cz/tests/round_trip.rs b/cz/tests/round_trip.rs index 2816a77..86774ea 100644 --- a/cz/tests/round_trip.rs +++ b/cz/tests/round_trip.rs @@ -13,12 +13,7 @@ const TEST_IMAGES: &[TestImage] = &[KODIM03, KODIM23, SQPTEXT, DPFLOGO]; #[test] fn cz0_round_trip() { for image in TEST_IMAGES { - let original_cz = DynamicCz::from_raw( - CzVersion::CZ0, - image.0, - image.1, - image.2.to_vec() - ); + let original_cz = DynamicCz::from_raw(CzVersion::CZ0, image.0, image.1, image.2.to_vec()); let mut cz_bytes = Vec::new(); original_cz.encode(&mut cz_bytes).unwrap(); @@ -33,12 +28,7 @@ fn cz0_round_trip() { #[test] fn cz1_round_trip() { for image in TEST_IMAGES { - let original_cz = DynamicCz::from_raw( - CzVersion::CZ1, - image.0, - image.1, - image.2.to_vec() - ); + let original_cz = DynamicCz::from_raw(CzVersion::CZ1, image.0, image.1, image.2.to_vec()); let mut cz_bytes = Vec::new(); original_cz.encode(&mut cz_bytes).unwrap(); @@ -54,12 +44,7 @@ fn cz1_round_trip() { fn cz2_round_trip() { let mut i = 0; for image in TEST_IMAGES { - let original_cz = DynamicCz::from_raw( - CzVersion::CZ2, - image.0, - image.1, - image.2.to_vec() - ); + let original_cz = DynamicCz::from_raw(CzVersion::CZ2, image.0, image.1, image.2.to_vec()); let mut cz_bytes = Vec::new(); original_cz.encode(&mut cz_bytes).unwrap(); @@ -76,12 +61,7 @@ fn cz2_round_trip() { #[test] fn cz3_round_trip() { for image in TEST_IMAGES { - let original_cz = DynamicCz::from_raw( - CzVersion::CZ3, - image.0, - image.1, - image.2.to_vec() - ); + let original_cz = DynamicCz::from_raw(CzVersion::CZ3, image.0, image.1, image.2.to_vec()); let mut cz_bytes = Vec::new(); original_cz.encode(&mut cz_bytes).unwrap(); @@ -96,12 +76,7 @@ fn cz3_round_trip() { #[test] fn cz4_round_trip() { for image in TEST_IMAGES { - let original_cz = DynamicCz::from_raw( - CzVersion::CZ4, - image.0, - image.1, - image.2.to_vec() - ); + let original_cz = DynamicCz::from_raw(CzVersion::CZ4, image.0, image.1, image.2.to_vec()); let mut cz_bytes = Vec::new(); original_cz.encode(&mut cz_bytes).unwrap(); diff --git a/luca_pak/src/lib.rs b/luca_pak/src/lib.rs index 8f569ca..25ab642 100644 --- a/luca_pak/src/lib.rs +++ b/luca_pak/src/lib.rs @@ -66,7 +66,7 @@ pub struct PakLimits { impl Default for PakLimits { fn default() -> Self { Self { - entry_limit: 10_000, // 10,000 entries + entry_limit: 10_000, // 10,000 entries size_limit: u32::MAX as usize, // 10 gb } } diff --git a/utils/build.rs b/utils/build.rs index 98d09a2..25c9a37 100644 --- a/utils/build.rs +++ b/utils/build.rs @@ -8,10 +8,16 @@ fn main() { let si = SysinfoBuilder::all_sysinfo().unwrap(); Emitter::default() - .add_instructions(&build).unwrap() - .add_instructions(&cargo).unwrap() - .add_instructions(&git2).unwrap() - .add_instructions(&rustc).unwrap() - .add_instructions(&si).unwrap() - .emit().unwrap(); + .add_instructions(&build) + .unwrap() + .add_instructions(&cargo) + .unwrap() + .add_instructions(&git2) + .unwrap() + .add_instructions(&rustc) + .unwrap() + .add_instructions(&si) + .unwrap() + .emit() + .unwrap(); } diff --git a/utils/src/bin/czutil.rs b/utils/src/bin/czutil.rs index 19ed478..11b4b9e 100644 --- a/utils/src/bin/czutil.rs +++ b/utils/src/bin/czutil.rs @@ -1,7 +1,8 @@ use clap::{error::ErrorKind, Command, Error, Parser, Subcommand}; use std::{ fs, - path::{Path, PathBuf}, process::exit, + path::{Path, PathBuf}, + process::exit, }; /// Utility to maniuplate CZ image files from the LUCA System game engine by diff --git a/utils/src/bin/pakutil.rs b/utils/src/bin/pakutil.rs index 66659b2..bbf1148 100644 --- a/utils/src/bin/pakutil.rs +++ b/utils/src/bin/pakutil.rs @@ -67,9 +67,9 @@ fn main() { println!( "{}, {} v{}-{}", env!("CARGO_BIN_NAME"), - env!("CARGO_PKG_NAME"), - env!("CARGO_PKG_VERSION"), - &env!("VERGEN_GIT_SHA")[0..=6] + env!("CARGO_PKG_NAME"), + env!("CARGO_PKG_VERSION"), + &env!("VERGEN_GIT_SHA")[0..=6] ); exit(0); } @@ -83,7 +83,7 @@ fn main() { Some(c) => c, None => { exit(0); - }, + } }; match command {