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 @@ -10,6 +10,10 @@

- [#55](https://github.com/embedded-graphics/tinybmp/pull/55) Added methods `CompressionMethod::is_compressed` and `Header::bytes_per_row`. The latter is essential information when walking through the bytes yourself.

### Fixed

- [#57](https://github.com/embedded-graphics/tinybmp/pull/57) Fixed RLE4/RLE8 compressed BMP pixel iterator returning only the first row of pixels instead of all pixels.

## [0.7.0] - 2026-01-14

### Fixed
Expand Down
18 changes: 10 additions & 8 deletions src/raw_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl<'a> Rle8Colors<'a> {
Rle8Colors {
data: raw_bmp.image_data(),
rle_state: RleState::Starting,
start_of_row: false,
start_of_row: true,
}
}

Expand Down Expand Up @@ -252,6 +252,7 @@ impl<'a> Iterator for Rle8Colors<'a> {
} else {
self.data = self.data.get(1..)?;
}
self.start_of_row = false;
return Some(RawU8::from(value));
}
RleState::Running {
Expand All @@ -268,6 +269,7 @@ impl<'a> Iterator for Rle8Colors<'a> {
is_odd,
};
}
self.start_of_row = false;
return Some(RawU8::from(value));
}
RleState::Starting => {
Expand All @@ -284,9 +286,8 @@ impl<'a> Iterator for Rle8Colors<'a> {
// the pair, which can be one of the following values.
match param {
0 => {
if !self.start_of_row {
return None;
}
// End of line - move to next row
self.start_of_row = true;
}
1 => {
// End of bitmap
Expand Down Expand Up @@ -340,7 +341,7 @@ impl<'a> Rle4Colors<'a> {
Rle4Colors {
data: raw_bmp.image_data(),
rle_state: RleState::Starting,
start_of_row: false,
start_of_row: true,
}
}

Expand Down Expand Up @@ -400,6 +401,7 @@ impl<'a> Iterator for Rle4Colors<'a> {
// remove the padding byte too
self.data = self.data.get(1..)?;
}
self.start_of_row = false;
return Some(RawU4::from(nibble_value));
}
RleState::Running {
Expand Down Expand Up @@ -434,6 +436,7 @@ impl<'a> Iterator for Rle4Colors<'a> {
};
}

self.start_of_row = false;
return Some(RawU4::from(nibble_value));
}
RleState::Starting => {
Expand All @@ -450,9 +453,8 @@ impl<'a> Iterator for Rle4Colors<'a> {
// the pair, which can be one of the following values.
match param {
0 => {
if !self.start_of_row {
return None;
}
// End of line - move to next row
self.start_of_row = true;
}
1 => {
// End of bitmap
Expand Down
56 changes: 56 additions & 0 deletions tests/logo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ fn logo_indexed_1bpp_pixel_getter() {
bmp.assert_eq(&raw);
}

#[test]
fn logo_indexed_1bpp_pixel_iteration() {
let bmp: Bmp<'_, Bgr888> = Bmp::from_slice(include_bytes!("logo-indexed-1bpp.bmp")).unwrap();
assert_eq!(bmp.pixels().count(), WIDTH * HEIGHT);
}

#[test]
fn logo_indexed_4bpp() {
let raw = draw_raw::<Bgr888>(include_bytes!("logo-indexed-4bpp.raw"));
Expand All @@ -147,6 +153,12 @@ fn logo_indexed_4bpp() {
bmp.assert_eq(&raw);
}

#[test]
fn logo_indexed_4bpp_pixel_iteration() {
let bmp: Bmp<'_, Bgr888> = Bmp::from_slice(include_bytes!("logo-indexed-4bpp.bmp")).unwrap();
assert_eq!(bmp.pixels().count(), WIDTH * HEIGHT);
}

#[test]
fn logo_indexed_4bpp_rle4() {
let raw = draw_raw::<Bgr888>(include_bytes!("logo-indexed-4bpp.raw"));
Expand All @@ -155,6 +167,13 @@ fn logo_indexed_4bpp_rle4() {
bmp.assert_eq(&raw);
}

#[test]
fn logo_indexed_4bpp_rle4_pixel_iteration() {
let bmp: Bmp<'_, Bgr888> =
Bmp::from_slice(include_bytes!("logo-indexed-4bpp-rle4.bmp")).unwrap();
assert_eq!(bmp.pixels().count(), WIDTH * HEIGHT);
}

#[test]
fn logo_indexed_4bpp_pixel_getter() {
let raw = draw_raw::<Bgr888>(include_bytes!("logo-indexed-4bpp.raw"));
Expand All @@ -179,6 +198,12 @@ fn logo_indexed_8bpp_pixel_getter() {
bmp.assert_eq(&raw);
}

#[test]
fn logo_indexed_8bpp_pixel_iteration() {
let bmp: Bmp<'_, Bgr888> = Bmp::from_slice(include_bytes!("logo-indexed-8bpp.bmp")).unwrap();
assert_eq!(bmp.pixels().count(), WIDTH * HEIGHT);
}

#[test]
fn logo_indexed_8bpp_rle8() {
let raw = draw_raw::<Bgr888>(include_bytes!("logo-indexed-8bpp.raw"));
Expand All @@ -187,6 +212,13 @@ fn logo_indexed_8bpp_rle8() {
bmp.assert_eq(&raw);
}

#[test]
fn logo_indexed_8bpp_rle8_pixel_iteration() {
let bmp: Bmp<'_, Bgr888> =
Bmp::from_slice(include_bytes!("logo-indexed-8bpp-rle8.bmp")).unwrap();
assert_eq!(bmp.pixels().count(), WIDTH * HEIGHT);
}

#[test]
fn logo_rgb555() {
let raw = draw_raw::<Rgb555>(include_bytes!("logo-rgb555.raw"));
Expand All @@ -203,6 +235,12 @@ fn logo_rgb555_pixel_getter() {
bmp.assert_eq(&raw);
}

#[test]
fn logo_rgb555_pixel_iteration() {
let bmp: Bmp<'_, Rgb555> = Bmp::from_slice(include_bytes!("logo-rgb555.bmp")).unwrap();
assert_eq!(bmp.pixels().count(), WIDTH * HEIGHT);
}

#[test]
fn logo_rgb565() {
let raw = draw_raw::<Rgb565>(include_bytes!("logo-rgb565.raw"));
Expand All @@ -219,6 +257,12 @@ fn logo_rgb565_pixel_getter() {
bmp.assert_eq(&raw);
}

#[test]
fn logo_rgb565_pixel_iteration() {
let bmp: Bmp<'_, Rgb565> = Bmp::from_slice(include_bytes!("logo-rgb565.bmp")).unwrap();
assert_eq!(bmp.pixels().count(), WIDTH * HEIGHT);
}

#[test]
fn logo_rgb888_24bpp() {
let raw = draw_raw::<Bgr888>(include_bytes!("logo-rgb888.raw"));
Expand All @@ -235,6 +279,12 @@ fn logo_rgb888_24bpp_pixel_getter() {
bmp.assert_eq(&raw);
}

#[test]
fn logo_rgb888_24bpp_pixel_iteration() {
let bmp: Bmp<'_, Bgr888> = Bmp::from_slice(include_bytes!("logo-rgb888-24bpp.bmp")).unwrap();
assert_eq!(bmp.pixels().count(), WIDTH * HEIGHT);
}

#[test]
fn logo_rgb888_32bpp() {
let raw = draw_raw::<Bgr888>(include_bytes!("logo-rgb888.raw"));
Expand All @@ -250,3 +300,9 @@ fn logo_rgb888_32bpp_pixel_getter() {

bmp.assert_eq(&raw);
}

#[test]
fn logo_rgb888_32bpp_pixel_iteration() {
let bmp: Bmp<'_, Bgr888> = Bmp::from_slice(include_bytes!("logo-rgb888-32bpp.bmp")).unwrap();
assert_eq!(bmp.pixels().count(), WIDTH * HEIGHT);
}
Loading