Skip to content

Instantly share code, notes, and snippets.

@tangzero
Created October 11, 2009 01:47
Show Gist options
  • Save tangzero/207317 to your computer and use it in GitHub Desktop.
Save tangzero/207317 to your computer and use it in GitHub Desktop.
PIL compatibles's .act color palette.
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