Merge pull request #3760 from radarhere/gimp

Simplified code
This commit is contained in:
Hugo 2019-04-01 08:08:54 +03:00 committed by GitHub
commit 73cf979adb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,14 +32,12 @@ class GimpPaletteFile(object):
if fp.readline()[:12] != b"GIMP Palette": if fp.readline()[:12] != b"GIMP Palette":
raise SyntaxError("not a GIMP palette file") raise SyntaxError("not a GIMP palette file")
i = 0 for i in range(256):
while i <= 255:
s = fp.readline() s = fp.readline()
if not s: if not s:
break break
# skip fields and comment lines # skip fields and comment lines
if re.match(br"\w+:|#", s): if re.match(br"\w+:|#", s):
continue continue
@ -50,10 +48,7 @@ class GimpPaletteFile(object):
if len(v) != 3: if len(v) != 3:
raise ValueError("bad palette entry") raise ValueError("bad palette entry")
if 0 <= i <= 255: self.palette[i] = o8(v[0]) + o8(v[1]) + o8(v[2])
self.palette[i] = o8(v[0]) + o8(v[1]) + o8(v[2])
i += 1
self.palette = b"".join(self.palette) self.palette = b"".join(self.palette)