def create_pil_palette(rgb_palette):
    """Converts a list of (r, g, b) tuples into a PIL-compatible palette."""
    pal = []
    for (r, g, b) in rgb_palette:
        pal += [r, g, b]
    # For classic PIL, the palette size *must* be 256 * 3
    pal += [0] * (256 * 3 - len(pal))

    return pal