Group local mask shapes into editable components.
A local adjustment is now a list of shapes composited in order (add, subtract, intersect) instead of a single shape, so dodging and burning can be built from several brushes, gradients and auto masks without spending layer channels. Existing edits migrate on load: the flat layer fields become components[0], keeping geometry, invert, feather and the layer's blend mode unchanged. The panel gains a shape list with active-shape editing, and the render gate now asserts a subtract shape clears the group while an intersect keeps it.
This commit is contained in:
+65
-26
@@ -6,6 +6,7 @@ import type {
|
||||
Edits,
|
||||
Flag,
|
||||
HealSpot,
|
||||
LocalComponent,
|
||||
LocalLayer,
|
||||
LocalMaskKind,
|
||||
LocalPoint,
|
||||
@@ -99,6 +100,9 @@ export const MAX_HEAL_SPOTS = 24;
|
||||
/** Eight masks are packed into two RGBA textures. */
|
||||
export const MAX_LOCAL_LAYERS = 8;
|
||||
|
||||
/** More shapes than this in one group stops being quicker than a second layer. */
|
||||
export const MAX_LOCAL_COMPONENTS = 8;
|
||||
|
||||
export function defaultLocalAdjust(): LocalLayer['adjust'] {
|
||||
return {
|
||||
exposure: 0,
|
||||
@@ -119,10 +123,9 @@ export function defaultLocalAdjust(): LocalLayer['adjust'] {
|
||||
};
|
||||
}
|
||||
|
||||
export function defaultLocalLayer(kind: LocalMaskKind, index: number): LocalLayer {
|
||||
export function defaultLocalComponent(kind: LocalMaskKind): LocalComponent {
|
||||
return {
|
||||
id: `local-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`,
|
||||
name: `Local ${index + 1}`,
|
||||
id: `shape-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`,
|
||||
kind,
|
||||
mode: 'add',
|
||||
inverted: false,
|
||||
@@ -130,6 +133,15 @@ export function defaultLocalLayer(kind: LocalMaskKind, index: number): LocalLaye
|
||||
brush: { strokes: [] },
|
||||
linear: { x1: 0.5, y1: 0.2, x2: 0.5, y2: 0.8 },
|
||||
radial: { cx: 0.5, cy: 0.5, rx: 0.25, ry: 0.3 },
|
||||
};
|
||||
}
|
||||
|
||||
export function defaultLocalLayer(kind: LocalMaskKind, index: number): LocalLayer {
|
||||
return {
|
||||
id: `local-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`,
|
||||
name: `Local ${index + 1}`,
|
||||
mode: 'add',
|
||||
components: [defaultLocalComponent(kind)],
|
||||
range: { enabled: false, lumaMin: 0, lumaMax: 100, hue: 30, hueRange: 180, satMin: 0 },
|
||||
curve: identityCurve(),
|
||||
adjust: defaultLocalAdjust(),
|
||||
@@ -287,40 +299,67 @@ function localCurve(input: unknown): CurvePoint[] {
|
||||
return points.length >= 2 ? points : identityCurve();
|
||||
}
|
||||
|
||||
/**
|
||||
* One shape from stored edits. It also reads the pre-group flat layout, where
|
||||
* the layer itself carried kind/feather/brush/...: that is how every mask saved
|
||||
* before mask groups existed migrates into `components[0]`.
|
||||
*/
|
||||
function localComponent(input: unknown, index: number): LocalComponent | null {
|
||||
if (!input || typeof input !== 'object') return null;
|
||||
const shape = input as Partial<LocalComponent> & { kind?: unknown };
|
||||
const kind: LocalMaskKind =
|
||||
shape.kind === 'linear' || shape.kind === 'radial' || shape.kind === 'raster' ? shape.kind : 'brush';
|
||||
const linear = (shape.linear ?? {}) as Partial<LocalComponent['linear']>;
|
||||
const radial = (shape.radial ?? {}) as Partial<LocalComponent['radial']>;
|
||||
const raster = kind === 'raster' ? rasterMask(shape.raster) : undefined;
|
||||
// A raster shape without its coverage would composite an empty hole, so it
|
||||
// falls back to a brush shape that can at least be painted over.
|
||||
const resolved: LocalMaskKind = kind === 'raster' && !raster ? 'brush' : kind;
|
||||
return {
|
||||
id: typeof shape.id === 'string' && shape.id ? shape.id.slice(0, 60) : `shape-${index}`,
|
||||
kind: resolved,
|
||||
mode: shape.mode === 'subtract' || shape.mode === 'intersect' ? shape.mode : 'add',
|
||||
inverted: !!shape.inverted,
|
||||
feather: num(shape.feather, 50, 0, 100),
|
||||
brush: { strokes: localStrokes(shape.brush?.strokes) },
|
||||
raster: resolved === 'raster' ? raster : undefined,
|
||||
linear: {
|
||||
x1: clamp01(num(linear.x1, 0.5, 0, 1)),
|
||||
y1: clamp01(num(linear.y1, 0.2, 0, 1)),
|
||||
x2: clamp01(num(linear.x2, 0.5, 0, 1)),
|
||||
y2: clamp01(num(linear.y2, 0.8, 0, 1)),
|
||||
},
|
||||
radial: {
|
||||
cx: clamp01(num(radial.cx, 0.5, 0, 1)),
|
||||
cy: clamp01(num(radial.cy, 0.5, 0, 1)),
|
||||
rx: num(radial.rx, 0.25, 0.01, 1.5),
|
||||
ry: num(radial.ry, 0.3, 0.01, 1.5),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function localLayers(input: unknown): LocalLayer[] {
|
||||
if (!Array.isArray(input)) return [];
|
||||
const out: LocalLayer[] = [];
|
||||
for (const raw of input.slice(0, MAX_LOCAL_LAYERS)) {
|
||||
if (!raw || typeof raw !== 'object') continue;
|
||||
const layer = raw as Partial<LocalLayer>;
|
||||
const kind: LocalMaskKind =
|
||||
layer.kind === 'linear' || layer.kind === 'radial' || layer.kind === 'raster' ? layer.kind : 'brush';
|
||||
const adjust = (layer.adjust ?? {}) as Partial<LocalLayer['adjust']>;
|
||||
const range = (layer.range ?? {}) as Partial<LocalLayer['range']>;
|
||||
const linear = (layer.linear ?? {}) as Partial<LocalLayer['linear']>;
|
||||
const radial = (layer.radial ?? {}) as Partial<LocalLayer['radial']>;
|
||||
const stored = Array.isArray(layer.components) && layer.components.length ? layer.components : [layer];
|
||||
const components: LocalComponent[] = [];
|
||||
for (const entry of stored.slice(0, MAX_LOCAL_COMPONENTS)) {
|
||||
const component = localComponent(entry, components.length);
|
||||
if (component) components.push(component);
|
||||
}
|
||||
// A layer must keep at least one shape, or it would adjust nothing with no
|
||||
// way to tell why from the panel.
|
||||
if (!components.length) components.push(defaultLocalComponent('brush'));
|
||||
out.push({
|
||||
id: typeof layer.id === 'string' && layer.id ? layer.id : `local-${out.length}`,
|
||||
name: typeof layer.name === 'string' && layer.name.trim() ? layer.name.slice(0, 40) : `Local ${out.length + 1}`,
|
||||
kind,
|
||||
mode:
|
||||
layer.mode === 'subtract' || layer.mode === 'intersect' ? layer.mode : 'add',
|
||||
inverted: !!layer.inverted,
|
||||
feather: num(layer.feather, 50, 0, 100),
|
||||
brush: { strokes: localStrokes(layer.brush?.strokes) },
|
||||
raster: kind === 'raster' ? rasterMask(layer.raster) : undefined,
|
||||
linear: {
|
||||
x1: clamp01(num(linear.x1, 0.5, 0, 1)),
|
||||
y1: clamp01(num(linear.y1, 0.2, 0, 1)),
|
||||
x2: clamp01(num(linear.x2, 0.5, 0, 1)),
|
||||
y2: clamp01(num(linear.y2, 0.8, 0, 1)),
|
||||
},
|
||||
radial: {
|
||||
cx: clamp01(num(radial.cx, 0.5, 0, 1)),
|
||||
cy: clamp01(num(radial.cy, 0.5, 0, 1)),
|
||||
rx: num(radial.rx, 0.25, 0.01, 1.5),
|
||||
ry: num(radial.ry, 0.3, 0.01, 1.5),
|
||||
},
|
||||
mode: layer.mode === 'subtract' || layer.mode === 'intersect' ? layer.mode : 'add',
|
||||
components,
|
||||
range: {
|
||||
enabled: !!range.enabled,
|
||||
lumaMin: num(range.lumaMin, 0, 0, 100),
|
||||
|
||||
Reference in New Issue
Block a user