Skip to content

Conversation

@radarhere
Copy link
Member

Removes an xfail

@pytest.mark.xfail(reason="Palm P image is wrong")
def test_p_mode(tmp_path: Path) -> None:

with the following changes

  1. Always save the colormap for a P mode image, because
    if im.mode == "P":
    # we assume this is a color Palm image with the standard colormap,
    # unless the "info" dict has a "custom-colormap" field

    is an odd assumption.
  2. Use OR instead of AND to apply the custom colormap flag
    flags = flags & _FLAGS["custom-colormap"]
  3. Do not presume that palettes are 256 in length.

At first glance, you might think that

elif colormapmode == "RGBA":
fp.write(
o8(colormap[4 * i])
+ o8(colormap[4 * i + 1])
+ o8(colormap[4 * i + 2])
)

offered support for saving RGBA palettes. But if you look again, you will see that is only writing three values, meaning it's not writing RGBA palettes, it's converting them to RGB. However, getpalette() will only return a RGB palette, so we won't need to worry about handling that.

@hugovk hugovk merged commit 25653d2 into python-pillow:main Mar 29, 2025
50 checks passed
@radarhere radarhere deleted the palm branch March 29, 2025 20:20
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