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)
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)