This commit is contained in:
Joe Ardent 2025-09-05 12:42:25 -07:00
parent ea3c4e89e0
commit d51a2dd5f4
2 changed files with 7 additions and 6 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
/target
*.tga

View file

@ -321,7 +321,7 @@ impl TGAImage {
let mut current_byte = current_pixel * bpp;
let mut run_length = 1;
let mut raw = true;
let mut is_raw = true;
while (current_pixel + run_length) < num_pixels && run_length < max_chunk_len {
let mut succ_eq = true;
@ -332,26 +332,26 @@ impl TGAImage {
}
current_byte += bpp;
if 1 == run_length {
raw = !succ_eq;
is_raw = !succ_eq;
}
if raw && succ_eq {
if is_raw && succ_eq {
run_length -= 1;
break;
}
if !(raw || succ_eq) {
if !(is_raw || succ_eq) {
break;
}
run_length += 1;
}
current_pixel += run_length;
let mut out = if raw {
let mut out = if is_raw {
[run_length as u8 - 1]
} else {
[run_length as u8 + 127]
};
file.write_all(&mut out)?;
let chunk_end = chunk_start + if raw { run_length * bpp } else { bpp };
let chunk_end = chunk_start + if is_raw { run_length * bpp } else { bpp };
file.write_all(&mut self.data[chunk_start..chunk_end])?;
}