Beispiel #1
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 #2
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)