30#ifndef DT_GUI_DTGTK_FOCUS_H
31#define DT_GUI_DTGTK_FOCUS_H
44#define gbuf(BUF, A, B) ((BUF)[4 * (width * ((B)) + ((A))) + ch])
50 return (uint8_t)CLAMP(
i + 127, 0, 255);
60 const int step = 1 << l;
61 const int st = step / 2;
63 for(
int j = 0; j <
height; j++)
68 for(;
i <
width - st;
i += step)
75 for(
i = step;
i <
width - st;
i += step)
86 for(; j <
height - st; j += step)
93 for(j = step; j <
height - st; j += step)
106 int fx =
i / (float)wd * fcols;
107 int fy = j / (float)ht * frows;
108 int fi = fcols * fy +
fx;
120 f[fi].x2 += (float)
i *
i;
124 f[fi].y2 += (float)j * j;
139 int buffer_width,
int buffer_height)
142 const int wd = buffer_width;
143 const int ht = buffer_height;
144 const int fs = frows * fcols;
152#pragma omp parallel for default(shared)
154 for(
int j = 0; j < ht - 1; j += 4)
155 for(
int i = 0;
i < wd - 1;
i += 4)
164 int num_clusters = 0;
165 for(
int k = 0;
k < fs;
k++)
166 if(focus[
k].
n * 4 > wd * ht / (
float)fs * 0.01f) num_clusters++;
172#pragma omp parallel for default(shared)
174 for(
int j = 0; j < ht - 1; j += 8)
176 for(
int i = 0;
i < wd - 1;
i += 8)
185 for(
int k = 0;
k < fs;
k++)
187 if(focus[
k].
n * 6.0f > wd * ht / (
float)fs * 0.01f)
200#pragma omp parallel for default(shared)
202 for(
int j=1;j<ht-1;j++)
204 int index = 4*j*wd+4;
205 for(
int i=1;
i<wd-1;
i++)
207 int32_t diff = 4*buffer[index+1]
210 - buffer[index-4*wd+1]
211 - buffer[index+4*wd+1];
218 for(
int k = 0;
k < fs;
k++)
220 focus[
k].
thrs /= fabsf((
float)focus[
k].
n);
221 focus[
k].
x /= fabsf((
float)focus[
k].
n);
222 focus[
k].
x2 /= fabsf((
float)focus[
k].
n);
223 focus[
k].
y /= fabsf((
float)focus[
k].
n);
224 focus[
k].
y2 /= fabsf((
float)focus[
k].
n);
230 float full_zoom,
float full_x,
float full_y)
232 const int fs = frows * fcols;
241 int wd = buffer_width + image.
crop_x;
242 int ht = buffer_height + image.
crop_y;
245 float *pos = malloc(fs * 6 *
sizeof(
float));
246 float *offx = pos + fs * 2, *offy = pos + fs * 4;
248 for(
int k = 0;
k < fs;
k++)
250 const float stddevx = sqrtf(focus[
k].x2 - focus[
k].
x * focus[
k].
x);
251 const float stddevy = sqrtf(focus[
k].y2 - focus[
k].y * focus[
k].y);
254 const float x = focus[
k].
x + image.
crop_x;
255 const float y = focus[
k].
y + image.
crop_y;
259 offx[2 *
k + 0] =
x + stddevx;
262 offy[2 *
k + 1] = y + stddevy;
294 const float scale = fminf((
width - 2 * tb) / (
float)wd, (
height - 2 * tb) / (
float)ht) * full_zoom;
295 cairo_scale(cr, scale, scale);
301 fx = fminf((wd * scale -
width) / 2, fabsf(full_x));
302 if(full_x < 0)
fx = -
fx;
303 if(wd * scale <=
width)
fx = 0;
304 fy = fminf((ht * scale -
height) / 2, fabsf(full_y));
305 if(full_y < 0) fy = -fy;
306 if(ht * scale <=
height) fy = 0;
311 cairo_rectangle(cr, 0, 0, wd, ht);
315 const int ndash =
sizeof(dashes) /
sizeof(dashes[0]);
316 double offset = 0.0f;
317 cairo_set_dash(cr, dashes, ndash, offset);
320 for(
int k = 0;
k < fs;
k++)
323 const float col = fminf(1.0f, intens);
325 if(focus[
k].
n * 4.0f > buffer_width * buffer_height / (
float)fs * 0.01f)
327 else if(-focus[
k].
n * 6.0f > buffer_width * buffer_height / (
float)fs * 0.01f)
331 for(
int i = 0;
i < 2;
i++)
336 cairo_set_source_rgb(cr, .1f, .1f, col);
338 cairo_set_source_rgb(cr, col, .1f, .1f);
339 cairo_set_dash(cr, dashes, ndash, dashes[0]);
343 cairo_set_source_rgb(cr, .1f, .1f, .1f);
344 cairo_set_dash(cr, dashes, ndash, 0);
346 cairo_move_to(cr, offx[2 *
k + 0], offx[2 *
k + 1]);
347 cairo_curve_to(cr, -pos[2 *
k + 0] + offx[2 *
k + 0] + offy[2 *
k + 0],
348 -pos[2 *
k + 1] + offx[2 *
k + 1] + offy[2 *
k + 1],
349 -pos[2 *
k + 0] + offx[2 *
k + 0] + offy[2 *
k + 0],
350 -pos[2 *
k + 1] + offx[2 *
k + 1] + offy[2 *
k + 1], offy[2 *
k + 0], offy[2 *
k + 1]);
351 cairo_curve_to(cr, pos[2 *
k + 0] - offx[2 *
k + 0] + offy[2 *
k + 0],
352 pos[2 *
k + 1] - offx[2 *
k + 1] + offy[2 *
k + 1],
353 pos[2 *
k + 0] - offx[2 *
k + 0] + offy[2 *
k + 0],
354 pos[2 *
k + 1] - offx[2 *
k + 1] + offy[2 *
k + 1],
355 2 * pos[2 *
k + 0] - offx[2 *
k + 0], 2 * pos[2 *
k + 1] - offx[2 *
k + 1]);
356 cairo_curve_to(cr, 3 * pos[2 *
k + 0] - offx[2 *
k + 0] - offy[2 *
k + 0],
357 3 * pos[2 *
k + 1] - offx[2 *
k + 1] - offy[2 *
k + 1],
358 3 * pos[2 *
k + 0] - offx[2 *
k + 0] - offy[2 *
k + 0],
359 3 * pos[2 *
k + 1] - offx[2 *
k + 1] - offy[2 *
k + 1],
360 2 * pos[2 *
k + 0] - offy[2 *
k + 0], 2 * pos[2 *
k + 1] - offy[2 *
k + 1]);
361 cairo_curve_to(cr, pos[2 *
k + 0] + offx[2 *
k + 0] - offy[2 *
k + 0],
362 pos[2 *
k + 1] + offx[2 *
k + 1] - offy[2 *
k + 1],
363 pos[2 *
k + 0] + offx[2 *
k + 0] - offy[2 *
k + 0],
364 pos[2 *
k + 1] + offx[2 *
k + 1] - offy[2 *
k + 1], offx[2 *
k + 0], offx[2 *
k + 1]);
367 cairo_scale(cr, 1. / scale, 1. / scale);
struct dt_develop_t * dt_dev_get_global(void)
struct dt_gui_gtk_t * dt_gui_get_global(void)
void dt_dev_pixelpipe_get_roi_out(dt_dev_pixelpipe_t *pipe, const int width_in, const int height_in, int *width, int *height)
int32_t dt_dev_viewport_border_size(const dt_develop_t *dev)
void dt_dev_cleanup(dt_develop_t *dev)
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)
dt_dev_image_storage_t dt_dev_load_image(dt_develop_t *dev, const int32_t imgid)
void dt_dev_init(dt_develop_t *dev, int32_t gui_attached)
@ DT_DEV_TRANSFORM_DIR_ALL
static void dt_focus_draw_clusters(cairo_t *cr, int width, int height, int32_t imgid, int buffer_width, int buffer_height, dt_focus_cluster_t *focus, int frows, int fcols, float full_zoom, float full_x, float full_y)
static void dt_focus_create_clusters(dt_focus_cluster_t *focus, int frows, int fcols, uint8_t *buffer, int buffer_width, int buffer_height)
static void _dt_focus_cdf22_wtf(uint8_t *buf, const int l, const int width, const int height)
static void _dt_focus_update(dt_focus_cluster_t *f, int frows, int fcols, int i, int j, int wd, int ht, int diff)
static int _from_uint8(uint8_t i)
static uint8_t _to_uint8(int i)
dt_image_t * dt_image_cache_get(const int32_t imgid, char mode)
void dt_image_cache_read_release(const dt_image_t *img)
float *const restrict const size_t k
float *const restrict const size_t const size_t ch
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
#define __OMP_PARALLEL_FOR__(...)
void dt_dev_pixelpipe_set_input(dt_dev_pixelpipe_t *pipe, int32_t imgid, int width, int height, float iscale, dt_mipmap_size_t size)
int dt_dev_pixelpipe_init_dummy(dt_dev_pixelpipe_t *pipe, dt_develop_t *dev)
void dt_dev_pixelpipe_create_nodes(dt_dev_pixelpipe_t *pipe)
void dt_dev_pixelpipe_cleanup(dt_dev_pixelpipe_t *pipe)
#define dt_dev_pixelpipe_synch_all(pipe)