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_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)
def test_SDL_PIXELLAYOUT(self): expected = [ (pixels.SDL_PIXELFORMAT_INDEX1LSB, pixels.SDL_PACKEDLAYOUT_NONE), (pixels.SDL_PIXELFORMAT_RGB332, pixels.SDL_PACKEDLAYOUT_332), (pixels.SDL_PIXELFORMAT_ARGB8888, pixels.SDL_PACKEDLAYOUT_8888) ] for fmt, pxlayout in expected: assert pixels.SDL_PIXELLAYOUT(fmt) == pxlayout