Skip to content

Conversation

@Ddystopia
Copy link
Contributor

Thank you for helping out with tinybmp development! Please:

  • Check that you've added passing tests and documentation
  • Add a CHANGELOG.md entry in the Unreleased section under the appropriate heading (Added, Fixed, etc) if your changes affect the public API
  • Run rustfmt on the project
  • Run just build (Linux/macOS only) and make sure it passes. If you use Windows, check that CI passes once you've opened the PR. - Some unrelated to PR error ocured with docs

PR description

GIMP can open bmp that is added in tests.

To explain, the bug, let's look at example:

We want to encode 4 bit colors "0, 1, 2". Spec says, absolute (in terms tinybmp code uses) offsets should be padded to 16bit offset. When we encode "0, 1, 2" we see: 00 03 01 20. This is aligned, so no padding. What tinybmp does? (len >> 1) % 2 != 0, which yields that there is padding.

Specification: https://gibberlings3.github.io/iesdp/file_formats/ie_formats/bmp.htm#Raster4RLE, at "Raster Data compression for 4bit / 16 color images:

Copy link
Member

@rfuest rfuest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. The fix itself looks good, but I would like to change a few details.

@Ddystopia Ddystopia requested a review from rfuest October 28, 2025 11:16
@Ddystopia
Copy link
Contributor Author

Just for your information, is stored as rgb bytes, like byte 0 is r, byte 1 is g, byte 2 is b, byte 3 is r etc... For some reason, I need to use Bgr with ImageRawLE.

Tests pass when fix is applied, and fail when there is old code, so I think test itself successes at detecting the issue, even though I am not sure what is going on with that Bgr business.

@rfuest
Copy link
Member

rfuest commented Oct 28, 2025

Just for your information, is stored as rgb bytes, like byte 0 is r, byte 1 is g, byte 2 is b, byte 3 is r etc... For some reason, I need to use Bgr with ImageRawLE.

Tests pass when fix is applied, and fail when there is old code, so I think test itself successes at detecting the issue, even though I am not sure what is going on with that Bgr business.

If the bytes are laid out as R1 B1 G1 R2 B2 G2 ... that would be big endian if you use Rgb888. For 24 bits per pixel Rgb888 big endian and Bgr888 little endian use the same memory encoding, which makes the example work but using BGR instead of RGB.

@rfuest rfuest merged commit 9fc7e07 into embedded-graphics:main Oct 28, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants