mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
parent
dcb6eef590
commit
b9ab3f5bf4
|
@ -54,7 +54,6 @@ class GifImageFile(ImageFile.ImageFile):
|
|||
|
||||
format = "GIF"
|
||||
format_description = "Compuserve GIF"
|
||||
|
||||
global_palette = None
|
||||
|
||||
def data(self):
|
||||
|
@ -71,13 +70,9 @@ class GifImageFile(ImageFile.ImageFile):
|
|||
raise SyntaxError("not a GIF file")
|
||||
|
||||
self.info["version"] = s[:6]
|
||||
|
||||
self.size = i16(s[6:]), i16(s[8:])
|
||||
|
||||
self.tile = []
|
||||
|
||||
flags = i8(s[10])
|
||||
|
||||
bits = (flags & 7) + 1
|
||||
|
||||
if flags & 128:
|
||||
|
@ -122,7 +117,8 @@ class GifImageFile(ImageFile.ImageFile):
|
|||
self.im = self.dispose
|
||||
self.dispose = None
|
||||
|
||||
self.palette = self.global_palette
|
||||
from copy import copy
|
||||
self.palette = copy(self.global_palette)
|
||||
|
||||
while True:
|
||||
|
||||
|
@ -252,6 +248,9 @@ def _save(im, fp, filename):
|
|||
palette = im.encoderinfo["palette"]
|
||||
except KeyError:
|
||||
palette = None
|
||||
if im.palette:
|
||||
# use existing if possible
|
||||
palette = im.palette.getdata()[1]
|
||||
|
||||
header, usedPaletteColors = getheader(imOut, palette, im.encoderinfo)
|
||||
for s in header:
|
||||
|
|
|
@ -489,26 +489,24 @@ def _save(im, fp, filename, chunk=putchunk, check=0):
|
|||
|
||||
#
|
||||
# attempt to minimize storage requirements for palette images
|
||||
|
||||
if "bits" in im.encoderinfo:
|
||||
|
||||
# number of bits specified by user
|
||||
n = 1 << im.encoderinfo["bits"]
|
||||
|
||||
colors = 1 << im.encoderinfo["bits"]
|
||||
else:
|
||||
|
||||
# check palette contents
|
||||
n = 256 # FIXME
|
||||
if im.palette:
|
||||
colors = len(im.palette.getdata()[1])//3
|
||||
else:
|
||||
colors = 256
|
||||
|
||||
if n <= 2:
|
||||
if colors <= 2:
|
||||
bits = 1
|
||||
elif n <= 4:
|
||||
elif colors <= 4:
|
||||
bits = 2
|
||||
elif n <= 16:
|
||||
elif colors <= 16:
|
||||
bits = 4
|
||||
else:
|
||||
bits = 8
|
||||
|
||||
if bits != 8:
|
||||
mode = "%s;%d" % (mode, bits)
|
||||
|
||||
|
@ -545,8 +543,11 @@ def _save(im, fp, filename, chunk=putchunk, check=0):
|
|||
b'\0') # 12: interlace flag
|
||||
|
||||
if im.mode == "P":
|
||||
palette_bytes = (2 ** bits) * 3
|
||||
chunk(fp, b"PLTE", im.im.getpalette("RGB")[:palette_bytes])
|
||||
palette_byte_number = (2 ** bits) * 3
|
||||
palette_bytes = im.im.getpalette("RGB")[:palette_byte_number]
|
||||
while len(palette_bytes) < palette_byte_number:
|
||||
palette_bytes += b'\0'
|
||||
chunk(fp, b"PLTE", palette_bytes)
|
||||
|
||||
if "transparency" in im.encoderinfo:
|
||||
if im.mode == "P":
|
||||
|
|
Loading…
Reference in New Issue
Block a user