feat(reader): night mode object mask keeps images undistorted - #377
deepin-bot[bot] merged 1 commit into
Conversation
Invert page content via CIELAB lightness flip with a two-level 65^3/128^3 RGB LUT (28x vs exact path, 13ms per 2M-pixel page), keep image objects out of the inverted area via a grayscale mask fetched on the render thread, and generate the night pixmap asynchronously (QtConcurrent) so paint never blocks. While the async job is in flight, paint composes an instant approximate night frame from the latest day render (fast full-page Difference invert plus image rects pasted back), so zooming responds in step with day mode instead of stretching a stale night pixmap. Mask rects are recorded with their fetch render size and scaled to the current render size before building the mask, so the mask stays aligned after zoom/rotation. Page filter only activates in EyeProtection Night mode; image dim factor defaults to 1.0 so photos keep original colors under the page overlay. 夜间模式页面内容按 CIELAB 明度反转,两级 65^3/128^3 RGB LUT 提速 28 倍(2M 像素 13ms);图片对象经灰度蒙版排除在反色区外,bbox 由 渲染线程随整页渲染预取并记录对应渲染尺寸,构建蒙版前按当前渲染 尺寸等比换算,缩放/旋转后蒙版不错位。夜间图经 QtConcurrent 异步 生成,paint 不阻塞;任务在途期间用最新日间渲染即时合成近似夜间帧 (整页 Difference 快速反相 + 图片 bbox 回贴原图),缩放与日间模式 同拍响应,不再拉伸旧夜间图,照片不出现负片。页面滤镜仅在护眼 夜间档生效;侧边栏缩略图仍随系统深色主题反色;图片调暗系数默认 1.0,照片保持原色。 Log: 夜间模式图片对象蒙版反色不失真 PMS: BUG-376493 Influence: 夜间模式下文字/背景反色为黑底白字,图片区域保持原色不 被反色,扫描页(图片覆盖>70%)整页反色;缩放/旋转与日间模式同拍 响应,过渡帧与最终渲染蒙版始终对齐;页面滤镜仅在夜间档生效, 经典/绿色护眼不受影响;侧边栏缩略图逻辑不变,仍随系统主题变化; DOCX/DJVU 无对象信息走整页反色。 Signed-off-by: zhanghongyuan <zhanghongyuan@uniontech.com>
Reviewer's GuideThe PR introduces a render-size-aware PDF image mask pipeline and an asynchronous, LUT-accelerated CIELAB night filter. Browser pages now maintain responsive approximate transition frames during background processing, preserve image regions according to configurable policy, handle scanned pages and unsupported document formats, and invalidate stale results safely as renders change. Sequence diagram for asynchronous night-mode renderingsequenceDiagram
participant RenderThread
participant SheetRenderer
participant BrowserPage
participant NightFilter
participant Painter
RenderThread->>SheetRenderer: getImageObjectRects(index, width, height)
SheetRenderer-->>RenderThread: imageRects
RenderThread->>BrowserPage: setImageObjectRects(rects, width, height)
RenderThread->>BrowserPage: handleRenderFinished(pixmapId, pixmap)
BrowserPage->>BrowserPage: startNightJob()
BrowserPage->>NightFilter: applyPage(src, rects, opt)
Painter->>BrowserPage: paint()
BrowserPage-->>Painter: drawPixmap(renderPixmap)
Painter->>Painter: Difference invert and paste image rects
NightFilter-->>BrowserPage: QImage
BrowserPage->>BrowserPage: onNightImageReady()
BrowserPage-->>Painter: drawPixmap(nightPixmap)
Flow diagram for render-size-aware image maskingflowchart LR
A[PDF page render at width x height] --> B[Extract image object bounding boxes]
B --> C[Record rects with fetch render size]
C --> D{Current render size changed?}
D -->|Yes| E[Scale bounding boxes to current size]
D -->|No| F[Use recorded bounding boxes]
E --> G[Build grayscale image mask]
F --> G
G --> H{Image coverage above 70 percent?}
H -->|Yes| I[Invert entire page]
H -->|No| J[CIELAB lightness inversion outside image areas]
J --> K[Preserve or dim image regions by policy]
I --> L[Night-mode image]
K --> L
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ❌评价: 一般 ❌ 不通过 潜在问题:
建议: 修复 linearChannelToSrgb 函数中线性分支缺失的 * 255.0 乘法,确保两分支返回值范围一致(0-255)。 2. 代码质量 ✅评价: 良好 ✅ 通过 潜在问题:
建议: 代码注释质量优秀,算法原理和设计决策均有详细说明。建议减少重复代码,封装夜间模式状态。 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题:
建议: LUT 加速路径设计优秀(O(1) 查表替代逐像素 CIELAB 转换),异步处理消除 UI 阻塞,过渡帧渲染提供即时反馈。整体性能设计合理。 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 无安全风险。线程安全设计完善(QFutureWatcher + DPdfMutexLocker + C++11 静态初始化),缓冲区操作有边界检查,环境变量处理有验证和钳制,资源管理无泄漏。 💡 改进建议代码示例// 修复 NightFilter.cpp 中 linearChannelToSrgb 函数
// 修改前(第36行):
inline double linearChannelToSrgb(double c)
{
c = qBound(0.0, c, 1.0);
return (c <= 0.0031308) ? (12.92 * c) : (1.055 * qPow(c, 1.0 / 2.4) - 0.055) * 255.0;
}
// 修改后:
inline double linearChannelToSrgb(double c)
{
c = qBound(0.0, c, 1.0);
return (c <= 0.0031308) ? (12.92 * c * 255.0) : (1.055 * qPow(c, 1.0 / 2.4) - 0.055) * 255.0;
}本报告由 AI 代码审查工具自动生成 |
|
[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 |
|
/merge |
Invert page content via CIELAB lightness flip with a two-level 65^3/128^3 RGB LUT (28x vs exact path, 13ms per 2M-pixel page), keep image objects out of the inverted area via a grayscale mask fetched on the render thread, and generate the night pixmap asynchronously (QtConcurrent) so paint never blocks. While the async job is in flight, paint composes an instant approximate night frame from the latest day render (fast full-page Difference invert plus image rects pasted back), so zooming responds in step with day mode instead of stretching a stale night pixmap. Mask rects are recorded with their fetch render size and scaled to the current render size before building the mask, so the mask stays aligned after zoom/rotation. Page filter only activates in EyeProtection Night mode; image dim factor defaults to 1.0 so photos keep original colors under the page overlay.
夜间模式页面内容按 CIELAB 明度反转,两级 65^3/128^3 RGB LUT 提速
28 倍(2M 像素 13ms);图片对象经灰度蒙版排除在反色区外,bbox 由
渲染线程随整页渲染预取并记录对应渲染尺寸,构建蒙版前按当前渲染
尺寸等比换算,缩放/旋转后蒙版不错位。夜间图经 QtConcurrent 异步
生成,paint 不阻塞;任务在途期间用最新日间渲染即时合成近似夜间帧
(整页 Difference 快速反相 + 图片 bbox 回贴原图),缩放与日间模式
同拍响应,不再拉伸旧夜间图,照片不出现负片。页面滤镜仅在护眼
夜间档生效;侧边栏缩略图仍随系统深色主题反色;图片调暗系数默认
1.0,照片保持原色。
Log: 夜间模式图片对象蒙版反色不失真
PMS: BUG-376493
Influence: 夜间模式下文字/背景反色为黑底白字,图片区域保持原色不
被反色,扫描页(图片覆盖>70%)整页反色;缩放/旋转与日间模式同拍
响应,过渡帧与最终渲染蒙版始终对齐;页面滤镜仅在夜间档生效,
经典/绿色护眼不受影响;侧边栏缩略图逻辑不变,仍随系统主题变化;
DOCX/DJVU 无对象信息走整页反色。
Summary by Sourcery
Keep night-mode page content responsive and perceptually inverted while excluding document images from the filter and maintaining mask alignment across rendering changes.
New Features:
Bug Fixes:
Enhancements: