# Path: lib/color_fade.py
# class ColorFade(object):
#     """Represents the fade of one color to another"""
# 
#     def __init__(self, keyframes, steps):
#         """
#         keyframes: a list of 3-element tuples representing the colors to fade between.
#         """
# 
#         self._steps = steps
#         self.keyframes = keyframes
#         self.color_cache = np.zeros(steps + 1, dtype=dtypes.pixel_color)
# 
#         # Warmup the cache
#         for i in range(steps + 1):
#             overall_progress = float(i) * (len(self.keyframes) - 1) / self._steps
#             stage = int(overall_progress)
#             stage_progress = overall_progress - stage # 0 to 1 float
# 
#             # special case stage_progress=0, so if progress=1, we don't get
#             # an IndexError
#             if stage_progress == 0:
#                 color = self.keyframes[stage]
#             else:
#                 frame1 = self.keyframes[stage]
#                 frame1_weight = 1 - stage_progress
# 
#                 frame2 = self.keyframes[stage + 1]
#                 frame2_weight = stage_progress
# 
#                 color = tuple([c1 * frame1_weight + c2 * frame2_weight for c1, c2 in zip(frame1, frame2)])
#             self.color_cache[i] = tuple(color)
# #            print progress, self.color_cache[progress]
# 
#     def get_color(self, progress):
#         """
#         Given a progress value between 0 and steps, returns the color for that
#         progress as a (h, l, s) tuple with float values
#         """
# 
#         progress = clip(0, int(progress), self._steps)
# 
#         return self.color_cache[progress]
# 
# Path: lib/dtypes.py

# 
# Path: lib/buffer_utils.py
# def struct_flat(arr):
#     """
#     Returns a flattened view of a structured array whose structure elements
#     are of a homogeneous type
#     """
#     return arr.view(dtype=arr.dtype[0])


from lib.color_fade import ColorFade
from lib import dtypes
from lib.buffer_utils import struct_flat
import colorsys
import numpy as np

        # green is max
        idx = (arr[:,:,1] == arr_max)
        out['hue'][idx] = 2. + (arr[idx, 2] - arr[idx, 0] ) / delta[idx]

        # blue is max
        idx = (arr[:,:,2] == arr_max)
        out['hue'][idx] = 4. + (arr[idx, 0] - arr[idx, 1] ) / delta[idx]

        out['hue'] = (out['hue']/6.0) % 1.0
        out['light'] = l
        out['sat'] = s

        idx = (delta==0)
        out['sat'][idx] = 0.0
        out['hue'][idx] = 0.0

        # remove NaN
        flat = struct_flat(out)
        flat[np.isnan(flat)] = 0

    return out

lookup_entries = 4096

max_r = 0.9
max_g = 0.7
max_b = 1.0
max_y = 0.9


# Path: lib/color_fade.py
# class ColorFade(object):
#     """Represents the fade of one color to another"""
# 
#     def __init__(self, keyframes, steps):
#         """
#         keyframes: a list of 3-element tuples representing the colors to fade between.
#         """
# 
#         self._steps = steps
#         self.keyframes = keyframes
#         self.color_cache = np.zeros(steps + 1, dtype=dtypes.pixel_color)
# 
#         # Warmup the cache
#         for i in range(steps + 1):
#             overall_progress = float(i) * (len(self.keyframes) - 1) / self._steps
#             stage = int(overall_progress)
#             stage_progress = overall_progress - stage # 0 to 1 float
# 
#             # special case stage_progress=0, so if progress=1, we don't get
#             # an IndexError
#             if stage_progress == 0:
#                 color = self.keyframes[stage]
#             else:
#                 frame1 = self.keyframes[stage]
#                 frame1_weight = 1 - stage_progress
# 
#                 frame2 = self.keyframes[stage + 1]
#                 frame2_weight = stage_progress
# 
#                 color = tuple([c1 * frame1_weight + c2 * frame2_weight for c1, c2 in zip(frame1, frame2)])
#             self.color_cache[i] = tuple(color)
# #            print progress, self.color_cache[progress]
# 
#     def get_color(self, progress):
#         """
#         Given a progress value between 0 and steps, returns the color for that
#         progress as a (h, l, s) tuple with float values
#         """
# 
#         progress = clip(0, int(progress), self._steps)
# 
#         return self.color_cache[progress]
# 
# Path: lib/dtypes.py

# 
# Path: lib/buffer_utils.py
# def struct_flat(arr):
#     """
#     Returns a flattened view of a structured array whose structure elements
#     are of a homogeneous type
#     """
#     return arr.view(dtype=arr.dtype[0])


# Path: lib/colors.py
from lib.color_fade import ColorFade
from lib import dtypes
from lib.buffer_utils import struct_flat
import colorsys
import numpy as np


        # green is max
        idx = (arr[:,:,1] == arr_max)
        out['hue'][idx] = 2. + (arr[idx, 2] - arr[idx, 0] ) / delta[idx]

        # blue is max
        idx = (arr[:,:,2] == arr_max)
        out['hue'][idx] = 4. + (arr[idx, 0] - arr[idx, 1] ) / delta[idx]

        out['hue'] = (out['hue']/6.0) % 1.0
        out['light'] = l
        out['sat'] = s

        idx = (delta==0)
        out['sat'][idx] = 0.0
        out['hue'][idx] = 0.0

        # remove NaN
        flat = struct_flat(out)
        flat[np.isnan(flat)] = 0

    return out

lookup_entries = 4096

max_r = 0.9
max_g = 0.7
max_b = 1.0
max_y = 0.9


hue_lookup = ColorFade(