mirror of
https://github.com/lifegpc/libtlg-rs.git
synced 2026-06-09 15:29:25 +08:00
features(libtlg-rs): Add tlg5 grayscale decode support
This commit is contained in:
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -164,7 +164,7 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||
|
||||
[[package]]
|
||||
name = "libtlg-rs"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"overf",
|
||||
@@ -253,7 +253,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tlg"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"libtlg-rs",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "libtlg-rs"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
description = "Rust version of libtlg"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
|
||||
@@ -12,6 +12,7 @@ fn load_tlg5<T: Read + Seek>(src: &mut T) -> Result<Tlg> {
|
||||
let color = match colors {
|
||||
3 => TlgColorType::Bgr24,
|
||||
4 => TlgColorType::Bgra32,
|
||||
1 => TlgColorType::Grayscale8,
|
||||
_ => return Err(TlgError::UnsupportedColorType(colors)),
|
||||
};
|
||||
let blockcount = ((height - 1) / blockheight) + 1;
|
||||
@@ -62,7 +63,10 @@ fn load_tlg5<T: Read + Seek>(src: &mut T) -> Result<Tlg> {
|
||||
outbufp[2] = &outbufp[2][width as usize..];
|
||||
outbufp[3] = &outbufp[3][width as usize..];
|
||||
}
|
||||
_ => {}
|
||||
TlgColorType::Grayscale8 => {
|
||||
tlg5_compose_colors1(current, &prev, &outbufp, width);
|
||||
outbufp[0] = &outbufp[0][width as usize..];
|
||||
}
|
||||
},
|
||||
None => match color {
|
||||
TlgColorType::Bgra32 => {
|
||||
@@ -125,7 +129,19 @@ fn load_tlg5<T: Read + Seek>(src: &mut T) -> Result<Tlg> {
|
||||
outbufp[1] = &outbufp[1][width as usize..];
|
||||
outbufp[2] = &outbufp[2][width as usize..];
|
||||
}
|
||||
_ => {}
|
||||
TlgColorType::Grayscale8 => {
|
||||
let mut current_pos = 0usize;
|
||||
let mut pb = 0u8;
|
||||
for x in 0..width as usize {
|
||||
let b = outbufp[0][x];
|
||||
wrapping! {
|
||||
pb += b;
|
||||
}
|
||||
current[current_pos] = pb;
|
||||
current_pos += 1;
|
||||
}
|
||||
outbufp[0] = &outbufp[0][width as usize..];
|
||||
}
|
||||
},
|
||||
}
|
||||
prevline = Some(current.to_vec());
|
||||
|
||||
@@ -54,6 +54,19 @@ fn tlg6_init_golomb_table() -> [[i8; TLG6_GOLOMB_N_COUNT]; TLG6_GLOBMB_TABLE_SIZ
|
||||
table
|
||||
}
|
||||
|
||||
pub fn tlg5_compose_colors1(outp: &mut [u8], upper: &[u8], buf: &[&[u8]], width: u32) {
|
||||
let mut outpos = 0usize;
|
||||
let mut upper_pos = 0usize;
|
||||
let mut pb = 0u8;
|
||||
for x in 0..width as usize {
|
||||
let b = buf[0][x];
|
||||
wrapping! { pb += b };
|
||||
outp[outpos] = wrapping! { pb + upper[upper_pos]};
|
||||
outpos += 1;
|
||||
upper_pos += 1;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tlg5_compose_colors3(outp: &mut [u8], upper: &[u8], buf: &[&[u8]], width: u32) {
|
||||
let mut outpos = 0usize;
|
||||
let mut upper_pos = 0usize;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tlg"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
description = "Tools to process TLG image file."
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
|
||||
Reference in New Issue
Block a user