features(libtlg-rs): Add tlg5 grayscale decode support

This commit is contained in:
2025-07-29 09:29:54 +08:00
parent b586a33fda
commit 1a252c05c2
5 changed files with 35 additions and 6 deletions

4
Cargo.lock generated
View File

@@ -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",

View File

@@ -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"

View File

@@ -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());

View File

@@ -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;

View File

@@ -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"