diff --git a/scripts/render-check.mjs b/scripts/render-check.mjs index e5335f6..1fe92b1 100644 --- a/scripts/render-check.mjs +++ b/scripts/render-check.mjs @@ -379,6 +379,26 @@ try { const lensTintOn = pixelAt(0.625, 0.469); const lensTintOff = pixelAt(0.7, 0.469); + // Before / after split: the edit is drawn full-frame, then the untouched + // source is painted over the left slice. Reading the same band either side of + // the line must give the moved slider on the right and the default on the + // left, which is what proves the scissor lands where the drag line sits. + const splitAfter = defaultEdits(); + splitAfter.exposure = 2; + renderer.render(splitAfter, { width: w, height: h }); + const splitAfterFull = pixelAt(0.75, 0.5); + renderer.render(defaultEdits(), { width: w, height: h }); + const splitBeforeFull = pixelAt(0.75, 0.5); + renderer.render(splitAfter, { width: w, height: h }); + renderer.render(defaultEdits(), { + width: w, + height: h, + scissor: { x: 0, w: Math.round(w / 2) }, + }); + const splitLeft = pixelAt(0.25, 0.5); + const splitRight = pixelAt(0.75, 0.5); + const sameRgb = (a, b) => a.every((v, i) => Math.abs(v - b[i]) <= 1); + pre.textContent = 'RESULT ' + JSON.stringify({ clipPixels, clipRed: near(clipPixels[0], RED_MARK), @@ -437,6 +457,14 @@ try { cropDetailBounded: Math.abs(cropDetailOff[2] - cropRefOff[2]) <= 3, lensTintAligned: lensTintOn[0] > lensRef[0] + 40, lensTintBounded: Math.abs(lensTintOff[0] - lensRefOff[0]) <= 2, + splitLeft, + splitRight, + splitBeforeFull, + splitAfterFull, + splitShowsBoth: + sameRgb(splitLeft, splitBeforeFull) && + sameRgb(splitRight, splitAfterFull) && + !sameRgb(splitAfterFull, splitBeforeFull), tintStrengthWorks: tintFull[2] > tintCore[2] + 8, tintOffMatches: Math.abs(tintOffPixel[2] - dabSoft[2]) <= 1, // A hard dab covers the core, and even an 80 % feather stops at the rim. @@ -702,6 +730,14 @@ async function main() { ); return 1; } + if (!result.splitShowsBoth) { + console.error( + 'render check FAILED: the before / after split does not follow its drag line ' + + `(left=${JSON.stringify(result.splitLeft)} vs ${JSON.stringify(result.splitBeforeFull)}, ` + + `right=${JSON.stringify(result.splitRight)} vs ${JSON.stringify(result.splitAfterFull)}).`, + ); + return 1; + } if ( !result.dabCoreDarkened || !result.dabSoftCoreDarkened || @@ -722,7 +758,11 @@ async function main() { return 1; } console.log( - 'render check PASSED: proxy and sidecar share a row order and the clipping overlay names the channels.', + `render check: before / after split left=${JSON.stringify(result.splitLeft)}` + + ` right=${JSON.stringify(result.splitRight)}`, + ); + console.log( + 'render check PASSED: proxy and sidecar share a row order, the clipping overlay names the channels, and the split keeps each side to its own edit.', ); return 0; } diff --git a/src/components/Develop.tsx b/src/components/Develop.tsx index 815fefa..9968907 100644 --- a/src/components/Develop.tsx +++ b/src/components/Develop.tsx @@ -276,6 +276,9 @@ export default function Develop({ const [lensCorrection, setLensCorrection] = useState(null); const [lensSplit, setLensSplit] = useState(false); const [lensSplitAt, setLensSplitAt] = useState(0.5); + // The whole edit compared with the untouched source, split by a drag line. + const [splitView, setSplitView] = useState(false); + const [splitAt, setSplitAt] = useState(0.5); const [lensState, setLensState] = useState<{ loading: boolean; error: string | null }>({ loading: false, error: null, @@ -373,11 +376,16 @@ export default function Develop({ onSelect(p.id); }; - const moveLensSplit = (e: React.PointerEvent) => { - const rect = e.currentTarget.parentElement?.getBoundingClientRect(); - if (!rect || rect.width <= 0) return; - setLensSplitAt(clampNum((e.clientX - rect.left) / rect.width, 0.02, 0.98)); - }; + // Both splits drag the same way: the handle sits on the line, and its + // percentage follows the pointer across the canvas. + const dragSplit = + (set: (at: number) => void) => (e: React.PointerEvent) => { + const rect = e.currentTarget.parentElement?.getBoundingClientRect(); + if (!rect || rect.width <= 0) return; + set(clampNum((e.clientX - rect.left) / rect.width, 0.02, 0.98)); + }; + const moveLensSplit = dragSplit(setLensSplitAt); + const moveSplit = dragSplit(setSplitAt); const setEdits = useCallback( (patch: Partial, label: string) => { @@ -546,7 +554,11 @@ export default function Develop({ if (!renderer || !canvas || !bitmap) return; if (stage.w < 40 || stage.h < 40) return; - const activeEdits = showOriginal ? { ...defaultEdits(), crop: edits.crop } : edits; + // Holding \ shows the untouched source full-frame; the split paints the same + // render over the left of its drag line, and steps aside while \ is held. + const beforeEdits = { ...defaultEdits(), crop: edits.crop }; + const splitOn = splitView && !showOriginal; + const activeEdits = showOriginal ? beforeEdits : edits; const frame = rotatedBounds(bitmap.width, bitmap.height, edits.crop.angle, edits.crop.quarter); const content: Rect = cropMode ? { x: 0, y: 0, w: 1, h: 1 } @@ -616,7 +628,7 @@ export default function Develop({ renderer.setImage(bitmap, hdrSource); // "Show original" must show the untouched source, not the cleaned proxy. renderer.setDenoised(showOriginal ? null : denoisedBitmap, activeEdits.aiDenoise.amount / 100); - renderer.render(activeEdits, { + const frameOpts = { width: pxW, height: pxH, cropPreview: cropMode, @@ -631,11 +643,30 @@ export default function Develop({ upscale: dpr * cap * fitScale * zoomFactor > 1.1, clipPreview, clipping: clipping ?? undefined, + }; + renderer.render(activeEdits, { + ...frameOpts, lens: showOriginal ? null : lensCorrection, - lensSplit: lensSplit && !showOriginal ? lensSplitAt : undefined, + lensSplit: lensSplit && !splitOn ? lensSplitAt : undefined, maskView, maskStrength: maskStrength / 100, }); + if (splitOn) { + // Paint the untouched source over the left half. The scissor is in + // device pixels and the same view is reused, so the halves line up. + renderer.setDenoised(null, 0); + renderer.render(beforeEdits, { + ...frameOpts, + histogram: false, + lens: null, + maskView: -1, + clipPreview: false, + scissor: { x: 0, w: Math.round(pxW * splitAt) }, + }); + // Restore what the rest of the frame and the eyedropper read from. + renderer.setDenoised(denoisedBitmap, edits.aiDenoise.amount / 100); + renderer.setLensCorrection(lensCorrection); + } histRef.current = renderer.histogram; setHistVersion((v) => v + 1); } catch (err) { @@ -656,6 +687,8 @@ export default function Develop({ lensCorrection, lensSplit, lensSplitAt, + splitView, + splitAt, localMode, localSelected, maskOverlay, @@ -1801,6 +1834,7 @@ export default function Develop({ 'separator', { label: 'Crop & Straighten', shortcut: 'C', onSelect: () => setCropMode((v) => !v) }, { label: 'Before / After', shortcut: '\\', onSelect: () => setShowOriginal((v) => !v) }, + { label: 'Before / After split', onSelect: () => setSplitView((v) => !v) }, 'separator', { label: 'Copy settings', shortcut: '⌘C', onSelect: onCopy }, { label: 'Paste settings', shortcut: '⌘V', onSelect: () => onPaste([photo.id]), disabled: !clipboard }, @@ -1884,6 +1918,14 @@ export default function Develop({ > Before / After + + + )} {healMode && bitmap && (() => { const geo = geoRef.current; const view = geo.view; diff --git a/src/gl/renderer.ts b/src/gl/renderer.ts index 0ba038a..83b775e 100644 --- a/src/gl/renderer.ts +++ b/src/gl/renderer.ts @@ -2011,6 +2011,12 @@ export class Renderer { lens?: LensCorrection | null; /** 0–1 screen split: left is uncorrected, right is corrected. */ lensSplit?: number; + /** + * Draw only this horizontal slice of the canvas, in device pixels. The + * before/after split renders the edit full-frame, then the untouched + * source over the left side, so both halves share one view and line up. + */ + scissor?: { x: number; w: number }; /** hold the grain pattern still, e.g. while a crop handle is being dragged */ freezeGrain?: boolean; /** paint clipped channels while the exposure control is being dragged */ @@ -2137,6 +2143,12 @@ export class Renderer { // Pass 4: detail, effects, grain -> canvas const finishDraw = (target: Target | null, clip = 0) => { const gl2 = this.gl; + // Render targets are always complete frames; only the canvas is ever cut. + const scissor = target ? undefined : opts.scissor; + if (scissor) { + gl2.enable(gl2.SCISSOR_TEST); + gl2.scissor(scissor.x, 0, Math.max(1, scissor.w), h); + } if (target) { gl2.bindFramebuffer(gl2.FRAMEBUFFER, target.fbo); gl2.viewport(0, 0, target.w, target.h); @@ -2213,6 +2225,7 @@ export class Renderer { this.finish.v2('u_outSize', target ? target.w : w, target ? target.h : h); this.finish.f('u_aspect', w / h); this.drawQuad(); + if (scissor) gl2.disable(gl2.SCISSOR_TEST); }; const clipMode = opts.clipPreview diff --git a/src/styles.css b/src/styles.css index 3e5d870..9fd9e16 100644 --- a/src/styles.css +++ b/src/styles.css @@ -5073,14 +5073,14 @@ figcaption { border-top: 1px solid var(--line); } -.lens-split { +.compare-split { position: absolute; inset: 0; pointer-events: none; z-index: 3; } -.lens-split-line { +.compare-split-line { position: absolute; top: 0; bottom: 0; @@ -5089,7 +5089,7 @@ figcaption { box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55), 0 0 10px rgba(0, 0, 0, 0.45); } -.lens-split-handle { +.compare-split-handle { position: absolute; top: 50%; display: flex; @@ -5111,14 +5111,14 @@ figcaption { touch-action: none; } -.lens-split-handle:hover, -.lens-split-handle:focus-visible { +.compare-split-handle:hover, +.compare-split-handle:focus-visible { background: var(--accent); border-color: #fff; outline: none; } -.lens-split-label { +.compare-split-label { position: absolute; top: 10px; padding: 2px 6px; @@ -5130,11 +5130,11 @@ figcaption { text-transform: uppercase; } -.lens-split-label.before { +.compare-split-label.before { left: 10px; } -.lens-split-label.after { +.compare-split-label.after { right: 10px; }