Skip to content

Commit

Permalink
Allow for shorter palette length
Browse files Browse the repository at this point in the history
  • Loading branch information
Diederik Veeze committed Jun 26, 2016
1 parent 9f48b1e commit f7d8466
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions PIL/ImagePalette.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ def getcolor(self, color):
if index >= 256:
raise ValueError("cannot allocate more than 256 colors")
self.colors[color] = index
self.palette[index] = color[0]
self.palette[index+256] = color[1]
self.palette[index+512] = color[2]
for i in range(len(self.mode)):
offset = int(len(self.palette) / len(self.mode))
val = 255 if len(color) < len(self.mode) else color[i]
self.palette[i * offset + index] = val
self.dirty = 1
return index
else:
Expand Down

0 comments on commit f7d8466

Please sign in to comment.