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:
@@ -318,6 +318,22 @@ class GameWindow:
|
||||
]
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user