diff --git a/engine/sdl2.py b/engine/sdl2.py index cd91b6d..60ae3e8 100644 --- a/engine/sdl2.py +++ b/engine/sdl2.py @@ -302,7 +302,7 @@ class GameWindow: """Load and process an image with optional transparency and scaling""" image_path = resolve_bundle_path(os.path.join("assets", path)) image = Image.open(image_path) - + # Handle transparency if transparent_color: image = image.convert("RGBA") @@ -317,10 +317,26 @@ class GameWindow: for item in datas ] image.putdata(new_data) - + + # Normalize near-white background pixels to pure white to avoid + # dark seams when the texture is drawn on a white panel. Applied + # to every asset, not only those with transparent_color, so the + # background is always pure white. + if image.mode != "RGBA": + image = image.convert("RGBA") + datas = image.getdata() + normalized = [ + (255, 255, 255, item[3]) if item[3] > 0 + and item[0] >= 250 and item[1] >= 250 and item[2] >= 250 + and item[0] == item[1] == item[2] + else item + for item in datas + ] + image.putdata(normalized) + # Scale image: tiles are now 64px (was 20px), multiply by 5/8 to reach cell_size (40px) image = image.resize((image.width * 5 // 8, image.height * 5 // 8), Image.NEAREST) - + if surface: return sdl2.ext.pillow_to_surface(image) temp_surface = sdl2.ext.pillow_to_surface(image)