Exemple #1
0
 def test_get_rgba(self):
     # TODO: invalid parameters
     pformat = pixels.alloc_format(pixels.SDL_PIXELFORMAT_RGBA8888)
     self.assertIsInstance(pformat, pixels.SDL_PixelFormat)
     rgba = pixels.get_rgba(0xFFAA8811, pformat)
     self.assertEqual(rgba, (0xFF, 0xAA, 0x88, 0x11))
     rgba = pixels.get_rgba(0x00000000, pformat)
     self.assertEqual(rgba, (0x00, 0x00, 0x00, 0x00))
     rgba = pixels.get_rgba(0xFFFFFFFF, pformat)
     self.assertEqual(rgba, (0xFF, 0xFF, 0xFF, 0xFF))
     rgba = pixels.get_rgba(0x11223344, pformat)
     self.assertEqual(rgba, (0x11, 0x22, 0x33, 0x44))
     pixels.free_format(pformat)
     fmts = (pixels.SDL_PIXELFORMAT_INDEX1LSB,
             pixels.SDL_PIXELFORMAT_INDEX1MSB)
     for fmt in fmts:
         pformat = pixels.alloc_format(fmt)
         self.assertIsInstance(pformat, pixels.SDL_PixelFormat)
         rgba = pixels.get_rgba(0x11223344, pformat)
         self.assertEqual(rgba, (0xFF, 0xFF, 0xFF, 0xFF))
         rgba = pixels.get_rgba(0x00000000, pformat)
         # TODO: Seems to be always(0xFF, 0xFF, 0xFF) ???
         #self.assertEqual(rgb,(0x00, 0x00, 0x00))
         pixels.free_format(pformat)
     fmts = (pixels.SDL_PIXELFORMAT_INDEX4LSB,
             pixels.SDL_PIXELFORMAT_INDEX4MSB)
     for fmt in fmts:
         pformat = pixels.alloc_format(fmt)
         self.assertIsInstance(pformat, pixels.SDL_PixelFormat)
         # TODO
         pixels.free_format(pformat)
Exemple #2
0
    def test_alloc_free_format(self):
        pformat = pixels.alloc_format(pixels.SDL_PIXELFORMAT_RGBA8888)
        self.assertIsInstance(pformat, pixels.SDL_PixelFormat)
        self.assertEqual(pformat.format, pixels.SDL_PIXELFORMAT_RGBA8888)
        self.assertEqual(pformat.BitsPerPixel, 32)
        self.assertEqual(pformat.BytesPerPixel, 4)
        pixels.free_format(pformat)

        pformat = pixels.alloc_format(pixels.SDL_PIXELFORMAT_INDEX1LSB)
        self.assertIsInstance(pformat, pixels.SDL_PixelFormat)
        self.assertEqual(pformat.format, pixels.SDL_PIXELFORMAT_INDEX1LSB)
        self.assertEqual(pformat.BitsPerPixel, 1)
        self.assertEqual(pformat.BytesPerPixel, 1)
        pixels.free_format(pformat)

        pformat = pixels.alloc_format(pixels.SDL_PIXELFORMAT_INDEX4MSB)
        self.assertIsInstance(pformat, pixels.SDL_PixelFormat)
        self.assertEqual(pformat.format, pixels.SDL_PIXELFORMAT_INDEX4MSB)
        self.assertEqual(pformat.BitsPerPixel, 4)
        self.assertEqual(pformat.BytesPerPixel, 1)
        pixels.free_format(pformat)

        self.assertRaises(sdl.SDLError, pixels.alloc_format,
                           pixels.SDL_PIXELFORMAT_UYVY)
        self.assertRaises(sdl.SDLError, pixels.alloc_format,
                           pixels.SDL_PIXELFORMAT_YUY2)
Exemple #3
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)
Exemple #4
0
 def test_get_set_color_key(self):
     colorkeys = ((0, 0, 0),
                  (32, 64, 128),
                  (10, 20, 30),
                  (1, 2, 4),
                  (255, 255, 255),
                  (128, 128, 128),
                  (127, 127, 127),
                  )
     for fmt in pixels.ALL_PIXELFORMATS:
         if pixels.SDL_ISPIXELFORMAT_FOURCC(fmt):
             continue
         pformat = pixels.alloc_format(fmt)
         bpp, rmask, gmask, bmask, amask = \
             pixels.pixelformat_enum_to_masks(fmt)
         sf = surface.create_rgb_surface(10, 10, bpp, rmask, gmask, bmask,
                                         amask)
         for r, g, b in colorkeys:
             key = pixels.map_rgb(pformat, r, g, b)
             surface.set_color_key(sf, 1, key)
             skey = surface.get_color_key(sf)
             self.assertEqual(skey, key,
                 "Could not set color key (%d, %d, %d)" % (r, g, b))
         pixels.free_format(pformat)
         surface.free_surface(sf)
Exemple #5
0
 def test_set_pixelformat_palette(self):
     palette = pixels.alloc_palette(10)
     self.assertIsInstance(palette, pixels.SDL_Palette)
     pformat = pixels.alloc_format(pixels.SDL_PIXELFORMAT_RGBA8888)
     self.assertIsInstance(pformat, pixels.SDL_PixelFormat)
     pixels.set_pixelformat_palette(pformat, palette)
     # TODO: improve tests
     pixels.free_format(pformat)
     pixels.free_palette(palette)
Exemple #6
0
    def test_convert_surface(self):
        pfmt = pixels.alloc_format(pixels.SDL_PIXELFORMAT_RGB444)
        for fmt in pixels.ALL_PIXELFORMATS:
            if pixels.SDL_ISPIXELFORMAT_FOURCC(fmt):
                continue
            if fmt in (pixels.SDL_PIXELFORMAT_RGB332,
                       pixels.SDL_PIXELFORMAT_ARGB2101010):
                # SDL2 segfault in the DUFFS_LOOOP() macros
                # http://bugzilla.libsdl.org/show_bug.cgi?id=1534
                continue
            bpp, rmask, gmask, bmask, amask = \
                pixels.pixelformat_enum_to_masks(fmt)
            sf = surface.create_rgb_surface(10, 20, bpp, rmask, gmask,
                                            bmask, amask)
            self.assertIsInstance(sf, surface.SDL_Surface)
            csf = surface.convert_surface(sf, pfmt, 0)
            self.assertIsInstance(csf, surface.SDL_Surface)
            surface.free_surface(sf)
            surface.free_surface(csf)

        sf = surface.create_rgb_surface(10, 10, 32, 0, 0, 0)
        self.assertRaises((AttributeError, TypeError),
                          surface.convert_surface, None, None, None)
        self.assertRaises((AttributeError, TypeError),
                          surface.convert_surface, sf, None, None)
        self.assertRaises((AttributeError, TypeError),
                          surface.convert_surface, sf, "Test", 0)
        self.assertRaises((AttributeError, TypeError),
                          surface.convert_surface, sf, 12345, 0)
        self.assertRaises((AttributeError, TypeError),
                          surface.convert_surface, None, pfmt, 0)
        self.assertRaises((AttributeError, TypeError),
                          surface.convert_surface, "Test", pfmt, 0)
        self.assertRaises((AttributeError, TypeError),
                          surface.convert_surface, 12345, pfmt, 0)
        pixels.free_format(pfmt)
        surface.free_surface(sf)