diff --git a/src/reduction/alpha.rs b/src/reduction/alpha.rs index 9190672b..a02f7be2 100644 --- a/src/reduction/alpha.rs +++ b/src/reduction/alpha.rs @@ -108,7 +108,7 @@ fn reduced_alpha_to_up(png: &PngImage, bpc: usize, bpp: usize) -> Vec { 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()); current_line.clear(); } @@ -118,6 +118,7 @@ fn reduced_alpha_to_up(png: &PngImage, bpc: usize, bpp: usize) -> Vec { fn reduced_alpha_to_down(png: &PngImage, bpc: usize, bpp: usize) -> Vec { let mut reduced = Vec::with_capacity(png.data.len()); let mut last_line = Vec::new(); + let mut pos = 0; for line in png.scan_lines() { if line.data.len() != last_line.len() { last_line = vec![0; line.data.len()]; @@ -131,7 +132,8 @@ fn reduced_alpha_to_down(png: &PngImage, bpc: usize, bpp: usize) -> Vec { reduced.extend_from_slice(pixel); } } - last_line = reduced.clone(); + last_line = reduced[(pos + 1)..reduced.len()].to_vec(); + pos = reduced.len(); } reduced } @@ -147,8 +149,8 @@ fn reduced_alpha_to_left(png: &PngImage, bpc: usize, bpp: usize) -> Vec { line_bytes.resize(line_bytes.len() + bpc, 0); } else { line_bytes.extend_from_slice(pixel); + last_pixel = pixel.to_owned(); } - last_pixel = pixel.to_owned(); } reduced.push(line.filter); reduced.extend(line_bytes.chunks(bpp).rev().flatten()); @@ -167,8 +169,8 @@ fn reduced_alpha_to_right(png: &PngImage, bpc: usize, bpp: usize) -> Vec { reduced.resize(reduced.len() + bpc, 0); } else { reduced.extend_from_slice(pixel); + last_pixel = pixel.to_owned(); } - last_pixel = pixel.to_owned(); } } reduced