fix(ui): scale large images and preserve original dimensions#380
fix(ui): scale large images and preserve original dimensions#380deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
Conversation
Reviewer's GuideAdds large-image handling by scaling images over 4096px with preserved aspect ratio, raises QImageReader memory limits, stores original dimensions in metadata, and updates the information dialog to prefer displaying original dimensions when available. Sequence diagram for large image loading and scaling in loadStaticImageFromFilesequenceDiagram
participant Caller
participant loadStaticImageFromFile
participant QImageReader
Caller->>loadStaticImageFromFile: loadStaticImageFromFile(path, image)
loadStaticImageFromFile->>QImageReader: construct QImageReader(path)
loadStaticImageFromFile->>QImageReader: setFormat(format)
loadStaticImageFromFile->>QImageReader: setAutoTransform(true)
loadStaticImageFromFile->>QImageReader: setAllocationLimit(2048)
loadStaticImageFromFile->>QImageReader: size() -> originalSize
alt originalSize.width > 4096 or originalSize.height > 4096
loadStaticImageFromFile->>QImageReader: setScaledSize(scaledSize up to 4096, keep aspect ratio)
end
loadStaticImageFromFile->>QImageReader: read() -> res_qt
QImageReader-->>loadStaticImageFromFile: scaled or original image
loadStaticImageFromFile-->>Caller: res_qt
Sequence diagram for metadata extraction and dimension display for large imagessequenceDiagram
actor User
participant InformationDialog
participant FileControl
participant getAllMetaData
participant QImageReader
User->>InformationDialog: open info dialog(filePath)
InformationDialog->>FileControl: slotGetInfo(Dimension, filePath)
FileControl->>getAllMetaData: getAllMetaData(path)
getAllMetaData->>QImageReader: construct QImageReader(path)
getAllMetaData->>QImageReader: setAllocationLimit(2048)
getAllMetaData->>QImageReader: size() -> originalSize
alt originalSize.width > 4096 or originalSize.height > 4096
getAllMetaData->>getAllMetaData: compute scaledSize (max 4096, keep aspect ratio)
getAllMetaData->>getAllMetaData: store OriginalDimension, OriginalWidth, OriginalHeight (original)
getAllMetaData->>getAllMetaData: update Dimension, Width, Height (scaled)
else small image
getAllMetaData->>getAllMetaData: store Dimension, Width, Height (original)
end
getAllMetaData-->>FileControl: metadata map
FileControl-->>InformationDialog: Dimension value
InformationDialog->>FileControl: slotGetInfo(OriginalDimension, filePath)
FileControl-->>InformationDialog: OriginalDimension or "-"
alt OriginalDimension exists and not "-"
InformationDialog->>InformationDialog: description = OriginalDimension
else
InformationDialog->>InformationDialog: description = dimensionsStr (Dimension)
end
InformationDialog-->>User: show Dimensions property item
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- The
maxDimension(4096) andallocationLimit(2048) values are duplicated in multiple places; consider extracting them into shared constants or a config to avoid divergence and make future tuning easier. - Before using
reader.size()to calculate scaled sizes, it would be safer to handle the case where the size is invalid (e.g.isEmpty()or negative dimensions) to avoid unexpected scaling behavior on malformed or unsupported images.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `maxDimension` (4096) and `allocationLimit` (2048) values are duplicated in multiple places; consider extracting them into shared constants or a config to avoid divergence and make future tuning easier.
- Before using `reader.size()` to calculate scaled sizes, it would be safer to handle the case where the size is invalid (e.g. `isEmpty()` or negative dimensions) to avoid unexpected scaling behavior on malformed or unsupported images.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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
deepin pr auto review我来对这段代码进行审查,主要从以下几个方面分析:
1. 语法逻辑代码的语法逻辑基本正确,但有一些需要改进的地方: QML部分: description: {
var originalDim = FileControl.slotGetInfo("OriginalDimension", filePath);
if (originalDim && originalDim !== "-") {
return originalDim;
} else {
return dimensionsStr;
}
}这里使用了不必要的else分支,可以简化为: description: {
var originalDim = FileControl.slotGetInfo("OriginalDimension", filePath);
return originalDim && originalDim !== "-" ? originalDim : dimensionsStr;
}C++部分:
2. 代码质量存在的问题:
改进建议: // 定义常量
const int MAX_MEMORY_LIMIT_MB = 2048;
const int MAX_DIMENSION = 4096;
// 提取公共函数
static void configureImageReader(QImageReader& reader, const QSize& originalSize) {
reader.setAllocationLimit(MAX_MEMORY_LIMIT_MB);
if (originalSize.width() > MAX_DIMENSION || originalSize.height() > MAX_DIMENSION) {
QSize scaledSize = originalSize;
scaledSize.scale(MAX_DIMENSION, MAX_DIMENSION, Qt::KeepAspectRatio);
reader.setScaledSize(scaledSize);
}
}3. 代码性能
改进建议:
4. 代码安全
改进建议: // 添加文件路径验证
if (path.isEmpty() || !QFile::exists(path)) {
return QMap<QString, QString>();
}
// 使用RAII管理资源
{
QImageReader reader(path);
if (!reader.canRead()) {
return QMap<QString, QString>();
}
// ... 其他代码
}总结建议
这些改进将使代码更加健壮、可维护,同时提高性能和安全性。 |
|
[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 |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
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
Summary by Sourcery
Handle very large images more efficiently while preserving and exposing their original dimensions.
Enhancements: