Transparent support for writing 1bpp and 4bpp BMPs #913
+144
−21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As is, we write palette images as 8bpp BMP images. Besides that this is wasteful, some readers may not even be able to read 8bpp BMP images. Thus, we write palette images with at most two colors as 1bpp BMPs, unless compression is requested, because BMPs do not support compressed encoding of 1bpp images; we write palette images with at most 16 colors as 4bpp BMPs, and apply
BMP_BI_RLE4compression if requested.We piggy-back on the existing implementation for
BMP_BI_RLE8; that keeps it simple, and although it might not yield the best compression, it ought to be good enough.References:
https://en.wikipedia.org/wiki/BMP_file_format
https://learn.microsoft.com/en-us/windows/win32/gdi/bitmap-compression
Closes #911.
While implementing this, I've noticed that the RLE compression is not quite as good as it could be. While there is room for improvement, it might get pretty tricky, and it may not be worth spending further time on that, given that RLE encoding only yields somewhat good compression for images with few details, anyway.