'Given an rgb tuple, allocate palette entry.
.. warning:: This method is experimental.'

def getcolor(self, color):

    if self.rawmode:
        raise ValueError('palette    contains    raw    palette    data')
    if isinstance(color, tuple):
        try:
            return self.colors[color]
        except KeyError:
            if isinstance(self.palette, bytes):
                self.palette = bytearray(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))
