Skip to content

Commit 2da1626

Browse files
committed
Implements path mask resize via rasterization and re-vectorization
Grow/shrink a path mask by rasterizing it to a bitmap, applying an exact Euclidean distance transform (Meijster 2000) to offset the boundary, then re-vectorizing with potrace. Includes a LIFO per-form cache to avoid recomputing at previously visited steps. Exposes user preferences for step amount, unit (px / % of path size), tracing resolution, and curve smoothing. Adds options to the mask manager to grow/shrink a mask by a specific amount for fine grained control. Re-routes the pre-existent resize algo (distance from centroid) to use CTRL+SHIFT+scroll, so that the two algorithms can co-exist.
1 parent cfe57f3 commit 2da1626

4 files changed

Lines changed: 1273 additions & 89 deletions

File tree

data/darktableconfig.xml.in

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<dttab name="darkroom" title="darkroom">
1212
<section title="general"/>
1313
<section name="modules" title="modules"/>
14+
<section name="masking" title="masking"/>
1415
</dttab>
1516
<dttab name="processing" title="processing">
1617
<section name="general" title="image processing"/>
@@ -1571,13 +1572,59 @@
15711572
<shortdescription>smoothing of brush strokes</shortdescription>
15721573
<longdescription>sets level for smoothing of brush strokes.\nstronger smoothing leads to less nodes and easier editing but with lower control of accuracy.</longdescription>
15731574
</dtconfig>
1574-
<dtconfig prefs="darkroom" section="general">
1575+
<dtconfig prefs="darkroom" section="masking">
15751576
<name>masks_scroll_down_increases</name>
15761577
<type>bool</type>
15771578
<default>false</default>
15781579
<shortdescription>scroll down to increase mask parameters</shortdescription>
15791580
<longdescription>when using the mouse scroll wheel to change mask parameters, scroll down to increase the mask size, feather size, opacity, brush hardness and gradient curvature\nby default scrolling up increases these parameters</longdescription>
15801581
</dtconfig>
1582+
<dtconfig prefs="darkroom" section="masking">
1583+
<name>masks/path_resize_amount</name>
1584+
<type>int</type>
1585+
<default>2</default>
1586+
<shortdescription>path mask resize step amount</shortdescription>
1587+
<longdescription>amount to grow or shrink a path mask per scroll wheel tick when resizing. the unit is set by the 'path mask resize unit' preference.</longdescription>
1588+
</dtconfig>
1589+
<dtconfig prefs="darkroom" section="masking">
1590+
<name>masks/path_resize_unit</name>
1591+
<type>
1592+
<enum>
1593+
<option>pixels</option>
1594+
<option>% of path size</option>
1595+
</enum>
1596+
</type>
1597+
<default>pixels</default>
1598+
<shortdescription>unit for path mask resize step amount</shortdescription>
1599+
<longdescription>unit for the path mask resize step: 'pixels' uses image pixels, '% of path size' uses a percentage of the path's largest bounding box dimension.</longdescription>
1600+
</dtconfig>
1601+
<dtconfig prefs="darkroom" section="masking">
1602+
<name>masks/path_resize_resolution</name>
1603+
<type>
1604+
<enum>
1605+
<option>512</option>
1606+
<option>1024</option>
1607+
<option>2048</option>
1608+
<option>4096</option>
1609+
</enum>
1610+
</type>
1611+
<default>2048</default>
1612+
<shortdescription>path mask resize tracing resolution</shortdescription>
1613+
<longdescription>internal raster resolution (in pixels on the longest side) used when re-vectorizing a resized path mask. higher values preserve more detail and nodes at the cost of speed.</longdescription>
1614+
</dtconfig>
1615+
<dtconfig prefs="darkroom" section="masking">
1616+
<name>masks/path_resize_curve_smoothing</name>
1617+
<type>
1618+
<enum>
1619+
<option>sharp</option>
1620+
<option>balanced</option>
1621+
<option>smooth</option>
1622+
</enum>
1623+
</type>
1624+
<default>balanced</default>
1625+
<shortdescription>path mask resize curve smoothing</shortdescription>
1626+
<longdescription>controls how corners are handled when re-vectorizing a resized path mask. 'sharp' preserves more nodes and corners; 'smooth' produces fewer, rounder control points.</longdescription>
1627+
</dtconfig>
15811628
<dtconfig prefs="darkroom" section="general">
15821629
<name>darkroom/mouse/middle_button_cycle_zoom_to_200_percent</name>
15831630
<type>bool</type>
@@ -4097,7 +4144,7 @@
40974144
<shortdescription>show right-side buttons in processing module headers</shortdescription>
40984145
<longdescription>when the mouse is not over a module, the multi-instance, reset and preset buttons can be hidden:\n - 'always': always show all buttons,\n - 'active': only show the buttons when the mouse is over the module,\n - 'dim': buttons are dimmed when mouse is away,\n - 'auto': hide the buttons when the panel is narrow,\n - 'fade': fade out all buttons when panel narrows,\n - 'fit': hide all the buttons if the module name doesn't fit,\n - 'smooth': fade out all buttons in one header simultaneously,\n - 'glide': gradually hide individual buttons as needed</longdescription>
40994146
</dtconfig>
4100-
<dtconfig prefs="darkroom" section="modules">
4147+
<dtconfig prefs="darkroom" section="masking">
41014148
<name>darkroom/ui/show_mask_indicator</name>
41024149
<type>bool</type>
41034150
<default>true</default>

src/develop/masks.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,21 @@ typedef struct dt_masks_functions_t
232232
int *count,
233233
float *min,
234234
float *max);
235+
// grow/shrink (outset/inset) a shape to a signed absolute amount in the given
236+
// unit (use_percent: TRUE = % of shape size, FALSE = image pixels), measured
237+
// from a baseline captured the first time the shape is resized. Positive grows,
238+
// negative shrinks, 0 restores the baseline. Results are cached per offset, so
239+
// re-requesting a value is lossless. Returns TRUE if a usable shape resulted.
240+
// Currently only implemented by path masks.
241+
gboolean (*resize)(struct dt_masks_form_t *const form,
242+
const int amount,
243+
const gboolean use_percent);
244+
// report the resize offset currently applied to the shape, in the requested
245+
// unit, so a UI control can mirror it. Returns FALSE (amount 0) if no resize is
246+
// active. Currently only implemented by path masks.
247+
gboolean (*resize_get)(struct dt_masks_form_t *const form,
248+
const gboolean use_percent,
249+
float *amount);
235250
void (*duplicate_points)(dt_develop_t *const dev,
236251
struct dt_masks_form_t *base,
237252
struct dt_masks_form_t *dest);

0 commit comments

Comments
 (0)