Ejemplo n.º 1
0
 def test_SDL_CreateRGBSurfaceWithFormatFrom(self):
     for buf, bpp, pitch, masks, fmt in rgba_pixelations_16x16:
         if bpp == 32:
             arflag = "I"
         elif bpp == 16:
             arflag = "H"
         bytebuf = CTypesView(array.array(arflag, buf))
         bufptr = cast(bytebuf.to_bytes(), POINTER(Uint8))
         sf = surface.SDL_CreateRGBSurfaceWithFormatFrom(
             bufptr, 16, 16, bpp, pitch, fmt)
         self.assertIsInstance(sf.contents, surface.SDL_Surface)
         surface.SDL_FreeSurface(sf)
Ejemplo n.º 2
0
 def test_SDL_ConvertPixels(self):
     for buf, bpp, pitch, masks, fmt in rgba_pixelations_16x16:
         bytecount = bpp // 8
         arflag = None
         if bpp == 32:
             arflag = "I"
         elif bpp == 16:
             arflag = "H"
         src = CTypesView(array.array(arflag, buf), bytecount)
         srcp = cast(src.to_bytes(), POINTER(Uint8))
         dst = (Uint8 * len(src))()
         dstp = cast(dst, POINTER(Uint8))
         ret = surface.SDL_ConvertPixels(16, 16, fmt, srcp, 16 * bytecount,
                                         fmt, dstp, 16 * bytecount)
         self.assertEqual(ret, 0)
         for index, val in enumerate(dst):
             self.assertEqual(val, src.view[index])
Ejemplo n.º 3
0
    def test_SDL_BlitSurface(self):
        bpp = 32
        w, h = 10, 10
        # no alpha to prevent blending
        masks = (0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000)
        dest = surface.SDL_CreateRGBSurface(0, w, h, bpp, masks[0], masks[1],
                                            masks[2], masks[3])
        pixelsize = h * dest.contents.pitch
        rowlen = dest.contents.pitch // 4

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

        for src in sources:
            for pos in blitpositions:
                drect = pos.__copy__()
                surface.SDL_FillRect(dest, None, 0x0)  # fill with black
                surface.SDL_BlitSurface(src, None, dest, drect)
                buf = cast(dest.contents.pixels, POINTER(Uint8 * pixelsize))
                pbuf = 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.contents.h):
                    for x in range(dest.contents.w):
                        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.SDL_FreeSurface(sf)
        surface.SDL_FreeSurface(dest)