Exemplo n.º 1
0
 def getcolor(self, color):
     # experimental: given an rgb tuple, allocate palette entry
     if self.rawmode:
         raise ValueError("palette contains raw palette data")
     if Image.isTupleType(color):
         try:
             return self.colors[color]
         except KeyError:
             # allocate new color slot
             if Image.isStringType(self.palette):
                 self.palette = map(int, self.palette)
             index = len(self.colors)
             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]
             self.dirty = 1
             return index
     else:
         raise ValueError("unknown color specifier: %r" % color)
Exemplo n.º 2
0
 def getcolor(self, color):
     # experimental: given an rgb tuple, allocate palette entry
     if self.rawmode:
         raise ValueError("palette contains raw palette data")
     if Image.isTupleType(color):
         try:
             return self.colors[color]
         except KeyError:
             # allocate new color slot
             if Image.isStringType(self.palette):
                 self.palette = map(int, self.palette)
             index = len(self.colors)
             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]
             self.dirty = 1
             return index
     else:
         raise ValueError("unknown color specifier: %r" % color)