fix(ui): scale large images and preserve original dimensions #266
Merged
deepin-bot[bot] merged 2 commits intolinuxdeepin:masterfrom Dec 9, 2025
Merged
fix(ui): scale large images and preserve original dimensions #266deepin-bot[bot] merged 2 commits intolinuxdeepin:masterfrom
deepin-bot[bot] merged 2 commits intolinuxdeepin:masterfrom
Conversation
Detect large images exceeding 4096px in either dimension and scale them down while maintaining aspect ratio for performance optimization. Store original dimensions in metadata and display them in the information dialog when available, falling back to scaled dimensions when original data is not present. log: scale large images and preserve original dimensions bug: https://pms.uniontech.com/bug-view-333195.html
Now explicitly requires only Qt6, no longer accepting Qt5.
deepin pr auto review我来分析一下这个diff的代码变更:
-find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
+find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core)这个变更移除了Qt5的支持,只保留Qt6。这个改动是合理的,因为:
description: {
var originalDim = IV.FileControl.slotGetInfo("OriginalDimension", filePath);
if (originalDim && originalDim !== "-") {
return originalDim;
} else {
return imageInfo.width + "x" + imageInfo.height;
}
}这个改动优化了尺寸显示逻辑:
a) 内存限制设置: reader.setAllocationLimit(2048);
b) 图片尺寸缩放逻辑: const int maxDimension = 4096;
if (originalSize.width() > maxDimension || originalSize.height() > maxDimension) {
QSize scaledSize = originalSize;
scaledSize.scale(maxDimension, maxDimension, Qt::KeepAspectRatio);
reader.setScaledSize(scaledSize);
}优点:
建议改进:
if (!reader.canRead()) {
qCWarning(logImageViewer) << "Cannot read image:" << path;
return false;
}
// 在读取大图片前检查可用内存
if (originalSize.width() * originalSize.height() * 4 > getAvailableMemory()) {
qCWarning(logImageViewer) << "Insufficient memory for image loading";
return false;
}
// 添加图片加载进度反馈
QFuture<QImage> future = QtConcurrent::run([&]() {
return reader.read();
});
// 验证图片文件大小
QFileInfo fileInfo(path);
if (fileInfo.size() > MAX_FILE_SIZE) {
qCWarning(logImageViewer) << "File too large:" << path;
return false;
}总体评价: |
lzwind
approved these changes
Dec 9, 2025
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Contributor
Author
|
/forcemerge |
Contributor
|
This pr force merged! (status: unstable) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(ui): scale large images and preserve original dimensions
build(cmake): improve Qt version detection logic