44#define M_PI 3.141592654
69static inline void dt_draw_star(cairo_t *cr,
float x,
float y,
float r1,
float r2)
71 const float d = 2.0 *
M_PI * 0.1f;
72 const float dx[10] = { sinf(0.0), sinf(d), sinf(2 * d), sinf(3 * d), sinf(4 * d),
73 sinf(5 * d), sinf(6 * d), sinf(7 * d), sinf(8 * d), sinf(9 * d) };
74 const float dy[10] = { cosf(0.0), cosf(d), cosf(2 * d), cosf(3 * d), cosf(4 * d),
75 cosf(5 * d), cosf(6 * d), cosf(7 * d), cosf(8 * d), cosf(9 * d) };
77 cairo_move_to(cr, x + r1 * dx[0], y - r1 * dy[0]);
78 for(
int k = 1; k < 10; k++)
80 cairo_line_to(cr, x + r2 * dx[k], y - r2 * dy[k]);
82 cairo_line_to(cr, x + r1 * dx[k], y - r1 * dy[k]);
69static inline void dt_draw_star(cairo_t *cr,
float x,
float y,
float r1,
float r2) {
…}
86static inline void dt_draw_line(cairo_t *cr,
float left,
float top,
float right,
float bottom)
88 cairo_move_to(cr, left, top);
89 cairo_line_to(cr, right, bottom);
86static inline void dt_draw_line(cairo_t *cr,
float left,
float top,
float right,
float bottom) {
…}
92static inline void dt_draw_grid(cairo_t *cr,
const int num,
const int left,
const int top,
const int right,
95 float width = right - left;
96 float height = bottom - top;
98 for(
int k = 1; k < num; k++)
92static inline void dt_draw_grid(cairo_t *cr,
const int num,
const int left,
const int top,
const int right, {
…}
107static inline float dt_curve_to_mouse(
const float x,
const float zoom_factor,
const float offset)
109 return (x - offset) * zoom_factor;
114 const float right,
const float bottom,
const float width,
115 const float height,
const float zoom_factor,
const float zoom_offset_x,
116 const float zoom_offset_y)
118 for(
int k = 1; k < num; k++)
135#pragma omp declare simd uniform(base)
139 return logf(x * (base - 1.0f) + 1.f) / logf(base);
142static inline void dt_draw_loglog_grid(cairo_t *cr,
const int num,
const int left,
const int top,
const int right,
143 const int bottom,
const float base)
145 float width = right - left;
146 float height = bottom - top;
148 for(
int k = 1; k < num; k++)
142static inline void dt_draw_loglog_grid(cairo_t *cr,
const int num,
const int left,
const int top,
const int right, {
…}
159 const int right,
const int bottom,
const float base)
161 float width = right - left;
162 float height = bottom - top;
164 for(
int k = 1; k < num; k++)
175 const int right,
const int bottom,
const float base)
177 float width = right - left;
178 float height = bottom - top;
180 for(
int k = 1; k < num; k++)
192 const int right,
const int bottom)
194 float width = right - left;
196 for(
int k = 1; k < num; k++)
198 cairo_move_to(cr, left + k / (
float)num *
width, top);
199 cairo_line_to(cr, left + k / (
float)num *
width, bottom);
205 const int right,
const int bottom)
207 float height = bottom - top;
209 for(
int k = 1; k < num; k++)
211 cairo_move_to(cr, left, top + k / (
float)num *
height);
212 cairo_line_to(cr, right, top + k / (
float)num *
height);
220 c->csample.m_samplingRes = 0x10000;
221 c->csample.m_outputRes = 0x10000;
222 c->csample.m_Samples = (uint16_t *)malloc(
sizeof(uint16_t) * 0x10000);
224 c->c.m_spline_type =
type;
225 c->c.m_numAnchors = 0;
235 free(c->csample.m_Samples);
241 c->c.m_anchors[num].x = x;
242 c->c.m_anchors[num].y = y;
251#pragma omp parallel for SIMD() default(none) dt_omp_firstprivate(res) shared(x) schedule(static)
253 for(
int k = 0; k < res; k++) x[k] = k * (1.0f / res);
258#pragma omp parallel for SIMD() default(none) dt_omp_firstprivate(min, max, res) shared(y, c) schedule(static)
260 for(
int k = 0; k < res; k++) y[k] = min + (max - min) * c->csample.m_Samples[k] * (1.0f / 0x10000);
267 c->csample.m_samplingRes = res;
268 c->csample.m_outputRes = 0x10000;
274 const int res,
float *x,
float *y)
276 c->csample.m_samplingRes = res;
277 c->csample.m_outputRes = 0x10000;
283 const int res,
float *x,
float *y)
285 c->csample.m_samplingRes = res;
286 c->csample.m_outputRes = 0x10000;
292 const int res,
float *x,
float *y,
const gboolean periodic)
302 float xa[20], ya[20];
305 for(
int i = 0; i < c->c.m_numAnchors; i++)
307 xa[i] = c->c.m_anchors[i].x;
308 ya[i] = c->c.m_anchors[i].y;
313 val =
interpolate_val(c->c.m_numAnchors, xa, x, ya, ypp, c->c.m_spline_type);
316 return MIN(
MAX(val, c->c.m_min_y), c->c.m_max_y);
321 c->c.m_anchors[c->c.m_numAnchors].x = x;
322 c->c.m_anchors[c->c.m_numAnchors].y = y;
331 cairo_move_to(cr, 0, 0);
332 for(
int k = 0; k < 256; k++) cairo_line_to(cr, k, hist[channels * k + channel]);
333 cairo_line_to(cr, 255, 0);
334 cairo_close_path(cr);
339 const float zoom_factor,
const float zoom_offset_x,
340 const float zoom_offset_y, gboolean
linear)
342 cairo_move_to(cr, -zoom_offset_x, -zoom_offset_y);
343 for(
int k = 0; k < 256; k++)
345 const float value = ((float)hist[channels * k + channel] - zoom_offset_y) * zoom_factor;
346 const float hist_value = value < 0 ? 0.f : value;
347 cairo_line_to(cr, ((
float)k - zoom_offset_x) * zoom_factor,
linear ? hist_value : logf(1.0f + hist_value));
349 cairo_line_to(cr, (255.f - zoom_offset_x), -zoom_offset_y * zoom_factor);
350 cairo_close_path(cr);
356 int32_t channel,
float base_log)
358 cairo_move_to(cr, 0, 0);
359 for(
int k = 0; k < 256; k++)
361 const float x = logf((
float)k / 255.0f * (base_log - 1.0f) + 1.0f) / logf(base_log) * 255.0f;
362 const float y = hist[channels * k + channel];
363 cairo_line_to(cr, x, y);
365 cairo_line_to(cr, 255, 0);
366 cairo_close_path(cr);
372 int32_t channel,
float base_log)
374 cairo_move_to(cr, 0, 0);
375 for(
int k = 0; k < 256; k++)
377 const float x = logf((
float)k / 255.0f * (base_log - 1.0f) + 1.0f) / logf(base_log) * 255.0f;
378 const float y = logf(1.0 + hist[channels * k + channel]);
379 cairo_line_to(cr, x, y);
381 cairo_line_to(cr, 255, 0);
382 cairo_close_path(cr);
390 cairo_move_to(cr, 0, 0);
391 for(
int k = 0; k < 256; k++) cairo_line_to(cr, k, logf(1.0 + hist[channels * k + channel]));
392 cairo_line_to(cr, 255, 0);
393 cairo_close_path(cr);
399 int32_t channel,
const gboolean
linear,
float base_log)
409static inline void dt_draw_histogram_8(cairo_t *cr,
const uint32_t *hist, int32_t channels, int32_t channel,
409static inline void dt_draw_histogram_8(cairo_t *cr,
const uint32_t *hist, int32_t channels, int32_t channel, {
…}
421 for(uint32_t y = 0; y <
height; y++)
422 for(uint32_t x = 0; x <
width; x++)
424 uint8_t *r, *g, *b, *a, tmp;
425 r = &data[(y *
width + x) * 4 + 0];
426 g = &data[(y *
width + x) * 4 + 1];
427 b = &data[(y *
width + x) * 4 + 2];
428 a = &data[(y *
width + x) * 4 + 3];
438 float inv_a = 255.0 / *a;
449 cairo_pattern_add_color_stop_rgba(grad, 0.0, 0.0, 0.0, 0.0, alpha);
450 cairo_pattern_add_color_stop_rgba(grad, 1.0, 1.0, 1.0, 1.0, alpha);
454 (GtkWidget *widget,
const guint pixbuf_size,
const int flags,
455 void (*dtgtk_cairo_paint_fct)(cairo_t *cr, gint x, gint y, gint w, gint h, gint
flags,
void *data))
458 GtkStyleContext *context = gtk_widget_get_style_context(widget);
459 GtkStateFlags state = gtk_widget_get_state_flags(widget);
460 gtk_style_context_get_color(context, state, &fg_color);
463 cairo_surface_t *cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, dim, dim);
464 cairo_t *cr = cairo_create(cst);
465 gdk_cairo_set_source_rgba(cr, &fg_color);
466 (*dtgtk_cairo_paint_fct)(cr, 0, 0, dim, dim,
flags, NULL);
468 uint8_t *data = cairo_image_surface_get_data(cst);
470 const size_t size = (size_t)dim * dim * 4;
471 uint8_t *buf = (uint8_t *)malloc(
size);
472 memcpy(buf, data,
size);
473 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_data(buf, GDK_COLORSPACE_RGB,
TRUE, 8, dim, dim, dim * 4,
474 (GdkPixbufDestroyNotify)free, NULL);
475 cairo_surface_destroy(cst);
#define TRUE
Definition ashift_lsd.c:151
int width
Definition bilateral.h:1
int height
Definition bilateral.h:1
darktable_t darktable
Definition darktable.c:111
static float dt_curve_to_mouse(const float x, const float zoom_factor, const float offset)
Definition draw.h:107
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:454
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:264
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:204
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:338
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:371
static void dt_draw_cairo_to_gdk_pixbuf(uint8_t *data, unsigned int width, unsigned int height)
Definition draw.h:419
static void dt_draw_histogram_8_linxlogy(cairo_t *cr, const uint32_t *hist, int32_t channels, int32_t channel)
Definition draw.h:387
static float dt_log_scale_axis(const float x, const float base)
Definition draw.h:137
static void dt_draw_set_color_overlay(cairo_t *cr, gboolean bright, double alpha)
Definition draw.h:55
static void dt_draw_line(cairo_t *cr, float left, float top, float right, float bottom)
Definition draw.h:86
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:245
static void dt_draw_histogram_8_linxliny(cairo_t *cr, const uint32_t *hist, int32_t channels, int32_t channel)
Definition draw.h:328
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:191
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:92
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:174
static float dt_draw_curve_calc_value(dt_draw_curve_t *c, const float x)
Definition draw.h:300
static void dt_cairo_perceptual_gradient(cairo_pattern_t *grad, double alpha)
Definition draw.h:446
static void dt_draw_star(cairo_t *cr, float x, float y, float r1, float r2)
Definition draw.h:69
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:273
static void dt_draw_curve_destroy(dt_draw_curve_t *c)
Definition draw.h:233
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:291
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:398
static void dt_draw_curve_set_point(dt_draw_curve_t *c, const int num, const float x, const float y)
Definition draw.h:239
static int dt_draw_curve_add_point(dt_draw_curve_t *c, const float x, const float y)
Definition draw.h:319
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:355
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:158
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:409
static dt_draw_curve_t * dt_draw_curve_new(const float min, const float max, unsigned int type)
Definition draw.h:217
#define M_PI
Definition draw.h:44
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:142
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:282
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:113
#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:51
CurveData c
Definition draw.h:50
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