diff pytouhou/ui/sdl/texture.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 a6af3ff86612
children
line wrap: on
line diff
--- a/pytouhou/ui/sdl/texture.pyx
+++ b/pytouhou/ui/sdl/texture.pyx
@@ -12,7 +12,7 @@
 ## GNU General Public License for more details.
 ##
 
-from pytouhou.lib.sdl cimport load_png, create_rgb_surface
+from pytouhou.lib.sdl cimport create_rgba_surface
 from pytouhou.lib.sdl import SDLError
 from pytouhou.game.text cimport NativeText
 
@@ -78,21 +78,9 @@ cdef class FontManager:
 
 
 cdef Surface decode_png(loader, first_name, secondary_name):
-    image_file = load_png(loader.get_file(os.path.basename(first_name)))
-    width, height = image_file.surface.w, image_file.surface.h
-
-    # Support only 32 bits RGBA. Paletted surfaces are awful to work with.
-    #TODO: verify it doesn’t blow up on big-endian systems.
-    new_image = create_rgb_surface(width, height, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000)
-    new_image.blit(image_file)
-
     if secondary_name:
-        alpha_file = load_png(loader.get_file(os.path.basename(secondary_name)))
-        assert (width == alpha_file.surface.w and height == alpha_file.surface.h)
-
-        new_alpha_file = create_rgb_surface(width, height, 24)
-        new_alpha_file.blit(alpha_file)
-
-        new_image.set_alpha(new_alpha_file)
-
-    return new_image
+        image = loader.get_image_with_alpha(first_name, secondary_name)
+    else:
+        image = loader.get_image(first_name)
+    width, height = image.dimensions
+    return create_rgba_surface(image.pixels, width, height)