Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

## [Unreleased] - ReleaseDate

### Fixed

- [#50](https://github.com/embedded-graphics/tinybmp/pull/50) Fixed handling of padding bytes in absolute mode for RLE4 compressed files.

### Changed

- **(breaking)** [#49](https://github.com/embedded-graphics/tinybmp/pull/41) Use 1.81 as the MSRV.
Expand Down
5 changes: 3 additions & 2 deletions src/raw_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,14 @@ impl<'a> Iterator for Rle4Pixels<'a> {
// Delta encoding is unsupported.
return None;
}
_ => {
num_pixels => {
let num_bytes = num_pixels.div_ceil(2);
// Absolute mode
self.rle_state = RleState::Absolute {
remaining: param.saturating_sub(1),
is_odd: (param % 2) != 0,
// padding if the number of *bytes* is odd
has_padding: ((param >> 1) % 2) != 0,
has_padding: num_bytes & 1 != 0,
};
}
}
Expand Down
22 changes: 20 additions & 2 deletions tests/embedded_graphics.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use embedded_graphics::{
image::Image,
image::{Image, ImageRawLE},
mock_display::{ColorMapping, MockDisplay},
pixelcolor::{Gray8, Rgb555, Rgb565, Rgb888},
pixelcolor::{Bgr888, Gray8, Rgb555, Rgb565, Rgb888},
prelude::*,
primitives::Rectangle,
};
Expand Down Expand Up @@ -149,3 +149,21 @@ fn issue_8_height_is_negative() {
bottom_up_display.assert_pattern(&["WK", "KK"]);
top_down_display.assert_eq(&bottom_up_display);
}

/// Test for PR #50
#[test]
fn pr_50_rle4_padding() {
let bmp = Bmp::<Bgr888>::from_slice(include_bytes!("pr_50_rle4_padding.bmp")).unwrap();
let raw = ImageRawLE::<Bgr888>::new(include_bytes!("pr_50_rle4_padding.raw"), 20);

assert_eq!(raw.size(), Size::new(20, 20));
assert_eq!(bmp.size(), Size::new(20, 20));

let mut display_bmp = MockDisplay::new();
let mut display_raw = MockDisplay::new();

bmp.draw(&mut display_bmp).unwrap();
raw.draw(&mut display_raw).unwrap();

display_bmp.assert_eq(&display_raw);
}
Binary file added tests/pr_50_rle4_padding.bmp
Binary file not shown.
Binary file added tests/pr_50_rle4_padding.raw
Binary file not shown.