Use wrapping macro

This commit is contained in:
2025-06-30 10:22:28 +08:00
parent ebcce0b741
commit aafa03db02
3 changed files with 24 additions and 5 deletions

12
Cargo.lock generated
View File

@@ -323,6 +323,7 @@ dependencies = [
"int-enum",
"lazy_static",
"msg_tool_macro",
"overf",
"png",
"rand",
"serde",
@@ -345,6 +346,17 @@ version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "overf"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63f45a6333db8b6985d6648e4f6c7f2aa814c660c0855c6f58ff67fea8b9f24b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "png"
version = "0.17.16"

View File

@@ -13,6 +13,7 @@ flate2 = { version = "1.1", optional = true }
int-enum = { version = "1.2", optional = true }
lazy_static = "1.5.0"
msg_tool_macro = { path = "./msg_tool_macro" }
overf = "0.1"
png = { version = "0.17", optional = true }
rand = { version = "0.9", optional = true }
serde = { version = "1", features = ["derive"] }

View File

@@ -7,6 +7,7 @@ use crate::utils::struct_pack::*;
use anyhow::Result;
use flate2::{Decompress, FlushDecompress};
use msg_tool_macro::*;
use overf::wrapping;
use std::io::{Read, Seek, Write};
#[derive(Debug)]
@@ -205,7 +206,7 @@ impl<'a, T: Iterator<Item = &'a (Hg3Entry, usize, usize)> + 'a> Iterator for Hg3
name: format!("{:04}", self.index - 1),
data: img,
}))
},
}
Err(e) => Some(Err(e)),
}
} else {
@@ -324,15 +325,20 @@ impl<'a> Hg3Reader<'a> {
}
let stride = self.m_info.width * self.m_pixel_size;
for x in self.m_pixel_size..stride {
output[x as usize] =
output[x as usize].wrapping_add(output[x as usize - self.m_pixel_size as usize]);
let target = x as usize - self.m_pixel_size as usize;
wrapping! {
output[x as usize] += output[target];
}
}
let mut prev = 0;
for _ in 1..self.m_info.height {
let line = prev + stride;
for x in 0..stride {
output[line as usize + x as usize] = output[line as usize + x as usize]
.wrapping_add(output[prev as usize + x as usize]);
let src = line as usize + x as usize;
let target = prev as usize + x as usize;
wrapping! {
output[src] += output[target];
}
}
prev = line;
}