Keep the brush guide round and show the feather in it.

The local brush cursor took its height from the canvas aspect and its width
from the frame window, so a cropped or zoomed photo drew an oval cursor
over a round mask, and the stroke preview was scaled the same wrong way.
Both now convert the brush radius through the visible frame on each axis,
which matches the baked mask at any crop or zoom.

The feather band was also invisible in the guide: the preview painted one
flat band and the cursor was a single ring. Painted strokes now show the
soft band under the solid core, and the cursor adds an inner ring at
1 - feather of the radius.

Masks shrink their width instead of clamping their height, so tall or wide
frames keep square mask pixels and round dabs.
This commit is contained in:
2026-11-28 17:09:02 +00:00
parent 69a327cd45
commit c05dbce580
4 changed files with 106 additions and 23 deletions
+46 -10
View File
@@ -2198,10 +2198,18 @@ export default function Develop({
y: ((f.y - view.y) / view.h) * 100,
};
};
const xScale = bitmap.width / (frame.w * view.w);
const canvasEl = canvasRef.current;
const canvasW = canvasEl?.clientWidth || 1;
const canvasH = canvasEl?.clientHeight || 1;
// A brush radius is a fraction of the source width, but the
// overlay's 100×100 box is stretched over the canvas, so the
// two axes are converted separately. Using one frame term for
// both (or the canvas aspect) turns the circle into an oval as
// soon as the photo is cropped or zoomed.
const radiusU = (r: number) => (r * bitmap.width * 100) / (frame.w * view.w);
const radiusV = (r: number) => (r * bitmap.width * 100) / (frame.h * view.h);
/** Brush diameter in canvas pixels, for the stroke preview. */
const diameterPx = (r: number) => (r * 2 * bitmap.width * canvasW) / (frame.w * view.w);
const feather = Math.max(0, Math.min(1, activeComponent.feather / 100));
const strokes = localDraft
? [...activeComponent.brush.strokes, localDraft]
: activeComponent.brush.strokes;
@@ -2211,15 +2219,25 @@ export default function Develop({
strokes.map((stroke, i) => {
if (!stroke.points.length) return null;
const points = stroke.points.map(marker).map((p) => `${p.x},${p.y}`).join(' ');
const width = Math.max(1, stroke.size * 2 * canvasW);
const width = Math.max(1, diameterPx(stroke.size));
const core = Math.max(1, width * (1 - feather));
return (
<g key={i}>
{core < width - 0.5 && (
<polyline
key={i}
points={points}
className={`local-brush ${stroke.erase ? 'erase' : ''}`}
className={`local-brush band ${stroke.erase ? 'erase' : ''}`}
strokeWidth={width}
vectorEffect="non-scaling-stroke"
/>
)}
<polyline
points={points}
className={`local-brush ${stroke.erase ? 'erase' : ''}`}
strokeWidth={core}
vectorEffect="non-scaling-stroke"
/>
</g>
);
})}
{activeComponent.kind === 'radial' && (() => {
@@ -2266,16 +2284,34 @@ export default function Develop({
</g>
);
})()}
{activeComponent.kind === 'brush' && localHover && !localDrag.current && (
{activeComponent.kind === 'brush' && localHover && !localDrag.current && (() => {
const c = marker(localHover);
const r = localRadius();
// Feather is the soft band inside the rim, so the inner
// ring marks where the dab is still at full strength.
return (
<g>
<ellipse
cx={marker(localHover).x}
cy={marker(localHover).y}
rx={localRadius() * xScale * 100}
ry={localRadius() * 100 * (canvasW / canvasH)}
cx={c.x}
cy={c.y}
rx={radiusU(r)}
ry={radiusV(r)}
className="local-cursor"
vectorEffect="non-scaling-stroke"
/>
{feather > 0.02 && (
<ellipse
cx={c.x}
cy={c.y}
rx={radiusU(r * (1 - feather))}
ry={radiusV(r * (1 - feather))}
className="local-cursor inner"
vectorEffect="non-scaling-stroke"
/>
)}
</g>
);
})()}
</svg>
);
})()}
+16 -1
View File
@@ -1,7 +1,22 @@
import { describe, expect, it } from 'vitest';
import { blendCoverage } from './masks';
import { blendCoverage, maskSize } from './masks';
/** Coverage values are 0–1 inside the baker, which this keeps readable. */
describe('mask texture size', () => {
it('keeps square mask pixels so a round brush stays round', () => {
const tall = maskSize(3000, 9000);
expect(tall.h).toBeLessThanOrEqual(1400);
expect(tall.w / tall.h).toBeCloseTo(1 / 3, 2);
const wide = maskSize(15000, 1000);
expect(wide.h).toBeGreaterThanOrEqual(120);
expect(wide.w / wide.h).toBeCloseTo(15, 1);
});
it('uses the full width for a normal photo', () => {
expect(maskSize(3464, 5202)).toEqual({ w: 800, h: 1201 });
});
});
describe('mask group compositing', () => {
it('starts a group with the first shape whatever its mode says', () => {
expect(blendCoverage(0, 0.6, 'subtract', true)).toBe(0.6);
+19 -2
View File
@@ -211,9 +211,26 @@ export function blendCoverage(
return Math.max(acc, value);
}
/**
* Mask texture size. Pixels are square, so both dimensions scale together with
* the source: clamping only the height would squeeze every round dab into an
* ellipse on tall or wide frames, so the width shrinks instead.
*/
export function maskSize(srcW: number, srcH: number) {
const safeW = Math.max(1, srcW);
const safeH = Math.max(1, srcH);
let w = 800;
let h = Math.round((w * safeH) / safeW);
const limit = h > 1400 ? 1400 : h < 120 ? 120 : 0;
if (limit) {
h = limit;
w = Math.max(160, Math.round((h * safeW) / safeH));
}
return { w, h: Math.max(1, h) };
}
export function buildLocalMasks(layers: LocalLayer[], srcW: number, srcH: number): PackedMasks {
const w = 800;
const h = Math.max(120, Math.min(1400, Math.round((w * Math.max(1, srcH)) / Math.max(1, srcW))));
const { w, h } = maskSize(srcW, srcH);
const out = new Uint8Array(w * h * 4);
const out2 = new Uint8Array(w * h * 4);
const count = Math.min(MAX_LOCAL_LAYERS, layers.length);
+15
View File
@@ -4661,6 +4661,15 @@ figcaption {
stroke: rgba(255, 92, 92, 0.4);
}
/* The soft band of the feather, drawn under the solid core. */
.local-brush.band {
stroke: rgba(240, 170, 80, 0.14);
}
.local-brush.band.erase {
stroke: rgba(255, 92, 92, 0.13);
}
.local-outline,
.local-line {
fill: none;
@@ -4686,6 +4695,12 @@ figcaption {
stroke-dasharray: 3 3;
}
/* Marks where the feather band starts, mirroring the baked mask. */
.local-cursor.inner {
stroke: rgba(240, 174, 85, 0.5);
stroke-dasharray: 2 4;
}
.local-list {
display: flex;
flex-direction: column;