mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-14 15:22:13 +03:00
Do not force palette length to be 256
This commit is contained in:
parent
18e2877f0b
commit
9c8c7a0a4e
|
@ -32,3 +32,4 @@ def test_get_palette() -> None:
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert mode == "RGB"
|
assert mode == "RGB"
|
||||||
|
assert len(palette) / 3 == 11
|
||||||
|
|
|
@ -27,12 +27,11 @@ class GimpPaletteFile:
|
||||||
rawmode = "RGB"
|
rawmode = "RGB"
|
||||||
|
|
||||||
def __init__(self, fp: IO[bytes]) -> None:
|
def __init__(self, fp: IO[bytes]) -> None:
|
||||||
palette = [o8(i) * 3 for i in range(256)]
|
|
||||||
|
|
||||||
if not fp.readline().startswith(b"GIMP Palette"):
|
if not fp.readline().startswith(b"GIMP Palette"):
|
||||||
msg = "not a GIMP palette file"
|
msg = "not a GIMP palette file"
|
||||||
raise SyntaxError(msg)
|
raise SyntaxError(msg)
|
||||||
|
|
||||||
|
palette: list[int] = []
|
||||||
for i in range(256):
|
for i in range(256):
|
||||||
s = fp.readline()
|
s = fp.readline()
|
||||||
if not s:
|
if not s:
|
||||||
|
@ -40,6 +39,7 @@ class GimpPaletteFile:
|
||||||
|
|
||||||
# skip fields and comment lines
|
# skip fields and comment lines
|
||||||
if re.match(rb"\w+:|#", s):
|
if re.match(rb"\w+:|#", s):
|
||||||
|
palette.append(o8(i) * 3)
|
||||||
continue
|
continue
|
||||||
if len(s) > 100:
|
if len(s) > 100:
|
||||||
msg = "bad palette file"
|
msg = "bad palette file"
|
||||||
|
@ -50,7 +50,7 @@ class GimpPaletteFile:
|
||||||
msg = "bad palette entry"
|
msg = "bad palette entry"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|
||||||
palette[i] = o8(int(v[0])) + o8(int(v[1])) + o8(int(v[2]))
|
palette.append(o8(int(v[0])) + o8(int(v[1])) + o8(int(v[2])))
|
||||||
|
|
||||||
self.palette = b"".join(palette)
|
self.palette = b"".join(palette)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user