git.haldean.org bitpic / master colors.py
master

Tree @master (Download .tar.gz)

colors.py @masterraw · history · blame

import colorsys

def rgb2hsv(rgb):
    return colorsys.rgb_to_hsv(*(float(x) / 255. for x in rgb))

def hsv2rgb(hsv):
    return tuple(int(round(255. * x)) for x in colorsys.hsv_to_rgb(*hsv))

def filter_hsv(hsv):
    h, s, v = hsv
    # apply "gamma" curve to boost mids in saturation
    s = pow(s, 0.5)
    return hsv2rgb((h, s, v))

def filter_rgb(rgb):
    return filter_hsv(rgb2hsv(rgb))