Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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