chore: update copyright year and improve image scaling#43
chore: update copyright year and improve image scaling#43deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
Conversation
Updated the copyright year range from 2022 to 2022-2026 in the file header. Modified the image scaling logic in ErollThread::processCapturedImage to use center-cropping instead of simple scaling when the preview image size is not 800x600. This ensures the captured image maintains its aspect ratio and focuses on the central region, preventing distortion that could occur with non-uniform scaling. The new method calculates the appropriate source rectangle based on the larger required scale factor, crops from the center, and then scales to the target dimensions. chore: 更新版权年份并改进图像缩放 更新了文件头中的版权年份范围,从2022年改为2022-2026年。 修改了ErollThread::processCapturedImage中的图像缩放逻辑,当预览图像尺寸 不是800x600时,使用中心裁剪代替简单的缩放。这确保了捕获的图像保持其宽高 比并聚焦于中央区域,防止了非均匀缩放可能导致的失真。新方法根据所需的最大 缩放因子计算适当的源矩形,从中心裁剪,然后缩放到目标尺寸。 PMS: BUG-304729
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates the module’s SPDX copyright header year range and changes ErollThread::processCapturedImage to perform a center-crop followed by scaling to 800x600 instead of always uniformly scaling the full preview image when its size differs from 800x600, to preserve aspect ratio and focus on the central region. 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 left some high level feedback:
- In the new scaling branch, consider guarding against invalid preview sizes (e.g., width or height <= 0) before computing
scaleto avoid potential division-by-zero or negative dimension issues when unexpected images are passed in.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the new scaling branch, consider guarding against invalid preview sizes (e.g., width or height <= 0) before computing `scale` to avoid potential division-by-zero or negative dimension issues when unexpected images are passed in.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
deepin pr auto review这段代码主要修改了图片处理逻辑,从简单的缩放改为“居中裁剪+缩放”的方式。以下是对该修改的详细审查和改进建议: 1. 代码逻辑审查
2. 代码质量与语法
3. 代码性能
4. 代码安全
改进后的代码建议// 定义常量,方便维护
const int TARGET_WIDTH = 800;
const int TARGET_HEIGHT = 600;
void ErollThread::processCapturedImage(int id, const QImage &preview)
{
if (preview.isNull()) {
return;
}
QImage img;
// 使用常量进行比较
if (preview.size() == QSize(TARGET_WIDTH, TARGET_HEIGHT)) {
img = preview;
} else {
const int pw = preview.width();
const int ph = preview.height();
// 防御性检查:防止原图尺寸过小导致计算异常
if (pw <= 0 || ph <= 0) {
return; // 或者处理错误情况
}
// 计算缩放比例,取较大值以覆盖目标区域
qreal scale = qMax(static_cast<qreal>(TARGET_WIDTH) / pw,
static_cast<qreal>(TARGET_HEIGHT) / ph);
// 计算源图像中需要截取的区域(保持宽高比)
int srcW = qRound(static_cast<qreal>(TARGET_WIDTH) / scale);
int srcH = qRound(static_cast<qreal>(TARGET_HEIGHT) / scale);
// 计算居中裁剪的起始坐标
int srcX = (pw - srcW) / 2;
int srcY = (ph - srcH) / 2;
// 执行裁剪和缩放
// 注意:这里会产生一次深拷贝和一次新图像分配
// 根据需求选择 FastTransformation (快) 或 SmoothTransformation (画质好)
img = preview.copy(srcX, srcY, srcW, srcH)
.scaled(TARGET_WIDTH, TARGET_HEIGHT, Qt::IgnoreAspectRatio, Qt::FastTransformation);
}
if (1 == id) {
sendCapture(img);
}
// ...
}总结修改点:
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mhduiy, robertkill 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 |
|
/merge |
Updated the copyright year range from 2022 to 2022-2026 in the file header.
Modified the image scaling logic in ErollThread::processCapturedImage to use center-cropping instead of simple scaling when the preview image size is not 800x600. This ensures the captured image maintains its aspect ratio and focuses on the central region, preventing distortion that could occur with non-uniform scaling. The new method calculates the appropriate source rectangle based on the larger required scale factor, crops from the center, and then scales to the target dimensions.
chore: 更新版权年份并改进图像缩放
更新了文件头中的版权年份范围,从2022年改为2022-2026年。
修改了ErollThread::processCapturedImage中的图像缩放逻辑,当预览图像尺寸 不是800x600时,使用中心裁剪代替简单的缩放。这确保了捕获的图像保持其宽高
比并聚焦于中央区域,防止了非均匀缩放可能导致的失真。新方法根据所需的最大
缩放因子计算适当的源矩形,从中心裁剪,然后缩放到目标尺寸。
PMS: BUG-304729
Summary by Sourcery
Update copyright metadata and refine captured image processing to avoid distorted previews.
Bug Fixes:
Chores: