Skip to content

[release/3.6] 修复无法加载 WebP 图标的问题#4436

Merged
Glavo merged 2 commits intoHMCL-dev:releasefrom
Glavo:backport/webp
Sep 10, 2025
Merged

[release/3.6] 修复无法加载 WebP 图标的问题#4436
Glavo merged 2 commits intoHMCL-dev:releasefrom
Glavo:backport/webp

Conversation

@Glavo
Copy link
Member

@Glavo Glavo commented Sep 10, 2025

@Glavo Glavo added the backport label Sep 10, 2025
@Glavo Glavo requested a review from Copilot September 10, 2025 14:57

This comment was marked as outdated.

@Glavo Glavo requested a review from Copilot September 10, 2025 15:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes WebP image loading issues in HMCL by refactoring the remote image loading system to support WebP format properly, addressing the problem described in issue #4171.

  • Adds WebP image loading support with scaling capabilities
  • Refactors remote image loading to use asynchronous tasks instead of direct Image constructor
  • Updates UI components to use property binding for remote images

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
SwingFXUtils.java Adds new method for scaling BufferedImage to WritableImage with aspect ratio preservation
FXUtils.java Major refactor of remote image loading system with WebP support and async task-based approach
DownloadPage.java Updates image loading calls to use new property binding method
DownloadListPage.java Updates image loading calls to use new property binding method
HTMLRenderer.java Refactors image loading to use synchronous task execution with improved error handling

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +125 to +131
if (requestedWidth <= 0. || requestedHeight <= 0.) {
return toFXImage(bimg, null);
}

int width = (int) requestedWidth;
int height = (int) requestedHeight;

Copy link

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

Use integer comparison instead of floating-point comparison for dimensions. Since width and height are cast to int later, compare against 0 directly: if (requestedWidth <= 0 || requestedHeight <= 0)

Suggested change
if (requestedWidth <= 0. || requestedHeight <= 0.) {
return toFXImage(bimg, null);
}
int width = (int) requestedWidth;
int height = (int) requestedHeight;
int width = (int) requestedWidth;
int height = (int) requestedHeight;
if (width <= 0 || height <= 0) {
return toFXImage(bimg, null);
}

Copilot uses AI. Check for mistakes.
@@ -851,15 +907,37 @@ public static Image newBuiltinImage(String url, double requestedWidth, double re
}
}

Copy link

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

This public method lacks JavaDoc documentation. It should include documentation explaining the parameters, return value, and behavior, especially since it's part of a utility class API.

Suggested change
/**
* Downloads an image from a remote URL asynchronously, caches it locally, and returns a {@link Task} that loads the image
* with the specified parameters. If the image has already been downloaded and cached, it will be loaded from the cache.
* If the cached file is unavailable or unreadable, it will be re-downloaded.
*
* @param url the URL of the remote image to download.
* @param requestedWidth the bounding box width for the loaded image.
* @param requestedHeight the bounding box height for the loaded image.
* @param preserveRatio whether to preserve the aspect ratio of the original image when scaling.
* @param smooth whether to use a better quality filtering algorithm or a faster one when scaling the image.
* @return a {@link Task} that, when executed, provides the loaded {@link Image}.
*/

Copilot uses AI. Check for mistakes.
Comment on lines +186 to +189
Image image = FXUtils.getRemoteImageTask(src, width, height, true, true)
.run();
if (image == null)
throw new AssertionError("Image loading task returned null");
Copy link

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

Calling .run() on a Task executes it synchronously on the current thread, which can block the UI thread if this is called from JavaFX Application Thread. Consider using async execution or documenting that this method should not be called from the UI thread.

Copilot uses AI. Check for mistakes.
@Glavo Glavo merged commit 34842a5 into HMCL-dev:release Sep 10, 2025
2 checks passed
@Glavo Glavo deleted the backport/webp branch September 10, 2025 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants