48#define extent_MIN 0.0005f
49#define extent_MAX 1.0f
50#define CURVATURE_MIN -2.0f
51#define CURVATURE_MAX 2.0f
53#define BORDER_MIN 0.00005f
54#define BORDER_MAX 0.5f
64#pragma omp parallel for reduction(min:found) if(count > 1000)
65 for(
int i = 0;
i < count;
i++)
67 if(!isfinite(border[
i * 2]) && !isfinite(border[
i * 2 + 1]))
70 return (found == count) ? -1 : found;
72 for(
int i = 0;
i < count;
i++)
74 if(!isfinite(border[
i * 2]) && !isfinite(border[
i * 2 + 1]))
84 float *closest_x,
float *closest_y,
float *distance_sq)
86 const float seg_dx = x2 - x1;
87 const float seg_dy = y2 - y1;
88 const float seg_length_sq = seg_dx * seg_dx + seg_dy * seg_dy;
90 if(seg_length_sq < 1e-10f)
95 *distance_sq = (px - x1) * (px - x1) + (py - y1) * (py - y1);
100 const float t = fmaxf(0.0f, fminf(1.0f,
101 ((px - x1) * seg_dx + (py - y1) * seg_dy) / seg_length_sq));
103 *closest_x = x1 +
t * seg_dx;
104 *closest_y = y1 +
t * seg_dy;
105 *distance_sq = (px - *closest_x) * (px - *closest_x) + (py - *closest_y) * (py - *closest_y);
110 float *closest_x,
float *closest_y,
float *min_distance_sq)
112 *min_distance_sq = FLT_MAX;
113 *closest_x = *closest_y = 0.0f;
115 if(start_idx >= end_idx - 1)
return;
118 float global_min = FLT_MAX;
119 float global_x = 0.0f, global_y = 0.0f;
123 float local_min = FLT_MAX;
124 float local_x = 0.0f, local_y = 0.0f;
126#pragma omp for nowait
127 for(
int i = start_idx;
i < end_idx - 1;
i++)
129 float seg_closest_x, seg_closest_y, seg_dist_sq;
131 border[
i * 2], border[
i * 2 + 1],
132 border[(
i + 1) * 2], border[(
i + 1) * 2 + 1],
133 &seg_closest_x, &seg_closest_y, &seg_dist_sq);
135 if(seg_dist_sq < local_min)
137 local_min = seg_dist_sq;
138 local_x = seg_closest_x;
139 local_y = seg_closest_y;
143 if(local_min < global_min)
147 if(local_min < global_min)
149 global_min = local_min;
157 *min_distance_sq = global_min;
158 *closest_x = global_x;
159 *closest_y = global_y;
161 for(
int i = start_idx;
i < end_idx - 1;
i++)
163 float seg_closest_x, seg_closest_y, seg_dist_sq;
165 border[
i * 2], border[
i * 2 + 1],
166 border[(
i + 1) * 2], border[(
i + 1) * 2 + 1],
167 &seg_closest_x, &seg_closest_y, &seg_dist_sq);
169 if(seg_dist_sq < *min_distance_sq)
171 *min_distance_sq = seg_dist_sq;
172 *closest_x = seg_closest_x;
173 *closest_y = seg_closest_y;
181 const float gradient_dx = gpt->
points[2] - gpt->
points[0];
182 const float gradient_dy = gpt->
points[3] - gpt->
points[1];
183 return gradient_dx * gradient_dx + gradient_dy * gradient_dy;
199 values->rotation =
dt_conf_get_float(
"plugins/darkroom/masks/gradient/rotation");
200 if(!isfinite(values->rotation)) values->rotation = 0.0f;
208 gradient->
extent = values.extent;
210 gradient->
rotation = values.rotation;
214 float **points,
int *points_count);
216 float curvature,
float **points,
int *points_count);
231 if(!err && values.extent > 0.0f)
233 values.extent, values.curvature, &
preview->border,
239 int num_points,
int *inside,
int *inside_border,
int *near_handle,
240 int *inside_source,
float *
dist)
248 const float sqr_dist_mouse = dist_mouse * dist_mouse;
253 float min_dist = FLT_MAX;
260 if(separator_idx > 0 && separator_idx < gpt->border_count - 1)
265 if(gradient_len_sq > 1e-12f)
268 float closest_x1, closest_y1, dist1_sq;
269 float closest_x2, closest_y2, dist2_sq;
272 &closest_x1, &closest_y1, &dist1_sq);
275 &closest_x2, &closest_y2, &dist2_sq);
278 if(dist1_sq < FLT_MAX && dist2_sq < FLT_MAX)
281 const float to_line1_x = closest_x1 -
x;
282 const float to_line1_y = closest_y1 - y;
283 const float to_line2_x = closest_x2 -
x;
284 const float to_line2_y = closest_y2 - y;
286 const float gradient_dx = gpt->
points[2] - gpt->
points[0];
287 const float gradient_dy = gpt->
points[3] - gpt->
points[1];
290 const float proj1 = to_line1_x * gradient_dx + to_line1_y * gradient_dy;
291 const float proj2 = to_line2_x * gradient_dx + to_line2_y * gradient_dy;
294 const gboolean between_lines = (proj1 * proj2 < 0.0f);
295 if(between_lines) *inside_border = 1;
298 const float min_dist_sq = fminf(dist1_sq, dist2_sq);
299 float handle_radius_sq =
CLAMPF(gradient_len_sq * 0.125f, sqr_dist_mouse, sqr_dist_mouse * 5);
301 if(min_dist_sq <= handle_radius_sq)
313 const float xx = gpt->
points[
i * 2];
314 const float yy = gpt->
points[
i * 2 + 1];
316 const float dx =
x - xx;
317 const float dy = y - yy;
318 const float dd = sqf(dx) + sqf(dy);
320 min_dist = fminf(min_dist, dd);
324 if(dd < sqr_dist_mouse)
333 float *node_x,
float *node_y,
void *user_data)
335 if(node_x) *node_x = NAN;
336 if(node_y) *node_y = NAN;
341 int *inside_border,
int *near_handle,
int *inside_source,
float *
dist,
void *user_data)
344 inside_border, near_handle, inside_source,
dist);
348 int inside_source,
void *user_data)
355 else if(inside_border)
373 increment, flow, _(
"extent: %3.2f%%"), 100.0f);
380 increment, flow, _(
"Curvature: %3.2f%%"), 50.f);
387 increment, flow, _(
"Opacity: %3.2f%%"), 100.f);
394 increment, flow, _(
"Rotation: %3.2f\302\260"), 1.0f);
422 center[0] = gradient->
center[0];
423 center[1] = gradient->
center[1];
486 if(amount > 2.0f && (gradient->
curvature > 2.0f ))
492 if(node_hovered == -1 || node_hovered == 0)
512 int flow_increased = (flow > 1) ? (flow - 1) * 5 : flow;
577 double pressure,
int which,
int type, uint32_t
state,
606 if(
type == GDK_2BUTTON_PRESS)
727 gradient->
center[0] = pts[0];
728 gradient->
center[1] = pts[1];
739 const float origin_point[2] = { gpt->
points[0], gpt->
points[1] };
754 return (isnormal(
x) && isnormal(y) && (
x >= -wd) && (
x <= 2 * wd) && (y >= -ht) && (y <= 2 * ht)) ?
TRUE :
FALSE;
766 float **points,
int *points_count)
772 const float wd =
geometry.raw_width;
773 const float ht =
geometry.raw_height;
774 if(!isfinite(wd) || !isfinite(ht) || wd <= 0.0f || ht <= 0.0f)
return 1;
776 const float scale = dt_fast_hypotf(wd, ht);
777 const float distance = 0.1f * fminf(wd, ht);
779 const float v = (-rotation / 180.0f) *
M_PI;
780 const float cosv = cosf(
v);
781 const float sinv = sinf(
v);
783 const int count = dt_fast_hypotf(wd, ht) + 3;
788 float center[2] = {
x, y };
790 const float center_x = center[0];
791 const float center_y = center[1];
792 (*points)[0] = center_x;
793 (*points)[1] = center_y;
796 const float v1 = (-(rotation - 90.0f) / 180.0f) *
M_PI;
797 const float x1 = center[0] + distance * cosf(v1);
798 const float y1 = center[1] + distance * sinf(v1);
801 const float v2 = (-(rotation + 90.0f) / 180.0f) *
M_PI;
802 const float x2 = center[0] + distance * cosf(v2);
803 const float y2 = center[1] + distance * sinf(v2);
808 size_t c_padded_size;
810 size_t pts_padded_size;
823 const float xstart = fabsf(curvature) > 1.0f ? -sqrtf(1.0f / fabsf(curvature)) : -1.0f;
824 const float xdelta = -2.0f * xstart / (count - 3);
828 for(
int i = 3;
i < count;
i++)
830 const float xi = xstart + (
i - 3) * xdelta;
831 const float yi = curvature * xi * xi;
832 const float xii = (cosv * xi + sinv * yi) * scale;
833 const float yii = (sinv * xi - cosv * yi) * scale;
834 const float xiii = xii + center_x;
835 const float yiii = yii + center_y;
839 if(!(xiii < -wd || xiii > 2 * wd || yiii < -ht || yiii > 2 * ht))
843 tpts[*tcount * 2] = xiii;
844 tpts[*tcount * 2 + 1] = yiii;
850 for(
int thread = 0; thread < nthreads; thread++)
852 const uint32_t tcount = *(uint32_t *)
dt_get_bythread(pts_count, c_padded_size, thread);
853 const float *
const tpts =
dt_get_bythread(pts, pts_padded_size, thread);
856 for(uint32_t
k = 0;
k < tcount && *points_count < count;
k++)
858 (*points)[(*points_count) * 2] = tpts[
k * 2];
859 (*points)[(*points_count) * 2 + 1] = tpts[
k * 2 + 1];
882 for(
int i = 3;
i < count;
i++, (*k)++)
884 dest[(*k) * 2] = src[
i * 2];
885 dest[(*k) * 2 + 1] = src[
i * 2 + 1];
890 float curvature,
float **points,
int *points_count)
898 const float wd =
geometry.raw_width;
899 const float ht =
geometry.raw_height;
900 const float scale = dt_fast_hypotf(wd, ht);
903 const float v1 = (-(rotation - 90.0f) / 180.0f) *
M_PI;
904 const float v2 = (-(rotation + 90.0f) / 180.0f) *
M_PI;
907 float center[2] = {
x, y };
909 float offsets[4] = { center[0] + distance * scale * cosf(v1),
910 center[1] + distance * scale * sinf(v1),
911 center[0] + distance * scale * cosf(v2),
912 center[1] + distance * scale * sinf(v2) };
914 const float x1 = offsets[0];
915 const float y1 = offsets[1];
916 const float x2 = offsets[2];
917 const float y2 = offsets[3];
920 float *points1 = NULL, *points2 = NULL;
921 int points_count1 = 0, points_count2 = 0;
922 const int err1 =
_gradient_get_points(dev, x1, y1, rotation, curvature, &points1, &points_count1);
923 const int err2 =
_gradient_get_points(dev, x2, y2, rotation, curvature, &points2, &points_count2);
926 const gboolean valid1 = (err1 == 0) && points_count1 > 4;
927 const gboolean valid2 = (err2 == 0) && points_count2 > 4;
934 const int total_points = (points_count1 - 3) + (points_count2 - 3) + 1;
938 *points_count = total_points;
942 (*points)[
k * 2] = (*points)[
k * 2 + 1] = INFINITY;
950 *points_count = points_count1 - 3;
961 *points_count = points_count2 - 3;
976static void _gradient_draw_shape(
struct dt_develop_t *dev, cairo_t *cr,
const float *pts_line,
const int pts_line_count,
const int nb,
const gboolean border,
const gboolean source,
984 if(border && pts_line_count <= 3)
return;
985 if(!border && pts_line_count <= 4)
return;
987 const float *points = (border) ? pts_line : pts_line + 6;
988 const int points_count = (border) ? pts_line_count : pts_line_count - 3;
991 const float wd =
geometry.raw_width;
992 const float ht =
geometry.raw_height;
997 const double min_step2 = min_step * min_step;
999 while(
i < points_count)
1001 const float px = points[
i * 2];
1002 const float py = points[
i * 2 + 1];
1010 cairo_move_to(cr, px, py);
1011 double last_x = px, last_y = py;
1015 while(
i < points_count)
1017 const double qx = points[
i * 2];
1018 const double qy = points[
i * 2 + 1];
1020 const double dx = qx - last_x, dy = qy - last_y;
1021 const gboolean is_last = (
i + 1 >= points_count) || !isnormal(points[(
i + 1) * 2])
1023 if(!is_last && (dx * dx + dy * dy) < min_step2) {
i++;
continue; }
1024 cairo_line_to(cr, qx, qy);
1025 last_x = qx; last_y = qy;
1032 const float zoom_scale,
float *pts,
int pts_count)
1034 if(pts_count < 3)
return;
1036 const float anchor_x = pts[0];
1037 const float anchor_y = pts[1];
1038 const float pivot_end_x = pts[2];
1039 const float pivot_end_y = pts[3];
1040 const float pivot_start_x = pts[4];
1041 const float pivot_start_y = pts[5];
1047 const float scale = 1 / zoom_scale;
1048 const float dx = pivot_end_x - pivot_start_x;
1049 const float dy = pivot_end_y - pivot_start_y;
1051 const float new_x1 = pivot_start_x - (dx * scale * 0.5f);
1052 const float new_y1 = pivot_start_y - (dy * scale * 0.5f);
1053 const float new_x2 = pivot_end_x + (dx * scale * 0.5f);
1054 const float new_y2 = pivot_end_y + (dy * scale * 0.5f);
1055 cairo_move_to(cr, new_x1, new_y1);
1056 cairo_line_to(cr, new_x2, new_y2);
1064 const float arrow_angle = 0.25f;
1068 const float dx = pivot_end_x - anchor_x;
1069 const float dy = pivot_end_y - anchor_y;
1070 const float angle_dir = atan2f(dy, dx);
1073 const float tip_x = anchor_x + arrow_length * cosf(angle_dir);
1074 const float tip_y = anchor_y + arrow_length * sinf(angle_dir);
1077 const float half_w = arrow_length * tanf(arrow_angle);
1080 const float nx = -sinf(angle_dir);
1081 const float ny = cosf(angle_dir);
1084 const float arrow_x1 = anchor_x + nx * half_w;
1085 const float arrow_y1 = anchor_y + ny * half_w;
1086 const float arrow_x2 = anchor_x - nx * half_w;
1087 const float arrow_y2 = anchor_y - ny * half_w;
1090 cairo_move_to(cr, tip_x, tip_y);
1091 cairo_line_to(cr, arrow_x1, arrow_y1);
1092 cairo_line_to(cr, arrow_x2, arrow_y2);
1093 cairo_close_path(cr);
1096 cairo_fill_preserve(cr);
1098 cairo_set_line_width(cr, line_width);
1148 float **points,
int *points_count,
1149 float **border,
int *border_count,
1154 if(!
IS_NULL_PTR(border_skips)) *border_skips = NULL;
1155 if(!
IS_NULL_PTR(border_skip_count)) *border_skip_count = 0;
1163 points, points_count) != 0)
1169 border, border_count));
1184 float points[8] = { 0.0f, 0.0f, wd, 0.0f, wd, ht, 0.0f, ht };
1191 float xmin = 0.0f, xmax = 0.0f, ymin = 0.0f, ymax = 0.0f;
1192 xmin = ymin = FLT_MAX;
1193 xmax = ymax = FLT_MIN;
1194 for(
int i = 0;
i < 4;
i++)
1196 xmin = fminf(points[
i * 2], xmin);
1197 xmax = fmaxf(points[
i * 2], xmax);
1198 ymin = fminf(points[
i * 2 + 1], ymin);
1199 ymax = fmaxf(points[
i * 2 + 1], ymax);
1205 *
width = (xmax - xmin);
1214 const int bin1 =
i + 1;
1215 const float f =
i - bin0;
1216 return lut[bin1] *
f +
lut[bin0] * (1.0f -
f);
1222 float **buffer,
int *
width,
int *
height,
int *posx,
int *posy)
1230 double start2 = 0.0;
1247 const int w = *
width;
1249 const int px = *posx;
1250 const int py = *posy;
1252 const int gw = (w + grid - 1) / grid + 1;
1253 const int gh = (h + grid - 1) / grid + 1;
1257 = { .
x0 = 0, .y0 = 0, .width = gw, .height =
gh,
1258 .step = grid, .px = px, .py = py, .iscale = 1.0f };
1265 const float wd = pipe->
iwidth;
1266 const float ht = pipe->
iheight;
1267 const float hwscale = 1.0f / dt_fast_hypotf(wd, ht);
1268 const float ihwscale = 1.0f / hwscale;
1270 const float sinv = sinf(
v);
1271 const float cosv = cosf(
v);
1272 const float xoffset = cosv * gradient->
center[0] * wd + sinv * gradient->
center[1] * ht;
1273 const float yoffset = sinv * gradient->
center[0] * wd - cosv * gradient->
center[1] * ht;
1274 const float extent = fmaxf(gradient->
extent, 0.001f);
1275 const float normf = 1.0f / extent;
1276 const float curvature = gradient->
curvature;
1279 const int lutmax = ceilf(4 * extent * ihwscale);
1280 const int lutsize = 2 * lutmax + 2;
1290 const float distance = (
n - lutmax) * hwscale;
1296 float *clut =
lut + lutmax;
1300 for(
int j = 0; j <
gh; j++)
1302 for(
int i = 0;
i < gw;
i++)
1304 const float x = points[(j * gw +
i) * 2];
1305 const float y = points[(j * gw +
i) * 2 + 1];
1307 const float x0 = (cosv *
x + sinv * y - xoffset) * hwscale;
1308 const float y0 = (sinv *
x - cosv * y - yoffset) * hwscale;
1310 const float distance = y0 - curvature * x0 * x0;
1312 points[(j * gw +
i) * 2] = (distance <= -4.0f * extent) ? 0.0f :
1313 ((distance >= 4.0f * extent) ? 1.0f :
dt_gradient_lookup(clut, distance * ihwscale));
1346 double start2 = 0.0;
1353 const int w = roi->
width;
1354 const int h = roi->
height;
1355 const int px = roi->
x;
1356 const int py = roi->
y;
1358 const int grid = CLAMP((10.0f*roi->
scale + 2.0f) / 3.0f, 1, 4);
1359 const int gw = (w + grid - 1) / grid + 1;
1360 const int gh = (h + grid - 1) / grid + 1;
1363 = { .
x0 = 0, .y0 = 0, .width = gw, .height =
gh,
1364 .step = grid, .px = px, .py = py, .iscale =
iscale };
1371 const float wd = pipe->
iwidth;
1372 const float ht = pipe->
iheight;
1373 const float hwscale = 1.0f / dt_fast_hypotf(wd, ht);
1374 const float ihwscale = 1.0f / hwscale;
1376 const float sinv = sinf(
v);
1377 const float cosv = cosf(
v);
1378 const float xoffset = cosv * gradient->
center[0] * wd + sinv * gradient->
center[1] * ht;
1379 const float yoffset = sinv * gradient->
center[0] * wd - cosv * gradient->
center[1] * ht;
1380 const float extent = fmaxf(gradient->
extent, 0.001f);
1381 const float normf = 1.0f / extent;
1382 const float curvature = gradient->
curvature;
1385 const int lutmax = ceilf(4 * extent * ihwscale);
1386 const int lutsize = 2 * lutmax + 2;
1396 const float distance = (
n - lutmax) * hwscale;
1402 float *clut =
lut + lutmax;
1405 for(
int j = 0; j <
gh; j++)
1407 for(
int i = 0;
i < gw;
i++)
1409 const size_t index = (size_t)j * gw +
i;
1410 const float x = points[index * 2];
1411 const float y = points[index * 2 + 1];
1413 const float x0 = (cosv *
x + sinv * y - xoffset) * hwscale;
1414 const float y0 = (sinv *
x - cosv * y - yoffset) * hwscale;
1416 const float distance = y0 - curvature * x0 * x0;
1418 points[index * 2] = (distance <= -4.0f * extent) ? 0.0f : ((distance >= 4.0f * extent) ? 1.0f :
dt_gradient_lookup(clut, distance * ihwscale));
1446 snprintf(form->
name,
sizeof(form->
name), _(
"gradient #%d"), (
int)nb);
1450 char *
const restrict msgbuf,
const size_t msgbuf_len)
1455 g_strlcat(msgbuf, _(
"<b>Linear/sigmoidal fade</b>: Shift+Click"), msgbuf_len);
1458 g_strlcat(msgbuf, _(
"<b>Rotate</b>: Drag"), msgbuf_len);
1460 g_strlcat(msgbuf, _(
"<b>Move</b>: Drag, <b>Reset curvature</b>: Double-click"), msgbuf_len);
Handle default and user-set shortcuts (accelerators)
static double dist(double x1, double y1, double x2, double y2)
void cleanup(dt_imageio_module_format_t *self)
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
const float const int lutsize
void dt_conf_set_float(const char *name, float val)
float dt_conf_get_float(const char *name)
Float for name, clamped to its declared bounds.
void dt_conf_set_int(const char *name, int val)
int dt_get_num_openmp_threads(void)
Number of OpenMP threads the application decided to use.
dt_dev_image_geometry_t dt_dev_geometry_snapshot(const dt_develop_t *dev)
int dt_dev_coordinates_raw_abs_to_image_abs(dt_develop_t *dev, float *points, size_t points_count)
void dt_dev_coordinates_raw_norm_to_raw_abs(dt_develop_t *dev, float *points, size_t num_points)
int dt_dev_distort_transform_plus(const dt_dev_pixelpipe_t *pipe, const double iop_order, const int transf_direction, float *points, size_t points_count)
void dt_dev_coordinates_raw_abs_to_raw_norm(dt_develop_t *dev, float *points, size_t num_points)
@ DT_DEV_TRANSFORM_DIR_BACK_INCL
GtkWidget * geometry
its size, under the preview
GtkWidget * preview
what the selected row actually captures
GHashTable * selected
set of checked row labels, mirrored to conf on every change
#define DT_DRAW_SIZE_LINE
static void dt_draw_stroke_line(const dt_draw_dash_type_t dash_type, const gboolean source, cairo_t *cr, const gboolean selected, const float zoom_scale, const cairo_line_cap_t line_cap)
#define DT_DRAW_SIZE_LINE_SELECTED
static double dt_draw_min_emit_step(cairo_t *cr)
Stroke a line with style.
static void dt_draw_set_color_overlay(cairo_t *cr, gboolean bright, double alpha)
#define DT_DRAW_SCALE_ARROW
static void dt_draw_shape_lines(struct dt_develop_t *dev, const dt_draw_dash_type_t dash_type, const gboolean source, cairo_t *cr, const int nb, const gboolean selected, const float zoom_scale, const float *points, const int points_count, const shape_draw_function_t *draw_shape_func, const cairo_line_cap_t line_cap, const struct dt_masks_skip_range_t *skips, const int skip_count)
Draw the lines of a mask shape.
static void dt_draw_node(cairo_t *cr, const gboolean square, const gboolean point_action, const gboolean selected, const float zoom_scale, const float x, const float y)
Draw an node point of a mask.
static void _gradient_events_post_expose(cairo_t *cr, float zoom_scale, dt_masks_form_gui_t *gui, int index, int nb)
static float _gradient_set_interaction_value(dt_masks_form_t *form, dt_masks_interaction_t interaction, float value, dt_masks_increment_t increment, int flow, dt_masks_form_gui_t *gui, struct dt_iop_module_t *module)
static int _gradient_events_button_released(struct dt_iop_module_t *module, double x, double y, int which, uint32_t state, dt_masks_form_t *form, int parentid, dt_masks_form_gui_t *gui, int index)
static float _gradient_get_interaction_value(const dt_masks_form_t *form, dt_masks_interaction_t interaction)
static void _closest_point_on_segment(float px, float py, float x1, float y1, float x2, float y2, float *closest_x, float *closest_y, float *distance_sq)
static void _copy_points(float *dest, const float *src, int count, int *k)
static void _gradient_node_position_cb(const dt_masks_form_gui_points_t *gui_points, int node_index, float *node_x, float *node_y, void *user_data)
static float dt_gradient_lookup(const float *lut, const float i)
static int _gradient_events_mouse_moved(struct dt_iop_module_t *module, double x, double y, double pressure, int which, dt_masks_form_t *form, int parentid, dt_masks_form_gui_t *gui, int index)
static int _gradient_events_key_pressed(struct dt_iop_module_t *module, GdkEventKey *event, dt_masks_form_t *form, int parentid, dt_masks_form_gui_t *gui, int index)
static int _gradient_events_button_pressed(struct dt_iop_module_t *module, double x, double y, double pressure, int which, int type, uint32_t state, dt_masks_form_t *form, int parentid, dt_masks_form_gui_t *gui, int index)
static int _gradient_get_pts_border(dt_develop_t *dev, float x, float y, float rotation, float distance, float curvature, float **points, int *points_count)
static int _find_border_separator(const float *border, int count)
static int _change_extent(dt_masks_form_t *form, dt_masks_form_gui_t *gui, struct dt_iop_module_t *module, int index, const float amount, const dt_masks_increment_t increment, const int flow)
static int _change_curvature(dt_masks_form_t *form, dt_masks_form_gui_t *gui, struct dt_iop_module_t *module, int index, const float amount, const dt_masks_increment_t increment, const int flow)
static void _gradient_get_creation_values(dt_masks_gradient_creation_values_t *values)
static void _closest_point_on_line(float px, float py, const float *border, int start_idx, int end_idx, float *closest_x, float *closest_y, float *min_distance_sq)
static int _init_opacity(dt_masks_form_t *form, const float amount, const dt_masks_increment_t increment, const int flow)
static dt_masks_raster_result_t _gradient_get_area(const dt_iop_module_t *const module, dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *const piece, dt_masks_form_t *const form, int *width, int *height, int *posx, int *posy)
static void _gradient_draw_arrow(cairo_t *cr, const gboolean selected, const gboolean pivot_selected, const gboolean is_rotating, const float zoom_scale, float *pts, int pts_count)
static void _gradient_distance_cb(float pointer_x, float pointer_y, float cursor_radius, dt_masks_form_gui_t *mask_gui, int form_index, int node_count, int *inside, int *inside_border, int *near_handle, int *inside_source, float *dist, void *user_data)
static dt_masks_raster_result_t _gradient_get_points_border(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, const dt_iop_module_t *module)
static int _find_closest_handle(dt_masks_form_t *mask_form, dt_masks_form_gui_t *mask_gui, int index)
static int _init_extent(dt_masks_form_t *form, const float amount, const dt_masks_increment_t increment, const int flow)
static int _gradient_get_creation_preview(dt_masks_form_gui_t *gui, dt_masks_preview_buffers_t *preview)
static dt_masks_raster_result_t _gradient_get_mask(const dt_iop_module_t *const module, dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *const piece, dt_masks_form_t *const form, float **buffer, int *width, int *height, int *posx, int *posy)
static int _init_curvature(dt_masks_form_t *form, const float amount, const dt_masks_increment_t increment, const int flow)
static int _gradient_get_points(dt_develop_t *dev, float x, float y, float rotation, float curvature, float **points, int *points_count)
Build the distorted display polyline for a gradient mask.
static gboolean _gradient_get_gravity_center(dt_develop_t *dev, const dt_masks_form_t *form, float center[2], float *area)
static void _gradient_set_form_name(struct dt_masks_form_t *const form, const size_t nb)
static int _gradient_events_mouse_scrolled(struct dt_iop_module_t *module, double x, double y, int up, const int flow, uint32_t state, dt_masks_form_t *form, int parentid, dt_masks_form_gui_t *gui, int index, dt_masks_interaction_t interaction)
static float _gradient_get_border_len_sq(const dt_masks_form_gui_points_t *gpt)
static void _gradient_init_new(dt_masks_form_gui_t *gui, dt_masks_anchor_gradient_t *gradient)
static void _gradient_draw_shape(struct dt_develop_t *dev, cairo_t *cr, const float *pts_line, const int pts_line_count, const int nb, const gboolean border, const gboolean source, const dt_masks_skip_range_t *skips, const int skip_count)
static int _change_rotation(dt_masks_form_t *form, dt_masks_form_gui_t *gui, struct dt_iop_module_t *module, int index, const float amount, const dt_masks_increment_t increment, const int flow)
static void _gradient_duplicate_points(dt_develop_t *dev, dt_masks_form_t *const base, dt_masks_form_t *const dest)
static dt_masks_raster_result_t _gradient_get_mask_roi(const dt_iop_module_t *const module, 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)
static void _gradient_sanitize_config(dt_masks_type_t type)
static int _init_rotation(dt_masks_form_t *form, const float amount, const dt_masks_increment_t increment, const int flow)
static gboolean _gradient_is_canonical(const float x, const float y, const float wd, const float ht)
static void _gradient_get_distance(float x, float y, float dist_mouse, dt_masks_form_gui_t *gui, int index, int num_points, int *inside, int *inside_border, int *near_handle, int *inside_source, float *dist)
static void _gradient_post_select_cb(dt_masks_form_gui_t *mask_gui, int inside, int inside_border, int inside_source, void *user_data)
const dt_masks_functions_t dt_masks_functions_gradient
static void _gradient_set_hint_message(const dt_masks_form_gui_t *const gui, const dt_masks_form_t *const form, char *const restrict msgbuf, const size_t msgbuf_len)
_lib_location_type_t type
int32_t dt_get_debug_flags(void)
void dt_print(dt_debug_thread_t thread, const char *msg,...) __attribute__((format(printf
Print to stdout when thread is enabled, prefixed with seconds since startup.
float *const restrict const size_t k
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
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)
float * dt_masks_sample_grid_backtransform(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)
static dt_masks_raster_result_t dt_masks_raster_from_status(const int status)
dt_masks_raster_result_t
What a rasterisation attempt produced.
void dt_masks_duplicate_points(const dt_masks_form_t *base, dt_masks_form_t *dest, size_t node_size)
Duplicate a points list for a mask using a fixed node size.
int dt_masks_form_change_opacity(dt_develop_t *dev, dt_masks_form_t *form, int parentid, int up, const int flow)
dt_masks_gradient_states_t
@ DT_MASKS_GRADIENT_STATE_SIGMOIDAL
@ DT_MASKS_GRADIENT_STATE_LINEAR
The per-shape function table, private to the masks implementation.
float dt_masks_rotate_with_anchor(dt_develop_t *develop, const float anchor[2], const float center[2], dt_masks_form_gui_t *mask_gui)
Compute rotation angle (degrees) around a center using an anchor point.
float dt_masks_apply_increment(float current, float amount, dt_masks_increment_t increment, int flow)
Apply a scroll increment to a scalar value.
int dt_masks_find_closest_handle_common(dt_masks_form_t *mask_form, dt_masks_form_gui_t *mask_gui, int form_index, int node_count_override, dt_masks_border_handle_fn border_handle_cb, dt_masks_curve_handle_fn curve_handle_cb, dt_masks_node_position_fn node_position_cb, dt_masks_distance_fn distance_cb, dt_masks_post_select_fn post_select_cb, void *user_data)
Centralized hit-testing for node/handle/segment selection across shapes.
void dt_masks_gui_form_create(dt_masks_form_t *mask_form, dt_masks_form_gui_t *mask_gui, int form_index, dt_iop_module_t *module)
float dt_masks_get_set_conf_value_with_toast(dt_masks_form_t *mask_form, const char *feature, float amount, float value_min, float value_max, dt_masks_increment_t increment, int flow, const char *toast_fmt, float toast_scale)
Update a mask configuration value and emit a toast message.
void dt_masks_gui_form_save_creation(dt_develop_t *develop, dt_iop_module_t *module, dt_masks_form_t *mask_form, dt_masks_form_gui_t *mask_gui)
Save the form creation right after a shape has been finished drawing.
The interactive half of the masks subsystem: the editing state (dt_masks_form_gui_t),...
static void dt_masks_gui_cursor_to_raw_norm(dt_develop_t *dev, const dt_masks_form_gui_t *gui, float point[2])
static void dt_masks_draw_preview_shape(struct dt_develop_t *dev, cairo_t *cr, const float zoom_scale, const int num_points, float *points, const int points_count, float *border, const int border_count, const shape_draw_function_t *draw_shape, const cairo_line_cap_t shape_cap, const cairo_line_cap_t border_cap, const gboolean save_restore, const gboolean source)
static void dt_masks_preview_buffers_cleanup(dt_masks_preview_buffers_t *buffers)
static void dt_masks_gui_delta_to_raw_norm(dt_develop_t *dev, const dt_masks_form_gui_t *gui, float point[2])
static void dt_masks_touched_full(dt_iop_roi_t *touched, const int width, const int height)
static void dt_masks_touched_none(dt_iop_roi_t *touched)
@ DT_MASKS_INTERACTION_OPACITY
@ DT_MASKS_INTERACTION_SIZE
@ DT_MASKS_INTERACTION_FADING
@ DT_MASKS_INTERACTION_ROTATION
@ DT_MASKS_INCREMENT_SCALE
@ DT_MASKS_INCREMENT_OFFSET
@ DT_MASKS_INCREMENT_ABSOLUTE
#define CLAMPF(a, mn, mx)
static float gh(const float f)
#define __OMP_PARALLEL_FOR__(...)
#define __OMP_PARALLEL_FOR_SIMD__(...)
#define dt_get_bythread(buf, padsize, tnum)
#define dt_pixelpipe_cache_alloc_align_float_cache(pixels, id)
#define dt_pixelpipe_cache_free_align(mem)
#define dt_get_perthread(buf, padsize)
#define dt_pixelpipe_cache_calloc_perthread(n, objsize, padded_size)
#define dt_pixelpipe_cache_alloc_perthread_float(n, padded_size)
static const dt_aligned_pixel_simd_t value
const float uint32_t state[4]
Objective facts about the image a dev is working on.
Region of interest passed through the pixelpipe.
dt_masks_gradient_states_t state
shape_draw_function_t draw_shape
One cut in a shape's border outline: while walking the border buffer forward, on reaching index jump_...
static double dt_get_wtime(void)