Created
October 11, 2009 01:47
-
-
Save tangzero/207317 to your computer and use it in GitHub Desktop.
PIL compatibles's .act color palette.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from struct import unpack | |
class Palette: | |
color_length = 3 | |
def __init__(self, fp): | |
self.palette = [] | |
for i in range(256): | |
color = fp.read(self.color_length) | |
if not color: | |
break | |
if len(color) != self.color_length: | |
raise SyntaxError, "Bad Photoshop palette file!" | |
for item in unpack("ccc", color): | |
self.palette.append(ord(item)) | |
fp.close() | |
def getpalette(self): | |
return self.palette |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment