mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 02:36:17 +03:00
Corrected palette size when saving
This commit is contained in:
parent
92b0f2c919
commit
99e401123b
|
@ -123,6 +123,18 @@ def test_save(tmp_path):
|
||||||
assert test_im.size == (100, 100)
|
assert test_im.size == (100, 100)
|
||||||
|
|
||||||
|
|
||||||
|
def test_small_palette(tmp_path):
|
||||||
|
im = Image.new("P", (1, 1))
|
||||||
|
colors = [0, 0, 0]
|
||||||
|
im.putpalette(colors)
|
||||||
|
|
||||||
|
out = str(tmp_path / "temp.tga")
|
||||||
|
im.save(out)
|
||||||
|
|
||||||
|
with Image.open(out) as reloaded:
|
||||||
|
assert reloaded.getpalette() == colors
|
||||||
|
|
||||||
|
|
||||||
def test_save_wrong_mode(tmp_path):
|
def test_save_wrong_mode(tmp_path):
|
||||||
im = hopper("PA")
|
im = hopper("PA")
|
||||||
out = str(tmp_path / "temp.tga")
|
out = str(tmp_path / "temp.tga")
|
||||||
|
|
|
@ -193,7 +193,8 @@ def _save(im, fp, filename):
|
||||||
warnings.warn("id_section has been trimmed to 255 characters")
|
warnings.warn("id_section has been trimmed to 255 characters")
|
||||||
|
|
||||||
if colormaptype:
|
if colormaptype:
|
||||||
colormapfirst, colormaplength, colormapentry = 0, 256, 24
|
palette = im.im.getpalette("RGB", "BGR")
|
||||||
|
colormapfirst, colormaplength, colormapentry = 0, len(palette) // 3, 24
|
||||||
else:
|
else:
|
||||||
colormapfirst, colormaplength, colormapentry = 0, 0, 0
|
colormapfirst, colormaplength, colormapentry = 0, 0, 0
|
||||||
|
|
||||||
|
@ -225,7 +226,7 @@ def _save(im, fp, filename):
|
||||||
fp.write(id_section)
|
fp.write(id_section)
|
||||||
|
|
||||||
if colormaptype:
|
if colormaptype:
|
||||||
fp.write(im.im.getpalette("RGB", "BGR"))
|
fp.write(palette)
|
||||||
|
|
||||||
if rle:
|
if rle:
|
||||||
ImageFile._save(
|
ImageFile._save(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user