Repository navigation
masks: a brush draws where its fading starts, and its size and fading edit its solid part and its ramp - #1634
Merged
Merged
Conversation
Jiyone
force-pushed
the
masks/brush-fading-contour
branch
from
November 11, 2026 21:59
b13a3cd to
e3a1020
Compare
A brush paints each spoke at full density over the first `fading` of its length and ramps to zero past it, but the overlay drew only its spine and, when selected, its dashed border: nothing showed where the fading started, or that a scroll on the fading had changed it. `get_points_border` now hands out the contour on the spokes through a new `fading` out-parameter, built in place from the producer's payload and index-aligned with the border; every other shape leaves it NULL. That contour is not the edge to draw. The solid part is the union of the bands between neighbouring spokes, and where the spokes lie along the spine (a size that climbs steeply, a small fading on a wide node) its edge is made of the spokes' sides, which no pass over the spoke ends can trace. The new masks_solid.c fills that union on a grid of one cell per device pixel and traces its half-coverage level by marching squares into closed loops, which the brush strokes solid in every state; its dashed border is still drawn only when it is selected. The bands are grouped into runs of one orientation, each a positively wound polygon, filled non-zero with exact crossings on four sub-scanlines per row, without cairo, which the toolkit ratchet keeps out of develop/. A run turns over only after a tenth of a cell of backward sweep, so a trembling long spoke does not split it at every band; the lobe of a bow-tie band wound against its run is added back twice, or it leaves a hole; a line's crossings are radix-sorted past 32. The corpus gains brush-fading-pinch and brush-fading-neck, and a judge that wants every pixel on the edge of the raster's full-density part within 4 px of the traced edge: all are within 3.12 px. At fit zoom a brush's outline build costs 1.2 to 10.9 ms more and a frame 0.5 to 3.9 ms more; the measurements are in doc/brush-boundary.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The line through a brush's nodes carries them but is no edge of the mask; the edge where its fading starts is now the solid line, and the two read alike when both are solid. dt_masks_draw_path_seg_by_seg() strokes the centreline with round dots; its `round_ends` argument, which only the brush passes, becomes `centreline`. The discs it painted on the two true ends are left commented out: stroked solid, they come out darker than the dots they end. The polygon's outline stays solid. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A brush node stores its whole radius and the fraction of it that is solid, and the controls edited those two numbers, so size grew the ramp along with the solid part and the node's border handle changed its size. They now edit the two parts as a circle's controls do: size the solid radius, fading the width of the ramp, each keeping the other. `_brush_resize_part()` turns a change of one part into a new radius and fraction, and the wheel, the context-menu sliders, the node handles and the creation defaults all go through it. The "Fading" slider sets the ramp width, in the units of the circle's and the polygon's border. The wheel scales either part by 1.02 per notch, raised to `flow` as the circle does, up growing it, where fading used to go the other way. A stored brush keeps its mask until one of its nodes is edited. A selected node gets a second handle where its own spoke turns from solid to ramp, which moves the edge of the solid part; the outer handle now moves only the ramp's outer edge. Both share the border-handle state and are told apart by `handle_border_solid`. dt_masks_find_closest_handle_common() takes its callbacks as a dt_masks_hit_callbacks_t, which gains `solid_handle`, rather than an eleventh argument, and post_expose is handed the form it draws, since the handle needs the node's fraction. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
post_expose is handed the form it draws, but the polygon still looked it up again, through the visible group at its own index, to tell which way round its handles go. It now reads the form it is given. Outside a group that lookup found nothing, and in a creation session the index counts the session's shapes, not the group's. _polygon_is_clockwise() takes a const form. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
get_points_border and dt_masks_get_points_border() took seven out-parameters, eleven arguments in all, since the brush added `fading`. They now take one dt_masks_outline_out_t, holding the addresses of the caller's variables, NULL for a part not wanted, as the arguments did: the five shapes and the six callers change in form only, each caller declaring its struct before the call. The shapes no longer clear `border_skips` themselves, which dt_masks_get_points_border(), their only caller, already does. The line numbers doc/ cites in the files touched follow, among them two the previous commits had left behind, in doc/darkroom-redraw.md and doc/masks-geometry.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every read of the brush's `border` conf key keeps it within FADING_MIN and FADING_MAX, a whole radius of at most 1, as the size and fading controls do, except the creation preview's: it kept the key within BORDER_MIN and BORDER_MAX, at most 0.5, and wrote the clamped value back. A size scrolled past 0.5 before the first stroke was toasted, then cut back by the next expose, and the brush started from 0.5. The preview now reads the key as the others do; BORDER_MIN and BORDER_MAX, used nowhere else, are gone. Four line numbers doc/ cites follow, two in brush.c, one in masks_gui.c and one in the geometry test, which the previous commits and the latest of master had left behind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The dotted centreline carries the nodes but is no edge of the mask, and every brush drew it in every state, next to the solid line where its fading starts. It is now drawn on the selected brush only, as its dashed border is: an unselected brush shows where its fading starts and nothing else. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dt_masks_hit_callbacks_t carries its user data, and the five callback types take it, as const void *: no callback writes through it, and the brush, which passes the form it draws, no longer casts the const away. Alongside, as SonarCloud asks of the code this branch touches: _gradient_get_points_border() marks its unused `source` and loses a comment orphaned by an earlier change, a brush node's two border values are assigned one at a time, and every multiple declaration in masks_solid.c, dt_masks_gui_form_remove() and the geometry test's fading-edge judge is split one to a line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dt_masks_solid_edge() traces the half-coverage level of the union of the bands between neighbouring spokes. Where the spokes lie along the spine, that union is a thread round it, and brush-fading-neck's is some 0.5 px thick: across the neck its cells read 50 to 175 out of 255, the level at 128, so it broke into islands that float rounding chose. The RelWithDebInfo build, with -ffast-math, traced 9 loops; the Debug builds the CI runs, without it, traced 7, left 9 px of the neck with no edge point within 4 px, and failed the geometry corpus on GNU, LLVM 20 and Windows alike. The spokes start on the spine, so the solid part holds it: every cell the spine of a kept band crosses is now set full before the trace, the segment walked from cell to cell across their sides. The neck is one loop round the spine in both builds, all its pixels within 2.47 px of the edge; brush-fading-pinch, whose solid part narrows to a point at its middle node, becomes one loop joined there, under the node's disc; the 18 other brushes and frames trace the same loops as before, within the same 2.65 px. The walk takes 0.57 ms in median over the corpus's 39 fills and 1.84 ms at most. doc/brush-boundary.md records it, and that a Debug build traces 4 loops on brush-1074-flare where RelWithDebInfo traces one, one of them a hole about a pixel wide that the judge does not see. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Jiyone
force-pushed
the
masks/brush-fading-contour
branch
from
November 12, 2026 00:01
e3a1020 to
c34db68
Compare
…teps from its start The previous two commits changed lines SonarCloud then read as new. Thirteen hit-test callbacks ignore their user data (three each of the brush, the ellipse, the gradient and the polygon, and the circle's one; SonarCloud flagged nine of them), and the ellipse's post-select also ignores `inside` and `inside_source`: they must keep the signature of their callback type, so those parameters are marked __attribute__((unused)), as the tree marks them elsewhere. _solid_spine() had a cognitive complexity of 29. It walked each segment with four accumulators, the fraction of the segment to the next side across x and across y and their steps. Each step now decides from the segment's start which side of the cell it reaches first, comparing |sx dy| with |sy dx|: two variables fewer, no error building up along the segment, and a complexity of about 17 counted by hand, below the 25 SonarCloud allows. On the geometry corpus, every verdict and every one of the 27 overlays is identical to the byte with the previous walk, in the RelWithDebInfo build and in a Debug one. The walk takes 0.59 ms in median over the corpus's 39 fills and 1.88 to 2.00 ms at most over two runs, against 0.57 and 1.84 ms before; doc/brush-boundary.md carries the new figures. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_gradient_post_select_cb() reads neither `inside_source` nor its user data. They keep the signature of the callback type, so both are marked __attribute__((unused)), as the other hit-test callbacks mark theirs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Between two nodes, the solid part was the first `fading` of each spoke, the fading eased linearly while the radius eased by a smoothstep. That point leans with the border's rate, not the solid part's, and lies on the envelope of nothing: between two nodes of one solid radius and different radii, the line where the fading starts bulged toward the wider node and moved when the border handle was dragged, and where the smaller disc nests in the larger the solid part thinned to a thread. A node's solid radius is now its radius times its fading, eased between the nodes by the same smoothstep, and a spoke's edge sample lies on the envelope of those discs, placed by _brush_border_get_XY() in the same evaluation of the Bézier that places its border sample. The payload stores that edge in the frame of its spoke, three values a sample, so it rides any distortion; the pipe and the GUI turn it into points after their own with _brush_payload_to_edges(). A joint arc, a cap or a borrowed border is radial; the spokes of an arc closing a gap in the border inside a segment take their leaf's edge. The raster paints each spoke solid to its edge and ramping from there to its border, and a spoke whose solid piece is the previous one's, to the pixel and the density, paints only its ramp. masks_solid.c begins a run once its bands have swept a tenth of a cell between them, not once one band is that wide: where the border moves fast the spine is sampled a fiftieth of a pixel apart, and brush-ramp-nested lost a stretch of its fill. The corpus gains a `solid part` judge, which holds the raster's full part to the disc union (every pixel within the discs shrunk by 2 px full, every full pixel within them grown by 3), and two brushes modelled on a test session's screenshots, brush-ramp-taper and brush-ramp-nested. Against the library built from 1b124f5 the judge fails 11 of its 21 brushes and frames; now it passes all 21 with 0 px either way, in the RelWithDebInfo build and in a Debug one, and every pixel on the full part's edge lies within 1.53 to 1.70 px of the fading edge, against 2.02 to 2.65. On the corpus, where a brush's nodes share a radius and a fading, 12 to 26 % of its painted pixels change, by at most 9 to 17 out of 255; elsewhere the solid part changes shape. Summed over its 22 brushes and frames, the lower of three runs, the walk takes 238.5 ms against 224.2, painting 1118.0 against 1522.0 and the whole buffer 1396.4 against 1772.5; the overlay's frames and builds move within noise. A boundary pass over the edge samples, measured in place of the fill and trace, kept up to 1281 points inside the solid part for no saving. doc/brush-boundary.md, masks-geometry.md and masks-gui.md carry the account. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eclaration SonarCloud reported five issues on the previous commit. _solid_band_signs() had a cognitive complexity of 35 and a nested conditional operator: it now sets the signs in one pass, a run waiting to begin handled apart from a run going on, then counts the bow ties and extends the box over the kept bands in a second. A run turns only on a band against it, so it turns to the other way without testing that band's sign. On the geometry corpus every verdict is the same and every render is identical to the byte with the previous code, against the bank's baselines. _brush_get_mask() declares its three segment ends one per statement. The two others, the `restrict` of _brush_bounding_box_raw() and the nine parameters of _brush_bounding_box(), are master's own issues on lines this branch changed; fixing them would twist the code, so they are left to be accepted in SonarCloud. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What changes
A brush now shows where its fading starts, and its size and fading edit the two parts of its radius as a circle's do. One commit per step, then nine follow-ups.
1. The edge where the fading starts is drawn solid (
2081ffb00b)A brush paints each spoke at full density over the first
fadingof its length and ramps to zero past it. The overlay drew only its spine and, when selected, its dashed border: nothing showed where the fading started, or what a scroll on the fading had changed.get_points_borderhands out the contour on the spokes through a newfadingout-parameter, built in place from the producer's payload. Every other shape leaves it NULL.masks_solid.cfills the union of the bands between neighbouring spokes on a grid of one cell per device pixel, then traces its half-coverage level into closed loops by marching squares. It does not use cairo, sincecheck_module_boundaries.shkeeps the toolkit out ofdevelop/.2. The centreline is dotted (
5a136d1a04)The line through the nodes carries them but is not an edge of the mask, and it looked just like the new solid line.
dt_masks_draw_path_seg_by_seg()strokes it with round dots. Itsround_endsargument, which only the brush passed, becomescentreline.3. Size edits the solid part, fading the ramp (
5ce746a011)A node stores its whole radius and the fraction of it that is solid, and the controls edited those two numbers. So size grew the ramp along with the solid part, and the node's border handle changed its size.
_brush_resize_part()turns a change of one part into a new radius and fraction, keeping the other part as it is. The wheel, the context-menu sliders, both node handles and the creation defaults all go through it.flowas the circle does, and up grows it. Fading used to go the other way.handle_border_solid.dt_masks_find_closest_handle_common()takes its callbacks as adt_masks_hit_callbacks_t, going from 10 parameters to 5, instead of gaining an eleventh.post_exposeis handed the form it draws, since the new handle needs the node's fraction.4. Follow-ups
9894b78409). Itspost_exposelooked the form up again through the visible group, at its own index: outside a group that found nothing, and in a creation session the index counts the session's shapes, not the group's.get_points_borderwrites through adt_masks_outline_out_t(7b11701ed8). Withfadingit had reached seven out-parameters, eleven arguments in all. The struct holds the addresses of the caller's variables, NULL for a part not wanted, as the arguments did, so the five shapes and the six callers change in form only. Each function goes from 11 parameters to 5 and loses 2 of lizard's complexity. The shapes no longer clearborder_skipsthemselves, sincedt_masks_get_points_border(), their only caller, already does.2924759cfb). Every read of the brush'sborderconf key allows a whole radius of up to 1, except the creation preview's, which clamped it to 0.5 and wrote that back. A size scrolled past 0.5 before the first stroke was toasted, then cut back, and the brush started from 0.5. The preview now reads the key as the others do.a6e97875cc), as its dashed border is. An unselected brush shows where its fading starts and nothing else.aff63448d6), so the brush no longer casts away the const of the form it passes. Alongside, the SonarCloud smells in the code this branch touches: an unused parameter marked, chained assignments and multiple declarations split.c34db68a44). Where the spokes lie along the spine, the solid part is a thread round it. Onbrush-fading-neckit is some 0.5 px thick, its cells reading 50 to 175 out of 255 against a level of 128, so it broke into islands that float rounding chose: 9 loops with-ffast-math, 7 without. The Debug builds of the CI, without it, failed the geometry corpus on GNU, LLVM 20 and Windows. The spokes start on the spine, so the cells it crosses are now set full before the trace, and the neck is one loop round it in both builds.1b124f5651), for the SonarCloud issues the two commits above raised. The callbacks that ignore their user data mark it__attribute__((unused)), since they must keep their callback type's signature. The walk along the spine had a cognitive complexity of 29: each step now decides from the segment's start which side of its cell it reaches first, instead of carrying four accumulators. Every verdict and every overlay of the geometry corpus is identical to the byte, in a RelWithDebInfo and a Debug build.0d108992d6): the last SonarCloud issue of that kind.3bac7a1a1b). Between two nodes the solid part was the firstfadingof each spoke, with the fading eased linearly while the radius eased by a smoothstep. That point leans with the border's rate and lies on the envelope of nothing. So between two nodes of one solid radius and different radii, the line where the fading starts bulged toward the wider node and moved when the border handle was dragged. Where the smaller disc nests in the larger, the solid part thinned to a thread._brush_border_get_XY()places it in the same Bézier evaluation as the border sample.masks_solid.cbegins a run once its bands have swept a tenth of a cell between them. Waiting for one band that wide dropped part ofbrush-ramp-nested's fill, where the spine is sampled a fiftieth of a pixel apart.These commits also bring the
doc/line citations into the touched files up to date, including some that earlier commits of the branch or of master had left behind.Documented in:
doc/brush-boundary.md, section "Where the fading starts";doc/masks-gui.md, section "A brush's size and fading edit its solid part and its ramp, as a circle's do";doc/masks-geometry.md.Measured
Measured with
tests/masks/masks_geometry.con a RelWithDebInfo build.Accuracy. The corpus gains four brushes and two judges:
brush-fading-pinch,brush-fading-neck, andbrush-ramp-taperandbrush-ramp-nested(modelled on the test session's screenshots);_judge_fading_edge()wants every pixel on the edge of the raster's full-density part within 4 px of the traced edge;_judge_solid_part()holds that full part to the disc union. Every pixel within the discs shrunk by 2 px must be full, and every full pixel must lie within them grown by 3.On
3bac7a1a1b, in RelWithDebInfo and in Debug, the solid-part judge passes all 21 brushes and frames with 0 px either way. Against the library built from1b124f5651, it fails 11 of them, for examplebrush-ramp-taperwith 2744 px in excess andbrush-fading-neckwith 6639 missing. The worst pixel of the fading edge is 1.53 to 1.70 px away, against 2.02 to 2.65 before.In a Debug build,
brush-1074-flaretraces 4 loops where RelWithDebInfo traces one. Onaff63448d6, one of them was a hole about a pixel wide inside its solid part, which the judge does not see. It is left as is.Alternative measured. In place of the fill and trace, a boundary pass over the edge samples (
dt_masks_outline_boundary_skips()) was faster on 3 of 21 cases and slower on the others. It left 1 to 19 open runs instead of closed loops, and kept up to 1281 points inside the solid part where the envelope folds (brush-1074-flare-b).Cost.
--time-overlay 30at a 2560×1440 view and fit zoom, lower of two runs, before → after, in ms:The table was measured before
c34db68a44. On3bac7a1a1bagainst1b124f5651, two runs each way: every brush's frames are within 0.26 ms and its builds within 3.4 ms.Raster,
MASKS_DEBUG=1, summed over the corpus's 22 brushes and frames, lower of three runs,1b124f5651→3bac7a1a1b:The skip changes no pixel: the corpus's 29 masks are identical to the bit with and without it. The walk along the spine adds 0.59 ms in median over the corpus's 39 fills and 1.88 to 2.00 ms at most, on 178,887 bands, over two runs with a probe in a RelWithDebInfo build on
1b124f5651.The fill itself is described in
doc/brush-boundary.md: runs of one orientation, bow-tie lobes, the radix sort of the crossings, and the grid limits.Tested by hand in a RelWithDebInfo build with OpenCL:
before the rebase onto
e19adbd0b9:post_exposechanged signature;before the rebase onto
f76012b77f:on
3bac7a1a1b, before its edge moved into the border's Bézier evaluation and before the repeated solid pieces were skipped: the line where the fading starts between two nodes of one solid radius, moderate and nested, while dragging the border handle.Not tested by hand yet:
a6e97875cc, which hides the centreline of an unselected brush;c34db68a44, which turns a thin neck from islands into one loop.ctest: 32/32 pass onc34db68a44, on1b124f5651and on3bac7a1a1b. The CI passes onc34db68a44, its Debug cells included.Gates run on this head, all pass:
check_layering.sh(cycles 0)check_module_boundaries.shcheck_return_types.pycheck_list_order.pypragma_once_to_guards.py --verifycheck_conditional_includes.sh origin/mastercheck_unused_includes.sh --changed origin/mastercheck_statelessness.shwas not run: it coverssrc/system,src/mathandsrc/widgets, which this branch does not touch. No new warning under clang-19.Left as is
Accepted in SonarCloud:
post_exposeand of the test's judge (c:S3776);breaks of the trace's loop (c:S924);_change_part's 8 parameters (c:S107);masks_gui.c(c:S125), kept on purpose for reuse;brush.c(c:S2259), which the producer never hands out with a payload, and an out-of-bounds read in the test (c:S3519).🤖 Generated with Claude Code