From 8e3757ac875a244adb1cef4d029cb8c59b345982 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Mon, 13 Oct 2025 16:49:39 -0700 Subject: [PATCH] raylib: image dimensions are optional (#36332) * meas * now no resizing * clean up --- selfdrive/ui/layouts/onboarding.py | 2 +- system/ui/lib/application.py | 33 ++++++++++++++++-------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/selfdrive/ui/layouts/onboarding.py b/selfdrive/ui/layouts/onboarding.py index ea6fedebf7..bccb36712c 100644 --- a/selfdrive/ui/layouts/onboarding.py +++ b/selfdrive/ui/layouts/onboarding.py @@ -46,7 +46,7 @@ class TrainingGuide(Widget): paths = sorted(paths, key=lambda x: int(re.search(r'\d+', x).group())) for fn in paths: path = os.path.join(BASEDIR, "selfdrive/assets/training", fn) - self._images.append(gui_app.texture(path, gui_app.width, gui_app.height)) + self._images.append(gui_app.texture(path)) def _handle_mouse_release(self, mouse_pos): if rl.check_collision_point_rec(mouse_pos, STEP_RECTS[self._step]): diff --git a/system/ui/lib/application.py b/system/ui/lib/application.py index f0bcdcdc6d..1925122d0b 100644 --- a/system/ui/lib/application.py +++ b/system/ui/lib/application.py @@ -189,7 +189,8 @@ class GuiApplication: self._modal_overlay = ModalOverlay(overlay=overlay, callback=callback) - def texture(self, asset_path: str, width: int, height: int, alpha_premultiply=False, keep_aspect_ratio=True): + def texture(self, asset_path: str, width: int | None = None, height: int | None = None, + alpha_premultiply=False, keep_aspect_ratio=True): cache_key = f"{asset_path}_{width}_{height}_{alpha_premultiply}{keep_aspect_ratio}" if cache_key in self._textures: return self._textures[cache_key] @@ -199,29 +200,31 @@ class GuiApplication: self._textures[cache_key] = texture_obj return texture_obj - def _load_texture_from_image(self, image_path: str, width: int, height: int, alpha_premultiply=False, keep_aspect_ratio=True): + def _load_texture_from_image(self, image_path: str, width: int | None = None, height: int | None = None, + alpha_premultiply=False, keep_aspect_ratio=True): """Load and resize a texture, storing it for later automatic unloading.""" image = rl.load_image(image_path) if alpha_premultiply: rl.image_alpha_premultiply(image) - # Resize with aspect ratio preservation if requested - if keep_aspect_ratio: - orig_width = image.width - orig_height = image.height + if width is not None and height is not None: + # Resize with aspect ratio preservation if requested + if keep_aspect_ratio: + orig_width = image.width + orig_height = image.height - scale_width = width / orig_width - scale_height = height / orig_height + scale_width = width / orig_width + scale_height = height / orig_height - # Calculate new dimensions - scale = min(scale_width, scale_height) - new_width = int(orig_width * scale) - new_height = int(orig_height * scale) + # Calculate new dimensions + scale = min(scale_width, scale_height) + new_width = int(orig_width * scale) + new_height = int(orig_height * scale) - rl.image_resize(image, new_width, new_height) - else: - rl.image_resize(image, width, height) + rl.image_resize(image, new_width, new_height) + else: + rl.image_resize(image, width, height) texture = rl.load_texture_from_image(image) # Set texture filtering to smooth the result