fix(wallpapercache): use QImageReader scaled decoding to avoid OOM on…#65
Conversation
Reviewer's GuideRefactors wallpaper image loading to use QImageReader with scaled decoding, caps effective decode resolution for pixmix and scaling threads, and switches format detection to QImageReader::imageFormat() to avoid loading full images, improving memory usage and error handling for large wallpapers. Class diagram for updated wallpaper image processing componentsclassDiagram
class ScaleImageThread {
+ScaleImageThread(parent: QObject*)
+void executeTask(task: TaskData)
+QImage scaleImage(task: TaskData)
+QString cacheImageToDisk(image: QImage&, task: TaskData, md5String: QString)
}
class ImageEffectProcessor {
+ImageEffectProcessor()
+EffectType effectTypeFromString(type: QString) EffectType
+QImage processPixmixEffect(imagePath: QString)
}
class WallpaperCacheService {
+WallpaperCacheService(parent: QObject*)
+QString saveImageFromFd(fd: QDBusUnixFileDescriptor, format: QString)
}
class TaskData {
+QString originalPath
+QSize targetSize
}
ScaleImageThread --> TaskData : uses
ImageEffectProcessor --> QImageReader : uses
ScaleImageThread --> QImageReader : uses
WallpaperCacheService --> QImageReader : uses
class QImageReader {
+QImageReader(fileName: QString)
+bool canRead()
+QSize size()
+void setScaledSize(size: QSize)
+QImage read()
+QString errorString()
+static QByteArray imageFormat(fileName: QString)
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/plugin-qt/wallpapercache/scaleimagethread.cpp" line_range="169-170" />
<code_context>
- size.height()));
-
- return image;
+ const QSize &size = task.targetSize;
+ return image.copy(QRect((image.width() - size.width()) / 2,
+ (image.height() - size.height()) / 2,
+ size.width(),
</code_context>
<issue_to_address>
**issue (bug_risk):** Guard against crop rect going out of bounds if decoded size is smaller than `task.targetSize`.
Because some decoders may ignore `setScaledSize`, apply rounding differently, or not honor the scaling hint, `image.size()` can occasionally be smaller than `task.targetSize`. In that case, the center offsets `(image.width() - size.width()) / 2` (and height) become negative and the crop `QRect` can fall partially or fully outside the image, leading to undefined behavior or a null image. Please clamp the crop rect to `image.size()` (e.g., via min/max on width/height and offsets), or fall back to a non-centered crop when `image.width() < size.width()` or `image.height() < size.height()`.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
… large images 1. Replace QImage::load() with QImageReader in pixmix effect processing, cap decoded resolution at 8K (7680px) to prevent excessive memory usage 2. Use QImageReader::setScaledSize() for scaleImage thread so decoding outputs directly at target size instead of full-size then downscale 3. Use QImageReader::imageFormat() static method for format detection to avoid instantiating a full reader when only the format is needed 4. Add proper error handling with canRead/isEmpty checks and error strings Log: Optimize wallpaper image decoding to use scaled reading and prevent OOM on large images fix(wallpapercache): 使用 QImageReader 缩放解码避免大图内存溢出 1. 将 pixmix 特效处理中的 QImage::load() 替换为 QImageReader, 限制解码分辨率上限为 8K (7680px),防止内存占用过大 2. 缩放线程使用 QImageReader::setScaledSize() 在解码时直接输出目标尺寸, 避免先全尺寸加载再缩放带来的额外内存开销 3. 格式检测改用 QImageReader::imageFormat() 静态方法, 避免实例化完整 reader 造成不必要的图片加载 4. 增加完善的错误检查,包含 canRead/isEmpty 校验及错误信息输出 Log: 优化壁纸图片解码流程,采用缩放读取方式防止超大图片导致内存溢出 PMS: BUG-359341
deepin pr auto review这份代码 diff 主要对图像加载和处理逻辑进行了优化,特别是在处理大图像和性能方面做了改进。以下是对代码的详细审查,包括语法逻辑、代码质量、代码性能和代码安全方面的改进意见。 1. 语法逻辑与代码质量优点:
改进建议:
2. 代码性能优点:
改进建议:
3. 代码安全优点:
改进建议:
总结这份代码 diff 质量很高,主要解决了处理大图时的性能和内存问题。
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mhduiy, yixinshark 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: blocked) |
… large images
Log: Optimize wallpaper image decoding to use scaled reading and prevent OOM on large images
fix(wallpapercache): 使用 QImageReader 缩放解码避免大图内存溢出
Log: 优化壁纸图片解码流程,采用缩放读取方式防止超大图片导致内存溢出
PMS: BUG-359341
Change-Id: I4ce0c8d32b51e7036a3457490b318f540b51f0f4
Summary by Sourcery
Optimize wallpaper image decoding to use scaled reads and avoid excessive memory usage or OOM with large images.
Bug Fixes:
Enhancements: