Fix directional alpha reductions (#458)
* Fix alpha up and down * Fix alpha left and right
This commit is contained in:
parent
8396a262c3
commit
a02d4ff0dd
1 changed files with 6 additions and 4 deletions
|
|
@ -108,7 +108,7 @@ fn reduced_alpha_to_up(png: &PngImage, bpc: usize, bpp: usize) -> Vec<u8> {
|
||||||
current_line.extend_from_slice(pixel);
|
current_line.extend_from_slice(pixel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
last_line = current_line.clone();
|
last_line = current_line[1..current_line.len()].to_vec();
|
||||||
lines.push(current_line.clone());
|
lines.push(current_line.clone());
|
||||||
current_line.clear();
|
current_line.clear();
|
||||||
}
|
}
|
||||||
|
|
@ -118,6 +118,7 @@ fn reduced_alpha_to_up(png: &PngImage, bpc: usize, bpp: usize) -> Vec<u8> {
|
||||||
fn reduced_alpha_to_down(png: &PngImage, bpc: usize, bpp: usize) -> Vec<u8> {
|
fn reduced_alpha_to_down(png: &PngImage, bpc: usize, bpp: usize) -> Vec<u8> {
|
||||||
let mut reduced = Vec::with_capacity(png.data.len());
|
let mut reduced = Vec::with_capacity(png.data.len());
|
||||||
let mut last_line = Vec::new();
|
let mut last_line = Vec::new();
|
||||||
|
let mut pos = 0;
|
||||||
for line in png.scan_lines() {
|
for line in png.scan_lines() {
|
||||||
if line.data.len() != last_line.len() {
|
if line.data.len() != last_line.len() {
|
||||||
last_line = vec![0; line.data.len()];
|
last_line = vec![0; line.data.len()];
|
||||||
|
|
@ -131,7 +132,8 @@ fn reduced_alpha_to_down(png: &PngImage, bpc: usize, bpp: usize) -> Vec<u8> {
|
||||||
reduced.extend_from_slice(pixel);
|
reduced.extend_from_slice(pixel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
last_line = reduced.clone();
|
last_line = reduced[(pos + 1)..reduced.len()].to_vec();
|
||||||
|
pos = reduced.len();
|
||||||
}
|
}
|
||||||
reduced
|
reduced
|
||||||
}
|
}
|
||||||
|
|
@ -147,8 +149,8 @@ fn reduced_alpha_to_left(png: &PngImage, bpc: usize, bpp: usize) -> Vec<u8> {
|
||||||
line_bytes.resize(line_bytes.len() + bpc, 0);
|
line_bytes.resize(line_bytes.len() + bpc, 0);
|
||||||
} else {
|
} else {
|
||||||
line_bytes.extend_from_slice(pixel);
|
line_bytes.extend_from_slice(pixel);
|
||||||
|
last_pixel = pixel.to_owned();
|
||||||
}
|
}
|
||||||
last_pixel = pixel.to_owned();
|
|
||||||
}
|
}
|
||||||
reduced.push(line.filter);
|
reduced.push(line.filter);
|
||||||
reduced.extend(line_bytes.chunks(bpp).rev().flatten());
|
reduced.extend(line_bytes.chunks(bpp).rev().flatten());
|
||||||
|
|
@ -167,8 +169,8 @@ fn reduced_alpha_to_right(png: &PngImage, bpc: usize, bpp: usize) -> Vec<u8> {
|
||||||
reduced.resize(reduced.len() + bpc, 0);
|
reduced.resize(reduced.len() + bpc, 0);
|
||||||
} else {
|
} else {
|
||||||
reduced.extend_from_slice(pixel);
|
reduced.extend_from_slice(pixel);
|
||||||
|
last_pixel = pixel.to_owned();
|
||||||
}
|
}
|
||||||
last_pixel = pixel.to_owned();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reduced
|
reduced
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue