2
# Python Imaging Library
5
# stuff to read GIMP palette files
8
# 1997-08-23 fl Created
9
# 2004-09-07 fl Support GIMP 2.0 palette files.
11
# Copyright (c) Secret Labs AB 1997-2004. All rights reserved.
12
# Copyright (c) Fredrik Lundh 1997-2004.
14
# See the README file for information on usage and redistribution.
20
# File handler for GIMP's palette format.
22
class GimpPaletteFile:
26
def __init__(self, fp):
28
self.palette = map(lambda i: chr(i)*3, range(256))
30
if fp.readline()[:12] != "GIMP Palette":
31
raise SyntaxError, "not a GIMP palette file"
41
# skip fields and comment lines
42
if re.match("\w+:|#", s):
45
raise SyntaxError, "bad palette file"
47
v = tuple(map(int, string.split(s)[:3]))
49
raise ValueError, "bad palette entry"
52
self.palette[i] = chr(v[0]) + chr(v[1]) + chr(v[2])
56
self.palette = string.join(self.palette, "")
61
return self.palette, self.rawmode