Repository navigation
Fix saving L images with bpp as Palm - #10266
Merged
Merged
Conversation
Since the colormap change in python-pillow#8685, an L image saved with bpp went through the P mode branch because its mode is switched to P before writing, and failed with 'image has no palette'. Only write the custom colormap for real P images. Also document the bpp option.
radarhere
force-pushed
the
fix-palm-l-save
branch
2 times, most recently
from
October 21, 2026 02:03
55fc81b to
855003b
Compare
radarhere
force-pushed
the
fix-palm-l-save
branch
from
October 21, 2026 02:05
855003b to
16ab902
Compare
Member
I actually think that is a problem. Saving an image shouldn't change it like that. I've pushed a commit to keep it in L mode, and fix the rawmode instead. I'm not a huge fan of testing specific bytes in the saved image. If we're writing specific bytes, and then checking those values specifically again, it doesn't seem like an effective way to know if we did anything incorrect. Instead, I've pushed a commit to check the image mode and similarity to the original image. See what you think. |
radarhere
approved these changes
Oct 21, 2026
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.
Saving an
Limage as Palm fails right now.The
Lbranch switchesim._modeto"P"so theP;1,P;2orP;4rawmode can be used, and since #8685 the colormap code checksim.mode == "P", so it also runs for these images and callsgetpalette()on an image that has none. The same happens whenbppcomes fromim.info.Changes proposed in this pull request:
Pimage (rawmode == "P"). Grayscale Palm images don't use one, which matches the "we ignore the palette here" comment.info["bpp"]bppsave option and which modes can be saved, since it wasn't in the handbookI also converted the bpp 1, 2 and 4 output of hopper with ImageMagick and it matched the expected gray levels exactly. Palm tests pass and ruff, black and sphinx-lint are happy.