From da52b99a36861500870eb7bee1a6348d85e10260 Mon Sep 17 00:00:00 2001 From: LemonNexus Date: Wed, 11 Feb 2026 16:53:44 +0000 Subject: [PATCH] fix: improve upscaling for pixel art icons - Use integer scaling (2x, 3x, 4x) instead of fractional for sharp pixels - Use NEAREST neighbor resampling (better for pixel art than Lanczos) - Add sharpening filter after upscale - Reduced padding to 85% so icons fill more of canvas This produces much sharper results for game icons! --- modules/tga_converter.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/modules/tga_converter.py b/modules/tga_converter.py index 02342d1..75e1482 100644 --- a/modules/tga_converter.py +++ b/modules/tga_converter.py @@ -420,7 +420,7 @@ class TGAConverter: Returns: New image with canvas size, source image centered """ - from PIL import Image + from PIL import Image, ImageFilter canvas_w, canvas_h = canvas_size img_w, img_h = image.size @@ -430,14 +430,23 @@ class TGAConverter: # Calculate scaling if upscale: - # Scale up to fit within canvas with some padding (e.g., 90%) - max_size = int(min(canvas_w, canvas_h) * 0.9) + # Scale up to fit within canvas with some padding (e.g., 85%) + max_size = int(min(canvas_w, canvas_h) * 0.85) scale = min(max_size / img_w, max_size / img_h) if scale > 1: # Only upscale, never downscale - new_w = int(img_w * scale) - new_h = int(img_h * scale) - image = image.resize((new_w, new_h), Image.Resampling.LANCZOS) + # For pixel art/game icons, use integer scaling + NEAREST for sharpness + # Round scale to nearest integer for clean pixel edges + int_scale = max(1, round(scale)) + new_w = img_w * int_scale + new_h = img_h * int_scale + + # Use NEAREST neighbor for pixel art - keeps edges sharp + image = image.resize((new_w, new_h), Image.Resampling.NEAREST) + + # Apply slight sharpening to reduce blur from the upscale + image = image.filter(ImageFilter.SHARPEN) + img_w, img_h = new_w, new_h # Calculate centered position