Ejemplo n.º 1
0
 def test_lock_unlock_MUSTLOCK_surface(self):
     colormods = ((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
         bpp, rmask, gmask, bmask, amask = \
             pixels.pixelformat_enum_to_masks(fmt)
         sf = surface.create_rgb_surface(10, 10, bpp, rmask, gmask, bmask,
                                         amask)
         # TODO: locking seems to be only necessary for RLE surfaces...
         if surface.SDL_MUSTLOCK(sf):
             self.assertFalse(sf.locked)
             surface.lock_surface(sf)
             self.assertTrue(sf.locked)
             surface.lock_surface(sf)
             self.assertTrue(sf.locked)
             surface.lock_surface(sf)
             self.assertTrue(sf.locked)
             surface.unlock_surface(sf)
             self.assertTrue(sf.locked)
             surface.unlock_surface(sf)
             self.assertTrue(sf.locked)
             surface.unlock_surface(sf)
             self.assertFalse(sf.locked)
         surface.free_surface(sf)
Ejemplo n.º 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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
    def test_get_set_clip_rect(self):
        rectlist = ((rect.SDL_Rect(0, 0, 0, 0), False, False),
                    (rect.SDL_Rect(2, 2, 0, 0), False, False),
                    (rect.SDL_Rect(2, 2, 5, 1), True, True),
                    (rect.SDL_Rect(6, 5, 10, 3), True, False),
                    (rect.SDL_Rect(0, 0, 10, 10), True, True),
                    (rect.SDL_Rect(0, 0, -10, 10), False, False),
                    (rect.SDL_Rect(0, 0, -10, -10), False, False),
                    (rect.SDL_Rect(-10, -10, 10, 10), False, False),
                    (rect.SDL_Rect(10, -10, 10, 10), False, False),
                    (rect.SDL_Rect(10, 10, 10, 10), True, False)
                    )

        sf = surface.create_rgb_surface(15, 15, 32)
        clip = surface.get_clip_rect(sf)
        self.assertIsInstance(clip, rect.SDL_Rect)
        self.assertEqual(clip, rect.SDL_Rect(0, 0, 15, 15))

        for r, clipsetval, cmpval in rectlist:
            retval = surface.set_clip_rect(sf, r)
            clip = surface.get_clip_rect(sf)
            self.assertEqual(retval, clipsetval,
                "Could not set clip rect %s" % r)
            self.assertEqual(clip == r, cmpval,
                "Could not set clip rect %s" % r)
        surface.free_surface(sf)
Ejemplo n.º 5
0
Archivo: gl.py Proyecto: lxnt/fgtestbed
 def __init__(self, w = None, h = None, data_ptr = None, surface = None,
                 filename = None, filedata = None):
     self.do_free = True
     if filedata is not None:
         if type(filedata) is bytes:
             imagedata = bytearray(filedata)
         if type(filedata) is bytearray:
             rwops = sdlrwops.rw_from_mem(bar2voidp(filedata).value, len(filedata))
         elif hasattr(filedata, "seek"):
             rwops = sdlrwops.rw_from_object(filedata)
         else:
             raise TypeError("unusable data type {}", str(type(filedata)))
         self._surf = sdlimage.load_rw(rwops, 1)
     elif isinstance(filename, str):
         self._surf = sdlimage.load(filename)
     elif isinstance(w, int) and isinstance(h, int):
         masks = list(sdlpixels.pixelformat_enum_to_masks(self.sdl_pixel_fmt))
         bpp = masks.pop(0)
         if data_ptr is None:
             self._surf = sdlsurface.create_rgb_surface(w, h, bpp, *masks)
         else: # data_ptr == ABGR8888
             self._surf = sdlsurface.create_rgb_surface_from(data_ptr, w, h, bpp, w*4, *masks)
     elif isinstance(surface, SDL_Surface):
         self.do_free = False
         self._surf = surface
     else:
         raise TypeError("Crazy shit in parameters: ({} {} {} {} {})".format(type(w),
                 type(h), type(data_ptr), type(surface), type(filename)))
         
     sdlsurface.set_surface_blend_mode(self._surf, sdlvideo.SDL_BLENDMODE_NONE)
Ejemplo n.º 6
0
    def test_fill_rects(self):
        rectlist = (rect.SDL_Rect(0, 0, 0, 0),
                    rect.SDL_Rect(0, 0, 10, 10),
                    rect.SDL_Rect(0, 0, -10, 10),
                    rect.SDL_Rect(0, 0, -10, -10),
                    rect.SDL_Rect(-10, -10, 10, 10),
                    rect.SDL_Rect(10, -10, 10, 10),
                    rect.SDL_Rect(10, 10, 10, 10),
                    )

        for fmt in pixels.ALL_PIXELFORMATS:
            if pixels.SDL_ISPIXELFORMAT_FOURCC(fmt):
                continue
            if pixels.SDL_BITSPERPIXEL(fmt) < 8:
                continue  # Skip < 8bpp, SDL_FillRect does not work on those
            for w in range(1, 100, 5):
                for h in range(1, 100, 5):
                    bpp, rmask, gmask, bmask, amask = \
                        pixels.pixelformat_enum_to_masks(fmt)
                    sf = surface.create_rgb_surface(w, h, bpp, rmask, gmask,
                                                    bmask, amask)
                    self.assertIsInstance(sf, surface.SDL_Surface)
                    # TODO: check for changed pixels
                    surface.fill_rects(sf, rectlist, 0xff00ff00)
                    surface.free_surface(sf)
Ejemplo n.º 7
0
    def test_load_texture(self):
        sf = surface.create_rgb_surface(10, 10, 32)
        rd = render.create_software_renderer(sf)

        fname = "surfacetest.%s"
        for fmt in formats:
            filename = RESOURCES.get_path(fname % fmt)
            tex = sdlimage.load_texture(rd, filename)
            self.assertIsInstance(tex, render.SDL_Texture)
            render.destroy_texture(tex)

        self.assertRaises(sdl.SDLError, sdlimage.load_texture, rd, RESOURCES.get_path("rwopstest.txt"))

        self.assertRaises(sdl.SDLError, sdlimage.load_texture, rd, None)
        self.assertRaises(sdl.SDLError, sdlimage.load_texture, rd, 1234)
        self.assertRaises(
            (AttributeError, TypeError), sdlimage.load_texture, None, RESOURCES.get_path("surfacetest.bmp")
        )
        self.assertRaises(
            (AttributeError, TypeError), sdlimage.load_texture, "Test", RESOURCES.get_path("surfacetest.bmp")
        )
        self.assertRaises(
            (AttributeError, TypeError), sdlimage.load_texture, 1234, RESOURCES.get_path("surfacetest.bmp")
        )

        render.destroy_renderer(rd)
        surface.free_surface(sf)
Ejemplo n.º 8
0
 def test_create_texture_from_surface(self):
     sf = surface.create_rgb_surface(100, 100, 32, 0xFF000000, 0x00FF0000,
                                     0x0000FF00, 0x000000FF)
     window = video.create_window("Test", 10, 10, 10, 10,
                                  video.SDL_WINDOW_HIDDEN)
     self.assertIsInstance(window, video.SDL_Window)
     renderer = render.create_renderer(window, -1,
                                       render.SDL_RENDERER_SOFTWARE)
     self.assertIsInstance(renderer, render.SDL_Renderer)
Ejemplo n.º 9
0
    def test_create_rgb_surface(self):
        for w in range(1, 100, 5):
            for h in range(1, 100, 5):
                for bpp in alldepths:
                    sf = surface.create_rgb_surface(w, h, bpp)
                    self.assertIsInstance(sf, surface.SDL_Surface)
                    surface.free_surface(sf)

        for fmt in pixels.ALL_PIXELFORMATS:
            if pixels.SDL_ISPIXELFORMAT_FOURCC(fmt):
                continue
            for w in range(1, 100, 5):
                for h in range(1, 100, 5):
                    bpp, rmask, gmask, bmask, amask = \
                        pixels.pixelformat_enum_to_masks(fmt)
                    sf = surface.create_rgb_surface(w, h, bpp, rmask, gmask,
                                                    bmask, amask)
                    self.assertIsInstance(sf, surface.SDL_Surface)
                    surface.free_surface(sf)

        # Broken ones
        # sizes = [(0, 0), (65536, 65536)]
        # for (w, h) in sizes:
        #    for bpp in alldepths:
        #        print w, h, bpp
        #        sf = surface.create_rgb_surface(w, h, bpp)
        #        self.assertIsInstance(sf, surface.SDL_Surface)
        #        surface.free_surface(sf)
        
        # TODO: raises a SDL Out of memory error, but 65536 works?!
        #
        # sf = surface.create_rgb_surface(65535, 65535, 32)
        # self.assertIsInstance(sf, surface.SDL_Surface)
        
        self.assertRaises(sdl.SDLError, surface.create_rgb_surface, 1, 1, 66)
        self.assertRaises(sdl.SDLError, surface.create_rgb_surface, 1, 1, 0)
        self.assertRaises(sdl.SDLError, surface.create_rgb_surface, 1, 1, 8,
                          0xf0, 0x0f, 0x01, 0x02)
        self.assertRaises(sdl.SDLError, surface.create_rgb_surface, 1, 1, 16,
                          0xf0, 0x0f, 0x01, 0x02)
        self.assertRaises(sdl.SDLError, surface.create_rgb_surface, 1, 1, 24,
                          0xf0, 0x0f, 0x01, 0x02)
        self.assertRaises(sdl.SDLError, surface.create_rgb_surface, 1, 1, 32,
                          0xf0, 0x0f, 0x01, 0x02)
Ejemplo n.º 10
0
    def test_blit_surface(self):
        bpp = 32
        w, h = 10, 10
        # no alpha to prevent blending
        masks = (0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000)
        dest = surface.create_rgb_surface(w, h, bpp, masks[0], masks[1],
                                          masks[2], masks[3])
        pixelsize = h * dest.pitch
        rowlen = dest.pitch // 4

        sources = []
        for width, height in blitsizes:
            src = surface.create_rgb_surface(width, height, bpp, masks[0],
                                             masks[1], masks[2], masks[3])
            surface.fill_rect(src, None, 0xFFFFFFFF)  # fill with white
            sources.append(src)

        for src in sources:
            for pos in blitpositions:
                drect = pos.__copy__()
                surface.fill_rect(dest, None, 0x0)  # fill with black
                surface.blit_surface(src, None, dest, drect)
                buf = ctypes.cast(dest.pixels,
                                  ctypes.POINTER(ctypes.c_ubyte * pixelsize))
                pbuf = pgarray.CTypesView(buf.contents, itemsize=1,
                                          objsize=pixelsize)
                iview = pbuf.to_uint32()
                pw = drect.x + drect.w
                ph = drect.y + drect.h
                for y in range(dest.size[1]):
                    for x in range(dest.size[0]):
                        col = iview[y * rowlen + x]
                        if y >= drect.y and y < ph and \
                                x >= drect.x and x < pw:
                            self.assertEqual(col, 0xFFFFFFFF, msg="""color
mismatch at %d,%d for %s: %d != %d""" % (y, x, pos, col, 0xFFFFFFFF))
                        else:
                            self.assertEqual(col, 0x0, msg="""color mismatch
at %d,%d for %s: %d != %d""" % (y, x, pos, col, 0x0))

        while len(sources) > 0:
            sf = sources.pop()
            surface.free_surface(sf)
        surface.free_surface(dest)
Ejemplo n.º 11
0
    def test_create_software_renderer(self):
        sf = surface.create_rgb_surface(100, 100, 32, 0xFF000000, 0x00FF0000,
                                        0x0000FF00, 0x000000FF)
        renderer = render.create_software_renderer(sf)
        self.assertIsInstance(renderer, render.SDL_Renderer)
        render.destroy_renderer(renderer)
        surface.free_surface(sf)

        self.assertRaises((AttributeError, TypeError),
                          render.create_software_renderer, None)
        self.assertRaises((AttributeError, TypeError),
                          render.create_software_renderer, 1234)
Ejemplo n.º 12
0
    def test_load_texture_typed_rw(self):
        sf = surface.create_rgb_surface(10, 10, 32)
        rd = render.create_software_renderer(sf)

        fname = "surfacetest.%s"
        for fmt in formats:
            fp = RESOURCES.get(fname % fmt)
            tex = sdlimage.load_texture_typed_rw(rd, rwops.rw_from_object(fp), False, fmt.upper())
            self.assertIsInstance(tex, render.SDL_Texture)
            render.destroy_texture(tex)
        render.destroy_renderer(rd)
        surface.free_surface(sf)
Ejemplo n.º 13
0
    def test_SoftwareSprite_area(self):
        sf = create_rgb_surface(10, 10, 32)
        sprite = video.SoftwareSprite(sf, True)
        self.assertEqual(sprite.area, (0, 0, 10, 10))
        def setarea(s, v):
            s.area = v
        self.assertRaises(AttributeError, setarea, sprite, (1, 2, 3, 4))

        sprite.position = 7, 3
        self.assertEqual(sprite.area, (7, 3, 17, 13))
        sprite.position = -22, 99
        self.assertEqual(sprite.area, (-22, 99, -12, 109))
Ejemplo n.º 14
0
    def test_SoftwareSprite_position_xy(self):
        sf = create_rgb_surface(10, 10, 32)
        sprite = video.SoftwareSprite(sf, True)

        self.assertEqual(sprite.position, (0, 0))
        positions = [(x, y) for x in range(-50, 50) for y in range(-50, 50)]
        for x, y in positions:
            sprite.position = x, y
            self.assertEqual(sprite.position, (x, y))
            sprite.x = x + 1
            sprite.y = y + 1
            self.assertEqual(sprite.position, (x + 1, y + 1))
Ejemplo n.º 15
0
    def create_software_sprite(self, size=(0, 0), bpp=32, masks=None):
        """Creates a software sprite.

        A size tuple containing the width and height of the sprite and a
        bpp value, indicating the bits per pixel to be used, need to be
        provided.
        """
        if masks:
            rmask, gmask, bmask, amask = masks
        else:
            rmask = gmask = bmask = amask = 0
        surface = sdlsurface.create_rgb_surface(size[0], size[1], bpp, rmask, gmask, bmask, amask)
        return SoftwareSprite(surface, True)
Ejemplo n.º 16
0
    def test_SoftwareSprite(self):
        self.assertRaises(TypeError, video.SoftwareSprite, None, None)
        self.assertRaises(TypeError, video.SoftwareSprite, None, True)
        self.assertRaises(TypeError, video.SoftwareSprite, None, False)

        sf = create_rgb_surface(10, 10, 32)
        sprite = video.SoftwareSprite(sf, False)
        self.assertEqual(sprite.surface, sf)
        self.assertFalse(sprite.free)

        sprite = video.SoftwareSprite(sf, True)
        self.assertEqual(sprite.surface, sf)
        self.assertTrue(sprite.free)
Ejemplo n.º 17
0
    def test_SoftwareSpriteRenderer_render(self):
        sf1= create_rgb_surface(12, 7, 32)
        sp1 = video.SoftwareSprite(sf1, True)
        video.fill(sp1, 0xFF0000)

        sf2 = create_rgb_surface(3, 9, 32)
        sp2 = video.SoftwareSprite(sf2, True)
        video.fill(sp2, 0x00FF00)
        sprites = [sp1, sp2]

        window = video.Window("Test", size=(20, 20))
        renderer = video.SoftwareSpriteRenderer(window)
        self.assertIsInstance(renderer, video.SpriteRenderer)

        self.assertRaises(AttributeError, renderer.render, None, None, None)
        self.assertRaises(AttributeError, renderer.render, [None, None],
                          None, None)

        for x, y in ((0, 0), (3, 3), (20, 20), (1, 12), (5, 6)):
            sp1.position = x, y
            renderer.render(sp1)
            view = video.PixelView(renderer.surface)
            self.check_pixels(view, 20, 20, sp1, 0xFF0000, (0x0, ))
            del view
            video.fill(renderer.surface, 0x0)
        sp1.position = 0, 0
        sp2.position = 14, 1
        renderer.render(sprites)
        view = video.PixelView(renderer.surface)
        self.check_pixels(view, 20, 20, sp1, 0xFF0000, (0x0, 0x00FF00))
        self.check_pixels(view, 20, 20, sp2, 0x00FF00, (0x0, 0xFF0000))
        del view
        video.fill(renderer.surface, 0x0)
        renderer.render(sprites, 1, 2)
        view = video.PixelView(renderer.surface)
        self.check_pixels(view, 20, 20, sp1, 0xFF0000, (0x0, 0x00FF00), 1, 2)
        self.check_pixels(view, 20, 20, sp2, 0x00FF00, (0x0, 0xFF0000), 1, 2)
        del view
Ejemplo n.º 18
0
    def test_SoftwareSpriteRenderer_process(self):
        sf1= create_rgb_surface(5, 10, 32)
        sp1 = video.SoftwareSprite(sf1, True)
        sp1.depth = 0
        video.fill(sp1, 0xFF0000)

        sf2 = create_rgb_surface(5, 10, 32)
        sp2 = video.SoftwareSprite(sf2, True)
        sp2.depth = 99
        video.fill(sp2, 0x00FF00)
        sprites = [sp1, sp2]

        window = video.Window("Test", size=(20, 20))
        renderer = video.SoftwareSpriteRenderer(window)

        renderer.process("fakeworld", sprites)
        view = video.PixelView(renderer.surface)
        # Only sp2 wins, since its depth is higher
        self.check_pixels(view, 20, 20, sp1, 0x00FF00, (0x0, ))
        self.check_pixels(view, 20, 20, sp2, 0x00FF00, (0x0, ))
        del view

        self.assertRaises(TypeError, renderer.process, None, None)
Ejemplo n.º 19
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)
Ejemplo n.º 20
0
 def test_get_set_surface_alpha_mod(self):
     for fmt in pixels.ALL_PIXELFORMATS:
         if pixels.SDL_ISPIXELFORMAT_FOURCC(fmt):
             continue
         bpp, rmask, gmask, bmask, amask = \
             pixels.pixelformat_enum_to_masks(fmt)
         sf = surface.create_rgb_surface(10, 10, bpp, rmask, gmask, bmask,
                                         amask)
         salpha = surface.get_surface_alpha_mod(sf)
         self.assertEqual(salpha, 255)
         for alpha in range(0, 255):
             surface.set_surface_alpha_mod(sf, alpha)
             salpha = surface.get_surface_alpha_mod(sf)
             self.assertEqual(salpha, alpha)
         surface.free_surface(sf)
Ejemplo n.º 21
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)
Ejemplo n.º 22
0
    def test_load_texture_rw(self):
        sf = surface.create_rgb_surface(10, 10, 32)
        rd = render.create_software_renderer(sf)

        fname = "surfacetest.%s"
        for fmt in formats:
            if fmt == "tga":
                # SDL_image does not support loading TGA via
                # IMG_LoadTexture_RW()
                continue
            fp = RESOURCES.get(fname % fmt)
            tex = sdlimage.load_texture_rw(rd, rwops.rw_from_object(fp), False)
            self.assertIsInstance(tex, render.SDL_Texture)
            render.destroy_texture(tex)

        render.destroy_renderer(rd)
        surface.free_surface(sf)
Ejemplo n.º 23
0
    def test_set_window_icon(self):
        sf = surface.create_rgb_surface(16, 16, 16, 0xF000, 0x0F00,
                                        0x00F0, 0x000F)
        self.assertIsInstance(sf, surface.SDL_Surface)
        window = video.create_window("Test", 10, 10, 10, 10, 0)
        video.set_window_icon(window, sf)

        self.assertRaises((AttributeError, TypeError),
                          video.set_window_icon, None, None)
        self.assertRaises((AttributeError, TypeError),
                          video.set_window_icon, window, None)
        self.assertRaises((AttributeError, TypeError),
                          video.set_window_icon, None, sf)
        self.assertRaises((AttributeError, TypeError),
                          video.set_window_icon, window, "Test")
        self.assertRaises((AttributeError, TypeError),
                          video.set_window_icon, window, 123456)
Ejemplo n.º 24
0
 def test_get_set_surface_blend_mode(self):
     modes = (video.SDL_BLENDMODE_NONE,
              video.SDL_BLENDMODE_BLEND,
              video.SDL_BLENDMODE_ADD,
              video.SDL_BLENDMODE_MOD
              )
     for fmt in pixels.ALL_PIXELFORMATS:
         if pixels.SDL_ISPIXELFORMAT_FOURCC(fmt):
             continue
         bpp, rmask, gmask, bmask, amask = \
             pixels.pixelformat_enum_to_masks(fmt)
         sf = surface.create_rgb_surface(10, 10, bpp, rmask, gmask, bmask,
                                         amask)
         for mode in modes:
             surface.set_surface_blend_mode(sf, mode)
             smode = surface.get_surface_blend_mode(sf)
             self.assertEqual(smode, mode)
         surface.free_surface(sf)
Ejemplo n.º 25
0
 def test_convert_surface_format(self):
     pfmt = 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 segault in the DUFFS_LOOP() 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_format(sf, pfmt, 0)
         self.assertIsInstance(csf, surface.SDL_Surface)
         surface.free_surface(sf)
         surface.free_surface(csf)
Ejemplo n.º 26
0
    def test_SpriteFactory_from_surface(self):
        window = video.Window("Test", size=(1, 1))
        renderer = video.RenderContext(window)
        tfactory = video.SpriteFactory(video.TEXTURE, renderer=renderer)
        sfactory = video.SpriteFactory(video.SOFTWARE)

        sf = create_rgb_surface(10, 10, 32)
        tsprite = tfactory.from_surface(sf)
        self.assertIsInstance(tsprite, video.TextureSprite)
        ssprite = sfactory.from_surface(sf)
        self.assertIsInstance(ssprite, video.SoftwareSprite)
        del sf

        for factory in (tfactory, sfactory):
            self.assertRaises((AttributeError, ArgumentError, TypeError),
                              factory.from_surface, None)
            self.assertRaises((AttributeError, ArgumentError, TypeError),
                              factory.from_surface, "test")
            self.assertRaises((AttributeError, ArgumentError, TypeError),
                              factory.from_surface, 1234)
Ejemplo n.º 27
0
    def test_set_surface_palette(self):
        invpalette = pixels.alloc_palette(10)
        palette = pixels.alloc_palette(1 << 16)
        sf = surface.create_rgb_surface(10, 10, 16)

        self.assertRaises((AttributeError, TypeError),
                          surface.set_surface_palette, None, None)
        self.assertRaises((AttributeError, TypeError),
                          surface.set_surface_palette, None, palette)
        self.assertIsNone(sf.format.palette)
        surface.set_surface_palette(sf, palette)
        self.assertIsNotNone(sf.format.palette)
        self.assertRaises(sdl.SDLError, surface.set_surface_palette, sf,
                          invpalette)
        self.assertIsNotNone(sf.format.palette)
        surface.set_surface_palette(sf, None)
        self.assertIsNone(sf.format.palette)

        surface.free_surface(sf)
        pixels.free_palette(invpalette)
        pixels.free_palette(palette)
Ejemplo n.º 28
0
 def test_get_set_surface_color_mod(self):
     colormods = ((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
         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 colormods:
             surface.set_surface_color_mod(sf, r, g, b)
             sr, sg, sb = surface.get_surface_color_mod(sf)
             self.assertEqual((sr, sg, sb), (r, g, b))
         surface.free_surface(sf)
Ejemplo n.º 29
0
    def test_free_surface(self):
        self.assertRaises((AttributeError, TypeError),
                          surface.free_surface, None)
        self.assertRaises((AttributeError, TypeError),
                          surface.free_surface, "Test")
        self.assertRaises((AttributeError, TypeError),
                          surface.free_surface, 5)

        formats = (pixels.SDL_PIXELFORMAT_INDEX1LSB,
                   pixels.SDL_PIXELFORMAT_RGB332,
                   pixels.SDL_PIXELFORMAT_RGBA4444,
                   pixels.SDL_PIXELFORMAT_BGR888,
                   pixels.SDL_PIXELFORMAT_ARGB8888,
                   pixels.SDL_PIXELFORMAT_ARGB2101010
                   )
        for fmt in formats:
            bpp, rmask, gmask, bmask, amask = \
                pixels.pixelformat_enum_to_masks(fmt)
            sf = surface.create_rgb_surface(5, 5, bpp, rmask, gmask, bmask,
                                            amask)
            surface.free_surface(sf)
Ejemplo n.º 30
0
    def test_set_window_shape(self):
        sf = surface.create_rgb_surface(10, 10, 32)
        mode = shape.SDL_WindowShapeMode()
        mode.mode = shape.ShapeModeDefault
        mode.parameters = shape.SDL_WindowShapeParams()
        mode.parameters.binarizationCutoff = 1

        flags = (video.SDL_WINDOW_HIDDEN, )
        for flag in flags:
            # TODO: find out, how shaping is supposed to work :-)
            # window = shape.create_shaped_window("Test", 10, 10, 10, 10, flag)
            # self.assertIsInstance(window, video.SDL_Window)
            # self.assertTrue(shape.is_shaped_window(window))

            # self.assertRaises(TypeError, shape.set_window_shape,
            #                   None, None, None)
            # self.assertRaises(TypeError, shape.set_window_shape,
            #                   window, None, None)
            # self.assertRaises(TypeError, shape.set_window_shape,
            #                   window, sf, None)
            # self.assertRaises(TypeError, shape.set_window_shape,
            #                   "Test", sf, mode)
            # self.assertRaises(TypeError, shape.set_window_shape,
            #                   window, 12345, mode)
            # self.assertRaises(TypeError, shape.set_window_shape,
            #                   window, sf, "Test")

            # shape.set_window_shape(window, sf, mode)
            # wmode = shape.get_shaped_window_mode(window)
            # self.assertEqual(wmode.mode, mode.mode)
            # self.assertEqual(wmode.parameters.binarizationCutoff,
            #                  mode.parameters.binarizationCutoff)
            # video.destroy_window(window)

            window = video.create_window("Test", 10, 10, 10, 10, flag)
            self.assertIsInstance(window, video.SDL_Window)
            self.assertRaises(sdl.SDLError, shape.set_window_shape,
                              window, sf, mode)
            video.destroy_window(window)