Skip to content

Add alpha channel to BMP with RLE to allow setting transparency to skipped pixels - #2773

Closed
telecos wants to merge 4 commits into
image-rs:mainfrom
telecos:feature/support-rle-transparency
Closed

telecos wants to merge 4 commits into
image-rs:mainfrom
telecos:feature/support-rle-transparency

Conversation

@telecos

@telecos telecos commented Feb 15, 2026 •

Copy link
Copy Markdown
Contributor

This change is adding alpha channel to RLE encoded images so that skipped pixels (by Delta, EndOfRow or EndOfFile commands) are set to transparent color, rather than opaque black. This change affects expected pixel output for pal4rlecut.bmp and pal4rletrns.bmp.

This change is part of #2747

However, I have done some investigation and based on this page: https://entropymine.com/jason/bmpsuite/bmpsuite/html/bmpsuite.html

These files which are skipping pixels with different RLE commands have multiple expected results, so both current result from BmpDecoder (which mimics Windows and old IE browser) and the proposed change on this PR (matching Chromium) seem correct. For example, in pal4rlecut.bmp:

image

Chromium (image on right) is displaying as 1st option on left, while our reference in BmpDecoder matches the 3rd

For additional info, I also checked Firefox and it is also showing as transparent, which can be checked also in a specific comment from their BMP decoder:

// Note that RLE-encoded BMPs might be transparent because the 'delta' mode
// can skip pixels and cause implicit transparency.

https://searchfox.org/firefox-main/source/image/decoders/nsBMPDecoder.cpp#688

Being both valid, I don't have strong opinion on adding this change by default (more on the opposite). Maybe adding a function to control externally from the consumer if RLE should be treated as RGB or RGBA?

Comment thread src/codecs/bmp/decoder.rs Resolved
@anforowicz

Copy link
Copy Markdown

These files which are skipping pixels with different RLE commands have multiple expected results, so both current result from BmpDecoder (which mimics Windows and old IE browser) and the proposed change on this PR (matching Chromium) seem correct. For example, in pal4rlecut.bmp:

...

For additional info, I also checked Firefox and it is also showing as transparent.

Thank you for the explanation. For completeness, we could check which reference result (left) is actually displayed (right) for pal4rlecut Safari when visiting https://entropymine.com/jason/bmpsuite/bmpsuite/html/bmpsuite.html (unfortunately I don't have a Mac or iPhone readily available...).

I think matching the current behavior of web browser (at least Firefox and Chromium) makes sense, but I don't have a strong opinion.

@telecos

telecos commented Feb 17, 2026

Copy link
Copy Markdown
Contributor Author

These files which are skipping pixels with different RLE commands have multiple expected results, so both current result from BmpDecoder (which mimics Windows and old IE browser) and the proposed change on this PR (matching Chromium) seem correct. For example, in pal4rlecut.bmp:
...
For additional info, I also checked Firefox and it is also showing as transparent.

Thank you for the explanation. For completeness, we could check which reference result (left) is actually displayed (right) for pal4rlecut Safari when visiting https://entropymine.com/jason/bmpsuite/bmpsuite/html/bmpsuite.html (unfortunately I don't have a Mac or iPhone readily available...).

I think matching the current behavior of web browser (at least Firefox and Chromium) makes sense, but I don't have a strong opinion.

I have just tested on Safari and found that it is showing the 2nd option (so not like Chromium nor like image crate)

image

@telecos
telecos marked this pull request as ready for review February 18, 2026 00:20
@anforowicz

Copy link
Copy Markdown

I have just tested on Safari and found that it is showing the 2nd option (so not like Chromium nor like image crate)

Ack. I think this means that web compatibility is not a strong argument for landing this PR (although it would align the behavior with Firefox and with the legacy decoder in Chromium). One option that is still on the table is updating the "golden" / expected images in Chromium tests (although ultimately I defer to the Skia folks on that decision).

I don't have a strong opinion on whether to pursue this PR, vs update the test expectations. Sorry for not being more decisive here.

@telecos

telecos commented Feb 20, 2026 •

Copy link
Copy Markdown
Contributor Author

For completeness, sharing how chromium renders when enabling rust bmp decoder from image crate in its current status:

image

@telecos
telecos force-pushed the feature/support-rle-transparency branch from 1d9c9f0 to 172feb8 Compare February 24, 2026 14:12
@telecos telecos closed this Mar 7, 2026
@telecos
telecos deleted the feature/support-rle-transparency branch March 7, 2026 19:59
@telecos
telecos restored the feature/support-rle-transparency branch March 7, 2026 20:00
@telecos telecos reopened this Mar 7, 2026
@telecos

telecos commented Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

Closing as current behavior being a valid solution for these ambiguous cases does not make high priority having behavior made configurable.

@telecos telecos closed this Apr 9, 2026
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