Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Gabriel committed Mar 4, 2024
1 parent 57ca79e commit c72a058
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/femtovg_area/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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() {
Expand Down

0 comments on commit c72a058

Please sign in to comment.