Skip to content

Improve support for TGA images in P mode with an RGBA palette - #10211

Merged
radarhere merged 3 commits into
python-pillow:mainfrom
sungbin1015:fix-tga-32bit-colormap
Oct 15, 2026
Merged

radarhere merged 3 commits into
python-pillow:mainfrom
sungbin1015:fix-tga-32bit-colormap

Conversation

@sungbin1015

Copy link
Copy Markdown
Contributor

Changes proposed in this pull request:

  • Set the palette mode to RGBA for TGA images with 32-bit colour map entries, as is already done for 16-bit entries
  • Add a test

TgaImagePlugin has a branch for 32-bit colour maps, but it reads them with the "BGRA" rawmode while leaving the palette mode as "RGB". There's no RGB unpacker for BGRA, so the image opens and then fails as soon as it's loaded:

with Image.open("p32.tga") as im:  # colour-mapped, 32-bit BGRA colour map
    im.load()
  File "src/PIL/Image.py", line 993, in load
    self.im.putpalette(self.palette.mode, mode, arr)
ValueError: unrecognized raw mode

The 16-bit branch right above it already sets self.palette.mode = "RGBA", so I've done the same. The image from the new test then converts to RGBA as (255, 0, 0, 255), (0, 0, 255, 0), which is also what ffmpeg decodes from the same bytes. Noticed while reading the plugin; tests pass locally.

Didn't find this reported. #5400 and #7965 dealt with 16-bit colour maps, and #8158 renames the 16-bit rawmode a few lines up but doesn't touch the 32-bit branch.

@radarhere

Copy link
Copy Markdown
Member

I've pushed a commit to support saving with a 32-bit colour map as well.

@radarhere
radarhere force-pushed the fix-tga-32bit-colormap branch from 5c84460 to 17f8eb8 Compare October 15, 2026 21:37
@radarhere radarhere changed the title Fix reading TGA images with a 32-bit colour map Improve support for TGA images in P mode with an RGBA palette Oct 15, 2026
@radarhere
radarhere force-pushed the fix-tga-32bit-colormap branch from 17f8eb8 to a60da6d Compare October 15, 2026 21:38
@radarhere
radarhere merged commit acc5490 into python-pillow:main Oct 15, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants