mirror of
https://github.com/G2-Games/lbee-utils.git
synced 2025-05-02 13:42:54 -05:00
Formatting and doc fixes
This commit is contained in:
parent
976fffed1f
commit
a1b4b04208
8 changed files with 41 additions and 37 deletions
|
@ -200,11 +200,10 @@ impl CommonHeader {
|
|||
self.unknown
|
||||
}
|
||||
|
||||
pub fn write_into<T: Seek + WriteBytesExt + Write>(
|
||||
pub fn write_into<T: WriteBytesExt + Write>(
|
||||
&self,
|
||||
output: &mut T,
|
||||
) -> Result<usize, io::Error> {
|
||||
let pos = output.stream_position()?;
|
||||
) -> Result<(), io::Error> {
|
||||
let magic_bytes = [b'C', b'Z', b'0' + self.version as u8, b'\0'];
|
||||
|
||||
output.write_all(&magic_bytes)?;
|
||||
|
@ -214,7 +213,7 @@ impl CommonHeader {
|
|||
output.write_u16::<LittleEndian>(self.depth())?;
|
||||
output.write_u8(self.color_block())?;
|
||||
|
||||
Ok((output.stream_position()? - pos) as usize)
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -325,12 +324,10 @@ impl ExtendedHeader {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn write_into<T: Seek + WriteBytesExt + Write>(
|
||||
pub fn write_into<T: WriteBytesExt + Write>(
|
||||
&self,
|
||||
output: &mut T,
|
||||
) -> Result<usize, io::Error> {
|
||||
let pos = output.stream_position()?;
|
||||
|
||||
) -> Result<(), io::Error> {
|
||||
output.write_all(&self.unknown_1)?;
|
||||
output.write_u16::<LittleEndian>(self.crop_width)?;
|
||||
output.write_u16::<LittleEndian>(self.crop_height)?;
|
||||
|
@ -343,6 +340,6 @@ impl ExtendedHeader {
|
|||
output.write_u32::<LittleEndian>(self.unknown_2.unwrap())?;
|
||||
}
|
||||
|
||||
Ok((output.stream_position()? - pos) as usize)
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ pub struct DynamicCz {
|
|||
}
|
||||
|
||||
impl DynamicCz {
|
||||
/// Decode a CZ# file from anything which implements [`Read`] and [`Seek`]
|
||||
/// Decode a CZ# file from anything that implements [`Read`] and [`Seek`]
|
||||
///
|
||||
/// The input must begin with the
|
||||
/// [magic bytes](https://en.wikipedia.org/wiki/File_format#Magic_number)
|
||||
|
@ -117,11 +117,12 @@ impl DynamicCz {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Encode the CZ file into a byte stream.
|
||||
/// Encode a CZ# file into anything that implements [`Write`] and [`Seek`]
|
||||
///
|
||||
/// This encodes everything based on options the header which have been
|
||||
/// set by the user. For example, to change the version of file to be
|
||||
/// saved, use [`CommonHeader::set_version()`]
|
||||
pub fn encode<T: Write + Seek>(
|
||||
pub fn encode<T: Write>(
|
||||
&self,
|
||||
mut output: &mut T
|
||||
) -> Result<(), CzError> {
|
||||
|
|
|
@ -3,7 +3,9 @@ use std::io::{Read, Seek, Write};
|
|||
|
||||
use crate::common::CzError;
|
||||
|
||||
pub fn decode<T: Seek + ReadBytesExt + Read>(input: &mut T) -> Result<Vec<u8>, CzError> {
|
||||
pub fn decode<T: Seek + ReadBytesExt + Read>(
|
||||
input: &mut T
|
||||
) -> Result<Vec<u8>, CzError> {
|
||||
// Get the rest of the file, which is the bitmap
|
||||
let mut bitmap = vec![];
|
||||
input.read_to_end(&mut bitmap)?;
|
||||
|
@ -11,7 +13,10 @@ pub fn decode<T: Seek + ReadBytesExt + Read>(input: &mut T) -> Result<Vec<u8>, C
|
|||
Ok(bitmap)
|
||||
}
|
||||
|
||||
pub fn encode<T: WriteBytesExt + Write>(output: &mut T, bitmap: &[u8]) -> Result<(), CzError> {
|
||||
pub fn encode<T: WriteBytesExt + Write>(
|
||||
output: &mut T,
|
||||
bitmap: &[u8]
|
||||
) -> Result<(), CzError> {
|
||||
output.write_all(bitmap)?;
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -4,7 +4,9 @@ use std::io::{Read, Seek, SeekFrom, Write};
|
|||
use crate::common::CzError;
|
||||
use crate::compression::{compress, decompress, get_chunk_info};
|
||||
|
||||
pub fn decode<T: Seek + ReadBytesExt + Read>(bytes: &mut T) -> Result<Vec<u8>, CzError> {
|
||||
pub fn decode<T: Seek + ReadBytesExt + Read>(
|
||||
bytes: &mut T
|
||||
) -> Result<Vec<u8>, 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 +17,10 @@ pub fn decode<T: Seek + ReadBytesExt + Read>(bytes: &mut T) -> Result<Vec<u8>, C
|
|||
Ok(bitmap)
|
||||
}
|
||||
|
||||
pub fn encode<T: WriteBytesExt + Write>(output: &mut T, bitmap: &[u8]) -> Result<(), CzError> {
|
||||
pub fn encode<T: WriteBytesExt + Write>(
|
||||
output: &mut T,
|
||||
bitmap: &[u8]
|
||||
) -> Result<(), CzError> {
|
||||
let (compressed_data, compressed_info) = compress(bitmap, 0xFEFD);
|
||||
|
||||
compressed_info.write_into(output)?;
|
||||
|
|
|
@ -4,7 +4,9 @@ use std::io::{Read, Seek, SeekFrom, Write};
|
|||
use crate::common::CzError;
|
||||
use crate::compression::{compress2, decompress2, get_chunk_info};
|
||||
|
||||
pub fn decode<T: Seek + ReadBytesExt + Read>(bytes: &mut T) -> Result<Vec<u8>, CzError> {
|
||||
pub fn decode<T: Seek + ReadBytesExt + Read>(
|
||||
bytes: &mut T
|
||||
) -> Result<Vec<u8>, CzError> {
|
||||
// Get information about the compressed chunks
|
||||
let block_info = get_chunk_info(bytes).unwrap();
|
||||
bytes.seek(SeekFrom::Start(block_info.length as u64))?;
|
||||
|
@ -15,7 +17,10 @@ pub fn decode<T: Seek + ReadBytesExt + Read>(bytes: &mut T) -> Result<Vec<u8>, C
|
|||
Ok(bitmap)
|
||||
}
|
||||
|
||||
pub fn encode<T: WriteBytesExt + Write>(output: &mut T, bitmap: &[u8]) -> Result<(), CzError> {
|
||||
pub fn encode<T: WriteBytesExt + Write>(
|
||||
output: &mut T,
|
||||
bitmap: &[u8]
|
||||
) -> Result<(), CzError> {
|
||||
let (compressed_data, compressed_info) = compress2(bitmap, 0x87BDF);
|
||||
|
||||
compressed_info.write_into(output)?;
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use byteorder::{ReadBytesExt, WriteBytesExt};
|
||||
use std::io::{Read, Seek, SeekFrom, Write};
|
||||
use std::time::Instant;
|
||||
|
||||
use crate::common::{CommonHeader, CzError};
|
||||
use crate::common::{CzError, CommonHeader};
|
||||
use crate::compression::{compress, decompress, get_chunk_info};
|
||||
|
||||
pub fn decode<T: Seek + ReadBytesExt + Read>(
|
||||
|
@ -12,13 +11,9 @@ pub fn decode<T: Seek + ReadBytesExt + Read>(
|
|||
let block_info = get_chunk_info(bytes)?;
|
||||
bytes.seek(SeekFrom::Start(block_info.length as u64))?;
|
||||
|
||||
let timer = Instant::now();
|
||||
let bitmap = decompress(bytes, &block_info)?;
|
||||
dbg!(timer.elapsed());
|
||||
let data = decompress(bytes, &block_info)?;
|
||||
|
||||
let timer = Instant::now();
|
||||
let bitmap = line_diff(header, &bitmap);
|
||||
dbg!(timer.elapsed());
|
||||
let bitmap = line_diff(header, &data);
|
||||
|
||||
Ok(bitmap)
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use byteorder::{ReadBytesExt, WriteBytesExt};
|
||||
use std::io::{Read, Seek, SeekFrom, Write};
|
||||
use std::time::Instant;
|
||||
|
||||
use crate::common::{CommonHeader, CzError};
|
||||
use crate::common::{CzError, CommonHeader};
|
||||
use crate::compression::{compress, decompress, get_chunk_info};
|
||||
|
||||
pub fn decode<T: Seek + ReadBytesExt + Read>(
|
||||
|
@ -12,15 +11,11 @@ pub fn decode<T: Seek + ReadBytesExt + Read>(
|
|||
let block_info = get_chunk_info(bytes)?;
|
||||
bytes.seek(SeekFrom::Start(block_info.length as u64))?;
|
||||
|
||||
let timer = Instant::now();
|
||||
let data = decompress(bytes, &block_info)?;
|
||||
dbg!(timer.elapsed());
|
||||
|
||||
let timer = Instant::now();
|
||||
let output = line_diff(header, &data);
|
||||
dbg!(timer.elapsed());
|
||||
let bitmap = line_diff(header, &data);
|
||||
|
||||
Ok(output)
|
||||
Ok(bitmap)
|
||||
}
|
||||
|
||||
pub fn encode<T: WriteBytesExt + Write>(
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
fn main() {
|
||||
let cz_file = cz::open("test_file.cz3").unwrap();
|
||||
let mut cz_file = cz::open("test_file.cz3").unwrap();
|
||||
cz_file.save_as_png("test.png").unwrap();
|
||||
|
||||
cz_file.save_as_png("test_file.png").unwrap();
|
||||
cz_file.header_mut().set_version(3).unwrap();
|
||||
|
||||
cz_file.save_as_cz("test_file.cz").unwrap();
|
||||
cz_file.save_as_cz("test_file.cz2").unwrap();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue