Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
masks_functions.h
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2013-2014, 2016, 2019, 2021 Aldric Renaudin.
4 Copyright (C) 2013, 2018, 2020-2021 Pascal Obry.
5 Copyright (C) 2013 Simon Spannagel.
6 Copyright (C) 2013-2014, 2016-2018 Tobias Ellinghaus.
7 Copyright (C) 2013-2017, 2019-2020 Ulrich Pegelow.
8 Copyright (C) 2014-2016 Roman Lebedev.
9 Copyright (C) 2017-2019 Edgardo Hoszowski.
10 Copyright (C) 2021 Hanno Schwalm.
11 Copyright (C) 2021 Hubert Kowalski.
12 Copyright (C) 2021 luzpaz.
13 Copyright (C) 2021 Philipp Lutz.
14 Copyright (C) 2021 Ralf Brown.
15 Copyright (C) 2022 Martin Bařinka.
16 Copyright (C) 2023, 2025-2026 Aurélien PIERRE.
17 Copyright (C) 2023 Luca Zulberti.
18 Copyright (C) 2025 Alynx Zhou.
19 Copyright (C) 2025-2026 Guillaume Stutin.
20
21 darktable is free software: you can redistribute it and/or modify
22 it under the terms of the GNU General Public License as published by
23 the Free Software Foundation, either version 3 of the License, or
24 (at your option) any later version.
25
26 darktable is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 GNU General Public License for more details.
30
31 You should have received a copy of the GNU General Public License
32 along with darktable. If not, see <http://www.gnu.org/licenses/>.
33*/
34
47#ifndef DT_DEVELOP_MASKS_MASKS_FUNCTIONS_H
48#define DT_DEVELOP_MASKS_MASKS_FUNCTIONS_H
49
50#include "develop/masks.h"
51#include "develop/masks_gui.h"
52
53#ifdef __cplusplus
54extern "C" {
55#endif
56
57
61{
62 int point_struct_size; // sizeof(struct dt_masks_point_*_t)
64 void (*set_form_name)(struct dt_masks_form_t *const form, const size_t nb);
65 void (*set_hint_message)(const struct dt_masks_form_gui_t *const gui, const struct dt_masks_form_t *const form,
66 char *const __restrict__ msgbuf, const size_t msgbuf_len);
67 void (*duplicate_points)(struct dt_develop_t *const dev, struct dt_masks_form_t *base, struct dt_masks_form_t *dest);
68 void (*initial_source_pos)(struct dt_develop_t *dev, const float iwd, const float iht, float *x, float *y);
69 // input coordinates are in absolute output-image space, dist is squared in the same space
70 void (*get_distance)(float x, float y, float as, struct dt_masks_form_gui_t *gui, int index, int num_points,
71 int *inside, int *inside_border, int *near_handle, int *inside_source, float *dist);
72 int (*get_points)(struct dt_develop_t *dev, float x, float y, float radius_a, float radius_b, float rotation,
73 float **points, int *points_count);
84 float **points, int *points_count,
85 float **border, int *border_count,
86 dt_masks_skip_range_t **border_skips, int *border_skip_count,
87 int source, const dt_iop_module_t *const module);
92 const dt_dev_pixelpipe_iop_t *const piece,
93 struct dt_masks_form_t *const form,
94 float **buffer, int *width, int *height, int *posx, int *posy);
107 const dt_dev_pixelpipe_iop_t *const piece,
108 struct dt_masks_form_t *const form,
109 const dt_iop_roi_t *roi, float *buffer, dt_iop_roi_t *touched);
112 const dt_dev_pixelpipe_iop_t *const piece,
113 struct dt_masks_form_t *const form,
114 int *width, int *height, int *posx, int *posy);
117 const dt_dev_pixelpipe_iop_t *piece, struct dt_masks_form_t *form,
118 int *width, int *height, int *posx, int *posy);
119 gboolean (*get_gravity_center)(struct dt_develop_t *dev, const struct dt_masks_form_t *form, float center[2], float *area);
120 float (*get_interaction_value)(const struct dt_masks_form_t *form, dt_masks_interaction_t interaction);
121 float (*set_interaction_value)(struct dt_masks_form_t *form, dt_masks_interaction_t interaction, float value,
122 dt_masks_increment_t increment, int flow,
123 struct dt_masks_form_gui_t *gui, struct dt_iop_module_t *module);
124 /* Recompute hovered handles/nodes from the cached cursor state in gui. */
125 int (*update_hover)(struct dt_masks_form_t *form, struct dt_masks_form_gui_t *gui, int index);
126 /* Mouse x and y are widget-space coordinates from GTK/Cairo */
127 int (*mouse_moved)(struct dt_iop_module_t *module, double x, double y, double pressure, int which,
128 struct dt_masks_form_t *form, int parentid, struct dt_masks_form_gui_t *gui, int index);
129 /* Mouse x and y are widget-space coordinates from GTK/Cairo */
130 int (*mouse_scrolled)(struct dt_iop_module_t *module, double x, double y, int up, const int delta_y, uint32_t state,
131 struct dt_masks_form_t *form, int parentid, struct dt_masks_form_gui_t *gui, int index,
132 dt_masks_interaction_t interaction);
133 /* Mouse x and y are widget-space coordinates from GTK/Cairo */
134 int (*button_pressed)(struct dt_iop_module_t *module, double x, double y,
135 double pressure, int which, int type, uint32_t state,
136 struct dt_masks_form_t *form, int parentid, struct dt_masks_form_gui_t *gui, int index);
137 /* Mouse x and y are widget-space coordinates from GTK/Cairo */
138 int (*button_released)(struct dt_iop_module_t *module, double x, double y, int which, uint32_t state,
139 struct dt_masks_form_t *form, int parentid, struct dt_masks_form_gui_t *gui, int index);
140 /* Key event */
141 int (*key_pressed)(struct dt_iop_module_t *module, GdkEventKey *event, struct dt_masks_form_t *form, int parentid, struct dt_masks_form_gui_t *gui, int index);
142 void (*post_expose)(cairo_t *cr, float zoom_scale, struct dt_masks_form_gui_t *gui, int index, int num_points);
143 // The function to draw the shape in question. Signature must match shape_draw_function_t.
147 int (*populate_context_menu)(GtkWidget *menu, struct dt_masks_form_t *form, struct dt_masks_form_gui_t *gui, const float pzx, const float pzy);
149
150/* Rasterisation entry points, dispatched only from inside the masks module: the group fold
151 * calls get_mask_roi on its children, and the GUI outline builder calls get_points_border.
152 * They were declared in the public header with no caller outside this directory. */
154 const dt_dev_pixelpipe_iop_t *const piece,
155 dt_masks_form_t *const form, const dt_iop_roi_t *roi,
156 float *buffer, dt_iop_roi_t *touched);
157
158/* The outline is sampled at the density the dev's GUI shows -- dt_masks_gui_outline_step(),
159 * read by dt_masks_distort_for_gui() -- so that it is built at the density it is drawn and
160 * hit-tested at. The brush and the polygon sample their curves, arcs and stamps at it; the
161 * circle, the ellipse and the gradient have their own sampling. */
163 float **points, int *points_count,
164 float **border, int *border_count,
165 dt_masks_skip_range_t **border_skips, int *border_skip_count,
166 int source, dt_iop_module_t *module);
167
172int dt_masks_outline_boundary_skips(const float *const points, const float *const border, const int count,
173 const int header, dt_masks_skip_range_t **skips_out);
176gboolean dt_masks_outline_short_way(const float *const centre, const float *const from, const float *const to,
177 const gboolean default_clockwise);
179void dt_masks_outline_offset_along(const float *const centre, float dx, float dy, const float radius,
180 float *const border);
181
192#define DT_MASKS_OUTLINE_TILT_MAX 1.0f
193
208void dt_masks_outline_envelope_offset(const float *centre, float dx, float dy, float radius, float radius_rate,
209 float *out);
210
211
214gboolean dt_masks_skip_contains(const dt_masks_skip_range_t *skips, const int skip_count, const int index);
215
216
225{
226 int x0, y0; // index of the first cell, in cells
227 int width, height; // number of cells
228 int step; // cell spacing, in output pixels
229 int px, py; // ROI origin, in output pixels
230 float iscale; // 1.0f / roi->scale
232
237void dt_masks_points_bounding_box(const float *const points, const int num_points,
238 int *width, int *height, int *posx, int *posy);
239
240float *dt_masks_sample_grid_backtransform(const struct dt_dev_pixelpipe_t *pipe, const double iop_order,
241 const dt_masks_sample_grid_t *const grid,
242 const char *const shape, const char *const form_name);
243
244
251
262 float **points, int *points_count,
263 const float xs, const float ys, const int first_shifted);
264
270#define DT_MASKS_GRID_MAX_STEP 8
271
281void dt_masks_sample_grid_interpolate(const float *const points, const dt_masks_sample_grid_t *const grid,
282 float *const buffer, const int buf_width, const int buf_height,
283 int *const endx, int *const endy);
297int dt_masks_point_in_form_exact(const float *pts, int num_pts, const float *points,
298 int points_start, int points_count,
300
301/* The raw membership-state mutator. Module-private on purpose: it takes a row by pointer and
302 * cannot touch the group, so every external caller had to remember the copy-on-write dance and
303 * most did not. Outside code goes through dt_masks_group_set_member_operation(), which owns it. */
306
314
318/* Shared between masks.c (data/persistence) and masks_gui.c (interaction) since the
319 * GUI half moved out; internal to the masks subsystem like everything here. */
320void dt_masks_form_gui_points_free(gpointer data);
326
327#ifdef __cplusplus
328}
329#endif
330
331#endif // DT_DEVELOP_MASKS_MASKS_FUNCTIONS_H
static double dist(double x1, double y1, double x2, double y2)
Definition ashift_lsd.c:250
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
static const float x
struct _GtkWidget GtkWidget
GtkWidget, opaque, spelled exactly as GTK spells it.
Definition colorspaces.h:98
const dt_colormatrix_t dt_aligned_pixel_t out
GtkWidget * preview
what the selected row actually captures
void(* shape_draw_function_t)(struct dt_develop_t *dev, cairo_t *cr, const float *points, const int points_count, const int nb, const gboolean border, const gboolean source, const struct dt_masks_skip_range_t *skips, const int skip_count)
Definition draw.h:815
static const dt_dev_pixelpipe_t * pipe
Definition layers.h:49
static const dt_dev_pixelpipe_t const dt_dev_pixelpipe_iop_t * piece
Definition layers.h:50
_lib_location_type_t type
Definition location.c:1
dt_masks_raster_result_t
What a rasterisation attempt produced.
Definition masks.h:313
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.
Definition masks_gui.c:5403
dt_masks_form_t * _group_create(dt_develop_t *develop, dt_iop_module_t *module, dt_masks_type_t group_type)
Definition masks.c:170
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)
Definition masks.c:345
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)
const dt_masks_functions_t dt_masks_functions_group
Definition group.c:1045
void _check_id(dt_develop_t *dev, dt_masks_form_t *mask_form)
Definition masks.c:125
int dt_masks_preview_add_clone_source(struct dt_masks_form_gui_t *gui, struct dt_masks_preview_buffers_t *preview)
Definition masks_gui.c:6083
void dt_masks_outline_envelope_offset(const float *centre, float dx, float dy, float radius, float radius_rate, float *out)
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)
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)
Definition masks.c:238
const dt_masks_functions_t dt_masks_functions_polygon
Definition polygon.c:3630
int _find_in_group(dt_develop_t *dev, dt_masks_form_t *group_form, int form_id)
Definition masks.c:1405
const dt_masks_functions_t dt_masks_functions_ellipse
Definition ellipse.c:1643
const dt_masks_functions_t dt_masks_functions_circle
Definition circle.c:1078
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)
Definition masks.c:1661
void dt_masks_points_bounding_box(const float *const points, const int num_points, int *width, int *height, int *posx, int *posy)
Definition masks.c:322
void _set_group_name_from_module(dt_iop_module_t *module, dt_masks_form_t *group_form)
Definition masks.c:161
dt_masks_form_t * _group_from_module(dt_develop_t *develop, dt_iop_module_t *module)
Definition masks.c:181
gboolean dt_masks_skip_contains(const dt_masks_skip_range_t *skips, const int skip_count, const int index)
Definition masks.c:306
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.
Definition masks_gui.c:5795
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)
Definition masks.c:393
const dt_masks_functions_t dt_masks_functions_brush
void dt_masks_outline_offset_along(const float *const centre, float dx, float dy, const float radius, float *const border)
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_form_gui_points_free(gpointer data)
Definition masks.c:112
const dt_masks_functions_t dt_masks_functions_gradient
Definition gradient.c:1470
The interactive half of the masks subsystem: the editing state (dt_masks_form_gui_t),...
dt_masks_state_t
Definition masks_types.h:87
dt_masks_type_t
Definition masks_types.h:62
dt_masks_interaction_t
dt_masks_increment_t
uint32_t width
Definition mipmap_cache.c:0
uint32_t height
Definition mipmap_cache.c:1
static const dt_aligned_pixel_simd_t value
Definition simd.h:144
const float uint32_t state[4]
Region of interest passed through the pixelpipe.
Definition format.h:49
struct dt_develop_t * dev
Definition masks_gui.h:101
float(* get_interaction_value)(const struct dt_masks_form_t *form, dt_masks_interaction_t interaction)
dt_masks_raster_result_t(* get_mask_roi)(const dt_iop_module_t *const fmodule, const struct dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *const piece, struct dt_masks_form_t *const form, const dt_iop_roi_t *roi, float *buffer, dt_iop_roi_t *touched)
int(* button_pressed)(struct dt_iop_module_t *module, double x, double y, double pressure, int which, int type, uint32_t state, struct dt_masks_form_t *form, int parentid, struct dt_masks_form_gui_t *gui, int index)
int(* get_points)(struct dt_develop_t *dev, float x, float y, float radius_a, float radius_b, float rotation, float **points, int *points_count)
void(* initial_source_pos)(struct dt_develop_t *dev, const float iwd, const float iht, float *x, float *y)
int(* button_released)(struct dt_iop_module_t *module, double x, double y, int which, uint32_t state, struct dt_masks_form_t *form, int parentid, struct dt_masks_form_gui_t *gui, int index)
int(* key_pressed)(struct dt_iop_module_t *module, GdkEventKey *event, struct dt_masks_form_t *form, int parentid, struct dt_masks_form_gui_t *gui, int index)
int(* mouse_moved)(struct dt_iop_module_t *module, double x, double y, double pressure, int which, struct dt_masks_form_t *form, int parentid, struct dt_masks_form_gui_t *gui, int index)
void(* sanitize_config)(dt_masks_type_t type_flags)
void(* set_form_name)(struct dt_masks_form_t *const form, const size_t nb)
void(* duplicate_points)(struct dt_develop_t *const dev, struct dt_masks_form_t *base, struct dt_masks_form_t *dest)
int(* populate_context_menu)(GtkWidget *menu, struct dt_masks_form_t *form, struct dt_masks_form_gui_t *gui, const float pzx, const float pzy)
int(* update_hover)(struct dt_masks_form_t *form, struct dt_masks_form_gui_t *gui, int index)
dt_masks_raster_result_t(* get_mask)(const dt_iop_module_t *const module, const struct dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *const piece, struct dt_masks_form_t *const form, float **buffer, int *width, int *height, int *posx, int *posy)
float(* set_interaction_value)(struct dt_masks_form_t *form, dt_masks_interaction_t interaction, float value, dt_masks_increment_t increment, int flow, struct dt_masks_form_gui_t *gui, struct dt_iop_module_t *module)
dt_masks_raster_result_t(* get_source_area)(const dt_iop_module_t *module, const struct dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, struct dt_masks_form_t *form, int *width, int *height, int *posx, int *posy)
void(* set_hint_message)(const struct dt_masks_form_gui_t *const gui, const struct dt_masks_form_t *const form, char *const __restrict__ msgbuf, const size_t msgbuf_len)
dt_masks_raster_result_t(* get_area)(const dt_iop_module_t *const module, const struct dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *const piece, struct dt_masks_form_t *const form, int *width, int *height, int *posx, int *posy)
int(* mouse_scrolled)(struct dt_iop_module_t *module, double x, double y, int up, const int delta_y, uint32_t state, struct dt_masks_form_t *form, int parentid, struct dt_masks_form_gui_t *gui, int index, dt_masks_interaction_t interaction)
gboolean(* get_gravity_center)(struct dt_develop_t *dev, const struct dt_masks_form_t *form, float center[2], float *area)
void(* post_expose)(cairo_t *cr, float zoom_scale, struct dt_masks_form_gui_t *gui, int index, int num_points)
shape_draw_function_t draw_shape
dt_masks_raster_result_t(* get_points_border)(struct dt_develop_t *dev, struct 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, const dt_iop_module_t *const module)
void(* get_distance)(float x, float y, float as, struct dt_masks_form_gui_t *gui, int index, int num_points, int *inside, int *inside_border, int *near_handle, int *inside_source, float *dist)
void(* init_ctrl_points)(struct dt_masks_form_t *form)
One cut in a shape's border outline: while walking the border buffer forward, on reaching index jump_...