Ejemplo n.º 1
0
def blit_array(surface, array):
    """
    Generates image pixels from a JNumeric array.
    Arguments include destination Surface and array of integer colors.
    JNumeric required as specified in numeric module.
    """
    if not _initialized:
        _init()
    if len(array.shape) == 2:
        data = numeric.transpose(array, (1,0))
        data = numeric.ravel(data)
    else:
        data = array[:,:,0]*0x10000 | array[:,:,1]*0x100 | array[:,:,2]
        data = numeric.transpose(data, (1,0))
        data = numeric.ravel(data)
    if not surface.getColorModel().hasAlpha():
        surface.setRGB(0, 0, surface.width, surface.height,
                       data, 0, surface.width)
    else:
        surf = Surface((surface.width, surface.height),
                       BufferedImage.TYPE_INT_RGB)
        surf.setRGB(0, 0, surface.width, surface.height,
                    data, 0, surface.width)
        g2d = surface.createGraphics()
        g2d.drawImage(surf, 0, 0, None)
        g2d.dispose()
    return None
Ejemplo n.º 2
0
def create_cursor(size, data, mask):
    """
    Create cursor image from binary data.
    Arguments cursor size and its binary data and mask.
    Return surface, can be used with mouse.set_cursor.
    """
    surface = Surface(size, Const.SRCALPHA)
    black = Color(0, 0, 0, 255).getRGB()
    white = Color(255, 255, 255, 255).getRGB()
    x = y = 0
    for i in range(len(data)):
        if data[i] or mask[i]:
            for j in range(8):
                if data[i] & 0x01 << 7 - j:
                    surface.setRGB(x + j, y, black)
                elif mask[i] & 0x01 << 7 - j:
                    surface.setRGB(x + j, y, white)
        x += 8
        if x >= size[0]:
            x = 0
            y += 1
    return surface
Ejemplo n.º 3
0
 def blit_array(self, surface, array):
     """
     Generates image pixels from a JNumeric array.
     Arguments include surface to generate the image, and array of integer colors.
     """
     if not self.initialized:
         self._init()
     if len(array.shape) == 2:
         data = numeric.transpose(array, (1,0))
         data = numeric.ravel(data)
     else:
         data = array[:,:,0]*0x10000 | array[:,:,1]*0x100 | array[:,:,2]
         data = numeric.transpose(data, (1,0))
         data = numeric.ravel(data)
     if not surface.getColorModel().hasAlpha():
         surface.setRGB(0, 0, surface.width, surface.height, data, 0, surface.width)
     else:
         surf = Surface((surface.width,surface.height), BufferedImage.TYPE_INT_RGB)
         surf.setRGB(0, 0, surface.width, surface.height, data, 0, surface.width)
         g2d = surface.createGraphics()
         g2d.drawImage(surf, 0, 0, None)
         g2d.dispose()
     return None
Ejemplo n.º 4
0
def create_cursor(size, data, mask):
    """
    Create cursor image from binary data.
    Arguments cursor size and its binary data and mask.
    Return surface, can be used with mouse.set_cursor.
    """
    surface = Surface(size, Const.SRCALPHA)
    black = Color(0,0,0,255).getRGB()
    white = Color(255,255,255,255).getRGB()
    x = y = 0
    rang = range(8)
    for i in range(len(data)):
        if data[i] or mask[i]:
            for j in rang:
                if data[i] & 0x01<<7-j:
                    surface.setRGB(x+j, y, black)
                elif mask[i] & 0x01<<7-j:
                    surface.setRGB(x+j, y, white)
        x += 8
        if x >= size[0]:
            x = 0
            y += 1
    return surface