Mercurial > touhou
diff pytouhou/lib/sdl.pyx @ 786:7e940ebeb5fd
Replace SDL2_image with the image crate
| author | Link Mauve <linkmauve@linkmauve.fr> |
|---|---|
| date | Mon, 01 Dec 2025 17:05:48 +0100 |
| parents | f73e8524c045 |
| children |
line wrap: on
line diff
--- a/pytouhou/lib/sdl.pyx +++ b/pytouhou/lib/sdl.pyx @@ -71,14 +71,12 @@ IF UNAME_SYSNAME == "Windows": SDL_SetMainReady() init(SDL_INIT_VIDEO if self.video else 0) - img_init(IMG_INIT_PNG) ttf_init() keyboard_state = SDL_GetKeyboardState(NULL) def __exit__(self, *args): TTF_Quit() - IMG_Quit() SDL_Quit() @@ -239,6 +237,9 @@ cdef class Surface: + def __init__(self, bytes data=None): + self.data = data + def __dealloc__(self): if self.surface != NULL: SDL_FreeSurface(self.surface) @@ -288,11 +289,6 @@ raise SDLError() -cdef bint img_init(int flags) except True: - if IMG_Init(flags) != flags: - raise SDLError() - - cdef bint ttf_init() except True: if TTF_Init() < 0: raise SDLError() @@ -303,20 +299,13 @@ raise SDLError() -cdef Surface load_png(file_): - data = file_.read() - rwops = SDL_RWFromConstMem(<char*>data, len(data)) - surface = Surface() - surface.surface = IMG_LoadPNG_RW(rwops) - SDL_RWclose(rwops) - if surface.surface == NULL: - raise SDLError() - return surface - - -cdef Surface create_rgb_surface(int width, int height, int depth, Uint32 rmask=0, Uint32 gmask=0, Uint32 bmask=0, Uint32 amask=0): - surface = Surface() - surface.surface = SDL_CreateRGBSurface(0, width, height, depth, rmask, gmask, bmask, amask) +cdef Surface create_rgba_surface(bytes data, int width, int height): + surface = Surface(data) + cdef char *pixels = <char*>data + depth = 32 + pitch = width * 4 + fmt = SDL_PIXELFORMAT_ABGR8888 + surface.surface = SDL_CreateRGBSurfaceWithFormatFrom(pixels, width, height, depth, pitch, fmt) if surface.surface == NULL: raise SDLError() return surface
