Selection brush and eraser¶
Selection brush¶
| Fact | Value |
|---|---|
| Status | Implemented and tested |
| Group | Brush |
| Engine | Browser |
| Code | web/src/core/mask/raster.ts, paintStroke |
Selection eraser¶
| Fact | Value |
|---|---|
| Status | Implemented and tested |
| Group | Brush |
| Engine | Browser |
| Code | web/src/core/mask/raster.ts, paintStroke |
Overview¶
The selection brush (B) paints the selection. The selection eraser (E) removes it. They are the most direct way to fix a selection that another tool made. A circle at the pointer shows the brush size.
How to use them¶
- Choose the brush or the eraser.
- Paint over the image. The selection updates while you paint.
- With the brush, hold Alt to remove instead of add.
- Turn on Quick Mask (Q) to see the result as a red tint over the unselected part.
How it works¶
Selection brush:
- Stamp the brush along the pointer path, with the brush value at each distance from the center.
- Keep the larger value where stamps overlap.
- Add the stroke to the selection, or remove it while Alt is held.
- Show the result while you paint, then add it to the history when you let go.
Selection eraser:
- Stamp the brush along the pointer path, keeping the larger value where stamps overlap.
- Lower the selection by the stroke: the result is the smaller of the selection and 255 minus the stroke.
- Show the result while you paint, then add it to the history when you let go.
Mathematical foundation¶
The brush value at distance \(d\) from the stroke, for a brush of radius \(r\) and hardness \(h\) from 0 to 1, is
where \(d\) is the distance in pixels from the pixel center to the nearest point of the stroke, and \(e\) is the width of the soft edge. This is an exact definition of what the code computes. A hard brush has one pixel of anti-aliasing. A softer brush fades from full to none over the outer part of its radius, with a smooth S-shaped curve.
The stroke keeps the larger value where stamps overlap. Then, with \(m\) the selection and \(v\) the stroke:
- the brush gives \(\max(m, v)\),
- the eraser, or the brush with Alt, gives \(\min(m, 255 - v)\).
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Size size |
30 | 1 to 1000 px | Diameter of the brush. |
Hardness hardness |
100 | 0 to 100 % | How sharp the edge of the brush is. |
The eraser has the same settings.
Implementation¶
While you paint, only the changed rectangle of the mask goes to the graphics card again. The stroke becomes one history step when you let go.
Limitations¶
- A soft brush selects pixels only partly, so filters blend in near the edge.
- The brush size is in image pixels, so it looks smaller when you zoom out.