Normalize near-white pixels to pure white in all loaded assets
Assets like lose.png contain thousands of (254,254,254) pixels on a background that is also white. When drawn on a white panel these near-white pixels are slightly darker, producing a visible gray seam. Apply a global normalization in load_image(): any opaque pixel with R=G=B >= 250 is clamped to (255,255,255). Applied to every asset, not only those with transparent_color, so the background is always pure white regardless of off-by-one in the source PNG.
This commit is contained in:
+19
-3
@@ -302,7 +302,7 @@ class GameWindow:
|
|||||||
"""Load and process an image with optional transparency and scaling"""
|
"""Load and process an image with optional transparency and scaling"""
|
||||||
image_path = resolve_bundle_path(os.path.join("assets", path))
|
image_path = resolve_bundle_path(os.path.join("assets", path))
|
||||||
image = Image.open(image_path)
|
image = Image.open(image_path)
|
||||||
|
|
||||||
# Handle transparency
|
# Handle transparency
|
||||||
if transparent_color:
|
if transparent_color:
|
||||||
image = image.convert("RGBA")
|
image = image.convert("RGBA")
|
||||||
@@ -317,10 +317,26 @@ class GameWindow:
|
|||||||
for item in datas
|
for item in datas
|
||||||
]
|
]
|
||||||
image.putdata(new_data)
|
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)
|
# 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)
|
image = image.resize((image.width * 5 // 8, image.height * 5 // 8), Image.NEAREST)
|
||||||
|
|
||||||
if surface:
|
if surface:
|
||||||
return sdl2.ext.pillow_to_surface(image)
|
return sdl2.ext.pillow_to_surface(image)
|
||||||
temp_surface = sdl2.ext.pillow_to_surface(image)
|
temp_surface = sdl2.ext.pillow_to_surface(image)
|
||||||
|
|||||||
Reference in New Issue
Block a user