# Path: opc/image.py
# class Image(object):
# 
#     def __init__(self, filename=None, bytestream=None):
#         if filename is not None:
#             image = PI.open(filename).rotate(-90, PI.BICUBIC).convert('RGB')
#             self.image = image
# 
#         if bytestream is not None:
#             self.image = PI.open(BytesIO(bytestream))
# 
#         self.width, self.height = self.image.size
# 
#     @timefunc
#     def translate(self, matrix, scale=0, x=0, y=0):
#         i = self.image.copy()
#         if scale == 0:
#             i = self.image.resize((matrix.height, matrix.width), PI.ANTIALIAS)
#         else:
#             i = self.image.resize((int(self.height/scale),
#                                    int(self.width/scale)), PI.ANTIALIAS)
# 
#         return np.asarray(i.crop((y, x, y+matrix.height, x+matrix.width)))


from ._baseclass import ArtBaseClass
    from thread import start_new_thread, allocate_lock
    from _thread import start_new_thread, allocate_lock
from opc.image import Image
import requests
import logging

    def start(self, matrix):
        matrix.clear()

    def _load(self):
        self.image_loaded = None
        start_new_thread(Art._loadthread, (self,))

    def _consume(self, matrix):
        if not self.image_loaded:
            return False

        self.image_active = self.image_loaded
        self._load()

        self.position = position(matrix, self.image_active)

        return True

    def _loadthread(self):
        logging.info("_loadthread begin")
        try:
            r = requests.get(self.url)
            if r.status_code == 200:
                self.image_loaded = Image(bytestream=r.content)
            else:
                logging.error("_loadthread   code %d, using fallback"%r.status_code)
                self.image_loaded = Image(filename="assets/images/lena.jpg")
        except Exception as e:
            logging.error("_loadthread   exception '%s', using fallback"%str(e))

# Path: opc/image.py
# class Image(object):
# 
#     def __init__(self, filename=None, bytestream=None):
#         if filename is not None:
#             image = PI.open(filename).rotate(-90, PI.BICUBIC).convert('RGB')
#             self.image = image
# 
#         if bytestream is not None:
#             self.image = PI.open(BytesIO(bytestream))
# 
#         self.width, self.height = self.image.size
# 
#     @timefunc
#     def translate(self, matrix, scale=0, x=0, y=0):
#         i = self.image.copy()
#         if scale == 0:
#             i = self.image.resize((matrix.height, matrix.width), PI.ANTIALIAS)
#         else:
#             i = self.image.resize((int(self.height/scale),
#                                    int(self.width/scale)), PI.ANTIALIAS)
# 
#         return np.asarray(i.crop((y, x, y+matrix.height, x+matrix.width)))


# Path: art/panimage.py
from ._baseclass import ArtBaseClass
    from thread import start_new_thread, allocate_lock
    from _thread import start_new_thread, allocate_lock
from opc.image import Image
import requests
import logging


    def start(self, matrix):
        matrix.clear()

    def _load(self):
        self.image_loaded = None
        start_new_thread(Art._loadthread, (self,))

    def _consume(self, matrix):
        if not self.image_loaded:
            return False

        self.image_active = self.image_loaded
        self._load()

        self.position = position(matrix, self.image_active)

        return True

    def _loadthread(self):
        logging.info("_loadthread begin")
        try:
            r = requests.get(self.url)
            if r.status_code == 200:
                self.image_loaded = Image(bytestream=r.content)
            else:
                logging.error("_loadthread   code %d, using fallback"%r.status_code)
                self.image_loaded = Image(filename="assets/images/lena.jpg")
        except Exception as e:
            logging.error("_loadthread   exception '%s', using fallback"%str(e))

            self.image_loaded = Image(filename="assets/images/lena.jpg")