@pixerate/editor 0.205.0 → 0.207.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/image-editor/controller.d.cts +11 -0
- package/dist/image-editor/controller.d.ts +11 -0
- package/dist/image-editor/index.cjs +853 -320
- package/dist/image-editor/index.js +557 -24
- package/dist/image-editor/selection/index.d.cts +2 -0
- package/dist/image-editor/selection/index.d.ts +2 -0
- package/dist/image-editor/selection/refine-edits.d.cts +50 -0
- package/dist/image-editor/selection/refine-edits.d.ts +50 -0
- package/dist/image-editor/selection/refine.d.cts +6 -4
- package/dist/image-editor/selection/refine.d.ts +6 -4
- package/dist/image-editor/selection/select-and-mask.d.cts +126 -0
- package/dist/image-editor/selection/select-and-mask.d.ts +126 -0
- package/package.json +1 -1
- package/skills/pixerate-image-editor/SKILL.md +1 -1
- package/skills/pixerate-image-selection-masking/SKILL.md +6 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Select and Mask workspace's strokes as plain data, so an agent can send what a person
|
|
3
|
+
* paints: Quick Selection strokes (grow to the region's edges), Brush strokes (paint the
|
|
4
|
+
* selection in or out directly), Refine Edge Brush strokes (mark where the edge should be
|
|
5
|
+
* re-estimated from the image, e.g. over hair), Lasso outlines and Object Selection boxes.
|
|
6
|
+
*/
|
|
7
|
+
import type { CropBox, ImagePoint } from '../types.cjs';
|
|
8
|
+
import { type PixelBuffer, type SelectionMask } from './mask.cjs';
|
|
9
|
+
/** One stroke in the workspace, in natural image pixels. */
|
|
10
|
+
export type RefineEdit = {
|
|
11
|
+
kind: 'quick-select';
|
|
12
|
+
points: ImagePoint[];
|
|
13
|
+
size?: number;
|
|
14
|
+
mode?: 'add' | 'subtract';
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'brush';
|
|
17
|
+
points: ImagePoint[];
|
|
18
|
+
size?: number;
|
|
19
|
+
mode?: 'add' | 'subtract';
|
|
20
|
+
hardness?: number;
|
|
21
|
+
} | {
|
|
22
|
+
kind: 'refine-brush';
|
|
23
|
+
points: ImagePoint[];
|
|
24
|
+
size?: number;
|
|
25
|
+
} | {
|
|
26
|
+
kind: 'lasso';
|
|
27
|
+
points: ImagePoint[];
|
|
28
|
+
mode?: 'add' | 'subtract';
|
|
29
|
+
} | {
|
|
30
|
+
kind: 'object';
|
|
31
|
+
rect?: CropBox;
|
|
32
|
+
point?: ImagePoint;
|
|
33
|
+
mode?: 'add' | 'subtract';
|
|
34
|
+
};
|
|
35
|
+
export declare const REFINE_EDIT_KINDS: readonly ["quick-select", "brush", "refine-brush", "lasso", "object"];
|
|
36
|
+
/**
|
|
37
|
+
* Coverage of a round brush of diameter `size` dragged along `points` (one point is a dab), over
|
|
38
|
+
* a `width × height` image. `hardness` 0..1 (default 1): the solid share of the radius; the rest
|
|
39
|
+
* fades out. The edge is anti-aliased either way.
|
|
40
|
+
*/
|
|
41
|
+
export declare function brushStrokeMask(width: number, height: number, points: readonly ImagePoint[], size: number, hardness?: number): SelectionMask;
|
|
42
|
+
/**
|
|
43
|
+
* Applies `edits` in order to `selection` (`null` starts empty) over `pixels` (needed for
|
|
44
|
+
* Quick Selection strokes). Returns the edited selection and the Refine Edge Brush's painted
|
|
45
|
+
* area (`null` when there were no such strokes), for `refineSelection`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function applyRefineEdits(pixels: PixelBuffer | null, selection: SelectionMask | null, edits: readonly RefineEdit[], width: number, height: number): {
|
|
48
|
+
selection: SelectionMask | null;
|
|
49
|
+
refineBrush: SelectionMask | null;
|
|
50
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Select and Mask workspace's strokes as plain data, so an agent can send what a person
|
|
3
|
+
* paints: Quick Selection strokes (grow to the region's edges), Brush strokes (paint the
|
|
4
|
+
* selection in or out directly), Refine Edge Brush strokes (mark where the edge should be
|
|
5
|
+
* re-estimated from the image, e.g. over hair), Lasso outlines and Object Selection boxes.
|
|
6
|
+
*/
|
|
7
|
+
import type { CropBox, ImagePoint } from '../types.js';
|
|
8
|
+
import { type PixelBuffer, type SelectionMask } from './mask.js';
|
|
9
|
+
/** One stroke in the workspace, in natural image pixels. */
|
|
10
|
+
export type RefineEdit = {
|
|
11
|
+
kind: 'quick-select';
|
|
12
|
+
points: ImagePoint[];
|
|
13
|
+
size?: number;
|
|
14
|
+
mode?: 'add' | 'subtract';
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'brush';
|
|
17
|
+
points: ImagePoint[];
|
|
18
|
+
size?: number;
|
|
19
|
+
mode?: 'add' | 'subtract';
|
|
20
|
+
hardness?: number;
|
|
21
|
+
} | {
|
|
22
|
+
kind: 'refine-brush';
|
|
23
|
+
points: ImagePoint[];
|
|
24
|
+
size?: number;
|
|
25
|
+
} | {
|
|
26
|
+
kind: 'lasso';
|
|
27
|
+
points: ImagePoint[];
|
|
28
|
+
mode?: 'add' | 'subtract';
|
|
29
|
+
} | {
|
|
30
|
+
kind: 'object';
|
|
31
|
+
rect?: CropBox;
|
|
32
|
+
point?: ImagePoint;
|
|
33
|
+
mode?: 'add' | 'subtract';
|
|
34
|
+
};
|
|
35
|
+
export declare const REFINE_EDIT_KINDS: readonly ["quick-select", "brush", "refine-brush", "lasso", "object"];
|
|
36
|
+
/**
|
|
37
|
+
* Coverage of a round brush of diameter `size` dragged along `points` (one point is a dab), over
|
|
38
|
+
* a `width × height` image. `hardness` 0..1 (default 1): the solid share of the radius; the rest
|
|
39
|
+
* fades out. The edge is anti-aliased either way.
|
|
40
|
+
*/
|
|
41
|
+
export declare function brushStrokeMask(width: number, height: number, points: readonly ImagePoint[], size: number, hardness?: number): SelectionMask;
|
|
42
|
+
/**
|
|
43
|
+
* Applies `edits` in order to `selection` (`null` starts empty) over `pixels` (needed for
|
|
44
|
+
* Quick Selection strokes). Returns the edited selection and the Refine Edge Brush's painted
|
|
45
|
+
* area (`null` when there were no such strokes), for `refineSelection`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function applyRefineEdits(pixels: PixelBuffer | null, selection: SelectionMask | null, edits: readonly RefineEdit[], width: number, height: number): {
|
|
48
|
+
selection: SelectionMask | null;
|
|
49
|
+
refineBrush: SelectionMask | null;
|
|
50
|
+
};
|
|
@@ -42,10 +42,12 @@ export declare function guidedFilterColor(guide: readonly [Float32Array, Float32
|
|
|
42
42
|
export declare function edgeWidth(guide: readonly [Float32Array, Float32Array, Float32Array], w: number, h: number, r: number): Float32Array;
|
|
43
43
|
/**
|
|
44
44
|
* Refines soft coverage `m` (`w × h`, 0..1) with `guide` (three 0..1 planes, required when
|
|
45
|
-
* `radius > 0`): edge-aware re-estimation in a band around the edge, then
|
|
46
|
-
* contrast and shift edge, in that order.
|
|
45
|
+
* `radius > 0` or a `band` is given): edge-aware re-estimation in a band around the edge, then
|
|
46
|
+
* smooth, feather, contrast and shift edge, in that order. `band` (0..1 per pixel, the Refine
|
|
47
|
+
* Edge Brush) adds to the band where it is painted, so hair or fur far from the edge is
|
|
48
|
+
* re-estimated too.
|
|
47
49
|
*/
|
|
48
|
-
export declare function refineCoverage(guide: readonly [Float32Array, Float32Array, Float32Array] | null, m: Float32Array, w: number, h: number, params?: RefineEdgeParams): Float32Array;
|
|
50
|
+
export declare function refineCoverage(guide: readonly [Float32Array, Float32Array, Float32Array] | null, m: Float32Array, w: number, h: number, params?: RefineEdgeParams, band?: ArrayLike<number> | null): Float32Array;
|
|
49
51
|
/** Three 0..1 planes of a window of an RGBA buffer. */
|
|
50
52
|
export declare function guidePlanes(pixels: PixelBuffer, win?: CropBox): [Float32Array, Float32Array, Float32Array];
|
|
51
53
|
/**
|
|
@@ -53,7 +55,7 @@ export declare function guidePlanes(pixels: PixelBuffer, win?: CropBox): [Float3
|
|
|
53
55
|
* same size). Work is confined to the mask's bounds grown by {@link refineEdgeHalo}, so a small
|
|
54
56
|
* selection on a large image stays cheap.
|
|
55
57
|
*/
|
|
56
|
-
export declare function refineSelection(pixels: PixelBuffer | null, mask: SelectionMask, params?: RefineEdgeParams): SelectionMask;
|
|
58
|
+
export declare function refineSelection(pixels: PixelBuffer | null, mask: SelectionMask, params?: RefineEdgeParams, refineBrush?: SelectionMask | null): SelectionMask;
|
|
57
59
|
/**
|
|
58
60
|
* Decontaminate Colors: along a soft edge, a pixel's colour is part subject and part the old
|
|
59
61
|
* background (C = αF + (1 − α)B), which shows as a fringe once the subject is on a new background.
|
|
@@ -42,10 +42,12 @@ export declare function guidedFilterColor(guide: readonly [Float32Array, Float32
|
|
|
42
42
|
export declare function edgeWidth(guide: readonly [Float32Array, Float32Array, Float32Array], w: number, h: number, r: number): Float32Array;
|
|
43
43
|
/**
|
|
44
44
|
* Refines soft coverage `m` (`w × h`, 0..1) with `guide` (three 0..1 planes, required when
|
|
45
|
-
* `radius > 0`): edge-aware re-estimation in a band around the edge, then
|
|
46
|
-
* contrast and shift edge, in that order.
|
|
45
|
+
* `radius > 0` or a `band` is given): edge-aware re-estimation in a band around the edge, then
|
|
46
|
+
* smooth, feather, contrast and shift edge, in that order. `band` (0..1 per pixel, the Refine
|
|
47
|
+
* Edge Brush) adds to the band where it is painted, so hair or fur far from the edge is
|
|
48
|
+
* re-estimated too.
|
|
47
49
|
*/
|
|
48
|
-
export declare function refineCoverage(guide: readonly [Float32Array, Float32Array, Float32Array] | null, m: Float32Array, w: number, h: number, params?: RefineEdgeParams): Float32Array;
|
|
50
|
+
export declare function refineCoverage(guide: readonly [Float32Array, Float32Array, Float32Array] | null, m: Float32Array, w: number, h: number, params?: RefineEdgeParams, band?: ArrayLike<number> | null): Float32Array;
|
|
49
51
|
/** Three 0..1 planes of a window of an RGBA buffer. */
|
|
50
52
|
export declare function guidePlanes(pixels: PixelBuffer, win?: CropBox): [Float32Array, Float32Array, Float32Array];
|
|
51
53
|
/**
|
|
@@ -53,7 +55,7 @@ export declare function guidePlanes(pixels: PixelBuffer, win?: CropBox): [Float3
|
|
|
53
55
|
* same size). Work is confined to the mask's bounds grown by {@link refineEdgeHalo}, so a small
|
|
54
56
|
* selection on a large image stays cheap.
|
|
55
57
|
*/
|
|
56
|
-
export declare function refineSelection(pixels: PixelBuffer | null, mask: SelectionMask, params?: RefineEdgeParams): SelectionMask;
|
|
58
|
+
export declare function refineSelection(pixels: PixelBuffer | null, mask: SelectionMask, params?: RefineEdgeParams, refineBrush?: SelectionMask | null): SelectionMask;
|
|
57
59
|
/**
|
|
58
60
|
* Decontaminate Colors: along a soft edge, a pixel's colour is part subject and part the old
|
|
59
61
|
* background (C = αF + (1 − α)B), which shows as a fringe once the subject is on a new background.
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Select and Mask workspace without a UI: its settings, strokes, preview and view modes, shared
|
|
3
|
+
* by the React and Svelte workspaces. Everything it holds is plain data (the strokes are
|
|
4
|
+
* `RefineEdit`s), and OK runs the same `refineSelectionTo` call an agent makes with `edits`, so
|
|
5
|
+
* the workspace and an agent produce the same result in one undo step.
|
|
6
|
+
*
|
|
7
|
+
* The preview is computed on a copy reduced to {@link PREVIEW_SIZE} px (or at full size with High
|
|
8
|
+
* Quality Preview) and drawn as RGBA in the chosen view mode.
|
|
9
|
+
*/
|
|
10
|
+
import type { ImageEditorController, RefineOutput, RefineOutputResult } from '../controller.cjs';
|
|
11
|
+
import type { ImagePoint } from '../types.cjs';
|
|
12
|
+
import { type RefineEdgeParams } from './refine.cjs';
|
|
13
|
+
import { type RefineEdit } from './refine-edits.cjs';
|
|
14
|
+
export type SelectAndMaskView = 'onion-skin' | 'marching-ants' | 'overlay' | 'on-black' | 'on-white' | 'black-white' | 'on-layers';
|
|
15
|
+
export type SelectAndMaskTool = 'quick-select' | 'refine-brush' | 'brush' | 'object' | 'lasso' | 'hand' | 'zoom';
|
|
16
|
+
/** The view modes with Photoshop's keys, in menu order. */
|
|
17
|
+
export declare const SELECT_AND_MASK_VIEWS: readonly {
|
|
18
|
+
id: SelectAndMaskView;
|
|
19
|
+
label: string;
|
|
20
|
+
key: string;
|
|
21
|
+
opacity: number;
|
|
22
|
+
}[];
|
|
23
|
+
/** The workspace tools with Photoshop's keys. */
|
|
24
|
+
export declare const SELECT_AND_MASK_TOOLS: readonly {
|
|
25
|
+
id: SelectAndMaskTool;
|
|
26
|
+
label: string;
|
|
27
|
+
key: string;
|
|
28
|
+
}[];
|
|
29
|
+
export interface SelectAndMaskSettings {
|
|
30
|
+
params: Required<RefineEdgeParams>;
|
|
31
|
+
output: RefineOutput;
|
|
32
|
+
/** Decontaminate Colors amount 0..100 (new-layer outputs). */
|
|
33
|
+
decontaminate: number;
|
|
34
|
+
refineMode: 'color' | 'object';
|
|
35
|
+
view: SelectAndMaskView;
|
|
36
|
+
/** How strongly the view shows what is not selected, 0..1. */
|
|
37
|
+
opacity: number;
|
|
38
|
+
/** Show only the area the refinement changes. */
|
|
39
|
+
showEdge: boolean;
|
|
40
|
+
/** Show the selection as it was, before the workspace. */
|
|
41
|
+
showOriginal: boolean;
|
|
42
|
+
/** Update the preview while painting (otherwise on release). */
|
|
43
|
+
realTime: boolean;
|
|
44
|
+
/** Preview at full size instead of a reduced copy. */
|
|
45
|
+
highQuality: boolean;
|
|
46
|
+
/** Keep these settings for the next time the workspace opens. */
|
|
47
|
+
remember: boolean;
|
|
48
|
+
tool: SelectAndMaskTool;
|
|
49
|
+
/** Brush diameter in natural pixels. */
|
|
50
|
+
brushSize: number;
|
|
51
|
+
brushMode: 'add' | 'subtract';
|
|
52
|
+
}
|
|
53
|
+
export declare const DEFAULT_SELECT_AND_MASK_SETTINGS: SelectAndMaskSettings;
|
|
54
|
+
/** Long side of the reduced preview. */
|
|
55
|
+
export declare const PREVIEW_SIZE = 1024;
|
|
56
|
+
export declare class SelectAndMaskSession {
|
|
57
|
+
readonly controller: ImageEditorController;
|
|
58
|
+
private settingsValue;
|
|
59
|
+
private readonly editsList;
|
|
60
|
+
/** The edit being painted, shown in the preview but not yet in `edits`. */
|
|
61
|
+
private live;
|
|
62
|
+
private dragStart;
|
|
63
|
+
private pixels;
|
|
64
|
+
private previewPixels;
|
|
65
|
+
private base;
|
|
66
|
+
private previewMask;
|
|
67
|
+
private baseMask;
|
|
68
|
+
private readonly listeners;
|
|
69
|
+
/** Why the preview could not be made (no pixels), for the UI. */
|
|
70
|
+
error: string | null;
|
|
71
|
+
/** A note for the UI, such as object aware refinement applying only on OK. */
|
|
72
|
+
note: string | null;
|
|
73
|
+
/** Bumped each time the preview changes, so a UI can redraw. */
|
|
74
|
+
revision: number;
|
|
75
|
+
constructor(controller: ImageEditorController);
|
|
76
|
+
get settings(): SelectAndMaskSettings;
|
|
77
|
+
get edits(): readonly RefineEdit[];
|
|
78
|
+
/** Reads the image and makes the first preview. Resolves to false when the pixels are unavailable. */
|
|
79
|
+
open(): Promise<boolean>;
|
|
80
|
+
subscribe(listener: () => void): () => void;
|
|
81
|
+
private emit;
|
|
82
|
+
/** Preview size and the scale from natural pixels to it. */
|
|
83
|
+
get previewSize(): {
|
|
84
|
+
width: number;
|
|
85
|
+
height: number;
|
|
86
|
+
scale: number;
|
|
87
|
+
};
|
|
88
|
+
/** Changes settings; the preview follows. Choosing a view also sets its usual opacity. */
|
|
89
|
+
update(changes: Partial<SelectAndMaskSettings>): void;
|
|
90
|
+
private rescale;
|
|
91
|
+
/** Recomputes the preview mask from the base selection, the strokes and the settings. */
|
|
92
|
+
recompute(): void;
|
|
93
|
+
/** Coverage 0..1 of the preview at (x, y) in preview pixels (for tests and hover readouts). */
|
|
94
|
+
coverageAt(x: number, y: number): number;
|
|
95
|
+
/** The preview drawn in the current view mode: RGBA at {@link previewSize}. */
|
|
96
|
+
render(): Uint8ClampedArray;
|
|
97
|
+
/**
|
|
98
|
+
* Pointer down at `point` (natural pixels) with the current tool: starts a stroke (Quick
|
|
99
|
+
* Selection, brushes, lasso) or a box (Object Selection). Alt (or the subtract mode) removes.
|
|
100
|
+
* Hand and Zoom are the UI's own; they return false here.
|
|
101
|
+
*/
|
|
102
|
+
begin(point: ImagePoint, modifiers?: {
|
|
103
|
+
altKey?: boolean;
|
|
104
|
+
}): boolean;
|
|
105
|
+
/** Pointer move while a stroke is down. */
|
|
106
|
+
move(point: ImagePoint): void;
|
|
107
|
+
/** Pointer up: the stroke becomes an edit (one step of the workspace's own undo). */
|
|
108
|
+
end(): void;
|
|
109
|
+
/** Removes the last stroke (Ctrl/⌘+Z in the workspace). Returns false when there is none. */
|
|
110
|
+
undoEdit(): boolean;
|
|
111
|
+
/** Clears the strokes and goes back to the default settings (Reset). */
|
|
112
|
+
reset(): void;
|
|
113
|
+
/**
|
|
114
|
+
* Photoshop's keys in the workspace: a view letter, F (next view), X (all views off and on:
|
|
115
|
+
* Show Original), J (Show Edge), P (Show Original), a tool letter, [ and ] (brush size).
|
|
116
|
+
* Returns true when the key was used.
|
|
117
|
+
*/
|
|
118
|
+
handleKey(key: string): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* OK: applies the strokes and settings to the image as one undo step (the same call an agent
|
|
121
|
+
* makes) and remembers the settings when asked to.
|
|
122
|
+
*/
|
|
123
|
+
commit(): Promise<RefineOutputResult>;
|
|
124
|
+
}
|
|
125
|
+
/** Forgets the remembered workspace settings. */
|
|
126
|
+
export declare function forgetSelectAndMaskSettings(): void;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Select and Mask workspace without a UI: its settings, strokes, preview and view modes, shared
|
|
3
|
+
* by the React and Svelte workspaces. Everything it holds is plain data (the strokes are
|
|
4
|
+
* `RefineEdit`s), and OK runs the same `refineSelectionTo` call an agent makes with `edits`, so
|
|
5
|
+
* the workspace and an agent produce the same result in one undo step.
|
|
6
|
+
*
|
|
7
|
+
* The preview is computed on a copy reduced to {@link PREVIEW_SIZE} px (or at full size with High
|
|
8
|
+
* Quality Preview) and drawn as RGBA in the chosen view mode.
|
|
9
|
+
*/
|
|
10
|
+
import type { ImageEditorController, RefineOutput, RefineOutputResult } from '../controller.js';
|
|
11
|
+
import type { ImagePoint } from '../types.js';
|
|
12
|
+
import { type RefineEdgeParams } from './refine.js';
|
|
13
|
+
import { type RefineEdit } from './refine-edits.js';
|
|
14
|
+
export type SelectAndMaskView = 'onion-skin' | 'marching-ants' | 'overlay' | 'on-black' | 'on-white' | 'black-white' | 'on-layers';
|
|
15
|
+
export type SelectAndMaskTool = 'quick-select' | 'refine-brush' | 'brush' | 'object' | 'lasso' | 'hand' | 'zoom';
|
|
16
|
+
/** The view modes with Photoshop's keys, in menu order. */
|
|
17
|
+
export declare const SELECT_AND_MASK_VIEWS: readonly {
|
|
18
|
+
id: SelectAndMaskView;
|
|
19
|
+
label: string;
|
|
20
|
+
key: string;
|
|
21
|
+
opacity: number;
|
|
22
|
+
}[];
|
|
23
|
+
/** The workspace tools with Photoshop's keys. */
|
|
24
|
+
export declare const SELECT_AND_MASK_TOOLS: readonly {
|
|
25
|
+
id: SelectAndMaskTool;
|
|
26
|
+
label: string;
|
|
27
|
+
key: string;
|
|
28
|
+
}[];
|
|
29
|
+
export interface SelectAndMaskSettings {
|
|
30
|
+
params: Required<RefineEdgeParams>;
|
|
31
|
+
output: RefineOutput;
|
|
32
|
+
/** Decontaminate Colors amount 0..100 (new-layer outputs). */
|
|
33
|
+
decontaminate: number;
|
|
34
|
+
refineMode: 'color' | 'object';
|
|
35
|
+
view: SelectAndMaskView;
|
|
36
|
+
/** How strongly the view shows what is not selected, 0..1. */
|
|
37
|
+
opacity: number;
|
|
38
|
+
/** Show only the area the refinement changes. */
|
|
39
|
+
showEdge: boolean;
|
|
40
|
+
/** Show the selection as it was, before the workspace. */
|
|
41
|
+
showOriginal: boolean;
|
|
42
|
+
/** Update the preview while painting (otherwise on release). */
|
|
43
|
+
realTime: boolean;
|
|
44
|
+
/** Preview at full size instead of a reduced copy. */
|
|
45
|
+
highQuality: boolean;
|
|
46
|
+
/** Keep these settings for the next time the workspace opens. */
|
|
47
|
+
remember: boolean;
|
|
48
|
+
tool: SelectAndMaskTool;
|
|
49
|
+
/** Brush diameter in natural pixels. */
|
|
50
|
+
brushSize: number;
|
|
51
|
+
brushMode: 'add' | 'subtract';
|
|
52
|
+
}
|
|
53
|
+
export declare const DEFAULT_SELECT_AND_MASK_SETTINGS: SelectAndMaskSettings;
|
|
54
|
+
/** Long side of the reduced preview. */
|
|
55
|
+
export declare const PREVIEW_SIZE = 1024;
|
|
56
|
+
export declare class SelectAndMaskSession {
|
|
57
|
+
readonly controller: ImageEditorController;
|
|
58
|
+
private settingsValue;
|
|
59
|
+
private readonly editsList;
|
|
60
|
+
/** The edit being painted, shown in the preview but not yet in `edits`. */
|
|
61
|
+
private live;
|
|
62
|
+
private dragStart;
|
|
63
|
+
private pixels;
|
|
64
|
+
private previewPixels;
|
|
65
|
+
private base;
|
|
66
|
+
private previewMask;
|
|
67
|
+
private baseMask;
|
|
68
|
+
private readonly listeners;
|
|
69
|
+
/** Why the preview could not be made (no pixels), for the UI. */
|
|
70
|
+
error: string | null;
|
|
71
|
+
/** A note for the UI, such as object aware refinement applying only on OK. */
|
|
72
|
+
note: string | null;
|
|
73
|
+
/** Bumped each time the preview changes, so a UI can redraw. */
|
|
74
|
+
revision: number;
|
|
75
|
+
constructor(controller: ImageEditorController);
|
|
76
|
+
get settings(): SelectAndMaskSettings;
|
|
77
|
+
get edits(): readonly RefineEdit[];
|
|
78
|
+
/** Reads the image and makes the first preview. Resolves to false when the pixels are unavailable. */
|
|
79
|
+
open(): Promise<boolean>;
|
|
80
|
+
subscribe(listener: () => void): () => void;
|
|
81
|
+
private emit;
|
|
82
|
+
/** Preview size and the scale from natural pixels to it. */
|
|
83
|
+
get previewSize(): {
|
|
84
|
+
width: number;
|
|
85
|
+
height: number;
|
|
86
|
+
scale: number;
|
|
87
|
+
};
|
|
88
|
+
/** Changes settings; the preview follows. Choosing a view also sets its usual opacity. */
|
|
89
|
+
update(changes: Partial<SelectAndMaskSettings>): void;
|
|
90
|
+
private rescale;
|
|
91
|
+
/** Recomputes the preview mask from the base selection, the strokes and the settings. */
|
|
92
|
+
recompute(): void;
|
|
93
|
+
/** Coverage 0..1 of the preview at (x, y) in preview pixels (for tests and hover readouts). */
|
|
94
|
+
coverageAt(x: number, y: number): number;
|
|
95
|
+
/** The preview drawn in the current view mode: RGBA at {@link previewSize}. */
|
|
96
|
+
render(): Uint8ClampedArray;
|
|
97
|
+
/**
|
|
98
|
+
* Pointer down at `point` (natural pixels) with the current tool: starts a stroke (Quick
|
|
99
|
+
* Selection, brushes, lasso) or a box (Object Selection). Alt (or the subtract mode) removes.
|
|
100
|
+
* Hand and Zoom are the UI's own; they return false here.
|
|
101
|
+
*/
|
|
102
|
+
begin(point: ImagePoint, modifiers?: {
|
|
103
|
+
altKey?: boolean;
|
|
104
|
+
}): boolean;
|
|
105
|
+
/** Pointer move while a stroke is down. */
|
|
106
|
+
move(point: ImagePoint): void;
|
|
107
|
+
/** Pointer up: the stroke becomes an edit (one step of the workspace's own undo). */
|
|
108
|
+
end(): void;
|
|
109
|
+
/** Removes the last stroke (Ctrl/⌘+Z in the workspace). Returns false when there is none. */
|
|
110
|
+
undoEdit(): boolean;
|
|
111
|
+
/** Clears the strokes and goes back to the default settings (Reset). */
|
|
112
|
+
reset(): void;
|
|
113
|
+
/**
|
|
114
|
+
* Photoshop's keys in the workspace: a view letter, F (next view), X (all views off and on:
|
|
115
|
+
* Show Original), J (Show Edge), P (Show Original), a tool letter, [ and ] (brush size).
|
|
116
|
+
* Returns true when the key was used.
|
|
117
|
+
*/
|
|
118
|
+
handleKey(key: string): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* OK: applies the strokes and settings to the image as one undo step (the same call an agent
|
|
121
|
+
* makes) and remembers the settings when asked to.
|
|
122
|
+
*/
|
|
123
|
+
commit(): Promise<RefineOutputResult>;
|
|
124
|
+
}
|
|
125
|
+
/** Forgets the remembered workspace settings. */
|
|
126
|
+
export declare function forgetSelectAndMaskSettings(): void;
|
package/package.json
CHANGED
|
@@ -269,7 +269,7 @@ in the source frame at the document's bit depth, colour mode and profile. Read
|
|
|
269
269
|
| `grow_selection` | Select › Grow: add connected pixels within `tolerance` (default 32) of a selected colour; follows colour, not distance. `sample`, `sampleMerged`. Fails when nothing is selected. Returns the summary. |
|
|
270
270
|
| `select_similar` | Select › Similar: add every pixel in the image within `tolerance` of a selected colour, connected or not. Fails when nothing is selected. Returns the summary. |
|
|
271
271
|
| `reselect` | Bring back the last selection `deselect` cleared (one undo step). Fails when there is none. Returns the summary. |
|
|
272
|
-
| `refine_selection` | Select and Mask: snap the selection edge to image edges within `radius` px (0..64, default 8), with `smartRadius`, `smooth` 0..100, `feather` px, `contrast` 0..100 and `shiftEdge` -100..100 %, then `output` to `selection` (default), `layer-mask`, `new-layer` or `new-layer-with-mask` (on `layerId`, default active; new layers hide the source), with `decontaminate` 0..100 for new layers. One step; returns `layerId` / `newLayerId`. Use on hair, fur, foliage or
|
|
272
|
+
| `refine_selection` | Select and Mask: snap the selection edge to image edges within `radius` px (0..64, default 8), with `smartRadius`, `smooth` 0..100, `feather` px, `contrast` 0..100 and `shiftEdge` -100..100 %, then `output` to `selection` (default), `layer-mask`, `new-layer` or `new-layer-with-mask` (on `layerId`, default active; new layers hide the source), with `decontaminate` 0..100 for new layers. `edits` (`quick-select`, `brush`, `lasso`, `object` add/subtract; `refine-brush` over hair) apply first; `refineMode: "object"` uses the host model. One step; returns `refineMode`, `layerId` / `newLayerId`. Use on hair, fur, foliage or a coarse AI mask. |
|
|
273
273
|
| `update_adjustment_layer` | Change a layer's `enabled` (false hides it without deleting), `blend`, `opacity` (0..1) or `name` in one undo step. Returns the layer. Its parameters change with `set_adjustments`. Toggle `enabled` to compare a layer's effect before and after. |
|
|
274
274
|
| `move_adjustment_layer` | Move a layer to index `to` (0 = bottom, applied first; past the top means top). Order matters: a curves layer above a hue/saturation layer works on its output. Fails when the layer is already there. Returns the ids bottom to top. |
|
|
275
275
|
| `remove_adjustment_layer` | Delete a layer and its mask. Prefer hiding it with `update_adjustment_layer` when the user may want it back. Returns the remaining ids. |
|
|
@@ -57,7 +57,12 @@ This skill is the method. `pixerate-image-editor` has the full tool reference.
|
|
|
57
57
|
`layerId` (white adds, black removes, a soft brush feathers; `blur_stroke` softens a part
|
|
58
58
|
of the edge), then `set_quick_mask` `enabled: false`.
|
|
59
59
|
- `refine_selection` snaps to real edges: radius 2–4 for hard edges, 8–20 for hair and fur;
|
|
60
|
-
`smartRadius: true` for mixed edges.
|
|
60
|
+
`smartRadius: true` for mixed edges. For flyaway hair beyond the radius, add `edits` with a
|
|
61
|
+
`refine-brush` stroke along it (size covering the strands); fix misses and leaks in the same
|
|
62
|
+
call with `quick-select`, `brush` or `lasso` strokes, or an `object` box (`mode:
|
|
63
|
+
"subtract"` to remove). These are the Select and Mask workspace's own tools, so a person
|
|
64
|
+
can open the same edits in the workspace. With a host model, `refineMode: "object"`
|
|
65
|
+
refines from the model's outline.
|
|
61
66
|
- `shiftEdge` −10..−30 % tightens a refined edge that picked up background.
|
|
62
67
|
**Check:** `percent` changed by roughly what you intended (a few percent at most for a
|
|
63
68
|
cleanup).
|