mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-07-08 01:31:53 +08:00
Use wrapping macro
This commit is contained in:
12
Cargo.lock
generated
12
Cargo.lock
generated
@@ -323,6 +323,7 @@ dependencies = [
|
|||||||
"int-enum",
|
"int-enum",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"msg_tool_macro",
|
"msg_tool_macro",
|
||||||
|
"overf",
|
||||||
"png",
|
"png",
|
||||||
"rand",
|
"rand",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -345,6 +346,17 @@ version = "1.21.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
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]]
|
[[package]]
|
||||||
name = "png"
|
name = "png"
|
||||||
version = "0.17.16"
|
version = "0.17.16"
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ flate2 = { version = "1.1", optional = true }
|
|||||||
int-enum = { version = "1.2", optional = true }
|
int-enum = { version = "1.2", optional = true }
|
||||||
lazy_static = "1.5.0"
|
lazy_static = "1.5.0"
|
||||||
msg_tool_macro = { path = "./msg_tool_macro" }
|
msg_tool_macro = { path = "./msg_tool_macro" }
|
||||||
|
overf = "0.1"
|
||||||
png = { version = "0.17", optional = true }
|
png = { version = "0.17", optional = true }
|
||||||
rand = { version = "0.9", optional = true }
|
rand = { version = "0.9", optional = true }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use crate::utils::struct_pack::*;
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use flate2::{Decompress, FlushDecompress};
|
use flate2::{Decompress, FlushDecompress};
|
||||||
use msg_tool_macro::*;
|
use msg_tool_macro::*;
|
||||||
|
use overf::wrapping;
|
||||||
use std::io::{Read, Seek, Write};
|
use std::io::{Read, Seek, Write};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[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),
|
name: format!("{:04}", self.index - 1),
|
||||||
data: img,
|
data: img,
|
||||||
}))
|
}))
|
||||||
},
|
}
|
||||||
Err(e) => Some(Err(e)),
|
Err(e) => Some(Err(e)),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -324,15 +325,20 @@ impl<'a> Hg3Reader<'a> {
|
|||||||
}
|
}
|
||||||
let stride = self.m_info.width * self.m_pixel_size;
|
let stride = self.m_info.width * self.m_pixel_size;
|
||||||
for x in self.m_pixel_size..stride {
|
for x in self.m_pixel_size..stride {
|
||||||
output[x as usize] =
|
let target = x as usize - self.m_pixel_size as usize;
|
||||||
output[x as usize].wrapping_add(output[x as usize - self.m_pixel_size as usize]);
|
wrapping! {
|
||||||
|
output[x as usize] += output[target];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let mut prev = 0;
|
let mut prev = 0;
|
||||||
for _ in 1..self.m_info.height {
|
for _ in 1..self.m_info.height {
|
||||||
let line = prev + stride;
|
let line = prev + stride;
|
||||||
for x in 0..stride {
|
for x in 0..stride {
|
||||||
output[line as usize + x as usize] = output[line as usize + x as usize]
|
let src = line as usize + x as usize;
|
||||||
.wrapping_add(output[prev as usize + x as usize]);
|
let target = prev as usize + x as usize;
|
||||||
|
wrapping! {
|
||||||
|
output[src] += output[target];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
prev = line;
|
prev = line;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user