Skip to content

Draw splash PNG via GDI+ DrawImage - #22

Open
dominicletz wants to merge 2 commits into
masterfrom
fix/splash-gdiplus-draw
Open

dominicletz wants to merge 2 commits into
masterfrom
fix/splash-gdiplus-draw

Conversation

@dominicletz

@dominicletz dominicletz commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Prefer GDI+ DrawImage with high-quality bicubic scaling for splash PNG/JPEG
  • Keep PE/module icon fallback when the file is missing or load fails

Test plan

  • Host-first Windows splash with splash.png looks sharp (no soft PE upscale)
  • Missing splash file still shows PE icon

Made with Cursor


Note

Low Risk
UI-only splash rendering change with existing icon fallbacks; no security or data-path impact.

Reviewed by Cursor Bugbot for commit 315cd27. Configure here.

Co-authored-by: Cursor <cursoragent@cursor.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Splash PNG scaling darkens logo edges
    • Splash PNG scaling now draws with ImageAttributes WrapModeTileFlipXY so bicubic samples repeat edge texels instead of transparent black.
Preview (4b4e3627a1)
diff --git a/docs/status/windows.md b/docs/status/windows.md
--- a/docs/status/windows.md
+++ b/docs/status/windows.md
@@ -13,6 +13,7 @@
 | `--edw-no-beam` / argv strip | done | E2E |
 | Ini + defaults | done | Same semantics as Linux/macOS |
 | Shared AppUserModelID | done | `[windows] app_user_model_id` / `--edw-app-user-model-id`; host sets via Win32 API; BEAM via `EDW_APP_USER_MODEL_ID` + prebuilt `aumid_nif.dll` (`build_windows.ps1`) |
+| Splash PNG draw | done | GDI+ `DrawImage` at 128×128 (HQ bicubic); PE icon fallback when file missing |
 | Lifetime reconnect | done | Packaged mode (keep listening) |
 | Lifetime coupled | done | Exit on disconnect; `--edw-no-beam` exits |
 | Window open/show/hide/title/min size | done | E2E window test |

diff --git a/native/windows/src/splash_window.cpp b/native/windows/src/splash_window.cpp
--- a/native/windows/src/splash_window.cpp
+++ b/native/windows/src/splash_window.cpp
@@ -14,6 +14,21 @@
   if (!g_bg_brush) g_bg_brush = CreateSolidBrush(kSplashBg);
   return g_bg_brush;
 }
+
+bool ensure_gdiplus() {
+  static ULONG_PTR token = 0;
+  static bool ready = false;
+  if (ready) return true;
+  Gdiplus::GdiplusStartupInput input;
+  ready = Gdiplus::GdiplusStartup(&token, &input, nullptr) == Gdiplus::Ok;
+  return ready;
+}
+
+bool is_raster_image_path(const std::wstring& path) {
+  return ends_with_ignore_case(path, L".png") || ends_with_ignore_case(path, L".jpg") ||
+         ends_with_ignore_case(path, L".jpeg") || ends_with_ignore_case(path, L".bmp") ||
+         ends_with_ignore_case(path, L".gif");
+}
 }  // namespace
 
 void SplashWindow::register_class() {
@@ -37,18 +52,36 @@
 
 SplashWindow::~SplashWindow() { dismiss(); }
 
-void SplashWindow::load_icon(const std::optional<std::wstring>& icon_path) {
+void SplashWindow::clear_logo() {
+  if (image_) {
+    delete image_;
+    image_ = nullptr;
+  }
   if (icon_ && owns_icon_) DestroyIcon(icon_);
   icon_ = nullptr;
   owns_icon_ = false;
+}
 
+void SplashWindow::load_icon(const std::optional<std::wstring>& icon_path) {
+  clear_logo();
+
   if (icon_path && !icon_path->empty()) {
+    if (is_raster_image_path(*icon_path) && ensure_gdiplus()) {
+      auto* img = new Gdiplus::Image(icon_path->c_str());
+      if (img->GetLastStatus() == Gdiplus::Ok) {
+        image_ = img;
+        return;
+      }
+      delete img;
+    }
+
     icon_ = load_hicon_from_file(*icon_path);
     if (icon_) {
       owns_icon_ = true;
       return;
     }
   }
+
   icon_ = extract_module_icon();
   owns_icon_ = icon_ != nullptr;
 }
@@ -92,9 +125,7 @@
     DestroyWindow(hwnd_);
     hwnd_ = nullptr;
   }
-  if (icon_ && owns_icon_) DestroyIcon(icon_);
-  icon_ = nullptr;
-  owns_icon_ = false;
+  clear_logo();
 }
 
 LRESULT CALLBACK SplashWindow::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
@@ -135,9 +166,22 @@
   GetClientRect(hwnd, &client);
   FillRect(hdc, &client, splash_bg_brush());
 
-  if (icon_) {
-    int icon_x = (client.right - kIconSize) / 2;
-    int icon_y = 28;
+  const int icon_x = (client.right - kIconSize) / 2;
+  const int icon_y = 28;
+
+  if (image_) {
+    Gdiplus::Graphics graphics(hdc);
+    graphics.SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic);
+    graphics.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHighQuality);
+    graphics.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);
+    // HQ bicubic reads past the source edge. TileFlipXY repeats those texels
+    // so the sample is not transparent black (dark halo on the gray splash).
+    Gdiplus::ImageAttributes attrs;
+    attrs.SetWrapMode(Gdiplus::WrapModeTileFlipXY);
+    const Gdiplus::Rect dest(icon_x, icon_y, kIconSize, kIconSize);
+    graphics.DrawImage(image_, dest, 0, 0, static_cast<INT>(image_->GetWidth()),
+                       static_cast<INT>(image_->GetHeight()), Gdiplus::UnitPixel, &attrs);
+  } else if (icon_) {
     DrawIconEx(hdc, icon_x, icon_y, icon_, kIconSize, kIconSize, 0, nullptr, DI_NORMAL);
   }
 

diff --git a/native/windows/src/splash_window.hpp b/native/windows/src/splash_window.hpp
--- a/native/windows/src/splash_window.hpp
+++ b/native/windows/src/splash_window.hpp
@@ -2,6 +2,8 @@
 
 #include "win_prefix.hpp"
 
+#include <gdiplus.h>
+
 #include <optional>
 #include <string>
 
@@ -27,8 +29,12 @@
   LRESULT on_message(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
   void paint(HWND hwnd);
   void load_icon(const std::optional<std::wstring>& icon_path);
+  void clear_logo();
 
   HWND hwnd_ = nullptr;
+  // Prefer GDI+ image for PNG/JPEG (sharp DrawImage). Fall back to HICON for
+  // .ico / embedded PE icons.
+  Gdiplus::Image* image_ = nullptr;
   HICON icon_ = nullptr;
   bool owns_icon_ = false;
   std::wstring status_;

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 315cd27. Configure here.

Comment thread native/windows/src/splash_window.cpp Outdated
graphics.SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic);
graphics.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHighQuality);
graphics.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);
graphics.DrawImage(image_, icon_x, icon_y, kIconSize, kIconSize);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splash PNG scaling darkens logo edges

Medium Severity

High-quality bicubic DrawImage samples pixels outside the source as transparent black, so scaled splash PNGs pick up a dark halo on the gray splash background. Packaged logos are typically transparent PNGs not already 128×128, so this fringe appears on the host-first splash path this change is meant to sharpen.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 315cd27. Configure here.

High-quality bicubic DrawImage reads past the bitmap as transparent black,
which leaves a dark halo on the gray splash. TileFlipXY repeats edge texels
instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants