# Path: opc/drivers/baseclass.py
# class RopDriver(object):
# 
#     def __init__(self, width, height, address):
#         raise NotImplementedError
# 
#     def send(self, packet):
#         raise NotImplementedError
# 
#     def putPixels(self, channel, *sources):
#         raise NotImplementedError
# 
#     def setFirmwareConfig(self, nodither=False, nointerp=False,
#                           manualled=False, ledonoff=True):
#         raise NotImplementedError
# 
#     def setGlobalColorCorrection(self, gamma, r, g, b):
#         raise NotImplementedError
# 
#     def terminate(self):
#         raise NotImplementedError
# 
# 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 curses
import numpy as np
from opc.drivers.baseclass import RopDriver
from opc.error import TtyTooSmall
from opc.utils.prof import timefunc
                curses.color_pair(curses.COLOR_BLUE)+curses.A_BOLD,     # ax
                curses.color_pair(curses.COLOR_YELLOW),                 # ax
                curses.color_pair(curses.COLOR_GREEN)+curses.A_BOLD,    # ax
                curses.color_pair(curses.COLOR_CYAN)+curses.A_BOLD,     # ax
                curses.color_pair(curses.COLOR_RED)+curses.A_BOLD,
                curses.color_pair(curses.COLOR_RED)+curses.A_BOLD,      # ax
                curses.color_pair(curses.COLOR_MAGENTA)+curses.A_BOLD,
                curses.color_pair(curses.COLOR_YELLOW),                 # ax
                curses.color_pair(curses.COLOR_RED)+curses.A_BOLD,      # ax
                curses.color_pair(curses.COLOR_MAGENTA)+curses.A_BOLD,  # ax
                curses.color_pair(curses.COLOR_YELLOW)+curses.A_BOLD,
                curses.color_pair(curses.COLOR_YELLOW)+curses.A_BOLD,   # ax
                curses.color_pair(curses.COLOR_WHITE)+curses.A_BOLD,
            ]

    @timefunc
    def _addstr(self, pixel):
        global stdscr

        stdscr.addstr(self.chars[pixel[0]]*2, self.colors[pixel[1]])

    @timefunc
    def _char(self, pixels):
        return (np.sum(pixels, axis=2) / 85).astype(dtype=np.uint8)

    @timefunc
    def _colorindex(self, pixels):
        # map 0 - 256 to  0 - c_mod
        return np.round(pixels / (256 / (self.c_mod - 1)))


# Path: opc/drivers/baseclass.py
# class RopDriver(object):
# 
#     def __init__(self, width, height, address):
#         raise NotImplementedError
# 
#     def send(self, packet):
#         raise NotImplementedError
# 
#     def putPixels(self, channel, *sources):
#         raise NotImplementedError
# 
#     def setFirmwareConfig(self, nodither=False, nointerp=False,
#                           manualled=False, ledonoff=True):
#         raise NotImplementedError
# 
#     def setGlobalColorCorrection(self, gamma, r, g, b):
#         raise NotImplementedError
# 
#     def terminate(self):
#         raise NotImplementedError
# 
# 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/drivers/ansi.py
import curses
import numpy as np
from opc.drivers.baseclass import RopDriver
from opc.error import TtyTooSmall
from opc.utils.prof import timefunc

                curses.color_pair(curses.COLOR_BLUE)+curses.A_BOLD,     # ax
                curses.color_pair(curses.COLOR_YELLOW),                 # ax
                curses.color_pair(curses.COLOR_GREEN)+curses.A_BOLD,    # ax
                curses.color_pair(curses.COLOR_CYAN)+curses.A_BOLD,     # ax
                curses.color_pair(curses.COLOR_RED)+curses.A_BOLD,
                curses.color_pair(curses.COLOR_RED)+curses.A_BOLD,      # ax
                curses.color_pair(curses.COLOR_MAGENTA)+curses.A_BOLD,
                curses.color_pair(curses.COLOR_YELLOW),                 # ax
                curses.color_pair(curses.COLOR_RED)+curses.A_BOLD,      # ax
                curses.color_pair(curses.COLOR_MAGENTA)+curses.A_BOLD,  # ax
                curses.color_pair(curses.COLOR_YELLOW)+curses.A_BOLD,
                curses.color_pair(curses.COLOR_YELLOW)+curses.A_BOLD,   # ax
                curses.color_pair(curses.COLOR_WHITE)+curses.A_BOLD,
            ]

    @timefunc
    def _addstr(self, pixel):
        global stdscr

        stdscr.addstr(self.chars[pixel[0]]*2, self.colors[pixel[1]])

    @timefunc
    def _char(self, pixels):
        return (np.sum(pixels, axis=2) / 85).astype(dtype=np.uint8)

    @timefunc
    def _colorindex(self, pixels):
        # map 0 - 256 to  0 - c_mod
        return np.round(pixels / (256 / (self.c_mod - 1)))


    @timefunc