Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
path.c File Reference
#include "bauhaus/bauhaus.h"
#include "common/debug.h"
#include "common/imagebuf.h"
#include "common/undo.h"
#include "control/conf.h"
#include "develop/blend.h"
#include "develop/imageop.h"
#include "develop/masks.h"
#include "develop/openmp_maths.h"
#include <assert.h>
+ Include dependency graph for path.c:

Functions

static void _path_bounding_box_raw (const float *const points, const float *border, const int nb_corner, const int num_points, int num_borders, float *x_min, float *x_max, float *y_min, float *y_max)
 
static void _path_get_XY (float p0x, float p0y, float p1x, float p1y, float p2x, float p2y, float p3x, float p3y, float t, float *x, float *y)
 
static void _path_border_get_XY (float p0x, float p0y, float p1x, float p1y, float p2x, float p2y, float p3x, float p3y, float t, float rad, float *xc, float *yc, float *xb, float *yb)
 
static void _path_ctrl2_to_feather (float ptx, float pty, float ctrlx, float ctrly, float *fx, float *fy, gboolean clockwise)
 
static void _path_feather_to_ctrl (float ptx, float pty, float fx, float fy, float *ctrl1x, float *ctrl1y, float *ctrl2x, float *ctrl2y, gboolean clockwise)
 
static void _path_catmull_to_bezier (float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float *bx1, float *by1, float *bx2, float *by2)
 
static void _path_init_ctrl_points (dt_masks_form_t *form)
 
static gboolean _path_is_clockwise (dt_masks_form_t *form)
 
static int _path_fill_gaps (int lastx, int lasty, int x, int y, dt_masks_dynbuf_t *points)
 
static void _path_points_recurs_border_gaps (float *cmax, float *bmin, float *bmin2, float *bmax, dt_masks_dynbuf_t *dpoints, dt_masks_dynbuf_t *dborder, gboolean clockwise)
 
static void _path_points_recurs (float *p1, float *p2, double tmin, double tmax, float *path_min, float *path_max, float *border_min, float *border_max, float *rpath, float *rborder, dt_masks_dynbuf_t *dpoints, dt_masks_dynbuf_t *dborder, int withborder)
 
static int _path_find_self_intersection (dt_masks_dynbuf_t *inter, int nb_corners, float *border, int border_count)
 
static int _path_get_pts_border (dt_develop_t *dev, dt_masks_form_t *form, const double iop_order, const int transf_direction, dt_dev_pixelpipe_t *pipe, float **points, int *points_count, float **border, int *border_count, gboolean source)
 
static void _path_get_distance (float x, float y, float as, dt_masks_form_gui_t *gui, int index, int corner_count, int *inside, int *inside_border, int *near, int *inside_source, float *dist)
 
static int _path_get_points_border (dt_develop_t *dev, dt_masks_form_t *form, float **points, int *points_count, float **border, int *border_count, int source, const dt_iop_module_t *module)
 
static void _path_get_sizes (struct dt_iop_module_t *module, dt_masks_form_t *form, dt_masks_form_gui_t *gui, int index, float *masks_size, float *feather_size)
 
static int _path_events_mouse_scrolled (struct dt_iop_module_t *module, float pzx, float pzy, int up, uint32_t state, dt_masks_form_t *form, int parentid, dt_masks_form_gui_t *gui, int index, dt_masks_interaction_t interaction)
 
static int _path_events_button_pressed (struct dt_iop_module_t *module, float pzx, float pzy, 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 _path_events_button_released (struct dt_iop_module_t *module, float pzx, float pzy, int which, uint32_t state, dt_masks_form_t *form, int parentid, dt_masks_form_gui_t *gui, int index)
 
static int _path_events_mouse_moved (struct dt_iop_module_t *module, float pzx, float pzy, double pressure, int which, dt_masks_form_t *form, int parentid, dt_masks_form_gui_t *gui, int index)
 
static void _path_events_post_expose (cairo_t *cr, float zoom_scale, dt_masks_form_gui_t *gui, int index, int nb)
 
static void _path_bounding_box (const float *const points, const float *border, const int nb_corner, const int num_points, int num_borders, int *width, int *height, int *posx, int *posy)
 
static int _get_area (const dt_iop_module_t *const module, const dt_dev_pixelpipe_iop_t *const piece, dt_masks_form_t *const form, int *width, int *height, int *posx, int *posy, gboolean get_source)
 
static int _path_get_source_area (dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, dt_masks_form_t *form, int *width, int *height, int *posx, int *posy)
 
static int _path_get_area (const dt_iop_module_t *const module, const dt_dev_pixelpipe_iop_t *const piece, dt_masks_form_t *const form, int *width, int *height, int *posx, int *posy)
 
void _path_falloff (float *const restrict buffer, int *p0, int *p1, int posx, int posy, int bw)
 
static int _path_get_mask (const dt_iop_module_t *const module, 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 _path_crop_to_roi (float *path, const int point_count, float xmin, float xmax, float ymin, float ymax)
 
static void _path_falloff_roi (float *buffer, int *p0, int *p1, int bw, int bh)
 
static int _path_get_mask_roi (const dt_iop_module_t *const module, const dt_dev_pixelpipe_iop_t *const piece, dt_masks_form_t *const form, const dt_iop_roi_t *roi, float *buffer)
 
static void _path_sanitize_config (dt_masks_type_t type)
 
static void _path_set_form_name (struct dt_masks_form_t *const form, const size_t nb)
 
static void _path_set_hint_message (const dt_masks_form_gui_t *const gui, const dt_masks_form_t *const form, const int opacity, char *const restrict msgbuf, const size_t msgbuf_len)
 
static void _path_duplicate_points (dt_develop_t *const dev, dt_masks_form_t *const base, dt_masks_form_t *const dest)
 
static void _path_initial_source_pos (const float iwd, const float iht, float *x, float *y)
 

Variables

const dt_masks_functions_t dt_masks_functions_path
 

Function Documentation

◆ _get_area()

static int _get_area ( const dt_iop_module_t *const  module,
const dt_dev_pixelpipe_iop_t *const  piece,
dt_masks_form_t *const  form,
int *  width,
int *  height,
int *  posx,
int *  posy,
gboolean  get_source 
)
static

◆ _path_border_get_XY()

static void _path_border_get_XY ( float  p0x,
float  p0y,
float  p1x,
float  p1y,
float  p2x,
float  p2y,
float  p3x,
float  p3y,
float  t,
float  rad,
float *  xc,
float *  yc,
float *  xb,
float *  yb 
)
static

get the point of the path at pos t [0,1] AND the corresponding border point

References _path_get_XY(), and double().

Referenced by _path_get_pts_border(), and _path_points_recurs().

◆ _path_bounding_box()

static void _path_bounding_box ( const float *const  points,
const float *  border,
const int  nb_corner,
const int  num_points,
int  num_borders,
int *  width,
int *  height,
int *  posx,
int *  posy 
)
static

References _path_bounding_box_raw(), height, and width.

Referenced by _get_area(), and _path_get_mask().

◆ _path_bounding_box_raw()

static void _path_bounding_box_raw ( const float *const  points,
const float *  border,
const int  nb_corner,
const int  num_points,
int  num_borders,
float *  x_min,
float *  x_max,
float *  y_min,
float *  y_max 
)
static

References MAX, and MIN.

Referenced by _path_bounding_box(), and _path_get_mask_roi().

◆ _path_catmull_to_bezier()

static void _path_catmull_to_bezier ( float  x1,
float  y1,
float  x2,
float  y2,
float  x3,
float  y3,
float  x4,
float  y4,
float *  bx1,
float *  by1,
float *  bx2,
float *  by2 
)
static

Get the control points of a segment to match exactly a catmull-rom spline

Referenced by _path_init_ctrl_points().

◆ _path_crop_to_roi()

static int _path_crop_to_roi ( float *  path,
const int  point_count,
float  xmin,
float  xmax,
float  ymin,
float  ymax 
)
static

crop path to roi given by xmin, xmax, ymin, ymax. path segments outside of roi are replaced by nodes lying on roi borders.

Referenced by _path_get_mask_roi().

◆ _path_ctrl2_to_feather()

static void _path_ctrl2_to_feather ( float  ptx,
float  pty,
float  ctrlx,
float  ctrly,
float *  fx,
float *  fy,
gboolean  clockwise 
)
static

get feather extremity from the control point n°2 the values should be in orthonormal space

Referenced by _path_events_mouse_moved(), and _path_events_post_expose().

◆ _path_duplicate_points()

static void _path_duplicate_points ( dt_develop_t *const  dev,
dt_masks_form_t *const  base,
dt_masks_form_t *const  dest 
)
static

References dt_masks_form_t::points, and void().

◆ _path_events_button_pressed()

static int _path_events_button_pressed ( struct dt_iop_module_t module,
float  pzx,
float  pzy,
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

References _path_init_ctrl_points(), _path_is_clockwise(), dt_dev_pixelpipe_t::backbuf_height, dt_dev_pixelpipe_t::backbuf_width, dt_masks_point_path_t::border, dt_masks_form_gui_points_t::clockwise, dt_masks_point_path_t::corner, dt_masks_form_gui_t::creation, dt_masks_form_gui_t::creation_closing_form, dt_masks_form_gui_t::creation_module, dt_masks_point_path_t::ctrl1, dt_masks_point_path_t::ctrl2, darktable, darktable_t::develop, dt_conf_get_float(), dt_dev_distort_backtransform(), dt_dev_masks_list_remove(), dt_dev_masks_selection_change(), dt_masks_change_form_gui(), dt_masks_clear_form_gui(), DT_MASKS_CLONE, DT_MASKS_EDIT_FULL, dt_masks_form_remove(), dt_masks_get_from_id(), DT_MASKS_GROUP, dt_masks_gui_form_create(), dt_masks_gui_form_remove(), dt_masks_gui_form_save_creation(), dt_masks_iop_update(), DT_MASKS_NON_CLONE, DT_MASKS_PATH, DT_MASKS_POINT_STATE_NORMAL, DT_MASKS_POINT_STATE_USER, dt_masks_select_form(), dt_masks_set_edit_mode(), dt_masks_set_source_pos_initial_state(), dt_masks_set_source_pos_initial_value(), dt_modifier_is(), dt_masks_form_gui_t::dx, dt_masks_form_gui_t::dy, dt_masks_form_gui_t::edit_mode, dt_masks_form_gui_t::feather_dragging, dt_masks_form_gui_t::feather_selected, dt_masks_form_gui_t::form_dragging, dt_develop_t::form_gui, dt_masks_form_gui_t::form_selected, dt_develop_t::form_visible, dt_masks_point_group_t::formid, dt_masks_form_t::formid, g_list_next_wraparound(), g_list_shorter_than(), dt_masks_form_gui_t::group_selected, dt_dev_pixelpipe_t::iheight, dt_dev_pixelpipe_t::iwidth, MAX, MIN, dt_masks_form_gui_t::point_border_dragging, dt_masks_form_gui_t::point_border_selected, dt_masks_form_gui_t::point_dragging, dt_masks_form_gui_t::point_edited, dt_masks_form_gui_t::point_selected, dt_masks_form_t::points, dt_masks_form_gui_points_t::points, dt_masks_form_gui_t::points, dt_masks_form_gui_t::posx, dt_masks_form_gui_t::posy, dt_develop_t::preview_pipe, dt_masks_form_gui_t::scrollx, dt_masks_form_gui_t::scrolly, dt_masks_form_gui_t::seg_dragging, dt_masks_form_gui_t::seg_selected, dt_masks_form_t::source, dt_masks_form_gui_points_t::source, dt_masks_form_gui_t::source_dragging, dt_masks_form_gui_t::source_selected, dt_masks_point_path_t::state, TRUE, type, and dt_masks_form_t::type.

◆ _path_events_button_released()

◆ _path_events_mouse_moved()

static int _path_events_mouse_moved ( struct dt_iop_module_t module,
float  pzx,
float  pzy,
double  pressure,
int  which,
dt_masks_form_t form,
int  parentid,
dt_masks_form_gui_t gui,
int  index 
)
static

References _path_ctrl2_to_feather(), _path_feather_to_ctrl(), _path_get_distance(), _path_init_ctrl_points(), dt_dev_pixelpipe_t::backbuf_height, dt_dev_pixelpipe_t::backbuf_width, dt_masks_form_gui_points_t::border, dt_masks_form_gui_t::border_selected, dt_masks_form_gui_points_t::clockwise, dt_masks_point_path_t::corner, dt_masks_form_gui_t::creation, dt_masks_form_gui_t::creation_closing_form, dt_masks_point_path_t::ctrl1, dt_masks_point_path_t::ctrl2, darktable, darktable_t::develop, dist(), dt_control_get_dev_closeup(), dt_control_get_dev_zoom(), dt_dev_distort_backtransform(), dt_dev_get_zoom_scale(), DT_MASKS_CLONE, DT_MASKS_EDIT_FULL, dt_masks_gui_form_create(), dt_masks_gui_form_remove(), DT_MASKS_POINT_STATE_USER, DT_PIXEL_APPLY_DPI, dt_masks_form_gui_t::dx, dt_masks_form_gui_t::dy, dt_masks_form_gui_t::edit_mode, FALSE, dt_masks_form_gui_t::feather_dragging, dt_masks_form_gui_t::feather_selected, dt_masks_form_gui_t::form_dragging, dt_masks_form_gui_t::form_selected, g_list_next_wraparound(), g_list_shorter_than(), dt_masks_form_gui_t::group_selected, dt_dev_pixelpipe_t::iheight, dt_dev_pixelpipe_t::iwidth, dt_masks_form_gui_t::point_border_dragging, dt_masks_form_gui_t::point_border_selected, dt_masks_form_gui_t::point_dragging, dt_masks_form_gui_t::point_edited, dt_masks_form_gui_t::point_selected, dt_masks_form_t::points, dt_masks_form_gui_points_t::points, dt_masks_form_gui_t::points, dt_develop_t::preview_pipe, dt_masks_form_gui_t::seg_dragging, dt_masks_form_gui_t::seg_selected, dt_masks_form_t::source, dt_masks_form_gui_t::source_dragging, dt_masks_form_gui_t::source_selected, TRUE, and dt_masks_form_t::type.

◆ _path_events_mouse_scrolled()

◆ _path_events_post_expose()

◆ _path_falloff()

void _path_falloff ( float *const restrict  buffer,
int *  p0,
int *  p1,
int  posx,
int  posy,
int  bw 
)

we write a falloff segment

References sqf().

Referenced by _path_get_mask().

◆ _path_falloff_roi()

static void _path_falloff_roi ( float *  buffer,
int *  p0,
int *  p1,
int  bw,
int  bh 
)
static

we write a falloff segment respecting limits of buffer

References MAX.

Referenced by _path_get_mask_roi().

◆ _path_feather_to_ctrl()

static void _path_feather_to_ctrl ( float  ptx,
float  pty,
float  fx,
float  fy,
float *  ctrl1x,
float *  ctrl1y,
float *  ctrl2x,
float *  ctrl2y,
gboolean  clockwise 
)
static

get bezier control points from feather extremity the values should be in orthonormal space

Referenced by _path_events_button_released(), and _path_events_mouse_moved().

◆ _path_fill_gaps()

static int _path_fill_gaps ( int  lastx,
int  lasty,
int  x,
int  y,
dt_masks_dynbuf_t points 
)
static

fill eventual gaps between 2 points with a line

References dt_masks_dynbuf_add_2(), dt_masks_dynbuf_get(), and dt_masks_dynbuf_reset().

Referenced by _path_find_self_intersection().

◆ _path_find_self_intersection()

static int _path_find_self_intersection ( dt_masks_dynbuf_t inter,
int  nb_corners,
float *  border,
int  border_count 
)
static

◆ _path_get_area()

static int _path_get_area ( const dt_iop_module_t *const  module,
const dt_dev_pixelpipe_iop_t *const  piece,
dt_masks_form_t *const  form,
int *  width,
int *  height,
int *  posx,
int *  posy 
)
static

References _get_area(), FALSE, height, and width.

◆ _path_get_distance()

static void _path_get_distance ( float  x,
float  y,
float  as,
dt_masks_form_gui_t gui,
int  index,
int  corner_count,
int *  inside,
int *  inside_border,
int *  near,
int *  inside_source,
float *  dist 
)
static

◆ _path_get_mask()

◆ _path_get_mask_roi()

◆ _path_get_points_border()

static int _path_get_points_border ( dt_develop_t dev,
dt_masks_form_t form,
float **  points,
int *  points_count,
float **  border,
int *  border_count,
int  source,
const dt_iop_module_t module 
)
static

◆ _path_get_pts_border()

◆ _path_get_sizes()

◆ _path_get_source_area()

static int _path_get_source_area ( dt_iop_module_t module,
dt_dev_pixelpipe_iop_t piece,
dt_masks_form_t form,
int *  width,
int *  height,
int *  posx,
int *  posy 
)
static

References _get_area(), height, TRUE, and width.

◆ _path_get_XY()

static void _path_get_XY ( float  p0x,
float  p0y,
float  p1x,
float  p1y,
float  p2x,
float  p2y,
float  p3x,
float  p3y,
float  t,
float *  x,
float *  y 
)
static

get the point of the path at pos t [0,1]

Referenced by _path_border_get_XY().

◆ _path_init_ctrl_points()

◆ _path_initial_source_pos()

static void _path_initial_source_pos ( const float  iwd,
const float  iht,
float *  x,
float *  y 
)
static

◆ _path_is_clockwise()

◆ _path_points_recurs()

static void _path_points_recurs ( float *  p1,
float *  p2,
double  tmin,
double  tmax,
float *  path_min,
float *  path_max,
float *  border_min,
float *  border_max,
float *  rpath,
float *  rborder,
dt_masks_dynbuf_t dpoints,
dt_masks_dynbuf_t dborder,
int  withborder 
)
static

recursive function to get all points of the path AND all point of the border the function take care to avoid big gaps between points

References _path_border_get_XY(), _path_points_recurs(), and dt_masks_dynbuf_add_2().

Referenced by _path_get_pts_border(), and _path_points_recurs().

◆ _path_points_recurs_border_gaps()

static void _path_points_recurs_border_gaps ( float *  cmax,
float *  bmin,
float *  bmin2,
float *  bmax,
dt_masks_dynbuf_t dpoints,
dt_masks_dynbuf_t dborder,
gboolean  clockwise 
)
static

fill the gap between 2 points with an arc of circle this function is here because we can have gap in border, esp. if the corner is very sharp

References dt_masks_dynbuf_reserve_n(), and M_PI.

Referenced by _path_get_pts_border().

◆ _path_sanitize_config()

static void _path_sanitize_config ( dt_masks_type_t  type)
static

◆ _path_set_form_name()

static void _path_set_form_name ( struct dt_masks_form_t *const  form,
const size_t  nb 
)
static

References dt_masks_form_t::name.

◆ _path_set_hint_message()

static void _path_set_hint_message ( const dt_masks_form_gui_t *const  gui,
const dt_masks_form_t *const  form,
const int  opacity,
char *const restrict  msgbuf,
const size_t  msgbuf_len 
)
static

Variable Documentation

◆ dt_masks_functions_path

const dt_masks_functions_t dt_masks_functions_path
Initial value:
= {
.point_struct_size = sizeof(struct dt_masks_point_path_t),
.sanitize_config = _path_sanitize_config,
.set_form_name = _path_set_form_name,
.set_hint_message = _path_set_hint_message,
.duplicate_points = _path_duplicate_points,
.initial_source_pos = _path_initial_source_pos,
.get_distance = _path_get_distance,
.get_points_border = _path_get_points_border,
.get_mask = _path_get_mask,
.get_mask_roi = _path_get_mask_roi,
.get_area = _path_get_area,
.get_source_area = _path_get_source_area,
.mouse_moved = _path_events_mouse_moved,
.mouse_scrolled = _path_events_mouse_scrolled,
.button_pressed = _path_events_button_pressed,
.button_released = _path_events_button_released,
.post_expose = _path_events_post_expose
}
static int _path_get_mask(const dt_iop_module_t *const module, const dt_dev_pixelpipe_iop_t *const piece, dt_masks_form_t *const form, float **buffer, int *width, int *height, int *posx, int *posy)
Definition path.c:2325
static void _path_set_form_name(struct dt_masks_form_t *const form, const size_t nb)
Definition path.c:3098
static void _path_sanitize_config(dt_masks_type_t type)
Definition path.c:3093
static void _path_initial_source_pos(const float iwd, const float iht, float *x, float *y)
Definition path.c:3136
static int _path_events_mouse_moved(struct dt_iop_module_t *module, float pzx, float pzy, double pressure, int which, dt_masks_form_t *form, int parentid, dt_masks_form_gui_t *gui, int index)
Definition path.c:1678
static int _path_events_button_pressed(struct dt_iop_module_t *module, float pzx, float pzy, double pressure, int which, int type, uint32_t state, dt_masks_form_t *form, int parentid, dt_masks_form_gui_t *gui, int index)
Definition path.c:1129
static int _path_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, float **points, int *points_count, float **border, int *border_count, int source, const dt_iop_module_t *module)
Definition path.c:941
static int _path_get_area(const dt_iop_module_t *const module, const dt_dev_pixelpipe_iop_t *const piece, dt_masks_form_t *const form, int *width, int *height, int *posx, int *posy)
Definition path.c:2294
static void _path_get_distance(float x, float y, float as, dt_masks_form_gui_t *gui, int index, int corner_count, int *inside, int *inside_border, int *near, int *inside_source, float *dist)
Definition path.c:826
static int _path_events_button_released(struct dt_iop_module_t *module, float pzx, float pzy, int which, uint32_t state, dt_masks_form_t *form, int parentid, dt_masks_form_gui_t *gui, int index)
Definition path.c:1515
static void _path_duplicate_points(dt_develop_t *const dev, dt_masks_form_t *const base, dt_masks_form_t *const dest)
Definition path.c:3124
static int _path_get_source_area(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, dt_masks_form_t *form, int *width, int *height, int *posx, int *posy)
Definition path.c:2288
static void _path_set_hint_message(const dt_masks_form_gui_t *const gui, const dt_masks_form_t *const form, const int opacity, char *const restrict msgbuf, const size_t msgbuf_len)
Definition path.c:3103
static void _path_events_post_expose(cairo_t *cr, float zoom_scale, dt_masks_form_gui_t *gui, int index, int nb)
Definition path.c:1963
static int _path_get_mask_roi(const dt_iop_module_t *const module, const dt_dev_pixelpipe_iop_t *const piece, dt_masks_form_t *const form, const dt_iop_roi_t *roi, float *buffer)
Definition path.c:2734
static int _path_events_mouse_scrolled(struct dt_iop_module_t *module, float pzx, float pzy, int up, uint32_t state, dt_masks_form_t *form, int parentid, dt_masks_form_gui_t *gui, int index, dt_masks_interaction_t interaction)
Definition path.c:999
Definition masks.h:133

Referenced by dt_masks_calculate_source_pos_value(), and dt_masks_create().