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:
1 parent
1dc423c025
commit
240d02684a
14 files changed
+1357
-17
No files matched your search
@@ -2532,6 +2532,142 @@ const shiftXSwap = await (async () => {
|
||||
})()
|
||||
check('Shift+X 交换填充色与描边色(填充不会被关掉、再按回到原样)', shiftXSwap.ok, shiftXSwap.detail)
|
||||
|
||||
// ================================================================
|
||||
// v1.15 图片调节(放最后:会改像素,放中间会污染依赖像素的用例)
|
||||
// ================================================================
|
||||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||||
await page.keyboard.press('Escape')
|
||||
// 前面几条效果用例会把「原图」栅格化成副本层并把原层隐藏,这里先还原成干净的单层,
|
||||
// 否则调节作用在一个隐藏层上 → 像素统计一动不动(第一次跑就踩了这个)
|
||||
await page.locator('[data-action="reset"]').click()
|
||||
await page.waitForTimeout(450)
|
||||
await page.evaluate(() => {
|
||||
const base = [...document.querySelectorAll('.iwb-layer-item')].find(el => /原图/.test(el.textContent || ''))
|
||||
if (base) base.click()
|
||||
})
|
||||
await page.waitForTimeout(320)
|
||||
|
||||
const adjRowCount = await page.locator('.iwb-editor-adj-row').count()
|
||||
const adjNames = await page.locator('.iwb-editor-adj-name').allTextContents()
|
||||
check('右侧栏出现「图片调节」,11 项齐全且顺序固定',
|
||||
adjRowCount === 11 && adjNames.join('/') === '曝光/明度/对比度/阴影/高光/色相/饱和度/温度/色调/锐度/清晰度',
|
||||
'rows=' + adjRowCount + ' ' + adjNames.join('/'))
|
||||
|
||||
/** 合成整幅可见像素后统计:平均亮度 / 灰像素占比 / R、B 均值 */
|
||||
const adjStat = () => page.evaluate(() => {
|
||||
const list = [...document.querySelectorAll('.iwb-editor-layer-canvas')]
|
||||
if (!list.length) return null
|
||||
const w = list[0].width, h = list[0].height
|
||||
const c = document.createElement('canvas')
|
||||
c.width = w; c.height = h
|
||||
const x = c.getContext('2d')
|
||||
for (const el of list) x.drawImage(el, 0, 0)
|
||||
const d = x.getImageData(0, 0, w, h).data
|
||||
let lum = 0, n = 0, gray = 0, r = 0, b = 0
|
||||
for (let i = 0; i < d.length; i += 4) {
|
||||
if (d[i + 3] === 0) continue
|
||||
lum += (d[i] + d[i + 1] + d[i + 2]) / 3
|
||||
if (Math.abs(d[i] - d[i + 1]) < 3 && Math.abs(d[i + 1] - d[i + 2]) < 3) gray++
|
||||
r += d[i]; b += d[i + 2]; n++
|
||||
}
|
||||
return n ? { lum: Math.round(lum / n), gray: +(gray / n).toFixed(2), r: Math.round(r / n), b: Math.round(b / n) } : null
|
||||
})
|
||||
|
||||
/** 设一个调节项的数值(模拟在数值框里输入并提交) */
|
||||
const adjSet = async (key, val) => {
|
||||
await page.evaluate(({ key, val }) => {
|
||||
const row = document.querySelector(`.iwb-editor-adj-row[data-adj="${key}"]`)
|
||||
const num = row.querySelector('.iwb-editor-adj-val')
|
||||
num.value = String(val)
|
||||
num.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
num.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
}, { key, val })
|
||||
await page.waitForTimeout(240)
|
||||
}
|
||||
const adjReset = async () => {
|
||||
const btn = page.locator('[data-adj-reset="all"]')
|
||||
if (await btn.isEnabled()) { await btn.click(); await page.waitForTimeout(260) }
|
||||
}
|
||||
|
||||
const adjBase = await adjStat()
|
||||
|
||||
await adjSet('exposure', 100)
|
||||
const adjBright = await adjStat()
|
||||
check('曝光 +100 明显提亮(不是「看不出变化」的强度)',
|
||||
adjBright && adjBase && adjBright.lum > adjBase.lum + 25,
|
||||
'亮度 ' + (adjBase && adjBase.lum) + ' → ' + (adjBright && adjBright.lum))
|
||||
await adjReset()
|
||||
|
||||
await adjSet('saturation', -100)
|
||||
const adjGray = await adjStat()
|
||||
check('饱和度 -100 完全去色(灰像素接近 100%)',
|
||||
adjGray && adjGray.gray > 0.9,
|
||||
'灰占比 ' + (adjGray && adjGray.gray))
|
||||
await adjReset()
|
||||
|
||||
await adjSet('temp', 100)
|
||||
const adjWarm = await adjStat()
|
||||
check('温度 +100 偏暖:R 通道升、B 通道降',
|
||||
adjWarm && adjBase && adjWarm.r > adjBase.r && adjWarm.b < adjBase.b,
|
||||
'R ' + (adjBase && adjBase.r) + '→' + (adjWarm && adjWarm.r) + ' B ' + (adjBase && adjBase.b) + '→' + (adjWarm && adjWarm.b))
|
||||
|
||||
const adjDirty = (await dbg()).adjust
|
||||
check('调节参数写回状态(debug 可观测,供后续撤销断言)',
|
||||
adjDirty.params && adjDirty.params.temp === 100 && adjDirty.hasSource,
|
||||
JSON.stringify(adjDirty.params))
|
||||
|
||||
await adjReset()
|
||||
const adjBack = await adjStat()
|
||||
check('「复位」把所有项归零,像素回到原图',
|
||||
adjBack && adjBase && Math.abs(adjBack.lum - adjBase.lum) <= 1 && Math.abs(adjBack.r - adjBase.r) <= 1,
|
||||
'亮度 ' + (adjBack && adjBack.lum) + ' vs ' + (adjBase && adjBase.lum))
|
||||
|
||||
// 一次拖动 = 一步历史(6 次 input + 1 次 change)
|
||||
// 注意不能比 history.length:历史栈有容量上限,push 到底后是「进一条、淘汰一条」,
|
||||
// 长度永远不变(第一次跑就是被这个坑到)。数标签出现次数才准。
|
||||
const adjLabelCount = async () => (await dbg()).historyLabels.filter(l => l === '图片调节').length
|
||||
const adjH0 = await adjLabelCount()
|
||||
for (const v of [20, 40, 60, 80, 90, 100]) {
|
||||
await page.evaluate(({ v }) => {
|
||||
const r = document.querySelector('.iwb-editor-adj-row[data-adj="exposure"] .iwb-editor-adj-range')
|
||||
r.value = String(v)
|
||||
r.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
}, { v })
|
||||
}
|
||||
await page.evaluate(() => {
|
||||
const r = document.querySelector('.iwb-editor-adj-row[data-adj="exposure"] .iwb-editor-adj-range')
|
||||
r.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
})
|
||||
await page.waitForTimeout(320)
|
||||
const adjH1 = await adjLabelCount()
|
||||
check('拖一次滑杆只记 1 步历史(不是每帧一步)', adjH1 === adjH0 + 1, '图片调节 标签 ' + adjH0 + ' → ' + adjH1)
|
||||
|
||||
await page.keyboard.press('Control+z')
|
||||
await page.waitForTimeout(320)
|
||||
const adjUndo = (await dbg()).adjust
|
||||
check('Ctrl+Z 撤销调节后滑块归零(参数不能和画面对不上)',
|
||||
adjUndo.params && adjUndo.params.exposure === 0,
|
||||
'exposure=' + (adjUndo.params && adjUndo.params.exposure))
|
||||
|
||||
// 切图层:面板 target 跟随,切回来参数恢复
|
||||
await adjSet('exposure', 40)
|
||||
const adjKept = (await dbg()).adjust.params.exposure
|
||||
await page.locator('[data-action="addBlankLayer"]').click()
|
||||
await page.waitForTimeout(400)
|
||||
const adjTargetNew = await page.locator('.iwb-editor-adj-target').textContent()
|
||||
const adjNewParams = (await dbg()).adjust.params
|
||||
await page.evaluate(() => {
|
||||
const base = [...document.querySelectorAll('.iwb-layer-item')].find(el => /原图/.test(el.textContent || ''))
|
||||
if (base) base.click()
|
||||
})
|
||||
await page.waitForTimeout(420)
|
||||
const adjBackParams = (await dbg()).adjust.params
|
||||
check('切图层时调节面板跟随新层,切回原层参数恢复',
|
||||
/空白图层/.test(adjTargetNew) && adjNewParams && adjNewParams.exposure === 0 && adjBackParams.exposure === adjKept,
|
||||
'新层=' + adjTargetNew + ' 新层exp=' + (adjNewParams && adjNewParams.exposure) + ' 回到原图exp=' + adjBackParams.exposure)
|
||||
|
||||
await adjReset()
|
||||
|
||||
await page.locator('[data-action="cancel"]').click()
|
||||
const openState = await poll(async () => page.evaluate(() => window.__openState))
|
||||
check('点「退出」:宿主 Promise 结算为 cancel 且编辑器关闭',
|
||||
|
||||
Reference in new issue
Block a user