feat(image-annotate): v1.15.0 右侧栏「图片调节」11 项 + 快速效果强度修正

用户要「添加基本的图片调节能力到右边栏,同时优化现在的效果,效果现在弱了一些」。

## 图片调节(新 adjust.js,作用于当前位图图层,默认原图)
曝光 ±100(±2EV)/ 明度 / 对比度 / 阴影 / 高光 / 色相 ±180° /
饱和度 / 温度 / 色调 / 锐度 / 清晰度,单行紧凑布局(240px 侧栏 11 项只占约 240px 高)。
拖滑杆实时预览、松手精细、双击归零、右上全部复位。

## 为什么走 getImageData 而不是 ctx.filter
CSS filter 只有 brightness/contrast/saturate/hue-rotate/blur,做不到:
阴影/高光(要按亮度开软蒙版分区)、白平衡(要 R/B、G/M 通道分别增益)、
锐化(要 USM 卷积)。所以只能逐像素。

## 性能:拖动降到 900 长边预览,松手才全量
实测全量耗时(边长 / 像素 / 毫秒):800²/0.6M/6.7 · 1200²/1.4M/12.8 ·
2000²/4.0M/36.8 · 4000²/16M/144.6。
4000×3000 实测:纯调色全量 64ms;叠锐度 287ms;叠清晰度 343ms;
首次(建 source + preview 缓存)256ms。锐度默认 0,不主动拉就不走 USM。

## 两个必须守住的坑(都写成用例了)
1. 不叠加:source 存调节前像素,每次从它重算;每层 sourceCache 另存,切层往返
   也不会拿「调过的像素」当新基准。
2. 撤销后归零:历史只存像素快照、不存调节基准。撤销还原了像素而滑块还停 +80 的话,
   再拖一次就从错误基准算,等于调两遍。规则:撤销一步 = 调整作废、滑块归零、基准重拍。

## 效果强度
「增强」原 brightness(1.12) contrast(1.1) saturate(1.06),截图对比几乎看不出变化 ——
这就是用户说的「效果弱」。改 1.4 / 1.25 / 1.2;「高对比」contrast 1.4 → 1.6。

回归:harness 199 → 208 全通(新增 9 条),validate 9/9。
踩到的用例坑:① 前面效果用例把原图栅格化并隐藏,调色要先用「还原原图」回到单层;
② 历史栈有容量上限,push 到底后「进一条淘汰一条」,长度永远不变,数标签次数才准。
This commit is contained in:
qiqi committed 2026-11-09 17:05:23 +08:00
1 parent 1dc423c025
commit 240d02684a
14 files changed
+1357 -17

No files matched your search

+12
View File
@@ -37,6 +37,7 @@ import { updateAllUI, bindLiteUI, renderOptionBar, updateStatusbar } from './eve
import { disposeSelection, renderSelection, selectionInfo, syncAnts, registerSelectionCommands } from './selection.js'
import { bindFloating, positionFloating, hideSelectionContext } from './floating.js'
import { renderFxPanel } from './effects.js'
import { onHistoryRestore as onAdjustHistoryRestore, renderAdjustPanel } from './adjust.js'
import { loadExportOptions, prepareOutput, downloadBlob, copyBlobToClipboard, bindExportUI, renderExportUI } from './export.js'
import { loadRecentColors } from './recent-colors.js'
import { toast } from './commands.js'
@@ -50,6 +51,9 @@ import { toast } from './commands.js'
S.renderAll = renderAll
S.positionFloating = positionFloating
S.renderFxPanel = renderFxPanel
S.renderAdjustPanel = renderAdjustPanel
// 撤销/重做后调节参数必须归零(详见 adjust.js#onHistoryRestore 的注释)
S.onHistoryRestore = onAdjustHistoryRestore
try {
const img = await loadImage(options.imageBase64)
@@ -154,6 +158,8 @@ import { toast } from './commands.js'
renderObjects()
renderLayerPanel()
renderFxPanel()
// 调节面板跟着图层走:新建/切换/删除图层都要刷新 target 与滑块值
renderAdjustPanel()
renderOptionBar()
updateStatusbar()
renderExportUI()
@@ -373,6 +379,12 @@ import { toast } from './commands.js'
lastExport: S.lastExport ? { ...S.lastExport } : null,
// 快速效果的可重调状态:hasSource=false 表示还没点过效果(滑杆应置灰)
fx: { key: S.fx.key, value: S.fx.value, layerId: S.fx.layerId, hasSource: Boolean(S.fx.source) },
// v1.15 图片调节:params 是 11 项当前值,hasSource 决定面板是否可用
adjust: {
layerId: S.adjust ? S.adjust.layerId : null,
hasSource: Boolean(S.adjust && S.adjust.source),
params: S.adjust && S.adjust.params ? { ...S.adjust.params } : null
},
interaction: S.interaction,
ants: !!S._antFrame,
view: S.viewX !== null ? [Math.round(S.viewX), Math.round(S.viewY)] : null,