def RGB_TO_HSB(col):
    """
    Converts a 3-tuple with RGB values (in range 0..255) into a 3-tuple
    with HSB color values in range [0..1].
    """
    r, g, b = col

    cmax = float(max(r, g, b))
    cmin = float(min(r, g, b))

    delta = cmax - cmin

    brightness = cmax / 255.0
    saturation = (delta / cmax) if cmax > 0 else 0
    hue = 0

    if saturation > 0:
        redc = (cmax - r) / delta
        greenc = (cmax - g) / delta
        bluec = (cmax - b) / delta

        if r == cmax:
            hue = bluec - greenc
        elif g == cmax:
            hue = 2.0 + redc - bluec
        else:
            hue = 4.0 + greenc - redc

        hue /= 6.0
        if hue < 0: hue += 1.0

    return (hue, saturation, brightness)