def quantize(rgb, quanta):
    """map a tuple (r,g,b) each between 0 and 255
    to our discrete color buckets"""
    r,g,b = rgb
    r = max([q for q in quanta if q <= r])
    g = max([q for q in quanta if q <= g])
    b = max([q for q in quanta if q <= b])
    return (r,g,b)