def test_SDL_ConvertSurfaceFormat(self): tenbit = [ pixels.SDL_PACKEDLAYOUT_2101010, pixels.SDL_PACKEDLAYOUT_1010102 ] for pfmt in pixels.ALL_PIXELFORMATS: for fmt in pixels.ALL_PIXELFORMATS: # SDL2 doesn't support converting fancier formats (e.g YUV, 10bit) if pixels.SDL_ISPIXELFORMAT_FOURCC( pfmt) or pixels.SDL_PIXELLAYOUT(pfmt) in tenbit: continue if pixels.SDL_ISPIXELFORMAT_FOURCC( fmt) or pixels.SDL_PIXELLAYOUT(fmt) in tenbit: continue # SDL2 doesn't support converting to formats w/ less than 8 bpp if pixels.SDL_BITSPERPIXEL(pfmt) < 8: continue # SDL2 doesn't support converting from indexed formats w/ 4 bpp if pixels.SDL_PIXELTYPE(fmt) == pixels.SDL_PIXELTYPE_INDEX4: continue bpp = c_int() rmask, gmask, bmask, amask = Uint32(), Uint32(), Uint32( ), Uint32() ret = pixels.SDL_PixelFormatEnumToMasks( fmt, byref(bpp), byref(rmask), byref(gmask), byref(bmask), byref(amask)) assert ret == SDL_TRUE sf = surface.SDL_CreateRGBSurface(0, 10, 20, bpp, rmask, gmask, bmask, amask) assert isinstance(sf.contents, surface.SDL_Surface) csf = surface.SDL_ConvertSurfaceFormat(sf, pfmt, 0) assert csf, error.SDL_GetError() assert isinstance(csf.contents, surface.SDL_Surface) surface.SDL_FreeSurface(sf) surface.SDL_FreeSurface(csf)
def test_SDL_FillRects(self): rectlist = to_ctypes([ 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) ], rect.SDL_Rect) bpp = c_int() rmask, gmask, bmask, amask = Uint32(), Uint32(), Uint32(), Uint32() 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 ret = pixels.SDL_PixelFormatEnumToMasks(fmt, byref(bpp), byref(rmask), byref(gmask), byref(bmask), byref(amask)) self.assertEqual(ret, SDL_TRUE) for w in range(1, 100, 5): for h in range(1, 100, 5): sf = surface.SDL_CreateRGBSurface(0, w, h, bpp, rmask, gmask, bmask, amask) # TODO: check for changed pixels surface.SDL_FillRects(sf, rectlist, 7, 0xff00ff00) surface.SDL_FreeSurface(sf)
def test_SDL_ConvertSurface(self): bad_combos = [] good_combos = [] tenbit = [ pixels.SDL_PACKEDLAYOUT_2101010, pixels.SDL_PACKEDLAYOUT_1010102 ] for idx in pixels.ALL_PIXELFORMATS: pfmt = pixels.SDL_AllocFormat(idx) for fmt in pixels.ALL_PIXELFORMATS: idx_name = pixels.SDL_GetPixelFormatName(idx).decode('utf-8') fmt_name = pixels.SDL_GetPixelFormatName(fmt).decode('utf-8') # SDL2 doesn't support converting fancier formats (e.g YUV, 10bit) if pixels.SDL_ISPIXELFORMAT_FOURCC( idx) or pixels.SDL_PIXELLAYOUT(idx) in tenbit: continue if pixels.SDL_ISPIXELFORMAT_FOURCC( fmt) or pixels.SDL_PIXELLAYOUT(fmt) in tenbit: continue # SDL2 doesn't support converting to formats w/ less than 8 bpp if pixels.SDL_BITSPERPIXEL(idx) < 8: continue # SDL2 doesn't support converting from indexed formats w/ 4 bpp if pixels.SDL_PIXELTYPE(fmt) == pixels.SDL_PIXELTYPE_INDEX4: continue bpp = c_int() rmask, gmask, bmask, amask = Uint32(), Uint32(), Uint32( ), Uint32() 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, 20, bpp, rmask, gmask, bmask, amask) self.assertIsInstance(sf.contents, surface.SDL_Surface) csf = surface.SDL_ConvertSurface(sf, pfmt, 0) self.assertTrue(csf) if error.SDL_GetError() == b'Blit combination not supported': bad_combos.append('{0} -> {1}'.format(fmt_name, idx_name)) error.SDL_ClearError() else: good_combos.append('{0} -> {1}'.format(fmt_name, idx_name)) self.assertIsInstance(csf.contents, surface.SDL_Surface) surface.SDL_FreeSurface(sf) surface.SDL_FreeSurface(csf) pixels.SDL_FreeFormat(pfmt) self.assertEqual(len(bad_combos), 0)