def array(self, surface): """ Return data array of the Surface argument. Array consists of pixel data arranged by [y,x] in RGBA format. Data array most consistent to ImageData format. """ imagedata = surface.impl.getImageData(0, 0, surface.width, surface.height) return PyImageMatrix(imagedata)
def blit_array(self, surface, array): """ Generates image pixels from array data. Arguments include surface to generate the image, and array containing image data. """ try: imagedata = array.getImageData() except (TypeError, AttributeError): #-O/-S: TypeError/AttributeError imagedata = surface.impl.getImageData(0, 0, surface.width, surface.height) if len(array._shape) == 2: array2d = PyImageMatrix(imagedata) for y in xrange(array2d.getHeight()): for x in xrange(array2d.getWidth()): value = array[x,y] array2d[y,x] = (value>>16 & 0xff, value>>8 & 0xff, value & 0xff, 255) imagedata = array2d.getImageData() else: imagedata.data.set(array.getArray()) surface.impl.putImageData(imagedata, 0, 0, 0, 0, surface.width, surface.height) return None
def blit_array(self, surface, array): """ Generates image pixels from array data. Arguments include surface to generate the image, and array containing image data. """ try: imagedata = array.getImageData() except (TypeError, AttributeError): #-O/-S: TypeError/AttributeError imagedata = surface.impl.getImageData(0, 0, surface.width, surface.height) if len(array._shape) == 2: array2d = PyImageMatrix(imagedata) for y in xrange(array2d.getHeight()): for x in xrange(array2d.getWidth()): value = array[x, y] array2d[y, x] = (value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff, 255) imagedata = array2d.getImageData() else: imagedata.data.set(array.getArray()) surface.impl.putImageData(imagedata, 0, 0, 0, 0, surface.width, surface.height) return None
def __setitem__(self, index, value): return PyImageMatrix.__setitem__( self, (index[1], index[0]), (value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff, value >> 24 & 0xff))
def __getitem__(self, index): value = PyImageMatrix.__getitem__(self, (index[1], index[0])) return value[0] << 16 | value[1] << 8 | value[2] | value[3] << 24
def __setitem__(self, index, value): return PyImageMatrix.__setitem__(self, (index[1], index[0], 3), value)
def __getitem__(self, index): return PyImageMatrix.__getitem__(self, (index[1], index[0], 3))
def __setitem__(self, index, value): index = list(index) index[0], index[1] = index[1], index[0] index = tuple(index) return PyImageMatrix.__setitem__(self, index, value)
def __setitem__(self, index, value): return PyImageMatrix.__setitem__(self, (index[1],index[0]), (value>>16 & 0xff, value>>8 & 0xff, value & 0xff, value>>24 & 0xff))
def __getitem__(self, index): value = PyImageMatrix.__getitem__(self, (index[1],index[0])) return value[0]<<16 | value[1]<<8 | value[2] | value[3]<<24
def __setitem__(self, index, value): return PyImageMatrix.__setitem__(self, (index[1],index[0],3), value)
def __getitem__(self, index): return PyImageMatrix.__getitem__(self, (index[1],index[0],3))