# Path: opc/utils/prof.py
# def timefunc(f, reference=False):
#     global records
# 
#     records[f.__name__] = Record(f.__name__, reference)
# 
#     @wraps(f)
#     def f_timer(*args, **kwargs):
#         global active
# 
#         if not active:
#             return f(*args, **kwargs)
# 
#         start = time.time()
#         result = f(*args, **kwargs)
#         end = time.time()
# 
#         records[f.__name__].addTime(end-start)
# 
#         return result
# 
#     return f_timer


import colorsys
from math import fmod, sin, pi
from mwt import mwt
from .utils.prof import timefunc


@mwt(timeout=20)
@timefunc
def hsvToRgb(h, s=1.0, v=1.0, rainbow=True):
    """
    Convert a (h, s, v) value to the (r, g, b) color space. By default,
    we use a more cpu-intense method to curve the hue ramps above the
    typical linear, with a view to evening out the visible range of yellow,
    cyan, and purple.

    This method takes h, s, and v values in range 0..1 and returns r, g,
    and b values in range 0..255.
    """
    if rainbow:
        return [sin(c*pi/2)*255 for c in colorsys.hsv_to_rgb(h, s, v)]

    return [c*255 for c in colorsys.hsv_to_rgb(h, s, v)]


@mwt(timeout=20)

# Path: opc/utils/prof.py
# def timefunc(f, reference=False):
#     global records
# 
#     records[f.__name__] = Record(f.__name__, reference)
# 
#     @wraps(f)
#     def f_timer(*args, **kwargs):
#         global active
# 
#         if not active:
#             return f(*args, **kwargs)
# 
#         start = time.time()
#         result = f(*args, **kwargs)
#         end = time.time()
# 
#         records[f.__name__].addTime(end-start)
# 
#         return result
# 
#     return f_timer


# Path: opc/hue.py
import colorsys
from math import fmod, sin, pi
from mwt import mwt
from .utils.prof import timefunc



@mwt(timeout=20)
@timefunc
def hsvToRgb(h, s=1.0, v=1.0, rainbow=True):
    """
    Convert a (h, s, v) value to the (r, g, b) color space. By default,
    we use a more cpu-intense method to curve the hue ramps above the
    typical linear, with a view to evening out the visible range of yellow,
    cyan, and purple.

    This method takes h, s, and v values in range 0..1 and returns r, g,
    and b values in range 0..255.
    """
    if rainbow:
        return [sin(c*pi/2)*255 for c in colorsys.hsv_to_rgb(h, s, v)]

    return [c*255 for c in colorsys.hsv_to_rgb(h, s, v)]


@mwt(timeout=20)

@timefunc