Pillow icon indicating copy to clipboard operation
Pillow copied to clipboard

Improve reading XPM images

Open radarhere opened this issue 8 months ago • 0 comments

Resolves #8872

Looking at the specification, or even just looking at https://github.com/python-pillow/Pillow/blob/main/Tests/images/hopper.xpm#L50), you will see that an XPM image describes a palette with a series of keys and values, and then lists the pixel values within lines separated by quotes and commas. Our "raw" decoder cannot handle this pixel data, and I've created a Python decoder instead.

I've also pushed commits to read an image as RGB if the palette is larger than 256 colours (test image from the user in the issue), or if the palette keys are longer than a single character (test image created by ImageMagick), removing this error. https://github.com/python-pillow/Pillow/blob/cda26be10e93472cca7cc2c07c045037572d9b38/src/PIL/XpmImagePlugin.py#L59-L61

radarhere avatar Apr 09 '25 10:04 radarhere