44#define M_PI 3.141592654
49#define DT_DRAW_SIZE_LINE DT_PIXEL_APPLY_DPI(1.5f)
50#define DT_DRAW_SIZE_LINE_SELECTED DT_PIXEL_APPLY_DPI(3.0f)
51#define DT_DRAW_SIZE_LINE_HIGHLIGHT (DT_PIXEL_APPLY_DPI(4.0f) + DT_DRAW_SIZE_LINE)
52#define DT_DRAW_SIZE_LINE_HIGHLIGHT_SELECTED (DT_PIXEL_APPLY_DPI(5.0f) + DT_DRAW_SIZE_LINE_SELECTED)
53#define DT_DRAW_SIZE_CROSS DT_PIXEL_APPLY_DPI(7.0f)
56#define DT_DRAW_SCALE_DASH DT_PIXEL_APPLY_DPI(12.0f)
57#define DT_DRAW_SCALE_ARROW DT_PIXEL_APPLY_DPI(18.0f)
60#define DT_DRAW_RADIUS_NODE DT_PIXEL_APPLY_DPI(5.0f)
61#define DT_DRAW_RADIUS_NODE_SELECTED (1.5f * DT_DRAW_RADIUS_NODE)
64#define DT_DRAW_SELECTION_RADIUS_NO_UPSCALE(dev) (2.0f * DT_DRAW_RADIUS_NODE / dt_dev_get_zoom_level((dt_develop_t *)dev))
65#define DT_DRAW_SELECTION_RADIUS(dev) (DT_DRAW_SELECTION_RADIUS_NO_UPSCALE((dt_develop_t*)dev) * darktable.gui->ppd)
68#define DT_DRAW_SELECTION_ROTATION_AREA DT_PIXEL_APPLY_DPI(50.0f)
69#define DT_DRAW_SELECTION_ROTATION_RADIUS(dev) (DT_DRAW_SELECTION_ROTATION_AREA / dt_dev_get_zoom_level((dt_develop_t *)dev))
101static inline void dt_draw_star(cairo_t *cr,
float x,
float y,
float r1,
float r2)
103 const float d = 2.0 *
M_PI * 0.1f;
104 const float dx[10] = { sinf(0.0), sinf(d), sinf(2 * d), sinf(3 * d), sinf(4 * d),
105 sinf(5 * d), sinf(6 * d), sinf(7 * d), sinf(8 * d), sinf(9 * d) };
106 const float dy[10] = { cosf(0.0), cosf(d), cosf(2 * d), cosf(3 * d), cosf(4 * d),
107 cosf(5 * d), cosf(6 * d), cosf(7 * d), cosf(8 * d), cosf(9 * d) };
109 cairo_move_to(cr, x + r1 * dx[0], y - r1 * dy[0]);
110 for(
int k = 1; k < 10; k++)
112 cairo_line_to(cr, x + r2 * dx[k], y - r2 * dy[k]);
114 cairo_line_to(cr, x + r1 * dx[k], y - r1 * dy[k]);
115 cairo_close_path(cr);
118static inline void dt_draw_line(cairo_t *cr,
float left,
float top,
float right,
float bottom)
120 cairo_move_to(cr, left, top);
121 cairo_line_to(cr, right, bottom);
124static inline void dt_draw_grid(cairo_t *cr,
const int num,
const int left,
const int top,
const int right,
127 float width = right - left;
128 float height = bottom - top;
130 for(
int k = 1; k < num; k++)
139static inline float dt_curve_to_mouse(
const float x,
const float zoom_factor,
const float offset)
141 return (x - offset) * zoom_factor;
146 const float right,
const float bottom,
const float width,
147 const float height,
const float zoom_factor,
const float zoom_offset_x,
148 const float zoom_offset_y)
150 for(
int k = 1; k < num; k++)
167#pragma omp declare simd uniform(base)
171 return logf(x * (base - 1.0f) + 1.f) / logf(base);
174static inline void dt_draw_loglog_grid(cairo_t *cr,
const int num,
const int left,
const int top,
const int right,
175 const int bottom,
const float base)
177 float width = right - left;
178 float height = bottom - top;
180 for(
int k = 1; k < num; k++)
191 const int right,
const int bottom,
const float base)
193 float width = right - left;
194 float height = bottom - top;
196 for(
int k = 1; k < num; k++)
207 const int right,
const int bottom,
const float base)
209 float width = right - left;
210 float height = bottom - top;
212 for(
int k = 1; k < num; k++)
224 const int right,
const int bottom)
226 float width = right - left;
228 for(
int k = 1; k < num; k++)
230 cairo_move_to(cr, left + k / (
float)num *
width, top);
231 cairo_line_to(cr, left + k / (
float)num *
width, bottom);
237 const int right,
const int bottom)
239 float height = bottom - top;
241 for(
int k = 1; k < num; k++)
243 cairo_move_to(cr, left, top + k / (
float)num *
height);
244 cairo_line_to(cr, right, top + k / (
float)num *
height);
252 c->csample.m_samplingRes = 0x10000;
253 c->csample.m_outputRes = 0x10000;
254 c->csample.m_Samples = (uint16_t *)malloc(
sizeof(uint16_t) * 0x10000);
256 c->c.m_spline_type =
type;
257 c->c.m_numAnchors = 0;
267 free(c->csample.m_Samples);
273 c->c.m_anchors[num].x = x;
274 c->c.m_anchors[num].y = y;
283#pragma omp parallel for SIMD() default(none) dt_omp_firstprivate(res) shared(x) schedule(static)
285 for(
int k = 0; k < res; k++) x[k] = k * (1.0f / res);
290#pragma omp parallel for SIMD() default(none) dt_omp_firstprivate(min, max, res) shared(y, c) schedule(static)
292 for(
int k = 0; k < res; k++) y[k] = min + (max - min) * c->csample.m_Samples[k] * (1.0f / 0x10000);
299 c->csample.m_samplingRes = res;
300 c->csample.m_outputRes = 0x10000;
306 const int res,
float *x,
float *y)
308 c->csample.m_samplingRes = res;
309 c->csample.m_outputRes = 0x10000;
315 const int res,
float *x,
float *y)
317 c->csample.m_samplingRes = res;
318 c->csample.m_outputRes = 0x10000;
324 const int res,
float *x,
float *y,
const gboolean periodic)
334 float xa[20], ya[20];
337 for(
int i = 0; i < c->c.m_numAnchors; i++)
339 xa[i] = c->c.m_anchors[i].x;
340 ya[i] = c->c.m_anchors[i].y;
345 val =
interpolate_val(c->c.m_numAnchors, xa, x, ya, ypp, c->c.m_spline_type);
348 return MIN(
MAX(val, c->c.m_min_y), c->c.m_max_y);
353 c->c.m_anchors[c->c.m_numAnchors].x = x;
354 c->c.m_anchors[c->c.m_numAnchors].y = y;
363 cairo_move_to(cr, 0, 0);
364 for(
int k = 0; k < 256; k++) cairo_line_to(cr, k, hist[channels * k + channel]);
365 cairo_line_to(cr, 255, 0);
366 cairo_close_path(cr);
371 const float zoom_factor,
const float zoom_offset_x,
372 const float zoom_offset_y, gboolean
linear)
374 cairo_move_to(cr, -zoom_offset_x, -zoom_offset_y);
375 for(
int k = 0; k < 256; k++)
377 const float value = ((float)hist[channels * k + channel] - zoom_offset_y) * zoom_factor;
378 const float hist_value = value < 0 ? 0.f : value;
379 cairo_line_to(cr, ((
float)k - zoom_offset_x) * zoom_factor,
linear ? hist_value : logf(1.0f + hist_value));
381 cairo_line_to(cr, (255.f - zoom_offset_x), -zoom_offset_y * zoom_factor);
382 cairo_close_path(cr);
388 int32_t channel,
float base_log)
390 cairo_move_to(cr, 0, 0);
391 for(
int k = 0; k < 256; k++)
393 const float x = logf((
float)k / 255.0f * (base_log - 1.0f) + 1.0f) / logf(base_log) * 255.0f;
394 const float y = hist[channels * k + channel];
395 cairo_line_to(cr, x, y);
397 cairo_line_to(cr, 255, 0);
398 cairo_close_path(cr);
404 int32_t channel,
float base_log)
406 cairo_move_to(cr, 0, 0);
407 for(
int k = 0; k < 256; k++)
409 const float x = logf((
float)k / 255.0f * (base_log - 1.0f) + 1.0f) / logf(base_log) * 255.0f;
410 const float y = logf(1.0 + hist[channels * k + channel]);
411 cairo_line_to(cr, x, y);
413 cairo_line_to(cr, 255, 0);
414 cairo_close_path(cr);
422 cairo_move_to(cr, 0, 0);
423 for(
int k = 0; k < 256; k++) cairo_line_to(cr, k, logf(1.0 + hist[channels * k + channel]));
424 cairo_line_to(cr, 255, 0);
425 cairo_close_path(cr);
431 int32_t channel,
const gboolean
linear,
float base_log)
441static inline void dt_draw_histogram_8(cairo_t *cr,
const uint32_t *hist, int32_t channels, int32_t channel,
453 for(uint32_t y = 0; y <
height; y++)
454 for(uint32_t x = 0; x <
width; x++)
456 uint8_t *r, *g, *b, *a, tmp;
457 r = &data[(y *
width + x) * 4 + 0];
458 g = &data[(y *
width + x) * 4 + 1];
459 b = &data[(y *
width + x) * 4 + 2];
460 a = &data[(y *
width + x) * 4 + 3];
470 float inv_a = 255.0 / *a;
481 cairo_pattern_add_color_stop_rgba(grad, 0.0, 0.0, 0.0, 0.0, alpha);
482 cairo_pattern_add_color_stop_rgba(grad, 1.0, 1.0, 1.0, 1.0, alpha);
486 (GtkWidget *widget,
const guint pixbuf_size,
const int flags,
487 void (*dtgtk_cairo_paint_fct)(cairo_t *cr, gint x, gint y, gint w, gint h, gint
flags,
void *data))
490 GtkStyleContext *context = gtk_widget_get_style_context(widget);
491 GtkStateFlags state = gtk_widget_get_state_flags(widget);
492 gtk_style_context_get_color(context, state, &fg_color);
495 cairo_surface_t *cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, dim, dim);
496 cairo_t *cr = cairo_create(cst);
497 gdk_cairo_set_source_rgba(cr, &fg_color);
498 (*dtgtk_cairo_paint_fct)(cr, 0, 0, dim, dim,
flags, NULL);
500 uint8_t *data = cairo_image_surface_get_data(cst);
502 const size_t size = (size_t)dim * dim * 4;
503 uint8_t *buf = (uint8_t *)malloc(
size);
504 memcpy(buf, data,
size);
505 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_data(buf, GDK_COLORSPACE_RGB,
TRUE, 8, dim, dim, dim * 4,
506 (GdkPixbufDestroyNotify)free, NULL);
507 cairo_surface_destroy(cst);
518 cairo_set_dash(cr, NULL, 0, 0);
542 cairo_set_dash(cr, NULL, 0, 0);
546 const int pattern_len = 2;
547 cairo_set_dash(cr, pattern, pattern_len, 0);
561static inline 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)
570 const float pos = node_width;
571 cairo_rectangle(cr, x - pos, y - pos, node_width * 2.f, node_width * 2.f);
574 cairo_arc(cr, x, y, node_width * 1.2f, 0.0, 2.0 * G_PI);
576 cairo_fill_preserve(cr);
581 cairo_set_line_width(cr, line_width);
586 cairo_fill_preserve(cr);
589 cairo_set_line_width(cr, (selected && !point_action) ? line_width * 2. : line_width);
609static inline void dt_draw_handle(cairo_t *cr,
const float pt_x,
const float pt_y,
const float zoom_scale,
610 const float handle_x,
const float handle_y,
const gboolean selected)
615 float delta_x = handle_x - pt_x;
616 float delta_y = handle_y - pt_y;
617 float tail_len = sqrtf(delta_x * delta_x + delta_y * delta_y);
621 if(tail_len > (2 * shorten))
623 float start_x = pt_x + delta_x * (shorten / tail_len);
624 float start_y = pt_y + delta_y * (shorten / tail_len);
625 float end_x = handle_x - delta_x * (shorten / tail_len);
626 float end_y = handle_y - delta_y * (shorten / tail_len);
627 cairo_move_to(cr, start_x, start_y);
628 cairo_line_to(cr, end_x, end_y);
633 cairo_stroke_preserve(cr);
642 float handle_radius = 0.0f;
643 float line_width = 0.0f;
655 cairo_arc(cr, handle_x, handle_y, handle_radius * 0.75f, 0, 2.0 *
M_PI);
657 cairo_fill_preserve(cr);
659 cairo_set_line_width(cr, line_width);
661 cairo_stroke_preserve(cr);
676typedef void (*
shape_draw_function_t)(cairo_t *cr,
const float *points,
const int points_count,
const int nb,
const gboolean border,
const gboolean source);
692 const float zoom_scale,
const float *points,
const int points_count,
const shape_draw_function_t *draw_shape_func)
699 if(draw_shape_func && points && points_count >= 2)
701 (*draw_shape_func)(cr, points, points_count, nb, border,
FALSE);
708 cairo_set_source_rgba(cr, 0., 0., 0., 0.);
709 cairo_fill_preserve(cr);
713 if(dash_type && !source)
724 cairo_stroke_preserve(cr);
747 const gboolean selected,
const float zoom_scale)
752static void _draw_arrow_head(cairo_t *cr,
const float arrow[2],
const float arrow_x_a,
const float arrow_y_a,
753 const float arrow_x_b,
const float arrow_y_b)
756 cairo_move_to(cr, arrow_x_a, arrow_y_a);
757 cairo_line_to(cr, arrow[0], arrow[1]);
758 cairo_line_to(cr, arrow_x_b, arrow_y_b);
760 cairo_close_path(cr);
764 const float tail[2],
const gboolean draw_tail)
766 if(draw_tail)
dt_draw_line(cr, arrow_bud_x, arrow_bud_y, tail[0], tail[1]);
782static inline void dt_draw_arrow(cairo_t *cr,
const float zoom_scale,
const gboolean selected,
const gboolean draw_tail,
786 float delta_x = tail[0] - arrow[0];
787 float delta_y = tail[1] - arrow[1];
788 float angle = atan2f(delta_y, delta_x);
791 const float arrow_x_a = arrow[0] + (
DT_DRAW_SCALE_ARROW / zoom_scale) * cosf(angle + (0.4f));
792 const float arrow_y_a = arrow[1] + (
DT_DRAW_SCALE_ARROW / zoom_scale) * sinf(angle + (0.4f));
793 const float arrow_x_b = arrow[0] + (
DT_DRAW_SCALE_ARROW / zoom_scale) * cosf(angle - (0.4f));
794 const float arrow_y_b = arrow[1] + (
DT_DRAW_SCALE_ARROW / zoom_scale) * sinf(angle - (0.4f));
796 const float arrow_bud_x = (arrow_x_a + arrow_x_b) * 0.5f;
797 const float arrow_bud_y = (arrow_y_a + arrow_y_b) * 0.5f;
800 cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
809 cairo_fill_preserve(cr);
840 cairo_set_source_rgba(cr, 0., 0., 0., 0.);
841 cairo_fill_preserve(cr);
#define TRUE
Definition ashift_lsd.c:151
#define FALSE
Definition ashift_lsd.c:147
int width
Definition bilateral.h:1
int height
Definition bilateral.h:1
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
darktable_t darktable
Definition darktable.c:111
static void dt_draw_arrow(cairo_t *cr, const float zoom_scale, const gboolean selected, const gboolean draw_tail, const dt_masks_dash_type_t dash_style, const float arrow[2], const float tail[2])
Draw an arrow with head and, if needed, tail. The length of the arrow head is defined by DT_DRAW_SCAL...
Definition draw.h:782
dt_masks_dash_type_t
Definition draw.h:73
@ DT_MASKS_DASH_STICK
Definition draw.h:75
@ DT_MASKS_DASH_ROUND
Definition draw.h:76
@ DT_MASKS_NO_DASH
Definition draw.h:74
static float dt_curve_to_mouse(const float x, const float zoom_factor, const float offset)
Definition draw.h:139
#define DT_DRAW_SCALE_DASH
Definition draw.h:56
#define DT_DRAW_SIZE_LINE
Definition draw.h:49
#define DT_DRAW_RADIUS_NODE_SELECTED
Definition draw.h:61
static void dt_draw_set_dash_style(cairo_t *cr, dt_masks_dash_type_t type, float zoom_scale)
Definition draw.h:513
static GdkPixbuf * dt_draw_paint_to_pixbuf(GtkWidget *widget, const guint pixbuf_size, const int flags, void(*dtgtk_cairo_paint_fct)(cairo_t *cr, gint x, gint y, gint w, gint h, gint flags, void *data))
Definition draw.h:486
static void dt_draw_curve_calc_values(dt_draw_curve_t *c, const float min, const float max, const int res, float *x, float *y)
Definition draw.h:296
static void dt_draw_horizontal_lines(cairo_t *cr, const int num, const int left, const int top, const int right, const int bottom)
Definition draw.h:236
static void dt_draw_histogram_8_zoomed(cairo_t *cr, const uint32_t *hist, int32_t channels, int32_t channel, const float zoom_factor, const float zoom_offset_x, const float zoom_offset_y, gboolean linear)
Definition draw.h:370
#define DT_DRAW_SIZE_LINE_HIGHLIGHT
Definition draw.h:51
#define DT_DRAW_SIZE_LINE_SELECTED
Definition draw.h:50
static void dt_draw_histogram_8_logxlogy(cairo_t *cr, const uint32_t *hist, int32_t channels, int32_t channel, float base_log)
Definition draw.h:403
static void dt_draw_cairo_to_gdk_pixbuf(uint8_t *data, unsigned int width, unsigned int height)
Definition draw.h:451
static void dt_draw_histogram_8_linxlogy(cairo_t *cr, const uint32_t *hist, int32_t channels, int32_t channel)
Definition draw.h:419
static float dt_log_scale_axis(const float x, const float base)
Definition draw.h:169
static void dt_draw_handle(cairo_t *cr, const float pt_x, const float pt_y, const float zoom_scale, const float handle_x, const float handle_y, const gboolean selected)
Draw & control handle of a point with a tail bet.
Definition draw.h:609
static void dt_draw_set_color_overlay(cairo_t *cr, gboolean bright, double alpha)
Definition draw.h:87
static void dt_draw_line(cairo_t *cr, float left, float top, float right, float bottom)
Definition draw.h:118
static void dt_draw_curve_smaple_values(dt_draw_curve_t *c, const float min, const float max, const int res, float *x, float *y)
Definition draw.h:277
static void dt_draw_histogram_8_linxliny(cairo_t *cr, const uint32_t *hist, int32_t channels, int32_t channel)
Definition draw.h:360
static void dt_draw_vertical_lines(cairo_t *cr, const int num, const int left, const int top, const int right, const int bottom)
Definition draw.h:223
static void dt_draw_grid(cairo_t *cr, const int num, const int left, const int top, const int right, const int bottom)
Definition draw.h:124
static void dt_draw_semilog_y_grid(cairo_t *cr, const int num, const int left, const int top, const int right, const int bottom, const float base)
Definition draw.h:206
static float dt_draw_curve_calc_value(dt_draw_curve_t *c, const float x)
Definition draw.h:332
static void dt_cairo_perceptual_gradient(cairo_pattern_t *grad, double alpha)
Definition draw.h:478
static void dt_draw_star(cairo_t *cr, float x, float y, float r1, float r2)
Definition draw.h:101
static void dt_draw_curve_calc_values_V2_nonperiodic(dt_draw_curve_t *c, const float min, const float max, const int res, float *x, float *y)
Definition draw.h:305
#define DT_DRAW_SCALE_ARROW
Definition draw.h:57
static void dt_draw_curve_destroy(dt_draw_curve_t *c)
Definition draw.h:265
static void dt_draw_curve_calc_values_V2(dt_draw_curve_t *c, const float min, const float max, const int res, float *x, float *y, const gboolean periodic)
Definition draw.h:323
static void dt_draw_histogram_8_log_base(cairo_t *cr, const uint32_t *hist, int32_t channels, int32_t channel, const gboolean linear, float base_log)
Definition draw.h:430
#define DT_DRAW_RADIUS_NODE
Definition draw.h:60
static void dt_draw_curve_set_point(dt_draw_curve_t *c, const int num, const float x, const float y)
Definition draw.h:271
static int dt_draw_curve_add_point(dt_draw_curve_t *c, const float x, const float y)
Definition draw.h:351
static void dt_draw_histogram_8_logxliny(cairo_t *cr, const uint32_t *hist, int32_t channels, int32_t channel, float base_log)
Definition draw.h:387
static void dt_draw_stroke_line(const dt_masks_dash_type_t dash_type, const gboolean source, cairo_t *cr, const gboolean selected, const float zoom_scale)
Stroke a line with style.
Definition draw.h:746
#define DT_DRAW_SIZE_LINE_HIGHLIGHT_SELECTED
Definition draw.h:52
static void dt_draw_semilog_x_grid(cairo_t *cr, const int num, const int left, const int top, const int right, const int bottom, const float base)
Definition draw.h:190
static void dt_draw_histogram_8(cairo_t *cr, const uint32_t *hist, int32_t channels, int32_t channel, const gboolean linear)
Definition draw.h:441
static dt_draw_curve_t * dt_draw_curve_new(const float min, const float max, unsigned int type)
Definition draw.h:249
#define M_PI
Definition draw.h:44
void(* shape_draw_function_t)(cairo_t *cr, const float *points, const int points_count, const int nb, const gboolean border, const gboolean source)
Definition draw.h:676
static void dt_draw_loglog_grid(cairo_t *cr, const int num, const int left, const int top, const int right, const int bottom, const float base)
Definition draw.h:174
static void _draw_arrow_head(cairo_t *cr, const float arrow[2], const float arrow_x_a, const float arrow_y_a, const float arrow_x_b, const float arrow_y_b)
Definition draw.h:752
static void dt_draw_curve_calc_values_V2_periodic(dt_draw_curve_t *c, const float min, const float max, const int res, float *x, float *y)
Definition draw.h:314
static void dt_draw_shape_lines(const dt_masks_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)
Draw the lines of a mask shape.
Definition draw.h:691
static void dt_draw_grid_zoomed(cairo_t *cr, const int num, const float left, const float top, const float right, const float bottom, const float width, const float height, const float zoom_factor, const float zoom_offset_x, const float zoom_offset_y)
Definition draw.h:145
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.
Definition draw.h:561
static void _draw_arrow_tail(cairo_t *cr, const float arrow_bud_x, const float arrow_bud_y, const float tail[2], const gboolean draw_tail)
Definition draw.h:763
#define DT_PIXEL_APPLY_DPI(value)
Definition gtk.h:38
@ linear
Definition lightroom.c:388
size_t size
Definition mipmap_cache.c:3
dt_mipmap_buffer_dsc_flags flags
Definition mipmap_cache.c:4
int CurveDataSampleV2Periodic(CurveData *curve, CurveSample *sample)
Definition splines.cpp:845
int CurveDataSampleV2(CurveData *curve, CurveSample *sample)
Definition splines.cpp:749
Definition curve_tools.h:56
Definition curve_tools.h:76
struct dt_gui_gtk_t * gui
Definition darktable.h:541
CurveSample csample
Definition draw.h:83
CurveData c
Definition draw.h:82
double overlay_contrast
Definition gtk.h:115
double overlay_red
Definition gtk.h:115
double overlay_green
Definition gtk.h:115
double overlay_blue
Definition gtk.h:115
#define MIN(a, b)
Definition thinplate.c:23
#define MAX(a, b)
Definition thinplate.c:20