Hello again,
I love PIL and would like support this.(,no matter whether it is
commercial) Sorry if my last messages was bad.
I've experimented with palette.save/load options and i extended the
palette.save/load functions.
It is not important, but it can be attained without large expenditure.
The Gimp and PaintShopP palette files are very similar.
I mean can bring in it in the next version!?
# add some psuedocolour palettes as well
( successfully tested with Gimp2.2 and PSP9.0) example:
def save(self, fp , art="GIMP"):
# (experimental) save palette to text file
des=""
if self.rawmode:
raise ValueError("palette contains raw palette data")
if type(fp) == type(""):
if art and art[:4] == "GIMP":
fp = open(fp, "wb")
fp.write("%s\n# Mode: %s\n" % ("GIMP Palette",self.mode))
des='" %i" % i' ##FIXME color description
elif art[:4] == "JASC":
fp = open(fp, "w")
fp.write("JASC-PAL\n0100\n256\n")
else:
raise ValueError, "wrong palette type"
for i in range(256):
fp.write("%d %d %d" % (self.palette[i] ,self.palette[i+256],
self.palette[i+512]))
fp.write("%s\n" % eval(des))
fp.close()
And again a big Question:
How i can load the palette from FLI/FLC files, or is it experimental
and/or not yet supported? The palette of each band is only gray.
Sorry if my english is to bad.
I've attached the sample Modul JascPaletteFile
--
<!O>input<?/>
import string
# File handler for Jasc's palette format.
class JascPaletteFile:
rawmode = "RGB"
def __init__(self, fp):
self.palette = map(lambda i: chr(i)*3, range(256))
if fp.readline()[:8] != "JASC-PAL": raise SyntaxError, "not a JASC
palette file"
fp.readline()# 0100
count = fp.readline()
i = 0
while i < count:
s = fp.readline()
if not s: break
v = tuple(map(int, string.split(s)[:3]))
if len(v) != 3: raise ValueError, "bad palette entry"
if 0 <= i < count: self.palette[i] = chr(v[0]) + chr(v[1]) +
chr(v[2])
i+=1
self.palette = string.join(self.palette, "")
def getpalette(self):
return self.palette, self.rawmode
#fp = open("D:\own_data\My PSP Files\Palettes\Stegadon1.PspPalette", "rb")
#p = JascPaletteFile(fp)
#p = p.getpalette()
#p= tuple(p[0])
#print len(p),p _______________________________________________
Image-SIG maillist - [email protected]
http://mail.python.org/mailman/listinfo/image-sig