From c72a0587f71cc54251723c286ee5e9f8f94010bf Mon Sep 17 00:00:00 2001 From: Matthias Gabriel <gabm+pub@mailbox.org> Date: Mon, 4 Mar 2024 07:08:43 +0100 Subject: [PATCH] clean --- src/femtovg_area/imp.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/femtovg_area/imp.rs b/src/femtovg_area/imp.rs index 0a71bf8..8bc1134 100644 --- a/src/femtovg_area/imp.rs +++ b/src/femtovg_area/imp.rs @@ -417,8 +417,11 @@ impl FemtoVgAreaMut { let row_length = width * bytes_per_pixel; let mut dst_buffer = if row_length == stride { + // stride == row_length, there are no additional bytes after the end of each row src_buffer.to_vec() } else { + // stride != row_length, there are additional bytes after the end of each row that + // need to be truncated. We copy row by row.. let mut dst_buffer = Vec::<u8>::with_capacity(width * height * bytes_per_pixel); for row in 0..height { @@ -428,6 +431,8 @@ impl FemtoVgAreaMut { dst_buffer }; + // in almost all cases, that should be a no-op. Buf we might have additional elements after the + // end of the buffer, e.g. after width * height * bytes_per_pixel dst_buffer.truncate(width * height * bytes_per_pixel); if image.has_alpha() {