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
46
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
70
74{
75 int point_struct_size; // sizeof(struct dt_masks_point_*_t)
77 void (*set_form_name)(struct dt_masks_form_t *const form, const size_t nb);
78 void (*set_hint_message)(const struct dt_masks_form_gui_t *const gui, const struct dt_masks_form_t *const form,
79 char *const __restrict__ msgbuf, const size_t msgbuf_len);
80 void (*duplicate_points)(struct dt_develop_t *const dev, struct dt_masks_form_t *base, struct dt_masks_form_t *dest);
81 void (*initial_source_pos)(struct dt_develop_t *dev, const float iwd, const float iht, float *x, float *y);
82 // input coordinates are in absolute output-image space, dist is squared in the same space
83 void (*get_distance)(float x, float y, float as, struct dt_masks_form_gui_t *gui, int index, int num_points,
84 int *inside, int *inside_border, int *near_handle, int *inside_source, float *dist);
85 int (*get_points)(struct dt_develop_t *dev, float x, float y, float radius_a, float radius_b, float rotation,
86 float **points, int *points_count);
103 dt_masks_raster_result_t (*get_points_border)(struct dt_develop_t *dev, struct dt_masks_form_t *form,
104 const dt_masks_outline_out_t *const out, int source,
105 const dt_iop_module_t *const module);
110 const dt_dev_pixelpipe_iop_t *const piece,
111 struct dt_masks_form_t *const form,
112 float **buffer, int *width, int *height, int *posx, int *posy);
125 const dt_dev_pixelpipe_iop_t *const piece,
126 struct dt_masks_form_t *const form,
127 const dt_iop_roi_t *roi, float *buffer, dt_iop_roi_t *touched);
130 const dt_dev_pixelpipe_iop_t *const piece,
131 struct dt_masks_form_t *const form,
132 int *width, int *height, int *posx, int *posy);
135 const dt_dev_pixelpipe_iop_t *piece, struct dt_masks_form_t *form,
136 int *width, int *height, int *posx, int *posy);
137 gboolean (*get_gravity_center)(struct dt_develop_t *dev, const struct dt_masks_form_t *form, float center[2], float *area);
138 float (*get_interaction_value)(const struct dt_masks_form_t *form, dt_masks_interaction_t interaction);
139 float (*set_interaction_value)(struct dt_masks_form_t *form, dt_masks_interaction_t interaction, float value,
140 dt_masks_increment_t increment, int flow,
141 struct dt_masks_form_gui_t *gui, struct dt_iop_module_t *module);
142 /* Recompute hovered handles/nodes from the cached cursor state in gui. */
143 int (*update_hover)(struct dt_masks_form_t *form, struct dt_masks_form_gui_t *gui, int index);
144 /* Mouse x and y are widget-space coordinates from GTK/Cairo */
145 int (*mouse_moved)(struct dt_iop_module_t *module, double x, double y, double pressure, int which,
146 struct dt_masks_form_t *form, int parentid, struct dt_masks_form_gui_t *gui, int index);
147 /* Mouse x and y are widget-space coordinates from GTK/Cairo */
148 int (*mouse_scrolled)(struct dt_iop_module_t *module, double x, double y, int up, const int delta_y, uint32_t state,
149 struct dt_masks_form_t *form, int parentid, struct dt_masks_form_gui_t *gui, int index,
150 dt_masks_interaction_t interaction);
151 /* Mouse x and y are widget-space coordinates from GTK/Cairo */
152 int (*button_pressed)(struct dt_iop_module_t *module, double x, double y,
153 double pressure, int which, int type, uint32_t state,
154 struct dt_masks_form_t *form, int parentid, struct dt_masks_form_gui_t *gui, int index);
155 /* Mouse x and y are widget-space coordinates from GTK/Cairo */
156 int (*button_released)(struct dt_iop_module_t *module, double x, double y, int which, uint32_t state,
157 struct dt_masks_form_t *form, int parentid, struct dt_masks_form_gui_t *gui, int index);
158 /* Key event */
159 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);
160 void (*post_expose)(cairo_t *cr, float zoom_scale, const struct dt_masks_form_t *form,
161 struct dt_masks_form_gui_t *gui, int index, int num_points);
162 // The function to draw the shape in question. Signature must match shape_draw_function_t.
166 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);
168
169/* Rasterisation entry points, dispatched only from inside the masks module: the group fold
170 * calls get_mask_roi on its children, and the GUI outline builder calls get_points_border.
171 * They were declared in the public header with no caller outside this directory. */
173 const dt_dev_pixelpipe_iop_t *const piece,
174 dt_masks_form_t *const form, const dt_iop_roi_t *roi,
175 float *buffer, dt_iop_roi_t *touched);
176
177/* The outline is sampled at the density the dev's GUI shows -- dt_masks_gui_outline_step(),
178 * read by dt_masks_distort_for_gui() -- so that it is built at the density it is drawn and
179 * hit-tested at. The brush and the polygon sample their curves, arcs and stamps at it; the
180 * circle, the ellipse and the gradient have their own sampling. */
182 const dt_masks_outline_out_t *const out, int source,
183 dt_iop_module_t *module);
184
189int dt_masks_outline_boundary_skips(const float *const points, const float *const border, const int count,
190 const int header, dt_masks_skip_range_t **skips_out);
193gboolean dt_masks_outline_short_way(const float *const centre, const float *const from, const float *const to,
194 const gboolean default_clockwise);
196void dt_masks_outline_offset_along(const float *const centre, float dx, float dy, const float radius,
197 float *const border);
198
209#define DT_MASKS_OUTLINE_TILT_MAX 1.0f
210
225void dt_masks_outline_envelope_offset(const float *centre, float dx, float dy, float radius, float radius_rate,
226 float *out);
227
228
231gboolean dt_masks_skip_contains(const dt_masks_skip_range_t *skips, const int skip_count, const int index);
232
233
242{
243 int x0, y0; // index of the first cell, in cells
244 int width, height; // number of cells
245 int step; // cell spacing, in output pixels
246 int px, py; // ROI origin, in output pixels
247 float iscale; // 1.0f / roi->scale
249
254void dt_masks_points_bounding_box(const float *const points, const int num_points,
255 int *width, int *height, int *posx, int *posy);
256
258 const dt_masks_sample_grid_t *const grid,
259 const char *const shape, const char *const form_name);
260
261
268
279 float **points, int *points_count,
280 const float xs, const float ys, const int first_shifted);
281
287#define DT_MASKS_GRID_MAX_STEP 8
288
298void dt_masks_sample_grid_interpolate(const float *const points, const dt_masks_sample_grid_t *const grid,
299 float *const buffer, const int buf_width, const int buf_height,
300 int *const endx, int *const endy);
314int dt_masks_point_in_form_exact(const float *pts, int num_pts, const float *points,
315 int points_start, int points_count,
316 const dt_masks_skip_range_t *skips, int skip_count);
317
318/* The raw membership-state mutator. Module-private on purpose: it takes a row by pointer and
319 * cannot touch the group, so every external caller had to remember the copy-on-write dance and
320 * most did not. Outside code goes through dt_masks_group_set_member_operation(), which owns it. */
322 const dt_masks_state_t apply_state);
323
331
333
334
335/* Shared between masks.c (data/persistence) and masks_gui.c (interaction) since the
336 * GUI half moved out; internal to the masks subsystem like everything here. */
338void _check_id(dt_develop_t *dev, dt_masks_form_t *mask_form);
342int _find_in_group(dt_develop_t *dev, dt_masks_form_t *group_form, int form_id);
343
344#ifdef __cplusplus
345}
346#endif
347
348#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))
const dt_masks_functions_t dt_masks_functions_circle
Definition circle.c:1077
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
dt_atomic_set_uint64 & dev
dev roi_request value
const dt_masks_functions_t dt_masks_functions_brush
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
const dt_masks_functions_t dt_masks_functions_ellipse
Definition ellipse.c:1643
double iop_order
Definition geometry.h:102
void * data
Definition geometry.h:111
const dt_masks_functions_t dt_masks_functions_gradient
Definition gradient.c:1470
const dt_masks_functions_t dt_masks_functions_group
Definition group.c:1046
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:5446
dt_masks_form_t * _group_create(dt_develop_t *develop, dt_iop_module_t *module, dt_masks_type_t group_type)
Definition masks.c:172
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:344
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 _check_id(dt_develop_t *dev, dt_masks_form_t *mask_form)
Definition masks.c:127
dt_masks_raster_result_t dt_masks_get_points_border(struct dt_develop_t *dev, dt_masks_form_t *form, const dt_masks_outline_out_t *const out, int source, dt_iop_module_t *module)
Definition masks.c:240
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:6126
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)
const dt_masks_functions_t dt_masks_functions_polygon
Definition polygon.c:3628
int _find_in_group(dt_develop_t *dev, dt_masks_form_t *group_form, int form_id)
Definition masks.c:1404
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:1660
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:321
void _set_group_name_from_module(dt_iop_module_t *module, dt_masks_form_t *group_form)
Definition masks.c:163
dt_masks_form_t * _group_from_module(dt_develop_t *develop, dt_iop_module_t *module)
Definition masks.c:183
gboolean dt_masks_skip_contains(const dt_masks_skip_range_t *skips, const int skip_count, const int index)
Definition masks.c:305
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:5838
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:392
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
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
const float uint32_t state[4]
Region of interest passed through the pixelpipe.
Definition format.h:49
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)
void(* post_expose)(cairo_t *cr, float zoom_scale, const struct dt_masks_form_t *form, struct dt_masks_form_gui_t *gui, int index, int num_points)
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)
shape_draw_function_t draw_shape
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)
dt_masks_skip_range_t ** border_skips
One cut in a shape's border outline: while walking the border buffer forward, on reaching index jump_...