Beispiel #1
0
    def test_SDL_MapRGB(self):
        pformat = pixels.SDL_AllocFormat(pixels.SDL_PIXELFORMAT_RGBA8888)
        assert isinstance(pformat.contents, pixels.SDL_PixelFormat)
        val = pixels.SDL_MapRGB(pformat, 0xFF, 0xAA, 0x88)
        assert val == 0xFFAA88FF
        pixels.SDL_FreeFormat(pformat)

        pformat = pixels.SDL_AllocFormat(pixels.SDL_PIXELFORMAT_UNKNOWN)
        assert isinstance(pformat.contents, pixels.SDL_PixelFormat)
        assert pformat.contents.format == pixels.SDL_PIXELFORMAT_UNKNOWN
        val = pixels.SDL_MapRGB(pformat, 0xFF, 0xAA, 0x88)
        assert val == 0x0
        pixels.SDL_FreeFormat(pformat)
    def test_SDL_MapRGB(self):
        pformat = pixels.SDL_AllocFormat(pixels.SDL_PIXELFORMAT_RGBA8888)
        self.assertIsInstance(pformat.contents, pixels.SDL_PixelFormat)
        val = pixels.SDL_MapRGB(pformat, 0xFF, 0xAA, 0x88)
        self.assertEqual(val, 0xFFAA88FF)
        pixels.SDL_FreeFormat(pformat)

        pformat = pixels.SDL_AllocFormat(pixels.SDL_PIXELFORMAT_UNKNOWN)
        self.assertIsInstance(pformat.contents, pixels.SDL_PixelFormat)
        self.assertEqual(pformat.contents.format,
                         pixels.SDL_PIXELFORMAT_UNKNOWN)
        val = pixels.SDL_MapRGB(pformat, 0xFF, 0xAA, 0x88)
        self.assertEqual(val, 0x0)
        pixels.SDL_FreeFormat(pformat)
Beispiel #3
0
 def test_SDL_GetSetColorKey(self):
     colorkeys = (
         (0, 0, 0),
         (32, 64, 128),
         (10, 20, 30),
         (1, 2, 4),
         (255, 255, 255),
         (128, 128, 128),
         (127, 127, 127),
     )
     bpp = c_int()
     rmask, gmask, bmask, amask = Uint32(), Uint32(), Uint32(), Uint32()
     for fmt in pixels.ALL_PIXELFORMATS:
         if pixels.SDL_ISPIXELFORMAT_FOURCC(fmt):
             continue
         pformat = pixels.SDL_AllocFormat(fmt)
         self.assertIsInstance(pformat.contents, pixels.SDL_PixelFormat)
         ret = pixels.SDL_PixelFormatEnumToMasks(fmt, byref(bpp),
                                                 byref(rmask), byref(gmask),
                                                 byref(bmask), byref(amask))
         self.assertEqual(ret, SDL_TRUE)
         sf = surface.SDL_CreateRGBSurface(0, 10, 10, bpp, rmask, gmask,
                                           bmask, amask)
         for r, g, b in colorkeys:
             key = pixels.SDL_MapRGB(pformat, r, g, b)
             surface.SDL_SetColorKey(sf, 1, key)
             skey = Uint32()
             ret = surface.SDL_GetColorKey(sf, byref(skey))
             self.assertEqual(ret, 0)
             self.assertEqual(
                 skey.value, key,
                 "Could not set color key (%d, %d, %d)" % (r, g, b))
         pixels.SDL_FreeFormat(pformat)
         surface.SDL_FreeSurface(sf)
Beispiel #4
0
 def test_SDL_HasColorKey(self):
     sf = surface.SDL_CreateRGBSurface(0, 10, 10, 32, 0, 0, 0, 0)
     assert surface.SDL_HasColorKey(sf) == SDL_FALSE
     key = pixels.SDL_MapRGB(sf.contents.format, 255, 255, 255)
     surface.SDL_SetColorKey(sf, 1, key)
     assert surface.SDL_HasColorKey(sf) == SDL_TRUE
     surface.SDL_FreeSurface(sf)