1def invert_colors(clip):
2    """ Returns the color-inversed clip.
3
4    The values of all pixels are replaced with (255-v) or (1-v) for masks
5    Black becomes white, green becomes purple, etc.
6    """
7    maxi = (1.0 if clip.ismask else 255)
8    return clip.fl_image(lambda f : maxi - f)
9