Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
76c29fd
Add load_meta, skipping all image parsing
itsmeow Jul 30, 2025
ba9b04a
oh clippy, spare me
itsmeow Jul 30, 2025
946a2eb
Rewrite load to not duplicate code. Add support for width/height bein…
itsmeow Jul 30, 2025
f4dc9a4
Remove debug statements
itsmeow Jul 30, 2025
c1827aa
Woops I was not using load_meta
itsmeow Jul 30, 2025
50cfe93
Fix logic error
itsmeow Jul 30, 2025
b9fa681
Format
itsmeow Jul 30, 2025
e299679
Minor code improvements
itsmeow Aug 1, 2025
208cf78
Reduce allocations for load_meta
itsmeow Aug 1, 2025
56d71df
Use == instead of contains
itsmeow Aug 1, 2025
8f76ab3
clippy
itsmeow Aug 1, 2025
f3e8f0f
Fix ability to read quotes and backslashes in icon state names, inclu…
itsmeow Aug 1, 2025
4179421
clippy + format
itsmeow Aug 1, 2025
b80a6d9
Improve the comment
itsmeow Aug 1, 2025
a7abfbb
Move read_dmi_headers off Icon impl
itsmeow Aug 1, 2025
3945d84
Speed up by returning the key as a borrowed slice
itsmeow Aug 1, 2025
7065a5e
clippy + fmt + microop
itsmeow Aug 1, 2025
08826e9
Update example benchmark to be more useful to others
itsmeow Aug 1, 2025
36bc2f9
Super mega fast image crop by doing direct PNG decoding
itsmeow Aug 1, 2025
7f866af
fmt
itsmeow Aug 1, 2025
b4e230e
Update bench_dmi_load.rs (lol)
itsmeow Aug 1, 2025
481fd33
Improve the readability of RawDmi buffer writing and add output_size_…
itsmeow Aug 2, 2025
fee48e5
BEGGONNE WRITTER
itsmeow Aug 2, 2025
031fb79
Minor load_meta optimizations and readability improvement
itsmeow Aug 2, 2025
3276276
Remove unused bench
itsmeow Aug 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
Cargo.lock
tests/resources/save_test.dmi
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ crc32fast = "1"
deflate = "1"
image = { version = "0.25", default-features = false, features = ["png"] }
inflate = "0.4"
png = "0.17.16"
thiserror = "2"
32 changes: 14 additions & 18 deletions src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl RawGenericChunk {
let chunk_length = chunk_bytes.len();

if chunk_length < 12 {
return Err(error::DmiError::Generic(format!("Failed to load Chunk. Supplied reader contained size of {} bytes, lower than the required 12.", chunk_length)));
return Err(error::DmiError::Generic(format!("Failed to load Chunk. Supplied reader contained size of {chunk_length} bytes, lower than the required 12.")));
};

let data_length = [
Expand All @@ -46,8 +46,7 @@ impl RawGenericChunk {
.all(|c| (b'A' <= *c && *c <= b'Z') || (b'a' <= *c && *c <= b'z'))
{
return Err(error::DmiError::Generic(format!(
"Failed to load Chunk. Type contained unlawful characters: {:#?}",
chunk_type
"Failed to load Chunk. Type contained unlawful characters: {chunk_type:#?}",
)));
};

Expand All @@ -61,9 +60,10 @@ impl RawGenericChunk {
];

let recalculated_crc = crc::calculate_chunk_data_crc(chunk_type, &data);
if u32::from_be_bytes(crc) != recalculated_crc {
let crc_le = u32::from_be_bytes(crc);
if crc_le != recalculated_crc {
let chunk_name = String::from_utf8(chunk_type.to_vec())?;
return Err(error::DmiError::Generic(format!("Failed to load Chunk of type {}. Supplied CRC invalid: {:#?}. Its value ({}) does not match the recalculated one ({}).", chunk_name, crc, u32::from_be_bytes(crc), recalculated_crc)));
return Err(error::DmiError::Generic(format!("Failed to load Chunk of type {chunk_name}. Supplied CRC invalid: {crc:#?}. Its value ({crc_le}) does not match the recalculated one ({recalculated_crc}).")));
}

Ok(RawGenericChunk {
Expand All @@ -74,40 +74,36 @@ impl RawGenericChunk {
})
}

pub fn save<W: Write>(&self, writter: &mut W) -> Result<usize, error::DmiError> {
let bytes_written = writter.write(&self.data_length)?;
pub fn save<W: Write>(&self, writer: &mut W) -> Result<usize, error::DmiError> {
let bytes_written = writer.write(&self.data_length)?;
let mut total_bytes_written = bytes_written;
if bytes_written < self.data_length.len() {
return Err(error::DmiError::Generic(format!(
"Failed to save Chunk. Buffer unable to hold the data, only {} bytes written.",
total_bytes_written
"Failed to save Chunk. Buffer unable to hold the data, only {total_bytes_written} bytes written."
)));
};

let bytes_written = writter.write(&self.chunk_type)?;
let bytes_written = writer.write(&self.chunk_type)?;
total_bytes_written += bytes_written;
if bytes_written < self.chunk_type.len() {
return Err(error::DmiError::Generic(format!(
"Failed to save Chunk. Buffer unable to hold the data, only {} bytes written.",
total_bytes_written
"Failed to save Chunk. Buffer unable to hold the data, only {total_bytes_written} bytes written."
)));
};

let bytes_written = writter.write(&self.data)?;
let bytes_written = writer.write(&self.data)?;
total_bytes_written += bytes_written;
if bytes_written < self.data.len() {
return Err(error::DmiError::Generic(format!(
"Failed to save Chunk. Buffer unable to hold the data, only {} bytes written.",
total_bytes_written
"Failed to save Chunk. Buffer unable to hold the data, only {total_bytes_written} bytes written."
)));
};

let bytes_written = writter.write(&self.crc)?;
let bytes_written = writer.write(&self.crc)?;
total_bytes_written += bytes_written;
if bytes_written < self.crc.len() {
return Err(error::DmiError::Generic(format!(
"Failed to save Chunk. Buffer unable to hold the data, only {} bytes written.",
total_bytes_written
"Failed to save Chunk. Buffer unable to hold the data, only {total_bytes_written} bytes written."
)));
};

Expand Down
5 changes: 5 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use png::DecodingError;
use std::io;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum DmiError {
#[error("IO error: {0}")]
Io(#[from] io::Error),
#[error("PNG decoding error: {0}")]
PngDecoding(#[from] DecodingError),
#[error("Image-processing error: {0}")]
Image(#[from] image::error::ImageError),
#[error("FromUtf8 error: {0}")]
Expand All @@ -19,6 +22,8 @@ pub enum DmiError {
CrcMismatch { stated: u32, calculated: u32 },
#[error("Dmi error: {0}")]
Generic(String),
#[error("Dmi block entry error: {0}")]
BlockEntry(String),
#[error("Dmi IconState error: {0}")]
IconState(String),
#[error("Encoding error: {0}")]
Expand Down
Loading
Loading