def test_SDL_MapRGBA(self): pformat = pixels.SDL_AllocFormat(pixels.SDL_PIXELFORMAT_RGBA8888) assert isinstance(pformat.contents, pixels.SDL_PixelFormat) val = pixels.SDL_MapRGBA(pformat, 0xFF, 0xAA, 0x88, 0x11) assert val == 0xFFAA8811 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_MapRGBA(pformat, 0xFF, 0xAA, 0x88, 0x11) assert val == 0x0 pixels.SDL_FreeFormat(pformat)
def test_SDL_MapRGBA(self): pformat = pixels.SDL_AllocFormat(pixels.SDL_PIXELFORMAT_RGBA8888) self.assertIsInstance(pformat.contents, pixels.SDL_PixelFormat) val = pixels.SDL_MapRGBA(pformat, 0xFF, 0xAA, 0x88, 0x11) self.assertEqual(val, 0xFFAA8811) 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_MapRGBA(pformat, 0xFF, 0xAA, 0x88, 0x11) self.assertEqual(val, 0x0) pixels.SDL_FreeFormat(pformat)
def test_SDL_RenderDrawPoint(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.SDL_CreateRGBSurface(0, w, h, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF) color = pixels.SDL_MapRGBA(sf.contents.format, r, g, b, a) renderer = render.SDL_CreateSoftwareRenderer(sf) self.assertIsInstance(renderer.contents, render.SDL_Renderer) ret = render.SDL_SetRenderDrawColor(renderer, r, g, b, a) self.assertEqual(ret, 0) for x, y in points: ret = render.SDL_RenderDrawPoint(renderer, x, y) self.assertEqual(ret, 0) render.SDL_RenderPresent(renderer) view = PixelView(sf.contents) 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.SDL_DestroyRenderer(renderer) del view surface.SDL_FreeSurface(sf)