def wrap(self, image):
        """
        Wraps a nested python sequence or PIL/pillow Image.
        """
        if hasattr(image, 'size') and hasattr(image, 'convert'):
            # Treat image as PIL/pillow Image object
            self.width, self.height = image.size
            array_type = ctypes.c_ubyte * 4 * (self.width * self.height)
            self.pixels_array = array_type()
            pixels = image.convert('RGBA').getdata()
            for i, pixel in enumerate(pixels):
                self.pixels_array[i] = pixel
        else:
            self.width, self.height, pixels = image
            array_type = ctypes.c_ubyte * 4 * self.width * self.height
            self.pixels_array = array_type()
            for i in range(self.height):
                for j in range(self.width):
                    for k in range(4):
                        self.pixels_array[i][j][k] = pixels[i][j][k]
        pointer_type = ctypes.POINTER(ctypes.c_ubyte)
        self.pixels = ctypes.cast(self.pixels_array, pointer_type)
def wrap ( self , image ) : if hasattr ( image , 'size' ) and hasattr ( image , 'convert' ) : self . width , self . height = image . size array_type = ctypes . c_ubyte * 4 * ( self . width * self . height ) self . pixels_array = array_type ( ) pixels = image . convert ( 'RGBA' ) . getdata ( ) for i , pixel in enumerate ( pixels ) : self . pixels_array [ i ] = pixel else : self . width , self . height , pixels = image array_type = ctypes . c_ubyte * 4 * self . width * self . height self . pixels_array = array_type ( ) for i in range ( self . height ) : for j in range ( self . width ) : for k in range ( 4 ) : self . pixels_array [ i ] [ j ] [ k ] = pixels [ i ] [ j ] [ k ] pointer_type = ctypes . POINTER ( ctypes . c_ubyte ) self . pixels = ctypes . cast ( self . pixels_array , pointer_type )
Wraps a nested python sequence or PIL/pillow Image.