Example #1
0
    def test_map_rgba(self):
        pformat = pixels.alloc_format(pixels.SDL_PIXELFORMAT_RGBA8888)
        self.assertIsInstance(pformat, pixels.SDL_PixelFormat)
        val = pixels.map_rgba(pformat, 0xFF, 0xAA, 0x88, 0x11)
        self.assertEqual(val, 0xFFAA8811)
        pixels.free_format(pformat)

        pformat = pixels.alloc_format(pixels.SDL_PIXELFORMAT_UNKNOWN)
        self.assertIsInstance(pformat, pixels.SDL_PixelFormat)
        self.assertEqual(pformat.format, pixels.SDL_PIXELFORMAT_UNKNOWN)
        val = pixels.map_rgba(pformat, 0xFF, 0xAA, 0x88, 0x11)
        self.assertEqual(val, 0x0)
        pixels.free_format(pformat)
Example #2
0
 def test_render_draw_point(self):
     points = ((-4, -3), (-4, 3), (4, -3),
               (0, 0), (1, 1), (10, 10), (99, 99),
               (4, 22), (57, 88), (45, 15),
               (100, 100)
               )
     r, g, b, a = 0xAA, 0xBB, 0xCC, 0xDD
     w, h = 100, 100
     sf = surface.create_rgb_surface(w, h, 32, 0xFF000000, 0x00FF0000,
                                     0x0000FF00, 0x000000FF)
     color = pixels.map_rgba(sf.format, r, g, b, a)
     renderer = render.create_software_renderer(sf)
     render.set_render_draw_color(renderer, r, g, b, a)
     for x, y in points:
         render.render_draw_point(renderer, x, y)
     render.render_present(renderer)
     view = pvid.PixelView(sf)
     for x, y in points:
         npx = max(x + 1, w)
         npy = max(y + 1, h)
         ppx = max(x - 1, 0)
         ppy = max(y - 1, 0)
         if x < 0 or x >= w or y < 0 or y >= h:
             continue
         self.assertEqual(hex(view[y][x]), hex(color))
         if (npx, npy) not in points:
             self.assertNotEqual(hex(view[npy][npx]), hex(color))
         if (ppx, ppy) not in points:
             self.assertNotEqual(hex(view[ppy][ppx]), hex(color))
     render.destroy_renderer(renderer)
     del view
     surface.free_surface(sf)
Example #3
0
 def from_color(self, color, size=(0, 0), bpp=32, masks=None):
     """Creates a sprite with a certain color.
     """
     color = convert_to_color(color)
     if masks:
         rmask, gmask, bmask, amask = masks
     else:
         rmask = gmask = bmask = amask = 0
     sf = sdlsurface.create_rgb_surface(size[0], size[1], bpp, rmask, gmask, bmask, amask)
     fmt = sf.format
     if fmt.Amask != 0:
         # Target has an alpha mask
         c = pixels.map_rgba(fmt, color.r, color.g, color.b, color.a)
     else:
         c = pixels.map_rgb(fmt, color.r, color.g, color.b)
     sdlsurface.fill_rect(sf, None, c)
     return self.from_surface(sf, True)
Example #4
0
def prepare_color(color, target):
    """Prepares the passed color for the passed target.
    """
    color = convert_to_color(color)
    pformat = None
    # Software surfaces
    if isinstance(target, sdlpixels.SDL_PixelFormat):
        pformat = target
    elif isinstance(target, sdlsurface.SDL_Surface):
        pformat = target.format
    elif isinstance(target, SoftwareSprite):
        pformat = target.surface.format
    if pformat is None:
        raise TypeError("unsupported target type")
    if pformat.Amask != 0:
        # Target has an alpha mask
        return sdlpixels.map_rgba(pformat, color.r, color.g, color.b, color.a)
    return sdlpixels.map_rgb(pformat, color.r, color.g, color.b)
Example #5
0
File: gl.py Project: lxnt/fgtestbed
 def fill(self, color):
     """ expects RGBA8888 4-tuple """
     color = sdlpixels.map_rgba(self._surf.format, *color)
     sdlsurface.fill_rect(self._surf, None, color)