Skip to content

fix(ui): scale large images and preserve original dimensions #266

Merged
deepin-bot[bot] merged 2 commits intolinuxdeepin:masterfrom
add-uos:master
Dec 9, 2025
Merged

fix(ui): scale large images and preserve original dimensions #266
deepin-bot[bot] merged 2 commits intolinuxdeepin:masterfrom
add-uos:master

Conversation

@add-uos
Copy link
Contributor

@add-uos add-uos commented Dec 9, 2025

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-ci-robot
Copy link

deepin pr auto review

我来分析一下这个diff的代码变更:

  1. CMakeLists.txt 变更:
-find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
+find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core)

这个变更移除了Qt5的支持,只保留Qt6。这个改动是合理的,因为:

  • 代码维护更简单,不需要同时支持两个版本
  • Qt6是最新版本,提供更好的性能和特性
  • 但需要注意这会提高系统的最低依赖要求
  1. InformationDialog.qml 变更:
description: {
    var originalDim = IV.FileControl.slotGetInfo("OriginalDimension", filePath);
    if (originalDim && originalDim !== "-") {
        return originalDim;
    } else {
        return imageInfo.width + "x" + imageInfo.height;
    }
}

这个改动优化了尺寸显示逻辑:

  • 优点:优先显示原始尺寸,提供更准确的信息
  • 建议:可以添加错误处理,防止slotGetInfo调用失败
  1. unionimage.cpp 变更:
    主要改进了图片处理逻辑,增加了大图片支持:

a) 内存限制设置:

reader.setAllocationLimit(2048);
  • 优点:防止内存溢出
  • 建议:2048MB的限制值可以考虑做成可配置项

b) 图片尺寸缩放逻辑:

const int maxDimension = 4096;
if (originalSize.width() > maxDimension || originalSize.height() > maxDimension) {
    QSize scaledSize = originalSize;
    scaledSize.scale(maxDimension, maxDimension, Qt::KeepAspectRatio);
    reader.setScaledSize(scaledSize);
}

优点:

  • 防止超大图片占用过多内存
  • 保持图片比例
  • 添加了详细的日志记录

建议改进:

  1. 错误处理:
if (!reader.canRead()) {
    qCWarning(logImageViewer) << "Cannot read image:" << path;
    return false;
}
  1. 资源管理:
// 在读取大图片前检查可用内存
if (originalSize.width() * originalSize.height() * 4 > getAvailableMemory()) {
    qCWarning(logImageViewer) << "Insufficient memory for image loading";
    return false;
}
  1. 性能优化:
// 添加图片加载进度反馈
QFuture<QImage> future = QtConcurrent::run([&]() {
    return reader.read();
});
  1. 安全性考虑:
// 验证图片文件大小
QFileInfo fileInfo(path);
if (fileInfo.size() > MAX_FILE_SIZE) {
    qCWarning(logImageViewer) << "File too large:" << path;
    return false;
}

总体评价:
这个改动主要解决了大图片处理的问题,增加了内存限制和自动缩放功能。代码质量良好,但可以进一步加强错误处理和安全性检查。建议添加更多的边界条件检查和资源管理机制。

@deepin-ci-robot
Copy link

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@add-uos
Copy link
Contributor Author

add-uos commented Dec 9, 2025

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Dec 9, 2025

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 29046d5 into linuxdeepin:master Dec 9, 2025
18 of 20 checks passed
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.

3 participants