tweak
This commit is contained in:
parent
ea3c4e89e0
commit
d51a2dd5f4
2 changed files with 7 additions and 6 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
/target
|
/target
|
||||||
|
*.tga
|
||||||
|
|
12
src/tga.rs
12
src/tga.rs
|
@ -321,7 +321,7 @@ impl TGAImage {
|
||||||
let mut current_byte = current_pixel * bpp;
|
let mut current_byte = current_pixel * bpp;
|
||||||
|
|
||||||
let mut run_length = 1;
|
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 {
|
while (current_pixel + run_length) < num_pixels && run_length < max_chunk_len {
|
||||||
let mut succ_eq = true;
|
let mut succ_eq = true;
|
||||||
|
@ -332,26 +332,26 @@ impl TGAImage {
|
||||||
}
|
}
|
||||||
current_byte += bpp;
|
current_byte += bpp;
|
||||||
if 1 == run_length {
|
if 1 == run_length {
|
||||||
raw = !succ_eq;
|
is_raw = !succ_eq;
|
||||||
}
|
}
|
||||||
if raw && succ_eq {
|
if is_raw && succ_eq {
|
||||||
run_length -= 1;
|
run_length -= 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if !(raw || succ_eq) {
|
if !(is_raw || succ_eq) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
run_length += 1;
|
run_length += 1;
|
||||||
}
|
}
|
||||||
current_pixel += run_length;
|
current_pixel += run_length;
|
||||||
let mut out = if raw {
|
let mut out = if is_raw {
|
||||||
[run_length as u8 - 1]
|
[run_length as u8 - 1]
|
||||||
} else {
|
} else {
|
||||||
[run_length as u8 + 127]
|
[run_length as u8 + 127]
|
||||||
};
|
};
|
||||||
|
|
||||||
file.write_all(&mut out)?;
|
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])?;
|
file.write_all(&mut self.data[chunk_start..chunk_end])?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue