BMP: Support encoding L2 and L4 images#3011
Open
RunDevelopment wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I suppose this is a continuation of both #2953 and #2625.
Changes:
I added support for writing L2 and L4 BMP images in this PR. This was quite easy after #2953 added L1, since I just had to generalize the logic it added. Now L1, L2, L4, and L8 all use the same functions for writing. The La8 path uses a simplified version of its previous path. All in all, this makes the code for writing easy to understand.
Note: BMP does support 2 bpp paletted images (=they're not disallowed), but not many decoders can read it. In my testing, Chrome, Gimp and
imagecould read it, while Firefox, Windows Photo Viewer and Paint.net could not, and Photoshop read it incorrectly. I also verified that the pal2 images from the BMP test suite by Jason Summers have the same issues, so the problem really is with those programs and not with the files produced by this encoder.I also found some issues with the existing code that I fixed along the way:
encode_with_palettesaid that a given palette is ignored if the color type is incompatible, but the function actually returns an error. I documented the error.Given this comment from #2625, this PR might not be accepted. In that case, just tell me and I'll spin off the fixes into a separate PR.