From 23524e203826ca944ffbff9789ec9765ba2b6c8e Mon Sep 17 00:00:00 2001 From: Cameron Clough Date: Tue, 22 Apr 2025 15:28:54 +0100 Subject: [PATCH] ui(raylib): reduce spinner rotation artifact (#35048) * ui(raylib): reduce spinner rotation artifact A visual artifact (white pixels) appeared on the edge of the rotating spinner track texture, likely due to RGB color bleed during bilinear filtering in Raylib. Pre-multiplying the alpha channel of the spinner track image using `rl.image_alpha_premultiply` significantly reduces the visibility of the artifact. * lint --- system/ui/lib/application.py | 4 +++- system/ui/spinner.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/system/ui/lib/application.py b/system/ui/lib/application.py index 470396bbc7..23f9316c3a 100644 --- a/system/ui/lib/application.py +++ b/system/ui/lib/application.py @@ -50,9 +50,11 @@ class GuiApplication: self._set_styles() self._load_fonts() - def load_texture_from_image(self, file_name: str, width: int, height: int): + def load_texture_from_image(self, file_name: str, width: int, height: int, alpha_premultiply = False): """Load and resize a texture, storing it for later automatic unloading.""" image = rl.load_image(file_name) + if alpha_premultiply: + rl.image_alpha_premultiply(image) rl.image_resize(image, width, height) texture = rl.load_texture_from_image(image) # Set texture filtering to smooth the result diff --git a/system/ui/spinner.py b/system/ui/spinner.py index adfb604de9..f3724cbd1e 100755 --- a/system/ui/spinner.py +++ b/system/ui/spinner.py @@ -23,7 +23,8 @@ def clamp(value, min_value, max_value): class Spinner: def __init__(self): self._comma_texture = gui_app.load_texture_from_image(os.path.join(BASEDIR, "selfdrive/assets/img_spinner_comma.png"), TEXTURE_SIZE, TEXTURE_SIZE) - self._spinner_texture = gui_app.load_texture_from_image(os.path.join(BASEDIR, "selfdrive/assets/img_spinner_track.png"), TEXTURE_SIZE, TEXTURE_SIZE) + self._spinner_texture = gui_app.load_texture_from_image(os.path.join(BASEDIR, "selfdrive/assets/img_spinner_track.png"), TEXTURE_SIZE, TEXTURE_SIZE, + alpha_premultiply=True) self._rotation = 0.0 self._text: str = "" self._progress: int | None = None