Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
masks_functions.h File Reference

The per-shape function table, private to the masks implementation. More...

#include "develop/masks.h"
#include "develop/masks_gui.h"
+ Include dependency graph for masks_functions.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  dt_masks_functions_t
 
struct  dt_masks_sample_grid_t
 

Macros

#define DT_MASKS_OUTLINE_TILT_MAX   1.0f
 
#define DT_MASKS_GRID_MAX_STEP   8
 

Typedefs

typedef struct dt_masks_functions_t dt_masks_functions_t
 
typedef struct dt_masks_sample_grid_t dt_masks_sample_grid_t
 

Functions

dt_masks_raster_result_t dt_masks_get_mask_roi (const dt_iop_module_t *const module, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *const piece, dt_masks_form_t *const form, const dt_iop_roi_t *roi, float *buffer, dt_iop_roi_t *touched)
 
dt_masks_raster_result_t dt_masks_get_points_border (struct dt_develop_t *dev, dt_masks_form_t *form, float **points, int *points_count, float **border, int *border_count, dt_masks_skip_range_t **border_skips, int *border_skip_count, int source, dt_iop_module_t *module)
 
int dt_masks_outline_boundary_skips (const float *const points, const float *const border, const int count, const int header, dt_masks_skip_range_t **skips_out)
 
gboolean dt_masks_outline_short_way (const float *const centre, const float *const from, const float *const to, const gboolean default_clockwise)
 
void dt_masks_outline_offset_along (const float *const centre, float dx, float dy, const float radius, float *const border)
 
void dt_masks_outline_envelope_offset (const float *centre, float dx, float dy, float radius, float radius_rate, float *out)
 
gboolean dt_masks_skip_contains (const dt_masks_skip_range_t *skips, const int skip_count, const int index)
 
void dt_masks_points_bounding_box (const float *const points, const int num_points, int *width, int *height, int *posx, int *posy)
 
float * dt_masks_sample_grid_backtransform (const struct dt_dev_pixelpipe_t *pipe, const double iop_order, const dt_masks_sample_grid_t *const grid, const char *const shape, const char *const form_name)
 
int dt_masks_preview_add_clone_source (struct dt_masks_form_gui_t *gui, struct dt_masks_preview_buffers_t *preview)
 
int dt_masks_points_shift_to_source (struct dt_develop_t *dev, const struct dt_iop_module_t *module, float **points, int *points_count, const float xs, const float ys, const int first_shifted)
 
void dt_masks_sample_grid_interpolate (const float *const points, const dt_masks_sample_grid_t *const grid, float *const buffer, const int buf_width, const int buf_height, int *const endx, int *const endy)
 
int dt_masks_point_in_form_exact (const float *pts, int num_pts, const float *points, int points_start, int points_count, const dt_masks_skip_range_t *skips, int skip_count)
 Ray-cast point-in-polygon over a form point stream, honouring skip ranges.
 
void dt_masks_group_entry_apply_operation (struct dt_masks_form_group_t *pt, const dt_masks_state_t apply_state)
 Apply a mask state operation on a group entry.
 
void dt_masks_form_gui_points_free (gpointer data)
 
void _check_id (dt_develop_t *dev, dt_masks_form_t *mask_form)
 
void _set_group_name_from_module (dt_iop_module_t *module, dt_masks_form_t *group_form)
 
dt_masks_form_t * _group_create (dt_develop_t *develop, dt_iop_module_t *module, dt_masks_type_t group_type)
 
dt_masks_form_t * _group_from_module (dt_develop_t *develop, dt_iop_module_t *module)
 
int _find_in_group (dt_develop_t *dev, dt_masks_form_t *group_form, int form_id)
 

Variables

const dt_masks_functions_t dt_masks_functions_circle
 
const dt_masks_functions_t dt_masks_functions_ellipse
 
const dt_masks_functions_t dt_masks_functions_brush
 
const dt_masks_functions_t dt_masks_functions_polygon
 
const dt_masks_functions_t dt_masks_functions_gradient
 
const dt_masks_functions_t dt_masks_functions_group
 

Detailed Description

The per-shape function table, private to the masks implementation.

Every member is dispatched from inside src/develop/masks/ and nowhere else (measured before the move), so nothing outside the shape files and the masks core has any business seeing the table's layout. Public code holds it only as the opaque dt_masks_form_t.functions pointer, forward-declared in develop/masks.h. Keeping the definition here is also what keeps drawing and event types out of the public header: several members take dt_masks_form_gui_t* or a shape_draw_function_t.

Definition in file masks_functions.h.

Macro Definition Documentation

◆ DT_MASKS_GRID_MAX_STEP

#define DT_MASKS_GRID_MAX_STEP   8

Largest cell spacing any caller of the sample-grid helpers may ask for.

The ROI rasterisers clamp their step to 4; _gradient_get_mask() uses a fixed 8. The interpolator sizes its per-cell weight tables from this, so a caller wanting a coarser grid must raise it here rather than locally.

Definition at line 270 of file masks_functions.h.

◆ DT_MASKS_OUTLINE_TILT_MAX

#define DT_MASKS_OUTLINE_TILT_MAX   1.0f

How far off the normal a border sample may tilt, as the sine of the angle: the rate of the radius along the spine, |dr/ds|, up to which the envelope is followed. At 1 the discs nest and there is no envelope beyond it, so this is the exact envelope and the clamp only keeps the square root real. A first version capped it at 0.7 to keep the spokes painted from the samples reaching across the stroke, on the argument that a family tilted further leans too far along the spine to paint the width. Measured, the raster oracle reports no missing pixel anywhere in the corpus at the exact envelope, while the cap left a real hole: a segment whose rate peaks near 1 – a brush flaring from a 132 px node to a 342 px one over 287 px – has its union's top on the rear envelope of the flare, 40 px outside the wide node's circle at a tilt of 64 degrees, and no sample reached it, so the outline lost the whole top of the shape.

Definition at line 192 of file masks_functions.h.

Typedef Documentation

◆ dt_masks_functions_t

structure used to store pointers to the functions implementing operations on a mask shape plus a few per-class descriptive data items

◆ dt_masks_sample_grid_t

One rectangular lattice of sample points over a rasterisation ROI.

Every shape whose mask is evaluated on a coarse grid and then interpolated back up describes that grid the same way: a cell count, a spacing in output pixels, the ROI origin, and the inverse of the ROI scale. x0/y0 are the index of the first cell – non-zero for the shapes that grid only their own bounding box (circle, ellipse), zero for the ones that grid the whole ROI (gradient).

Function Documentation

◆ _check_id()

void _check_id ( dt_develop_t *  dev,
dt_masks_form_t *  mask_form 
)

Definition at line 125 of file masks.c.

References dt_develop_t::forms, and L.

Referenced by _group_create(), dt_masks_form_duplicate(), and dt_masks_gui_form_save_creation().

◆ _find_in_group()

int _find_in_group ( dt_develop_t *  dev,
dt_masks_form_t *  group_form,
int  form_id 
)

◆ _group_create()

◆ _group_from_module()

◆ _set_group_name_from_module()

void _set_group_name_from_module ( dt_iop_module_t *  module,
dt_masks_form_t *  group_form 
)

Definition at line 161 of file masks.c.

References dt_free, dt_masks_group_name_for_module(), IS_NULL_PTR, and L.

Referenced by _group_create().

◆ dt_masks_form_gui_points_free()

void dt_masks_form_gui_points_free ( gpointer  data)

◆ dt_masks_get_mask_roi()

◆ dt_masks_get_points_border()

dt_masks_raster_result_t dt_masks_get_points_border ( struct dt_develop_t *  dev,
dt_masks_form_t *  form,
float **  points,
int *  points_count,
float **  border,
int *  border_count,
dt_masks_skip_range_t **  border_skips,
int *  border_skip_count,
int  source,
dt_iop_module_t *  module 
)

◆ dt_masks_group_entry_apply_operation()

void dt_masks_group_entry_apply_operation ( struct dt_masks_form_group_t *  group_entry,
const dt_masks_state_t  apply_state 
)

Apply a mask state operation on a group entry.

Inverse toggles its flag, combine operations replace the combine bits.

Definition at line 5795 of file masks_gui.c.

References DT_MASKS_STATE_INVERSE, DT_MASKS_STATE_IS_COMBINE_OP, IS_NULL_PTR, and L.

Referenced by _masks_operation_callback().

◆ dt_masks_outline_boundary_skips()

int dt_masks_outline_boundary_skips ( const float *const  points,
const float *const  border,
const int  count,
const int  header,
dt_masks_skip_range_t **  skips_out 
)

The boundary of a shape's outline: which border samples are not strictly inside any other sample's disc, published as the skip ranges every consumer of the outline already reads. points and border are the index-aligned centreline and border arrays, header the per-node header triplets both carry. See masks_outline.c.

Definition at line 735 of file masks_outline.c.

References _outline_boundary_alloc(), _outline_boundary_free(), _outline_cells_build(), _outline_discs_from_outline(), _outline_grid_build(), _outline_keep_specks(), _outline_probe_samples(), _outline_skips_from_dropped(), bbox, dt_alloc_align(), DT_DEBUG_MASKS, DT_DEBUG_PERF, dt_free_align, dt_get_debug_flags(), dt_get_wtime(), dt_print(), i, IS_NULL_PTR, L, and n.

Referenced by _brush_get_points_border(), and _polygon_get_points_border().

◆ dt_masks_outline_envelope_offset()

void dt_masks_outline_envelope_offset ( const float *  centre,
float  dx,
float  dy,
float  radius,
float  radius_rate,
float *  out 
)

Place the border sample of a disc of radius centred at centre, when the disc belongs to a family whose centre moves along the tangent (dx, dy) – any length, the derivative of the spine by its parameter – and whose radius changes by radius_rate per unit of that same parameter.

A border sample on the NORMAL of its spine sample is on the boundary of the union only while the radius is constant. Where the radius grows or shrinks along the spine the boundary is the envelope of the discs, c + r * (-r' T + sqrt(1 - r'^2) N) with r' = dr/ds, tilted off the normal by asin(r'); the normal sample sits inside the union by about r'^2 r / 2 – a fraction of a pixel at the rates a pen draws, invisible to the eye and exactly what the boundary detector rejects, so the outline of a stroke whose radius varied lost whole stretches of both sides (a 37% skipped border on the #1313 corpus brush, most of it along the sides). The tilt is capped at DT_MASKS_OUTLINE_TILT_MAX. The normal is (dy, -dx), the side every border in this module offsets to.

Definition at line 62 of file masks_outline.c.

References DT_MASKS_OUTLINE_TILT_MAX, L, and out.

Referenced by _brush_border_get_XY(), and _polygon_border_get_XY().

◆ dt_masks_outline_offset_along()

void dt_masks_outline_offset_along ( const float *const  centre,
float  dx,
float  dy,
const float  radius,
float *const  border 
)

A border sample at radius from centre in the direction (dx, dy); (1, 0) if none.

Definition at line 44 of file masks_outline.c.

References L.

Referenced by _brush_leaf_borrow_border(), _brush_walk_segment(), _polygon_points_recurs(), and _polygon_walk_segment().

◆ dt_masks_outline_short_way()

gboolean dt_masks_outline_short_way ( const float *const  centre,
const float *const  from,
const float *const  to,
const gboolean  default_clockwise 
)

Which way round a joint arc from from to to about centre goes: the short way, or default_clockwise on a tie.

Definition at line 95 of file masks_outline.c.

References FALSE, L, M_PI, and TRUE.

Referenced by _brush_joint_arc(), and _polygon_joint_arc().

◆ dt_masks_point_in_form_exact()

int dt_masks_point_in_form_exact ( const float *  test_points,
int  test_point_count,
const float *  form_points,
int  form_points_start,
int  form_points_count,
const dt_masks_skip_range_t *  skips,
int  skip_count 
)

Ray-cast point-in-polygon over a form point stream, honouring skip ranges.

Walks [points_start, points_count) forward, wrapping to points_start exactly once. A skip range closes the contour with a chord from the point before jump_from to resume_at. A range that does not move the walk strictly forward is IGNORED AND REPORTED rather than followed: a backward jump would re-walk the span just left and spin until the visit cap – the silent-garbage mode both historical bugs of the in-band encoding shipped as.

Parameters
skipsmay be NULL (with skip_count 0): no cuts, the common case for every shape but polygon and for path (non-border) walks.
Returns
Index of the first tested point found inside the form, -1 otherwise.

Ray-cast point-in-polygon over a form point stream, honouring skip ranges.

We use the ray casting algorithm for each tested point.

Parameters
ptsFlat array of tested points [x0, y0, x1, y1, ...].
num_ptsNumber of tested points in pts.
pointsThe array of form vertices.
points_startThe starting index of the form vertices in the array.
points_countThe total number of vertices in the form.
Returns
int Index of the first tested point found inside the form, -1 otherwise.

Definition at line 5403 of file masks_gui.c.

References DT_DEBUG_ALWAYS, dt_print(), FALSE, i, IS_NULL_PTR, L, and TRUE.

Referenced by _circle_get_distance(), _ellipse_get_distance(), _polygon_get_distance(), and dt_masks_draw_source().

◆ dt_masks_points_bounding_box()

void dt_masks_points_bounding_box ( const float *const  points,
const int  num_points,
int *  width,
int *  height,
int *  posx,
int *  posy 
)

Axis-aligned bounding box of an outline, in the outline's own coordinates.

points is the interleaved x/y array a shape's get_points_border produced, and point 0 is SKIPPED: every shape that uses this stores its centre there, not a point on the outline.

Definition at line 322 of file masks.c.

References height, i, L, and width.

Referenced by _circle_get_area(), _circle_get_source_area(), _ellipse_get_area(), and _ellipse_get_source_area().

◆ dt_masks_points_shift_to_source()

int dt_masks_points_shift_to_source ( struct dt_develop_t *  dev,
const struct dt_iop_module_t *  module,
float **  points,
int *  points_count,
const float  xs,
const float  ys,
const int  first_shifted 
)

Turn an outline of a shape into the outline of its clone source, in final image reference.

*points arrives as the TARGET outline in RAW reference and leaves as the SOURCE outline with every distortion applied. first_shifted is the index the outline proper begins at: shapes that keep handle points in their header pass the index past them and get their centre written directly, shapes whose point 0 is the centre and nothing else pass 0 and have it shifted with the rest. On failure the buffer is freed and *points/*points_count are cleared.

Returns 0 on success, 1 on failure.

Referenced by _circle_get_points_source(), and _ellipse_get_points_source().

◆ dt_masks_preview_add_clone_source()

int dt_masks_preview_add_clone_source ( struct dt_masks_form_gui_t *  gui,
struct dt_masks_preview_buffers_t *  preview 
)

Give a creation preview its clone-source outline: the target outline, offset by the drag.

Allocates preview->source_points from preview->points, which must already be populated. Returns 0 on success, 1 on allocation failure – the caller's own error convention.

Definition at line 6083 of file masks_gui.c.

References dt_masks_calculate_source_pos_origin(), dt_pixelpipe_cache_alloc_align_float_cache, FALSE, i, IS_NULL_PTR, L, dt_masks_form_gui_t::pos, and preview.

Referenced by _circle_get_creation_preview(), and _ellipse_get_creation_preview().

◆ dt_masks_sample_grid_backtransform()

◆ dt_masks_sample_grid_interpolate()

void dt_masks_sample_grid_interpolate ( const float *const  points,
const dt_masks_sample_grid_t *const  grid,
float *const  buffer,
const int  buf_width,
const int  buf_height,
int *const  endx,
int *const  endy 
)

Bilinear expansion of a coarse grid of mask values back to full ROI resolution.

points is the buffer dt_masks_sample_grid_backtransform() returned, with each cell's mask value written over its x coordinate (that is, at points[index * 2]) – every shape evaluates in place like that, so the interpolator reads the same stride whatever the shape.

Writes into buffer over the rectangle the grid covers, clipped to the buffer, and reports the exclusive end of that rectangle through endx/endy for callers that go on to mark the touched box.

Definition at line 393 of file masks.c.

References __OMP_PARALLEL_FOR__, DT_MASKS_GRID_MAX_STEP, dt_masks_sample_grid_t::height, i, L, MIN, row, dt_masks_sample_grid_t::step, w1, dt_masks_sample_grid_t::width, dt_masks_sample_grid_t::x0, and dt_masks_sample_grid_t::y0.

Referenced by _circle_get_mask_roi(), _ellipse_get_mask_roi(), _gradient_get_mask(), and _gradient_get_mask_roi().

◆ dt_masks_skip_contains()

gboolean dt_masks_skip_contains ( const dt_masks_skip_range_t *  skips,
const int  skip_count,
const int  index 
)

Is index inside one of the excluded spans? For a consumer that SEARCHES the outline rather than walking it; a forward walk should use dt_masks_draw_outline_runs() instead.

Is index inside one of the excluded spans? For a consumer that SEARCHES the outline rather than walking it forward – a forward walk should use dt_masks_draw_outline_runs() or carry its own cursor. skips must be sorted and disjoint.

Definition at line 306 of file masks.c.

References FALSE, IS_NULL_PTR, L, and TRUE.

Referenced by _brush_get_border_handle_resampled(), and _outline_band_check().

Variable Documentation

◆ dt_masks_functions_brush

◆ dt_masks_functions_circle

const dt_masks_functions_t dt_masks_functions_circle
extern

the shape-specific function tables

Definition at line 1078 of file circle.c.

Referenced by _circle_events_post_expose(), dt_masks_create(), and main().

◆ dt_masks_functions_ellipse

const dt_masks_functions_t dt_masks_functions_ellipse
extern

Definition at line 1643 of file ellipse.c.

Referenced by _ellipse_events_post_expose(), dt_masks_create(), and main().

◆ dt_masks_functions_gradient

const dt_masks_functions_t dt_masks_functions_gradient
extern

Definition at line 1470 of file gradient.c.

Referenced by _gradient_events_post_expose(), dt_masks_create(), and main().

◆ dt_masks_functions_group

const dt_masks_functions_t dt_masks_functions_group
extern

Definition at line 1045 of file group.c.

Referenced by _write_fixture_init(), and dt_masks_create().

◆ dt_masks_functions_polygon

const dt_masks_functions_t dt_masks_functions_polygon
extern