Merge pull request #6391 from radarhere/pcx

Pad PCX palette to 768 bytes when saving
This commit is contained in:
Hugo van Kemenade 2022-06-23 09:50:22 +03:00 committed by GitHub
commit e774be01fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -20,6 +20,11 @@ def test_sanity(tmp_path):
for mode in ("1", "L", "P", "RGB"): for mode in ("1", "L", "P", "RGB"):
_roundtrip(tmp_path, hopper(mode)) _roundtrip(tmp_path, hopper(mode))
# Test a palette with less than 256 colors
im = Image.new("P", (1, 1))
im.putpalette((255, 0, 0))
_roundtrip(tmp_path, im)
# Test an unsupported mode # Test an unsupported mode
f = str(tmp_path / "temp.pcx") f = str(tmp_path / "temp.pcx")
im = hopper("RGBA") im = hopper("RGBA")

View File

@ -198,7 +198,9 @@ def _save(im, fp, filename):
if im.mode == "P": if im.mode == "P":
# colour palette # colour palette
fp.write(o8(12)) fp.write(o8(12))
fp.write(im.im.getpalette("RGB", "RGB")) # 768 bytes palette = im.im.getpalette("RGB", "RGB")
palette += b"\x00" * (768 - len(palette))
fp.write(palette) # 768 bytes
elif im.mode == "L": elif im.mode == "L":
# greyscale palette # greyscale palette
fp.write(o8(12)) fp.write(o8(12))