diff --git a/.gitignore b/.gitignore index 82d5f81fbcfe..eb7e6203a75f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ tools/iop_deps.pdf cscope.out .*.swp .vscode/ +.idea diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000000..79b3c94830ba --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000000..94a25f7f4cb4 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/bauhaus/bauhaus.c b/src/bauhaus/bauhaus.c index 27f897a3fb33..94d378456b06 100644 --- a/src/bauhaus/bauhaus.c +++ b/src/bauhaus/bauhaus.c @@ -72,8 +72,7 @@ static void set_bg_normal(cairo_t *cr) static void set_bg_focus(cairo_t *cr) { - cairo_set_source_rgb(cr, darktable.bauhaus->bg_focus, darktable.bauhaus->bg_focus, - darktable.bauhaus->bg_focus); + cairo_set_source_rgb(cr, darktable.bauhaus->bg_focus, darktable.bauhaus->bg_focus, darktable.bauhaus->bg_focus); } static void set_text_color(cairo_t *cr, int sensitive) @@ -117,9 +116,12 @@ static int show_pango_text(cairo_t *cr, char *text, float x_pos, float y_pos, fl pango_layout_set_width(layout, (int)(PANGO_SCALE * max_width + 0.5f)); } - if(text) { + if(text) + { pango_layout_set_text(layout, text, -1); - } else { + } + else + { // length of -1 is not allowed with NULL string (wtf) pango_layout_set_text(layout, NULL, 0); } @@ -129,7 +131,7 @@ static int show_pango_text(cairo_t *cr, char *text, float x_pos, float y_pos, fl int pango_width, pango_height; pango_layout_get_size(layout, &pango_width, &pango_height); - float text_width = ((double)pango_width/PANGO_SCALE); + float text_width = ((double)pango_width / PANGO_SCALE); if(right_aligned) x_pos -= text_width; @@ -213,8 +215,8 @@ static float get_slider_line_offset(float pos, float scale, float x, float y, fl } // draw a loupe guideline for the quadratic zoom in in the slider interface: -static void draw_slider_line(cairo_t *cr, float pos, float off, float scale, const int width, - const int height, const int ht) +static void draw_slider_line(cairo_t *cr, float pos, float off, float scale, const int width, const int height, + const int ht) { // pos is normalized position [0,1], offset is on that scale. // ht is in pixels here @@ -310,8 +312,7 @@ static gboolean dt_bauhaus_popup_scroll(GtkWidget *widget, GdkEventScroll *event switch(darktable.bauhaus->current->type) { case DT_BAUHAUS_COMBOBOX: - if(dt_gui_get_scroll_unit_deltas(event, NULL, &delta_y)) - combobox_popup_scroll(delta_y); + if(dt_gui_get_scroll_unit_deltas(event, NULL, &delta_y)) combobox_popup_scroll(delta_y); break; case DT_BAUHAUS_SLIDER: break; @@ -499,11 +500,11 @@ void dt_bauhaus_init() GtkWidget *root_window = dt_ui_main_window(darktable.gui->ui); GtkStyleContext *ctx = gtk_style_context_new(); GtkWidgetPath *path; - path = gtk_widget_path_new (); + path = gtk_widget_path_new(); int pos = gtk_widget_path_append_type(path, GTK_TYPE_WIDGET); gtk_widget_path_iter_set_name(path, pos, "iop-plugin-ui"); gtk_style_context_set_path(ctx, path); - gtk_style_context_set_screen (ctx, gtk_widget_get_screen(root_window)); + gtk_style_context_set_screen(ctx, gtk_widget_get_screen(root_window)); GdkRGBA color, selected_color, bg_color, selected_bg_color; gtk_style_context_get_color(ctx, GTK_STATE_FLAG_NORMAL, &color); @@ -581,17 +582,18 @@ void dt_bauhaus_init() gtk_widget_set_can_focus(darktable.bauhaus->popup_area, TRUE); gtk_widget_add_events(darktable.bauhaus->popup_area, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_KEY_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK - | GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK); + | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + | GDK_KEY_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK + | GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK); - g_signal_connect(G_OBJECT(darktable.bauhaus->popup_window), "show", G_CALLBACK(dt_bauhaus_window_show), (gpointer)NULL); + g_signal_connect(G_OBJECT(darktable.bauhaus->popup_window), "show", G_CALLBACK(dt_bauhaus_window_show), + (gpointer)NULL); g_signal_connect(G_OBJECT(darktable.bauhaus->popup_area), "draw", G_CALLBACK(dt_bauhaus_popup_draw), (gpointer)NULL); g_signal_connect(G_OBJECT(darktable.bauhaus->popup_window), "motion-notify-event", G_CALLBACK(dt_bauhaus_window_motion_notify), (gpointer)NULL); - g_signal_connect(G_OBJECT(darktable.bauhaus->popup_window), "button-press-event", G_CALLBACK(dt_bauhaus_window_button_press), - (gpointer)NULL); + g_signal_connect(G_OBJECT(darktable.bauhaus->popup_window), "button-press-event", + G_CALLBACK(dt_bauhaus_window_button_press), (gpointer)NULL); g_signal_connect(G_OBJECT(darktable.bauhaus->popup_area), "motion-notify-event", G_CALLBACK(dt_bauhaus_popup_motion_notify), (gpointer)NULL); g_signal_connect(G_OBJECT(darktable.bauhaus->popup_area), "leave-notify-event", @@ -604,8 +606,8 @@ void dt_bauhaus_init() // G_CALLBACK (dt_bauhaus_popup_button_release), (gpointer)NULL); g_signal_connect(G_OBJECT(darktable.bauhaus->popup_area), "key-press-event", G_CALLBACK(dt_bauhaus_popup_key_press), (gpointer)NULL); - g_signal_connect(G_OBJECT(darktable.bauhaus->popup_area), "scroll-event", - G_CALLBACK(dt_bauhaus_popup_scroll), (gpointer)NULL); + g_signal_connect(G_OBJECT(darktable.bauhaus->popup_area), "scroll-event", G_CALLBACK(dt_bauhaus_popup_scroll), + (gpointer)NULL); } void dt_bauhaus_cleanup() @@ -650,9 +652,8 @@ static void dt_bauhaus_widget_init(dt_bauhaus_widget_t *w, dt_iop_module_t *self gtk_widget_set_size_request(GTK_WIDGET(w), -1, get_line_height()); gtk_widget_add_events(GTK_WIDGET(w), GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK - | GDK_SMOOTH_SCROLL_MASK); + | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK); g_signal_connect(G_OBJECT(w), "draw", G_CALLBACK(dt_bauhaus_draw), NULL); @@ -670,7 +671,7 @@ void dt_bauhaus_combobox_set_default(GtkWidget *widget, int def) d->defpos = def; } -void dt_bauhaus_slider_set_hard_min(GtkWidget* widget, float val) +void dt_bauhaus_slider_set_hard_min(GtkWidget *widget, float val) { dt_bauhaus_widget_t *w = DT_BAUHAUS_WIDGET(widget); dt_bauhaus_slider_data_t *d = &w->data.slider; @@ -679,25 +680,25 @@ void dt_bauhaus_slider_set_hard_min(GtkWidget* widget, float val) d->hard_min = rawval; d->min = MAX(d->min, d->hard_min); d->soft_min = MAX(d->soft_min, d->hard_min); - if(rawval > d->hard_max) dt_bauhaus_slider_set_hard_max(widget,val); + if(rawval > d->hard_max) dt_bauhaus_slider_set_hard_max(widget, val); if(pos < val) { - dt_bauhaus_slider_set_soft(widget,val); + dt_bauhaus_slider_set_soft(widget, val); } - else + else { - dt_bauhaus_slider_set_soft(widget,pos); + dt_bauhaus_slider_set_soft(widget, pos); } } -float dt_bauhaus_slider_get_hard_min(GtkWidget* widget) +float dt_bauhaus_slider_get_hard_min(GtkWidget *widget) { dt_bauhaus_widget_t *w = DT_BAUHAUS_WIDGET(widget); dt_bauhaus_slider_data_t *d = &w->data.slider; return d->callback(widget, d->hard_min, DT_BAUHAUS_GET); } -void dt_bauhaus_slider_set_hard_max(GtkWidget* widget, float val) +void dt_bauhaus_slider_set_hard_max(GtkWidget *widget, float val) { dt_bauhaus_widget_t *w = DT_BAUHAUS_WIDGET(widget); dt_bauhaus_slider_data_t *d = &w->data.slider; @@ -706,53 +707,54 @@ void dt_bauhaus_slider_set_hard_max(GtkWidget* widget, float val) d->hard_max = rawval; d->max = MIN(d->max, d->hard_max); d->soft_max = MIN(d->soft_max, d->hard_max); - if(rawval < d->hard_min) dt_bauhaus_slider_set_hard_min(widget,val); - if(pos > val) { + if(rawval < d->hard_min) dt_bauhaus_slider_set_hard_min(widget, val); + if(pos > val) + { - dt_bauhaus_slider_set_soft(widget,val); - } - else + dt_bauhaus_slider_set_soft(widget, val); + } + else { - dt_bauhaus_slider_set_soft(widget,pos); + dt_bauhaus_slider_set_soft(widget, pos); } } -float dt_bauhaus_slider_get_hard_max(GtkWidget* widget) +float dt_bauhaus_slider_get_hard_max(GtkWidget *widget) { dt_bauhaus_widget_t *w = DT_BAUHAUS_WIDGET(widget); dt_bauhaus_slider_data_t *d = &w->data.slider; return d->callback(widget, d->hard_max, DT_BAUHAUS_GET); } -void dt_bauhaus_slider_set_soft_min(GtkWidget* widget, float val) +void dt_bauhaus_slider_set_soft_min(GtkWidget *widget, float val) { dt_bauhaus_widget_t *w = DT_BAUHAUS_WIDGET(widget); dt_bauhaus_slider_data_t *d = &w->data.slider; float pos = dt_bauhaus_slider_get(widget); float rawval = d->callback(widget, val, DT_BAUHAUS_SET); d->soft_min = rawval; - d->hard_min = MIN(d->hard_min,d->soft_min); - d->min = d->soft_min; - if(rawval > d->soft_max) dt_bauhaus_slider_set_soft_max(widget,val); - if(rawval > d->hard_max) dt_bauhaus_slider_set_hard_max(widget,val); - if(pos < val) + d->hard_min = MIN(d->hard_min, d->soft_min); + d->min = d->soft_min; + if(rawval > d->soft_max) dt_bauhaus_slider_set_soft_max(widget, val); + if(rawval > d->hard_max) dt_bauhaus_slider_set_hard_max(widget, val); + if(pos < val) { - dt_bauhaus_slider_set_soft(widget,val); - } - else + dt_bauhaus_slider_set_soft(widget, val); + } + else { - dt_bauhaus_slider_set_soft(widget,pos); + dt_bauhaus_slider_set_soft(widget, pos); } } -float dt_bauhaus_slider_get_soft_min(GtkWidget* widget) +float dt_bauhaus_slider_get_soft_min(GtkWidget *widget) { dt_bauhaus_widget_t *w = DT_BAUHAUS_WIDGET(widget); dt_bauhaus_slider_data_t *d = &w->data.slider; return d->callback(widget, d->soft_min, DT_BAUHAUS_GET); } -void dt_bauhaus_slider_set_soft_max(GtkWidget* widget, float val) +void dt_bauhaus_slider_set_soft_max(GtkWidget *widget, float val) { dt_bauhaus_widget_t *w = DT_BAUHAUS_WIDGET(widget); dt_bauhaus_slider_data_t *d = &w->data.slider; @@ -760,17 +762,20 @@ void dt_bauhaus_slider_set_soft_max(GtkWidget* widget, float val) float rawval = d->callback(widget, val, DT_BAUHAUS_SET); d->soft_max = rawval; d->hard_max = MAX(d->soft_max, d->hard_max); - d->max = d->soft_max; - if(rawval < d->soft_min) dt_bauhaus_slider_set_soft_min(widget,val); - if(rawval < d->hard_min) dt_bauhaus_slider_set_hard_min(widget,val); - if(pos > val) { - dt_bauhaus_slider_set_soft(widget,val); - } else { - dt_bauhaus_slider_set_soft(widget,pos); + d->max = d->soft_max; + if(rawval < d->soft_min) dt_bauhaus_slider_set_soft_min(widget, val); + if(rawval < d->hard_min) dt_bauhaus_slider_set_hard_min(widget, val); + if(pos > val) + { + dt_bauhaus_slider_set_soft(widget, val); + } + else + { + dt_bauhaus_slider_set_soft(widget, pos); } } -float dt_bauhaus_slider_get_soft_max(GtkWidget* widget) +float dt_bauhaus_slider_get_soft_max(GtkWidget *widget) { dt_bauhaus_widget_t *w = DT_BAUHAUS_WIDGET(widget); dt_bauhaus_slider_data_t *d = &w->data.slider; @@ -825,8 +830,7 @@ void dt_bauhaus_widget_set_label(GtkWidget *widget, const char *section, const c { *val = 0; if(!g_list_find_custom(darktable.bauhaus->key_mod, mod, (GCompareFunc)strcmp)) - darktable.bauhaus->key_mod - = g_list_insert_sorted(darktable.bauhaus->key_mod, mod, (GCompareFunc)strcmp); + darktable.bauhaus->key_mod = g_list_insert_sorted(darktable.bauhaus->key_mod, mod, (GCompareFunc)strcmp); else g_free(mod); @@ -840,7 +844,7 @@ void dt_bauhaus_widget_set_label(GtkWidget *widget, const char *section, const c } } -const char* dt_bauhaus_widget_get_label(GtkWidget *widget) +const char *dt_bauhaus_widget_get_label(GtkWidget *widget) { dt_bauhaus_widget_t *w = DT_BAUHAUS_WIDGET(widget); return w->label; @@ -880,20 +884,20 @@ GtkWidget *dt_bauhaus_slider_new(dt_iop_module_t *self) return dt_bauhaus_slider_new_with_range(self, 0.0, 1.0, 0.1, 0.5, 3); } -GtkWidget *dt_bauhaus_slider_new_with_range(dt_iop_module_t *self, float min, float max, float step, - float defval, int digits) +GtkWidget *dt_bauhaus_slider_new_with_range(dt_iop_module_t *self, float min, float max, float step, float defval, + int digits) { return dt_bauhaus_slider_new_with_range_and_feedback(self, min, max, step, defval, digits, 1); } -GtkWidget *dt_bauhaus_slider_new_with_range_and_feedback(dt_iop_module_t *self, float min, float max, - float step, float defval, int digits, int feedback) +GtkWidget *dt_bauhaus_slider_new_with_range_and_feedback(dt_iop_module_t *self, float min, float max, float step, + float defval, int digits, int feedback) { dt_bauhaus_widget_t *w = DT_BAUHAUS_WIDGET(g_object_new(DT_BAUHAUS_WIDGET_TYPE, NULL)); - return dt_bauhaus_slider_from_widget(w,self, min, max, step, defval, digits, feedback); + return dt_bauhaus_slider_from_widget(w, self, min, max, step, defval, digits, feedback); } -GtkWidget *dt_bauhaus_slider_from_widget(dt_bauhaus_widget_t* w,dt_iop_module_t *self, float min, float max, - float step, float defval, int digits, int feedback) +GtkWidget *dt_bauhaus_slider_from_widget(dt_bauhaus_widget_t *w, dt_iop_module_t *self, float min, float max, + float step, float defval, int digits, int feedback) { w->type = DT_BAUHAUS_SLIDER; dt_bauhaus_widget_init(w, self); @@ -921,14 +925,12 @@ GtkWidget *dt_bauhaus_slider_from_widget(dt_bauhaus_widget_t* w,dt_iop_module_t gtk_widget_add_events(GTK_WIDGET(w), GDK_KEY_PRESS_MASK); gtk_widget_set_can_focus(GTK_WIDGET(w), TRUE); - g_signal_connect(G_OBJECT(w), "button-press-event", G_CALLBACK(dt_bauhaus_slider_button_press), - (gpointer)NULL); + g_signal_connect(G_OBJECT(w), "button-press-event", G_CALLBACK(dt_bauhaus_slider_button_press), (gpointer)NULL); g_signal_connect(G_OBJECT(w), "button-release-event", G_CALLBACK(dt_bauhaus_slider_button_release), (gpointer)NULL); g_signal_connect(G_OBJECT(w), "scroll-event", G_CALLBACK(dt_bauhaus_slider_scroll), (gpointer)NULL); g_signal_connect(G_OBJECT(w), "key-press-event", G_CALLBACK(dt_bauhaus_slider_key_press), (gpointer)NULL); - g_signal_connect(G_OBJECT(w), "motion-notify-event", G_CALLBACK(dt_bauhaus_slider_motion_notify), - (gpointer)NULL); + g_signal_connect(G_OBJECT(w), "motion-notify-event", G_CALLBACK(dt_bauhaus_slider_motion_notify), (gpointer)NULL); g_signal_connect(G_OBJECT(w), "destroy", G_CALLBACK(dt_bauhaus_slider_destroy), (gpointer)NULL); return GTK_WIDGET(w); } @@ -948,11 +950,11 @@ static void dt_bauhaus_combobox_destroy(dt_bauhaus_widget_t *widget, gpointer us GtkWidget *dt_bauhaus_combobox_new(dt_iop_module_t *self) { dt_bauhaus_widget_t *w = DT_BAUHAUS_WIDGET(g_object_new(DT_BAUHAUS_WIDGET_TYPE, NULL)); - dt_bauhaus_combobox_from_widget(w,self); + dt_bauhaus_combobox_from_widget(w, self); return GTK_WIDGET(w); } -void dt_bauhaus_combobox_from_widget(dt_bauhaus_widget_t* w,dt_iop_module_t *self) +void dt_bauhaus_combobox_from_widget(dt_bauhaus_widget_t *w, dt_iop_module_t *self) { w->type = DT_BAUHAUS_COMBOBOX; dt_bauhaus_widget_init(w, self); @@ -968,8 +970,7 @@ void dt_bauhaus_combobox_from_widget(dt_bauhaus_widget_t* w,dt_iop_module_t *sel gtk_widget_add_events(GTK_WIDGET(w), GDK_KEY_PRESS_MASK); gtk_widget_set_can_focus(GTK_WIDGET(w), TRUE); - g_signal_connect(G_OBJECT(w), "button-press-event", G_CALLBACK(dt_bauhaus_combobox_button_press), - (gpointer)NULL); + g_signal_connect(G_OBJECT(w), "button-press-event", G_CALLBACK(dt_bauhaus_combobox_button_press), (gpointer)NULL); g_signal_connect(G_OBJECT(w), "button-release-event", G_CALLBACK(dt_bauhaus_popup_button_release), (gpointer)NULL); g_signal_connect(G_OBJECT(w), "scroll-event", G_CALLBACK(dt_bauhaus_combobox_scroll), (gpointer)NULL); @@ -1033,7 +1034,7 @@ void dt_bauhaus_combobox_remove_at(GtkWidget *widget, int pos) d->num_labels--; } -void dt_bauhaus_combobox_insert(GtkWidget *widget, const char *text,int pos) +void dt_bauhaus_combobox_insert(GtkWidget *widget, const char *text, int pos) { dt_bauhaus_widget_t *w = DT_BAUHAUS_WIDGET(widget); if(w->type != DT_BAUHAUS_COMBOBOX) return; @@ -1185,8 +1186,7 @@ static void dt_bauhaus_draw_indicator(dt_bauhaus_widget_t *w, float pos, cairo_t const float r = 1.0f - (ht + 4.0f) / wd; set_indicator_color(cr, 1); #ifndef DT_BAUHAUS_OLD - cairo_translate(cr, (l + pos * (r - l)) * wd, - get_line_height() * (darktable.bauhaus->label_font_size + 0.25f)); + cairo_translate(cr, (l + pos * (r - l)) * wd, get_line_height() * (darktable.bauhaus->label_font_size + 0.25f)); cairo_scale(cr, 1.0f, -1.0f); draw_equilateral_triangle(cr, ht * get_marker_size()); cairo_fill_preserve(cr); @@ -1413,9 +1413,9 @@ static void dt_bauhaus_widget_accept(dt_bauhaus_widget_t *w) case DT_BAUHAUS_SLIDER: { dt_bauhaus_slider_data_t *d = &w->data.slider; - const float mouse_off = get_slider_line_offset( - d->oldpos, d->scale, darktable.bauhaus->end_mouse_x / width, - darktable.bauhaus->end_mouse_y / height, allocation.height / (float)height, allocation.width); + const float mouse_off = get_slider_line_offset(d->oldpos, d->scale, darktable.bauhaus->end_mouse_x / width, + darktable.bauhaus->end_mouse_y / height, + allocation.height / (float)height, allocation.width); dt_bauhaus_slider_set_normalized(w, d->oldpos + mouse_off); d->oldpos = d->pos; break; @@ -1667,8 +1667,7 @@ static gboolean dt_bauhaus_draw(GtkWidget *widget, cairo_t *crf, gpointer user_d case DT_BAUHAUS_COMBOBOX: { // draw label and quad area at right end - float label_width - = show_pango_text(cr, w->label, 2, 0, 0, FALSE, gtk_widget_is_sensitive(widget), FALSE); + float label_width = show_pango_text(cr, w->label, 2, 0, 0, FALSE, gtk_widget_is_sensitive(widget), FALSE); dt_bauhaus_draw_quad(w, cr); if(gtk_widget_is_sensitive(widget)) @@ -1676,8 +1675,8 @@ static gboolean dt_bauhaus_draw(GtkWidget *widget, cairo_t *crf, gpointer user_d dt_bauhaus_combobox_data_t *d = &w->data.combobox; gchar *text = d->text; if(d->active >= 0) text = (gchar *)g_list_nth_data(d->labels, d->active); - show_pango_text(cr, text, width - 4 - height, 0, width - 4 - height - label_width - height, TRUE, - TRUE, FALSE); + show_pango_text(cr, text, width - 4 - height, 0, width - 4 - height - label_width - height, TRUE, TRUE, + FALSE); } break; } @@ -1913,8 +1912,10 @@ static gboolean dt_bauhaus_combobox_button_press(GtkWidget *widget, GdkEventButt gtk_widget_get_allocation(widget, &allocation); dt_bauhaus_widget_t *w = (dt_bauhaus_widget_t *)widget; if(w->type != DT_BAUHAUS_COMBOBOX) return FALSE; - if(w->module) dt_iop_request_focus(w->module); - else gtk_widget_grab_focus(GTK_WIDGET(w)); + if(w->module) + dt_iop_request_focus(w->module); + else + gtk_widget_grab_focus(GTK_WIDGET(w)); GtkAllocation tmp; gtk_widget_get_allocation(GTK_WIDGET(w), &tmp); dt_bauhaus_combobox_data_t *d = &w->data.combobox; @@ -1959,7 +1960,8 @@ float dt_bauhaus_slider_get(GtkWidget *widget) dt_bauhaus_widget_t *w = (dt_bauhaus_widget_t *)DT_BAUHAUS_WIDGET(widget); if(w->type != DT_BAUHAUS_SLIDER) return -1.0f; dt_bauhaus_slider_data_t *d = &w->data.slider; - if(d->max == d->min) { + if(d->max == d->min) + { return d->max; } float rawval = d->min + d->pos * (d->max - d->min); @@ -2044,7 +2046,8 @@ void dt_bauhaus_slider_set_format(GtkWidget *widget, const char *format) g_strlcpy(d->format, format, sizeof(d->format)); } -void dt_bauhaus_slider_set_callback(GtkWidget *widget, float (*callback)(GtkWidget *self, float value, dt_bauhaus_callback_t dir)) +void dt_bauhaus_slider_set_callback(GtkWidget *widget, + float (*callback)(GtkWidget *self, float value, dt_bauhaus_callback_t dir)) { dt_bauhaus_widget_t *w = (dt_bauhaus_widget_t *)DT_BAUHAUS_WIDGET(widget); if(w->type != DT_BAUHAUS_SLIDER) return; @@ -2167,9 +2170,8 @@ static gboolean dt_bauhaus_popup_key_press(GtkWidget *widget, GdkEventKey *event else if(darktable.bauhaus->keys_cnt > 0 && (event->keyval == GDK_KEY_BackSpace || event->keyval == GDK_KEY_Delete)) { - darktable.bauhaus->keys_cnt - -= (darktable.bauhaus->keys + darktable.bauhaus->keys_cnt) - - g_utf8_prev_char(darktable.bauhaus->keys + darktable.bauhaus->keys_cnt); + darktable.bauhaus->keys_cnt -= (darktable.bauhaus->keys + darktable.bauhaus->keys_cnt) + - g_utf8_prev_char(darktable.bauhaus->keys + darktable.bauhaus->keys_cnt); darktable.bauhaus->keys[darktable.bauhaus->keys_cnt] = 0; gtk_widget_queue_draw(darktable.bauhaus->popup_area); } @@ -2226,8 +2228,10 @@ static gboolean dt_bauhaus_slider_button_press(GtkWidget *widget, GdkEventButton GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); dt_bauhaus_widget_t *w = (dt_bauhaus_widget_t *)widget; - if(w->module) dt_iop_request_focus(w->module); - else gtk_widget_grab_focus(GTK_WIDGET(w)); + if(w->module) + dt_iop_request_focus(w->module); + else + gtk_widget_grab_focus(GTK_WIDGET(w)); GtkAllocation tmp; gtk_widget_get_allocation(GTK_WIDGET(w), &tmp); if(w->quad_paint && (event->x > allocation.width - allocation.height)) diff --git a/src/bauhaus/bauhaus.h b/src/bauhaus/bauhaus.h index 392a0524842b..9686c66e7d86 100644 --- a/src/bauhaus/bauhaus.h +++ b/src/bauhaus/bauhaus.h @@ -39,7 +39,7 @@ #define DT_BAUHAUS_WIDGET_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST((obj), DT_BAUHAUS_WIDGET, DtBauhausWidgetClass)) #define DT_IS_BAUHAUS_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), DT_BAUHAUS_WIDGET_TYPE)) #define DT_IS_BAUHAUS_WIDGET_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((obj), DT_BAUHAUS_WIDGET_TYPE)) -#define DT_BAUHAUS_WIDGET_GET_CLASS \ +#define DT_BAUHAUS_WIDGET_GET_CLASS \ (G_TYPE_INSTANCE_GET_CLASS((obj), DT_BAUHAUS_WIDGET_TYPE, DtBauhausWidgetClass)) extern GType DT_BAUHAUS_WIDGET_TYPE; @@ -82,10 +82,10 @@ typedef struct dt_bauhaus_slider_data_t char format[24]; // numeric value is printed with this string - int is_dragging; // indicates is mouse is dragging slider - int is_changed; // indicates new data - guint timeout_handle; // used to store id of timeout routine - float (*callback)(GtkWidget*, float, dt_bauhaus_callback_t); // callback function + int is_dragging; // indicates is mouse is dragging slider + int is_changed; // indicates new data + guint timeout_handle; // used to store id of timeout routine + float (*callback)(GtkWidget *, float, dt_bauhaus_callback_t); // callback function } dt_bauhaus_slider_data_t; typedef enum dt_bauhaus_combobox_alignment_t @@ -227,7 +227,7 @@ void dt_bauhaus_cleanup(); // common functions: // set the label text: void dt_bauhaus_widget_set_label(GtkWidget *w, const char *section, const char *label); -const char* dt_bauhaus_widget_get_label(GtkWidget *w); +const char *dt_bauhaus_widget_get_label(GtkWidget *w); // attach a custom painted quad to the space at the right side (overwriting the default icon if any): void dt_bauhaus_widget_set_quad_paint(GtkWidget *w, dt_bauhaus_quad_paint_f f, int paint_flags); // make this quad a toggle button: @@ -238,27 +238,27 @@ void dt_bauhaus_show_popup(dt_bauhaus_widget_t *w); // slider: GtkWidget *dt_bauhaus_slider_new(dt_iop_module_t *self); -GtkWidget *dt_bauhaus_slider_new_with_range(dt_iop_module_t *self, float min, float max, float step, - float defval, int digits); -GtkWidget *dt_bauhaus_slider_new_with_range_and_feedback(dt_iop_module_t *self, float min, float max, - float step, float defval, int digits, int feedback); +GtkWidget *dt_bauhaus_slider_new_with_range(dt_iop_module_t *self, float min, float max, float step, float defval, + int digits); +GtkWidget *dt_bauhaus_slider_new_with_range_and_feedback(dt_iop_module_t *self, float min, float max, float step, + float defval, int digits, int feedback); -GtkWidget *dt_bauhaus_slider_from_widget(dt_bauhaus_widget_t* widget, dt_iop_module_t *self, float min, float max, - float step, float defval, int digits, int feedback); +GtkWidget *dt_bauhaus_slider_from_widget(dt_bauhaus_widget_t *widget, dt_iop_module_t *self, float min, float max, + float step, float defval, int digits, int feedback); // outside doesn't see the real type, we cast it internally. void dt_bauhaus_slider_set(GtkWidget *w, float pos); void dt_bauhaus_slider_set_soft(GtkWidget *w, float pos); float dt_bauhaus_slider_get(GtkWidget *w); -void dt_bauhaus_slider_set_soft_min(GtkWidget* w, float val); -float dt_bauhaus_slider_get_soft_min(GtkWidget* w); -void dt_bauhaus_slider_set_soft_max(GtkWidget* w, float val); -float dt_bauhaus_slider_get_soft_max(GtkWidget* w); +void dt_bauhaus_slider_set_soft_min(GtkWidget *w, float val); +float dt_bauhaus_slider_get_soft_min(GtkWidget *w); +void dt_bauhaus_slider_set_soft_max(GtkWidget *w, float val); +float dt_bauhaus_slider_get_soft_max(GtkWidget *w); -void dt_bauhaus_slider_set_hard_min(GtkWidget* w, float val); -float dt_bauhaus_slider_get_hard_min(GtkWidget* w); -void dt_bauhaus_slider_set_hard_max(GtkWidget* w, float val); -float dt_bauhaus_slider_get_hard_max(GtkWidget* w); +void dt_bauhaus_slider_set_hard_min(GtkWidget *w, float val); +float dt_bauhaus_slider_get_hard_min(GtkWidget *w); +void dt_bauhaus_slider_set_hard_max(GtkWidget *w, float val); +float dt_bauhaus_slider_get_hard_max(GtkWidget *w); void dt_bauhaus_slider_set_digits(GtkWidget *w, int val); int dt_bauhaus_slider_get_digits(GtkWidget *w); @@ -271,17 +271,18 @@ void dt_bauhaus_slider_set_stop(GtkWidget *widget, float stop, float r, float g, void dt_bauhaus_slider_clear_stops(GtkWidget *widget); void dt_bauhaus_slider_set_default(GtkWidget *widget, float def); void dt_bauhaus_slider_enable_soft_boundaries(GtkWidget *widget, float hard_min, float hard_max); -void dt_bauhaus_slider_set_callback(GtkWidget *widget, float (*callback)(GtkWidget *self, float value, dt_bauhaus_callback_t dir)); +void dt_bauhaus_slider_set_callback(GtkWidget *widget, + float (*callback)(GtkWidget *self, float value, dt_bauhaus_callback_t dir)); // combobox: -void dt_bauhaus_combobox_from_widget(dt_bauhaus_widget_t* widget,dt_iop_module_t *self); +void dt_bauhaus_combobox_from_widget(dt_bauhaus_widget_t *widget, dt_iop_module_t *self); GtkWidget *dt_bauhaus_combobox_new(dt_iop_module_t *self); void dt_bauhaus_combobox_add(GtkWidget *widget, const char *text); void dt_bauhaus_combobox_add_aligned(GtkWidget *widget, const char *text, dt_bauhaus_combobox_alignment_t align); void dt_bauhaus_combobox_set(GtkWidget *w, int pos); void dt_bauhaus_combobox_remove_at(GtkWidget *widget, int pos); -void dt_bauhaus_combobox_insert(GtkWidget *widget, const char *text,int pos); +void dt_bauhaus_combobox_insert(GtkWidget *widget, const char *text, int pos); int dt_bauhaus_combobox_length(GtkWidget *widget); void dt_bauhaus_combobox_set_editable(GtkWidget *w, int editable); int dt_bauhaus_combobox_get_editable(GtkWidget *w); diff --git a/src/chart/cairo.c b/src/chart/cairo.c index acc27171dd19..6ad89fea0032 100644 --- a/src/chart/cairo.c +++ b/src/chart/cairo.c @@ -127,7 +127,8 @@ void draw_color_boxes_outline(cairo_t *cr, point_t *bb, chart_t *chart) _draw_boxes(cr, bb, chart->box_table); } -void draw_color_boxes_inside(cairo_t *cr, point_t *bb, chart_t *chart, float shrink, float line_width, gboolean colored) +void draw_color_boxes_inside(cairo_t *cr, point_t *bb, chart_t *chart, float shrink, float line_width, + gboolean colored) { GHashTableIter table_iter; gpointer key, value; diff --git a/src/chart/colorchart.c b/src/chart/colorchart.c index 441424f15924..2e5ffa53ef72 100644 --- a/src/chart/colorchart.c +++ b/src/chart/colorchart.c @@ -27,7 +27,8 @@ #define MAX_LINE_LENGTH 512 -typedef enum parser_state_t { +typedef enum parser_state_t +{ BLOCK_NONE = 0, BLOCK_BOXES, BLOCK_BOX_SHRINK, diff --git a/src/chart/main.c b/src/chart/main.c index 472092fb472d..849ed80e1ee9 100644 --- a/src/chart/main.c +++ b/src/chart/main.c @@ -604,8 +604,7 @@ static void export_raw(dt_lut_t *self, char *filename, char *name, char *descrip GList *patch_names = NULL; char *gray_ramp_key = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(self->gray_ramp)); - if(gray_ramp_key) - patch_names = g_hash_table_lookup(self->chart->patch_sets, gray_ramp_key); + if(gray_ramp_key) patch_names = g_hash_table_lookup(self->chart->patch_sets, gray_ramp_key); const int num_gray = g_list_length(patch_names); @@ -708,13 +707,15 @@ static void add_hdr_patches(int *N, double **target_L, double **target_a, double for(int j = 0; j < *N; j++) { - if((*target_L)[j] == 100.0 && (*target_a)[j] == 0.0 && (*target_b)[j] == 0.0 && (*colorchecker_Lab)[j * 3] == 100.0 - && (*colorchecker_Lab)[j * 3 + 1] == 0.0 && (*colorchecker_Lab)[j * 3 + 2] == 0.0) + if((*target_L)[j] == 100.0 && (*target_a)[j] == 0.0 && (*target_b)[j] == 0.0 + && (*colorchecker_Lab)[j * 3] == 100.0 && (*colorchecker_Lab)[j * 3 + 1] == 0.0 + && (*colorchecker_Lab)[j * 3 + 2] == 0.0) { need_hdr00 = FALSE; } - else if((*target_L)[j] == 200.0 && (*target_a)[j] == 0.0 && (*target_b)[j] == 0.0 && (*colorchecker_Lab)[j * 3] == 200.0 - && (*colorchecker_Lab)[j * 3 + 1] == 0.0 && (*colorchecker_Lab)[j * 3 + 2] == 0.0) + else if((*target_L)[j] == 200.0 && (*target_a)[j] == 0.0 && (*target_b)[j] == 0.0 + && (*colorchecker_Lab)[j * 3] == 200.0 && (*colorchecker_Lab)[j * 3 + 1] == 0.0 + && (*colorchecker_Lab)[j * 3 + 2] == 0.0) { need_hdr01 = FALSE; } @@ -970,14 +971,14 @@ static void process_data(dt_lut_t *self, double *target_L, double *target_a, dou double avgerr, maxerr; sparsity = thinplate_match(&tonecurve, 3, N, colorchecker_Lab, target, sparsity, perm, coeff, &avgerr, &maxerr); - if (self->result_label != NULL) + if(self->result_label != NULL) { // TODO: is the rank interesting, too? char *result_string = g_strdup_printf(_("average dE: %.02f\nmax dE: %.02f"), avgerr, maxerr); gtk_label_set_text(GTK_LABEL(self->result_label), result_string); g_free(result_string); } - + free(coeff_b); free(coeff_a); free(coeff_L); @@ -1539,21 +1540,19 @@ static void get_corners(point_t *bb, box_t *box, point_t *corners) static void get_pixel_region(const image_t *const image, const point_t *const corners, int *x_start, int *y_start, int *x_end, int *y_end) { - *x_start = CLAMP((int)(MIN(corners[TOP_LEFT].x, - MIN(corners[TOP_RIGHT].x, MIN(corners[BOTTOM_RIGHT].x, corners[BOTTOM_LEFT].x))) - + 0.5), - 0, image->width); + *x_start + = CLAMP((int)(MIN(corners[TOP_LEFT].x, + MIN(corners[TOP_RIGHT].x, MIN(corners[BOTTOM_RIGHT].x, corners[BOTTOM_LEFT].x))) + 0.5), + 0, image->width); *x_end = CLAMP((int)(MAX(corners[TOP_LEFT].x, - MAX(corners[TOP_RIGHT].x, MAX(corners[BOTTOM_RIGHT].x, corners[BOTTOM_LEFT].x))) - + 0.5), + MAX(corners[TOP_RIGHT].x, MAX(corners[BOTTOM_RIGHT].x, corners[BOTTOM_LEFT].x))) + 0.5), 0, image->width); - *y_start = CLAMP((int)(MIN(corners[TOP_LEFT].y, - MIN(corners[TOP_RIGHT].y, MIN(corners[BOTTOM_RIGHT].y, corners[BOTTOM_LEFT].y))) - + 0.5), - 0, image->height); + *y_start + = CLAMP((int)(MIN(corners[TOP_LEFT].y, + MIN(corners[TOP_RIGHT].y, MIN(corners[BOTTOM_RIGHT].y, corners[BOTTOM_LEFT].y))) + 0.5), + 0, image->height); *y_end = CLAMP((int)(MAX(corners[TOP_LEFT].y, - MAX(corners[TOP_RIGHT].y, MAX(corners[BOTTOM_RIGHT].y, corners[BOTTOM_LEFT].y))) - + 0.5), + MAX(corners[TOP_RIGHT].y, MAX(corners[BOTTOM_RIGHT].y, corners[BOTTOM_LEFT].y))) + 0.5), 0, image->height); } @@ -1675,7 +1674,8 @@ static int main_gui(dt_lut_t *self, int argc, char *argv[]) } static int parse_csv(dt_lut_t *self, const char *filename, double **target_L_ptr, double **target_a_ptr, - double **target_b_ptr, double **source_Lab_ptr, int *num_gray, char **name, char **description) + double **target_b_ptr, double **source_Lab_ptr, int *num_gray, char **name, + char **description) { *target_L_ptr = NULL; *target_a_ptr = NULL; @@ -1698,7 +1698,7 @@ static int parse_csv(dt_lut_t *self, const char *filename, double **target_L_ptr } // header lines - char key[16] = {0}, value[256] = {0}; + char key[16] = { 0 }, value[256] = { 0 }; int unused = fscanf(f, "%15[^;];%255[^\n]\n", key, value); if(g_strcmp0(key, "name") || unused == EOF) { diff --git a/src/chart/pfm.c b/src/chart/pfm.c index 7fb64e65be39..6b58b73747bf 100644 --- a/src/chart/pfm.c +++ b/src/chart/pfm.c @@ -81,7 +81,8 @@ float *read_pfm(const char *filename, int *wd, int *ht) for(size_t i = (size_t)width * height; i > 0; i--) for(int c = 0; c < 3; c++) { - union { + union + { float f; guint32 i; } v; @@ -95,7 +96,8 @@ float *read_pfm(const char *filename, int *wd, int *ht) for(size_t j = 0; j < height; j++) for(size_t i = 0; i < width; i++) { - union { + union + { float f; guint32 i; } v; diff --git a/src/chart/thinplate.c b/src/chart/thinplate.c index 6668e606b4af..ed3ca00bbfe0 100644 --- a/src/chart/thinplate.c +++ b/src/chart/thinplate.c @@ -38,7 +38,11 @@ // very fast, very approximate static inline float __attribute__((__unused__)) fasterlog(float x) { - union { float f; uint32_t i; } vx = { x }; + union + { + float f; + uint32_t i; + } vx = { x }; float y = vx.i; y *= 8.2629582881927490e-8f; return y - 87.989971088f; @@ -55,14 +59,9 @@ static inline double thinplate_kernel(const double *x, const double *y) // return r * r * fasterlog(MAX(1e-8f, r)); } -static inline double compute_error( - const tonecurve_t *c, - const double **target, - const double *residual_L, - const double *residual_a, - const double *residual_b, - const int wd, - double *maxerr) +static inline double compute_error(const tonecurve_t *c, const double **target, const double *residual_L, + const double *residual_a, const double *residual_b, const int wd, + double *maxerr) { // compute error: double err = 0.0; @@ -78,8 +77,9 @@ static inline double compute_error( const double localerr = dt_colorspaces_deltaE_2000(Lab0, Lab1); err += localerr; #else - const double localerr = sqrt(residual_L[i] * residual_L[i] + residual_a[i] * residual_a[i] + residual_b[i] * residual_b[i]); - err += localerr/wd; + const double localerr + = sqrt(residual_L[i] * residual_L[i] + residual_a[i] * residual_a[i] + residual_b[i] * residual_b[i]); + err += localerr / wd; #endif merr = MAX(merr, localerr); @@ -150,8 +150,8 @@ int thinplate_match(const tonecurve_t *curve, // tonecurve to apply after this ( int *permutation, // pointing to original order of points, to identify correct output coeff double **coeff, // output coefficient arrays for each dimension, ordered according to // permutation[dim] - double *avgerr, // average error - double *maxerr) // max error + double *avgerr, // average error + double *maxerr) // max error { if(avgerr) *avgerr = 0.0; if(maxerr) *maxerr = 0.0; @@ -306,7 +306,7 @@ int thinplate_match(const tonecurve_t *curve, // tonecurve to apply after this ( for(int i = 0; i < sparsity; i++) for(int j = 0; j < wd; j++) As[j * S + i] = A[j * wd + permutation[i]]; - if(solve(As, w, v, b[ch], coeff[ch], wd, sparsity-1, S)) + if(solve(As, w, v, b[ch], coeff[ch], wd, sparsity - 1, S)) { free(r); free(b); @@ -357,7 +357,7 @@ int thinplate_match(const tonecurve_t *curve, // tonecurve to apply after this ( fprintf(stderr, "replacing %d <- %d\n", mincol, maxcol); // replace column permutation[mincol] = maxcol; - // reset norm[] of discarded column to something > 0 +// reset norm[] of discarded column to something > 0 #ifdef EXACT norm[mincol] = 1.0; #else @@ -372,7 +372,7 @@ int thinplate_match(const tonecurve_t *curve, // tonecurve to apply after this ( #ifdef EXACT double err = 1. / maxdot; #else - const int sp = MIN(sparsity, S-1); // need to fix up for replacement + const int sp = MIN(sparsity, S - 1); // need to fix up for replacement // solve linear least squares for sparse c for every output channel: for(int ch = 0; ch < dim; ch++) { @@ -408,15 +408,14 @@ int thinplate_match(const tonecurve_t *curve, // tonecurve to apply after this ( #endif // residual is max CIE76 delta E now // everything < 2 is usually considired a very good approximation: - if(patches == S-4) + if(patches == S - 4) { if(avgerr) *avgerr = err; if(maxerr) *maxerr = merr; fprintf(stderr, "rank %d/%d avg DE %g max DE %g\n", sp + 1, patches, err, merr); } - if(s >= S && err >= olderr) - fprintf(stderr, "error increased!\n"); - // return sparsity + 1; + if(s >= S && err >= olderr) fprintf(stderr, "error increased!\n"); + // return sparsity + 1; // if(err < 2.0) return sparsity+1; olderr = err; } diff --git a/src/chart/thinplate.h b/src/chart/thinplate.h index bf33e8bbafad..f997f4241778 100644 --- a/src/chart/thinplate.h +++ b/src/chart/thinplate.h @@ -29,8 +29,8 @@ int thinplate_match(const tonecurve_t *curve, // tonecurve to apply after this ( int *permutation, // pointing to original order of points, to identify correct output coeff double **coeff, // output coefficient arrays for each dimension, ordered according to // permutation[dim] - double *avgerr, // average error - double *maxerr); // max error + double *avgerr, // average error + double *maxerr); // max error float thinplate_color_pos(float L, float a, float b); diff --git a/src/cli/main.c b/src/cli/main.c index 7fb32f8a9c0b..56a1589b4058 100644 --- a/src/cli/main.c +++ b/src/cli/main.c @@ -52,7 +52,8 @@ static void usage(const char *progname) { fprintf(stderr, "usage: %s [] <output file> [--width <max width>,--height <max " - "height>,--bpp <bpp>,--hq <0|1|true|false>,--upscale <0|1|true|false>,--verbose] [--core <darktable options>]\n", + "height>,--bpp <bpp>,--hq <0|1|true|false>,--upscale <0|1|true|false>,--verbose] [--core " + "<darktable options>]\n", progname); } @@ -102,8 +103,8 @@ int main(int argc, char *arg[]) { k++; bpp = MAX(atoi(arg[k]), 0); - fprintf(stderr, "%s %d\n", - _("TODO: sorry, due to API restrictions we currently cannot set the BPP to"), bpp); + fprintf(stderr, "%s %d\n", _("TODO: sorry, due to API restrictions we currently cannot set the BPP to"), + bpp); } else if(!strcmp(arg[k], "--hq") && argc > k + 1) { @@ -128,7 +129,7 @@ int main(int argc, char *arg[]) if(!g_strcmp0(str, "0") || !g_strcmp0(str, "FALSE")) upscale = FALSE; else if(!g_strcmp0(str, "1") || !g_strcmp0(str, "TRUE")) - upscale= TRUE; + upscale = TRUE; else { fprintf(stderr, "%s: %s\n", _("unknown option for --upscale"), arg[k]); @@ -290,9 +291,8 @@ int main(int argc, char *arg[]) storage = dt_imageio_get_storage_by_name("disk"); // only exporting to disk makes sense if(storage == NULL) { - fprintf( - stderr, "%s\n", - _("cannot find disk storage module. please check your installation, something seems to be broken.")); + fprintf(stderr, "%s\n", + _("cannot find disk storage module. please check your installation, something seems to be broken.")); free(m_arg); exit(1); } diff --git a/src/cltest/main.c b/src/cltest/main.c index c307b689729c..d08e637065c0 100644 --- a/src/cltest/main.c +++ b/src/cltest/main.c @@ -28,14 +28,12 @@ int main(int argc, char *arg[]) { int result = 1; // only used to force-init opencl, so we want these options: - char *m_arg[] = { "-d", "opencl", "--library", ":memory:"}; + char *m_arg[] = { "-d", "opencl", "--library", ":memory:" }; const int m_argc = sizeof(m_arg) / sizeof(m_arg[0]); char **argv = malloc(argc * sizeof(arg[0]) + sizeof(m_arg)); if(!argv) goto end; - for(int i = 0; i < argc; i++) - argv[i] = arg[i]; - for(int i = 0; i < m_argc; i++) - argv[argc + i] = m_arg[i]; + for(int i = 0; i < argc; i++) argv[i] = arg[i]; + for(int i = 0; i < m_argc; i++) argv[argc + i] = m_arg[i]; argc += m_argc; if(dt_init(argc, argv, FALSE, FALSE, NULL)) goto end; dt_cleanup(); diff --git a/src/cmstest/main.c b/src/cmstest/main.c index 7e9c0223a708..d03e6dc7185d 100644 --- a/src/cmstest/main.c +++ b/src/cmstest/main.c @@ -121,8 +121,7 @@ static gint sort_monitor_list(gconstpointer a, gconstpointer b) monitor_t *monitor_a = (monitor_t *)a; monitor_t *monitor_b = (monitor_t *)b; - if(monitor_a->screen != monitor_b->screen) - return monitor_a->screen - monitor_b->screen; + if(monitor_a->screen != monitor_b->screen) return monitor_a->screen - monitor_b->screen; if(monitor_a->is_primary) return -1; if(monitor_b->is_primary) return 1; @@ -167,8 +166,9 @@ int main(int argc __attribute__((unused)), char *arg[] __attribute__((unused))) { if((pp = g_strstr_len(pp, -1, ".")) == NULL) g_strlcat(disp_name, ".0", sizeof(disp_name)); - else { - if (pp[1] == '\0') + else + { + if(pp[1] == '\0') g_strlcat(disp_name, "0", sizeof(disp_name)); else { @@ -205,8 +205,7 @@ int main(int argc __attribute__((unused)), char *arg[] __attribute__((unused))) for(int crtc = 0; crtc < rsrc->ncrtc; crtc++) { XRRCrtcInfo *crtc_info = XRRGetCrtcInfo(display, rsrc, rsrc->crtcs[crtc]); - if(!crtc_info) - continue; + if(!crtc_info) continue; if(crtc_info->mode != None && crtc_info->noutput > 0) { @@ -223,7 +222,7 @@ int main(int argc __attribute__((unused)), char *arg[] __attribute__((unused))) XRRFreeCrtcInfo(crtc_info); } } - if (primary_id == -1) + if(primary_id == -1) printf("couldn't locate primary CRTC!\n"); else { @@ -306,7 +305,7 @@ int main(int argc __attribute__((unused)), char *arg[] __attribute__((unused))) monitor->name = g_strdup(output_info->name); monitor_list = g_list_append(monitor_list, monitor); -end: + end: XRRFreeCrtcInfo(crtc_info); XRRFreeOutputInfo(output_info); } @@ -408,11 +407,9 @@ int main(int argc __attribute__((unused)), char *arg[] __attribute__((unused))) message = "the X atom seems to be missing"; any_unprofiled_monitor = TRUE; } -#else // HAVE_COLORD - char *colord_filename = monitor->colord_filename ? monitor->colord_filename : "(none)", - *colord_description; - if(monitor->colord_filename == NULL - || g_file_test(monitor->colord_filename, G_FILE_TEST_IS_REGULAR) == FALSE) +#else // HAVE_COLORD + char *colord_filename = monitor->colord_filename ? monitor->colord_filename : "(none)", *colord_description; + if(monitor->colord_filename == NULL || g_file_test(monitor->colord_filename, G_FILE_TEST_IS_REGULAR) == FALSE) { colord_description = g_strdup("(file not found)"); if(monitor->x_atom_length > 0) @@ -431,8 +428,8 @@ int main(int argc __attribute__((unused)), char *arg[] __attribute__((unused))) unsigned char *tmp_data = NULL; size_t size = 0; g_file_get_contents(monitor->colord_filename, (gchar **)&tmp_data, &size, NULL); - gboolean profiles_equal = (size == monitor->x_atom_length - && (size == 0 || memcmp(monitor->x_atom_data, tmp_data, size) == 0)); + gboolean profiles_equal + = (size == monitor->x_atom_length && (size == 0 || memcmp(monitor->x_atom_data, tmp_data, size) == 0)); if(!profiles_equal) any_profile_mismatch = TRUE; if(size == 0 && monitor->x_atom_length == 0) any_unprofiled_monitor = TRUE; message = profiles_equal ? "the X atom and colord returned the same profile" @@ -457,7 +454,6 @@ int main(int argc __attribute__((unused)), char *arg[] __attribute__((unused))) #ifdef HAVE_COLORD g_free(colord_description); #endif - } diff --git a/src/common/bilateral.c b/src/common/bilateral.c index 2708eea8406c..a444a12be7b6 100644 --- a/src/common/bilateral.c +++ b/src/common/bilateral.c @@ -48,10 +48,7 @@ size_t dt_bilateral_memory_use(const int width, // width of input image } // for the CPU path this is just an alias as no additional temp buffer is needed -size_t dt_bilateral_memory_use2(const int width, - const int height, - const float sigma_s, - const float sigma_r) +size_t dt_bilateral_memory_use2(const int width, const int height, const float sigma_s, const float sigma_r) { return dt_bilateral_memory_use(width, height, sigma_s, sigma_r); } @@ -72,10 +69,7 @@ size_t dt_bilateral_singlebuffer_size(const int width, // width of input ima } // for the CPU path this is just an alias as no additional temp buffer is needed -size_t dt_bilateral_singlebuffer_size2(const int width, - const int height, - const float sigma_s, - const float sigma_r) +size_t dt_bilateral_singlebuffer_size2(const int width, const int height, const float sigma_s, const float sigma_r) { return dt_bilateral_singlebuffer_size(width, height, sigma_s, sigma_r); } @@ -224,8 +218,7 @@ static void blur_line(float *buf, const int offset1, const int offset2, const in for(int i = 2; i < size3 - 2; i++) { const float tmp3 = buf[index]; - buf[index] - = buf[index] * w0 + w1 * (buf[index + offset3] + tmp2) + w2 * (buf[index + 2 * offset3] + tmp1); + buf[index] = buf[index] * w0 + w1 * (buf[index + offset3] + tmp2) + w2 * (buf[index + 2 * offset3] + tmp1); index += offset3; tmp1 = tmp2; tmp2 = tmp3; diff --git a/src/common/bilateralcl.c b/src/common/bilateralcl.c index 6dc940819757..73d165203078 100644 --- a/src/common/bilateralcl.c +++ b/src/common/bilateralcl.c @@ -70,10 +70,7 @@ size_t dt_bilateral_memory_use(const int width, // width of input image // modules that want to use dt_bilateral_slice_to_output_cl() ought to take this one; // takes account of an additional temp buffer needed in the OpenCL code path -size_t dt_bilateral_memory_use2(const int width, - const int height, - const float sigma_s, - const float sigma_r) +size_t dt_bilateral_memory_use2(const int width, const int height, const float sigma_s, const float sigma_r) { return dt_bilateral_memory_use(width, height, sigma_s, sigma_r) + (size_t)width * height * 4 * sizeof(float); } @@ -96,12 +93,10 @@ size_t dt_bilateral_singlebuffer_size(const int width, // width of input ima // modules that want to use dt_bilateral_slice_to_output_cl() ought to take this one; // takes account of an additional temp buffer needed in the OpenCL code path -size_t dt_bilateral_singlebuffer_size2(const int width, - const int height, - const float sigma_s, - const float sigma_r) +size_t dt_bilateral_singlebuffer_size2(const int width, const int height, const float sigma_s, const float sigma_r) { - return MAX(dt_bilateral_singlebuffer_size(width, height, sigma_s, sigma_r), (size_t)width * height * 4 * sizeof(float)); + return MAX(dt_bilateral_singlebuffer_size(width, height, sigma_s, sigma_r), + (size_t)width * height * 4 * sizeof(float)); } @@ -111,10 +106,14 @@ dt_bilateral_cl_t *dt_bilateral_init_cl(const int devid, const float sigma_s, // spatial sigma (blur pixel coords) const float sigma_r) // range sigma (blur luma values) { - dt_opencl_local_buffer_t locopt - = (dt_opencl_local_buffer_t){ .xoffset = 0, .xfactor = 1, .yoffset = 0, .yfactor = 1, - .cellsize = 8 * sizeof(float) + sizeof(int), .overhead = 0, - .sizex = 1 << 6, .sizey = 1 << 6 }; + dt_opencl_local_buffer_t locopt = (dt_opencl_local_buffer_t){.xoffset = 0, + .xfactor = 1, + .yoffset = 0, + .yfactor = 1, + .cellsize = 8 * sizeof(float) + sizeof(int), + .overhead = 0, + .sizex = 1 << 6, + .sizey = 1 << 6 }; if(!dt_opencl_local_buffer_opt(devid, darktable.opencl->bilateral->kernel_splat, &locopt)) { @@ -126,8 +125,7 @@ dt_bilateral_cl_t *dt_bilateral_init_cl(const int devid, if(locopt.sizex * locopt.sizey < 16 * 16) { dt_print(DT_DEBUG_OPENCL, - "[opencl_bilateral] device %d does not offer sufficient resources to run bilateral grid\n", - devid); + "[opencl_bilateral] device %d does not offer sufficient resources to run bilateral grid\n", devid); return NULL; } @@ -152,8 +150,7 @@ dt_bilateral_cl_t *dt_bilateral_init_cl(const int devid, b->dev_grid_tmp = NULL; // alloc grid buffer: - b->dev_grid - = dt_opencl_alloc_device_buffer(b->devid, (size_t)b->size_x * b->size_y * b->size_z * sizeof(float)); + b->dev_grid = dt_opencl_alloc_device_buffer(b->devid, (size_t)b->size_x * b->size_y * b->size_z * sizeof(float)); if(!b->dev_grid) { dt_bilateral_free_cl(b); @@ -205,8 +202,7 @@ cl_int dt_bilateral_splat_cl(dt_bilateral_cl_t *b, cl_mem in) dt_opencl_set_kernel_arg(b->devid, b->global->kernel_splat, 6, sizeof(int), (void *)&b->size_z); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_splat, 7, sizeof(float), (void *)&b->sigma_s); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_splat, 8, sizeof(float), (void *)&b->sigma_r); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_splat, 9, b->blocksizex * b->blocksizey * sizeof(int), - NULL); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_splat, 9, b->blocksizex * b->blocksizey * sizeof(int), NULL); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_splat, 10, b->blocksizex * b->blocksizey * 8 * sizeof(float), NULL); err = dt_opencl_enqueue_kernel_2d_with_local(b->devid, b->global->kernel_splat, sizes, local); @@ -260,8 +256,7 @@ cl_int dt_bilateral_blur_cl(dt_bilateral_cl_t *b) stride3 = b->size_x * b->size_y; sizes[0] = ROUNDUPWD(b->size_x); sizes[1] = ROUNDUPHT(b->size_y); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_blur_line_z, 0, sizeof(cl_mem), - (void *)&b->dev_grid_tmp); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_blur_line_z, 0, sizeof(cl_mem), (void *)&b->dev_grid_tmp); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_blur_line_z, 1, sizeof(cl_mem), (void *)&b->dev_grid); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_blur_line_z, 2, sizeof(int), (void *)&stride1); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_blur_line_z, 3, sizeof(int), (void *)&stride2); diff --git a/src/common/cache.c b/src/common/cache.c index 6c95c1b7cbc4..99ceeb0a3b49 100644 --- a/src/common/cache.c +++ b/src/common/cache.c @@ -28,10 +28,7 @@ // this implements a concurrent LRU cache -void dt_cache_init( - dt_cache_t *cache, - size_t entry_size, - size_t cost_quota) +void dt_cache_init(dt_cache_t *cache, size_t entry_size, size_t cost_quota) { cache->cost = 0; cache->lru = 0; @@ -79,17 +76,15 @@ int32_t dt_cache_contains(dt_cache_t *cache, const uint32_t key) return result; } -int dt_cache_for_all( - dt_cache_t *cache, - int (*process)(const uint32_t key, const void *data, void *user_data), - void *user_data) +int dt_cache_for_all(dt_cache_t *cache, int (*process)(const uint32_t key, const void *data, void *user_data), + void *user_data) { dt_pthread_mutex_lock(&cache->lock); GHashTableIter iter; gpointer key, value; - g_hash_table_iter_init (&iter, cache->hashtable); - while (g_hash_table_iter_next (&iter, &key, &value)) + g_hash_table_iter_init(&iter, cache->hashtable); + while(g_hash_table_iter_next(&iter, &key, &value)) { dt_cache_entry_t *entry = (dt_cache_entry_t *)value; const int err = process(GPOINTER_TO_INT(key), entry->data, user_data); @@ -112,14 +107,15 @@ dt_cache_entry_t *dt_cache_testget(dt_cache_t *cache, const uint32_t key, char m int result; double start = dt_get_wtime(); dt_pthread_mutex_lock(&cache->lock); - res = g_hash_table_lookup_extended( - cache->hashtable, GINT_TO_POINTER(key), &orig_key, &value); + res = g_hash_table_lookup_extended(cache->hashtable, GINT_TO_POINTER(key), &orig_key, &value); if(res) { dt_cache_entry_t *entry = (dt_cache_entry_t *)value; // lock the cache entry - if(mode == 'w') result = dt_pthread_rwlock_trywrlock(&entry->lock); - else result = dt_pthread_rwlock_tryrdlock(&entry->lock); + if(mode == 'w') + result = dt_pthread_rwlock_trywrlock(&entry->lock); + else + result = dt_pthread_rwlock_tryrdlock(&entry->lock); if(result) { // need to give up mutex so other threads have a chance to get in between and // free the lock we're trying to acquire: @@ -131,8 +127,7 @@ dt_cache_entry_t *dt_cache_testget(dt_cache_t *cache, const uint32_t key, char m cache->lru = g_list_concat(cache->lru, entry->link); dt_pthread_mutex_unlock(&cache->lock); double end = dt_get_wtime(); - if(end - start > 0.1) - fprintf(stderr, "try+ wait time %.06fs mode %c \n", end - start, mode); + if(end - start > 0.1) fprintf(stderr, "try+ wait time %.06fs mode %c \n", end - start, mode); if(mode == 'w') { @@ -146,15 +141,15 @@ dt_cache_entry_t *dt_cache_testget(dt_cache_t *cache, const uint32_t key, char m } dt_pthread_mutex_unlock(&cache->lock); double end = dt_get_wtime(); - if(end - start > 0.1) - fprintf(stderr, "try- wait time %.06fs\n", end - start); + if(end - start > 0.1) fprintf(stderr, "try- wait time %.06fs\n", end - start); return 0; } // if found, the data void* is returned. if not, it is set to be // the given *data and a new hash table entry is created, which can be // found using the given key later on. -dt_cache_entry_t *dt_cache_get_with_caller(dt_cache_t *cache, const uint32_t key, char mode, const char *file, int line) +dt_cache_entry_t *dt_cache_get_with_caller(dt_cache_t *cache, const uint32_t key, char mode, const char *file, + int line) { gpointer orig_key, value; gboolean res; @@ -162,13 +157,14 @@ dt_cache_entry_t *dt_cache_get_with_caller(dt_cache_t *cache, const uint32_t key double start = dt_get_wtime(); restart: dt_pthread_mutex_lock(&cache->lock); - res = g_hash_table_lookup_extended( - cache->hashtable, GINT_TO_POINTER(key), &orig_key, &value); + res = g_hash_table_lookup_extended(cache->hashtable, GINT_TO_POINTER(key), &orig_key, &value); if(res) { // yay, found. read lock and pass on. dt_cache_entry_t *entry = (dt_cache_entry_t *)value; - if(mode == 'w') result = dt_pthread_rwlock_trywrlock_with_caller(&entry->lock, file, line); - else result = dt_pthread_rwlock_tryrdlock_with_caller(&entry->lock, file, line); + if(mode == 'w') + result = dt_pthread_rwlock_trywrlock_with_caller(&entry->lock, file, line); + else + result = dt_pthread_rwlock_tryrdlock_with_caller(&entry->lock, file, line); if(result) { // need to give up mutex so other threads have a chance to get in between and // free the lock we're trying to acquire: @@ -241,8 +237,10 @@ dt_cache_entry_t *dt_cache_get_with_caller(dt_cache_t *cache, const uint32_t key const int write = ((mode == 'w') || cache->allocate); // write lock in case the caller requests it: - if(write) dt_pthread_rwlock_wrlock_with_caller(&entry->lock, file, line); - else dt_pthread_rwlock_rdlock_with_caller(&entry->lock, file, line); + if(write) + dt_pthread_rwlock_wrlock_with_caller(&entry->lock, file, line); + else + dt_pthread_rwlock_rdlock_with_caller(&entry->lock, file, line); cache->cost += entry->cost; @@ -251,8 +249,7 @@ dt_cache_entry_t *dt_cache_get_with_caller(dt_cache_t *cache, const uint32_t key dt_pthread_mutex_unlock(&cache->lock); double end = dt_get_wtime(); - if(end - start > 0.1) - fprintf(stderr, "wait time %.06fs\n", end - start); + if(end - start > 0.1) fprintf(stderr, "wait time %.06fs\n", end - start); // WARNING: do *NOT* unpoison here. it must be done by the caller! @@ -268,8 +265,7 @@ int dt_cache_remove(dt_cache_t *cache, const uint32_t key) restart: dt_pthread_mutex_lock(&cache->lock); - res = g_hash_table_lookup_extended( - cache->hashtable, GINT_TO_POINTER(key), &orig_key, &value); + res = g_hash_table_lookup_extended(cache->hashtable, GINT_TO_POINTER(key), &orig_key, &value); entry = (dt_cache_entry_t *)value; if(!res) { // not found in cache, not deleting. @@ -365,7 +361,7 @@ void dt_cache_gc(dt_cache_t *cache, const float fill_ratio) void dt_cache_release_with_caller(dt_cache_t *cache, dt_cache_entry_t *entry, const char *file, int line) { #if((__has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)) && 1) - // yes, this is *HIGHLY* unportable and is accessing implementation details. +// yes, this is *HIGHLY* unportable and is accessing implementation details. #ifdef _DEBUG if(entry->lock.lock.__data.__nr_readers <= 1) #else diff --git a/src/common/cache.h b/src/common/cache.h index 81b7e9eaca97..62dbbecdd83e 100644 --- a/src/common/cache.h +++ b/src/common/cache.h @@ -32,15 +32,15 @@ typedef struct dt_cache_entry_t dt_pthread_rwlock_t lock; int _lock_demoting; uint32_t key; -} -dt_cache_entry_t; +} dt_cache_entry_t; typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry)); typedef void((*dt_cache_cleanup_t)(void *userdata, dt_cache_entry_t *entry)); typedef struct dt_cache_t { - dt_pthread_mutex_t lock; // big fat lock. we're only expecting a couple hand full of cpu threads to use this concurrently. + dt_pthread_mutex_t lock; // big fat lock. we're only expecting a couple hand full of cpu threads to use this + // concurrently. size_t entry_size; // cache line allocation size_t cost; // user supplied cost per cache line (bytes?) @@ -54,8 +54,7 @@ typedef struct dt_cache_t dt_cache_allocate_t cleanup; void *allocate_data; void *cleanup_data; -} -dt_cache_t; +} dt_cache_t; // entry size is only used if alloc callback is 0 void dt_cache_init(dt_cache_t *cache, size_t entry_size, size_t cost_quota); @@ -75,8 +74,9 @@ static inline void dt_cache_set_cleanup_callback(dt_cache_t *cache, dt_cache_cle } // returns a slot in the cache for this key (newly allocated if need be), locked according to mode (r, w) -#define dt_cache_get(A, B, C) dt_cache_get_with_caller(A, B, C, __FILE__, __LINE__) -dt_cache_entry_t *dt_cache_get_with_caller(dt_cache_t *cache, const uint32_t key, char mode, const char *file, int line); +#define dt_cache_get(A, B, C) dt_cache_get_with_caller(A, B, C, __FILE__, __LINE__) +dt_cache_entry_t *dt_cache_get_with_caller(dt_cache_t *cache, const uint32_t key, char mode, const char *file, + int line); // same but returns 0 if not allocated yet (both will block and wait for entry rw locks to be released) dt_cache_entry_t *dt_cache_testget(dt_cache_t *cache, const uint32_t key, char mode); // release a lock on a cache entry. the cache knows which one you mean (r or w). @@ -96,9 +96,8 @@ void dt_cache_gc(dt_cache_t *cache, const float fill_ratio); // iterate over all currently contained data blocks. // not thread safe! only use this for init/cleanup! // returns non zero the first time process() returns non zero. -int dt_cache_for_all(dt_cache_t *cache, - int (*process)(const uint32_t key, const void *data, void *user_data), - void *user_data); +int dt_cache_for_all(dt_cache_t *cache, int (*process)(const uint32_t key, const void *data, void *user_data), + void *user_data); // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh // vim: shiftwidth=2 expandtab tabstop=2 cindent diff --git a/src/common/calculator.c b/src/common/calculator.c index 81feb75274d7..4d372d989f5a 100644 --- a/src/common/calculator.c +++ b/src/common/calculator.c @@ -307,8 +307,7 @@ static float parse_primary_expression(parser_state_t *self) free(self->token); self->token = get_token(self); result = parse_expression(self); - if(!self->token || self->token->type != T_OPERATOR || self->token->data.operator!= O_RIGHTROUND) - return NAN; + if(!self->token || self->token->type != T_OPERATOR || self->token->data.operator!= O_RIGHTROUND) return NAN; free(self->token); self->token = get_token(self); return result; diff --git a/src/common/camera_control.c b/src/common/camera_control.c index b511907b3df3..a41f16fc5656 100644 --- a/src/common/camera_control.c +++ b/src/common/camera_control.c @@ -106,21 +106,20 @@ static void _camera_process_job(const dt_camctl_t *c, const dt_camera_t *camera, /** Dispatch functions for listener interfaces */ const char *_dispatch_request_image_path(const dt_camctl_t *c, time_t *exif_time, const dt_camera_t *camera); -const char *_dispatch_request_image_filename(const dt_camctl_t *c, const char *filename, - time_t *exif_time, const dt_camera_t *camera); +const char *_dispatch_request_image_filename(const dt_camctl_t *c, const char *filename, time_t *exif_time, + const dt_camera_t *camera); void _dispatch_camera_image_downloaded(const dt_camctl_t *c, const dt_camera_t *camera, const char *filename); void _dispatch_camera_connected(const dt_camctl_t *c, const dt_camera_t *camera); void _dispatch_camera_disconnected(const dt_camctl_t *c, const dt_camera_t *camera); void _dispatch_control_status(const dt_camctl_t *c, dt_camctl_status_t status); void _dispatch_camera_error(const dt_camctl_t *c, const dt_camera_t *camera, dt_camera_error_t error); -int _dispatch_camera_storage_image_filename(const dt_camctl_t *c, const dt_camera_t *camera, - const char *filename, CameraFile *preview, CameraFile *exif); -void _dispatch_camera_property_value_changed(const dt_camctl_t *c, const dt_camera_t *camera, - const char *name, const char *value); +int _dispatch_camera_storage_image_filename(const dt_camctl_t *c, const dt_camera_t *camera, const char *filename, + CameraFile *preview, CameraFile *exif); +void _dispatch_camera_property_value_changed(const dt_camctl_t *c, const dt_camera_t *camera, const char *name, + const char *value); void _dispatch_camera_property_accessibility_changed(const dt_camctl_t *c, const dt_camera_t *camera, const char *name, gboolean read_only); -void _dispatch_camera_exif_data_changed(const dt_camctl_t *c,const time_t exif_time, - const dt_camera_t *camera); +void _dispatch_camera_exif_data_changed(const dt_camctl_t *c, const time_t exif_time, const dt_camera_t *camera); /** Helper function to destroy a dt_camera_t object */ static void dt_camctl_camera_destroy(dt_camera_t *cam); @@ -233,8 +232,8 @@ static gboolean _camera_timeout_job(gpointer data) static int _camera_start_timeout_func(Camera *c, unsigned int timeout, CameraTimeoutFunc func, void *data) { - dt_print(DT_DEBUG_CAMCTL, - "[camera_control] start timeout %d seconds for camera %p requested by driver.\n", timeout, data); + dt_print(DT_DEBUG_CAMCTL, "[camera_control] start timeout %d seconds for camera %p requested by driver.\n", + timeout, data); dt_camera_t *cam = (dt_camera_t *)data; cam->timeout = func; return g_timeout_add_seconds(timeout, _camera_timeout_job, cam); @@ -299,8 +298,8 @@ static void _camera_process_job(const dt_camctl_t *c, const dt_camera_t *camera, if(handle != -1) { gp_file_new_from_fd(&destination, handle); - if(gp_camera_file_get(camera->gpcam, fp.folder, fp.name, GP_FILE_TYPE_NORMAL, destination, - c->gpcontext) == GP_OK) + if(gp_camera_file_get(camera->gpcam, fp.folder, fp.name, GP_FILE_TYPE_NORMAL, destination, c->gpcontext) + == GP_OK) { // Notify listeners of captured image _dispatch_camera_image_downloaded(c, camera, output); @@ -380,8 +379,7 @@ static void _camera_process_job(const dt_camctl_t *c, const dt_camera_t *camera, case _JOB_TYPE_SET_PROPERTY_STRING: { _camctl_camera_set_property_string_job_t *spj = (_camctl_camera_set_property_string_job_t *)job; - dt_print(DT_DEBUG_CAMCTL, "[camera_control] executing set camera config job %s=%s\n", spj->name, - spj->value); + dt_print(DT_DEBUG_CAMCTL, "[camera_control] executing set camera config job %s=%s\n", spj->name, spj->value); CameraWidget *config; // Copy of camera configuration CameraWidget *widget; @@ -442,8 +440,7 @@ static void _camera_process_job(const dt_camctl_t *c, const dt_camera_t *camera, case _JOB_TYPE_SET_PROPERTY_INT: { _camctl_camera_set_property_int_job_t *spj = (_camctl_camera_set_property_int_job_t *)job; - dt_print(DT_DEBUG_CAMCTL, "[camera_control] executing set camera config job %s=%d\n", spj->name, - spj->value); + dt_print(DT_DEBUG_CAMCTL, "[camera_control] executing set camera config job %s=%d\n", spj->name, spj->value); CameraWidget *config; // Copy of camera configuration CameraWidget *widget; @@ -704,8 +701,7 @@ void dt_camctl_detect_cameras(const dt_camctl_t *c) gp_port_info_list_new(&camctl->gpports); gp_port_info_list_load(camctl->gpports); - dt_print(DT_DEBUG_CAMCTL, "[camera_control] loaded %d port drivers.\n", - gp_port_info_list_count(camctl->gpports)); + dt_print(DT_DEBUG_CAMCTL, "[camera_control] loaded %d port drivers.\n", gp_port_info_list_count(camctl->gpports)); @@ -748,10 +744,9 @@ void dt_camctl_detect_cameras(const dt_camctl_t *c) // Check if camera has capabilities for being presented to darktable if(camera->can_import == FALSE && camera->can_tether == FALSE) { - dt_print( - DT_DEBUG_CAMCTL, - "[camera_control] device %s on port %s doesn't support import or tether, skipping device.\n", - camera->model, camera->port); + dt_print(DT_DEBUG_CAMCTL, + "[camera_control] device %s on port %s doesn't support import or tether, skipping device.\n", + camera->model, camera->port); dt_camctl_camera_destroy(camera); continue; } @@ -871,8 +866,8 @@ gboolean _camera_initialize(const dt_camctl_t *c, dt_camera_t *cam) gp_camera_get_config(cam->gpcam, &cam->configuration, c->gpcontext); // TODO: find a more robust way for this, once we find out how to do it with non-EOS cameras - cam->can_live_view_advanced = cam->can_live_view && - dt_camctl_camera_property_exists(camctl, cam, "eoszoomposition"); + cam->can_live_view_advanced = cam->can_live_view + && dt_camctl_camera_property_exists(camctl, cam, "eoszoomposition"); // initialize timeout callbacks eg. keep alive, some cameras needs it. cam->gpcontext = camctl->gpcontext; @@ -885,8 +880,7 @@ gboolean _camera_initialize(const dt_camctl_t *c, dt_camera_t *cam) dt_print(DT_DEBUG_CAMCTL, "[camera_control] device %s on port %s initialized\n", cam->model, cam->port); } else - dt_print(DT_DEBUG_CAMCTL, "[camera_control] device %s on port %s already initialized\n", cam->model, - cam->port); + dt_print(DT_DEBUG_CAMCTL, "[camera_control] device %s on port %s already initialized\n", cam->model, cam->port); return TRUE; } @@ -913,18 +907,20 @@ void dt_camctl_import(const dt_camctl_t *c, const dt_camera_t *cam, GList *image g_strlcat(filename, eos + 1, sizeof(filename)); g_free(_file); - CameraFile* camfile; + CameraFile *camfile; int res = GP_OK; - const uint8_t* data = NULL; + const uint8_t *data = NULL; unsigned long int size; gp_file_new(&camfile); - if ((res = gp_camera_file_get(cam->gpcam, folder, filename, GP_FILE_TYPE_NORMAL, camfile, NULL)) < GP_OK) { + if((res = gp_camera_file_get(cam->gpcam, folder, filename, GP_FILE_TYPE_NORMAL, camfile, NULL)) < GP_OK) + { dt_print(DT_DEBUG_CAMCTL, "[camera_control] import failed: %s\n", gp_result_as_string(res)); gp_file_free(camfile); continue; } - if ((res = gp_file_get_data_and_size(camfile, (const char**)&data, &size)) < GP_OK) { + if((res = gp_file_get_data_and_size(camfile, (const char **)&data, &size)) < GP_OK) + { dt_print(DT_DEBUG_CAMCTL, "[camera_control] import failed: %s\n", gp_result_as_string(res)); gp_file_free(camfile); continue; @@ -1031,8 +1027,7 @@ int _camctl_recursive_get_previews(const dt_camctl_t *c, dt_camera_preview_flags c->gpcontext) < GP_OK) { preview = NULL; - dt_print(DT_DEBUG_CAMCTL, "[camera_control] failed to retrieve preview of file %s\n", - filename); + dt_print(DT_DEBUG_CAMCTL, "[camera_control] failed to retrieve preview of file %s\n", filename); } } else if(!strncmp(c->active_camera->port, "disk:", 5)) @@ -1054,8 +1049,8 @@ int _camctl_recursive_get_previews(const dt_camctl_t *c, dt_camera_preview_flags if(flags & CAMCTL_IMAGE_EXIF_DATA) { gp_file_new(&exif); - if(gp_camera_file_get(c->active_camera->gpcam, path, filename, GP_FILE_TYPE_EXIF, exif, - c->gpcontext) < GP_OK) + if(gp_camera_file_get(c->active_camera->gpcam, path, filename, GP_FILE_TYPE_EXIF, exif, c->gpcontext) + < GP_OK) { exif = NULL; dt_print(DT_DEBUG_CAMCTL, "[camera_control] failed to retrieve exif of file %s\n", filename); @@ -1072,9 +1067,8 @@ int _camctl_recursive_get_previews(const dt_camctl_t *c, dt_camera_preview_flags } } else - dt_print(DT_DEBUG_CAMCTL, - "[camera_control] failed to get file information of %s in folder %s on device\n", filename, - path); + dt_print(DT_DEBUG_CAMCTL, "[camera_control] failed to get file information of %s in folder %s on device\n", + filename, path); g_free(file); } } @@ -1185,8 +1179,7 @@ const char *dt_camctl_camera_get_model(const dt_camctl_t *c, const dt_camera_t * } -void _camera_build_property_menu(CameraWidget *widget, GtkMenu *menu, GCallback item_activate, - gpointer user_data) +void _camera_build_property_menu(CameraWidget *widget, GtkMenu *menu, GCallback item_activate, gpointer user_data) { int num_childs = 0; const char *sk; @@ -1209,8 +1202,7 @@ void _camera_build_property_menu(CameraWidget *widget, GtkMenu *menu, GCallback gtk_menu_item_set_submenu(item, gtk_menu_new()); /* recurse into submenu */ - _camera_build_property_menu(child, GTK_MENU(gtk_menu_item_get_submenu(item)), item_activate, - user_data); + _camera_build_property_menu(child, GTK_MENU(gtk_menu_item_get_submenu(item)), item_activate, user_data); /* add submenu item to menu if not empty*/ GList *childs = gtk_container_get_children(GTK_CONTAINER(gtk_menu_item_get_submenu(item))); @@ -1262,8 +1254,8 @@ void dt_camctl_camera_build_property_menu(const dt_camctl_t *c, const dt_camera_ -void dt_camctl_camera_set_property_string(const dt_camctl_t *c, const dt_camera_t *cam, - const char *property_name, const char *value) +void dt_camctl_camera_set_property_string(const dt_camctl_t *c, const dt_camera_t *cam, const char *property_name, + const char *value) { dt_camctl_t *camctl = (dt_camctl_t *)c; if(!cam && (cam = camctl->active_camera) == NULL && (cam = camctl->wanted_camera) == NULL) @@ -1282,8 +1274,8 @@ void dt_camctl_camera_set_property_string(const dt_camctl_t *c, const dt_camera_ _camera_add_job(camctl, camera, job); } -void dt_camctl_camera_set_property_choice(const dt_camctl_t *c, const dt_camera_t *cam, - const char *property_name, const int value) +void dt_camctl_camera_set_property_choice(const dt_camctl_t *c, const dt_camera_t *cam, const char *property_name, + const int value) { dt_camctl_t *camctl = (dt_camctl_t *)c; if(!cam && (cam = camctl->active_camera) == NULL && (cam = camctl->wanted_camera) == NULL) @@ -1302,8 +1294,8 @@ void dt_camctl_camera_set_property_choice(const dt_camctl_t *c, const dt_camera_ _camera_add_job(camctl, camera, job); } -void dt_camctl_camera_set_property_int(const dt_camctl_t *c, const dt_camera_t *cam, - const char *property_name, const int value) +void dt_camctl_camera_set_property_int(const dt_camctl_t *c, const dt_camera_t *cam, const char *property_name, + const int value) { dt_camctl_t *camctl = (dt_camctl_t *)c; if(!cam && (cam = camctl->active_camera) == NULL && (cam = camctl->wanted_camera) == NULL) @@ -1322,8 +1314,7 @@ void dt_camctl_camera_set_property_int(const dt_camctl_t *c, const dt_camera_t * _camera_add_job(camctl, camera, job); } -const char *dt_camctl_camera_get_property(const dt_camctl_t *c, const dt_camera_t *cam, - const char *property_name) +const char *dt_camctl_camera_get_property(const dt_camctl_t *c, const dt_camera_t *cam, const char *property_name) { dt_camctl_t *camctl = (dt_camctl_t *)c; if(!cam && (cam = camctl->active_camera) == NULL && (cam = camctl->wanted_camera) == NULL) @@ -1378,8 +1369,7 @@ const char *dt_camctl_camera_property_get_first_choice(const dt_camctl_t *c, con } dt_camera_t *camera = (dt_camera_t *)cam; dt_pthread_mutex_lock(&camera->config_lock); - if(gp_widget_get_child_by_name(camera->configuration, property_name, &camera->current_choice.widget) - == GP_OK) + if(gp_widget_get_child_by_name(camera->configuration, property_name, &camera->current_choice.widget) == GP_OK) { camera->current_choice.index = 0; gp_widget_get_choice(camera->current_choice.widget, camera->current_choice.index, &value); @@ -1481,8 +1471,8 @@ void _camera_poll_events(const dt_camctl_t *c, const dt_camera_t *cam) if(handle != -1) { gp_file_new_from_fd(&destination, handle); - if(gp_camera_file_get(cam->gpcam, fp->folder, fp->name, GP_FILE_TYPE_NORMAL, destination, - c->gpcontext) == GP_OK) + if(gp_camera_file_get(cam->gpcam, fp->folder, fp->name, GP_FILE_TYPE_NORMAL, destination, c->gpcontext) + == GP_OK) { // Notify listeners of captured image _dispatch_camera_image_downloaded(c, cam, output); @@ -1596,8 +1586,8 @@ void _camera_configuration_update(const dt_camctl_t *c, const dt_camera_t *camer dt_pthread_mutex_unlock(&cam->config_lock); } -const char *_dispatch_request_image_filename(const dt_camctl_t *c, const char *filename, - time_t *exif_time, const dt_camera_t *camera) +const char *_dispatch_request_image_filename(const dt_camctl_t *c, const char *filename, time_t *exif_time, + const dt_camera_t *camera) { dt_camctl_t *camctl = (dt_camctl_t *)c; GList *listener; @@ -1674,8 +1664,8 @@ void _dispatch_camera_image_downloaded(const dt_camctl_t *c, const dt_camera_t * dt_pthread_mutex_unlock(&camctl->listeners_lock); } -int _dispatch_camera_storage_image_filename(const dt_camctl_t *c, const dt_camera_t *camera, - const char *filename, CameraFile *preview, CameraFile *exif) +int _dispatch_camera_storage_image_filename(const dt_camctl_t *c, const dt_camera_t *camera, const char *filename, + CameraFile *preview, CameraFile *exif) { int res = 0; dt_camctl_t *camctl = (dt_camctl_t *)c; @@ -1706,8 +1696,8 @@ void _dispatch_control_status(const dt_camctl_t *c, dt_camctl_status_t status) dt_pthread_mutex_unlock(&camctl->listeners_lock); } -void _dispatch_camera_property_value_changed(const dt_camctl_t *c, const dt_camera_t *camera, - const char *name, const char *value) +void _dispatch_camera_property_value_changed(const dt_camctl_t *c, const dt_camera_t *camera, const char *name, + const char *value) { dt_camctl_t *camctl = (dt_camctl_t *)c; GList *listener; @@ -1716,8 +1706,7 @@ void _dispatch_camera_property_value_changed(const dt_camctl_t *c, const dt_came { if(((dt_camctl_listener_t *)listener->data)->camera_property_value_changed != NULL) ((dt_camctl_listener_t *)listener->data) - ->camera_property_value_changed(camera, name, value, - ((dt_camctl_listener_t *)listener->data)->data); + ->camera_property_value_changed(camera, name, value, ((dt_camctl_listener_t *)listener->data)->data); } while((listener = g_list_next(listener)) != NULL); dt_pthread_mutex_unlock(&camctl->listeners_lock); } diff --git a/src/common/camera_control.h b/src/common/camera_control.h index 06f996b60a16..6a8a80c7edac 100644 --- a/src/common/camera_control.h +++ b/src/common/camera_control.h @@ -22,11 +22,11 @@ #include <glib.h> -#if defined (_WIN32) +#if defined(_WIN32) #ifdef interface #undef interface #endif -#endif //defined (_WIN32) +#endif // defined (_WIN32) #include <gphoto2/gphoto2.h> #include <gtk/gtk.h> @@ -182,11 +182,10 @@ typedef struct dt_camctl_listener_t CameraFile *exif, void *data); /** Invoked when a value of a property is changed. */ - void (*camera_property_value_changed)(const dt_camera_t *camera, const char *name, const char *value, - void *data); + void (*camera_property_value_changed)(const dt_camera_t *camera, const char *name, const char *value, void *data); /** Invoked when accessibility of a property is changed. */ - void (*camera_property_accessibility_changed)(const dt_camera_t *camera, const char *name, - gboolean read_only, void *data); + void (*camera_property_accessibility_changed)(const dt_camera_t *camera, const char *name, gboolean read_only, + void *data); /** Invoked from dt_camctl_detect_cameras() when a new camera is connected */ void (*camera_connected)(const dt_camera_t *camera, void *data); @@ -242,16 +241,15 @@ void dt_camctl_camera_stop_live_view(const dt_camctl_t *c); const char *dt_camctl_camera_get_model(const dt_camctl_t *c, const dt_camera_t *cam); /** Set a property value \param cam Pointer to dt_camera_t if NULL the camctl->active_camera is used. */ -void dt_camctl_camera_set_property_string(const dt_camctl_t *c, const dt_camera_t *cam, - const char *property_name, const char *value); -void dt_camctl_camera_set_property_choice(const dt_camctl_t *c, const dt_camera_t *cam, - const char *property_name, const int value); -void dt_camctl_camera_set_property_int(const dt_camctl_t *c, const dt_camera_t *cam, - const char *property_name, const int value); +void dt_camctl_camera_set_property_string(const dt_camctl_t *c, const dt_camera_t *cam, const char *property_name, + const char *value); +void dt_camctl_camera_set_property_choice(const dt_camctl_t *c, const dt_camera_t *cam, const char *property_name, + const int value); +void dt_camctl_camera_set_property_int(const dt_camctl_t *c, const dt_camera_t *cam, const char *property_name, + const int value); /** Get a property value from cached configuration. \param cam Pointer to dt_camera_t if NULL the * camctl->active_camera is used. */ -const char *dt_camctl_camera_get_property(const dt_camctl_t *c, const dt_camera_t *cam, - const char *property_name); +const char *dt_camctl_camera_get_property(const dt_camctl_t *c, const dt_camera_t *cam, const char *property_name); /** Check if property exists. */ int dt_camctl_camera_property_exists(const dt_camctl_t *c, const dt_camera_t *cam, const char *property_name); /** Get first choice available for named property. */ diff --git a/src/common/collection.c b/src/common/collection.c index e80a61fad3af..a8d96c14ad28 100644 --- a/src/common/collection.c +++ b/src/common/collection.c @@ -33,7 +33,7 @@ #ifdef _WIN32 -//MSVCRT does not have strptime implemented +// MSVCRT does not have strptime implemented #include "win/strptime.h" #endif @@ -134,9 +134,8 @@ int dt_collection_update(const dt_collection_t *collection) need_operator = 1; } // DON'T SELECT IMAGES MARKED TO BE DELETED. - wq = dt_util_dstrcat(wq, " %s (flags & %d) != %d", - (need_operator) ? "AND" : ((need_operator = 1) ? "" : ""), DT_IMAGE_REMOVE, - DT_IMAGE_REMOVE); + wq = dt_util_dstrcat(wq, " %s (flags & %d) != %d", (need_operator) ? "AND" : ((need_operator = 1) ? "" : ""), + DT_IMAGE_REMOVE, DT_IMAGE_REMOVE); if(collection->params.filter_flags & COLLECTION_FILTER_CUSTOM_COMPARE) wq = dt_util_dstrcat(wq, " %s (flags & 7) %s %d AND (flags & 7) != 6", @@ -146,8 +145,8 @@ int dt_collection_update(const dt_collection_t *collection) wq = dt_util_dstrcat(wq, " %s (flags & 7) >= %d AND (flags & 7) != 6", (need_operator) ? "and" : ((need_operator = 1) ? "" : ""), rating - 1); else if(collection->params.filter_flags & COLLECTION_FILTER_EQUAL_RATING) - wq = dt_util_dstrcat(wq, " %s (flags & 7) == %d", - (need_operator) ? "AND" : ((need_operator = 1) ? "" : ""), rating - 1); + wq = dt_util_dstrcat(wq, " %s (flags & 7) == %d", (need_operator) ? "AND" : ((need_operator = 1) ? "" : ""), + rating - 1); if(collection->params.filter_flags & COLLECTION_FILTER_ALTERED) wq = dt_util_dstrcat(wq, " %s id IN (SELECT imgid FROM main.history WHERE imgid=id)", @@ -195,9 +194,8 @@ int dt_collection_update(const dt_collection_t *collection) } /* store the new query */ - query - = dt_util_dstrcat(query, "%s %s%s", selq, sq ? sq : "", - (collection->params.query_flags & COLLECTION_QUERY_USE_LIMIT) ? " " LIMIT_QUERY : ""); + query = dt_util_dstrcat(query, "%s %s%s", selq, sq ? sq : "", + (collection->params.query_flags & COLLECTION_QUERY_USE_LIMIT) ? " " LIMIT_QUERY : ""); result = _dt_collection_store(collection, query); /* free memory used */ @@ -436,7 +434,8 @@ static uint32_t _dt_collection_compute_count(const dt_collection_t *collection) gchar *fq = g_strstr_len(query, strlen(query), "FROM"); if((collection->params.query_flags & COLLECTION_QUERY_USE_ONLY_WHERE_EXT)) - count_query = dt_util_dstrcat(NULL, "SELECT COUNT(DISTINCT main.images.id) FROM main.images %s", collection->where_ext); + count_query = dt_util_dstrcat(NULL, "SELECT COUNT(DISTINCT main.images.id) FROM main.images %s", + collection->where_ext); else count_query = dt_util_dstrcat(count_query, "SELECT COUNT(DISTINCT id) %s", fq); @@ -463,8 +462,8 @@ uint32_t dt_collection_get_selected_count(const dt_collection_t *collection) { sqlite3_stmt *stmt = NULL; uint32_t count = 0; - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), - "SELECT COUNT(*) FROM main.selected_images", -1, &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT COUNT(*) FROM main.selected_images", -1, + &stmt, NULL); if(sqlite3_step(stmt) == SQLITE_ROW) count = sqlite3_column_int(stmt, 0); sqlite3_finalize(stmt); return count; @@ -477,8 +476,7 @@ GList *dt_collection_get_all(const dt_collection_t *collection, int limit) gchar *sq = NULL; /* get collection order */ - if((collection->params.query_flags & COLLECTION_QUERY_USE_SORT)) - sq = dt_collection_get_sort_query(collection); + if((collection->params.query_flags & COLLECTION_QUERY_USE_SORT)) sq = dt_collection_get_sort_query(collection); sqlite3_stmt *stmt = NULL; @@ -517,8 +515,7 @@ GList *dt_collection_get_all(const dt_collection_t *collection, int limit) int dt_collection_get_nth(const dt_collection_t *collection, int nth) { - if(nth < 0 || nth >= dt_collection_get_count(collection)) - return -1; + if(nth < 0 || nth >= dt_collection_get_count(collection)) return -1; const gchar *query = dt_collection_get_query(collection); sqlite3_stmt *stmt = NULL; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), query, -1, &stmt, NULL); @@ -528,13 +525,12 @@ int dt_collection_get_nth(const dt_collection_t *collection, int nth) int result = -1; if(sqlite3_step(stmt) == SQLITE_ROW) { - result = sqlite3_column_int(stmt, 0); + result = sqlite3_column_int(stmt, 0); } sqlite3_finalize(stmt); return result; - } GList *dt_collection_get_selected(const dt_collection_t *collection, int limit) @@ -544,8 +540,7 @@ GList *dt_collection_get_selected(const dt_collection_t *collection, int limit) gchar *sq = NULL; /* get collection order */ - if((collection->params.query_flags & COLLECTION_QUERY_USE_SORT)) - sq = dt_collection_get_sort_query(collection); + if((collection->params.query_flags & COLLECTION_QUERY_USE_SORT)) sq = dt_collection_get_sort_query(collection); sqlite3_stmt *stmt = NULL; @@ -762,15 +757,12 @@ void dt_collection_get_makermodel(const gchar *filter, GList **sanitized, GList gchar *needle = NULL; GHashTable *names = NULL; - if (sanitized) - names = g_hash_table_new(g_str_hash, g_str_equal); + if(sanitized) names = g_hash_table_new(g_str_hash, g_str_equal); - if (filter && filter[0] != '\0') - needle = g_utf8_strdown(filter, -1); + if(filter && filter[0] != '\0') needle = g_utf8_strdown(filter, -1); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), - "SELECT maker, model FROM main.images GROUP BY maker, model", - -1, &stmt, NULL); + "SELECT maker, model FROM main.images GROUP BY maker, model", -1, &stmt, NULL); while(sqlite3_step(stmt) == SQLITE_ROW) { char *exif_maker = (char *)sqlite3_column_text(stmt, 0); @@ -780,22 +772,20 @@ void dt_collection_get_makermodel(const gchar *filter, GList **sanitized, GList char model[64]; char alias[64]; maker[0] = model[0] = alias[0] = '\0'; - dt_rawspeed_lookup_makermodel(exif_maker, exif_model, - maker, sizeof(maker), - model, sizeof(model), - alias, sizeof(alias)); + dt_rawspeed_lookup_makermodel(exif_maker, exif_model, maker, sizeof(maker), model, sizeof(model), alias, + sizeof(alias)); // Create the makermodel by concatenation char makermodel[128]; g_strlcpy(makermodel, maker, sizeof(makermodel)); int maker_len = strlen(maker); makermodel[maker_len] = ' '; - g_strlcpy(makermodel+maker_len+1, model, sizeof(makermodel)-maker_len-1); + g_strlcpy(makermodel + maker_len + 1, model, sizeof(makermodel) - maker_len - 1); gchar *haystack = g_utf8_strdown(makermodel, -1); - if (!needle || g_strrstr(haystack, needle) != NULL) + if(!needle || g_strrstr(haystack, needle) != NULL) { - if (exif) + if(exif) { // Append a two element list with maker and model GList *inner_list = NULL; @@ -804,7 +794,7 @@ void dt_collection_get_makermodel(const gchar *filter, GList **sanitized, GList *exif = g_list_append(*exif, inner_list); } - if (sanitized) + if(sanitized) { gchar *key = g_strdup(makermodel); g_hash_table_add(names, key); @@ -817,7 +807,7 @@ void dt_collection_get_makermodel(const gchar *filter, GList **sanitized, GList if(sanitized) { - *sanitized = g_list_sort(g_hash_table_get_keys(names), (GCompareFunc) strcmp); + *sanitized = g_list_sort(g_hash_table_get_keys(names), (GCompareFunc)strcmp); g_hash_table_destroy(names); } } @@ -878,7 +868,7 @@ static gchar *get_query_string(const dt_collection_properties_t property, const break; case DT_COLLECTION_PROP_CAMERA: // camera - if (!text || text[0] == '\0') // Optimize away the empty case + if(!text || text[0] == '\0') // Optimize away the empty case query = dt_util_dstrcat(query, "(1=1)"); else { @@ -887,7 +877,7 @@ static gchar *get_query_string(const dt_collection_properties_t property, const GList *lists = NULL; dt_collection_get_makermodel(text, NULL, &lists); GList *element = lists; - while (element) + while(element) { GList *tuple = element->data; char *mk = sqlite3_mprintf("%q", tuple->data); @@ -914,23 +904,28 @@ static gchar *get_query_string(const dt_collection_properties_t property, const // TODO: Autogenerate this code? case DT_COLLECTION_PROP_TITLE: // title query = dt_util_dstrcat(query, "(id IN (SELECT id FROM main.meta_data WHERE key = %d AND value " - "LIKE '%%%s%%'))", DT_METADATA_XMP_DC_TITLE, escaped_text); + "LIKE '%%%s%%'))", + DT_METADATA_XMP_DC_TITLE, escaped_text); break; case DT_COLLECTION_PROP_DESCRIPTION: // description query = dt_util_dstrcat(query, "(id IN (SELECT id FROM main.meta_data WHERE key = %d AND value " - "LIKE '%%%s%%'))", DT_METADATA_XMP_DC_DESCRIPTION, escaped_text); + "LIKE '%%%s%%'))", + DT_METADATA_XMP_DC_DESCRIPTION, escaped_text); break; case DT_COLLECTION_PROP_CREATOR: // creator query = dt_util_dstrcat(query, "(id IN (SELECT id FROM main.meta_data WHERE key = %d AND value " - "LIKE '%%%s%%'))", DT_METADATA_XMP_DC_CREATOR, escaped_text); + "LIKE '%%%s%%'))", + DT_METADATA_XMP_DC_CREATOR, escaped_text); break; case DT_COLLECTION_PROP_PUBLISHER: // publisher query = dt_util_dstrcat(query, "(id IN (SELECT id FROM main.meta_data WHERE key = %d AND value " - "LIKE '%%%s%%'))", DT_METADATA_XMP_DC_PUBLISHER, escaped_text); + "LIKE '%%%s%%'))", + DT_METADATA_XMP_DC_PUBLISHER, escaped_text); break; case DT_COLLECTION_PROP_RIGHTS: // rights query = dt_util_dstrcat(query, "(id IN (SELECT id FROM main.meta_data WHERE key = %d AND value " - "LIKE '%%%s%%'))", DT_METADATA_XMP_DC_RIGHTS, escaped_text); + "LIKE '%%%s%%'))", + DT_METADATA_XMP_DC_RIGHTS, escaped_text); break; case DT_COLLECTION_PROP_LENS: // lens query = dt_util_dstrcat(query, "(lens LIKE '%%%s%%')", escaped_text); @@ -966,8 +961,7 @@ static gchar *get_query_string(const dt_collection_properties_t property, const if(operator&& strcmp(operator, "[]") == 0) { - if(number1 && number2) - query = dt_util_dstrcat(query, "((iso >= %s) AND (iso <= %s))", number1, number2); + if(number1 && number2) query = dt_util_dstrcat(query, "((iso >= %s) AND (iso <= %s))", number1, number2); } else if(operator&& number1) query = dt_util_dstrcat(query, "(iso %s %s)", operator, number1); @@ -1242,12 +1236,9 @@ void dt_collection_hint_message(const dt_collection_t *collection) } else { - message = g_strdup_printf( - ngettext( - "%d image of %d in current collection is selected", - "%d images of %d in current collection are selected", - cs), - cs, c); + message = g_strdup_printf(ngettext("%d image of %d in current collection is selected", + "%d images of %d in current collection are selected", cs), + cs, c); } g_idle_add(dt_collection_hint_message_internal, message); diff --git a/src/common/collection.h b/src/common/collection.h index 997f3f9c4498..59e315dc4e5e 100644 --- a/src/common/collection.h +++ b/src/common/collection.h @@ -39,8 +39,7 @@ typedef enum dt_collection_filter_comparator_t COLLECTION_FILTER_EQUAL_RATING = 1 << 2, // show only selected star filter COLLECTION_FILTER_ALTERED = 1 << 3, // show only altered images COLLECTION_FILTER_UNALTERED = 1 << 4, // show only unaltered images - COLLECTION_FILTER_CUSTOM_COMPARE - = 1 << 5 // use the comparator defined in the comparator field to filter stars + COLLECTION_FILTER_CUSTOM_COMPARE = 1 << 5 // use the comparator defined in the comparator field to filter stars } dt_collection_filter_comparator_t; typedef enum dt_collection_filter_t @@ -210,8 +209,7 @@ int dt_collection_serialize(char *buf, int bufsize); /* splits an input string into a number part and an optional operator part */ void dt_collection_split_operator_number(const gchar *input, char **number1, char **number2, char **operator); -void dt_collection_split_operator_datetime(const gchar *input, char **number1, char **number2, - char **operator); +void dt_collection_split_operator_datetime(const gchar *input, char **number1, char **number2, char **operator); // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh // vim: shiftwidth=2 expandtab tabstop=2 cindent diff --git a/src/common/color_picker.c b/src/common/color_picker.c index 76875d483b31..ad2abba6bab4 100644 --- a/src/common/color_picker.c +++ b/src/common/color_picker.c @@ -271,7 +271,7 @@ static void color_picker_helper_xtrans_seq(const dt_iop_buffer_dsc_t *const dsc, float *const picked_color_max) { const int width = roi->width; - const uint8_t(*const xtrans)[6] = (const uint8_t(*const)[6])dsc->xtrans; + const uint8_t (*const xtrans)[6] = (const uint8_t (*const)[6])dsc->xtrans; uint32_t weights[3] = { 0u, 0u, 0u }; @@ -306,7 +306,7 @@ static void color_picker_helper_xtrans_parallel(const dt_iop_buffer_dsc_t *const float *const picked_color_max) { const int width = roi->width; - const uint8_t(*const xtrans)[6] = (const uint8_t(*const)[6])dsc->xtrans; + const uint8_t (*const xtrans)[6] = (const uint8_t (*const)[6])dsc->xtrans; uint32_t weights[3] = { 0u, 0u, 0u }; diff --git a/src/common/colorlabels.c b/src/common/colorlabels.c index 95069fe6e110..486ac987f4d6 100644 --- a/src/common/colorlabels.c +++ b/src/common/colorlabels.c @@ -85,8 +85,8 @@ void dt_colorlabels_toggle_label_selection(const int color) // none or only part of images have that color label, so label them all DT_DEBUG_SQLITE3_PREPARE_V2( dt_database_get(darktable.db), - "INSERT OR IGNORE INTO main.color_labels (imgid, color) SELECT imgid, ?1 FROM main.selected_images", - -1, &stmt2, NULL); + "INSERT OR IGNORE INTO main.color_labels (imgid, color) SELECT imgid, ?1 FROM main.selected_images", -1, + &stmt2, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt2, 1, color); sqlite3_step(stmt2); sqlite3_finalize(stmt2); @@ -112,8 +112,8 @@ void dt_colorlabels_toggle_label(const int imgid, const int color) if(imgid <= 0) return; sqlite3_stmt *stmt, *stmt2; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), - "SELECT * FROM main.color_labels WHERE imgid=?1 AND color=?2 LIMIT 1", - -1, &stmt, NULL); + "SELECT * FROM main.color_labels WHERE imgid=?1 AND color=?2 LIMIT 1", -1, &stmt, + NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, color); if(sqlite3_step(stmt) == SQLITE_ROW) @@ -144,8 +144,8 @@ int dt_colorlabels_check_label(const int imgid, const int color) if(imgid <= 0) return 0; sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), - "SELECT * FROM main.color_labels WHERE imgid=?1 AND color=?2 LIMIT 1", - -1, &stmt, NULL); + "SELECT * FROM main.color_labels WHERE imgid=?1 AND color=?2 LIMIT 1", -1, &stmt, + NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, color); if(sqlite3_step(stmt) == SQLITE_ROW) diff --git a/src/common/colorspaces.c b/src/common/colorspaces.c index 82c3506b531b..74d5deec0a6f 100644 --- a/src/common/colorspaces.c +++ b/src/common/colorspaces.c @@ -37,48 +37,42 @@ #include <CoreServices/CoreServices.h> #endif -static const cmsCIEXYZ d65 = {0.95045471, 1.00000000, 1.08905029}; -static const cmsCIEXYZTRIPLE rec709_primaries_pre_quantized = { - {0.43603516, 0.22248840, 0.01391602}, - {0.38511658, 0.71690369, 0.09706116}, - {0.14305115, 0.06060791, 0.71392822} -}; -static const cmsCIEXYZTRIPLE rec2020_primaries_prequantized = { - {0.67349243, 0.27903748, -0.00193787}, - {0.16566467, 0.67535400, 0.02998352}, - {0.12504578, 0.04560852, 0.79685974} -}; -static const cmsCIEXYZTRIPLE adobe_primaries_prequantized = { - {0.60974121, 0.31111145, 0.01947021}, - {0.20527649, 0.62567139, 0.06086731}, - {0.14918518, 0.06321716, 0.74456787} -}; - -#define generate_mat3inv_body(c_type, A, B) \ - int mat3inv_##c_type(c_type *const dst, const c_type *const src) \ - { \ - \ - const c_type det = A(1, 1) * (A(3, 3) * A(2, 2) - A(3, 2) * A(2, 3)) \ - - A(2, 1) * (A(3, 3) * A(1, 2) - A(3, 2) * A(1, 3)) \ - + A(3, 1) * (A(2, 3) * A(1, 2) - A(2, 2) * A(1, 3)); \ - \ - const c_type epsilon = 1e-7f; \ - if(fabs(det) < epsilon) return 1; \ - \ - const c_type invDet = 1.0 / det; \ - \ - B(1, 1) = invDet * (A(3, 3) * A(2, 2) - A(3, 2) * A(2, 3)); \ - B(1, 2) = -invDet * (A(3, 3) * A(1, 2) - A(3, 2) * A(1, 3)); \ - B(1, 3) = invDet * (A(2, 3) * A(1, 2) - A(2, 2) * A(1, 3)); \ - \ - B(2, 1) = -invDet * (A(3, 3) * A(2, 1) - A(3, 1) * A(2, 3)); \ - B(2, 2) = invDet * (A(3, 3) * A(1, 1) - A(3, 1) * A(1, 3)); \ - B(2, 3) = -invDet * (A(2, 3) * A(1, 1) - A(2, 1) * A(1, 3)); \ - \ - B(3, 1) = invDet * (A(3, 2) * A(2, 1) - A(3, 1) * A(2, 2)); \ - B(3, 2) = -invDet * (A(3, 2) * A(1, 1) - A(3, 1) * A(1, 2)); \ - B(3, 3) = invDet * (A(2, 2) * A(1, 1) - A(2, 1) * A(1, 2)); \ - return 0; \ +static const cmsCIEXYZ d65 = { 0.95045471, 1.00000000, 1.08905029 }; +static const cmsCIEXYZTRIPLE rec709_primaries_pre_quantized = { { 0.43603516, 0.22248840, 0.01391602 }, + { 0.38511658, 0.71690369, 0.09706116 }, + { 0.14305115, 0.06060791, 0.71392822 } }; +static const cmsCIEXYZTRIPLE rec2020_primaries_prequantized = { { 0.67349243, 0.27903748, -0.00193787 }, + { 0.16566467, 0.67535400, 0.02998352 }, + { 0.12504578, 0.04560852, 0.79685974 } }; +static const cmsCIEXYZTRIPLE adobe_primaries_prequantized = { { 0.60974121, 0.31111145, 0.01947021 }, + { 0.20527649, 0.62567139, 0.06086731 }, + { 0.14918518, 0.06321716, 0.74456787 } }; + +#define generate_mat3inv_body(c_type, A, B) \ + int mat3inv_##c_type(c_type *const dst, const c_type *const src) \ + { \ + \ + const c_type det = A(1, 1) * (A(3, 3) * A(2, 2) - A(3, 2) * A(2, 3)) \ + - A(2, 1) * (A(3, 3) * A(1, 2) - A(3, 2) * A(1, 3)) \ + + A(3, 1) * (A(2, 3) * A(1, 2) - A(2, 2) * A(1, 3)); \ + \ + const c_type epsilon = 1e-7f; \ + if(fabs(det) < epsilon) return 1; \ + \ + const c_type invDet = 1.0 / det; \ + \ + B(1, 1) = invDet * (A(3, 3) * A(2, 2) - A(3, 2) * A(2, 3)); \ + B(1, 2) = -invDet * (A(3, 3) * A(1, 2) - A(3, 2) * A(1, 3)); \ + B(1, 3) = invDet * (A(2, 3) * A(1, 2) - A(2, 2) * A(1, 3)); \ + \ + B(2, 1) = -invDet * (A(3, 3) * A(2, 1) - A(3, 1) * A(2, 3)); \ + B(2, 2) = invDet * (A(3, 3) * A(1, 1) - A(3, 1) * A(1, 3)); \ + B(2, 3) = -invDet * (A(2, 3) * A(1, 1) - A(2, 1) * A(1, 3)); \ + \ + B(3, 1) = invDet * (A(3, 2) * A(2, 1) - A(3, 1) * A(2, 2)); \ + B(3, 2) = -invDet * (A(3, 2) * A(1, 1) - A(3, 1) * A(1, 2)); \ + B(3, 3) = invDet * (A(2, 2) * A(1, 1) - A(2, 1) * A(1, 2)); \ + return 0; \ } #define A(y, x) src[(y - 1) * 3 + (x - 1)] @@ -97,7 +91,7 @@ generate_mat3inv_body(double, A, B) #undef generate_mat3inv_body -static void mat3mulv(float *dst, const float *const mat, const float *const v) + static void mat3mulv(float *dst, const float *const mat, const float *const v) { for(int k = 0; k < 3; k++) { @@ -236,8 +230,8 @@ static cmsHPROFILE dt_colorspaces_create_lab_profile() return cmsCreateLab4Profile(cmsD50_xyY()); } -static cmsHPROFILE _create_lcms_profile(const char *desc, const char *dmdd, - const cmsCIEXYZTRIPLE *primaries, const cmsToneCurve *trc, gboolean v2) +static cmsHPROFILE _create_lcms_profile(const char *desc, const char *dmdd, const cmsCIEXYZTRIPLE *primaries, + const cmsToneCurve *trc, gboolean v2) { cmsCIEXYZ black = { 0, 0, 0 }; @@ -245,8 +239,7 @@ static cmsHPROFILE _create_lcms_profile(const char *desc, const char *dmdd, if(!profile) return NULL; - if(v2) - cmsSetProfileVersion(profile, 2.1); + if(v2) cmsSetProfileVersion(profile, 2.1); cmsMLU *mlu0 = cmsMLUalloc(NULL, 1); cmsMLUsetASCII(mlu0, "en", "US", "Public Domain"); @@ -286,11 +279,11 @@ static cmsHPROFILE _create_lcms_profile(const char *desc, const char *dmdd, static cmsHPROFILE _colorspaces_create_srgb_profile(gboolean v2) { - cmsFloat64Number srgb_parameters[5] = { 2.4, 1.0 / 1.055, 0.055 / 1.055, 1.0 / 12.92, 0.04045 }; + cmsFloat64Number srgb_parameters[5] = { 2.4, 1.0 / 1.055, 0.055 / 1.055, 1.0 / 12.92, 0.04045 }; cmsToneCurve *transferFunction = cmsBuildParametricToneCurve(NULL, 4, srgb_parameters); - cmsHPROFILE profile = _create_lcms_profile("sRGB", "sRGB", - &rec709_primaries_pre_quantized, transferFunction, v2); + cmsHPROFILE profile + = _create_lcms_profile("sRGB", "sRGB", &rec709_primaries_pre_quantized, transferFunction, v2); cmsFreeToneCurve(transferFunction); @@ -310,15 +303,12 @@ static cmsHPROFILE dt_colorspaces_create_srgb_profile_v4() static cmsHPROFILE dt_colorspaces_create_brg_profile() { cmsCIEXYZTRIPLE primaries_pre_quantized = { - rec709_primaries_pre_quantized.Blue, - rec709_primaries_pre_quantized.Red, - rec709_primaries_pre_quantized.Green, + rec709_primaries_pre_quantized.Blue, rec709_primaries_pre_quantized.Red, rec709_primaries_pre_quantized.Green, }; - cmsFloat64Number srgb_parameters[5] = { 2.4, 1.0 / 1.055, 0.055 / 1.055, 1.0 / 12.92, 0.04045 }; + cmsFloat64Number srgb_parameters[5] = { 2.4, 1.0 / 1.055, 0.055 / 1.055, 1.0 / 12.92, 0.04045 }; cmsToneCurve *transferFunction = cmsBuildParametricToneCurve(NULL, 4, srgb_parameters); - cmsHPROFILE profile = _create_lcms_profile("BRG", "BRG", - &primaries_pre_quantized, transferFunction, TRUE); + cmsHPROFILE profile = _create_lcms_profile("BRG", "BRG", &primaries_pre_quantized, transferFunction, TRUE); cmsFreeToneCurve(transferFunction); @@ -331,8 +321,8 @@ static cmsHPROFILE dt_colorspaces_create_adobergb_profile(void) // AdobeRGB's "2.2" gamma is technically defined as 2 + 51/256 cmsToneCurve *transferFunction = cmsBuildGamma(NULL, 2.19921875); - cmsHPROFILE profile = _create_lcms_profile("Adobe RGB (compatible)", "Adobe RGB", - &adobe_primaries_prequantized, transferFunction, TRUE); + cmsHPROFILE profile = _create_lcms_profile("Adobe RGB (compatible)", "Adobe RGB", &adobe_primaries_prequantized, + transferFunction, TRUE); cmsFreeToneCurve(transferFunction); @@ -406,9 +396,8 @@ int dt_colorspaces_get_darktable_matrix(const char *makermodel, float *matrix) mat3mulv(cone_src_rgb, lam_rigg, dn); mat3mulv(cone_dst_rgb, lam_rigg, d50); - const float cone[9] - = { cone_dst_rgb[0] / cone_src_rgb[0], 0.0f, 0.0f, 0.0f, cone_dst_rgb[1] / cone_src_rgb[1], 0.0f, 0.0f, - 0.0f, cone_dst_rgb[2] / cone_src_rgb[2] }; + const float cone[9] = { cone_dst_rgb[0] / cone_src_rgb[0], 0.0f, 0.0f, 0.0f, cone_dst_rgb[1] / cone_src_rgb[1], + 0.0f, 0.0f, 0.0f, cone_dst_rgb[2] / cone_src_rgb[2] }; float tmp2[9]; float bradford[9]; @@ -623,9 +612,7 @@ static cmsHPROFILE dt_colorspaces_create_linear_infrared_profile(void) { // linear rgb with r and b swapped: cmsCIEXYZTRIPLE primaries_pre_quantized = { - rec709_primaries_pre_quantized.Blue, - rec709_primaries_pre_quantized.Green, - rec709_primaries_pre_quantized.Red, + rec709_primaries_pre_quantized.Blue, rec709_primaries_pre_quantized.Green, rec709_primaries_pre_quantized.Red, }; cmsToneCurve *transferFunction = build_linear_gamma(); @@ -678,7 +665,8 @@ const dt_colorspaces_color_profile_t *dt_colorspaces_get_output_profile(const in if(over_type != DT_COLORSPACE_NONE) { // return the profile specified in export - p = dt_colorspaces_get_profile(over_type, over_filename, DT_PROFILE_DIRECTION_OUT | DT_PROFILE_DIRECTION_DISPLAY); + p = dt_colorspaces_get_profile(over_type, over_filename, + DT_PROFILE_DIRECTION_OUT | DT_PROFILE_DIRECTION_DISPLAY); } else if(colorout && colorout->get_p) { @@ -686,9 +674,9 @@ const dt_colorspaces_color_profile_t *dt_colorspaces_get_output_profile(const in // FIXME: does this work when using JPEG thumbs and the image was never opened? sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2( - dt_database_get(darktable.db), - "SELECT op_params FROM main.history WHERE imgid=?1 AND operation='colorout' ORDER BY num DESC LIMIT 1", -1, - &stmt, NULL); + dt_database_get(darktable.db), + "SELECT op_params FROM main.history WHERE imgid=?1 AND operation='colorout' ORDER BY num DESC LIMIT 1", -1, + &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); if(sqlite3_step(stmt) == SQLITE_ROW) { @@ -697,8 +685,8 @@ const dt_colorspaces_color_profile_t *dt_colorspaces_get_output_profile(const in dt_colorspaces_color_profile_type_t *type = colorout->get_p(params, "type"); char *filename = colorout->get_p(params, "filename"); - if(type && filename) p = dt_colorspaces_get_profile(*type, filename, - DT_PROFILE_DIRECTION_OUT | DT_PROFILE_DIRECTION_DISPLAY); + if(type && filename) + p = dt_colorspaces_get_profile(*type, filename, DT_PROFILE_DIRECTION_OUT | DT_PROFILE_DIRECTION_DISPLAY); } sqlite3_finalize(stmt); } @@ -943,28 +931,17 @@ void hsl2rgb(float rgb[3], float h, float s, float l) rgb[2] = hue2rgb(m1, m2, h - (1.0 / 3.0)); } -static const char *_profile_names[] = -{ - "", // 0th entry is a dummy for DT_COLORSPACE_FILE and not used - N_("sRGB"), // this is only used in error messages, no need for the (...) description - N_("Adobe RGB (compatible)"), - N_("linear Rec709 RGB"), - N_("linear Rec2020 RGB"), - N_("linear XYZ"), - N_("Lab"), - N_("linear infrared BGR"), - N_("system display profile"), - N_("embedded ICC profile"), - N_("embedded matrix"), - N_("standard color matrix"), - N_("enhanced color matrix"), - N_("vendor color matrix"), - N_("alternate color matrix") -}; +static const char *_profile_names[] + = { "", // 0th entry is a dummy for DT_COLORSPACE_FILE and not used + N_("sRGB"), // this is only used in error messages, no need for the (...) description + N_("Adobe RGB (compatible)"), N_("linear Rec709 RGB"), N_("linear Rec2020 RGB"), N_("linear XYZ"), + N_("Lab"), N_("linear infrared BGR"), N_("system display profile"), N_("embedded ICC profile"), + N_("embedded matrix"), N_("standard color matrix"), N_("enhanced color matrix"), N_("vendor color matrix"), + N_("alternate color matrix") }; static dt_colorspaces_color_profile_t *_create_profile(dt_colorspaces_color_profile_type_t type, - cmsHPROFILE profile, const char *name, - int in_pos, int out_pos, int display_pos) + cmsHPROFILE profile, const char *name, int in_pos, + int out_pos, int display_pos) { dt_colorspaces_color_profile_t *prof; prof = (dt_colorspaces_color_profile_t *)calloc(1, sizeof(dt_colorspaces_color_profile_t)); @@ -986,28 +963,19 @@ static void _update_display_transforms(dt_colorspaces_t *self) if(self->transform_adobe_rgb_to_display) cmsDeleteTransform(self->transform_adobe_rgb_to_display); self->transform_adobe_rgb_to_display = NULL; - const dt_colorspaces_color_profile_t *display_dt_profile = _get_profile(self, self->display_type, - self->display_filename, - DT_PROFILE_DIRECTION_DISPLAY); + const dt_colorspaces_color_profile_t *display_dt_profile + = _get_profile(self, self->display_type, self->display_filename, DT_PROFILE_DIRECTION_DISPLAY); if(!display_dt_profile) return; cmsHPROFILE display_profile = display_dt_profile->profile; if(!display_profile) return; - self->transform_srgb_to_display = cmsCreateTransform(_get_profile(self, DT_COLORSPACE_SRGB, "", - DT_PROFILE_DIRECTION_DISPLAY)->profile, - TYPE_RGBA_8, - display_profile, - TYPE_BGRA_8, - self->display_intent, - 0); - - self->transform_adobe_rgb_to_display = cmsCreateTransform(_get_profile(self, DT_COLORSPACE_ADOBERGB, "", - DT_PROFILE_DIRECTION_DISPLAY)->profile, - TYPE_RGBA_8, - display_profile, - TYPE_BGRA_8, - self->display_intent, - 0); + self->transform_srgb_to_display + = cmsCreateTransform(_get_profile(self, DT_COLORSPACE_SRGB, "", DT_PROFILE_DIRECTION_DISPLAY)->profile, + TYPE_RGBA_8, display_profile, TYPE_BGRA_8, self->display_intent, 0); + + self->transform_adobe_rgb_to_display + = cmsCreateTransform(_get_profile(self, DT_COLORSPACE_ADOBERGB, "", DT_PROFILE_DIRECTION_DISPLAY)->profile, + TYPE_RGBA_8, display_profile, TYPE_BGRA_8, self->display_intent, 0); } // update cached transforms for color management of thumbnails @@ -1034,8 +1002,7 @@ static void _update_display_profile(guchar *tmp_data, gsize size, char *name, si { if(p->profile) dt_colorspaces_cleanup_profile(p->profile); p->profile = profile; - if(name) - dt_colorspaces_get_profile_name(profile, "en", "US", name, name_size); + if(name) dt_colorspaces_get_profile_name(profile, "en", "US", name, name_size); // update cached transforms for color management of thumbnails dt_colorspaces_update_display_transforms(); @@ -1113,7 +1080,8 @@ static GList *load_profile_from_dir(const char *subdir) tmpprof = _ensure_rgb_profile(cmsOpenProfileFromMem(icc_content, end * sizeof(char))); if(tmpprof) { - dt_colorspaces_color_profile_t *prof = (dt_colorspaces_color_profile_t *)calloc(1, sizeof(dt_colorspaces_color_profile_t)); + dt_colorspaces_color_profile_t *prof + = (dt_colorspaces_color_profile_t *)calloc(1, sizeof(dt_colorspaces_color_profile_t)); dt_colorspaces_get_profile_name(tmpprof, lang, lang + 3, prof->name, sizeof(prof->name)); g_strlcpy(prof->filename, d_name, sizeof(prof->filename)); @@ -1126,7 +1094,7 @@ static GList *load_profile_from_dir(const char *subdir) temp_profiles = g_list_append(temp_profiles, prof); } -icc_loading_done: + icc_loading_done: if(fd) fclose(fd); free(icc_content); } @@ -1147,62 +1115,51 @@ dt_colorspaces_t *dt_colorspaces_init() pthread_rwlock_init(&res->xprofile_lock, NULL); - int in_pos = -1, - out_pos = -1, - display_pos = -1; + int in_pos = -1, out_pos = -1, display_pos = -1; - // init the display profile with srgb so some stupid code that runs before the real profile could be fetched has something to work with - res->profiles = g_list_append(res->profiles, _create_profile(DT_COLORSPACE_DISPLAY, dt_colorspaces_create_srgb_profile(), - _("system display profile"), -1, -1, ++display_pos)); + // init the display profile with srgb so some stupid code that runs before the real profile could be fetched has + // something to work with + res->profiles + = g_list_append(res->profiles, _create_profile(DT_COLORSPACE_DISPLAY, dt_colorspaces_create_srgb_profile(), + _("system display profile"), -1, -1, ++display_pos)); // we want a v4 with parametric curve for input and a v2 with point trc for output // see http://ninedegreesbelow.com/photography/lcms-make-icc-profiles.html#profile-variants-and-versions // TODO: what about display? - res->profiles = g_list_append(res->profiles, _create_profile(DT_COLORSPACE_SRGB, - dt_colorspaces_create_srgb_profile_v4(), - _("sRGB (e.g. JPG)"), - ++in_pos, -1, -1)); - - res->profiles = g_list_append(res->profiles, _create_profile(DT_COLORSPACE_SRGB, - dt_colorspaces_create_srgb_profile(), - _("sRGB (web-safe)"), - -1, ++out_pos, ++display_pos)); - - res->profiles = g_list_append(res->profiles, _create_profile(DT_COLORSPACE_ADOBERGB, - dt_colorspaces_create_adobergb_profile(), - _("Adobe RGB (compatible)"), - ++in_pos, ++out_pos, ++display_pos)); - - res->profiles = g_list_append(res->profiles, _create_profile(DT_COLORSPACE_LIN_REC709, - dt_colorspaces_create_linear_rec709_rgb_profile(), - _("linear Rec709 RGB"), - ++in_pos, ++out_pos, ++display_pos)); - - res->profiles = g_list_append(res->profiles, _create_profile(DT_COLORSPACE_LIN_REC2020, - dt_colorspaces_create_linear_rec2020_rgb_profile(), - _("linear Rec2020 RGB"), - ++in_pos, ++out_pos, ++display_pos)); - - res->profiles = g_list_append(res->profiles, _create_profile(DT_COLORSPACE_XYZ, - dt_colorspaces_create_xyz_profile(), - _("linear XYZ"), - ++in_pos, - dt_conf_get_bool("allow_lab_output") ? ++out_pos : -1, -1)); - - res->profiles = g_list_append(res->profiles, _create_profile(DT_COLORSPACE_LAB, - dt_colorspaces_create_lab_profile(), - _("Lab"), - ++in_pos, - dt_conf_get_bool("allow_lab_output") ? ++out_pos : -1, -1)); + res->profiles + = g_list_append(res->profiles, _create_profile(DT_COLORSPACE_SRGB, dt_colorspaces_create_srgb_profile_v4(), + _("sRGB (e.g. JPG)"), ++in_pos, -1, -1)); + + res->profiles + = g_list_append(res->profiles, _create_profile(DT_COLORSPACE_SRGB, dt_colorspaces_create_srgb_profile(), + _("sRGB (web-safe)"), -1, ++out_pos, ++display_pos)); + + res->profiles = g_list_append(res->profiles, + _create_profile(DT_COLORSPACE_ADOBERGB, dt_colorspaces_create_adobergb_profile(), + _("Adobe RGB (compatible)"), ++in_pos, ++out_pos, ++display_pos)); + + res->profiles = g_list_append( + res->profiles, _create_profile(DT_COLORSPACE_LIN_REC709, dt_colorspaces_create_linear_rec709_rgb_profile(), + _("linear Rec709 RGB"), ++in_pos, ++out_pos, ++display_pos)); + + res->profiles = g_list_append( + res->profiles, _create_profile(DT_COLORSPACE_LIN_REC2020, dt_colorspaces_create_linear_rec2020_rgb_profile(), + _("linear Rec2020 RGB"), ++in_pos, ++out_pos, ++display_pos)); + + res->profiles = g_list_append( + res->profiles, _create_profile(DT_COLORSPACE_XYZ, dt_colorspaces_create_xyz_profile(), _("linear XYZ"), + ++in_pos, dt_conf_get_bool("allow_lab_output") ? ++out_pos : -1, -1)); + + res->profiles = g_list_append( + res->profiles, _create_profile(DT_COLORSPACE_LAB, dt_colorspaces_create_lab_profile(), _("Lab"), ++in_pos, + dt_conf_get_bool("allow_lab_output") ? ++out_pos : -1, -1)); res->profiles = g_list_append(res->profiles, _create_profile(DT_COLORSPACE_INFRARED, dt_colorspaces_create_linear_infrared_profile(), - _("linear infrared BGR"), - ++in_pos, -1, -1)); + _("linear infrared BGR"), ++in_pos, -1, -1)); - res->profiles = g_list_append(res->profiles, _create_profile(DT_COLORSPACE_BRG, - dt_colorspaces_create_brg_profile(), - _("BRG (for testing)"), - ++in_pos, ++out_pos, ++display_pos)); + res->profiles + = g_list_append(res->profiles, _create_profile(DT_COLORSPACE_BRG, dt_colorspaces_create_brg_profile(), + _("BRG (for testing)"), ++in_pos, ++out_pos, ++display_pos)); // temporary list of profiles to be added, we keep this separate to be able to sort it before adding GList *temp_profiles; @@ -1239,12 +1196,12 @@ dt_colorspaces_t *dt_colorspaces_init() res->softproof_intent = dt_conf_get_int("ui_last/color/softproof_intent"); res->mode = dt_conf_get_int("ui_last/color/mode"); if((unsigned int)res->display_type >= DT_COLORSPACE_LAST - || (res->display_type == DT_COLORSPACE_FILE - && (!res->display_filename[0] || !g_file_test(res->display_filename, G_FILE_TEST_IS_REGULAR)))) + || (res->display_type == DT_COLORSPACE_FILE + && (!res->display_filename[0] || !g_file_test(res->display_filename, G_FILE_TEST_IS_REGULAR)))) res->display_type = DT_COLORSPACE_DISPLAY; if((unsigned int)res->softproof_type >= DT_COLORSPACE_LAST - || (res->softproof_type == DT_COLORSPACE_FILE - && (!res->softproof_filename[0] || !g_file_test(res->softproof_filename, G_FILE_TEST_IS_REGULAR)))) + || (res->softproof_type == DT_COLORSPACE_FILE + && (!res->softproof_filename[0] || !g_file_test(res->softproof_filename, G_FILE_TEST_IS_REGULAR)))) res->softproof_type = DT_COLORSPACE_SRGB; if((unsigned int)res->mode > DT_PROFILE_GAMUTCHECK) res->mode = DT_PROFILE_NORMAL; @@ -1294,7 +1251,8 @@ const char *dt_colorspaces_get_name(dt_colorspaces_color_profile_type_t type, co } #ifdef USE_COLORDGTK -static void dt_colorspaces_get_display_profile_colord_callback(GObject *source, GAsyncResult *res, gpointer user_data) +static void dt_colorspaces_get_display_profile_colord_callback(GObject *source, GAsyncResult *res, + gpointer user_data) { pthread_rwlock_wrlock(&darktable.color_profiles->xprofile_lock); @@ -1319,12 +1277,12 @@ static void dt_colorspaces_get_display_profile_colord_callback(GObject *source, gsize size; g_file_get_contents(filename, (gchar **)&tmp_data, &size, NULL); profile_changed = size > 0 && (darktable.color_profiles->xprofile_size != size - || memcmp(darktable.color_profiles->xprofile_data, tmp_data, size) != 0); + || memcmp(darktable.color_profiles->xprofile_data, tmp_data, size) != 0); if(profile_changed) { _update_display_profile(tmp_data, size, NULL, 0); - dt_print(DT_DEBUG_CONTROL, - "[color profile] colord gave us a new screen profile: '%s' (size: %zu)\n", filename, size); + dt_print(DT_DEBUG_CONTROL, "[color profile] colord gave us a new screen profile: '%s' (size: %zu)\n", + filename, size); } else { @@ -1513,10 +1471,10 @@ static const dt_colorspaces_color_profile_t *_get_profile(dt_colorspaces_t *self for(GList *iter = self->profiles; iter; iter = g_list_next(iter)) { dt_colorspaces_color_profile_t *p = (dt_colorspaces_color_profile_t *)iter->data; - if(((direction & DT_PROFILE_DIRECTION_IN && p->in_pos > -1) || - (direction & DT_PROFILE_DIRECTION_OUT && p->out_pos > -1) || - (direction & DT_PROFILE_DIRECTION_DISPLAY && p->display_pos > -1)) && - (p->type == type && (type != DT_COLORSPACE_FILE || !strcmp(p->filename, filename)))) + if(((direction & DT_PROFILE_DIRECTION_IN && p->in_pos > -1) + || (direction & DT_PROFILE_DIRECTION_OUT && p->out_pos > -1) + || (direction & DT_PROFILE_DIRECTION_DISPLAY && p->display_pos > -1)) + && (p->type == type && (type != DT_COLORSPACE_FILE || !strcmp(p->filename, filename)))) { return p; } @@ -1537,41 +1495,38 @@ static void dt_colorspaces_pseudoinverse(double (*in)[3], double (*out)[3], int { double work[3][6], num; - for(int i = 0; i < 3; i++) { - for(int j = 0; j < 6; j++) - work[i][j] = j == i+3; + for(int i = 0; i < 3; i++) + { + for(int j = 0; j < 6; j++) work[i][j] = j == i + 3; for(int j = 0; j < 3; j++) - for(int k = 0; k < size; k++) - work[i][j] += in[k][i] * in[k][j]; + for(int k = 0; k < size; k++) work[i][j] += in[k][i] * in[k][j]; } - for(int i = 0; i < 3; i++) { + for(int i = 0; i < 3; i++) + { num = work[i][i]; - for(int j = 0; j < 6; j++) - work[i][j] /= num; - for(int k = 0; k < 3; k++) { - if(k==i) continue; + for(int j = 0; j < 6; j++) work[i][j] /= num; + for(int k = 0; k < 3; k++) + { + if(k == i) continue; num = work[k][i]; - for(int j = 0; j < 6; j++) - work[k][j] -= work[i][j] * num; + for(int j = 0; j < 6; j++) work[k][j] -= work[i][j] * num; } } for(int i = 0; i < size; i++) for(int j = 0; j < 3; j++) { out[i][j] = 0.0f; - for(int k = 0; k < 3; k++) - out[i][j] += work[j][k+3] * in[i][k]; + for(int k = 0; k < 3; k++) out[i][j] += work[j][k + 3] * in[i][k]; } } -int dt_colorspaces_conversion_matrices_xyz(const char *name, float in_XYZ_to_CAM[9], double XYZ_to_CAM[4][3], double CAM_to_XYZ[3][4]) +int dt_colorspaces_conversion_matrices_xyz(const char *name, float in_XYZ_to_CAM[9], double XYZ_to_CAM[4][3], + double CAM_to_XYZ[3][4]) { if(!isnan(in_XYZ_to_CAM[0])) { - for(int i = 0; i < 9; i++) - XYZ_to_CAM[i/3][i%3] = (double) in_XYZ_to_CAM[i]; - for(int i = 0; i < 3; i++) - XYZ_to_CAM[3][i] = 0.0f; + for(int i = 0; i < 9; i++) XYZ_to_CAM[i / 3][i % 3] = (double)in_XYZ_to_CAM[i]; + for(int i = 0; i < 3; i++) XYZ_to_CAM[3][i] = 0.0f; } else { @@ -1579,37 +1534,34 @@ int dt_colorspaces_conversion_matrices_xyz(const char *name, float in_XYZ_to_CAM adobe_XYZ_to_CAM[0][0] = NAN; dt_dcraw_adobe_coeff(name, (float(*)[12])adobe_XYZ_to_CAM); - if(isnan(adobe_XYZ_to_CAM[0][0])) - return FALSE; + if(isnan(adobe_XYZ_to_CAM[0][0])) return FALSE; for(int i = 0; i < 4; i++) - for(int j = 0; j < 3; j++) - XYZ_to_CAM[i][j] = (double) adobe_XYZ_to_CAM[i][j]; + for(int j = 0; j < 3; j++) XYZ_to_CAM[i][j] = (double)adobe_XYZ_to_CAM[i][j]; } // Invert the matrix double inverse[4][3]; - dt_colorspaces_pseudoinverse (XYZ_to_CAM, inverse, 4); + dt_colorspaces_pseudoinverse(XYZ_to_CAM, inverse, 4); for(int i = 0; i < 3; i++) - for(int j = 0; j < 4; j++) - CAM_to_XYZ[i][j] = inverse[j][i]; + for(int j = 0; j < 4; j++) CAM_to_XYZ[i][j] = inverse[j][i]; return TRUE; } // Converted from dcraw's cam_xyz_coeff() -int dt_colorspaces_conversion_matrices_rgb(const char *name, double out_RGB_to_CAM[4][3], double out_CAM_to_RGB[3][4], double mul[4]) +int dt_colorspaces_conversion_matrices_rgb(const char *name, double out_RGB_to_CAM[4][3], + double out_CAM_to_RGB[3][4], double mul[4]) { double RGB_to_CAM[4][3]; float XYZ_to_CAM[4][3]; XYZ_to_CAM[0][0] = NAN; dt_dcraw_adobe_coeff(name, (float(*)[12])XYZ_to_CAM); - if(isnan(XYZ_to_CAM[0][0])) - return FALSE; + if(isnan(XYZ_to_CAM[0][0])) return FALSE; const double RGB_to_XYZ[3][3] = { - // sRGB D65 + // sRGB D65 { 0.412453, 0.357580, 0.180423 }, { 0.212671, 0.715160, 0.072169 }, { 0.019334, 0.119193, 0.950227 }, @@ -1620,53 +1572,49 @@ int dt_colorspaces_conversion_matrices_rgb(const char *name, double out_RGB_to_C for(int j = 0; j < 3; j++) { RGB_to_CAM[i][j] = 0.0f; - for(int k = 0; k < 3; k++) - RGB_to_CAM[i][j] += XYZ_to_CAM[i][k] * RGB_to_XYZ[k][j]; + for(int k = 0; k < 3; k++) RGB_to_CAM[i][j] += XYZ_to_CAM[i][k] * RGB_to_XYZ[k][j]; } // Normalize cam_rgb so that cam_rgb * (1,1,1) is (1,1,1,1) - for(int i = 0; i < 4; i++) { + for(int i = 0; i < 4; i++) + { double num = 0.0f; - for(int j = 0; j < 3; j++) - num += RGB_to_CAM[i][j]; - for(int j = 0; j < 3; j++) - RGB_to_CAM[i][j] /= num; + for(int j = 0; j < 3; j++) num += RGB_to_CAM[i][j]; + for(int j = 0; j < 3; j++) RGB_to_CAM[i][j] /= num; if(mul) mul[i] = 1.0f / num; } if(out_RGB_to_CAM) for(int i = 0; i < 4; i++) - for(int j = 0; j < 3; j++) - out_RGB_to_CAM[i][j] = RGB_to_CAM[i][j]; + for(int j = 0; j < 3; j++) out_RGB_to_CAM[i][j] = RGB_to_CAM[i][j]; if(out_CAM_to_RGB) { // Invert the matrix double inverse[4][3]; - dt_colorspaces_pseudoinverse (RGB_to_CAM, inverse, 4); + dt_colorspaces_pseudoinverse(RGB_to_CAM, inverse, 4); for(int i = 0; i < 3; i++) - for(int j = 0; j < 4; j++) - out_CAM_to_RGB[i][j] = inverse[j][i]; + for(int j = 0; j < 4; j++) out_CAM_to_RGB[i][j] = inverse[j][i]; } return TRUE; } -void dt_colorspaces_cygm_apply_coeffs_to_rgb(float *out, const float *in, int num, double RGB_to_CAM[4][3], double CAM_to_RGB[3][4], float coeffs[4]) +void dt_colorspaces_cygm_apply_coeffs_to_rgb(float *out, const float *in, int num, double RGB_to_CAM[4][3], + double CAM_to_RGB[3][4], float coeffs[4]) { // Create the CAM to RGB with applied WB matrix double CAM_to_RGB_WB[3][4]; - for (int a=0; a<3; a++) - for (int b=0; b<4; b++) - CAM_to_RGB_WB[a][b] = CAM_to_RGB[a][b] * coeffs[b]; + for(int a = 0; a < 3; a++) + for(int b = 0; b < 4; b++) CAM_to_RGB_WB[a][b] = CAM_to_RGB[a][b] * coeffs[b]; // Create the RGB->RGB+WB matrix double RGB_to_RGB_WB[3][3]; - for (int a=0; a<3; a++) - for (int b=0; b<3; b++) { + for(int a = 0; a < 3; a++) + for(int b = 0; b < 3; b++) + { RGB_to_RGB_WB[a][b] = 0.0f; - for (int c=0; c<4; c++) - RGB_to_RGB_WB[a][b] += CAM_to_RGB_WB[a][c] * RGB_to_CAM[c][b]; + for(int c = 0; c < 4; c++) RGB_to_RGB_WB[a][b] += CAM_to_RGB_WB[a][c] * RGB_to_CAM[c][b]; } #ifdef _OPENMP @@ -1674,12 +1622,11 @@ void dt_colorspaces_cygm_apply_coeffs_to_rgb(float *out, const float *in, int nu #endif for(int i = 0; i < num; i++) { - const float *inpos = &in[i*4]; - float *outpos = &out[i*4]; - outpos[0]=outpos[1]=outpos[2] = 0.0f; - for (int a=0; a<3; a++) - for (int b=0; b<3; b++) - outpos[a] += RGB_to_RGB_WB[a][b] * inpos[b]; + const float *inpos = &in[i * 4]; + float *outpos = &out[i * 4]; + outpos[0] = outpos[1] = outpos[2] = 0.0f; + for(int a = 0; a < 3; a++) + for(int b = 0; b < 3; b++) outpos[a] += RGB_to_RGB_WB[a][b] * inpos[b]; } } @@ -1690,13 +1637,11 @@ void dt_colorspaces_cygm_to_rgb(float *out, int num, double CAM_to_RGB[3][4]) #endif for(int i = 0; i < num; i++) { - float *in = &out[i*4]; - float o[3] = {0.0f,0.0f,0.0f}; + float *in = &out[i * 4]; + float o[3] = { 0.0f, 0.0f, 0.0f }; for(int c = 0; c < 3; c++) - for(int k = 0; k < 4; k++) - o[c] += CAM_to_RGB[c][k] * in[k]; - for(int c = 0; c < 3; c++) - in[c] = o[c]; + for(int k = 0; k < 4; k++) o[c] += CAM_to_RGB[c][k] * in[k]; + for(int c = 0; c < 3; c++) in[c] = o[c]; } } @@ -1707,13 +1652,11 @@ void dt_colorspaces_rgb_to_cygm(float *out, int num, double RGB_to_CAM[4][3]) #endif for(int i = 0; i < num; i++) { - float *in = &out[i*3]; - float o[4] = {0.0f,0.0f,0.0f,0.0f}; - for(int c = 0; c < 4; c++) - for(int k = 0; k < 3; k++) - o[c] += RGB_to_CAM[c][k] * in[k]; + float *in = &out[i * 3]; + float o[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; for(int c = 0; c < 4; c++) - in[c] = o[c]; + for(int k = 0; k < 3; k++) o[c] += RGB_to_CAM[c][k] * in[k]; + for(int c = 0; c < 4; c++) in[c] = o[c]; } } diff --git a/src/common/colorspaces.h b/src/common/colorspaces.h index 661c36f71dc9..63aacc758fef 100644 --- a/src/common/colorspaces.h +++ b/src/common/colorspaces.h @@ -25,7 +25,7 @@ // this was removed from lcms2 in 2.4 #ifndef TYPE_XYZA_FLT - #define TYPE_XYZA_FLT (FLOAT_SH(1)|COLORSPACE_SH(PT_XYZ)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(4)) +#define TYPE_XYZA_FLT (FLOAT_SH(1) | COLORSPACE_SH(PT_XYZ) | EXTRA_SH(1) | CHANNELS_SH(3) | BYTES_SH(4)) #endif // constants fit to the ones from lcms.h: @@ -172,22 +172,25 @@ void hsl2rgb(float rgb[3], float h, float s, float l); void dt_colorspaces_set_display_profile(); /** get the profile described by type & filename. * this doesn't support image specifics like embedded profiles or camera matrices */ -const dt_colorspaces_color_profile_t * -dt_colorspaces_get_profile(dt_colorspaces_color_profile_type_t type, const char *filename, - dt_colorspaces_profile_direction_t direction); +const dt_colorspaces_color_profile_t *dt_colorspaces_get_profile(dt_colorspaces_color_profile_type_t type, + const char *filename, + dt_colorspaces_profile_direction_t direction); /** update the display transforms of srgb and adobergb to the display profile. * make sure that darktable.color_profiles->xprofile_lock is held when calling this! */ void dt_colorspaces_update_display_transforms(); /** Calculate CAM->XYZ, XYZ->CAM matrices **/ -int dt_colorspaces_conversion_matrices_xyz(const char *name, float in_XYZ_to_CAM[9], double XYZ_to_CAM[4][3], double CAM_to_XYZ[3][4]); +int dt_colorspaces_conversion_matrices_xyz(const char *name, float in_XYZ_to_CAM[9], double XYZ_to_CAM[4][3], + double CAM_to_XYZ[3][4]); /** Calculate CAM->RGB, RGB->CAM matrices and default WB multipliers */ -int dt_colorspaces_conversion_matrices_rgb(const char *name, double RGB_to_CAM[4][3], double CAM_to_RGB[3][4], double mul[4]); +int dt_colorspaces_conversion_matrices_rgb(const char *name, double RGB_to_CAM[4][3], double CAM_to_RGB[3][4], + double mul[4]); /** Applies CYGM WB coeffs to an image that's already been converted to RGB by dt_colorspaces_cygm_to_rgb */ -void dt_colorspaces_cygm_apply_coeffs_to_rgb(float *out, const float *in, int num, double RGB_to_CAM[4][3], double CAM_to_RGB[3][4], float coeffs[4]); +void dt_colorspaces_cygm_apply_coeffs_to_rgb(float *out, const float *in, int num, double RGB_to_CAM[4][3], + double CAM_to_RGB[3][4], float coeffs[4]); /** convert CYGM buffer to RGB */ void dt_colorspaces_cygm_to_rgb(float *out, int num, double CAM_to_RGB[3][4]); diff --git a/src/common/convolution.c b/src/common/convolution.c index ff5399257648..4d4422b7f414 100644 --- a/src/common/convolution.c +++ b/src/common/convolution.c @@ -40,148 +40,145 @@ // // Code adapted from gsl/fft/factorize.c -static void fftw3_factorize (const int n, int *n_factors, int factors[], int * implemented_factors) +static void fftw3_factorize(const int n, int *n_factors, int factors[], int *implemented_factors) { - int nf = 0; - int ntest = n; - int factor; - int i = 0; - - if (n == 0) - { - printf("Length n must be positive integer\n"); - return ; - } - - if (n == 1) - { - factors[0] = 1; - *n_factors = 1; - return ; - } - - /* deal with the implemented factors */ - while (implemented_factors[i] && ntest != 1) - { - factor = implemented_factors[i]; - while ((ntest % factor) == 0) - { - ntest = ntest / factor; - factors[nf] = factor; - nf++; - } - i++; - } - - // Ok that's it - if(ntest != 1) - { - factors[nf] = ntest; - nf++; - } - - /* check that the factorization is correct */ - { - int product = 1; - - for (i = 0; i < nf; i++) - { - product *= factors[i]; - } - - if (product != n) - { - printf("factorization failed"); - } - } - - *n_factors = nf; + int nf = 0; + int ntest = n; + int factor; + int i = 0; + + if(n == 0) + { + printf("Length n must be positive integer\n"); + return; + } + + if(n == 1) + { + factors[0] = 1; + *n_factors = 1; + return; + } + + /* deal with the implemented factors */ + while(implemented_factors[i] && ntest != 1) + { + factor = implemented_factors[i]; + while((ntest % factor) == 0) + { + ntest = ntest / factor; + factors[nf] = factor; + nf++; + } + i++; + } + + // Ok that's it + if(ntest != 1) + { + factors[nf] = ntest; + nf++; + } + + /* check that the factorization is correct */ + { + int product = 1; + + for(i = 0; i < nf; i++) + { + product *= factors[i]; + } + + if(product != n) + { + printf("factorization failed"); + } + } + + *n_factors = nf; } -static int fftw3_is_optimal(int n, int * implemented_factors) +static int fftw3_is_optimal(int n, int *implemented_factors) { - // We check that n is not a multiple of 4*4*4*2 - if(n % 4*4*4*2 == 0) - return 0; - - int nf = 0; - int factors[64]; - int i = 0; - - fftw3_factorize(n, &nf, factors,implemented_factors); - - // We just have to check if the last factor belongs to GSL_FACTORS - while(implemented_factors[i]) - { - if(factors[nf-1] == implemented_factors[i]) - return 1; - ++i; - } - - return 0; + // We check that n is not a multiple of 4*4*4*2 + if(n % 4 * 4 * 4 * 2 == 0) return 0; + + int nf = 0; + int factors[64]; + int i = 0; + + fftw3_factorize(n, &nf, factors, implemented_factors); + + // We just have to check if the last factor belongs to GSL_FACTORS + while(implemented_factors[i]) + { + if(factors[nf - 1] == implemented_factors[i]) return 1; + ++i; + } + + return 0; } -static int fftw3_find_closest_factor(int n, int * implemented_factor) +static int fftw3_find_closest_factor(int n, int *implemented_factor) { - int j; - if (fftw3_is_optimal(n,implemented_factor)) - return n; - else - { - j = n+1; - while (!fftw3_is_optimal(j,implemented_factor)) - ++j; - return j; - } + int j; + if(fftw3_is_optimal(n, implemented_factor)) + return n; + else + { + j = n + 1; + while(!fftw3_is_optimal(j, implemented_factor)) ++j; + return j; + } } - + void fftw3_convolve_free(fftw3_convolve_t *fftw_conv, double *time) { FFTW3_TIME_DECL - if (fftw_conv) - { - FFTW3_TIME_BEGIN - dt_pthread_mutex_lock(&darktable.plugin_threadsafe); - FFTW3_TIME_END(TIME_FFTW3_LOCK) - - FFTW3_TIME_BEGIN - if (fftw_conv->plan_src) fftwf_destroy_plan(fftw_conv->plan_src); - if (fftw_conv->plan_kernel) fftwf_destroy_plan(fftw_conv->plan_kernel); - if (fftw_conv->plan_inv) fftwf_destroy_plan(fftw_conv->plan_inv); - FFTW3_TIME_END(TIME_FFTW3_PLAN) - - if (fftw_conv->in_src) fftwf_free(fftw_conv->in_src); - if (fftw_conv->out_src) fftwf_free(fftw_conv->out_src); - if (fftw_conv->in_kernel) fftwf_free(fftw_conv->in_kernel); - if (fftw_conv->out_kernel) fftwf_free(fftw_conv->out_kernel); - - FFTW3_TIME_BEGIN - dt_pthread_mutex_unlock(&darktable.plugin_threadsafe); - FFTW3_TIME_END(TIME_FFTW3_LOCK) - - free(fftw_conv); - } + if(fftw_conv) + { + FFTW3_TIME_BEGIN + dt_pthread_mutex_lock(&darktable.plugin_threadsafe); + FFTW3_TIME_END(TIME_FFTW3_LOCK) + + FFTW3_TIME_BEGIN + if(fftw_conv->plan_src) fftwf_destroy_plan(fftw_conv->plan_src); + if(fftw_conv->plan_kernel) fftwf_destroy_plan(fftw_conv->plan_kernel); + if(fftw_conv->plan_inv) fftwf_destroy_plan(fftw_conv->plan_inv); + FFTW3_TIME_END(TIME_FFTW3_PLAN) + + if(fftw_conv->in_src) fftwf_free(fftw_conv->in_src); + if(fftw_conv->out_src) fftwf_free(fftw_conv->out_src); + if(fftw_conv->in_kernel) fftwf_free(fftw_conv->in_kernel); + if(fftw_conv->out_kernel) fftwf_free(fftw_conv->out_kernel); + + FFTW3_TIME_BEGIN + dt_pthread_mutex_unlock(&darktable.plugin_threadsafe); + FFTW3_TIME_END(TIME_FFTW3_LOCK) + + free(fftw_conv); + } } -fftw3_convolve_t * fftw3_convolve_init(const int width_src, const int height_src, const int ch, - const int width_kernel, const int height_kernel, - const int width_dest, const int height_dest, const int mode, double *time) +fftw3_convolve_t *fftw3_convolve_init(const int width_src, const int height_src, const int ch, + const int width_kernel, const int height_kernel, const int width_dest, + const int height_dest, const int mode, double *time) { - fftw3_convolve_t *fftw_conv = calloc(1, sizeof(fftw3_convolve_t)); - if (fftw_conv) - { + fftw3_convolve_t *fftw_conv = calloc(1, sizeof(fftw3_convolve_t)); + if(fftw_conv) + { #ifdef HAVE_FFTW3_OMP #ifdef _OPENMP - - fftwf_plan_with_nthreads(dt_get_num_threads()); - + + fftwf_plan_with_nthreads(dt_get_num_threads()); + #endif #endif - - FFTW3_TIME_DECL - int FFTW_FACTORS[7] = {13,11,7,5,3,2,0}; // end with zero to detect the end of the array + FFTW3_TIME_DECL + + int FFTW_FACTORS[7] = { 13, 11, 7, 5, 3, 2, 0 }; // end with zero to detect the end of the array fftw_conv->width_src = width_src; fftw_conv->height_src = height_src; @@ -192,115 +189,120 @@ fftw3_convolve_t * fftw3_convolve_init(const int width_src, const int height_src fftw_conv->height_dest = height_dest; fftw_conv->mode = mode; - fftw_conv->width_fft = 0; - fftw_conv->height_fft = 0; - - if (fftw_conv->mode == convolve_mode_full) - { - fftw_conv->height_fft = fftw_conv->height_src + fftw_conv->height_kernel - 1; - fftw_conv->width_fft = fftw_conv->width_src + fftw_conv->width_kernel - 1; - } - else if (fftw_conv->mode == convolve_mode_valid) - { - fftw_conv->height_fft = fftw_conv->height_src; - fftw_conv->width_fft = fftw_conv->width_src; - } - else - { - printf("fftw3_convolve: unknown mode=%i\n", fftw_conv->mode); - goto cleanup; - } - - { - int w = 0, h = 0; - convolve_get_dest_size(fftw_conv->width_src, fftw_conv->height_src, - fftw_conv->width_kernel, fftw_conv->height_kernel, - &w, &h, fftw_conv->mode); - if (fftw_conv->height_dest != h || fftw_conv->width_dest != w) + fftw_conv->width_fft = 0; + fftw_conv->height_fft = 0; + + if(fftw_conv->mode == convolve_mode_full) + { + fftw_conv->height_fft = fftw_conv->height_src + fftw_conv->height_kernel - 1; + fftw_conv->width_fft = fftw_conv->width_src + fftw_conv->width_kernel - 1; + } + else if(fftw_conv->mode == convolve_mode_valid) + { + fftw_conv->height_fft = fftw_conv->height_src; + fftw_conv->width_fft = fftw_conv->width_src; + } + else + { + printf("fftw3_convolve: unknown mode=%i\n", fftw_conv->mode); + goto cleanup; + } + + { + int w = 0, h = 0; + convolve_get_dest_size(fftw_conv->width_src, fftw_conv->height_src, fftw_conv->width_kernel, + fftw_conv->height_kernel, &w, &h, fftw_conv->mode); + if(fftw_conv->height_dest != h || fftw_conv->width_dest != w) { printf("fftw3_convolve: invalid dest size\n"); goto cleanup; } - } - - fftw_conv->height_fft = fftw3_find_closest_factor(fftw_conv->height_fft, FFTW_FACTORS); - fftw_conv->width_fft = fftw3_find_closest_factor(fftw_conv->width_fft, FFTW_FACTORS); - - fftw_conv->width_fft_complex = fftw_conv->width_fft/2+1; - fftw_conv->height_fft_complex = fftw_conv->height_fft; - - FFTW3_TIME_BEGIN - dt_pthread_mutex_lock(&darktable.plugin_threadsafe); + } + + fftw_conv->height_fft = fftw3_find_closest_factor(fftw_conv->height_fft, FFTW_FACTORS); + fftw_conv->width_fft = fftw3_find_closest_factor(fftw_conv->width_fft, FFTW_FACTORS); + + fftw_conv->width_fft_complex = fftw_conv->width_fft / 2 + 1; + fftw_conv->height_fft_complex = fftw_conv->height_fft; + + FFTW3_TIME_BEGIN + dt_pthread_mutex_lock(&darktable.plugin_threadsafe); FFTW3_TIME_END(TIME_FFTW3_LOCK) - fftw_conv->in_src = (float*)fftwf_malloc(sizeof(float) * fftw_conv->width_fft * fftw_conv->height_fft); - fftw_conv->out_src = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * fftw_conv->width_fft_complex * fftw_conv->height_fft_complex); - - fftw_conv->in_kernel = (float*)fftwf_malloc(sizeof(float) * fftw_conv->width_fft * fftw_conv->height_fft); - fftw_conv->out_kernel = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * fftw_conv->width_fft_complex * fftw_conv->height_fft_complex); - - FFTW3_TIME_BEGIN - dt_pthread_mutex_unlock(&darktable.plugin_threadsafe); + fftw_conv->in_src = (float *)fftwf_malloc(sizeof(float) * fftw_conv->width_fft * fftw_conv->height_fft); + fftw_conv->out_src = (fftwf_complex *)fftwf_malloc(sizeof(fftwf_complex) * fftw_conv->width_fft_complex + * fftw_conv->height_fft_complex); + + fftw_conv->in_kernel = (float *)fftwf_malloc(sizeof(float) * fftw_conv->width_fft * fftw_conv->height_fft); + fftw_conv->out_kernel = (fftwf_complex *)fftwf_malloc(sizeof(fftwf_complex) * fftw_conv->width_fft_complex + * fftw_conv->height_fft_complex); + + FFTW3_TIME_BEGIN + dt_pthread_mutex_unlock(&darktable.plugin_threadsafe); FFTW3_TIME_END(TIME_FFTW3_LOCK) - FFTW3_TIME_BEGIN - dt_pthread_mutex_lock(&darktable.plugin_threadsafe); + FFTW3_TIME_BEGIN + dt_pthread_mutex_lock(&darktable.plugin_threadsafe); FFTW3_TIME_END(TIME_FFTW3_LOCK) - + FFTW3_TIME_BEGIN - fftw_conv->plan_src = fftwf_plan_dft_r2c_2d(fftw_conv->height_fft, fftw_conv->width_fft, fftw_conv->in_src, fftw_conv->out_src, FFTW_ESTIMATE); - fftw_conv->plan_kernel = fftwf_plan_dft_r2c_2d(fftw_conv->height_fft, fftw_conv->width_fft, fftw_conv->in_kernel, fftw_conv->out_kernel, FFTW_ESTIMATE); + fftw_conv->plan_src = fftwf_plan_dft_r2c_2d(fftw_conv->height_fft, fftw_conv->width_fft, fftw_conv->in_src, + fftw_conv->out_src, FFTW_ESTIMATE); + fftw_conv->plan_kernel = fftwf_plan_dft_r2c_2d(fftw_conv->height_fft, fftw_conv->width_fft, + fftw_conv->in_kernel, fftw_conv->out_kernel, FFTW_ESTIMATE); - fftw_conv->plan_inv = fftwf_plan_dft_c2r_2d(fftw_conv->height_fft, fftw_conv->width_fft, fftw_conv->out_src, fftw_conv->in_src, FFTW_ESTIMATE); + fftw_conv->plan_inv = fftwf_plan_dft_c2r_2d(fftw_conv->height_fft, fftw_conv->width_fft, fftw_conv->out_src, + fftw_conv->in_src, FFTW_ESTIMATE); FFTW3_TIME_END(TIME_FFTW3_PLAN) - - FFTW3_TIME_BEGIN - dt_pthread_mutex_unlock(&darktable.plugin_threadsafe); + + FFTW3_TIME_BEGIN + dt_pthread_mutex_unlock(&darktable.plugin_threadsafe); FFTW3_TIME_END(TIME_FFTW3_LOCK) + } + + return fftw_conv; - } - - return fftw_conv; - cleanup: - - fftw3_convolve_free(fftw_conv, time); - return NULL; - + + fftw3_convolve_free(fftw_conv, time); + return NULL; } -void fftw3_convolve(fftw3_convolve_t *fftw_conv, const float *const image_src, const int width_src, const int height_src, const int ch, - const float *const image_kernel, const int width_kernel, const int height_kernel, - float *image_dest, const int width_dest, const int height_dest, const int channel, double *time) +void fftw3_convolve(fftw3_convolve_t *fftw_conv, const float *const image_src, const int width_src, + const int height_src, const int ch, const float *const image_kernel, const int width_kernel, + const int height_kernel, float *image_dest, const int width_dest, const int height_dest, + const int channel, double *time) { FFTW3_TIME_DECL - if (width_src != fftw_conv->width_src || height_src != fftw_conv->height_src || ch != fftw_conv->ch) + if(width_src != fftw_conv->width_src || height_src != fftw_conv->height_src || ch != fftw_conv->ch) printf("fftw3_convolve: image_src different from defined\n"); - if (width_kernel != fftw_conv->width_kernel || height_kernel != fftw_conv->height_kernel) + if(width_kernel != fftw_conv->width_kernel || height_kernel != fftw_conv->height_kernel) printf("fftw3_convolve: image_kernel different from defined\n"); - if (width_dest != fftw_conv->width_dest || height_dest != fftw_conv->height_dest) + if(width_dest != fftw_conv->width_dest || height_dest != fftw_conv->height_dest) printf("fftw3_convolve: image_dest different from defined\n"); - + const float scale = 1.0 / (fftw_conv->width_fft * fftw_conv->height_fft); memset(fftw_conv->in_src, 0, sizeof(float) * fftw_conv->width_fft * fftw_conv->height_fft); - memset(fftw_conv->out_src, 0, sizeof(fftwf_complex) * fftw_conv->width_fft_complex * fftw_conv->height_fft_complex); + memset(fftw_conv->out_src, 0, + sizeof(fftwf_complex) * fftw_conv->width_fft_complex * fftw_conv->height_fft_complex); memset(fftw_conv->in_kernel, 0, sizeof(float) * fftw_conv->width_fft * fftw_conv->height_fft); - memset(fftw_conv->out_kernel, 0, sizeof(fftwf_complex) * fftw_conv->width_fft_complex * fftw_conv->height_fft_complex); + memset(fftw_conv->out_kernel, 0, + sizeof(fftwf_complex) * fftw_conv->width_fft_complex * fftw_conv->height_fft_complex); FFTW3_TIME_BEGIN - + #ifdef _OPENMP #pragma omp parallel for default(none) shared(fftw_conv) schedule(static) #endif - for (int y = 0; y < fftw_conv->height_src; y++) + for(int y = 0; y < fftw_conv->height_src; y++) { float *in_src = fftw_conv->in_src + y * fftw_conv->width_fft; const float *src = image_src + y * fftw_conv->width_src * fftw_conv->ch; - for (int x = 0; x < fftw_conv->width_src; x++) + for(int x = 0; x < fftw_conv->width_src; x++) { in_src[x] = src[x * fftw_conv->ch + channel]; } @@ -309,154 +311,150 @@ void fftw3_convolve(fftw3_convolve_t *fftw_conv, const float *const image_src, c #ifdef _OPENMP #pragma omp parallel for default(none) shared(fftw_conv) schedule(static) #endif - for (int y = 0; y < fftw_conv->height_kernel; y++) + for(int y = 0; y < fftw_conv->height_kernel; y++) { float *in_kernel = fftw_conv->in_kernel + y * fftw_conv->width_fft; const float *kernel = image_kernel + y * fftw_conv->width_kernel * fftw_conv->ch; - for (int x = 0; x < fftw_conv->width_kernel; x++) + for(int x = 0; x < fftw_conv->width_kernel; x++) { in_kernel[x] = kernel[x * fftw_conv->ch + channel]; } } FFTW3_TIME_END(TIME_FFTW3_COPY) - -// FFTW3_TIME_BEGIN -// dt_pthread_mutex_lock(&darktable.plugin_threadsafe); -// FFTW3_TIME_END(TIME_FFTW3_LOCK) + + // FFTW3_TIME_BEGIN + // dt_pthread_mutex_lock(&darktable.plugin_threadsafe); + // FFTW3_TIME_END(TIME_FFTW3_LOCK) FFTW3_TIME_BEGIN fftwf_execute(fftw_conv->plan_src); fftwf_execute(fftw_conv->plan_kernel); FFTW3_TIME_END(TIME_FFTW3_EXEC) -// FFTW3_TIME_BEGIN -// dt_pthread_mutex_unlock(&darktable.plugin_threadsafe); -// FFTW3_TIME_END(TIME_FFTW3_LOCK) + // FFTW3_TIME_BEGIN + // dt_pthread_mutex_unlock(&darktable.plugin_threadsafe); + // FFTW3_TIME_END(TIME_FFTW3_LOCK) FFTW3_TIME_BEGIN - + #ifdef _OPENMP #pragma omp parallel for default(none) shared(fftw_conv) schedule(static) #endif - for (int i = 0; i < fftw_conv->height_fft_complex; ++i) + for(int i = 0; i < fftw_conv->height_fft_complex; ++i) { fftwf_complex *in_inv = fftw_conv->out_src + i * fftw_conv->width_fft_complex; fftwf_complex *out_src = fftw_conv->out_src + i * fftw_conv->width_fft_complex; fftwf_complex *out_kernel = fftw_conv->out_kernel + i * fftw_conv->width_fft_complex; - for (int j = 0; j < fftw_conv->width_fft_complex; ++j) + for(int j = 0; j < fftw_conv->width_fft_complex; ++j) { - float in_r = (out_src[j][0] * out_kernel[j][0] - out_src[j][1] * out_kernel[j][1]);// * scale; - float in_c = (out_src[j][0] * out_kernel[j][1] + out_src[j][1] * out_kernel[j][0]);// * scale; + float in_r = (out_src[j][0] * out_kernel[j][0] - out_src[j][1] * out_kernel[j][1]); // * scale; + float in_c = (out_src[j][0] * out_kernel[j][1] + out_src[j][1] * out_kernel[j][0]); // * scale; in_inv[j][0] = in_r; in_inv[j][1] = in_c; } } - + FFTW3_TIME_END(TIME_FFTW3_MULT) - + memset(fftw_conv->in_src, 0, sizeof(float) * fftw_conv->width_fft * fftw_conv->height_fft); -// FFTW3_TIME_BEGIN -// dt_pthread_mutex_lock(&darktable.plugin_threadsafe); -// FFTW3_TIME_END(TIME_FFTW3_LOCK) + // FFTW3_TIME_BEGIN + // dt_pthread_mutex_lock(&darktable.plugin_threadsafe); + // FFTW3_TIME_END(TIME_FFTW3_LOCK) FFTW3_TIME_BEGIN fftwf_execute(fftw_conv->plan_inv); FFTW3_TIME_END(TIME_FFTW3_EXEC) -// FFTW3_TIME_BEGIN -// dt_pthread_mutex_unlock(&darktable.plugin_threadsafe); -// FFTW3_TIME_END(TIME_FFTW3_LOCK) + // FFTW3_TIME_BEGIN + // dt_pthread_mutex_unlock(&darktable.plugin_threadsafe); + // FFTW3_TIME_END(TIME_FFTW3_LOCK) FFTW3_TIME_BEGIN - if (fftw_conv->mode == convolve_mode_full) + if(fftw_conv->mode == convolve_mode_full) { - // return [0:height_dest-1; 0:width_dest-1] +// return [0:height_dest-1; 0:width_dest-1] #ifdef _OPENMP #pragma omp parallel for default(none) shared(fftw_conv, image_dest) schedule(static) #endif - for (int y = 0; y < fftw_conv->height_dest; y++) + for(int y = 0; y < fftw_conv->height_dest; y++) { float *dest = image_dest + y * fftw_conv->width_dest * fftw_conv->ch; float *out_inv = fftw_conv->in_src + y * fftw_conv->width_fft; - for (int x = 0; x < fftw_conv->width_dest; x++) + for(int x = 0; x < fftw_conv->width_dest; x++) { dest[x * fftw_conv->ch + channel] = out_inv[x] * scale; } } } - else if (fftw_conv->mode == convolve_mode_valid) + else if(fftw_conv->mode == convolve_mode_valid) { - // return [height_dest; width_dest] starting at [height_kernel-1; width_kernel-1] +// return [height_dest; width_dest] starting at [height_kernel-1; width_kernel-1] #ifdef _OPENMP #pragma omp parallel for default(none) shared(fftw_conv, image_dest) schedule(static) #endif - for (int y = 0; y < fftw_conv->height_dest; y++) + for(int y = 0; y < fftw_conv->height_dest; y++) { float *dest = image_dest + y * fftw_conv->width_dest * fftw_conv->ch; float *out_inv = fftw_conv->in_src + (y + fftw_conv->height_kernel - 1) * fftw_conv->width_fft; - for (int x = 0; x < fftw_conv->width_dest; x++) + for(int x = 0; x < fftw_conv->width_dest; x++) { dest[x * fftw_conv->ch + channel] = out_inv[x + fftw_conv->width_kernel - 1] * scale; } } } FFTW3_TIME_END(TIME_FFTW3_COPY) - } -#endif // HAVE_FFTW3 +#endif // HAVE_FFTW3 -void convolve_get_dest_size(const int width_src, const int height_src, - const int width_kernel, const int height_kernel, - int *width_dest, int *height_dest, const int mode) +void convolve_get_dest_size(const int width_src, const int height_src, const int width_kernel, + const int height_kernel, int *width_dest, int *height_dest, const int mode) { - if (mode == convolve_mode_full) + if(mode == convolve_mode_full) { - *height_dest = height_src + height_kernel-1; - *width_dest = width_src + width_kernel-1; + *height_dest = height_src + height_kernel - 1; + *width_dest = width_src + width_kernel - 1; } - else if (mode == convolve_mode_valid) + else if(mode == convolve_mode_valid) { - *height_dest = height_src - height_kernel+1; - *width_dest = width_src - width_kernel+1; + *height_dest = height_src - height_kernel + 1; + *width_dest = width_src - width_kernel + 1; } else { printf("convolve_get_dest_size: unknown mode=%i\n", mode); } - } #ifdef HAVE_FFTW3 -static fftw3_convolve_t * fftw3_find_conv_kernel(convolve_data_t *fft_conv_data, - const int width_src, const int height_src, const int ch, - const int width_kernel, const int height_kernel, - const int width_dest, const int height_dest, - const int mode, double *time) +static fftw3_convolve_t *fftw3_find_conv_kernel(convolve_data_t *fft_conv_data, const int width_src, + const int height_src, const int ch, const int width_kernel, + const int height_kernel, const int width_dest, + const int height_dest, const int mode, double *time) { - fftw3_convolve_t * kernel = NULL; + fftw3_convolve_t *kernel = NULL; int null_index = -1; - - for (int i = 0; i < RLUCY_CONV_DATA_MAX; i++) + + for(int i = 0; i < RLUCY_CONV_DATA_MAX; i++) { fftw3_convolve_t *fftw3_conv = fft_conv_data->conv_kern[i]; - - if (fftw3_conv) + + if(fftw3_conv) { - if (width_src == fftw3_conv->width_src && height_src == fftw3_conv->height_src && ch == fftw3_conv->ch && - width_kernel == fftw3_conv->width_kernel && height_kernel == fftw3_conv->height_kernel && - width_dest == fftw3_conv->width_dest && height_dest == fftw3_conv->height_dest) - { + if(width_src == fftw3_conv->width_src && height_src == fftw3_conv->height_src && ch == fftw3_conv->ch + && width_kernel == fftw3_conv->width_kernel && height_kernel == fftw3_conv->height_kernel + && width_dest == fftw3_conv->width_dest && height_dest == fftw3_conv->height_dest) + { kernel = fftw3_conv; break; - } + } } else { @@ -464,74 +462,63 @@ static fftw3_convolve_t * fftw3_find_conv_kernel(convolve_data_t *fft_conv_data, break; } } - - if (kernel == NULL && null_index >= 0) + + if(kernel == NULL && null_index >= 0) { - kernel = fftw3_convolve_init(width_src, height_src, ch, - width_kernel, height_kernel, - width_dest, height_dest, - mode, time); - + kernel = fftw3_convolve_init(width_src, height_src, ch, width_kernel, height_kernel, width_dest, height_dest, + mode, time); + fft_conv_data->conv_kern[null_index] = kernel; } - + return kernel; } -void convolve(convolve_data_t *fft_conv_data, const float *const src, const int width_src, const int height_src, const int ch, - const float *const kernel, const int width_kernel, const int height_kernel, - float *dest, const int width_dest, const int height_dest, - const int mode, double *time) -{ - const int ch1 = (ch == 4) ? 3: ch; +void convolve(convolve_data_t *fft_conv_data, const float *const src, const int width_src, const int height_src, + const int ch, const float *const kernel, const int width_kernel, const int height_kernel, + float *dest, const int width_dest, const int height_dest, const int mode, double *time) +{ + const int ch1 = (ch == 4) ? 3 : ch; int free_conv = 0; fftw3_convolve_t *fftw3_conv = NULL; - fftw3_conv = fftw3_find_conv_kernel(fft_conv_data, - width_src, height_src, ch, - width_kernel, height_kernel, - width_dest, height_dest, mode, time); - - if (fftw3_conv == NULL) + fftw3_conv = fftw3_find_conv_kernel(fft_conv_data, width_src, height_src, ch, width_kernel, height_kernel, + width_dest, height_dest, mode, time); + + if(fftw3_conv == NULL) { - fftw3_conv = fftw3_convolve_init(width_src, height_src, ch, - width_kernel, height_kernel, - width_dest, height_dest, - mode, time); - + fftw3_conv = fftw3_convolve_init(width_src, height_src, ch, width_kernel, height_kernel, width_dest, + height_dest, mode, time); + free_conv = 1; } - - if (fftw3_conv) + + if(fftw3_conv) { - for (int c = 0; c < ch1; c++) + for(int c = 0; c < ch1; c++) { - fftw3_convolve(fftw3_conv, src, width_src, height_src, ch, - kernel, width_kernel, height_kernel, - dest, width_dest, height_dest, c, time); + fftw3_convolve(fftw3_conv, src, width_src, height_src, ch, kernel, width_kernel, height_kernel, dest, + width_dest, height_dest, c, time); } } else { printf("rlucy_convolve: error initializing fftw3\n"); } - - if (free_conv) + + if(free_conv) { fftw3_convolve_free(fftw3_conv, time); } - } - + #else // HAVE_FFTW3 -void convolve(convolve_data_t *fft_conv_data, const float *const src, const int width_src, const int height_src, const int ch, - const float *const kernel, const int width_kernel, const int height_kernel, - float *dest, const int width_dest, const int height_dest, - const int mode, double *time) +void convolve(convolve_data_t *fft_conv_data, const float *const src, const int width_src, const int height_src, + const int ch, const float *const kernel, const int width_kernel, const int height_kernel, + float *dest, const int width_dest, const int height_dest, const int mode, double *time) { - } #endif // HAVE_FFTW3 @@ -539,9 +526,9 @@ void convolve(convolve_data_t *fft_conv_data, const float *const src, const int void convolve_free(convolve_data_t *fft_conv_data, double *time) { #ifdef HAVE_FFTW3 - for (int i = 0; i < RLUCY_CONV_DATA_MAX; i++) + for(int i = 0; i < RLUCY_CONV_DATA_MAX; i++) { - if (fft_conv_data->conv_kern[i]) + if(fft_conv_data->conv_kern[i]) { fftw3_convolve_free(fft_conv_data->conv_kern[i], time); fft_conv_data->conv_kern[i] = NULL; @@ -550,35 +537,35 @@ void convolve_free(convolve_data_t *fft_conv_data, double *time) #endif } -void convolve_pad_image(const float *const img_src, const int width_src, const int height_src, const int ch, - const int pad_h, const int pad_v, - float *img_dest, const int width_dest, const int height_dest, double *time) +void convolve_pad_image(const float *const img_src, const int width_src, const int height_src, const int ch, + const int pad_h, const int pad_v, float *img_dest, const int width_dest, + const int height_dest, double *time) { - + // copy image - for (int y = 0; y < height_src; y++) + for(int y = 0; y < height_src; y++) { const float *const src = img_src + y * width_src * ch; float *dest = img_dest + (y + pad_v) * width_dest * ch + pad_h * ch; - + memcpy(dest, src, width_src * ch * sizeof(float)); } - + // pad left and right - for (int y = 0; y < height_src; y++) + for(int y = 0; y < height_src; y++) { const float *const src_l = img_src + y * width_src * ch; float *dest_l = img_dest + (y + pad_v) * width_dest * ch; - - const float *const src_r = img_src + y * width_src * ch + (width_src-1) * ch; - float *dest_r = img_dest + (y + pad_v) * width_dest * ch + (width_src+pad_h) * ch; - - for (int x = 0; x < pad_h; x++) + + const float *const src_r = img_src + y * width_src * ch + (width_src - 1) * ch; + float *dest_r = img_dest + (y + pad_v) * width_dest * ch + (width_src + pad_h) * ch; + + for(int x = 0; x < pad_h; x++) { - for (int c = 0; c < ch; c++) + for(int c = 0; c < ch; c++) { - dest_l[x*ch + c] = src_l[c]; - dest_r[x*ch + c] = src_r[c]; + dest_l[x * ch + c] = src_l[c]; + dest_r[x * ch + c] = src_r[c]; } } } @@ -586,15 +573,13 @@ void convolve_pad_image(const float *const img_src, const int width_src, const i // pad top and bottom const float *const src_t = img_dest + pad_v * width_dest * ch; const float *const src_b = img_dest + (height_src + pad_v - 1) * width_dest * ch; - - for (int y = 0; y < pad_v; y++) + + for(int y = 0; y < pad_v; y++) { float *dest_t = img_dest + y * width_dest * ch; float *dest_b = img_dest + (y + height_src + pad_v) * width_dest * ch; - + memcpy(dest_t, src_t, width_dest * ch * sizeof(float)); memcpy(dest_b, src_b, width_dest * ch * sizeof(float)); } - } - diff --git a/src/common/convolution.h b/src/common/convolution.h index 1fa14aea8bca..ffb5fe2883ad 100644 --- a/src/common/convolution.h +++ b/src/common/convolution.h @@ -17,32 +17,32 @@ typedef enum typedef struct { - float *in_src; - fftwf_complex *out_src; - fftwf_plan plan_src; - - float *in_kernel; - fftwf_complex *out_kernel; - fftwf_plan plan_kernel; - - fftwf_plan plan_inv; - - int width_src; - int height_src; - int ch; - - int width_kernel; - int height_kernel; - - int width_dest; - int height_dest; - - int mode; - - int width_fft; - int height_fft; - int width_fft_complex; - int height_fft_complex; + float *in_src; + fftwf_complex *out_src; + fftwf_plan plan_src; + + float *in_kernel; + fftwf_complex *out_kernel; + fftwf_plan plan_kernel; + + fftwf_plan plan_inv; + + int width_src; + int height_src; + int ch; + + int width_kernel; + int height_kernel; + + int width_dest; + int height_dest; + + int mode; + + int width_fft; + int height_fft; + int width_fft_complex; + int height_fft_complex; } fftw3_convolve_t; @@ -66,18 +66,16 @@ typedef struct #endif -void convolve_pad_image(const float *const img_src, const int width_src, const int height_src, const int ch, - const int pad_h, const int pad_v, - float *img_dest, const int width_dest, const int height_dest, double *time); +void convolve_pad_image(const float *const img_src, const int width_src, const int height_src, const int ch, + const int pad_h, const int pad_v, float *img_dest, const int width_dest, + const int height_dest, double *time); -void convolve_get_dest_size(const int width_src, const int height_src, - const int width_kernel, const int height_kernel, - int *width_dest, int *height_dest, const int mode); +void convolve_get_dest_size(const int width_src, const int height_src, const int width_kernel, + const int height_kernel, int *width_dest, int *height_dest, const int mode); -void convolve(convolve_data_t *fft_conv_data, const float *const src, const int width_src, const int height_src, const int ch, - const float *const kernel, const int width_kernel, const int height_kernel, - float *dest, const int width_dest, const int height_dest, - const int mode, double *time); +void convolve(convolve_data_t *fft_conv_data, const float *const src, const int width_src, const int height_src, + const int ch, const float *const kernel, const int width_kernel, const int height_kernel, + float *dest, const int width_dest, const int height_dest, const int mode, double *time); void convolve_free(convolve_data_t *fft_conv_data, double *time); diff --git a/src/common/cpuid.c b/src/common/cpuid.c index eadbc238156b..00dc7fbc763f 100644 --- a/src/common/cpuid.c +++ b/src/common/cpuid.c @@ -46,11 +46,11 @@ dt_cpu_flags_t dt_detect_cpu_features() { -#define cpuid(cmd) \ - __asm volatile("push %%" R_BX "\n" \ - "cpuid\n" \ - "pop %%" R_BX "\n" \ - : "=a"(ax), "=c"(cx), "=d"(dx) \ +#define cpuid(cmd) \ + __asm volatile("push %%" R_BX "\n" \ + "cpuid\n" \ + "pop %%" R_BX "\n" \ + : "=a"(ax), "=c"(cx), "=d"(dx) \ : "0"(cmd)) #ifdef __x86_64__ diff --git a/src/common/cups_print.c b/src/common/cups_print.c index 62ed5671cc46..5a9be19b765d 100644 --- a/src/common/cups_print.c +++ b/src/common/cups_print.c @@ -51,14 +51,14 @@ dt_printer_info_t *dt_get_printer_info(const char *printer_name) cups_dest_t *dest = cupsGetDest(printer_name, NULL, num_dests, dests); dt_printer_info_t *result = NULL; - if (dest) + if(dest) { - const char *PPDFile = cupsGetPPD (printer_name); + const char *PPDFile = cupsGetPPD(printer_name); result = (dt_printer_info_t *)malloc(sizeof(dt_printer_info_t)); g_strlcpy(result->name, dest->name, MAX_NAME); ppd_file_t *ppd = ppdOpenFile(PPDFile); - if (ppd) + if(ppd) { ppdMarkDefaults(ppd); cupsMarkOptions(ppd, dest->num_options, dest->options); @@ -67,36 +67,34 @@ dt_printer_info_t *dt_get_printer_info(const char *printer_name) ppd_attr_t *attr = ppdFindAttr(ppd, "HWMargins", NULL); - if (attr) + if(attr) { - sscanf(attr->value, "%lf %lf %lf %lf", - &result->hw_margin_left, &result->hw_margin_bottom, + sscanf(attr->value, "%lf %lf %lf %lf", &result->hw_margin_left, &result->hw_margin_bottom, &result->hw_margin_right, &result->hw_margin_top); - result->hw_margin_left = dt_pdf_point_to_mm (result->hw_margin_left); - result->hw_margin_bottom = dt_pdf_point_to_mm (result->hw_margin_bottom); - result->hw_margin_right = dt_pdf_point_to_mm (result->hw_margin_right); - result->hw_margin_top = dt_pdf_point_to_mm (result->hw_margin_top); + result->hw_margin_left = dt_pdf_point_to_mm(result->hw_margin_left); + result->hw_margin_bottom = dt_pdf_point_to_mm(result->hw_margin_bottom); + result->hw_margin_right = dt_pdf_point_to_mm(result->hw_margin_right); + result->hw_margin_top = dt_pdf_point_to_mm(result->hw_margin_top); } // default resolution attr = ppdFindAttr(ppd, "DefaultResolution", NULL); - if (attr) + if(attr) { char *x = strstr(attr->value, "x"); - if (x) - sscanf (x+1, "%ddpi", &result->resolution); + if(x) + sscanf(x + 1, "%ddpi", &result->resolution); else - sscanf (attr->value, "%ddpi", &result->resolution); + sscanf(attr->value, "%ddpi", &result->resolution); } else result->resolution = 300; - while(result->resolution>360) - result->resolution /= 2.0; + while(result->resolution > 360) result->resolution /= 2.0; ppdClose(ppd); g_unlink(PPDFile); @@ -113,10 +111,10 @@ static int _dest_cb(void *user_data, unsigned flags, cups_dest_t *dest) const char *psvalue = cupsGetOption("printer-state", dest->num_options, dest->options); // check that the printer is ready - if (psvalue!=NULL && strtol(psvalue, NULL, 10) < IPP_PRINTER_STOPPED) + if(psvalue != NULL && strtol(psvalue, NULL, 10) < IPP_PRINTER_STOPPED) { dt_printer_info_t *pr = dt_get_printer_info(dest->name); - if (pctl->cb) pctl->cb(pr, pctl->user_data); + if(pctl->cb) pctl->cb(pr, pctl->user_data); free(pr); } else @@ -131,25 +129,26 @@ static int _detect_printers_callback(dt_job_t *job) { dt_prtctl_t *pctl = dt_control_job_get_params(job); int res; -#if ((CUPS_VERSION_MAJOR == 1) && (CUPS_VERSION_MINOR >= 6)) || CUPS_VERSION_MAJOR > 1 +#if((CUPS_VERSION_MAJOR == 1) && (CUPS_VERSION_MINOR >= 6)) || CUPS_VERSION_MAJOR > 1 #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 - if (cupsEnumDests != NULL) + if(cupsEnumDests != NULL) #endif res = cupsEnumDests(CUPS_MEDIA_FLAGS_DEFAULT, 30000, &_cancel, 0, 0, _dest_cb, pctl); #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 else #endif #endif -#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 || !(((CUPS_VERSION_MAJOR == 1) && (CUPS_VERSION_MINOR >= 6)) || CUPS_VERSION_MAJOR > 1) +#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 \ + || !(((CUPS_VERSION_MAJOR == 1) && (CUPS_VERSION_MINOR >= 6)) || CUPS_VERSION_MAJOR > 1) { cups_dest_t *dests; const int num_dests = cupsGetDests(&dests); - for (int k=0; k<num_dests; k++) + for(int k = 0; k < num_dests; k++) { _dest_cb((void *)pctl, 0, &dests[k]); } cupsFreeDests(num_dests, dests); - res=1; + res = 1; } #endif return !res; @@ -178,16 +177,14 @@ void dt_printers_discovery(void (*cb)(dt_printer_info_t *pr, void *user_data), v static int paper_exists(GList *papers, const char *name) { - if (strstr(name,"custom_") == name) - return 1; + if(strstr(name, "custom_") == name) return 1; GList *p = papers; - while (p) + while(p) { - const dt_paper_info_t *pi = (dt_paper_info_t*)p->data; - if (!strcmp(pi->name,name) || !strcmp(pi->common_name,name)) - return 1; - p = g_list_next (p); + const dt_paper_info_t *pi = (dt_paper_info_t *)p->data; + if(!strcmp(pi->name, name) || !strcmp(pi->common_name, name)) return 1; + p = g_list_next(p); } return 0; } @@ -197,37 +194,36 @@ dt_paper_info_t *dt_get_paper(GList *papers, const char *name) GList *p = papers; dt_paper_info_t *result = NULL; - while (p) + while(p) { - dt_paper_info_t *pi = (dt_paper_info_t*)p->data; - if (!strcmp(pi->name,name) || !strcmp(pi->common_name,name)) + dt_paper_info_t *pi = (dt_paper_info_t *)p->data; + if(!strcmp(pi->name, name) || !strcmp(pi->common_name, name)) { result = pi; break; } - p = g_list_next (p); + p = g_list_next(p); } return result; } -static gint -sort_papers (gconstpointer p1, gconstpointer p2) +static gint sort_papers(gconstpointer p1, gconstpointer p2) { const dt_paper_info_t *n1 = (dt_paper_info_t *)p1; const dt_paper_info_t *n2 = (dt_paper_info_t *)p2; const int l1 = strlen(n1->common_name); const int l2 = strlen(n2->common_name); - return l1==l2 ? strcmp(n1->common_name, n2->common_name) : (l1 < l2 ? -1 : +1); + return l1 == l2 ? strcmp(n1->common_name, n2->common_name) : (l1 < l2 ? -1 : +1); } GList *dt_get_papers(const char *printer_name) { GList *result = NULL; -#if ((CUPS_VERSION_MAJOR == 1) && (CUPS_VERSION_MINOR >= 7)) || CUPS_VERSION_MAJOR > 1 +#if((CUPS_VERSION_MAJOR == 1) && (CUPS_VERSION_MINOR >= 7)) || CUPS_VERSION_MAJOR > 1 #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9 - if (cupsConnectDest != NULL && cupsCopyDestInfo != NULL && cupsGetDestMediaCount != NULL && - cupsGetDestMediaByIndex != NULL && cupsFreeDestInfo != NULL) + if(cupsConnectDest != NULL && cupsCopyDestInfo != NULL && cupsGetDestMediaCount != NULL + && cupsGetDestMediaByIndex != NULL && cupsFreeDestInfo != NULL) #endif { cups_dest_t *dests; @@ -238,35 +234,35 @@ GList *dt_get_papers(const char *printer_name) char resource[1024]; - if (dest) + if(dest) { http_t *hcon = cupsConnectDest(dest, 0, 2000, &cancel, resource, sizeof(resource), NULL, (void *)NULL); - if (hcon) + if(hcon) { cups_size_t size; - cups_dinfo_t *info = cupsCopyDestInfo (hcon, dest); + cups_dinfo_t *info = cupsCopyDestInfo(hcon, dest); const int count = cupsGetDestMediaCount(hcon, dest, info, CUPS_MEDIA_FLAGS_DEFAULT); - for (int k=0; k<count; k++) + for(int k = 0; k < count; k++) { - if (cupsGetDestMediaByIndex(hcon, dest, info, k, CUPS_MEDIA_FLAGS_DEFAULT, &size)) + if(cupsGetDestMediaByIndex(hcon, dest, info, k, CUPS_MEDIA_FLAGS_DEFAULT, &size)) { - if (!paper_exists(result,size.media)) + if(!paper_exists(result, size.media)) { - pwg_media_t *med = pwgMediaForPWG (size.media); + pwg_media_t *med = pwgMediaForPWG(size.media); char common_name[MAX_NAME] = { 0 }; - if (med->ppd) + if(med->ppd) g_strlcpy(common_name, med->ppd, sizeof(common_name)); else g_strlcpy(common_name, size.media, sizeof(common_name)); - dt_paper_info_t *paper = (dt_paper_info_t*)malloc(sizeof(dt_paper_info_t)); + dt_paper_info_t *paper = (dt_paper_info_t *)malloc(sizeof(dt_paper_info_t)); g_strlcpy(paper->name, size.media, sizeof(paper->name)); g_strlcpy(paper->common_name, common_name, sizeof(paper->common_name)); paper->width = (double)size.width / 100.0; paper->height = (double)size.length / 100.0; - result = g_list_append (result, paper); + result = g_list_append(result, paper); } } } @@ -287,20 +283,20 @@ GList *dt_get_papers(const char *printer_name) const char *PPDFile = cupsGetPPD(printer_name); ppd_file_t *ppd = ppdOpenFile(PPDFile); - if (ppd) + if(ppd) { ppd_size_t *size = ppd->sizes; - for (int k=0; k<ppd->num_sizes; k++) + for(int k = 0; k < ppd->num_sizes; k++) { - if (!paper_exists(result,size->name)) + if(!paper_exists(result, size->name)) { - dt_paper_info_t *paper = (dt_paper_info_t*)malloc(sizeof(dt_paper_info_t)); + dt_paper_info_t *paper = (dt_paper_info_t *)malloc(sizeof(dt_paper_info_t)); g_strlcpy(paper->name, size->name, MAX_NAME); g_strlcpy(paper->common_name, size->name, MAX_NAME); paper->width = (double)dt_pdf_point_to_mm(size->width); paper->height = (double)dt_pdf_point_to_mm(size->length); - result = g_list_append (result, paper); + result = g_list_append(result, paper); } size++; } @@ -309,7 +305,7 @@ GList *dt_get_papers(const char *printer_name) g_unlink(PPDFile); } - result = g_list_sort_with_data (result, (GCompareDataFunc)sort_papers, NULL); + result = g_list_sort_with_data(result, (GCompareDataFunc)sort_papers, NULL); return result; } @@ -317,7 +313,7 @@ void dt_print_file(const int32_t imgid, const char *filename, const dt_print_inf { // first for safety check that filename exists and is readable - if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) + if(!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) { dt_control_log(_("file `%s' to print not found for image %d on `%s'"), filename, imgid, pinfo->printer.name); return; @@ -330,19 +326,15 @@ void dt_print_file(const int32_t imgid, const char *filename, const dt_print_inf cups_option_t *options = NULL; int num_options = 0; - for (int j = 0; j < dest->num_options; j ++) - if (cupsGetOption(dest->options[j].name, num_options, - options) == NULL) - num_options = cupsAddOption(dest->options[j].name, - dest->options[j].value, - num_options, &options); + for(int j = 0; j < dest->num_options; j++) + if(cupsGetOption(dest->options[j].name, num_options, options) == NULL) + num_options = cupsAddOption(dest->options[j].name, dest->options[j].value, num_options, &options); cupsFreeDests(num_dests, dests); // disable cm on CUPS, this is important as dt does the cm - if (*pinfo->printer.profile) - num_options = cupsAddOption("cm-calibration", "true", num_options, &options); + if(*pinfo->printer.profile) num_options = cupsAddOption("cm-calibration", "true", num_options, &options); // media to print on @@ -358,8 +350,8 @@ void dt_print_file(const int32_t imgid, const char *filename, const dt_print_inf // if the printer has no hardward margins activate the borderless mode - if (pinfo->printer.hw_margin_top == 0 || pinfo->printer.hw_margin_bottom == 0 - || pinfo->printer.hw_margin_left == 0 || pinfo->printer.hw_margin_right == 0) + if(pinfo->printer.hw_margin_top == 0 || pinfo->printer.hw_margin_bottom == 0 + || pinfo->printer.hw_margin_left == 0 || pinfo->printer.hw_margin_right == 0) { // there is many variant for this parameter num_options = cupsAddOption("StpFullBleed", "true", num_options, &options); @@ -367,7 +359,7 @@ void dt_print_file(const int32_t imgid, const char *filename, const dt_print_inf num_options = cupsAddOption("Borderless", "true", num_options, &options); } - if (pinfo->page.landscape) + if(pinfo->page.landscape) num_options = cupsAddOption("landscape", "true", num_options, &options); else num_options = cupsAddOption("landscape", "false", num_options, &options); @@ -375,20 +367,20 @@ void dt_print_file(const int32_t imgid, const char *filename, const dt_print_inf // print lp options dt_print(DT_DEBUG_PRINT, "[print] printer options (%d)\n", num_options); - for (int k=0; k<num_options; k++) + for(int k = 0; k < num_options; k++) dt_print(DT_DEBUG_PRINT, "[print] %s=%s\n", options[k].name, options[k].value); - const int job_id = cupsPrintFile(pinfo->printer.name, filename, "darktable", num_options, options); + const int job_id = cupsPrintFile(pinfo->printer.name, filename, "darktable", num_options, options); - if (job_id == 0) + if(job_id == 0) dt_control_log(_("error while printing image %d on `%s'"), imgid, pinfo->printer.name); else dt_control_log(_("printing image %d on `%s'"), imgid, pinfo->printer.name); - cupsFreeOptions (num_options, options); + cupsFreeOptions(num_options, options); } -static void _get_image_dimension (int32_t imgid, int32_t *iwidth, int32_t *iheight) +static void _get_image_dimension(int32_t imgid, int32_t *iwidth, int32_t *iheight) { dt_develop_t dev; @@ -417,12 +409,10 @@ static void _get_image_dimension (int32_t imgid, int32_t *iwidth, int32_t *iheig *iheight = ht; } -void dt_get_print_layout(const int32_t imgid, const dt_print_info_t *prt, - const int32_t area_width, const int32_t area_height, - int32_t *iwpix, int32_t *ihpix, - int32_t *px, int32_t *py, int32_t *pwidth, int32_t *pheight, - int32_t *ax, int32_t *ay, int32_t *awidth, int32_t *aheight, - int32_t *ix, int32_t *iy, int32_t *iwidth, int32_t *iheight) +void dt_get_print_layout(const int32_t imgid, const dt_print_info_t *prt, const int32_t area_width, + const int32_t area_height, int32_t *iwpix, int32_t *ihpix, int32_t *px, int32_t *py, + int32_t *pwidth, int32_t *pheight, int32_t *ax, int32_t *ay, int32_t *awidth, + int32_t *aheight, int32_t *ix, int32_t *iy, int32_t *iwidth, int32_t *iheight) { /* this is where the layout is done for the display and for the print too. So this routine is one of the most critical for the print circuitry. */ @@ -430,15 +420,15 @@ void dt_get_print_layout(const int32_t imgid, const dt_print_info_t *prt, double width, height; // page w/h - double pg_width = prt->paper.width; + double pg_width = prt->paper.width; double pg_height = prt->paper.height; - if (area_width==0) + if(area_width == 0) width = pg_width; else width = area_width; - if (area_height==0) + if(area_height == 0) height = pg_height; else height = area_height; @@ -453,14 +443,14 @@ void dt_get_print_layout(const int32_t imgid, const dt_print_info_t *prt, /* do some arrangements for the landscape mode. */ - if (prt->page.landscape) + if(prt->page.landscape) { double tmp = pg_width; pg_width = pg_height; pg_height = tmp; // only invert if we did not get a specific area - if (area_width == 0 && area_height == 0) + if(area_width == 0 && area_height == 0) { tmp = width; width = height; @@ -468,11 +458,11 @@ void dt_get_print_layout(const int32_t imgid, const dt_print_info_t *prt, } // rotate the non-printable margins - tmp = np_top; - np_top = np_right; - np_right = np_bottom; + tmp = np_top; + np_top = np_right; + np_right = np_bottom; np_bottom = np_left; - np_left = tmp; + np_left = tmp; } // the image area aspect @@ -484,7 +474,7 @@ void dt_get_print_layout(const int32_t imgid, const dt_print_info_t *prt, // display page int32_t p_bottom, p_right; - if (a_aspect > pg_aspect) + if(a_aspect > pg_aspect) { *px = (width - (height * pg_aspect)) / 2; *py = 0; @@ -514,21 +504,20 @@ void dt_get_print_layout(const int32_t imgid, const dt_print_info_t *prt, // display picture area, that is removing the non printable areas and user's margins const int32_t bx = *px + ((np_left + border_left) / pg_width) * (*pwidth); - const int32_t by = *py + ((np_top + border_top)/ pg_height) * (*pheight); + const int32_t by = *py + ((np_top + border_top) / pg_height) * (*pheight); const int32_t bb = p_bottom - ((np_bottom + border_bottom) / pg_height) * (*pheight); const int32_t br = p_right - ((np_right + border_right) / pg_width) * (*pwidth); // now we have the printable area (ax, ay) -> (ax + awidth, ay + aheight) - *ax = bx; - *ay = by; - *awidth = br - bx; + *ax = bx; + *ay = by; + *awidth = br - bx; *aheight = bb - by; // get the image dimensions if needed - if (*iwpix <= 0 || *ihpix <= 0) - _get_image_dimension (imgid, iwpix, ihpix); + if(*iwpix <= 0 || *ihpix <= 0) _get_image_dimension(imgid, iwpix, ihpix); // compute the scaling for the image to fit into the printable area @@ -537,14 +526,14 @@ void dt_get_print_layout(const int32_t imgid, const dt_print_info_t *prt, *iwidth = *iwpix; *iheight = *ihpix; - if (*iwidth > *awidth) + if(*iwidth > *awidth) { - scale = (double)(*awidth) / (double)*iwidth; + scale = (double)(*awidth) / (double)*iwidth; *iwidth = *awidth; *iheight = (int32_t)(((double)*iheight + 0.5) * scale); } - if (*iheight > *aheight) + if(*iheight > *aheight) { scale = (double)(*aheight) / (double)*iheight; *iheight = *aheight; @@ -554,7 +543,7 @@ void dt_get_print_layout(const int32_t imgid, const dt_print_info_t *prt, // now the image position (top-left corner coordinates) in the display area depending on the page // alignment set by the user. - switch (prt->page.alignment) + switch(prt->page.alignment) { case ALIGNMENT_TOP_LEFT: *ix = bx; diff --git a/src/common/cups_print.h b/src/common/cups_print.h index 12a49032763e..6670f4add3ea 100644 --- a/src/common/cups_print.h +++ b/src/common/cups_print.h @@ -22,7 +22,8 @@ #define MAX_NAME 128 -typedef enum dt_alignment_t { +typedef enum dt_alignment_t +{ ALIGNMENT_TOP_LEFT, ALIGNMENT_TOP, ALIGNMENT_TOP_RIGHT, @@ -88,11 +89,10 @@ void dt_print_file(const int32_t imgid, const char *filename, const dt_print_inf // - the printable area (ax, ay, awidth and aheight), the area without the borders // - the image position (ix, iy, iwidth, iheight) // there is no unit, every returned values are based on the area size. -void dt_get_print_layout(const int32_t imgid, const dt_print_info_t *prt, const int32_t area_width, const int32_t area_height, - int32_t *iwpix, int32_t *ihpix, - int32_t *px, int32_t *py, int32_t *pwidth, int32_t *pheight, - int32_t *ax, int32_t *ay, int32_t *awidth, int32_t *aheight, - int32_t *ix, int32_t *iy, int32_t *iwidth, int32_t *iheight); +void dt_get_print_layout(const int32_t imgid, const dt_print_info_t *prt, const int32_t area_width, + const int32_t area_height, int32_t *iwpix, int32_t *ihpix, int32_t *px, int32_t *py, + int32_t *pwidth, int32_t *pheight, int32_t *ax, int32_t *ay, int32_t *awidth, + int32_t *aheight, int32_t *ix, int32_t *iy, int32_t *iwidth, int32_t *iheight); // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh // vim: shiftwidth=2 expandtab tabstop=2 cindent diff --git a/src/common/darktable.c b/src/common/darktable.c index 93ce4e0c550b..919943977141 100644 --- a/src/common/darktable.c +++ b/src/common/darktable.c @@ -94,6 +94,10 @@ #include <omp.h> #endif +#ifdef HAVE_FFTW3_OMP +#include <fftw3.h> +#endif + #ifdef _WIN32 #include "win/dtwin.h" #endif //_WIN32 @@ -107,7 +111,8 @@ darktable_t darktable; static int usage(const char *argv0) { printf("usage: %s [-d " - "{all,cache,camctl,camsupport,control,dev,input,lighttable,lua,masks,memory,nan,opencl,perf,pwstorage,print,sql}]" + "{all,cache,camctl,camsupport,control,dev,input,lighttable,lua,masks,memory,nan,opencl,perf,pwstorage," + "print,sql}]" " [IMG_1234.{RAW,..}|image_folder/]", argv0); #ifdef HAVE_OPENCL @@ -133,8 +138,7 @@ gboolean dt_supported_image(const gchar *filename) { gboolean supported = FALSE; char *ext = g_strrstr(filename, "."); - if(!ext) - return FALSE; + if(!ext) return FALSE; ext++; for(const char **i = dt_supported_extensions; *i != NULL; i++) if(!g_ascii_strncasecmp(ext, *i, strlen(*i))) @@ -306,8 +310,7 @@ static void dt_codepaths_init() #endif { fprintf(stderr, "[dt_codepaths_init] SSE2-optimized codepath is disabled or unavailable.\n"); - fprintf(stderr, - "[dt_codepaths_init] expect a LOT of functionality to be broken. you have been warned.\n"); + fprintf(stderr, "[dt_codepaths_init] expect a LOT of functionality to be broken. you have been warned.\n"); } } @@ -317,8 +320,7 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load #ifndef __WIN32__ if(getuid() == 0 || geteuid() == 0) - printf( - "WARNING: either your user id or the effective user id are 0. are you running darktable as root?\n"); + printf("WARNING: either your user id or the effective user id are 0. are you running darktable as root?\n"); #endif #if defined(__SSE__) @@ -381,13 +383,13 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load #ifndef _WIN32 // see http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html for a reason to use those as a // default - if(!g_strcmp0(DARKTABLE_SHAREDIR, "/usr/local/share") - || !g_strcmp0(DARKTABLE_SHAREDIR, "/usr/local/share/") + if(!g_strcmp0(DARKTABLE_SHAREDIR, "/usr/local/share") || !g_strcmp0(DARKTABLE_SHAREDIR, "/usr/local/share/") || !g_strcmp0(DARKTABLE_SHAREDIR, "/usr/share") || !g_strcmp0(DARKTABLE_SHAREDIR, "/usr/share/")) new_xdg_data_dirs = g_strdup("/usr/local/share/" G_SEARCHPATH_SEPARATOR_S "/usr/share/"); else - new_xdg_data_dirs = g_strdup_printf("%s" G_SEARCHPATH_SEPARATOR_S "/usr/local/share/" G_SEARCHPATH_SEPARATOR_S - "/usr/share/", DARKTABLE_SHAREDIR); + new_xdg_data_dirs = g_strdup_printf("%s" G_SEARCHPATH_SEPARATOR_S + "/usr/local/share/" G_SEARCHPATH_SEPARATOR_S "/usr/share/", + DARKTABLE_SHAREDIR); #else set_env = FALSE; #endif @@ -436,6 +438,10 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load darktable.num_openmp_threads = 1; #ifdef _OPENMP darktable.num_openmp_threads = omp_get_num_procs(); + +#ifdef HAVE_FFTW3_OMP + fftwf_init_threads(); +#endif #endif darktable.unmuted = 0; GSList *config_override = NULL; @@ -454,14 +460,11 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load else if(!strcmp(argv[k], "--version")) { #ifdef USE_LUA - const char *lua_api_version = strcmp(LUA_API_VERSION_SUFFIX, "") ? - STR(LUA_API_VERSION_MAJOR) "." - STR(LUA_API_VERSION_MINOR) "." - STR(LUA_API_VERSION_PATCH) "-" - LUA_API_VERSION_SUFFIX : - STR(LUA_API_VERSION_MAJOR) "." - STR(LUA_API_VERSION_MINOR) "." - STR(LUA_API_VERSION_PATCH); + const char *lua_api_version + = strcmp(LUA_API_VERSION_SUFFIX, "") + ? STR(LUA_API_VERSION_MAJOR) "." STR(LUA_API_VERSION_MINOR) "." STR( + LUA_API_VERSION_PATCH) "-" LUA_API_VERSION_SUFFIX + : STR(LUA_API_VERSION_MAJOR) "." STR(LUA_API_VERSION_MINOR) "." STR(LUA_API_VERSION_PATCH); #endif printf("this is %s\ncopyright (c) 2009-%s johannes hanika\n" PACKAGE_BUGREPORT "\n\ncompile options:\n" " bit depth is %s\n" @@ -517,8 +520,7 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load " OpenEXR support disabled\n" #endif , - darktable_package_string, - darktable_last_commit_year, + darktable_package_string, darktable_last_commit_year, (sizeof(void *) == 8 ? "64 bit" : sizeof(void *) == 4 ? "32 bit" : "unknown") #if USE_LUA , @@ -530,43 +532,43 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load else if(!strcmp(argv[k], "--library") && argc > k + 1) { dbfilename_from_command = argv[++k]; - argv[k-1] = NULL; + argv[k - 1] = NULL; argv[k] = NULL; } else if(!strcmp(argv[k], "--datadir") && argc > k + 1) { datadir_from_command = argv[++k]; - argv[k-1] = NULL; + argv[k - 1] = NULL; argv[k] = NULL; } else if(!strcmp(argv[k], "--moduledir") && argc > k + 1) { moduledir_from_command = argv[++k]; - argv[k-1] = NULL; + argv[k - 1] = NULL; argv[k] = NULL; } else if(!strcmp(argv[k], "--tmpdir") && argc > k + 1) { tmpdir_from_command = argv[++k]; - argv[k-1] = NULL; + argv[k - 1] = NULL; argv[k] = NULL; } else if(!strcmp(argv[k], "--configdir") && argc > k + 1) { configdir_from_command = argv[++k]; - argv[k-1] = NULL; + argv[k - 1] = NULL; argv[k] = NULL; } else if(!strcmp(argv[k], "--cachedir") && argc > k + 1) { cachedir_from_command = argv[++k]; - argv[k-1] = NULL; + argv[k - 1] = NULL; argv[k] = NULL; } else if(!strcmp(argv[k], "--localedir") && argc > k + 1) { bindtextdomain(GETTEXT_PACKAGE, argv[++k]); - argv[k-1] = NULL; + argv[k - 1] = NULL; argv[k] = NULL; } else if(argv[k][1] == 'd' && argc > k + 1) @@ -608,7 +610,7 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load else return usage(argv[0]); k++; - argv[k-1] = NULL; + argv[k - 1] = NULL; argv[k] = NULL; } else if(argv[k][1] == 't' && argc > k + 1) @@ -616,13 +618,13 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load darktable.num_openmp_threads = CLAMP(atol(argv[k + 1]), 1, 100); printf("[dt_init] using %d threads for openmp parallel sections\n", darktable.num_openmp_threads); k++; - argv[k-1] = NULL; + argv[k - 1] = NULL; argv[k] = NULL; } else if(!strcmp(argv[k], "--conf") && argc > k + 1) { gchar *keyval = g_strdup(argv[++k]), *c = keyval; - argv[k-1] = NULL; + argv[k - 1] = NULL; argv[k] = NULL; gchar *end = keyval + strlen(keyval); while(*c != '=' && c < end) c++; @@ -639,7 +641,7 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load else if(!strcmp(argv[k], "--noiseprofiles") && argc > k + 1) { noiseprofiles_from_command = argv[++k]; - argv[k-1] = NULL; + argv[k - 1] = NULL; argv[k] = NULL; } else if(!strcmp(argv[k], "--luacmd") && argc > k + 1) @@ -649,7 +651,7 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load #else ++k; #endif - argv[k-1] = NULL; + argv[k - 1] = NULL; argv[k] = NULL; } else if(!strcmp(argv[k], "--disable-opencl")) @@ -682,7 +684,7 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load k -= i; for(int j = i + k; j < argc; j++) { - argv[j-k] = argv[j]; + argv[j - k] = argv[j]; argv[j] = NULL; } argc -= k; @@ -804,10 +806,10 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load if(filename == NULL) continue; if(!connection) connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); // ... and send it to the running instance of darktable - image_loaded_elsewhere = g_dbus_connection_call_sync(connection, "org.darktable.service", "/darktable", - "org.darktable.service.Remote", "Open", - g_variant_new("(s)", filename), NULL, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL) != NULL; + image_loaded_elsewhere + = g_dbus_connection_call_sync(connection, "org.darktable.service", "/darktable", + "org.darktable.service.Remote", "Open", g_variant_new("(s)", filename), + NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL) != NULL; g_free(filename); } if(connection) g_object_unref(connection); @@ -1035,6 +1037,16 @@ void dt_cleanup() #ifdef USE_LUA dt_lua_finalize(); #endif + +#ifdef HAVE_FFTW3_OMP +#ifdef _OPENMP + + fftwf_cleanup_threads(); + +#endif +#endif + + dt_view_manager_cleanup(darktable.view_manager); free(darktable.view_manager); if(init_gui) @@ -1162,8 +1174,8 @@ void dt_configure_defaults() const int threads = dt_get_num_threads(); const size_t mem = dt_get_total_memory(); const int bits = (sizeof(void *) == 4) ? 32 : 64; - fprintf(stderr, "[defaults] found a %d-bit system with %zu kb ram and %d cores (%d atom based)\n", bits, - mem, threads, atom_cores); + fprintf(stderr, "[defaults] found a %d-bit system with %zu kb ram and %d cores (%d atom based)\n", bits, mem, + threads, atom_cores); if(mem >= (8u << 20) && threads > 4) { fprintf(stderr, "[defaults] setting very high quality defaults\n"); diff --git a/src/common/darktable.h b/src/common/darktable.h index 01caf66afadc..f7390b2d4851 100644 --- a/src/common/darktable.h +++ b/src/common/darktable.h @@ -86,24 +86,24 @@ typedef unsigned int u_int; // every module has to define this: #ifdef _DEBUG -#define DT_MODULE(MODVER) \ - int dt_module_dt_version() \ - { \ - return -DT_MODULE_VERSION; \ - } \ - int dt_module_mod_version() \ - { \ - return MODVER; \ +#define DT_MODULE(MODVER) \ + int dt_module_dt_version() \ + { \ + return -DT_MODULE_VERSION; \ + } \ + int dt_module_mod_version() \ + { \ + return MODVER; \ } #else -#define DT_MODULE(MODVER) \ - int dt_module_dt_version() \ - { \ - return DT_MODULE_VERSION; \ - } \ - int dt_module_mod_version() \ - { \ - return MODVER; \ +#define DT_MODULE(MODVER) \ + int dt_module_dt_version() \ + { \ + return DT_MODULE_VERSION; \ + } \ + int dt_module_mod_version() \ + { \ + return MODVER; \ } #endif @@ -249,7 +249,7 @@ void dt_free_align(void *mem); static inline gboolean dt_is_aligned(const void *pointer, size_t byte_count) { - return (uintptr_t)pointer % byte_count == 0; + return (uintptr_t)pointer % byte_count == 0; } int dt_capabilities_check(char *capability); @@ -273,7 +273,8 @@ static inline void dt_get_times(dt_times_t *t) t->user = ru.ru_utime.tv_sec + ru.ru_utime.tv_usec * (1.0 / 1000000.0); } -void dt_show_times(const dt_times_t *start, const char *prefix, const char *suffix, ...) __attribute__((format(printf, 3, 4))); +void dt_show_times(const dt_times_t *start, const char *prefix, const char *suffix, ...) + __attribute__((format(printf, 3, 4))); /** \brief check if file is a supported image */ gboolean dt_supported_image(const gchar *filename); @@ -374,8 +375,9 @@ static inline void dt_print_mem_usage() "[memory] max used memory (vmhwm ): %15s\n" "[memory] cur used memory (vmrss ): %12llu kB\n", "unknown", (uint64_t)t_info.virtual_size / 1024, "unknown", (uint64_t)t_info.resident_size / 1024); -#elif defined (_WIN32) - //Based on: http://stackoverflow.com/questions/63166/how-to-determine-cpu-and-memory-consumption-from-inside-a-process +#elif defined(_WIN32) + // Based on: + // http://stackoverflow.com/questions/63166/how-to-determine-cpu-and-memory-consumption-from-inside-a-process MEMORYSTATUSEX memInfo; memInfo.dwLength = sizeof(MEMORYSTATUSEX); GlobalMemoryStatusEx(&memInfo); @@ -501,7 +503,7 @@ static inline size_t dt_get_total_memory() fclose(f); if(len > 0) free(line); return mem; -#elif defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) \ +#elif defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) \ || defined(__OpenBSD__) #if defined(__APPLE__) int mib[2] = { CTL_HW, HW_MEMSIZE }; @@ -532,11 +534,11 @@ void dt_configure_defaults(); // it tells you if it was a single image or a directory in single_image (when it's not NULL) int dt_load_from_string(const gchar *image_to_load, gboolean open_image_in_dr, gboolean *single_image); -#define dt_unreachable_codepath_with_desc(D) \ +#define dt_unreachable_codepath_with_desc(D) \ dt_unreachable_codepath_with_caller(D, __FILE__, __LINE__, __FUNCTION__) #define dt_unreachable_codepath() dt_unreachable_codepath_with_caller(NULL, __FILE__, __LINE__, __FUNCTION__) -static inline void dt_unreachable_codepath_with_caller(const char *description, const char *file, - const int line, const char *function) +static inline void dt_unreachable_codepath_with_caller(const char *description, const char *file, const int line, + const char *function) { fprintf(stderr, "[dt_unreachable_codepath] {%s} %s:%d (%s) - we should not be here. please report this to " "the developers.", diff --git a/src/common/database.c b/src/common/database.c index 1174c74c7282..840ae811cf57 100644 --- a/src/common/database.c +++ b/src/common/database.c @@ -63,12 +63,12 @@ static void _database_migrate_to_xdg_structure(); /* delete old mipmaps files */ static void _database_delete_mipmaps_files(); -#define _SQLITE3_EXEC(a, b, c, d, e) \ - if(sqlite3_exec(a, b, c, d, e) != SQLITE_OK) \ - { \ - all_ok = FALSE; \ - failing_query = b; \ - goto end; \ +#define _SQLITE3_EXEC(a, b, c, d, e) \ + if(sqlite3_exec(a, b, c, d, e) != SQLITE_OK) \ + { \ + all_ok = FALSE; \ + failing_query = b; \ + goto end; \ } /* migrate from the legacy db format (with the 'settings' blob) to the first version this system knows */ @@ -96,16 +96,16 @@ static gboolean _migrate_schema(dt_database_t *db, int version) _SQLITE3_EXEC(db->handle, "DROP TABLE IF EXISTS main.mipmap_timestamps", NULL, NULL, NULL); _SQLITE3_EXEC(db->handle, "DROP TABLE IF EXISTS main.dt_migration_table", NULL, NULL, NULL); - // using _create_library_schema() and filling that with the old data doesn't work since we always want to generate + // using _create_library_schema() and filling that with the old data doesn't work since we always want to + // generate // version 1 tables ////////////////////////////// db_info - _SQLITE3_EXEC(db->handle, "CREATE TABLE main.db_info (key VARCHAR PRIMARY KEY, value VARCHAR)", - NULL, NULL, NULL); - _SQLITE3_EXEC(db->handle, "INSERT OR REPLACE INTO main.db_info (key, value) VALUES ('version', 1)", - NULL, NULL, NULL); + _SQLITE3_EXEC(db->handle, "CREATE TABLE main.db_info (key VARCHAR PRIMARY KEY, value VARCHAR)", NULL, NULL, NULL); + _SQLITE3_EXEC(db->handle, "INSERT OR REPLACE INTO main.db_info (key, value) VALUES ('version', 1)", NULL, NULL, + NULL); ////////////////////////////// film_rolls - _SQLITE3_EXEC(db->handle, "CREATE INDEX IF NOT EXISTS main.film_rolls_folder_index ON film_rolls (folder)", - NULL, NULL, NULL); + _SQLITE3_EXEC(db->handle, "CREATE INDEX IF NOT EXISTS main.film_rolls_folder_index ON film_rolls (folder)", NULL, + NULL, NULL); ////////////////////////////// images sqlite3_exec(db->handle, "ALTER TABLE main.images ADD COLUMN orientation INTEGER", NULL, NULL, NULL); sqlite3_exec(db->handle, "ALTER TABLE main.images ADD COLUMN focus_distance REAL", NULL, NULL, NULL); @@ -120,19 +120,17 @@ static gboolean _migrate_schema(dt_database_t *db, int version) sqlite3_exec(db->handle, "ALTER TABLE main.images ADD COLUMN version INTEGER", NULL, NULL, NULL); sqlite3_exec(db->handle, "ALTER TABLE main.images ADD COLUMN max_version INTEGER", NULL, NULL, NULL); _SQLITE3_EXEC(db->handle, "UPDATE main.images SET orientation = -1 WHERE orientation IS NULL", NULL, NULL, NULL); - _SQLITE3_EXEC(db->handle, "UPDATE main.images SET focus_distance = -1 WHERE focus_distance IS NULL", - NULL, NULL, NULL); + _SQLITE3_EXEC(db->handle, "UPDATE main.images SET focus_distance = -1 WHERE focus_distance IS NULL", NULL, NULL, + NULL); _SQLITE3_EXEC(db->handle, "UPDATE main.images SET group_id = id WHERE group_id IS NULL", NULL, NULL, NULL); _SQLITE3_EXEC(db->handle, "UPDATE main.images SET max_version = (SELECT COUNT(*)-1 FROM main.images i WHERE " "i.filename = main.images.filename AND " "i.film_id = main.images.film_id) WHERE max_version IS NULL", NULL, NULL, NULL); - _SQLITE3_EXEC( - db->handle, - "UPDATE main.images SET version = (SELECT COUNT(*) FROM main.images i " - "WHERE i.filename = main.images.filename AND " - "i.film_id = main.images.film_id AND i.id < main.images.id) WHERE version IS NULL", - NULL, NULL, NULL); + _SQLITE3_EXEC(db->handle, "UPDATE main.images SET version = (SELECT COUNT(*) FROM main.images i " + "WHERE i.filename = main.images.filename AND " + "i.film_id = main.images.film_id AND i.id < main.images.id) WHERE version IS NULL", + NULL, NULL, NULL); // make sure we have AUTOINCREMENT on imgid --> move the whole thing away and recreate the table :( _SQLITE3_EXEC(db->handle, "ALTER TABLE main.images RENAME TO dt_migration_table", NULL, NULL, NULL); _SQLITE3_EXEC(db->handle, "DROP INDEX IF EXISTS main.images_group_id_index", NULL, NULL, NULL); @@ -223,8 +221,8 @@ static gboolean _migrate_schema(dt_database_t *db, int version) NULL); ////////////////////////////// color_labels // color_labels could have a PRIMARY KEY that we don't want - _SQLITE3_EXEC(db->handle, "CREATE TEMPORARY TABLE dt_migration_table (imgid INTEGER, color INTEGER)", NULL, - NULL, NULL); + _SQLITE3_EXEC(db->handle, "CREATE TEMPORARY TABLE dt_migration_table (imgid INTEGER, color INTEGER)", NULL, NULL, + NULL); _SQLITE3_EXEC(db->handle, "INSERT INTO dt_migration_table SELECT imgid, color FROM main.color_labels", NULL, NULL, NULL); _SQLITE3_EXEC(db->handle, "DROP TABLE main.color_labels", NULL, NULL, NULL); @@ -372,43 +370,43 @@ static gboolean _migrate_schema(dt_database_t *db, int version) #undef _SQLITE3_EXEC -#define TRY_EXEC(_query, _message) \ - do \ - { \ - if(sqlite3_exec(db->handle, _query, NULL, NULL, NULL) != SQLITE_OK) \ - { \ - fprintf(stderr, _message); \ - fprintf(stderr, "[init] %s\n", sqlite3_errmsg(db->handle)); \ - FINALIZE; \ - sqlite3_exec(db->handle, "ROLLBACK TRANSACTION", NULL, NULL, NULL); \ - return version; \ - } \ +#define TRY_EXEC(_query, _message) \ + do \ + { \ + if(sqlite3_exec(db->handle, _query, NULL, NULL, NULL) != SQLITE_OK) \ + { \ + fprintf(stderr, _message); \ + fprintf(stderr, "[init] %s\n", sqlite3_errmsg(db->handle)); \ + FINALIZE; \ + sqlite3_exec(db->handle, "ROLLBACK TRANSACTION", NULL, NULL, NULL); \ + return version; \ + } \ } while(0) -#define TRY_STEP(_stmt, _expected, _message) \ - do \ - { \ - if(sqlite3_step(_stmt) != _expected) \ - { \ - fprintf(stderr, _message); \ - fprintf(stderr, "[init] %s\n", sqlite3_errmsg(db->handle)); \ - FINALIZE; \ - sqlite3_exec(db->handle, "ROLLBACK TRANSACTION", NULL, NULL, NULL); \ - return version; \ - } \ +#define TRY_STEP(_stmt, _expected, _message) \ + do \ + { \ + if(sqlite3_step(_stmt) != _expected) \ + { \ + fprintf(stderr, _message); \ + fprintf(stderr, "[init] %s\n", sqlite3_errmsg(db->handle)); \ + FINALIZE; \ + sqlite3_exec(db->handle, "ROLLBACK TRANSACTION", NULL, NULL, NULL); \ + return version; \ + } \ } while(0) -#define TRY_PREPARE(_stmt, _query, _message) \ - do \ - { \ - if(sqlite3_prepare_v2(db->handle, _query, -1, &_stmt, NULL) != SQLITE_OK) \ - { \ - fprintf(stderr, _message); \ - fprintf(stderr, "[init] %s\n", sqlite3_errmsg(db->handle)); \ - FINALIZE; \ - sqlite3_exec(db->handle, "ROLLBACK TRANSACTION", NULL, NULL, NULL); \ - return version; \ - } \ +#define TRY_PREPARE(_stmt, _query, _message) \ + do \ + { \ + if(sqlite3_prepare_v2(db->handle, _query, -1, &_stmt, NULL) != SQLITE_OK) \ + { \ + fprintf(stderr, _message); \ + fprintf(stderr, "[init] %s\n", sqlite3_errmsg(db->handle)); \ + FINALIZE; \ + sqlite3_exec(db->handle, "ROLLBACK TRANSACTION", NULL, NULL, NULL); \ + return version; \ + } \ } while(0) // redefine this where needed @@ -489,7 +487,7 @@ static int _upgrade_library_schema_step(dt_database_t *db, int version) { sqlite3_exec(db->handle, "BEGIN TRANSACTION", NULL, NULL, NULL); - TRY_EXEC("ALTER TABLE main.presets RENAME TO tmp_presets", "[init] can't rename table presets\n"); + TRY_EXEC("ALTER TABLE main.presets RENAME TO tmp_presets", "[init] can't rename table presets\n"); TRY_EXEC("CREATE TABLE main.presets (name VARCHAR, description VARCHAR, operation VARCHAR, op_params BLOB," "enabled INTEGER, blendop_params BLOB, model VARCHAR, maker VARCHAR, lens VARCHAR," @@ -583,7 +581,8 @@ static int _upgrade_library_schema_step(dt_database_t *db, int version) "[init] can't add `history_end' column to database\n"); TRY_EXEC("UPDATE main.images SET history_end = (SELECT IFNULL(MAX(num) + 1, 0) FROM main.history " - "WHERE imgid = id)", "[init] can't initialize `history_end' with last history entry\n"); + "WHERE imgid = id)", + "[init] can't initialize `history_end' with last history entry\n"); sqlite3_exec(db->handle, "COMMIT", NULL, NULL, NULL); new_version = 9; @@ -594,7 +593,8 @@ static int _upgrade_library_schema_step(dt_database_t *db, int version) sqlite3_exec(db->handle, "BEGIN TRANSACTION", NULL, NULL, NULL); TRY_EXEC("UPDATE main.images SET history_end = (SELECT IFNULL(MAX(num) + 1, 0) FROM main.history " - "WHERE imgid = id)", "[init] can't set `history_end' to 0 where it was NULL\n"); + "WHERE imgid = id)", + "[init] can't set `history_end' to 0 where it was NULL\n"); sqlite3_exec(db->handle, "COMMIT", NULL, NULL, NULL); new_version = 10; @@ -635,52 +635,52 @@ static int _upgrade_library_schema_step(dt_database_t *db, int version) // 11 -> 12 move presets, styles and tags over to the data database sqlite3_exec(db->handle, "BEGIN TRANSACTION", NULL, NULL, NULL); - ////////////// presets +////////////// presets #undef FINALIZE -#define FINALIZE \ - do \ - { \ - sqlite3_finalize(stmt); \ - sqlite3_finalize(select_stmt); \ - sqlite3_finalize(count_clashes_stmt); \ - sqlite3_finalize(update_name_stmt); \ - sqlite3_finalize(insert_stmt); \ - sqlite3_finalize(delete_stmt); \ - } while(0) +#define FINALIZE \ + do \ + { \ + sqlite3_finalize(stmt); \ + sqlite3_finalize(select_stmt); \ + sqlite3_finalize(count_clashes_stmt); \ + sqlite3_finalize(update_name_stmt); \ + sqlite3_finalize(insert_stmt); \ + sqlite3_finalize(delete_stmt); \ + } while(0) stmt = NULL; sqlite3_stmt *insert_stmt = NULL, *delete_stmt = NULL, *select_stmt = NULL, *count_clashes_stmt = NULL, - *update_name_stmt = NULL; + *update_name_stmt = NULL; // remove presets that are already in data. // we can't use a NATURAL JOIN here as that fails when columns have NULL values. :-( TRY_EXEC("DELETE FROM main.presets WHERE rowid IN (SELECT p1.rowid FROM main.presets p1 " "JOIN data.presets p2 ON " - "p1.name IS p2.name AND " - "p1.description IS p2.description AND " - "p1.operation IS p2.operation AND " - "p1.op_version IS p2.op_version AND " - "p1.op_params IS p2.op_params AND " - "p1.enabled IS p2.enabled AND " - "p1.blendop_params IS p2.blendop_params AND " - "p1.blendop_version IS p2.blendop_version AND " - "p1.multi_priority IS p2.multi_priority AND " - "p1.multi_name IS p2.multi_name AND " - "p1.model IS p2.model AND " - "p1.maker IS p2.maker AND " - "p1.lens IS p2.lens AND " - "p1.iso_min IS p2.iso_min AND " - "p1.iso_max IS p2.iso_max AND " - "p1.exposure_min IS p2.exposure_min AND " - "p1.exposure_max IS p2.exposure_max AND " - "p1.aperture_min IS p2.aperture_min AND " - "p1.aperture_max IS p2.aperture_max AND " - "p1.focal_length_min IS p2.focal_length_min AND " - "p1.focal_length_max IS p2.focal_length_max AND " - "p1.writeprotect IS p2.writeprotect AND " - "p1.autoapply IS p2.autoapply AND " - "p1.filter IS p2.filter AND " - "p1.def IS p2.def AND " - "p1.format IS p2.format " + "p1.name IS p2.name AND " + "p1.description IS p2.description AND " + "p1.operation IS p2.operation AND " + "p1.op_version IS p2.op_version AND " + "p1.op_params IS p2.op_params AND " + "p1.enabled IS p2.enabled AND " + "p1.blendop_params IS p2.blendop_params AND " + "p1.blendop_version IS p2.blendop_version AND " + "p1.multi_priority IS p2.multi_priority AND " + "p1.multi_name IS p2.multi_name AND " + "p1.model IS p2.model AND " + "p1.maker IS p2.maker AND " + "p1.lens IS p2.lens AND " + "p1.iso_min IS p2.iso_min AND " + "p1.iso_max IS p2.iso_max AND " + "p1.exposure_min IS p2.exposure_min AND " + "p1.exposure_max IS p2.exposure_max AND " + "p1.aperture_min IS p2.aperture_min AND " + "p1.aperture_max IS p2.aperture_max AND " + "p1.focal_length_min IS p2.focal_length_min AND " + "p1.focal_length_max IS p2.focal_length_max AND " + "p1.writeprotect IS p2.writeprotect AND " + "p1.autoapply IS p2.autoapply AND " + "p1.filter IS p2.filter AND " + "p1.def IS p2.def AND " + "p1.format IS p2.format " "WHERE p1.writeprotect = 0)", "[init] can't delete already migrated presets from database\n"); @@ -719,7 +719,8 @@ static int _upgrade_library_schema_step(dt_database_t *db, int version) "FROM main.presets p1 WHERE p1.rowid = ?2", "[init] can't prepare insertion statement\n"); - TRY_PREPARE(delete_stmt, "DELETE FROM main.presets WHERE rowid = ?1", "[init] can't prepare deletion statement\n"); + TRY_PREPARE(delete_stmt, "DELETE FROM main.presets WHERE rowid = ?1", + "[init] can't prepare deletion statement\n"); // first rename presets with (name, operation, op_version) not being unique while(sqlite3_step(select_stmt) == SQLITE_ROW) @@ -735,8 +736,7 @@ static int _upgrade_library_schema_step(dt_database_t *db, int version) sqlite3_clear_bindings(count_clashes_stmt); sqlite3_bind_int(count_clashes_stmt, 1, other_rowid); sqlite3_bind_int(count_clashes_stmt, 2, preset_version); - } - while(sqlite3_step(count_clashes_stmt) == SQLITE_ROW && sqlite3_column_int(count_clashes_stmt, 0) > 0); + } while(sqlite3_step(count_clashes_stmt) == SQLITE_ROW && sqlite3_column_int(count_clashes_stmt, 0) > 0); sqlite3_bind_int(update_name_stmt, 1, preset_version); sqlite3_bind_int(update_name_stmt, 2, own_rowid); @@ -781,19 +781,19 @@ static int _upgrade_library_schema_step(dt_database_t *db, int version) FINALIZE; #undef FINALIZE - ////////////// styles -#define FINALIZE \ - do \ - { \ - sqlite3_finalize(stmt); \ - sqlite3_finalize(insert_stmt); \ - sqlite3_finalize(select_stmt); \ - sqlite3_finalize(delete_stmt); \ - sqlite3_finalize(update_name_stmt); \ - sqlite3_finalize(select_new_stmt); \ - sqlite3_finalize(copy_style_items_stmt); \ - sqlite3_finalize(delete_style_items_stmt); \ - } while(0) +////////////// styles +#define FINALIZE \ + do \ + { \ + sqlite3_finalize(stmt); \ + sqlite3_finalize(insert_stmt); \ + sqlite3_finalize(select_stmt); \ + sqlite3_finalize(delete_stmt); \ + sqlite3_finalize(update_name_stmt); \ + sqlite3_finalize(select_new_stmt); \ + sqlite3_finalize(copy_style_items_stmt); \ + sqlite3_finalize(delete_style_items_stmt); \ + } while(0) stmt = NULL; select_stmt = NULL; @@ -895,7 +895,7 @@ static int _upgrade_library_schema_step(dt_database_t *db, int version) FINALIZE; #undef FINALIZE - ////////////// tags +////////////// tags #define FINALIZE // tags @@ -910,7 +910,8 @@ static int _upgrade_library_schema_step(dt_database_t *db, int version) TRY_EXEC("INSERT INTO tagged_images_tmp (imgid, tagid) " "SELECT imgid, (SELECT t2.id FROM main.tags t1, data.tags t2 USING (name) WHERE t1.id = tagid) " - "FROM main.tagged_images", "[init] can't insert into `tagged_images_tmp'\n"); + "FROM main.tagged_images", + "[init] can't insert into `tagged_images_tmp'\n"); TRY_EXEC("DELETE FROM main.tagged_images", "[init] can't delete tagged images in database\n"); @@ -928,7 +929,8 @@ static int _upgrade_library_schema_step(dt_database_t *db, int version) sqlite3_exec(db->handle, "COMMIT", NULL, NULL, NULL); new_version = 13; - } else if(version == 13) + } + else if(version == 13) { // 12 -> 13 bring back the used tag names to library.db so people can use it independently of data.db sqlite3_exec(db->handle, "BEGIN TRANSACTION", NULL, NULL, NULL); @@ -968,17 +970,17 @@ static int _upgrade_library_schema_step(dt_database_t *db, int version) sqlite3_exec(db->handle, "COMMIT", NULL, NULL, NULL); new_version = 15; } // maybe in the future, see commented out code elsewhere - // else if(version == XXX) - // { - // sqlite3_exec(db->handle, "ALTER TABLE film_rolls ADD COLUMN external_drive VARCHAR(1024)", NULL, - // NULL, NULL); - // } + // else if(version == XXX) + // { + // sqlite3_exec(db->handle, "ALTER TABLE film_rolls ADD COLUMN external_drive VARCHAR(1024)", NULL, + // NULL, NULL); + // } else new_version = version; // should be the fallback so that calling code sees that we are in an infinite loop // write the new version to db - sqlite3_prepare_v2(db->handle, "INSERT OR REPLACE INTO main.db_info (key, value) VALUES ('version', ?1)", -1, &stmt, - NULL); + sqlite3_prepare_v2(db->handle, "INSERT OR REPLACE INTO main.db_info (key, value) VALUES ('version', ?1)", -1, + &stmt, NULL); sqlite3_bind_int(stmt, 1, new_version); sqlite3_step(stmt); sqlite3_finalize(stmt); @@ -1010,8 +1012,8 @@ static int _upgrade_data_schema_step(dt_database_t *db, int version) new_version = version; // should be the fallback so that calling code sees that we are in an infinite loop // write the new version to db - sqlite3_prepare_v2(db->handle, "INSERT OR REPLACE INTO data.db_info (key, value) VALUES ('version', ?1)", -1, &stmt, - NULL); + sqlite3_prepare_v2(db->handle, "INSERT OR REPLACE INTO data.db_info (key, value) VALUES ('version', ?1)", -1, + &stmt, NULL); sqlite3_bind_int(stmt, 1, new_version); sqlite3_step(stmt); sqlite3_finalize(stmt); @@ -1054,10 +1056,9 @@ static void _create_library_schema(dt_database_t *db) { sqlite3_stmt *stmt; ////////////////////////////// db_info - sqlite3_exec(db->handle, "CREATE TABLE main.db_info (key VARCHAR PRIMARY KEY, value VARCHAR)", NULL, - NULL, NULL); - sqlite3_prepare_v2( - db->handle, "INSERT OR REPLACE INTO main.db_info (key, value) VALUES ('version', ?1)", -1, &stmt, NULL); + sqlite3_exec(db->handle, "CREATE TABLE main.db_info (key VARCHAR PRIMARY KEY, value VARCHAR)", NULL, NULL, NULL); + sqlite3_prepare_v2(db->handle, "INSERT OR REPLACE INTO main.db_info (key, value) VALUES ('version', ?1)", -1, + &stmt, NULL); sqlite3_bind_int(stmt, 1, CURRENT_DATABASE_VERSION_LIBRARY); sqlite3_step(stmt); sqlite3_finalize(stmt); @@ -1092,12 +1093,11 @@ static void _create_library_schema(dt_database_t *db) ////////////////////////////// selected_images sqlite3_exec(db->handle, "CREATE TABLE main.selected_images (imgid INTEGER PRIMARY KEY)", NULL, NULL, NULL); ////////////////////////////// history - sqlite3_exec( - db->handle, - "CREATE TABLE main.history (imgid INTEGER, num INTEGER, module INTEGER, " - "operation VARCHAR(256), op_params BLOB, enabled INTEGER, " - "blendop_params BLOB, blendop_version INTEGER, multi_priority INTEGER, multi_name VARCHAR(256))", - NULL, NULL, NULL); + sqlite3_exec(db->handle, + "CREATE TABLE main.history (imgid INTEGER, num INTEGER, module INTEGER, " + "operation VARCHAR(256), op_params BLOB, enabled INTEGER, " + "blendop_params BLOB, blendop_version INTEGER, multi_priority INTEGER, multi_name VARCHAR(256))", + NULL, NULL, NULL); sqlite3_exec(db->handle, "CREATE INDEX main.history_imgid_index ON history (imgid)", NULL, NULL, NULL); ////////////////////////////// mask sqlite3_exec(db->handle, @@ -1106,8 +1106,10 @@ static void _create_library_schema(dt_database_t *db) NULL, NULL, NULL); ////////////////////////////// tagged_images sqlite3_exec(db->handle, "CREATE TABLE main.tagged_images (imgid INTEGER, tagid INTEGER, " - "PRIMARY KEY (imgid, tagid))", NULL, NULL, NULL); - sqlite3_exec(db->handle, "CREATE INDEX main.tagged_images_tagid_index ON tagged_images (tagid)", NULL, NULL, NULL); + "PRIMARY KEY (imgid, tagid))", + NULL, NULL, NULL); + sqlite3_exec(db->handle, "CREATE INDEX main.tagged_images_tagid_index ON tagged_images (tagid)", NULL, NULL, + NULL); ////////////////////////////// used_tags sqlite3_exec(db->handle, "CREATE TABLE main.used_tags (id INTEGER, name VARCHAR NOT NULL)", NULL, NULL, NULL); sqlite3_exec(db->handle, "CREATE UNIQUE INDEX main.used_tags_idx ON used_tags (id, name)", NULL, NULL, NULL); @@ -1116,7 +1118,8 @@ static void _create_library_schema(dt_database_t *db) sqlite3_exec(db->handle, "CREATE UNIQUE INDEX main.color_labels_idx ON color_labels (imgid, color)", NULL, NULL, NULL); ////////////////////////////// meta_data - sqlite3_exec(db->handle, "CREATE TABLE main.meta_data (id INTEGER, key INTEGER, value VARCHAR)", NULL, NULL, NULL); + sqlite3_exec(db->handle, "CREATE TABLE main.meta_data (id INTEGER, key INTEGER, value VARCHAR)", NULL, NULL, + NULL); sqlite3_exec(db->handle, "CREATE INDEX main.metadata_index ON meta_data (id, key)", NULL, NULL, NULL); } @@ -1125,27 +1128,26 @@ static void _create_data_schema(dt_database_t *db) { sqlite3_stmt *stmt; ////////////////////////////// db_info - sqlite3_exec(db->handle, "CREATE TABLE data.db_info (key VARCHAR PRIMARY KEY, value VARCHAR)", NULL, - NULL, NULL); - sqlite3_prepare_v2( - db->handle, "INSERT OR REPLACE INTO data.db_info (key, value) VALUES ('version', ?1)", -1, &stmt, NULL); + sqlite3_exec(db->handle, "CREATE TABLE data.db_info (key VARCHAR PRIMARY KEY, value VARCHAR)", NULL, NULL, NULL); + sqlite3_prepare_v2(db->handle, "INSERT OR REPLACE INTO data.db_info (key, value) VALUES ('version', ?1)", -1, + &stmt, NULL); sqlite3_bind_int(stmt, 1, CURRENT_DATABASE_VERSION_DATA); sqlite3_step(stmt); sqlite3_finalize(stmt); ////////////////////////////// tags sqlite3_exec(db->handle, "CREATE TABLE data.tags (id INTEGER PRIMARY KEY, name VARCHAR, icon BLOB, " - "description VARCHAR, flags INTEGER)", NULL, NULL, NULL); + "description VARCHAR, flags INTEGER)", + NULL, NULL, NULL); sqlite3_exec(db->handle, "CREATE UNIQUE INDEX data.tags_name_idx ON tags (name)", NULL, NULL, NULL); ////////////////////////////// styles - sqlite3_exec(db->handle, "CREATE TABLE data.styles (id INTEGER, name VARCHAR, description VARCHAR)", - NULL, NULL, NULL); + sqlite3_exec(db->handle, "CREATE TABLE data.styles (id INTEGER, name VARCHAR, description VARCHAR)", NULL, NULL, + NULL); ////////////////////////////// style_items - sqlite3_exec( - db->handle, - "CREATE TABLE data.style_items (styleid INTEGER, num INTEGER, module INTEGER, " - "operation VARCHAR(256), op_params BLOB, enabled INTEGER, " - "blendop_params BLOB, blendop_version INTEGER, multi_priority INTEGER, multi_name VARCHAR(256))", - NULL, NULL, NULL); + sqlite3_exec(db->handle, + "CREATE TABLE data.style_items (styleid INTEGER, num INTEGER, module INTEGER, " + "operation VARCHAR(256), op_params BLOB, enabled INTEGER, " + "blendop_params BLOB, blendop_version INTEGER, multi_priority INTEGER, multi_name VARCHAR(256))", + NULL, NULL, NULL); ////////////////////////////// presets sqlite3_exec(db->handle, "CREATE TABLE data.presets (name VARCHAR, description VARCHAR, operation " "VARCHAR, op_version INTEGER, op_params BLOB, " @@ -1157,8 +1159,8 @@ static void _create_data_schema(dt_database_t *db) "focal_length_max REAL, writeprotect INTEGER, " "autoapply INTEGER, filter INTEGER, def INTEGER, format INTEGER)", NULL, NULL, NULL); - sqlite3_exec(db->handle, "CREATE UNIQUE INDEX data.presets_idx ON presets (name, operation, op_version)", - NULL, NULL, NULL); + sqlite3_exec(db->handle, "CREATE UNIQUE INDEX data.presets_idx ON presets (name, operation, op_version)", NULL, + NULL, NULL); } // create the in-memory tables @@ -1166,28 +1168,25 @@ static void _create_data_schema(dt_database_t *db) static void _create_memory_schema(dt_database_t *db) { sqlite3_exec(db->handle, "CREATE TABLE memory.color_labels_temp (imgid INTEGER PRIMARY KEY)", NULL, NULL, NULL); - sqlite3_exec( - db->handle, - "CREATE TABLE memory.collected_images (rowid INTEGER PRIMARY KEY AUTOINCREMENT, imgid INTEGER)", NULL, - NULL, NULL); + sqlite3_exec(db->handle, + "CREATE TABLE memory.collected_images (rowid INTEGER PRIMARY KEY AUTOINCREMENT, imgid INTEGER)", + NULL, NULL, NULL); sqlite3_exec(db->handle, "CREATE TABLE memory.tmp_selection (imgid INTEGER)", NULL, NULL, NULL); sqlite3_exec(db->handle, "CREATE TABLE memory.tagq (tmpid INTEGER PRIMARY KEY, id INTEGER)", NULL, NULL, NULL); sqlite3_exec(db->handle, "CREATE TABLE memory.taglist " "(tmpid INTEGER PRIMARY KEY, id INTEGER UNIQUE ON CONFLICT IGNORE, count INTEGER)", NULL, NULL, NULL); sqlite3_exec(db->handle, "CREATE TABLE memory.similar_tags (tagid INTEGER)", NULL, NULL, NULL); - sqlite3_exec( - db->handle, - "CREATE TABLE memory.history (imgid INTEGER, num INTEGER, module INTEGER, " - "operation VARCHAR(256) UNIQUE ON CONFLICT REPLACE, op_params BLOB, enabled INTEGER, " - "blendop_params BLOB, blendop_version INTEGER, multi_priority INTEGER, multi_name VARCHAR(256))", - NULL, NULL, NULL); - sqlite3_exec( - db->handle, - "CREATE TABLE memory.style_items (styleid INTEGER, num INTEGER, module INTEGER, " - "operation VARCHAR(256), op_params BLOB, enabled INTEGER, " - "blendop_params BLOB, blendop_version INTEGER, multi_priority INTEGER, multi_name VARCHAR(256))", - NULL, NULL, NULL); + sqlite3_exec(db->handle, + "CREATE TABLE memory.history (imgid INTEGER, num INTEGER, module INTEGER, " + "operation VARCHAR(256) UNIQUE ON CONFLICT REPLACE, op_params BLOB, enabled INTEGER, " + "blendop_params BLOB, blendop_version INTEGER, multi_priority INTEGER, multi_name VARCHAR(256))", + NULL, NULL, NULL); + sqlite3_exec(db->handle, + "CREATE TABLE memory.style_items (styleid INTEGER, num INTEGER, module INTEGER, " + "operation VARCHAR(256), op_params BLOB, enabled INTEGER, " + "blendop_params BLOB, blendop_version INTEGER, multi_priority INTEGER, multi_name VARCHAR(256))", + NULL, NULL, NULL); } static void _sanitize_db(dt_database_t *db) @@ -1223,49 +1222,50 @@ static void _sanitize_db(dt_database_t *db) // in library we keep the names of the tags used in tagged_images. however, using that table at runtime results // in some overhead not necessary so instead we just use the used_tags table to update tagged_images on startup -#define TRY_EXEC(_query, _message) \ - do \ - { \ - if(sqlite3_exec(db->handle, _query, NULL, NULL, NULL) != SQLITE_OK) \ - { \ - fprintf(stderr, _message); \ - fprintf(stderr, "[init] %s\n", sqlite3_errmsg(db->handle)); \ - FINALIZE; \ - sqlite3_exec(db->handle, "ROLLBACK TRANSACTION", NULL, NULL, NULL); \ - return FALSE; \ - } \ +#define TRY_EXEC(_query, _message) \ + do \ + { \ + if(sqlite3_exec(db->handle, _query, NULL, NULL, NULL) != SQLITE_OK) \ + { \ + fprintf(stderr, _message); \ + fprintf(stderr, "[init] %s\n", sqlite3_errmsg(db->handle)); \ + FINALIZE; \ + sqlite3_exec(db->handle, "ROLLBACK TRANSACTION", NULL, NULL, NULL); \ + return FALSE; \ + } \ } while(0) -#define TRY_STEP(_stmt, _expected, _message) \ - do \ - { \ - if(sqlite3_step(_stmt) != _expected) \ - { \ - fprintf(stderr, _message); \ - fprintf(stderr, "[init] %s\n", sqlite3_errmsg(db->handle)); \ - FINALIZE; \ - sqlite3_exec(db->handle, "ROLLBACK TRANSACTION", NULL, NULL, NULL); \ - return FALSE; \ - } \ +#define TRY_STEP(_stmt, _expected, _message) \ + do \ + { \ + if(sqlite3_step(_stmt) != _expected) \ + { \ + fprintf(stderr, _message); \ + fprintf(stderr, "[init] %s\n", sqlite3_errmsg(db->handle)); \ + FINALIZE; \ + sqlite3_exec(db->handle, "ROLLBACK TRANSACTION", NULL, NULL, NULL); \ + return FALSE; \ + } \ } while(0) -#define TRY_PREPARE(_stmt, _query, _message) \ - do \ - { \ - if(sqlite3_prepare_v2(db->handle, _query, -1, &_stmt, NULL) != SQLITE_OK) \ - { \ - fprintf(stderr, _message); \ - fprintf(stderr, "[init] %s\n", sqlite3_errmsg(db->handle)); \ - FINALIZE; \ - sqlite3_exec(db->handle, "ROLLBACK TRANSACTION", NULL, NULL, NULL); \ - return FALSE; \ - } \ +#define TRY_PREPARE(_stmt, _query, _message) \ + do \ + { \ + if(sqlite3_prepare_v2(db->handle, _query, -1, &_stmt, NULL) != SQLITE_OK) \ + { \ + fprintf(stderr, _message); \ + fprintf(stderr, "[init] %s\n", sqlite3_errmsg(db->handle)); \ + FINALIZE; \ + sqlite3_exec(db->handle, "ROLLBACK TRANSACTION", NULL, NULL, NULL); \ + return FALSE; \ + } \ } while(0) -#define FINALIZE \ - do \ - { \ - sqlite3_finalize(stmt); stmt = NULL; /* NULL so that finalize becomes a NOP */ \ +#define FINALIZE \ + do \ + { \ + sqlite3_finalize(stmt); \ + stmt = NULL; /* NULL so that finalize becomes a NOP */ \ } while(0) static gboolean _synchronize_tags(dt_database_t *db) @@ -1294,7 +1294,8 @@ static gboolean _synchronize_tags(dt_database_t *db) // insert id, name for the tags in main.used_tags according to data.tags TRY_EXEC("INSERT INTO temp_used_tags (id, name) SELECT t.id, t.name FROM main.used_tags, data.tags " - "AS t USING (name)", "[synchronize tags] can't collect used tags into temporary table\n"); + "AS t USING (name)", + "[synchronize tags] can't collect used tags into temporary table\n"); // insert updated valued into temp_tagged_images // FIXME: slowish! @@ -1338,14 +1339,14 @@ void dt_database_show_error(const dt_database_t *db) if(!db->lock_acquired) { char *label_text = g_markup_printf_escaped(_("an error has occured while trying to open the database from\n" - "\n" - "<span style=\"italic\">%s</span>\n" - "\n" - "%s\n"), - db->error_dbfilename, db->error_message ? db->error_message : ""); + "\n" + "<span style=\"italic\">%s</span>\n" + "\n" + "%s\n"), + db->error_dbfilename, db->error_message ? db->error_message : ""); dt_gui_show_standalone_yes_no_dialog(_("darktable - error locking database"), label_text, _("close darktable"), - /*_("try again")*/NULL); + /*_("try again")*/ NULL); g_free(label_text); } @@ -1369,8 +1370,7 @@ static gboolean pid_is_alive(int pid) long unsigned int n_filename = sizeof(wfilename); int ret = QueryFullProcessImageNameW(h, 0, wfilename, &n_filename); char *filename = g_utf16_to_utf8(wfilename, -1, NULL, NULL, NULL); - if(ret && n_filename > 0 && filename && g_str_has_suffix(filename, "darktable.exe")) - pid_is_alive = TRUE; + if(ret && n_filename > 0 && filename && g_str_has_suffix(filename, "darktable.exe")) pid_is_alive = TRUE; g_free(filename); CloseHandle(h); } @@ -1417,7 +1417,7 @@ static gboolean _lock_single_database(dt_database_t *db, const char *dbfilename, else { *lockfile = g_strconcat(dbfilename, ".lock", NULL); -lock_again: + lock_again: lock_tries++; old_mode = umask(0); fd = g_open(*lockfile, O_RDWR | O_CREAT | O_EXCL, 0666); @@ -1451,11 +1451,11 @@ static gboolean _lock_single_database(dt_database_t *db, const char *dbfilename, } else { - fprintf( - stderr, - "[init] the database lock file contains a pid that seems to be alive in your system: %d\n", - other_pid); - db->error_message = g_strdup_printf(_("the database lock file contains a pid that seems to be alive in your system: %d"), other_pid); + fprintf(stderr, + "[init] the database lock file contains a pid that seems to be alive in your system: %d\n", + other_pid); + db->error_message = g_strdup_printf( + _("the database lock file contains a pid that seems to be alive in your system: %d"), other_pid); } } else @@ -1469,23 +1469,22 @@ static gboolean _lock_single_database(dt_database_t *db, const char *dbfilename, { int err = errno; fprintf(stderr, "[init] error opening the database lock file for reading: %s\n", strerror(err)); - db->error_message = g_strdup_printf(_("error opening the database lock file for reading: %s"), strerror(err)); + db->error_message + = g_strdup_printf(_("error opening the database lock file for reading: %s"), strerror(err)); } } } g_free(pid); - if(db->error_message) - db->error_dbfilename = g_strdup(dbfilename); + if(db->error_message) db->error_dbfilename = g_strdup(dbfilename); return lock_acquired; } static gboolean _lock_databases(dt_database_t *db) { - if(!_lock_single_database(db, db->dbfilename_data, &db->lockfile_data)) - return FALSE; + if(!_lock_single_database(db, db->dbfilename_data, &db->lockfile_data)) return FALSE; if(!_lock_single_database(db, db->dbfilename_library, &db->lockfile_library)) { // unlock data.db to not leave a stale lock file around @@ -1655,9 +1654,8 @@ dt_database_t *dt_database_init(const char *alternative, const gboolean load_dat "the database from a backup or start with a new one?"), dbfilename_data); - gboolean shall_we_delete_the_db = - dt_gui_show_standalone_yes_no_dialog(_("darktable - error opening database"), label_text, - _("close darktable"), _("delete database")); + gboolean shall_we_delete_the_db = dt_gui_show_standalone_yes_no_dialog( + _("darktable - error opening database"), label_text, _("close darktable"), _("delete database")); g_free(label_text); @@ -1678,7 +1676,8 @@ dt_database_t *dt_database_init(const char *alternative, const gboolean load_dat else { fprintf(stderr, "[init] database `%s' is corrupt and can't be opened! either replace it from a backup or " - "delete the file so that darktable can create a new one the next time. aborting\n", dbfilename_data); + "delete the file so that darktable can create a new one the next time. aborting\n", + dbfilename_data); goto error; } } @@ -1709,8 +1708,7 @@ dt_database_t *dt_database_init(const char *alternative, const gboolean load_dat else if(db_version > CURRENT_DATABASE_VERSION_LIBRARY) { // newer: bail out. it's better than what we did before: delete everything - fprintf(stderr, "[init] database version of `%s' is too new for this build of darktable. aborting\n", - dbname); + fprintf(stderr, "[init] database version of `%s' is too new for this build of darktable. aborting\n", dbname); dt_database_destroy(db); db = NULL; goto error; @@ -1723,17 +1721,16 @@ dt_database_t *dt_database_init(const char *alternative, const gboolean load_dat // we inform the user here and let him decide what to do: exit or delete and try again. char *label_text = g_markup_printf_escaped(_("an error has occured while trying to open the database from\n" - "\n" - "<span style=\"italic\">%s</span>\n" - "\n" - "it seems that the database is corrupt.\n" - "do you want to close darktable now to manually restore\n" - "the database from a backup or start with a new one?"), + "\n" + "<span style=\"italic\">%s</span>\n" + "\n" + "it seems that the database is corrupt.\n" + "do you want to close darktable now to manually restore\n" + "the database from a backup or start with a new one?"), dbfilename_library); - gboolean shall_we_delete_the_db = - dt_gui_show_standalone_yes_no_dialog(_("darktable - error opening database"), label_text, - _("close darktable"), _("delete database")); + gboolean shall_we_delete_the_db = dt_gui_show_standalone_yes_no_dialog( + _("darktable - error opening database"), label_text, _("close darktable"), _("delete database")); g_free(label_text); @@ -1754,7 +1751,8 @@ dt_database_t *dt_database_init(const char *alternative, const gboolean load_dat else { fprintf(stderr, "[init] database `%s' is corrupt and can't be opened! either replace it from a backup or " - "delete the file so that darktable can create a new one the next time. aborting\n", dbname); + "delete the file so that darktable can create a new one the next time. aborting\n", + dbname); goto error; } } @@ -1773,8 +1771,8 @@ dt_database_t *dt_database_init(const char *alternative, const gboolean load_dat // path ... { // we couldn't migrate the db for some reason. bail out. - fprintf(stderr, "[init] database `%s' couldn't be migrated from the legacy version %d. aborting\n", - dbname, db_version); + fprintf(stderr, "[init] database `%s' couldn't be migrated from the legacy version %d. aborting\n", dbname, + db_version); dt_database_destroy(db); db = NULL; goto error; @@ -1826,12 +1824,12 @@ dt_database_t *dt_database_init(const char *alternative, const gboolean load_dat void dt_database_destroy(const dt_database_t *db) { sqlite3_close(db->handle); - if (db->lockfile_data) + if(db->lockfile_data) { g_unlink(db->lockfile_data); g_free(db->lockfile_data); } - if (db->lockfile_library) + if(db->lockfile_library) { g_unlink(db->lockfile_library); g_free(db->lockfile_library); diff --git a/src/common/dbus.c b/src/common/dbus.c index a83292e51970..c5427e197ca5 100644 --- a/src/common/dbus.c +++ b/src/common/dbus.c @@ -47,9 +47,9 @@ static const gchar introspection_xml[] = "<node>" #ifdef USE_LUA -static void dbus_lua_call_finished(lua_State* L,int result,void* data) +static void dbus_lua_call_finished(lua_State *L, int result, void *data) { - GDBusMethodInvocation *invocation = (GDBusMethodInvocation*)data; + GDBusMethodInvocation *invocation = (GDBusMethodInvocation *)data; if(result == LUA_OK) { if(lua_isnil(L, -1)) @@ -66,7 +66,7 @@ static void dbus_lua_call_finished(lua_State* L,int result,void* data) { const char *msg = luaL_checkstring(L, -1); g_dbus_method_invocation_return_dbus_error(invocation, "org.darktable.Error.LuaError", msg); - dt_lua_check_print_error(L,result); + dt_lua_check_print_error(L, result); } } #endif @@ -92,7 +92,7 @@ static void _handle_method_call(GDBusConnection *connection, const gchar *sender { const gchar *command; g_variant_get(parameters, "(&s)", &command); - dt_lua_async_call_string(command, 1,dbus_lua_call_finished,invocation); + dt_lua_async_call_string(command, 1, dbus_lua_call_finished, invocation); // we don't finish the invocation, the async task will do this for us } #endif @@ -100,9 +100,9 @@ static void _handle_method_call(GDBusConnection *connection, const gchar *sender // TODO: expose the conf? partly? completely? -static GVariant *_handle_get_property(GDBusConnection *connection, const gchar *sender, - const gchar *object_path, const gchar *interface_name, - const gchar *property_name, GError **error, gpointer user_data) +static GVariant *_handle_get_property(GDBusConnection *connection, const gchar *sender, const gchar *object_path, + const gchar *interface_name, const gchar *property_name, GError **error, + gpointer user_data) { GVariant *ret; @@ -151,15 +151,13 @@ static void _on_bus_acquired(GDBusConnection *connection, const gchar *name, gpo { dt_dbus_t *dbus = (dt_dbus_t *)user_data; - dbus->registration_id - = g_dbus_connection_register_object(connection, "/darktable", dbus->introspection_data->interfaces[0], - &interface_vtable, dbus, /* user_data */ - NULL, /* user_data_free_func */ - NULL); /* GError** */ + dbus->registration_id = g_dbus_connection_register_object( + connection, "/darktable", dbus->introspection_data->interfaces[0], &interface_vtable, dbus, /* user_data */ + NULL, /* user_data_free_func */ + NULL); /* GError** */ if(dbus->registration_id == 0) - dbus->connected - = 0; // technically we are connected, but we are not exporting anything. or something like that + dbus->connected = 0; // technically we are connected, but we are not exporting anything. or something like that } static void _on_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) @@ -185,8 +183,8 @@ struct dt_dbus_t *dt_dbus_init() dbus->owner_id = g_bus_own_name(G_BUS_TYPE_SESSION, "org.darktable.service", // FIXME - G_BUS_NAME_OWNER_FLAGS_NONE, _on_bus_acquired, _on_name_acquired, - _on_name_lost, dbus, NULL); + G_BUS_NAME_OWNER_FLAGS_NONE, _on_bus_acquired, _on_name_acquired, _on_name_lost, + dbus, NULL); dbus->dbus_connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); g_object_set(G_OBJECT(dbus->dbus_connection), "exit-on-close", FALSE, (gchar *)0); diff --git a/src/common/debug.h b/src/common/debug.h index a48118a6ee4a..b5ea812282aa 100644 --- a/src/common/debug.h +++ b/src/common/debug.h @@ -27,11 +27,11 @@ // #define DEBUG_SQL_QUERIES #ifdef DEBUG_SQL_QUERIES - #define __STRINGIFY(TEXT) #TEXT - #define MESSAGE(VALUE) __STRINGIFY(message __STRINGIFY(SQLDEBUG: VALUE)) - #define __DT_DEBUG_SQL_QUERY__(value) _Pragma(MESSAGE(value)) +#define __STRINGIFY(TEXT) #TEXT +#define MESSAGE(VALUE) __STRINGIFY(message __STRINGIFY(SQLDEBUG : VALUE)) +#define __DT_DEBUG_SQL_QUERY__(value) _Pragma(MESSAGE(value)) #else - #define __DT_DEBUG_SQL_QUERY__(value) +#define __DT_DEBUG_SQL_QUERY__(value) #endif @@ -53,8 +53,8 @@ _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wshadow\"") const int x = xin; \ if(x != SQLITE_OK) \ { \ - fprintf(stderr, "sqlite3 error: %s:%d, function %s(), query \"%s\": %s\n", __FILE__, __LINE__, __FUNCTION__,\ - (query), sqlite3_errmsg(dt_database_get(darktable.db))); \ + fprintf(stderr, "sqlite3 error: %s:%d, function %s(), query \"%s\": %s\n", __FILE__, __LINE__, \ + __FUNCTION__, (query), sqlite3_errmsg(dt_database_get(darktable.db))); \ } \ assert(x == SQLITE_OK); \ _Pragma("GCC diagnostic pop") \ @@ -75,8 +75,8 @@ _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wshadow\"") const int x = xin; \ if(x != SQLITE_OK) \ { \ - fprintf(stderr, "sqlite3 error: %s:%d, function %s(), query \"%s\": %s\n", __FILE__, __LINE__, __FUNCTION__,\ - (query), sqlite3_errmsg(dt_database_get(darktable.db))); \ + fprintf(stderr, "sqlite3 error: %s:%d, function %s(), query \"%s\": %s\n", __FILE__, __LINE__, \ + __FUNCTION__, (query), sqlite3_errmsg(dt_database_get(darktable.db))); \ } \ _Pragma("GCC diagnostic pop") \ } @@ -91,12 +91,12 @@ __DT_DEBUG_SQL_QUERY__(b) \ } while(0) -#define DT_DEBUG_SQLITE3_PREPARE_V2(a, b, c, d, e) \ - do \ - { \ - dt_print(DT_DEBUG_SQL, "[sql] %s:%d, function %s(): prepare \"%s\"\n", __FILE__, __LINE__, __FUNCTION__, (b));\ - __DT_DEBUG_ASSERT_WITH_QUERY__(sqlite3_prepare_v2(a, b, c, d, e), (b)); \ - __DT_DEBUG_SQL_QUERY__(b) \ +#define DT_DEBUG_SQLITE3_PREPARE_V2(a, b, c, d, e) \ + do \ + { \ + dt_print(DT_DEBUG_SQL, "[sql] %s:%d, function %s(): prepare \"%s\"\n", __FILE__, __LINE__, __FUNCTION__, (b)); \ + __DT_DEBUG_ASSERT_WITH_QUERY__(sqlite3_prepare_v2(a, b, c, d, e), (b)); \ + __DT_DEBUG_SQL_QUERY__(b) \ } while(0) #define DT_DEBUG_SQLITE3_BIND_INT(a, b, c) __DT_DEBUG_ASSERT__(sqlite3_bind_int(a, b, c)) diff --git a/src/common/dlopencl.c b/src/common/dlopencl.c index 9ed06016c465..fab767922797 100644 --- a/src/common/dlopencl.c +++ b/src/common/dlopencl.c @@ -119,8 +119,8 @@ dt_dlopencl_t *dt_dlopencl_init(const char *name) (void (**)(void)) & ocl->symbols->dt_clGetPlatformIDs); success = success && dt_gmodule_symbol(module, "clGetPlatformInfo", (void (**)(void)) & ocl->symbols->dt_clGetPlatformInfo); - success = success && dt_gmodule_symbol(module, "clGetDeviceIDs", - (void (**)(void)) & ocl->symbols->dt_clGetDeviceIDs); + success = success + && dt_gmodule_symbol(module, "clGetDeviceIDs", (void (**)(void)) & ocl->symbols->dt_clGetDeviceIDs); success = success && dt_gmodule_symbol(module, "clGetDeviceInfo", (void (**)(void)) & ocl->symbols->dt_clGetDeviceInfo); success = success && dt_gmodule_symbol(module, "clCreateContext", @@ -129,20 +129,20 @@ dt_dlopencl_t *dt_dlopencl_init(const char *name) (void (**)(void)) & ocl->symbols->dt_clCreateCommandQueue); success = success && dt_gmodule_symbol(module, "clCreateProgramWithSource", (void (**)(void)) & ocl->symbols->dt_clCreateProgramWithSource); - success = success && dt_gmodule_symbol(module, "clBuildProgram", - (void (**)(void)) & ocl->symbols->dt_clBuildProgram); + success = success + && dt_gmodule_symbol(module, "clBuildProgram", (void (**)(void)) & ocl->symbols->dt_clBuildProgram); success = success && dt_gmodule_symbol(module, "clGetProgramBuildInfo", (void (**)(void)) & ocl->symbols->dt_clGetProgramBuildInfo); - success = success && dt_gmodule_symbol(module, "clCreateKernel", - (void (**)(void)) & ocl->symbols->dt_clCreateKernel); - success = success && dt_gmodule_symbol(module, "clCreateBuffer", - (void (**)(void)) & ocl->symbols->dt_clCreateBuffer); + success = success + && dt_gmodule_symbol(module, "clCreateKernel", (void (**)(void)) & ocl->symbols->dt_clCreateKernel); + success = success + && dt_gmodule_symbol(module, "clCreateBuffer", (void (**)(void)) & ocl->symbols->dt_clCreateBuffer); success = success && dt_gmodule_symbol(module, "clCreateImage2D", (void (**)(void)) & ocl->symbols->dt_clCreateImage2D); success = success && dt_gmodule_symbol(module, "clEnqueueWriteBuffer", (void (**)(void)) & ocl->symbols->dt_clEnqueueWriteBuffer); - success = success && dt_gmodule_symbol(module, "clSetKernelArg", - (void (**)(void)) & ocl->symbols->dt_clSetKernelArg); + success = success + && dt_gmodule_symbol(module, "clSetKernelArg", (void (**)(void)) & ocl->symbols->dt_clSetKernelArg); success = success && dt_gmodule_symbol(module, "clGetKernelWorkGroupInfo", (void (**)(void)) & ocl->symbols->dt_clGetKernelWorkGroupInfo); success = success && dt_gmodule_symbol(module, "clEnqueueNDRangeKernel", @@ -170,12 +170,12 @@ dt_dlopencl_t *dt_dlopencl_init(const char *name) (void (**)(void)) & ocl->symbols->dt_clReleaseCommandQueue); success = success && dt_gmodule_symbol(module, "clReleaseContext", (void (**)(void)) & ocl->symbols->dt_clReleaseContext); - success = success && dt_gmodule_symbol(module, "clReleaseEvent", - (void (**)(void)) & ocl->symbols->dt_clReleaseEvent); + success = success + && dt_gmodule_symbol(module, "clReleaseEvent", (void (**)(void)) & ocl->symbols->dt_clReleaseEvent); success = success && dt_gmodule_symbol(module, "clWaitForEvents", (void (**)(void)) & ocl->symbols->dt_clWaitForEvents); - success = success && dt_gmodule_symbol(module, "clGetEventInfo", - (void (**)(void)) & ocl->symbols->dt_clGetEventInfo); + success = success + && dt_gmodule_symbol(module, "clGetEventInfo", (void (**)(void)) & ocl->symbols->dt_clGetEventInfo); success = success && dt_gmodule_symbol(module, "clGetEventProfilingInfo", (void (**)(void)) & ocl->symbols->dt_clGetEventProfilingInfo); success = success && dt_gmodule_symbol(module, "clGetKernelInfo", @@ -204,8 +204,7 @@ dt_dlopencl_t *dt_dlopencl_init(const char *name) ocl->have_opencl = success; - if(!success) - dt_print(DT_DEBUG_OPENCL, "[opencl_init] could not load all required symbols from library\n"); + if(!success) dt_print(DT_DEBUG_OPENCL, "[opencl_init] could not load all required symbols from library\n"); } free(module); diff --git a/src/common/dlopencl.h b/src/common/dlopencl.h index 9a55dfbccd13..ecf2f759fd88 100644 --- a/src/common/dlopencl.h +++ b/src/common/dlopencl.h @@ -31,11 +31,10 @@ typedef cl_int (*dt_clGetPlatformInfo_t)(cl_platform_id, cl_platform_info, size_ typedef cl_int (*dt_clGetDeviceIDs_t)(cl_platform_id, cl_device_type, cl_uint, cl_device_id *, cl_uint *); typedef cl_int (*dt_clGetDeviceInfo_t)(cl_device_id, cl_device_info, size_t, void *, size_t *); typedef cl_context (*dt_clCreateContext_t)(const cl_context_properties *, cl_uint, const cl_device_id *, - void (*)(const char *, const void *, size_t, void *), void *, - cl_int *); + void (*)(const char *, const void *, size_t, void *), void *, cl_int *); typedef cl_context (*dt_clCreateContextFromType_t)(const cl_context_properties *, cl_device_type, - void (*)(const char *, const void *, size_t, void *), - void *, cl_int *); + void (*)(const char *, const void *, size_t, void *), void *, + cl_int *); typedef cl_int (*dt_clRetainContext_t)(cl_context); typedef cl_int (*dt_clReleaseContext_t)(cl_context); typedef cl_int (*dt_clGetContextInfo_t)(cl_context, cl_context_info, size_t, void *, size_t *); @@ -43,16 +42,15 @@ typedef cl_command_queue (*dt_clCreateCommandQueue_t)(cl_context, cl_device_id, cl_int *); typedef cl_int (*dt_clRetainCommandQueue_t)(cl_command_queue); typedef cl_int (*dt_clReleaseCommandQueue_t)(cl_command_queue); -typedef cl_int (*dt_clGetCommandQueueInfo_t)(cl_command_queue, cl_command_queue_info, size_t, void *, - size_t *); +typedef cl_int (*dt_clGetCommandQueueInfo_t)(cl_command_queue, cl_command_queue_info, size_t, void *, size_t *); typedef cl_int (*dt_clSetCommandQueueProperty_t)(cl_command_queue, cl_command_queue_properties, cl_bool, cl_command_queue_properties *); typedef cl_mem (*dt_clCreateBuffer_t)(cl_context, cl_mem_flags, size_t, void *, cl_int *); typedef cl_mem (*dt_clCreateSubBuffer_t)(cl_mem, cl_mem_flags, cl_buffer_create_type, const void *, cl_int *); -typedef cl_mem (*dt_clCreateImage2D_t)(cl_context, cl_mem_flags, const cl_image_format *, size_t, size_t, - size_t, void *, cl_int *); -typedef cl_mem (*dt_clCreateImage3D_t)(cl_context, cl_mem_flags, const cl_image_format *, size_t, size_t, - size_t, size_t, size_t, void *, cl_int *); +typedef cl_mem (*dt_clCreateImage2D_t)(cl_context, cl_mem_flags, const cl_image_format *, size_t, size_t, size_t, + void *, cl_int *); +typedef cl_mem (*dt_clCreateImage3D_t)(cl_context, cl_mem_flags, const cl_image_format *, size_t, size_t, size_t, + size_t, size_t, void *, cl_int *); typedef cl_int (*dt_clRetainMemObject_t)(cl_mem); typedef cl_int (*dt_clReleaseMemObject_t)(cl_mem); typedef cl_int (*dt_clGetSupportedImageFormats_t)(cl_context, cl_mem_flags, cl_mem_object_type, cl_uint, @@ -64,15 +62,12 @@ typedef cl_sampler (*dt_clCreateSampler_t)(cl_context, cl_bool, cl_addressing_mo typedef cl_int (*dt_clRetainSampler_t)(cl_sampler); typedef cl_int (*dt_clReleaseSampler_t)(cl_sampler); typedef cl_int (*dt_clGetSamplerInfo_t)(cl_sampler, cl_sampler_info, size_t, void *, size_t *); -typedef cl_program (*dt_clCreateProgramWithSource_t)(cl_context, cl_uint, const char **, const size_t *, - cl_int *); -typedef cl_program (*dt_clCreateProgramWithBinary_t)(cl_context, cl_uint, const cl_device_id *, - const size_t *, const unsigned char **, cl_int *, - cl_int *); +typedef cl_program (*dt_clCreateProgramWithSource_t)(cl_context, cl_uint, const char **, const size_t *, cl_int *); +typedef cl_program (*dt_clCreateProgramWithBinary_t)(cl_context, cl_uint, const cl_device_id *, const size_t *, + const unsigned char **, cl_int *, cl_int *); typedef cl_int (*dt_clRetainProgram_t)(cl_program); typedef cl_int (*dt_clReleaseProgram_t)(cl_program); -typedef cl_int (*dt_clBuildProgram_t)(cl_program, cl_uint, const cl_device_id *, const char *, void(*), - void *); +typedef cl_int (*dt_clBuildProgram_t)(cl_program, cl_uint, const cl_device_id *, const char *, void(*), void *); typedef cl_int (*dt_clUnloadCompiler_t)(void); typedef cl_int (*dt_clGetProgramInfo_t)(cl_program, cl_program_info, size_t, void *, size_t *); typedef cl_int (*dt_clGetProgramBuildInfo_t)(cl_program, cl_device_id, cl_program_build_info, size_t, void *, @@ -83,8 +78,8 @@ typedef cl_int (*dt_clRetainKernel_t)(cl_kernel); typedef cl_int (*dt_clReleaseKernel_t)(cl_kernel); typedef cl_int (*dt_clSetKernelArg_t)(cl_kernel, cl_uint, size_t, const void *); typedef cl_int (*dt_clGetKernelInfo_t)(cl_kernel, cl_kernel_info, size_t, void *, size_t *); -typedef cl_int (*dt_clGetKernelWorkGroupInfo_t)(cl_kernel, cl_device_id, cl_kernel_work_group_info, size_t, - void *, size_t *); +typedef cl_int (*dt_clGetKernelWorkGroupInfo_t)(cl_kernel, cl_device_id, cl_kernel_work_group_info, size_t, void *, + size_t *); typedef cl_int (*dt_clWaitForEvents_t)(cl_uint, const cl_event *); typedef cl_int (*dt_clGetEventInfo_t)(cl_event, cl_event_info, size_t, void *, size_t *); typedef cl_event (*dt_clCreateUserEvent_t)(cl_context, cl_int *); @@ -97,45 +92,41 @@ typedef cl_int (*dt_clFlush_t)(cl_command_queue); typedef cl_int (*dt_clFinish_t)(cl_command_queue); typedef cl_int (*dt_clEnqueueReadBuffer_t)(cl_command_queue, cl_mem, cl_bool, size_t, size_t, void *, cl_uint, const cl_event *, cl_event *); -typedef cl_int (*dt_clEnqueueReadBufferRect_t)(cl_command_queue, cl_mem, cl_bool, const size_t *, - const size_t *, const size_t *, size_t, size_t, size_t, size_t, - void *, cl_uint, const cl_event *, cl_event *); +typedef cl_int (*dt_clEnqueueReadBufferRect_t)(cl_command_queue, cl_mem, cl_bool, const size_t *, const size_t *, + const size_t *, size_t, size_t, size_t, size_t, void *, cl_uint, + const cl_event *, cl_event *); typedef cl_int (*dt_clEnqueueWriteBuffer_t)(cl_command_queue, cl_mem, cl_bool, size_t, size_t, const void *, cl_uint, const cl_event *, cl_event *); -typedef cl_int (*dt_clEnqueueWriteBufferRect_t)(cl_command_queue, cl_mem, cl_bool, const size_t *, - const size_t *, const size_t *, size_t, size_t, size_t, - size_t, const void *, cl_uint, const cl_event *, cl_event *); +typedef cl_int (*dt_clEnqueueWriteBufferRect_t)(cl_command_queue, cl_mem, cl_bool, const size_t *, const size_t *, + const size_t *, size_t, size_t, size_t, size_t, const void *, + cl_uint, const cl_event *, cl_event *); typedef cl_int (*dt_clEnqueueCopyBuffer_t)(cl_command_queue, cl_mem, cl_mem, size_t, size_t, size_t, cl_uint, const cl_event *, cl_event *); -typedef cl_int (*dt_clEnqueueCopyBufferRect_t)(cl_command_queue, cl_mem, cl_mem, const size_t *, - const size_t *, const size_t *, size_t, size_t, size_t, size_t, - cl_uint, const cl_event *, cl_event *); +typedef cl_int (*dt_clEnqueueCopyBufferRect_t)(cl_command_queue, cl_mem, cl_mem, const size_t *, const size_t *, + const size_t *, size_t, size_t, size_t, size_t, cl_uint, + const cl_event *, cl_event *); typedef cl_int (*dt_clEnqueueReadImage_t)(cl_command_queue, cl_mem, cl_bool, const size_t *, const size_t *, size_t, size_t, void *, cl_uint, const cl_event *, cl_event *); typedef cl_int (*dt_clEnqueueWriteImage_t)(cl_command_queue, cl_mem, cl_bool, const size_t *, const size_t *, - size_t, size_t, const void *, cl_uint, const cl_event *, - cl_event *); + size_t, size_t, const void *, cl_uint, const cl_event *, cl_event *); typedef cl_int (*dt_clEnqueueCopyImage_t)(cl_command_queue, cl_mem, cl_mem, const size_t *, const size_t *, const size_t *, cl_uint, const cl_event *, cl_event *); -typedef cl_int (*dt_clEnqueueCopyImageToBuffer_t)(cl_command_queue, cl_mem, cl_mem, const size_t *, - const size_t *, size_t, cl_uint, const cl_event *, - cl_event *); +typedef cl_int (*dt_clEnqueueCopyImageToBuffer_t)(cl_command_queue, cl_mem, cl_mem, const size_t *, const size_t *, + size_t, cl_uint, const cl_event *, cl_event *); typedef cl_int (*dt_clEnqueueCopyBufferToImage_t)(cl_command_queue, cl_mem, cl_mem, size_t, const size_t *, const size_t *, cl_uint, const cl_event *, cl_event *); -typedef void *(*dt_clEnqueueMapBuffer_t)(cl_command_queue, cl_mem, cl_bool, cl_map_flags, size_t, size_t, - cl_uint, const cl_event *, cl_event *, cl_int *); +typedef void *(*dt_clEnqueueMapBuffer_t)(cl_command_queue, cl_mem, cl_bool, cl_map_flags, size_t, size_t, cl_uint, + const cl_event *, cl_event *, cl_int *); typedef void *(*dt_clEnqueueMapImage_t)(cl_command_queue, cl_mem, cl_bool, cl_map_flags, const size_t *, - const size_t *, size_t *, size_t *, cl_uint, const cl_event *, - cl_event *, cl_int *); + const size_t *, size_t *, size_t *, cl_uint, const cl_event *, cl_event *, + cl_int *); typedef cl_int (*dt_clEnqueueUnmapMemObject_t)(cl_command_queue, cl_mem, void *, cl_uint, const cl_event *, cl_event *); -typedef cl_int (*dt_clEnqueueNDRangeKernel_t)(cl_command_queue, cl_kernel, cl_uint, const size_t *, - const size_t *, const size_t *, cl_uint, const cl_event *, - cl_event *); +typedef cl_int (*dt_clEnqueueNDRangeKernel_t)(cl_command_queue, cl_kernel, cl_uint, const size_t *, const size_t *, + const size_t *, cl_uint, const cl_event *, cl_event *); typedef cl_int (*dt_clEnqueueTask_t)(cl_command_queue, cl_kernel, cl_uint, const cl_event *, cl_event *); -typedef cl_int (*dt_clEnqueueNativeKernel_t)(cl_command_queue, void (*user_func)(void *), void *, size_t, - cl_uint, const cl_mem *, const void **, cl_uint, - const cl_event *, cl_event *); +typedef cl_int (*dt_clEnqueueNativeKernel_t)(cl_command_queue, void (*user_func)(void *), void *, size_t, cl_uint, + const cl_mem *, const void **, cl_uint, const cl_event *, cl_event *); typedef cl_int (*dt_clEnqueueMarker_t)(cl_command_queue, cl_event *); typedef cl_int (*dt_clEnqueueWaitForEvents_t)(cl_command_queue, cl_uint, const cl_event *); typedef cl_int (*dt_clEnqueueBarrier_t)(cl_command_queue); diff --git a/src/common/dtpthread.c b/src/common/dtpthread.c index d3090c1c7cf8..8452fc4bb725 100644 --- a/src/common/dtpthread.c +++ b/src/common/dtpthread.c @@ -78,13 +78,13 @@ void dt_pthread_setname(const char *name) #if defined __linux__ pthread_setname_np(pthread_self(), name); #elif defined __FreeBSD__ || defined __DragonFly__ - // TODO: is this the right syntax? - // pthread_setname_np(pthread_self(), name, 0); +// TODO: is this the right syntax? +// pthread_setname_np(pthread_self(), name, 0); #elif defined __NetBSD__ - // TODO: is this the right syntax? - // pthread_setname_np(pthread_self(), name, NULL); +// TODO: is this the right syntax? +// pthread_setname_np(pthread_self(), name, NULL); #elif defined __OpenBSD__ - // TODO: find out if there is pthread_setname_np() on OpenBSD and how to call it +// TODO: find out if there is pthread_setname_np() on OpenBSD and how to call it #elif defined __APPLE__ pthread_setname_np(name); #elif defined _WIN32 diff --git a/src/common/dtpthread.h b/src/common/dtpthread.h index 9a11fa486df7..ee2fc763cc31 100644 --- a/src/common/dtpthread.h +++ b/src/common/dtpthread.h @@ -84,9 +84,8 @@ static inline int dt_pthread_mutex_destroy(dt_pthread_mutex_t *mutex) } #define dt_pthread_mutex_init(A, B) dt_pthread_mutex_init_with_caller(A, B, __FILE__, __LINE__, __FUNCTION__) -static inline int dt_pthread_mutex_init_with_caller(dt_pthread_mutex_t *mutex, - const pthread_mutexattr_t *attr, const char *file, - const int line, const char *function) +static inline int dt_pthread_mutex_init_with_caller(dt_pthread_mutex_t *mutex, const pthread_mutexattr_t *attr, + const char *file, const int line, const char *function) { memset(mutex, 0x0, sizeof(dt_pthread_mutex_t)); snprintf(mutex->name, sizeof(mutex->name), "%s:%d (%s)", file, line, function); @@ -107,8 +106,8 @@ static inline int dt_pthread_mutex_init_with_caller(dt_pthread_mutex_t *mutex, } #define dt_pthread_mutex_lock(A) dt_pthread_mutex_lock_with_caller(A, __FILE__, __LINE__, __FUNCTION__) -static inline int dt_pthread_mutex_lock_with_caller(dt_pthread_mutex_t *mutex, const char *file, - const int line, const char *function) +static inline int dt_pthread_mutex_lock_with_caller(dt_pthread_mutex_t *mutex, const char *file, const int line, + const char *function) { const double t0 = dt_pthread_get_wtime(); const int ret = pthread_mutex_lock(&(mutex->mutex)); @@ -134,8 +133,8 @@ static inline int dt_pthread_mutex_lock_with_caller(dt_pthread_mutex_t *mutex, c } #define dt_pthread_mutex_trylock(A) dt_pthread_mutex_trylock_with_caller(A, __FILE__, __LINE__, __FUNCTION__) -static inline int dt_pthread_mutex_trylock_with_caller(dt_pthread_mutex_t *mutex, const char *file, - const int line, const char *function) +static inline int dt_pthread_mutex_trylock_with_caller(dt_pthread_mutex_t *mutex, const char *file, const int line, + const char *function) { const double t0 = dt_pthread_get_wtime(); const int ret = pthread_mutex_trylock(&(mutex->mutex)); @@ -162,8 +161,8 @@ static inline int dt_pthread_mutex_trylock_with_caller(dt_pthread_mutex_t *mutex } #define dt_pthread_mutex_unlock(A) dt_pthread_mutex_unlock_with_caller(A, __FILE__, __LINE__, __FUNCTION__) -static inline int dt_pthread_mutex_unlock_with_caller(dt_pthread_mutex_t *mutex, const char *file, - const int line, const char *function) +static inline int dt_pthread_mutex_unlock_with_caller(dt_pthread_mutex_t *mutex, const char *file, const int line, + const char *function) { const double t0 = dt_pthread_get_wtime(); const double locked = t0 - mutex->time_locked; @@ -200,8 +199,7 @@ static inline int dt_pthread_cond_wait(pthread_cond_t *cond, dt_pthread_mutex_t } -static inline int dt_pthread_rwlock_init(dt_pthread_rwlock_t *lock, - const pthread_rwlockattr_t *attr) +static inline int dt_pthread_rwlock_init(dt_pthread_rwlock_t *lock, const pthread_rwlockattr_t *attr) { memset(lock, 0, sizeof(dt_pthread_rwlock_t)); lock->cnt = 0; @@ -244,8 +242,7 @@ static inline int dt_pthread_rwlock_rdlock_with_caller(dt_pthread_rwlock_t *rwlo assert(!res); assert(!(res && pthread_equal(rwlock->writer, pthread_self()))); __sync_fetch_and_add(&(rwlock->cnt), 1); - if(!res) - snprintf(rwlock->name, sizeof(rwlock->name), "r:%s:%d", file, line); + if(!res) snprintf(rwlock->name, sizeof(rwlock->name), "r:%s:%d", file, line); return res; } #define dt_pthread_rwlock_wrlock(A) dt_pthread_rwlock_wrlock_with_caller(A, __FILE__, __LINE__) @@ -336,10 +333,10 @@ static inline int dt_pthread_cond_wait(pthread_cond_t *cond, dt_pthread_mutex_t #define dt_pthread_rwlock_tryrdlock pthread_rwlock_tryrdlock #define dt_pthread_rwlock_trywrlock pthread_rwlock_trywrlock -#define dt_pthread_rwlock_rdlock_with_caller(A,B,C) pthread_rwlock_rdlock(A) -#define dt_pthread_rwlock_wrlock_with_caller(A,B,C) pthread_rwlock_wrlock(A) -#define dt_pthread_rwlock_tryrdlock_with_caller(A,B,C) pthread_rwlock_tryrdlock(A) -#define dt_pthread_rwlock_trywrlock_with_caller(A,B,C) pthread_rwlock_trywrlock(A) +#define dt_pthread_rwlock_rdlock_with_caller(A, B, C) pthread_rwlock_rdlock(A) +#define dt_pthread_rwlock_wrlock_with_caller(A, B, C) pthread_rwlock_wrlock(A) +#define dt_pthread_rwlock_tryrdlock_with_caller(A, B, C) pthread_rwlock_tryrdlock(A) +#define dt_pthread_rwlock_trywrlock_with_caller(A, B, C) pthread_rwlock_trywrlock(A) #endif diff --git a/src/common/exif.cc b/src/common/exif.cc index 3d6cce3f322f..2243496a946d 100644 --- a/src/common/exif.cc +++ b/src/common/exif.cc @@ -44,9 +44,9 @@ extern "C" { #include <exiv2/exiv2.hpp> #if defined(_WIN32) && defined(EXV_UNICODE_PATH) - #define WIDEN(s) pugi::as_wide(s) +#define WIDEN(s) pugi::as_wide(s) #else - #define WIDEN(s) (s) +#define WIDEN(s) (s) #endif #include <pugixml.hpp> @@ -196,8 +196,7 @@ static void dt_remove_known_keys(Exiv2::XmpData &xmp) const char *ckey = key.c_str(); size_t len = key.size(); // stop iterating once the key no longer matches what we are trying to delete. this assumes sorted input - if(!(g_str_has_prefix(ckey, dt_xmp_keys[i]) && (ckey[len] == '[' || ckey[len] == '\0'))) - break; + if(!(g_str_has_prefix(ckey, dt_xmp_keys[i]) && (ckey[len] == '[' || ckey[len] == '\0'))) break; pos = xmp.erase(pos); } } @@ -210,8 +209,7 @@ static void dt_remove_exif_keys(Exiv2::ExifData &exif, const char *keys[], unsig try { Exiv2::ExifData::iterator pos; - while((pos = exif.findKey(Exiv2::ExifKey(keys[i]))) != exif.end()) - exif.erase(pos); + while((pos = exif.findKey(Exiv2::ExifKey(keys[i]))) != exif.end()) exif.erase(pos); } catch(Exiv2::AnyError &e) { @@ -242,8 +240,7 @@ static bool dt_exif_read_xmp_tag(Exiv2::XmpData &xmpData, Exiv2::XmpData::iterat // FIXME: according to http://www.exiv2.org/doc/classExiv2_1_1Metadatum.html#63c2b87249ba96679c29e01218169124 // there is no need to pass xmpData // version = -1 -> version ignored -static bool dt_exif_read_xmp_data(dt_image_t *img, Exiv2::XmpData &xmpData, int version, - bool use_default_rating) +static bool dt_exif_read_xmp_data(dt_image_t *img, Exiv2::XmpData &xmpData, int version, bool use_default_rating) { try { @@ -391,7 +388,7 @@ static bool dt_exif_read_xmp_data(dt_image_t *img, Exiv2::XmpData &xmpData, int { // lens model char *lens = strdup(pos->toString().c_str()); - char *adr = lens; + char *adr = lens; if(strncmp(lens, "lang=", 5) == 0) { lens = strchr(lens, ' '); @@ -603,7 +600,7 @@ static bool dt_exif_read_exif_data(dt_image_t *img, Exiv2::ExifData &exifData) img->exif_iso = (float)std::atof(str.c_str()); } else if((!g_strcmp0(img->exif_maker, "SONY") || !g_strcmp0(img->exif_maker, "Canon")) - && FIND_EXIF_TAG("Exif.Photo.RecommendedExposureIndex")) + && FIND_EXIF_TAG("Exif.Photo.RecommendedExposureIndex")) { img->exif_iso = pos->toFloat(); } @@ -614,7 +611,7 @@ static bool dt_exif_read_exif_data(dt_image_t *img, Exiv2::ExifData &exifData) { // This works around a bug in exiv2 the developers refuse to fix // For details see http://dev.exiv2.org/issues/1083 - if (pos->key() == "Exif.Canon.FocalLength" && pos->count() == 4) + if(pos->key() == "Exif.Canon.FocalLength" && pos->count() == 4) img->exif_focal_length = pos->toFloat(1); else img->exif_focal_length = pos->toFloat(); @@ -661,7 +658,7 @@ static bool dt_exif_read_exif_data(dt_image_t *img, Exiv2::ExifData &exifData) int nominator = pos->toRational(0).first; img->exif_focus_distance = fmax(0.0, (0.001 * nominator)); } - else if(Exiv2::testVersion(0,25,0) && FIND_EXIF_TAG("Exif.CanonFi.FocusDistanceUpper")) + else if(Exiv2::testVersion(0, 25, 0) && FIND_EXIF_TAG("Exif.CanonFi.FocusDistanceUpper")) { float FocusDistanceUpper = pos->toFloat(); if(FocusDistanceUpper <= 0.0f || FocusDistanceUpper >= 0xffff) @@ -697,9 +694,9 @@ static bool dt_exif_read_exif_data(dt_image_t *img, Exiv2::ExifData &exifData) std::string sign_str = ref->toString(); const char *sign = sign_str.c_str(); double latitude = 0.0; - if(_gps_rationale_to_number(pos->toRational(0).first, pos->toRational(0).second, - pos->toRational(1).first, pos->toRational(1).second, - pos->toRational(2).first, pos->toRational(2).second, sign[0], &latitude)) + if(_gps_rationale_to_number(pos->toRational(0).first, pos->toRational(0).second, pos->toRational(1).first, + pos->toRational(1).second, pos->toRational(2).first, pos->toRational(2).second, + sign[0], &latitude)) img->latitude = latitude; } } @@ -712,9 +709,9 @@ static bool dt_exif_read_exif_data(dt_image_t *img, Exiv2::ExifData &exifData) std::string sign_str = ref->toString(); const char *sign = sign_str.c_str(); double longitude = 0.0; - if(_gps_rationale_to_number(pos->toRational(0).first, pos->toRational(0).second, - pos->toRational(1).first, pos->toRational(1).second, - pos->toRational(2).first, pos->toRational(2).second, sign[0], &longitude)) + if(_gps_rationale_to_number(pos->toRational(0).first, pos->toRational(0).second, pos->toRational(1).first, + pos->toRational(1).second, pos->toRational(2).first, pos->toRational(2).second, + sign[0], &longitude)) img->longitude = longitude; } } @@ -734,12 +731,11 @@ static bool dt_exif_read_exif_data(dt_image_t *img, Exiv2::ExifData &exifData) /* Read lens name */ if((FIND_EXIF_TAG("Exif.CanonCs.LensType") && pos->print(&exifData) != "(0)" - && pos->print(&exifData) != "(65535)") - || FIND_EXIF_TAG("Exif.Canon.0x0095")) + && pos->print(&exifData) != "(65535)") || FIND_EXIF_TAG("Exif.Canon.0x0095")) { dt_strlcpy_to_utf8(img->exif_lens, sizeof(img->exif_lens), pos, exifData); } - else if(Exiv2::testVersion(0,25,0) && FIND_EXIF_TAG("Exif.PentaxDng.LensType")) + else if(Exiv2::testVersion(0, 25, 0) && FIND_EXIF_TAG("Exif.PentaxDng.LensType")) { dt_strlcpy_to_utf8(img->exif_lens, sizeof(img->exif_lens), pos, exifData); } @@ -1009,17 +1005,19 @@ int dt_exif_get_thumbnail(const char *path, uint8_t **buffer, size_t *size, char // Get the selected preview image Exiv2::PreviewImage preview = loader.getPreviewImage(selected); - const unsigned char *tmp = preview.pData(); + const unsigned char *tmp = preview.pData(); size_t _size = preview.size(); *size = _size; *mime_type = strdup(preview.mimeType().c_str()); *buffer = (uint8_t *)malloc(_size); - if(!*buffer) { + if(!*buffer) + { std::cerr << "[exiv2] couldn't allocate memory for thumbnail for " << path << std::endl; return 1; } - //std::cerr << "[exiv2] "<< path << ": found thumbnail "<< preview.width() << "x" << preview.height() << std::endl; + // std::cerr << "[exiv2] "<< path << ": found thumbnail "<< preview.width() << "x" << preview.height() << + // std::endl; memcpy(*buffer, tmp, _size); return 0; @@ -1111,14 +1109,10 @@ int dt_exif_write_blob(uint8_t *blob, uint32_t size, const char *path, const int { // Remove thumbnail - static const char *keys[] = { - "Exif.Thumbnail.Compression", - "Exif.Thumbnail.XResolution", - "Exif.Thumbnail.YResolution", - "Exif.Thumbnail.ResolutionUnit", - "Exif.Thumbnail.JPEGInterchangeFormat", - "Exif.Thumbnail.JPEGInterchangeFormatLength" - }; + static const char *keys[] + = { "Exif.Thumbnail.Compression", "Exif.Thumbnail.XResolution", + "Exif.Thumbnail.YResolution", "Exif.Thumbnail.ResolutionUnit", + "Exif.Thumbnail.JPEGInterchangeFormat", "Exif.Thumbnail.JPEGInterchangeFormatLength" }; static const guint n_keys = G_N_ELEMENTS(keys); dt_remove_exif_keys(imgExifData, keys, n_keys); } @@ -1126,10 +1120,7 @@ int dt_exif_write_blob(uint8_t *blob, uint32_t size, const char *path, const int // only compressed images may set PixelXDimension and PixelYDimension if(!compressed) { - static const char *keys[] = { - "Exif.Photo.PixelXDimension", - "Exif.Photo.PixelYDimension" - }; + static const char *keys[] = { "Exif.Photo.PixelXDimension", "Exif.Photo.PixelYDimension" }; static const guint n_keys = G_N_ELEMENTS(keys); dt_remove_exif_keys(imgExifData, keys, n_keys); } @@ -1163,22 +1154,13 @@ int dt_exif_read_blob(uint8_t **buf, const char *path, const int imgid, const in // ufraw-style exif stripping: Exiv2::ExifData::iterator pos; { - /* Delete original TIFF data, which is irrelevant*/ - static const char *keys[] = { - "Exif.Image.ImageWidth", - "Exif.Image.ImageLength", - "Exif.Image.BitsPerSample", - "Exif.Image.Compression", - "Exif.Image.PhotometricInterpretation", - "Exif.Image.FillOrder", - "Exif.Image.SamplesPerPixel", - "Exif.Image.StripOffsets", - "Exif.Image.RowsPerStrip", - "Exif.Image.StripByteCounts", - "Exif.Image.PlanarConfiguration", - "Exif.Image.DNGVersion", - "Exif.Image.DNGBackwardVersion" - }; + /* Delete original TIFF data, which is irrelevant*/ + static const char *keys[] + = { "Exif.Image.ImageWidth", "Exif.Image.ImageLength", "Exif.Image.BitsPerSample", + "Exif.Image.Compression", "Exif.Image.PhotometricInterpretation", "Exif.Image.FillOrder", + "Exif.Image.SamplesPerPixel", "Exif.Image.StripOffsets", "Exif.Image.RowsPerStrip", + "Exif.Image.StripByteCounts", "Exif.Image.PlanarConfiguration", "Exif.Image.DNGVersion", + "Exif.Image.DNGBackwardVersion" }; static const guint n_keys = G_N_ELEMENTS(keys); dt_remove_exif_keys(exifData, keys, n_keys); } @@ -1190,66 +1172,42 @@ int dt_exif_read_blob(uint8_t **buf, const char *path, const int imgid, const in exifData["Exif.Image.Orientation"] = uint16_t(1); { - static const char *keys[] = { - // Embedded color profile info - "Exif.Image.BaselineExposureOffset", - "Exif.Image.CalibrationIlluminant1", - "Exif.Image.CalibrationIlluminant2", - "Exif.Image.ColorMatrix1", - "Exif.Image.ColorMatrix2", - "Exif.Image.DefaultBlackRender", - "Exif.Image.ForwardMatrix1", - "Exif.Image.ForwardMatrix2", - "Exif.Image.ProfileCalibrationSignature", - "Exif.Image.ProfileCopyright", - "Exif.Image.ProfileEmbedPolicy", - "Exif.Image.ProfileHueSatMapData1", - "Exif.Image.ProfileHueSatMapData2", - "Exif.Image.ProfileHueSatMapDims", - "Exif.Image.ProfileHueSatMapEncoding", - "Exif.Image.ProfileLookTableData", - "Exif.Image.ProfileLookTableDims", - "Exif.Image.ProfileLookTableEncoding", - "Exif.Image.ProfileName", - "Exif.Image.ProfileToneCurve", - "Exif.Image.ReductionMatrix1", - "Exif.Image.ReductionMatrix2", - - // Canon color space info - "Exif.Canon.ColorSpace", - "Exif.Canon.ColorData", - - // Nikon thumbnail data - "Exif.Nikon3.Preview", - "Exif.NikonPreview.JPEGInterchangeFormat", - - // DNG private data - "Exif.Image.DNGPrivateData", - - // Pentax thumbnail data - "Exif.Pentax.PreviewResolution", - "Exif.Pentax.PreviewLength", - "Exif.Pentax.PreviewOffset", - "Exif.PentaxDng.PreviewResolution", - "Exif.PentaxDng.PreviewLength", - "Exif.PentaxDng.PreviewOffset", - // Pentax color info - "Exif.PentaxDng.ColorInfo", - - // Minolta thumbnail data - "Exif.Minolta.Thumbnail", - "Exif.Minolta.ThumbnailOffset", - "Exif.Minolta.ThumbnailLength", - - // Sony thumbnail data - "Exif.SonyMinolta.ThumbnailOffset", - "Exif.SonyMinolta.ThumbnailLength", - - // Olympus thumbnail data - "Exif.Olympus.Thumbnail", - "Exif.Olympus.ThumbnailOffset", - "Exif.Olympus.ThumbnailLength" - }; + static const char *keys[] + = { // Embedded color profile info + "Exif.Image.BaselineExposureOffset", "Exif.Image.CalibrationIlluminant1", + "Exif.Image.CalibrationIlluminant2", "Exif.Image.ColorMatrix1", "Exif.Image.ColorMatrix2", + "Exif.Image.DefaultBlackRender", "Exif.Image.ForwardMatrix1", "Exif.Image.ForwardMatrix2", + "Exif.Image.ProfileCalibrationSignature", "Exif.Image.ProfileCopyright", + "Exif.Image.ProfileEmbedPolicy", "Exif.Image.ProfileHueSatMapData1", + "Exif.Image.ProfileHueSatMapData2", "Exif.Image.ProfileHueSatMapDims", + "Exif.Image.ProfileHueSatMapEncoding", "Exif.Image.ProfileLookTableData", + "Exif.Image.ProfileLookTableDims", "Exif.Image.ProfileLookTableEncoding", "Exif.Image.ProfileName", + "Exif.Image.ProfileToneCurve", "Exif.Image.ReductionMatrix1", "Exif.Image.ReductionMatrix2", + + // Canon color space info + "Exif.Canon.ColorSpace", "Exif.Canon.ColorData", + + // Nikon thumbnail data + "Exif.Nikon3.Preview", "Exif.NikonPreview.JPEGInterchangeFormat", + + // DNG private data + "Exif.Image.DNGPrivateData", + + // Pentax thumbnail data + "Exif.Pentax.PreviewResolution", "Exif.Pentax.PreviewLength", "Exif.Pentax.PreviewOffset", + "Exif.PentaxDng.PreviewResolution", "Exif.PentaxDng.PreviewLength", "Exif.PentaxDng.PreviewOffset", + // Pentax color info + "Exif.PentaxDng.ColorInfo", + + // Minolta thumbnail data + "Exif.Minolta.Thumbnail", "Exif.Minolta.ThumbnailOffset", "Exif.Minolta.ThumbnailLength", + + // Sony thumbnail data + "Exif.SonyMinolta.ThumbnailOffset", "Exif.SonyMinolta.ThumbnailLength", + + // Olympus thumbnail data + "Exif.Olympus.Thumbnail", "Exif.Olympus.ThumbnailOffset", "Exif.Olympus.ThumbnailLength" + }; static const guint n_keys = G_N_ELEMENTS(keys); dt_remove_exif_keys(exifData, keys, n_keys); } @@ -1268,23 +1226,13 @@ int dt_exif_read_blob(uint8_t **buf, const char *path, const int imgid, const in { // Exiv2 versions older than 0.23 drop all EXIF if the code below is executed // Samsung makernote cleanup, the entries below have no relevance for exported images - static const char *keys[] = { - "Exif.Samsung2.SensorAreas", - "Exif.Samsung2.ColorSpace", - "Exif.Samsung2.EncryptionKey", - "Exif.Samsung2.WB_RGGBLevelsUncorrected", - "Exif.Samsung2.WB_RGGBLevelsAuto", - "Exif.Samsung2.WB_RGGBLevelsIlluminator1", - "Exif.Samsung2.WB_RGGBLevelsIlluminator2", - "Exif.Samsung2.WB_RGGBLevelsBlack", - "Exif.Samsung2.ColorMatrix", - "Exif.Samsung2.ColorMatrixSRGB", - "Exif.Samsung2.ColorMatrixAdobeRGB", - "Exif.Samsung2.ToneCurve1", - "Exif.Samsung2.ToneCurve2", - "Exif.Samsung2.ToneCurve3", - "Exif.Samsung2.ToneCurve4" - }; + static const char *keys[] + = { "Exif.Samsung2.SensorAreas", "Exif.Samsung2.ColorSpace", "Exif.Samsung2.EncryptionKey", + "Exif.Samsung2.WB_RGGBLevelsUncorrected", "Exif.Samsung2.WB_RGGBLevelsAuto", + "Exif.Samsung2.WB_RGGBLevelsIlluminator1", "Exif.Samsung2.WB_RGGBLevelsIlluminator2", + "Exif.Samsung2.WB_RGGBLevelsBlack", "Exif.Samsung2.ColorMatrix", "Exif.Samsung2.ColorMatrixSRGB", + "Exif.Samsung2.ColorMatrixAdobeRGB", "Exif.Samsung2.ToneCurve1", "Exif.Samsung2.ToneCurve2", + "Exif.Samsung2.ToneCurve3", "Exif.Samsung2.ToneCurve4" }; static const guint n_keys = G_N_ELEMENTS(keys); dt_remove_exif_keys(exifData, keys, n_keys); } @@ -1311,11 +1259,8 @@ int dt_exif_read_blob(uint8_t **buf, const char *path, const int imgid, const in } else { - static const char *keys[] = { - "Exif.Image.XResolution", - "Exif.Image.YResolution", - "Exif.Image.ResolutionUnit" - }; + static const char *keys[] + = { "Exif.Image.XResolution", "Exif.Image.YResolution", "Exif.Image.ResolutionUnit" }; static const guint n_keys = G_N_ELEMENTS(keys); dt_remove_exif_keys(exifData, keys, n_keys); } @@ -1328,21 +1273,11 @@ int dt_exif_read_blob(uint8_t **buf, const char *path, const int imgid, const in if(imgid >= 0) { /* Delete metadata taken from the original file if it's fileds we manage in dt, too */ - static const char * keys[] = { - "Exif.Image.Artist", - "Exif.Image.ImageDescription", - "Exif.Photo.UserComment", - "Exif.Image.Copyright", - "Exif.Image.Rating", - "Exif.Image.RatingPercent", - "Exif.GPSInfo.GPSVersionID", - "Exif.GPSInfo.GPSLongitudeRef", - "Exif.GPSInfo.GPSLatitudeRef", - "Exif.GPSInfo.GPSLongitude", - "Exif.GPSInfo.GPSLatitude", - "Exif.GPSInfo.GPSAltitudeRef", - "Exif.GPSInfo.GPSAltitude" - }; + static const char *keys[] + = { "Exif.Image.Artist", "Exif.Image.ImageDescription", "Exif.Photo.UserComment", "Exif.Image.Copyright", + "Exif.Image.Rating", "Exif.Image.RatingPercent", "Exif.GPSInfo.GPSVersionID", + "Exif.GPSInfo.GPSLongitudeRef", "Exif.GPSInfo.GPSLatitudeRef", "Exif.GPSInfo.GPSLongitude", + "Exif.GPSInfo.GPSLatitude", "Exif.GPSInfo.GPSAltitudeRef", "Exif.GPSInfo.GPSAltitude" }; static const guint n_keys = G_N_ELEMENTS(keys); dt_remove_exif_keys(exifData, keys, n_keys); @@ -1429,8 +1364,8 @@ int dt_exif_read_blob(uint8_t **buf, const char *path, const int imgid, const in Exiv2::Blob blob; Exiv2::ExifParser::encode(blob, Exiv2::bigEndian, exifData); const int length = blob.size(); - *buf = (uint8_t *)malloc(length+6); - if (!*buf) + *buf = (uint8_t *)malloc(length + 6); + if(!*buf) { return 0; } @@ -1708,13 +1643,13 @@ static void print_entry(history_entry_t *entry) } std::cout << entry->operation << std::endl; - std::cout << " modversion :" << entry->modversion << std::endl; - std::cout << " enabled :" << entry->enabled << std::endl; - std::cout << " params :" << (entry->params ? "<found>" : "<missing>") << std::endl; + std::cout << " modversion :" << entry->modversion << std::endl; + std::cout << " enabled :" << entry->enabled << std::endl; + std::cout << " params :" << (entry->params ? "<found>" : "<missing>") << std::endl; std::cout << " multi_name :" << (entry->multi_name ? entry->multi_name : "<missing>") << std::endl; - std::cout << " multi_priority :" << entry->multi_priority << std::endl; - std::cout << " blendop_version :" << entry->blendop_version << std::endl; - std::cout << " blendop_params :" << (entry->blendop_params ? "<found>" : "<missing>") << std::endl; + std::cout << " multi_priority :" << entry->multi_priority << std::endl; + std::cout << " blendop_version :" << entry->blendop_version << std::endl; + std::cout << " blendop_params :" << (entry->blendop_params ? "<found>" : "<missing>") << std::endl; std::cout << std::endl; } @@ -1750,58 +1685,42 @@ static GList *read_history_v1(const std::string &xmpPacket, const char *filename return NULL; } - // get the old elements - // select_single_node() is deprecated and just kept for old versions shipped in some distributions +// get the old elements +// select_single_node() is deprecated and just kept for old versions shipped in some distributions #if defined(PUGIXML_VERSION) && PUGIXML_VERSION >= 150 - pugi::xpath_node modversion = superold ? - doc.select_node("//darktable:history_modversion/rdf:Bag"): - doc.select_node("//darktable:history_modversion/rdf:Seq"); - pugi::xpath_node enabled = superold ? - doc.select_node("//darktable:history_enabled/rdf:Bag"): - doc.select_node("//darktable:history_enabled/rdf:Seq"); - pugi::xpath_node operation = superold ? - doc.select_node("//darktable:history_operation/rdf:Bag"): - doc.select_node("//darktable:history_operation/rdf:Seq"); - pugi::xpath_node params = superold ? - doc.select_node("//darktable:history_params/rdf:Bag"): - doc.select_node("//darktable:history_params/rdf:Seq"); - pugi::xpath_node blendop_params = superold ? - doc.select_node("//darktable:blendop_params/rdf:Bag"): - doc.select_node("//darktable:blendop_params/rdf:Seq"); - pugi::xpath_node blendop_version = superold ? - doc.select_node("//darktable:blendop_version/rdf:Bag"): - doc.select_node("//darktable:blendop_version/rdf:Seq"); - pugi::xpath_node multi_priority = superold ? - doc.select_node("//darktable:multi_priority/rdf:Bag"): - doc.select_node("//darktable:multi_priority/rdf:Seq"); - pugi::xpath_node multi_name = superold ? - doc.select_node("//darktable:multi_name/rdf:Bag"): - doc.select_node("//darktable:multi_name/rdf:Bag"); + pugi::xpath_node modversion = superold ? doc.select_node("//darktable:history_modversion/rdf:Bag") + : doc.select_node("//darktable:history_modversion/rdf:Seq"); + pugi::xpath_node enabled = superold ? doc.select_node("//darktable:history_enabled/rdf:Bag") + : doc.select_node("//darktable:history_enabled/rdf:Seq"); + pugi::xpath_node operation = superold ? doc.select_node("//darktable:history_operation/rdf:Bag") + : doc.select_node("//darktable:history_operation/rdf:Seq"); + pugi::xpath_node params = superold ? doc.select_node("//darktable:history_params/rdf:Bag") + : doc.select_node("//darktable:history_params/rdf:Seq"); + pugi::xpath_node blendop_params = superold ? doc.select_node("//darktable:blendop_params/rdf:Bag") + : doc.select_node("//darktable:blendop_params/rdf:Seq"); + pugi::xpath_node blendop_version = superold ? doc.select_node("//darktable:blendop_version/rdf:Bag") + : doc.select_node("//darktable:blendop_version/rdf:Seq"); + pugi::xpath_node multi_priority = superold ? doc.select_node("//darktable:multi_priority/rdf:Bag") + : doc.select_node("//darktable:multi_priority/rdf:Seq"); + pugi::xpath_node multi_name = superold ? doc.select_node("//darktable:multi_name/rdf:Bag") + : doc.select_node("//darktable:multi_name/rdf:Bag"); #else - pugi::xpath_node modversion = superold ? - doc.select_single_node("//darktable:history_modversion/rdf:Bag"): - doc.select_single_node("//darktable:history_modversion/rdf:Seq"); - pugi::xpath_node enabled = superold ? - doc.select_single_node("//darktable:history_enabled/rdf:Bag"): - doc.select_single_node("//darktable:history_enabled/rdf:Seq"); - pugi::xpath_node operation = superold ? - doc.select_single_node("//darktable:history_operation/rdf:Bag"): - doc.select_single_node("//darktable:history_operation/rdf:Seq"); - pugi::xpath_node params = superold ? - doc.select_single_node("//darktable:history_params/rdf:Bag"): - doc.select_single_node("//darktable:history_params/rdf:Seq"); - pugi::xpath_node blendop_params = superold ? - doc.select_single_node("//darktable:blendop_params/rdf:Bag"): - doc.select_single_node("//darktable:blendop_params/rdf:Seq"); - pugi::xpath_node blendop_version = superold ? - doc.select_single_node("//darktable:blendop_version/rdf:Bag"): - doc.select_single_node("//darktable:blendop_version/rdf:Seq"); - pugi::xpath_node multi_priority = superold ? - doc.select_single_node("//darktable:multi_priority/rdf:Bag"): - doc.select_single_node("//darktable:multi_priority/rdf:Seq"); - pugi::xpath_node multi_name = superold ? - doc.select_single_node("//darktable:multi_name/rdf:Bag"): - doc.select_single_node("//darktable:multi_name/rdf:Bag"); + pugi::xpath_node modversion = superold ? doc.select_single_node("//darktable:history_modversion/rdf:Bag") + : doc.select_single_node("//darktable:history_modversion/rdf:Seq"); + pugi::xpath_node enabled = superold ? doc.select_single_node("//darktable:history_enabled/rdf:Bag") + : doc.select_single_node("//darktable:history_enabled/rdf:Seq"); + pugi::xpath_node operation = superold ? doc.select_single_node("//darktable:history_operation/rdf:Bag") + : doc.select_single_node("//darktable:history_operation/rdf:Seq"); + pugi::xpath_node params = superold ? doc.select_single_node("//darktable:history_params/rdf:Bag") + : doc.select_single_node("//darktable:history_params/rdf:Seq"); + pugi::xpath_node blendop_params = superold ? doc.select_single_node("//darktable:blendop_params/rdf:Bag") + : doc.select_single_node("//darktable:blendop_params/rdf:Seq"); + pugi::xpath_node blendop_version = superold ? doc.select_single_node("//darktable:blendop_version/rdf:Bag") + : doc.select_single_node("//darktable:blendop_version/rdf:Seq"); + pugi::xpath_node multi_priority = superold ? doc.select_single_node("//darktable:multi_priority/rdf:Bag") + : doc.select_single_node("//darktable:multi_priority/rdf:Seq"); + pugi::xpath_node multi_name = superold ? doc.select_single_node("//darktable:multi_name/rdf:Bag") + : doc.select_single_node("//darktable:multi_name/rdf:Bag"); #endif // fill the list of history entries. we are iterating over history_operation as we know that it's there. @@ -1814,7 +1733,7 @@ static GList *read_history_v1(const std::string &xmpPacket, const char *filename auto multi_priority_iter = multi_priority.node().children().begin(); auto multi_name_iter = multi_name.node().children().begin(); - for(pugi::xml_node operation_iter: operation.node().children()) + for(pugi::xml_node operation_iter : operation.node().children()) { history_entry_t *current_entry = (history_entry_t *)calloc(1, sizeof(history_entry_t)); current_entry->blendop_version = 1; // default version in case it's not specified @@ -1849,9 +1768,9 @@ static GList *read_history_v1(const std::string &xmpPacket, const char *filename if(blendop_params && blendop_params_iter != blendop_params.node().children().end()) { - current_entry->blendop_params = dt_exif_xmp_decode(blendop_params_iter->child_value(), - strlen(blendop_params_iter->child_value()), - &current_entry->blendop_params_len); + current_entry->blendop_params + = dt_exif_xmp_decode(blendop_params_iter->child_value(), strlen(blendop_params_iter->child_value()), + &current_entry->blendop_params_len); blendop_params_iter++; } @@ -1951,13 +1870,11 @@ static GList *read_history_v2(Exiv2::XmpData &xmpData, const char *filename) } else if(g_str_has_prefix(key_iter, "darktable:blendop_params")) { - current_entry->blendop_params = dt_exif_xmp_decode(history->value().toString().c_str(), - history->value().size(), - &current_entry->blendop_params_len); + current_entry->blendop_params = dt_exif_xmp_decode( + history->value().toString().c_str(), history->value().size(), &current_entry->blendop_params_len); } - } -skip: + skip: g_free(key); } @@ -1967,7 +1884,8 @@ static GList *read_history_v2(Exiv2::XmpData &xmpData, const char *filename) history_entry_t *entry = (history_entry_t *)iter->data; if(!(entry->have_operation && entry->have_params && entry->have_modversion)) { - std::cerr << "[exif] error: reading history from '" << filename << "' failed due to missing tags" << std::endl; + std::cerr << "[exif] error: reading history from '" << filename << "' failed due to missing tags" + << std::endl; g_list_free_full(history_entries, free_entry); history_entries = NULL; break; @@ -2147,12 +2065,13 @@ int dt_exif_xmp_read(dt_image_t *img, const char *filename, const int history_on DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "INSERT INTO main.history (imgid, num, module, operation, op_params, enabled, " "blendop_params, blendop_version, multi_priority, multi_name) " - "VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10)", -1, &stmt, NULL); + "VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10)", + -1, &stmt, NULL); for(GList *iter = history_entries; iter; iter = g_list_next(iter)) { history_entry_t *entry = (history_entry_t *)iter->data; -// print_entry(entry); + // print_entry(entry); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, img->id); DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, num); @@ -2198,8 +2117,7 @@ int dt_exif_xmp_read(dt_image_t *img, const char *filename, const int history_on { int history_end = MIN(pos->toLong(), num); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), - "UPDATE main.images SET history_end = ?1 WHERE id = ?2", -1, - &stmt, NULL); + "UPDATE main.images SET history_end = ?1 WHERE id = ?2", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, history_end); DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, img->id); if(sqlite3_step(stmt) != SQLITE_DONE) @@ -2214,8 +2132,8 @@ int dt_exif_xmp_read(dt_image_t *img, const char *filename, const int history_on { DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "UPDATE main.images SET history_end = (SELECT IFNULL(MAX(num) + 1, 0) " - "FROM main.history WHERE imgid = ?1) WHERE id = ?1", -1, - &stmt, NULL); + "FROM main.history WHERE imgid = ?1) WHERE id = ?1", + -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, img->id); if(sqlite3_step(stmt) != SQLITE_DONE) { @@ -2226,7 +2144,7 @@ int dt_exif_xmp_read(dt_image_t *img, const char *filename, const int history_on } } -end: + end: sqlite3_finalize(stmt); g_list_free_full(history_entries, free_entry); @@ -2241,7 +2159,6 @@ int dt_exif_xmp_read(dt_image_t *img, const char *filename, const int history_on sqlite3_exec(dt_database_get(darktable.db), "ROLLBACK TRANSACTION", NULL, NULL, NULL); return 1; } - } catch(Exiv2::AnyError &e) { @@ -2534,8 +2451,10 @@ static void dt_exif_xmp_read_data(Exiv2::XmpData &xmpData, const int imgid) num++; } - if(history_end == -1) history_end = num - 1; - else history_end = MIN(history_end, num - 1); // safeguard for some old buggy libraries + if(history_end == -1) + history_end = num - 1; + else + history_end = MIN(history_end, num - 1); // safeguard for some old buggy libraries xmpData["Xmp.darktable.history_end"] = history_end; sqlite3_finalize(stmt); @@ -2590,7 +2509,7 @@ char *dt_exif_xmp_read_string(const int imgid) // serialize the xmp data and output the xmp packet std::string xmpPacket; if(Exiv2::XmpParser::encode(xmpPacket, xmpData, - Exiv2::XmpParser::useCompactFormat | Exiv2::XmpParser::omitPacketWrapper) != 0) + Exiv2::XmpParser::useCompactFormat | Exiv2::XmpParser::omitPacketWrapper) != 0) { throw Exiv2::Error(1, "[xmp_write] failed to serialize xmp data"); } @@ -2684,7 +2603,8 @@ int dt_exif_xmp_write(const int imgid, const char *filename) if(g_file_test(filename, G_FILE_TEST_EXISTS)) { // we want to avoid writing the sidecar file if it didn't change to avoid issues when using the same images - // from different computers. sample use case: images on NAS, several computers using them NOT AT THE SAME TIME and + // from different computers. sample use case: images on NAS, several computers using them NOT AT THE SAME + // TIME and // the xmp crawler is used to find changed sidecars. FILE *fd = g_fopen(filename, "rb"); if(fd) @@ -2715,7 +2635,7 @@ int dt_exif_xmp_write(const int imgid, const char *filename) // serialize the xmp data and output the xmp packet if(Exiv2::XmpParser::encode(xmpPacket, xmpData, - Exiv2::XmpParser::useCompactFormat | Exiv2::XmpParser::omitPacketWrapper) != 0) + Exiv2::XmpParser::useCompactFormat | Exiv2::XmpParser::omitPacketWrapper) != 0) { throw Exiv2::Error(1, "[xmp_write] failed to serialize xmp data"); } @@ -2728,8 +2648,8 @@ int dt_exif_xmp_write(const int imgid, const char *filename) GChecksum *checksum = g_checksum_new(G_CHECKSUM_MD5); if(checksum) { - g_checksum_update(checksum, (unsigned char*)xml_header, -1); - g_checksum_update(checksum, (unsigned char*)xmpPacket.c_str(), -1); + g_checksum_update(checksum, (unsigned char *)xml_header, -1); + g_checksum_update(checksum, (unsigned char *)xmpPacket.c_str(), -1); const char *checksum_new = g_checksum_get_string(checksum); write_sidecar = g_strcmp0(checksum_old, checksum_new) != 0; g_checksum_free(checksum); @@ -2781,7 +2701,7 @@ dt_colorspaces_color_profile_type_t dt_exif_get_color_space(const uint8_t *data, else if(colorspace == 0xffff) { if((pos = exifData.findKey(Exiv2::ExifKey("Exif.Iop.InteroperabilityIndex"))) != exifData.end() - && pos->size()) + && pos->size()) { std::string interop_index = pos->toString(); if(interop_index == "R03") @@ -2816,14 +2736,9 @@ gboolean dt_exif_get_datetime_taken(const uint8_t *data, size_t size, time_t *da if(*exif_datetime_taken) { - struct tm exif_tm= {0}; - if(sscanf(exif_datetime_taken,"%d:%d:%d %d:%d:%d", - &exif_tm.tm_year, - &exif_tm.tm_mon, - &exif_tm.tm_mday, - &exif_tm.tm_hour, - &exif_tm.tm_min, - &exif_tm.tm_sec) == 6) + struct tm exif_tm = { 0 }; + if(sscanf(exif_datetime_taken, "%d:%d:%d %d:%d:%d", &exif_tm.tm_year, &exif_tm.tm_mon, &exif_tm.tm_mday, + &exif_tm.tm_hour, &exif_tm.tm_min, &exif_tm.tm_sec) == 6) { exif_tm.tm_year -= 1900; exif_tm.tm_mon--; diff --git a/src/common/exif.h b/src/common/exif.h index 2a7d91957089..b722e2077759 100644 --- a/src/common/exif.h +++ b/src/common/exif.h @@ -65,7 +65,8 @@ char *dt_exif_xmp_encode(const unsigned char *input, const int len, int *output_ char *dt_exif_xmp_encode_internal(const unsigned char *input, const int len, int *output_len, gboolean do_compress); unsigned char *dt_exif_xmp_decode(const char *input, const int len, int *output_len); -/** look for color space hints in data and tell the caller if it's sRGB, AdobeRGB or something else. used for mipmaps */ +/** look for color space hints in data and tell the caller if it's sRGB, AdobeRGB or something else. used for + * mipmaps */ dt_colorspaces_color_profile_type_t dt_exif_get_color_space(const uint8_t *data, size_t size); /** look for datetime_taken in data. used for gphoto downloads */ diff --git a/src/common/file_location.c b/src/common/file_location.c index b195e71f8456..9d9ed66808b7 100644 --- a/src/common/file_location.c +++ b/src/common/file_location.c @@ -17,8 +17,8 @@ */ /* getpwnam_r availability check */ -#if defined __APPLE__ || defined _POSIX_C_SOURCE >= 1 || defined _XOPEN_SOURCE || defined _BSD_SOURCE \ - || defined _SVID_SOURCE || defined _POSIX_SOURCE || defined __DragonFly__ || defined __FreeBSD__ \ +#if defined __APPLE__ || defined _POSIX_C_SOURCE >= 1 || defined _XOPEN_SOURCE || defined _BSD_SOURCE \ + || defined _SVID_SOURCE || defined _POSIX_SOURCE || defined __DragonFly__ || defined __FreeBSD__ \ || defined __NetBSD__ || defined __OpenBSD__ #include "config.h" #include <pwd.h> diff --git a/src/common/film.c b/src/common/film.c index d31ccdfc4a93..fbc4048eddb4 100644 --- a/src/common/film.c +++ b/src/common/film.c @@ -200,8 +200,7 @@ int dt_film_new(dt_film_t *film, const char *directory) dt_pthread_mutex_lock(&darktable.db_insert); rc = sqlite3_step(stmt); if(rc != SQLITE_DONE) - fprintf(stderr, "[film_new] failed to insert film roll! %s\n", - sqlite3_errmsg(dt_database_get(darktable.db))); + fprintf(stderr, "[film_new] failed to insert film roll! %s\n", sqlite3_errmsg(dt_database_get(darktable.db))); sqlite3_finalize(stmt); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT id FROM main.film_rolls WHERE folder=?1", -1, &stmt, NULL); @@ -325,8 +324,8 @@ static gboolean ask_and_delete(gpointer user_data) GtkWidget *tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree), FALSE); - GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes(_("name"), gtk_cell_renderer_text_new(), - "text", 0, NULL); + GtkTreeViewColumn *column + = gtk_tree_view_column_new_with_attributes(_("name"), gtk_cell_renderer_text_new(), "text", 0, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); gtk_container_add(GTK_CONTAINER(scroll), tree); @@ -339,8 +338,7 @@ static gboolean ask_and_delete(gpointer user_data) gint res = gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); if(res == GTK_RESPONSE_YES) - for(GList *iter = empty_dirs; iter; iter = g_list_next(iter)) - rmdir((char *)iter->data); + for(GList *iter = empty_dirs; iter; iter = g_list_next(iter)) rmdir((char *)iter->data); g_list_free_full(empty_dirs, g_free); g_object_unref(store); @@ -373,16 +371,17 @@ void dt_film_remove_empty() if(dt_util_is_dir_empty(folder)) { - if(ask_before_rmdir) empty_dirs = g_list_append(empty_dirs, g_strdup(folder)); - else rmdir(folder); + if(ask_before_rmdir) + empty_dirs = g_list_append(empty_dirs, g_strdup(folder)); + else + rmdir(folder); } } sqlite3_finalize(stmt); if(raise_signal) dt_control_signal_raise(darktable.signals, DT_SIGNAL_FILMROLLS_REMOVED); // dispatch asking for deletion (and subsequent deletion) to the gui thread - if(empty_dirs) - g_idle_add(ask_and_delete, empty_dirs); + if(empty_dirs) g_idle_add(ask_and_delete, empty_dirs); } int dt_film_is_empty(const int id) @@ -493,8 +492,8 @@ GList *dt_film_get_image_ids(const int filmid) { GList *result = NULL; sqlite3_stmt *stmt; - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT id FROM main.images WHERE film_id = ?1", - -1, &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT id FROM main.images WHERE film_id = ?1", -1, + &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, filmid); while(sqlite3_step(stmt) == SQLITE_ROW) { diff --git a/src/common/focus.h b/src/common/focus.h index efbfca5653db..315f92f666d4 100644 --- a/src/common/focus.h +++ b/src/common/focus.h @@ -87,8 +87,7 @@ static inline void _dt_focus_cdf22_wtf(uint8_t *buf, const int l, const int widt } } -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 void _dt_focus_update(dt_focus_cluster_t *f, int frows, int fcols, int i, int j, int wd, int ht, int diff) { const int32_t thrs = FOCUS_THRS; if(diff > thrs) @@ -146,8 +145,7 @@ static void dt_focus_create_clusters(dt_focus_cluster_t *focus, int frows, int f { _dt_focus_update(focus, frows, fcols, i, j, wd, ht, abs(_from_uint8(buffer[4 * ((j + 2) * wd + i) + CHANNEL]))); - _dt_focus_update(focus, frows, fcols, i, j, wd, ht, - abs(_from_uint8(buffer[4 * (j * wd + i + 2) + CHANNEL]))); + _dt_focus_update(focus, frows, fcols, i, j, wd, ht, abs(_from_uint8(buffer[4 * (j * wd + i + 2) + CHANNEL]))); } #if 1 // second pass, HH2 @@ -272,7 +270,7 @@ static void dt_focus_draw_clusters(cairo_t *cr, int width, int height, int imgid } const int32_t tb = DT_PIXEL_APPLY_DPI(dt_conf_get_int("plugins/darkroom/ui/border_size")); - const float scale = fminf((width-2*tb) / (float)wd, (height-2*tb) / (float)ht); + const float scale = fminf((width - 2 * tb) / (float)wd, (height - 2 * tb) / (float)ht); cairo_scale(cr, scale, scale); cairo_translate(cr, -wd / 2.0f, -ht / 2.0f); @@ -320,8 +318,8 @@ static void dt_focus_draw_clusters(cairo_t *cr, int width, int height, int imgid cairo_curve_to(cr, pos[2 * k + 0] - offx[2 * k + 0] + offy[2 * k + 0], pos[2 * k + 1] - offx[2 * k + 1] + offy[2 * k + 1], pos[2 * k + 0] - offx[2 * k + 0] + offy[2 * k + 0], - pos[2 * k + 1] - offx[2 * k + 1] + offy[2 * k + 1], - 2 * pos[2 * k + 0] - offx[2 * k + 0], 2 * pos[2 * k + 1] - offx[2 * k + 1]); + pos[2 * k + 1] - offx[2 * k + 1] + offy[2 * k + 1], 2 * pos[2 * k + 0] - offx[2 * k + 0], + 2 * pos[2 * k + 1] - offx[2 * k + 1]); cairo_curve_to(cr, 3 * pos[2 * k + 0] - offx[2 * k + 0] - offy[2 * k + 0], 3 * pos[2 * k + 1] - offx[2 * k + 1] - offy[2 * k + 1], 3 * pos[2 * k + 0] - offx[2 * k + 0] - offy[2 * k + 0], diff --git a/src/common/gaussian.c b/src/common/gaussian.c index 545377e119b1..406b695ced10 100644 --- a/src/common/gaussian.c +++ b/src/common/gaussian.c @@ -33,8 +33,8 @@ #define BLOCKSIZE (1 << 6) -static void compute_gauss_params(const float sigma, dt_gaussian_order_t order, float *a0, float *a1, - float *a2, float *a3, float *b1, float *b2, float *coefp, float *coefn) +static void compute_gauss_params(const float sigma, dt_gaussian_order_t order, float *a0, float *a1, float *a2, + float *a3, float *b1, float *b2, float *coefp, float *coefn) { const float alpha = 1.695f / sigma; const float ema = exp(-alpha); @@ -55,9 +55,9 @@ static void compute_gauss_params(const float sigma, dt_gaussian_order_t order, f { const float k = (1.0f - ema) * (1.0f - ema) / (1.0f + (2.0f * alpha * ema) - ema2); *a0 = k; - *a1 = k * (alpha - 1.0f) * ema; - *a2 = k * (alpha + 1.0f) * ema; - *a3 = -k * ema2; + *a1 = k *(alpha - 1.0f) * ema; + *a2 = k *(alpha + 1.0f) * ema; + *a3 = -k *ema2; } break; @@ -76,9 +76,9 @@ static void compute_gauss_params(const float sigma, dt_gaussian_order_t order, f float kn = -2.0f * (-1.0f + (3.0f * ema) - (3.0f * ema * ema) + (ema * ema * ema)); kn /= ((3.0f * ema) + 1.0f + (3.0f * ema * ema) + (ema * ema * ema)); *a0 = kn; - *a1 = -kn * (1.0f + (k * alpha)) * ema; - *a2 = kn * (1.0f - (k * alpha)) * ema; - *a3 = -kn * ema2; + *a1 = -kn *(1.0f + (k * alpha)) * ema; + *a2 = kn *(1.0f - (k * alpha)) * ema; + *a3 = -kn *ema2; } } @@ -173,20 +173,20 @@ void dt_gaussian_blur(dt_gaussian_t *g, const float *const in, float *const out) // vertical blur column by column #ifdef _OPENMP -#pragma omp parallel for default(none) shared(temp, Labmin, Labmax, a0, a1, a2, a3, b1, b2, coefp, \ +#pragma omp parallel for default(none) shared(temp, Labmin, Labmax, a0, a1, a2, a3, b1, b2, coefp, \ coefn) schedule(static) #endif for(int i = 0; i < width; i++) { - float xp[4] = {0.0f}; - float yb[4] = {0.0f}; - float yp[4] = {0.0f}; - float xc[4] = {0.0f}; - float yc[4] = {0.0f}; - float xn[4] = {0.0f}; - float xa[4] = {0.0f}; - float yn[4] = {0.0f}; - float ya[4] = {0.0f}; + float xp[4] = { 0.0f }; + float yb[4] = { 0.0f }; + float yp[4] = { 0.0f }; + float xc[4] = { 0.0f }; + float yc[4] = { 0.0f }; + float xn[4] = { 0.0f }; + float xa[4] = { 0.0f }; + float yn[4] = { 0.0f }; + float ya[4] = { 0.0f }; // forward filter for(int k = 0; k < ch; k++) @@ -245,20 +245,20 @@ void dt_gaussian_blur(dt_gaussian_t *g, const float *const in, float *const out) // horizontal blur line by line #ifdef _OPENMP -#pragma omp parallel for default(none) shared(temp, Labmin, Labmax, a0, a1, a2, a3, b1, b2, coefp, \ +#pragma omp parallel for default(none) shared(temp, Labmin, Labmax, a0, a1, a2, a3, b1, b2, coefp, \ coefn) schedule(static) #endif for(int j = 0; j < height; j++) { - float xp[4] = {0.0f}; - float yb[4] = {0.0f}; - float yp[4] = {0.0f}; - float xc[4] = {0.0f}; - float yc[4] = {0.0f}; - float xn[4] = {0.0f}; - float xa[4] = {0.0f}; - float yn[4] = {0.0f}; - float ya[4] = {0.0f}; + float xp[4] = { 0.0f }; + float yb[4] = { 0.0f }; + float yp[4] = { 0.0f }; + float xc[4] = { 0.0f }; + float yc[4] = { 0.0f }; + float xn[4] = { 0.0f }; + float xa[4] = { 0.0f }; + float yn[4] = { 0.0f }; + float ya[4] = { 0.0f }; // forward filter for(int k = 0; k < ch; k++) @@ -367,10 +367,9 @@ static void dt_gaussian_blur_4c_sse(dt_gaussian_t *g, const float *const in, flo xc = MMCLAMPPS(_mm_load_ps(in + offset), Labmin, Labmax); - yc = _mm_add_ps( - _mm_mul_ps(xc, _mm_set_ps1(a0)), - _mm_sub_ps(_mm_mul_ps(xp, _mm_set_ps1(a1)), - _mm_add_ps(_mm_mul_ps(yp, _mm_set_ps1(b1)), _mm_mul_ps(yb, _mm_set_ps1(b2))))); + yc = _mm_add_ps(_mm_mul_ps(xc, _mm_set_ps1(a0)), + _mm_sub_ps(_mm_mul_ps(xp, _mm_set_ps1(a1)), + _mm_add_ps(_mm_mul_ps(yp, _mm_set_ps1(b1)), _mm_mul_ps(yb, _mm_set_ps1(b2))))); _mm_store_ps(temp + offset, yc); @@ -391,10 +390,9 @@ static void dt_gaussian_blur_4c_sse(dt_gaussian_t *g, const float *const in, flo xc = MMCLAMPPS(_mm_load_ps(in + offset), Labmin, Labmax); - yc = _mm_add_ps( - _mm_mul_ps(xn, _mm_set_ps1(a2)), - _mm_sub_ps(_mm_mul_ps(xa, _mm_set_ps1(a3)), - _mm_add_ps(_mm_mul_ps(yn, _mm_set_ps1(b1)), _mm_mul_ps(ya, _mm_set_ps1(b2))))); + yc = _mm_add_ps(_mm_mul_ps(xn, _mm_set_ps1(a2)), + _mm_sub_ps(_mm_mul_ps(xa, _mm_set_ps1(a3)), + _mm_add_ps(_mm_mul_ps(yn, _mm_set_ps1(b1)), _mm_mul_ps(ya, _mm_set_ps1(b2))))); xa = xn; @@ -434,10 +432,9 @@ static void dt_gaussian_blur_4c_sse(dt_gaussian_t *g, const float *const in, flo xc = MMCLAMPPS(_mm_load_ps(temp + offset), Labmin, Labmax); - yc = _mm_add_ps( - _mm_mul_ps(xc, _mm_set_ps1(a0)), - _mm_sub_ps(_mm_mul_ps(xp, _mm_set_ps1(a1)), - _mm_add_ps(_mm_mul_ps(yp, _mm_set_ps1(b1)), _mm_mul_ps(yb, _mm_set_ps1(b2))))); + yc = _mm_add_ps(_mm_mul_ps(xc, _mm_set_ps1(a0)), + _mm_sub_ps(_mm_mul_ps(xp, _mm_set_ps1(a1)), + _mm_add_ps(_mm_mul_ps(yp, _mm_set_ps1(b1)), _mm_mul_ps(yb, _mm_set_ps1(b2))))); _mm_store_ps(out + offset, yc); @@ -459,10 +456,9 @@ static void dt_gaussian_blur_4c_sse(dt_gaussian_t *g, const float *const in, flo xc = MMCLAMPPS(_mm_load_ps(temp + offset), Labmin, Labmax); - yc = _mm_add_ps( - _mm_mul_ps(xn, _mm_set_ps1(a2)), - _mm_sub_ps(_mm_mul_ps(xa, _mm_set_ps1(a3)), - _mm_add_ps(_mm_mul_ps(yn, _mm_set_ps1(b1)), _mm_mul_ps(ya, _mm_set_ps1(b2))))); + yc = _mm_add_ps(_mm_mul_ps(xn, _mm_set_ps1(a2)), + _mm_sub_ps(_mm_mul_ps(xa, _mm_set_ps1(a3)), + _mm_add_ps(_mm_mul_ps(yn, _mm_set_ps1(b1)), _mm_mul_ps(ya, _mm_set_ps1(b2))))); xa = xn; @@ -564,10 +560,14 @@ dt_gaussian_cl_t *dt_gaussian_init_cl(const int devid, : g->global->kernel_gaussian_transpose_4c; int blocksize; - dt_opencl_local_buffer_t locopt - = (dt_opencl_local_buffer_t){ .xoffset = 1, .xfactor = 1, .yoffset = 0, .yfactor = 1, - .cellsize = channels * sizeof(float), .overhead = 0, - .sizex = BLOCKSIZE, .sizey = BLOCKSIZE }; + dt_opencl_local_buffer_t locopt = (dt_opencl_local_buffer_t){.xoffset = 1, + .xfactor = 1, + .yoffset = 0, + .yfactor = 1, + .cellsize = channels * sizeof(float), + .overhead = 0, + .sizex = BLOCKSIZE, + .sizey = BLOCKSIZE }; if(dt_opencl_local_buffer_opt(devid, kernel_gaussian_transpose, &locopt)) blocksize = MIN(locopt.sizex, locopt.sizey); diff --git a/src/common/gpx.c b/src/common/gpx.c index 260f307042fa..0c887aff546b 100644 --- a/src/common/gpx.c +++ b/src/common/gpx.c @@ -51,10 +51,10 @@ typedef struct dt_gpx_t static void _gpx_parser_start_element(GMarkupParseContext *ctx, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer ueer_data, GError **error); -static void _gpx_parser_end_element(GMarkupParseContext *context, const gchar *element_name, - gpointer user_data, GError **error); -static void _gpx_parser_text(GMarkupParseContext *context, const gchar *text, gsize text_len, - gpointer user_data, GError **error); +static void _gpx_parser_end_element(GMarkupParseContext *context, const gchar *element_name, gpointer user_data, + GError **error); +static void _gpx_parser_text(GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, + GError **error); static GMarkupParser _gpx_parser = { _gpx_parser_start_element, _gpx_parser_end_element, _gpx_parser_text, NULL, NULL }; @@ -134,8 +134,7 @@ void dt_gpx_destroy(struct dt_gpx_t *gpx) g_free(gpx); } -gboolean dt_gpx_get_location(struct dt_gpx_t *gpx, GTimeVal *timestamp, gdouble *lon, gdouble *lat, - gdouble *ele) +gboolean dt_gpx_get_location(struct dt_gpx_t *gpx, GTimeVal *timestamp, gdouble *lon, gdouble *lat, gdouble *ele) { g_assert(gpx != NULL); @@ -178,9 +177,8 @@ gboolean dt_gpx_get_location(struct dt_gpx_t *gpx, GTimeVal *timestamp, gdouble /* * GPX XML parser code */ -void _gpx_parser_start_element(GMarkupParseContext *ctx, const gchar *element_name, - const gchar **attribute_names, const gchar **attribute_values, - gpointer user_data, GError **error) +void _gpx_parser_start_element(GMarkupParseContext *ctx, const gchar *element_name, const gchar **attribute_names, + const gchar **attribute_values, gpointer user_data, GError **error) { dt_gpx_t *gpx = (dt_gpx_t *)user_data; diff --git a/src/common/histogram.c b/src/common/histogram.c index 2fccdd3f37c1..58639a8f2628 100644 --- a/src/common/histogram.c +++ b/src/common/histogram.c @@ -203,8 +203,8 @@ inline static void histogram_helper_cs_Lab(const dt_dev_histogram_collection_par //============================================================================== void dt_histogram_worker(dt_dev_histogram_collection_params_t *const histogram_params, - dt_dev_histogram_stats_t *histogram_stats, const void *const pixel, - uint32_t **histogram, const dt_worker Worker) + dt_dev_histogram_stats_t *histogram_stats, const void *const pixel, uint32_t **histogram, + const dt_worker Worker) { const int nthreads = omp_get_max_threads(); @@ -276,8 +276,8 @@ void dt_histogram_helper(dt_dev_histogram_collection_params_t *histogram_params, } } -void dt_histogram_max_helper(const dt_dev_histogram_stats_t *const histogram_stats, - dt_iop_colorspace_type_t cst, uint32_t **histogram, uint32_t *histogram_max) +void dt_histogram_max_helper(const dt_dev_histogram_stats_t *const histogram_stats, dt_iop_colorspace_type_t cst, + uint32_t **histogram, uint32_t *histogram_max) { if(*histogram == NULL) return; histogram_max[0] = histogram_max[1] = histogram_max[2] = histogram_max[3] = 0; diff --git a/src/common/histogram.h b/src/common/histogram.h index 954ce346b3bf..e7d0d389a967 100644 --- a/src/common/histogram.h +++ b/src/common/histogram.h @@ -38,19 +38,19 @@ typedef struct dt_histogram_roi_t void dt_histogram_helper_cs_RAW_uint16(const dt_dev_histogram_collection_params_t *histogram_params, const void *pixel, uint32_t *histogram, int j); -typedef void((*dt_worker)(const dt_dev_histogram_collection_params_t *const histogram_params, - const void *pixel, uint32_t *histogram, int j)); +typedef void((*dt_worker)(const dt_dev_histogram_collection_params_t *const histogram_params, const void *pixel, + uint32_t *histogram, int j)); void dt_histogram_worker(dt_dev_histogram_collection_params_t *const histogram_params, - dt_dev_histogram_stats_t *histogram_stats, const void *const pixel, - uint32_t **histogram, const dt_worker Worker); + dt_dev_histogram_stats_t *histogram_stats, const void *const pixel, uint32_t **histogram, + const dt_worker Worker); void dt_histogram_helper(dt_dev_histogram_collection_params_t *histogram_params, dt_dev_histogram_stats_t *histogram_stats, dt_iop_colorspace_type_t cst, const void *pixel, uint32_t **histogram); -void dt_histogram_max_helper(const dt_dev_histogram_stats_t *const histogram_stats, - dt_iop_colorspace_type_t cst, uint32_t **histogram, uint32_t *histogram_max); +void dt_histogram_max_helper(const dt_dev_histogram_stats_t *const histogram_stats, dt_iop_colorspace_type_t cst, + uint32_t **histogram, uint32_t *histogram_max); // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh // vim: shiftwidth=2 expandtab tabstop=2 cindent diff --git a/src/common/history.c b/src/common/history.c index dd6c68d49689..1696e29eecb6 100644 --- a/src/common/history.c +++ b/src/common/history.c @@ -87,18 +87,19 @@ static void _dt_history_cleanup_multi_instance(int imgid, int minnum) { const char *op = (const char *)sqlite3_column_text(stmt, 1); GList *modules = darktable.iop; - while (modules) + while(modules) { dt_iop_module_so_t *find_op = (dt_iop_module_so_t *)(modules->data); - if (!strcmp(find_op->op, op)) + if(!strcmp(find_op->op, op)) { break; } modules = g_list_next(modules); } - if (modules && (((dt_iop_module_so_t *)(modules->data))->flags() & IOP_FLAGS_ONE_INSTANCE)) + if(modules && (((dt_iop_module_so_t *)(modules->data))->flags() & IOP_FLAGS_ONE_INSTANCE)) { - // the current module is a single-instance one, so there's no point in trying to mess up our multi_priority value + // the current module is a single-instance one, so there's no point in trying to mess up our multi_priority + // value continue; } @@ -197,8 +198,8 @@ void dt_history_delete_on_image(int32_t imgid) void dt_history_delete_on_selection() { sqlite3_stmt *stmt; - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT imgid FROM main.selected_images", - -1, &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT imgid FROM main.selected_images", -1, &stmt, + NULL); while(sqlite3_step(stmt) == SQLITE_ROW) { int imgid = sqlite3_column_int(stmt, 0); @@ -228,8 +229,8 @@ int dt_history_load_and_apply_on_selection(gchar *filename) { int res = 0; sqlite3_stmt *stmt; - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT imgid FROM main.selected_images", - -1, &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT imgid FROM main.selected_images", -1, &stmt, + NULL); while(sqlite3_step(stmt) == SQLITE_ROW) { int imgid = sqlite3_column_int(stmt, 0); @@ -262,14 +263,15 @@ int dt_history_copy_and_paste_on_image(int32_t imgid, int32_t dest_imgid, gboole // first trim the stack to get rid of whatever is above the selected entry DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "DELETE FROM main.history WHERE imgid = ?1 AND num >= (SELECT history_end " - "FROM main.images WHERE id = imgid)", -1, &stmt, NULL); + "FROM main.images WHERE id = imgid)", + -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, dest_imgid); sqlite3_step(stmt); sqlite3_finalize(stmt); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), - "SELECT IFNULL(MAX(num), -1)+1 FROM main.history WHERE imgid = ?1", - -1, &stmt, NULL); + "SELECT IFNULL(MAX(num), -1)+1 FROM main.history WHERE imgid = ?1", -1, &stmt, + NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, dest_imgid); if(sqlite3_step(stmt) == SQLITE_ROW) offs = sqlite3_column_int(stmt, 0); } @@ -415,11 +417,9 @@ GList *dt_history_get_items(int32_t imgid, gboolean enabled) if(enabled) { if(strcmp(mname, "0") == 0) - g_snprintf(name, sizeof(name), "%s", - dt_iop_get_localized_name((char *)sqlite3_column_text(stmt, 1))); + g_snprintf(name, sizeof(name), "%s", dt_iop_get_localized_name((char *)sqlite3_column_text(stmt, 1))); else - g_snprintf(name, sizeof(name), "%s %s", - dt_iop_get_localized_name((char *)sqlite3_column_text(stmt, 1)), + g_snprintf(name, sizeof(name), "%s %s", dt_iop_get_localized_name((char *)sqlite3_column_text(stmt, 1)), (char *)sqlite3_column_text(stmt, 3)); } else diff --git a/src/common/http_server.c b/src/common/http_server.c index 2c59ffb562be..db8ab3137d5c 100644 --- a/src/common/http_server.c +++ b/src/common/http_server.c @@ -146,8 +146,8 @@ dt_http_server_t *dt_http_server_create(const int *ports, const int n_ports, con return NULL; } - httpserver = soup_server_new(SOUP_SERVER_SERVER_HEADER, "darktable internal server", "interface", - httpaddress, NULL); + httpserver + = soup_server_new(SOUP_SERVER_SERVER_HEADER, "darktable internal server", "interface", httpaddress, NULL); if(httpserver) break; diff --git a/src/common/image.c b/src/common/image.c index 68c58548fd18..ce49c448f801 100644 --- a/src/common/image.c +++ b/src/common/image.c @@ -52,8 +52,7 @@ int dt_image_is_ldr(const dt_image_t *img) { const char *c = img->filename + strlen(img->filename); while(*c != '.' && c > img->filename) c--; - if((img->flags & DT_IMAGE_LDR) || !strcasecmp(c, ".jpg") || !strcasecmp(c, ".png") - || !strcasecmp(c, ".ppm")) + if((img->flags & DT_IMAGE_LDR) || !strcasecmp(c, ".jpg") || !strcasecmp(c, ".png") || !strcasecmp(c, ".ppm")) return 1; else return 0; @@ -63,8 +62,7 @@ int dt_image_is_hdr(const dt_image_t *img) { const char *c = img->filename + strlen(img->filename); while(*c != '.' && c > img->filename) c--; - if((img->flags & DT_IMAGE_HDR) || !strcasecmp(c, ".exr") || !strcasecmp(c, ".hdr") - || !strcasecmp(c, ".pfm")) + if((img->flags & DT_IMAGE_HDR) || !strcasecmp(c, ".exr") || !strcasecmp(c, ".hdr") || !strcasecmp(c, ".pfm")) return 1; else return 0; @@ -194,7 +192,7 @@ void dt_image_full_path(const int imgid, char *pathname, size_t pathname_len, gb char lc_pathname[PATH_MAX] = { 0 }; _image_local_copy_full_path(imgid, lc_pathname, sizeof(lc_pathname)); - if (g_file_test(lc_pathname, G_FILE_TEST_EXISTS)) + if(g_file_test(lc_pathname, G_FILE_TEST_EXISTS)) g_strlcpy(pathname, (char *)lc_pathname, pathname_len); else *from_cache = FALSE; @@ -331,7 +329,8 @@ void dt_image_set_flip(const int32_t imgid, const dt_image_orientation_t orienta sqlite3_stmt *stmt; // push new orientation to sql via additional history entry: DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT IFNULL(MAX(num)+1, 0) FROM main.history " - "WHERE imgid = ?1", -1, &stmt, NULL); + "WHERE imgid = ?1", + -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); const int iop_flip_MODVER = 2; int num = 0; @@ -352,7 +351,8 @@ void dt_image_set_flip(const int32_t imgid, const dt_image_orientation_t orienta DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "UPDATE main.images SET history_end = (SELECT MAX(num) + 1 FROM main.history " - "WHERE imgid = ?1) WHERE id = ?1", -1, &stmt, NULL); + "WHERE imgid = ?1) WHERE id = ?1", + -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); sqlite3_step(stmt); sqlite3_finalize(stmt); @@ -660,8 +660,7 @@ void dt_image_read_duplicates(const uint32_t id, const char *filename) gchar pattern[PATH_MAX] = { 0 }; // NULL terminated list of glob patterns; should include "" and can be extended if needed - static const gchar *glob_patterns[] - = { "", "_[0-9][0-9]", "_[0-9][0-9][0-9]", "_[0-9][0-9][0-9][0-9]", NULL }; + static const gchar *glob_patterns[] = { "", "_[0-9][0-9]", "_[0-9][0-9][0-9]", "_[0-9][0-9][0-9][0-9]", NULL }; const gchar **glob_pattern = glob_patterns; GList *files = NULL; @@ -687,16 +686,14 @@ void dt_image_read_duplicates(const uint32_t id, const char *filename) char *file = g_utf16_to_utf8(data.cFileName, -1, NULL, NULL, NULL); files = g_list_append(files, g_build_filename(imgpath, file, NULL)); g_free(file); - } - while(FindNextFileW(handle, &data)); + } while(FindNextFileW(handle, &data)); } FindClose(handle); #else glob_t globbuf; if(!glob(pattern, 0, NULL, &globbuf)) { - for(size_t i = 0; i < globbuf.gl_pathc; i++) - files = g_list_append(files, g_strdup(globbuf.gl_pathv[i])); + for(size_t i = 0; i < globbuf.gl_pathc; i++) files = g_list_append(files, g_strdup(globbuf.gl_pathv[i])); globfree(&globbuf); } #endif @@ -725,8 +722,7 @@ void dt_image_read_duplicates(const uint32_t id, const char *filename) gchar *c3 = xmpfilename + strlen(xmpfilename) - 5; // skip over .xmp extension; position c3 at character before the '.' - while(*c3 != '.' && c3 > xmpfilename) - c3--; // skip over filename extension; position c3 is at character '.' + while(*c3 != '.' && c3 > xmpfilename) c3--; // skip over filename extension; position c3 is at character '.' gchar *c4 = c3; while(*c4 != '_' && c4 > xmpfilename) c4--; // move to beginning of version number c4++; @@ -751,10 +747,12 @@ void dt_image_read_duplicates(const uint32_t id, const char *filename) } -static uint32_t dt_image_import_internal(const int32_t film_id, const char *filename, gboolean override_ignore_jpegs, gboolean lua_locking) +static uint32_t dt_image_import_internal(const int32_t film_id, const char *filename, + gboolean override_ignore_jpegs, gboolean lua_locking) { char *normalized_filename = dt_util_normalize_path(filename); - if(!normalized_filename || !g_file_test(normalized_filename, G_FILE_TEST_IS_REGULAR) || dt_util_get_file_size(normalized_filename) == 0) + if(!normalized_filename || !g_file_test(normalized_filename, G_FILE_TEST_IS_REGULAR) + || dt_util_get_file_size(normalized_filename) == 0) { g_free(normalized_filename); return 0; @@ -985,17 +983,15 @@ static uint32_t dt_image_import_internal(const int32_t film_id, const char *file g_free(normalized_filename); #ifdef USE_LUA - //Synchronous calling of lua post-import-image events - if(lua_locking) - dt_lua_lock(); + // Synchronous calling of lua post-import-image events + if(lua_locking) dt_lua_lock(); lua_State *L = darktable.lua_state.state; luaA_push(L, dt_lua_image_t, &id); dt_lua_event_trigger(L, "post-import-image", 1); - if(lua_locking) - dt_lua_unlock(); + if(lua_locking) dt_lua_unlock(); #endif dt_control_signal_raise(darktable.signals, DT_SIGNAL_IMAGE_IMPORT, id); @@ -1072,20 +1068,19 @@ void dt_image_init(dt_image_t *img) void dt_image_refresh_makermodel(dt_image_t *img) { - if (!img->camera_maker[0] || !img->camera_model[0] || !img->camera_alias[0]) + if(!img->camera_maker[0] || !img->camera_model[0] || !img->camera_alias[0]) { // We need to use the exif values, so let's get rawspeed to munge them - dt_rawspeed_lookup_makermodel(img->exif_maker, img->exif_model, - img->camera_maker, sizeof(img->camera_maker), - img->camera_model, sizeof(img->camera_model), - img->camera_alias, sizeof(img->camera_alias)); + dt_rawspeed_lookup_makermodel(img->exif_maker, img->exif_model, img->camera_maker, sizeof(img->camera_maker), + img->camera_model, sizeof(img->camera_model), img->camera_alias, + sizeof(img->camera_alias)); } // Now we just create a makermodel by concatenation g_strlcpy(img->camera_makermodel, img->camera_maker, sizeof(img->camera_makermodel)); int len = strlen(img->camera_maker); img->camera_makermodel[len] = ' '; - g_strlcpy(img->camera_makermodel+len+1, img->camera_model, sizeof(img->camera_makermodel)-len-1); + g_strlcpy(img->camera_makermodel + len + 1, img->camera_model, sizeof(img->camera_makermodel) - len - 1); } int32_t dt_image_move(const int32_t imgid, const int32_t filmid) @@ -1148,8 +1143,7 @@ int32_t dt_image_move(const int32_t imgid, const int32_t filmid) GFile *goldxmp = g_file_new_for_path(oldxmp); GFile *gnewxmp = g_file_new_for_path(newxmp); - if(g_file_test(oldxmp, G_FILE_TEST_EXISTS)) - (void)g_file_move(goldxmp, gnewxmp, 0, NULL, NULL, NULL, NULL); + if(g_file_test(oldxmp, G_FILE_TEST_EXISTS)) (void)g_file_move(goldxmp, gnewxmp, 0, NULL, NULL, NULL, NULL); g_object_unref(goldxmp); g_object_unref(gnewxmp); @@ -1459,8 +1453,7 @@ int dt_image_local_copy_reset(const int32_t imgid) const gboolean local_copy_exists = (imgr->flags & DT_IMAGE_LOCAL_COPY) == DT_IMAGE_LOCAL_COPY ? TRUE : FALSE; dt_image_cache_read_release(darktable.image_cache, imgr); - if (!local_copy_exists) - return 0; + if(!local_copy_exists) return 0; // check that the original file is accessible @@ -1539,14 +1532,14 @@ void dt_image_write_sidecar_file(int imgid) gboolean from_cache = FALSE; dt_image_full_path(imgid, filename, sizeof(filename), &from_cache); - if (!g_file_test(filename, G_FILE_TEST_EXISTS)) + if(!g_file_test(filename, G_FILE_TEST_EXISTS)) { // OTHERWISE: check if the local copy exists from_cache = TRUE; dt_image_full_path(imgid, filename, sizeof(filename), &from_cache); // nothing to do, the original is not accessible and there is no local copy - if (!from_cache) return; + if(!from_cache) return; } dt_image_path_append_version(imgid, filename, sizeof(filename)); @@ -1642,9 +1635,8 @@ void dt_image_local_copy_synch(void) if(count > 0) { - dt_control_log(ngettext("%d local copy has been synchronized", - "%d local copies have been synchronized", count), - count); + dt_control_log( + ngettext("%d local copy has been synchronized", "%d local copies have been synchronized", count), count); } } @@ -1661,8 +1653,8 @@ void dt_image_add_time_offset(const int imgid, const long int offset) gint minute; gint seconds; - if(sscanf(cimg->exif_datetime_taken, "%d:%d:%d %d:%d:%d", (int *)&year, (int *)&month, (int *)&day, - (int *)&hour, (int *)&minute, (int *)&seconds) != 6) + if(sscanf(cimg->exif_datetime_taken, "%d:%d:%d %d:%d:%d", (int *)&year, (int *)&month, (int *)&day, (int *)&hour, + (int *)&minute, (int *)&seconds) != 6) { fprintf(stderr, "broken exif time in db, '%s', imgid %d\n", cimg->exif_datetime_taken, imgid); dt_image_cache_read_release(darktable.image_cache, cimg); @@ -1699,7 +1691,8 @@ void dt_image_add_time_offset(const int imgid, const long int offset) g_strlcpy(img->exif_datetime_taken, datetime, sizeof(img->exif_datetime_taken)); dt_image_cache_write_release(darktable.image_cache, img, DT_IMAGE_CACHE_SAFE); } - else dt_image_cache_read_release(darktable.image_cache, cimg); + else + dt_image_cache_read_release(darktable.image_cache, cimg); g_free(datetime); } diff --git a/src/common/image.h b/src/common/image.h index 9bcf083355bd..d9bc71088711 100644 --- a/src/common/image.h +++ b/src/common/image.h @@ -94,12 +94,12 @@ typedef enum dt_image_orientation_t ORIENTATION_SWAP_XY = 1 << 2, // 4 /* ClockWise rotation == "-"; CounterClockWise rotation == "+" */ - ORIENTATION_FLIP_HORIZONTALLY = ORIENTATION_FLIP_Y, // 1 - ORIENTATION_FLIP_VERTICALLY = ORIENTATION_FLIP_X, // 2 - ORIENTATION_ROTATE_180_DEG = ORIENTATION_FLIP_Y | ORIENTATION_FLIP_X, // 3 - ORIENTATION_400 /* ??? */ = ORIENTATION_SWAP_XY, // 4 - ORIENTATION_ROTATE_CCW_90_DEG = ORIENTATION_FLIP_Y | ORIENTATION_SWAP_XY, // 5 - ORIENTATION_ROTATE_CW_90_DEG = ORIENTATION_FLIP_X | ORIENTATION_SWAP_XY, // 6 + ORIENTATION_FLIP_HORIZONTALLY = ORIENTATION_FLIP_Y, // 1 + ORIENTATION_FLIP_VERTICALLY = ORIENTATION_FLIP_X, // 2 + ORIENTATION_ROTATE_180_DEG = ORIENTATION_FLIP_Y | ORIENTATION_FLIP_X, // 3 + ORIENTATION_400 /* ??? */ = ORIENTATION_SWAP_XY, // 4 + ORIENTATION_ROTATE_CCW_90_DEG = ORIENTATION_FLIP_Y | ORIENTATION_SWAP_XY, // 5 + ORIENTATION_ROTATE_CW_90_DEG = ORIENTATION_FLIP_X | ORIENTATION_SWAP_XY, // 6 ORIENTATION_421 /* ??? */ = ORIENTATION_FLIP_Y | ORIENTATION_FLIP_X | ORIENTATION_SWAP_XY // 7 } dt_image_orientation_t; @@ -211,7 +211,8 @@ void dt_image_path_append_version(int imgid, char *pathname, size_t pathname_len void dt_image_print_exif(const dt_image_t *img, char *line, size_t line_len); /** look for duplicate's xmp files and read them. */ void dt_image_read_duplicates(uint32_t id, const char *filename); -/** imports a new image from raw/etc file and adds it to the data base and image cache. Use from threads other than lua.*/ +/** imports a new image from raw/etc file and adds it to the data base and image cache. Use from threads other than + * lua.*/ uint32_t dt_image_import(int32_t film_id, const char *filename, gboolean override_ignore_jpegs); /** imports a new image from raw/etc file and adds it to the data base and image cache. Use from lua thread.*/ uint32_t dt_image_import_lua(int32_t film_id, const char *filename, gboolean override_ignore_jpegs); diff --git a/src/common/image_cache.c b/src/common/image_cache.c index 252059e3a8a3..4f7e86f20ee9 100644 --- a/src/common/image_cache.c +++ b/src/common/image_cache.c @@ -52,8 +52,8 @@ void dt_image_cache_allocate(void *data, dt_cache_entry_t *entry) img->width = sqlite3_column_int(stmt, 3); img->height = sqlite3_column_int(stmt, 4); img->crop_x = img->crop_y = img->crop_width = img->crop_height = 0; - img->filename[0] = img->exif_maker[0] = img->exif_model[0] = img->exif_lens[0] - = img->exif_datetime_taken[0] = '\0'; + img->filename[0] = img->exif_maker[0] = img->exif_model[0] = img->exif_lens[0] = img->exif_datetime_taken[0] + = '\0'; str = (char *)sqlite3_column_text(stmt, 5); if(str) g_strlcpy(img->filename, str, sizeof(img->filename)); str = (char *)sqlite3_column_text(stmt, 6); @@ -172,8 +172,7 @@ void dt_image_cache_cleanup(dt_image_cache_t *cache) void dt_image_cache_print(dt_image_cache_t *cache) { printf("[image cache] fill %.2f/%.2f MB (%.2f%%)\n", cache->cache.cost / (1024.0 * 1024.0), - cache->cache.cost_quota / (1024.0 * 1024.0), - (float)cache->cache.cost / (float)cache->cache.cost_quota); + cache->cache.cost_quota / (1024.0 * 1024.0), (float)cache->cache.cost / (float)cache->cache.cost_quota); } dt_image_t *dt_image_cache_get(dt_image_cache_t *cache, const uint32_t imgid, char mode) diff --git a/src/common/image_cache.h b/src/common/image_cache.h index 3fd38da8ff54..0519c56ef6c2 100644 --- a/src/common/image_cache.h +++ b/src/common/image_cache.h @@ -24,8 +24,7 @@ typedef struct dt_image_cache_t { dt_cache_t cache; -} -dt_image_cache_t; +} dt_image_cache_t; // what to do if an image struct is // released after writing. @@ -35,8 +34,7 @@ typedef enum dt_image_cache_write_mode_t DT_IMAGE_CACHE_SAFE = 0, // only write to db and do xmp only during shutdown DT_IMAGE_CACHE_RELAXED = 1 -} -dt_image_cache_write_mode_t; +} dt_image_cache_write_mode_t; void dt_image_cache_init(dt_image_cache_t *cache); void dt_image_cache_cleanup(dt_image_cache_t *cache); diff --git a/src/common/imageio.c b/src/common/imageio.c index a95b4354d85e..444da9e2e793 100644 --- a/src/common/imageio.c +++ b/src/common/imageio.c @@ -157,10 +157,9 @@ int dt_imageio_large_thumbnail(const char *filename, uint8_t **buffer, int32_t * if(res) { - fprintf( - stderr, - "[dt_imageio_large_thumbnail] error: Not a supported thumbnail image format or broken thumbnail: %s\n", - mime_type); + fprintf(stderr, + "[dt_imageio_large_thumbnail] error: Not a supported thumbnail image format or broken thumbnail: %s\n", + mime_type); goto error; } @@ -215,10 +214,9 @@ void dt_imageio_flip_buffers(char *out, const char *in, const size_t bpp, const } } -void dt_imageio_flip_buffers_ui16_to_float(float *out, const uint16_t *in, const float black, - const float white, const int ch, const int wd, const int ht, - const int fwd, const int fht, const int stride, - const dt_image_orientation_t orientation) +void dt_imageio_flip_buffers_ui16_to_float(float *out, const uint16_t *in, const float black, const float white, + const int ch, const int wd, const int ht, const int fwd, const int fht, + const int stride, const dt_image_orientation_t orientation) { const float scale = 1.0f / (white - black); if(!orientation) @@ -266,9 +264,8 @@ void dt_imageio_flip_buffers_ui16_to_float(float *out, const uint16_t *in, const } void dt_imageio_flip_buffers_ui8_to_float(float *out, const uint8_t *in, const float black, const float white, - const int ch, const int wd, const int ht, const int fwd, - const int fht, const int stride, - const dt_image_orientation_t orientation) + const int ch, const int wd, const int ht, const int fwd, const int fht, + const int stride, const dt_image_orientation_t orientation) { const float scale = 1.0f / (white - black); if(!orientation) @@ -315,8 +312,7 @@ void dt_imageio_flip_buffers_ui8_to_float(float *out, const uint8_t *in, const f } } -size_t dt_imageio_write_pos(int i, int j, int wd, int ht, float fwd, float fht, - dt_image_orientation_t orientation) +size_t dt_imageio_write_pos(int i, int j, int wd, int ht, float fwd, float fht, dt_image_orientation_t orientation) { int ii = i, jj = j, w = wd, fw = fwd, fh = fht; if(orientation & ORIENTATION_SWAP_XY) @@ -531,25 +527,23 @@ int dt_imageio_export(const uint32_t imgid, const char *filename, dt_imageio_mod dt_imageio_module_storage_t *storage, dt_imageio_module_data_t *storage_params, int num, int total) { - if(strcmp(format->mime(format_params), "x-copy") == 0) - /* This is a just a copy, skip process and just export */ + if(strcmp(format->mime(format_params), "x-copy") == 0) /* This is a just a copy, skip process and just export */ return format->write_image(format_params, filename, NULL, NULL, 0, imgid, num, total); else - return dt_imageio_export_with_flags(imgid, filename, format, format_params, 0, 0, high_quality, upscale, - 0, NULL, copy_metadata, icc_type, icc_filename, icc_intent, storage, + return dt_imageio_export_with_flags(imgid, filename, format, format_params, 0, 0, high_quality, upscale, 0, + NULL, copy_metadata, icc_type, icc_filename, icc_intent, storage, storage_params, num, total); } // internal function: to avoid exif blob reading + 8-bit byteorder flag + high-quality override -int dt_imageio_export_with_flags(const uint32_t imgid, const char *filename, - dt_imageio_module_format_t *format, dt_imageio_module_data_t *format_params, - const int32_t ignore_exif, const int32_t display_byteorder, - const gboolean high_quality, const gboolean upscale, const int32_t thumbnail_export, - const char *filter, const gboolean copy_metadata, - dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename, - dt_iop_color_intent_t icc_intent, - dt_imageio_module_storage_t *storage, - dt_imageio_module_data_t *storage_params, int num, int total) +int dt_imageio_export_with_flags(const uint32_t imgid, const char *filename, dt_imageio_module_format_t *format, + dt_imageio_module_data_t *format_params, const int32_t ignore_exif, + const int32_t display_byteorder, const gboolean high_quality, + const gboolean upscale, const int32_t thumbnail_export, const char *filter, + const gboolean copy_metadata, dt_colorspaces_color_profile_type_t icc_type, + const gchar *icc_filename, dt_iop_color_intent_t icc_intent, + dt_imageio_module_storage_t *storage, dt_imageio_module_data_t *storage_params, + int num, int total) { dt_develop_t dev; dt_dev_init(&dev, 0); @@ -629,7 +623,8 @@ int dt_imageio_export_with_flags(const uint32_t imgid, const char *filename, dt_dev_history_item_t *h = malloc(sizeof(dt_dev_history_item_t)); dt_iop_module_t *style_module = m; - if((format_params->style_append && !(m->flags() & IOP_FLAGS_ONE_INSTANCE)) || m->multi_priority != s->multi_priority) + if((format_params->style_append && !(m->flags() & IOP_FLAGS_ONE_INSTANCE)) + || m->multi_priority != s->multi_priority) { // dt_dev_module_duplicate() doesn't work here, it's trying too hard to be clever style_module = (dt_iop_module_t *)calloc(1, sizeof(dt_iop_module_t)); @@ -890,7 +885,7 @@ int dt_imageio_export_with_flags(const uint32_t imgid, const char *filename, } if(!thumbnail_export && strcmp(format->mime(format_params), "memory") - && !(format->flags(format_params) & FORMAT_FLAGS_NO_TMPFILE)) + && !(format->flags(format_params) & FORMAT_FLAGS_NO_TMPFILE)) { dt_control_signal_raise(darktable.signals, DT_SIGNAL_IMAGE_EXPORT_TMPFILE, imgid, filename, format, format_params, storage, storage_params); @@ -909,8 +904,7 @@ int dt_imageio_export_with_flags(const uint32_t imgid, const char *filename, // fallback read method in case file could not be opened yet. // use GraphicsMagick (if supported) to read exotic LDRs -dt_imageio_retval_t dt_imageio_open_exotic(dt_image_t *img, const char *filename, - dt_mipmap_buffer_t *buf) +dt_imageio_retval_t dt_imageio_open_exotic(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *buf) { #ifdef HAVE_GRAPHICSMAGICK dt_imageio_retval_t ret = dt_imageio_open_gm(img, filename, buf); @@ -933,8 +927,8 @@ dt_imageio_retval_t dt_imageio_open_exotic(dt_image_t *img, const char *filename // combined reading // ================================================= -dt_imageio_retval_t dt_imageio_open(dt_image_t *img, // non-const * means you hold a write lock! - const char *filename, // full path +dt_imageio_retval_t dt_imageio_open(dt_image_t *img, // non-const * means you hold a write lock! + const char *filename, // full path dt_mipmap_buffer_t *buf) { /* first of all, check if file exists, don't bother to test loading if not exists */ @@ -949,7 +943,7 @@ dt_imageio_retval_t dt_imageio_open(dt_image_t *img, // non-const /* silly check using file extensions: */ if(ret != DT_IMAGEIO_OK && ret != DT_IMAGEIO_CACHE_FULL && dt_imageio_is_hdr(filename)) ret = dt_imageio_open_hdr(img, filename, buf); - + /* use rawspeed to load the raw */ if(ret != DT_IMAGEIO_OK && ret != DT_IMAGEIO_CACHE_FULL) { @@ -958,8 +952,7 @@ dt_imageio_retval_t dt_imageio_open(dt_image_t *img, // non-const } /* fallback that tries to open file via GraphicsMagick */ - if(ret != DT_IMAGEIO_OK && ret != DT_IMAGEIO_CACHE_FULL) - ret = dt_imageio_open_exotic(img, filename, buf); + if(ret != DT_IMAGEIO_OK && ret != DT_IMAGEIO_CACHE_FULL) ret = dt_imageio_open_exotic(img, filename, buf); return ret; } diff --git a/src/common/imageio.h b/src/common/imageio.h index d4d41dfe85c3..f62ff364a94b 100644 --- a/src/common/imageio.h +++ b/src/common/imageio.h @@ -60,28 +60,28 @@ dt_imageio_retval_t dt_imageio_open_ldr(dt_image_t *img, const char *filename, d // try all the options in sequence dt_imageio_retval_t dt_imageio_open(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *buf); // tries to open the files not opened by the other routines using GraphicsMagick (if supported) -dt_imageio_retval_t dt_imageio_open_exotic(dt_image_t *img, const char *filename, - dt_mipmap_buffer_t *buf); +dt_imageio_retval_t dt_imageio_open_exotic(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *buf); struct dt_imageio_module_format_t; struct dt_imageio_module_data_t; int dt_imageio_export(const uint32_t imgid, const char *filename, struct dt_imageio_module_format_t *format, - struct dt_imageio_module_data_t *format_params, const gboolean high_quality, const gboolean upscale, - const gboolean copy_metadata, dt_colorspaces_color_profile_type_t icc_type, - const gchar *icc_filename, dt_iop_color_intent_t icc_intent, dt_imageio_module_storage_t *storage, + struct dt_imageio_module_data_t *format_params, const gboolean high_quality, + const gboolean upscale, const gboolean copy_metadata, + dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename, + dt_iop_color_intent_t icc_intent, dt_imageio_module_storage_t *storage, dt_imageio_module_data_t *storage_params, int num, int total); int dt_imageio_export_with_flags(const uint32_t imgid, const char *filename, struct dt_imageio_module_format_t *format, struct dt_imageio_module_data_t *format_params, const int32_t ignore_exif, - const int32_t display_byteorder, const gboolean high_quality, const gboolean upscale, - const int32_t thumbnail_export, const char *filter, const gboolean copy_metadata, - dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename, - dt_iop_color_intent_t icc_intent, dt_imageio_module_storage_t *storage, - dt_imageio_module_data_t *storage_params, int num, int total); + const int32_t display_byteorder, const gboolean high_quality, + const gboolean upscale, const int32_t thumbnail_export, const char *filter, + const gboolean copy_metadata, dt_colorspaces_color_profile_type_t icc_type, + const gchar *icc_filename, dt_iop_color_intent_t icc_intent, + dt_imageio_module_storage_t *storage, dt_imageio_module_data_t *storage_params, + int num, int total); -size_t dt_imageio_write_pos(int i, int j, int wd, int ht, float fwd, float fht, - dt_image_orientation_t orientation); +size_t dt_imageio_write_pos(int i, int j, int wd, int ht, float fwd, float fht, dt_image_orientation_t orientation); // general, efficient buffer flipping function using memcopies void dt_imageio_flip_buffers(char *out, const char *in, @@ -89,14 +89,12 @@ void dt_imageio_flip_buffers(char *out, const char *in, const int wd, const int ht, const int fwd, const int fht, const int stride, const dt_image_orientation_t orientation); -void dt_imageio_flip_buffers_ui16_to_float(float *out, const uint16_t *in, const float black, - const float white, const int ch, const int wd, const int ht, - const int fwd, const int fht, const int stride, - const dt_image_orientation_t orientation); +void dt_imageio_flip_buffers_ui16_to_float(float *out, const uint16_t *in, const float black, const float white, + const int ch, const int wd, const int ht, const int fwd, const int fht, + const int stride, const dt_image_orientation_t orientation); void dt_imageio_flip_buffers_ui8_to_float(float *out, const uint8_t *in, const float black, const float white, - const int ch, const int wd, const int ht, const int fwd, - const int fht, const int stride, - const dt_image_orientation_t orientation); + const int ch, const int wd, const int ht, const int fwd, const int fht, + const int stride, const dt_image_orientation_t orientation); // allocate buffer and return 0 on success along with largest jpg thumbnail from raw. int dt_imageio_large_thumbnail(const char *filename, uint8_t **buffer, int32_t *width, int32_t *height, diff --git a/src/common/imageio_dng.h b/src/common/imageio_dng.h index a05fddaed4c6..595b2a701956 100644 --- a/src/common/imageio_dng.h +++ b/src/common/imageio_dng.h @@ -45,9 +45,8 @@ static inline void dt_imageio_dng_write_buf(uint8_t *buf, int adr, int val) buf[adr] = val >> 24; } -static inline uint8_t *dt_imageio_dng_make_tag( - uint16_t tag, uint16_t type, uint32_t lng, uint32_t fld, - uint8_t *b, uint8_t *cnt) +static inline uint8_t *dt_imageio_dng_make_tag(uint16_t tag, uint16_t type, uint32_t lng, uint32_t fld, uint8_t *b, + uint8_t *cnt) { dt_imageio_dng_write_buf(b, 0, (tag << 16) | type); dt_imageio_dng_write_buf(b, 4, lng); @@ -71,11 +70,9 @@ static inline void dt_imageio_dng_convert_rational(float f, int32_t *num, int32_ *num *= sign; } -static inline void dt_imageio_dng_write_tiff_header( - FILE *fp, uint32_t xs, uint32_t ys, float Tv, float Av, - float f, float iso, uint32_t filter, - const uint8_t xtrans[6][6], - const float whitelevel) +static inline void dt_imageio_dng_write_tiff_header(FILE *fp, uint32_t xs, uint32_t ys, float Tv, float Av, + float f, float iso, uint32_t filter, + const uint8_t xtrans[6][6], const float whitelevel) { const uint32_t channels = 1; uint8_t *b /*, *offs1, *offs2*/; @@ -100,7 +97,7 @@ static inline void dt_imageio_dng_write_tiff_header( // buf[507] = buf[509] = buf[511] = 32; b = dt_imageio_dng_make_tag(259, SHORT, 1, (1 << 16), b, &cnt); /* Compression. */ b = dt_imageio_dng_make_tag(262, SHORT, 1, 32803 << 16, b, &cnt); - /* cfa */ // 34892, b, &cnt ); // linear raw /* Photo interp. */ + /* cfa */ // 34892, b, &cnt ); // linear raw /* Photo interp. */ // b = dt_imageio_dng_make_tag( 271, ASCII, 8, 494, b, &cnt); // maker, needed for dcraw // b = dt_imageio_dng_make_tag( 272, ASCII, 9, 484, b, &cnt); // model // offs2 = b + 8; @@ -111,10 +108,9 @@ static inline void dt_imageio_dng_write_tiff_header( b = dt_imageio_dng_make_tag(279, LONG, 1, (ys * xs * channels * 4), b, &cnt); // 32 bits/channel /* Strip byte count. */ b = dt_imageio_dng_make_tag(284, SHORT, 1, (1 << 16), b, &cnt); /* Planar configuration. */ - b = dt_imageio_dng_make_tag(339, SHORT, 1, (3 << 16), b, - &cnt); /* SampleFormat = 3 => ieee floating point */ + b = dt_imageio_dng_make_tag(339, SHORT, 1, (3 << 16), b, &cnt); /* SampleFormat = 3 => ieee floating point */ - if(filter == 9u) // xtrans + if(filter == 9u) // xtrans b = dt_imageio_dng_make_tag(33421, SHORT, 2, (6 << 16) | 6, b, &cnt); /* CFAREPEATEDPATTERNDIM */ else b = dt_imageio_dng_make_tag(33421, SHORT, 2, (2 << 16) | 2, b, &cnt); /* CFAREPEATEDPATTERNDIM */ @@ -135,9 +131,9 @@ static inline void dt_imageio_dng_write_tiff_header( cfapattern = (2 << 24) | (1 << 16) | (1 << 8) | 0; // bggr break; } - if(filter == 9u) // xtrans - b = dt_imageio_dng_make_tag(33422, BYTE, 36, 240, b, &cnt); /* CFAPATTERN */ - else // bayer + if(filter == 9u) // xtrans + b = dt_imageio_dng_make_tag(33422, BYTE, 36, 240, b, &cnt); /* CFAPATTERN */ + else // bayer b = dt_imageio_dng_make_tag(33422, BYTE, 4, cfapattern, b, &cnt); /* CFAPATTERN */ // b = dt_imageio_dng_make_tag( 306, ASCII, 20, 428, b, &cnt ); // DateTime @@ -152,12 +148,12 @@ static inline void dt_imageio_dng_write_tiff_header( // b = dt_imageio_dng_make_tag(50728, RATIONAL, 3, 512, b, &cnt); // AsShotNeutral // b = dt_imageio_dng_make_tag(50729, RATIONAL, 2, 512, b, &cnt); // AsShotWhiteXY b = dt_imageio_dng_make_tag(0, 0, 0, 0, b, &cnt); /* Next IFD. */ - buf[11] = cnt - 1; // write number of directory entries of this ifd + buf[11] = cnt - 1; // write number of directory entries of this ifd // exif is written later, by exiv2: // printf("offset: %d\n", b - buf); // find out where we're writing data // apparently this doesn't need byteswap: - memcpy(buf+240, xtrans, sizeof(uint8_t)*36); + memcpy(buf + 240, xtrans, sizeof(uint8_t) * 36); #if 0 // mostly garbage below, but i'm too lazy to clean it up: @@ -209,17 +205,16 @@ static inline void dt_imageio_dng_write_tiff_header( if(written != 584) fprintf(stderr, "[dng_write_header] failed to write image header!\n"); } -static inline void dt_imageio_write_dng( - const char *filename, const float *const pixel, const int wd, - const int ht, void *exif, const int exif_len, const uint32_t filter, - const uint8_t xtrans[6][6], - const float whitelevel) +static inline void dt_imageio_write_dng(const char *filename, const float *const pixel, const int wd, const int ht, + void *exif, const int exif_len, const uint32_t filter, + const uint8_t xtrans[6][6], const float whitelevel) { FILE *f = g_fopen(filename, "wb"); int k = 0; if(f) { - dt_imageio_dng_write_tiff_header(f, wd, ht, 1.0f / 100.0f, 1.0f / 4.0f, 50.0f, 100.0f, filter, xtrans, whitelevel); + dt_imageio_dng_write_tiff_header(f, wd, ht, 1.0f / 100.0f, 1.0f / 4.0f, 50.0f, 100.0f, filter, xtrans, + whitelevel); k = fwrite(pixel, sizeof(float), wd * ht, f); if(k != wd * ht) fprintf(stderr, "[dng_write] Error writing image data to %s\n", filename); fclose(f); diff --git a/src/common/imageio_exr.cc b/src/common/imageio_exr.cc index 23b842429e7a..29c2b7592818 100644 --- a/src/common/imageio_exr.cc +++ b/src/common/imageio_exr.cc @@ -155,18 +155,16 @@ dt_imageio_retval_t dt_imageio_open_exr(dt_image_t *img, const char *filename, d Imf::Chromaticities chromaticities; float whiteLuminance = 1.0; - if(Imf::hasChromaticities(header)) - chromaticities = Imf::chromaticities(header); - - if(Imf::hasWhiteLuminance(header)) - whiteLuminance = Imf::whiteLuminance(header); - -// printf("hasChromaticities: %d\n", Imf::hasChromaticities(header)); -// printf("hasWhiteLuminance: %d\n", Imf::hasWhiteLuminance(header)); -// std::cout << chromaticities.red << std::endl; -// std::cout << chromaticities.green << std::endl; -// std::cout << chromaticities.blue << std::endl; -// std::cout << chromaticities.white << std::endl; + if(Imf::hasChromaticities(header)) chromaticities = Imf::chromaticities(header); + + if(Imf::hasWhiteLuminance(header)) whiteLuminance = Imf::whiteLuminance(header); + + // printf("hasChromaticities: %d\n", Imf::hasChromaticities(header)); + // printf("hasWhiteLuminance: %d\n", Imf::hasWhiteLuminance(header)); + // std::cout << chromaticities.red << std::endl; + // std::cout << chromaticities.green << std::endl; + // std::cout << chromaticities.blue << std::endl; + // std::cout << chromaticities.white << std::endl; Imath::M44f m = Imf::RGBtoXYZ(chromaticities, whiteLuminance); float mat[3][3]; diff --git a/src/common/imageio_gm.h b/src/common/imageio_gm.h index ee7709216132..160b6ee7a34e 100644 --- a/src/common/imageio_gm.h +++ b/src/common/imageio_gm.h @@ -24,8 +24,7 @@ #ifdef HAVE_GRAPHICSMAGICK dt_imageio_retval_t dt_imageio_open_gm(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *buf); #else -inline dt_imageio_retval_t dt_imageio_open_gm(dt_image_t *img, const char *filename, - dt_mipmap_buffer_t *buf) +inline dt_imageio_retval_t dt_imageio_open_gm(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *buf) { return DT_IMAGEIO_FILE_NOT_FOUND; } diff --git a/src/common/imageio_j2k.c b/src/common/imageio_j2k.c index 2868168496dc..9f39e7e79249 100644 --- a/src/common/imageio_j2k.c +++ b/src/common/imageio_j2k.c @@ -249,8 +249,7 @@ dt_imageio_retval_t dt_imageio_open_j2k(dt_image_t *img, const char *filename, d } if(image->comps[i].prec > 16) { - fprintf(stderr, "[j2k_open] Error: precision %d is larger than 16 in `%s'\n", image->comps[1].prec, - filename); + fprintf(stderr, "[j2k_open] Error: precision %d is larger than 16 in `%s'\n", image->comps[1].prec, filename); ret = DT_IMAGEIO_FILE_CORRUPTED; goto end_of_the_world; } @@ -679,15 +678,13 @@ static void color_sycc_to_rgb(opj_image_t *img) { sycc420_to_rgb(img); } - else if((img->comps[0].dx == 1) && (img->comps[1].dx == 2) && (img->comps[2].dx == 2) - && (img->comps[0].dy == 1) && (img->comps[1].dy == 1) - && (img->comps[2].dy == 1)) /* horizontal sub-sample only */ + else if((img->comps[0].dx == 1) && (img->comps[1].dx == 2) && (img->comps[2].dx == 2) && (img->comps[0].dy == 1) + && (img->comps[1].dy == 1) && (img->comps[2].dy == 1)) /* horizontal sub-sample only */ { sycc422_to_rgb(img); } - else if((img->comps[0].dx == 1) && (img->comps[1].dx == 1) && (img->comps[2].dx == 1) - && (img->comps[0].dy == 1) && (img->comps[1].dy == 1) - && (img->comps[2].dy == 1)) /* no sub-sample */ + else if((img->comps[0].dx == 1) && (img->comps[1].dx == 1) && (img->comps[2].dx == 1) && (img->comps[0].dy == 1) + && (img->comps[1].dy == 1) && (img->comps[2].dy == 1)) /* no sub-sample */ { sycc444_to_rgb(img); } diff --git a/src/common/imageio_jpeg.c b/src/common/imageio_jpeg.c index e7efbae3d8b0..04fff783c356 100644 --- a/src/common/imageio_jpeg.c +++ b/src/common/imageio_jpeg.c @@ -260,8 +260,7 @@ int dt_imageio_jpeg_decompress(dt_imageio_jpeg_t *jpg, uint8_t *out) return 0; } -int dt_imageio_jpeg_compress(const uint8_t *in, uint8_t *out, const int width, const int height, - const int quality) +int dt_imageio_jpeg_compress(const uint8_t *in, uint8_t *out, const int width, const int height, const int quality) { struct dt_imageio_jpeg_error_mgr jerr; dt_imageio_jpeg_t jpg; @@ -374,8 +373,7 @@ static void write_icc_profile(j_compress_ptr cinfo, const JOCTET *icc_data_ptr, static boolean marker_is_icc(jpeg_saved_marker_ptr marker) { - return marker->marker == ICC_MARKER && marker->data_length >= ICC_OVERHEAD_LEN - && + return marker->marker == ICC_MARKER && marker->data_length >= ICC_OVERHEAD_LEN && /* verify the identifying string */ GETJOCTET(marker->data[0]) == 0x49 && GETJOCTET(marker->data[1]) == 0x43 && GETJOCTET(marker->data[2]) == 0x43 && GETJOCTET(marker->data[3]) == 0x5F @@ -726,8 +724,7 @@ dt_imageio_retval_t dt_imageio_open_jpeg(dt_image_t *img, const char *filename, { const char *ext = filename + strlen(filename); while(*ext != '.' && ext > filename) ext--; - if(strncmp(ext, ".jpg", 4) && strncmp(ext, ".JPG", 4) && strncmp(ext, ".jpeg", 5) - && strncmp(ext, ".JPEG", 5)) + if(strncmp(ext, ".jpg", 4) && strncmp(ext, ".JPG", 4) && strncmp(ext, ".jpeg", 5) && strncmp(ext, ".JPEG", 5)) return DT_IMAGEIO_FILE_CORRUPTED; if(!img->exif_inited) (void)dt_exif_read(img, filename); diff --git a/src/common/imageio_jpeg.h b/src/common/imageio_jpeg.h index 756de526ad08..4d1552b3c369 100644 --- a/src/common/imageio_jpeg.h +++ b/src/common/imageio_jpeg.h @@ -48,8 +48,7 @@ int dt_imageio_jpeg_decompress_header(const void *in, size_t length, dt_imageio_ int dt_imageio_jpeg_decompress(dt_imageio_jpeg_t *jpg, uint8_t *out); /** compresses in to out buffer with given quality (0..100). out buffer must be large enough. returns actual * data length. */ -int dt_imageio_jpeg_compress(const uint8_t *in, uint8_t *out, const int width, const int height, - const int quality); +int dt_imageio_jpeg_compress(const uint8_t *in, uint8_t *out, const int width, const int height, const int quality); /** write jpeg to file, with exif if not NULL. */ int dt_imageio_jpeg_write(const char *filename, const uint8_t *in, const int width, const int height, @@ -64,7 +63,8 @@ int dt_imageio_jpeg_read_header(const char *filename, dt_imageio_jpeg_t *jpg); int dt_imageio_jpeg_read(dt_imageio_jpeg_t *jpg, uint8_t *out); /** reads the color profile attached to the jpeg, closes file. */ int dt_imageio_jpeg_read_profile(dt_imageio_jpeg_t *jpg, uint8_t **out); -/** return the color space of the image, this only distinguishs between sRGB, AdobeRGB and unknown. used for mipmaps */ +/** return the color space of the image, this only distinguishs between sRGB, AdobeRGB and unknown. used for + * mipmaps */ dt_colorspaces_color_profile_type_t dt_imageio_jpeg_read_color_space(dt_imageio_jpeg_t *jpg); /** utility function to read and open jpeg from imagio.c */ diff --git a/src/common/imageio_module.c b/src/common/imageio_module.c index 9a14f22cae33..7b94ac91072c 100644 --- a/src/common/imageio_module.c +++ b/src/common/imageio_module.c @@ -76,11 +76,10 @@ static int dt_imageio_load_module_format(dt_imageio_module_format_t *module, con if(!g_module_symbol(module->module, "dt_module_dt_version", (gpointer) & (version))) goto error; if(version() != dt_version()) { - fprintf( - stderr, - "[imageio_load_module] `%s' is compiled for another version of dt (module %d (%s) != dt %d (%s)) !\n", - libname, abs(version()), version() < 0 ? "debug" : "opt", abs(dt_version()), - dt_version() < 0 ? "debug" : "opt"); + fprintf(stderr, + "[imageio_load_module] `%s' is compiled for another version of dt (module %d (%s) != dt %d (%s)) !\n", + libname, abs(version()), version() < 0 ? "debug" : "opt", abs(dt_version()), + dt_version() < 0 ? "debug" : "opt"); goto error; } if(!g_module_symbol(module->module, "dt_module_mod_version", (gpointer) & (module->version))) goto error; @@ -114,16 +113,13 @@ static int dt_imageio_load_module_format(dt_imageio_module_format_t *module, con module->flags = _default_format_flags; if(!g_module_symbol(module->module, "levels", (gpointer) & (module->levels))) module->levels = _default_format_levels; - if(!g_module_symbol(module->module, "read_image", (gpointer) & (module->read_image))) - module->read_image = NULL; + if(!g_module_symbol(module->module, "read_image", (gpointer) & (module->read_image))) module->read_image = NULL; #ifdef USE_LUA { char pseudo_type_name[1024]; - snprintf(pseudo_type_name, sizeof(pseudo_type_name), "dt_imageio_module_format_data_%s", - module->plugin_name); - luaA_Type my_type - = luaA_type_add(darktable.lua_state.state, pseudo_type_name, module->params_size(module)); + snprintf(pseudo_type_name, sizeof(pseudo_type_name), "dt_imageio_module_format_data_%s", module->plugin_name); + luaA_Type my_type = luaA_type_add(darktable.lua_state.state, pseudo_type_name, module->params_size(module)); module->parameter_lua_type = dt_lua_init_type_type(darktable.lua_state.state, my_type); luaA_struct_type(darktable.lua_state.state, my_type); dt_lua_register_format_type(darktable.lua_state.state, module, my_type); @@ -182,8 +178,7 @@ static int dt_imageio_load_modules_format(dt_imageio_t *iio) } /** Default implementation of supported function, used if storage modules not implements supported() */ -static int _default_supported(struct dt_imageio_module_storage_t *self, - struct dt_imageio_module_format_t *format) +static int _default_supported(struct dt_imageio_module_storage_t *self, struct dt_imageio_module_format_t *format) { return 1; } @@ -212,11 +207,10 @@ static int dt_imageio_load_module_storage(dt_imageio_module_storage_t *module, c if(!g_module_symbol(module->module, "dt_module_dt_version", (gpointer) & (version))) goto error; if(version() != dt_version()) { - fprintf( - stderr, - "[imageio_load_module] `%s' is compiled for another version of dt (module %d (%s) != dt %d (%s)) !\n", - libname, abs(version()), version() < 0 ? "debug" : "opt", abs(dt_version()), - dt_version() < 0 ? "debug" : "opt"); + fprintf(stderr, + "[imageio_load_module] `%s' is compiled for another version of dt (module %d (%s) != dt %d (%s)) !\n", + libname, abs(version()), version() < 0 ? "debug" : "opt", abs(dt_version()), + dt_version() < 0 ? "debug" : "opt"); goto error; } if(!g_module_symbol(module->module, "dt_module_mod_version", (gpointer) & (module->version))) goto error; @@ -256,10 +250,8 @@ static int dt_imageio_load_module_storage(dt_imageio_module_storage_t *module, c #ifdef USE_LUA { char pseudo_type_name[1024]; - snprintf(pseudo_type_name, sizeof(pseudo_type_name), "dt_imageio_module_storage_data_%s", - module->plugin_name); - luaA_Type my_type - = luaA_type_add(darktable.lua_state.state, pseudo_type_name, module->params_size(module)); + snprintf(pseudo_type_name, sizeof(pseudo_type_name), "dt_imageio_module_storage_data_%s", module->plugin_name); + luaA_Type my_type = luaA_type_add(darktable.lua_state.state, pseudo_type_name, module->params_size(module)); module->parameter_lua_type = dt_lua_init_type_type(darktable.lua_state.state, my_type); luaA_struct_type(darktable.lua_state.state, my_type); dt_lua_register_storage_type(darktable.lua_state.state, module, my_type); diff --git a/src/common/imageio_module.h b/src/common/imageio_module.h index ce2141e44fd9..92e72e5b81f0 100644 --- a/src/common/imageio_module.h +++ b/src/common/imageio_module.h @@ -109,7 +109,8 @@ typedef struct dt_imageio_module_format_t /* this extension (plus dot) is appended to the exported filename. */ const char *(*extension)(dt_imageio_module_data_t *data); /* get storage max supported image dimension, return 0 if no dimension restrictions exists. */ - int (*dimension)(struct dt_imageio_module_format_t *self, dt_imageio_module_data_t *data, uint32_t *width, uint32_t *height); + int (*dimension)(struct dt_imageio_module_format_t *self, dt_imageio_module_data_t *data, uint32_t *width, + uint32_t *height); // writing functions: /* bits per pixel and color channel we want to write: 8: char x3, 16: uint16_t x3, 32: float x3. */ @@ -160,20 +161,22 @@ typedef struct dt_imageio_module_storage_t /* try and see if this format is supported? */ int (*supported)(struct dt_imageio_module_storage_t *self, struct dt_imageio_module_format_t *format); /* get storage max supported image dimension, return 0 if no dimension restrictions exists. */ - int (*dimension)(struct dt_imageio_module_storage_t *self, dt_imageio_module_data_t *data, uint32_t *width, uint32_t *height); + int (*dimension)(struct dt_imageio_module_storage_t *self, dt_imageio_module_data_t *data, uint32_t *width, + uint32_t *height); /* get storage recommended image dimension, return 0 if no recommendation exists. */ - int (*recommended_dimension)(struct dt_imageio_module_storage_t *self, dt_imageio_module_data_t *data, uint32_t *width, uint32_t *height); + int (*recommended_dimension)(struct dt_imageio_module_storage_t *self, dt_imageio_module_data_t *data, + uint32_t *width, uint32_t *height); /* called once at the beginning (before exporting image), if implemented * can change the list of exported images (including a NULL list) */ int (*initialize_store)(struct dt_imageio_module_storage_t *self, dt_imageio_module_data_t *data, - dt_imageio_module_format_t **format, dt_imageio_module_data_t **fdata, - GList **images, const gboolean high_quality, const gboolean upscale); + dt_imageio_module_format_t **format, dt_imageio_module_data_t **fdata, GList **images, + const gboolean high_quality, const gboolean upscale); /* this actually does the work */ int (*store)(struct dt_imageio_module_storage_t *self, struct dt_imageio_module_data_t *self_data, - const int imgid, dt_imageio_module_format_t *format, dt_imageio_module_data_t *fdata, - const int num, const int total, const gboolean high_quality, const gboolean upscale, + const int imgid, dt_imageio_module_format_t *format, dt_imageio_module_data_t *fdata, const int num, + const int total, const gboolean high_quality, const gboolean upscale, dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename, dt_iop_color_intent_t icc_intent); /* called once at the end (after exporting all images), if implemented. */ diff --git a/src/common/imageio_pfm.c b/src/common/imageio_pfm.c index ba3f792cc52c..a2af7fe13b3a 100644 --- a/src/common/imageio_pfm.c +++ b/src/common/imageio_pfm.c @@ -67,7 +67,11 @@ dt_imageio_retval_t dt_imageio_open_pfm(dt_image_t *img, const char *filename, d for(size_t i = (size_t)img->width * img->height; i > 0; i--) for(int c = 0; c < 3; c++) { - union { float f; guint32 i; } v; + union + { + float f; + guint32 i; + } v; v.f = buf[3 * (i - 1) + c]; if(swap_byte_order) v.i = GUINT32_SWAP_LE_BE(v.i); buf[4 * (i - 1) + c] = v.f; @@ -77,18 +81,21 @@ dt_imageio_retval_t dt_imageio_open_pfm(dt_image_t *img, const char *filename, d for(size_t j = 0; j < img->height; j++) for(size_t i = 0; i < img->width; i++) { - union { float f; guint32 i; } v; + union + { + float f; + guint32 i; + } v; ret = fread(&v.f, sizeof(float), 1, f); if(swap_byte_order) v.i = GUINT32_SWAP_LE_BE(v.i); - buf[4 * (img->width * j + i) + 2] = buf[4 * (img->width * j + i) + 1] - = buf[4 * (img->width * j + i) + 0] = v.f; + buf[4 * (img->width * j + i) + 2] = buf[4 * (img->width * j + i) + 1] = buf[4 * (img->width * j + i) + 0] + = v.f; } float *line = (float *)calloc(4 * img->width, sizeof(float)); for(size_t j = 0; j < img->height / 2; j++) { memcpy(line, buf + img->width * j * 4, 4 * sizeof(float) * img->width); - memcpy(buf + img->width * j * 4, buf + img->width * (img->height - 1 - j) * 4, - 4 * sizeof(float) * img->width); + memcpy(buf + img->width * j * 4, buf + img->width * (img->height - 1 - j) * 4, 4 * sizeof(float) * img->width); memcpy(buf + img->width * (img->height - 1 - j) * 4, line, 4 * sizeof(float) * img->width); } free(line); diff --git a/src/common/imageio_rawspeed.cc b/src/common/imageio_rawspeed.cc index 0b6ad5ad679a..a560142a11ff 100644 --- a/src/common/imageio_rawspeed.cc +++ b/src/common/imageio_rawspeed.cc @@ -48,10 +48,11 @@ int rawspeed_get_number_of_processor_cores() using namespace rawspeed; -static dt_imageio_retval_t dt_imageio_open_rawspeed_sraw (dt_image_t *img, RawImage r, dt_mipmap_buffer_t *buf); +static dt_imageio_retval_t dt_imageio_open_rawspeed_sraw(dt_image_t *img, RawImage r, dt_mipmap_buffer_t *buf); static CameraMetaData *meta = NULL; -static void dt_rawspeed_load_meta() { +static void dt_rawspeed_load_meta() +{ /* Load rawspeed cameras.xml meta file once */ if(meta == NULL) { @@ -68,18 +69,17 @@ static void dt_rawspeed_load_meta() { } } -void dt_rawspeed_lookup_makermodel(const char *maker, const char *model, - char *mk, int mk_len, char *md, int md_len, - char *al, int al_len) +void dt_rawspeed_lookup_makermodel(const char *maker, const char *model, char *mk, int mk_len, char *md, + int md_len, char *al, int al_len) { int got_it_done = FALSE; - try { + try + { dt_rawspeed_load_meta(); const Camera *cam = meta->getCamera(maker, model, ""); // Also look for dng cameras - if (!cam) - cam = meta->getCamera(maker, model, "dng"); - if (cam) + if(!cam) cam = meta->getCamera(maker, model, "dng"); + if(cam) { g_strlcpy(mk, cam->canonical_make.c_str(), mk_len); g_strlcpy(md, cam->canonical_model.c_str(), md_len); @@ -92,7 +92,7 @@ void dt_rawspeed_lookup_makermodel(const char *maker, const char *model, printf("[rawspeed] %s\n", exc.what()); } - if (!got_it_done) + if(!got_it_done) { // We couldn't find the camera or caught some exception, just punt and pass // through the same values @@ -109,8 +109,7 @@ uint32_t dt_rawspeed_crop_dcraw_filters(uint32_t filters, uint32_t crop_x, uint3 return ColorFilterArray::shiftDcrawFilter(filters, crop_x, crop_y); } -dt_imageio_retval_t dt_imageio_open_rawspeed(dt_image_t *img, const char *filename, - dt_mipmap_buffer_t *mbuf) +dt_imageio_retval_t dt_imageio_open_rawspeed(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *mbuf) { if(!img->exif_inited) (void)dt_exif_read(img, filename); @@ -148,43 +147,46 @@ dt_imageio_retval_t dt_imageio_open_rawspeed(dt_image_t *img, const char *filena // We used to partial match the Canon local rebrandings so lets pass on // the value just in those cases to be able to fix old history stacks - static const struct { + static const struct + { const char *mungedname; const char *origname; } legacy_aliases[] = { - {"Canon EOS","Canon EOS REBEL SL1"}, - {"Canon EOS","Canon EOS Kiss X7"}, - {"Canon EOS","Canon EOS DIGITAL REBEL XT"}, - {"Canon EOS","Canon EOS Kiss Digital N"}, - {"Canon EOS","Canon EOS 350D"}, - {"Canon EOS","Canon EOS DIGITAL REBEL XSi"}, - {"Canon EOS","Canon EOS Kiss Digital X2"}, - {"Canon EOS","Canon EOS Kiss X2"}, - {"Canon EOS","Canon EOS REBEL T5i"}, - {"Canon EOS","Canon EOS Kiss X7i"}, - {"Canon EOS","Canon EOS Rebel T6i"}, - {"Canon EOS","Canon EOS Kiss X8i"}, - {"Canon EOS","Canon EOS Rebel T6s"}, - {"Canon EOS","Canon EOS 8000D"}, - {"Canon EOS","Canon EOS REBEL T1i"}, - {"Canon EOS","Canon EOS Kiss X3"}, - {"Canon EOS","Canon EOS REBEL T2i"}, - {"Canon EOS","Canon EOS Kiss X4"}, - {"Canon EOS REBEL T3","Canon EOS REBEL T3i"}, - {"Canon EOS","Canon EOS Kiss X5"}, - {"Canon EOS","Canon EOS REBEL T4i"}, - {"Canon EOS","Canon EOS Kiss X6i"}, - {"Canon EOS","Canon EOS DIGITAL REBEL XS"}, - {"Canon EOS","Canon EOS Kiss Digital F"}, - {"Canon EOS","Canon EOS REBEL T5"}, - {"Canon EOS","Canon EOS Kiss X70"}, - {"Canon EOS","Canon EOS DIGITAL REBEL XTi"}, - {"Canon EOS","Canon EOS Kiss Digital X"}, + { "Canon EOS", "Canon EOS REBEL SL1" }, + { "Canon EOS", "Canon EOS Kiss X7" }, + { "Canon EOS", "Canon EOS DIGITAL REBEL XT" }, + { "Canon EOS", "Canon EOS Kiss Digital N" }, + { "Canon EOS", "Canon EOS 350D" }, + { "Canon EOS", "Canon EOS DIGITAL REBEL XSi" }, + { "Canon EOS", "Canon EOS Kiss Digital X2" }, + { "Canon EOS", "Canon EOS Kiss X2" }, + { "Canon EOS", "Canon EOS REBEL T5i" }, + { "Canon EOS", "Canon EOS Kiss X7i" }, + { "Canon EOS", "Canon EOS Rebel T6i" }, + { "Canon EOS", "Canon EOS Kiss X8i" }, + { "Canon EOS", "Canon EOS Rebel T6s" }, + { "Canon EOS", "Canon EOS 8000D" }, + { "Canon EOS", "Canon EOS REBEL T1i" }, + { "Canon EOS", "Canon EOS Kiss X3" }, + { "Canon EOS", "Canon EOS REBEL T2i" }, + { "Canon EOS", "Canon EOS Kiss X4" }, + { "Canon EOS REBEL T3", "Canon EOS REBEL T3i" }, + { "Canon EOS", "Canon EOS Kiss X5" }, + { "Canon EOS", "Canon EOS REBEL T4i" }, + { "Canon EOS", "Canon EOS Kiss X6i" }, + { "Canon EOS", "Canon EOS DIGITAL REBEL XS" }, + { "Canon EOS", "Canon EOS Kiss Digital F" }, + { "Canon EOS", "Canon EOS REBEL T5" }, + { "Canon EOS", "Canon EOS Kiss X70" }, + { "Canon EOS", "Canon EOS DIGITAL REBEL XTi" }, + { "Canon EOS", "Canon EOS Kiss Digital X" }, }; - for (uint32 i=0; i<(sizeof(legacy_aliases)/sizeof(legacy_aliases[1])); i++) - if (!strcmp(legacy_aliases[i].origname, r->metadata.model.c_str())) { - g_strlcpy(img->camera_legacy_makermodel, legacy_aliases[i].mungedname, sizeof(img->camera_legacy_makermodel)); + for(uint32 i = 0; i < (sizeof(legacy_aliases) / sizeof(legacy_aliases[1])); i++) + if(!strcmp(legacy_aliases[i].origname, r->metadata.model.c_str())) + { + g_strlcpy(img->camera_legacy_makermodel, legacy_aliases[i].mungedname, + sizeof(img->camera_legacy_makermodel)); break; } @@ -387,7 +389,7 @@ dt_imageio_retval_t dt_imageio_open_rawspeed_sraw(dt_image_t *img, RawImage r, d #endif for(int j = 0; j < img->height; j++) { - const uint16_t *in = (uint16_t *) r->getData(0, j); + const uint16_t *in = (uint16_t *)r->getData(0, j); float *out = ((float *)buf) + (size_t)4 * j * img->width; for(int i = 0; i < img->width; i++, in += cpp, out += 4) @@ -411,7 +413,7 @@ dt_imageio_retval_t dt_imageio_open_rawspeed_sraw(dt_image_t *img, RawImage r, d #endif for(int j = 0; j < img->height; j++) { - const uint16_t *in = (uint16_t *) r->getData(0, j); + const uint16_t *in = (uint16_t *)r->getData(0, j); float *out = ((float *)buf) + (size_t)4 * j * img->width; for(int i = 0; i < img->width; i++, in += cpp, out += 4) diff --git a/src/common/imageio_rawspeed.h b/src/common/imageio_rawspeed.h index 9c8d7f67cac7..2dca8376427f 100644 --- a/src/common/imageio_rawspeed.h +++ b/src/common/imageio_rawspeed.h @@ -25,14 +25,12 @@ extern "C" { #include "common/image.h" #include "common/mipmap_cache.h" -void dt_rawspeed_lookup_makermodel(const char *maker, const char *model, - char *mk, int mk_len, char *md, int md_len, - char *al, int al_len); +void dt_rawspeed_lookup_makermodel(const char *maker, const char *model, char *mk, int mk_len, char *md, + int md_len, char *al, int al_len); uint32_t dt_rawspeed_crop_dcraw_filters(uint32_t filters, uint32_t crop_x, uint32_t crop_y); -dt_imageio_retval_t dt_imageio_open_rawspeed(dt_image_t *img, const char *filename, - dt_mipmap_buffer_t *buf); +dt_imageio_retval_t dt_imageio_open_rawspeed(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *buf); #ifdef __cplusplus } diff --git a/src/common/imageio_tiff.c b/src/common/imageio_tiff.c index a314e17326f1..0733dcd4edcf 100644 --- a/src/common/imageio_tiff.c +++ b/src/common/imageio_tiff.c @@ -138,7 +138,7 @@ static inline int _read_planar_f(tiff_t *t) return 1; } -static void _warning_handler(const char* module, const char* fmt, va_list ap) +static void _warning_handler(const char *module, const char *fmt, va_list ap) { fprintf(stderr, "[tiff_open] warning: %s: ", module); vfprintf(stderr, fmt, ap); @@ -153,8 +153,7 @@ dt_imageio_retval_t dt_imageio_open_tiff(dt_image_t *img, const char *filename, const char *ext = filename + strlen(filename); while(*ext != '.' && ext > filename) ext--; - if(strncmp(ext, ".tif", 4) && strncmp(ext, ".TIF", 4) && strncmp(ext, ".tiff", 5) - && strncmp(ext, ".TIFF", 5)) + if(strncmp(ext, ".tif", 4) && strncmp(ext, ".TIF", 4) && strncmp(ext, ".tiff", 5) && strncmp(ext, ".TIFF", 5)) return DT_IMAGEIO_FILE_CORRUPTED; if(!img->exif_inited) (void)dt_exif_read(img, filename); @@ -176,7 +175,8 @@ dt_imageio_retval_t dt_imageio_open_tiff(dt_image_t *img, const char *filename, t.scanlinesize = TIFFScanlineSize(t.tiff); - dt_print(DT_DEBUG_CAMERA_SUPPORT, "[tiff_open] %dx%d %dbpp, %d samples per pixel.\n", t.width, t.height, t.bpp, t.spp); + dt_print(DT_DEBUG_CAMERA_SUPPORT, "[tiff_open] %dx%d %dbpp, %d samples per pixel.\n", t.width, t.height, t.bpp, + t.spp); // we only support 8/16 and 32 bits per pixel formats. if(t.bpp != 8 && t.bpp != 16 && t.bpp != 32) diff --git a/src/common/import_session.c b/src/common/import_session.c index 79bf8b90420c..b1f02a393bbb 100644 --- a/src/common/import_session.c +++ b/src/common/import_session.c @@ -204,8 +204,7 @@ void dt_import_session_set_time(struct dt_import_session_t *self, time_t time) } -void -dt_import_session_set_exif_time(struct dt_import_session_t *self, time_t exif_time) +void dt_import_session_set_exif_time(struct dt_import_session_t *self, time_t exif_time) { dt_variables_set_exif_time(self->vp, exif_time); } @@ -268,8 +267,8 @@ const char *dt_import_session_filename(struct dt_import_session_t *self, gboolea { g_free(previous_fname); g_free(fname); - dt_control_log(_( - "couldn't expand to a unique filename for session, please check your import session settings.")); + dt_control_log( + _("couldn't expand to a unique filename for session, please check your import session settings.")); return NULL; } diff --git a/src/common/interpolation.c b/src/common/interpolation.c index a77aebfea629..9f982ff197c2 100644 --- a/src/common/interpolation.c +++ b/src/common/interpolation.c @@ -69,20 +69,20 @@ enum border_mode #endif #if DEBUG_PRINT_INFO -#define debug_info(...) \ - do \ - { \ - fprintf(stderr, __VA_ARGS__); \ +#define debug_info(...) \ + do \ + { \ + fprintf(stderr, __VA_ARGS__); \ } while(0) #else #define debug_info(...) #endif #if DEBUG_PRINT_VERBOSE -#define debug_extra(...) \ - do \ - { \ - fprintf(stderr, __VA_ARGS__); \ +#define debug_extra(...) \ + do \ + { \ + fprintf(stderr, __VA_ARGS__); \ } while(0) #else #define debug_extra(...) @@ -252,8 +252,7 @@ static inline float sinf_fast(float t) */ static inline __m128 sinf_fast_sse(__m128 t) { - static const __m128 a - = { 4.f / (M_PI * M_PI), 4.f / (M_PI * M_PI), 4.f / (M_PI * M_PI), 4.f / (M_PI * M_PI) }; + static const __m128 a = { 4.f / (M_PI * M_PI), 4.f / (M_PI * M_PI), 4.f / (M_PI * M_PI), 4.f / (M_PI * M_PI) }; static const __m128 p = { 0.225f, 0.225f, 0.225f, 0.225f }; static const __m128 pi = { M_PI, M_PI, M_PI, M_PI }; @@ -452,8 +451,7 @@ static inline __m128 lanczos_sse2(__m128 width, __m128 t) static const uint32_t fone[] __attribute__((aligned(SSE_ALIGNMENT))) = { 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000 }; static const uint32_t ione[] __attribute__((aligned(SSE_ALIGNMENT))) = { 1, 1, 1, 1 }; - static const __m128 eps - = { DT_LANCZOS_EPSILON, DT_LANCZOS_EPSILON, DT_LANCZOS_EPSILON, DT_LANCZOS_EPSILON }; + static const __m128 eps = { DT_LANCZOS_EPSILON, DT_LANCZOS_EPSILON, DT_LANCZOS_EPSILON, DT_LANCZOS_EPSILON }; static const __m128 pi = { M_PI, M_PI, M_PI, M_PI }; static const __m128 pi2 = { M_PI * M_PI, M_PI * M_PI, M_PI * M_PI, M_PI * M_PI }; @@ -531,8 +529,8 @@ static const struct dt_interpolation dt_interpolator[] = { * @param norm [out] Kernel norm * @param first [out] first input sample index used * @param t [in] Interpolated coordinate */ -static inline void compute_upsampling_kernel_plain(const struct dt_interpolation *itor, float *kernel, - float *norm, int *first, float t) +static inline void compute_upsampling_kernel_plain(const struct dt_interpolation *itor, float *kernel, float *norm, + int *first, float t) { int f = (int)t - itor->width + 1; if(first) @@ -573,8 +571,8 @@ static inline void compute_upsampling_kernel_plain(const struct dt_interpolation * * @return kernel norm */ -static inline void compute_upsampling_kernel_sse(const struct dt_interpolation *itor, float *kernel, - float *norm, int *first, float t) +static inline void compute_upsampling_kernel_sse(const struct dt_interpolation *itor, float *kernel, float *norm, + int *first, float t) { int f = (int)t - itor->width + 1; if(first) @@ -648,9 +646,8 @@ static inline void compute_upsampling_kernel(const struct dt_interpolation *itor * @param first [out] index of the first sample for which the kernel is to be applied * @param outoinratio [in] "out samples" over "in samples" ratio * @param xout [in] Output coordinate */ -static inline void compute_downsampling_kernel_plain(const struct dt_interpolation *itor, int *taps, - int *first, float *kernel, float *norm, - float outoinratio, int xout) +static inline void compute_downsampling_kernel_plain(const struct dt_interpolation *itor, int *taps, int *first, + float *kernel, float *norm, float outoinratio, int xout) { // Keep this at hand float w = (float)itor->width; @@ -777,8 +774,8 @@ static inline void compute_downsampling_kernel(const struct dt_interpolation *it #define MAX_KERNEL_REQ ((2 * (MAX_HALF_FILTER_WIDTH) + 3) & (~3)) float dt_interpolation_compute_sample(const struct dt_interpolation *itor, const float *in, const float x, - const float y, const int width, const int height, - const int samplestride, const int linestride) + const float y, const int width, const int height, const int samplestride, + const int linestride) { assert(itor->width < (MAX_HALF_FILTER_WIDTH + 1)); @@ -964,9 +961,9 @@ static void dt_interpolation_compute_pixel4c_plain(const struct dt_interpolation } #if defined(__SSE2__) -static void dt_interpolation_compute_pixel4c_sse(const struct dt_interpolation *itor, const float *in, - float *out, const float x, const float y, const int width, - const int height, const int linestride) +static void dt_interpolation_compute_pixel4c_sse(const struct dt_interpolation *itor, const float *in, float *out, + const float x, const float y, const int width, const int height, + const int linestride) { assert(itor->width < (MAX_HALF_FILTER_WIDTH + 1)); @@ -1170,8 +1167,8 @@ const struct dt_interpolation *dt_interpolation_new(enum dt_interpolation_type t * @return 0 for success, !0 for failure */ static int prepare_resampling_plan(const struct dt_interpolation *itor, int in, const int in_x0, int out, - const int out_x0, float scale, int **plength, float **pkernel, - int **pindex, int **pmeta) + const int out_x0, float scale, int **plength, float **pkernel, int **pindex, + int **pmeta) { // Safe return values *plength = NULL; @@ -1228,7 +1225,7 @@ static int prepare_resampling_plan(const struct dt_interpolation *itor, int in, float *scratchpad = scratchreq ? (float *)blob : NULL; blob = (char *)blob + scratchreq; int *meta = metareq ? (int *)blob : NULL; -// blob = (char *)blob + metareq; + // blob = (char *)blob + metareq; /* setting this as a const should help the compilers trim all unnecessary * codepaths */ @@ -1366,8 +1363,8 @@ static void dt_interpolation_resample_plain(const struct dt_interpolation *itor, int r; debug_info("resampling %p (%dx%d@%dx%d scale %f) -> %p (%dx%d@%dx%d scale %f)\n", in, roi_in->width, - roi_in->height, roi_in->x, roi_in->y, roi_in->scale, out, roi_out->width, roi_out->height, - roi_out->x, roi_out->y, roi_out->scale); + roi_in->height, roi_in->x, roi_in->y, roi_in->scale, out, roi_out->width, roi_out->height, roi_out->x, + roi_out->y, roi_out->scale); // Fast code path for 1:1 copy, only cropping area can change if(roi_out->scale == 1.f) @@ -1400,8 +1397,8 @@ static void dt_interpolation_resample_plain(const struct dt_interpolation *itor, #endif // Prepare resampling plans once and for all - r = prepare_resampling_plan(itor, roi_in->width, roi_in->x, roi_out->width, roi_out->x, roi_out->scale, - &hlength, &hkernel, &hindex, NULL); + r = prepare_resampling_plan(itor, roi_in->width, roi_in->x, roi_out->width, roi_out->x, roi_out->scale, &hlength, + &hkernel, &hindex, NULL); if(r) { goto exit; @@ -1524,8 +1521,8 @@ static void dt_interpolation_resample_sse(const struct dt_interpolation *itor, f int r; debug_info("resampling %p (%dx%d@%dx%d scale %f) -> %p (%dx%d@%dx%d scale %f)\n", in, roi_in->width, - roi_in->height, roi_in->x, roi_in->y, roi_in->scale, out, roi_out->width, roi_out->height, - roi_out->x, roi_out->y, roi_out->scale); + roi_in->height, roi_in->x, roi_in->y, roi_in->scale, out, roi_out->width, roi_out->height, roi_out->x, + roi_out->y, roi_out->scale); // Fast code path for 1:1 copy, only cropping area can change if(roi_out->scale == 1.f) @@ -1558,8 +1555,8 @@ static void dt_interpolation_resample_sse(const struct dt_interpolation *itor, f #endif // Prepare resampling plans once and for all - r = prepare_resampling_plan(itor, roi_in->width, roi_in->x, roi_out->width, roi_out->x, roi_out->scale, - &hlength, &hkernel, &hindex, NULL); + r = prepare_resampling_plan(itor, roi_in->width, roi_in->x, roi_out->width, roi_out->x, roi_out->scale, &hlength, + &hkernel, &hindex, NULL); if(r) { goto exit; @@ -1650,8 +1647,8 @@ static void dt_interpolation_resample_sse(const struct dt_interpolation *itor, f } // Progress in vertical context -// viidx += vl; -// vkidx += vl; + // viidx += vl; + // vkidx += vl; } _mm_sfence(); @@ -1673,9 +1670,8 @@ static void dt_interpolation_resample_sse(const struct dt_interpolation *itor, f /** Applies resampling (re-scaling) on *full* input and output buffers. * roi_in and roi_out define the part of the buffers that is affected. */ -void dt_interpolation_resample(const struct dt_interpolation *itor, float *out, - const dt_iop_roi_t *const roi_out, const int32_t out_stride, - const float *const in, const dt_iop_roi_t *const roi_in, +void dt_interpolation_resample(const struct dt_interpolation *itor, float *out, const dt_iop_roi_t *const roi_out, + const int32_t out_stride, const float *const in, const dt_iop_roi_t *const roi_in, const int32_t in_stride) { if(darktable.codepath.OPENMP_SIMD) @@ -1709,8 +1705,7 @@ void dt_interpolation_resample_roi(const struct dt_interpolation *itor, float *o #ifdef HAVE_OPENCL dt_interpolation_cl_global_t *dt_interpolation_init_cl_global() { - dt_interpolation_cl_global_t *g - = (dt_interpolation_cl_global_t *)malloc(sizeof(dt_interpolation_cl_global_t)); + dt_interpolation_cl_global_t *g = (dt_interpolation_cl_global_t *)malloc(sizeof(dt_interpolation_cl_global_t)); const int program = 2; // basic.cl, from programs.conf g->kernel_interpolation_resample = dt_opencl_create_kernel(program, "interpolation_resample"); @@ -1766,8 +1761,8 @@ int dt_interpolation_resample_cl(const struct dt_interpolation *itor, int devid, cl_mem dev_vmeta = NULL; debug_info("resampling_cl %p (%dx%d@%dx%d scale %f) -> %p (%dx%d@%dx%d scale %f)\n", (void *)dev_in, - roi_in->width, roi_in->height, roi_in->x, roi_in->y, roi_in->scale, (void *)dev_out, - roi_out->width, roi_out->height, roi_out->x, roi_out->y, roi_out->scale); + roi_in->width, roi_in->height, roi_in->x, roi_in->y, roi_in->scale, (void *)dev_out, roi_out->width, + roi_out->height, roi_out->x, roi_out->y, roi_out->scale); // Fast code path for 1:1 copy, only cropping area can change if(roi_out->scale == 1.f) @@ -1797,8 +1792,8 @@ int dt_interpolation_resample_cl(const struct dt_interpolation *itor, int devid, #endif // Prepare resampling plans once and for all - r = prepare_resampling_plan(itor, roi_in->width, roi_in->x, roi_out->width, roi_out->x, roi_out->scale, - &hlength, &hkernel, &hindex, &hmeta); + r = prepare_resampling_plan(itor, roi_in->width, roi_in->x, roi_out->width, roi_out->x, roi_out->scale, &hlength, + &hkernel, &hindex, &hmeta); if(r) { goto error; @@ -1837,9 +1832,14 @@ int dt_interpolation_resample_cl(const struct dt_interpolation *itor, int devid, int vblocksize; dt_opencl_local_buffer_t locopt - = (dt_opencl_local_buffer_t){ .xoffset = 0, .xfactor = 1, .yoffset = 0, .yfactor = 1, - .cellsize = 4 * sizeof(float), .overhead = hmaxtaps * sizeof(float) + hmaxtaps * sizeof(int), - .sizex = 1, .sizey = (1 << 16) * taps }; + = (dt_opencl_local_buffer_t){.xoffset = 0, + .xfactor = 1, + .yoffset = 0, + .yfactor = 1, + .cellsize = 4 * sizeof(float), + .overhead = hmaxtaps * sizeof(float) + hmaxtaps * sizeof(int), + .sizex = 1, + .sizey = (1 << 16) * taps }; if(dt_opencl_local_buffer_opt(devid, kernel, &locopt)) vblocksize = locopt.sizey; @@ -1851,9 +1851,8 @@ int dt_interpolation_resample_cl(const struct dt_interpolation *itor, int devid, // our strategy does not work: the vertical number of taps exceeds the vertical workgroupsize; // there is no point in continuing on the GPU - that would be way too slow; let's delegate the stuff to // the CPU then. - dt_print( - DT_DEBUG_OPENCL, - "[opencl_resampling] resampling plan cannot efficiently be run on the GPU - fall back to CPU.\n"); + dt_print(DT_DEBUG_OPENCL, + "[opencl_resampling] resampling plan cannot efficiently be run on the GPU - fall back to CPU.\n"); goto error; } @@ -1868,8 +1867,7 @@ int dt_interpolation_resample_cl(const struct dt_interpolation *itor, int devid, dev_hlength = dt_opencl_copy_host_to_device_constant(devid, sizeof(int) * width, hlength); if(dev_hlength == NULL) goto error; - dev_hkernel - = dt_opencl_copy_host_to_device_constant(devid, sizeof(float) * width * (hmaxtaps + 1), hkernel); + dev_hkernel = dt_opencl_copy_host_to_device_constant(devid, sizeof(float) * width * (hmaxtaps + 1), hkernel); if(dev_hkernel == NULL) goto error; dev_hmeta = dt_opencl_copy_host_to_device_constant(devid, sizeof(int) * width * 3, hmeta); @@ -1881,8 +1879,7 @@ int dt_interpolation_resample_cl(const struct dt_interpolation *itor, int devid, dev_vlength = dt_opencl_copy_host_to_device_constant(devid, sizeof(int) * height, vlength); if(dev_vlength == NULL) goto error; - dev_vkernel - = dt_opencl_copy_host_to_device_constant(devid, sizeof(float) * height * (vmaxtaps + 1), vkernel); + dev_vkernel = dt_opencl_copy_host_to_device_constant(devid, sizeof(float) * height * (vmaxtaps + 1), vkernel); if(dev_vkernel == NULL) goto error; dev_vmeta = dt_opencl_copy_host_to_device_constant(devid, sizeof(int) * height * 3, vmeta); diff --git a/src/common/interpolation.h b/src/common/interpolation.h index f7614543f784..d3ea7069f2c0 100644 --- a/src/common/interpolation.h +++ b/src/common/interpolation.h @@ -49,10 +49,10 @@ typedef __m128 (*dt_interpolation_sse_func)(__m128 width, __m128 t); /** Interpolation structure */ struct dt_interpolation { - enum dt_interpolation_type id; /**< Id such as defined by the dt_interpolation_type */ - const char *name; /**< internal name */ - int width; /**< Half width of its kernel support */ - dt_interpolation_func func; /**< Kernel function */ + enum dt_interpolation_type id; /**< Id such as defined by the dt_interpolation_type */ + const char *name; /**< internal name */ + int width; /**< Half width of its kernel support */ + dt_interpolation_func func; /**< Kernel function */ #if defined(__SSE2__) dt_interpolation_sse_func funcsse; /**< Kernel function (four params a time) */ #endif @@ -79,8 +79,8 @@ struct dt_interpolation * @return computed sample */ float dt_interpolation_compute_sample(const struct dt_interpolation *itor, const float *in, const float x, - const float y, const int width, const int height, - const int samplestride, const int linestride); + const float y, const int width, const int height, const int samplestride, + const int linestride); /** Compute an interpolated 4 component pixel. * @@ -132,9 +132,8 @@ const struct dt_interpolation *dt_interpolation_new(enum dt_interpolation_type t * @param roi_in [in] Region of interest of the original image * @param in_stride [in] Input line stride in <strong>bytes</strong> */ -void dt_interpolation_resample(const struct dt_interpolation *itor, float *out, - const dt_iop_roi_t *const roi_out, const int32_t out_stride, - const float *const in, const dt_iop_roi_t *const roi_in, +void dt_interpolation_resample(const struct dt_interpolation *itor, float *out, const dt_iop_roi_t *const roi_out, + const int32_t out_stride, const float *const in, const dt_iop_roi_t *const roi_in, const int32_t in_stride); void dt_interpolation_resample_roi(const struct dt_interpolation *itor, float *out, diff --git a/src/common/introspection.h b/src/common/introspection.h index a185e67e72e9..684fde659b3a 100644 --- a/src/common/introspection.h +++ b/src/common/introspection.h @@ -292,8 +292,7 @@ static inline const char *dt_introspection_get_enum_name(dt_introspection_field_ if(!(self && self->header.type == DT_INTROSPECTION_TYPE_ENUM)) return NULL; for(dt_introspection_type_enum_tuple_t *iter = self->Enum.values; iter->name; iter++) - if(iter->value == value) - return iter->name; + if(iter->value == value) return iter->name; return NULL; } diff --git a/src/common/locallaplacian.c b/src/common/locallaplacian.c index c475c72024d3..6b0a59ce2970 100644 --- a/src/common/locallaplacian.c +++ b/src/common/locallaplacian.c @@ -32,8 +32,7 @@ // downsample width/height to given level static inline int dl(int size, const int level) { - for(int l=0;l<level;l++) - size = (size-1)/2+1; + for(int l = 0; l < level; l++) size = (size - 1) / 2 + 1; return size; } @@ -41,96 +40,86 @@ static inline int dl(int size, const int level) // (translates to a 1px boundary around the corresponding pixel in the coarse buffer) // more precisely, 1<=i<wd-1 for even wd and // 1<=i<wd-2 for odd wd (j likewise with ht) -static inline float ll_expand_gaussian( - const float *const coarse, - const int i, - const int j, - const int wd, - const int ht) +static inline float ll_expand_gaussian(const float *const coarse, const int i, const int j, const int wd, + const int ht) { assert(i > 0); - assert(i < wd-1); + assert(i < wd - 1); assert(j > 0); - assert(j < ht-1); - assert(j/2 + 1 < (ht-1)/2+1); - assert(i/2 + 1 < (wd-1)/2+1); - const int cw = (wd-1)/2+1; - const int ind = (j/2)*cw+i/2; + assert(j < ht - 1); + assert(j / 2 + 1 < (ht - 1) / 2 + 1); + assert(i / 2 + 1 < (wd - 1) / 2 + 1); + const int cw = (wd - 1) / 2 + 1; + const int ind = (j / 2) * cw + i / 2; // case 0: case 1: case 2: case 3: // x . x . x x . x . x x . x . x x . x . x // . . . . . . . . . . . .[.]. . .[.]. . . // x .[x]. x x[.]x . x x . x . x x . x . x // . . . . . . . . . . . . . . . . . . . . // x . x . x x . x . x x . x . x x . x . x - switch((i&1) + 2*(j&1)) + switch((i & 1) + 2 * (j & 1)) { case 0: // both are even, 3x3 stencil - return 4./256. * ( - 6.0f*(coarse[ind-cw] + coarse[ind-1] + 6.0f*coarse[ind] + coarse[ind+1] + coarse[ind+cw]) - + coarse[ind-cw-1] + coarse[ind-cw+1] + coarse[ind+cw-1] + coarse[ind+cw+1]); + return 4. / 256. + * (6.0f * (coarse[ind - cw] + coarse[ind - 1] + 6.0f * coarse[ind] + coarse[ind + 1] + + coarse[ind + cw]) + + coarse[ind - cw - 1] + coarse[ind - cw + 1] + coarse[ind + cw - 1] + coarse[ind + cw + 1]); case 1: // i is odd, 2x3 stencil - return 4./256. * ( - 24.0*(coarse[ind] + coarse[ind+1]) + - 4.0*(coarse[ind-cw] + coarse[ind-cw+1] + coarse[ind+cw] + coarse[ind+cw+1])); + return 4. / 256. + * (24.0 * (coarse[ind] + coarse[ind + 1]) + + 4.0 * (coarse[ind - cw] + coarse[ind - cw + 1] + coarse[ind + cw] + coarse[ind + cw + 1])); case 2: // j is odd, 3x2 stencil - return 4./256. * ( - 24.0*(coarse[ind] + coarse[ind+cw]) + - 4.0*(coarse[ind-1] + coarse[ind+1] + coarse[ind+cw-1] + coarse[ind+cw+1])); + return 4. / 256. + * (24.0 * (coarse[ind] + coarse[ind + cw]) + + 4.0 * (coarse[ind - 1] + coarse[ind + 1] + coarse[ind + cw - 1] + coarse[ind + cw + 1])); default: // case 3: // both are odd, 2x2 stencil - return .25f * (coarse[ind] + coarse[ind+1] + coarse[ind+cw] + coarse[ind+cw+1]); + return .25f * (coarse[ind] + coarse[ind + 1] + coarse[ind + cw] + coarse[ind + cw + 1]); } } // helper to fill in one pixel boundary by copying it -static inline void ll_fill_boundary1( - float *const input, - const int wd, - const int ht) +static inline void ll_fill_boundary1(float *const input, const int wd, const int ht) { - for(int j=1;j<ht-1;j++) input[j*wd] = input[j*wd+1]; - for(int j=1;j<ht-1;j++) input[j*wd+wd-1] = input[j*wd+wd-2]; - memcpy(input, input+wd, sizeof(float)*wd); - memcpy(input+wd*(ht-1), input+wd*(ht-2), sizeof(float)*wd); + for(int j = 1; j < ht - 1; j++) input[j * wd] = input[j * wd + 1]; + for(int j = 1; j < ht - 1; j++) input[j * wd + wd - 1] = input[j * wd + wd - 2]; + memcpy(input, input + wd, sizeof(float) * wd); + memcpy(input + wd * (ht - 1), input + wd * (ht - 2), sizeof(float) * wd); } // helper to fill in two pixels boundary by copying it -static inline void ll_fill_boundary2( - float *const input, - const int wd, - const int ht) +static inline void ll_fill_boundary2(float *const input, const int wd, const int ht) { - for(int j=1;j<ht-1;j++) input[j*wd] = input[j*wd+1]; - if(wd & 1) for(int j=1;j<ht-1;j++) input[j*wd+wd-1] = input[j*wd+wd-2]; - else for(int j=1;j<ht-1;j++) input[j*wd+wd-1] = input[j*wd+wd-2] = input[j*wd+wd-3]; - memcpy(input, input+wd, sizeof(float)*wd); - if(!(ht & 1)) memcpy(input+wd*(ht-2), input+wd*(ht-3), sizeof(float)*wd); - memcpy(input+wd*(ht-1), input+wd*(ht-2), sizeof(float)*wd); + for(int j = 1; j < ht - 1; j++) input[j * wd] = input[j * wd + 1]; + if(wd & 1) + for(int j = 1; j < ht - 1; j++) input[j * wd + wd - 1] = input[j * wd + wd - 2]; + else + for(int j = 1; j < ht - 1; j++) input[j * wd + wd - 1] = input[j * wd + wd - 2] = input[j * wd + wd - 3]; + memcpy(input, input + wd, sizeof(float) * wd); + if(!(ht & 1)) memcpy(input + wd * (ht - 2), input + wd * (ht - 3), sizeof(float) * wd); + memcpy(input + wd * (ht - 1), input + wd * (ht - 2), sizeof(float) * wd); } -static inline void gauss_expand( - const float *const input, // coarse input - float *const fine, // upsampled, blurry output - const int wd, // fine res - const int ht) +static inline void gauss_expand(const float *const input, // coarse input + float *const fine, // upsampled, blurry output + const int wd, // fine res + const int ht) { #ifdef _OPENMP #pragma omp parallel for default(none) schedule(static) collapse(2) #endif - for(int j=1;j<((ht-1)&~1);j++) // even ht: two px boundary. odd ht: one px. - for(int i=1;i<((wd-1)&~1);i++) - fine[j*wd+i] = ll_expand_gaussian(input, i, j, wd, ht); + for(int j = 1; j < ((ht - 1) & ~1); j++) // even ht: two px boundary. odd ht: one px. + for(int i = 1; i < ((wd - 1) & ~1); i++) fine[j * wd + i] = ll_expand_gaussian(input, i, j, wd, ht); ll_fill_boundary2(fine, wd, ht); } #if defined(__SSE2__) -static inline void gauss_reduce_sse2( - const float *const input, // fine input buffer - float *const coarse, // coarse scale, blurred input buf - const int wd, // fine res - const int ht) +static inline void gauss_reduce_sse2(const float *const input, // fine input buffer + float *const coarse, // coarse scale, blurred input buf + const int wd, // fine res + const int ht) { // blur, store only coarse res - const int cw = (wd-1)/2+1, ch = (ht-1)/2+1; + const int cw = (wd - 1) / 2 + 1, ch = (ht - 1) / 2 + 1; // this version is inspired by opencv's pyrDown_ : // - allocate 5 rows of ring buffer (aligned) @@ -138,40 +127,39 @@ static inline void gauss_reduce_sse2( // - fill 5 coarse-res row buffers with 1 4 6 4 1 weights (reuse some from last time) // - do vertical convolution via sse and write to coarse output buf - const int stride = ((cw+8)&~7); // assure sse alignment of rows - float *ringbuf = dt_alloc_align(16, sizeof(*ringbuf)*stride*5); - float *rows[5] = {0}; + const int stride = ((cw + 8) & ~7); // assure sse alignment of rows + float *ringbuf = dt_alloc_align(16, sizeof(*ringbuf) * stride * 5); + float *rows[5] = { 0 }; int rowj = 0; // we initialised this many rows so far - for(int j=1;j<ch-1;j++) + for(int j = 1; j < ch - 1; j++) { // horizontal pass, convolve with 1 4 6 4 1 kernel and decimate - for(;rowj<=2*j+2;rowj++) + for(; rowj <= 2 * j + 2; rowj++) { - float *const row = ringbuf + (rowj % 5)*stride; - const float *const in = input + rowj*wd; + float *const row = ringbuf + (rowj % 5) * stride; + const float *const in = input + rowj * wd; #ifdef _OPENMP #pragma omp parallel for schedule(static) default(none) #endif - for(int i=1;i<cw-1;i++) - row[i] = 6*in[2*i] + 4*(in[2*i-1]+in[2*i+1]) + in[2*i-2] + in[2*i+2]; + for(int i = 1; i < cw - 1; i++) + row[i] = 6 * in[2 * i] + 4 * (in[2 * i - 1] + in[2 * i + 1]) + in[2 * i - 2] + in[2 * i + 2]; } // init row pointers - for(int k=0;k<5;k++) - rows[k] = ringbuf + ((2*j-2+k)%5)*stride; + for(int k = 0; k < 5; k++) rows[k] = ringbuf + ((2 * j - 2 + k) % 5) * stride; // vertical pass, convolve and decimate using SIMD: // note that we're ignoring the (1..cw-1) buffer limit, we'll pull in // garbage and fix it later by border filling. - float *const out = coarse + j*cw; - const float *const row0 = rows[0], *const row1 = rows[1], - *const row2 = rows[2], *const row3 = rows[3], *const row4 = rows[4]; - const __m128 four = _mm_set1_ps(4.f), scale = _mm_set1_ps(1.f/256.f); + float *const out = coarse + j * cw; + const float *const row0 = rows[0], *const row1 = rows[1], *const row2 = rows[2], *const row3 = rows[3], + *const row4 = rows[4]; + const __m128 four = _mm_set1_ps(4.f), scale = _mm_set1_ps(1.f / 256.f); #ifdef _OPENMP #pragma omp parallel for schedule(static) default(none) #endif - for(int i=0;i<=cw-8;i+=8) + for(int i = 0; i <= cw - 8; i += 8) { __m128 r0, r1, r2, r3, r4, t0, t1; r0 = _mm_load_ps(row0 + i); @@ -201,100 +189,98 @@ static inline void gauss_reduce_sse2( _mm_storeu_ps(out + i + 4, t1); } // process the rest - for(int i=cw&~7;i<cw-1;i++) - out[i] = (6*row2[i] + 4*(row1[i] + row3[i]) + row0[i] + row4[i])*(1.0f/256.0f); + for(int i = cw & ~7; i < cw - 1; i++) + out[i] = (6 * row2[i] + 4 * (row1[i] + row3[i]) + row0[i] + row4[i]) * (1.0f / 256.0f); } dt_free_align(ringbuf); ll_fill_boundary1(coarse, cw, ch); } #endif -static inline void gauss_reduce( - const float *const input, // fine input buffer - float *const coarse, // coarse scale, blurred input buf - const int wd, // fine res - const int ht) +static inline void gauss_reduce(const float *const input, // fine input buffer + float *const coarse, // coarse scale, blurred input buf + const int wd, // fine res + const int ht) { // blur, store only coarse res - const int cw = (wd-1)/2+1, ch = (ht-1)/2+1; + const int cw = (wd - 1) / 2 + 1, ch = (ht - 1) / 2 + 1; // this is the scalar (non-simd) code: const float a = 0.4f; - const float w[5] = {1./4.-a/2., 1./4., a, 1./4., 1./4.-a/2.}; - memset(coarse, 0, sizeof(float)*cw*ch); - // direct 5x5 stencil only on required pixels: + const float w[5] = { 1. / 4. - a / 2., 1. / 4., a, 1. / 4., 1. / 4. - a / 2. }; + memset(coarse, 0, sizeof(float) * cw * ch); +// direct 5x5 stencil only on required pixels: #ifdef _OPENMP #pragma omp parallel for schedule(static) default(none) collapse(2) #endif - for(int j=1;j<ch-1;j++) for(int i=1;i<cw-1;i++) - for(int jj=-2;jj<=2;jj++) for(int ii=-2;ii<=2;ii++) - coarse[j*cw+i] += input[(2*j+jj)*wd+2*i+ii] * w[ii+2] * w[jj+2]; + for(int j = 1; j < ch - 1; j++) + for(int i = 1; i < cw - 1; i++) + for(int jj = -2; jj <= 2; jj++) + for(int ii = -2; ii <= 2; ii++) + coarse[j * cw + i] += input[(2 * j + jj) * wd + 2 * i + ii] * w[ii + 2] * w[jj + 2]; ll_fill_boundary1(coarse, cw, ch); } // allocate output buffer with monochrome brightness channel from input, padded // up by max_supp on all four sides, dimensions written to wd2 ht2 -static inline float *ll_pad_input( - const float *const input, - const int wd, - const int ht, - const int max_supp, - int *wd2, - int *ht2, - local_laplacian_boundary_t *b) +static inline float *ll_pad_input(const float *const input, const int wd, const int ht, const int max_supp, + int *wd2, int *ht2, local_laplacian_boundary_t *b) { const int stride = 4; - *wd2 = 2*max_supp + wd; - *ht2 = 2*max_supp + ht; - float *const out = dt_alloc_align(16, *wd2**ht2*sizeof(*out)); + *wd2 = 2 * max_supp + wd; + *ht2 = 2 * max_supp + ht; + float *const out = dt_alloc_align(16, *wd2 * *ht2 * sizeof(*out)); if(b && b->mode == 2) { // pad by preview buffer #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) default(none) shared(wd2, ht2) collapse(2) #endif // fill regular pixels: - for(int j=0;j<ht;j++) for(int i=0;i<wd;i++) - out[(j+max_supp)**wd2+i+max_supp] = input[stride*(wd*j+i)] * 0.01f; // L -> [0,1] - - // for all out of roi pixels on the boundary we wish to pad: - // compute coordinate in full image. - // if not out of buf: - // compute padded preview pixel coordinate (clamp to padded preview buffer size) - // else - // pad as usual (hi-res sample and hold) -#define LL_FILL(fallback) do {\ - float isx = ((i - max_supp) + b->roi->x)/b->roi->scale;\ - float isy = ((j - max_supp) + b->roi->y)/b->roi->scale;\ - if(isx < 0 || isy >= b->buf->width\ - || isy < 0 || isy >= b->buf->height)\ - out[*wd2*j+i] = (fallback);\ - else\ - {\ - int px = CLAMP(isx / (float)b->buf->width * b->wd + (b->pwd-b->wd)/2, 0, b->pwd-1);\ - int py = CLAMP(isy / (float)b->buf->height * b->ht + (b->pht-b->ht)/2, 0, b->pht-1);\ - /* TODO: linear interpolation?*/\ - out[*wd2*j+i] = b->pad0[b->pwd*py+px];\ - } } while(0) + for(int j = 0; j < ht; j++) + for(int i = 0; i < wd; i++) + out[(j + max_supp) * *wd2 + i + max_supp] = input[stride * (wd * j + i)] * 0.01f; // L -> [0,1] + +// for all out of roi pixels on the boundary we wish to pad: +// compute coordinate in full image. +// if not out of buf: +// compute padded preview pixel coordinate (clamp to padded preview buffer size) +// else +// pad as usual (hi-res sample and hold) +#define LL_FILL(fallback) \ + do \ + { \ + float isx = ((i - max_supp) + b->roi->x) / b->roi->scale; \ + float isy = ((j - max_supp) + b->roi->y) / b->roi->scale; \ + if(isx < 0 || isy >= b->buf->width || isy < 0 || isy >= b->buf->height) \ + out[*wd2 * j + i] = (fallback); \ + else \ + { \ + int px = CLAMP(isx / (float)b->buf->width * b->wd + (b->pwd - b->wd) / 2, 0, b->pwd - 1); \ + int py = CLAMP(isy / (float)b->buf->height * b->ht + (b->pht - b->ht) / 2, 0, b->pht - 1); \ + /* TODO: linear interpolation?*/ \ + out[*wd2 * j + i] = b->pad0[b->pwd * py + px]; \ + } \ + } while(0) #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) default(none) shared(wd2, ht2, b) collapse(2) #endif // left border - for(int j=max_supp;j<*ht2-max_supp;j++) for(int i=0;i<max_supp;i++) - LL_FILL(input[stride*wd*(j-max_supp)]* 0.01f); + for(int j = max_supp; j < *ht2 - max_supp; j++) + for(int i = 0; i < max_supp; i++) LL_FILL(input[stride * wd * (j - max_supp)] * 0.01f); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) default(none) shared(wd2, ht2, b) collapse(2) #endif // right border - for(int j=max_supp;j<*ht2-max_supp;j++) for(int i=wd+max_supp;i<*wd2;i++) - LL_FILL(input[stride*((j-max_supp)*wd+wd-1)] * 0.01f); + for(int j = max_supp; j < *ht2 - max_supp; j++) + for(int i = wd + max_supp; i < *wd2; i++) LL_FILL(input[stride * ((j - max_supp) * wd + wd - 1)] * 0.01f); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) default(none) shared(wd2, ht2, b) collapse(2) #endif // top border - for(int j=0;j<max_supp;j++) for(int i=0;i<*wd2;i++) - LL_FILL(out[*wd2*max_supp+i]); + for(int j = 0; j < max_supp; j++) + for(int i = 0; i < *wd2; i++) LL_FILL(out[*wd2 * max_supp + i]); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) default(none) shared(wd2, ht2, b) collapse(2) #endif // bottom border - for(int j=max_supp+ht;j<*ht2;j++) for(int i=0;i<*wd2;i++) - LL_FILL(out[*wd2*(max_supp+ht-1)+i]); + for(int j = max_supp + ht; j < *ht2; j++) + for(int i = 0; i < *wd2; i++) LL_FILL(out[*wd2 * (max_supp + ht - 1) + i]); #undef LL_FILL } else @@ -302,25 +288,24 @@ static inline float *ll_pad_input( #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) default(none) shared(wd2, ht2) #endif - for(int j=0;j<ht;j++) + for(int j = 0; j < ht; j++) { - for(int i=0;i<max_supp;i++) - out[(j+max_supp)**wd2+i] = input[stride*wd*j]* 0.01f; // L -> [0,1] - for(int i=0;i<wd;i++) - out[(j+max_supp)**wd2+i+max_supp] = input[stride*(wd*j+i)] * 0.01f; // L -> [0,1] - for(int i=wd+max_supp;i<*wd2;i++) - out[(j+max_supp)**wd2+i] = input[stride*(j*wd+wd-1)] * 0.01f; // L -> [0,1] + for(int i = 0; i < max_supp; i++) + out[(j + max_supp) * *wd2 + i] = input[stride * wd * j] * 0.01f; // L -> [0,1] + for(int i = 0; i < wd; i++) + out[(j + max_supp) * *wd2 + i + max_supp] = input[stride * (wd * j + i)] * 0.01f; // L -> [0,1] + for(int i = wd + max_supp; i < *wd2; i++) + out[(j + max_supp) * *wd2 + i] = input[stride * (j * wd + wd - 1)] * 0.01f; // L -> [0,1] } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) default(none) shared(wd2, ht2) #endif - for(int j=0;j<max_supp;j++) - memcpy(out + *wd2*j, out+max_supp**wd2, sizeof(float)**wd2); + for(int j = 0; j < max_supp; j++) memcpy(out + *wd2 * j, out + max_supp * *wd2, sizeof(float) * *wd2); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) default(none) shared(wd2, ht2) #endif - for(int j=max_supp+ht;j<*ht2;j++) - memcpy(out + *wd2*j, out + *wd2*(max_supp+ht-1), sizeof(float)**wd2); + for(int j = max_supp + ht; j < *ht2; j++) + memcpy(out + *wd2 * j, out + *wd2 * (max_supp + ht - 1), sizeof(float) * *wd2); } #if 0 if(b && b->mode == 2) @@ -337,68 +322,59 @@ static inline float *ll_pad_input( return out; } -static inline float ll_laplacian( - const float *const coarse, // coarse res gaussian - const float *const fine, // fine res gaussian - const int i, // fine index - const int j, - const int wd, // fine width - const int ht) // fine height +static inline float ll_laplacian(const float *const coarse, // coarse res gaussian + const float *const fine, // fine res gaussian + const int i, // fine index + const int j, + const int wd, // fine width + const int ht) // fine height { - const float c = ll_expand_gaussian(coarse, - CLAMPS(i, 1, ((wd-1)&~1)-1), CLAMPS(j, 1, ((ht-1)&~1)-1), wd, ht); - return fine[j*wd+i] - c; + const float c + = ll_expand_gaussian(coarse, CLAMPS(i, 1, ((wd - 1) & ~1) - 1), CLAMPS(j, 1, ((ht - 1) & ~1) - 1), wd, ht); + return fine[j * wd + i] - c; } -static inline float curve_scalar( - const float x, - const float g, - const float sigma, - const float shadows, - const float highlights, - const float clarity) +static inline float curve_scalar(const float x, const float g, const float sigma, const float shadows, + const float highlights, const float clarity) { - const float c = x-g; + const float c = x - g; float val; // blend in via quadratic bezier - if (c > 2*sigma) val = g + sigma + shadows * (c-sigma); - else if(c < -2*sigma) val = g - sigma + highlights * (c+sigma); + if(c > 2 * sigma) + val = g + sigma + shadows * (c - sigma); + else if(c < -2 * sigma) + val = g - sigma + highlights * (c + sigma); else if(c > 0.0f) { // shadow contrast - const float t = CLAMPS(c / (2.0f*sigma), 0.0f, 1.0f); + const float t = CLAMPS(c / (2.0f * sigma), 0.0f, 1.0f); const float t2 = t * t; - const float mt = 1.0f-t; - val = g + sigma * 2.0f*mt*t + t2*(sigma + sigma*shadows); + const float mt = 1.0f - t; + val = g + sigma * 2.0f * mt * t + t2 * (sigma + sigma * shadows); } else { // highlight contrast - const float t = CLAMPS(-c / (2.0f*sigma), 0.0f, 1.0f); + const float t = CLAMPS(-c / (2.0f * sigma), 0.0f, 1.0f); const float t2 = t * t; - const float mt = 1.0f-t; - val = g - sigma * 2.0f*mt*t + t2*(- sigma - sigma*highlights); + const float mt = 1.0f - t; + val = g - sigma * 2.0f * mt * t + t2 * (-sigma - sigma * highlights); } // midtone local contrast - val += clarity * c * dt_fast_expf(-c*c/(2.0*sigma*sigma/3.0f)); + val += clarity * c * dt_fast_expf(-c * c / (2.0 * sigma * sigma / 3.0f)); return val; } #if defined(__SSE2__) -static inline __m128 curve_vec4( - const __m128 x, - const __m128 g, - const __m128 sigma, - const __m128 shadows, - const __m128 highlights, - const __m128 clarity) +static inline __m128 curve_vec4(const __m128 x, const __m128 g, const __m128 sigma, const __m128 shadows, + const __m128 highlights, const __m128 clarity) { // TODO: pull these non-data depedent constants out of the loop to see // whether the compiler fail to do so const __m128 const0 = _mm_set_ps1(0x3f800000u); const __m128 const1 = _mm_set_ps1(0x402DF854u); // for e^x - const __m128 sign_mask = _mm_set1_ps(-0.f); // -0.f = 1 << 31 + const __m128 sign_mask = _mm_set1_ps(-0.f); // -0.f = 1 << 31 const __m128 one = _mm_set1_ps(1.0f); const __m128 two = _mm_set1_ps(2.0f); - const __m128 twothirds = _mm_set1_ps(2.0f/3.0f); + const __m128 twothirds = _mm_set1_ps(2.0f / 3.0f); const __m128 twosig = _mm_mul_ps(two, sigma); const __m128 sigma2 = _mm_mul_ps(sigma, sigma); const __m128 s22 = _mm_mul_ps(twothirds, sigma2); @@ -412,15 +388,13 @@ static inline __m128 curve_vec4( // this contains the linear parts valid for c > 2*sigma or c < - 2*sigma const __m128 vlin = _mm_add_ps(g, _mm_add_ps(ssigma, _mm_mul_ps(shadhi, _mm_sub_ps(c, ssigma)))); - const __m128 t = _mm_min_ps(one, _mm_max_ps(_mm_setzero_ps(), - _mm_div_ps(c, _mm_mul_ps(two, ssigma)))); + const __m128 t = _mm_min_ps(one, _mm_max_ps(_mm_setzero_ps(), _mm_div_ps(c, _mm_mul_ps(two, ssigma)))); const __m128 t2 = _mm_mul_ps(t, t); const __m128 mt = _mm_sub_ps(one, t); // midtone value fading over to linear part, without local contrast: - const __m128 vmid = _mm_add_ps(g, - _mm_add_ps(_mm_mul_ps(_mm_mul_ps(ssigma, two), _mm_mul_ps(mt, t)), - _mm_mul_ps(t2, _mm_add_ps(ssigma, _mm_mul_ps(ssigma, shadhi))))); + const __m128 vmid = _mm_add_ps(g, _mm_add_ps(_mm_mul_ps(_mm_mul_ps(ssigma, two), _mm_mul_ps(mt, t)), + _mm_mul_ps(t2, _mm_add_ps(ssigma, _mm_mul_ps(ssigma, shadhi))))); // c > 2*sigma? const __m128 linselect = _mm_cmpgt_ps(_mm_andnot_ps(sign_mask, c), twosig); @@ -432,181 +406,160 @@ static inline __m128 curve_vec4( const __m128 k0 = _mm_add_ps(const0, _mm_mul_ps(arg, _mm_sub_ps(const1, const0))); const __m128 k = _mm_max_ps(k0, _mm_setzero_ps()); const __m128i ki = _mm_cvtps_epi32(k); - const __m128 gauss = _mm_load_ps((float*)&ki); + const __m128 gauss = _mm_load_ps((float *)&ki); const __m128 vcon = _mm_mul_ps(clarity, _mm_mul_ps(c, gauss)); return _mm_add_ps(val, vcon); } // sse (4-wide) -void apply_curve_sse2( - float *const out, - const float *const in, - const uint32_t w, - const uint32_t h, - const uint32_t padding, - const float g, - const float sigma, - const float shadows, - const float highlights, - const float clarity) +void apply_curve_sse2(float *const out, const float *const in, const uint32_t w, const uint32_t h, + const uint32_t padding, const float g, const float sigma, const float shadows, + const float highlights, const float clarity) { - // TODO: do all this in avx2 8-wide (should be straight forward): +// TODO: do all this in avx2 8-wide (should be straight forward): #ifdef _OPENMP #pragma omp parallel for default(none) schedule(dynamic) #endif - for(uint32_t j=padding;j<h-padding;j++) + for(uint32_t j = padding; j < h - padding; j++) { - const float *in2 = in + j*w + padding; - float *out2 = out + j*w + padding; + const float *in2 = in + j * w + padding; + float *out2 = out + j * w + padding; // find 4-byte aligned block in the middle: - const float *const beg = (float *)((size_t)(out2+3)&(size_t)0x10ul); - const float *const end = (float *)((size_t)(out2+w-padding)&(size_t)0x10ul); - const float *const fin = out2+w-padding; + const float *const beg = (float *)((size_t)(out2 + 3) & (size_t)0x10ul); + const float *const end = (float *)((size_t)(out2 + w - padding) & (size_t)0x10ul); + const float *const fin = out2 + w - padding; const __m128 g4 = _mm_set1_ps(g); const __m128 sig4 = _mm_set1_ps(sigma); const __m128 shd4 = _mm_set1_ps(shadows); const __m128 hil4 = _mm_set1_ps(highlights); const __m128 clr4 = _mm_set1_ps(clarity); - for(;out2<beg;out2++,in2++) - *out2 = curve_scalar(*in2, g, sigma, shadows, highlights, clarity); - for(;out2<end;out2+=4,in2+=4) + for(; out2 < beg; out2++, in2++) *out2 = curve_scalar(*in2, g, sigma, shadows, highlights, clarity); + for(; out2 < end; out2 += 4, in2 += 4) _mm_stream_ps(out2, curve_vec4(_mm_load_ps(in2), g4, sig4, shd4, hil4, clr4)); - for(;out2<fin;out2++,in2++) - *out2 = curve_scalar(*in2, g, sigma, shadows, highlights, clarity); - out2 = out + j*w; - for(int i=0;i<padding;i++) out2[i] = out2[padding]; - for(int i=w-padding;i<w;i++) out2[i] = out2[w-padding-1]; + for(; out2 < fin; out2++, in2++) *out2 = curve_scalar(*in2, g, sigma, shadows, highlights, clarity); + out2 = out + j * w; + for(int i = 0; i < padding; i++) out2[i] = out2[padding]; + for(int i = w - padding; i < w; i++) out2[i] = out2[w - padding - 1]; } #ifdef _OPENMP #pragma omp parallel for default(none) schedule(dynamic) #endif - for(int j=0;j<padding;j++) memcpy(out + w*j, out+padding*w, sizeof(float)*w); + for(int j = 0; j < padding; j++) memcpy(out + w * j, out + padding * w, sizeof(float) * w); #ifdef _OPENMP #pragma omp parallel for default(none) schedule(dynamic) #endif - for(int j=h-padding;j<h;j++) memcpy(out + w*j, out+w*(h-padding-1), sizeof(float)*w); + for(int j = h - padding; j < h; j++) memcpy(out + w * j, out + w * (h - padding - 1), sizeof(float) * w); } #endif // scalar version -void apply_curve( - float *const out, - const float *const in, - const uint32_t w, - const uint32_t h, - const uint32_t padding, - const float g, - const float sigma, - const float shadows, - const float highlights, - const float clarity) +void apply_curve(float *const out, const float *const in, const uint32_t w, const uint32_t h, + const uint32_t padding, const float g, const float sigma, const float shadows, + const float highlights, const float clarity) { #ifdef _OPENMP #pragma omp parallel for default(none) schedule(dynamic) #endif - for(uint32_t j=padding;j<h-padding;j++) + for(uint32_t j = padding; j < h - padding; j++) { - const float *in2 = in + j*w + padding; - float *out2 = out + j*w + padding; - for(uint32_t i=padding;i<w-padding;i++) + const float *in2 = in + j * w + padding; + float *out2 = out + j * w + padding; + for(uint32_t i = padding; i < w - padding; i++) (*out2++) = curve_scalar(*(in2++), g, sigma, shadows, highlights, clarity); - out2 = out + j*w; - for(int i=0;i<padding;i++) out2[i] = out2[padding]; - for(int i=w-padding;i<w;i++) out2[i] = out2[w-padding-1]; + out2 = out + j * w; + for(int i = 0; i < padding; i++) out2[i] = out2[padding]; + for(int i = w - padding; i < w; i++) out2[i] = out2[w - padding - 1]; } #ifdef _OPENMP #pragma omp parallel for default(none) schedule(dynamic) #endif - for(int j=0;j<padding;j++) memcpy(out + w*j, out+padding*w, sizeof(float)*w); + for(int j = 0; j < padding; j++) memcpy(out + w * j, out + padding * w, sizeof(float) * w); #ifdef _OPENMP #pragma omp parallel for default(none) schedule(dynamic) #endif - for(int j=h-padding;j<h;j++) memcpy(out + w*j, out+w*(h-padding-1), sizeof(float)*w); + for(int j = h - padding; j < h; j++) memcpy(out + w * j, out + w * (h - padding - 1), sizeof(float) * w); } -void local_laplacian_internal( - const float *const input, // input buffer in some Labx or yuvx format - float *const out, // output buffer with colour - const int wd, // width and - const int ht, // height of the input buffer - const float sigma, // user param: separate shadows/midtones/highlights - const float shadows, // user param: lift shadows - const float highlights, // user param: compress highlights - const float clarity, // user param: increase clarity/local contrast - const int use_sse2, // flag whether to use SSE version - local_laplacian_boundary_t *b) +void local_laplacian_internal(const float *const input, // input buffer in some Labx or yuvx format + float *const out, // output buffer with colour + const int wd, // width and + const int ht, // height of the input buffer + const float sigma, // user param: separate shadows/midtones/highlights + const float shadows, // user param: lift shadows + const float highlights, // user param: compress highlights + const float clarity, // user param: increase clarity/local contrast + const int use_sse2, // flag whether to use SSE version + local_laplacian_boundary_t *b) { #define max_levels 30 #define num_gamma 6 // don't divide by 2 more often than we can: - const int num_levels = MIN(max_levels, 31-__builtin_clz(MIN(wd,ht))); - int last_level = num_levels-1; + const int num_levels = MIN(max_levels, 31 - __builtin_clz(MIN(wd, ht))); + int last_level = num_levels - 1; if(b && b->mode == 2) // last_level = num_levels-3 >= 2 ? num_levels-3 : 2; - last_level = num_levels > 4 ? 4 : num_levels-1; - const int max_supp = 1<<last_level; + last_level = num_levels > 4 ? 4 : num_levels - 1; + const int max_supp = 1 << last_level; int w, h; - float *padded[max_levels] = {0}; + float *padded[max_levels] = { 0 }; if(b && b->mode == 2) padded[0] = ll_pad_input(input, wd, ht, max_supp, &w, &h, b); else padded[0] = ll_pad_input(input, wd, ht, max_supp, &w, &h, 0); // allocate pyramid pointers for padded input - for(int l=1;l<=last_level;l++) - padded[l] = dt_alloc_align(16, sizeof(float)*dl(w,l)*dl(h,l)); + for(int l = 1; l <= last_level; l++) padded[l] = dt_alloc_align(16, sizeof(float) * dl(w, l) * dl(h, l)); // allocate pyramid pointers for output - float *output[max_levels] = {0}; - for(int l=0;l<=last_level;l++) - output[l] = dt_alloc_align(16, sizeof(float)*dl(w,l)*dl(h,l)); + float *output[max_levels] = { 0 }; + for(int l = 0; l <= last_level; l++) output[l] = dt_alloc_align(16, sizeof(float) * dl(w, l) * dl(h, l)); - // create gauss pyramid of padded input, write coarse directly to output +// create gauss pyramid of padded input, write coarse directly to output #if defined(__SSE2__) if(use_sse2) { - for(int l=1;l<last_level;l++) - gauss_reduce_sse2(padded[l-1], padded[l], dl(w,l-1), dl(h,l-1)); - gauss_reduce_sse2(padded[last_level-1], output[last_level], dl(w,last_level-1), dl(h,last_level-1)); + for(int l = 1; l < last_level; l++) gauss_reduce_sse2(padded[l - 1], padded[l], dl(w, l - 1), dl(h, l - 1)); + gauss_reduce_sse2(padded[last_level - 1], output[last_level], dl(w, last_level - 1), dl(h, last_level - 1)); } else #endif { - for(int l=1;l<last_level;l++) - gauss_reduce(padded[l-1], padded[l], dl(w,l-1), dl(h,l-1)); - gauss_reduce(padded[last_level-1], output[last_level], dl(w,last_level-1), dl(h,last_level-1)); + for(int l = 1; l < last_level; l++) gauss_reduce(padded[l - 1], padded[l], dl(w, l - 1), dl(h, l - 1)); + gauss_reduce(padded[last_level - 1], output[last_level], dl(w, last_level - 1), dl(h, last_level - 1)); } // evenly sample brightness [0,1]: - float gamma[num_gamma] = {0.0f}; - for(int k=0;k<num_gamma;k++) gamma[k] = (k+.5f)/(float)num_gamma; + float gamma[num_gamma] = { 0.0f }; + for(int k = 0; k < num_gamma; k++) gamma[k] = (k + .5f) / (float)num_gamma; // for(int k=0;k<num_gamma;k++) gamma[k] = k/(num_gamma-1.0f); // allocate memory for intermediate laplacian pyramids - float *buf[num_gamma][max_levels] = {{0}}; - for(int k=0;k<num_gamma;k++) for(int l=0;l<=last_level;l++) - buf[k][l] = dt_alloc_align(16, sizeof(float)*dl(w,l)*dl(h,l)); + float *buf[num_gamma][max_levels] = { { 0 } }; + for(int k = 0; k < num_gamma; k++) + for(int l = 0; l <= last_level; l++) buf[k][l] = dt_alloc_align(16, sizeof(float) * dl(w, l) * dl(h, l)); // the paper says remapping only level 3 not 0 does the trick, too // (but i really like the additional octave of sharpness we get, // willing to pay the cost). - for(int k=0;k<num_gamma;k++) + for(int k = 0; k < num_gamma; k++) { // process images #if defined(__SSE2__) if(use_sse2) apply_curve_sse2(buf[k][0], padded[0], w, h, max_supp, gamma[k], sigma, shadows, highlights, clarity); else // brackets in next line needed for silly gcc warning: #endif - {apply_curve(buf[k][0], padded[0], w, h, max_supp, gamma[k], sigma, shadows, highlights, clarity);} + { + apply_curve(buf[k][0], padded[0], w, h, max_supp, gamma[k], sigma, shadows, highlights, clarity); + } // create gaussian pyramids - for(int l=1;l<=last_level;l++) + for(int l = 1; l <= last_level; l++) #if defined(__SSE2__) if(use_sse2) - gauss_reduce_sse2(buf[k][l-1], buf[k][l], dl(w,l-1), dl(h,l-1)); + gauss_reduce_sse2(buf[k][l - 1], buf[k][l], dl(w, l - 1), dl(h, l - 1)); else #endif - gauss_reduce(buf[k][l-1], buf[k][l], dl(w,l-1), dl(h,l-1)); + gauss_reduce(buf[k][l - 1], buf[k][l], dl(w, l - 1), dl(h, l - 1)); } // resample output[last_level] from preview @@ -615,14 +568,14 @@ void local_laplacian_internal( if(b && b->mode == 2) { const float isize = powf(2.0f, last_level) / b->roi->scale; // pixel size of coarsest level in image space - const float psize = isize / b->buf->width * b->wd; // pixel footprint rescaled to preview buffer - const float pl = log2f(psize); // mip level in preview buffer - const int pl0 = CLAMP((int)pl, 0, b->num_levels-1), pl1 = CLAMP((int)(pl+1), 0, b->num_levels-1); - const float weight = CLAMP(pl-pl0, 0, 1); // weight between mip levels - const float mul0 = 1.0/powf(2.0f, pl0); - const float mul1 = 1.0/powf(2.0f, pl1); + const float psize = isize / b->buf->width * b->wd; // pixel footprint rescaled to preview buffer + const float pl = log2f(psize); // mip level in preview buffer + const int pl0 = CLAMP((int)pl, 0, b->num_levels - 1), pl1 = CLAMP((int)(pl + 1), 0, b->num_levels - 1); + const float weight = CLAMP(pl - pl0, 0, 1); // weight between mip levels + const float mul0 = 1.0 / powf(2.0f, pl0); + const float mul1 = 1.0 / powf(2.0f, pl1); const float mul = powf(2.0f, last_level); - const int pw = dl(w,last_level), ph = dl(h,last_level); + const int pw = dl(w, last_level), ph = dl(h, last_level); const int pw0 = dl(b->pwd, pl0), ph0 = dl(b->pht, pl0); const int pw1 = dl(b->pwd, pl1), ph1 = dl(b->pht, pl1); #if 0 @@ -650,38 +603,39 @@ void local_laplacian_internal( #ifdef _OPENMP #pragma omp parallel for schedule(static) collapse(2) default(shared) #endif - for(int j=0;j<ph;j++) for(int i=0;i<pw;i++) - { - float ix = ((i*mul - max_supp) + b->roi->x)/b->roi->scale; - float iy = ((j*mul - max_supp) + b->roi->y)/b->roi->scale; - float px = CLAMP(ix / (float)b->buf->width * b->wd + (b->pwd-b->wd)/2, 0, b->pwd-1); - float py = CLAMP(iy / (float)b->buf->height * b->ht + (b->pht-b->ht)/2, 0, b->pht-1); - // trilinear lookup: - int px0 = CLAMP(px*mul0-.5f, 0, pw0-1); - int py0 = CLAMP(py*mul0-.5f, 0, ph0-1); - int px1 = CLAMP(px*mul1-.5f, 0, pw1-1); - int py1 = CLAMP(py*mul1-.5f, 0, ph1-1); + for(int j = 0; j < ph; j++) + for(int i = 0; i < pw; i++) + { + float ix = ((i * mul - max_supp) + b->roi->x) / b->roi->scale; + float iy = ((j * mul - max_supp) + b->roi->y) / b->roi->scale; + float px = CLAMP(ix / (float)b->buf->width * b->wd + (b->pwd - b->wd) / 2, 0, b->pwd - 1); + float py = CLAMP(iy / (float)b->buf->height * b->ht + (b->pht - b->ht) / 2, 0, b->pht - 1); + // trilinear lookup: + int px0 = CLAMP(px * mul0 - .5f, 0, pw0 - 1); + int py0 = CLAMP(py * mul0 - .5f, 0, ph0 - 1); + int px1 = CLAMP(px * mul1 - .5f, 0, pw1 - 1); + int py1 = CLAMP(py * mul1 - .5f, 0, ph1 - 1); #if 1 - float f0x = CLAMP(px*mul0 - px0, 0.0, 1.0); - float f0y = CLAMP(py*mul0 - py0, 0.0, 1.0); - float f1x = CLAMP(px*mul1 - px1, 0.0, 1.0); - float f1y = CLAMP(py*mul1 - py1, 0.0, 1.0); - float c0 = - (1.0f-f0x)*(1.0f-f0y)*b->output[pl0][CLAMP(py0 , 0, ph0-1)*pw0 + CLAMP(px0 , 0, pw0-1)]+ - ( f0x)*(1.0f-f0y)*b->output[pl0][CLAMP(py0 , 0, ph0-1)*pw0 + CLAMP(px0+1, 0, pw0-1)]+ - (1.0f-f0x)*( f0y)*b->output[pl0][CLAMP(py0+1, 0, ph0-1)*pw0 + CLAMP(px0 , 0, pw0-1)]+ - ( f0x)*( f0y)*b->output[pl0][CLAMP(py0+1, 0, ph0-1)*pw0 + CLAMP(px0+1, 0, pw0-1)]; - float c1 = - (1.0f-f1x)*(1.0f-f1y)*b->output[pl1][CLAMP(py1 , 0, ph1-1)*pw1 + CLAMP(px1 , 0, pw1-1)]+ - ( f1x)*(1.0f-f1y)*b->output[pl1][CLAMP(py1 , 0, ph1-1)*pw1 + CLAMP(px1+1, 0, pw1-1)]+ - (1.0f-f1x)*( f1y)*b->output[pl1][CLAMP(py1+1, 0, ph1-1)*pw1 + CLAMP(px1 , 0, pw1-1)]+ - ( f1x)*( f1y)*b->output[pl1][CLAMP(py1+1, 0, ph1-1)*pw1 + CLAMP(px1+1, 0, pw1-1)]; + float f0x = CLAMP(px * mul0 - px0, 0.0, 1.0); + float f0y = CLAMP(py * mul0 - py0, 0.0, 1.0); + float f1x = CLAMP(px * mul1 - px1, 0.0, 1.0); + float f1y = CLAMP(py * mul1 - py1, 0.0, 1.0); + float c0 + = (1.0f - f0x) * (1.0f - f0y) * b->output[pl0][CLAMP(py0, 0, ph0 - 1) * pw0 + CLAMP(px0, 0, pw0 - 1)] + + (f0x) * (1.0f - f0y) * b->output[pl0][CLAMP(py0, 0, ph0 - 1) * pw0 + CLAMP(px0 + 1, 0, pw0 - 1)] + + (1.0f - f0x) * (f0y)*b->output[pl0][CLAMP(py0 + 1, 0, ph0 - 1) * pw0 + CLAMP(px0, 0, pw0 - 1)] + + (f0x) * (f0y)*b->output[pl0][CLAMP(py0 + 1, 0, ph0 - 1) * pw0 + CLAMP(px0 + 1, 0, pw0 - 1)]; + float c1 + = (1.0f - f1x) * (1.0f - f1y) * b->output[pl1][CLAMP(py1, 0, ph1 - 1) * pw1 + CLAMP(px1, 0, pw1 - 1)] + + (f1x) * (1.0f - f1y) * b->output[pl1][CLAMP(py1, 0, ph1 - 1) * pw1 + CLAMP(px1 + 1, 0, pw1 - 1)] + + (1.0f - f1x) * (f1y)*b->output[pl1][CLAMP(py1 + 1, 0, ph1 - 1) * pw1 + CLAMP(px1, 0, pw1 - 1)] + + (f1x) * (f1y)*b->output[pl1][CLAMP(py1 + 1, 0, ph1 - 1) * pw1 + CLAMP(px1 + 1, 0, pw1 - 1)]; #else - float c0 = b->output[pl0][py0*pw0 + px0]; - float c1 = b->output[pl1][py1*pw1 + px1]; + float c0 = b->output[pl0][py0 * pw0 + px0]; + float c1 = b->output[pl1][py1 * pw1 + px1]; #endif - output[last_level][j*pw+i] = weight * c1 + (1.0f-weight) * c0; - } + output[last_level][j * pw + i] = weight * c1 + (1.0f - weight) * c0; + } #if 0 { FILE *f = fopen("/tmp/newcoarse.pfm", "wb"); @@ -696,41 +650,44 @@ void local_laplacian_internal( } // assemble output pyramid coarse to fine - for(int l=last_level-1;l >= 0; l--) + for(int l = last_level - 1; l >= 0; l--) { - const int pw = dl(w,l), ph = dl(h,l); + const int pw = dl(w, l), ph = dl(h, l); - gauss_expand(output[l+1], output[l], pw, ph); - // go through all coefficients in the upsampled gauss buffer: + gauss_expand(output[l + 1], output[l], pw, ph); +// go through all coefficients in the upsampled gauss buffer: #ifdef _OPENMP -#pragma omp parallel for default(none) schedule(static) collapse(2) shared(w,h,buf,output,l,gamma,padded) +#pragma omp parallel for default(none) schedule(static) collapse(2) shared(w, h, buf, output, l, gamma, padded) #endif - for(int j=0;j<ph;j++) for(int i=0;i<pw;i++) - { - const float v = padded[l][j*pw+i]; - int hi = 1; - for(;hi<num_gamma-1 && gamma[hi] <= v;hi++); - int lo = hi-1; - const float a = CLAMPS((v - gamma[lo])/(gamma[hi]-gamma[lo]), 0.0f, 1.0f); - const float l0 = ll_laplacian(buf[lo][l+1], buf[lo][l], i, j, pw, ph); - const float l1 = ll_laplacian(buf[hi][l+1], buf[hi][l], i, j, pw, ph); - output[l][j*pw+i] += l0 * (1.0f-a) + l1 * a; - // we could do this to save on memory (no need for finest buf[][]). - // unfortunately it results in a quite noticable loss of sharpness, i think - // the extra level is worth it. - // else if(l == 0) // use finest scale from input to not amplify noise (and use less memory) - // output[l][j*pw+i] += ll_laplacian(padded[l+1], padded[l], i, j, pw, ph); - } + for(int j = 0; j < ph; j++) + for(int i = 0; i < pw; i++) + { + const float v = padded[l][j * pw + i]; + int hi = 1; + for(; hi < num_gamma - 1 && gamma[hi] <= v; hi++) + ; + int lo = hi - 1; + const float a = CLAMPS((v - gamma[lo]) / (gamma[hi] - gamma[lo]), 0.0f, 1.0f); + const float l0 = ll_laplacian(buf[lo][l + 1], buf[lo][l], i, j, pw, ph); + const float l1 = ll_laplacian(buf[hi][l + 1], buf[hi][l], i, j, pw, ph); + output[l][j * pw + i] += l0 * (1.0f - a) + l1 * a; + // we could do this to save on memory (no need for finest buf[][]). + // unfortunately it results in a quite noticable loss of sharpness, i think + // the extra level is worth it. + // else if(l == 0) // use finest scale from input to not amplify noise (and use less memory) + // output[l][j*pw+i] += ll_laplacian(padded[l+1], padded[l], i, j, pw, ph); + } } #ifdef _OPENMP -#pragma omp parallel for default(none) schedule(dynamic) collapse(2) shared(w,output,buf) +#pragma omp parallel for default(none) schedule(dynamic) collapse(2) shared(w, output, buf) #endif - for(int j=0;j<ht;j++) for(int i=0;i<wd;i++) - { - out[4*(j*wd+i)+0] = 100.0f * output[0][(j+max_supp)*w+max_supp+i]; // [0,1] -> L - out[4*(j*wd+i)+1] = input[4*(j*wd+i)+1]; // copy original colour channels - out[4*(j*wd+i)+2] = input[4*(j*wd+i)+2]; - } + for(int j = 0; j < ht; j++) + for(int i = 0; i < wd; i++) + { + out[4 * (j * wd + i) + 0] = 100.0f * output[0][(j + max_supp) * w + max_supp + i]; // [0,1] -> L + out[4 * (j * wd + i) + 1] = input[4 * (j * wd + i) + 1]; // copy original colour channels + out[4 * (j * wd + i) + 2] = input[4 * (j * wd + i) + 2]; + } if(b && b->mode == 1) { // output the buffers for later re-use b->pad0 = padded[0]; @@ -739,33 +696,33 @@ void local_laplacian_internal( b->pwd = w; b->pht = h; b->num_levels = num_levels; - for(int l=0;l<num_levels;l++) b->output[l] = output[l]; + for(int l = 0; l < num_levels; l++) b->output[l] = output[l]; } // free all buffers except the ones passed out for preview rendering - for(int l=0;l<max_levels;l++) + for(int l = 0; l < max_levels; l++) { - if(!b || b->mode != 1 || l) dt_free_align(padded[l]); - if(!b || b->mode != 1) dt_free_align(output[l]); - for(int k=0; k<num_gamma;k++) dt_free_align(buf[k][l]); + if(!b || b->mode != 1 || l) dt_free_align(padded[l]); + if(!b || b->mode != 1) dt_free_align(output[l]); + for(int k = 0; k < num_gamma; k++) dt_free_align(buf[k][l]); } #undef num_levels #undef num_gamma } -size_t local_laplacian_memory_use(const int width, // width of input image - const int height) // height of input image +size_t local_laplacian_memory_use(const int width, // width of input image + const int height) // height of input image { #define max_levels 30 #define num_gamma 6 - const int num_levels = MIN(max_levels, 31-__builtin_clz(MIN(width,height))); - const int max_supp = 1<<(num_levels-1); - const int paddwd = width + 2*max_supp; - const int paddht = height + 2*max_supp; + const int num_levels = MIN(max_levels, 31 - __builtin_clz(MIN(width, height))); + const int max_supp = 1 << (num_levels - 1); + const int paddwd = width + 2 * max_supp; + const int paddht = height + 2 * max_supp; size_t memory_use = 0; - for(int l=0;l<num_levels;l++) + for(int l = 0; l < num_levels; l++) memory_use += (size_t)(2 + num_gamma) * dl(paddwd, l) * dl(paddht, l) * sizeof(float); return memory_use; @@ -773,15 +730,15 @@ size_t local_laplacian_memory_use(const int width, // width of input image #undef num_gamma } -size_t local_laplacian_singlebuffer_size(const int width, // width of input image - const int height) // height of input image +size_t local_laplacian_singlebuffer_size(const int width, // width of input image + const int height) // height of input image { #define max_levels 30 #define num_gamma 6 - const int num_levels = MIN(max_levels, 31-__builtin_clz(MIN(width,height))); - const int max_supp = 1<<(num_levels-1); - const int paddwd = width + 2*max_supp; - const int paddht = height + 2*max_supp; + const int num_levels = MIN(max_levels, 31 - __builtin_clz(MIN(width, height))); + const int max_supp = 1 << (num_levels - 1); + const int paddwd = width + 2 * max_supp; + const int paddht = height + 2 * max_supp; return (size_t)dl(paddwd, 0) * dl(paddht, 0) * sizeof(float); #undef num_levels diff --git a/src/common/locallaplacian.h b/src/common/locallaplacian.h index 16ee7cd573d8..05b3701fd51a 100644 --- a/src/common/locallaplacian.h +++ b/src/common/locallaplacian.h @@ -34,63 +34,59 @@ typedef struct local_laplacian_boundary_t const dt_iop_roi_t *buf; // dimensions of full buffer float *output[30]; // output pyramid of preview pass (allocated via dt_alloc_align) int num_levels; // number of levels in preview output pyramid -} -local_laplacian_boundary_t; +} local_laplacian_boundary_t; -void local_laplacian_boundary_free( - local_laplacian_boundary_t *b) +void local_laplacian_boundary_free(local_laplacian_boundary_t *b) { dt_free_align(b->pad0); - for(int l=0;l<b->num_levels;l++) dt_free_align(b->output[l]); + for(int l = 0; l < b->num_levels; l++) dt_free_align(b->output[l]); memset(b, 0, sizeof(*b)); } -void local_laplacian_internal( - const float *const input, // input buffer in some Labx or yuvx format - float *const out, // output buffer with colour - const int wd, // width and - const int ht, // height of the input buffer - const float sigma, // user param: separate shadows/midtones/highlights - const float shadows, // user param: lift shadows - const float highlights, // user param: compress highlights - const float clarity, // user param: increase clarity/local contrast - const int use_sse2, // switch on sse optimised version, if available - // the following is just needed for clipped roi with boundary conditions from coarse buffer (can be 0) - local_laplacian_boundary_t *b); +void local_laplacian_internal(const float *const input, // input buffer in some Labx or yuvx format + float *const out, // output buffer with colour + const int wd, // width and + const int ht, // height of the input buffer + const float sigma, // user param: separate shadows/midtones/highlights + const float shadows, // user param: lift shadows + const float highlights, // user param: compress highlights + const float clarity, // user param: increase clarity/local contrast + const int use_sse2, // switch on sse optimised version, if available + // the following is just needed for clipped roi with boundary conditions from coarse + // buffer (can be 0) + local_laplacian_boundary_t *b); -void local_laplacian( - const float *const input, // input buffer in some Labx or yuvx format - float *const out, // output buffer with colour - const int wd, // width and - const int ht, // height of the input buffer - const float sigma, // user param: separate shadows/midtones/highlights - const float shadows, // user param: lift shadows - const float highlights, // user param: compress highlights - const float clarity, // user param: increase clarity/local contrast - local_laplacian_boundary_t *b) // can be 0 +void local_laplacian(const float *const input, // input buffer in some Labx or yuvx format + float *const out, // output buffer with colour + const int wd, // width and + const int ht, // height of the input buffer + const float sigma, // user param: separate shadows/midtones/highlights + const float shadows, // user param: lift shadows + const float highlights, // user param: compress highlights + const float clarity, // user param: increase clarity/local contrast + local_laplacian_boundary_t *b) // can be 0 { local_laplacian_internal(input, out, wd, ht, sigma, shadows, highlights, clarity, 0, b); } -size_t local_laplacian_memory_use(const int width, // width of input image - const int height); // height of input image +size_t local_laplacian_memory_use(const int width, // width of input image + const int height); // height of input image -size_t local_laplacian_singlebuffer_size(const int width, // width of input image - const int height); // height of input image +size_t local_laplacian_singlebuffer_size(const int width, // width of input image + const int height); // height of input image #if defined(__SSE2__) -void local_laplacian_sse2( - const float *const input, // input buffer in some Labx or yuvx format - float *const out, // output buffer with colour - const int wd, // width and - const int ht, // height of the input buffer - const float sigma, // user param: separate shadows/midtones/highlights - const float shadows, // user param: lift shadows - const float highlights, // user param: compress highlights - const float clarity, // user param: increase clarity/local contrast - local_laplacian_boundary_t *b) // can be 0 +void local_laplacian_sse2(const float *const input, // input buffer in some Labx or yuvx format + float *const out, // output buffer with colour + const int wd, // width and + const int ht, // height of the input buffer + const float sigma, // user param: separate shadows/midtones/highlights + const float shadows, // user param: lift shadows + const float highlights, // user param: compress highlights + const float clarity, // user param: increase clarity/local contrast + local_laplacian_boundary_t *b) // can be 0 { local_laplacian_internal(input, out, wd, ht, sigma, shadows, highlights, clarity, 1, b); } diff --git a/src/common/locallaplaciancl.c b/src/common/locallaplaciancl.c index 678b26649542..67d2998151ff 100644 --- a/src/common/locallaplaciancl.c +++ b/src/common/locallaplaciancl.c @@ -26,22 +26,22 @@ // downsample width/height to given level static inline uint64_t dl(uint64_t size, const int level) { - for(int l=0;l<level;l++) - size = (size-1)/2+1; + for(int l = 0; l < level; l++) size = (size - 1) / 2 + 1; return size; } dt_local_laplacian_cl_global_t *dt_local_laplacian_init_cl_global() { - dt_local_laplacian_cl_global_t *g = (dt_local_laplacian_cl_global_t *)malloc(sizeof(dt_local_laplacian_cl_global_t)); + dt_local_laplacian_cl_global_t *g + = (dt_local_laplacian_cl_global_t *)malloc(sizeof(dt_local_laplacian_cl_global_t)); const int program = 19; // locallaplacian.cl, from programs.conf - g->kernel_pad_input = dt_opencl_create_kernel(program, "pad_input"); - g->kernel_gauss_expand = dt_opencl_create_kernel(program, "gauss_expand"); - g->kernel_gauss_reduce = dt_opencl_create_kernel(program, "gauss_reduce"); + g->kernel_pad_input = dt_opencl_create_kernel(program, "pad_input"); + g->kernel_gauss_expand = dt_opencl_create_kernel(program, "gauss_expand"); + g->kernel_gauss_reduce = dt_opencl_create_kernel(program, "gauss_reduce"); g->kernel_laplacian_assemble = dt_opencl_create_kernel(program, "laplacian_assemble"); - g->kernel_process_curve = dt_opencl_create_kernel(program, "process_curve"); - g->kernel_write_back = dt_opencl_create_kernel(program, "write_back"); + g->kernel_process_curve = dt_opencl_create_kernel(program, "process_curve"); + g->kernel_write_back = dt_opencl_create_kernel(program, "write_back"); return g; } @@ -52,14 +52,13 @@ void dt_local_laplacian_free_cl(dt_local_laplacian_cl_t *g) dt_opencl_finish(g->devid); // free device mem - for(int l=0;l<max_levels;l++) + for(int l = 0; l < max_levels; l++) { dt_opencl_release_mem_object(g->dev_padded[l]); dt_opencl_release_mem_object(g->dev_output[l]); - for(int k=0;k<num_gamma;k++) - dt_opencl_release_mem_object(g->dev_processed[k][l]); + for(int k = 0; k < num_gamma; k++) dt_opencl_release_mem_object(g->dev_processed[k][l]); } - for(int k=0;k<num_gamma;k++) free(g->dev_processed[k]); + for(int k = 0; k < num_gamma; k++) free(g->dev_processed[k]); free(g->dev_padded); free(g->dev_output); free(g->dev_processed); @@ -68,14 +67,14 @@ void dt_local_laplacian_free_cl(dt_local_laplacian_cl_t *g) free(g); } -dt_local_laplacian_cl_t *dt_local_laplacian_init_cl( - const int devid, - const int width, // width of input image - const int height, // height of input image - const float sigma, // user param: separate shadows/midtones/highlights - const float shadows, // user param: lift shadows - const float highlights, // user param: compress highlights - const float clarity) // user param: increase clarity/local contrast +dt_local_laplacian_cl_t * +dt_local_laplacian_init_cl(const int devid, + const int width, // width of input image + const int height, // height of input image + const float sigma, // user param: separate shadows/midtones/highlights + const float shadows, // user param: lift shadows + const float highlights, // user param: compress highlights + const float clarity) // user param: increase clarity/local contrast { dt_local_laplacian_cl_t *g = (dt_local_laplacian_cl_t *)malloc(sizeof(dt_local_laplacian_cl_t)); if(!g) return 0; @@ -91,27 +90,29 @@ dt_local_laplacian_cl_t *dt_local_laplacian_init_cl( g->dev_padded = (cl_mem *)calloc(max_levels, sizeof(cl_mem *)); g->dev_output = (cl_mem *)calloc(max_levels, sizeof(cl_mem *)); g->dev_processed = (cl_mem **)calloc(num_gamma, sizeof(cl_mem **)); - for(int k=0;k<num_gamma;k++) - g->dev_processed[k] = (cl_mem *)calloc(max_levels, sizeof(cl_mem *)); + for(int k = 0; k < num_gamma; k++) g->dev_processed[k] = (cl_mem *)calloc(max_levels, sizeof(cl_mem *)); - g->num_levels = MIN(max_levels, 31-__builtin_clz(MIN(width,height))); - const int max_supp = 1<<(g->num_levels-1); - const int paddwd = width + 2*max_supp; - const int paddht = height + 2*max_supp; + g->num_levels = MIN(max_levels, 31 - __builtin_clz(MIN(width, height))); + const int max_supp = 1 << (g->num_levels - 1); + const int paddwd = width + 2 * max_supp; + const int paddht = height + 2 * max_supp; const size_t bwidth = ROUNDUPWD(paddwd); const size_t bheight = ROUNDUPWD(paddht); // get intermediate vector buffers with read-write access - for(int l=0;l<g->num_levels;l++) + for(int l = 0; l < g->num_levels; l++) { - g->dev_padded[l] = dt_opencl_alloc_device(devid, ROUNDUPWD(dl(bwidth, l)), ROUNDUPHT(dl(bheight, l)), sizeof(float)); + g->dev_padded[l] + = dt_opencl_alloc_device(devid, ROUNDUPWD(dl(bwidth, l)), ROUNDUPHT(dl(bheight, l)), sizeof(float)); if(!g->dev_padded[l]) goto error; - g->dev_output[l] = dt_opencl_alloc_device(devid, ROUNDUPWD(dl(bwidth, l)), ROUNDUPHT(dl(bheight, l)), sizeof(float)); + g->dev_output[l] + = dt_opencl_alloc_device(devid, ROUNDUPWD(dl(bwidth, l)), ROUNDUPHT(dl(bheight, l)), sizeof(float)); if(!g->dev_output[l]) goto error; - for(int k=0;k<num_gamma;k++) + for(int k = 0; k < num_gamma; k++) { - g->dev_processed[k][l] = dt_opencl_alloc_device(devid, ROUNDUPWD(dl(bwidth, l)), ROUNDUPHT(dl(bheight, l)), sizeof(float)); + g->dev_processed[k][l] + = dt_opencl_alloc_device(devid, ROUNDUPWD(dl(bwidth, l)), ROUNDUPHT(dl(bheight, l)), sizeof(float)); if(!g->dev_processed[k][l]) goto error; } } @@ -124,14 +125,13 @@ dt_local_laplacian_cl_t *dt_local_laplacian_init_cl( return 0; } -cl_int dt_local_laplacian_cl( - dt_local_laplacian_cl_t *b, // opencl context with temp buffers - cl_mem input, // input buffer in some Labx or yuvx format - cl_mem output) // output buffer with colour +cl_int dt_local_laplacian_cl(dt_local_laplacian_cl_t *b, // opencl context with temp buffers + cl_mem input, // input buffer in some Labx or yuvx format + cl_mem output) // output buffer with colour { - const int max_supp = 1<<(b->num_levels-1); - const int wd2 = 2*max_supp + b->width; - const int ht2 = 2*max_supp + b->height; + const int max_supp = 1 << (b->num_levels - 1); + const int wd2 = 2 * max_supp + b->width; + const int ht2 = 2 * max_supp + b->height; cl_int err = -666; size_t sizes_pad[] = { ROUNDUPWD(wd2), ROUNDUPHT(ht2), 1 }; @@ -146,26 +146,31 @@ cl_int dt_local_laplacian_cl( if(err != CL_SUCCESS) goto error; // create gauss pyramid of padded input, write coarse directly to output - for(int l=1;l<b->num_levels;l++) + for(int l = 1; l < b->num_levels; l++) { const int wd = dl(wd2, l), ht = dl(ht2, l); size_t sizes[] = { ROUNDUPWD(wd), ROUNDUPHT(ht), 1 }; - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_gauss_reduce, 0, sizeof(cl_mem), (void *)&b->dev_padded[l-1]); - if(l == b->num_levels-1) - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_gauss_reduce, 1, sizeof(cl_mem), (void *)&b->dev_output[l]); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_gauss_reduce, 0, sizeof(cl_mem), + (void *)&b->dev_padded[l - 1]); + if(l == b->num_levels - 1) + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_gauss_reduce, 1, sizeof(cl_mem), + (void *)&b->dev_output[l]); else - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_gauss_reduce, 1, sizeof(cl_mem), (void *)&b->dev_padded[l]); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_gauss_reduce, 1, sizeof(cl_mem), + (void *)&b->dev_padded[l]); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_gauss_reduce, 2, sizeof(int), (void *)&wd); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_gauss_reduce, 3, sizeof(int), (void *)&ht); err = dt_opencl_enqueue_kernel_2d(b->devid, b->global->kernel_gauss_reduce, sizes); if(err != CL_SUCCESS) goto error; } - for(int k=0;k<num_gamma;k++) + for(int k = 0; k < num_gamma; k++) { // process images - const float g = (k+.5f)/(float)num_gamma; - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_process_curve, 0, sizeof(cl_mem), (void *)&b->dev_padded[0]); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_process_curve, 1, sizeof(cl_mem), (void *)&b->dev_processed[k][0]); + const float g = (k + .5f) / (float)num_gamma; + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_process_curve, 0, sizeof(cl_mem), + (void *)&b->dev_padded[0]); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_process_curve, 1, sizeof(cl_mem), + (void *)&b->dev_processed[k][0]); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_process_curve, 2, sizeof(float), (void *)&g); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_process_curve, 3, sizeof(float), (void *)&b->sigma); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_process_curve, 4, sizeof(float), (void *)&b->shadows); @@ -177,12 +182,14 @@ cl_int dt_local_laplacian_cl( if(err != CL_SUCCESS) goto error; // create gaussian pyramids - for(int l=1;l<b->num_levels;l++) + for(int l = 1; l < b->num_levels; l++) { const int wd = dl(wd2, l), ht = dl(ht2, l); size_t sizes[] = { ROUNDUPWD(wd), ROUNDUPHT(ht), 1 }; - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_gauss_reduce, 0, sizeof(cl_mem), (void *)&b->dev_processed[k][l-1]); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_gauss_reduce, 1, sizeof(cl_mem), (void *)&b->dev_processed[k][l]); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_gauss_reduce, 0, sizeof(cl_mem), + (void *)&b->dev_processed[k][l - 1]); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_gauss_reduce, 1, sizeof(cl_mem), + (void *)&b->dev_processed[k][l]); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_gauss_reduce, 2, sizeof(int), (void *)&wd); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_gauss_reduce, 3, sizeof(int), (void *)&ht); err = dt_opencl_enqueue_kernel_2d(b->devid, b->global->kernel_gauss_reduce, sizes); @@ -191,30 +198,49 @@ cl_int dt_local_laplacian_cl( } // assemble output pyramid coarse to fine - for(int l=b->num_levels-2;l >= 0; l--) + for(int l = b->num_levels - 2; l >= 0; l--) { - const int pw = dl(wd2,l), ph = dl(ht2,l); + const int pw = dl(wd2, l), ph = dl(ht2, l); size_t sizes[] = { ROUNDUPWD(pw), ROUNDUPHT(ph), 1 }; // this is so dumb: - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 0, sizeof(cl_mem), (void *)&b->dev_padded[l]); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 1, sizeof(cl_mem), (void *)&b->dev_output[l+1]); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 2, sizeof(cl_mem), (void *)&b->dev_output[l]); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 3, sizeof(cl_mem), (void *)&b->dev_processed[0][l]); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 4, sizeof(cl_mem), (void *)&b->dev_processed[0][l+1]); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 5, sizeof(cl_mem), (void *)&b->dev_processed[1][l]); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 6, sizeof(cl_mem), (void *)&b->dev_processed[1][l+1]); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 7, sizeof(cl_mem), (void *)&b->dev_processed[2][l]); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 8, sizeof(cl_mem), (void *)&b->dev_processed[2][l+1]); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 9, sizeof(cl_mem), (void *)&b->dev_processed[3][l]); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 10, sizeof(cl_mem), (void *)&b->dev_processed[3][l+1]); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 11, sizeof(cl_mem), (void *)&b->dev_processed[4][l]); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 12, sizeof(cl_mem), (void *)&b->dev_processed[4][l+1]); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 13, sizeof(cl_mem), (void *)&b->dev_processed[5][l]); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 14, sizeof(cl_mem), (void *)&b->dev_processed[5][l+1]); - // dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 15, sizeof(cl_mem), (void *)&b->dev_processed[6][l]); - // dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 16, sizeof(cl_mem), (void *)&b->dev_processed[6][l+1]); - // dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 17, sizeof(cl_mem), (void *)&b->dev_processed[7][l]); - // dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 18, sizeof(cl_mem), (void *)&b->dev_processed[7][l+1]); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 0, sizeof(cl_mem), + (void *)&b->dev_padded[l]); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 1, sizeof(cl_mem), + (void *)&b->dev_output[l + 1]); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 2, sizeof(cl_mem), + (void *)&b->dev_output[l]); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 3, sizeof(cl_mem), + (void *)&b->dev_processed[0][l]); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 4, sizeof(cl_mem), + (void *)&b->dev_processed[0][l + 1]); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 5, sizeof(cl_mem), + (void *)&b->dev_processed[1][l]); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 6, sizeof(cl_mem), + (void *)&b->dev_processed[1][l + 1]); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 7, sizeof(cl_mem), + (void *)&b->dev_processed[2][l]); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 8, sizeof(cl_mem), + (void *)&b->dev_processed[2][l + 1]); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 9, sizeof(cl_mem), + (void *)&b->dev_processed[3][l]); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 10, sizeof(cl_mem), + (void *)&b->dev_processed[3][l + 1]); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 11, sizeof(cl_mem), + (void *)&b->dev_processed[4][l]); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 12, sizeof(cl_mem), + (void *)&b->dev_processed[4][l + 1]); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 13, sizeof(cl_mem), + (void *)&b->dev_processed[5][l]); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 14, sizeof(cl_mem), + (void *)&b->dev_processed[5][l + 1]); + // dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 15, sizeof(cl_mem), (void + // *)&b->dev_processed[6][l]); + // dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 16, sizeof(cl_mem), (void + // *)&b->dev_processed[6][l+1]); + // dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 17, sizeof(cl_mem), (void + // *)&b->dev_processed[7][l]); + // dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 18, sizeof(cl_mem), (void + // *)&b->dev_processed[7][l+1]); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 15, sizeof(int), (void *)&pw); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_laplacian_assemble, 16, sizeof(int), (void *)&ph); err = dt_opencl_enqueue_kernel_2d(b->devid, b->global->kernel_laplacian_assemble, sizes); diff --git a/src/common/locallaplaciancl.h b/src/common/locallaplaciancl.h index d8014e0fd5de..88f4c0975e1b 100644 --- a/src/common/locallaplaciancl.h +++ b/src/common/locallaplaciancl.h @@ -25,8 +25,7 @@ typedef struct dt_local_laplacian_cl_global_t int kernel_laplacian_assemble; int kernel_process_curve; int kernel_write_back; -} -dt_local_laplacian_cl_global_t; +} dt_local_laplacian_cl_global_t; typedef struct dt_local_laplacian_cl_t { @@ -46,18 +45,17 @@ typedef struct dt_local_laplacian_cl_t // one pyramid of padded monochrome buffers for every value // of gamma (curve parameter) that we process: cl_mem **dev_processed; -} -dt_local_laplacian_cl_t; +} dt_local_laplacian_cl_t; dt_local_laplacian_cl_global_t *dt_local_laplacian_init_cl_global(); -dt_local_laplacian_cl_t *dt_local_laplacian_init_cl( - const int devid, - const int width, // width of input image - const int height, // height of input image - const float sigma, // user param: separate shadows/midtones/highlights - const float shadows, // user param: lift shadows - const float highlights, // user param: compress highlights - const float clarity); // user param: increase clarity/local contrast +dt_local_laplacian_cl_t * +dt_local_laplacian_init_cl(const int devid, + const int width, // width of input image + const int height, // height of input image + const float sigma, // user param: separate shadows/midtones/highlights + const float shadows, // user param: lift shadows + const float highlights, // user param: compress highlights + const float clarity); // user param: increase clarity/local contrast void dt_local_laplacian_free_cl(dt_local_laplacian_cl_t *g); cl_int dt_local_laplacian_cl(dt_local_laplacian_cl_t *g, cl_mem input, cl_mem output); #endif diff --git a/src/common/metadata.c b/src/common/metadata.c index 399d7e05f267..59609d698ca4 100644 --- a/src/common/metadata.c +++ b/src/common/metadata.c @@ -148,8 +148,8 @@ static GList *dt_metadata_get_xmp(int id, const char *key, uint32_t *count) else // single image under mouse cursor { DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), - "SELECT color FROM main.color_labels WHERE imgid=?1 ORDER BY color", - -1, &stmt, NULL); + "SELECT color FROM main.color_labels WHERE imgid=?1 ORDER BY color", -1, &stmt, + NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id); } while(sqlite3_step(stmt) == SQLITE_ROW) @@ -242,9 +242,9 @@ static GList *dt_metadata_get_exif(int id, const char *key, uint32_t *count) { if(id == -1) { - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), - "SELECT iso FROM main.images WHERE id IN " - "(SELECT imgid FROM main.selected_images)", -1, &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT iso FROM main.images WHERE id IN " + "(SELECT imgid FROM main.selected_images)", + -1, &stmt, NULL); } else // single image under mouse cursor { diff --git a/src/common/mipmap_cache.c b/src/common/mipmap_cache.c index aa947309be3a..079fc529e975 100644 --- a/src/common/mipmap_cache.c +++ b/src/common/mipmap_cache.c @@ -45,8 +45,8 @@ #if !defined(_WIN32) #include <sys/statvfs.h> -#else -//statvfs does not exist in Windows, providing implementation +#else +// statvfs does not exist in Windows, providing implementation #include "win/statvfs.h" #endif @@ -62,20 +62,18 @@ typedef enum dt_mipmap_buffer_dsc_flags } dt_mipmap_buffer_dsc_flags; // the embedded Exif data to tag thumbnails as sRGB or AdobeRGB -static const uint8_t dt_mipmap_cache_exif_data_srgb[] = { - 0x45, 0x78, 0x69, 0x66, 0x00, 0x00, 0x49, 0x49, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x69, - 0x87, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, - 0x01, 0xa0, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; -static const uint8_t dt_mipmap_cache_exif_data_adobergb[] = { - 0x45, 0x78, 0x69, 0x66, 0x00, 0x00, 0x49, 0x49, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x69, - 0x87, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, - 0x01, 0xa0, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; -static const int dt_mipmap_cache_exif_data_srgb_length - = sizeof(dt_mipmap_cache_exif_data_srgb) / sizeof(*dt_mipmap_cache_exif_data_srgb); -static const int dt_mipmap_cache_exif_data_adobergb_length - = sizeof(dt_mipmap_cache_exif_data_adobergb) / sizeof(*dt_mipmap_cache_exif_data_adobergb); +static const uint8_t dt_mipmap_cache_exif_data_srgb[] + = { 0x45, 0x78, 0x69, 0x66, 0x00, 0x00, 0x49, 0x49, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x69, + 0x87, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x01, 0xa0, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +static const uint8_t dt_mipmap_cache_exif_data_adobergb[] + = { 0x45, 0x78, 0x69, 0x66, 0x00, 0x00, 0x49, 0x49, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x69, + 0x87, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x01, 0xa0, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +static const int dt_mipmap_cache_exif_data_srgb_length = sizeof(dt_mipmap_cache_exif_data_srgb) + / sizeof(*dt_mipmap_cache_exif_data_srgb); +static const int dt_mipmap_cache_exif_data_adobergb_length = sizeof(dt_mipmap_cache_exif_data_adobergb) + / sizeof(*dt_mipmap_cache_exif_data_adobergb); struct dt_mipmap_buffer_dsc { @@ -362,7 +360,7 @@ void dt_mipmap_cache_allocate_dynamic(void *data, dt_cache_entry_t *entry) if(cache->cachedir[0] && dt_conf_get_bool("cache_disk_backend")) { // try and load from disk, if successful set flag - char filename[PATH_MAX] = {0}; + char filename[PATH_MAX] = { 0 }; snprintf(filename, sizeof(filename), "%s.d/%d/%d.jpg", cache->cachedir, mip, get_imgid(entry->key)); FILE *f = g_fopen(filename, "rb"); if(f) @@ -381,10 +379,12 @@ void dt_mipmap_cache_allocate_dynamic(void *data, dt_cache_entry_t *entry) dt_imageio_jpeg_t jpg; if(dt_imageio_jpeg_decompress_header(blob, len, &jpg) || (jpg.width > cache->max_width[mip] || jpg.height > cache->max_height[mip]) - || ((color_space = dt_imageio_jpeg_read_color_space(&jpg)) == DT_COLORSPACE_NONE) // pointless test to keep it in the if clause + || ((color_space = dt_imageio_jpeg_read_color_space(&jpg)) + == DT_COLORSPACE_NONE) // pointless test to keep it in the if clause || dt_imageio_jpeg_decompress(&jpg, entry->data + sizeof(*dsc))) { - fprintf(stderr, "[mipmap_cache] failed to decompress thumbnail for image %d from `%s'!\n", get_imgid(entry->key), filename); + fprintf(stderr, "[mipmap_cache] failed to decompress thumbnail for image %d from `%s'!\n", + get_imgid(entry->key), filename); goto read_error; } dsc->width = jpg.width; @@ -394,7 +394,7 @@ void dt_mipmap_cache_allocate_dynamic(void *data, dt_cache_entry_t *entry) loaded_from_disk = 1; if(0) { -read_error: + read_error: g_unlink(filename); } free(blob); @@ -405,12 +405,15 @@ void dt_mipmap_cache_allocate_dynamic(void *data, dt_cache_entry_t *entry) if(!loaded_from_disk) dsc->flags = DT_MIPMAP_BUFFER_DSC_FLAG_GENERATE; - else dsc->flags = 0; + else + dsc->flags = 0; // cost is just flat one for the buffer, as the buffers might have different sizes, // to make sure quota is meaningful. - if(mip >= DT_MIPMAP_F) entry->cost = 1; - else entry->cost = cache->buffer_size[mip]; + if(mip >= DT_MIPMAP_F) + entry->cost = 1; + else + entry->cost = cache->buffer_size[mip]; } static void dt_mipmap_cache_unlink_ondisk_thumbnail(void *data, uint32_t imgid, dt_mipmap_size_t mip) @@ -445,7 +448,7 @@ void dt_mipmap_cache_deallocate_dynamic(void *data, dt_cache_entry_t *entry) else if(cache->cachedir[0] && dt_conf_get_bool("cache_disk_backend")) { // serialize to disk - char filename[PATH_MAX] = {0}; + char filename[PATH_MAX] = { 0 }; snprintf(filename, sizeof(filename), "%s.d/%d", cache->cachedir, mip); int mkd = g_mkdir_with_parents(filename, 0750); if(!mkd) @@ -453,22 +456,24 @@ void dt_mipmap_cache_deallocate_dynamic(void *data, dt_cache_entry_t *entry) snprintf(filename, sizeof(filename), "%s.d/%d/%d.jpg", cache->cachedir, mip, get_imgid(entry->key)); // Don't write existing files as both performance and quality (lossy jpg) suffer FILE *f = NULL; - if (!g_file_test(filename, G_FILE_TEST_EXISTS) && (f = g_fopen(filename, "wb"))) + if(!g_file_test(filename, G_FILE_TEST_EXISTS) && (f = g_fopen(filename, "wb"))) { // first check the disk isn't full struct statvfs vfsbuf; - if (!statvfs(filename, &vfsbuf)) + if(!statvfs(filename, &vfsbuf)) { int64_t free_mb = ((vfsbuf.f_frsize * vfsbuf.f_bavail) >> 20); - if (free_mb < 100) + if(free_mb < 100) { - fprintf(stderr, "Aborting image write as only %" PRId64 " MB free to write %s\n", free_mb, filename); + fprintf(stderr, "Aborting image write as only %" PRId64 " MB free to write %s\n", free_mb, + filename); goto write_error; } } else { - fprintf(stderr, "Aborting image write since couldn't determine free space available to write %s\n", filename); + fprintf(stderr, "Aborting image write since couldn't determine free space available to write %s\n", + filename); goto write_error; } @@ -485,9 +490,10 @@ void dt_mipmap_cache_deallocate_dynamic(void *data, dt_cache_entry_t *entry) exif = dt_mipmap_cache_exif_data_adobergb; exif_len = dt_mipmap_cache_exif_data_adobergb_length; } - if(dt_imageio_jpeg_write(filename, entry->data + sizeof(*dsc), dsc->width, dsc->height, MIN(100, MAX(10, cache_quality)), exif, exif_len)) + if(dt_imageio_jpeg_write(filename, entry->data + sizeof(*dsc), dsc->width, dsc->height, + MIN(100, MAX(10, cache_quality)), exif, exif_len)) { -write_error: + write_error: g_unlink(filename); } } @@ -522,28 +528,27 @@ void dt_mipmap_cache_init(dt_mipmap_cache_t *cache) // Fixed sizes for the thumbnail mip levels, selected for coverage of most screen sizes int32_t mipsizes[DT_MIPMAP_F][2] = { - {180, 110}, // mip0 - ~1/2 size previous one - {360, 225}, // mip1 - 1/2 size previous one - {720, 450}, // mip2 - 1/2 size previous one - {1440, 900}, // mip3 - covers 720p and 1366x768 - {1920, 1200}, // mip4 - covers 1080p and 1600x1200 - {2560, 1600}, // mip5 - covers 2560x1440 - {4096, 2560}, // mip6 - covers 4K and UHD - {5120, 3200}, // mip7 - covers 5120x2880 panels + { 180, 110 }, // mip0 - ~1/2 size previous one + { 360, 225 }, // mip1 - 1/2 size previous one + { 720, 450 }, // mip2 - 1/2 size previous one + { 1440, 900 }, // mip3 - covers 720p and 1366x768 + { 1920, 1200 }, // mip4 - covers 1080p and 1600x1200 + { 2560, 1600 }, // mip5 - covers 2560x1440 + { 4096, 2560 }, // mip6 - covers 4K and UHD + { 5120, 3200 }, // mip7 - covers 5120x2880 panels }; // Set mipf to mip2 size as at most the user will be using an 8K screen and // have a preview that's ~4x smaller cache->max_width[DT_MIPMAP_F] = mipsizes[DT_MIPMAP_2][0]; cache->max_height[DT_MIPMAP_F] = mipsizes[DT_MIPMAP_2][1]; - for(int k = DT_MIPMAP_F-1; k >= 0; k--) + for(int k = DT_MIPMAP_F - 1; k >= 0; k--) { - cache->max_width[k] = mipsizes[k][0]; + cache->max_width[k] = mipsizes[k][0]; cache->max_height[k] = mipsizes[k][1]; } - // header + buffer - for(int k = DT_MIPMAP_F-1; k >= 0; k--) - cache->buffer_size[k] = sizeof(struct dt_mipmap_buffer_dsc) - + cache->max_width[k] * cache->max_height[k] * 4; + // header + buffer + for(int k = DT_MIPMAP_F - 1; k >= 0; k--) + cache->buffer_size[k] = sizeof(struct dt_mipmap_buffer_dsc) + cache->max_width[k] * cache->max_height[k] * 4; // clear stats: cache->mip_thumbs.stats_requests = 0; @@ -581,7 +586,7 @@ void dt_mipmap_cache_init(dt_mipmap_cache_t *cache) dt_cache_set_allocate_callback(&cache->mip_f.cache, dt_mipmap_cache_allocate_dynamic, cache); dt_cache_set_cleanup_callback(&cache->mip_f.cache, dt_mipmap_cache_deallocate_dynamic, cache); cache->buffer_size[DT_MIPMAP_F] = sizeof(struct dt_mipmap_buffer_dsc) - + 4 * sizeof(float) * cache->max_width[DT_MIPMAP_F] + + 4 * sizeof(float) * cache->max_width[DT_MIPMAP_F] * cache->max_height[DT_MIPMAP_F]; } @@ -594,15 +599,14 @@ void dt_mipmap_cache_cleanup(dt_mipmap_cache_t *cache) void dt_mipmap_cache_print(dt_mipmap_cache_t *cache) { - printf("[mipmap_cache] thumbs fill %.2f/%.2f MB (%.2f%%)\n", - cache->mip_thumbs.cache.cost / (1024.0 * 1024.0), + printf("[mipmap_cache] thumbs fill %.2f/%.2f MB (%.2f%%)\n", cache->mip_thumbs.cache.cost / (1024.0 * 1024.0), cache->mip_thumbs.cache.cost_quota / (1024.0 * 1024.0), 100.0f * (float)cache->mip_thumbs.cache.cost / (float)cache->mip_thumbs.cache.cost_quota); - printf("[mipmap_cache] float fill %d/%d slots (%.2f%%)\n", - (uint32_t)cache->mip_f.cache.cost, (uint32_t)cache->mip_f.cache.cost_quota, + printf("[mipmap_cache] float fill %d/%d slots (%.2f%%)\n", (uint32_t)cache->mip_f.cache.cost, + (uint32_t)cache->mip_f.cache.cost_quota, 100.0f * (float)cache->mip_f.cache.cost / (float)cache->mip_f.cache.cost_quota); - printf("[mipmap_cache] full fill %d/%d slots (%.2f%%)\n", - (uint32_t)cache->mip_full.cache.cost, (uint32_t)cache->mip_full.cache.cost_quota, + printf("[mipmap_cache] full fill %d/%d slots (%.2f%%)\n", (uint32_t)cache->mip_full.cache.cost, + (uint32_t)cache->mip_full.cache.cost_quota, 100.0f * (float)cache->mip_full.cache.cost / (float)cache->mip_full.cache.cost_quota); uint64_t sum = 0; @@ -658,15 +662,9 @@ static dt_mipmap_cache_one_t *_get_cache(dt_mipmap_cache_t *cache, const dt_mipm } } -void dt_mipmap_cache_get_with_caller( - dt_mipmap_cache_t *cache, - dt_mipmap_buffer_t *buf, - const uint32_t imgid, - const dt_mipmap_size_t mip, - const dt_mipmap_get_flags_t flags, - const char mode, - const char *file, - int line) +void dt_mipmap_cache_get_with_caller(dt_mipmap_cache_t *cache, dt_mipmap_buffer_t *buf, const uint32_t imgid, + const dt_mipmap_size_t mip, const dt_mipmap_get_flags_t flags, + const char mode, const char *file, int line) { const uint32_t key = get_key(imgid, mip); if(flags == DT_MIPMAP_TESTLOCK) @@ -714,7 +712,7 @@ void dt_mipmap_cache_get_with_caller( if(!cache->cachedir[0]) return; if(mip > DT_MIPMAP_FULL || (int)mip < DT_MIPMAP_0) return; // remove the (int) once we no longer have to support gcc < 4.8 :/ - char filename[PATH_MAX] = {0}; + char filename[PATH_MAX] = { 0 }; snprintf(filename, sizeof(filename), "%s.d/%d/%d.jpg", cache->cachedir, mip, key); // don't attempt to load if disk cache doesn't exist if(!g_file_test(filename, G_FILE_TEST_EXISTS)) return; @@ -723,7 +721,7 @@ void dt_mipmap_cache_get_with_caller( else if(flags == DT_MIPMAP_BLOCKING) { // simple case: blocking get - dt_cache_entry_t *entry = dt_cache_get_with_caller(&_get_cache(cache, mip)->cache, key, mode, file, line); + dt_cache_entry_t *entry = dt_cache_get_with_caller(&_get_cache(cache, mip)->cache, key, mode, file, line); ASAN_UNPOISON_MEMORY_REGION(entry->data, dt_mipmap_buffer_dsc_size); @@ -857,7 +855,8 @@ void dt_mipmap_cache_get_with_caller( else if(mip == DT_MIPMAP_F) dead_image_f(buf); else - buf->buf = NULL; // full images with NULL buffer have to be handled, indicates `missing image', but still return locked slot + buf->buf = NULL; // full images with NULL buffer have to be handled, indicates `missing image', but still + // return locked slot } } else if(flags == DT_MIPMAP_BEST_EFFORT) @@ -882,9 +881,10 @@ void dt_mipmap_cache_get_with_caller( dt_mipmap_cache_get(cache, buf, imgid, mip, DT_MIPMAP_PREFETCH, 'r'); } } - // couldn't find a smaller thumb, try larger ones only now (these will be slightly slower due to cairo rescaling): - dt_mipmap_size_t max_mip = (mip >= DT_MIPMAP_F) ? mip : DT_MIPMAP_F-1; - for(int k = mip+1; k <= max_mip; k++) + // couldn't find a smaller thumb, try larger ones only now (these will be slightly slower due to cairo + // rescaling): + dt_mipmap_size_t max_mip = (mip >= DT_MIPMAP_F) ? mip : DT_MIPMAP_F - 1; + for(int k = mip + 1; k <= max_mip; k++) { // already loaded? dt_mipmap_cache_get(cache, buf, imgid, k, DT_MIPMAP_TESTLOCK, 'r'); @@ -899,7 +899,7 @@ void dt_mipmap_cache_get_with_caller( // prefetch at least mip0, in case we have that in the disk caches: if(cache->cachedir[0]) { - char filename[PATH_MAX] = {0}; + char filename[PATH_MAX] = { 0 }; snprintf(filename, sizeof(filename), "%s.d/%d/%d.jpg", cache->cachedir, mip, key); if(g_file_test(filename, G_FILE_TEST_EXISTS)) dt_mipmap_cache_get(cache, 0, imgid, DT_MIPMAP_0, DT_MIPMAP_PREFETCH_DISK, 0); @@ -914,7 +914,8 @@ void dt_mipmap_cache_get_with_caller( } } -void dt_mipmap_cache_write_get_with_caller(dt_mipmap_cache_t *cache, dt_mipmap_buffer_t *buf, const uint32_t imgid, const int mip, const char *file, int line) +void dt_mipmap_cache_write_get_with_caller(dt_mipmap_cache_t *cache, dt_mipmap_buffer_t *buf, const uint32_t imgid, + const int mip, const char *file, int line) { dt_mipmap_cache_get_with_caller(cache, buf, imgid, mip, DT_MIPMAP_BLOCKING, 'w', file, line); } @@ -1186,13 +1187,12 @@ static void _init_8(uint8_t *buf, uint32_t *width, uint32_t *height, float *isca if(res) { - //try to generate mip from larger mip + // try to generate mip from larger mip for(dt_mipmap_size_t k = size + 1; k <= DT_MIPMAP_7; k++) { dt_mipmap_buffer_t tmp; dt_mipmap_cache_get(darktable.mipmap_cache, &tmp, imgid, k, DT_MIPMAP_TESTLOCK, 'r'); - if(tmp.buf == NULL) - continue; + if(tmp.buf == NULL) continue; dt_print(DT_DEBUG_CACHE, "[_init_8] generate mip %d for %s from level %d\n", size, filename, k); *color_space = tmp.color_space; // downsample @@ -1250,20 +1250,20 @@ static void _init_8(uint8_t *buf, uint32_t *width, uint32_t *height, float *isca dt_colorspaces_color_profile_type_t dt_mipmap_cache_get_colorspace() { - if(dt_conf_get_bool("cache_color_managed")) - return DT_COLORSPACE_ADOBERGB; + if(dt_conf_get_bool("cache_color_managed")) return DT_COLORSPACE_ADOBERGB; return DT_COLORSPACE_DISPLAY; } -void dt_mipmap_cache_copy_thumbnails(const dt_mipmap_cache_t *cache, const uint32_t dst_imgid, const uint32_t src_imgid) +void dt_mipmap_cache_copy_thumbnails(const dt_mipmap_cache_t *cache, const uint32_t dst_imgid, + const uint32_t src_imgid) { if(cache->cachedir[0] && dt_conf_get_bool("cache_disk_backend")) { for(dt_mipmap_size_t mip = DT_MIPMAP_0; mip < DT_MIPMAP_F; mip++) { // try and load from disk, if successful set flag - char srcpath[PATH_MAX] = {0}; - char dstpath[PATH_MAX] = {0}; + char srcpath[PATH_MAX] = { 0 }; + char dstpath[PATH_MAX] = { 0 }; snprintf(srcpath, sizeof(srcpath), "%s.d/%d/%d.jpg", cache->cachedir, mip, src_imgid); snprintf(dstpath, sizeof(dstpath), "%s.d/%d/%d.jpg", cache->cachedir, mip, dst_imgid); GFile *src = g_file_new_for_path(srcpath); diff --git a/src/common/mipmap_cache.h b/src/common/mipmap_cache.h index 67875951d3fa..da052f857c74 100644 --- a/src/common/mipmap_cache.h +++ b/src/common/mipmap_cache.h @@ -113,26 +113,15 @@ void dt_mipmap_cache_print(dt_mipmap_cache_t *cache); // get a buffer and lock according to mode ('r' or 'w'). // see dt_mipmap_get_flags_t for explanation of the exact // behaviour. pass 0 as flags for the default (best effort) -#define dt_mipmap_cache_get(A,B,C,D,E,F) dt_mipmap_cache_get_with_caller(A,B,C,D,E,F,__FILE__,__LINE__) -void dt_mipmap_cache_get_with_caller( - dt_mipmap_cache_t *cache, - dt_mipmap_buffer_t *buf, - const uint32_t imgid, - const dt_mipmap_size_t mip, - const dt_mipmap_get_flags_t flags, - const char mode, - const char *file, - int line); +#define dt_mipmap_cache_get(A, B, C, D, E, F) dt_mipmap_cache_get_with_caller(A, B, C, D, E, F, __FILE__, __LINE__) +void dt_mipmap_cache_get_with_caller(dt_mipmap_cache_t *cache, dt_mipmap_buffer_t *buf, const uint32_t imgid, + const dt_mipmap_size_t mip, const dt_mipmap_get_flags_t flags, + const char mode, const char *file, int line); // convenience function with fewer params -#define dt_mipmap_cache_write_get(A,B,C,D) dt_mipmap_cache_write_get_with_caller(A,B,C,D,__FILE__,__LINE__) -void dt_mipmap_cache_write_get_with_caller( - dt_mipmap_cache_t *cache, - dt_mipmap_buffer_t *buf, - const uint32_t imgid, - const int mip, - const char *file, - int line); +#define dt_mipmap_cache_write_get(A, B, C, D) dt_mipmap_cache_write_get_with_caller(A, B, C, D, __FILE__, __LINE__) +void dt_mipmap_cache_write_get_with_caller(dt_mipmap_cache_t *cache, dt_mipmap_buffer_t *buf, const uint32_t imgid, + const int mip, const char *file, int line); // drop a lock #define dt_mipmap_cache_release(A, B) dt_mipmap_cache_release_with_caller(A, B, __FILE__, __LINE__) @@ -151,17 +140,16 @@ void dt_mimap_cache_evict(dt_mipmap_cache_t *cache, const uint32_t imgid); // depending on the user parameter for the maximum thumbnail dimensions. // actual resolution depends on the image and is only known after // the thumbnail is loaded. -dt_mipmap_size_t dt_mipmap_cache_get_matching_size( - const dt_mipmap_cache_t *cache, - const int32_t width, - const int32_t height); +dt_mipmap_size_t dt_mipmap_cache_get_matching_size(const dt_mipmap_cache_t *cache, const int32_t width, + const int32_t height); // returns the colorspace to use for created thumbnails, takes config into account dt_colorspaces_color_profile_type_t dt_mipmap_cache_get_colorspace(); // copy over thumbnails. used by file operation that copies raw files, to speed up thumbnail generation. // only copies over the jpg backend on disk, doesn't directly affect the in-memory cache. -void dt_mipmap_cache_copy_thumbnails(const dt_mipmap_cache_t *cache, const uint32_t dst_imgid, const uint32_t src_imgid); +void dt_mipmap_cache_copy_thumbnails(const dt_mipmap_cache_t *cache, const uint32_t dst_imgid, + const uint32_t src_imgid); // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh // vim: shiftwidth=2 expandtab tabstop=2 cindent diff --git a/src/common/module.c b/src/common/module.c index b6ed9aae9d60..2a4cc2f1efd2 100644 --- a/src/common/module.c +++ b/src/common/module.c @@ -62,7 +62,7 @@ GList *dt_module_load_modules(const char *subdir, size_t module_size, if(sort_modules) plugin_list = g_list_sort(plugin_list, sort_modules); - return plugin_list; + return plugin_list; } // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh diff --git a/src/common/noiseprofiles.c b/src/common/noiseprofiles.c index 23099850893e..f1f75c5362d9 100644 --- a/src/common/noiseprofiles.c +++ b/src/common/noiseprofiles.c @@ -24,7 +24,8 @@ // bump this when the noiseprofiles are getting a differen layout or meaning (raw-raw data, ...) #define DT_NOISE_PROFILE_VERSION 0 -const dt_noiseprofile_t dt_noiseprofile_generic = {N_("generic poissonian"), "", "", 0, {0.0001f, 0.0001f, 0.0001}, {0.0f, 0.0f, 0.0f}}; +const dt_noiseprofile_t dt_noiseprofile_generic + = { N_("generic poissonian"), "", "", 0, { 0.0001f, 0.0001f, 0.0001 }, { 0.0f, 0.0f, 0.0f } }; static gboolean dt_noiseprofile_verify(JsonParser *parser); @@ -60,7 +61,9 @@ JsonParser *dt_noiseprofile_init(const char *alternative) if(!dt_noiseprofile_verify(parser)) { dt_control_log(_("noiseprofile file `%s' is not valid"), filename); - fprintf(stderr, "[noiseprofile] error: `%s' is not a valid noiseprofile file. run with -d control for details\n", filename); + fprintf(stderr, + "[noiseprofile] error: `%s' is not a valid noiseprofile file. run with -d control for details\n", + filename); g_object_unref(parser); return NULL; } @@ -68,12 +71,11 @@ JsonParser *dt_noiseprofile_init(const char *alternative) return parser; } -int is_member(gchar** names, char* name) +int is_member(gchar **names, char *name) { while(*names) { - if(!g_strcmp0(*names, name)) - return 1; + if(!g_strcmp0(*names, name)) return 1; names++; } return 0; @@ -87,13 +89,14 @@ static gint _sort_by_iso(gconstpointer a, gconstpointer b) return profile_a->iso - profile_b->iso; } -#define _ERROR(...) {\ - dt_print(DT_DEBUG_CONTROL, "[noiseprofile] error: " );\ - dt_print(DT_DEBUG_CONTROL, __VA_ARGS__);\ - dt_print(DT_DEBUG_CONTROL, "\n");\ - valid = FALSE;\ - goto end;\ - } +#define _ERROR(...) \ + { \ + dt_print(DT_DEBUG_CONTROL, "[noiseprofile] error: "); \ + dt_print(DT_DEBUG_CONTROL, __VA_ARGS__); \ + dt_print(DT_DEBUG_CONTROL, "\n"); \ + valid = FALSE; \ + goto end; \ + } static gboolean dt_noiseprofile_verify(JsonParser *parser) { @@ -126,7 +129,7 @@ static gboolean dt_noiseprofile_verify(JsonParser *parser) dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found %d makers\n", n_makers); for(int i = 0; i < n_makers; i++) { - if(!json_reader_read_element(reader, i)) _ERROR("can't access maker at position %d / %d", i+1, n_makers); + if(!json_reader_read_element(reader, i)) _ERROR("can't access maker at position %d / %d", i + 1, n_makers); if(!json_reader_read_member(reader, "maker")) _ERROR("missing `maker`"); @@ -141,7 +144,7 @@ static gboolean dt_noiseprofile_verify(JsonParser *parser) n_profiles_total += n_models; for(int j = 0; j < n_models; j++) { - if(!json_reader_read_element(reader, j)) _ERROR("can't access model at position %d / %d", j+1, n_models); + if(!json_reader_read_element(reader, j)) _ERROR("can't access model at position %d / %d", j + 1, n_models); if(!json_reader_read_member(reader, "model")) _ERROR("missing `model`"); @@ -154,9 +157,10 @@ static gboolean dt_noiseprofile_verify(JsonParser *parser) dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found %d profiles\n", n_profiles); for(int k = 0; k < n_profiles; k++) { - if(!json_reader_read_element(reader, k)) _ERROR("can't access profile at position %d / %d", k+1, n_profiles); + if(!json_reader_read_element(reader, k)) + _ERROR("can't access profile at position %d / %d", k + 1, n_profiles); - gchar** member_names = json_reader_list_members(reader); + gchar **member_names = json_reader_list_members(reader); // name if(!is_member(member_names, "name")) @@ -232,7 +236,8 @@ GList *dt_noiseprofile_get_matching(const dt_image_t *cimg) if(!parser) goto end; - dt_print(DT_DEBUG_CONTROL, "[noiseprofile] looking for maker `%s', model `%s'\n", cimg->camera_maker, cimg->camera_model); + dt_print(DT_DEBUG_CONTROL, "[noiseprofile] looking for maker `%s', model `%s'\n", cimg->camera_maker, + cimg->camera_model); JsonNode *root = json_parser_get_root(parser); @@ -251,7 +256,8 @@ GList *dt_noiseprofile_get_matching(const dt_image_t *cimg) if(g_strstr_len(cimg->camera_maker, -1, json_reader_get_string_value(reader))) { - dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found `%s' as `%s'\n", cimg->camera_maker, json_reader_get_string_value(reader)); + dt_print(DT_DEBUG_CONTROL, "[noiseprofile] found `%s' as `%s'\n", cimg->camera_maker, + json_reader_get_string_value(reader)); // go through all models and check those json_reader_end_member(reader); @@ -281,7 +287,7 @@ GList *dt_noiseprofile_get_matching(const dt_image_t *cimg) json_reader_read_element(reader, k); - gchar** member_names = json_reader_list_members(reader); + gchar **member_names = json_reader_list_members(reader); // do we want to skip this entry? if(is_member(member_names, "skip")) @@ -372,20 +378,17 @@ void dt_noiseprofile_free(gpointer data) free(profile); } -void dt_noiseprofile_interpolate( - const dt_noiseprofile_t *const p1, // the smaller iso - const dt_noiseprofile_t *const p2, // the larger iso (can't be == iso1) - dt_noiseprofile_t *out) // has iso initialized +void dt_noiseprofile_interpolate(const dt_noiseprofile_t *const p1, // the smaller iso + const dt_noiseprofile_t *const p2, // the larger iso (can't be == iso1) + dt_noiseprofile_t *out) // has iso initialized { // stupid linear interpolation. // to be confirmed for gaussian part. - const float t = CLAMP( - (float)(out->iso - p1->iso) / (float)(p2->iso - p1->iso), - 0.0f, 1.0f); - for(int k=0; k<3; k++) + const float t = CLAMP((float)(out->iso - p1->iso) / (float)(p2->iso - p1->iso), 0.0f, 1.0f); + for(int k = 0; k < 3; k++) { - out->a[k] = (1.0f-t)*p1->a[k] + t*p2->a[k]; - out->b[k] = (1.0f-t)*p1->b[k] + t*p2->b[k]; + out->a[k] = (1.0f - t) * p1->a[k] + t * p2->a[k]; + out->b[k] = (1.0f - t) * p1->b[k] + t * p2->b[k]; } } diff --git a/src/common/opencl.c b/src/common/opencl.c index 8700a75dac66..e9da2e70ef11 100644 --- a/src/common/opencl.c +++ b/src/common/opencl.c @@ -45,7 +45,8 @@ #include <zlib.h> static const char *dt_opencl_get_vendor_by_id(unsigned int id); -static float dt_opencl_benchmark_gpu(const int devid, const size_t width, const size_t height, const int count, const float sigma); +static float dt_opencl_benchmark_gpu(const int devid, const size_t width, const size_t height, const int count, + const float sigma); static float dt_opencl_benchmark_cpu(const size_t width, const size_t height, const int count, const float sigma); static char *_ascii_str_canonical(const char *in, char *out, int maxlen); /** parse a single token of priority string and store priorities in priority_list */ @@ -544,8 +545,7 @@ void dt_opencl_init(dt_opencl_t *cl, const gboolean exclude_opencl, const gboole g_free(str); dt_print(DT_DEBUG_OPENCL, "[opencl_init] opencl_mandatory_timeout: %d\n", dt_conf_get_int("opencl_mandatory_timeout")); - dt_print(DT_DEBUG_OPENCL, "[opencl_init] opencl_size_roundup: %d\n", - dt_conf_get_int("opencl_size_roundup")); + dt_print(DT_DEBUG_OPENCL, "[opencl_init] opencl_size_roundup: %d\n", dt_conf_get_int("opencl_size_roundup")); dt_print(DT_DEBUG_OPENCL, "[opencl_init] opencl_async_pixelpipe: %d\n", dt_conf_get_bool("opencl_async_pixelpipe")); dt_print(DT_DEBUG_OPENCL, "[opencl_init] opencl_synch_cache: %d\n", dt_conf_get_bool("opencl_synch_cache")); @@ -557,8 +557,7 @@ void dt_opencl_init(dt_opencl_t *cl, const gboolean exclude_opencl, const gboole dt_print(DT_DEBUG_OPENCL, "[opencl_init] opencl_use_cpu_devices: %d\n", dt_conf_get_bool("opencl_use_cpu_devices")); - dt_print(DT_DEBUG_OPENCL, "[opencl_init] opencl_avoid_atomics: %d\n", - dt_conf_get_bool("opencl_avoid_atomics")); + dt_print(DT_DEBUG_OPENCL, "[opencl_init] opencl_avoid_atomics: %d\n", dt_conf_get_bool("opencl_avoid_atomics")); dt_print(DT_DEBUG_OPENCL, "[opencl_init] \n"); @@ -569,8 +568,7 @@ void dt_opencl_init(dt_opencl_t *cl, const gboolean exclude_opencl, const gboole // dynamically load opencl runtime if((cl->dlocl = dt_dlopencl_init(library)) == NULL) { - dt_print(DT_DEBUG_OPENCL, - "[opencl_init] no working opencl library found. Continue with opencl disabled\n"); + dt_print(DT_DEBUG_OPENCL, "[opencl_init] no working opencl library found. Continue with opencl disabled\n"); g_free(library); goto finally; } @@ -597,16 +595,14 @@ void dt_opencl_init(dt_opencl_t *cl, const gboolean exclude_opencl, const gboole dt_print(DT_DEBUG_OPENCL, "[opencl_init] no opencl platform available\n"); goto finally; } - dt_print(DT_DEBUG_OPENCL, "[opencl_init] found %d platform%s\n", num_platforms, - num_platforms > 1 ? "s" : ""); + dt_print(DT_DEBUG_OPENCL, "[opencl_init] found %d platform%s\n", num_platforms, num_platforms > 1 ? "s" : ""); for(int n = 0; n < num_platforms; n++) { cl_platform_id platform = all_platforms[n]; // get the number of GPU devices available to the platforms // the other common option is CL_DEVICE_TYPE_GPU/CPU (but the latter doesn't work with the nvidia drivers) - err = (cl->dlocl->symbols->dt_clGetDeviceIDs)(platform, CL_DEVICE_TYPE_ALL, 0, NULL, - &(all_num_devices[n])); + err = (cl->dlocl->symbols->dt_clGetDeviceIDs)(platform, CL_DEVICE_TYPE_ALL, 0, NULL, &(all_num_devices[n])); if(err != CL_SUCCESS) { all_num_devices[n] = 0; @@ -638,8 +634,7 @@ void dt_opencl_init(dt_opencl_t *cl, const gboolean exclude_opencl, const gboole if(all_num_devices[n]) { cl_platform_id platform = all_platforms[n]; - err = (cl->dlocl->symbols->dt_clGetDeviceIDs)(platform, CL_DEVICE_TYPE_ALL, all_num_devices[n], devs, - NULL); + err = (cl->dlocl->symbols->dt_clGetDeviceIDs)(platform, CL_DEVICE_TYPE_ALL, all_num_devices[n], devs, NULL); if(err != CL_SUCCESS) { num_devices -= all_num_devices[n]; @@ -680,13 +675,12 @@ void dt_opencl_init(dt_opencl_t *cl, const gboolean exclude_opencl, const gboole // only check successful malloc in debug mode; darktable will crash anyhow sooner or later if mallocs that // small would fail - assert(cl->dev_priority_image != NULL && cl->dev_priority_preview != NULL - && cl->dev_priority_export != NULL && cl->dev_priority_thumbnail != NULL); + assert(cl->dev_priority_image != NULL && cl->dev_priority_preview != NULL && cl->dev_priority_export != NULL + && cl->dev_priority_thumbnail != NULL); dt_print(DT_DEBUG_OPENCL, "[opencl_init] OpenCL successfully initialized.\n"); - dt_print( - DT_DEBUG_OPENCL, - "[opencl_init] here are the internal numbers and names of OpenCL devices available to darktable:\n"); + dt_print(DT_DEBUG_OPENCL, + "[opencl_init] here are the internal numbers and names of OpenCL devices available to darktable:\n"); for(int i = 0; i < dev; i++) dt_print(DT_DEBUG_OPENCL, "[opencl_init]\t\t%d\t'%s'\n", i, cl->dev[i].name); } else @@ -726,12 +720,14 @@ void dt_opencl_init(dt_opencl_t *cl, const gboolean exclude_opencl, const gboole float tgpu = cl->dev[n].benchmark = dt_opencl_benchmark_gpu(n, 1024, 1024, 5, 100.0f); tgpumin = fmin(tgpu, tgpumin); } - dt_print(DT_DEBUG_OPENCL, "[opencl_init] benchmarking results: %f seconds for fastest GPU versus %f seconds for CPU.\n", - tgpumin, tcpu); + dt_print(DT_DEBUG_OPENCL, + "[opencl_init] benchmarking results: %f seconds for fastest GPU versus %f seconds for CPU.\n", + tgpumin, tcpu); if(tcpu <= 1.5f * tgpumin) { - // de-activate opencl for darktable in case of too slow GPU(s). user can always manually overrule this later. + // de-activate opencl for darktable in case of too slow GPU(s). user can always manually overrule this + // later. cl->enabled = FALSE; dt_conf_set_bool("opencl", FALSE); dt_print(DT_DEBUG_OPENCL, "[opencl_init] due to a slow GPU the opencl flag has been set to OFF.\n"); @@ -821,7 +817,7 @@ void dt_opencl_cleanup(dt_opencl_t *cl) if(cl->print_statistics && (darktable.unmuted & DT_DEBUG_MEMORY)) { dt_print(DT_DEBUG_OPENCL, "[opencl_summary_statistics] device '%s' (%d): peak memory usage %zu bytes\n", - cl->dev[i].name, i, cl->dev[i].peak_memory); + cl->dev[i].name, i, cl->dev[i].peak_memory); } if(cl->print_statistics && cl->use_events) @@ -915,7 +911,8 @@ static float tpdf(unsigned int urandom) return (frandom < 0.5f ? (sqrtf(2.0f * frandom) - 1.0f) : (1.0f - sqrtf(2.0f * (1.0f - frandom)))); } -static float dt_opencl_benchmark_gpu(const int devid, const size_t width, const size_t height, const int count, const float sigma) +static float dt_opencl_benchmark_gpu(const int devid, const size_t width, const size_t height, const int count, + const float sigma) { const int bpp = 4 * sizeof(float); cl_int err = 666; @@ -950,7 +947,7 @@ static float dt_opencl_benchmark_gpu(const int devid, const size_t width, const double start = dt_get_wtime(); // allocate dev_mem buffer - dev_mem = dt_opencl_alloc_device_use_host_pointer(devid, width, height, bpp, width*bpp, buf); + dev_mem = dt_opencl_alloc_device_use_host_pointer(devid, width, height, bpp, width * bpp, buf); if(dev_mem == NULL) goto error; // prepare gaussian filter @@ -1317,8 +1314,8 @@ static void dt_opencl_update_priorities(const char *configstr) cl->dev_priority_preview[i], cl->dev_priority_export[i], cl->dev_priority_thumbnail[i]); dt_print(DT_DEBUG_OPENCL, "[opencl_priorities] show if opencl use is mandatory for a given pixelpipe:\n"); dt_print(DT_DEBUG_OPENCL, "[opencl_priorities] \t\timage\tpreview\texport\tthumbnail\n"); - dt_print(DT_DEBUG_OPENCL, "[opencl_priorities]\t\t%d\t%d\t%d\t%d\n", cl->mandatory[0], - cl->mandatory[1], cl->mandatory[2], cl->mandatory[3]); + dt_print(DT_DEBUG_OPENCL, "[opencl_priorities]\t\t%d\t%d\t%d\t%d\n", cl->mandatory[0], cl->mandatory[1], + cl->mandatory[2], cl->mandatory[3]); } int dt_opencl_lock_device(const int pipetype) @@ -1498,16 +1495,14 @@ int dt_opencl_load_program(const int dev, const int prog, const char *filename, if(prog < 0 || prog >= DT_OPENCL_MAX_PROGRAMS) { - dt_print(DT_DEBUG_OPENCL, "[opencl_load_source] invalid program number `%d' of file `%s'!\n", prog, - filename); + dt_print(DT_DEBUG_OPENCL, "[opencl_load_source] invalid program number `%d' of file `%s'!\n", prog, filename); return 0; } if(cl->dev[dev].program_used[prog]) { - dt_print(DT_DEBUG_OPENCL, - "[opencl_load_source] program number `%d' already in use when loading file `%s'!\n", prog, - filename); + dt_print(DT_DEBUG_OPENCL, "[opencl_load_source] program number `%d' already in use when loading file `%s'!\n", + prog, filename); return 0; } @@ -1599,8 +1594,8 @@ int dt_opencl_load_program(const int dev, const int prog, const char *filename, if(err != CL_SUCCESS) { dt_print(DT_DEBUG_OPENCL, - "[opencl_load_program] could not load cached binary program from file `%s'! (%d)\n", - binname, err); + "[opencl_load_program] could not load cached binary program from file `%s'! (%d)\n", binname, + err); } else { @@ -1635,8 +1630,8 @@ int dt_opencl_load_program(const int dev, const int prog, const char *filename, free(file); if(err != CL_SUCCESS) { - dt_print(DT_DEBUG_OPENCL, "[opencl_load_source] could not create program from file `%s'! (%d)\n", - filename, err); + dt_print(DT_DEBUG_OPENCL, "[opencl_load_source] could not create program from file `%s'! (%d)\n", filename, + err); return 0; } else @@ -1655,8 +1650,8 @@ int dt_opencl_load_program(const int dev, const int prog, const char *filename, return 1; } -int dt_opencl_build_program(const int dev, const int prog, const char *binname, const char *cachedir, - char *md5sum, int loaded_cached) +int dt_opencl_build_program(const int dev, const int prog, const char *binname, const char *cachedir, char *md5sum, + int loaded_cached) { if(prog < 0 || prog >= DT_OPENCL_MAX_PROGRAMS) return -1; dt_opencl_t *cl = darktable.opencl; @@ -1704,8 +1699,8 @@ int dt_opencl_build_program(const int dev, const int prog, const char *binname, dt_print(DT_DEBUG_OPENCL, "[opencl_build_program] saving binary\n"); cl_uint numdev = 0; - err = (cl->dlocl->symbols->dt_clGetProgramInfo)(program, CL_PROGRAM_NUM_DEVICES, sizeof(cl_uint), - &numdev, NULL); + err = (cl->dlocl->symbols->dt_clGetProgramInfo)(program, CL_PROGRAM_NUM_DEVICES, sizeof(cl_uint), &numdev, + NULL); if(err != CL_SUCCESS) { dt_print(DT_DEBUG_OPENCL, "[opencl_build_program] CL_PROGRAM_NUM_DEVICES failed: %d\n", err); @@ -1713,8 +1708,8 @@ int dt_opencl_build_program(const int dev, const int prog, const char *binname, } cl_device_id *devices = malloc(numdev * sizeof(cl_device_id)); - err = (cl->dlocl->symbols->dt_clGetProgramInfo)(program, CL_PROGRAM_DEVICES, - sizeof(cl_device_id) * numdev, devices, NULL); + err = (cl->dlocl->symbols->dt_clGetProgramInfo)(program, CL_PROGRAM_DEVICES, sizeof(cl_device_id) * numdev, + devices, NULL); if(err != CL_SUCCESS) { dt_print(DT_DEBUG_OPENCL, "[opencl_build_program] CL_PROGRAM_DEVICES failed: %d\n", err); @@ -1723,8 +1718,8 @@ int dt_opencl_build_program(const int dev, const int prog, const char *binname, } size_t *binary_sizes = malloc(numdev * sizeof(size_t)); - err = (cl->dlocl->symbols->dt_clGetProgramInfo)(program, CL_PROGRAM_BINARY_SIZES, - sizeof(size_t) * numdev, binary_sizes, NULL); + err = (cl->dlocl->symbols->dt_clGetProgramInfo)(program, CL_PROGRAM_BINARY_SIZES, sizeof(size_t) * numdev, + binary_sizes, NULL); if(err != CL_SUCCESS) { dt_print(DT_DEBUG_OPENCL, "[opencl_build_program] CL_PROGRAM_BINARY_SIZES failed: %d\n", err); @@ -1763,8 +1758,8 @@ int dt_opencl_build_program(const int dev, const int prog, const char *binname, g_strlcpy(dup, binname, sizeof(dup)); char *bname = basename(dup); #if defined(_WIN32) - //CreateSymbolicLink in Windows requires admin privileges, which we don't want/need - //store has using a simple filerename + // CreateSymbolicLink in Windows requires admin privileges, which we don't want/need + // store has using a simple filerename char finalfilename[PATH_MAX] = { 0 }; snprintf(finalfilename, sizeof(finalfilename), "%s/%s.%s", cachedir, bname, md5sum); rename(link_dest, finalfilename); @@ -1798,8 +1793,7 @@ int dt_opencl_create_kernel(const int prog, const char *name) if(!cl->dev[dev].kernel_used[k]) { cl->dev[dev].kernel_used[k] = 1; - cl->dev[dev].kernel[k] - = (cl->dlocl->symbols->dt_clCreateKernel)(cl->dev[dev].program[prog], name, &err); + cl->dev[dev].kernel[k] = (cl->dlocl->symbols->dt_clCreateKernel)(cl->dev[dev].program[prog], name, &err); if(err != CL_SUCCESS) { dt_print(DT_DEBUG_OPENCL, "[opencl_create_kernel] could not create kernel `%s'! (%d)\n", name, err); @@ -1857,14 +1851,14 @@ int dt_opencl_get_work_group_limits(const int dev, size_t *sizes, size_t *workgr cl_ulong lmemsize; cl_int err; - err = (cl->dlocl->symbols->dt_clGetDeviceInfo)(cl->dev[dev].devid, CL_DEVICE_LOCAL_MEM_SIZE, - sizeof(cl_ulong), &lmemsize, NULL); + err = (cl->dlocl->symbols->dt_clGetDeviceInfo)(cl->dev[dev].devid, CL_DEVICE_LOCAL_MEM_SIZE, sizeof(cl_ulong), + &lmemsize, NULL); if(err != CL_SUCCESS) return err; *localmemsize = lmemsize; - err = (cl->dlocl->symbols->dt_clGetDeviceInfo)(cl->dev[dev].devid, CL_DEVICE_MAX_WORK_GROUP_SIZE, - sizeof(size_t), workgroupsize, NULL); + err = (cl->dlocl->symbols->dt_clGetDeviceInfo)(cl->dev[dev].devid, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), + workgroupsize, NULL); if(err != CL_SUCCESS) return err; return dt_opencl_get_max_work_item_sizes(dev, sizes); @@ -1883,8 +1877,7 @@ int dt_opencl_get_kernel_work_group_size(const int dev, const int kernel, size_t } -int dt_opencl_set_kernel_arg(const int dev, const int kernel, const int num, const size_t size, - const void *arg) +int dt_opencl_set_kernel_arg(const int dev, const int kernel, const int num, const size_t size, const void *arg) { dt_opencl_t *cl = darktable.opencl; if(!cl->inited || dev < 0) return -1; @@ -1907,23 +1900,22 @@ int dt_opencl_enqueue_kernel_2d_with_local(const int dev, const int kernel, cons int err; char buf[256]; buf[0] = '\0'; - (cl->dlocl->symbols->dt_clGetKernelInfo)(cl->dev[dev].kernel[kernel], CL_KERNEL_FUNCTION_NAME, 256, buf, - NULL); + (cl->dlocl->symbols->dt_clGetKernelInfo)(cl->dev[dev].kernel[kernel], CL_KERNEL_FUNCTION_NAME, 256, buf, NULL); cl_event *eventp = dt_opencl_events_get_slot(dev, buf); - err = (cl->dlocl->symbols->dt_clEnqueueNDRangeKernel)(cl->dev[dev].cmd_queue, cl->dev[dev].kernel[kernel], - 2, NULL, sizes, local, 0, NULL, eventp); + err = (cl->dlocl->symbols->dt_clEnqueueNDRangeKernel)(cl->dev[dev].cmd_queue, cl->dev[dev].kernel[kernel], 2, + NULL, sizes, local, 0, NULL, eventp); // if (err == CL_SUCCESS) err = dt_opencl_finish(dev); return err; } -int dt_opencl_copy_device_to_host(const int devid, void *host, void *device, const int width, - const int height, const int bpp) +int dt_opencl_copy_device_to_host(const int devid, void *host, void *device, const int width, const int height, + const int bpp) { return dt_opencl_read_host_from_device(devid, host, device, width, height, bpp); } -int dt_opencl_read_host_from_device(const int devid, void *host, void *device, const int width, - const int height, const int bpp) +int dt_opencl_read_host_from_device(const int devid, void *host, void *device, const int width, const int height, + const int bpp) { return dt_opencl_read_host_from_device_rowpitch(devid, host, device, width, height, bpp * width); } @@ -1941,13 +1933,11 @@ int dt_opencl_read_host_from_device_rowpitch(const int devid, void *host, void * int dt_opencl_read_host_from_device_non_blocking(const int devid, void *host, void *device, const int width, const int height, const int bpp) { - return dt_opencl_read_host_from_device_rowpitch_non_blocking(devid, host, device, width, height, - bpp * width); + return dt_opencl_read_host_from_device_rowpitch_non_blocking(devid, host, device, width, height, bpp * width); } int dt_opencl_read_host_from_device_rowpitch_non_blocking(const int devid, void *host, void *device, - const int width, const int height, - const int rowpitch) + const int width, const int height, const int rowpitch) { if(!darktable.opencl->inited || devid < 0) return -1; const size_t origin[] = { 0, 0, 0 }; @@ -1964,13 +1954,13 @@ int dt_opencl_read_host_from_device_raw(const int devid, void *host, void *devic cl_event *eventp = dt_opencl_events_get_slot(devid, "[Read Image (from device to host)]"); - return (darktable.opencl->dlocl->symbols->dt_clEnqueueReadImage)(darktable.opencl->dev[devid].cmd_queue, - device, blocking, origin, region, rowpitch, - 0, host, 0, NULL, eventp); + return (darktable.opencl->dlocl->symbols->dt_clEnqueueReadImage)(darktable.opencl->dev[devid].cmd_queue, device, + blocking, origin, region, rowpitch, 0, host, 0, + NULL, eventp); } -int dt_opencl_write_host_to_device(const int devid, void *host, void *device, const int width, - const int height, const int bpp) +int dt_opencl_write_host_to_device(const int devid, void *host, void *device, const int width, const int height, + const int bpp) { return dt_opencl_write_host_to_device_rowpitch(devid, host, device, width, height, width * bpp); } @@ -1992,8 +1982,7 @@ int dt_opencl_write_host_to_device_non_blocking(const int devid, void *host, voi } int dt_opencl_write_host_to_device_rowpitch_non_blocking(const int devid, void *host, void *device, - const int width, const int height, - const int rowpitch) + const int width, const int height, const int rowpitch) { if(!darktable.opencl->inited || devid < 0) return -1; const size_t origin[] = { 0, 0, 0 }; @@ -2009,9 +1998,9 @@ int dt_opencl_write_host_to_device_raw(const int devid, void *host, void *device cl_event *eventp = dt_opencl_events_get_slot(devid, "[Write Image (from host to device)]"); - return (darktable.opencl->dlocl->symbols->dt_clEnqueueWriteImage)(darktable.opencl->dev[devid].cmd_queue, - device, blocking, origin, region, - rowpitch, 0, host, 0, NULL, eventp); + return (darktable.opencl->dlocl->symbols->dt_clEnqueueWriteImage)(darktable.opencl->dev[devid].cmd_queue, device, + blocking, origin, region, rowpitch, 0, host, 0, + NULL, eventp); } int dt_opencl_enqueue_copy_image(const int devid, cl_mem src, cl_mem dst, size_t *orig_src, size_t *orig_dst, @@ -2020,27 +2009,26 @@ int dt_opencl_enqueue_copy_image(const int devid, cl_mem src, cl_mem dst, size_t if(!darktable.opencl->inited || devid < 0) return -1; cl_int err; cl_event *eventp = dt_opencl_events_get_slot(devid, "[Copy Image (on device)]"); - err = (darktable.opencl->dlocl->symbols->dt_clEnqueueCopyImage)( - darktable.opencl->dev[devid].cmd_queue, src, dst, orig_src, orig_dst, region, 0, NULL, eventp); + err = (darktable.opencl->dlocl->symbols->dt_clEnqueueCopyImage)(darktable.opencl->dev[devid].cmd_queue, src, dst, + orig_src, orig_dst, region, 0, NULL, eventp); if(err != CL_SUCCESS) dt_print(DT_DEBUG_OPENCL, "[opencl copy_image] could not copy image: %d\n", err); return err; } -int dt_opencl_enqueue_copy_image_to_buffer(const int devid, cl_mem src_image, cl_mem dst_buffer, - size_t *origin, size_t *region, size_t offset) +int dt_opencl_enqueue_copy_image_to_buffer(const int devid, cl_mem src_image, cl_mem dst_buffer, size_t *origin, + size_t *region, size_t offset) { if(!darktable.opencl->inited) return -1; cl_int err; cl_event *eventp = dt_opencl_events_get_slot(devid, "[Copy Image to Buffer (on device)]"); err = (darktable.opencl->dlocl->symbols->dt_clEnqueueCopyImageToBuffer)( darktable.opencl->dev[devid].cmd_queue, src_image, dst_buffer, origin, region, offset, 0, NULL, eventp); - if(err != CL_SUCCESS) - dt_print(DT_DEBUG_OPENCL, "[opencl copy_image_to_buffer] could not copy image: %d\n", err); + if(err != CL_SUCCESS) dt_print(DT_DEBUG_OPENCL, "[opencl copy_image_to_buffer] could not copy image: %d\n", err); return err; } -int dt_opencl_enqueue_copy_buffer_to_image(const int devid, cl_mem src_buffer, cl_mem dst_image, - size_t offset, size_t *origin, size_t *region) +int dt_opencl_enqueue_copy_buffer_to_image(const int devid, cl_mem src_buffer, cl_mem dst_image, size_t offset, + size_t *origin, size_t *region) { if(!darktable.opencl->inited) return -1; cl_int err; @@ -2058,9 +2046,8 @@ int dt_opencl_enqueue_copy_buffer_to_buffer(const int devid, cl_mem src_buffer, if(!darktable.opencl->inited) return -1; cl_int err; cl_event *eventp = dt_opencl_events_get_slot(devid, "[Copy Buffer to Buffer (on device)]"); - err = (darktable.opencl->dlocl->symbols->dt_clEnqueueCopyBuffer)(darktable.opencl->dev[devid].cmd_queue, - src_buffer, dst_buffer, srcoffset, - dstoffset, size, 0, NULL, eventp); + err = (darktable.opencl->dlocl->symbols->dt_clEnqueueCopyBuffer)( + darktable.opencl->dev[devid].cmd_queue, src_buffer, dst_buffer, srcoffset, dstoffset, size, 0, NULL, eventp); if(err != CL_SUCCESS) dt_print(DT_DEBUG_OPENCL, "[opencl copy_buffer_to_buffer] could not copy buffer: %d\n", err); return err; @@ -2073,8 +2060,8 @@ int dt_opencl_read_buffer_from_device(const int devid, void *host, void *device, cl_event *eventp = dt_opencl_events_get_slot(devid, "[Read Buffer (from device to host)]"); - return (darktable.opencl->dlocl->symbols->dt_clEnqueueReadBuffer)( - darktable.opencl->dev[devid].cmd_queue, device, blocking, offset, size, host, 0, NULL, eventp); + return (darktable.opencl->dlocl->symbols->dt_clEnqueueReadBuffer)(darktable.opencl->dev[devid].cmd_queue, device, + blocking, offset, size, host, 0, NULL, eventp); } int dt_opencl_write_buffer_to_device(const int devid, void *host, void *device, const size_t offset, @@ -2096,16 +2083,15 @@ void *dt_opencl_copy_host_to_device_constant(const int devid, const size_t size, cl_mem dev = (darktable.opencl->dlocl->symbols->dt_clCreateBuffer)( darktable.opencl->dev[devid].context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, size, host, &err); if(err != CL_SUCCESS) - dt_print(DT_DEBUG_OPENCL, - "[opencl copy_host_to_device_constant] could not alloc buffer on device %d: %d\n", devid, err); + dt_print(DT_DEBUG_OPENCL, "[opencl copy_host_to_device_constant] could not alloc buffer on device %d: %d\n", + devid, err); dt_opencl_memory_statistics(devid, dev, OPENCL_MEMORY_ADD); return dev; } -void *dt_opencl_copy_host_to_device(const int devid, void *host, const int width, const int height, - const int bpp) +void *dt_opencl_copy_host_to_device(const int devid, void *host, const int width, const int height, const int bpp) { return dt_opencl_copy_host_to_device_rowpitch(devid, host, width, height, bpp, 0); } @@ -2127,12 +2113,12 @@ void *dt_opencl_copy_host_to_device_rowpitch(const int devid, void *host, const return NULL; // TODO: if fmt = uint16_t, blow up to 4xuint16_t and copy manually! - cl_mem dev = (darktable.opencl->dlocl->symbols->dt_clCreateImage2D)( - darktable.opencl->dev[devid].context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, &fmt, width, height, - rowpitch, host, &err); + cl_mem dev = (darktable.opencl->dlocl->symbols->dt_clCreateImage2D)(darktable.opencl->dev[devid].context, + CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, + &fmt, width, height, rowpitch, host, &err); if(err != CL_SUCCESS) - dt_print(DT_DEBUG_OPENCL, - "[opencl copy_host_to_device] could not alloc/copy img buffer on device %d: %d\n", devid, err); + dt_print(DT_DEBUG_OPENCL, "[opencl copy_host_to_device] could not alloc/copy img buffer on device %d: %d\n", + devid, err); dt_opencl_memory_statistics(devid, dev, OPENCL_MEMORY_ADD); @@ -2171,8 +2157,8 @@ int dt_opencl_unmap_mem_object(const int devid, cl_mem mem_object, void *mapped_ if(!darktable.opencl->inited) return -1; cl_int err; cl_event *eventp = dt_opencl_events_get_slot(devid, "[Unmap Mem Object]"); - err = (darktable.opencl->dlocl->symbols->dt_clEnqueueUnmapMemObject)( - darktable.opencl->dev[devid].cmd_queue, mem_object, mapped_ptr, 0, NULL, eventp); + err = (darktable.opencl->dlocl->symbols->dt_clEnqueueUnmapMemObject)(darktable.opencl->dev[devid].cmd_queue, + mem_object, mapped_ptr, 0, NULL, eventp); if(err != CL_SUCCESS) dt_print(DT_DEBUG_OPENCL, "[opencl unmap mem object] could not unmap mem object: %d\n", err); return err; @@ -2196,8 +2182,7 @@ void *dt_opencl_alloc_device(const int devid, const int width, const int height, cl_mem dev = (darktable.opencl->dlocl->symbols->dt_clCreateImage2D)( darktable.opencl->dev[devid].context, CL_MEM_READ_WRITE, &fmt, width, height, 0, NULL, &err); if(err != CL_SUCCESS) - dt_print(DT_DEBUG_OPENCL, "[opencl alloc_device] could not alloc img buffer on device %d: %d\n", devid, - err); + dt_print(DT_DEBUG_OPENCL, "[opencl alloc_device] could not alloc img buffer on device %d: %d\n", devid, err); dt_opencl_memory_statistics(devid, dev, OPENCL_MEMORY_ADD); @@ -2205,8 +2190,8 @@ void *dt_opencl_alloc_device(const int devid, const int width, const int height, } -void *dt_opencl_alloc_device_use_host_pointer(const int devid, const int width, const int height, - const int bpp, const int rowpitch, void *host) +void *dt_opencl_alloc_device_use_host_pointer(const int devid, const int width, const int height, const int bpp, + const int rowpitch, void *host) { if(!darktable.opencl->inited || devid < 0) return NULL; cl_int err; @@ -2227,8 +2212,7 @@ void *dt_opencl_alloc_device_use_host_pointer(const int devid, const int width, rowpitch, host, &err); if(err != CL_SUCCESS) dt_print(DT_DEBUG_OPENCL, - "[opencl alloc_device_use_host_pointer] could not alloc img buffer on device %d: %d\n", devid, - err); + "[opencl alloc_device_use_host_pointer] could not alloc img buffer on device %d: %d\n", devid, err); dt_opencl_memory_statistics(devid, dev, OPENCL_MEMORY_ADD); @@ -2244,8 +2228,7 @@ void *dt_opencl_alloc_device_buffer(const int devid, const size_t size) cl_mem buf = (darktable.opencl->dlocl->symbols->dt_clCreateBuffer)(darktable.opencl->dev[devid].context, CL_MEM_READ_WRITE, size, NULL, &err); if(err != CL_SUCCESS) - dt_print(DT_DEBUG_OPENCL, "[opencl alloc_device_buffer] could not alloc buffer on device %d: %d\n", devid, - err); + dt_print(DT_DEBUG_OPENCL, "[opencl alloc_device_buffer] could not alloc buffer on device %d: %d\n", devid, err); dt_opencl_memory_statistics(devid, buf, OPENCL_MEMORY_ADD); @@ -2257,11 +2240,10 @@ void *dt_opencl_alloc_device_buffer_with_flags(const int devid, const size_t siz if(!darktable.opencl->inited) return NULL; cl_int err; - cl_mem buf = (darktable.opencl->dlocl->symbols->dt_clCreateBuffer)(darktable.opencl->dev[devid].context, - flags, size, NULL, &err); + cl_mem buf = (darktable.opencl->dlocl->symbols->dt_clCreateBuffer)(darktable.opencl->dev[devid].context, flags, + size, NULL, &err); if(err != CL_SUCCESS) - dt_print(DT_DEBUG_OPENCL, "[opencl alloc_device_buffer] could not alloc buffer on device %d: %d\n", devid, - err); + dt_print(DT_DEBUG_OPENCL, "[opencl alloc_device_buffer] could not alloc buffer on device %d: %d\n", devid, err); dt_opencl_memory_statistics(devid, buf, OPENCL_MEMORY_ADD); @@ -2285,14 +2267,13 @@ int dt_opencl_get_mem_context_id(cl_mem mem) cl_context context; if(mem == NULL) return -1; - err = (darktable.opencl->dlocl->symbols->dt_clGetMemObjectInfo)(mem, CL_MEM_CONTEXT, sizeof(context), &context, NULL); - if(err != CL_SUCCESS) - return -1; + err = (darktable.opencl->dlocl->symbols->dt_clGetMemObjectInfo)(mem, CL_MEM_CONTEXT, sizeof(context), &context, + NULL); + if(err != CL_SUCCESS) return -1; for(int devid = 0; devid < darktable.opencl->num_devs; devid++) { - if(darktable.opencl->dev[devid].context == context) - return devid; + if(darktable.opencl->dev[devid].context == context) return devid; } return -1; @@ -2300,23 +2281,21 @@ int dt_opencl_get_mem_context_id(cl_mem mem) void dt_opencl_memory_statistics(int devid, cl_mem mem, dt_opencl_memory_t action) { - if(devid < 0) - devid = dt_opencl_get_mem_context_id(mem); + if(devid < 0) devid = dt_opencl_get_mem_context_id(mem); - if(devid < 0) - return; + if(devid < 0) return; if(action == OPENCL_MEMORY_ADD) darktable.opencl->dev[devid].memory_in_use += dt_opencl_get_mem_object_size(mem); else darktable.opencl->dev[devid].memory_in_use -= dt_opencl_get_mem_object_size(mem); - darktable.opencl->dev[devid].peak_memory = MAX(darktable.opencl->dev[devid].peak_memory, - darktable.opencl->dev[devid].memory_in_use); + darktable.opencl->dev[devid].peak_memory + = MAX(darktable.opencl->dev[devid].peak_memory, darktable.opencl->dev[devid].memory_in_use); if(darktable.unmuted & DT_DEBUG_MEMORY) - dt_print(DT_DEBUG_OPENCL, - "[opencl memory] device %d: %zu bytes in use\n", devid, darktable.opencl->dev[devid].memory_in_use); + dt_print(DT_DEBUG_OPENCL, "[opencl memory] device %d: %zu bytes in use\n", devid, + darktable.opencl->dev[devid].memory_in_use); } /** check if image size fit into limits given by OpenCL runtime */ @@ -2340,8 +2319,7 @@ int dt_opencl_image_fits_device(const int devid, const size_t width, const size_ float singlebuffer = (float)width * height * bpp; float total = factor * singlebuffer + overhead; - if(darktable.opencl->dev[devid].max_image_width < width - || darktable.opencl->dev[devid].max_image_height < height) + if(darktable.opencl->dev[devid].max_image_width < width || darktable.opencl->dev[devid].max_image_height < height) return FALSE; if(darktable.opencl->dev[devid].max_mem_alloc < singlebuffer) return FALSE; @@ -2648,8 +2626,7 @@ void dt_opencl_events_wait_for(const int devid) // now wait for all remaining events to terminate // Risk: might never return in case of OpenCL blocks or endless loops // TODO: run clWaitForEvents in separate thread and implement watchdog timer - (cl->dlocl->symbols->dt_clWaitForEvents)(*numevents - *eventsconsolidated, - (*eventlist) + *eventsconsolidated); + (cl->dlocl->symbols->dt_clWaitForEvents)(*numevents - *eventsconsolidated, (*eventlist) + *eventsconsolidated); return; } @@ -2698,8 +2675,8 @@ cl_int dt_opencl_events_flush(const int devid, const int reset) } else if(*retval != CL_COMPLETE) { - dt_print(DT_DEBUG_OPENCL, "[opencl_events_flush] execution of '%s' %s: %d\n", - tag[0] == '\0' ? "<?>" : tag, *retval == CL_COMPLETE ? "was successful" : "failed", *retval); + dt_print(DT_DEBUG_OPENCL, "[opencl_events_flush] execution of '%s' %s: %d\n", tag[0] == '\0' ? "<?>" : tag, + *retval == CL_COMPLETE ? "was successful" : "failed", *retval); *summary = *retval; } else @@ -2710,10 +2687,10 @@ cl_int dt_opencl_events_flush(const int devid, const int reset) // get profiling info of event (only if darktable was called with '-d perf') cl_ulong start; cl_ulong end; - cl_int errs = (cl->dlocl->symbols->dt_clGetEventProfilingInfo)( - (*eventlist)[k], CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &start, NULL); + cl_int errs = (cl->dlocl->symbols->dt_clGetEventProfilingInfo)((*eventlist)[k], CL_PROFILING_COMMAND_START, + sizeof(cl_ulong), &start, NULL); cl_int erre = (cl->dlocl->symbols->dt_clGetEventProfilingInfo)((*eventlist)[k], CL_PROFILING_COMMAND_END, - sizeof(cl_ulong), &end, NULL); + sizeof(cl_ulong), &end, NULL); if(errs == CL_SUCCESS && erre == CL_SUCCESS) { (*eventtags)[k].timelapsed = end - start; @@ -2812,9 +2789,7 @@ void dt_opencl_events_profiling(const int devid, const int aggregated) } // now display profiling info - dt_print(DT_DEBUG_OPENCL, - "[opencl_profiling] profiling device %d ('%s'):\n", devid, - cl->dev[devid].name); + dt_print(DT_DEBUG_OPENCL, "[opencl_profiling] profiling device %d ('%s'):\n", devid, cl->dev[devid].name); float total = 0.0f; for(int i = 1; i < items; i++) @@ -2843,8 +2818,7 @@ void dt_opencl_events_profiling(const int devid, const int aggregated) static int nextpow2(int n) { int k = 1; - while (k < n) - k <<= 1; + while(k < n) k <<= 1; return k; } @@ -2872,9 +2846,11 @@ int dt_opencl_local_buffer_opt(const int devid, const int kernel, dt_opencl_loca && dt_opencl_get_kernel_work_group_size(devid, kernel, &kernelworkgroupsize) == CL_SUCCESS) { while(maxsizes[0] < *blocksizex || maxsizes[1] < *blocksizey - || localmemsize < ((factors->xfactor * (*blocksizex) + factors->xoffset) * - (factors->yfactor * (*blocksizey) + factors->yoffset)) * factors->cellsize + factors->overhead - || workgroupsize < (*blocksizex) * (*blocksizey) || kernelworkgroupsize < (*blocksizex) * (*blocksizey)) + || localmemsize < ((factors->xfactor * (*blocksizex) + factors->xoffset) + * (factors->yfactor * (*blocksizey) + factors->yoffset)) * factors->cellsize + + factors->overhead + || workgroupsize < (*blocksizex) * (*blocksizey) + || kernelworkgroupsize < (*blocksizex) * (*blocksizey)) { if(*blocksizex == 1 && *blocksizey == 1) return FALSE; @@ -2886,8 +2862,7 @@ int dt_opencl_local_buffer_opt(const int devid, const int kernel, dt_opencl_loca } else { - dt_print(DT_DEBUG_OPENCL, - "[opencl_demosaic] can not identify resource limits for device %d\n", devid); + dt_print(DT_DEBUG_OPENCL, "[opencl_demosaic] can not identify resource limits for device %d\n", devid); return FALSE; } diff --git a/src/common/opencl.h b/src/common/opencl.h index 180f3b5ba85a..bda20c2222c3 100644 --- a/src/common/opencl.h +++ b/src/common/opencl.h @@ -43,7 +43,7 @@ #include <CL/cl.h> // #pragma GCC diagnostic -#define ROUNDUP(a, n) ((a) % (n) == 0 ? (a) : ((a) / (n)+1) * (n)) +#define ROUNDUP(a, n) ((a) % (n) == 0 ? (a) : ((a) / (n) + 1) * (n)) #define ROUNDUPWD(a) dt_opencl_roundup(a) #define ROUNDUPHT(a) dt_opencl_roundup(a) @@ -169,8 +169,8 @@ typedef struct dt_opencl_local_buffer_t const int yfactor; const size_t cellsize; const size_t overhead; - int sizex; // initial value and final values after optimization - int sizey; // initial value and final values after optimization + int sizex; // initial value and final values after optimization + int sizey; // initial value and final values after optimization } dt_opencl_local_buffer_t; /** internally calls dt_clGetDeviceInfo, and takes care of memory allocation @@ -205,8 +205,8 @@ int dt_opencl_load_program(const int dev, const int prog, const char *filename, const char *cachedir, char *md5sum, char **includemd5, int *loaded_cached); /** builds the given program. */ -int dt_opencl_build_program(const int dev, const int prog, const char *binname, const char *cachedir, - char *md5sum, int loaded_cached); +int dt_opencl_build_program(const int dev, const int prog, const char *binname, const char *cachedir, char *md5sum, + int loaded_cached); /** inits a kernel. returns the index or -1 if fail. */ int dt_opencl_create_kernel(const int program, const char *name); @@ -225,8 +225,7 @@ int dt_opencl_get_work_group_limits(const int dev, size_t *sizes, size_t *workgr int dt_opencl_get_kernel_work_group_size(const int dev, const int kernel, size_t *kernelworkgroupsize); /** attach arg. */ -int dt_opencl_set_kernel_arg(const int dev, const int kernel, const int num, const size_t size, - const void *arg); +int dt_opencl_set_kernel_arg(const int dev, const int kernel, const int num, const size_t size, const void *arg); /** launch kernel! */ int dt_opencl_enqueue_kernel_2d(const int dev, const int kernel, const size_t *sizes); @@ -248,11 +247,11 @@ void dt_opencl_disable(void); int dt_opencl_update_settings(void); /** HAVE_OPENCL mode only: copy and alloc buffers. */ -int dt_opencl_copy_device_to_host(const int devid, void *host, void *device, const int width, - const int height, const int bpp); +int dt_opencl_copy_device_to_host(const int devid, void *host, void *device, const int width, const int height, + const int bpp); -int dt_opencl_read_host_from_device(const int devid, void *host, void *device, const int width, - const int height, const int bpp); +int dt_opencl_read_host_from_device(const int devid, void *host, void *device, const int width, const int height, + const int bpp); int dt_opencl_read_host_from_device_rowpitch(const int devid, void *host, void *device, const int width, const int height, const int rowpitch); @@ -261,14 +260,13 @@ int dt_opencl_read_host_from_device_non_blocking(const int devid, void *host, vo const int height, const int bpp); int dt_opencl_read_host_from_device_rowpitch_non_blocking(const int devid, void *host, void *device, - const int width, const int height, - const int rowpitch); + const int width, const int height, const int rowpitch); int dt_opencl_read_host_from_device_raw(const int devid, void *host, void *device, const size_t *origin, const size_t *region, const int rowpitch, const int blocking); -int dt_opencl_write_host_to_device(const int devid, void *host, void *device, const int width, - const int height, const int bpp); +int dt_opencl_write_host_to_device(const int devid, void *host, void *device, const int width, const int height, + const int bpp); int dt_opencl_write_host_to_device_rowpitch(const int devid, void *host, void *device, const int width, const int height, const int rowpitch); @@ -277,14 +275,12 @@ int dt_opencl_write_host_to_device_non_blocking(const int devid, void *host, voi const int height, const int bpp); int dt_opencl_write_host_to_device_rowpitch_non_blocking(const int devid, void *host, void *device, - const int width, const int height, - const int rowpitch); + const int width, const int height, const int rowpitch); int dt_opencl_write_host_to_device_raw(const int devid, void *host, void *device, const size_t *origin, const size_t *region, const int rowpitch, const int blocking); -void *dt_opencl_copy_host_to_device(const int devid, void *host, const int width, const int height, - const int bpp); +void *dt_opencl_copy_host_to_device(const int devid, void *host, const int width, const int height, const int bpp); void *dt_opencl_copy_host_to_device_rowpitch(const int devid, void *host, const int width, const int height, const int bpp, const int rowpitch); @@ -296,14 +292,14 @@ int dt_opencl_enqueue_copy_image(const int devid, cl_mem src, cl_mem dst, size_t void *dt_opencl_alloc_device(const int devid, const int width, const int height, const int bpp); -void *dt_opencl_alloc_device_use_host_pointer(const int devid, const int width, const int height, - const int bpp, const int rowpitch, void *host); +void *dt_opencl_alloc_device_use_host_pointer(const int devid, const int width, const int height, const int bpp, + const int rowpitch, void *host); -int dt_opencl_enqueue_copy_image_to_buffer(const int devid, cl_mem src_image, cl_mem dst_buffer, - size_t *origin, size_t *region, size_t offset); +int dt_opencl_enqueue_copy_image_to_buffer(const int devid, cl_mem src_image, cl_mem dst_buffer, size_t *origin, + size_t *region, size_t offset); -int dt_opencl_enqueue_copy_buffer_to_image(const int devid, cl_mem src_buffer, cl_mem dst_image, - size_t offset, size_t *origin, size_t *region); +int dt_opencl_enqueue_copy_buffer_to_image(const int devid, cl_mem src_buffer, cl_mem dst_image, size_t offset, + size_t *origin, size_t *region); int dt_opencl_enqueue_copy_buffer_to_buffer(const int devid, cl_mem src_buffer, cl_mem dst_buffer, size_t srcoffset, size_t dstoffset, size_t size); @@ -422,8 +418,7 @@ static inline int dt_opencl_get_work_group_limits(const int dev, size_t *sizes, { return -1; } -static inline int dt_opencl_get_kernel_work_group_size(const int dev, const int kernel, - size_t *kernelworkgroupsize) +static inline int dt_opencl_get_kernel_work_group_size(const int dev, const int kernel, size_t *kernelworkgroupsize) { return -1; } diff --git a/src/common/pdf.c b/src/common/pdf.c index 2eb1413c96a6..764e8a4cda45 100644 --- a/src/common/pdf.c +++ b/src/common/pdf.c @@ -24,7 +24,8 @@ // add the following define to compile this into a standalone test program: // #define STANDALONE // or use -// gcc -W -Wall -std=c99 -lz -lm `pkg-config --cflags --libs glib-2.0` -g -O3 -fopenmp -DSTANDALONE -o darktable-pdf pdf.c +// gcc -W -Wall -std=c99 -lz -lm `pkg-config --cflags --libs glib-2.0` -g -O3 -fopenmp -DSTANDALONE -o +// darktable-pdf pdf.c #ifdef HAVE_CONFIG_H #include "config.h" @@ -52,7 +53,10 @@ #define CLAMP_FLT(A) ((A) > (0.0f) ? ((A) < (1.0f) ? (A) : (1.0f)) : (0.0f)) -#define SKIP_SPACES(s) {while(*(s) == ' ')(s)++;} +#define SKIP_SPACES(s) \ + { \ + while(*(s) == ' ') (s)++; \ + } // puts the length as described in str as pdf points into *length // returns 0 on error @@ -62,17 +66,15 @@ int dt_pdf_parse_length(const char *str, float *length) int res = 0; char *nptr, *endptr; - if(str == NULL || length == NULL) - return 0; + if(str == NULL || length == NULL) return 0; SKIP_SPACES(str); nptr = g_strdelimit(g_strdup(str), ",", '.'); - *length = g_ascii_strtod(nptr, &endptr); + *length = g_ascii_strtod(nptr, &endptr); - if(endptr == NULL || errno == ERANGE) - goto end; + if(endptr == NULL || errno == ERANGE) goto end; // 0 is 0 is 0, why should we care about the unit? if(*length == 0.0 && nptr != endptr) @@ -82,8 +84,7 @@ int dt_pdf_parse_length(const char *str, float *length) } // we don't want NAN, INF or parse errors (== 0.0) - if(!isnormal(*length)) - goto end; + if(!isnormal(*length)) goto end; SKIP_SPACES(endptr); @@ -102,7 +103,8 @@ int dt_pdf_parse_length(const char *str, float *length) return res; } -// a paper size has 2 numbers, separated by 'x' or '*' and a unit, either one per number or one in the end (for both) +// a paper size has 2 numbers, separated by 'x' or '*' and a unit, either one per number or one in the end (for +// both) // <n> <u>? [x|*] <n> <u> // alternatively it could be a well defined format int dt_pdf_parse_paper_size(const char *str, float *width, float *height) @@ -111,8 +113,7 @@ int dt_pdf_parse_paper_size(const char *str, float *width, float *height) gboolean width_has_unit = FALSE; char *ptr, *nptr, *endptr; - if(str == NULL || width == NULL || height == NULL) - return 0; + if(str == NULL || width == NULL || height == NULL) return 0; // first check if this is a well known size for(int i = 0; dt_pdf_paper_sizes[i].name; i++) @@ -130,10 +131,9 @@ int dt_pdf_parse_paper_size(const char *str, float *width, float *height) // width SKIP_SPACES(nptr); - *width = g_ascii_strtod(nptr, &endptr); + *width = g_ascii_strtod(nptr, &endptr); - if(endptr == NULL || *endptr == '\0' || errno == ERANGE || !isnormal(*width)) - goto end; + if(endptr == NULL || *endptr == '\0' || errno == ERANGE || !isnormal(*width)) goto end; nptr = endptr; @@ -154,18 +154,16 @@ int dt_pdf_parse_paper_size(const char *str, float *width, float *height) // x SKIP_SPACES(nptr); - if(*nptr != 'x' && *nptr != '*') - goto end; + if(*nptr != 'x' && *nptr != '*') goto end; nptr++; // height SKIP_SPACES(nptr); - *height = g_ascii_strtod(nptr, &endptr); + *height = g_ascii_strtod(nptr, &endptr); - if(endptr == NULL || *endptr == '\0' || errno == ERANGE || !isnormal(*height)) - goto end; + if(endptr == NULL || *endptr == '\0' || errno == ERANGE || !isnormal(*height)) goto end; nptr = endptr; @@ -177,8 +175,7 @@ int dt_pdf_parse_paper_size(const char *str, float *width, float *height) if(!g_strcmp0(nptr, dt_pdf_units[i].name)) { *height *= dt_pdf_units[i].factor; - if(width_has_unit == FALSE) - *width *= dt_pdf_units[i].factor; + if(width_has_unit == FALSE) *width *= dt_pdf_units[i].factor; res = 1; break; } @@ -192,7 +189,7 @@ int dt_pdf_parse_paper_size(const char *str, float *width, float *height) #undef SKIP_SPACES -static const char *stream_encoder_filters[] = {"/ASCIIHexDecode", "/FlateDecode"}; +static const char *stream_encoder_filters[] = { "/ASCIIHexDecode", "/FlateDecode" }; static void _pdf_set_offset(dt_pdf_t *pdf, int id, size_t offset) { @@ -205,7 +202,8 @@ static void _pdf_set_offset(dt_pdf_t *pdf, int id, size_t offset) pdf->offsets[id] = offset; } -dt_pdf_t *dt_pdf_start(const char *filename, float width, float height, float dpi, dt_pdf_stream_encoder_t default_encoder) +dt_pdf_t *dt_pdf_start(const char *filename, float width, float height, float dpi, + dt_pdf_stream_encoder_t default_encoder) { dt_pdf_t *pdf = calloc(1, sizeof(dt_pdf_t)); if(!pdf) return NULL; @@ -236,14 +234,12 @@ dt_pdf_t *dt_pdf_start(const char *filename, float width, float height, float dp // document catalog _pdf_set_offset(pdf, 1, bytes_written); - bytes_written += fprintf(pdf->fd, - "1 0 obj\n" - "<<\n" - "/Pages 2 0 R\n" - "/Type /Catalog\n" - ">>\n" - "endobj\n" - ); + bytes_written += fprintf(pdf->fd, "1 0 obj\n" + "<<\n" + "/Pages 2 0 R\n" + "/Type /Catalog\n" + ">>\n" + "endobj\n"); pdf->bytes_written += bytes_written; @@ -290,7 +286,8 @@ static size_t _pdf_stream_encoder_Flate(dt_pdf_t *pdf, const unsigned char *data return destLen; } -static size_t _pdf_write_stream(dt_pdf_t *pdf, dt_pdf_stream_encoder_t encoder, const unsigned char *data, size_t len) +static size_t _pdf_write_stream(dt_pdf_t *pdf, dt_pdf_stream_encoder_t encoder, const unsigned char *data, + size_t len) { size_t stream_size = 0; switch(encoder) @@ -354,17 +351,14 @@ int dt_pdf_add_icc_from_data(dt_pdf_t *pdf, const unsigned char *data, size_t si "/Filter [ /ASCIIHexDecode ]\n" ">>\n" "stream\n", - icc_id, length_id - ); + icc_id, length_id); size_t stream_size = _pdf_stream_encoder_ASCIIHex(pdf, data, size); bytes_written += stream_size; - bytes_written += fprintf(pdf->fd, - "\n" - "endstream\n" - "endobj\n" - ); + bytes_written += fprintf(pdf->fd, "\n" + "endstream\n" + "endobj\n"); // length of the stream _pdf_set_offset(pdf, length_id, pdf->bytes_written + bytes_written); @@ -379,9 +373,11 @@ int dt_pdf_add_icc_from_data(dt_pdf_t *pdf, const unsigned char *data, size_t si } // this adds an image to the pdf file and returns the info needed to reference it later. -// if icc_id is 0 then we suppose the pixel data to be in output device space, otherwise the ICC profile object is referenced. +// if icc_id is 0 then we suppose the pixel data to be in output device space, otherwise the ICC profile object is +// referenced. // if image == NULL only the outline can be shown later -dt_pdf_image_t *dt_pdf_add_image(dt_pdf_t *pdf, const unsigned char *image, int width, int height, int bpp, int icc_id, float border) +dt_pdf_image_t *dt_pdf_add_image(dt_pdf_t *pdf, const unsigned char *image, int width, int height, int bpp, + int icc_id, float border) { size_t stream_size = 0; size_t bytes_written = 0; @@ -407,32 +403,31 @@ dt_pdf_image_t *dt_pdf_add_image(dt_pdf_t *pdf, const unsigned char *image, int int length_id = pdf->next_id++; // the image - //start + // start _pdf_set_offset(pdf, pdf_image->object_id, pdf->bytes_written + bytes_written); - bytes_written += fprintf(pdf->fd, - "%d 0 obj\n" - "<<\n" - "/Type /XObject\n" - "/Subtype /Image\n" - "/Name /Im%d\n" - "/Filter [ %s ]\n" - "/Width %d\n" - "/Height %d\n", - pdf_image->object_id, pdf_image->name_id, stream_encoder_filters[pdf->default_encoder], width, height - ); - // As I understand it in the printing case DeviceRGB (==> icc_id = 0) is enough since the pixel data is in the device space then. + bytes_written += fprintf(pdf->fd, "%d 0 obj\n" + "<<\n" + "/Type /XObject\n" + "/Subtype /Image\n" + "/Name /Im%d\n" + "/Filter [ %s ]\n" + "/Width %d\n" + "/Height %d\n", + pdf_image->object_id, pdf_image->name_id, stream_encoder_filters[pdf->default_encoder], + width, height); + // As I understand it in the printing case DeviceRGB (==> icc_id = 0) is enough since the pixel data is in the + // device space then. if(icc_id > 0) bytes_written += fprintf(pdf->fd, "/ColorSpace [ /ICCBased %d 0 R ]\n", icc_id); else bytes_written += fprintf(pdf->fd, "/ColorSpace /DeviceRGB\n"); bytes_written += fprintf(pdf->fd, - "/BitsPerComponent %d\n" - "/Intent /Perceptual\n" // TODO: allow setting it from the outside - "/Length %d 0 R\n" - ">>\n" - "stream\n", - bpp, length_id - ); + "/BitsPerComponent %d\n" + "/Intent /Perceptual\n" // TODO: allow setting it from the outside + "/Length %d 0 R\n" + ">>\n" + "stream\n", + bpp, length_id); // the stream stream_size = _pdf_write_stream(pdf, pdf->default_encoder, image, width * height * 3 * (bpp / 8)); @@ -443,12 +438,10 @@ dt_pdf_image_t *dt_pdf_add_image(dt_pdf_t *pdf, const unsigned char *image, int } bytes_written += stream_size; - //end - bytes_written += fprintf(pdf->fd, - "\n" - "endstream\n" - "endobj\n" - ); + // end + bytes_written += fprintf(pdf->fd, "\n" + "endstream\n" + "endobj\n"); // length of the last stream _pdf_set_offset(pdf, length_id, pdf->bytes_written + bytes_written); @@ -474,37 +467,31 @@ dt_pdf_page_t *dt_pdf_add_page(dt_pdf_t *pdf, dt_pdf_image_t **images, int n_ima // the page object _pdf_set_offset(pdf, pdf_page->object_id, pdf->bytes_written + bytes_written); - bytes_written += fprintf(pdf->fd, - "%d 0 obj\n" - "<<\n" - "/Type /Page\n" - "/Parent 2 0 R\n" - "/Resources <<\n" - "/XObject <<", - pdf_page->object_id - ); + bytes_written += fprintf(pdf->fd, "%d 0 obj\n" + "<<\n" + "/Type /Page\n" + "/Parent 2 0 R\n" + "/Resources <<\n" + "/XObject <<", + pdf_page->object_id); for(int i = 0; i < n_images; i++) bytes_written += fprintf(pdf->fd, "/Im%d %d 0 R\n", images[i]->name_id, images[i]->object_id); - bytes_written += fprintf(pdf->fd, - ">>\n" - "/ProcSet [ /PDF /Text /ImageC ] >>\n" - "/MediaBox [0 0 %d %d]\n" - "/Contents %d 0 R\n" - ">>\n" - "endobj\n", - (int)(pdf->page_width + 0.5), (int)(pdf->page_height + 0.5), content_id - ); + bytes_written += fprintf(pdf->fd, ">>\n" + "/ProcSet [ /PDF /Text /ImageC ] >>\n" + "/MediaBox [0 0 %d %d]\n" + "/Contents %d 0 R\n" + ">>\n" + "endobj\n", + (int)(pdf->page_width + 0.5), (int)(pdf->page_height + 0.5), content_id); // page content _pdf_set_offset(pdf, content_id, pdf->bytes_written + bytes_written); - bytes_written += fprintf(pdf->fd, - "%d 0 obj\n" - "<<\n" - "/Length %d 0 R\n" - ">>\n" - "stream\n", - content_id, length_id - ); + bytes_written += fprintf(pdf->fd, "%d 0 obj\n" + "<<\n" + "/Length %d 0 R\n" + ">>\n" + "stream\n", + content_id, length_id); // the stream -- we need its size in the length object // we want the image printed with at least the given DPI, scaling it down to fit the page if it is too big @@ -573,32 +560,29 @@ dt_pdf_page_t *dt_pdf_add_page(dt_pdf_t *pdf, dt_pdf_image_t **images, int n_ima if(images[i]->outline_mode) { // instead of drawign the image we just draw the outlines - stream_size += fprintf(pdf->fd, - "q\n" - "[4 6] 0 d\n" - "%s %s %s %s re\n" - "S\n" - "Q\n", - translate_x_str, translate_y_str, scale_x_str, scale_y_str - ); + stream_size += fprintf(pdf->fd, "q\n" + "[4 6] 0 d\n" + "%s %s %s %s re\n" + "S\n" + "Q\n", + translate_x_str, translate_y_str, scale_x_str, scale_y_str); } else { stream_size += fprintf(pdf->fd, - "q\n" - "1 0 0 1 %s %s cm\n", // translate - translate_x_str, translate_y_str - ); + "q\n" + "1 0 0 1 %s %s cm\n", // translate + translate_x_str, + translate_y_str); if(rotate_to_fit) stream_size += fprintf(pdf->fd, - "0 1 -1 0 0 0 cm\n" // rotate - ); + "0 1 -1 0 0 0 cm\n" // rotate + ); stream_size += fprintf(pdf->fd, - "%s 0 0 %s 0 0 cm\n" // scale - "/Im%d Do\n" - "Q\n", - scale_x_str, scale_y_str, images[i]->name_id - ); + "%s 0 0 %s 0 0 cm\n" // scale + "/Im%d Do\n" + "Q\n", + scale_x_str, scale_y_str, images[i]->name_id); } // DEBUG: draw the bounding box @@ -614,20 +598,16 @@ dt_pdf_page_t *dt_pdf_add_page(dt_pdf_t *pdf, dt_pdf_image_t **images, int n_ima g_ascii_dtostr(bb_w_str, G_ASCII_DTOSTR_BUF_SIZE, images[i]->bb_width); g_ascii_dtostr(bb_h_str, G_ASCII_DTOSTR_BUF_SIZE, images[i]->bb_height); - stream_size += fprintf(pdf->fd, - "q\n" - "%s %s %s %s re\n" - "S\n" - "Q\n", - bb_x_str, bb_y_str, bb_w_str, bb_h_str - ); + stream_size += fprintf(pdf->fd, "q\n" + "%s %s %s %s re\n" + "S\n" + "Q\n", + bb_x_str, bb_y_str, bb_w_str, bb_h_str); } } - bytes_written += fprintf(pdf->fd, - "endstream\n" - "endobj\n" - ); + bytes_written += fprintf(pdf->fd, "endstream\n" + "endobj\n"); bytes_written += stream_size; // length of the last stream @@ -653,20 +633,16 @@ void dt_pdf_finish(dt_pdf_t *pdf, dt_pdf_page_t **pages, int n_pages) // the pages dictionary _pdf_set_offset(pdf, 2, pdf->bytes_written + bytes_written); bytes_written += fprintf(pdf->fd, - "2 0 obj\n" // yes, this is hardcoded to be object 2, even if written in the end - "<<\n" - "/Type /Pages\n" - "/Kids [\n" - ); - for(int i = 0; i < n_pages; i++) - bytes_written += fprintf(pdf->fd, "%d 0 R\n", pages[i]->object_id); - bytes_written += fprintf(pdf->fd, - "]\n" - "/Count %d\n" - ">>\n" - "endobj\n", - n_pages - ); + "2 0 obj\n" // yes, this is hardcoded to be object 2, even if written in the end + "<<\n" + "/Type /Pages\n" + "/Kids [\n"); + for(int i = 0; i < n_pages; i++) bytes_written += fprintf(pdf->fd, "%d 0 R\n", pages[i]->object_id); + bytes_written += fprintf(pdf->fd, "]\n" + "/Count %d\n" + ">>\n" + "endobj\n", + n_pages); // the info @@ -696,7 +672,7 @@ void dt_pdf_finish(dt_pdf_t *pdf, dt_pdf_page_t **pages, int n_pages) { time_str[14] = '5'; time_str[15] = '9'; - time_str[16] = '\0'; /* for safety */ + time_str[16] = '\0'; /* for safety */ } /* get the time zone offset */ @@ -724,19 +700,15 @@ void dt_pdf_finish(dt_pdf_t *pdf, dt_pdf_page_t **pages, int n_pages) time_error: _pdf_set_offset(pdf, info_id, pdf->bytes_written + bytes_written); - bytes_written += fprintf(pdf->fd, - "%d 0 obj\n" - "<<\n" - "/Title (%s)\n", - info_id, pdf->title ? pdf->title : "untitled" - ); + bytes_written += fprintf(pdf->fd, "%d 0 obj\n" + "<<\n" + "/Title (%s)\n", + info_id, pdf->title ? pdf->title : "untitled"); if(*time_str) { - bytes_written += fprintf(pdf->fd, - "/CreationDate (%1$s)\n" - "/ModDate (%1$s)\n", - time_str - ); + bytes_written += fprintf(pdf->fd, "/CreationDate (%1$s)\n" + "/ModDate (%1$s)\n", + time_str); } bytes_written += fprintf(pdf->fd, "/Producer (%s http://www.darktable.org)\n" ">>\n" @@ -746,25 +718,23 @@ void dt_pdf_finish(dt_pdf_t *pdf, dt_pdf_page_t **pages, int n_pages) pdf->bytes_written += bytes_written; // the cross reference table - fprintf(pdf->fd, - "xref\n" - "0 %d\n" - "0000000000 65535 f \n", - pdf->next_id - ); + fprintf(pdf->fd, "xref\n" + "0 %d\n" + "0000000000 65535 f \n", + pdf->next_id); for(int i = 0; i < pdf->next_id - 1; i++) fprintf(pdf->fd, "%010zu 00000 n \n", pdf->offsets[i]); // the trailer fprintf(pdf->fd, - "trailer\n" - "<<\n" - "/Size %d\n" - "/Info %d 0 R\n" // we want to have the Info last in the file, so this is /Size - 1 - "/Root 1 0 R\n" - "/ID [<dead> <babe>]\n" // TODO find something less necrophilic, maybe hash of image + history? or just of filename + date :) - ">>\n", - pdf->next_id, info_id - ); + "trailer\n" + "<<\n" + "/Size %d\n" + "/Info %d 0 R\n" // we want to have the Info last in the file, so this is /Size - 1 + "/Root 1 0 R\n" + "/ID [<dead> <babe>]\n" // TODO find something less necrophilic, maybe hash of image + history? or just + // of filename + date :) + ">>\n", + pdf->next_id, info_id); // and finally the file footer with the offset of the xref section fprintf(pdf->fd, "startxref\n" @@ -780,7 +750,7 @@ void dt_pdf_finish(dt_pdf_t *pdf, dt_pdf_page_t **pages, int n_pages) #ifdef STANDALONE // just for debugging to read a ppm file -float * read_ppm(const char * filename, int * wd, int * ht) +float *read_ppm(const char *filename, int *wd, int *ht) { FILE *f = g_fopen(filename, "rb"); @@ -800,7 +770,7 @@ float * read_ppm(const char * filename, int * wd, int * ht) return NULL; } - float *image = (float*)malloc(sizeof(float) * width * height * 3); + float *image = (float *)malloc(sizeof(float) * width * height * 3); if(max <= 255) { @@ -815,12 +785,11 @@ float * read_ppm(const char * filename, int * wd, int * ht) fclose(f); return NULL; } - // and transform it into 0..1 range - #ifdef _OPENMP - #pragma omp parallel for schedule(static) default(none) shared(image, tmp, width, height, max) - #endif - for(int i = 0; i < width * height * 3; i++) - image[i] = (float)tmp[i] / max; +// and transform it into 0..1 range +#ifdef _OPENMP +#pragma omp parallel for schedule(static) default(none) shared(image, tmp, width, height, max) +#endif + for(int i = 0; i < width * height * 3; i++) image[i] = (float)tmp[i] / max; free(tmp); } else @@ -836,18 +805,16 @@ float * read_ppm(const char * filename, int * wd, int * ht) fclose(f); return NULL; } - // swap byte order - #ifdef _OPENMP - #pragma omp parallel for schedule(static) default(none) shared(tmp, width, height) - #endif - for(int k = 0; k < 3 * width * height; k++) - tmp[k] = ((tmp[k] & 0xff) << 8) | (tmp[k] >> 8); - // and transform it into 0..1 range - #ifdef _OPENMP - #pragma omp parallel for schedule(static) default(none) shared(image, tmp, max, width, height) - #endif - for(int i = 0; i < width * height * 3; i++) - image[i] = (float)tmp[i] / max; +// swap byte order +#ifdef _OPENMP +#pragma omp parallel for schedule(static) default(none) shared(tmp, width, height) +#endif + for(int k = 0; k < 3 * width * height; k++) tmp[k] = ((tmp[k] & 0xff) << 8) | (tmp[k] >> 8); +// and transform it into 0..1 range +#ifdef _OPENMP +#pragma omp parallel for schedule(static) default(none) shared(image, tmp, max, width, height) +#endif + for(int i = 0; i < width * height * 3; i++) image[i] = (float)tmp[i] / max; free(tmp); } fclose(f); @@ -900,10 +867,9 @@ int main(int argc, char *argv[]) } #ifdef _OPENMP - #pragma omp parallel for schedule(static) default(none) shared(image, data, width, height) +#pragma omp parallel for schedule(static) default(none) shared(image, data, width, height) #endif - for(int i = 0; i < width * height * 3; i++) - data[i] = CLAMP_FLT(image[i]) * 65535; + for(int i = 0; i < width * height * 3; i++) data[i] = CLAMP_FLT(image[i]) * 65535; images[i] = dt_pdf_add_image(pdf, (unsigned char *)data, width, height, 16, icc_id, border); free(image); @@ -911,12 +877,13 @@ int main(int argc, char *argv[]) } // add pages with one image each, filling the page minus borders - for(int i = 0; i < n_images; i++) - pages[i] = dt_pdf_add_page(pdf, &images[i], 1); + for(int i = 0; i < n_images; i++) pages[i] = dt_pdf_add_page(pdf, &images[i], 1); // add the whole bunch of images to the last page - // images' default bounding boxen span the whole page, so set them a little smaller first, also enable bounding box drawing. - // we can also set outline mode afterwards. note that it is NOT safe to load images with outline_mode = 1 and then set it to 0 later! + // images' default bounding boxen span the whole page, so set them a little smaller first, also enable bounding + // box drawing. + // we can also set outline mode afterwards. note that it is NOT safe to load images with outline_mode = 1 and + // then set it to 0 later! { // TODO: use border and add new pages when we filled one up float bb_size = dt_pdf_mm_to_point(60); @@ -935,7 +902,7 @@ int main(int argc, char *argv[]) images[i]->bb_x = x; images[i]->bb_y = y; x += bb_step; - if((i+1) % n_x == 0) + if((i + 1) % n_x == 0) { x = bb_empty * 0.5; y += bb_step; @@ -947,10 +914,8 @@ int main(int argc, char *argv[]) dt_pdf_finish(pdf, pages, n_pages); - for(int i = 0; i < n_images; i++) - free(images[i]); - for(int i = 0; i < n_pages; i++) - free(pages[i]); + for(int i = 0; i < n_images; i++) free(images[i]); + for(int i = 0; i < n_pages; i++) free(pages[i]); return 0; } diff --git a/src/common/pdf.h b/src/common/pdf.h index 25583a172d03..87e6ed13b280 100644 --- a/src/common/pdf.h +++ b/src/common/pdf.h @@ -113,10 +113,12 @@ static const struct static const int dt_pdf_paper_sizes_n = sizeof(dt_pdf_paper_sizes) / sizeof(dt_pdf_paper_sizes[0]); // construction of the pdf -dt_pdf_t *dt_pdf_start(const char *filename, float width, float height, float dpi, dt_pdf_stream_encoder_t default_encoder); +dt_pdf_t *dt_pdf_start(const char *filename, float width, float height, float dpi, + dt_pdf_stream_encoder_t default_encoder); int dt_pdf_add_icc(dt_pdf_t *pdf, const char *filename); int dt_pdf_add_icc_from_data(dt_pdf_t *pdf, const unsigned char *data, size_t size); -dt_pdf_image_t *dt_pdf_add_image(dt_pdf_t *pdf, const unsigned char *image, int bpp, int width, int height, int icc_id, float border); +dt_pdf_image_t *dt_pdf_add_image(dt_pdf_t *pdf, const unsigned char *image, int bpp, int width, int height, + int icc_id, float border); dt_pdf_page_t *dt_pdf_add_page(dt_pdf_t *pdf, dt_pdf_image_t **images, int n_images); void dt_pdf_finish(dt_pdf_t *pdf, dt_pdf_page_t **pages, int n_pages); diff --git a/src/common/points.h b/src/common/points.h index cee0cb0d4929..73b864e5d7ce 100644 --- a/src/common/points.h +++ b/src/common/points.h @@ -21,7 +21,7 @@ #ifndef __SSE2__ -#if !defined _XOPEN_SOURCE && !defined(__DragonFly__) && !defined(__FreeBSD__) && !defined(__NetBSD__) \ +#if !defined _XOPEN_SOURCE && !defined(__DragonFly__) && !defined(__FreeBSD__) && !defined(__NetBSD__) \ && !defined(__OpenBSD__) && !defined(__WIN32__) #define _XOPEN_SOURCE #endif @@ -203,37 +203,37 @@ static inline float dt_points_get() #define PARITY4 0x13c9e684U -#define ALTI_SL1 \ - { \ - SL1, SL1, SL1, SL1 \ +#define ALTI_SL1 \ + { \ + SL1, SL1, SL1, SL1 \ } -#define ALTI_SR1 \ - { \ - SR1, SR1, SR1, SR1 \ +#define ALTI_SR1 \ + { \ + SR1, SR1, SR1, SR1 \ } -#define ALTI_MSK \ - { \ - MSK1, MSK2, MSK3, MSK4 \ +#define ALTI_MSK \ + { \ + MSK1, MSK2, MSK3, MSK4 \ } -#define ALTI_MSK64 \ - { \ - MSK2, MSK1, MSK4, MSK3 \ +#define ALTI_MSK64 \ + { \ + MSK2, MSK1, MSK4, MSK3 \ } -#define ALTI_SL2_PERM \ - { \ - 1, 2, 3, 23, 5, 6, 7, 0, 9, 10, 11, 4, 13, 14, 15, 8 \ +#define ALTI_SL2_PERM \ + { \ + 1, 2, 3, 23, 5, 6, 7, 0, 9, 10, 11, 4, 13, 14, 15, 8 \ } -#define ALTI_SL2_PERM64 \ - { \ - 1, 2, 3, 4, 5, 6, 7, 31, 9, 10, 11, 12, 13, 14, 15, 0 \ +#define ALTI_SL2_PERM64 \ + { \ + 1, 2, 3, 4, 5, 6, 7, 31, 9, 10, 11, 12, 13, 14, 15, 0 \ } -#define ALTI_SR2_PERM \ - { \ - 7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, 17, 12, 13, 14 \ +#define ALTI_SR2_PERM \ + { \ + 7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, 17, 12, 13, 14 \ } -#define ALTI_SR2_PERM64 \ - { \ - 15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, 11, 12, 13, 14 \ +#define ALTI_SR2_PERM64 \ + { \ + 15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, 11, 12, 13, 14 \ } #define IDSTR "SFMT-19937:122-18-1-11-1:dfffffef-ddfecb7f-bffaffff-bffffff6" @@ -454,8 +454,7 @@ inline static double genrand_res53_mix(struct sfmt_state_t *s) #ifndef SFMT_SSE2_H #define SFMT_SSE2_H -PRE_ALWAYS static __m128i mm_recursion(__m128i *a, __m128i *b, __m128i c, __m128i d, - __m128i mask) ALWAYSINLINE; +PRE_ALWAYS static __m128i mm_recursion(__m128i *a, __m128i *b, __m128i c, __m128i d, __m128i mask) ALWAYSINLINE; /** * This function represents the recursion formula. @@ -1088,8 +1087,7 @@ void init_by_array(sfmt_state_t *s, uint32_t *init_key, int key_length) count--; for(i = 1, j = 0; (j < count) && (j < key_length); j++) { - r = func1(s->psfmt32[idxof(i)] ^ s->psfmt32[idxof((i + mid) % N32)] - ^ s->psfmt32[idxof((i + N32 - 1) % N32)]); + r = func1(s->psfmt32[idxof(i)] ^ s->psfmt32[idxof((i + mid) % N32)] ^ s->psfmt32[idxof((i + N32 - 1) % N32)]); s->psfmt32[idxof((i + mid) % N32)] += r; r += init_key[j] + i; s->psfmt32[idxof((i + mid + lag) % N32)] += r; @@ -1098,8 +1096,7 @@ void init_by_array(sfmt_state_t *s, uint32_t *init_key, int key_length) } for(; j < count; j++) { - r = func1(s->psfmt32[idxof(i)] ^ s->psfmt32[idxof((i + mid) % N32)] - ^ s->psfmt32[idxof((i + N32 - 1) % N32)]); + r = func1(s->psfmt32[idxof(i)] ^ s->psfmt32[idxof((i + mid) % N32)] ^ s->psfmt32[idxof((i + N32 - 1) % N32)]); s->psfmt32[idxof((i + mid) % N32)] += r; r += i; s->psfmt32[idxof((i + mid + lag) % N32)] += r; @@ -1108,8 +1105,7 @@ void init_by_array(sfmt_state_t *s, uint32_t *init_key, int key_length) } for(j = 0; j < N32; j++) { - r = func2(s->psfmt32[idxof(i)] + s->psfmt32[idxof((i + mid) % N32)] - + s->psfmt32[idxof((i + N32 - 1) % N32)]); + r = func2(s->psfmt32[idxof(i)] + s->psfmt32[idxof((i + mid) % N32)] + s->psfmt32[idxof((i + N32 - 1) % N32)]); s->psfmt32[idxof((i + mid) % N32)] ^= r; r -= i; s->psfmt32[idxof((i + mid + lag) % N32)] ^= r; diff --git a/src/common/poison.h b/src/common/poison.h index 0112f693c980..34a75c14d5e4 100644 --- a/src/common/poison.h +++ b/src/common/poison.h @@ -16,10 +16,10 @@ #pragma GCC poison vsprintf // use vsnprintf #pragma GCC poison strcpy // use g_strncpy //#pragma GCC poison strncpy // use g_strncpy -#pragma GCC poison strcat // use g_strncat -#pragma GCC poison strncat // use g_strncat +#pragma GCC poison strcat // use g_strncat +#pragma GCC poison strncat // use g_strncat #pragma GCC poison pthread_create // use dt_pthread_create, musl issues -#pragma GCC poison fopen // use g_fopen +#pragma GCC poison fopen // use g_fopen // #pragma GCC poison open // use g_open -- this one doesn't work #pragma GCC poison unlink // use g_unlink diff --git a/src/common/printprof.c b/src/common/printprof.c index 95a6515a6b72..e43b1fa05b6d 100644 --- a/src/common/printprof.c +++ b/src/common/printprof.c @@ -22,20 +22,22 @@ #include <glib.h> #include <unistd.h> -static cmsUInt32Number ComputeOutputFormatDescriptor (cmsUInt32Number dwInput, int OutColorSpace, int bps) +static cmsUInt32Number ComputeOutputFormatDescriptor(cmsUInt32Number dwInput, int OutColorSpace, int bps) { - int IsPlanar = T_PLANAR(dwInput); - int Channels = 3; - int IsFlt = 0; - return (FLOAT_SH(IsFlt)|COLORSPACE_SH(OutColorSpace)|PLANAR_SH(IsPlanar)|CHANNELS_SH(Channels)|BYTES_SH(bps)); + int IsPlanar = T_PLANAR(dwInput); + int Channels = 3; + int IsFlt = 0; + return (FLOAT_SH(IsFlt) | COLORSPACE_SH(OutColorSpace) | PLANAR_SH(IsPlanar) | CHANNELS_SH(Channels) + | BYTES_SH(bps)); } -static cmsUInt32Number ComputeFormatDescriptor (int OutColorSpace, int bps) +static cmsUInt32Number ComputeFormatDescriptor(int OutColorSpace, int bps) { - int IsPlanar = 0; - int Channels = 3; + int IsPlanar = 0; + int Channels = 3; int IsFlt = 0; - return (FLOAT_SH(IsFlt)|COLORSPACE_SH(OutColorSpace)|PLANAR_SH(IsPlanar)|CHANNELS_SH(Channels)|BYTES_SH(bps)); + return (FLOAT_SH(IsFlt) | COLORSPACE_SH(OutColorSpace) | PLANAR_SH(IsPlanar) | CHANNELS_SH(Channels) + | BYTES_SH(bps)); } int dt_apply_printer_profile(int imgid, void **in, uint32_t width, uint32_t height, int bpp, @@ -46,8 +48,7 @@ int dt_apply_printer_profile(int imgid, void **in, uint32_t width, uint32_t heig cmsUInt32Number wInput, wOutput; int OutputColorSpace; - if(!hOutProfile) - return 1; + if(!hOutProfile) return 1; const dt_colorspaces_color_profile_t *in_profile = dt_colorspaces_get_output_profile(imgid); if(!in_profile || !in_profile->profile) @@ -57,26 +58,23 @@ int dt_apply_printer_profile(int imgid, void **in, uint32_t width, uint32_t heig } hInProfile = in_profile->profile; - wInput = ComputeFormatDescriptor (PT_RGB, (bpp==8?1:2)); + wInput = ComputeFormatDescriptor(PT_RGB, (bpp == 8 ? 1 : 2)); OutputColorSpace = _cmsLCMScolorSpace(cmsGetColorSpace(hOutProfile)); wOutput = ComputeOutputFormatDescriptor(wInput, OutputColorSpace, 1); - hTransform = cmsCreateTransform - (hInProfile, wInput, - hOutProfile, wOutput, - intent, - black_point_compensation ? cmsFLAGS_BLACKPOINTCOMPENSATION : 0); + hTransform = cmsCreateTransform(hInProfile, wInput, hOutProfile, wOutput, intent, + black_point_compensation ? cmsFLAGS_BLACKPOINTCOMPENSATION : 0); - if (!hTransform) + if(!hTransform) { fprintf(stderr, "error printer profile may be corrupted\n"); return 1; } - void *out = (void *)malloc(width*height*3); + void *out = (void *)malloc(width * height * 3); - if (bpp == 8) + if(bpp == 8) { const uint8_t *ptr_in = (uint8_t *)*in; uint8_t *ptr_out = (uint8_t *)out; @@ -84,8 +82,8 @@ int dt_apply_printer_profile(int imgid, void **in, uint32_t width, uint32_t heig #ifdef _OPENMP #pragma omp parallel for schedule(static) default(none) shared(ptr_in, ptr_out, hTransform, height, width) #endif - for (int k=0; k<height; k++) - cmsDoTransform(hTransform, (const void *)&ptr_in[k*width*3], (void *)&ptr_out[k*width*3], width); + for(int k = 0; k < height; k++) + cmsDoTransform(hTransform, (const void *)&ptr_in[k * width * 3], (void *)&ptr_out[k * width * 3], width); } else { @@ -95,8 +93,8 @@ int dt_apply_printer_profile(int imgid, void **in, uint32_t width, uint32_t heig #ifdef _OPENMP #pragma omp parallel for schedule(static) default(none) shared(ptr_in, ptr_out, hTransform, height, width) #endif - for (int k=0; k<height; k++) - cmsDoTransform(hTransform, (const void *)&ptr_in[k*width*3], (void *)&ptr_out[k*width*3], width); + for(int k = 0; k < height; k++) + cmsDoTransform(hTransform, (const void *)&ptr_in[k * width * 3], (void *)&ptr_out[k * width * 3], width); } cmsDeleteTransform(hTransform); diff --git a/src/common/profiling.h b/src/common/profiling.h index 0b01b008493e..1611a705c93e 100644 --- a/src/common/profiling.h +++ b/src/common/profiling.h @@ -22,19 +22,19 @@ #ifdef USE_DARKTABLE_PROFILING -#define TIMER_START(name, description) \ +#define TIMER_START(name, description) \ dt_timer_t *name = dt_timer_start_with_name(__FILE__, __FUNCTION__, description) #else -#define TIMER_START(name, description) \ - { \ +#define TIMER_START(name, description) \ + { \ } #endif #ifdef USE_DARKTABLE_PROFILING #define TIMER_STOP(name) dt_timer_stop_with_name(name) #else -#define TIMER_STOP(name) \ - { \ +#define TIMER_STOP(name) \ + { \ } #endif diff --git a/src/common/pwstorage/backend_kwallet.c b/src/common/pwstorage/backend_kwallet.c index ce7dd72850c9..b4764a91b104 100644 --- a/src/common/pwstorage/backend_kwallet.c +++ b/src/common/pwstorage/backend_kwallet.c @@ -147,8 +147,8 @@ static gboolean start_kwallet(backend_kwallet_context_t *context) */ GVariant *ret = g_dbus_connection_call_sync(context->connection, klauncher_service_name, klauncher_path, klauncher_interface, "start_service_by_desktop_name", - g_variant_new("(sasassb)", "kwalletd", NULL, NULL, "", FALSE), - NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + g_variant_new("(sasassb)", "kwalletd", NULL, NULL, "", FALSE), NULL, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if(check_error(error)) { @@ -181,8 +181,8 @@ static gboolean init_kwallet(backend_kwallet_context_t *context) // Make a proxy to KWallet. if(context->proxy) g_object_unref(context->proxy); - context->proxy = g_dbus_proxy_new_sync(context->connection, G_DBUS_PROXY_FLAGS_NONE, NULL, - kwallet_service_name, kwallet_path, kwallet_interface, NULL, &error); + context->proxy = g_dbus_proxy_new_sync(context->connection, G_DBUS_PROXY_FLAGS_NONE, NULL, kwallet_service_name, + kwallet_path, kwallet_interface, NULL, &error); if(check_error(error)) { @@ -205,8 +205,7 @@ static gboolean init_kwallet(backend_kwallet_context_t *context) // Get the wallet name. g_free(context->wallet_name); - ret = g_dbus_proxy_call_sync(context->proxy, "networkWallet", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, - &error); + ret = g_dbus_proxy_call_sync(context->proxy, "networkWallet", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); child = g_variant_get_child_value(ret, 0); context->wallet_name = g_variant_dup_string(child, NULL); @@ -274,9 +273,9 @@ static int get_wallet_handle(const backend_kwallet_context_t *context) * * out i arg_0 */ - GVariant *ret = g_dbus_proxy_call_sync(context->proxy, "open", - g_variant_new("(sxs)", context->wallet_name, 0LL, app_id), - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + GVariant *ret + = g_dbus_proxy_call_sync(context->proxy, "open", g_variant_new("(sxs)", context->wallet_name, 0LL, app_id), + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if(check_error(error)) { @@ -300,9 +299,8 @@ static int get_wallet_handle(const backend_kwallet_context_t *context) * * out b arg_0 */ - ret = g_dbus_proxy_call_sync(context->proxy, "hasFolder", - g_variant_new("(iss)", handle, kwallet_folder, app_id), G_DBUS_CALL_FLAGS_NONE, - -1, NULL, &error); + ret = g_dbus_proxy_call_sync(context->proxy, "hasFolder", g_variant_new("(iss)", handle, kwallet_folder, app_id), + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if(check_error(error)) { @@ -330,8 +328,8 @@ static int get_wallet_handle(const backend_kwallet_context_t *context) * out b arg_0 */ ret = g_dbus_proxy_call_sync(context->proxy, "createFolder", - g_variant_new("(iss)", handle, kwallet_folder, app_id), - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + g_variant_new("(iss)", handle, kwallet_folder, app_id), G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error); if(check_error(error)) { @@ -352,8 +350,7 @@ static int get_wallet_handle(const backend_kwallet_context_t *context) // Store (key,value) pairs from a GHashTable in the kwallet. // Every 'slot' has to take care of it's own data. -gboolean dt_pwstorage_kwallet_set(const backend_kwallet_context_t *context, const gchar *slot, - GHashTable *table) +gboolean dt_pwstorage_kwallet_set(const backend_kwallet_context_t *context, const gchar *slot, GHashTable *table) { printf("slot %s\n", slot); @@ -408,8 +405,8 @@ gboolean dt_pwstorage_kwallet_set(const backend_kwallet_context_t *context, cons GVariant *ret = g_dbus_proxy_call_sync( context->proxy, "writeMap", g_variant_new("(iss@ays)", wallet_handle, kwallet_folder, slot, - g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING, byte_array->data, byte_array->len, - TRUE, g_free, byte_array->data), + g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING, byte_array->data, byte_array->len, TRUE, + g_free, byte_array->data), app_id), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); @@ -427,8 +424,7 @@ gboolean dt_pwstorage_kwallet_set(const backend_kwallet_context_t *context, cons g_variant_unref(ret); if(return_code != 0) - dt_print(DT_DEBUG_PWSTORAGE, "[pwstorage_kwallet_set] Warning: bad return code %d from kwallet\n", - return_code); + dt_print(DT_DEBUG_PWSTORAGE, "[pwstorage_kwallet_set] Warning: bad return code %d from kwallet\n", return_code); return return_code == 0; } diff --git a/src/common/pwstorage/backend_kwallet.h b/src/common/pwstorage/backend_kwallet.h index 2c9e8323c737..9ddab12175b9 100644 --- a/src/common/pwstorage/backend_kwallet.h +++ b/src/common/pwstorage/backend_kwallet.h @@ -38,8 +38,7 @@ const backend_kwallet_context_t *dt_pwstorage_kwallet_new(); /** Cleanup and destroy kwallet backend context. */ void dt_pwstorage_kwallet_destroy(const backend_kwallet_context_t *context); /** Store (key,value) pairs. */ -gboolean dt_pwstorage_kwallet_set(const backend_kwallet_context_t *context, const gchar *slot, - GHashTable *table); +gboolean dt_pwstorage_kwallet_set(const backend_kwallet_context_t *context, const gchar *slot, GHashTable *table); /** Load (key,value) pairs. */ GHashTable *dt_pwstorage_kwallet_get(const backend_kwallet_context_t *context, const gchar *slot); diff --git a/src/common/pwstorage/backend_libsecret.c b/src/common/pwstorage/backend_libsecret.c index 9e8679a8c584..b92cef99b412 100644 --- a/src/common/pwstorage/backend_libsecret.c +++ b/src/common/pwstorage/backend_libsecret.c @@ -45,8 +45,7 @@ static const SecretSchema *secret_darktable_get_schema(void) "org.darktable.Password", SECRET_SCHEMA_NONE, { - { "slot", SECRET_SCHEMA_ATTRIBUTE_STRING }, { "magic", SECRET_SCHEMA_ATTRIBUTE_STRING }, { "NULL", 0 }, - } + { "slot", SECRET_SCHEMA_ATTRIBUTE_STRING }, { "magic", SECRET_SCHEMA_ATTRIBUTE_STRING }, { "NULL", 0 }, } }; return &darktable_schema; @@ -71,8 +70,7 @@ const backend_libsecret_context_t *dt_pwstorage_libsecret_new() return NULL; } - if(secret_service) - g_object_unref(secret_service); + if(secret_service) g_object_unref(secret_service); return context; } @@ -105,15 +103,8 @@ gboolean dt_pwstorage_libsecret_set(const backend_libsecret_context_t *context, return FALSE; } - gboolean res = secret_password_store_sync(SECRET_SCHEMA_DARKTABLE, - SECRET_COLLECTION_DARKTABLE, - label, - secret_value, - NULL, - &error, - "slot", slot, - "magic", PACKAGE_NAME, - NULL); + gboolean res = secret_password_store_sync(SECRET_SCHEMA_DARKTABLE, SECRET_COLLECTION_DARKTABLE, label, + secret_value, NULL, &error, "slot", slot, "magic", PACKAGE_NAME, NULL); if(!res) { fprintf(stderr, "[pwstorage_libsecret] error storing password: %s\n", error->message); @@ -137,12 +128,8 @@ GHashTable *dt_pwstorage_libsecret_get(const backend_libsecret_context_t *contex goto error; } - secret_value = secret_password_lookup_sync(SECRET_SCHEMA_DARKTABLE, - NULL, - &error, - "slot", slot, - "magic", PACKAGE_NAME, - NULL); + secret_value = secret_password_lookup_sync(SECRET_SCHEMA_DARKTABLE, NULL, &error, "slot", slot, "magic", + PACKAGE_NAME, NULL); if(error) { fprintf(stderr, "[pwstorage_libsecret] error retrieving password: %s\n", error->message); diff --git a/src/common/pwstorage/pwstorage.c b/src/common/pwstorage/pwstorage.c index 8122bfb04284..13e1dba981a1 100644 --- a/src/common/pwstorage/pwstorage.c +++ b/src/common/pwstorage/pwstorage.c @@ -112,8 +112,7 @@ const dt_pwstorage_t *dt_pwstorage_new() } break; #else - dt_print(DT_DEBUG_PWSTORAGE, - "[pwstorage_new] libsecret backend not available. using no storage backend.\n"); + dt_print(DT_DEBUG_PWSTORAGE, "[pwstorage_new] libsecret backend not available. using no storage backend.\n"); pwstorage->backend_context = NULL; pwstorage->pw_storage_backend = PW_STORAGE_BACKEND_NONE; #endif @@ -134,8 +133,7 @@ const dt_pwstorage_t *dt_pwstorage_new() dt_print(DT_DEBUG_PWSTORAGE, " done.\n"); break; #else - dt_print(DT_DEBUG_PWSTORAGE, - "[pwstorage_new] kwallet backend not available. using no storage backend.\n"); + dt_print(DT_DEBUG_PWSTORAGE, "[pwstorage_new] kwallet backend not available. using no storage backend.\n"); pwstorage->backend_context = NULL; pwstorage->pw_storage_backend = PW_STORAGE_BACKEND_NONE; #endif @@ -189,8 +187,8 @@ gboolean dt_pwstorage_set(const gchar *slot, GHashTable *table) break; case PW_STORAGE_BACKEND_LIBSECRET: #if HAVE_LIBSECRET - return dt_pwstorage_libsecret_set((backend_libsecret_context_t *)darktable.pwstorage->backend_context, - slot, table); + return dt_pwstorage_libsecret_set((backend_libsecret_context_t *)darktable.pwstorage->backend_context, slot, + table); #endif break; case PW_STORAGE_BACKEND_KWALLET: @@ -213,8 +211,7 @@ GHashTable *dt_pwstorage_get(const gchar *slot) break; case PW_STORAGE_BACKEND_LIBSECRET: #if HAVE_LIBSECRET - return dt_pwstorage_libsecret_get((backend_libsecret_context_t *)darktable.pwstorage->backend_context, - slot); + return dt_pwstorage_libsecret_get((backend_libsecret_context_t *)darktable.pwstorage->backend_context, slot); #endif break; case PW_STORAGE_BACKEND_KWALLET: diff --git a/src/common/ratings.c b/src/common/ratings.c index 55e4e6f3a7a6..8db0e44e2edc 100644 --- a/src/common/ratings.c +++ b/src/common/ratings.c @@ -48,8 +48,8 @@ void dt_ratings_apply_to_selection(int rating) if(rating == 6) dt_control_log(ngettext("rejecting %d image", "rejecting %d images", count), count); else - dt_control_log(ngettext("applying rating %d to %d image", "applying rating %d to %d images", count), - rating, count); + dt_control_log(ngettext("applying rating %d to %d image", "applying rating %d to %d images", count), rating, + count); #if 0 // not updating cache gchar query[1024]= {0}; g_snprintf(query,sizeof(query), "UPDATE main.images SET flags=(flags & ~7) | (7 & %d) WHERE id IN " diff --git a/src/common/resource_limits.c b/src/common/resource_limits.c index 0bd8402dd4e6..e64930dab4dc 100644 --- a/src/common/resource_limits.c +++ b/src/common/resource_limits.c @@ -21,16 +21,16 @@ #endif #include "common/resource_limits.h" -#include <assert.h> // for assert -#include <errno.h> // for errno -#include <stdint.h> // for uintmax_t -#include <stdio.h> // for fprintf, stderr -#include <string.h> // for strerror +#include <assert.h> // for assert +#include <errno.h> // for errno +#include <stdint.h> // for uintmax_t +#include <stdio.h> // for fprintf, stderr +#include <string.h> // for strerror #ifdef _WIN32 #include "win/rlimit.h" #else #include <sys/resource.h> // for rlimit, RLIMIT_STACK, getrlimit, setrlimit -#endif //_WIN32 +#endif //_WIN32 static void dt_set_rlimits_stack() { diff --git a/src/common/rlucy_deblur.c b/src/common/rlucy_deblur.c index fc199deac325..bcc192dce52d 100644 --- a/src/common/rlucy_deblur.c +++ b/src/common/rlucy_deblur.c @@ -1,51 +1,53 @@ +/* + This file is part of darktable, + copyright (c) 2017 Edgardo Hoszowski. + copyright (c) 2017 Aurélien Pierre. -#include <stdlib.h> -#include "develop/imageop.h" -#include "common/interpolation.h" - -#include "common/convolution.h" - -#include "rlucy_deblur.h" - -//----------------------------------------------------------------------------------------- + This work would not have been possible without the research of Daniele Perrone, Paolo Favaro and Anath Levin. -/* -Created on 30 avr. 2017 + darktable is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -@author: aurelien + darktable is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -This script shows an implementation of the Richardson-Lucy deconvolution. + You should have received a copy of the GNU General Public License + along with darktable. If not, see <http://www.gnu.org/licenses/>. +*/ -In theory, blurred and noisy pictures can be perfectly sharpened if we perfectly -know the [*Point spread function*](https://en.wikipedia.org/wiki/Point_spread_function) -of their maker. In practice, we can only estimate it. -One of the means to do so is the [Richardson-Lucy deconvolution](https://en.wikipedia.org/wiki/Richardson%E2%80%93Lucy_deconvolution). +#include <stdlib.h> +#include <cblas.h> -The Richardson-Lucy algorithm used here has a damping coefficient wich allows to remove from -the iterations the pixels which deviate to much (x times the standard deviation of the difference -source image - deconvoluted image) from the original image. This pixels are considered -noise and would be amplificated from iteration to iteration otherwise. +#include "develop/imageop.h" +#include "common/interpolation.h" +#include "common/convolution.h" -*/ +#include "rlucy_deblur.h" -//----------------------------------------------------------------------------------------- //#define RLUCY_NAN #ifdef RLUCY_NAN -static void rlucy_check_nan(rlucy_image_t* im, const char *str) +static void rlucy_check_nan(rlucy_image_t *im, const char *str) { int i_nan = 0; - - for (int i = 0; i < im->w*im->h*im->h; i++) if ( isnan(im->im[i]) ) i_nan++; - - if (i_nan > 0) printf("%s nan: %i\n", str, i_nan); + + for(int i = 0; i < im->w * im->h * im->h; i++) + if(isnan(im->im[i])) i_nan++; + + if(i_nan > 0) printf("%s nan: %i\n", str, i_nan); } #else - -#define rlucy_check_nan(im, str) {} + +#define rlucy_check_nan(im, str) \ + { \ + } #endif @@ -75,47 +77,21 @@ static void rlucy_check_nan(rlucy_image_t* im, const char *str) #define MAX_TIME 20 -const char *rlucy_time_desc[MAX_TIME] = { - "dummy " - ,"fft lock " - ,"fft execute " - ,"fft copy " - ,"fft mult " - ,"fft plan " - ,"convolve " - ,"sum " - ,"subtract " - ,"mulsub " - ,"add " - ,"pad image " - ,"unpad image " - ,"trim mask " - ,"divTV " - ,"rotate " - ,"gradient " - ,"divide " - ,"process " - ,"build kernel " -}; +const char *rlucy_time_desc[MAX_TIME] + = { "dummy ", "fft lock ", "fft execute ", "fft copy ", "fft mult ", + "fft plan ", "convolve ", "sum ", "subtract ", "mulsub ", + "add ", "pad image ", "unpad image ", "trim mask ", "divTV ", + "rotate ", "gradient ", "divide ", "process ", "build kernel " }; #define RLUCY_TIME - #ifdef RLUCY_TIME - #define RLUCY_TIME_DECL double start = 0; - #define RLUCY_TIME_BEGIN start = dt_get_wtime(); - #define RLUCY_TIME_END(time_index) time[time_index] += dt_get_wtime() - start; - #else - #define RLUCY_TIME_DECL ; - #define RLUCY_TIME_BEGIN ; - #define RLUCY_TIME_END(time_index) ; - #endif //----------------------------------------------------------------------------------------- @@ -132,7 +108,7 @@ typedef struct static void rlucy_free_image(rlucy_image_t *image) { - if (image->im) + if(image->im) { dt_free_align(image->im); image->im = NULL; @@ -144,9 +120,9 @@ static void rlucy_free_image(rlucy_image_t *image) static void rlucy_alloc_image(rlucy_image_t *image, const int w, const int h, const int c) { // re-alloc - if (image->im != NULL) + if(image->im != NULL) { - if (image->alloc_size >= w * h * c) + if(image->alloc_size >= w * h * c) { image->w = w; image->h = h; @@ -157,8 +133,8 @@ static void rlucy_alloc_image(rlucy_image_t *image, const int w, const int h, co rlucy_free_image(image); } } - - if (image->im == NULL) + + if(image->im == NULL) { image->w = w; image->h = h; @@ -168,63 +144,62 @@ static void rlucy_alloc_image(rlucy_image_t *image, const int w, const int h, co } } -static void rlucy_copy_image(rlucy_image_t * img_dest, rlucy_image_t *img_src) +static void rlucy_copy_image(rlucy_image_t *img_dest, rlucy_image_t *img_src) { - if (img_dest->im == NULL || img_src->im == NULL) + if(img_dest->im == NULL || img_src->im == NULL) { printf("rlucy_copy_image: NULL image\n"); return; } - - if (img_src->w == img_dest->w && img_src->h == img_dest->h && img_src->c == img_dest->c) + + if(img_src->w == img_dest->w && img_src->h == img_dest->h && img_src->c == img_dest->c) { memcpy(img_dest->im, img_src->im, img_src->w * img_src->h * img_src->c * sizeof(float)); return; } - - if (img_src->c == img_dest->c) + + if(img_src->c == img_dest->c) { const int h = MIN(img_src->h, img_dest->h); const int size = MIN(img_src->w * img_src->c, img_dest->w * img_dest->c) * sizeof(float); - - for (int y = 0; y < h; y++) + + for(int y = 0; y < h; y++) { float *dest = img_dest->im + y * img_dest->w * img_dest->c; float *src = img_src->im + y * img_src->w * img_src->c; - + memcpy(dest, src, size); } } else printf("rlucy_copy_image: different channels not implemented\n"); - } -static void rlucy_resize_1c(rlucy_image_t *image_src, rlucy_image_t *image_dest, const float scale, const int new_w, const int new_h, - rlucy_image_t *im_tmp_in, rlucy_image_t *im_tmp_out) +static void rlucy_resize_1c(rlucy_image_t *image_src, rlucy_image_t *image_dest, const float scale, + const int new_w, const int new_h, rlucy_image_t *im_tmp_in, rlucy_image_t *im_tmp_out) { float *out = NULL; float *in = NULL; - dt_iop_roi_t roi_out = {0}; - dt_iop_roi_t roi_in = {0}; + dt_iop_roi_t roi_out = { 0 }; + dt_iop_roi_t roi_in = { 0 }; int32_t out_stride = 0; int32_t in_stride = 0; - + // in-place - if (image_src->im == image_dest->im) + if(image_src->im == image_dest->im) { - if (scale == 1.f) return; + if(scale == 1.f) return; } else { - if (scale == 1.f) + if(scale == 1.f) { rlucy_alloc_image(image_dest, image_src->w, image_src->h, image_src->c); memcpy(image_dest->im, image_src->im, image_dest->w * image_dest->h * image_dest->c * sizeof(float)); return; } } - + roi_in.width = image_src->w; roi_in.height = image_src->h; roi_in.scale = 1.0f; @@ -239,68 +214,67 @@ static void rlucy_resize_1c(rlucy_image_t *image_src, rlucy_image_t *image_dest, rlucy_alloc_image(im_tmp_out, roi_out.width, roi_out.height, 4); rlucy_alloc_image(im_tmp_in, roi_in.width, roi_in.height, 4); memset(im_tmp_in->im, 0, im_tmp_in->alloc_size * sizeof(float)); - + out = im_tmp_out->im; in = im_tmp_in->im; - + int size = image_src->w * image_src->h; - for (int i = 0; i < size; i++) + for(int i = 0; i < size; i++) { - in[i*4] = image_src->im[i]; + in[i * 4] = image_src->im[i]; } - + const struct dt_interpolation *itor = dt_interpolation_new(DT_INTERPOLATION_USERPREF); - + dt_interpolation_resample(itor, out, &roi_out, out_stride, in, &roi_in, in_stride); rlucy_alloc_image(image_dest, roi_out.width, roi_out.height, image_src->c); - + size = image_dest->w * image_dest->h; - for (int i = 0; i < size; i++) + for(int i = 0; i < size; i++) { - image_dest->im[i] = out[i*4]; + image_dest->im[i] = out[i * 4]; } - } -static void rlucy_resize(rlucy_image_t *image_src, rlucy_image_t *image_dest, const float scale, const int new_w, const int new_h, - rlucy_image_t *im_tmp_in, rlucy_image_t *im_tmp_out) +static void rlucy_resize(rlucy_image_t *image_src, rlucy_image_t *image_dest, const float scale, const int new_w, + const int new_h, rlucy_image_t *im_tmp_in, rlucy_image_t *im_tmp_out) { - if (image_src->c == 1) + if(image_src->c == 1) { rlucy_resize_1c(image_src, image_dest, scale, new_w, new_h, im_tmp_in, im_tmp_out); return; } - + float *out = NULL; float *in = NULL; - dt_iop_roi_t roi_out = {0}; - dt_iop_roi_t roi_in = {0}; + dt_iop_roi_t roi_out = { 0 }; + dt_iop_roi_t roi_in = { 0 }; int32_t out_stride = 0; int32_t in_stride = 0; - - rlucy_image_t im_dest = {0}; - + + rlucy_image_t im_dest = { 0 }; + // in-place - if (image_src->im == image_dest->im) + if(image_src->im == image_dest->im) { - if (scale == 1.f) return; - + if(scale == 1.f) return; + rlucy_alloc_image(&im_dest, new_w, new_h, image_src->c); } else { rlucy_alloc_image(image_dest, new_w, new_h, image_src->c); - - if (scale == 1.f) + + if(scale == 1.f) { memcpy(image_dest->im, image_src->im, image_dest->w * image_dest->h * image_dest->c * sizeof(float)); return; } - + im_dest = *image_dest; } - + roi_in.width = image_src->w; roi_in.height = image_src->h; roi_in.scale = 1.0f; @@ -316,15 +290,15 @@ static void rlucy_resize(rlucy_image_t *image_src, rlucy_image_t *image_dest, co in = image_src->im; const struct dt_interpolation *itor = dt_interpolation_new(DT_INTERPOLATION_USERPREF); - + dt_interpolation_resample(itor, out, &roi_out, out_stride, in, &roi_in, in_stride); // in-place - if (image_src->im == image_dest->im) + if(image_src->im == image_dest->im) { rlucy_alloc_image(image_dest, roi_out.width, roi_out.height, image_src->c); memcpy(image_dest->im, im_dest.im, image_dest->w * image_dest->h * image_dest->c * sizeof(float)); - + rlucy_free_image(&im_dest); } else @@ -332,57 +306,56 @@ static void rlucy_resize(rlucy_image_t *image_src, rlucy_image_t *image_dest, co image_dest->w = roi_out.width; image_dest->h = roi_out.height; } - } static void rlucy_img_sum(const rlucy_image_t *const image, float *sum, double *time) { RLUCY_TIME_DECL RLUCY_TIME_BEGIN - + + // FIXME use OpenBLAS + const int size = image->w * image->h * image->c; - for (int c = 0; c < image->c; c++) - sum[c] = 0.f; + for(int c = 0; c < image->c; c++) sum[c] = 0.f; - for (int i = 0; i < size; i += image->c) + for(int i = 0; i < size; i += image->c) { - for (int c = 0; c < image->c; c++) - sum[c] += image->im[i+c]; + for(int c = 0; c < image->c; c++) sum[c] += image->im[i + c]; } - + RLUCY_TIME_END(TIME_SUM) - } static void rlucy_img_abs(const rlucy_image_t *const image, double *time) { RLUCY_TIME_DECL RLUCY_TIME_BEGIN - + const int size = image->w * image->h * image->c; - for (int i = 0; i < size; i += image->c) +#ifdef _OPENMP +#pragma omp parallel for default(none) schedule(static) +#endif + for(int i = 0; i < size; i += image->c) { - for (int c = 0; c < image->c; c++) - image->im[i+c] = fabs(image->im[i+c]); + for(int c = 0; c < image->c; c++) image->im[i + c] = fabs(image->im[i + c]); } - + RLUCY_TIME_END(TIME_SUM) - } static void rlucy_img_divide(rlucy_image_t *image, float *div, double *time) { RLUCY_TIME_DECL RLUCY_TIME_BEGIN - + const int size = image->w * image->h * image->c; - float mult[4] = {0}; - - for (int c = 0; c < image->c; c++) + float mult[4] = { 0 }; + + for(int c = 0; c < image->c; c++) { - if (div[c] == 0.f) + if(div[c] == 0.f) { mult[c] = 0.f; printf("rlucy_img_divide: division by zero\n"); @@ -390,23 +363,22 @@ static void rlucy_img_divide(rlucy_image_t *image, float *div, double *time) else mult[c] = 1.f / div[c]; } - + float *im = image->im; const int ch = image->c; - -#ifdef _OPENMPx + +#ifdef _OPENMP #pragma omp parallel for default(none) shared(im, mult) schedule(static) #endif - for (int i = 0; i < size; i+=ch) + for(int i = 0; i < size; i += ch) { - for (int c = 0; c < ch; c++) + for(int c = 0; c < ch; c++) { - im[i+c] *= mult[c]; + im[i + c] *= mult[c]; } } - + RLUCY_TIME_END(TIME_DIVIDE) - } #if 0 @@ -419,7 +391,7 @@ static void rlucy_img_multiply(rlucy_image_t *image, float *mult, double *time) float *im = image->im; const int ch = image->c; - + #ifdef _OPENMPx #pragma omp parallel for default(none) shared(im, mult) schedule(static) #endif @@ -440,36 +412,34 @@ static void rlucy_img_subtract_1(rlucy_image_t *image, float *sub, double *time) { RLUCY_TIME_DECL RLUCY_TIME_BEGIN - + const int size = image->w * image->h * image->c; - + float *im = image->im; const int ch = image->c; - -#ifdef _OPENMPx + +#ifdef _OPENMP #pragma omp parallel for default(none) shared(im, sub) schedule(static) #endif - for (int i = 0; i < size; i+=ch) + for(int i = 0; i < size; i += ch) { - for (int c = 0; c < ch; c++) + for(int c = 0; c < ch; c++) { - im[i+c] -= sub[c]; + im[i + c] -= sub[c]; } } - + RLUCY_TIME_END(TIME_DIVIDE) - } -static void rlucy_img_subtract(rlucy_image_t *img_in1, - const rlucy_image_t *const img_in2, double *time) +static void rlucy_img_subtract(rlucy_image_t *img_in1, const rlucy_image_t *const img_in2, double *time) { RLUCY_TIME_DECL RLUCY_TIME_BEGIN - + const int size = img_in1->w * img_in1->h * img_in1->c; - - if (img_in1->w != img_in2->w || img_in1->h != img_in2->h) + + if(img_in1->w != img_in2->w || img_in1->h != img_in2->h) { printf("rlucy_img_subtract: invalid image size\n"); return; @@ -477,21 +447,20 @@ static void rlucy_img_subtract(rlucy_image_t *img_in1, float *img_in1_im = img_in1->im; const float *const img_in2_im = img_in2->im; - -#ifdef _OPENMPx + +#ifdef _OPENMP #pragma omp parallel for default(none) shared(img_in1_im) schedule(static) #endif - for (int i = 0; i < size; i++) + for(int i = 0; i < size; i++) { img_in1_im[i] -= img_in2_im[i]; } - + RLUCY_TIME_END(TIME_SUBTRACT) - } #if 0 -static void rlucy_img_add(rlucy_image_t *img_in1, +static void rlucy_img_add(rlucy_image_t *img_in1, const rlucy_image_t *const img_in2, double *time) { RLUCY_TIME_DECL @@ -507,7 +476,7 @@ static void rlucy_img_add(rlucy_image_t *img_in1, float *img_in1_im = img_in1->im; const float *const img_in2_im = img_in2->im; - + #ifdef _OPENMPx #pragma omp parallel for default(none) shared(img_in1_im) schedule(static) #endif @@ -521,15 +490,14 @@ static void rlucy_img_add(rlucy_image_t *img_in1, } #endif -static void rlucy_img_add3(rlucy_image_t *img_in1, - const rlucy_image_t *const img_in2, float *add, double *time) +static void rlucy_img_add3(rlucy_image_t *img_in1, const rlucy_image_t *const img_in2, float *add, double *time) { RLUCY_TIME_DECL RLUCY_TIME_BEGIN - + const int size = img_in1->w * img_in1->h * img_in1->c; - - if (img_in1->w != img_in2->w || img_in1->h != img_in2->h) + + if(img_in1->w != img_in2->w || img_in1->h != img_in2->h) { printf("rlucy_img_add3: invalid image size\n"); return; @@ -537,30 +505,27 @@ static void rlucy_img_add3(rlucy_image_t *img_in1, float *img_in1_im = img_in1->im; const float *const img_in2_im = img_in2->im; - -#ifdef _OPENMPx -#pragma omp parallel for default(none) shared(img_in1_im) schedule(static) + +#ifdef _OPENMP +#pragma omp parallel for default(none) shared(img_in1_im, add, img_in1) schedule(static) #endif - for (int i = 0; i < size; i+=img_in1->c) + for(int i = 0; i < size; i += img_in1->c) { - for (int c = 0; c < img_in1->c; c++) - img_in1_im[i+c] += img_in2_im[i+c] + add[c]; + for(int c = 0; c < img_in1->c; c++) img_in1_im[i + c] += img_in2_im[i + c] + add[c]; } - + RLUCY_TIME_END(TIME_SUBTRACT) - } -static void rlucy_img_mulsub(rlucy_image_t *img_in1, - const rlucy_image_t *const img_in2, - const float *const mult, double *time) +static void rlucy_img_mulsub(rlucy_image_t *img_in1, const rlucy_image_t *const img_in2, const float *const mult, + double *time) { RLUCY_TIME_DECL RLUCY_TIME_BEGIN - + const int size = img_in1->w * img_in1->h * img_in1->c; - - if (img_in1->w != img_in2->w || img_in1->h != img_in2->h) + + if(img_in1->w != img_in2->w || img_in1->h != img_in2->h) { printf("rlucy_img_mulsub: invalid image size\n"); return; @@ -569,32 +534,30 @@ static void rlucy_img_mulsub(rlucy_image_t *img_in1, float *img_in1_im = img_in1->im; const float *const img_in2_im = img_in2->im; const int ch = img_in1->c; - -#ifdef _OPENMPx + +#ifdef _OPENMP #pragma omp parallel for default(none) shared(img_in1_im) schedule(static) #endif - for (int i = 0; i < size; i+=ch) + for(int i = 0; i < size; i += ch) { - for (int c = 0; c < ch; c++) + for(int c = 0; c < ch; c++) { - img_in1_im[i+c] -= img_in2_im[i+c] * mult[c]; + img_in1_im[i + c] -= img_in2_im[i + c] * mult[c]; } } - + RLUCY_TIME_END(TIME_MULSUB) - } -static void rlucy_img_divadd(rlucy_image_t *img_in1, - const rlucy_image_t *const img_in2, - const float *const add, double *time) +static void rlucy_img_divadd(rlucy_image_t *img_in1, const rlucy_image_t *const img_in2, const float *const add, + double *time) { RLUCY_TIME_DECL RLUCY_TIME_BEGIN - + const int size = img_in1->w * img_in1->h * img_in1->c; - - if (img_in1->w != img_in2->w || img_in1->h != img_in2->h) + + if(img_in1->w != img_in2->w || img_in1->h != img_in2->h) { printf("rlucy_img_divadd: invalid image size\n"); return; @@ -603,141 +566,129 @@ static void rlucy_img_divadd(rlucy_image_t *img_in1, float *img_in1_im = img_in1->im; const float *const img_in2_im = img_in2->im; const int ch = img_in1->c; - -#ifdef _OPENMPx + +#ifdef _OPENMP #pragma omp parallel for default(none) shared(img_in1_im) schedule(static) #endif - for (int i = 0; i < size; i+=ch) + for(int i = 0; i < size; i += ch) { - for (int c = 0; c < ch; c++) + for(int c = 0; c < ch; c++) { - float div = img_in2_im[i+c] + add[c]; - if (div != 0.f && div != -0.f) - img_in1_im[i+c] /= div; + float div = img_in2_im[i + c] + add[c]; + if(div != 0.f && div != -0.f) + img_in1_im[i + c] /= div; else printf("rlucy_img_divadd: division by zero\n"); } } - + RLUCY_TIME_END(TIME_MULSUB) - } -static void pad_image(const rlucy_image_t *const img_src, - const int pad_h, const int pad_v, - rlucy_image_t *img_dest, rlucy_image_t *img_tmp1, double *time) +static void pad_image(const rlucy_image_t *const img_src, const int pad_h, const int pad_v, + rlucy_image_t *img_dest, rlucy_image_t *img_tmp1, double *time) { RLUCY_TIME_DECL RLUCY_TIME_BEGIN - - if (img_src->im == img_dest->im) + + if(img_src->im == img_dest->im) { - pad_image(img_src, - pad_h, pad_v, - img_tmp1, img_tmp1, time); + pad_image(img_src, pad_h, pad_v, img_tmp1, img_tmp1, time); rlucy_alloc_image(img_dest, img_tmp1->w, img_tmp1->h, img_tmp1->c); rlucy_copy_image(img_dest, img_tmp1); } else { rlucy_alloc_image(img_dest, img_src->w + pad_h * 2, img_src->h + pad_v * 2, img_src->c); - - convolve_pad_image(img_src->im, img_src->w, img_src->h, img_src->c, - pad_h, pad_v, - img_dest->im, img_dest->w, img_dest->h, time); + + convolve_pad_image(img_src->im, img_src->w, img_src->h, img_src->c, pad_h, pad_v, img_dest->im, img_dest->w, + img_dest->h, time); } - - RLUCY_TIME_END(TIME_PADIMAGE) + RLUCY_TIME_END(TIME_PADIMAGE) } -static void unpad_image(rlucy_image_t * img_dest, - const int pad_h, const int pad_v, - rlucy_image_t *img_src, rlucy_image_t *img_tmp1, double *time) +static void unpad_image(rlucy_image_t *img_dest, const int pad_h, const int pad_v, rlucy_image_t *img_src, + rlucy_image_t *img_tmp1, double *time) { RLUCY_TIME_DECL RLUCY_TIME_BEGIN - - if (img_src->im == img_dest->im) + + if(img_src->im == img_dest->im) { - unpad_image(img_tmp1, - pad_h, pad_v, - img_src, img_tmp1, time); + unpad_image(img_tmp1, pad_h, pad_v, img_src, img_tmp1, time); rlucy_alloc_image(img_dest, img_tmp1->w, img_tmp1->h, img_tmp1->c); rlucy_copy_image(img_dest, img_tmp1); } else { rlucy_alloc_image(img_dest, img_src->w - pad_h * 2, img_src->h - pad_v * 2, img_src->c); - + // copy image - for (int y = 0; y < img_dest->h; y++) + for(int y = 0; y < img_dest->h; y++) { float *dest = img_dest->im + y * img_dest->w * img_dest->c; float *src = img_src->im + (y + pad_v) * img_src->w * img_src->c + pad_h * img_src->c; - + memcpy(dest, src, img_dest->w * img_dest->c * sizeof(float)); } } - + RLUCY_TIME_END(TIME_UNPADIMAGE) } //----------------------------------------------------------------------------------------- -static void rlucy_convolve(const rlucy_image_t *const image, - const rlucy_image_t *const kernel, - const int mode, rlucy_image_t *img_dest, - convolve_data_t *fft_conv_data, - double *time) +static void rlucy_convolve(const rlucy_image_t *const image, const rlucy_image_t *const kernel, const int mode, + rlucy_image_t *img_dest, convolve_data_t *fft_conv_data, double *time) { + + // FIXME ensure correct padding + RLUCY_TIME_DECL RLUCY_TIME_BEGIN - + int w = 0, h = 0; - convolve_get_dest_size(image->w, image->h, - kernel->w, kernel->h, - &w, &h, mode); + convolve_get_dest_size(image->w, image->h, kernel->w, kernel->h, &w, &h, mode); rlucy_alloc_image(img_dest, w, h, image->c); - + memset(img_dest->im, 0, img_dest->w * img_dest->h * img_dest->c * sizeof(float)); - - convolve(fft_conv_data, image->im, image->w, image->h, image->c, - kernel->im, kernel->w, kernel->h, - img_dest->im, img_dest->w, img_dest->h, - mode, &(time[TIME_CONV_FFT_LOCK])); - + + convolve(fft_conv_data, image->im, image->w, image->h, image->c, kernel->im, kernel->w, kernel->h, img_dest->im, + img_dest->w, img_dest->h, mode, &(time[TIME_CONV_FFT_LOCK])); + RLUCY_TIME_END(TIME_CONVOLVE) - + rlucy_check_nan(img_dest, "rlucy_convolve fft"); - } static void rlucy_img_max(const rlucy_image_t *const image, float *max, double *time) { + + // FIXME use BLAS amax instead + RLUCY_TIME_DECL RLUCY_TIME_BEGIN - + const int size = image->w * image->h * image->c; - - for (int c = 0; c < image->c; c++) + + for(int c = 0; c < image->c; c++) { max[c] = -INFINITY; } - - for (int i = 0; i < size; i+=image->c) + + for(int i = 0; i < size; i += image->c) { - for (int c = 0; c < image->c; c++) + for(int c = 0; c < image->c; c++) { - max[c] = MAX(max[c], image->im[i+c]); + max[c] = MAX(max[c], image->im[i + c]); } } - + RLUCY_TIME_END(0) - } // from: @@ -748,43 +699,45 @@ static void rlucy_gradient(const rlucy_image_t *const f, rlucy_image_t *outvals, { RLUCY_TIME_DECL RLUCY_TIME_BEGIN - + + // FIXME use separable filters instead + int edge_order = 2; float *yy = NULL; int len_axes = 2; - const float dx[2] = {1.0f, 1.0f}; - + const float dx[2] = { 1.0f, 1.0f }; + yy = dt_alloc_align(64, f->w * f->h * f->c * sizeof(float)); - if (yy == NULL) goto cleanup; + if(yy == NULL) goto cleanup; memcpy(yy, f->im, f->w * f->h * f->c * sizeof(float)); - - for (int i = 0, axis = 0; i < len_axes; i++, axis++) + + for(int i = 0, axis = 0; i < len_axes; i++, axis++) { - rlucy_image_t out = {0}; - + rlucy_image_t out = { 0 }; + rlucy_alloc_image(&out, f->w, f->h, f->c); int uniform_spacing = 1; - if (uniform_spacing) + if(uniform_spacing) { const float dx_2 = 1.f / (2.f * dx[i]); - - if (axis == 0) + + if(axis == 0) { -#ifdef _OPENMPx +#ifdef _OPENMP #pragma omp parallel for default(none) shared(out, i) schedule(static) #endif - for (int y = 0; y < f->h; y++) + for(int y = 0; y < f->h; y++) { - for (int x = 1; x < f->w - 1; x++) + for(int x = 1; x < f->w - 1; x++) { const int idx_out = y * f->w * f->c + x * f->c; const int idx_f2 = y * f->w * f->c + (x - 1) * f->c; const int idx_f4 = y * f->w * f->c + (x + 1) * f->c; - - for (int c = 0; c < f->c; c++) + + for(int c = 0; c < f->c; c++) { out.im[idx_out + c] = (f->im[idx_f4 + c] - f->im[idx_f2 + c]) * dx_2; } @@ -793,18 +746,18 @@ static void rlucy_gradient(const rlucy_image_t *const f, rlucy_image_t *outvals, } else { -#ifdef _OPENMPx +#ifdef _OPENMP #pragma omp parallel for default(none) shared(out, i) schedule(static) #endif - for (int y = 1; y < f->h - 1; y++) + for(int y = 1; y < f->h - 1; y++) { - for (int x = 0; x < f->w; x++) + for(int x = 0; x < f->w; x++) { const int idx_out = y * f->w * f->c + x * f->c; const int idx_f2 = (y - 1) * f->w * f->c + x * f->c; const int idx_f4 = (y + 1) * f->w * f->c + x * f->c; - - for (int c = 0; c < f->c; c++) + + for(int c = 0; c < f->c; c++) { out.im[idx_out + c] = (f->im[idx_f4 + c] - f->im[idx_f2 + c]) * dx_2; } @@ -812,28 +765,28 @@ static void rlucy_gradient(const rlucy_image_t *const f, rlucy_image_t *outvals, } } } - - if (edge_order == 1) + + if(edge_order == 1) { } else { - if (uniform_spacing) + if(uniform_spacing) { const float ia = -1.5f / dx[i]; const float ib = 2.f / dx[i]; const float ic = -0.5f / dx[i]; - if (axis == 0) + if(axis == 0) { - for (int y = 0; y < f->h; y++) + for(int y = 0; y < f->h; y++) { const int idx_out = y * f->w * f->c; const int idx_y2 = y * f->w * f->c; const int idx_y3 = y * f->w * f->c + 1 * f->c; const int idx_y4 = y * f->w * f->c + 2 * f->c; - - for (int c = 0; c < f->c; c++) + + for(int c = 0; c < f->c; c++) { out.im[idx_out + c] = ia * yy[idx_y2 + c] + ib * yy[idx_y3 + c] + ic * yy[idx_y4 + c]; } @@ -841,14 +794,14 @@ static void rlucy_gradient(const rlucy_image_t *const f, rlucy_image_t *outvals, } else { - for (int x = 0; x < f->w; x++) + for(int x = 0; x < f->w; x++) { const int idx_out = x * f->c; const int idx_y2 = x * f->c; const int idx_y3 = x * f->c + 1 * f->w * f->c; const int idx_y4 = x * f->c + 2 * f->w * f->c; - - for (int c = 0; c < f->c; c++) + + for(int c = 0; c < f->c; c++) { out.im[idx_out + c] = ia * yy[idx_y2 + c] + ib * yy[idx_y3 + c] + ic * yy[idx_y4 + c]; } @@ -856,23 +809,23 @@ static void rlucy_gradient(const rlucy_image_t *const f, rlucy_image_t *outvals, } } } - - if (uniform_spacing) + + if(uniform_spacing) { const float ia = 0.5f / dx[i]; const float ib = -2.f / dx[i]; const float ic = 1.5f / dx[i]; - if (axis == 0) + if(axis == 0) { - for (int y = 0; y < f->h; y++) + for(int y = 0; y < f->h; y++) { const int idx_out = y * f->w * f->c + (f->w - 1) * f->c; const int idx_y2 = y * f->w * f->c + (f->w - 3) * f->c; const int idx_y3 = y * f->w * f->c + (f->w - 2) * f->c; const int idx_y4 = y * f->w * f->c + (f->w - 1) * f->c; - - for (int c = 0; c < f->c; c++) + + for(int c = 0; c < f->c; c++) { out.im[idx_out + c] = ia * yy[idx_y2 + c] + ib * yy[idx_y3 + c] + ic * yy[idx_y4 + c]; } @@ -880,14 +833,14 @@ static void rlucy_gradient(const rlucy_image_t *const f, rlucy_image_t *outvals, } else { - for (int x = 0; x < f->w; x++) + for(int x = 0; x < f->w; x++) { const int idx_out = (f->h - 1) * f->w * f->c + x * f->c; const int idx_y2 = (f->h - 3) * f->w * f->c + x * f->c; const int idx_y3 = (f->h - 2) * f->w * f->c + x * f->c; const int idx_y4 = (f->h - 1) * f->w * f->c + x * f->c; - - for (int c = 0; c < f->c; c++) + + for(int c = 0; c < f->c; c++) { out.im[idx_out + c] = ia * yy[idx_y2 + c] + ib * yy[idx_y3 + c] + ic * yy[idx_y4 + c]; } @@ -897,123 +850,119 @@ static void rlucy_gradient(const rlucy_image_t *const f, rlucy_image_t *outvals, outvals[axis] = out; } - + cleanup: - if (yy) dt_free_align(yy); - - RLUCY_TIME_END(TIME_GRADIENT) + if(yy) dt_free_align(yy); + RLUCY_TIME_END(TIME_GRADIENT) } static void rlucy_img_mean(const rlucy_image_t *const image, float *mean, double *time) { RLUCY_TIME_DECL RLUCY_TIME_BEGIN - + const int size = image->w * image->h * image->c; - - for (int c = 0; c < image->c; c++) + + for(int c = 0; c < image->c; c++) { mean[c] = 0.f; } - - for (int i = 0; i < size; i+=image->c) + + for(int i = 0; i < size; i += image->c) { - for (int c = 0; c < image->c; c++) + for(int c = 0; c < image->c; c++) { - mean[c] += image->im[i+c]; + mean[c] += image->im[i + c]; } } - - for (int c = 0; c < image->c; c++) + + for(int c = 0; c < image->c; c++) { mean[c] /= (float)(image->w * image->h); } - + RLUCY_TIME_END(0) - } static void rlucy_img_absmax(const rlucy_image_t *const image, float *max, double *time) { RLUCY_TIME_DECL RLUCY_TIME_BEGIN - + const int size = image->w * image->h * image->c; - - for (int c = 0; c < image->c; c++) + + for(int c = 0; c < image->c; c++) { max[c] = 0.f; } - - for (int i = 0; i < size; i+=image->c) + + for(int i = 0; i < size; i += image->c) { - for (int c = 0; c < image->c; c++) + for(int c = 0; c < image->c; c++) { - max[c] = MAX(max[c], fabs(image->im[i+c])); + max[c] = MAX(max[c], fabs(image->im[i + c])); } } - + RLUCY_TIME_END(0) - } -static void rlucy_img_rotate90(const rlucy_image_t *const img_in, - rlucy_image_t *img_dest, - const int times, double *time) +static void rlucy_img_rotate90(const rlucy_image_t *const img_in, rlucy_image_t *img_dest, const int times, + double *time) { RLUCY_TIME_DECL RLUCY_TIME_BEGIN - - if (times == 1) + + if(times == 1) { rlucy_alloc_image(img_dest, img_in->h, img_in->w, img_in->c); - - if (img_in->w != img_dest->h || img_in->h != img_dest->w) + + if(img_in->w != img_dest->h || img_in->h != img_dest->w) { printf("rlucy_img_rotate90: invalid image size\n"); return; } - for (int y = 0; y < img_in->h; y++) + for(int y = 0; y < img_in->h; y++) { const int x1 = (img_dest->w - y - 1) * img_dest->c; const int y2 = y * img_in->w * img_in->c; - - for (int x = 0; x < img_in->w; x++) + + for(int x = 0; x < img_in->w; x++) { const int y1 = (x * img_dest->w * img_dest->c) + x1; const int x2 = y2 + (x * img_in->c); - - for (int c = 0; c < img_in->c; c++) + + for(int c = 0; c < img_in->c; c++) { img_dest->im[y1 + c] = img_in->im[x2 + c]; } } } } - else if (times == 2) + else if(times == 2) { rlucy_alloc_image(img_dest, img_in->w, img_in->h, img_in->c); - - if (img_in->w != img_dest->w || img_in->h != img_dest->h) + + if(img_in->w != img_dest->w || img_in->h != img_dest->h) { printf("rlucy_img_rotate90: invalid image size\n"); return; } - for (int y = 0; y < img_in->h; y++) + for(int y = 0; y < img_in->h; y++) { const int y1 = (img_dest->h - y - 1) * img_dest->w * img_dest->c; const int y2 = (y * img_in->w * img_in->c); - - for (int x = 0; x < img_in->w; x++) + + for(int x = 0; x < img_in->w; x++) { const int x1 = y1 + (img_dest->w - x - 1) * img_dest->c; const int x2 = y2 + (x * img_in->c); - - for (int c = 0; c < img_in->c; c++) + + for(int c = 0; c < img_in->c; c++) { img_dest->im[x1 + c] = img_in->im[x2 + c]; } @@ -1022,89 +971,80 @@ static void rlucy_img_rotate90(const rlucy_image_t *const img_in, } else printf("rlucy_img_rotate90: invalid argument times\n"); - + RLUCY_TIME_END(TIME_ROTATE) - } // mask[left, top, width, height] -static void rlucy_trim_mask(const rlucy_image_t *const img_src, rlucy_image_t *img_dest, - const int im_x, const int im_y, const int im_w, const int im_h, rlucy_image_t *im_tmp1, - double *time) +static void rlucy_trim_mask(const rlucy_image_t *const img_src, rlucy_image_t *img_dest, const int im_x, + const int im_y, const int im_w, const int im_h, rlucy_image_t *im_tmp1, double *time) { RLUCY_TIME_DECL RLUCY_TIME_BEGIN - - if (img_src->im == img_dest->im) + + if(img_src->im == img_dest->im) { - rlucy_image_t tmp = {0}; - + rlucy_image_t tmp = { 0 }; + rlucy_trim_mask(img_src, im_tmp1, im_x, im_y, im_w, im_h, &tmp, time); rlucy_alloc_image(img_dest, im_tmp1->w, im_tmp1->h, im_tmp1->c); rlucy_copy_image(img_dest, im_tmp1); - + rlucy_free_image(&tmp); } else { rlucy_alloc_image(img_dest, im_w, im_h, img_src->c); - - if (img_dest->w > img_src->w || img_dest->h > img_src->h) - printf("rlucy_trim_mask: roi_dest > roi_src\n"); - if (img_dest->w+im_x > img_src->w || img_dest->h+im_y > img_src->h) + + if(img_dest->w > img_src->w || img_dest->h > img_src->h) printf("rlucy_trim_mask: roi_dest > roi_src\n"); + if(img_dest->w + im_x > img_src->w || img_dest->h + im_y > img_src->h) printf("rlucy_trim_mask: roi_dest+x > roi_src\n"); - + // copy image - for (int y = 0; y < img_dest->h; y++) + for(int y = 0; y < img_dest->h; y++) { const float *const src = img_src->im + (y + im_y) * img_src->w * img_src->c + im_x * img_src->c; float *dest = img_dest->im + y * img_dest->w * img_dest->c; - + memcpy(dest, src, img_dest->w * img_dest->c * sizeof(float)); } } - - RLUCY_TIME_END(TIME_TRIMMASK) + RLUCY_TIME_END(TIME_TRIMMASK) } -/* -@jit(float32[:](float32[:]), cache=True, nogil=True) -def _normalize_kernel(kern): -*/ -static void _normalize_kernel(rlucy_image_t *kern, double *time) +static void _normalize_kernel(rlucy_image_t *kern, double *time) { -/* kern[kern < 0] = 0 - kern /= np.sum(kern, axis=(0, 1)) - return kern -*/ + /* kern[kern < 0] = 0 + kern /= np.sum(kern, axis=(0, 1)) + return kern + */ // FIXME: axis=(0, 1) ??? - for (int i = 0; i < kern->w * kern->h * kern->c; i++) + for(int i = 0; i < kern->w * kern->h * kern->c; i++) { - if (kern->im[i] < 0.f) kern->im[i] = 0.f; + if(kern->im[i] < 0.f) kern->im[i] = 0.f; } - - float kern_sum[4] = {0}; + + float kern_sum[4] = { 0 }; rlucy_img_sum(kern, kern_sum, time); rlucy_img_divide(kern, kern_sum, time); } static void rlucy_img_dot(rlucy_image_t *image, float *dot) { - for (int c = 0; c < image->c; c++) + for(int c = 0; c < image->c; c++) { dot[c] = 0.f; } const int size = image->w * image->h * image->c; - for (int i = 0; i < size; i += image->c) + for(int i = 0; i < size; i += image->c) { - for (int c = 0; c < image->c; c++) + for(int c = 0; c < image->c; c++) { dot[c] += image->im[i + c] * image->im[i + c]; } } - } // from: https://github.com/numpy/numpy/blob/v1.13.0/numpy/linalg/linalg.py#L2014-L2257 @@ -1112,106 +1052,96 @@ static void rlucy_img_dot(rlucy_image_t *image, float *dot) // def norm(x, ord=None, axis=None, keepdims=False): static void rlucy_img_norm(rlucy_image_t *image, float *norm, double *time) { - + rlucy_img_dot(image, norm); - for (int c = 0; c < image->c; c++) - norm[c] = sqrtf(norm[c]); - + for(int c = 0; c < image->c; c++) norm[c] = sqrtf(norm[c]); } static void rlucy_img_norm2(rlucy_image_t *image1, rlucy_image_t *image2, float *norm, double *time) { - - float norm1[4] = {0}; - float norm2[4] = {0}; - + + float norm1[4] = { 0 }; + float norm2[4] = { 0 }; + rlucy_img_dot(image1, norm1); rlucy_img_dot(image2, norm2); - for (int c = 0; c < image1->c; c++) - norm[c] = sqrtf(norm1[c] + norm2[c]); - + for(int c = 0; c < image1->c; c++) norm[c] = sqrtf(norm1[c] + norm2[c]); } -/* -@jit(float32[:](float32[:], float32, float32), cache=True, nogil=True) -def best_param(image, lambd, p=1): -*/ + static void best_param(rlucy_image_t *image, float *lambd, int p, float *epsilon, double *time) { -/* - Determine by a statistical method the best lambda parameter. [1] + /* + Determine by a statistical method the best lambda parameter. [1] - Find the minimum acceptable epsilon to avoid a degenerate constant solution [2] + Find the minimum acceptable epsilon to avoid a degenerate constant solution [2] - Reference : - .. [1] https://pdfs.semanticscholar.org/1d84/0981a4623bcd26985300e6aa922266dab7d5.pdf - .. [2] http://www.cvg.unibe.ch/publications/perroneIJCV2015.pdf + Reference : + .. [1] https://pdfs.semanticscholar.org/1d84/0981a4623bcd26985300e6aa922266dab7d5.pdf + .. [2] http://www.cvg.unibe.ch/publications/perroneIJCV2015.pdf - :param image: - :return: -*/ + :param image: + :return: + */ - rlucy_image_t grad[2] = {0}; - rlucy_image_t img_tmp1 = {0}; - float grad_std[4] = {0}; - float grad_mean[4] = {0}; - float norm[4] = {0}; - float omega[4] = {0}; - - float mean[4] = {0}; + rlucy_image_t grad[2] = { 0 }; + rlucy_image_t img_tmp1 = { 0 }; + float grad_std[4] = { 0 }; + float grad_mean[4] = { 0 }; + float norm[4] = { 0 }; + float omega[4] = { 0 }; - /* grad = np.gradient(image) */ + float mean[4] = { 0 }; + + /* grad = np.gradient(image) */ rlucy_gradient(image, grad, time); - if (grad[0].im == NULL || grad[1].im == NULL) goto cleanup; + if(grad[0].im == NULL || grad[1].im == NULL) goto cleanup; - /* grad_std = np.linalg.norm(image - image.mean()) / image.size */ + /* grad_std = np.linalg.norm(image - image.mean()) / image.size */ rlucy_img_mean(image, mean, time); rlucy_alloc_image(&img_tmp1, image->w, image->h, image->c); rlucy_copy_image(&img_tmp1, image); rlucy_img_subtract_1(&img_tmp1, mean, time); rlucy_img_norm(&img_tmp1, norm, time); - for (int c = 0; c < image->c; c++) - grad_std[c] = norm[c] / (float)(image->w*image->h); - - /* grad_mean = np.linalg.norm(grad) / image.size */ + for(int c = 0; c < image->c; c++) grad_std[c] = norm[c] / (float)(image->w * image->h); + + /* grad_mean = np.linalg.norm(grad) / image.size */ rlucy_img_norm2(&(grad[0]), &(grad[1]), grad_mean, time); - for (int c = 0; c < image->c; c++) - grad_mean[c] = grad_mean[c] / (float)(image->w*image->h); + for(int c = 0; c < image->c; c++) grad_mean[c] = grad_mean[c] / (float)(image->w * image->h); - // # lambd = noise_reduction_factor * np.sum(np.sqrt(divTV(image, p=1)))**2 / (-np.log(np.std(image)**2) * * 2 * np.pi) + // # lambd = noise_reduction_factor * np.sum(np.sqrt(divTV(image, p=1)))**2 / (-np.log(np.std(image)**2) * * 2 * + // np.pi) - /* omega = 2 * lambd * grad_std / p */ - for (int c = 0; c < image->c; c++) - omega[c] = 2.f * lambd[c] * grad_std[c] / (float)p; - - /* epsilon = np.sqrt(grad_mean / (np.exp(omega) - 1)) */ - for (int c = 0; c < image->c; c++) + /* omega = 2 * lambd * grad_std / p */ + for(int c = 0; c < image->c; c++) omega[c] = 2.f * lambd[c] * grad_std[c] / (float)p; + + /* epsilon = np.sqrt(grad_mean / (np.exp(omega) - 1)) */ + for(int c = 0; c < image->c; c++) { - if (grad_mean[c] == 0.f || grad_mean[c] == -0.f) - printf("best_param: grad_mean is zero\n"); - + if(grad_mean[c] == 0.f || grad_mean[c] == -0.f) printf("best_param: grad_mean is zero\n"); + float div = (expf(omega[c]) - 1.f); epsilon[c] = sqrtf(grad_mean[c] / div); - -// double div = (exp((double)omega[c]) - 1.); -// epsilon[c] = sqrt(((double)grad_mean[c]) / div); - - if (epsilon[c] == 0.f || epsilon[c] == -0.f) + + // double div = (exp((double)omega[c]) - 1.); + // epsilon[c] = sqrt(((double)grad_mean[c]) / div); + + if(epsilon[c] == 0.f || epsilon[c] == -0.f) { - printf("best_param: epsilon is zero, grad_mean[c]=%f, div=%f, omega[c]=%f, grad_std[c]=%f, lambd[c]=%f\n", grad_mean[c], div, omega[c], grad_std[c], lambd[c]); + printf("best_param: epsilon is zero, grad_mean[c]=%f, div=%f, omega[c]=%f, grad_std[c]=%f, lambd[c]=%f\n", + grad_mean[c], div, omega[c], grad_std[c], lambd[c]); } } -// print(lambd, epsilon, p) - /* return epsilon * 1.001 */ - for (int c = 0; c < image->c; c++) + // print(lambd, epsilon, p) + /* return epsilon * 1.001 */ + for(int c = 0; c < image->c; c++) { - if (epsilon[c] == 0.f || epsilon[c] == -0.f) - printf("best_param: epsilon is zero\n"); - + if(epsilon[c] == 0.f || epsilon[c] == -0.f) printf("best_param: epsilon is zero\n"); + epsilon[c] *= 1.001f; } - cleanup: +cleanup: rlucy_free_image(&img_tmp1); rlucy_free_image(&(grad[0])); @@ -1224,16 +1154,17 @@ def divTV(u, epsilon=0, p=1): */ static void divTV(rlucy_image_t *u, float *epsilon, int p, rlucy_image_t *divtv, double *time) { - rlucy_image_t grad[2] = {0}; - - /* grad = np.gradient(u, edge_order=2) */ + rlucy_image_t grad[2] = { 0 }; + + /* grad = np.gradient(u, edge_order=2) */ rlucy_gradient(u, grad, time); - if (grad[0].im == NULL || grad[1].im == NULL) goto cleanup; + if(grad[0].im == NULL || grad[1].im == NULL) goto cleanup; - // # For Darktable implementation, don't bother to implement the p parameter, just use the p = 1 case to optimize the computations - if (p == 1) + // # For Darktable implementation, don't bother to implement the p parameter, just use the p = 1 case to optimize + // the computations + if(p == 1) { - /* return np.abs(grad[0]) + np.abs(grad[1]) + epsilon */ + /* return np.abs(grad[0]) + np.abs(grad[1]) + epsilon */ rlucy_img_abs(&(grad[0]), time); rlucy_img_abs(&(grad[1]), time); rlucy_img_add3(&(grad[0]), &(grad[1]), epsilon, time); @@ -1243,7 +1174,7 @@ static void divTV(rlucy_image_t *u, float *epsilon, int p, rlucy_image_t *divtv, /* else: return (np.abs(grad[0]) ** p + np.abs(grad[1]) ** p + epsilon ** p) ** (1 / p) */ - cleanup: +cleanup: rlucy_free_image(&(grad[0])); rlucy_free_image(&(grad[1])); @@ -1253,30 +1184,30 @@ static void divTV(rlucy_image_t *u, float *epsilon, int p, rlucy_image_t *divtv, @jit(float32[:](float32[:], float32[:], float32, float32, float32), cache=True, nogil=True) def gradTVEM(u, ut, epsilon=1e-3, tau=1e-1, p=0.5): */ -static void gradTVEM(rlucy_image_t *u, rlucy_image_t *ut, float *epsilon /* = 1e-3 */, float *tau /* = 1e-1 */, float p /* = 0.5 */, rlucy_image_t *img_dest, - double *time) +static void gradTVEM(rlucy_image_t *u, rlucy_image_t *ut, float *epsilon /* = 1e-3 */, float *tau /* = 1e-1 */, + float p /* = 0.5 */, rlucy_image_t *img_dest, double *time) { -/* TVt = divTV(ut, epsilon=epsilon, p=p) - TV = divTV(u, epsilon=epsilon, p=p) - return TV / (tau + TVt) -*/ + /* TVt = divTV(ut, epsilon=epsilon, p=p) + TV = divTV(u, epsilon=epsilon, p=p) + return TV / (tau + TVt) + */ rlucy_image_t *TV = img_dest; - rlucy_image_t TVt = {0}; - + rlucy_image_t TVt = { 0 }; + divTV(ut, epsilon, p, &TVt, time); divTV(u, epsilon, p, TV, time); rlucy_img_divadd(TV, &TVt, tau, time); - + rlucy_free_image(&TVt); } - + /* @jit(float32[:](float32[:], float32[:], float32[:]), cache=True, nogil=True) def _convolve_image(u, image, psf): */ -static void _convolve_image(const rlucy_image_t *const u, const rlucy_image_t *const image, const rlucy_image_t *const psf, rlucy_image_t *dest, - rlucy_image_t *tmp1, rlucy_image_t *tmp2, - convolve_data_t *fft_conv_data, double *time) +static void _convolve_image(const rlucy_image_t *const u, const rlucy_image_t *const image, + const rlucy_image_t *const psf, rlucy_image_t *dest, rlucy_image_t *tmp1, + rlucy_image_t *tmp2, convolve_data_t *fft_conv_data, double *time) { /* error = np.ascontiguousarray(convolve(u, psf, "valid"), np.float32) error -= image @@ -1286,16 +1217,15 @@ static void _convolve_image(const rlucy_image_t *const u, const rlucy_image_t *c rlucy_img_subtract(tmp1, image, time); rlucy_img_rotate90(psf, tmp2, 2, time); rlucy_convolve(tmp1, tmp2, convolve_mode_full, dest, fft_conv_data, time); - } /* @jit(float32[:](float32[:], float32[:], float32[:]), cache=True, nogil=True) def _convolve_kernel(u, image, psf): */ -static void _convolve_kernel(const rlucy_image_t *const u, const rlucy_image_t *const image, const rlucy_image_t *const psf, rlucy_image_t *dest, - rlucy_image_t *tmp1, rlucy_image_t *tmp2, - convolve_data_t *fft_conv_data, double *time) +static void _convolve_kernel(const rlucy_image_t *const u, const rlucy_image_t *const image, + const rlucy_image_t *const psf, rlucy_image_t *dest, rlucy_image_t *tmp1, + rlucy_image_t *tmp2, convolve_data_t *fft_conv_data, double *time) { /* error = np.ascontiguousarray(convolve(u, psf, "valid"), np.float32) error -= image @@ -1306,7 +1236,6 @@ static void _convolve_kernel(const rlucy_image_t *const u, const rlucy_image_t * rlucy_img_rotate90(u, tmp2, 2, time); rlucy_convolve(tmp2, tmp1, convolve_mode_valid, dest, fft_conv_data, time); - } /* @@ -1320,111 +1249,102 @@ def richardson_lucy_PAM(image: np.ndarray, mask=None, blind=True) -> np.ndarray: */ -static void richardson_lucy_PAM(rlucy_image_t *image, - rlucy_image_t *u, - rlucy_image_t *psf, - float *lambd, - int iterations, - float *epsilon /* = 1e-3 */, - int *mask /* = None */, - int blind /* = True */, - convolve_data_t *fft_conv_data, - double *time) +static void richardson_lucy_PAM(rlucy_image_t *image, rlucy_image_t *u, rlucy_image_t *psf, float *lambd, + int iterations, float *epsilon /* = 1e-3 */, int *mask /* = None */, + int blind /* = True */, convolve_data_t *fft_conv_data, double *time) { printf("richardson_lucy_PAM not implemented\n"); } - + /* @jit(float32[:](float32[:], float32[:], float32[:], float32, int16, float32[:], float32[:], float32), cache=True, nogil=True) def _update_both_MM(u, image, psf, lambd, iterations, mask_u, mask_i, epsilon): */ -static void _update_both_MM(rlucy_image_t *u, rlucy_image_t *image, rlucy_image_t *psf, float *lambd, - int iterations, float *mask_u, float *mask_i, float *epsilon, int blind, - convolve_data_t *fft_conv_data, double *time) +static void _update_both_MM(rlucy_image_t *u, rlucy_image_t *image, rlucy_image_t *psf, float *lambd, + int iterations, float *mask_u, float *mask_i, float *epsilon, int blind, + convolve_data_t *fft_conv_data, double *time) { -/* - Utility function to launch the actual deconvolution in parallel - :param u: - :param image: - :param psf: - :param lambd: - :param iterations: - :param mask_u: - :param mask_i: - :param epsilon: - :return: -*/ + /* + Utility function to launch the actual deconvolution in parallel + :param u: + :param image: + :param psf: + :param lambd: + :param iterations: + :param mask_u: + :param mask_i: + :param epsilon: + :return: + */ - rlucy_image_t ut = {0}; - rlucy_image_t u_masked = {0}; - rlucy_image_t image_masked = {0}; - rlucy_image_t gradu = {0}; - rlucy_image_t gradk = {0}; - rlucy_image_t img_tmp1 = {0}; - rlucy_image_t img_tmp2 = {0}; - rlucy_image_t img_tmp3 = {0}; - -// float tau = 0.f; - float k_step[4] = {epsilon[0], epsilon[1], epsilon[2], epsilon[3]}; - float u_step[4] = {epsilon[0], epsilon[1], epsilon[2], epsilon[3]}; - float eps[4] = {0}; + rlucy_image_t ut = { 0 }; + rlucy_image_t u_masked = { 0 }; + rlucy_image_t image_masked = { 0 }; + rlucy_image_t gradu = { 0 }; + rlucy_image_t gradk = { 0 }; + rlucy_image_t img_tmp1 = { 0 }; + rlucy_image_t img_tmp2 = { 0 }; + rlucy_image_t img_tmp3 = { 0 }; + + // float tau = 0.f; + float k_step[4] = { epsilon[0], epsilon[1], epsilon[2], epsilon[3] }; + float u_step[4] = { epsilon[0], epsilon[1], epsilon[2], epsilon[3] }; + float eps[4] = { 0 }; // # For Darktable implementation, don't bother to implement the p parameter const int p = 1; rlucy_alloc_image(&ut, u->w, u->h, u->c); - if (ut.im == NULL) goto cleanup; + if(ut.im == NULL) goto cleanup; - for (int it = 0; it < iterations; it++) + for(int it = 0; it < iterations; it++) { -/* ut = u -*/ + /* ut = u + */ rlucy_copy_image(&ut, u); - + /* lambd = min([lambd, 50000]) */ - for (int c = 0; c < image->c; c++) - lambd[c] = MIN(lambd[c], 50000.f); - + for(int c = 0; c < image->c; c++) lambd[c] = MIN(lambd[c], 50000.f); + best_param(u, lambd, p, eps, time); - - for (int itt = 0; itt < 5; itt++) + + for(int itt = 0; itt < 5; itt++) { - // # Image update + // # Image update /* lambd = min([lambd, 50000]) */ - for (int c = 0; c < image->c; c++) - lambd[c] = MIN(lambd[c], 50000.f); - + for(int c = 0; c < image->c; c++) lambd[c] = MIN(lambd[c], 50000.f); + /* gradu = lambd * _convolve_image(u, image, psf) + gradTVEM(u, ut, eps, eps, p=p) */ gradTVEM(u, &ut, eps, eps, p, &gradu, time); _convolve_image(u, image, psf, &img_tmp1, &img_tmp2, &img_tmp3, fft_conv_data, time); - - float lambd_a[4] = {-lambd[0], -lambd[1], -lambd[2], -lambd[3]}; + + float lambd_a[4] = { -lambd[0], -lambd[1], -lambd[2], -lambd[3] }; rlucy_img_mulsub(&gradu, &img_tmp1, lambd_a, time); - + /* dt = u_step * (np.amax(u) + 1 / u.size) / np.amax(np.abs(gradu) + 1e-31) */ - float max_u[4] = {0}; - float max_gradu[4] = {0}; - + float max_u[4] = { 0 }; + float max_gradu[4] = { 0 }; + rlucy_img_max(u, max_u, time); rlucy_img_absmax(&gradu, max_gradu, time); - float dt[4] = {0}; - for (int c = 0; c < image->c; c++) + float dt[4] = { 0 }; + for(int c = 0; c < image->c; c++) { - dt[c] = u_step[c] * (max_u[c] + 1.f / (float)(u->w*u->h)) / MAX(max_gradu[c], 1e-31); + dt[c] = u_step[c] * (max_u[c] + 1.f / (float)(u->w * u->h)) / MAX(max_gradu[c], 1e-31); } - + /* u -= dt * gradu */ rlucy_img_mulsub(u, &gradu, dt, time); - + /* np.clip(u, 0, 1, out=u) */ - - if (blind) + + if(blind) { // # PSF update -/* gradk = _convolve_kernel(u[mask_u[0]:mask_u[1], mask_u[2]:mask_u[3]], - image[mask_i[0]:mask_i[1], mask_i[2]:mask_i[3]], psf) -*/ - if (mask_u) + /* gradk = _convolve_kernel(u[mask_u[0]:mask_u[1], mask_u[2]:mask_u[3]], + image[mask_i[0]:mask_i[1], mask_i[2]:mask_i[3]], psf) + */ + if(mask_u) { rlucy_trim_mask(u, &u_masked, mask_u[0], mask_u[1], mask_u[2], mask_u[3], &img_tmp1, time); } @@ -1433,8 +1353,8 @@ static void _update_both_MM(rlucy_image_t *u, rlucy_image_t *image, rlucy_image_ rlucy_alloc_image(&u_masked, u->w, u->h, u->c); rlucy_copy_image(&u_masked, u); } - - if (mask_i) + + if(mask_i) { rlucy_trim_mask(image, &image_masked, mask_i[0], mask_i[1], mask_i[2], mask_i[3], &img_tmp1, time); } @@ -1443,40 +1363,35 @@ static void _update_both_MM(rlucy_image_t *u, rlucy_image_t *image, rlucy_image_ rlucy_alloc_image(&image_masked, image->w, image->h, image->c); rlucy_copy_image(&image_masked, image); } - + _convolve_kernel(&u_masked, &image_masked, psf, &gradk, &img_tmp2, &img_tmp3, fft_conv_data, time); - + /* alpha = k_step * (np.amax(psf) + 1 / psf.size) / np.amax(np.abs(gradk) + 1e-31) */ - float max_psf[4] = {0}; - float max_gradk[4] = {0}; - + float max_psf[4] = { 0 }; + float max_gradk[4] = { 0 }; + rlucy_img_max(psf, max_psf, time); rlucy_img_absmax(&gradk, max_gradk, time); - float alpha[4] = {0}; - for (int c = 0; c < image->c; c++) + float alpha[4] = { 0 }; + for(int c = 0; c < image->c; c++) { - alpha[c] = k_step[c] * (max_psf[c] + 1.f / (float)(psf->w*psf->h)) / MAX(max_gradk[c], 1e-31); + alpha[c] = k_step[c] * (max_psf[c] + 1.f / (float)(psf->w * psf->h)) / MAX(max_gradk[c], 1e-31); } /* psf -= alpha * gradk */ rlucy_img_mulsub(psf, &gradk, alpha, time); - + /* psf = _normalize_kernel(psf) */ _normalize_kernel(psf, time); } - - for(int c = 0; c < image->c; c++) - lambd[c] *= 1.001; + + for(int c = 0; c < image->c; c++) lambd[c] *= 1.001; } } - + printf("_update_both_MM: iterations=%i\n", iterations * 5); - -/* return u.astype(np.float32), psf -*/ - + cleanup: - rlucy_free_image(&ut); rlucy_free_image(&u_masked); rlucy_free_image(&image_masked); @@ -1485,278 +1400,219 @@ static void _update_both_MM(rlucy_image_t *u, rlucy_image_t *image, rlucy_image_ rlucy_free_image(&img_tmp1); rlucy_free_image(&img_tmp2); rlucy_free_image(&img_tmp3); - } - - -/* -@utils.timeit -def richardson_lucy_MM(image: np.ndarray, - u: np.ndarray, - psf: np.ndarray, - lambd: float, - iterations: int, - epsilon=5e-3, - mask=None, - blind=True) -> np.ndarray: -*/ -static void richardson_lucy_MM(rlucy_image_t *image, - rlucy_image_t *u, - rlucy_image_t *psf, - float *lambd, - int iterations, - float *epsilon /* = 5e-3 */, - int *mask /* = None */, - int blind /* = True */, - convolve_data_t *fft_conv_data, - double *time) + + +static void richardson_lucy_MM(rlucy_image_t *image, rlucy_image_t *u, rlucy_image_t *psf, float *lambd, + int iterations, float *epsilon /* = 5e-3 */, int *mask /* = None */, + int blind /* = True */, convolve_data_t *fft_conv_data, double *time) { -/* - """Richardson-Lucy Blind and non Blind Deconvolution with Total Variation Regularization by the Minimization-Maximization - algorithm. This is known to give the sharp image in more than 50 % of the cases. - - Based on Matlab sourcecode of : - - Copyright (C) Daniele Perrone, perrone@iam.unibe.ch - Remo Diethelm, remo.diethelm@outlook.com - Paolo Favaro, paolo.favaro@iam.unibe.ch - 2014, All rights reserved. - - :param ndarray image : Input 3 channels image. - :param ndarray psf : The point spread function. - :param int iterations : Number of iterations. - :param float lambd : Lambda parameter of the total Variation regularization - :param bool blind : Determine if it is a blind deconvolution is launched, thus if the PSF is updated - between two iterations - :returns ndarray: deconvoluted image - - References - ---------- - .. [1] http://en.wikipedia.org/wiki/Richardson%E2%80%93Lucy_deconvolution - .. [2] http://www.cvg.unibe.ch/dperrone/tvdb/perrone2014tv.pdf - .. [3] http://hal.archives-ouvertes.fr/docs/00/43/75/81/PDF/preprint.pdf - .. [4] http://znah.net/rof-and-tv-l1-denoising-with-primal-dual-algorithm.html - .. [5] http://www.cs.sfu.ca/~pingtan/Papers/pami10_deblur.pdf - """ -*/ - - rlucy_image_t u_padded = {0}; - rlucy_image_t img_tmp1 = {0}; - + /* + """Richardson-Lucy Blind and non Blind Deconvolution with Total Variation Regularization by the + Minimization-Maximization + algorithm. This is known to give the sharp image in more than 50 % of the cases. + + Based on Matlab sourcecode of : + + Copyright (C) Daniele Perrone, perrone@iam.unibe.ch + Remo Diethelm, remo.diethelm@outlook.com + Paolo Favaro, paolo.favaro@iam.unibe.ch + 2014, All rights reserved. + + :param ndarray image : Input 3 channels image. + :param ndarray psf : The point spread function. + :param int iterations : Number of iterations. + :param float lambd : Lambda parameter of the total Variation regularization + :param bool blind : Determine if it is a blind deconvolution is launched, thus if the PSF is updated + between two iterations + :returns ndarray: deconvoluted image + + References + ---------- + .. [1] http://en.wikipedia.org/wiki/Richardson%E2%80%93Lucy_deconvolution + .. [2] http://www.cvg.unibe.ch/dperrone/tvdb/perrone2014tv.pdf + .. [3] http://hal.archives-ouvertes.fr/docs/00/43/75/81/PDF/preprint.pdf + .. [4] http://znah.net/rof-and-tv-l1-denoising-with-primal-dual-algorithm.html + .. [5] http://www.cs.sfu.ca/~pingtan/Papers/pami10_deblur.pdf + """ + */ + + rlucy_image_t u_padded = { 0 }; + rlucy_image_t img_tmp1 = { 0 }; + // # image dimensions -/* MK, NK, C = psf.shape - M, N, C = image.shape - pad = np.floor(MK / 2).astype(int) -*/ + /* MK, NK, C = psf.shape + M, N, C = image.shape + pad = np.floor(MK / 2).astype(int) + */ int MK = psf->w; -// int NK = psf->h; + // int NK = psf->h; int M = image->w; int N = image->h; -// int C = image->c; - + // int C = image->c; + int pad = floor(MK / 2); - + printf("richardson_lucy_MM: working on image :%i, %i, %i\n", u->w, u->h, u->c); -/* u = pad_image(u, (pad, pad)) -*/ + /* u = pad_image(u, (pad, pad)) + */ pad_image(u, pad, pad, &u_padded, &img_tmp1, time); - float mask_i[4] = {0}; - float mask_u[4] = {0}; + float mask_i[4] = { 0 }; + float mask_u[4] = { 0 }; - if (mask == NULL) + if(mask == NULL) { - mask_i[0] = 0; mask_i[2] = M + 2 * pad; mask_i[1] = 0; mask_i[3] = N + 2 * pad; - mask_u[0] = 0; mask_u[2] = M + 2 * pad; mask_u[1] = 0; mask_u[3] = N + 2 * pad; + mask_i[0] = 0; + mask_i[2] = M + 2 * pad; + mask_i[1] = 0; + mask_i[3] = N + 2 * pad; + mask_u[0] = 0; + mask_u[2] = M + 2 * pad; + mask_u[1] = 0; + mask_u[3] = N + 2 * pad; } else { - mask_u[0] = mask[0] - pad; mask_u[2] = mask[2] + 2*pad; mask_u[1] = mask[1] - pad; mask_u[3] = mask[3] + 2*pad; - mask_i[0] = mask[0]; mask_i[2] = mask[2]; mask_i[1] = mask[1]; mask_i[3] = mask[3]; + mask_u[0] = mask[0] - pad; + mask_u[2] = mask[2] + 2 * pad; + mask_u[1] = mask[1] - pad; + mask_u[3] = mask[3] + 2 * pad; + mask_i[0] = mask[0]; + mask_i[2] = mask[2]; + mask_i[1] = mask[1]; + mask_i[3] = mask[3]; } -/* pool = multiprocessing.Pool(processes=CPU) - output = pool.starmap(_update_both_MM, - [(u[..., 0], image[..., 0], psf[..., 0], lambd, iterations, mask_u, mask_i, epsilon, blind), - (u[..., 1], image[..., 1], psf[..., 1], lambd, iterations, mask_u, mask_i, epsilon, blind), - (u[..., 2], image[..., 2], psf[..., 2], lambd, iterations, mask_u, mask_i, epsilon, blind), - ] - ) - - u = np.dstack((output[0][0], output[1][0], output[2][0])) - psf = np.dstack((output[0][1], output[1][1], output[2][1])) - pool.close() - -*/ - if (mask == NULL) + if(mask == NULL) _update_both_MM(&u_padded, image, psf, lambd, iterations, NULL, NULL, epsilon, blind, fft_conv_data, time); else _update_both_MM(&u_padded, image, psf, lambd, iterations, mask_u, mask_i, epsilon, blind, fft_conv_data, time); -/* u = unpad_image(u, (pad, pad)) -*/ unpad_image(u, pad, pad, &u_padded, &img_tmp1, time); - // return u.astype(np.float32), psf - rlucy_free_image(&u_padded); rlucy_free_image(&img_tmp1); - } - -/* -@jit(cache=True) -def build_pyramid(psf_size: int, lambd: float, method) -> list: -*/ -static void build_pyramid(const int psf_size, const float lambd, int method, - int **kernels_size, float **images_scaling, float **lambdas, int *pyramid_len) -{ -/* - To speed-up the deconvolution, the PSF is estimated successively on smaller images of increasing sizes. This function - computes the intermediates sizes and regularization factors - - :param image_size: - :param psf_size: - :param lambd: - :param method: - :return: -*/ -/* - lambdas = [lambd] - images = [1] - kernels = [psf_size] - - if method == richardson_lucy_PAM: - image_multiplier = 1.1 - lambda_multiplier = 1.9 - lambda_max = 0.5 - - elif method == richardson_lucy_MM: - image_multiplier = np.sqrt(2) - lambda_multiplier = 1 / 2.1 - lambda_max = 999999 - - while kernels[-1] > 3: - lambdas.append(min([lambdas[-1] * lambda_multiplier, lambda_max])) - kernels.append(int(np.floor(kernels[-1] / image_multiplier))) - images.append(images[-1] / image_multiplier) - if kernels[-1] % 2 == 0: - kernels[-1] -= 1 - if kernels[-1] < 3: - kernels[-1] = 3 - - print(kernels) - - return images, kernels, lambdas -*/ +static void build_pyramid(const int psf_size, const float lambd, int method, int **kernels_size, + float **images_scaling, float **lambdas, int *pyramid_len) +{ + /* + To speed-up the deconvolution, the PSF is estimated successively on smaller images of increasing sizes. This + function + computes the intermediates sizes and regularization factors + + :param image_size: + :param psf_size: + :param lambd: + :param method: + :return: + */ int len = 1; -// float lambda_tmp = lambd; + // float lambda_tmp = lambd; int kernel_tmp = psf_size; - + int *arr_kernels = NULL; float *arr_images_scaling = NULL; float *arr_lambdas = NULL; - + float image_multiplier = .0f; float lambda_multiplier = .0f; float lambda_max = .0f; - if (method == rlucy_method_fast) + if(method == rlucy_method_fast) { image_multiplier = 1.1f; lambda_multiplier = 1.9f; lambda_max = 0.5f; } - else if (method == rlucy_method_best) + else if(method == rlucy_method_best) { image_multiplier = sqrtf(2.f); lambda_multiplier = 1.f / 2.1f; lambda_max = 999999.f; } - - while ((int)(kernel_tmp / image_multiplier) >= 3) + + while((int)(kernel_tmp / image_multiplier) >= 3) { kernel_tmp = (int)floor(kernel_tmp / image_multiplier); - + len++; } - + arr_kernels = calloc(len, sizeof(int)); arr_images_scaling = calloc(len, sizeof(float)); arr_lambdas = calloc(len, sizeof(float)); - if (arr_kernels == NULL || arr_images_scaling == NULL || arr_lambdas == NULL) - goto cleanup; - + if(arr_kernels == NULL || arr_images_scaling == NULL || arr_lambdas == NULL) goto cleanup; + arr_kernels[0] = psf_size; arr_images_scaling[0] = 1.f; arr_lambdas[0] = lambd; - - for (int i = 1; i < len; i++) + + for(int i = 1; i < len; i++) { - arr_lambdas[i] = MIN(arr_lambdas[i-1] * lambda_multiplier, lambda_max); - arr_kernels[i] = (int)(floor(arr_kernels[i-1] / image_multiplier)); - arr_images_scaling[i] = arr_images_scaling[i-1] / image_multiplier; - - if (arr_kernels[i] % 2 == 0) + arr_lambdas[i] = MIN(arr_lambdas[i - 1] * lambda_multiplier, lambda_max); + arr_kernels[i] = (int)(floor(arr_kernels[i - 1] / image_multiplier)); + arr_images_scaling[i] = arr_images_scaling[i - 1] / image_multiplier; + + if(arr_kernels[i] % 2 == 0) { arr_kernels[i] -= 1; } - if (arr_kernels[i] < 3) + if(arr_kernels[i] < 3) { arr_kernels[i] = 3; } } - - if (!(arr_lambdas[len-1] < lambda_max && arr_kernels[len-1] >= 3) && len > 1) + + if(!(arr_lambdas[len - 1] < lambda_max && arr_kernels[len - 1] >= 3) && len > 1) printf("rlucy_build_pyramid: error in construction, len=%i\n", len); - + *kernels_size = arr_kernels; *images_scaling = arr_images_scaling; *lambdas = arr_lambdas; *pyramid_len = len; - + return; - + cleanup: - if (arr_kernels) free(arr_kernels); - if (arr_images_scaling) free(arr_images_scaling); - if (arr_lambdas) free(arr_lambdas); - + if(arr_kernels) free(arr_kernels); + if(arr_images_scaling) free(arr_images_scaling); + if(arr_lambdas) free(arr_lambdas); + *pyramid_len = 0; - + return; } - -/* -def process_pyramid(pic, u, psf, lambd, method, epsilon=1e-3, quality=1): -*/ -static void process_pyramid(rlucy_image_t *pic, rlucy_image_t *u, rlucy_image_t *psf, float lambd, int method, float epsilon /* = 1e-3 */, int quality /* = 1 */, - convolve_data_t *fft_conv_data, double *time) +static void process_pyramid(rlucy_image_t *pic, rlucy_image_t *u, rlucy_image_t *psf, float lambd, int method, + float epsilon /* = 1e-3 */, int quality /* = 1 */, convolve_data_t *fft_conv_data, + double *time) { -/* - To speed-up the deconvolution, the PSF is estimated successively on smaller images of increasing sizes. This function - computes the intermediates deblured pictures and PSF. - - :param pic: - :param u: - :param psf: - :param lambd: - :param method: - :param epsilon: - :param quality: the number of iterations performed at each pyramid step will be adjusted by this factor. - :return: -*/ - - rlucy_image_t im = {0}; - rlucy_image_t img_tmp1 = {0}; - rlucy_image_t img_tmp2 = {0}; - + /* + To speed-up the deconvolution, the PSF is estimated successively on smaller images of increasing sizes. This + function + computes the intermediates deblured pictures and PSF. + + :param pic: + :param u: + :param psf: + :param lambd: + :param method: + :param epsilon: + :param quality: the number of iterations performed at each pyramid step will be adjusted by this factor. + :return: + */ + + rlucy_image_t im = { 0 }; + rlucy_image_t img_tmp1 = { 0 }; + rlucy_image_t img_tmp2 = { 0 }; + int pyramid_len = 0; int *arr_kernels = NULL; float *arr_images_scaling = NULL; @@ -1764,39 +1620,36 @@ static void process_pyramid(rlucy_image_t *pic, rlucy_image_t *u, rlucy_image_t /* Mk, Nk, C = psf.shape */ int Mk = psf->w; -// int Nk = psf->h; -// int C = psf->c; - + // int Nk = psf->h; + // int C = psf->c; + /* images, kernels, lambdas = build_pyramid(Mk, lambd, method) */ build_pyramid(Mk, lambd, method, &arr_kernels, &arr_images_scaling, &arr_lambdas, &pyramid_len); - -/* rlucy_alloc_image(&u_zoom, u->w, u->h, u->c); - if (u_zoom.im == NULL) goto cleanup; - rlucy_copy_image(&u_zoom, u); -*/ + rlucy_alloc_image(&im, pic->w, pic->h, pic->c); - if (im.im == NULL) goto cleanup; /* u = ndimage.zoom(u, (images[-1], images[-1], 1)) */ -// rlucy_resize(u, u, arr_images_scaling[pyramid_len-1], u->w * arr_images_scaling[pyramid_len-1], u->h * arr_images_scaling[pyramid_len-1], &img_tmp1, &img_tmp2); - + // rlucy_resize(u, u, arr_images_scaling[pyramid_len-1], u->w * arr_images_scaling[pyramid_len-1], u->h * + // arr_images_scaling[pyramid_len-1], &img_tmp1, &img_tmp2); + printf("\n== Processing Pyramid steps=%i ==\n", pyramid_len); int k_prec = Mk; - int iterations = quality * 10; + int iterations = quality; float scale = 1.f; /* for i, k, l in zip(reversed(images), reversed(kernels), reversed(lambdas)): */ - for (int i = pyramid_len-1; i >= 0; i--) + for(int i = pyramid_len - 1; i >= 0; i--) { printf("== Pyramid step=%i ==\n", i); // # Resize blured, deblured images and PSF from previous step - if (arr_images_scaling[i] != 1.f) + if(arr_images_scaling[i] != 1.f) { - // # TODO : pad the picture to make its dimensions odd + // # TODO : pad the picture to make its dimensions odd /* im = ndimage.zoom(pic, (i, i, 1)) */ - rlucy_resize(pic, &im, arr_images_scaling[i], pic->w * arr_images_scaling[i], pic->h * arr_images_scaling[i], &img_tmp1, &img_tmp2); + rlucy_resize(pic, &im, arr_images_scaling[i], pic->w * arr_images_scaling[i], pic->h * arr_images_scaling[i], + &img_tmp1, &img_tmp2); } else { @@ -1808,35 +1661,33 @@ static void process_pyramid(rlucy_image_t *pic, rlucy_image_t *u, rlucy_image_t /* psf = ndimage.zoom(psf, (k / k_prec, k / k_prec, 1)) */ scale = (float)arr_kernels[i] / (float)k_prec; rlucy_resize(psf, psf, scale, psf->w * scale, psf->h * scale, &img_tmp1, &img_tmp2); - + /* psf = _normalize_kernel(psf) */ _normalize_kernel(psf, time); - + /* u = ndimage.zoom(u, (im.shape[0] / u.shape[0], im.shape[1] / u.shape[1], 1)) */ scale = (float)(im.w) / (float)(u->w); rlucy_resize(u, u, scale, im.w, im.h, &img_tmp1, &img_tmp2); - // # Make a blind Richardson-Lucy deconvolution on the RGB signal + // # Make a blind Richardson-Lucy deconvolution on the RGB signal /* u, psf = method(im, u, psf, l, iterations, epsilon=epsilon) */ - float noise_damping_a[4] = {arr_lambdas[i], arr_lambdas[i], arr_lambdas[i], arr_lambdas[i]}; - float epsilon_a[4] = {epsilon, epsilon, epsilon, epsilon}; - - if (method == rlucy_method_fast) + float noise_damping_a[4] = { arr_lambdas[i], arr_lambdas[i], arr_lambdas[i], arr_lambdas[i] }; + float epsilon_a[4] = { epsilon, epsilon, epsilon, epsilon }; + + if(method == rlucy_method_fast) richardson_lucy_PAM(&im, u, psf, noise_damping_a, iterations, epsilon_a, NULL, 1, fft_conv_data, time); - else if (method == rlucy_method_best) + else if(method == rlucy_method_best) richardson_lucy_MM(&im, u, psf, noise_damping_a, iterations, epsilon_a, NULL, 1, fft_conv_data, time); // # TODO : unpad the picture - + /* k_prec = k */ k_prec = arr_kernels[i]; } /* return u, psf */ printf("== Pyramid end ==\n"); - - cleanup: - + rlucy_free_image(&im); rlucy_free_image(&img_tmp1); rlucy_free_image(&img_tmp2); @@ -1845,196 +1696,116 @@ static void process_pyramid(rlucy_image_t *pic, rlucy_image_t *u, rlucy_image_t static void rlucy_img_outer(float *vector, const int size, float *outer, const int ch) { const int size_c = size * ch; - - for (int i = 0; i < size; i++) + + for(int i = 0; i < size; i++) { const int idx_outer = i * size_c; - - for (int j = 0; j < size; j++) + + for(int j = 0; j < size; j++) { const float mult = vector[i] * vector[j]; - - for (int c = 0; c < ch; c++) + + for(int c = 0; c < ch; c++) { outer[idx_outer + j * ch + c] = mult; } } } +} + +/*static float gaussian_function(int x, int mu, float sigma) { + return expf(- (powf(x - mu, 2)) / (2.f * powf(sigma, 2) )) / (sigma * sqrtf(2.f * M_PI)); } + +static float gaussian_vector(int size, float sigma) { + + int mu = ceilf(size / 2) + 1; + float vect[size] = {0}; + + for (int i = 0; i < size; i++) { + vect[i] = gaussian_function(i, mu, sigma); + } + + return vect; +} + +*/ + // from: // https://github.com/scipy/scipy/blob/v0.19.1/scipy/signal/windows.py#L1159-L1219 // static void rlucy_buildGaussianWindow(float *win, const int win_size, const float shape) -{ - if (win_size == 1) +{ + if(win_size == 1) { win[0] = 1.f; } else { - for (int i = 0; i < win_size; i++) + for(int i = 0; i < win_size; i++) { win[i] = i - (win_size - 1.f) / 2.f; } - + float sig2 = 2.f * shape * shape; - - for (int i = 0; i < win_size; i++) + + for(int i = 0; i < win_size; i++) { - win[i] = expf( -(win[i] * win[i]) / sig2 ); + win[i] = expf(-(win[i] * win[i]) / sig2); } } - } static void rlucy_gaussian_kernel(rlucy_image_t *kern, const float beta, double *time) { float *win = NULL; const int radius = kern->w; - - if (kern->w != kern->h) - printf("rlucy_gaussian_kernel: invalid kernel size\n"); - -// window = np.kaiser(radius, beta) - win = calloc(radius, sizeof(float)); - if (win) - { - rlucy_buildGaussianWindow(win, radius, beta); - -// kern = np.outer(window, window) - rlucy_img_outer(win, radius, kern->im, kern->c); - - float kern_sum[4] = {0}; - -// kern = kern / kern.sum() - rlucy_img_sum(kern, kern_sum, time); - rlucy_img_divide(kern, kern_sum, time); - } - - if (win) free(win); -} - -// from: -// https://github.com/johnglover/simpl/blob/master/src/loris/KaiserWindow.C -// - -// Compute the zeroeth order modified Bessel function of the first kind -// at x using the series expansion, used to compute the Kasier window -// function. -// -static float rlucy_zeroethOrderBessel(const float x) -{ - const float eps = 0.000001; - // initialize the series term for m=0 and the result - float besselValue = 0; - float term = 1; - float m = 0; + if(kern->w != kern->h) printf("rlucy_gaussian_kernel: invalid kernel size\n"); - // accumulate terms as long as they are significant - while(term > eps * besselValue) + // window = np.kaiser(radius, beta) + win = calloc(radius, sizeof(float)); + if(win) { - besselValue += term; - - // update the term - ++m; - term *= (x*x) / (4*m*m); - } - - return besselValue; -} - -//! Build a new Kaiser analysis window having the specified shaping -//! parameter. See Oppenheim and Schafer: "Digital Signal Processing" -//! (1975), p. 452 for further explanation of the Kaiser window. Also, -//! see Kaiser and Schafer, 1980. -//! -//! \param win is the vector that will store the window -//! samples. The number of samples computed will be -//! equal to the length of this vector. Any previous -//! contents will be overwritten. -//! \param shape is the Kaiser shaping parameter, controlling -//! the sidelobe rejection level. -// -static void rlucy_buildKaiserWindow(float *win, const int win_size, const float shape) -{ - // Pre-compute the shared denominator in the Kaiser equation. - const float oneOverDenom = 1.0f / rlucy_zeroethOrderBessel( shape ); - - const int N = win_size - 1; - const float oneOverN = 1.0 / N; + rlucy_buildGaussianWindow(win, radius, beta); - for ( int n = 0; n <= N; ++n ) - { - const float K = (2.0 * n * oneOverN) - 1.0; - const float arg = sqrtf( 1.0 - (K * K) ); + // kern = np.outer(window, window) + rlucy_img_outer(win, radius, kern->im, kern->c); - win[n] = rlucy_zeroethOrderBessel( shape * arg ) * oneOverDenom; - } -} + float kern_sum[4] = { 0 }; -static void rlucy_kaiser_kernel(rlucy_image_t *kern, const float beta, double *time) -{ - float *win = NULL; - const int radius = kern->w; - - if (kern->w != kern->h) - printf("rlucy_kaiser_kernel: invalid kernel size\n"); - -// window = np.kaiser(radius, beta) - win = calloc(radius, sizeof(float)); - if (win) - { - rlucy_buildKaiserWindow(win, radius, beta); - -// kern = np.outer(window, window) - rlucy_img_outer(win, radius, kern->im, kern->c); - - float kern_sum[4] = {0}; - -// kern = kern / kern.sum() + // kern = kern / kern.sum() rlucy_img_sum(kern, kern_sum, time); rlucy_img_divide(kern, kern_sum, time); } - - if (win) free(win); + + if(win) free(win); } -/*def uniform_kernel(size): - kern = np.ones((size, size)) - kern /= np.sum(kern) - return kern*/ static void rlucy_uniform_kernel(rlucy_image_t *kern) { const int radius = kern->w; const float radius2 = 1.f / (radius * radius); const int size = kern->w * kern->h * kern->c; - if (kern->w != kern->h) - printf("rlucy_uniform_kernel: invalid kernel size\n"); - - for (int i = 0; i < size; i++) + for(int i = 0; i < size; i++) { kern->im[i] = radius2; } } -static void build_kernel(rlucy_image_t *psf, int blur_type, int blur_width, int blur_strength, int ch, double *time) +static void build_kernel(rlucy_image_t *psf, int blur_type, int blur_width, int ch, double *time) { rlucy_alloc_image(psf, blur_width, blur_width, ch); - - if (blur_type == rlucy_blur_type_gaussian) - { - rlucy_gaussian_kernel(psf, blur_strength, time); - } - else if (blur_type == rlucy_blur_type_kaiser) + + if(blur_type == rlucy_blur_type_gaussian) { - rlucy_kaiser_kernel(psf, blur_strength, time); + rlucy_gaussian_kernel(psf, blur_width, time); } - else if (blur_type == rlucy_blur_type_auto) + else if(blur_type == rlucy_blur_type_auto) { rlucy_uniform_kernel(psf); } @@ -2042,331 +1813,129 @@ static void build_kernel(rlucy_image_t *psf, int blur_type, int blur_width, int { printf("richardson_lucy: invalid blur type\n"); } - } -/* -@utils.timeit -@jit(float32[:](float32[:], - int8, - int8, - int8, - int16, - float32, - float32, - int16, - float32, - float32, - boolean, - int16, - int16[:], - float32, - boolean, - float32, - float32, - float32[:], - boolean, - int8), - parallel=True) -def deblur_module(pic: np.ndarray, - filename: str, - dest_path: str, - blur_type: str, - blur_width: int, - noise_reduction_factor: float, - deblur_strength: int, - blur_strength: int = 1, - auto_quality=1, - epsilon=1e-3, - refine: bool = False, - refine_quality=0, - mask: np.ndarray = None, - backvsmask_ratio: float = 0, - debug: bool = False, - effect_strength=1, - preview=1, - psf: np.ndarray = None, - denoise: bool = False, - method="fast"): -*/ -/* - This mimics a Darktable module inputs where the technical specs are hidden and translated into human-readable parameters. - - It's an interface between the regular user and the geeky actual deconvolution parameters - - :param pic: Blured image in RGB 8 bits as a 3D array where the last dimension is the RGB channel - :param filename: File name to use to save the deblured picture - :param destpath: The destination path to save the picture - :param blur_type: kind of blur or "auto" to perform a blind deconvolution. Use "auto" for motion blur or composite blur. - Other parameters : `poisson`, `gaussian`, `kaiser` - :param blur_width: the width of the blur in px - must be an odd integer - :param blur_strength: the strength of the blur, thus the standard deviation of the blur kernel - :param auto_quality: when the `blur_type` is `auto`, the number of iterations of the initial blur estimation is half the - square of the PSF size. The `auto_quality` parameter is a factor that allows you to reduce the number of iteration to speed up the process. - Default : 1. Recommended values : between 0.25 and 2. - :param noise_reduction_factor: the noise reduction factor lambda. For the `best` method, default is 1000, use 12000 to 30000 to speed up the convergence. Lower values don't help to reduce the noise, decrease the `ringing_facter` instead. - for the `fast` method, default is 0.0006, increase up to 0.05 to reduce the noise. This unconsistency must be corrected soon. - :param ringing_factor: the iterations factor. Typically 1e-3, reduce it to 5e-4 or ever 1e-4 if you see ringing or periodic edges appear. - :param refine: True or False, decide if the blur kernel should be refined through myopic deconvolution - :param refine_quality: the number of iterations to perform during the refinement step - :param mask: the coordinates of the rectangular mask to apply on the image to refine the blur kernel from the top-left corner of the image - in list [y_top, y_bottom, x_left, x_right] - :param preview: If you want to fast preview your setting on a smaller picture size, set the downsampling ratio in `previem`. Default : 1 - :param psf: if you already know the PSF kernel, enter it here as an 3D array where the last dimension is the RGB component - :param denoise: True or False. Perform an initial denoising by Total Variation - Chambolle algorithm before deconvoluting - :param method: `fast` or `best`. Set the method to deconvolute. - :return: - """ - # TODO : refocus http://web.media.mit.edu/~bandy/refocus/PG07refocus.pdf - # TODO : extract foreground only https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_grabcut/py_grabcut.html#grabcut -*/ -void rlucy_deblur_module(float *pic_in, - int blur_type, - int blur_width, - float noise_reduction_factor, - int deblur_strength, - int blur_strength, - float auto_quality, - float ringing_factor, - int refine, - int refine_quality, - int *mask, - float effect_strength, - float *psf_in, - int denoise, - int method, - float *pic_out, - int width, - int height, - int ch) +void rlucy_deblur_module(float *pic_in, int blur_type, int blur_width, float noise_reduction_factor, float quality, + float ringing_factor, int *mask, int method, float *pic_out, int width, int height, + int ch) { - double time[MAX_TIME] = {0}; - + double time[MAX_TIME] = { 0 }; + RLUCY_TIME_DECL RLUCY_TIME_BEGIN - - // # Verify the input and scream like a virgin - if (blur_width < 3) - { - printf("The PSF kernel is too small !\n"); - return; - } - if (blur_width % 2 == 0) - { - printf("The dimensions of the PSF must be odd !\n"); - return; - } - - convolve_data_t fft_conv_data = {0}; - - rlucy_image_t pic = {0}; - rlucy_image_t u = {0}; - rlucy_image_t psf = {0}; - rlucy_image_t img_tmp = {0}; - float noise_reduction_factor_a[4] = {noise_reduction_factor, noise_reduction_factor, noise_reduction_factor, noise_reduction_factor}; - float ringing_factor_a[4] = {ringing_factor, ringing_factor, ringing_factor, ringing_factor}; - + // initialize intermediate data + convolve_data_t fft_conv_data = { 0 }; + rlucy_image_t pic = { 0 }; + rlucy_image_t u = { 0 }; + rlucy_image_t psf = { 0 }; + rlucy_image_t img_tmp = { 0 }; + + float noise_reduction_factor_a[4] + = { noise_reduction_factor, noise_reduction_factor, noise_reduction_factor, noise_reduction_factor }; + float ringing_factor_a[4] = { ringing_factor, ringing_factor, ringing_factor, ringing_factor }; + rlucy_alloc_image(&pic, width, height, ch); - if (pic.im == NULL) goto cleanup; + if(pic.im == NULL) goto cleanup; memcpy(pic.im, pic_in, pic.w * pic.h * pic.c * sizeof(float)); -/* # Backup ICC color profile - icc_profile = pic.info.get("icc_profile") - # Assuming 8 bits input, we rescale the RGB values betweem 0 and 1 - pic = np.ascontiguousarray(pic, np.float32) / 255 -*/ - // # Make the picture dimensions odd to avoid ringing on the border of even pictures. We just replicate the last row/column + // Make the picture dimensions odd to avoid ringing on the border of even pictures. We just replicate the last + // row/column int odd_vert = 0; int odd_hor = 0; - if (pic.w % 2 == 0) + if(pic.w % 2 == 0) { - /* pic = pad_image(pic, ((1, 0), (0, 0))) */ pad_image(&pic, 1, 0, &pic, &img_tmp, time); odd_hor = 1; } - if (pic.h % 2 == 0) + if(pic.h % 2 == 0) { - /* pic = pad_image(pic, ((0, 0), (0, 1))) */ pad_image(&pic, 0, 1, &pic, &img_tmp, time); odd_vert = 1; } -/* # Choose the RL method - methods_collection = { - "fast": richardson_lucy_PAM, - "best": richardson_lucy_MM - } -*/ -// int richardson_lucy = method; - -/* # Construct a PSF - if psf == None: - blur_collection = { - "gaussian": utils.gaussian_kernel(blur_width, blur_strength), - "kaiser": utils.kaiser_kernel(blur_width, blur_strength), - "auto": utils.uniform_kernel(blur_width), - "poisson": utils.poisson_kernel(blur_width, blur_strength), - } + build_kernel(&psf, blur_type, blur_width, ch, time); + rlucy_alloc_image(&u, pic.w, pic.h, pic.c); + rlucy_copy_image(&u, &pic); - # TODO http://yehar.com/blog/?p=1495 - - psf = blur_collection[blur_type] - - psf = np.dstack((psf, psf, psf)) -*/ - if (psf_in == NULL) + if(blur_type == rlucy_blur_type_auto) { - build_kernel(&psf, blur_type, blur_width, blur_strength, ch, time); - } - else - { - rlucy_alloc_image(&psf, blur_width, blur_width, ch); - if (psf.im == NULL) goto cleanup; - memcpy(psf.im, psf_in, psf.w * psf.h * psf.c * sizeof(float)); + printf("\n===== BLIND ESTIMATION OF BLUR =====\n"); + + process_pyramid(&pic, &u, &psf, noise_reduction_factor, method, ringing_factor, quality, &fft_conv_data, time); } - -/* if preview != 1: - print("\nWorking on a scaled picture") - pic, psf, mask = make_preview(pic, psf, preview, mask) -*/ - -/* if denoise: - # TODO : http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=6572468 - u = denoise_tv_chambolle(pic, weight=noise_reduction_factor, multichannel=True) - else: - u = pic.copy() -*/ - if (denoise) + + if(mask) { - // TODO: - printf("denoise not implemented\n"); - goto cleanup; -// u = denoise_tv_chambolle(pic, weight=noise_reduction_factor, multichannel=True); + printf("\n===== BLIND MASKED REFINEMENT =====\n"); + + if(method == rlucy_method_fast) + richardson_lucy_PAM(&pic, &u, &psf, noise_reduction_factor_a, quality, ringing_factor_a, mask, 1, + &fft_conv_data, time); + else if(method == rlucy_method_best) + richardson_lucy_MM(&pic, &u, &psf, noise_reduction_factor_a, quality, ringing_factor_a, mask, 1, + &fft_conv_data, time); } else { - rlucy_alloc_image(&u, pic.w, pic.h, pic.c); - if (u.im == NULL) goto cleanup; - rlucy_copy_image(&u, &pic); + printf("\n===== BLIND UNMASKED REFINEMENT =====\n"); + + if(method == rlucy_method_fast) + richardson_lucy_PAM(&pic, &u, &psf, noise_reduction_factor_a, quality, ringing_factor_a, NULL, 1, + &fft_conv_data, time); + else if(method == rlucy_method_best) + richardson_lucy_MM(&pic, &u, &psf, noise_reduction_factor_a, quality, ringing_factor_a, NULL, 1, + &fft_conv_data, time); } - - if (blur_type == rlucy_blur_type_auto) - { - printf("\n===== BLIND ESTIMATION OF BLUR =====\n"); -/* u, psf = process_pyramid(pic, u, psf, noise_reduction_factor, richardson_lucy, ringing_factor, quality=auto_quality) - */ - - // FIXME: do we need to return u here? - process_pyramid(&pic, &u, &psf, noise_reduction_factor, method, ringing_factor, auto_quality, &fft_conv_data, time); - -// rlucy_alloc_image(&u, pic.w, pic.h, pic.c); -// rlucy_copy_image(&u, &pic); - } - - if (refine) - { - if (mask) - { - printf("\n===== BLIND MASKED REFINEMENT =====\n"); -/* u, psf = richardson_lucy(pic, u, psf, noise_reduction_factor, 10 * refine_quality, ringing_factor, mask=mask) -*/ - if (method == rlucy_method_fast) - richardson_lucy_PAM(&pic, &u, &psf, noise_reduction_factor_a, 10 * refine_quality, ringing_factor_a, mask, 1, &fft_conv_data, time); - else if (method == rlucy_method_best) - richardson_lucy_MM(&pic, &u, &psf, noise_reduction_factor_a, 10 * refine_quality, ringing_factor_a, mask, 1, &fft_conv_data, time); + /* + printf("\n===== REGULAR DECONVOLUTION =====\n"); - } - else - { - printf("\n===== BLIND UNMASKED REFINEMENT =====\n"); - -/* u, psf = richardson_lucy(pic, u, psf, noise_reduction_factor, 10 * refine_quality, ringing_factor) -*/ - if (method == rlucy_method_fast) - richardson_lucy_PAM(&pic, &u, &psf, noise_reduction_factor_a, 10 * refine_quality, ringing_factor_a, NULL, 1, &fft_conv_data, time); - else if (method == rlucy_method_best) - richardson_lucy_MM(&pic, &u, &psf, noise_reduction_factor_a, 10 * refine_quality, ringing_factor_a, NULL, 1, &fft_conv_data, time); - } - } - - if (deblur_strength > 0) - { - printf("\n===== REGULAR DECONVOLUTION =====\n"); - -/* u, psf = richardson_lucy(pic, u, psf, noise_reduction_factor, deblur_strength * 10, ringing_factor, blind=False) -*/ - if (method == rlucy_method_fast) - richardson_lucy_PAM(&pic, &u, &psf, noise_reduction_factor_a, 10 * deblur_strength, ringing_factor_a, NULL, 0, &fft_conv_data, time); - else if (method == rlucy_method_best) - richardson_lucy_MM(&pic, &u, &psf, noise_reduction_factor_a, 10 * deblur_strength, ringing_factor_a, NULL, 0, &fft_conv_data, time); - } + if (method == rlucy_method_fast) + richardson_lucy_PAM(&pic, &u, &psf, noise_reduction_factor_a, quality, ringing_factor_a, NULL, 0, + &fft_conv_data, time); + else if (method == rlucy_method_best) + richardson_lucy_MM(&pic, &u, &psf, noise_reduction_factor_a, quality, ringing_factor_a, NULL, 0, + &fft_conv_data, time); - // # Convert back into 8 bits RGB - /* u = (pic - effect_strength * (pic - u)) * 255 */ - + */ // # if the picture has been padded to make it odd, unpad it to get the original size - if (odd_hor) + if(odd_hor) { /* u = u[:, :-1, ...] */ unpad_image(&u, 1, 0, &u, &img_tmp, time); } - if (odd_vert) + if(odd_vert) { /* u = u[:-1, :, ...] */ unpad_image(&u, 0, 1, &u, &img_tmp, time); } -/* if debug and mask: - # Print the mask in debug mode - utils.save(u, filename, dest_path, mask=mask, icc_profile=icc_profile) - else: - utils.save(u, filename, dest_path, icc_profile=icc_profile) - - return u, psf -*/ - - if (u.w != width || u.h != height || u.c != ch) + if(u.w != width || u.h != height || u.c != ch) { printf("rlucy_deblur_module: result with diffrent size than output image\n"); printf("rlucy_deblur_module: u.w=%i, u.h=%i, u.c=%i\n", u.w, u.h, u.c); printf("rlucy_deblur_module: width=%i, height=%i, ch=%i\n", width, height, ch); - + rlucy_trim_mask(&u, &u, 0, 0, width, height, &img_tmp, time); } memcpy(pic_out, u.im, u.w * u.h * u.c * sizeof(float)); - if (psf_in) - { - if (psf.w == blur_width && psf.h == blur_width && psf.c == ch) - { - memcpy(psf_in, psf.im, psf.w * psf.h * psf.c * sizeof(float)); - } - else - { - printf("rlucy_deblur_module: psf result with diffrent size than output psf\n"); - printf("rlucy_deblur_module: psf.w=%i, psf.h=%i, psf.c=%i\n", psf.w, psf.h, psf.c); - printf("rlucy_deblur_module: blur_width=%i, ch=%i\n", blur_width, ch); - } - } - RLUCY_TIME_END(TIME_PROCESS) - + #ifdef RLUCY_TIME printf("\n"); - for (int i = 1; i < MAX_TIME; i++) - if (time[i] > 0.0) printf("rlucy %i:%s took %0.06f sec\n", i, rlucy_time_desc[i], time[i]); + for(int i = 1; i < MAX_TIME; i++) + if(time[i] > 0.0) printf("rlucy %i:%s took %0.06f sec\n", i, rlucy_time_desc[i], time[i]); printf("\n"); #endif - cleanup: +cleanup: convolve_free(&fft_conv_data, time); - rlucy_free_image(&u); rlucy_free_image(&psf); rlucy_free_image(&pic); @@ -2374,75 +1943,3 @@ void rlucy_deblur_module(float *pic_in, printf("rlucy_deblur_module end\n"); } - -/* -if __name__ == '__main__': - source_path = "img" - dest_path = "img/richardson-lucy-deconvolution" - - picture = "blured.jpg" - with Image.open(join(source_path, picture)) as pic: - # deblur_module(pic, "fast-v4", "kaiser", 0, 0.05, 50, blur_width=11, blur_strength=8) - - # deblur_module(pic, "myope-v4", "kaiser", 10, 0.05, 50, blur_width=11, blur_strength=8, mask=[150, 150 + 256, 600, 600 + 256], refine=True,) - """ - deblur_module(pic, picture + "-blind-v10-best", dest_path, "auto", 5, 0.0005, 0, - mask=[150, 150 + 512, 600, 600 + 512], - refine=True, - refine_quality=50, - auto_quality=2, - backvsmask_ratio=0, - method="best", - ringing_factor=5e-1, - debug=True) - """ - - """ - deblur_module(pic, picture + "-blind-v10-fast", dest_path, "auto", 5, 0.05, 0, - mask=[150, 150 + 512, 600, 600 + 512], - refine=True, - refine_quality=50, - auto_quality=2, - backvsmask_ratio=0, - method="fast", - debug=True) - - """ - pass - - picture = "Shoot-Sienna-Hayes-0042-_DSC0284-sans-PHOTOSHOP-WEB.jpg" - with Image.open(join(source_path, picture)) as pic: - """ - deblur_module(pic, picture + "test-v7", dest_path, "auto", 9, 0.00005, 0, - mask=[318, 357 + 800, 357, 357 + 440], - denoise=False, - refine=False, - refine_quality=50, - auto_quality=1, - backvsmask_ratio=0, - preview=1, - debug=True, - method="best", - ) - - """ - pass - - picture = "DSC1168.jpg" - with Image.open(join(source_path, picture)) as pic: - mask = [631 + 512, 631 + 512 + 1024, 2826 + 512, 2826 + 512 + 1024] - - deblur_module(pic, picture + "test-v7-gradient-alternatif-3-2", dest_path, "auto", 13, 0.05, 0, - mask=mask, - denoise=False, - refine=True, - refine_quality=500, - auto_quality=1, - backvsmask_ratio=0, - preview=0.5, - debug=True, - method="best", - ) - pass -*/ - diff --git a/src/common/rlucy_deblur.h b/src/common/rlucy_deblur.h index d7cc55475a03..fa5f53db8aa8 100644 --- a/src/common/rlucy_deblur.h +++ b/src/common/rlucy_deblur.h @@ -6,7 +6,6 @@ typedef enum { rlucy_blur_type_auto = 0, rlucy_blur_type_gaussian = 1, - rlucy_blur_type_kaiser = 2 } rlucy_blur_types; typedef enum @@ -15,25 +14,9 @@ typedef enum rlucy_method_best = 1 } rlucy_methods; -void rlucy_deblur_module(float *pic_in, - int blur_type, - int blur_width, - float noise_reduction_factor, - int deblur_strength, - int blur_strength, - float auto_quality, - float ringing_factor, - int refine, - int refine_quality, - int *mask, - float effect_strength, - float *psf_in, - int denoise, - int method, - float *pic_out, - int width, - int height, - int ch); +void rlucy_deblur_module(float *pic_in, int blur_type, int blur_width, float noise_reduction_factor, float quality, + float ringing_factor, int *mask, int method, float *pic_out, int width, int height, + int ch); -#endif +#endif diff --git a/src/common/selection.c b/src/common/selection.c index 620ddec2c7b9..3c1b771d50a6 100644 --- a/src/common/selection.c +++ b/src/common/selection.c @@ -186,8 +186,8 @@ void dt_selection_select_range(dt_selection_t *selection, uint32_t imgid) /* get start and end rows for range selection */ int rc = 0; uint32_t sr = -1, er = -1; - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), dt_collection_get_query(selection->collection), - -1, &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), dt_collection_get_query(selection->collection), -1, + &stmt, NULL); while(sqlite3_step(stmt) == SQLITE_ROW) { diff --git a/src/common/srgb_tone_curve_values.h b/src/common/srgb_tone_curve_values.h index 0630dc25c777..22d2b02fdee8 100644 --- a/src/common/srgb_tone_curve_values.h +++ b/src/common/srgb_tone_curve_values.h @@ -1,75 +1,70 @@ #pragma once static const uint16_t dt_srgb_tone_curve_values[] = { - 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 59, 64, 69, - 74, 79, 84, 89, 94, 99, 104, 109, 114, 119, 124, 129, 134, 139, 144, - 149, 154, 159, 164, 169, 174, 178, 183, 188, 193, 198, 203, 208, 213, 219, - 224, 229, 235, 240, 246, 251, 257, 263, 269, 275, 281, 287, 293, 299, 306, - 312, 318, 325, 332, 338, 345, 352, 359, 366, 373, 380, 387, 395, 402, 410, - 417, 425, 433, 441, 449, 457, 465, 473, 481, 489, 498, 506, 515, 524, 532, - 541, 550, 559, 568, 577, 587, 596, 605, 615, 625, 634, 644, 654, 664, 674, - 684, 694, 705, 715, 725, 736, 747, 757, 768, 779, 790, 801, 813, 824, 835, - 847, 858, 870, 882, 894, 906, 918, 930, 942, 954, 967, 979, 992, 1004, 1017, - 1030, 1043, 1056, 1069, 1083, 1096, 1109, 1123, 1137, 1150, 1164, 1178, 1192, 1206, 1220, - 1235, 1249, 1264, 1278, 1293, 1308, 1323, 1338, 1353, 1368, 1383, 1399, 1414, 1430, 1446, - 1461, 1477, 1493, 1509, 1526, 1542, 1558, 1575, 1591, 1608, 1625, 1642, 1659, 1676, 1693, - 1711, 1728, 1745, 1763, 1781, 1799, 1817, 1835, 1853, 1871, 1889, 1908, 1926, 1945, 1964, - 1983, 2002, 2021, 2040, 2059, 2079, 2098, 2118, 2138, 2158, 2178, 2198, 2218, 2238, 2258, - 2279, 2299, 2320, 2341, 2362, 2383, 2404, 2425, 2447, 2468, 2490, 2511, 2533, 2555, 2577, - 2599, 2621, 2644, 2666, 2689, 2712, 2734, 2757, 2780, 2803, 2827, 2850, 2873, 2897, 2921, - 2944, 2968, 2992, 3016, 3041, 3065, 3090, 3114, 3139, 3164, 3189, 3214, 3239, 3264, 3289, - 3315, 3341, 3366, 3392, 3418, 3444, 3470, 3497, 3523, 3550, 3576, 3603, 3630, 3657, 3684, - 3711, 3739, 3766, 3794, 3822, 3849, 3877, 3905, 3934, 3962, 3990, 4019, 4047, 4076, 4105, - 4134, 4163, 4193, 4222, 4251, 4281, 4311, 4341, 4371, 4401, 4431, 4461, 4492, 4522, 4553, - 4584, 4615, 4646, 4677, 4708, 4740, 4771, 4803, 4835, 4867, 4899, 4931, 4963, 4995, 5028, - 5061, 5093, 5126, 5159, 5193, 5226, 5259, 5293, 5326, 5360, 5394, 5428, 5462, 5496, 5531, - 5565, 5600, 5635, 5670, 5705, 5740, 5775, 5810, 5846, 5882, 5917, 5953, 5989, 6025, 6062, - 6098, 6135, 6171, 6208, 6245, 6282, 6319, 6357, 6394, 6432, 6469, 6507, 6545, 6583, 6621, - 6660, 6698, 6737, 6775, 6814, 6853, 6892, 6932, 6971, 7011, 7050, 7090, 7130, 7170, 7210, - 7250, 7291, 7331, 7372, 7413, 7454, 7495, 7536, 7577, 7619, 7660, 7702, 7744, 7786, 7828, - 7870, 7913, 7955, 7998, 8041, 8084, 8127, 8170, 8213, 8257, 8300, 8344, 8388, 8432, 8476, - 8520, 8565, 8609, 8654, 8699, 8743, 8789, 8834, 8879, 8925, 8970, 9016, 9062, 9108, 9154, - 9200, 9247, 9293, 9340, 9387, 9434, 9481, 9528, 9576, 9623, 9671, 9719, 9767, 9815, 9863, - 9911, 9960, 10008, 10057, 10106, 10155, 10204, 10253, 10303, 10353, 10402, 10452, 10502, 10552, 10603, - 10653, 10704, 10754, 10805, 10856, 10907, 10959, 11010, 11062, 11113, 11165, 11217, 11269, 11321, 11374, - 11426, 11479, 11532, 11585, 11638, 11691, 11745, 11798, 11852, 11906, 11959, 12014, 12068, 12122, 12177, - 12231, 12286, 12341, 12396, 12452, 12507, 12562, 12618, 12674, 12730, 12786, 12842, 12899, 12955, 13012, - 13069, 13126, 13183, 13240, 13297, 13355, 13413, 13470, 13528, 13587, 13645, 13703, 13762, 13821, 13879, - 13938, 13998, 14057, 14116, 14176, 14236, 14295, 14356, 14416, 14476, 14536, 14597, 14658, 14719, 14780, - 14841, 14902, 14964, 15026, 15087, 15149, 15211, 15274, 15336, 15399, 15461, 15524, 15587, 15650, 15713, - 15777, 15840, 15904, 15968, 16032, 16096, 16161, 16225, 16290, 16354, 16419, 16484, 16550, 16615, 16681, - 16746, 16812, 16878, 16944, 17010, 17077, 17143, 17210, 17277, 17344, 17411, 17479, 17546, 17614, 17682, - 17749, 17818, 17886, 17954, 18023, 18091, 18160, 18229, 18299, 18368, 18437, 18507, 18577, 18647, 18717, - 18787, 18857, 18928, 18999, 19069, 19140, 19212, 19283, 19354, 19426, 19498, 19570, 19642, 19714, 19786, - 19859, 19932, 20005, 20078, 20151, 20224, 20297, 20371, 20445, 20519, 20593, 20667, 20742, 20816, 20891, - 20966, 21041, 21116, 21191, 21267, 21343, 21418, 21494, 21570, 21647, 21723, 21800, 21877, 21954, 22031, - 22108, 22185, 22263, 22340, 22418, 22496, 22575, 22653, 22731, 22810, 22889, 22968, 23047, 23126, 23206, - 23285, 23365, 23445, 23525, 23605, 23686, 23766, 23847, 23928, 24009, 24090, 24172, 24253, 24335, 24417, - 24499, 24581, 24663, 24746, 24828, 24911, 24994, 25077, 25161, 25244, 25328, 25411, 25495, 25579, 25664, - 25748, 25833, 25917, 26002, 26087, 26173, 26258, 26344, 26429, 26515, 26601, 26687, 26774, 26860, 26947, - 27034, 27121, 27208, 27295, 27383, 27471, 27559, 27647, 27735, 27823, 27912, 28000, 28089, 28178, 28267, - 28356, 28446, 28536, 28625, 28715, 28806, 28896, 28986, 29077, 29168, 29259, 29350, 29441, 29533, 29624, - 29716, 29808, 29900, 29992, 30085, 30177, 30270, 30363, 30456, 30550, 30643, 30737, 30830, 30924, 31018, - 31113, 31207, 31302, 31397, 31492, 31587, 31682, 31777, 31873, 31969, 32065, 32161, 32257, 32354, 32450, - 32547, 32644, 32741, 32839, 32936, 33034, 33131, 33229, 33328, 33426, 33524, 33623, 33722, 33821, 33920, - 34019, 34119, 34219, 34318, 34418, 34519, 34619, 34719, 34820, 34921, 35022, 35123, 35225, 35326, 35428, - 35530, 35632, 35734, 35836, 35939, 36042, 36145, 36248, 36351, 36454, 36558, 36662, 36766, 36870, 36974, - 37078, 37183, 37288, 37393, 37498, 37603, 37709, 37814, 37920, 38026, 38132, 38239, 38345, 38452, 38559, - 38666, 38773, 38880, 38988, 39096, 39204, 39312, 39420, 39528, 39637, 39746, 39855, 39964, 40073, 40183, - 40292, 40402, 40512, 40622, 40733, 40843, 40954, 41065, 41176, 41287, 41398, 41510, 41622, 41734, 41846, - 41958, 42070, 42183, 42296, 42409, 42522, 42635, 42749, 42862, 42976, 43090, 43204, 43319, 43433, 43548, - 43663, 43778, 43893, 44009, 44124, 44240, 44356, 44472, 44589, 44705, 44822, 44939, 45056, 45173, 45290, - 45408, 45526, 45643, 45762, 45880, 45998, 46117, 46236, 46355, 46474, 46593, 46713, 46832, 46952, 47072, - 47193, 47313, 47434, 47554, 47675, 47797, 47918, 48039, 48161, 48283, 48405, 48527, 48650, 48772, 48895, - 49018, 49141, 49264, 49388, 49511, 49635, 49759, 49883, 50008, 50132, 50257, 50382, 50507, 50632, 50758, - 50883, 51009, 51135, 51261, 51388, 51514, 51641, 51768, 51895, 52022, 52150, 52277, 52405, 52533, 52661, - 52790, 52918, 53047, 53176, 53305, 53434, 53564, 53694, 53823, 53953, 54084, 54214, 54345, 54475, 54606, - 54737, 54869, 55000, 55132, 55264, 55396, 55528, 55660, 55793, 55926, 56059, 56192, 56325, 56458, 56592, - 56726, 56860, 56994, 57129, 57263, 57398, 57533, 57668, 57804, 57939, 58075, 58211, 58347, 58483, 58620, - 58756, 58893, 59030, 59167, 59305, 59442, 59580, 59718, 59856, 59995, 60133, 60272, 60411, 60550, 60689, - 60828, 60968, 61108, 61248, 61388, 61528, 61669, 61810, 61951, 62092, 62233, 62375, 62516, 62658, 62800, - 62942, 63085, 63227, 63370, 63513, 63656, 63800, 63943, 64087, 64231, 64375, 64519, 64664, 64809, 64954, - 65099, 65244, 65389, 65535 + 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 59, 64, 69, 74, + 79, 84, 89, 94, 99, 104, 109, 114, 119, 124, 129, 134, 139, 144, 149, 154, + 159, 164, 169, 174, 178, 183, 188, 193, 198, 203, 208, 213, 219, 224, 229, 235, + 240, 246, 251, 257, 263, 269, 275, 281, 287, 293, 299, 306, 312, 318, 325, 332, + 338, 345, 352, 359, 366, 373, 380, 387, 395, 402, 410, 417, 425, 433, 441, 449, + 457, 465, 473, 481, 489, 498, 506, 515, 524, 532, 541, 550, 559, 568, 577, 587, + 596, 605, 615, 625, 634, 644, 654, 664, 674, 684, 694, 705, 715, 725, 736, 747, + 757, 768, 779, 790, 801, 813, 824, 835, 847, 858, 870, 882, 894, 906, 918, 930, + 942, 954, 967, 979, 992, 1004, 1017, 1030, 1043, 1056, 1069, 1083, 1096, 1109, 1123, 1137, + 1150, 1164, 1178, 1192, 1206, 1220, 1235, 1249, 1264, 1278, 1293, 1308, 1323, 1338, 1353, 1368, + 1383, 1399, 1414, 1430, 1446, 1461, 1477, 1493, 1509, 1526, 1542, 1558, 1575, 1591, 1608, 1625, + 1642, 1659, 1676, 1693, 1711, 1728, 1745, 1763, 1781, 1799, 1817, 1835, 1853, 1871, 1889, 1908, + 1926, 1945, 1964, 1983, 2002, 2021, 2040, 2059, 2079, 2098, 2118, 2138, 2158, 2178, 2198, 2218, + 2238, 2258, 2279, 2299, 2320, 2341, 2362, 2383, 2404, 2425, 2447, 2468, 2490, 2511, 2533, 2555, + 2577, 2599, 2621, 2644, 2666, 2689, 2712, 2734, 2757, 2780, 2803, 2827, 2850, 2873, 2897, 2921, + 2944, 2968, 2992, 3016, 3041, 3065, 3090, 3114, 3139, 3164, 3189, 3214, 3239, 3264, 3289, 3315, + 3341, 3366, 3392, 3418, 3444, 3470, 3497, 3523, 3550, 3576, 3603, 3630, 3657, 3684, 3711, 3739, + 3766, 3794, 3822, 3849, 3877, 3905, 3934, 3962, 3990, 4019, 4047, 4076, 4105, 4134, 4163, 4193, + 4222, 4251, 4281, 4311, 4341, 4371, 4401, 4431, 4461, 4492, 4522, 4553, 4584, 4615, 4646, 4677, + 4708, 4740, 4771, 4803, 4835, 4867, 4899, 4931, 4963, 4995, 5028, 5061, 5093, 5126, 5159, 5193, + 5226, 5259, 5293, 5326, 5360, 5394, 5428, 5462, 5496, 5531, 5565, 5600, 5635, 5670, 5705, 5740, + 5775, 5810, 5846, 5882, 5917, 5953, 5989, 6025, 6062, 6098, 6135, 6171, 6208, 6245, 6282, 6319, + 6357, 6394, 6432, 6469, 6507, 6545, 6583, 6621, 6660, 6698, 6737, 6775, 6814, 6853, 6892, 6932, + 6971, 7011, 7050, 7090, 7130, 7170, 7210, 7250, 7291, 7331, 7372, 7413, 7454, 7495, 7536, 7577, + 7619, 7660, 7702, 7744, 7786, 7828, 7870, 7913, 7955, 7998, 8041, 8084, 8127, 8170, 8213, 8257, + 8300, 8344, 8388, 8432, 8476, 8520, 8565, 8609, 8654, 8699, 8743, 8789, 8834, 8879, 8925, 8970, + 9016, 9062, 9108, 9154, 9200, 9247, 9293, 9340, 9387, 9434, 9481, 9528, 9576, 9623, 9671, 9719, + 9767, 9815, 9863, 9911, 9960, 10008, 10057, 10106, 10155, 10204, 10253, 10303, 10353, 10402, 10452, 10502, + 10552, 10603, 10653, 10704, 10754, 10805, 10856, 10907, 10959, 11010, 11062, 11113, 11165, 11217, 11269, 11321, + 11374, 11426, 11479, 11532, 11585, 11638, 11691, 11745, 11798, 11852, 11906, 11959, 12014, 12068, 12122, 12177, + 12231, 12286, 12341, 12396, 12452, 12507, 12562, 12618, 12674, 12730, 12786, 12842, 12899, 12955, 13012, 13069, + 13126, 13183, 13240, 13297, 13355, 13413, 13470, 13528, 13587, 13645, 13703, 13762, 13821, 13879, 13938, 13998, + 14057, 14116, 14176, 14236, 14295, 14356, 14416, 14476, 14536, 14597, 14658, 14719, 14780, 14841, 14902, 14964, + 15026, 15087, 15149, 15211, 15274, 15336, 15399, 15461, 15524, 15587, 15650, 15713, 15777, 15840, 15904, 15968, + 16032, 16096, 16161, 16225, 16290, 16354, 16419, 16484, 16550, 16615, 16681, 16746, 16812, 16878, 16944, 17010, + 17077, 17143, 17210, 17277, 17344, 17411, 17479, 17546, 17614, 17682, 17749, 17818, 17886, 17954, 18023, 18091, + 18160, 18229, 18299, 18368, 18437, 18507, 18577, 18647, 18717, 18787, 18857, 18928, 18999, 19069, 19140, 19212, + 19283, 19354, 19426, 19498, 19570, 19642, 19714, 19786, 19859, 19932, 20005, 20078, 20151, 20224, 20297, 20371, + 20445, 20519, 20593, 20667, 20742, 20816, 20891, 20966, 21041, 21116, 21191, 21267, 21343, 21418, 21494, 21570, + 21647, 21723, 21800, 21877, 21954, 22031, 22108, 22185, 22263, 22340, 22418, 22496, 22575, 22653, 22731, 22810, + 22889, 22968, 23047, 23126, 23206, 23285, 23365, 23445, 23525, 23605, 23686, 23766, 23847, 23928, 24009, 24090, + 24172, 24253, 24335, 24417, 24499, 24581, 24663, 24746, 24828, 24911, 24994, 25077, 25161, 25244, 25328, 25411, + 25495, 25579, 25664, 25748, 25833, 25917, 26002, 26087, 26173, 26258, 26344, 26429, 26515, 26601, 26687, 26774, + 26860, 26947, 27034, 27121, 27208, 27295, 27383, 27471, 27559, 27647, 27735, 27823, 27912, 28000, 28089, 28178, + 28267, 28356, 28446, 28536, 28625, 28715, 28806, 28896, 28986, 29077, 29168, 29259, 29350, 29441, 29533, 29624, + 29716, 29808, 29900, 29992, 30085, 30177, 30270, 30363, 30456, 30550, 30643, 30737, 30830, 30924, 31018, 31113, + 31207, 31302, 31397, 31492, 31587, 31682, 31777, 31873, 31969, 32065, 32161, 32257, 32354, 32450, 32547, 32644, + 32741, 32839, 32936, 33034, 33131, 33229, 33328, 33426, 33524, 33623, 33722, 33821, 33920, 34019, 34119, 34219, + 34318, 34418, 34519, 34619, 34719, 34820, 34921, 35022, 35123, 35225, 35326, 35428, 35530, 35632, 35734, 35836, + 35939, 36042, 36145, 36248, 36351, 36454, 36558, 36662, 36766, 36870, 36974, 37078, 37183, 37288, 37393, 37498, + 37603, 37709, 37814, 37920, 38026, 38132, 38239, 38345, 38452, 38559, 38666, 38773, 38880, 38988, 39096, 39204, + 39312, 39420, 39528, 39637, 39746, 39855, 39964, 40073, 40183, 40292, 40402, 40512, 40622, 40733, 40843, 40954, + 41065, 41176, 41287, 41398, 41510, 41622, 41734, 41846, 41958, 42070, 42183, 42296, 42409, 42522, 42635, 42749, + 42862, 42976, 43090, 43204, 43319, 43433, 43548, 43663, 43778, 43893, 44009, 44124, 44240, 44356, 44472, 44589, + 44705, 44822, 44939, 45056, 45173, 45290, 45408, 45526, 45643, 45762, 45880, 45998, 46117, 46236, 46355, 46474, + 46593, 46713, 46832, 46952, 47072, 47193, 47313, 47434, 47554, 47675, 47797, 47918, 48039, 48161, 48283, 48405, + 48527, 48650, 48772, 48895, 49018, 49141, 49264, 49388, 49511, 49635, 49759, 49883, 50008, 50132, 50257, 50382, + 50507, 50632, 50758, 50883, 51009, 51135, 51261, 51388, 51514, 51641, 51768, 51895, 52022, 52150, 52277, 52405, + 52533, 52661, 52790, 52918, 53047, 53176, 53305, 53434, 53564, 53694, 53823, 53953, 54084, 54214, 54345, 54475, + 54606, 54737, 54869, 55000, 55132, 55264, 55396, 55528, 55660, 55793, 55926, 56059, 56192, 56325, 56458, 56592, + 56726, 56860, 56994, 57129, 57263, 57398, 57533, 57668, 57804, 57939, 58075, 58211, 58347, 58483, 58620, 58756, + 58893, 59030, 59167, 59305, 59442, 59580, 59718, 59856, 59995, 60133, 60272, 60411, 60550, 60689, 60828, 60968, + 61108, 61248, 61388, 61528, 61669, 61810, 61951, 62092, 62233, 62375, 62516, 62658, 62800, 62942, 63085, 63227, + 63370, 63513, 63656, 63800, 63943, 64087, 64231, 64375, 64519, 64664, 64809, 64954, 65099, 65244, 65389, 65535 }; static const guint dt_srgb_tone_curve_values_n = G_N_ELEMENTS(dt_srgb_tone_curve_values); diff --git a/src/common/styles.c b/src/common/styles.c index d384a07e6110..ad6bc00dcf8d 100644 --- a/src/common/styles.c +++ b/src/common/styles.c @@ -87,8 +87,8 @@ void dt_style_item_free(gpointer data) free(item); } -static gboolean _apply_style_shortcut_callback(GtkAccelGroup *accel_group, GObject *acceleratable, - guint keyval, GdkModifierType modifier, gpointer data) +static gboolean _apply_style_shortcut_callback(GtkAccelGroup *accel_group, GObject *acceleratable, guint keyval, + GdkModifierType modifier, gpointer data) { dt_styles_apply_to_selection(data, 0); return TRUE; @@ -182,10 +182,10 @@ static gboolean dt_styles_create_style_header(const char *name, const char *desc return FALSE; } /* first create the style header */ - DT_DEBUG_SQLITE3_PREPARE_V2( - dt_database_get(darktable.db), - "INSERT INTO data.styles (name,description,id) VALUES " - "(?1,?2,(SELECT COALESCE(MAX(id),0)+1 FROM data.styles))", -1, &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), + "INSERT INTO data.styles (name,description,id) VALUES " + "(?1,?2,(SELECT COALESCE(MAX(id),0)+1 FROM data.styles))", + -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, name, -1, SQLITE_STATIC); DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, description, -1, SQLITE_STATIC); sqlite3_step(stmt); @@ -241,8 +241,8 @@ static void _dt_style_update_from_image(int id, int imgid, GList *filter, GList } } -void dt_styles_update(const char *name, const char *newname, const char *newdescription, GList *filter, - int imgid, GList *update) +void dt_styles_update(const char *name, const char *newname, const char *newdescription, GList *filter, int imgid, + GList *update) { sqlite3_stmt *stmt; int id = 0; @@ -311,8 +311,8 @@ void dt_styles_update(const char *name, const char *newname, const char *newdesc snprintf(tmp_accel, sizeof(tmp_accel), C_("accel", "styles/apply %s"), newname); dt_accel_register_global(tmp_accel, 0, 0); GClosure *closure; - closure = g_cclosure_new(G_CALLBACK(_apply_style_shortcut_callback), tmp_name, - _destroy_style_shortcut_callback); + closure + = g_cclosure_new(G_CALLBACK(_apply_style_shortcut_callback), tmp_name, _destroy_style_shortcut_callback); dt_accel_connect_global(tmp_accel, closure); } @@ -321,8 +321,8 @@ void dt_styles_update(const char *name, const char *newname, const char *newdesc g_free(desc); } -void dt_styles_create_from_style(const char *name, const char *newname, const char *description, - GList *filter, int imgid, GList *update) +void dt_styles_create_from_style(const char *name, const char *newname, const char *description, GList *filter, + int imgid, GList *update) { sqlite3_stmt *stmt; int id = 0; @@ -391,8 +391,8 @@ void dt_styles_create_from_style(const char *name, const char *newname, const ch snprintf(tmp_accel, sizeof(tmp_accel), C_("accel", "styles/apply %s"), newname); dt_accel_register_global(tmp_accel, 0, 0); GClosure *closure; - closure = g_cclosure_new(G_CALLBACK(_apply_style_shortcut_callback), tmp_name, - _destroy_style_shortcut_callback); + closure + = g_cclosure_new(G_CALLBACK(_apply_style_shortcut_callback), tmp_name, _destroy_style_shortcut_callback); dt_accel_connect_global(tmp_accel, closure); dt_control_log(_("style named '%s' successfully created"), newname); dt_control_signal_raise(darktable.signals, DT_SIGNAL_STYLE_CHANGED); @@ -460,8 +460,8 @@ gboolean dt_styles_create_from_image(const char *name, const char *description, snprintf(tmp_accel, sizeof(tmp_accel), C_("accel", "styles/apply %s"), name); dt_accel_register_global(tmp_accel, 0, 0); GClosure *closure; - closure = g_cclosure_new(G_CALLBACK(_apply_style_shortcut_callback), tmp_name, - _destroy_style_shortcut_callback); + closure + = g_cclosure_new(G_CALLBACK(_apply_style_shortcut_callback), tmp_name, _destroy_style_shortcut_callback); dt_accel_connect_global(tmp_accel, closure); dt_control_signal_raise(darktable.signals, DT_SIGNAL_STYLE_CHANGED); return TRUE; @@ -481,8 +481,8 @@ void dt_styles_apply_to_selection(const char *name, gboolean duplicate) /* for each selected image apply style */ sqlite3_stmt *stmt; - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT imgid FROM main.selected_images", - -1, &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT imgid FROM main.selected_images", -1, &stmt, + NULL); while(sqlite3_step(stmt) == SQLITE_ROW) { int imgid = sqlite3_column_int(stmt, 0); @@ -499,8 +499,8 @@ void dt_styles_create_from_selection() gboolean selected = FALSE; /* for each selected create style */ sqlite3_stmt *stmt; - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT imgid FROM main.selected_images", - -1, &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT imgid FROM main.selected_images", -1, &stmt, + NULL); while(sqlite3_step(stmt) == SQLITE_ROW) { int imgid = sqlite3_column_int(stmt, 0); @@ -533,7 +533,8 @@ void dt_styles_apply_to_image(const char *name, gboolean duplicate, int32_t imgi /* first trim the stack to get rid of whatever is above the selected entry */ DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "DELETE FROM main.history WHERE imgid = ?1 AND num >= (SELECT history_end " - "FROM main.images WHERE id = imgid)", -1, &stmt, NULL); + "FROM main.images WHERE id = imgid)", + -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, newimgid); sqlite3_step(stmt); sqlite3_finalize(stmt); @@ -643,10 +644,11 @@ GList *dt_styles_get_item_list(const char *name, gboolean params, int imgid) if((id = dt_styles_get_id_by_name(name)) != 0) { if(params) - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), - "SELECT num, multi_priority, module, operation, enabled, op_params, blendop_params, " - "multi_name FROM data.style_items WHERE styleid=?1 ORDER BY num DESC", - -1, &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2( + dt_database_get(darktable.db), + "SELECT num, multi_priority, module, operation, enabled, op_params, blendop_params, " + "multi_name FROM data.style_items WHERE styleid=?1 ORDER BY num DESC", + -1, &stmt, NULL); else if(imgid != -1) { // get all items from the style @@ -654,21 +656,25 @@ GList *dt_styles_get_item_list(const char *name, gboolean params, int imgid) // get all items from history, not in the style : select only the last operation, that is max(num) DT_DEBUG_SQLITE3_PREPARE_V2( dt_database_get(darktable.db), - "SELECT num, multi_priority, module, operation, enabled, (SELECT MAX(num) FROM main.history WHERE imgid=?2 " - "AND operation=data.style_items.operation GROUP BY multi_priority),multi_name FROM data.style_items WHERE " + "SELECT num, multi_priority, module, operation, enabled, (SELECT MAX(num) FROM main.history WHERE " + "imgid=?2 " + "AND operation=data.style_items.operation GROUP BY multi_priority),multi_name FROM data.style_items " + "WHERE " "styleid=?1 UNION SELECT -1,main.history.module,main.history.operation,main.history.enabled, " "main.history.num,multi_name FROM main.history WHERE imgid=?2 AND main.history.enabled=1 AND " "(main.history.operation NOT IN (SELECT operation FROM data.style_items WHERE styleid=?1) OR " "(main.history.op_params NOT IN (SELECT op_params FROM data.style_items WHERE styleid=?1 AND " "operation=main.history.operation)) OR (main.history.blendop_params NOT IN (SELECT blendop_params FROM " "data.style_items WHERE styleid=?1 AND operation=main.history.operation))) GROUP BY operation HAVING " - "MAX(num) ORDER BY num DESC", -1, &stmt, NULL); + "MAX(num) ORDER BY num DESC", + -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, imgid); } else - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT num, multi_priority, module, operation, " - "enabled, 0, multi_name FROM data.style_items WHERE " - "styleid=?1 ORDER BY num DESC", + DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), + "SELECT num, multi_priority, module, operation, " + "enabled, 0, multi_name FROM data.style_items WHERE " + "styleid=?1 ORDER BY num DESC", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id); @@ -916,8 +922,8 @@ static void dt_styles_start_tag_handler(GMarkupParseContext *context, const gcha } } -static void dt_styles_end_tag_handler(GMarkupParseContext *context, const gchar *element_name, - gpointer user_data, GError **error) +static void dt_styles_end_tag_handler(GMarkupParseContext *context, const gchar *element_name, gpointer user_data, + GError **error) { StyleData *style = user_data; const gchar *elt = g_markup_parse_context_get_element(context); @@ -1019,8 +1025,8 @@ static void dt_style_plugin_save(StylePluginData *plugin, gpointer styleId) /* decode and store blendop params */ int blendop_params_len = 0; - unsigned char *blendop_params = dt_exif_xmp_decode( - plugin->blendop_params->str, strlen(plugin->blendop_params->str), &blendop_params_len); + unsigned char *blendop_params + = dt_exif_xmp_decode(plugin->blendop_params->str, strlen(plugin->blendop_params->str), &blendop_params_len); DT_DEBUG_SQLITE3_BIND_BLOB(stmt, 7, blendop_params, blendop_params_len, SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_INT(stmt, 8, plugin->blendop_version); diff --git a/src/common/styles.h b/src/common/styles.h index 0cca0a76a449..b92594295b52 100644 --- a/src/common/styles.h +++ b/src/common/styles.h @@ -58,12 +58,12 @@ gboolean dt_styles_create_from_image(const char *name, const char *description, void dt_styles_create_from_selection(void); /** creates a new style from specified style, items are the style number of items to include in style */ -void dt_styles_create_from_style(const char *name, const char *newname, const char *description, - GList *filter, int imgid, GList *update); +void dt_styles_create_from_style(const char *name, const char *newname, const char *description, GList *filter, + int imgid, GList *update); /** update a style */ -void dt_styles_update(const char *name, const char *newname, const char *description, GList *filter, - int imgid, GList *update); +void dt_styles_update(const char *name, const char *newname, const char *description, GList *filter, int imgid, + GList *update); /** applies the style to selection of images */ void dt_styles_apply_to_selection(const char *name, gboolean duplicate); diff --git a/src/common/tags.c b/src/common/tags.c index 1515b61754b7..18a80924ec21 100644 --- a/src/common/tags.c +++ b/src/common/tags.c @@ -23,7 +23,7 @@ #include "control/conf.h" #include "control/control.h" #include <glib.h> -#if defined (_WIN32) +#if defined(_WIN32) #include "win/getdelim.h" #endif // defined (_WIN32) @@ -101,8 +101,8 @@ guint dt_tag_remove(const guint tagid, gboolean final) sqlite3_step(stmt); sqlite3_finalize(stmt); - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "DELETE FROM main.tagged_images WHERE tagid=?1", - -1, &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "DELETE FROM main.tagged_images WHERE tagid=?1", -1, + &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, tagid); sqlite3_step(stmt); sqlite3_finalize(stmt); @@ -157,8 +157,8 @@ void dt_tag_reorganize(const gchar *source, const gchar *dest) sqlite3_finalize(stmt); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), - "UPDATE main.used_tags SET name=REPLACE(name,?1,?2) WHERE name LIKE ?3", - -1, &stmt, NULL); + "UPDATE main.used_tags SET name=REPLACE(name,?1,?2) WHERE name LIKE ?3", -1, &stmt, + NULL); DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, source, -1, SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, new_expr, -1, SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 3, source_expr, -1, SQLITE_TRANSIENT); @@ -335,13 +335,12 @@ uint32_t dt_tag_get_attached(gint imgid, GList **result, gboolean ignore_dt_tags else { if(ignore_dt_tags) - DT_DEBUG_SQLITE3_PREPARE_V2( - dt_database_get(darktable.db), - "SELECT DISTINCT T.id, T.name " - "FROM main.tagged_images AS I, data.tags AS T " - "WHERE I.imgid IN (SELECT imgid FROM main.selected_images) " - "AND T.id = I.tagid AND NOT T.name LIKE \"darktable|%\" ORDER BY T.name", - -1, &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), + "SELECT DISTINCT T.id, T.name " + "FROM main.tagged_images AS I, data.tags AS T " + "WHERE I.imgid IN (SELECT imgid FROM main.selected_images) " + "AND T.id = I.tagid AND NOT T.name LIKE \"darktable|%\" ORDER BY T.name", + -1, &stmt, NULL); else DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT DISTINCT T.id, T.name " @@ -389,7 +388,8 @@ GList *dt_tag_get_list(gint imgid) if(omit_tag_hierarchy) { char **iter = pch; - for(; *iter && *(iter + 1); iter++); + for(; *iter && *(iter + 1); iter++) + ; if(*iter) tags = g_list_prepend(tags, g_strdup(*iter)); } else @@ -441,15 +441,17 @@ GList *dt_tag_get_images_from_selection(gint imgid, gint tagid) if(imgid > 0) { DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT imgid FROM main.tagged_images WHERE " - "imgid = ?1 AND tagid = ?2", -1, &stmt, NULL); + "imgid = ?1 AND tagid = ?2", + -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, tagid); } else { - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT imgid FROM main.tagged_images WHERE " - "tagid = ?1 AND imgid IN (SELECT imgid FROM main.selected_images)", -1, &stmt, - NULL); + DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), + "SELECT imgid FROM main.tagged_images WHERE " + "tagid = ?1 AND imgid IN (SELECT imgid FROM main.selected_images)", + -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, tagid); } @@ -484,9 +486,9 @@ uint32_t dt_tag_get_suggestions(const gchar *keyword, GList **result) gchar *keyword_expr = g_strdup_printf("%%%s%%", keyword); /* Only select tags that are similar to the one we are looking for once. */ - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), - "INSERT INTO memory.similar_tags (tagid) SELECT id FROM data.tags WHERE name LIKE ?1", - -1, &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2( + dt_database_get(darktable.db), + "INSERT INTO memory.similar_tags (tagid) SELECT id FROM data.tags WHERE name LIKE ?1", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, keyword_expr, -1, SQLITE_TRANSIENT); sqlite3_step(stmt); sqlite3_finalize(stmt); @@ -503,24 +505,26 @@ uint32_t dt_tag_get_suggestions(const gchar *keyword, GList **result) sqlite3_finalize(stmt); /* Select tags that are similar to the keyword but were not used to tag any image*/ - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), - "INSERT INTO memory.taglist (id, count) SELECT tagid,1000000 FROM memory.similar_tags", - -1, &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2( + dt_database_get(darktable.db), + "INSERT INTO memory.taglist (id, count) SELECT tagid,1000000 FROM memory.similar_tags", -1, &stmt, NULL); sqlite3_step(stmt); sqlite3_finalize(stmt); /* Select tags from tagged images when at least one tag is similar to the keyword and insert in temp table*/ - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), - "INSERT INTO memory.tagq (id) SELECT tagid FROM main.tagged_images WHERE imgid IN " - "(SELECT DISTINCT imgid FROM main.tagged_images JOIN memory.similar_tags USING (tagid)) ", - -1, &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2( + dt_database_get(darktable.db), + "INSERT INTO memory.tagq (id) SELECT tagid FROM main.tagged_images WHERE imgid IN " + "(SELECT DISTINCT imgid FROM main.tagged_images JOIN memory.similar_tags USING (tagid)) ", + -1, &stmt, NULL); sqlite3_step(stmt); sqlite3_finalize(stmt); /* Select tags from temp table that are not similar to the keyword */ DT_DEBUG_SQLITE3_EXEC(dt_database_get(darktable.db), "INSERT INTO memory.taglist (id, count) SELECT id, " "COUNT(*) FROM memory.tagq WHERE id NOT IN (SELECT id FROM " - "memory.taglist) GROUP BY id", NULL, NULL, NULL); + "memory.taglist) GROUP BY id", + NULL, NULL, NULL); /* Now put all the bits together */ DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), @@ -585,7 +589,7 @@ ssize_t dt_tag_import(const char *filename) if(!fd) return -1; - GList * hierarchy = NULL; + GList *hierarchy = NULL; char *line = NULL; size_t len = 0; ssize_t count = 0; @@ -608,8 +612,8 @@ ssize_t dt_tag_import(const char *filename) // don't add the entry if it's a category // TODO also ignore synonyms for now as our db can't express that concept. gboolean skip = FALSE; - if((*start == '[' && *end == ']') // categories - || (*start == '{' && *end == '}')) // synonyms + if((*start == '[' && *end == ']') // categories + || (*start == '{' && *end == '}')) // synonyms { skip = TRUE; start++; @@ -681,7 +685,8 @@ ssize_t dt_tag_export(const char *filename) sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT name FROM data.tags WHERE name NOT LIKE \"darktable|%\" " - "ORDER BY name COLLATE NOCASE ASC", -1, &stmt, NULL); + "ORDER BY name COLLATE NOCASE ASC", + -1, &stmt, NULL); ssize_t count = 0; diff --git a/src/common/undo.c b/src/common/undo.c index 915f144d81ae..31334d6223db 100644 --- a/src/common/undo.c +++ b/src/common/undo.c @@ -18,8 +18,8 @@ #include "common/darktable.h" #include "common/undo.h" -#include <glib.h> // for GList, gpointer, g_list_first, g_list_prepend -#include <stdlib.h> // for NULL, malloc, free +#include <glib.h> // for GList, gpointer, g_list_first, g_list_prepend +#include <stdlib.h> // for NULL, malloc, free #include <sys/time.h> const double MAX_TIME_PERIOD = 0.5; // in second @@ -52,7 +52,7 @@ void dt_undo_cleanup(dt_undo_t *self) static void _free_undo_data(void *p) { dt_undo_item_t *item = (dt_undo_item_t *)p; - if (item->free_data) item->free_data(item->data); + if(item->free_data) item->free_data(item->data); free(item); } @@ -65,11 +65,11 @@ void dt_undo_record(dt_undo_t *self, gpointer user_data, dt_undo_type_t type, dt dt_undo_item_t *item = malloc(sizeof(dt_undo_item_t)); item->user_data = user_data; - item->type = type; - item->data = data; - item->undo = undo; + item->type = type; + item->data = data; + item->undo = undo; item->free_data = free_data; - item->ts = dt_get_wtime(); + item->ts = dt_get_wtime(); dt_pthread_mutex_lock(&self->mutex); self->undo_list = g_list_prepend(self->undo_list, (gpointer)item); @@ -114,8 +114,8 @@ void dt_undo_do_redo(dt_undo_t *self, uint32_t filter) self->undo_list = g_list_prepend(self->undo_list, item); l = next; - if (l) item = (dt_undo_item_t *)l->data; - } while (l && (item->type & filter) && (item->ts - first_item_ts < MAX_TIME_PERIOD)); + if(l) item = (dt_undo_item_t *)l->data; + } while(l && (item->type & filter) && (item->ts - first_item_ts < MAX_TIME_PERIOD)); break; } @@ -149,7 +149,7 @@ void dt_undo_do_undo(dt_undo_t *self, uint32_t filter) // now record in the redo list also all items that are on the same time period l = next; - while (l) + while(l) { next = g_list_next(l); item = (dt_undo_item_t *)l->data; @@ -157,7 +157,7 @@ void dt_undo_do_undo(dt_undo_t *self, uint32_t filter) item->undo(item->user_data, item->type, item->data); // if we are on the same time frame, just continue - if (item->type & filter && (first_item_ts - item->ts < MAX_TIME_PERIOD)) + if(item->type & filter && (first_item_ts - item->ts < MAX_TIME_PERIOD)) { self->undo_list = g_list_remove(self->undo_list, item); self->redo_list = g_list_prepend(self->redo_list, item); diff --git a/src/common/undo.h b/src/common/undo.h index 64d81fbca4d5..8c8bfe095077 100644 --- a/src/common/undo.h +++ b/src/common/undo.h @@ -18,9 +18,9 @@ #pragma once -#include "common/dtpthread.h" // for dt_pthread_mutex_t -#include <glib.h> // for gpointer, GList -#include <stdint.h> // for uint32_t +#include "common/dtpthread.h" // for dt_pthread_mutex_t +#include <glib.h> // for gpointer, GList +#include <stdint.h> // for uint32_t // types that are known by the undo module typedef enum dt_undo_type_t diff --git a/src/common/utility.c b/src/common/utility.c index bf67adfe0659..2ea4a888d6ba 100644 --- a/src/common/utility.c +++ b/src/common/utility.c @@ -23,18 +23,18 @@ #include "gui/gtk.h" /* getpwnam_r availibility check */ -#if defined __APPLE__ || defined _POSIX_C_SOURCE >= 1 || defined _XOPEN_SOURCE || defined _BSD_SOURCE \ - || defined _SVID_SOURCE || defined _POSIX_SOURCE || defined __DragonFly__ || defined __FreeBSD__ \ +#if defined __APPLE__ || defined _POSIX_C_SOURCE >= 1 || defined _XOPEN_SOURCE || defined _BSD_SOURCE \ + || defined _SVID_SOURCE || defined _POSIX_SOURCE || defined __DragonFly__ || defined __FreeBSD__ \ || defined __NetBSD__ || defined __OpenBSD__ - #include <pwd.h> - #include <sys/types.h> - #include <unistd.h> +#include <pwd.h> +#include <sys/types.h> +#include <unistd.h> #endif #ifdef _WIN32 - #include <Windows.h> - #include <WinBase.h> - #include <FileAPI.h> +#include <Windows.h> +#include <WinBase.h> +#include <FileAPI.h> #endif #include <math.h> @@ -43,7 +43,7 @@ #include <sys/stat.h> #ifdef HAVE_CONFIG_H - #include <config.h> +#include <config.h> #endif #include <librsvg/rsvg.h> @@ -328,22 +328,22 @@ gchar *dt_util_foo_to_utf8(const char *string) } // get easter sunday (in the western world) -static void easter(int Y, int* month, int *day) +static void easter(int Y, int *month, int *day) { - int a = Y % 19; - int b = Y / 100; - int c = Y % 100; - int d = b / 4; - int e = b % 4; - int f = (b + 8) / 25; - int g = (b - f + 1) / 3; - int h = (19*a + b - d - g + 15) % 30; - int i = c / 4; - int k = c % 4; - int L = (32 + 2*e + 2*i - h - k) % 7; - int m = (a + 11*h + 22*L) / 451; - *month = (h + L - 7*m + 114) / 31; - *day = ((h + L - 7*m + 114) % 31) + 1; + int a = Y % 19; + int b = Y / 100; + int c = Y % 100; + int d = b / 4; + int e = b % 4; + int f = (b + 8) / 25; + int g = (b - f + 1) / 3; + int h = (19 * a + b - d - g + 15) % 30; + int i = c / 4; + int k = c % 4; + int L = (32 + 2 * e + 2 * i - h - k) % 7; + int m = (a + 11 * h + 22 * L) / 451; + *month = (h + L - 7 * m + 114) / 31; + *day = ((h + L - 7 * m + 114) % 31) + 1; } // days are in [1..31], months are in [0..11], see "man localtime" @@ -355,8 +355,7 @@ dt_logo_season_t dt_util_get_logo_season(void) localtime_r(&now, &lt); // Halloween is active on 31.10. and 01.11. - if((lt.tm_mon == 9 && lt.tm_mday == 31) || (lt.tm_mon == 10 && lt.tm_mday == 1)) - return DT_LOGO_SEASON_HALLOWEEN; + if((lt.tm_mon == 9 && lt.tm_mday == 31) || (lt.tm_mon == 10 && lt.tm_mday == 1)) return DT_LOGO_SEASON_HALLOWEEN; // Xmas is active from 24.12. until the end of the year if(lt.tm_mon == 11 && lt.tm_mday >= 24) return DT_LOGO_SEASON_XMAS; @@ -364,7 +363,7 @@ dt_logo_season_t dt_util_get_logo_season(void) // Easter is active from 2 days before Easter Sunday until 1 day after { struct tm easter_sunday = lt; - easter(lt.tm_year+1900, &easter_sunday.tm_mon, &easter_sunday.tm_mday); + easter(lt.tm_year + 1900, &easter_sunday.tm_mon, &easter_sunday.tm_mday); easter_sunday.tm_mon--; easter_sunday.tm_hour = easter_sunday.tm_min = easter_sunday.tm_sec = 0; easter_sunday.tm_isdst = -1; @@ -402,17 +401,16 @@ cairo_surface_t *dt_util_get_logo(float size) float svg_size = MAX(dimension.width, dimension.height); float factor = size > 0.0 ? size / svg_size : -1.0 * size; - float final_width = dimension.width * factor * ppd, - final_height = dimension.height * factor * ppd; + float final_width = dimension.width * factor * ppd, final_height = dimension.height * factor * ppd; int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, final_width); guint8 *image_buffer = (guint8 *)calloc(stride * final_height, sizeof(guint8)); if(darktable.gui) surface = dt_cairo_image_surface_create_for_data(image_buffer, CAIRO_FORMAT_ARGB32, final_width, - final_height, stride); - else // during startup we don't know ppd yet and darktable.gui isn't initialized yet. - surface = cairo_image_surface_create_for_data(image_buffer, CAIRO_FORMAT_ARGB32, final_width, final_height, stride); + else // during startup we don't know ppd yet and darktable.gui isn't initialized yet. + surface = cairo_image_surface_create_for_data(image_buffer, CAIRO_FORMAT_ARGB32, final_width, final_height, + stride); if(cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) { fprintf(stderr, "warning: can't load darktable logo from SVG file `%s'\n", dtlogo); @@ -447,10 +445,10 @@ cairo_surface_t *dt_util_get_logo(float size) // Copyright (C) 2013 John Stowers <john.stowers@gmail.com> /* these can be overwritten with versions that support * localization */ -#define OSD_COORDINATES_CHR_N "N" -#define OSD_COORDINATES_CHR_S "S" -#define OSD_COORDINATES_CHR_E "E" -#define OSD_COORDINATES_CHR_W "W" +#define OSD_COORDINATES_CHR_N "N" +#define OSD_COORDINATES_CHR_S "S" +#define OSD_COORDINATES_CHR_E "E" +#define OSD_COORDINATES_CHR_W "W" static const char *OSD_ELEVATION_ASL = N_("above sea level"); static const char *OSD_ELEVATION_BSL = N_("below sea level"); @@ -471,7 +469,7 @@ gchar *dt_util_latitude_str(float latitude) fractional = modff(latitude, &integral); - return g_strdup_printf("%s %02d° %06.3f'", c, (int)integral, fractional*60.0); + return g_strdup_printf("%s %02d° %06.3f'", c, (int)integral, fractional * 60.0); } gchar *dt_util_longitude_str(float longitude) @@ -489,7 +487,7 @@ gchar *dt_util_longitude_str(float longitude) fractional = modff(longitude, &integral); - return g_strdup_printf("%s %03d° %06.3f'", c, (int)integral, fractional*60.0); + return g_strdup_printf("%s %03d° %06.3f'", c, (int)integral, fractional * 60.0); } gchar *dt_util_elevation_str(float elevation) @@ -559,37 +557,34 @@ gchar *dt_util_normalize_path(const gchar *_input) } #ifdef _WIN32 - // on Windows filenames are case insensitive, so we can end up with an arbitrary number of different spellings for the same file. + // on Windows filenames are case insensitive, so we can end up with an arbitrary number of different spellings + // for the same file. // another problem is that path separators can either be / or \ leading to even more problems. // TODO: - // this only handles filenames in the old <drive letter>:\path\to\file form, not the \\?\UNC\ form and not some others like \Device\... + // this only handles filenames in the old <drive letter>:\path\to\file form, not the \\?\UNC\ form and not some + // others like \Device\... // the Windows api expects wide chars and not utf8 :( wchar_t *wfilename = g_utf8_to_utf16(filename, -1, NULL, NULL, NULL); g_free(filename); - if(!wfilename) - return NULL; + if(!wfilename) return NULL; - wchar_t LongPath[MAX_PATH] = {0}; + wchar_t LongPath[MAX_PATH] = { 0 }; DWORD size = GetLongPathNameW(wfilename, LongPath, MAX_PATH); g_free(wfilename); - if(size == 0 || size > MAX_PATH) - return NULL; + if(size == 0 || size > MAX_PATH) return NULL; // back to utf8! filename = g_utf16_to_utf8(LongPath, -1, NULL, NULL, NULL); - if(!filename) - return NULL; + if(!filename) return NULL; GFile *gfile = g_file_new_for_path(filename); g_free(filename); - if(!gfile) - return NULL; + if(!gfile) return NULL; filename = g_file_get_path(gfile); g_object_unref(gfile); - if(!filename) - return NULL; + if(!filename) return NULL; char drive_letter = g_ascii_toupper(filename[0]); if(drive_letter < 'A' || drive_letter > 'Z' || filename[1] != ':') diff --git a/src/common/variables.c b/src/common/variables.c index 4ffa36bf30a5..46ec72fd13c1 100644 --- a/src/common/variables.c +++ b/src/common/variables.c @@ -60,7 +60,8 @@ static void init_expansion(dt_variables_params_t *params, gboolean iterate) params->data->homedir = dt_loc_get_home_dir(NULL); if(g_get_user_special_dir(G_USER_DIRECTORY_PICTURES) == NULL) - params->data->pictures_folder = g_build_path(G_DIR_SEPARATOR_S, params->data->homedir, "Pictures", (char *)NULL); + params->data->pictures_folder + = g_build_path(G_DIR_SEPARATOR_S, params->data->homedir, "Pictures", (char *)NULL); else params->data->pictures_folder = g_strdup(g_get_user_special_dir(G_USER_DIRECTORY_PICTURES)); @@ -82,8 +83,9 @@ static void init_expansion(dt_variables_params_t *params, gboolean iterate) if(params->imgid) { const dt_image_t *img = dt_image_cache_get(darktable.image_cache, params->imgid, 'r'); - if(sscanf(img->exif_datetime_taken, "%d:%d:%d %d:%d:%d", &params->data->exif_tm.tm_year, &params->data->exif_tm.tm_mon, - &params->data->exif_tm.tm_mday, &params->data->exif_tm.tm_hour, &params->data->exif_tm.tm_min, &params->data->exif_tm.tm_sec) == 6) + if(sscanf(img->exif_datetime_taken, "%d:%d:%d %d:%d:%d", &params->data->exif_tm.tm_year, + &params->data->exif_tm.tm_mon, &params->data->exif_tm.tm_mday, &params->data->exif_tm.tm_hour, + &params->data->exif_tm.tm_min, &params->data->exif_tm.tm_sec) == 6) { params->data->exif_tm.tm_year -= 1900; params->data->exif_tm.tm_mon--; @@ -98,7 +100,8 @@ static void init_expansion(dt_variables_params_t *params, gboolean iterate) dt_image_cache_read_release(darktable.image_cache, img); } - else if (params->data->exif_time) { + else if(params->data->exif_time) + { localtime_r(&params->data->exif_time, &params->data->exif_tm); params->data->have_exif_tm = TRUE; } @@ -174,13 +177,11 @@ static char *get_base_value(dt_variables_params_t *params, char **variable) else if(has_prefix(variable, "FILE_DIRECTORY")) { // undocumented : backward compatibility - if(params->filename) - result = g_path_get_dirname(params->filename); + if(params->filename) result = g_path_get_dirname(params->filename); } else if(has_prefix(variable, "FILE_FOLDER")) { - if(params->filename) - result = g_path_get_dirname(params->filename); + if(params->filename) result = g_path_get_dirname(params->filename); } else if(has_prefix(variable, "FILE_NAME")) { @@ -351,7 +352,8 @@ static char *variable_get_value(dt_variables_params_t *params, char **variable) if(offset >= 0) start = g_utf8_offset_to_pointer(base_value, MIN(offset, base_value_utf8_length)); else - start = g_utf8_offset_to_pointer(base_value + base_value_length, MAX(offset, -1 * base_value_utf8_length)); + start + = g_utf8_offset_to_pointer(base_value + base_value_length, MAX(offset, -1 * base_value_utf8_length)); // now find the end if there is a length provided char *end = base_value + base_value_length; // ... and until where @@ -411,7 +413,8 @@ static char *variable_get_value(dt_variables_params_t *params, char **variable) $(var//Pattern/Replacement) Global replacement. All matches of Pattern, within var replaced with Replacement. - As above, if Replacement is omitted, then all occurrences of Pattern are replaced by nothing, that is, deleted. + As above, if Replacement is omitted, then all occurrences of Pattern are replaced by nothing, that is, + deleted. $(var/#Pattern/Replacement) If prefix of var matches Pattern, then substitute Replacement for Pattern. @@ -509,7 +512,7 @@ static char *variable_get_value(dt_variables_params_t *params, char **variable) char *_base_value = NULL; if(operation == '^' && mode == '^') { - _base_value = g_utf8_strup (base_value, -1); + _base_value = g_utf8_strup(base_value, -1); (*variable)++; } else if(operation == ',' && mode == ',') @@ -580,7 +583,6 @@ static char *expand(dt_variables_params_t *params, char **source, char extra_sto *result_iter = c; result_iter++; source_iter++; - } // it seems we have a variable here diff --git a/src/control/control.c b/src/control/control.c index 254120b43845..5ee7125e9dc6 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -80,15 +80,13 @@ void dt_control_init(dt_control_t *s) void dt_control_key_accelerators_on(struct dt_control_t *s) { - gtk_window_add_accel_group(GTK_WINDOW(dt_ui_main_window(darktable.gui->ui)), - darktable.control->accelerators); + gtk_window_add_accel_group(GTK_WINDOW(dt_ui_main_window(darktable.gui->ui)), darktable.control->accelerators); if(!s->key_accelerators_on) s->key_accelerators_on = 1; } void dt_control_key_accelerators_off(struct dt_control_t *s) { - gtk_window_remove_accel_group(GTK_WINDOW(dt_ui_main_window(darktable.gui->ui)), - darktable.control->accelerators); + gtk_window_remove_accel_group(GTK_WINDOW(dt_ui_main_window(darktable.gui->ui)), darktable.control->accelerators); s->key_accelerators_on = 0; } @@ -148,7 +146,6 @@ void dt_control_shutdown(dt_control_t *s) for(k = 0; k < DT_CTL_WORKER_RESERVED; k++) // pthread_kill(s->thread_res[k], 9); pthread_join(s->thread_res[k], NULL); - } void dt_control_cleanup(dt_control_t *s) @@ -192,8 +189,8 @@ void *dt_control_expose(void *voidptr) GtkWidget *widget = dt_ui_center(darktable.gui->ui); #if GTK_CHECK_VERSION(3, 20, 0) gdk_window_get_device_position(gtk_widget_get_window(widget), - gdk_seat_get_pointer(gdk_display_get_default_seat(gtk_widget_get_display(widget))), - &pointerx, &pointery, NULL); + gdk_seat_get_pointer(gdk_display_get_default_seat(gtk_widget_get_display(widget))), + &pointerx, &pointery, NULL); #else GdkDevice *device = gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gtk_widget_get_display(widget))); @@ -213,7 +210,7 @@ void *dt_control_expose(void *voidptr) GdkRGBA color; GtkStyleContext *context = gtk_widget_get_style_context(widget); - gboolean color_found = gtk_style_context_lookup_color (context, "bg_color", &color); + gboolean color_found = gtk_style_context_lookup_color(context, "bg_color", &color); if(!color_found) { color.red = 1.0; @@ -227,7 +224,7 @@ void *dt_control_expose(void *voidptr) cairo_rectangle(cr, tb / 2., tb / 2., width - tb, height - tb); cairo_stroke(cr); cairo_set_line_width(cr, 1.5); - color_found = gtk_style_context_lookup_color (context, "really_dark_bg_color", &color); + color_found = gtk_style_context_lookup_color(context, "really_dark_bg_color", &color); if(!color_found) { color.red = 1.0; @@ -245,8 +242,7 @@ void *dt_control_expose(void *voidptr) cairo_clip(cr); cairo_new_path(cr); // draw view - dt_view_manager_expose(darktable.view_manager, cr, width - 2 * tb, height - 2 * tb, pointerx - tb, - pointery - tb); + dt_view_manager_expose(darktable.view_manager, cr, width - 2 * tb, height - 2 * tb, pointerx - tb, pointery - tb); cairo_restore(cr); // draw log message, if any @@ -276,7 +272,7 @@ void *dt_control_expose(void *voidptr) cairo_line_to(cr, xc - wd, yc + rad); if(k == 0) { - color_found = gtk_style_context_lookup_color (context, "selected_bg_color", &color); + color_found = gtk_style_context_lookup_color(context, "selected_bg_color", &color); if(!color_found) { color.red = 1.0; @@ -291,7 +287,7 @@ void *dt_control_expose(void *voidptr) cairo_stroke(cr); rad += .5f; } - color_found = gtk_style_context_lookup_color (context, "fg_color", &color); + color_found = gtk_style_context_lookup_color(context, "fg_color", &color); if(!color_found) { color.red = 1.0; @@ -402,7 +398,7 @@ static void _dt_ctl_switch_mode_prepare() static gboolean _dt_ctl_switch_mode_to(gpointer user_data) { - const char *mode = (const char*)user_data; + const char *mode = (const char *)user_data; _dt_ctl_switch_mode_prepare(); dt_view_manager_switch(darktable.view_manager, mode); return FALSE; @@ -410,7 +406,7 @@ static gboolean _dt_ctl_switch_mode_to(gpointer user_data) static gboolean _dt_ctl_switch_mode_to_by_view(gpointer user_data) { - const dt_view_t *view = (const dt_view_t*)user_data; + const dt_view_t *view = (const dt_view_t *)user_data; _dt_ctl_switch_mode_prepare(); dt_view_manager_switch_by_view(darktable.view_manager, view); return FALSE; @@ -551,8 +547,7 @@ static gboolean _gtk_widget_queue_draw(gpointer user_data) void dt_control_queue_redraw_widget(GtkWidget *widget) { - if(dt_control_running()) - g_main_context_invoke(NULL, _gtk_widget_queue_draw, widget); + if(dt_control_running()) g_main_context_invoke(NULL, _gtk_widget_queue_draw, widget); } diff --git a/src/control/control.h b/src/control/control.h index 9265d6c00556..355f392ff9cc 100644 --- a/src/control/control.h +++ b/src/control/control.h @@ -102,10 +102,10 @@ int dt_control_is_key_accelerators_on(struct dt_control_t *s); // All the accelerator keys for the key_pressed style shortcuts typedef struct dt_control_accels_t { - GtkAccelKey filmstrip_forward, filmstrip_back, lighttable_up, lighttable_down, lighttable_right, - lighttable_left, lighttable_center, lighttable_preview, lighttable_preview_display_focus, - lighttable_preview_sticky, lighttable_preview_sticky_focus, lighttable_preview_sticky_exit, - global_sideborders, global_header, darkroom_preview, slideshow_start; + GtkAccelKey filmstrip_forward, filmstrip_back, lighttable_up, lighttable_down, lighttable_right, lighttable_left, + lighttable_center, lighttable_preview, lighttable_preview_display_focus, lighttable_preview_sticky, + lighttable_preview_sticky_focus, lighttable_preview_sticky_exit, global_sideborders, global_header, + darkroom_preview, slideshow_start; } dt_control_accels_t; diff --git a/src/control/crawler.c b/src/control/crawler.c index 4e2074f7eaaf..91ea308ef5e7 100644 --- a/src/control/crawler.c +++ b/src/control/crawler.c @@ -254,8 +254,8 @@ static void _reload_button_clicked(GtkButton *button, gpointer user_data) gboolean selected; int id; gchar *xmp_path; - gtk_tree_model_get(gui->model, &iter, DT_CONTROL_CRAWLER_COL_SELECTED, &selected, - DT_CONTROL_CRAWLER_COL_ID, &id, DT_CONTROL_CRAWLER_COL_XMP_PATH, &xmp_path, -1); + gtk_tree_model_get(gui->model, &iter, DT_CONTROL_CRAWLER_COL_SELECTED, &selected, DT_CONTROL_CRAWLER_COL_ID, + &id, DT_CONTROL_CRAWLER_COL_XMP_PATH, &xmp_path, -1); if(selected) { dt_history_load_and_apply(id, xmp_path, 0); @@ -279,8 +279,8 @@ void _overwrite_button_clicked(GtkButton *button, gpointer user_data) { gboolean selected; int id; - gtk_tree_model_get(gui->model, &iter, DT_CONTROL_CRAWLER_COL_SELECTED, &selected, - DT_CONTROL_CRAWLER_COL_ID, &id, -1); + gtk_tree_model_get(gui->model, &iter, DT_CONTROL_CRAWLER_COL_SELECTED, &selected, DT_CONTROL_CRAWLER_COL_ID, + &id, -1); if(selected) { dt_image_write_sidecar_file(id); @@ -327,8 +327,8 @@ void dt_control_crawler_show_image_list(GList *images) gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, DT_CONTROL_CRAWLER_COL_SELECTED, 0, DT_CONTROL_CRAWLER_COL_ID, item->id, DT_CONTROL_CRAWLER_COL_IMAGE_PATH, item->image_path, DT_CONTROL_CRAWLER_COL_XMP_PATH, - item->xmp_path, DT_CONTROL_CRAWLER_COL_TS_XMP, timestamp_xmp, - DT_CONTROL_CRAWLER_COL_TS_DB, timestamp_db, -1); + item->xmp_path, DT_CONTROL_CRAWLER_COL_TS_XMP, timestamp_xmp, DT_CONTROL_CRAWLER_COL_TS_DB, + timestamp_db, -1); g_free(item->image_path); g_free(item->xmp_path); list_iter = g_list_next(list_iter); @@ -351,8 +351,8 @@ void dt_control_crawler_show_image_list(GList *images) DT_CONTROL_CRAWLER_COL_TS_XMP, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); - column = gtk_tree_view_column_new_with_attributes(_("database timestamp"), gtk_cell_renderer_text_new(), - "text", DT_CONTROL_CRAWLER_COL_TS_DB, NULL); + column = gtk_tree_view_column_new_with_attributes(_("database timestamp"), gtk_cell_renderer_text_new(), "text", + DT_CONTROL_CRAWLER_COL_TS_DB, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); gtk_container_add(GTK_CONTAINER(scroll), tree); @@ -361,8 +361,8 @@ void dt_control_crawler_show_image_list(GList *images) // build a dialog window that contains the list of images GtkWidget *win = dt_ui_main_window(darktable.gui->ui); GtkWidget *dialog = gtk_dialog_new_with_buttons(_("updated xmp sidecar files found"), GTK_WINDOW(win), - GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL, - _("_close"), GTK_RESPONSE_CLOSE, NULL); + GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL, _("_close"), + GTK_RESPONSE_CLOSE, NULL); #ifdef GDK_WINDOWING_QUARTZ dt_osx_disallow_fullscreen(dialog); #endif diff --git a/src/control/jobs.c b/src/control/jobs.c index f32f3831b861..f9c23fe1d9fa 100644 --- a/src/control/jobs.c +++ b/src/control/jobs.c @@ -68,8 +68,8 @@ static inline int dt_control_job_equal(_dt_job_t *j1, _dt_job_t *j2) { if(!j1 || !j2) return 0; if(j1->params_size != 0 && j1->params_size == j2->params_size) - return (j1->execute == j2->execute && j1->state_changed_cb == j2->state_changed_cb - && j1->queue == j2->queue && (memcmp(j1->params, j2->params, j1->params_size) == 0)); + return (j1->execute == j2->execute && j1->state_changed_cb == j2->state_changed_cb && j1->queue == j2->queue + && (memcmp(j1->params, j2->params, j1->params_size) == 0)); return (j1->execute == j2->execute && j1->state_changed_cb == j2->state_changed_cb && j1->queue == j2->queue && (g_strcmp0(j1->description, j2->description) == 0)); } @@ -78,7 +78,7 @@ static void dt_control_job_set_state(_dt_job_t *job, dt_job_state_t state) { if(!job) return; dt_pthread_mutex_lock(&job->state_mutex); - if(state >= DT_JOB_STATE_FINISHED && job->state != DT_JOB_STATE_RUNNING && job->progress) + if(state >= DT_JOB_STATE_FINISHED && job->state != DT_JOB_STATE_RUNNING && job->progress) { dt_control_progress_destroy(darktable.control, job->progress); job->progress = NULL; @@ -319,8 +319,7 @@ static int32_t dt_control_run_job(dt_control_t *control) /* change state to running */ dt_pthread_mutex_lock(&job->wait_mutex); - if(dt_control_job_get_state(job) == DT_JOB_STATE_QUEUED) - dt_control_job_execute(job); + if(dt_control_job_get_state(job) == DT_JOB_STATE_QUEUED) dt_control_job_execute(job); dt_pthread_mutex_unlock(&job->wait_mutex); @@ -466,9 +465,8 @@ int dt_control_add_job(dt_control_t *control, dt_job_queue_t queue_id, _dt_job_t else { // the rest are FIFOs - if(queue_id == DT_JOB_QUEUE_USER_BG || - queue_id == DT_JOB_QUEUE_USER_EXPORT || - queue_id == DT_JOB_QUEUE_SYSTEM_BG) + if(queue_id == DT_JOB_QUEUE_USER_BG || queue_id == DT_JOB_QUEUE_USER_EXPORT + || queue_id == DT_JOB_QUEUE_SYSTEM_BG) job->priority = 0; else job->priority = DT_CONTROL_FG_PRIORITY; @@ -512,7 +510,7 @@ static void *dt_control_work_res(void *ptr) worker_thread_parameters_t *params = (worker_thread_parameters_t *)ptr; dt_control_t *s = params->self; threadid = params->threadid; - char name[16] = {0}; + char name[16] = { 0 }; snprintf(name, sizeof(name), "worker res %d", threadid); dt_pthread_setname(name); free(params); @@ -557,7 +555,7 @@ static void *dt_control_work(void *ptr) worker_thread_parameters_t *params = (worker_thread_parameters_t *)ptr; dt_control_t *control = params->self; threadid = params->threadid; - char name[16] = {0}; + char name[16] = { 0 }; snprintf(name, sizeof(name), "worker %d", threadid); dt_pthread_setname(name); free(params); @@ -582,8 +580,7 @@ void dt_control_job_add_progress(dt_job_t *job, const char *message, gboolean ca { if(!job) return; job->progress = dt_control_progress_create(darktable.control, TRUE, message); - if(cancellable) - dt_control_progress_attach_job(darktable.control, job->progress, job); + if(cancellable) dt_control_progress_attach_job(darktable.control, job->progress, job); } void dt_control_job_set_progress_message(dt_job_t *job, const char *message) diff --git a/src/control/jobs.h b/src/control/jobs.h index 9bc80f2a3b44..c94b9d4149e7 100644 --- a/src/control/jobs.h +++ b/src/control/jobs.h @@ -58,7 +58,8 @@ typedef void (*dt_job_state_change_callback)(dt_job_t *, dt_job_state_t state); typedef void (*dt_job_destroy_callback)(void *data); /** create a new initialized job */ -dt_job_t *dt_control_job_create(dt_job_execute_callback execute, const char *msg, ...) __attribute__((format(printf, 2, 3))); +dt_job_t *dt_control_job_create(dt_job_execute_callback execute, const char *msg, ...) + __attribute__((format(printf, 2, 3))); /** destroy a job object and free its memory. this does NOT remove it from any job queues! */ void dt_control_job_dispose(dt_job_t *job); /** setup a state callback for job. */ diff --git a/src/control/jobs/camera_jobs.c b/src/control/jobs/camera_jobs.c index cf5486137484..6da07acea726 100644 --- a/src/control/jobs/camera_jobs.c +++ b/src/control/jobs/camera_jobs.c @@ -91,8 +91,7 @@ static int32_t dt_camera_capture_job_run(dt_job_t *job) char *expprogram = (char *)dt_camctl_camera_get_property(darktable.camctl, NULL, "expprogram"); /* if fail, lets try fetching mode for cannon */ - if(!expprogram) - expprogram = (char *)dt_camctl_camera_get_property(darktable.camctl, NULL, "autoexposuremode"); + if(!expprogram) expprogram = (char *)dt_camctl_camera_get_property(darktable.camctl, NULL, "autoexposuremode"); /* Fetch all values for shutterspeed and initialize current value */ GList *values = NULL; @@ -109,8 +108,7 @@ static int32_t dt_camera_capture_job_run(dt_job_t *job) values = g_list_append(values, g_strdup(value)); // Check if current values is the same as original value, then lets store item ptr if(strcmp(value, cvalue) == 0) original_value = g_list_last(values)->data; - } while((value = dt_camctl_camera_property_get_next_choice(darktable.camctl, NULL, "shutterspeed")) - != NULL); + } while((value = dt_camctl_camera_property_get_next_choice(darktable.camctl, NULL, "shutterspeed")) != NULL); } else { @@ -249,8 +247,8 @@ static void dt_camera_get_previews_cleanup(void *p) free(params); } -dt_job_t *dt_camera_get_previews_job_create(dt_camera_t *camera, dt_camctl_listener_t *listener, - uint32_t flags, void *data) +dt_job_t *dt_camera_get_previews_job_create(dt_camera_t *camera, dt_camctl_listener_t *listener, uint32_t flags, + void *data) { dt_job_t *job = dt_control_job_create(&dt_camera_get_previews_job_run, "get camera previews job"); if(!job) return NULL; @@ -299,8 +297,7 @@ static const char *_camera_request_image_filename(const dt_camera_t *camera, con /* update import session with orginal filename so that $(FILE_EXTENSION) * and alikes can be expanded. */ dt_import_session_set_filename(shared->session, filename); - if(exif_time) - dt_import_session_set_exif_time(shared->session, *exif_time); + if(exif_time) dt_import_session_set_exif_time(shared->session, *exif_time); file = dt_import_session_filename(shared->session, FALSE); if(file == NULL) return NULL; @@ -312,8 +309,7 @@ static const char *_camera_request_image_path(const dt_camera_t *camera, time_t { struct dt_camera_shared_t *shared; shared = (struct dt_camera_shared_t *)data; - if(exif_time) - dt_import_session_set_exif_time(shared->session, *exif_time); + if(exif_time) dt_import_session_set_exif_time(shared->session, *exif_time); return dt_import_session_path(shared->session, FALSE); } diff --git a/src/control/jobs/control_jobs.c b/src/control/jobs/control_jobs.c index 2daf93c05898..af76f55b2b5d 100644 --- a/src/control/jobs/control_jobs.c +++ b/src/control/jobs/control_jobs.c @@ -113,8 +113,7 @@ static void dt_control_image_enumerator_job_selected_init(dt_control_image_enume } static int32_t _generic_dt_control_fileop_images_job_run(dt_job_t *job, - int32_t (*fileop_callback)(const int32_t, - const int32_t), + int32_t (*fileop_callback)(const int32_t, const int32_t), const char *desc, const char *desc_pl) { dt_control_image_enumerator_t *params = (dt_control_image_enumerator_t *)dt_control_job_get_params(job); @@ -173,7 +172,12 @@ static void dt_control_image_enumerator_cleanup(void *p) free(params); } -typedef enum {PROGRESS_NONE, PROGRESS_SIMPLE, PROGRESS_CANCELLABLE} progress_type_t; +typedef enum +{ + PROGRESS_NONE, + PROGRESS_SIMPLE, + PROGRESS_CANCELLABLE +} progress_type_t; static dt_job_t *dt_control_generic_images_job_create(dt_job_execute_callback execute, const char *message, int flag, gpointer data, progress_type_t progress_type) @@ -312,10 +316,10 @@ static int dt_control_merge_hdr_process(dt_imageio_module_data_t *datai, const c // need to load in the FCxtrans dependency into the dng writer. // for some stupid reason the dng needs this layout wrt cropped // offsets, not globally. - dt_iop_roi_t roi = {0}; + dt_iop_roi_t roi = { 0 }; roi.x = image.crop_x; roi.y = image.crop_y; - for(int j=0;j<6;j++) + for(int j = 0; j < 6; j++) for(int i = 0; i < 6; i++) d->first_xtrans[j][i] = FCxtrans(j, i, &roi, image.buf_dsc.xtrans); d->pixels = calloc(datai->width * datai->height, sizeof(float)); d->weight = calloc(datai->width * datai->height, sizeof(float)); @@ -446,7 +450,8 @@ static int32_t dt_control_merge_hdr_job_run(dt_job_t *job) const uint32_t imgid = GPOINTER_TO_INT(t->data); dt_imageio_export_with_flags(imgid, "unused", &buf, (dt_imageio_module_data_t *)&dat, 1, 0, 0, 1, 0, - "pre:rawprepare", 0, DT_COLORSPACE_NONE, NULL, DT_INTENT_LAST, NULL, NULL, num, total); + "pre:rawprepare", 0, DT_COLORSPACE_NONE, NULL, DT_INTENT_LAST, NULL, NULL, num, + total); t = g_list_delete_link(t, t); @@ -480,7 +485,8 @@ static int32_t dt_control_merge_hdr_job_run(dt_job_t *job) char *c = pathname + strlen(pathname); while(*c != '.' && c > pathname) c--; g_strlcpy(c, "-hdr.dng", sizeof(pathname) - (c - pathname)); - dt_imageio_write_dng(pathname, d.pixels, d.wd, d.ht, exif, exif_len, d.first_filter, (const uint8_t (*)[6])d.first_xtrans, 1.0f); + dt_imageio_write_dng(pathname, d.pixels, d.wd, d.ht, exif, exif_len, d.first_filter, + (const uint8_t(*)[6])d.first_xtrans, 1.0f); free(exif); dt_control_job_set_progress(job, 1.0); @@ -703,32 +709,24 @@ enum _dt_delete_dialog_choice static gboolean _dt_delete_dialog_main_thread(gpointer user_data) { - _dt_delete_modal_dialog_t* modal_dialog = (_dt_delete_modal_dialog_t*)user_data; + _dt_delete_modal_dialog_t *modal_dialog = (_dt_delete_modal_dialog_t *)user_data; dt_pthread_mutex_lock(&modal_dialog->mutex); GtkWidget *dialog = gtk_message_dialog_new( - GTK_WINDOW(dt_ui_main_window(darktable.gui->ui)), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, + GTK_WINDOW(dt_ui_main_window(darktable.gui->ui)), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, - modal_dialog->send_to_trash - ? _("could not send %s to trash%s%s") - : _("could not physically delete %s%s%s"), - modal_dialog->filename, - modal_dialog->error_message != NULL ? ": " : "", + modal_dialog->send_to_trash ? _("could not send %s to trash%s%s") : _("could not physically delete %s%s%s"), + modal_dialog->filename, modal_dialog->error_message != NULL ? ": " : "", modal_dialog->error_message != NULL ? modal_dialog->error_message : ""); - if (modal_dialog->send_to_trash) + if(modal_dialog->send_to_trash) gtk_dialog_add_button(GTK_DIALOG(dialog), _("physically delete"), _DT_DELETE_DIALOG_CHOICE_DELETE); gtk_dialog_add_button(GTK_DIALOG(dialog), _("only remove from the collection"), _DT_DELETE_DIALOG_CHOICE_REMOVE); gtk_dialog_add_button(GTK_DIALOG(dialog), _("skip to next file"), _DT_DELETE_DIALOG_CHOICE_CONTINUE); gtk_dialog_add_button(GTK_DIALOG(dialog), _("stop process"), _DT_DELETE_DIALOG_CHOICE_STOP); - gtk_window_set_title( - GTK_WINDOW(dialog), - modal_dialog->send_to_trash - ? _("trashing error") - : _("deletion error")); + gtk_window_set_title(GTK_WINDOW(dialog), + modal_dialog->send_to_trash ? _("trashing error") : _("deletion error")); modal_dialog->dialog_result = gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); @@ -755,7 +753,7 @@ static gint _dt_delete_file_display_modal_dialog(int send_to_trash, const char * dt_pthread_mutex_lock(&modal_dialog.mutex); gdk_threads_add_idle(_dt_delete_dialog_main_thread, &modal_dialog); - while (modal_dialog.dialog_result == GTK_RESPONSE_NONE) + while(modal_dialog.dialog_result == GTK_RESPONSE_NONE) dt_pthread_cond_wait(&modal_dialog.cond, &modal_dialog.mutex); dt_pthread_mutex_unlock(&modal_dialog.mutex); @@ -772,17 +770,17 @@ static enum _dt_delete_status delete_file_from_disk(const char *filename) GFile *gfile = g_file_new_for_path(filename); int send_to_trash = dt_conf_get_bool("send_to_trash"); - while (delete_status == _DT_DELETE_STATUS_UNKNOWN) + while(delete_status == _DT_DELETE_STATUS_UNKNOWN) { gboolean delete_success = FALSE; GError *gerror = NULL; - if (send_to_trash) + if(send_to_trash) { - #ifdef __APPLE__ +#ifdef __APPLE__ delete_success = dt_osx_file_trash(filename, &gerror); - #else +#else delete_success = g_file_trash(gfile, NULL /*cancellable*/, &gerror); - #endif +#endif } else { @@ -790,41 +788,33 @@ static enum _dt_delete_status delete_file_from_disk(const char *filename) } // Delete is a success or the file does not exists: OK to remove from collection - if (delete_success - || g_error_matches(gerror, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) + if(delete_success || g_error_matches(gerror, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { delete_status = _DT_DELETE_STATUS_OK_TO_REMOVE; } else { const char *filename_display = NULL; - GFileInfo *gfileinfo = g_file_query_info( - gfile, - G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, - G_FILE_QUERY_INFO_NONE, - NULL /*cancellable*/, - NULL /*error*/); - if (gfileinfo != NULL) - filename_display = g_file_info_get_attribute_string( - gfileinfo, - G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME); - - gint res = _dt_delete_file_display_modal_dialog( - send_to_trash, - filename_display == NULL ? filename : filename_display, - gerror == NULL ? NULL : gerror->message); - - if (send_to_trash && res == _DT_DELETE_DIALOG_CHOICE_DELETE) + GFileInfo *gfileinfo = g_file_query_info(gfile, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, + G_FILE_QUERY_INFO_NONE, NULL /*cancellable*/, NULL /*error*/); + if(gfileinfo != NULL) + filename_display = g_file_info_get_attribute_string(gfileinfo, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME); + + gint res = _dt_delete_file_display_modal_dialog(send_to_trash, + filename_display == NULL ? filename : filename_display, + gerror == NULL ? NULL : gerror->message); + + if(send_to_trash && res == _DT_DELETE_DIALOG_CHOICE_DELETE) { // Loop again, this time delete instead of trashing delete_status = _DT_DELETE_STATUS_UNKNOWN; send_to_trash = FALSE; } - else if (res == _DT_DELETE_DIALOG_CHOICE_REMOVE) + else if(res == _DT_DELETE_DIALOG_CHOICE_REMOVE) { delete_status = _DT_DELETE_STATUS_OK_TO_REMOVE; } - else if (res == _DT_DELETE_DIALOG_CHOICE_CONTINUE) + else if(res == _DT_DELETE_DIALOG_CHOICE_CONTINUE) { delete_status = _DT_DELETE_STATUS_SKIP_FILE; } @@ -833,12 +823,10 @@ static enum _dt_delete_status delete_file_from_disk(const char *filename) delete_status = _DT_DELETE_STATUS_STOP_PROCESSING; } } - if (gerror != NULL) - g_error_free(gerror); + if(gerror != NULL) g_error_free(gerror); } - if (gfile != NULL) - g_object_unref(gfile); + if(gfile != NULL) g_object_unref(gfile); return delete_status; } @@ -854,7 +842,7 @@ static int32_t dt_control_delete_images_job_run(dt_job_t *job) guint total = g_list_length(t); char message[512] = { 0 }; double fraction = 0; - if (dt_conf_get_bool("send_to_trash")) + if(dt_conf_get_bool("send_to_trash")) snprintf(message, sizeof(message), ngettext("trashing %d image", "trashing %d images", total), total); else snprintf(message, sizeof(message), ngettext("deleting %d image", "deleting %d images", total), total); @@ -872,7 +860,8 @@ static int32_t dt_control_delete_images_job_run(dt_job_t *job) DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT COUNT(*) FROM main.images WHERE filename IN (SELECT filename FROM " "main.images WHERE id = ?1) AND film_id IN (SELECT film_id FROM main.images WHERE " - "id = ?1)", -1, &stmt, NULL); + "id = ?1)", + -1, &stmt, NULL); while(t) { enum _dt_delete_status delete_status = _DT_DELETE_STATUS_UNKNOWN; @@ -895,8 +884,7 @@ static int32_t dt_control_delete_images_job_run(dt_job_t *job) if(duplicates == 1) { // first check for local copies, never delete a file whose original file is not accessible - if (dt_image_local_copy_reset(imgid)) - goto delete_next_file; + if(dt_image_local_copy_reset(imgid)) goto delete_next_file; snprintf(imgidstr, sizeof(imgidstr), "%d", imgid); _set_remove_flag(imgidstr); @@ -904,8 +892,7 @@ static int32_t dt_control_delete_images_job_run(dt_job_t *job) // there are no further duplicates so we can remove the source data file delete_status = delete_file_from_disk(filename); - if (delete_status != _DT_DELETE_STATUS_OK_TO_REMOVE) - goto delete_next_file; + if(delete_status != _DT_DELETE_STATUS_OK_TO_REMOVE) goto delete_next_file; // all sidecar files - including left-overs - can be deleted; // left-overs can result when previously duplicates have been REMOVED; @@ -926,8 +913,7 @@ static int32_t dt_control_delete_images_job_run(dt_job_t *job) snprintf(c1, pattern + sizeof(pattern) - c1, "%s", *glob_pattern); const gchar *c2 = filename + strlen(filename); while(*c2 != '.' && c2 > filename) c2--; - snprintf(c1 + strlen(*glob_pattern), pattern + sizeof(pattern) - c1 - strlen(*glob_pattern), "%s.xmp", - c2); + snprintf(c1 + strlen(*glob_pattern), pattern + sizeof(pattern) - c1 - strlen(*glob_pattern), "%s.xmp", c2); #ifdef _WIN32 wchar_t *wpattern = g_utf8_to_utf16(pattern, -1, NULL, NULL, NULL); @@ -941,15 +927,13 @@ static int32_t dt_control_delete_images_job_run(dt_job_t *job) char *xmp_filename = g_utf16_to_utf8(data.cFileName, -1, NULL, NULL, NULL); files = g_list_append(files, g_build_filename(dirname, xmp_filename)); g_free(xmp_filename); - } - while(FindNextFileW(handle, &data)); + } while(FindNextFileW(handle, &data)); } #else glob_t globbuf; if(!glob(pattern, 0, NULL, &globbuf)) { - for(size_t i = 0; i < globbuf.gl_pathc; i++) - files = g_list_append(files, g_strdup(globbuf.gl_pathv[i])); + for(size_t i = 0; i < globbuf.gl_pathc; i++) files = g_list_append(files, g_strdup(globbuf.gl_pathv[i])); globfree(&globbuf); } #endif @@ -961,8 +945,7 @@ static int32_t dt_control_delete_images_job_run(dt_job_t *job) while(file_iter != NULL) { delete_status = delete_file_from_disk(file_iter->data); - if (delete_status != _DT_DELETE_STATUS_OK_TO_REMOVE) - break; + if(delete_status != _DT_DELETE_STATUS_OK_TO_REMOVE) break; file_iter = g_list_next(file_iter); } @@ -985,18 +968,16 @@ static int32_t dt_control_delete_images_job_run(dt_job_t *job) delete_file_from_disk(filename); } -delete_next_file: + delete_next_file: #ifdef _WIN32 g_free(dirname); #endif t = g_list_delete_link(t, t); fraction = 1.0 / total; dt_control_job_set_progress(job, fraction); - if (delete_status == _DT_DELETE_STATUS_STOP_PROCESSING) - break; + if(delete_status == _DT_DELETE_STATUS_STOP_PROCESSING) break; } - while (t) - t = g_list_delete_link(t, t); + while(t) t = g_list_delete_link(t, t); params->index = NULL; sqlite3_finalize(stmt); @@ -1091,7 +1072,9 @@ static int32_t dt_control_gpx_apply_job_run(dt_job_t *job) } while((t = g_list_next(t)) != NULL); - dt_control_log(ngettext("applied matched GPX location onto %d image", "applied matched GPX location onto %d images", cntr), cntr); + dt_control_log( + ngettext("applied matched GPX location onto %d image", "applied matched GPX location onto %d images", cntr), + cntr); g_time_zone_unref(tz_camera); g_time_zone_unref(tz_utc); @@ -1144,13 +1127,11 @@ static int32_t dt_control_local_copy_images_job_run(dt_job_t *job) imgid = GPOINTER_TO_INT(t->data); if(is_copy) { - if (dt_image_local_copy_set(imgid) == 0) - dt_tag_attach(tagid, imgid); + if(dt_image_local_copy_set(imgid) == 0) dt_tag_attach(tagid, imgid); } else { - if (dt_image_local_copy_reset(imgid) == 0) - dt_tag_detach(tagid, imgid); + if(dt_image_local_copy_reset(imgid) == 0) dt_tag_detach(tagid, imgid); } t = g_list_delete_link(t, t); @@ -1216,8 +1197,10 @@ static int32_t dt_control_export_job_run(dt_job_t *job) double fraction = 0; // set up the fdata struct - fdata->max_width = (settings->max_width != 0 && w != 0) ? MIN(w, settings->max_width) : MAX(w, settings->max_width); - fdata->max_height = (settings->max_height != 0 && h != 0) ? MIN(h, settings->max_height) : MAX(h, settings->max_height); + fdata->max_width = (settings->max_width != 0 && w != 0) ? MIN(w, settings->max_width) + : MAX(w, settings->max_width); + fdata->max_height = (settings->max_height != 0 && h != 0) ? MIN(h, settings->max_height) + : MAX(h, settings->max_height); g_strlcpy(fdata->style, settings->style, sizeof(fdata->style)); fdata->style_append = settings->style_append; guint num = 0; @@ -1260,7 +1243,8 @@ static int32_t dt_control_export_job_run(dt_job_t *job) { dt_image_cache_read_release(darktable.image_cache, image); if(mstorage->store(mstorage, sdata, imgid, mformat, fdata, num, total, settings->high_quality, - settings->upscale, settings->icc_type, settings->icc_filename, settings->icc_intent) != 0) + settings->upscale, settings->icc_type, settings->icc_filename, settings->icc_intent) + != 0) dt_control_job_cancel(job); } } @@ -1337,10 +1321,9 @@ static dt_job_t *dt_control_gpx_apply_job_create(const gchar *filename, int32_t void dt_control_merge_hdr() { - dt_control_add_job( - darktable.control, DT_JOB_QUEUE_USER_FG, - dt_control_generic_images_job_create(&dt_control_merge_hdr_job_run, N_("merge hdr image"), 0, NULL, - PROGRESS_CANCELLABLE)); + dt_control_add_job(darktable.control, DT_JOB_QUEUE_USER_FG, + dt_control_generic_images_job_create(&dt_control_merge_hdr_job_run, N_("merge hdr image"), 0, + NULL, PROGRESS_CANCELLABLE)); } void dt_control_gpx_apply(const gchar *filename, int32_t filmid, const gchar *tz) @@ -1358,28 +1341,27 @@ void dt_control_duplicate_images() void dt_control_flip_images(const int32_t cw) { - dt_control_add_job( - darktable.control, DT_JOB_QUEUE_USER_FG, - dt_control_generic_images_job_create(&dt_control_flip_images_job_run, N_("flip images"), cw, NULL, - PROGRESS_SIMPLE)); + dt_control_add_job(darktable.control, DT_JOB_QUEUE_USER_FG, + dt_control_generic_images_job_create(&dt_control_flip_images_job_run, N_("flip images"), cw, + NULL, PROGRESS_SIMPLE)); } gboolean dt_control_remove_images() { // get all selected images now, to avoid the set changing during ui interaction - dt_job_t *job = dt_control_generic_images_job_create(&dt_control_remove_images_job_run, N_("remove images"), 0, NULL, - PROGRESS_SIMPLE); + dt_job_t *job = dt_control_generic_images_job_create(&dt_control_remove_images_job_run, N_("remove images"), 0, + NULL, PROGRESS_SIMPLE); if(dt_conf_get_bool("ask_before_remove")) { GtkWidget *dialog; GtkWidget *win = dt_ui_main_window(darktable.gui->ui); int number; - if (dt_view_get_image_to_act_on() != -1) + if(dt_view_get_image_to_act_on() != -1) number = 1; else number = dt_collection_get_selected_count(darktable.collection); - + // Do not show the dialog if no image is selected: if(number == 0) { @@ -1409,8 +1391,8 @@ gboolean dt_control_remove_images() void dt_control_delete_images() { // first get all selected images, to avoid the set changing during ui interaction - dt_job_t *job = dt_control_generic_images_job_create(&dt_control_delete_images_job_run, N_("delete images"), 0, NULL, - PROGRESS_SIMPLE); + dt_job_t *job = dt_control_generic_images_job_create(&dt_control_delete_images_job_run, N_("delete images"), 0, + NULL, PROGRESS_SIMPLE); int send_to_trash = dt_conf_get_bool("send_to_trash"); if(dt_conf_get_bool("ask_before_delete")) { @@ -1418,7 +1400,7 @@ void dt_control_delete_images() GtkWidget *win = dt_ui_main_window(darktable.gui->ui); int number; - if (dt_view_get_image_to_act_on() != -1) + if(dt_view_get_image_to_act_on() != -1) number = 1; else number = dt_collection_get_selected_count(darktable.collection); @@ -1432,11 +1414,10 @@ void dt_control_delete_images() dialog = gtk_message_dialog_new( GTK_WINDOW(win), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, - send_to_trash - ? ngettext("do you really want to send %d selected image to trash?", - "do you really want to send %d selected images to trash?", number) - : ngettext("do you really want to physically delete %d selected image from disk?", - "do you really want to physically delete %d selected images from disk?", number), + send_to_trash ? ngettext("do you really want to send %d selected image to trash?", + "do you really want to send %d selected images to trash?", number) + : ngettext("do you really want to physically delete %d selected image from disk?", + "do you really want to physically delete %d selected images from disk?", number), number); gtk_window_set_title(GTK_WINDOW(dialog), send_to_trash ? _("trash images?") : _("delete images?")); @@ -1744,8 +1725,7 @@ static dt_job_t *dt_control_time_offset_job_create(const long int offset, int im void dt_control_time_offset(const long int offset, int imgid) { - dt_control_add_job(darktable.control, DT_JOB_QUEUE_USER_FG, - dt_control_time_offset_job_create(offset, imgid)); + dt_control_add_job(darktable.control, DT_JOB_QUEUE_USER_FG, dt_control_time_offset_job_create(offset, imgid)); } void dt_control_write_sidecar_files() diff --git a/src/control/progress.c b/src/control/progress.c index ffb3145fbd20..36815558b2c7 100644 --- a/src/control/progress.c +++ b/src/control/progress.c @@ -30,13 +30,14 @@ #ifdef _WIN32 #include <gdk/gdkwin32.h> #ifndef ITaskbarList3_SetProgressValue - #define ITaskbarList3_SetProgressValue(This,hwnd,ullCompleted,ullTotal) (This)->lpVtbl->SetProgressValue(This,hwnd,ullCompleted,ullTotal) +#define ITaskbarList3_SetProgressValue(This, hwnd, ullCompleted, ullTotal) \ + (This)->lpVtbl->SetProgressValue(This, hwnd, ullCompleted, ullTotal) #endif #ifndef ITaskbarList3_SetProgressState - #define ITaskbarList3_SetProgressState(This,hwnd,tbpFlags) (This)->lpVtbl->SetProgressState(This,hwnd,tbpFlags) +#define ITaskbarList3_SetProgressState(This, hwnd, tbpFlags) (This)->lpVtbl->SetProgressState(This, hwnd, tbpFlags) #endif #ifndef ITaskbarList3_HrInit - #define ITaskbarList3_HrInit(This) (This)->lpVtbl->HrInit(This) +#define ITaskbarList3_HrInit(This) (This)->lpVtbl->HrInit(This) #endif #endif @@ -82,17 +83,13 @@ static void global_progress_start(dt_control_t *control, dt_progress_t *progress GVariantBuilder builder; g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}")); - g_variant_builder_add(&builder, "{sv}", "progress", g_variant_new_double(control->progress_system.global_progress)); + g_variant_builder_add(&builder, "{sv}", "progress", + g_variant_new_double(control->progress_system.global_progress)); g_variant_builder_add(&builder, "{sv}", "progress-visible", g_variant_new_boolean(TRUE)); GVariant *params = g_variant_new("(sa{sv})", "application://darktable.desktop", &builder); - g_dbus_connection_emit_signal(darktable.dbus->dbus_connection, - "com.canonical.Unity", - "/darktable", - "com.canonical.Unity.LauncherEntry", - "Update", - params, - &error); + g_dbus_connection_emit_signal(darktable.dbus->dbus_connection, "com.canonical.Unity", "/darktable", + "com.canonical.Unity.LauncherEntry", "Update", params, &error); if(error) { fprintf(stderr, "[progress_create] dbus error: %s\n", error->message); @@ -108,7 +105,8 @@ static void global_progress_start(dt_control_t *control, dt_progress_t *progress if(!control->progress_system.taskbarlist) { void *taskbarlist; - if(CoCreateInstance(&CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, &IID_ITaskbarList3, (void **)&taskbarlist) == S_OK) + if(CoCreateInstance(&CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, &IID_ITaskbarList3, (void **)&taskbarlist) + == S_OK) if(ITaskbarList3_HrInit((ITaskbarList3 *)taskbarlist) == S_OK) control->progress_system.taskbarlist = taskbarlist; } @@ -118,7 +116,8 @@ static void global_progress_start(dt_control_t *control, dt_progress_t *progress HWND hwnd = GDK_WINDOW_HWND(gtk_widget_get_window(dt_ui_main_window(darktable.gui->ui))); if(ITaskbarList3_SetProgressState(control->progress_system.taskbarlist, hwnd, TBPF_NORMAL) != S_OK) fprintf(stderr, "[progress_create] SetProgressState failed\n"); - if(ITaskbarList3_SetProgressValue(control->progress_system.taskbarlist, hwnd, control->progress_system.global_progress * 100, 100) != S_OK) + if(ITaskbarList3_SetProgressValue(control->progress_system.taskbarlist, hwnd, + control->progress_system.global_progress * 100, 100) != S_OK) fprintf(stderr, "[progress_create] SetProgressValue failed\n"); } @@ -143,16 +142,12 @@ static void global_progress_set(dt_control_t *control, dt_progress_t *progress, GVariantBuilder builder; g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}")); - g_variant_builder_add(&builder, "{sv}", "progress", g_variant_new_double(control->progress_system.global_progress)); + g_variant_builder_add(&builder, "{sv}", "progress", + g_variant_new_double(control->progress_system.global_progress)); GVariant *params = g_variant_new("(sa{sv})", "application://darktable.desktop", &builder); - g_dbus_connection_emit_signal(darktable.dbus->dbus_connection, - "com.canonical.Unity", - "/darktable", - "com.canonical.Unity.LauncherEntry", - "Update", - params, - &error); + g_dbus_connection_emit_signal(darktable.dbus->dbus_connection, "com.canonical.Unity", "/darktable", + "com.canonical.Unity.LauncherEntry", "Update", params, &error); if(error) { fprintf(stderr, "[progress_set] dbus error: %s\n", error->message); @@ -167,7 +162,8 @@ static void global_progress_set(dt_control_t *control, dt_progress_t *progress, if(control->progress_system.taskbarlist) { HWND hwnd = GDK_WINDOW_HWND(gtk_widget_get_window(dt_ui_main_window(darktable.gui->ui))); - if(ITaskbarList3_SetProgressValue(control->progress_system.taskbarlist, hwnd, control->progress_system.global_progress * 100, 100) != S_OK) + if(ITaskbarList3_SetProgressValue(control->progress_system.taskbarlist, hwnd, + control->progress_system.global_progress * 100, 100) != S_OK) fprintf(stderr, "[progress_create] SetProgressValue failed\n"); } @@ -205,16 +201,12 @@ static void global_progress_end(dt_control_t *control, dt_progress_t *progress) g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}")); if(control->progress_system.n_progress_bar == 0) g_variant_builder_add(&builder, "{sv}", "progress-visible", g_variant_new_boolean(FALSE)); - g_variant_builder_add(&builder, "{sv}", "progress", g_variant_new_double(control->progress_system.global_progress)); + g_variant_builder_add(&builder, "{sv}", "progress", + g_variant_new_double(control->progress_system.global_progress)); GVariant *params = g_variant_new("(sa{sv})", "application://darktable.desktop", &builder); - g_dbus_connection_emit_signal(darktable.dbus->dbus_connection, - "com.canonical.Unity", - "/darktable", - "com.canonical.Unity.LauncherEntry", - "Update", - params, - &error); + g_dbus_connection_emit_signal(darktable.dbus->dbus_connection, "com.canonical.Unity", "/darktable", + "com.canonical.Unity.LauncherEntry", "Update", params, &error); if(error) { fprintf(stderr, "[progress_destroy] dbus error: %s\n", error->message); @@ -267,13 +259,8 @@ void dt_control_progress_init(struct dt_control_t *control) g_variant_builder_add(&builder, "{sv}", "progress-visible", g_variant_new_boolean(FALSE)); GVariant *params = g_variant_new("(sa{sv})", "application://darktable.desktop", &builder); - g_dbus_connection_emit_signal(darktable.dbus->dbus_connection, - "com.canonical.Unity", - "/darktable", - "com.canonical.Unity.LauncherEntry", - "Update", - params, - &error); + g_dbus_connection_emit_signal(darktable.dbus->dbus_connection, "com.canonical.Unity", "/darktable", + "com.canonical.Unity.LauncherEntry", "Update", params, &error); if(error) { fprintf(stderr, "[progress_init] dbus error: %s\n", error->message); @@ -287,14 +274,13 @@ void dt_control_progress_init(struct dt_control_t *control) #else // _WIN32 - // initializing control->progress_system.taskbarlist in here doesn't work, - // it seems to only succeed after dt_gui_gtk_init +// initializing control->progress_system.taskbarlist in here doesn't work, +// it seems to only succeed after dt_gui_gtk_init #endif // _WIN32 } -dt_progress_t *dt_control_progress_create(dt_control_t *control, gboolean has_progress_bar, - const gchar *message) +dt_progress_t *dt_control_progress_create(dt_control_t *control, gboolean has_progress_bar, const gchar *message) { // create the object dt_progress_t *progress = (dt_progress_t *)calloc(1, sizeof(dt_progress_t)); @@ -313,8 +299,8 @@ dt_progress_t *dt_control_progress_create(dt_control_t *control, gboolean has_pr // tell the gui if(control->progress_system.proxy.module != NULL) - progress->gui_data = control->progress_system.proxy.added(control->progress_system.proxy.module, - has_progress_bar, message); + progress->gui_data + = control->progress_system.proxy.added(control->progress_system.proxy.module, has_progress_bar, message); dt_pthread_mutex_unlock(&control->progress_system.mutex); @@ -354,8 +340,7 @@ void dt_control_progress_make_cancellable(struct dt_control_t *control, dt_progr // tell the gui dt_pthread_mutex_lock(&control->progress_system.mutex); if(control->progress_system.proxy.module != NULL) - control->progress_system.proxy.cancellable(control->progress_system.proxy.module, progress->gui_data, - progress); + control->progress_system.proxy.cancellable(control->progress_system.proxy.module, progress->gui_data, progress); dt_pthread_mutex_unlock(&control->progress_system.mutex); } diff --git a/src/control/progress.h b/src/control/progress.h index 73c78cfa6e19..9fbe8d30e707 100644 --- a/src/control/progress.h +++ b/src/control/progress.h @@ -42,8 +42,7 @@ void dt_control_progress_destroy(struct dt_control_t *control, dt_progress_t *pr void dt_control_progress_make_cancellable(struct dt_control_t *control, dt_progress_t *progress, dt_progress_cancel_callback_t cancel, void *data); /** convenience function to cancel a job when the progress gets cancelled. */ -void dt_control_progress_attach_job(struct dt_control_t *control, dt_progress_t *progress, - struct _dt_job_t *job); +void dt_control_progress_attach_job(struct dt_control_t *control, dt_progress_t *progress, struct _dt_job_t *job); /** cancel the job linked to with dt_control_progress_attach_job(). don't forget to call * dt_control_progress_destroy() afterwards. */ void dt_control_progress_cancel(struct dt_control_t *control, dt_progress_t *progress); diff --git a/src/control/signal.c b/src/control/signal.c index 411c26a75a08..d8138af6734e 100644 --- a/src/control/signal.c +++ b/src/control/signal.c @@ -54,64 +54,64 @@ static GType image_export_arg[] static dt_signal_description _signal_description[DT_SIGNAL_COUNT] = { /* Global signals */ - { "dt-global-mouse-over-image-change", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, - NULL, NULL, FALSE }, // DT_SIGNAL_MOUSE_OVER_IMAGE_CHANGE - - { "dt-control-redraw-all", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, - NULL, NULL, FALSE }, // DT_SIGNAL_CONTROL_REDRAW_ALL - { "dt-control-redraw-center", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, - NULL, NULL, FALSE }, // DT_SIGNAL_CONTROL_REDRAW_CENTER - - { "dt-viewmanager-view-changed", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_generic, 2, - pointer_2arg, NULL, FALSE }, // DT_SIGNAL_VIEWMANAGER_VIEW_CHANGED - { "dt-viewmanager-filmstrip-activate", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, - NULL, NULL, FALSE }, // DT_SIGNAL_VIEWMANAGER_FILMSTRIP_ACTIVATE - - { "dt-collection-changed", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, - NULL, NULL, FALSE }, // DT_SIGNAL_COLLECTION_CHANGED - { "dt-tag-changed", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, - NULL, NULL, FALSE }, // DT_SIGNAL_TAG_CHANGED - { "dt-style-changed", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, - NULL, NULL, FALSE }, // DT_SIGNAL_STYLE_CHANGED - { "dt-filmrolls-changed", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, - NULL, NULL, FALSE }, // DT_SIGNAL_FILMROLLS_CHANGED - { "dt-filmrolls-imported", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__UINT, 1, - uint_arg, NULL, FALSE }, // DT_SIGNAL_FILMROLLS_IMPORTED - { "dt-filmrolls-removed", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, - NULL, NULL, FALSE }, // DT_SIGNAL_FILMROLLS_REMOVED + { "dt-global-mouse-over-image-change", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, NULL, NULL, + FALSE }, // DT_SIGNAL_MOUSE_OVER_IMAGE_CHANGE + + { "dt-control-redraw-all", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, NULL, NULL, + FALSE }, // DT_SIGNAL_CONTROL_REDRAW_ALL + { "dt-control-redraw-center", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, NULL, NULL, + FALSE }, // DT_SIGNAL_CONTROL_REDRAW_CENTER + + { "dt-viewmanager-view-changed", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_generic, 2, pointer_2arg, NULL, + FALSE }, // DT_SIGNAL_VIEWMANAGER_VIEW_CHANGED + { "dt-viewmanager-filmstrip-activate", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, NULL, NULL, + FALSE }, // DT_SIGNAL_VIEWMANAGER_FILMSTRIP_ACTIVATE + + { "dt-collection-changed", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, NULL, NULL, + FALSE }, // DT_SIGNAL_COLLECTION_CHANGED + { "dt-tag-changed", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, NULL, NULL, + FALSE }, // DT_SIGNAL_TAG_CHANGED + { "dt-style-changed", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, NULL, NULL, + FALSE }, // DT_SIGNAL_STYLE_CHANGED + { "dt-filmrolls-changed", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, NULL, NULL, + FALSE }, // DT_SIGNAL_FILMROLLS_CHANGED + { "dt-filmrolls-imported", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__UINT, 1, uint_arg, NULL, + FALSE }, // DT_SIGNAL_FILMROLLS_IMPORTED + { "dt-filmrolls-removed", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, NULL, NULL, + FALSE }, // DT_SIGNAL_FILMROLLS_REMOVED /* Develop related signals */ - { "dt-develop-initialized", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, - NULL, NULL, FALSE }, // DT_SIGNAL_DEVELOP_INITIALIZED - { "dt-develop-mipmap-updated", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, - NULL, NULL, FALSE }, // DT_SIGNAL_DEVELOP_MIPMAP_UPDATED - { "dt-develop-preview-pipe-finished", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, - NULL, NULL, FALSE }, // DT_SIGNAL_DEVELOP_PREVIEW_PIPE_FINISHED - { "dt-develop-ui-pipe-finished", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, - NULL, NULL, FALSE }, // DT_SIGNAL_DEVELOP_UI_PIPE_FINISHED - { "dt-develop-history-change", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, - NULL, NULL, FALSE }, // DT_SIGNAL_HISTORY_CHANGE - { "dt-develop-module-remove", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_generic, 1, - pointer_arg, NULL, TRUE }, // DT_SIGNAL_MODULE_REMOVE - { "dt-develop-image-changed", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, - NULL, NULL, FALSE }, // DT_SIGNAL_DEVELOP_IMAGE_CHANGE - { "dt-control-profile-changed", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, - NULL, NULL, FALSE }, // DT_SIGNAL_CONTROL_PROFILE_CHANGED - { "dt-image-import", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__UINT, 1, - uint_arg, NULL, FALSE }, // DT_SIGNAL_IMAGE_IMPORT - { "dt-image-export-tmpfile", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_generic, 6, - image_export_arg, NULL, TRUE }, // DT_SIGNAL_IMAGE_EXPORT_TMPFILE - { "dt-imageio-storage-change", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, - NULL, NULL, FALSE }, // DT_SIGNAL_IMAGEIO_STORAGE_CHANGE - - - { "dt-preferences-changed", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, - NULL, NULL, FALSE }, // DT_SIGNAL_PREFERENCES_CHANGE - - - { "dt-camera-detected", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, - NULL, NULL, FALSE }, // DT_SIGNAL_CAMERA_DETECTED, + { "dt-develop-initialized", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, NULL, NULL, + FALSE }, // DT_SIGNAL_DEVELOP_INITIALIZED + { "dt-develop-mipmap-updated", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, NULL, NULL, + FALSE }, // DT_SIGNAL_DEVELOP_MIPMAP_UPDATED + { "dt-develop-preview-pipe-finished", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, NULL, NULL, + FALSE }, // DT_SIGNAL_DEVELOP_PREVIEW_PIPE_FINISHED + { "dt-develop-ui-pipe-finished", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, NULL, NULL, + FALSE }, // DT_SIGNAL_DEVELOP_UI_PIPE_FINISHED + { "dt-develop-history-change", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, NULL, NULL, + FALSE }, // DT_SIGNAL_HISTORY_CHANGE + { "dt-develop-module-remove", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_generic, 1, pointer_arg, NULL, + TRUE }, // DT_SIGNAL_MODULE_REMOVE + { "dt-develop-image-changed", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, NULL, NULL, + FALSE }, // DT_SIGNAL_DEVELOP_IMAGE_CHANGE + { "dt-control-profile-changed", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, NULL, NULL, + FALSE }, // DT_SIGNAL_CONTROL_PROFILE_CHANGED + { "dt-image-import", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__UINT, 1, uint_arg, NULL, + FALSE }, // DT_SIGNAL_IMAGE_IMPORT + { "dt-image-export-tmpfile", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_generic, 6, image_export_arg, NULL, + TRUE }, // DT_SIGNAL_IMAGE_EXPORT_TMPFILE + { "dt-imageio-storage-change", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, NULL, NULL, + FALSE }, // DT_SIGNAL_IMAGEIO_STORAGE_CHANGE + + + { "dt-preferences-changed", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, NULL, NULL, + FALSE }, // DT_SIGNAL_PREFERENCES_CHANGE + + + { "dt-camera-detected", NULL, NULL, G_TYPE_NONE, g_cclosure_marshal_VOID__VOID, 0, NULL, NULL, + FALSE }, // DT_SIGNAL_CAMERA_DETECTED, }; @@ -135,14 +135,16 @@ dt_control_signal_t *dt_control_signal_init() ctlsig->sink = g_object_new(_signal_type, NULL); /* create the signals */ - for(int k = 0; k < DT_SIGNAL_COUNT; k++) + for(int k = 0; k < DT_SIGNAL_COUNT; k++) { g_signal_newv(_signal_description[k].name, _signal_type, G_SIGNAL_RUN_LAST, 0, - _signal_description[k].accumulator, _signal_description[k].accu_data, - _signal_description[k].c_marshaller, _signal_description[k].return_type, - _signal_description[k].n_params, _signal_description[k].param_types); - if(_signal_description[k].destructor) { - g_signal_connect_after(G_OBJECT(ctlsig->sink), _signal_description[k].name, _signal_description[k].destructor, NULL); + _signal_description[k].accumulator, _signal_description[k].accu_data, + _signal_description[k].c_marshaller, _signal_description[k].return_type, + _signal_description[k].n_params, _signal_description[k].param_types); + if(_signal_description[k].destructor) + { + g_signal_connect_after(G_OBJECT(ctlsig->sink), _signal_description[k].name, + _signal_description[k].destructor, NULL); } } return ctlsig; @@ -165,7 +167,8 @@ static gboolean _signal_raise(gpointer user_data) return FALSE; } -typedef struct async_com_data { +typedef struct async_com_data +{ GCond end_cond; GMutex end_mutex; gpointer user_data; @@ -173,14 +176,14 @@ typedef struct async_com_data { gboolean _async_com_callback(gpointer data) { - async_com_data *communication = (async_com_data*)data; + async_com_data *communication = (async_com_data *)data; g_mutex_lock(&communication->end_mutex); _signal_raise(communication->user_data); g_cond_signal(&communication->end_cond); g_mutex_unlock(&communication->end_mutex); return FALSE; -} +} void dt_control_signal_raise(const dt_control_signal_t *ctlsig, dt_signal_t signal, ...) { @@ -209,7 +212,7 @@ void dt_control_signal_raise(const dt_control_signal_t *ctlsig, dt_signal_t sign for(int i = 1; i <= signal_description->n_params; i++) { - GType type = signal_description->param_types[i-1]; + GType type = signal_description->param_types[i - 1]; g_value_init(&instance_and_params[i], type); switch(type) { @@ -223,7 +226,8 @@ void dt_control_signal_raise(const dt_control_signal_t *ctlsig, dt_signal_t sign g_value_set_pointer(&instance_and_params[i], va_arg(extra_args, void *)); break; default: - fprintf(stderr, "error: unsupported parameter type `%s' for signal `%s'\n", g_type_name(type), signal_description->name); + fprintf(stderr, "error: unsupported parameter type `%s' for signal `%s'\n", g_type_name(type), + signal_description->name); va_end(extra_args); for(int j = 0; j <= i; j++) g_value_unset(&instance_and_params[j]); free(instance_and_params); @@ -241,17 +245,22 @@ void dt_control_signal_raise(const dt_control_signal_t *ctlsig, dt_signal_t sign if(!signal_description->synchronous) { g_main_context_invoke(NULL, _signal_raise, params); - } else { - if(pthread_equal(darktable.control->gui_thread, pthread_self())) { + } + else + { + if(pthread_equal(darktable.control->gui_thread, pthread_self())) + { _signal_raise(params); - } else { + } + else + { async_com_data communication; g_mutex_init(&communication.end_mutex); g_cond_init(&communication.end_cond); g_mutex_lock(&communication.end_mutex); communication.user_data = params; - g_main_context_invoke(NULL,_async_com_callback,&communication); - g_cond_wait(&communication.end_cond,&communication.end_mutex); + g_main_context_invoke(NULL, _async_com_callback, &communication); + g_cond_wait(&communication.end_cond, &communication.end_mutex); g_mutex_unlock(&communication.end_mutex); g_mutex_clear(&communication.end_mutex); } @@ -267,8 +276,8 @@ void dt_control_signal_connect(const dt_control_signal_t *ctlsig, dt_signal_t si void dt_control_signal_disconnect(const struct dt_control_signal_t *ctlsig, GCallback cb, gpointer user_data) { - g_signal_handlers_disconnect_matched(G_OBJECT(ctlsig->sink), G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, 0, - 0, NULL, cb, user_data); + g_signal_handlers_disconnect_matched(G_OBJECT(ctlsig->sink), G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, 0, 0, + NULL, cb, user_data); } // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh diff --git a/src/control/signal.h b/src/control/signal.h index f777fee4c686..92c89126d278 100644 --- a/src/control/signal.h +++ b/src/control/signal.h @@ -169,8 +169,8 @@ struct dt_control_signal_t *dt_control_signal_init(); /* raises a signal */ void dt_control_signal_raise(const struct dt_control_signal_t *ctlsig, const dt_signal_t signal, ...); /* connects a callback to a signal */ -void dt_control_signal_connect(const struct dt_control_signal_t *ctlsig, const dt_signal_t signal, - GCallback cb, gpointer user_data); +void dt_control_signal_connect(const struct dt_control_signal_t *ctlsig, const dt_signal_t signal, GCallback cb, + gpointer user_data); /* disconnects a callback from a sink */ void dt_control_signal_disconnect(const struct dt_control_signal_t *ctlsig, GCallback cb, gpointer user_data); diff --git a/src/develop/blend.c b/src/develop/blend.c index 26137a402c8b..1a6c30b9812e 100644 --- a/src/develop/blend.c +++ b/src/develop/blend.c @@ -256,16 +256,12 @@ static inline float _blendif_factor(dt_iop_colorspace_type_t cst, const float *i switch(cst) { case iop_cs_Lab: - scaled[DEVELOP_BLENDIF_L_in] = CLAMP_RANGE(input[0] / 100.0f, 0.0f, 1.0f); // L scaled to 0..1 - scaled[DEVELOP_BLENDIF_A_in] - = CLAMP_RANGE((input[1] + 128.0f) / 256.0f, 0.0f, 1.0f); // a scaled to 0..1 - scaled[DEVELOP_BLENDIF_B_in] - = CLAMP_RANGE((input[2] + 128.0f) / 256.0f, 0.0f, 1.0f); // b scaled to 0..1 - scaled[DEVELOP_BLENDIF_L_out] = CLAMP_RANGE(output[0] / 100.0f, 0.0f, 1.0f); // L scaled to 0..1 - scaled[DEVELOP_BLENDIF_A_out] - = CLAMP_RANGE((output[1] + 128.0f) / 256.0f, 0.0f, 1.0f); // a scaled to 0..1 - scaled[DEVELOP_BLENDIF_B_out] - = CLAMP_RANGE((output[2] + 128.0f) / 256.0f, 0.0f, 1.0f); // b scaled to 0..1 + scaled[DEVELOP_BLENDIF_L_in] = CLAMP_RANGE(input[0] / 100.0f, 0.0f, 1.0f); // L scaled to 0..1 + scaled[DEVELOP_BLENDIF_A_in] = CLAMP_RANGE((input[1] + 128.0f) / 256.0f, 0.0f, 1.0f); // a scaled to 0..1 + scaled[DEVELOP_BLENDIF_B_in] = CLAMP_RANGE((input[2] + 128.0f) / 256.0f, 0.0f, 1.0f); // b scaled to 0..1 + scaled[DEVELOP_BLENDIF_L_out] = CLAMP_RANGE(output[0] / 100.0f, 0.0f, 1.0f); // L scaled to 0..1 + scaled[DEVELOP_BLENDIF_A_out] = CLAMP_RANGE((output[1] + 128.0f) / 256.0f, 0.0f, 1.0f); // a scaled to 0..1 + scaled[DEVELOP_BLENDIF_B_out] = CLAMP_RANGE((output[2] + 128.0f) / 256.0f, 0.0f, 1.0f); // b scaled to 0..1 if(blendif & 0x7f00) // do we need to consider LCh ? { @@ -287,9 +283,8 @@ static inline float _blendif_factor(dt_iop_colorspace_type_t cst, const float *i break; case iop_cs_rgb: - scaled[DEVELOP_BLENDIF_GRAY_in] - = CLAMP_RANGE(0.3f * input[0] + 0.59f * input[1] + 0.11f * input[2], 0.0f, - 1.0f); // Gray scaled to 0..1 + scaled[DEVELOP_BLENDIF_GRAY_in] = CLAMP_RANGE(0.3f * input[0] + 0.59f * input[1] + 0.11f * input[2], 0.0f, + 1.0f); // Gray scaled to 0..1 scaled[DEVELOP_BLENDIF_RED_in] = CLAMP_RANGE(input[0], 0.0f, 1.0f); // Red scaled[DEVELOP_BLENDIF_GREEN_in] = CLAMP_RANGE(input[1], 0.0f, 1.0f); // Green scaled[DEVELOP_BLENDIF_BLUE_in] = CLAMP_RANGE(input[2], 0.0f, 1.0f); // Blue @@ -348,7 +343,7 @@ static inline float _blendif_factor(dt_iop_colorspace_type_t cst, const float *i { factor = 1.0f - (scaled[ch] - parameters[4 * ch + 2]) - / fmax(0.01f, parameters[4 * ch + 3] - parameters[4 * ch + 2]); + / fmax(0.01f, parameters[4 * ch + 3] - parameters[4 * ch + 2]); } else factor = 0.0f; @@ -408,7 +403,8 @@ static inline void _blend_noop(const _blend_buffer_desc_t *bd, const float *a, f { for(size_t i = 0, j = 0; j < bd->stride; i++, j += bd->ch) { - for(int k = 0; k < bd->bch; k++) b[j + k] = CLAMP_RANGE(a[j + k], min ? min[k] : -INFINITY, max ? max[k] : INFINITY); + for(int k = 0; k < bd->bch; k++) + b[j + k] = CLAMP_RANGE(a[j + k], min ? min[k] : -INFINITY, max ? max[k] : INFINITY); if(bd->cst != iop_cs_RAW) b[j + 3] = mask[i]; } } @@ -417,8 +413,8 @@ static inline void _blend_noop(const _blend_buffer_desc_t *bd, const float *a, f /* generate blend mask */ static void _blend_make_mask(const _blend_buffer_desc_t *bd, const unsigned int blendif, const float *blendif_parameters, const unsigned int mask_mode, - const unsigned int mask_combine, const float gopacity, const float *a, - const float *b, float *mask) + const unsigned int mask_combine, const float gopacity, const float *a, const float *b, + float *mask) { for(size_t i = 0, j = 0; j < bd->stride; i++, j += bd->ch) { @@ -471,8 +467,7 @@ static void _blend_normal_bounded(const _blend_buffer_desc_t *bd, const float *a { float local_opacity = mask[i]; for(int k = 0; k < bd->bch; k++) - b[j + k] - = CLAMP_RANGE((a[j + k] * (1.0f - local_opacity)) + b[j + k] * local_opacity, min[k], max[k]); + b[j + k] = CLAMP_RANGE((a[j + k] * (1.0f - local_opacity)) + b[j + k] * local_opacity, min[k], max[k]); b[j + 3] = local_opacity; } } @@ -482,15 +477,14 @@ static void _blend_normal_bounded(const _blend_buffer_desc_t *bd, const float *a { float local_opacity = mask[i]; for(int k = 0; k < bd->bch; k++) - b[j + k] - = CLAMP_RANGE((a[j + k] * (1.0f - local_opacity)) + b[j + k] * local_opacity, min[k], max[k]); + b[j + k] = CLAMP_RANGE((a[j + k] * (1.0f - local_opacity)) + b[j + k] * local_opacity, min[k], max[k]); } } } /* normal blend without any clamping */ -static void _blend_normal_unbounded(const _blend_buffer_desc_t *bd, const float *a, float *b, - const float *mask, int flag) +static void _blend_normal_unbounded(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, + int flag) { float max[4] = { 0 }, min[4] = { 0 }; _blend_colorspace_channel_range(bd->cst, min, max); @@ -526,8 +520,7 @@ static void _blend_normal_unbounded(const _blend_buffer_desc_t *bd, const float for(size_t i = 0, j = 0; j < bd->stride; i++, j += bd->ch) { float local_opacity = mask[i]; - for(int k = 0; k < bd->bch; k++) - b[j + k] = (a[j + k] * (1.0f - local_opacity)) + b[j + k] * local_opacity; + for(int k = 0; k < bd->bch; k++) b[j + k] = (a[j + k] * (1.0f - local_opacity)) + b[j + k] * local_opacity; b[j + 3] = local_opacity; } } @@ -536,15 +529,13 @@ static void _blend_normal_unbounded(const _blend_buffer_desc_t *bd, const float for(size_t i = 0, j = 0; j < bd->stride; i++, j += bd->ch) { float local_opacity = mask[i]; - for(int k = 0; k < bd->bch; k++) - b[j + k] = (a[j + k] * (1.0f - local_opacity)) + b[j + k] * local_opacity; + for(int k = 0; k < bd->bch; k++) b[j + k] = (a[j + k] * (1.0f - local_opacity)) + b[j + k] * local_opacity; } } } /* lighten */ -static void _blend_lighten(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_lighten(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { float max[4] = { 0 }, min[4] = { 0 }; _blend_colorspace_channel_range(bd->cst, min, max); @@ -559,8 +550,8 @@ static void _blend_lighten(const _blend_buffer_desc_t *bd, const float *a, float _blend_Lab_scale(&b[j], tb); tbo = tb[0]; - tb[0] = CLAMP_RANGE(ta[0] * (1.0f - local_opacity) + (ta[0] > tb[0] ? ta[0] : tb[0]) * local_opacity, - min[0], max[0]); + tb[0] = CLAMP_RANGE(ta[0] * (1.0f - local_opacity) + (ta[0] > tb[0] ? ta[0] : tb[0]) * local_opacity, min[0], + max[0]); if(flag == 0) { @@ -603,8 +594,7 @@ static void _blend_lighten(const _blend_buffer_desc_t *bd, const float *a, float } /* darken */ -static void _blend_darken(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_darken(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { float max[4] = { 0 }, min[4] = { 0 }; _blend_colorspace_channel_range(bd->cst, min, max); @@ -619,8 +609,8 @@ static void _blend_darken(const _blend_buffer_desc_t *bd, const float *a, float _blend_Lab_scale(&b[j], tb); tbo = tb[0]; - tb[0] = CLAMP_RANGE(ta[0] * (1.0f - local_opacity) + (ta[0] < tb[0] ? ta[0] : tb[0]) * local_opacity, - min[0], max[0]); + tb[0] = CLAMP_RANGE(ta[0] * (1.0f - local_opacity) + (ta[0] < tb[0] ? ta[0] : tb[0]) * local_opacity, min[0], + max[0]); if(flag == 0) { @@ -664,8 +654,7 @@ static void _blend_darken(const _blend_buffer_desc_t *bd, const float *a, float } /* multiply */ -static void _blend_multiply(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_multiply(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { float max[4] = { 0 }, min[4] = { 0 }; _blend_colorspace_channel_range(bd->cst, min, max); @@ -691,21 +680,17 @@ static void _blend_multiply(const _blend_buffer_desc_t *bd, const float *a, floa { if(ta[0] > 0.01f) { - tb[1] - = CLAMP_RANGE(ta[1] * (1.0f - local_opacity) + (ta[1] + tb[1]) * tb[0] / ta[0] * local_opacity, - min[1], max[1]); - tb[2] - = CLAMP_RANGE(ta[2] * (1.0f - local_opacity) + (ta[2] + tb[2]) * tb[0] / ta[0] * local_opacity, - min[2], max[2]); + tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity) + (ta[1] + tb[1]) * tb[0] / ta[0] * local_opacity, + min[1], max[1]); + tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity) + (ta[2] + tb[2]) * tb[0] / ta[0] * local_opacity, + min[2], max[2]); } else { - tb[1] - = CLAMP_RANGE(ta[1] * (1.0f - local_opacity) + (ta[1] + tb[1]) * tb[0] / 0.01f * local_opacity, - min[1], max[1]); - tb[2] - = CLAMP_RANGE(ta[2] * (1.0f - local_opacity) + (ta[2] + tb[2]) * tb[0] / 0.01f * local_opacity, - min[2], max[2]); + tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity) + (ta[1] + tb[1]) * tb[0] / 0.01f * local_opacity, + min[1], max[1]); + tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity) + (ta[2] + tb[2]) * tb[0] / 0.01f * local_opacity, + min[2], max[2]); } } else @@ -724,8 +709,8 @@ static void _blend_multiply(const _blend_buffer_desc_t *bd, const float *a, floa { float local_opacity = mask[i]; for(int k = 0; k < bd->bch; k++) - b[j + k] = CLAMP_RANGE( - ((a[j + k] * (1.0f - local_opacity)) + ((a[j + k] * b[j + k]) * local_opacity)), min[k], max[k]); + b[j + k] = CLAMP_RANGE(((a[j + k] * (1.0f - local_opacity)) + ((a[j + k] * b[j + k]) * local_opacity)), + min[k], max[k]); b[j + 3] = local_opacity; } } @@ -736,16 +721,15 @@ static void _blend_multiply(const _blend_buffer_desc_t *bd, const float *a, floa float local_opacity = mask[i]; for(int k = 0; k < bd->bch; k++) - b[j + k] = CLAMP_RANGE( - ((a[j + k] * (1.0f - local_opacity)) + ((a[j + k] * b[j + k]) * local_opacity)), min[k], max[k]); + b[j + k] = CLAMP_RANGE(((a[j + k] * (1.0f - local_opacity)) + ((a[j + k] * b[j + k]) * local_opacity)), + min[k], max[k]); } } // return (a*b); } /* average */ -static void _blend_average(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_average(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { float max[4] = { 0 }, min[4] = { 0 }; _blend_colorspace_channel_range(bd->cst, min, max); @@ -759,15 +743,14 @@ static void _blend_average(const _blend_buffer_desc_t *bd, const float *a, float _blend_Lab_scale(&a[j], ta); _blend_Lab_scale(&b[j], tb); - tb[0] = CLAMP_RANGE(ta[0] * (1.0f - local_opacity) + (ta[0] + tb[0]) / 2.0f * local_opacity, min[0], - max[0]); + tb[0] = CLAMP_RANGE(ta[0] * (1.0f - local_opacity) + (ta[0] + tb[0]) / 2.0f * local_opacity, min[0], max[0]); if(flag == 0) { - tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity) + (ta[1] + tb[1]) / 2.0f * local_opacity, min[1], - max[1]); - tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity) + (ta[2] + tb[2]) / 2.0f * local_opacity, min[2], - max[2]); + tb[1] + = CLAMP_RANGE(ta[1] * (1.0f - local_opacity) + (ta[1] + tb[1]) / 2.0f * local_opacity, min[1], max[1]); + tb[2] + = CLAMP_RANGE(ta[2] * (1.0f - local_opacity) + (ta[2] + tb[2]) / 2.0f * local_opacity, min[2], max[2]); } else { @@ -785,8 +768,8 @@ static void _blend_average(const _blend_buffer_desc_t *bd, const float *a, float { float local_opacity = mask[i]; for(int k = 0; k < bd->bch; k++) - b[j + k] = CLAMP_RANGE( - a[j + k] * (1.0f - local_opacity) + (a[j + k] + b[j + k]) / 2.0f * local_opacity, min[k], max[k]); + b[j + k] = CLAMP_RANGE(a[j + k] * (1.0f - local_opacity) + (a[j + k] + b[j + k]) / 2.0f * local_opacity, + min[k], max[k]); b[j + 3] = local_opacity; } @@ -797,8 +780,8 @@ static void _blend_average(const _blend_buffer_desc_t *bd, const float *a, float { float local_opacity = mask[i]; for(int k = 0; k < bd->bch; k++) - b[j + k] = CLAMP_RANGE( - a[j + k] * (1.0f - local_opacity) + (a[j + k] + b[j + k]) / 2.0f * local_opacity, min[k], max[k]); + b[j + k] = CLAMP_RANGE(a[j + k] * (1.0f - local_opacity) + (a[j + k] + b[j + k]) / 2.0f * local_opacity, + min[k], max[k]); } } // return (a+b)/2.0; @@ -819,15 +802,14 @@ static void _blend_add(const _blend_buffer_desc_t *bd, const float *a, float *b, _blend_Lab_scale(&a[j], ta); _blend_Lab_scale(&b[j], tb); - tb[0] = CLAMP_RANGE((ta[0] * (1.0f - local_opacity)) + (((ta[0] + tb[0])) * local_opacity), min[0], - max[0]); + tb[0] = CLAMP_RANGE((ta[0] * (1.0f - local_opacity)) + (((ta[0] + tb[0])) * local_opacity), min[0], max[0]); if(flag == 0) { - tb[1] = CLAMP_RANGE((ta[1] * (1.0f - local_opacity)) + (((ta[1] + tb[1])) * local_opacity), min[1], - max[1]); - tb[2] = CLAMP_RANGE((ta[2] * (1.0f - local_opacity)) + (((ta[2] + tb[2])) * local_opacity), min[2], - max[2]); + tb[1] + = CLAMP_RANGE((ta[1] * (1.0f - local_opacity)) + (((ta[1] + tb[1])) * local_opacity), min[1], max[1]); + tb[2] + = CLAMP_RANGE((ta[2] * (1.0f - local_opacity)) + (((ta[2] + tb[2])) * local_opacity), min[2], max[2]); } else { @@ -845,8 +827,8 @@ static void _blend_add(const _blend_buffer_desc_t *bd, const float *a, float *b, { float local_opacity = mask[i]; for(int k = 0; k < bd->bch; k++) - b[j + k] = CLAMP_RANGE( - (a[j + k] * (1.0f - local_opacity)) + (((a[j + k] + b[j + k])) * local_opacity), min[k], max[k]); + b[j + k] = CLAMP_RANGE((a[j + k] * (1.0f - local_opacity)) + (((a[j + k] + b[j + k])) * local_opacity), + min[k], max[k]); b[j + 3] = local_opacity; } } @@ -856,8 +838,8 @@ static void _blend_add(const _blend_buffer_desc_t *bd, const float *a, float *b, { float local_opacity = mask[i]; for(int k = 0; k < bd->bch; k++) - b[j + k] = CLAMP_RANGE( - (a[j + k] * (1.0f - local_opacity)) + (((a[j + k] + b[j + k])) * local_opacity), min[k], max[k]); + b[j + k] = CLAMP_RANGE((a[j + k] * (1.0f - local_opacity)) + (((a[j + k] + b[j + k])) * local_opacity), + min[k], max[k]); } } /* @@ -868,8 +850,7 @@ static void _blend_add(const _blend_buffer_desc_t *bd, const float *a, float *b, } /* substract */ -static void _blend_substract(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_substract(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { float max[4] = { 0 }, min[4] = { 0 }; _blend_colorspace_channel_range(bd->cst, min, max); @@ -889,12 +870,12 @@ static void _blend_substract(const _blend_buffer_desc_t *bd, const float *a, flo if(flag == 0) { - tb[1] = CLAMP_RANGE(((ta[1] * (1.0f - local_opacity)) - + (((tb[1] + ta[1]) - (fabs(min[1] + max[1]))) * local_opacity)), - min[1], max[1]); - tb[2] = CLAMP_RANGE(((ta[2] * (1.0f - local_opacity)) - + (((tb[2] + ta[2]) - (fabs(min[2] + max[2]))) * local_opacity)), - min[2], max[2]); + tb[1] = CLAMP_RANGE( + ((ta[1] * (1.0f - local_opacity)) + (((tb[1] + ta[1]) - (fabs(min[1] + max[1]))) * local_opacity)), + min[1], max[1]); + tb[2] = CLAMP_RANGE( + ((ta[2] * (1.0f - local_opacity)) + (((tb[2] + ta[2]) - (fabs(min[2] + max[2]))) * local_opacity)), + min[2], max[2]); } else { @@ -937,8 +918,7 @@ static void _blend_substract(const _blend_buffer_desc_t *bd, const float *a, flo } /* difference (deprecated) */ -static void _blend_difference(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_difference(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { float max[4] = { 0 }, min[4] = { 0 }; _blend_colorspace_channel_range(bd->cst, min, max); @@ -1098,8 +1078,7 @@ static void _blend_difference2(const _blend_buffer_desc_t *bd, const float *a, f } /* screen */ -static void _blend_screen(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_screen(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { float max[4] = { 0 }, min[4] = { 0 }; _blend_colorspace_channel_range(bd->cst, min, max); @@ -1117,28 +1096,27 @@ static void _blend_screen(const _blend_buffer_desc_t *bd, const float *a, float la = CLAMP_RANGE(ta[0] + fabs(min[0]), lmin, lmax); lb = CLAMP_RANGE(tb[0] + fabs(min[0]), lmin, lmax); - tb[0] - = CLAMP_RANGE((la * (1.0 - local_opacity)) + (((lmax - (lmax - la) * (lmax - lb))) * local_opacity), - lmin, lmax) - fabs(min[0]); + tb[0] = CLAMP_RANGE((la * (1.0 - local_opacity)) + (((lmax - (lmax - la) * (lmax - lb))) * local_opacity), + lmin, lmax) - fabs(min[0]); if(flag == 0) { if(ta[0] > 0.01f) { tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity) - + 0.5f * (ta[1] + tb[1]) * tb[0] / ta[0] * local_opacity, + + 0.5f * (ta[1] + tb[1]) * tb[0] / ta[0] * local_opacity, min[1], max[1]); tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity) - + 0.5f * (ta[2] + tb[2]) * tb[0] / ta[0] * local_opacity, + + 0.5f * (ta[2] + tb[2]) * tb[0] / ta[0] * local_opacity, min[2], max[2]); } else { tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity) - + 0.5f * (ta[1] + tb[1]) * tb[0] / 0.01f * local_opacity, + + 0.5f * (ta[1] + tb[1]) * tb[0] / 0.01f * local_opacity, min[1], max[1]); tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity) - + 0.5f * (ta[2] + tb[2]) * tb[0] / 0.01f * local_opacity, + + 0.5f * (ta[2] + tb[2]) * tb[0] / 0.01f * local_opacity, min[2], max[2]); } } @@ -1164,9 +1142,9 @@ static void _blend_screen(const _blend_buffer_desc_t *bd, const float *a, float la = CLAMP_RANGE(a[j + k] + fabs(min[k]), lmin, lmax); lb = CLAMP_RANGE(b[j + k] + fabs(min[k]), lmin, lmax); - b[j + k] = CLAMP_RANGE((la * (1.0f - local_opacity)) - + (((lmax - (lmax - la) * (lmax - lb))) * local_opacity), - lmin, lmax) - fabs(min[k]); + b[j + k] + = CLAMP_RANGE((la * (1.0f - local_opacity)) + (((lmax - (lmax - la) * (lmax - lb))) * local_opacity), + lmin, lmax) - fabs(min[k]); } b[j + 3] = local_opacity; } @@ -1183,9 +1161,9 @@ static void _blend_screen(const _blend_buffer_desc_t *bd, const float *a, float la = CLAMP_RANGE(a[j + k] + fabs(min[k]), lmin, lmax); lb = CLAMP_RANGE(b[j + k] + fabs(min[k]), lmin, lmax); - b[j + k] = CLAMP_RANGE((la * (1.0f - local_opacity)) - + (((lmax - (lmax - la) * (lmax - lb))) * local_opacity), - lmin, lmax) - fabs(min[k]); + b[j + k] + = CLAMP_RANGE((la * (1.0f - local_opacity)) + (((lmax - (lmax - la) * (lmax - lb))) * local_opacity), + lmin, lmax) - fabs(min[k]); } } } @@ -1197,8 +1175,7 @@ static void _blend_screen(const _blend_buffer_desc_t *bd, const float *a, float } /* overlay */ -static void _blend_overlay(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_overlay(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { float max[4] = { 0 }, min[4] = { 0 }; _blend_colorspace_channel_range(bd->cst, min, max); @@ -1228,20 +1205,16 @@ static void _blend_overlay(const _blend_buffer_desc_t *bd, const float *a, float { if(ta[0] > 0.01f) { - tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity2) - + (ta[1] + tb[1]) * tb[0] / ta[0] * local_opacity2, + tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity2) + (ta[1] + tb[1]) * tb[0] / ta[0] * local_opacity2, min[1], max[1]); - tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity2) - + (ta[2] + tb[2]) * tb[0] / ta[0] * local_opacity2, + tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity2) + (ta[2] + tb[2]) * tb[0] / ta[0] * local_opacity2, min[2], max[2]); } else { - tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity2) - + (ta[1] + tb[1]) * tb[0] / 0.01f * local_opacity2, + tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity2) + (ta[1] + tb[1]) * tb[0] / 0.01f * local_opacity2, min[1], max[1]); - tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity2) - + (ta[2] + tb[2]) * tb[0] / 0.01f * local_opacity2, + tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity2) + (ta[2] + tb[2]) * tb[0] / 0.01f * local_opacity2, min[2], max[2]); } } @@ -1311,8 +1284,7 @@ static void _blend_overlay(const _blend_buffer_desc_t *bd, const float *a, float } /* softlight */ -static void _blend_softlight(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_softlight(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { float max[4] = { 0 }, min[4] = { 0 }; @@ -1342,20 +1314,16 @@ static void _blend_softlight(const _blend_buffer_desc_t *bd, const float *a, flo { if(ta[0] > 0.01f) { - tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity2) - + (ta[1] + tb[1]) * tb[0] / ta[0] * local_opacity2, + tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity2) + (ta[1] + tb[1]) * tb[0] / ta[0] * local_opacity2, min[1], max[1]); - tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity2) - + (ta[2] + tb[2]) * tb[0] / ta[0] * local_opacity2, + tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity2) + (ta[2] + tb[2]) * tb[0] / ta[0] * local_opacity2, min[2], max[2]); } else { - tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity2) - + (ta[1] + tb[1]) * tb[0] / 0.01f * local_opacity2, + tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity2) + (ta[1] + tb[1]) * tb[0] / 0.01f * local_opacity2, min[1], max[1]); - tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity2) - + (ta[2] + tb[2]) * tb[0] / 0.01f * local_opacity2, + tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity2) + (ta[2] + tb[2]) * tb[0] / 0.01f * local_opacity2, min[2], max[2]); } } @@ -1422,8 +1390,7 @@ static void _blend_softlight(const _blend_buffer_desc_t *bd, const float *a, flo } /* hardlight */ -static void _blend_hardlight(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_hardlight(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { float max[4] = { 0 }, min[4] = { 0 }; _blend_colorspace_channel_range(bd->cst, min, max); @@ -1453,20 +1420,16 @@ static void _blend_hardlight(const _blend_buffer_desc_t *bd, const float *a, flo { if(ta[0] > 0.01f) { - tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity2) - + (ta[1] + tb[1]) * tb[0] / ta[0] * local_opacity2, + tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity2) + (ta[1] + tb[1]) * tb[0] / ta[0] * local_opacity2, min[1], max[1]); - tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity2) - + (ta[2] + tb[2]) * tb[0] / ta[0] * local_opacity2, + tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity2) + (ta[2] + tb[2]) * tb[0] / ta[0] * local_opacity2, min[2], max[2]); } else { - tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity2) - + (ta[1] + tb[1]) * tb[0] / 0.01f * local_opacity2, + tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity2) + (ta[1] + tb[1]) * tb[0] / 0.01f * local_opacity2, min[1], max[1]); - tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity2) - + (ta[2] + tb[2]) * tb[0] / 0.01f * local_opacity2, + tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity2) + (ta[2] + tb[2]) * tb[0] / 0.01f * local_opacity2, min[2], max[2]); } } @@ -1536,8 +1499,7 @@ static void _blend_hardlight(const _blend_buffer_desc_t *bd, const float *a, flo } /* vividlight */ -static void _blend_vividlight(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_vividlight(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { float max[4] = { 0 }, min[4] = { 0 }; _blend_colorspace_channel_range(bd->cst, min, max); @@ -1561,27 +1523,23 @@ static void _blend_vividlight(const _blend_buffer_desc_t *bd, const float *a, fl tb[0] = CLAMP_RANGE(((la * (1.0 - local_opacity2)) + ((lb > halfmax) ? (lb >= lmax ? lmax : la / (doublemax * (lmax - lb))) : (lb <= lmin ? lmin : lmax - (lmax - la) / (doublemax * lb))) - * local_opacity2), + * local_opacity2), lmin, lmax) - fabs(min[0]); if(flag == 0) { if(ta[0] > 0.01f) { - tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity2) - + (ta[1] + tb[1]) * tb[0] / ta[0] * local_opacity2, + tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity2) + (ta[1] + tb[1]) * tb[0] / ta[0] * local_opacity2, min[1], max[1]); - tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity2) - + (ta[2] + tb[2]) * tb[0] / ta[0] * local_opacity2, + tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity2) + (ta[2] + tb[2]) * tb[0] / ta[0] * local_opacity2, min[2], max[2]); } else { - tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity2) - + (ta[1] + tb[1]) * tb[0] / 0.01f * local_opacity2, + tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity2) + (ta[1] + tb[1]) * tb[0] / 0.01f * local_opacity2, min[1], max[1]); - tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity2) - + (ta[2] + tb[2]) * tb[0] / 0.01f * local_opacity2, + tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity2) + (ta[2] + tb[2]) * tb[0] / 0.01f * local_opacity2, min[2], max[2]); } } @@ -1610,12 +1568,11 @@ static void _blend_vividlight(const _blend_buffer_desc_t *bd, const float *a, fl halfmax = lmax / 2.0f; doublemax = lmax * 2.0f; - b[j + k] - = CLAMP_RANGE(((la * (1.0f - local_opacity2)) - + ((lb > halfmax) ? (lb >= lmax ? lmax : la / (doublemax * (lmax - lb))) - : (lb <= lmin ? lmin : lmax - (lmax - la) / (doublemax * lb))) - * local_opacity2), - lmin, lmax) - fabs(min[k]); + b[j + k] = CLAMP_RANGE(((la * (1.0f - local_opacity2)) + + ((lb > halfmax) ? (lb >= lmax ? lmax : la / (doublemax * (lmax - lb))) + : (lb <= lmin ? lmin : lmax - (lmax - la) / (doublemax * lb))) + * local_opacity2), + lmin, lmax) - fabs(min[k]); } b[j + 3] = local_opacity; } @@ -1635,12 +1592,11 @@ static void _blend_vividlight(const _blend_buffer_desc_t *bd, const float *a, fl halfmax = lmax / 2.0f; doublemax = lmax * 2.0f; - b[j + k] - = CLAMP_RANGE(((la * (1.0f - local_opacity2)) - + ((lb > halfmax) ? (lb >= lmax ? lmax : la / (doublemax * (lmax - lb))) - : (lb <= lmin ? lmin : lmax - (lmax - la) / (doublemax * lb))) - * local_opacity2), - lmin, lmax) - fabs(min[k]); + b[j + k] = CLAMP_RANGE(((la * (1.0f - local_opacity2)) + + ((lb > halfmax) ? (lb >= lmax ? lmax : la / (doublemax * (lmax - lb))) + : (lb <= lmin ? lmin : lmax - (lmax - la) / (doublemax * lb))) + * local_opacity2), + lmin, lmax) - fabs(min[k]); } } } @@ -1675,27 +1631,23 @@ static void _blend_linearlight(const _blend_buffer_desc_t *bd, const float *a, f lb = CLAMP_RANGE(tb[0] + fabs(min[0]), lmin, lmax); doublemax = lmax * 2.0f; - tb[0] = CLAMP_RANGE(((la * (1.0 - local_opacity2)) + (la + doublemax * lb - lmax) * local_opacity2), - lmin, lmax) - fabs(min[0]); + tb[0] = CLAMP_RANGE(((la * (1.0 - local_opacity2)) + (la + doublemax * lb - lmax) * local_opacity2), lmin, + lmax) - fabs(min[0]); if(flag == 0) { if(ta[0] > 0.01f) { - tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity2) - + (ta[1] + tb[1]) * tb[0] / ta[0] * local_opacity2, + tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity2) + (ta[1] + tb[1]) * tb[0] / ta[0] * local_opacity2, min[1], max[1]); - tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity2) - + (ta[2] + tb[2]) * tb[0] / ta[0] * local_opacity2, + tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity2) + (ta[2] + tb[2]) * tb[0] / ta[0] * local_opacity2, min[2], max[2]); } else { - tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity2) - + (ta[1] + tb[1]) * tb[0] / 0.01f * local_opacity2, + tb[1] = CLAMP_RANGE(ta[1] * (1.0f - local_opacity2) + (ta[1] + tb[1]) * tb[0] / 0.01f * local_opacity2, min[1], max[1]); - tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity2) - + (ta[2] + tb[2]) * tb[0] / 0.01f * local_opacity2, + tb[2] = CLAMP_RANGE(ta[2] * (1.0f - local_opacity2) + (ta[2] + tb[2]) * tb[0] / 0.01f * local_opacity2, min[2], max[2]); } } @@ -1723,9 +1675,8 @@ static void _blend_linearlight(const _blend_buffer_desc_t *bd, const float *a, f lb = CLAMP_RANGE(b[j + k] + fabs(min[k]), lmin, lmax); doublemax = lmax * 2.0f; - b[j + k] - = CLAMP_RANGE(((la * (1.0f - local_opacity2)) + (la + doublemax * lb - lmax) * local_opacity2), - lmin, lmax) - fabs(min[k]); + b[j + k] = CLAMP_RANGE(((la * (1.0f - local_opacity2)) + (la + doublemax * lb - lmax) * local_opacity2), + lmin, lmax) - fabs(min[k]); } b[j + 3] = local_opacity; } @@ -1744,9 +1695,8 @@ static void _blend_linearlight(const _blend_buffer_desc_t *bd, const float *a, f lb = CLAMP_RANGE(b[j + k] + fabs(min[k]), lmin, lmax); doublemax = lmax * 2.0f; - b[j + k] - = CLAMP_RANGE(((la * (1.0f - local_opacity2)) + (la + doublemax * lb - lmax) * local_opacity2), - lmin, lmax) - fabs(min[k]); + b[j + k] = CLAMP_RANGE(((la * (1.0f - local_opacity2)) + (la + doublemax * lb - lmax) * local_opacity2), + lmin, lmax) - fabs(min[k]); } } } @@ -1760,8 +1710,7 @@ static void _blend_linearlight(const _blend_buffer_desc_t *bd, const float *a, f } /* pinlight */ -static void _blend_pinlight(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_pinlight(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { float max[4] = { 0 }, min[4] = { 0 }; _blend_colorspace_channel_range(bd->cst, min, max); @@ -1783,8 +1732,8 @@ static void _blend_pinlight(const _blend_buffer_desc_t *bd, const float *a, floa doublemax = lmax * 2.0f; tb[0] = CLAMP_RANGE(((la * (1.0f - local_opacity2)) - + ((lb > halfmax) ? (fmax(la, doublemax * (lb - halfmax))) - : (fmin(la, doublemax * lb))) * local_opacity2), + + ((lb > halfmax) ? (fmax(la, doublemax * (lb - halfmax))) : (fmin(la, doublemax * lb))) + * local_opacity2), lmin, lmax) - fabs(min[0]); tb[1] = CLAMP_RANGE(ta[1], min[1], max[1]); @@ -1849,8 +1798,7 @@ static void _blend_pinlight(const _blend_buffer_desc_t *bd, const float *a, floa } /* lightness blend */ -static void _blend_lightness(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_lightness(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { float max[4] = { 0 }, min[4] = { 0 }; _blend_colorspace_channel_range(bd->cst, min, max); @@ -1898,13 +1846,12 @@ static void _blend_lightness(const _blend_buffer_desc_t *bd, const float *a, flo b[j + 3] = local_opacity; } } - else /* if(bd->cst == iop_cs_RAW) */ + else /* if(bd->cst == iop_cs_RAW) */ _blend_noop(bd, a, b, mask, min, max); // Noop for Raw } /* chroma blend */ -static void _blend_chroma(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_chroma(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { float max[4] = { 0 }, min[4] = { 0 }; _blend_colorspace_channel_range(bd->cst, min, max); @@ -1959,7 +1906,7 @@ static void _blend_chroma(const _blend_buffer_desc_t *bd, const float *a, float b[j + 3] = local_opacity; } } - else /* if(bd->cst == iop_cs_RAW) */ + else /* if(bd->cst == iop_cs_RAW) */ _blend_noop(bd, a, b, mask, min, max); // Noop for Raw } @@ -2025,7 +1972,7 @@ static void _blend_hue(const _blend_buffer_desc_t *bd, const float *a, float *b, b[j + 3] = local_opacity; } } - else /* if(bd->cst == iop_cs_RAW) */ + else /* if(bd->cst == iop_cs_RAW) */ _blend_noop(bd, a, b, mask, min, max); // Noop for Raw } @@ -2094,7 +2041,7 @@ static void _blend_color(const _blend_buffer_desc_t *bd, const float *a, float * b[j + 3] = local_opacity; } } - else /* if(bd->cst == iop_cs_RAW) */ + else /* if(bd->cst == iop_cs_RAW) */ _blend_noop(bd, a, b, mask, min, max); // Noop for Raw } @@ -2163,13 +2110,12 @@ static void _blend_coloradjust(const _blend_buffer_desc_t *bd, const float *a, f b[j + 3] = local_opacity; } } - else /* if(bd->cst == iop_cs_RAW) */ + else /* if(bd->cst == iop_cs_RAW) */ _blend_noop(bd, a, b, mask, min, max); // Noop for Raw } /* inverse blend */ -static void _blend_inverse(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_inverse(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { float max[4] = { 0 }, min[4] = { 0 }; _blend_colorspace_channel_range(bd->cst, min, max); @@ -2206,8 +2152,7 @@ static void _blend_inverse(const _blend_buffer_desc_t *bd, const float *a, float { float local_opacity = mask[i]; for(int k = 0; k < bd->bch; k++) - b[j + k] - = CLAMP_RANGE((a[j + k] * (1.0f - local_opacity)) + b[j + k] * local_opacity, min[k], max[k]); + b[j + k] = CLAMP_RANGE((a[j + k] * (1.0f - local_opacity)) + b[j + k] * local_opacity, min[k], max[k]); b[j + 3] = local_opacity; } } @@ -2217,8 +2162,7 @@ static void _blend_inverse(const _blend_buffer_desc_t *bd, const float *a, float { float local_opacity = mask[i]; for(int k = 0; k < bd->bch; k++) - b[j + k] - = CLAMP_RANGE((a[j + k] * (1.0f - local_opacity)) + b[j + k] * local_opacity, min[k], max[k]); + b[j + k] = CLAMP_RANGE((a[j + k] * (1.0f - local_opacity)) + b[j + k] * local_opacity, min[k], max[k]); } } } @@ -2245,14 +2189,13 @@ static void _blend_Lab_lightness(const _blend_buffer_desc_t *bd, const float *a, b[j + 3] = local_opacity; } } - else /* if(bd->cst == iop_cs_rgb || bd->cst == iop_cs_RAW) */ + else /* if(bd->cst == iop_cs_rgb || bd->cst == iop_cs_RAW) */ _blend_noop(bd, a, b, mask, NULL, NULL); // Noop for RGB and Raw (unclamped) } /* blend only a-channel in Lab color space without any clamping (a noop for * other color spaces) */ -static void _blend_Lab_a(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_Lab_a(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { if(bd->cst == iop_cs_Lab) { @@ -2271,14 +2214,13 @@ static void _blend_Lab_a(const _blend_buffer_desc_t *bd, const float *a, float * b[j + 3] = local_opacity; } } - else /* if(bd->cst == iop_cs_rgb || bd->cst == iop_cs_RAW) */ + else /* if(bd->cst == iop_cs_rgb || bd->cst == iop_cs_RAW) */ _blend_noop(bd, a, b, mask, NULL, NULL); // Noop for RGB and Raw (unclamped) } /* blend only b-channel in Lab color space without any clamping (a noop for * other color spaces) */ -static void _blend_Lab_b(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_Lab_b(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { if(bd->cst == iop_cs_Lab) { @@ -2297,15 +2239,14 @@ static void _blend_Lab_b(const _blend_buffer_desc_t *bd, const float *a, float * b[j + 3] = local_opacity; } } - else /* if(bd->cst == iop_cs_rgb || bd->cst == iop_cs_RAW) */ + else /* if(bd->cst == iop_cs_rgb || bd->cst == iop_cs_RAW) */ _blend_noop(bd, a, b, mask, NULL, NULL); // Noop for RGB and Raw (unclamped) } /* blend only color in Lab color space without any clamping (a noop for other * color spaces) */ -static void _blend_Lab_color(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_Lab_color(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { if(bd->cst == iop_cs_Lab) { @@ -2330,7 +2271,7 @@ static void _blend_Lab_color(const _blend_buffer_desc_t *bd, const float *a, flo b[j + 3] = local_opacity; } } - else /* if(bd->cst == iop_cs_rgb || bd->cst == iop_cs_RAW) */ + else /* if(bd->cst == iop_cs_rgb || bd->cst == iop_cs_RAW) */ _blend_noop(bd, a, b, mask, NULL, NULL); // Noop for RGB and Raw (unclamped) } @@ -2359,14 +2300,13 @@ static void _blend_HSV_lightness(const _blend_buffer_desc_t *bd, const float *a, b[j + 3] = local_opacity; } } - else /* if(bd->cst == iop_cs_Lab || bd->cst == iop_cs_RAW) */ + else /* if(bd->cst == iop_cs_Lab || bd->cst == iop_cs_RAW) */ _blend_noop(bd, a, b, mask, NULL, NULL); // Noop for Lab and Raw (unclamped) } /* blend only color in HSV color space without any clamping (a noop for other * color spaces) */ -static void _blend_HSV_color(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_HSV_color(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { if(bd->cst == iop_cs_rgb) { @@ -2398,14 +2338,13 @@ static void _blend_HSV_color(const _blend_buffer_desc_t *bd, const float *a, flo b[j + 3] = local_opacity; } } - else /* if(bd->cst == iop_cs_Lab || bd->cst == iop_cs_RAW) */ + else /* if(bd->cst == iop_cs_Lab || bd->cst == iop_cs_RAW) */ _blend_noop(bd, a, b, mask, NULL, NULL); // Noop for Lab and Raw (unclamped) } /* blend only R-channel in RGB color space without any clamping (a noop for * other color spaces) */ -static void _blend_RGB_R(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_RGB_R(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { if(bd->cst == iop_cs_rgb) { @@ -2419,15 +2358,13 @@ static void _blend_RGB_R(const _blend_buffer_desc_t *bd, const float *a, float * b[j + 3] = local_opacity; } } - else /* if(bd->cst == iop_cs_Lab || bd->cst == iop_cs_RAW) */ + else /* if(bd->cst == iop_cs_Lab || bd->cst == iop_cs_RAW) */ _blend_noop(bd, a, b, mask, NULL, NULL); // Noop for Lab and Raw (unclamped) - } /* blend only R-channel in RGB color space without any clamping (a noop for * other color spaces) */ -static void _blend_RGB_G(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_RGB_G(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { if(bd->cst == iop_cs_rgb) { @@ -2441,14 +2378,13 @@ static void _blend_RGB_G(const _blend_buffer_desc_t *bd, const float *a, float * b[j + 3] = local_opacity; } } - else /* if(bd->cst == iop_cs_Lab || bd->cst == iop_cs_RAW) */ + else /* if(bd->cst == iop_cs_Lab || bd->cst == iop_cs_RAW) */ _blend_noop(bd, a, b, mask, NULL, NULL); // Noop for Lab and Raw (unclamped) } /* blend only R-channel in RGB color space without any clamping (a noop for * other color spaces) */ -static void _blend_RGB_B(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, - int flag) +static void _blend_RGB_B(const _blend_buffer_desc_t *bd, const float *a, float *b, const float *mask, int flag) { if(bd->cst == iop_cs_rgb) { @@ -2462,7 +2398,7 @@ static void _blend_RGB_B(const _blend_buffer_desc_t *bd, const float *a, float * b[j + 3] = local_opacity; } } - else /* if(bd->cst == iop_cs_Lab || bd->cst == iop_cs_RAW) */ + else /* if(bd->cst == iop_cs_Lab || bd->cst == iop_cs_RAW) */ _blend_noop(bd, a, b, mask, NULL, NULL); // Noop for Lab and Raw (unclamped) } @@ -2480,7 +2416,7 @@ static void display_channel(const _blend_buffer_desc_t *bd, const float *a, floa for(int k = 0; k < bd->bch; k++) b[j + k] = c; } break; - case (DT_DEV_PIXELPIPE_DISPLAY_L | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): + case(DT_DEV_PIXELPIPE_DISPLAY_L | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): for(size_t i = 0, j = 0; j < bd->stride; i++, j += bd->ch) { const float c = CLAMP_RANGE(b[j] / 100.0f, 0.0f, 1.0f); @@ -2494,7 +2430,7 @@ static void display_channel(const _blend_buffer_desc_t *bd, const float *a, floa for(int k = 0; k < bd->bch; k++) b[j + k] = c; } break; - case (DT_DEV_PIXELPIPE_DISPLAY_a | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): + case(DT_DEV_PIXELPIPE_DISPLAY_a | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): for(size_t i = 0, j = 0; j < bd->stride; i++, j += bd->ch) { const float c = CLAMP_RANGE((b[j + 1] + 128.0f) / 256.0f, 0.0f, 1.0f); @@ -2508,7 +2444,7 @@ static void display_channel(const _blend_buffer_desc_t *bd, const float *a, floa for(int k = 0; k < bd->bch; k++) b[j + k] = c; } break; - case (DT_DEV_PIXELPIPE_DISPLAY_b | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): + case(DT_DEV_PIXELPIPE_DISPLAY_b | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): for(size_t i = 0, j = 0; j < bd->stride; i++, j += bd->ch) { const float c = CLAMP_RANGE((b[j + 2] + 128.0f) / 256.0f, 0.0f, 1.0f); @@ -2522,7 +2458,7 @@ static void display_channel(const _blend_buffer_desc_t *bd, const float *a, floa for(int k = 0; k < bd->bch; k++) b[j + k] = c; } break; - case (DT_DEV_PIXELPIPE_DISPLAY_R | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): + case(DT_DEV_PIXELPIPE_DISPLAY_R | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): for(size_t i = 0, j = 0; j < bd->stride; i++, j += bd->ch) { const float c = CLAMP_RANGE(b[j], 0.0f, 1.0f); @@ -2536,7 +2472,7 @@ static void display_channel(const _blend_buffer_desc_t *bd, const float *a, floa for(int k = 0; k < bd->bch; k++) b[j + k] = c; } break; - case (DT_DEV_PIXELPIPE_DISPLAY_G | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): + case(DT_DEV_PIXELPIPE_DISPLAY_G | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): for(size_t i = 0, j = 0; j < bd->stride; i++, j += bd->ch) { const float c = CLAMP_RANGE(b[j + 1], 0.0f, 1.0f); @@ -2550,7 +2486,7 @@ static void display_channel(const _blend_buffer_desc_t *bd, const float *a, floa for(int k = 0; k < bd->bch; k++) b[j + k] = c; } break; - case (DT_DEV_PIXELPIPE_DISPLAY_B | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): + case(DT_DEV_PIXELPIPE_DISPLAY_B | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): for(size_t i = 0, j = 0; j < bd->stride; i++, j += bd->ch) { const float c = CLAMP_RANGE(b[j + 2], 0.0f, 1.0f); @@ -2564,7 +2500,7 @@ static void display_channel(const _blend_buffer_desc_t *bd, const float *a, floa for(int k = 0; k < bd->bch; k++) b[j + k] = c; } break; - case (DT_DEV_PIXELPIPE_DISPLAY_GRAY | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): + case(DT_DEV_PIXELPIPE_DISPLAY_GRAY | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): for(size_t i = 0, j = 0; j < bd->stride; i++, j += bd->ch) { const float c = CLAMP_RANGE(0.3f * b[j] + 0.59f * b[j + 1] + 0.11f * b[j + 2], 0.0f, 1.0f); @@ -2580,7 +2516,7 @@ static void display_channel(const _blend_buffer_desc_t *bd, const float *a, floa for(int k = 0; k < bd->bch; k++) b[j + k] = c; } break; - case (DT_DEV_PIXELPIPE_DISPLAY_LCH_C | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): + case(DT_DEV_PIXELPIPE_DISPLAY_LCH_C | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): for(size_t i = 0, j = 0; j < bd->stride; i++, j += bd->ch) { float LCH[3]; @@ -2598,7 +2534,7 @@ static void display_channel(const _blend_buffer_desc_t *bd, const float *a, floa for(int k = 0; k < bd->bch; k++) b[j + k] = c; } break; - case (DT_DEV_PIXELPIPE_DISPLAY_LCH_h | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): + case(DT_DEV_PIXELPIPE_DISPLAY_LCH_h | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): for(size_t i = 0, j = 0; j < bd->stride; i++, j += bd->ch) { float LCH[3]; @@ -2616,7 +2552,7 @@ static void display_channel(const _blend_buffer_desc_t *bd, const float *a, floa for(int k = 0; k < bd->bch; k++) b[j + k] = c; } break; - case (DT_DEV_PIXELPIPE_DISPLAY_HSL_H | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): + case(DT_DEV_PIXELPIPE_DISPLAY_HSL_H | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): for(size_t i = 0, j = 0; j < bd->stride; i++, j += bd->ch) { float HSL[3]; @@ -2634,7 +2570,7 @@ static void display_channel(const _blend_buffer_desc_t *bd, const float *a, floa for(int k = 0; k < bd->bch; k++) b[j + k] = c; } break; - case (DT_DEV_PIXELPIPE_DISPLAY_HSL_S | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): + case(DT_DEV_PIXELPIPE_DISPLAY_HSL_S | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): for(size_t i = 0, j = 0; j < bd->stride; i++, j += bd->ch) { float HSL[3]; @@ -2652,7 +2588,7 @@ static void display_channel(const _blend_buffer_desc_t *bd, const float *a, floa for(int k = 0; k < bd->bch; k++) b[j + k] = c; } break; - case (DT_DEV_PIXELPIPE_DISPLAY_HSL_l | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): + case(DT_DEV_PIXELPIPE_DISPLAY_HSL_l | DT_DEV_PIXELPIPE_DISPLAY_OUTPUT): for(size_t i = 0, j = 0; j < bd->stride; i++, j += bd->ch) { float HSL[3]; @@ -2671,8 +2607,7 @@ static void display_channel(const _blend_buffer_desc_t *bd, const float *a, floa if(bd->cst != iop_cs_rgb) { - for(size_t i = 0, j = 0; j < bd->stride; i++, j += bd->ch) - b[j + 3] = mask[i]; + for(size_t i = 0, j = 0; j < bd->stride; i++, j += bd->ch) b[j + 3] = mask[i]; } } @@ -2841,9 +2776,11 @@ void dt_develop_blend_process(struct dt_iop_module_t *self, struct dt_dev_pixelp const dt_dev_pixelpipe_display_mask_t mask_display = piece->pipe->mask_display; /* does user want us to display a specific channel? */ - const dt_dev_pixelpipe_display_mask_t request_mask_display = - (self->dev->gui_attached && (self == self->dev->gui_module) && (piece->pipe == self->dev->pipe) && (mask_mode & DEVELOP_MASK_BOTH)) ? - self->request_mask_display : DT_DEV_PIXELPIPE_DISPLAY_NONE; + const dt_dev_pixelpipe_display_mask_t request_mask_display + = (self->dev->gui_attached && (self == self->dev->gui_module) && (piece->pipe == self->dev->pipe) + && (mask_mode & DEVELOP_MASK_BOTH)) + ? self->request_mask_display + : DT_DEV_PIXELPIPE_DISPLAY_NONE; /* check if we only should blend lightness channel. will affect only Lab space */ @@ -2923,12 +2860,11 @@ void dt_develop_blend_process(struct dt_iop_module_t *self, struct dt_dev_pixelp size_t iindex = ((size_t)(y + yoffs) * iwidth + xoffs) * ch; size_t oindex = (size_t)y * roi_out->width * ch; - _blend_buffer_desc_t bd = { .cst = cst, .stride = (size_t)roi_out->width * ch, .ch = ch, .bch = bch }; + _blend_buffer_desc_t bd = {.cst = cst, .stride = (size_t)roi_out->width * ch, .ch = ch, .bch = bch }; float *in = (float *)ivoid + iindex; float *out = (float *)ovoid + oindex; float *m = (float *)mask + y * roi_out->width; - _blend_make_mask(&bd, d->blendif, d->blendif_parameters, d->mask_mode, d->mask_combine, opacity, in, - out, m); + _blend_make_mask(&bd, d->blendif, d->blendif_parameters, d->mask_mode, d->mask_combine, opacity, in, out, m); } const int maskblur = fabs(d->radius) <= 0.1f ? 0 : 1; @@ -2980,7 +2916,7 @@ void dt_develop_blend_process(struct dt_iop_module_t *self, struct dt_dev_pixelp { size_t iindex = ((size_t)(y + yoffs) * iwidth + xoffs) * ch; size_t oindex = (size_t)y * roi_out->width * ch; - _blend_buffer_desc_t bd = { .cst = cst, .stride = (size_t)roi_out->width * ch, .ch = ch, .bch = bch }; + _blend_buffer_desc_t bd = {.cst = cst, .stride = (size_t)roi_out->width * ch, .ch = ch, .bch = bch }; float *in = (float *)ivoid + iindex; float *out = (float *)ovoid + oindex; float *m = (float *)mask + y * roi_out->width; @@ -3004,8 +2940,8 @@ void dt_develop_blend_process(struct dt_iop_module_t *self, struct dt_dev_pixelp } #ifdef HAVE_OPENCL -int dt_develop_blend_process_cl(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - cl_mem dev_in, cl_mem dev_out, const struct dt_iop_roi_t *roi_in, +int dt_develop_blend_process_cl(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, + cl_mem dev_out, const struct dt_iop_roi_t *roi_in, const struct dt_iop_roi_t *roi_out) { dt_develop_blend_params_t *d = (dt_develop_blend_params_t *)piece->blendop_data; @@ -3088,9 +3024,11 @@ int dt_develop_blend_process_cl(struct dt_iop_module_t *self, struct dt_dev_pixe const dt_dev_pixelpipe_display_mask_t mask_display = piece->pipe->mask_display; /* does user want us to display a specific channel? */ - const dt_dev_pixelpipe_display_mask_t request_mask_display = - (self->dev->gui_attached && (self == self->dev->gui_module) && (piece->pipe == self->dev->pipe) && (mask_mode & DEVELOP_MASK_BOTH)) ? - self->request_mask_display : DT_DEV_PIXELPIPE_DISPLAY_NONE; + const dt_dev_pixelpipe_display_mask_t request_mask_display + = (self->dev->gui_attached && (self == self->dev->gui_module) && (piece->pipe == self->dev->pipe) + && (mask_mode & DEVELOP_MASK_BOTH)) + ? self->request_mask_display + : DT_DEV_PIXELPIPE_DISPLAY_NONE; const int offs[2] = { xoffs, yoffs }; const size_t sizes[] = { ROUNDUPWD(width), ROUNDUPHT(height), 1 }; @@ -3202,8 +3140,7 @@ int dt_develop_blend_process_cl(struct dt_iop_module_t *self, struct dt_dev_pixe const float mmax[] = { 1.0f }; const float mmin[] = { 0.0f }; - dt_gaussian_cl_t *g - = dt_gaussian_init_cl(devid, roi_out->width, roi_out->height, 1, mmax, mmin, sigma, 0); + dt_gaussian_cl_t *g = dt_gaussian_init_cl(devid, roi_out->width, roi_out->height, 1, mmax, mmin, sigma, 0); if(g) { dt_gaussian_blur_cl(g, dev_masktmp, dev_mask); @@ -3372,9 +3309,8 @@ gboolean dt_develop_blend_params_is_all_zero(const void *params, size_t length) } /** update blendop params from older versions */ -int dt_develop_blend_legacy_params(dt_iop_module_t *module, const void *const old_params, - const int old_version, void *new_params, const int new_version, - const int length) +int dt_develop_blend_legacy_params(dt_iop_module_t *module, const void *const old_params, const int old_version, + void *new_params, const int new_version, const int length) { // first deal with all-zero parmameter sets, regardless of version number. diff --git a/src/develop/blend.h b/src/develop/blend.h index 28e8ac7984d7..770841f4f03b 100644 --- a/src/develop/blend.h +++ b/src/develop/blend.h @@ -372,9 +372,8 @@ int dt_develop_blend_version(void); gboolean dt_develop_blend_params_is_all_zero(const void *params, size_t length); /** update blendop params from older versions */ -int dt_develop_blend_legacy_params(dt_iop_module_t *module, const void *const old_params, - const int old_version, void *new_params, const int new_version, - const int lenght); +int dt_develop_blend_legacy_params(dt_iop_module_t *module, const void *const old_params, const int old_version, + void *new_params, const int new_version, const int lenght); /** gui related stuff */ void dt_iop_gui_init_blendif(GtkBox *blendw, dt_iop_module_t *module); @@ -390,8 +389,8 @@ int dt_iop_gui_blending_mode_seq(dt_iop_gui_blend_data_t *bd, int mode); #ifdef HAVE_OPENCL /** apply blend for opencl modules*/ -int dt_develop_blend_process_cl(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - cl_mem dev_in, cl_mem dev_out, const struct dt_iop_roi_t *roi_in, +int dt_develop_blend_process_cl(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, + cl_mem dev_out, const struct dt_iop_roi_t *roi_in, const struct dt_iop_roi_t *roi_out); #endif diff --git a/src/develop/blend_gui.c b/src/develop/blend_gui.c index 85470824cb07..3dde483ffbcd 100644 --- a/src/develop/blend_gui.c +++ b/src/develop/blend_gui.c @@ -94,24 +94,22 @@ static const dt_iop_gui_blendif_colorstop_t _gradient_chroma[] { 0.5f, { NEUTRAL_GRAY, NEUTRAL_GRAY / 2, NEUTRAL_GRAY, 1.0 } }, { 1.0f, { NEUTRAL_GRAY, 0, NEUTRAL_GRAY, 1.0 } } }; -static const dt_iop_gui_blendif_colorstop_t _gradient_hue[] = { - { 0.0f, { 1.00f * 1.5f * NEUTRAL_GRAY, 0.68f * 1.5f * NEUTRAL_GRAY, 0.78f * 1.5f * NEUTRAL_GRAY, 1.0 } }, - { 0.166f, { 0.95f * 1.5f * NEUTRAL_GRAY, 0.73f * 1.5f * NEUTRAL_GRAY, 0.56f * 1.5f * NEUTRAL_GRAY, 1.0 } }, - { 0.333f, { 0.71f * 1.5f * NEUTRAL_GRAY, 0.81f * 1.5f * NEUTRAL_GRAY, 0.55f * 1.5f * NEUTRAL_GRAY, 1.0 } }, - { 0.500f, { 0.45f * 1.5f * NEUTRAL_GRAY, 0.85f * 1.5f * NEUTRAL_GRAY, 0.77f * 1.5f * NEUTRAL_GRAY, 1.0 } }, - { 0.666f, { 0.49f * 1.5f * NEUTRAL_GRAY, 0.82f * 1.5f * NEUTRAL_GRAY, 1.00f * 1.5f * NEUTRAL_GRAY, 1.0 } }, - { 0.833f, { 0.82f * 1.5f * NEUTRAL_GRAY, 0.74f * 1.5f * NEUTRAL_GRAY, 1.00f * 1.5f * NEUTRAL_GRAY, 1.0 } }, - { 1.0f, { 1.00f * 1.5f * NEUTRAL_GRAY, 0.68f * 1.5f * NEUTRAL_GRAY, 0.78f * 1.5f * NEUTRAL_GRAY, 1.0 } } -}; - -static const dt_iop_gui_blendif_colorstop_t _gradient_HUE[] - = { { 0.0f, { NEUTRAL_GRAY, 0, 0, 1.0 } }, - { 0.166f, { NEUTRAL_GRAY, NEUTRAL_GRAY, 0, 1.0 } }, - { 0.332f, { 0, NEUTRAL_GRAY, 0, 1.0 } }, - { 0.498f, { 0, NEUTRAL_GRAY, NEUTRAL_GRAY, 1.0 } }, - { 0.664f, { 0, 0, NEUTRAL_GRAY, 1.0 } }, - { 0.830f, { NEUTRAL_GRAY, 0, NEUTRAL_GRAY, 1.0 } }, - { 1.0f, { NEUTRAL_GRAY, 0, 0, 1.0 } } }; +static const dt_iop_gui_blendif_colorstop_t _gradient_hue[] + = { { 0.0f, { 1.00f * 1.5f * NEUTRAL_GRAY, 0.68f * 1.5f * NEUTRAL_GRAY, 0.78f * 1.5f * NEUTRAL_GRAY, 1.0 } }, + { 0.166f, { 0.95f * 1.5f * NEUTRAL_GRAY, 0.73f * 1.5f * NEUTRAL_GRAY, 0.56f * 1.5f * NEUTRAL_GRAY, 1.0 } }, + { 0.333f, { 0.71f * 1.5f * NEUTRAL_GRAY, 0.81f * 1.5f * NEUTRAL_GRAY, 0.55f * 1.5f * NEUTRAL_GRAY, 1.0 } }, + { 0.500f, { 0.45f * 1.5f * NEUTRAL_GRAY, 0.85f * 1.5f * NEUTRAL_GRAY, 0.77f * 1.5f * NEUTRAL_GRAY, 1.0 } }, + { 0.666f, { 0.49f * 1.5f * NEUTRAL_GRAY, 0.82f * 1.5f * NEUTRAL_GRAY, 1.00f * 1.5f * NEUTRAL_GRAY, 1.0 } }, + { 0.833f, { 0.82f * 1.5f * NEUTRAL_GRAY, 0.74f * 1.5f * NEUTRAL_GRAY, 1.00f * 1.5f * NEUTRAL_GRAY, 1.0 } }, + { 1.0f, { 1.00f * 1.5f * NEUTRAL_GRAY, 0.68f * 1.5f * NEUTRAL_GRAY, 0.78f * 1.5f * NEUTRAL_GRAY, 1.0 } } }; + +static const dt_iop_gui_blendif_colorstop_t _gradient_HUE[] = { { 0.0f, { NEUTRAL_GRAY, 0, 0, 1.0 } }, + { 0.166f, { NEUTRAL_GRAY, NEUTRAL_GRAY, 0, 1.0 } }, + { 0.332f, { 0, NEUTRAL_GRAY, 0, 1.0 } }, + { 0.498f, { 0, NEUTRAL_GRAY, NEUTRAL_GRAY, 1.0 } }, + { 0.664f, { 0, 0, NEUTRAL_GRAY, 1.0 } }, + { 0.830f, { NEUTRAL_GRAY, 0, NEUTRAL_GRAY, 1.0 } }, + { 1.0f, { NEUTRAL_GRAY, 0, 0, 1.0 } } }; static inline void _RGB_2_HSL(const float *RGB, float *HSL) @@ -268,8 +266,8 @@ static void _blendif_scale_print_default(float value, char *string, int n) static void _blendop_masks_mode_callback(GtkWidget *combo, dt_iop_gui_blend_data_t *data) { - const unsigned int mask_mode = GPOINTER_TO_UINT( - g_list_nth_data(data->masks_modes, dt_bauhaus_combobox_get(data->masks_modes_combo))); + const unsigned int mask_mode + = GPOINTER_TO_UINT(g_list_nth_data(data->masks_modes, dt_bauhaus_combobox_get(data->masks_modes_combo))); data->module->blend_params->mask_mode = mask_mode; @@ -282,16 +280,15 @@ static void _blendop_masks_mode_callback(GtkWidget *combo, dt_iop_gui_blend_data gtk_widget_hide(GTK_WIDGET(data->top_box)); } - if((mask_mode & DEVELOP_MASK_ENABLED) - && ((data->masks_inited && (mask_mode & DEVELOP_MASK_MASK)) - || (data->blendif_inited && (mask_mode & DEVELOP_MASK_CONDITIONAL)))) + if((mask_mode & DEVELOP_MASK_ENABLED) && ((data->masks_inited && (mask_mode & DEVELOP_MASK_MASK)) + || (data->blendif_inited && (mask_mode & DEVELOP_MASK_CONDITIONAL)))) { if(data->blendif_inited && (mask_mode & DEVELOP_MASK_CONDITIONAL)) { - dt_bauhaus_combobox_set(data->masks_combine_combo, - g_list_index(data->masks_combine, - GUINT_TO_POINTER(data->module->blend_params->mask_combine - & (DEVELOP_COMBINE_INV | DEVELOP_COMBINE_INCL)))); + dt_bauhaus_combobox_set( + data->masks_combine_combo, + g_list_index(data->masks_combine, GUINT_TO_POINTER(data->module->blend_params->mask_combine + & (DEVELOP_COMBINE_INV | DEVELOP_COMBINE_INCL)))); gtk_widget_hide(GTK_WIDGET(data->masks_invert_combo)); gtk_widget_show(GTK_WIDGET(data->masks_combine_combo)); } @@ -376,15 +373,15 @@ static void _blendop_masks_mode_callback(GtkWidget *combo, dt_iop_gui_blend_data static void _blendop_blend_mode_callback(GtkWidget *combo, dt_iop_gui_blend_data_t *data) { - data->module->blend_params->blend_mode = GPOINTER_TO_UINT( - g_list_nth_data(data->blend_modes, dt_bauhaus_combobox_get(data->blend_modes_combo))); + data->module->blend_params->blend_mode + = GPOINTER_TO_UINT(g_list_nth_data(data->blend_modes, dt_bauhaus_combobox_get(data->blend_modes_combo))); dt_dev_add_history_item(darktable.develop, data->module, TRUE); } static void _blendop_masks_combine_callback(GtkWidget *combo, dt_iop_gui_blend_data_t *data) { - const unsigned combine = GPOINTER_TO_UINT( - g_list_nth_data(data->masks_combine, dt_bauhaus_combobox_get(data->masks_combine_combo))); + const unsigned combine + = GPOINTER_TO_UINT(g_list_nth_data(data->masks_combine, dt_bauhaus_combobox_get(data->masks_combine_combo))); data->module->blend_params->mask_combine &= ~(DEVELOP_COMBINE_INV | DEVELOP_COMBINE_INCL); data->module->blend_params->mask_combine |= combine; dt_dev_add_history_item(darktable.develop, data->module, TRUE); @@ -392,9 +389,9 @@ static void _blendop_masks_combine_callback(GtkWidget *combo, dt_iop_gui_blend_d static void _blendop_masks_invert_callback(GtkWidget *combo, dt_iop_gui_blend_data_t *data) { - unsigned int invert = GPOINTER_TO_UINT(g_list_nth_data(data->masks_invert, - dt_bauhaus_combobox_get(data->masks_invert_combo))) - & DEVELOP_COMBINE_INV; + unsigned int invert + = GPOINTER_TO_UINT(g_list_nth_data(data->masks_invert, dt_bauhaus_combobox_get(data->masks_invert_combo))) + & DEVELOP_COMBINE_INV; if(invert) data->module->blend_params->mask_combine |= DEVELOP_COMBINE_INV; else @@ -543,9 +540,11 @@ static void _blendop_blendif_showmask_clicked(GtkWidget *button, GdkEventButton if(event->button == 1) { - const int has_mask_display = module->request_mask_display & (DT_DEV_PIXELPIPE_DISPLAY_MASK | DT_DEV_PIXELPIPE_DISPLAY_CHANNEL); + const int has_mask_display = module->request_mask_display + & (DT_DEV_PIXELPIPE_DISPLAY_MASK | DT_DEV_PIXELPIPE_DISPLAY_CHANNEL); - module->request_mask_display &= ~(DT_DEV_PIXELPIPE_DISPLAY_MASK | DT_DEV_PIXELPIPE_DISPLAY_CHANNEL | DT_DEV_PIXELPIPE_DISPLAY_ANY); + module->request_mask_display + &= ~(DT_DEV_PIXELPIPE_DISPLAY_MASK | DT_DEV_PIXELPIPE_DISPLAY_CHANNEL | DT_DEV_PIXELPIPE_DISPLAY_ANY); GdkModifierType modifiers = gtk_accelerator_get_default_mod_mask(); if((event->state & modifiers) == (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) @@ -848,8 +847,8 @@ static gboolean _blendop_blendif_draw(GtkWidget *widget, cairo_t *cr, dt_iop_mod snprintf(text, sizeof(text), "(%.1f)", cooked[data->tab]); - dtgtk_gradient_slider_multivalue_set_picker_meanminmax( - DTGTK_GRADIENT_SLIDER(widget), picker_mean[data->tab], picker_min[data->tab], picker_max[data->tab]); + dtgtk_gradient_slider_multivalue_set_picker_meanminmax(DTGTK_GRADIENT_SLIDER(widget), picker_mean[data->tab], + picker_min[data->tab], picker_max[data->tab]); gtk_label_set_text(label, text); } else @@ -1076,9 +1075,8 @@ void dt_iop_gui_init_blendif(GtkBox *blendw, dt_iop_module_t *module) if(bd->blendif_support) { char *Lab_labels[] = { " L ", " a ", " b ", " C ", " h " }; - char *Lab_tooltips[] - = { _("sliders for L channel"), _("sliders for a channel"), _("sliders for b channel"), - _("sliders for chroma channel (of LCh)"), _("sliders for hue channel (of LCh)") }; + char *Lab_tooltips[] = { _("sliders for L channel"), _("sliders for a channel"), _("sliders for b channel"), + _("sliders for chroma channel (of LCh)"), _("sliders for hue channel (of LCh)") }; char *rgb_labels[] = { _(" g "), _(" R "), _(" G "), _(" B "), _(" H "), _(" S "), _(" L ") }; char *rgb_tooltips[] = { _("sliders for gray value"), _("sliders for red channel"), _("sliders for green channel"), @@ -1225,11 +1223,10 @@ void dt_iop_gui_init_blendif(GtkBox *blendw, dt_iop_module_t *module) for(int ch = 0; ch < maxchannels; ch++) { gtk_notebook_append_page(GTK_NOTEBOOK(bd->channel_tabs), - GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)), - gtk_label_new(labels[ch])); - gtk_widget_set_tooltip_text(gtk_notebook_get_tab_label(bd->channel_tabs, - gtk_notebook_get_nth_page(bd->channel_tabs, -1)), - tooltips[ch]); + GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)), gtk_label_new(labels[ch])); + gtk_widget_set_tooltip_text( + gtk_notebook_get_tab_label(bd->channel_tabs, gtk_notebook_get_nth_page(bd->channel_tabs, -1)), + tooltips[ch]); } gtk_widget_show_all(GTK_WIDGET(gtk_notebook_get_nth_page(bd->channel_tabs, bd->tab))); @@ -1307,11 +1304,9 @@ void dt_iop_gui_init_blendif(GtkBox *blendw, dt_iop_module_t *module) g_signal_connect(G_OBJECT(bd->channel_tabs), "switch_page", G_CALLBACK(_blendop_blendif_tab_switch), bd); - g_signal_connect(G_OBJECT(bd->upper_slider), "value-changed", G_CALLBACK(_blendop_blendif_upper_callback), - bd); + g_signal_connect(G_OBJECT(bd->upper_slider), "value-changed", G_CALLBACK(_blendop_blendif_upper_callback), bd); - g_signal_connect(G_OBJECT(bd->lower_slider), "value-changed", G_CALLBACK(_blendop_blendif_lower_callback), - bd); + g_signal_connect(G_OBJECT(bd->lower_slider), "value-changed", G_CALLBACK(_blendop_blendif_lower_callback), bd); g_signal_connect(G_OBJECT(bd->lower_slider), "leave-notify-event", G_CALLBACK(_blendop_blendif_leave), module); @@ -1327,11 +1322,9 @@ void dt_iop_gui_init_blendif(GtkBox *blendw, dt_iop_module_t *module) g_signal_connect(G_OBJECT(inv), "clicked", G_CALLBACK(_blendop_blendif_invert), module); - g_signal_connect(G_OBJECT(bd->lower_polarity), "toggled", G_CALLBACK(_blendop_blendif_polarity_callback), - bd); + g_signal_connect(G_OBJECT(bd->lower_polarity), "toggled", G_CALLBACK(_blendop_blendif_polarity_callback), bd); - g_signal_connect(G_OBJECT(bd->upper_polarity), "toggled", G_CALLBACK(_blendop_blendif_polarity_callback), - bd); + g_signal_connect(G_OBJECT(bd->upper_polarity), "toggled", G_CALLBACK(_blendop_blendif_polarity_callback), bd); gtk_box_pack_start(GTK_BOX(bd->blendif_box), GTK_WIDGET(header), TRUE, FALSE, 0); gtk_box_pack_start(GTK_BOX(bd->blendif_box), GTK_WIDGET(uplabel), TRUE, FALSE, 0); @@ -1372,8 +1365,7 @@ void dt_iop_gui_update_masks(dt_iop_module_t *module) dt_bauhaus_combobox_set(bd->masks_combo, 0); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bd->masks_edit), bd->masks_shown != DT_MASKS_EDIT_OFF); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bd->masks_polarity), - bp->mask_combine & DEVELOP_COMBINE_MASKS_POS); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bd->masks_polarity), bp->mask_combine & DEVELOP_COMBINE_MASKS_POS); // update buttons status int b1 = 0, b2 = 0, b3 = 0, b4 = 0, b5 = 0; @@ -1419,13 +1411,12 @@ void dt_iop_gui_init_masks(GtkBox *blendw, dt_iop_module_t *module) dt_bauhaus_widget_set_label(bd->masks_combo, _("blend"), _("drawn mask")); dt_bauhaus_combobox_add(bd->masks_combo, _("no mask used")); dt_bauhaus_combobox_set(bd->masks_combo, 0); - g_signal_connect(G_OBJECT(bd->masks_combo), "value-changed", - G_CALLBACK(dt_masks_iop_value_changed_callback), module); + g_signal_connect(G_OBJECT(bd->masks_combo), "value-changed", G_CALLBACK(dt_masks_iop_value_changed_callback), + module); dt_bauhaus_combobox_add_populate_fct(bd->masks_combo, dt_masks_iop_combo_populate); gtk_box_pack_start(GTK_BOX(hbox), bd->masks_combo, TRUE, TRUE, 0); - bd->masks_edit - = dtgtk_togglebutton_new(dtgtk_cairo_paint_masks_eye, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); + bd->masks_edit = dtgtk_togglebutton_new(dtgtk_cairo_paint_masks_eye, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); g_signal_connect(G_OBJECT(bd->masks_edit), "button-press-event", G_CALLBACK(_blendop_masks_show_and_edit), module); gtk_widget_set_tooltip_text(bd->masks_edit, _("show and edit mask elements")); @@ -1436,25 +1427,22 @@ void dt_iop_gui_init_masks(GtkBox *blendw, dt_iop_module_t *module) bd->masks_polarity = dtgtk_togglebutton_new(dtgtk_cairo_paint_plusminus, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); gtk_widget_set_tooltip_text(bd->masks_polarity, _("toggle polarity of drawn mask")); - g_signal_connect(G_OBJECT(bd->masks_polarity), "toggled", G_CALLBACK(_blendop_masks_polarity_callback), - module); + g_signal_connect(G_OBJECT(bd->masks_polarity), "toggled", G_CALLBACK(_blendop_masks_polarity_callback), module); gtk_widget_set_size_request(GTK_WIDGET(bd->masks_polarity), bs, bs); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bd->masks_polarity), FALSE); gtk_box_pack_start(GTK_BOX(hbox), bd->masks_polarity, FALSE, FALSE, 0); bd->masks_gradient = dtgtk_togglebutton_new(dtgtk_cairo_paint_masks_gradient, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); - g_signal_connect(G_OBJECT(bd->masks_gradient), "button-press-event", - G_CALLBACK(_blendop_masks_add_gradient), module); + g_signal_connect(G_OBJECT(bd->masks_gradient), "button-press-event", G_CALLBACK(_blendop_masks_add_gradient), + module); gtk_widget_set_tooltip_text(bd->masks_gradient, _("add gradient")); gtk_widget_set_size_request(GTK_WIDGET(bd->masks_gradient), bs, bs); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bd->masks_gradient), FALSE); gtk_box_pack_end(GTK_BOX(abox), bd->masks_gradient, FALSE, FALSE, 0); - bd->masks_path - = dtgtk_togglebutton_new(dtgtk_cairo_paint_masks_path, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); - g_signal_connect(G_OBJECT(bd->masks_path), "button-press-event", G_CALLBACK(_blendop_masks_add_path), - module); + bd->masks_path = dtgtk_togglebutton_new(dtgtk_cairo_paint_masks_path, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); + g_signal_connect(G_OBJECT(bd->masks_path), "button-press-event", G_CALLBACK(_blendop_masks_add_path), module); gtk_widget_set_tooltip_text(bd->masks_path, _("add path")); gtk_widget_set_size_request(GTK_WIDGET(bd->masks_path), bs, bs); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bd->masks_path), FALSE); @@ -1462,8 +1450,8 @@ void dt_iop_gui_init_masks(GtkBox *blendw, dt_iop_module_t *module) bd->masks_ellipse = dtgtk_togglebutton_new(dtgtk_cairo_paint_masks_ellipse, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); - g_signal_connect(G_OBJECT(bd->masks_ellipse), "button-press-event", - G_CALLBACK(_blendop_masks_add_ellipse), module); + g_signal_connect(G_OBJECT(bd->masks_ellipse), "button-press-event", G_CALLBACK(_blendop_masks_add_ellipse), + module); gtk_widget_set_tooltip_text(bd->masks_ellipse, _("add ellipse")); gtk_widget_set_size_request(GTK_WIDGET(bd->masks_ellipse), bs, bs); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bd->masks_ellipse), FALSE); @@ -1480,8 +1468,7 @@ void dt_iop_gui_init_masks(GtkBox *blendw, dt_iop_module_t *module) bd->masks_brush = dtgtk_togglebutton_new(dtgtk_cairo_paint_masks_brush, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); - g_signal_connect(G_OBJECT(bd->masks_brush), "button-press-event", G_CALLBACK(_blendop_masks_add_brush), - module); + g_signal_connect(G_OBJECT(bd->masks_brush), "button-press-event", G_CALLBACK(_blendop_masks_add_brush), module); gtk_widget_set_tooltip_text(bd->masks_brush, _("add brush")); gtk_widget_set_size_request(GTK_WIDGET(bd->masks_brush), bs, bs); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bd->masks_brush), FALSE); @@ -1503,8 +1490,7 @@ void dt_iop_gui_cleanup_blending(dt_iop_module_t *module) dt_iop_gui_blend_data_t *bd = (dt_iop_gui_blend_data_t *)module->blend_data; dt_pthread_mutex_lock(&bd->lock); - if(bd->timeout_handle) - g_source_remove(bd->timeout_handle); + if(bd->timeout_handle) g_source_remove(bd->timeout_handle); g_list_free(bd->blend_modes); g_list_free(bd->masks_modes); @@ -1571,9 +1557,9 @@ void dt_iop_gui_update_blending(dt_iop_module_t *module) bd->masks_combine_combo, g_list_index(bd->masks_combine, GUINT_TO_POINTER(module->blend_params->mask_combine & (DEVELOP_COMBINE_INV | DEVELOP_COMBINE_INCL)))); - dt_bauhaus_combobox_set(bd->masks_invert_combo, - g_list_index(bd->masks_invert, GUINT_TO_POINTER(module->blend_params->mask_combine - & DEVELOP_COMBINE_INV))); + dt_bauhaus_combobox_set( + bd->masks_invert_combo, + g_list_index(bd->masks_invert, GUINT_TO_POINTER(module->blend_params->mask_combine & DEVELOP_COMBINE_INV))); dt_bauhaus_slider_set(bd->opacity_slider, module->blend_params->opacity); dt_bauhaus_slider_set(bd->radius_slider, module->blend_params->radius); @@ -1754,32 +1740,22 @@ void dt_iop_gui_init_blending(GtkWidget *iopw, dt_iop_module_t *module) _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "chroma"), DEVELOP_BLEND_CHROMA); _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "hue"), DEVELOP_BLEND_HUE); _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "color"), DEVELOP_BLEND_COLOR); - _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "coloradjustment"), - DEVELOP_BLEND_COLORADJUST); - _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "Lab lightness"), - DEVELOP_BLEND_LAB_LIGHTNESS); + _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "coloradjustment"), DEVELOP_BLEND_COLORADJUST); + _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "Lab lightness"), DEVELOP_BLEND_LAB_LIGHTNESS); _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "Lab color"), DEVELOP_BLEND_LAB_COLOR); - _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "Lab L-channel"), - DEVELOP_BLEND_LAB_L); - _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "Lab a-channel"), - DEVELOP_BLEND_LAB_A); - _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "Lab b-channel"), - DEVELOP_BLEND_LAB_B); - _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "HSV lightness"), - DEVELOP_BLEND_HSV_LIGHTNESS); + _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "Lab L-channel"), DEVELOP_BLEND_LAB_L); + _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "Lab a-channel"), DEVELOP_BLEND_LAB_A); + _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "Lab b-channel"), DEVELOP_BLEND_LAB_B); + _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "HSV lightness"), DEVELOP_BLEND_HSV_LIGHTNESS); _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "HSV color"), DEVELOP_BLEND_HSV_COLOR); - _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "RGB red channel"), - DEVELOP_BLEND_RGB_R); - _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "RGB green channel"), - DEVELOP_BLEND_RGB_G); - _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "RGB blue channel"), - DEVELOP_BLEND_RGB_B); + _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "RGB red channel"), DEVELOP_BLEND_RGB_R); + _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "RGB green channel"), DEVELOP_BLEND_RGB_G); + _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "RGB blue channel"), DEVELOP_BLEND_RGB_B); /** deprecated blend modes: make them available as legacy history stacks might want them */ _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "difference (deprecated)"), DEVELOP_BLEND_DIFFERENCE); - _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "inverse (deprecated)"), - DEVELOP_BLEND_INVERSE); + _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "inverse (deprecated)"), DEVELOP_BLEND_INVERSE); _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "normal (deprecated)"), DEVELOP_BLEND_NORMAL); _collect_blend_modes(&(bd->blend_modes_all), C_("blendmode", "unbounded (deprecated)"), DEVELOP_BLEND_UNBOUNDED); @@ -1797,8 +1773,7 @@ void dt_iop_gui_init_blending(GtkWidget *iopw, dt_iop_module_t *module) if(bd->masks_support) { dt_bauhaus_combobox_add(bd->masks_modes_combo, _("drawn mask")); - bd->masks_modes - = g_list_append(bd->masks_modes, GUINT_TO_POINTER(DEVELOP_MASK_ENABLED | DEVELOP_MASK_MASK)); + bd->masks_modes = g_list_append(bd->masks_modes, GUINT_TO_POINTER(DEVELOP_MASK_ENABLED | DEVELOP_MASK_MASK)); } if(bd->blendif_support) @@ -1811,15 +1786,14 @@ void dt_iop_gui_init_blending(GtkWidget *iopw, dt_iop_module_t *module) if(bd->blendif_support && bd->masks_support) { dt_bauhaus_combobox_add(bd->masks_modes_combo, _("drawn & parametric mask")); - bd->masks_modes - = g_list_append(bd->masks_modes, GUINT_TO_POINTER(DEVELOP_MASK_ENABLED | DEVELOP_MASK_BOTH)); + bd->masks_modes = g_list_append(bd->masks_modes, GUINT_TO_POINTER(DEVELOP_MASK_ENABLED | DEVELOP_MASK_BOTH)); } dt_bauhaus_combobox_set(bd->masks_modes_combo, 0); - gtk_widget_set_tooltip_text(bd->masks_modes_combo,_("activate blending: uniformly, with drawn mask, with " - "parametric mask, or combination of both")); - g_signal_connect(G_OBJECT(bd->masks_modes_combo), "value-changed", - G_CALLBACK(_blendop_masks_mode_callback), bd); + gtk_widget_set_tooltip_text(bd->masks_modes_combo, _("activate blending: uniformly, with drawn mask, with " + "parametric mask, or combination of both")); + g_signal_connect(G_OBJECT(bd->masks_modes_combo), "value-changed", G_CALLBACK(_blendop_masks_mode_callback), + bd); @@ -1831,28 +1805,20 @@ void dt_iop_gui_init_blending(GtkWidget *iopw, dt_iop_module_t *module) switch(bd->csp) { case iop_cs_Lab: - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_NORMAL2); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_BOUNDED); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_LIGHTEN); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_DARKEN); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_NORMAL2); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_BOUNDED); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_LIGHTEN); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_DARKEN); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_MULTIPLY); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_AVERAGE); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_ADD); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_AVERAGE); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_ADD); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_SUBSTRACT); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_DIFFERENCE2); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_SCREEN); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_OVERLAY); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_SCREEN); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_OVERLAY); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_SOFTLIGHT); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, @@ -1865,47 +1831,34 @@ void dt_iop_gui_init_blending(GtkWidget *iopw, dt_iop_module_t *module) DEVELOP_BLEND_PINLIGHT); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_LAB_LIGHTNESS); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_LAB_A); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_LAB_B); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_LAB_A); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_LAB_B); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_LAB_COLOR); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_LIGHTNESS); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_CHROMA); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_HUE); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_COLOR); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_CHROMA); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_HUE); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_COLOR); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_COLORADJUST); break; case iop_cs_rgb: - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_NORMAL2); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_BOUNDED); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_LIGHTEN); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_DARKEN); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_NORMAL2); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_BOUNDED); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_LIGHTEN); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_DARKEN); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_MULTIPLY); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_AVERAGE); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_ADD); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_AVERAGE); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_ADD); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_SUBSTRACT); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_DIFFERENCE2); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_SCREEN); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_OVERLAY); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_SCREEN); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_OVERLAY); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_SOFTLIGHT); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, @@ -1920,47 +1873,33 @@ void dt_iop_gui_init_blending(GtkWidget *iopw, dt_iop_module_t *module) DEVELOP_BLEND_HSV_LIGHTNESS); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_HSV_COLOR); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_RGB_R); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_RGB_G); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_RGB_B); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_RGB_R); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_RGB_G); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_RGB_B); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_LIGHTNESS); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_CHROMA); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_HUE); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_COLOR); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_CHROMA); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_HUE); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_COLOR); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_COLORADJUST); break; case iop_cs_RAW: - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_NORMAL2); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_BOUNDED); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_LIGHTEN); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_DARKEN); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_NORMAL2); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_BOUNDED); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_LIGHTEN); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_DARKEN); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_MULTIPLY); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_AVERAGE); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_ADD); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_AVERAGE); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_ADD); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_SUBSTRACT); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_DIFFERENCE2); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_SCREEN); - _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, - DEVELOP_BLEND_OVERLAY); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_SCREEN); + _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_OVERLAY); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, DEVELOP_BLEND_SOFTLIGHT); _add_blendmode_combo(&(bd->blend_modes), bd->blend_modes_combo, bd->blend_modes_all, @@ -1976,8 +1915,8 @@ void dt_iop_gui_init_blending(GtkWidget *iopw, dt_iop_module_t *module) dt_bauhaus_combobox_set(bd->blend_modes_combo, 0); - g_signal_connect(G_OBJECT(bd->blend_modes_combo), "value-changed", - G_CALLBACK(_blendop_blend_mode_callback), bd); + g_signal_connect(G_OBJECT(bd->blend_modes_combo), "value-changed", G_CALLBACK(_blendop_blend_mode_callback), + bd); bd->opacity_slider = dt_bauhaus_slider_new_with_range(module, 0.0, 100.0, 1, 100.0, 0); @@ -2004,8 +1943,9 @@ void dt_iop_gui_init_blending(GtkWidget *iopw, dt_iop_module_t *module) bd->masks_combine = g_list_append(bd->masks_combine, GUINT_TO_POINTER(DEVELOP_COMBINE_INV_INCL)); dt_bauhaus_combobox_set(bd->masks_combine_combo, 0); - gtk_widget_set_tooltip_text(bd->masks_combine_combo, - _("how to combine individual drawn mask and different channels of parametric mask")); + gtk_widget_set_tooltip_text( + bd->masks_combine_combo, + _("how to combine individual drawn mask and different channels of parametric mask")); g_signal_connect(G_OBJECT(bd->masks_combine_combo), "value-changed", G_CALLBACK(_blendop_masks_combine_callback), bd); @@ -2021,8 +1961,8 @@ void dt_iop_gui_init_blending(GtkWidget *iopw, dt_iop_module_t *module) dt_bauhaus_combobox_set(bd->masks_invert_combo, 0); gtk_widget_set_tooltip_text(bd->masks_invert_combo, _("apply mask in normal or inverted mode")); - g_signal_connect(G_OBJECT(bd->masks_invert_combo), "value-changed", - G_CALLBACK(_blendop_masks_invert_callback), bd); + g_signal_connect(G_OBJECT(bd->masks_invert_combo), "value-changed", G_CALLBACK(_blendop_masks_invert_callback), + bd); @@ -2030,20 +1970,21 @@ void dt_iop_gui_init_blending(GtkWidget *iopw, dt_iop_module_t *module) dt_bauhaus_widget_set_label(bd->radius_slider, _("blend"), _("mask blur")); dt_bauhaus_slider_set_format(bd->radius_slider, "%.1f"); gtk_widget_set_tooltip_text(bd->radius_slider, _("radius for gaussian blur of blend mask")); - g_signal_connect(G_OBJECT(bd->radius_slider), "value-changed", - G_CALLBACK(_blendop_blendif_radius_callback), bd); + g_signal_connect(G_OBJECT(bd->radius_slider), "value-changed", G_CALLBACK(_blendop_blendif_radius_callback), + bd); bd->showmask = dtgtk_button_new(dtgtk_cairo_paint_showmask, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); - gtk_widget_set_tooltip_text(bd->showmask, _("display mask and/or color channel. ctrl-click to display mask, " - "shift-click to display channel. hover over parametric mask slider to " - "select channel for display")); + gtk_widget_set_tooltip_text(bd->showmask, + _("display mask and/or color channel. ctrl-click to display mask, " + "shift-click to display channel. hover over parametric mask slider to " + "select channel for display")); gtk_widget_set_size_request(GTK_WIDGET(bd->showmask), bs, bs); - g_signal_connect(G_OBJECT(bd->showmask), "button-press-event", G_CALLBACK(_blendop_blendif_showmask_clicked), module); + g_signal_connect(G_OBJECT(bd->showmask), "button-press-event", G_CALLBACK(_blendop_blendif_showmask_clicked), + module); - bd->suppress - = dtgtk_togglebutton_new(dtgtk_cairo_paint_eye_toggle, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); + bd->suppress = dtgtk_togglebutton_new(dtgtk_cairo_paint_eye_toggle, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); gtk_widget_set_tooltip_text(bd->suppress, _("temporarily switch off blend mask. only for module in focus")); gtk_widget_set_size_request(GTK_WIDGET(bd->suppress), bs, bs); g_signal_connect(G_OBJECT(bd->suppress), "toggled", G_CALLBACK(_blendop_blendif_suppress_toggled), module); diff --git a/src/develop/develop.c b/src/develop/develop.c index c0963fe9642a..2ad8119ecb58 100644 --- a/src/develop/develop.c +++ b/src/develop/develop.c @@ -177,16 +177,15 @@ void dt_dev_cleanup(dt_develop_t *dev) void dt_dev_process_image(dt_develop_t *dev) { if(!dev->gui_attached || dev->pipe->processing) return; - int err - = dt_control_add_job_res(darktable.control, dt_dev_process_image_job_create(dev), DT_CTL_WORKER_ZOOM_1); + int err = dt_control_add_job_res(darktable.control, dt_dev_process_image_job_create(dev), DT_CTL_WORKER_ZOOM_1); if(err) fprintf(stderr, "[dev_process_image] job queue exceeded!\n"); } void dt_dev_process_preview(dt_develop_t *dev) { if(!dev->gui_attached) return; - int err = dt_control_add_job_res(darktable.control, dt_dev_process_preview_job_create(dev), - DT_CTL_WORKER_ZOOM_FILL); + int err + = dt_control_add_job_res(darktable.control, dt_dev_process_preview_job_create(dev), DT_CTL_WORKER_ZOOM_FILL); if(err) fprintf(stderr, "[dev_process_preview] job queue exceeded!\n"); } @@ -225,8 +224,7 @@ void dt_dev_process_preview_job(dt_develop_t *dev) // lock if there, issue a background load, if not (best-effort for mip f). dt_mipmap_buffer_t buf; - dt_mipmap_cache_get(darktable.mipmap_cache, &buf, dev->image_storage.id, DT_MIPMAP_F, DT_MIPMAP_BEST_EFFORT, - 'r'); + dt_mipmap_cache_get(darktable.mipmap_cache, &buf, dev->image_storage.id, DT_MIPMAP_F, DT_MIPMAP_BEST_EFFORT, 'r'); if(!buf.buf) { dt_control_log_busy_leave(); @@ -313,8 +311,7 @@ void dt_dev_process_image_job(dt_develop_t *dev) dt_mipmap_buffer_t buf; dt_times_t start; dt_get_times(&start); - dt_mipmap_cache_get(darktable.mipmap_cache, &buf, dev->image_storage.id, DT_MIPMAP_FULL, - DT_MIPMAP_BLOCKING, 'r'); + dt_mipmap_cache_get(darktable.mipmap_cache, &buf, dev->image_storage.id, DT_MIPMAP_FULL, DT_MIPMAP_BLOCKING, 'r'); dt_show_times(&start, "[dev]", "to load the image."); // failed to load raw? @@ -391,7 +388,7 @@ void dt_dev_process_image_job(dt_develop_t *dev) } const int wd = MIN(window_width, dev->pipe->processed_width * scale); const int ht = MIN(window_height, dev->pipe->processed_height * scale); - x = MAX(0, scale * dev->pipe->processed_width * (.5 + zoom_x) - wd / 2); + x = MAX(0, scale * dev->pipe->processed_width * (.5 + zoom_x) - wd / 2); y = MAX(0, scale * dev->pipe->processed_height * (.5 + zoom_y) - ht / 2); dt_get_times(&start); @@ -509,8 +506,8 @@ void dt_dev_configure(dt_develop_t *dev, int wd, int ht) { // fixed border on every side const int tb = DT_PIXEL_APPLY_DPI(dt_conf_get_int("plugins/darkroom/ui/border_size")); - wd -= 2*tb; - ht -= 2*tb; + wd -= 2 * tb; + ht -= 2 * tb; if(dev->width != wd || dev->height != ht) { dev->width = wd; @@ -582,13 +579,13 @@ void dt_dev_add_history_item(dt_develop_t *dev, dt_iop_module_t *module, gboolea history = g_list_nth(dev->history, dev->history_end - 1); dt_dev_history_item_t *hist = history ? (dt_dev_history_item_t *)(history->data) : 0; if(!history // if no history yet, push new item for sure. - || module != hist->module - || module->instance != hist->module->instance // add new item for different op - || module->multi_priority != hist->module->multi_priority // or instance - || ((dev->focus_hash != hist->focus_hash) // or if focused out and in - && (// but only add item if there is a difference at all for the same module - (module->params_size != hist->module->params_size) || - (module->params_size == hist->module->params_size && memcmp(hist->params, module->params, module->params_size))))) + || module != hist->module || module->instance != hist->module->instance // add new item for different op + || module->multi_priority != hist->module->multi_priority // or instance + || ((dev->focus_hash != hist->focus_hash) // or if focused out and in + && ( // but only add item if there is a difference at all for the same module + (module->params_size != hist->module->params_size) + || (module->params_size == hist->module->params_size + && memcmp(hist->params, module->params, module->params_size))))) { // new operation, push new item // printf("adding new history item %d - %s\n", dev->history_end, module->op); @@ -744,8 +741,8 @@ void dt_dev_reload_history_items(dt_develop_t *dev) gtk_container_child_get_property( GTK_CONTAINER(dt_ui_get_container(darktable.gui->ui, DT_UI_CONTAINER_PANEL_RIGHT_CENTER)), base->expander, "position", &gv); - gtk_box_reorder_child(dt_ui_get_container(darktable.gui->ui, DT_UI_CONTAINER_PANEL_RIGHT_CENTER), - expander, g_value_get_int(&gv) + pos_base - pos_module); + gtk_box_reorder_child(dt_ui_get_container(darktable.gui->ui, DT_UI_CONTAINER_PANEL_RIGHT_CENTER), expander, + g_value_get_int(&gv) + pos_base - pos_module); dt_iop_gui_set_expanded(module, TRUE, FALSE); dt_iop_gui_update_blending(module); @@ -842,8 +839,7 @@ void dt_dev_write_history(dt_develop_t *dev) } DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), - "UPDATE main.images SET history_end = ?1 WHERE id = ?2", -1, - &stmt, NULL); + "UPDATE main.images SET history_end = ?1 WHERE id = ?2", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, dev->history_end); DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, dev->image_storage.id); sqlite3_step(stmt); @@ -918,8 +914,8 @@ static void auto_apply_presets(dt_develop_t *dev) sqlite3_finalize(stmt); int cnt = 0; // count what we found: - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT COUNT(*) FROM memory.history", -1, - &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT COUNT(*) FROM memory.history", -1, &stmt, + NULL); if(sqlite3_step(stmt) == SQLITE_ROW) { // if there is anything.. @@ -927,7 +923,8 @@ static void auto_apply_presets(dt_develop_t *dev) sqlite3_finalize(stmt); // workaround a sqlite3 "feature". The above statement to insert items into memory.history is complex and in - // this case sqlite does not give rowid a linear increment. But the following code really expect that the rowid in + // this case sqlite does not give rowid a linear increment. But the following code really expect that the + // rowid in // this table starts from 0 and increment one by one. So in the following code we rewrite the num values. if(cnt > 0) @@ -981,8 +978,8 @@ static void auto_apply_presets(dt_develop_t *dev) { sqlite3_finalize(stmt); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), - "UPDATE main.images SET history_end=history_end+?1 WHERE id=?2", - -1, &stmt, NULL); + "UPDATE main.images SET history_end=history_end+?1 WHERE id=?2", -1, &stmt, + NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, cnt); DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, imgid); if(sqlite3_step(stmt) == SQLITE_DONE) @@ -1088,10 +1085,9 @@ void dt_dev_read_history(dt_develop_t *dev) if(!hist->module) { - fprintf( - stderr, - "[dev_read_history] the module `%s' requested by image `%s' is not installed on this computer!\n", - opname, dev->image_storage.filename); + fprintf(stderr, + "[dev_read_history] the module `%s' requested by image `%s' is not installed on this computer!\n", + opname, dev->image_storage.filename); free(hist); continue; } @@ -1119,8 +1115,8 @@ void dt_dev_read_history(dt_develop_t *dev) memcpy(hist->blend_params, blendop_params, sizeof(dt_develop_blend_params_t)); } else if(blendop_params - && dt_develop_blend_legacy_params(hist->module, blendop_params, blendop_version, - hist->blend_params, dt_develop_blend_version(), bl_length) == 0) + && dt_develop_blend_legacy_params(hist->module, blendop_params, blendop_version, hist->blend_params, + dt_develop_blend_version(), bl_length) == 0) { // do nothing } @@ -1133,8 +1129,8 @@ void dt_dev_read_history(dt_develop_t *dev) || strcmp((char *)sqlite3_column_text(stmt, 3), hist->module->op)) { if(!hist->module->legacy_params - || hist->module->legacy_params(hist->module, sqlite3_column_blob(stmt, 4), labs(modversion), - hist->params, labs(hist->module->version()))) + || hist->module->legacy_params(hist->module, sqlite3_column_blob(stmt, 4), labs(modversion), hist->params, + labs(hist->module->version()))) { fprintf(stderr, "[dev_read_history] module `%s' version mismatch: history is %d, dt %d.\n", hist->module->op, modversion, hist->module->version()); @@ -1195,8 +1191,7 @@ void dt_dev_read_history(dt_develop_t *dev) DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, dev->image_storage.id); if(sqlite3_step(stmt) == SQLITE_ROW) // seriously, this should never fail { - if(sqlite3_column_type(stmt, 0) != SQLITE_NULL) - dev->history_end = sqlite3_column_int(stmt, 0); + if(sqlite3_column_type(stmt, 0) != SQLITE_NULL) dev->history_end = sqlite3_column_int(stmt, 0); } if(dev->gui_attached) @@ -1247,8 +1242,8 @@ void dt_dev_reprocess_center(dt_develop_t *dev) } -void dt_dev_check_zoom_bounds(dt_develop_t *dev, float *zoom_x, float *zoom_y, dt_dev_zoom_t zoom, - int closeup, float *boxww, float *boxhh) +void dt_dev_check_zoom_bounds(dt_develop_t *dev, float *zoom_x, float *zoom_y, dt_dev_zoom_t zoom, int closeup, + float *boxww, float *boxhh) { int procw = 0, proch = 0; dt_dev_get_processed_size(dev, &procw, &proch); @@ -1315,8 +1310,7 @@ void dt_dev_get_processed_size(const dt_develop_t *dev, int *procw, int *proch) return; } -void dt_dev_get_pointer_zoom_pos(dt_develop_t *dev, const float px, const float py, float *zoom_x, - float *zoom_y) +void dt_dev_get_pointer_zoom_pos(dt_develop_t *dev, const float px, const float py, float *zoom_x, float *zoom_y) { dt_dev_zoom_t zoom; int closeup, procw = 0, proch = 0; @@ -1427,8 +1421,7 @@ float dt_dev_exposure_get_black(dt_develop_t *dev) gboolean dt_dev_modulegroups_available(dt_develop_t *dev) { - if(dev->proxy.modulegroups.module && dev->proxy.modulegroups.set && dev->proxy.modulegroups.get) - return TRUE; + if(dev->proxy.modulegroups.module && dev->proxy.modulegroups.set && dev->proxy.modulegroups.get) return TRUE; return FALSE; } @@ -1576,10 +1569,10 @@ dt_iop_module_t *dt_dev_module_duplicate(dt_develop_t *dev, dt_iop_module_t *bas void dt_dev_invalidate_history_module(GList *list, dt_iop_module_t *module) { - while (list) + while(list) { dt_dev_history_item_t *hitem = (dt_dev_history_item_t *)list->data; - if (hitem->module == module) + if(hitem->module == module) { hitem->module = NULL; // set the multi_name to the module op name to be able to recreate the multi-instance later @@ -1710,8 +1703,8 @@ int dt_dev_distort_backtransform(dt_develop_t *dev, float *points, size_t points return dt_dev_distort_backtransform_plus(dev, dev->preview_pipe, 0, 99999, points, points_count); } -int dt_dev_distort_transform_plus(dt_develop_t *dev, dt_dev_pixelpipe_t *pipe, int pmin, int pmax, - float *points, size_t points_count) +int dt_dev_distort_transform_plus(dt_develop_t *dev, dt_dev_pixelpipe_t *pipe, int pmin, int pmax, float *points, + size_t points_count) { dt_pthread_mutex_lock(&dev->history_mutex); GList *modules = g_list_first(dev->iop); @@ -1725,8 +1718,8 @@ int dt_dev_distort_transform_plus(dt_develop_t *dev, dt_dev_pixelpipe_t *pipe, i } dt_iop_module_t *module = (dt_iop_module_t *)(modules->data); dt_dev_pixelpipe_iop_t *piece = (dt_dev_pixelpipe_iop_t *)(pieces->data); - if(piece->enabled && module->priority <= pmax && module->priority >= pmin && - !(dev->gui_module && dev->gui_module->operation_tags_filter() & module->operation_tags())) + if(piece->enabled && module->priority <= pmax && module->priority >= pmin + && !(dev->gui_module && dev->gui_module->operation_tags_filter() & module->operation_tags())) { module->distort_transform(module, piece, points, points_count); } @@ -1752,8 +1745,8 @@ int dt_dev_distort_backtransform_plus(dt_develop_t *dev, dt_dev_pixelpipe_t *pip } dt_iop_module_t *module = (dt_iop_module_t *)(modules->data); dt_dev_pixelpipe_iop_t *piece = (dt_dev_pixelpipe_iop_t *)(pieces->data); - if(piece->enabled && module->priority <= pmax && module->priority >= pmin && - !(dev->gui_module && dev->gui_module->operation_tags_filter() & module->operation_tags())) + if(piece->enabled && module->priority <= pmax && module->priority >= pmin + && !(dev->gui_module && dev->gui_module->operation_tags_filter() & module->operation_tags())) { module->distort_backtransform(module, piece, points, points_count); } @@ -1811,8 +1804,8 @@ uint64_t dt_dev_hash_plus(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, in return hash; } -int dt_dev_wait_hash(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmin, int pmax, dt_pthread_mutex_t *lock, - const volatile uint64_t *const hash) +int dt_dev_wait_hash(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmin, int pmax, + dt_pthread_mutex_t *lock, const volatile uint64_t *const hash) { const int usec = 5000; int nloop; @@ -1826,12 +1819,11 @@ int dt_dev_wait_hash(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmi nloop = dt_conf_get_int("pixelpipe_synchronization_timeout"); #endif - if(nloop <= 0) return TRUE; // non-positive values omit pixelpipe synchronization + if(nloop <= 0) return TRUE; // non-positive values omit pixelpipe synchronization for(int n = 0; n < nloop; n++) { - if(pipe->shutdown) - return TRUE; // stop waiting if pipe shuts down + if(pipe->shutdown) return TRUE; // stop waiting if pipe shuts down uint64_t probehash; @@ -1844,8 +1836,7 @@ int dt_dev_wait_hash(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmi else probehash = *hash; - if(probehash == dt_dev_hash_plus(dev, pipe, pmin, pmax)) - return TRUE; + if(probehash == dt_dev_hash_plus(dev, pipe, pmin, pmax)) return TRUE; dt_iop_nap(usec); } @@ -1853,12 +1844,11 @@ int dt_dev_wait_hash(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmi return FALSE; } -int dt_dev_sync_pixelpipe_hash(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmin, int pmax, dt_pthread_mutex_t *lock, - const volatile uint64_t *const hash) +int dt_dev_sync_pixelpipe_hash(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmin, int pmax, + dt_pthread_mutex_t *lock, const volatile uint64_t *const hash) { // first wait for matching hash values - if(dt_dev_wait_hash(dev, pipe, pmin, pmax, lock, hash)) - return TRUE; + if(dt_dev_wait_hash(dev, pipe, pmin, pmax, lock, hash)) return TRUE; // timed out. let's see if history stack has changed if(pipe->changed & (DT_DEV_PIPE_TOP_CHANGED | DT_DEV_PIPE_REMOVE | DT_DEV_PIPE_SYNCH)) @@ -1894,8 +1884,8 @@ uint64_t dt_dev_hash_distort_plus(dt_develop_t *dev, struct dt_dev_pixelpipe_t * } dt_iop_module_t *module = (dt_iop_module_t *)(modules->data); dt_dev_pixelpipe_iop_t *piece = (dt_dev_pixelpipe_iop_t *)(pieces->data); - if(piece->enabled && module->operation_tags() & IOP_TAG_DISTORT - && module->priority <= pmax && module->priority >= pmin) + if(piece->enabled && module->operation_tags() & IOP_TAG_DISTORT && module->priority <= pmax + && module->priority >= pmin) { hash = ((hash << 5) + hash) ^ piece->hash; } @@ -1906,8 +1896,8 @@ uint64_t dt_dev_hash_distort_plus(dt_develop_t *dev, struct dt_dev_pixelpipe_t * return hash; } -int dt_dev_wait_hash_distort(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmin, int pmax, dt_pthread_mutex_t *lock, - const volatile uint64_t *const hash) +int dt_dev_wait_hash_distort(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmin, int pmax, + dt_pthread_mutex_t *lock, const volatile uint64_t *const hash) { const int usec = 5000; int nloop; @@ -1921,12 +1911,11 @@ int dt_dev_wait_hash_distort(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, nloop = dt_conf_get_int("pixelpipe_synchronization_timeout"); #endif - if(nloop <= 0) return TRUE; // non-positive values omit pixelpipe synchronization + if(nloop <= 0) return TRUE; // non-positive values omit pixelpipe synchronization for(int n = 0; n < nloop; n++) { - if(pipe->shutdown) - return TRUE; // stop waiting if pipe shuts down + if(pipe->shutdown) return TRUE; // stop waiting if pipe shuts down uint64_t probehash; @@ -1939,8 +1928,7 @@ int dt_dev_wait_hash_distort(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, else probehash = *hash; - if(probehash == dt_dev_hash_distort_plus(dev, pipe, pmin, pmax)) - return TRUE; + if(probehash == dt_dev_hash_distort_plus(dev, pipe, pmin, pmax)) return TRUE; dt_iop_nap(usec); } @@ -1948,12 +1936,11 @@ int dt_dev_wait_hash_distort(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, return FALSE; } -int dt_dev_sync_pixelpipe_hash_distort(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmin, int pmax, dt_pthread_mutex_t *lock, - const volatile uint64_t *const hash) +int dt_dev_sync_pixelpipe_hash_distort(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmin, int pmax, + dt_pthread_mutex_t *lock, const volatile uint64_t *const hash) { // first wait for matching hash values - if(dt_dev_wait_hash_distort(dev, pipe, pmin, pmax, lock, hash)) - return TRUE; + if(dt_dev_wait_hash_distort(dev, pipe, pmin, pmax, lock, hash)) return TRUE; // timed out. let's see if history stack has changed if(pipe->changed & (DT_DEV_PIPE_TOP_CHANGED | DT_DEV_PIPE_REMOVE | DT_DEV_PIPE_SYNCH)) diff --git a/src/develop/develop.h b/src/develop/develop.h index 8142e6e71506..ebd88a18bbd3 100644 --- a/src/develop/develop.h +++ b/src/develop/develop.h @@ -39,7 +39,7 @@ typedef struct dt_dev_history_item_t struct dt_develop_blend_params_t *blend_params; int multi_priority; char multi_name[128]; - int32_t focus_hash; // used to determine whether or not to start a new item or to merge down + int32_t focus_hash; // used to determine whether or not to start a new item or to merge down } dt_dev_history_item_t; typedef enum dt_dev_overexposed_colorscheme_t @@ -49,13 +49,15 @@ typedef enum dt_dev_overexposed_colorscheme_t DT_DEV_OVEREXPOSED_PURPLEGREEN = 2 } dt_dev_overexposed_colorscheme_t; -typedef enum dt_dev_rawoverexposed_mode_t { +typedef enum dt_dev_rawoverexposed_mode_t +{ DT_DEV_RAWOVEREXPOSED_MODE_MARK_CFA = 0, DT_DEV_RAWOVEREXPOSED_MODE_MARK_SOLID = 1, DT_DEV_RAWOVEREXPOSED_MODE_FALSECOLOR = 2, } dt_dev_rawoverexposed_mode_t; -typedef enum dt_dev_rawoverexposed_colorscheme_t { +typedef enum dt_dev_rawoverexposed_colorscheme_t +{ DT_DEV_RAWOVEREXPOSED_RED = 0, DT_DEV_RAWOVEREXPOSED_GREEN = 1, DT_DEV_RAWOVEREXPOSED_BLUE = 2, @@ -154,8 +156,7 @@ typedef struct dt_develop_t // histogram for display. uint32_t *histogram, *histogram_pre_tonecurve, *histogram_pre_levels; uint32_t histogram_max, histogram_pre_tonecurve_max, histogram_pre_levels_max; - uint32_t *histogram_waveform, histogram_waveform_width, histogram_waveform_height, - histogram_waveform_stride; + uint32_t *histogram_waveform, histogram_waveform_width, histogram_waveform_height, histogram_waveform_stride; // we should process the waveform histogram in the correct size to make it not look like crap. since this // requires gui knowledge we need this mutex // dt_pthread_mutex_t histogram_waveform_mutex; @@ -168,7 +169,7 @@ typedef struct dt_develop_t // all forms to be linked here for cleanup: GList *allforms; - //full preview stuff + // full preview stuff int full_preview; int full_preview_last_zoom, full_preview_last_closeup; float full_preview_last_zoom_x, full_preview_last_zoom_y; @@ -283,11 +284,10 @@ void dt_dev_reprocess_all(dt_develop_t *dev); void dt_dev_reprocess_center(dt_develop_t *dev); void dt_dev_get_processed_size(const dt_develop_t *dev, int *procw, int *proch); -void dt_dev_check_zoom_bounds(dt_develop_t *dev, float *zoom_x, float *zoom_y, dt_dev_zoom_t zoom, - int closeup, float *boxw, float *boxh); +void dt_dev_check_zoom_bounds(dt_develop_t *dev, float *zoom_x, float *zoom_y, dt_dev_zoom_t zoom, int closeup, + float *boxw, float *boxh); float dt_dev_get_zoom_scale(dt_develop_t *dev, dt_dev_zoom_t zoom, int closeup_factor, int mode); -void dt_dev_get_pointer_zoom_pos(dt_develop_t *dev, const float px, const float py, float *zoom_x, - float *zoom_y); +void dt_dev_get_pointer_zoom_pos(dt_develop_t *dev, const float px, const float py, float *zoom_x, float *zoom_y); void dt_dev_configure(dt_develop_t *dev, int wd, int ht); @@ -378,21 +378,21 @@ uint64_t dt_dev_hash(dt_develop_t *dev); /** same function, but we can specify iop with priority between pmin and pmax */ uint64_t dt_dev_hash_plus(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmin, int pmax); /** wait until hash value found in hash matches hash value defined by dev/pipe/pmin/pmax with timeout */ -int dt_dev_wait_hash(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmin, int pmax, dt_pthread_mutex_t *lock, - const volatile uint64_t *const hash); +int dt_dev_wait_hash(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmin, int pmax, + dt_pthread_mutex_t *lock, const volatile uint64_t *const hash); /** synchronize pixelpipe by means hash values by waiting with timeout and potential reprocessing */ -int dt_dev_sync_pixelpipe_hash(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmin, int pmax, dt_pthread_mutex_t *lock, - const volatile uint64_t *const hash); +int dt_dev_sync_pixelpipe_hash(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmin, int pmax, + dt_pthread_mutex_t *lock, const volatile uint64_t *const hash); /** generate hash value out of module settings of all distorting modules of pixelpipe */ uint64_t dt_dev_hash_distort(dt_develop_t *dev); /** same function, but we can specify iop with priority between pmin and pmax */ uint64_t dt_dev_hash_distort_plus(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmin, int pmax); /** same as dt_dev_wait_hash but only for distorting modules */ -int dt_dev_wait_hash_distort(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmin, int pmax, dt_pthread_mutex_t *lock, - const volatile uint64_t *const hash); +int dt_dev_wait_hash_distort(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmin, int pmax, + dt_pthread_mutex_t *lock, const volatile uint64_t *const hash); /** same as dt_dev_sync_pixelpipe_hash but ony for distorting modules */ -int dt_dev_sync_pixelpipe_hash_distort (dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmin, int pmax, dt_pthread_mutex_t *lock, - const volatile uint64_t *const hash); +int dt_dev_sync_pixelpipe_hash_distort(dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe, int pmin, int pmax, + dt_pthread_mutex_t *lock, const volatile uint64_t *const hash); // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh // vim: shiftwidth=2 expandtab tabstop=2 cindent diff --git a/src/develop/format.c b/src/develop/format.c index 1fbcb95e2441..dbd85c5aea1b 100644 --- a/src/develop/format.c +++ b/src/develop/format.c @@ -72,8 +72,7 @@ void default_input_format(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_de if(self->priority > _iop_module_rawprepare) return; - if(piece->pipe->dsc.filters) - dsc->datatype = TYPE_UINT16; + if(piece->pipe->dsc.filters) dsc->datatype = TYPE_UINT16; } void default_output_format(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece, @@ -90,8 +89,7 @@ void default_output_format(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_d if(self->priority >= _iop_module_rawprepare) return; - if(piece->pipe->dsc.filters) - dsc->datatype = TYPE_UINT16; + if(piece->pipe->dsc.filters) dsc->datatype = TYPE_UINT16; } // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh diff --git a/src/develop/format.h b/src/develop/format.h index d3d547f2c324..2f6713680d13 100644 --- a/src/develop/format.h +++ b/src/develop/format.h @@ -25,7 +25,8 @@ struct dt_dev_pixelpipe_iop_t; struct dt_dev_pixelpipe_t; struct dt_iop_module_t; -typedef enum dt_iop_buffer_type_t { +typedef enum dt_iop_buffer_type_t +{ TYPE_UNKNOWN, TYPE_FLOAT, TYPE_UINT16, diff --git a/src/develop/imageop.c b/src/develop/imageop.c index 681ba43df366..8a319c6ce7e3 100644 --- a/src/develop/imageop.c +++ b/src/develop/imageop.c @@ -67,10 +67,10 @@ static dt_develop_blend_params_t _default_blendop_params 0, 0.0f, { 0, 0, 0, 0 }, - { 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, - 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, - 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, - 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f } }; + { 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, + 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, + 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, + 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f } }; static void _iop_panel_label(GtkWidget *lab, dt_iop_module_t *module); @@ -125,14 +125,13 @@ static int default_operation_tags_filter() return 0; } -static void default_commit_params(struct dt_iop_module_t *self, dt_iop_params_t *params, - dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece) +static void default_commit_params(struct dt_iop_module_t *self, dt_iop_params_t *params, dt_dev_pixelpipe_t *pipe, + dt_dev_pixelpipe_iop_t *piece) { memcpy(piece->data, params, self->params_size); } -static void default_init_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, - dt_dev_pixelpipe_iop_t *piece) +static void default_init_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece) { piece->data = malloc(self->params_size); default_commit_params(self, self->default_params, pipe, piece); @@ -225,10 +224,10 @@ int dt_iop_load_module_so(void *m, const char *libname, const char *op) } if(!g_module_symbol(module->module, "dt_module_mod_version", (gpointer) & (module->version))) goto error; if(!g_module_symbol(module->module, "name", (gpointer) & (module->name))) goto error; - if(!g_module_symbol(module->module, "groups", (gpointer) & (module->groups))) - module->groups = default_groups; + if(!g_module_symbol(module->module, "groups", (gpointer) & (module->groups))) module->groups = default_groups; if(!g_module_symbol(module->module, "flags", (gpointer) & (module->flags))) module->flags = default_flags; - if(!g_module_symbol(module->module, "description", (gpointer) & (module->description))) module->description = NULL; + if(!g_module_symbol(module->module, "description", (gpointer) & (module->description))) + module->description = NULL; if(!g_module_symbol(module->module, "operation_tags", (gpointer) & (module->operation_tags))) module->operation_tags = default_operation_tags; if(!g_module_symbol(module->module, "operation_tags_filter", (gpointer) & (module->operation_tags_filter))) @@ -239,18 +238,15 @@ int dt_iop_load_module_so(void *m, const char *libname, const char *op) module->output_format = default_output_format; if(!g_module_symbol(module->module, "tiling_callback", (gpointer) & (module->tiling_callback))) module->tiling_callback = default_tiling_callback; - if(!g_module_symbol(module->module, "gui_reset", (gpointer) & (module->gui_reset))) - module->gui_reset = NULL; + if(!g_module_symbol(module->module, "gui_reset", (gpointer) & (module->gui_reset))) module->gui_reset = NULL; if(!g_module_symbol(module->module, "gui_init", (gpointer) & (module->gui_init))) module->gui_init = NULL; - if(!g_module_symbol(module->module, "gui_update", (gpointer) & (module->gui_update))) - module->gui_update = NULL; + if(!g_module_symbol(module->module, "gui_update", (gpointer) & (module->gui_update))) module->gui_update = NULL; if(!g_module_symbol(module->module, "gui_cleanup", (gpointer) & (module->gui_cleanup))) module->gui_cleanup = default_gui_cleanup; if(!g_module_symbol(module->module, "gui_post_expose", (gpointer) & (module->gui_post_expose))) module->gui_post_expose = NULL; - if(!g_module_symbol(module->module, "gui_focus", (gpointer) & (module->gui_focus))) - module->gui_focus = NULL; + if(!g_module_symbol(module->module, "gui_focus", (gpointer) & (module->gui_focus))) module->gui_focus = NULL; if(!g_module_symbol(module->module, "init_key_accels", (gpointer) & (module->init_key_accels))) module->init_key_accels = NULL; @@ -267,8 +263,7 @@ int dt_iop_load_module_so(void *m, const char *libname, const char *op) module->button_released = NULL; if(!g_module_symbol(module->module, "button_pressed", (gpointer) & (module->button_pressed))) module->button_pressed = NULL; - if(!g_module_symbol(module->module, "configure", (gpointer) & (module->configure))) - module->configure = NULL; + if(!g_module_symbol(module->module, "configure", (gpointer) & (module->configure))) module->configure = NULL; if(!g_module_symbol(module->module, "scrolled", (gpointer) & (module->scrolled))) module->scrolled = NULL; if(!g_module_symbol(module->module, "init", (gpointer) & (module->init))) goto error; @@ -299,8 +294,7 @@ int dt_iop_load_module_so(void *m, const char *libname, const char *op) if(!g_module_symbol(module->module, "process", (gpointer) & (module->process_plain))) goto error; - if(!darktable.opencl->inited - || !g_module_symbol(module->module, "process_cl", (gpointer) & (module->process_cl))) + if(!darktable.opencl->inited || !g_module_symbol(module->module, "process_cl", (gpointer) & (module->process_cl))) module->process_cl = NULL; if(!g_module_symbol(module->module, "process_tiling_cl", (gpointer) & (module->process_tiling_cl))) module->process_tiling_cl = darktable.opencl->inited ? default_process_tiling_cl : NULL; @@ -330,8 +324,7 @@ int dt_iop_load_module_so(void *m, const char *libname, const char *op) module->have_introspection = TRUE; if(!g_module_symbol(module->module, "get_p", (gpointer) & (module->get_p))) goto error; if(!g_module_symbol(module->module, "get_f", (gpointer) & (module->get_f))) goto error; - if(!g_module_symbol(module->module, "get_introspection", (gpointer) & (module->get_introspection))) - goto error; + if(!g_module_symbol(module->module, "get_introspection", (gpointer) & (module->get_introspection))) goto error; if(!g_module_symbol(module->module, "get_introspection_linear", (gpointer) & (module->get_introspection_linear))) goto error; @@ -369,8 +362,7 @@ static int dt_iop_load_module_by_so(dt_iop_module_t *module, dt_iop_module_so_t module->color_picker_box[2] = module->color_picker_box[3] = .75f; module->color_picker_point[0] = module->color_picker_point[1] = 0.5f; module->histogram = NULL; - module->histogram_max[0] = module->histogram_max[1] = module->histogram_max[2] = module->histogram_max[3] - = 0; + module->histogram_max[0] = module->histogram_max[1] = module->histogram_max[2] = module->histogram_max[3] = 0; module->request_mask_display = DT_DEV_PIXELPIPE_DISPLAY_NONE; module->suppress_mask = 0; module->enabled = module->default_enabled = 0; // all modules disabled by default. @@ -648,8 +640,8 @@ static void dt_iop_gui_movedown_callback(GtkButton *button, dt_iop_module_t *mod GValue gv = { 0, { { 0 } } }; g_value_init(&gv, G_TYPE_INT); gtk_container_child_get_property( - GTK_CONTAINER(dt_ui_get_container(darktable.gui->ui, DT_UI_CONTAINER_PANEL_RIGHT_CENTER)), - module->expander, "position", &gv); + GTK_CONTAINER(dt_ui_get_container(darktable.gui->ui, DT_UI_CONTAINER_PANEL_RIGHT_CENTER)), module->expander, + "position", &gv); gtk_box_reorder_child(dt_ui_get_container(darktable.gui->ui, DT_UI_CONTAINER_PANEL_RIGHT_CENTER), module->expander, g_value_get_int(&gv) + 1); @@ -725,8 +717,8 @@ static void dt_iop_gui_moveup_callback(GtkButton *button, dt_iop_module_t *modul GValue gv = { 0, { { 0 } } }; g_value_init(&gv, G_TYPE_INT); gtk_container_child_get_property( - GTK_CONTAINER(dt_ui_get_container(darktable.gui->ui, DT_UI_CONTAINER_PANEL_RIGHT_CENTER)), - module->expander, "position", &gv); + GTK_CONTAINER(dt_ui_get_container(darktable.gui->ui, DT_UI_CONTAINER_PANEL_RIGHT_CENTER)), module->expander, + "position", &gv); gtk_box_reorder_child(dt_ui_get_container(darktable.gui->ui, DT_UI_CONTAINER_PANEL_RIGHT_CENTER), module->expander, g_value_get_int(&gv) - 1); @@ -809,10 +801,10 @@ static void dt_iop_gui_duplicate(dt_iop_module_t *base, gboolean copy_params) GValue gv = { 0, { { 0 } } }; g_value_init(&gv, G_TYPE_INT); gtk_container_child_get_property( - GTK_CONTAINER(dt_ui_get_container(darktable.gui->ui, DT_UI_CONTAINER_PANEL_RIGHT_CENTER)), - base->expander, "position", &gv); - gtk_box_reorder_child(dt_ui_get_container(darktable.gui->ui, DT_UI_CONTAINER_PANEL_RIGHT_CENTER), - expander, g_value_get_int(&gv) + pos_base - pos_module + 1); + GTK_CONTAINER(dt_ui_get_container(darktable.gui->ui, DT_UI_CONTAINER_PANEL_RIGHT_CENTER)), base->expander, + "position", &gv); + gtk_box_reorder_child(dt_ui_get_container(darktable.gui->ui, DT_UI_CONTAINER_PANEL_RIGHT_CENTER), expander, + g_value_get_int(&gv) + pos_base - pos_module + 1); dt_iop_gui_set_expanded(module, TRUE, FALSE); dt_iop_gui_update_blending(module); } @@ -910,7 +902,7 @@ static void dt_iop_gui_multiinstance_callback(GtkButton *button, GdkEventButton gtk_widget_show_all(GTK_WIDGET(menu)); - // popup +// popup #if GTK_CHECK_VERSION(3, 22, 0) gtk_menu_popup_at_pointer(GTK_MENU(menu), NULL); #else @@ -1183,8 +1175,7 @@ static void init_presets(dt_iop_module_so_t *module_so) if(!old_blend_params || dt_develop_blend_version() > old_blend_params_version) { - fprintf(stderr, - "[imageop_init_presets] updating '%s' preset '%s' from blendop version %d to version %d\n", + fprintf(stderr, "[imageop_init_presets] updating '%s' preset '%s' from blendop version %d to version %d\n", module_so->op, name, old_blend_params_version, dt_develop_blend_version()); // we need a dt_iop_module_t for dt_develop_blend_legacy_params() @@ -1206,9 +1197,8 @@ static void init_presets(dt_iop_module_so_t *module_so) // convert the old blend params to new if(old_blend_params - && dt_develop_blend_legacy_params(module, old_blend_params, old_blend_params_version, - new_blend_params, dt_develop_blend_version(), - old_blend_params_size) == 0) + && dt_develop_blend_legacy_params(module, old_blend_params, old_blend_params_version, new_blend_params, + dt_develop_blend_version(), old_blend_params_size) == 0) { // do nothing } @@ -1224,8 +1214,7 @@ static void init_presets(dt_iop_module_so_t *module_so) "WHERE operation=?3 AND name=?4", -1, &stmt2, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt2, 1, dt_develop_blend_version()); - DT_DEBUG_SQLITE3_BIND_BLOB(stmt2, 2, new_blend_params, sizeof(dt_develop_blend_params_t), - SQLITE_TRANSIENT); + DT_DEBUG_SQLITE3_BIND_BLOB(stmt2, 2, new_blend_params, sizeof(dt_develop_blend_params_t), SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_TEXT(stmt2, 3, module->op, -1, SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_TEXT(stmt2, 4, name, -1, SQLITE_TRANSIENT); @@ -1543,8 +1532,7 @@ void dt_iop_request_focus(dt_iop_module_t *module) if(darktable.develop->gui_module->gui_focus) darktable.develop->gui_module->gui_focus(darktable.develop->gui_module, FALSE); - gtk_widget_set_state_flags(dt_iop_gui_get_pluginui(darktable.develop->gui_module), GTK_STATE_FLAG_NORMAL, - TRUE); + gtk_widget_set_state_flags(dt_iop_gui_get_pluginui(darktable.develop->gui_module), GTK_STATE_FLAG_NORMAL, TRUE); // gtk_widget_set_state(darktable.develop->gui_module->topwidget, GTK_STATE_NORMAL); @@ -1737,8 +1725,7 @@ static gboolean _iop_plugin_header_button_press(GtkWidget *w, GdkEventButton *e, if(e->button == 1) { // make gtk scroll to the module once it updated its allocation size - if(dt_conf_get_bool("darkroom/ui/scroll_to_module")) - darktable.gui->scroll_to[1] = module->expander; + if(dt_conf_get_bool("darkroom/ui/scroll_to_module")) darktable.gui->scroll_to[1] = module->expander; gboolean collapse_others = !dt_conf_get_bool("darkroom/ui/single_module") != !(e->state & GDK_SHIFT_MASK); dt_iop_gui_set_expanded(module, !module->expanded, collapse_others); @@ -1796,12 +1783,10 @@ GtkWidget *dt_iop_gui_get_expander(dt_iop_module_t *module) module->header = header; /* setup the header box */ - g_signal_connect(G_OBJECT(header_evb), "button-press-event", G_CALLBACK(_iop_plugin_header_button_press), - module); + g_signal_connect(G_OBJECT(header_evb), "button-press-event", G_CALLBACK(_iop_plugin_header_button_press), module); /* connect mouse button callbacks for focus and presets */ - g_signal_connect(G_OBJECT(body_evb), "button-press-event", G_CALLBACK(_iop_plugin_body_button_press), - module); + g_signal_connect(G_OBJECT(body_evb), "button-press-event", G_CALLBACK(_iop_plugin_body_button_press), module); /* * initialize the header widgets @@ -1828,8 +1813,8 @@ GtkWidget *dt_iop_gui_get_expander(dt_iop_module_t *module) char datadir[PATH_MAX] = { 0 }; dt_loc_get_datadir(datadir, sizeof(datadir)); - // make the icons a little more visible - #define ICON_SIZE (bs * 1.7) +// make the icons a little more visible +#define ICON_SIZE (bs * 1.7) snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/%s.svg", datadir, module->op); pixbuf = load_image(filename, ICON_SIZE); @@ -1847,7 +1832,7 @@ GtkWidget *dt_iop_gui_get_expander(dt_iop_module_t *module) pixbuf = load_image(filename, ICON_SIZE); if(pixbuf) goto got_image; - #undef ICON_SIZE +#undef ICON_SIZE // wow, we could neither load the SVG nor the PNG files. something is fucked up. pixbuf = gdk_pixbuf_new_from_data(fallback_pixel, GDK_COLORSPACE_RGB, TRUE, 8, 1, 1, 4, NULL, NULL); @@ -1962,8 +1947,7 @@ int dt_iop_breakpoint(struct dt_develop_t *dev, struct dt_dev_pixelpipe_t *pipe) { if(pipe != dev->preview_pipe) sched_yield(); if(pipe != dev->preview_pipe && pipe->changed == DT_DEV_PIPE_ZOOMED) return 1; - if((pipe->changed != DT_DEV_PIPE_UNCHANGED && pipe->changed != DT_DEV_PIPE_ZOOMED) || dev->gui_leaving) - return 1; + if((pipe->changed != DT_DEV_PIPE_UNCHANGED && pipe->changed != DT_DEV_PIPE_ZOOMED) || dev->gui_leaving) return 1; return 0; } @@ -2039,8 +2023,7 @@ void dt_iop_connect_common_accels(dt_iop_module_t *module) dt_accel_connect_iop(module, "enable module", closure); // Connecting the reset and preset buttons - if(module->reset_button) - dt_accel_connect_button_iop(module, "reset module parameters", module->reset_button); + if(module->reset_button) dt_accel_connect_button_iop(module, "reset module parameters", module->reset_button); if(module->presets_button) dt_accel_connect_button_iop(module, "show preset menu", module->presets_button); if(module->fusion_slider) dt_accel_connect_slider_iop(module, "fusion", module->fusion_slider); diff --git a/src/develop/imageop.h b/src/develop/imageop.h index 0ac41e7b729d..dbf4712d0717 100644 --- a/src/develop/imageop.h +++ b/src/develop/imageop.h @@ -82,16 +82,15 @@ typedef enum dt_iop_flags_t IOP_FLAGS_SUPPORTS_BLENDING = 1 << 1, // Does provide blending modes IOP_FLAGS_DEPRECATED = 1 << 2, IOP_FLAGS_BLEND_ONLY_LIGHTNESS - = 1 << 3, // Does only blend with L-channel in Lab space. Keeps a, b of original image. + = 1 << 3, // Does only blend with L-channel in Lab space. Keeps a, b of original image. IOP_FLAGS_ALLOW_TILING = 1 << 4, // Does allow tile-wise processing (valid for CPU and GPU processing) IOP_FLAGS_HIDDEN = 1 << 5, // Hide the iop from userinterface IOP_FLAGS_TILING_FULL_ROI = 1 << 6, // Tiling code has to expect arbitrary roi's for this module (incl. flipping, mirroring etc.) - IOP_FLAGS_ONE_INSTANCE = 1 << 7, // The module doesn't support multiple instances - IOP_FLAGS_PREVIEW_NON_OPENCL - = 1 << 8, // Preview pixelpipe of this module must not run on GPU but always on CPU - IOP_FLAGS_NO_HISTORY_STACK = 1 << 9, // This iop will never show up in the history stack - IOP_FLAGS_NO_MASKS = 1 << 10 // The module doesn't support masks (used with SUPPORT_BLENDING) + IOP_FLAGS_ONE_INSTANCE = 1 << 7, // The module doesn't support multiple instances + IOP_FLAGS_PREVIEW_NON_OPENCL = 1 << 8, // Preview pixelpipe of this module must not run on GPU but always on CPU + IOP_FLAGS_NO_HISTORY_STACK = 1 << 9, // This iop will never show up in the history stack + IOP_FLAGS_NO_MASKS = 1 << 10 // The module doesn't support masks (used with SUPPORT_BLENDING) } dt_iop_flags_t; /** status of a module*/ @@ -185,8 +184,8 @@ typedef struct dt_iop_module_so_t int (*mouse_leave)(struct dt_iop_module_t *self); int (*mouse_moved)(struct dt_iop_module_t *self, double x, double y, double pressure, int which); int (*button_released)(struct dt_iop_module_t *self, double x, double y, int which, uint32_t state); - int (*button_pressed)(struct dt_iop_module_t *self, double x, double y, double pressure, int which, - int type, uint32_t state); + int (*button_pressed)(struct dt_iop_module_t *self, double x, double y, double pressure, int which, int type, + uint32_t state); int (*scrolled)(struct dt_iop_module_t *self, double x, double y, int up, uint32_t state); void (*configure)(struct dt_iop_module_t *self, int width, int height); @@ -195,8 +194,8 @@ typedef struct dt_iop_module_so_t void (*cleanup)(struct dt_iop_module_t *self); void (*init_pipe)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_t *pipe, struct dt_dev_pixelpipe_iop_t *piece); - void (*commit_params)(struct dt_iop_module_t *self, dt_iop_params_t *params, - struct dt_dev_pixelpipe_t *pipe, struct dt_dev_pixelpipe_iop_t *piece); + void (*commit_params)(struct dt_iop_module_t *self, dt_iop_params_t *params, struct dt_dev_pixelpipe_t *pipe, + struct dt_dev_pixelpipe_iop_t *piece); void (*reload_defaults)(struct dt_iop_module_t *self); void (*cleanup_pipe)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_t *pipe, struct dt_dev_pixelpipe_iop_t *piece); @@ -210,26 +209,26 @@ typedef struct dt_iop_module_so_t void (*process)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const i, void *const o, const struct dt_iop_roi_t *const roi_in, const struct dt_iop_roi_t *const roi_out); - void (*process_tiling)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const void *const i, void *const o, const struct dt_iop_roi_t *const roi_in, + void (*process_tiling)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const i, + void *const o, const struct dt_iop_roi_t *const roi_in, const struct dt_iop_roi_t *const roi_out, const int bpp); - void (*process_plain)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const void *const i, void *const o, const struct dt_iop_roi_t *const roi_in, + void (*process_plain)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const i, + void *const o, const struct dt_iop_roi_t *const roi_in, const struct dt_iop_roi_t *const roi_out); - void (*process_sse2)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const void *const i, void *const o, const struct dt_iop_roi_t *const roi_in, + void (*process_sse2)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const i, + void *const o, const struct dt_iop_roi_t *const roi_in, const struct dt_iop_roi_t *const roi_out); int (*process_cl)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const i, void *const o, const struct dt_iop_roi_t *const roi_in, const struct dt_iop_roi_t *const roi_out); - int (*process_tiling_cl)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const void *const i, void *const o, const struct dt_iop_roi_t *const roi_in, + int (*process_tiling_cl)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const i, + void *const o, const struct dt_iop_roi_t *const roi_in, const struct dt_iop_roi_t *const roi_out, const int bpp); int (*distort_transform)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, float *points, size_t points_count); - int (*distort_backtransform)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - float *points, size_t points_count); + int (*distort_backtransform)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, float *points, + size_t points_count); // introspection related callbacks gboolean have_introspection; @@ -318,7 +317,7 @@ typedef struct dt_iop_module_t dt_iop_module_so_t *so; /** multi-instances things */ - int multi_priority; // user may change this + int multi_priority; // user may change this char multi_name[128]; // user may change this name gboolean multi_show_close; gboolean multi_show_up; @@ -370,8 +369,8 @@ typedef struct dt_iop_module_t int (*mouse_leave)(struct dt_iop_module_t *self); int (*mouse_moved)(struct dt_iop_module_t *self, double x, double y, double pressure, int which); int (*button_released)(struct dt_iop_module_t *self, double x, double y, int which, uint32_t state); - int (*button_pressed)(struct dt_iop_module_t *self, double x, double y, double pressure, int which, - int type, uint32_t state); + int (*button_pressed)(struct dt_iop_module_t *self, double x, double y, double pressure, int which, int type, + uint32_t state); int (*key_pressed)(struct dt_iop_module_t *self, uint16_t which); int (*scrolled)(struct dt_iop_module_t *self, double x, double y, int up, uint32_t state); void (*configure)(struct dt_iop_module_t *self, int width, int height); @@ -385,8 +384,8 @@ typedef struct dt_iop_module_t /** this resets the params to factory defaults. used at the beginning of each history synch. */ /** this commits (a mutex will be locked to synch pipe/gui) the given history params to the pixelpipe piece. */ - void (*commit_params)(struct dt_iop_module_t *self, dt_iop_params_t *params, - struct dt_dev_pixelpipe_t *pipe, struct dt_dev_pixelpipe_iop_t *piece); + void (*commit_params)(struct dt_iop_module_t *self, dt_iop_params_t *params, struct dt_dev_pixelpipe_t *pipe, + struct dt_dev_pixelpipe_iop_t *piece); /** this is the chance to update default parameters, after the full raw is loaded. */ void (*reload_defaults)(struct dt_iop_module_t *self); /** this destroys all resources needed by the piece of the pixelpipe. */ @@ -408,25 +407,25 @@ typedef struct dt_iop_module_t void *const o, const struct dt_iop_roi_t *const roi_in, const struct dt_iop_roi_t *const roi_out); /** a tiling variant of process(). */ - void (*process_tiling)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const void *const i, void *const o, const struct dt_iop_roi_t *const roi_in, + void (*process_tiling)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const i, + void *const o, const struct dt_iop_roi_t *const roi_in, const struct dt_iop_roi_t *const roi_out, const int bpp); /** WARNING: in IOP implementation, it is called process()!!! */ /** the simplest variant of process(). you can only use OpenMP SIMD here, no intrinsics */ - void (*process_plain)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const void *const i, void *const o, const struct dt_iop_roi_t *const roi_in, + void (*process_plain)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const i, + void *const o, const struct dt_iop_roi_t *const roi_in, const struct dt_iop_roi_t *const roi_out); /** a variant process(), that can contain SSE2 intrinsics. */ - void (*process_sse2)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const void *const i, void *const o, const struct dt_iop_roi_t *const roi_in, + void (*process_sse2)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const i, + void *const o, const struct dt_iop_roi_t *const roi_in, const struct dt_iop_roi_t *const roi_out); /** the opencl equivalent of process(). */ int (*process_cl)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const i, void *const o, const struct dt_iop_roi_t *const roi_in, const struct dt_iop_roi_t *const roi_out); /** a tiling variant of process_cl(). */ - int (*process_tiling_cl)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const void *const i, void *const o, const struct dt_iop_roi_t *const roi_in, + int (*process_tiling_cl)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const i, + void *const o, const struct dt_iop_roi_t *const roi_in, const struct dt_iop_roi_t *const roi_out, const int bpp); /** this functions are used for distort iop @@ -436,8 +435,8 @@ typedef struct dt_iop_module_t int (*distort_transform)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, float *points, size_t points_count); /** reverse points after the iop is applied => point before process */ - int (*distort_backtransform)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - float *points, size_t points_count); + int (*distort_backtransform)(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, float *points, + size_t points_count); /** Key accelerator registration callbacks */ void (*connect_key_accels)(struct dt_iop_module_t *self); diff --git a/src/develop/imageop_math.c b/src/develop/imageop_math.c index 3159e1434a3f..56b403e69824 100644 --- a/src/develop/imageop_math.c +++ b/src/develop/imageop_math.c @@ -29,10 +29,10 @@ #ifdef __SSE__ #include <xmmintrin.h> // for _mm_set_ps, _mm_mul_ps, _mm_set... #endif -#include "common/darktable.h" // for darktable, darktable_t, dt_code... -#include "common/imageio.h" // for FILTERS_ARE_4BAYER -#include "common/interpolation.h" // for dt_interpolation_new, dt_interp... -#include "develop/imageop.h" // for dt_iop_roi_t +#include "common/darktable.h" // for darktable, darktable_t, dt_code... +#include "common/imageio.h" // for FILTERS_ARE_4BAYER +#include "common/interpolation.h" // for dt_interpolation_new, dt_interp... +#include "develop/imageop.h" // for dt_iop_roi_t void dt_iop_flip_and_zoom_8(const uint8_t *in, int32_t iw, int32_t ih, uint8_t *out, int32_t ow, int32_t oh, const dt_image_orientation_t orientation, uint32_t *width, uint32_t *height) @@ -86,8 +86,7 @@ void dt_iop_flip_and_zoom_8(const uint8_t *in, int32_t iw, int32_t ih, uint8_t * for(int k = 0; k < 3; k++) out2[k] = // in3[k]; CLAMP(((int32_t)in3[bpp * half_pixel * sj + k] + (int32_t)in3[bpp * half_pixel * (si + sj) + k] - + (int32_t)in3[bpp * half_pixel * si + k] + (int32_t)in3[k]) - / 4, + + (int32_t)in3[bpp * half_pixel * si + k] + (int32_t)in3[k]) / 4, 0, 255); } out2 += bpp; @@ -97,8 +96,8 @@ void dt_iop_flip_and_zoom_8(const uint8_t *in, int32_t iw, int32_t ih, uint8_t * } void dt_iop_clip_and_zoom_8(const uint8_t *i, int32_t ix, int32_t iy, int32_t iw, int32_t ih, int32_t ibw, - int32_t ibh, uint8_t *o, int32_t ox, int32_t oy, int32_t ow, int32_t oh, - int32_t obw, int32_t obh) + int32_t ibh, uint8_t *o, int32_t ox, int32_t oy, int32_t ow, int32_t oh, int32_t obw, + int32_t obh) { const float scalex = iw / (float)ow; const float scaley = ih / (float)oh; @@ -124,8 +123,7 @@ void dt_iop_clip_and_zoom_8(const uint8_t *i, int32_t ix, int32_t iy, int32_t iw CLAMP(((int32_t)i[(4 * (ibw * (int32_t)y + (int32_t)(x + .5f * scalex)) + k)] + (int32_t)i[(4 * (ibw * (int32_t)(y + .5f * scaley) + (int32_t)(x + .5f * scalex)) + k)] + (int32_t)i[(4 * (ibw * (int32_t)(y + .5f * scaley) + (int32_t)(x)) + k)] - + (int32_t)i[(4 * (ibw * (int32_t)y + (int32_t)(x)) + k)]) - / 4, + + (int32_t)i[(4 * (ibw * (int32_t)y + (int32_t)(x)) + k)]) / 4, 0, 255); x += scalex; idx++; @@ -148,8 +146,7 @@ void dt_iop_clip_and_zoom(float *out, const float *const in, const dt_iop_roi_t // apply clip and zoom on the image region supplied in the input buffer. // roi_in and roi_out describe which part of the full image this relates to. void dt_iop_clip_and_zoom_roi(float *out, const float *const in, const dt_iop_roi_t *const roi_out, - const dt_iop_roi_t *const roi_in, const int32_t out_stride, - const int32_t in_stride) + const dt_iop_roi_t *const roi_in, const int32_t out_stride, const int32_t in_stride) { const struct dt_interpolation *itor = dt_interpolation_new(DT_INTERPOLATION_USERPREF); dt_interpolation_resample_roi(itor, out, roi_out, out_stride * 4 * sizeof(float), in, roi_in, @@ -201,7 +198,7 @@ void dt_iop_clip_and_zoom_mosaic_half_size_plain(uint16_t *const out, const uint // offsets from start of a 2x2 block at which to find that // color. First index is color, second is to the list of offsets, // preceded by the number of offsets. - int clut[4][3] = {{0}}; + int clut[4][3] = { { 0 } }; for(int y = 0; y < 2; ++y) for(int x = 0; x < 2; ++x) { @@ -218,14 +215,14 @@ void dt_iop_clip_and_zoom_mosaic_half_size_plain(uint16_t *const out, const uint uint16_t *outc = out + out_stride * y; const float fy = (y + roi_out->y) * px_footprint; - const int miny = (CLAMPS((int)floorf(fy - px_footprint), 0, roi_in->height-3) & ~1u) + rggby; - const int maxy = MIN(roi_in->height-1, (int)ceilf(fy + px_footprint)); + const int miny = (CLAMPS((int)floorf(fy - px_footprint), 0, roi_in->height - 3) & ~1u) + rggby; + const int maxy = MIN(roi_in->height - 1, (int)ceilf(fy + px_footprint)); float fx = roi_out->x * px_footprint; for(int x = 0; x < roi_out->width; x++, fx += px_footprint, outc++) { - const int minx = (CLAMPS((int)floorf(fx - px_footprint), 0, roi_in->width-3) & ~1u) + rggbx; - const int maxx = MIN(roi_in->width-1, (int)ceilf(fx + px_footprint)); + const int minx = (CLAMPS((int)floorf(fx - px_footprint), 0, roi_in->width - 3) & ~1u) + rggbx; + const int maxx = MIN(roi_in->width - 1, (int)ceilf(fx + px_footprint)); const int c = FC(y, x, filters); int num = 0; @@ -236,7 +233,7 @@ void dt_iop_clip_and_zoom_mosaic_half_size_plain(uint16_t *const out, const uint { col += in[clut[c][1] + xx + in_stride * yy]; num++; - if (clut[c][0] == 2) + if(clut[c][0] == 2) { // G in RGGB CFA col += in[clut[c][2] + xx + in_stride * yy]; num++; @@ -447,7 +444,7 @@ void dt_iop_clip_and_zoom_mosaic_half_size(uint16_t *const out, const uint16_t * const int32_t out_stride, const int32_t in_stride, const uint32_t filters) { - if(1)//(darktable.codepath.OPENMP_SIMD) + if(1) //(darktable.codepath.OPENMP_SIMD) return dt_iop_clip_and_zoom_mosaic_half_size_plain(out, in, roi_out, roi_in, out_stride, in_stride, filters); #if defined(__SSE__) else if(darktable.codepath.SSE2) @@ -863,9 +860,9 @@ void dt_iop_clip_and_zoom_mosaic_third_size_xtrans(uint16_t *const out, const ui const int32_t in_stride, const uint8_t (*const xtrans)[6]) { const float px_footprint = 1.f / roi_out->scale; - // Use box filter of width px_footprint*2+1 centered on the current - // sample (rounded to nearest input pixel) to anti-alias. Higher MP - // images need larger filters to avoid artifacts. +// Use box filter of width px_footprint*2+1 centered on the current +// sample (rounded to nearest input pixel) to anti-alias. Higher MP +// images need larger filters to avoid artifacts. #ifdef _OPENMP #pragma omp parallel for default(none) schedule(static) #endif @@ -875,13 +872,13 @@ void dt_iop_clip_and_zoom_mosaic_third_size_xtrans(uint16_t *const out, const ui const float fy = (y + roi_out->y) * px_footprint; const int miny = MAX(0, (int)roundf(fy - px_footprint)); - const int maxy = MIN(roi_in->height-1, (int)roundf(fy + px_footprint)); + const int maxy = MIN(roi_in->height - 1, (int)roundf(fy + px_footprint)); float fx = roi_out->x * px_footprint; for(int x = 0; x < roi_out->width; x++, fx += px_footprint, outc++) { const int minx = MAX(0, (int)roundf(fx - px_footprint)); - const int maxx = MIN(roi_in->width-1, (int)roundf(fx + px_footprint)); + const int maxx = MIN(roi_in->width - 1, (int)roundf(fx + px_footprint)); const int c = FCxtrans(y, x, roi_out, xtrans); int num = 0; @@ -914,13 +911,13 @@ void dt_iop_clip_and_zoom_mosaic_third_size_xtrans_f(float *const out, const flo const float fy = (y + roi_out->y) * px_footprint; const int miny = MAX(0, (int)roundf(fy - px_footprint)); - const int maxy = MIN(roi_in->height-1, (int)roundf(fy + px_footprint)); + const int maxy = MIN(roi_in->height - 1, (int)roundf(fy + px_footprint)); float fx = roi_out->x * px_footprint; for(int x = 0; x < roi_out->width; x++, fx += px_footprint, outc++) { const int minx = MAX(0, (int)roundf(fx - px_footprint)); - const int maxx = MIN(roi_in->width-1, (int)roundf(fx + px_footprint)); + const int maxx = MIN(roi_in->width - 1, (int)roundf(fx + px_footprint)); const int c = FCxtrans(y, x, roi_out, xtrans); int num = 0; @@ -1083,8 +1080,7 @@ void dt_iop_clip_and_zoom_demosaic_passthrough_monochrome_f_plain(float *out, co void dt_iop_clip_and_zoom_demosaic_passthrough_monochrome_f_sse2(float *out, const float *const in, const dt_iop_roi_t *const roi_out, const dt_iop_roi_t *const roi_in, - const int32_t out_stride, - const int32_t in_stride) + const int32_t out_stride, const int32_t in_stride) { // adjust to pixel region and don't sample more than scale/2 nbs! // pixel footprint on input buffer, radius: @@ -1696,20 +1692,19 @@ void dt_iop_clip_and_zoom_demosaic_half_size_f(float *out, const float *const in void dt_iop_clip_and_zoom_demosaic_third_size_xtrans_f(float *out, const float *const in, const dt_iop_roi_t *const roi_out, - const dt_iop_roi_t *const roi_in, - const int32_t out_stride, const int32_t in_stride, - const uint8_t (*const xtrans)[6]) + const dt_iop_roi_t *const roi_in, const int32_t out_stride, + const int32_t in_stride, const uint8_t (*const xtrans)[6]) { const float px_footprint = 1.f / roi_out->scale; const int samples = MAX(1, (int)floorf(px_footprint / 3)); - // A slightly different algorithm than - // dt_iop_clip_and_zoom_demosaic_half_size_f() which aligns to 2x2 - // Bayer grid and hence most pull additional data from all edges - // which don't align with CFA. Instead align to a 3x3 pattern (which - // is semi-regular in X-Trans CFA). This code doesn't worry about - // fractional pixel offset of top/left of pattern nor oversampling - // by non-integer number of samples. +// A slightly different algorithm than +// dt_iop_clip_and_zoom_demosaic_half_size_f() which aligns to 2x2 +// Bayer grid and hence most pull additional data from all edges +// which don't align with CFA. Instead align to a 3x3 pattern (which +// is semi-regular in X-Trans CFA). This code doesn't worry about +// fractional pixel offset of top/left of pattern nor oversampling +// by non-integer number of samples. #ifdef _OPENMP #pragma omp parallel for default(none) shared(out) schedule(static) @@ -1772,56 +1767,40 @@ static inline void mat4inv(const float X[][4], float R[][4]) + X[0][2] * X[1][0] * X[2][1] * X[3][3] - X[0][0] * X[1][2] * X[2][1] * X[3][3] - X[0][1] * X[1][0] * X[2][2] * X[3][3] + X[0][0] * X[1][1] * X[2][2] * X[3][3]; R[0][0] = (X[1][2] * X[2][3] * X[3][1] - X[1][3] * X[2][2] * X[3][1] + X[1][3] * X[2][1] * X[3][2] - - X[1][1] * X[2][3] * X[3][2] - X[1][2] * X[2][1] * X[3][3] + X[1][1] * X[2][2] * X[3][3]) - / det; + - X[1][1] * X[2][3] * X[3][2] - X[1][2] * X[2][1] * X[3][3] + X[1][1] * X[2][2] * X[3][3]) / det; R[1][0] = (X[1][3] * X[2][2] * X[3][0] - X[1][2] * X[2][3] * X[3][0] - X[1][3] * X[2][0] * X[3][2] - + X[1][0] * X[2][3] * X[3][2] + X[1][2] * X[2][0] * X[3][3] - X[1][0] * X[2][2] * X[3][3]) - / det; + + X[1][0] * X[2][3] * X[3][2] + X[1][2] * X[2][0] * X[3][3] - X[1][0] * X[2][2] * X[3][3]) / det; R[2][0] = (X[1][1] * X[2][3] * X[3][0] - X[1][3] * X[2][1] * X[3][0] + X[1][3] * X[2][0] * X[3][1] - - X[1][0] * X[2][3] * X[3][1] - X[1][1] * X[2][0] * X[3][3] + X[1][0] * X[2][1] * X[3][3]) - / det; + - X[1][0] * X[2][3] * X[3][1] - X[1][1] * X[2][0] * X[3][3] + X[1][0] * X[2][1] * X[3][3]) / det; R[3][0] = (X[1][2] * X[2][1] * X[3][0] - X[1][1] * X[2][2] * X[3][0] - X[1][2] * X[2][0] * X[3][1] - + X[1][0] * X[2][2] * X[3][1] + X[1][1] * X[2][0] * X[3][2] - X[1][0] * X[2][1] * X[3][2]) - / det; + + X[1][0] * X[2][2] * X[3][1] + X[1][1] * X[2][0] * X[3][2] - X[1][0] * X[2][1] * X[3][2]) / det; R[0][1] = (X[0][3] * X[2][2] * X[3][1] - X[0][2] * X[2][3] * X[3][1] - X[0][3] * X[2][1] * X[3][2] - + X[0][1] * X[2][3] * X[3][2] + X[0][2] * X[2][1] * X[3][3] - X[0][1] * X[2][2] * X[3][3]) - / det; + + X[0][1] * X[2][3] * X[3][2] + X[0][2] * X[2][1] * X[3][3] - X[0][1] * X[2][2] * X[3][3]) / det; R[1][1] = (X[0][2] * X[2][3] * X[3][0] - X[0][3] * X[2][2] * X[3][0] + X[0][3] * X[2][0] * X[3][2] - - X[0][0] * X[2][3] * X[3][2] - X[0][2] * X[2][0] * X[3][3] + X[0][0] * X[2][2] * X[3][3]) - / det; + - X[0][0] * X[2][3] * X[3][2] - X[0][2] * X[2][0] * X[3][3] + X[0][0] * X[2][2] * X[3][3]) / det; R[2][1] = (X[0][3] * X[2][1] * X[3][0] - X[0][1] * X[2][3] * X[3][0] - X[0][3] * X[2][0] * X[3][1] - + X[0][0] * X[2][3] * X[3][1] + X[0][1] * X[2][0] * X[3][3] - X[0][0] * X[2][1] * X[3][3]) - / det; + + X[0][0] * X[2][3] * X[3][1] + X[0][1] * X[2][0] * X[3][3] - X[0][0] * X[2][1] * X[3][3]) / det; R[3][1] = (X[0][1] * X[2][2] * X[3][0] - X[0][2] * X[2][1] * X[3][0] + X[0][2] * X[2][0] * X[3][1] - - X[0][0] * X[2][2] * X[3][1] - X[0][1] * X[2][0] * X[3][2] + X[0][0] * X[2][1] * X[3][2]) - / det; + - X[0][0] * X[2][2] * X[3][1] - X[0][1] * X[2][0] * X[3][2] + X[0][0] * X[2][1] * X[3][2]) / det; R[0][2] = (X[0][2] * X[1][3] * X[3][1] - X[0][3] * X[1][2] * X[3][1] + X[0][3] * X[1][1] * X[3][2] - - X[0][1] * X[1][3] * X[3][2] - X[0][2] * X[1][1] * X[3][3] + X[0][1] * X[1][2] * X[3][3]) - / det; + - X[0][1] * X[1][3] * X[3][2] - X[0][2] * X[1][1] * X[3][3] + X[0][1] * X[1][2] * X[3][3]) / det; R[1][2] = (X[0][3] * X[1][2] * X[3][0] - X[0][2] * X[1][3] * X[3][0] - X[0][3] * X[1][0] * X[3][2] - + X[0][0] * X[1][3] * X[3][2] + X[0][2] * X[1][0] * X[3][3] - X[0][0] * X[1][2] * X[3][3]) - / det; + + X[0][0] * X[1][3] * X[3][2] + X[0][2] * X[1][0] * X[3][3] - X[0][0] * X[1][2] * X[3][3]) / det; R[2][2] = (X[0][1] * X[1][3] * X[3][0] - X[0][3] * X[1][1] * X[3][0] + X[0][3] * X[1][0] * X[3][1] - - X[0][0] * X[1][3] * X[3][1] - X[0][1] * X[1][0] * X[3][3] + X[0][0] * X[1][1] * X[3][3]) - / det; + - X[0][0] * X[1][3] * X[3][1] - X[0][1] * X[1][0] * X[3][3] + X[0][0] * X[1][1] * X[3][3]) / det; R[3][2] = (X[0][2] * X[1][1] * X[3][0] - X[0][1] * X[1][2] * X[3][0] - X[0][2] * X[1][0] * X[3][1] - + X[0][0] * X[1][2] * X[3][1] + X[0][1] * X[1][0] * X[3][2] - X[0][0] * X[1][1] * X[3][2]) - / det; + + X[0][0] * X[1][2] * X[3][1] + X[0][1] * X[1][0] * X[3][2] - X[0][0] * X[1][1] * X[3][2]) / det; R[0][3] = (X[0][3] * X[1][2] * X[2][1] - X[0][2] * X[1][3] * X[2][1] - X[0][3] * X[1][1] * X[2][2] - + X[0][1] * X[1][3] * X[2][2] + X[0][2] * X[1][1] * X[2][3] - X[0][1] * X[1][2] * X[2][3]) - / det; + + X[0][1] * X[1][3] * X[2][2] + X[0][2] * X[1][1] * X[2][3] - X[0][1] * X[1][2] * X[2][3]) / det; R[1][3] = (X[0][2] * X[1][3] * X[2][0] - X[0][3] * X[1][2] * X[2][0] + X[0][3] * X[1][0] * X[2][2] - - X[0][0] * X[1][3] * X[2][2] - X[0][2] * X[1][0] * X[2][3] + X[0][0] * X[1][2] * X[2][3]) - / det; + - X[0][0] * X[1][3] * X[2][2] - X[0][2] * X[1][0] * X[2][3] + X[0][0] * X[1][2] * X[2][3]) / det; R[2][3] = (X[0][3] * X[1][1] * X[2][0] - X[0][1] * X[1][3] * X[2][0] - X[0][3] * X[1][0] * X[2][1] - + X[0][0] * X[1][3] * X[2][1] + X[0][1] * X[1][0] * X[2][3] - X[0][0] * X[1][1] * X[2][3]) - / det; + + X[0][0] * X[1][3] * X[2][1] + X[0][1] * X[1][0] * X[2][3] - X[0][0] * X[1][1] * X[2][3]) / det; R[3][3] = (X[0][1] * X[1][2] * X[2][0] - X[0][2] * X[1][1] * X[2][0] + X[0][2] * X[1][0] * X[2][1] - - X[0][0] * X[1][2] * X[2][1] - X[0][1] * X[1][0] * X[2][2] + X[0][0] * X[1][1] * X[2][2]) - / det; + - X[0][0] * X[1][2] * X[2][1] - X[0][1] * X[1][0] * X[2][2] + X[0][0] * X[1][1] * X[2][2]) / det; } static void mat4mulv(float *dst, float mat[][4], const float *const v) diff --git a/src/develop/imageop_math.h b/src/develop/imageop_math.h index 6102ed23da3f..950de6a5dbb8 100644 --- a/src/develop/imageop_math.h +++ b/src/develop/imageop_math.h @@ -43,12 +43,10 @@ void dt_iop_clip_and_zoom_roi(float *out, const float *const in, const struct dt const struct dt_iop_roi_t *const roi_in, const int32_t out_stride, const int32_t in_stride); #ifdef HAVE_OPENCL -int dt_iop_clip_and_zoom_cl(int devid, cl_mem dev_out, cl_mem dev_in, - const struct dt_iop_roi_t *const roi_out, +int dt_iop_clip_and_zoom_cl(int devid, cl_mem dev_out, cl_mem dev_in, const struct dt_iop_roi_t *const roi_out, const struct dt_iop_roi_t *const roi_in); -int dt_iop_clip_and_zoom_roi_cl(int devid, cl_mem dev_out, cl_mem dev_in, - const struct dt_iop_roi_t *const roi_out, +int dt_iop_clip_and_zoom_roi_cl(int devid, cl_mem dev_out, cl_mem dev_in, const struct dt_iop_roi_t *const roi_out, const struct dt_iop_roi_t *const roi_in); #endif @@ -75,8 +73,7 @@ void dt_iop_clip_and_zoom_mosaic_third_size_xtrans_f(float *const out, const flo void dt_iop_clip_and_zoom_demosaic_passthrough_monochrome_f(float *out, const float *const in, const struct dt_iop_roi_t *const roi_out, const struct dt_iop_roi_t *const roi_in, - const int32_t out_stride, - const int32_t in_stride); + const int32_t out_stride, const int32_t in_stride); void dt_iop_clip_and_zoom_demosaic_half_size_f(float *out, const float *const in, const struct dt_iop_roi_t *const roi_out, @@ -93,8 +90,8 @@ void dt_iop_clip_and_zoom_demosaic_third_size_xtrans_f(float *out, const float * /** as dt_iop_clip_and_zoom, but for rgba 8-bit channels. */ void dt_iop_clip_and_zoom_8(const uint8_t *i, int32_t ix, int32_t iy, int32_t iw, int32_t ih, int32_t ibw, - int32_t ibh, uint8_t *o, int32_t ox, int32_t oy, int32_t ow, int32_t oh, - int32_t obw, int32_t obh); + int32_t ibh, uint8_t *o, int32_t ox, int32_t oy, int32_t ow, int32_t oh, int32_t obw, + int32_t obh); void dt_iop_YCbCr_to_RGB(const float *yuv, float *rgb); void dt_iop_RGB_to_YCbCr(const float *rgb, float *yuv); diff --git a/src/develop/lightroom.c b/src/develop/lightroom.c index fbafb6ace3ed..2cf8141fd6b4 100644 --- a/src/develop/lightroom.c +++ b/src/develop/lightroom.c @@ -245,17 +245,14 @@ char *dt_get_lightroom_xmp(int imgid) // Look for extension char *pos = strrchr(pathname, '.'); - if(pos == NULL) - return NULL; + if(pos == NULL) return NULL; // If found, replace extension with xmp strncpy(pos + 1, "xmp", 4); - if(g_file_test(pathname, G_FILE_TEST_EXISTS)) - return g_strdup(pathname); + if(g_file_test(pathname, G_FILE_TEST_EXISTS)) return g_strdup(pathname); strncpy(pos + 1, "XMP", 4); - if(g_file_test(pathname, G_FILE_TEST_EXISTS)) - return g_strdup(pathname); + if(g_file_test(pathname, G_FILE_TEST_EXISTS)) return g_strdup(pathname); return NULL; } @@ -268,13 +265,12 @@ static float get_interpolate(lr2dt_t lr2dt_table[], float value) return lr2dt_table[k].dt + ((value - lr2dt_table[k].lr) / (lr2dt_table[k + 1].lr - lr2dt_table[k].lr)) - * (lr2dt_table[k + 1].dt - lr2dt_table[k].dt); + * (lr2dt_table[k + 1].dt - lr2dt_table[k].dt); } static float lr2dt_blacks(float value) { - lr2dt_t lr2dt_blacks_table[] - = { { -100, 0.020 }, { -50, 0.005 }, { 0, 0 }, { 50, -0.005 }, { 100, -0.010 } }; + lr2dt_t lr2dt_blacks_table[] = { { -100, 0.020 }, { -50, 0.005 }, { 0, 0 }, { 50, -0.005 }, { 100, -0.010 } }; return get_interpolate(lr2dt_blacks_table, value); } @@ -329,8 +325,8 @@ static void dt_add_hist(int imgid, char *operation, dt_iop_params_t *params, int // get current num if any sqlite3_stmt *stmt; - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), - "SELECT COUNT(*) FROM main.history WHERE imgid = ?1", -1, &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT COUNT(*) FROM main.history WHERE imgid = ?1", + -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); if(sqlite3_step(stmt) == SQLITE_ROW) { @@ -358,7 +354,8 @@ static void dt_add_hist(int imgid, char *operation, dt_iop_params_t *params, int // also bump history_end DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "UPDATE main.images SET history_end = (SELECT IFNULL(MAX(num) + 1, 0) FROM " - "main.history WHERE imgid = ?1) WHERE id = ?1", -1, &stmt, NULL); + "main.history WHERE imgid = ?1) WHERE id = ?1", + -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); sqlite3_step(stmt); sqlite3_finalize(stmt); @@ -458,16 +455,16 @@ void dt_lightroom_import(int imgid, dt_develop_t *dev, gboolean iauto) } xmlFree(value); } -// we could bail out here if we ONLY wanted to load a file known to be from lightroom. -// if we don't know who created it we will just import it however. -// else -// { -// xmlXPathFreeObject(xpathObj); -// xmlXPathFreeContext(xpathCtx); -// if(!iauto) dt_control_log(_("`%s' not a lightroom XMP!"), pathname); -// g_free(pathname); -// return; -// } + // we could bail out here if we ONLY wanted to load a file known to be from lightroom. + // if we don't know who created it we will just import it however. + // else + // { + // xmlXPathFreeObject(xpathObj); + // xmlXPathFreeContext(xpathCtx); + // if(!iauto) dt_control_log(_("`%s' not a lightroom XMP!"), pathname); + // g_free(pathname); + // return; + // } xmlXPathFreeObject(xpathObj); xmlXPathFreeContext(xpathCtx); @@ -1208,8 +1205,8 @@ void dt_lightroom_import(int imgid, dt_develop_t *dev, gboolean iauto) break; } - dt_add_hist(imgid, "flip", (dt_iop_params_t *)&pf, sizeof(dt_iop_flip_params_t), imported, - sizeof(imported), LRDT_FLIP_VERSION, &n_import); + dt_add_hist(imgid, "flip", (dt_iop_params_t *)&pf, sizeof(dt_iop_flip_params_t), imported, sizeof(imported), + LRDT_FLIP_VERSION, &n_import); refresh_needed = TRUE; } @@ -1224,8 +1221,8 @@ void dt_lightroom_import(int imgid, dt_develop_t *dev, gboolean iauto) { pg.channel = 0; - dt_add_hist(imgid, "grain", (dt_iop_params_t *)&pg, sizeof(dt_iop_grain_params_t), imported, - sizeof(imported), LRDT_GRAIN_VERSION, &n_import); + dt_add_hist(imgid, "grain", (dt_iop_params_t *)&pg, sizeof(dt_iop_grain_params_t), imported, sizeof(imported), + LRDT_GRAIN_VERSION, &n_import); refresh_needed = TRUE; } @@ -1279,14 +1276,13 @@ void dt_lightroom_import(int imgid, dt_develop_t *dev, gboolean iauto) ps.spot[k].xc = tmp; } - dt_add_hist(imgid, "spots", (dt_iop_params_t *)&ps, sizeof(dt_iop_spots_params_t), imported, - sizeof(imported), LRDT_SPOTS_VERSION, &n_import); + dt_add_hist(imgid, "spots", (dt_iop_params_t *)&ps, sizeof(dt_iop_spots_params_t), imported, sizeof(imported), + LRDT_SPOTS_VERSION, &n_import); refresh_needed = TRUE; } - if(dev != NULL && - (curve_kind != linear - || ptc_value[0] != 0 || ptc_value[1] != 0 || ptc_value[2] != 0 || ptc_value[3] != 0)) + if(dev != NULL + && (curve_kind != linear || ptc_value[0] != 0 || ptc_value[1] != 0 || ptc_value[2] != 0 || ptc_value[3] != 0)) { const int total_pts = (curve_kind == custom) ? n_pts : 6; ptc.tonecurve_nodes[ch_L] = total_pts; @@ -1341,10 +1337,8 @@ void dt_lightroom_import(int imgid, dt_develop_t *dev, gboolean iauto) ptc.tonecurve[ch_L][3].y += ptc.tonecurve[ch_L][3].y * ((float)ptc_value[2] / 100.0); ptc.tonecurve[ch_L][4].y += ptc.tonecurve[ch_L][4].y * ((float)ptc_value[3] / 100.0); - if(ptc.tonecurve[ch_L][1].y > ptc.tonecurve[ch_L][2].y) - ptc.tonecurve[ch_L][1].y = ptc.tonecurve[ch_L][2].y; - if(ptc.tonecurve[ch_L][3].y > ptc.tonecurve[ch_L][4].y) - ptc.tonecurve[ch_L][4].y = ptc.tonecurve[ch_L][3].y; + if(ptc.tonecurve[ch_L][1].y > ptc.tonecurve[ch_L][2].y) ptc.tonecurve[ch_L][1].y = ptc.tonecurve[ch_L][2].y; + if(ptc.tonecurve[ch_L][3].y > ptc.tonecurve[ch_L][4].y) ptc.tonecurve[ch_L][4].y = ptc.tonecurve[ch_L][3].y; } dt_add_hist(imgid, "tonecurve", (dt_iop_params_t *)&ptc, sizeof(dt_iop_tonecurve_params_t), imported, @@ -1378,8 +1372,8 @@ void dt_lightroom_import(int imgid, dt_develop_t *dev, gboolean iauto) pbl.sigma_r = 100.0; pbl.sigma_s = 100.0; - dt_add_hist(imgid, "bilat", (dt_iop_params_t *)&pbl, sizeof(dt_iop_bilat_params_t), imported, - sizeof(imported), LRDT_BILAT_VERSION, &n_import); + dt_add_hist(imgid, "bilat", (dt_iop_params_t *)&pbl, sizeof(dt_iop_bilat_params_t), imported, sizeof(imported), + LRDT_BILAT_VERSION, &n_import); refresh_needed = TRUE; } diff --git a/src/develop/masks.h b/src/develop/masks.h index bb59bea6d965..cab6c6bfe951 100644 --- a/src/develop/masks.h +++ b/src/develop/masks.h @@ -230,8 +230,8 @@ int dt_masks_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, float * float **border, int *border_count, int source); /** get the rectangle which include the form and his border */ -int dt_masks_get_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); +int dt_masks_get_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); int dt_masks_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); /** get the transparency mask of the form and his border */ @@ -279,12 +279,10 @@ void dt_masks_clear_form_gui(dt_develop_t *dev); void dt_masks_reset_form_gui(void); void dt_masks_reset_show_masks_icons(void); -int dt_masks_events_mouse_moved(struct dt_iop_module_t *module, double x, double y, double pressure, - int which); -int dt_masks_events_button_released(struct dt_iop_module_t *module, double x, double y, int which, - uint32_t state); -int dt_masks_events_button_pressed(struct dt_iop_module_t *module, double x, double y, double pressure, - int which, int type, uint32_t state); +int dt_masks_events_mouse_moved(struct dt_iop_module_t *module, double x, double y, double pressure, int which); +int dt_masks_events_button_released(struct dt_iop_module_t *module, double x, double y, int which, uint32_t state); +int dt_masks_events_button_pressed(struct dt_iop_module_t *module, double x, double y, double pressure, int which, + int type, uint32_t state); int dt_masks_events_mouse_scrolled(struct dt_iop_module_t *module, double x, double y, int up, uint32_t state); void dt_masks_events_post_expose(struct dt_iop_module_t *module, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, int32_t pointery); @@ -314,25 +312,25 @@ int dt_masks_form_duplicate(dt_develop_t *dev, int formid); /** utils functions */ int dt_masks_point_in_form_exact(float x, float y, float *points, int points_start, int points_count); -int dt_masks_point_in_form_near(float x, float y, float *points, int points_start, int points_count, float distance, int *near); +int dt_masks_point_in_form_near(float x, float y, float *points, int points_start, int points_count, + float distance, int *near); /** code for dynamic handling of intermediate buffers */ -static inline -dt_masks_dynbuf_t *dt_masks_dynbuf_init(size_t size, const char *tag) +static inline dt_masks_dynbuf_t *dt_masks_dynbuf_init(size_t size, const char *tag) { assert(size > 0); dt_masks_dynbuf_t *a = (dt_masks_dynbuf_t *)calloc(1, sizeof(dt_masks_dynbuf_t)); if(a != NULL) { - strncpy(a->tag, tag, sizeof(a->tag)); //only for debugging purposes - a->tag[sizeof(a->tag)-1] = '\0'; + strncpy(a->tag, tag, sizeof(a->tag)); // only for debugging purposes + a->tag[sizeof(a->tag) - 1] = '\0'; a->pos = 0; a->size = size; a->buffer = (float *)malloc(size * sizeof(float)); - dt_print(DT_DEBUG_MASKS, "[masks dynbuf '%s'] with initial size %lu (is %p)\n", a->tag, - (unsigned long)a->size, a->buffer); + dt_print(DT_DEBUG_MASKS, "[masks dynbuf '%s'] with initial size %lu (is %p)\n", a->tag, (unsigned long)a->size, + a->buffer); if(a->buffer == NULL) { free(a); @@ -342,8 +340,7 @@ dt_masks_dynbuf_t *dt_masks_dynbuf_init(size_t size, const char *tag) return a; } -static inline -void dt_masks_dynbuf_add(dt_masks_dynbuf_t *a, float value) +static inline void dt_masks_dynbuf_add(dt_masks_dynbuf_t *a, float value) { assert(a != NULL); assert(a->pos <= a->size); @@ -369,8 +366,7 @@ void dt_masks_dynbuf_add(dt_masks_dynbuf_t *a, float value) a->buffer[a->pos++] = value; } -static inline -float dt_masks_dynbuf_get(dt_masks_dynbuf_t *a, int offset) +static inline float dt_masks_dynbuf_get(dt_masks_dynbuf_t *a, int offset) { assert(a != NULL); // offset: must be negative distance relative to end of buffer @@ -379,8 +375,7 @@ float dt_masks_dynbuf_get(dt_masks_dynbuf_t *a, int offset) return (a->buffer[a->pos + offset]); } -static inline -void dt_masks_dynbuf_set(dt_masks_dynbuf_t *a, int offset, float value) +static inline void dt_masks_dynbuf_set(dt_masks_dynbuf_t *a, int offset, float value) { assert(a != NULL); // offset: must be negative distance relative to end of buffer @@ -389,29 +384,25 @@ void dt_masks_dynbuf_set(dt_masks_dynbuf_t *a, int offset, float value) a->buffer[a->pos + offset] = value; } -static inline -float *dt_masks_dynbuf_buffer(dt_masks_dynbuf_t *a) +static inline float *dt_masks_dynbuf_buffer(dt_masks_dynbuf_t *a) { assert(a != NULL); return a->buffer; } -static inline -size_t dt_masks_dynbuf_position(dt_masks_dynbuf_t *a) +static inline size_t dt_masks_dynbuf_position(dt_masks_dynbuf_t *a) { assert(a != NULL); return a->pos; } -static inline -void dt_masks_dynbuf_reset(dt_masks_dynbuf_t *a) +static inline void dt_masks_dynbuf_reset(dt_masks_dynbuf_t *a) { assert(a != NULL); a->pos = 0; } -static inline -float *dt_masks_dynbuf_harvest(dt_masks_dynbuf_t *a) +static inline float *dt_masks_dynbuf_harvest(dt_masks_dynbuf_t *a) { // take out data buffer and make dynamic buffer obsolete if(a == NULL) return NULL; @@ -421,12 +412,10 @@ float *dt_masks_dynbuf_harvest(dt_masks_dynbuf_t *a) return r; } -static inline -void dt_masks_dynbuf_free(dt_masks_dynbuf_t *a) +static inline void dt_masks_dynbuf_free(dt_masks_dynbuf_t *a) { if(a == NULL) return; - dt_print(DT_DEBUG_MASKS, "[masks dynbuf '%s'] freed (was %p)\n", a->tag, - a->buffer); + dt_print(DT_DEBUG_MASKS, "[masks dynbuf '%s'] freed (was %p)\n", a->tag, a->buffer); free(a->buffer); free(a); } diff --git a/src/develop/masks/brush.c b/src/develop/masks/brush.c index 532c2d2c1270..881a1a055b8f 100644 --- a/src/develop/masks/brush.c +++ b/src/develop/masks/brush.c @@ -118,8 +118,8 @@ static GList *_brush_ramer_douglas_peucker(const float *points, int points_count if(dmax2 >= epsilon2) { GList *ResultList1 = _brush_ramer_douglas_peucker(points, index + 1, payload, epsilon2); - GList *ResultList2 = _brush_ramer_douglas_peucker(points + index * 2, points_count - index, - payload + index * 4, epsilon2); + GList *ResultList2 + = _brush_ramer_douglas_peucker(points + index * 2, points_count - index, payload + index * 4, epsilon2); // remove last element from ResultList1 GList *end1 = g_list_last(ResultList1); @@ -155,15 +155,15 @@ static GList *_brush_ramer_douglas_peucker(const float *points, int points_count } /** get the point of the brush at pos t [0,1] */ -static void _brush_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 _brush_get_XY(float p0x, float p0y, float p1x, float p1y, float p2x, float p2y, float p3x, float p3y, + float t, float *x, float *y) { float a = (1 - t) * (1 - t) * (1 - t); float b = 3 * t * (1 - t) * (1 - t); float c = 3 * t * t * (1 - t); float d = t * t * t; - *x = p0x * a + p1x * b + p2x * c + p3x * d; - *y = p0y * a + p1y * b + p2y * c + p3y * d; + *x = p0x *a + p1x *b + p2x *c + p3x *d; + *y = p0y *a + p1y *b + p2y *c + p3y *d; } /** get the point of the brush at pos t [0,1] AND the corresponding border point */ @@ -196,8 +196,7 @@ static void _brush_border_get_XY(float p0x, float p0y, float p1x, float p1y, flo /** get feather extremity from the control point n°2 */ /** the values should be in orthonormal space */ -static void _brush_ctrl2_to_feather(int ptx, int pty, int ctrlx, int ctrly, int *fx, int *fy, - gboolean clockwise) +static void _brush_ctrl2_to_feather(int ptx, int pty, int ctrlx, int ctrly, int *fx, int *fy, gboolean clockwise) { if(clockwise) { @@ -259,14 +258,14 @@ static void _brush_init_ctrl_points(dt_masks_form_t *form) if(point3->state & DT_MASKS_POINT_STATE_NORMAL) { // we want to get point-2, point-1, point+1, point+2 - dt_masks_point_brush_t *point1 - = k - 2 >= 0 ? (dt_masks_point_brush_t *)g_list_nth_data(form->points, k - 2) : NULL; - dt_masks_point_brush_t *point2 - = k - 1 >= 0 ? (dt_masks_point_brush_t *)g_list_nth_data(form->points, k - 1) : NULL; - dt_masks_point_brush_t *point4 - = k + 1 < nb ? (dt_masks_point_brush_t *)g_list_nth_data(form->points, k + 1) : NULL; - dt_masks_point_brush_t *point5 - = k + 2 < nb ? (dt_masks_point_brush_t *)g_list_nth_data(form->points, k + 2) : NULL; + dt_masks_point_brush_t *point1 = k - 2 >= 0 ? (dt_masks_point_brush_t *)g_list_nth_data(form->points, k - 2) + : NULL; + dt_masks_point_brush_t *point2 = k - 1 >= 0 ? (dt_masks_point_brush_t *)g_list_nth_data(form->points, k - 1) + : NULL; + dt_masks_point_brush_t *point4 = k + 1 < nb ? (dt_masks_point_brush_t *)g_list_nth_data(form->points, k + 1) + : NULL; + dt_masks_point_brush_t *point5 = k + 2 < nb ? (dt_masks_point_brush_t *)g_list_nth_data(form->points, k + 2) + : NULL; // deal with end points: make both extending points mirror their neighborhood if(point1 == NULL && point2 == NULL) @@ -300,15 +299,15 @@ static void _brush_init_ctrl_points(dt_masks_form_t *form) float bx1, by1, bx2, by2; _brush_catmull_to_bezier(point1->corner[0], point1->corner[1], point2->corner[0], point2->corner[1], - point3->corner[0], point3->corner[1], point4->corner[0], point4->corner[1], - &bx1, &by1, &bx2, &by2); + point3->corner[0], point3->corner[1], point4->corner[0], point4->corner[1], &bx1, + &by1, &bx2, &by2); if(point2->ctrl2[0] == -1.0) point2->ctrl2[0] = bx1; if(point2->ctrl2[1] == -1.0) point2->ctrl2[1] = by1; point3->ctrl1[0] = bx2; point3->ctrl1[1] = by2; _brush_catmull_to_bezier(point2->corner[0], point2->corner[1], point3->corner[0], point3->corner[1], - point4->corner[0], point4->corner[1], point5->corner[0], point5->corner[1], - &bx1, &by1, &bx2, &by2); + point4->corner[0], point4->corner[1], point5->corner[0], point5->corner[1], &bx1, + &by1, &bx2, &by2); if(point4->ctrl1[0] == -1.0) point4->ctrl1[0] = bx2; if(point4->ctrl1[1] == -1.0) point4->ctrl1[1] = by2; point3->ctrl2[0] = bx1; @@ -411,7 +410,7 @@ static void _brush_points_recurs_border_small_gaps(float *cmax, float *bmin, flo /** draw a circle with given radius. can be used to terminate a stroke and to draw junctions where attributes * (opacity) change */ -static void _brush_points_stamp(float *cmax, float *bmin, dt_masks_dynbuf_t *dpoints, dt_masks_dynbuf_t *dborder, +static void _brush_points_stamp(float *cmax, float *bmin, dt_masks_dynbuf_t *dpoints, dt_masks_dynbuf_t *dborder, gboolean clockwise) { // we want to find the start angle @@ -441,8 +440,8 @@ static void _brush_points_stamp(float *cmax, float *bmin, dt_masks_dynbuf_t *dpo /** the function takes care to avoid big gaps between points */ static void _brush_points_recurs(float *p1, float *p2, double tmin, double tmax, float *points_min, float *points_max, float *border_min, float *border_max, float *rpoints, - float *rborder, float *rpayload, dt_masks_dynbuf_t *dpoints, dt_masks_dynbuf_t *dborder, - dt_masks_dynbuf_t *dpayload) + float *rborder, float *rpayload, dt_masks_dynbuf_t *dpoints, + dt_masks_dynbuf_t *dborder, dt_masks_dynbuf_t *dpayload) { const gboolean withborder = (dborder != NULL); const gboolean withpayload = (dpayload != NULL); @@ -451,14 +450,14 @@ static void _brush_points_recurs(float *p1, float *p2, double tmin, double tmax, if(isnan(points_min[0])) { _brush_border_get_XY(p1[0], p1[1], p1[2], p1[3], p2[2], p2[3], p2[0], p2[1], tmin, - p1[4] + (p2[4] - p1[4]) * tmin * tmin * (3.0 - 2.0 * tmin), points_min, - points_min + 1, border_min, border_min + 1); + p1[4] + (p2[4] - p1[4]) * tmin * tmin * (3.0 - 2.0 * tmin), points_min, points_min + 1, + border_min, border_min + 1); } if(isnan(points_max[0])) { _brush_border_get_XY(p1[0], p1[1], p1[2], p1[3], p2[2], p2[3], p2[0], p2[1], tmax, - p1[4] + (p2[4] - p1[4]) * tmax * tmax * (3.0 - 2.0 * tmax), points_max, - points_max + 1, border_max, border_max + 1); + p1[4] + (p2[4] - p1[4]) * tmax * tmax * (3.0 - 2.0 * tmax), points_max, points_max + 1, + border_max, border_max + 1); } // are the points near ? if((tmax - tmin < 0.0001f) @@ -466,8 +465,7 @@ static void _brush_points_recurs(float *p1, float *p2, double tmin, double tmax, && (int)points_min[1] - (int)points_max[1] < 1 && (int)points_min[1] - (int)points_max[1] > -1 && (!withborder || ((int)border_min[0] - (int)border_max[0] < 1 && (int)border_min[0] - (int)border_max[0] > -1 - && (int)border_min[1] - (int)border_max[1] < 1 - && (int)border_min[1] - (int)border_max[1] > -1)))) + && (int)border_min[1] - (int)border_max[1] < 1 && (int)border_min[1] - (int)border_max[1] > -1)))) { rpoints[0] = points_max[0]; rpoints[1] = points_max[1]; @@ -537,9 +535,8 @@ static inline int _brush_cyclic_cursor(int n, int nb) /** get all points of the brush and the border */ /** this takes care of gaps and iop distortions */ static int _brush_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, int prio_max, - dt_dev_pixelpipe_t *pipe, float **points, int *points_count, - float **border, int *border_count, float **payload, int *payload_count, - int source) + dt_dev_pixelpipe_t *pipe, float **points, int *points_count, float **border, + int *border_count, float **payload, int *payload_count, int source) { double start2 = dt_get_wtime(); @@ -633,8 +630,7 @@ static int _brush_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, in int start_stamp = 0; if(darktable.unmuted & DT_DEBUG_PERF) - dt_print(DT_DEBUG_MASKS, "[masks %s] brush_points init took %0.04f sec\n", form->name, - dt_get_wtime() - start2); + dt_print(DT_DEBUG_MASKS, "[masks %s] brush_points init took %0.04f sec\n", form->name, dt_get_wtime() - start2); start2 = dt_get_wtime(); // we render all segments first upwards, then downwards @@ -650,18 +646,18 @@ static int _brush_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, in dt_masks_point_brush_t *point3 = (dt_masks_point_brush_t *)g_list_nth_data(form->points, k2); if(cw > 0) { - float pa[7] = { point1->corner[0] * wd - dx, point1->corner[1] * ht - dy, point1->ctrl2[0] * wd - dx, - point1->ctrl2[1] * ht - dy, point1->border[1] * MIN(wd, ht), point1->hardness, - point1->density }; - float pb[7] = { point2->corner[0] * wd - dx, point2->corner[1] * ht - dy, point2->ctrl1[0] * wd - dx, - point2->ctrl1[1] * ht - dy, point2->border[0] * MIN(wd, ht), point2->hardness, - point2->density }; - float pc[7] = { point2->corner[0] * wd - dx, point2->corner[1] * ht - dy, point2->ctrl2[0] * wd - dx, - point2->ctrl2[1] * ht - dy, point2->border[1] * MIN(wd, ht), point2->hardness, - point2->density }; - float pd[7] = { point3->corner[0] * wd - dx, point3->corner[1] * ht - dy, point3->ctrl1[0] * wd - dx, - point3->ctrl1[1] * ht - dy, point3->border[0] * MIN(wd, ht), point3->hardness, - point3->density }; + float pa[7] + = { point1->corner[0] * wd - dx, point1->corner[1] * ht - dy, point1->ctrl2[0] * wd - dx, + point1->ctrl2[1] * ht - dy, point1->border[1] * MIN(wd, ht), point1->hardness, point1->density }; + float pb[7] + = { point2->corner[0] * wd - dx, point2->corner[1] * ht - dy, point2->ctrl1[0] * wd - dx, + point2->ctrl1[1] * ht - dy, point2->border[0] * MIN(wd, ht), point2->hardness, point2->density }; + float pc[7] + = { point2->corner[0] * wd - dx, point2->corner[1] * ht - dy, point2->ctrl2[0] * wd - dx, + point2->ctrl2[1] * ht - dy, point2->border[1] * MIN(wd, ht), point2->hardness, point2->density }; + float pd[7] + = { point3->corner[0] * wd - dx, point3->corner[1] * ht - dy, point3->ctrl1[0] * wd - dx, + point3->ctrl1[1] * ht - dy, point3->border[0] * MIN(wd, ht), point3->hardness, point3->density }; memcpy(p1, pa, 7 * sizeof(float)); memcpy(p2, pb, 7 * sizeof(float)); memcpy(p3, pc, 7 * sizeof(float)); @@ -669,18 +665,18 @@ static int _brush_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, in } else { - float pa[7] = { point1->corner[0] * wd - dx, point1->corner[1] * ht - dy, point1->ctrl1[0] * wd - dx, - point1->ctrl1[1] * ht - dy, point1->border[1] * MIN(wd, ht), point1->hardness, - point1->density }; - float pb[7] = { point2->corner[0] * wd - dx, point2->corner[1] * ht - dy, point2->ctrl2[0] * wd - dx, - point2->ctrl2[1] * ht - dy, point2->border[0] * MIN(wd, ht), point2->hardness, - point2->density }; - float pc[7] = { point2->corner[0] * wd - dx, point2->corner[1] * ht - dy, point2->ctrl1[0] * wd - dx, - point2->ctrl1[1] * ht - dy, point2->border[1] * MIN(wd, ht), point2->hardness, - point2->density }; - float pd[7] = { point3->corner[0] * wd - dx, point3->corner[1] * ht - dy, point3->ctrl2[0] * wd - dx, - point3->ctrl2[1] * ht - dy, point3->border[0] * MIN(wd, ht), point3->hardness, - point3->density }; + float pa[7] + = { point1->corner[0] * wd - dx, point1->corner[1] * ht - dy, point1->ctrl1[0] * wd - dx, + point1->ctrl1[1] * ht - dy, point1->border[1] * MIN(wd, ht), point1->hardness, point1->density }; + float pb[7] + = { point2->corner[0] * wd - dx, point2->corner[1] * ht - dy, point2->ctrl2[0] * wd - dx, + point2->ctrl2[1] * ht - dy, point2->border[0] * MIN(wd, ht), point2->hardness, point2->density }; + float pc[7] + = { point2->corner[0] * wd - dx, point2->corner[1] * ht - dy, point2->ctrl1[0] * wd - dx, + point2->ctrl1[1] * ht - dy, point2->border[1] * MIN(wd, ht), point2->hardness, point2->density }; + float pd[7] + = { point3->corner[0] * wd - dx, point3->corner[1] * ht - dy, point3->ctrl2[0] * wd - dx, + point3->ctrl2[1] * ht - dy, point3->border[0] * MIN(wd, ht), point3->hardness, point3->density }; memcpy(p1, pa, 7 * sizeof(float)); memcpy(p2, pb, 7 * sizeof(float)); memcpy(p3, pc, 7 * sizeof(float)); @@ -797,12 +793,12 @@ static int _brush_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, in if(dborder && nb >= 3) { // we get the next point (start of the next segment) - _brush_border_get_XY(p3[0], p3[1], p3[2], p3[3], p4[2], p4[3], p4[0], p4[1], 0, p3[4], cmin, cmin + 1, - bmax, bmax + 1); + _brush_border_get_XY(p3[0], p3[1], p3[2], p3[3], p4[2], p4[3], p4[0], p4[1], 0, p3[4], cmin, cmin + 1, bmax, + bmax + 1); if(isnan(bmax[0])) { - _brush_border_get_XY(p3[0], p3[1], p3[2], p3[3], p4[2], p4[3], p4[0], p4[1], 0.0001, p3[4], cmin, - cmin + 1, bmax, bmax + 1); + _brush_border_get_XY(p3[0], p3[1], p3[2], p3[3], p4[2], p4[3], p4[0], p4[1], 0.0001, p3[4], cmin, cmin + 1, + bmax, bmax + 1); } if(bmax[0] - rb[0] > 1 || bmax[0] - rb[0] < -1 || bmax[1] - rb[1] > 1 || bmax[1] - rb[1] < -1) { @@ -854,7 +850,7 @@ static int _brush_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, in if(darktable.unmuted & DT_DEBUG_PERF) dt_print(DT_DEBUG_MASKS, "[masks %s] brush_points transform took %0.04f sec\n", form->name, dt_get_wtime() - start2); -// start2 = dt_get_wtime(); + // start2 = dt_get_wtime(); return 1; } } @@ -873,9 +869,8 @@ static int _brush_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, in } /** get the distance between point (x,y) and the brush */ -static void dt_brush_get_distance(float x, int y, float as, dt_masks_form_gui_t *gui, int index, - int corner_count, int *inside, int *inside_border, int *near, - int *inside_source) +static void dt_brush_get_distance(float x, int y, float as, dt_masks_form_gui_t *gui, int index, int corner_count, + int *inside, int *inside_border, int *near, int *inside_source) { // initialise returned values *inside_source = 0; @@ -890,7 +885,7 @@ static void dt_brush_get_distance(float x, int y, float as, dt_masks_form_gui_t if(!gpt) return; // we first check if we are inside the source form - if(dt_masks_point_in_form_exact(x,yf,gpt->source,corner_count * 6,gpt->source_count)) + if(dt_masks_point_in_form_exact(x, yf, gpt->source, corner_count * 6, gpt->source_count)) { *inside_source = 1; *inside = 1; @@ -905,7 +900,7 @@ static void dt_brush_get_distance(float x, int y, float as, dt_masks_form_gui_t for(int i = corner_count * 3; i < gpt->border_count; i++) { float yy = gpt->border[i * 2 + 1]; - if (((yf<=yy && yf>last) || (yf>=yy && yf<last)) && (gpt->border[i * 2] > x)) nb++; + if(((yf <= yy && yf > last) || (yf >= yy && yf < last)) && (gpt->border[i * 2] > x)) nb++; last = yy; } *inside = *inside_border = (nb & 1); @@ -918,14 +913,15 @@ static void dt_brush_get_distance(float x, int y, float as, dt_masks_form_gui_t for(int i = corner_count * 3; i < gpt->points_count; i++) { // do we change of path segment ? - if(gpt->points[i * 2 + 1] == gpt->points[current_seg * 6 + 3] && gpt->points[i * 2] == gpt->points[current_seg * 6 + 2]) + if(gpt->points[i * 2 + 1] == gpt->points[current_seg * 6 + 3] + && gpt->points[i * 2] == gpt->points[current_seg * 6 + 2]) { current_seg = (current_seg + 1) % corner_count; } - //distance from tested point to current form point + // distance from tested point to current form point float yy = gpt->points[i * 2 + 1]; float xx = gpt->points[i * 2]; - if ((yy-yf)<as && (yy-yf)>-as && (xx-x)<as && (xx-x)>-as) + if((yy - yf) < as && (yy - yf) > -as && (xx - x) < as && (xx - x) > -as) { if(current_seg == 0) *near = corner_count - 1; @@ -938,11 +934,11 @@ static void dt_brush_get_distance(float x, int y, float as, dt_masks_form_gui_t } } -static int dt_brush_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, float **points, - int *points_count, float **border, int *border_count, int source) +static int dt_brush_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, float **points, int *points_count, + float **border, int *border_count, int source) { - return _brush_get_points_border(dev, form, 999999, dev->preview_pipe, points, points_count, border, - border_count, NULL, NULL, source); + return _brush_get_points_border(dev, form, 999999, dev->preview_pipe, points, points_count, border, border_count, + NULL, NULL, source); } /** find relative position within a brush segment that is closest to the point given by coordinates x and y; @@ -971,8 +967,8 @@ static float _brush_get_position_in_segment(float x, float y, dt_masks_form_t *f { float t = i / 100.0f; float sx, sy; - _brush_get_XY(point0->corner[0], point0->corner[1], point1->corner[0], point1->corner[1], - point2->corner[0], point2->corner[1], point3->corner[0], point3->corner[1], t, &sx, &sy); + _brush_get_XY(point0->corner[0], point0->corner[1], point1->corner[0], point1->corner[1], point2->corner[0], + point2->corner[1], point3->corner[0], point3->corner[1], t, &sx, &sy); float d = (x - sx) * (x - sx) + (y - sy) * (y - sy); if(d < dmin) @@ -1068,8 +1064,7 @@ static int dt_brush_events_mouse_scrolled(struct dt_iop_module_t *module, float dt_control_queue_redraw_center(); return 1; } - else if(gui->form_selected || gui->point_selected >= 0 || gui->feather_selected >= 0 - || gui->seg_selected >= 0) + else if(gui->form_selected || gui->point_selected >= 0 || gui->feather_selected >= 0 || gui->seg_selected >= 0) { // we register the current position if(gui->scrollx == 0.0f && gui->scrolly == 0.0f) @@ -1152,10 +1147,9 @@ static int dt_brush_events_mouse_scrolled(struct dt_iop_module_t *module, float return 0; } -static int dt_brush_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 dt_brush_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) { if(type == GDK_2BUTTON_PRESS || type == GDK_3BUTTON_PRESS) return 1; if(!gui) return 0; @@ -1247,8 +1241,7 @@ static int dt_brush_events_button_pressed(struct dt_iop_module_t *module, float // if ctrl is pressed, we change the type of point if(gui->point_edited == gui->point_selected && ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)) { - dt_masks_point_brush_t *point - = (dt_masks_point_brush_t *)g_list_nth_data(form->points, gui->point_edited); + dt_masks_point_brush_t *point = (dt_masks_point_brush_t *)g_list_nth_data(form->points, gui->point_edited); if(point->state != DT_MASKS_POINT_STATE_NORMAL) { point->state = DT_MASKS_POINT_STATE_NORMAL; @@ -1381,8 +1374,7 @@ static int dt_brush_events_button_pressed(struct dt_iop_module_t *module, float dt_masks_point_group_t *gpt = (dt_masks_point_group_t *)forms->data; if(gpt->formid == form->formid) { - darktable.develop->form_visible->points - = g_list_remove(darktable.develop->form_visible->points, gpt); + darktable.develop->form_visible->points = g_list_remove(darktable.develop->form_visible->points, gpt); free(gpt); break; } @@ -1397,8 +1389,7 @@ static int dt_brush_events_button_pressed(struct dt_iop_module_t *module, float dt_control_queue_redraw_center(); return 1; } - dt_masks_point_brush_t *point - = (dt_masks_point_brush_t *)g_list_nth_data(form->points, gui->point_selected); + dt_masks_point_brush_t *point = (dt_masks_point_brush_t *)g_list_nth_data(form->points, gui->point_selected); form->points = g_list_remove(form->points, point); free(point); gui->point_selected = -1; @@ -1416,8 +1407,7 @@ static int dt_brush_events_button_pressed(struct dt_iop_module_t *module, float } else if(gui->feather_selected >= 0 && which == 3) { - dt_masks_point_brush_t *point - = (dt_masks_point_brush_t *)g_list_nth_data(form->points, gui->feather_selected); + dt_masks_point_brush_t *point = (dt_masks_point_brush_t *)g_list_nth_data(form->points, gui->feather_selected); if(point->state != DT_MASKS_POINT_STATE_NORMAL) { point->state = DT_MASKS_POINT_STATE_NORMAL; @@ -1449,8 +1439,7 @@ static int dt_brush_events_button_pressed(struct dt_iop_module_t *module, float dt_masks_point_group_t *gpt = (dt_masks_point_group_t *)forms->data; if(gpt->formid == form->formid) { - darktable.develop->form_visible->points - = g_list_remove(darktable.develop->form_visible->points, gpt); + darktable.develop->form_visible->points = g_list_remove(darktable.develop->form_visible->points, gpt); free(gpt); break; } @@ -1686,8 +1675,7 @@ static int dt_brush_events_button_released(struct dt_iop_module_t *module, float } else if(gui->point_dragging >= 0) { - dt_masks_point_brush_t *point - = (dt_masks_point_brush_t *)g_list_nth_data(form->points, gui->point_dragging); + dt_masks_point_brush_t *point = (dt_masks_point_brush_t *)g_list_nth_data(form->points, gui->point_dragging); gui->point_dragging = -1; if(gui->scrollx != 0.0f || gui->scrolly != 0.0f) { @@ -1723,8 +1711,7 @@ static int dt_brush_events_button_released(struct dt_iop_module_t *module, float } else if(gui->feather_dragging >= 0) { - dt_masks_point_brush_t *point - = (dt_masks_point_brush_t *)g_list_nth_data(form->points, gui->feather_dragging); + dt_masks_point_brush_t *point = (dt_masks_point_brush_t *)g_list_nth_data(form->points, gui->feather_dragging); gui->feather_dragging = -1; float wd = darktable.develop->preview_pipe->backbuf_width; float ht = darktable.develop->preview_pipe->backbuf_height; @@ -1733,8 +1720,8 @@ static int dt_brush_events_button_released(struct dt_iop_module_t *module, float int p1x, p1y, p2x, p2y; _brush_feather_to_ctrl(point->corner[0] * darktable.develop->preview_pipe->iwidth, - point->corner[1] * darktable.develop->preview_pipe->iheight, pts[0], pts[1], &p1x, - &p1y, &p2x, &p2y, TRUE); + point->corner[1] * darktable.develop->preview_pipe->iheight, pts[0], pts[1], &p1x, &p1y, + &p2x, &p2y, TRUE); point->ctrl1[0] = (float)p1x / darktable.develop->preview_pipe->iwidth; point->ctrl1[1] = (float)p1y / darktable.develop->preview_pipe->iheight; point->ctrl2[0] = (float)p2x / darktable.develop->preview_pipe->iwidth; @@ -1769,8 +1756,8 @@ static int dt_brush_events_button_released(struct dt_iop_module_t *module, float } static int dt_brush_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) + int which, dt_masks_form_t *form, int parentid, dt_masks_form_gui_t *gui, + int index) { dt_dev_zoom_t zoom = dt_control_get_dev_zoom(); int closeup = dt_control_get_dev_closeup(); @@ -1809,8 +1796,7 @@ static int dt_brush_events_mouse_moved(struct dt_iop_module_t *module, float pzx float ht = darktable.develop->preview_pipe->backbuf_height; float pts[2] = { pzx * wd, pzy * ht }; dt_dev_distort_backtransform(darktable.develop, pts, 1); - dt_masks_point_brush_t *bzpt - = (dt_masks_point_brush_t *)g_list_nth_data(form->points, gui->point_dragging); + dt_masks_point_brush_t *bzpt = (dt_masks_point_brush_t *)g_list_nth_data(form->points, gui->point_dragging); pzx = pts[0] / darktable.develop->preview_pipe->iwidth; pzy = pts[1] / darktable.develop->preview_pipe->iheight; bzpt->ctrl1[0] += pzx - bzpt->corner[0]; @@ -1830,8 +1816,7 @@ static int dt_brush_events_mouse_moved(struct dt_iop_module_t *module, float pzx { // we get point0 new values int pos2 = (gui->seg_dragging + 1) % g_list_length(form->points); - dt_masks_point_brush_t *point - = (dt_masks_point_brush_t *)g_list_nth_data(form->points, gui->seg_dragging); + dt_masks_point_brush_t *point = (dt_masks_point_brush_t *)g_list_nth_data(form->points, gui->seg_dragging); dt_masks_point_brush_t *point2 = (dt_masks_point_brush_t *)g_list_nth_data(form->points, pos2); float wd = darktable.develop->preview_pipe->backbuf_width; float ht = darktable.develop->preview_pipe->backbuf_height; @@ -1871,13 +1856,12 @@ static int dt_brush_events_mouse_moved(struct dt_iop_module_t *module, float pzx float ht = darktable.develop->preview_pipe->backbuf_height; float pts[2] = { pzx * wd, pzy * ht }; dt_dev_distort_backtransform(darktable.develop, pts, 1); - dt_masks_point_brush_t *point - = (dt_masks_point_brush_t *)g_list_nth_data(form->points, gui->feather_dragging); + dt_masks_point_brush_t *point = (dt_masks_point_brush_t *)g_list_nth_data(form->points, gui->feather_dragging); int p1x, p1y, p2x, p2y; _brush_feather_to_ctrl(point->corner[0] * darktable.develop->preview_pipe->iwidth, - point->corner[1] * darktable.develop->preview_pipe->iheight, pts[0], pts[1], &p1x, - &p1y, &p2x, &p2y, TRUE); + point->corner[1] * darktable.develop->preview_pipe->iheight, pts[0], pts[1], &p1x, &p1y, + &p2x, &p2y, TRUE); point->ctrl1[0] = (float)p1x / darktable.develop->preview_pipe->iwidth; point->ctrl1[1] = (float)p1y / darktable.develop->preview_pipe->iheight; point->ctrl2[0] = (float)p2x / darktable.develop->preview_pipe->iwidth; @@ -1941,8 +1925,7 @@ static int dt_brush_events_mouse_moved(struct dt_iop_module_t *module, float pzx // are we near a point or feather ? guint nb = g_list_length(form->points); - pzx *= darktable.develop->preview_pipe->backbuf_width, - pzy *= darktable.develop->preview_pipe->backbuf_height; + pzx *= darktable.develop->preview_pipe->backbuf_width, pzy *= darktable.develop->preview_pipe->backbuf_height; if((gui->group_selected == index) && gui->point_edited >= 0) { @@ -2018,8 +2001,7 @@ static int dt_brush_events_mouse_moved(struct dt_iop_module_t *module, float pzx return 1; } -static void dt_brush_events_post_expose(cairo_t *cr, float zoom_scale, dt_masks_form_gui_t *gui, int index, - int nb) +static void dt_brush_events_post_expose(cairo_t *cr, float zoom_scale, dt_masks_form_gui_t *gui, int index, int nb) { double dashed[] = { 4.0, 4.0 }; dashed[0] /= zoom_scale; @@ -2199,15 +2181,14 @@ static void dt_brush_events_post_expose(cairo_t *cr, float zoom_scale, dt_masks_ cairo_set_line_width(cr, linewidth); dt_gui_gtk_set_source_rgba(cr, DT_GUI_COLOR_BRUSH_CURSOR, opacity); if(opacity < 1.0) cairo_set_line_width(cr, cairo_get_line_width(cr) * .8); - cairo_arc(cr, guipoints[2 * (gui->guipoints_count - 1)], - guipoints[2 * (gui->guipoints_count - 1) + 1], radius, 0, 2.0 * M_PI); + cairo_arc(cr, guipoints[2 * (gui->guipoints_count - 1)], guipoints[2 * (gui->guipoints_count - 1) + 1], + radius, 0, 2.0 * M_PI); cairo_fill_preserve(cr); cairo_set_source_rgba(cr, .8, .8, .8, .8); cairo_stroke(cr); cairo_set_dash(cr, dashed, len, 0); - cairo_arc(cr, guipoints[2 * (gui->guipoints_count - 1)], - guipoints[2 * (gui->guipoints_count - 1) + 1], masks_border * MIN(wd, ht), 0, - 2.0 * M_PI); + cairo_arc(cr, guipoints[2 * (gui->guipoints_count - 1)], guipoints[2 * (gui->guipoints_count - 1) + 1], + masks_border * MIN(wd, ht), 0, 2.0 * M_PI); cairo_stroke(cr); cairo_restore(cr); @@ -2294,8 +2275,8 @@ static void dt_brush_events_post_expose(cairo_t *cr, float zoom_scale, dt_masks_ cairo_line_to(cr, gui->points[k*6+4]+dx,gui->points[k*6+5]+dy); cairo_stroke(cr);*/ int ffx, ffy; - _brush_ctrl2_to_feather(gpt->points[k * 6 + 2] + dx, gpt->points[k * 6 + 3] + dy, - gpt->points[k * 6 + 4] + dx, gpt->points[k * 6 + 5] + dy, &ffx, &ffy, TRUE); + _brush_ctrl2_to_feather(gpt->points[k * 6 + 2] + dx, gpt->points[k * 6 + 3] + dy, gpt->points[k * 6 + 4] + dx, + gpt->points[k * 6 + 5] + dy, &ffx, &ffy, TRUE); cairo_move_to(cr, gpt->points[k * 6 + 2] + dx, gpt->points[k * 6 + 3] + dy); cairo_line_to(cr, ffx, ffy); cairo_set_line_width(cr, 1.5 / zoom_scale); @@ -2414,15 +2395,15 @@ static void dt_brush_events_post_expose(cairo_t *cr, float zoom_scale, dt_masks_ } } -static int dt_brush_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 dt_brush_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) { if(!module) return 0; // we get buffers for all points float *points = NULL, *border = NULL; int points_count, border_count; - if(!_brush_get_points_border(module->dev, form, module->priority, piece->pipe, &points, &points_count, - &border, &border_count, NULL, NULL, 1)) + if(!_brush_get_points_border(module->dev, form, module->priority, piece->pipe, &points, &points_count, &border, + &border_count, NULL, NULL, 1)) { free(points); free(border); @@ -2471,8 +2452,8 @@ static int dt_brush_get_area(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *pi // we get buffers for all points float *points = NULL, *border = NULL; int points_count, border_count; - if(!_brush_get_points_border(module->dev, form, module->priority, piece->pipe, &points, &points_count, - &border, &border_count, NULL, NULL, 0)) + if(!_brush_get_points_border(module->dev, form, module->priority, piece->pipe, &points, &points_count, &border, + &border_count, NULL, NULL, 0)) { free(points); free(border); @@ -2553,8 +2534,8 @@ static int dt_brush_get_mask(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *pi // we get buffers for all points float *points = NULL, *border = NULL, *payload = NULL; int points_count, border_count, payload_count; - if(!_brush_get_points_border(module->dev, form, module->priority, piece->pipe, &points, &points_count, - &border, &border_count, &payload, &payload_count, 0)) + if(!_brush_get_points_border(module->dev, form, module->priority, piece->pipe, &points, &points_count, &border, + &border_count, &payload, &payload_count, 0)) { free(points); free(border); @@ -2600,7 +2581,7 @@ static int dt_brush_get_mask(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *pi if(darktable.unmuted & DT_DEBUG_PERF) dt_print(DT_DEBUG_MASKS, "[masks %s] brush_fill min max took %0.04f sec\n", form->name, dt_get_wtime() - start2); -// start2 = dt_get_wtime(); + // start2 = dt_get_wtime(); // we allocate the buffer *buffer = calloc((size_t)(*width) * (*height), sizeof(float)); @@ -2623,8 +2604,7 @@ static int dt_brush_get_mask(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *pi free(payload); if(darktable.unmuted & DT_DEBUG_PERF) - dt_print(DT_DEBUG_MASKS, "[masks %s] brush fill buffer took %0.04f sec\n", form->name, - dt_get_wtime() - start); + dt_print(DT_DEBUG_MASKS, "[masks %s] brush fill buffer took %0.04f sec\n", form->name, dt_get_wtime() - start); return 1; } @@ -2665,15 +2645,13 @@ static inline void _brush_falloff_roi(float *buffer, int *p0, int *p1, int bw, i float *buf = buffer + (size_t)y * bw + x; *buf = fmaxf(*buf, op); - if(x + dx >= 0 && x + dx < bw) - buf[dpx] = fmaxf(buf[dpx], op); // this one is to avoid gaps due to int rounding - if(y + dy >= 0 && y + dy < bh) - buf[dpy] = fmaxf(buf[dpy], op); // this one is to avoid gaps due to int rounding + if(x + dx >= 0 && x + dx < bw) buf[dpx] = fmaxf(buf[dpx], op); // this one is to avoid gaps due to int rounding + if(y + dy >= 0 && y + dy < bh) buf[dpy] = fmaxf(buf[dpy], op); // this one is to avoid gaps due to int rounding } } -static int dt_brush_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, - dt_masks_form_t *form, const dt_iop_roi_t *roi, float *buffer) +static int dt_brush_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, dt_masks_form_t *form, + const dt_iop_roi_t *roi, float *buffer) { if(!module) return 0; double start = dt_get_wtime(); @@ -2689,8 +2667,8 @@ static int dt_brush_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t float *points = NULL, *border = NULL, *payload = NULL; int points_count, border_count, payload_count; - if(!_brush_get_points_border(module->dev, form, module->priority, piece->pipe, &points, &points_count, - &border, &border_count, &payload, &payload_count, 0)) + if(!_brush_get_points_border(module->dev, form, module->priority, piece->pipe, &points, &points_count, &border, + &border_count, &payload, &payload_count, 0)) { free(points); free(border); @@ -2753,7 +2731,7 @@ static int dt_brush_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t if(darktable.unmuted & DT_DEBUG_PERF) dt_print(DT_DEBUG_MASKS, "[masks %s] brush_fill min max took %0.04f sec\n", form->name, dt_get_wtime() - start2); -// start2 = dt_get_wtime(); + // start2 = dt_get_wtime(); // check if the path completely lies outside of roi -> we're done/mask remains empty if(xmax < 0 || ymax < 0 || xmin >= width || ymin >= height) @@ -2773,8 +2751,7 @@ static int dt_brush_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t p1[0] = border[i * 2]; p1[1] = border[i * 2 + 1]; - if(MAX(p0[0], p1[0]) < 0 || MIN(p0[0], p1[0]) >= width || MAX(p0[1], p1[1]) < 0 - || MIN(p0[1], p1[1]) >= height) + if(MAX(p0[0], p1[0]) < 0 || MIN(p0[0], p1[0]) >= width || MAX(p0[1], p1[1]) < 0 || MIN(p0[1], p1[1]) >= height) continue; _brush_falloff_roi(buffer, p0, p1, width, height, payload[i * 2], payload[i * 2 + 1]); @@ -2785,8 +2762,7 @@ static int dt_brush_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t free(payload); if(darktable.unmuted & DT_DEBUG_PERF) - dt_print(DT_DEBUG_MASKS, "[masks %s] brush fill buffer took %0.04f sec\n", form->name, - dt_get_wtime() - start); + dt_print(DT_DEBUG_MASKS, "[masks %s] brush fill buffer took %0.04f sec\n", form->name, dt_get_wtime() - start); return 1; } diff --git a/src/develop/masks/circle.c b/src/develop/masks/circle.c index b95451361809..10e279b6cff8 100644 --- a/src/develop/masks/circle.c +++ b/src/develop/masks/circle.c @@ -38,7 +38,7 @@ static void dt_circle_get_distance(float x, int y, float as, dt_masks_form_gui_t if(!gpt) return; // we first check if we are inside the source form - if(dt_masks_point_in_form_exact(x,yf,gpt->source,1,gpt->source_count)) + if(dt_masks_point_in_form_exact(x, yf, gpt->source, 1, gpt->source_count)) { *inside_source = 1; *inside = 1; @@ -46,13 +46,13 @@ static void dt_circle_get_distance(float x, int y, float as, dt_masks_form_gui_t } // we check if it's inside borders - if(!dt_masks_point_in_form_exact(x,yf,gpt->border,1,gpt->border_count)) return; + if(!dt_masks_point_in_form_exact(x, yf, gpt->border, 1, gpt->border_count)) return; *inside = 1; *near = 0; // and we check if it's inside form - *inside_border = !(dt_masks_point_in_form_near(x,yf,gpt->points,1,gpt->points_count,as,near)); + *inside_border = !(dt_masks_point_in_form_near(x, yf, gpt->points, 1, gpt->points_count, as, near)); } static int dt_circle_events_mouse_scrolled(struct dt_iop_module_t *module, float pzx, float pzy, int up, @@ -118,10 +118,9 @@ static int dt_circle_events_mouse_scrolled(struct dt_iop_module_t *module, float return 0; } -static int dt_circle_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 dt_circle_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) { if(!gui) return 0; if(gui->source_selected && !gui->creation && gui->edit_mode == DT_MASKS_EDIT_FULL) @@ -261,8 +260,7 @@ static int dt_circle_events_button_released(struct dt_iop_module_t *module, floa dt_masks_point_group_t *gpt = (dt_masks_point_group_t *)forms->data; if(gpt->formid == form->formid) { - darktable.develop->form_visible->points - = g_list_remove(darktable.develop->form_visible->points, gpt); + darktable.develop->form_visible->points = g_list_remove(darktable.develop->form_visible->points, gpt); free(gpt); break; } @@ -340,8 +338,8 @@ static int dt_circle_events_button_released(struct dt_iop_module_t *module, floa } static int dt_circle_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) + int which, dt_masks_form_t *form, int parentid, dt_masks_form_gui_t *gui, + int index) { if(gui->form_dragging || gui->source_dragging) { @@ -358,8 +356,8 @@ static int dt_circle_events_mouse_moved(struct dt_iop_module_t *module, float pz float as = 0.005f / zoom_scale * darktable.develop->preview_pipe->backbuf_width; int in, inb, near, ins; dt_circle_get_distance(pzx * darktable.develop->preview_pipe->backbuf_width, - pzy * darktable.develop->preview_pipe->backbuf_height, as, gui, index, &in, &inb, - &near, &ins); + pzy * darktable.develop->preview_pipe->backbuf_height, as, gui, index, &in, &inb, &near, + &ins); if(ins) { gui->form_selected = TRUE; @@ -494,11 +492,9 @@ static void dt_circle_events_post_expose(cairo_t *cr, float zoom_scale, dt_masks cairo_line_to(cr, arrowx, arrowy); // dest border // then draw to line for the arrow itself const float arrow_scale = 8.0; - cairo_move_to(cr, arrowx + arrow_scale * cos(cangle + (0.4)), - arrowy + arrow_scale * sin(cangle + (0.4))); + cairo_move_to(cr, arrowx + arrow_scale * cos(cangle + (0.4)), arrowy + arrow_scale * sin(cangle + (0.4))); cairo_line_to(cr, arrowx, arrowy); - cairo_line_to(cr, arrowx + arrow_scale * cos(cangle - (0.4)), - arrowy + arrow_scale * sin(cangle - (0.4))); + cairo_line_to(cr, arrowx + arrow_scale * cos(cangle - (0.4)), arrowy + arrow_scale * sin(cangle - (0.4))); cairo_set_dash(cr, dashed, 0, 0); if((gui->group_selected == index) && (gui->form_selected || gui->form_dragging)) @@ -572,8 +568,8 @@ static int dt_circle_get_points(dt_develop_t *dev, float x, float y, float radiu return 0; } -static int dt_circle_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 dt_circle_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) { // we get the circle values dt_masks_point_circle_t *circle = (dt_masks_point_circle_t *)(g_list_first(form->points)->data); @@ -708,8 +704,7 @@ static int dt_circle_get_mask(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *p } if(darktable.unmuted & DT_DEBUG_PERF) - dt_print(DT_DEBUG_MASKS, "[masks %s] circle transform took %0.04f sec\n", form->name, - dt_get_wtime() - start2); + dt_print(DT_DEBUG_MASKS, "[masks %s] circle transform took %0.04f sec\n", form->name, dt_get_wtime() - start2); start2 = dt_get_wtime(); // we allocate the buffer @@ -719,8 +714,7 @@ static int dt_circle_get_mask(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *p int wi = piece->pipe->iwidth, hi = piece->pipe->iheight; float center[2] = { circle->center[0] * wi, circle->center[1] * hi }; float radius2 = circle->radius * MIN(wi, hi) * circle->radius * MIN(wi, hi); - float total2 = (circle->radius + circle->border) * MIN(wi, hi) * (circle->radius + circle->border) - * MIN(wi, hi); + float total2 = (circle->radius + circle->border) * MIN(wi, hi) * (circle->radius + circle->border) * MIN(wi, hi); for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) { @@ -741,14 +735,14 @@ static int dt_circle_get_mask(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *p if(darktable.unmuted & DT_DEBUG_PERF) dt_print(DT_DEBUG_MASKS, "[masks %s] circle fill took %0.04f sec\n", form->name, dt_get_wtime() - start2); -// start2 = dt_get_wtime(); + // start2 = dt_get_wtime(); return 1; } -static int dt_circle_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, - dt_masks_form_t *form, const dt_iop_roi_t *roi, float *buffer) +static int dt_circle_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, dt_masks_form_t *form, + const dt_iop_roi_t *roi, float *buffer) { double start2 = dt_get_wtime(); @@ -788,16 +782,14 @@ static int dt_circle_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_ start2 = dt_get_wtime(); // we back transform all these points - if(!dt_dev_distort_backtransform_plus(module->dev, piece->pipe, 0, module->priority, points, - (size_t)mw * mh)) + if(!dt_dev_distort_backtransform_plus(module->dev, piece->pipe, 0, module->priority, points, (size_t)mw * mh)) { free(points); return 0; } if(darktable.unmuted & DT_DEBUG_PERF) - dt_print(DT_DEBUG_MASKS, "[masks %s] circle transform took %0.04f sec\n", form->name, - dt_get_wtime() - start2); + dt_print(DT_DEBUG_MASKS, "[masks %s] circle transform took %0.04f sec\n", form->name, dt_get_wtime() - start2); start2 = dt_get_wtime(); // we populate the buffer @@ -862,7 +854,7 @@ static int dt_circle_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_ if(darktable.unmuted & DT_DEBUG_PERF) dt_print(DT_DEBUG_MASKS, "[masks %s] circle fill took %0.04f sec\n", form->name, dt_get_wtime() - start2); -// start2 = dt_get_wtime(); + // start2 = dt_get_wtime(); return 1; } diff --git a/src/develop/masks/ellipse.c b/src/develop/masks/ellipse.c index b27ce4a4a238..5cbb6a46dfbe 100644 --- a/src/develop/masks/ellipse.c +++ b/src/develop/masks/ellipse.c @@ -25,16 +25,16 @@ static inline void _ellipse_point_transform(const float xref, const float yref, const float x, const float y, const float sinr, const float cosr, const float scalea, - const float scaleb, const float sinv, const float cosv, - float *xnew, float *ynew) + const float scaleb, const float sinv, const float cosv, float *xnew, + float *ynew) { float xtmp = (scaleb * sinr * sinr + scalea * cosr * cosr) * (x - xref) + (scalea * cosr * sinr - scaleb * cosr * sinr) * (y - yref); float ytmp = (scalea * cosr * sinr - scaleb * cosr * sinr) * (x - xref) + (scalea * sinr * sinr + scaleb * cosr * cosr) * (y - yref); - *xnew = xref + cosv * xtmp - sinv * ytmp; - *ynew = yref + sinv * xtmp + cosv * ytmp; + *xnew = xref + cosv *xtmp - sinv *ytmp; + *ynew = yref + sinv *xtmp + cosv *ytmp; } @@ -83,8 +83,7 @@ static int dt_ellipse_point_in_polygon(float x, float y, float *points, int poin t *= dt_ellipse_cross_test(x, y, points + 2 * (points_count - 1), points); - for(int i = 0; i < points_count - 2; i++) - t *= dt_ellipse_cross_test(x, y, points + 2 * i, points + 2 * (i + 1)); + for(int i = 0; i < points_count - 2; i++) t *= dt_ellipse_cross_test(x, y, points + 2 * i, points + 2 * (i + 1)); return t; } @@ -138,8 +137,8 @@ static int dt_ellipse_point_close_to_path(float x, float y, float as, float *poi } -static void dt_ellipse_get_distance(float x, int y, float as, dt_masks_form_gui_t *gui, int index, - int *inside, int *inside_border, int *near, int *inside_source) +static void dt_ellipse_get_distance(float x, int y, float as, dt_masks_form_gui_t *gui, int index, int *inside, + int *inside_border, int *near, int *inside_source) { if(!gui) return; @@ -202,12 +201,15 @@ static int dt_ellipse_events_mouse_scrolled(struct dt_iop_module_t *module, floa dt_masks_point_ellipse_t *ellipse = (dt_masks_point_ellipse_t *)(g_list_first(form->points)->data); if(gui->border_selected || (state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK) { - const float reference = (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? 1.0f/fmin(ellipse->radius[0], ellipse->radius[1]) : 1.0f); + const float reference + = (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? 1.0f / fmin(ellipse->radius[0], ellipse->radius[1]) + : 1.0f); if(up && ellipse->border > 0.001f * reference) ellipse->border *= 0.97f; else if(!up && ellipse->border < 1.0f * reference) - ellipse->border *= 1.0f/0.97f; - else return 1; + ellipse->border *= 1.0f / 0.97f; + else + return 1; ellipse->border = CLAMP(ellipse->border, 0.001f * reference, reference); dt_masks_write_form(form, darktable.develop); dt_masks_gui_form_remove(form, gui, index); @@ -225,7 +227,8 @@ static int dt_ellipse_events_mouse_scrolled(struct dt_iop_module_t *module, floa ellipse->radius[0] *= 0.97f; else if(!up && ellipse->radius[0] < 1.0f) ellipse->radius[0] *= 1.0f / 0.97f; - else return 1; + else + return 1; ellipse->radius[0] = CLAMP(ellipse->radius[0], 0.001f, 1.0f); @@ -257,10 +260,9 @@ static int dt_ellipse_events_mouse_scrolled(struct dt_iop_module_t *module, floa return 0; } -static int dt_ellipse_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 dt_ellipse_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) { if(!gui) return 0; if(gui->source_selected && !gui->creation && gui->edit_mode == DT_MASKS_EDIT_FULL) @@ -323,8 +325,7 @@ static int dt_ellipse_events_button_pressed(struct dt_iop_module_t *module, floa { dt_iop_module_t *crea_module = gui->creation_module; // we create the ellipse - dt_masks_point_ellipse_t *ellipse - = (dt_masks_point_ellipse_t *)(malloc(sizeof(dt_masks_point_ellipse_t))); + dt_masks_point_ellipse_t *ellipse = (dt_masks_point_ellipse_t *)(malloc(sizeof(dt_masks_point_ellipse_t))); // we change the center value float wd = darktable.develop->preview_pipe->backbuf_width; @@ -346,7 +347,7 @@ static int dt_ellipse_events_button_pressed(struct dt_iop_module_t *module, floa ellipse->flags = flags; ellipse->rotation = rotation; const float min_radius = fmin(ellipse->radius[0], ellipse->radius[1]); - const float reference = (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? 1.0f/min_radius : 1.0f); + const float reference = (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? 1.0f / min_radius : 1.0f); ellipse->border = MAX(0.005f * reference, MIN(0.5f * reference, ellipse_border)); form->source[0] = ellipse->center[0] + 0.02f; form->source[1] = ellipse->center[1] + 0.02f; @@ -363,7 +364,7 @@ static int dt_ellipse_events_button_pressed(struct dt_iop_module_t *module, floa ellipse->flags = flags; ellipse->rotation = rotation; const float min_radius = fmin(ellipse->radius[0], ellipse->radius[1]); - const float reference = (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? 1.0f/min_radius : 1.0f); + const float reference = (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? 1.0f / min_radius : 1.0f); ellipse->border = MAX(0.005f * reference, MIN(0.5f * reference, ellipse_border)); // not used for masks form->source[0] = form->source[1] = 0.0f; @@ -441,8 +442,7 @@ static int dt_ellipse_events_button_released(struct dt_iop_module_t *module, flo dt_masks_point_group_t *gpt = (dt_masks_point_group_t *)forms->data; if(gpt->formid == form->formid) { - darktable.develop->form_visible->points - = g_list_remove(darktable.develop->form_visible->points, gpt); + darktable.develop->form_visible->points = g_list_remove(darktable.develop->form_visible->points, gpt); free(gpt); break; } @@ -503,8 +503,8 @@ static int dt_ellipse_events_button_released(struct dt_iop_module_t *module, flo else { const float min_radius = fmin(ellipse->radius[0], ellipse->radius[1]); - ellipse->border = ellipse->border/min_radius; - ellipse->border = CLAMP(ellipse->border, 0.001f/min_radius, 1.0f/min_radius); + ellipse->border = ellipse->border / min_radius; + ellipse->border = CLAMP(ellipse->border, 0.001f / min_radius, 1.0f / min_radius); ellipse->flags |= DT_MASKS_ELLIPSE_PROPORTIONAL; } @@ -663,9 +663,9 @@ static int dt_ellipse_events_button_released(struct dt_iop_module_t *module, flo return 0; } -static int dt_ellipse_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 int dt_ellipse_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) { if(gui->form_dragging || gui->form_rotating || gui->source_dragging || gui->point_dragging >= 1) { @@ -815,8 +815,8 @@ static void dt_ellipse_events_post_expose(cairo_t *cr, float zoom_scale, dt_mask cairo_set_line_width(cr, 3.0 / zoom_scale); cairo_set_source_rgba(cr, .3, .3, .3, .8); - _ellipse_point_transform(xref, yref, gpt->points[10] + dx, gpt->points[11] + dy, sinr, cosr, scalea, - scaleb, sinv, cosv, &x, &y); + _ellipse_point_transform(xref, yref, gpt->points[10] + dx, gpt->points[11] + dy, sinr, cosr, scalea, scaleb, + sinv, cosv, &x, &y); cairo_move_to(cr, x, y); for(int i = 6; i < gpt->points_count; i++) { @@ -824,8 +824,8 @@ static void dt_ellipse_events_post_expose(cairo_t *cr, float zoom_scale, dt_mask scalea, scaleb, sinv, cosv, &x, &y); cairo_line_to(cr, x, y); } - _ellipse_point_transform(xref, yref, gpt->points[10] + dx, gpt->points[11] + dy, sinr, cosr, scalea, - scaleb, sinv, cosv, &x, &y); + _ellipse_point_transform(xref, yref, gpt->points[10] + dx, gpt->points[11] + dy, sinr, cosr, scalea, scaleb, + sinv, cosv, &x, &y); cairo_line_to(cr, x, y); cairo_stroke_preserve(cr); if((gui->group_selected == index) && (gui->form_selected || gui->form_dragging)) @@ -877,8 +877,8 @@ static void dt_ellipse_events_post_expose(cairo_t *cr, float zoom_scale, dt_mask cairo_set_line_width(cr, 1.0 / zoom_scale); cairo_set_source_rgba(cr, .3, .3, .3, .8); - _ellipse_point_transform(xref, yref, gpt->border[10] + dx, gpt->border[11] + dy, sinr, cosr, scaleab, - scalebb, sinv, cosv, &x, &y); + _ellipse_point_transform(xref, yref, gpt->border[10] + dx, gpt->border[11] + dy, sinr, cosr, scaleab, scalebb, + sinv, cosv, &x, &y); cairo_move_to(cr, x, y); for(int i = 6; i < gpt->border_count; i++) { @@ -886,8 +886,8 @@ static void dt_ellipse_events_post_expose(cairo_t *cr, float zoom_scale, dt_mask scaleab, scalebb, sinv, cosv, &x, &y); cairo_line_to(cr, x, y); } - _ellipse_point_transform(xref, yref, gpt->border[10] + dx, gpt->border[11] + dy, sinr, cosr, scaleab, - scalebb, sinv, cosv, &x, &y); + _ellipse_point_transform(xref, yref, gpt->border[10] + dx, gpt->border[11] + dy, sinr, cosr, scaleab, scalebb, + sinv, cosv, &x, &y); cairo_line_to(cr, x, y); cairo_stroke_preserve(cr); @@ -925,11 +925,9 @@ static void dt_ellipse_events_post_expose(cairo_t *cr, float zoom_scale, dt_mask cairo_line_to(cr, arrowx, arrowy); // dest border // then draw to line for the arrow itself const float arrow_scale = 8.0; - cairo_move_to(cr, arrowx + arrow_scale * cos(cangle + (0.4)), - arrowy + arrow_scale * sin(cangle + (0.4))); + cairo_move_to(cr, arrowx + arrow_scale * cos(cangle + (0.4)), arrowy + arrow_scale * sin(cangle + (0.4))); cairo_line_to(cr, arrowx, arrowy); - cairo_line_to(cr, arrowx + arrow_scale * cos(cangle - (0.4)), - arrowy + arrow_scale * sin(cangle - (0.4))); + cairo_line_to(cr, arrowx + arrow_scale * cos(cangle - (0.4)), arrowy + arrow_scale * sin(cangle - (0.4))); cairo_set_dash(cr, dashed, 0, 0); if((gui->group_selected == index) && (gui->form_selected || gui->form_dragging)) @@ -958,8 +956,8 @@ static void dt_ellipse_events_post_expose(cairo_t *cr, float zoom_scale, dt_mask cairo_move_to(cr, x, y); for(int i = 6; i < gpt->source_count; i++) { - _ellipse_point_transform(xrefs, yrefs, gpt->source[i * 2] + dxs, gpt->source[i * 2 + 1] + dys, sinr, - cosr, scalea, scaleb, sinv, cosv, &x, &y); + _ellipse_point_transform(xrefs, yrefs, gpt->source[i * 2] + dxs, gpt->source[i * 2 + 1] + dys, sinr, cosr, + scalea, scaleb, sinv, cosv, &x, &y); cairo_line_to(cr, x, y); } _ellipse_point_transform(xrefs, yrefs, gpt->source[10] + dxs, gpt->source[11] + dys, sinr, cosr, scalea, @@ -1052,8 +1050,11 @@ static int dt_ellipse_get_source_area(dt_iop_module_t *module, dt_dev_pixelpipe_ dt_masks_point_ellipse_t *ellipse = (dt_masks_point_ellipse_t *)(g_list_first(form->points)->data); const float wd = piece->pipe->iwidth, ht = piece->pipe->iheight; - const float total[2] = { (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? ellipse->radius[0] * (1.0f + ellipse->border) : ellipse->radius[0] + ellipse->border) * MIN(wd, ht), - (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? ellipse->radius[1] * (1.0f + ellipse->border) : ellipse->radius[1] + ellipse->border) * MIN(wd, ht) }; + const float total[2] + = { (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? ellipse->radius[0] * (1.0f + ellipse->border) + : ellipse->radius[0] + ellipse->border) * MIN(wd, ht), + (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? ellipse->radius[1] * (1.0f + ellipse->border) + : ellipse->radius[1] + ellipse->border) * MIN(wd, ht) }; const float v1 = ((ellipse->rotation) / 180.0f) * M_PI; const float v2 = ((ellipse->rotation - 90.0f) / 180.0f) * M_PI; float a, b, v; @@ -1076,8 +1077,8 @@ static int dt_ellipse_get_source_area(dt_iop_module_t *module, dt_dev_pixelpipe_ // how many points do we need ? const float lambda = (a - b) / (a + b); - const int l = (int)(M_PI * (a + b) - * (1.0f + (3.0f * lambda * lambda) / (10.0f + sqrtf(4.0f - 3.0f * lambda * lambda)))); + const int l + = (int)(M_PI * (a + b) * (1.0f + (3.0f * lambda * lambda) / (10.0f + sqrtf(4.0f - 3.0f * lambda * lambda)))); // buffer allocations float *points = calloc(2 * (l + 5), sizeof(float)); @@ -1138,8 +1139,11 @@ static int dt_ellipse_get_area(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t * const float wd = piece->pipe->iwidth, ht = piece->pipe->iheight; - const float total[2] = { (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? ellipse->radius[0] * (1.0f + ellipse->border) : ellipse->radius[0] + ellipse->border) * MIN(wd, ht), - (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? ellipse->radius[1] * (1.0f + ellipse->border) : ellipse->radius[1] + ellipse->border) * MIN(wd, ht) }; + const float total[2] + = { (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? ellipse->radius[0] * (1.0f + ellipse->border) + : ellipse->radius[0] + ellipse->border) * MIN(wd, ht), + (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? ellipse->radius[1] * (1.0f + ellipse->border) + : ellipse->radius[1] + ellipse->border) * MIN(wd, ht) }; const float v1 = ((ellipse->rotation) / 180.0f) * M_PI; const float v2 = ((ellipse->rotation - 90.0f) / 180.0f) * M_PI; float a, b, v; @@ -1162,8 +1166,8 @@ static int dt_ellipse_get_area(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t * // how many points do we need ? const float lambda = (a - b) / (a + b); - const int l = (int)(M_PI * (a + b) - * (1.0f + (3.0f * lambda * lambda) / (10.0f + sqrtf(4.0f - 3.0f * lambda * lambda)))); + const int l + = (int)(M_PI * (a + b) * (1.0f + (3.0f * lambda * lambda) / (10.0f + sqrtf(4.0f - 3.0f * lambda * lambda)))); // buffer allocations float *points = calloc(2 * (l + 5), sizeof(float)); @@ -1254,8 +1258,7 @@ static int dt_ellipse_get_mask(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t * } if(darktable.unmuted & DT_DEBUG_PERF) - dt_print(DT_DEBUG_MASKS, "[masks %s] ellipse transform took %0.04f sec\n", form->name, - dt_get_wtime() - start2); + dt_print(DT_DEBUG_MASKS, "[masks %s] ellipse transform took %0.04f sec\n", form->name, dt_get_wtime() - start2); start2 = dt_get_wtime(); // we allocate the buffer @@ -1265,8 +1268,11 @@ static int dt_ellipse_get_mask(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t * const int wi = piece->pipe->iwidth, hi = piece->pipe->iheight; const float center[2] = { ellipse->center[0] * wi, ellipse->center[1] * hi }; const float radius[2] = { ellipse->radius[0] * MIN(wi, hi), ellipse->radius[1] * MIN(wi, hi) }; - const float total[2] = { (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? ellipse->radius[0] * (1.0f + ellipse->border) : ellipse->radius[0] + ellipse->border) * MIN(wi, hi), - (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? ellipse->radius[1] * (1.0f + ellipse->border) : ellipse->radius[1] + ellipse->border) * MIN(wi, hi) }; + const float total[2] + = { (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? ellipse->radius[0] * (1.0f + ellipse->border) + : ellipse->radius[0] + ellipse->border) * MIN(wi, hi), + (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? ellipse->radius[1] * (1.0f + ellipse->border) + : ellipse->radius[1] + ellipse->border) * MIN(wi, hi) }; float a, b, ta, tb, alpha; @@ -1313,14 +1319,14 @@ static int dt_ellipse_get_mask(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t * if(darktable.unmuted & DT_DEBUG_PERF) dt_print(DT_DEBUG_MASKS, "[masks %s] ellipse fill took %0.04f sec\n", form->name, dt_get_wtime() - start2); -// start2 = dt_get_wtime(); + // start2 = dt_get_wtime(); return 1; } -static int dt_ellipse_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, - dt_masks_form_t *form, const dt_iop_roi_t *roi, float *buffer) +static int dt_ellipse_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, dt_masks_form_t *form, + const dt_iop_roi_t *roi, float *buffer) { double start2 = dt_get_wtime(); @@ -1360,24 +1366,25 @@ static int dt_ellipse_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop start2 = dt_get_wtime(); // we back transform all these points - if(!dt_dev_distort_backtransform_plus(module->dev, piece->pipe, 0, module->priority, points, - (size_t)mw * mh)) + if(!dt_dev_distort_backtransform_plus(module->dev, piece->pipe, 0, module->priority, points, (size_t)mw * mh)) { free(points); return 0; } if(darktable.unmuted & DT_DEBUG_PERF) - dt_print(DT_DEBUG_MASKS, "[masks %s] ellipse transform took %0.04f sec\n", form->name, - dt_get_wtime() - start2); + dt_print(DT_DEBUG_MASKS, "[masks %s] ellipse transform took %0.04f sec\n", form->name, dt_get_wtime() - start2); start2 = dt_get_wtime(); // we populate the buffer const int wi = piece->pipe->iwidth, hi = piece->pipe->iheight; const float center[2] = { ellipse->center[0] * wi, ellipse->center[1] * hi }; const float radius[2] = { ellipse->radius[0] * MIN(wi, hi), ellipse->radius[1] * MIN(wi, hi) }; - const float total[2] = { (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? ellipse->radius[0] * (1.0f + ellipse->border) : ellipse->radius[0] + ellipse->border) * MIN(wi, hi), - (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? ellipse->radius[1] * (1.0f + ellipse->border) : ellipse->radius[1] + ellipse->border) * MIN(wi, hi) }; + const float total[2] + = { (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? ellipse->radius[0] * (1.0f + ellipse->border) + : ellipse->radius[0] + ellipse->border) * MIN(wi, hi), + (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? ellipse->radius[1] * (1.0f + ellipse->border) + : ellipse->radius[1] + ellipse->border) * MIN(wi, hi) }; float a, b, ta, tb, alpha; @@ -1458,7 +1465,7 @@ static int dt_ellipse_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop if(darktable.unmuted & DT_DEBUG_PERF) dt_print(DT_DEBUG_MASKS, "[masks %s] ellipse fill took %0.04f sec\n", form->name, dt_get_wtime() - start2); -// start2 = dt_get_wtime(); + // start2 = dt_get_wtime(); return 1; } diff --git a/src/develop/masks/gradient.c b/src/develop/masks/gradient.c index 73b1eb51e9c4..bac9756ccdde 100644 --- a/src/develop/masks/gradient.c +++ b/src/develop/masks/gradient.c @@ -27,13 +27,13 @@ static inline void _gradient_point_transform(const float xref, const float yref, const float x, const float y, const float sinv, const float cosv, float *xnew, float *ynew) { - *xnew = xref + cosv * (x - xref) - sinv * (y - yref); - *ynew = yref + sinv * (x - xref) + cosv * (y - yref); + *xnew = xref + cosv *(x - xref) - sinv * (y - yref); + *ynew = yref + sinv *(x - xref) + cosv * (y - yref); } -static void dt_gradient_get_distance(float x, float y, float as, dt_masks_form_gui_t *gui, int index, - int *inside, int *inside_border, int *near, int *inside_source) +static void dt_gradient_get_distance(float x, float y, float as, dt_masks_form_gui_t *gui, int index, int *inside, + int *inside_border, int *near, int *inside_source) { if(!gui) return; @@ -58,7 +58,8 @@ static void dt_gradient_get_distance(float x, float y, float as, dt_masks_form_g for(int i = 0; i < gpt->border_count; i++) { if((x - gpt->border[i * 2]) * (x - gpt->border[i * 2]) - + (y - gpt->border[i * 2 + 1]) * (y - gpt->border[i * 2 + 1]) < as2) + + (y - gpt->border[i * 2 + 1]) * (y - gpt->border[i * 2 + 1]) + < as2) { *inside_border = 1; return; @@ -69,7 +70,8 @@ static void dt_gradient_get_distance(float x, float y, float as, dt_masks_form_g for(int i = 3; i < gpt->points_count; i++) { if((x - gpt->points[i * 2]) * (x - gpt->points[i * 2]) - + (y - gpt->points[i * 2 + 1]) * (y - gpt->points[i * 2 + 1]) < as2) + + (y - gpt->points[i * 2 + 1]) * (y - gpt->points[i * 2 + 1]) + < as2) { *inside = 1; return; @@ -113,10 +115,9 @@ static int dt_gradient_events_mouse_scrolled(struct dt_iop_module_t *module, flo return 0; } -static int dt_gradient_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 dt_gradient_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) { if(!gui) return 0; if(!gui->creation && gui->edit_mode == DT_MASKS_EDIT_FULL) @@ -145,8 +146,7 @@ static int dt_gradient_events_button_pressed(struct dt_iop_module_t *module, flo { dt_iop_module_t *crea_module = gui->creation_module; // we create the circle - dt_masks_point_gradient_t *gradient - = (dt_masks_point_gradient_t *)(malloc(sizeof(dt_masks_point_gradient_t))); + dt_masks_point_gradient_t *gradient = (dt_masks_point_gradient_t *)(malloc(sizeof(dt_masks_point_gradient_t))); // we change the offset value float wd = darktable.develop->preview_pipe->backbuf_width; @@ -211,8 +211,7 @@ static int dt_gradient_events_button_released(struct dt_iop_module_t *module, fl dt_masks_point_group_t *gpt = (dt_masks_point_group_t *)forms->data; if(gpt->formid == form->formid) { - darktable.develop->form_visible->points - = g_list_remove(darktable.develop->form_visible->points, gpt); + darktable.develop->form_visible->points = g_list_remove(darktable.develop->form_visible->points, gpt); free(gpt); break; } @@ -292,9 +291,9 @@ static int dt_gradient_events_button_released(struct dt_iop_module_t *module, fl return 0; } -static int dt_gradient_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 int dt_gradient_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) { if(gui->form_dragging || gui->form_rotating) { @@ -316,16 +315,14 @@ static int dt_gradient_events_mouse_moved(struct dt_iop_module_t *module, float dt_masks_form_gui_points_t *gpt = (dt_masks_form_gui_points_t *)g_list_nth_data(gui->points, index); - if(gpt - && (x - gpt->points[2]) * (x - gpt->points[2]) + (y - gpt->points[3]) * (y - gpt->points[3]) < as * as) + if(gpt && (x - gpt->points[2]) * (x - gpt->points[2]) + (y - gpt->points[3]) * (y - gpt->points[3]) < as * as) { gui->pivot_selected = TRUE; gui->form_selected = TRUE; gui->border_selected = FALSE; } else if(gpt - && (x - gpt->points[4]) * (x - gpt->points[4]) + (y - gpt->points[5]) * (y - gpt->points[5]) - < as * as) + && (x - gpt->points[4]) * (x - gpt->points[4]) + (y - gpt->points[5]) * (y - gpt->points[5]) < as * as) { gui->pivot_selected = TRUE; gui->form_selected = TRUE; @@ -395,8 +392,8 @@ static void dt_gradient_events_post_expose(cairo_t *cr, float zoom_scale, dt_mas cairo_move_to(cr, x, y); for(int i = 5; i < gpt->points_count; i++) { - _gradient_point_transform(xref, yref, gpt->points[i * 2] + dx, gpt->points[i * 2 + 1] + dy, sinv, cosv, - &x, &y); + _gradient_point_transform(xref, yref, gpt->points[i * 2] + dx, gpt->points[i * 2 + 1] + dy, sinv, cosv, &x, + &y); cairo_line_to(cr, x, y); } cairo_stroke_preserve(cr); @@ -425,14 +422,14 @@ static void dt_gradient_events_post_expose(cairo_t *cr, float zoom_scale, dt_mas cairo_set_line_width(cr, 1.0 / zoom_scale); cairo_set_source_rgba(cr, .3, .3, .3, .8); - _gradient_point_transform(xref, yref, gpt->border[count * 2] + dx, gpt->border[count * 2 + 1] + dy, - sinv, cosv, &x, &y); + _gradient_point_transform(xref, yref, gpt->border[count * 2] + dx, gpt->border[count * 2 + 1] + dy, sinv, + cosv, &x, &y); cairo_move_to(cr, x, y); count++; for(; count < border_count && !isinf(border[count * 2]); count++) { - _gradient_point_transform(xref, yref, gpt->border[count * 2] + dx, gpt->border[count * 2 + 1] + dy, - sinv, cosv, &x, &y); + _gradient_point_transform(xref, yref, gpt->border[count * 2] + dx, gpt->border[count * 2 + 1] + dy, sinv, + cosv, &x, &y); cairo_line_to(cr, x, y); } cairo_stroke_preserve(cr); @@ -788,8 +785,7 @@ static int dt_gradient_get_mask(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t if(!dt_gradient_get_area(module, piece, form, width, height, posx, posy)) return 0; if(darktable.unmuted & DT_DEBUG_PERF) - dt_print(DT_DEBUG_MASKS, "[masks %s] gradient area took %0.04f sec\n", form->name, - dt_get_wtime() - start2); + dt_print(DT_DEBUG_MASKS, "[masks %s] gradient area took %0.04f sec\n", form->name, dt_get_wtime() - start2); start2 = dt_get_wtime(); // we get the gradient values @@ -822,8 +818,7 @@ static int dt_gradient_get_mask(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t } if(darktable.unmuted & DT_DEBUG_PERF) - dt_print(DT_DEBUG_MASKS, "[masks %s] gradient draw took %0.04f sec\n", form->name, - dt_get_wtime() - start2); + dt_print(DT_DEBUG_MASKS, "[masks %s] gradient draw took %0.04f sec\n", form->name, dt_get_wtime() - start2); start2 = dt_get_wtime(); // we backtransform all these points @@ -906,16 +901,15 @@ static int dt_gradient_get_mask(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t free(points); if(darktable.unmuted & DT_DEBUG_PERF) - dt_print(DT_DEBUG_MASKS, "[masks %s] gradient fill took %0.04f sec\n", form->name, - dt_get_wtime() - start2); -// start2 = dt_get_wtime(); + dt_print(DT_DEBUG_MASKS, "[masks %s] gradient fill took %0.04f sec\n", form->name, dt_get_wtime() - start2); + // start2 = dt_get_wtime(); return 1; } -static int dt_gradient_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, - dt_masks_form_t *form, const dt_iop_roi_t *roi, float *buffer) +static int dt_gradient_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, dt_masks_form_t *form, + const dt_iop_roi_t *roi, float *buffer) { double start2 = dt_get_wtime(); @@ -951,13 +945,11 @@ static int dt_gradient_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_io } if(darktable.unmuted & DT_DEBUG_PERF) - dt_print(DT_DEBUG_MASKS, "[masks %s] gradient draw took %0.04f sec\n", form->name, - dt_get_wtime() - start2); + dt_print(DT_DEBUG_MASKS, "[masks %s] gradient draw took %0.04f sec\n", form->name, dt_get_wtime() - start2); start2 = dt_get_wtime(); // we backtransform all these points - if(!dt_dev_distort_backtransform_plus(module->dev, piece->pipe, 0, module->priority, points, - (size_t)mw * mh)) + if(!dt_dev_distort_backtransform_plus(module->dev, piece->pipe, 0, module->priority, points, (size_t)mw * mh)) { free(points); return 0; @@ -1030,9 +1022,8 @@ static int dt_gradient_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_io free(points); if(darktable.unmuted & DT_DEBUG_PERF) - dt_print(DT_DEBUG_MASKS, "[masks %s] gradient fill took %0.04f sec\n", form->name, - dt_get_wtime() - start2); -// start2 = dt_get_wtime(); + dt_print(DT_DEBUG_MASKS, "[masks %s] gradient fill took %0.04f sec\n", form->name, dt_get_wtime() - start2); + // start2 = dt_get_wtime(); return 1; } diff --git a/src/develop/masks/group.c b/src/develop/masks/group.c index 71fdb2f9cc3f..76ed31e25af1 100644 --- a/src/develop/masks/group.c +++ b/src/develop/masks/group.c @@ -35,8 +35,7 @@ static int dt_group_events_mouse_scrolled(struct dt_iop_module_t *module, float return dt_circle_events_mouse_scrolled(module, pzx, pzy, up, state, sel, fpt->parentid, gui, gui->group_edited); else if(sel->type & DT_MASKS_PATH) - return dt_path_events_mouse_scrolled(module, pzx, pzy, up, state, sel, fpt->parentid, gui, - gui->group_edited); + return dt_path_events_mouse_scrolled(module, pzx, pzy, up, state, sel, fpt->parentid, gui, gui->group_edited); else if(sel->type & DT_MASKS_GRADIENT) return dt_gradient_events_mouse_scrolled(module, pzx, pzy, up, state, sel, fpt->parentid, gui, gui->group_edited); @@ -50,9 +49,9 @@ static int dt_group_events_mouse_scrolled(struct dt_iop_module_t *module, float return 0; } -static int dt_group_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, dt_masks_form_gui_t *gui) +static int dt_group_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, + dt_masks_form_gui_t *gui) { if(gui->group_edited != gui->group_selected) { @@ -75,20 +74,20 @@ static int dt_group_events_button_pressed(struct dt_iop_module_t *module, float dt_masks_form_t *sel = dt_masks_get_from_id(darktable.develop, fpt->formid); if(!sel) return 0; if(sel->type & DT_MASKS_CIRCLE) - return dt_circle_events_button_pressed(module, pzx, pzy, pressure, which, type, state, sel, - fpt->parentid, gui, gui->group_edited); + return dt_circle_events_button_pressed(module, pzx, pzy, pressure, which, type, state, sel, fpt->parentid, + gui, gui->group_edited); else if(sel->type & DT_MASKS_PATH) - return dt_path_events_button_pressed(module, pzx, pzy, pressure, which, type, state, sel, fpt->parentid, - gui, gui->group_edited); + return dt_path_events_button_pressed(module, pzx, pzy, pressure, which, type, state, sel, fpt->parentid, gui, + gui->group_edited); else if(sel->type & DT_MASKS_GRADIENT) - return dt_gradient_events_button_pressed(module, pzx, pzy, pressure, which, type, state, sel, - fpt->parentid, gui, gui->group_edited); + return dt_gradient_events_button_pressed(module, pzx, pzy, pressure, which, type, state, sel, fpt->parentid, + gui, gui->group_edited); else if(sel->type & DT_MASKS_ELLIPSE) - return dt_ellipse_events_button_pressed(module, pzx, pzy, pressure, which, type, state, sel, - fpt->parentid, gui, gui->group_edited); + return dt_ellipse_events_button_pressed(module, pzx, pzy, pressure, which, type, state, sel, fpt->parentid, + gui, gui->group_edited); else if(sel->type & DT_MASKS_BRUSH) - return dt_brush_events_button_pressed(module, pzx, pzy, pressure, which, type, state, sel, - fpt->parentid, gui, gui->group_edited); + return dt_brush_events_button_pressed(module, pzx, pzy, pressure, which, type, state, sel, fpt->parentid, + gui, gui->group_edited); } return 0; } @@ -230,7 +229,7 @@ static void dt_group_events_post_expose(cairo_t *cr, float zoom_scale, dt_masks_ { dt_masks_point_group_t *fpt = (dt_masks_point_group_t *)fpts->data; dt_masks_form_t *sel = dt_masks_get_from_id(darktable.develop, fpt->formid); - if (!sel) return; + if(!sel) return; if(sel->type & DT_MASKS_CIRCLE) dt_circle_events_post_expose(cr, zoom_scale, gui, pos); else if(sel->type & DT_MASKS_PATH) @@ -316,7 +315,7 @@ static int dt_group_get_mask(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *pi _inverse_mask(module, piece, sel, &bufs[pos], &w[pos], &h[pos], &px[pos], &py[pos]); if(darktable.unmuted & DT_DEBUG_PERF) dt_print(DT_DEBUG_MASKS, "[masks %s] inverse took %0.04f sec\n", sel->name, dt_get_wtime() - start2); -// start2 = dt_get_wtime(); + // start2 = dt_get_wtime(); } op[pos] = fpt->opacity; states[pos] = fpt->state; @@ -422,7 +421,7 @@ static int dt_group_get_mask(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *pi if(darktable.unmuted & DT_DEBUG_PERF) dt_print(DT_DEBUG_MASKS, "[masks %d] combine took %0.04f sec\n", i, dt_get_wtime() - start2); -// start2 = dt_get_wtime(); + // start2 = dt_get_wtime(); } free(op); @@ -510,8 +509,8 @@ int dt_masks_group_render(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece return 1; } -static int dt_group_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, - dt_masks_form_t *form, const dt_iop_roi_t *roi, float *buffer) +static int dt_group_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, dt_masks_form_t *form, + const dt_iop_roi_t *roi, float *buffer) { double start2 = dt_get_wtime(); const guint nb = g_list_length(form->points); diff --git a/src/develop/masks/masks.c b/src/develop/masks/masks.c index 72f278609bcc..222dba8c0884 100644 --- a/src/develop/masks/masks.c +++ b/src/develop/masks/masks.c @@ -50,7 +50,7 @@ static void _masks_write_forms_db(dt_develop_t *dev, gboolean undo); static dt_masks_form_t *_dup_masks_form(const dt_masks_form_t *form) { - if (!form) return NULL; + if(!form) return NULL; dt_masks_form_t *new_form = malloc(sizeof(struct dt_masks_form_t)); memcpy(new_form, form, sizeof(struct dt_masks_form_t)); @@ -59,27 +59,27 @@ static dt_masks_form_t *_dup_masks_form(const dt_masks_form_t *form) new_form->points = NULL; - if (form->points) + if(form->points) { int size_item = 0; - if (form->type & DT_MASKS_CIRCLE) + if(form->type & DT_MASKS_CIRCLE) size_item = sizeof(struct dt_masks_point_circle_t); - else if (form->type & DT_MASKS_ELLIPSE) + else if(form->type & DT_MASKS_ELLIPSE) size_item = sizeof(struct dt_masks_point_ellipse_t); - else if (form->type & DT_MASKS_GRADIENT) + else if(form->type & DT_MASKS_GRADIENT) size_item = sizeof(struct dt_masks_point_gradient_t); - else if (form->type & DT_MASKS_BRUSH) + else if(form->type & DT_MASKS_BRUSH) size_item = sizeof(struct dt_masks_point_brush_t); - else if (form->type & DT_MASKS_GROUP) + else if(form->type & DT_MASKS_GROUP) size_item = sizeof(struct dt_masks_point_group_t); - else if (form->type & DT_MASKS_PATH) + else if(form->type & DT_MASKS_PATH) size_item = sizeof(struct dt_masks_point_path_t); - if (size_item != 0) + if(size_item != 0) { GList *pt = g_list_first(form->points); - while (pt) + while(pt) { void *item = malloc(size_item); memcpy(item, pt->data, size_item); @@ -111,7 +111,7 @@ static _masks_undo_data_t *_create_snapshot(GList *forms, dt_masks_form_t *form, { _masks_undo_data_t *data = malloc(sizeof(struct _masks_undo_data_t)); data->forms = _dup_masks_forms_deep(forms, form); - data->form = dev->form_visible ? _dup_masks_form(dev->form_visible) : NULL; + data->form = dev->form_visible ? _dup_masks_form(dev->form_visible) : NULL; return data; } @@ -181,7 +181,9 @@ static void _set_hinter_message(dt_masks_form_gui_t *gui, dt_masks_type_t formty if(gui->point_selected >= 0) g_strlcat(msg, _("ctrl+click to rotate"), sizeof(msg)); else if(gui->form_selected) - g_strlcat(msg, _("shift+click to switch feathering mode, ctrl+scroll to set shape opacity,\nshift+scroll to set feather size"), sizeof(msg)); + g_strlcat(msg, _("shift+click to switch feathering mode, ctrl+scroll to set shape opacity,\nshift+scroll to " + "set feather size"), + sizeof(msg)); } else if(formtype & DT_MASKS_BRUSH) { @@ -206,8 +208,7 @@ void dt_masks_gui_form_create(dt_masks_form_t *form, dt_masks_form_gui_t *gui, i { if(g_list_length(gui->points) == index) { - dt_masks_form_gui_points_t *gpt2 - = (dt_masks_form_gui_points_t *)calloc(1, sizeof(dt_masks_form_gui_points_t)); + dt_masks_form_gui_points_t *gpt2 = (dt_masks_form_gui_points_t *)calloc(1, sizeof(dt_masks_form_gui_points_t)); gui->points = g_list_append(gui->points, gpt2); } else if(g_list_length(gui->points) < index) @@ -279,7 +280,7 @@ void dt_masks_gui_form_test_create(dt_masks_form_t *form, dt_masks_form_gui_t *g { dt_masks_point_group_t *fpt = (dt_masks_point_group_t *)fpts->data; dt_masks_form_t *sel = dt_masks_get_from_id(darktable.develop, fpt->formid); - if (!sel) return; + if(!sel) return; dt_masks_gui_form_create(sel, gui, pos); fpts = g_list_next(fpts); pos++; @@ -504,8 +505,8 @@ int dt_masks_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, float * points_count)) { if(border) - return dt_gradient_get_points_border(dev, gradient->anchor[0], gradient->anchor[1], - gradient->rotation, gradient->compression, border, border_count); + return dt_gradient_get_points_border(dev, gradient->anchor[0], gradient->anchor[1], gradient->rotation, + gradient->compression, border, border_count); else return 1; } @@ -522,10 +523,11 @@ int dt_masks_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, float * if(dt_ellipse_get_points(dev, x, y, a, b, ellipse->rotation, points, points_count)) { if(border) - return dt_ellipse_get_points(dev, x, y, - (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? a * (1.0f + ellipse->border) : a + ellipse->border), - (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? b * (1.0f + ellipse->border) : b + ellipse->border), - ellipse->rotation, border, border_count); + return dt_ellipse_get_points( + dev, x, y, + (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? a * (1.0f + ellipse->border) : a + ellipse->border), + (ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL ? b * (1.0f + ellipse->border) : b + ellipse->border), + ellipse->rotation, border, border_count); else return 1; } @@ -534,8 +536,8 @@ int dt_masks_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, float * return 0; } -int dt_masks_get_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) +int dt_masks_get_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) { if(form->type & DT_MASKS_CIRCLE) { @@ -1027,15 +1029,13 @@ void dt_masks_read_forms(dt_develop_t *dev) } else if(form->type & DT_MASKS_GRADIENT) { - dt_masks_point_gradient_t *gradient - = (dt_masks_point_gradient_t *)malloc(sizeof(dt_masks_point_gradient_t)); + dt_masks_point_gradient_t *gradient = (dt_masks_point_gradient_t *)malloc(sizeof(dt_masks_point_gradient_t)); memcpy(gradient, sqlite3_column_blob(stmt, 5), sizeof(dt_masks_point_gradient_t)); form->points = g_list_append(form->points, gradient); } else if(form->type & DT_MASKS_ELLIPSE) { - dt_masks_point_ellipse_t *ellipse - = (dt_masks_point_ellipse_t *)malloc(sizeof(dt_masks_point_ellipse_t)); + dt_masks_point_ellipse_t *ellipse = (dt_masks_point_ellipse_t *)malloc(sizeof(dt_masks_point_ellipse_t)); memcpy(ellipse, sqlite3_column_blob(stmt, 5), sizeof(dt_masks_point_ellipse_t)); form->points = g_list_append(form->points, ellipse); } @@ -1058,8 +1058,7 @@ void dt_masks_read_forms(dt_develop_t *dev) while(fname > dev->image_storage.filename && *fname != '/') fname--; if(fname > dev->image_storage.filename) fname++; - fprintf(stderr, - "[dt_masks_read_forms] %s (imgid `%i'): mask version mismatch: history is %d, dt %d.\n", + fprintf(stderr, "[dt_masks_read_forms] %s (imgid `%i'): mask version mismatch: history is %d, dt %d.\n", fname, dev->image_storage.id, form->version, dt_masks_version()); dt_control_log(_("%s: mask version mismatch: %d != %d"), fname, dt_masks_version(), form->version); @@ -1087,7 +1086,7 @@ static void _masks_write_forms_db(dt_develop_t *dev, gboolean undo) // and now we write each forms GList *forms = g_list_first(dev->forms); - if (undo) + if(undo) { _do_record_undo(dev, NULL); } @@ -1096,8 +1095,7 @@ static void _masks_write_forms_db(dt_develop_t *dev, gboolean undo) { dt_masks_form_t *form = (dt_masks_form_t *)forms->data; - if (form) - _masks_write_form_db(form, dev); + if(form) _masks_write_form_db(form, dev); forms = g_list_next(forms); } @@ -1262,8 +1260,7 @@ int dt_masks_events_mouse_moved(struct dt_iop_module_t *module, double x, double if(gui->group_edited >= 0) { // we get the slected form - dt_masks_point_group_t *fpt - = (dt_masks_point_group_t *)g_list_nth_data(form->points, gui->group_edited); + dt_masks_point_group_t *fpt = (dt_masks_point_group_t *)g_list_nth_data(form->points, gui->group_edited); dt_masks_form_t *sel = dt_masks_get_from_id(darktable.develop, fpt->formid); if(!sel) return 0; ftype = sel->type; @@ -1274,8 +1271,7 @@ int dt_masks_events_mouse_moved(struct dt_iop_module_t *module, double x, double return rep; } -int dt_masks_events_button_released(struct dt_iop_module_t *module, double x, double y, int which, - uint32_t state) +int dt_masks_events_button_released(struct dt_iop_module_t *module, double x, double y, int which, uint32_t state) { dt_masks_form_t *form = darktable.develop->form_visible; dt_masks_form_gui_t *gui = darktable.develop->form_gui; @@ -1300,8 +1296,8 @@ int dt_masks_events_button_released(struct dt_iop_module_t *module, double x, do return 0; } -int dt_masks_events_button_pressed(struct dt_iop_module_t *module, double x, double y, double pressure, - int which, int type, uint32_t state) +int dt_masks_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 = darktable.develop->form_visible; dt_masks_form_gui_t *gui = darktable.develop->form_gui; @@ -1487,7 +1483,7 @@ void dt_masks_set_edit_mode(struct dt_iop_module_t *module, dt_masks_edit_mode_t dt_masks_group_ungroup(grp, form); } - if (bd) bd->masks_shown = value; + if(bd) bd->masks_shown = value; dt_masks_change_form_gui(grp); darktable.develop->form_gui->edit_mode = value; @@ -1510,8 +1506,7 @@ void dt_masks_iop_edit_toggle_callback(GtkToggleButton *togglebutton, dt_iop_mod } // reset the gui - dt_masks_set_edit_mode(module, - (bd->masks_shown == DT_MASKS_EDIT_OFF ? DT_MASKS_EDIT_FULL : DT_MASKS_EDIT_OFF)); + dt_masks_set_edit_mode(module, (bd->masks_shown == DT_MASKS_EDIT_OFF ? DT_MASKS_EDIT_FULL : DT_MASKS_EDIT_OFF)); } static void _menu_no_masks(struct dt_iop_module_t *module) @@ -2292,14 +2287,14 @@ int dt_masks_point_in_form_exact(float x, float y, float *points, int points_sta for(int i = points_start; i < points_count; i++) { float yy = points[i * 2 + 1]; - //if we need to skip points (in case of deleted point, because of self-intersection) + // if we need to skip points (in case of deleted point, because of self-intersection) if(isnan(points[i * 2])) { if(isnan(yy)) break; i = (int)yy - 1; continue; } - if (((yf<=yy && yf>last) || (yf>=yy && yf<last)) && (points[i * 2] > x)) nb++; + if(((yf <= yy && yf > last) || (yf >= yy && yf < last)) && (points[i * 2] > x)) nb++; last = yy; } return (nb & 1); @@ -2307,7 +2302,8 @@ int dt_masks_point_in_form_exact(float x, float y, float *points, int points_sta return 0; } -int dt_masks_point_in_form_near(float x, float y, float *points, int points_start, int points_count, float distance, int *near) +int dt_masks_point_in_form_near(float x, float y, float *points, int points_start, int points_count, + float distance, int *near) { // we use ray casting algorith // to avoid most problems with horizontal segments, y should be rounded as int @@ -2323,14 +2319,14 @@ int dt_masks_point_in_form_near(float x, float y, float *points, int points_star for(int i = points_start; i < points_count; i++) { float yy = points[i * 2 + 1]; - //if we need to jump to skip points (in case of deleted point, because of self-intersection) + // if we need to jump to skip points (in case of deleted point, because of self-intersection) if(isnan(points[i * 2])) { if(isnan(yy)) break; i = (int)yy - 1; continue; } - if ((yf<=yy && yf>last) || (yf>=yy && yf<last)) + if((yf <= yy && yf > last) || (yf >= yy && yf < last)) { if(points[i * 2] > x) nb++; if(points[i * 2] - x < distance && points[i * 2] - x > -distance) *near = 1; diff --git a/src/develop/masks/path.c b/src/develop/masks/path.c index d290ef83f3fa..8863d0eb83f2 100644 --- a/src/develop/masks/path.c +++ b/src/develop/masks/path.c @@ -26,15 +26,15 @@ /** get the point of the path at pos t [0,1] */ -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_get_XY(float p0x, float p0y, float p1x, float p1y, float p2x, float p2y, float p3x, float p3y, + float t, float *x, float *y) { float a = (1 - t) * (1 - t) * (1 - t); float b = 3 * t * (1 - t) * (1 - t); float c = 3 * t * t * (1 - t); float d = t * t * t; - *x = p0x * a + p1x * b + p2x * c + p3x * d; - *y = p0y * a + p1y * b + p2y * c + p3y * d; + *x = p0x *a + p1x *b + p2x *c + p3x *d; + *y = p0y *a + p1y *b + p2y *c + p3y *d; } /** get the point of the path at pos t [0,1] AND the corresponding border point */ @@ -67,8 +67,7 @@ static void _path_border_get_XY(float p0x, float p0y, float p1x, float p1y, floa /** get feather extremity from the control point n°2 */ /** the values should be in orthonormal space */ -static void _path_ctrl2_to_feather(int ptx, int pty, int ctrlx, int ctrly, int *fx, int *fy, - gboolean clockwise) +static void _path_ctrl2_to_feather(int ptx, int pty, int ctrlx, int ctrly, int *fx, int *fy, gboolean clockwise) { if(clockwise) { @@ -104,8 +103,8 @@ static void _path_feather_to_ctrl(int ptx, int pty, int fx, int fy, int *ctrl1x, } /** Get the control points of a segment to match exactly a catmull-rom spline */ -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_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) { *bx1 = (-x1 + 6 * x2 + x3) / 6; *by1 = (-y1 + 6 * y2 + y3) / 6; @@ -139,15 +138,15 @@ static void _path_init_ctrl_points(dt_masks_form_t *form) float bx1, by1, bx2, by2; _path_catmull_to_bezier(point1->corner[0], point1->corner[1], point2->corner[0], point2->corner[1], - point3->corner[0], point3->corner[1], point4->corner[0], point4->corner[1], - &bx1, &by1, &bx2, &by2); + point3->corner[0], point3->corner[1], point4->corner[0], point4->corner[1], &bx1, + &by1, &bx2, &by2); if(point2->ctrl2[0] == -1.0) point2->ctrl2[0] = bx1; if(point2->ctrl2[1] == -1.0) point2->ctrl2[1] = by1; point3->ctrl1[0] = bx2; point3->ctrl1[1] = by2; _path_catmull_to_bezier(point2->corner[0], point2->corner[1], point3->corner[0], point3->corner[1], - point4->corner[0], point4->corner[1], point5->corner[0], point5->corner[1], - &bx1, &by1, &bx2, &by2); + point4->corner[0], point4->corner[1], point5->corner[0], point5->corner[1], &bx1, + &by1, &bx2, &by2); if(point4->ctrl1[0] == -1.0) point4->ctrl1[0] = bx2; if(point4->ctrl1[1] == -1.0) point4->ctrl1[1] = by2; point3->ctrl2[0] = bx1; @@ -241,8 +240,9 @@ static int _path_fill_gaps(int lastx, int lasty, int x, int y, dt_masks_dynbuf_t /** 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 */ -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_border_gaps(float *cmax, float *bmin, float *bmin2, float *bmax, + dt_masks_dynbuf_t *dpoints, dt_masks_dynbuf_t *dborder, + gboolean clockwise) { // we want to find the start and end angles double a1 = atan2(bmin[1] - cmax[1], bmin[0] - cmax[0]); @@ -289,10 +289,9 @@ static void _path_points_recurs_border_gaps(float *cmax, float *bmin, float *bmi /** 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 */ -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 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) { // we calculate points if needed if(isnan(path_min[0])) @@ -313,8 +312,7 @@ static void _path_points_recurs(float *p1, float *p2, double tmin, double tmax, && (int)path_min[1] - (int)path_max[1] < 1 && (int)path_min[1] - (int)path_max[1] > -1 && (!withborder || ((int)border_min[0] - (int)border_max[0] < 1 && (int)border_min[0] - (int)border_max[0] > -1 - && (int)border_min[1] - (int)border_max[1] < 1 - && (int)border_min[1] - (int)border_max[1] > -1)))) + && (int)border_min[1] - (int)border_max[1] < 1 && (int)border_min[1] - (int)border_max[1] > -1)))) { dt_masks_dynbuf_add(dpoints, path_max[0]); dt_masks_dynbuf_add(dpoints, path_max[1]); @@ -443,9 +441,8 @@ static int _path_find_self_intersection(dt_masks_dynbuf_t *inter, int nb_corners // this is not a real self-interesection, so we just update binter binter[(yy - ymin) * wb + (xx - xmin)] = i; } - else if((i > v[k] - && ((posextr[0] < v[k] || posextr[0] > i) && (posextr[1] < v[k] || posextr[1] > i) - && (posextr[2] < v[k] || posextr[2] > i) && (posextr[3] < v[k] || posextr[3] > i))) + else if((i > v[k] && ((posextr[0] < v[k] || posextr[0] > i) && (posextr[1] < v[k] || posextr[1] > i) + && (posextr[2] < v[k] || posextr[2] > i) && (posextr[3] < v[k] || posextr[3] > i))) || (i < v[k] && posextr[0] < v[k] && posextr[0] > i && posextr[1] < v[k] && posextr[1] > i && posextr[2] < v[k] && posextr[2] > i && posextr[3] < v[k] && posextr[3] > i)) { @@ -500,8 +497,8 @@ static int _path_find_self_intersection(dt_masks_dynbuf_t *inter, int nb_corners /** get all points of the path and the border */ /** this take care of gaps and self-intersection and iop distortions */ static int _path_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, int prio_max, - dt_dev_pixelpipe_t *pipe, float **points, int *points_count, - float **border, int *border_count, int source) + dt_dev_pixelpipe_t *pipe, float **points, int *points_count, float **border, + int *border_count, int source) { double start2 = dt_get_wtime(); @@ -575,8 +572,7 @@ static int _path_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, int if(cw == 0) cw = -1; if(darktable.unmuted & DT_DEBUG_PERF) - dt_print(DT_DEBUG_MASKS, "[masks %s] path_points init took %0.04f sec\n", form->name, - dt_get_wtime() - start2); + dt_print(DT_DEBUG_MASKS, "[masks %s] path_points init took %0.04f sec\n", form->name, dt_get_wtime() - start2); start2 = dt_get_wtime(); // we render all segments @@ -608,8 +604,8 @@ static int _path_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, int _path_points_recurs(p1, p2, 0.0, 1.0, cmin, cmax, bmin, bmax, rc, rb, dpoints, dborder, border && (nb >= 3)); // we check gaps in the border (sharp edges) - if(dborder && (fabs(dt_masks_dynbuf_get(dborder, -2) - rb[0]) > 1.0f || - fabs(dt_masks_dynbuf_get(dborder, -1) - rb[1]) > 1.0f)) + if(dborder && (fabs(dt_masks_dynbuf_get(dborder, -2) - rb[0]) > 1.0f + || fabs(dt_masks_dynbuf_get(dborder, -1) - rb[1]) > 1.0f)) { bmin[0] = dt_masks_dynbuf_get(dborder, -2); bmin[1] = dt_masks_dynbuf_get(dborder, -1); @@ -617,14 +613,14 @@ static int _path_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, int dt_masks_dynbuf_add(dpoints, rc[0]); dt_masks_dynbuf_add(dpoints, rc[1]); - + border_init[k * 6 + 4] = dborder ? -dt_masks_dynbuf_position(dborder) : 0; if(dborder) { if(isnan(rb[0])) { - if(isnan(dt_masks_dynbuf_get(dborder, - 2))) + if(isnan(dt_masks_dynbuf_get(dborder, -2))) { dt_masks_dynbuf_set(dborder, -2, dt_masks_dynbuf_get(dborder, -4)); dt_masks_dynbuf_set(dborder, -1, dt_masks_dynbuf_get(dborder, -3)); @@ -636,19 +632,20 @@ static int _path_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, int dt_masks_dynbuf_add(dborder, rb[1]); (dt_masks_dynbuf_buffer(dborder))[k * 6] = border_init[k * 6] = (dt_masks_dynbuf_buffer(dborder))[pb]; - (dt_masks_dynbuf_buffer(dborder))[k * 6 + 1] = border_init[k * 6 + 1] = (dt_masks_dynbuf_buffer(dborder))[pb + 1]; + (dt_masks_dynbuf_buffer(dborder))[k * 6 + 1] = border_init[k * 6 + 1] + = (dt_masks_dynbuf_buffer(dborder))[pb + 1]; } // we first want to be sure that there are no gaps in border if(dborder && nb >= 3) { // we get the next point (start of the next segment) - _path_border_get_XY(p3[0], p3[1], p3[2], p3[3], p4[2], p4[3], p4[0], p4[1], 0, p3[4], cmin, cmin + 1, - bmax, bmax + 1); + _path_border_get_XY(p3[0], p3[1], p3[2], p3[3], p4[2], p4[3], p4[0], p4[1], 0, p3[4], cmin, cmin + 1, bmax, + bmax + 1); if(isnan(bmax[0])) { - _path_border_get_XY(p3[0], p3[1], p3[2], p3[3], p4[2], p4[3], p4[0], p4[1], 0.0001, p3[4], cmin, - cmin + 1, bmax, bmax + 1); + _path_border_get_XY(p3[0], p3[1], p3[2], p3[3], p4[2], p4[3], p4[0], p4[1], 0.0001, p3[4], cmin, cmin + 1, + bmax, bmax + 1); } if(bmax[0] - rb[0] > 1 || bmax[0] - rb[0] < -1 || bmax[1] - rb[1] > 1 || bmax[1] - rb[1] < -1) { @@ -706,7 +703,7 @@ static int _path_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, int for(int i = 0; i < inter_count; i++) { int v = (dt_masks_dynbuf_buffer(intersections))[i * 2]; - int w = (dt_masks_dynbuf_buffer(intersections))[ i * 2 + 1]; + int w = (dt_masks_dynbuf_buffer(intersections))[i * 2 + 1]; if(v <= w) { (*border)[v * 2] = NAN; @@ -733,7 +730,7 @@ static int _path_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, int if(darktable.unmuted & DT_DEBUG_PERF) dt_print(DT_DEBUG_MASKS, "[masks %s] path_points end took %0.04f sec\n", form->name, dt_get_wtime() - start2); -// start2 = dt_get_wtime(); + // start2 = dt_get_wtime(); dt_masks_dynbuf_free(intersections); free(border_init); return 1; @@ -753,9 +750,8 @@ static int _path_get_points_border(dt_develop_t *dev, dt_masks_form_t *form, int } /** get the distance between point (x,y) and the path */ -static void dt_path_get_distance(float x, int y, float as, dt_masks_form_gui_t *gui, int index, - int corner_count, int *inside, int *inside_border, int *near, - int *inside_source) +static void dt_path_get_distance(float x, int y, float as, dt_masks_form_gui_t *gui, int index, int corner_count, + int *inside, int *inside_border, int *near, int *inside_source) { // initialise returned values *inside_source = 0; @@ -770,7 +766,7 @@ static void dt_path_get_distance(float x, int y, float as, dt_masks_form_gui_t * if(!gpt) return; // we first check if we are inside the source form - if(dt_masks_point_in_form_exact(x,yf,gpt->source,corner_count * 6,gpt->source_count)) + if(dt_masks_point_in_form_exact(x, yf, gpt->source, corner_count * 6, gpt->source_count)) { *inside_source = 1; *inside = 1; @@ -778,7 +774,7 @@ static void dt_path_get_distance(float x, int y, float as, dt_masks_form_gui_t * } // we check if it's inside borders - if(!dt_masks_point_in_form_exact(x,yf,gpt->border,corner_count * 3,gpt->border_count)) return; + if(!dt_masks_point_in_form_exact(x, yf, gpt->border, corner_count * 3, gpt->border_count)) return; *inside = 1; @@ -786,14 +782,14 @@ static void dt_path_get_distance(float x, int y, float as, dt_masks_form_gui_t * if(gpt->points_count > 2 + corner_count * 3) { float as2 = as * as; - //float as2 = 1600.0 * as1; + // float as2 = 1600.0 * as1; float last = gpt->points[gpt->points_count * 2 - 1]; int nb = 0; int near_form = 0; int current_seg = 1; for(int i = corner_count * 3; i < gpt->points_count; i++) { - //if we need to jump to skip points (in case of deleted point, because of self-intersection) + // if we need to jump to skip points (in case of deleted point, because of self-intersection) if(isnan(gpt->points[i * 2])) { if(isnan(gpt->points[i * 2 + 1])) break; @@ -801,14 +797,14 @@ static void dt_path_get_distance(float x, int y, float as, dt_masks_form_gui_t * continue; } // do we change of path segment ? - if(gpt->points[i * 2 + 1] == gpt->points[current_seg * 6 + 3] && gpt->points[i * 2] == gpt->points[current_seg * 6 + 2]) + if(gpt->points[i * 2 + 1] == gpt->points[current_seg * 6 + 3] + && gpt->points[i * 2] == gpt->points[current_seg * 6 + 2]) { current_seg = (current_seg + 1) % corner_count; } - //distance from tested point to current form point + // distance from tested point to current form point float yy = gpt->points[i * 2 + 1]; - float dd = (gpt->points[i * 2] - x) * (gpt->points[i * 2] - x) - + (yy - yf) * (yy - yf); + float dd = (gpt->points[i * 2] - x) * (gpt->points[i * 2] - x) + (yy - yf) * (yy - yf); if(dd < as2) { @@ -819,20 +815,21 @@ static void dt_path_get_distance(float x, int y, float as, dt_masks_form_gui_t * *near = current_seg - 1; } - if (((yf<=yy && yf>last) || (yf>=yy && yf<last)) && (gpt->points[i * 2] > x)) nb++; + if(((yf <= yy && yf > last) || (yf >= yy && yf < last)) && (gpt->points[i * 2] > x)) nb++; last = yy; } *inside_border = !((nb & 1) || (near_form)); } - else *inside_border = 1; + else + *inside_border = 1; } -static int dt_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) +static int dt_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) { - return _path_get_points_border(dev, form, 999999, dev->preview_pipe, points, points_count, border, - border_count, source); + return _path_get_points_border(dev, form, 999999, dev->preview_pipe, points, points_count, border, border_count, + source); } static int dt_path_events_mouse_scrolled(struct dt_iop_module_t *module, float pzx, float pzy, int up, @@ -953,10 +950,9 @@ static int dt_path_events_mouse_scrolled(struct dt_iop_module_t *module, float p return 0; } -static int dt_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 dt_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) { if(type == GDK_2BUTTON_PRESS || type == GDK_3BUTTON_PRESS) return 1; if(!gui) return 0; @@ -1090,8 +1086,7 @@ static int dt_path_events_button_pressed(struct dt_iop_module_t *module, float p // if ctrl is pressed, we change the type of point if(gui->point_edited == gui->point_selected && ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)) { - dt_masks_point_path_t *point - = (dt_masks_point_path_t *)g_list_nth_data(form->points, gui->point_edited); + dt_masks_point_path_t *point = (dt_masks_point_path_t *)g_list_nth_data(form->points, gui->point_edited); if(point->state != DT_MASKS_POINT_STATE_NORMAL) { point->state = DT_MASKS_POINT_STATE_NORMAL; @@ -1208,8 +1203,7 @@ static int dt_path_events_button_pressed(struct dt_iop_module_t *module, float p dt_masks_point_group_t *gpt = (dt_masks_point_group_t *)forms->data; if(gpt->formid == form->formid) { - darktable.develop->form_visible->points - = g_list_remove(darktable.develop->form_visible->points, gpt); + darktable.develop->form_visible->points = g_list_remove(darktable.develop->form_visible->points, gpt); free(gpt); break; } @@ -1224,8 +1218,7 @@ static int dt_path_events_button_pressed(struct dt_iop_module_t *module, float p dt_control_queue_redraw_center(); return 1; } - dt_masks_point_path_t *point - = (dt_masks_point_path_t *)g_list_nth_data(form->points, gui->point_selected); + dt_masks_point_path_t *point = (dt_masks_point_path_t *)g_list_nth_data(form->points, gui->point_selected); form->points = g_list_remove(form->points, point); free(point); // form->points = g_list_delete_link(form->points, g_list_nth(form->points, gui->point_selected)); @@ -1245,8 +1238,7 @@ static int dt_path_events_button_pressed(struct dt_iop_module_t *module, float p } else if(which == 3 && gui->feather_selected >= 0) { - dt_masks_point_path_t *point - = (dt_masks_point_path_t *)g_list_nth_data(form->points, gui->feather_selected); + dt_masks_point_path_t *point = (dt_masks_point_path_t *)g_list_nth_data(form->points, gui->feather_selected); if(point->state != DT_MASKS_POINT_STATE_NORMAL) { point->state = DT_MASKS_POINT_STATE_NORMAL; @@ -1279,8 +1271,7 @@ static int dt_path_events_button_pressed(struct dt_iop_module_t *module, float p dt_masks_point_group_t *gpt = (dt_masks_point_group_t *)forms->data; if(gpt->formid == form->formid) { - darktable.develop->form_visible->points - = g_list_remove(darktable.develop->form_visible->points, gpt); + darktable.develop->form_visible->points = g_list_remove(darktable.develop->form_visible->points, gpt); free(gpt); break; } @@ -1378,8 +1369,7 @@ static int dt_path_events_button_released(struct dt_iop_module_t *module, float } else if(gui->point_dragging >= 0) { - dt_masks_point_path_t *point - = (dt_masks_point_path_t *)g_list_nth_data(form->points, gui->point_dragging); + dt_masks_point_path_t *point = (dt_masks_point_path_t *)g_list_nth_data(form->points, gui->point_dragging); gui->point_dragging = -1; if(gui->scrollx != 0.0f || gui->scrolly != 0.0f) { @@ -1416,8 +1406,7 @@ static int dt_path_events_button_released(struct dt_iop_module_t *module, float } else if(gui->feather_dragging >= 0) { - dt_masks_point_path_t *point - = (dt_masks_point_path_t *)g_list_nth_data(form->points, gui->feather_dragging); + dt_masks_point_path_t *point = (dt_masks_point_path_t *)g_list_nth_data(form->points, gui->feather_dragging); gui->feather_dragging = -1; float wd = darktable.develop->preview_pipe->backbuf_width; float ht = darktable.develop->preview_pipe->backbuf_height; @@ -1426,8 +1415,8 @@ static int dt_path_events_button_released(struct dt_iop_module_t *module, float int p1x, p1y, p2x, p2y; _path_feather_to_ctrl(point->corner[0] * darktable.develop->preview_pipe->iwidth, - point->corner[1] * darktable.develop->preview_pipe->iheight, pts[0], pts[1], &p1x, - &p1y, &p2x, &p2y, gpt->clockwise); + point->corner[1] * darktable.develop->preview_pipe->iheight, pts[0], pts[1], &p1x, &p1y, + &p2x, &p2y, gpt->clockwise); point->ctrl1[0] = (float)p1x / darktable.develop->preview_pipe->iwidth; point->ctrl1[1] = (float)p1y / darktable.develop->preview_pipe->iheight; point->ctrl2[0] = (float)p2x / darktable.develop->preview_pipe->iwidth; @@ -1463,14 +1452,14 @@ static int dt_path_events_button_released(struct dt_iop_module_t *module, float } static int dt_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) + int which, dt_masks_form_t *form, int parentid, dt_masks_form_gui_t *gui, + int index) { dt_dev_zoom_t zoom = dt_control_get_dev_zoom(); int closeup = dt_control_get_dev_closeup(); float zoom_scale = dt_dev_get_zoom_scale(darktable.develop, zoom, closeup ? 2 : 1, 1); // centre view will have zoom_scale * backbuf_width pixels, we want the handle offset to scale with DPI: - const float as = DT_PIXEL_APPLY_DPI(5) / zoom_scale; // transformed to backbuf dimensions + const float as = DT_PIXEL_APPLY_DPI(5) / zoom_scale; // transformed to backbuf dimensions if(!gui) return 0; dt_masks_form_gui_points_t *gpt = (dt_masks_form_gui_points_t *)g_list_nth_data(gui->points, index); if(!gpt) return 0; @@ -1555,13 +1544,12 @@ static int dt_path_events_mouse_moved(struct dt_iop_module_t *module, float pzx, float ht = darktable.develop->preview_pipe->backbuf_height; float pts[2] = { pzx * wd, pzy * ht }; dt_dev_distort_backtransform(darktable.develop, pts, 1); - dt_masks_point_path_t *point - = (dt_masks_point_path_t *)g_list_nth_data(form->points, gui->feather_dragging); + dt_masks_point_path_t *point = (dt_masks_point_path_t *)g_list_nth_data(form->points, gui->feather_dragging); int p1x, p1y, p2x, p2y; _path_feather_to_ctrl(point->corner[0] * darktable.develop->preview_pipe->iwidth, - point->corner[1] * darktable.develop->preview_pipe->iheight, pts[0], pts[1], &p1x, - &p1y, &p2x, &p2y, gpt->clockwise); + point->corner[1] * darktable.develop->preview_pipe->iheight, pts[0], pts[1], &p1x, &p1y, + &p2x, &p2y, gpt->clockwise); point->ctrl1[0] = (float)p1x / darktable.develop->preview_pipe->iwidth; point->ctrl1[1] = (float)p1y / darktable.develop->preview_pipe->iheight; point->ctrl2[0] = (float)p2x / darktable.develop->preview_pipe->iwidth; @@ -1625,8 +1613,7 @@ static int dt_path_events_mouse_moved(struct dt_iop_module_t *module, float pzx, // are we near a point or feather ? guint nb = g_list_length(form->points); - pzx *= darktable.develop->preview_pipe->backbuf_width, - pzy *= darktable.develop->preview_pipe->backbuf_height; + pzx *= darktable.develop->preview_pipe->backbuf_width, pzy *= darktable.develop->preview_pipe->backbuf_height; if((gui->group_selected == index) && gui->point_edited >= 0) { @@ -1702,8 +1689,7 @@ static int dt_path_events_mouse_moved(struct dt_iop_module_t *module, float pzx, return 1; } -static void dt_path_events_post_expose(cairo_t *cr, float zoom_scale, dt_masks_form_gui_t *gui, int index, - int nb) +static void dt_path_events_post_expose(cairo_t *cr, float zoom_scale, dt_masks_form_gui_t *gui, int index, int nb) { double dashed[] = { 4.0, 4.0 }; dashed[0] /= zoom_scale; @@ -1803,9 +1789,8 @@ static void dt_path_events_post_expose(cairo_t *cr, float zoom_scale, dt_masks_f cairo_line_to(cr, gui->points[k*6+4]+dx,gui->points[k*6+5]+dy); cairo_stroke(cr);*/ int ffx, ffy; - _path_ctrl2_to_feather(gpt->points[k * 6 + 2] + dx, gpt->points[k * 6 + 3] + dy, - gpt->points[k * 6 + 4] + dx, gpt->points[k * 6 + 5] + dy, &ffx, &ffy, - gpt->clockwise); + _path_ctrl2_to_feather(gpt->points[k * 6 + 2] + dx, gpt->points[k * 6 + 3] + dy, gpt->points[k * 6 + 4] + dx, + gpt->points[k * 6 + 5] + dy, &ffx, &ffy, gpt->clockwise); cairo_move_to(cr, gpt->points[k * 6 + 2] + dx, gpt->points[k * 6 + 3] + dy); cairo_line_to(cr, ffx, ffy); cairo_set_line_width(cr, 1.5 / zoom_scale); @@ -1931,15 +1916,15 @@ static void dt_path_events_post_expose(cairo_t *cr, float zoom_scale, dt_masks_f } } -static int dt_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 dt_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) { if(!module) return 0; // we get buffers for all points float *points = NULL, *border = NULL; int points_count, border_count; - if(!_path_get_points_border(module->dev, form, module->priority, piece->pipe, &points, &points_count, - &border, &border_count, 1)) + if(!_path_get_points_border(module->dev, form, module->priority, piece->pipe, &points, &points_count, &border, + &border_count, 1)) { free(points); free(border); @@ -1994,8 +1979,8 @@ static int dt_path_get_area(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *pie // we get buffers for all points float *points = NULL, *border = NULL; int points_count, border_count; - if(!_path_get_points_border(module->dev, form, module->priority, piece->pipe, &points, &points_count, - &border, &border_count, 0)) + if(!_path_get_points_border(module->dev, form, module->priority, piece->pipe, &points, &points_count, &border, + &border_count, 0)) { free(points); free(border); @@ -2079,8 +2064,8 @@ static int dt_path_get_mask(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *pie // we get buffers for all points float *points = NULL, *border = NULL; int points_count, border_count; - if(!_path_get_points_border(module->dev, form, module->priority, piece->pipe, &points, &points_count, - &border, &border_count, 0)) + if(!_path_get_points_border(module->dev, form, module->priority, piece->pipe, &points, &points_count, &border, + &border_count, 0)) { free(points); free(border); @@ -2130,8 +2115,7 @@ static int dt_path_get_mask(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *pie *posy = ymin - 2; if(darktable.unmuted & DT_DEBUG_PERF) - dt_print(DT_DEBUG_MASKS, "[masks %s] path_fill min max took %0.04f sec\n", form->name, - dt_get_wtime() - start2); + dt_print(DT_DEBUG_MASKS, "[masks %s] path_fill min max took %0.04f sec\n", form->name, dt_get_wtime() - start2); start2 = dt_get_wtime(); // we allocate the buffer @@ -2303,8 +2287,7 @@ static int dt_path_get_mask(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *pie free(border); if(darktable.unmuted & DT_DEBUG_PERF) - dt_print(DT_DEBUG_MASKS, "[masks %s] path fill buffer took %0.04f sec\n", form->name, - dt_get_wtime() - start); + dt_print(DT_DEBUG_MASKS, "[masks %s] path fill buffer took %0.04f sec\n", form->name, dt_get_wtime() - start); return 1; } @@ -2312,8 +2295,7 @@ static int dt_path_get_mask(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *pie /** crop path to roi given by xmin, xmax, ymin, ymax. path segments outside of roi are replaced by nodes lying on roi borders. */ -static int _path_crop_to_roi(float *path, const int point_count, float xmin, float xmax, float ymin, - float ymax) +static int _path_crop_to_roi(float *path, const int point_count, float xmin, float xmax, float ymin, float ymax) { int point_start = -1; int l = -1, r = -1; @@ -2504,8 +2486,8 @@ static int dt_path_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t // we get buffers for all points float *points = NULL, *border = NULL, *cpoints = NULL; int points_count, border_count; - if(!_path_get_points_border(module->dev, form, module->priority, piece->pipe, &points, &points_count, - &border, &border_count, 0) || (points_count <= 2)) + if(!_path_get_points_border(module->dev, form, module->priority, piece->pipe, &points, &points_count, &border, + &border_count, 0) || (points_count <= 2)) { free(points); free(border); @@ -2637,8 +2619,7 @@ static int dt_path_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t } if(darktable.unmuted & DT_DEBUG_PERF) - dt_print(DT_DEBUG_MASKS, "[masks %s] path_fill min max took %0.04f sec\n", form->name, - dt_get_wtime() - start2); + dt_print(DT_DEBUG_MASKS, "[masks %s] path_fill min max took %0.04f sec\n", form->name, dt_get_wtime() - start2); start2 = dt_get_wtime(); // deal with path if it does not lie outside of roi @@ -2657,8 +2638,8 @@ static int dt_path_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t // now we clip cpoints to roi -> catch special case when roi lies completely within path. // dirty trick: we allow path to extend one pixel beyond height-1. this avoids need of special handling // of the last roi line in the following edge-flag polygon fill algorithm. - int crop_success = _path_crop_to_roi(cpoints + 2 * (nb_corner * 3), points_count - nb_corner * 3, 0, - width - 1, 0, height); + int crop_success + = _path_crop_to_roi(cpoints + 2 * (nb_corner * 3), points_count - nb_corner * 3, 0, width - 1, 0, height); path_encircles_roi = path_encircles_roi || !crop_success; if(darktable.unmuted & DT_DEBUG_PERF) @@ -2705,8 +2686,7 @@ static int dt_path_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t int xx = floorf(xcross); if((float)xx + 0.5f <= xcross) xx++; - if(xx < 0 || xx >= width || yy < 0 || yy >= height) - continue; // sanity check just to be on the safe side + if(xx < 0 || xx >= width || yy < 0 || yy >= height) continue; // sanity check just to be on the safe side size_t index = (size_t)yy * width + xx; @@ -2801,8 +2781,7 @@ static int dt_path_get_mask_roi(dt_iop_module_t *module, dt_dev_pixelpipe_iop_t free(border); if(darktable.unmuted & DT_DEBUG_PERF) - dt_print(DT_DEBUG_MASKS, "[masks %s] path fill buffer took %0.04f sec\n", form->name, - dt_get_wtime() - start); + dt_print(DT_DEBUG_MASKS, "[masks %s] path fill buffer took %0.04f sec\n", form->name, dt_get_wtime() - start); return 1; } diff --git a/src/develop/pixelpipe_cache.c b/src/develop/pixelpipe_cache.c index 7267c465d086..b91fc7bdb0a5 100644 --- a/src/develop/pixelpipe_cache.c +++ b/src/develop/pixelpipe_cache.c @@ -55,7 +55,8 @@ int dt_dev_pixelpipe_cache_init(dt_dev_pixelpipe_cache_t *cache, int entries, si #endif ASAN_POISON_MEMORY_REGION(cache->data[k], cache->size[k]); } - else cache->data[k] = 0; + else + cache->data[k] = 0; cache->hash[k] = -1; cache->used[k] = 0; } diff --git a/src/develop/pixelpipe_cache.h b/src/develop/pixelpipe_cache.h index 62689660b40e..afbcbfda72cb 100644 --- a/src/develop/pixelpipe_cache.h +++ b/src/develop/pixelpipe_cache.h @@ -53,8 +53,8 @@ int dt_dev_pixelpipe_cache_init(dt_dev_pixelpipe_cache_t *cache, int entries, si void dt_dev_pixelpipe_cache_cleanup(dt_dev_pixelpipe_cache_t *cache); /** creates a hopefully unique hash from the complete module stack up to the module-th. */ -uint64_t dt_dev_pixelpipe_cache_hash(int imgid, const struct dt_iop_roi_t *roi, - struct dt_dev_pixelpipe_t *pipe, int module); +uint64_t dt_dev_pixelpipe_cache_hash(int imgid, const struct dt_iop_roi_t *roi, struct dt_dev_pixelpipe_t *pipe, + int module); /** returns the float data buffer for the given hash from the cache. if the hash does not match any * cache line, the least recently used cache line will be cleared and an empty buffer is returned diff --git a/src/develop/pixelpipe_hb.c b/src/develop/pixelpipe_hb.c index 79fac32f3c2e..bdb3c7c8d01d 100644 --- a/src/develop/pixelpipe_hb.c +++ b/src/develop/pixelpipe_hb.c @@ -114,8 +114,7 @@ int dt_dev_pixelpipe_init_dummy(dt_dev_pixelpipe_t *pipe, int32_t width, int32_t int dt_dev_pixelpipe_init_preview(dt_dev_pixelpipe_t *pipe) { // don't know which buffer size we're going to need, set to 0 (will be alloced on demand) - int res = dt_dev_pixelpipe_init_cached( - pipe, 0, 5); + int res = dt_dev_pixelpipe_init_cached(pipe, 0, 5); pipe->type = DT_DEV_PIXELPIPE_PREVIEW; return res; } @@ -123,8 +122,7 @@ int dt_dev_pixelpipe_init_preview(dt_dev_pixelpipe_t *pipe) int dt_dev_pixelpipe_init(dt_dev_pixelpipe_t *pipe) { // don't know which buffer size we're going to need, set to 0 (will be alloced on demand) - int res = dt_dev_pixelpipe_init_cached( - pipe, 0, 5); + int res = dt_dev_pixelpipe_init_cached(pipe, 0, 5); pipe->type = DT_DEV_PIXELPIPE_FULL; return res; } @@ -236,8 +234,8 @@ void dt_dev_pixelpipe_create_nodes(dt_dev_pixelpipe_t *pipe, dt_develop_t *dev) piece->histogram_params.bins_count = 256; piece->histogram_stats.bins_count = 0; piece->histogram_stats.pixels = 0; - piece->colors - = ((dt_iop_module_colorspace(module) == iop_cs_RAW) && (pipe->image.flags & DT_IMAGE_RAW)) ? 1 : 4; + piece->colors = ((dt_iop_module_colorspace(module) == iop_cs_RAW) && (pipe->image.flags & DT_IMAGE_RAW)) ? 1 + : 4; piece->iscale = pipe->iscale; piece->iwidth = pipe->iwidth; piece->iheight = pipe->iheight; @@ -284,8 +282,8 @@ void dt_dev_pixelpipe_synch_all(dt_dev_pixelpipe_t *pipe, dt_develop_t *dev) dt_dev_pixelpipe_iop_t *piece = (dt_dev_pixelpipe_iop_t *)nodes->data; piece->hash = 0; piece->enabled = piece->module->default_enabled; - dt_iop_commit_params(piece->module, piece->module->default_params, piece->module->default_blendop_params, - pipe, piece); + dt_iop_commit_params(piece->module, piece->module->default_params, piece->module->default_blendop_params, pipe, + piece); nodes = g_list_next(nodes); } // go through all history items and adjust params @@ -387,9 +385,8 @@ static void histogram_collect(dt_dev_pixelpipe_iop_t *piece, const void *pixel, // // this algorithm is inefficient as hell when it comes to larger images. it's only acceptable // as long as we work on small image sizes like in image preview -static void histogram_collect_cl(int devid, dt_dev_pixelpipe_iop_t *piece, cl_mem img, - const dt_iop_roi_t *roi, uint32_t **histogram, uint32_t *histogram_max, - float *buffer, size_t bufsize) +static void histogram_collect_cl(int devid, dt_dev_pixelpipe_iop_t *piece, cl_mem img, const dt_iop_roi_t *roi, + uint32_t **histogram, uint32_t *histogram_max, float *buffer, size_t bufsize) { float *tmpbuf = NULL; float *pixel; @@ -561,7 +558,8 @@ static void pixelpipe_picker_cl(int devid, dt_iop_module_t *module, dt_iop_buffe if(err != CL_SUCCESS) goto error; - dt_iop_roi_t roi_copy = (dt_iop_roi_t){.x = roi->x + box[0], .y = roi->y + box[1], .width = region[0], .height = region[1] }; + dt_iop_roi_t roi_copy + = (dt_iop_roi_t){.x = roi->x + box[0], .y = roi->y + box[1], .width = region[0], .height = region[1] }; box[0] = 0; box[1] = 0; @@ -594,8 +592,7 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * module = (dt_iop_module_t *)modules->data; piece = (dt_dev_pixelpipe_iop_t *)pieces->data; // skip this module? - if(!piece->enabled - || (dev->gui_module && dev->gui_module->operation_tags_filter() & module->operation_tags())) + if(!piece->enabled || (dev->gui_module && dev->gui_module->operation_tags_filter() & module->operation_tags())) return dt_dev_pixelpipe_process_rec(pipe, dev, output, cl_mem_output, out_format, &roi_in, g_list_previous(modules), g_list_previous(pieces), pos - 1); } @@ -744,8 +741,8 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * dt_pthread_mutex_unlock(&pipe->busy_mutex); -// if(module) printf("reserving new buf in cache for module %s %s: %ld buf %p\n", module->op, pipe == -// dev->preview_pipe ? "[preview]" : "", hash, *output); + // if(module) printf("reserving new buf in cache for module %s %s: %ld buf %p\n", module->op, pipe == + // dev->preview_pipe ? "[preview]" : "", hash, *output); dt_pthread_mutex_lock(&pipe->busy_mutex); if(pipe->shutdown) @@ -762,8 +759,9 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * // special case: user requests to see channel data in the parametric mask of a module. In that case // we skip all modules manipulating pixel content and only process image distorting modules. Finally // "gamma" is responsible to display channel data accordingly. - if(strcmp(module->op, "gamma") && (pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_ANY) && !(module->operation_tags() & IOP_TAG_DISTORT) && - (in_bpp == out_bpp) && !memcmp(&roi_in, roi_out, sizeof(struct dt_iop_roi_t))) + if(strcmp(module->op, "gamma") && (pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_ANY) + && !(module->operation_tags() & IOP_TAG_DISTORT) && (in_bpp == out_bpp) + && !memcmp(&roi_in, roi_out, sizeof(struct dt_iop_roi_t))) { #ifdef HAVE_OPENCL if(dt_opencl_is_inited() && pipe->opencl_enabled && pipe->devid >= 0 && (cl_mem_input != NULL)) @@ -776,18 +774,16 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * #pragma omp parallel for schedule(static) default(none) shared(roi_out, roi_in, output, input) #endif for(int j = 0; j < roi_out->height; j++) - memcpy(((char *)*output) + (size_t)out_bpp * j * roi_out->width, - ((char *)input) + (size_t)in_bpp * j * roi_in.width, - (size_t)in_bpp * roi_in.width); + memcpy(((char *)*output) + (size_t)out_bpp * j * roi_out->width, + ((char *)input) + (size_t)in_bpp * j * roi_in.width, (size_t)in_bpp * roi_in.width); } #else // don't HAVE_OPENCL #ifdef _OPENMP #pragma omp parallel for schedule(static) default(none) shared(roi_out, roi_in, output, input) #endif for(int j = 0; j < roi_out->height; j++) - memcpy(((char *)*output) + (size_t)out_bpp * j * roi_out->width, - ((char *)input) + (size_t)in_bpp * j * roi_in.width, - (size_t)in_bpp * roi_in.width); + memcpy(((char *)*output) + (size_t)out_bpp * j * roi_out->width, + ((char *)input) + (size_t)in_bpp * j * roi_in.width, (size_t)in_bpp * roi_in.width); #endif dt_pthread_mutex_unlock(&pipe->busy_mutex); @@ -879,13 +875,12 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * if(success_opencl) { - cl_int err = dt_opencl_write_host_to_device(pipe->devid, input, cl_mem_input, - roi_in.width, roi_in.height, in_bpp); + cl_int err = dt_opencl_write_host_to_device(pipe->devid, input, cl_mem_input, roi_in.width, + roi_in.height, in_bpp); if(err != CL_SUCCESS) { dt_print(DT_DEBUG_OPENCL, - "[opencl_pixelpipe] couldn't copy image to opencl device for module %s\n", - module->op); + "[opencl_pixelpipe] couldn't copy image to opencl device for module %s\n", module->op); success_opencl = FALSE; } } @@ -955,8 +950,7 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * /* now call process_cl of module; module should emit meaningful messages in case of error */ if(success_opencl) { - success_opencl - = module->process_cl(module, piece, cl_mem_input, *cl_mem_output, &roi_in, roi_out); + success_opencl = module->process_cl(module, piece, cl_mem_input, *cl_mem_output, &roi_in, roi_out); pixelpipe_flow |= (PIXELPIPE_FLOW_PROCESSED_ON_GPU); pixelpipe_flow &= ~(PIXELPIPE_FLOW_PROCESSED_ON_CPU | PIXELPIPE_FLOW_PROCESSED_WITH_TILING); } @@ -1037,10 +1031,9 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * if(err != CL_SUCCESS) { /* late opencl error */ - dt_print( - DT_DEBUG_OPENCL, - "[opencl_pixelpipe (a)] late opencl error detected while copying back to cpu buffer: %d\n", - err); + dt_print(DT_DEBUG_OPENCL, + "[opencl_pixelpipe (a)] late opencl error detected while copying back to cpu buffer: %d\n", + err); dt_opencl_release_mem_object(cl_mem_input); pipe->opencl_error = 1; dt_pthread_mutex_unlock(&pipe->busy_mutex); @@ -1094,8 +1087,7 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * /* now call process_tiling_cl of module; module should emit meaningful messages in case of error */ if(success_opencl) { - success_opencl - = module->process_tiling_cl(module, piece, input, *output, &roi_in, roi_out, in_bpp); + success_opencl = module->process_tiling_cl(module, piece, input, *output, &roi_in, roi_out, in_bpp); pixelpipe_flow |= (PIXELPIPE_FLOW_PROCESSED_ON_GPU | PIXELPIPE_FLOW_PROCESSED_WITH_TILING); pixelpipe_flow &= ~(PIXELPIPE_FLOW_PROCESSED_ON_CPU); } @@ -1182,8 +1174,8 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * cl_int err; /* copy input to host memory, so we can find it in cache */ - err = dt_opencl_copy_device_to_host(pipe->devid, input, cl_mem_input, roi_in.width, - roi_in.height, in_bpp); + err = dt_opencl_copy_device_to_host(pipe->devid, input, cl_mem_input, roi_in.width, roi_in.height, + in_bpp); if(err != CL_SUCCESS) { /* late opencl error, not likely to happen here */ @@ -1219,8 +1211,8 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * else { /* Bad luck, opencl failed. Let's clean up and fall back to cpu module */ - dt_print(DT_DEBUG_OPENCL, "[opencl_pixelpipe] could not run module '%s' on gpu. falling back to cpu path\n", - module->op); + dt_print(DT_DEBUG_OPENCL, + "[opencl_pixelpipe] could not run module '%s' on gpu. falling back to cpu path\n", module->op); // fprintf(stderr, "[opencl_pixelpipe 4] module '%s' running on cpu\n", module->op); @@ -1244,10 +1236,9 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * if(err != CL_SUCCESS) { /* late opencl error */ - dt_print( - DT_DEBUG_OPENCL, - "[opencl_pixelpipe (b)] late opencl error detected while copying back to cpu buffer: %d\n", - err); + dt_print(DT_DEBUG_OPENCL, + "[opencl_pixelpipe (b)] late opencl error detected while copying back to cpu buffer: %d\n", + err); dt_opencl_release_mem_object(cl_mem_input); pipe->opencl_error = 1; dt_pthread_mutex_unlock(&pipe->busy_mutex); @@ -1377,10 +1368,9 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * if(err != CL_SUCCESS) { /* late opencl error */ - dt_print( - DT_DEBUG_OPENCL, - "[opencl_pixelpipe (c)] late opencl error detected while copying back to cpu buffer: %d\n", - err); + dt_print(DT_DEBUG_OPENCL, + "[opencl_pixelpipe (c)] late opencl error detected while copying back to cpu buffer: %d\n", + err); dt_opencl_release_mem_object(cl_mem_input); pipe->opencl_error = 1; dt_pthread_mutex_unlock(&pipe->busy_mutex); @@ -1531,8 +1521,8 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * /* process module on cpu. use tiling if needed and possible. */ if(piece->process_tiling_ready && !dt_tiling_piece_fits_host_memory(MAX(roi_in.width, roi_out->width), - MAX(roi_in.height, roi_out->height), MAX(in_bpp, bpp), - tiling.factor, tiling.overhead)) + MAX(roi_in.height, roi_out->height), MAX(in_bpp, bpp), tiling.factor, + tiling.overhead)) { module->process_tiling(module, piece, input, *output, &roi_in, roi_out, in_bpp); pixelpipe_flow |= (PIXELPIPE_FLOW_PROCESSED_ON_CPU | PIXELPIPE_FLOW_PROCESSED_WITH_TILING); @@ -1590,8 +1580,7 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * pixelpipe_flow |= (PIXELPIPE_FLOW_HISTOGRAM_ON_CPU); pixelpipe_flow &= ~(PIXELPIPE_FLOW_HISTOGRAM_NONE | PIXELPIPE_FLOW_HISTOGRAM_ON_GPU); - if(piece->histogram && (module->request_histogram & DT_REQUEST_ON) - && pipe->type == DT_DEV_PIXELPIPE_PREVIEW) + if(piece->histogram && (module->request_histogram & DT_REQUEST_ON) && pipe->type == DT_DEV_PIXELPIPE_PREVIEW) { const size_t buf_size = 4 * piece->histogram_stats.bins_count * sizeof(uint32_t); module->histogram = realloc(module->histogram, buf_size); @@ -1615,9 +1604,8 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * /* process module on cpu. use tiling if needed and possible. */ if(piece->process_tiling_ready - && !dt_tiling_piece_fits_host_memory(MAX(roi_in.width, roi_out->width), - MAX(roi_in.height, roi_out->height), MAX(in_bpp, bpp), - tiling.factor, tiling.overhead)) + && !dt_tiling_piece_fits_host_memory(MAX(roi_in.width, roi_out->width), MAX(roi_in.height, roi_out->height), + MAX(in_bpp, bpp), tiling.factor, tiling.overhead)) { module->process_tiling(module, piece, input, *output, &roi_in, roi_out, in_bpp); pixelpipe_flow |= (PIXELPIPE_FLOW_PROCESSED_ON_CPU | PIXELPIPE_FLOW_PROCESSED_WITH_TILING); @@ -1676,19 +1664,18 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * } gchar *module_label = dt_history_item_get_name(module); - dt_show_times( - &start, "[dev_pixelpipe]", "processed `%s' on %s%s%s, blended on %s [%s]", module_label, - pixelpipe_flow & PIXELPIPE_FLOW_PROCESSED_ON_GPU - ? "GPU" - : pixelpipe_flow & PIXELPIPE_FLOW_PROCESSED_ON_CPU ? "CPU" : "", - pixelpipe_flow & PIXELPIPE_FLOW_PROCESSED_WITH_TILING ? " with tiling" : "", - (!(pixelpipe_flow & PIXELPIPE_FLOW_HISTOGRAM_NONE) && (piece->request_histogram & DT_REQUEST_ON)) - ? histogram_log - : "", - pixelpipe_flow & PIXELPIPE_FLOW_BLENDED_ON_GPU - ? "GPU" - : pixelpipe_flow & PIXELPIPE_FLOW_BLENDED_ON_CPU ? "CPU" : "", - _pipe_type_to_str(pipe->type)); + dt_show_times(&start, "[dev_pixelpipe]", "processed `%s' on %s%s%s, blended on %s [%s]", module_label, + pixelpipe_flow & PIXELPIPE_FLOW_PROCESSED_ON_GPU + ? "GPU" + : pixelpipe_flow & PIXELPIPE_FLOW_PROCESSED_ON_CPU ? "CPU" : "", + pixelpipe_flow & PIXELPIPE_FLOW_PROCESSED_WITH_TILING ? " with tiling" : "", + (!(pixelpipe_flow & PIXELPIPE_FLOW_HISTOGRAM_NONE) && (piece->request_histogram & DT_REQUEST_ON)) + ? histogram_log + : "", + pixelpipe_flow & PIXELPIPE_FLOW_BLENDED_ON_GPU + ? "GPU" + : pixelpipe_flow & PIXELPIPE_FLOW_BLENDED_ON_CPU ? "CPU" : "", + _pipe_type_to_str(pipe->type)); g_free(module_label); module_label = NULL; @@ -1811,11 +1798,14 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * if(darktable.color_profiles->display_type == DT_COLORSPACE_DISPLAY) pthread_rwlock_rdlock(&darktable.color_profiles->xprofile_lock); - cmsHPROFILE out_profile = dt_colorspaces_get_profile(darktable.color_profiles->display_type, - darktable.color_profiles->display_filename, - DT_PROFILE_DIRECTION_OUT | DT_PROFILE_DIRECTION_DISPLAY)->profile; + cmsHPROFILE out_profile + = dt_colorspaces_get_profile(darktable.color_profiles->display_type, + darktable.color_profiles->display_filename, + DT_PROFILE_DIRECTION_OUT | DT_PROFILE_DIRECTION_DISPLAY)->profile; - cmsHTRANSFORM xform = out_profile ? cmsCreateTransform(out_profile, TYPE_RGB_FLT, Lab, TYPE_Lab_FLT, INTENT_PERCEPTUAL, 0) : NULL; + cmsHTRANSFORM xform + = out_profile ? cmsCreateTransform(out_profile, TYPE_RGB_FLT, Lab, TYPE_Lab_FLT, INTENT_PERCEPTUAL, 0) + : NULL; if(darktable.color_profiles->display_type == DT_COLORSPACE_DISPLAY) pthread_rwlock_unlock(&darktable.color_profiles->xprofile_lock); @@ -1838,10 +1828,8 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * int point[2]; float rgb[3]; for(int k = 0; k < 3; k++) rgb[k] = 0.0f; - for(int k = 0; k < 4; k += 2) - box[k] = MIN(roi_out->width - 1, MAX(0, sample->box[k] * roi_out->width)); - for(int k = 1; k < 4; k += 2) - box[k] = MIN(roi_out->height - 1, MAX(0, sample->box[k] * roi_out->height)); + for(int k = 0; k < 4; k += 2) box[k] = MIN(roi_out->width - 1, MAX(0, sample->box[k] * roi_out->width)); + for(int k = 1; k < 4; k += 2) box[k] = MIN(roi_out->height - 1, MAX(0, sample->box[k] * roi_out->height)); point[0] = MIN(roi_out->width - 1, MAX(0, sample->point[0] * roi_out->width)); point[1] = MIN(roi_out->height - 1, MAX(0, sample->point[1] * roi_out->height)); const float w = 1.0 / ((box[3] - box[1] + 1) * (box[2] - box[0] + 1)); @@ -1864,8 +1852,8 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * else { for(int i = 0; i < 3; i++) - sample->picked_color_rgb_mean[i] = sample->picked_color_rgb_min[i] - = sample->picked_color_rgb_max[i] = pixel[4 * (roi_out->width * point[1] + point[0]) + 2 - i]; + sample->picked_color_rgb_mean[i] = sample->picked_color_rgb_min[i] = sample->picked_color_rgb_max[i] + = pixel[4 * (roi_out->width * point[1] + point[0]) + 2 - i]; } // Converting the RGB values to Lab @@ -1948,15 +1936,17 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * if(darktable.color_profiles->display_type == DT_COLORSPACE_DISPLAY) pthread_rwlock_rdlock(&darktable.color_profiles->xprofile_lock); - cmsHPROFILE out_profile = dt_colorspaces_get_profile(darktable.color_profiles->display_type, - darktable.color_profiles->display_filename, - DT_PROFILE_DIRECTION_OUT | DT_PROFILE_DIRECTION_DISPLAY)->profile; + cmsHPROFILE out_profile + = dt_colorspaces_get_profile(darktable.color_profiles->display_type, + darktable.color_profiles->display_filename, + DT_PROFILE_DIRECTION_OUT | DT_PROFILE_DIRECTION_DISPLAY)->profile; if(out_profile) { cmsHPROFILE Lab = dt_colorspaces_get_profile(DT_COLORSPACE_LAB, "", DT_PROFILE_DIRECTION_ANY)->profile; - cmsHTRANSFORM xform = cmsCreateTransform(out_profile, TYPE_RGB_FLT, Lab, TYPE_Lab_FLT, INTENT_PERCEPTUAL, 0); + cmsHTRANSFORM xform + = cmsCreateTransform(out_profile, TYPE_RGB_FLT, Lab, TYPE_Lab_FLT, INTENT_PERCEPTUAL, 0); // Preparing the data for transformation @@ -2000,8 +1990,7 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * dt_pthread_mutex_unlock(&pipe->busy_mutex); return 1; } - if(dev->gui_attached && !dev->gui_leaving && pipe == dev->preview_pipe - && (strcmp(module->op, "gamma") == 0)) + if(dev->gui_attached && !dev->gui_leaving && pipe == dev->preview_pipe && (strcmp(module->op, "gamma") == 0)) { float box[4]; // Constraining the area if the colorpicker is active in area mode @@ -2012,20 +2001,19 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * if(darktable.lib->proxy.colorpicker.size == DT_COLORPICKER_SIZE_BOX) { for(int k = 0; k < 4; k += 2) - box[k] = MIN(roi_out->width - 1, - MAX(0, dev->gui_module->color_picker_box[k] * (roi_out->width - 1))); + box[k] = MIN(roi_out->width - 1, MAX(0, dev->gui_module->color_picker_box[k] * (roi_out->width - 1))); for(int k = 1; k < 4; k += 2) - box[k] = MIN(roi_out->height - 1, - MAX(0, dev->gui_module->color_picker_box[k] * (roi_out->height - 1))); + box[k] + = MIN(roi_out->height - 1, MAX(0, dev->gui_module->color_picker_box[k] * (roi_out->height - 1))); } else { for(int k = 0; k < 4; k += 2) - box[k] = MIN(roi_out->width - 1, - MAX(0, dev->gui_module->color_picker_point[0] * (roi_out->width - 1))); + box[k] + = MIN(roi_out->width - 1, MAX(0, dev->gui_module->color_picker_point[0] * (roi_out->width - 1))); for(int k = 1; k < 4; k += 2) - box[k] = MIN(roi_out->height - 1, - MAX(0, dev->gui_module->color_picker_point[1] * (roi_out->height - 1))); + box[k] + = MIN(roi_out->height - 1, MAX(0, dev->gui_module->color_picker_point[1] * (roi_out->height - 1))); } } else @@ -2084,8 +2072,7 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * const int out_x = MIN(x / bin_width, dev->histogram_waveform_width - 1); for(int k = 0; k < 3; k++) { - const float v = isnan(rgb[k]) ? 0.0f - : rgb[k]; // catch NaNs as they don't convert well to integers + const float v = isnan(rgb[k]) ? 0.0f : rgb[k]; // catch NaNs as they don't convert well to integers const int out_y = CLAMP(1.0 - (8.0 / 9.0) * v, 0.0, 1.0) * _height; uint32_t *const out = buf + (out_y * dev->histogram_waveform_width * 3 + out_x * 3 + k); (*out)++; @@ -2103,15 +2090,14 @@ static int dt_dev_pixelpipe_process_rec(dt_dev_pixelpipe_t *pipe, dt_develop_t * // ... and scale that into a nice image. putting the pixels into the image directly gets too // saturated/clips. // new scale factor to do about the same as the old one for 1MP views, but scale to hidpi - const float scale = 0.5 * 1e6f/(roi_in.height*roi_in.width) * - (dev->histogram_waveform_width*dev->histogram_waveform_height) / (350.0f*233.); + const float scale = 0.5 * 1e6f / (roi_in.height * roi_in.width) + * (dev->histogram_waveform_width * dev->histogram_waveform_height) / (350.0f * 233.); for(int y = 0; y < dev->histogram_waveform_height; y++) { for(int x = 0; x < dev->histogram_waveform_width; x++) { uint32_t *const in = buf + (y * dev->histogram_waveform_width + x) * 3; - uint8_t *const out - = (uint8_t *)(dev->histogram_waveform + (y * dev->histogram_waveform_width + x)); + uint8_t *const out = (uint8_t *)(dev->histogram_waveform + (y * dev->histogram_waveform_width + x)); for(int k = 0; k < 3; k++) { if(in[k] == 0) continue; @@ -2226,8 +2212,7 @@ static int dt_dev_pixelpipe_process_rec_and_backcopy(dt_dev_pixelpipe_t *pipe, d { /* this indicates a opencl problem earlier in the pipeline */ dt_print(DT_DEBUG_OPENCL, - "[opencl_pixelpipe (d)] late opencl error detected while copying back to cpu buffer: %d\n", - err); + "[opencl_pixelpipe (d)] late opencl error detected while copying back to cpu buffer: %d\n", err); pipe->opencl_error = 1; ret = 1; } @@ -2247,8 +2232,7 @@ int dt_dev_pixelpipe_process(dt_dev_pixelpipe_t *pipe, dt_develop_t *dev, int x, { pipe->processing = 1; pipe->opencl_enabled = dt_opencl_update_settings(); // update enabled flag and profile from preferences - pipe->devid = (pipe->opencl_enabled) ? dt_opencl_lock_device(pipe->type) - : -1; // try to get/lock opencl resource + pipe->devid = (pipe->opencl_enabled) ? dt_opencl_lock_device(pipe->type) : -1; // try to get/lock opencl resource dt_print(DT_DEBUG_OPENCL, "[pixelpipe_process] [%s] using device %d\n", _pipe_type_to_str(pipe->type), pipe->devid); @@ -2323,8 +2307,7 @@ int dt_dev_pixelpipe_process(dt_dev_pixelpipe_t *pipe, dt_develop_t *dev, int x, dt_dev_pixelpipe_flush_caches(pipe); dt_dev_pixelpipe_change(pipe, dev); - dt_print(DT_DEBUG_OPENCL, "[pixelpipe_process] [%s] falling back to cpu path\n", - _pipe_type_to_str(pipe->type)); + dt_print(DT_DEBUG_OPENCL, "[pixelpipe_process] [%s] falling back to cpu path\n", _pipe_type_to_str(pipe->type)); goto restart; // try again (this time without opencl) } @@ -2375,8 +2358,7 @@ void dt_dev_pixelpipe_get_dimensions(dt_dev_pixelpipe_t *pipe, struct dt_develop piece->buf_in = roi_in; // skip this module? - if(piece->enabled - && !(dev->gui_module && dev->gui_module->operation_tags_filter() & module->operation_tags())) + if(piece->enabled && !(dev->gui_module && dev->gui_module->operation_tags_filter() & module->operation_tags())) { module->modify_roi_out(module, piece, &roi_out, &roi_in); } diff --git a/src/develop/pixelpipe_hb.h b/src/develop/pixelpipe_hb.h index 94658ceac19c..f129dd6a832b 100644 --- a/src/develop/pixelpipe_hb.h +++ b/src/develop/pixelpipe_hb.h @@ -38,7 +38,7 @@ typedef struct dt_dev_pixelpipe_iop_t struct dt_dev_pixelpipe_t *pipe; // the pipe this piece belongs to void *data; // to be used by the module to store stuff per pipe piece void *blendop_data; // to be used by the module to store blendop per pipe piece - int enabled; // used to disable parts of the pipe for export, independent on module itself. + int enabled; // used to disable parts of the pipe for export, independent on module itself. dt_dev_request_flags_t request_histogram; // (bitwise) set if you want an histogram captured dt_dev_histogram_collection_params_t histogram_params; // set histogram generation params @@ -46,15 +46,14 @@ typedef struct dt_dev_pixelpipe_iop_t dt_dev_histogram_stats_t histogram_stats; // stats of captured histogram uint32_t histogram_max[4]; // maximum levels in histogram, one per channel - float iscale; // input actually just downscaled buffer? iscale*iwidth = actual width - int iwidth, iheight; // width and height of input buffer - uint64_t hash; // hash of params and enabled. - int bpc; // bits per channel, 32 means float - int colors; // how many colors per pixel - dt_iop_roi_t buf_in, - buf_out; // theoretical full buffer regions of interest, as passed through modify_roi_out - int process_cl_ready; // set this to 0 in commit_params to temporarily disable the use of process_cl - int process_tiling_ready; // set this to 0 in commit_params to temporarily disable tiling + float iscale; // input actually just downscaled buffer? iscale*iwidth = actual width + int iwidth, iheight; // width and height of input buffer + uint64_t hash; // hash of params and enabled. + int bpc; // bits per channel, 32 means float + int colors; // how many colors per pixel + dt_iop_roi_t buf_in, buf_out; // theoretical full buffer regions of interest, as passed through modify_roi_out + int process_cl_ready; // set this to 0 in commit_params to temporarily disable the use of process_cl + int process_tiling_ready; // set this to 0 in commit_params to temporarily disable tiling // the following are used internally for caching: dt_iop_buffer_dsc_t dsc_in, dsc_out; @@ -181,8 +180,8 @@ void dt_dev_pixelpipe_synch_top(dt_dev_pixelpipe_t *pipe, struct dt_develop_t *d int dt_dev_pixelpipe_process(dt_dev_pixelpipe_t *pipe, struct dt_develop_t *dev, int x, int y, int width, int height, float scale); // convenience method that does not gamma-compress the image. -int dt_dev_pixelpipe_process_no_gamma(dt_dev_pixelpipe_t *pipe, struct dt_develop_t *dev, int x, int y, - int width, int height, float scale); +int dt_dev_pixelpipe_process_no_gamma(dt_dev_pixelpipe_t *pipe, struct dt_develop_t *dev, int x, int y, int width, + int height, float scale); // disable given op and all that comes after it in the pipe: void dt_dev_pixelpipe_disable_after(dt_dev_pixelpipe_t *pipe, const char *op); diff --git a/src/develop/tiling.c b/src/develop/tiling.c index 4125cd3f4fd8..968c8b3bce5c 100644 --- a/src/develop/tiling.c +++ b/src/develop/tiling.c @@ -174,8 +174,8 @@ static double _nm_fitness(double x[], void *rest[]) #define BETA 0.5 /* contraction coefficient */ #define GAMMA 2.0 /* expansion coefficient */ -static int _simplex(double (*objfunc)(double[], void *[]), double start[], int n, double EPSILON, - double scale, int maxiter, void (*constrain)(double[], int n), void *rest[]) +static int _simplex(double (*objfunc)(double[], void *[]), double start[], int n, double EPSILON, double scale, + int maxiter, void (*constrain)(double[], int n), void *rest[]) { int vs; /* vertex with smallest value */ @@ -614,7 +614,7 @@ static void _default_process_tiling_ptp(struct dt_iop_module_t *self, struct dt_ assert(available >= 500.0f * 1024.0f * 1024.0f); /* correct for size of ivoid and ovoid which are needed on top of tiling */ available = fmax(available - ((float)roi_out->width * roi_out->height * out_bpp) - - ((float)roi_in->width * roi_in->height * in_bpp) - tiling.overhead, + - ((float)roi_in->width * roi_in->height * in_bpp) - tiling.overhead, 0); /* we ignore the above value if singlebuffer_limit (is defined and) is higher than available/tiling.factor. @@ -672,8 +672,7 @@ static void _default_process_tiling_ptp(struct dt_iop_module_t *self, struct dt_ if(height < roi_in->height) height = (height / xyalign) * xyalign; /* also make sure that overlap follows alignment rules by making it wider when needed */ - const int overlap = tiling.overlap % xyalign != 0 ? (tiling.overlap / xyalign + 1) * xyalign - : tiling.overlap; + const int overlap = tiling.overlap % xyalign != 0 ? (tiling.overlap / xyalign + 1) * xyalign : tiling.overlap; /* calculate effective tile size */ const int tile_wd = width - 2 * overlap > 0 ? width - 2 * overlap : 1; @@ -687,25 +686,24 @@ static void _default_process_tiling_ptp(struct dt_iop_module_t *self, struct dt_ if(tiles_x * tiles_y > dt_conf_get_int("maximum_number_tiles")) { dt_print(DT_DEBUG_DEV, - "[default_process_tiling_ptp] gave up tiling for module '%s'. too many tiles: %d x %d\n", - self->op, tiles_x, tiles_y); + "[default_process_tiling_ptp] gave up tiling for module '%s'. too many tiles: %d x %d\n", self->op, + tiles_x, tiles_y); goto error; } dt_print(DT_DEBUG_DEV, - "[default_process_tiling_ptp] use tiling on module '%s' for image with full size %d x %d\n", - self->op, roi_in->width, roi_in->height); + "[default_process_tiling_ptp] use tiling on module '%s' for image with full size %d x %d\n", self->op, + roi_in->width, roi_in->height); dt_print(DT_DEBUG_DEV, - "[default_process_tiling_ptp] (%d x %d) tiles with max dimensions %d x %d and overlap %d\n", - tiles_x, tiles_y, width, height, overlap); + "[default_process_tiling_ptp] (%d x %d) tiles with max dimensions %d x %d and overlap %d\n", tiles_x, + tiles_y, width, height, overlap); /* reserve input and output buffers for tiles */ input = dt_alloc_align(64, (size_t)width * height * in_bpp); if(input == NULL) { - dt_print(DT_DEBUG_DEV, "[default_process_tiling_ptp] could not alloc input buffer for module '%s'\n", - self->op); + dt_print(DT_DEBUG_DEV, "[default_process_tiling_ptp] could not alloc input buffer for module '%s'\n", self->op); goto error; } output = dt_alloc_align(64, (size_t)width * height * out_bpp); @@ -769,10 +767,9 @@ static void _default_process_tiling_ptp(struct dt_iop_module_t *self, struct dt_ for(int k = 0; k < 4; k++) { if(tx + ty > 0 && fabs(processed_maximum_new[k] - piece->pipe->dsc.processed_maximum[k]) > 1.0e-6f) - dt_print( - DT_DEBUG_DEV, - "[default_process_tiling_ptp] processed_maximum[%d] differs between tiles in module '%s'\n", k, - self->op); + dt_print(DT_DEBUG_DEV, + "[default_process_tiling_ptp] processed_maximum[%d] differs between tiles in module '%s'\n", k, + self->op); processed_maximum_new[k] = piece->pipe->dsc.processed_maximum[k]; } @@ -796,8 +793,8 @@ static void _default_process_tiling_ptp(struct dt_iop_module_t *self, struct dt_ #pragma omp parallel for default(none) shared(ooffs, output, width, origin, region, wd) schedule(static) #endif for(size_t j = 0; j < region[1]; j++) - memcpy((char *)ovoid + ooffs + j * opitch, - (char *)output + ((j + origin[1]) * wd + origin[0]) * out_bpp, (size_t)region[0] * out_bpp); + memcpy((char *)ovoid + ooffs + j * opitch, (char *)output + ((j + origin[1]) * wd + origin[0]) * out_bpp, + (size_t)region[0] * out_bpp); } /* copy back final processed_maximum */ @@ -873,7 +870,7 @@ static void _default_process_tiling_roi(struct dt_iop_module_t *self, struct dt_ assert(available >= 500.0f * 1024.0f * 1024.0f); /* correct for size of ivoid and ovoid which are needed on top of tiling */ available = fmax(available - ((float)roi_out->width * roi_out->height * out_bpp) - - ((float)roi_in->width * roi_in->height * in_bpp) - tiling.overhead, + - ((float)roi_in->width * roi_in->height * in_bpp) - tiling.overhead, 0); /* we ignore the above value if singlebuffer_limit (is defined and) is higher than available/tiling.factor. @@ -935,28 +932,25 @@ static void _default_process_tiling_roi(struct dt_iop_module_t *self, struct dt_ /* calculate number of tiles taking the larger buffer (input or output) as a guiding one. normally it is roi_in > roi_out; but let's be prepared */ if(roi_in->width > roi_out->width) - tiles_x = width < roi_in->width - ? ceilf((float)roi_in->width / (float)_max(width - 2 * overlap_in - inacc, 1)) - : 1; + tiles_x = width < roi_in->width ? ceilf((float)roi_in->width / (float)_max(width - 2 * overlap_in - inacc, 1)) + : 1; else - tiles_x = width < roi_out->width ? ceilf((float)roi_out->width / (float)_max(width - 2 * overlap_out, 1)) - : 1; + tiles_x = width < roi_out->width ? ceilf((float)roi_out->width / (float)_max(width - 2 * overlap_out, 1)) : 1; if(roi_in->height > roi_out->height) tiles_y = height < roi_in->height ? ceilf((float)roi_in->height / (float)_max(height - 2 * overlap_in - inacc, 1)) : 1; else - tiles_y = height < roi_out->height - ? ceilf((float)roi_out->height / (float)_max(height - 2 * overlap_out, 1)) - : 1; + tiles_y = height < roi_out->height ? ceilf((float)roi_out->height / (float)_max(height - 2 * overlap_out, 1)) + : 1; /* sanity check: don't run wild on too many tiles */ if(tiles_x * tiles_y > dt_conf_get_int("maximum_number_tiles")) { dt_print(DT_DEBUG_DEV, - "[default_process_tiling_roi] gave up tiling for module '%s'. too many tiles: %d x %d\n", - self->op, tiles_x, tiles_y); + "[default_process_tiling_roi] gave up tiling for module '%s'. too many tiles: %d x %d\n", self->op, + tiles_x, tiles_y); goto error; } @@ -971,8 +965,8 @@ static void _default_process_tiling_roi(struct dt_iop_module_t *self, struct dt_ dt_print(DT_DEBUG_DEV, "[default_process_tiling_roi] use tiling on module '%s' for image with full input size %d x %d\n", self->op, roi_in->width, roi_in->height); - dt_print(DT_DEBUG_DEV, "[default_process_tiling_roi] (%d x %d) tiles with max dimensions %d x %d\n", - tiles_x, tiles_y, width, height); + dt_print(DT_DEBUG_DEV, "[default_process_tiling_roi] (%d x %d) tiles with max dimensions %d x %d\n", tiles_x, + tiles_y, width, height); /* store processed_maximum to be re-used and aggregated */ @@ -993,8 +987,7 @@ static void _default_process_tiling_roi(struct dt_iop_module_t *self, struct dt_ /* roi_in and roi_out of good part: oroi_good easy to calculate based on number and dimension of tile. iroi_good is calculated by modify_roi_in() of respective module */ dt_iop_roi_t iroi_good = { roi_in->x + tx * tile_wd, roi_in->y + ty * tile_ht, wd, ht, roi_in->scale }; - dt_iop_roi_t oroi_good - = { roi_out->x + tx * tile_wd, roi_out->y + ty * tile_ht, wd, ht, roi_out->scale }; + dt_iop_roi_t oroi_good = { roi_out->x + tx * tile_wd, roi_out->y + ty * tile_ht, wd, ht, roi_out->scale }; self->modify_roi_in(self, piece, &oroi_good, &iroi_good); @@ -1070,11 +1063,10 @@ static void _default_process_tiling_roi(struct dt_iop_module_t *self, struct dt_ /* offsets of tile into ivoid and ovoid */ size_t ioffs = ((size_t)iroi_full.y - roi_in->y) * ipitch + ((size_t)iroi_full.x - roi_in->x) * in_bpp; - size_t ooffs = ((size_t)oroi_good.y - roi_out->y) * opitch - + ((size_t)oroi_good.x - roi_out->x) * out_bpp; + size_t ooffs = ((size_t)oroi_good.y - roi_out->y) * opitch + ((size_t)oroi_good.x - roi_out->x) * out_bpp; - dt_print(DT_DEBUG_DEV, "[default_process_tiling_roi] tile (%zu, %zu) with %d x %d at origin [%d, %d]\n", - tx, ty, iroi_full.width, iroi_full.height, iroi_full.x, iroi_full.y); + dt_print(DT_DEBUG_DEV, "[default_process_tiling_roi] tile (%zu, %zu) with %d x %d at origin [%d, %d]\n", tx, + ty, iroi_full.width, iroi_full.height, iroi_full.x, iroi_full.y); /* prepare input tile buffer */ @@ -1112,10 +1104,9 @@ static void _default_process_tiling_roi(struct dt_iop_module_t *self, struct dt_ for(int k = 0; k < 4; k++) { if(tx + ty > 0 && fabs(processed_maximum_new[k] - piece->pipe->dsc.processed_maximum[k]) > 1.0e-6f) - dt_print( - DT_DEBUG_DEV, - "[default_process_tiling_roi] processed_maximum[%d] differs between tiles in module '%s'\n", k, - self->op); + dt_print(DT_DEBUG_DEV, + "[default_process_tiling_roi] processed_maximum[%d] differs between tiles in module '%s'\n", k, + self->op); processed_maximum_new[k] = piece->pipe->dsc.processed_maximum[k]; } @@ -1211,9 +1202,8 @@ static int _default_process_tiling_cl_ptp(struct dt_iop_module_t *self, struct d // which seemingly get allocated not only on // host but also on device (why???) const float pinned_buffer_slack - = use_pinned_memory - ? 0.85f - : 1.0f; // avoid problems when pinned buffer size gets too close to max_mem_alloc size + = use_pinned_memory ? 0.85f + : 1.0f; // avoid problems when pinned buffer size gets too close to max_mem_alloc size /* calculate optimal size of tiles */ float headroom = dt_conf_get_float("opencl_memory_headroom") * 1024.0f * 1024.0f; @@ -1275,8 +1265,7 @@ static int _default_process_tiling_cl_ptp(struct dt_iop_module_t *self, struct d if(height < roi_in->height) height = (height / halign) * halign; /* also make sure that overlap follows alignment rules by making it wider when needed */ - const int overlap = tiling.overlap % xyalign != 0 ? (tiling.overlap / xyalign + 1) * xyalign - : tiling.overlap; + const int overlap = tiling.overlap % xyalign != 0 ? (tiling.overlap / xyalign + 1) * xyalign : tiling.overlap; /* calculate effective tile size */ @@ -1292,8 +1281,8 @@ static int _default_process_tiling_cl_ptp(struct dt_iop_module_t *self, struct d if(tiles_x * tiles_y > dt_conf_get_int("maximum_number_tiles")) { dt_print(DT_DEBUG_OPENCL, - "[default_process_tiling_cl_ptp] aborted tiling for module '%s'. too many tiles: %d x %d\n", - self->op, tiles_x, tiles_y); + "[default_process_tiling_cl_ptp] aborted tiling for module '%s'. too many tiles: %d x %d\n", self->op, + tiles_x, tiles_y); return FALSE; } @@ -1302,8 +1291,8 @@ static int _default_process_tiling_cl_ptp(struct dt_iop_module_t *self, struct d "[default_process_tiling_cl_ptp] use tiling on module '%s' for image with full size %d x %d\n", self->op, roi_in->width, roi_in->height); dt_print(DT_DEBUG_OPENCL, - "[default_process_tiling_cl_ptp] (%d x %d) tiles with max dimensions %d x %d and overlap %d\n", - tiles_x, tiles_y, width, height, overlap); + "[default_process_tiling_cl_ptp] (%d x %d) tiles with max dimensions %d x %d and overlap %d\n", tiles_x, + tiles_y, width, height, overlap); /* store processed_maximum to be re-used and aggregated */ float processed_maximum_saved[4]; @@ -1318,8 +1307,7 @@ static int _default_process_tiling_cl_ptp(struct dt_iop_module_t *self, struct d if(pinned_input == NULL) { dt_print(DT_DEBUG_OPENCL, - "[default_process_tiling_cl_ptp] could not alloc pinned input buffer for module '%s'\n", - self->op); + "[default_process_tiling_cl_ptp] could not alloc pinned input buffer for module '%s'\n", self->op); use_pinned_memory = 0; } } @@ -1327,8 +1315,8 @@ static int _default_process_tiling_cl_ptp(struct dt_iop_module_t *self, struct d if(use_pinned_memory) { - input_buffer = dt_opencl_map_buffer(devid, pinned_input, CL_TRUE, CL_MAP_WRITE, 0, - (size_t)width * height * in_bpp); + input_buffer + = dt_opencl_map_buffer(devid, pinned_input, CL_TRUE, CL_MAP_WRITE, 0, (size_t)width * height * in_bpp); if(input_buffer == NULL) { dt_print(DT_DEBUG_OPENCL, "[default_process_tiling_cl_ptp] could not map pinned input buffer to host " @@ -1346,8 +1334,7 @@ static int _default_process_tiling_cl_ptp(struct dt_iop_module_t *self, struct d if(pinned_output == NULL) { dt_print(DT_DEBUG_OPENCL, - "[default_process_tiling_cl_ptp] could not alloc pinned output buffer for module '%s'\n", - self->op); + "[default_process_tiling_cl_ptp] could not alloc pinned output buffer for module '%s'\n", self->op); use_pinned_memory = 0; } } @@ -1355,8 +1342,8 @@ static int _default_process_tiling_cl_ptp(struct dt_iop_module_t *self, struct d if(use_pinned_memory) { - output_buffer = dt_opencl_map_buffer(devid, pinned_output, CL_TRUE, CL_MAP_READ, 0, - (size_t)width * height * out_bpp); + output_buffer + = dt_opencl_map_buffer(devid, pinned_output, CL_TRUE, CL_MAP_READ, 0, (size_t)width * height * out_bpp); if(output_buffer == NULL) { dt_print(DT_DEBUG_OPENCL, "[default_process_tiling_cl_ptp] could not map pinned output buffer to host " @@ -1409,12 +1396,11 @@ static int _default_process_tiling_cl_ptp(struct dt_iop_module_t *self, struct d #pragma omp parallel for default(none) shared(input_buffer, width, ioffs, wd, ht) schedule(static) #endif for(size_t j = 0; j < ht; j++) - memcpy((char *)input_buffer + j * wd * in_bpp, (char *)ivoid + ioffs + j * ipitch, - (size_t)wd * in_bpp); + memcpy((char *)input_buffer + j * wd * in_bpp, (char *)ivoid + ioffs + j * ipitch, (size_t)wd * in_bpp); /* blocking memory transfer: pinned host input buffer -> opencl/device tile */ - err = dt_opencl_write_host_to_device_raw(devid, (char *)input_buffer, input, origin, region, - wd * in_bpp, CL_TRUE); + err = dt_opencl_write_host_to_device_raw(devid, (char *)input_buffer, input, origin, region, wd * in_bpp, + CL_TRUE); if(err != CL_SUCCESS) goto error; } else @@ -1437,10 +1423,9 @@ static int _default_process_tiling_cl_ptp(struct dt_iop_module_t *self, struct d for(int k = 0; k < 4; k++) { if(tx + ty > 0 && fabs(processed_maximum_new[k] - piece->pipe->dsc.processed_maximum[k]) > 1.0e-6f) - dt_print( - DT_DEBUG_OPENCL, - "[default_process_tiling_cl_ptp] processed_maximum[%d] differs between tiles in module '%s'\n", - k, self->op); + dt_print(DT_DEBUG_OPENCL, + "[default_process_tiling_cl_ptp] processed_maximum[%d] differs between tiles in module '%s'\n", + k, self->op); processed_maximum_new[k] = piece->pipe->dsc.processed_maximum[k]; } @@ -1471,7 +1456,7 @@ static int _default_process_tiling_cl_ptp(struct dt_iop_module_t *self, struct d { /* copy "good" part of tile from pinned output buffer to output image */ #if 0 // def _OPENMP -#pragma omp parallel for default(none) shared(ovoid, ooffs, output_buffer, width, origin, region, \ +#pragma omp parallel for default(none) shared(ovoid, ooffs, output_buffer, width, origin, region, \ wd) schedule(static) #endif for(size_t j = 0; j < region[1]; j++) @@ -1482,8 +1467,8 @@ static int _default_process_tiling_cl_ptp(struct dt_iop_module_t *self, struct d else { /* blocking direct memory transfer: good part of opencl/device tile -> host output image */ - err = dt_opencl_read_host_from_device_raw(devid, (char *)ovoid + ooffs, output, origin, region, - opitch, CL_TRUE); + err = dt_opencl_read_host_from_device_raw(devid, (char *)ovoid + ooffs, output, origin, region, opitch, + CL_TRUE); if(err != CL_SUCCESS) goto error; } @@ -1520,10 +1505,9 @@ static int _default_process_tiling_cl_ptp(struct dt_iop_module_t *self, struct d dt_opencl_release_mem_object(input); dt_opencl_release_mem_object(output); piece->pipe->tiling = 0; - dt_print( - DT_DEBUG_OPENCL, - "[default_process_tiling_opencl_ptp] couldn't run process_cl() for module '%s' in tiling mode: %d\n", - self->op, err); + dt_print(DT_DEBUG_OPENCL, + "[default_process_tiling_opencl_ptp] couldn't run process_cl() for module '%s' in tiling mode: %d\n", + self->op, err); return FALSE; } @@ -1575,9 +1559,8 @@ static int _default_process_tiling_cl_roi(struct dt_iop_module_t *self, struct d // which seemingly get allocated not only on // host but also on device (why???) const float pinned_buffer_slack - = use_pinned_memory - ? 0.85f - : 1.0f; // avoid problems when pinned buffer size gets too close to max_mem_alloc size + = use_pinned_memory ? 0.85f + : 1.0f; // avoid problems when pinned buffer size gets too close to max_mem_alloc size /* calculate optimal size of tiles */ float headroom = dt_conf_get_float("opencl_memory_headroom") * 1024.0f * 1024.0f; @@ -1639,28 +1622,25 @@ static int _default_process_tiling_cl_roi(struct dt_iop_module_t *self, struct d /* calculate number of tiles taking the larger buffer (input or output) as a guiding one. normally it is roi_in > roi_out; but let's be prepared */ if(roi_in->width > roi_out->width) - tiles_x = width < roi_in->width - ? ceilf((float)roi_in->width / (float)_max(width - 2 * overlap_in - inacc, 1)) - : 1; + tiles_x = width < roi_in->width ? ceilf((float)roi_in->width / (float)_max(width - 2 * overlap_in - inacc, 1)) + : 1; else - tiles_x = width < roi_out->width ? ceilf((float)roi_out->width / (float)_max(width - 2 * overlap_out, 1)) - : 1; + tiles_x = width < roi_out->width ? ceilf((float)roi_out->width / (float)_max(width - 2 * overlap_out, 1)) : 1; if(roi_in->height > roi_out->height) tiles_y = height < roi_in->height ? ceilf((float)roi_in->height / (float)_max(height - 2 * overlap_in - inacc, 1)) : 1; else - tiles_y = height < roi_out->height - ? ceilf((float)roi_out->height / (float)_max(height - 2 * overlap_out, 1)) - : 1; + tiles_y = height < roi_out->height ? ceilf((float)roi_out->height / (float)_max(height - 2 * overlap_out, 1)) + : 1; /* sanity check: don't run wild on too many tiles */ if(tiles_x * tiles_y > dt_conf_get_int("maximum_number_tiles")) { dt_print(DT_DEBUG_OPENCL, - "[default_process_tiling_cl_roi] aborted tiling for module '%s'. too many tiles: %d x %d\n", - self->op, tiles_x, tiles_y); + "[default_process_tiling_cl_roi] aborted tiling for module '%s'. too many tiles: %d x %d\n", self->op, + tiles_x, tiles_y); return FALSE; } @@ -1672,13 +1652,11 @@ static int _default_process_tiling_cl_roi(struct dt_iop_module_t *self, struct d roi_out->height % tiles_y == 0 ? roi_out->height / tiles_y : roi_out->height / tiles_y + 1, xyalign); - dt_print( - DT_DEBUG_OPENCL, - "[default_process_tiling_cl_roi] use tiling on module '%s' for image with full input size %d x %d\n", - self->op, roi_in->width, roi_in->height); dt_print(DT_DEBUG_OPENCL, - "[default_process_tiling_cl_roi] (%d x %d) tiles with max input dimensions %d x %d\n", tiles_x, - tiles_y, width, height); + "[default_process_tiling_cl_roi] use tiling on module '%s' for image with full input size %d x %d\n", + self->op, roi_in->width, roi_in->height); + dt_print(DT_DEBUG_OPENCL, "[default_process_tiling_cl_roi] (%d x %d) tiles with max input dimensions %d x %d\n", + tiles_x, tiles_y, width, height); /* store processed_maximum to be re-used and aggregated */ @@ -1694,8 +1672,7 @@ static int _default_process_tiling_cl_roi(struct dt_iop_module_t *self, struct d if(pinned_input == NULL) { dt_print(DT_DEBUG_OPENCL, - "[default_process_tiling_cl_roi] could not alloc pinned input buffer for module '%s'\n", - self->op); + "[default_process_tiling_cl_roi] could not alloc pinned input buffer for module '%s'\n", self->op); use_pinned_memory = 0; } } @@ -1703,8 +1680,8 @@ static int _default_process_tiling_cl_roi(struct dt_iop_module_t *self, struct d if(use_pinned_memory) { - input_buffer = dt_opencl_map_buffer(devid, pinned_input, CL_TRUE, CL_MAP_WRITE, 0, - (size_t)width * height * in_bpp); + input_buffer + = dt_opencl_map_buffer(devid, pinned_input, CL_TRUE, CL_MAP_WRITE, 0, (size_t)width * height * in_bpp); if(input_buffer == NULL) { dt_print(DT_DEBUG_OPENCL, "[default_process_tiling_cl_roi] could not map pinned input buffer to host " @@ -1722,8 +1699,7 @@ static int _default_process_tiling_cl_roi(struct dt_iop_module_t *self, struct d if(pinned_output == NULL) { dt_print(DT_DEBUG_OPENCL, - "[default_process_tiling_cl_roi] could not alloc pinned output buffer for module '%s'\n", - self->op); + "[default_process_tiling_cl_roi] could not alloc pinned output buffer for module '%s'\n", self->op); use_pinned_memory = 0; } } @@ -1731,8 +1707,8 @@ static int _default_process_tiling_cl_roi(struct dt_iop_module_t *self, struct d if(use_pinned_memory) { - output_buffer = dt_opencl_map_buffer(devid, pinned_output, CL_TRUE, CL_MAP_READ, 0, - (size_t)width * height * out_bpp); + output_buffer + = dt_opencl_map_buffer(devid, pinned_output, CL_TRUE, CL_MAP_READ, 0, (size_t)width * height * out_bpp); if(output_buffer == NULL) { dt_print(DT_DEBUG_OPENCL, "[default_process_tiling_cl_roi] could not map pinned output buffer to host " @@ -1756,8 +1732,7 @@ static int _default_process_tiling_cl_roi(struct dt_iop_module_t *self, struct d /* roi_in and roi_out of good part: oroi_good easy to calculate based on number and dimension of tile. iroi_good is calculated by modify_roi_in() of respective module */ dt_iop_roi_t iroi_good = { roi_in->x + tx * tile_wd, roi_in->y + ty * tile_ht, wd, ht, roi_in->scale }; - dt_iop_roi_t oroi_good - = { roi_out->x + tx * tile_wd, roi_out->y + ty * tile_ht, wd, ht, roi_out->scale }; + dt_iop_roi_t oroi_good = { roi_out->x + tx * tile_wd, roi_out->y + ty * tile_ht, wd, ht, roi_out->scale }; self->modify_roi_in(self, piece, &oroi_good, &iroi_good); @@ -1831,8 +1806,7 @@ static int _default_process_tiling_cl_roi(struct dt_iop_module_t *self, struct d /* offsets of tile into ivoid and ovoid */ size_t ioffs = ((size_t)iroi_full.y - roi_in->y) * ipitch + ((size_t)iroi_full.x - roi_in->x) * in_bpp; - size_t ooffs = ((size_t)oroi_good.y - roi_out->y) * opitch - + ((size_t)oroi_good.x - roi_out->x) * out_bpp; + size_t ooffs = ((size_t)oroi_good.y - roi_out->y) * opitch + ((size_t)oroi_good.x - roi_out->x) * out_bpp; dt_print(DT_DEBUG_OPENCL, "[default_process_tiling_cl_roi] tile (%zu, %zu) with %d x %d at origin [%d, %d]\n", tx, ty, @@ -1875,8 +1849,8 @@ static int _default_process_tiling_cl_roi(struct dt_iop_module_t *self, struct d else { /* blocking direct memory transfer: host input image -> opencl/device tile */ - err = dt_opencl_write_host_to_device_raw(devid, (char *)ivoid + ioffs, input, iorigin, iregion, - ipitch, CL_TRUE); + err = dt_opencl_write_host_to_device_raw(devid, (char *)ivoid + ioffs, input, iorigin, iregion, ipitch, + CL_TRUE); if(err != CL_SUCCESS) goto error; } @@ -1892,10 +1866,9 @@ static int _default_process_tiling_cl_roi(struct dt_iop_module_t *self, struct d for(int k = 0; k < 4; k++) { if(tx + ty > 0 && fabs(processed_maximum_new[k] - piece->pipe->dsc.processed_maximum[k]) > 1.0e-6f) - dt_print( - DT_DEBUG_OPENCL, - "[default_process_tiling_cl_roi] processed_maximum[%d] differs between tiles in module '%s'\n", - k, self->op); + dt_print(DT_DEBUG_OPENCL, + "[default_process_tiling_cl_roi] processed_maximum[%d] differs between tiles in module '%s'\n", + k, self->op); processed_maximum_new[k] = piece->pipe->dsc.processed_maximum[k]; } @@ -1908,8 +1881,7 @@ static int _default_process_tiling_cl_roi(struct dt_iop_module_t *self, struct d /* copy "good" part of tile from pinned output buffer to output image */ #ifdef _OPENMP -#pragma omp parallel for default(none) shared(ooffs, output_buffer, oroi_full, oorigin, \ - oregion) schedule(static) +#pragma omp parallel for default(none) shared(ooffs, output_buffer, oroi_full, oorigin, oregion) schedule(static) #endif for(size_t j = 0; j < oregion[1]; j++) memcpy((char *)ovoid + ooffs + j * opitch, @@ -1919,8 +1891,8 @@ static int _default_process_tiling_cl_roi(struct dt_iop_module_t *self, struct d else { /* blocking direct memory transfer: good part of opencl/device tile -> host output image */ - err = dt_opencl_read_host_from_device_raw(devid, (char *)ovoid + ooffs, output, oorigin, oregion, - opitch, CL_TRUE); + err = dt_opencl_read_host_from_device_raw(devid, (char *)ovoid + ooffs, output, oorigin, oregion, opitch, + CL_TRUE); if(err != CL_SUCCESS) goto error; } @@ -1956,10 +1928,9 @@ static int _default_process_tiling_cl_roi(struct dt_iop_module_t *self, struct d dt_opencl_release_mem_object(input); dt_opencl_release_mem_object(output); piece->pipe->tiling = 0; - dt_print( - DT_DEBUG_OPENCL, - "[default_process_tiling_opencl_roi] couldn't run process_cl() for module '%s' in tiling mode: %d\n", - self->op, err); + dt_print(DT_DEBUG_OPENCL, + "[default_process_tiling_opencl_roi] couldn't run process_cl() for module '%s' in tiling mode: %d\n", + self->op, err); return FALSE; } @@ -2019,8 +1990,8 @@ void default_tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpi { _get_iop_priorities(self); - const float ioratio - = ((float)roi_out->width * (float)roi_out->height) / ((float)roi_in->width * (float)roi_in->height); + const float ioratio = ((float)roi_out->width * (float)roi_out->height) + / ((float)roi_in->width * (float)roi_in->height); tiling->factor = 1.0f + ioratio; tiling->maxbuf = 1.0f; diff --git a/src/develop/tiling.h b/src/develop/tiling.h index df6c8178a94b..55ba80661178 100644 --- a/src/develop/tiling.h +++ b/src/develop/tiling.h @@ -43,17 +43,17 @@ int default_process_tiling_cl(struct dt_iop_module_t *self, struct dt_dev_pixelp const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, const int bpp); -int process_tiling_cl(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, - const dt_iop_roi_t *const roi_out, const int bpp); +int process_tiling_cl(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, + void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, + const int bpp); void default_process_tiling(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, const int bpp); -void process_tiling(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, - const dt_iop_roi_t *const roi_out, const int bpp); +void process_tiling(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, + void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, + const int bpp); void default_tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, @@ -64,8 +64,7 @@ void tiling_callback_blendop(struct dt_iop_module_t *self, struct dt_dev_pixelpi struct dt_develop_tiling_t *tiling); void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling); + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling); int dt_tiling_piece_fits_host_memory(const size_t width, const size_t height, const unsigned bpp, const float factor, const size_t overhead); diff --git a/src/dtgtk/button.c b/src/dtgtk/button.c index 1e30d71b0cd3..523fb2f8bc20 100644 --- a/src/dtgtk/button.c +++ b/src/dtgtk/button.c @@ -90,8 +90,7 @@ static gboolean _button_draw(GtkWidget *widget, cairo_t *cr) { /* draw default boxed button */ gtk_render_background(context, cr, 0, 0, width, height); - if(!(flags & CPF_DO_NOT_USE_BORDER)) - gtk_render_frame(context, cr, 0, 0, width, height); + if(!(flags & CPF_DO_NOT_USE_BORDER)) gtk_render_frame(context, cr, 0, 0, width, height); } gdk_cairo_set_source_rgba(cr, &fg_color); @@ -105,11 +104,9 @@ static gboolean _button_draw(GtkWidget *widget, cairo_t *cr) if(icon_width > 0 && icon_height > 0) { if(text) - DTGTK_BUTTON(widget) - ->icon(cr, border, border, height - (border * 2), height - (border * 2), flags); + DTGTK_BUTTON(widget)->icon(cr, border, border, height - (border * 2), height - (border * 2), flags); else - DTGTK_BUTTON(widget) - ->icon(cr, border, border, width - (border * 2), height - (border * 2), flags); + DTGTK_BUTTON(widget)->icon(cr, border, border, width - (border * 2), height - (border * 2), flags); } } diff --git a/src/dtgtk/button.h b/src/dtgtk/button.h index 1118b6cd22c6..bd6d8494b306 100644 --- a/src/dtgtk/button.h +++ b/src/dtgtk/button.h @@ -22,8 +22,7 @@ #include <gtk/gtk.h> G_BEGIN_DECLS #define DTGTK_BUTTON(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, dtgtk_button_get_type(), GtkDarktableButton) -#define DTGTK_BUTTON_CLASS(klass) \ - G_TYPE_CHECK_CLASS_CAST(klass, dtgtk_button_get_type(), GtkDarktableButtonClass) +#define DTGTK_BUTTON_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, dtgtk_button_get_type(), GtkDarktableButtonClass) #define DTGTK_IS_BUTTON(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, dtgtk_button_get_type()) #define DTGTK_IS_BUTTON_CLASS(klass) G_TYPE_CHECK_CLASS_TYPE(obj, dtgtk_button_get_type()) diff --git a/src/dtgtk/drawingarea.c b/src/dtgtk/drawingarea.c index 923d5989003e..99512167e1e3 100644 --- a/src/dtgtk/drawingarea.c +++ b/src/dtgtk/drawingarea.c @@ -25,8 +25,8 @@ static GtkSizeRequestMode dtgtk_drawing_area_get_request_mode(GtkWidget *widget) return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH; }; -static void dtgtk_drawing_area_get_preferred_height_for_width(GtkWidget *widget, gint for_width, - gint *min_height, gint *nat_height) +static void dtgtk_drawing_area_get_preferred_height_for_width(GtkWidget *widget, gint for_width, gint *min_height, + gint *nat_height) { GtkDarktableDrawingArea *da = DTGTK_DRAWING_AREA(widget); diff --git a/src/dtgtk/drawingarea.h b/src/dtgtk/drawingarea.h index da9108802899..d112c2e6c562 100644 --- a/src/dtgtk/drawingarea.h +++ b/src/dtgtk/drawingarea.h @@ -24,13 +24,13 @@ G_BEGIN_DECLS #define DTGTK_TYPE_DRAWING_AREA (dtgtk_drawing_area_get_type()) -#define DTGTK_DRAWING_AREA(obj) \ +#define DTGTK_DRAWING_AREA(obj) \ (G_TYPE_CHECK_INSTANCE_CAST((obj), DTGTK_TYPE_DRAWING_AREA, GtkDarktableDrawingArea)) #define DTGTK_IS_DRAWING_AREA(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), DTGTK_TYPE_DRAWING_AREA)) -#define DTGTK_DRAWING_AREA_CLASS(klass) \ +#define DTGTK_DRAWING_AREA_CLASS(klass) \ (G_TYPE_CHECK_CLASS_CAST((klass), DTGTK_TYPE_DRAWING_AREA, GtkDarktableDrawingAreaClass)) #define DTGTK_IS_DRAWING_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), DTGTK_TYPE_DRAWING_AREA)) -#define DTGTK_DRAWING_AREA_GET_CLASS(obj) \ +#define DTGTK_DRAWING_AREA_GET_CLASS(obj) \ (G_TYPE_INSTANCE_GET_CLASS((obj), DTGTK_TYPE_DRAWING_AREA, GtkDarktableDrawingAreaClass)) typedef struct _GtkDarktableDrawingArea diff --git a/src/dtgtk/expander.c b/src/dtgtk/expander.c index 926687ca1049..09ca4356d9f6 100644 --- a/src/dtgtk/expander.c +++ b/src/dtgtk/expander.c @@ -104,8 +104,7 @@ GtkWidget *dtgtk_expander_new(GtkWidget *header, GtkWidget *body) g_return_val_if_fail(GTK_IS_WIDGET(header), NULL); g_return_val_if_fail(GTK_IS_WIDGET(body), NULL); - expander - = g_object_new(dtgtk_expander_get_type(), "orientation", GTK_ORIENTATION_VERTICAL, "spacing", 3, NULL); + expander = g_object_new(dtgtk_expander_get_type(), "orientation", GTK_ORIENTATION_VERTICAL, "spacing", 3, NULL); expander->expanded = -1; expander->header = header; expander->body = body; diff --git a/src/dtgtk/expander.h b/src/dtgtk/expander.h index 07f18ff4d7b9..ca5e2a4825c9 100644 --- a/src/dtgtk/expander.h +++ b/src/dtgtk/expander.h @@ -26,10 +26,10 @@ G_BEGIN_DECLS #define DTGTK_TYPE_EXPANDER (dtgtk_expander_get_type()) #define DTGTK_EXPANDER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), DTGTK_TYPE_EXPANDER, GtkDarktableExpander)) #define DTGTK_IS_EXPANDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), DTGTK_TYPE_EXPANDER)) -#define DTGTK_EXPANDER_CLASS(klass) \ +#define DTGTK_EXPANDER_CLASS(klass) \ (G_TYPE_CHECK_CLASS_CAST((klass), DTGTK_TYPE_EXPANDER, GtkDarktableExpanderClass)) #define DTGTK_IS_EXPANDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), DTGTK_TYPE_EXPANDER)) -#define DTGTK_EXPANDER_GET_CLASS(obj) \ +#define DTGTK_EXPANDER_GET_CLASS(obj) \ (G_TYPE_INSTANCE_GET_CLASS((obj), DTGTK_TYPE_EXPANDER, GtkDarktableExpanderClass)) typedef struct _GtkDarktableExpander diff --git a/src/dtgtk/gradientslider.c b/src/dtgtk/gradientslider.c index 1c118222787b..ac81f0358ab9 100644 --- a/src/dtgtk/gradientslider.c +++ b/src/dtgtk/gradientslider.c @@ -158,8 +158,7 @@ static gboolean _gradient_slider_button_press(GtkWidget *widget, GdkEventButton else if((event->button == 1 || event->button == 3) && event->type == GDK_BUTTON_PRESS) { gint lselected = -1; - gdouble newposition = roundf(_screen_to_scale(widget, event->x) / gslider->increment) - * gslider->increment; + gdouble newposition = roundf(_screen_to_scale(widget, event->x) / gslider->increment) * gslider->increment; gslider->prev_x_root = event->x_root; assert(gslider->positions > 0); @@ -201,15 +200,14 @@ static gboolean _gradient_slider_button_press(GtkWidget *widget, GdkEventButton _slider_move(widget, gslider->selected, newposition, direction); gslider->min = gslider->selected == 0 ? 0.0f : gslider->position[gslider->selected - 1]; - gslider->max = gslider->selected == gslider->positions - 1 ? 1.0f - : gslider->position[gslider->selected + 1]; + gslider->max = gslider->selected == gslider->positions - 1 ? 1.0f : gslider->position[gslider->selected + 1]; gslider->is_changed = TRUE; gslider->is_dragging = TRUE; // timeout_handle should always be zero here, but check just in case - int delay = CLAMP_RANGE(darktable.develop->average_delay * 3 / 2, - DTGTK_GRADIENT_SLIDER_VALUE_CHANGED_DELAY_MIN, - DTGTK_GRADIENT_SLIDER_VALUE_CHANGED_DELAY_MAX); + int delay + = CLAMP_RANGE(darktable.develop->average_delay * 3 / 2, DTGTK_GRADIENT_SLIDER_VALUE_CHANGED_DELAY_MIN, + DTGTK_GRADIENT_SLIDER_VALUE_CHANGED_DELAY_MAX); if(!gslider->timeout_handle) gslider->timeout_handle = g_timeout_add(delay, _gradient_slider_postponed_value_change, widget); } @@ -244,8 +242,7 @@ static gboolean _gradient_slider_motion_notify(GtkWidget *widget, GdkEventMotion { assert(gslider->timeout_handle > 0); - gdouble newposition = roundf(_screen_to_scale(widget, event->x) / gslider->increment) - * gslider->increment; + gdouble newposition = roundf(_screen_to_scale(widget, event->x) / gslider->increment) * gslider->increment; newposition = CLAMP_RANGE(newposition, 0.0, 1.0); @@ -253,8 +250,7 @@ static gboolean _gradient_slider_motion_notify(GtkWidget *widget, GdkEventMotion _slider_move(widget, gslider->selected, newposition, direction); gslider->min = gslider->selected == 0 ? 0.0f : gslider->position[gslider->selected - 1]; - gslider->max = gslider->selected == gslider->positions - 1 ? 1.0f - : gslider->position[gslider->selected + 1]; + gslider->max = gslider->selected == gslider->positions - 1 ? 1.0f : gslider->position[gslider->selected + 1]; gslider->is_changed = TRUE; @@ -273,8 +269,7 @@ static gboolean _gradient_slider_button_release(GtkWidget *widget, GdkEventButto { // First get some dimension info gslider->is_changed = TRUE; - gdouble newposition = roundf(_screen_to_scale(widget, event->x) / gslider->increment) - * gslider->increment; + gdouble newposition = roundf(_screen_to_scale(widget, event->x) / gslider->increment) * gslider->increment; newposition = CLAMP_RANGE(newposition, 0.0, 1.0); @@ -282,8 +277,7 @@ static gboolean _gradient_slider_button_release(GtkWidget *widget, GdkEventButto _slider_move(widget, gslider->selected, newposition, direction); gslider->min = gslider->selected == 0 ? 0.0f : gslider->position[gslider->selected - 1]; - gslider->max = gslider->selected == gslider->positions - 1 ? 1.0f - : gslider->position[gslider->selected + 1]; + gslider->max = gslider->selected == gslider->positions - 1 ? 1.0f : gslider->position[gslider->selected + 1]; gtk_widget_queue_draw(widget); gslider->prev_x_root = event->x_root; @@ -388,8 +382,8 @@ static void _gradient_slider_class_init(GtkDarktableGradientSliderClass *klass) widget_class->scroll_event = _gradient_slider_scroll_event; widget_class->key_press_event = _gradient_slider_key_press_event; - _signals[VALUE_CHANGED] = g_signal_new("value-changed", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, 0, - NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + _signals[VALUE_CHANGED] = g_signal_new("value-changed", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, 0, NULL, + NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); } static void _gradient_slider_init(GtkDarktableGradientSlider *slider) @@ -420,14 +414,13 @@ static void _gradient_slider_realize(GtkWidget *widget) attributes.wclass = GDK_INPUT_OUTPUT; attributes.event_mask = gtk_widget_get_events(widget) | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK - | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_POINTER_MOTION_MASK - | GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK; + | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_SCROLL_MASK + | GDK_SMOOTH_SCROLL_MASK; attributes_mask = GDK_WA_X | GDK_WA_Y; gtk_widget_set_can_focus(GTK_WIDGET(widget), TRUE); - gtk_widget_set_window(widget, - gdk_window_new(gtk_widget_get_parent_window(widget), &attributes, attributes_mask)); + gtk_widget_set_window(widget, gdk_window_new(gtk_widget_get_parent_window(widget), &attributes, attributes_mask)); gdk_window_set_user_data(gtk_widget_get_window(widget), widget); } @@ -439,8 +432,7 @@ static void _gradient_slider_destroy(GtkWidget *widget) g_return_if_fail(widget != NULL); g_return_if_fail(DTGTK_IS_GRADIENT_SLIDER(widget)); - if(DTGTK_GRADIENT_SLIDER(widget)->timeout_handle) - g_source_remove(DTGTK_GRADIENT_SLIDER(widget)->timeout_handle); + if(DTGTK_GRADIENT_SLIDER(widget)->timeout_handle) g_source_remove(DTGTK_GRADIENT_SLIDER(widget)->timeout_handle); DTGTK_GRADIENT_SLIDER(widget)->timeout_handle = 0; if(DTGTK_GRADIENT_SLIDER(widget)->colors) @@ -570,8 +562,7 @@ static gboolean _gradient_slider_draw(GtkWidget *widget, cairo_t *cr) { if(mk & 0x01) /* filled */ dtgtk_cairo_paint_solid_triangle(cr, (vx - DT_PIXEL_APPLY_DPI(sz) * 0.5), - sz < 10 ? height - DT_PIXEL_APPLY_DPI(6) : height - - DT_PIXEL_APPLY_DPI(11), + sz < 10 ? height - DT_PIXEL_APPLY_DPI(6) : height - DT_PIXEL_APPLY_DPI(11), DT_PIXEL_APPLY_DPI(sz), DT_PIXEL_APPLY_DPI(sz), CPF_DIRECTION_UP); else dtgtk_cairo_paint_triangle(cr, (vx - DT_PIXEL_APPLY_DPI(sz) * 0.5), @@ -649,8 +640,7 @@ gint _list_find_by_position(gconstpointer a, gconstpointer b) return (gint)((stop->position * 100.0) - (position * 100.0)); } -void dtgtk_gradient_slider_multivalue_set_stop(GtkDarktableGradientSlider *gslider, gfloat position, - GdkRGBA color) +void dtgtk_gradient_slider_multivalue_set_stop(GtkDarktableGradientSlider *gslider, gfloat position, GdkRGBA color) { // First find color at position, if exists update color, otherwise create a new stop at position. GList *current = g_list_find_custom(gslider->colors, (gpointer)&position, _list_find_by_position); @@ -686,8 +676,8 @@ GType dtgtk_gradient_slider_multivalue_get_type() sizeof(GtkDarktableGradientSlider), 0, /* n_preallocs */ (GInstanceInitFunc)_gradient_slider_init, }; - dtgtk_gradient_slider_type = g_type_register_static(GTK_TYPE_WIDGET, "GtkDarktableGradientSlider", - &dtgtk_gradient_slider_info, 0); + dtgtk_gradient_slider_type + = g_type_register_static(GTK_TYPE_WIDGET, "GtkDarktableGradientSlider", &dtgtk_gradient_slider_info, 0); } return dtgtk_gradient_slider_type; } @@ -731,8 +721,7 @@ void dtgtk_gradient_slider_multivalue_set_markers(GtkDarktableGradientSlider *gs gtk_widget_queue_draw(GTK_WIDGET(gslider)); } -void dtgtk_gradient_slider_multivalue_set_resetvalue(GtkDarktableGradientSlider *gslider, gdouble value, - gint pos) +void dtgtk_gradient_slider_multivalue_set_resetvalue(GtkDarktableGradientSlider *gslider, gdouble value, gint pos) { assert(pos <= gslider->positions); @@ -829,8 +818,8 @@ void dtgtk_gradient_slider_set_picker(GtkDarktableGradientSlider *gslider, gdoub gtk_widget_queue_draw(GTK_WIDGET(gslider)); } -void dtgtk_gradient_slider_set_picker_meanminmax(GtkDarktableGradientSlider *gslider, gdouble mean, - gdouble min, gdouble max) +void dtgtk_gradient_slider_set_picker_meanminmax(GtkDarktableGradientSlider *gslider, gdouble mean, gdouble min, + gdouble max) { gslider->picker[0] = mean; gslider->picker[1] = min; diff --git a/src/dtgtk/gradientslider.h b/src/dtgtk/gradientslider.h index 1433d76d7d53..6f49ffb4345b 100644 --- a/src/dtgtk/gradientslider.h +++ b/src/dtgtk/gradientslider.h @@ -24,19 +24,19 @@ #include "paint.h" #include <gtk/gtk.h> G_BEGIN_DECLS -#define DTGTK_GRADIENT_SLIDER(obj) \ +#define DTGTK_GRADIENT_SLIDER(obj) \ G_TYPE_CHECK_INSTANCE_CAST(obj, dtgtk_gradient_slider_get_type(), GtkDarktableGradientSlider) -#define DTGTK_GRADIENT_SLIDER_CLASS(klass) \ +#define DTGTK_GRADIENT_SLIDER_CLASS(klass) \ G_TYPE_CHECK_CLASS_CAST(klass, dtgtk_gradient_slider_get_type(), GtkDarktableGradientSliderClass) #define DTGTK_IS_GRADIENT_SLIDER(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, dtgtk_gradient_slider_get_type()) #define DTGTK_IS_GRADIENT_SLIDER_CLASS(klass) G_TYPE_CHECK_CLASS_TYPE(obj, dtgtk_gradient_slider_get_type()) -#define DTGTK_GRADIENT_SLIDER_MULTIVALUE(obj) \ +#define DTGTK_GRADIENT_SLIDER_MULTIVALUE(obj) \ G_TYPE_CHECK_INSTANCE_CAST(obj, dtgtk_gradient_slider_multivalue_get_type(), GtkDarktableGradientSlider) -#define DTGTK_GRADIENT_SLIDER_MULTIVALUE_CLASS(klass) \ +#define DTGTK_GRADIENT_SLIDER_MULTIVALUE_CLASS(klass) \ G_TYPE_CHECK_CLASS_CAST(klass, dtgtk_gradient_slider_multivalue_get_type(), GtkDarktableGradientSliderClass) -#define DTGTK_IS_GRADIENT_SLIDER_MULTIVALUE(obj) \ +#define DTGTK_IS_GRADIENT_SLIDER_MULTIVALUE(obj) \ G_TYPE_CHECK_INSTANCE_TYPE(obj, dtgtk_gradient_slider_multivalue_get_type()) -#define DTGTK_IS_GRADIENT_SLIDER_MULTIVALUE_CLASS(klass) \ +#define DTGTK_IS_GRADIENT_SLIDER_MULTIVALUE_CLASS(klass) \ G_TYPE_CHECK_CLASS_TYPE(obj, dtgtk_gradient_slider_multivalue_get_type()) enum @@ -139,8 +139,8 @@ void dtgtk_gradient_slider_set_resetvalue(GtkDarktableGradientSlider *gslider, g /** Set a picker */ void dtgtk_gradient_slider_set_picker(GtkDarktableGradientSlider *gslider, gdouble value); -void dtgtk_gradient_slider_set_picker_meanminmax(GtkDarktableGradientSlider *gslider, gdouble mean, - gdouble min, gdouble max); +void dtgtk_gradient_slider_set_picker_meanminmax(GtkDarktableGradientSlider *gslider, gdouble mean, gdouble min, + gdouble max); /** Set left/right margins */ void dtgtk_gradient_slider_set_margins(GtkDarktableGradientSlider *gslider, gint value); @@ -154,14 +154,12 @@ GtkWidget *dtgtk_gradient_slider_multivalue_new(gint positions); GtkWidget *dtgtk_gradient_slider_multivalue_new_with_color(GdkRGBA start, GdkRGBA end, gint positions); /** Set a color at specified stop for multivalue control */ -void dtgtk_gradient_slider_multivalue_set_stop(GtkDarktableGradientSlider *gslider, gfloat position, - GdkRGBA color); +void dtgtk_gradient_slider_multivalue_set_stop(GtkDarktableGradientSlider *gslider, gfloat position, GdkRGBA color); /** Get the slider value 0 - 1.0 for multivalue control */ gdouble dtgtk_gradient_slider_multivalue_get_value(GtkDarktableGradientSlider *gslider, gint position); void dtgtk_gradient_slider_multivalue_get_values(GtkDarktableGradientSlider *gslider, gdouble *values); -void dtgtk_gradient_slider_multivalue_set_value(GtkDarktableGradientSlider *gslider, gdouble value, - gint position); +void dtgtk_gradient_slider_multivalue_set_value(GtkDarktableGradientSlider *gslider, gdouble value, gint position); void dtgtk_gradient_slider_multivalue_set_values(GtkDarktableGradientSlider *gslider, gdouble *values); gboolean dtgtk_gradient_slider_multivalue_is_dragging(GtkDarktableGradientSlider *gslider); @@ -170,8 +168,7 @@ void dtgtk_gradient_slider_multivalue_set_marker(GtkDarktableGradientSlider *gsl void dtgtk_gradient_slider_multivalue_set_markers(GtkDarktableGradientSlider *gslider, gint *markers); /** Set the slider reset values for multivalue control */ -void dtgtk_gradient_slider_multivalue_set_resetvalue(GtkDarktableGradientSlider *gslider, gdouble value, - gint pos); +void dtgtk_gradient_slider_multivalue_set_resetvalue(GtkDarktableGradientSlider *gslider, gdouble value, gint pos); void dtgtk_gradient_slider_multivalue_set_resetvalues(GtkDarktableGradientSlider *gslider, gdouble *values); /** Set a picker for multivalue control */ diff --git a/src/dtgtk/paint.h b/src/dtgtk/paint.h index 9fdedd2c50ca..f9c860f4a5b4 100644 --- a/src/dtgtk/paint.h +++ b/src/dtgtk/paint.h @@ -32,14 +32,14 @@ typedef enum dtgtk_cairo_paint_flags_t CPF_DIRECTION_RIGHT = 1 << 3, CPF_ACTIVE = 1 << 4, CPF_PRELIGHT = 1 << 5, - CPF_IGNORE_FG_STATE = 1 << 6, // Ignore state when setting foregroundcolor + CPF_IGNORE_FG_STATE = 1 << 6, // Ignore state when setting foregroundcolor CPF_BG_TRANSPARENT = 1 << 7, // transparent background CPF_STYLE_FLAT = 1 << 8, // flat style widget CPF_STYLE_BOX = 1 << 9, // boxed style widget CPF_DO_NOT_USE_BORDER = 1 << 10, // do not paint inner border CPF_CUSTOM_BG = 1 << 11, CPF_CUSTOM_FG = 1 << 12, - CPF_SPECIAL_FLAG = 1 << 13 // this needs to be the last one. also update shift in dtgtk_cairo_paint_alignment + CPF_SPECIAL_FLAG = 1 << 13 // this needs to be the last one. also update shift in dtgtk_cairo_paint_alignment } dtgtk_cairo_paint_flags_t; diff --git a/src/dtgtk/resetlabel.h b/src/dtgtk/resetlabel.h index ac5c9e7e3a94..4473794494aa 100644 --- a/src/dtgtk/resetlabel.h +++ b/src/dtgtk/resetlabel.h @@ -22,9 +22,9 @@ #include <gtk/gtk.h> G_BEGIN_DECLS -#define DTGTK_RESET_LABEL(obj) \ +#define DTGTK_RESET_LABEL(obj) \ G_TYPE_CHECK_INSTANCE_CAST(obj, dtgtk_reset_label_get_type(), GtkDarktableResetLabel) -#define DTGTK_RESET_LABEL_CLASS(klass) \ +#define DTGTK_RESET_LABEL_CLASS(klass) \ G_TYPE_CHECK_CLASS_CAST(klass, dtgtk_reset_label_get_type(), GtkDarktableButtonClass) #define DTGTK_IS_RESET_LABEL(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, dtgtk_reset_label_get_type()) #define DTGTK_IS_RESET_LABEL_CLASS(klass) G_TYPE_CHECK_CLASS_TYPE(obj, dtgtk_reset_label_get_type()) diff --git a/src/dtgtk/sidepanel.h b/src/dtgtk/sidepanel.h index 90128c83b5f7..a16cdcd48017 100644 --- a/src/dtgtk/sidepanel.h +++ b/src/dtgtk/sidepanel.h @@ -24,13 +24,12 @@ G_BEGIN_DECLS #define DTGTK_TYPE_SIDE_PANEL (dtgtk_side_panel_get_type()) -#define DTGTK_SIDE_PANEL(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), DTGTK_TYPE_SIDE_PANEL, GtkDarktableSidePanel)) +#define DTGTK_SIDE_PANEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), DTGTK_TYPE_SIDE_PANEL, GtkDarktableSidePanel)) #define DTGTK_IS_SIDE_PANEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), DTGTK_TYPE_SIDE_PANEL)) -#define DTGTK_SIDE_PANEL_CLASS(klass) \ +#define DTGTK_SIDE_PANEL_CLASS(klass) \ (G_TYPE_CHECK_CLASS_CAST((klass), DTGTK_TYPE_SIDE_PANEL, GtkDarktableSidePanelClass)) #define DTGTK_IS_SIDE_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), DTGTK_TYPE_SIDE_PANEL)) -#define DTGTK_SIDE_PANEL_GET_CLASS(obj) \ +#define DTGTK_SIDE_PANEL_GET_CLASS(obj) \ (G_TYPE_INSTANCE_GET_CLASS((obj), DTGTK_TYPE_SIDE_PANEL, GtkDarktableSidePanelClass)) typedef struct _GtkDarktableSidePanel diff --git a/src/dtgtk/togglebutton.c b/src/dtgtk/togglebutton.c index c326110d07a4..5b2206bb560d 100644 --- a/src/dtgtk/togglebutton.c +++ b/src/dtgtk/togglebutton.c @@ -100,8 +100,7 @@ static gboolean _togglebutton_draw(GtkWidget *widget, cairo_t *cr) { /* draw default boxed button */ gtk_render_background(context, cr, 0, 0, width, height); - if(!(flags & CPF_DO_NOT_USE_BORDER)) - gtk_render_frame(context, cr, 0, 0, width, height); + if(!(flags & CPF_DO_NOT_USE_BORDER)) gtk_render_frame(context, cr, 0, 0, width, height); } @@ -132,11 +131,9 @@ static gboolean _togglebutton_draw(GtkWidget *widget, cairo_t *cr) if(icon_width > 0 && icon_height > 0) { if(text) - DTGTK_TOGGLEBUTTON(widget) - ->icon(cr, border, border, height - (border * 2), height - (border * 2), flags); + DTGTK_TOGGLEBUTTON(widget)->icon(cr, border, border, height - (border * 2), height - (border * 2), flags); else - DTGTK_TOGGLEBUTTON(widget) - ->icon(cr, border, border, width - (border * 2), height - (border * 2), flags); + DTGTK_TOGGLEBUTTON(widget)->icon(cr, border, border, width - (border * 2), height - (border * 2), flags); } } @@ -180,15 +177,14 @@ GType dtgtk_togglebutton_get_type() sizeof(GtkDarktableToggleButton), 0, /* n_preallocs */ (GInstanceInitFunc)_togglebutton_init, }; - dtgtk_togglebutton_type = g_type_register_static(GTK_TYPE_TOGGLE_BUTTON, "GtkDarktableToggleButton", - &dtgtk_togglebutton_info, 0); + dtgtk_togglebutton_type + = g_type_register_static(GTK_TYPE_TOGGLE_BUTTON, "GtkDarktableToggleButton", &dtgtk_togglebutton_info, 0); } return dtgtk_togglebutton_type; } -void dtgtk_togglebutton_set_paint(GtkDarktableToggleButton *button, DTGTKCairoPaintIconFunc paint, - gint paintflags) +void dtgtk_togglebutton_set_paint(GtkDarktableToggleButton *button, DTGTKCairoPaintIconFunc paint, gint paintflags) { button->icon = paint; button->icon_flags = paintflags; diff --git a/src/dtgtk/togglebutton.h b/src/dtgtk/togglebutton.h index f89822d520aa..f141c0a170b4 100644 --- a/src/dtgtk/togglebutton.h +++ b/src/dtgtk/togglebutton.h @@ -21,9 +21,9 @@ #include "paint.h" #include <gtk/gtk.h> G_BEGIN_DECLS -#define DTGTK_TOGGLEBUTTON(obj) \ +#define DTGTK_TOGGLEBUTTON(obj) \ G_TYPE_CHECK_INSTANCE_CAST(obj, dtgtk_togglebutton_get_type(), GtkDarktableToggleButton) -#define DTGTK_TOGGLEBUTTON_CLASS(klass) \ +#define DTGTK_TOGGLEBUTTON_CLASS(klass) \ G_TYPE_CHECK_CLASS_CAST(klass, dtgtk_togglebutton_get_type(), GtkDarktableToggleButtonClass) #define DTGTK_IS_TOGGLEBUTTON(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, dtgtk_togglebutton_get_type()) #define DTGTK_IS_TOGGLEBUTTON_CLASS(klass) G_TYPE_CHECK_CLASS_TYPE(obj, dtgtk_togglebutton_get_type()) @@ -47,8 +47,7 @@ GType dtgtk_togglebutton_get_type(void); GtkWidget *dtgtk_togglebutton_new(DTGTKCairoPaintIconFunc paint, gint paintflag); /** Set the paint function and paint flags */ -void dtgtk_togglebutton_set_paint(GtkDarktableToggleButton *button, DTGTKCairoPaintIconFunc paint, - gint paintflags); +void dtgtk_togglebutton_set_paint(GtkDarktableToggleButton *button, DTGTKCairoPaintIconFunc paint, gint paintflags); /** overwrite the foreground color, or NULL to reset it */ void dtgtk_togglebutton_override_color(GtkDarktableToggleButton *button, GdkRGBA *color); /** overwrite the background color, or NULL to reset it */ diff --git a/src/generate-cache/main.c b/src/generate-cache/main.c index 1e503323d536..1f40407309b2 100644 --- a/src/generate-cache/main.c +++ b/src/generate-cache/main.c @@ -40,7 +40,8 @@ #include "win/main_wrapper.h" #endif -static int generate_thumbnail_cache(const dt_mipmap_size_t min_mip, const dt_mipmap_size_t max_mip, const int32_t min_imgid, const int32_t max_imgid) +static int generate_thumbnail_cache(const dt_mipmap_size_t min_mip, const dt_mipmap_size_t max_mip, + const int32_t min_imgid, const int32_t max_imgid) { fprintf(stderr, _("creating cache directories\n")); for(dt_mipmap_size_t k = min_mip; k <= max_mip; k++) @@ -92,7 +93,8 @@ static int generate_thumbnail_cache(const dt_mipmap_size_t min_mip, const dt_mip const int32_t imgid = sqlite3_column_int(stmt, 0); counter++; - fprintf(stderr, "image %zu/%zu (%.02f%%) (id:%d)\n", counter, image_count, 100.0 * counter / (float)image_count, imgid); + fprintf(stderr, "image %zu/%zu (%.02f%%) (id:%d)\n", counter, image_count, + 100.0 * counter / (float)image_count, imgid); for(int k = max_mip; k >= min_mip && k >= 0; k--) { @@ -120,19 +122,17 @@ static int generate_thumbnail_cache(const dt_mipmap_size_t min_mip, const dt_mip static void usage(const char *progname) { - fprintf( - stderr, - "usage: %s [-h, --help; --version]\n" - " [--min-mip <0-7> (default = 0)] [-m, --max-mip <0-7> (default = 2)]\n" - " [--min-imgid <N>] [--max-imgid <N>]\n" - " [--core <darktable options>]\n" - "\n" - "When multiple mipmap sizes are requested, the biggest one is computed\n" - "while the rest are quickly downsampled.\n" - "\n" - "The --min-imgid and --max-imgid specify the range of internal image ID\n" - "numbers to work on.\n", - progname); + fprintf(stderr, "usage: %s [-h, --help; --version]\n" + " [--min-mip <0-7> (default = 0)] [-m, --max-mip <0-7> (default = 2)]\n" + " [--min-imgid <N>] [--max-imgid <N>]\n" + " [--core <darktable options>]\n" + "\n" + "When multiple mipmap sizes are requested, the biggest one is computed\n" + "while the rest are quickly downsampled.\n" + "\n" + "The --min-imgid and --max-imgid specify the range of internal image ID\n" + "numbers to work on.\n", + progname); } int main(int argc, char *arg[]) @@ -207,10 +207,9 @@ int main(int argc, char *arg[]) if(!dt_conf_get_bool("cache_disk_backend")) { - fprintf(stderr, - _("warning: disk backend for thumbnail cache is disabled (cache_disk_backend)\nif you want " - "to pre-generate thumbnails and for darktable to use them, you need to enable disk backend " - "for thumbnail cache\nno thumbnails to be generated, done.")); + fprintf(stderr, _("warning: disk backend for thumbnail cache is disabled (cache_disk_backend)\nif you want " + "to pre-generate thumbnails and for darktable to use them, you need to enable disk backend " + "for thumbnail cache\nno thumbnails to be generated, done.")); dt_cleanup(); free(m_arg); exit(EXIT_FAILURE); diff --git a/src/gui/accelerators.c b/src/gui/accelerators.c index 9f6f92f94b20..e73767d3a991 100644 --- a/src/gui/accelerators.c +++ b/src/gui/accelerators.c @@ -87,8 +87,7 @@ static void dt_accel_path_lib_translated(char *s, size_t n, dt_lib_module_t *mod g_dpgettext2(NULL, "accel", path)); } -static void dt_accel_paths_slider_iop_translated(char *s[], size_t n, dt_iop_module_so_t *module, - const char *path) +static void dt_accel_paths_slider_iop_translated(char *s[], size_t n, dt_iop_module_so_t *module, const char *path) { snprintf(s[0], n, "<Darktable>/%s/%s/%s/%s", C_("accel", "image operations"), module->name(), g_dpgettext2(NULL, "accel", path), C_("accel", "increase")); @@ -320,8 +319,8 @@ static gboolean _press_button_callback(GtkAccelGroup *accel_group, GObject *acce return TRUE; } -static gboolean _tooltip_callback(GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, - GtkTooltip *tooltip, gpointer user_data) +static gboolean _tooltip_callback(GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip, + gpointer user_data) { char *text = gtk_widget_get_tooltip_text(widget); @@ -374,8 +373,8 @@ static gboolean bauhaus_slider_edit_callback(GtkAccelGroup *accel_group, GObject return TRUE; } -static gboolean bauhaus_slider_increase_callback(GtkAccelGroup *accel_group, GObject *acceleratable, - guint keyval, GdkModifierType modifier, gpointer data) +static gboolean bauhaus_slider_increase_callback(GtkAccelGroup *accel_group, GObject *acceleratable, guint keyval, + GdkModifierType modifier, gpointer data) { GtkWidget *slider = GTK_WIDGET(data); @@ -388,8 +387,8 @@ static gboolean bauhaus_slider_increase_callback(GtkAccelGroup *accel_group, GOb return TRUE; } -static gboolean bauhaus_slider_decrease_callback(GtkAccelGroup *accel_group, GObject *acceleratable, - guint keyval, GdkModifierType modifier, gpointer data) +static gboolean bauhaus_slider_decrease_callback(GtkAccelGroup *accel_group, GObject *acceleratable, guint keyval, + GdkModifierType modifier, gpointer data) { GtkWidget *slider = GTK_WIDGET(data); @@ -402,8 +401,8 @@ static gboolean bauhaus_slider_decrease_callback(GtkAccelGroup *accel_group, GOb return TRUE; } -static gboolean bauhaus_slider_reset_callback(GtkAccelGroup *accel_group, GObject *acceleratable, - guint keyval, GdkModifierType modifier, gpointer data) +static gboolean bauhaus_slider_reset_callback(GtkAccelGroup *accel_group, GObject *acceleratable, guint keyval, + GdkModifierType modifier, gpointer data) { GtkWidget *slider = GTK_WIDGET(data); @@ -562,8 +561,7 @@ typedef struct static void preset_iop_module_callback_destroyer(gpointer data, GClosure *closure) { - preset_iop_module_callback_description *callback_description - = (preset_iop_module_callback_description *)data; + preset_iop_module_callback_description *callback_description = (preset_iop_module_callback_description *)data; g_free(callback_description->name); g_free(data); } @@ -571,8 +569,7 @@ static gboolean preset_iop_module_callback(GtkAccelGroup *accel_group, GObject * GdkModifierType modifier, gpointer data) { - preset_iop_module_callback_description *callback_description - = (preset_iop_module_callback_description *)data; + preset_iop_module_callback_description *callback_description = (preset_iop_module_callback_description *)data; dt_iop_module_t *module = callback_description->module; const char *name = callback_description->name; @@ -646,8 +643,7 @@ typedef struct static void preset_lib_module_callback_destroyer(gpointer data, GClosure *closure) { - preset_lib_module_callback_description *callback_description - = (preset_lib_module_callback_description *)data; + preset_lib_module_callback_description *callback_description = (preset_lib_module_callback_description *)data; g_free(callback_description->name); g_free(data); } @@ -655,8 +651,7 @@ static gboolean preset_lib_module_callback(GtkAccelGroup *accel_group, GObject * GdkModifierType modifier, gpointer data) { - preset_lib_module_callback_description *callback_description - = (preset_lib_module_callback_description *)data; + preset_lib_module_callback_description *callback_description = (preset_lib_module_callback_description *)data; dt_lib_module_t *module = callback_description->module; const char *pn = callback_description->name; diff --git a/src/gui/camera_import_dialog.c b/src/gui/camera_import_dialog.c index cf5600680246..d1afa72072ae 100644 --- a/src/gui/camera_import_dialog.c +++ b/src/gui/camera_import_dialog.c @@ -34,7 +34,7 @@ #include <time.h> #ifdef _WIN32 -//MSVCRT does not have strptime implemented +// MSVCRT does not have strptime implemented #include "win/strptime.h" #endif /* @@ -107,8 +107,8 @@ static void _check_button_callback(GtkWidget *cb, gpointer user_data) else if(cb == cid->settings.general.date_override) { // Enable/disable the date entry widget - gtk_widget_set_sensitive(cid->settings.general.date_entry, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( - cid->settings.general.date_override))); + gtk_widget_set_sensitive(cid->settings.general.date_entry, + gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cid->settings.general.date_override))); } } @@ -208,9 +208,9 @@ static _camera_gconf_widget_t *_camera_import_gconf_widget(_camera_import_dialog static void _camera_import_dialog_new(_camera_import_dialog_t *data) { - data->dialog = gtk_dialog_new_with_buttons(_("import images from camera"), NULL, GTK_DIALOG_MODAL, - _("cancel"), GTK_RESPONSE_NONE, C_("camera import", "import"), - GTK_RESPONSE_ACCEPT, NULL); + data->dialog + = gtk_dialog_new_with_buttons(_("import images from camera"), NULL, GTK_DIALOG_MODAL, _("cancel"), + GTK_RESPONSE_NONE, C_("camera import", "import"), GTK_RESPONSE_ACCEPT, NULL); #ifdef GDK_WINDOWING_QUARTZ dt_osx_disallow_fullscreen(data->dialog); #endif @@ -232,15 +232,13 @@ static void _camera_import_dialog_new(_camera_import_dialog_t *data) gtk_box_pack_start(GTK_BOX(data->import.page), data->import.info, FALSE, FALSE, 0); // jobcode - data->import.jobname - = _camera_import_gconf_widget(data, _("jobcode"), "plugins/capture/camera/import/jobcode"); + data->import.jobname = _camera_import_gconf_widget(data, _("jobcode"), "plugins/capture/camera/import/jobcode"); gtk_box_pack_start(GTK_BOX(data->import.page), GTK_WIDGET(data->import.jobname->widget), FALSE, FALSE, 0); // Create the treview with list model data store data->import.treeview = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(data->import.treeview), GTK_POLICY_NEVER, - GTK_POLICY_ALWAYS); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(data->import.treeview), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); gtk_container_add(GTK_CONTAINER(data->import.treeview), gtk_tree_view_new()); GtkTreeView *treeview = GTK_TREE_VIEW(gtk_bin_get_child(GTK_BIN(data->import.treeview))); @@ -274,29 +272,31 @@ static void _camera_import_dialog_new(_camera_import_dialog_t *data) // ignoring of jpegs. hack while we don't handle raw+jpeg in the same directories. data->settings.general.ignore_jpeg = gtk_check_button_new_with_label(_("ignore JPEG files")); - gtk_widget_set_tooltip_text(data->settings.general.ignore_jpeg, - _("do not load files with an extension of .jpg or .jpeg. this can be useful when there are " - "raw+JPEG in a directory.")); + gtk_widget_set_tooltip_text( + data->settings.general.ignore_jpeg, + _("do not load files with an extension of .jpg or .jpeg. this can be useful when there are " + "raw+JPEG in a directory.")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->settings.general.ignore_jpeg), dt_conf_get_bool("ui_last/import_ignore_jpegs")); gtk_box_pack_start(GTK_BOX(data->settings.page), data->settings.general.ignore_jpeg, FALSE, FALSE, 0); - g_signal_connect(G_OBJECT(data->settings.general.ignore_jpeg), "clicked", - G_CALLBACK(_check_button_callback), data); + g_signal_connect(G_OBJECT(data->settings.general.ignore_jpeg), "clicked", G_CALLBACK(_check_button_callback), + data); GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); data->settings.general.date_override = gtk_check_button_new_with_label(_("override today's date")); gtk_box_pack_start(GTK_BOX(hbox), data->settings.general.date_override, FALSE, FALSE, 0); - gtk_widget_set_tooltip_text(data->settings.general.date_override, - _("check this, if you want to override the timestamp used when expanding variables:\n$(YEAR), " - "$(MONTH), $(DAY),\n$(HOUR), $(MINUTE), $(SECONDS)")); + gtk_widget_set_tooltip_text( + data->settings.general.date_override, + _("check this, if you want to override the timestamp used when expanding variables:\n$(YEAR), " + "$(MONTH), $(DAY),\n$(HOUR), $(MINUTE), $(SECONDS)")); data->settings.general.date_entry = gtk_entry_new(); - gtk_widget_set_sensitive(data->settings.general.date_entry, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( - data->settings.general.date_override))); + gtk_widget_set_sensitive(data->settings.general.date_entry, + gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->settings.general.date_override))); gtk_box_pack_start(GTK_BOX(hbox), data->settings.general.date_entry, TRUE, TRUE, 0); - g_signal_connect(G_OBJECT(data->settings.general.date_override), "clicked", - G_CALLBACK(_check_button_callback), data); + g_signal_connect(G_OBJECT(data->settings.general.date_override), "clicked", G_CALLBACK(_check_button_callback), + data); gtk_box_pack_start(GTK_BOX(data->settings.page), hbox, FALSE, FALSE, 0); @@ -333,8 +333,8 @@ static gboolean _camera_storage_image_filename_gui_thread(gpointer user_data) return FALSE; } -static int _camera_storage_image_filename(const dt_camera_t *camera, const char *filename, - CameraFile *preview, CameraFile *exif, void *user_data) +static int _camera_storage_image_filename(const dt_camera_t *camera, const char *filename, CameraFile *preview, + CameraFile *exif, void *user_data) { _camera_import_dialog_t *data = (_camera_import_dialog_t *)user_data; const char *img; @@ -395,8 +395,7 @@ static int _camera_storage_image_filename(const dt_camera_t *camera, const char } // filename\n 1/60 f/2.8 24mm iso 160 - params->file_info = g_strdup_printf("%s%c%s", filename, *exif_info ? '\n' : '\0', - *exif_info ? exif_info : ""); + params->file_info = g_strdup_printf("%s%c%s", filename, *exif_info ? '\n' : '\0', *exif_info ? exif_info : ""); params->thumb = thumb; params->store = data->store; g_main_context_invoke(NULL, _camera_storage_image_filename_gui_thread, params); diff --git a/src/gui/draw.h b/src/gui/draw.h index 16ff8b647805..4f2410bf6c72 100644 --- a/src/gui/draw.h +++ b/src/gui/draw.h @@ -82,8 +82,8 @@ static inline void dt_draw_grid(cairo_t *cr, const int num, const int left, cons } } -static inline void dt_draw_loglog_grid(cairo_t *cr, const int num, const int left, const int top, - const int right, const int bottom, const int base) +static inline void dt_draw_loglog_grid(cairo_t *cr, const int num, const int left, const int top, const int right, + const int bottom, const int base) { float width = right - left; float height = bottom - top; @@ -188,8 +188,8 @@ static inline void dt_draw_curve_set_point(dt_draw_curve_t *c, const int num, co c->c.m_anchors[num].y = y; } -static inline void dt_draw_curve_calc_values(dt_draw_curve_t *c, const float min, const float max, - const int res, float *x, float *y) +static inline void dt_draw_curve_calc_values(dt_draw_curve_t *c, const float min, const float max, const int res, + float *x, float *y) { c->csample.m_samplingRes = res; c->csample.m_outputRes = 0x10000; diff --git a/src/gui/gtk.c b/src/gui/gtk.c index d54b5373d48f..adb21f4934d3 100644 --- a/src/gui/gtk.c +++ b/src/gui/gtk.c @@ -70,8 +70,7 @@ typedef enum dt_gui_view_switch_t DT_GUI_VIEW_SWITCH_TO_PRINT } dt_gui_view_switch_to_t; -const char *_ui_panel_config_names[] - = { "header", "toolbar_top", "toolbar_bottom", "left", "right", "bottom" }; +const char *_ui_panel_config_names[] = { "header", "toolbar_top", "toolbar_bottom", "left", "right", "bottom" }; typedef struct dt_ui_t { @@ -121,8 +120,8 @@ static void init_widgets(dt_gui_gtk_t *gui); static void init_main_table(GtkWidget *container); -static void key_accel_changed(GtkAccelMap *object, gchar *accel_path, guint accel_key, - GdkModifierType accel_mods, gpointer user_data) +static void key_accel_changed(GtkAccelMap *object, gchar *accel_path, guint accel_key, GdkModifierType accel_mods, + gpointer user_data) { char path[256]; @@ -170,8 +169,8 @@ static void key_accel_changed(GtkAccelMap *object, gchar *accel_path, guint acce gtk_accel_map_lookup_entry(path, &darktable.control->accels.global_header); } -static gboolean fullscreen_key_accel_callback(GtkAccelGroup *accel_group, GObject *acceleratable, - guint keyval, GdkModifierType modifier, gpointer data) +static gboolean fullscreen_key_accel_callback(GtkAccelGroup *accel_group, GObject *acceleratable, guint keyval, + GdkModifierType modifier, gpointer data) { GtkWidget *widget; int fullscreen; @@ -202,8 +201,8 @@ static gboolean fullscreen_key_accel_callback(GtkAccelGroup *accel_group, GObjec return TRUE; } -static gboolean view_switch_key_accel_callback(GtkAccelGroup *accel_group, GObject *acceleratable, - guint keyval, GdkModifierType modifier, gpointer data) +static gboolean view_switch_key_accel_callback(GtkAccelGroup *accel_group, GObject *acceleratable, guint keyval, + GdkModifierType modifier, gpointer data) { dt_ctl_switch_mode(); gtk_widget_queue_draw(dt_ui_center(darktable.gui->ui)); @@ -222,16 +221,14 @@ static gboolean borders_button_pressed(GtkWidget *w, GdkEventButton *event, gpoi { case 0: // left border { - g_snprintf(key, sizeof(key), "%s/ui/%s_visible", cv->module_name, - _ui_panel_config_names[DT_UI_PANEL_LEFT]); + g_snprintf(key, sizeof(key), "%s/ui/%s_visible", cv->module_name, _ui_panel_config_names[DT_UI_PANEL_LEFT]); dt_ui_panel_show(ui, DT_UI_PANEL_LEFT, !dt_conf_get_bool(key), TRUE); } break; case 1: // right border { - g_snprintf(key, sizeof(key), "%s/ui/%s_visible", cv->module_name, - _ui_panel_config_names[DT_UI_PANEL_RIGHT]); + g_snprintf(key, sizeof(key), "%s/ui/%s_visible", cv->module_name, _ui_panel_config_names[DT_UI_PANEL_RIGHT]); dt_ui_panel_show(ui, DT_UI_PANEL_RIGHT, !dt_conf_get_bool(key), TRUE); } break; @@ -299,7 +296,7 @@ gboolean dt_gui_get_scroll_deltas(const GdkEventScroll *event, gdouble *delta_x, handled = TRUE; default: break; - } + } return handled; } @@ -376,8 +373,7 @@ static gboolean _widget_focus_in_block_key_accelerators(GtkWidget *widget, GdkEv return FALSE; } -static gboolean _widget_focus_out_unblock_key_accelerators(GtkWidget *widget, GdkEventFocus *event, - gpointer data) +static gboolean _widget_focus_out_unblock_key_accelerators(GtkWidget *widget, GdkEventFocus *event, gpointer data) { dt_control_key_accelerators_on(darktable.control); return FALSE; @@ -395,8 +391,7 @@ void dt_gui_key_accel_block_on_focus_connect(GtkWidget *w) gtk_widget_add_events(w, GDK_FOCUS_CHANGE_MASK); /* connect the signals */ - g_signal_connect(G_OBJECT(w), "focus-in-event", G_CALLBACK(_widget_focus_in_block_key_accelerators), - (gpointer)w); + g_signal_connect(G_OBJECT(w), "focus-in-event", G_CALLBACK(_widget_focus_in_block_key_accelerators), (gpointer)w); g_signal_connect(G_OBJECT(w), "focus-out-event", G_CALLBACK(_widget_focus_out_unblock_key_accelerators), (gpointer)w); } @@ -414,7 +409,7 @@ static gboolean draw_borders(GtkWidget *widget, cairo_t *crf, gpointer user_data GdkRGBA color; GtkStyleContext *context = gtk_widget_get_style_context(widget); - gboolean color_found = gtk_style_context_lookup_color (context, "selected_bg_color", &color); + gboolean color_found = gtk_style_context_lookup_color(context, "selected_bg_color", &color); if(!color_found) { color.red = 1.0; @@ -427,7 +422,7 @@ static gboolean draw_borders(GtkWidget *widget, cairo_t *crf, gpointer user_data // draw scrollbar indicators const dt_view_t *view = dt_view_manager_get_current_view(darktable.view_manager); - color_found = gtk_style_context_lookup_color (context, "bg_color", &color); + color_found = gtk_style_context_lookup_color(context, "bg_color", &color); if(!color_found) { color.red = 1.0; @@ -450,7 +445,8 @@ static gboolean draw_borders(GtkWidget *widget, cairo_t *crf, gpointer user_data break; default: // bottom, top: horizontal cairo_rectangle(cr, view->hscroll_pos / view->hscroll_size * width, 0.0, - MAX(DT_PIXEL_APPLY_DPI(5), view->hscroll_viewport_size / view->hscroll_size * width), height); + MAX(DT_PIXEL_APPLY_DPI(5), view->hscroll_viewport_size / view->hscroll_size * width), + height); break; } cairo_fill(cr); @@ -463,19 +459,18 @@ static gboolean draw_borders(GtkWidget *widget, cairo_t *crf, gpointer user_data cairo_rectangle(cr, 0.0, 0.0, border * width, height); break; case 2: - cairo_rectangle(cr, (1.0 - border) * height, (1.0 - border) * height, - width - 2 * (1.0 - border) * height, border * height); + cairo_rectangle(cr, (1.0 - border) * height, (1.0 - border) * height, width - 2 * (1.0 - border) * height, + border * height); break; default: - cairo_rectangle(cr, (1.0 - border) * height, 0.0, width - 2 * (1.0 - border) * height, - border * height); + cairo_rectangle(cr, (1.0 - border) * height, 0.0, width - 2 * (1.0 - border) * height, border * height); break; } cairo_fill(cr); } // draw gui arrows. - color_found = gtk_style_context_lookup_color (context, "fg_color", &color); + color_found = gtk_style_context_lookup_color(context, "fg_color", &color); if(!color_found) { color.red = 1.0; @@ -577,9 +572,7 @@ static gboolean scrolled(GtkWidget *widget, GdkEventScroll *event, gpointer user int delta_y; if(dt_gui_get_scroll_unit_deltas(event, NULL, &delta_y)) { - dt_view_manager_scrolled(darktable.view_manager, event->x, event->y, - delta_y < 0, - event->state & 0xf); + dt_view_manager_scrolled(darktable.view_manager, event->x, event->y, delta_y < 0, event->state & 0xf); gtk_widget_queue_draw(widget); } @@ -736,8 +729,7 @@ static gboolean osx_quit_callback(GtkosxApplication *OSXapp, gpointer user_data) GList *windows, *window; windows = gtk_window_list_toplevels(); for(window = g_list_first(windows); window != NULL; window = g_list_next(window)) - if(gtk_window_get_modal(GTK_WINDOW(window->data)) && gtk_widget_get_visible(GTK_WIDGET(window->data))) - break; + if(gtk_window_get_modal(GTK_WINDOW(window->data)) && gtk_widget_get_visible(GTK_WIDGET(window->data))) break; if(window == NULL) dt_control_quit(); g_list_free(windows); return TRUE; @@ -761,8 +753,7 @@ static gboolean configure(GtkWidget *da, GdkEventConfigure *event, gpointer user if(oldw != event->width || oldh != event->height) { // create our new pixmap with the correct size. - cairo_surface_t *tmpsurface - = dt_cairo_image_surface_create(CAIRO_FORMAT_ARGB32, event->width, event->height); + cairo_surface_t *tmpsurface = dt_cairo_image_surface_create(CAIRO_FORMAT_ARGB32, event->width, event->height); // copy the contents of the old pixmap to the new pixmap. This keeps ugly uninitialized // pixmaps from being painted upon resize // int minw = oldw, minh = oldh; @@ -783,7 +774,7 @@ static gboolean configure(GtkWidget *da, GdkEventConfigure *event, gpointer user oldh = event->height; #ifndef GDK_WINDOWING_QUARTZ - configure_ppd_dpi((dt_gui_gtk_t *) user_data); + configure_ppd_dpi((dt_gui_gtk_t *)user_data); #endif return dt_control_configure(da, event, user_data); @@ -824,7 +815,7 @@ static gboolean button_pressed(GtkWidget *w, GdkEventButton *event, gpointer use if(device && gdk_device_get_source(device) == GDK_SOURCE_PEN) { - gdk_event_get_axis ((GdkEvent *)event, GDK_AXIS_PRESSURE, &pressure); + gdk_event_get_axis((GdkEvent *)event, GDK_AXIS_PRESSURE, &pressure); } dt_control_button_pressed(event->x, event->y, pressure, event->button, event->type, event->state & 0xf); gtk_widget_grab_focus(w); @@ -846,7 +837,7 @@ static gboolean mouse_moved(GtkWidget *w, GdkEventMotion *event, gpointer user_d if(device && gdk_device_get_source(device) == GDK_SOURCE_PEN) { - gdk_event_get_axis ((GdkEvent *)event, GDK_AXIS_PRESSURE, &pressure); + gdk_event_get_axis((GdkEvent *)event, GDK_AXIS_PRESSURE, &pressure); } dt_control_mouse_moved(event->x, event->y, pressure, event->state & 0xf); gint x, y; @@ -873,29 +864,28 @@ static gboolean center_enter(GtkWidget *widget, GdkEventCrossing *event, gpointe return TRUE; } -static const char* get_source_name(int pos) +static const char *get_source_name(int pos) { - static const gchar *SOURCE_NAMES[] - = { "GDK_SOURCE_MOUSE", "GDK_SOURCE_PEN", "GDK_SOURCE_ERASER", "GDK_SOURCE_CURSOR", - "GDK_SOURCE_KEYBOARD", "GDK_SOURCE_TOUCHSCREEN", "GDK_SOURCE_TOUCHPAD", "GDK_SOURCE_TRACKPOINT", - "GDK_SOURCE_TABLET_PAD" }; + static const gchar *SOURCE_NAMES[] = { "GDK_SOURCE_MOUSE", "GDK_SOURCE_PEN", "GDK_SOURCE_ERASER", + "GDK_SOURCE_CURSOR", "GDK_SOURCE_KEYBOARD", "GDK_SOURCE_TOUCHSCREEN", + "GDK_SOURCE_TOUCHPAD", "GDK_SOURCE_TRACKPOINT", "GDK_SOURCE_TABLET_PAD" }; if(pos >= G_N_ELEMENTS(SOURCE_NAMES)) return "<UNKNOWN>"; return SOURCE_NAMES[pos]; } -static const char* get_mode_name(int pos) +static const char *get_mode_name(int pos) { static const gchar *MODE_NAMES[] = { "GDK_MODE_DISABLED", "GDK_MODE_SCREEN", "GDK_MODE_WINDOW" }; if(pos >= G_N_ELEMENTS(MODE_NAMES)) return "<UNKNOWN>"; return MODE_NAMES[pos]; } -static const char* get_axis_name(int pos) +static const char *get_axis_name(int pos) { static const gchar *AXIS_NAMES[] - = { "GDK_AXIS_IGNORE", "GDK_AXIS_X", "GDK_AXIS_Y", "GDK_AXIS_PRESSURE", - "GDK_AXIS_XTILT", "GDK_AXIS_YTILT", "GDK_AXIS_WHEEL", "GDK_AXIS_DISTANCE", - "GDK_AXIS_ROTATION", "GDK_AXIS_SLIDER", "GDK_AXIS_LAST" }; + = { "GDK_AXIS_IGNORE", "GDK_AXIS_X", "GDK_AXIS_Y", "GDK_AXIS_PRESSURE", + "GDK_AXIS_XTILT", "GDK_AXIS_YTILT", "GDK_AXIS_WHEEL", "GDK_AXIS_DISTANCE", + "GDK_AXIS_ROTATION", "GDK_AXIS_SLIDER", "GDK_AXIS_LAST" }; if(pos >= G_N_ELEMENTS(AXIS_NAMES)) return "<UNKNOWN>"; return AXIS_NAMES[pos]; } @@ -926,12 +916,12 @@ int dt_gui_gtk_init(dt_gui_gtk_t *gui) #ifdef MAC_INTEGRATION #ifdef GTK_TYPE_OSX_APPLICATION GtkOSXApplication *OSXApp = g_object_new(GTK_TYPE_OSX_APPLICATION, NULL); - gtk_osxapplication_set_menu_bar( - OSXApp, GTK_MENU_SHELL(gtk_menu_bar_new())); // needed for default entries to show up + gtk_osxapplication_set_menu_bar(OSXApp, + GTK_MENU_SHELL(gtk_menu_bar_new())); // needed for default entries to show up #else GtkosxApplication *OSXApp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL); - gtkosx_application_set_menu_bar( - OSXApp, GTK_MENU_SHELL(gtk_menu_bar_new())); // needed for default entries to show up + gtkosx_application_set_menu_bar(OSXApp, + GTK_MENU_SHELL(gtk_menu_bar_new())); // needed for default entries to show up #endif g_signal_connect(G_OBJECT(OSXApp), "NSApplicationBlockTermination", G_CALLBACK(osx_quit_callback), NULL); g_signal_connect(G_OBJECT(OSXApp), "NSApplicationOpenFile", G_CALLBACK(osx_openfile_callback), NULL); @@ -955,7 +945,8 @@ int dt_gui_gtk_init(dt_gui_gtk_t *gui) GError *error = NULL; GtkStyleProvider *themes_style_provider = GTK_STYLE_PROVIDER(gtk_css_provider_new()); - gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), themes_style_provider, GTK_STYLE_PROVIDER_PRIORITY_USER + 1); + gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), themes_style_provider, + GTK_STYLE_PROVIDER_PRIORITY_USER + 1); if(!gtk_css_provider_load_from_path(GTK_CSS_PROVIDER(themes_style_provider), gui->gtkrc, &error)) { @@ -977,8 +968,7 @@ int dt_gui_gtk_init(dt_gui_gtk_t *gui) init_widgets(gui); // Adding the global shortcut group to the main window - gtk_window_add_accel_group(GTK_WINDOW(dt_ui_main_window(darktable.gui->ui)), - darktable.control->accelerators); + gtk_window_add_accel_group(GTK_WINDOW(dt_ui_main_window(darktable.gui->ui)), darktable.control->accelerators); // dt_gui_background_jobs_init(); @@ -1004,23 +994,19 @@ int dt_gui_gtk_init(dt_gui_gtk_t *gui) widget = darktable.gui->widgets.left_border; g_signal_connect(G_OBJECT(widget), "draw", G_CALLBACK(draw_borders), GINT_TO_POINTER(0)); - g_signal_connect(G_OBJECT(widget), "button-press-event", G_CALLBACK(borders_button_pressed), - darktable.gui->ui); + g_signal_connect(G_OBJECT(widget), "button-press-event", G_CALLBACK(borders_button_pressed), darktable.gui->ui); g_object_set_data(G_OBJECT(widget), "border", GINT_TO_POINTER(0)); widget = darktable.gui->widgets.right_border; g_signal_connect(G_OBJECT(widget), "draw", G_CALLBACK(draw_borders), GINT_TO_POINTER(1)); - g_signal_connect(G_OBJECT(widget), "button-press-event", G_CALLBACK(borders_button_pressed), - darktable.gui->ui); + g_signal_connect(G_OBJECT(widget), "button-press-event", G_CALLBACK(borders_button_pressed), darktable.gui->ui); g_object_set_data(G_OBJECT(widget), "border", GINT_TO_POINTER(1)); widget = darktable.gui->widgets.top_border; g_signal_connect(G_OBJECT(widget), "draw", G_CALLBACK(draw_borders), GINT_TO_POINTER(2)); - g_signal_connect(G_OBJECT(widget), "button-press-event", G_CALLBACK(borders_button_pressed), - darktable.gui->ui); + g_signal_connect(G_OBJECT(widget), "button-press-event", G_CALLBACK(borders_button_pressed), darktable.gui->ui); g_object_set_data(G_OBJECT(widget), "border", GINT_TO_POINTER(2)); widget = darktable.gui->widgets.bottom_border; g_signal_connect(G_OBJECT(widget), "draw", G_CALLBACK(draw_borders), GINT_TO_POINTER(3)); - g_signal_connect(G_OBJECT(widget), "button-press-event", G_CALLBACK(borders_button_pressed), - darktable.gui->ui); + g_signal_connect(G_OBJECT(widget), "button-press-event", G_CALLBACK(borders_button_pressed), darktable.gui->ui); g_object_set_data(G_OBJECT(widget), "border", GINT_TO_POINTER(3)); dt_gui_presets_init(); @@ -1046,22 +1032,19 @@ int dt_gui_gtk_init(dt_gui_gtk_t *gui) dt_accel_register_global(NC_("accel", "slideshow view"), GDK_KEY_s, 0); dt_accel_register_global(NC_("accel", "print view"), GDK_KEY_p, 0); - dt_accel_connect_global("tethering view", - g_cclosure_new(G_CALLBACK(_gui_switch_view_key_accel_callback), - GINT_TO_POINTER(DT_GUI_VIEW_SWITCH_TO_TETHERING), NULL)); + dt_accel_connect_global("tethering view", g_cclosure_new(G_CALLBACK(_gui_switch_view_key_accel_callback), + GINT_TO_POINTER(DT_GUI_VIEW_SWITCH_TO_TETHERING), NULL)); dt_accel_connect_global("lighttable view", g_cclosure_new(G_CALLBACK(_gui_switch_view_key_accel_callback), GINT_TO_POINTER(DT_GUI_VIEW_SWITCH_TO_LIGHTTABLE), NULL)); - dt_accel_connect_global("darkroom view", - g_cclosure_new(G_CALLBACK(_gui_switch_view_key_accel_callback), - GINT_TO_POINTER(DT_GUI_VIEW_SWITCH_TO_DARKROOM), NULL)); + dt_accel_connect_global("darkroom view", g_cclosure_new(G_CALLBACK(_gui_switch_view_key_accel_callback), + GINT_TO_POINTER(DT_GUI_VIEW_SWITCH_TO_DARKROOM), NULL)); dt_accel_connect_global("map view", g_cclosure_new(G_CALLBACK(_gui_switch_view_key_accel_callback), GINT_TO_POINTER(DT_GUI_VIEW_SWITCH_TO_MAP), NULL)); - dt_accel_connect_global("slideshow view", - g_cclosure_new(G_CALLBACK(_gui_switch_view_key_accel_callback), - GINT_TO_POINTER(DT_GUI_VIEW_SWITCH_TO_SLIDESHOW), NULL)); + dt_accel_connect_global("slideshow view", g_cclosure_new(G_CALLBACK(_gui_switch_view_key_accel_callback), + GINT_TO_POINTER(DT_GUI_VIEW_SWITCH_TO_SLIDESHOW), NULL)); dt_accel_connect_global("print view", g_cclosure_new(G_CALLBACK(_gui_switch_view_key_accel_callback), - GINT_TO_POINTER(DT_GUI_VIEW_SWITCH_TO_PRINT), NULL)); + GINT_TO_POINTER(DT_GUI_VIEW_SWITCH_TO_PRINT), NULL)); // register_keys for applying styles init_styles_key_accels(); @@ -1075,10 +1058,10 @@ int dt_gui_gtk_init(dt_gui_gtk_t *gui) dt_accel_register_global(NC_("accel", "toggle fullscreen"), GDK_KEY_F11, 0); dt_accel_register_global(NC_("accel", "leave fullscreen"), GDK_KEY_Escape, 0); - dt_accel_connect_global("toggle fullscreen", g_cclosure_new(G_CALLBACK(fullscreen_key_accel_callback), - GINT_TO_POINTER(1), NULL)); - dt_accel_connect_global("leave fullscreen", g_cclosure_new(G_CALLBACK(fullscreen_key_accel_callback), - GINT_TO_POINTER(0), NULL)); + dt_accel_connect_global("toggle fullscreen", + g_cclosure_new(G_CALLBACK(fullscreen_key_accel_callback), GINT_TO_POINTER(1), NULL)); + dt_accel_connect_global("leave fullscreen", + g_cclosure_new(G_CALLBACK(fullscreen_key_accel_callback), GINT_TO_POINTER(0), NULL)); // Side-border hide/show dt_accel_register_global(NC_("accel", "toggle side borders"), GDK_KEY_Tab, 0); @@ -1089,8 +1072,7 @@ int dt_gui_gtk_init(dt_gui_gtk_t *gui) // View-switch dt_accel_register_global(NC_("accel", "switch view"), GDK_KEY_period, 0); - dt_accel_connect_global("switch view", - g_cclosure_new(G_CALLBACK(view_switch_key_accel_callback), NULL, NULL)); + dt_accel_connect_global("switch view", g_cclosure_new(G_CALLBACK(view_switch_key_accel_callback), NULL, NULL)); darktable.gui->reset = 0; @@ -1159,8 +1141,7 @@ void dt_gui_gtk_run(dt_gui_gtk_t *gui) GtkWidget *widget = dt_ui_center(darktable.gui->ui); GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); - darktable.gui->surface - = dt_cairo_image_surface_create(CAIRO_FORMAT_ARGB32, allocation.width, allocation.height); + darktable.gui->surface = dt_cairo_image_surface_create(CAIRO_FORMAT_ARGB32, allocation.width, allocation.height); // need to pre-configure views to avoid crash caused by draw coming before configure-event darktable.control->tabborder = 8; int tb = darktable.control->tabborder; @@ -1182,13 +1163,14 @@ static void configure_ppd_dpi(dt_gui_gtk_t *gui) { GtkWidget *widget = gui->ui->main_window; - // check if in HiDPI mode -#if (CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 13, 1)) +// check if in HiDPI mode +#if(CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 13, 1)) float screen_ppd_overwrite = dt_conf_get_float("screen_ppd_overwrite"); if(screen_ppd_overwrite > 0.0) { gui->ppd = screen_ppd_overwrite; - dt_print(DT_DEBUG_CONTROL, "[HiDPI] setting ppd to %f as specified in the configuration file\n", screen_ppd_overwrite); + dt_print(DT_DEBUG_CONTROL, "[HiDPI] setting ppd to %f as specified in the configuration file\n", + screen_ppd_overwrite); } else { @@ -1233,8 +1215,8 @@ static void configure_ppd_dpi(dt_gui_gtk_t *gui) else dt_print(DT_DEBUG_CONTROL, "[screen resolution] setting the screen resolution to %f dpi\n", gui->dpi); } - gui->dpi_factor - = gui->dpi / 96; // according to man xrandr and the docs of gdk_screen_set_resolution 96 is the default + gui->dpi_factor = gui->dpi + / 96; // according to man xrandr and the docs of gdk_screen_set_resolution 96 is the default } static gboolean _focus_in_out_event(GtkWidget *widget, GdkEvent *event, gpointer user_data) @@ -1296,8 +1278,8 @@ static void init_widgets(dt_gui_gtk_t *gui) gtk_widget_set_size_request(widget, -1, DT_PIXEL_APPLY_DPI(10)); gtk_widget_set_app_paintable(widget, TRUE); gtk_widget_set_events(widget, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK - | GDK_SCROLL_MASK); + | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK + | GDK_SCROLL_MASK); gtk_widget_show(widget); // Initializing the main table @@ -1310,8 +1292,8 @@ static void init_widgets(dt_gui_gtk_t *gui) gtk_widget_set_size_request(widget, -1, DT_PIXEL_APPLY_DPI(10)); gtk_widget_set_app_paintable(widget, TRUE); gtk_widget_set_events(widget, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK - | GDK_SCROLL_MASK); + | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK + | GDK_SCROLL_MASK); gtk_widget_show(widget); // Showing everything @@ -1352,8 +1334,8 @@ static void init_main_table(GtkWidget *container) gtk_widget_set_size_request(widget, DT_PIXEL_APPLY_DPI(10), -1); gtk_widget_set_app_paintable(widget, TRUE); gtk_widget_set_events(widget, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK - | GDK_SCROLL_MASK); + | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK + | GDK_SCROLL_MASK); gtk_grid_attach(GTK_GRID(container), widget, 0, 0, 1, 2); gtk_widget_show(widget); @@ -1364,8 +1346,8 @@ static void init_main_table(GtkWidget *container) gtk_widget_set_size_request(widget, DT_PIXEL_APPLY_DPI(10), -1); gtk_widget_set_app_paintable(widget, TRUE); gtk_widget_set_events(widget, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK - | GDK_SCROLL_MASK); + | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK + | GDK_SCROLL_MASK); gtk_grid_attach(GTK_GRID(container), widget, 4, 0, 1, 2); gtk_widget_show(widget); @@ -1388,8 +1370,8 @@ static void init_main_table(GtkWidget *container) gtk_widget_set_size_request(cda, DT_PIXEL_APPLY_DPI(50), DT_PIXEL_APPLY_DPI(200)); gtk_widget_set_app_paintable(cda, TRUE); gtk_widget_set_events(cda, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK - | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK - | GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK); + | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK + | GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK); gtk_widget_set_can_focus(cda, TRUE); gtk_widget_set_visible(cda, TRUE); @@ -1640,8 +1622,7 @@ static GtkWidget *_ui_init_panel_container_center(GtkWidget *container, gboolean /* create the scrolled window */ widget = gtk_scrolled_window_new(a[0], a[1]); gtk_widget_set_can_focus(widget, TRUE); - gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(widget), - left ? GTK_CORNER_TOP_LEFT : GTK_CORNER_TOP_RIGHT); + gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(widget), left ? GTK_CORNER_TOP_LEFT : GTK_CORNER_TOP_RIGHT); gtk_box_pack_start(GTK_BOX(container), widget, TRUE, TRUE, 0); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); @@ -1689,7 +1670,7 @@ static void _ui_init_panel_left(dt_ui_t *ui, GtkWidget *container) /* create left panel main widget and add it to ui */ widget = ui->panels[DT_UI_PANEL_LEFT] = dtgtk_side_panel_new(); gtk_widget_set_name(widget, "left"); -// gtk_widget_set_margin_left(widget, DT_PIXEL_APPLY_DPI(5)); // i prefer it with less blank space + // gtk_widget_set_margin_left(widget, DT_PIXEL_APPLY_DPI(5)); // i prefer it with less blank space gtk_grid_attach(GTK_GRID(container), widget, 1, 1, 1, 1); /* add top,center,bottom*/ @@ -1709,7 +1690,7 @@ static void _ui_init_panel_right(dt_ui_t *ui, GtkWidget *container) /* create left panel main widget and add it to ui */ widget = ui->panels[DT_UI_PANEL_RIGHT] = dtgtk_side_panel_new(); gtk_widget_set_name(widget, "right"); -// gtk_widget_set_margin_right(widget, DT_PIXEL_APPLY_DPI(5)); // i prefer it with less blank space + // gtk_widget_set_margin_right(widget, DT_PIXEL_APPLY_DPI(5)); // i prefer it with less blank space gtk_grid_attach(GTK_GRID(container), widget, 3, 1, 1, 1); /* add top,center,bottom*/ @@ -1832,7 +1813,12 @@ void dt_ellipsize_combo(GtkComboBox *cbox) typedef struct result_t { - enum {RESULT_NONE, RESULT_NO, RESULT_YES} result; + enum + { + RESULT_NONE, + RESULT_NO, + RESULT_YES + } result; GtkWidget *window; } result_t; @@ -1879,7 +1865,7 @@ gboolean dt_gui_show_standalone_yes_no_dialog(const char *title, const char *mar gtk_widget_set_margin_top(hbox, 10); gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); - result_t result = {.result = RESULT_NONE, .window = window}; + result_t result = {.result = RESULT_NONE, .window = window }; GtkWidget *button; diff --git a/src/gui/gtk.h b/src/gui/gtk.h index 1661a8910814..83a14adfef4a 100644 --- a/src/gui/gtk.h +++ b/src/gui/gtk.h @@ -27,7 +27,7 @@ /* helper macro that applies the DPI transformation to fixed pixel values. input should be defaulting to 96 * DPI */ -#define DT_PIXEL_APPLY_DPI(value) ((value) * darktable.gui->dpi_factor) +#define DT_PIXEL_APPLY_DPI(value) ((value)*darktable.gui->dpi_factor) typedef struct dt_gui_widgets_t { @@ -44,7 +44,8 @@ typedef struct dt_gui_widgets_t } dt_gui_widgets_t; -typedef enum dt_gui_color_t { +typedef enum dt_gui_color_t +{ DT_GUI_COLOR_BG = 0, DT_GUI_COLOR_DARKROOM_BG, DT_GUI_COLOR_DARKROOM_PREVIEW_BG, @@ -85,40 +86,51 @@ typedef struct dt_gui_gtk_t } dt_gui_gtk_t; -#if (CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 13, 1)) -static inline cairo_surface_t *dt_cairo_image_surface_create(cairo_format_t format, int width, int height) { - cairo_surface_t *cst = cairo_image_surface_create(format, width * darktable.gui->ppd, height * darktable.gui->ppd); +#if(CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 13, 1)) +static inline cairo_surface_t *dt_cairo_image_surface_create(cairo_format_t format, int width, int height) +{ + cairo_surface_t *cst + = cairo_image_surface_create(format, width * darktable.gui->ppd, height * darktable.gui->ppd); cairo_surface_set_device_scale(cst, darktable.gui->ppd, darktable.gui->ppd); return cst; } -static inline cairo_surface_t *dt_cairo_image_surface_create_for_data(unsigned char *data, cairo_format_t format, int width, int height, int stride) { +static inline cairo_surface_t *dt_cairo_image_surface_create_for_data(unsigned char *data, cairo_format_t format, + int width, int height, int stride) +{ cairo_surface_t *cst = cairo_image_surface_create_for_data(data, format, width, height, stride); cairo_surface_set_device_scale(cst, darktable.gui->ppd, darktable.gui->ppd); return cst; } -static inline cairo_surface_t *dt_cairo_image_surface_create_from_png(const char *filename) { +static inline cairo_surface_t *dt_cairo_image_surface_create_from_png(const char *filename) +{ cairo_surface_t *cst = cairo_image_surface_create_from_png(filename); cairo_surface_set_device_scale(cst, darktable.gui->ppd, darktable.gui->ppd); return cst; } -static inline int dt_cairo_image_surface_get_width(cairo_surface_t *surface) { +static inline int dt_cairo_image_surface_get_width(cairo_surface_t *surface) +{ return cairo_image_surface_get_width(surface) / darktable.gui->ppd; } -static inline int dt_cairo_image_surface_get_height(cairo_surface_t *surface) { +static inline int dt_cairo_image_surface_get_height(cairo_surface_t *surface) +{ return cairo_image_surface_get_height(surface) / darktable.gui->ppd; } -static inline cairo_surface_t *dt_gdk_cairo_surface_create_from_pixbuf(const GdkPixbuf *pixbuf, int scale, GdkWindow *for_window) { +static inline cairo_surface_t *dt_gdk_cairo_surface_create_from_pixbuf(const GdkPixbuf *pixbuf, int scale, + GdkWindow *for_window) +{ cairo_surface_t *cst = gdk_cairo_surface_create_from_pixbuf(pixbuf, scale, for_window); cairo_surface_set_device_scale(cst, darktable.gui->ppd, darktable.gui->ppd); return cst; } -static inline GdkPixbuf *dt_gdk_pixbuf_new_from_file_at_size(const char *filename, int width, int height, GError **error) { +static inline GdkPixbuf *dt_gdk_pixbuf_new_from_file_at_size(const char *filename, int width, int height, + GError **error) +{ return gdk_pixbuf_new_from_file_at_size(filename, width * darktable.gui->ppd, height * darktable.gui->ppd, error); } #else @@ -275,8 +287,8 @@ static inline void dt_ui_section_label_set(GtkWidget *label) gtk_widget_set_hexpand(label, TRUE); // not really needed, but it makes sure that parent containers expand g_object_set(G_OBJECT(label), "xalign", 1.0, (gchar *)0); // make the text right aligned gtk_widget_set_margin_bottom(label, DT_PIXEL_APPLY_DPI(10)); // gtk+ css doesn't support margins :( - gtk_widget_set_margin_start(label, DT_PIXEL_APPLY_DPI(30)); // gtk+ css doesn't support margins :( - gtk_widget_set_name(label, "section_label"); // make sure that we can style these easily + gtk_widget_set_margin_start(label, DT_PIXEL_APPLY_DPI(30)); // gtk+ css doesn't support margins :( + gtk_widget_set_name(label, "section_label"); // make sure that we can style these easily } static inline GtkWidget *dt_ui_section_label_new(const gchar *str) { diff --git a/src/gui/gtkentry.c b/src/gui/gtkentry.c index cc768e5f0bd4..913d338c33a2 100644 --- a/src/gui/gtkentry.c +++ b/src/gui/gtkentry.c @@ -224,8 +224,7 @@ const dt_gtkentry_completion_spec *dt_gtkentry_get_default_path_compl_list() * * @return g_malloc()'ed string. Must be free'd by the caller. */ -gchar *dt_gtkentry_build_completion_tooltip_text(const gchar *header, - const dt_gtkentry_completion_spec *compl_list) +gchar *dt_gtkentry_build_completion_tooltip_text(const gchar *header, const dt_gtkentry_completion_spec *compl_list) { size_t array_len = 0; for(dt_gtkentry_completion_spec const *p = compl_list; p->description != NULL; p++) array_len++; @@ -233,8 +232,7 @@ gchar *dt_gtkentry_build_completion_tooltip_text(const gchar *header, const gchar **l = lines; *l++ = header; - for(dt_gtkentry_completion_spec const *p = compl_list; p->description != NULL; p++, l++) - *l = _(p->description); + for(dt_gtkentry_completion_spec const *p = compl_list; p->description != NULL; p++, l++) *l = _(p->description); *l = NULL; diff --git a/src/gui/guides.c b/src/gui/guides.c index 9033da790f05..9325b34c4c20 100644 --- a/src/gui/guides.c +++ b/src/gui/guides.c @@ -38,8 +38,8 @@ static void dt_guides_q_rect(dt_QRect_t *R1, float left, float top, float width, } -static void dt_guides_draw_simple_grid(cairo_t *cr, const float x, const float y, const float w, - const float h, float zoom_scale) +static void dt_guides_draw_simple_grid(cairo_t *cr, const float x, const float y, const float w, const float h, + float zoom_scale) { float right = x + w; float bottom = y + h; @@ -76,8 +76,8 @@ static void dt_guides_draw_diagonal_method(cairo_t *cr, const float x, const flo } -static void dt_guides_draw_rules_of_thirds(cairo_t *cr, const float left, const float top, - const float width, const float height) +static void dt_guides_draw_rules_of_thirds(cairo_t *cr, const float left, const float top, const float width, + const float height) { const float right = left + width, bottom = top + height; const float x_3 = width / 3.0, y_3 = height / 3.0; @@ -91,7 +91,7 @@ static void dt_guides_draw_rules_of_thirds(cairo_t *cr, const float left, const static void dt_guides_draw_harmonious_triangles(cairo_t *cr, const float left, const float top, const float width, - const float height/*, const float dst*/) + const float height /*, const float dst*/) { int dst = (int)((height * cos(atan(width / height)) / (cos(atan(height / width))))); @@ -179,7 +179,8 @@ static void dt_guides_draw_metering(cairo_t *cr, const float x, const float y, c #define RADIANS(degrees) ((degrees) * (M_PI / 180.)) static void dt_guides_draw_golden_mean(cairo_t *cr, dt_QRect_t *R1, dt_QRect_t *R2, dt_QRect_t *R3, dt_QRect_t *R4, dt_QRect_t *R5, dt_QRect_t *R6, dt_QRect_t *R7, gboolean goldenSection, - gboolean goldenTriangle, gboolean goldenSpiralSection, gboolean goldenSpiral) + gboolean goldenTriangle, gboolean goldenSpiralSection, + gboolean goldenSpiral) { // Drawing Golden sections. if(goldenSection) @@ -280,44 +281,37 @@ typedef struct _golden_mean_t gboolean golden_spiral; } _golden_mean_t; -static void _guides_draw_grid(cairo_t *cr, const float x, const float y, - const float w, const float h, +static void _guides_draw_grid(cairo_t *cr, const float x, const float y, const float w, const float h, const float zoom_scale, void *user_data) { dt_guides_draw_simple_grid(cr, x, y, w, h, zoom_scale); } -static void _guides_draw_rules_of_thirds(cairo_t *cr, const float x, const float y, - const float w, const float h, +static void _guides_draw_rules_of_thirds(cairo_t *cr, const float x, const float y, const float w, const float h, const float zoom_scale, void *user_data) { dt_guides_draw_rules_of_thirds(cr, x, y, w, h); } -static void _guides_draw_metering(cairo_t *cr, const float x, const float y, - const float w, const float h, +static void _guides_draw_metering(cairo_t *cr, const float x, const float y, const float w, const float h, const float zoom_scale, void *user_data) { dt_guides_draw_metering(cr, x, y, w, h); } -static void _guides_draw_perspective(cairo_t *cr, const float x, const float y, - const float w, const float h, +static void _guides_draw_perspective(cairo_t *cr, const float x, const float y, const float w, const float h, const float zoom_scale, void *user_data) { dt_guides_draw_perspective(cr, x, y, w, h); } -static void _guides_draw_diagonal_method(cairo_t *cr, const float x, const float y, - const float w, const float h, +static void _guides_draw_diagonal_method(cairo_t *cr, const float x, const float y, const float w, const float h, const float zoom_scale, void *user_data) { dt_guides_draw_diagonal_method(cr, x, y, w, h); } -static void _guides_draw_harmonious_triangles(cairo_t *cr, const float x, const float y, - const float w, const float h, - const float zoom_scale, void *user_data) +static void _guides_draw_harmonious_triangles(cairo_t *cr, const float x, const float y, const float w, + const float h, const float zoom_scale, void *user_data) { dt_guides_draw_harmonious_triangles(cr, x, y, w, h); } -static void _guides_draw_golden_mean(cairo_t *cr, const float x, const float y, - const float w, const float h, +static void _guides_draw_golden_mean(cairo_t *cr, const float x, const float y, const float w, const float h, const float zoom_scale, void *user_data) { _golden_mean_t *d = (_golden_mean_t *)user_data; @@ -337,8 +331,7 @@ static void _guides_draw_golden_mean(cairo_t *cr, const float x, const float y, dt_guides_q_rect(&R3, w_2 - R2.width * INVPHI, -h_2, R2.width * INVPHI, h - R2.height); dt_guides_q_rect(&R4, R2.left, R1.top, R3.left - R2.left, R3.height * INVPHI); dt_guides_q_rect(&R5, R4.left, R4.bottom, R4.width * INVPHI, R3.height - R4.height); - dt_guides_q_rect(&R6, R5.left + R5.width, R5.bottom - R5.height * INVPHI, R3.left - R5.right, - R5.height * INVPHI); + dt_guides_q_rect(&R6, R5.left + R5.width, R5.bottom - R5.height * INVPHI, R3.left - R5.right, R5.height * INVPHI); dt_guides_q_rect(&R7, R6.right - R6.width * INVPHI, R4.bottom, R6.width * INVPHI, R5.height - R6.height); dt_guides_draw_golden_mean(cr, &R1, &R2, &R3, &R4, &R5, &R6, &R7, d->golden_section, d->golden_triangle, @@ -380,10 +373,8 @@ static GtkWidget *_guides_gui_golden_mean(dt_iop_module_t *self, void *user_data } -static void _guides_add_guide(GList **list, const char *name, - dt_guides_draw_callback draw, - dt_guides_widget_callback widget, - void *user_data, GDestroyNotify free) +static void _guides_add_guide(GList **list, const char *name, dt_guides_draw_callback draw, + dt_guides_widget_callback widget, void *user_data, GDestroyNotify free) { dt_guides_t *guide = (dt_guides_t *)malloc(sizeof(dt_guides_t)); g_strlcpy(guide->name, name, sizeof(guide->name)); @@ -394,7 +385,8 @@ static void _guides_add_guide(GList **list, const char *name, *list = g_list_append(*list, guide); } -void dt_guides_add_guide(const char *name, dt_guides_draw_callback draw, dt_guides_widget_callback widget, void *user_data, GDestroyNotify free) +void dt_guides_add_guide(const char *name, dt_guides_draw_callback draw, dt_guides_widget_callback widget, + void *user_data, GDestroyNotify free) { _guides_add_guide(&darktable.guides, name, draw, widget, user_data, free); } @@ -404,16 +396,19 @@ GList *dt_guides_init() GList *guides = NULL; - _guides_add_guide(&guides, _("grid"), _guides_draw_grid, NULL, NULL, NULL); // TODO: make the number of lines configurable with a slider? + _guides_add_guide(&guides, _("grid"), _guides_draw_grid, NULL, NULL, + NULL); // TODO: make the number of lines configurable with a slider? _guides_add_guide(&guides, _("rules of thirds"), _guides_draw_rules_of_thirds, NULL, NULL, NULL); _guides_add_guide(&guides, _("metering"), _guides_draw_metering, NULL, NULL, NULL); - _guides_add_guide(&guides, _("perspective"), _guides_draw_perspective, NULL, NULL, NULL); // TODO: make the number of lines configurable with a slider? + _guides_add_guide(&guides, _("perspective"), _guides_draw_perspective, NULL, NULL, + NULL); // TODO: make the number of lines configurable with a slider? _guides_add_guide(&guides, _("diagonal method"), _guides_draw_diagonal_method, NULL, NULL, NULL); _guides_add_guide(&guides, _("harmonious triangles"), _guides_draw_harmonious_triangles, NULL, NULL, NULL); { _golden_mean_t *user_data = (_golden_mean_t *)malloc(sizeof(_golden_mean_t)); _golden_mean_set_data(user_data, dt_conf_get_int("plugins/darkroom/clipping/golden_extras")); - _guides_add_guide(&guides, _("golden mean"), _guides_draw_golden_mean, _guides_gui_golden_mean, user_data, free); + _guides_add_guide(&guides, _("golden mean"), _guides_draw_golden_mean, _guides_gui_golden_mean, user_data, + free); } return guides; diff --git a/src/gui/guides.h b/src/gui/guides.h index c9cafccedfae..b8274ab65e62 100644 --- a/src/gui/guides.h +++ b/src/gui/guides.h @@ -20,8 +20,7 @@ #include "develop/imageop.h" -typedef void (*dt_guides_draw_callback)(cairo_t *cr, const float x, const float y, - const float w, const float h, +typedef void (*dt_guides_draw_callback)(cairo_t *cr, const float x, const float y, const float w, const float h, const float zoom_scale, void *user_data); typedef GtkWidget *(*dt_guides_widget_callback)(dt_iop_module_t *self, void *user_data); @@ -38,7 +37,8 @@ typedef struct dt_guides_t GList *dt_guides_init(); void dt_guides_cleanup(GList *guides); -void dt_guides_add_guide(const char *name, dt_guides_draw_callback draw, dt_guides_widget_callback widget, void *user_data, GDestroyNotify free); +void dt_guides_add_guide(const char *name, dt_guides_draw_callback draw, dt_guides_widget_callback widget, + void *user_data, GDestroyNotify free); // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh // vim: shiftwidth=2 expandtab tabstop=2 cindent diff --git a/src/gui/hist_dialog.c b/src/gui/hist_dialog.c index 0cf5317f02d3..7b5fb71d8528 100644 --- a/src/gui/hist_dialog.c +++ b/src/gui/hist_dialog.c @@ -154,8 +154,7 @@ int dt_gui_hist_dialog_new(dt_gui_hist_dialog_t *d, int imgid, gboolean iscopy) /* create the list of items */ d->items = GTK_TREE_VIEW(gtk_tree_view_new()); - GtkListStore *liststore - = gtk_list_store_new(DT_HIST_ITEMS_NUM_COLS, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_UINT); + GtkListStore *liststore = gtk_list_store_new(DT_HIST_ITEMS_NUM_COLS, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_UINT); /* enabled */ GtkCellRenderer *renderer = gtk_cell_renderer_toggle_new(); @@ -190,8 +189,8 @@ int dt_gui_hist_dialog_new(dt_gui_hist_dialog_t *d, int imgid, gboolean iscopy) gtk_list_store_append(GTK_LIST_STORE(liststore), &iter); gtk_list_store_set(GTK_LIST_STORE(liststore), &iter, DT_HIST_ITEMS_COL_ENABLED, - iscopy ? TRUE : _gui_is_set(d->selops, item->num), DT_HIST_ITEMS_COL_NAME, - item->name, DT_HIST_ITEMS_COL_NUM, (guint)item->num, -1); + iscopy ? TRUE : _gui_is_set(d->selops, item->num), DT_HIST_ITEMS_COL_NAME, item->name, + DT_HIST_ITEMS_COL_NUM, (guint)item->num, -1); } while((items = g_list_next(items))); g_list_free_full(items, dt_history_item_free); diff --git a/src/gui/preferences.c b/src/gui/preferences.c index 1950513a146a..029ce06205b3 100644 --- a/src/gui/preferences.c +++ b/src/gui/preferences.c @@ -67,16 +67,13 @@ static const char *dt_gui_presets_exposure_value_str[] "1\"", "2\"", "4\"", "8\"", "15\"", "30\"", "60\"", "+" }; static const int dt_gui_presets_aperture_value_cnt = 19; static const float dt_gui_presets_aperture_value[] - = { 0, 0.5, 0.7, 1.0, 1.4, 2.0, 2.8, 4.0, 5.6, 8.0, - 11.0, 16.0, 22.0, 32.0, 45.0, 64.0, 90.0, 128.0, FLT_MAX }; + = { 0, 0.5, 0.7, 1.0, 1.4, 2.0, 2.8, 4.0, 5.6, 8.0, 11.0, 16.0, 22.0, 32.0, 45.0, 64.0, 90.0, 128.0, FLT_MAX }; static const char *dt_gui_presets_aperture_value_str[] = { "f/0", "f/0.5", "f/0.7", "f/1.0", "f/1.4", "f/2", "f/2.8", "f/4", "f/5.6", "f/8", "f/11", "f/16", "f/22", "f/32", "f/45", "f/64", "f/90", "f/128", "f/+" }; // format string and corresponding flag stored into the database -static const char *dt_gui_presets_format_value_str[3] = { N_("normal images"), - N_("raw"), - N_("HDR")}; +static const char *dt_gui_presets_format_value_str[3] = { N_("normal images"), N_("raw"), N_("HDR") }; static const int dt_gui_presets_format_flag[3] = { FOR_LDR, FOR_RAW, FOR_HDR }; // Values for the accelerators/presets treeview @@ -128,8 +125,7 @@ static void tree_row_activated_presets(GtkTreeView *tree, GtkTreePath *path, Gtk static void tree_selection_changed(GtkTreeSelection *selection, gpointer data); static gboolean tree_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data); static gboolean tree_key_press_presets(GtkWidget *widget, GdkEventKey *event, gpointer data); -static gboolean prefix_search(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, - gpointer d); +static gboolean prefix_search(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer d); static void edit_preset(GtkTreeView *tree, const gint rowid, const gchar *name, const gchar *module); static void edit_preset_response(GtkDialog *dialog, gint response_id, dt_gui_presets_edit_dialog_t *g); @@ -248,8 +244,8 @@ void dt_gui_preferences_show() { GtkWidget *win = dt_ui_main_window(darktable.gui->ui); _preferences_dialog = gtk_dialog_new_with_buttons(_("darktable preferences"), GTK_WINDOW(win), - GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL, - _("close"), GTK_RESPONSE_ACCEPT, NULL); + GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL, _("close"), + GTK_RESPONSE_ACCEPT, NULL); #ifdef GDK_WINDOWING_QUARTZ dt_osx_disallow_fullscreen(_preferences_dialog); #endif @@ -271,7 +267,7 @@ void dt_gui_preferences_show() init_tab_accels(notebook); init_tab_presets(notebook); #ifdef USE_LUA - GtkGrid* lua_grid = init_tab_lua(_preferences_dialog, notebook); + GtkGrid *lua_grid = init_tab_lua(_preferences_dialog, notebook); #endif gtk_widget_show_all(_preferences_dialog); (void)gtk_dialog_run(GTK_DIALOG(_preferences_dialog)); @@ -311,10 +307,9 @@ static void tree_insert_presets(GtkTreeStore *tree_model) cairo_surface_flush(lock_cst); guchar *data = cairo_image_surface_get_data(lock_cst); dt_draw_cairo_to_gdk_pixbuf(data, DT_PIXEL_APPLY_DPI(ICON_SIZE), DT_PIXEL_APPLY_DPI(ICON_SIZE)); - GdkPixbuf *lock_pixbuf = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, TRUE, 8, - DT_PIXEL_APPLY_DPI(ICON_SIZE), DT_PIXEL_APPLY_DPI(ICON_SIZE), - cairo_image_surface_get_stride(lock_cst), - cairo_destroy_from_pixbuf, lock_cr); + GdkPixbuf *lock_pixbuf = gdk_pixbuf_new_from_data( + data, GDK_COLORSPACE_RGB, TRUE, 8, DT_PIXEL_APPLY_DPI(ICON_SIZE), DT_PIXEL_APPLY_DPI(ICON_SIZE), + cairo_image_surface_get_stride(lock_cst), cairo_destroy_from_pixbuf, lock_cr); // check mark cairo_surface_t *check_cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, DT_PIXEL_APPLY_DPI(ICON_SIZE), @@ -325,10 +320,9 @@ static void tree_insert_presets(GtkTreeStore *tree_model) cairo_surface_flush(check_cst); data = cairo_image_surface_get_data(check_cst); dt_draw_cairo_to_gdk_pixbuf(data, DT_PIXEL_APPLY_DPI(ICON_SIZE), DT_PIXEL_APPLY_DPI(ICON_SIZE)); - GdkPixbuf *check_pixbuf = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, TRUE, 8, - DT_PIXEL_APPLY_DPI(ICON_SIZE), DT_PIXEL_APPLY_DPI(ICON_SIZE), - cairo_image_surface_get_stride(check_cst), - cairo_destroy_from_pixbuf, check_cr); + GdkPixbuf *check_pixbuf = gdk_pixbuf_new_from_data( + data, GDK_COLORSPACE_RGB, TRUE, 8, DT_PIXEL_APPLY_DPI(ICON_SIZE), DT_PIXEL_APPLY_DPI(ICON_SIZE), + cairo_image_surface_get_stride(check_cst), cairo_destroy_from_pixbuf, check_cr); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT rowid, name, operation, autoapply, model, maker, lens, iso_min, " @@ -397,22 +391,21 @@ static void tree_insert_presets(GtkTreeStore *tree_model) if(g_strcmp0(last_module, operation) != 0) { gtk_tree_store_append(tree_model, &iter, NULL); - gtk_tree_store_set(tree_model, &iter, P_ROWID_COLUMN, 0, P_OPERATION_COLUMN, "", P_MODULE_COLUMN, - _(module), P_EDITABLE_COLUMN, NULL, P_NAME_COLUMN, "", P_MODEL_COLUMN, "", - P_MAKER_COLUMN, "", P_LENS_COLUMN, "", P_ISO_COLUMN, "", P_EXPOSURE_COLUMN, "", - P_APERTURE_COLUMN, "", P_FOCAL_LENGTH_COLUMN, "", P_AUTOAPPLY_COLUMN, NULL, -1); + gtk_tree_store_set(tree_model, &iter, P_ROWID_COLUMN, 0, P_OPERATION_COLUMN, "", P_MODULE_COLUMN, _(module), + P_EDITABLE_COLUMN, NULL, P_NAME_COLUMN, "", P_MODEL_COLUMN, "", P_MAKER_COLUMN, "", + P_LENS_COLUMN, "", P_ISO_COLUMN, "", P_EXPOSURE_COLUMN, "", P_APERTURE_COLUMN, "", + P_FOCAL_LENGTH_COLUMN, "", P_AUTOAPPLY_COLUMN, NULL, -1); g_free(last_module); last_module = g_strdup(operation); parent = iter; } gtk_tree_store_append(tree_model, &iter, &parent); - gtk_tree_store_set(tree_model, &iter, P_ROWID_COLUMN, rowid, P_OPERATION_COLUMN, operation, - P_MODULE_COLUMN, "", P_EDITABLE_COLUMN, writeprotect ? lock_pixbuf : NULL, - P_NAME_COLUMN, name, P_MODEL_COLUMN, model, P_MAKER_COLUMN, maker, P_LENS_COLUMN, lens, - P_ISO_COLUMN, iso, P_EXPOSURE_COLUMN, exposure, P_APERTURE_COLUMN, aperture, - P_FOCAL_LENGTH_COLUMN, focal_length, P_AUTOAPPLY_COLUMN, - autoapply ? check_pixbuf : NULL, -1); + gtk_tree_store_set(tree_model, &iter, P_ROWID_COLUMN, rowid, P_OPERATION_COLUMN, operation, P_MODULE_COLUMN, + "", P_EDITABLE_COLUMN, writeprotect ? lock_pixbuf : NULL, P_NAME_COLUMN, name, + P_MODEL_COLUMN, model, P_MAKER_COLUMN, maker, P_LENS_COLUMN, lens, P_ISO_COLUMN, iso, + P_EXPOSURE_COLUMN, exposure, P_APERTURE_COLUMN, aperture, P_FOCAL_LENGTH_COLUMN, + focal_length, P_AUTOAPPLY_COLUMN, autoapply ? check_pixbuf : NULL, -1); g_free(focal_length); g_free(aperture); @@ -492,8 +485,8 @@ static void init_tab_presets(GtkWidget *book) gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); renderer = gtk_cell_renderer_text_new(); - column = gtk_tree_view_column_new_with_attributes(_("focal length"), renderer, "text", - P_FOCAL_LENGTH_COLUMN, NULL); + column + = gtk_tree_view_column_new_with_attributes(_("focal length"), renderer, "text", P_FOCAL_LENGTH_COLUMN, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); renderer = gtk_cell_renderer_pixbuf_new(); @@ -688,8 +681,7 @@ static void tree_insert_rec(GtkTreeStore *model, GtkTreeIter *parent, const gcha if(!found) { gtk_tree_store_append(model, &iter, parent); - gtk_tree_store_set(model, &iter, A_ACCEL_COLUMN, node, A_BINDING_COLUMN, "", A_TRANS_COLUMN, trans_node, - -1); + gtk_tree_store_set(model, &iter, A_ACCEL_COLUMN, node, A_BINDING_COLUMN, "", A_TRANS_COLUMN, trans_node, -1); } /* recurse further down the path */ @@ -836,8 +828,8 @@ static void tree_row_activated_presets(GtkTreeView *tree, GtkTreePath *path, Gtk gint rowid; gchar *name, *operation; GdkPixbuf *editable; - gtk_tree_model_get(model, &iter, P_ROWID_COLUMN, &rowid, P_NAME_COLUMN, &name, P_OPERATION_COLUMN, - &operation, P_EDITABLE_COLUMN, &editable, -1); + gtk_tree_model_get(model, &iter, P_ROWID_COLUMN, &rowid, P_NAME_COLUMN, &name, P_OPERATION_COLUMN, &operation, + P_EDITABLE_COLUMN, &editable, -1); if(editable == NULL) edit_preset(tree, rowid, name, operation); else @@ -873,8 +865,7 @@ static void tree_row_activated_accels(GtkTreeView *tree, GtkTreePath *path, GtkT path_to_accel(model, path, accel_path, sizeof(accel_path)); // Setting the notification text - gtk_tree_store_set(GTK_TREE_STORE(model), &iter, A_BINDING_COLUMN, _("press key combination to remap..."), - -1); + gtk_tree_store_set(GTK_TREE_STORE(model), &iter, A_BINDING_COLUMN, _("press key combination to remap..."), -1); // Activating remapping darktable.control->accel_remap_str = accel_path; @@ -931,8 +922,8 @@ static gboolean tree_key_press(GtkWidget *widget, GdkEventKey *event, gpointer d if(darktable.control->accel_remap_str) { // Change the accel map entry - if(gtk_accel_map_change_entry(darktable.control->accel_remap_str, event->keyval, - event->state & KEY_STATE_MASK, TRUE)) + if(gtk_accel_map_change_entry(darktable.control->accel_remap_str, event->keyval, event->state & KEY_STATE_MASK, + TRUE)) { // If it succeeded delete any conflicting accelerators // First locate the accel list entry @@ -963,8 +954,7 @@ static gboolean tree_key_press(GtkWidget *widget, GdkEventKey *event, gpointer d // If a leaf node is selected, clear that accelerator // If nothing is selected, or branch node selected, just return - if(!gtk_tree_selection_get_selected(selection, &model, &iter) - || gtk_tree_model_iter_has_child(model, &iter)) + if(!gtk_tree_selection_get_selected(selection, &model, &iter) || gtk_tree_model_iter_has_child(model, &iter)) return FALSE; // Otherwise, construct the proper accelerator path and delete its entry @@ -1002,24 +992,23 @@ static gboolean tree_key_press_presets(GtkWidget *widget, GdkEventKey *event, gp // If a leaf node is selected, delete that preset // If nothing is selected, or branch node selected, just return - if(!gtk_tree_selection_get_selected(selection, &model, &iter) - || gtk_tree_model_iter_has_child(model, &iter)) + if(!gtk_tree_selection_get_selected(selection, &model, &iter) || gtk_tree_model_iter_has_child(model, &iter)) return FALSE; // For leaf nodes, open delete confirmation window if the preset is not writeprotected gint rowid; gchar *name; GdkPixbuf *editable; - gtk_tree_model_get(model, &iter, P_ROWID_COLUMN, &rowid, P_NAME_COLUMN, &name, P_EDITABLE_COLUMN, - &editable, -1); + gtk_tree_model_get(model, &iter, P_ROWID_COLUMN, &rowid, P_NAME_COLUMN, &name, P_EDITABLE_COLUMN, &editable, + -1); if(editable == NULL) { sqlite3_stmt *stmt; GtkWidget *window = dt_ui_main_window(darktable.gui->ui); - GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, - _("do you really want to delete the preset `%s'?"), name); + GtkWidget *dialog + = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, + GTK_BUTTONS_YES_NO, _("do you really want to delete the preset `%s'?"), name); gtk_window_set_title(GTK_WINDOW(dialog), _("delete preset?")); if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_YES) { @@ -1056,9 +1045,9 @@ static void import_export(GtkButton *button, gpointer data) if(data) { // Non-zero value indicates export - chooser = gtk_file_chooser_dialog_new(_("select file to export"), NULL, GTK_FILE_CHOOSER_ACTION_SAVE, - _("_cancel"), GTK_RESPONSE_CANCEL, _("_save"), GTK_RESPONSE_ACCEPT, - NULL); + chooser + = gtk_file_chooser_dialog_new(_("select file to export"), NULL, GTK_FILE_CHOOSER_ACTION_SAVE, _("_cancel"), + GTK_RESPONSE_CANCEL, _("_save"), GTK_RESPONSE_ACCEPT, NULL); #ifdef GDK_WINDOWING_QUARTZ dt_osx_disallow_fullscreen(chooser); #endif @@ -1082,9 +1071,9 @@ static void import_export(GtkButton *button, gpointer data) else { // Zero value indicates import - chooser = gtk_file_chooser_dialog_new(_("select file to import"), NULL, GTK_FILE_CHOOSER_ACTION_OPEN, - _("_cancel"), GTK_RESPONSE_CANCEL, _("_open"), GTK_RESPONSE_ACCEPT, - NULL); + chooser + = gtk_file_chooser_dialog_new(_("select file to import"), NULL, GTK_FILE_CHOOSER_ACTION_OPEN, _("_cancel"), + GTK_RESPONSE_CANCEL, _("_open"), GTK_RESPONSE_ACCEPT, NULL); #ifdef GDK_WINDOWING_QUARTZ dt_osx_disallow_fullscreen(chooser); #endif @@ -1157,8 +1146,7 @@ static void restore_defaults(GtkButton *button, gpointer data) gtk_widget_destroy(message); } -static gboolean prefix_search(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, - gpointer d) +static gboolean prefix_search(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer d) { gchar *row_data; @@ -1256,8 +1244,7 @@ static void edit_preset(GtkTreeView *tree, const gint rowid, const gchar *name, gtk_container_add(content_area, GTK_WIDGET(box)); GtkWidget *label; - dt_gui_presets_edit_dialog_t *g - = (dt_gui_presets_edit_dialog_t *)malloc(sizeof(dt_gui_presets_edit_dialog_t)); + dt_gui_presets_edit_dialog_t *g = (dt_gui_presets_edit_dialog_t *)malloc(sizeof(dt_gui_presets_edit_dialog_t)); // g->module = module; g->rowid = rowid; g->tree = tree; @@ -1268,13 +1255,12 @@ static void edit_preset(GtkTreeView *tree, const gint rowid, const gchar *name, gtk_box_pack_start(box, GTK_WIDGET(g->description), FALSE, FALSE, 0); gtk_widget_set_tooltip_text(GTK_WIDGET(g->description), _("description or further information")); - g->autoapply - = GTK_CHECK_BUTTON(gtk_check_button_new_with_label(_("auto apply this preset to matching images"))); + g->autoapply = GTK_CHECK_BUTTON(gtk_check_button_new_with_label(_("auto apply this preset to matching images"))); gtk_box_pack_start(box, GTK_WIDGET(g->autoapply), FALSE, FALSE, 0); - g->filter - = GTK_CHECK_BUTTON(gtk_check_button_new_with_label(_("only show this preset for matching images"))); - gtk_widget_set_tooltip_text(GTK_WIDGET(g->filter), - _("be very careful with this option. this might be the last time you see your preset.")); + g->filter = GTK_CHECK_BUTTON(gtk_check_button_new_with_label(_("only show this preset for matching images"))); + gtk_widget_set_tooltip_text( + GTK_WIDGET(g->filter), + _("be very careful with this option. this might be the last time you see your preset.")); gtk_box_pack_start(box, GTK_WIDGET(g->filter), FALSE, FALSE, 0); g_signal_connect(G_OBJECT(g->autoapply), "toggled", G_CALLBACK(check_buttons_activated), g); g_signal_connect(G_OBJECT(g->filter), "toggled", G_CALLBACK(check_buttons_activated), g); @@ -1321,7 +1307,8 @@ static void edit_preset(GtkTreeView *tree, const gint rowid, const gchar *name, gtk_spin_button_set_digits(g->iso_max, 0); gtk_grid_attach(GTK_GRID(g->details), label, 0, line++, 1, 1); gtk_grid_attach_next_to(GTK_GRID(g->details), GTK_WIDGET(g->iso_min), label, GTK_POS_RIGHT, 1, 1); - gtk_grid_attach_next_to(GTK_GRID(g->details), GTK_WIDGET(g->iso_max), GTK_WIDGET(g->iso_min), GTK_POS_RIGHT, 1, 1); + gtk_grid_attach_next_to(GTK_GRID(g->details), GTK_WIDGET(g->iso_max), GTK_WIDGET(g->iso_min), GTK_POS_RIGHT, 1, + 1); // exposure label = gtk_label_new(_("exposure")); @@ -1364,7 +1351,8 @@ static void edit_preset(GtkTreeView *tree, const gint rowid, const gchar *name, gtk_spin_button_set_digits(g->focal_length_max, 0); gtk_grid_attach(GTK_GRID(g->details), label, 0, line++, 1, 1); gtk_grid_attach_next_to(GTK_GRID(g->details), GTK_WIDGET(g->focal_length_min), label, GTK_POS_RIGHT, 1, 1); - gtk_grid_attach_next_to(GTK_GRID(g->details), GTK_WIDGET(g->focal_length_max), GTK_WIDGET(g->focal_length_min), GTK_POS_RIGHT, 1, 1); + gtk_grid_attach_next_to(GTK_GRID(g->details), GTK_WIDGET(g->focal_length_max), GTK_WIDGET(g->focal_length_min), + GTK_POS_RIGHT, 1, 1); gtk_widget_set_hexpand(GTK_WIDGET(g->focal_length_min), TRUE); gtk_widget_set_hexpand(GTK_WIDGET(g->focal_length_max), TRUE); @@ -1445,14 +1433,10 @@ static void edit_preset_response(GtkDialog *dialog, gint response_id, dt_gui_pre DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 4, gtk_entry_get_text(g->lens), -1, SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 5, gtk_spin_button_get_value(g->iso_min)); DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 6, gtk_spin_button_get_value(g->iso_max)); - DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 7, - dt_gui_presets_exposure_value[dt_bauhaus_combobox_get(g->exposure_min)]); - DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 8, - dt_gui_presets_exposure_value[dt_bauhaus_combobox_get(g->exposure_max)]); - DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 9, - dt_gui_presets_aperture_value[dt_bauhaus_combobox_get(g->aperture_min)]); - DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 10, - dt_gui_presets_aperture_value[dt_bauhaus_combobox_get(g->aperture_max)]); + DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 7, dt_gui_presets_exposure_value[dt_bauhaus_combobox_get(g->exposure_min)]); + DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 8, dt_gui_presets_exposure_value[dt_bauhaus_combobox_get(g->exposure_max)]); + DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 9, dt_gui_presets_aperture_value[dt_bauhaus_combobox_get(g->aperture_min)]); + DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 10, dt_gui_presets_aperture_value[dt_bauhaus_combobox_get(g->aperture_max)]); DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 11, gtk_spin_button_get_value(g->focal_length_min)); DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 12, gtk_spin_button_get_value(g->focal_length_max)); DT_DEBUG_SQLITE3_BIND_INT(stmt, 13, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g->autoapply))); diff --git a/src/gui/presets.c b/src/gui/presets.c index 2335acbabb75..2cf7a60dd0de 100644 --- a/src/gui/presets.c +++ b/src/gui/presets.c @@ -42,16 +42,13 @@ static const char *dt_gui_presets_exposure_value_str[] "1\"", "2\"", "4\"", "8\"", "15\"", "30\"", "60\"", "+" }; static const int dt_gui_presets_aperture_value_cnt = 19; static const float dt_gui_presets_aperture_value[] - = { 0, 0.5, 0.7, 1.0, 1.4, 2.0, 2.8, 4.0, 5.6, 8.0, - 11.0, 16.0, 22.0, 32.0, 45.0, 64.0, 90.0, 128.0, FLT_MAX }; + = { 0, 0.5, 0.7, 1.0, 1.4, 2.0, 2.8, 4.0, 5.6, 8.0, 11.0, 16.0, 22.0, 32.0, 45.0, 64.0, 90.0, 128.0, FLT_MAX }; static const char *dt_gui_presets_aperture_value_str[] = { "f/0", "f/0.5", "f/0.7", "f/1.0", "f/1.4", "f/2", "f/2.8", "f/4", "f/5.6", "f/8", "f/11", "f/16", "f/22", "f/32", "f/45", "f/64", "f/90", "f/128", "f/+" }; // format string and corresponding flag stored into the database -static const char *dt_gui_presets_format_value_str[3] = { N_("normal images"), - N_("raw"), - N_("HDR")}; +static const char *dt_gui_presets_format_value_str[3] = { N_("normal images"), N_("raw"), N_("HDR") }; static const int dt_gui_presets_format_flag[3] = { FOR_LDR, FOR_RAW, FOR_HDR }; typedef struct dt_gui_presets_edit_dialog_t @@ -79,8 +76,8 @@ void dt_gui_presets_init() NULL, NULL); } -void dt_gui_presets_add_generic(const char *name, dt_dev_operation_t op, const int32_t version, - const void *params, const int32_t params_size, const int32_t enabled) +void dt_gui_presets_add_generic(const char *name, dt_dev_operation_t op, const int32_t version, const void *params, + const int32_t params_size, const int32_t enabled) { sqlite3_stmt *stmt; dt_develop_blend_params_t default_blendop_params @@ -92,10 +89,10 @@ void dt_gui_presets_add_generic(const char *name, dt_dev_operation_t op, const i 0, 0.0f, { 0, 0, 0, 0 }, - { 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, - 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, - 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, - 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f } }; + { 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, + 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, + 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, + 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f } }; DT_DEBUG_SQLITE3_PREPARE_V2( dt_database_get(darktable.db), @@ -113,8 +110,7 @@ void dt_gui_presets_add_generic(const char *name, dt_dev_operation_t op, const i DT_DEBUG_SQLITE3_BIND_INT(stmt, 3, version); DT_DEBUG_SQLITE3_BIND_BLOB(stmt, 4, params, params_size, SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_INT(stmt, 5, enabled); - DT_DEBUG_SQLITE3_BIND_BLOB(stmt, 6, &default_blendop_params, sizeof(dt_develop_blend_params_t), - SQLITE_TRANSIENT); + DT_DEBUG_SQLITE3_BIND_BLOB(stmt, 6, &default_blendop_params, sizeof(dt_develop_blend_params_t), SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_INT(stmt, 7, dt_develop_blend_version()); sqlite3_step(stmt); sqlite3_finalize(stmt); @@ -164,8 +160,8 @@ static gchar *get_active_preset_name(dt_iop_module_t *module) int32_t bl_params_size = sqlite3_column_bytes(stmt, 2); int enabled = sqlite3_column_int(stmt, 3); if(!memcmp(module->params, op_params, MIN(op_params_size, module->params_size)) - && !memcmp(module->blend_params, blendop_params, - MIN(bl_params_size, sizeof(dt_develop_blend_params_t))) && module->enabled == enabled) + && !memcmp(module->blend_params, blendop_params, MIN(bl_params_size, sizeof(dt_develop_blend_params_t))) + && module->enabled == enabled) { name = g_strdup((char *)sqlite3_column_text(stmt, 0)); break; @@ -236,8 +232,8 @@ static void edit_preset_response(GtkDialog *dialog, gint response_id, dt_gui_pre // name: DT_DEBUG_SQLITE3_PREPARE_V2( dt_database_get(darktable.db), - "SELECT name FROM data.presets WHERE name = ?1 AND operation=?2 AND op_version=?3 LIMIT 1", - -1, &stmt, NULL); + "SELECT name FROM data.presets WHERE name = ?1 AND operation=?2 AND op_version=?3 LIMIT 1", -1, &stmt, + NULL); DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, name, -1, SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, g->module->op, -1, SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_INT(stmt, 3, g->module->version()); @@ -322,14 +318,10 @@ static void edit_preset_response(GtkDialog *dialog, gint response_id, dt_gui_pre DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 11, gtk_entry_get_text(GTK_ENTRY(g->lens)), -1, SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 12, gtk_spin_button_get_value(GTK_SPIN_BUTTON(g->iso_min))); DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 13, gtk_spin_button_get_value(GTK_SPIN_BUTTON(g->iso_max))); - DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 14, - dt_gui_presets_exposure_value[dt_bauhaus_combobox_get(g->exposure_min)]); - DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 15, - dt_gui_presets_exposure_value[dt_bauhaus_combobox_get(g->exposure_max)]); - DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 16, - dt_gui_presets_aperture_value[dt_bauhaus_combobox_get(g->aperture_min)]); - DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 17, - dt_gui_presets_aperture_value[dt_bauhaus_combobox_get(g->aperture_max)]); + DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 14, dt_gui_presets_exposure_value[dt_bauhaus_combobox_get(g->exposure_min)]); + DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 15, dt_gui_presets_exposure_value[dt_bauhaus_combobox_get(g->exposure_max)]); + DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 16, dt_gui_presets_aperture_value[dt_bauhaus_combobox_get(g->aperture_min)]); + DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 17, dt_gui_presets_aperture_value[dt_bauhaus_combobox_get(g->aperture_max)]); DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 18, gtk_spin_button_get_value(GTK_SPIN_BUTTON(g->focal_length_min))); DT_DEBUG_SQLITE3_BIND_DOUBLE(stmt, 19, gtk_spin_button_get_value(GTK_SPIN_BUTTON(g->focal_length_max))); DT_DEBUG_SQLITE3_BIND_INT(stmt, 20, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g->autoapply))); @@ -390,8 +382,7 @@ static void edit_preset(const char *name_in, dt_iop_module_t *module) gtk_container_add(content_area, GTK_WIDGET(box)); GtkWidget *label; - dt_gui_presets_edit_dialog_t *g - = (dt_gui_presets_edit_dialog_t *)malloc(sizeof(dt_gui_presets_edit_dialog_t)); + dt_gui_presets_edit_dialog_t *g = (dt_gui_presets_edit_dialog_t *)malloc(sizeof(dt_gui_presets_edit_dialog_t)); g->old_id = -1; g->original_name = name; g->module = module; @@ -404,13 +395,11 @@ static void edit_preset(const char *name_in, dt_iop_module_t *module) gtk_box_pack_start(box, GTK_WIDGET(g->description), FALSE, FALSE, 0); gtk_widget_set_tooltip_text(GTK_WIDGET(g->description), _("description or further information")); - g->autoapply - = GTK_CHECK_BUTTON(gtk_check_button_new_with_label(_("auto apply this preset to matching images"))); + g->autoapply = GTK_CHECK_BUTTON(gtk_check_button_new_with_label(_("auto apply this preset to matching images"))); gtk_box_pack_start(box, GTK_WIDGET(g->autoapply), FALSE, FALSE, 0); - g->filter - = GTK_CHECK_BUTTON(gtk_check_button_new_with_label(_("only show this preset for matching images"))); + g->filter = GTK_CHECK_BUTTON(gtk_check_button_new_with_label(_("only show this preset for matching images"))); gtk_widget_set_tooltip_text(GTK_WIDGET(g->filter), _("be very careful with this option. " - "this might be the last time you see your preset.")); + "this might be the last time you see your preset.")); gtk_box_pack_start(box, GTK_WIDGET(g->filter), FALSE, FALSE, 0); g_signal_connect(G_OBJECT(g->autoapply), "toggled", G_CALLBACK(check_buttons_activated), g); g_signal_connect(G_OBJECT(g->filter), "toggled", G_CALLBACK(check_buttons_activated), g); @@ -616,8 +605,7 @@ static void menuitem_update_preset(GtkMenuItem *menuitem, dt_iop_module_t *modul DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, module->version()); DT_DEBUG_SQLITE3_BIND_BLOB(stmt, 3, module->params, module->params_size, SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_INT(stmt, 4, module->enabled); - DT_DEBUG_SQLITE3_BIND_BLOB(stmt, 5, module->blend_params, sizeof(dt_develop_blend_params_t), - SQLITE_TRANSIENT); + DT_DEBUG_SQLITE3_BIND_BLOB(stmt, 5, module->blend_params, sizeof(dt_develop_blend_params_t), SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_INT(stmt, 6, dt_develop_blend_version()); DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 7, name, -1, SQLITE_TRANSIENT); sqlite3_step(stmt); @@ -760,8 +748,8 @@ void dt_gui_favorite_presets_menu_show() static void dt_gui_presets_popup_menu_show_internal(dt_dev_operation_t op, int32_t version, dt_iop_params_t *params, int32_t params_size, - dt_develop_blend_params_t *bl_params, - dt_iop_module_t *module, const dt_image_t *image, + dt_develop_blend_params_t *bl_params, dt_iop_module_t *module, + const dt_image_t *image, void (*pick_callback)(GtkMenuItem *, void *), void *callback_data) { @@ -918,10 +906,8 @@ static void dt_gui_presets_popup_menu_show_internal(dt_dev_operation_t op, int32 } void dt_gui_presets_popup_menu_show_for_params(dt_dev_operation_t op, int32_t version, void *params, - int32_t params_size, void *blendop_params, - const dt_image_t *image, - void (*pick_callback)(GtkMenuItem *, void *), - void *callback_data) + int32_t params_size, void *blendop_params, const dt_image_t *image, + void (*pick_callback)(GtkMenuItem *, void *), void *callback_data) { dt_gui_presets_popup_menu_show_internal(op, version, params, params_size, blendop_params, NULL, image, pick_callback, callback_data); @@ -930,12 +916,11 @@ void dt_gui_presets_popup_menu_show_for_params(dt_dev_operation_t op, int32_t ve void dt_gui_presets_popup_menu_show_for_module(dt_iop_module_t *module) { dt_gui_presets_popup_menu_show_internal(module->op, module->version(), module->params, module->params_size, - module->blend_params, module, &module->dev->image_storage, NULL, - NULL); + module->blend_params, module, &module->dev->image_storage, NULL, NULL); } -void dt_gui_presets_update_mml(const char *name, dt_dev_operation_t op, const int32_t version, - const char *maker, const char *model, const char *lens) +void dt_gui_presets_update_mml(const char *name, dt_dev_operation_t op, const int32_t version, const char *maker, + const char *model, const char *lens) { char tmp[1024]; sqlite3_stmt *stmt; @@ -956,8 +941,8 @@ void dt_gui_presets_update_mml(const char *name, dt_dev_operation_t op, const in sqlite3_finalize(stmt); } -void dt_gui_presets_update_iso(const char *name, dt_dev_operation_t op, const int32_t version, - const float min, const float max) +void dt_gui_presets_update_iso(const char *name, dt_dev_operation_t op, const int32_t version, const float min, + const float max) { sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2( @@ -1024,8 +1009,7 @@ void dt_gui_presets_update_fl(const char *name, dt_dev_operation_t op, const int sqlite3_finalize(stmt); } -void dt_gui_presets_update_ldr(const char *name, dt_dev_operation_t op, const int32_t version, - const int ldrflag) +void dt_gui_presets_update_ldr(const char *name, dt_dev_operation_t op, const int32_t version, const int ldrflag) { sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), @@ -1054,8 +1038,7 @@ void dt_gui_presets_update_autoapply(const char *name, dt_dev_operation_t op, co sqlite3_finalize(stmt); } -void dt_gui_presets_update_filter(const char *name, dt_dev_operation_t op, const int32_t version, - const int filter) +void dt_gui_presets_update_filter(const char *name, dt_dev_operation_t op, const int32_t version, const int filter) { sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), diff --git a/src/gui/presets.h b/src/gui/presets.h index 5847084dc9bd..c8b291ebed5a 100644 --- a/src/gui/presets.h +++ b/src/gui/presets.h @@ -12,15 +12,15 @@ typedef enum dt_gui_presets_format_flag_t void dt_gui_presets_init(); /** add or replace a generic (i.e. non-exif specific) preset for this operation. */ -void dt_gui_presets_add_generic(const char *name, dt_dev_operation_t op, const int32_t version, - const void *params, const int32_t params_size, const int32_t enabled); +void dt_gui_presets_add_generic(const char *name, dt_dev_operation_t op, const int32_t version, const void *params, + const int32_t params_size, const int32_t enabled); /** update match strings for maker, model, lens. */ -void dt_gui_presets_update_mml(const char *name, dt_dev_operation_t op, const int32_t version, - const char *maker, const char *model, const char *lens); +void dt_gui_presets_update_mml(const char *name, dt_dev_operation_t op, const int32_t version, const char *maker, + const char *model, const char *lens); /** update ranges for iso, aperture, exposure, and focal length, respectively. */ -void dt_gui_presets_update_iso(const char *name, dt_dev_operation_t op, const int32_t version, - const float min, const float max); +void dt_gui_presets_update_iso(const char *name, dt_dev_operation_t op, const int32_t version, const float min, + const float max); void dt_gui_presets_update_av(const char *name, dt_dev_operation_t op, const int32_t version, const float min, const float max); void dt_gui_presets_update_tv(const char *name, dt_dev_operation_t op, const int32_t version, const float min, @@ -28,21 +28,17 @@ void dt_gui_presets_update_tv(const char *name, dt_dev_operation_t op, const int void dt_gui_presets_update_fl(const char *name, dt_dev_operation_t op, const int32_t version, const float min, const float max); /** update ldr flag: 0-dont care, 1-low dynamic range, 2-raw */ -void dt_gui_presets_update_ldr(const char *name, dt_dev_operation_t op, const int32_t version, - const int ldrflag); +void dt_gui_presets_update_ldr(const char *name, dt_dev_operation_t op, const int32_t version, const int ldrflag); /** set auto apply property of preset. */ void dt_gui_presets_update_autoapply(const char *name, dt_dev_operation_t op, const int32_t version, const int autoapply); /** set filter mode. if 1, the preset will only show for matching images. */ -void dt_gui_presets_update_filter(const char *name, dt_dev_operation_t op, const int32_t version, - const int filter); +void dt_gui_presets_update_filter(const char *name, dt_dev_operation_t op, const int32_t version, const int filter); /** show a popup menu without initialized module. */ void dt_gui_presets_popup_menu_show_for_params(dt_dev_operation_t op, int32_t version, void *params, - int32_t params_size, void *blendop_params, - const dt_image_t *image, - void (*pick_callback)(GtkMenuItem *, void *), - void *callback_data); + int32_t params_size, void *blendop_params, const dt_image_t *image, + void (*pick_callback)(GtkMenuItem *, void *), void *callback_data); /** show the popup menu for the given module, with default behavior. */ void dt_gui_presets_popup_menu_show_for_module(dt_iop_module_t *module); diff --git a/src/gui/styles_dialog.c b/src/gui/styles_dialog.c index 4e7f03e3a290..6876e195b278 100644 --- a/src/gui/styles_dialog.c +++ b/src/gui/styles_dialog.c @@ -86,9 +86,8 @@ void _gui_styles_get_active_items(dt_gui_styles_dialog_t *sd, GList **enabled, G { do { - gtk_tree_model_get(model, &iter, DT_STYLE_ITEMS_COL_ENABLED, &active, DT_STYLE_ITEMS_COL_UPDATE, - &uactive, DT_STYLE_ITEMS_COL_NUM, &num, DT_STYLE_ITEMS_COL_UPDATE_NUM, &update_num, - -1); + gtk_tree_model_get(model, &iter, DT_STYLE_ITEMS_COL_ENABLED, &active, DT_STYLE_ITEMS_COL_UPDATE, &uactive, + DT_STYLE_ITEMS_COL_NUM, &num, DT_STYLE_ITEMS_COL_UPDATE_NUM, &update_num, -1); if(active || uactive) { *enabled = g_list_append(*enabled, GINT_TO_POINTER(num)); @@ -345,8 +344,8 @@ static void _gui_styles_dialog_run(gboolean edit, const char *name, int imgid) gtk_cell_renderer_toggle_set_activatable(GTK_CELL_RENDERER_TOGGLE(renderer), TRUE); g_object_set_data(G_OBJECT(renderer), "column", (gint *)DT_STYLE_ITEMS_COL_ENABLED); g_signal_connect(renderer, "toggled", G_CALLBACK(_gui_styles_item_new_toggled), sd); - gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(sd->items_new), -1, _("include"), renderer, - "active", DT_STYLE_ITEMS_COL_ENABLED, NULL); + gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(sd->items_new), -1, _("include"), renderer, "active", + DT_STYLE_ITEMS_COL_ENABLED, NULL); } /* update */ @@ -396,8 +395,8 @@ static void _gui_styles_dialog_run(gboolean edit, const char *name, int imgid) gtk_list_store_append(GTK_LIST_STORE(liststore), &iter); gtk_list_store_set(GTK_LIST_STORE(liststore), &iter, DT_STYLE_ITEMS_COL_ENABLED, TRUE, DT_STYLE_ITEMS_COL_UPDATE, FALSE, DT_STYLE_ITEMS_COL_NAME, item->name, - DT_STYLE_ITEMS_COL_NUM, item->num, DT_STYLE_ITEMS_COL_UPDATE_NUM, - item->selimg_num, -1); + DT_STYLE_ITEMS_COL_NUM, item->num, DT_STYLE_ITEMS_COL_UPDATE_NUM, item->selimg_num, + -1); has_item = TRUE; } else if(item->num != -1 @@ -406,8 +405,8 @@ static void _gui_styles_dialog_run(gboolean edit, const char *name, int imgid) gtk_list_store_append(GTK_LIST_STORE(liststore_new), &iter); gtk_list_store_set(GTK_LIST_STORE(liststore_new), &iter, DT_STYLE_ITEMS_COL_ENABLED, item->num != -1 ? TRUE : FALSE, DT_STYLE_ITEMS_COL_NAME, item->name, - DT_STYLE_ITEMS_COL_NUM, item->num, DT_STYLE_ITEMS_COL_UPDATE_NUM, - item->selimg_num, -1); + DT_STYLE_ITEMS_COL_NUM, item->num, DT_STYLE_ITEMS_COL_UPDATE_NUM, item->selimg_num, + -1); has_new_item = TRUE; } } while((items = g_list_next(items))); @@ -429,8 +428,8 @@ static void _gui_styles_dialog_run(gboolean edit, const char *name, int imgid) GList *modules = g_list_first(darktable.develop->iop); if(modules) { - GList *result = g_list_find_custom( - modules, item->op, _g_list_find_module_by_name); // (dt_iop_module_t *)(modules->data); + GList *result = g_list_find_custom(modules, item->op, + _g_list_find_module_by_name); // (dt_iop_module_t *)(modules->data); if(result) { module = (dt_iop_module_t *)(result->data); diff --git a/src/imageio/format/exr.cc b/src/imageio/format/exr.cc index 58c3ec2e48d6..c3291f323308 100644 --- a/src/imageio/format/exr.cc +++ b/src/imageio/format/exr.cc @@ -101,8 +101,8 @@ void cleanup(dt_imageio_module_format_t *self) { } -int write_image(dt_imageio_module_data_t *tmp, const char *filename, const void *in_tmp, void *exif, - int exif_len, int imgid, int num, int total) +int write_image(dt_imageio_module_data_t *tmp, const char *filename, const void *in_tmp, void *exif, int exif_len, + int imgid, int num, int total) { const dt_imageio_exr_t *exr = (dt_imageio_exr_t *)tmp; @@ -130,13 +130,8 @@ int write_image(dt_imageio_module_data_t *tmp, const char *filename, const void // try to add the chromaticities if(imgid > 0) { - cmsToneCurve *red_curve = NULL, - *green_curve = NULL, - *blue_curve = NULL; - cmsCIEXYZ *red_color = NULL, - *green_color = NULL, - *blue_color = NULL, - *white_point = NULL; + cmsToneCurve *red_curve = NULL, *green_curve = NULL, *blue_curve = NULL; + cmsCIEXYZ *red_color = NULL, *green_color = NULL, *blue_color = NULL, *white_point = NULL; cmsHPROFILE out_profile = dt_colorspaces_get_output_profile(imgid)->profile; float r[2], g[2], b[2], w[2]; float sum; @@ -159,10 +154,10 @@ int write_image(dt_imageio_module_data_t *tmp, const char *filename, const void if(!cmsIsToneCurveLinear(red_curve) || !cmsIsToneCurveLinear(green_curve) || !cmsIsToneCurveLinear(blue_curve)) goto icc_error; -// printf("r: %f %f %f\n", red_color->X, red_color->Y, red_color->Z); -// printf("g: %f %f %f\n", green_color->X, green_color->Y, green_color->Z); -// printf("b: %f %f %f\n", blue_color->X, blue_color->Y, blue_color->Z); -// printf("w: %f %f %f\n", white_point->X, white_point->Y, white_point->Z); + // printf("r: %f %f %f\n", red_color->X, red_color->Y, red_color->Z); + // printf("g: %f %f %f\n", green_color->X, green_color->Y, green_color->Z); + // printf("b: %f %f %f\n", blue_color->X, blue_color->Y, blue_color->Z); + // printf("w: %f %f %f\n", white_point->X, white_point->Y, white_point->Z); sum = red_color->X + red_color->Y + red_color->Z; r[0] = red_color->X / sum; @@ -187,9 +182,10 @@ int write_image(dt_imageio_module_data_t *tmp, const char *filename, const void goto icc_end; -icc_error: + icc_error: dt_control_log("%s", _("the selected output profile doesn't work well with exr")); - fprintf(stderr, "[exr export] warning: exporting with anything but linear matrix profiles might lead to wrong results when opening the image\n"); + fprintf(stderr, "[exr export] warning: exporting with anything but linear matrix profiles might lead to wrong " + "results when opening the image\n"); } icc_end: @@ -206,14 +202,14 @@ int write_image(dt_imageio_module_data_t *tmp, const char *filename, const void const float *in = (const float *)in_tmp; - data.insert("R", Imf::Slice(Imf::PixelType::FLOAT, (char *)(in + 0), 4 * sizeof(float), - 4 * sizeof(float) * exr->width)); + data.insert( + "R", Imf::Slice(Imf::PixelType::FLOAT, (char *)(in + 0), 4 * sizeof(float), 4 * sizeof(float) * exr->width)); - data.insert("G", Imf::Slice(Imf::PixelType::FLOAT, (char *)(in + 1), 4 * sizeof(float), - 4 * sizeof(float) * exr->width)); + data.insert( + "G", Imf::Slice(Imf::PixelType::FLOAT, (char *)(in + 1), 4 * sizeof(float), 4 * sizeof(float) * exr->width)); - data.insert("B", Imf::Slice(Imf::PixelType::FLOAT, (char *)(in + 2), 4 * sizeof(float), - 4 * sizeof(float) * exr->width)); + data.insert( + "B", Imf::Slice(Imf::PixelType::FLOAT, (char *)(in + 2), 4 * sizeof(float), 4 * sizeof(float) * exr->width)); file.setFrameBuffer(data); file.writeTiles(0, file.numXTiles() - 1, 0, file.numYTiles() - 1); @@ -226,9 +222,8 @@ size_t params_size(dt_imageio_module_format_t *self) return sizeof(dt_imageio_exr_t); } -void *legacy_params(dt_imageio_module_format_t *self, const void *const old_params, - const size_t old_params_size, const int old_version, const int new_version, - size_t *new_size) +void *legacy_params(dt_imageio_module_format_t *self, const void *const old_params, const size_t old_params_size, + const int old_version, const int new_version, size_t *new_size) { if(old_version == 1 && new_version == 4) { diff --git a/src/imageio/format/imageio_format_api.h b/src/imageio/format/imageio_format_api.h index 3c3d07d1c305..6bbc754f9f18 100644 --- a/src/imageio/format/imageio_format_api.h +++ b/src/imageio/format/imageio_format_api.h @@ -54,8 +54,7 @@ void cleanup(struct dt_imageio_module_format_t *self); /* gets the current export parameters from gui/conf and stores in this struct for later use. */ void *legacy_params(struct dt_imageio_module_format_t *self, const void *const old_params, - const size_t old_params_size, const int old_version, const int new_version, - size_t *new_size); + const size_t old_params_size, const int old_version, const int new_version, size_t *new_size); size_t params_size(struct dt_imageio_module_format_t *self); void *get_params(struct dt_imageio_module_format_t *self); void free_params(struct dt_imageio_module_format_t *self, struct dt_imageio_module_data_t *data); diff --git a/src/imageio/format/j2k.c b/src/imageio/format/j2k.c index 6c80be0d2613..94487f0d125f 100644 --- a/src/imageio/format/j2k.c +++ b/src/imageio/format/j2k.c @@ -71,8 +71,7 @@ typedef enum // borrowed from blender #define DOWNSAMPLE_FLOAT_TO_8BIT(_val) (_val) <= 0.0f ? 0 : ((_val) >= 1.0f ? 255 : (int)(255.0f * (_val))) #define DOWNSAMPLE_FLOAT_TO_12BIT(_val) (_val) <= 0.0f ? 0 : ((_val) >= 1.0f ? 4095 : (int)(4095.0f * (_val))) -#define DOWNSAMPLE_FLOAT_TO_16BIT(_val) \ - (_val) <= 0.0f ? 0 : ((_val) >= 1.0f ? 65535 : (int)(65535.0f * (_val))) +#define DOWNSAMPLE_FLOAT_TO_16BIT(_val) (_val) <= 0.0f ? 0 : ((_val) >= 1.0f ? 65535 : (int)(65535.0f * (_val))) DT_MODULE(2) @@ -110,8 +109,7 @@ void init(dt_imageio_module_format_t *self) luaA_enum(darktable.lua_state.state, dt_imageio_j2k_format_t); luaA_enum_value_name(darktable.lua_state.state, dt_imageio_j2k_format_t, J2K_CFMT, "j2k"); luaA_enum_value_name(darktable.lua_state.state, dt_imageio_j2k_format_t, JP2_CFMT, "jp2"); - dt_lua_register_module_member(darktable.lua_state.state, self, dt_imageio_j2k_t, format, - dt_imageio_j2k_format_t); + dt_lua_register_module_member(darktable.lua_state.state, self, dt_imageio_j2k_t, format, dt_imageio_j2k_format_t); dt_lua_register_module_member(darktable.lua_state.state, self, dt_imageio_j2k_t, quality, int); luaA_enum(darktable.lua_state.state, dt_imageio_j2k_preset_t); luaA_enum_value_name(darktable.lua_state.state, dt_imageio_j2k_preset_t, DT_J2K_PRESET_OFF, "off"); @@ -121,8 +119,7 @@ void init(dt_imageio_module_format_t *self) "cinema2k_48"); luaA_enum_value_name(darktable.lua_state.state, dt_imageio_j2k_preset_t, DT_J2K_PRESET_CINEMA4K_24, "cinema4k_24"); - dt_lua_register_module_member(darktable.lua_state.state, self, dt_imageio_j2k_t, preset, - dt_imageio_j2k_preset_t); + dt_lua_register_module_member(darktable.lua_state.state, self, dt_imageio_j2k_t, preset, dt_imageio_j2k_preset_t); #endif } void cleanup(dt_imageio_module_format_t *self) @@ -223,9 +220,8 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters, opj_image_t *ima } if(!((image->comps[0].w == 2048) | (image->comps[0].h == 1080))) { - fprintf(stdout, - "Image coordinates %d x %d is not 2K compliant.\nJPEG Digital Cinema Profile-3 " - "(2K profile) compliance requires that at least one of coordinates match 2048 x 1080\n", + fprintf(stdout, "Image coordinates %d x %d is not 2K compliant.\nJPEG Digital Cinema Profile-3 " + "(2K profile) compliance requires that at least one of coordinates match 2048 x 1080\n", image->comps[0].w, image->comps[0].h); parameters->cp_rsiz = OPJ_STD_RSIZ; } @@ -243,9 +239,8 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters, opj_image_t *ima } if(!((image->comps[0].w == 4096) | (image->comps[0].h == 2160))) { - fprintf(stdout, - "Image coordinates %d x %d is not 4K compliant.\nJPEG Digital Cinema Profile-4" - "(4K profile) compliance requires that at least one of coordinates match 4096 x 2160\n", + fprintf(stdout, "Image coordinates %d x %d is not 4K compliant.\nJPEG Digital Cinema Profile-4" + "(4K profile) compliance requires that at least one of coordinates match 4096 x 2160\n", image->comps[0].w, image->comps[0].h); parameters->cp_rsiz = OPJ_STD_RSIZ; } @@ -269,9 +264,8 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters, opj_image_t *ima } else { - temp_rate - = ((float)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)) - / (rates[i] * 8 * image->comps[0].dx * image->comps[0].dy); + temp_rate = ((float)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)) + / (rates[i] * 8 * image->comps[0].dx * image->comps[0].dy); if(temp_rate > OPJ_CINEMA_24_CS) { parameters->tcp_rates[i] @@ -298,9 +292,8 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters, opj_image_t *ima } else { - temp_rate - = ((float)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)) - / (rates[i] * 8 * image->comps[0].dx * image->comps[0].dy); + temp_rate = ((float)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)) + / (rates[i] * 8 * image->comps[0].dx * image->comps[0].dy); if(temp_rate > OPJ_CINEMA_48_CS) { parameters->tcp_rates[0] @@ -405,20 +398,17 @@ int write_image(dt_imageio_module_data_t *j2k_tmp, const char *filename, const v case 12: for(int i = 0; i < w * h; i++) { - for(int k = 0; k < numcomps; k++) - image->comps[k].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(in[i * 4 + k]); + for(int k = 0; k < numcomps; k++) image->comps[k].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(in[i * 4 + k]); } break; case 16: for(int i = 0; i < w * h; i++) { - for(int k = 0; k < numcomps; k++) - image->comps[k].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(in[i * 4 + k]); + for(int k = 0; k < numcomps; k++) image->comps[k].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(in[i * 4 + k]); } break; default: - fprintf(stderr, "Error: this shouldn't happen, there is no bit depth of %d for jpeg 2000 images.\n", - prec); + fprintf(stderr, "Error: this shouldn't happen, there is no bit depth of %d for jpeg 2000 images.\n", prec); free(rates); opj_image_destroy(image); return 1; @@ -520,9 +510,8 @@ size_t params_size(dt_imageio_module_format_t *self) return sizeof(dt_imageio_j2k_t); } -void *legacy_params(dt_imageio_module_format_t *self, const void *const old_params, - const size_t old_params_size, const int old_version, const int new_version, - size_t *new_size) +void *legacy_params(dt_imageio_module_format_t *self, const void *const old_params, const size_t old_params_size, + const int old_version, const int new_version, size_t *new_size) { if(old_version == 1 && new_version == 2) { diff --git a/src/imageio/format/jpeg.c b/src/imageio/format/jpeg.c index 35d66db8eb35..7653f2217549 100644 --- a/src/imageio/format/jpeg.c +++ b/src/imageio/format/jpeg.c @@ -471,9 +471,8 @@ size_t params_size(dt_imageio_module_format_t *self) return sizeof(dt_imageio_module_data_t) + sizeof(int); } -void *legacy_params(dt_imageio_module_format_t *self, const void *const old_params, - const size_t old_params_size, const int old_version, const int new_version, - size_t *new_size) +void *legacy_params(dt_imageio_module_format_t *self, const void *const old_params, const size_t old_params_size, + const int old_version, const int new_version, size_t *new_size) { if(old_version == 1 && new_version == 2) { diff --git a/src/imageio/format/pdf.c b/src/imageio/format/pdf.c index 1cc8a26eb441..61a00c0486ad 100644 --- a/src/imageio/format/pdf.c +++ b/src/imageio/format/pdf.c @@ -121,24 +121,30 @@ typedef struct dt_imageio_pdf_t #ifdef USE_LUA static int orientation_member(lua_State *L) { - dt_imageio_pdf_t *d = (dt_imageio_pdf_t *)lua_touserdata(L,1); + dt_imageio_pdf_t *d = (dt_imageio_pdf_t *)lua_touserdata(L, 1); dt_lua_orientation_t orientation; if(lua_gettop(L) != 3) { - if(d->params.orientation == ORIENTATION_LANDSCAPE) { + if(d->params.orientation == ORIENTATION_LANDSCAPE) + { orientation = GTK_ORIENTATION_HORIZONTAL; - } else { + } + else + { orientation = GTK_ORIENTATION_VERTICAL; } - luaA_push(L,dt_lua_orientation_t,&orientation); + luaA_push(L, dt_lua_orientation_t, &orientation); return 1; } else { - luaA_to(L,dt_lua_orientation_t,&orientation,3); - if(orientation == GTK_ORIENTATION_HORIZONTAL) { + luaA_to(L, dt_lua_orientation_t, &orientation, 3); + if(orientation == GTK_ORIENTATION_HORIZONTAL) + { d->params.orientation = ORIENTATION_LANDSCAPE; - } else { + } + else + { d->params.orientation = ORIENTATION_PORTRAIT; } return 0; @@ -148,7 +154,7 @@ static int orientation_member(lua_State *L) void init(dt_imageio_module_format_t *self) { - lua_State* L = darktable.lua_state.state ; + lua_State *L = darktable.lua_state.state; luaA_enum(L, _pdf_pages_t); luaA_enum_value_name(L, _pdf_pages_t, PAGES_ALL, "all"); @@ -164,22 +170,27 @@ void init(dt_imageio_module_format_t *self) luaA_enum_value_name(L, dt_pdf_stream_encoder_t, DT_PDF_STREAM_ENCODER_ASCII_HEX, "uncompressed"); luaA_enum_value_name(L, dt_pdf_stream_encoder_t, DT_PDF_STREAM_ENCODER_FLATE, "deflate"); - dt_lua_register_module_member_indirect(L, self, dt_imageio_pdf_t, params,dt_imageio_pdf_params_t,title, char_128); - dt_lua_register_module_member_indirect(L, self, dt_imageio_pdf_t, params,dt_imageio_pdf_params_t,size, char_64); - dt_lua_register_module_member_indirect(L, self, dt_imageio_pdf_t, params,dt_imageio_pdf_params_t,border, char_64); - dt_lua_register_module_member_indirect(L, self, dt_imageio_pdf_t, params,dt_imageio_pdf_params_t,dpi, float); - dt_lua_register_module_member_indirect(L, self, dt_imageio_pdf_t, params,dt_imageio_pdf_params_t,rotate, bool); - dt_lua_register_module_member_indirect(L, self, dt_imageio_pdf_t, params,dt_imageio_pdf_params_t,pages, _pdf_pages_t); - dt_lua_register_module_member_indirect(L, self, dt_imageio_pdf_t, params,dt_imageio_pdf_params_t,icc, bool); - dt_lua_register_module_member_indirect(L, self, dt_imageio_pdf_t, params,dt_imageio_pdf_params_t,mode, _pdf_mode_t); - dt_lua_register_module_member_indirect(L, self, dt_imageio_pdf_t, params,dt_imageio_pdf_params_t,compression, dt_pdf_stream_encoder_t); + dt_lua_register_module_member_indirect(L, self, dt_imageio_pdf_t, params, dt_imageio_pdf_params_t, title, + char_128); + dt_lua_register_module_member_indirect(L, self, dt_imageio_pdf_t, params, dt_imageio_pdf_params_t, size, char_64); + dt_lua_register_module_member_indirect(L, self, dt_imageio_pdf_t, params, dt_imageio_pdf_params_t, border, + char_64); + dt_lua_register_module_member_indirect(L, self, dt_imageio_pdf_t, params, dt_imageio_pdf_params_t, dpi, float); + dt_lua_register_module_member_indirect(L, self, dt_imageio_pdf_t, params, dt_imageio_pdf_params_t, rotate, bool); + dt_lua_register_module_member_indirect(L, self, dt_imageio_pdf_t, params, dt_imageio_pdf_params_t, pages, + _pdf_pages_t); + dt_lua_register_module_member_indirect(L, self, dt_imageio_pdf_t, params, dt_imageio_pdf_params_t, icc, bool); + dt_lua_register_module_member_indirect(L, self, dt_imageio_pdf_t, params, dt_imageio_pdf_params_t, mode, + _pdf_mode_t); + dt_lua_register_module_member_indirect(L, self, dt_imageio_pdf_t, params, dt_imageio_pdf_params_t, compression, + dt_pdf_stream_encoder_t); lua_pushcfunction(L, orientation_member); dt_lua_type_register_type(L, self->parameter_lua_type, "orientation"); } -#else // USE_LUA +#else // USE_LUA void init(dt_imageio_module_format_t *self) { // we need an empty init, even when compiled without Lua @@ -205,7 +216,7 @@ static int _paper_size(dt_imageio_pdf_params_t *d, float *page_width, float *pag { fprintf(stderr, "[imageio_format_pdf] invalid border size: `%s'! using 0\n", d->border); dt_control_log(_("invalid border size, using 0")); -// return 1; + // return 1; border = 0.0; } @@ -230,8 +241,8 @@ static int _paper_size(dt_imageio_pdf_params_t *d, float *page_width, float *pag } -int write_image(dt_imageio_module_data_t *data, const char *filename, const void *in, void *exif, - int exif_len, int imgid, int num, int total) +int write_image(dt_imageio_module_data_t *data, const char *filename, const void *in, void *exif, int exif_len, + int imgid, int num, int total) { dt_imageio_pdf_t *d = (dt_imageio_pdf_t *)data; @@ -241,8 +252,7 @@ int write_image(dt_imageio_module_data_t *data, const char *filename, const void float page_width, page_height, page_border; float page_dpi = d->params.dpi; - if(_paper_size(&d->params, &page_width, &page_height, &page_border)) - return 1; + if(_paper_size(&d->params, &page_width, &page_height, &page_border)) return 1; unsigned int compression = d->params.compression; compression = MIN(compression, DT_PDF_STREAM_ENCODER_FLATE); @@ -313,8 +323,7 @@ int write_image(dt_imageio_module_data_t *data, const char *filename, const void uint8_t *out_ptr = (uint8_t *)image_data; for(int y = 0; y < data->height; y++) { - for(int x = 0; x < data->width; x++, in_ptr += 4, out_ptr += 3) - memcpy(out_ptr, in_ptr, 3); + for(int x = 0; x < data->width; x++, in_ptr += 4, out_ptr += 3) memcpy(out_ptr, in_ptr, 3); } } else @@ -326,14 +335,14 @@ int write_image(dt_imageio_module_data_t *data, const char *filename, const void { for(int x = 0; x < data->width; x++, in_ptr += 4, out_ptr += 3) { - for(int c = 0; c < 3; c++) - out_ptr[c] = (0xff00 & (in_ptr[c] << 8)) | (in_ptr[c] >> 8); + for(int c = 0; c < 3; c++) out_ptr[c] = (0xff00 & (in_ptr[c] << 8)) | (in_ptr[c] >> 8); } } } } - dt_pdf_image_t *image = dt_pdf_add_image(d->pdf, image_data, d->params.parent.width, d->params.parent.height, d->params.bpp, icc_id, d->page_border); + dt_pdf_image_t *image = dt_pdf_add_image(d->pdf, image_data, d->params.parent.width, d->params.parent.height, + d->params.bpp, icc_id, d->page_border); free(image_data); @@ -414,7 +423,8 @@ int flags(dt_imageio_module_data_t *data) return FORMAT_FLAGS_NO_TMPFILE; } -int dimension(struct dt_imageio_module_format_t *self, dt_imageio_module_data_t *data, uint32_t *width, uint32_t *height) +int dimension(struct dt_imageio_module_format_t *self, dt_imageio_module_data_t *data, uint32_t *width, + uint32_t *height) { if(data) { @@ -423,14 +433,12 @@ int dimension(struct dt_imageio_module_format_t *self, dt_imageio_module_data_t float page_width, page_height, page_border; float page_dpi = d->params.dpi; - if(_paper_size(&d->params, &page_width, &page_height, &page_border)) - return 1; + if(_paper_size(&d->params, &page_width, &page_height, &page_border)) return 1; *width = dt_pdf_point_to_pixel(page_width - 2 * page_border, page_dpi) + 0.5; *height = dt_pdf_point_to_pixel(page_height - 2 * page_border, page_dpi) + 0.5; - if(d->params.rotate) - *width = *height = MAX(*width, *height); + if(d->params.rotate) *width = *height = MAX(*width, *height); } return 0; } @@ -455,7 +463,7 @@ static void _set_paper_size(dt_imageio_module_format_t *self, const char *text) while(labels) { - const char *l = (char*)labels->data; + const char *l = (char *)labels->data; if((pos < dt_pdf_paper_sizes_n && !strcasecmp(text, dt_pdf_paper_sizes[pos].name)) || !strcasecmp(text, l)) break; pos++; @@ -497,7 +505,6 @@ static void _set_paper_size(dt_imageio_module_format_t *self, const char *text) } g_signal_handlers_unblock_by_func(d->size, size_toggle_callback, self); - } static void title_changed_callback(GtkWidget *widget, gpointer user_data) @@ -515,8 +522,8 @@ static void size_toggle_callback(GtkWidget *widget, gpointer user_data) unsigned int pos = dt_bauhaus_combobox_get(widget); if(pos < dt_pdf_paper_sizes_n) _set_paper_size(user_data, dt_pdf_paper_sizes[pos].name); // has to be untranslated - else - _set_paper_size(user_data, dt_bauhaus_combobox_get_text(widget)); + else + _set_paper_size(user_data, dt_bauhaus_combobox_get_text(widget)); } static void orientation_toggle_callback(GtkWidget *widget, gpointer user_data) @@ -553,8 +560,7 @@ static void bpp_toggle_callback(GtkWidget *widget, gpointer user_data) { const int sel = dt_bauhaus_combobox_get(widget); // we don't allow typing in that dropdown so -1 shouldn't happen, but coverity doesn't know that - if(sel >= 0) - dt_conf_set_int("plugins/imageio/format/pdf/bpp", _pdf_bpp[sel].bpp); + if(sel >= 0) dt_conf_set_int("plugins/imageio/format/pdf/bpp", _pdf_bpp[sel].bpp); } static void compression_toggle_callback(GtkWidget *widget, gpointer user_data) @@ -600,8 +606,7 @@ void gui_init(dt_imageio_module_format_t *self) d->size = dt_bauhaus_combobox_new(NULL); dt_bauhaus_combobox_set_editable(d->size, 1); dt_bauhaus_widget_set_label(d->size, NULL, _("paper size")); - for(int i = 0; dt_pdf_paper_sizes[i].name; i++) - dt_bauhaus_combobox_add(d->size, _(dt_pdf_paper_sizes[i].name)); + for(int i = 0; dt_pdf_paper_sizes[i].name; i++) dt_bauhaus_combobox_add(d->size, _(dt_pdf_paper_sizes[i].name)); gtk_grid_attach(grid, GTK_WIDGET(d->size), 0, ++line, 2, 1); g_signal_connect(G_OBJECT(d->size), "value-changed", G_CALLBACK(size_toggle_callback), self); gtk_widget_set_tooltip_text(d->size, _("paper size of the pdf\neither one from the list or " @@ -677,8 +682,8 @@ void gui_init(dt_imageio_module_format_t *self) dt_bauhaus_combobox_add(d->pages, _("all")); dt_bauhaus_combobox_add(d->pages, _("single images")); dt_bauhaus_combobox_add(d->pages, _("contact sheet")); -// gtk_grid_attach(grid, GTK_WIDGET(d->pages), 0, ++line, 2, 1); -// g_signal_connect(G_OBJECT(d->pages), "value-changed", G_CALLBACK(pages_toggle_callback), self); + // gtk_grid_attach(grid, GTK_WIDGET(d->pages), 0, ++line, 2, 1); + // g_signal_connect(G_OBJECT(d->pages), "value-changed", G_CALLBACK(pages_toggle_callback), self); gtk_widget_set_tooltip_text(d->pages, _("what pages should be added to the pdf")); dt_bauhaus_combobox_set(d->pages, dt_conf_get_int("plugins/imageio/format/pdf/pages")); gtk_widget_set_sensitive(d->pages, FALSE); // TODO @@ -804,8 +809,7 @@ void free_params(dt_imageio_module_format_t *self, dt_imageio_module_data_t *par { dt_imageio_pdf_t *d = (dt_imageio_pdf_t *)params; - if(d->pdf) - dt_pdf_finish(d->pdf, NULL, 0); + if(d->pdf) dt_pdf_finish(d->pdf, NULL, 0); g_list_free_full(d->images, free); @@ -833,8 +837,7 @@ int set_params(dt_imageio_module_format_t *self, const void *params, const int s for(int i = 0; _pdf_bpp[i].name; i++) { - if(_pdf_bpp[i].bpp == d->params.bpp) - dt_bauhaus_combobox_set(g->bpp, i); + if(_pdf_bpp[i].bpp == d->params.bpp) dt_bauhaus_combobox_set(g->bpp, i); } gtk_entry_set_text(g->title, d->params.title); diff --git a/src/imageio/format/pfm.c b/src/imageio/format/pfm.c index a4ce97152cea..4095b11474cb 100644 --- a/src/imageio/format/pfm.c +++ b/src/imageio/format/pfm.c @@ -28,8 +28,8 @@ DT_MODULE(1) -int write_image(dt_imageio_module_data_t *data, const char *filename, const void *ivoid, void *exif, - int exif_len, int imgid, int num, int total) +int write_image(dt_imageio_module_data_t *data, const char *filename, const void *ivoid, void *exif, int exif_len, + int imgid, int num, int total) { const dt_imageio_module_data_t *const pfm = data; int status = 0; diff --git a/src/imageio/format/ppm.c b/src/imageio/format/ppm.c index 1cd28a33020c..0389bbfb837a 100644 --- a/src/imageio/format/ppm.c +++ b/src/imageio/format/ppm.c @@ -33,8 +33,8 @@ void cleanup(dt_imageio_module_format_t *self) { } -int write_image(dt_imageio_module_data_t *ppm, const char *filename, const void *in_tmp, void *exif, - int exif_len, int imgid, int num, int total) +int write_image(dt_imageio_module_data_t *ppm, const char *filename, const void *in_tmp, void *exif, int exif_len, + int imgid, int num, int total) { const uint16_t *in = (const uint16_t *)in_tmp; int status = 0; diff --git a/src/imageio/format/tiff.c b/src/imageio/format/tiff.c index 697115ab0e4d..28f5be2d8d56 100644 --- a/src/imageio/format/tiff.c +++ b/src/imageio/format/tiff.c @@ -258,9 +258,8 @@ size_t params_size(dt_imageio_module_format_t *self) return sizeof(dt_imageio_tiff_t) - sizeof(TIFF *); } -void *legacy_params(dt_imageio_module_format_t *self, const void *const old_params, - const size_t old_params_size, const int old_version, const int new_version, - size_t *new_size) +void *legacy_params(dt_imageio_module_format_t *self, const void *const old_params, const size_t old_params_size, + const int old_version, const int new_version, size_t *new_size) { if(old_version == 1 && new_version == 2) { diff --git a/src/imageio/format/webp.c b/src/imageio/format/webp.c index 442b8fbaccd4..78c45bcdcda7 100644 --- a/src/imageio/format/webp.c +++ b/src/imageio/format/webp.c @@ -67,20 +67,19 @@ typedef struct dt_imageio_webp_gui_data_t GtkWidget *hint; } dt_imageio_webp_gui_data_t; -static const char *const EncoderError[] = { - "ok", "out_of_memory: out of memory allocating objects", - "bitstream_out_of_memory: out of memory re-allocating byte buffer", - "null_parameter: null parameter passed to function", "invalid_configuration: configuration is invalid", - "bad_dimension: bad picture dimension. maximum width and height " - "allowed is 16383 pixels.", - "partition0_overflow: partition #0 is too big to fit 512k.\n" - "to reduce the size of this partition, try using less segments " - "with the -segments option, and eventually reduce the number of " - "header bits using -partition_limit. more details are available " - "in the manual (`man cwebp`)", - "partition_overflow: partition is too big to fit 16M", "bad_write: picture writer returned an i/o error", - "file_too_big: file would be too big to fit in 4G", "user_abort: encoding abort requested by user" -}; +static const char *const EncoderError[] + = { "ok", "out_of_memory: out of memory allocating objects", + "bitstream_out_of_memory: out of memory re-allocating byte buffer", + "null_parameter: null parameter passed to function", "invalid_configuration: configuration is invalid", + "bad_dimension: bad picture dimension. maximum width and height " + "allowed is 16383 pixels.", + "partition0_overflow: partition #0 is too big to fit 512k.\n" + "to reduce the size of this partition, try using less segments " + "with the -segments option, and eventually reduce the number of " + "header bits using -partition_limit. more details are available " + "in the manual (`man cwebp`)", + "partition_overflow: partition is too big to fit 16M", "bad_write: picture writer returned an i/o error", + "file_too_big: file would be too big to fit in 4G", "user_abort: encoding abort requested by user" }; void init(dt_imageio_module_format_t *self) { @@ -108,8 +107,8 @@ static int FileWriter(const uint8_t *data, size_t data_size, const WebPPicture * return data_size ? (fwrite(data, data_size, 1, out) == 1) : 1; } -int write_image(dt_imageio_module_data_t *webp, const char *filename, const void *in_tmp, void *exif, - int exif_len, int imgid, int num, int total) +int write_image(dt_imageio_module_data_t *webp, const char *filename, const void *in_tmp, void *exif, int exif_len, + int imgid, int num, int total) { dt_imageio_webp_t *webp_data = (dt_imageio_webp_t *)webp; FILE *out = g_fopen(filename, "wb"); @@ -180,9 +179,8 @@ size_t params_size(dt_imageio_module_format_t *self) return sizeof(dt_imageio_webp_t); } -void *legacy_params(dt_imageio_module_format_t *self, const void *const old_params, - const size_t old_params_size, const int old_version, const int new_version, - size_t *new_size) +void *legacy_params(dt_imageio_module_format_t *self, const void *const old_params, const size_t old_params_size, + const int old_version, const int new_version, size_t *new_size) { if(old_version == 1 && new_version == 2) { @@ -316,11 +314,10 @@ void gui_init(dt_imageio_module_format_t *self) gui->hint = dt_bauhaus_combobox_new(NULL); dt_bauhaus_widget_set_label(gui->hint, NULL, _("image hint")); - gtk_widget_set_tooltip_text(gui->hint, - _("image characteristics hint for the underlying encoder.\n" - "picture : digital picture, like portrait, inner shot\n" - "photo : outdoor photograph, with natural lighting\n" - "graphic : discrete tone image (graph, map-tile etc)")); + gtk_widget_set_tooltip_text(gui->hint, _("image characteristics hint for the underlying encoder.\n" + "picture : digital picture, like portrait, inner shot\n" + "photo : outdoor photograph, with natural lighting\n" + "graphic : discrete tone image (graph, map-tile etc)")); dt_bauhaus_combobox_add(gui->hint, _("default")); dt_bauhaus_combobox_add(gui->hint, _("picture")); dt_bauhaus_combobox_add(gui->hint, _("photo")); diff --git a/src/imageio/storage/disk.c b/src/imageio/storage/disk.c index 1f9d6e38ad17..7dd1adb58a26 100644 --- a/src/imageio/storage/disk.c +++ b/src/imageio/storage/disk.c @@ -63,9 +63,8 @@ const char *name(const struct dt_imageio_module_storage_t *self) return _("file on disk"); } -void *legacy_params(dt_imageio_module_storage_t *self, const void *const old_params, - const size_t old_params_size, const int old_version, const int new_version, - size_t *new_size) +void *legacy_params(dt_imageio_module_storage_t *self, const void *const old_params, const size_t old_params_size, + const int old_version, const int new_version, size_t *new_size) { if(old_version == 1 && new_version == 2) { @@ -212,7 +211,7 @@ int store(dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, co // about a potentially added "_$(SEQUENCE)" char *original_filename = g_strdup(d->filename); -try_again: + try_again: // avoid braindead export which is bound to overwrite at random: if(total > 1 && !g_strrstr(d->filename, "$")) { @@ -314,8 +313,8 @@ int store(dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, co printf("[export_job] exported to `%s'\n", filename); char *trunc = filename + strlen(filename) - 32; if(trunc < filename) trunc = filename; - dt_control_log(ngettext("%d/%d exported to `%s%s'", "%d/%d exported to `%s%s'", num), - num, total, trunc != filename ? ".." : "", trunc); + dt_control_log(ngettext("%d/%d exported to `%s%s'", "%d/%d exported to `%s%s'", num), num, total, + trunc != filename ? ".." : "", trunc); return 0; } @@ -327,8 +326,7 @@ size_t params_size(dt_imageio_module_storage_t *self) void init(dt_imageio_module_storage_t *self) { #ifdef USE_LUA - dt_lua_register_module_member(darktable.lua_state.state, self, dt_imageio_disk_t, filename, - char_path_length); + dt_lua_register_module_member(darktable.lua_state.state, self, dt_imageio_disk_t, filename, char_path_length); #endif } diff --git a/src/imageio/storage/email.c b/src/imageio/storage/email.c index 920fdbec78e3..039d29f149bd 100644 --- a/src/imageio/storage/email.c +++ b/src/imageio/storage/email.c @@ -51,9 +51,8 @@ const char *name(const struct dt_imageio_module_storage_t *self) return _("send as email"); } -void *legacy_params(dt_imageio_module_storage_t *self, const void *const old_params, - const size_t old_params_size, const int old_version, const int new_version, - size_t *new_size) +void *legacy_params(dt_imageio_module_storage_t *self, const void *const old_params, const size_t old_params_size, + const int old_version, const int new_version, size_t *new_size) { if(old_version == 1 && new_version == 2) { @@ -74,7 +73,8 @@ void *legacy_params(dt_imageio_module_storage_t *self, const void *const old_par return NULL; } -int recommended_dimension(struct dt_imageio_module_storage_t *self, dt_imageio_module_data_t *data, uint32_t *width, uint32_t *height) +int recommended_dimension(struct dt_imageio_module_storage_t *self, dt_imageio_module_data_t *data, + uint32_t *width, uint32_t *height) { *width = 1536; *height = 1536; @@ -128,8 +128,8 @@ int store(dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, co attachment->file = g_build_filename(tmpdir, dirname, (char *)NULL); - if(dt_imageio_export(imgid, attachment->file, format, fdata, high_quality, upscale, FALSE, icc_type, icc_filename, - icc_intent, self, sdata, num, total) != 0) + if(dt_imageio_export(imgid, attachment->file, format, fdata, high_quality, upscale, FALSE, icc_type, + icc_filename, icc_intent, self, sdata, num, total) != 0) { fprintf(stderr, "[imageio_storage_email] could not export to file: `%s'!\n", attachment->file); dt_control_log(_("could not export to file `%s'!"), attachment->file); @@ -141,8 +141,8 @@ int store(dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, co char *trunc = attachment->file + strlen(attachment->file) - 32; if(trunc < attachment->file) trunc = attachment->file; - dt_control_log(ngettext("%d/%d exported to `%s%s'", "%d/%d exported to `%s%s'", num), - num, total, trunc != filename ? ".." : "", trunc); + dt_control_log(ngettext("%d/%d exported to `%s%s'", "%d/%d exported to `%s%s'", num), num, total, + trunc != filename ? ".." : "", trunc); #ifdef _OPENMP // store can be called in parallel, so synch access to shared memory #pragma omp critical diff --git a/src/imageio/storage/facebook.c b/src/imageio/storage/facebook.c index 2e31ac0b5703..679608b13bf3 100644 --- a/src/imageio/storage/facebook.c +++ b/src/imageio/storage/facebook.c @@ -356,14 +356,14 @@ typedef struct static void fb_query_post_add_form_arguments(const gchar *key, const gchar *value, HttppostFormList *formlist) { - curl_formadd(&(formlist->formpost), &(formlist->lastptr), CURLFORM_COPYNAME, key, CURLFORM_COPYCONTENTS, - value, CURLFORM_END); + curl_formadd(&(formlist->formpost), &(formlist->lastptr), CURLFORM_COPYNAME, key, CURLFORM_COPYCONTENTS, value, + CURLFORM_END); } static void fb_query_post_add_file_arguments(const gchar *key, const gchar *value, HttppostFormList *formlist) { - curl_formadd(&(formlist->formpost), &(formlist->lastptr), CURLFORM_COPYNAME, key, CURLFORM_COPYCONTENTS, - value, CURLFORM_END); + curl_formadd(&(formlist->formpost), &(formlist->lastptr), CURLFORM_COPYNAME, key, CURLFORM_COPYCONTENTS, value, + CURLFORM_END); curl_formadd(&(formlist->formpost), &(formlist->lastptr), CURLFORM_COPYNAME, key, CURLFORM_FILE, value, CURLFORM_END); @@ -393,8 +393,8 @@ static JsonObject *fb_query_post(FBContext *ctx, const gchar *method, GHashTable formlist.formpost = NULL; formlist.lastptr = NULL; - curl_formadd(&(formlist.formpost), &(formlist.lastptr), CURLFORM_COPYNAME, "access_token", - CURLFORM_COPYCONTENTS, ctx->token, CURLFORM_END); + curl_formadd(&(formlist.formpost), &(formlist.lastptr), CURLFORM_COPYNAME, "access_token", CURLFORM_COPYCONTENTS, + ctx->token, CURLFORM_END); if(args != NULL) g_hash_table_foreach(args, (GHFunc)fb_query_post_add_form_arguments, &formlist); if(files != NULL) g_hash_table_foreach(files, (GHFunc)fb_query_post_add_file_arguments, &formlist); @@ -622,9 +622,9 @@ static gchar *facebook_get_user_auth_token_from_url(dt_storage_facebook_gui_data "you are done."); GtkWidget *window = dt_ui_main_window(darktable.gui->ui); - GtkDialog *fb_auth_dialog = GTK_DIALOG( - gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, - GTK_BUTTONS_OK_CANCEL, _("facebook authentication"))); + GtkDialog *fb_auth_dialog + = GTK_DIALOG(gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, + GTK_BUTTONS_OK_CANCEL, _("facebook authentication"))); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(fb_auth_dialog), "%s\n\n%s", text1, text2); GtkWidget *entry = gtk_entry_new(); @@ -661,8 +661,7 @@ static gchar *facebook_get_user_auth_token_from_url(dt_storage_facebook_gui_data gtk_message_dialog_format_secondary_markup( GTK_MESSAGE_DIALOG(fb_auth_dialog), "%s\n\n%s%s\n\n<span foreground=\"" MSGCOLOR_RED "\"><small>%s</small></span>", text1, text2, - _("the given URL is not valid, it should look like: "), - FB_WS_BASE_URL "connect/login_success.html?..."); + _("the given URL is not valid, it should look like: "), FB_WS_BASE_URL "connect/login_success.html?..."); } gtk_widget_destroy(GTK_WIDGET(fb_auth_dialog)); @@ -707,11 +706,11 @@ static gboolean facebook_get_user_auth_token_from_server(dt_storage_facebook_gui // create a dialog telling the user to login in the browser GtkWidget *win = dt_ui_main_window(darktable.gui->ui); - GtkWidget *dialog = gtk_message_dialog_new( - GTK_WINDOW(win), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CANCEL, - _("a new window or tab of your browser should have been " - "loaded. you have to login into your facebook account there " - "and authorize darktable to upload photos before continuing.")); + GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(win), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, + GTK_BUTTONS_CANCEL, + _("a new window or tab of your browser should have been " + "loaded. you have to login into your facebook account there " + "and authorize darktable to upload photos before continuing.")); gtk_window_set_title(GTK_WINDOW(dialog), _("facebook authentication")); @@ -840,8 +839,8 @@ static void ui_refresh_users(dt_storage_facebook_gui_data_t *ui) int active_account = 0; if(g_slist_length(accountlist) == 0) { - gtk_list_store_set(list_store, &iter, COMBO_USER_MODEL_NAME_COL, _("new account"), - COMBO_USER_MODEL_TOKEN_COL, NULL, COMBO_USER_MODEL_ID_COL, NULL, -1); + gtk_list_store_set(list_store, &iter, COMBO_USER_MODEL_NAME_COL, _("new account"), COMBO_USER_MODEL_TOKEN_COL, + NULL, COMBO_USER_MODEL_ID_COL, NULL, -1); } else { @@ -942,8 +941,8 @@ static void ui_authenticate_finish(dt_storage_facebook_gui_data_t *ui, gboolean { gtk_list_store_append(model, &iter); gtk_list_store_set(model, &iter, COMBO_USER_MODEL_NAME_COL, accountinfo->readablename, - COMBO_USER_MODEL_TOKEN_COL, accountinfo->token, COMBO_USER_MODEL_ID_COL, - accountinfo->id, -1); + COMBO_USER_MODEL_TOKEN_COL, accountinfo->token, COMBO_USER_MODEL_ID_COL, accountinfo->id, + -1); } gtk_combo_box_set_active_iter(ui->comboBox_username, &iter); // we have to re-set the current token here since ui_combo_username_changed is called @@ -1157,14 +1156,14 @@ void gui_init(struct dt_imageio_module_storage_t *self) GtkListStore *list_store = gtk_list_store_new(COMBO_ALBUM_MODEL_NB_COL, G_TYPE_STRING, G_TYPE_INT); GtkTreeIter iter; gtk_list_store_append(list_store, &iter); - gtk_list_store_set(list_store, &iter, COMBO_PRIVACY_MODEL_NAME_COL, _("only me"), - COMBO_PRIVACY_MODEL_VAL_COL, FBALBUM_PRIVACY_SELF, -1); + gtk_list_store_set(list_store, &iter, COMBO_PRIVACY_MODEL_NAME_COL, _("only me"), COMBO_PRIVACY_MODEL_VAL_COL, + FBALBUM_PRIVACY_SELF, -1); gtk_list_store_append(list_store, &iter); - gtk_list_store_set(list_store, &iter, COMBO_PRIVACY_MODEL_NAME_COL, _("friends"), - COMBO_PRIVACY_MODEL_VAL_COL, FBALBUM_PRIVACY_ALL_FRIENDS, -1); + gtk_list_store_set(list_store, &iter, COMBO_PRIVACY_MODEL_NAME_COL, _("friends"), COMBO_PRIVACY_MODEL_VAL_COL, + FBALBUM_PRIVACY_ALL_FRIENDS, -1); gtk_list_store_append(list_store, &iter); - gtk_list_store_set(list_store, &iter, COMBO_PRIVACY_MODEL_NAME_COL, _("public"), - COMBO_PRIVACY_MODEL_VAL_COL, FBALBUM_PRIVACY_EVERYONE, -1); + gtk_list_store_set(list_store, &iter, COMBO_PRIVACY_MODEL_NAME_COL, _("public"), COMBO_PRIVACY_MODEL_VAL_COL, + FBALBUM_PRIVACY_EVERYONE, -1); gtk_list_store_append(list_store, &iter); gtk_list_store_set(list_store, &iter, COMBO_PRIVACY_MODEL_NAME_COL, _("friends of friends"), COMBO_PRIVACY_MODEL_VAL_COL, FBALBUM_PRIVACY_FRIENDS_OF_FRIENDS, -1); @@ -1207,8 +1206,7 @@ void gui_init(struct dt_imageio_module_storage_t *self) // connect buttons to signals g_signal_connect(G_OBJECT(ui->button_login), "clicked", G_CALLBACK(ui_login_clicked), (gpointer)ui); - g_signal_connect(G_OBJECT(ui->comboBox_username), "changed", G_CALLBACK(ui_combo_username_changed), - (gpointer)ui); + g_signal_connect(G_OBJECT(ui->comboBox_username), "changed", G_CALLBACK(ui_combo_username_changed), (gpointer)ui); g_signal_connect(G_OBJECT(ui->comboBox_album), "changed", G_CALLBACK(ui_combo_album_changed), (gpointer)ui); g_object_unref(model_username); @@ -1292,9 +1290,8 @@ int store(dt_imageio_module_storage_t *self, struct dt_imageio_module_data_t *sd if(fdata->max_height == 0 || fdata->max_height > FB_IMAGE_MAX_SIZE) fdata->max_height = FB_IMAGE_MAX_SIZE; if(fdata->max_width == 0 || fdata->max_width > FB_IMAGE_MAX_SIZE) fdata->max_width = FB_IMAGE_MAX_SIZE; - if(dt_imageio_export(imgid, fname, format, fdata, high_quality, upscale, FALSE, icc_type, icc_filename, icc_intent, - self, sdata, num, total) - != 0) + if(dt_imageio_export(imgid, fname, format, fdata, high_quality, upscale, FALSE, icc_type, icc_filename, + icc_intent, self, sdata, num, total) != 0) { g_printerr("[facebook] could not export to file: `%s'!\n", fname); dt_control_log(_("could not export to file `%s'!"), fname); @@ -1310,9 +1307,8 @@ int store(dt_imageio_module_storage_t *self, struct dt_imageio_module_data_t *sd result = 0; goto cleanup; } - const gchar *album_id - = fb_create_album(p->facebook_ctx, p->facebook_ctx->album_title, p->facebook_ctx->album_summary, - p->facebook_ctx->album_permission); + const gchar *album_id = fb_create_album(p->facebook_ctx, p->facebook_ctx->album_title, + p->facebook_ctx->album_summary, p->facebook_ctx->album_permission); if(album_id == NULL) { dt_control_log(_("unable to create album")); @@ -1374,8 +1370,7 @@ void *get_params(struct dt_imageio_module_storage_t *self) { return NULL; } - dt_storage_facebook_param_t *p - = (dt_storage_facebook_param_t *)g_malloc0(sizeof(dt_storage_facebook_param_t)); + dt_storage_facebook_param_t *p = (dt_storage_facebook_param_t *)g_malloc0(sizeof(dt_storage_facebook_param_t)); p->hash = 1; p->facebook_ctx = ui->facebook_api; int index = gtk_combo_box_get_active(ui->comboBox_album); diff --git a/src/imageio/storage/flickr.c b/src/imageio/storage/flickr.c index e95498e093d9..37be4852767e 100644 --- a/src/imageio/storage/flickr.c +++ b/src/imageio/storage/flickr.c @@ -64,7 +64,7 @@ typedef struct dt_storage_flickr_gui_data_t GtkLabel *status_label; GtkEntry *user_entry, *title_entry, *summary_entry; GtkWidget *export_tags; - GtkBox *create_box; // Create album options... + GtkBox *create_box; // Create album options... GtkWidget *permission_list, *album_list; char *user_token; @@ -256,8 +256,8 @@ static _flickr_api_context_t *_flickr_api_authenticate(dt_storage_flickr_gui_dat } -static flickcurl_upload_status *_flickr_api_upload_photo(dt_storage_flickr_params_t *p, char *fname, - char *caption, char *description, gint imgid) +static flickcurl_upload_status *_flickr_api_upload_photo(dt_storage_flickr_params_t *p, char *fname, char *caption, + char *description, gint imgid) { flickcurl_upload_params *params = g_malloc0(sizeof(flickcurl_upload_params)); @@ -385,7 +385,7 @@ static void refresh_albums(dt_storage_flickr_gui_data_t *ui) // Add standard action dt_bauhaus_combobox_add(ui->album_list, _("without album")); dt_bauhaus_combobox_add(ui->album_list, _("create new album")); -// dt_bauhaus_combobox_add(ui->album_list, ""); // Separator // FIXME: bauhaus doesn't support separators + // dt_bauhaus_combobox_add(ui->album_list, ""); // Separator // FIXME: bauhaus doesn't support separators // Then add albums from list... for(i = 0; ui->albums[i]; i++) @@ -642,8 +642,8 @@ int store(dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, co } dt_image_cache_read_release(darktable.image_cache, img); - if(dt_imageio_export(imgid, fname, format, fdata, high_quality, upscale, FALSE, icc_type, icc_filename, icc_intent, - self, sdata, num, total) != 0) + if(dt_imageio_export(imgid, fname, format, fdata, high_quality, upscale, FALSE, icc_type, icc_filename, + icc_intent, self, sdata, num, total) != 0) { fprintf(stderr, "[imageio_storage_flickr] could not export to file: `%s'!\n", fname); dt_control_log(_("could not export to file `%s'!"), fname); @@ -717,8 +717,8 @@ int store(dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, co if(!result) { // this makes sense only if the export was successful - dt_control_log(ngettext("%d/%d exported to flickr webalbum", "%d/%d exported to flickr webalbum", num), - num, total); + dt_control_log(ngettext("%d/%d exported to flickr webalbum", "%d/%d exported to flickr webalbum", num), num, + total); } return result; } @@ -764,8 +764,7 @@ void *get_params(dt_imageio_module_storage_t *self) break; default: // use existing album - d->flickr_api->current_album - = flickcurl_photosets_getInfo(d->flickr_api->fc, ui->albums[index - 2]->id); + d->flickr_api->current_album = flickcurl_photosets_getInfo(d->flickr_api->fc, ui->albums[index - 2]->id); if(d->flickr_api->current_album == NULL) { // Something went wrong... diff --git a/src/imageio/storage/gallery.c b/src/imageio/storage/gallery.c index d6d7b85d921c..9401d408fae3 100644 --- a/src/imageio/storage/gallery.c +++ b/src/imageio/storage/gallery.c @@ -71,9 +71,8 @@ const char *name(const struct dt_imageio_module_storage_t *self) return _("website gallery"); } -void *legacy_params(dt_imageio_module_storage_t *self, const void *const old_params, - const size_t old_params_size, const int old_version, const int new_version, - size_t *new_size) +void *legacy_params(dt_imageio_module_storage_t *self, const void *const old_params, const size_t old_params_size, + const int old_version, const int new_version, size_t *new_size) { if(old_version == 1 && new_version == 2) { @@ -236,8 +235,7 @@ int store(dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, co // if filenamepattern is a directory just let att ${FILE_NAME} as default.. if(g_file_test(tmp_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) - || ((d->filename + strlen(d->filename) - 1)[0] == '/' - || (d->filename + strlen(d->filename) - 1)[0] == '\\')) + || ((d->filename + strlen(d->filename) - 1)[0] == '/' || (d->filename + strlen(d->filename) - 1)[0] == '\\')) snprintf(d->filename + strlen(d->filename), sizeof(d->filename) - strlen(d->filename), "/$(FILE_NAME)"); // avoid braindead export which is bound to overwrite at random: @@ -322,8 +320,7 @@ int store(dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, co " <img src=\"%s\" alt=\"img%d\" class=\"img\" onclick=\"openSwipe(%d)\"/></div>\n" " <h1>%s</h1>\n" " %s</div>\n", - relthumbfilename, - num, num-1, title ? title : "&nbsp;", description ? description : "&nbsp;"); + relthumbfilename, num, num - 1, title ? title : "&nbsp;", description ? description : "&nbsp;"); // export image to file. need this to be able to access meaningful // fdata->width and height below. @@ -335,13 +332,12 @@ int store(dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, co return 1; } - snprintf(pair->item, sizeof(pair->item), - "{\n" - "src: '%s',\n" - "w: %d,\n" - "h: %d,\n" - "msrc: '%s',\n" - "},\n", + snprintf(pair->item, sizeof(pair->item), "{\n" + "src: '%s',\n" + "w: %d,\n" + "h: %d,\n" + "msrc: '%s',\n" + "},\n", relfilename, fdata->width, fdata->height, relthumbfilename); pair->pos = num; @@ -362,8 +358,8 @@ int store(dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, co if(c <= filename || *c == '/') c = filename + strlen(filename); ext = format->extension(fdata); sprintf(c, "-thumb.%s", ext); - if(dt_imageio_export(imgid, filename, format, fdata, FALSE, TRUE, FALSE, icc_type, icc_filename, icc_intent, self, - sdata, num, total) != 0) + if(dt_imageio_export(imgid, filename, format, fdata, FALSE, TRUE, FALSE, icc_type, icc_filename, icc_intent, + self, sdata, num, total) != 0) { fprintf(stderr, "[imageio_storage_gallery] could not export to file: `%s'!\n", filename); dt_control_log(_("could not export to file `%s'!"), filename); @@ -376,8 +372,8 @@ int store(dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, co printf("[export_job] exported to `%s'\n", filename); char *trunc = filename + strlen(filename) - 32; if(trunc < filename) trunc = filename; - dt_control_log(ngettext("%d/%d exported to `%s%s'", "%d/%d exported to `%s%s'", num), - num, total, trunc != filename ? ".." : "", trunc); + dt_control_log(ngettext("%d/%d exported to `%s%s'", "%d/%d exported to `%s%s'", num), num, total, + trunc != filename ? ".." : "", trunc); return 0; } @@ -452,23 +448,22 @@ void finalize_store(dt_imageio_module_storage_t *self, dt_imageio_module_data_t FILE *f = g_fopen(filename, "wb"); if(!f) return; - fprintf(f, - "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " - "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" - "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" - " <head>\n" - " <meta http-equiv=\"Content-type\" content=\"text/html;charset=UTF-8\" />\n" - " <link rel=\"shortcut icon\" href=\"style/favicon.ico\" />\n" - " <link rel=\"stylesheet\" href=\"style/style.css\" type=\"text/css\" />\n" - " <link rel=\"stylesheet\" href=\"pswp/photoswipe.css\">\n" - " <link rel=\"stylesheet\" href=\"pswp/default-skin/default-skin.css\">\n" - " <script src=\"pswp/photoswipe.min.js\"></script>\n" - " <script src=\"pswp/photoswipe-ui-default.min.js\"></script>\n" - " <title>%s</title>\n" - " </head>\n" - " <body>\n" - " <div class=\"title\">%s</div>\n" - " <div class=\"page\">\n", + fprintf(f, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" + "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + " <head>\n" + " <meta http-equiv=\"Content-type\" content=\"text/html;charset=UTF-8\" />\n" + " <link rel=\"shortcut icon\" href=\"style/favicon.ico\" />\n" + " <link rel=\"stylesheet\" href=\"style/style.css\" type=\"text/css\" />\n" + " <link rel=\"stylesheet\" href=\"pswp/photoswipe.css\">\n" + " <link rel=\"stylesheet\" href=\"pswp/default-skin/default-skin.css\">\n" + " <script src=\"pswp/photoswipe.min.js\"></script>\n" + " <script src=\"pswp/photoswipe-ui-default.min.js\"></script>\n" + " <title>%s</title>\n" + " </head>\n" + " <body>\n" + " <div class=\"title\">%s</div>\n" + " <div class=\"page\">\n", title, title); size_t count = 0; @@ -481,56 +476,58 @@ void finalize_store(dt_imageio_module_storage_t *self, dt_imageio_module_data_t count++; } - fprintf(f, " <p style=\"clear:both;\"></p>\n" - " </div>\n" - " <div class=\"footer\">\n" - " <script language=\"JavaScript\" type=\"text/javascript\">\n" - " document.write(\"download all: <em>curl -O# \" + document.documentURI.replace( /\\\\/g, '/' ).replace( /\\/[^\\/]*$/, '' ) + \"/img_[0000-%04zu].jpg</em>\")\n" - " </script><br />\n" - " created with %s\n" - " </div>\n" - " <div class=\"pswp\" tabindex=\"-1\" role=\"dialog\" aria-hidden=\"true\">\n" - " <div class=\"pswp__bg\"></div>\n" - " <div class=\"pswp__scroll-wrap\">\n" - " <div class=\"pswp__container\">\n" - " <div class=\"pswp__item\"></div>\n" - " <div class=\"pswp__item\"></div>\n" - " <div class=\"pswp__item\"></div>\n" - " </div>\n" - " <div class=\"pswp__ui pswp__ui--hidden\">\n" - " <div class=\"pswp__top-bar\">\n" - " <div class=\"pswp__counter\"></div>\n" - " <button class=\"pswp__button pswp__button--close\" title=\"Close (Esc)\"></button>\n" - " <button class=\"pswp__button pswp__button--share\" title=\"Share\"></button>\n" - " <button class=\"pswp__button pswp__button--fs\" title=\"Toggle fullscreen\"></button>\n" - " <button class=\"pswp__button pswp__button--zoom\" title=\"Zoom in/out\"></button>\n" - " <div class=\"pswp__preloader\">\n" - " <div class=\"pswp__preloader__icn\">\n" - " <div class=\"pswp__preloader__cut\">\n" - " <div class=\"pswp__preloader__donut\"></div>\n" - " </div>\n" - " </div>\n" - " </div>\n" - " </div>\n" - " <div class=\"pswp__share-modal pswp__share-modal--hidden pswp__single-tap\">\n" - " <div class=\"pswp__share-tooltip\"></div>\n" - " </div>\n" - " <button class=\"pswp__button pswp__button--arrow--left\" title=\"Previous (arrow left)\">\n" - " </button>\n" - " <button class=\"pswp__button pswp__button--arrow--right\" title=\"Next (arrow right)\">\n" - " </button>\n" - " <div class=\"pswp__caption\">\n" - " <div class=\"pswp__caption__center\"></div>\n" - " </div>\n" - " </div>\n" - " </div>\n" - " </div>\n" - " </body>\n" - "<script>\n" - "var pswpElement = document.querySelectorAll('.pswp')[0];\n" - "var items = [\n", - count, - darktable_package_string); + fprintf( + f, + " <p style=\"clear:both;\"></p>\n" + " </div>\n" + " <div class=\"footer\">\n" + " <script language=\"JavaScript\" type=\"text/javascript\">\n" + " document.write(\"download all: <em>curl -O# \" + document.documentURI.replace( /\\\\/g, '/' " + ").replace( /\\/[^\\/]*$/, '' ) + \"/img_[0000-%04zu].jpg</em>\")\n" + " </script><br />\n" + " created with %s\n" + " </div>\n" + " <div class=\"pswp\" tabindex=\"-1\" role=\"dialog\" aria-hidden=\"true\">\n" + " <div class=\"pswp__bg\"></div>\n" + " <div class=\"pswp__scroll-wrap\">\n" + " <div class=\"pswp__container\">\n" + " <div class=\"pswp__item\"></div>\n" + " <div class=\"pswp__item\"></div>\n" + " <div class=\"pswp__item\"></div>\n" + " </div>\n" + " <div class=\"pswp__ui pswp__ui--hidden\">\n" + " <div class=\"pswp__top-bar\">\n" + " <div class=\"pswp__counter\"></div>\n" + " <button class=\"pswp__button pswp__button--close\" title=\"Close (Esc)\"></button>\n" + " <button class=\"pswp__button pswp__button--share\" title=\"Share\"></button>\n" + " <button class=\"pswp__button pswp__button--fs\" title=\"Toggle fullscreen\"></button>\n" + " <button class=\"pswp__button pswp__button--zoom\" title=\"Zoom in/out\"></button>\n" + " <div class=\"pswp__preloader\">\n" + " <div class=\"pswp__preloader__icn\">\n" + " <div class=\"pswp__preloader__cut\">\n" + " <div class=\"pswp__preloader__donut\"></div>\n" + " </div>\n" + " </div>\n" + " </div>\n" + " </div>\n" + " <div class=\"pswp__share-modal pswp__share-modal--hidden pswp__single-tap\">\n" + " <div class=\"pswp__share-tooltip\"></div>\n" + " </div>\n" + " <button class=\"pswp__button pswp__button--arrow--left\" title=\"Previous (arrow left)\">\n" + " </button>\n" + " <button class=\"pswp__button pswp__button--arrow--right\" title=\"Next (arrow right)\">\n" + " </button>\n" + " <div class=\"pswp__caption\">\n" + " <div class=\"pswp__caption__center\"></div>\n" + " </div>\n" + " </div>\n" + " </div>\n" + " </div>\n" + " </body>\n" + "<script>\n" + "var pswpElement = document.querySelectorAll('.pswp')[0];\n" + "var items = [\n", + count, darktable_package_string); while(d->l) { pair_t *p = (pair_t *)d->l->data; @@ -562,8 +559,7 @@ size_t params_size(dt_imageio_module_storage_t *self) void init(dt_imageio_module_storage_t *self) { #ifdef USE_LUA - dt_lua_register_module_member(darktable.lua_state.state, self, dt_imageio_gallery_t, filename, - char_path_length); + dt_lua_register_module_member(darktable.lua_state.state, self, dt_imageio_gallery_t, filename, char_path_length); dt_lua_register_module_member(darktable.lua_state.state, self, dt_imageio_gallery_t, title, char_1024); #endif } @@ -609,12 +605,9 @@ int set_params(dt_imageio_module_storage_t *self, const void *params, const int int supported(dt_imageio_module_storage_t *storage, dt_imageio_module_format_t *format) { const char *mime = format->mime(NULL); - if(strcmp(mime, "image/jpeg") == 0) - return 1; - if(strcmp(mime, "image/png") == 0) - return 1; - if(strcmp(mime, "image/webp") == 0) - return 1; + if(strcmp(mime, "image/jpeg") == 0) return 1; + if(strcmp(mime, "image/png") == 0) return 1; + if(strcmp(mime, "image/webp") == 0) return 1; return 0; } diff --git a/src/imageio/storage/imageio_storage_api.h b/src/imageio/storage/imageio_storage_api.h index 1207dedfb4a8..e7ca4d7f8502 100644 --- a/src/imageio/storage/imageio_storage_api.h +++ b/src/imageio/storage/imageio_storage_api.h @@ -52,8 +52,8 @@ void init(struct dt_imageio_module_storage_t *self); /* try and see if this format is supported? */ int supported(struct dt_imageio_module_storage_t *self, struct dt_imageio_module_format_t *format); /* get storage max supported image dimension, return 0 if no dimension restrictions exists. */ -int dimension(struct dt_imageio_module_storage_t *self, struct dt_imageio_module_data_t *data, - uint32_t *width, uint32_t *height); +int dimension(struct dt_imageio_module_storage_t *self, struct dt_imageio_module_data_t *data, uint32_t *width, + uint32_t *height); /* get storage recommended image dimension, return 0 if no recommendation exists. */ int recommended_dimension(struct dt_imageio_module_storage_t *self, struct dt_imageio_module_data_t *data, uint32_t *width, uint32_t *height); @@ -65,17 +65,16 @@ int initialize_store(struct dt_imageio_module_storage_t *self, struct dt_imageio struct dt_imageio_module_format_t **format, struct dt_imageio_module_data_t **fdata, GList **images, const gboolean high_quality, const gboolean upscale); /* this actually does the work */ -int store(struct dt_imageio_module_storage_t *self, struct dt_imageio_module_data_t *self_data, - const int imgid, struct dt_imageio_module_format_t *format, struct dt_imageio_module_data_t *fdata, - const int num, const int total, const gboolean high_quality, const gboolean upscale, +int store(struct dt_imageio_module_storage_t *self, struct dt_imageio_module_data_t *self_data, const int imgid, + struct dt_imageio_module_format_t *format, struct dt_imageio_module_data_t *fdata, const int num, + const int total, const gboolean high_quality, const gboolean upscale, enum dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename, enum dt_iop_color_intent_t icc_intent); /* called once at the end (after exporting all images), if implemented. */ void finalize_store(struct dt_imageio_module_storage_t *self, struct dt_imageio_module_data_t *data); void *legacy_params(struct dt_imageio_module_storage_t *self, const void *const old_params, - const size_t old_params_size, const int old_version, const int new_version, - size_t *new_size); + const size_t old_params_size, const int old_version, const int new_version, size_t *new_size); size_t params_size(struct dt_imageio_module_storage_t *self); void *get_params(struct dt_imageio_module_storage_t *self); void free_params(struct dt_imageio_module_storage_t *self, struct dt_imageio_module_data_t *data); diff --git a/src/imageio/storage/latex.c b/src/imageio/storage/latex.c index 90f7ed23228a..1bf9200d960c 100644 --- a/src/imageio/storage/latex.c +++ b/src/imageio/storage/latex.c @@ -70,9 +70,8 @@ const char *name(const struct dt_imageio_module_storage_t *self) return _("LaTeX book template"); } -void *legacy_params(dt_imageio_module_storage_t *self, const void *const old_params, - const size_t old_params_size, const int old_version, const int new_version, - size_t *new_size) +void *legacy_params(dt_imageio_module_storage_t *self, const void *const old_params, const size_t old_params_size, + const int old_version, const int new_version, size_t *new_size) { if(old_version == 1 && new_version == 2) { @@ -216,7 +215,7 @@ static gint sort_pos(pair_t *a, pair_t *b) int store(dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, const int imgid, dt_imageio_module_format_t *format, dt_imageio_module_data_t *fdata, const int num, const int total, - const gboolean high_quality, const gboolean upscale,dt_colorspaces_color_profile_type_t icc_type, + const gboolean high_quality, const gboolean upscale, dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename, dt_iop_color_intent_t icc_intent) { dt_imageio_latex_t *d = (dt_imageio_latex_t *)sdata; @@ -348,14 +347,14 @@ int store(dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, co dt_pthread_mutex_unlock(&darktable.plugin_threadsafe); /* export image to file */ - dt_imageio_export(imgid, filename, format, fdata, high_quality, upscale, FALSE, icc_type, icc_filename, icc_intent, - self, sdata, num, total); + dt_imageio_export(imgid, filename, format, fdata, high_quality, upscale, FALSE, icc_type, icc_filename, + icc_intent, self, sdata, num, total); printf("[export_job] exported to `%s'\n", filename); char *trunc = filename + strlen(filename) - 32; if(trunc < filename) trunc = filename; - dt_control_log(ngettext("%d/%d exported to `%s%s'", "%d/%d exported to `%s%s'", num), - num, total, trunc != filename ? ".." : "", trunc); + dt_control_log(ngettext("%d/%d exported to `%s%s'", "%d/%d exported to `%s%s'", num), num, total, + trunc != filename ? ".." : "", trunc); return 0; } @@ -437,8 +436,7 @@ size_t params_size(dt_imageio_module_storage_t *self) void init(dt_imageio_module_storage_t *self) { #ifdef USE_LUA - dt_lua_register_module_member(darktable.lua_state.state, self, dt_imageio_latex_t, filename, - char_path_length); + dt_lua_register_module_member(darktable.lua_state.state, self, dt_imageio_latex_t, filename, char_path_length); dt_lua_register_module_member(darktable.lua_state.state, self, dt_imageio_latex_t, title, char_1024); #endif } diff --git a/src/imageio/storage/picasa.c b/src/imageio/storage/picasa.c index 88c41c7b547a..6555c4df725b 100644 --- a/src/imageio/storage/picasa.c +++ b/src/imageio/storage/picasa.c @@ -445,8 +445,8 @@ static GList *picasa_get_album_list(PicasaContext *ctx, gboolean *ok) * @see https://developers.google.com/picasa-web/docs/2.0/developers_guide_protocol#PostPhotos * @return the id of the uploaded photo */ -static const gchar *picasa_upload_photo_to_album(PicasaContext *ctx, gchar *albumid, gchar *fname, - gchar *title, gchar *summary, const int imgid) +static const gchar *picasa_upload_photo_to_album(PicasaContext *ctx, gchar *albumid, gchar *fname, gchar *title, + gchar *summary, const int imgid) { _buffer_t buffer = { 0 }; gchar *photo_id = NULL; @@ -680,8 +680,8 @@ static gchar *picasa_get_user_refresh_token(PicasaContext *ctx) JsonObject *reply; gchar *params = NULL; - params = dt_util_dstrcat(params, "refresh_token=%s&client_id=" GOOGLE_API_KEY - "&client_secret=" GOOGLE_API_SECRET "&grant_type=refresh_token", + params = dt_util_dstrcat(params, "refresh_token=%s&client_id=" GOOGLE_API_KEY "&client_secret=" GOOGLE_API_SECRET + "&grant_type=refresh_token", ctx->refresh_token); reply = picasa_query_post_auth(ctx, "o/oauth2/token", params); @@ -701,14 +701,13 @@ static int picasa_get_user_auth_token(dt_storage_picasa_gui_data_t *ui) { ///////////// open the authentication url in a browser GError *error = NULL; - if(!gtk_show_uri( - gdk_screen_get_default(), GOOGLE_WS_BASE_URL - "o/oauth2/auth?" - "client_id=" GOOGLE_API_KEY "&redirect_uri=urn:ietf:wg:oauth:2.0:oob" - "&scope=https://picasaweb.google.com/data/ https://www.googleapis.com/auth/userinfo.profile" - " https://www.googleapis.com/auth/userinfo.email" - "&response_type=code", - gtk_get_current_event_time(), &error)) + if(!gtk_show_uri(gdk_screen_get_default(), GOOGLE_WS_BASE_URL + "o/oauth2/auth?" + "client_id=" GOOGLE_API_KEY "&redirect_uri=urn:ietf:wg:oauth:2.0:oob" + "&scope=https://picasaweb.google.com/data/ https://www.googleapis.com/auth/userinfo.profile" + " https://www.googleapis.com/auth/userinfo.email" + "&response_type=code", + gtk_get_current_event_time(), &error)) { fprintf(stderr, "[picasa] error opening browser: %s\n", error->message); g_error_free(error); @@ -722,9 +721,9 @@ static int picasa_get_user_auth_token(dt_storage_picasa_gui_data_t *ui) "and click the OK button once you are done."); GtkWidget *window = dt_ui_main_window(darktable.gui->ui); - GtkDialog *picasa_auth_dialog = GTK_DIALOG( - gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, - GTK_BUTTONS_OK_CANCEL, _("google+ authentication"))); + GtkDialog *picasa_auth_dialog + = GTK_DIALOG(gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, + GTK_BUTTONS_OK_CANCEL, _("google+ authentication"))); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(picasa_auth_dialog), "%s\n\n%s", text1, text2); GtkWidget *entry = gtk_entry_new(); @@ -732,8 +731,7 @@ static int picasa_get_user_auth_token(dt_storage_picasa_gui_data_t *ui) gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(gtk_label_new(_("verification code:"))), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry), TRUE, TRUE, 0); - GtkWidget *picasaauthdialog_vbox - = gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG(picasa_auth_dialog)); + GtkWidget *picasaauthdialog_vbox = gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG(picasa_auth_dialog)); gtk_box_pack_end(GTK_BOX(picasaauthdialog_vbox), hbox, TRUE, TRUE, 0); gtk_widget_show_all(GTK_WIDGET(picasa_auth_dialog)); @@ -763,8 +761,7 @@ static int picasa_get_user_auth_token(dt_storage_picasa_gui_data_t *ui) } gtk_widget_destroy(GTK_WIDGET(picasa_auth_dialog)); - if(result == GTK_RESPONSE_CANCEL) - return 1; + if(result == GTK_RESPONSE_CANCEL) return 1; // Interchange now the authorization_code for an access_token and refresh_token JsonObject *reply; @@ -894,8 +891,8 @@ static void ui_refresh_users(dt_storage_picasa_gui_data_t *ui) if(g_slist_length(accountlist) == 0) { - gtk_list_store_set(list_store, &iter, COMBO_USER_MODEL_NAME_COL, _("new account"), - COMBO_USER_MODEL_TOKEN_COL, NULL, COMBO_USER_MODEL_ID_COL, NULL, -1); + gtk_list_store_set(list_store, &iter, COMBO_USER_MODEL_NAME_COL, _("new account"), COMBO_USER_MODEL_TOKEN_COL, + NULL, COMBO_USER_MODEL_ID_COL, NULL, -1); } else { @@ -935,8 +932,8 @@ static void ui_refresh_albums(dt_storage_picasa_gui_data_t *ui) GtkTreeIter iter; gtk_list_store_clear(model_album); gtk_list_store_append(model_album, &iter); - gtk_list_store_set(model_album, &iter, COMBO_ALBUM_MODEL_NAME_COL, _("drop box"), - COMBO_ALBUM_MODEL_ID_COL, NULL, -1); + gtk_list_store_set(model_album, &iter, COMBO_ALBUM_MODEL_NAME_COL, _("drop box"), COMBO_ALBUM_MODEL_ID_COL, NULL, + -1); if(albumList != NULL) { gtk_list_store_append(model_album, &iter); @@ -1021,8 +1018,7 @@ static gboolean ui_authenticate(dt_storage_picasa_gui_data_t *ui) gtk_combo_box_get_active_iter(ui->comboBox_username, &iter); GtkTreeModel *accountModel = gtk_combo_box_get_model(ui->comboBox_username); gtk_tree_model_get(accountModel, &iter, COMBO_USER_MODEL_TOKEN_COL, &uiselectedaccounttoken, -1); - gtk_tree_model_get(accountModel, &iter, COMBO_USER_MODEL_REFRESH_TOKEN_COL, &uiselectedaccountrefreshtoken, - -1); + gtk_tree_model_get(accountModel, &iter, COMBO_USER_MODEL_REFRESH_TOKEN_COL, &uiselectedaccountrefreshtoken, -1); gtk_tree_model_get(accountModel, &iter, COMBO_USER_MODEL_ID_COL, &uiselecteduserid, -1); if(ctx->token != NULL) @@ -1083,8 +1079,8 @@ static gboolean ui_authenticate(dt_storage_picasa_gui_data_t *ui) if(g_strcmp0(uid, accountinfo->id) == 0) { gtk_list_store_set(model, &iter, COMBO_USER_MODEL_NAME_COL, accountinfo->username, - COMBO_USER_MODEL_TOKEN_COL, accountinfo->token, - COMBO_USER_MODEL_REFRESH_TOKEN_COL, accountinfo->refresh_token, -1); + COMBO_USER_MODEL_TOKEN_COL, accountinfo->token, COMBO_USER_MODEL_REFRESH_TOKEN_COL, + accountinfo->refresh_token, -1); updated = TRUE; break; } @@ -1215,8 +1211,7 @@ void gui_init(struct dt_imageio_module_storage_t *self) // connect buttons to signals g_signal_connect(G_OBJECT(ui->button_login), "clicked", G_CALLBACK(ui_login_clicked), (gpointer)ui); - g_signal_connect(G_OBJECT(ui->comboBox_username), "changed", G_CALLBACK(ui_combo_username_changed), - (gpointer)ui); + g_signal_connect(G_OBJECT(ui->comboBox_username), "changed", G_CALLBACK(ui_combo_username_changed), (gpointer)ui); g_signal_connect(G_OBJECT(ui->comboBox_album), "changed", G_CALLBACK(ui_combo_album_changed), (gpointer)ui); g_object_unref(model_username); @@ -1282,8 +1277,8 @@ int store(dt_imageio_module_storage_t *self, struct dt_imageio_module_data_t *sd dt_image_cache_read_release(darktable.image_cache, img); - if(dt_imageio_export(imgid, fname, format, fdata, high_quality, upscale, FALSE, icc_type, icc_filename, icc_intent, - self, sdata, num, total) != 0) + if(dt_imageio_export(imgid, fname, format, fdata, high_quality, upscale, FALSE, icc_type, icc_filename, + icc_intent, self, sdata, num, total) != 0) { g_printerr("[picasa] could not export to file: `%s'!\n", fname); dt_control_log(_("could not export to file `%s'!"), fname); diff --git a/src/iop/Permutohedral.h b/src/iop/Permutohedral.h index b6ee89cf6b0c..b25c5f7aaa91 100644 --- a/src/iop/Permutohedral.h +++ b/src/iop/Permutohedral.h @@ -296,8 +296,8 @@ template <int D, int VD> class PermutohedralLattice // first rotate position into the (d+1)-dimensional hyperplane elevated[D] = -D * position[D - 1] * scaleFactor[D - 1]; for(int i = D - 1; i > 0; i--) - elevated[i] = (elevated[i + 1] - i * position[i - 1] * scaleFactor[i - 1] - + (i + 2) * position[i] * scaleFactor[i]); + elevated[i] + = (elevated[i + 1] - i * position[i - 1] * scaleFactor[i - 1] + (i + 2) * position[i] * scaleFactor[i]); elevated[0] = elevated[1] + 2 * position[0] * scaleFactor[0]; // prepare to find the closest lattice points @@ -520,7 +520,7 @@ template <int D, int VD> class PermutohedralLattice int table; int offset; float weight; - } *replay; + } * replay; HashTablePermutohedral<D, VD> *hashTables; }; diff --git a/src/iop/amaze_demosaic_RT.cc b/src/iop/amaze_demosaic_RT.cc index 685d9d9b7470..a806f730541e 100644 --- a/src/iop/amaze_demosaic_RT.cc +++ b/src/iop/amaze_demosaic_RT.cc @@ -100,7 +100,7 @@ static __inline float xdivf(float d, int n) #define STVF(x, y) _mm_store_ps(&x, y) #define STVFU(x, y) _mm_storeu_ps(&x, y) #else // there is a bug in gcc 4.7.x when using openmp and aligned memory and -O3, also need to map the - // aligned functions to unaligned functions for WIN32 builds +// aligned functions to unaligned functions for WIN32 builds #define LVF(x) _mm_loadu_ps(&x) #define LVFU(x) _mm_loadu_ps(&x) #define STVF(x, y) _mm_storeu_ps(&x, y) @@ -113,15 +113,15 @@ static __inline float xdivf(float d, int n) #define STVFU(x, y) _mm_storeu_ps(&x, y) #endif -#define STC2VFU(a, v) \ - { \ - __m128 TST1V = _mm_loadu_ps(&a); \ - __m128 TST2V = _mm_unpacklo_ps(v, v); \ - vmask cmask = _mm_set_epi32(0xffffffff, 0, 0xffffffff, 0); \ - _mm_storeu_ps(&a, vself(cmask, TST1V, TST2V)); \ - TST1V = _mm_loadu_ps((&a) + 4); \ - TST2V = _mm_unpackhi_ps(v, v); \ - _mm_storeu_ps((&a) + 4, vself(cmask, TST1V, TST2V)); \ +#define STC2VFU(a, v) \ + { \ + __m128 TST1V = _mm_loadu_ps(&a); \ + __m128 TST2V = _mm_unpacklo_ps(v, v); \ + vmask cmask = _mm_set_epi32(0xffffffff, 0, 0xffffffff, 0); \ + _mm_storeu_ps(&a, vself(cmask, TST1V, TST2V)); \ + TST1V = _mm_loadu_ps((&a) + 4); \ + TST2V = _mm_unpackhi_ps(v, v); \ + _mm_storeu_ps((&a) + 4, vself(cmask, TST1V, TST2V)); \ } #define ZEROV _mm_setzero_ps() @@ -369,8 +369,8 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie } // shifts of pointer value to access pixels in vertical and diagonal directions - constexpr int v1 = ts, v2 = 2 * ts, v3 = 3 * ts, p1 = -ts + 1, p2 = -2 * ts + 2, p3 = -3 * ts + 3, - m1 = ts + 1, m2 = 2 * ts + 2, m3 = 3 * ts + 3; + constexpr int v1 = ts, v2 = 2 * ts, v3 = 3 * ts, p1 = -ts + 1, p2 = -2 * ts + 2, p3 = -3 * ts + 3, m1 = ts + 1, + m2 = 2 * ts + 2, m3 = 3 * ts + 3; // tolerance to avoid dividing by zero constexpr float eps = 1e-5, epssq = 1e-10; // tolerance to avoid dividing by zero @@ -385,9 +385,9 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie constexpr float nyqthresh = 0.5; // gaussian on 5x5, sigma=1.2, multiplied with nyqthresh to save some time later in loop // Is this really sigma=1.2????, seems more like sigma = 1.672 - constexpr float gaussgrad[6] = { nyqthresh * 0.07384411893421103f, nyqthresh * 0.06207511968171489f, - nyqthresh * 0.0521818194747806f, nyqthresh * 0.03687419286733595f, - nyqthresh * 0.03099732204057846f, nyqthresh * 0.018413194161458882f }; + constexpr float gaussgrad[6] + = { nyqthresh * 0.07384411893421103f, nyqthresh * 0.06207511968171489f, nyqthresh * 0.0521818194747806f, + nyqthresh * 0.03687419286733595f, nyqthresh * 0.03099732204057846f, nyqthresh * 0.018413194161458882f }; // gaussian on 5x5 alt quincunx, sigma=1.5 constexpr float gausseven[2] = { 0.13719494435797422f, 0.05640252782101291f }; // guassian on quincunx grid @@ -407,8 +407,7 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie constexpr int cldf = 2; // factor to multiply cache line distance. 1 = 64 bytes, 2 = 128 bytes ... // assign working space - char *buffer - = (char *)calloc(14 * sizeof(float) * ts * ts + sizeof(char) * ts * tsh + 18 * cldf * 64 + 63, 1); + char *buffer = (char *)calloc(14 * sizeof(float) * ts * ts + sizeof(char) * ts * tsh + 18 * cldf * 64 + 63, 1); // aligned to 64 byte boundary char *data = (char *)((uintptr_t(buffer) + uintptr_t(63)) / 64 * 64); @@ -668,8 +667,7 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie { float delh = fabsf(cfa[indx + 1] - cfa[indx - 1]); float delv = fabsf(cfa[indx + v1] - cfa[indx - v1]); - dirwts0[indx] - = eps + fabsf(cfa[indx + v2] - cfa[indx]) + fabsf(cfa[indx] - cfa[indx - v2]) + delv; + dirwts0[indx] = eps + fabsf(cfa[indx + v2] - cfa[indx]) + fabsf(cfa[indx] - cfa[indx - v2]) + delv; dirwts1[indx] = eps + fabsf(cfa[indx + 2] - cfa[indx]) + fabsf(cfa[indx] - cfa[indx - 2]) + delh; delhvsqsum[indx] = SQR(delh) + SQR(delv); } @@ -702,18 +700,18 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie { // colour ratios in each cardinal direction vfloat cfav = LVF(cfa[indx]); - vfloat cruv = LVF(cfa[indx - v1]) * (LVF(dirwts0[indx - v2]) + LVF(dirwts0[indx])) - / (LVF(dirwts0[indx - v2]) * (epsv + cfav) - + LVF(dirwts0[indx]) * (epsv + LVF(cfa[indx - v2]))); - vfloat crdv = LVF(cfa[indx + v1]) * (LVF(dirwts0[indx + v2]) + LVF(dirwts0[indx])) - / (LVF(dirwts0[indx + v2]) * (epsv + cfav) - + LVF(dirwts0[indx]) * (epsv + LVF(cfa[indx + v2]))); - vfloat crlv = LVFU(cfa[indx - 1]) * (LVFU(dirwts1[indx - 2]) + LVF(dirwts1[indx])) - / (LVFU(dirwts1[indx - 2]) * (epsv + cfav) - + LVF(dirwts1[indx]) * (epsv + LVFU(cfa[indx - 2]))); - vfloat crrv = LVFU(cfa[indx + 1]) * (LVFU(dirwts1[indx + 2]) + LVF(dirwts1[indx])) - / (LVFU(dirwts1[indx + 2]) * (epsv + cfav) - + LVF(dirwts1[indx]) * (epsv + LVFU(cfa[indx + 2]))); + vfloat cruv + = LVF(cfa[indx - v1]) * (LVF(dirwts0[indx - v2]) + LVF(dirwts0[indx])) + / (LVF(dirwts0[indx - v2]) * (epsv + cfav) + LVF(dirwts0[indx]) * (epsv + LVF(cfa[indx - v2]))); + vfloat crdv + = LVF(cfa[indx + v1]) * (LVF(dirwts0[indx + v2]) + LVF(dirwts0[indx])) + / (LVF(dirwts0[indx + v2]) * (epsv + cfav) + LVF(dirwts0[indx]) * (epsv + LVF(cfa[indx + v2]))); + vfloat crlv + = LVFU(cfa[indx - 1]) * (LVFU(dirwts1[indx - 2]) + LVF(dirwts1[indx])) + / (LVFU(dirwts1[indx - 2]) * (epsv + cfav) + LVF(dirwts1[indx]) * (epsv + LVFU(cfa[indx - 2]))); + vfloat crrv + = LVFU(cfa[indx + 1]) * (LVFU(dirwts1[indx + 2]) + LVF(dirwts1[indx])) + / (LVFU(dirwts1[indx + 2]) * (epsv + cfav) + LVF(dirwts1[indx]) * (epsv + LVFU(cfa[indx + 2]))); // G interpolated in vert/hor directions using Hamilton-Adams method vfloat guhav = LVF(cfa[indx - v1]) + zd5v * (cfav - LVF(cfa[indx - v2])); @@ -894,16 +892,14 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie for(int indx = rr * ts + 4; indx < rr * ts + cc1 - 4; indx += 4) { vfloat hcdv = LVF(hcd[indx]); - vfloat hcdvarv = SQRV(LVFU(hcd[indx - 2]) - hcdv) - + SQRV(LVFU(hcd[indx - 2]) - LVFU(hcd[indx + 2])) + vfloat hcdvarv = SQRV(LVFU(hcd[indx - 2]) - hcdv) + SQRV(LVFU(hcd[indx - 2]) - LVFU(hcd[indx + 2])) + SQRV(hcdv - LVFU(hcd[indx + 2])); vfloat hcdaltv = LVF(hcdalt[indx]); vfloat hcdaltvarv = SQRV(LVFU(hcdalt[indx - 2]) - hcdaltv) + SQRV(LVFU(hcdalt[indx - 2]) - LVFU(hcdalt[indx + 2])) + SQRV(hcdaltv - LVFU(hcdalt[indx + 2])); vfloat vcdv = LVF(vcd[indx]); - vfloat vcdvarv = SQRV(LVF(vcd[indx - v2]) - vcdv) - + SQRV(LVF(vcd[indx - v2]) - LVF(vcd[indx + v2])) + vfloat vcdvarv = SQRV(LVF(vcd[indx - v2]) - vcdv) + SQRV(LVF(vcd[indx - v2]) - LVF(vcd[indx + v2])) + SQRV(vcdv - LVF(vcd[indx + v2])); vfloat vcdaltv = LVF(vcdalt[indx]); vfloat vcdaltvarv = SQRV(LVF(vcdalt[indx - v2]) - vcdaltv) @@ -1207,27 +1203,26 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie for(; cc < cc1 - 7; cc += 8, indx += 8) { - vfloat valv - = (gausso0 * LC2VFU(cddiffsq[indx]) - + gausso1 * (LC2VFU(cddiffsq[(indx - m1)]) + LC2VFU(cddiffsq[(indx + p1)]) - + LC2VFU(cddiffsq[(indx - p1)]) + LC2VFU(cddiffsq[(indx + m1)])) - + gausso2 * (LC2VFU(cddiffsq[(indx - v2)]) + LC2VFU(cddiffsq[(indx - 2)]) - + LC2VFU(cddiffsq[(indx + 2)]) + LC2VFU(cddiffsq[(indx + v2)])) - + gausso3 * (LC2VFU(cddiffsq[(indx - m2)]) + LC2VFU(cddiffsq[(indx + p2)]) - + LC2VFU(cddiffsq[(indx - p2)]) + LC2VFU(cddiffsq[(indx + m2)]))) - - (gaussg0 * LC2VFU(delhvsqsum[indx]) - + gaussg1 * (LC2VFU(delhvsqsum[indx - v1]) + LC2VFU(delhvsqsum[indx - 1]) - + LC2VFU(delhvsqsum[indx + 1]) + LC2VFU(delhvsqsum[indx + v1])) - + gaussg2 * (LC2VFU(delhvsqsum[indx - m1]) + LC2VFU(delhvsqsum[indx + p1]) - + LC2VFU(delhvsqsum[indx - p1]) + LC2VFU(delhvsqsum[indx + m1])) - + gaussg3 * (LC2VFU(delhvsqsum[indx - v2]) + LC2VFU(delhvsqsum[indx - 2]) - + LC2VFU(delhvsqsum[indx + 2]) + LC2VFU(delhvsqsum[indx + v2])) - + gaussg4 * (LC2VFU(delhvsqsum[indx - v2 - 1]) + LC2VFU(delhvsqsum[indx - v2 + 1]) - + LC2VFU(delhvsqsum[indx - ts - 2]) + LC2VFU(delhvsqsum[indx - ts + 2]) - + LC2VFU(delhvsqsum[indx + ts - 2]) + LC2VFU(delhvsqsum[indx + ts + 2]) - + LC2VFU(delhvsqsum[indx + v2 - 1]) + LC2VFU(delhvsqsum[indx + v2 + 1])) - + gaussg5 * (LC2VFU(delhvsqsum[indx - m2]) + LC2VFU(delhvsqsum[indx + p2]) - + LC2VFU(delhvsqsum[indx - p2]) + LC2VFU(delhvsqsum[indx + m2]))); + vfloat valv = (gausso0 * LC2VFU(cddiffsq[indx]) + + gausso1 * (LC2VFU(cddiffsq[(indx - m1)]) + LC2VFU(cddiffsq[(indx + p1)]) + + LC2VFU(cddiffsq[(indx - p1)]) + LC2VFU(cddiffsq[(indx + m1)])) + + gausso2 * (LC2VFU(cddiffsq[(indx - v2)]) + LC2VFU(cddiffsq[(indx - 2)]) + + LC2VFU(cddiffsq[(indx + 2)]) + LC2VFU(cddiffsq[(indx + v2)])) + + gausso3 * (LC2VFU(cddiffsq[(indx - m2)]) + LC2VFU(cddiffsq[(indx + p2)]) + + LC2VFU(cddiffsq[(indx - p2)]) + LC2VFU(cddiffsq[(indx + m2)]))) + - (gaussg0 * LC2VFU(delhvsqsum[indx]) + + gaussg1 * (LC2VFU(delhvsqsum[indx - v1]) + LC2VFU(delhvsqsum[indx - 1]) + + LC2VFU(delhvsqsum[indx + 1]) + LC2VFU(delhvsqsum[indx + v1])) + + gaussg2 * (LC2VFU(delhvsqsum[indx - m1]) + LC2VFU(delhvsqsum[indx + p1]) + + LC2VFU(delhvsqsum[indx - p1]) + LC2VFU(delhvsqsum[indx + m1])) + + gaussg3 * (LC2VFU(delhvsqsum[indx - v2]) + LC2VFU(delhvsqsum[indx - 2]) + + LC2VFU(delhvsqsum[indx + 2]) + LC2VFU(delhvsqsum[indx + v2])) + + gaussg4 * (LC2VFU(delhvsqsum[indx - v2 - 1]) + LC2VFU(delhvsqsum[indx - v2 + 1]) + + LC2VFU(delhvsqsum[indx - ts - 2]) + LC2VFU(delhvsqsum[indx - ts + 2]) + + LC2VFU(delhvsqsum[indx + ts - 2]) + LC2VFU(delhvsqsum[indx + ts + 2]) + + LC2VFU(delhvsqsum[indx + v2 - 1]) + LC2VFU(delhvsqsum[indx + v2 + 1])) + + gaussg5 * (LC2VFU(delhvsqsum[indx - m2]) + LC2VFU(delhvsqsum[indx + p2]) + + LC2VFU(delhvsqsum[indx - p2]) + LC2VFU(delhvsqsum[indx + m2]))); STVFU(nyqutest[indx >> 1], valv); } @@ -1235,27 +1230,26 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie for(; cc < cc1 - 6; cc += 2, indx += 2) { - nyqutest[indx >> 1] - = (gaussodd[0] * cddiffsq[indx] - + gaussodd[1] * (cddiffsq[(indx - m1)] + cddiffsq[(indx + p1)] + cddiffsq[(indx - p1)] - + cddiffsq[(indx + m1)]) - + gaussodd[2] * (cddiffsq[(indx - v2)] + cddiffsq[(indx - 2)] + cddiffsq[(indx + 2)] - + cddiffsq[(indx + v2)]) - + gaussodd[3] * (cddiffsq[(indx - m2)] + cddiffsq[(indx + p2)] + cddiffsq[(indx - p2)] - + cddiffsq[(indx + m2)])) - - (gaussgrad[0] * delhvsqsum[indx] - + gaussgrad[1] * (delhvsqsum[indx - v1] + delhvsqsum[indx + 1] + delhvsqsum[indx - 1] - + delhvsqsum[indx + v1]) - + gaussgrad[2] * (delhvsqsum[indx - m1] + delhvsqsum[indx + p1] + delhvsqsum[indx - p1] - + delhvsqsum[indx + m1]) - + gaussgrad[3] * (delhvsqsum[indx - v2] + delhvsqsum[indx - 2] + delhvsqsum[indx + 2] - + delhvsqsum[indx + v2]) - + gaussgrad[4] * (delhvsqsum[indx - v2 - 1] + delhvsqsum[indx - v2 + 1] - + delhvsqsum[indx - ts - 2] + delhvsqsum[indx - ts + 2] - + delhvsqsum[indx + ts - 2] + delhvsqsum[indx + ts + 2] - + delhvsqsum[indx + v2 - 1] + delhvsqsum[indx + v2 + 1]) - + gaussgrad[5] * (delhvsqsum[indx - m2] + delhvsqsum[indx + p2] + delhvsqsum[indx - p2] - + delhvsqsum[indx + m2])); + nyqutest[indx >> 1] = (gaussodd[0] * cddiffsq[indx] + + gaussodd[1] * (cddiffsq[(indx - m1)] + cddiffsq[(indx + p1)] + + cddiffsq[(indx - p1)] + cddiffsq[(indx + m1)]) + + gaussodd[2] * (cddiffsq[(indx - v2)] + cddiffsq[(indx - 2)] + + cddiffsq[(indx + 2)] + cddiffsq[(indx + v2)]) + + gaussodd[3] * (cddiffsq[(indx - m2)] + cddiffsq[(indx + p2)] + + cddiffsq[(indx - p2)] + cddiffsq[(indx + m2)])) + - (gaussgrad[0] * delhvsqsum[indx] + + gaussgrad[1] * (delhvsqsum[indx - v1] + delhvsqsum[indx + 1] + + delhvsqsum[indx - 1] + delhvsqsum[indx + v1]) + + gaussgrad[2] * (delhvsqsum[indx - m1] + delhvsqsum[indx + p1] + + delhvsqsum[indx - p1] + delhvsqsum[indx + m1]) + + gaussgrad[3] * (delhvsqsum[indx - v2] + delhvsqsum[indx - 2] + + delhvsqsum[indx + 2] + delhvsqsum[indx + v2]) + + gaussgrad[4] * (delhvsqsum[indx - v2 - 1] + delhvsqsum[indx - v2 + 1] + + delhvsqsum[indx - ts - 2] + delhvsqsum[indx - ts + 2] + + delhvsqsum[indx + ts - 2] + delhvsqsum[indx + ts + 2] + + delhvsqsum[indx + v2 - 1] + delhvsqsum[indx + v2 + 1]) + + gaussgrad[5] * (delhvsqsum[indx - m2] + delhvsqsum[indx + p2] + + delhvsqsum[indx - p2] + delhvsqsum[indx + m2])); } } @@ -1328,8 +1322,7 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie #else - for(int indx = rr * ts + nystartcol + (FC(rr, 2, filters) & 1); indx < rr * ts + nyendcol; - indx += 2) + for(int indx = rr * ts + nystartcol + (FC(rr, 2, filters) & 1); indx < rr * ts + nyendcol; indx += 2) { unsigned int nyquisttemp = (nyquist[(indx - v2) >> 1] + nyquist[(indx - m1) >> 1] + nyquist[(indx + p1) >> 1] @@ -1346,8 +1339,7 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie // in areas of Nyquist texture, do area interpolation for(int rr = nystartrow; rr < nyendrow; rr++) - for(int indx = rr * ts + nystartcol + (FC(rr, 2, filters) & 1); indx < rr * ts + nyendcol; - indx += 2) + for(int indx = rr * ts + nystartcol + (FC(rr, 2, filters) & 1); indx < rr * ts + nyendcol; indx += 2) { if(nyquist2[indx >> 1]) @@ -1399,8 +1391,7 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie + hvwt[(indx + m1) >> 1], 2); - hvwt[indx >> 1] - = fabsf(0.5f - hvwt[indx >> 1]) < fabsf(0.5f - hvwtalt) ? hvwtalt : hvwt[indx >> 1]; + hvwt[indx >> 1] = fabsf(0.5f - hvwt[indx >> 1]) < fabsf(0.5f - hvwtalt) ? hvwtalt : hvwt[indx >> 1]; // a better result was obtained from the neighbours Dgrb[0][indx >> 1] = intp(hvwt[indx >> 1], vcd[indx], hcd[indx]); // evaluate colour differences @@ -1423,29 +1414,26 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie if(doNyquist) { for(int rr = nystartrow; rr < nyendrow; rr++) - for(int indx = rr * ts + nystartcol + (FC(rr, 2, filters) & 1); indx < rr * ts + nyendcol; - indx += 2) + for(int indx = rr * ts + nystartcol + (FC(rr, 2, filters) & 1); indx < rr * ts + nyendcol; indx += 2) { if(nyquist2[indx >> 1]) { // local averages (over Nyquist pixels only) of G curvature squared - float gvarh - = epssq + (gquinc[0] * Dgrb2[indx >> 1].h - + gquinc[1] * (Dgrb2[(indx - m1) >> 1].h + Dgrb2[(indx + p1) >> 1].h - + Dgrb2[(indx - p1) >> 1].h + Dgrb2[(indx + m1) >> 1].h) - + gquinc[2] * (Dgrb2[(indx - v2) >> 1].h + Dgrb2[(indx - 2) >> 1].h - + Dgrb2[(indx + 2) >> 1].h + Dgrb2[(indx + v2) >> 1].h) - + gquinc[3] * (Dgrb2[(indx - m2) >> 1].h + Dgrb2[(indx + p2) >> 1].h - + Dgrb2[(indx - p2) >> 1].h + Dgrb2[(indx + m2) >> 1].h)); - float gvarv - = epssq + (gquinc[0] * Dgrb2[indx >> 1].v - + gquinc[1] * (Dgrb2[(indx - m1) >> 1].v + Dgrb2[(indx + p1) >> 1].v - + Dgrb2[(indx - p1) >> 1].v + Dgrb2[(indx + m1) >> 1].v) - + gquinc[2] * (Dgrb2[(indx - v2) >> 1].v + Dgrb2[(indx - 2) >> 1].v - + Dgrb2[(indx + 2) >> 1].v + Dgrb2[(indx + v2) >> 1].v) - + gquinc[3] * (Dgrb2[(indx - m2) >> 1].v + Dgrb2[(indx + p2) >> 1].v - + Dgrb2[(indx - p2) >> 1].v + Dgrb2[(indx + m2) >> 1].v)); + float gvarh = epssq + (gquinc[0] * Dgrb2[indx >> 1].h + + gquinc[1] * (Dgrb2[(indx - m1) >> 1].h + Dgrb2[(indx + p1) >> 1].h + + Dgrb2[(indx - p1) >> 1].h + Dgrb2[(indx + m1) >> 1].h) + + gquinc[2] * (Dgrb2[(indx - v2) >> 1].h + Dgrb2[(indx - 2) >> 1].h + + Dgrb2[(indx + 2) >> 1].h + Dgrb2[(indx + v2) >> 1].h) + + gquinc[3] * (Dgrb2[(indx - m2) >> 1].h + Dgrb2[(indx + p2) >> 1].h + + Dgrb2[(indx - p2) >> 1].h + Dgrb2[(indx + m2) >> 1].h)); + float gvarv = epssq + (gquinc[0] * Dgrb2[indx >> 1].v + + gquinc[1] * (Dgrb2[(indx - m1) >> 1].v + Dgrb2[(indx + p1) >> 1].v + + Dgrb2[(indx - p1) >> 1].v + Dgrb2[(indx + m1) >> 1].v) + + gquinc[2] * (Dgrb2[(indx - v2) >> 1].v + Dgrb2[(indx - 2) >> 1].v + + Dgrb2[(indx + 2) >> 1].v + Dgrb2[(indx + v2) >> 1].v) + + gquinc[3] * (Dgrb2[(indx - m2) >> 1].v + Dgrb2[(indx + p2) >> 1].v + + Dgrb2[(indx - p2) >> 1].v + Dgrb2[(indx + m2) >> 1].v)); // use the results as weights for refined G interpolation Dgrb[0][indx >> 1] = (hcd[indx] * gvarv + vcd[indx] * gvarh) / (gvarv + gvarh); rgbgreen[indx] = cfa[indx] + Dgrb[0][indx >> 1]; @@ -1478,12 +1466,10 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie for(int cc = 6, indx = rr * ts + cc; cc < cc1 - 6; cc += 8, indx += 8) { vfloat tempv = LC2VFU(cfa[indx]); - vfloat Dgrbsq1pv - = (SQRV(tempv - LC2VFU(cfa[indx - p1])) + SQRV(tempv - LC2VFU(cfa[indx + p1]))); + vfloat Dgrbsq1pv = (SQRV(tempv - LC2VFU(cfa[indx - p1])) + SQRV(tempv - LC2VFU(cfa[indx + p1]))); STVFU(delp[indx >> 1], vabsf(LC2VFU(cfa[indx + 1 + p1]) - LC2VFU(cfa[indx + 1 - p1]))); STVFU(delm[indx >> 1], vabsf(LC2VFU(cfa[indx + 1 + m1]) - LC2VFU(cfa[indx + 1 - m1]))); - vfloat Dgrbsq1mv - = (SQRV(tempv - LC2VFU(cfa[indx - m1])) + SQRV(tempv - LC2VFU(cfa[indx + m1]))); + vfloat Dgrbsq1mv = (SQRV(tempv - LC2VFU(cfa[indx - m1])) + SQRV(tempv - LC2VFU(cfa[indx + m1]))); STVFU(Dgrbsq1m[indx >> 1], Dgrbsq1mv); STVFU(Dgrbsq1p[indx >> 1], Dgrbsq1pv); } @@ -1541,14 +1527,14 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie vfloat temp1v = LC2VFU(cfa[indx + m1]); vfloat temp2v = LC2VFU(cfa[indx + m2]); vfloat rbsev = vmul2f(temp1v) / (epsv + cfav + temp2v); - rbsev = vself(vmaskf_lt(vabsf(onev - rbsev), arthreshv), cfav * rbsev, - temp1v + zd5v * (cfav - temp2v)); + rbsev + = vself(vmaskf_lt(vabsf(onev - rbsev), arthreshv), cfav * rbsev, temp1v + zd5v * (cfav - temp2v)); temp1v = LC2VFU(cfa[indx - m1]); temp2v = LC2VFU(cfa[indx - m2]); vfloat rbnwv = vmul2f(temp1v) / (epsv + cfav + temp2v); - rbnwv = vself(vmaskf_lt(vabsf(onev - rbnwv), arthreshv), cfav * rbnwv, - temp1v + zd5v * (cfav - temp2v)); + rbnwv + = vself(vmaskf_lt(vabsf(onev - rbnwv), arthreshv), cfav * rbnwv, temp1v + zd5v * (cfav - temp2v)); temp1v = epsv + LVFU(delm[indx1]); vfloat wtsev = temp1v + LVFU(delm[(indx + m1) >> 1]) @@ -1570,14 +1556,14 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie temp1v = LC2VFU(cfa[indx + p1]); temp2v = LC2VFU(cfa[indx + p2]); vfloat rbnev = vmul2f(temp1v) / (epsv + cfav + temp2v); - rbnev = vself(vmaskf_lt(vabsf(onev - rbnev), arthreshv), cfav * rbnev, - temp1v + zd5v * (cfav - temp2v)); + rbnev + = vself(vmaskf_lt(vabsf(onev - rbnev), arthreshv), cfav * rbnev, temp1v + zd5v * (cfav - temp2v)); temp1v = LC2VFU(cfa[indx - p1]); temp2v = LC2VFU(cfa[indx - p2]); vfloat rbswv = vmul2f(temp1v) / (epsv + cfav + temp2v); - rbswv = vself(vmaskf_lt(vabsf(onev - rbswv), arthreshv), cfav * rbswv, - temp1v + zd5v * (cfav - temp2v)); + rbswv + = vself(vmaskf_lt(vabsf(onev - rbswv), arthreshv), cfav * rbswv, temp1v + zd5v * (cfav - temp2v)); temp1v = epsv + LVFU(delp[indx1]); vfloat wtnev = temp1v + LVFU(delp[(indx + p1) >> 1]) + LVFU(delp[(indx + p2) >> 1]); @@ -1604,19 +1590,16 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie + LVFU(Dgrbsq1m[(indx - 2 + v1) >> 1]) + LVFU(Dgrbsq1m[(indx + 2 + v1) >> 1]) + LVFU(Dgrbsq1m[(indx + v2 - 1) >> 1]) + LVFU(Dgrbsq1m[(indx + v2 + 1) >> 1]))); STVFU(pmwt[indx1], - rbvarmv / ((epssqv - + (gausseven0v - * (LVFU(Dgrbsq1p[(indx - v1) >> 1]) + LVFU(Dgrbsq1p[(indx - 1) >> 1]) - + LVFU(Dgrbsq1p[(indx + 1) >> 1]) + LVFU(Dgrbsq1p[(indx + v1) >> 1])) - + gausseven1v * (LVFU(Dgrbsq1p[(indx - v2 - 1) >> 1]) - + LVFU(Dgrbsq1p[(indx - v2 + 1) >> 1]) - + LVFU(Dgrbsq1p[(indx - 2 - v1) >> 1]) - + LVFU(Dgrbsq1p[(indx + 2 - v1) >> 1]) - + LVFU(Dgrbsq1p[(indx - 2 + v1) >> 1]) - + LVFU(Dgrbsq1p[(indx + 2 + v1) >> 1]) - + LVFU(Dgrbsq1p[(indx + v2 - 1) >> 1]) - + LVFU(Dgrbsq1p[(indx + v2 + 1) >> 1])))) - + rbvarmv)); + rbvarmv + / ((epssqv + + (gausseven0v * (LVFU(Dgrbsq1p[(indx - v1) >> 1]) + LVFU(Dgrbsq1p[(indx - 1) >> 1]) + + LVFU(Dgrbsq1p[(indx + 1) >> 1]) + LVFU(Dgrbsq1p[(indx + v1) >> 1])) + + gausseven1v + * (LVFU(Dgrbsq1p[(indx - v2 - 1) >> 1]) + LVFU(Dgrbsq1p[(indx - v2 + 1) >> 1]) + + LVFU(Dgrbsq1p[(indx - 2 - v1) >> 1]) + LVFU(Dgrbsq1p[(indx + 2 - v1) >> 1]) + + LVFU(Dgrbsq1p[(indx - 2 + v1) >> 1]) + LVFU(Dgrbsq1p[(indx + 2 + v1) >> 1]) + + LVFU(Dgrbsq1p[(indx + v2 - 1) >> 1]) + + LVFU(Dgrbsq1p[(indx + v2 + 1) >> 1])))) + rbvarmv)); } #else @@ -1682,23 +1665,21 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie // variance of R-B in plus/minus directions float rbvarm - = epssq - + (gausseven[0] * (Dgrbsq1m[(indx - v1) >> 1] + Dgrbsq1m[(indx - 1) >> 1] - + Dgrbsq1m[(indx + 1) >> 1] + Dgrbsq1m[(indx + v1) >> 1]) - + gausseven[1] * (Dgrbsq1m[(indx - v2 - 1) >> 1] + Dgrbsq1m[(indx - v2 + 1) >> 1] - + Dgrbsq1m[(indx - 2 - v1) >> 1] + Dgrbsq1m[(indx + 2 - v1) >> 1] - + Dgrbsq1m[(indx - 2 + v1) >> 1] + Dgrbsq1m[(indx + 2 + v1) >> 1] - + Dgrbsq1m[(indx + v2 - 1) >> 1] + Dgrbsq1m[(indx + v2 + 1) >> 1])); + = epssq + (gausseven[0] * (Dgrbsq1m[(indx - v1) >> 1] + Dgrbsq1m[(indx - 1) >> 1] + + Dgrbsq1m[(indx + 1) >> 1] + Dgrbsq1m[(indx + v1) >> 1]) + + gausseven[1] * (Dgrbsq1m[(indx - v2 - 1) >> 1] + Dgrbsq1m[(indx - v2 + 1) >> 1] + + Dgrbsq1m[(indx - 2 - v1) >> 1] + Dgrbsq1m[(indx + 2 - v1) >> 1] + + Dgrbsq1m[(indx - 2 + v1) >> 1] + Dgrbsq1m[(indx + 2 + v1) >> 1] + + Dgrbsq1m[(indx + v2 - 1) >> 1] + Dgrbsq1m[(indx + v2 + 1) >> 1])); pmwt[indx1] = rbvarm / ((epssq + (gausseven[0] * (Dgrbsq1p[(indx - v1) >> 1] + Dgrbsq1p[(indx - 1) >> 1] + Dgrbsq1p[(indx + 1) >> 1] + Dgrbsq1p[(indx + v1) >> 1]) - + gausseven[1] - * (Dgrbsq1p[(indx - v2 - 1) >> 1] + Dgrbsq1p[(indx - v2 + 1) >> 1] - + Dgrbsq1p[(indx - 2 - v1) >> 1] + Dgrbsq1p[(indx + 2 - v1) >> 1] - + Dgrbsq1p[(indx - 2 + v1) >> 1] + Dgrbsq1p[(indx + 2 + v1) >> 1] - + Dgrbsq1p[(indx + v2 - 1) >> 1] + Dgrbsq1p[(indx + v2 + 1) >> 1]))) - + rbvarm); + + gausseven[1] * (Dgrbsq1p[(indx - v2 - 1) >> 1] + Dgrbsq1p[(indx - v2 + 1) >> 1] + + Dgrbsq1p[(indx - 2 - v1) >> 1] + Dgrbsq1p[(indx + 2 - v1) >> 1] + + Dgrbsq1p[(indx - 2 + v1) >> 1] + Dgrbsq1p[(indx + 2 + v1) >> 1] + + Dgrbsq1p[(indx + v2 - 1) >> 1] + + Dgrbsq1p[(indx + v2 + 1) >> 1]))) + rbvarm); // bound the interpolation in regions of high saturation @@ -1711,8 +1692,7 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie else { float pwt = xmul2f(cfa[indx] - rbp[indx1]) / (eps + rbp[indx1] + cfa[indx]); - rbp[indx1] - = pwt * rbp[indx1] + (1.f - pwt) * ULIM(rbp[indx1], cfa[indx - p1], cfa[indx + p1]); + rbp[indx1] = pwt * rbp[indx1] + (1.f - pwt) * ULIM(rbp[indx1], cfa[indx - p1], cfa[indx + p1]); } } @@ -1725,8 +1705,7 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie else { float mwt = xmul2f(cfa[indx] - rbm[indx1]) / (eps + rbm[indx1] + cfa[indx]); - rbm[indx1] - = mwt * rbm[indx1] + (1.f - mwt) * ULIM(rbm[indx1], cfa[indx - m1], cfa[indx + m1]); + rbm[indx1] = mwt * rbm[indx1] + (1.f - mwt) * ULIM(rbm[indx1], cfa[indx - m1], cfa[indx + m1]); } } @@ -1750,8 +1729,8 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie for(int rr = 10; rr < rr1 - 10; rr++) #ifdef __SSE2__ - for(int indx = rr * ts + 10 + (FC(rr, 2, filters) & 1), indx1 = indx >> 1; - indx < rr * ts + cc1 - 10; indx += 8, indx1 += 4) + for(int indx = rr * ts + 10 + (FC(rr, 2, filters) & 1), indx1 = indx >> 1; indx < rr * ts + cc1 - 10; + indx += 8, indx1 += 4) { // first ask if one gets more directional discrimination from nearby B/R sites @@ -1760,8 +1739,7 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie vfloat tempv = LVFU(pmwt[indx1]); tempv = vself(vmaskf_lt(vabsf(zd5v - tempv), vabsf(zd5v - pmwtaltv)), pmwtaltv, tempv); STVFU(pmwt[indx1], tempv); - STVFU(rbint[indx1], - zd5v * (LC2VFU(cfa[indx]) + vintpf(tempv, LVFU(rbp[indx1]), LVFU(rbm[indx1])))); + STVFU(rbint[indx1], zd5v * (LC2VFU(cfa[indx]) + vintpf(tempv, LVFU(rbp[indx1]), LVFU(rbm[indx1])))); } #else @@ -1788,8 +1766,8 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie for(int rr = 12; rr < rr1 - 12; rr++) #ifdef __SSE2__ - for(int indx = rr * ts + 12 + (FC(rr, 2, filters) & 1), indx1 = indx >> 1; - indx < rr * ts + cc1 - 12; indx += 8, indx1 += 4) + for(int indx = rr * ts + 12 + (FC(rr, 2, filters) & 1), indx1 = indx >> 1; indx < rr * ts + cc1 - 12; + indx += 8, indx1 += 4) { vmask copymask = vmaskf_ge(vabsf(zd5v - LVFU(pmwt[indx1])), vabsf(zd5v - LVFU(hvwt[indx1]))); @@ -1842,8 +1820,7 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie Ginthv = vself(vmaskf_gt(Ginthv, clip_ptv), ULIMV(Ginthv, LC2VFU(cfa[indx - 1]), LC2VFU(cfa[indx + 1])), Ginthv); - vfloat greenv - = vself(copymask, vintpf(LVFU(hvwt[indx1]), Gintvv, Ginthv), LC2VFU(rgbgreen[indx])); + vfloat greenv = vself(copymask, vintpf(LVFU(hvwt[indx1]), Gintvv, Ginthv), LC2VFU(rgbgreen[indx])); STC2VFU(rgbgreen[indx], greenv); STVFU(Dgrb[0][indx1], vself(copymask, greenv - LC2VFU(cfa[indx]), LVFU(Dgrb[0][indx1]))); @@ -1913,8 +1890,8 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie // interpolated G via adaptive weights of cardinal evaluations float Gintv = (dirwts0[indx - v1] * gd + dirwts0[indx + v1] * gu) / (dirwts0[indx + v1] + dirwts0[indx - v1]); - float Ginth - = (dirwts1[indx - 1] * gr + dirwts1[indx + 1] * gl) / (dirwts1[indx - 1] + dirwts1[indx + 1]); + float Ginth = (dirwts1[indx - 1] * gr + dirwts1[indx + 1] * gl) + / (dirwts1[indx - 1] + dirwts1[indx + 1]); // bound the interpolation in regions of high saturation if(Gintv < rbint[indx1]) @@ -1983,36 +1960,29 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie { vfloat tempv = epsv + vabsf(LVFU(Dgrb[c][(indx - m1) >> 1]) - LVFU(Dgrb[c][(indx + m1) >> 1])); vfloat temp2v = epsv + vabsf(LVFU(Dgrb[c][(indx + p1) >> 1]) - LVFU(Dgrb[c][(indx - p1) >> 1])); - vfloat wtnwv - = onev / (tempv + vabsf(LVFU(Dgrb[c][(indx - m1) >> 1]) - LVFU(Dgrb[c][(indx - m3) >> 1])) - + vabsf(LVFU(Dgrb[c][(indx + m1) >> 1]) - LVFU(Dgrb[c][(indx - m3) >> 1]))); - vfloat wtnev - = onev / (temp2v + vabsf(LVFU(Dgrb[c][(indx + p1) >> 1]) - LVFU(Dgrb[c][(indx + p3) >> 1])) - + vabsf(LVFU(Dgrb[c][(indx - p1) >> 1]) - LVFU(Dgrb[c][(indx + p3) >> 1]))); - vfloat wtswv - = onev / (temp2v + vabsf(LVFU(Dgrb[c][(indx - p1) >> 1]) - LVFU(Dgrb[c][(indx + m3) >> 1])) - + vabsf(LVFU(Dgrb[c][(indx + p1) >> 1]) - LVFU(Dgrb[c][(indx - p3) >> 1]))); - vfloat wtsev - = onev / (tempv + vabsf(LVFU(Dgrb[c][(indx + m1) >> 1]) - LVFU(Dgrb[c][(indx - p3) >> 1])) - + vabsf(LVFU(Dgrb[c][(indx - m1) >> 1]) - LVFU(Dgrb[c][(indx + m3) >> 1]))); - - STVFU(Dgrb[c][indx >> 1], (wtnwv * (oned325v * LVFU(Dgrb[c][(indx - m1) >> 1]) - - zd175v * LVFU(Dgrb[c][(indx - m3) >> 1]) - - zd075v * (LVFU(Dgrb[c][(indx - m1 - 2) >> 1]) - + LVFU(Dgrb[c][(indx - m1 - v2) >> 1]))) - + wtnev * (oned325v * LVFU(Dgrb[c][(indx + p1) >> 1]) - - zd175v * LVFU(Dgrb[c][(indx + p3) >> 1]) - - zd075v * (LVFU(Dgrb[c][(indx + p1 + 2) >> 1]) - + LVFU(Dgrb[c][(indx + p1 + v2) >> 1]))) - + wtswv * (oned325v * LVFU(Dgrb[c][(indx - p1) >> 1]) - - zd175v * LVFU(Dgrb[c][(indx - p3) >> 1]) - - zd075v * (LVFU(Dgrb[c][(indx - p1 - 2) >> 1]) - + LVFU(Dgrb[c][(indx - p1 - v2) >> 1]))) - + wtsev * (oned325v * LVFU(Dgrb[c][(indx + m1) >> 1]) - - zd175v * LVFU(Dgrb[c][(indx + m3) >> 1]) - - zd075v * (LVFU(Dgrb[c][(indx + m1 + 2) >> 1]) - + LVFU(Dgrb[c][(indx + m1 + v2) >> 1])))) - / (wtnwv + wtnev + wtswv + wtsev)); + vfloat wtnwv = onev / (tempv + vabsf(LVFU(Dgrb[c][(indx - m1) >> 1]) - LVFU(Dgrb[c][(indx - m3) >> 1])) + + vabsf(LVFU(Dgrb[c][(indx + m1) >> 1]) - LVFU(Dgrb[c][(indx - m3) >> 1]))); + vfloat wtnev = onev + / (temp2v + vabsf(LVFU(Dgrb[c][(indx + p1) >> 1]) - LVFU(Dgrb[c][(indx + p3) >> 1])) + + vabsf(LVFU(Dgrb[c][(indx - p1) >> 1]) - LVFU(Dgrb[c][(indx + p3) >> 1]))); + vfloat wtswv = onev + / (temp2v + vabsf(LVFU(Dgrb[c][(indx - p1) >> 1]) - LVFU(Dgrb[c][(indx + m3) >> 1])) + + vabsf(LVFU(Dgrb[c][(indx + p1) >> 1]) - LVFU(Dgrb[c][(indx - p3) >> 1]))); + vfloat wtsev = onev / (tempv + vabsf(LVFU(Dgrb[c][(indx + m1) >> 1]) - LVFU(Dgrb[c][(indx - p3) >> 1])) + + vabsf(LVFU(Dgrb[c][(indx - m1) >> 1]) - LVFU(Dgrb[c][(indx + m3) >> 1]))); + + STVFU( + Dgrb[c][indx >> 1], + (wtnwv * (oned325v * LVFU(Dgrb[c][(indx - m1) >> 1]) - zd175v * LVFU(Dgrb[c][(indx - m3) >> 1]) + - zd075v * (LVFU(Dgrb[c][(indx - m1 - 2) >> 1]) + LVFU(Dgrb[c][(indx - m1 - v2) >> 1]))) + + wtnev * (oned325v * LVFU(Dgrb[c][(indx + p1) >> 1]) - zd175v * LVFU(Dgrb[c][(indx + p3) >> 1]) + - zd075v * (LVFU(Dgrb[c][(indx + p1 + 2) >> 1]) + LVFU(Dgrb[c][(indx + p1 + v2) >> 1]))) + + wtswv * (oned325v * LVFU(Dgrb[c][(indx - p1) >> 1]) - zd175v * LVFU(Dgrb[c][(indx - p3) >> 1]) + - zd075v * (LVFU(Dgrb[c][(indx - p1 - 2) >> 1]) + LVFU(Dgrb[c][(indx - p1 - v2) >> 1]))) + + wtsev + * (oned325v * LVFU(Dgrb[c][(indx + m1) >> 1]) - zd175v * LVFU(Dgrb[c][(indx + m3) >> 1]) + - zd075v * (LVFU(Dgrb[c][(indx + m1 + 2) >> 1]) + LVFU(Dgrb[c][(indx + m1 + v2) >> 1])))) + / (wtnwv + wtnev + wtswv + wtsev)); } #else @@ -2037,14 +2007,11 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie = (wtnw * (1.325f * Dgrb[c][(indx - m1) >> 1] - 0.175f * Dgrb[c][(indx - m3) >> 1] - 0.075f * Dgrb[c][(indx - m1 - 2) >> 1] - 0.075f * Dgrb[c][(indx - m1 - v2) >> 1]) + wtne * (1.325f * Dgrb[c][(indx + p1) >> 1] - 0.175f * Dgrb[c][(indx + p3) >> 1] - - 0.075f * Dgrb[c][(indx + p1 + 2) >> 1] - - 0.075f * Dgrb[c][(indx + p1 + v2) >> 1]) + - 0.075f * Dgrb[c][(indx + p1 + 2) >> 1] - 0.075f * Dgrb[c][(indx + p1 + v2) >> 1]) + wtsw * (1.325f * Dgrb[c][(indx - p1) >> 1] - 0.175f * Dgrb[c][(indx - p3) >> 1] - - 0.075f * Dgrb[c][(indx - p1 - 2) >> 1] - - 0.075f * Dgrb[c][(indx - p1 - v2) >> 1]) + - 0.075f * Dgrb[c][(indx - p1 - 2) >> 1] - 0.075f * Dgrb[c][(indx - p1 - v2) >> 1]) + wtse * (1.325f * Dgrb[c][(indx + m1) >> 1] - 0.175f * Dgrb[c][(indx + m3) >> 1] - - 0.075f * Dgrb[c][(indx + m1 + 2) >> 1] - - 0.075f * Dgrb[c][(indx + m1 + v2) >> 1])) + - 0.075f * Dgrb[c][(indx + m1 + 2) >> 1] - 0.075f * Dgrb[c][(indx + m1 + v2) >> 1])) / (wtnw + wtne + wtsw + wtse); } @@ -2093,16 +2060,14 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie * vdup(LVFU(Dgrb[0][(indx + 1 + offset) >> 1])) + (onev - vdup(LVFU(hvwt[(indx - 1 + offset) >> 1]))) * vdup(LVFU(Dgrb[0][(indx - 1 + offset) >> 1])) - + temp01v * vdup(LVFU(Dgrb[0][(indx + v1) >> 1]))) - * tempv; + + temp01v * vdup(LVFU(Dgrb[0][(indx + v1) >> 1]))) * tempv; vfloat bluev1 = greenv - (temp00v * vdup(LVFU(Dgrb[1][(indx - v1) >> 1])) + (onev - vdup(LVFU(hvwt[(indx + 1 + offset) >> 1]))) * vdup(LVFU(Dgrb[1][(indx + 1 + offset) >> 1])) + (onev - vdup(LVFU(hvwt[(indx - 1 + offset) >> 1]))) * vdup(LVFU(Dgrb[1][(indx - 1 + offset) >> 1])) - + temp01v * vdup(LVFU(Dgrb[1][(indx + v1) >> 1]))) - * tempv; + + temp01v * vdup(LVFU(Dgrb[1][(indx + v1) >> 1]))) * tempv; vfloat redv2 = greenv - vdup(LVFU(Dgrb[0][indx >> 1])); vfloat bluev2 = greenv - vdup(LVFU(Dgrb[1][indx >> 1])); __attribute__((aligned(16))) float _r[4]; @@ -2123,23 +2088,21 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie { if(col < roi_out->width && row < roi_out->height) { - float temp = 1.f / (hvwt[(indx - v1) >> 1] + 2.f - hvwt[(indx + 1) >> 1] - - hvwt[(indx - 1) >> 1] + hvwt[(indx + v1) >> 1]); + float temp = 1.f / (hvwt[(indx - v1) >> 1] + 2.f - hvwt[(indx + 1) >> 1] - hvwt[(indx - 1) >> 1] + + hvwt[(indx + v1) >> 1]); out[(row * roi_out->width + col) * 4] = clampnan(rgbgreen[indx] - ((hvwt[(indx - v1) >> 1]) * Dgrb[0][(indx - v1) >> 1] + (1.f - hvwt[(indx + 1) >> 1]) * Dgrb[0][(indx + 1) >> 1] + (1.f - hvwt[(indx - 1) >> 1]) * Dgrb[0][(indx - 1) >> 1] - + (hvwt[(indx + v1) >> 1]) * Dgrb[0][(indx + v1) >> 1]) - * temp, + + (hvwt[(indx + v1) >> 1]) * Dgrb[0][(indx + v1) >> 1]) * temp, 0.0, 1.0); out[(row * roi_out->width + col) * 4 + 2] = clampnan(rgbgreen[indx] - ((hvwt[(indx - v1) >> 1]) * Dgrb[1][(indx - v1) >> 1] + (1.f - hvwt[(indx + 1) >> 1]) * Dgrb[1][(indx + 1) >> 1] + (1.f - hvwt[(indx - 1) >> 1]) * Dgrb[1][(indx - 1) >> 1] - + (hvwt[(indx + v1) >> 1]) * Dgrb[1][(indx + v1) >> 1]) - * temp, + + (hvwt[(indx + v1) >> 1]) * Dgrb[1][(indx + v1) >> 1]) * temp, 0.0, 1.0); } @@ -2147,8 +2110,7 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie col++; if(col < roi_out->width && row < roi_out->height) { - out[(row * roi_out->width + col) * 4] - = clampnan(rgbgreen[indx] - Dgrb[0][indx >> 1], 0.0, 1.0); + out[(row * roi_out->width + col) * 4] = clampnan(rgbgreen[indx] - Dgrb[0][indx >> 1], 0.0, 1.0); out[(row * roi_out->width + col) * 4 + 2] = clampnan(rgbgreen[indx] - Dgrb[1][indx >> 1], 0.0, 1.0); } @@ -2158,23 +2120,21 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie { // width of tile is odd if(col < roi_out->width && row < roi_out->height) { - float temp = 1.f / (hvwt[(indx - v1) >> 1] + 2.f - hvwt[(indx + 1) >> 1] - - hvwt[(indx - 1) >> 1] + hvwt[(indx + v1) >> 1]); + float temp = 1.f / (hvwt[(indx - v1) >> 1] + 2.f - hvwt[(indx + 1) >> 1] - hvwt[(indx - 1) >> 1] + + hvwt[(indx + v1) >> 1]); out[(row * roi_out->width + col) * 4] = clampnan(rgbgreen[indx] - ((hvwt[(indx - v1) >> 1]) * Dgrb[0][(indx - v1) >> 1] + (1.f - hvwt[(indx + 1) >> 1]) * Dgrb[0][(indx + 1) >> 1] + (1.f - hvwt[(indx - 1) >> 1]) * Dgrb[0][(indx - 1) >> 1] - + (hvwt[(indx + v1) >> 1]) * Dgrb[0][(indx + v1) >> 1]) - * temp, + + (hvwt[(indx + v1) >> 1]) * Dgrb[0][(indx + v1) >> 1]) * temp, 0.0, 1.0); out[(row * roi_out->width + col) * 4 + 2] = clampnan(rgbgreen[indx] - ((hvwt[(indx - v1) >> 1]) * Dgrb[1][(indx - v1) >> 1] + (1.f - hvwt[(indx + 1) >> 1]) * Dgrb[1][(indx + 1) >> 1] + (1.f - hvwt[(indx - 1) >> 1]) * Dgrb[1][(indx - 1) >> 1] - + (hvwt[(indx + v1) >> 1]) * Dgrb[1][(indx + v1) >> 1]) - * temp, + + (hvwt[(indx + v1) >> 1]) * Dgrb[1][(indx + v1) >> 1]) * temp, 0.0, 1.0); } } @@ -2185,8 +2145,7 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie { if(col < roi_out->width && row < roi_out->height) { - out[(row * roi_out->width + col) * 4] - = clampnan(rgbgreen[indx] - Dgrb[0][indx >> 1], 0.0, 1.0); + out[(row * roi_out->width + col) * 4] = clampnan(rgbgreen[indx] - Dgrb[0][indx >> 1], 0.0, 1.0); out[(row * roi_out->width + col) * 4 + 2] = clampnan(rgbgreen[indx] - Dgrb[1][indx >> 1], 0.0, 1.0); } @@ -2195,23 +2154,21 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie col++; if(col < roi_out->width && row < roi_out->height) { - float temp = 1.f / (hvwt[(indx - v1) >> 1] + 2.f - hvwt[(indx + 1) >> 1] - - hvwt[(indx - 1) >> 1] + hvwt[(indx + v1) >> 1]); + float temp = 1.f / (hvwt[(indx - v1) >> 1] + 2.f - hvwt[(indx + 1) >> 1] - hvwt[(indx - 1) >> 1] + + hvwt[(indx + v1) >> 1]); out[(row * roi_out->width + col) * 4] = clampnan(rgbgreen[indx] - ((hvwt[(indx - v1) >> 1]) * Dgrb[0][(indx - v1) >> 1] + (1.f - hvwt[(indx + 1) >> 1]) * Dgrb[0][(indx + 1) >> 1] + (1.f - hvwt[(indx - 1) >> 1]) * Dgrb[0][(indx - 1) >> 1] - + (hvwt[(indx + v1) >> 1]) * Dgrb[0][(indx + v1) >> 1]) - * temp, + + (hvwt[(indx + v1) >> 1]) * Dgrb[0][(indx + v1) >> 1]) * temp, 0.0, 1.0); out[(row * roi_out->width + col) * 4 + 2] = clampnan(rgbgreen[indx] - ((hvwt[(indx - v1) >> 1]) * Dgrb[1][(indx - v1) >> 1] + (1.f - hvwt[(indx + 1) >> 1]) * Dgrb[1][(indx + 1) >> 1] + (1.f - hvwt[(indx - 1) >> 1]) * Dgrb[1][(indx - 1) >> 1] - + (hvwt[(indx + v1) >> 1]) * Dgrb[1][(indx + v1) >> 1]) - * temp, + + (hvwt[(indx + v1) >> 1]) * Dgrb[1][(indx + v1) >> 1]) * temp, 0.0, 1.0); } } @@ -2220,8 +2177,7 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie { // width of tile is odd if(col < roi_out->width && row < roi_out->height) { - out[(row * roi_out->width + col) * 4] - = clampnan(rgbgreen[indx] - Dgrb[0][indx >> 1], 0.0, 1.0); + out[(row * roi_out->width + col) * 4] = clampnan(rgbgreen[indx] - Dgrb[0][indx >> 1], 0.0, 1.0); out[(row * roi_out->width + col) * 4 + 2] = clampnan(rgbgreen[indx] - Dgrb[1][indx >> 1], 0.0, 1.0); } @@ -2236,23 +2192,21 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie { if(col < roi_out->width && row < roi_out->height) { - float temp = 1.f / (hvwt[(indx - v1) >> 1] + 2.f - hvwt[(indx + 1) >> 1] - - hvwt[(indx - 1) >> 1] + hvwt[(indx + v1) >> 1]); + float temp = 1.f / (hvwt[(indx - v1) >> 1] + 2.f - hvwt[(indx + 1) >> 1] - hvwt[(indx - 1) >> 1] + + hvwt[(indx + v1) >> 1]); out[(row * roi_out->width + col) * 4] = clampnan(rgbgreen[indx] - ((hvwt[(indx - v1) >> 1]) * Dgrb[0][(indx - v1) >> 1] + (1.f - hvwt[(indx + 1) >> 1]) * Dgrb[0][(indx + 1) >> 1] + (1.f - hvwt[(indx - 1) >> 1]) * Dgrb[0][(indx - 1) >> 1] - + (hvwt[(indx + v1) >> 1]) * Dgrb[0][(indx + v1) >> 1]) - * temp, + + (hvwt[(indx + v1) >> 1]) * Dgrb[0][(indx + v1) >> 1]) * temp, 0.0, 1.0); out[(row * roi_out->width + col) * 4 + 2] = clampnan(rgbgreen[indx] - ((hvwt[(indx - v1) >> 1]) * Dgrb[1][(indx - v1) >> 1] + (1.f - hvwt[(indx + 1) >> 1]) * Dgrb[1][(indx + 1) >> 1] + (1.f - hvwt[(indx - 1) >> 1]) * Dgrb[1][(indx - 1) >> 1] - + (hvwt[(indx + v1) >> 1]) * Dgrb[1][(indx + v1) >> 1]) - * temp, + + (hvwt[(indx + v1) >> 1]) * Dgrb[1][(indx + v1) >> 1]) * temp, 0.0, 1.0); } @@ -2260,8 +2214,7 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie col++; if(col < roi_out->width && row < roi_out->height) { - out[(row * roi_out->width + col) * 4] - = clampnan(rgbgreen[indx] - Dgrb[0][indx >> 1], 0.0, 1.0); + out[(row * roi_out->width + col) * 4] = clampnan(rgbgreen[indx] - Dgrb[0][indx >> 1], 0.0, 1.0); out[(row * roi_out->width + col) * 4 + 2] = clampnan(rgbgreen[indx] - Dgrb[1][indx >> 1], 0.0, 1.0); } @@ -2271,23 +2224,21 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie { // width of tile is odd if(col < roi_out->width && row < roi_out->height) { - float temp = 1.f / (hvwt[(indx - v1) >> 1] + 2.f - hvwt[(indx + 1) >> 1] - - hvwt[(indx - 1) >> 1] + hvwt[(indx + v1) >> 1]); + float temp = 1.f / (hvwt[(indx - v1) >> 1] + 2.f - hvwt[(indx + 1) >> 1] - hvwt[(indx - 1) >> 1] + + hvwt[(indx + v1) >> 1]); out[(row * roi_out->width + col) * 4] = clampnan(rgbgreen[indx] - ((hvwt[(indx - v1) >> 1]) * Dgrb[0][(indx - v1) >> 1] + (1.f - hvwt[(indx + 1) >> 1]) * Dgrb[0][(indx + 1) >> 1] + (1.f - hvwt[(indx - 1) >> 1]) * Dgrb[0][(indx - 1) >> 1] - + (hvwt[(indx + v1) >> 1]) * Dgrb[0][(indx + v1) >> 1]) - * temp, + + (hvwt[(indx + v1) >> 1]) * Dgrb[0][(indx + v1) >> 1]) * temp, 0.0, 1.0); out[(row * roi_out->width + col) * 4 + 2] = clampnan(rgbgreen[indx] - ((hvwt[(indx - v1) >> 1]) * Dgrb[1][(indx - v1) >> 1] + (1.f - hvwt[(indx + 1) >> 1]) * Dgrb[1][(indx + 1) >> 1] + (1.f - hvwt[(indx - 1) >> 1]) * Dgrb[1][(indx - 1) >> 1] - + (hvwt[(indx + v1) >> 1]) * Dgrb[1][(indx + v1) >> 1]) - * temp, + + (hvwt[(indx + v1) >> 1]) * Dgrb[1][(indx + v1) >> 1]) * temp, 0.0, 1.0); } } @@ -2298,8 +2249,7 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie { if(col < roi_out->width && row < roi_out->height) { - out[(row * roi_out->width + col) * 4] - = clampnan(rgbgreen[indx] - Dgrb[0][indx >> 1], 0.0f, 1.0f); + out[(row * roi_out->width + col) * 4] = clampnan(rgbgreen[indx] - Dgrb[0][indx >> 1], 0.0f, 1.0f); out[(row * roi_out->width + col) * 4 + 2] = clampnan(rgbgreen[indx] - Dgrb[1][indx >> 1], 0.0f, 1.0f); } @@ -2308,16 +2258,15 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie col++; if(col < roi_out->width && row < roi_out->height) { - float temp = 1.f / (hvwt[(indx - v1) >> 1] + 2.f - hvwt[(indx + 1) >> 1] - - hvwt[(indx - 1) >> 1] + hvwt[(indx + v1) >> 1]); + float temp = 1.f / (hvwt[(indx - v1) >> 1] + 2.f - hvwt[(indx + 1) >> 1] - hvwt[(indx - 1) >> 1] + + hvwt[(indx + v1) >> 1]); out[(row * roi_out->width + col) * 4] = clampnan(rgbgreen[indx] - ((hvwt[(indx - v1) >> 1]) * Dgrb[0][(indx - v1) >> 1] + (1.0f - hvwt[(indx + 1) >> 1]) * Dgrb[0][(indx + 1) >> 1] + (1.0f - hvwt[(indx - 1) >> 1]) * Dgrb[0][(indx - 1) >> 1] - + (hvwt[(indx + v1) >> 1]) * Dgrb[0][(indx + v1) >> 1]) - * temp, + + (hvwt[(indx + v1) >> 1]) * Dgrb[0][(indx + v1) >> 1]) * temp, 0.0f, 1.0f); out[(row * roi_out->width + col) * 4 + 2] @@ -2325,8 +2274,7 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie - ((hvwt[(indx - v1) >> 1]) * Dgrb[1][(indx - v1) >> 1] + (1.0f - hvwt[(indx + 1) >> 1]) * Dgrb[1][(indx + 1) >> 1] + (1.0f - hvwt[(indx - 1) >> 1]) * Dgrb[1][(indx - 1) >> 1] - + (hvwt[(indx + v1) >> 1]) * Dgrb[1][(indx + v1) >> 1]) - * temp, + + (hvwt[(indx + v1) >> 1]) * Dgrb[1][(indx + v1) >> 1]) * temp, 0.0f, 1.0f); } } @@ -2335,8 +2283,7 @@ void amaze_demosaic_RT(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie { // width of tile is odd if(col < roi_out->width && row < roi_out->height) { - out[(row * roi_out->width + col) * 4] - = clampnan(rgbgreen[indx] - Dgrb[0][indx >> 1], 0.0f, 1.0f); + out[(row * roi_out->width + col) * 4] = clampnan(rgbgreen[indx] - Dgrb[0][indx >> 1], 0.0f, 1.0f); out[(row * roi_out->width + col) * 4 + 2] = clampnan(rgbgreen[indx] - Dgrb[1][indx >> 1], 0.0f, 1.0f); } diff --git a/src/iop/ashift.c b/src/iop/ashift.c index 7b59eefe8051..86e6c0812e76 100644 --- a/src/iop/ashift.c +++ b/src/iop/ashift.c @@ -50,41 +50,43 @@ // Thanks to Marcus for his support when implementing part of the ShiftN functionality // to darktable. -#define ROTATION_RANGE 10 // allowed min/max default range for rotation parameter -#define ROTATION_RANGE_SOFT 20 // allowed min/max range for rotation parameter with manual adjustment -#define LENSSHIFT_RANGE 0.5 // allowed min/max default range for lensshift paramters -#define LENSSHIFT_RANGE_SOFT 1 // allowed min/max range for lensshift paramters with manual adjustment -#define SHEAR_RANGE 0.2 // allowed min/max range for shear parameter -#define SHEAR_RANGE_SOFT 0.5 // allowed min/max range for shear parameter with manual adjustment -#define MIN_LINE_LENGTH 5 // the minimum length of a line in pixels to be regarded as relevant -#define MAX_TANGENTIAL_DEVIATION 30 // by how many degrees a line may deviate from the +/-180 and +/-90 to be regarded as relevant -#define POINTS_NEAR_DELTA 4 // distance of mouse pointer to line for "near" detection -#define LSD_SCALE 0.99 // LSD: scaling factor for line detection -#define LSD_SIGMA_SCALE 0.6 // LSD: sigma for Gaussian filter is computed as sigma = sigma_scale/scale -#define LSD_QUANT 2.0 // LSD: bound to the quantization error on the gradient norm -#define LSD_ANG_TH 22.5 // LSD: gradient angle tolerance in degrees -#define LSD_LOG_EPS 0.0 // LSD: detection threshold: -log10(NFA) > log_eps -#define LSD_DENSITY_TH 0.7 // LSD: minimal density of region points in rectangle -#define LSD_N_BINS 1024 // LSD: number of bins in pseudo-ordering of gradient modulus -#define LSD_GAMMA 0.45 // gamma correction to apply on raw images prior to line detection -#define RANSAC_RUNS 400 // how many interations to run in ransac -#define RANSAC_EPSILON 2 // starting value for ransac epsilon (in -log10 units) -#define RANSAC_EPSILON_STEP 1 // step size of epsilon optimization (log10 units) -#define RANSAC_ELIMINATION_RATIO 60 // percentage of lines we try to eliminate as outliers -#define RANSAC_OPTIMIZATION_STEPS 5 // home many steps to optimize epsilon -#define RANSAC_OPTIMIZATION_DRY_RUNS 50 // how man runs per optimization steps -#define RANSAC_HURDLE 5 // hurdle rate: the number of lines below which we do a complete permutation instead of random sampling -#define MINIMUM_FITLINES 4 // minimum number of lines needed for automatic parameter fit -#define NMS_EPSILON 1e-3 // break criterion for Nelder-Mead simplex -#define NMS_SCALE 1.0 // scaling factor for Nelder-Mead simplex -#define NMS_ITERATIONS 400 // number of iterations for Nelder-Mead simplex -#define NMS_CROP_EPSILON 100.0 // break criterion for Nelder-Mead simplex on crop fitting -#define NMS_CROP_SCALE 0.5 // scaling factor for Nelder-Mead simplex on crop fitting -#define NMS_CROP_ITERATIONS 100 // number of iterations for Nelder-Mead simplex on crop fitting -#define NMS_ALPHA 1.0 // reflection coefficient for Nelder-Mead simplex -#define NMS_BETA 0.5 // contraction coefficient for Nelder-Mead simplex -#define NMS_GAMMA 2.0 // expansion coefficient for Nelder-Mead simplex -#define DEFAULT_F_LENGTH 28.0 // focal length we assume if no exif data are available +#define ROTATION_RANGE 10 // allowed min/max default range for rotation parameter +#define ROTATION_RANGE_SOFT 20 // allowed min/max range for rotation parameter with manual adjustment +#define LENSSHIFT_RANGE 0.5 // allowed min/max default range for lensshift paramters +#define LENSSHIFT_RANGE_SOFT 1 // allowed min/max range for lensshift paramters with manual adjustment +#define SHEAR_RANGE 0.2 // allowed min/max range for shear parameter +#define SHEAR_RANGE_SOFT 0.5 // allowed min/max range for shear parameter with manual adjustment +#define MIN_LINE_LENGTH 5 // the minimum length of a line in pixels to be regarded as relevant +#define MAX_TANGENTIAL_DEVIATION \ + 30 // by how many degrees a line may deviate from the +/-180 and +/-90 to be regarded as relevant +#define POINTS_NEAR_DELTA 4 // distance of mouse pointer to line for "near" detection +#define LSD_SCALE 0.99 // LSD: scaling factor for line detection +#define LSD_SIGMA_SCALE 0.6 // LSD: sigma for Gaussian filter is computed as sigma = sigma_scale/scale +#define LSD_QUANT 2.0 // LSD: bound to the quantization error on the gradient norm +#define LSD_ANG_TH 22.5 // LSD: gradient angle tolerance in degrees +#define LSD_LOG_EPS 0.0 // LSD: detection threshold: -log10(NFA) > log_eps +#define LSD_DENSITY_TH 0.7 // LSD: minimal density of region points in rectangle +#define LSD_N_BINS 1024 // LSD: number of bins in pseudo-ordering of gradient modulus +#define LSD_GAMMA 0.45 // gamma correction to apply on raw images prior to line detection +#define RANSAC_RUNS 400 // how many interations to run in ransac +#define RANSAC_EPSILON 2 // starting value for ransac epsilon (in -log10 units) +#define RANSAC_EPSILON_STEP 1 // step size of epsilon optimization (log10 units) +#define RANSAC_ELIMINATION_RATIO 60 // percentage of lines we try to eliminate as outliers +#define RANSAC_OPTIMIZATION_STEPS 5 // home many steps to optimize epsilon +#define RANSAC_OPTIMIZATION_DRY_RUNS 50 // how man runs per optimization steps +#define RANSAC_HURDLE \ + 5 // hurdle rate: the number of lines below which we do a complete permutation instead of random sampling +#define MINIMUM_FITLINES 4 // minimum number of lines needed for automatic parameter fit +#define NMS_EPSILON 1e-3 // break criterion for Nelder-Mead simplex +#define NMS_SCALE 1.0 // scaling factor for Nelder-Mead simplex +#define NMS_ITERATIONS 400 // number of iterations for Nelder-Mead simplex +#define NMS_CROP_EPSILON 100.0 // break criterion for Nelder-Mead simplex on crop fitting +#define NMS_CROP_SCALE 0.5 // scaling factor for Nelder-Mead simplex on crop fitting +#define NMS_CROP_ITERATIONS 100 // number of iterations for Nelder-Mead simplex on crop fitting +#define NMS_ALPHA 1.0 // reflection coefficient for Nelder-Mead simplex +#define NMS_BETA 0.5 // contraction coefficient for Nelder-Mead simplex +#define NMS_GAMMA 2.0 // expansion coefficient for Nelder-Mead simplex +#define DEFAULT_F_LENGTH 28.0 // focal length we assume if no exif data are available // define to get debugging output #undef ASHIFT_DEBUG @@ -140,12 +142,12 @@ typedef enum dt_iop_ashift_homodir_t typedef enum dt_iop_ashift_linetype_t { - ASHIFT_LINE_IRRELEVANT = 0, // the line is found to be not interesting - // eg. too short, or not horizontal or vertical - ASHIFT_LINE_RELEVANT = 1 << 0, // the line is relevant for us - ASHIFT_LINE_DIRVERT = 1 << 1, // the line is (mostly) vertical, else (mostly) horizontal - ASHIFT_LINE_SELECTED = 1 << 2, // the line is selected for fitting - ASHIFT_LINE_VERTICAL_NOT_SELECTED = ASHIFT_LINE_RELEVANT | ASHIFT_LINE_DIRVERT, + ASHIFT_LINE_IRRELEVANT = 0, // the line is found to be not interesting + // eg. too short, or not horizontal or vertical + ASHIFT_LINE_RELEVANT = 1 << 0, // the line is relevant for us + ASHIFT_LINE_DIRVERT = 1 << 1, // the line is (mostly) vertical, else (mostly) horizontal + ASHIFT_LINE_SELECTED = 1 << 2, // the line is selected for fitting + ASHIFT_LINE_VERTICAL_NOT_SELECTED = ASHIFT_LINE_RELEVANT | ASHIFT_LINE_DIRVERT, ASHIFT_LINE_HORIZONTAL_NOT_SELECTED = ASHIFT_LINE_RELEVANT, ASHIFT_LINE_VERTICAL_SELECTED = ASHIFT_LINE_RELEVANT | ASHIFT_LINE_DIRVERT | ASHIFT_LINE_SELECTED, ASHIFT_LINE_HORIZONTAL_SELECTED = ASHIFT_LINE_RELEVANT | ASHIFT_LINE_SELECTED, @@ -154,34 +156,34 @@ typedef enum dt_iop_ashift_linetype_t typedef enum dt_iop_ashift_linecolor_t { - ASHIFT_LINECOLOR_GREY = 0, - ASHIFT_LINECOLOR_GREEN = 1, - ASHIFT_LINECOLOR_RED = 2, - ASHIFT_LINECOLOR_BLUE = 3, - ASHIFT_LINECOLOR_YELLOW = 4 + ASHIFT_LINECOLOR_GREY = 0, + ASHIFT_LINECOLOR_GREEN = 1, + ASHIFT_LINECOLOR_RED = 2, + ASHIFT_LINECOLOR_BLUE = 3, + ASHIFT_LINECOLOR_YELLOW = 4 } dt_iop_ashift_linecolor_t; typedef enum dt_iop_ashift_fitaxis_t { - ASHIFT_FIT_NONE = 0, // none - ASHIFT_FIT_ROTATION = 1 << 0, // flag indicates to fit rotation angle - ASHIFT_FIT_LENS_VERT = 1 << 1, // flag indicates to fit vertical lens shift - ASHIFT_FIT_LENS_HOR = 1 << 2, // flag indicates to fit horizontal lens shift - ASHIFT_FIT_SHEAR = 1 << 3, // flag indicates to fit shear parameter - ASHIFT_FIT_LINES_VERT = 1 << 4, // use vertical lines for fitting - ASHIFT_FIT_LINES_HOR = 1 << 5, // use horizontal lines for fitting + ASHIFT_FIT_NONE = 0, // none + ASHIFT_FIT_ROTATION = 1 << 0, // flag indicates to fit rotation angle + ASHIFT_FIT_LENS_VERT = 1 << 1, // flag indicates to fit vertical lens shift + ASHIFT_FIT_LENS_HOR = 1 << 2, // flag indicates to fit horizontal lens shift + ASHIFT_FIT_SHEAR = 1 << 3, // flag indicates to fit shear parameter + ASHIFT_FIT_LINES_VERT = 1 << 4, // use vertical lines for fitting + ASHIFT_FIT_LINES_HOR = 1 << 5, // use horizontal lines for fitting ASHIFT_FIT_LENS_BOTH = ASHIFT_FIT_LENS_VERT | ASHIFT_FIT_LENS_HOR, ASHIFT_FIT_LINES_BOTH = ASHIFT_FIT_LINES_VERT | ASHIFT_FIT_LINES_HOR, ASHIFT_FIT_VERTICALLY = ASHIFT_FIT_ROTATION | ASHIFT_FIT_LENS_VERT | ASHIFT_FIT_LINES_VERT, ASHIFT_FIT_HORIZONTALLY = ASHIFT_FIT_ROTATION | ASHIFT_FIT_LENS_HOR | ASHIFT_FIT_LINES_HOR, - ASHIFT_FIT_BOTH = ASHIFT_FIT_ROTATION | ASHIFT_FIT_LENS_VERT | ASHIFT_FIT_LENS_HOR | - ASHIFT_FIT_LINES_VERT | ASHIFT_FIT_LINES_HOR, + ASHIFT_FIT_BOTH = ASHIFT_FIT_ROTATION | ASHIFT_FIT_LENS_VERT | ASHIFT_FIT_LENS_HOR | ASHIFT_FIT_LINES_VERT + | ASHIFT_FIT_LINES_HOR, ASHIFT_FIT_VERTICALLY_NO_ROTATION = ASHIFT_FIT_LENS_VERT | ASHIFT_FIT_LINES_VERT, ASHIFT_FIT_HORIZONTALLY_NO_ROTATION = ASHIFT_FIT_LENS_HOR | ASHIFT_FIT_LINES_HOR, - ASHIFT_FIT_BOTH_NO_ROTATION = ASHIFT_FIT_LENS_VERT | ASHIFT_FIT_LENS_HOR | - ASHIFT_FIT_LINES_VERT | ASHIFT_FIT_LINES_HOR, - ASHIFT_FIT_BOTH_SHEAR = ASHIFT_FIT_ROTATION | ASHIFT_FIT_LENS_VERT | ASHIFT_FIT_LENS_HOR | - ASHIFT_FIT_SHEAR | ASHIFT_FIT_LINES_VERT | ASHIFT_FIT_LINES_HOR, + ASHIFT_FIT_BOTH_NO_ROTATION = ASHIFT_FIT_LENS_VERT | ASHIFT_FIT_LENS_HOR | ASHIFT_FIT_LINES_VERT + | ASHIFT_FIT_LINES_HOR, + ASHIFT_FIT_BOTH_SHEAR = ASHIFT_FIT_ROTATION | ASHIFT_FIT_LENS_VERT | ASHIFT_FIT_LENS_HOR | ASHIFT_FIT_SHEAR + | ASHIFT_FIT_LINES_VERT | ASHIFT_FIT_LINES_HOR, ASHIFT_FIT_ROTATION_VERTICAL_LINES = ASHIFT_FIT_ROTATION | ASHIFT_FIT_LINES_VERT, ASHIFT_FIT_ROTATION_HORIZONTAL_LINES = ASHIFT_FIT_ROTATION | ASHIFT_FIT_LINES_HOR, ASHIFT_FIT_ROTATION_BOTH_LINES = ASHIFT_FIT_ROTATION | ASHIFT_FIT_LINES_VERT | ASHIFT_FIT_LINES_HOR, @@ -198,11 +200,11 @@ typedef enum dt_iop_ashift_nmsresult_t typedef enum dt_iop_ashift_enhance_t { - ASHIFT_ENHANCE_NONE = 0, - ASHIFT_ENHANCE_EDGES = 1 << 0, - ASHIFT_ENHANCE_DETAIL = 1 << 1, + ASHIFT_ENHANCE_NONE = 0, + ASHIFT_ENHANCE_EDGES = 1 << 0, + ASHIFT_ENHANCE_DETAIL = 1 << 1, ASHIFT_ENHANCE_HORIZONTAL = 0x100, - ASHIFT_ENHANCE_VERTICAL = 0x200 + ASHIFT_ENHANCE_VERTICAL = 0x200 } dt_iop_ashift_enhance_t; typedef enum dt_iop_ashift_mode_t @@ -434,8 +436,8 @@ typedef struct dt_iop_ashift_global_data_t int kernel_ashift_lanczos3; } dt_iop_ashift_global_data_t; -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 1 && new_version == 4) { @@ -617,7 +619,12 @@ static void print_roi(const dt_iop_roi_t *roi, const char *label) } #endif -#define MAT3SWAP(a, b) { float (*tmp)[3] = (a); (a) = (b); (b) = tmp; } +#define MAT3SWAP(a, b) \ + { \ + float(*tmp)[3] = (a); \ + (a) = (b); \ + (b) = tmp; \ + } static void homography(float *homograph, const float angle, const float shift_v, const float shift_h, const float shear, const float f_length_kb, const float orthocorr, const float aspect, @@ -661,9 +668,9 @@ static void homography(float *homograph, const float angle, const float shift_v, float m1[3][3], m2[3][3], m3[3][3]; // ... and some pointers to handle them more intuitively - float (*mwork)[3] = m1; - float (*minput)[3] = m2; - float (*moutput)[3] = m3; + float(*mwork)[3] = m1; + float(*minput)[3] = m2; + float(*moutput)[3] = m3; // Step 1: flip x and y coordinates (see above) memset(minput, 0, 9 * sizeof(float)); @@ -846,10 +853,8 @@ static inline int isneutral(dt_iop_ashift_data_t *data) // values lower than this have no visible effect const float eps = 1.0e-4f; - return(fabs(data->rotation) < eps && - fabs(data->lensshift_v) < eps && - fabs(data->lensshift_h) < eps && - fabs(data->shear) < eps); + return (fabs(data->rotation) < eps && fabs(data->lensshift_v) < eps && fabs(data->lensshift_h) < eps + && fabs(data->shear) < eps); } @@ -861,8 +866,9 @@ int distort_transform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, floa if(isneutral(data)) return 1; float homograph[3][3]; - homography((float *)homograph, data->rotation, data->lensshift_v, data->lensshift_h, data->shear, data->f_length_kb, - data->orthocorr, data->aspect, piece->buf_in.width, piece->buf_in.height, ASHIFT_HOMOGRAPH_FORWARD); + homography((float *)homograph, data->rotation, data->lensshift_v, data->lensshift_h, data->shear, + data->f_length_kb, data->orthocorr, data->aspect, piece->buf_in.width, piece->buf_in.height, + ASHIFT_HOMOGRAPH_FORWARD); // clipping offset const float fullwidth = (float)piece->buf_out.width / (data->cr - data->cl); @@ -886,8 +892,7 @@ int distort_transform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, floa } -int distort_backtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, float *points, - size_t points_count) +int distort_backtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, float *points, size_t points_count) { dt_iop_ashift_data_t *data = (dt_iop_ashift_data_t *)piece->data; @@ -895,8 +900,9 @@ int distort_backtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, if(isneutral(data)) return 1; float ihomograph[3][3]; - homography((float *)ihomograph, data->rotation, data->lensshift_v, data->lensshift_h, data->shear, data->f_length_kb, - data->orthocorr, data->aspect, piece->buf_in.width, piece->buf_in.height, ASHIFT_HOMOGRAPH_INVERTED); + homography((float *)ihomograph, data->rotation, data->lensshift_v, data->lensshift_h, data->shear, + data->f_length_kb, data->orthocorr, data->aspect, piece->buf_in.width, piece->buf_in.height, + ASHIFT_HOMOGRAPH_INVERTED); // clipping offset const float fullwidth = (float)piece->buf_out.width / (data->cr - data->cl); @@ -929,8 +935,9 @@ void modify_roi_out(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t if(isneutral(data)) return; float homograph[3][3]; - homography((float *)homograph, data->rotation, data->lensshift_v, data->lensshift_h, data->shear, data->f_length_kb, - data->orthocorr, data->aspect, piece->buf_in.width, piece->buf_in.height, ASHIFT_HOMOGRAPH_FORWARD); + homography((float *)homograph, data->rotation, data->lensshift_v, data->lensshift_h, data->shear, + data->f_length_kb, data->orthocorr, data->aspect, piece->buf_in.width, piece->buf_in.height, + ASHIFT_HOMOGRAPH_FORWARD); float xm = FLT_MAX, xM = -FLT_MAX, ym = FLT_MAX, yM = -FLT_MAX; @@ -988,8 +995,9 @@ void modify_roi_in(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t * if(isneutral(data)) return; float ihomograph[3][3]; - homography((float *)ihomograph, data->rotation, data->lensshift_v, data->lensshift_h, data->shear, data->f_length_kb, - data->orthocorr, data->aspect, piece->buf_in.width, piece->buf_in.height, ASHIFT_HOMOGRAPH_INVERTED); + homography((float *)ihomograph, data->rotation, data->lensshift_v, data->lensshift_h, data->shear, + data->f_length_kb, data->orthocorr, data->aspect, piece->buf_in.width, piece->buf_in.height, + ASHIFT_HOMOGRAPH_INVERTED); const float orig_w = roi_in->scale * piece->buf_in.width; const float orig_h = roi_in->scale * piece->buf_in.height; @@ -1168,9 +1176,9 @@ static int edge_enhance(const double *in, double *out, const int width, const in // XYZ -> sRGB matrix static void XYZ_to_sRGB(const float *XYZ, float *sRGB) { - sRGB[0] = 3.1338561f * XYZ[0] - 1.6168667f * XYZ[1] - 0.4906146f * XYZ[2]; + sRGB[0] = 3.1338561f * XYZ[0] - 1.6168667f * XYZ[1] - 0.4906146f * XYZ[2]; sRGB[1] = -0.9787684f * XYZ[0] + 1.9161415f * XYZ[1] + 0.0334540f * XYZ[2]; - sRGB[2] = 0.0719453f * XYZ[0] - 0.2289914f * XYZ[1] + 1.4052427f * XYZ[2]; + sRGB[2] = 0.0719453f * XYZ[0] - 0.2289914f * XYZ[1] + 1.4052427f * XYZ[2]; } // sRGB -> XYZ matrix @@ -1190,10 +1198,10 @@ static int detail_enhance(const float *in, float *out, const int width, const in int success = TRUE; - // we need to convert from RGB to Lab first; - // as colors don't matter we are safe to assume data to be sRGB +// we need to convert from RGB to Lab first; +// as colors don't matter we are safe to assume data to be sRGB - // convert RGB input to Lab, use output buffer for intermediate storage +// convert RGB input to Lab, use output buffer for intermediate storage #ifdef _OPENMP #pragma omp parallel for schedule(static) default(none) shared(in, out) #endif @@ -1222,7 +1230,7 @@ static int detail_enhance(const float *in, float *out, const int width, const in else success = FALSE; - // convert resulting Lab to RGB output +// convert resulting Lab to RGB output #ifdef _OPENMP #pragma omp parallel for schedule(static) default(none) shared(out) #endif @@ -1252,8 +1260,7 @@ static void gamma_correct(const float *in, float *out, const int width, const in float *outp = out + (size_t)4 * j * width; for(int i = 0; i < width; i++, inp += 4, outp += 4) { - for(int c = 0; c < 3; c++) - outp[c] = powf(inp[c], LSD_GAMMA); + for(int c = 0; c < 3; c++) outp[c] = powf(inp[c], LSD_GAMMA); } } } @@ -1302,10 +1309,8 @@ static int line_detect(float *in, const int width, const int height, const int x // LSD stores the number of found lines in lines_count. // it returns structural details as vector 'double lines[7 * lines_count]' int lines_count; - lsd_lines = LineSegmentDetection(&lines_count, greyscale, width, height, - LSD_SCALE, LSD_SIGMA_SCALE, LSD_QUANT, - LSD_ANG_TH, LSD_LOG_EPS, LSD_DENSITY_TH, - LSD_N_BINS, NULL, NULL, NULL); + lsd_lines = LineSegmentDetection(&lines_count, greyscale, width, height, LSD_SCALE, LSD_SIGMA_SCALE, LSD_QUANT, + LSD_ANG_TH, LSD_LOG_EPS, LSD_DENSITY_TH, LSD_N_BINS, NULL, NULL, NULL); // we count the lines that we really want to use int lct = 0; @@ -1326,10 +1331,8 @@ static int line_detect(float *in, const int width, const int height, const int x // check for lines running along image borders and skip them. // these would likely be false-positives which could result // from any kind of processing artifacts - if((fabs(x1 - x2) < 1 && fmax(x1, x2) < 2) || - (fabs(x1 - x2) < 1 && fmin(x1, x2) > width - 3) || - (fabs(y1 - y2) < 1 && fmax(y1, y2) < 2) || - (fabs(y1 - y2) < 1 && fmin(y1, y2) > height - 3)) + if((fabs(x1 - x2) < 1 && fmax(x1, x2) < 2) || (fabs(x1 - x2) < 1 && fmin(x1, x2) > width - 3) + || (fabs(y1 - y2) < 1 && fmax(y1, y2) < 2) || (fabs(y1 - y2) < 1 && fmin(y1, y2) > height - 3)) continue; // line position in absolute coordinates @@ -1395,23 +1398,22 @@ static int line_detect(float *in, const int width, const int height, const int x } } #ifdef ASHIFT_DEBUG - printf("%d lines (vertical %d, horizontal %d, not relevant %d)\n", lines_count, vertical_count, - horizontal_count, lct - vertical_count - horizontal_count); - float xmin = FLT_MAX, xmax = FLT_MIN, ymin = FLT_MAX, ymax = FLT_MIN; - for(int n = 0; n < lct; n++) - { - xmin = fmin(xmin, fmin(ashift_lines[n].p1[0], ashift_lines[n].p2[0])); - xmax = fmax(xmax, fmax(ashift_lines[n].p1[0], ashift_lines[n].p2[0])); - ymin = fmin(ymin, fmin(ashift_lines[n].p1[1], ashift_lines[n].p2[1])); - ymax = fmax(ymax, fmax(ashift_lines[n].p1[1], ashift_lines[n].p2[1])); - printf("x1 %.0f, y1 %.0f, x2 %.0f, y2 %.0f, length %.0f, width %f, X %f, Y %f, Z %f, type %d, scalars %f %f\n", - ashift_lines[n].p1[0], ashift_lines[n].p1[1], ashift_lines[n].p2[0], ashift_lines[n].p2[1], - ashift_lines[n].length, ashift_lines[n].width, - ashift_lines[n].L[0], ashift_lines[n].L[1], ashift_lines[n].L[2], ashift_lines[n].type, - vec3scalar(ashift_lines[n].p1, ashift_lines[n].L), - vec3scalar(ashift_lines[n].p2, ashift_lines[n].L)); - } - printf("xmin %.0f, xmax %.0f, ymin %.0f, ymax %.0f\n", xmin, xmax, ymin, ymax); + printf("%d lines (vertical %d, horizontal %d, not relevant %d)\n", lines_count, vertical_count, horizontal_count, + lct - vertical_count - horizontal_count); + float xmin = FLT_MAX, xmax = FLT_MIN, ymin = FLT_MAX, ymax = FLT_MIN; + for(int n = 0; n < lct; n++) + { + xmin = fmin(xmin, fmin(ashift_lines[n].p1[0], ashift_lines[n].p2[0])); + xmax = fmax(xmax, fmax(ashift_lines[n].p1[0], ashift_lines[n].p2[0])); + ymin = fmin(ymin, fmin(ashift_lines[n].p1[1], ashift_lines[n].p2[1])); + ymax = fmax(ymax, fmax(ashift_lines[n].p1[1], ashift_lines[n].p2[1])); + printf("x1 %.0f, y1 %.0f, x2 %.0f, y2 %.0f, length %.0f, width %f, X %f, Y %f, Z %f, type %d, scalars %f %f\n", + ashift_lines[n].p1[0], ashift_lines[n].p1[1], ashift_lines[n].p2[0], ashift_lines[n].p2[1], + ashift_lines[n].length, ashift_lines[n].width, ashift_lines[n].L[0], ashift_lines[n].L[1], + ashift_lines[n].L[2], ashift_lines[n].type, vec3scalar(ashift_lines[n].p1, ashift_lines[n].L), + vec3scalar(ashift_lines[n].p2, ashift_lines[n].L)); + } + printf("xmin %.0f, xmax %.0f, ymin %.0f, ymax %.0f\n", xmin, xmax, ymin, ymax); #endif // store results in provided locations @@ -1457,8 +1459,7 @@ static int get_structure(dt_iop_module_t *module, dt_iop_ashift_enhance_t enhanc // create a temporary buffer to hold image data buffer = malloc((size_t)width * height * 4 * sizeof(float)); - if(buffer != NULL) - memcpy(buffer, g->buf, (size_t)width * height * 4 * sizeof(float)); + if(buffer != NULL) memcpy(buffer, g->buf, (size_t)width * height * 4 * sizeof(float)); } dt_pthread_mutex_unlock(&g->lock); @@ -1479,9 +1480,9 @@ static int get_structure(dt_iop_module_t *module, dt_iop_ashift_enhance_t enhanc float horizontal_weight; // get new structural data - if(!line_detect(buffer, width, height, x_off, y_off, scale, &lines, &lines_count, - &vertical_count, &horizontal_count, &vertical_weight, &horizontal_weight, - enhance, dt_image_is_raw(&module->dev->image_storage))) + if(!line_detect(buffer, width, height, x_off, y_off, scale, &lines, &lines_count, &vertical_count, + &horizontal_count, &vertical_weight, &horizontal_weight, enhance, + dt_image_is_raw(&module->dev->image_storage))) goto error; // save new structural data @@ -1564,9 +1565,8 @@ static int fact(const int n) // note: the actual percentage of outliers removed in the final run will be lower because we // will finally look for the best quality model with the optimized epsilon and that quality value also // encloses the number of good lines -static void ransac(const dt_iop_ashift_line_t *lines, int *index_set, int *inout_set, - const int set_count, const float total_weight, const int xmin, const int xmax, - const int ymin, const int ymax) +static void ransac(const dt_iop_ashift_line_t *lines, int *index_set, int *inout_set, const int set_count, + const float total_weight, const int xmin, const int xmax, const int ymin, const int ymax) { if(set_count < 3) return; @@ -1620,12 +1620,8 @@ static void ransac(const dt_iop_ashift_line_t *lines, int *index_set, int *inout // catch special cases: // a) L1 and L2 are identical -> V is NULL -> no valid vantage point // b) vantage point lies inside image frame (no chance to correct for this case) - if(vec3isnull(V) || - (fabs(V[2]) > 0.0f && - V[0]/V[2] >= xmin && - V[1]/V[2] >= ymin && - V[0]/V[2] <= xmax && - V[1]/V[2] <= ymax)) + if(vec3isnull(V) || (fabs(V[2]) > 0.0f && V[0] / V[2] >= xmin && V[1] / V[2] >= ymin && V[0] / V[2] <= xmax + && V[1] / V[2] <= ymax)) { // no valid model quality = 0.0f; @@ -1664,8 +1660,7 @@ static void ransac(const dt_iop_ashift_line_t *lines, int *index_set, int *inout { // a quality parameter that depends 1/3 on the number of lines within the model, // 1/3 on their weight, and 1/3 on their weighted distance d to the vantage point - q = 0.33f / (float)set_count - + 0.33f * lines[index_set[n]].weight / total_weight + q = 0.33f / (float)set_count + 0.33f * lines[index_set[n]].weight / total_weight + 0.33f * (1.0f - d / epsilon) * (float)set_count * lines[index_set[n]].weight / total_weight; } else @@ -1719,8 +1714,9 @@ static void ransac(const dt_iop_ashift_line_t *lines, int *index_set, int *inout int count = 0, lastcount = 0; for(int n = 0; n < set_count; n++) count += best_inout[n]; for(int n = 0; n < set_count; n++) lastcount += inout[n]; - printf("ransac run %d: best qual %.6f, eps %.6f, line count %d of %d (this run: qual %.5f, count %d (%2f%%))\n", r, - best_quality, epsilon, count, set_count, quality, lastcount, 100.0f * lastcount / (float)set_count); + printf( + "ransac run %d: best qual %.6f, eps %.6f, line count %d of %d (this run: qual %.5f, count %d (%2f%%))\n", + r, best_quality, epsilon, count, set_count, quality, lastcount, 100.0f * lastcount / (float)set_count); #endif } @@ -1764,8 +1760,7 @@ static int remove_outliers(dt_iop_module_t *module) for(int n = 0; n < g->lines_count; n++) { // is this a selected vertical line? - if((g->lines[n].type & ASHIFT_LINE_MASK) != ASHIFT_LINE_VERTICAL_SELECTED) - continue; + if((g->lines[n].type & ASHIFT_LINE_MASK) != ASHIFT_LINE_VERTICAL_SELECTED) continue; lines_set[vnb] = n; inout_set[vnb] = 0; @@ -1773,9 +1768,7 @@ static int remove_outliers(dt_iop_module_t *module) } // it only makes sense to call ransac if we have more than two lines - if(vnb > 2) - ransac(g->lines, lines_set, inout_set, vnb, g->vertical_weight, - xmin, xmax, ymin, ymax); + if(vnb > 2) ransac(g->lines, lines_set, inout_set, vnb, g->vertical_weight, xmin, xmax, ymin, ymax); // adjust line selected flag according to the ransac results for(int n = 0; n < vnb; n++) @@ -1797,8 +1790,7 @@ static int remove_outliers(dt_iop_module_t *module) for(int n = 0; n < g->lines_count; n++) { // is this a selected horizontal line? - if((g->lines[n].type & ASHIFT_LINE_MASK) != ASHIFT_LINE_HORIZONTAL_SELECTED) - continue; + if((g->lines[n].type & ASHIFT_LINE_MASK) != ASHIFT_LINE_HORIZONTAL_SELECTED) continue; lines_set[hnb] = n; inout_set[hnb] = 0; @@ -1806,9 +1798,7 @@ static int remove_outliers(dt_iop_module_t *module) } // it only makes sense to call ransac if we have more than two lines - if(hnb > 2) - ransac(g->lines, lines_set, inout_set, hnb, g->horizontal_weight, - xmin, xmax, ymin, ymax); + if(hnb > 2) ransac(g->lines, lines_set, inout_set, hnb, g->horizontal_weight, xmin, xmax, ymin, ymax); // adjust line selected flag according to the ransac results for(int n = 0; n < hnb; n++) @@ -1920,8 +1910,8 @@ static double model_fitness(double *params, void *data) // generate homograph out of the parameters float homograph[3][3]; - homography((float *)homograph, rotation, lensshift_v, lensshift_h, shear, f_length_kb, - orthocorr, aspect, width, height, ASHIFT_HOMOGRAPH_FORWARD); + homography((float *)homograph, rotation, lensshift_v, lensshift_h, shear, f_length_kb, orthocorr, aspect, width, + height, ASHIFT_HOMOGRAPH_FORWARD); // accounting variables double sumsq_v = 0.0; @@ -1936,8 +1926,7 @@ static double model_fitness(double *params, void *data) for(int n = 0; n < lines_count; n++) { // check if this is a line which we must skip - if((lines[n].type & fit->linemask) != fit->linetype) - continue; + if((lines[n].type & fit->linemask) != fit->linetype) continue; // the direction of this line (vertical?) const int isvertical = lines[n].type & ASHIFT_LINE_DIRVERT; @@ -1963,10 +1952,10 @@ static double model_fitness(double *params, void *data) // sum up weighted s^2 for both directions individually sumsq_v += isvertical ? s * s * lines[n].weight : 0.0; - weight_v += isvertical ? lines[n].weight : 0.0; + weight_v += isvertical ? lines[n].weight : 0.0; count_v += isvertical ? 1 : 0; sumsq_h += !isvertical ? s * s * lines[n].weight : 0.0; - weight_h += !isvertical ? lines[n].weight : 0.0; + weight_h += !isvertical ? lines[n].weight : 0.0; count_h += !isvertical ? 1 : 0; count++; } @@ -1975,7 +1964,7 @@ static double model_fitness(double *params, void *data) const double h = weight_h > 0.0f && count > 0 ? sumsq_h / weight_h * (float)count_h / count : 0.0; double sum = sqrt(1.0 - (1.0 - v) * (1.0 - h)) * 1.0e6; - //double sum = sqrt(v + h) * 1.0e6; +// double sum = sqrt(v + h) * 1.0e6; #ifdef ASHIFT_DEBUG printf("fitness with rotation %f, lensshift_v %f, lensshift_h %f, shear %f -> lines %d, quality %10f\n", @@ -1986,7 +1975,8 @@ static double model_fitness(double *params, void *data) } // setup all data structures for fitting and call NM simplex -static dt_iop_ashift_nmsresult_t nmsfit(dt_iop_module_t *module, dt_iop_ashift_params_t *p, dt_iop_ashift_fitaxis_t dir) +static dt_iop_ashift_nmsresult_t nmsfit(dt_iop_module_t *module, dt_iop_ashift_params_t *p, + dt_iop_ashift_fitaxis_t dir) { dt_iop_ashift_gui_data_t *g = (dt_iop_ashift_gui_data_t *)module->gui_data; @@ -2022,8 +2012,7 @@ static dt_iop_ashift_nmsresult_t nmsfit(dt_iop_module_t *module, dt_iop_ashift_p // if the image is flipped and if we do not want to fit both lens shift // directions or none at all, then we need to change direction dt_iop_ashift_fitaxis_t mdir = dir; - if((mdir & ASHIFT_FIT_LENS_BOTH) != ASHIFT_FIT_LENS_BOTH && - (mdir & ASHIFT_FIT_LENS_BOTH) != 0) + if((mdir & ASHIFT_FIT_LENS_BOTH) != ASHIFT_FIT_LENS_BOTH && (mdir & ASHIFT_FIT_LENS_BOTH) != 0) { // flip all directions mdir ^= g->isflipped ? ASHIFT_FIT_FLIP : 0; @@ -2108,7 +2097,8 @@ static dt_iop_ashift_nmsresult_t nmsfit(dt_iop_module_t *module, dt_iop_ashift_p } // start the simplex fit - int iter = simplex(model_fitness, params, fit.params_count, NMS_EPSILON, NMS_SCALE, NMS_ITERATIONS, NULL, (void*)&fit); + int iter = simplex(model_fitness, params, fit.params_count, NMS_EPSILON, NMS_SCALE, NMS_ITERATIONS, NULL, + (void *)&fit); // error case: the fit did not converge if(iter >= NMS_ITERATIONS) @@ -2121,16 +2111,22 @@ static dt_iop_ashift_nmsresult_t nmsfit(dt_iop_module_t *module, dt_iop_ashift_p // fit was successful: now consolidate the results (order matters!!!) pcount = 0; - fit.rotation = isnan(fit.rotation) ? ilogit(params[pcount++], -fit.rotation_range, fit.rotation_range) : fit.rotation; - fit.lensshift_v = isnan(fit.lensshift_v) ? ilogit(params[pcount++], -fit.lensshift_v_range, fit.lensshift_v_range) : fit.lensshift_v; - fit.lensshift_h = isnan(fit.lensshift_h) ? ilogit(params[pcount++], -fit.lensshift_h_range, fit.lensshift_h_range) : fit.lensshift_h; + fit.rotation = isnan(fit.rotation) ? ilogit(params[pcount++], -fit.rotation_range, fit.rotation_range) + : fit.rotation; + fit.lensshift_v = isnan(fit.lensshift_v) + ? ilogit(params[pcount++], -fit.lensshift_v_range, fit.lensshift_v_range) + : fit.lensshift_v; + fit.lensshift_h = isnan(fit.lensshift_h) + ? ilogit(params[pcount++], -fit.lensshift_h_range, fit.lensshift_h_range) + : fit.lensshift_h; fit.shear = isnan(fit.shear) ? ilogit(params[pcount++], -fit.shear_range, fit.shear_range) : fit.shear; #ifdef ASHIFT_DEBUG printf("params after optimization (%d interations): rotation %f, lensshift_v %f, lensshift_h %f, shear %f\n", iter, fit.rotation, fit.lensshift_v, fit.lensshift_h, fit.shear); #endif - // sanity check: in case of extreme values the image gets distorted so strongly that it spans an insanely huge area. we check that + // sanity check: in case of extreme values the image gets distorted so strongly that it spans an insanely huge + // area. we check that // case and assume values that increase the image area by more than a factor of 4 as being insane. float homograph[3][3]; homography((float *)homograph, fit.rotation, fit.lensshift_v, fit.lensshift_h, fit.shear, fit.f_length_kb, @@ -2205,8 +2201,7 @@ static void model_probe(dt_iop_module_t *module, dt_iop_ashift_params_t *p, dt_i // if the image is flipped and if we do not want to fit both lens shift // directions or none at all, then we need to change direction dt_iop_ashift_fitaxis_t mdir = dir; - if((mdir & ASHIFT_FIT_LENS_BOTH) != ASHIFT_FIT_LENS_BOTH && - (mdir & ASHIFT_FIT_LENS_BOTH) != 0) + if((mdir & ASHIFT_FIT_LENS_BOTH) != ASHIFT_FIT_LENS_BOTH && (mdir & ASHIFT_FIT_LENS_BOTH) != 0) { // flip all directions mdir ^= g->isflipped ? ASHIFT_FIT_FLIP : 0; @@ -2241,8 +2236,8 @@ static void model_probe(dt_iop_module_t *module, dt_iop_ashift_params_t *p, dt_i double quality = model_fitness(params, (void *)&fit); - printf("model fitness: %.8f (rotation %f, lensshift_v %f, lensshift_h %f, shear %f)\n", - quality, p->rotation, p->lensshift_v, p->lensshift_h, p->shear); + printf("model fitness: %.8f (rotation %f, lensshift_v %f, lensshift_h %f, shear %f)\n", quality, p->rotation, + p->lensshift_v, p->lensshift_h, p->shear); } #endif @@ -2255,7 +2250,7 @@ static void crop_constraint(double *params, int pcount) if(pcount > 0 && params[0] > 1.0) params[0] = 1.0 - params[0]; if(pcount > 1 && params[1] > 1.0) params[1] = 1.0 - params[1]; - if(pcount > 2 && params[2] > 0.5*M_PI) params[2] = 0.5*M_PI - params[2]; + if(pcount > 2 && params[2] > 0.5 * M_PI) params[2] = 0.5 * M_PI - params[2]; } // helper function for getting the best fitting crop area; @@ -2314,8 +2309,7 @@ static double crop_fitness(double *params, void *data) } // special case: I[2] is 0.0f -> E and D are parallel and intersect at infinity -> no relevant point - if(I[2] == 0.0f) - continue; + if(I[2] == 0.0f) continue; // the default case -> normlize I I[0] /= I[2]; @@ -2332,8 +2326,7 @@ static double crop_fitness(double *params, void *data) const float A = 2.0f * d2min * sin(2.0f * alpha); #ifdef ASHIFT_DEBUG - printf("crop fitness with x %f, y %f, angle %f -> distance %f, area %f\n", - x, y, alpha, d2min, A); + printf("crop fitness with x %f, y %f, angle %f -> distance %f, area %f\n", x, y, alpha, d2min, A); #endif // and return -A to allow Nelder-Mead simplex to search for the minimum return -A; @@ -2378,22 +2371,18 @@ static void do_crop(dt_iop_module_t *module, dt_iop_ashift_params_t *p) dt_iop_ashift_cropfit_params_t cropfit; cropfit.width = g->buf_width; cropfit.height = g->buf_height; - homography((float *)cropfit.homograph, rotation, lensshift_v, lensshift_h, shear, f_length_kb, - orthocorr, aspect, cropfit.width, cropfit.height, ASHIFT_HOMOGRAPH_FORWARD); + homography((float *)cropfit.homograph, rotation, lensshift_v, lensshift_h, shear, f_length_kb, orthocorr, aspect, + cropfit.width, cropfit.height, ASHIFT_HOMOGRAPH_FORWARD); const float wd = cropfit.width; const float ht = cropfit.height; // the four vertices of the image in input image coordinates - const float Vc[4][3] = { { 0.0f, 0.0f, 1.0f }, - { 0.0f, ht, 1.0f }, - { wd, ht, 1.0f }, - { wd, 0.0f, 1.0f } }; + const float Vc[4][3] = { { 0.0f, 0.0f, 1.0f }, { 0.0f, ht, 1.0f }, { wd, ht, 1.0f }, { wd, 0.0f, 1.0f } }; // convert the vertices to output image coordinates float V[4][3]; - for(int n = 0; n < 4; n++) - mat3mulv(V[n], (float *)cropfit.homograph, Vc[n]); + for(int n = 0; n < 4; n++) mat3mulv(V[n], (float *)cropfit.homograph, Vc[n]); // get width and height of output image for later use float xmin = FLT_MAX, ymin = FLT_MAX, xmax = FLT_MIN, ymax = FLT_MIN; @@ -2412,8 +2401,7 @@ static void do_crop(dt_iop_module_t *module, dt_iop_ashift_params_t *p) const float oht = ymax - ymin; // calculate the lines defining the four edges of the image area: E = V[n] x V[n+1] - for(int n = 0; n < 4; n++) - vec3prodn(cropfit.edges[n], V[n], V[(n + 1) % 4]); + for(int n = 0; n < 4; n++) vec3prodn(cropfit.edges[n], V[n], V[(n + 1) % 4]); // initial fit parameters: crop area is centered and aspect angle is that of the original image // number of parameters: fit only crop center coordinates with a fixed aspect ratio, or fit all three variables @@ -2439,7 +2427,7 @@ static void do_crop(dt_iop_module_t *module, dt_iop_ashift_params_t *p) // start the simplex fit int iter = simplex(crop_fitness, params, pcount, NMS_CROP_EPSILON, NMS_CROP_SCALE, NMS_CROP_ITERATIONS, - crop_constraint, (void*)&cropfit); + crop_constraint, (void *)&cropfit); // in case the fit did not converge -> failed if(iter >= NMS_CROP_ITERATIONS) goto failed; @@ -2450,7 +2438,7 @@ static void do_crop(dt_iop_module_t *module, dt_iop_ashift_params_t *p) cropfit.alpha = isnan(cropfit.alpha) ? params[2] : cropfit.alpha; // the area of the best fitting rectangle - const float A = fabs(crop_fitness(params, (void*)&cropfit)); + const float A = fabs(crop_fitness(params, (void *)&cropfit)); // unlikely to happen but we need to catch this case if(A == 0.0f) goto failed; @@ -2480,8 +2468,9 @@ static void do_crop(dt_iop_module_t *module, dt_iop_ashift_params_t *p) g->fitting = 0; #ifdef ASHIFT_DEBUG - printf("margins after crop fitting: iter %d, x %f, y %f, angle %f, crop area (%f %f %f %f), width %f, height %f\n", - iter, cropfit.x, cropfit.y, cropfit.alpha, p->cl, p->cr, p->ct, p->cb, wd, ht); + printf( + "margins after crop fitting: iter %d, x %f, y %f, angle %f, crop area (%f %f %f %f), width %f, height %f\n", + iter, cropfit.x, cropfit.y, cropfit.alpha, p->cl, p->cr, p->ct, p->cb, wd, ht); #endif return; @@ -2500,8 +2489,7 @@ static void do_crop(dt_iop_module_t *module, dt_iop_ashift_params_t *p) } // helper function to start analysis for structural data and report about errors -static int do_get_structure(dt_iop_module_t *module, dt_iop_ashift_params_t *p, - dt_iop_ashift_enhance_t enhance) +static int do_get_structure(dt_iop_module_t *module, dt_iop_ashift_params_t *p, dt_iop_ashift_enhance_t enhance) { dt_iop_ashift_gui_data_t *g = (dt_iop_ashift_gui_data_t *)module->gui_data; @@ -2639,8 +2627,7 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const float ivecl = sqrt(ivec[0] * ivec[0] + ivec[1] * ivec[1]); // where do they go? - dt_dev_distort_backtransform_plus(self->dev, self->dev->preview_pipe, self->priority + 1, 9999999, points, - 2); + dt_dev_distort_backtransform_plus(self->dev, self->dev->preview_pipe, self->priority + 1, 9999999, points, 2); float ovec[2] = { points[2] - points[0], points[3] - points[1] }; float ovecl = sqrt(ovec[0] * ovec[0] + ovec[1] * ovec[1]); @@ -2692,8 +2679,9 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const const struct dt_interpolation *interpolation = dt_interpolation_new(DT_INTERPOLATION_USERPREF); float ihomograph[3][3]; - homography((float *)ihomograph, data->rotation, data->lensshift_v, data->lensshift_h, data->shear, data->f_length_kb, - data->orthocorr, data->aspect, piece->buf_in.width, piece->buf_in.height, ASHIFT_HOMOGRAPH_INVERTED); + homography((float *)ihomograph, data->rotation, data->lensshift_v, data->lensshift_h, data->shear, + data->f_length_kb, data->orthocorr, data->aspect, piece->buf_in.width, piece->buf_in.height, + ASHIFT_HOMOGRAPH_INVERTED); // clipping offset const float fullwidth = (float)piece->buf_out.width / (data->cr - data->cl); @@ -2771,8 +2759,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m float ivecl = sqrt(ivec[0] * ivec[0] + ivec[1] * ivec[1]); // where do they go? - dt_dev_distort_backtransform_plus(self->dev, self->dev->preview_pipe, self->priority + 1, 9999999, points, - 2); + dt_dev_distort_backtransform_plus(self->dev, self->dev->preview_pipe, self->priority + 1, 9999999, points, 2); float ovec[2] = { points[2] - points[0], points[3] - points[1] }; float ovecl = sqrt(ovec[0] * ovec[0] + ovec[1] * ovec[1]); @@ -2893,8 +2880,8 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m #endif // gather information about "near"-ness in g->points_idx -static void get_near(const float *points, dt_iop_ashift_points_idx_t *points_idx, const int lines_count, - float pzx, float pzy, float delta) +static void get_near(const float *points, dt_iop_ashift_points_idx_t *points_idx, const int lines_count, float pzx, + float pzy, float delta) { const float delta2 = delta * delta; @@ -2903,14 +2890,11 @@ static void get_near(const float *points, dt_iop_ashift_points_idx_t *points_idx points_idx[n].near = 0; // skip irrelevant lines - if(points_idx[n].type == ASHIFT_LINE_IRRELEVANT) - continue; + if(points_idx[n].type == ASHIFT_LINE_IRRELEVANT) continue; // first check if the mouse pointer is outside the bounding box of the line -> skip this line - if(pzx < points_idx[n].bbx - delta && - pzx > points_idx[n].bbX + delta && - pzy < points_idx[n].bby - delta && - pzy > points_idx[n].bbY + delta) + if(pzx < points_idx[n].bbx - delta && pzx > points_idx[n].bbX + delta && pzy < points_idx[n].bby - delta + && pzy > points_idx[n].bbY + delta) continue; // pointer is inside bounding box @@ -2967,13 +2951,11 @@ static void get_bounded_inside(const float *points, dt_iop_ashift_points_idx_t * points_idx[n].bounded = 0; // skip irrelevant lines - if(points_idx[n].type == ASHIFT_LINE_IRRELEVANT) - continue; + if(points_idx[n].type == ASHIFT_LINE_IRRELEVANT) continue; // is the line inside the box ? - if(points_idx[n].bbx >= ax && points_idx[n].bbx <= bx && points_idx[n].bbX >= ax - && points_idx[n].bbX <= bx && points_idx[n].bby >= ay && points_idx[n].bby <= by - && points_idx[n].bbY >= ay && points_idx[n].bbY <= by) + if(points_idx[n].bbx >= ax && points_idx[n].bbx <= bx && points_idx[n].bbX >= ax && points_idx[n].bbX <= bx + && points_idx[n].bby >= ay && points_idx[n].bby <= by && points_idx[n].bbY >= ay && points_idx[n].bbY <= by) { points_idx[n].bounded = 1; // only mark "near"-ness of those lines we are interested in @@ -2990,8 +2972,7 @@ static uint64_t get_lines_hash(const dt_iop_ashift_line_t *lines, const int line { float v[4] = { lines[n].p1[0], lines[n].p1[1], lines[n].p2[0], lines[n].p2[1] }; - for(int i = 0; i < 4; i++) - hash = ((hash << 5) + hash) ^ ((uint32_t *)v)[i]; + for(int i = 0; i < 4; i++) hash = ((hash << 5) + hash) ^ ((uint32_t *)v)[i]; } return hash; } @@ -3054,7 +3035,7 @@ static int get_points(struct dt_iop_module_t *self, const dt_iop_ashift_line_t * for(int n = 0; n < lines_count; n++) { const int length = lines[n].length; - + total_points += length; my_points_idx[n].length = length; @@ -3132,8 +3113,7 @@ static int get_points(struct dt_iop_module_t *self, const dt_iop_ashift_line_t * } // check if lines_version has changed in-between -> too bad: we can forget about all we did :( - if(g->lines_version > lines_version) - goto error; + if(g->lines_version > lines_version) goto error; *points = my_points; *points_idx = my_points_idx; @@ -3153,8 +3133,8 @@ static int gui_has_focus(struct dt_iop_module_t *self) return self->dev->gui_module == self; } -void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, int32_t height, - int32_t pointerx, int32_t pointery) +void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, + int32_t pointery) { dt_develop_t *dev = self->dev; dt_iop_ashift_gui_data_t *g = (dt_iop_ashift_gui_data_t *)self->gui_data; @@ -3172,7 +3152,7 @@ void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, i // we draw the cropping area; we need x_off/y_off/width/height which is only availabe // after g->buf has been processed - if(g->buf && (p->cropmode != ASHIFT_CROP_OFF) && self->enabled) + if(g->buf && (p->cropmode != ASHIFT_CROP_OFF) && self->enabled) { // roi data of the preview pipe input buffer float iwd = g->buf_width; @@ -3181,14 +3161,11 @@ void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, i float iyo = g->buf_y_off; // the four corners of the input buffer of this module - const float V[4][2] = { { ixo, iyo }, - { ixo, iyo + iht }, - { ixo + iwd, iyo + iht }, - { ixo + iwd, iyo } }; + const float V[4][2] = { { ixo, iyo }, { ixo, iyo + iht }, { ixo + iwd, iyo + iht }, { ixo + iwd, iyo } }; // convert coordinates of corners to coordinates of this module's output if(!dt_dev_distort_transform_plus(self->dev, self->dev->preview_pipe, self->priority, self->priority + 1, - (float *)V, 4)) + (float *)V, 4)) return; // get x/y-offset as well as width and height of output buffer @@ -3210,8 +3187,8 @@ void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, i { xmin + p->cr * owd, ymin + p->ct * oht } }; // convert clipping corners to final output image - if(!dt_dev_distort_transform_plus(self->dev, self->dev->preview_pipe, self->priority + 1, 9999999, - (float *)C, 4)) + if(!dt_dev_distort_transform_plus(self->dev, self->dev->preview_pipe, self->priority + 1, 9999999, (float *)C, + 4)) return; cairo_save(cr); @@ -3279,8 +3256,8 @@ void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, i uint64_t lines_hash = get_lines_hash(g->lines, g->lines_count); // points data are missing or outdated, or distortion has changed? - if(g->points == NULL || g->points_idx == NULL || hash != g->grid_hash || - (g->lines_version > g->points_version && g->lines_hash != lines_hash)) + if(g->points == NULL || g->points_idx == NULL || hash != g->grid_hash + || (g->lines_version > g->points_version && g->lines_hash != lines_hash)) { // we need to reprocess points free(g->points); @@ -3300,12 +3277,10 @@ void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, i else if(g->lines_hash == lines_hash) { // update line type information in points_idx - for(int n = 0; n < g->points_lines_count; n++) - g->points_idx[n].type = g->lines[n].type; + for(int n = 0; n < g->points_lines_count; n++) g->points_idx[n].type = g->lines[n].type; // coordinates of lines are unchanged -> we only need to update colors - if(!update_colors(self, g->points_idx, g->points_lines_count)) - return; + if(!update_colors(self, g->points_idx, g->points_lines_count)) return; g->points_version = g->lines_version; } @@ -3321,12 +3296,11 @@ void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, i cairo_translate(cr, -.5f * wd - zoom_x * wd, -.5f * ht - zoom_y * ht); // this must match the sequence of enum dt_iop_ashift_linecolor_t! - const float line_colors[5][4] = - { { 0.3f, 0.3f, 0.3f, 0.8f }, // grey (misc. lines) - { 0.0f, 1.0f, 0.0f, 0.8f }, // green (selected vertical lines) - { 0.8f, 0.0f, 0.0f, 0.8f }, // red (de-selected vertical lines) - { 0.0f, 0.0f, 1.0f, 0.8f }, // blue (selected horizontal lines) - { 0.8f, 0.8f, 0.0f, 0.8f } }; // yellow (de-selected horizontal lines) + const float line_colors[5][4] = { { 0.3f, 0.3f, 0.3f, 0.8f }, // grey (misc. lines) + { 0.0f, 1.0f, 0.0f, 0.8f }, // green (selected vertical lines) + { 0.8f, 0.0f, 0.0f, 0.8f }, // red (de-selected vertical lines) + { 0.0f, 0.0f, 1.0f, 0.8f }, // blue (selected horizontal lines) + { 0.8f, 0.8f, 0.0f, 0.8f } }; // yellow (de-selected horizontal lines) cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); @@ -3391,8 +3365,8 @@ void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, i } // update the number of selected vertical and horizontal lines -static void update_lines_count(const dt_iop_ashift_line_t *lines, const int lines_count, - int *vertical_count, int *horizontal_count) +static void update_lines_count(const dt_iop_ashift_line_t *lines, const int lines_count, int *vertical_count, + int *horizontal_count) { int vlines = 0; int hlines = 0; @@ -3446,8 +3420,7 @@ int mouse_moved(struct dt_iop_module_t *self, double x, double y, double pressur { for(int n = 0; g->selecting_lines_version == g->lines_version && n < g->points_lines_count; n++) { - if(g->points_idx[n].near == 0) - continue; + if(g->points_idx[n].near == 0) continue; if(g->isdeselecting) g->lines[n].type &= ~ASHIFT_LINE_SELECTED; @@ -3478,8 +3451,7 @@ int button_pressed(struct dt_iop_module_t *self, double x, double y, double pres int handled = 0; // do nothing if visibility of lines is switched off or no lines available - if(g->lines_suppressed || g->lines == NULL) - return FALSE; + if(g->lines_suppressed || g->lines == NULL) return FALSE; // remember lines version at this stage so we can continuously monitor if the // lines have changed in-between @@ -3515,8 +3487,7 @@ int button_pressed(struct dt_iop_module_t *self, double x, double y, double pres // left-click selects and right-click deselects the line for(int n = 0; g->selecting_lines_version == g->lines_version && n < g->points_lines_count; n++) { - if(g->points_idx[n].near == 0) - continue; + if(g->points_idx[n].near == 0) continue; if(which == 3) g->lines[n].type &= ~ASHIFT_LINE_SELECTED; @@ -3596,7 +3567,7 @@ int button_released(struct dt_iop_module_t *self, double x, double y, int which, g->selecting_lines_version++; } - dt_control_queue_redraw_center(); + dt_control_queue_redraw_center(); } } @@ -4026,7 +3997,7 @@ static void process_after_preview_callback(gpointer instance, gpointer user_data } dt_dev_add_history_item(darktable.develop, self, TRUE); break; - + case ASHIFT_JOBCODE_NONE: default: break; @@ -4120,11 +4091,12 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_ashift_params_t)); module->default_params = calloc(1, sizeof(dt_iop_ashift_params_t)); module->default_enabled = 0; - module->priority = 205; // module order created by iop_dependencies.py, do not edit! + module->priority = 217; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_ashift_params_t); module->gui_data = NULL; - dt_iop_ashift_params_t tmp = (dt_iop_ashift_params_t){ 0.0f, 0.0f, 0.0f, 0.0f, DEFAULT_F_LENGTH, 1.0f, 100.0f, 1.0f, ASHIFT_MODE_GENERIC, 0, - ASHIFT_CROP_OFF, 0.0f, 1.0f, 0.0f, 1.0f }; + dt_iop_ashift_params_t tmp + = (dt_iop_ashift_params_t){ 0.0f, 0.0f, 0.0f, 0.0f, DEFAULT_F_LENGTH, 1.0f, 100.0f, 1.0f, + ASHIFT_MODE_GENERIC, 0, ASHIFT_CROP_OFF, 0.0f, 1.0f, 0.0f, 1.0f }; memcpy(module->params, &tmp, sizeof(dt_iop_ashift_params_t)); memcpy(module->default_params, &tmp, sizeof(dt_iop_ashift_params_t)); } @@ -4145,20 +4117,22 @@ void reload_defaults(dt_iop_module_t *module) // orientation only needed as a-priori information to correctly label some sliders // before pixelpipe has been set up. later we will get a definite result by // assessing the pixelpipe - isflipped = (img->orientation == ORIENTATION_ROTATE_CCW_90_DEG - || img->orientation == ORIENTATION_ROTATE_CW_90_DEG) - ? 1 - : 0; + isflipped + = (img->orientation == ORIENTATION_ROTATE_CCW_90_DEG || img->orientation == ORIENTATION_ROTATE_CW_90_DEG) + ? 1 + : 0; // focal length should be available in exif data if lens is electronically coupled to the camera - f_length = isfinite(img->exif_focal_length) && img->exif_focal_length > 0.0f ? img->exif_focal_length : f_length; + f_length = isfinite(img->exif_focal_length) && img->exif_focal_length > 0.0f ? img->exif_focal_length + : f_length; // crop factor of the camera is often not available and user will need to set it manually in the gui crop_factor = isfinite(img->exif_crop) && img->exif_crop > 0.0f ? img->exif_crop : crop_factor; } // init defaults: - dt_iop_ashift_params_t tmp = (dt_iop_ashift_params_t){ 0.0f, 0.0f, 0.0f, 0.0f, f_length, crop_factor, 100.0f, 1.0f, ASHIFT_MODE_GENERIC, 0, - ASHIFT_CROP_OFF, 0.0f, 1.0f, 0.0f, 1.0f }; + dt_iop_ashift_params_t tmp + = (dt_iop_ashift_params_t){ 0.0f, 0.0f, 0.0f, 0.0f, f_length, crop_factor, 100.0f, 1.0f, ASHIFT_MODE_GENERIC, + 0, ASHIFT_CROP_OFF, 0.0f, 1.0f, 0.0f, 1.0f }; memcpy(module->params, &tmp, sizeof(dt_iop_ashift_params_t)); memcpy(module->default_params, &tmp, sizeof(dt_iop_ashift_params_t)); @@ -4195,7 +4169,7 @@ void reload_defaults(dt_iop_module_t *module) g->fitting = 0; free(g->lines); g->lines = NULL; - g->lines_count =0; + g->lines_count = 0; g->horizontal_count = 0; g->vertical_count = 0; g->grid_hash = 0; @@ -4227,8 +4201,7 @@ void reload_defaults(dt_iop_module_t *module) void init_global(dt_iop_module_so_t *module) { - dt_iop_ashift_global_data_t *gd - = (dt_iop_ashift_global_data_t *)malloc(sizeof(dt_iop_ashift_global_data_t)); + dt_iop_ashift_global_data_t *gd = (dt_iop_ashift_global_data_t *)malloc(sizeof(dt_iop_ashift_global_data_t)); module->data = gd; const int program = 2; // basic.cl, from programs.conf @@ -4284,8 +4257,7 @@ static gboolean draw(GtkWidget *widget, cairo_t *cr, dt_iop_module_t *self) void gui_focus(struct dt_iop_module_t *self, gboolean in) { - if(self->enabled) - dt_dev_reprocess_all(self->dev); + if(self->enabled) dt_dev_reprocess_all(self->dev); } static float log10_callback(GtkWidget *self, float inval, dt_bauhaus_callback_t dir) @@ -4370,23 +4342,26 @@ void gui_init(struct dt_iop_module_t *self) self->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, DT_BAUHAUS_SPACE); - g->rotation = dt_bauhaus_slider_new_with_range(self, -ROTATION_RANGE, ROTATION_RANGE, 0.01*ROTATION_RANGE, p->rotation, 2); + g->rotation = dt_bauhaus_slider_new_with_range(self, -ROTATION_RANGE, ROTATION_RANGE, 0.01 * ROTATION_RANGE, + p->rotation, 2); dt_bauhaus_widget_set_label(g->rotation, NULL, _("rotation")); dt_bauhaus_slider_set_format(g->rotation, "%.2f°"); dt_bauhaus_slider_enable_soft_boundaries(g->rotation, -ROTATION_RANGE_SOFT, ROTATION_RANGE_SOFT); gtk_box_pack_start(GTK_BOX(self->widget), g->rotation, TRUE, TRUE, 0); - g->lensshift_v = dt_bauhaus_slider_new_with_range(self, -LENSSHIFT_RANGE, LENSSHIFT_RANGE, 0.01*LENSSHIFT_RANGE, p->lensshift_v, 3); + g->lensshift_v = dt_bauhaus_slider_new_with_range(self, -LENSSHIFT_RANGE, LENSSHIFT_RANGE, + 0.01 * LENSSHIFT_RANGE, p->lensshift_v, 3); dt_bauhaus_widget_set_label(g->lensshift_v, NULL, _("lens shift (vertical)")); dt_bauhaus_slider_enable_soft_boundaries(g->lensshift_v, -LENSSHIFT_RANGE_SOFT, LENSSHIFT_RANGE_SOFT); gtk_box_pack_start(GTK_BOX(self->widget), g->lensshift_v, TRUE, TRUE, 0); - g->lensshift_h = dt_bauhaus_slider_new_with_range(self, -LENSSHIFT_RANGE, LENSSHIFT_RANGE, 0.01*LENSSHIFT_RANGE, p->lensshift_h, 3); + g->lensshift_h = dt_bauhaus_slider_new_with_range(self, -LENSSHIFT_RANGE, LENSSHIFT_RANGE, + 0.01 * LENSSHIFT_RANGE, p->lensshift_h, 3); dt_bauhaus_widget_set_label(g->lensshift_h, NULL, _("lens shift (horizontal)")); dt_bauhaus_slider_enable_soft_boundaries(g->lensshift_h, -LENSSHIFT_RANGE_SOFT, LENSSHIFT_RANGE_SOFT); gtk_box_pack_start(GTK_BOX(self->widget), g->lensshift_h, TRUE, TRUE, 0); - g->shear = dt_bauhaus_slider_new_with_range(self, -SHEAR_RANGE, SHEAR_RANGE, 0.01*SHEAR_RANGE, p->shear, 3); + g->shear = dt_bauhaus_slider_new_with_range(self, -SHEAR_RANGE, SHEAR_RANGE, 0.01 * SHEAR_RANGE, p->shear, 3); dt_bauhaus_widget_set_label(g->shear, NULL, _("shear")); dt_bauhaus_slider_enable_soft_boundaries(g->shear, -SHEAR_RANGE_SOFT, SHEAR_RANGE_SOFT); gtk_box_pack_start(GTK_BOX(self->widget), g->shear, TRUE, TRUE, 0); @@ -4522,8 +4497,9 @@ void gui_init(struct dt_iop_module_t *self) gtk_widget_set_tooltip_text(g->crop_factor, _("crop factor of the camera sensor, " "default value set from exif data if available, " "manual setting is often required")); - gtk_widget_set_tooltip_text(g->orthocorr, _("the level of lens dependent correction, set to maximum for full lens dependency, " - "set to zero for the generic case")); + gtk_widget_set_tooltip_text(g->orthocorr, + _("the level of lens dependent correction, set to maximum for full lens dependency, " + "set to zero for the generic case")); gtk_widget_set_tooltip_text(g->aspect, _("adjust aspect ratio of image by horizontal and vertical scaling")); gtk_widget_set_tooltip_text(g->fit_v, _("automatically correct for vertical perspective distortion\n" "ctrl-click to only fit rotation\n" @@ -4557,8 +4533,10 @@ void gui_init(struct dt_iop_module_t *self) g_signal_connect(G_OBJECT(g->aspect), "value-changed", G_CALLBACK(aspect_callback), self); g_signal_connect(G_OBJECT(g->fit_v), "button-press-event", G_CALLBACK(fit_v_button_clicked), (gpointer)self); g_signal_connect(G_OBJECT(g->fit_h), "button-press-event", G_CALLBACK(fit_h_button_clicked), (gpointer)self); - g_signal_connect(G_OBJECT(g->fit_both), "button-press-event", G_CALLBACK(fit_both_button_clicked), (gpointer)self); - g_signal_connect(G_OBJECT(g->structure), "button-press-event", G_CALLBACK(structure_button_clicked), (gpointer)self); + g_signal_connect(G_OBJECT(g->fit_both), "button-press-event", G_CALLBACK(fit_both_button_clicked), + (gpointer)self); + g_signal_connect(G_OBJECT(g->structure), "button-press-event", G_CALLBACK(structure_button_clicked), + (gpointer)self); g_signal_connect(G_OBJECT(g->clean), "clicked", G_CALLBACK(clean_button_clicked), (gpointer)self); g_signal_connect(G_OBJECT(g->eye), "toggled", G_CALLBACK(eye_button_toggled), (gpointer)self); g_signal_connect(G_OBJECT(self->widget), "draw", G_CALLBACK(draw), self); @@ -4566,7 +4544,6 @@ void gui_init(struct dt_iop_module_t *self) /* add signal handler for preview pipe finish to redraw the overlay */ dt_control_signal_connect(darktable.signals, DT_SIGNAL_DEVELOP_PREVIEW_PIPE_FINISHED, G_CALLBACK(process_after_preview_callback), self); - } void gui_cleanup(struct dt_iop_module_t *self) diff --git a/src/iop/ashift_nmsimplex.c b/src/iop/ashift_nmsimplex.c index 10dc533435b7..e4e332c6332b 100644 --- a/src/iop/ashift_nmsimplex.c +++ b/src/iop/ashift_nmsimplex.c @@ -99,7 +99,7 @@ static int simplex(double (*objfunc)(double[], void *params), double start[], in double *ve; /* expansion - coordinates */ double *vc; /* contraction - coordinates */ double *vm; /* centroid - coordinates */ - //double min; + // double min; double fsum, favg, s, cent; diff --git a/src/iop/atrous.c b/src/iop/atrous.c index 3c51a0b5d546..4e65a863115a 100644 --- a/src/iop/atrous.c +++ b/src/iop/atrous.c @@ -46,17 +46,17 @@ DT_MODULE_INTROSPECTION(1, dt_iop_atrous_params_t) #define MAX_NUM_SCALES 8 // 2*2^(i+1) + 1 = 1025px support for i = 8 #define RES 64 -#define dt_atrous_show_upper_label(cr, text, layout, ink) \ - pango_layout_set_text(layout, text, -1); \ - pango_layout_get_pixel_extents(layout, &ink, NULL); \ - cairo_move_to(cr, .5 * (width - ink.width), (.08 * height) - ink.height); \ +#define dt_atrous_show_upper_label(cr, text, layout, ink) \ + pango_layout_set_text(layout, text, -1); \ + pango_layout_get_pixel_extents(layout, &ink, NULL); \ + cairo_move_to(cr, .5 * (width - ink.width), (.08 * height) - ink.height); \ pango_cairo_show_layout(cr, layout); -#define dt_atrous_show_lower_label(cr, text, layout, ink) \ - pango_layout_set_text(layout, text, -1); \ - pango_layout_get_pixel_extents(layout, &ink, NULL); \ - cairo_move_to(cr, .5 * (width - ink.width), (.98 * height) - ink.height); \ +#define dt_atrous_show_lower_label(cr, text, layout, ink) \ + pango_layout_set_text(layout, text, -1); \ + pango_layout_get_pixel_extents(layout, &ink, NULL); \ + cairo_move_to(cr, .5 * (width - ink.width), (.98 * height) - ink.height); \ pango_cairo_show_layout(cr, layout); @@ -137,9 +137,9 @@ void connect_key_accels(dt_iop_module_t *self) #define ALIGNED(a) __attribute__((aligned(a))) -#define VEC4(a) \ - { \ - (a), (a), (a), (a) \ +#define VEC4(a) \ + { \ + (a), (a), (a), (a) \ } #if defined(__SSE2__) @@ -192,121 +192,121 @@ static inline __m128 weight_sse2(const __m128 *c1, const __m128 *c2, const float __m128 square2 = _mm_shuffle_ps(square, square, _MM_SHUFFLE(3, 1, 2, 0)); // (?, d2, d3, d1) __m128 added = _mm_add_ps(square, square2); // (?, d2+d3, d2+d3, 2*d1) added = _mm_sub_ss(added, square); // (?, d2+d3, d2+d3, d1) - __m128 sharpened = _mm_mul_ps(added, vsharpen); // (?, -s*(d2+d3), -s*(d2+d3), -s*d1) - __m128 exp = dt_fast_expf_sse2(sharpened); // (?, wc, wc, wl) - exp = _mm_castsi128_ps(_mm_slli_si128(_mm_castps_si128(exp), 4)); // (wc, wc, wl, 0) - exp = _mm_castsi128_ps(_mm_srli_si128(_mm_castps_si128(exp), 4)); // (0, wc, wc, wl) - exp = _mm_or_ps(exp, ooo1); // (1, wc, wc, wl) + __m128 sharpened = _mm_mul_ps(added, vsharpen); // (?, -s*(d2+d3), -s*(d2+d3), -s*d1) + __m128 exp = dt_fast_expf_sse2(sharpened); // (?, wc, wc, wl) + exp = _mm_castsi128_ps(_mm_slli_si128(_mm_castps_si128(exp), 4)); // (wc, wc, wl, 0) + exp = _mm_castsi128_ps(_mm_srli_si128(_mm_castps_si128(exp), 4)); // (0, wc, wc, wl) + exp = _mm_or_ps(exp, ooo1); // (1, wc, wc, wl) return exp; } #endif -#define SUM_PIXEL_CONTRIBUTION_COMMON(ii, jj) \ - do \ - { \ - const float f = filter[(ii)] * filter[(jj)]; \ - float wp[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; \ - weight(px, px2, sharpen, wp); \ - float w[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; \ - for(int c = 0; c < 4; c++) w[c] = f * wp[c]; \ - float pd[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; \ - for(int c = 0; c < 4; c++) pd[c] = w[c] * px2[c]; \ - for(int c = 0; c < 4; c++) sum[c] += pd[c]; \ - for(int c = 0; c < 4; c++) wgt[c] += w[c]; \ +#define SUM_PIXEL_CONTRIBUTION_COMMON(ii, jj) \ + do \ + { \ + const float f = filter[(ii)] * filter[(jj)]; \ + float wp[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; \ + weight(px, px2, sharpen, wp); \ + float w[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; \ + for(int c = 0; c < 4; c++) w[c] = f * wp[c]; \ + float pd[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; \ + for(int c = 0; c < 4; c++) pd[c] = w[c] * px2[c]; \ + for(int c = 0; c < 4; c++) sum[c] += pd[c]; \ + for(int c = 0; c < 4; c++) wgt[c] += w[c]; \ } while(0) #if defined(__SSE2__) -#define SUM_PIXEL_CONTRIBUTION_COMMON_SSE2(ii, jj) \ - do \ - { \ - const __m128 f = _mm_set1_ps(filter[(ii)] * filter[(jj)]); \ - const __m128 wp = weight_sse2(px, px2, sharpen); \ - const __m128 w = _mm_mul_ps(f, wp); \ - const __m128 pd = _mm_mul_ps(w, *px2); \ - sum = _mm_add_ps(sum, pd); \ - wgt = _mm_add_ps(wgt, w); \ +#define SUM_PIXEL_CONTRIBUTION_COMMON_SSE2(ii, jj) \ + do \ + { \ + const __m128 f = _mm_set1_ps(filter[(ii)] * filter[(jj)]); \ + const __m128 wp = weight_sse2(px, px2, sharpen); \ + const __m128 w = _mm_mul_ps(f, wp); \ + const __m128 pd = _mm_mul_ps(w, *px2); \ + sum = _mm_add_ps(sum, pd); \ + wgt = _mm_add_ps(wgt, w); \ } while(0) #endif -#define SUM_PIXEL_CONTRIBUTION_WITH_TEST(ii, jj) \ - do \ - { \ - const int iii = (ii)-2; \ - const int jjj = (jj)-2; \ - int x = i + mult * iii; \ - int y = j + mult * jjj; \ - \ - if(x < 0) x = 0; \ - if(x >= width) x = width - 1; \ - if(y < 0) y = 0; \ - if(y >= height) y = height - 1; \ - \ - px2 = ((float *)in) + 4 * x + (size_t)4 * y * width; \ - \ - SUM_PIXEL_CONTRIBUTION_COMMON(ii, jj); \ +#define SUM_PIXEL_CONTRIBUTION_WITH_TEST(ii, jj) \ + do \ + { \ + const int iii = (ii)-2; \ + const int jjj = (jj)-2; \ + int x = i + mult * iii; \ + int y = j + mult * jjj; \ + \ + if(x < 0) x = 0; \ + if(x >= width) x = width - 1; \ + if(y < 0) y = 0; \ + if(y >= height) y = height - 1; \ + \ + px2 = ((float *)in) + 4 * x + (size_t)4 * y * width; \ + \ + SUM_PIXEL_CONTRIBUTION_COMMON(ii, jj); \ } while(0) #if defined(__SSE2__) -#define SUM_PIXEL_CONTRIBUTION_WITH_TEST_SSE2(ii, jj) \ - do \ - { \ - const int iii = (ii)-2; \ - const int jjj = (jj)-2; \ - int x = i + mult * iii; \ - int y = j + mult * jjj; \ - \ - if(x < 0) x = 0; \ - if(x >= width) x = width - 1; \ - if(y < 0) y = 0; \ - if(y >= height) y = height - 1; \ - \ - px2 = ((__m128 *)in) + x + (size_t)y * width; \ - \ - SUM_PIXEL_CONTRIBUTION_COMMON_SSE2(ii, jj); \ +#define SUM_PIXEL_CONTRIBUTION_WITH_TEST_SSE2(ii, jj) \ + do \ + { \ + const int iii = (ii)-2; \ + const int jjj = (jj)-2; \ + int x = i + mult * iii; \ + int y = j + mult * jjj; \ + \ + if(x < 0) x = 0; \ + if(x >= width) x = width - 1; \ + if(y < 0) y = 0; \ + if(y >= height) y = height - 1; \ + \ + px2 = ((__m128 *)in) + x + (size_t)y * width; \ + \ + SUM_PIXEL_CONTRIBUTION_COMMON_SSE2(ii, jj); \ } while(0) #endif -#define ROW_PROLOGUE \ - const float *px = ((float *)in) + (size_t)4 * j * width; \ - const float *px2; \ - float *pdetail = detail + (size_t)4 * j * width; \ +#define ROW_PROLOGUE \ + const float *px = ((float *)in) + (size_t)4 * j * width; \ + const float *px2; \ + float *pdetail = detail + (size_t)4 * j * width; \ float *pcoarse = out + (size_t)4 * j * width; #if defined(__SSE2__) -#define ROW_PROLOGUE_SSE \ - const __m128 *px = ((__m128 *)in) + (size_t)j * width; \ - const __m128 *px2; \ - float *pdetail = detail + (size_t)4 * j * width; \ +#define ROW_PROLOGUE_SSE \ + const __m128 *px = ((__m128 *)in) + (size_t)j * width; \ + const __m128 *px2; \ + float *pdetail = detail + (size_t)4 * j * width; \ float *pcoarse = out + (size_t)4 * j * width; #endif -#define SUM_PIXEL_PROLOGUE \ - float sum[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; \ +#define SUM_PIXEL_PROLOGUE \ + float sum[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; \ float wgt[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; #if defined(__SSE2__) -#define SUM_PIXEL_PROLOGUE_SSE \ - __m128 sum = _mm_setzero_ps(); \ +#define SUM_PIXEL_PROLOGUE_SSE \ + __m128 sum = _mm_setzero_ps(); \ __m128 wgt = _mm_setzero_ps(); #endif -#define SUM_PIXEL_EPILOGUE \ - for(int c = 0; c < 4; c++) sum[c] /= wgt[c]; \ - \ - for(int c = 0; c < 4; c++) pdetail[c] = (px[c] - sum[c]); \ - for(int c = 0; c < 4; c++) pcoarse[c] = sum[c]; \ - px += 4; \ - pdetail += 4; \ +#define SUM_PIXEL_EPILOGUE \ + for(int c = 0; c < 4; c++) sum[c] /= wgt[c]; \ + \ + for(int c = 0; c < 4; c++) pdetail[c] = (px[c] - sum[c]); \ + for(int c = 0; c < 4; c++) pcoarse[c] = sum[c]; \ + px += 4; \ + pdetail += 4; \ pcoarse += 4; #if defined(__SSE2__) -#define SUM_PIXEL_EPILOGUE_SSE \ - sum = _mm_mul_ps(sum, _mm_rcp_ps(wgt)); \ - \ - _mm_stream_ps(pdetail, _mm_sub_ps(*px, sum)); \ - _mm_stream_ps(pcoarse, sum); \ - px++; \ - pdetail += 4; \ +#define SUM_PIXEL_EPILOGUE_SSE \ + sum = _mm_mul_ps(sum, _mm_rcp_ps(wgt)); \ + \ + _mm_stream_ps(pdetail, _mm_sub_ps(*px, sum)); \ + _mm_stream_ps(pcoarse, sum); \ + px++; \ + pdetail += 4; \ pcoarse += 4; #endif @@ -549,8 +549,8 @@ typedef void((*eaw_synthesize_t)(float *const out, const float *const in, const const float *thrsf, const float *boostf, const int32_t width, const int32_t height)); -static void eaw_synthesize(float *const out, const float *const in, const float *const detail, - const float *thrsf, const float *boostf, const int32_t width, const int32_t height) +static void eaw_synthesize(float *const out, const float *const in, const float *const detail, const float *thrsf, + const float *boostf, const int32_t width, const int32_t height) { const float threshold[4] = { thrsf[0], thrsf[1], thrsf[2], thrsf[3] }; const float boost[4] = { boostf[0], boostf[1], boostf[2], boostf[3] }; @@ -571,8 +571,7 @@ static void eaw_synthesize(float *const out, const float *const in, const float #if defined(__SSE2__) static void eaw_synthesize_sse2(float *const out, const float *const in, const float *const detail, - const float *thrsf, const float *boostf, const int32_t width, - const int32_t height) + const float *thrsf, const float *boostf, const int32_t width, const int32_t height) { const __m128 threshold = _mm_set_ps(thrsf[3], thrsf[2], thrsf[1], thrsf[0]); const __m128 boost = _mm_set_ps(boostf[3], boostf[2], boostf[1], boostf[0]); @@ -590,8 +589,7 @@ static void eaw_synthesize_sse2(float *const out, const float *const in, const f { const __m128i maski = _mm_set1_epi32(0x80000000u); const __m128 *mask = (__m128 *)&maski; - const __m128 absamt - = _mm_max_ps(_mm_setzero_ps(), _mm_sub_ps(_mm_andnot_ps(*mask, *pdetail), threshold)); + const __m128 absamt = _mm_max_ps(_mm_setzero_ps(), _mm_sub_ps(_mm_andnot_ps(*mask, *pdetail), threshold)); const __m128 amount = _mm_or_ps(_mm_and_ps(*pdetail, *mask), absamt); _mm_stream_ps(pout, _mm_add_ps(*pin, _mm_mul_ps(boost, amount))); pdetail++; @@ -639,9 +637,8 @@ static int get_scales(float (*thrs)[4], float (*boost)[4], float *sharp, const d // cut off too fine ones, if image is not detailed enough (due to roi_in->scale) const float scale = roi_in->scale / piece->iscale; // largest desired filter on input buffer (20% of input dim) - const float supp0 - = MIN(2 * (2 << (MAX_NUM_SCALES - 1)) + 1, - MAX(piece->buf_in.height * piece->iscale, piece->buf_in.width * piece->iscale) * 0.2f); + const float supp0 = MIN(2 * (2 << (MAX_NUM_SCALES - 1)) + 1, + MAX(piece->buf_in.height * piece->iscale, piece->buf_in.width * piece->iscale) * 0.2f); const float i0 = dt_log2f((supp0 - 1.0f) * .5f); int i = 0; for(; i < MAX_NUM_SCALES; i++) @@ -883,21 +880,18 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m dt_iop_nap(darktable.opencl->micro_nap); } - if(!darktable.opencl->async_pixelpipe || piece->pipe->type == DT_DEV_PIXELPIPE_EXPORT) - dt_opencl_finish(devid); + if(!darktable.opencl->async_pixelpipe || piece->pipe->type == DT_DEV_PIXELPIPE_EXPORT) dt_opencl_finish(devid); dt_opencl_release_mem_object(dev_filter); dt_opencl_release_mem_object(dev_tmp); - for(int k = 0; k < max_scale; k++) - dt_opencl_release_mem_object(dev_detail[k]); + for(int k = 0; k < max_scale; k++) dt_opencl_release_mem_object(dev_detail[k]); free(dev_detail); return TRUE; error: dt_opencl_release_mem_object(dev_filter); dt_opencl_release_mem_object(dev_tmp); - for(int k = 0; k < max_scale; k++) - dt_opencl_release_mem_object(dev_detail[k]); + for(int k = 0; k < max_scale; k++) dt_opencl_release_mem_object(dev_detail[k]); free(dev_detail); dt_print(DT_DEBUG_OPENCL, "[opencl_atrous] couldn't enqueue kernel! %d\n", err); return FALSE; @@ -905,8 +899,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m #endif void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling) + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling) { dt_iop_atrous_data_t *d = (dt_iop_atrous_data_t *)piece->data; float thrs[MAX_NUM_SCALES][4]; @@ -929,7 +922,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_atrous_params_t)); module->default_params = calloc(1, sizeof(dt_iop_atrous_params_t)); module->default_enabled = 0; - module->priority = 573; // module order created by iop_dependencies.py, do not edit! + module->priority = 579; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_atrous_params_t); module->gui_data = NULL; dt_iop_atrous_params_t tmp; @@ -948,8 +941,7 @@ void init(dt_iop_module_t *module) void init_global(dt_iop_module_so_t *module) { const int program = 1; // from programs.conf - dt_iop_atrous_global_data_t *gd - = (dt_iop_atrous_global_data_t *)malloc(sizeof(dt_iop_atrous_global_data_t)); + dt_iop_atrous_global_data_t *gd = (dt_iop_atrous_global_data_t *)malloc(sizeof(dt_iop_atrous_global_data_t)); module->data = gd; gd->kernel_decompose = dt_opencl_create_kernel(program, "eaw_decompose"); gd->kernel_synthesize = dt_opencl_create_kernel(program, "eaw_synthesize"); @@ -1190,7 +1182,7 @@ static gboolean area_draw(GtkWidget *widget, cairo_t *crf, gpointer user_data) // clear bg, match color of the notebook tabs: GdkRGBA bright_bg_color, really_dark_bg_color; GtkStyleContext *context = gtk_widget_get_style_context(self->expander); - gboolean color_found = gtk_style_context_lookup_color (context, "selected_bg_color", &bright_bg_color); + gboolean color_found = gtk_style_context_lookup_color(context, "selected_bg_color", &bright_bg_color); if(!color_found) { bright_bg_color.red = 1.0; @@ -1199,7 +1191,7 @@ static gboolean area_draw(GtkWidget *widget, cairo_t *crf, gpointer user_data) bright_bg_color.alpha = 1.0; } - color_found = gtk_style_context_lookup_color (context, "really_dark_bg_color", &really_dark_bg_color); + color_found = gtk_style_context_lookup_color(context, "really_dark_bg_color", &really_dark_bg_color); if(!color_found) { really_dark_bg_color.red = 1.0; @@ -1257,7 +1249,8 @@ static gboolean area_draw(GtkWidget *widget, cairo_t *crf, gpointer user_data) cairo_save(cr); for(int k = 1; k < c->num_samples; k += 2) { - cairo_set_source_rgba(cr, really_dark_bg_color.red, really_dark_bg_color.green, really_dark_bg_color.blue, .3); + cairo_set_source_rgba(cr, really_dark_bg_color.red, really_dark_bg_color.green, really_dark_bg_color.blue, + .3); cairo_move_to(cr, width * c->sample[k - 1], 0.0f); cairo_line_to(cr, width * c->sample[k - 1], -height); cairo_line_to(cr, width * c->sample[k], -height); @@ -1325,8 +1318,7 @@ static gboolean area_draw(GtkWidget *widget, cairo_t *crf, gpointer user_data) for(int k = 0; k < BANDS; k++) dt_draw_curve_set_point(c->minmax_curve, k, p.x[ch2][k], p.y[ch2][k]); dt_draw_curve_calc_values(c->minmax_curve, 0.0, 1.0, RES, c->draw_xs, c->draw_ys); cairo_move_to(cr, width, -height * p.y[ch2][BANDS - 1]); - for(int k = RES - 2; k >= 0; k--) - cairo_line_to(cr, k * width / (float)(RES - 1), -height * c->draw_ys[k]); + for(int k = RES - 2; k >= 0; k--) cairo_line_to(cr, k * width / (float)(RES - 1), -height * c->draw_ys[k]); } else cairo_move_to(cr, 0, 0); @@ -1368,8 +1360,7 @@ static gboolean area_draw(GtkWidget *widget, cairo_t *crf, gpointer user_data) // cairo_set_source_rgba(cr, .6, .6, .6, .5); cairo_move_to(cr, 0, -height * c->draw_min_ys[0]); for(int k = 1; k < RES; k++) cairo_line_to(cr, k * width / (float)(RES - 1), -height * c->draw_min_ys[k]); - for(int k = RES - 1; k >= 0; k--) - cairo_line_to(cr, k * width / (float)(RES - 1), -height * c->draw_max_ys[k]); + for(int k = RES - 1; k >= 0; k--) cairo_line_to(cr, k * width / (float)(RES - 1), -height * c->draw_max_ys[k]); cairo_close_path(cr); cairo_fill(cr); // draw mouse focus circle @@ -1533,14 +1524,13 @@ static gboolean area_motion_notify(GtkWidget *widget, GdkEventMotion *event, gpo gtk_widget_queue_draw(widget); gint x, y; #if GTK_CHECK_VERSION(3, 20, 0) - gdk_window_get_device_position(event->window, - gdk_seat_get_pointer(gdk_display_get_default_seat(gtk_widget_get_display(widget))), - &x, &y, 0); + gdk_window_get_device_position( + event->window, gdk_seat_get_pointer(gdk_display_get_default_seat(gtk_widget_get_display(widget))), &x, &y, 0); #else - gdk_window_get_device_position(event->window, - gdk_device_manager_get_client_pointer( - gdk_display_get_device_manager(gdk_window_get_display(event->window))), - &x, &y, NULL); + gdk_window_get_device_position( + event->window, + gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gdk_window_get_display(event->window))), + &x, &y, NULL); #endif return TRUE; } @@ -1572,8 +1562,7 @@ static gboolean area_button_press(GtkWidget *widget, GdkEventButton *event, gpoi GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); int height = allocation.height - 2 * inset, width = allocation.width - 2 * inset; - c->mouse_pick - = dt_draw_curve_calc_value(c->minmax_curve, CLAMP(event->x - inset, 0, width) / (float)width); + c->mouse_pick = dt_draw_curve_calc_value(c->minmax_curve, CLAMP(event->x - inset, 0, width) / (float)width); c->mouse_pick -= 1.0 - CLAMP(event->y - inset, 0, height) / (float)height; c->dragging = 1; return TRUE; @@ -1657,19 +1646,21 @@ void gui_init(struct dt_iop_module_t *self) c->channel_tabs = GTK_NOTEBOOK(gtk_notebook_new()); - gtk_notebook_append_page(GTK_NOTEBOOK(c->channel_tabs), - GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)), gtk_label_new(_("luma"))); - gtk_widget_set_tooltip_text(gtk_notebook_get_tab_label(c->channel_tabs, gtk_notebook_get_nth_page(c->channel_tabs, -1)), - _("change lightness at each feature size")); - gtk_notebook_append_page(GTK_NOTEBOOK(c->channel_tabs), - GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)), + gtk_notebook_append_page(GTK_NOTEBOOK(c->channel_tabs), GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)), + gtk_label_new(_("luma"))); + gtk_widget_set_tooltip_text( + gtk_notebook_get_tab_label(c->channel_tabs, gtk_notebook_get_nth_page(c->channel_tabs, -1)), + _("change lightness at each feature size")); + gtk_notebook_append_page(GTK_NOTEBOOK(c->channel_tabs), GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)), gtk_label_new(_("chroma"))); - gtk_widget_set_tooltip_text(gtk_notebook_get_tab_label(c->channel_tabs, gtk_notebook_get_nth_page(c->channel_tabs, -1)), - _("change color saturation at each feature size")); - gtk_notebook_append_page(GTK_NOTEBOOK(c->channel_tabs), - GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)), gtk_label_new(_("edges"))); - gtk_widget_set_tooltip_text(gtk_notebook_get_tab_label(c->channel_tabs, gtk_notebook_get_nth_page(c->channel_tabs, -1)), - _("change edge halos at each feature size\nonly changes results of luma and chroma tabs")); + gtk_widget_set_tooltip_text( + gtk_notebook_get_tab_label(c->channel_tabs, gtk_notebook_get_nth_page(c->channel_tabs, -1)), + _("change color saturation at each feature size")); + gtk_notebook_append_page(GTK_NOTEBOOK(c->channel_tabs), GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)), + gtk_label_new(_("edges"))); + gtk_widget_set_tooltip_text( + gtk_notebook_get_tab_label(c->channel_tabs, gtk_notebook_get_nth_page(c->channel_tabs, -1)), + _("change edge halos at each feature size\nonly changes results of luma and chroma tabs")); gtk_widget_show_all(GTK_WIDGET(gtk_notebook_get_nth_page(c->channel_tabs, c->channel))); gtk_notebook_set_current_page(GTK_NOTEBOOK(c->channel_tabs), c->channel); @@ -1683,9 +1674,9 @@ void gui_init(struct dt_iop_module_t *self) gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(c->area), TRUE, TRUE, 0); gtk_widget_add_events(GTK_WIDGET(c->area), GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK - | GDK_SMOOTH_SCROLL_MASK); + | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK + | GDK_SMOOTH_SCROLL_MASK); g_signal_connect(G_OBJECT(c->area), "draw", G_CALLBACK(area_draw), self); g_signal_connect(G_OBJECT(c->area), "button-press-event", G_CALLBACK(area_button_press), self); g_signal_connect(G_OBJECT(c->area), "button-release-event", G_CALLBACK(area_button_release), self); diff --git a/src/iop/basecurve.c b/src/iop/basecurve.c index 7f86ee620119..9706ec19ca74 100644 --- a/src/iop/basecurve.c +++ b/src/iop/basecurve.c @@ -60,9 +60,9 @@ typedef struct dt_iop_basecurve_params_t dt_iop_basecurve_node_t basecurve[3][MAXNODES]; int basecurve_nodes[3]; int basecurve_type[3]; - int exposure_fusion; // number of exposure fusion steps - float exposure_stops; // number of stops between fusion images - float exposure_bias; // whether to do exposure-fusion with over or under-exposure + int exposure_fusion; // number of exposure fusion steps + float exposure_stops; // number of stops between fusion images + float exposure_bias; // whether to do exposure-fusion with over or under-exposure } dt_iop_basecurve_params_t; typedef struct dt_iop_basecurve_params3_t @@ -94,8 +94,8 @@ typedef struct dt_iop_basecurve_params1_t int tonecurve_preset; } dt_iop_basecurve_params1_t; -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 1 && new_version == 5) { @@ -105,10 +105,12 @@ int legacy_params(dt_iop_module_t *self, const void *const old_params, const int // start with a fresh copy of default parameters // unfortunately default_params aren't inited at this stage. *n = (dt_iop_basecurve_params_t){ { - { { 0.0, 0.0 }, { 1.0, 1.0 } }, + { { 0.0, 0.0 }, { 1.0, 1.0 } }, }, { 2, 3, 3 }, - { MONOTONE_HERMITE, MONOTONE_HERMITE, MONOTONE_HERMITE } , 0, 1}; + { MONOTONE_HERMITE, MONOTONE_HERMITE, MONOTONE_HERMITE }, + 0, + 1 }; for(int k = 0; k < 6; k++) n->basecurve[0][k].x = o->tonecurve_x[k]; for(int k = 0; k < 6; k++) n->basecurve[0][k].y = o->tonecurve_y[k]; n->basecurve_nodes[0] = 6; @@ -303,7 +305,8 @@ int flags() return IOP_FLAGS_SUPPORTS_BLENDING | IOP_FLAGS_ALLOW_TILING; } -static void set_presets(dt_iop_module_so_t *self, const basecurve_preset_t *presets, int count, int *force_autoapply) +static void set_presets(dt_iop_module_so_t *self, const basecurve_preset_t *presets, int count, + int *force_autoapply) { // transform presets above to db entries. for(int k = 0; k < count; k++) @@ -317,13 +320,13 @@ static void set_presets(dt_iop_module_so_t *self, const basecurve_preset_t *pres tmp.exposure_bias = 1.0f; } // add the preset. - dt_gui_presets_add_generic(_(presets[k].name), self->op, self->version(), - &tmp, sizeof(dt_iop_basecurve_params_t), 1); + dt_gui_presets_add_generic(_(presets[k].name), self->op, self->version(), &tmp, + sizeof(dt_iop_basecurve_params_t), 1); // and restrict it to model, maker, iso, and raw images - dt_gui_presets_update_mml(_(presets[k].name), self->op, self->version(), - presets[k].maker, presets[k].model, ""); - dt_gui_presets_update_iso(_(presets[k].name), self->op, self->version(), - presets[k].iso_min, presets[k].iso_max); + dt_gui_presets_update_mml(_(presets[k].name), self->op, self->version(), presets[k].maker, presets[k].model, + ""); + dt_gui_presets_update_iso(_(presets[k].name), self->op, self->version(), presets[k].iso_min, + presets[k].iso_max); dt_gui_presets_update_ldr(_(presets[k].name), self->op, self->version(), FOR_RAW); // make it auto-apply for matching images: dt_gui_presets_update_autoapply(_(presets[k].name), self->op, self->version(), @@ -355,10 +358,8 @@ static float exposure_increment(float stops, int e, float fusion, float bias) } #ifdef HAVE_OPENCL -static -int gauss_blur_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, - cl_mem dev_in, cl_mem dev_out, cl_mem dev_tmp, - const int width, const int height) +static int gauss_blur_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, + cl_mem dev_out, cl_mem dev_tmp, const int width, const int height) { dt_iop_basecurve_global_data_t *gd = (dt_iop_basecurve_global_data_t *)self->data; @@ -385,10 +386,8 @@ int gauss_blur_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, return TRUE; } -static -int gauss_expand_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, - cl_mem dev_in, cl_mem dev_out, cl_mem dev_tmp, - const int width, const int height) +static int gauss_expand_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, + cl_mem dev_out, cl_mem dev_tmp, const int width, const int height) { dt_iop_basecurve_global_data_t *gd = (dt_iop_basecurve_global_data_t *)self->data; @@ -407,11 +406,9 @@ int gauss_expand_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, } -static -int gauss_reduce_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, - cl_mem dev_in, cl_mem dev_coarse, cl_mem dev_detail, - cl_mem dev_tmp1, cl_mem dev_tmp2, - const int width, const int height) +static int gauss_reduce_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, + cl_mem dev_coarse, cl_mem dev_detail, cl_mem dev_tmp1, cl_mem dev_tmp2, const int width, + const int height) { dt_iop_basecurve_global_data_t *gd = (dt_iop_basecurve_global_data_t *)self->data; @@ -420,8 +417,7 @@ int gauss_reduce_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, do { - if(!gauss_blur_cl(self, piece, dev_in, dev_tmp1, dev_tmp2, width, height)) - return FALSE; + if(!gauss_blur_cl(self, piece, dev_in, dev_tmp1, dev_tmp2, width, height)) return FALSE; const int cw = (width - 1) / 2 + 1; const int ch = (height - 1) / 2 + 1; @@ -438,8 +434,7 @@ int gauss_reduce_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, if(dev_detail != NULL) { - if(!gauss_expand_cl(self, piece, dev_coarse, dev_tmp1, dev_tmp2, width, height)) - return FALSE; + if(!gauss_expand_cl(self, piece, dev_coarse, dev_tmp1, dev_tmp2, width, height)) return FALSE; size_t sizes[] = { ROUNDUPWD(width), ROUNDUPHT(height), 1 }; dt_opencl_set_kernel_arg(devid, gd->kernel_basecurve_detail, 0, sizeof(cl_mem), (void *)&dev_in); @@ -454,9 +449,8 @@ int gauss_reduce_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, return TRUE; } -static -int process_cl_fusion(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, cl_mem dev_out, - const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) +static int process_cl_fusion(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, + cl_mem dev_out, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) { dt_iop_basecurve_data_t *d = (dt_iop_basecurve_data_t *)piece->data; dt_iop_basecurve_global_data_t *gd = (dt_iop_basecurve_global_data_t *)self->data; @@ -489,7 +483,7 @@ int process_cl_fusion(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piec for(int k = 0, step = 1, w = width, h = height; k < num_levels; k++) { // coarsest step is some % of image width. - dev_col[k] = dt_opencl_alloc_device(devid, w, h, 4 * sizeof(float)); + dev_col[k] = dt_opencl_alloc_device(devid, w, h, 4 * sizeof(float)); if(dev_col[k] == NULL) goto error; dev_comb[k] = dt_opencl_alloc_device(devid, w, h, 4 * sizeof(float)); @@ -539,7 +533,8 @@ int process_cl_fusion(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piec if(err != CL_SUCCESS) goto error; dt_opencl_set_kernel_arg(devid, gd->kernel_basecurve_compute_features, 0, sizeof(cl_mem), (void *)&dev_tmp1); - dt_opencl_set_kernel_arg(devid, gd->kernel_basecurve_compute_features, 1, sizeof(cl_mem), (void *)&dev_col[0]); + dt_opencl_set_kernel_arg(devid, gd->kernel_basecurve_compute_features, 1, sizeof(cl_mem), + (void *)&dev_col[0]); dt_opencl_set_kernel_arg(devid, gd->kernel_basecurve_compute_features, 2, sizeof(int), (void *)&width); dt_opencl_set_kernel_arg(devid, gd->kernel_basecurve_compute_features, 3, sizeof(int), (void *)&height); err = dt_opencl_enqueue_kernel_2d(devid, gd->kernel_basecurve_compute_features, sizes); @@ -571,8 +566,7 @@ int process_cl_fusion(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piec for(int k = 1, w = width, h = height; k < num_levels; k++) { - if(!gauss_reduce_cl(self, piece, dev_col[k-1], dev_col[k], NULL, dev_tmp1, dev_tmp2, w, h)) - goto error; + if(!gauss_reduce_cl(self, piece, dev_col[k - 1], dev_col[k], NULL, dev_tmp1, dev_tmp2, w, h)) goto error; w = (w - 1) / 2 + 1; h = (h - 1) / 2 + 1; @@ -592,16 +586,17 @@ int process_cl_fusion(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piec // dev_col[k+1] -> dev_tmp2[k] if(k != num_levels - 1) - if(!gauss_expand_cl(self, piece, dev_col[k+1], dev_tmp2, dev_tmp1, w, h)) - goto error; + if(!gauss_expand_cl(self, piece, dev_col[k + 1], dev_tmp2, dev_tmp1, w, h)) goto error; // blend images into output pyramid if(k == num_levels - 1) { // blend gaussian base size_t sizes[] = { ROUNDUPWD(w), ROUNDUPHT(h), 1 }; - dt_opencl_set_kernel_arg(devid, gd->kernel_basecurve_blend_gaussian, 0, sizeof(cl_mem), (void *)&dev_comb[k]); - dt_opencl_set_kernel_arg(devid, gd->kernel_basecurve_blend_gaussian, 1, sizeof(cl_mem), (void *)&dev_col[k]); + dt_opencl_set_kernel_arg(devid, gd->kernel_basecurve_blend_gaussian, 0, sizeof(cl_mem), + (void *)&dev_comb[k]); + dt_opencl_set_kernel_arg(devid, gd->kernel_basecurve_blend_gaussian, 1, sizeof(cl_mem), + (void *)&dev_col[k]); dt_opencl_set_kernel_arg(devid, gd->kernel_basecurve_blend_gaussian, 2, sizeof(cl_mem), (void *)&dev_tmp1); dt_opencl_set_kernel_arg(devid, gd->kernel_basecurve_blend_gaussian, 3, sizeof(int), (void *)&w); dt_opencl_set_kernel_arg(devid, gd->kernel_basecurve_blend_gaussian, 4, sizeof(int), (void *)&h); @@ -617,8 +612,10 @@ int process_cl_fusion(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piec { // blend laplacian size_t sizes[] = { ROUNDUPWD(w), ROUNDUPHT(h), 1 }; - dt_opencl_set_kernel_arg(devid, gd->kernel_basecurve_blend_laplacian, 0, sizeof(cl_mem), (void *)&dev_comb[k]); - dt_opencl_set_kernel_arg(devid, gd->kernel_basecurve_blend_laplacian, 1, sizeof(cl_mem), (void *)&dev_col[k]); + dt_opencl_set_kernel_arg(devid, gd->kernel_basecurve_blend_laplacian, 0, sizeof(cl_mem), + (void *)&dev_comb[k]); + dt_opencl_set_kernel_arg(devid, gd->kernel_basecurve_blend_laplacian, 1, sizeof(cl_mem), + (void *)&dev_col[k]); dt_opencl_set_kernel_arg(devid, gd->kernel_basecurve_blend_laplacian, 2, sizeof(cl_mem), (void *)&dev_tmp2); dt_opencl_set_kernel_arg(devid, gd->kernel_basecurve_blend_laplacian, 3, sizeof(cl_mem), (void *)&dev_tmp1); dt_opencl_set_kernel_arg(devid, gd->kernel_basecurve_blend_laplacian, 4, sizeof(int), (void *)&w); @@ -670,8 +667,7 @@ int process_cl_fusion(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piec // reconstruct output image // dev_comb[k+1] -> dev_tmp1 - if(!gauss_expand_cl(self, piece, dev_comb[k+1], dev_tmp1, dev_tmp2, w, h)) - goto error; + if(!gauss_expand_cl(self, piece, dev_comb[k + 1], dev_tmp1, dev_tmp2, w, h)) goto error; // dev_comb[k] + dev_tmp1 -> dev_tmp2 size_t sizes[] = { ROUNDUPWD(w), ROUNDUPHT(h), 1 }; @@ -734,9 +730,8 @@ int process_cl_fusion(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piec return FALSE; } -static -int process_cl_lut(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, cl_mem dev_out, - const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) +static int process_cl_lut(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, + cl_mem dev_out, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) { dt_iop_basecurve_data_t *d = (dt_iop_basecurve_data_t *)piece->data; dt_iop_basecurve_global_data_t *gd = (dt_iop_basecurve_global_data_t *)self->data; @@ -787,8 +782,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m #endif void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling) + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling) { dt_iop_basecurve_data_t *d = (dt_iop_basecurve_data_t *)piece->data; @@ -796,7 +790,7 @@ void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t { const int rad = MIN(roi_in->width, ceilf(256 * roi_in->scale / piece->iscale)); - tiling->factor = 6.666f; // in + out + col[] + comb[] + 2*tmp + tiling->factor = 6.666f; // in + out + col[] + comb[] + 2*tmp tiling->maxbuf = 1.0f; tiling->overhead = 0; tiling->xalign = 1; @@ -805,7 +799,7 @@ void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t } else { - tiling->factor = 2.0f; // in + out + tiling->factor = 2.0f; // in + out tiling->maxbuf = 1.0f; tiling->overhead = 0; tiling->xalign = 1; @@ -816,14 +810,9 @@ void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t } -static inline void apply_ev_and_curve( - const float *const in, - float *const out, - const int width, - const int height, - const float mul, - const float *const table, - const float *const unbounded_coeffs) +static inline void apply_ev_and_curve(const float *const in, float *const out, const int width, const int height, + const float mul, const float *const table, + const float *const unbounded_coeffs) { #ifdef _OPENMP #pragma omp parallel for default(none) schedule(static) @@ -840,103 +829,101 @@ static inline void apply_ev_and_curve( outp[i] = table[CLAMP((int)(f * 0x10000ul), 0, 0xffff)]; else if(unbounded_coeffs) outp[i] = dt_iop_eval_exp(unbounded_coeffs, f); - else outp[i] = 1.0f; + else + outp[i] = 1.0f; } } } -static inline void compute_features( - float *const col, - const int wd, - const int ht) +static inline void compute_features(float *const col, const int wd, const int ht) { - // features are product of - // 1) well exposedness - // 2) saturation - // 3) local contrast (handled in laplacian form later) +// features are product of +// 1) well exposedness +// 2) saturation +// 3) local contrast (handled in laplacian form later) #ifdef _OPENMP #pragma omp parallel for default(none) schedule(static) collapse(2) #endif - for(int j=0;j<ht;j++) for(int i=0;i<wd;i++) - { - const size_t x = 4ul*(wd*j+i); - const float max = MAX(col[x], MAX(col[x+1], col[x+2])); - const float min = MIN(col[x], MIN(col[x+1], col[x+2])); - const float sat = .1f + .1f*(max-min)/MAX(1e-4, max); - col[x+3] = sat; - - const float c = 0.54f; - float v = fabsf(col[x]-c); - v = MAX(fabsf(col[x+1]-c), v); - v = MAX(fabsf(col[x+2]-c), v); - const float var = 0.5; - const float exp = .2f + dt_fast_expf(-v*v/(var*var)); - col[x+3] *= exp; - } + for(int j = 0; j < ht; j++) + for(int i = 0; i < wd; i++) + { + const size_t x = 4ul * (wd * j + i); + const float max = MAX(col[x], MAX(col[x + 1], col[x + 2])); + const float min = MIN(col[x], MIN(col[x + 1], col[x + 2])); + const float sat = .1f + .1f * (max - min) / MAX(1e-4, max); + col[x + 3] = sat; + + const float c = 0.54f; + float v = fabsf(col[x] - c); + v = MAX(fabsf(col[x + 1] - c), v); + v = MAX(fabsf(col[x + 2] - c), v); + const float var = 0.5; + const float exp = .2f + dt_fast_expf(-v * v / (var * var)); + col[x + 3] *= exp; + } } -static inline void gauss_blur( - const float *const input, - float *const output, - const size_t wd, - const size_t ht) +static inline void gauss_blur(const float *const input, float *const output, const size_t wd, const size_t ht) { - const float w[5] = {1./16., 4./16., 6./16., 4./16., 1./16.}; - float *tmp = dt_alloc_align(64, (size_t)wd*ht*4*sizeof(float)); - memset(tmp, 0, 4*wd*ht*sizeof(float)); + const float w[5] = { 1. / 16., 4. / 16., 6. / 16., 4. / 16., 1. / 16. }; + float *tmp = dt_alloc_align(64, (size_t)wd * ht * 4 * sizeof(float)); + memset(tmp, 0, 4 * wd * ht * sizeof(float)); #ifdef _OPENMP #pragma omp parallel for default(none) schedule(static) shared(tmp) #endif - for(int j=0;j<ht;j++) + for(int j = 0; j < ht; j++) { // horizontal pass // left borders - for(int i=0;i<2;i++) for(int c=0;c<4;c++) - for(int ii=-2;ii<=2;ii++) - tmp[4*(j*wd+i)+c] += input[4*(j*wd+MAX(-i-ii,i+ii))+c] * w[ii+2]; + for(int i = 0; i < 2; i++) + for(int c = 0; c < 4; c++) + for(int ii = -2; ii <= 2; ii++) + tmp[4 * (j * wd + i) + c] += input[4 * (j * wd + MAX(-i - ii, i + ii)) + c] * w[ii + 2]; // most pixels - for(int i=2;i<wd-2;i++) for(int c=0;c<4;c++) - for(int ii=-2;ii<=2;ii++) - tmp[4*(j*wd+i)+c] += input[4*(j*wd+i+ii)+c] * w[ii+2]; + for(int i = 2; i < wd - 2; i++) + for(int c = 0; c < 4; c++) + for(int ii = -2; ii <= 2; ii++) tmp[4 * (j * wd + i) + c] += input[4 * (j * wd + i + ii) + c] * w[ii + 2]; // right borders - for(int i=wd-2;i<wd;i++) for(int c=0;c<4;c++) - for(int ii=-2;ii<=2;ii++) - tmp[4*(j*wd+i)+c] += input[4*(j*wd+MIN(i+ii, wd-(i+ii-wd+1) ))+c] * w[ii+2]; + for(int i = wd - 2; i < wd; i++) + for(int c = 0; c < 4; c++) + for(int ii = -2; ii <= 2; ii++) + tmp[4 * (j * wd + i) + c] += input[4 * (j * wd + MIN(i + ii, wd - (i + ii - wd + 1))) + c] * w[ii + 2]; } - memset(output, 0, 4*wd*ht*sizeof(float)); + memset(output, 0, 4 * wd * ht * sizeof(float)); #ifdef _OPENMP #pragma omp parallel for default(none) schedule(static) shared(tmp) #endif - for(int i=0;i<wd;i++) + for(int i = 0; i < wd; i++) { // vertical pass - for(int j=0;j<2;j++) for(int c=0;c<4;c++) - for(int jj=-2;jj<=2;jj++) - output[4*(j*wd+i)+c] += tmp[4*(MAX(-j-jj,j+jj)*wd+i)+c] * w[jj+2]; - for(int j=2;j<ht-2;j++) for(int c=0;c<4;c++) - for(int jj=-2;jj<=2;jj++) - output[4*(j*wd+i)+c] += tmp[4*((j+jj)*wd+i)+c] * w[jj+2]; - for(int j=ht-2;j<ht;j++) for(int c=0;c<4;c++) - for(int jj=-2;jj<=2;jj++) - output[4*(j*wd+i)+c] += tmp[4*(MIN(j+jj, ht-(j+jj-ht+1))*wd+i)+c] * w[jj+2]; + for(int j = 0; j < 2; j++) + for(int c = 0; c < 4; c++) + for(int jj = -2; jj <= 2; jj++) + output[4 * (j * wd + i) + c] += tmp[4 * (MAX(-j - jj, j + jj) * wd + i) + c] * w[jj + 2]; + for(int j = 2; j < ht - 2; j++) + for(int c = 0; c < 4; c++) + for(int jj = -2; jj <= 2; jj++) + output[4 * (j * wd + i) + c] += tmp[4 * ((j + jj) * wd + i) + c] * w[jj + 2]; + for(int j = ht - 2; j < ht; j++) + for(int c = 0; c < 4; c++) + for(int jj = -2; jj <= 2; jj++) + output[4 * (j * wd + i) + c] += tmp[4 * (MIN(j + jj, ht - (j + jj - ht + 1)) * wd + i) + c] * w[jj + 2]; } dt_free_align(tmp); } -static inline void gauss_expand( - const float *const input, // coarse input - float *const fine, // upsampled, blurry output - const size_t wd, // fine res - const size_t ht) +static inline void gauss_expand(const float *const input, // coarse input + float *const fine, // upsampled, blurry output + const size_t wd, // fine res + const size_t ht) { - const size_t cw = (wd-1)/2+1; + const size_t cw = (wd - 1) / 2 + 1; // fill numbers in even pixels, zero odd ones - memset(fine, 0, 4*wd*ht*sizeof(float)); + memset(fine, 0, 4 * wd * ht * sizeof(float)); #ifdef _OPENMP #pragma omp parallel for default(none) schedule(static) collapse(2) #endif - for(int j=0;j<ht;j+=2) - for(int i=0;i<wd;i+=2) - for(int c=0;c<4;c++) - fine[4*(j*wd+i)+c] = 4.0f * input[4*(j/2*cw + i/2)+c]; + for(int j = 0; j < ht; j += 2) + for(int i = 0; i < wd; i += 2) + for(int c = 0; c < 4; c++) fine[4 * (j * wd + i) + c] = 4.0f * input[4 * (j / 2 * cw + i / 2) + c]; // convolve with same kernel weights mul by 4: gauss_blur(fine, fine, wd, ht); @@ -946,20 +933,19 @@ static inline void gauss_expand( // XXX FIXME: downsampling will not result in an energy conserving pattern (every 4 pixels one sample) // XXX FIXME: neither will a mirror boundary condition (mirrors in subsampled values at random density) // TODO: copy laplacian code from local laplacian filters, it's faster. -static inline void gauss_reduce( - const float *const input, // fine input buffer - float *const coarse, // coarse scale, blurred input buf - float *const detail, // detail/laplacian, fine scale, or 0 - const size_t wd, - const size_t ht) +static inline void gauss_reduce(const float *const input, // fine input buffer + float *const coarse, // coarse scale, blurred input buf + float *const detail, // detail/laplacian, fine scale, or 0 + const size_t wd, const size_t ht) { // blur, store only coarse res - const size_t cw = (wd-1)/2+1, ch = (ht-1)/2+1; + const size_t cw = (wd - 1) / 2 + 1, ch = (ht - 1) / 2 + 1; - float *blurred = dt_alloc_align(64, (size_t)wd*ht*4*sizeof(float)); + float *blurred = dt_alloc_align(64, (size_t)wd * ht * 4 * sizeof(float)); gauss_blur(input, blurred, wd, ht); - for(size_t j=0;j<ch;j++) for(size_t i=0;i<cw;i++) - for(int c=0;c<4;c++) coarse[4*(j*cw+i)+c] = blurred[4*(2*j*wd+2*i)+c]; + for(size_t j = 0; j < ch; j++) + for(size_t i = 0; i < cw; i++) + for(int c = 0; c < 4; c++) coarse[4 * (j * cw + i) + c] = blurred[4 * (2 * j * wd + 2 * i) + c]; dt_free_align(blurred); if(detail) @@ -967,15 +953,14 @@ static inline void gauss_reduce( // compute laplacian/details: expand coarse buffer into detail // buffer subtract expanded buffer from input in place gauss_expand(coarse, detail, wd, ht); - for(size_t k=0;k<wd*ht*4;k++) - detail[k] = input[k] - detail[k]; + for(size_t k = 0; k < wd * ht * 4; k++) detail[k] = input[k] - detail[k]; } } void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, - void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) + void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) { - const float *const in = (float *)ivoid; + const float *const in = (float *)ivoid; float *const out = (float *)ovoid; const int ch = piece->colors; dt_iop_basecurve_data_t *const d = (dt_iop_basecurve_data_t *)(piece->data); @@ -986,27 +971,28 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const // allocate temporary buffer for wavelet transform + blending const int wd = roi_in->width, ht = roi_in->height; int num_levels = 8; - float **col = malloc(num_levels * sizeof(float*)); - float **comb = malloc(num_levels * sizeof(float*)); + float **col = malloc(num_levels * sizeof(float *)); + float **comb = malloc(num_levels * sizeof(float *)); int w = wd, h = ht; const int rad = MIN(wd, ceilf(256 * roi_in->scale / piece->iscale)); int step = 1; - for(int k=0;k<num_levels;k++) + for(int k = 0; k < num_levels; k++) { // coarsest step is some % of image width. - col[k] = dt_alloc_align(64, sizeof(float)*4ul*w*h); - comb[k] = dt_alloc_align(64, sizeof(float)*4ul*w*h); - memset(comb[k], 0, sizeof(float)*4*w*h); - w = (w-1)/2+1; h = (h-1)/2+1; + col[k] = dt_alloc_align(64, sizeof(float) * 4ul * w * h); + comb[k] = dt_alloc_align(64, sizeof(float) * 4ul * w * h); + memset(comb[k], 0, sizeof(float) * 4 * w * h); + w = (w - 1) / 2 + 1; + h = (h - 1) / 2 + 1; step *= 2; if(step > rad || w < 4 || h < 4) { - num_levels = k+1; + num_levels = k + 1; break; } } - for(int e=0;e<d->exposure_fusion+1;e++) + for(int e = 0; e < d->exposure_fusion + 1; e++) { // for every exposure fusion image: // push by some ev, apply base curve: apply_ev_and_curve(in, col[0], wd, ht, @@ -1017,107 +1003,116 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const compute_features(col[0], wd, ht); // create gaussian pyramid of colour buffer - w = wd; h = ht; + w = wd; + h = ht; gauss_reduce(col[0], col[1], out, w, h); #ifdef _OPENMP #pragma omp parallel for default(none) shared(col) schedule(static) #endif - for(size_t k=0;k<4ul*wd*ht;k+=4) - col[0][k+3] *= .1f + sqrtf(out[k]*out[k] + out[k+1]*out[k+1] + out[k+2]*out[k+2]); + for(size_t k = 0; k < 4ul * wd * ht; k += 4) + col[0][k + 3] *= .1f + sqrtf(out[k] * out[k] + out[k + 1] * out[k + 1] + out[k + 2] * out[k + 2]); // #define DEBUG_VIS2 #ifdef DEBUG_VIS2 // transform weights in channels - for(size_t k=0;k<4ul*w*h;k+=4) - col[0][k+e] = col[0][k+3]; + for(size_t k = 0; k < 4ul * w * h; k += 4) col[0][k + e] = col[0][k + 3]; #endif // #define DEBUG_VIS #ifdef DEBUG_VIS // DEBUG visualise weight buffer - for(size_t k=0;k<4ul*w*h;k+=4) - comb[0][k+e] = col[0][k+3]; + for(size_t k = 0; k < 4ul * w * h; k += 4) comb[0][k + e] = col[0][k + 3]; continue; #endif - for(int k=1;k<num_levels;k++) + for(int k = 1; k < num_levels; k++) { - gauss_reduce(col[k-1], col[k], 0, w, h); - w = (w-1)/2+1; h = (h-1)/2+1; + gauss_reduce(col[k - 1], col[k], 0, w, h); + w = (w - 1) / 2 + 1; + h = (h - 1) / 2 + 1; } // update pyramid coarse to fine - for(int k=num_levels-1;k>=0;k--) + for(int k = num_levels - 1; k >= 0; k--) { - w = wd; h = ht; - for(int i=0;i<k;i++) { w = (w-1)/2+1; h = (h-1)/2+1; } + w = wd; + h = ht; + for(int i = 0; i < k; i++) + { + w = (w - 1) / 2 + 1; + h = (h - 1) / 2 + 1; + } // abuse output buffer as temporary memory: - if(k!=num_levels-1) - gauss_expand(col[k+1], out, w, h); + if(k != num_levels - 1) gauss_expand(col[k + 1], out, w, h); #ifdef _OPENMP -#pragma omp parallel for default(none) shared(col,comb,w,h,num_levels,k) schedule(static) +#pragma omp parallel for default(none) shared(col, comb, w, h, num_levels, k) schedule(static) #endif - for(int j=0;j<h;j++) for(int i=0;i<w;i++) - { - const size_t x = 4ul*(w*j+i); - // blend images into output pyramid - if(k == num_levels-1) // blend gaussian base + for(int j = 0; j < h; j++) + for(int i = 0; i < w; i++) + { + const size_t x = 4ul * (w * j + i); + // blend images into output pyramid + if(k == num_levels - 1) // blend gaussian base #ifdef DEBUG_VIS2 - ; + ; #else - for(int c=0;c<3;c++) - comb[k][x+c] += col[k][x+3] * col[k][x+c]; + for(int c = 0; c < 3; c++) comb[k][x + c] += col[k][x + 3] * col[k][x + c]; #endif - else // laplacian - for(int c=0;c<3;c++) comb[k][x+c] += - col[k][x+3] * (col[k][x+c] - out[x+c]); - comb[k][x+3] += col[k][x+3]; - } + else // laplacian + for(int c = 0; c < 3; c++) comb[k][x + c] += col[k][x + 3] * (col[k][x + c] - out[x + c]); + comb[k][x + 3] += col[k][x + 3]; + } } } #ifndef DEBUG_VIS // DEBUG: switch off when visualising weight buf // normalise and reconstruct output pyramid buffer coarse to fine - for(int k=num_levels-1;k>=0;k--) + for(int k = num_levels - 1; k >= 0; k--) { - w = wd; h = ht; - for(int i=0;i<k;i++) { w = (w-1)/2+1; h = (h-1)/2+1;} + w = wd; + h = ht; + for(int i = 0; i < k; i++) + { + w = (w - 1) / 2 + 1; + h = (h - 1) / 2 + 1; + } - // normalise both gaussian base and laplacians: +// normalise both gaussian base and laplacians: #ifdef _OPENMP -#pragma omp parallel for default(none) shared(comb,w,h,k) schedule(static) +#pragma omp parallel for default(none) shared(comb, w, h, k) schedule(static) #endif - for(size_t i=0;i<(size_t)4*w*h;i+=4) - if(comb[k][i+3] > 1e-8f) - for(int c=0;c<3;c++) comb[k][i+c] /= comb[k][i+3]; + for(size_t i = 0; i < (size_t)4 * w * h; i += 4) + if(comb[k][i + 3] > 1e-8f) + for(int c = 0; c < 3; c++) comb[k][i + c] /= comb[k][i + 3]; - if(k < num_levels-1) + if(k < num_levels - 1) { // reconstruct output image - gauss_expand(comb[k+1], out, w, h); + gauss_expand(comb[k + 1], out, w, h); #ifdef _OPENMP -#pragma omp parallel for default(none) shared(comb,w,h,k) schedule(static) +#pragma omp parallel for default(none) shared(comb, w, h, k) schedule(static) #endif - for(int j=0;j<h;j++) for(int i=0;i<w;i++) - { - const size_t x = 4ul*(w*j+i); - for(int c=0;c<3;c++) comb[k][x+c] += out[x+c]; - } + for(int j = 0; j < h; j++) + for(int i = 0; i < w; i++) + { + const size_t x = 4ul * (w * j + i); + for(int c = 0; c < 3; c++) comb[k][x + c] += out[x + c]; + } } } #endif - // copy output buffer +// copy output buffer #ifdef _OPENMP #pragma omp parallel for default(none) shared(comb) schedule(static) #endif - for(size_t k=0;k<4ul*wd*ht;k+=4) + for(size_t k = 0; k < 4ul * wd * ht; k += 4) { - out[k+0] = comb[0][k+0]; - out[k+1] = comb[0][k+1]; - out[k+2] = comb[0][k+2]; - out[k+3] = in[k+3]; // pass on 4th channel + out[k + 0] = comb[0][k + 0]; + out[k + 1] = comb[0][k + 1]; + out[k + 2] = comb[0][k + 2]; + out[k + 3] = in[k + 3]; // pass on 4th channel } // free temp buffers - for(int k=0;k<num_levels;k++) + for(int k = 0; k < num_levels; k++) { dt_free_align(col[k]); dt_free_align(comb[k]); @@ -1127,7 +1122,7 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const return; } - // fast path for non-fusion +// fast path for non-fusion #ifdef _OPENMP #pragma omp parallel for default(none) schedule(static) #endif @@ -1184,10 +1179,10 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix // now the extrapolation stuff: const float xm = p->basecurve[0][p->basecurve_nodes[0] - 1].x; const float x[4] = { 0.7f * xm, 0.8f * xm, 0.9f * xm, 1.0f * xm }; - const float y[4] = { d->table[CLAMP((int)(x[0] * 0x10000ul), 0, 0xffff)], - d->table[CLAMP((int)(x[1] * 0x10000ul), 0, 0xffff)], - d->table[CLAMP((int)(x[2] * 0x10000ul), 0, 0xffff)], - d->table[CLAMP((int)(x[3] * 0x10000ul), 0, 0xffff)] }; + const float y[4] + = { d->table[CLAMP((int)(x[0] * 0x10000ul), 0, 0xffff)], d->table[CLAMP((int)(x[1] * 0x10000ul), 0, 0xffff)], + d->table[CLAMP((int)(x[2] * 0x10000ul), 0, 0xffff)], + d->table[CLAMP((int)(x[3] * 0x10000ul), 0, 0xffff)] }; dt_iop_estimate_exp(x, y, 4, d->unbounded_coeffs); } @@ -1233,19 +1228,20 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_basecurve_params_t)); module->default_params = calloc(1, sizeof(dt_iop_basecurve_params_t)); module->default_enabled = 0; - module->priority = 294; // module order created by iop_dependencies.py, do not edit! + module->priority = 304; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_basecurve_params_t); module->gui_data = NULL; dt_iop_basecurve_params_t tmp = (dt_iop_basecurve_params_t){ { - { // three curves (L, a, b) with a number of nodes - { 0.0, 0.0 }, - { 1.0, 1.0 } - }, + { // three curves (L, a, b) with a number of nodes + { 0.0, 0.0 }, + { 1.0, 1.0 } }, }, { 2, 0, 0 }, // number of nodes per curve { MONOTONE_HERMITE, MONOTONE_HERMITE, MONOTONE_HERMITE }, - 0, 1.0f, 1.0f // no exposure fusion, but if we would, add one stop + 0, + 1.0f, + 1.0f // no exposure fusion, but if we would, add one stop }; memcpy(module->params, &tmp, sizeof(dt_iop_basecurve_params_t)); memcpy(module->default_params, &tmp, sizeof(dt_iop_basecurve_params_t)); @@ -1420,7 +1416,7 @@ static gboolean dt_iop_basecurve_draw(GtkWidget *widget, cairo_t *crf, gpointer snprintf(text, sizeof(text), "100.00 / 100.00 ( +100.00)"); pango_layout_set_text(layout, text, -1); pango_layout_get_pixel_extents(layout, &ink, NULL); - pango_font_description_set_absolute_size(desc, width*1.0/ink.width * PANGO_SCALE); + pango_font_description_set_absolute_size(desc, width * 1.0 / ink.width * PANGO_SCALE); pango_layout_set_font_description(layout, desc); snprintf(text, sizeof(text), "%.2f / %.2f ( %+.2f)", x_node_value, y_node_value, d_node_value); @@ -1609,9 +1605,8 @@ static gboolean dt_iop_basecurve_motion_notify(GtkWidget *widget, GdkEventMotion int nearest = -1; for(int k = 0; k < nodes; k++) { - float dist - = (my - to_log(basecurve[k].y, c->loglogscale)) * (my - to_log(basecurve[k].y, c->loglogscale)) - + (mx - to_log(basecurve[k].x, c->loglogscale)) * (mx - to_log(basecurve[k].x, c->loglogscale)); + float dist = (my - to_log(basecurve[k].y, c->loglogscale)) * (my - to_log(basecurve[k].y, c->loglogscale)) + + (mx - to_log(basecurve[k].x, c->loglogscale)) * (mx - to_log(basecurve[k].x, c->loglogscale)); if(dist < min) { min = dist; @@ -1638,8 +1633,8 @@ static gboolean dt_iop_basecurve_button_press(GtkWidget *widget, GdkEventButton if(event->button == 1) { - if(event->type == GDK_BUTTON_PRESS && (event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK - && nodes < MAXNODES && c->selected == -1) + if(event->type == GDK_BUTTON_PRESS && (event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK && nodes < MAXNODES + && c->selected == -1) { // if we are not on a node -> add a new node at the current x of the pointer and y of the curve at that x const int inset = DT_GUI_CURVE_EDITOR_INSET; @@ -1670,8 +1665,8 @@ static gboolean dt_iop_basecurve_button_press(GtkWidget *widget, GdkEventButton if(selected == -1) selected = nodes; // > 0 -> check distance to left neighbour // < nodes -> check distance to right neighbour - if(!((selected > 0 && linx - basecurve[selected - 1].x <= 0.025) || - (selected < nodes && basecurve[selected].x - linx <= 0.025))) + if(!((selected > 0 && linx - basecurve[selected - 1].x <= 0.025) + || (selected < nodes && basecurve[selected].x - linx <= 0.025))) { // evaluate the curve at the current x position const float y = dt_draw_curve_calc_value(c->minmax_curve, linx); @@ -1949,8 +1944,8 @@ void gui_init(struct dt_iop_module_t *self) gtk_widget_add_events(GTK_WIDGET(c->area), GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK - | GDK_SMOOTH_SCROLL_MASK | GDK_KEY_PRESS_MASK); + | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK + | GDK_KEY_PRESS_MASK); gtk_widget_set_can_focus(GTK_WIDGET(c->area), TRUE); g_signal_connect(G_OBJECT(c->area), "draw", G_CALLBACK(dt_iop_basecurve_draw), self); g_signal_connect(G_OBJECT(c->area), "button-press-event", G_CALLBACK(dt_iop_basecurve_button_press), self); diff --git a/src/iop/bilat.c b/src/iop/bilat.c index 748509ec79dc..9d4dd38b1045 100644 --- a/src/iop/bilat.c +++ b/src/iop/bilat.c @@ -41,8 +41,7 @@ typedef enum dt_iop_bilat_mode_t { s_mode_bilateral = 0, s_mode_local_laplacian = 1, -} -dt_iop_bilat_mode_t; +} dt_iop_bilat_mode_t; typedef struct dt_iop_bilat_params_t { @@ -51,8 +50,7 @@ typedef struct dt_iop_bilat_params_t float sigma_s; float detail; float midtone; -} -dt_iop_bilat_params_t; +} dt_iop_bilat_params_t; typedef struct dt_iop_bilat_params_v2_t { @@ -60,16 +58,14 @@ typedef struct dt_iop_bilat_params_v2_t float sigma_r; float sigma_s; float detail; -} -dt_iop_bilat_params_v2_t; +} dt_iop_bilat_params_v2_t; typedef struct dt_iop_bilat_params_v1_t { float sigma_r; float sigma_s; float detail; -} -dt_iop_bilat_params_v1_t; +} dt_iop_bilat_params_v1_t; typedef dt_iop_bilat_params_t dt_iop_bilat_data_t; @@ -86,8 +82,7 @@ typedef struct dt_iop_bilat_gui_data_t local_laplacian_boundary_t ll_boundary; uint64_t hash; dt_pthread_mutex_t lock; -} -dt_iop_bilat_gui_data_t; +} dt_iop_bilat_gui_data_t; // this returns a translatable name const char *name() @@ -107,30 +102,29 @@ int groups() return IOP_GROUP_TONE; } -int legacy_params( - dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 2 && new_version == 3) { const dt_iop_bilat_params_v2_t *p2 = old_params; dt_iop_bilat_params_t *p = new_params; - p->detail = p2->detail; + p->detail = p2->detail; p->sigma_r = p2->sigma_r; p->sigma_s = p2->sigma_s; p->midtone = 0.2f; - p->mode = p2->mode; + p->mode = p2->mode; return 0; } else if(old_version == 1 && new_version == 3) { const dt_iop_bilat_params_v1_t *p1 = old_params; dt_iop_bilat_params_t *p = new_params; - p->detail = p1->detail; + p->detail = p1->detail; p->sigma_r = p1->sigma_r; p->sigma_s = p1->sigma_s; p->midtone = 0.2f; - p->mode = s_mode_bilateral; + p->mode = s_mode_bilateral; return 0; } return 1; @@ -152,7 +146,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m cl_int err = -666; dt_bilateral_cl_t *b - = dt_bilateral_init_cl(piece->pipe->devid, roi_in->width, roi_in->height, sigma_s, sigma_r); + = dt_bilateral_init_cl(piece->pipe->devid, roi_in->width, roi_in->height, sigma_s, sigma_r); if(!b) goto error; err = dt_bilateral_splat_cl(b, dev_in); if(err != CL_SUCCESS) goto error; @@ -162,7 +156,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m if(err != CL_SUCCESS) goto error; dt_bilateral_free_cl(b); return TRUE; -error: + error: dt_bilateral_free_cl(b); dt_print(DT_DEBUG_OPENCL, "[opencl_bilateral] couldn't enqueue kernel! %d\n", err); return FALSE; @@ -170,12 +164,12 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m else // mode == s_mode_local_laplacian { dt_local_laplacian_cl_t *b = dt_local_laplacian_init_cl(piece->pipe->devid, roi_in->width, roi_in->height, - d->midtone, d->sigma_s, d->sigma_r, d->detail); + d->midtone, d->sigma_s, d->sigma_r, d->detail); if(!b) goto error_ll; if(dt_local_laplacian_cl(b, dev_in, dev_out) != CL_SUCCESS) goto error_ll; dt_local_laplacian_free_cl(b); return TRUE; -error_ll: + error_ll: dt_local_laplacian_free_cl(b); return FALSE; } @@ -184,8 +178,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling) + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling) { dt_iop_bilat_data_t *d = (dt_iop_bilat_data_t *)piece->data; // the total scale is composed of scale before input to the pipeline (iscale), @@ -211,7 +204,7 @@ void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t tiling->xalign = 1; tiling->yalign = 1; } - else // mode == s_mode_local_laplacian + else // mode == s_mode_local_laplacian { const int width = roi_in->width; const int height = roi_in->height; @@ -221,8 +214,7 @@ void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t const int rad = MIN(roi_in->width, ceilf(256 * roi_in->scale / piece->iscale)); tiling->factor = 2.0f + (float)local_laplacian_memory_use(width, height) / basebuffer; - tiling->maxbuf - = fmax(1.0f, (float)local_laplacian_singlebuffer_size(width, height) / basebuffer); + tiling->maxbuf = fmax(1.0f, (float)local_laplacian_singlebuffer_size(width, height) / basebuffer); tiling->overhead = 0; tiling->overlap = rad; tiling->xalign = 1; @@ -241,8 +233,7 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix if(d->mode == s_mode_bilateral) piece->process_cl_ready = (piece->process_cl_ready && !(darktable.opencl->avoid_atomics)); #endif - if(d->mode == s_mode_local_laplacian) - piece->process_tiling_ready = 0; // can't deal with tiles, sorry. + if(d->mode == s_mode_local_laplacian) piece->process_tiling_ready = 0; // can't deal with tiles, sorry. } @@ -262,7 +253,7 @@ void cleanup_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev #if defined(__SSE2__) void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const i, void *const o, - const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) + const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) { // this is called for preview and full pipe separately, each with its own pixelpipe piece. // get our data struct: @@ -284,7 +275,7 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c } else // s_mode_local_laplacian { - local_laplacian_boundary_t b = {0}; + local_laplacian_boundary_t b = { 0 }; if(self->dev->gui_attached && g && piece->pipe->type == DT_DEV_PIXELPIPE_PREVIEW) { b.mode = 1; @@ -293,8 +284,8 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c { // full pipeline working on ROI needs boundary conditions from preview pipe // only do this if roi covers less than 90% of full width - if(MIN(roi_in->width/roi_in->scale / piece->buf_in.width, - roi_in->height/roi_in->scale / piece->buf_in.height) < 0.9) + if(MIN(roi_in->width / roi_in->scale / piece->buf_in.width, + roi_in->height / roi_in->scale / piece->buf_in.height) < 0.9) { dt_pthread_mutex_lock(&g->lock); const uint64_t hash = g->hash; @@ -327,7 +318,8 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c } } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(i, o, roi_in->width, roi_in->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(i, o, roi_in->width, roi_in->height); } #endif @@ -356,7 +348,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const local_laplacian(i, o, roi_in->width, roi_in->height, d->midtone, d->sigma_s, d->sigma_r, d->detail, 0); } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(i, o, roi_in->width, roi_in->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(i, o, roi_in->width, roi_in->height); } /** init, cleanup, commit to pipeline */ @@ -368,7 +361,7 @@ void init(dt_iop_module_t *module) // by default: module->default_enabled = 0; // order has to be changed by editing the dependencies in tools/iop_dependencies.py - module->priority = 588; // module order created by iop_dependencies.py, do not edit! + module->priority = 594; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_bilat_params_t); module->gui_data = NULL; // init defaults: @@ -401,14 +394,14 @@ static void range_callback(GtkWidget *w, dt_iop_module_t *self) static void highlights_callback(GtkWidget *w, dt_iop_module_t *self) { dt_iop_bilat_params_t *p = (dt_iop_bilat_params_t *)self->params; - p->sigma_r = dt_bauhaus_slider_get(w)/100.0f; + p->sigma_r = dt_bauhaus_slider_get(w) / 100.0f; dt_dev_add_history_item(darktable.develop, self, TRUE); } static void shadows_callback(GtkWidget *w, dt_iop_module_t *self) { dt_iop_bilat_params_t *p = (dt_iop_bilat_params_t *)self->params; - p->sigma_s = dt_bauhaus_slider_get(w)/100.0f; + p->sigma_s = dt_bauhaus_slider_get(w) / 100.0f; dt_dev_add_history_item(darktable.develop, self, TRUE); } @@ -422,7 +415,7 @@ static void midtone_callback(GtkWidget *w, dt_iop_module_t *self) static void detail_callback(GtkWidget *w, dt_iop_module_t *self) { dt_iop_bilat_params_t *p = (dt_iop_bilat_params_t *)self->params; - p->detail = (dt_bauhaus_slider_get(w)-100.0f)/100.0f; + p->detail = (dt_bauhaus_slider_get(w) - 100.0f) / 100.0f; dt_dev_add_history_item(darktable.develop, self, TRUE); } @@ -460,12 +453,12 @@ void gui_update(dt_iop_module_t *self) // let gui slider match current parameters: dt_iop_bilat_gui_data_t *g = (dt_iop_bilat_gui_data_t *)self->gui_data; dt_iop_bilat_params_t *p = (dt_iop_bilat_params_t *)self->params; - dt_bauhaus_slider_set(g->detail, 100.0f*p->detail+100.0f); + dt_bauhaus_slider_set(g->detail, 100.0f * p->detail + 100.0f); dt_bauhaus_combobox_set(g->mode, p->mode); if(p->mode == s_mode_local_laplacian) { - dt_bauhaus_slider_set(g->shadows, p->sigma_s*100.0f); - dt_bauhaus_slider_set(g->highlights, p->sigma_r*100.0f); + dt_bauhaus_slider_set(g->shadows, p->sigma_s * 100.0f); + dt_bauhaus_slider_set(g->highlights, p->sigma_r * 100.0f); dt_bauhaus_slider_set(g->midtone, p->midtone); gtk_widget_set_visible(g->range, FALSE); gtk_widget_set_visible(g->spatial, FALSE); @@ -505,7 +498,8 @@ void gui_init(dt_iop_module_t *self) dt_bauhaus_combobox_add(g->mode, _("local laplacian filter")); dt_bauhaus_combobox_set_default(g->mode, s_mode_local_laplacian); dt_bauhaus_combobox_set(g->mode, s_mode_local_laplacian); - gtk_widget_set_tooltip_text(g->mode, _("the filter used for local contrast enhancement. bilateral is faster but can lead to artifacts around edges for extreme settings.")); + gtk_widget_set_tooltip_text(g->mode, _("the filter used for local contrast enhancement. bilateral is faster but " + "can lead to artifacts around edges for extreme settings.")); g->detail = dt_bauhaus_slider_new_with_range(self, 0.0, 500.0, 1.0, 100.0, 0); gtk_box_pack_start(GTK_BOX(self->widget), g->detail, TRUE, TRUE, 0); @@ -538,7 +532,9 @@ void gui_init(dt_iop_module_t *self) g->midtone = dt_bauhaus_slider_new_with_range(self, 0.001, 1.0, 0.001, 0.2, 3); gtk_box_pack_start(GTK_BOX(self->widget), g->midtone, TRUE, TRUE, 0); dt_bauhaus_widget_set_label(g->midtone, NULL, _("midtone range")); - gtk_widget_set_tooltip_text(g->midtone, _("defines what counts as midtones. lower for better dynamic range compression (reduce shadow and highlight contrast), increase for more powerful local contrast")); + gtk_widget_set_tooltip_text( + g->midtone, _("defines what counts as midtones. lower for better dynamic range compression (reduce shadow " + "and highlight contrast), increase for more powerful local contrast")); // work around multi-instance issue which calls show all a fair bit: g_object_set(G_OBJECT(g->highlights), "no-show-all", TRUE, NULL); diff --git a/src/iop/bilateral.cc b/src/iop/bilateral.cc index 15bf7e2280ae..b4061b4409bf 100644 --- a/src/iop/bilateral.cc +++ b/src/iop/bilateral.cc @@ -159,10 +159,9 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const for(int k = -rad; k <= rad; k++) { float *inp = in + ch * (l * roi_in->width + k); - sumw += w[l * wd + k] = m[l * wd + k] - * expf(-((in[0] - inp[0]) * (in[0] - inp[0]) * isig2col[0] - + (in[1] - inp[1]) * (in[1] - inp[1]) * isig2col[1] - + (in[2] - inp[2]) * (in[2] - inp[2]) * isig2col[2])); + sumw += w[l * wd + k] = m[l * wd + k] * expf(-((in[0] - inp[0]) * (in[0] - inp[0]) * isig2col[0] + + (in[1] - inp[1]) * (in[1] - inp[1]) * isig2col[1] + + (in[2] - inp[2]) * (in[2] - inp[2]) * isig2col[2])); } for(int l = -rad; l <= rad; l++) for(int k = -rad; k <= rad; k++) w[l * wd + k] /= sumw; @@ -183,11 +182,11 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const // fill unprocessed border for(int j = 0; j < rad; j++) - memcpy(((float *)ovoid) + (size_t)ch * j * roi_out->width, - ((float *)ivoid) + (size_t)ch * j * roi_in->width, (size_t)ch * sizeof(float) * roi_out->width); + memcpy(((float *)ovoid) + (size_t)ch * j * roi_out->width, ((float *)ivoid) + (size_t)ch * j * roi_in->width, + (size_t)ch * sizeof(float) * roi_out->width); for(int j = roi_out->height - rad; j < roi_out->height; j++) - memcpy(((float *)ovoid) + (size_t)ch * j * roi_out->width, - ((float *)ivoid) + (size_t)ch * j * roi_in->width, (size_t)ch * sizeof(float) * roi_out->width); + memcpy(((float *)ovoid) + (size_t)ch * j * roi_out->width, ((float *)ivoid) + (size_t)ch * j * roi_in->width, + (size_t)ch * sizeof(float) * roi_out->width); for(int j = rad; j < roi_out->height - rad; j++) { in = ((float *)ivoid) + (size_t)ch * roi_out->width * j; @@ -301,8 +300,7 @@ void gui_update(struct dt_iop_module_t *self) } void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling) + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling) { dt_iop_bilateral_data_t *data = (dt_iop_bilateral_data_t *)piece->data; float sigma[5]; @@ -323,7 +321,7 @@ void init(dt_iop_module_t *module) module->params = (dt_iop_params_t *)malloc(sizeof(dt_iop_bilateral_params_t)); module->default_params = (dt_iop_params_t *)malloc(sizeof(dt_iop_bilateral_params_t)); module->default_enabled = 0; - module->priority = 308; // module order created by iop_dependencies.py, do not edit! + module->priority = 318; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_bilateral_params_t); module->gui_data = NULL; dt_iop_bilateral_params_t tmp = (dt_iop_bilateral_params_t){ { 15.0, 15.0, 0.005, 0.005, 0.005 } }; diff --git a/src/iop/bloom.c b/src/iop/bloom.c index 93aef6e929fe..5a2032000325 100644 --- a/src/iop/bloom.c +++ b/src/iop/bloom.c @@ -225,7 +225,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const outp[2] = inp[2]; } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); free(blurlightness); } @@ -265,10 +266,14 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m const float scale = 1.0f / exp2f(-1.0f * (fmin(100.0f, d->strength + 1.0f) / 100.0f)); int hblocksize; - dt_opencl_local_buffer_t hlocopt - = (dt_opencl_local_buffer_t){ .xoffset = 2 * radius, .xfactor = 1, .yoffset = 0, .yfactor = 1, - .cellsize = sizeof(float), .overhead = 0, - .sizex = 1 << 16, .sizey = 1 }; + dt_opencl_local_buffer_t hlocopt = (dt_opencl_local_buffer_t){.xoffset = 2 * radius, + .xfactor = 1, + .yoffset = 0, + .yfactor = 1, + .cellsize = sizeof(float), + .overhead = 0, + .sizex = 1 << 16, + .sizey = 1 }; if(dt_opencl_local_buffer_opt(devid, gd->kernel_bloom_hblur, &hlocopt)) hblocksize = hlocopt.sizex; @@ -276,10 +281,14 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m hblocksize = 1; int vblocksize; - dt_opencl_local_buffer_t vlocopt - = (dt_opencl_local_buffer_t){ .xoffset = 1, .xfactor = 1, .yoffset = 2 * radius, .yfactor = 1, - .cellsize = sizeof(float), .overhead = 0, - .sizex = 1, .sizey = 1 << 16 }; + dt_opencl_local_buffer_t vlocopt = (dt_opencl_local_buffer_t){.xoffset = 1, + .xfactor = 1, + .yoffset = 2 * radius, + .yfactor = 1, + .cellsize = sizeof(float), + .overhead = 0, + .sizex = 1, + .sizey = 1 << 16 }; if(dt_opencl_local_buffer_opt(devid, gd->kernel_bloom_vblur, &vlocopt)) vblocksize = vlocopt.sizey; @@ -330,8 +339,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m dt_opencl_set_kernel_arg(devid, gd->kernel_bloom_hblur, 3, sizeof(int), (void *)&width); dt_opencl_set_kernel_arg(devid, gd->kernel_bloom_hblur, 4, sizeof(int), (void *)&height); dt_opencl_set_kernel_arg(devid, gd->kernel_bloom_hblur, 5, sizeof(int), (void *)&hblocksize); - dt_opencl_set_kernel_arg(devid, gd->kernel_bloom_hblur, 6, (hblocksize + 2 * radius) * sizeof(float), - NULL); + dt_opencl_set_kernel_arg(devid, gd->kernel_bloom_hblur, 6, (hblocksize + 2 * radius) * sizeof(float), NULL); err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_bloom_hblur, sizes, local); if(err != CL_SUCCESS) goto error; @@ -350,8 +358,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m dt_opencl_set_kernel_arg(devid, gd->kernel_bloom_vblur, 3, sizeof(int), (void *)&width); dt_opencl_set_kernel_arg(devid, gd->kernel_bloom_vblur, 4, sizeof(int), (void *)&height); dt_opencl_set_kernel_arg(devid, gd->kernel_bloom_vblur, 5, sizeof(int), (void *)&vblocksize); - dt_opencl_set_kernel_arg(devid, gd->kernel_bloom_vblur, 6, (vblocksize + 2 * radius) * sizeof(float), - NULL); + dt_opencl_set_kernel_arg(devid, gd->kernel_bloom_vblur, 6, (vblocksize + 2 * radius) * sizeof(float), NULL); err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_bloom_vblur, sizes, local); if(err != CL_SUCCESS) goto error; } @@ -368,21 +375,18 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m err = dt_opencl_enqueue_kernel_2d(devid, gd->kernel_bloom_mix, sizes); if(err != CL_SUCCESS) goto error; - for(int i = 0; i < NUM_BUCKETS; i++) - dt_opencl_release_mem_object(dev_tmp[i]); + for(int i = 0; i < NUM_BUCKETS; i++) dt_opencl_release_mem_object(dev_tmp[i]); return TRUE; error: - for(int i = 0; i < NUM_BUCKETS; i++) - dt_opencl_release_mem_object(dev_tmp[i]); + for(int i = 0; i < NUM_BUCKETS; i++) dt_opencl_release_mem_object(dev_tmp[i]); dt_print(DT_DEBUG_OPENCL, "[opencl_bloom] couldn't enqueue kernel! %d\n", err); return FALSE; } #endif void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling) + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling) { const dt_iop_bloom_data_t *d = (dt_iop_bloom_data_t *)piece->data; @@ -486,7 +490,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_bloom_params_t)); module->default_params = calloc(1, sizeof(dt_iop_bloom_params_t)); module->default_enabled = 0; - module->priority = 514; // module order created by iop_dependencies.py, do not edit! + module->priority = 521; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_bloom_params_t); module->gui_data = NULL; dt_iop_bloom_params_t tmp = (dt_iop_bloom_params_t){ 20, 90, 25 }; diff --git a/src/iop/borders.c b/src/iop/borders.c index 2a82210a045b..856528c745df 100644 --- a/src/iop/borders.c +++ b/src/iop/borders.c @@ -92,8 +92,8 @@ typedef struct dt_iop_borders_gui_data_t GtkWidget *active_colorpick; } dt_iop_borders_gui_data_t; -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 1 && new_version == 3) { @@ -210,8 +210,7 @@ int distort_transform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, floa return 1; } -int distort_backtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, float *points, - size_t points_count) +int distort_backtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, float *points, size_t points_count) { dt_iop_borders_data_t *d = (dt_iop_borders_data_t *)piece->data; @@ -288,8 +287,8 @@ void modify_roi_out(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t } // 2nd pass: which roi would this operation need as input to fill the given output region? -void modify_roi_in(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_out, dt_iop_roi_t *roi_in) +void modify_roi_in(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const dt_iop_roi_t *roi_out, + dt_iop_roi_t *roi_in) { dt_iop_borders_data_t *d = (dt_iop_borders_data_t *)piece->data; *roi_in = *roi_out; @@ -304,8 +303,7 @@ void modify_roi_in(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t * roi_in->height -= MAX(bh * d->pos_v - roi_out->y, 0); // subtract lower right border from dimensions - roi_in->width -= roi_out->scale - * MAX((roi_in->x + roi_in->width) / roi_out->scale - (piece->buf_in.width), 0); + roi_in->width -= roi_out->scale * MAX((roi_in->x + roi_in->width) / roi_out->scale - (piece->buf_in.width), 0); roi_in->height -= roi_out->scale * MAX((roi_in->y + roi_in->height) / roi_out->scale - (piece->buf_in.height), 0); // don't request nothing or outside roi @@ -372,8 +370,7 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const for(int r = frame_tl_out_y; r <= frame_br_out_y; r++) { buf = (float *)ovoid + ((size_t)r * out_stride + frame_tl_out_x * ch); - for(int c = frame_tl_out_x; c <= frame_br_out_x; c++, buf += 4) - memcpy(buf, col_frame, sizeof(float) * 4); + for(int c = frame_tl_out_x; c <= frame_br_out_x; c++, buf += 4) memcpy(buf, col_frame, sizeof(float) * 4); } for(int r = frame_tl_in_y; r <= frame_br_in_y; r++) { @@ -500,8 +497,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m void init_global(dt_iop_module_so_t *module) { const int program = 2; // basic.cl from programs.conf - dt_iop_borders_global_data_t *gd - = (dt_iop_borders_global_data_t *)malloc(sizeof(dt_iop_borders_global_data_t)); + dt_iop_borders_global_data_t *gd = (dt_iop_borders_global_data_t *)malloc(sizeof(dt_iop_borders_global_data_t)); module->data = gd; gd->kernel_borders_fill = dt_opencl_create_kernel(program, "borders_fill"); } @@ -538,19 +534,9 @@ void cleanup_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev void init_presets(dt_iop_module_so_t *self) { - dt_iop_borders_params_t p = (dt_iop_borders_params_t){ { 1.0f, 1.0f, 1.0f }, - 3.0f / 2.0f, - "3:2", - 0, - 0.1f, - 0.5f, - "1/2", - 0.5f, - "1/2", - 0.0f, - 0.5f, - { 0.0f, 0.0f, 0.0f }, - TRUE }; + dt_iop_borders_params_t p = (dt_iop_borders_params_t){ + { 1.0f, 1.0f, 1.0f }, 3.0f / 2.0f, "3:2", 0, 0.1f, 0.5f, "1/2", 0.5f, "1/2", 0.0f, 0.5f, { 0.0f, 0.0f, 0.0f }, TRUE + }; dt_gui_presets_add_generic(_("15:10 postcard white"), self->op, self->version(), &p, sizeof(p), 1); p.color[0] = p.color[1] = p.color[2] = 0.0f; p.frame_color[0] = p.frame_color[1] = p.frame_color[2] = 1.0f; @@ -602,8 +588,7 @@ static gboolean borders_draw(GtkWidget *widget, cairo_t *cr, dt_iop_module_t *se // interrupt if no valid color reading if(self->picked_color_min[0] == INFINITY) return FALSE; - if(fabsf(p->color[0] - self->picked_color[0]) < 0.0001f - && fabsf(p->color[1] - self->picked_color[1]) < 0.0001f + if(fabsf(p->color[0] - self->picked_color[0]) < 0.0001f && fabsf(p->color[1] - self->picked_color[1]) < 0.0001f && fabsf(p->color[2] - self->picked_color[2]) < 0.0001f) { // interrupt infinite loops @@ -618,10 +603,9 @@ static gboolean borders_draw(GtkWidget *widget, cairo_t *cr, dt_iop_module_t *se return FALSE; } - GdkRGBA c = (GdkRGBA){.red = self->picked_color[0], - .green = self->picked_color[1], - .blue = self->picked_color[2], - .alpha = 1.0 }; + GdkRGBA c = (GdkRGBA){ + .red = self->picked_color[0], .green = self->picked_color[1], .blue = self->picked_color[2], .alpha = 1.0 + }; if(g->active_colorpick == g->frame_colorpick) { p->frame_color[0] = self->picked_color[0]; @@ -881,9 +865,8 @@ void gui_update(struct dt_iop_module_t *self) gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(g->colorpick), &c); // ----- Frame Color - GdkRGBA fc = (GdkRGBA){ - .red = p->frame_color[0], .green = p->frame_color[1], .blue = p->frame_color[2], .alpha = 1.0 - }; + GdkRGBA fc + = (GdkRGBA){.red = p->frame_color[0], .green = p->frame_color[1], .blue = p->frame_color[2], .alpha = 1.0 }; gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(g->frame_colorpick), &fc); } @@ -895,7 +878,7 @@ void init(dt_iop_module_t *module) module->default_enabled = 0; module->params_size = sizeof(dt_iop_borders_params_t); module->gui_data = NULL; - module->priority = 955; // module order created by iop_dependencies.py, do not edit! + module->priority = 956; // module order created by iop_dependencies.py, do not edit! } void cleanup(dt_iop_module_t *module) diff --git a/src/iop/cacorrect.c b/src/iop/cacorrect.c index ab93a2b8963c..d33463fea322 100644 --- a/src/iop/cacorrect.c +++ b/src/iop/cacorrect.c @@ -93,15 +93,15 @@ typedef __m128 vfloat; #define STVFU(x, y) _mm_storeu_ps(&x, y) #define LVFU(x) _mm_loadu_ps(&x) -#define STC2VFU(a, v) \ - { \ - __m128 TST1V = _mm_loadu_ps(&a); \ - __m128 TST2V = _mm_unpacklo_ps(v, v); \ - vmask cmask = _mm_set_epi32(0xffffffff, 0, 0xffffffff, 0); \ - _mm_storeu_ps(&a, vself(cmask, TST1V, TST2V)); \ - TST1V = _mm_loadu_ps((&a) + 4); \ - TST2V = _mm_unpackhi_ps(v, v); \ - _mm_storeu_ps((&a) + 4, vself(cmask, TST1V, TST2V)); \ +#define STC2VFU(a, v) \ + { \ + __m128 TST1V = _mm_loadu_ps(&a); \ + __m128 TST2V = _mm_unpacklo_ps(v, v); \ + vmask cmask = _mm_set_epi32(0xffffffff, 0, 0xffffffff, 0); \ + _mm_storeu_ps(&a, vself(cmask, TST1V, TST2V)); \ + TST1V = _mm_loadu_ps((&a) + 4); \ + TST2V = _mm_unpackhi_ps(v, v); \ + _mm_storeu_ps((&a) + 4, vself(cmask, TST1V, TST2V)); \ } static INLINE vfloat LC2VFU(float *a) @@ -602,8 +602,7 @@ static void CA_correct(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie // store in rgb array the interpolated G value at R/B grid points using directional weighted // average rgb[1][indx] = (wtu * rgb[1][indx - v1] + wtd * rgb[1][indx + v1] + wtl * rgb[1][indx - 1] - + wtr * rgb[1][indx + 1]) - / (wtu + wtd + wtl + wtr); + + wtr * rgb[1][indx + 1]) / (wtu + wtd + wtl + wtr); } if(row > -1 && row < height) @@ -636,8 +635,8 @@ static void CA_correct(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie vfloat temp2v = vabsf(vabsf((rgb1v - rgbcv) - (LC2VFU(&rgb[1][indx + 4]) - LC2VFU(&rgb[c][indx + 4]))) + vabsf(LC2VFU(&rgb[1][indx - 4]) - LC2VFU(&rgb[c][indx - 4]) - rgb1v + rgbcv) - - vabsf(LC2VFU(&rgb[1][indx - 4]) - LC2VFU(&rgb[c][indx - 4]) - - LC2VFU(&rgb[1][indx + 4]) + LC2VFU(&rgb[c][indx + 4]))); + - vabsf(LC2VFU(&rgb[1][indx - 4]) - LC2VFU(&rgb[c][indx - 4]) - LC2VFU(&rgb[1][indx + 4]) + + LC2VFU(&rgb[c][indx + 4]))); STVFU(rbhpfh[indx >> 1], temp2v); // low and high pass 1D filters of G in vertical/horizontal directions @@ -649,8 +648,7 @@ static void CA_correct(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie epsv + vabsf(glpfvv - zd25v * (rgbcv + LC2VFU(&rgb[c][indx + v2]) + LC2VFU(&rgb[c][indx - v2])))); STVFU(rblpfh[indx >> 1], - epsv + vabsf(glpfhv - - zd25v * (rgbcv + LC2VFU(&rgb[c][indx + 2]) + LC2VFU(&rgb[c][indx - 2])))); + epsv + vabsf(glpfhv - zd25v * (rgbcv + LC2VFU(&rgb[c][indx + 2]) + LC2VFU(&rgb[c][indx - 2])))); STVFU(grblpfv[indx >> 1], glpfvv + zd25v * (rgbcv + LC2VFU(&rgb[c][indx + v2]) + LC2VFU(&rgb[c][indx - v2]))); STVFU(grblpfh[indx >> 1], @@ -664,10 +662,10 @@ static void CA_correct(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie fabsf((rgb[1][indx] - rgb[c][indx]) - (rgb[1][indx + v4] - rgb[c][indx + v4])) + fabsf((rgb[1][indx - v4] - rgb[c][indx - v4]) - (rgb[1][indx] - rgb[c][indx])) - fabsf((rgb[1][indx - v4] - rgb[c][indx - v4]) - (rgb[1][indx + v4] - rgb[c][indx + v4]))); - rbhpfh[indx >> 1] = fabsf( - fabsf((rgb[1][indx] - rgb[c][indx]) - (rgb[1][indx + 4] - rgb[c][indx + 4])) - + fabsf((rgb[1][indx - 4] - rgb[c][indx - 4]) - (rgb[1][indx] - rgb[c][indx])) - - fabsf((rgb[1][indx - 4] - rgb[c][indx - 4]) - (rgb[1][indx + 4] - rgb[c][indx + 4]))); + rbhpfh[indx >> 1] + = fabsf(fabsf((rgb[1][indx] - rgb[c][indx]) - (rgb[1][indx + 4] - rgb[c][indx + 4])) + + fabsf((rgb[1][indx - 4] - rgb[c][indx - 4]) - (rgb[1][indx] - rgb[c][indx])) + - fabsf((rgb[1][indx - 4] - rgb[c][indx - 4]) - (rgb[1][indx + 4] - rgb[c][indx + 4]))); // low and high pass 1D filters of G in vertical/horizontal directions float glpfv = 0.25f * (2.f * rgb[1][indx] + rgb[1][indx + v2] + rgb[1][indx - v2]); @@ -676,8 +674,7 @@ static void CA_correct(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie = eps + fabsf(glpfv - 0.25f * (2.f * rgb[c][indx] + rgb[c][indx + v2] + rgb[c][indx - v2])); rblpfh[indx >> 1] = eps + fabsf(glpfh - 0.25f * (2.f * rgb[c][indx] + rgb[c][indx + 2] + rgb[c][indx - 2])); - grblpfv[indx >> 1] - = glpfv + 0.25f * (2.f * rgb[c][indx] + rgb[c][indx + v2] + rgb[c][indx - v2]); + grblpfv[indx >> 1] = glpfv + 0.25f * (2.f * rgb[c][indx] + rgb[c][indx + v2] + rgb[c][indx - v2]); grblpfh[indx >> 1] = glpfh + 0.25f * (2.f * rgb[c][indx] + rgb[c][indx + 2] + rgb[c][indx - 2]); } } @@ -722,18 +719,16 @@ static void CA_correct(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie // solve for the interpolation position that minimizes colour difference variance over the tile // vertical - vfloat gdiffv - = zd3125v * (LC2VFU(&rgb[1][indx + ts]) - LC2VFU(&rgb[1][indx - ts])) - + zd09375v * (LC2VFU(&rgb[1][indx + ts + 1]) - LC2VFU(&rgb[1][indx - ts + 1]) - + LC2VFU(&rgb[1][indx + ts - 1]) - LC2VFU(&rgb[1][indx - ts - 1])); + vfloat gdiffv = zd3125v * (LC2VFU(&rgb[1][indx + ts]) - LC2VFU(&rgb[1][indx - ts])) + + zd09375v * (LC2VFU(&rgb[1][indx + ts + 1]) - LC2VFU(&rgb[1][indx - ts + 1]) + + LC2VFU(&rgb[1][indx + ts - 1]) - LC2VFU(&rgb[1][indx - ts - 1])); vfloat deltgrbv = LC2VFU(&rgb[c][indx]) - LC2VFU(&rgb[1][indx]); - vfloat gradwtv - = vabsf(zd25v * LVFU(rbhpfv[indx >> 1]) - + zd125v * (LVFU(rbhpfv[(indx >> 1) + 1]) + LVFU(rbhpfv[(indx >> 1) - 1]))) - * (LVFU(grblpfv[(indx >> 1) - v1]) + LVFU(grblpfv[(indx >> 1) + v1])) - / (epsv + zd1v * (LVFU(grblpfv[(indx >> 1) - v1]) + LVFU(grblpfv[(indx >> 1) + v1])) - + LVFU(rblpfv[(indx >> 1) - v1]) + LVFU(rblpfv[(indx >> 1) + v1])); + vfloat gradwtv = vabsf(zd25v * LVFU(rbhpfv[indx >> 1]) + + zd125v * (LVFU(rbhpfv[(indx >> 1) + 1]) + LVFU(rbhpfv[(indx >> 1) - 1]))) + * (LVFU(grblpfv[(indx >> 1) - v1]) + LVFU(grblpfv[(indx >> 1) + v1])) + / (epsv + zd1v * (LVFU(grblpfv[(indx >> 1) - v1]) + LVFU(grblpfv[(indx >> 1) + v1])) + + LVFU(rblpfv[(indx >> 1) - v1]) + LVFU(rblpfv[(indx >> 1) + v1])); coeff00v += gradwtv * deltgrbv * deltgrbv; coeff01v += gradwtv * gdiffv * deltgrbv; @@ -777,15 +772,15 @@ static void CA_correct(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie // vertical float gdiff = 0.3125f * (rgb[1][indx + ts] - rgb[1][indx - ts]) - + 0.09375f * (rgb[1][indx + ts + 1] - rgb[1][indx - ts + 1] - + rgb[1][indx + ts - 1] - rgb[1][indx - ts - 1]); + + 0.09375f * (rgb[1][indx + ts + 1] - rgb[1][indx - ts + 1] + rgb[1][indx + ts - 1] + - rgb[1][indx - ts - 1]); float deltgrb = (rgb[c][indx] - rgb[1][indx]); - float gradwt = fabsf(0.25f * rbhpfv[indx >> 1] - + 0.125f * (rbhpfv[(indx >> 1) + 1] + rbhpfv[(indx >> 1) - 1])) - * (grblpfv[(indx >> 1) - v1] + grblpfv[(indx >> 1) + v1]) - / (eps + 0.1f * (grblpfv[(indx >> 1) - v1] + grblpfv[(indx >> 1) + v1]) - + rblpfv[(indx >> 1) - v1] + rblpfv[(indx >> 1) + v1]); + float gradwt + = fabsf(0.25f * rbhpfv[indx >> 1] + 0.125f * (rbhpfv[(indx >> 1) + 1] + rbhpfv[(indx >> 1) - 1])) + * (grblpfv[(indx >> 1) - v1] + grblpfv[(indx >> 1) + v1]) + / (eps + 0.1f * (grblpfv[(indx >> 1) - v1] + grblpfv[(indx >> 1) + v1]) + + rblpfv[(indx >> 1) - v1] + rblpfv[(indx >> 1) + v1]); coeff[0][0][c >> 1] += gradwt * deltgrb * deltgrb; coeff[0][1][c >> 1] += gradwt * gdiff * deltgrb; @@ -894,8 +889,8 @@ static void CA_correct(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie { if(blockdenom[dir][c]) { - blockvar[dir][c] - = blocksqave[dir][c] / blockdenom[dir][c] - SQR(blockave[dir][c] / blockdenom[dir][c]); + blockvar[dir][c] = blocksqave[dir][c] / blockdenom[dir][c] + - SQR(blockave[dir][c] / blockdenom[dir][c]); } else { @@ -930,8 +925,7 @@ static void CA_correct(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie for(int i = 0; i < 2; i++) { blockshifts[hblock][c][i] = blockshifts[2 * hblsz + hblock][c][i]; - blockshifts[(vblsz - 1) * hblsz + hblock][c][i] - = blockshifts[(vblsz - 3) * hblsz + hblock][c][i]; + blockshifts[(vblsz - 1) * hblsz + hblock][c][i] = blockshifts[(vblsz - 3) * hblsz + hblock][c][i]; } } } @@ -1025,8 +1019,8 @@ static void CA_correct(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie } powVblock *= vblock; } - shiftmat[c][dir][(polyord * i + j)] - += powVblockInit * powHblockInit * bstemp[dir] * blockwt[vblock * hblsz + hblock]; + shiftmat[c][dir][(polyord * i + j)] += powVblockInit * powHblockInit * bstemp[dir] + * blockwt[vblock * hblsz + hblock]; powHblockInit *= hblock; } powVblockInit *= vblock; @@ -1238,8 +1232,7 @@ static void CA_correct(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie // store in rgb array the interpolated G value at R/B grid points using directional weighted // average rgb[1][indx] = (wtu * rgb[1][indx - v1] + wtd * rgb[1][indx + v1] + wtl * rgb[1][indx - 1] - + wtr * rgb[1][indx + 1]) - / (wtu + wtd + wtl + wtr); + + wtr * rgb[1][indx + 1]) / (wtu + wtd + wtl + wtr); } if(row > -1 && row < height && col > -1 && col < width) @@ -1353,8 +1346,8 @@ static void CA_correct(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie // this loop does not deserve vectorization in mainly because the most expensive part with the // divisions does not happen often (less than 1/10 in my tests) for(int rr = 8; rr < rr1 - 8; rr++) - for(int cc = 8 + (FC(rr, 2, filters) & 1), c = FC(rr, cc, filters), indx = rr * ts + cc; - cc < cc1 - 8; cc += 2, indx += 2) + for(int cc = 8 + (FC(rr, 2, filters) & 1), c = FC(rr, cc, filters), indx = rr * ts + cc; cc < cc1 - 8; + cc += 2, indx += 2) { float grbdiffold = rgb[1][indx] - rgb[c][indx]; @@ -1387,8 +1380,8 @@ static void CA_correct(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie float p1 = 1.0f / (eps + fabsf(rgb[1][indx] - gshift[(indx - GRBdir[1][c]) >> 1])); float p2 = 1.0f / (eps + fabsf(rgb[1][indx] - gshift[((rr - GRBdir[0][c]) * ts + cc) >> 1])); float p3 - = 1.0f / (eps + fabsf(rgb[1][indx] - - gshift[((rr - GRBdir[0][c]) * ts + cc - GRBdir[1][c]) >> 1])); + = 1.0f + / (eps + fabsf(rgb[1][indx] - gshift[((rr - GRBdir[0][c]) * ts + cc - GRBdir[1][c]) >> 1])); grbdiffint = (p0 * grbdiff[indx >> 1] + p1 * grbdiff[(indx - GRBdir[1][c]) >> 1] + p2 * grbdiff[((rr - GRBdir[0][c]) * ts + cc) >> 1] @@ -1415,8 +1408,7 @@ static void CA_correct(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie { int c = FC(rr + top, left + border + (FC(rr + top, 2, filters) & 1), filters); - for(int row = rr + top, cc = border + (FC(rr, 2, filters) & 1), - indx = (row * width + cc + left) >> 1; + for(int row = rr + top, cc = border + (FC(rr, 2, filters) & 1), indx = (row * width + cc + left) >> 1; cc < cc1 - border; cc += 2, indx++) { // int col = cc + left; @@ -1452,8 +1444,7 @@ static void CA_correct(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pie #endif for(int row = 0; row < height; row++) - for(int col = 0 + (FC(row, 0, filters) & 1), indx = (row * width + col) >> 1; col < width; - col += 2, indx++) + for(int col = 0 + (FC(row, 0, filters) & 1), indx = (row * width + col) >> 1; col < width; col += 2, indx++) { out[row * width + col] = RawDataTmp[indx]; } @@ -1517,7 +1508,7 @@ void init(dt_iop_module_t *module) module->default_enabled = 0; // we come just before demosaicing. - module->priority = 73; // module order created by iop_dependencies.py, do not edit! + module->priority = 72; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_cacorrect_params_t); module->gui_data = NULL; } diff --git a/src/iop/channelmixer.c b/src/iop/channelmixer.c index 55dfa4ad1539..c0fdf353e322 100644 --- a/src/iop/channelmixer.c +++ b/src/iop/channelmixer.c @@ -89,10 +89,10 @@ typedef struct dt_iop_channelmixer_params_t typedef struct dt_iop_channelmixer_gui_data_t { GtkBox *vbox; - GtkWidget *combo1; // Output channel - GtkLabel *dtlabel1, *dtlabel2; // output channel, source channels - GtkLabel *label1, *label2, *label3; // red, green, blue - GtkWidget *scale1, *scale2, *scale3; // red, green, blue + GtkWidget *combo1; // Output channel + GtkLabel *dtlabel1, *dtlabel2; // output channel, source channels + GtkLabel *label1, *label2, *label3; // red, green, blue + GtkWidget *scale1, *scale2, *scale3; // red, green, blue } dt_iop_channelmixer_gui_data_t; typedef struct dt_iop_channelmixer_data_t @@ -147,10 +147,10 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) { const dt_iop_channelmixer_data_t *data = (dt_iop_channelmixer_data_t *)piece->data; - const gboolean gray_mix_mode = (data->red[CHANNEL_GRAY] != 0.0 || data->green[CHANNEL_GRAY] != 0.0 - || data->blue[CHANNEL_GRAY] != 0.0) - ? TRUE - : FALSE; + const gboolean gray_mix_mode + = (data->red[CHANNEL_GRAY] != 0.0 || data->green[CHANNEL_GRAY] != 0.0 || data->blue[CHANNEL_GRAY] != 0.0) + ? TRUE + : FALSE; const int ch = piece->colors; #ifdef _OPENMP @@ -228,7 +228,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const } } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } @@ -249,10 +250,10 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m const int width = roi_in->width; const int height = roi_in->height; - const int gray_mix_mode = (data->red[CHANNEL_GRAY] != 0.0f || data->green[CHANNEL_GRAY] != 0.0f - || data->blue[CHANNEL_GRAY] != 0.0f) - ? TRUE - : FALSE; + const int gray_mix_mode + = (data->red[CHANNEL_GRAY] != 0.0f || data->green[CHANNEL_GRAY] != 0.0f || data->blue[CHANNEL_GRAY] != 0.0f) + ? TRUE + : FALSE; size_t sizes[] = { ROUNDUPWD(width), ROUNDUPHT(height), 1 }; @@ -418,12 +419,11 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_channelmixer_params_t)); module->default_params = calloc(1, sizeof(dt_iop_channelmixer_params_t)); module->default_enabled = 0; - module->priority = 823; // module order created by iop_dependencies.py, do not edit! + module->priority = 826; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_channelmixer_params_t); module->gui_data = NULL; - dt_iop_channelmixer_params_t tmp = (dt_iop_channelmixer_params_t){ { 0, 0, 0, 1, 0, 0, 0 }, - { 0, 0, 0, 0, 1, 0, 0 }, - { 0, 0, 0, 0, 0, 1, 0 } }; + dt_iop_channelmixer_params_t tmp + = (dt_iop_channelmixer_params_t){ { 0, 0, 0, 1, 0, 0, 0 }, { 0, 0, 0, 0, 1, 0, 0 }, { 0, 0, 0, 0, 0, 1, 0 } }; memcpy(module->params, &tmp, sizeof(dt_iop_channelmixer_params_t)); memcpy(module->default_params, &tmp, sizeof(dt_iop_channelmixer_params_t)); } @@ -486,25 +486,21 @@ void init_presets(dt_iop_module_so_t *self) { DT_DEBUG_SQLITE3_EXEC(dt_database_get(darktable.db), "BEGIN", NULL, NULL, NULL); - dt_gui_presets_add_generic(_("swap R and B"), self->op, self->version(), - &(dt_iop_channelmixer_params_t){ { 0, 0, 0, 0, 0, 1, 0 }, - { 0, 0, 0, 0, 1, 0, 0 }, - { 0, 0, 0, 1, 0, 0, 0 } }, - sizeof(dt_iop_channelmixer_params_t), 1); - dt_gui_presets_add_generic(_("swap G and B"), self->op, self->version(), - &(dt_iop_channelmixer_params_t){ { 0, 0, 0, 1, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 1, 0 }, - { 0, 0, 0, 0, 1, 0, 0 } }, - sizeof(dt_iop_channelmixer_params_t), 1); + dt_gui_presets_add_generic( + _("swap R and B"), self->op, self->version(), + &(dt_iop_channelmixer_params_t){ { 0, 0, 0, 0, 0, 1, 0 }, { 0, 0, 0, 0, 1, 0, 0 }, { 0, 0, 0, 1, 0, 0, 0 } }, + sizeof(dt_iop_channelmixer_params_t), 1); + dt_gui_presets_add_generic( + _("swap G and B"), self->op, self->version(), + &(dt_iop_channelmixer_params_t){ { 0, 0, 0, 1, 0, 0, 0 }, { 0, 0, 0, 0, 0, 1, 0 }, { 0, 0, 0, 0, 1, 0, 0 } }, + sizeof(dt_iop_channelmixer_params_t), 1); dt_gui_presets_add_generic(_("color contrast boost"), self->op, self->version(), - &(dt_iop_channelmixer_params_t){ { 0, 0, 0.8, 1, 0, 0, 0 }, - { 0, 0, 0.1, 0, 1, 0, 0 }, - { 0, 0, 0.1, 0, 0, 1, 0 } }, + &(dt_iop_channelmixer_params_t){ + { 0, 0, 0.8, 1, 0, 0, 0 }, { 0, 0, 0.1, 0, 1, 0, 0 }, { 0, 0, 0.1, 0, 0, 1, 0 } }, sizeof(dt_iop_channelmixer_params_t), 1); dt_gui_presets_add_generic(_("color details boost"), self->op, self->version(), - &(dt_iop_channelmixer_params_t){ { 0, 0, 0.1, 1, 0, 0, 0 }, - { 0, 0, 0.8, 0, 1, 0, 0 }, - { 0, 0, 0.1, 0, 0, 1, 0 } }, + &(dt_iop_channelmixer_params_t){ + { 0, 0, 0.1, 1, 0, 0, 0 }, { 0, 0, 0.8, 0, 1, 0, 0 }, { 0, 0, 0.1, 0, 0, 1, 0 } }, sizeof(dt_iop_channelmixer_params_t), 1); dt_gui_presets_add_generic(_("color artifacts boost"), self->op, self->version(), &(dt_iop_channelmixer_params_t){ { 0, 0, 0.1, 1, 0, 0, 0 }, diff --git a/src/iop/clahe.c b/src/iop/clahe.c index c2c9083b9653..08b382f0fe18 100644 --- a/src/iop/clahe.c +++ b/src/iop/clahe.c @@ -36,7 +36,7 @@ #define CLIP(x) ((x < 0) ? 0.0 : (x > 1.0) ? 1.0 : x) -#define ROUND_POSISTIVE(f) ((unsigned int)((f)+0.5)) +#define ROUND_POSISTIVE(f) ((unsigned int)((f) + 0.5)) DT_MODULE(1) @@ -292,7 +292,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_rlce_params_t)); module->default_params = calloc(1, sizeof(dt_iop_rlce_params_t)); module->default_enabled = 0; - module->priority = 897; // module order created by iop_dependencies.py, do not edit! + module->priority = 898; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_rlce_params_t); module->gui_data = NULL; dt_iop_rlce_params_t tmp = (dt_iop_rlce_params_t){ 64, 1.25 }; @@ -323,10 +323,8 @@ void gui_init(struct dt_iop_module_t *self) g->label2 = dtgtk_reset_label_new(_("amount"), self, &p->slope, sizeof(float)); gtk_box_pack_start(GTK_BOX(g->vbox1), g->label2, TRUE, TRUE, 0); - g->scale1 = dt_bauhaus_slider_new_with_range(NULL, 0.0, 256.0, 1.0, - p->radius, 0); - g->scale2 = dt_bauhaus_slider_new_with_range(NULL, 1.0, 3.0, 0.05, - p->slope, 2); + g->scale1 = dt_bauhaus_slider_new_with_range(NULL, 0.0, 256.0, 1.0, p->radius, 0); + g->scale2 = dt_bauhaus_slider_new_with_range(NULL, 1.0, 3.0, 0.05, p->slope, 2); // dtgtk_slider_set_format_type(g->scale2,DARKTABLE_SLIDER_FORMAT_PERCENT); gtk_box_pack_start(GTK_BOX(g->vbox2), GTK_WIDGET(g->scale1), TRUE, TRUE, 0); diff --git a/src/iop/clipping.c b/src/iop/clipping.c index 016028102f20..13bcd5d4f805 100644 --- a/src/iop/clipping.c +++ b/src/iop/clipping.c @@ -51,9 +51,9 @@ DT_MODULE_INTROSPECTION(5, dt_iop_clipping_params_t) typedef enum dt_iop_clipping_flags_t { FLAG_FLIP_NONE = 0, - FLAG_FLIP_HORIZONTAL = 1<<0, - FLAG_FLIP_VERTICAL = 1<<1, - FLAG_FLIP_BOTH = FLAG_FLIP_HORIZONTAL|FLAG_FLIP_VERTICAL + FLAG_FLIP_HORIZONTAL = 1 << 0, + FLAG_FLIP_VERTICAL = 1 << 1, + FLAG_FLIP_BOTH = FLAG_FLIP_HORIZONTAL | FLAG_FLIP_VERTICAL } dt_iop_clipping_flags_t; typedef struct dt_iop_clipping_aspect_t @@ -91,8 +91,8 @@ typedef enum _grab_region_t /* calculate the aspect ratios for current image */ static void keystone_type_populate(struct dt_iop_module_t *self, gboolean with_applied, int select); -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(new_version <= old_version) return 1; if(new_version != 5) return 1; @@ -252,7 +252,7 @@ typedef struct dt_iop_clipping_data_t float k_space[4]; // space for the "destination" rectangle of the keystone quadrilatere float kxa, kya, kxb, kyb, kxc, kyc, kxd, - kyd; // point of the "source" quadrilatere (modified if keystone is not "full") + kyd; // point of the "source" quadrilatere (modified if keystone is not "full") float a, b, d, e, g, h; // value of the transformation matrix (c=f=0 && i=1) int k_apply; int crop_auto; @@ -322,22 +322,18 @@ static int gui_has_focus(struct dt_iop_module_t *self) return self->dev->gui_module == self; } -static void keystone_get_matrix(float *k_space, float kxa, float kxb, float kxc, float kxd, float kya, - float kyb, float kyc, float kyd, float *a, float *b, float *d, float *e, - float *g, float *h) +static void keystone_get_matrix(float *k_space, float kxa, float kxb, float kxc, float kxd, float kya, float kyb, + float kyc, float kyd, float *a, float *b, float *d, float *e, float *g, float *h) { *a = -((kxb * (kyd * kyd - kyc * kyd) - kxc * kyd * kyd + kyb * (kxc * kyd - kxd * kyd) + kxd * kyc * kyd) - * k_space[2]) - / (kxb * (kxc * kyd * kyd - kxd * kyc * kyd) + kyb * (kxd * kxd * kyc - kxc * kxd * kyd)); + * k_space[2]) / (kxb * (kxc * kyd * kyd - kxd * kyc * kyd) + kyb * (kxd * kxd * kyc - kxc * kxd * kyd)); *b = ((kxb * (kxd * kyd - kxd * kyc) - kxc * kxd * kyd + kxd * kxd * kyc + (kxc * kxd - kxd * kxd) * kyb) - * k_space[2]) - / (kxb * (kxc * kyd * kyd - kxd * kyc * kyd) + kyb * (kxd * kxd * kyc - kxc * kxd * kyd)); + * k_space[2]) / (kxb * (kxc * kyd * kyd - kxd * kyc * kyd) + kyb * (kxd * kxd * kyc - kxc * kxd * kyd)); *d = (kyb * (kxb * (kyd * k_space[3] - kyc * k_space[3]) - kxc * kyd * k_space[3] + kxd * kyc * k_space[3]) + kyb * kyb * (kxc * k_space[3] - kxd * k_space[3])) / (kxb * kyb * (-kxc * kyd - kxd * kyc) + kxb * kxb * kyc * kyd + kxc * kxd * kyb * kyb); *e = -(kxb * (kxd * kyc * k_space[3] - kxc * kyd * k_space[3]) - + kxb * kxb * (kyd * k_space[3] - kyc * k_space[3]) - + kxb * kyb * (kxc * k_space[3] - kxd * k_space[3])) + + kxb * kxb * (kyd * k_space[3] - kyc * k_space[3]) + kxb * kyb * (kxc * k_space[3] - kxd * k_space[3])) / (kxb * kyb * (-kxc * kyd - kxd * kyc) + kxb * kxb * kyc * kyd + kxc * kxd * kyb * kyb); *g = -(kyb * (kxb * (2.0f * kxc * kyd * kyd - 2.0f * kxc * kyc * kyd) - kxc * kxc * kyd * kyd + 2.0f * kxc * kxd * kyc * kyd - kxd * kxd * kyc * kyc) @@ -355,8 +351,8 @@ static void keystone_get_matrix(float *k_space, float kxa, float kxb, float kxc, + kyb * kyb * (kxc * kxd * kxd * kyc - kxc * kxc * kxd * kyd)); } -static void keystone_backtransform(float *i, float *k_space, float a, float b, float d, float e, float g, - float h, float kxa, float kya) +static void keystone_backtransform(float *i, float *k_space, float a, float b, float d, float e, float g, float h, + float kxa, float kya) { float xx = i[0] - k_space[0]; float yy = i[1] - k_space[1]; @@ -458,8 +454,7 @@ int distort_transform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, floa return 1; } -int distort_backtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, float *points, - size_t points_count) +int distort_backtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, float *points, size_t points_count) { // as dt_iop_roi_t contain int values and not floats, we can have some rounding errors // as a workaround, we use a factor for preview pipes @@ -752,8 +747,8 @@ void modify_roi_out(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t } // 2nd pass: which roi would this operation need as input to fill the given output region? -void modify_roi_in(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_out, dt_iop_roi_t *roi_in) +void modify_roi_in(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const dt_iop_roi_t *roi_out, + dt_iop_roi_t *roi_in) { dt_iop_clipping_data_t *d = (dt_iop_clipping_data_t *)piece->data; *roi_in = *roi_out; @@ -794,8 +789,7 @@ void modify_roi_in(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t * o[1] += d->ty * so; o[0] /= kw; o[1] /= kh; - if(d->k_apply == 1) - keystone_backtransform(o, d->k_space, d->a, d->b, d->d, d->e, d->g, d->h, d->kxa, d->kya); + if(d->k_apply == 1) keystone_backtransform(o, d->k_space, d->a, d->b, d->d, d->e, d->g, d->h, d->kxa, d->kya); o[0] *= kw; o[1] *= kh; // transform to roi_in space, get aabb. @@ -868,8 +862,7 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const keystone_get_matrix(k_space, kxa, kxb, kxc, kxd, kya, kyb, kyc, kyd, &ma, &mb, &md, &me, &mg, &mh); #ifdef _OPENMP -#pragma omp parallel for schedule(static) default(none) shared(d, interpolation, k_space, ma, mb, md, me, \ - mg, mh) +#pragma omp parallel for schedule(static) default(none) shared(d, interpolation, k_space, ma, mb, md, me, mg, mh) #endif // (slow) point-by-point transformation. // TODO: optimize with scanlines and linear steps between? @@ -1173,8 +1166,8 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix d->kyb = d->kyb - d->kya; d->kyc = d->kyc - d->kya; d->kyd = d->kyd - d->kya; - keystone_get_matrix(d->k_space, d->kxa, d->kxb, d->kxc, d->kxd, d->kya, d->kyb, d->kyc, d->kyd, &d->a, - &d->b, &d->d, &d->e, &d->g, &d->h); + keystone_get_matrix(d->k_space, d->kxa, d->kxb, d->kxc, d->kxd, d->kya, d->kyb, d->kyc, d->kyd, &d->a, &d->b, + &d->d, &d->e, &d->g, &d->h); d->k_apply = 1; d->all_off = 0; @@ -1644,8 +1637,10 @@ void gui_update(struct dt_iop_module_t *self) } // keystone : - if(p->k_apply == 1) g->k_show = 2; // needed to initialise correctly the combobox - else g->k_show = -1; + if(p->k_apply == 1) + g->k_show = 2; // needed to initialise correctly the combobox + else + g->k_show = -1; if(g->k_show == 2) { @@ -1689,7 +1684,7 @@ void init(dt_iop_module_t *module) module->default_enabled = 0; module->params_size = sizeof(dt_iop_clipping_params_t); module->gui_data = NULL; - module->priority = 455; // module order created by iop_dependencies.py, do not edit! + module->priority = 463; // module order created by iop_dependencies.py, do not edit! } void cleanup(dt_iop_module_t *module) @@ -1827,7 +1822,8 @@ static gint _aspect_ratio_cmp(const dt_iop_clipping_aspect_t *a, const dt_iop_cl static gchar *format_aspect(gchar *original, int adim, int bdim) { // Special ratios: freehand, original image - if ( bdim == 0 ) { + if(bdim == 0) + { return g_strdup(original); } @@ -1895,26 +1891,27 @@ void gui_init(struct dt_iop_module_t *self) g_signal_connect(G_OBJECT(g->crop_auto), "value-changed", G_CALLBACK(crop_auto_changed), self); gtk_box_pack_start(GTK_BOX(self->widget), g->crop_auto, TRUE, TRUE, 0); - dt_iop_clipping_aspect_t aspects[] = { { _("freehand"), 0, 0 }, - { _("original image"), 1, 0 }, - { _("square"), 1, 1 }, - { _("10:8 in print"), 2445, 2032 }, - { _("5:4, 4x5, 8x10"), 5, 4 }, - { _("11x14"), 14, 11 }, - { _("8.5x11, letter"), 110, 85 }, - { _("4:3, VGA, TV"), 4, 3 }, - { _("5x7"), 7, 5 }, - { _("ISO 216, DIN 476, A4"), 14142136, 10000000 }, - { _("3:2, 4x6, 35mm"), 3, 2 }, - { _("16:10, 8x5"), 16, 10 }, - { _("golden cut"), 16180340, 10000000 }, - { _("16:9, HDTV"), 16, 9 }, - { _("widescreen"), 185, 100 }, - { _("2:1, univisium"), 2, 1 }, - { _("cinemascope"), 235, 100 }, - { _("21:9"), 237, 100 }, - { _("anamorphic"), 239, 100 }, - { _("3:1, panorama"), 300, 100 }, + dt_iop_clipping_aspect_t aspects[] = { + { _("freehand"), 0, 0 }, + { _("original image"), 1, 0 }, + { _("square"), 1, 1 }, + { _("10:8 in print"), 2445, 2032 }, + { _("5:4, 4x5, 8x10"), 5, 4 }, + { _("11x14"), 14, 11 }, + { _("8.5x11, letter"), 110, 85 }, + { _("4:3, VGA, TV"), 4, 3 }, + { _("5x7"), 7, 5 }, + { _("ISO 216, DIN 476, A4"), 14142136, 10000000 }, + { _("3:2, 4x6, 35mm"), 3, 2 }, + { _("16:10, 8x5"), 16, 10 }, + { _("golden cut"), 16180340, 10000000 }, + { _("16:9, HDTV"), 16, 9 }, + { _("widescreen"), 185, 100 }, + { _("2:1, univisium"), 2, 1 }, + { _("cinemascope"), 235, 100 }, + { _("21:9"), 237, 100 }, + { _("anamorphic"), 239, 100 }, + { _("3:1, panorama"), 300, 100 }, }; const int aspects_count = sizeof(aspects) / sizeof(dt_iop_clipping_aspect_t); @@ -1961,7 +1958,6 @@ void gui_init(struct dt_iop_module_t *self) dt_control_log(_("invalid ratio format for `%s'. it should be \"number:number\""), nv->key); continue; } - } g_slist_free_full(custom_aspects, dt_conf_string_entry_free); @@ -2119,9 +2115,9 @@ static void gui_draw_sym(cairo_t *cr, float x, float y, gboolean active) pango_layout_set_text(layout, "ꝏ", -1); pango_layout_get_pixel_extents(layout, &ink, NULL); cairo_set_source_rgba(cr, .5, .5, .5, .7); - gui_draw_rounded_rectangle( - cr, ink.width + DT_PIXEL_APPLY_DPI(4), ink.height + DT_PIXEL_APPLY_DPI(8), - x - ink.width / 2.0f - DT_PIXEL_APPLY_DPI(2), y - ink.height / 2.0f - DT_PIXEL_APPLY_DPI(4)); + gui_draw_rounded_rectangle(cr, ink.width + DT_PIXEL_APPLY_DPI(4), ink.height + DT_PIXEL_APPLY_DPI(8), + x - ink.width / 2.0f - DT_PIXEL_APPLY_DPI(2), + y - ink.height / 2.0f - DT_PIXEL_APPLY_DPI(4)); cairo_move_to(cr, x - ink.width / 2.0f, y - 3.0 * ink.height / 4.0f - DT_PIXEL_APPLY_DPI(4)); if(active) cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, .9); @@ -2133,8 +2129,8 @@ static void gui_draw_sym(cairo_t *cr, float x, float y, gboolean active) } // draw guides and handles over the image -void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, int32_t height, - int32_t pointerx, int32_t pointery) +void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, + int32_t pointery) { dt_develop_t *dev = self->dev; dt_iop_clipping_gui_data_t *g = (dt_iop_clipping_gui_data_t *)self->gui_data; @@ -2302,8 +2298,8 @@ void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, i if(grab == GRAB_BOTTOM) cairo_rectangle(cr, g->clip_x * wd, (g->clip_y + g->clip_h) * ht - border, g->clip_w * wd, border); if(grab == GRAB_BOTTOM_RIGHT) - cairo_rectangle(cr, (g->clip_x + g->clip_w) * wd - border, (g->clip_y + g->clip_h) * ht - border, - border, border); + cairo_rectangle(cr, (g->clip_x + g->clip_w) * wd - border, (g->clip_y + g->clip_h) * ht - border, border, + border); if(grab == GRAB_TOP_RIGHT) cairo_rectangle(cr, (g->clip_x + g->clip_w) * wd - border, g->clip_y * ht, border, border); if(grab == GRAB_BOTTOM_LEFT) @@ -2500,8 +2496,7 @@ void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, i int c[2] = { (MIN(pts[4], pts[2]) + MAX(pts[0], pts[6])) / 2.0f, (MIN(pts[5], pts[7]) + MAX(pts[1], pts[3])) / 2.0f }; cairo_set_source_rgba(cr, .5, .5, .5, .9); - gui_draw_rounded_rectangle(cr, ink.width + DT_PIXEL_APPLY_DPI(8), - ink.height + DT_PIXEL_APPLY_DPI(12), + gui_draw_rounded_rectangle(cr, ink.width + DT_PIXEL_APPLY_DPI(8), ink.height + DT_PIXEL_APPLY_DPI(12), c[0] - ink.width / 2.0f - DT_PIXEL_APPLY_DPI(4), c[1] - ink.height / 2.0f - DT_PIXEL_APPLY_DPI(6)); cairo_move_to(cr, c[0] - ink.width / 2.0f, c[1] - 3.0 * ink.height / 4.0f); @@ -2557,9 +2552,7 @@ int mouse_moved(struct dt_iop_module_t *self, double x, double y, double pressur // we don't do anything if the image is not ready if((self->dev->preview_pipe->backbuf_width == g->old_width - && self->dev->preview_pipe->backbuf_height == g->old_height) - ||self->dev->preview_loading - ) + && self->dev->preview_pipe->backbuf_height == g->old_height) || self->dev->preview_loading) return 0; g->old_width = g->old_height = -1; @@ -2589,8 +2582,7 @@ int mouse_moved(struct dt_iop_module_t *self, double x, double y, double pressur if(g->k_drag == TRUE && g->k_selected >= 0) { float pts[2] = { pzx * wd, pzy * ht }; - dt_dev_distort_backtransform_plus(self->dev, self->dev->preview_pipe, self->priority + 1, 9999999, pts, - 1); + dt_dev_distort_backtransform_plus(self->dev, self->dev->preview_pipe, self->priority + 1, 9999999, pts, 1); dt_dev_pixelpipe_iop_t *piece = dt_dev_distort_get_iop_pipe(self->dev, self->dev->preview_pipe, self); float xx = pts[0] / (float)piece->buf_out.width, yy = pts[1] / (float)piece->buf_out.height; if(g->k_selected == 0) @@ -2733,8 +2725,7 @@ int mouse_moved(struct dt_iop_module_t *self, double x, double y, double pressur length = (fabs(xx) > fabs(yy)) ? xx : yy; - if((g->prev_clip_w - (length + length)) < 0.1 || (g->prev_clip_h - (length + length)) < 0.1) - flag = TRUE; + if((g->prev_clip_w - (length + length)) < 0.1 || (g->prev_clip_h - (length + length)) < 0.1) flag = TRUE; g->clip_x = flag ? g->clip_x : g->prev_clip_x + length; g->clip_y = flag ? g->clip_y : g->prev_clip_y + length; @@ -2771,8 +2762,8 @@ int mouse_moved(struct dt_iop_module_t *self, double x, double y, double pressur // we save crop params too float points[4] = { g->clip_x * wd, g->clip_y * ht, (g->clip_x + g->clip_w) * wd, (g->clip_y + g->clip_h) * ht }; - if(dt_dev_distort_backtransform_plus(self->dev, self->dev->preview_pipe, self->priority + 1, 9999999, - points, 2)) + if(dt_dev_distort_backtransform_plus(self->dev, self->dev->preview_pipe, self->priority + 1, 9999999, points, + 2)) { dt_dev_pixelpipe_iop_t *piece = dt_dev_distort_get_iop_pipe(self->dev, self->dev->preview_pipe, self); if(piece) @@ -2824,8 +2815,7 @@ int mouse_moved(struct dt_iop_module_t *self, double x, double y, double pressur if(g->k_show == 1 && g->k_drag == FALSE) { float pts[2] = { pzx * wd, pzy * ht }; - dt_dev_distort_backtransform_plus(self->dev, self->dev->preview_pipe, self->priority + 1, 9999999, pts, - 1); + dt_dev_distort_backtransform_plus(self->dev, self->dev->preview_pipe, self->priority + 1, 9999999, pts, 1); dt_dev_pixelpipe_iop_t *piece = dt_dev_distort_get_iop_pipe(self->dev, self->dev->preview_pipe, self); float xx = pts[0] / (float)piece->buf_out.width, yy = pts[1] / (float)piece->buf_out.height; // are we near a keystone point ? @@ -2881,10 +2871,8 @@ static void commit_box(dt_iop_module_t *self, dt_iop_clipping_gui_data_t *g, dt_ // we want value in iop space float wd = self->dev->preview_pipe->backbuf_width; float ht = self->dev->preview_pipe->backbuf_height; - float points[4] - = { g->clip_x * wd, g->clip_y * ht, (g->clip_x + g->clip_w) * wd, (g->clip_y + g->clip_h) * ht }; - if(dt_dev_distort_backtransform_plus(self->dev, self->dev->preview_pipe, self->priority + 1, 9999999, - points, 2)) + float points[4] = { g->clip_x * wd, g->clip_y * ht, (g->clip_x + g->clip_w) * wd, (g->clip_y + g->clip_h) * ht }; + if(dt_dev_distort_backtransform_plus(self->dev, self->dev->preview_pipe, self->priority + 1, 9999999, points, 2)) { dt_dev_pixelpipe_iop_t *piece = dt_dev_distort_get_iop_pipe(self->dev, self->dev->preview_pipe, self); if(piece) @@ -2971,7 +2959,7 @@ int button_pressed(struct dt_iop_module_t *self, double x, double y, double pres { if(g->k_selected >= 0) g->k_drag = TRUE; // if a keystone point is selected then we start to drag it - else // if we click to the apply button + else // if we click to the apply button { dt_dev_zoom_t zoom = dt_control_get_dev_zoom(); int closeup = dt_control_get_dev_closeup(); @@ -3074,8 +3062,7 @@ int button_pressed(struct dt_iop_module_t *self, double x, double y, double pres // dragging a border ? if(g->k_selected_segment >= 0) { - dt_dev_get_pointer_zoom_pos(self->dev, x, y, &g->button_down_zoom_x, - &g->button_down_zoom_y); + dt_dev_get_pointer_zoom_pos(self->dev, x, y, &g->button_down_zoom_x, &g->button_down_zoom_y); g->button_down_zoom_x += 0.5; g->button_down_zoom_y += 0.5; g->k_drag = TRUE; diff --git a/src/iop/colisa.c b/src/iop/colisa.c index f081c1d79bef..42360f638582 100644 --- a/src/iop/colisa.c +++ b/src/iop/colisa.c @@ -229,7 +229,7 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix dt_iop_colisa_params_t *p = (dt_iop_colisa_params_t *)p1; dt_iop_colisa_data_t *d = (dt_iop_colisa_data_t *)piece->data; - d->contrast = p->contrast + 1.0f; // rescale from [-1;+1] to [0;+2] (zero meaning no contrast -> gray plane) + d->contrast = p->contrast + 1.0f; // rescale from [-1;+1] to [0;+2] (zero meaning no contrast -> gray plane) d->brightness = p->brightness * 2.0f; // rescale from [-1;+1] to [-2;+2] d->saturation = p->saturation + 1.0f; // rescale from [-1;+1] to [0;+2] (zero meaning no saturation -> b&w) @@ -316,7 +316,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_colisa_params_t)); module->default_params = calloc(1, sizeof(dt_iop_colisa_params_t)); module->default_enabled = 0; - module->priority = 647; // module order created by iop_dependencies.py, do not edit! + module->priority = 652; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_colisa_params_t); module->gui_data = NULL; dt_iop_colisa_params_t tmp = (dt_iop_colisa_params_t){ 0, 0, 0 }; @@ -327,8 +327,7 @@ void init(dt_iop_module_t *module) void init_global(dt_iop_module_so_t *module) { const int program = 2; // basic.cl, from programs.conf - dt_iop_colisa_global_data_t *gd - = (dt_iop_colisa_global_data_t *)malloc(sizeof(dt_iop_colisa_global_data_t)); + dt_iop_colisa_global_data_t *gd = (dt_iop_colisa_global_data_t *)malloc(sizeof(dt_iop_colisa_global_data_t)); module->data = gd; gd->kernel_colisa = dt_opencl_create_kernel(program, "colisa"); } diff --git a/src/iop/colorbalance.c b/src/iop/colorbalance.c index 775cdc1028ff..754f4edf2c79 100644 --- a/src/iop/colorbalance.c +++ b/src/iop/colorbalance.c @@ -109,18 +109,18 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const const int ch = piece->colors; // these are RGB values! - const float lift[3] = { 2.0 - (d->lift[CHANNEL_RED] * d->lift[CHANNEL_FACTOR]), - 2.0 - (d->lift[CHANNEL_GREEN] * d->lift[CHANNEL_FACTOR]), - 2.0 - (d->lift[CHANNEL_BLUE] * d->lift[CHANNEL_FACTOR]) }, - gamma[3] = { d->gamma[CHANNEL_RED] * d->gamma[CHANNEL_FACTOR], - d->gamma[CHANNEL_GREEN] * d->gamma[CHANNEL_FACTOR], - d->gamma[CHANNEL_BLUE] * d->gamma[CHANNEL_FACTOR] }, - gamma_inv[3] = { (gamma[0] != 0.0) ? 1.0 / gamma[0] : 1000000.0, - (gamma[1] != 0.0) ? 1.0 / gamma[1] : 1000000.0, - (gamma[2] != 0.0) ? 1.0 / gamma[2] : 1000000.0 }, - gain[3] = { d->gain[CHANNEL_RED] * d->gain[CHANNEL_FACTOR], - d->gain[CHANNEL_GREEN] * d->gain[CHANNEL_FACTOR], - d->gain[CHANNEL_BLUE] * d->gain[CHANNEL_FACTOR] }; + const float lift[3] + = { 2.0 - (d->lift[CHANNEL_RED] * d->lift[CHANNEL_FACTOR]), + 2.0 - (d->lift[CHANNEL_GREEN] * d->lift[CHANNEL_FACTOR]), + 2.0 - (d->lift[CHANNEL_BLUE] * d->lift[CHANNEL_FACTOR]) }, + gamma[3] + = { d->gamma[CHANNEL_RED] * d->gamma[CHANNEL_FACTOR], d->gamma[CHANNEL_GREEN] * d->gamma[CHANNEL_FACTOR], + d->gamma[CHANNEL_BLUE] * d->gamma[CHANNEL_FACTOR] }, + gamma_inv[3] + = { (gamma[0] != 0.0) ? 1.0 / gamma[0] : 1000000.0, (gamma[1] != 0.0) ? 1.0 / gamma[1] : 1000000.0, + (gamma[2] != 0.0) ? 1.0 / gamma[2] : 1000000.0 }, + gain[3] = { d->gain[CHANNEL_RED] * d->gain[CHANNEL_FACTOR], d->gain[CHANNEL_GREEN] * d->gain[CHANNEL_FACTOR], + d->gain[CHANNEL_BLUE] * d->gain[CHANNEL_FACTOR] }; #ifdef _OPENMP #pragma omp parallel for default(none) schedule(static) @@ -163,7 +163,7 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const #if defined(__SSE__) void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, - void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) + void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) { dt_iop_colorbalance_data_t *d = (dt_iop_colorbalance_data_t *)piece->data; const int ch = piece->colors; @@ -171,20 +171,16 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c // these are RGB values! const __m128 lift = _mm_setr_ps(2.0 - (d->lift[CHANNEL_RED] * d->lift[CHANNEL_FACTOR]), 2.0 - (d->lift[CHANNEL_GREEN] * d->lift[CHANNEL_FACTOR]), - 2.0 - (d->lift[CHANNEL_BLUE] * d->lift[CHANNEL_FACTOR]), - 0.0f); + 2.0 - (d->lift[CHANNEL_BLUE] * d->lift[CHANNEL_FACTOR]), 0.0f); const __m128 gamma = _mm_setr_ps(d->gamma[CHANNEL_RED] * d->gamma[CHANNEL_FACTOR], d->gamma[CHANNEL_GREEN] * d->gamma[CHANNEL_FACTOR], - d->gamma[CHANNEL_BLUE] * d->gamma[CHANNEL_FACTOR], - 0.0f); - const __m128 gamma_inv = _mm_setr_ps((gamma[0] != 0.0) ? 1.0 / gamma[0] : 1000000.0, - (gamma[1] != 0.0) ? 1.0 / gamma[1] : 1000000.0, - (gamma[2] != 0.0) ? 1.0 / gamma[2] : 1000000.0, - 0.0f); + d->gamma[CHANNEL_BLUE] * d->gamma[CHANNEL_FACTOR], 0.0f); + const __m128 gamma_inv + = _mm_setr_ps((gamma[0] != 0.0) ? 1.0 / gamma[0] : 1000000.0, (gamma[1] != 0.0) ? 1.0 / gamma[1] : 1000000.0, + (gamma[2] != 0.0) ? 1.0 / gamma[2] : 1000000.0, 0.0f); const __m128 gain = _mm_setr_ps(d->gain[CHANNEL_RED] * d->gain[CHANNEL_FACTOR], d->gain[CHANNEL_GREEN] * d->gain[CHANNEL_FACTOR], - d->gain[CHANNEL_BLUE] * d->gain[CHANNEL_FACTOR], - 0.0f); + d->gain[CHANNEL_BLUE] * d->gain[CHANNEL_FACTOR], 0.0f); #ifdef _OPENMP #pragma omp parallel for default(none) schedule(static) @@ -204,7 +200,7 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c // do the calculation in RGB space __m128 one = _mm_set1_ps(1.0); - __m128 tmp = _mm_mul_ps(_mm_add_ps(_mm_mul_ps(_mm_sub_ps(rgb, one), lift),one), gain); + __m128 tmp = _mm_mul_ps(_mm_add_ps(_mm_mul_ps(_mm_sub_ps(rgb, one), lift), one), gain); tmp = _mm_max_ps(tmp, _mm_setzero_ps()); rgb = _mm_pow_ps(tmp, gamma_inv); @@ -217,7 +213,8 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c } } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #endif @@ -233,18 +230,18 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m const int width = roi_in->width; const int height = roi_in->height; - const float lift[4] = { 2.0f - (d->lift[CHANNEL_RED] * d->lift[CHANNEL_FACTOR]), - 2.0f - (d->lift[CHANNEL_GREEN] * d->lift[CHANNEL_FACTOR]), - 2.0f - (d->lift[CHANNEL_BLUE] * d->lift[CHANNEL_FACTOR]), 0.0f }, - gamma[4] = { d->gamma[CHANNEL_RED] * d->gamma[CHANNEL_FACTOR], - d->gamma[CHANNEL_GREEN] * d->gamma[CHANNEL_FACTOR], - d->gamma[CHANNEL_BLUE] * d->gamma[CHANNEL_FACTOR], 0.0f }, - gamma_inv[4] = { (gamma[0] != 0.0f) ? 1.0f / gamma[0] : 1000000.0f, - (gamma[1] != 0.0f) ? 1.0f / gamma[1] : 1000000.0f, - (gamma[2] != 0.0f) ? 1.0f / gamma[2] : 1000000.0f, 0.0f }, - gain[4] = { d->gain[CHANNEL_RED] * d->gain[CHANNEL_FACTOR], - d->gain[CHANNEL_GREEN] * d->gain[CHANNEL_FACTOR], - d->gain[CHANNEL_BLUE] * d->gain[CHANNEL_FACTOR], 0.0f }; + const float lift[4] + = { 2.0f - (d->lift[CHANNEL_RED] * d->lift[CHANNEL_FACTOR]), + 2.0f - (d->lift[CHANNEL_GREEN] * d->lift[CHANNEL_FACTOR]), + 2.0f - (d->lift[CHANNEL_BLUE] * d->lift[CHANNEL_FACTOR]), 0.0f }, + gamma[4] + = { d->gamma[CHANNEL_RED] * d->gamma[CHANNEL_FACTOR], d->gamma[CHANNEL_GREEN] * d->gamma[CHANNEL_FACTOR], + d->gamma[CHANNEL_BLUE] * d->gamma[CHANNEL_FACTOR], 0.0f }, + gamma_inv[4] + = { (gamma[0] != 0.0f) ? 1.0f / gamma[0] : 1000000.0f, (gamma[1] != 0.0f) ? 1.0f / gamma[1] : 1000000.0f, + (gamma[2] != 0.0f) ? 1.0f / gamma[2] : 1000000.0f, 0.0f }, + gain[4] = { d->gain[CHANNEL_RED] * d->gain[CHANNEL_FACTOR], d->gain[CHANNEL_GREEN] * d->gain[CHANNEL_FACTOR], + d->gain[CHANNEL_BLUE] * d->gain[CHANNEL_FACTOR], 0.0f }; size_t sizes[] = { ROUNDUPWD(width), ROUNDUPHT(height), 1 }; @@ -271,7 +268,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_colorbalance_params_t)); module->default_params = calloc(1, sizeof(dt_iop_colorbalance_params_t)); module->default_enabled = 0; - module->priority = 441; // module order created by iop_dependencies.py, do not edit! + module->priority = 449; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_colorbalance_params_t); module->gui_data = NULL; dt_iop_colorbalance_params_t tmp = (dt_iop_colorbalance_params_t){ { 1.0f, 1.0f, 1.0f, 1.0f }, @@ -605,20 +602,21 @@ void gui_init(dt_iop_module_t *self) #endif -#define ADD_FACTOR(which) \ - g->which##_factor = dt_bauhaus_slider_new_with_range(self, -1.0, 1.0, 0.005, p->which[CHANNEL_FACTOR] - 1.0f, 3);\ - dt_bauhaus_slider_set_stop(g->which##_factor, 0.0, 0.0, 0.0, 0.0);\ - dt_bauhaus_slider_set_stop(g->which##_factor, 1.0, 1.0, 1.0, 1.0);\ - gtk_widget_set_tooltip_text(g->which##_factor, _("factor of " #which));\ - dt_bauhaus_widget_set_label(g->which##_factor, _(#which), _("factor"));\ - g_signal_connect(G_OBJECT(g->which##_factor), "value-changed", G_CALLBACK(which##_factor_callback), self);\ +#define ADD_FACTOR(which) \ + g->which##_factor \ + = dt_bauhaus_slider_new_with_range(self, -1.0, 1.0, 0.005, p->which[CHANNEL_FACTOR] - 1.0f, 3); \ + dt_bauhaus_slider_set_stop(g->which##_factor, 0.0, 0.0, 0.0, 0.0); \ + dt_bauhaus_slider_set_stop(g->which##_factor, 1.0, 1.0, 1.0, 1.0); \ + gtk_widget_set_tooltip_text(g->which##_factor, _("factor of " #which)); \ + dt_bauhaus_widget_set_label(g->which##_factor, _(#which), _("factor")); \ + g_signal_connect(G_OBJECT(g->which##_factor), "value-changed", G_CALLBACK(which##_factor_callback), self); \ gtk_box_pack_start(GTK_BOX(self->widget), g->which##_factor, TRUE, TRUE, 0); -#define ADD_CHANNEL(which, c, n, N) \ - g->which##_##c = dt_bauhaus_slider_new_with_range(self, -1.0, 1.0, 0.005, p->which[CHANNEL_##N] - 1.0f, 3);\ - gtk_widget_set_tooltip_text(g->which##_##c, _("factor of " #n " for " #which));\ - dt_bauhaus_widget_set_label(g->which##_##c, _(#which), _(#n));\ - g_signal_connect(G_OBJECT(g->which##_##c), "value-changed", G_CALLBACK(which##_##n##_callback), self);\ +#define ADD_CHANNEL(which, c, n, N) \ + g->which##_##c = dt_bauhaus_slider_new_with_range(self, -1.0, 1.0, 0.005, p->which[CHANNEL_##N] - 1.0f, 3); \ + gtk_widget_set_tooltip_text(g->which##_##c, _("factor of " #n " for " #which)); \ + dt_bauhaus_widget_set_label(g->which##_##c, _(#which), _(#n)); \ + g_signal_connect(G_OBJECT(g->which##_##c), "value-changed", G_CALLBACK(which##_##n##_callback), self); \ gtk_box_pack_start(GTK_BOX(self->widget), g->which##_##c, TRUE, TRUE, 0); /* lift */ diff --git a/src/iop/colorchecker.c b/src/iop/colorchecker.c index ee63bd4bc46e..06fd221e3d2c 100644 --- a/src/iop/colorchecker.c +++ b/src/iop/colorchecker.c @@ -42,32 +42,32 @@ DT_MODULE_INTROSPECTION(2, dt_iop_colorchecker_params_t) static const int colorchecker_patches = 24; -static const float colorchecker_Lab[] = -{ // from argyll ColorChecker.cie - 37.99, 13.56, 14.06, // dark skin - 65.71, 18.13, 17.81, // light skin - 49.93, -4.88, -21.93, // blue sky - 43.14, -13.10, 21.91, // foliage - 55.11, 8.84, -25.40, // blue flower - 70.72, -33.40, -0.20 , // bluish green - 62.66, 36.07, 57.10, // orange - 40.02, 10.41, -45.96, // purple red - 51.12, 48.24, 16.25, // moderate red - 30.33, 22.98, -21.59, // purple - 72.53, -23.71, 57.26, // yellow green - 71.94, 19.36 , 67.86, // orange yellow - 28.78, 14.18 , -50.30, // blue - 55.26, -38.34, 31.37, // green - 42.10, 53.38 , 28.19, // red - 81.73, 4.04 , 79.82, // yellow - 51.94, 49.99 , -14.57, // magenta - 51.04, -28.63, -28.64, // cyan - 96.54, -0.43 , 1.19 , // white - 81.26, -0.64 , -0.34 , // neutral 8 - 66.77, -0.73 , -0.50 , // neutral 65 - 50.87, -0.15 , -0.27 , // neutral 5 - 35.66, -0.42 , -1.23 , // neutral 35 - 20.46, -0.08 , -0.97 // black +static const float colorchecker_Lab[] = { + // from argyll ColorChecker.cie + 37.99, 13.56, 14.06, // dark skin + 65.71, 18.13, 17.81, // light skin + 49.93, -4.88, -21.93, // blue sky + 43.14, -13.10, 21.91, // foliage + 55.11, 8.84, -25.40, // blue flower + 70.72, -33.40, -0.20, // bluish green + 62.66, 36.07, 57.10, // orange + 40.02, 10.41, -45.96, // purple red + 51.12, 48.24, 16.25, // moderate red + 30.33, 22.98, -21.59, // purple + 72.53, -23.71, 57.26, // yellow green + 71.94, 19.36, 67.86, // orange yellow + 28.78, 14.18, -50.30, // blue + 55.26, -38.34, 31.37, // green + 42.10, 53.38, 28.19, // red + 81.73, 4.04, 79.82, // yellow + 51.94, 49.99, -14.57, // magenta + 51.04, -28.63, -28.64, // cyan + 96.54, -0.43, 1.19, // white + 81.26, -0.64, -0.34, // neutral 8 + 66.77, -0.73, -0.50, // neutral 65 + 50.87, -0.15, -0.27, // neutral 5 + 35.66, -0.42, -1.23, // neutral 35 + 20.46, -0.08, -0.97 // black }; // we came to the conclusion that more than 7x7 patches will not be @@ -97,10 +97,10 @@ typedef struct dt_iop_colorchecker_gui_data_t typedef struct dt_iop_colorchecker_data_t { int32_t num_patches; - float source_Lab[3*MAX_PATCHES]; - float coeff_L[MAX_PATCHES+4]; - float coeff_a[MAX_PATCHES+4]; - float coeff_b[MAX_PATCHES+4]; + float source_Lab[3 * MAX_PATCHES]; + float coeff_L[MAX_PATCHES + 4]; + float coeff_a[MAX_PATCHES + 4]; + float coeff_b[MAX_PATCHES + 4]; } dt_iop_colorchecker_data_t; typedef struct dt_iop_colorchecker_global_data_t @@ -123,12 +123,8 @@ int flags() return IOP_FLAGS_SUPPORTS_BLENDING | IOP_FLAGS_ALLOW_TILING; } -int legacy_params( - dt_iop_module_t *self, - const void *const old_params, - const int old_version, - void *new_params, - const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { static const float colorchecker_Lab_v1[] = { 39.19, 13.76, 14.29, // dark skin @@ -167,10 +163,10 @@ int legacy_params( if(old_version == 1 && new_version == 2) { dt_iop_colorchecker_params_v1_t *p1 = (dt_iop_colorchecker_params_v1_t *)old_params; - dt_iop_colorchecker_params_t *p2 = (dt_iop_colorchecker_params_t *)new_params; + dt_iop_colorchecker_params_t *p2 = (dt_iop_colorchecker_params_t *)new_params; p2->num_patches = 24; - for(int k=0;k<24;k++) + for(int k = 0; k < 24; k++) { p2->target_L[k] = p1->target_L[k]; p2->target_a[k] = p1->target_a[k]; @@ -189,16 +185,16 @@ void init_presets(dt_iop_module_so_t *self) dt_iop_colorchecker_params_t p; memset(&p, 0, sizeof(p)); p.num_patches = 24; - p.target_L[ 0] = p.source_L[ 0] = 17.460945129394531; - p.target_L[ 1] = p.source_L[ 1] = 26.878498077392578; - p.target_L[ 2] = p.source_L[ 2] = 34.900054931640625; - p.target_L[ 3] = p.source_L[ 3] = 21.692604064941406; - p.target_L[ 4] = p.source_L[ 4] = 32.18853759765625; - p.target_L[ 5] = p.source_L[ 5] = 62.531227111816406; - p.target_L[ 6] = p.source_L[ 6] = 18.933284759521484; - p.target_L[ 7] = p.source_L[ 7] = 53.936111450195312; - p.target_L[ 8] = p.source_L[ 8] = 69.154266357421875; - p.target_L[ 9] = p.source_L[ 9] = 43.381229400634766; + p.target_L[0] = p.source_L[0] = 17.460945129394531; + p.target_L[1] = p.source_L[1] = 26.878498077392578; + p.target_L[2] = p.source_L[2] = 34.900054931640625; + p.target_L[3] = p.source_L[3] = 21.692604064941406; + p.target_L[4] = p.source_L[4] = 32.18853759765625; + p.target_L[5] = p.source_L[5] = 62.531227111816406; + p.target_L[6] = p.source_L[6] = 18.933284759521484; + p.target_L[7] = p.source_L[7] = 53.936111450195312; + p.target_L[8] = p.source_L[8] = 69.154266357421875; + p.target_L[9] = p.source_L[9] = 43.381229400634766; p.target_L[10] = p.source_L[10] = 57.797889709472656; p.target_L[11] = p.source_L[11] = 73.27630615234375; p.target_L[12] = p.source_L[12] = 53.175498962402344; @@ -213,16 +209,16 @@ void init_presets(dt_iop_module_so_t *self) p.target_L[21] = p.source_L[21] = 76.070747375488281; p.target_L[22] = p.source_L[22] = 68.645004272460938; p.target_L[23] = p.source_L[23] = 74.502906799316406; - p.target_a[ 0] = p.source_a[ 0] = 8.4928874969482422; - p.target_a[ 1] = p.source_a[ 1] = 27.94782829284668; - p.target_a[ 2] = p.source_a[ 2] = 43.8824462890625; - p.target_a[ 3] = p.source_a[ 3] = 16.723676681518555; - p.target_a[ 4] = p.source_a[ 4] = 39.174972534179688; - p.target_a[ 5] = p.source_a[ 5] = 24.966419219970703; - p.target_a[ 6] = p.source_a[ 6] = 8.8226642608642578; - p.target_a[ 7] = p.source_a[ 7] = 34.451812744140625; - p.target_a[ 8] = p.source_a[ 8] = 18.39008903503418; - p.target_a[ 9] = p.source_a[ 9] = 28.272598266601562; + p.target_a[0] = p.source_a[0] = 8.4928874969482422; + p.target_a[1] = p.source_a[1] = 27.94782829284668; + p.target_a[2] = p.source_a[2] = 43.8824462890625; + p.target_a[3] = p.source_a[3] = 16.723676681518555; + p.target_a[4] = p.source_a[4] = 39.174972534179688; + p.target_a[5] = p.source_a[5] = 24.966419219970703; + p.target_a[6] = p.source_a[6] = 8.8226642608642578; + p.target_a[7] = p.source_a[7] = 34.451812744140625; + p.target_a[8] = p.source_a[8] = 18.39008903503418; + p.target_a[9] = p.source_a[9] = 28.272598266601562; p.target_a[10] = p.source_a[10] = 10.193824768066406; p.target_a[11] = p.source_a[11] = 13.241470336914062; p.target_a[12] = p.source_a[12] = 43.655307769775391; @@ -237,16 +233,16 @@ void init_presets(dt_iop_module_so_t *self) p.target_a[21] = p.source_a[21] = 4.7686996459960938; p.target_a[22] = p.source_a[22] = 3.0603706836700439; p.target_a[23] = p.source_a[23] = -3.687053918838501; - p.target_b[ 0] = p.source_b[ 0] = -0.023579597473144531; - p.target_b[ 1] = p.source_b[ 1] = 14.991056442260742; - p.target_b[ 2] = p.source_b[ 2] = 26.443553924560547; - p.target_b[ 3] = p.source_b[ 3] = 7.3905587196350098; - p.target_b[ 4] = p.source_b[ 4] = 23.309671401977539; - p.target_b[ 5] = p.source_b[ 5] = 19.262432098388672; - p.target_b[ 6] = p.source_b[ 6] = 3.136211633682251; - p.target_b[ 7] = p.source_b[ 7] = 31.949621200561523; - p.target_b[ 8] = p.source_b[ 8] = 16.144514083862305; - p.target_b[ 9] = p.source_b[ 9] = 25.893926620483398; + p.target_b[0] = p.source_b[0] = -0.023579597473144531; + p.target_b[1] = p.source_b[1] = 14.991056442260742; + p.target_b[2] = p.source_b[2] = 26.443553924560547; + p.target_b[3] = p.source_b[3] = 7.3905587196350098; + p.target_b[4] = p.source_b[4] = 23.309671401977539; + p.target_b[5] = p.source_b[5] = 19.262432098388672; + p.target_b[6] = p.source_b[6] = 3.136211633682251; + p.target_b[7] = p.source_b[7] = 31.949621200561523; + p.target_b[8] = p.source_b[8] = 16.144514083862305; + p.target_b[9] = p.source_b[9] = 25.893926620483398; p.target_b[10] = p.source_b[10] = 12.271202087402344; p.target_b[11] = p.source_b[11] = 16.763805389404297; p.target_b[12] = p.source_b[12] = 53.904998779296875; @@ -267,19 +263,42 @@ void init_presets(dt_iop_module_so_t *self) // implemented by wmader as an iop and matched as a clut for increased // flexibility. this was done using darktable-chart and this is copied // from the resulting dtstyle output file: - const char *hk_params_input = - "9738b84231c098426fb8814234a82d422ac41d422e3fa04100004843f7daa24257e09a422a1a984225113842f89cc9410836ca4295049542ad1c9242887370427cb32b427c512242b5a40742545bd141808740412cc6964262e484429604c44100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ef6d3bc152c2acc1ef6566c093a522c2e7d4e4c1a87c7cc100000000b4c4dd407af09e40d060df418afc7d421dadd0413ec5124097d79041fcba2642fc9f484183eb92415d6b7040fcdcdc41b8fe2f42b64a1740fc8612c1276defc144432ec100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d237eb4022a72842f5639742396d1442a2660d411c338b40000000006e35ca408df2054289658d4132327a4118427741d4cf08c0f8a4d5c03abed7c13fac36c23b41a6c03c2230c07d5088c26caff7c1e0e9c6bff14ecec073b028c29e0accc10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000085f2b642a4ba9a423c9a8442a6493c428baf28425667b64100004843a836a142a84e9b4226719d421cb15d424c22ee4175fcca4211ae96426e6d9a4243878142ef45354222f82542629527420280ff416c2066417e3996420d838e424182e3410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000fa370000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c8b700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004837000000000000c8b60000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000018000000"; + const char *hk_params_input + = "9738b84231c098426fb8814234a82d422ac41d422e3fa04100004843f7daa24257e09a422a1a984225113842f89cc9410836ca429" + "5049542ad1c9242887370427cb32b427c512242b5a40742545bd141808740412cc6964262e484429604c441000000000000000000" + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000000000000000000ef6d3bc152c2acc1ef6566c093a5" + "22c2e7d4e4c1a87c7cc100000000b4c4dd407af09e40d060df418afc7d421dadd0413ec5124097d79041fcba2642fc9f484183eb9" + "2415d6b7040fcdcdc41b8fe2f42b64a1740fc8612c1276defc144432ec10000000000000000000000000000000000000000000000" + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000d237eb4022a72842f5639742396d1442a2660d411c338b4000000000" + "6e35ca408df2054289658d4132327a4118427741d4cf08c0f8a4d5c03abed7c13fac36c23b41a6c03c2230c07d5088c26caff7c1e" + "0e9c6bff14ecec073b028c29e0accc100000000000000000000000000000000000000000000000000000000000000000000000000" + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "00000000000000000000085f2b642a4ba9a423c9a8442a6493c428baf28425667b64100004843a836a142a84e9b4226719d421cb1" + "5d424c22ee4175fcca4211ae96426e6d9a4243878142ef45354222f82542629527420280ff416c2066417e3996420d838e424182e" + "341000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000fa370000000000000000" + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "000000000000000000000000000000000c8b700000000000000000000000000000000000000000000000000000000000000000000" + "000000000000000000000000000000004837000000000000c8b600000000000000000000000000000000000000000000000000000" + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000018000000"; int params_len = 0; - uint8_t *hk_params = dt_exif_xmp_decode( - hk_params_input, strlen(hk_params_input), &params_len); + uint8_t *hk_params = dt_exif_xmp_decode(hk_params_input, strlen(hk_params_input), &params_len); assert(params_len == sizeof(dt_iop_colorchecker_params_t)); assert(hk_params); - dt_gui_presets_add_generic(_("helmholtz/kohlrausch monochrome"), self->op, self->version(), hk_params, params_len, 1); + dt_gui_presets_add_generic(_("helmholtz/kohlrausch monochrome"), self->op, self->version(), hk_params, + params_len, 1); free(hk_params); } -// fast logarithms stolen from paul mineiro http://fastapprox.googlecode.com/svn/trunk/fastapprox/src/fastonebigheader.h -#if 0//def __SSE2__ +// fast logarithms stolen from paul mineiro +// http://fastapprox.googlecode.com/svn/trunk/fastapprox/src/fastonebigheader.h +#if 0 // def __SSE2__ #include <xmmintrin.h> typedef __m128 v4sf; @@ -288,9 +307,9 @@ typedef __m128i v4si; #define v4si_to_v4sf _mm_cvtepi32_ps #define v4sf_to_v4si _mm_cvttps_epi32 -#define v4sfl(x) ((const v4sf) { (x), (x), (x), (x) }) -#define v2dil(x) ((const v4si) { (x), (x) }) -#define v4sil(x) v2dil((((unsigned long long) (x)) << 32) | (x)) +#define v4sfl(x) ((const v4sf){ (x), (x), (x), (x) }) +#define v2dil(x) ((const v4si){ (x), (x) }) +#define v4sil(x) v2dil((((unsigned long long)(x)) << 32) | (x)) static inline v4sf vfastlog2 (v4sf x) { @@ -327,23 +346,27 @@ static inline v4sf kerneldist4(const float *x, const float *y) } #endif -static inline float -fastlog2 (float x) +static inline float fastlog2(float x) { - union { float f; uint32_t i; } vx = { x }; - union { uint32_t i; float f; } mx = { (vx.i & 0x007FFFFF) | 0x3f000000 }; + union + { + float f; + uint32_t i; + } vx = { x }; + union + { + uint32_t i; + float f; + } mx = { (vx.i & 0x007FFFFF) | 0x3f000000 }; float y = vx.i; y *= 1.1920928955078125e-7f; - return y - 124.22551499f - - 1.498030302f * mx.f - - 1.72587999f / (0.3520887068f + mx.f); + return y - 124.22551499f - 1.498030302f * mx.f - 1.72587999f / (0.3520887068f + mx.f); } -static inline float -fastlog (float x) +static inline float fastlog(float x) { - return 0.69314718f * fastlog2 (x); + return 0.69314718f * fastlog2(x); } // static inline float @@ -365,11 +388,8 @@ static inline float kernel(const float *x, const float *y) // well damnit, this speedup thing unfortunately shows severe artifacts. // return r*r*fasterlog(MAX(1e-8f,r)); // this one seems to be a lot better, let's see how it goes: - const float r2 = - (x[0]-y[0])*(x[0]-y[0])+ - (x[1]-y[1])*(x[1]-y[1])+ - (x[2]-y[2])*(x[2]-y[2]); - return r2*fastlog(MAX(1e-8f,r2)); + const float r2 = (x[0] - y[0]) * (x[0] - y[0]) + (x[1] - y[1]) * (x[1] - y[1]) + (x[2] - y[2]) * (x[2] - y[2]); + return r2 * fastlog(MAX(1e-8f, r2)); } void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, @@ -380,9 +400,9 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const #ifdef _OPENMP #pragma omp parallel for default(none) schedule(static) collapse(2) #endif - for(int j=0;j<roi_out->height;j++) + for(int j = 0; j < roi_out->height; j++) { - for(int i=0;i<roi_out->width;i++) + for(int i = 0; i < roi_out->width; i++) { const float *in = ((float *)ivoid) + (size_t)ch * (j * roi_in->width + i); float *out = ((float *)ovoid) + (size_t)ch * (j * roi_in->width + i); @@ -390,28 +410,26 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const out[1] = data->coeff_a[data->num_patches]; out[2] = data->coeff_b[data->num_patches]; // polynomial part: - out[0] += data->coeff_L[data->num_patches+1] * in[0] + - data->coeff_L[data->num_patches+2] * in[1] + - data->coeff_L[data->num_patches+3] * in[2]; - out[1] += data->coeff_a[data->num_patches+1] * in[0] + - data->coeff_a[data->num_patches+2] * in[1] + - data->coeff_a[data->num_patches+3] * in[2]; - out[2] += data->coeff_b[data->num_patches+1] * in[0] + - data->coeff_b[data->num_patches+2] * in[1] + - data->coeff_b[data->num_patches+3] * in[2]; + out[0] += data->coeff_L[data->num_patches + 1] * in[0] + data->coeff_L[data->num_patches + 2] * in[1] + + data->coeff_L[data->num_patches + 3] * in[2]; + out[1] += data->coeff_a[data->num_patches + 1] * in[0] + data->coeff_a[data->num_patches + 2] * in[1] + + data->coeff_a[data->num_patches + 3] * in[2]; + out[2] += data->coeff_b[data->num_patches + 1] * in[0] + data->coeff_b[data->num_patches + 2] * in[1] + + data->coeff_b[data->num_patches + 3] * in[2]; #if defined(_OPENMP) && defined(OPENMP_SIMD_) // <== nice try, i don't think this does anything here #pragma omp SIMD() #endif - for(int k=0;k<data->num_patches;k++) + for(int k = 0; k < data->num_patches; k++) { // rbf from thin plate spline - const float phi = kernel(in, data->source_Lab + 3*k); + const float phi = kernel(in, data->source_Lab + 3 * k); out[0] += data->coeff_L[k] * phi; out[1] += data->coeff_a[k] * phi; out[2] += data->coeff_b[k] * phi; } } } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #if 0 // TODO: @@ -537,14 +555,14 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix const int N = d->num_patches, N4 = N + 4; for(int k = 0; k < N; k++) { - d->source_Lab[3*k+0] = p->source_L[k]; - d->source_Lab[3*k+1] = p->source_a[k]; - d->source_Lab[3*k+2] = p->source_b[k]; + d->source_Lab[3 * k + 0] = p->source_L[k]; + d->source_Lab[3 * k + 1] = p->source_a[k]; + d->source_Lab[3 * k + 2] = p->source_b[k]; } // initialize coefficients with default values that will be // used for N<=4 and if coefficient matrix A is singular - for(int i=0;i<4+N;i++) + for(int i = 0; i < 4 + N; i++) { d->coeff_L[i] = 0; d->coeff_a[i] = 0; @@ -582,158 +600,150 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix */ switch(N) { - case 0: - break; - case 1: - // interpolation via constant function - d->coeff_L[N + 1] = p->target_L[0] / p->source_L[0]; - d->coeff_a[N + 2] = p->target_a[0] / p->source_a[0]; - d->coeff_b[N + 3] = p->target_b[0] / p->source_b[0]; - break; - case 2: - // interpolation via single constant function and the linear - // function of the corresponding color channel - { - double A[2 * 2] = { 1, p->source_L[0], - 1, p->source_L[1] }; - double b[2] = { p->target_L[0], p->target_L[1] }; - if(!gauss_solve(A, b, 2)) break; - d->coeff_L[N + 0] = b[0]; - d->coeff_L[N + 1] = b[1]; - } - { - double A[2 * 2] = { 1, p->source_a[0], - 1, p->source_a[1] }; - double b[2] = { p->target_a[0], p->target_a[1] }; - if(!gauss_solve(A, b, 2)) break; - d->coeff_a[N + 0] = b[0]; - d->coeff_a[N + 2] = b[1]; - } - { - double A[2 * 2] = { 1, p->source_b[0], - 1, p->source_b[1] }; - double b[2] = { p->target_b[0], p->target_b[1] }; - if(!gauss_solve(A, b, 2)) break; - d->coeff_b[N + 0] = b[0]; - d->coeff_b[N + 3] = b[1]; - } - break; - case 3: - // interpolation via single constant function, the linear function - // of the corresponding color channel and the linear functions - // of the other two color channels having both the same weight - { - double A[3 * 3] = { 1, p->source_L[0], p->source_a[0] + p->source_b[0], - 1, p->source_L[1], p->source_a[1] + p->source_b[1], - 1, p->source_L[2], p->source_a[2] + p->source_b[2] }; - double b[3] = { p->target_L[0], p->target_L[1], p->target_L[2] }; - if(!gauss_solve(A, b, 3)) break; - d->coeff_L[N + 0] = b[0]; - d->coeff_L[N + 1] = b[1]; - d->coeff_L[N + 2] = b[2]; - d->coeff_L[N + 3] = b[2]; - } - { - double A[3 * 3] = { 1, p->source_a[0], p->source_L[0] + p->source_b[0], - 1, p->source_a[1], p->source_L[1] + p->source_b[1], - 1, p->source_a[2], p->source_L[2] + p->source_b[2] }; - double b[3] = { p->target_a[0], p->target_a[1], p->target_a[2] }; - if(!gauss_solve(A, b, 3)) break; - d->coeff_a[N + 0] = b[0]; - d->coeff_a[N + 1] = b[2]; - d->coeff_a[N + 2] = b[1]; - d->coeff_a[N + 3] = b[2]; - } - { - double A[3 * 3] = { 1, p->source_b[0], p->source_L[0] + p->source_a[0], - 1, p->source_b[1], p->source_L[1] + p->source_a[1], - 1, p->source_b[2], p->source_L[2] + p->source_a[2] }; - double b[3] = { p->target_b[0], p->target_b[1], p->target_b[2] }; - if(!gauss_solve(A, b, 3)) break; - d->coeff_b[N + 0] = b[0]; - d->coeff_b[N + 1] = b[2]; - d->coeff_b[N + 2] = b[2]; - d->coeff_b[N + 3] = b[1]; - } - break; - case 4: - { - // interpolation via constant function and 3 linear functions - double A[4 * 4] = { 1, p->source_L[0], p->source_a[0], p->source_b[0], - 1, p->source_L[1], p->source_a[1], p->source_b[1], - 1, p->source_L[2], p->source_a[2], p->source_b[2], - 1, p->source_L[3], p->source_a[3], p->source_b[3] }; - int pivot[4]; - if(!gauss_make_triangular(A, pivot, 4)) break; - { - double b[4] = { p->target_L[0], p->target_L[1], p->target_L[2], p->target_L[3] }; - gauss_solve_triangular(A, pivot, b, 4); - d->coeff_L[N + 0] = b[0]; - d->coeff_L[N + 1] = b[1]; - d->coeff_L[N + 2] = b[2]; - d->coeff_L[N + 3] = b[3]; - } - { - double b[4] = { p->target_a[0], p->target_a[1], p->target_a[2], p->target_a[3] }; - gauss_solve_triangular(A, pivot, b, 4); - d->coeff_a[N + 0] = b[0]; - d->coeff_a[N + 1] = b[1]; - d->coeff_a[N + 2] = b[2]; - d->coeff_a[N + 3] = b[3]; - } + case 0: + break; + case 1: + // interpolation via constant function + d->coeff_L[N + 1] = p->target_L[0] / p->source_L[0]; + d->coeff_a[N + 2] = p->target_a[0] / p->source_a[0]; + d->coeff_b[N + 3] = p->target_b[0] / p->source_b[0]; + break; + case 2: + // interpolation via single constant function and the linear + // function of the corresponding color channel + { + double A[2 * 2] = { 1, p->source_L[0], 1, p->source_L[1] }; + double b[2] = { p->target_L[0], p->target_L[1] }; + if(!gauss_solve(A, b, 2)) break; + d->coeff_L[N + 0] = b[0]; + d->coeff_L[N + 1] = b[1]; + } + { + double A[2 * 2] = { 1, p->source_a[0], 1, p->source_a[1] }; + double b[2] = { p->target_a[0], p->target_a[1] }; + if(!gauss_solve(A, b, 2)) break; + d->coeff_a[N + 0] = b[0]; + d->coeff_a[N + 2] = b[1]; + } + { + double A[2 * 2] = { 1, p->source_b[0], 1, p->source_b[1] }; + double b[2] = { p->target_b[0], p->target_b[1] }; + if(!gauss_solve(A, b, 2)) break; + d->coeff_b[N + 0] = b[0]; + d->coeff_b[N + 3] = b[1]; + } + break; + case 3: + // interpolation via single constant function, the linear function + // of the corresponding color channel and the linear functions + // of the other two color channels having both the same weight + { + double A[3 * 3] = { 1, p->source_L[0], p->source_a[0] + p->source_b[0], 1, p->source_L[1], + p->source_a[1] + p->source_b[1], 1, p->source_L[2], p->source_a[2] + p->source_b[2] }; + double b[3] = { p->target_L[0], p->target_L[1], p->target_L[2] }; + if(!gauss_solve(A, b, 3)) break; + d->coeff_L[N + 0] = b[0]; + d->coeff_L[N + 1] = b[1]; + d->coeff_L[N + 2] = b[2]; + d->coeff_L[N + 3] = b[2]; + } + { + double A[3 * 3] = { 1, p->source_a[0], p->source_L[0] + p->source_b[0], 1, p->source_a[1], + p->source_L[1] + p->source_b[1], 1, p->source_a[2], p->source_L[2] + p->source_b[2] }; + double b[3] = { p->target_a[0], p->target_a[1], p->target_a[2] }; + if(!gauss_solve(A, b, 3)) break; + d->coeff_a[N + 0] = b[0]; + d->coeff_a[N + 1] = b[2]; + d->coeff_a[N + 2] = b[1]; + d->coeff_a[N + 3] = b[2]; + } + { + double A[3 * 3] = { 1, p->source_b[0], p->source_L[0] + p->source_a[0], 1, p->source_b[1], + p->source_L[1] + p->source_a[1], 1, p->source_b[2], p->source_L[2] + p->source_a[2] }; + double b[3] = { p->target_b[0], p->target_b[1], p->target_b[2] }; + if(!gauss_solve(A, b, 3)) break; + d->coeff_b[N + 0] = b[0]; + d->coeff_b[N + 1] = b[2]; + d->coeff_b[N + 2] = b[2]; + d->coeff_b[N + 3] = b[1]; + } + break; + case 4: { - double b[4] = { p->target_b[0], p->target_b[1], p->target_b[2], p->target_b[3] }; - gauss_solve_triangular(A, pivot, b, 4); - d->coeff_b[N + 0] = b[0]; - d->coeff_b[N + 1] = b[1]; - d->coeff_b[N + 2] = b[2]; - d->coeff_b[N + 3] = b[3]; + // interpolation via constant function and 3 linear functions + double A[4 * 4] = { 1, p->source_L[0], p->source_a[0], p->source_b[0], 1, p->source_L[1], p->source_a[1], + p->source_b[1], 1, p->source_L[2], p->source_a[2], p->source_b[2], 1, p->source_L[3], + p->source_a[3], p->source_b[3] }; + int pivot[4]; + if(!gauss_make_triangular(A, pivot, 4)) break; + { + double b[4] = { p->target_L[0], p->target_L[1], p->target_L[2], p->target_L[3] }; + gauss_solve_triangular(A, pivot, b, 4); + d->coeff_L[N + 0] = b[0]; + d->coeff_L[N + 1] = b[1]; + d->coeff_L[N + 2] = b[2]; + d->coeff_L[N + 3] = b[3]; + } + { + double b[4] = { p->target_a[0], p->target_a[1], p->target_a[2], p->target_a[3] }; + gauss_solve_triangular(A, pivot, b, 4); + d->coeff_a[N + 0] = b[0]; + d->coeff_a[N + 1] = b[1]; + d->coeff_a[N + 2] = b[2]; + d->coeff_a[N + 3] = b[3]; + } + { + double b[4] = { p->target_b[0], p->target_b[1], p->target_b[2], p->target_b[3] }; + gauss_solve_triangular(A, pivot, b, 4); + d->coeff_b[N + 0] = b[0]; + d->coeff_b[N + 1] = b[1]; + d->coeff_b[N + 2] = b[2]; + d->coeff_b[N + 3] = b[3]; + } + break; } - break; - } - default: - { - // setup linear system of equations - double *A = malloc(N4 * N4 * sizeof(*A)); - double *b = malloc(N4 * sizeof(*b)); - // coefficients from nonlinear radial kernel functions - for(int j=0;j<N;j++) - for(int i=j;i<N;i++) - A[j*N4+i] = A[i*N4+j] = kernel(d->source_Lab+3*i, d->source_Lab+3*j); - // coefficients from constant and linear functions - for(int i=0;i<N;i++) A[i*N4+N+0] = A[(N+0)*N4+i] = 1; - for(int i=0;i<N;i++) A[i*N4+N+1] = A[(N+1)*N4+i] = d->source_Lab[3*i+0]; - for(int i=0;i<N;i++) A[i*N4+N+2] = A[(N+2)*N4+i] = d->source_Lab[3*i+1]; - for(int i=0;i<N;i++) A[i*N4+N+3] = A[(N+3)*N4+i] = d->source_Lab[3*i+2]; - // lower-right zero block - for(int j=N;j<N4;j++) - for(int i=N;i<N4;i++) - A[j*N4+i] = 0; - // make coefficient matrix triangular - int *pivot = malloc(N4 * sizeof(*pivot)); - if (gauss_make_triangular(A, pivot, N4)) + default: { - // calculate coefficients for L channel - for(int i=0;i<N;i++) b[i] = p->target_L[i]; - for(int i=N;i<N+4;i++) b[i] = 0; - gauss_solve_triangular(A, pivot, b, N4); - for(int i=0;i<N+4;i++) d->coeff_L[i] = b[i]; - // calculate coefficients for a channel - for(int i=0;i<N;i++) b[i] = p->target_a[i]; - for(int i=N;i<N+4;i++) b[i] = 0; - gauss_solve_triangular(A, pivot, b, N4); - for(int i=0;i<N+4;i++) d->coeff_a[i] = b[i]; - // calculate coefficients for b channel - for(int i=0;i<N;i++) b[i] = p->target_b[i]; - for(int i=N;i<N+4;i++) b[i] = 0; - gauss_solve_triangular(A, pivot, b, N4); - for(int i=0;i<N+4;i++) d->coeff_b[i] = b[i]; + // setup linear system of equations + double *A = malloc(N4 * N4 * sizeof(*A)); + double *b = malloc(N4 * sizeof(*b)); + // coefficients from nonlinear radial kernel functions + for(int j = 0; j < N; j++) + for(int i = j; i < N; i++) + A[j * N4 + i] = A[i * N4 + j] = kernel(d->source_Lab + 3 * i, d->source_Lab + 3 * j); + // coefficients from constant and linear functions + for(int i = 0; i < N; i++) A[i * N4 + N + 0] = A[(N + 0) * N4 + i] = 1; + for(int i = 0; i < N; i++) A[i * N4 + N + 1] = A[(N + 1) * N4 + i] = d->source_Lab[3 * i + 0]; + for(int i = 0; i < N; i++) A[i * N4 + N + 2] = A[(N + 2) * N4 + i] = d->source_Lab[3 * i + 1]; + for(int i = 0; i < N; i++) A[i * N4 + N + 3] = A[(N + 3) * N4 + i] = d->source_Lab[3 * i + 2]; + // lower-right zero block + for(int j = N; j < N4; j++) + for(int i = N; i < N4; i++) A[j * N4 + i] = 0; + // make coefficient matrix triangular + int *pivot = malloc(N4 * sizeof(*pivot)); + if(gauss_make_triangular(A, pivot, N4)) + { + // calculate coefficients for L channel + for(int i = 0; i < N; i++) b[i] = p->target_L[i]; + for(int i = N; i < N + 4; i++) b[i] = 0; + gauss_solve_triangular(A, pivot, b, N4); + for(int i = 0; i < N + 4; i++) d->coeff_L[i] = b[i]; + // calculate coefficients for a channel + for(int i = 0; i < N; i++) b[i] = p->target_a[i]; + for(int i = N; i < N + 4; i++) b[i] = 0; + gauss_solve_triangular(A, pivot, b, N4); + for(int i = 0; i < N + 4; i++) d->coeff_a[i] = b[i]; + // calculate coefficients for b channel + for(int i = 0; i < N; i++) b[i] = p->target_b[i]; + for(int i = N; i < N + 4; i++) b[i] = 0; + gauss_solve_triangular(A, pivot, b, N4); + for(int i = 0; i < N + 4; i++) d->coeff_b[i] = b[i]; + } + // free resources + free(pivot); + free(b); + free(A); } - // free resources - free(pivot); - free(b); - free(A); - } } } @@ -759,13 +769,13 @@ void gui_update(struct dt_iop_module_t *self) { dt_bauhaus_combobox_clear(g->combobox_patch); char cboxentry[1024]; - for(int k=0;k<p->num_patches;k++) + for(int k = 0; k < p->num_patches; k++) { snprintf(cboxentry, sizeof(cboxentry), _("patch #%d"), k); dt_bauhaus_combobox_add(g->combobox_patch, cboxentry); } if(p->num_patches <= 24) - dtgtk_drawing_area_set_aspect_ratio(g->area, 2.0/3.0); + dtgtk_drawing_area_set_aspect_ratio(g->area, 2.0 / 3.0); else dtgtk_drawing_area_set_aspect_ratio(g->area, 1.0); } @@ -774,9 +784,8 @@ void gui_update(struct dt_iop_module_t *self) dt_bauhaus_slider_set(g->scale_L, p->target_L[g->patch]); dt_bauhaus_slider_set(g->scale_a, p->target_a[g->patch]); dt_bauhaus_slider_set(g->scale_b, p->target_b[g->patch]); - const float Cout = sqrtf( - p->target_a[g->patch]*p->target_a[g->patch]+ - p->target_b[g->patch]*p->target_b[g->patch]); + const float Cout + = sqrtf(p->target_a[g->patch] * p->target_a[g->patch] + p->target_b[g->patch] * p->target_b[g->patch]); dt_bauhaus_slider_set(g->scale_C, Cout); } else @@ -784,13 +793,11 @@ void gui_update(struct dt_iop_module_t *self) dt_bauhaus_slider_set(g->scale_L, p->target_L[g->patch] - p->source_L[g->patch]); dt_bauhaus_slider_set(g->scale_a, p->target_a[g->patch] - p->source_a[g->patch]); dt_bauhaus_slider_set(g->scale_b, p->target_b[g->patch] - p->source_b[g->patch]); - const float Cin = sqrtf( - p->source_a[g->patch]*p->source_a[g->patch] + - p->source_b[g->patch]*p->source_b[g->patch]); - const float Cout = sqrtf( - p->target_a[g->patch]*p->target_a[g->patch]+ - p->target_b[g->patch]*p->target_b[g->patch]); - dt_bauhaus_slider_set(g->scale_C, Cout-Cin); + const float Cin + = sqrtf(p->source_a[g->patch] * p->source_a[g->patch] + p->source_b[g->patch] * p->source_b[g->patch]); + const float Cout + = sqrtf(p->target_a[g->patch] * p->target_a[g->patch] + p->target_b[g->patch] * p->target_b[g->patch]); + dt_bauhaus_slider_set(g->scale_C, Cout - Cin); } gtk_widget_queue_draw(g->area); } @@ -800,17 +807,17 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_colorchecker_params_t)); module->default_params = calloc(1, sizeof(dt_iop_colorchecker_params_t)); module->default_enabled = 0; - module->priority = 382; // module order created by iop_dependencies.py, do not edit! + module->priority = 391; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_colorchecker_params_t); module->gui_data = NULL; dt_iop_colorchecker_params_t tmp; tmp.num_patches = 24; - for(int k=0;k<tmp.num_patches;k++) tmp.source_L[k] = colorchecker_Lab[3*k+0]; - for(int k=0;k<tmp.num_patches;k++) tmp.source_a[k] = colorchecker_Lab[3*k+1]; - for(int k=0;k<tmp.num_patches;k++) tmp.source_b[k] = colorchecker_Lab[3*k+2]; - for(int k=0;k<tmp.num_patches;k++) tmp.target_L[k] = colorchecker_Lab[3*k+0]; - for(int k=0;k<tmp.num_patches;k++) tmp.target_a[k] = colorchecker_Lab[3*k+1]; - for(int k=0;k<tmp.num_patches;k++) tmp.target_b[k] = colorchecker_Lab[3*k+2]; + for(int k = 0; k < tmp.num_patches; k++) tmp.source_L[k] = colorchecker_Lab[3 * k + 0]; + for(int k = 0; k < tmp.num_patches; k++) tmp.source_a[k] = colorchecker_Lab[3 * k + 1]; + for(int k = 0; k < tmp.num_patches; k++) tmp.source_b[k] = colorchecker_Lab[3 * k + 2]; + for(int k = 0; k < tmp.num_patches; k++) tmp.target_L[k] = colorchecker_Lab[3 * k + 0]; + for(int k = 0; k < tmp.num_patches; k++) tmp.target_a[k] = colorchecker_Lab[3 * k + 1]; + for(int k = 0; k < tmp.num_patches; k++) tmp.target_b[k] = colorchecker_Lab[3 * k + 2]; memcpy(module->params, &tmp, sizeof(dt_iop_colorchecker_params_t)); memcpy(module->default_params, &tmp, sizeof(dt_iop_colorchecker_params_t)); } @@ -881,9 +888,8 @@ static void target_a_callback(GtkWidget *slider, gpointer user_data) if(g->absolute_target) { p->target_a[g->patch] = CLAMP(dt_bauhaus_slider_get(slider), -128.0, 128.0); - const float Cout = sqrtf( - p->target_a[g->patch]*p->target_a[g->patch]+ - p->target_b[g->patch]*p->target_b[g->patch]); + const float Cout + = sqrtf(p->target_a[g->patch] * p->target_a[g->patch] + p->target_b[g->patch] * p->target_b[g->patch]); const int reset = darktable.gui->reset; darktable.gui->reset = 1; // avoid history item dt_bauhaus_slider_set(g->scale_C, Cout); @@ -892,15 +898,13 @@ static void target_a_callback(GtkWidget *slider, gpointer user_data) else { p->target_a[g->patch] = CLAMP(p->source_a[g->patch] + dt_bauhaus_slider_get(slider), -128.0, 128.0); - const float Cin = sqrtf( - p->source_a[g->patch]*p->source_a[g->patch] + - p->source_b[g->patch]*p->source_b[g->patch]); - const float Cout = sqrtf( - p->target_a[g->patch]*p->target_a[g->patch]+ - p->target_b[g->patch]*p->target_b[g->patch]); + const float Cin + = sqrtf(p->source_a[g->patch] * p->source_a[g->patch] + p->source_b[g->patch] * p->source_b[g->patch]); + const float Cout + = sqrtf(p->target_a[g->patch] * p->target_a[g->patch] + p->target_b[g->patch] * p->target_b[g->patch]); const int reset = darktable.gui->reset; darktable.gui->reset = 1; // avoid history item - dt_bauhaus_slider_set(g->scale_C, Cout-Cin); + dt_bauhaus_slider_set(g->scale_C, Cout - Cin); darktable.gui->reset = reset; } dt_dev_add_history_item(darktable.develop, self, TRUE); @@ -915,9 +919,8 @@ static void target_b_callback(GtkWidget *slider, gpointer user_data) if(g->absolute_target) { p->target_b[g->patch] = CLAMP(dt_bauhaus_slider_get(slider), -128.0, 128.0); - const float Cout = sqrtf( - p->target_a[g->patch]*p->target_a[g->patch]+ - p->target_b[g->patch]*p->target_b[g->patch]); + const float Cout + = sqrtf(p->target_a[g->patch] * p->target_a[g->patch] + p->target_b[g->patch] * p->target_b[g->patch]); const int reset = darktable.gui->reset; darktable.gui->reset = 1; // avoid history item dt_bauhaus_slider_set(g->scale_C, Cout); @@ -926,15 +929,13 @@ static void target_b_callback(GtkWidget *slider, gpointer user_data) else { p->target_b[g->patch] = CLAMP(p->source_b[g->patch] + dt_bauhaus_slider_get(slider), -128.0, 128.0); - const float Cin = sqrtf( - p->source_a[g->patch]*p->source_a[g->patch] + - p->source_b[g->patch]*p->source_b[g->patch]); - const float Cout = sqrtf( - p->target_a[g->patch]*p->target_a[g->patch]+ - p->target_b[g->patch]*p->target_b[g->patch]); + const float Cin + = sqrtf(p->source_a[g->patch] * p->source_a[g->patch] + p->source_b[g->patch] * p->source_b[g->patch]); + const float Cout + = sqrtf(p->target_a[g->patch] * p->target_a[g->patch] + p->target_b[g->patch] * p->target_b[g->patch]); const int reset = darktable.gui->reset; darktable.gui->reset = 1; // avoid history item - dt_bauhaus_slider_set(g->scale_C, Cout-Cin); + dt_bauhaus_slider_set(g->scale_C, Cout - Cin); darktable.gui->reset = reset; } dt_dev_add_history_item(darktable.develop, self, TRUE); @@ -946,18 +947,16 @@ static void target_C_callback(GtkWidget *slider, gpointer user_data) dt_iop_colorchecker_params_t *p = (dt_iop_colorchecker_params_t *)self->params; dt_iop_colorchecker_gui_data_t *g = (dt_iop_colorchecker_gui_data_t *)self->gui_data; if(g->patch >= p->num_patches || g->patch < 0) return; - const float Cin = sqrtf( - p->source_a[g->patch]*p->source_a[g->patch] + - p->source_b[g->patch]*p->source_b[g->patch]); - const float Cout = MAX(1e-4f, sqrtf( - p->target_a[g->patch]*p->target_a[g->patch]+ - p->target_b[g->patch]*p->target_b[g->patch])); + const float Cin + = sqrtf(p->source_a[g->patch] * p->source_a[g->patch] + p->source_b[g->patch] * p->source_b[g->patch]); + const float Cout = MAX( + 1e-4f, sqrtf(p->target_a[g->patch] * p->target_a[g->patch] + p->target_b[g->patch] * p->target_b[g->patch])); if(g->absolute_target) { const float Cnew = CLAMP(dt_bauhaus_slider_get(slider), 0.01, 128.0); - p->target_a[g->patch] = CLAMP(p->target_a[g->patch]*Cnew/Cout, -128.0, 128.0); - p->target_b[g->patch] = CLAMP(p->target_b[g->patch]*Cnew/Cout, -128.0, 128.0); + p->target_a[g->patch] = CLAMP(p->target_a[g->patch] * Cnew / Cout, -128.0, 128.0); + p->target_b[g->patch] = CLAMP(p->target_b[g->patch] * Cnew / Cout, -128.0, 128.0); const int reset = darktable.gui->reset; darktable.gui->reset = 1; // avoid history item dt_bauhaus_slider_set(g->scale_a, p->target_a[g->patch]); @@ -967,8 +966,8 @@ static void target_C_callback(GtkWidget *slider, gpointer user_data) else { const float Cnew = CLAMP(Cin + dt_bauhaus_slider_get(slider), 0.01, 128.0); - p->target_a[g->patch] = CLAMP(p->target_a[g->patch]*Cnew/Cout, -128.0, 128.0); - p->target_b[g->patch] = CLAMP(p->target_b[g->patch]*Cnew/Cout, -128.0, 128.0); + p->target_a[g->patch] = CLAMP(p->target_a[g->patch] * Cnew / Cout, -128.0, 128.0); + p->target_b[g->patch] = CLAMP(p->target_b[g->patch] * Cnew / Cout, -128.0, 128.0); const int reset = darktable.gui->reset; darktable.gui->reset = 1; // avoid history item dt_bauhaus_slider_set(g->scale_a, p->target_a[g->patch] - p->source_a[g->patch]); @@ -1028,7 +1027,7 @@ static gboolean checker_draw(GtkWidget *widget, cairo_t *crf, gpointer user_data { double rgb[3] = { 0.5, 0.5, 0.5 }; // Lab: rgb grey converted to Lab cmsCIELab Lab; - const int patch = i + j*cells_x; + const int patch = i + j * cells_x; if(patch >= p->num_patches) continue; Lab.L = p->source_L[patch]; Lab.a = p->source_a[patch]; @@ -1050,28 +1049,26 @@ static gboolean checker_draw(GtkWidget *widget, cairo_t *crf, gpointer user_data cmsDoTransform(g->xform, &Lab, rgb, 1); cairo_set_source_rgb(cr, rgb[0], rgb[1], rgb[2]); cairo_rectangle(cr, width * i / (float)cells_x, height * j / (float)cells_y, - width / (float)cells_x - DT_PIXEL_APPLY_DPI(1), - height / (float)cells_y - DT_PIXEL_APPLY_DPI(1)); + width / (float)cells_x - DT_PIXEL_APPLY_DPI(1), + height / (float)cells_y - DT_PIXEL_APPLY_DPI(1)); cairo_fill(cr); - if(fabsf(p->target_L[patch] - p->source_L[patch]) > 1e-5f || - fabsf(p->target_a[patch] - p->source_a[patch]) > 1e-5f || - fabsf(p->target_b[patch] - p->source_b[patch]) > 1e-5f) + if(fabsf(p->target_L[patch] - p->source_L[patch]) > 1e-5f + || fabsf(p->target_a[patch] - p->source_a[patch]) > 1e-5f + || fabsf(p->target_b[patch] - p->source_b[patch]) > 1e-5f) { cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(2.)); cairo_set_source_rgb(cr, 0.8, 0.8, 0.8); - cairo_rectangle(cr, - width * i / (float)cells_x + DT_PIXEL_APPLY_DPI(1), - height * j / (float)cells_y + DT_PIXEL_APPLY_DPI(1), - width / (float)cells_x - DT_PIXEL_APPLY_DPI(3), - height / (float)cells_y - DT_PIXEL_APPLY_DPI(3)); + cairo_rectangle(cr, width * i / (float)cells_x + DT_PIXEL_APPLY_DPI(1), + height * j / (float)cells_y + DT_PIXEL_APPLY_DPI(1), + width / (float)cells_x - DT_PIXEL_APPLY_DPI(3), + height / (float)cells_y - DT_PIXEL_APPLY_DPI(3)); cairo_stroke(cr); cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(1.)); cairo_set_source_rgb(cr, 0.2, 0.2, 0.2); - cairo_rectangle(cr, - width * i / (float)cells_x + DT_PIXEL_APPLY_DPI(2), - height * j / (float)cells_y + DT_PIXEL_APPLY_DPI(2), - width / (float)cells_x - DT_PIXEL_APPLY_DPI(5), - height / (float)cells_y - DT_PIXEL_APPLY_DPI(5)); + cairo_rectangle(cr, width * i / (float)cells_x + DT_PIXEL_APPLY_DPI(2), + height * j / (float)cells_y + DT_PIXEL_APPLY_DPI(2), + width / (float)cells_x - DT_PIXEL_APPLY_DPI(5), + height / (float)cells_y - DT_PIXEL_APPLY_DPI(5)); cairo_stroke(cr); } } @@ -1104,11 +1101,10 @@ static gboolean checker_draw(GtkWidget *widget, cairo_t *crf, gpointer user_data } cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(2.)); cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); - cairo_rectangle(cr, - width * besti / (float)cells_x + DT_PIXEL_APPLY_DPI(5), - height * bestj / (float)cells_y + DT_PIXEL_APPLY_DPI(5), - width / (float)cells_x - DT_PIXEL_APPLY_DPI(11), - height / (float)cells_y - DT_PIXEL_APPLY_DPI(11)); + cairo_rectangle(cr, width * besti / (float)cells_x + DT_PIXEL_APPLY_DPI(5), + height * bestj / (float)cells_y + DT_PIXEL_APPLY_DPI(5), + width / (float)cells_x - DT_PIXEL_APPLY_DPI(11), + height / (float)cells_y - DT_PIXEL_APPLY_DPI(11)); cairo_stroke(cr); cairo_destroy(cr); @@ -1118,8 +1114,7 @@ static gboolean checker_draw(GtkWidget *widget, cairo_t *crf, gpointer user_data return TRUE; } -static gboolean checker_motion_notify(GtkWidget *widget, GdkEventMotion *event, - gpointer user_data) +static gboolean checker_motion_notify(GtkWidget *widget, GdkEventMotion *event, gpointer user_data) { // highlight? dt_iop_module_t *self = (dt_iop_module_t *)user_data; @@ -1141,20 +1136,18 @@ static gboolean checker_motion_notify(GtkWidget *widget, GdkEventMotion *event, const int patch = (int)mx + cells_x * (int)my; if(patch < 0 || patch >= p->num_patches) return FALSE; char tooltip[1024]; - snprintf(tooltip, sizeof(tooltip), - _("(%2.2f %2.2f %2.2f)\n" - "altered patches are marked with an outline\n" - "click to select\n" - "double click to reset\n" - "right click to delete patch\n" - "shift-click while color picking to replace patch"), - p->source_L[patch], p->source_a[patch], p->source_b[patch]); + snprintf(tooltip, sizeof(tooltip), _("(%2.2f %2.2f %2.2f)\n" + "altered patches are marked with an outline\n" + "click to select\n" + "double click to reset\n" + "right click to delete patch\n" + "shift-click while color picking to replace patch"), + p->source_L[patch], p->source_a[patch], p->source_b[patch]); gtk_widget_set_tooltip_text(g->area, tooltip); return TRUE; } -static gboolean checker_button_press(GtkWidget *widget, GdkEventButton *event, - gpointer user_data) +static gboolean checker_button_press(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { dt_iop_module_t *self = (dt_iop_module_t *)user_data; dt_iop_colorchecker_gui_data_t *g = (dt_iop_colorchecker_gui_data_t *)self->gui_data; @@ -1172,7 +1165,7 @@ static gboolean checker_button_press(GtkWidget *widget, GdkEventButton *event, } const float mx = mouse_x * cells_x / (float)width; const float my = mouse_y * cells_y / (float)height; - int patch = (int)mx + cells_x*(int)my; + int patch = (int)mx + cells_x * (int)my; if(event->button == 1 && event->type == GDK_2BUTTON_PRESS) { // reset on double click if(patch < 0 || patch >= p->num_patches) return FALSE; @@ -1187,30 +1180,28 @@ static gboolean checker_button_press(GtkWidget *widget, GdkEventButton *event, { // right click: delete patch, move others up if(patch < 0 || patch >= p->num_patches) return FALSE; - memmove(p->target_L+patch, p->target_L+patch+1, sizeof(float)*(p->num_patches-1-patch)); - memmove(p->target_a+patch, p->target_a+patch+1, sizeof(float)*(p->num_patches-1-patch)); - memmove(p->target_b+patch, p->target_b+patch+1, sizeof(float)*(p->num_patches-1-patch)); - memmove(p->source_L+patch, p->source_L+patch+1, sizeof(float)*(p->num_patches-1-patch)); - memmove(p->source_a+patch, p->source_a+patch+1, sizeof(float)*(p->num_patches-1-patch)); - memmove(p->source_b+patch, p->source_b+patch+1, sizeof(float)*(p->num_patches-1-patch)); + memmove(p->target_L + patch, p->target_L + patch + 1, sizeof(float) * (p->num_patches - 1 - patch)); + memmove(p->target_a + patch, p->target_a + patch + 1, sizeof(float) * (p->num_patches - 1 - patch)); + memmove(p->target_b + patch, p->target_b + patch + 1, sizeof(float) * (p->num_patches - 1 - patch)); + memmove(p->source_L + patch, p->source_L + patch + 1, sizeof(float) * (p->num_patches - 1 - patch)); + memmove(p->source_a + patch, p->source_a + patch + 1, sizeof(float) * (p->num_patches - 1 - patch)); + memmove(p->source_b + patch, p->source_b + patch + 1, sizeof(float) * (p->num_patches - 1 - patch)); p->num_patches--; dt_dev_add_history_item(darktable.develop, self, TRUE); self->gui_update(self); return TRUE; } - else if((event->button == 1) && - ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK) && - (self->request_color_pick == DT_REQUEST_COLORPICK_MODULE)) + else if((event->button == 1) && ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK) + && (self->request_color_pick == DT_REQUEST_COLORPICK_MODULE)) { // shift-left while colour picking: replace source colour // if clicked outside the valid patches: add new one // color channels should be nonzero to avoid numerical issues - int new_color_valid = fabsf(self->picked_color[0]) > 1.e-3f && - fabsf(self->picked_color[1]) > 1.e-3f && - fabsf(self->picked_color[2]) > 1.e-3f; + int new_color_valid = fabsf(self->picked_color[0]) > 1.e-3f && fabsf(self->picked_color[1]) > 1.e-3f + && fabsf(self->picked_color[2]) > 1.e-3f; // check if the new color is very close to some color already in the colorchecker - for(int i=0;i<p->num_patches;++i) + for(int i = 0; i < p->num_patches; ++i) { float color[] = { p->source_L[i], p->source_a[i], p->source_b[i] }; if(fabsf(self->picked_color[0] - color[0]) < 1.e-3f && fabsf(self->picked_color[1] - color[1]) < 1.e-3f @@ -1232,13 +1223,12 @@ static gboolean checker_button_press(GtkWidget *widget, GdkEventButton *event, } return TRUE; } - if(patch >= p->num_patches) patch = p->num_patches-1; + if(patch >= p->num_patches) patch = p->num_patches - 1; dt_bauhaus_combobox_set(g->combobox_patch, patch); return FALSE; } -static gboolean checker_leave_notify(GtkWidget *widget, GdkEventCrossing *event, - gpointer user_data) +static gboolean checker_leave_notify(GtkWidget *widget, GdkEventCrossing *event, gpointer user_data) { return FALSE; // ? } @@ -1252,12 +1242,12 @@ void gui_init(struct dt_iop_module_t *self) self->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, DT_BAUHAUS_SPACE); // custom 24-patch widget in addition to combo box - g->area = dtgtk_drawing_area_new_with_aspect_ratio(4.0/6.0); + g->area = dtgtk_drawing_area_new_with_aspect_ratio(4.0 / 6.0); gtk_box_pack_start(GTK_BOX(self->widget), g->area, TRUE, TRUE, 0); gtk_widget_add_events(GTK_WIDGET(g->area), GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK); + | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK); g_signal_connect(G_OBJECT(g->area), "draw", G_CALLBACK(checker_draw), self); g_signal_connect(G_OBJECT(g->area), "button-press-event", G_CALLBACK(checker_button_press), self); g_signal_connect(G_OBJECT(g->area), "motion-notify-event", G_CALLBACK(checker_motion_notify), self); @@ -1269,7 +1259,7 @@ void gui_init(struct dt_iop_module_t *self) dt_bauhaus_widget_set_label(g->combobox_patch, NULL, _("patch")); gtk_widget_set_tooltip_text(g->combobox_patch, _("color checker patch")); char cboxentry[1024]; - for(int k=0;k<p->num_patches;k++) + for(int k = 0; k < p->num_patches; k++) { snprintf(cboxentry, sizeof(cboxentry), _("patch #%d"), k); dt_bauhaus_combobox_add(g->combobox_patch, cboxentry); @@ -1302,7 +1292,9 @@ void gui_init(struct dt_iop_module_t *self) g->absolute_target = 0; g->combobox_target = dt_bauhaus_combobox_new(self); dt_bauhaus_widget_set_label(g->combobox_target, 0, _("target color")); - gtk_widget_set_tooltip_text(g->combobox_target, _("control target color of the patches via relative offsets or via absolute Lab values")); + gtk_widget_set_tooltip_text( + g->combobox_target, + _("control target color of the patches via relative offsets or via absolute Lab values")); dt_bauhaus_combobox_add(g->combobox_target, _("relative")); dt_bauhaus_combobox_add(g->combobox_target, _("absolute")); diff --git a/src/iop/colorcontrast.c b/src/iop/colorcontrast.c index 80ed43e75b31..b949069259db 100644 --- a/src/iop/colorcontrast.c +++ b/src/iop/colorcontrast.c @@ -98,8 +98,8 @@ int groups() return IOP_GROUP_COLOR; } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 1 && new_version == 2) { @@ -218,8 +218,8 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c { for(int i = 0; i < roi_out->width; i++) { - _mm_stream_ps( - out, _mm_min_ps(max, _mm_max_ps(min, _mm_add_ps(offset, _mm_mul_ps(scale, _mm_load_ps(in)))))); + _mm_stream_ps(out, + _mm_min_ps(max, _mm_max_ps(min, _mm_add_ps(offset, _mm_mul_ps(scale, _mm_load_ps(in)))))); in += ch; out += ch; } @@ -303,7 +303,7 @@ void init(dt_iop_module_t *module) // our module is disabled by default module->default_enabled = 0; // we are pretty late in the pipe: - module->priority = 794; // module order created by iop_dependencies.py, do not edit! + module->priority = 797; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_colorcontrast_params_t); module->gui_data = NULL; // init defaults: diff --git a/src/iop/colorcorrection.c b/src/iop/colorcorrection.c index adae2902afe5..468c5579718f 100644 --- a/src/iop/colorcorrection.c +++ b/src/iop/colorcorrection.c @@ -226,7 +226,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_colorcorrection_params_t)); module->default_params = calloc(1, sizeof(dt_iop_colorcorrection_params_t)); module->default_enabled = 0; - module->priority = 720; // module order created by iop_dependencies.py, do not edit! + module->priority = 724; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_colorcorrection_params_t); module->gui_data = NULL; dt_iop_colorcorrection_params_t tmp = (dt_iop_colorcorrection_params_t){ 0., 0., 0., 0., 1.0 }; @@ -242,12 +242,9 @@ void cleanup(dt_iop_module_t *module) static void sat_callback(GtkWidget *slider, gpointer user_data); static gboolean dt_iop_colorcorrection_draw(GtkWidget *widget, cairo_t *cr, gpointer user_data); -static gboolean dt_iop_colorcorrection_motion_notify(GtkWidget *widget, GdkEventMotion *event, - gpointer user_data); -static gboolean dt_iop_colorcorrection_button_press(GtkWidget *widget, GdkEventButton *event, - gpointer user_data); -static gboolean dt_iop_colorcorrection_leave_notify(GtkWidget *widget, GdkEventCrossing *event, - gpointer user_data); +static gboolean dt_iop_colorcorrection_motion_notify(GtkWidget *widget, GdkEventMotion *event, gpointer user_data); +static gboolean dt_iop_colorcorrection_button_press(GtkWidget *widget, GdkEventButton *event, gpointer user_data); +static gboolean dt_iop_colorcorrection_leave_notify(GtkWidget *widget, GdkEventCrossing *event, gpointer user_data); static gboolean dt_iop_colorcorrection_scrolled(GtkWidget *widget, GdkEventScroll *event, gpointer user_data); static gboolean dt_iop_colorcorrection_key_press(GtkWidget *widget, GdkEventKey *event, gpointer user_data); @@ -267,16 +264,14 @@ void gui_init(struct dt_iop_module_t *self) gtk_widget_add_events(GTK_WIDGET(g->area), GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK - | GDK_SMOOTH_SCROLL_MASK | GDK_KEY_PRESS_MASK); + | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK + | GDK_KEY_PRESS_MASK); gtk_widget_set_can_focus(GTK_WIDGET(g->area), TRUE); g_signal_connect(G_OBJECT(g->area), "draw", G_CALLBACK(dt_iop_colorcorrection_draw), self); - g_signal_connect(G_OBJECT(g->area), "button-press-event", G_CALLBACK(dt_iop_colorcorrection_button_press), - self); + g_signal_connect(G_OBJECT(g->area), "button-press-event", G_CALLBACK(dt_iop_colorcorrection_button_press), self); g_signal_connect(G_OBJECT(g->area), "motion-notify-event", G_CALLBACK(dt_iop_colorcorrection_motion_notify), self); - g_signal_connect(G_OBJECT(g->area), "leave-notify-event", G_CALLBACK(dt_iop_colorcorrection_leave_notify), - self); + g_signal_connect(G_OBJECT(g->area), "leave-notify-event", G_CALLBACK(dt_iop_colorcorrection_leave_notify), self); g_signal_connect(G_OBJECT(g->area), "scroll-event", G_CALLBACK(dt_iop_colorcorrection_scrolled), self); g_signal_connect(G_OBJECT(g->area), "key-press-event", G_CALLBACK(dt_iop_colorcorrection_key_press), self); @@ -349,8 +344,7 @@ static gboolean dt_iop_colorcorrection_draw(GtkWidget *widget, cairo_t *crf, gpo // dt_iop_Lab_to_sRGB(Lab, rgb, 0, 0, 1.0, 1, 1); cairo_set_source_rgb(cr, rgb[0], rgb[1], rgb[2]); cairo_rectangle(cr, width * i / (float)cells, height * j / (float)cells, - width / (float)cells - DT_PIXEL_APPLY_DPI(1), - height / (float)cells - DT_PIXEL_APPLY_DPI(1)); + width / (float)cells - DT_PIXEL_APPLY_DPI(1), height / (float)cells - DT_PIXEL_APPLY_DPI(1)); cairo_fill(cr); } cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT); @@ -386,8 +380,7 @@ static gboolean dt_iop_colorcorrection_draw(GtkWidget *widget, cairo_t *crf, gpo return TRUE; } -static gboolean dt_iop_colorcorrection_motion_notify(GtkWidget *widget, GdkEventMotion *event, - gpointer user_data) +static gboolean dt_iop_colorcorrection_motion_notify(GtkWidget *widget, GdkEventMotion *event, gpointer user_data) { dt_iop_module_t *self = (dt_iop_module_t *)user_data; dt_iop_colorcorrection_gui_data_t *g = (dt_iop_colorcorrection_gui_data_t *)self->gui_data; @@ -431,8 +424,7 @@ static gboolean dt_iop_colorcorrection_motion_notify(GtkWidget *widget, GdkEvent return TRUE; } -static gboolean dt_iop_colorcorrection_button_press(GtkWidget *widget, GdkEventButton *event, - gpointer user_data) +static gboolean dt_iop_colorcorrection_button_press(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { if(event->button == 1 && event->type == GDK_2BUTTON_PRESS) { @@ -462,8 +454,7 @@ static gboolean dt_iop_colorcorrection_button_press(GtkWidget *widget, GdkEventB return FALSE; } -static gboolean dt_iop_colorcorrection_leave_notify(GtkWidget *widget, GdkEventCrossing *event, - gpointer user_data) +static gboolean dt_iop_colorcorrection_leave_notify(GtkWidget *widget, GdkEventCrossing *event, gpointer user_data) { dt_iop_module_t *self = (dt_iop_module_t *)user_data; gtk_widget_queue_draw(self->widget); @@ -479,9 +470,9 @@ static gboolean dt_iop_colorcorrection_scrolled(GtkWidget *widget, GdkEventScrol gdouble delta_y; if(dt_gui_get_scroll_deltas(event, NULL, &delta_y)) { - p->saturation = CLAMP(p->saturation - 0.1 * delta_y, -3.0, 3.0); - dt_bauhaus_slider_set(g->slider, p->saturation); - gtk_widget_queue_draw(widget); + p->saturation = CLAMP(p->saturation - 0.1 * delta_y, -3.0, 3.0); + dt_bauhaus_slider_set(g->slider, p->saturation); + gtk_widget_queue_draw(widget); } return TRUE; diff --git a/src/iop/colorin.c b/src/iop/colorin.c index 962daf03205c..f5347fc169d5 100644 --- a/src/iop/colorin.c +++ b/src/iop/colorin.c @@ -121,8 +121,8 @@ int flags() return IOP_FLAGS_ALLOW_TILING | IOP_FLAGS_ONE_INSTANCE; } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 1 && new_version == 4) { @@ -282,8 +282,7 @@ int legacy_params(dt_iop_module_t *self, const void *const old_params, const int void init_global(dt_iop_module_so_t *module) { const int program = 2; // basic.cl, from programs.conf - dt_iop_colorin_global_data_t *gd - = (dt_iop_colorin_global_data_t *)malloc(sizeof(dt_iop_colorin_global_data_t)); + dt_iop_colorin_global_data_t *gd = (dt_iop_colorin_global_data_t *)malloc(sizeof(dt_iop_colorin_global_data_t)); module->data = gd; gd->kernel_colorin_unbound = dt_opencl_create_kernel(program, "colorin_unbound"); gd->kernel_colorin_clipping = dt_opencl_create_kernel(program, "colorin_clipping"); @@ -338,7 +337,8 @@ static void profile_changed(GtkWidget *widget, gpointer user_data) prof = g_list_next(prof); } // should really never happen. - fprintf(stderr, "[colorin] color profile %s seems to have disappeared!\n", dt_colorspaces_get_name(p->type, p->filename)); + fprintf(stderr, "[colorin] color profile %s seems to have disappeared!\n", + dt_colorspaces_get_name(p->type, p->filename)); } @@ -413,8 +413,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m if(dev_g == NULL) goto error; dev_b = dt_opencl_copy_host_to_device(devid, d->lut[2], 256, 256, sizeof(float)); if(dev_b == NULL) goto error; - dev_coeffs - = dt_opencl_copy_host_to_device_constant(devid, sizeof(float) * 3 * 3, (float *)d->unbounded_coeffs); + dev_coeffs = dt_opencl_copy_host_to_device_constant(devid, sizeof(float) * 3 * 3, (float *)d->unbounded_coeffs); if(dev_coeffs == NULL) goto error; dt_opencl_set_kernel_arg(devid, kernel, 0, sizeof(cl_mem), (void *)&dev_in); dt_opencl_set_kernel_arg(devid, kernel, 1, sizeof(cl_mem), (void *)&dev_out); @@ -478,8 +477,8 @@ static void process_cmatrix_bm(struct dt_iop_module_t *self, dt_dev_pixelpipe_io const int ch = piece->colors; const int clipping = (d->nrgb != NULL); - // fprintf(stderr, "Using cmatrix codepath\n"); - // only color matrix. use our optimized fast path! +// fprintf(stderr, "Using cmatrix codepath\n"); +// only color matrix. use our optimized fast path! #ifdef _OPENMP #pragma omp parallel for default(none) schedule(static) #endif @@ -863,7 +862,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const process_lcms2(self, piece, ivoid, ovoid, roi_in, roi_out); } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #if defined(__SSE2__) @@ -1245,7 +1245,8 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c process_sse2_lcms2(self, piece, ivoid, ovoid, roi_in, roi_out); } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #endif @@ -1347,20 +1348,26 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix if(type == DT_COLORSPACE_ENHANCED_MATRIX) { d->input = dt_colorspaces_create_darktable_profile(pipe->image.camera_makermodel); - if(!d->input) type = DT_COLORSPACE_EMBEDDED_ICC; - else d->clear_input = 1; + if(!d->input) + type = DT_COLORSPACE_EMBEDDED_ICC; + else + d->clear_input = 1; } if(type == DT_COLORSPACE_VENDOR_MATRIX) { d->input = dt_colorspaces_create_vendor_profile(pipe->image.camera_makermodel); - if(!d->input) type = DT_COLORSPACE_EMBEDDED_ICC; - else d->clear_input = 1; + if(!d->input) + type = DT_COLORSPACE_EMBEDDED_ICC; + else + d->clear_input = 1; } if(type == DT_COLORSPACE_ALTERNATE_MATRIX) { d->input = dt_colorspaces_create_alternate_profile(pipe->image.camera_makermodel); - if(!d->input) type = DT_COLORSPACE_EMBEDDED_ICC; - else d->clear_input = 1; + if(!d->input) + type = DT_COLORSPACE_EMBEDDED_ICC; + else + d->clear_input = 1; } if(type == DT_COLORSPACE_EMBEDDED_ICC) { @@ -1393,7 +1400,7 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix cam_xyz[0] = NAN; // Use the legacy name if it has been set to honor the partial matching matrices of low-end Canons - if (pipe->image.camera_legacy_makermodel[0]) + if(pipe->image.camera_legacy_makermodel[0]) dt_dcraw_adobe_coeff(pipe->image.camera_legacy_makermodel, (float(*)[12])cam_xyz); else dt_dcraw_adobe_coeff(pipe->image.camera_makermodel, (float(*)[12])cam_xyz); @@ -1416,7 +1423,8 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix if(!d->input) { - const dt_colorspaces_color_profile_t *profile = dt_colorspaces_get_profile(type, p->filename, DT_PROFILE_DIRECTION_IN); + const dt_colorspaces_color_profile_t *profile + = dt_colorspaces_get_profile(type, p->filename, DT_PROFILE_DIRECTION_IN); if(profile) d->input = profile->profile; } @@ -1455,9 +1463,7 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix default: // fprintf("%.*s", 4, input_color_space) doesn't work, it prints the string backwards :( fprintf(stderr, "[colorin] input profile color space `%c%c%c%c' not supported\n", - (char)(input_color_space>>24), - (char)(input_color_space>>16), - (char)(input_color_space>>8), + (char)(input_color_space >> 24), (char)(input_color_space >> 16), (char)(input_color_space >> 8), (char)(input_color_space)); input_format = TYPE_RGBA_FLT; // this will fail later, triggering the linear rec709 fallback } @@ -1613,8 +1619,8 @@ void gui_update(struct dt_iop_module_t *self) while(prof) { dt_colorspaces_color_profile_t *pp = (dt_colorspaces_color_profile_t *)prof->data; - if(pp->in_pos > -1 && - pp->type == p->type && (pp->type != DT_COLORSPACE_FILE || !strcmp(pp->filename, p->filename))) + if(pp->in_pos > -1 && pp->type == p->type + && (pp->type != DT_COLORSPACE_FILE || !strcmp(pp->filename, p->filename))) { dt_bauhaus_combobox_set(g->profile_combobox, pp->in_pos + g->n_image_profiles); return; @@ -1624,17 +1630,18 @@ void gui_update(struct dt_iop_module_t *self) dt_bauhaus_combobox_set(g->profile_combobox, 0); if(p->type != DT_COLORSPACE_ENHANCED_MATRIX) - fprintf(stderr, "[colorin] could not find requested profile `%s'!\n", dt_colorspaces_get_name(p->type, p->filename)); + fprintf(stderr, "[colorin] could not find requested profile `%s'!\n", + dt_colorspaces_get_name(p->type, p->filename)); } // FIXME: update the gui when we add/remove the eprofile or ematrix void reload_defaults(dt_iop_module_t *module) { - dt_iop_colorin_params_t tmp = (dt_iop_colorin_params_t){ .type = DT_COLORSPACE_ENHANCED_MATRIX, - .filename = "", - .intent = DT_INTENT_PERCEPTUAL, - .normalize = DT_NORMALIZE_OFF, - .blue_mapping = 0 }; + dt_iop_colorin_params_t tmp = (dt_iop_colorin_params_t){.type = DT_COLORSPACE_ENHANCED_MATRIX, + .filename = "", + .intent = DT_INTENT_PERCEPTUAL, + .normalize = DT_NORMALIZE_OFF, + .blue_mapping = 0 }; // we might be called from presets update infrastructure => there is no image if(!module->dev) goto end; @@ -1710,7 +1717,7 @@ void init(dt_iop_module_t *module) module->default_params = calloc(1, sizeof(dt_iop_colorin_params_t)); module->params_size = sizeof(dt_iop_colorin_params_t); module->gui_data = NULL; - module->priority = 352; // module order created by iop_dependencies.py, do not edit! + module->priority = 362; // module order created by iop_dependencies.py, do not edit! module->hide_enable_button = 1; module->default_enabled = 1; } @@ -1759,7 +1766,7 @@ static void update_profile_list(dt_iop_module_t *self) cam_xyz[0] = NAN; // Use the legacy name if it has been set to honor the partial matching matrices of low-end Canons - if (self->dev->image_storage.camera_legacy_makermodel[0]) + if(self->dev->image_storage.camera_legacy_makermodel[0]) dt_dcraw_adobe_coeff(self->dev->image_storage.camera_legacy_makermodel, (float(*)[12])cam_xyz); else dt_dcraw_adobe_coeff(self->dev->image_storage.camera_makermodel, (float(*)[12])cam_xyz); diff --git a/src/iop/colorize.c b/src/iop/colorize.c index a3796255c544..00bb7fe9bd15 100644 --- a/src/iop/colorize.c +++ b/src/iop/colorize.c @@ -59,7 +59,7 @@ typedef struct dt_iop_colorize_params_t typedef struct dt_iop_colorize_gui_data_t { - GtkWidget *scale1, *scale2; // lightness, source_lightnessmix + GtkWidget *scale1, *scale2; // lightness, source_lightnessmix GtkWidget *gslider1, *gslider2; // hue, saturation } dt_iop_colorize_gui_data_t; @@ -92,8 +92,8 @@ int groups() return IOP_GROUP_EFFECT; } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 1 && new_version == 2) { @@ -398,7 +398,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_colorize_params_t)); module->default_params = calloc(1, sizeof(dt_iop_colorize_params_t)); module->default_enabled = 0; - module->priority = 470; // module order created by iop_dependencies.py, do not edit! + module->priority = 478; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_colorize_params_t); module->gui_data = NULL; dt_iop_colorize_params_t tmp = (dt_iop_colorize_params_t){ 0, 0.5, 50, 50, module->version() }; diff --git a/src/iop/colormapping.c b/src/iop/colormapping.c index 05ea32104d2e..94350e93f5ed 100644 --- a/src/iop/colormapping.c +++ b/src/iop/colormapping.c @@ -182,8 +182,7 @@ static void capture_histogram(const float *col, const int width, const int heigh // accumulated start distribution of G1 G2 for(int k = 1; k < HISTN; k++) hist[k] += hist[k - 1]; - for(int k = 0; k < HISTN; k++) - hist[k] = (int)CLAMP(hist[k] * (HISTN / (float)hist[HISTN - 1]), 0, HISTN - 1); + for(int k = 0; k < HISTN; k++) hist[k] = (int)CLAMP(hist[k] * (HISTN / (float)hist[HISTN - 1]), 0, HISTN - 1); // for(int i=0;i<100;i++) printf("#[%d] %d \n", (int)CLAMP(HISTN*i/100.0, 0, HISTN-1), // hist[(int)CLAMP(HISTN*i/100.0, 0, HISTN-1)]); } @@ -266,8 +265,7 @@ static void get_clusters(const float *col, const int n, float mean[n][2], float if(dist2 < mdist) mdist = dist2; } if(mdist < 1.0e-6f) - for(int k = 0; k < n; k++) - weight[k] = weight[k] < 0.0f ? 1.0f : 0.0f; // correction in case of direct hits + for(int k = 0; k < n; k++) weight[k] = weight[k] < 0.0f ? 1.0f : 0.0f; // correction in case of direct hits float sum = 0.0f; for(int k = 0; k < n; k++) sum += weight[k]; if(sum > 0.0f) @@ -298,8 +296,8 @@ static void kmeans(const float *col, const int width, const int height, const in const int nit = 40; // number of iterations const int samples = width * height * 0.2; // samples: only a fraction of the buffer. - float(*const mean)[2] = malloc(2 * n * sizeof(float)); - float(*const var)[2] = malloc(2 * n * sizeof(float)); + float (*const mean)[2] = malloc(2 * n * sizeof(float)); + float (*const var)[2] = malloc(2 * n * sizeof(float)); int *const cnt = malloc(n * sizeof(int)); int count; @@ -477,17 +475,17 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const // get mapping from input clusters to target clusters int *const mapio = malloc(data->n * sizeof(int)); - get_cluster_mapping(data->n, data->target_mean, data->target_weight, data->source_mean, - data->source_weight, dominance, mapio); + get_cluster_mapping(data->n, data->target_mean, data->target_weight, data->source_mean, data->source_weight, + dominance, mapio); - float(*const var_ratio)[2] = malloc(2 * data->n * sizeof(float)); + float (*const var_ratio)[2] = malloc(2 * data->n * sizeof(float)); for(int i = 0; i < data->n; i++) { - var_ratio[i][0] - = (data->target_var[i][0] > 0.0f) ? data->source_var[mapio[i]][0] / data->target_var[i][0] : 0.0f; - var_ratio[i][1] - = (data->target_var[i][1] > 0.0f) ? data->source_var[mapio[i]][1] / data->target_var[i][1] : 0.0f; + var_ratio[i][0] = (data->target_var[i][0] > 0.0f) ? data->source_var[mapio[i]][0] / data->target_var[i][0] + : 0.0f; + var_ratio[i][1] = (data->target_var[i][1] > 0.0f) ? data->source_var[mapio[i]][1] / data->target_var[i][1] + : 0.0f; } // first get delta L of equalized L minus original image L, scaled to fit into [0 .. 100] @@ -502,7 +500,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const const float L = in[j]; out[j] = 0.5f * ((L * (1.0f - equalization) + data->source_ihist[data->target_hist[(int)CLAMP( - HISTN * L / 100.0f, 0.0f, (float)HISTN - 1.0f)]] * equalization) - L) + 50.0f; + HISTN * L / 100.0f, 0.0f, (float)HISTN - 1.0f)]] * equalization) - L) + + 50.0f; out[j] = CLAMP(out[j], 0.0f, 100.0f); j += ch; } @@ -546,10 +545,10 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const out[j + 1] = out[j + 2] = 0.0f; for(int c = 0; c < data->n; c++) { - out[j + 1] += weight[c] * ((Lab[1] - data->target_mean[c][0]) * var_ratio[c][0] - + data->source_mean[mapio[c]][0]); - out[j + 2] += weight[c] * ((Lab[2] - data->target_mean[c][1]) * var_ratio[c][1] - + data->source_mean[mapio[c]][1]); + out[j + 1] += weight[c] + * ((Lab[1] - data->target_mean[c][0]) * var_ratio[c][0] + data->source_mean[mapio[c]][0]); + out[j + 2] += weight[c] + * ((Lab[2] - data->target_mean[c][1]) * var_ratio[c][1] + data->source_mean[mapio[c]][1]); } out[j + 3] = in[j + 3]; j += ch; @@ -611,8 +610,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m g->height = height; g->ch = ch; - if(g->buffer) - err = dt_opencl_copy_device_to_host(devid, g->buffer, dev_in, width, height, ch * sizeof(float)); + if(g->buffer) err = dt_opencl_copy_device_to_host(devid, g->buffer, dev_in, width, height, ch * sizeof(float)); dt_pthread_mutex_unlock(&g->lock); @@ -625,16 +623,16 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m { // get mapping from input clusters to target clusters int mapio[MAXN]; - get_cluster_mapping(data->n, data->target_mean, data->target_weight, data->source_mean, - data->source_weight, dominance, mapio); + get_cluster_mapping(data->n, data->target_mean, data->target_weight, data->source_mean, data->source_weight, + dominance, mapio); float var_ratio[MAXN][2]; for(int i = 0; i < data->n; i++) { - var_ratio[i][0] - = (data->target_var[i][0] > 0.0f) ? data->source_var[mapio[i]][0] / data->target_var[i][0] : 0.0f; - var_ratio[i][1] - = (data->target_var[i][1] > 0.0f) ? data->source_var[mapio[i]][1] / data->target_var[i][1] : 0.0f; + var_ratio[i][0] = (data->target_var[i][0] > 0.0f) ? data->source_var[mapio[i]][0] / data->target_var[i][0] + : 0.0f; + var_ratio[i][1] = (data->target_var[i][1] > 0.0f) ? data->source_var[mapio[i]][1] / data->target_var[i][1] + : 0.0f; } dev_tmp = dt_opencl_alloc_device(devid, width, height, 4 * sizeof(float)); @@ -643,16 +641,13 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m dev_target_hist = dt_opencl_copy_host_to_device_constant(devid, sizeof(int) * HISTN, data->target_hist); if(dev_target_hist == NULL) goto error; - dev_source_ihist - = dt_opencl_copy_host_to_device_constant(devid, sizeof(float) * HISTN, data->source_ihist); + dev_source_ihist = dt_opencl_copy_host_to_device_constant(devid, sizeof(float) * HISTN, data->source_ihist); if(dev_source_ihist == NULL) goto error; - dev_target_mean - = dt_opencl_copy_host_to_device_constant(devid, sizeof(float) * MAXN * 2, data->target_mean); + dev_target_mean = dt_opencl_copy_host_to_device_constant(devid, sizeof(float) * MAXN * 2, data->target_mean); if(dev_target_mean == NULL) goto error; - dev_source_mean - = dt_opencl_copy_host_to_device_constant(devid, sizeof(float) * MAXN * 2, data->source_mean); + dev_source_mean = dt_opencl_copy_host_to_device_constant(devid, sizeof(float) * MAXN * 2, data->source_mean); if(dev_source_mean == NULL) goto error; dev_var_ratio = dt_opencl_copy_host_to_device_constant(devid, sizeof(float) * MAXN * 2, var_ratio); @@ -741,8 +736,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling) + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling) { const float scale = piece->iscale / roi_in->scale; const float sigma_s = 50.0f / scale; @@ -755,8 +749,7 @@ void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t const size_t basebuffer = width * height * channels * sizeof(float); tiling->factor = 3.0f + (float)dt_bilateral_memory_use(width, height, sigma_s, sigma_r) / basebuffer; - tiling->maxbuf - = fmax(1.0f, (float)dt_bilateral_singlebuffer_size(width, height, sigma_s, sigma_r) / basebuffer); + tiling->maxbuf = fmax(1.0f, (float)dt_bilateral_singlebuffer_size(width, height, sigma_s, sigma_r) / basebuffer); tiling->overhead = 0; tiling->overlap = ceilf(4 * sigma_s); tiling->xalign = 1; @@ -868,7 +861,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_colormapping_params_t)); module->default_params = calloc(1, sizeof(dt_iop_colormapping_params_t)); module->default_enabled = 0; - module->priority = 499; // module order created by iop_dependencies.py, do not edit! + module->priority = 507; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_colormapping_params_t); module->gui_data = NULL; } @@ -901,7 +894,7 @@ void cleanup_global(dt_iop_module_so_t *module) void reload_defaults(dt_iop_module_t *module) { dt_iop_colormapping_params_t tmp - = (dt_iop_colormapping_params_t){ .flag = NEUTRAL, .n = 3, .dominance = 100.0f, .equalization = 50.0f }; + = (dt_iop_colormapping_params_t){.flag = NEUTRAL, .n = 3, .dominance = 100.0f, .equalization = 50.0f }; // we might be called from presets update infrastructure => there is no image if(!module->dev) goto end; @@ -969,7 +962,7 @@ static gboolean cluster_preview_draw(GtkWidget *widget, cairo_t *crf, dt_iop_mod // draw 9x9 grid showing mean and variance of this cluster. double rgb[3] = { 0.5, 0.5, 0.5 }; cmsCIELab Lab; - Lab.L = 5.0; // 53.390011; + Lab.L = 5.0; // 53.390011; Lab.a = (mean[cl][0] + i * var[cl][0]); // / Lab.L; Lab.b = (mean[cl][1] + j * var[cl][1]); // / Lab.L; Lab.L = 53.390011; @@ -1129,7 +1122,8 @@ void gui_init(struct dt_iop_module_t *self) g->clusters = dt_bauhaus_slider_new_with_range(self, 1.0f, 5.0f, 1., p->n, 0); dt_bauhaus_widget_set_label(g->clusters, NULL, _("number of clusters")); dt_bauhaus_slider_set_format(g->clusters, "%.0f"); - gtk_widget_set_tooltip_text(g->clusters, _("number of clusters to find in image. value change resets all clusters")); + gtk_widget_set_tooltip_text(g->clusters, + _("number of clusters to find in image. value change resets all clusters")); gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(g->clusters), TRUE, TRUE, 0); g_signal_connect(G_OBJECT(g->clusters), "value-changed", G_CALLBACK(clusters_changed), (gpointer)self); diff --git a/src/iop/colorout.c b/src/iop/colorout.c index 4bd7b28450e6..2f7cf78846df 100644 --- a/src/iop/colorout.c +++ b/src/iop/colorout.c @@ -89,8 +89,8 @@ int flags() return IOP_FLAGS_ALLOW_TILING | IOP_FLAGS_ONE_INSTANCE; } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { /* if(old_version == 1 && new_version == 2) { @@ -187,7 +187,8 @@ static void output_profile_changed(GtkWidget *widget, gpointer user_data) } } - fprintf(stderr, "[colorout] color profile %s seems to have disappeared!\n", dt_colorspaces_get_name(p->type, p->filename)); + fprintf(stderr, "[colorout] color profile %s seems to have disappeared!\n", + dt_colorspaces_get_name(p->type, p->filename)); } static void _signal_profile_changed(gpointer instance, gpointer user_data) @@ -242,8 +243,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m if(dev_g == NULL) goto error; dev_b = dt_opencl_copy_host_to_device(devid, d->lut[2], 256, 256, sizeof(float)); if(dev_b == NULL) goto error; - dev_coeffs - = dt_opencl_copy_host_to_device_constant(devid, sizeof(float) * 3 * 3, (float *)d->unbounded_coeffs); + dev_coeffs = dt_opencl_copy_host_to_device_constant(devid, sizeof(float) * 3 * 3, (float *)d->unbounded_coeffs); if(dev_coeffs == NULL) goto error; dt_opencl_set_kernel_arg(devid, gd->kernel_colorout, 0, sizeof(cl_mem), (void *)&dev_in); dt_opencl_set_kernel_arg(devid, gd->kernel_colorout, 1, sizeof(cl_mem), (void *)&dev_out); @@ -276,8 +276,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m static void process_fastpath_apply_tonecurves(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid, - const dt_iop_roi_t *const roi_in, - const dt_iop_roi_t *const roi_out) + const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) { const dt_iop_colorout_data_t *const d = (dt_iop_colorout_data_t *)piece->data; const int ch = piece->colors; @@ -332,7 +331,7 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const if(d->type == DT_COLORSPACE_LAB) { - memcpy(ovoid, ivoid, sizeof(float)*4*roi_out->width*roi_out->height); + memcpy(ovoid, ivoid, sizeof(float) * 4 * roi_out->width * roi_out->height); } else if(!isnan(d->cmatrix[0])) { @@ -389,7 +388,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const } } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #if defined(__SSE__) @@ -402,7 +402,7 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c if(d->type == DT_COLORSPACE_LAB) { - memcpy(ovoid, ivoid, sizeof(float)*4*roi_out->width*roi_out->height); + memcpy(ovoid, ivoid, sizeof(float) * 4 * roi_out->width * roi_out->height); } else if(!isnan(d->cmatrix[0])) { @@ -423,10 +423,9 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c for(int i = 0; i < roi_out->width; i++, in += ch, out += ch) { const __m128 xyz = dt_Lab_to_XYZ_sse2(_mm_load_ps(in)); - const __m128 t - = _mm_add_ps(_mm_mul_ps(m0, _mm_shuffle_ps(xyz, xyz, _MM_SHUFFLE(0, 0, 0, 0))), - _mm_add_ps(_mm_mul_ps(m1, _mm_shuffle_ps(xyz, xyz, _MM_SHUFFLE(1, 1, 1, 1))), - _mm_mul_ps(m2, _mm_shuffle_ps(xyz, xyz, _MM_SHUFFLE(2, 2, 2, 2))))); + const __m128 t = _mm_add_ps(_mm_mul_ps(m0, _mm_shuffle_ps(xyz, xyz, _MM_SHUFFLE(0, 0, 0, 0))), + _mm_add_ps(_mm_mul_ps(m1, _mm_shuffle_ps(xyz, xyz, _MM_SHUFFLE(1, 1, 1, 1))), + _mm_mul_ps(m2, _mm_shuffle_ps(xyz, xyz, _MM_SHUFFLE(2, 2, 2, 2))))); _mm_stream_ps(out, t); } @@ -459,8 +458,7 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c ingamut = _mm_or_ps(_mm_unpacklo_ps(ingamut, ingamut), _mm_unpackhi_ps(ingamut, ingamut)); ingamut = _mm_or_ps(_mm_unpacklo_ps(ingamut, ingamut), _mm_unpackhi_ps(ingamut, ingamut)); - const __m128 result - = _mm_or_ps(_mm_and_ps(ingamut, outofgamutpixel), _mm_andnot_ps(ingamut, pixel)); + const __m128 result = _mm_or_ps(_mm_and_ps(ingamut, outofgamutpixel), _mm_andnot_ps(ingamut, pixel)); _mm_stream_ps(out, result); } } @@ -468,7 +466,8 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c _mm_sfence(); } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #endif @@ -482,8 +481,7 @@ static cmsHPROFILE _make_clipping_profile(cmsHPROFILE profile) { char *data = malloc(size); - if(cmsSaveProfileToMem(old_profile, data, &size)) - profile = cmsOpenProfileFromMem(data, size); + if(cmsSaveProfileToMem(old_profile, data, &size)) profile = cmsOpenProfileFromMem(data, size); free(data); } @@ -555,8 +553,7 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix // when the output type is Lab then process is a nop, so we can avoid creating a transform // and the subsequent error messages d->type = out_type; - if(out_type == DT_COLORSPACE_LAB) - return; + if(out_type == DT_COLORSPACE_LAB) return; /* * Setup transform flags @@ -566,8 +563,8 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix /* creating output profile */ if(out_type == DT_COLORSPACE_DISPLAY) pthread_rwlock_rdlock(&darktable.color_profiles->xprofile_lock); - const dt_colorspaces_color_profile_t *out_profile - = dt_colorspaces_get_profile(out_type, out_filename, DT_PROFILE_DIRECTION_OUT | DT_PROFILE_DIRECTION_DISPLAY); + const dt_colorspaces_color_profile_t *out_profile = dt_colorspaces_get_profile( + out_type, out_filename, DT_PROFILE_DIRECTION_OUT | DT_PROFILE_DIRECTION_DISPLAY); if(out_profile) { output = out_profile->profile; @@ -630,8 +627,8 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix { d->cmatrix[0] = NAN; piece->process_cl_ready = 0; - d->xform = cmsCreateProofingTransform(Lab, TYPE_LabA_FLT, output, output_format, softproof, - out_intent, INTENT_RELATIVE_COLORIMETRIC, transformFlags); + d->xform = cmsCreateProofingTransform(Lab, TYPE_LabA_FLT, output, output_format, softproof, out_intent, + INTENT_RELATIVE_COLORIMETRIC, transformFlags); } // user selected a non-supported output profile, check that: @@ -641,14 +638,14 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix fprintf(stderr, "unsupported output profile `%s' has been replaced by sRGB!\n", out_profile->name); output = dt_colorspaces_get_profile(DT_COLORSPACE_SRGB, "", DT_PROFILE_DIRECTION_OUT)->profile; if(d->mode != DT_PROFILE_NORMAL - || dt_colorspaces_get_matrix_from_output_profile(output, d->cmatrix, d->lut[0], d->lut[1], - d->lut[2], LUT_SAMPLES, out_intent)) + || dt_colorspaces_get_matrix_from_output_profile(output, d->cmatrix, d->lut[0], d->lut[1], d->lut[2], + LUT_SAMPLES, out_intent)) { d->cmatrix[0] = NAN; piece->process_cl_ready = 0; - d->xform = cmsCreateProofingTransform(Lab, TYPE_LabA_FLT, output, output_format, softproof, - out_intent, INTENT_RELATIVE_COLORIMETRIC, transformFlags); + d->xform = cmsCreateProofingTransform(Lab, TYPE_LabA_FLT, output, output_format, softproof, out_intent, + INTENT_RELATIVE_COLORIMETRIC, transformFlags); } } @@ -674,7 +671,6 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix // softproof is never the original but always a copy that went through _make_clipping_profile() dt_colorspaces_cleanup_profile(softproof); - } void init_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece) @@ -708,8 +704,8 @@ void gui_update(struct dt_iop_module_t *self) for(GList *iter = darktable.color_profiles->profiles; iter; iter = g_list_next(iter)) { dt_colorspaces_color_profile_t *pp = (dt_colorspaces_color_profile_t *)iter->data; - if(pp->out_pos > -1 && - p->type == pp->type && (p->type != DT_COLORSPACE_FILE || !strcmp(p->filename, pp->filename))) + if(pp->out_pos > -1 && p->type == pp->type + && (p->type != DT_COLORSPACE_FILE || !strcmp(p->filename, pp->filename))) { dt_bauhaus_combobox_set(g->output_profile, pp->out_pos); return; @@ -717,7 +713,8 @@ void gui_update(struct dt_iop_module_t *self) } dt_bauhaus_combobox_set(g->output_profile, 0); - fprintf(stderr, "[colorout] could not find requested profile `%s'!\n", dt_colorspaces_get_name(p->type, p->filename)); + fprintf(stderr, "[colorout] could not find requested profile `%s'!\n", + dt_colorspaces_get_name(p->type, p->filename)); } void init(dt_iop_module_t *module) @@ -726,10 +723,10 @@ void init(dt_iop_module_t *module) module->default_params = calloc(1, sizeof(dt_iop_colorout_params_t)); module->params_size = sizeof(dt_iop_colorout_params_t); module->gui_data = NULL; - module->priority = 808; // module order created by iop_dependencies.py, do not edit! + module->priority = 811; // module order created by iop_dependencies.py, do not edit! module->hide_enable_button = 1; module->default_enabled = 1; - dt_iop_colorout_params_t tmp = (dt_iop_colorout_params_t){ DT_COLORSPACE_SRGB, "", DT_INTENT_PERCEPTUAL}; + dt_iop_colorout_params_t tmp = (dt_iop_colorout_params_t){ DT_COLORSPACE_SRGB, "", DT_INTENT_PERCEPTUAL }; memcpy(module->params, &tmp, sizeof(dt_iop_colorout_params_t)); memcpy(module->default_params, &tmp, sizeof(dt_iop_colorout_params_t)); } @@ -802,14 +799,15 @@ void gui_init(struct dt_iop_module_t *self) gtk_widget_set_tooltip_text(g->output_profile, tooltip); g_signal_connect(G_OBJECT(g->output_intent), "value-changed", G_CALLBACK(intent_changed), (gpointer)self); - g_signal_connect(G_OBJECT(g->output_profile), "value-changed", G_CALLBACK(output_profile_changed), (gpointer)self); + g_signal_connect(G_OBJECT(g->output_profile), "value-changed", G_CALLBACK(output_profile_changed), + (gpointer)self); // reload the profiles when the display or softproof profile changed! dt_control_signal_connect(darktable.signals, DT_SIGNAL_CONTROL_PROFILE_CHANGED, G_CALLBACK(_signal_profile_changed), self->dev); // update the gui when the preferences changed (i.e. show intent when using lcms2) - dt_control_signal_connect(darktable.signals, DT_SIGNAL_PREFERENCES_CHANGE, - G_CALLBACK(_preference_changed), (gpointer)self); + dt_control_signal_connect(darktable.signals, DT_SIGNAL_PREFERENCES_CHANGE, G_CALLBACK(_preference_changed), + (gpointer)self); } void gui_cleanup(struct dt_iop_module_t *self) diff --git a/src/iop/colorreconstruction.c b/src/iop/colorreconstruction.c index 47c83465111a..08a2af7ebfc1 100644 --- a/src/iop/colorreconstruction.c +++ b/src/iop/colorreconstruction.c @@ -46,9 +46,9 @@ DT_MODULE_INTROSPECTION(3, dt_iop_colorreconstruct_params_t) typedef enum dt_iop_colorreconstruct_precedence_t { - COLORRECONSTRUCT_PRECEDENCE_NONE, // same weighting factor for all pixels - COLORRECONSTRUCT_PRECEDENCE_CHROMA, // use chromaticy as weighting factor -> prefers saturated colors - COLORRECONSTRUCT_PRECEDENCE_HUE // use a specific hue as weighting factor + COLORRECONSTRUCT_PRECEDENCE_NONE, // same weighting factor for all pixels + COLORRECONSTRUCT_PRECEDENCE_CHROMA, // use chromaticy as weighting factor -> prefers saturated colors + COLORRECONSTRUCT_PRECEDENCE_HUE // use a specific hue as weighting factor } dt_iop_colorreconstruct_precedence_t; typedef struct dt_iop_colorreconstruct_params1_t @@ -139,8 +139,8 @@ int groups() return IOP_GROUP_BASIC; } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 1 && new_version == 3) { @@ -214,16 +214,16 @@ static inline float hue_conversion(const float HSL_Hue) } -static inline void image_to_grid(const dt_iop_colorreconstruct_bilateral_t *const b, const float i, const float j, const float L, float *x, - float *y, float *z) +static inline void image_to_grid(const dt_iop_colorreconstruct_bilateral_t *const b, const float i, const float j, + const float L, float *x, float *y, float *z) { *x = CLAMPS(i / b->sigma_s, 0, b->size_x - 1); *y = CLAMPS(j / b->sigma_s, 0, b->size_y - 1); *z = CLAMPS(L / b->sigma_r, 0, b->size_z - 1); } -static inline void grid_rescale(const dt_iop_colorreconstruct_bilateral_t *const b, const int i, const int j, const dt_iop_roi_t *roi, - const float scale, float *px, float *py) +static inline void grid_rescale(const dt_iop_colorreconstruct_bilateral_t *const b, const int i, const int j, + const dt_iop_roi_t *roi, const float scale, float *px, float *py) { *px = (roi->x + i) * scale - b->x; *py = (roi->y + j) * scale - b->y; @@ -243,12 +243,14 @@ static void dt_iop_colorreconstruct_bilateral_free(dt_iop_colorreconstruct_bilat free(b); } -static dt_iop_colorreconstruct_bilateral_t *dt_iop_colorreconstruct_bilateral_init(const dt_iop_roi_t *roi, // dimensions of input image - const float iscale, // overall scale of input image - const float sigma_s, // spatial sigma (blur pixel coords) - const float sigma_r) // range sigma (blur luma values) +static dt_iop_colorreconstruct_bilateral_t * +dt_iop_colorreconstruct_bilateral_init(const dt_iop_roi_t *roi, // dimensions of input image + const float iscale, // overall scale of input image + const float sigma_s, // spatial sigma (blur pixel coords) + const float sigma_r) // range sigma (blur luma values) { - dt_iop_colorreconstruct_bilateral_t *b = (dt_iop_colorreconstruct_bilateral_t *)malloc(sizeof(dt_iop_colorreconstruct_bilateral_t)); + dt_iop_colorreconstruct_bilateral_t *b + = (dt_iop_colorreconstruct_bilateral_t *)malloc(sizeof(dt_iop_colorreconstruct_bilateral_t)); if(!b) { fprintf(stderr, "[color reconstruction] not able to allocate buffer (a)\n"); @@ -284,11 +286,13 @@ static dt_iop_colorreconstruct_bilateral_t *dt_iop_colorreconstruct_bilateral_in return b; } -static dt_iop_colorreconstruct_bilateral_frozen_t *dt_iop_colorreconstruct_bilateral_freeze(dt_iop_colorreconstruct_bilateral_t *b) +static dt_iop_colorreconstruct_bilateral_frozen_t * +dt_iop_colorreconstruct_bilateral_freeze(dt_iop_colorreconstruct_bilateral_t *b) { if(!b) return NULL; - dt_iop_colorreconstruct_bilateral_frozen_t *bf = (dt_iop_colorreconstruct_bilateral_frozen_t *)malloc(sizeof(dt_iop_colorreconstruct_bilateral_frozen_t)); + dt_iop_colorreconstruct_bilateral_frozen_t *bf + = (dt_iop_colorreconstruct_bilateral_frozen_t *)malloc(sizeof(dt_iop_colorreconstruct_bilateral_frozen_t)); if(!bf) { fprintf(stderr, "[color reconstruction] not able to allocate buffer (c)\n"); @@ -320,11 +324,13 @@ static dt_iop_colorreconstruct_bilateral_frozen_t *dt_iop_colorreconstruct_bilat return bf; } -static dt_iop_colorreconstruct_bilateral_t *dt_iop_colorreconstruct_bilateral_thaw(dt_iop_colorreconstruct_bilateral_frozen_t *bf) +static dt_iop_colorreconstruct_bilateral_t * +dt_iop_colorreconstruct_bilateral_thaw(dt_iop_colorreconstruct_bilateral_frozen_t *bf) { if(!bf) return NULL; - dt_iop_colorreconstruct_bilateral_t *b = (dt_iop_colorreconstruct_bilateral_t *)malloc(sizeof(dt_iop_colorreconstruct_bilateral_t)); + dt_iop_colorreconstruct_bilateral_t *b + = (dt_iop_colorreconstruct_bilateral_t *)malloc(sizeof(dt_iop_colorreconstruct_bilateral_t)); if(!b) { fprintf(stderr, "[color reconstruction] not able to allocate buffer (e)\n"); @@ -357,12 +363,14 @@ static dt_iop_colorreconstruct_bilateral_t *dt_iop_colorreconstruct_bilateral_th } -static void dt_iop_colorreconstruct_bilateral_splat(dt_iop_colorreconstruct_bilateral_t *b, const float *const in, const float threshold, - dt_iop_colorreconstruct_precedence_t precedence, const float *params) +static void dt_iop_colorreconstruct_bilateral_splat(dt_iop_colorreconstruct_bilateral_t *b, const float *const in, + const float threshold, + dt_iop_colorreconstruct_precedence_t precedence, + const float *params) { if(!b) return; - // splat into downsampled grid +// splat into downsampled grid #ifdef _OPENMP #pragma omp parallel for default(none) shared(b, precedence, params) #endif @@ -376,7 +384,7 @@ static void dt_iop_colorreconstruct_bilateral_splat(dt_iop_colorreconstruct_bila const float ain = in[index + 1]; const float bin = in[index + 2]; // we deliberately ignore pixels above threshold - if (Lin > threshold) continue; + if(Lin > threshold) continue; switch(precedence) { @@ -387,8 +395,8 @@ static void dt_iop_colorreconstruct_bilateral_splat(dt_iop_colorreconstruct_bila case COLORRECONSTRUCT_PRECEDENCE_HUE: m = atan2(bin, ain) - params[0]; // readjust m into [-pi, +pi] interval - m = m > M_PI ? m - 2*M_PI : (m < -M_PI ? m + 2*M_PI : m); - weight = exp(-m*m/params[1]); + m = m > M_PI ? m - 2 * M_PI : (m < -M_PI ? m + 2 * M_PI : m); + weight = exp(-m * m / params[1]); break; case COLORRECONSTRUCT_PRECEDENCE_NONE: @@ -429,8 +437,8 @@ static void dt_iop_colorreconstruct_bilateral_splat(dt_iop_colorreconstruct_bila } -static void blur_line(dt_iop_colorreconstruct_Lab_t *buf, const int offset1, const int offset2, const int offset3, const int size1, - const int size2, const int size3) +static void blur_line(dt_iop_colorreconstruct_Lab_t *buf, const int offset1, const int offset2, const int offset3, + const int size1, const int size2, const int size3) { if(!buf) return; @@ -446,42 +454,45 @@ static void blur_line(dt_iop_colorreconstruct_Lab_t *buf, const int offset1, con for(int j = 0; j < size2; j++) { dt_iop_colorreconstruct_Lab_t tmp1 = buf[index]; - buf[index].L = buf[index].L * w0 + w1 * buf[index + offset3].L + w2 * buf[index + 2 * offset3].L; - buf[index].a = buf[index].a * w0 + w1 * buf[index + offset3].a + w2 * buf[index + 2 * offset3].a; - buf[index].b = buf[index].b * w0 + w1 * buf[index + offset3].b + w2 * buf[index + 2 * offset3].b; - buf[index].weight = buf[index].weight * w0 + w1 * buf[index + offset3].weight + w2 * buf[index + 2 * offset3].weight; + buf[index].L = buf[index].L * w0 + w1 * buf[index + offset3].L + w2 * buf[index + 2 * offset3].L; + buf[index].a = buf[index].a * w0 + w1 * buf[index + offset3].a + w2 * buf[index + 2 * offset3].a; + buf[index].b = buf[index].b * w0 + w1 * buf[index + offset3].b + w2 * buf[index + 2 * offset3].b; + buf[index].weight = buf[index].weight * w0 + w1 * buf[index + offset3].weight + + w2 * buf[index + 2 * offset3].weight; index += offset3; dt_iop_colorreconstruct_Lab_t tmp2 = buf[index]; - buf[index].L = buf[index].L * w0 + w1 * (buf[index + offset3].L + tmp1.L) + w2 * buf[index + 2 * offset3].L; - buf[index].a = buf[index].a * w0 + w1 * (buf[index + offset3].a + tmp1.a) + w2 * buf[index + 2 * offset3].a; - buf[index].b = buf[index].b * w0 + w1 * (buf[index + offset3].b + tmp1.b) + w2 * buf[index + 2 * offset3].b; - buf[index].weight = buf[index].weight * w0 + w1 * (buf[index + offset3].weight + tmp1.weight) + w2 * buf[index + 2 * offset3].weight; + buf[index].L = buf[index].L * w0 + w1 * (buf[index + offset3].L + tmp1.L) + w2 * buf[index + 2 * offset3].L; + buf[index].a = buf[index].a * w0 + w1 * (buf[index + offset3].a + tmp1.a) + w2 * buf[index + 2 * offset3].a; + buf[index].b = buf[index].b * w0 + w1 * (buf[index + offset3].b + tmp1.b) + w2 * buf[index + 2 * offset3].b; + buf[index].weight = buf[index].weight * w0 + w1 * (buf[index + offset3].weight + tmp1.weight) + + w2 * buf[index + 2 * offset3].weight; index += offset3; for(int i = 2; i < size3 - 2; i++) { const dt_iop_colorreconstruct_Lab_t tmp3 = buf[index]; - buf[index].L = buf[index].L * w0 + w1 * (buf[index + offset3].L + tmp2.L) - + w2 * (buf[index + 2 * offset3].L + tmp1.L); - buf[index].a = buf[index].a * w0 + w1 * (buf[index + offset3].a + tmp2.a) - + w2 * (buf[index + 2 * offset3].a + tmp1.a); - buf[index].b = buf[index].b * w0 + w1 * (buf[index + offset3].b + tmp2.b) - + w2 * (buf[index + 2 * offset3].b + tmp1.b); + buf[index].L = buf[index].L * w0 + w1 * (buf[index + offset3].L + tmp2.L) + + w2 * (buf[index + 2 * offset3].L + tmp1.L); + buf[index].a = buf[index].a * w0 + w1 * (buf[index + offset3].a + tmp2.a) + + w2 * (buf[index + 2 * offset3].a + tmp1.a); + buf[index].b = buf[index].b * w0 + w1 * (buf[index + offset3].b + tmp2.b) + + w2 * (buf[index + 2 * offset3].b + tmp1.b); buf[index].weight = buf[index].weight * w0 + w1 * (buf[index + offset3].weight + tmp2.weight) - + w2 * (buf[index + 2 * offset3].weight + tmp1.weight); + + w2 * (buf[index + 2 * offset3].weight + tmp1.weight); index += offset3; tmp1 = tmp2; tmp2 = tmp3; } const dt_iop_colorreconstruct_Lab_t tmp3 = buf[index]; - buf[index].L = buf[index].L * w0 + w1 * (buf[index + offset3].L + tmp2.L) + w2 * tmp1.L; - buf[index].a = buf[index].a * w0 + w1 * (buf[index + offset3].a + tmp2.a) + w2 * tmp1.a; - buf[index].b = buf[index].b * w0 + w1 * (buf[index + offset3].b + tmp2.b) + w2 * tmp1.b; - buf[index].weight = buf[index].weight * w0 + w1 * (buf[index + offset3].weight + tmp2.weight) + w2 * tmp1.weight; + buf[index].L = buf[index].L * w0 + w1 * (buf[index + offset3].L + tmp2.L) + w2 * tmp1.L; + buf[index].a = buf[index].a * w0 + w1 * (buf[index + offset3].a + tmp2.a) + w2 * tmp1.a; + buf[index].b = buf[index].b * w0 + w1 * (buf[index + offset3].b + tmp2.b) + w2 * tmp1.b; + buf[index].weight = buf[index].weight * w0 + w1 * (buf[index + offset3].weight + tmp2.weight) + + w2 * tmp1.weight; index += offset3; - buf[index].L = buf[index].L * w0 + w1 * tmp3.L + w2 * tmp2.L; - buf[index].a = buf[index].a * w0 + w1 * tmp3.a + w2 * tmp2.a; - buf[index].b = buf[index].b * w0 + w1 * tmp3.b + w2 * tmp2.b; + buf[index].L = buf[index].L * w0 + w1 * tmp3.L + w2 * tmp2.L; + buf[index].a = buf[index].a * w0 + w1 * tmp3.a + w2 * tmp2.a; + buf[index].b = buf[index].b * w0 + w1 * tmp3.b + w2 * tmp2.b; buf[index].weight = buf[index].weight * w0 + w1 * tmp3.weight + w2 * tmp2.weight; index += offset3; index += offset2 - offset3 * size3; @@ -503,9 +514,8 @@ static void dt_iop_colorreconstruct_bilateral_blur(dt_iop_colorreconstruct_bilat } static void dt_iop_colorreconstruct_bilateral_slice(const dt_iop_colorreconstruct_bilateral_t *const b, - const float *const in, float *const out, - const float threshold, const dt_iop_roi_t *const roi, - const float iscale) + const float *const in, float *const out, const float threshold, + const dt_iop_roi_t *const roi, const float iscale) { if(!b) return; @@ -528,7 +538,7 @@ static void dt_iop_colorreconstruct_bilateral_slice(const dt_iop_colorreconstruc const float bin = out[index + 2] = in[index + 2]; out[index + 3] = in[index + 3]; const float blend = CLAMPS(20.0f / threshold * Lin - 19.0f, 0.0f, 1.0f); - if (blend == 0.0f) continue; + if(blend == 0.0f) continue; grid_rescale(b, i, j, roi, rescale, &px, &py); image_to_grid(b, px, py, Lin, &x, &y, &z); // trilinear lookup: @@ -540,7 +550,7 @@ static void dt_iop_colorreconstruct_bilateral_slice(const dt_iop_colorreconstruc const float zf = z - zi; const size_t gi = xi + b->size_x * (yi + b->size_y * zi); - const float Lout = b->buf[gi].L * (1.0f - xf) * (1.0f - yf) * (1.0f - zf) + const float Lout = b->buf[gi].L * (1.0f - xf) * (1.0f - yf) * (1.0f - zf) + b->buf[gi + ox].L * (xf) * (1.0f - yf) * (1.0f - zf) + b->buf[gi + oy].L * (1.0f - xf) * (yf) * (1.0f - zf) + b->buf[gi + ox + oy].L * (xf) * (yf) * (1.0f - zf) @@ -549,7 +559,7 @@ static void dt_iop_colorreconstruct_bilateral_slice(const dt_iop_colorreconstruc + b->buf[gi + oy + oz].L * (1.0f - xf) * (yf) * (zf) + b->buf[gi + ox + oy + oz].L * (xf) * (yf) * (zf); - const float aout = b->buf[gi].a * (1.0f - xf) * (1.0f - yf) * (1.0f - zf) + const float aout = b->buf[gi].a * (1.0f - xf) * (1.0f - yf) * (1.0f - zf) + b->buf[gi + ox].a * (xf) * (1.0f - yf) * (1.0f - zf) + b->buf[gi + oy].a * (1.0f - xf) * (yf) * (1.0f - zf) + b->buf[gi + ox + oy].a * (xf) * (yf) * (1.0f - zf) @@ -559,7 +569,7 @@ static void dt_iop_colorreconstruct_bilateral_slice(const dt_iop_colorreconstruc + b->buf[gi + ox + oy + oz].a * (xf) * (yf) * (zf); - const float bout = b->buf[gi].b * (1.0f - xf) * (1.0f - yf) * (1.0f - zf) + const float bout = b->buf[gi].b * (1.0f - xf) * (1.0f - yf) * (1.0f - zf) + b->buf[gi + ox].b * (xf) * (1.0f - yf) * (1.0f - zf) + b->buf[gi + oy].b * (1.0f - xf) * (yf) * (1.0f - zf) + b->buf[gi + ox + oy].b * (xf) * (yf) * (1.0f - zf) @@ -569,17 +579,17 @@ static void dt_iop_colorreconstruct_bilateral_slice(const dt_iop_colorreconstruc + b->buf[gi + ox + oy + oz].b * (xf) * (yf) * (zf); const float weight = b->buf[gi].weight * (1.0f - xf) * (1.0f - yf) * (1.0f - zf) - + b->buf[gi + ox].weight * (xf) * (1.0f - yf) * (1.0f - zf) - + b->buf[gi + oy].weight * (1.0f - xf) * (yf) * (1.0f - zf) - + b->buf[gi + ox + oy].weight * (xf) * (yf) * (1.0f - zf) - + b->buf[gi + oz].weight * (1.0f - xf) * (1.0f - yf) * (zf) - + b->buf[gi + ox + oz].weight * (xf) * (1.0f - yf) * (zf) - + b->buf[gi + oy + oz].weight * (1.0f - xf) * (yf) * (zf) - + b->buf[gi + ox + oy + oz].weight * (xf) * (yf) * (zf); + + b->buf[gi + ox].weight * (xf) * (1.0f - yf) * (1.0f - zf) + + b->buf[gi + oy].weight * (1.0f - xf) * (yf) * (1.0f - zf) + + b->buf[gi + ox + oy].weight * (xf) * (yf) * (1.0f - zf) + + b->buf[gi + oz].weight * (1.0f - xf) * (1.0f - yf) * (zf) + + b->buf[gi + ox + oz].weight * (xf) * (1.0f - yf) * (zf) + + b->buf[gi + oy + oz].weight * (1.0f - xf) * (yf) * (zf) + + b->buf[gi + ox + oy + oz].weight * (xf) * (yf) * (zf); const float lout = fmax(Lout, 0.01f); - out[index + 1] = (weight > 0.0f) ? ain * (1.0f - blend) + aout * Lin/lout * blend : ain; - out[index + 2] = (weight > 0.0f) ? bin * (1.0f - blend) + bout * Lin/lout * blend : bin; + out[index + 1] = (weight > 0.0f) ? ain * (1.0f - blend) + aout * Lin / lout * blend : ain; + out[index + 2] = (weight > 0.0f) ? bin * (1.0f - blend) + bout * Lin / lout * blend : bin; } } } @@ -598,18 +608,20 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const const float sigma_s = fmax(data->spatial, 1.0f) / scale; const float hue = hue_conversion(data->hue); // convert to LCH hue which better fits to Lab colorspace - const float params[4] = { hue, M_PI*M_PI/8, 0.0f, 0.0f }; + const float params[4] = { hue, M_PI * M_PI / 8, 0.0f, 0.0f }; dt_iop_colorreconstruct_bilateral_t *b; dt_iop_colorreconstruct_bilateral_frozen_t *can = NULL; // color reconstruction often involves a massive spatial blur of the bilateral grid. this typically requires // more or less the whole image to contribute to the grid. In pixelpipe FULL we can not rely on this - // as the pixelpipe might only see part of the image (region of interest). Therefore we "steal" the bilateral grid + // as the pixelpipe might only see part of the image (region of interest). Therefore we "steal" the bilateral + // grid // of the preview pipe if needed. However, the grid of the preview pipeline is coarser and may lead // to other artifacts so we only want to use it when necessary. The threshold for data->spatial has been selected // arbitrarily. - if(sigma_s > DT_COLORRECONSTRUCT_SPATIAL_APPROX && self->dev->gui_attached && g && piece->pipe->type == DT_DEV_PIXELPIPE_FULL) + if(sigma_s > DT_COLORRECONSTRUCT_SPATIAL_APPROX && self->dev->gui_attached && g + && piece->pipe->type == DT_DEV_PIXELPIPE_FULL) { // check how far we are zoomed-in dt_dev_zoom_t zoom = dt_control_get_dev_zoom(); @@ -641,7 +653,7 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const } if(!b) goto error; - + dt_iop_colorreconstruct_bilateral_slice(b, in, out, data->threshold, roi_in, piece->iscale); // here is where we generate the canned bilateral grid of the preview pipe for later use @@ -689,20 +701,23 @@ static void dt_iop_colorreconstruct_bilateral_free_cl(dt_iop_colorreconstruct_bi free(b); } -static dt_iop_colorreconstruct_bilateral_cl_t *dt_iop_colorreconstruct_bilateral_init_cl( - const int devid, - dt_iop_colorreconstruct_global_data_t *global, - const dt_iop_roi_t *roi, // dimensions of input image - const float iscale, // overall scale of input image - const float sigma_s, // spatial sigma (blur pixel coords) - const float sigma_r) // range sigma (blur luma values) +static dt_iop_colorreconstruct_bilateral_cl_t * +dt_iop_colorreconstruct_bilateral_init_cl(const int devid, dt_iop_colorreconstruct_global_data_t *global, + const dt_iop_roi_t *roi, // dimensions of input image + const float iscale, // overall scale of input image + const float sigma_s, // spatial sigma (blur pixel coords) + const float sigma_r) // range sigma (blur luma values) { int blocksizex, blocksizey; - dt_opencl_local_buffer_t locopt - = (dt_opencl_local_buffer_t){ .xoffset = 0, .xfactor = 1, .yoffset = 0, .yfactor = 1, - .cellsize = 4 * sizeof(float) + sizeof(int), .overhead = 0, - .sizex = 1 << 6, .sizey = 1 << 6 }; + dt_opencl_local_buffer_t locopt = (dt_opencl_local_buffer_t){.xoffset = 0, + .xfactor = 1, + .yoffset = 0, + .yfactor = 1, + .cellsize = 4 * sizeof(float) + sizeof(int), + .overhead = 0, + .sizex = 1 << 6, + .sizey = 1 << 6 }; if(dt_opencl_local_buffer_opt(devid, global->kernel_colorreconstruct_splat, &locopt)) { @@ -720,7 +735,8 @@ static dt_iop_colorreconstruct_bilateral_cl_t *dt_iop_colorreconstruct_bilateral return NULL; } - dt_iop_colorreconstruct_bilateral_cl_t *b = (dt_iop_colorreconstruct_bilateral_cl_t *)malloc(sizeof(dt_iop_colorreconstruct_bilateral_cl_t)); + dt_iop_colorreconstruct_bilateral_cl_t *b + = (dt_iop_colorreconstruct_bilateral_cl_t *)malloc(sizeof(dt_iop_colorreconstruct_bilateral_cl_t)); if(!b) { dt_print(DT_DEBUG_OPENCL, "[opencl_colorreconstruction] not able to allocate host buffer (a)\n"); @@ -770,7 +786,8 @@ static dt_iop_colorreconstruct_bilateral_cl_t *dt_iop_colorreconstruct_bilateral // zero out grid int wd = 4 * b->size_x, ht = b->size_y * b->size_z; size_t sizes[] = { ROUNDUPWD(wd), ROUNDUPHT(ht), 1 }; - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_zero, 0, sizeof(cl_mem), (void *)&b->dev_grid); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_zero, 0, sizeof(cl_mem), + (void *)&b->dev_grid); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_zero, 1, sizeof(int), (void *)&wd); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_zero, 2, sizeof(int), (void *)&ht); cl_int err = -666; @@ -790,11 +807,13 @@ static dt_iop_colorreconstruct_bilateral_cl_t *dt_iop_colorreconstruct_bilateral return b; } -static dt_iop_colorreconstruct_bilateral_frozen_t *dt_iop_colorreconstruct_bilateral_freeze_cl(dt_iop_colorreconstruct_bilateral_cl_t *b) +static dt_iop_colorreconstruct_bilateral_frozen_t * +dt_iop_colorreconstruct_bilateral_freeze_cl(dt_iop_colorreconstruct_bilateral_cl_t *b) { if(!b) return NULL; - dt_iop_colorreconstruct_bilateral_frozen_t *bf = (dt_iop_colorreconstruct_bilateral_frozen_t *)malloc(sizeof(dt_iop_colorreconstruct_bilateral_frozen_t)); + dt_iop_colorreconstruct_bilateral_frozen_t *bf + = (dt_iop_colorreconstruct_bilateral_frozen_t *)malloc(sizeof(dt_iop_colorreconstruct_bilateral_frozen_t)); if(!bf) { dt_print(DT_DEBUG_OPENCL, "[opencl_colorreconstruction] not able to allocate host buffer (d)\n"); @@ -815,12 +834,13 @@ static dt_iop_colorreconstruct_bilateral_frozen_t *dt_iop_colorreconstruct_bilat if(bf->buf && b->dev_grid) { // read bilateral grid from device memory to host buffer (blocking) - cl_int err = dt_opencl_read_buffer_from_device(b->devid, bf->buf, b->dev_grid, 0, - b->size_x * b->size_y * b->size_z * sizeof(dt_iop_colorreconstruct_Lab_t), TRUE); + cl_int err = dt_opencl_read_buffer_from_device( + b->devid, bf->buf, b->dev_grid, 0, + b->size_x * b->size_y * b->size_z * sizeof(dt_iop_colorreconstruct_Lab_t), TRUE); if(err != CL_SUCCESS) { - dt_print(DT_DEBUG_OPENCL, - "[opencl_colorreconstruction] can not read bilateral grid from device %d\n", b->devid); + dt_print(DT_DEBUG_OPENCL, "[opencl_colorreconstruction] can not read bilateral grid from device %d\n", + b->devid); dt_iop_colorreconstruct_bilateral_dump(bf); return NULL; } @@ -835,18 +855,22 @@ static dt_iop_colorreconstruct_bilateral_frozen_t *dt_iop_colorreconstruct_bilat return bf; } -static dt_iop_colorreconstruct_bilateral_cl_t *dt_iop_colorreconstruct_bilateral_thaw_cl(dt_iop_colorreconstruct_bilateral_frozen_t *bf, - const int devid, - dt_iop_colorreconstruct_global_data_t *global) +static dt_iop_colorreconstruct_bilateral_cl_t * +dt_iop_colorreconstruct_bilateral_thaw_cl(dt_iop_colorreconstruct_bilateral_frozen_t *bf, const int devid, + dt_iop_colorreconstruct_global_data_t *global) { if(!bf || !bf->buf) return NULL; int blocksizex, blocksizey; - dt_opencl_local_buffer_t locopt - = (dt_opencl_local_buffer_t){ .xoffset = 0, .xfactor = 1, .yoffset = 0, .yfactor = 1, - .cellsize = 4 * sizeof(float) + sizeof(int), .overhead = 0, - .sizex = 1 << 6, .sizey = 1 << 6 }; + dt_opencl_local_buffer_t locopt = (dt_opencl_local_buffer_t){.xoffset = 0, + .xfactor = 1, + .yoffset = 0, + .yfactor = 1, + .cellsize = 4 * sizeof(float) + sizeof(int), + .overhead = 0, + .sizex = 1 << 6, + .sizey = 1 << 6 }; if(dt_opencl_local_buffer_opt(devid, global->kernel_colorreconstruct_splat, &locopt)) { @@ -864,7 +888,8 @@ static dt_iop_colorreconstruct_bilateral_cl_t *dt_iop_colorreconstruct_bilateral return NULL; } - dt_iop_colorreconstruct_bilateral_cl_t *b = (dt_iop_colorreconstruct_bilateral_cl_t *)malloc(sizeof(dt_iop_colorreconstruct_bilateral_cl_t)); + dt_iop_colorreconstruct_bilateral_cl_t *b + = (dt_iop_colorreconstruct_bilateral_cl_t *)malloc(sizeof(dt_iop_colorreconstruct_bilateral_cl_t)); if(!b) { dt_print(DT_DEBUG_OPENCL, "[opencl_colorreconstruction] not able to allocate host buffer (f)\n"); @@ -887,7 +912,7 @@ static dt_iop_colorreconstruct_bilateral_cl_t *dt_iop_colorreconstruct_bilateral b->sigma_r = bf->sigma_r; b->dev_grid = NULL; b->dev_grid_tmp = NULL; - + // alloc grid buffer: b->dev_grid = dt_opencl_alloc_device_buffer(b->devid, (size_t)b->size_x * b->size_y * b->size_z * 4 * sizeof(float)); @@ -911,12 +936,13 @@ static dt_iop_colorreconstruct_bilateral_cl_t *dt_iop_colorreconstruct_bilateral if(bf->buf) { // write bilateral grid from host buffer to device memory (blocking) - cl_int err = dt_opencl_write_buffer_to_device(b->devid, bf->buf, b->dev_grid, 0, - bf->size_x * bf->size_y * bf->size_z * sizeof(dt_iop_colorreconstruct_Lab_t), TRUE); + cl_int err = dt_opencl_write_buffer_to_device( + b->devid, bf->buf, b->dev_grid, 0, + bf->size_x * bf->size_y * bf->size_z * sizeof(dt_iop_colorreconstruct_Lab_t), TRUE); if(err != CL_SUCCESS) { - dt_print(DT_DEBUG_OPENCL, - "[opencl_colorreconstruction] can not write bilateral grid to device %d\n", b->devid); + dt_print(DT_DEBUG_OPENCL, "[opencl_colorreconstruction] can not write bilateral grid to device %d\n", + b->devid); dt_iop_colorreconstruct_bilateral_free_cl(b); return NULL; } @@ -925,8 +951,10 @@ static dt_iop_colorreconstruct_bilateral_cl_t *dt_iop_colorreconstruct_bilateral return b; } -static cl_int dt_iop_colorreconstruct_bilateral_splat_cl(dt_iop_colorreconstruct_bilateral_cl_t *b, cl_mem in, const float threshold, - dt_iop_colorreconstruct_precedence_t precedence, const float *params) +static cl_int dt_iop_colorreconstruct_bilateral_splat_cl(dt_iop_colorreconstruct_bilateral_cl_t *b, cl_mem in, + const float threshold, + dt_iop_colorreconstruct_precedence_t precedence, + const float *params) { cl_int err = -666; if(!b) return err; @@ -934,19 +962,24 @@ static cl_int dt_iop_colorreconstruct_bilateral_splat_cl(dt_iop_colorreconstruct size_t sizes[] = { ROUNDUP(b->width, b->blocksizex), ROUNDUP(b->height, b->blocksizey), 1 }; size_t local[] = { b->blocksizex, b->blocksizey, 1 }; dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_splat, 0, sizeof(cl_mem), (void *)&in); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_splat, 1, sizeof(cl_mem), (void *)&b->dev_grid); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_splat, 1, sizeof(cl_mem), + (void *)&b->dev_grid); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_splat, 2, sizeof(int), (void *)&b->width); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_splat, 3, sizeof(int), (void *)&b->height); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_splat, 4, sizeof(int), (void *)&b->size_x); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_splat, 5, sizeof(int), (void *)&b->size_y); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_splat, 6, sizeof(int), (void *)&b->size_z); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_splat, 7, sizeof(float), (void *)&b->sigma_s); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_splat, 8, sizeof(float), (void *)&b->sigma_r); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_splat, 9, sizeof(float), (void *)&threshold); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_splat, 7, sizeof(float), + (void *)&b->sigma_s); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_splat, 8, sizeof(float), + (void *)&b->sigma_r); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_splat, 9, sizeof(float), + (void *)&threshold); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_splat, 10, sizeof(int), (void *)&pref); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_splat, 11, 4*sizeof(float), (void *)params); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_splat, 12, b->blocksizex * b->blocksizey * sizeof(int), - NULL); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_splat, 11, 4 * sizeof(float), + (void *)params); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_splat, 12, + b->blocksizex * b->blocksizey * sizeof(int), NULL); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_splat, 13, b->blocksizex * b->blocksizey * 4 * sizeof(float), NULL); err = dt_opencl_enqueue_kernel_2d_with_local(b->devid, b->global->kernel_colorreconstruct_splat, sizes, local); @@ -969,14 +1002,22 @@ static cl_int dt_iop_colorreconstruct_bilateral_blur_cl(dt_iop_colorreconstruct_ stride1 = b->size_x * b->size_y; stride2 = b->size_x; stride3 = 1; - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 0, sizeof(cl_mem), (void *)&b->dev_grid_tmp); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 1, sizeof(cl_mem), (void *)&b->dev_grid); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 2, sizeof(int), (void *)&stride1); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 3, sizeof(int), (void *)&stride2); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 4, sizeof(int), (void *)&stride3); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 5, sizeof(int), (void *)&b->size_z); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 6, sizeof(int), (void *)&b->size_y); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 7, sizeof(int), (void *)&b->size_x); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 0, sizeof(cl_mem), + (void *)&b->dev_grid_tmp); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 1, sizeof(cl_mem), + (void *)&b->dev_grid); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 2, sizeof(int), + (void *)&stride1); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 3, sizeof(int), + (void *)&stride2); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 4, sizeof(int), + (void *)&stride3); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 5, sizeof(int), + (void *)&b->size_z); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 6, sizeof(int), + (void *)&b->size_y); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 7, sizeof(int), + (void *)&b->size_x); err = dt_opencl_enqueue_kernel_2d(b->devid, b->global->kernel_colorreconstruct_blur_line, sizes); if(err != CL_SUCCESS) return err; @@ -985,14 +1026,22 @@ static cl_int dt_iop_colorreconstruct_bilateral_blur_cl(dt_iop_colorreconstruct_ stride3 = b->size_x; sizes[0] = ROUNDUPWD(b->size_z); sizes[1] = ROUNDUPHT(b->size_x); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 0, sizeof(cl_mem), (void *)&b->dev_grid); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 1, sizeof(cl_mem), (void *)&b->dev_grid_tmp); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 2, sizeof(int), (void *)&stride1); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 3, sizeof(int), (void *)&stride2); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 4, sizeof(int), (void *)&stride3); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 5, sizeof(int), (void *)&b->size_z); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 6, sizeof(int), (void *)&b->size_x); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 7, sizeof(int), (void *)&b->size_y); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 0, sizeof(cl_mem), + (void *)&b->dev_grid); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 1, sizeof(cl_mem), + (void *)&b->dev_grid_tmp); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 2, sizeof(int), + (void *)&stride1); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 3, sizeof(int), + (void *)&stride2); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 4, sizeof(int), + (void *)&stride3); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 5, sizeof(int), + (void *)&b->size_z); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 6, sizeof(int), + (void *)&b->size_x); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 7, sizeof(int), + (void *)&b->size_y); err = dt_opencl_enqueue_kernel_2d(b->devid, b->global->kernel_colorreconstruct_blur_line, sizes); if(err != CL_SUCCESS) return err; @@ -1003,19 +1052,27 @@ static cl_int dt_iop_colorreconstruct_bilateral_blur_cl(dt_iop_colorreconstruct_ sizes[1] = ROUNDUPHT(b->size_y); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 0, sizeof(cl_mem), (void *)&b->dev_grid_tmp); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 1, sizeof(cl_mem), (void *)&b->dev_grid); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 2, sizeof(int), (void *)&stride1); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 3, sizeof(int), (void *)&stride2); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 4, sizeof(int), (void *)&stride3); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 5, sizeof(int), (void *)&b->size_x); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 6, sizeof(int), (void *)&b->size_y); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 7, sizeof(int), (void *)&b->size_z); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 1, sizeof(cl_mem), + (void *)&b->dev_grid); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 2, sizeof(int), + (void *)&stride1); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 3, sizeof(int), + (void *)&stride2); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 4, sizeof(int), + (void *)&stride3); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 5, sizeof(int), + (void *)&b->size_x); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 6, sizeof(int), + (void *)&b->size_y); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_blur_line, 7, sizeof(int), + (void *)&b->size_z); err = dt_opencl_enqueue_kernel_2d(b->devid, b->global->kernel_colorreconstruct_blur_line, sizes); return err; } -static cl_int dt_iop_colorreconstruct_bilateral_slice_cl(dt_iop_colorreconstruct_bilateral_cl_t *b, cl_mem in, cl_mem out, - const float threshold, const dt_iop_roi_t *roi, const float iscale) +static cl_int dt_iop_colorreconstruct_bilateral_slice_cl(dt_iop_colorreconstruct_bilateral_cl_t *b, cl_mem in, + cl_mem out, const float threshold, + const dt_iop_roi_t *roi, const float iscale) { cl_int err = -666; if(!b) return err; @@ -1026,17 +1083,22 @@ static cl_int dt_iop_colorreconstruct_bilateral_slice_cl(dt_iop_colorreconstruct size_t sizes[] = { ROUNDUPWD(roi->width), ROUNDUPHT(roi->height), 1 }; dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 0, sizeof(cl_mem), (void *)&in); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 1, sizeof(cl_mem), (void *)&out); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 2, sizeof(cl_mem), (void *)&b->dev_grid); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 2, sizeof(cl_mem), + (void *)&b->dev_grid); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 3, sizeof(int), (void *)&roi->width); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 4, sizeof(int), (void *)&roi->height); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 4, sizeof(int), + (void *)&roi->height); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 5, sizeof(int), (void *)&b->size_x); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 6, sizeof(int), (void *)&b->size_y); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 7, sizeof(int), (void *)&b->size_z); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 8, sizeof(float), (void *)&b->sigma_s); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 9, sizeof(float), (void *)&b->sigma_r); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 10, sizeof(float), (void *)&threshold); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 11, 2*sizeof(int), (void *)&bxy); - dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 12, 2*sizeof(int), (void *)&roixy); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 8, sizeof(float), + (void *)&b->sigma_s); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 9, sizeof(float), + (void *)&b->sigma_r); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 10, sizeof(float), + (void *)&threshold); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 11, 2 * sizeof(int), (void *)&bxy); + dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 12, 2 * sizeof(int), (void *)&roixy); dt_opencl_set_kernel_arg(b->devid, b->global->kernel_colorreconstruct_slice, 13, sizeof(float), (void *)&rescale); err = dt_opencl_enqueue_kernel_2d(b->devid, b->global->kernel_colorreconstruct_slice, sizes); return err; @@ -1054,7 +1116,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m const float sigma_s = fmax(d->spatial, 1.0f) / scale; const float hue = hue_conversion(d->hue); // convert to LCH hue which better fits to Lab colorspace - const float params[4] = { hue, M_PI*M_PI/8, 0.0f, 0.0f }; + const float params[4] = { hue, M_PI * M_PI / 8, 0.0f, 0.0f }; cl_int err = -666; @@ -1062,7 +1124,8 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m dt_iop_colorreconstruct_bilateral_frozen_t *can = NULL; // see process() for more details on how we transfer a bilateral grid from the preview to the full pipeline - if(sigma_s > DT_COLORRECONSTRUCT_SPATIAL_APPROX && self->dev->gui_attached && g && piece->pipe->type == DT_DEV_PIXELPIPE_FULL) + if(sigma_s > DT_COLORRECONSTRUCT_SPATIAL_APPROX && self->dev->gui_attached && g + && piece->pipe->type == DT_DEV_PIXELPIPE_FULL) { // check how far we are zoomed-in dt_dev_zoom_t zoom = dt_control_get_dev_zoom(); @@ -1121,10 +1184,11 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m #endif -static size_t dt_iop_colorreconstruct_bilateral_memory_use(const int width, // width of input image - const int height, // height of input image - const float sigma_s, // spatial sigma (blur pixel coords) - const float sigma_r) // range sigma (blur luma values) +static size_t +dt_iop_colorreconstruct_bilateral_memory_use(const int width, // width of input image + const int height, // height of input image + const float sigma_s, // spatial sigma (blur pixel coords) + const float sigma_r) // range sigma (blur luma values) { float _x = roundf(width / sigma_s); float _y = roundf(height / sigma_s); @@ -1133,14 +1197,16 @@ static size_t dt_iop_colorreconstruct_bilateral_memory_use(const int width, size_t size_y = CLAMPS((int)_y, 4, DT_COLORRECONSTRUCT_BILATERAL_MAX_RES_S) + 1; size_t size_z = CLAMPS((int)_z, 4, DT_COLORRECONSTRUCT_BILATERAL_MAX_RES_R) + 1; - return size_x * size_y * size_z * 4 * sizeof(float) * 2; // in fact only the OpenCL path needs a second tmp buffer + return size_x * size_y * size_z * 4 * sizeof(float) + * 2; // in fact only the OpenCL path needs a second tmp buffer } -static size_t dt_iop_colorreconstruct_bilateral_singlebuffer_size(const int width, // width of input image - const int height, // height of input image - const float sigma_s, // spatial sigma (blur pixel coords) - const float sigma_r) // range sigma (blur luma values) +static size_t +dt_iop_colorreconstruct_bilateral_singlebuffer_size(const int width, // width of input image + const int height, // height of input image + const float sigma_s, // spatial sigma (blur pixel coords) + const float sigma_r) // range sigma (blur luma values) { float _x = roundf(width / sigma_s); float _y = roundf(height / sigma_s); @@ -1153,8 +1219,7 @@ static size_t dt_iop_colorreconstruct_bilateral_singlebuffer_size(const int widt } void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling) + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling) { dt_iop_colorreconstruct_data_t *d = (dt_iop_colorreconstruct_data_t *)piece->data; // the total scale is composed of scale before input to the pipeline (iscale), @@ -1169,9 +1234,10 @@ void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t const size_t basebuffer = width * height * channels * sizeof(float); - tiling->factor = 2.0f + (float)dt_iop_colorreconstruct_bilateral_memory_use(width, height, sigma_s, sigma_r) / basebuffer; - tiling->maxbuf - = fmax(1.0f, (float)dt_iop_colorreconstruct_bilateral_singlebuffer_size(width, height, sigma_s, sigma_r) / basebuffer); + tiling->factor + = 2.0f + (float)dt_iop_colorreconstruct_bilateral_memory_use(width, height, sigma_s, sigma_r) / basebuffer; + tiling->maxbuf = fmax(1.0f, (float)dt_iop_colorreconstruct_bilateral_singlebuffer_size(width, height, sigma_s, + sigma_r) / basebuffer); tiling->overhead = 0; tiling->overlap = ceilf(4 * sigma_s); tiling->xalign = 1; @@ -1257,7 +1323,8 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix void init_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece) { - dt_iop_colorreconstruct_data_t *d = (dt_iop_colorreconstruct_data_t *)calloc(1, sizeof(dt_iop_colorreconstruct_data_t)); + dt_iop_colorreconstruct_data_t *d + = (dt_iop_colorreconstruct_data_t *)calloc(1, sizeof(dt_iop_colorreconstruct_data_t)); piece->data = (void *)d; self->commit_params(self, self->default_params, pipe, piece); } @@ -1301,10 +1368,11 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_colorreconstruct_params_t)); module->default_params = calloc(1, sizeof(dt_iop_colorreconstruct_params_t)); module->default_enabled = 0; - module->priority = 367; // module order created by iop_dependencies.py, do not edit! + module->priority = 376; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_colorreconstruct_params_t); module->gui_data = NULL; - dt_iop_colorreconstruct_params_t tmp = (dt_iop_colorreconstruct_params_t){ 100.0f, 400.0f, 10.0f, 0.66f, COLORRECONSTRUCT_PRECEDENCE_NONE }; + dt_iop_colorreconstruct_params_t tmp + = (dt_iop_colorreconstruct_params_t){ 100.0f, 400.0f, 10.0f, 0.66f, COLORRECONSTRUCT_PRECEDENCE_NONE }; memcpy(module->params, &tmp, sizeof(dt_iop_colorreconstruct_params_t)); memcpy(module->default_params, &tmp, sizeof(dt_iop_colorreconstruct_params_t)); } diff --git a/src/iop/colortransfer.c b/src/iop/colortransfer.c index f1cf0bda8e6f..84249ff74b2a 100644 --- a/src/iop/colortransfer.c +++ b/src/iop/colortransfer.c @@ -139,8 +139,7 @@ static void capture_histogram(const float *col, const dt_iop_roi_t *roi, int *hi // accumulated start distribution of G1 G2 for(int k = 1; k < HISTN; k++) hist[k] += hist[k - 1]; - for(int k = 0; k < HISTN; k++) - hist[k] = (int)CLAMP(hist[k] * (HISTN / (float)hist[HISTN - 1]), 0, HISTN - 1); + for(int k = 0; k < HISTN; k++) hist[k] = (int)CLAMP(hist[k] * (HISTN / (float)hist[HISTN - 1]), 0, HISTN - 1); // for(int i=0;i<100;i++) printf("#[%d] %d \n", i, hist[(int)CLAMP(HISTN*i/100.0, 0, HISTN-1)]); } @@ -241,8 +240,8 @@ static void kmeans(const float *col, const dt_iop_roi_t *const roi, const int n, const int nit = 10; // number of iterations const int samples = roi->width * roi->height * 0.2; // samples: only a fraction of the buffer. - float(*const mean)[2] = malloc(2 * n * sizeof(float)); - float(*const var)[2] = malloc(2 * n * sizeof(float)); + float (*const mean)[2] = malloc(2 * n * sizeof(float)); + float (*const var)[2] = malloc(2 * n * sizeof(float)); int *const cnt = malloc(n * sizeof(int)); // init n clusters for a, b channels at random @@ -371,8 +370,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const } // cluster input buffer - float(*const mean)[2] = malloc(2 * data->n * sizeof(float)); - float(*const var)[2] = malloc(2 * data->n * sizeof(float)); + float (*const mean)[2] = malloc(2 * data->n * sizeof(float)); + float (*const var)[2] = malloc(2 * data->n * sizeof(float)); kmeans(in, roi_in, data->n, mean, var); @@ -403,10 +402,10 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const out[j + 1] = out[j + 2] = 0.0f; for(int c = 0; c < data->n; c++) { - out[j + 1] += weight[c] * ((Lab[1] - mean[c][0]) * data->var[mapio[c]][0] / var[c][0] - + data->mean[mapio[c]][0]); - out[j + 2] += weight[c] * ((Lab[2] - mean[c][1]) * data->var[mapio[c]][1] / var[c][1] - + data->mean[mapio[c]][1]); + out[j + 1] += weight[c] + * ((Lab[1] - mean[c][0]) * data->var[mapio[c]][0] / var[c][0] + data->mean[mapio[c]][0]); + out[j + 2] += weight[c] + * ((Lab[2] - mean[c][1]) * data->var[mapio[c]][1] / var[c][1] + data->mean[mapio[c]][1]); } #endif out[j + 3] = in[j + 3]; @@ -559,7 +558,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_colortransfer_params_t)); module->default_params = calloc(1, sizeof(dt_iop_colortransfer_params_t)); module->default_enabled = 0; - module->priority = 485; // module order created by iop_dependencies.py, do not edit! + module->priority = 492; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_colortransfer_params_t); module->gui_data = NULL; dt_iop_colortransfer_params_t tmp; diff --git a/src/iop/colorzones.c b/src/iop/colorzones.c index aa2116fd5519..7886fbf2b913 100644 --- a/src/iop/colorzones.c +++ b/src/iop/colorzones.c @@ -122,8 +122,8 @@ int groups() return IOP_GROUP_COLOR; } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 1 && new_version == 3) { @@ -344,8 +344,7 @@ void init_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pi for(int ch = 0; ch < 3; ch++) { d->curve[ch] = dt_draw_curve_new(0.0, 1.0, CATMULL_ROM); - (void)dt_draw_curve_add_point(d->curve[ch], - default_params->equalizer_x[ch][DT_IOP_COLORZONES_BANDS - 2] - 1.0, + (void)dt_draw_curve_add_point(d->curve[ch], default_params->equalizer_x[ch][DT_IOP_COLORZONES_BANDS - 2] - 1.0, default_params->equalizer_y[ch][DT_IOP_COLORZONES_BANDS - 2]); for(int k = 0; k < DT_IOP_COLORZONES_BANDS; k++) (void)dt_draw_curve_add_point(d->curve[ch], default_params->equalizer_x[ch][k], @@ -358,7 +357,7 @@ void init_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pi void cleanup_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece) { -// clean up everything again. + // clean up everything again. dt_iop_colorzones_data_t *d = (dt_iop_colorzones_data_t *)(piece->data); for(int ch = 0; ch < 3; ch++) dt_draw_curve_destroy(d->curve[ch]); @@ -380,14 +379,13 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_colorzones_params_t)); module->default_params = calloc(1, sizeof(dt_iop_colorzones_params_t)); module->default_enabled = 0; // we're a rather slow and rare op. - module->priority = 602; // module order created by iop_dependencies.py, do not edit! + module->priority = 608; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_colorzones_params_t); module->gui_data = NULL; dt_iop_colorzones_params_t tmp; for(int ch = 0; ch < 3; ch++) { - for(int k = 0; k < DT_IOP_COLORZONES_BANDS; k++) - tmp.equalizer_x[ch][k] = k / (DT_IOP_COLORZONES_BANDS - 1.0); + for(int k = 0; k < DT_IOP_COLORZONES_BANDS; k++) tmp.equalizer_x[ch][k] = k / (DT_IOP_COLORZONES_BANDS - 1.0); for(int k = 0; k < DT_IOP_COLORZONES_BANDS; k++) tmp.equalizer_y[ch][k] = 0.5f; } tmp.strength = 0.0; @@ -422,8 +420,7 @@ void init_presets(dt_iop_module_so_t *self) p.equalizer_x[DT_IOP_COLORZONES_C][k] = k / (DT_IOP_COLORZONES_BANDS - 1.); p.equalizer_x[DT_IOP_COLORZONES_h][k] = k / (DT_IOP_COLORZONES_BANDS - 1.); } - p.equalizer_y[DT_IOP_COLORZONES_C][0] = p.equalizer_y[DT_IOP_COLORZONES_C][DT_IOP_COLORZONES_BANDS - 1] - = 0.65; + p.equalizer_y[DT_IOP_COLORZONES_C][0] = p.equalizer_y[DT_IOP_COLORZONES_C][DT_IOP_COLORZONES_BANDS - 1] = 0.65; p.equalizer_x[DT_IOP_COLORZONES_C][1] = 3. / 16.; p.equalizer_x[DT_IOP_COLORZONES_C][3] = 0.50; p.equalizer_x[DT_IOP_COLORZONES_C][4] = 0.51; @@ -442,8 +439,7 @@ void init_presets(dt_iop_module_so_t *self) p.equalizer_x[DT_IOP_COLORZONES_C][k] = k / (DT_IOP_COLORZONES_BANDS - 1.); p.equalizer_x[DT_IOP_COLORZONES_h][k] = k / (DT_IOP_COLORZONES_BANDS - 1.); } - p.equalizer_y[DT_IOP_COLORZONES_C][0] = p.equalizer_y[DT_IOP_COLORZONES_C][DT_IOP_COLORZONES_BANDS - 1] - = 0.5; + p.equalizer_y[DT_IOP_COLORZONES_C][0] = p.equalizer_y[DT_IOP_COLORZONES_C][DT_IOP_COLORZONES_BANDS - 1] = 0.5; p.equalizer_x[DT_IOP_COLORZONES_C][2] = 0.25f; p.equalizer_x[DT_IOP_COLORZONES_C][1] = 0.16f; p.equalizer_y[DT_IOP_COLORZONES_C][1] = 0.3f; @@ -535,8 +531,7 @@ static void dt_iop_colorzones_get_params(dt_iop_colorzones_params_t *p, const in // periodic boundary for(int k = 1; k < DT_IOP_COLORZONES_BANDS - 1; k++) { - const float f - = expf(-(mouse_x - p->equalizer_x[ch][k]) * (mouse_x - p->equalizer_x[ch][k]) / (rad * rad)); + const float f = expf(-(mouse_x - p->equalizer_x[ch][k]) * (mouse_x - p->equalizer_x[ch][k]) / (rad * rad)); p->equalizer_y[ch][k] = (1 - f) * p->equalizer_y[ch][k] + f * mouse_y; } const int m = DT_IOP_COLORZONES_BANDS - 1; @@ -550,8 +545,7 @@ static void dt_iop_colorzones_get_params(dt_iop_colorzones_params_t *p, const in { for(int k = 0; k < DT_IOP_COLORZONES_BANDS; k++) { - const float f - = expf(-(mouse_x - p->equalizer_x[ch][k]) * (mouse_x - p->equalizer_x[ch][k]) / (rad * rad)); + const float f = expf(-(mouse_x - p->equalizer_x[ch][k]) * (mouse_x - p->equalizer_x[ch][k]) / (rad * rad)); p->equalizer_y[ch][k] = (1 - f) * p->equalizer_y[ch][k] + f * mouse_y; } } @@ -587,7 +581,7 @@ static gboolean colorzones_draw(GtkWidget *widget, cairo_t *crf, gpointer user_d // clear bg, match color of the notebook tabs: GdkRGBA color; GtkStyleContext *context = gtk_widget_get_style_context(widget); - gboolean color_found = gtk_style_context_lookup_color (context, "selected_bg_color", &color); + gboolean color_found = gtk_style_context_lookup_color(context, "selected_bg_color", &color); if(!color_found) { color.red = 1.0; @@ -629,8 +623,7 @@ static gboolean colorzones_draw(GtkWidget *widget, cairo_t *crf, gpointer user_d else dt_draw_curve_set_point(c->minmax_curve, DT_IOP_COLORZONES_BANDS + 1, p.equalizer_x[ch][1] + 1.0, p.equalizer_y[ch][DT_IOP_COLORZONES_BANDS - 1]); - dt_draw_curve_calc_values(c->minmax_curve, 0.0, 1.0, DT_IOP_COLORZONES_RES, c->draw_min_xs, - c->draw_min_ys); + dt_draw_curve_calc_values(c->minmax_curve, 0.0, 1.0, DT_IOP_COLORZONES_RES, c->draw_min_xs, c->draw_min_ys); p = *(dt_iop_colorzones_params_t *)self->params; dt_iop_colorzones_get_params(&p, c->channel, c->mouse_x, .0, c->mouse_radius); @@ -648,8 +641,7 @@ static gboolean colorzones_draw(GtkWidget *widget, cairo_t *crf, gpointer user_d else dt_draw_curve_set_point(c->minmax_curve, DT_IOP_COLORZONES_BANDS + 1, p.equalizer_x[ch][1] + 1.0, p.equalizer_y[ch][DT_IOP_COLORZONES_BANDS - 1]); - dt_draw_curve_calc_values(c->minmax_curve, 0.0, 1.0, DT_IOP_COLORZONES_RES, c->draw_max_xs, - c->draw_max_ys); + dt_draw_curve_calc_values(c->minmax_curve, 0.0, 1.0, DT_IOP_COLORZONES_RES, c->draw_max_xs, c->draw_max_ys); } if(self->picked_color_max[0] < 0.0f || self->picked_color[0] == 0.0f) @@ -716,7 +708,7 @@ static gboolean colorzones_draw(GtkWidget *widget, cairo_t *crf, gpointer user_d const float Lcap = fminf(100.0, Lab.L); const float clip = 1.0 - (Lcap - L0) * (1.0 / 100.0) * fminf(Lwhite - Lclip, fmaxf(0.0, Lab.L - Lclip)) - / (Lwhite - Lclip); + / (Lwhite - Lclip); const float clip2 = clip * clip * clip; Lab.a *= Lab.L / L0 * clip2; Lab.b *= Lab.L / L0 * clip2; @@ -934,8 +926,7 @@ static gboolean colorzones_button_press(GtkWidget *widget, GdkEventButton *event gtk_widget_get_allocation(widget, &allocation); const int inset = DT_IOP_COLORZONES_INSET; int height = allocation.height - 2 * inset, width = allocation.width - 2 * inset; - c->mouse_pick - = dt_draw_curve_calc_value(c->minmax_curve, CLAMP(event->x - inset, 0, width) / (float)width); + c->mouse_pick = dt_draw_curve_calc_value(c->minmax_curve, CLAMP(event->x - inset, 0, width) / (float)width); c->mouse_pick -= 1.0 - CLAMP(event->y - inset, 0, height) / (float)height; c->dragging = 1; return TRUE; @@ -1067,20 +1058,18 @@ void gui_init(struct dt_iop_module_t *self) c->channel_tabs = GTK_NOTEBOOK(gtk_notebook_new()); - gtk_notebook_append_page(GTK_NOTEBOOK(c->channel_tabs), - GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)), + gtk_notebook_append_page(GTK_NOTEBOOK(c->channel_tabs), GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)), gtk_label_new(_("lightness"))); - gtk_notebook_append_page(GTK_NOTEBOOK(c->channel_tabs), - GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)), + gtk_notebook_append_page(GTK_NOTEBOOK(c->channel_tabs), GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)), gtk_label_new(_("saturation"))); - gtk_notebook_append_page(GTK_NOTEBOOK(c->channel_tabs), - GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)), gtk_label_new(_("hue"))); + gtk_notebook_append_page(GTK_NOTEBOOK(c->channel_tabs), GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)), + gtk_label_new(_("hue"))); gtk_widget_show_all(GTK_WIDGET(gtk_notebook_get_nth_page(c->channel_tabs, c->channel))); gtk_notebook_set_current_page(GTK_NOTEBOOK(c->channel_tabs), c->channel); gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(c->channel_tabs), FALSE, FALSE, 0); - GtkWidget *tb = dtgtk_togglebutton_new(dtgtk_cairo_paint_colorpicker, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); + GtkWidget *tb = dtgtk_togglebutton_new(dtgtk_cairo_paint_colorpicker, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); gtk_widget_set_size_request(GTK_WIDGET(tb), DT_PIXEL_APPLY_DPI(14), DT_PIXEL_APPLY_DPI(14)); gtk_widget_set_tooltip_text(tb, _("pick GUI color from image")); g_signal_connect(G_OBJECT(tb), "toggled", G_CALLBACK(request_pick_toggled), self); @@ -1113,9 +1102,9 @@ void gui_init(struct dt_iop_module_t *self) gtk_widget_add_events(GTK_WIDGET(c->area), GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK - | GDK_SMOOTH_SCROLL_MASK); + | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK + | GDK_SMOOTH_SCROLL_MASK); g_signal_connect(G_OBJECT(c->area), "draw", G_CALLBACK(colorzones_draw), self); g_signal_connect(G_OBJECT(c->area), "button-press-event", G_CALLBACK(colorzones_button_press), self); g_signal_connect(G_OBJECT(c->area), "button-release-event", G_CALLBACK(colorzones_button_release), self); diff --git a/src/iop/defringe.c b/src/iop/defringe.c index 0c8e7d33eb05..a1eb1e992c02 100644 --- a/src/iop/defringe.c +++ b/src/iop/defringe.c @@ -138,8 +138,8 @@ static inline void fib_latt(int *const x, int *const y, float radius, int step, // most are chosen arbitrarily and/or by experiment/trial+error ... I am sorry ;-) // and having everything user-defineable would be just too much // ----------------------------------------------------------------------------------------- -void process(struct dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, const void *const i, - void *const o, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) +void process(struct dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, const void *const i, void *const o, + const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) { dt_iop_defringe_data_t *d = (dt_iop_defringe_data_t *)piece->data; assert(dt_iop_module_colorspace(module) == iop_cs_Lab); @@ -249,8 +249,7 @@ void process(struct dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, cons } #ifdef _OPENMP -#pragma omp parallel for default(none) shared(width, height, \ - d) reduction(+ : avg_edge_chroma) schedule(static) +#pragma omp parallel for default(none) shared(width, height, d) reduction(+ : avg_edge_chroma) schedule(static) #endif for(int v = 0; v < height; v++) { @@ -286,8 +285,8 @@ void process(struct dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, cons #ifdef _OPENMP // dynamically/guided scheduled due to possible uneven edge-chroma distribution (thanks to rawtherapee code // for this hint!) -#pragma omp parallel for default(none) shared(width, height, d, xy_small, xy_avg, xy_artifact) \ - firstprivate(thresh, avg_edge_chroma) schedule(guided, 32) +#pragma omp parallel for default(none) shared(width, height, d, xy_small, xy_avg, xy_artifact) \ + firstprivate(thresh, avg_edge_chroma) schedule(guided, 32) #endif for(int v = 0; v < height; v++) { @@ -321,8 +320,7 @@ void process(struct dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, cons || out[(size_t)v * width * ch + MIN(width - 1, (t + 1)) * ch + 3] > local_thresh || out[(size_t)MIN(height - 1, (v + 1)) * width * ch + MAX(0, (t - 1)) * ch + 3] > local_thresh || out[(size_t)MIN(height - 1, (v + 1)) * width * ch + t * ch + 3] > local_thresh - || out[(size_t)MIN(height - 1, (v + 1)) * width * ch + MIN(width - 1, (t + 1)) * ch + 3] - > local_thresh) + || out[(size_t)MIN(height - 1, (v + 1)) * width * ch + MIN(width - 1, (t + 1)) * ch + 3] > local_thresh) { float atot = 0, btot = 0; float norm = 0; @@ -369,7 +367,8 @@ void process(struct dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, cons } } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(i, o, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(i, o, roi_out->width, roi_out->height); goto FINISH_PROCESS; @@ -395,7 +394,7 @@ void init(dt_iop_module_t *module) { module->params = calloc(1, sizeof(dt_iop_defringe_params_t)); module->default_params = calloc(1, sizeof(dt_iop_defringe_params_t)); - module->priority = 397; // module order created by iop_dependencies.py, do not edit! + module->priority = 405; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_defringe_params_t); module->gui_data = NULL; module->data = NULL; @@ -445,7 +444,8 @@ void gui_init(dt_iop_module_t *module) dt_bauhaus_combobox_add(g->mode_select, _("global average (fast)")); // 0 dt_bauhaus_combobox_add(g->mode_select, _("local average (slow)")); // 1 dt_bauhaus_combobox_add(g->mode_select, _("static threshold (fast)")); // 2 - gtk_widget_set_tooltip_text(g->mode_select, + gtk_widget_set_tooltip_text( + g->mode_select, _("method for color protection:\n - global average: fast, might show slightly wrong previews in high " "magnification; might sometimes protect saturation too much or too low in comparison to local " "average\n - local average: slower, might protect saturation better than global average by using " diff --git a/src/iop/demosaic.c b/src/iop/demosaic.c index 2294d4c30dee..776ae36339de 100644 --- a/src/iop/demosaic.c +++ b/src/iop/demosaic.c @@ -71,10 +71,10 @@ typedef enum dt_iop_demosaic_qual_flags_t { // either perform full scale demosaicing or choose simple half scale // or third scale interpolation instead - DEMOSAIC_FULL_SCALE = 1 << 0, - DEMOSAIC_ONLY_VNG_LINEAR = 1 << 1, + DEMOSAIC_FULL_SCALE = 1 << 0, + DEMOSAIC_ONLY_VNG_LINEAR = 1 << 1, DEMOSAIC_XTRANS_FULL_MARKESTEIJN = 1 << 2, - DEMOSAIC_MEDIUM_QUAL = 1 << 3 + DEMOSAIC_MEDIUM_QUAL = 1 << 3 } dt_iop_demosaic_qual_flags_t; typedef struct dt_iop_demosaic_params_t @@ -178,8 +178,8 @@ void connect_key_accels(dt_iop_module_t *self) GTK_WIDGET(((dt_iop_demosaic_gui_data_t *)self->gui_data)->median_thrs)); } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 2 && new_version == 3) { @@ -196,7 +196,7 @@ int legacy_params(dt_iop_module_t *self, const void *const old_params, const int } #ifdef HAVE_OPENCL -static const char* method2string(dt_iop_demosaic_method_t method) +static const char *method2string(dt_iop_demosaic_method_t method) { const char *string; @@ -230,11 +230,11 @@ static const char* method2string(dt_iop_demosaic_method_t method) } #endif -#define SWAP(a, b) \ - { \ - const float tmp = (b); \ - (b) = (a); \ - (a) = tmp; \ +#define SWAP(a, b) \ + { \ + const float tmp = (b); \ + (b) = (a); \ + (a) = tmp; \ } static void pre_median_b(float *out, const float *const in, const dt_iop_roi_t *const roi, const uint32_t filters, @@ -346,7 +346,7 @@ static void pre_median(float *out, const float *const in, const dt_iop_roi_t *co pre_median_b(out, in, roi, filters, num_passes, threshold); } -#define SWAPmed(I, J) \ +#define SWAPmed(I, J) \ if(med[I] > med[J]) SWAP(med[I], med[J]) static void color_smoothing(float *out, const dt_iop_roi_t *const roi_out, const int num_passes) @@ -504,8 +504,7 @@ static void green_equilibration_favg(float *out, const float *const in, const in #define TS 122 /** Lookup for allhex[], making sure that row/col aren't negative **/ -static inline const short *const hexmap(const int row, const int col, - short (*const allhex)[3][8]) +static inline const short *const hexmap(const int row, const int col, short (*const allhex)[3][8]) { // Row and column offsets may be negative, but C's modulo function // is not useful here with a negative dividend. To be safe, add a @@ -520,10 +519,9 @@ static inline const short *const hexmap(const int row, const int col, /* Frank Markesteijn's algorithm for Fuji X-Trans sensors */ -static void xtrans_markesteijn_interpolate(float *out, const float *const in, - const dt_iop_roi_t *const roi_out, - const dt_iop_roi_t *const roi_in, - const uint8_t (*const xtrans)[6], const int passes) +static void xtrans_markesteijn_interpolate(float *out, const float *const in, const dt_iop_roi_t *const roi_out, + const dt_iop_roi_t *const roi_in, const uint8_t (*const xtrans)[6], + const int passes) { static const short orth[12] = { 1, 0, 0, 1, -1, 0, 0, -1, 1, 0, 0, 1 }, patt[2][16] = { { 0, 1, 0, -1, 2, 0, -1, 0, 1, 1, 1, -1, 0, 0, 0, 0 }, @@ -581,7 +579,7 @@ static void xtrans_markesteijn_interpolate(float *out, const float *const in, #endif // step through TSxTS cells of image, each tile overlapping the // prior as interpolation needs a substantial border - for(int top = -pad_tile; top < height - pad_tile; top += TS - (pad_tile*2)) + for(int top = -pad_tile; top < height - pad_tile; top += TS - (pad_tile * 2)) { char *const buffer = all_buffers + dt_get_thread_num() * buffer_size; // rgb points to ndir TSxTS tiles of 3 channels (R, G, and B) @@ -599,10 +597,10 @@ static void xtrans_markesteijn_interpolate(float *out, const float *const in, // homo and homosum reuse memory which is used earlier in the // loop; each points to ndir single-channel TSxTS tiles uint8_t (*const homo)[TS][TS] = (uint8_t(*)[TS][TS])(buffer + TS * TS * (ndir * 3) * sizeof(float)); - uint8_t (*const homosum)[TS][TS] = (uint8_t(*)[TS][TS])(buffer + TS * TS * (ndir * 3) * sizeof(float) - + TS * TS * ndir * sizeof(uint8_t)); + uint8_t (*const homosum)[TS][TS] + = (uint8_t(*)[TS][TS])(buffer + TS * TS * (ndir * 3) * sizeof(float) + TS * TS * ndir * sizeof(uint8_t)); - for(int left = -pad_tile; left < width - pad_tile; left += TS - (pad_tile*2)) + for(int left = -pad_tile; left < width - pad_tile; left += TS - (pad_tile * 2)) { int mrow = MIN(top + TS, height + pad_tile); int mcol = MIN(left + TS, width + pad_tile); @@ -691,7 +689,7 @@ static void xtrans_markesteijn_interpolate(float *out, const float *const in, if(max == 0.0f) { float (*const pix)[3] = &rgb[0][row - top][col - left]; - const short *const hex = hexmap(row,col,allhex); + const short *const hex = hexmap(row, col, allhex); for(int c = 0; c < 6; c++) { const float val = pix[hex[c]][1]; @@ -727,7 +725,7 @@ static void xtrans_markesteijn_interpolate(float *out, const float *const in, int f = FCxtrans(row, col, roi_in, xtrans); if(f == 1) continue; float (*const pix)[3] = &rgb[0][row - top][col - left]; - const short *const hex = hexmap(row,col,allhex); + const short *const hex = hexmap(row, col, allhex); // TODO: these constants come from integer math constants in // dcraw -- calculate them instead from interpolation math color[0] = 0.6796875f * (pix[hex[1]][1] + pix[hex[0]][1]) @@ -761,12 +759,12 @@ static void xtrans_markesteijn_interpolate(float *out, const float *const in, { int f = FCxtrans(row, col, roi_in, xtrans); if(f == 1) continue; - const short *const hex = hexmap(row,col,allhex); + const short *const hex = hexmap(row, col, allhex); for(int d = 3; d < 6; d++) { float(*rfx)[3] = &rgb[(d - 2) ^ !((row - sgrow) % 3)][row - top][col - left]; - float val = rfx[-2 * hex[d]][1] + 2 * rfx[hex[d]][1] - rfx[-2 * hex[d]][f] - - 2 * rfx[hex[d]][f] + 3 * rfx[0][f]; + float val = rfx[-2 * hex[d]][1] + 2 * rfx[hex[d]][1] - rfx[-2 * hex[d]][f] - 2 * rfx[hex[d]][f] + + 3 * rfx[0][f]; rfx[0][1] = CLAMPS(val / 3.0f, gmin[row - top][col - left], gmax[row - top][col - left]); } } @@ -810,13 +808,12 @@ static void xtrans_markesteijn_interpolate(float *out, const float *const in, // For 2nd and 3rd hori+vert passes, create a sum of // steepness for both cardinal directions. if(d > 1) - diff[d] += SQR(rfx[i << c][1] - rfx[-(i << c)][1] - rfx[i << c][h] + rfx[-(i << c)][h]) - + SQR(g); + diff[d] += SQR(rfx[i << c][1] - rfx[-(i << c)][1] - rfx[i << c][h] + rfx[-(i << c)][h]) + SQR(g); } if((d < 2) || (d & 1)) { // output for passes 0, 1, 3, 5 // for 0, 1 just use hori/vert, for 3, 5 use best of x/y dir - const int d_out = d - ((d > 1) && (diff[d-1] < diff[d])); + const int d_out = d - ((d > 1) && (diff[d - 1] < diff[d])); rfx[0][0] = color[0][d_out] / 2.f; rfx[0][2] = color[1][d_out] / 2.f; rfx += TS * TS; @@ -836,9 +833,11 @@ static void xtrans_markesteijn_interpolate(float *out, const float *const in, int h = 3 * (c ^ TS ^ 1); for(int d = 0; d < 4; d++, rfx += TS * TS) { - int i = d > 1 || ((d ^ c) & 1) || - ((fabsf(rfx[0][1]-rfx[c][1]) + fabsf(rfx[0][1]-rfx[-c][1])) < - 2.f*(fabsf(rfx[0][1]-rfx[h][1]) + fabsf(rfx[0][1]-rfx[-h][1]))) ? c:h; + int i = d > 1 || ((d ^ c) & 1) + || ((fabsf(rfx[0][1] - rfx[c][1]) + fabsf(rfx[0][1] - rfx[-c][1])) + < 2.f * (fabsf(rfx[0][1] - rfx[h][1]) + fabsf(rfx[0][1] - rfx[-h][1]))) + ? c + : h; rfx[0][f] = (rfx[i][f] + rfx[-i][f] + 2.f * rfx[0][1] - rfx[i][1] - rfx[-i][1]) / 2.f; } } @@ -851,7 +850,7 @@ static void xtrans_markesteijn_interpolate(float *out, const float *const in, if((col - sgcol) % 3) { float(*rfx)[3] = &rgb[0][row - top][col - left]; - const short *const hex = hexmap(row,col,allhex); + const short *const hex = hexmap(row, col, allhex); for(int d = 0; d < ndir; d += 2, rfx += TS * TS) if(hex[d] + hex[d + 1]) { @@ -862,8 +861,7 @@ static void xtrans_markesteijn_interpolate(float *out, const float *const in, else { float g = 2.f * rfx[0][1] - rfx[hex[d]][1] - rfx[hex[d + 1]][1]; - for(int c = 0; c < 4; c += 2) - rfx[0][c] = (g + rfx[hex[d]][c] + rfx[hex[d + 1]][c]) / 2.f; + for(int c = 0; c < 4; c += 2) rfx[0][c] = (g + rfx[hex[d]][c] + rfx[hex[d + 1]][c]) / 2.f; } } } // end of multipass loop @@ -937,7 +935,7 @@ static void xtrans_markesteijn_interpolate(float *out, const float *const in, { // start before first column where homo[d][row][col+2] != 0, // so can know v5sum and homosum[d][row][col] will be 0 - int col = pad_tile-5; + int col = pad_tile - 5; uint8_t v5sum[5] = { 0 }; homosum[d][row][col] = 0; // calculate by rolling through column sums @@ -974,9 +972,7 @@ static void xtrans_markesteijn_interpolate(float *out, const float *const in, for(int c = 0; c < 3; c++) avg[c] += rgb[d][row][col][c]; avg[3]++; } - for(int c = 0; c < 3; c++) - out[4 * (width * (row + top) + col + left) + c] = - avg[c]/avg[3]; + for(int c = 0; c < 3; c++) out[4 * (width * (row + top) + col + left) + c] = avg[c] / avg[3]; } } } @@ -1037,7 +1033,7 @@ static void lin_interpolate(float *out, const float *const in, const dt_iop_roi_ // COLORB TOT_WEIGHT // COLORPIX # color of center pixel - int(*const lookup)[16][32] = malloc((size_t)16 * 16 * 32 * sizeof(int)); + int (*const lookup)[16][32] = malloc((size_t)16 * 16 * 32 * sizeof(int)); const int size = (filters == 9) ? 6 : 16; for(int row = 0; row < size; row++) @@ -1105,9 +1101,9 @@ static void lin_interpolate(float *out, const float *const in, const dt_iop_roi_ I've extended the basic idea to work with non-Bayer filter arrays. Gradients are numbered clockwise from NW=0 to W=7. */ -static void vng_interpolate(float *out, const float *const in, - const dt_iop_roi_t *const roi_out, const dt_iop_roi_t *const roi_in, - const uint32_t filters, const uint8_t (*const xtrans)[6], const int only_vng_linear) +static void vng_interpolate(float *out, const float *const in, const dt_iop_roi_t *const roi_out, + const dt_iop_roi_t *const roi_in, const uint32_t filters, + const uint8_t (*const xtrans)[6], const int only_vng_linear) { static const signed char terms[] = { -2, -2, +0, -1, 1, 0x01, -2, -2, +0, +0, 2, 0x01, -2, -1, -1, +0, 1, 0x01, -2, -1, +0, -1, 1, 0x02, @@ -1150,8 +1146,7 @@ static void vng_interpolate(float *out, const float *const in, // if only linear interpolation is requested we can stop it here if(only_vng_linear) return; - char *buffer - = (char *)dt_alloc_align(16, (size_t)sizeof(**brow) * width * 3 + sizeof(*ip) * prow * pcol * 320); + char *buffer = (char *)dt_alloc_align(16, (size_t)sizeof(**brow) * width * 3 + sizeof(*ip) * prow * pcol * 320); if(!buffer) { fprintf(stderr, "[demosaic] not able to allocate VNG buffer\n"); @@ -1173,10 +1168,9 @@ static void vng_interpolate(float *out, const float *const in, int grads = *cp++; int color = fcol(row + y1, col + x1, filters4, xtrans); if(fcol(row + y2, col + x2, filters4, xtrans) != color) continue; - int diag - = (fcol(row, col + 1, filters4, xtrans) == color && fcol(row + 1, col, filters4, xtrans) == color) - ? 2 - : 1; + int diag = (fcol(row, col + 1, filters4, xtrans) == color && fcol(row + 1, col, filters4, xtrans) == color) + ? 2 + : 1; if(abs(y1 - y2) == diag && abs(x1 - x2) == diag) continue; *ip++ = (y1 * width + x1) * 4 + color; *ip++ = (y2 * width + x2) * 4 + color; @@ -1438,7 +1432,7 @@ static void demosaic_ppg(float *const out, const float *const in, const dt_iop_r float *buf = out + (size_t)4 * roi_out->width * j + 4; for(int i = 1; i < roi_out->width - 1; i++) { - // also prefetch direct nbs top/bottom +// also prefetch direct nbs top/bottom #if defined(__SSE__) _mm_prefetch((char *)buf + 256, _MM_HINT_NTA); _mm_prefetch((char *)buf - roi_out->width * 4 * sizeof(float) + 256, _MM_HINT_NTA); @@ -1531,8 +1525,8 @@ void modify_roi_out(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t // which roi input is needed to process to this output? // roi_out is unchanged, full buffer in is full buffer out. -void modify_roi_in(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_out, dt_iop_roi_t *roi_in) +void modify_roi_in(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const dt_iop_roi_t *roi_out, + dt_iop_roi_t *roi_in) { // this op is disabled for preview pipe/filters == 0 @@ -1586,14 +1580,22 @@ static int get_thumb_quality(int width, int height) int level = dt_mipmap_cache_get_matching_size(darktable.mipmap_cache, width, height); int res = 0; - if (strcmp(min, "always")==0) res = 1; - else if (strcmp(min, "small")==0) res = ( level >= 1 ); - else if (strcmp(min, "VGA")==0) res = ( level >= 2 ); - else if (strcmp(min, "720p")==0) res = ( level >= 3 ); - else if (strcmp(min, "1080p")==0) res = ( level >= 4 ); - else if (strcmp(min, "WQXGA")==0) res = ( level >= 5 ); - else if (strcmp(min, "4k")==0) res = ( level >= 6 ); - else if (strcmp(min, "5K")==0) res = ( level >= 7 ); + if(strcmp(min, "always") == 0) + res = 1; + else if(strcmp(min, "small") == 0) + res = (level >= 1); + else if(strcmp(min, "VGA") == 0) + res = (level >= 2); + else if(strcmp(min, "720p") == 0) + res = (level >= 3); + else if(strcmp(min, "1080p") == 0) + res = (level >= 4); + else if(strcmp(min, "WQXGA") == 0) + res = (level >= 5); + else if(strcmp(min, "4k") == 0) + res = (level >= 6); + else if(strcmp(min, "5K") == 0) + res = (level >= 7); g_free(min); return res; @@ -1601,28 +1603,26 @@ static int get_thumb_quality(int width, int height) // set flags for demosaic quality based on factors besides demosaic // method (e.g. config, scale, pixelpipe type) -static int demosaic_qual_flags(const dt_dev_pixelpipe_iop_t *const piece, - const dt_image_t *const img, +static int demosaic_qual_flags(const dt_dev_pixelpipe_iop_t *const piece, const dt_image_t *const img, const dt_iop_roi_t *const roi_out) { int flags = 0; - switch (piece->pipe->type) + switch(piece->pipe->type) { case DT_DEV_PIXELPIPE_FULL: - { - const int qual = get_quality(); - if (qual > 0) flags |= DEMOSAIC_FULL_SCALE; - if (qual > 1) flags |= DEMOSAIC_XTRANS_FULL_MARKESTEIJN; - if ((qual < 2) && (roi_out->scale <= .99999f)) - flags |= DEMOSAIC_MEDIUM_QUAL; - } - break; + { + const int qual = get_quality(); + if(qual > 0) flags |= DEMOSAIC_FULL_SCALE; + if(qual > 1) flags |= DEMOSAIC_XTRANS_FULL_MARKESTEIJN; + if((qual < 2) && (roi_out->scale <= .99999f)) flags |= DEMOSAIC_MEDIUM_QUAL; + } + break; case DT_DEV_PIXELPIPE_EXPORT: flags |= DEMOSAIC_FULL_SCALE | DEMOSAIC_XTRANS_FULL_MARKESTEIJN; break; case DT_DEV_PIXELPIPE_THUMBNAIL: // we check if we need ultra-high quality thumbnail for this size - if (get_thumb_quality(roi_out->width, roi_out->height)) + if(get_thumb_quality(roi_out->width, roi_out->height)) { flags |= DEMOSAIC_FULL_SCALE | DEMOSAIC_XTRANS_FULL_MARKESTEIJN; } @@ -1636,23 +1636,22 @@ static int demosaic_qual_flags(const dt_dev_pixelpipe_iop_t *const piece, // possible to skip the full demosaic and perform a quick downscale. // Note even though the X-Trans CFA is 6x6, for this purposes we can // see each 6x6 tile as four fairly similar 3x3 tiles - if (roi_out->scale > (piece->pipe->dsc.filters == 9u ? 0.333f : 0.5f)) + if(roi_out->scale > (piece->pipe->dsc.filters == 9u ? 0.333f : 0.5f)) { flags |= DEMOSAIC_FULL_SCALE; } // half_size_f doesn't support 4bayer images - if (img->flags & DT_IMAGE_4BAYER) flags |= DEMOSAIC_FULL_SCALE; + if(img->flags & DT_IMAGE_4BAYER) flags |= DEMOSAIC_FULL_SCALE; // we use full Markesteijn demosaicing on xtrans sensors if maximum // quality is required - if (roi_out->scale > 0.667f) + if(roi_out->scale > 0.667f) { flags |= DEMOSAIC_XTRANS_FULL_MARKESTEIJN; } // we check if we can stop at the linear interpolation step in VNG // instead of going the full way - if ((flags & DEMOSAIC_FULL_SCALE) && - (roi_out->scale < (piece->pipe->dsc.filters == 9u ? 0.5f : 0.667f))) + if((flags & DEMOSAIC_FULL_SCALE) && (roi_out->scale < (piece->pipe->dsc.filters == 9u ? 0.5f : 0.667f))) { flags |= DEMOSAIC_ONLY_VNG_LINEAR; } @@ -1671,14 +1670,13 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const roo.x = roo.y = 0; // roi_out->scale = global scale: (iscale == 1.0, always when demosaic is on) - const uint8_t(*const xtrans)[6] = (const uint8_t(*const)[6])piece->pipe->dsc.xtrans; + const uint8_t (*const xtrans)[6] = (const uint8_t (*const)[6])piece->pipe->dsc.xtrans; dt_iop_demosaic_data_t *data = (dt_iop_demosaic_data_t *)piece->data; const int qual_flags = demosaic_qual_flags(piece, img, roi_out); int demosaicing_method = data->demosaicing_method; - if((qual_flags & DEMOSAIC_MEDIUM_QUAL) - && // only overwrite setting if quality << requested and in dr mode + if((qual_flags & DEMOSAIC_MEDIUM_QUAL) && // only overwrite setting if quality << requested and in dr mode (demosaicing_method != DT_IOP_DEMOSAIC_PASSTHROUGH_MONOCHROME)) // do not touch this special method demosaicing_method = (piece->pipe->dsc.filters != 9u) ? DT_IOP_DEMOSAIC_PPG : DT_IOP_DEMOSAIC_MARKESTEIJN; @@ -1688,7 +1686,7 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const { // Full demosaic and then scaling if needed const int scaled = (roi_out->width != roi_in->width || roi_out->height != roi_in->height); - float *tmp = (float *) o; + float *tmp = (float *)o; if(scaled) { // demosaic and then clip and zoom @@ -1710,7 +1708,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const xtrans_markesteijn_interpolate(tmp, pixels, &roo, &roi, xtrans, 1 + (demosaicing_method - DT_IOP_DEMOSAIC_MARKESTEIJN) * 2); else - vng_interpolate(tmp, pixels, &roo, &roi, piece->pipe->dsc.filters, xtrans, qual_flags & DEMOSAIC_ONLY_VNG_LINEAR); + vng_interpolate(tmp, pixels, &roo, &roi, piece->pipe->dsc.filters, xtrans, + qual_flags & DEMOSAIC_ONLY_VNG_LINEAR); } else { @@ -1743,10 +1742,11 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const if(demosaicing_method == DT_IOP_DEMOSAIC_VNG4 || (img->flags & DT_IMAGE_4BAYER)) { - vng_interpolate(tmp, in, &roo, &roi, piece->pipe->dsc.filters, xtrans, qual_flags & DEMOSAIC_ONLY_VNG_LINEAR); - if (img->flags & DT_IMAGE_4BAYER) + vng_interpolate(tmp, in, &roo, &roi, piece->pipe->dsc.filters, xtrans, + qual_flags & DEMOSAIC_ONLY_VNG_LINEAR); + if(img->flags & DT_IMAGE_4BAYER) { - dt_colorspaces_cygm_to_rgb(tmp, roo.width*roo.height, data->CAM_to_RGB); + dt_colorspaces_cygm_to_rgb(tmp, roo.width * roo.height, data->CAM_to_RGB); dt_colorspaces_cygm_to_rgb(piece->pipe->dsc.processed_maximum, 1, data->CAM_to_RGB); } } @@ -1798,13 +1798,16 @@ static int color_smoothing_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop cl_mem dev_tmp = dt_opencl_alloc_device(devid, width, height, 4 * sizeof(float)); if(dev_tmp == NULL) goto error; - dt_opencl_local_buffer_t locopt - = (dt_opencl_local_buffer_t){ .xoffset = 2*1, .xfactor = 1, .yoffset = 2*1, .yfactor = 1, - .cellsize = 4 * sizeof(float), .overhead = 0, - .sizex = 1 << 8, .sizey = 1 << 8 }; + dt_opencl_local_buffer_t locopt = (dt_opencl_local_buffer_t){.xoffset = 2 * 1, + .xfactor = 1, + .yoffset = 2 * 1, + .yfactor = 1, + .cellsize = 4 * sizeof(float), + .overhead = 0, + .sizex = 1 << 8, + .sizey = 1 << 8 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_color_smoothing, &locopt)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_color_smoothing, &locopt)) goto error; // two buffer references for our ping-pong cl_mem dev_t1 = dev_out; @@ -1819,7 +1822,7 @@ static int color_smoothing_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop dt_opencl_set_kernel_arg(devid, gd->kernel_color_smoothing, 2, sizeof(int), &width); dt_opencl_set_kernel_arg(devid, gd->kernel_color_smoothing, 3, sizeof(int), &height); dt_opencl_set_kernel_arg(devid, gd->kernel_color_smoothing, 4, - (locopt.sizex + 2) * (locopt.sizey + 2) * 4 * sizeof(float), NULL); + (locopt.sizex + 2) * (locopt.sizey + 2) * 4 * sizeof(float), NULL); err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_color_smoothing, sizes, local); if(err != CL_SUCCESS) goto error; @@ -1899,13 +1902,16 @@ static int green_equilibration_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe if(data->green_eq == DT_IOP_GREEN_EQ_FULL || data->green_eq == DT_IOP_GREEN_EQ_BOTH) { - dt_opencl_local_buffer_t flocopt - = (dt_opencl_local_buffer_t){ .xoffset = 0, .xfactor = 1, .yoffset = 0, .yfactor = 1, - .cellsize = 2 * sizeof(float), .overhead = 0, - .sizex = 1 << 4, .sizey = 1 << 4 }; + dt_opencl_local_buffer_t flocopt = (dt_opencl_local_buffer_t){.xoffset = 0, + .xfactor = 1, + .yoffset = 0, + .yfactor = 1, + .cellsize = 2 * sizeof(float), + .overhead = 0, + .sizex = 1 << 4, + .sizey = 1 << 4 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_green_eq_favg_reduce_first, &flocopt)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_green_eq_favg_reduce_first, &flocopt)) goto error; const size_t bwidth = ROUNDUP(width, flocopt.sizex); const size_t bheight = ROUNDUP(height, flocopt.sizey); @@ -1921,22 +1927,25 @@ static int green_equilibration_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_reduce_first, 1, sizeof(int), &width); dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_reduce_first, 2, sizeof(int), &height); dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_reduce_first, 3, sizeof(cl_mem), &dev_m); - dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_reduce_first, 4, sizeof(uint32_t), (void *)&piece->pipe->dsc.filters); + dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_reduce_first, 4, sizeof(uint32_t), + (void *)&piece->pipe->dsc.filters); dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_reduce_first, 5, sizeof(int), &roi_in->x); dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_reduce_first, 6, sizeof(int), &roi_in->y); dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_reduce_first, 7, flocopt.sizex * flocopt.sizey * 2 * sizeof(float), NULL); - err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_green_eq_favg_reduce_first, fsizes, - flocal); + err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_green_eq_favg_reduce_first, fsizes, flocal); if(err != CL_SUCCESS) goto error; - dt_opencl_local_buffer_t slocopt - = (dt_opencl_local_buffer_t){ .xoffset = 0, .xfactor = 1, .yoffset = 0, .yfactor = 1, - .cellsize = 2 * sizeof(float), .overhead = 0, - .sizex = 1 << 16, .sizey = 1 }; + dt_opencl_local_buffer_t slocopt = (dt_opencl_local_buffer_t){.xoffset = 0, + .xfactor = 1, + .yoffset = 0, + .yfactor = 1, + .cellsize = 2 * sizeof(float), + .overhead = 0, + .sizex = 1 << 16, + .sizey = 1 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_green_eq_favg_reduce_second, &slocopt)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_green_eq_favg_reduce_second, &slocopt)) goto error; const int reducesize = MIN(REDUCESIZE, ROUNDUP(bufsize, slocopt.sizex) / slocopt.sizex); @@ -1948,9 +1957,9 @@ static int green_equilibration_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_reduce_second, 0, sizeof(cl_mem), &dev_m); dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_reduce_second, 1, sizeof(cl_mem), &dev_r); dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_reduce_second, 2, sizeof(int), &bufsize); - dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_reduce_second, 3, slocopt.sizex * 2 * sizeof(float), NULL); - err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_green_eq_favg_reduce_second, ssizes, - slocal); + dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_reduce_second, 3, slocopt.sizex * 2 * sizeof(float), + NULL); + err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_green_eq_favg_reduce_second, ssizes, slocal); if(err != CL_SUCCESS) goto error; sumsum = dt_alloc_align(16, (size_t)reducesize * 2 * sizeof(float)); @@ -1973,7 +1982,8 @@ static int green_equilibration_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_apply, 1, sizeof(cl_mem), &dev_out1); dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_apply, 2, sizeof(int), &width); dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_apply, 3, sizeof(int), &height); - dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_apply, 4, sizeof(uint32_t), (void *)&piece->pipe->dsc.filters); + dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_apply, 4, sizeof(uint32_t), + (void *)&piece->pipe->dsc.filters); dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_apply, 5, sizeof(int), &roi_in->x); dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_apply, 6, sizeof(int), &roi_in->y); dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_favg_apply, 7, sizeof(float), &gr_ratio); @@ -1986,13 +1996,16 @@ static int green_equilibration_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe const dt_image_t *img = &self->dev->image_storage; const float threshold = 0.0001f * img->exif_iso; - dt_opencl_local_buffer_t locopt - = (dt_opencl_local_buffer_t){ .xoffset = 2*2, .xfactor = 1, .yoffset = 2*2, .yfactor = 1, - .cellsize = 1 * sizeof(float), .overhead = 0, - .sizex = 1 << 8, .sizey = 1 << 8 }; + dt_opencl_local_buffer_t locopt = (dt_opencl_local_buffer_t){.xoffset = 2 * 2, + .xfactor = 1, + .yoffset = 2 * 2, + .yfactor = 1, + .cellsize = 1 * sizeof(float), + .overhead = 0, + .sizex = 1 << 8, + .sizey = 1 << 8 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_green_eq_lavg, &locopt)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_green_eq_lavg, &locopt)) goto error; size_t sizes[3] = { ROUNDUP(width, locopt.sizex), ROUNDUP(height, locopt.sizey), 1 }; size_t local[3] = { locopt.sizex, locopt.sizey, 1 }; @@ -2000,12 +2013,13 @@ static int green_equilibration_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_lavg, 1, sizeof(cl_mem), &dev_out2); dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_lavg, 2, sizeof(int), &width); dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_lavg, 3, sizeof(int), &height); - dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_lavg, 4, sizeof(uint32_t), (void *)&piece->pipe->dsc.filters); + dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_lavg, 4, sizeof(uint32_t), + (void *)&piece->pipe->dsc.filters); dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_lavg, 5, sizeof(int), &roi_in->x); dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_lavg, 6, sizeof(int), &roi_in->y); dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_lavg, 7, sizeof(float), (void *)&threshold); dt_opencl_set_kernel_arg(devid, gd->kernel_green_eq_lavg, 8, - (locopt.sizex + 4) * (locopt.sizey + 4) * sizeof(float), NULL); + (locopt.sizex + 4) * (locopt.sizey + 4) * sizeof(float), NULL); err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_green_eq_lavg, sizes, local); if(err != CL_SUCCESS) goto error; } @@ -2027,8 +2041,7 @@ static int green_equilibration_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe static int process_default_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, - cl_mem dev_out, const dt_iop_roi_t *const roi_in, - const dt_iop_roi_t *const roi_out) + cl_mem dev_out, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) { dt_iop_demosaic_data_t *data = (dt_iop_demosaic_data_t *)piece->data; dt_iop_demosaic_global_data_t *gd = (dt_iop_demosaic_global_data_t *)self->data; @@ -2058,8 +2071,7 @@ static int process_default_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop dev_green_eq = dt_opencl_alloc_device(devid, roi_in->width, roi_in->height, sizeof(float)); if(dev_green_eq == NULL) goto error; - if(!green_equilibration_cl(self, piece, dev_in, dev_green_eq, roi_in)) - goto error; + if(!green_equilibration_cl(self, piece, dev_in, dev_green_eq, roi_in)) goto error; dev_in = dev_green_eq; } @@ -2089,13 +2101,16 @@ static int process_default_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop { if(data->median_thrs > 0.0f) { - dt_opencl_local_buffer_t locopt - = (dt_opencl_local_buffer_t){ .xoffset = 2*2, .xfactor = 1, .yoffset = 2*2, .yfactor = 1, - .cellsize = 1 * sizeof(float), .overhead = 0, - .sizex = 1 << 8, .sizey = 1 << 8 }; + dt_opencl_local_buffer_t locopt = (dt_opencl_local_buffer_t){.xoffset = 2 * 2, + .xfactor = 1, + .yoffset = 2 * 2, + .yfactor = 1, + .cellsize = 1 * sizeof(float), + .overhead = 0, + .sizex = 1 << 8, + .sizey = 1 << 8 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_pre_median, &locopt)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_pre_median, &locopt)) goto error; size_t sizes[3] = { ROUNDUP(width, locopt.sizex), ROUNDUP(height, locopt.sizey), 1 }; size_t local[3] = { locopt.sizex, locopt.sizey, 1 }; @@ -2107,7 +2122,7 @@ static int process_default_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop (void *)&piece->pipe->dsc.filters); dt_opencl_set_kernel_arg(devid, gd->kernel_pre_median, 5, sizeof(float), (void *)&data->median_thrs); dt_opencl_set_kernel_arg(devid, gd->kernel_pre_median, 6, - (locopt.sizex + 4) * (locopt.sizey + 4) * sizeof(float), NULL); + (locopt.sizex + 4) * (locopt.sizey + 4) * sizeof(float), NULL); err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_pre_median, sizes, local); if(err != CL_SUCCESS) goto error; dev_in = dev_aux; @@ -2118,13 +2133,16 @@ static int process_default_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop do { - dt_opencl_local_buffer_t locopt - = (dt_opencl_local_buffer_t){ .xoffset = 2*3, .xfactor = 1, .yoffset = 2*3, .yfactor = 1, - .cellsize = 1 * sizeof(float), .overhead = 0, - .sizex = 1 << 8, .sizey = 1 << 8 }; + dt_opencl_local_buffer_t locopt = (dt_opencl_local_buffer_t){.xoffset = 2 * 3, + .xfactor = 1, + .yoffset = 2 * 3, + .yfactor = 1, + .cellsize = 1 * sizeof(float), + .overhead = 0, + .sizex = 1 << 8, + .sizey = 1 << 8 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_ppg_green, &locopt)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_ppg_green, &locopt)) goto error; size_t sizes[3] = { ROUNDUP(width, locopt.sizex), ROUNDUP(height, locopt.sizey), 1 }; size_t local[3] = { locopt.sizex, locopt.sizey, 1 }; @@ -2135,7 +2153,7 @@ static int process_default_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop dt_opencl_set_kernel_arg(devid, gd->kernel_ppg_green, 4, sizeof(uint32_t), (void *)&piece->pipe->dsc.filters); dt_opencl_set_kernel_arg(devid, gd->kernel_ppg_green, 5, - (locopt.sizex + 2*3) * (locopt.sizey + 2*3) * sizeof(float), NULL); + (locopt.sizex + 2 * 3) * (locopt.sizey + 2 * 3) * sizeof(float), NULL); err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_ppg_green, sizes, local); if(err != CL_SUCCESS) goto error; @@ -2144,13 +2162,16 @@ static int process_default_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop do { - dt_opencl_local_buffer_t locopt - = (dt_opencl_local_buffer_t){ .xoffset = 2*1, .xfactor = 1, .yoffset = 2*1, .yfactor = 1, - .cellsize = 4 * sizeof(float), .overhead = 0, - .sizex = 1 << 8, .sizey = 1 << 8 }; + dt_opencl_local_buffer_t locopt = (dt_opencl_local_buffer_t){.xoffset = 2 * 1, + .xfactor = 1, + .yoffset = 2 * 1, + .yfactor = 1, + .cellsize = 4 * sizeof(float), + .overhead = 0, + .sizex = 1 << 8, + .sizey = 1 << 8 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_ppg_redblue, &locopt)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_ppg_redblue, &locopt)) goto error; size_t sizes[3] = { ROUNDUP(width, locopt.sizex), ROUNDUP(height, locopt.sizey), 1 }; size_t local[3] = { locopt.sizex, locopt.sizey, 1 }; @@ -2161,7 +2182,7 @@ static int process_default_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop dt_opencl_set_kernel_arg(devid, gd->kernel_ppg_redblue, 4, sizeof(uint32_t), (void *)&piece->pipe->dsc.filters); dt_opencl_set_kernel_arg(devid, gd->kernel_ppg_redblue, 5, - (locopt.sizex + 2) * (locopt.sizey + 2) * 4 * sizeof(float), NULL); + (locopt.sizex + 2) * (locopt.sizey + 2) * 4 * sizeof(float), NULL); err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_ppg_redblue, sizes, local); if(err != CL_SUCCESS) goto error; @@ -2250,8 +2271,7 @@ static int process_default_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop // color smoothing if(data->color_smoothing) { - if(!color_smoothing_cl(self, piece, dev_out, dev_out, roi_out)) - goto error; + if(!color_smoothing_cl(self, piece, dev_out, dev_out, roi_out)) goto error; } return TRUE; @@ -2271,7 +2291,7 @@ static int process_vng_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t * dt_iop_demosaic_global_data_t *gd = (dt_iop_demosaic_global_data_t *)self->data; const dt_image_t *img = &self->dev->image_storage; - const uint8_t(*const xtrans)[6] = (const uint8_t(*const)[6])piece->pipe->dsc.xtrans; + const uint8_t (*const xtrans)[6] = (const uint8_t (*const)[6])piece->pipe->dsc.xtrans; // separate out G1 and G2 in Bayer patterns uint32_t filters4; @@ -2363,24 +2383,23 @@ static int process_vng_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t * // Precalculate for VNG static const signed char terms[] - = { -2, -2, +0, -1, 1, 0x01, -2, -2, +0, +0, 2, 0x01, -2, -1, -1, +0, 1, 0x01, -2, -1, +0, -1, 1, 0x02, - -2, -1, +0, +0, 1, 0x03, -2, -1, +0, +1, 2, 0x01, -2, +0, +0, -1, 1, 0x06, -2, +0, +0, +0, 2, 0x02, - -2, +0, +0, +1, 1, 0x03, -2, +1, -1, +0, 1, 0x04, -2, +1, +0, -1, 2, 0x04, -2, +1, +0, +0, 1, 0x06, - -2, +1, +0, +1, 1, 0x02, -2, +2, +0, +0, 2, 0x04, -2, +2, +0, +1, 1, 0x04, -1, -2, -1, +0, 1, 0x80, - -1, -2, +0, -1, 1, 0x01, -1, -2, +1, -1, 1, 0x01, -1, -2, +1, +0, 2, 0x01, -1, -1, -1, +1, 1, 0x88, - -1, -1, +1, -2, 1, 0x40, -1, -1, +1, -1, 1, 0x22, -1, -1, +1, +0, 1, 0x33, -1, -1, +1, +1, 2, 0x11, - -1, +0, -1, +2, 1, 0x08, -1, +0, +0, -1, 1, 0x44, -1, +0, +0, +1, 1, 0x11, -1, +0, +1, -2, 2, 0x40, - -1, +0, +1, -1, 1, 0x66, -1, +0, +1, +0, 2, 0x22, -1, +0, +1, +1, 1, 0x33, -1, +0, +1, +2, 2, 0x10, - -1, +1, +1, -1, 2, 0x44, -1, +1, +1, +0, 1, 0x66, -1, +1, +1, +1, 1, 0x22, -1, +1, +1, +2, 1, 0x10, - -1, +2, +0, +1, 1, 0x04, -1, +2, +1, +0, 2, 0x04, -1, +2, +1, +1, 1, 0x04, +0, -2, +0, +0, 2, 0x80, - +0, -1, +0, +1, 2, 0x88, +0, -1, +1, -2, 1, 0x40, +0, -1, +1, +0, 1, 0x11, +0, -1, +2, -2, 1, 0x40, - +0, -1, +2, -1, 1, 0x20, +0, -1, +2, +0, 1, 0x30, +0, -1, +2, +1, 2, 0x10, +0, +0, +0, +2, 2, 0x08, - +0, +0, +2, -2, 2, 0x40, +0, +0, +2, -1, 1, 0x60, +0, +0, +2, +0, 2, 0x20, +0, +0, +2, +1, 1, 0x30, - +0, +0, +2, +2, 2, 0x10, +0, +1, +1, +0, 1, 0x44, +0, +1, +1, +2, 1, 0x10, +0, +1, +2, -1, 2, 0x40, - +0, +1, +2, +0, 1, 0x60, +0, +1, +2, +1, 1, 0x20, +0, +1, +2, +2, 1, 0x10, +1, -2, +1, +0, 1, 0x80, - +1, -1, +1, +1, 1, 0x88, +1, +0, +1, +2, 1, 0x08, +1, +0, +2, -1, 1, 0x40, +1, +0, +2, +1, 1, 0x10 }; - static const signed char chood[] - = { -1, -1, -1, 0, -1, +1, 0, +1, +1, +1, +1, 0, +1, -1, 0, -1 }; + = { -2, -2, +0, -1, 1, 0x01, -2, -2, +0, +0, 2, 0x01, -2, -1, -1, +0, 1, 0x01, -2, -1, +0, -1, 1, 0x02, + -2, -1, +0, +0, 1, 0x03, -2, -1, +0, +1, 2, 0x01, -2, +0, +0, -1, 1, 0x06, -2, +0, +0, +0, 2, 0x02, + -2, +0, +0, +1, 1, 0x03, -2, +1, -1, +0, 1, 0x04, -2, +1, +0, -1, 2, 0x04, -2, +1, +0, +0, 1, 0x06, + -2, +1, +0, +1, 1, 0x02, -2, +2, +0, +0, 2, 0x04, -2, +2, +0, +1, 1, 0x04, -1, -2, -1, +0, 1, 0x80, + -1, -2, +0, -1, 1, 0x01, -1, -2, +1, -1, 1, 0x01, -1, -2, +1, +0, 2, 0x01, -1, -1, -1, +1, 1, 0x88, + -1, -1, +1, -2, 1, 0x40, -1, -1, +1, -1, 1, 0x22, -1, -1, +1, +0, 1, 0x33, -1, -1, +1, +1, 2, 0x11, + -1, +0, -1, +2, 1, 0x08, -1, +0, +0, -1, 1, 0x44, -1, +0, +0, +1, 1, 0x11, -1, +0, +1, -2, 2, 0x40, + -1, +0, +1, -1, 1, 0x66, -1, +0, +1, +0, 2, 0x22, -1, +0, +1, +1, 1, 0x33, -1, +0, +1, +2, 2, 0x10, + -1, +1, +1, -1, 2, 0x44, -1, +1, +1, +0, 1, 0x66, -1, +1, +1, +1, 1, 0x22, -1, +1, +1, +2, 1, 0x10, + -1, +2, +0, +1, 1, 0x04, -1, +2, +1, +0, 2, 0x04, -1, +2, +1, +1, 1, 0x04, +0, -2, +0, +0, 2, 0x80, + +0, -1, +0, +1, 2, 0x88, +0, -1, +1, -2, 1, 0x40, +0, -1, +1, +0, 1, 0x11, +0, -1, +2, -2, 1, 0x40, + +0, -1, +2, -1, 1, 0x20, +0, -1, +2, +0, 1, 0x30, +0, -1, +2, +1, 2, 0x10, +0, +0, +0, +2, 2, 0x08, + +0, +0, +2, -2, 2, 0x40, +0, +0, +2, -1, 1, 0x60, +0, +0, +2, +0, 2, 0x20, +0, +0, +2, +1, 1, 0x30, + +0, +0, +2, +2, 2, 0x10, +0, +1, +1, +0, 1, 0x44, +0, +1, +1, +2, 1, 0x10, +0, +1, +2, -1, 2, 0x40, + +0, +1, +2, +0, 1, 0x60, +0, +1, +2, +1, 1, 0x20, +0, +1, +2, +2, 1, 0x10, +1, -2, +1, +0, 1, 0x80, + +1, -1, +1, +1, 1, 0x88, +1, +0, +1, +2, 1, 0x08, +1, +0, +2, -1, 1, 0x40, +1, +0, +2, +1, 1, 0x10 }; + static const signed char chood[] = { -1, -1, -1, 0, -1, +1, 0, +1, +1, +1, +1, 0, +1, -1, 0, -1 }; const size_t ips_size = (size_t)prow * pcol * 352 * sizeof(int); ips = malloc(ips_size); @@ -2423,7 +2442,7 @@ static int process_vng_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t * if(fcol(row + y, col + x, filters4, xtrans) != color && fcol(row + y * 2, col + x * 2, filters4, xtrans) == color) { - *ip++ = (2*y << 16) | (2*x & 0xffffu); + *ip++ = (2 * y << 16) | (2 * x & 0xffffu); *ip++ = color; } else @@ -2450,8 +2469,7 @@ static int process_vng_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t * dev_green_eq = dt_opencl_alloc_device(devid, roi_in->width, roi_in->height, sizeof(float)); if(dev_green_eq == NULL) goto error; - if(!green_equilibration_cl(self, piece, dev_in, dev_green_eq, roi_in)) - goto error; + if(!green_equilibration_cl(self, piece, dev_in, dev_green_eq, roi_in)) goto error; dev_in = dev_green_eq; } @@ -2495,13 +2513,16 @@ static int process_vng_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t * do { // do linear interpolation - dt_opencl_local_buffer_t locopt - = (dt_opencl_local_buffer_t){ .xoffset = 2*1, .xfactor = 1, .yoffset = 2*1, .yfactor = 1, - .cellsize = 1 * sizeof(float), .overhead = 0, - .sizex = 1 << 8, .sizey = 1 << 8 }; + dt_opencl_local_buffer_t locopt = (dt_opencl_local_buffer_t){.xoffset = 2 * 1, + .xfactor = 1, + .yoffset = 2 * 1, + .yfactor = 1, + .cellsize = 1 * sizeof(float), + .overhead = 0, + .sizex = 1 << 8, + .sizey = 1 << 8 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_vng_lin_interpolate, &locopt)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_vng_lin_interpolate, &locopt)) goto error; size_t sizes[3] = { ROUNDUP(width, locopt.sizex), ROUNDUP(height, locopt.sizey), 1 }; size_t local[3] = { locopt.sizex, locopt.sizey, 1 }; @@ -2529,13 +2550,16 @@ static int process_vng_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t * else { // do full VNG interpolation - dt_opencl_local_buffer_t locopt - = (dt_opencl_local_buffer_t){ .xoffset = 2*2, .xfactor = 1, .yoffset = 2*2, .yfactor = 1, - .cellsize = 4 * sizeof(float), .overhead = 0, - .sizex = 1 << 8, .sizey = 1 << 8 }; + dt_opencl_local_buffer_t locopt = (dt_opencl_local_buffer_t){.xoffset = 2 * 2, + .xfactor = 1, + .yoffset = 2 * 2, + .yfactor = 1, + .cellsize = 4 * sizeof(float), + .overhead = 0, + .sizex = 1 << 8, + .sizey = 1 << 8 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_vng_interpolate, &locopt)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_vng_interpolate, &locopt)) goto error; size_t sizes[3] = { ROUNDUP(width, locopt.sizex), ROUNDUP(height, locopt.sizey), 1 }; size_t local[3] = { locopt.sizex, locopt.sizey, 1 }; @@ -2546,11 +2570,12 @@ static int process_vng_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t * dt_opencl_set_kernel_arg(devid, gd->kernel_vng_interpolate, 4, sizeof(int), (void *)&roi_in->x); dt_opencl_set_kernel_arg(devid, gd->kernel_vng_interpolate, 5, sizeof(int), (void *)&roi_in->y); dt_opencl_set_kernel_arg(devid, gd->kernel_vng_interpolate, 6, sizeof(uint32_t), (void *)&filters4); - dt_opencl_set_kernel_arg(devid, gd->kernel_vng_interpolate, 7, 4*sizeof(float), (void *)processed_maximum); + dt_opencl_set_kernel_arg(devid, gd->kernel_vng_interpolate, 7, 4 * sizeof(float), (void *)processed_maximum); dt_opencl_set_kernel_arg(devid, gd->kernel_vng_interpolate, 8, sizeof(cl_mem), (void *)&dev_xtrans); dt_opencl_set_kernel_arg(devid, gd->kernel_vng_interpolate, 9, sizeof(cl_mem), (void *)&dev_ips); dt_opencl_set_kernel_arg(devid, gd->kernel_vng_interpolate, 10, sizeof(cl_mem), (void *)&dev_code); - dt_opencl_set_kernel_arg(devid, gd->kernel_vng_interpolate, 11, (locopt.sizex + 4) * (locopt.sizey + 4) * 4 * sizeof(float), NULL); + dt_opencl_set_kernel_arg(devid, gd->kernel_vng_interpolate, 11, + (locopt.sizex + 4) * (locopt.sizey + 4) * 4 * sizeof(float), NULL); err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_vng_interpolate, sizes, local); if(err != CL_SUCCESS) goto error; } @@ -2673,8 +2698,7 @@ static int process_vng_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t * // color smoothing if(data->color_smoothing) { - if(!color_smoothing_cl(self, piece, dev_out, dev_out, roi_out)) - goto error; + if(!color_smoothing_cl(self, piece, dev_out, dev_out, roi_out)) goto error; } return TRUE; @@ -2701,7 +2725,7 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe dt_iop_demosaic_global_data_t *gd = (dt_iop_demosaic_global_data_t *)self->data; const int devid = piece->pipe->devid; - const uint8_t(*const xtrans)[6] = (const uint8_t(*const)[6])piece->pipe->dsc.xtrans; + const uint8_t (*const xtrans)[6] = (const uint8_t (*const)[6])piece->pipe->dsc.xtrans; const float processed_maximum[4] = { piece->pipe->dsc.processed_maximum[0], piece->pipe->dsc.processed_maximum[1], @@ -2833,13 +2857,16 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe // find minimum and maximum allowed green values of red/blue pixel pairs const int pad_g1_g3 = 3; - dt_opencl_local_buffer_t locopt_g1_g3 - = (dt_opencl_local_buffer_t){ .xoffset = 2*3, .xfactor = 1, .yoffset = 2*3, .yfactor = 1, - .cellsize = 1 * sizeof(float), .overhead = 0, - .sizex = 1 << 8, .sizey = 1 << 8 }; + dt_opencl_local_buffer_t locopt_g1_g3 = (dt_opencl_local_buffer_t){.xoffset = 2 * 3, + .xfactor = 1, + .yoffset = 2 * 3, + .yfactor = 1, + .cellsize = 1 * sizeof(float), + .overhead = 0, + .sizex = 1 << 8, + .sizey = 1 << 8 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_markesteijn_green_minmax, &locopt_g1_g3)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_markesteijn_green_minmax, &locopt_g1_g3)) goto error; do { @@ -2856,40 +2883,53 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_green_minmax, 8, sizeof(cl_mem), (void *)&dev_xtrans); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_green_minmax, 9, sizeof(cl_mem), (void *)&dev_allhex); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_green_minmax, 10, - (locopt_g1_g3.sizex + 2*3) * (locopt_g1_g3.sizey + 2*3) * sizeof(float), NULL); + (locopt_g1_g3.sizex + 2 * 3) * (locopt_g1_g3.sizey + 2 * 3) * sizeof(float), NULL); err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_markesteijn_green_minmax, sizes, local); if(err != CL_SUCCESS) goto error; } while(0); // interpolate green horizontally, vertically, and along both diagonals const int pad_g_interp = 3; - dt_opencl_local_buffer_t locopt_g_interp - = (dt_opencl_local_buffer_t){ .xoffset = 2*6, .xfactor = 1, .yoffset = 2*6, .yfactor = 1, - .cellsize = 4 * sizeof(float), .overhead = 0, - .sizex = 1 << 8, .sizey = 1 << 8 }; + dt_opencl_local_buffer_t locopt_g_interp = (dt_opencl_local_buffer_t){.xoffset = 2 * 6, + .xfactor = 1, + .yoffset = 2 * 6, + .yfactor = 1, + .cellsize = 4 * sizeof(float), + .overhead = 0, + .sizex = 1 << 8, + .sizey = 1 << 8 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_markesteijn_interpolate_green, &locopt_g_interp)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_markesteijn_interpolate_green, &locopt_g_interp)) goto error; do { size_t sizes[3] = { ROUNDUP(width, locopt_g_interp.sizex), ROUNDUP(height, locopt_g_interp.sizey), 1 }; size_t local[3] = { locopt_g_interp.sizex, locopt_g_interp.sizey, 1 }; - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 0, sizeof(cl_mem), (void *)&dev_rgb[0]); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 1, sizeof(cl_mem), (void *)&dev_rgb[1]); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 2, sizeof(cl_mem), (void *)&dev_rgb[2]); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 3, sizeof(cl_mem), (void *)&dev_rgb[3]); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 4, sizeof(cl_mem), (void *)&dev_gminmax); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 0, sizeof(cl_mem), + (void *)&dev_rgb[0]); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 1, sizeof(cl_mem), + (void *)&dev_rgb[1]); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 2, sizeof(cl_mem), + (void *)&dev_rgb[2]); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 3, sizeof(cl_mem), + (void *)&dev_rgb[3]); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 4, sizeof(cl_mem), + (void *)&dev_gminmax); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 5, sizeof(int), (void *)&width); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 6, sizeof(int), (void *)&height); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 7, sizeof(int), (void *)&pad_g_interp); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 7, sizeof(int), + (void *)&pad_g_interp); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 8, sizeof(int), (void *)&roi_in->x); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 9, sizeof(int), (void *)&roi_in->y); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 10, 2 * sizeof(char), (void *)sgreen); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 11, sizeof(cl_mem), (void *)&dev_xtrans); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 12, sizeof(cl_mem), (void *)&dev_allhex); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 13, - (locopt_g_interp.sizex + 2*6) * (locopt_g_interp.sizey + 2*6) * 4 * sizeof(float), NULL); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 10, 2 * sizeof(char), + (void *)sgreen); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 11, sizeof(cl_mem), + (void *)&dev_xtrans); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_green, 12, sizeof(cl_mem), + (void *)&dev_allhex); + dt_opencl_set_kernel_arg( + devid, gd->kernel_markesteijn_interpolate_green, 13, + (locopt_g_interp.sizex + 2 * 6) * (locopt_g_interp.sizey + 2 * 6) * 4 * sizeof(float), NULL); err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_markesteijn_interpolate_green, sizes, local); if(err != CL_SUCCESS) goto error; } while(0); @@ -2917,32 +2957,46 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe // recalculate green from interpolated values of closer pixels const int pad_g_recalc = 6; size_t sizes[3] = { ROUNDUPWD(width), ROUNDUPHT(height), 1 }; - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 0, sizeof(cl_mem), (void *)&dev_rgb[0]); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 1, sizeof(cl_mem), (void *)&dev_rgb[1]); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 2, sizeof(cl_mem), (void *)&dev_rgb[2]); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 3, sizeof(cl_mem), (void *)&dev_rgb[3]); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 4, sizeof(cl_mem), (void *)&dev_gminmax); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 0, sizeof(cl_mem), + (void *)&dev_rgb[0]); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 1, sizeof(cl_mem), + (void *)&dev_rgb[1]); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 2, sizeof(cl_mem), + (void *)&dev_rgb[2]); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 3, sizeof(cl_mem), + (void *)&dev_rgb[3]); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 4, sizeof(cl_mem), + (void *)&dev_gminmax); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 5, sizeof(int), (void *)&width); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 6, sizeof(int), (void *)&height); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 7, sizeof(int), (void *)&pad_g_recalc); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 8, sizeof(int), (void *)&roi_in->x); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 9, sizeof(int), (void *)&roi_in->y); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 10, 2 * sizeof(char), (void *)sgreen); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 11, sizeof(cl_mem), (void *)&dev_xtrans); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 12, sizeof(cl_mem), (void *)&dev_allhex); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 7, sizeof(int), + (void *)&pad_g_recalc); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 8, sizeof(int), + (void *)&roi_in->x); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 9, sizeof(int), + (void *)&roi_in->y); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 10, 2 * sizeof(char), + (void *)sgreen); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 11, sizeof(cl_mem), + (void *)&dev_xtrans); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_recalculate_green, 12, sizeof(cl_mem), + (void *)&dev_allhex); err = dt_opencl_enqueue_kernel_2d(devid, gd->kernel_markesteijn_recalculate_green, sizes); if(err != CL_SUCCESS) goto error; } // interpolate red and blue values for solitary green pixels const int pad_rb_g = (passes == 1) ? 6 : 5; - dt_opencl_local_buffer_t locopt_rb_g - = (dt_opencl_local_buffer_t){ .xoffset = 2*2, .xfactor = 1, .yoffset = 2*2, .yfactor = 1, - .cellsize = 4 * sizeof(float), .overhead = 0, - .sizex = 1 << 8, .sizey = 1 << 8 }; + dt_opencl_local_buffer_t locopt_rb_g = (dt_opencl_local_buffer_t){.xoffset = 2 * 2, + .xfactor = 1, + .yoffset = 2 * 2, + .yfactor = 1, + .cellsize = 4 * sizeof(float), + .overhead = 0, + .sizex = 1 << 8, + .sizey = 1 << 8 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_markesteijn_solitary_green, &locopt_rb_g)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_markesteijn_solitary_green, &locopt_rb_g)) goto error; cl_mem *dev_trgb = dev_rgb; for(int d = 0, i = 1, h = 0; d < 6; d++, i ^= 1, h ^= 2) @@ -2952,7 +3006,8 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe // we use dev_aux to transport intermediate results from one loop run to the next size_t sizes[3] = { ROUNDUP(width, locopt_rb_g.sizex), ROUNDUP(height, locopt_rb_g.sizey), 1 }; size_t local[3] = { locopt_rb_g.sizex, locopt_rb_g.sizey, 1 }; - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_solitary_green, 0, sizeof(cl_mem), (void *)&dev_trgb[0]); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_solitary_green, 0, sizeof(cl_mem), + (void *)&dev_trgb[0]); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_solitary_green, 1, sizeof(cl_mem), (void *)&dev_aux); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_solitary_green, 2, sizeof(int), (void *)&width); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_solitary_green, 3, sizeof(int), (void *)&height); @@ -2962,10 +3017,13 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_solitary_green, 7, sizeof(int), (void *)&d); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_solitary_green, 8, 2 * sizeof(char), (void *)dir); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_solitary_green, 9, sizeof(int), (void *)&h); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_solitary_green, 10, 2 * sizeof(char), (void *)sgreen); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_solitary_green, 11, sizeof(cl_mem), (void *)&dev_xtrans); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_solitary_green, 10, 2 * sizeof(char), + (void *)sgreen); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_solitary_green, 11, sizeof(cl_mem), + (void *)&dev_xtrans); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_solitary_green, 12, - (locopt_rb_g.sizex + 2*2) * (locopt_rb_g.sizey + 2*2) * 4 * sizeof(float), NULL); + (locopt_rb_g.sizex + 2 * 2) * (locopt_rb_g.sizey + 2 * 2) * 4 * sizeof(float), + NULL); err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_markesteijn_solitary_green, sizes, local); if(err != CL_SUCCESS) goto error; @@ -2974,19 +3032,23 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe // interpolate red for blue pixels and vice versa const int pad_rb_br = (passes == 1) ? 6 : 5; - dt_opencl_local_buffer_t locopt_rb_br - = (dt_opencl_local_buffer_t){ .xoffset = 2*3, .xfactor = 1, .yoffset = 2*3, .yfactor = 1, - .cellsize = 4 * sizeof(float), .overhead = 0, - .sizex = 1 << 8, .sizey = 1 << 8 }; + dt_opencl_local_buffer_t locopt_rb_br = (dt_opencl_local_buffer_t){.xoffset = 2 * 3, + .xfactor = 1, + .yoffset = 2 * 3, + .yfactor = 1, + .cellsize = 4 * sizeof(float), + .overhead = 0, + .sizex = 1 << 8, + .sizey = 1 << 8 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_markesteijn_red_and_blue, &locopt_rb_br)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_markesteijn_red_and_blue, &locopt_rb_br)) goto error; for(int d = 0; d < 4; d++) { size_t sizes[3] = { ROUNDUP(width, locopt_rb_br.sizex), ROUNDUP(height, locopt_rb_br.sizey), 1 }; size_t local[3] = { locopt_rb_br.sizex, locopt_rb_br.sizey, 1 }; - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_red_and_blue, 0, sizeof(cl_mem), (void *)&dev_rgb[d]); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_red_and_blue, 0, sizeof(cl_mem), + (void *)&dev_rgb[d]); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_red_and_blue, 1, sizeof(int), (void *)&width); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_red_and_blue, 2, sizeof(int), (void *)&height); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_red_and_blue, 3, sizeof(int), (void *)&pad_rb_br); @@ -2994,40 +3056,55 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_red_and_blue, 5, sizeof(int), (void *)&roi_in->y); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_red_and_blue, 6, sizeof(int), (void *)&d); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_red_and_blue, 7, 2 * sizeof(char), (void *)sgreen); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_red_and_blue, 8, sizeof(cl_mem), (void *)&dev_xtrans); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_red_and_blue, 8, sizeof(cl_mem), + (void *)&dev_xtrans); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_red_and_blue, 9, - (locopt_rb_br.sizex + 2*3) * (locopt_rb_br.sizey + 2*3) * 4 * sizeof(float), NULL); + (locopt_rb_br.sizex + 2 * 3) * (locopt_rb_br.sizey + 2 * 3) * 4 * sizeof(float), + NULL); err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_markesteijn_red_and_blue, sizes, local); if(err != CL_SUCCESS) goto error; } // interpolate red and blue for 2x2 blocks of green const int pad_g22 = (passes == 1) ? 8 : 4; - dt_opencl_local_buffer_t locopt_g22 - = (dt_opencl_local_buffer_t){ .xoffset = 2*2, .xfactor = 1, .yoffset = 2*2, .yfactor = 1, - .cellsize = 4 * sizeof(float), .overhead = 0, - .sizex = 1 << 8, .sizey = 1 << 8 }; + dt_opencl_local_buffer_t locopt_g22 = (dt_opencl_local_buffer_t){.xoffset = 2 * 2, + .xfactor = 1, + .yoffset = 2 * 2, + .yfactor = 1, + .cellsize = 4 * sizeof(float), + .overhead = 0, + .sizex = 1 << 8, + .sizey = 1 << 8 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_markesteijn_interpolate_twoxtwo, &locopt_g22)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_markesteijn_interpolate_twoxtwo, &locopt_g22)) goto error; for(int d = 0, n = 0; d < ndir; d += 2, n++) { size_t sizes[3] = { ROUNDUP(width, locopt_g22.sizex), ROUNDUP(height, locopt_g22.sizey), 1 }; size_t local[3] = { locopt_g22.sizex, locopt_g22.sizey, 1 }; - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_twoxtwo, 0, sizeof(cl_mem), (void *)&dev_rgb[n]); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_twoxtwo, 0, sizeof(cl_mem), + (void *)&dev_rgb[n]); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_twoxtwo, 1, sizeof(int), (void *)&width); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_twoxtwo, 2, sizeof(int), (void *)&height); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_twoxtwo, 3, sizeof(int), (void *)&pad_g22); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_twoxtwo, 4, sizeof(int), (void *)&roi_in->x); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_twoxtwo, 5, sizeof(int), (void *)&roi_in->y); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_twoxtwo, 2, sizeof(int), + (void *)&height); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_twoxtwo, 3, sizeof(int), + (void *)&pad_g22); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_twoxtwo, 4, sizeof(int), + (void *)&roi_in->x); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_twoxtwo, 5, sizeof(int), + (void *)&roi_in->y); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_twoxtwo, 6, sizeof(int), (void *)&d); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_twoxtwo, 7, 2 * sizeof(char), (void *)sgreen); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_twoxtwo, 8, sizeof(cl_mem), (void *)&dev_xtrans); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_twoxtwo, 9, sizeof(cl_mem), (void *)&dev_allhex); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_twoxtwo, 7, 2 * sizeof(char), + (void *)sgreen); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_twoxtwo, 8, sizeof(cl_mem), + (void *)&dev_xtrans); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_twoxtwo, 9, sizeof(cl_mem), + (void *)&dev_allhex); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_interpolate_twoxtwo, 10, - (locopt_g22.sizex + 2*2) * (locopt_g22.sizey + 2*2) * 4 * sizeof(float), NULL); - err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_markesteijn_interpolate_twoxtwo, sizes, local); + (locopt_g22.sizex + 2 * 2) * (locopt_g22.sizey + 2 * 2) * 4 * sizeof(float), + NULL); + err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_markesteijn_interpolate_twoxtwo, sizes, + local); if(err != CL_SUCCESS) goto error; } } @@ -3049,13 +3126,16 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe // convert to perceptual colorspace and differentiate in all directions const int pad_yuv = (passes == 1) ? 8 : 13; - dt_opencl_local_buffer_t locopt_diff - = (dt_opencl_local_buffer_t){ .xoffset = 2*1, .xfactor = 1, .yoffset = 2*1, .yfactor = 1, - .cellsize = 4 * sizeof(float), .overhead = 0, - .sizex = 1 << 8, .sizey = 1 << 8 }; + dt_opencl_local_buffer_t locopt_diff = (dt_opencl_local_buffer_t){.xoffset = 2 * 1, + .xfactor = 1, + .yoffset = 2 * 1, + .yfactor = 1, + .cellsize = 4 * sizeof(float), + .overhead = 0, + .sizex = 1 << 8, + .sizey = 1 << 8 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_markesteijn_differentiate, &locopt_diff)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_markesteijn_differentiate, &locopt_diff)) goto error; for(int d = 0; d < ndir; d++) { @@ -3080,8 +3160,10 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_differentiate, 4, sizeof(int), (void *)&pad_yuv); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_differentiate, 5, sizeof(int), (void *)&d); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_differentiate, 6, - (locopt_diff.sizex + 2*1) * (locopt_diff.sizey + 2*1) * 4 * sizeof(float), NULL); - err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_markesteijn_differentiate, sizes_diff, local_diff); + (locopt_diff.sizex + 2 * 1) * (locopt_diff.sizey + 2 * 1) * 4 * sizeof(float), + NULL); + err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_markesteijn_differentiate, sizes_diff, + local_diff); if(err != CL_SUCCESS) goto error; } @@ -3100,7 +3182,8 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe { const int pad_homo = (passes == 1) ? 10 : 15; size_t sizes[3] = { ROUNDUPWD(width), ROUNDUPHT(height), 1 }; - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_homo_threshold, 0, sizeof(cl_mem), (void *)&dev_drv[d]); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_homo_threshold, 0, sizeof(cl_mem), + (void *)&dev_drv[d]); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_homo_threshold, 1, sizeof(cl_mem), (void *)&dev_aux); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_homo_threshold, 2, sizeof(int), (void *)&width); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_homo_threshold, 3, sizeof(int), (void *)&height); @@ -3112,17 +3195,20 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe // set homogeneity maps const int pad_homo = (passes == 1) ? 10 : 15; - dt_opencl_local_buffer_t locopt_homo - = (dt_opencl_local_buffer_t){ .xoffset = 2*1, .xfactor = 1, .yoffset = 2*1, .yfactor = 1, - .cellsize = 1 * sizeof(float), .overhead = 0, - .sizex = 1 << 8, .sizey = 1 << 8 }; + dt_opencl_local_buffer_t locopt_homo = (dt_opencl_local_buffer_t){.xoffset = 2 * 1, + .xfactor = 1, + .yoffset = 2 * 1, + .yfactor = 1, + .cellsize = 1 * sizeof(float), + .overhead = 0, + .sizex = 1 << 8, + .sizey = 1 << 8 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_markesteijn_homo_set, &locopt_homo)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_markesteijn_homo_set, &locopt_homo)) goto error; for(int d = 0; d < ndir; d++) { - size_t sizes[3] = { ROUNDUP(width, locopt_homo.sizex),ROUNDUP(height, locopt_homo.sizey), 1 }; + size_t sizes[3] = { ROUNDUP(width, locopt_homo.sizex), ROUNDUP(height, locopt_homo.sizey), 1 }; size_t local[3] = { locopt_homo.sizex, locopt_homo.sizey, 1 }; dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_homo_set, 0, sizeof(cl_mem), (void *)&dev_drv[d]); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_homo_set, 1, sizeof(cl_mem), (void *)&dev_aux); @@ -3131,7 +3217,7 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_homo_set, 4, sizeof(int), (void *)&height); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_homo_set, 5, sizeof(int), (void *)&pad_homo); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_homo_set, 6, - (locopt_homo.sizex + 2*1) * (locopt_homo.sizey + 2*1) * sizeof(float), NULL); + (locopt_homo.sizex + 2 * 1) * (locopt_homo.sizey + 2 * 1) * sizeof(float), NULL); err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_markesteijn_homo_set, sizes, local); if(err != CL_SUCCESS) goto error; } @@ -3144,13 +3230,16 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe } // build 5x5 sum of homogeneity maps for each pixel and direction - dt_opencl_local_buffer_t locopt_homo_sum - = (dt_opencl_local_buffer_t){ .xoffset = 2*2, .xfactor = 1, .yoffset = 2*2, .yfactor = 1, - .cellsize = 1 * sizeof(float), .overhead = 0, - .sizex = 1 << 8, .sizey = 1 << 8 }; + dt_opencl_local_buffer_t locopt_homo_sum = (dt_opencl_local_buffer_t){.xoffset = 2 * 2, + .xfactor = 1, + .yoffset = 2 * 2, + .yfactor = 1, + .cellsize = 1 * sizeof(float), + .overhead = 0, + .sizex = 1 << 8, + .sizey = 1 << 8 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_markesteijn_homo_sum, &locopt_homo_sum)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_markesteijn_homo_sum, &locopt_homo_sum)) goto error; for(int d = 0; d < ndir; d++) { @@ -3162,7 +3251,8 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_homo_sum, 3, sizeof(int), (void *)&height); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_homo_sum, 4, sizeof(int), (void *)&pad_tile); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_homo_sum, 5, - (locopt_homo_sum.sizex + 2*2) * (locopt_homo_sum.sizey + 2*2) * sizeof(char), NULL); + (locopt_homo_sum.sizex + 2 * 2) * (locopt_homo_sum.sizey + 2 * 2) * sizeof(char), + NULL); err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_markesteijn_homo_sum, sizes, local); if(err != CL_SUCCESS) goto error; } @@ -3197,8 +3287,10 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe for(int d = 0; d < ndir - 4; d++) { size_t sizes[3] = { ROUNDUPWD(width), ROUNDUPHT(height), 1 }; - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_homo_quench, 0, sizeof(cl_mem), (void *)&dev_homosum[d]); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_homo_quench, 1, sizeof(cl_mem), (void *)&dev_homosum[d + 4]); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_homo_quench, 0, sizeof(cl_mem), + (void *)&dev_homosum[d]); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_homo_quench, 1, sizeof(cl_mem), + (void *)&dev_homosum[d + 4]); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_homo_quench, 2, sizeof(int), (void *)&width); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_homo_quench, 3, sizeof(int), (void *)&height); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_homo_quench, 4, sizeof(int), (void *)&pad_tile); @@ -3265,7 +3357,8 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_final, 2, sizeof(int), (void *)&width); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_final, 3, sizeof(int), (void *)&height); dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_final, 4, sizeof(int), (void *)&pad_tile); - dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_final, 5, 4*sizeof(float), (void *)processed_maximum); + dt_opencl_set_kernel_arg(devid, gd->kernel_markesteijn_final, 5, 4 * sizeof(float), + (void *)processed_maximum); err = dt_opencl_enqueue_kernel_2d(devid, gd->kernel_markesteijn_final, sizes); if(err != CL_SUCCESS) goto error; } while(0); @@ -3310,10 +3403,10 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe // drop 3px on the inner side if possible // take care of some degenerate cases (which might happen if we are called in a tiling context) - const int wd = (width > pad_tile+3) ? pad_tile+3 : width; - const int ht = (height > pad_tile+3) ? pad_tile+3 : height; - const int wdc = (wd >= pad_tile+3) ? 3 : 0; - const int htc = (ht >= pad_tile+3) ? 3 : 0; + const int wd = (width > pad_tile + 3) ? pad_tile + 3 : width; + const int ht = (height > pad_tile + 3) ? pad_tile + 3 : height; + const int wdc = (wd >= pad_tile + 3) ? 3 : 0; + const int htc = (ht >= pad_tile + 3) ? 3 : 0; // the data of all four edges: // total edge: x-offset, y-offset, width, height, @@ -3344,8 +3437,7 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe if(err != CL_SUCCESS) goto error; // VNG processing - if(!process_vng_cl(self, piece, dev_edge_in, dev_edge_out, &roi, &roi)) - goto error; + if(!process_vng_cl(self, piece, dev_edge_in, dev_edge_out, &roi, &roi)) goto error; // adjust for "good" part, dropping linear border where possible iorigin[0] += edges[n][4]; @@ -3405,8 +3497,7 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe // color smoothing if(data->color_smoothing) { - if(!color_smoothing_cl(self, piece, dev_out, dev_out, roi_out)) - goto error; + if(!color_smoothing_cl(self, piece, dev_out, dev_out, roi_out)) goto error; } return TRUE; @@ -3414,14 +3505,10 @@ static int process_markesteijn_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe error: if(dev_tmp != dev_out) dt_opencl_release_mem_object(dev_tmp); - for(int n = 0; n < 8; n++) - dt_opencl_release_mem_object(dev_rgbv[n]); - for(int n = 0; n < 8; n++) - dt_opencl_release_mem_object(dev_drv[n]); - for(int n = 0; n < 8; n++) - dt_opencl_release_mem_object(dev_homo[n]); - for(int n = 0; n < 8; n++) - dt_opencl_release_mem_object(dev_homosum[n]); + for(int n = 0; n < 8; n++) dt_opencl_release_mem_object(dev_rgbv[n]); + for(int n = 0; n < 8; n++) dt_opencl_release_mem_object(dev_drv[n]); + for(int n = 0; n < 8; n++) dt_opencl_release_mem_object(dev_homo[n]); + for(int n = 0; n < 8; n++) dt_opencl_release_mem_object(dev_homosum[n]); dt_opencl_release_mem_object(dev_gminmax); dt_opencl_release_mem_object(dev_tmptmp); dt_opencl_release_mem_object(dev_xtrans); @@ -3445,12 +3532,12 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m { return process_default_cl(self, piece, dev_in, dev_out, roi_in, roi_out); } - else if(demosaicing_method == DT_IOP_DEMOSAIC_VNG4 || demosaicing_method == DT_IOP_DEMOSAIC_VNG) + else if(demosaicing_method == DT_IOP_DEMOSAIC_VNG4 || demosaicing_method == DT_IOP_DEMOSAIC_VNG) { return process_vng_cl(self, piece, dev_in, dev_out, roi_in, roi_out); } - else if((demosaicing_method == DT_IOP_DEMOSAIC_MARKESTEIJN || demosaicing_method == DT_IOP_DEMOSAIC_MARKESTEIJN_3) && - !(qual_flags & DEMOSAIC_XTRANS_FULL_MARKESTEIJN)) + else if((demosaicing_method == DT_IOP_DEMOSAIC_MARKESTEIJN || demosaicing_method == DT_IOP_DEMOSAIC_MARKESTEIJN_3) + && !(qual_flags & DEMOSAIC_XTRANS_FULL_MARKESTEIJN)) { return process_vng_cl(self, piece, dev_in, dev_out, roi_in, roi_out); } @@ -3460,22 +3547,22 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m } else { - dt_print(DT_DEBUG_OPENCL, "[opencl_demosaic] demosaicing method '%s' not yet supported by opencl code\n", method2string(demosaicing_method)); + dt_print(DT_DEBUG_OPENCL, "[opencl_demosaic] demosaicing method '%s' not yet supported by opencl code\n", + method2string(demosaicing_method)); return FALSE; } } #endif void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling) + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling) { dt_iop_demosaic_data_t *data = (dt_iop_demosaic_data_t *)piece->data; const float ioratio = (float)roi_out->width * roi_out->height / ((float)roi_in->width * roi_in->height); const float smooth = data->color_smoothing ? ioratio : 0.0f; - const float greeneq - = ((piece->pipe->dsc.filters != 9u) && (data->green_eq != DT_IOP_GREEN_EQ_NO)) ? 0.25f : 0.0f; + const float greeneq = ((piece->pipe->dsc.filters != 9u) && (data->green_eq != DT_IOP_GREEN_EQ_NO)) ? 0.25f + : 0.0f; const dt_iop_demosaic_method_t demosaicing_method = data->demosaicing_method; const int qual_flags = demosaic_qual_flags(piece, &self->dev->image_storage, roi_out); @@ -3485,19 +3572,18 @@ void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t // additional temporary buffer) const int unscaled = (roi_out->width == roi_in->width && roi_out->height == roi_in->height); - if((demosaicing_method == DT_IOP_DEMOSAIC_PPG) || - (demosaicing_method == DT_IOP_DEMOSAIC_PASSTHROUGH_MONOCHROME) || - (demosaicing_method == DT_IOP_DEMOSAIC_AMAZE)) + if((demosaicing_method == DT_IOP_DEMOSAIC_PPG) || (demosaicing_method == DT_IOP_DEMOSAIC_PASSTHROUGH_MONOCHROME) + || (demosaicing_method == DT_IOP_DEMOSAIC_AMAZE)) { // Bayer pattern with PPG, Monochrome and Amaze - tiling->factor = 1.0f + ioratio; // in + out + tiling->factor = 1.0f + ioratio; // in + out if(full_scale_demosaicing && unscaled) - tiling->factor += fmax(1.0f + greeneq, smooth); // + tmp + geeneq | + smooth + tiling->factor += fmax(1.0f + greeneq, smooth); // + tmp + geeneq | + smooth else if(full_scale_demosaicing) - tiling->factor += fmax(2.0f + greeneq, smooth); // + tmp + aux + greeneq | + smooth + tiling->factor += fmax(2.0f + greeneq, smooth); // + tmp + aux + greeneq | + smooth else - tiling->factor += smooth; // + smooth + tiling->factor += smooth; // + smooth tiling->maxbuf = 1.0f; tiling->overhead = 0; @@ -3505,19 +3591,19 @@ void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t tiling->yalign = 2; tiling->overlap = 5; // take care of border handling } - else if(((demosaicing_method == DT_IOP_DEMOSAIC_MARKESTEIJN) || - (demosaicing_method == DT_IOP_DEMOSAIC_MARKESTEIJN_3)) && - (qual_flags & DEMOSAIC_XTRANS_FULL_MARKESTEIJN)) + else if(((demosaicing_method == DT_IOP_DEMOSAIC_MARKESTEIJN) + || (demosaicing_method == DT_IOP_DEMOSAIC_MARKESTEIJN_3)) + && (qual_flags & DEMOSAIC_XTRANS_FULL_MARKESTEIJN)) { // X-Trans pattern full Markesteijn processing const int ndir = (demosaicing_method == DT_IOP_DEMOSAIC_MARKESTEIJN_3) ? 8 : 4; const int overlap = (demosaicing_method == DT_IOP_DEMOSAIC_MARKESTEIJN_3) ? 17 : 12; tiling->factor = 1.0f + ioratio; - tiling->factor += ndir * 1.0f // rgb - + ndir * 0.25f // drv - + ndir * 0.125f // homo + homosum - + 1.0f; // aux + tiling->factor += ndir * 1.0f // rgb + + ndir * 0.25f // drv + + ndir * 0.125f // homo + homosum + + 1.0f; // aux if(full_scale_demosaicing && unscaled) tiling->factor += fmax(1.0f + greeneq, smooth); @@ -3560,7 +3646,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_demosaic_params_t)); module->default_params = calloc(1, sizeof(dt_iop_demosaic_params_t)); module->default_enabled = 1; - module->priority = 117; // module order created by iop_dependencies.py, do not edit! + module->priority = 115; // module order created by iop_dependencies.py, do not edit! module->hide_enable_button = 1; module->params_size = sizeof(dt_iop_demosaic_params_t); module->gui_data = NULL; @@ -3575,8 +3661,10 @@ void init_global(dt_iop_module_so_t *module) gd->kernel_zoom_half_size = dt_opencl_create_kernel(program, "clip_and_zoom_demosaic_half_size"); gd->kernel_ppg_green = dt_opencl_create_kernel(program, "ppg_demosaic_green"); gd->kernel_green_eq_lavg = dt_opencl_create_kernel(program, "green_equilibration_lavg"); - gd->kernel_green_eq_favg_reduce_first = dt_opencl_create_kernel(program, "green_equilibration_favg_reduce_first"); - gd->kernel_green_eq_favg_reduce_second = dt_opencl_create_kernel(program, "green_equilibration_favg_reduce_second"); + gd->kernel_green_eq_favg_reduce_first + = dt_opencl_create_kernel(program, "green_equilibration_favg_reduce_first"); + gd->kernel_green_eq_favg_reduce_second + = dt_opencl_create_kernel(program, "green_equilibration_favg_reduce_second"); gd->kernel_green_eq_favg_apply = dt_opencl_create_kernel(program, "green_equilibration_favg_apply"); gd->kernel_pre_median = dt_opencl_create_kernel(program, "pre_median"); gd->kernel_ppg_redblue = dt_opencl_create_kernel(program, "ppg_demosaic_redblue"); @@ -3603,7 +3691,8 @@ void init_global(dt_iop_module_so_t *module) gd->kernel_markesteijn_solitary_green = dt_opencl_create_kernel(markesteijn, "markesteijn_solitary_green"); gd->kernel_markesteijn_recalculate_green = dt_opencl_create_kernel(markesteijn, "markesteijn_recalculate_green"); gd->kernel_markesteijn_red_and_blue = dt_opencl_create_kernel(markesteijn, "markesteijn_red_and_blue"); - gd->kernel_markesteijn_interpolate_twoxtwo = dt_opencl_create_kernel(markesteijn, "markesteijn_interpolate_twoxtwo"); + gd->kernel_markesteijn_interpolate_twoxtwo + = dt_opencl_create_kernel(markesteijn, "markesteijn_interpolate_twoxtwo"); gd->kernel_markesteijn_convert_yuv = dt_opencl_create_kernel(markesteijn, "markesteijn_convert_yuv"); gd->kernel_markesteijn_differentiate = dt_opencl_create_kernel(markesteijn, "markesteijn_differentiate"); gd->kernel_markesteijn_homo_threshold = dt_opencl_create_kernel(markesteijn, "markesteijn_homo_threshold"); @@ -3722,14 +3811,14 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *params, dt_dev // green-equilibrate over full image excludes tiling if(d->green_eq == DT_IOP_GREEN_EQ_FULL || d->green_eq == DT_IOP_GREEN_EQ_BOTH) piece->process_tiling_ready = 0; - if (self->dev->image_storage.flags & DT_IMAGE_4BAYER) + if(self->dev->image_storage.flags & DT_IMAGE_4BAYER) { // 4Bayer images not implemented in OpenCL yet piece->process_cl_ready = 0; // Get and store the matrix to go from camera to RGB for 4Bayer images char *camera = self->dev->image_storage.camera_makermodel; - if (!dt_colorspaces_conversion_matrices_rgb(camera, NULL, d->CAM_to_RGB, NULL)) + if(!dt_colorspaces_conversion_matrices_rgb(camera, NULL, d->CAM_to_RGB, NULL)) { fprintf(stderr, "[colorspaces] `%s' color matrix not found for 4bayer image!\n", camera); dt_control_log(_("`%s' color matrix not found for 4bayer image!"), camera); @@ -3801,12 +3890,11 @@ void gui_update(struct dt_iop_module_t *self) void reload_defaults(dt_iop_module_t *module) { - dt_iop_demosaic_params_t tmp - = (dt_iop_demosaic_params_t){ .green_eq = DT_IOP_GREEN_EQ_NO, - .median_thrs = 0.0f, - .color_smoothing = 0, - .demosaicing_method = DT_IOP_DEMOSAIC_PPG, - .yet_unused_data_specific_to_demosaicing_method = 0 }; + dt_iop_demosaic_params_t tmp = (dt_iop_demosaic_params_t){.green_eq = DT_IOP_GREEN_EQ_NO, + .median_thrs = 0.0f, + .color_smoothing = 0, + .demosaicing_method = DT_IOP_DEMOSAIC_PPG, + .yet_unused_data_specific_to_demosaicing_method = 0 }; // we might be called from presets update infrastructure => there is no image if(!module->dev) goto end; @@ -3978,8 +4066,8 @@ void gui_init(struct dt_iop_module_t *self) g_signal_connect(G_OBJECT(g->median_thrs), "value-changed", G_CALLBACK(median_thrs_callback), self); g_signal_connect(G_OBJECT(g->color_smoothing), "value-changed", G_CALLBACK(color_smoothing_callback), self); g_signal_connect(G_OBJECT(g->greeneq), "value-changed", G_CALLBACK(greeneq_callback), self); - g_signal_connect(G_OBJECT(g->demosaic_method_bayer), "value-changed", - G_CALLBACK(demosaic_method_bayer_callback), self); + g_signal_connect(G_OBJECT(g->demosaic_method_bayer), "value-changed", G_CALLBACK(demosaic_method_bayer_callback), + self); g_signal_connect(G_OBJECT(g->demosaic_method_xtrans), "value-changed", G_CALLBACK(demosaic_method_xtrans_callback), self); diff --git a/src/iop/denoiseprofile.c b/src/iop/denoiseprofile.c index d102c0d8e028..35e5a1d5b771 100644 --- a/src/iop/denoiseprofile.c +++ b/src/iop/denoiseprofile.c @@ -53,9 +53,9 @@ DT_MODULE_INTROSPECTION(3, dt_iop_denoiseprofile_params_t) typedef struct dt_iop_denoiseprofile_params_t { - float radius; // search radius - float strength; // noise level after equalization - float a[3], b[3]; // fit for poissonian-gaussian noise per color channel. + float radius; // search radius + float strength; // noise level after equalization + float a[3], b[3]; // fit for poissonian-gaussian noise per color channel. dt_iop_denoiseprofile_mode_t mode; // switch between nlmeans and wavelets } dt_iop_denoiseprofile_params_t; @@ -89,8 +89,8 @@ typedef struct dt_iop_denoiseprofile_global_data_t static dt_noiseprofile_t dt_iop_denoiseprofile_get_auto_profile(dt_iop_module_t *self); -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if((old_version == 1 || old_version == 2) && new_version == 3) { @@ -163,16 +163,14 @@ static inline float fast_mexp2f(const float x) } void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling) + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling) { dt_iop_denoiseprofile_params_t *d = (dt_iop_denoiseprofile_params_t *)piece->data; if(d->mode == MODE_NLMEANS) { - const int P - = ceilf(d->radius * fmin(roi_in->scale, 2.0f) / fmax(piece->iscale, 1.0f)); // pixel filter size - const int K = ceilf(7 * fmin(roi_in->scale, 2.0f) / fmax(piece->iscale, 1.0f)); // nbhood + const int P = ceilf(d->radius * fmin(roi_in->scale, 2.0f) / fmax(piece->iscale, 1.0f)); // pixel filter size + const int K = ceilf(7 * fmin(roi_in->scale, 2.0f) / fmax(piece->iscale, 1.0f)); // nbhood tiling->factor = 4.0f + 0.25f * NUM_BUCKETS; // in + out + (2 + NUM_BUCKETS * 0.25) tmp tiling->maxbuf = 1.0f; @@ -187,9 +185,8 @@ void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t int max_scale = 0; const float scale = roi_in->scale / piece->iscale; // largest desired filter on input buffer (20% of input dim) - const float supp0 - = MIN(2 * (2 << (max_max_scale - 1)) + 1, - MAX(piece->buf_in.height * piece->iscale, piece->buf_in.width * piece->iscale) * 0.2f); + const float supp0 = MIN(2 * (2 << (max_max_scale - 1)) + 1, + MAX(piece->buf_in.height * piece->iscale, piece->buf_in.width * piece->iscale) * 0.2f); const float i0 = dt_log2f((supp0 - 1.0f) * .5f); for(; max_scale < max_max_scale; max_scale++) { @@ -220,9 +217,7 @@ static inline void precondition(const float *const in, float *const buf, const i const float a[3], const float b[3]) { const float sigma2[3] - = { (b[0] / a[0]) * (b[0] / a[0]), - (b[1] / a[1]) * (b[1] / a[1]), - (b[2] / a[2]) * (b[2] / a[2]) }; + = { (b[0] / a[0]) * (b[0] / a[0]), (b[1] / a[1]) * (b[1] / a[1]), (b[2] / a[2]) * (b[2] / a[2]) }; #ifdef _OPENMP #pragma omp parallel for schedule(static) default(none) shared(a) @@ -245,13 +240,10 @@ static inline void precondition(const float *const in, float *const buf, const i } } -static inline void backtransform(float *const buf, const int wd, const int ht, const float a[3], - const float b[3]) +static inline void backtransform(float *const buf, const int wd, const int ht, const float a[3], const float b[3]) { const float sigma2[3] - = { (b[0] / a[0]) * (b[0] / a[0]), - (b[1] / a[1]) * (b[1] / a[1]), - (b[2] / a[2]) * (b[2] / a[2]) }; + = { (b[0] / a[0]) * (b[0] / a[0]), (b[1] / a[1]) * (b[1] / a[1]), (b[2] / a[2]) * (b[2] / a[2]) }; #ifdef _OPENMP #pragma omp parallel for schedule(static) default(none) shared(a) @@ -295,8 +287,7 @@ static inline float weight(const float *c1, const float *c2, const float inv_sig for(int c = 0; c < 4; c++) sqr[c] = diff[c] * diff[c]; const float dot = (sqr[0] + sqr[1] + sqr[2]) * inv_sigma2; - const float var - = 0.02f; // FIXME: this should ideally depend on the image before noise stabilizing transforms! + const float var = 0.02f; // FIXME: this should ideally depend on the image before noise stabilizing transforms! const float off2 = 9.0f; // (3 sigma)^2 return fast_mexp2f(MAX(0, dot * var - off2)); #endif @@ -312,118 +303,117 @@ static inline __m128 weight_sse(const __m128 *c1, const __m128 *c2, const float __m128 sqr = _mm_mul_ps(diff, diff); float *fsqr = (float *)&sqr; const float dot = (fsqr[0] + fsqr[1] + fsqr[2]) * inv_sigma2; - const float var - = 0.02f; // FIXME: this should ideally depend on the image before noise stabilizing transforms! + const float var = 0.02f; // FIXME: this should ideally depend on the image before noise stabilizing transforms! const float off2 = 9.0f; // (3 sigma)^2 return _mm_set1_ps(fast_mexp2f(MAX(0, dot * var - off2))); #endif } #endif -#define SUM_PIXEL_CONTRIBUTION_COMMON(ii, jj) \ - do \ - { \ - const float f = filter[(ii)] * filter[(jj)]; \ - const float wp = weight(px, px2, inv_sigma2); \ - const float w = f * wp; \ - float pd[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; \ - for(int c = 0; c < 4; c++) pd[c] = w * px2[c]; \ - for(int c = 0; c < 4; c++) sum[c] += pd[c]; \ - for(int c = 0; c < 4; c++) wgt[c] += w; \ +#define SUM_PIXEL_CONTRIBUTION_COMMON(ii, jj) \ + do \ + { \ + const float f = filter[(ii)] * filter[(jj)]; \ + const float wp = weight(px, px2, inv_sigma2); \ + const float w = f * wp; \ + float pd[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; \ + for(int c = 0; c < 4; c++) pd[c] = w * px2[c]; \ + for(int c = 0; c < 4; c++) sum[c] += pd[c]; \ + for(int c = 0; c < 4; c++) wgt[c] += w; \ } while(0) #if defined(__SSE__) -#define SUM_PIXEL_CONTRIBUTION_COMMON_SSE(ii, jj) \ - do \ - { \ - const __m128 f = _mm_set1_ps(filter[(ii)] * filter[(jj)]); \ - const __m128 wp = weight_sse(px, px2, inv_sigma2); \ - const __m128 w = _mm_mul_ps(f, wp); \ - const __m128 pd = _mm_mul_ps(w, *px2); \ - sum = _mm_add_ps(sum, pd); \ - wgt = _mm_add_ps(wgt, w); \ +#define SUM_PIXEL_CONTRIBUTION_COMMON_SSE(ii, jj) \ + do \ + { \ + const __m128 f = _mm_set1_ps(filter[(ii)] * filter[(jj)]); \ + const __m128 wp = weight_sse(px, px2, inv_sigma2); \ + const __m128 w = _mm_mul_ps(f, wp); \ + const __m128 pd = _mm_mul_ps(w, *px2); \ + sum = _mm_add_ps(sum, pd); \ + wgt = _mm_add_ps(wgt, w); \ } while(0) #endif -#define SUM_PIXEL_CONTRIBUTION_WITH_TEST(ii, jj) \ - do \ - { \ - const int iii = (ii)-2; \ - const int jjj = (jj)-2; \ - int x = i + mult * iii; \ - int y = j + mult * jjj; \ - \ - if(x < 0) x = 0; \ - if(x >= width) x = width - 1; \ - if(y < 0) y = 0; \ - if(y >= height) y = height - 1; \ - \ - px2 = ((float *)in) + 4 * x + (size_t)4 * y * width; \ - \ - SUM_PIXEL_CONTRIBUTION_COMMON(ii, jj); \ +#define SUM_PIXEL_CONTRIBUTION_WITH_TEST(ii, jj) \ + do \ + { \ + const int iii = (ii)-2; \ + const int jjj = (jj)-2; \ + int x = i + mult * iii; \ + int y = j + mult * jjj; \ + \ + if(x < 0) x = 0; \ + if(x >= width) x = width - 1; \ + if(y < 0) y = 0; \ + if(y >= height) y = height - 1; \ + \ + px2 = ((float *)in) + 4 * x + (size_t)4 * y * width; \ + \ + SUM_PIXEL_CONTRIBUTION_COMMON(ii, jj); \ } while(0) #if defined(__SSE__) -#define SUM_PIXEL_CONTRIBUTION_WITH_TEST_SSE(ii, jj) \ - do \ - { \ - const int iii = (ii)-2; \ - const int jjj = (jj)-2; \ - int x = i + mult * iii; \ - int y = j + mult * jjj; \ - \ - if(x < 0) x = 0; \ - if(x >= width) x = width - 1; \ - if(y < 0) y = 0; \ - if(y >= height) y = height - 1; \ - \ - px2 = ((__m128 *)in) + x + (size_t)y * width; \ - \ - SUM_PIXEL_CONTRIBUTION_COMMON_SSE(ii, jj); \ +#define SUM_PIXEL_CONTRIBUTION_WITH_TEST_SSE(ii, jj) \ + do \ + { \ + const int iii = (ii)-2; \ + const int jjj = (jj)-2; \ + int x = i + mult * iii; \ + int y = j + mult * jjj; \ + \ + if(x < 0) x = 0; \ + if(x >= width) x = width - 1; \ + if(y < 0) y = 0; \ + if(y >= height) y = height - 1; \ + \ + px2 = ((__m128 *)in) + x + (size_t)y * width; \ + \ + SUM_PIXEL_CONTRIBUTION_COMMON_SSE(ii, jj); \ } while(0) #endif -#define ROW_PROLOGUE \ - const float *px = ((float *)in) + (size_t)4 * j * width; \ - const float *px2; \ - float *pdetail = detail + (size_t)4 * j * width; \ +#define ROW_PROLOGUE \ + const float *px = ((float *)in) + (size_t)4 * j * width; \ + const float *px2; \ + float *pdetail = detail + (size_t)4 * j * width; \ float *pcoarse = out + (size_t)4 * j * width; #if defined(__SSE__) -#define ROW_PROLOGUE_SSE \ - const __m128 *px = ((__m128 *)in) + (size_t)j * width; \ - const __m128 *px2; \ - float *pdetail = detail + (size_t)4 * j * width; \ +#define ROW_PROLOGUE_SSE \ + const __m128 *px = ((__m128 *)in) + (size_t)j * width; \ + const __m128 *px2; \ + float *pdetail = detail + (size_t)4 * j * width; \ float *pcoarse = out + (size_t)4 * j * width; #endif -#define SUM_PIXEL_PROLOGUE \ - float sum[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; \ +#define SUM_PIXEL_PROLOGUE \ + float sum[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; \ float wgt[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; #if defined(__SSE__) -#define SUM_PIXEL_PROLOGUE_SSE \ - __m128 sum = _mm_setzero_ps(); \ +#define SUM_PIXEL_PROLOGUE_SSE \ + __m128 sum = _mm_setzero_ps(); \ __m128 wgt = _mm_setzero_ps(); #endif -#define SUM_PIXEL_EPILOGUE \ - for(int c = 0; c < 4; c++) sum[c] /= wgt[c]; \ - \ - for(int c = 0; c < 4; c++) pdetail[c] = (px[c] - sum[c]); \ - for(int c = 0; c < 4; c++) pcoarse[c] = sum[c]; \ - px += 4; \ - pdetail += 4; \ +#define SUM_PIXEL_EPILOGUE \ + for(int c = 0; c < 4; c++) sum[c] /= wgt[c]; \ + \ + for(int c = 0; c < 4; c++) pdetail[c] = (px[c] - sum[c]); \ + for(int c = 0; c < 4; c++) pcoarse[c] = sum[c]; \ + px += 4; \ + pdetail += 4; \ pcoarse += 4; #if defined(__SSE__) -#define SUM_PIXEL_EPILOGUE_SSE \ - sum = _mm_div_ps(sum, wgt); \ - \ - _mm_stream_ps(pdetail, _mm_sub_ps(*px, sum)); \ - _mm_stream_ps(pcoarse, sum); \ - px++; \ - pdetail += 4; \ +#define SUM_PIXEL_EPILOGUE_SSE \ + sum = _mm_div_ps(sum, wgt); \ + \ + _mm_stream_ps(pdetail, _mm_sub_ps(*px, sum)); \ + _mm_stream_ps(pcoarse, sum); \ + px++; \ + pdetail += 4; \ pcoarse += 4; #endif @@ -666,8 +656,8 @@ typedef void((*eaw_synthesize_t)(float *const out, const float *const in, const const float *thrsf, const float *boostf, const int32_t width, const int32_t height)); -static void eaw_synthesize(float *const out, const float *const in, const float *const detail, - const float *thrsf, const float *boostf, const int32_t width, const int32_t height) +static void eaw_synthesize(float *const out, const float *const in, const float *const detail, const float *thrsf, + const float *boostf, const int32_t width, const int32_t height) { const float threshold[4] = { thrsf[0], thrsf[1], thrsf[2], thrsf[3] }; const float boost[4] = { boostf[0], boostf[1], boostf[2], boostf[3] }; @@ -688,8 +678,7 @@ static void eaw_synthesize(float *const out, const float *const in, const float #if defined(__SSE2__) static void eaw_synthesize_sse2(float *const out, const float *const in, const float *const detail, - const float *thrsf, const float *boostf, const int32_t width, - const int32_t height) + const float *thrsf, const float *boostf, const int32_t width, const int32_t height) { const __m128 threshold = _mm_set_ps(thrsf[3], thrsf[2], thrsf[1], thrsf[0]); const __m128 boost = _mm_set_ps(boostf[3], boostf[2], boostf[1], boostf[0]); @@ -708,8 +697,7 @@ static void eaw_synthesize_sse2(float *const out, const float *const in, const f #if 1 const __m128i maski = _mm_set1_epi32(0x80000000u); const __m128 *mask = (__m128 *)&maski; - const __m128 absamt - = _mm_max_ps(_mm_setzero_ps(), _mm_sub_ps(_mm_andnot_ps(*mask, *pdetail), threshold)); + const __m128 absamt = _mm_max_ps(_mm_setzero_ps(), _mm_sub_ps(_mm_andnot_ps(*mask, *pdetail), threshold)); const __m128 amount = _mm_or_ps(_mm_and_ps(*pdetail, *mask), absamt); _mm_stream_ps(pout, _mm_add_ps(*pin, _mm_mul_ps(boost, amount))); #endif @@ -725,8 +713,8 @@ static void eaw_synthesize_sse2(float *const out, const float *const in, const f // ===================================================================================== -static void process_wavelets(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, - const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, +static void process_wavelets(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, + void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, const eaw_decompose_t decompose, const eaw_synthesize_t synthesize) { @@ -755,7 +743,7 @@ static void process_wavelets(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_ } const int width = roi_in->width, height = roi_in->height; - const size_t npixels = (size_t)width*height; + const size_t npixels = (size_t)width * height; // corner case of extremely small image. this is not really likely to happen but would cause issues later // when we divide by (n-1). so let's be prepared @@ -768,8 +756,7 @@ static void process_wavelets(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_ float *buf[MAX_MAX_SCALE]; float *tmp = NULL; float *buf1 = NULL, *buf2 = NULL; - for(int k = 0; k < max_scale; k++) - buf[k] = dt_alloc_align(64, (size_t)4 * sizeof(float) * npixels); + for(int k = 0; k < max_scale; k++) buf[k] = dt_alloc_align(64, (size_t)4 * sizeof(float) * npixels); tmp = dt_alloc_align(64, (size_t)4 * sizeof(float) * npixels); const float wb[3] = { // twice as many samples in green channel: @@ -846,7 +833,8 @@ static void process_wavelets(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_ for(int c = 0; c < 3; c++) sum_y2[c] += buf[scale][4 * k + c] * buf[scale][4 * k + c]; const float sb2 = sigma_band * sigma_band; - const float var_y[3] = { sum_y2[0] / (npixels - 1.0f), sum_y2[1] / (npixels - 1.0f), sum_y2[2] / (npixels - 1.0f) }; + const float var_y[3] + = { sum_y2[0] / (npixels - 1.0f), sum_y2[1] / (npixels - 1.0f), sum_y2[2] / (npixels - 1.0f) }; const float std_x[3] = { sqrtf(MAX(1e-6f, var_y[0] - sb2)), sqrtf(MAX(1e-6f, var_y[1] - sb2)), sqrtf(MAX(1e-6f, var_y[2] - sb2)) }; // add 8.0 here because it seemed a little weak @@ -878,9 +866,8 @@ static void process_wavelets(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_ #undef MAX_MAX_SCALE } -static void process_nlmeans(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, - const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, - const dt_iop_roi_t *const roi_out) +static void process_nlmeans(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, + void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) { // this is called for preview and full pipe separately, each with its own pixelpipe piece. // get our data struct: @@ -1024,7 +1011,8 @@ static void process_nlmeans(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t dt_free_align(in); backtransform((float *)ovoid, roi_in->width, roi_in->height, aa, bb); - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #if defined(__SSE2__) @@ -1119,8 +1107,7 @@ static void process_nlmeans_sse(struct dt_iop_module_t *self, dt_dev_pixelpipe_i // DEBUG XXX bring back to computable range: const float norm = .015f / (2 * P + 1); const __m128 iv = { ins[0], ins[1], ins[2], 1.0f }; - _mm_store_ps(out, - _mm_load_ps(out) + iv * _mm_set1_ps(fast_mexp2f(fmaxf(0.0f, slide * norm - 2.0f)))); + _mm_store_ps(out, _mm_load_ps(out) + iv * _mm_set1_ps(fast_mexp2f(fmaxf(0.0f, slide * norm - 2.0f)))); // _mm_store_ps(out, _mm_load_ps(out) + iv * _mm_set1_ps(fast_mexp2f(fmaxf(0.0f, slide*norm)))); } s++; @@ -1221,7 +1208,8 @@ static void process_nlmeans_sse(struct dt_iop_module_t *self, dt_dev_pixelpipe_i dt_free_align(in); backtransform((float *)ovoid, roi_in->width, roi_in->height, aa, bb); - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #endif @@ -1237,8 +1225,7 @@ static int bucket_next(unsigned int *state, unsigned int max) } static int process_nlmeans_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, - cl_mem dev_out, const dt_iop_roi_t *const roi_in, - const dt_iop_roi_t *const roi_out) + cl_mem dev_out, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) { dt_iop_denoiseprofile_params_t *d = (dt_iop_denoiseprofile_params_t *)piece->data; dt_iop_denoiseprofile_global_data_t *gd = (dt_iop_denoiseprofile_global_data_t *)self->data; @@ -1286,10 +1273,14 @@ static int process_nlmeans_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop } int hblocksize; - dt_opencl_local_buffer_t hlocopt - = (dt_opencl_local_buffer_t){ .xoffset = 2 * P, .xfactor = 1, .yoffset = 0, .yfactor = 1, - .cellsize = sizeof(float), .overhead = 0, - .sizex = 1 << 16, .sizey = 1 }; + dt_opencl_local_buffer_t hlocopt = (dt_opencl_local_buffer_t){.xoffset = 2 * P, + .xfactor = 1, + .yoffset = 0, + .yfactor = 1, + .cellsize = sizeof(float), + .overhead = 0, + .sizex = 1 << 16, + .sizey = 1 }; if(dt_opencl_local_buffer_opt(devid, gd->kernel_denoiseprofile_horiz, &hlocopt)) hblocksize = hlocopt.sizex; @@ -1297,10 +1288,14 @@ static int process_nlmeans_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop hblocksize = 1; int vblocksize; - dt_opencl_local_buffer_t vlocopt - = (dt_opencl_local_buffer_t){ .xoffset = 1, .xfactor = 1, .yoffset = 2 * P, .yfactor = 1, - .cellsize = sizeof(float), .overhead = 0, - .sizex = 1, .sizey = 1 << 16 }; + dt_opencl_local_buffer_t vlocopt = (dt_opencl_local_buffer_t){.xoffset = 1, + .xfactor = 1, + .yoffset = 2 * P, + .yfactor = 1, + .cellsize = sizeof(float), + .overhead = 0, + .sizex = 1, + .sizey = 1 << 16 }; if(dt_opencl_local_buffer_opt(devid, gd->kernel_denoiseprofile_vert, &vlocopt)) vblocksize = vlocopt.sizey; @@ -1320,8 +1315,7 @@ static int process_nlmeans_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_precondition, 2, sizeof(int), (void *)&width); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_precondition, 3, sizeof(int), (void *)&height); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_precondition, 4, 4 * sizeof(float), (void *)&aa); - dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_precondition, 5, 4 * sizeof(float), - (void *)&sigma2); + dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_precondition, 5, 4 * sizeof(float), (void *)&sigma2); err = dt_opencl_enqueue_kernel_2d(devid, gd->kernel_denoiseprofile_precondition, sizes); if(err != CL_SUCCESS) goto error; @@ -1433,8 +1427,7 @@ static int process_nlmeans_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop static int process_wavelets_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, - cl_mem dev_out, const dt_iop_roi_t *const roi_in, - const dt_iop_roi_t *const roi_out) + cl_mem dev_out, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) { dt_iop_denoiseprofile_data_t *d = (dt_iop_denoiseprofile_data_t *)piece->data; dt_iop_denoiseprofile_global_data_t *gd = (dt_iop_denoiseprofile_global_data_t *)self->data; @@ -1443,9 +1436,8 @@ static int process_wavelets_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_io int max_scale = 0; const float scale = roi_in->scale / piece->iscale; // largest desired filter on input buffer (20% of input dim) - const float supp0 - = MIN(2 * (2 << (max_max_scale - 1)) + 1, - MAX(piece->buf_in.height * piece->iscale, piece->buf_in.width * piece->iscale) * 0.2f); + const float supp0 = MIN(2 * (2 << (max_max_scale - 1)) + 1, + MAX(piece->buf_in.height * piece->iscale, piece->buf_in.width * piece->iscale) * 0.2f); const float i0 = dt_log2f((supp0 - 1.0f) * .5f); for(; max_scale < max_max_scale; max_scale++) { @@ -1487,26 +1479,32 @@ static int process_wavelets_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_io return TRUE; } - dt_opencl_local_buffer_t flocopt - = (dt_opencl_local_buffer_t){ .xoffset = 0, .xfactor = 1, .yoffset = 0, .yfactor = 1, - .cellsize = 4 * sizeof(float), .overhead = 0, - .sizex = 1 << 4, .sizey = 1 << 4 }; + dt_opencl_local_buffer_t flocopt = (dt_opencl_local_buffer_t){.xoffset = 0, + .xfactor = 1, + .yoffset = 0, + .yfactor = 1, + .cellsize = 4 * sizeof(float), + .overhead = 0, + .sizex = 1 << 4, + .sizey = 1 << 4 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_denoiseprofile_reduce_first, &flocopt)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_denoiseprofile_reduce_first, &flocopt)) goto error; const size_t bwidth = ROUNDUP(width, flocopt.sizex); const size_t bheight = ROUNDUP(height, flocopt.sizey); const int bufsize = (bwidth / flocopt.sizex) * (bheight / flocopt.sizey); - dt_opencl_local_buffer_t slocopt - = (dt_opencl_local_buffer_t){ .xoffset = 0, .xfactor = 1, .yoffset = 0, .yfactor = 1, - .cellsize = 4 * sizeof(float), .overhead = 0, - .sizex = 1 << 16, .sizey = 1 }; + dt_opencl_local_buffer_t slocopt = (dt_opencl_local_buffer_t){.xoffset = 0, + .xfactor = 1, + .yoffset = 0, + .yfactor = 1, + .cellsize = 4 * sizeof(float), + .overhead = 0, + .sizex = 1 << 16, + .sizey = 1 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_denoiseprofile_reduce_first, &slocopt)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_denoiseprofile_reduce_first, &slocopt)) goto error; const int reducesize = MIN(REDUCESIZE, ROUNDUP(bufsize, slocopt.sizex) / slocopt.sizex); @@ -1551,8 +1549,7 @@ static int process_wavelets_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_io dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_precondition, 2, sizeof(int), (void *)&width); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_precondition, 3, sizeof(int), (void *)&height); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_precondition, 4, 4 * sizeof(float), (void *)&aa); - dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_precondition, 5, 4 * sizeof(float), - (void *)&sigma2); + dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_precondition, 5, 4 * sizeof(float), (void *)&sigma2); err = dt_opencl_enqueue_kernel_2d(devid, gd->kernel_denoiseprofile_precondition, sizes); if(err != CL_SUCCESS) goto error; @@ -1569,16 +1566,12 @@ static int process_wavelets_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_io dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_decompose, 0, sizeof(cl_mem), (void *)&dev_buf1); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_decompose, 1, sizeof(cl_mem), (void *)&dev_buf2); - dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_decompose, 2, sizeof(cl_mem), - (void *)&dev_detail[s]); + dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_decompose, 2, sizeof(cl_mem), (void *)&dev_detail[s]); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_decompose, 3, sizeof(int), (void *)&width); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_decompose, 4, sizeof(int), (void *)&height); - dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_decompose, 5, sizeof(unsigned int), - (void *)&s); - dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_decompose, 6, sizeof(float), - (void *)&inv_sigma2); - dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_decompose, 7, sizeof(cl_mem), - (void *)&dev_filter); + dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_decompose, 5, sizeof(unsigned int), (void *)&s); + dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_decompose, 6, sizeof(float), (void *)&inv_sigma2); + dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_decompose, 7, sizeof(cl_mem), (void *)&dev_filter); err = dt_opencl_enqueue_kernel_2d(devid, gd->kernel_denoiseprofile_decompose, sizes); if(err != CL_SUCCESS) goto error; @@ -1612,15 +1605,13 @@ static int process_wavelets_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_io llocal[0] = flocopt.sizex; llocal[1] = flocopt.sizey; llocal[2] = 1; - dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_reduce_first, 0, sizeof(cl_mem), - &(dev_detail[s])); + dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_reduce_first, 0, sizeof(cl_mem), &(dev_detail[s])); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_reduce_first, 1, sizeof(int), &width); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_reduce_first, 2, sizeof(int), &height); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_reduce_first, 3, sizeof(cl_mem), &dev_m); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_reduce_first, 4, flocopt.sizex * flocopt.sizey * 4 * sizeof(float), NULL); - err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_denoiseprofile_reduce_first, lsizes, - llocal); + err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_denoiseprofile_reduce_first, lsizes, llocal); if(err != CL_SUCCESS) goto error; @@ -1635,14 +1626,12 @@ static int process_wavelets_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_io dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_reduce_second, 2, sizeof(int), &bufsize); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_reduce_second, 3, slocopt.sizex * 4 * sizeof(float), NULL); - err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_denoiseprofile_reduce_second, lsizes, - llocal); + err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_denoiseprofile_reduce_second, lsizes, llocal); if(err != CL_SUCCESS) goto error; err = dt_opencl_read_buffer_from_device(devid, (void *)sumsum, dev_r, 0, (size_t)reducesize * 4 * sizeof(float), CL_TRUE); - if(err != CL_SUCCESS) - goto error; + if(err != CL_SUCCESS) goto error; for(int k = 0; k < reducesize; k++) { @@ -1653,7 +1642,8 @@ static int process_wavelets_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_io } const float sb2 = sigma_band * sigma_band; - const float var_y[3] = { sum_y2[0] / (npixels - 1.0f), sum_y2[1] / (npixels - 1.0f), sum_y2[2] / (npixels - 1.0f) }; + const float var_y[3] + = { sum_y2[0] / (npixels - 1.0f), sum_y2[1] / (npixels - 1.0f), sum_y2[2] / (npixels - 1.0f) }; const float std_x[3] = { sqrtf(MAX(1e-6f, var_y[0] - sb2)), sqrtf(MAX(1e-6f, var_y[1] - sb2)), sqrtf(MAX(1e-6f, var_y[2] - sb2)) }; // add 8.0 here because it seemed a little weak @@ -1664,12 +1654,10 @@ static int process_wavelets_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_io const float boost[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; - dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_synthesize, 0, sizeof(cl_mem), - (void *)&dev_buf1); + dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_synthesize, 0, sizeof(cl_mem), (void *)&dev_buf1); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_synthesize, 1, sizeof(cl_mem), (void *)&dev_detail[s]); - dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_synthesize, 2, sizeof(cl_mem), - (void *)&dev_buf2); + dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_synthesize, 2, sizeof(cl_mem), (void *)&dev_buf2); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_synthesize, 3, sizeof(int), (void *)&width); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_synthesize, 4, sizeof(int), (void *)&height); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_synthesize, 5, sizeof(float), (void *)&thrs[0]); @@ -1677,12 +1665,9 @@ static int process_wavelets_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_io dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_synthesize, 7, sizeof(float), (void *)&thrs[2]); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_synthesize, 8, sizeof(float), (void *)&thrs[3]); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_synthesize, 9, sizeof(float), (void *)&boost[0]); - dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_synthesize, 10, sizeof(float), - (void *)&boost[1]); - dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_synthesize, 11, sizeof(float), - (void *)&boost[2]); - dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_synthesize, 12, sizeof(float), - (void *)&boost[3]); + dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_synthesize, 10, sizeof(float), (void *)&boost[1]); + dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_synthesize, 11, sizeof(float), (void *)&boost[2]); + dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_synthesize, 12, sizeof(float), (void *)&boost[3]); err = dt_opencl_enqueue_kernel_2d(devid, gd->kernel_denoiseprofile_synthesize, sizes); if(err != CL_SUCCESS) goto error; @@ -1705,28 +1690,23 @@ static int process_wavelets_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_io if(err != CL_SUCCESS) goto error; } - dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_backtransform, 0, sizeof(cl_mem), - (void *)&dev_tmp); - dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_backtransform, 1, sizeof(cl_mem), - (void *)&dev_out); + dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_backtransform, 0, sizeof(cl_mem), (void *)&dev_tmp); + dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_backtransform, 1, sizeof(cl_mem), (void *)&dev_out); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_backtransform, 2, sizeof(int), (void *)&width); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_backtransform, 3, sizeof(int), (void *)&height); dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_backtransform, 4, 4 * sizeof(float), (void *)&aa); - dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_backtransform, 5, 4 * sizeof(float), - (void *)&sigma2); + dt_opencl_set_kernel_arg(devid, gd->kernel_denoiseprofile_backtransform, 5, 4 * sizeof(float), (void *)&sigma2); err = dt_opencl_enqueue_kernel_2d(devid, gd->kernel_denoiseprofile_backtransform, sizes); if(err != CL_SUCCESS) goto error; - if(!darktable.opencl->async_pixelpipe || piece->pipe->type == DT_DEV_PIXELPIPE_EXPORT) - dt_opencl_finish(devid); + if(!darktable.opencl->async_pixelpipe || piece->pipe->type == DT_DEV_PIXELPIPE_EXPORT) dt_opencl_finish(devid); dt_opencl_release_mem_object(dev_r); dt_opencl_release_mem_object(dev_m); dt_opencl_release_mem_object(dev_tmp); dt_opencl_release_mem_object(dev_filter); - for(int k = 0; k < max_scale; k++) - dt_opencl_release_mem_object(dev_detail[k]); + for(int k = 0; k < max_scale; k++) dt_opencl_release_mem_object(dev_detail[k]); free(dev_detail); dt_free_align(sumsum); return TRUE; @@ -1736,8 +1716,7 @@ static int process_wavelets_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_io dt_opencl_release_mem_object(dev_m); dt_opencl_release_mem_object(dev_tmp); dt_opencl_release_mem_object(dev_filter); - for(int k = 0; k < max_scale; k++) - dt_opencl_release_mem_object(dev_detail[k]); + for(int k = 0; k < max_scale; k++) dt_opencl_release_mem_object(dev_detail[k]); free(dev_detail); dt_free_align(sumsum); dt_print(DT_DEBUG_OPENCL, "[opencl_denoiseprofile] couldn't enqueue kernel! %d, devid %d\n", err, devid); @@ -1849,7 +1828,7 @@ void init(dt_iop_module_t *module) { module->params = calloc(1, sizeof(dt_iop_denoiseprofile_params_t)); module->default_params = calloc(1, sizeof(dt_iop_denoiseprofile_params_t)); - module->priority = 132; // module order created by iop_dependencies.py, do not edit! + module->priority = 130; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_denoiseprofile_params_t); module->gui_data = NULL; module->data = NULL; @@ -2027,8 +2006,7 @@ void gui_update(dt_iop_module_t *self) for(GList *iter = g->profiles; iter; iter = g_list_next(iter), i++) { dt_noiseprofile_t *profile = (dt_noiseprofile_t *)iter->data; - if(!memcmp(profile->a, p->a, sizeof(float) * 3) - && !memcmp(profile->b, p->b, sizeof(float) * 3)) + if(!memcmp(profile->a, p->a, sizeof(float) * 3) && !memcmp(profile->b, p->b, sizeof(float) * 3)) { dt_bauhaus_combobox_set(g->profile, i); break; diff --git a/src/iop/dither.c b/src/iop/dither.c index 0b9ff13c9eb1..e476a023acfe 100644 --- a/src/iop/dither.c +++ b/src/iop/dither.c @@ -189,10 +189,9 @@ static __m128 _find_nearest_color_n_levels_rgb_sse2(float *val, const float f, c __m128 tmp = _mm_mul_ps(old, _mm_set1_ps(f)); // old * f __m128 itmp = _mm_cvtepi32_ps(_mm_cvtps_epi32(tmp)); // floor(tmp) __m128 new = _mm_mul_ps( - _mm_add_ps(itmp, - _mm_and_ps(_mm_cmpgt_ps(_mm_sub_ps(tmp, itmp), // (tmp - itmp > 0.5f ? itmp + 1 : itmp) * rf - _mm_set1_ps(0.5f)), - _mm_set1_ps(1.0f))), + _mm_add_ps(itmp, _mm_and_ps(_mm_cmpgt_ps(_mm_sub_ps(tmp, itmp), // (tmp - itmp > 0.5f ? itmp + 1 : itmp) * rf + _mm_set1_ps(0.5f)), + _mm_set1_ps(1.0f))), _mm_set1_ps(rf)); _mm_store_ps(val, new); @@ -212,8 +211,7 @@ static inline void _diffuse_error(float *val, const float *err, const float fact #if defined(__SSE__) static inline void _diffuse_error_sse(float *val, const __m128 err, const float factor) { - _mm_store_ps(val, - _mm_add_ps(_mm_load_ps(val), _mm_mul_ps(err, _mm_set1_ps(factor)))); // *val += err * factor + _mm_store_ps(val, _mm_add_ps(_mm_load_ps(val), _mm_mul_ps(err, _mm_set1_ps(factor)))); // *val += err * factor } #endif @@ -230,8 +228,8 @@ static inline float clipnan(const float x) } static void process_floyd_steinberg(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, - const void *const ivoid, void *const ovoid, - const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) + const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, + const dt_iop_roi_t *const roi_out) { dt_iop_dither_data_t *data = (dt_iop_dither_data_t *)piece->data; @@ -335,7 +333,8 @@ static void process_floyd_steinberg(struct dt_iop_module_t *self, dt_dev_pixelpi for(int i = 0; i < width; i++) nearest_color(out + ch * i, err, f, rf); } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); return; } @@ -391,7 +390,8 @@ static void process_floyd_steinberg(struct dt_iop_module_t *self, dt_dev_pixelpi } while(0); // copy alpha channel if needed - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #if defined(__SSE2__) @@ -501,7 +501,8 @@ static void process_floyd_steinberg_sse2(struct dt_iop_module_t *self, dt_dev_pi for(int i = 0; i < width; i++) (void)nearest_color(out + ch * i, f, rf); } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); return; } @@ -557,7 +558,8 @@ static void process_floyd_steinberg_sse2(struct dt_iop_module_t *self, dt_dev_pi } while(0); // copy alpha channel if needed - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #endif @@ -587,9 +589,8 @@ static float tpdf(unsigned int urandom) } -static void process_random(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, - const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, - const dt_iop_roi_t *const roi_out) +static void process_random(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, + void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) { dt_iop_dither_data_t *data = (dt_iop_dither_data_t *)piece->data; diff --git a/src/iop/equalizer.c b/src/iop/equalizer.c index d80e90d95474..46dcfb384d52 100644 --- a/src/iop/equalizer.c +++ b/src/iop/equalizer.c @@ -187,11 +187,10 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const for(int j = step / 2; j < height; j += step) for(int i = 0; i < width; i += step) out[(size_t)chs * width * j + chs * i + ch] *= coeff; for(int j = step / 2; j < height; j += step) - for(int i = step / 2; i < width; i += step) - out[(size_t)chs * width * j + chs * i + ch] *= coeff * coeff; + for(int i = step / 2; i < width; i += step) out[(size_t)chs * width * j + chs * i + ch] *= coeff * coeff; #else // soft-thresholding (shrinkage) -#define wshrink \ - (copysignf(fmaxf(0.0f, fabsf(out[(size_t)chs * width * j + chs * i + ch]) - (1.0 - coeff)), \ +#define wshrink \ + (copysignf(fmaxf(0.0f, fabsf(out[(size_t)chs * width * j + chs * i + ch]) - (1.0 - coeff)), \ out[(size_t)chs * width * j + chs * i + ch])) for(int j = 0; j < height; j += step) for(int i = step / 2; i < width; i += step) out[(size_t)chs * width * j + chs * i + ch] = wshrink; @@ -249,7 +248,7 @@ void init_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pi void cleanup_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece) { -// clean up everything again. + // clean up everything again. dt_iop_equalizer_data_t *d = (dt_iop_equalizer_data_t *)(piece->data); for(int ch = 0; ch < 3; ch++) dt_draw_curve_destroy(d->curve[ch]); free(piece->data); @@ -267,7 +266,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_equalizer_params_t)); module->default_params = calloc(1, sizeof(dt_iop_equalizer_params_t)); module->default_enabled = 0; // we're a rather slow and rare op. - module->priority = 411; // module order created by iop_dependencies.py, do not edit! + module->priority = 420; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_equalizer_params_t); module->gui_data = NULL; dt_iop_equalizer_params_t tmp; diff --git a/src/iop/equalizer_eaw.h b/src/iop/equalizer_eaw.h index 1d58e244b173..7874e4364d10 100644 --- a/src/iop/equalizer_eaw.h +++ b/src/iop/equalizer_eaw.h @@ -19,8 +19,8 @@ #pragma once // edge-avoiding wavelet: -#define gweight(i, j, ii, jj) \ - 1.0 / (fabsf(weight_a[l][(size_t)wd * ((j) >> (l - 1)) + ((i) >> (l - 1))] \ +#define gweight(i, j, ii, jj) \ + 1.0 / (fabsf(weight_a[l][(size_t)wd * ((j) >> (l - 1)) + ((i) >> (l - 1))] \ - weight_a[l][(size_t)wd * ((jj) >> (l - 1)) + ((ii) >> (l - 1))]) + 1.e-5) // #define gweight(i, j, ii, jj) 1.0/(powf(fabsf(weight_a[l][wd*((j)>>(l-1)) + ((i)>>(l-1))] - // weight_a[l][wd*((jj)>>(l-1)) + ((ii)>>(l-1))]),0.8)+1.e-5) diff --git a/src/iop/exposure.c b/src/iop/exposure.c index 956351eb69e8..eca3768da68d 100644 --- a/src/iop/exposure.c +++ b/src/iop/exposure.c @@ -136,8 +136,8 @@ void connect_key_accels(dt_iop_module_t *self) dt_accel_connect_slider_iop(self, "target level", GTK_WIDGET(g->deflicker_target_level)); } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 2 && new_version == 5) { @@ -180,7 +180,8 @@ int legacy_params(dt_iop_module_t *self, const void *const old_params, const int } if(old_version == 4 && new_version == 5) { - typedef enum dt_iop_exposure_deflicker_histogram_source_t { + typedef enum dt_iop_exposure_deflicker_histogram_source_t + { DEFLICKER_HISTOGRAM_SOURCE_THUMBNAIL, DEFLICKER_HISTOGRAM_SOURCE_SOURCEFILE } dt_iop_exposure_deflicker_histogram_source_t; @@ -212,7 +213,7 @@ int legacy_params(dt_iop_module_t *self, const void *const old_params, const int return 1; } -void init_presets (dt_iop_module_so_t *self) +void init_presets(dt_iop_module_so_t *self) { DT_DEBUG_SQLITE3_EXEC(dt_database_get(darktable.db), "BEGIN", NULL, NULL, NULL); @@ -260,8 +261,7 @@ static void deflicker_prepare_histogram(dt_iop_module_t *self, uint32_t **histog histogram_params.roi = &histogram_roi; histogram_params.bins_count = DEFLICKER_BINS_COUNT; - dt_histogram_worker(&histogram_params, histogram_stats, buf.buf, histogram, - dt_histogram_helper_cs_RAW_uint16); + dt_histogram_worker(&histogram_params, histogram_stats, buf.buf, histogram, dt_histogram_helper_cs_RAW_uint16); histogram_stats->ch = 1u; dt_mipmap_cache_release(darktable.mipmap_cache, &buf); @@ -294,8 +294,7 @@ static void compute_correction(dt_iop_module_t *self, dt_iop_params_t *p1, dt_de const size_t total = (size_t)histogram_stats->ch * histogram_stats->pixels; - const double thr - = CLAMP(((double)total * (double)p->deflicker_percentile / (double)100.0), 0.0, (double)total); + const double thr = CLAMP(((double)total * (double)p->deflicker_percentile / (double)100.0), 0.0, (double)total); size_t n = 0; uint32_t raw = 0; @@ -405,14 +404,15 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const ((float *)o)[k] = (((float *)i)[k] - d->black) * d->scale; } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(i, o, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(i, o, roi_out->width, roi_out->height); for(int k = 0; k < 3; k++) piece->pipe->dsc.processed_maximum[k] *= d->scale; } #if defined(__SSE__) -void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const i, - void *const o, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) +void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const i, void *const o, + const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) { const dt_iop_exposure_data_t *const d = (const dt_iop_exposure_data_t *const)piece->data; @@ -433,7 +433,8 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c _mm_store_ps(out, _mm_mul_ps(_mm_sub_ps(_mm_load_ps(in), blackv), scalev)); } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(i, o, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(i, o, roi_out->width, roi_out->height); for(int k = 0; k < 3; k++) piece->pipe->dsc.processed_maximum[k] *= d->scale; } @@ -539,7 +540,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_exposure_params_t)); module->default_params = calloc(1, sizeof(dt_iop_exposure_params_t)); module->default_enabled = 0; - module->priority = 161; // module order created by iop_dependencies.py, do not edit! + module->priority = 173; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_exposure_params_t); module->gui_data = NULL; } @@ -550,8 +551,7 @@ void reload_defaults(dt_iop_module_t *module) .black = 0.0f, .exposure = 0.0f, .deflicker_percentile = 50.0f, - .deflicker_target_level = -4.0f - }; + .deflicker_target_level = -4.0f }; memcpy(module->params, &tmp, sizeof(dt_iop_exposure_params_t)); memcpy(module->default_params, &tmp, sizeof(dt_iop_exposure_params_t)); @@ -739,8 +739,8 @@ static void autoexpp_callback(GtkWidget *slider, gpointer user_data) if(self->request_color_pick != DT_REQUEST_COLORPICK_MODULE || self->picked_color_max[0] < 0.0f) return; dt_iop_exposure_gui_data_t *g = (dt_iop_exposure_gui_data_t *)self->gui_data; - const float white = fmaxf(fmaxf(self->picked_color_max[0], self->picked_color_max[1]), - self->picked_color_max[2]) * (1.0 - dt_bauhaus_slider_get(g->autoexpp)); + const float white = fmaxf(fmaxf(self->picked_color_max[0], self->picked_color_max[1]), self->picked_color_max[2]) + * (1.0 - dt_bauhaus_slider_get(g->autoexpp)); exposure_set_white(self, white); } @@ -807,8 +807,8 @@ static gboolean draw(GtkWidget *widget, cairo_t *cr, dt_iop_module_t *self) if(self->picked_color_max[0] < 0.0f) return FALSE; - const float white = fmaxf(fmaxf(self->picked_color_max[0], self->picked_color_max[1]), - self->picked_color_max[2]) * (1.0 - dt_bauhaus_slider_get(g->autoexpp)); + const float white = fmaxf(fmaxf(self->picked_color_max[0], self->picked_color_max[1]), self->picked_color_max[2]) + * (1.0 - dt_bauhaus_slider_get(g->autoexpp)); const float black = fminf(fminf(self->picked_color_min[0], self->picked_color_min[1]), self->picked_color_min[2]); @@ -867,7 +867,7 @@ void gui_init(struct dt_iop_module_t *self) gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(g->black), TRUE, TRUE, 0); g->mode_stack = gtk_stack_new(); - gtk_stack_set_homogeneous(GTK_STACK(g->mode_stack),FALSE); + gtk_stack_set_homogeneous(GTK_STACK(g->mode_stack), FALSE); gtk_box_pack_start(GTK_BOX(self->widget), g->mode_stack, TRUE, TRUE, 0); GtkWidget *vbox_manual = GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_VERTICAL, DT_BAUHAUS_SPACE)); @@ -880,7 +880,8 @@ void gui_init(struct dt_iop_module_t *self) gtk_box_pack_start(GTK_BOX(vbox_manual), GTK_WIDGET(g->exposure), TRUE, TRUE, 0); g->autoexpp = dt_bauhaus_slider_new_with_range(self, 0.0, 0.2, .001, 0.01, 3); - gtk_widget_set_tooltip_text(g->autoexpp, _("percentage of bright values clipped out, toggle color picker to activate")); + gtk_widget_set_tooltip_text(g->autoexpp, + _("percentage of bright values clipped out, toggle color picker to activate")); dt_bauhaus_slider_set_format(g->autoexpp, "%.3f%%"); dt_bauhaus_widget_set_label(g->autoexpp, NULL, _("clipping threshold")); dt_bauhaus_widget_set_quad_paint(g->autoexpp, dtgtk_cairo_paint_colorpicker, CPF_ACTIVE); @@ -912,7 +913,8 @@ void gui_init(struct dt_iop_module_t *self) gtk_box_pack_start(GTK_BOX(hbox1), GTK_WIDGET(label), FALSE, FALSE, 0); g->deflicker_used_EC = GTK_LABEL(gtk_label_new("")); // This gets filled in by process - gtk_widget_set_tooltip_text(GTK_WIDGET(g->deflicker_used_EC), _("what exposure correction has actually been used")); + gtk_widget_set_tooltip_text(GTK_WIDGET(g->deflicker_used_EC), + _("what exposure correction has actually been used")); gtk_box_pack_start(GTK_BOX(hbox1), GTK_WIDGET(g->deflicker_used_EC), FALSE, FALSE, 0); dt_pthread_mutex_lock(&g->lock); @@ -929,10 +931,9 @@ void gui_init(struct dt_iop_module_t *self) g_signal_connect(G_OBJECT(g->exposure), "value-changed", G_CALLBACK(exposure_callback), self); g_signal_connect(G_OBJECT(g->autoexpp), "value-changed", G_CALLBACK(autoexpp_callback), self); g_signal_connect(G_OBJECT(g->autoexpp), "quad-pressed", G_CALLBACK(autoexp_callback), self); - g_signal_connect(G_OBJECT(g->deflicker_percentile), "value-changed", G_CALLBACK(deflicker_params_callback), + g_signal_connect(G_OBJECT(g->deflicker_percentile), "value-changed", G_CALLBACK(deflicker_params_callback), self); + g_signal_connect(G_OBJECT(g->deflicker_target_level), "value-changed", G_CALLBACK(deflicker_params_callback), self); - g_signal_connect(G_OBJECT(g->deflicker_target_level), "value-changed", - G_CALLBACK(deflicker_params_callback), self); g_signal_connect(G_OBJECT(self->widget), "draw", G_CALLBACK(draw), self); } diff --git a/src/iop/finalscale.c b/src/iop/finalscale.c index 603bde32de64..fad4a35856e9 100644 --- a/src/iop/finalscale.c +++ b/src/iop/finalscale.c @@ -41,7 +41,8 @@ const char *name() int flags() { - return IOP_FLAGS_ALLOW_TILING | IOP_FLAGS_HIDDEN | IOP_FLAGS_TILING_FULL_ROI | IOP_FLAGS_ONE_INSTANCE | IOP_FLAGS_NO_HISTORY_STACK; + return IOP_FLAGS_ALLOW_TILING | IOP_FLAGS_HIDDEN | IOP_FLAGS_TILING_FULL_ROI | IOP_FLAGS_ONE_INSTANCE + | IOP_FLAGS_NO_HISTORY_STACK; } int groups() @@ -57,8 +58,8 @@ void modify_roi_in(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const d roi_in->x /= roi_out->scale; roi_in->y /= roi_out->scale; // out = in * scale + .5f to more precisely round to user input in export module: - roi_in->width = (roi_out->width - .5f)/roi_out->scale; - roi_in->height = (roi_out->height - .5f)/roi_out->scale; + roi_in->width = (roi_out->width - .5f) / roi_out->scale; + roi_in->height = (roi_out->height - .5f) / roi_out->scale; roi_in->scale = 1.0f; } @@ -68,8 +69,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m { if(roi_out->scale >= 1.00001f) { - dt_print(DT_DEBUG_OPENCL, - "[opencl_finalscale] finalscale with upscaling not yet supported by opencl code\n"); + dt_print(DT_DEBUG_OPENCL, "[opencl_finalscale] finalscale with upscaling not yet supported by opencl code\n"); return FALSE; } @@ -117,7 +117,7 @@ void init(dt_iop_module_t *self) self->default_params = calloc(1, sizeof(dt_iop_finalscale_params_t)); self->default_enabled = 1; self->hide_enable_button = 1; - self->priority = 911; // module order created by iop_dependencies.py, do not edit! + self->priority = 913; // module order created by iop_dependencies.py, do not edit! self->params_size = sizeof(dt_iop_finalscale_params_t); self->gui_data = NULL; } diff --git a/src/iop/flip.c b/src/iop/flip.c index 0546fddf92c0..a5fd5788189f 100644 --- a/src/iop/flip.c +++ b/src/iop/flip.c @@ -119,8 +119,8 @@ static dt_image_orientation_t merge_two_orientations(dt_image_orientation_t raw_ return raw_orientation_corrected ^ user_orientation; } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 1 && new_version == 2) { @@ -138,11 +138,9 @@ int legacy_params(dt_iop_module_t *self, const void *const old_params, const int // we might be called from presets update infrastructure => there is no image dt_image_orientation_t image_orientation = ORIENTATION_NONE; - if(self->dev) - image_orientation = dt_image_orientation(&self->dev->image_storage); + if(self->dev) image_orientation = dt_image_orientation(&self->dev->image_storage); - n->orientation = merge_two_orientations(image_orientation, - (dt_image_orientation_t)(old->orientation)); + n->orientation = merge_two_orientations(image_orientation, (dt_image_orientation_t)(old->orientation)); return 0; } @@ -200,8 +198,7 @@ int distort_transform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, floa return 1; } -int distort_backtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, float *points, - size_t points_count) +int distort_backtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, float *points, size_t points_count) { // if (!self->enabled) return 2; const dt_iop_flip_data_t *d = (dt_iop_flip_data_t *)piece->data; @@ -246,8 +243,8 @@ void modify_roi_out(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t } // 2nd pass: which roi would this operation need as input to fill the given output region? -void modify_roi_in(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_out, dt_iop_roi_t *roi_in) +void modify_roi_in(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const dt_iop_roi_t *roi_out, + dt_iop_roi_t *roi_in) { const dt_iop_flip_data_t *d = (dt_iop_flip_data_t *)piece->data; *roi_in = *roi_out; @@ -293,8 +290,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const const int bpp = sizeof(float) * piece->colors; const int stride = bpp * roi_in->width; - dt_imageio_flip_buffers((char *)ovoid, (const char *)ivoid, bpp, roi_in->width, roi_in->height, - roi_in->width, roi_in->height, stride, d->orientation); + dt_imageio_flip_buffers((char *)ovoid, (const char *)ivoid, bpp, roi_in->width, roi_in->height, roi_in->width, + roi_in->height, stride, d->orientation); } #ifdef HAVE_OPENCL @@ -398,15 +395,14 @@ void init_presets(dt_iop_module_so_t *self) void reload_defaults(dt_iop_module_t *self) { - dt_iop_flip_params_t tmp = (dt_iop_flip_params_t){ .orientation = ORIENTATION_NULL }; + dt_iop_flip_params_t tmp = (dt_iop_flip_params_t){.orientation = ORIENTATION_NULL }; // we might be called from presets update infrastructure => there is no image if(!self->dev) goto end; self->default_enabled = 1; - if(self->dev->image_storage.legacy_flip.user_flip != 0 - && self->dev->image_storage.legacy_flip.user_flip != 0xff) + if(self->dev->image_storage.legacy_flip.user_flip != 0 && self->dev->image_storage.legacy_flip.user_flip != 0xff) { sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), @@ -442,7 +438,7 @@ void init(dt_iop_module_t *module) module->default_enabled = 1; module->params_size = sizeof(dt_iop_flip_params_t); module->gui_data = NULL; - module->priority = 264; // module order created by iop_dependencies.py, do not edit! + module->priority = 275; // module order created by iop_dependencies.py, do not edit! } void cleanup(dt_iop_module_t *module) diff --git a/src/iop/globaltonemap.c b/src/iop/globaltonemap.c index eaad0069132e..d51d763dedc4 100644 --- a/src/iop/globaltonemap.c +++ b/src/iop/globaltonemap.c @@ -111,8 +111,8 @@ int groups() return IOP_GROUP_TONE; } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version < 3 && new_version == 3) { @@ -128,9 +128,8 @@ int legacy_params(dt_iop_module_t *self, const void *const old_params, const int } static inline void process_reinhard(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, - const void *const ivoid, void *const ovoid, - const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, - dt_iop_global_tonemap_data_t *data) + const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, + const dt_iop_roi_t *const roi_out, dt_iop_global_tonemap_data_t *data) { float *in = (float *)ivoid; float *out = (float *)ovoid; @@ -229,9 +228,8 @@ static inline void process_drago(struct dt_iop_module_t *self, dt_dev_pixelpipe_ } static inline void process_filmic(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, - const void *const ivoid, void *const ovoid, - const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, - dt_iop_global_tonemap_data_t *data) + const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, + const dt_iop_roi_t *const roi_out, dt_iop_global_tonemap_data_t *data) { float *in = (float *)ivoid; float *out = (float *)ovoid; @@ -290,7 +288,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const dt_bilateral_free(b); } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #ifdef HAVE_OPENCL @@ -348,26 +347,32 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m if(isnan(tmp_lwmax)) { - dt_opencl_local_buffer_t flocopt - = (dt_opencl_local_buffer_t){ .xoffset = 0, .xfactor = 1, .yoffset = 0, .yfactor = 1, - .cellsize = sizeof(float), .overhead = 0, - .sizex = 1 << 4, .sizey = 1 << 4 }; + dt_opencl_local_buffer_t flocopt = (dt_opencl_local_buffer_t){.xoffset = 0, + .xfactor = 1, + .yoffset = 0, + .yfactor = 1, + .cellsize = sizeof(float), + .overhead = 0, + .sizex = 1 << 4, + .sizey = 1 << 4 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_pixelmax_first, &flocopt)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_pixelmax_first, &flocopt)) goto error; const size_t bwidth = ROUNDUP(width, flocopt.sizex); const size_t bheight = ROUNDUP(height, flocopt.sizey); const int bufsize = (bwidth / flocopt.sizex) * (bheight / flocopt.sizey); - dt_opencl_local_buffer_t slocopt - = (dt_opencl_local_buffer_t){ .xoffset = 0, .xfactor = 1, .yoffset = 0, .yfactor = 1, - .cellsize = sizeof(float), .overhead = 0, - .sizex = 1 << 16, .sizey = 1 }; + dt_opencl_local_buffer_t slocopt = (dt_opencl_local_buffer_t){.xoffset = 0, + .xfactor = 1, + .yoffset = 0, + .yfactor = 1, + .cellsize = sizeof(float), + .overhead = 0, + .sizex = 1 << 16, + .sizey = 1 }; - if(!dt_opencl_local_buffer_opt(devid, gd->kernel_pixelmax_second, &slocopt)) - goto error; + if(!dt_opencl_local_buffer_opt(devid, gd->kernel_pixelmax_second, &slocopt)) goto error; const int reducesize = MIN(REDUCESIZE, ROUNDUP(bufsize, slocopt.sizex) / slocopt.sizex); @@ -390,7 +395,8 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m dt_opencl_set_kernel_arg(devid, gd->kernel_pixelmax_first, 1, sizeof(int), &width); dt_opencl_set_kernel_arg(devid, gd->kernel_pixelmax_first, 2, sizeof(int), &height); dt_opencl_set_kernel_arg(devid, gd->kernel_pixelmax_first, 3, sizeof(cl_mem), &dev_m); - dt_opencl_set_kernel_arg(devid, gd->kernel_pixelmax_first, 4, flocopt.sizex * flocopt.sizey * sizeof(float), NULL); + dt_opencl_set_kernel_arg(devid, gd->kernel_pixelmax_first, 4, flocopt.sizex * flocopt.sizey * sizeof(float), + NULL); err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_pixelmax_first, sizes, local); if(err != CL_SUCCESS) goto error; @@ -408,8 +414,8 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m if(err != CL_SUCCESS) goto error; maximum = dt_alloc_align(16, reducesize * sizeof(float)); - err = dt_opencl_read_buffer_from_device(devid, (void *)maximum, dev_r, 0, - (size_t)reducesize * sizeof(float), CL_TRUE); + err = dt_opencl_read_buffer_from_device(devid, (void *)maximum, dev_r, 0, (size_t)reducesize * sizeof(float), + CL_TRUE); if(err != CL_SUCCESS) goto error; dt_opencl_release_mem_object(dev_r); @@ -496,8 +502,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling) + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling) { dt_iop_global_tonemap_data_t *d = (dt_iop_global_tonemap_data_t *)piece->data; @@ -514,9 +519,11 @@ void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t const size_t basebuffer = width * height * channels * sizeof(float); - tiling->factor = 2.0f + (detail ? (float)dt_bilateral_memory_use2(width, height, sigma_s, sigma_r) / basebuffer : 0.0f); + tiling->factor + = 2.0f + (detail ? (float)dt_bilateral_memory_use2(width, height, sigma_s, sigma_r) / basebuffer : 0.0f); tiling->maxbuf - = (detail ? MAX(1.0f, (float)dt_bilateral_singlebuffer_size2(width, height, sigma_s, sigma_r) / basebuffer) : 1.0f); + = (detail ? MAX(1.0f, (float)dt_bilateral_singlebuffer_size2(width, height, sigma_s, sigma_r) / basebuffer) + : 1.0f); tiling->overhead = 0; tiling->overlap = (detail ? ceilf(4 * sigma_s) : 0); tiling->xalign = 1; @@ -536,11 +543,10 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix d->detail = p->detail; // drago needs the maximum L-value of the whole image so it must not use tiling - if(d->operator == OPERATOR_DRAGO) piece->process_tiling_ready = 0; + if(d->operator== OPERATOR_DRAGO) piece->process_tiling_ready = 0; #ifdef HAVE_OPENCL - if(d->detail != 0.0f) - piece->process_cl_ready = (piece->process_cl_ready && !(darktable.opencl->avoid_atomics)); + if(d->detail != 0.0f) piece->process_cl_ready = (piece->process_cl_ready && !(darktable.opencl->avoid_atomics)); #endif } @@ -654,7 +660,6 @@ void gui_update(struct dt_iop_module_t *self) g->lwmax = NAN; g->hash = 0; dt_pthread_mutex_unlock(&g->lock); - } void init(dt_iop_module_t *module) @@ -662,11 +667,10 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_global_tonemap_params_t)); module->default_params = calloc(1, sizeof(dt_iop_global_tonemap_params_t)); module->default_enabled = 0; - module->priority = 544; // module order created by iop_dependencies.py, do not edit! + module->priority = 550; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_global_tonemap_params_t); module->gui_data = NULL; - dt_iop_global_tonemap_params_t tmp - = (dt_iop_global_tonemap_params_t){ OPERATOR_DRAGO, { 0.85f, 100.0f }, 0.0f }; + dt_iop_global_tonemap_params_t tmp = (dt_iop_global_tonemap_params_t){ OPERATOR_DRAGO, { 0.85f, 100.0f }, 0.0f }; memcpy(module->params, &tmp, sizeof(dt_iop_global_tonemap_params_t)); memcpy(module->default_params, &tmp, sizeof(dt_iop_global_tonemap_params_t)); } diff --git a/src/iop/graduatednd.c b/src/iop/graduatednd.c index 560e0b940391..a4a14ea2fda8 100644 --- a/src/iop/graduatednd.c +++ b/src/iop/graduatednd.c @@ -201,9 +201,8 @@ static int set_grad_from_points(struct dt_iop_module_t *self, float xa, float ya float *rotation, float *offset) { // we want absolute positions - float pts[4] - = { xa * self->dev->preview_pipe->backbuf_width, ya * self->dev->preview_pipe->backbuf_height, - xb * self->dev->preview_pipe->backbuf_width, yb * self->dev->preview_pipe->backbuf_height }; + float pts[4] = { xa * self->dev->preview_pipe->backbuf_width, ya * self->dev->preview_pipe->backbuf_height, + xb * self->dev->preview_pipe->backbuf_width, yb * self->dev->preview_pipe->backbuf_height }; dt_dev_distort_backtransform_plus(self->dev, self->dev->preview_pipe, self->priority + 1, 9999999, pts, 2); dt_dev_pixelpipe_iop_t *piece = dt_dev_distort_get_iop_pipe(self->dev, self->dev->preview_pipe, self); pts[0] /= (float)piece->buf_out.width; @@ -389,8 +388,8 @@ static int set_points_from_grad(struct dt_iop_module_t *self, float *xa, float * return 1; } -void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, int32_t height, - int32_t pointerx, int32_t pointery) +void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, + int32_t pointery) { dt_develop_t *dev = self->dev; dt_iop_graduatednd_gui_data_t *g = (dt_iop_graduatednd_gui_data_t *)self->gui_data; @@ -672,8 +671,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const const float offset = data->offset / 100.0 * 2; #if 1 - const float filter_compression - = 1.0 / filter_radie / (1.0 - (0.5 + (data->compression / 100.0) * 0.9 / 2.0)) * 0.5; + const float filter_compression = 1.0 / filter_radie / (1.0 - (0.5 + (data->compression / 100.0) * 0.9 / 2.0)) + * 0.5; #else const float compression = data->compression / 100.0f; const float t = 1.0f - .8f / (.8f + compression); @@ -772,7 +771,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const } } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #if defined(__SSE__) @@ -797,8 +797,8 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c const float offset = data->offset / 100.0 * 2; #if 1 - const float filter_compression = 1.0 / filter_radie - / (1.0 - (0.5 + (data->compression / 100.0) * 0.9 / 2.0)) * 0.5; + const float filter_compression = 1.0 / filter_radie / (1.0 - (0.5 + (data->compression / 100.0) * 0.9 / 2.0)) + * 0.5; #else const float compression = data->compression / 100.0f; const float t = 1.0f - .8f / (.8f + compression); @@ -902,7 +902,8 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c } _mm_sfence(); - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #endif @@ -935,8 +936,8 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m const float density = data->density; #if 1 - const float filter_compression = 1.0 / filter_radie - / (1.0 - (0.5 + (data->compression / 100.0) * 0.9 / 2.0)) * 0.5; + const float filter_compression = 1.0 / filter_radie / (1.0 - (0.5 + (data->compression / 100.0) * 0.9 / 2.0)) + * 0.5; #else const float compression = data->compression / 100.0f; const float t = 1.0f - .8f / (.8f + compression); @@ -1084,7 +1085,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_graduatednd_params_t)); module->default_params = calloc(1, sizeof(dt_iop_graduatednd_params_t)); module->default_enabled = 0; - module->priority = 279; // module order created by iop_dependencies.py, do not edit! + module->priority = 289; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_graduatednd_params_t); module->gui_data = NULL; dt_iop_graduatednd_params_t tmp = (dt_iop_graduatednd_params_t){ 1.0, 0, 0, 50, 0, 0 }; diff --git a/src/iop/grain.c b/src/iop/grain.c index ced320a0b26e..4053c2271d9d 100644 --- a/src/iop/grain.c +++ b/src/iop/grain.c @@ -353,8 +353,8 @@ static double _simplex_2d_noise(double x, double y, uint32_t octaves, double per double total = 0; // parametrization of octaves to match power spectrum of real grain scans - static double f[] = {0.4910, 0.9441, 1.7280}; - static double a[] = {0.2340, 0.7850, 1.2150}; + static double f[] = { 0.4910, 0.9441, 1.7280 }; + static double a[] = { 0.2340, 0.7850, 1.2150 }; for(uint32_t o = 0; o < octaves; o++) { @@ -367,7 +367,7 @@ static float paper_resp(float exposure, float mb, float gp) { float density; float delta = GRAIN_LUT_DELTA_MAX * expf((mb / 100.0f) * logf(GRAIN_LUT_DELTA_MIN)); - density = (1.0f + 2.0f * delta) / (1.0f + expf( (4.0f * gp * (0.5f - exposure)) / (1.0f + 2.0f * delta) )) - delta; + density = (1.0f + 2.0f * delta) / (1.0f + expf((4.0f * gp * (0.5f - exposure)) / (1.0f + 2.0f * delta))) - delta; return density; } @@ -387,7 +387,9 @@ static void evaluate_grain_lut(float *grain_lut, const float mb) { float gu = (float)i / (GRAIN_LUT_SIZE - 1) - 0.5; float l = (float)j / (GRAIN_LUT_SIZE - 1); - grain_lut[j * GRAIN_LUT_SIZE + i] = 100.0f * (paper_resp(gu + paper_resp_inverse(l, mb, GRAIN_LUT_PAPER_GAMMA), mb, GRAIN_LUT_PAPER_GAMMA) - l); + grain_lut[j * GRAIN_LUT_SIZE + i] + = 100.0f + * (paper_resp(gu + paper_resp_inverse(l, mb, GRAIN_LUT_PAPER_GAMMA), mb, GRAIN_LUT_PAPER_GAMMA) - l); } } } @@ -511,7 +513,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const noise = _simplex_2d_noise(x + hash, y, octaves, 1.0, zoom); } - out[0] = in[0] + dt_lut_lookup_2d_1c(data->grain_lut, (noise * strength) * GRAIN_LIGHTNESS_STRENGTH_SCALE, in[0] / 100.0f); + out[0] = in[0] + dt_lut_lookup_2d_1c(data->grain_lut, (noise * strength) * GRAIN_LIGHTNESS_STRENGTH_SCALE, + in[0] / 100.0f); out[1] = in[1]; out[2] = in[2]; out[3] = in[3]; @@ -559,7 +562,7 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix d->scale = p->scale; d->strength = p->strength; d->midtones_bias = p->midtones_bias; - + evaluate_grain_lut(d->grain_lut, d->midtones_bias); } @@ -592,7 +595,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_grain_params_t)); module->default_params = calloc(1, sizeof(dt_iop_grain_params_t)); module->default_enabled = 0; - module->priority = 779; // module order created by iop_dependencies.py, do not edit! + module->priority = 782; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_grain_params_t); module->gui_data = NULL; dt_iop_grain_params_t tmp @@ -636,7 +639,9 @@ void gui_init(struct dt_iop_module_t *self) dt_bauhaus_widget_set_label(g->scale3, NULL, _("midtones bias")); dt_bauhaus_slider_set_format(g->scale3, "%.0f%%"); gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(g->scale3), TRUE, TRUE, 0); - gtk_widget_set_tooltip_text(g->scale3, _("amount of midtones bias from the photographic paper response modeling. the greater the bias, the more pronounced the fall off of the grain in shadows and highlights")); + gtk_widget_set_tooltip_text( + g->scale3, _("amount of midtones bias from the photographic paper response modeling. the greater the bias, " + "the more pronounced the fall off of the grain in shadows and highlights")); g_signal_connect(G_OBJECT(g->scale3), "value-changed", G_CALLBACK(midtones_bias_callback), self); } diff --git a/src/iop/hazeremoval.c b/src/iop/hazeremoval.c index c4b986bdc87f..f92c04a1c1b9 100644 --- a/src/iop/hazeremoval.c +++ b/src/iop/hazeremoval.c @@ -120,7 +120,7 @@ void init(dt_iop_module_t *self) self->params = calloc(1, sizeof(dt_iop_hazeremoval_params_t)); self->default_params = calloc(1, sizeof(dt_iop_hazeremoval_params_t)); self->default_enabled = 0; - self->priority = 338; // module order created by iop_dependencies.py, do not edit! + self->priority = 347; // module order created by iop_dependencies.py, do not edit! self->params_size = sizeof(dt_iop_hazeremoval_params_t); self->gui_data = NULL; dt_iop_hazeremoval_params_t tmp = (dt_iop_hazeremoval_params_t){ 0.5f, 0.25f }; diff --git a/src/iop/highlights.c b/src/iop/highlights.c index 33af22040840..818c59891bf7 100644 --- a/src/iop/highlights.c +++ b/src/iop/highlights.c @@ -87,8 +87,8 @@ int flags() return IOP_FLAGS_SUPPORTS_BLENDING | IOP_FLAGS_ALLOW_TILING | IOP_FLAGS_ONE_INSTANCE; } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 1 && new_version == 2) { @@ -168,10 +168,14 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m // xtrans sensor raws with LCH mode int blocksizex, blocksizey; - dt_opencl_local_buffer_t locopt - = (dt_opencl_local_buffer_t){ .xoffset = 2 * 2, .xfactor = 1, .yoffset = 2 * 2, .yfactor = 1, - .cellsize = sizeof(float), .overhead = 0, - .sizex = 1 << 8, .sizey = 1 << 8 }; + dt_opencl_local_buffer_t locopt = (dt_opencl_local_buffer_t){.xoffset = 2 * 2, + .xfactor = 1, + .yoffset = 2 * 2, + .yfactor = 1, + .cellsize = sizeof(float), + .overhead = 0, + .sizex = 1 << 8, + .sizey = 1 << 8 }; if(dt_opencl_local_buffer_opt(devid, gd->kernel_highlights_1f_lch_xtrans, &locopt)) { @@ -196,7 +200,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m dt_opencl_set_kernel_arg(devid, gd->kernel_highlights_1f_lch_xtrans, 6, sizeof(int), (void *)&roi_out->y); dt_opencl_set_kernel_arg(devid, gd->kernel_highlights_1f_lch_xtrans, 7, sizeof(cl_mem), (void *)&dev_xtrans); dt_opencl_set_kernel_arg(devid, gd->kernel_highlights_1f_lch_xtrans, 8, - (blocksizex + 4) * (blocksizey + 4) * sizeof(float), NULL); + (blocksizex + 4) * (blocksizey + 4) * sizeof(float), NULL); err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_highlights_1f_lch_xtrans, sizes, local); if(err != CL_SUCCESS) goto error; @@ -218,13 +222,12 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m #endif void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling) + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling) { dt_iop_highlights_data_t *d = (dt_iop_highlights_data_t *)piece->data; const uint32_t filters = piece->pipe->dsc.filters; - tiling->factor = 2.0f; // in + out + tiling->factor = 2.0f; // in + out tiling->maxbuf = 1.0f; tiling->overhead = 0; @@ -252,11 +255,8 @@ void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t } /* interpolate value for a pixel, ideal via ratio to nearby pixel */ -static inline float interp_pix_xtrans(const int ratio_next, - const ssize_t offset_next, - const float clip0, const float clip_next, - const float *const in, - const float *const ratios) +static inline float interp_pix_xtrans(const int ratio_next, const ssize_t offset_next, const float clip0, + const float clip_next, const float *const in, const float *const ratios) { assert(ratio_next != 0); // it's OK to exceed clipping of current pixel's color based on a @@ -272,7 +272,7 @@ static inline float interp_pix_xtrans(const int ratio_next, { // set this pixel in ratio to the next assert(ratio_next != 0); - if (ratio_next > 0) + if(ratio_next > 0) return fminf(in[offset_next] / ratios[ratio_next], clip_val); else return fminf(in[offset_next] * ratios[-ratio_next], clip_val); @@ -280,12 +280,9 @@ static inline float interp_pix_xtrans(const int ratio_next, } static inline void interpolate_color_xtrans(const void *const ivoid, void *const ovoid, - const dt_iop_roi_t *const roi_in, - const dt_iop_roi_t *const roi_out, - int dim, int dir, int other, - const float *const clip, - const uint8_t (*const xtrans)[6], - const int pass) + const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, + int dim, int dir, int other, const float *const clip, + const uint8_t (*const xtrans)[6], const int pass) { // In Bayer each row/col has only green/red or green/blue // transitions, hence can reconstruct color by single ratio per @@ -298,11 +295,9 @@ static inline void interpolate_color_xtrans(const void *const ivoid, void *const // -> red is roff[2][0]. Returned value is an index into ratios. If // negative, then need to invert the ratio. Identity color // transitions aren't used. - const int roff[3][3] = {{ 0, -1, -2}, - { 1, 0, -3}, - { 2, 3, 0}}; + const int roff[3][3] = { { 0, -1, -2 }, { 1, 0, -3 }, { 2, 3, 0 } }; // record ratios of color transitions 0:unused, 1:RG, 2:RB, and 3:GB - float ratios[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + float ratios[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; // passes are 0:+x, 1:-x, 2:+y, 3:-y // dims are 0:traverse a row, 1:traverse a column @@ -361,13 +356,11 @@ static inline void interpolate_color_xtrans(const void *const ivoid, void *const { // ratio to next pixel if this & next are unclamped and not in // 2x2 green block - if ((f0 != f1) && - (in[0] < clip0 && in[0] > 1e-5f) && - (in[offs] < clip1 && in[offs] > 1e-5f)) + if((f0 != f1) && (in[0] < clip0 && in[0] > 1e-5f) && (in[offs] < clip1 && in[offs] > 1e-5f)) { const int r = roff[f0][f1]; assert(r != 0); - if (r > 0) + if(r > 0) ratios[r] = (3.f * ratios[r] + (in[offs] / in[0])) / 4.f; else ratios[-r] = (3.f * ratios[-r] + (in[0] / in[offs])) / 4.f; @@ -379,13 +372,11 @@ static inline void interpolate_color_xtrans(const void *const ivoid, void *const float add; if(f0 != f1) // next pixel is different color - add = - interp_pix_xtrans(roff[f0][f1], offs, clip0, clip1, in, ratios); + add = interp_pix_xtrans(roff[f0][f1], offs, clip0, clip1, in, ratios); else // at start of 2x2 green block, look diagonally - add = (fl != f0) ? - interp_pix_xtrans(roff[f0][fl], offl, clip0, clipl, in, ratios) : - interp_pix_xtrans(roff[f0][fr], offr, clip0, clipr, in, ratios); + add = (fl != f0) ? interp_pix_xtrans(roff[f0][fl], offl, clip0, clipl, in, ratios) + : interp_pix_xtrans(roff[f0][fr], offr, clip0, clipr, in, ratios); if(pass == 0) out[0] = add; @@ -405,9 +396,9 @@ static inline void interpolate_color_xtrans(const void *const ivoid, void *const } } -static inline void interpolate_color(const void *const ivoid, void *const ovoid, - const dt_iop_roi_t *const roi_out, int dim, int dir, int other, - const float *clip, const uint32_t filters, const int pass) +static inline void interpolate_color(const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_out, + int dim, int dir, int other, const float *clip, const uint32_t filters, + const int pass) { float ratio = 1.0f; float *in, *out; @@ -620,7 +611,7 @@ static void process_lch_xtrans(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pi void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, const float clip) { - const uint8_t(*const xtrans)[6] = (const uint8_t(*const)[6])piece->pipe->dsc.xtrans; + const uint8_t (*const xtrans)[6] = (const uint8_t (*const)[6])piece->pipe->dsc.xtrans; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) default(none) @@ -698,16 +689,16 @@ static void process_lch_xtrans(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pi for(int ii = -1; ii <= 1; ii++) { const float val = in[(ssize_t)jj * roi_in->width + ii]; - const int c = FCxtrans(j+jj, i+ii, roi_in, xtrans); + const int c = FCxtrans(j + jj, i + ii, roi_in, xtrans); mean[c] += val; cnt[c]++; RGBmax[c] = MAX(RGBmax[c], val); } } - const float Ro = MIN(mean[0]/cnt[0], clip); - const float Go = MIN(mean[1]/cnt[1], clip); - const float Bo = MIN(mean[2]/cnt[2], clip); + const float Ro = MIN(mean[0] / cnt[0], clip); + const float Go = MIN(mean[1] / cnt[1], clip); + const float Bo = MIN(mean[2] / cnt[2], clip); const float R = RGBmax[0]; const float G = RGBmax[1]; @@ -822,8 +813,7 @@ static void process_clip_sse2(dt_dev_pixelpipe_iop_t *piece, const void *const i #endif static void process_clip(dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid, - const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, - const float clip) + const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, const float clip) { if(darktable.codepath.OPENMP_SIMD) process_clip_plain(piece, ivoid, ovoid, roi_in, roi_out, clip); #if defined(__SSE__) @@ -840,14 +830,14 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const const uint32_t filters = piece->pipe->dsc.filters; dt_iop_highlights_data_t *data = (dt_iop_highlights_data_t *)piece->data; - const float clip - = data->clip * fminf(piece->pipe->dsc.processed_maximum[0], - fminf(piece->pipe->dsc.processed_maximum[1], piece->pipe->dsc.processed_maximum[2])); + const float clip = data->clip + * fminf(piece->pipe->dsc.processed_maximum[0], + fminf(piece->pipe->dsc.processed_maximum[1], piece->pipe->dsc.processed_maximum[2])); // const int ch = piece->colors; if(!filters) { process_clip(piece, ivoid, ovoid, roi_in, roi_out, clip); - for(int k=0;k<3;k++) + for(int k = 0; k < 3; k++) piece->pipe->dsc.processed_maximum[k] = fminf(piece->pipe->dsc.processed_maximum[0], fminf(piece->pipe->dsc.processed_maximum[1], piece->pipe->dsc.processed_maximum[2])); @@ -864,7 +854,7 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const if(filters == 9u) { - const uint8_t(*const xtrans)[6] = (const uint8_t(*const)[6])piece->pipe->dsc.xtrans; + const uint8_t (*const xtrans)[6] = (const uint8_t (*const)[6])piece->pipe->dsc.xtrans; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) default(none) #endif @@ -922,7 +912,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const piece->pipe->dsc.processed_maximum[2]); for(int k = 0; k < 3; k++) piece->pipe->dsc.processed_maximum[k] = m; - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } static void clip_callback(GtkWidget *slider, dt_iop_module_t *self) @@ -1023,7 +1014,7 @@ void init(dt_iop_module_t *module) // module->data = malloc(sizeof(dt_iop_highlights_data_t)); module->params = calloc(1, sizeof(dt_iop_highlights_params_t)); module->default_params = calloc(1, sizeof(dt_iop_highlights_params_t)); - module->priority = 58; // module order created by iop_dependencies.py, do not edit! + module->priority = 57; // module order created by iop_dependencies.py, do not edit! module->default_enabled = 1; module->params_size = sizeof(dt_iop_highlights_params_t); module->gui_data = NULL; diff --git a/src/iop/highpass.c b/src/iop/highpass.c index 9f2d43a1b637..af7ea0e001f1 100644 --- a/src/iop/highpass.c +++ b/src/iop/highpass.c @@ -104,8 +104,7 @@ void connect_key_accels(dt_iop_module_t *self) #endif void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling) + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling) { dt_iop_highpass_data_t *d = (dt_iop_highpass_data_t *)piece->data; @@ -164,10 +163,14 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m float contrast_scale = ((d->contrast / 100.0f) * 7.5f); int hblocksize; - dt_opencl_local_buffer_t hlocopt - = (dt_opencl_local_buffer_t){ .xoffset = 2 * wdh, .xfactor = 1, .yoffset = 0, .yfactor = 1, - .cellsize = sizeof(float), .overhead = 0, - .sizex = 1 << 16, .sizey = 1 }; + dt_opencl_local_buffer_t hlocopt = (dt_opencl_local_buffer_t){.xoffset = 2 * wdh, + .xfactor = 1, + .yoffset = 0, + .yfactor = 1, + .cellsize = sizeof(float), + .overhead = 0, + .sizex = 1 << 16, + .sizey = 1 }; if(dt_opencl_local_buffer_opt(devid, gd->kernel_highpass_hblur, &hlocopt)) hblocksize = hlocopt.sizex; @@ -175,10 +178,14 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m hblocksize = 1; int vblocksize; - dt_opencl_local_buffer_t vlocopt - = (dt_opencl_local_buffer_t){ .xoffset = 1, .xfactor = 1, .yoffset = 2 * wdh, .yfactor = 1, - .cellsize = sizeof(float), .overhead = 0, - .sizex = 1, .sizey = 1 << 16 }; + dt_opencl_local_buffer_t vlocopt = (dt_opencl_local_buffer_t){.xoffset = 1, + .xfactor = 1, + .yoffset = 2 * wdh, + .yfactor = 1, + .cellsize = sizeof(float), + .overhead = 0, + .sizex = 1, + .sizey = 1 << 16 }; if(dt_opencl_local_buffer_opt(devid, gd->kernel_highpass_vblur, &vlocopt)) vblocksize = vlocopt.sizey; @@ -432,7 +439,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_highpass_params_t)); module->default_params = calloc(1, sizeof(dt_iop_highpass_params_t)); module->default_enabled = 0; - module->priority = 764; // module order created by iop_dependencies.py, do not edit! + module->priority = 768; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_highpass_params_t); module->gui_data = NULL; dt_iop_highpass_params_t tmp = (dt_iop_highpass_params_t){ 50, 50 }; diff --git a/src/iop/hotpixels.c b/src/iop/hotpixels.c index ee184a99ec94..d9a63b022eb9 100644 --- a/src/iop/hotpixels.c +++ b/src/iop/hotpixels.c @@ -102,8 +102,7 @@ void connect_key_accels(dt_iop_module_t *self) * the maximum produces fewer artifacts when inadvertently replacing * non-hot pixels. * This is the Bayer sensor variant. */ -static int process_bayer(const dt_iop_hotpixels_data_t *data, - const void *const ivoid, void *const ovoid, +static int process_bayer(const dt_iop_hotpixels_data_t *data, const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_out) { const float threshold = data->threshold; @@ -129,12 +128,12 @@ static int process_bayer(const dt_iop_hotpixels_data_t *data, int count = 0; float maxin = 0.0; float other; -#define TESTONE(OFFSET) \ - other = in[OFFSET]; \ - if(mid > other) \ - { \ - count++; \ - if(other > maxin) maxin = other; \ +#define TESTONE(OFFSET) \ + other = in[OFFSET]; \ + if(mid > other) \ + { \ + count++; \ + if(other > maxin) maxin = other; \ } TESTONE(-2); TESTONE(-widthx2); @@ -159,8 +158,7 @@ static int process_bayer(const dt_iop_hotpixels_data_t *data, } /* X-Trans sensor equivalent of process_bayer(). */ -static int process_xtrans(const dt_iop_hotpixels_data_t *data, - const void *const ivoid, void *const ovoid, +static int process_xtrans(const dt_iop_hotpixels_data_t *data, const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_out, const uint8_t (*const xtrans)[6]) { // for each cell of sensor array, pre-calculate, a list of the x/y @@ -246,14 +244,14 @@ static int process_xtrans(const dt_iop_hotpixels_data_t *data, const uint8_t c = FCxtrans(row, col, roi_out, xtrans); for(int i = -2; i >= -10 && i >= -col; --i) { - if(c == FCxtrans(row, col+i, roi_out, xtrans)) + if(c == FCxtrans(row, col + i, roi_out, xtrans)) { out[i] = *in; } } for(int i = 2; i <= 10 && i < width - col; ++i) { - if(c == FCxtrans(row, col+i, roi_out, xtrans)) + if(c == FCxtrans(row, col + i, roi_out, xtrans)) { out[i] = *in; } @@ -279,7 +277,7 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const int fixed; if(piece->pipe->dsc.filters == 9u) { - fixed = process_xtrans(data, ivoid, ovoid, roi_out, (const uint8_t(*const)[6])piece->pipe->dsc.xtrans); + fixed = process_xtrans(data, ivoid, ovoid, roi_out, (const uint8_t (*const)[6])piece->pipe->dsc.xtrans); } else { @@ -317,7 +315,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_hotpixels_params_t)); module->default_params = calloc(1, sizeof(dt_iop_hotpixels_params_t)); module->default_enabled = 0; - module->priority = 88; // module order created by iop_dependencies.py, do not edit! + module->priority = 86; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_hotpixels_params_t); module->gui_data = NULL; } diff --git a/src/iop/invert.c b/src/iop/invert.c index 73c3e3b89c66..1934cd60cdf0 100644 --- a/src/iop/invert.c +++ b/src/iop/invert.c @@ -231,8 +231,7 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const const float *const m = piece->pipe->dsc.processed_maximum; - const float film_rgb_f[4] - = { d->color[0] * m[0], d->color[1] * m[1], d->color[2] * m[2], d->color[3] * m[3] }; + const float film_rgb_f[4] = { d->color[0] * m[0], d->color[1] * m[1], d->color[2] * m[2], d->color[3] * m[3] }; // FIXME: it could be wise to make this a NOP when picking colors. not sure about that though. // if(self->request_color_pick){ @@ -240,7 +239,7 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const // } const uint32_t filters = piece->pipe->dsc.filters; - const uint8_t(*const xtrans)[6] = (const uint8_t(*const)[6])piece->pipe->dsc.xtrans; + const uint8_t (*const xtrans)[6] = (const uint8_t (*const)[6])piece->pipe->dsc.xtrans; const float *const in = (const float *const)ivoid; float *const out = (float *const)ovoid; @@ -294,7 +293,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const } } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } } @@ -306,8 +306,7 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c const float *const m = piece->pipe->dsc.processed_maximum; - const float film_rgb_f[4] - = { d->color[0] * m[0], d->color[1] * m[1], d->color[2] * m[2], d->color[3] * m[3] }; + const float film_rgb_f[4] = { d->color[0] * m[0], d->color[1] * m[1], d->color[2] * m[2], d->color[3] * m[3] }; // FIXME: it could be wise to make this a NOP when picking colors. not sure about that though. // if(self->request_color_pick){ @@ -315,7 +314,7 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c // } const uint32_t filters = piece->pipe->dsc.filters; - const uint8_t(*const xtrans)[6] = (const uint8_t(*const)[6])piece->pipe->dsc.xtrans; + const uint8_t (*const xtrans)[6] = (const uint8_t (*const)[6])piece->pipe->dsc.xtrans; if(filters == 9u) { // xtrans float mosaiced @@ -436,7 +435,8 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c } _mm_sfence(); - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } } #endif @@ -537,7 +537,7 @@ void init(dt_iop_module_t *module) module->default_enabled = 0; module->params_size = sizeof(dt_iop_invert_params_t); module->gui_data = NULL; - module->priority = 29; // module order created by iop_dependencies.py, do not edit! + module->priority = 28; // module order created by iop_dependencies.py, do not edit! } void cleanup(dt_iop_module_t *module) diff --git a/src/iop/iop_api.h b/src/iop/iop_api.h index bb5fd736a0ab..20dad44fe637 100644 --- a/src/iop/iop_api.h +++ b/src/iop/iop_api.h @@ -98,8 +98,8 @@ void gui_init(struct dt_iop_module_t *self); /** destroy widget. */ void gui_cleanup(struct dt_iop_module_t *self); /** optional method called after darkroom expose. */ -void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, int32_t height, - int32_t pointerx, int32_t pointery); +void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, + int32_t pointery); /** optional callback to be notified if the module acquires gui focus/loses it. */ void gui_focus(struct dt_iop_module_t *self, gboolean in); @@ -127,8 +127,7 @@ void original_init(struct dt_iop_module_t *self); void cleanup(struct dt_iop_module_t *self); /** this inits the piece of the pipe, allocing piece->data as necessary. */ -void init_pipe(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_t *pipe, - struct dt_dev_pixelpipe_iop_t *piece); +void init_pipe(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_t *pipe, struct dt_dev_pixelpipe_iop_t *piece); /** this resets the params to factory defaults. used at the beginning of each history synch. */ /** this commits (a mutex will be locked to synch pipe/gui) the given history params to the pixelpipe piece. */ @@ -154,8 +153,7 @@ int legacy_params(struct dt_iop_module_t *self, const void *const old_params, co /** the simplest variant of process(). you can only use OpenMP SIMD here, no intrinsics */ /** must be provided by each IOP. */ void process(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const i, - void *const o, const struct dt_iop_roi_t *const roi_in, - const struct dt_iop_roi_t *const roi_out); + void *const o, const struct dt_iop_roi_t *const roi_in, const struct dt_iop_roi_t *const roi_out); /** a tiling variant of process(). */ void process_tiling(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const i, void *const o, const struct dt_iop_roi_t *const roi_in, @@ -171,9 +169,8 @@ void process_sse2(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *p #ifdef HAVE_OPENCL /** the opencl equivalent of process(). */ -int process_cl(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, - cl_mem dev_out, const struct dt_iop_roi_t *const roi_in, - const struct dt_iop_roi_t *const roi_out); +int process_cl(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, cl_mem dev_out, + const struct dt_iop_roi_t *const roi_in, const struct dt_iop_roi_t *const roi_out); /** a tiling variant of process_cl(). */ int process_tiling_cl(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const void *const i, void *const o, const struct dt_iop_roi_t *const roi_in, diff --git a/src/iop/lens.c b/src/iop/lens.c index e724cd3b51f1..b105eb7630ce 100644 --- a/src/iop/lens.c +++ b/src/iop/lens.c @@ -176,8 +176,8 @@ void connect_key_accels(dt_iop_module_t *self) dt_accel_connect_slider_iop(self, "tca B", GTK_WIDGET(g->tca_b)); } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 2 && new_version == 5) { @@ -351,9 +351,8 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c dt_pthread_mutex_lock(&darktable.plugin_threadsafe); lfModifier *modifier = lf_modifier_new(d->lens, d->crop, orig_w, orig_h); - const int modflags - = lf_modifier_initialize(modifier, d->lens, LF_PF_F32, d->focal, d->aperture, d->distance, d->scale, - d->target_geom, d->modify_flags, d->inverse); + const int modflags = lf_modifier_initialize(modifier, d->lens, LF_PF_F32, d->focal, d->aperture, d->distance, + d->scale, d->target_geom, d->modify_flags, d->inverse); dt_pthread_mutex_unlock(&darktable.plugin_threadsafe); const struct dt_interpolation *const interpolation = dt_interpolation_new(DT_INTERPOLATION_USERPREF); @@ -373,8 +372,8 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c for(int y = 0; y < roi_out->height; y++) { float *bufptr = ((float *)buf) + (size_t)bufsize * dt_get_thread_num(); - lf_modifier_apply_subpixel_geometry_distortion(modifier, roi_out->x, roi_out->y + y, roi_out->width, - 1, bufptr); + lf_modifier_apply_subpixel_geometry_distortion(modifier, roi_out->x, roi_out->y + y, roi_out->width, 1, + bufptr); // reverse transform the global coords from lf to our buffer float *out = ((float *)ovoid) + (size_t)y * roi_out->width * ch; @@ -391,8 +390,8 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c const float *const inptr = (const float *const)ivoid + (size_t)c; const float pi0 = bufptr[c * 2] - roi_in->x; const float pi1 = bufptr[c * 2 + 1] - roi_in->y; - out[c] = dt_interpolation_compute_sample(interpolation, inptr, pi0, pi1, roi_in->width, - roi_in->height, ch, ch_width); + out[c] = dt_interpolation_compute_sample(interpolation, inptr, pi0, pi1, roi_in->width, roi_in->height, + ch, ch_width); } if(mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) @@ -407,8 +406,8 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c const float *const inptr = (const float *const)ivoid + (size_t)3; const float pi0 = bufptr[2] - roi_in->x; const float pi1 = bufptr[3] - roi_in->y; - out[3] = dt_interpolation_compute_sample(interpolation, inptr, pi0, pi1, roi_in->width, - roi_in->height, ch, ch_width); + out[3] = dt_interpolation_compute_sample(interpolation, inptr, pi0, pi1, roi_in->width, roi_in->height, + ch, ch_width); } } } @@ -468,8 +467,8 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c for(int y = 0; y < roi_out->height; y++) { float *buf2ptr = ((float *)buf2) + (size_t)buf2size * dt_get_thread_num(); - lf_modifier_apply_subpixel_geometry_distortion(modifier, roi_out->x, roi_out->y + y, roi_out->width, - 1, buf2ptr); + lf_modifier_apply_subpixel_geometry_distortion(modifier, roi_out->x, roi_out->y + y, roi_out->width, 1, + buf2ptr); // reverse transform the global coords from lf to our buffer float *out = ((float *)ovoid) + (size_t)y * roi_out->width * ch; for(int x = 0; x < roi_out->width; x++, buf2ptr += 6, out += ch) @@ -552,7 +551,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m const int tmpbufwidth = owidth * 2 * 3; const size_t tmpbuflen = d->inverse ? (size_t)oheight * owidth * 2 * 3 * sizeof(float) : MAX((size_t)oheight * owidth * 2 * 3, (size_t)iheight * iwidth * ch) - * sizeof(float); + * sizeof(float); const unsigned int pixelformat = ch == 3 ? LF_CR_3(RED, GREEN, BLUE) : LF_CR_4(RED, GREEN, BLUE, UNKNOWN); const float orig_w = roi_in->scale * piece->buf_in.width, orig_h = roi_in->scale * piece->buf_in.height; @@ -604,8 +603,8 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m dt_pthread_mutex_lock(&darktable.plugin_threadsafe); modifier = lf_modifier_new(d->lens, d->crop, orig_w, orig_h); - int modflags = lf_modifier_initialize(modifier, d->lens, LF_PF_F32, d->focal, d->aperture, d->distance, - d->scale, d->target_geom, d->modify_flags, d->inverse); + int modflags = lf_modifier_initialize(modifier, d->lens, LF_PF_F32, d->focal, d->aperture, d->distance, d->scale, + d->target_geom, d->modify_flags, d->inverse); dt_pthread_mutex_unlock(&darktable.plugin_threadsafe); if(d->inverse) @@ -619,8 +618,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m for(int y = 0; y < roi_out->height; y++) { float *pi = tmpbuf + (size_t)y * tmpbufwidth; - lf_modifier_apply_subpixel_geometry_distortion(modifier, roi_out->x, roi_out->y + y, roi_out->width, - 1, pi); + lf_modifier_apply_subpixel_geometry_distortion(modifier, roi_out->x, roi_out->y + y, roi_out->width, 1, pi); } /* _blocking_ memory transfer: host tmpbuf buffer -> opencl dev_tmpbuf */ @@ -663,9 +661,8 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m } /* _blocking_ memory transfer: host tmpbuf buffer -> opencl dev_tmpbuf */ - err = dt_opencl_write_buffer_to_device(devid, tmpbuf, dev_tmpbuf, 0, - (size_t)ch * roi_out->width * roi_out->height * sizeof(float), - CL_TRUE); + err = dt_opencl_write_buffer_to_device( + devid, tmpbuf, dev_tmpbuf, 0, (size_t)ch * roi_out->width * roi_out->height * sizeof(float), CL_TRUE); if(err != CL_SUCCESS) goto error; dt_opencl_set_kernel_arg(devid, gd->kernel_lens_vignette, 0, sizeof(cl_mem), (void *)&dev_tmp); @@ -702,8 +699,8 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m } /* _blocking_ memory transfer: host tmpbuf buffer -> opencl dev_tmpbuf */ - err = dt_opencl_write_buffer_to_device( - devid, tmpbuf, dev_tmpbuf, 0, (size_t)ch * roi_in->width * roi_in->height * sizeof(float), CL_TRUE); + err = dt_opencl_write_buffer_to_device(devid, tmpbuf, dev_tmpbuf, 0, + (size_t)ch * roi_in->width * roi_in->height * sizeof(float), CL_TRUE); if(err != CL_SUCCESS) goto error; dt_opencl_set_kernel_arg(devid, gd->kernel_lens_vignette, 0, sizeof(cl_mem), (void *)&dev_in); @@ -728,8 +725,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m for(int y = 0; y < roi_out->height; y++) { float *pi = tmpbuf + (size_t)y * tmpbufwidth; - lf_modifier_apply_subpixel_geometry_distortion(modifier, roi_out->x, roi_out->y + y, roi_out->width, - 1, pi); + lf_modifier_apply_subpixel_geometry_distortion(modifier, roi_out->x, roi_out->y + y, roi_out->width, 1, pi); } /* _blocking_ memory transfer: host tmpbuf buffer -> opencl dev_tmpbuf */ @@ -781,8 +777,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m #endif void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling) + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling) { tiling->factor = 4.5f; // in + out + tmp + tmpbuf tiling->maxbuf = 1.5f; @@ -802,8 +797,8 @@ int distort_transform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, floa const float orig_w = piece->buf_in.width, orig_h = piece->buf_in.height; lfModifier *modifier = lf_modifier_new(d->lens, d->crop, orig_w, orig_h); - int modflags = lf_modifier_initialize(modifier, d->lens, LF_PF_F32, d->focal, d->aperture, d->distance, - d->scale, d->target_geom, d->modify_flags, !d->inverse); + int modflags = lf_modifier_initialize(modifier, d->lens, LF_PF_F32, d->focal, d->aperture, d->distance, d->scale, + d->target_geom, d->modify_flags, !d->inverse); float *buf = malloc(2 * 3 * sizeof(float)); for(size_t i = 0; i < points_count * 2; i += 2) @@ -820,8 +815,7 @@ int distort_transform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, floa return 1; } -int distort_backtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, float *points, - size_t points_count) +int distort_backtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, float *points, size_t points_count) { dt_iop_lensfun_data_t *d = (dt_iop_lensfun_data_t *)piece->data; if(!d->lens || !d->lens->Maker || d->crop <= 0.0f) return 0; @@ -829,8 +823,8 @@ int distort_backtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const float orig_w = piece->buf_in.width, orig_h = piece->buf_in.height; lfModifier *modifier = lf_modifier_new(d->lens, d->crop, orig_w, orig_h); - int modflags = lf_modifier_initialize(modifier, d->lens, LF_PF_F32, d->focal, d->aperture, d->distance, - d->scale, d->target_geom, d->modify_flags, d->inverse); + int modflags = lf_modifier_initialize(modifier, d->lens, LF_PF_F32, d->focal, d->aperture, d->distance, d->scale, + d->target_geom, d->modify_flags, d->inverse); float *buf = malloc(2 * 3 * sizeof(float)); for(size_t i = 0; i < points_count * 2; i += 2) @@ -866,8 +860,8 @@ void modify_roi_in(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t * lfModifier *modifier = lf_modifier_new(d->lens, d->crop, orig_w, orig_h); - int modflags = lf_modifier_initialize(modifier, d->lens, LF_PF_F32, d->focal, d->aperture, d->distance, - d->scale, d->target_geom, d->modify_flags, d->inverse); + int modflags = lf_modifier_initialize(modifier, d->lens, LF_PF_F32, d->focal, d->aperture, d->distance, d->scale, + d->target_geom, d->modify_flags, d->inverse); if(modflags & (LF_MODIFY_TCA | LF_MODIFY_DISTORTION | LF_MODIFY_GEOMETRY | LF_MODIFY_SCALE)) { @@ -899,19 +893,22 @@ void modify_roi_in(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t * #pragma omp for schedule(static) #endif for(int i = 0; i < awidth; i++) - lf_modifier_apply_subpixel_geometry_distortion(modifier, xoff + i * xstep, yoff + (height - 1), 1, 1, buf + 6 * (awidth + i)); + lf_modifier_apply_subpixel_geometry_distortion(modifier, xoff + i * xstep, yoff + (height - 1), 1, 1, + buf + 6 * (awidth + i)); #ifdef _OPENMP #pragma omp for schedule(static) #endif for(int j = 0; j < aheight; j++) - lf_modifier_apply_subpixel_geometry_distortion(modifier, xoff, yoff + j * ystep, 1, 1, buf + 6 * (2 * awidth + j)); + lf_modifier_apply_subpixel_geometry_distortion(modifier, xoff, yoff + j * ystep, 1, 1, + buf + 6 * (2 * awidth + j)); #ifdef _OPENMP #pragma omp for schedule(static) #endif for(int j = 0; j < aheight; j++) - lf_modifier_apply_subpixel_geometry_distortion(modifier, xoff + (width - 1), yoff + j * ystep, 1, 1, buf + 6 * (2 * awidth + aheight + j)); + lf_modifier_apply_subpixel_geometry_distortion(modifier, xoff + (width - 1), yoff + j * ystep, 1, 1, + buf + 6 * (2 * awidth + aheight + j)); #ifdef _OPENMP #pragma omp barrier @@ -996,8 +993,7 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix if(p->lens[0]) { dt_pthread_mutex_lock(&darktable.plugin_threadsafe); - const lfLens **lens - = lf_db_find_lenses_hd(dt_iop_lensfun_db, camera, NULL, p->lens, 0); + const lfLens **lens = lf_db_find_lenses_hd(dt_iop_lensfun_db, camera, NULL, p->lens, 0); dt_pthread_mutex_unlock(&darktable.plugin_threadsafe); if(lens) { @@ -1087,7 +1083,8 @@ void init_global(dt_iop_module_so_t *module) *c = '\0'; #ifdef LF_MAX_DATABASE_VERSION g_free(dt_iop_lensfun_db->HomeDataDir); - dt_iop_lensfun_db->HomeDataDir = g_build_filename(path, "lensfun", "version_" STR(LF_MAX_DATABASE_VERSION), NULL); + dt_iop_lensfun_db->HomeDataDir + = g_build_filename(path, "lensfun", "version_" STR(LF_MAX_DATABASE_VERSION), NULL); if(lf_db_load(dt_iop_lensfun_db) != LF_NO_ERROR) { fprintf(stderr, "[iop_lens]: could not load lensfun database in `%s'!\n", path); @@ -1235,7 +1232,7 @@ void init(dt_iop_module_t *module) module->default_enabled = 0; module->params_size = sizeof(dt_iop_lensfun_params_t); module->gui_data = NULL; - module->priority = 191; // module order created by iop_dependencies.py, do not edit! + module->priority = 202; // module order created by iop_dependencies.py, do not edit! } void cleanup(dt_iop_module_t *module) @@ -1900,8 +1897,8 @@ static void lens_autosearch_clicked(GtkWidget *button, gpointer user_data) parse_maker_model(txt, make, sizeof(make), model, sizeof(model)); dt_pthread_mutex_lock(&darktable.plugin_threadsafe); - lenslist = lf_db_find_lenses_hd(dt_iop_lensfun_db, g->camera, make[0] ? make : NULL, - model[0] ? model : NULL, LF_SEARCH_SORT_AND_UNIQUIFY); + lenslist = lf_db_find_lenses_hd(dt_iop_lensfun_db, g->camera, make[0] ? make : NULL, model[0] ? model : NULL, + LF_SEARCH_SORT_AND_UNIQUIFY); dt_pthread_mutex_unlock(&darktable.plugin_threadsafe); if(!lenslist) return; lens_menu_fill(self, lenslist); @@ -1990,8 +1987,7 @@ static float get_autoscale(dt_iop_module_t *self, dt_iop_lensfun_params_t *p, co if(p->lens[0] != '\0') { dt_pthread_mutex_lock(&darktable.plugin_threadsafe); - const lfLens **lenslist - = lf_db_find_lenses_hd(dt_iop_lensfun_db, camera, NULL, p->lens, 0); + const lfLens **lenslist = lf_db_find_lenses_hd(dt_iop_lensfun_db, camera, NULL, p->lens, 0); if(lenslist) { const dt_image_t *img = &(self->dev->image_storage); @@ -2210,8 +2206,7 @@ void gui_init(struct dt_iop_module_t *self) dt_bauhaus_combobox_add(g->target_geom, _("equisolid angle")); dt_bauhaus_combobox_add(g->target_geom, _("thoby fish-eye")); #endif - g_signal_connect(G_OBJECT(g->target_geom), "value-changed", G_CALLBACK(target_geometry_changed), - (gpointer)self); + g_signal_connect(G_OBJECT(g->target_geom), "value-changed", G_CALLBACK(target_geometry_changed), (gpointer)self); // scale g->scale = dt_bauhaus_slider_new_with_range(self, 0.1, 2.0, 0.005, p->scale, 3); @@ -2322,8 +2317,8 @@ void gui_update(struct dt_iop_module_t *self) char make[200], model[200]; parse_maker_model(p->lens, make, sizeof(make), model, sizeof(model)); dt_pthread_mutex_lock(&darktable.plugin_threadsafe); - const lfLens **lenslist = lf_db_find_lenses_hd(dt_iop_lensfun_db, g->camera, make[0] ? make : NULL, - model[0] ? model : NULL, 0); + const lfLens **lenslist + = lf_db_find_lenses_hd(dt_iop_lensfun_db, g->camera, make[0] ? make : NULL, model[0] ? model : NULL, 0); if(lenslist) lens_set(self, lenslist[0]); else diff --git a/src/iop/levels.c b/src/iop/levels.c index b453de15534d..fddd05cd6bcc 100644 --- a/src/iop/levels.c +++ b/src/iop/levels.c @@ -127,8 +127,8 @@ int flags() return IOP_FLAGS_SUPPORTS_BLENDING; } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 1 && new_version == 2) { @@ -337,7 +337,8 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c } } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #ifdef HAVE_OPENCL @@ -508,7 +509,7 @@ void init(dt_iop_module_t *self) self->default_params = calloc(1, sizeof(dt_iop_levels_params_t)); self->default_enabled = 0; self->request_histogram |= (DT_REQUEST_ON); - self->priority = 691; // module order created by iop_dependencies.py, do not edit! + self->priority = 695; // module order created by iop_dependencies.py, do not edit! self->params_size = sizeof(dt_iop_levels_params_t); self->gui_data = NULL; } @@ -516,8 +517,7 @@ void init(dt_iop_module_t *self) void init_global(dt_iop_module_so_t *self) { const int program = 2; // basic.cl, from programs.conf - dt_iop_levels_global_data_t *gd - = (dt_iop_levels_global_data_t *)malloc(sizeof(dt_iop_levels_global_data_t)); + dt_iop_levels_global_data_t *gd = (dt_iop_levels_global_data_t *)malloc(sizeof(dt_iop_levels_global_data_t)); self->data = gd; gd->kernel_levels = dt_opencl_create_kernel(program, "levels"); } @@ -576,20 +576,20 @@ void gui_init(dt_iop_module_t *self) gtk_box_pack_start(GTK_BOX(self->widget), c->mode, TRUE, TRUE, 0); c->mode_stack = gtk_stack_new(); - gtk_stack_set_homogeneous(GTK_STACK(c->mode_stack),FALSE); + gtk_stack_set_homogeneous(GTK_STACK(c->mode_stack), FALSE); gtk_box_pack_start(GTK_BOX(self->widget), c->mode_stack, TRUE, TRUE, 0); c->area = GTK_DRAWING_AREA(dtgtk_drawing_area_new_with_aspect_ratio(9.0 / 16.0)); GtkWidget *vbox_manual = GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_VERTICAL, 5)); gtk_box_pack_start(GTK_BOX(vbox_manual), GTK_WIDGET(c->area), TRUE, TRUE, 0); - gtk_widget_set_tooltip_text(GTK_WIDGET(c->area),_("drag handles to set black, gray, and white points. " - "operates on L channel.")); + gtk_widget_set_tooltip_text(GTK_WIDGET(c->area), _("drag handles to set black, gray, and white points. " + "operates on L channel.")); gtk_widget_add_events(GTK_WIDGET(c->area), GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK - | GDK_SMOOTH_SCROLL_MASK); + | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK + | GDK_SMOOTH_SCROLL_MASK); g_signal_connect(G_OBJECT(c->area), "draw", G_CALLBACK(dt_iop_levels_area_draw), self); g_signal_connect(G_OBJECT(c->area), "button-press-event", G_CALLBACK(dt_iop_levels_button_press), self); g_signal_connect(G_OBJECT(c->area), "button-release-event", G_CALLBACK(dt_iop_levels_button_release), self); @@ -664,15 +664,14 @@ void gui_init(dt_iop_module_t *self) } g_signal_connect(G_OBJECT(c->mode), "value-changed", G_CALLBACK(dt_iop_levels_mode_callback), self); - g_signal_connect(G_OBJECT(c->percentile_black), "value-changed", - G_CALLBACK(dt_iop_levels_percentiles_callback), self); - g_signal_connect(G_OBJECT(c->percentile_grey), "value-changed", - G_CALLBACK(dt_iop_levels_percentiles_callback), self); - g_signal_connect(G_OBJECT(c->percentile_white), "value-changed", - G_CALLBACK(dt_iop_levels_percentiles_callback), self); - - g_signal_connect(G_OBJECT(autobutton), "clicked", G_CALLBACK(dt_iop_levels_autoadjust_callback), - (gpointer)self); + g_signal_connect(G_OBJECT(c->percentile_black), "value-changed", G_CALLBACK(dt_iop_levels_percentiles_callback), + self); + g_signal_connect(G_OBJECT(c->percentile_grey), "value-changed", G_CALLBACK(dt_iop_levels_percentiles_callback), + self); + g_signal_connect(G_OBJECT(c->percentile_white), "value-changed", G_CALLBACK(dt_iop_levels_percentiles_callback), + self); + + g_signal_connect(G_OBJECT(autobutton), "clicked", G_CALLBACK(dt_iop_levels_autoadjust_callback), (gpointer)self); g_signal_connect(G_OBJECT(blackpick), "toggled", G_CALLBACK(dt_iop_levels_pick_black_callback), self); g_signal_connect(G_OBJECT(greypick), "toggled", G_CALLBACK(dt_iop_levels_pick_grey_callback), self); g_signal_connect(G_OBJECT(whitepick), "toggled", G_CALLBACK(dt_iop_levels_pick_white_callback), self); @@ -768,8 +767,7 @@ static gboolean dt_iop_levels_area_draw(GtkWidget *widget, cairo_t *crf, gpointe c->pick_xy_positions[2][1] = self->color_picker_point[1]; } - if(previous_color[0] != p->levels[0] || previous_color[1] != p->levels[1] - || previous_color[2] != p->levels[2]) + if(previous_color[0] != p->levels[0] || previous_color[1] != p->levels[1] || previous_color[2] != p->levels[2]) { dt_dev_add_history_item(darktable.develop, self, TRUE); } @@ -971,14 +969,13 @@ static gboolean dt_iop_levels_motion_notify(GtkWidget *widget, GdkEventMotion *e gint x, y; #if GTK_CHECK_VERSION(3, 20, 0) - gdk_window_get_device_position(event->window, - gdk_seat_get_pointer(gdk_display_get_default_seat(gtk_widget_get_display(widget))), - &x, &y, 0); + gdk_window_get_device_position( + event->window, gdk_seat_get_pointer(gdk_display_get_default_seat(gtk_widget_get_display(widget))), &x, &y, 0); #else - gdk_window_get_device_position(event->window, - gdk_device_manager_get_client_pointer( - gdk_display_get_device_manager(gdk_window_get_display(event->window))), - &x, &y, NULL); + gdk_window_get_device_position( + event->window, + gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gdk_window_get_display(event->window))), + &x, &y, NULL); #endif return TRUE; } @@ -1048,8 +1045,8 @@ static gboolean dt_iop_levels_scroll(GtkWidget *widget, GdkEventScroll *event, g return FALSE; } -static void dt_iop_levels_pick_general_handler(GtkToggleButton *togglebutton, dt_iop_module_t *self, - double xpick, double ypick, dt_iop_levels_pick_t picklevel) +static void dt_iop_levels_pick_general_handler(GtkToggleButton *togglebutton, dt_iop_module_t *self, double xpick, + double ypick, dt_iop_levels_pick_t picklevel) { dt_iop_levels_gui_data_t *c = (dt_iop_levels_gui_data_t *)self->gui_data; diff --git a/src/iop/liquify.c b/src/iop/liquify.c index 0ffbf8014765..639b6b7a8a98 100644 --- a/src/iop/liquify.c +++ b/src/iop/liquify.c @@ -46,15 +46,16 @@ DT_MODULE_INTROSPECTION(1, dt_iop_liquify_params_t) #define MAX_NODES 100 // max of nodes in one instance -const int LOOKUP_OVERSAMPLE = 10; -const int INTERPOLATION_POINTS = 100; // when interpolating bezier -const float STAMP_RELOCATION = 0.1; // how many radii to move stamp forward when following a path +const int LOOKUP_OVERSAMPLE = 10; +const int INTERPOLATION_POINTS = 100; // when interpolating bezier +const float STAMP_RELOCATION = 0.1; // how many radii to move stamp forward when following a path #define CONF_RADIUS "plugins/darkroom/liquify/radius" // enum of layers. sorted back to front. -typedef enum { +typedef enum +{ DT_LIQUIFY_LAYER_BACKGROUND, DT_LIQUIFY_LAYER_RADIUS, DT_LIQUIFY_LAYER_HARDNESS1, @@ -77,62 +78,121 @@ typedef enum { DT_LIQUIFY_LAYER_LAST } dt_liquify_layer_enum_t; -typedef enum { - DT_LIQUIFY_LAYER_FLAG_HIT_TEST = 1, ///< include layer in hit testing - DT_LIQUIFY_LAYER_FLAG_PREV_SELECTED = 2, ///< show if previous node is selected - DT_LIQUIFY_LAYER_FLAG_NODE_SELECTED = 4, ///< show if node is selected - DT_LIQUIFY_LAYER_FLAG_POINT_TOOL = 8, ///< show if point tool active - DT_LIQUIFY_LAYER_FLAG_LINE_TOOL = 16, ///< show if line tool active - DT_LIQUIFY_LAYER_FLAG_CURVE_TOOL = 32, ///< show if line tool active - DT_LIQUIFY_LAYER_FLAG_NODE_TOOL = 64, ///< show if node tool active - DT_LIQUIFY_LAYER_FLAG_ANY_TOOL = 8 + 16 + 32 + 64, +typedef enum +{ + DT_LIQUIFY_LAYER_FLAG_HIT_TEST = 1, ///< include layer in hit testing + DT_LIQUIFY_LAYER_FLAG_PREV_SELECTED = 2, ///< show if previous node is selected + DT_LIQUIFY_LAYER_FLAG_NODE_SELECTED = 4, ///< show if node is selected + DT_LIQUIFY_LAYER_FLAG_POINT_TOOL = 8, ///< show if point tool active + DT_LIQUIFY_LAYER_FLAG_LINE_TOOL = 16, ///< show if line tool active + DT_LIQUIFY_LAYER_FLAG_CURVE_TOOL = 32, ///< show if line tool active + DT_LIQUIFY_LAYER_FLAG_NODE_TOOL = 64, ///< show if node tool active + DT_LIQUIFY_LAYER_FLAG_ANY_TOOL = 8 + 16 + 32 + 64, } dt_liquify_layer_flag_enum_t; -typedef struct { +typedef struct +{ float red, green, blue, alpha; } dt_liquify_rgba_t; -#define COLOR_NULL { 0.0, 0.0, 0.0, 0.8 } -#define GREY { 0.3, 0.3, 0.3, 0.8 } -#define LGREY { 0.8, 0.8, 0.8, 1.0 } -#define COLOR_DEBUG { 0.9, 0.9, 0.0, 1.0 } +#define COLOR_NULL \ + { \ + 0.0, 0.0, 0.0, 0.8 \ + } +#define GREY \ + { \ + 0.3, 0.3, 0.3, 0.8 \ + } +#define LGREY \ + { \ + 0.8, 0.8, 0.8, 1.0 \ + } +#define COLOR_DEBUG \ + { \ + 0.9, 0.9, 0.0, 1.0 \ + } static const dt_liquify_rgba_t DT_LIQUIFY_COLOR_SELECTED = { 1.0, 1.0, 1.0, 1.0 }; -static const dt_liquify_rgba_t DT_LIQUIFY_COLOR_HOVER = { 1.0, 1.0, 1.0, 0.8 }; - -typedef struct { - dt_liquify_layer_enum_t hover_master; ///< hover whenever master layer hovers, eg. to - dt_liquify_rgba_t fg; ///< the foreground color for this layer - dt_liquify_rgba_t bg; ///< the background color for this layer - double opacity; ///< the opacity of this layer - /// highlight the whole radius when only the - /// radius point is hovered - dt_liquify_layer_flag_enum_t flags; ///< various flags for layer - const char *hint; ///< hint displayed when hovering +static const dt_liquify_rgba_t DT_LIQUIFY_COLOR_HOVER = { 1.0, 1.0, 1.0, 0.8 }; + +typedef struct +{ + dt_liquify_layer_enum_t hover_master; ///< hover whenever master layer hovers, eg. to + dt_liquify_rgba_t fg; ///< the foreground color for this layer + dt_liquify_rgba_t bg; ///< the background color for this layer + double opacity; ///< the opacity of this layer + /// highlight the whole radius when only the + /// radius point is hovered + dt_liquify_layer_flag_enum_t flags; ///< various flags for layer + const char *hint; ///< hint displayed when hovering } dt_liquify_layer_t; dt_liquify_layer_t dt_liquify_layers[] = { - { DT_LIQUIFY_LAYER_BACKGROUND, COLOR_NULL, COLOR_NULL, 0.0, 0, }, - { DT_LIQUIFY_LAYER_RADIUS, COLOR_DEBUG, COLOR_NULL, 0.25, DT_LIQUIFY_LAYER_FLAG_ANY_TOOL, }, - { DT_LIQUIFY_LAYER_HARDNESS1, COLOR_DEBUG, COLOR_NULL, 1.0, 0, }, - { DT_LIQUIFY_LAYER_HARDNESS2, COLOR_DEBUG, COLOR_NULL, 1.0, 0, }, - { DT_LIQUIFY_LAYER_WARPS, COLOR_DEBUG, LGREY, 0.5, DT_LIQUIFY_LAYER_FLAG_ANY_TOOL, }, - { DT_LIQUIFY_LAYER_PATH, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_ANY_TOOL | DT_LIQUIFY_LAYER_FLAG_HIT_TEST, }, - { DT_LIQUIFY_LAYER_CTRLPOINT1, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_NODE_TOOL, }, - { DT_LIQUIFY_LAYER_CTRLPOINT2, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_NODE_TOOL, }, - { DT_LIQUIFY_LAYER_RADIUSPOINT, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_NODE_TOOL, }, - { DT_LIQUIFY_LAYER_HARDNESSPOINT1, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_NODE_TOOL | DT_LIQUIFY_LAYER_FLAG_NODE_SELECTED, }, - { DT_LIQUIFY_LAYER_HARDNESSPOINT2, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_NODE_TOOL | DT_LIQUIFY_LAYER_FLAG_NODE_SELECTED, }, - { DT_LIQUIFY_LAYER_STRENGTHPOINT, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_ANY_TOOL, }, - { DT_LIQUIFY_LAYER_CENTERPOINT, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_ANY_TOOL | DT_LIQUIFY_LAYER_FLAG_HIT_TEST, }, - { DT_LIQUIFY_LAYER_CTRLPOINT1, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_NODE_TOOL | DT_LIQUIFY_LAYER_FLAG_HIT_TEST, }, - { DT_LIQUIFY_LAYER_CTRLPOINT2, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_NODE_TOOL | DT_LIQUIFY_LAYER_FLAG_HIT_TEST, }, - { DT_LIQUIFY_LAYER_RADIUSPOINT, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_NODE_TOOL | DT_LIQUIFY_LAYER_FLAG_HIT_TEST, }, - { DT_LIQUIFY_LAYER_HARDNESSPOINT1, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_NODE_TOOL | DT_LIQUIFY_LAYER_FLAG_NODE_SELECTED | DT_LIQUIFY_LAYER_FLAG_HIT_TEST, }, - { DT_LIQUIFY_LAYER_HARDNESSPOINT2, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_NODE_TOOL | DT_LIQUIFY_LAYER_FLAG_NODE_SELECTED | DT_LIQUIFY_LAYER_FLAG_HIT_TEST, }, - { DT_LIQUIFY_LAYER_STRENGTHPOINT, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_ANY_TOOL | DT_LIQUIFY_LAYER_FLAG_HIT_TEST, } + { + DT_LIQUIFY_LAYER_BACKGROUND, COLOR_NULL, COLOR_NULL, 0.0, 0, + }, + { + DT_LIQUIFY_LAYER_RADIUS, COLOR_DEBUG, COLOR_NULL, 0.25, DT_LIQUIFY_LAYER_FLAG_ANY_TOOL, + }, + { + DT_LIQUIFY_LAYER_HARDNESS1, COLOR_DEBUG, COLOR_NULL, 1.0, 0, + }, + { + DT_LIQUIFY_LAYER_HARDNESS2, COLOR_DEBUG, COLOR_NULL, 1.0, 0, + }, + { + DT_LIQUIFY_LAYER_WARPS, COLOR_DEBUG, LGREY, 0.5, DT_LIQUIFY_LAYER_FLAG_ANY_TOOL, + }, + { + DT_LIQUIFY_LAYER_PATH, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_ANY_TOOL | DT_LIQUIFY_LAYER_FLAG_HIT_TEST, + }, + { + DT_LIQUIFY_LAYER_CTRLPOINT1, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_NODE_TOOL, + }, + { + DT_LIQUIFY_LAYER_CTRLPOINT2, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_NODE_TOOL, + }, + { + DT_LIQUIFY_LAYER_RADIUSPOINT, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_NODE_TOOL, + }, + { + DT_LIQUIFY_LAYER_HARDNESSPOINT1, GREY, LGREY, 1.0, + DT_LIQUIFY_LAYER_FLAG_NODE_TOOL | DT_LIQUIFY_LAYER_FLAG_NODE_SELECTED, + }, + { + DT_LIQUIFY_LAYER_HARDNESSPOINT2, GREY, LGREY, 1.0, + DT_LIQUIFY_LAYER_FLAG_NODE_TOOL | DT_LIQUIFY_LAYER_FLAG_NODE_SELECTED, + }, + { + DT_LIQUIFY_LAYER_STRENGTHPOINT, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_ANY_TOOL, + }, + { + DT_LIQUIFY_LAYER_CENTERPOINT, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_ANY_TOOL | DT_LIQUIFY_LAYER_FLAG_HIT_TEST, + }, + { + DT_LIQUIFY_LAYER_CTRLPOINT1, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_NODE_TOOL | DT_LIQUIFY_LAYER_FLAG_HIT_TEST, + }, + { + DT_LIQUIFY_LAYER_CTRLPOINT2, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_NODE_TOOL | DT_LIQUIFY_LAYER_FLAG_HIT_TEST, + }, + { + DT_LIQUIFY_LAYER_RADIUSPOINT, GREY, LGREY, 1.0, DT_LIQUIFY_LAYER_FLAG_NODE_TOOL | DT_LIQUIFY_LAYER_FLAG_HIT_TEST, + }, + { + DT_LIQUIFY_LAYER_HARDNESSPOINT1, GREY, LGREY, 1.0, + DT_LIQUIFY_LAYER_FLAG_NODE_TOOL | DT_LIQUIFY_LAYER_FLAG_NODE_SELECTED | DT_LIQUIFY_LAYER_FLAG_HIT_TEST, + }, + { + DT_LIQUIFY_LAYER_HARDNESSPOINT2, GREY, LGREY, 1.0, + DT_LIQUIFY_LAYER_FLAG_NODE_TOOL | DT_LIQUIFY_LAYER_FLAG_NODE_SELECTED | DT_LIQUIFY_LAYER_FLAG_HIT_TEST, + }, + { + DT_LIQUIFY_LAYER_STRENGTHPOINT, GREY, LGREY, 1.0, + DT_LIQUIFY_LAYER_FLAG_ANY_TOOL | DT_LIQUIFY_LAYER_FLAG_HIT_TEST, + } }; -typedef enum { +typedef enum +{ DT_LIQUIFY_UI_WIDTH_THINLINE, DT_LIQUIFY_UI_WIDTH_THICKLINE, DT_LIQUIFY_UI_WIDTH_DOUBLELINE, @@ -144,26 +204,28 @@ typedef enum { DT_LIQUIFY_UI_WIDTH_LAST } dt_liquify_ui_width_enum_t; -float dt_liquify_ui_widths [] = { +float dt_liquify_ui_widths[] = { // value in 1/96 inch (that is: in pixels on a standard 96 dpi screen) - 2.0, // DT_LIQUIFY_UI_WIDTH_THINLINE - 3.0, // DT_LIQUIFY_UI_WIDTH_THICKLINE - 3.0, // DT_LIQUIFY_UI_WIDTH_DOUBLELINE - 9.0, // DT_LIQUIFY_UI_WIDTH_GIZMO - 7.0, // DT_LIQUIFY_UI_WIDTH_GIZMO_SMALL + 2.0, // DT_LIQUIFY_UI_WIDTH_THINLINE + 3.0, // DT_LIQUIFY_UI_WIDTH_THICKLINE + 3.0, // DT_LIQUIFY_UI_WIDTH_DOUBLELINE + 9.0, // DT_LIQUIFY_UI_WIDTH_GIZMO + 7.0, // DT_LIQUIFY_UI_WIDTH_GIZMO_SMALL 100.0, // DT_LIQUIFY_UI_WIDTH_DEFAULT_RADIUS, - 50.0, // DT_LIQUIFY_UI_WIDTH_DEFAULT_STRENGTH, - 4.0 // DT_LIQUIFY_UI_WIDTH_MIN_DRAG + 50.0, // DT_LIQUIFY_UI_WIDTH_DEFAULT_STRENGTH, + 4.0 // DT_LIQUIFY_UI_WIDTH_MIN_DRAG }; -typedef enum { - DT_LIQUIFY_WARP_TYPE_LINEAR, ///< A linear warp originating from one point. - DT_LIQUIFY_WARP_TYPE_RADIAL_GROW, ///< A radial warp originating from one point. +typedef enum +{ + DT_LIQUIFY_WARP_TYPE_LINEAR, ///< A linear warp originating from one point. + DT_LIQUIFY_WARP_TYPE_RADIAL_GROW, ///< A radial warp originating from one point. DT_LIQUIFY_WARP_TYPE_RADIAL_SHRINK, DT_LIQUIFY_WARP_TYPE_LAST } dt_liquify_warp_type_enum_t; -typedef enum { +typedef enum +{ DT_LIQUIFY_NODE_TYPE_CUSP, DT_LIQUIFY_NODE_TYPE_SMOOTH, DT_LIQUIFY_NODE_TYPE_SYMMETRICAL, @@ -171,7 +233,8 @@ typedef enum { DT_LIQUIFY_NODE_TYPE_LAST } dt_liquify_node_type_enum_t; -typedef enum { +typedef enum +{ DT_LIQUIFY_STATUS_NONE = 0, DT_LIQUIFY_STATUS_NEW = 1, DT_LIQUIFY_STATUS_INTERPOLATED = 2, @@ -180,14 +243,16 @@ typedef enum { // enumerates the shapes types we use. -typedef enum { +typedef enum +{ DT_LIQUIFY_PATH_INVALIDATED = 0, DT_LIQUIFY_PATH_MOVE_TO_V1, DT_LIQUIFY_PATH_LINE_TO_V1, DT_LIQUIFY_PATH_CURVE_TO_V1, } dt_liquify_path_data_enum_t; -typedef struct { +typedef struct +{ dt_liquify_path_data_enum_t type; dt_liquify_node_type_enum_t node_type; dt_liquify_layer_enum_t selected; @@ -200,60 +265,67 @@ typedef struct { // Scalars and vectors are represented here as points because the only // thing we can reasonably distort_transform are points. -typedef struct { +typedef struct +{ float complex point; - float complex strength; ///< a point (the effective strength vector is: strength - point) - float complex radius; ///< a point (the effective radius scalar is: cabs (radius - point)) - float control1; ///< range 0.0 .. 1.0 == radius - float control2; ///< range 0.0 .. 1.0 == radius + float complex strength; ///< a point (the effective strength vector is: strength - point) + float complex radius; ///< a point (the effective radius scalar is: cabs (radius - point)) + float control1; ///< range 0.0 .. 1.0 == radius + float control2; ///< range 0.0 .. 1.0 == radius dt_liquify_warp_type_enum_t type; dt_liquify_status_enum_t status; } dt_liquify_warp_t; -typedef struct { +typedef struct +{ float complex ctrl1; float complex ctrl2; } dt_liquify_node_t; // set up lots of alternative ways to get at the popular members. -typedef struct { +typedef struct +{ dt_liquify_path_header_t header; - dt_liquify_warp_t warp; - dt_liquify_node_t node; // extended node data + dt_liquify_warp_t warp; + dt_liquify_node_t node; // extended node data } dt_liquify_path_data_t; -typedef struct { +typedef struct +{ dt_liquify_layer_enum_t layer; dt_liquify_path_data_t *elem; } dt_liquify_hit_t; static const dt_liquify_hit_t NOWHERE = { DT_LIQUIFY_LAYER_BACKGROUND, NULL }; -typedef struct { +typedef struct +{ dt_liquify_path_data_t nodes[MAX_NODES]; } dt_iop_liquify_params_t; -typedef struct { +typedef struct +{ int warp_kernel; } dt_iop_liquify_global_data_t; -typedef struct { +typedef struct +{ dt_pthread_mutex_t lock; dt_iop_liquify_params_t params; int node_index; // last node index inserted float complex last_mouse_pos; float complex last_button1_pressed_pos; - GdkModifierType last_mouse_mods; ///< GDK modifiers at the time mouse button was pressed. + GdkModifierType last_mouse_mods; ///< GDK modifiers at the time mouse button was pressed. - dt_liquify_hit_t last_hit; ///< Element last hit with mouse button. - dt_liquify_hit_t dragging; ///< Element being dragged with mouse button. + dt_liquify_hit_t last_hit; ///< Element last hit with mouse button. + dt_liquify_hit_t dragging; ///< Element being dragged with mouse button. dt_liquify_path_data_t *temp; ///< Points to the element under construction or NULL. dt_liquify_status_enum_t status; ///< Various flags. - cairo_t *fake_cr; ///< A fake cairo context for hit testing and coordinate transform. + cairo_t *fake_cr; ///< A fake cairo context for hit testing and coordinate transform. GtkLabel *label; GtkToggleButton *btn_point_tool, *btn_line_tool, *btn_curve_tool, *btn_node_tool; @@ -261,24 +333,24 @@ typedef struct { } dt_iop_liquify_gui_data_t; // this returns a translatable name -const char *name () +const char *name() { return _("liquify"); } -int groups () +int groups() { return IOP_GROUP_CORRECT; } -int flags () +int flags() { return IOP_FLAGS_SUPPORTS_BLENDING; } int operation_tags() { - return IOP_TAG_DISTORT; + return IOP_TAG_DISTORT; } /******************************************************************************/ @@ -287,16 +359,16 @@ int operation_tags() static const float get_rot(const dt_liquify_warp_type_enum_t warp_type) { - if (warp_type == DT_LIQUIFY_WARP_TYPE_RADIAL_SHRINK) + if(warp_type == DT_LIQUIFY_WARP_TYPE_RADIAL_SHRINK) return M_PI; else return 0.0; } -static dt_liquify_path_data_t *node_alloc (dt_iop_liquify_params_t *p, int *node_index) +static dt_liquify_path_data_t *node_alloc(dt_iop_liquify_params_t *p, int *node_index) { - for (int k=0; k<MAX_NODES; k++) - if (p->nodes[k].header.type == DT_LIQUIFY_PATH_INVALIDATED) + for(int k = 0; k < MAX_NODES; k++) + if(p->nodes[k].header.type == DT_LIQUIFY_PATH_INVALIDATED) { *node_index = k; p->nodes[k].header.idx = k; @@ -307,59 +379,58 @@ static dt_liquify_path_data_t *node_alloc (dt_iop_liquify_params_t *p, int *node return NULL; } -static dt_liquify_path_data_t *node_prev (dt_iop_liquify_params_t *p, const dt_liquify_path_data_t *n) +static dt_liquify_path_data_t *node_prev(dt_iop_liquify_params_t *p, const dt_liquify_path_data_t *n) { - if (n->header.prev == -1) + if(n->header.prev == -1) return NULL; else return &p->nodes[n->header.prev]; } -static dt_liquify_path_data_t *node_get (dt_iop_liquify_params_t *p, const int index) +static dt_liquify_path_data_t *node_get(dt_iop_liquify_params_t *p, const int index) { - if (index > -1 && index < MAX_NODES) + if(index > -1 && index < MAX_NODES) return &p->nodes[index]; else return NULL; } -static dt_liquify_path_data_t *node_next (dt_iop_liquify_params_t *p, const dt_liquify_path_data_t *n) +static dt_liquify_path_data_t *node_next(dt_iop_liquify_params_t *p, const dt_liquify_path_data_t *n) { - if (n->header.next == -1) + if(n->header.next == -1) return NULL; else return &p->nodes[n->header.next]; } -static void node_insert_before (dt_iop_liquify_params_t *p, dt_liquify_path_data_t *this, dt_liquify_path_data_t *new) +static void node_insert_before(dt_iop_liquify_params_t *p, dt_liquify_path_data_t *this, + dt_liquify_path_data_t *new) { - new->header.next = this->header.idx; - new->header.prev = this->header.prev; - if (this->header.prev != -1) - p->nodes[this->header.prev].header.next = new->header.idx; + new->header.next = this->header.idx; + new->header.prev = this->header.prev; + if(this->header.prev != -1) p->nodes[this->header.prev].header.next = new->header.idx; this->header.prev = new->header.idx; } -static void node_gc (dt_iop_liquify_params_t *p) +static void node_gc(dt_iop_liquify_params_t *p) { - int last=0; - for (last=MAX_NODES-1; last>0; last--) - if (p->nodes[last].header.type != DT_LIQUIFY_PATH_INVALIDATED) - break; + int last = 0; + for(last = MAX_NODES - 1; last > 0; last--) + if(p->nodes[last].header.type != DT_LIQUIFY_PATH_INVALIDATED) break; int k = 0; - while (k<=last) + while(k <= last) { - if (p->nodes[k].header.type == DT_LIQUIFY_PATH_INVALIDATED) + if(p->nodes[k].header.type == DT_LIQUIFY_PATH_INVALIDATED) { - for (int e=0; e<last; e++) + for(int e = 0; e < last; e++) { // then move slot if above position k - if (e >= k) p->nodes[e] = p->nodes[e+1]; + if(e >= k) p->nodes[e] = p->nodes[e + 1]; // update all pointers above position k - if (e >= k) p->nodes[e].header.idx--; - if (p->nodes[e].header.prev >= k) p->nodes[e].header.prev--; - if (p->nodes[e].header.next >= k) p->nodes[e].header.next--; + if(e >= k) p->nodes[e].header.idx--; + if(p->nodes[e].header.prev >= k) p->nodes[e].header.prev--; + if(p->nodes[e].header.next >= k) p->nodes[e].header.next--; } last--; } @@ -367,52 +438,50 @@ static void node_gc (dt_iop_liquify_params_t *p) k++; } // invalidate all nodes beyond the last moved one - for (int k=last+1; k<MAX_NODES; k++) - p->nodes[k].header.type = DT_LIQUIFY_PATH_INVALIDATED; + for(int k = last + 1; k < MAX_NODES; k++) p->nodes[k].header.type = DT_LIQUIFY_PATH_INVALIDATED; } -static void node_delete (dt_iop_liquify_params_t *p, dt_liquify_path_data_t *this) +static void node_delete(dt_iop_liquify_params_t *p, dt_liquify_path_data_t *this) { - dt_liquify_path_data_t *prev = node_prev (p, this); - dt_liquify_path_data_t *next = node_next (p, this); + dt_liquify_path_data_t *prev = node_prev(p, this); + dt_liquify_path_data_t *next = node_next(p, this); - if (!prev && next) + if(!prev && next) { next->header.prev = -1; next->header.type = DT_LIQUIFY_PATH_MOVE_TO_V1; } - else if (prev) + else if(prev) { prev->header.next = this->header.next; - if (next) - next->header.prev = prev->header.idx; + if(next) next->header.prev = prev->header.idx; } - this->header.prev = this->header.next = - 1; + this->header.prev = this->header.next = -1; this->header.type = DT_LIQUIFY_PATH_INVALIDATED; - node_gc (p); + node_gc(p); } -static void path_delete (dt_iop_liquify_params_t *p, dt_liquify_path_data_t *this) +static void path_delete(dt_iop_liquify_params_t *p, dt_liquify_path_data_t *this) { dt_liquify_path_data_t *n = this; // clear next - while (n) + while(n) { n->header.type = DT_LIQUIFY_PATH_INVALIDATED; - n = node_next (p, n); + n = node_next(p, n); } // clear prev n = this; - while (n) + while(n) { n->header.type = DT_LIQUIFY_PATH_INVALIDATED; - n = node_prev (p, n); + n = node_prev(p, n); } - node_gc (p); + node_gc(p); } /** @@ -477,7 +546,8 @@ static void path_delete (dt_iop_liquify_params_t *p, dt_liquify_path_data_t *thi * */ -typedef struct { +typedef struct +{ dt_develop_t *develop; dt_dev_pixelpipe_t *pipe; float from_scale; @@ -486,130 +556,124 @@ typedef struct { int pmax; } distort_params_t; -static void _distort_paths (const struct dt_iop_module_t *module, - const distort_params_t *params, const dt_iop_liquify_params_t *p) +static void _distort_paths(const struct dt_iop_module_t *module, const distort_params_t *params, + const dt_iop_liquify_params_t *p) { int len = 0; // count nodes - for (int k=0; k<MAX_NODES; k++) + for(int k = 0; k < MAX_NODES; k++) { - dt_liquify_path_data_t *data = (dt_liquify_path_data_t *) &p->nodes[k]; - if (data->header.type == DT_LIQUIFY_PATH_INVALIDATED) - break; + dt_liquify_path_data_t *data = (dt_liquify_path_data_t *)&p->nodes[k]; + if(data->header.type == DT_LIQUIFY_PATH_INVALIDATED) break; - switch (data->header.type) + switch(data->header.type) { - case DT_LIQUIFY_PATH_CURVE_TO_V1: - len += 2; + case DT_LIQUIFY_PATH_CURVE_TO_V1: + len += 2; // fall thru - case DT_LIQUIFY_PATH_MOVE_TO_V1: - case DT_LIQUIFY_PATH_LINE_TO_V1: - len += 3; - break; - default: - break; + case DT_LIQUIFY_PATH_MOVE_TO_V1: + case DT_LIQUIFY_PATH_LINE_TO_V1: + len += 3; + break; + default: + break; } } // create buffer with all points - float *buffer = malloc (2 * sizeof (float) * len); + float *buffer = malloc(2 * sizeof(float) * len); float *b = buffer; - for (int k=0; k<MAX_NODES; k++) + for(int k = 0; k < MAX_NODES; k++) { - dt_liquify_path_data_t *data = (dt_liquify_path_data_t *) &p->nodes[k]; - if (data->header.type == DT_LIQUIFY_PATH_INVALIDATED) - break; + dt_liquify_path_data_t *data = (dt_liquify_path_data_t *)&p->nodes[k]; + if(data->header.type == DT_LIQUIFY_PATH_INVALIDATED) break; - switch (data->header.type) + switch(data->header.type) { - case DT_LIQUIFY_PATH_CURVE_TO_V1: - *b++ = creal (data->node.ctrl1) / params->from_scale; - *b++ = cimag (data->node.ctrl1) / params->from_scale; - *b++ = creal (data->node.ctrl2) / params->from_scale; - *b++ = cimag (data->node.ctrl2) / params->from_scale; + case DT_LIQUIFY_PATH_CURVE_TO_V1: + *b++ = creal(data->node.ctrl1) / params->from_scale; + *b++ = cimag(data->node.ctrl1) / params->from_scale; + *b++ = creal(data->node.ctrl2) / params->from_scale; + *b++ = cimag(data->node.ctrl2) / params->from_scale; // fall thru - case DT_LIQUIFY_PATH_MOVE_TO_V1: - case DT_LIQUIFY_PATH_LINE_TO_V1: - *b++ = creal (data->warp.point) / params->from_scale; - *b++ = cimag (data->warp.point) / params->from_scale; - *b++ = creal (data->warp.strength) / params->from_scale; - *b++ = cimag (data->warp.strength) / params->from_scale; - *b++ = creal (data->warp.radius) / params->from_scale; - *b++ = cimag (data->warp.radius) / params->from_scale; - break; - default: - break; + case DT_LIQUIFY_PATH_MOVE_TO_V1: + case DT_LIQUIFY_PATH_LINE_TO_V1: + *b++ = creal(data->warp.point) / params->from_scale; + *b++ = cimag(data->warp.point) / params->from_scale; + *b++ = creal(data->warp.strength) / params->from_scale; + *b++ = cimag(data->warp.strength) / params->from_scale; + *b++ = creal(data->warp.radius) / params->from_scale; + *b++ = cimag(data->warp.radius) / params->from_scale; + break; + default: + break; } } - if (params->pmin < module->priority && params->pmax > module->priority) + if(params->pmin < module->priority && params->pmax > module->priority) { - dt_dev_distort_transform_plus (params->develop, params->pipe, params->pmin, module->priority - 1, buffer, len); - dt_dev_distort_transform_plus (params->develop, params->pipe, module->priority + 1, params->pmax, buffer, len); + dt_dev_distort_transform_plus(params->develop, params->pipe, params->pmin, module->priority - 1, buffer, len); + dt_dev_distort_transform_plus(params->develop, params->pipe, module->priority + 1, params->pmax, buffer, len); } else - dt_dev_distort_transform_plus (params->develop, params->pipe, params->pmin, params->pmax, buffer, len); + dt_dev_distort_transform_plus(params->develop, params->pipe, params->pmin, params->pmax, buffer, len); // record back the transformed points b = buffer; - for (int k=0; k<MAX_NODES; k++) + for(int k = 0; k < MAX_NODES; k++) { - dt_liquify_path_data_t *data = (dt_liquify_path_data_t *) &p->nodes[k]; - if (data->header.type == DT_LIQUIFY_PATH_INVALIDATED) - break; + dt_liquify_path_data_t *data = (dt_liquify_path_data_t *)&p->nodes[k]; + if(data->header.type == DT_LIQUIFY_PATH_INVALIDATED) break; - switch (data->header.type) + switch(data->header.type) { - case DT_LIQUIFY_PATH_CURVE_TO_V1: - data->node.ctrl1 = (b[0] + b[1] * I) * params->to_scale; - b += 2; - data->node.ctrl2 = (b[0] + b[1] * I) * params->to_scale; - b += 2; + case DT_LIQUIFY_PATH_CURVE_TO_V1: + data->node.ctrl1 = (b[0] + b[1] * I) * params->to_scale; + b += 2; + data->node.ctrl2 = (b[0] + b[1] * I) * params->to_scale; + b += 2; // fall thru - case DT_LIQUIFY_PATH_MOVE_TO_V1: - case DT_LIQUIFY_PATH_LINE_TO_V1: - data->warp.point = (b[0] + b[1] * I) * params->to_scale; - b += 2; - data->warp.strength = (b[0] + b[1] * I) * params->to_scale; - b += 2; - data->warp.radius = (b[0] + b[1] * I) * params->to_scale; - b += 2; - break; - default: - break; + case DT_LIQUIFY_PATH_MOVE_TO_V1: + case DT_LIQUIFY_PATH_LINE_TO_V1: + data->warp.point = (b[0] + b[1] * I) * params->to_scale; + b += 2; + data->warp.strength = (b[0] + b[1] * I) * params->to_scale; + b += 2; + data->warp.radius = (b[0] + b[1] * I) * params->to_scale; + b += 2; + break; + default: + break; } } - free (buffer); + free(buffer); } -static void distort_paths_raw_to_piece (const struct dt_iop_module_t *module, - dt_dev_pixelpipe_t *pipe, - const float roi_in_scale, - dt_iop_liquify_params_t *p) +static void distort_paths_raw_to_piece(const struct dt_iop_module_t *module, dt_dev_pixelpipe_t *pipe, + const float roi_in_scale, dt_iop_liquify_params_t *p) { const distort_params_t params = { module->dev, pipe, pipe->iscale, roi_in_scale, 0, module->priority - 1 }; - _distort_paths (module, &params, p); + _distort_paths(module, &params, p); } // op-engine code -static inline float complex normalize (const float complex v) +static inline float complex normalize(const float complex v) { - if (cabs (v) < 0.000001) - return 1.0; - return v / cabs (v); + if(cabs(v) < 0.000001) return 1.0; + return v / cabs(v); } // calculate the linear blend of scalars a and b -static inline float mix (const float a, const float b, const float t) +static inline float mix(const float a, const float b, const float t) { return a + (b - a) * t; } @@ -617,61 +681,54 @@ static inline float mix (const float a, const float b, const float t) // calculate the linear blend of points p0 and p1 -static inline float complex cmix (const float complex p0, const float complex p1, const float t) +static inline float complex cmix(const float complex p0, const float complex p1, const float t) { return p0 + (p1 - p0) * t; } -static void mix_warps (dt_liquify_warp_t *result, - const dt_liquify_warp_t *warp1, - const dt_liquify_warp_t *warp2, - const complex float pt, - const float t) +static void mix_warps(dt_liquify_warp_t *result, const dt_liquify_warp_t *warp1, const dt_liquify_warp_t *warp2, + const complex float pt, const float t) { - result->type = warp1->type; - result->control1 = mix (warp1->control1, warp2->control1, t); - result->control2 = mix (warp1->control2, warp2->control2, t); + result->type = warp1->type; + result->control1 = mix(warp1->control1, warp2->control1, t); + result->control2 = mix(warp1->control2, warp2->control2, t); - const float radius = mix (cabs (warp1->radius - warp1->point), cabs (warp2->radius - warp2->point), t); - result->radius = pt + radius; + const float radius = mix(cabs(warp1->radius - warp1->point), cabs(warp2->radius - warp2->point), t); + result->radius = pt + radius; - const float r = mix (cabs (warp1->strength - warp1->point), cabs (warp2->strength - warp2->point), t); - const float phi = mix (carg (warp1->strength - warp1->point), carg (warp2->strength - warp2->point), t); - result->strength = pt + r * cexp (phi * I); + const float r = mix(cabs(warp1->strength - warp1->point), cabs(warp2->strength - warp2->point), t); + const float phi = mix(carg(warp1->strength - warp1->point), carg(warp2->strength - warp2->point), t); + result->strength = pt + r * cexp(phi * I); - result->point = pt; + result->point = pt; } // Interpolate a cubic bezier spline into a series of points. -static void interpolate_cubic_bezier (const float complex p0, - const float complex p1, - const float complex p2, - const float complex p3, - float complex buffer[], - const int n) +static void interpolate_cubic_bezier(const float complex p0, const float complex p1, const float complex p2, + const float complex p3, float complex buffer[], const int n) { // convert from bernstein basis to polynomial basis to get faster math // See: http://www.tinaja.com/glib/cubemath.pdf - const float complex A = p3 - 3 * p2 + 3 * p1 - p0; - const float complex B = 3 * p2 - 6 * p1 + 3 * p0; - const float complex C = 3 * p1 - 3 * p0; - const float complex D = p0; + const float complex A = p3 - 3 * p2 + 3 * p1 - p0; + const float complex B = 3 * p2 - 6 * p1 + 3 * p0; + const float complex C = 3 * p1 - 3 * p0; + const float complex D = p0; float complex *buf = buffer; const float step = 1.0 / n; float t = step; *buf++ = p0; - for (int i = 1; i < n - 1; ++i) + for(int i = 1; i < n - 1; ++i) { - *buf++ = ((((A) * t) + B) * t + C) * t + D; + *buf++ = ((((A)*t) + B) * t + C) * t + D; t += step; } *buf = p3; } -static GList *interpolate_paths (dt_iop_liquify_params_t *p); +static GList *interpolate_paths(dt_iop_liquify_params_t *p); /* Get approx. arc length of a curve. @@ -679,15 +736,15 @@ static GList *interpolate_paths (dt_iop_liquify_params_t *p); Used to approximate the arc length of a bezier curve. */ -static const float get_arc_length (const float complex points[], const int n_points) +static const float get_arc_length(const float complex points[], const int n_points) { float length = 0.0; - for (int i = 1; i < n_points; i++) - length += cabs (points[i-1] - points[i]); + for(int i = 1; i < n_points; i++) length += cabs(points[i - 1] - points[i]); return length; } -typedef struct { +typedef struct +{ int i; double length; } restart_cookie_t; @@ -699,26 +756,25 @@ typedef struct { the arc length. */ -static const float complex point_at_arc_length (const float complex points[], - const int n_points, - const float arc_length, - restart_cookie_t *restart) +static const float complex point_at_arc_length(const float complex points[], const int n_points, + const float arc_length, restart_cookie_t *restart) { float length = restart ? restart->length : 0.0; - int i = restart ? restart->i : 1; + int i = restart ? restart->i : 1; - for ( ; i < n_points; i++) + for(; i < n_points; i++) { const float prev_length = length; - length += cabsf (points[i-1] - points[i]); - if (length >= arc_length) { + length += cabsf(points[i - 1] - points[i]); + if(length >= arc_length) + { const float t = (arc_length - prev_length) / (length - prev_length); - if (restart) + if(restart) { restart->i = i; restart->length = prev_length; } - return cmix (points[i-1], points[i], t); + return cmix(points[i - 1], points[i], t); } } @@ -756,48 +812,45 @@ static const float complex point_at_arc_length (const float complex points[], hold off; */ -static float * -build_lookup_table (const int distance, const float control1, const float control2) +static float *build_lookup_table(const int distance, const float control1, const float control2) { - float complex *clookup = dt_alloc_align (16, (distance + 2) * sizeof (float complex)); + float complex *clookup = dt_alloc_align(16, (distance + 2) * sizeof(float complex)); - interpolate_cubic_bezier (I, control1 + I, control2, 1.0, clookup, distance + 2); + interpolate_cubic_bezier(I, control1 + I, control2, 1.0, clookup, distance + 2); // reparameterize bezier by x and keep only y values - float *lookup = dt_alloc_align (16, (distance + 1) * sizeof (float)); + float *lookup = dt_alloc_align(16, (distance + 1) * sizeof(float)); float *ptr = lookup; float complex *cptr = clookup + 1; const float complex *cptr_end = cptr + distance; - const float step = 1.0 / (float) distance; + const float step = 1.0 / (float)distance; float x = 0.0; *ptr++ = 1.0; - for (int i = 1; i < distance && cptr < cptr_end; i++) + for(int i = 1; i < distance && cptr < cptr_end; i++) { x += step; - while (creal (*cptr) < x && cptr < cptr_end) - cptr++; - const float dx1 = creal (cptr[0] - cptr[-1]); - const float dx2 = x - creal (cptr[-1]); - *ptr++ = cimag (cptr[0]) + (dx2 / dx1) * (cimag (cptr[0]) - cimag (cptr[-1])); + while(creal(*cptr) < x && cptr < cptr_end) cptr++; + const float dx1 = creal(cptr[0] - cptr[-1]); + const float dx2 = x - creal(cptr[-1]); + *ptr++ = cimag(cptr[0]) + (dx2 / dx1) * (cimag(cptr[0]) - cimag(cptr[-1])); } *ptr++ = 0.0; - dt_free_align (clookup); + dt_free_align(clookup); return lookup; } -static void compute_round_stamp_extent (cairo_rectangle_int_t *stamp_extent, - const dt_liquify_warp_t *warp) +static void compute_round_stamp_extent(cairo_rectangle_int_t *stamp_extent, const dt_liquify_warp_t *warp) { - const int iradius = round (cabs (warp->radius - warp->point)); - assert (iradius > 0); + const int iradius = round(cabs(warp->radius - warp->point)); + assert(iradius > 0); stamp_extent->x = stamp_extent->y = -iradius; - stamp_extent->x += creal (warp->point); - stamp_extent->y += cimag (warp->point); + stamp_extent->x += creal(warp->point); + stamp_extent->y += cimag(warp->point); stamp_extent->width = stamp_extent->height = 2 * iradius + 1; } @@ -821,12 +874,11 @@ static void compute_round_stamp_extent (cairo_rectangle_int_t *stamp_extent, Our stamp is stored in a rectangular region. */ -static void build_round_stamp (float complex **pstamp, - cairo_rectangle_int_t *stamp_extent, - const dt_liquify_warp_t *warp) +static void build_round_stamp(float complex **pstamp, cairo_rectangle_int_t *stamp_extent, + const dt_liquify_warp_t *warp) { - const int iradius = round (cabs (warp->radius - warp->point)); - assert (iradius > 0); + const int iradius = round(cabs(warp->radius - warp->point)); + assert(iradius > 0); stamp_extent->x = stamp_extent->y = -iradius; stamp_extent->width = stamp_extent->height = 2 * iradius + 1; @@ -834,45 +886,43 @@ static void build_round_stamp (float complex **pstamp, // 0.5 is factored in so the warp starts to degenerate when the // strength arrow crosses the warp radius. float complex strength = 0.5 * (warp->strength - warp->point); - strength = (warp->status & DT_LIQUIFY_STATUS_INTERPOLATED) ? - (strength * STAMP_RELOCATION) : strength; - const float abs_strength = cabs (strength); + strength = (warp->status & DT_LIQUIFY_STATUS_INTERPOLATED) ? (strength * STAMP_RELOCATION) : strength; + const float abs_strength = cabs(strength); - float complex *stamp = malloc (sizeof (float complex) - * stamp_extent->width * stamp_extent->height); + float complex *stamp = malloc(sizeof(float complex) * stamp_extent->width * stamp_extent->height); - // clear memory - #ifdef _OPENMP - #pragma omp parallel for schedule (static) default (shared) - #endif +// clear memory +#ifdef _OPENMP +#pragma omp parallel for schedule(static) default(shared) +#endif - for (int i = 0; i < stamp_extent->height; i++) + for(int i = 0; i < stamp_extent->height; i++) { float complex *row = stamp + i * stamp_extent->width; - memset (row, 0, sizeof (float complex) * stamp_extent->width); + memset(row, 0, sizeof(float complex) * stamp_extent->width); } // lookup table: map of distance from center point => warp const int table_size = iradius * LOOKUP_OVERSAMPLE; - const float *lookup_table = build_lookup_table (table_size, warp->control1, warp->control2); + const float *lookup_table = build_lookup_table(table_size, warp->control1, warp->control2); // points into buffer at the center of the circle float complex *center = stamp + 2 * iradius * iradius + 2 * iradius; - // The expensive operation here is hypotf (). By dividing the - // circle in octants and doing only the inside we have to calculate - // hypotf only for PI / 32 = 0.098 of the stamp area. - #ifdef _OPENMP - #pragma omp parallel for schedule (dynamic, 1) default (shared) - #endif +// The expensive operation here is hypotf (). By dividing the +// circle in octants and doing only the inside we have to calculate +// hypotf only for PI / 32 = 0.098 of the stamp area. +#ifdef _OPENMP +#pragma omp parallel for schedule(dynamic, 1) default(shared) +#endif - for (int y = 0; y <= iradius; y++) + for(int y = 0; y <= iradius; y++) { - for (int x = y; x <= iradius; x++) + for(int x = y; x <= iradius; x++) { - const float dist = hypotf (x, y); - const int idist = round (dist * LOOKUP_OVERSAMPLE); - if (idist >= table_size) + const float dist = hypotf(x, y); + const int idist = round(dist * LOOKUP_OVERSAMPLE); + if(idist >= table_size) // idist will only grow bigger in this row goto next_row; @@ -889,40 +939,40 @@ static void build_round_stamp (float complex **pstamp, float abs_lookup = abs_strength * lookup_table[idist] / iradius; - switch (warp->type) + switch(warp->type) { - case DT_LIQUIFY_WARP_TYPE_RADIAL_GROW: - *o1 = abs_lookup * ( x - y * I); - *o2 = abs_lookup * ( y - x * I); - *o3 = abs_lookup * (-y - x * I); - *o4 = abs_lookup * (-x - y * I); - *o5 = abs_lookup * (-x + y * I); - *o6 = abs_lookup * (-y + x * I); - *o7 = abs_lookup * ( y + x * I); - *o8 = abs_lookup * ( x + y * I); - break; - - case DT_LIQUIFY_WARP_TYPE_RADIAL_SHRINK: - *o1 = -abs_lookup * ( x - y * I); - *o2 = -abs_lookup * ( y - x * I); - *o3 = -abs_lookup * (-y - x * I); - *o4 = -abs_lookup * (-x - y * I); - *o5 = -abs_lookup * (-x + y * I); - *o6 = -abs_lookup * (-y + x * I); - *o7 = -abs_lookup * ( y + x * I); - *o8 = -abs_lookup * ( x + y * I); - break; - - default: - *o1 = *o2 = *o3 = *o4 = *o5 = *o6 = *o7 = *o8 = - strength * lookup_table[idist]; - break; + case DT_LIQUIFY_WARP_TYPE_RADIAL_GROW: + *o1 = abs_lookup *(x - y * I); + *o2 = abs_lookup *(y - x * I); + *o3 = abs_lookup *(-y - x * I); + *o4 = abs_lookup *(-x - y * I); + *o5 = abs_lookup *(-x + y * I); + *o6 = abs_lookup *(-y + x * I); + *o7 = abs_lookup *(y + x * I); + *o8 = abs_lookup *(x + y * I); + break; + + case DT_LIQUIFY_WARP_TYPE_RADIAL_SHRINK: + *o1 = -abs_lookup *(x - y * I); + *o2 = -abs_lookup *(y - x * I); + *o3 = -abs_lookup *(-y - x * I); + *o4 = -abs_lookup *(-x - y * I); + *o5 = -abs_lookup *(-x + y * I); + *o6 = -abs_lookup *(-y + x * I); + *o7 = -abs_lookup *(y + x * I); + *o8 = -abs_lookup *(x + y * I); + break; + + default: + *o1 = *o2 = *o3 = *o4 = *o5 = *o6 = *o7 = *o8 = strength *lookup_table[idist]; + break; } } - next_row: ; // ";" makes compiler happy + next_row: + ; // ";" makes compiler happy } - dt_free_align ((void *) lookup_table); + dt_free_align((void *)lookup_table); *pstamp = stamp; } @@ -936,33 +986,30 @@ static void build_round_stamp (float complex **pstamp, encompassing all our paths. */ -static void add_to_global_distortion_map (float complex *global_map, - const cairo_rectangle_int_t *global_map_extent, - const dt_liquify_warp_t *warp, - const float complex *stamp, - const cairo_rectangle_int_t *stamp_extent) +static void add_to_global_distortion_map(float complex *global_map, const cairo_rectangle_int_t *global_map_extent, + const dt_liquify_warp_t *warp, const float complex *stamp, + const cairo_rectangle_int_t *stamp_extent) { cairo_rectangle_int_t mmext = *stamp_extent; - mmext.x += (int) round (creal (warp->point)); - mmext.y += (int) round (cimag (warp->point)); + mmext.x += (int)round(creal(warp->point)); + mmext.y += (int)round(cimag(warp->point)); cairo_rectangle_int_t cmmext = mmext; - cairo_region_t *mmreg = cairo_region_create_rectangle (&mmext); - cairo_region_intersect_rectangle (mmreg, global_map_extent); - cairo_region_get_extents (mmreg, &cmmext); - free (mmreg); + cairo_region_t *mmreg = cairo_region_create_rectangle(&mmext); + cairo_region_intersect_rectangle(mmreg, global_map_extent); + cairo_region_get_extents(mmreg, &cmmext); + free(mmreg); - #ifdef _OPENMP - #pragma omp parallel for schedule (static) default (shared) - #endif +#ifdef _OPENMP +#pragma omp parallel for schedule(static) default(shared) +#endif - for (int y = cmmext.y; y < cmmext.y + cmmext.height; y++) + for(int y = cmmext.y; y < cmmext.y + cmmext.height; y++) { const float complex *srcrow = stamp + ((y - mmext.y) * mmext.width); - float complex *destrow = global_map + - ((y - global_map_extent->y) * global_map_extent->width); + float complex *destrow = global_map + ((y - global_map_extent->y) * global_map_extent->width); - for (int x = cmmext.x; x < cmmext.x + cmmext.width; x++) + for(int x = cmmext.x; x < cmmext.x + cmmext.width; x++) { destrow[x - global_map_extent->x] -= srcrow[x - mmext.x]; } @@ -976,49 +1023,36 @@ static void add_to_global_distortion_map (float complex *global_map, device coords. */ -static void apply_global_distortion_map (struct dt_iop_module_t *module, - dt_dev_pixelpipe_iop_t *piece, - const float *in, - float *out, - const dt_iop_roi_t *roi_in, - const dt_iop_roi_t *roi_out, - const float complex *map, - const cairo_rectangle_int_t *extent) +static void apply_global_distortion_map(struct dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, + const float *in, float *out, const dt_iop_roi_t *roi_in, + const dt_iop_roi_t *roi_out, const float complex *map, + const cairo_rectangle_int_t *extent) { const int ch = piece->colors; const int ch_width = ch * roi_in->width; - const struct dt_interpolation * const interpolation = - dt_interpolation_new (DT_INTERPOLATION_USERPREF); + const struct dt_interpolation *const interpolation = dt_interpolation_new(DT_INTERPOLATION_USERPREF); - #ifdef _OPENMP - #pragma omp parallel for schedule (static) default (shared) - #endif +#ifdef _OPENMP +#pragma omp parallel for schedule(static) default(shared) +#endif - for (int y = extent->y; y < extent->y + extent->height; y++) + for(int y = extent->y; y < extent->y + extent->height; y++) { // point inside roi_out ? - if (y >= roi_out->y && y < roi_out->y + roi_out->height) + if(y >= roi_out->y && y < roi_out->y + roi_out->height) { const float complex *row = map + (y - extent->y) * extent->width; - float* out_sample = out + ((y - roi_out->y) * roi_out->width + - extent->x - roi_out->x) * ch; - for (int x = extent->x; x < extent->x + extent->width; x++) + float *out_sample = out + ((y - roi_out->y) * roi_out->width + extent->x - roi_out->x) * ch; + for(int x = extent->x; x < extent->x + extent->width; x++) { - if ( - // point inside roi_out ? - (x >= roi_out->x && x < roi_out->x + roi_out->width) && - // point actually warped ? - (*row != 0)) + if( + // point inside roi_out ? + (x >= roi_out->x && x < roi_out->x + roi_out->width) && + // point actually warped ? + (*row != 0)) { - dt_interpolation_compute_pixel4c ( - interpolation, - in, - out_sample, - x + creal (*row) - roi_in->x, - y + cimag (*row) - roi_in->y, - roi_in->width, - roi_in->height, - ch_width); + dt_interpolation_compute_pixel4c(interpolation, in, out_sample, x + creal(*row) - roi_in->x, + y + cimag(*row) - roi_in->y, roi_in->width, roi_in->height, ch_width); } ++row; out_sample += ch; @@ -1029,68 +1063,65 @@ static void apply_global_distortion_map (struct dt_iop_module_t *module, // calculate the map extent. -static void _get_map_extent (const dt_iop_roi_t *roi_out, - GList *interpolated, - cairo_rectangle_int_t *map_extent) +static void _get_map_extent(const dt_iop_roi_t *roi_out, GList *interpolated, cairo_rectangle_int_t *map_extent) { const cairo_rectangle_int_t roi_out_rect = { roi_out->x, roi_out->y, roi_out->width, roi_out->height }; - cairo_region_t *roi_out_region = cairo_region_create_rectangle (&roi_out_rect); - cairo_region_t *map_region = cairo_region_create (); + cairo_region_t *roi_out_region = cairo_region_create_rectangle(&roi_out_rect); + cairo_region_t *map_region = cairo_region_create(); - for (GList *i = interpolated; i != NULL; i = i->next) + for(GList *i = interpolated; i != NULL; i = i->next) { - const dt_liquify_warp_t *warp = ((dt_liquify_warp_t *) i->data); + const dt_liquify_warp_t *warp = ((dt_liquify_warp_t *)i->data); cairo_rectangle_int_t r; - compute_round_stamp_extent (&r, warp); + compute_round_stamp_extent(&r, warp); // add extent if not entirely outside the roi - if (cairo_region_contains_rectangle (roi_out_region, &r) != CAIRO_REGION_OVERLAP_OUT) + if(cairo_region_contains_rectangle(roi_out_region, &r) != CAIRO_REGION_OVERLAP_OUT) { - cairo_region_union_rectangle (map_region, &r); + cairo_region_union_rectangle(map_region, &r); } } // return the paths and the extent of all paths - cairo_region_get_extents (map_region, map_extent); - cairo_region_destroy (map_region); - cairo_region_destroy (roi_out_region); + cairo_region_get_extents(map_region, map_extent); + cairo_region_destroy(map_region); + cairo_region_destroy(roi_out_region); } -static float complex *create_global_distortion_map (const cairo_rectangle_int_t *map_extent, - GList *interpolated, - gboolean inverted) +static float complex *create_global_distortion_map(const cairo_rectangle_int_t *map_extent, GList *interpolated, + gboolean inverted) { // allocate distortion map big enough to contain all paths const int mapsize = map_extent->width * map_extent->height; - float complex * map = dt_alloc_align (16, mapsize * sizeof (float complex)); - memset (map, 0, mapsize * sizeof (float complex)); + float complex *map = dt_alloc_align(16, mapsize * sizeof(float complex)); + memset(map, 0, mapsize * sizeof(float complex)); // build map - for (GList *i = interpolated; i != NULL; i = i->next) + for(GList *i = interpolated; i != NULL; i = i->next) { - const dt_liquify_warp_t *warp = ((dt_liquify_warp_t *) i->data); + const dt_liquify_warp_t *warp = ((dt_liquify_warp_t *)i->data); float complex *stamp = NULL; cairo_rectangle_int_t r; - build_round_stamp (&stamp, &r, warp); - add_to_global_distortion_map (map, map_extent, warp, stamp, &r); - free ((void *) stamp); + build_round_stamp(&stamp, &r, warp); + add_to_global_distortion_map(map, map_extent, warp, stamp, &r); + free((void *)stamp); } - if (inverted) + if(inverted) { - float complex * const imap = dt_alloc_align (16, mapsize * sizeof (float complex)); - memset (imap, 0, mapsize * sizeof (float complex)); + float complex *const imap = dt_alloc_align(16, mapsize * sizeof(float complex)); + memset(imap, 0, mapsize * sizeof(float complex)); - // copy map into imap (inverted map). - // imap [ n + dx(map[n]) , n + dy(map[n]) ] = -map[n] +// copy map into imap (inverted map). +// imap [ n + dx(map[n]) , n + dy(map[n]) ] = -map[n] - #ifdef _OPENMP - #pragma omp parallel for schedule (static) default (shared) - #endif +#ifdef _OPENMP +#pragma omp parallel for schedule(static) default(shared) +#endif - for (int y = 0; y < map_extent->height; y++) + for(int y = 0; y < map_extent->height; y++) { const float complex *row = map + y * map_extent->width; - for (int x = 0; x < map_extent->width; x++) + for(int x = 0; x < map_extent->width; x++) { const float complex d = *(row + x); // compute new position (nx,ny) given the displacement d @@ -1098,35 +1129,36 @@ static float complex *create_global_distortion_map (const cairo_rectangle_int_t const int ny = y + (int)cimag(d); // if the point falls into the extent, set it - if (nx>0 && nx<map_extent->width && ny>0 && ny<map_extent->height) + if(nx > 0 && nx < map_extent->width && ny > 0 && ny < map_extent->height) imap[nx + ny * map_extent->width] = -d; } } - dt_free_align ((void *) map); + dt_free_align((void *)map); - // now just do a pass to avoid gap with a displacement of zero, note that we do not need high - // precision here as the inverted distortion mask is only used to compute a final displacement - // of points. +// now just do a pass to avoid gap with a displacement of zero, note that we do not need high +// precision here as the inverted distortion mask is only used to compute a final displacement +// of points. - #ifdef _OPENMP - #pragma omp parallel for schedule (dynamic) default (shared) - #endif +#ifdef _OPENMP +#pragma omp parallel for schedule(dynamic) default(shared) +#endif - for (int y = 0; y < map_extent->height; y++) + for(int y = 0; y < map_extent->height; y++) { float complex *row = imap + y * map_extent->width; float complex last[2] = { 0, 0 }; - for (int x = 0; x < map_extent->width / 2 + 1; x++) + for(int x = 0; x < map_extent->width / 2 + 1; x++) { float complex *cl = row + x; float complex *cr = row + map_extent->width - x; - if (x!=0) + if(x != 0) { - if (*cl == 0) *cl = last[0]; - if (*cr == 0) *cr = last[1]; + if(*cl == 0) *cl = last[0]; + if(*cr == 0) *cr = last[1]; } - last[0] = *cl; last[1] = *cr; + last[0] = *cl; + last[1] = *cr; } } @@ -1136,44 +1168,38 @@ static float complex *create_global_distortion_map (const cairo_rectangle_int_t return map; } -static float complex *build_global_distortion_map (struct dt_iop_module_t *module, - const dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, - const dt_iop_roi_t *roi_out, - cairo_rectangle_int_t *map_extent) +static float complex *build_global_distortion_map(struct dt_iop_module_t *module, + const dt_dev_pixelpipe_iop_t *piece, const dt_iop_roi_t *roi_in, + const dt_iop_roi_t *roi_out, cairo_rectangle_int_t *map_extent) { // copy params dt_iop_liquify_params_t copy_params; memcpy(&copy_params, (dt_iop_liquify_params_t *)piece->data, sizeof(dt_iop_liquify_params_t)); - distort_paths_raw_to_piece (module, piece->pipe, roi_in->scale, &copy_params); + distort_paths_raw_to_piece(module, piece->pipe, roi_in->scale, &copy_params); - GList *interpolated = interpolate_paths (&copy_params); + GList *interpolated = interpolate_paths(&copy_params); - _get_map_extent (roi_out, interpolated, map_extent); + _get_map_extent(roi_out, interpolated, map_extent); float complex *map = create_global_distortion_map(map_extent, interpolated, FALSE); - g_list_free_full (interpolated, free); + g_list_free_full(interpolated, free); return map; } // 1st pass: how large would the output be, given this input roi? // this is always called with the full buffer before processing. -void modify_roi_out (struct dt_iop_module_t *module, - struct dt_dev_pixelpipe_iop_t *piece, - dt_iop_roi_t *roi_out, - const dt_iop_roi_t *roi_in) +void modify_roi_out(struct dt_iop_module_t *module, struct dt_dev_pixelpipe_iop_t *piece, dt_iop_roi_t *roi_out, + const dt_iop_roi_t *roi_in) { // output is same size as input *roi_out = *roi_in; } // 2nd pass: which roi would this operation need as input to fill the given output region? -void modify_roi_in (struct dt_iop_module_t *module, - struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_out, - dt_iop_roi_t *roi_in) +void modify_roi_in(struct dt_iop_module_t *module, struct dt_dev_pixelpipe_iop_t *piece, + const dt_iop_roi_t *roi_out, dt_iop_roi_t *roi_in) { // Because we move pixels, and we may have to sample a pixel from // outside roi_in, we need to expand roi_in to contain all our @@ -1183,98 +1209,93 @@ void modify_roi_in (struct dt_iop_module_t *module, // copy params dt_iop_liquify_params_t copy_params; - memcpy(&copy_params, (dt_iop_liquify_params_t*)piece->data, sizeof(dt_iop_liquify_params_t)); + memcpy(&copy_params, (dt_iop_liquify_params_t *)piece->data, sizeof(dt_iop_liquify_params_t)); - distort_paths_raw_to_piece (module, piece->pipe, roi_in->scale, &copy_params); + distort_paths_raw_to_piece(module, piece->pipe, roi_in->scale, &copy_params); - cairo_rectangle_int_t pipe_rect = { - 0, - 0, - lroundf((double)piece->buf_in.width * roi_in->scale), - lroundf((double)piece->buf_in.height * roi_in->scale) - }; + cairo_rectangle_int_t pipe_rect = { 0, 0, lroundf((double)piece->buf_in.width * roi_in->scale), + lroundf((double)piece->buf_in.height * roi_in->scale) }; - cairo_rectangle_int_t roi_in_rect = { - roi_in->x, - roi_in->y, - roi_in->width, - roi_in->height - }; - cairo_region_t *roi_in_region = cairo_region_create_rectangle (&roi_in_rect); + cairo_rectangle_int_t roi_in_rect = { roi_in->x, roi_in->y, roi_in->width, roi_in->height }; + cairo_region_t *roi_in_region = cairo_region_create_rectangle(&roi_in_rect); // get extent of all paths - GList *interpolated = interpolate_paths (&copy_params); + GList *interpolated = interpolate_paths(&copy_params); cairo_rectangle_int_t extent; - _get_map_extent (roi_out, interpolated, &extent); + _get_map_extent(roi_out, interpolated, &extent); // (eventually) extend roi_in - cairo_region_union_rectangle (roi_in_region, &extent); + cairo_region_union_rectangle(roi_in_region, &extent); // and clamp to pipe extent - cairo_region_intersect_rectangle (roi_in_region, &pipe_rect); + cairo_region_intersect_rectangle(roi_in_region, &pipe_rect); // write new extent to roi_in - cairo_region_get_extents (roi_in_region, &roi_in_rect); + cairo_region_get_extents(roi_in_region, &roi_in_rect); roi_in->x = roi_in_rect.x; roi_in->y = roi_in_rect.y; - roi_in->width = roi_in_rect.width; + roi_in->width = roi_in_rect.width; roi_in->height = roi_in_rect.height; // cleanup - cairo_region_destroy (roi_in_region); - g_list_free_full (interpolated, free); + cairo_region_destroy(roi_in_region); + g_list_free_full(interpolated, free); } -static int _distort_xtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, float *points, size_t points_count, gboolean inverted) +static int _distort_xtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, float *points, + size_t points_count, gboolean inverted) { const float scale = piece->iscale; // compute the extent of all points (all computations are done in RAW coordinate) - float xmin=FLT_MAX, xmax=FLT_MIN, ymin=FLT_MAX, ymax=FLT_MIN; + float xmin = FLT_MAX, xmax = FLT_MIN, ymin = FLT_MAX, ymax = FLT_MIN; for(size_t i = 0; i < points_count * 2; i += 2) { const float x = points[i] * scale; const float y = points[i + 1] * scale; - xmin = fmin (xmin, x); - xmax = fmax (xmax, x); - ymin = fmin (ymin, y); - ymax = fmax (ymax, y); + xmin = fmin(xmin, x); + xmax = fmax(xmax, x); + ymin = fmin(ymin, y); + ymax = fmax(ymax, y); } - cairo_rectangle_int_t extent = { .x = (int)(xmin - .5), .y = (int)(ymin - .5), - .width = (int)(xmax - xmin + 2.5), .height = (int)(ymax - ymin + 2.5) }; + cairo_rectangle_int_t extent = {.x = (int)(xmin - .5), + .y = (int)(ymin - .5), + .width = (int)(xmax - xmin + 2.5), + .height = (int)(ymax - ymin + 2.5) }; - if (extent.width != 0 && extent.height != 0) + if(extent.width != 0 && extent.height != 0) { // create the distortion map for this extent - GList *interpolated = interpolate_paths ((dt_iop_liquify_params_t *)piece->data); + GList *interpolated = interpolate_paths((dt_iop_liquify_params_t *)piece->data); // we need to adjust the extent to be the union enclosing all the points (currently in extent) and // the warps that are in (possibly partly) in this same region. - dt_iop_roi_t roi_in = { .x = extent.x, .y = extent.y, .width = extent.width, .height = extent.height }; - _get_map_extent (&roi_in, interpolated, &extent); + dt_iop_roi_t roi_in = {.x = extent.x, .y = extent.y, .width = extent.width, .height = extent.height }; + _get_map_extent(&roi_in, interpolated, &extent); - float complex *map = create_global_distortion_map (&extent, interpolated, inverted); - g_list_free_full (interpolated, free); + float complex *map = create_global_distortion_map(&extent, interpolated, inverted); + g_list_free_full(interpolated, free); - if (map == NULL) return 0; + if(map == NULL) return 0; - const int map_size = extent.width * extent.height; + const int map_size = extent.width * extent.height; const int x_last = extent.x + extent.width; const int y_last = extent.y + extent.height; - // apply distortion to all points (this is a simple displacement given by a vector at this same point in the map) + // apply distortion to all points (this is a simple displacement given by a vector at this same point in the + // map) for(size_t i = 0; i < points_count; i++) { - float *px = &points[i*2]; - float *py = &points[i*2+1]; + float *px = &points[i * 2]; + float *py = &points[i * 2 + 1]; const float x = *px * scale; const float y = *py * scale; const int map_offset = ((int)(x - 0.5) - extent.x) + ((int)(y - 0.5) - extent.y) * extent.width; - if (x >= extent.x && x < x_last && y >= extent.y && y < y_last && map_offset >= 0 && map_offset < map_size) + if(x >= extent.x && x < x_last && y >= extent.y && y < y_last && map_offset >= 0 && map_offset < map_size) { const float complex dist = map[map_offset] / scale; *px += creal(dist); @@ -1282,7 +1303,7 @@ static int _distort_xtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *pi } } - dt_free_align ((void *) map); + dt_free_align((void *)map); } return 1; @@ -1298,39 +1319,38 @@ int distort_backtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, return _distort_xtransform(self, piece, points, points_count, FALSE); } -void process(struct dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, const void *const in, - void *const out, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) +void process(struct dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, const void *const in, void *const out, + const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) { // 1. copy the whole image (we'll change only a small part of it) const int ch = piece->colors; - assert (ch == 4); + assert(ch == 4); #ifdef _OPENMP #pragma omp parallel for schedule(static) default(none) #endif - for (int i = 0; i < roi_out->height; i++) + for(int i = 0; i < roi_out->height; i++) { - float *destrow = (float *)out + (size_t) ch * i * roi_out->width; - const float *srcrow = (float *)in + (size_t) ch * (roi_in->width * (i + roi_out->y - roi_in->y) + - roi_out->x - roi_in->x); + float *destrow = (float *)out + (size_t)ch * i * roi_out->width; + const float *srcrow = (float *)in + + (size_t)ch * (roi_in->width * (i + roi_out->y - roi_in->y) + roi_out->x - roi_in->x); - memcpy (destrow, srcrow, sizeof (float) * ch * roi_out->width); + memcpy(destrow, srcrow, sizeof(float) * ch * roi_out->width); } // 2. build the distortion map cairo_rectangle_int_t map_extent; - float complex *map = build_global_distortion_map (module, piece, roi_in, roi_out, &map_extent); - if (map == NULL) - return; + float complex *map = build_global_distortion_map(module, piece, roi_in, roi_out, &map_extent); + if(map == NULL) return; // 3. apply the map - if (map_extent.width != 0 && map_extent.height != 0) - apply_global_distortion_map (module, piece, in, out, roi_in, roi_out, map, &map_extent); + if(map_extent.width != 0 && map_extent.height != 0) + apply_global_distortion_map(module, piece, in, out, roi_in, roi_out, map, &map_extent); - dt_free_align ((void *) map); + dt_free_align((void *)map); } #ifdef HAVE_OPENCL @@ -1339,31 +1359,27 @@ void process(struct dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, cons static float lanczos(const float a, const float x) { - if (fabs (x) >= a) return 0.0f; - if (fabs (x) < CL_FLT_EPSILON) return 1.0f; + if(fabs(x) >= a) return 0.0f; + if(fabs(x) < CL_FLT_EPSILON) return 1.0f; - return - (a * sinf (M_PI * x) * sinf (M_PI * x / a)) - / - (M_PI * M_PI * x * x); + return (a * sinf(M_PI * x) * sinf(M_PI * x / a)) / (M_PI * M_PI * x * x); } // compute bicubic kernel. See: https://en.wikipedia.org/wiki/Bicubic_interpolation#Bicubic_convolution_algorithm static float bicubic(const float a, const float x) { - const float absx = fabs (x); + const float absx = fabs(x); - if (absx <= 1) - return ((a + 2) * absx - (a + 3)) * absx * absx + 1; + if(absx <= 1) return ((a + 2) * absx - (a + 3)) * absx * absx + 1; - if (absx < 2) - return ((a * absx - 5 * a) * absx + 8 * a) * absx - 4 * a; + if(absx < 2) return ((a * absx - 5 * a) * absx + 8 * a) * absx - 4 * a; return 0.0f; } -typedef struct { +typedef struct +{ int size; int resolution; } dt_liquify_kernel_descriptor_t; @@ -1371,109 +1387,96 @@ typedef struct { typedef cl_mem cl_mem_t; typedef cl_int cl_int_t; -static cl_int_t apply_global_distortion_map_cl (struct dt_iop_module_t *module, - dt_dev_pixelpipe_iop_t *piece, - const cl_mem_t dev_in, - const cl_mem_t dev_out, - const dt_iop_roi_t *roi_in, - const dt_iop_roi_t *roi_out, - const float complex *map, - const cairo_rectangle_int_t *map_extent) +static cl_int_t apply_global_distortion_map_cl(struct dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, + const cl_mem_t dev_in, const cl_mem_t dev_out, + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, + const float complex *map, const cairo_rectangle_int_t *map_extent) { cl_int_t err = CL_MEM_OBJECT_ALLOCATION_FAILURE; - dt_iop_liquify_global_data_t *gd = (dt_iop_liquify_global_data_t *) module->data; + dt_iop_liquify_global_data_t *gd = (dt_iop_liquify_global_data_t *)module->data; const int devid = piece->pipe->devid; - const struct dt_interpolation* interpolation = dt_interpolation_new (DT_INTERPOLATION_USERPREF); - dt_liquify_kernel_descriptor_t kdesc = { .size = 0, .resolution = 100 }; + const struct dt_interpolation *interpolation = dt_interpolation_new(DT_INTERPOLATION_USERPREF); + dt_liquify_kernel_descriptor_t kdesc = {.size = 0, .resolution = 100 }; float *k = NULL; - switch (interpolation->id) - { - case DT_INTERPOLATION_BILINEAR: - kdesc.size = 1; - kdesc.resolution = 1; - k = malloc (2 * sizeof (float)); - k[0] = 1.0f; - k[1] = 0.0f; - break; - case DT_INTERPOLATION_BICUBIC: - kdesc.size = 2; - k = malloc ((kdesc.size * kdesc.resolution + 1) * sizeof (float)); - for (int i = 0; i <= kdesc.size * kdesc.resolution; ++i) - k[i] = bicubic (0.5f, (float) i / kdesc.resolution); - break; - case DT_INTERPOLATION_LANCZOS2: - kdesc.size = 2; - k = malloc ((kdesc.size * kdesc.resolution + 1) * sizeof (float)); - for (int i = 0; i <= kdesc.size * kdesc.resolution; ++i) - k[i] = lanczos (2, (float) i / kdesc.resolution); - break; - case DT_INTERPOLATION_LANCZOS3: - kdesc.size = 3; - k = malloc ((kdesc.size * kdesc.resolution + 1) * sizeof (float)); - for (int i = 0; i <= kdesc.size * kdesc.resolution; ++i) - k[i] = lanczos (3, (float) i / kdesc.resolution); - break; - default: - return FALSE; + switch(interpolation->id) + { + case DT_INTERPOLATION_BILINEAR: + kdesc.size = 1; + kdesc.resolution = 1; + k = malloc(2 * sizeof(float)); + k[0] = 1.0f; + k[1] = 0.0f; + break; + case DT_INTERPOLATION_BICUBIC: + kdesc.size = 2; + k = malloc((kdesc.size * kdesc.resolution + 1) * sizeof(float)); + for(int i = 0; i <= kdesc.size * kdesc.resolution; ++i) k[i] = bicubic(0.5f, (float)i / kdesc.resolution); + break; + case DT_INTERPOLATION_LANCZOS2: + kdesc.size = 2; + k = malloc((kdesc.size * kdesc.resolution + 1) * sizeof(float)); + for(int i = 0; i <= kdesc.size * kdesc.resolution; ++i) k[i] = lanczos(2, (float)i / kdesc.resolution); + break; + case DT_INTERPOLATION_LANCZOS3: + kdesc.size = 3; + k = malloc((kdesc.size * kdesc.resolution + 1) * sizeof(float)); + for(int i = 0; i <= kdesc.size * kdesc.resolution; ++i) k[i] = lanczos(3, (float)i / kdesc.resolution); + break; + default: + return FALSE; } - cl_mem_t dev_roi_in = dt_opencl_copy_host_to_device_constant ( - devid, sizeof (dt_iop_roi_t), (void *) roi_in); + cl_mem_t dev_roi_in = dt_opencl_copy_host_to_device_constant(devid, sizeof(dt_iop_roi_t), (void *)roi_in); - cl_mem_t dev_roi_out = dt_opencl_copy_host_to_device_constant ( - devid, sizeof (dt_iop_roi_t), (void *) roi_out); + cl_mem_t dev_roi_out = dt_opencl_copy_host_to_device_constant(devid, sizeof(dt_iop_roi_t), (void *)roi_out); - cl_mem_t dev_map = dt_opencl_copy_host_to_device_constant ( - devid, map_extent->width * map_extent->height * sizeof (float complex), (void *) map); + cl_mem_t dev_map = dt_opencl_copy_host_to_device_constant( + devid, map_extent->width * map_extent->height * sizeof(float complex), (void *)map); - cl_mem_t dev_map_extent = dt_opencl_copy_host_to_device_constant ( - devid, sizeof (cairo_rectangle_int_t), (void *) map_extent); + cl_mem_t dev_map_extent + = dt_opencl_copy_host_to_device_constant(devid, sizeof(cairo_rectangle_int_t), (void *)map_extent); - cl_mem_t dev_kdesc = dt_opencl_copy_host_to_device_constant ( - devid, sizeof (dt_liquify_kernel_descriptor_t), (void *) &kdesc); + cl_mem_t dev_kdesc + = dt_opencl_copy_host_to_device_constant(devid, sizeof(dt_liquify_kernel_descriptor_t), (void *)&kdesc); - cl_mem_t dev_kernel = dt_opencl_copy_host_to_device_constant ( - devid, (kdesc.size * kdesc.resolution + 1) * sizeof (float), (void *) k); + cl_mem_t dev_kernel = dt_opencl_copy_host_to_device_constant( + devid, (kdesc.size * kdesc.resolution + 1) * sizeof(float), (void *)k); - if (dev_roi_in == NULL || dev_roi_out == NULL || dev_map == NULL || dev_map_extent == NULL - || dev_kdesc == NULL || dev_kernel == NULL) + if(dev_roi_in == NULL || dev_roi_out == NULL || dev_map == NULL || dev_map_extent == NULL || dev_kdesc == NULL + || dev_kernel == NULL) goto error; - dt_opencl_set_kernel_arg (devid, gd->warp_kernel, 0, sizeof (cl_mem), &dev_in); - dt_opencl_set_kernel_arg (devid, gd->warp_kernel, 1, sizeof (cl_mem), &dev_out); - dt_opencl_set_kernel_arg (devid, gd->warp_kernel, 2, sizeof (cl_mem), &dev_roi_in); - dt_opencl_set_kernel_arg (devid, gd->warp_kernel, 3, sizeof (cl_mem), &dev_roi_out); - dt_opencl_set_kernel_arg (devid, gd->warp_kernel, 4, sizeof (cl_mem), &dev_map); - dt_opencl_set_kernel_arg (devid, gd->warp_kernel, 5, sizeof (cl_mem), &dev_map_extent); + dt_opencl_set_kernel_arg(devid, gd->warp_kernel, 0, sizeof(cl_mem), &dev_in); + dt_opencl_set_kernel_arg(devid, gd->warp_kernel, 1, sizeof(cl_mem), &dev_out); + dt_opencl_set_kernel_arg(devid, gd->warp_kernel, 2, sizeof(cl_mem), &dev_roi_in); + dt_opencl_set_kernel_arg(devid, gd->warp_kernel, 3, sizeof(cl_mem), &dev_roi_out); + dt_opencl_set_kernel_arg(devid, gd->warp_kernel, 4, sizeof(cl_mem), &dev_map); + dt_opencl_set_kernel_arg(devid, gd->warp_kernel, 5, sizeof(cl_mem), &dev_map_extent); - dt_opencl_set_kernel_arg (devid, gd->warp_kernel, 6, sizeof (cl_mem), &dev_kdesc); - dt_opencl_set_kernel_arg (devid, gd->warp_kernel, 7, sizeof (cl_mem), &dev_kernel); + dt_opencl_set_kernel_arg(devid, gd->warp_kernel, 6, sizeof(cl_mem), &dev_kdesc); + dt_opencl_set_kernel_arg(devid, gd->warp_kernel, 7, sizeof(cl_mem), &dev_kernel); - const size_t sizes[] = { ROUNDUPWD (map_extent->width), ROUNDUPHT (map_extent->height) }; - err = dt_opencl_enqueue_kernel_2d (devid, gd->warp_kernel, sizes); + const size_t sizes[] = { ROUNDUPWD(map_extent->width), ROUNDUPHT(map_extent->height) }; + err = dt_opencl_enqueue_kernel_2d(devid, gd->warp_kernel, sizes); error: - dt_opencl_release_mem_object (dev_kernel); - dt_opencl_release_mem_object (dev_kdesc); - dt_opencl_release_mem_object (dev_map_extent); - dt_opencl_release_mem_object (dev_map); - dt_opencl_release_mem_object (dev_roi_out); - dt_opencl_release_mem_object (dev_roi_in); - if (k ) free (k); + dt_opencl_release_mem_object(dev_kernel); + dt_opencl_release_mem_object(dev_kdesc); + dt_opencl_release_mem_object(dev_map_extent); + dt_opencl_release_mem_object(dev_map); + dt_opencl_release_mem_object(dev_roi_out); + dt_opencl_release_mem_object(dev_roi_in); + if(k) free(k); return err; } -int process_cl (struct dt_iop_module_t *module, - dt_dev_pixelpipe_iop_t *piece, - const cl_mem_t dev_in, - const cl_mem_t dev_out, - const dt_iop_roi_t *roi_in, - const dt_iop_roi_t *roi_out) +int process_cl(struct dt_iop_module_t *module, dt_dev_pixelpipe_iop_t *piece, const cl_mem_t dev_in, + const cl_mem_t dev_out, const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out) { cl_int_t err = -999; const int devid = piece->pipe->devid; @@ -1481,646 +1484,639 @@ int process_cl (struct dt_iop_module_t *module, // 1. copy the whole image (we'll change only a small part of it) { - size_t src[] = { roi_out->x - roi_in->x, roi_out->y - roi_in->y, 0 }; - size_t dest[] = { 0, 0, 0 }; + size_t src[] = { roi_out->x - roi_in->x, roi_out->y - roi_in->y, 0 }; + size_t dest[] = { 0, 0, 0 }; size_t extent[] = { roi_out->width, roi_out->height, 1 }; - err = dt_opencl_enqueue_copy_image (devid, dev_in, dev_out, src, dest, extent); - if (err != CL_SUCCESS) goto error; + err = dt_opencl_enqueue_copy_image(devid, dev_in, dev_out, src, dest, extent); + if(err != CL_SUCCESS) goto error; } // 2. build the distortion map cairo_rectangle_int_t map_extent; - const float complex *map = build_global_distortion_map (module, piece, roi_in, roi_out, &map_extent); - if (map == NULL) - return TRUE; + const float complex *map = build_global_distortion_map(module, piece, roi_in, roi_out, &map_extent); + if(map == NULL) return TRUE; // 3. apply the map - if (map_extent.width != 0 && map_extent.height != 0) - err = apply_global_distortion_map_cl (module, piece, dev_in, dev_out, roi_in, roi_out, map, &map_extent); + if(map_extent.width != 0 && map_extent.height != 0) + err = apply_global_distortion_map_cl(module, piece, dev_in, dev_out, roi_in, roi_out, map, &map_extent); - dt_free_align ((void *) map); - if (err != CL_SUCCESS) goto error; + dt_free_align((void *)map); + if(err != CL_SUCCESS) goto error; return TRUE; error: - dt_print (DT_DEBUG_OPENCL, "[opencl_liquify] couldn't enqueue kernel! %d\n", err); + dt_print(DT_DEBUG_OPENCL, "[opencl_liquify] couldn't enqueue kernel! %d\n", err); return FALSE; } #endif -void init_global (dt_iop_module_so_t *module) +void init_global(dt_iop_module_so_t *module) { // called once at startup const int program = 17; // from programs.conf - dt_iop_liquify_global_data_t *gd = (dt_iop_liquify_global_data_t *) malloc (sizeof (dt_iop_liquify_global_data_t)); + dt_iop_liquify_global_data_t *gd = (dt_iop_liquify_global_data_t *)malloc(sizeof(dt_iop_liquify_global_data_t)); module->data = gd; - gd->warp_kernel = dt_opencl_create_kernel (program, "warp_kernel"); + gd->warp_kernel = dt_opencl_create_kernel(program, "warp_kernel"); } -void cleanup_global (dt_iop_module_so_t *module) +void cleanup_global(dt_iop_module_so_t *module) { // called once at shutdown - dt_iop_liquify_global_data_t *gd = (dt_iop_liquify_global_data_t *) module->data; - dt_opencl_free_kernel (gd->warp_kernel); - free (module->data); + dt_iop_liquify_global_data_t *gd = (dt_iop_liquify_global_data_t *)module->data; + dt_opencl_free_kernel(gd->warp_kernel); + free(module->data); module->data = NULL; } -void init (dt_iop_module_t *module) +void init(dt_iop_module_t *module) { // module is disabled by default module->default_enabled = 0; - module->priority = 220; // module order created by iop_dependencies.py, do not edit! + module->priority = 231; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_liquify_params_t); module->gui_data = NULL; // all allocated to 0, which is the default - module->params = calloc (1, module->params_size); - module->default_params = calloc (1, module->params_size); + module->params = calloc(1, module->params_size); + module->default_params = calloc(1, module->params_size); } -void cleanup (dt_iop_module_t *module) +void cleanup(dt_iop_module_t *module) { - free (module->params); + free(module->params); module->params = NULL; } -void init_pipe (struct dt_iop_module_t *module, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece) +void init_pipe(struct dt_iop_module_t *module, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece) { - piece->data = malloc (module->params_size); - module->commit_params (module, module->default_params, pipe, piece); + piece->data = malloc(module->params_size); + module->commit_params(module, module->default_params, pipe, piece); } -void cleanup_pipe (struct dt_iop_module_t *module, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece) +void cleanup_pipe(struct dt_iop_module_t *module, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece) { - free (piece->data); + free(piece->data); piece->data = NULL; } /* commit is the synch point between core and gui, so it copies params to pipe data. */ -void commit_params (struct dt_iop_module_t *module, - dt_iop_params_t *params, - dt_dev_pixelpipe_t *pipe, - dt_dev_pixelpipe_iop_t *piece) +void commit_params(struct dt_iop_module_t *module, dt_iop_params_t *params, dt_dev_pixelpipe_t *pipe, + dt_dev_pixelpipe_iop_t *piece) { - memcpy (piece->data, params, module->params_size); + memcpy(piece->data, params, module->params_size); } // calculate the dot product of 2 vectors. -static float cdot (const float complex p0, const float complex p1) +static float cdot(const float complex p0, const float complex p1) { #ifdef FP_FAST_FMA - return fma (creal (p0), creal (p1), cimag (p0) * cimag (p1)); + return fma(creal(p0), creal(p1), cimag(p0) * cimag(p1)); #else - return creal (p0) * creal (p1) + cimag (p0) * cimag (p1); + return creal(p0) * creal(p1) + cimag(p0) * cimag(p1); #endif } -static void draw_rectangle (cairo_t *cr, const float complex pt, const double theta, const double size) +static void draw_rectangle(cairo_t *cr, const float complex pt, const double theta, const double size) { - const double x = creal (pt), y = cimag (pt); - cairo_save (cr); - cairo_translate (cr, x, y); - cairo_rotate (cr, theta); - cairo_rectangle (cr, -size / 2.0, -size / 2.0, size, size); - cairo_restore (cr); + const double x = creal(pt), y = cimag(pt); + cairo_save(cr); + cairo_translate(cr, x, y); + cairo_rotate(cr, theta); + cairo_rectangle(cr, -size / 2.0, -size / 2.0, size, size); + cairo_restore(cr); } -static void draw_triangle (cairo_t *cr, const float complex pt, const double theta, const double size) +static void draw_triangle(cairo_t *cr, const float complex pt, const double theta, const double size) { - const double x = creal (pt), y = cimag (pt); - cairo_save (cr); - cairo_translate (cr, x, y); - cairo_rotate (cr, theta); - cairo_move_to (cr, -size, -size / 2.0); - cairo_line_to (cr, 0, 0 ); - cairo_line_to (cr, -size, +size / 2.0); - cairo_close_path (cr); - cairo_restore (cr); + const double x = creal(pt), y = cimag(pt); + cairo_save(cr); + cairo_translate(cr, x, y); + cairo_rotate(cr, theta); + cairo_move_to(cr, -size, -size / 2.0); + cairo_line_to(cr, 0, 0); + cairo_line_to(cr, -size, +size / 2.0); + cairo_close_path(cr); + cairo_restore(cr); } -static void draw_circle (cairo_t *cr, const float complex pt, const double diameter) +static void draw_circle(cairo_t *cr, const float complex pt, const double diameter) { - const double x = creal (pt), y = cimag (pt); - cairo_save (cr); - cairo_new_sub_path (cr); - cairo_arc (cr, x, y, diameter / 2.0, 0, 2 * M_PI); - cairo_restore (cr); + const double x = creal(pt), y = cimag(pt); + cairo_save(cr); + cairo_new_sub_path(cr); + cairo_arc(cr, x, y, diameter / 2.0, 0, 2 * M_PI); + cairo_restore(cr); } -static void set_source_rgba (cairo_t *cr, dt_liquify_rgba_t rgba) +static void set_source_rgba(cairo_t *cr, dt_liquify_rgba_t rgba) { - cairo_set_source_rgba (cr, rgba.red, rgba.green, rgba.blue, rgba.alpha); + cairo_set_source_rgba(cr, rgba.red, rgba.green, rgba.blue, rgba.alpha); } -static float get_ui_width (const float scale, const dt_liquify_ui_width_enum_t w) +static float get_ui_width(const float scale, const dt_liquify_ui_width_enum_t w) { - assert (w >= 0 && w < DT_LIQUIFY_UI_WIDTH_LAST); - return scale * DT_PIXEL_APPLY_DPI (dt_liquify_ui_widths[w]); + assert(w >= 0 && w < DT_LIQUIFY_UI_WIDTH_LAST); + return scale * DT_PIXEL_APPLY_DPI(dt_liquify_ui_widths[w]); } -#define GET_UI_WIDTH(a) (get_ui_width (scale, DT_LIQUIFY_UI_WIDTH_##a)) +#define GET_UI_WIDTH(a) (get_ui_width(scale, DT_LIQUIFY_UI_WIDTH_##a)) -static void set_line_width (cairo_t *cr, double scale, dt_liquify_ui_width_enum_t w) +static void set_line_width(cairo_t *cr, double scale, dt_liquify_ui_width_enum_t w) { - const double width = get_ui_width (scale, w); - cairo_set_line_width (cr, width); + const double width = get_ui_width(scale, w); + cairo_set_line_width(cr, width); } -static gboolean detect_drag (const dt_iop_liquify_gui_data_t *g, const double scale, const float complex pt) +static gboolean detect_drag(const dt_iop_liquify_gui_data_t *g, const double scale, const float complex pt) { // g->last_button1_pressed_pos is valid only while BUTTON1 is down - return g->last_button1_pressed_pos != -1.0 && - cabs (pt - g->last_button1_pressed_pos) >= GET_UI_WIDTH (MIN_DRAG); + return g->last_button1_pressed_pos != -1.0 && cabs(pt - g->last_button1_pressed_pos) >= GET_UI_WIDTH(MIN_DRAG); } -static void update_warp_count (const dt_iop_liquify_gui_data_t *g) +static void update_warp_count(const dt_iop_liquify_gui_data_t *g) { guint warp = 0, node = 0; - for (int k=0; k<MAX_NODES; k++) - if (g->params.nodes[k].header.type == DT_LIQUIFY_PATH_INVALIDATED) + for(int k = 0; k < MAX_NODES; k++) + if(g->params.nodes[k].header.type == DT_LIQUIFY_PATH_INVALIDATED) break; else { node++; - if (g->params.nodes[k].header.type == DT_LIQUIFY_PATH_MOVE_TO_V1) - warp++; + if(g->params.nodes[k].header.type == DT_LIQUIFY_PATH_MOVE_TO_V1) warp++; } char str[10]; - snprintf (str, sizeof (str), "%d|%d", warp, node); - gtk_label_set_text (g->label, str); + snprintf(str, sizeof(str), "%d|%d", warp, node); + gtk_label_set_text(g->label, str); } -static GList *interpolate_paths (dt_iop_liquify_params_t *p) +static GList *interpolate_paths(dt_iop_liquify_params_t *p) { GList *l = NULL; - for (int k=0; k<MAX_NODES; k++) + for(int k = 0; k < MAX_NODES; k++) { const dt_liquify_path_data_t *data = &p->nodes[k]; - if (data->header.type == DT_LIQUIFY_PATH_INVALIDATED) - break; + if(data->header.type == DT_LIQUIFY_PATH_INVALIDATED) break; const float complex *p2 = &data->warp.point; const dt_liquify_warp_t *warp2 = &data->warp; - if (data->header.type == DT_LIQUIFY_PATH_MOVE_TO_V1) + if(data->header.type == DT_LIQUIFY_PATH_MOVE_TO_V1) { - if (data->header.next == -1) + if(data->header.next == -1) { - dt_liquify_warp_t *w = malloc (sizeof (dt_liquify_warp_t)); + dt_liquify_warp_t *w = malloc(sizeof(dt_liquify_warp_t)); *w = *warp2; - l = g_list_append (l, w); + l = g_list_append(l, w); } continue; } - const dt_liquify_path_data_t *prev = node_prev (p, data); + const dt_liquify_path_data_t *prev = node_prev(p, data); const dt_liquify_warp_t *warp1 = &prev->warp; const float complex *p1 = &prev->warp.point; - if (data->header.type == DT_LIQUIFY_PATH_LINE_TO_V1) + if(data->header.type == DT_LIQUIFY_PATH_LINE_TO_V1) { - const float total_length = cabs (*p1 - *p2); + const float total_length = cabs(*p1 - *p2); float arc_length = 0.0; - while (arc_length < total_length) + while(arc_length < total_length) { - dt_liquify_warp_t *w = malloc (sizeof (dt_liquify_warp_t)); + dt_liquify_warp_t *w = malloc(sizeof(dt_liquify_warp_t)); const float t = arc_length / total_length; - const float complex pt = cmix (*p1, *p2, t); - mix_warps (w, warp1, warp2, pt, t); + const float complex pt = cmix(*p1, *p2, t); + mix_warps(w, warp1, warp2, pt, t); w->status = DT_LIQUIFY_STATUS_INTERPOLATED; - arc_length += cabs (w->radius - w->point) * STAMP_RELOCATION; - l = g_list_append (l, w); + arc_length += cabs(w->radius - w->point) * STAMP_RELOCATION; + l = g_list_append(l, w); } continue; } - if (data->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) + if(data->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) { - float complex *buffer = malloc (INTERPOLATION_POINTS * sizeof (float complex)); - interpolate_cubic_bezier (*p1, - data->node.ctrl1, - data->node.ctrl2, - *p2, - buffer, - INTERPOLATION_POINTS); - const float total_length = get_arc_length (buffer, INTERPOLATION_POINTS); + float complex *buffer = malloc(INTERPOLATION_POINTS * sizeof(float complex)); + interpolate_cubic_bezier(*p1, data->node.ctrl1, data->node.ctrl2, *p2, buffer, INTERPOLATION_POINTS); + const float total_length = get_arc_length(buffer, INTERPOLATION_POINTS); float arc_length = 0.0; restart_cookie_t restart = { 1, 0.0 }; - while (arc_length < total_length) + while(arc_length < total_length) { - dt_liquify_warp_t *w = malloc (sizeof (dt_liquify_warp_t)); - const float complex pt = point_at_arc_length (buffer, INTERPOLATION_POINTS, arc_length, &restart); - mix_warps (w, warp1, warp2, pt, arc_length / total_length); + dt_liquify_warp_t *w = malloc(sizeof(dt_liquify_warp_t)); + const float complex pt = point_at_arc_length(buffer, INTERPOLATION_POINTS, arc_length, &restart); + mix_warps(w, warp1, warp2, pt, arc_length / total_length); w->status = DT_LIQUIFY_STATUS_INTERPOLATED; - arc_length += cabs (w->radius - w->point) * STAMP_RELOCATION; - l = g_list_append (l, w); + arc_length += cabs(w->radius - w->point) * STAMP_RELOCATION; + l = g_list_append(l, w); } - free ((void *) buffer); + free((void *)buffer); continue; } } return l; } -#define STROKE_TEST \ - if (do_hit_test) { if (cairo_in_stroke (cr, creal (*pt), cimag (*pt))) goto hit; continue; } +#define STROKE_TEST \ + if(do_hit_test) \ + { \ + if(cairo_in_stroke(cr, creal(*pt), cimag(*pt))) goto hit; \ + continue; \ + } -#define FILL_TEST \ - if (do_hit_test) { if (cairo_in_fill (cr, creal (*pt), cimag (*pt)) || cairo_in_stroke (cr, creal (*pt), cimag (*pt))) goto hit; continue; } +#define FILL_TEST \ + if(do_hit_test) \ + { \ + if(cairo_in_fill(cr, creal(*pt), cimag(*pt)) || cairo_in_stroke(cr, creal(*pt), cimag(*pt))) goto hit; \ + continue; \ + } -#define FG_COLOR set_source_rgba (cr, fg_color); -#define BG_COLOR set_source_rgba (cr, bg_color); -#define VERYTHINLINE set_line_width (cr, scale, DT_LIQUIFY_UI_WIDTH_THINLINE / 2.0); -#define THINLINE set_line_width (cr, scale, DT_LIQUIFY_UI_WIDTH_THINLINE); -#define THICKLINE set_line_width (cr, scale, DT_LIQUIFY_UI_WIDTH_THICKLINE); +#define FG_COLOR set_source_rgba(cr, fg_color); +#define BG_COLOR set_source_rgba(cr, bg_color); +#define VERYTHINLINE set_line_width(cr, scale, DT_LIQUIFY_UI_WIDTH_THINLINE / 2.0); +#define THINLINE set_line_width(cr, scale, DT_LIQUIFY_UI_WIDTH_THINLINE); +#define THICKLINE set_line_width(cr, scale, DT_LIQUIFY_UI_WIDTH_THICKLINE); -static dt_liquify_hit_t _draw_paths (dt_iop_module_t *module, - cairo_t *cr, - const float scale, - dt_iop_liquify_params_t *p, - GList *layers, - const float complex *pt) +static dt_liquify_hit_t _draw_paths(dt_iop_module_t *module, cairo_t *cr, const float scale, + dt_iop_liquify_params_t *p, GList *layers, const float complex *pt) { dt_liquify_hit_t hit = NOWHERE; const gboolean do_hit_test = pt != NULL; - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); - GList *interpolated = do_hit_test ? NULL : interpolate_paths (p); + GList *interpolated = do_hit_test ? NULL : interpolate_paths(p); - for (GList *l = layers; l != NULL; l = l->next) + for(GList *l = layers; l != NULL; l = l->next) { - const dt_liquify_layer_enum_t layer = (dt_liquify_layer_enum_t) GPOINTER_TO_INT (l->data); + const dt_liquify_layer_enum_t layer = (dt_liquify_layer_enum_t)GPOINTER_TO_INT(l->data); dt_liquify_rgba_t fg_color = dt_liquify_layers[layer].fg; dt_liquify_rgba_t bg_color = dt_liquify_layers[layer].bg; - if (do_hit_test && ((dt_liquify_layers[layer].flags & DT_LIQUIFY_LAYER_FLAG_HIT_TEST) == 0)) - continue; + if(do_hit_test && ((dt_liquify_layers[layer].flags & DT_LIQUIFY_LAYER_FLAG_HIT_TEST) == 0)) continue; hit.layer = layer; - if (dt_liquify_layers[layer].opacity < 1.0) - cairo_push_group (cr); + if(dt_liquify_layers[layer].opacity < 1.0) cairo_push_group(cr); - for (int k=0; k<MAX_NODES; k++) + for(int k = 0; k < MAX_NODES; k++) { dt_liquify_path_data_t *data = &p->nodes[k]; - const dt_liquify_path_data_t *prev = node_prev (p, data); + const dt_liquify_path_data_t *prev = node_prev(p, data); - if (p->nodes[k].header.type == DT_LIQUIFY_PATH_INVALIDATED) - break; + if(p->nodes[k].header.type == DT_LIQUIFY_PATH_INVALIDATED) break; hit.elem = data; - if ((dt_liquify_layers[layer].flags & DT_LIQUIFY_LAYER_FLAG_NODE_SELECTED) - && !data->header.selected) + if((dt_liquify_layers[layer].flags & DT_LIQUIFY_LAYER_FLAG_NODE_SELECTED) && !data->header.selected) continue; - if ((dt_liquify_layers[layer].flags & DT_LIQUIFY_LAYER_FLAG_PREV_SELECTED) - && (!prev || !prev->header.selected)) + if((dt_liquify_layers[layer].flags & DT_LIQUIFY_LAYER_FLAG_PREV_SELECTED) + && (!prev || !prev->header.selected)) continue; fg_color = dt_liquify_layers[layer].fg; bg_color = dt_liquify_layers[layer].bg; - if (data->header.selected == layer) - fg_color = DT_LIQUIFY_COLOR_SELECTED; + if(data->header.selected == layer) fg_color = DT_LIQUIFY_COLOR_SELECTED; - if (data->header.hovered == dt_liquify_layers[layer].hover_master) - fg_color = DT_LIQUIFY_COLOR_HOVER; + if(data->header.hovered == dt_liquify_layers[layer].hover_master) fg_color = DT_LIQUIFY_COLOR_HOVER; - cairo_new_path (cr); + cairo_new_path(cr); const float complex point = data->warp.point; - if (data->header.type == DT_LIQUIFY_PATH_MOVE_TO_V1) - cairo_move_to (cr, creal (point), cimag (point)); + if(data->header.type == DT_LIQUIFY_PATH_MOVE_TO_V1) cairo_move_to(cr, creal(point), cimag(point)); - if (layer == DT_LIQUIFY_LAYER_RADIUS) + if(layer == DT_LIQUIFY_LAYER_RADIUS) { - for (GList *i = interpolated; i != NULL; i = i->next) + for(GList *i = interpolated; i != NULL; i = i->next) { - const dt_liquify_warp_t *pwarp = ((dt_liquify_warp_t *) i->data); - draw_circle (cr, pwarp->point, 2.0f * cabs (pwarp->radius - pwarp->point)); + const dt_liquify_warp_t *pwarp = ((dt_liquify_warp_t *)i->data); + draw_circle(cr, pwarp->point, 2.0f * cabs(pwarp->radius - pwarp->point)); } - draw_circle (cr, point, 2.0f * cabs (data->warp.radius - data->warp.point)); + draw_circle(cr, point, 2.0f * cabs(data->warp.radius - data->warp.point)); FG_COLOR; - cairo_fill (cr); + cairo_fill(cr); } - if (layer == DT_LIQUIFY_LAYER_HARDNESS1) + if(layer == DT_LIQUIFY_LAYER_HARDNESS1) { - for (GList *i = interpolated; i != NULL; i = i->next) + for(GList *i = interpolated; i != NULL; i = i->next) { - const dt_liquify_warp_t *pwarp = ((dt_liquify_warp_t *) i->data); - draw_circle (cr, pwarp->point, 2.0f * cabs (pwarp->radius - pwarp->point) * pwarp->control1); + const dt_liquify_warp_t *pwarp = ((dt_liquify_warp_t *)i->data); + draw_circle(cr, pwarp->point, 2.0f * cabs(pwarp->radius - pwarp->point) * pwarp->control1); } FG_COLOR; - cairo_fill (cr); + cairo_fill(cr); } - if (layer == DT_LIQUIFY_LAYER_HARDNESS2) + if(layer == DT_LIQUIFY_LAYER_HARDNESS2) { - for (GList *i = interpolated; i != NULL; i = i->next) + for(GList *i = interpolated; i != NULL; i = i->next) { - const dt_liquify_warp_t *pwarp = ((dt_liquify_warp_t *) i->data); - draw_circle (cr, pwarp->point, 2.0f * cabs (pwarp->radius - pwarp->point) * pwarp->control2); + const dt_liquify_warp_t *pwarp = ((dt_liquify_warp_t *)i->data); + draw_circle(cr, pwarp->point, 2.0f * cabs(pwarp->radius - pwarp->point) * pwarp->control2); } FG_COLOR; - cairo_fill (cr); + cairo_fill(cr); } - if (layer == DT_LIQUIFY_LAYER_WARPS) + if(layer == DT_LIQUIFY_LAYER_WARPS) { - VERYTHINLINE; FG_COLOR; - for (GList *i = interpolated; i != NULL; i = i->next) + VERYTHINLINE; + FG_COLOR; + for(GList *i = interpolated; i != NULL; i = i->next) { - const dt_liquify_warp_t *pwarp = ((dt_liquify_warp_t *) i->data); - cairo_move_to (cr, creal (pwarp->point), cimag (pwarp->point)); - cairo_line_to (cr, creal (pwarp->strength), cimag (pwarp->strength)); + const dt_liquify_warp_t *pwarp = ((dt_liquify_warp_t *)i->data); + cairo_move_to(cr, creal(pwarp->point), cimag(pwarp->point)); + cairo_line_to(cr, creal(pwarp->strength), cimag(pwarp->strength)); } - cairo_stroke (cr); + cairo_stroke(cr); - for (GList *i = interpolated; i != NULL; i = i->next) + for(GList *i = interpolated; i != NULL; i = i->next) { - const dt_liquify_warp_t *pwarp = ((dt_liquify_warp_t *) i->data); - const float rot = get_rot (pwarp->type); - draw_circle (cr, pwarp->point, GET_UI_WIDTH (GIZMO_SMALL)); - draw_triangle (cr, pwarp->strength, - carg (pwarp->strength - pwarp->point) + rot, - GET_UI_WIDTH (GIZMO_SMALL) / 3.0); + const dt_liquify_warp_t *pwarp = ((dt_liquify_warp_t *)i->data); + const float rot = get_rot(pwarp->type); + draw_circle(cr, pwarp->point, GET_UI_WIDTH(GIZMO_SMALL)); + draw_triangle(cr, pwarp->strength, carg(pwarp->strength - pwarp->point) + rot, + GET_UI_WIDTH(GIZMO_SMALL) / 3.0); } BG_COLOR; - cairo_fill_preserve (cr); + cairo_fill_preserve(cr); FG_COLOR; - cairo_stroke (cr); + cairo_stroke(cr); } - if (layer == DT_LIQUIFY_LAYER_PATH) + if(layer == DT_LIQUIFY_LAYER_PATH) { - if ((data->header.type == DT_LIQUIFY_PATH_LINE_TO_V1) - || (data->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1)) + if((data->header.type == DT_LIQUIFY_PATH_LINE_TO_V1) || (data->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1)) { - assert (prev); - cairo_move_to (cr, creal (prev->warp.point), cimag (prev->warp.point)); - if (data->header.type == DT_LIQUIFY_PATH_LINE_TO_V1) - cairo_line_to (cr, creal (point), cimag (point)); - if (data->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) { - cairo_curve_to (cr, creal (data->node.ctrl1), cimag (data->node.ctrl1), - creal (data->node.ctrl2), cimag (data->node.ctrl2), - creal (point), cimag (point)); + assert(prev); + cairo_move_to(cr, creal(prev->warp.point), cimag(prev->warp.point)); + if(data->header.type == DT_LIQUIFY_PATH_LINE_TO_V1) cairo_line_to(cr, creal(point), cimag(point)); + if(data->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) + { + cairo_curve_to(cr, creal(data->node.ctrl1), cimag(data->node.ctrl1), creal(data->node.ctrl2), + cimag(data->node.ctrl2), creal(point), cimag(point)); } - THICKLINE; FG_COLOR; + THICKLINE; + FG_COLOR; STROKE_TEST; - cairo_stroke_preserve (cr); - THINLINE; BG_COLOR; - cairo_stroke (cr); + cairo_stroke_preserve(cr); + THINLINE; + BG_COLOR; + cairo_stroke(cr); } } - if (layer == DT_LIQUIFY_LAYER_CENTERPOINT) + if(layer == DT_LIQUIFY_LAYER_CENTERPOINT) { - if (data->header.type == DT_LIQUIFY_PATH_MOVE_TO_V1 - || data->header.type == DT_LIQUIFY_PATH_LINE_TO_V1 - || data->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) + if(data->header.type == DT_LIQUIFY_PATH_MOVE_TO_V1 || data->header.type == DT_LIQUIFY_PATH_LINE_TO_V1 + || data->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) { - const float w = GET_UI_WIDTH (GIZMO); - switch (data->header.node_type) + const float w = GET_UI_WIDTH(GIZMO); + switch(data->header.node_type) { - case DT_LIQUIFY_NODE_TYPE_CUSP: - draw_triangle (cr, point - w / 2.0 * I, -M_PI / 2.0, w); - break; - case DT_LIQUIFY_NODE_TYPE_SMOOTH: - draw_rectangle (cr, point, M_PI / 4.0, w); - break; - case DT_LIQUIFY_NODE_TYPE_SYMMETRICAL: - draw_rectangle (cr, point, 0, w); - break; - case DT_LIQUIFY_NODE_TYPE_AUTOSMOOTH: - draw_circle (cr, point, w); - break; - default: - break; + case DT_LIQUIFY_NODE_TYPE_CUSP: + draw_triangle(cr, point - w / 2.0 * I, -M_PI / 2.0, w); + break; + case DT_LIQUIFY_NODE_TYPE_SMOOTH: + draw_rectangle(cr, point, M_PI / 4.0, w); + break; + case DT_LIQUIFY_NODE_TYPE_SYMMETRICAL: + draw_rectangle(cr, point, 0, w); + break; + case DT_LIQUIFY_NODE_TYPE_AUTOSMOOTH: + draw_circle(cr, point, w); + break; + default: + break; } - THINLINE; BG_COLOR; + THINLINE; + BG_COLOR; FILL_TEST; - cairo_fill_preserve (cr); + cairo_fill_preserve(cr); FG_COLOR; - cairo_stroke (cr); + cairo_stroke(cr); } } - if (data->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) + if(data->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) { - if (layer == DT_LIQUIFY_LAYER_CTRLPOINT1_HANDLE && - !(prev && prev->header.node_type == DT_LIQUIFY_NODE_TYPE_AUTOSMOOTH)) + if(layer == DT_LIQUIFY_LAYER_CTRLPOINT1_HANDLE + && !(prev && prev->header.node_type == DT_LIQUIFY_NODE_TYPE_AUTOSMOOTH)) { - THINLINE; FG_COLOR; - cairo_move_to (cr, creal (prev->warp.point), cimag (prev->warp.point)); - cairo_line_to (cr, creal (data->node.ctrl1), cimag (data->node.ctrl1)); - cairo_stroke (cr); + THINLINE; + FG_COLOR; + cairo_move_to(cr, creal(prev->warp.point), cimag(prev->warp.point)); + cairo_line_to(cr, creal(data->node.ctrl1), cimag(data->node.ctrl1)); + cairo_stroke(cr); } - if (layer == DT_LIQUIFY_LAYER_CTRLPOINT2_HANDLE && - data->header.node_type != DT_LIQUIFY_NODE_TYPE_AUTOSMOOTH) + if(layer == DT_LIQUIFY_LAYER_CTRLPOINT2_HANDLE && data->header.node_type != DT_LIQUIFY_NODE_TYPE_AUTOSMOOTH) { - THINLINE; FG_COLOR; - cairo_move_to (cr, creal (data->warp.point), cimag (data->warp.point)); - cairo_line_to (cr, creal (data->node.ctrl2), cimag (data->node.ctrl2)); - cairo_stroke (cr); + THINLINE; + FG_COLOR; + cairo_move_to(cr, creal(data->warp.point), cimag(data->warp.point)); + cairo_line_to(cr, creal(data->node.ctrl2), cimag(data->node.ctrl2)); + cairo_stroke(cr); } - if (layer == DT_LIQUIFY_LAYER_CTRLPOINT1 && - !(prev && prev->header.node_type == DT_LIQUIFY_NODE_TYPE_AUTOSMOOTH)) + if(layer == DT_LIQUIFY_LAYER_CTRLPOINT1 + && !(prev && prev->header.node_type == DT_LIQUIFY_NODE_TYPE_AUTOSMOOTH)) { - THINLINE; BG_COLOR; - draw_circle (cr, data->node.ctrl1, GET_UI_WIDTH (GIZMO_SMALL)); + THINLINE; + BG_COLOR; + draw_circle(cr, data->node.ctrl1, GET_UI_WIDTH(GIZMO_SMALL)); FILL_TEST; - cairo_fill_preserve (cr); + cairo_fill_preserve(cr); FG_COLOR; - cairo_stroke (cr); + cairo_stroke(cr); } - if (layer == DT_LIQUIFY_LAYER_CTRLPOINT2 && - data->header.node_type != DT_LIQUIFY_NODE_TYPE_AUTOSMOOTH) + if(layer == DT_LIQUIFY_LAYER_CTRLPOINT2 && data->header.node_type != DT_LIQUIFY_NODE_TYPE_AUTOSMOOTH) { - THINLINE; BG_COLOR; - draw_circle (cr, data->node.ctrl2, GET_UI_WIDTH (GIZMO_SMALL)); + THINLINE; + BG_COLOR; + draw_circle(cr, data->node.ctrl2, GET_UI_WIDTH(GIZMO_SMALL)); FILL_TEST; - cairo_fill_preserve (cr); + cairo_fill_preserve(cr); FG_COLOR; - cairo_stroke (cr); + cairo_stroke(cr); } } - const dt_liquify_warp_t *warp = &data->warp; + const dt_liquify_warp_t *warp = &data->warp; - if (layer == DT_LIQUIFY_LAYER_RADIUSPOINT_HANDLE) + if(layer == DT_LIQUIFY_LAYER_RADIUSPOINT_HANDLE) { - draw_circle (cr, point, 2.0 * cabs (warp->radius - point)); - THICKLINE; FG_COLOR; - cairo_stroke_preserve (cr); - THINLINE; BG_COLOR; - cairo_stroke (cr); + draw_circle(cr, point, 2.0 * cabs(warp->radius - point)); + THICKLINE; + FG_COLOR; + cairo_stroke_preserve(cr); + THINLINE; + BG_COLOR; + cairo_stroke(cr); } - if (layer == DT_LIQUIFY_LAYER_RADIUSPOINT) + if(layer == DT_LIQUIFY_LAYER_RADIUSPOINT) { - THINLINE; BG_COLOR; - draw_circle (cr, warp->radius, GET_UI_WIDTH (GIZMO_SMALL)); + THINLINE; + BG_COLOR; + draw_circle(cr, warp->radius, GET_UI_WIDTH(GIZMO_SMALL)); FILL_TEST; - cairo_fill_preserve (cr); + cairo_fill_preserve(cr); FG_COLOR; - cairo_stroke (cr); + cairo_stroke(cr); } - if (layer == DT_LIQUIFY_LAYER_HARDNESSPOINT1_HANDLE) + if(layer == DT_LIQUIFY_LAYER_HARDNESSPOINT1_HANDLE) { - draw_circle (cr, point, 2.0 * cabs (warp->radius - point) * warp->control1); - THICKLINE; FG_COLOR; - cairo_stroke_preserve (cr); - THINLINE; BG_COLOR; - cairo_stroke (cr); + draw_circle(cr, point, 2.0 * cabs(warp->radius - point) * warp->control1); + THICKLINE; + FG_COLOR; + cairo_stroke_preserve(cr); + THINLINE; + BG_COLOR; + cairo_stroke(cr); } - if (layer == DT_LIQUIFY_LAYER_HARDNESSPOINT2_HANDLE) + if(layer == DT_LIQUIFY_LAYER_HARDNESSPOINT2_HANDLE) { - draw_circle (cr, point, 2.0 * cabs (warp->radius - point) * warp->control2); - THICKLINE; FG_COLOR; - cairo_stroke_preserve (cr); - THINLINE; BG_COLOR; - cairo_stroke (cr); + draw_circle(cr, point, 2.0 * cabs(warp->radius - point) * warp->control2); + THICKLINE; + FG_COLOR; + cairo_stroke_preserve(cr); + THINLINE; + BG_COLOR; + cairo_stroke(cr); } - if (layer == DT_LIQUIFY_LAYER_HARDNESSPOINT1) + if(layer == DT_LIQUIFY_LAYER_HARDNESSPOINT1) { - draw_triangle (cr, cmix (point, warp->radius, warp->control1), - carg (warp->radius - point), - GET_UI_WIDTH (GIZMO_SMALL)); - THINLINE; BG_COLOR; + draw_triangle(cr, cmix(point, warp->radius, warp->control1), carg(warp->radius - point), + GET_UI_WIDTH(GIZMO_SMALL)); + THINLINE; + BG_COLOR; FILL_TEST; - cairo_fill_preserve (cr); + cairo_fill_preserve(cr); FG_COLOR; - cairo_stroke (cr); + cairo_stroke(cr); } - if (layer == DT_LIQUIFY_LAYER_HARDNESSPOINT2) + if(layer == DT_LIQUIFY_LAYER_HARDNESSPOINT2) { - draw_triangle (cr, cmix (point, warp->radius, warp->control2), - carg (- (warp->radius - point)), - GET_UI_WIDTH (GIZMO_SMALL)); - THINLINE; BG_COLOR; + draw_triangle(cr, cmix(point, warp->radius, warp->control2), carg(-(warp->radius - point)), + GET_UI_WIDTH(GIZMO_SMALL)); + THINLINE; + BG_COLOR; FILL_TEST; - cairo_fill_preserve (cr); + cairo_fill_preserve(cr); FG_COLOR; - cairo_stroke (cr); + cairo_stroke(cr); } - if (layer == DT_LIQUIFY_LAYER_STRENGTHPOINT_HANDLE) + if(layer == DT_LIQUIFY_LAYER_STRENGTHPOINT_HANDLE) { - cairo_move_to (cr, creal (point), cimag (point)); - if (warp->type == DT_LIQUIFY_WARP_TYPE_LINEAR) + cairo_move_to(cr, creal(point), cimag(point)); + if(warp->type == DT_LIQUIFY_WARP_TYPE_LINEAR) { - float complex pt = cmix (point, warp->strength, 1.0 - 0.5 * - (GET_UI_WIDTH (GIZMO_SMALL) / - cabs (warp->strength - point))); - cairo_line_to (cr, creal (pt), cimag (pt)); + float complex pt = cmix(point, warp->strength, + 1.0 - 0.5 * (GET_UI_WIDTH(GIZMO_SMALL) / cabs(warp->strength - point))); + cairo_line_to(cr, creal(pt), cimag(pt)); } else - draw_circle (cr, point, 2.0 * cabs (warp->strength - warp->point)); - THICKLINE; FG_COLOR; - cairo_stroke_preserve (cr); - THINLINE; BG_COLOR; - cairo_stroke (cr); + draw_circle(cr, point, 2.0 * cabs(warp->strength - warp->point)); + THICKLINE; + FG_COLOR; + cairo_stroke_preserve(cr); + THINLINE; + BG_COLOR; + cairo_stroke(cr); } - if (layer == DT_LIQUIFY_LAYER_STRENGTHPOINT) + if(layer == DT_LIQUIFY_LAYER_STRENGTHPOINT) { - const float rot = get_rot (warp->type); - draw_triangle (cr, warp->strength, - carg (warp->strength - warp->point) + rot, - GET_UI_WIDTH (GIZMO_SMALL)); - THINLINE; BG_COLOR; + const float rot = get_rot(warp->type); + draw_triangle(cr, warp->strength, carg(warp->strength - warp->point) + rot, GET_UI_WIDTH(GIZMO_SMALL)); + THINLINE; + BG_COLOR; FILL_TEST; - cairo_fill_preserve (cr); + cairo_fill_preserve(cr); FG_COLOR; - cairo_stroke (cr); + cairo_stroke(cr); } } - if (dt_liquify_layers[layer].opacity < 1.0) + if(dt_liquify_layers[layer].opacity < 1.0) { - cairo_pop_group_to_source (cr); - cairo_paint_with_alpha (cr, dt_liquify_layers[layer].opacity); + cairo_pop_group_to_source(cr); + cairo_paint_with_alpha(cr, dt_liquify_layers[layer].opacity); } } - g_list_free_full (interpolated, free); + g_list_free_full(interpolated, free); return NOWHERE; hit: - g_list_free_full (interpolated, free); - cairo_new_path (cr); // otherwise a successful hit test would leave the path behind + g_list_free_full(interpolated, free); + cairo_new_path(cr); // otherwise a successful hit test would leave the path behind return hit; } -static void draw_paths (struct dt_iop_module_t *module, cairo_t *cr, float scale, dt_iop_liquify_params_t *params) +static void draw_paths(struct dt_iop_module_t *module, cairo_t *cr, float scale, dt_iop_liquify_params_t *params) { - const dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *) module->gui_data; + const dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *)module->gui_data; GList *layers = NULL; - for (dt_liquify_layer_enum_t layer = 0; layer < DT_LIQUIFY_LAYER_LAST; ++layer) - { - if (gtk_toggle_button_get_active (g->btn_point_tool) - && (dt_liquify_layers[layer].flags & DT_LIQUIFY_LAYER_FLAG_POINT_TOOL)) - layers = g_list_append (layers, GINT_TO_POINTER (layer)); - if (gtk_toggle_button_get_active (g->btn_line_tool) - && (dt_liquify_layers[layer].flags & DT_LIQUIFY_LAYER_FLAG_LINE_TOOL)) - layers = g_list_append (layers, GINT_TO_POINTER (layer)); - if (gtk_toggle_button_get_active (g->btn_curve_tool) - && (dt_liquify_layers[layer].flags & DT_LIQUIFY_LAYER_FLAG_CURVE_TOOL)) - layers = g_list_append (layers, GINT_TO_POINTER (layer)); - if (gtk_toggle_button_get_active (g->btn_node_tool) - && (dt_liquify_layers[layer].flags & DT_LIQUIFY_LAYER_FLAG_NODE_TOOL)) - layers = g_list_append (layers, GINT_TO_POINTER (layer)); + for(dt_liquify_layer_enum_t layer = 0; layer < DT_LIQUIFY_LAYER_LAST; ++layer) + { + if(gtk_toggle_button_get_active(g->btn_point_tool) + && (dt_liquify_layers[layer].flags & DT_LIQUIFY_LAYER_FLAG_POINT_TOOL)) + layers = g_list_append(layers, GINT_TO_POINTER(layer)); + if(gtk_toggle_button_get_active(g->btn_line_tool) + && (dt_liquify_layers[layer].flags & DT_LIQUIFY_LAYER_FLAG_LINE_TOOL)) + layers = g_list_append(layers, GINT_TO_POINTER(layer)); + if(gtk_toggle_button_get_active(g->btn_curve_tool) + && (dt_liquify_layers[layer].flags & DT_LIQUIFY_LAYER_FLAG_CURVE_TOOL)) + layers = g_list_append(layers, GINT_TO_POINTER(layer)); + if(gtk_toggle_button_get_active(g->btn_node_tool) + && (dt_liquify_layers[layer].flags & DT_LIQUIFY_LAYER_FLAG_NODE_TOOL)) + layers = g_list_append(layers, GINT_TO_POINTER(layer)); } - _draw_paths (module, cr, scale, params, layers, NULL); + _draw_paths(module, cr, scale, params, layers, NULL); - g_list_free (layers); + g_list_free(layers); } -static dt_liquify_hit_t hit_test_paths (struct dt_iop_module_t *module, - float scale, - cairo_t *cr, - dt_iop_liquify_params_t *params, - float complex pt) +static dt_liquify_hit_t hit_test_paths(struct dt_iop_module_t *module, float scale, cairo_t *cr, + dt_iop_liquify_params_t *params, float complex pt) { dt_liquify_hit_t hit = NOWHERE; GList *layers = NULL; - for (dt_liquify_layer_enum_t layer = 0; layer < DT_LIQUIFY_LAYER_LAST; ++layer) + for(dt_liquify_layer_enum_t layer = 0; layer < DT_LIQUIFY_LAYER_LAST; ++layer) { - if (dt_liquify_layers[layer].flags & DT_LIQUIFY_LAYER_FLAG_HIT_TEST) - layers = g_list_append (layers, GINT_TO_POINTER (layer)); + if(dt_liquify_layers[layer].flags & DT_LIQUIFY_LAYER_FLAG_HIT_TEST) + layers = g_list_append(layers, GINT_TO_POINTER(layer)); } - layers = g_list_reverse (layers); - hit = _draw_paths (module, cr, scale, params, layers, &pt); - g_list_free (layers); + layers = g_list_reverse(layers); + hit = _draw_paths(module, cr, scale, params, layers, &pt); + g_list_free(layers); return hit; } // split a cubic bezier at t into two cubic beziers. -static void casteljau (const float complex *p0, float complex *p1, float complex *p2, float complex *p3, const float t) +static void casteljau(const float complex *p0, float complex *p1, float complex *p2, float complex *p3, + const float t) { const float complex p01 = *p0 + (*p1 - *p0) * t; const float complex p12 = *p1 + (*p2 - *p1) * t; @@ -2146,27 +2142,19 @@ static void casteljau (const float complex *p0, float complex *p1, float complex http://tog.acm.org/resources/GraphicsGems/gems/NearestPoint.c */ -static float find_nearest_on_curve_t (const float complex p0, - const float complex p1, - const float complex p2, - const float complex p3, - const float complex x, - const int n) +static float find_nearest_on_curve_t(const float complex p0, const float complex p1, const float complex p2, + const float complex p3, const float complex x, const int n) { - float min_t = 0, min_dist = cabs (x - p0); + float min_t = 0, min_dist = cabs(x - p0); - for (int i = 0; i < n; i++) + for(int i = 0; i < n; i++) { const float t = (1.0 * i) / n; const float t1 = 1.0 - t; - const float complex ip = - t1 * t1 * t1 * p0 + - 3 * t1 * t1 * t * p1 + - 3 * t1 * t * t * p2 + - t * t * t * p3; - - const float dist = cabs (x - ip); - if (dist < min_dist) + const float complex ip = t1 * t1 * t1 * p0 + 3 * t1 * t1 * t * p1 + 3 * t1 * t * t * p2 + t * t * t * p3; + + const float dist = cabs(x - ip); + if(dist < min_dist) { min_dist = dist; min_t = t; @@ -2182,12 +2170,12 @@ static float find_nearest_on_curve_t (const float complex p0, to another arbitrary point. */ -static float find_nearest_on_line_t (const float complex p0, const float complex p1, const float complex x) +static float find_nearest_on_line_t(const float complex p0, const float complex p1, const float complex x) { // scalar projection - const float b = cabs (p1 - p0); // |b| - const float dotab = cdot (x - p0, p1 - p0); // |a| * |b| * cos(phi) - return dotab / (b * b); // |a| / |b| * cos(phi) + const float b = cabs(p1 - p0); // |b| + const float dotab = cdot(x - p0, p1 - p0); // |a| * |b| * cos(phi) + return dotab / (b * b); // |a| / |b| * cos(phi) } /** @@ -2244,83 +2232,110 @@ static float find_nearest_on_line_t (const float complex p0, const float complex * c2. (You may open your eyes again.) */ -static void smooth_path_linsys (size_t n, - const float complex *k, - float complex *c1, - float complex *c2, - const int *equation) +static void smooth_path_linsys(size_t n, const float complex *k, float complex *c1, float complex *c2, + const int *equation) { --n; - float *a = malloc (n * sizeof (float)); // subdiagonal - float *b = malloc (n * sizeof (float)); // main diagonal - float *c = malloc (n * sizeof (float)); // superdiagonal - float complex *d = malloc (n * sizeof (float complex)); // right hand side + float *a = malloc(n * sizeof(float)); // subdiagonal + float *b = malloc(n * sizeof(float)); // main diagonal + float *c = malloc(n * sizeof(float)); // superdiagonal + float complex *d = malloc(n * sizeof(float complex)); // right hand side // Build the tridiagonal matrix. - for (int i = 0; i < n; i++) + for(int i = 0; i < n; i++) { - switch (equation[i]) + switch(equation[i]) { - #define ABCD(A,B,C,D) { { a[i] = A; b[i] = B; c[i] = C; d[i] = D; continue; } } - case 1: ABCD (0, 2, 1, k[i] + 2 * k[i+1] ); break; - case 2: ABCD (1, 4, 1, 4 * k[i] + 2 * k[i+1] ); break; - case 3: ABCD (2, 7, 0, 8 * k[i] + k[i+1] ); break; - case 4: ABCD (0, 1, 0, c1[i] ); break; - case 5: ABCD (0, 1, 0, c1[i] ); break; - case 6: ABCD (1, 4, 0, 4 * k[i] + c2[i] ); break; - case 7: ABCD (0, 1, 0, c1[i] ); break; - case 8: ABCD (0, 3, 0, 2 * k[i] + k[i+1] ); break; - case 9: ABCD (0, 2, 0, k[i] + c2[i] ); break; - #undef ABCD +#define ABCD(A, B, C, D) \ + { \ + { \ + a[i] = A; \ + b[i] = B; \ + c[i] = C; \ + d[i] = D; \ + continue; \ + } \ + } + case 1: + ABCD(0, 2, 1, k[i] + 2 * k[i + 1]); + break; + case 2: + ABCD(1, 4, 1, 4 * k[i] + 2 * k[i + 1]); + break; + case 3: + ABCD(2, 7, 0, 8 * k[i] + k[i + 1]); + break; + case 4: + ABCD(0, 1, 0, c1[i]); + break; + case 5: + ABCD(0, 1, 0, c1[i]); + break; + case 6: + ABCD(1, 4, 0, 4 * k[i] + c2[i]); + break; + case 7: + ABCD(0, 1, 0, c1[i]); + break; + case 8: + ABCD(0, 3, 0, 2 * k[i] + k[i + 1]); + break; + case 9: + ABCD(0, 2, 0, k[i] + c2[i]); + break; +#undef ABCD } } // Solve with the Thomas algorithm to compute c1's. See: // http://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm - for (int i = 1; i < n; i++) + for(int i = 1; i < n; i++) { - const float m = a[i] / b[i-1]; - b[i] = b[i] - m * c[i-1]; - d[i] = d[i] - m * d[i-1]; + const float m = a[i] / b[i - 1]; + b[i] = b[i] - m * c[i - 1]; + d[i] = d[i] - m * d[i - 1]; } - c1[n-1] = d[n-1] / b[n-1]; - for (int i = n - 2; i >= 0; i--) - c1[i] = (d[i] - c[i] * c1[i+1]) / b[i]; + c1[n - 1] = d[n - 1] / b[n - 1]; + for(int i = n - 2; i >= 0; i--) c1[i] = (d[i] - c[i] * c1[i + 1]) / b[i]; // Now compute the c2's. - for (int i = 0; i < n; i++) + for(int i = 0; i < n; i++) { - switch (equation[i]) + switch(equation[i]) { - // keep end: c2 does not change - case 5: - case 6: - case 9: break; - - // straight end: put c2[i] halfway between c1[i] and k[i+1] - case 3: - case 7: - case 8: c2[i] = (c1[i] + k[i+1]) / 2; break; - - // smooth end: c2 and c1 are symmetrical around the knot - default: c2[i] = 2 * k[i+1] - c1[i+1]; + // keep end: c2 does not change + case 5: + case 6: + case 9: + break; + + // straight end: put c2[i] halfway between c1[i] and k[i+1] + case 3: + case 7: + case 8: + c2[i] = (c1[i] + k[i + 1]) / 2; + break; + + // smooth end: c2 and c1 are symmetrical around the knot + default: + c2[i] = 2 * k[i + 1] - c1[i + 1]; } } - free (a); - free (b); - free (c); - free (d); + free(a); + free(b); + free(c); + free(d); } static const int path_length(dt_iop_liquify_params_t *p, dt_liquify_path_data_t *n) { int count = 1; - while (n->header.next != -1) + while(n->header.next != -1) { count++; n = &p->nodes[n->header.next]; @@ -2328,48 +2343,45 @@ static const int path_length(dt_iop_liquify_params_t *p, dt_liquify_path_data_t return count; } -static void smooth_paths_linsys (dt_iop_liquify_params_t *params) +static void smooth_paths_linsys(dt_iop_liquify_params_t *params) { - for (int k=0; k<MAX_NODES; k++) + for(int k = 0; k < MAX_NODES; k++) { - if (params->nodes[k].header.type == DT_LIQUIFY_PATH_INVALIDATED) - break; + if(params->nodes[k].header.type == DT_LIQUIFY_PATH_INVALIDATED) break; - if (params->nodes[k].header.prev != -1) - continue; + if(params->nodes[k].header.prev != -1) continue; dt_liquify_path_data_t *node = &params->nodes[k]; - const size_t n = path_length (params, node); + const size_t n = path_length(params, node); - if (n < 2) - continue; + if(n < 2) continue; - float complex *pt = calloc (n, sizeof (float complex)); - float complex *c1 = calloc (n, sizeof (float complex)); - float complex *c2 = calloc (n, sizeof (float complex)); - int *eqn = calloc (n, sizeof (int)); + float complex *pt = calloc(n, sizeof(float complex)); + float complex *c1 = calloc(n, sizeof(float complex)); + float complex *c2 = calloc(n, sizeof(float complex)); + int *eqn = calloc(n, sizeof(int)); size_t idx = 0; - while (node) + while(node) { - const dt_liquify_path_data_t *d = (dt_liquify_path_data_t *) node; - const dt_liquify_path_data_t *p = node_prev (params, node); - const dt_liquify_path_data_t *n = node_next (params, node); - const dt_liquify_path_data_t *nn = n ? node_next (params, n) : NULL; + const dt_liquify_path_data_t *d = (dt_liquify_path_data_t *)node; + const dt_liquify_path_data_t *p = node_prev(params, node); + const dt_liquify_path_data_t *n = node_next(params, node); + const dt_liquify_path_data_t *nn = n ? node_next(params, n) : NULL; pt[idx] = node->warp.point; - if (d->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) + if(d->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) { - c1[idx-1] = d->node.ctrl1; - c2[idx-1] = d->node.ctrl2; + c1[idx - 1] = d->node.ctrl1; + c2[idx - 1] = d->node.ctrl2; } - const int autosmooth = d->header.node_type == DT_LIQUIFY_NODE_TYPE_AUTOSMOOTH; - const int next_autosmooth = n && n->header.node_type == DT_LIQUIFY_NODE_TYPE_AUTOSMOOTH; - const int firstseg = !p || d->header.type != DT_LIQUIFY_PATH_CURVE_TO_V1; - const int lastseg = !nn || nn->header.type != DT_LIQUIFY_PATH_CURVE_TO_V1; - const int lineseg = n && n->header.type == DT_LIQUIFY_PATH_LINE_TO_V1; + const int autosmooth = d->header.node_type == DT_LIQUIFY_NODE_TYPE_AUTOSMOOTH; + const int next_autosmooth = n && n->header.node_type == DT_LIQUIFY_NODE_TYPE_AUTOSMOOTH; + const int firstseg = !p || d->header.type != DT_LIQUIFY_PATH_CURVE_TO_V1; + const int lastseg = !nn || nn->header.type != DT_LIQUIFY_PATH_CURVE_TO_V1; + const int lineseg = n && n->header.type == DT_LIQUIFY_PATH_LINE_TO_V1; // Program the linear system with equations: // @@ -2385,33 +2397,45 @@ static void smooth_paths_linsys (dt_iop_liquify_params_t *params) // 8: straight straight (== line) // 9: straight keep - if (lineseg) eqn[idx] = 5; - else if (!autosmooth && !next_autosmooth) eqn[idx] = 5; - else if (firstseg && lastseg && !autosmooth && next_autosmooth) eqn[idx] = 7; - else if (firstseg && lastseg && autosmooth && next_autosmooth) eqn[idx] = 8; - else if (firstseg && lastseg && autosmooth && !next_autosmooth) eqn[idx] = 9; - else if (firstseg && autosmooth && !next_autosmooth) eqn[idx] = 5; - else if (firstseg && autosmooth) eqn[idx] = 1; - else if (lastseg && autosmooth && next_autosmooth) eqn[idx] = 3; - else if (lastseg && !autosmooth && next_autosmooth) eqn[idx] = 7; - else if (autosmooth && !next_autosmooth) eqn[idx] = 6; - else if (!autosmooth && next_autosmooth) eqn[idx] = 4; - else eqn[idx] = 2; + if(lineseg) + eqn[idx] = 5; + else if(!autosmooth && !next_autosmooth) + eqn[idx] = 5; + else if(firstseg && lastseg && !autosmooth && next_autosmooth) + eqn[idx] = 7; + else if(firstseg && lastseg && autosmooth && next_autosmooth) + eqn[idx] = 8; + else if(firstseg && lastseg && autosmooth && !next_autosmooth) + eqn[idx] = 9; + else if(firstseg && autosmooth && !next_autosmooth) + eqn[idx] = 5; + else if(firstseg && autosmooth) + eqn[idx] = 1; + else if(lastseg && autosmooth && next_autosmooth) + eqn[idx] = 3; + else if(lastseg && !autosmooth && next_autosmooth) + eqn[idx] = 7; + else if(autosmooth && !next_autosmooth) + eqn[idx] = 6; + else if(!autosmooth && next_autosmooth) + eqn[idx] = 4; + else + eqn[idx] = 2; ++idx; - node = node_next (params, node); + node = node_next(params, node); } - smooth_path_linsys (n, pt, c1, c2, eqn); + smooth_path_linsys(n, pt, c1, c2, eqn); // write calculated control points back to list structure node = &params->nodes[k]; node = node_next(params, node); idx = 0; - while (node) + while(node) { - dt_liquify_path_data_t *d = (dt_liquify_path_data_t *) node; - if (d->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) + dt_liquify_path_data_t *d = (dt_liquify_path_data_t *)node; + if(d->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) { d->node.ctrl1 = c1[idx]; d->node.ctrl2 = c2[idx]; @@ -2420,81 +2444,81 @@ static void smooth_paths_linsys (dt_iop_liquify_params_t *params) node = node_next(params, node); } - free (pt); - free (c1); - free (c2); - free (eqn); + free(pt); + free(c1); + free(c2); + free(eqn); } } -static dt_liquify_path_data_t *find_hovered (dt_iop_liquify_params_t *p) +static dt_liquify_path_data_t *find_hovered(dt_iop_liquify_params_t *p) { - for (int k=0; k<MAX_NODES; k++) - if (p->nodes[k].header.type == DT_LIQUIFY_PATH_INVALIDATED) + for(int k = 0; k < MAX_NODES; k++) + if(p->nodes[k].header.type == DT_LIQUIFY_PATH_INVALIDATED) break; - else if (p->nodes[k].header.hovered) + else if(p->nodes[k].header.hovered) return &p->nodes[k]; return NULL; } -static void init_warp (dt_liquify_warp_t *warp, float complex point) +static void init_warp(dt_liquify_warp_t *warp, float complex point) { - warp->type = DT_LIQUIFY_WARP_TYPE_LINEAR; - warp->point = point; - warp->radius = point; + warp->type = DT_LIQUIFY_WARP_TYPE_LINEAR; + warp->point = point; + warp->radius = point; warp->strength = point; warp->control1 = 0.5; warp->control2 = 0.75; - warp->status = DT_LIQUIFY_STATUS_NONE; + warp->status = DT_LIQUIFY_STATUS_NONE; } -static dt_liquify_path_data_t *alloc_move_to (dt_iop_module_t *module, float complex start_point) +static dt_liquify_path_data_t *alloc_move_to(dt_iop_module_t *module, float complex start_point) { - dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *) module->gui_data; - dt_liquify_path_data_t* m = (dt_liquify_path_data_t*)node_alloc (&g->params, &g->node_index); - if (m) + dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *)module->gui_data; + dt_liquify_path_data_t *m = (dt_liquify_path_data_t *)node_alloc(&g->params, &g->node_index); + if(m) { m->header.type = DT_LIQUIFY_PATH_MOVE_TO_V1; m->header.node_type = DT_LIQUIFY_NODE_TYPE_AUTOSMOOTH; - init_warp (&m->warp, start_point); + init_warp(&m->warp, start_point); } return (dt_liquify_path_data_t *)m; } -static dt_liquify_path_data_t *alloc_line_to (dt_iop_module_t *module, float complex end_point) +static dt_liquify_path_data_t *alloc_line_to(dt_iop_module_t *module, float complex end_point) { - dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *) module->gui_data; - dt_liquify_path_data_t* l = (dt_liquify_path_data_t*)node_alloc (&g->params, &g->node_index); - if (l) + dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *)module->gui_data; + dt_liquify_path_data_t *l = (dt_liquify_path_data_t *)node_alloc(&g->params, &g->node_index); + if(l) { l->header.type = DT_LIQUIFY_PATH_LINE_TO_V1; l->header.node_type = DT_LIQUIFY_NODE_TYPE_AUTOSMOOTH; - init_warp (&l->warp, end_point); + init_warp(&l->warp, end_point); } return (dt_liquify_path_data_t *)l; } -static dt_liquify_path_data_t *alloc_curve_to (dt_iop_module_t *module, float complex end_point) +static dt_liquify_path_data_t *alloc_curve_to(dt_iop_module_t *module, float complex end_point) { - dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *) module->gui_data; - dt_liquify_path_data_t* c = (dt_liquify_path_data_t*)node_alloc (&g->params, &g->node_index); - if (c) + dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *)module->gui_data; + dt_liquify_path_data_t *c = (dt_liquify_path_data_t *)node_alloc(&g->params, &g->node_index); + if(c) { c->header.type = DT_LIQUIFY_PATH_CURVE_TO_V1; c->header.node_type = DT_LIQUIFY_NODE_TYPE_AUTOSMOOTH; c->node.ctrl1 = c->node.ctrl2 = 0.0; - init_warp (&c->warp, end_point); + init_warp(&c->warp, end_point); } return (dt_liquify_path_data_t *)c; } -static void start_drag (dt_iop_liquify_gui_data_t *g, dt_liquify_layer_enum_t layer, dt_liquify_path_data_t *elem) +static void start_drag(dt_iop_liquify_gui_data_t *g, dt_liquify_layer_enum_t layer, dt_liquify_path_data_t *elem) { g->dragging.layer = layer; g->dragging.elem = elem; } -static void end_drag (dt_iop_liquify_gui_data_t *g) +static void end_drag(dt_iop_liquify_gui_data_t *g) { g->dragging = NOWHERE; } @@ -2504,98 +2528,92 @@ static gboolean is_dragging(dt_iop_liquify_gui_data_t *g) return g->dragging.elem != NULL; } -static void unselect_all (dt_iop_liquify_params_t *p) +static void unselect_all(dt_iop_liquify_params_t *p) { - for (int k=0; k<MAX_NODES; k++) - if (p->nodes[k].header.type == DT_LIQUIFY_PATH_INVALIDATED) + for(int k = 0; k < MAX_NODES; k++) + if(p->nodes[k].header.type == DT_LIQUIFY_PATH_INVALIDATED) break; else p->nodes[k].header.selected = 0; } -static float get_zoom_scale (dt_develop_t *develop) +static float get_zoom_scale(dt_develop_t *develop) { - const dt_dev_zoom_t zoom = dt_control_get_dev_zoom (); - const int closeup = dt_control_get_dev_closeup (); - return dt_dev_get_zoom_scale (develop, zoom, closeup ? 2 : 1, 1); + const dt_dev_zoom_t zoom = dt_control_get_dev_zoom(); + const int closeup = dt_control_get_dev_closeup(); + return dt_dev_get_zoom_scale(develop, zoom, closeup ? 2 : 1, 1); } -void gui_post_expose (struct dt_iop_module_t *module, - cairo_t *cr, - int32_t width, - int32_t height, - int32_t pointerx, - int32_t pointery) +void gui_post_expose(struct dt_iop_module_t *module, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, + int32_t pointery) { dt_develop_t *develop = module->dev; - dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *) module->gui_data; - if (!g) - return; + dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *)module->gui_data; + if(!g) return; const float bb_width = develop->preview_pipe->backbuf_width; const float bb_height = develop->preview_pipe->backbuf_height; const float iscale = develop->preview_pipe->iscale; - const float scale = MAX (bb_width, bb_height); - if (bb_width < 1.0 || bb_height < 1.0) - return; + const float scale = MAX(bb_width, bb_height); + if(bb_width < 1.0 || bb_height < 1.0) return; // get a copy of all iop params - dt_pthread_mutex_lock (&g->lock); - update_warp_count (g); - smooth_paths_linsys (&g->params); + dt_pthread_mutex_lock(&g->lock); + update_warp_count(g); + smooth_paths_linsys(&g->params); dt_iop_liquify_params_t copy_params; memcpy(&copy_params, &g->params, sizeof(dt_iop_liquify_params_t)); - dt_pthread_mutex_unlock (&g->lock); + dt_pthread_mutex_unlock(&g->lock); // distort all points dt_pthread_mutex_lock(&develop->preview_pipe_mutex); const distort_params_t d_params = { develop, develop->preview_pipe, iscale, 1.0 / scale, 0, 9999999 }; - _distort_paths (module, &d_params, &copy_params); + _distort_paths(module, &d_params, &copy_params); dt_pthread_mutex_unlock(&develop->preview_pipe_mutex); // You're not supposed to understand this - const float zoom_x = dt_control_get_dev_zoom_x (); - const float zoom_y = dt_control_get_dev_zoom_y (); - const float zoom_scale = get_zoom_scale (develop); + const float zoom_x = dt_control_get_dev_zoom_x(); + const float zoom_y = dt_control_get_dev_zoom_y(); + const float zoom_scale = get_zoom_scale(develop); // setup CAIRO coordinate system - cairo_translate (cr, 0.5 * width, 0.5 * height); // origin @ center of view - cairo_scale (cr, zoom_scale, zoom_scale); // the zoom - cairo_translate (cr, -bb_width * (0.5 + zoom_x), -bb_height * (0.5 + zoom_y)); - cairo_scale (cr, scale, scale); + cairo_translate(cr, 0.5 * width, 0.5 * height); // origin @ center of view + cairo_scale(cr, zoom_scale, zoom_scale); // the zoom + cairo_translate(cr, -bb_width * (0.5 + zoom_x), -bb_height * (0.5 + zoom_y)); + cairo_scale(cr, scale, scale); - draw_paths (module, cr, 1.0 / (scale * zoom_scale), &copy_params); + draw_paths(module, cr, 1.0 / (scale * zoom_scale), &copy_params); } -void gui_focus (struct dt_iop_module_t *module, gboolean in) +void gui_focus(struct dt_iop_module_t *module, gboolean in) { - dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *) module->gui_data; + dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *)module->gui_data; - if (!in) + if(!in) { - dt_control_hinter_message (darktable.control, ""); - gtk_toggle_button_set_active (g->btn_point_tool, FALSE); - gtk_toggle_button_set_active (g->btn_line_tool, FALSE); - gtk_toggle_button_set_active (g->btn_curve_tool, FALSE); - gtk_toggle_button_set_active (g->btn_node_tool, FALSE); + dt_control_hinter_message(darktable.control, ""); + gtk_toggle_button_set_active(g->btn_point_tool, FALSE); + gtk_toggle_button_set_active(g->btn_line_tool, FALSE); + gtk_toggle_button_set_active(g->btn_curve_tool, FALSE); + gtk_toggle_button_set_active(g->btn_node_tool, FALSE); } } -static void sync_pipe (struct dt_iop_module_t *module, gboolean history) +static void sync_pipe(struct dt_iop_module_t *module, gboolean history) { - if (history) + if(history) { - const dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *) module->gui_data; + const dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *)module->gui_data; // something definitive has happened like button release ... so // redraw pipe memcpy(module->params, &g->params, sizeof(dt_iop_liquify_params_t)); - dt_dev_add_history_item (darktable.develop, module, TRUE); + dt_dev_add_history_item(darktable.develop, module, TRUE); } else { // only moving mouse around, pointing at things or dragging ... so // give some cairo feedback, but don't redraw pipe - dt_control_queue_redraw_center (); + dt_control_queue_redraw_center(); } } @@ -2619,63 +2637,57 @@ static void get_point_scale(struct dt_iop_module_t *module, float x, float y, fl float wd = darktable.develop->preview_pipe->backbuf_width; float ht = darktable.develop->preview_pipe->backbuf_height; float pts[2] = { pzx * wd, pzy * ht }; - dt_dev_distort_backtransform_plus(darktable.develop, darktable.develop->preview_pipe, - module->priority + 1, 9999999, pts, 1); - dt_dev_distort_backtransform_plus(darktable.develop, darktable.develop->preview_pipe, - 0, module->priority - 1, pts, 1); + dt_dev_distort_backtransform_plus(darktable.develop, darktable.develop->preview_pipe, module->priority + 1, + 9999999, pts, 1); + dt_dev_distort_backtransform_plus(darktable.develop, darktable.develop->preview_pipe, 0, module->priority - 1, + pts, 1); float nx = pts[0] / darktable.develop->preview_pipe->iwidth; float ny = pts[1] / darktable.develop->preview_pipe->iheight; *scale = darktable.develop->preview_pipe->iscale / get_zoom_scale(module->dev); - *pt = (nx * darktable.develop->pipe->iwidth) + (ny * darktable.develop->pipe->iheight) * I; + *pt = (nx * darktable.develop->pipe->iwidth) + (ny * darktable.develop->pipe->iheight) * I; } -int mouse_moved (struct dt_iop_module_t *module, - double x, - double y, - double pressure, - int which) +int mouse_moved(struct dt_iop_module_t *module, double x, double y, double pressure, int which) { - dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *) module->gui_data; + dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *)module->gui_data; int handled = g->last_hit.elem ? 1 : 0; float complex pt; float scale; get_point_scale(module, x, y, &pt, &scale); - dt_pthread_mutex_lock (&g->lock); + dt_pthread_mutex_lock(&g->lock); g->last_mouse_pos = pt; - const int dragged = detect_drag (g, scale, pt); + const int dragged = detect_drag(g, scale, pt); // Don't hit test while dragging, you'd only hit the dragged thing // anyway. - if (!is_dragging(g)) + if(!is_dragging(g)) { - dt_liquify_hit_t hit = hit_test_paths (module, scale, g->fake_cr, &g->params, pt); - dt_liquify_path_data_t *last_hovered = find_hovered (&g->params); - if (hit.elem != last_hovered || - (last_hovered && hit.elem && hit.elem->header.hovered != last_hovered->header.hovered)) + dt_liquify_hit_t hit = hit_test_paths(module, scale, g->fake_cr, &g->params, pt); + dt_liquify_path_data_t *last_hovered = find_hovered(&g->params); + if(hit.elem != last_hovered + || (last_hovered && hit.elem && hit.elem->header.hovered != last_hovered->header.hovered)) { - if (hit.elem) - hit.elem->header.hovered = hit.layer; - if (last_hovered) - last_hovered->header.hovered = 0; + if(hit.elem) hit.elem->header.hovered = hit.layer; + if(last_hovered) last_hovered->header.hovered = 0; // change in hover display - dt_control_hinter_message (darktable.control, dt_liquify_layers[hit.layer].hint); + dt_control_hinter_message(darktable.control, dt_liquify_layers[hit.layer].hint); handled = 1; goto done; } } - if (dragged && !is_dragging(g) && g->last_hit.elem) + if(dragged && !is_dragging(g) && g->last_hit.elem) { // start dragging - start_drag (g, g->last_hit.layer, g->last_hit.elem); + start_drag(g, g->last_hit.layer, g->last_hit.elem); } - if (is_dragging(g)) + if(is_dragging(g)) { dt_liquify_path_data_t *d = g->dragging.elem; dt_liquify_path_data_t *n = node_next(&g->params, d); @@ -2683,159 +2695,150 @@ int mouse_moved (struct dt_iop_module_t *module, const float complex *start_pt = &d->warp.point; - switch (g->dragging.layer) + switch(g->dragging.layer) { - case DT_LIQUIFY_LAYER_CENTERPOINT: - switch (d->header.type) - { - case DT_LIQUIFY_PATH_CURVE_TO_V1: - d->node.ctrl2 += pt - d->warp.point; - // fall thru - case DT_LIQUIFY_PATH_MOVE_TO_V1: - case DT_LIQUIFY_PATH_LINE_TO_V1: - if (n && n->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) - n->node.ctrl1 += pt - d->warp.point; - if (p && p->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) - p->node.ctrl2 += pt - d->warp.point; - d->warp.radius += pt - d->warp.point; - d->warp.strength += pt - d->warp.point; - d->warp.point = pt; - break; - default: + case DT_LIQUIFY_LAYER_CENTERPOINT: + switch(d->header.type) + { + case DT_LIQUIFY_PATH_CURVE_TO_V1: + d->node.ctrl2 += pt - d->warp.point; + // fall thru + case DT_LIQUIFY_PATH_MOVE_TO_V1: + case DT_LIQUIFY_PATH_LINE_TO_V1: + if(n && n->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) n->node.ctrl1 += pt - d->warp.point; + if(p && p->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) p->node.ctrl2 += pt - d->warp.point; + d->warp.radius += pt - d->warp.point; + d->warp.strength += pt - d->warp.point; + d->warp.point = pt; + break; + default: + break; + } break; - } - break; - case DT_LIQUIFY_LAYER_CTRLPOINT1: - switch (d->header.type) - { - case DT_LIQUIFY_PATH_CURVE_TO_V1: - d->node.ctrl1 = pt; - if (p && p->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) + case DT_LIQUIFY_LAYER_CTRLPOINT1: + switch(d->header.type) { - switch (p->header.node_type) - { - case DT_LIQUIFY_NODE_TYPE_SMOOTH: - p->node.ctrl2 = p->warp.point + - cabs (p->warp.point - p->node.ctrl2) * - cexp (carg (p->warp.point - pt) * I); - break; - case DT_LIQUIFY_NODE_TYPE_SYMMETRICAL: - p->node.ctrl2 = 2 * p->warp.point - pt; + case DT_LIQUIFY_PATH_CURVE_TO_V1: + d->node.ctrl1 = pt; + if(p && p->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) + { + switch(p->header.node_type) + { + case DT_LIQUIFY_NODE_TYPE_SMOOTH: + p->node.ctrl2 = p->warp.point + + cabs(p->warp.point - p->node.ctrl2) * cexp(carg(p->warp.point - pt) * I); + break; + case DT_LIQUIFY_NODE_TYPE_SYMMETRICAL: + p->node.ctrl2 = 2 * p->warp.point - pt; + break; + default: + break; + } + } break; default: break; - } } break; - default: - break; - } - break; - case DT_LIQUIFY_LAYER_CTRLPOINT2: - switch (d->header.type) - { - case DT_LIQUIFY_PATH_CURVE_TO_V1: - d->node.ctrl2 = pt; - if (n && n->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) + case DT_LIQUIFY_LAYER_CTRLPOINT2: + switch(d->header.type) { - switch (d->header.node_type) - { - case DT_LIQUIFY_NODE_TYPE_SMOOTH: - n->node.ctrl1 = d->warp.point + - cabs (d->warp.point - n->node.ctrl1) * - cexp (carg (d->warp.point - pt) * I); - break; - case DT_LIQUIFY_NODE_TYPE_SYMMETRICAL: - n->node.ctrl1 = 2 * d->warp.point - pt; + case DT_LIQUIFY_PATH_CURVE_TO_V1: + d->node.ctrl2 = pt; + if(n && n->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) + { + switch(d->header.node_type) + { + case DT_LIQUIFY_NODE_TYPE_SMOOTH: + n->node.ctrl1 = d->warp.point + + cabs(d->warp.point - n->node.ctrl1) * cexp(carg(d->warp.point - pt) * I); + break; + case DT_LIQUIFY_NODE_TYPE_SYMMETRICAL: + n->node.ctrl1 = 2 * d->warp.point - pt; + break; + default: + break; + } + } break; default: break; - } } break; - default: - break; - } - break; - case DT_LIQUIFY_LAYER_RADIUSPOINT: - d->warp.radius = pt; - dt_conf_set_float(CONF_RADIUS, cabs(d->warp.radius - d->warp.point)); - break; + case DT_LIQUIFY_LAYER_RADIUSPOINT: + d->warp.radius = pt; + dt_conf_set_float(CONF_RADIUS, cabs(d->warp.radius - d->warp.point)); + break; - case DT_LIQUIFY_LAYER_STRENGTHPOINT: - d->warp.strength = pt; - break; + case DT_LIQUIFY_LAYER_STRENGTHPOINT: + d->warp.strength = pt; + break; - case DT_LIQUIFY_LAYER_HARDNESSPOINT1: - d->warp.control1 = MIN (1.0, cabs (pt - *start_pt) / cabs (d->warp.radius - *start_pt)); - break; + case DT_LIQUIFY_LAYER_HARDNESSPOINT1: + d->warp.control1 = MIN(1.0, cabs(pt - *start_pt) / cabs(d->warp.radius - *start_pt)); + break; - case DT_LIQUIFY_LAYER_HARDNESSPOINT2: - d->warp.control2 = MIN (1.0, cabs (pt - *start_pt) / cabs (d->warp.radius - *start_pt)); - break; + case DT_LIQUIFY_LAYER_HARDNESSPOINT2: + d->warp.control2 = MIN(1.0, cabs(pt - *start_pt) / cabs(d->warp.radius - *start_pt)); + break; - default: - break; + default: + break; } handled = 1; } done: - dt_pthread_mutex_unlock (&g->lock); - if (handled) { - sync_pipe (module, handled == 2); + dt_pthread_mutex_unlock(&g->lock); + if(handled) + { + sync_pipe(module, handled == 2); } return handled; } -int button_pressed (struct dt_iop_module_t *module, - double x, - double y, - double pressure, - int which, - int type, - uint32_t state) +int button_pressed(struct dt_iop_module_t *module, double x, double y, double pressure, int which, int type, + uint32_t state) { - dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *) module->gui_data; + dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *)module->gui_data; int handled = 0; float complex pt; float scale; get_point_scale(module, x, y, &pt, &scale); - dt_pthread_mutex_lock (&g->lock); + dt_pthread_mutex_lock(&g->lock); g->last_mouse_pos = pt; - g->last_mouse_mods = state & gtk_accelerator_get_default_mod_mask (); - if (which == 1) - g->last_button1_pressed_pos = pt; + g->last_mouse_mods = state & gtk_accelerator_get_default_mod_mask(); + if(which == 1) g->last_button1_pressed_pos = pt; - if (!is_dragging(g)) + if(!is_dragging(g)) // while dragging you would always hit the dragged thing - g->last_hit = hit_test_paths (module, scale, g->fake_cr, &g->params, pt); + g->last_hit = hit_test_paths(module, scale, g->fake_cr, &g->params, pt); - if (which == 2) goto done; + if(which == 2) goto done; // Point tool - if (which == 1 && gtk_toggle_button_get_active (g->btn_point_tool)) + if(which == 1 && gtk_toggle_button_get_active(g->btn_point_tool)) { // always end dragging before manipulating the path list to avoid // dangling pointers - end_drag (g); + end_drag(g); // start a new path - g->temp = alloc_move_to (module, pt); - if (!g->temp) goto done; - g->temp->warp.radius = pt + - (dt_conf_key_exists(CONF_RADIUS) ? dt_conf_get_float(CONF_RADIUS) : GET_UI_WIDTH (DEFAULT_RADIUS)); - g->temp->warp.strength = pt + GET_UI_WIDTH (DEFAULT_STRENGTH); + g->temp = alloc_move_to(module, pt); + if(!g->temp) goto done; + g->temp->warp.radius + = pt + (dt_conf_key_exists(CONF_RADIUS) ? dt_conf_get_float(CONF_RADIUS) : GET_UI_WIDTH(DEFAULT_RADIUS)); + g->temp->warp.strength = pt + GET_UI_WIDTH(DEFAULT_STRENGTH); g->status |= DT_LIQUIFY_STATUS_NEW; - start_drag (g, DT_LIQUIFY_LAYER_STRENGTHPOINT, g->temp); + start_drag(g, DT_LIQUIFY_LAYER_STRENGTHPOINT, g->temp); g->last_hit = NOWHERE; handled = 1; goto done; @@ -2843,15 +2846,15 @@ int button_pressed (struct dt_iop_module_t *module, // Line tool or curve tool - if (which == 1 && (gtk_toggle_button_get_active (g->btn_line_tool) - || gtk_toggle_button_get_active (g->btn_curve_tool))) + if(which == 1 + && (gtk_toggle_button_get_active(g->btn_line_tool) || gtk_toggle_button_get_active(g->btn_curve_tool))) { // always end dragging before manipulating the path list to avoid // dangling pointers - end_drag (g); - if (!g->temp) + end_drag(g); + if(!g->temp) { - if (g->last_hit.layer == DT_LIQUIFY_LAYER_CENTERPOINT) + if(g->last_hit.layer == DT_LIQUIFY_LAYER_CENTERPOINT) { // continue path g->temp = g->last_hit.elem; @@ -2859,17 +2862,17 @@ int button_pressed (struct dt_iop_module_t *module, else { // start a new path - g->temp = alloc_move_to (module, pt); - if (!g->temp) goto done; - g->temp->warp.radius = pt + - (dt_conf_key_exists(CONF_RADIUS) ? dt_conf_get_float(CONF_RADIUS) : GET_UI_WIDTH (DEFAULT_RADIUS)); - g->temp->warp.strength = pt + GET_UI_WIDTH (DEFAULT_STRENGTH); + g->temp = alloc_move_to(module, pt); + if(!g->temp) goto done; + g->temp->warp.radius = pt + (dt_conf_key_exists(CONF_RADIUS) ? dt_conf_get_float(CONF_RADIUS) + : GET_UI_WIDTH(DEFAULT_RADIUS)); + g->temp->warp.strength = pt + GET_UI_WIDTH(DEFAULT_STRENGTH); } } g->last_hit = NOWHERE; - if (gtk_toggle_button_get_active (g->btn_curve_tool)) + if(gtk_toggle_button_get_active(g->btn_curve_tool)) { - start_drag (g, DT_LIQUIFY_LAYER_CTRLPOINT1, g->temp); + start_drag(g, DT_LIQUIFY_LAYER_CTRLPOINT1, g->temp); } g->status |= DT_LIQUIFY_STATUS_NEW; handled = 1; @@ -2878,10 +2881,10 @@ int button_pressed (struct dt_iop_module_t *module, // Node tool - if (gtk_toggle_button_get_active (g->btn_node_tool)) + if(gtk_toggle_button_get_active(g->btn_node_tool)) { - if (which == 1 && (g->last_mouse_mods == GDK_CONTROL_MASK) && - (g->last_hit.layer == DT_LIQUIFY_LAYER_CENTERPOINT)) + if(which == 1 && (g->last_mouse_mods == GDK_CONTROL_MASK) + && (g->last_hit.layer == DT_LIQUIFY_LAYER_CENTERPOINT)) { // cycle node type: smooth -> cusp etc. dt_liquify_path_data_t *node = g->last_hit.elem; @@ -2889,11 +2892,11 @@ int button_pressed (struct dt_iop_module_t *module, handled = 1; goto done; } - if (which == 1 && (g->last_mouse_mods == GDK_CONTROL_MASK) && - (g->last_hit.layer == DT_LIQUIFY_LAYER_STRENGTHPOINT)) + if(which == 1 && (g->last_mouse_mods == GDK_CONTROL_MASK) + && (g->last_hit.layer == DT_LIQUIFY_LAYER_STRENGTHPOINT)) { // cycle warp type: linear -> radial etc. - if (g->last_hit.elem->header.type == DT_LIQUIFY_PATH_MOVE_TO_V1) + if(g->last_hit.elem->header.type == DT_LIQUIFY_PATH_MOVE_TO_V1) { dt_liquify_warp_t *warp = &g->last_hit.elem->warp; warp->type = (warp->type + 1) % DT_LIQUIFY_WARP_TYPE_LAST; @@ -2904,124 +2907,118 @@ int button_pressed (struct dt_iop_module_t *module, } done: - dt_pthread_mutex_unlock (&g->lock); - if (handled) - sync_pipe (module, TRUE); + dt_pthread_mutex_unlock(&g->lock); + if(handled) sync_pipe(module, TRUE); return handled; } -int button_released (struct dt_iop_module_t *module, - double x, - double y, - int which, - uint32_t state) +int button_released(struct dt_iop_module_t *module, double x, double y, int which, uint32_t state) { - dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *) module->gui_data; + dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *)module->gui_data; int handled = 0; float complex pt; float scale; get_point_scale(module, x, y, &pt, &scale); - dt_pthread_mutex_lock (&g->lock); + dt_pthread_mutex_lock(&g->lock); g->last_mouse_pos = pt; - const gboolean dragged = detect_drag (g, scale, pt); + const gboolean dragged = detect_drag(g, scale, pt); - if (which == 1 && g->temp && (g->status & DT_LIQUIFY_STATUS_NEW)) + if(which == 1 && g->temp && (g->status & DT_LIQUIFY_STATUS_NEW)) { - end_drag (g); - if (gtk_toggle_button_get_active (g->btn_point_tool)) + end_drag(g); + if(gtk_toggle_button_get_active(g->btn_point_tool)) { // user released without dragging, set a default strength vector - if (!dragged) + if(!dragged) { - g->temp->warp.strength = pt + GET_UI_WIDTH (DEFAULT_STRENGTH); + g->temp->warp.strength = pt + GET_UI_WIDTH(DEFAULT_STRENGTH); } g->temp = NULL; // a point is done - gtk_toggle_button_set_active (g->btn_node_tool, 1); + gtk_toggle_button_set_active(g->btn_node_tool, 1); } - if (gtk_toggle_button_get_active (g->btn_line_tool)) + if(gtk_toggle_button_get_active(g->btn_line_tool)) { const int prev_index = g->node_index; - g->temp = alloc_line_to (module, pt); - if (!g->temp) goto done; - g->temp->warp.radius = pt + - (dt_conf_key_exists(CONF_RADIUS) ? dt_conf_get_float(CONF_RADIUS) : GET_UI_WIDTH (DEFAULT_RADIUS)); - g->temp->warp.strength = pt + GET_UI_WIDTH (DEFAULT_STRENGTH); + g->temp = alloc_line_to(module, pt); + if(!g->temp) goto done; + g->temp->warp.radius + = pt + (dt_conf_key_exists(CONF_RADIUS) ? dt_conf_get_float(CONF_RADIUS) : GET_UI_WIDTH(DEFAULT_RADIUS)); + g->temp->warp.strength = pt + GET_UI_WIDTH(DEFAULT_STRENGTH); // links g->temp->header.prev = prev_index; node_get(&g->params, prev_index)->header.next = g->node_index; - start_drag (g, DT_LIQUIFY_LAYER_CENTERPOINT, g->temp); + start_drag(g, DT_LIQUIFY_LAYER_CENTERPOINT, g->temp); } - if (gtk_toggle_button_get_active (g->btn_curve_tool)) + if(gtk_toggle_button_get_active(g->btn_curve_tool)) { const int prev_index = g->node_index; - g->temp = alloc_curve_to (module, pt); - if (!g->temp) goto done; + g->temp = alloc_curve_to(module, pt); + if(!g->temp) goto done; // user dragged, make it a symmetrical node - if (dragged) + if(dragged) { g->temp->header.node_type = DT_LIQUIFY_NODE_TYPE_SYMMETRICAL; } - g->temp->warp.radius = pt + - (dt_conf_key_exists(CONF_RADIUS) ? dt_conf_get_float(CONF_RADIUS) : GET_UI_WIDTH (DEFAULT_RADIUS)); - g->temp->warp.strength = pt + GET_UI_WIDTH (DEFAULT_STRENGTH); + g->temp->warp.radius + = pt + (dt_conf_key_exists(CONF_RADIUS) ? dt_conf_get_float(CONF_RADIUS) : GET_UI_WIDTH(DEFAULT_RADIUS)); + g->temp->warp.strength = pt + GET_UI_WIDTH(DEFAULT_STRENGTH); // links g->temp->header.prev = prev_index; node_get(&g->params, prev_index)->header.next = g->node_index; - start_drag (g, DT_LIQUIFY_LAYER_CENTERPOINT, g->temp); + start_drag(g, DT_LIQUIFY_LAYER_CENTERPOINT, g->temp); } g->status &= ~DT_LIQUIFY_STATUS_NEW; handled = 1; goto done; } - if (which == 1 && is_dragging(g)) + if(which == 1 && is_dragging(g)) { - end_drag (g); + end_drag(g); handled = 2; goto done; } // right click == cancel or delete - if (which == 3) + if(which == 3) { - dt_control_hinter_message (darktable.control, ""); - end_drag (g); + dt_control_hinter_message(darktable.control, ""); + end_drag(g); // cancel line or curve creation - if (g->temp) + if(g->temp) { - node_delete (&g->params, g->temp); + node_delete(&g->params, g->temp); g->temp = NULL; - gtk_toggle_button_set_active (g->btn_node_tool, 1); + gtk_toggle_button_set_active(g->btn_node_tool, 1); handled = 2; goto done; } // right click on background toggles node tool - if (g->last_hit.layer == DT_LIQUIFY_LAYER_BACKGROUND) + if(g->last_hit.layer == DT_LIQUIFY_LAYER_BACKGROUND) { - gtk_toggle_button_set_active (g->btn_node_tool, - !gtk_toggle_button_get_active (g->btn_node_tool)); + gtk_toggle_button_set_active(g->btn_node_tool, !gtk_toggle_button_get_active(g->btn_node_tool)); handled = 1; goto done; } // delete node - if (g->last_hit.layer == DT_LIQUIFY_LAYER_CENTERPOINT) + if(g->last_hit.layer == DT_LIQUIFY_LAYER_CENTERPOINT) { - node_delete (&g->params, g->last_hit.elem); + node_delete(&g->params, g->last_hit.elem); g->last_hit = NOWHERE; handled = 2; goto done; } // delete shape - if (g->last_hit.layer == DT_LIQUIFY_LAYER_PATH) + if(g->last_hit.layer == DT_LIQUIFY_LAYER_PATH) { - path_delete (&g->params, g->last_hit.elem); + path_delete(&g->params, g->last_hit.elem); g->last_hit = NOWHERE; handled = 2; goto done; @@ -3031,31 +3028,31 @@ int button_released (struct dt_iop_module_t *module, // Node tool - if (gtk_toggle_button_get_active (g->btn_node_tool)) + if(gtk_toggle_button_get_active(g->btn_node_tool)) { - if (which == 1 && g->last_mouse_mods == 0 && !dragged) + if(which == 1 && g->last_mouse_mods == 0 && !dragged) { // select/unselect start/endpoint and clear previous selections - if (g->last_hit.layer == DT_LIQUIFY_LAYER_CENTERPOINT) + if(g->last_hit.layer == DT_LIQUIFY_LAYER_CENTERPOINT) { const int oldsel = !!g->last_hit.elem->header.selected; - unselect_all (&g->params); + unselect_all(&g->params); g->last_hit.elem->header.selected = oldsel ? 0 : g->last_hit.layer; handled = 1; goto done; } // unselect all - if (g->last_hit.layer == DT_LIQUIFY_LAYER_BACKGROUND) + if(g->last_hit.layer == DT_LIQUIFY_LAYER_BACKGROUND) { - unselect_all (&g->params); + unselect_all(&g->params); handled = 1; goto done; } } - if (which == 1 && g->last_mouse_mods == GDK_SHIFT_MASK && !dragged) + if(which == 1 && g->last_mouse_mods == GDK_SHIFT_MASK && !dragged) { // select/unselect start/endpoint and keep previous selections - if (g->last_hit.layer == DT_LIQUIFY_LAYER_CENTERPOINT) + if(g->last_hit.layer == DT_LIQUIFY_LAYER_CENTERPOINT) { const int oldsel = !!g->last_hit.elem->header.selected; g->last_hit.elem->header.selected = oldsel ? 0 : g->last_hit.layer; @@ -3063,20 +3060,20 @@ int button_released (struct dt_iop_module_t *module, goto done; } } - if (which == 1 && (g->last_mouse_mods == GDK_CONTROL_MASK) && !dragged) + if(which == 1 && (g->last_mouse_mods == GDK_CONTROL_MASK) && !dragged) { // add node - if (g->last_hit.layer == DT_LIQUIFY_LAYER_PATH) + if(g->last_hit.layer == DT_LIQUIFY_LAYER_PATH) { dt_liquify_path_data_t *e = g->last_hit.elem; - dt_liquify_path_data_t *prev = node_prev (&g->params, e); - if (prev && e->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) + dt_liquify_path_data_t *prev = node_prev(&g->params, e); + if(prev && e->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) { - // add node to curve - dt_liquify_path_data_t *curve1 = (dt_liquify_path_data_t *) e; + // add node to curve + dt_liquify_path_data_t *curve1 = (dt_liquify_path_data_t *)e; - dt_liquify_path_data_t *curve2 = (dt_liquify_path_data_t *)alloc_curve_to (module, 0); - if (!curve2) goto done; + dt_liquify_path_data_t *curve2 = (dt_liquify_path_data_t *)alloc_curve_to(module, 0); + if(!curve2) goto done; curve2->node.ctrl1 = curve1->node.ctrl1; curve2->node.ctrl2 = curve1->node.ctrl2; @@ -3085,52 +3082,50 @@ int button_released (struct dt_iop_module_t *module, dt_liquify_warp_t *warp2 = &curve2->warp; dt_liquify_warp_t *warp3 = &e->warp; - const float t = find_nearest_on_curve_t (warp1->point, curve1->node.ctrl1, curve1->node.ctrl2, - warp3->point, pt, INTERPOLATION_POINTS); + const float t = find_nearest_on_curve_t(warp1->point, curve1->node.ctrl1, curve1->node.ctrl2, + warp3->point, pt, INTERPOLATION_POINTS); float complex midpoint = warp3->point; - casteljau (&warp1->point, &curve1->node.ctrl1, &curve1->node.ctrl2, &midpoint, t); + casteljau(&warp1->point, &curve1->node.ctrl1, &curve1->node.ctrl2, &midpoint, t); midpoint = warp1->point; - casteljau (&warp3->point, &curve2->node.ctrl2, &curve2->node.ctrl1, &midpoint, 1.0 - t); + casteljau(&warp3->point, &curve2->node.ctrl2, &curve2->node.ctrl1, &midpoint, 1.0 - t); - mix_warps (warp2, warp1, warp3, midpoint, t); + mix_warps(warp2, warp1, warp3, midpoint, t); - node_insert_before (&g->params, e, (dt_liquify_path_data_t *)curve2); + node_insert_before(&g->params, e, (dt_liquify_path_data_t *)curve2); handled = 2; goto done; } - if (prev && e->header.type == DT_LIQUIFY_PATH_LINE_TO_V1) + if(prev && e->header.type == DT_LIQUIFY_PATH_LINE_TO_V1) { - // add node to line + // add node to line dt_liquify_warp_t *warp1 = &prev->warp; dt_liquify_warp_t *warp3 = &e->warp; - const float t = find_nearest_on_line_t (warp1->point, warp3->point, pt); + const float t = find_nearest_on_line_t(warp1->point, warp3->point, pt); - dt_liquify_path_data_t *tmp = alloc_line_to (module, e->warp.point); - if (!tmp) goto done; + dt_liquify_path_data_t *tmp = alloc_line_to(module, e->warp.point); + if(!tmp) goto done; dt_liquify_warp_t *warp2 = &tmp->warp; - double complex midpoint = cmix (warp1->point, warp3->point, t); + double complex midpoint = cmix(warp1->point, warp3->point, t); - mix_warps (warp2, warp1, warp3, midpoint, t); - node_insert_before (&g->params, e, tmp); + mix_warps(warp2, warp1, warp3, midpoint, t); + node_insert_before(&g->params, e, tmp); handled = 2; goto done; } } } - if (which == 1 - && (g->last_mouse_mods == (GDK_MOD1_MASK | GDK_CONTROL_MASK)) - && !dragged) + if(which == 1 && (g->last_mouse_mods == (GDK_MOD1_MASK | GDK_CONTROL_MASK)) && !dragged) { - if (g->last_hit.layer == DT_LIQUIFY_LAYER_PATH) + if(g->last_hit.layer == DT_LIQUIFY_LAYER_PATH) { // change segment dt_liquify_path_data_t *e = g->last_hit.elem; - dt_liquify_path_data_t *prev = node_prev (&g->params, e); - if (prev && e->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) + dt_liquify_path_data_t *prev = node_prev(&g->params, e); + if(prev && e->header.type == DT_LIQUIFY_PATH_CURVE_TO_V1) { // curve -> line e->header.type = DT_LIQUIFY_PATH_LINE_TO_V1; @@ -3139,7 +3134,7 @@ int button_released (struct dt_iop_module_t *module, handled = 2; goto done; } - if (prev && e->header.type == DT_LIQUIFY_PATH_LINE_TO_V1) + if(prev && e->header.type == DT_LIQUIFY_PATH_LINE_TO_V1) { // line -> curve const float complex p0 = prev->warp.point; @@ -3147,8 +3142,8 @@ int button_released (struct dt_iop_module_t *module, dt_liquify_path_data_t *c = (dt_liquify_path_data_t *)e; e->header.type = DT_LIQUIFY_PATH_CURVE_TO_V1; e->header.node_type = DT_LIQUIFY_NODE_TYPE_AUTOSMOOTH; - c->node.ctrl1 = (2 * p0 + p1) / 3.0; - c->node.ctrl2 = ( p0 + 2 * p1) / 3.0; + c->node.ctrl1 = (2 * p0 + p1) / 3.0; + c->node.ctrl2 = (p0 + 2 * p1) / 3.0; handled = 2; goto done; @@ -3158,243 +3153,238 @@ int button_released (struct dt_iop_module_t *module, } done: - if (which == 1) - g->last_button1_pressed_pos = -1; + if(which == 1) g->last_button1_pressed_pos = -1; g->last_hit = NOWHERE; - dt_pthread_mutex_unlock (&g->lock); - if (handled) { - update_warp_count (g); - sync_pipe (module, handled == 2); + dt_pthread_mutex_unlock(&g->lock); + if(handled) + { + update_warp_count(g); + sync_pipe(module, handled == 2); } return handled; } -static void _liquify_cairo_paint_point_tool -(cairo_t *cr, const gint x, const gint y, const gint w, const gint h, const gint flags); +static void _liquify_cairo_paint_point_tool(cairo_t *cr, const gint x, const gint y, const gint w, const gint h, + const gint flags); -static void _liquify_cairo_paint_line_tool -(cairo_t *cr, const gint x, const gint y, const gint w, const gint h, const gint flags); +static void _liquify_cairo_paint_line_tool(cairo_t *cr, const gint x, const gint y, const gint w, const gint h, + const gint flags); -static void _liquify_cairo_paint_curve_tool -(cairo_t *cr, const gint x, const gint y, const gint w, const gint h, const gint flags); +static void _liquify_cairo_paint_curve_tool(cairo_t *cr, const gint x, const gint y, const gint w, const gint h, + const gint flags); -static void _liquify_cairo_paint_node_tool -(cairo_t *cr, const gint x, const gint y, const gint w, const gint h, const gint flags); +static void _liquify_cairo_paint_node_tool(cairo_t *cr, const gint x, const gint y, const gint w, const gint h, + const gint flags); // we need this only because darktable has no radiobutton support -static void btn_make_radio_callback (GtkToggleButton *btn, dt_iop_module_t *module) +static void btn_make_radio_callback(GtkToggleButton *btn, dt_iop_module_t *module) { - dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *) module->gui_data; - dt_control_hinter_message (darktable.control, ""); + dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *)module->gui_data; + dt_control_hinter_message(darktable.control, ""); // if currently dragging, does nothing - if (is_dragging(g)) + if(is_dragging(g)) { - gtk_toggle_button_set_active (btn, 0); + gtk_toggle_button_set_active(btn, 0); return; } - if (gtk_toggle_button_get_active (btn)) - { - gtk_toggle_button_set_active (g->btn_point_tool, btn == g->btn_point_tool); - gtk_toggle_button_set_active (g->btn_line_tool, btn == g->btn_line_tool); - gtk_toggle_button_set_active (g->btn_curve_tool, btn == g->btn_curve_tool); - gtk_toggle_button_set_active (g->btn_node_tool, btn == g->btn_node_tool); - if (btn == g->btn_point_tool) - dt_control_hinter_message (darktable.control, _("click and drag to add point")); - if (btn == g->btn_line_tool) - dt_control_hinter_message (darktable.control, _("click to add line")); - if (btn == g->btn_curve_tool) - dt_control_hinter_message (darktable.control, _("click to add curve")); - if (btn == g->btn_node_tool) - dt_control_hinter_message (darktable.control, _("click to edit nodes")); + if(gtk_toggle_button_get_active(btn)) + { + gtk_toggle_button_set_active(g->btn_point_tool, btn == g->btn_point_tool); + gtk_toggle_button_set_active(g->btn_line_tool, btn == g->btn_line_tool); + gtk_toggle_button_set_active(g->btn_curve_tool, btn == g->btn_curve_tool); + gtk_toggle_button_set_active(g->btn_node_tool, btn == g->btn_node_tool); + if(btn == g->btn_point_tool) dt_control_hinter_message(darktable.control, _("click and drag to add point")); + if(btn == g->btn_line_tool) dt_control_hinter_message(darktable.control, _("click to add line")); + if(btn == g->btn_curve_tool) dt_control_hinter_message(darktable.control, _("click to add curve")); + if(btn == g->btn_node_tool) dt_control_hinter_message(darktable.control, _("click to edit nodes")); } - sync_pipe (module, FALSE); + sync_pipe(module, FALSE); dt_iop_request_focus(module); } -void gui_update (dt_iop_module_t *module) +void gui_update(dt_iop_module_t *module) { - dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *) module->gui_data; + dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *)module->gui_data; memcpy(&g->params, module->params, sizeof(dt_iop_liquify_params_t)); update_warp_count(g); } -void gui_init (dt_iop_module_t *module) +void gui_init(dt_iop_module_t *module) { const int bs = DT_PIXEL_APPLY_DPI(14); - module->gui_data = malloc (sizeof (dt_iop_liquify_gui_data_t)); - dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *) module->gui_data; + module->gui_data = malloc(sizeof(dt_iop_liquify_gui_data_t)); + dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *)module->gui_data; // A dummy surface for calculations only, no drawing. - cairo_surface_t *cs = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1); - g->fake_cr = cairo_create (cs); - cairo_surface_destroy (cs); + cairo_surface_t *cs = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1); + g->fake_cr = cairo_create(cs); + cairo_surface_destroy(cs); g->dragging = NOWHERE; g->temp = NULL; g->status = 0; - g->last_mouse_pos = - g->last_button1_pressed_pos = -1; + g->last_mouse_pos = g->last_button1_pressed_pos = -1; g->last_hit = NOWHERE; - dt_pthread_mutex_init (&g->lock, NULL); + dt_pthread_mutex_init(&g->lock, NULL); g->node_index = 0; - module->widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); + module->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); - GtkWidget *hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5); + GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); gtk_widget_set_tooltip_text(hbox, _("use a tool to add warps.\nright-click to remove a warp.")); - gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new (_("warps|nodes count:")), FALSE, TRUE, 0); - g->label = GTK_LABEL(gtk_label_new ("-")); - gtk_box_pack_start (GTK_BOX(hbox), GTK_WIDGET(g->label), FALSE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(_("warps|nodes count:")), FALSE, TRUE, 0); + g->label = GTK_LABEL(gtk_label_new("-")); + gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(g->label), FALSE, TRUE, 0); - g->btn_node_tool = GTK_TOGGLE_BUTTON(dtgtk_togglebutton_new(_liquify_cairo_paint_node_tool, - CPF_STYLE_FLAT|CPF_DO_NOT_USE_BORDER)); - g_signal_connect(G_OBJECT(g->btn_node_tool), "toggled", G_CALLBACK (btn_make_radio_callback), module); + g->btn_node_tool = GTK_TOGGLE_BUTTON( + dtgtk_togglebutton_new(_liquify_cairo_paint_node_tool, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER)); + g_signal_connect(G_OBJECT(g->btn_node_tool), "toggled", G_CALLBACK(btn_make_radio_callback), module); gtk_widget_set_tooltip_text(GTK_WIDGET(g->btn_node_tool), _("node tool: edit, add and delete nodes")); - gtk_toggle_button_set_active (g->btn_node_tool, 0); + gtk_toggle_button_set_active(g->btn_node_tool, 0); gtk_widget_set_size_request(GTK_WIDGET(g->btn_node_tool), bs, bs); gtk_box_pack_end(GTK_BOX(hbox), GTK_WIDGET(g->btn_node_tool), FALSE, FALSE, 0); - g->btn_curve_tool = GTK_TOGGLE_BUTTON(dtgtk_togglebutton_new(_liquify_cairo_paint_curve_tool, - CPF_STYLE_FLAT|CPF_DO_NOT_USE_BORDER)); - g_signal_connect (G_OBJECT (g->btn_curve_tool), "toggled", G_CALLBACK (btn_make_radio_callback), module); + g->btn_curve_tool = GTK_TOGGLE_BUTTON( + dtgtk_togglebutton_new(_liquify_cairo_paint_curve_tool, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER)); + g_signal_connect(G_OBJECT(g->btn_curve_tool), "toggled", G_CALLBACK(btn_make_radio_callback), module); gtk_widget_set_tooltip_text(GTK_WIDGET(g->btn_curve_tool), _("curve tool: draw curves")); - gtk_toggle_button_set_active (g->btn_curve_tool, 0); - gtk_widget_set_size_request (GTK_WIDGET(g->btn_curve_tool), bs, bs); - gtk_box_pack_end (GTK_BOX(hbox), GTK_WIDGET(g->btn_curve_tool), FALSE, FALSE, 0); + gtk_toggle_button_set_active(g->btn_curve_tool, 0); + gtk_widget_set_size_request(GTK_WIDGET(g->btn_curve_tool), bs, bs); + gtk_box_pack_end(GTK_BOX(hbox), GTK_WIDGET(g->btn_curve_tool), FALSE, FALSE, 0); - g->btn_line_tool = GTK_TOGGLE_BUTTON(dtgtk_togglebutton_new(_liquify_cairo_paint_line_tool, - CPF_STYLE_FLAT|CPF_DO_NOT_USE_BORDER)); - g_signal_connect (G_OBJECT (g->btn_line_tool), "toggled", G_CALLBACK (btn_make_radio_callback), module); + g->btn_line_tool = GTK_TOGGLE_BUTTON( + dtgtk_togglebutton_new(_liquify_cairo_paint_line_tool, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER)); + g_signal_connect(G_OBJECT(g->btn_line_tool), "toggled", G_CALLBACK(btn_make_radio_callback), module); gtk_widget_set_tooltip_text(GTK_WIDGET(g->btn_line_tool), _("line tool: draw lines")); - gtk_toggle_button_set_active (g->btn_line_tool, 0); - gtk_widget_set_size_request (GTK_WIDGET(g->btn_line_tool), bs, bs); - gtk_box_pack_end (GTK_BOX(hbox), GTK_WIDGET(g->btn_line_tool), FALSE, FALSE, 0); + gtk_toggle_button_set_active(g->btn_line_tool, 0); + gtk_widget_set_size_request(GTK_WIDGET(g->btn_line_tool), bs, bs); + gtk_box_pack_end(GTK_BOX(hbox), GTK_WIDGET(g->btn_line_tool), FALSE, FALSE, 0); - g->btn_point_tool = GTK_TOGGLE_BUTTON(dtgtk_togglebutton_new(_liquify_cairo_paint_point_tool, - CPF_STYLE_FLAT|CPF_DO_NOT_USE_BORDER)); - g_signal_connect (G_OBJECT (g->btn_point_tool), "toggled", G_CALLBACK (btn_make_radio_callback), module); + g->btn_point_tool = GTK_TOGGLE_BUTTON( + dtgtk_togglebutton_new(_liquify_cairo_paint_point_tool, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER)); + g_signal_connect(G_OBJECT(g->btn_point_tool), "toggled", G_CALLBACK(btn_make_radio_callback), module); gtk_widget_set_tooltip_text(GTK_WIDGET(g->btn_point_tool), _("point tool: draw points")); - gtk_toggle_button_set_active (g->btn_point_tool, 0); - gtk_widget_set_size_request (GTK_WIDGET(g->btn_point_tool), bs, bs); - gtk_box_pack_end (GTK_BOX(hbox), GTK_WIDGET(g->btn_point_tool), FALSE, FALSE, 0); + gtk_toggle_button_set_active(g->btn_point_tool, 0); + gtk_widget_set_size_request(GTK_WIDGET(g->btn_point_tool), bs, bs); + gtk_box_pack_end(GTK_BOX(hbox), GTK_WIDGET(g->btn_point_tool), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(module->widget), hbox, TRUE, TRUE, 0); - dt_liquify_layers[DT_LIQUIFY_LAYER_PATH].hint = _("ctrl-click: add node - right click: remove path\n" - "ctrl-alt-click: toggle line/curve"); - dt_liquify_layers[DT_LIQUIFY_LAYER_CENTERPOINT].hint = _("click and drag to move - click: show/hide feathering controls\n" - "ctrl-click: autosmooth, cusp, smooth, symmetrical" - " - right click to remove"); - dt_liquify_layers[DT_LIQUIFY_LAYER_CTRLPOINT1].hint = _("drag to change shape of path"); - dt_liquify_layers[DT_LIQUIFY_LAYER_CTRLPOINT2].hint = _("drag to change shape of path"); - dt_liquify_layers[DT_LIQUIFY_LAYER_RADIUSPOINT].hint = _("drag to adjust warp radius"); + dt_liquify_layers[DT_LIQUIFY_LAYER_PATH].hint = _("ctrl-click: add node - right click: remove path\n" + "ctrl-alt-click: toggle line/curve"); + dt_liquify_layers[DT_LIQUIFY_LAYER_CENTERPOINT].hint + = _("click and drag to move - click: show/hide feathering controls\n" + "ctrl-click: autosmooth, cusp, smooth, symmetrical" + " - right click to remove"); + dt_liquify_layers[DT_LIQUIFY_LAYER_CTRLPOINT1].hint = _("drag to change shape of path"); + dt_liquify_layers[DT_LIQUIFY_LAYER_CTRLPOINT2].hint = _("drag to change shape of path"); + dt_liquify_layers[DT_LIQUIFY_LAYER_RADIUSPOINT].hint = _("drag to adjust warp radius"); dt_liquify_layers[DT_LIQUIFY_LAYER_HARDNESSPOINT1].hint = _("drag to adjust hardness (center)"); dt_liquify_layers[DT_LIQUIFY_LAYER_HARDNESSPOINT2].hint = _("drag to adjust hardness (feather)"); - dt_liquify_layers[DT_LIQUIFY_LAYER_STRENGTHPOINT].hint = _("drag to adjust warp strength\n" - "ctrl-click: linear, grow, and shrink"); + dt_liquify_layers[DT_LIQUIFY_LAYER_STRENGTHPOINT].hint = _("drag to adjust warp strength\n" + "ctrl-click: linear, grow, and shrink"); } -void gui_cleanup (dt_iop_module_t *module) +void gui_cleanup(dt_iop_module_t *module) { - dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *) module->gui_data; - if (g) + dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *)module->gui_data; + if(g) { - cairo_destroy (g->fake_cr); - dt_pthread_mutex_destroy (&g->lock); - free (g); + cairo_destroy(g->fake_cr); + dt_pthread_mutex_destroy(&g->lock); + free(g); } module->gui_data = NULL; } -void init_key_accels (dt_iop_module_so_t *module) +void init_key_accels(dt_iop_module_so_t *module) { - dt_accel_register_iop (module, FALSE, NC_("accel", "point tool"), 0, 0); - dt_accel_register_iop (module, FALSE, NC_("accel", "line tool"), 0, 0); - dt_accel_register_iop (module, FALSE, NC_("accel", "curve tool"), 0, 0); - dt_accel_register_iop (module, FALSE, NC_("accel", "node tool"), 0, 0); + dt_accel_register_iop(module, FALSE, NC_("accel", "point tool"), 0, 0); + dt_accel_register_iop(module, FALSE, NC_("accel", "line tool"), 0, 0); + dt_accel_register_iop(module, FALSE, NC_("accel", "curve tool"), 0, 0); + dt_accel_register_iop(module, FALSE, NC_("accel", "node tool"), 0, 0); } -void connect_key_accels (dt_iop_module_t *module) +void connect_key_accels(dt_iop_module_t *module) { - const dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *) module->gui_data; + const dt_iop_liquify_gui_data_t *g = (dt_iop_liquify_gui_data_t *)module->gui_data; - dt_accel_connect_button_iop (module, "point tool", GTK_WIDGET (g->btn_point_tool)); - dt_accel_connect_button_iop (module, "line tool", GTK_WIDGET (g->btn_line_tool)); - dt_accel_connect_button_iop (module, "curve tool", GTK_WIDGET (g->btn_curve_tool)); - dt_accel_connect_button_iop (module, "node tool", GTK_WIDGET (g->btn_node_tool)); + dt_accel_connect_button_iop(module, "point tool", GTK_WIDGET(g->btn_point_tool)); + dt_accel_connect_button_iop(module, "line tool", GTK_WIDGET(g->btn_line_tool)); + dt_accel_connect_button_iop(module, "curve tool", GTK_WIDGET(g->btn_curve_tool)); + dt_accel_connect_button_iop(module, "node tool", GTK_WIDGET(g->btn_node_tool)); } // defgroup Button paint functions -#define PREAMBLE \ - cairo_save (cr); \ - const gint s = MIN (w, h); \ - cairo_translate (cr, x + (w / 2.0) - (s / 2.0), \ - y + (h / 2.0) - (s / 2.0)); \ - cairo_scale (cr, s, s); \ - cairo_push_group (cr); \ - cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0); \ - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); \ - cairo_set_line_width (cr, 0.2); - -#define POSTAMBLE \ - cairo_pop_group_to_source (cr); \ - cairo_paint_with_alpha (cr, flags & CPF_ACTIVE ? 1.0 : 0.5); \ - cairo_restore (cr); - -static void _liquify_cairo_paint_point_tool (cairo_t *cr, - const gint x, const gint y, const gint w, const gint h, const gint flags) +#define PREAMBLE \ + cairo_save(cr); \ + const gint s = MIN(w, h); \ + cairo_translate(cr, x + (w / 2.0) - (s / 2.0), y + (h / 2.0) - (s / 2.0)); \ + cairo_scale(cr, s, s); \ + cairo_push_group(cr); \ + cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); \ + cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); \ + cairo_set_line_width(cr, 0.2); + +#define POSTAMBLE \ + cairo_pop_group_to_source(cr); \ + cairo_paint_with_alpha(cr, flags &CPF_ACTIVE ? 1.0 : 0.5); \ + cairo_restore(cr); + +static void _liquify_cairo_paint_point_tool(cairo_t *cr, const gint x, const gint y, const gint w, const gint h, + const gint flags) { PREAMBLE; - cairo_new_sub_path (cr); - cairo_arc (cr, 0.5, 0.5, 0.2, 0.0, 2 * M_PI); - cairo_fill (cr); + cairo_new_sub_path(cr); + cairo_arc(cr, 0.5, 0.5, 0.2, 0.0, 2 * M_PI); + cairo_fill(cr); POSTAMBLE; } -static void _liquify_cairo_paint_line_tool (cairo_t *cr, - const gint x, const gint y, const gint w, const gint h, const gint flags) +static void _liquify_cairo_paint_line_tool(cairo_t *cr, const gint x, const gint y, const gint w, const gint h, + const gint flags) { PREAMBLE; - cairo_move_to (cr, 0.1, 0.9); - cairo_line_to (cr, 0.9, 0.1); - cairo_stroke (cr); + cairo_move_to(cr, 0.1, 0.9); + cairo_line_to(cr, 0.9, 0.1); + cairo_stroke(cr); POSTAMBLE; } -static void _liquify_cairo_paint_curve_tool (cairo_t *cr, - const gint x, const gint y, const gint w, const gint h, const gint flags) +static void _liquify_cairo_paint_curve_tool(cairo_t *cr, const gint x, const gint y, const gint w, const gint h, + const gint flags) { PREAMBLE; - cairo_move_to (cr, 0.1, 0.9); - cairo_curve_to (cr, 0.1, 0.5, 0.5, 0.1, 0.9, 0.1); - cairo_stroke (cr); + cairo_move_to(cr, 0.1, 0.9); + cairo_curve_to(cr, 0.1, 0.5, 0.5, 0.1, 0.9, 0.1); + cairo_stroke(cr); POSTAMBLE; } -static void _liquify_cairo_paint_node_tool (cairo_t *cr, - const gint x, const gint y, const gint w, const gint h, const gint flags) +static void _liquify_cairo_paint_node_tool(cairo_t *cr, const gint x, const gint y, const gint w, const gint h, + const gint flags) { PREAMBLE; - const double dashed[] = {0.2, 0.2}; - cairo_set_dash (cr, dashed, 2, 0); - cairo_set_line_width (cr, 0.1); + const double dashed[] = { 0.2, 0.2 }; + cairo_set_dash(cr, dashed, 2, 0); + cairo_set_line_width(cr, 0.1); - cairo_arc (cr, 0.75, 0.75, 0.75, 2.8, 4.7124); - cairo_stroke (cr); + cairo_arc(cr, 0.75, 0.75, 0.75, 2.8, 4.7124); + cairo_stroke(cr); - cairo_rectangle (cr, 0.2, 0.0, 0.4, 0.4); - cairo_fill (cr); + cairo_rectangle(cr, 0.2, 0.0, 0.4, 0.4); + cairo_fill(cr); - cairo_move_to (cr, 0.4, 0.2); - cairo_line_to (cr, 0.5, 1.0); - cairo_line_to (cr, 0.9, 0.7); - cairo_close_path (cr); - cairo_fill (cr); + cairo_move_to(cr, 0.4, 0.2); + cairo_line_to(cr, 0.5, 1.0); + cairo_line_to(cr, 0.9, 0.7); + cairo_close_path(cr); + cairo_fill(cr); POSTAMBLE; } diff --git a/src/iop/lowlight.c b/src/iop/lowlight.c index fa4a20cb287b..553127dec81b 100644 --- a/src/iop/lowlight.c +++ b/src/iop/lowlight.c @@ -262,8 +262,7 @@ void init_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pi default_params->transition_y[DT_IOP_LOWLIGHT_BANDS - 2]); for(int k = 0; k < DT_IOP_LOWLIGHT_BANDS; k++) (void)dt_draw_curve_add_point(d->curve, default_params->transition_x[k], default_params->transition_y[k]); - (void)dt_draw_curve_add_point(d->curve, default_params->transition_x[1] + 1.0, - default_params->transition_y[1]); + (void)dt_draw_curve_add_point(d->curve, default_params->transition_x[1] + 1.0, default_params->transition_y[1]); } void cleanup_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece) @@ -288,7 +287,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_lowlight_params_t)); module->default_params = calloc(1, sizeof(dt_iop_lowlight_params_t)); module->default_enabled = 0; // we're a rather slow and rare op. - module->priority = 617; // module order created by iop_dependencies.py, do not edit! + module->priority = 623; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_lowlight_params_t); module->gui_data = NULL; dt_iop_lowlight_params_t tmp; @@ -469,8 +468,8 @@ void init_presets(dt_iop_module_so_t *self) } // fills in new parameters based on mouse position (in 0,1) -static void dt_iop_lowlight_get_params(dt_iop_lowlight_params_t *p, const double mouse_x, - const double mouse_y, const float rad) +static void dt_iop_lowlight_get_params(dt_iop_lowlight_params_t *p, const double mouse_x, const double mouse_y, + const float rad) { for(int k = 0; k < DT_IOP_LOWLIGHT_BANDS; k++) { @@ -531,8 +530,7 @@ static gboolean lowlight_draw(GtkWidget *widget, cairo_t *crf, gpointer user_dat dt_draw_curve_set_point(c->transition_curve, k + 1, p.transition_x[k], p.transition_y[k]); dt_draw_curve_set_point(c->transition_curve, DT_IOP_LOWLIGHT_BANDS + 1, p.transition_x[1] + 1.0, p.transition_y[DT_IOP_LOWLIGHT_BANDS - 1]); - dt_draw_curve_calc_values(c->transition_curve, 0.0, 1.0, DT_IOP_LOWLIGHT_RES, c->draw_min_xs, - c->draw_min_ys); + dt_draw_curve_calc_values(c->transition_curve, 0.0, 1.0, DT_IOP_LOWLIGHT_RES, c->draw_min_xs, c->draw_min_ys); p = *(dt_iop_lowlight_params_t *)self->params; dt_iop_lowlight_get_params(&p, c->mouse_x, .0, c->mouse_radius); @@ -542,8 +540,7 @@ static gboolean lowlight_draw(GtkWidget *widget, cairo_t *crf, gpointer user_dat dt_draw_curve_set_point(c->transition_curve, k + 1, p.transition_x[k], p.transition_y[k]); dt_draw_curve_set_point(c->transition_curve, DT_IOP_LOWLIGHT_BANDS + 1, p.transition_x[1] + 1.0, p.transition_y[DT_IOP_LOWLIGHT_BANDS - 1]); - dt_draw_curve_calc_values(c->transition_curve, 0.0, 1.0, DT_IOP_LOWLIGHT_RES, c->draw_max_xs, - c->draw_max_ys); + dt_draw_curve_calc_values(c->transition_curve, 0.0, 1.0, DT_IOP_LOWLIGHT_RES, c->draw_max_xs, c->draw_max_ys); } cairo_save(cr); @@ -591,8 +588,7 @@ static gboolean lowlight_draw(GtkWidget *widget, cairo_t *crf, gpointer user_dat cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(1.)); for(int k = 0; k < DT_IOP_LOWLIGHT_BANDS; k++) { - cairo_arc(cr, width * p.transition_x[k], -height * p.transition_y[k], DT_PIXEL_APPLY_DPI(3.0), 0.0, - 2.0 * M_PI); + cairo_arc(cr, width * p.transition_x[k], -height * p.transition_y[k], DT_PIXEL_APPLY_DPI(3.0), 0.0, 2.0 * M_PI); if(c->x_move == k) cairo_fill(cr); else @@ -630,7 +626,7 @@ static gboolean lowlight_draw(GtkWidget *widget, cairo_t *crf, gpointer user_dat PangoRectangle ink; PangoFontDescription *desc = pango_font_description_copy_static(darktable.bauhaus->pango_font_desc); pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD); - pango_font_description_set_absolute_size(desc,(.06 * height) * PANGO_SCALE); + pango_font_description_set_absolute_size(desc, (.06 * height) * PANGO_SCALE); layout = pango_cairo_create_layout(cr); pango_layout_set_font_description(layout, desc); cairo_set_source_rgb(cr, .1, .1, .1); @@ -722,15 +718,14 @@ static gboolean lowlight_motion_notify(GtkWidget *widget, GdkEventMotion *event, gtk_widget_queue_draw(widget); gint x, y; #if GTK_CHECK_VERSION(3, 20, 0) - gdk_window_get_device_position(event->window, - gdk_seat_get_pointer(gdk_display_get_default_seat( - gdk_window_get_display(event->window))), - &x, &y, 0); + gdk_window_get_device_position( + event->window, gdk_seat_get_pointer(gdk_display_get_default_seat(gdk_window_get_display(event->window))), &x, + &y, 0); #else - gdk_window_get_device_position(event->window, - gdk_device_manager_get_client_pointer( - gdk_display_get_device_manager(gdk_window_get_display(event->window))), - &x, &y, NULL); + gdk_window_get_device_position( + event->window, + gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gdk_window_get_display(event->window))), + &x, &y, NULL); #endif return TRUE; } @@ -839,9 +834,9 @@ void gui_init(struct dt_iop_module_t *self) gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(c->area), FALSE, FALSE, 0); gtk_widget_add_events(GTK_WIDGET(c->area), GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK - | GDK_SMOOTH_SCROLL_MASK); + | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK + | GDK_SMOOTH_SCROLL_MASK); g_signal_connect(G_OBJECT(c->area), "draw", G_CALLBACK(lowlight_draw), self); g_signal_connect(G_OBJECT(c->area), "button-press-event", G_CALLBACK(lowlight_button_press), self); g_signal_connect(G_OBJECT(c->area), "button-release-event", G_CALLBACK(lowlight_button_release), self); diff --git a/src/iop/lowpass.c b/src/iop/lowpass.c index 1e460f2fb54c..ac43dcbaf4c4 100644 --- a/src/iop/lowpass.c +++ b/src/iop/lowpass.c @@ -138,8 +138,8 @@ int groups() return IOP_GROUP_EFFECT; } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 1 && new_version == 4) { @@ -332,8 +332,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m #endif void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling) + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling) { dt_iop_lowpass_data_t *d = (dt_iop_lowpass_data_t *)piece->data; @@ -351,7 +350,8 @@ void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t if(d->lowpass_algo == LOWPASS_ALGO_BILATERAL) { // bilateral filter - tiling->factor = 2.0f + fmax(1.0f, (float)dt_bilateral_memory_use(width, height, sigma_s, sigma_r) / basebuffer); + tiling->factor = 2.0f + + fmax(1.0f, (float)dt_bilateral_memory_use(width, height, sigma_s, sigma_r) / basebuffer); tiling->maxbuf = fmax(1.0f, (float)dt_bilateral_singlebuffer_size(width, height, sigma_s, sigma_r) / basebuffer); } @@ -598,7 +598,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_lowpass_params_t)); module->default_params = calloc(1, sizeof(dt_iop_lowpass_params_t)); module->default_enabled = 0; - module->priority = 749; // module order created by iop_dependencies.py, do not edit! + module->priority = 753; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_lowpass_params_t); module->gui_data = NULL; dt_iop_lowpass_params_t tmp = (dt_iop_lowpass_params_t){ 0, 10.0f, 1.0f, 0.0f, 1.0f, LOWPASS_ALGO_GAUSSIAN, 1 }; @@ -609,8 +609,7 @@ void init(dt_iop_module_t *module) void init_global(dt_iop_module_so_t *module) { const int program = 6; // gaussian.cl, from programs.conf - dt_iop_lowpass_global_data_t *gd - = (dt_iop_lowpass_global_data_t *)malloc(sizeof(dt_iop_lowpass_global_data_t)); + dt_iop_lowpass_global_data_t *gd = (dt_iop_lowpass_global_data_t *)malloc(sizeof(dt_iop_lowpass_global_data_t)); module->data = gd; gd->kernel_lowpass_mix = dt_opencl_create_kernel(program, "lowpass_mix"); } diff --git a/src/iop/monochrome.c b/src/iop/monochrome.c index dca71a3f75f6..6129a0ebd375 100644 --- a/src/iop/monochrome.c +++ b/src/iop/monochrome.c @@ -82,8 +82,8 @@ int flags() return IOP_FLAGS_INCLUDE_IN_STYLES | IOP_FLAGS_SUPPORTS_BLENDING | IOP_FLAGS_ALLOW_TILING; } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 1 && new_version == 2) { @@ -189,8 +189,7 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const { const float tt = envelope(in[0]); const float t = tt + (1.0f - tt) * (1.0f - d->highlights); - out[0] = (1.0f - t) * in[0] - + t * out[0] * (1.0f / 100.0f) * in[0]; // normalized filter * input brightness + out[0] = (1.0f - t) * in[0] + t * out[0] * (1.0f / 100.0f) * in[0]; // normalized filter * input brightness } } } @@ -265,8 +264,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m #endif void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling) + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling) { const float scale = piece->iscale / roi_in->scale; const float sigma_s = 20.0f / scale; @@ -279,8 +277,7 @@ void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t const size_t basebuffer = width * height * channels * sizeof(float); tiling->factor = 3.0f + (float)dt_bilateral_memory_use(width, height, sigma_s, sigma_r) / basebuffer; - tiling->maxbuf - = fmax(1.0f, (float)dt_bilateral_singlebuffer_size(width, height, sigma_s, sigma_r) / basebuffer); + tiling->maxbuf = fmax(1.0f, (float)dt_bilateral_singlebuffer_size(width, height, sigma_s, sigma_r) / basebuffer); tiling->overhead = 0; tiling->overlap = ceilf(4 * sigma_s); tiling->xalign = 1; @@ -337,7 +334,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_monochrome_params_t)); module->default_params = calloc(1, sizeof(dt_iop_monochrome_params_t)); module->default_enabled = 0; - module->priority = 632; // module order created by iop_dependencies.py, do not edit! + module->priority = 637; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_monochrome_params_t); module->gui_data = NULL; dt_iop_monochrome_params_t tmp = (dt_iop_monochrome_params_t){ 0., 0., 2., 0. }; @@ -376,7 +373,7 @@ static gboolean dt_iop_monochrome_draw(GtkWidget *widget, cairo_t *crf, gpointer p->b = self->picked_color[2]; float da = self->picked_color_max[1] - self->picked_color_min[1]; float db = self->picked_color_max[2] - self->picked_color_min[2]; - p->size = CLAMP((da + db)/128.0, .5, 3.0); + p->size = CLAMP((da + db) / 128.0, .5, 3.0); if(old_a != p->a || old_b != p->b || old_size != p->size) dt_dev_add_history_item(darktable.develop, self, TRUE); } @@ -420,8 +417,7 @@ static gboolean dt_iop_monochrome_draw(GtkWidget *widget, cairo_t *crf, gpointer cmsDoTransform(g->xform, &Lab, rgb, 1); cairo_set_source_rgb(cr, rgb[0], rgb[1], rgb[2]); cairo_rectangle(cr, width * i / (float)cells, height * j / (float)cells, - width / (float)cells - DT_PIXEL_APPLY_DPI(1), - height / (float)cells - DT_PIXEL_APPLY_DPI(1)); + width / (float)cells - DT_PIXEL_APPLY_DPI(1), height / (float)cells - DT_PIXEL_APPLY_DPI(1)); cairo_fill(cr); } cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT); @@ -459,14 +455,13 @@ static gboolean dt_iop_monochrome_motion_notify(GtkWidget *widget, GdkEventMotio } gint x, y; #if GTK_CHECK_VERSION(3, 20, 0) - gdk_window_get_device_position(event->window, - gdk_seat_get_pointer(gdk_display_get_default_seat(gtk_widget_get_display(widget))), - &x, &y, 0); + gdk_window_get_device_position( + event->window, gdk_seat_get_pointer(gdk_display_get_default_seat(gtk_widget_get_display(widget))), &x, &y, 0); #else - gdk_window_get_device_position(event->window, - gdk_device_manager_get_client_pointer( - gdk_display_get_device_manager(gdk_window_get_display(event->window))), - &x, &y, NULL); + gdk_window_get_device_position( + event->window, + gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gdk_window_get_display(event->window))), + &x, &y, NULL); #endif return TRUE; } @@ -588,18 +583,17 @@ void gui_init(struct dt_iop_module_t *self) self->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, DT_BAUHAUS_SPACE); g->area = GTK_DRAWING_AREA(dtgtk_drawing_area_new_with_aspect_ratio(1.0)); gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(g->area), TRUE, TRUE, 0); - gtk_widget_set_tooltip_text(GTK_WIDGET(g->area), _("drag and scroll mouse wheel to adjust the virtual color filter")); + gtk_widget_set_tooltip_text(GTK_WIDGET(g->area), + _("drag and scroll mouse wheel to adjust the virtual color filter")); gtk_widget_add_events(GTK_WIDGET(g->area), GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK - | GDK_SMOOTH_SCROLL_MASK); + | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK + | GDK_SMOOTH_SCROLL_MASK); g_signal_connect(G_OBJECT(g->area), "draw", G_CALLBACK(dt_iop_monochrome_draw), self); g_signal_connect(G_OBJECT(g->area), "button-press-event", G_CALLBACK(dt_iop_monochrome_button_press), self); - g_signal_connect(G_OBJECT(g->area), "button-release-event", G_CALLBACK(dt_iop_monochrome_button_release), - self); - g_signal_connect(G_OBJECT(g->area), "motion-notify-event", G_CALLBACK(dt_iop_monochrome_motion_notify), - self); + g_signal_connect(G_OBJECT(g->area), "button-release-event", G_CALLBACK(dt_iop_monochrome_button_release), self); + g_signal_connect(G_OBJECT(g->area), "motion-notify-event", G_CALLBACK(dt_iop_monochrome_motion_notify), self); g_signal_connect(G_OBJECT(g->area), "leave-notify-event", G_CALLBACK(dt_iop_monochrome_leave_notify), self); g_signal_connect(G_OBJECT(g->area), "scroll-event", G_CALLBACK(dt_iop_monochrome_scrolled), self); diff --git a/src/iop/nlmeans.c b/src/iop/nlmeans.c index 1ccafa038169..6c5dd22a84b0 100644 --- a/src/iop/nlmeans.c +++ b/src/iop/nlmeans.c @@ -80,8 +80,8 @@ const char *name() return _("denoise (non-local means)"); } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 1 && new_version == 2) { @@ -214,10 +214,14 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m } int hblocksize; - dt_opencl_local_buffer_t hlocopt - = (dt_opencl_local_buffer_t){ .xoffset = 2 * P, .xfactor = 1, .yoffset = 0, .yfactor = 1, - .cellsize = sizeof(float), .overhead = 0, - .sizex = 1 << 16, .sizey = 1 }; + dt_opencl_local_buffer_t hlocopt = (dt_opencl_local_buffer_t){.xoffset = 2 * P, + .xfactor = 1, + .yoffset = 0, + .yfactor = 1, + .cellsize = sizeof(float), + .overhead = 0, + .sizex = 1 << 16, + .sizey = 1 }; if(dt_opencl_local_buffer_opt(devid, gd->kernel_nlmeans_horiz, &hlocopt)) hblocksize = hlocopt.sizex; @@ -225,10 +229,14 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m hblocksize = 1; int vblocksize; - dt_opencl_local_buffer_t vlocopt - = (dt_opencl_local_buffer_t){ .xoffset = 1, .xfactor = 1, .yoffset = 2 * P, .yfactor = 1, - .cellsize = sizeof(float), .overhead = 0, - .sizex = 1, .sizey = 1 << 16 }; + dt_opencl_local_buffer_t vlocopt = (dt_opencl_local_buffer_t){.xoffset = 1, + .xfactor = 1, + .yoffset = 2 * P, + .yfactor = 1, + .cellsize = sizeof(float), + .overhead = 0, + .sizex = 1, + .sizey = 1 << 16 }; if(dt_opencl_local_buffer_opt(devid, gd->kernel_nlmeans_vert, &vlocopt)) vblocksize = vlocopt.sizey; @@ -350,8 +358,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling) + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling) { dt_iop_nlmeans_params_t *d = (dt_iop_nlmeans_params_t *)piece->data; const int P = ceilf(d->radius * fmin(roi_in->scale, 2.0f) / fmax(piece->iscale, 1.0f)); // pixel filter size @@ -507,7 +514,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const // free shared tmp memory: dt_free_align(Sa); - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #if defined(__SSE__) @@ -701,7 +709,8 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c // free shared tmp memory: dt_free_align(Sa); - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #endif @@ -722,7 +731,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_nlmeans_params_t)); module->default_params = calloc(1, sizeof(dt_iop_nlmeans_params_t)); // about the first thing to do in Lab space: - module->priority = 529; // module order created by iop_dependencies.py, do not edit! + module->priority = 536; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_nlmeans_params_t); module->gui_data = NULL; module->data = NULL; @@ -737,8 +746,7 @@ void cleanup(dt_iop_module_t *module) void init_global(dt_iop_module_so_t *module) { const int program = 5; // nlmeans.cl, from programs.conf - dt_iop_nlmeans_global_data_t *gd - = (dt_iop_nlmeans_global_data_t *)malloc(sizeof(dt_iop_nlmeans_global_data_t)); + dt_iop_nlmeans_global_data_t *gd = (dt_iop_nlmeans_global_data_t *)malloc(sizeof(dt_iop_nlmeans_global_data_t)); module->data = gd; gd->kernel_nlmeans_init = dt_opencl_create_kernel(program, "nlmeans_init"); gd->kernel_nlmeans_dist = dt_opencl_create_kernel(program, "nlmeans_dist"); diff --git a/src/iop/overexposed.c b/src/iop/overexposed.c index a9ebc6fd594e..486b1174f0b7 100644 --- a/src/iop/overexposed.c +++ b/src/iop/overexposed.c @@ -42,19 +42,18 @@ typedef enum dt_iop_overexposed_colorscheme_t DT_IOP_OVEREXPOSED_PURPLEGREEN = 2 } dt_iop_overexposed_colorscheme_t; -static const float dt_iop_overexposed_colors[][2][4] - = { { - { 0.0f, 0.0f, 0.0f, 1.0f }, // black - { 1.0f, 1.0f, 1.0f, 1.0f } // white - }, - { - { 1.0f, 0.0f, 0.0f, 1.0f }, // red - { 0.0f, 0.0f, 1.0f, 1.0f } // blue - }, - { - { 0.371f, 0.434f, 0.934f, 1.0f }, // purple (#5f6fef) - { 0.512f, 0.934f, 0.371f, 1.0f } // green (#83ef5f) - } }; +static const float dt_iop_overexposed_colors[][2][4] = { { + { 0.0f, 0.0f, 0.0f, 1.0f }, // black + { 1.0f, 1.0f, 1.0f, 1.0f } // white + }, + { + { 1.0f, 0.0f, 0.0f, 1.0f }, // red + { 0.0f, 0.0f, 1.0f, 1.0f } // blue + }, + { + { 0.371f, 0.434f, 0.934f, 1.0f }, // purple (#5f6fef) + { 0.512f, 0.934f, 0.371f, 1.0f } // green (#83ef5f) + } }; typedef struct dt_iop_overexposed_global_data_t { @@ -82,8 +81,8 @@ int flags() } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { // we do no longer have module params in here and just ignore any legacy entries return 0; @@ -153,7 +152,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const } } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #if defined(__SSE__) @@ -202,7 +202,8 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c } _mm_sfence(); - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #endif @@ -286,7 +287,7 @@ void init(dt_iop_module_t *module) module->default_params = calloc(1, sizeof(dt_iop_overexposed_t)); module->hide_enable_button = 1; module->default_enabled = 1; - module->priority = 926; // module order created by iop_dependencies.py, do not edit! + module->priority = 927; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_overexposed_t); module->gui_data = NULL; } diff --git a/src/iop/profile_gamma.c b/src/iop/profile_gamma.c index 288f1a14b869..3ee6b25b6e92 100644 --- a/src/iop/profile_gamma.c +++ b/src/iop/profile_gamma.c @@ -163,7 +163,8 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c } } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } static void linear_callback(GtkWidget *slider, gpointer user_data) @@ -244,10 +245,10 @@ void commit_params(dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pixelpipe_ // now the extrapolation stuff: const float x[4] = { 0.7f, 0.8f, 0.9f, 1.0f }; - const float y[4] = { d->table[CLAMP((int)(x[0] * 0x10000ul), 0, 0xffff)], - d->table[CLAMP((int)(x[1] * 0x10000ul), 0, 0xffff)], - d->table[CLAMP((int)(x[2] * 0x10000ul), 0, 0xffff)], - d->table[CLAMP((int)(x[3] * 0x10000ul), 0, 0xffff)] }; + const float y[4] + = { d->table[CLAMP((int)(x[0] * 0x10000ul), 0, 0xffff)], d->table[CLAMP((int)(x[1] * 0x10000ul), 0, 0xffff)], + d->table[CLAMP((int)(x[2] * 0x10000ul), 0, 0xffff)], + d->table[CLAMP((int)(x[3] * 0x10000ul), 0, 0xffff)] }; dt_iop_estimate_exp(x, y, 4, d->unbounded_coeffs); } @@ -277,7 +278,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_profilegamma_params_t)); module->default_params = calloc(1, sizeof(dt_iop_profilegamma_params_t)); module->default_enabled = 0; - module->priority = 323; // module order created by iop_dependencies.py, do not edit! + module->priority = 333; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_profilegamma_params_t); module->gui_data = NULL; dt_iop_profilegamma_params_t tmp = (dt_iop_profilegamma_params_t){ 0.1, 0.45 }; diff --git a/src/iop/rawdenoise.c b/src/iop/rawdenoise.c index d89f77e74811..81c6b655185c 100644 --- a/src/iop/rawdenoise.c +++ b/src/iop/rawdenoise.c @@ -165,8 +165,7 @@ static void wavelet_denoise(const float *const in, float *const out, const dt_io #endif for(int col = 0; col < halfwidth; col++) { - hat_transform(fimg + pass2 + (size_t)col * halfheight, fimg + pass1 + col, halfwidth, halfheight, - 1 << lev); + hat_transform(fimg + pass2 + (size_t)col * halfheight, fimg + pass1 + col, halfwidth, halfheight, 1 << lev); } // filter vertically and transpose back #ifdef _OPENMP @@ -174,8 +173,7 @@ static void wavelet_denoise(const float *const in, float *const out, const dt_io #endif for(int row = 0; row < halfheight; row++) { - hat_transform(fimg + pass3 + (size_t)row * halfwidth, fimg + pass2 + row, halfheight, halfwidth, - 1 << lev); + hat_transform(fimg + pass3 + (size_t)row * halfwidth, fimg + pass2 + row, halfheight, halfwidth, 1 << lev); } const float thold = threshold * noise[lev]; @@ -202,7 +200,7 @@ static void wavelet_denoise(const float *const in, float *const out, const dt_io for(; col < roi->width; col += 2, fimgp++, outp += 2) { float d = fimgp[0] + fimgp[lastpass]; - *outp = d * d; + *outp = d *d; } } } @@ -335,7 +333,7 @@ static void wavelet_denoise_xtrans(const float *const in, float *out, const dt_i if(FCxtrans(row, col, roi, xtrans) == c) { float d = fimgp[0] + fimgp[lastpass]; - *outp = d * d; + *outp = d *d; } } } @@ -353,13 +351,13 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const if(!(d->threshold > 0.0f)) { - memcpy(ovoid, ivoid, (size_t)sizeof(float)*width*height); + memcpy(ovoid, ivoid, (size_t)sizeof(float) * width * height); } else { const uint32_t filters = piece->pipe->dsc.filters; - const uint8_t(*const xtrans)[6] = (const uint8_t(*const)[6])piece->pipe->dsc.xtrans; - if (filters != 9u) + const uint8_t (*const xtrans)[6] = (const uint8_t (*const)[6])piece->pipe->dsc.xtrans; + if(filters != 9u) wavelet_denoise(ivoid, ovoid, roi_in, d->threshold, filters); else wavelet_denoise_xtrans(ivoid, ovoid, roi_in, d->threshold, xtrans); @@ -369,7 +367,7 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void reload_defaults(dt_iop_module_t *module) { // init defaults: - dt_iop_rawdenoise_params_t tmp = (dt_iop_rawdenoise_params_t){ .threshold = 0.01 }; + dt_iop_rawdenoise_params_t tmp = (dt_iop_rawdenoise_params_t){.threshold = 0.01 }; // we might be called from presets update infrastructure => there is no image if(!module->dev) goto end; @@ -394,7 +392,7 @@ void init(dt_iop_module_t *module) module->default_enabled = 0; // raw denoise must come just before demosaicing. - module->priority = 102; // module order created by iop_dependencies.py, do not edit! + module->priority = 101; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_rawdenoise_params_t); module->gui_data = NULL; } @@ -415,8 +413,7 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *params, dt_dev d->threshold = p->threshold; - if (!(pipe->image.flags & DT_IMAGE_RAW)) - piece->enabled = 0; + if(!(pipe->image.flags & DT_IMAGE_RAW)) piece->enabled = 0; } void init_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece) diff --git a/src/iop/rawoverexposed.c b/src/iop/rawoverexposed.c index 01abdbbd572e..3a44ff6c030f 100644 --- a/src/iop/rawoverexposed.c +++ b/src/iop/rawoverexposed.c @@ -30,12 +30,12 @@ #include "develop/imageop_math.h" // for FC, FCxtrans #include "develop/pixelpipe.h" // for dt_dev_pixelpipe_type_t::DT_DEV_PI... #include "develop/tiling.h" -#include "iop/iop_api.h" // for dt_iop_params_t -#include <glib/gi18n.h> // for _ -#include <gtk/gtktypes.h> // for GtkWidget -#include <stdint.h> // for uint16_t, uint8_t, uint32_t -#include <stdlib.h> // for size_t, free, NULL, calloc, malloc -#include <string.h> // for memcpy +#include "iop/iop_api.h" // for dt_iop_params_t +#include <glib/gi18n.h> // for _ +#include <gtk/gtktypes.h> // for GtkWidget +#include <stdint.h> // for uint16_t, uint8_t, uint32_t +#include <stdlib.h> // for size_t, free, NULL, calloc, malloc +#include <string.h> // for memcpy DT_MODULE(1) @@ -181,7 +181,7 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c // NOT FROM THE PIPE !!! const uint32_t filters = image->buf_dsc.filters; - const uint8_t(*const xtrans)[6] = (const uint8_t(*const)[6])image->buf_dsc.xtrans; + const uint8_t (*const xtrans)[6] = (const uint8_t (*const)[6])image->buf_dsc.xtrans; // acquire temp memory for distorted pixel coords const size_t coordbufsize = (size_t)roi_out->width * 2; @@ -249,7 +249,8 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c dt_mipmap_cache_release(darktable.mipmap_cache, &buf); - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #ifdef HAVE_OPENCL @@ -361,8 +362,8 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m if(filters == 9u) { - dev_xtrans - = dt_opencl_copy_host_to_device_constant(devid, sizeof(image->buf_dsc.xtrans), (void *)image->buf_dsc.xtrans); + dev_xtrans = dt_opencl_copy_host_to_device_constant(devid, sizeof(image->buf_dsc.xtrans), + (void *)image->buf_dsc.xtrans); if(dev_xtrans == NULL) goto error; } @@ -414,8 +415,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m #endif void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling) + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling) { dt_develop_t *dev = self->dev; const dt_image_t *const image = &(dev->image_storage); @@ -437,7 +437,7 @@ void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t dt_mipmap_cache_release(darktable.mipmap_cache, &buf); - tiling->factor = 2.5f; // in + out + coordinates + tiling->factor = 2.5f; // in + out + coordinates tiling->maxbuf = 1.0f; tiling->overhead = (size_t)raw_width * raw_height * sizeof(uint16_t); tiling->overlap = 0; @@ -499,7 +499,7 @@ void init(dt_iop_module_t *module) module->default_params = calloc(1, sizeof(dt_iop_rawoverexposed_t)); module->hide_enable_button = 1; module->default_enabled = 1; - module->priority = 941; // module order created by iop_dependencies.py, do not edit! + module->priority = 942; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_rawoverexposed_t); module->gui_data = NULL; } diff --git a/src/iop/rawprepare.c b/src/iop/rawprepare.c index 4c754711c9b3..16b864c30588 100644 --- a/src/iop/rawprepare.c +++ b/src/iop/rawprepare.c @@ -50,7 +50,8 @@ static const struct typedef struct dt_iop_rawprepare_params_t { - union { + union + { struct { int32_t x, y, width, height; @@ -186,8 +187,7 @@ int distort_transform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, floa return 1; } -int distort_backtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, float *points, - size_t points_count) +int distort_backtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, float *points, size_t points_count) { dt_iop_rawprepare_data_t *d = (dt_iop_rawprepare_data_t *)piece->data; @@ -244,8 +244,7 @@ void output_format(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixel dsc->rawprepare.raw_white_point = d->rawprepare.raw_white_point; } -static void adjust_xtrans_filters(dt_dev_pixelpipe_t *pipe, - uint32_t crop_x, uint32_t crop_y) +static void adjust_xtrans_filters(dt_dev_pixelpipe_t *pipe, uint32_t crop_x, uint32_t crop_y) { for(int i = 0; i < 6; ++i) { @@ -372,8 +371,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const } #if defined(__SSE2__) -void process_sse2(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, - void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) +void process_sse2(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid, + const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) { const dt_iop_rawprepare_data_t *const d = (dt_iop_rawprepare_data_t *)piece->data; @@ -781,8 +780,7 @@ static void callback(GtkWidget *widget, gpointer *user_data) dt_iop_rawprepare_gui_data_t *g = (dt_iop_rawprepare_gui_data_t *)self->gui_data; dt_iop_rawprepare_params_t *p = (dt_iop_rawprepare_params_t *)self->params; - for(int i = 0; i < 4; i++) - p->raw_black_level_separate[i] = dt_bauhaus_slider_get(g->black_level_separate[i]); + for(int i = 0; i < 4; i++) p->raw_black_level_separate[i] = dt_bauhaus_slider_get(g->black_level_separate[i]); p->raw_white_point = dt_bauhaus_slider_get(g->white_point); if(dt_conf_get_bool("plugins/darkroom/rawprepare/allow_editing_crop")) diff --git a/src/iop/relight.c b/src/iop/relight.c index 6a0d5915a44b..39699593bd20 100644 --- a/src/iop/relight.c +++ b/src/iop/relight.c @@ -52,11 +52,9 @@ void init_presets(dt_iop_module_so_t *self) DT_DEBUG_SQLITE3_EXEC(dt_database_get(darktable.db), "BEGIN", NULL, NULL, NULL); dt_gui_presets_add_generic(_("fill-light 0.25EV with 4 zones"), self->op, self->version(), - &(dt_iop_relight_params_t){ 0.25, 0.25, 4.0 }, sizeof(dt_iop_relight_params_t), - 1); + &(dt_iop_relight_params_t){ 0.25, 0.25, 4.0 }, sizeof(dt_iop_relight_params_t), 1); dt_gui_presets_add_generic(_("fill-shadow -0.25EV with 4 zones"), self->op, self->version(), - &(dt_iop_relight_params_t){ -0.25, 0.25, 4.0 }, sizeof(dt_iop_relight_params_t), - 1); + &(dt_iop_relight_params_t){ -0.25, 0.25, 4.0 }, sizeof(dt_iop_relight_params_t), 1); DT_DEBUG_SQLITE3_EXEC(dt_database_get(darktable.db), "COMMIT", NULL, NULL, NULL); } @@ -191,8 +189,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m void init_global(dt_iop_module_so_t *module) { const int program = 8; // extended.cl, from programs.conf - dt_iop_relight_global_data_t *gd - = (dt_iop_relight_global_data_t *)malloc(sizeof(dt_iop_relight_global_data_t)); + dt_iop_relight_global_data_t *gd = (dt_iop_relight_global_data_t *)malloc(sizeof(dt_iop_relight_global_data_t)); module->data = gd; gd->kernel_relight = dt_opencl_create_kernel(program, "relight"); } @@ -210,9 +207,8 @@ static void picker_callback(GtkDarktableToggleButton *button, gpointer user_data dt_iop_module_t *self = (dt_iop_module_t *)user_data; if(darktable.gui->reset) return; - self->request_color_pick - = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)) ? DT_REQUEST_COLORPICK_MODULE - : DT_REQUEST_COLORPICK_OFF); + self->request_color_pick = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)) ? DT_REQUEST_COLORPICK_MODULE + : DT_REQUEST_COLORPICK_OFF); /* set the area sample size*/ if(self->request_color_pick != DT_REQUEST_COLORPICK_OFF) @@ -297,7 +293,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_relight_params_t)); module->default_params = calloc(1, sizeof(dt_iop_relight_params_t)); module->default_enabled = 0; - module->priority = 705; // module order created by iop_dependencies.py, do not edit! + module->priority = 710; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_relight_params_t); module->gui_data = NULL; dt_iop_relight_params_t tmp = (dt_iop_relight_params_t){ 0.33, 0, 4 }; @@ -366,8 +362,7 @@ void gui_init(struct dt_iop_module_t *self) GtkBox *hbox = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2)); #define NEUTRAL_GRAY 0.5 - static const GdkRGBA _gradient_L[] - = { { 0, 0, 0, 1.0 }, { NEUTRAL_GRAY, NEUTRAL_GRAY, NEUTRAL_GRAY, 1.0 } }; + static const GdkRGBA _gradient_L[] = { { 0, 0, 0, 1.0 }, { NEUTRAL_GRAY, NEUTRAL_GRAY, NEUTRAL_GRAY, 1.0 } }; g->gslider1 = DTGTK_GRADIENT_SLIDER(dtgtk_gradient_slider_new_with_color(_gradient_L[0], _gradient_L[1])); gtk_widget_set_tooltip_text(GTK_WIDGET(g->gslider1), _("select the center of fill-light")); diff --git a/src/iop/rlucy_deblur.c b/src/iop/rlucy_deblur.c index 81513bd6b239..410fd4aeed29 100644 --- a/src/iop/rlucy_deblur.c +++ b/src/iop/rlucy_deblur.c @@ -1,7 +1,9 @@ /* This file is part of darktable, - copyright (c) 2009--2010 johannes hanika. - copyright (c) 2014-2016 Roman Lebedev. + copyright (c) 2017 Edgardo Hoszowski. + copyright (c) 2017 Aurélien Pierre. + + This work would not have been possible without the research of Daniele Perrone, Paolo Favaro and Anath Levin. darktable is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,16 +18,16 @@ You should have received a copy of the GNU General Public License along with darktable. If not, see <http://www.gnu.org/licenses/>. */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "bauhaus/bauhaus.h" -#include "common/rlucy_deblur.h" +#include "develop/tiling.h" -#ifdef HAVE_FFTW3_OMP -#include <fftw3.h> -#endif +#include "iop/iop_api.h" +#include "common/rlucy_deblur.h" DT_MODULE_INTROSPECTION(1, dt_iop_rlucydeblur_params_t) @@ -34,34 +36,26 @@ DT_MODULE_INTROSPECTION(1, dt_iop_rlucydeblur_params_t) typedef struct dt_iop_rlucydeblur_params_t { int blur_type; - int refine_quality; + int quality; float ringing_factor; - int deblur_strength; int blur_width; - int blur_strength; - int refine; float mask[4]; int use_mask; - float auto_quality; float noise_reduction_factor; - int denoise; } dt_iop_rlucydeblur_params_t; + typedef struct dt_iop_rlucydeblur_gui_data_t { - int drawing; - float pt_down_x, pt_down_y, pt_last_x, pt_last_y; + int drawing; + float pt_down_x, pt_down_y, pt_last_x, pt_last_y; GtkWidget *bt_draw_focus_zone; GtkWidget *cmb_blur_type; - GtkWidget *sl_refine_quality; GtkWidget *sl_ringing_factor; - GtkWidget *sl_deblur_strength; GtkWidget *sl_blur_width; - GtkWidget *sl_blur_strength; - GtkWidget *chk_refine; GtkWidget *chk_use_mask; - GtkWidget *sl_auto_quality; + GtkWidget *sl_quality; GtkWidget *sl_noise_reduction_factor; } dt_iop_rlucydeblur_gui_data_t; @@ -69,7 +63,7 @@ typedef struct dt_iop_rlucydeblur_params_t dt_iop_rlucydeblur_data_t; const char *name() { - return _("richardson-lucy deblur"); + return _("optimized deblur"); } int groups() @@ -82,27 +76,31 @@ int flags() return IOP_FLAGS_SUPPORTS_BLENDING; } -#define PREAMBLE \ - cairo_save (cr); \ - const gint s = MIN (w, h); \ - cairo_translate (cr, x + (w / 2.0) - (s / 2.0), \ - y + (h / 2.0) - (s / 2.0)); \ - cairo_scale (cr, s, s); \ - cairo_push_group (cr); \ - cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0); \ - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); \ - cairo_set_line_width (cr, 0.1); - -#define POSTAMBLE \ - cairo_pop_group_to_source (cr); \ - cairo_paint_with_alpha (cr, flags & CPF_ACTIVE ? 1.0 : 0.5); \ - cairo_restore (cr); - -static void _cairo_paint_tool_draw_focus_zone(cairo_t *cr, - const gint x, const gint y, const gint w, const gint h, const gint flags) +#define TS 122 + +#define PREAMBLE \ + cairo_save(cr); \ + const gint s = MIN(w, h); \ + cairo_translate(cr, x + (w / 2.0) - (s / 2.0), y + (h / 2.0) - (s / 2.0)); \ + cairo_scale(cr, s, s); \ + cairo_push_group(cr); \ + cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); \ + cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); \ + cairo_set_line_width(cr, 0.1); + +#define POSTAMBLE \ + cairo_pop_group_to_source(cr); \ + cairo_paint_with_alpha(cr, flags &CPF_ACTIVE ? 1.0 : 0.5); \ + cairo_restore(cr); + + + +static void _cairo_paint_tool_draw_focus_zone(cairo_t *cr, const gint x, const gint y, const gint w, const gint h, + const gint flags) { + PREAMBLE; - + cairo_set_line_width(cr, 0.1); cairo_rectangle(cr, 0., 0., 1., 1.); cairo_stroke(cr); @@ -111,24 +109,13 @@ static void _cairo_paint_tool_draw_focus_zone(cairo_t *cr, } +/* Event and GUI objects callback functions */ + static void rlucy_blur_type_callback(GtkComboBox *combo, dt_iop_module_t *self) { if(self->dt->gui->reset) return; - dt_iop_rlucydeblur_params_t *p = (dt_iop_rlucydeblur_params_t *)self->params; - p->blur_type = dt_bauhaus_combobox_get((GtkWidget *)combo); - - dt_dev_add_history_item(darktable.develop, self, TRUE); -} - -static void rlucy_refine_quality_callback(GtkWidget *slider, dt_iop_module_t *self) -{ - if(darktable.gui->reset) return; - dt_iop_rlucydeblur_params_t *p = (dt_iop_rlucydeblur_params_t *)self->params; - - p->refine_quality = dt_bauhaus_slider_get(slider); - dt_dev_add_history_item(darktable.develop, self, TRUE); } @@ -136,19 +123,7 @@ static void rlucy_ringing_factor_callback(GtkWidget *slider, dt_iop_module_t *se { if(darktable.gui->reset) return; dt_iop_rlucydeblur_params_t *p = (dt_iop_rlucydeblur_params_t *)self->params; - p->ringing_factor = dt_bauhaus_slider_get(slider); - - dt_dev_add_history_item(darktable.develop, self, TRUE); -} - -static void rlucy_deblur_strength_callback(GtkWidget *slider, dt_iop_module_t *self) -{ - if(darktable.gui->reset) return; - dt_iop_rlucydeblur_params_t *p = (dt_iop_rlucydeblur_params_t *)self->params; - - p->deblur_strength = dt_bauhaus_slider_get(slider); - dt_dev_add_history_item(darktable.develop, self, TRUE); } @@ -156,49 +131,25 @@ static void rlucy_blur_width_callback(GtkWidget *slider, dt_iop_module_t *self) { if(darktable.gui->reset) return; dt_iop_rlucydeblur_params_t *p = (dt_iop_rlucydeblur_params_t *)self->params; - p->blur_width = dt_bauhaus_slider_get(slider); - + if(p->blur_width < 3) p->blur_width = 3; + if(p->blur_width % 2 == 0) p->blur_width = p->blur_width + 1; dt_dev_add_history_item(darktable.develop, self, TRUE); } -static void rlucy_blur_strength_callback(GtkWidget *slider, dt_iop_module_t *self) +static void rlucy_chk_use_mask_callback(GtkWidget *widget, dt_iop_module_t *self) { - if(darktable.gui->reset) return; + if(self->dt->gui->reset) return; dt_iop_rlucydeblur_params_t *p = (dt_iop_rlucydeblur_params_t *)self->params; - - p->blur_strength = dt_bauhaus_slider_get(slider); - + p->use_mask = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); dt_dev_add_history_item(darktable.develop, self, TRUE); } -static void rlucy_chk_refine_callback(GtkWidget *widget, dt_iop_module_t *self) -{ - if(self->dt->gui->reset) return; - dt_iop_rlucydeblur_params_t *p = (dt_iop_rlucydeblur_params_t *)self->params; - - p->refine = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); - - dt_dev_add_history_item(darktable.develop, self, TRUE); -} - -static void rlucy_chk_use_mask_callback(GtkWidget *widget, dt_iop_module_t *self) -{ - if(self->dt->gui->reset) return; - dt_iop_rlucydeblur_params_t *p = (dt_iop_rlucydeblur_params_t *)self->params; - - p->use_mask = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); - - dt_dev_add_history_item(darktable.develop, self, TRUE); -} - -static void rlucy_auto_quality_callback(GtkWidget *slider, dt_iop_module_t *self) +static void rlucy_quality_callback(GtkWidget *slider, dt_iop_module_t *self) { if(darktable.gui->reset) return; dt_iop_rlucydeblur_params_t *p = (dt_iop_rlucydeblur_params_t *)self->params; - - p->auto_quality = dt_bauhaus_slider_get(slider); - + p->quality = dt_bauhaus_slider_get(slider); dt_dev_add_history_item(darktable.develop, self, TRUE); } @@ -206,30 +157,30 @@ static void rlucy_noise_reduction_factor_callback(GtkWidget *slider, dt_iop_modu { if(darktable.gui->reset) return; dt_iop_rlucydeblur_params_t *p = (dt_iop_rlucydeblur_params_t *)self->params; - p->noise_reduction_factor = dt_bauhaus_slider_get(slider); - dt_dev_add_history_item(darktable.develop, self, TRUE); } + static void rlucy_draw_focus_zone_callback(GtkToggleButton *togglebutton, dt_iop_module_t *self) { if(darktable.gui->reset) return; - dt_iop_request_focus(self); - dt_control_queue_redraw_center(); - + dt_dev_add_history_item(darktable.develop, self, TRUE); } + static float get_zoom_scale(dt_develop_t *develop) { - const dt_dev_zoom_t zoom = dt_control_get_dev_zoom (); - const int closeup = dt_control_get_dev_closeup (); - return dt_dev_get_zoom_scale (develop, zoom, closeup ? 2 : 1, 1); + const dt_dev_zoom_t zoom = dt_control_get_dev_zoom(); + const int closeup = dt_control_get_dev_closeup(); + return dt_dev_get_zoom_scale(develop, zoom, closeup ? 2 : 1, 1); } -static void get_point_scale(struct dt_iop_module_t *module, float x, float y, float *pt_x, float *pt_y, float *scale) + +static void get_point_scale(struct dt_iop_module_t *module, float x, float y, float *pt_x, float *pt_y, + float *scale) { float pzx, pzy; dt_dev_get_pointer_zoom_pos(darktable.develop, x, y, &pzx, &pzy); @@ -238,10 +189,10 @@ static void get_point_scale(struct dt_iop_module_t *module, float x, float y, fl float wd = darktable.develop->preview_pipe->backbuf_width; float ht = darktable.develop->preview_pipe->backbuf_height; float pts[2] = { pzx * wd, pzy * ht }; - dt_dev_distort_backtransform_plus(darktable.develop, darktable.develop->preview_pipe, - module->priority + 1, 9999999, pts, 1); - dt_dev_distort_backtransform_plus(darktable.develop, darktable.develop->preview_pipe, - 0, module->priority - 1, pts, 1); + dt_dev_distort_backtransform_plus(darktable.develop, darktable.develop->preview_pipe, module->priority + 1, + 9999999, pts, 1); + dt_dev_distort_backtransform_plus(darktable.develop, darktable.develop->preview_pipe, 0, module->priority - 1, + pts, 1); float nx = pts[0] / darktable.develop->preview_pipe->iwidth; float ny = pts[1] / darktable.develop->preview_pipe->iheight; @@ -250,45 +201,45 @@ static void get_point_scale(struct dt_iop_module_t *module, float x, float y, fl *pt_y = (ny * darktable.develop->pipe->iheight); } -static void distord_rec(struct dt_iop_module_t *self, dt_develop_t *dev, dt_dev_pixelpipe_t *pipe, - float from_scale, float to_scale, int pmin, int pmax, - float *pt_x, float *pt_y, float *pt_w, float *pt_h) +static void distord_rec(struct dt_iop_module_t *self, dt_develop_t *dev, dt_dev_pixelpipe_t *pipe, + float from_scale, float to_scale, int pmin, int pmax, float *pt_x, float *pt_y, + float *pt_w, float *pt_h) { float x = *pt_x; float y = *pt_y; float w = *pt_w; float h = *pt_h; - - float buffer[4] = {x / from_scale, y / from_scale, (x+w) / from_scale, (y+h) / from_scale}; + + float buffer[4] = { x / from_scale, y / from_scale, (x + w) / from_scale, (y + h) / from_scale }; int len = 2; - - if (pmin < self->priority && pmax > self->priority) + + if(pmin < self->priority && pmax > self->priority) { - dt_dev_distort_transform_plus (dev, pipe, pmin, self->priority - 1, buffer, len); - dt_dev_distort_transform_plus (dev, pipe, self->priority + 1, pmax, buffer, len); + dt_dev_distort_transform_plus(dev, pipe, pmin, self->priority - 1, buffer, len); + dt_dev_distort_transform_plus(dev, pipe, self->priority + 1, pmax, buffer, len); } else - dt_dev_distort_transform_plus (dev, pipe, pmin, pmax, buffer, len); + dt_dev_distort_transform_plus(dev, pipe, pmin, pmax, buffer, len); *pt_x = buffer[0] * to_scale; *pt_y = buffer[1] * to_scale; *pt_w = buffer[2] * to_scale - *pt_x; *pt_h = buffer[3] * to_scale - *pt_y; - } + void gui_focus(struct dt_iop_module_t *self, gboolean in) { dt_iop_rlucydeblur_gui_data_t *g = (dt_iop_rlucydeblur_gui_data_t *)self->gui_data; - if (!in) + if(!in) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->bt_draw_focus_zone), FALSE); } } void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *params, dt_dev_pixelpipe_t *pipe, - dt_dev_pixelpipe_iop_t *piece) + dt_dev_pixelpipe_iop_t *piece) { memcpy(piece->data, params, sizeof(dt_iop_rlucydeblur_params_t)); } @@ -310,47 +261,36 @@ void gui_update(struct dt_iop_module_t *self) dt_iop_rlucydeblur_gui_data_t *g = (dt_iop_rlucydeblur_gui_data_t *)self->gui_data; dt_iop_rlucydeblur_params_t *p = (dt_iop_rlucydeblur_params_t *)self->params; - dt_bauhaus_combobox_set(g->cmb_blur_type, p->blur_type); - - dt_bauhaus_slider_set(g->sl_refine_quality, p->refine_quality); dt_bauhaus_slider_set(g->sl_ringing_factor, p->ringing_factor); - dt_bauhaus_slider_set(g->sl_deblur_strength, p->deblur_strength); - dt_bauhaus_slider_set(g->sl_blur_width, p->blur_width); - dt_bauhaus_slider_set(g->sl_blur_strength, p->blur_strength); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->chk_refine), p->refine); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->chk_use_mask), p->use_mask); - dt_bauhaus_slider_set(g->sl_auto_quality, p->auto_quality); dt_bauhaus_slider_set(g->sl_noise_reduction_factor, p->noise_reduction_factor); + dt_bauhaus_slider_set(g->sl_quality, p->quality); + dt_bauhaus_combobox_set(g->cmb_blur_type, p->blur_type); + dt_bauhaus_slider_set(g->sl_blur_width, p->blur_width); + + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->chk_use_mask), p->use_mask); } void init(dt_iop_module_t *module) { - module->data = NULL; + module->data = NULL; module->params = calloc(1, sizeof(dt_iop_rlucydeblur_params_t)); module->default_params = calloc(1, sizeof(dt_iop_rlucydeblur_params_t)); module->default_enabled = 0; -// module->priority = 164; // module order created by iop_dependencies.py, do not edit! // from exposure - module->priority = 582; // module order created by iop_dependencies.py, do not edit! // from bilat + module->priority = 144; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_rlucydeblur_params_t); module->gui_data = NULL; - - dt_iop_rlucydeblur_params_t tmp = {0}; - - tmp.blur_type = rlucy_blur_type_auto; - tmp.blur_width = 11; - tmp.deblur_strength = 0; - tmp.blur_strength = 8; - tmp.auto_quality = 1.f; - tmp.noise_reduction_factor = 1000.f; - tmp.refine_quality = 50; + + dt_iop_rlucydeblur_params_t tmp = { 0 }; + + tmp.blur_type = rlucy_blur_type_gaussian; + tmp.blur_width = 5; + tmp.quality = 5; + tmp.noise_reduction_factor = 1000; tmp.ringing_factor = 0.001f; - tmp.refine = 0; - tmp.refine_quality = 0; memcpy(module->params, &tmp, sizeof(dt_iop_rlucydeblur_params_t)); memcpy(module->default_params, &tmp, sizeof(dt_iop_rlucydeblur_params_t)); - } void cleanup(dt_iop_module_t *module) @@ -362,134 +302,94 @@ void cleanup(dt_iop_module_t *module) void gui_init(struct dt_iop_module_t *self) { const int bs = DT_PIXEL_APPLY_DPI(14); - + self->gui_data = malloc(sizeof(dt_iop_rlucydeblur_gui_data_t)); dt_iop_rlucydeblur_gui_data_t *g = (dt_iop_rlucydeblur_gui_data_t *)self->gui_data; dt_iop_rlucydeblur_params_t *p = (dt_iop_rlucydeblur_params_t *)self->params; - self->widget = GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_VERTICAL, DT_BAUHAUS_SPACE)); g->drawing = 0; g->pt_down_x = g->pt_down_y = g->pt_last_x = g->pt_last_y = 0.f; + // Noise tolerance factor + g->sl_noise_reduction_factor + = dt_bauhaus_slider_new_with_range(self, 500, 30000, 100, p->noise_reduction_factor, 0); + dt_bauhaus_widget_set_label(g->sl_noise_reduction_factor, _("noise tolerance factor"), + _("noise tolerance factor")); + gtk_box_pack_start(GTK_BOX(self->widget), g->sl_noise_reduction_factor, TRUE, TRUE, 0); + + // Iteration/gradient descent factor + g->sl_ringing_factor = dt_bauhaus_slider_new_with_range(self, 0.0001, 0.01, 1, p->ringing_factor, 4); + dt_bauhaus_widget_set_label(g->sl_ringing_factor, _("gradient descent factor"), _("gradient descent factor")); + gtk_box_pack_start(GTK_BOX(self->widget), g->sl_ringing_factor, TRUE, TRUE, 0); + + // Quality + g->sl_quality = dt_bauhaus_slider_new_with_range(self, 1, 100, 1, p->quality, 0); + dt_bauhaus_widget_set_label(g->sl_quality, _("quality "), _("quality")); + gtk_box_pack_start(GTK_BOX(self->widget), g->sl_quality, TRUE, TRUE, 0); + + // Blur type g->cmb_blur_type = dt_bauhaus_combobox_new(self); dt_bauhaus_widget_set_label(g->cmb_blur_type, NULL, _("blur type")); dt_bauhaus_combobox_add(g->cmb_blur_type, _("auto")); dt_bauhaus_combobox_add(g->cmb_blur_type, _("gaussian")); - dt_bauhaus_combobox_add(g->cmb_blur_type, _("kaiser")); - g_object_set(g->cmb_blur_type, "tooltip-text", _("blur type."), (char *)NULL); - g_signal_connect(G_OBJECT(g->cmb_blur_type), "value-changed", G_CALLBACK(rlucy_blur_type_callback), self); - - g->sl_refine_quality = dt_bauhaus_slider_new_with_range(self, 0, 100, 1, p->refine_quality, 0); - dt_bauhaus_widget_set_label(g->sl_refine_quality, _("refine quality"), _("refine quality")); - g_object_set(g->sl_refine_quality, "tooltip-text", _("the number of iterations to perform during the refinement step."), (char *)NULL); - g_signal_connect(G_OBJECT(g->sl_refine_quality), "value-changed", G_CALLBACK(rlucy_refine_quality_callback), self); - - g->sl_ringing_factor = dt_bauhaus_slider_new_with_range(self, 0.00001, 1.0, 0.00001, p->ringing_factor, 6); - dt_bauhaus_widget_set_label(g->sl_ringing_factor, _("ringing factor"), _("ringing factor")); - g_object_set(g->sl_ringing_factor, "tooltip-text", _("the iterations factor. Typically 1e-3, reduce it to 5e-4 or ever 1e-4 if you see ringing or periodic edges appear."), (char *)NULL); - g_signal_connect(G_OBJECT(g->sl_ringing_factor), "value-changed", G_CALLBACK(rlucy_ringing_factor_callback), self); + // TODO: https://en.wikipedia.org/wiki/Defocus_aberration + // dt_bauhaus_combobox_add(g->cmb_blur_type, _("defocus")); + gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(g->cmb_blur_type), TRUE, TRUE, 0); - g->sl_blur_width = dt_bauhaus_slider_new_with_range(self, 3, 111.0, 1, p->blur_width, 0); + // Blur width + g->sl_blur_width = dt_bauhaus_slider_new_with_range(self, 3, 111, 2, p->blur_width, 0); dt_bauhaus_widget_set_label(g->sl_blur_width, _("blur width"), _("blur width")); - g_object_set(g->sl_blur_width, "tooltip-text", _("the width of the blur in px - must be an odd integer"), (char *)NULL); - g_signal_connect(G_OBJECT(g->sl_blur_width), "value-changed", G_CALLBACK(rlucy_blur_width_callback), self); - - g->sl_blur_strength = dt_bauhaus_slider_new_with_range(self, 1, 50.0, 1, p->blur_strength, 0); - dt_bauhaus_widget_set_label(g->sl_blur_strength, _("blur strength"), _("blur strength")); - g_object_set(g->sl_blur_strength, "tooltip-text", _("standard deviation of the blur kernel."), (char *)NULL); - g_signal_connect(G_OBJECT(g->sl_blur_strength), "value-changed", G_CALLBACK(rlucy_blur_strength_callback), self); - - g->chk_refine = gtk_check_button_new_with_label("refine"); - g_object_set(G_OBJECT(g->chk_refine), "tooltip-text", _("decide if the blur kernel should be refined through myopic deconvolution"), (char *)NULL); - g_signal_connect(G_OBJECT(g->chk_refine), "toggled", G_CALLBACK(rlucy_chk_refine_callback), self); - - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->chk_refine), p->refine); - - g->sl_deblur_strength = dt_bauhaus_slider_new_with_range(self, 0, 100.0, 1, p->deblur_strength, 0); - dt_bauhaus_widget_set_label(g->sl_deblur_strength, _("deblur strength"), _("deblur strength")); - g_object_set(g->sl_deblur_strength, "tooltip-text", _("number of debluring iterations to perform."), (char *)NULL); - g_signal_connect(G_OBJECT(g->sl_deblur_strength), "value-changed", G_CALLBACK(rlucy_deblur_strength_callback), self); + gtk_box_pack_start(GTK_BOX(self->widget), g->sl_blur_width, TRUE, TRUE, 0); + // Paint the refining mask GtkWidget *hbox_mask = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); - - g->bt_draw_focus_zone = dtgtk_togglebutton_new(_cairo_paint_tool_draw_focus_zone, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); - g_object_set(G_OBJECT(g->bt_draw_focus_zone), "tooltip-text", _("activates focus zone drawing"), (char *)NULL); - g_signal_connect(G_OBJECT(g->bt_draw_focus_zone), "toggled", G_CALLBACK(rlucy_draw_focus_zone_callback), self); + g->bt_draw_focus_zone + = dtgtk_togglebutton_new(_cairo_paint_tool_draw_focus_zone, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); gtk_widget_set_size_request(GTK_WIDGET(g->bt_draw_focus_zone), bs, bs); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->bt_draw_focus_zone), FALSE); gtk_box_pack_end(GTK_BOX(hbox_mask), g->bt_draw_focus_zone, FALSE, FALSE, 0); - g->chk_use_mask = gtk_check_button_new_with_label("use mask"); - g_object_set(G_OBJECT(g->chk_use_mask), "tooltip-text", _("use mask"), (char *)NULL); - g_signal_connect(G_OBJECT(g->chk_use_mask), "toggled", G_CALLBACK(rlucy_chk_use_mask_callback), self); - + // Refine over the mask only + g->chk_use_mask = gtk_check_button_new_with_label("refine over the mask only"); gtk_box_pack_start(GTK_BOX(hbox_mask), g->chk_use_mask, TRUE, TRUE, 0); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->chk_use_mask), p->use_mask); - - g->sl_auto_quality = dt_bauhaus_slider_new_with_range(self, 0.0, 2.0, 0.01, p->auto_quality, 3); - dt_bauhaus_widget_set_label(g->sl_auto_quality, _("auto quality"), _("auto quality")); - g_object_set(g->sl_auto_quality, "tooltip-text", _("when the `blur_type` is `auto`, the number of iterations of the initial blur estimation is half the" - "square of the PSF size.\nThe `auto_quality` parameter is a factor that allows you to reduce the number of iteration to speed up the process.\n" - "Default : 1. Recommended values : between 0.25 and 2."), (char *)NULL); - g_signal_connect(G_OBJECT(g->sl_auto_quality), "value-changed", G_CALLBACK(rlucy_auto_quality_callback), self); - - g->sl_noise_reduction_factor = dt_bauhaus_slider_new_with_range(self, 0.0, 30000.0, 1.0, p->noise_reduction_factor, 3); - dt_bauhaus_widget_set_label(g->sl_noise_reduction_factor, _("noise reduction factor"), _("noise reduction factor")); - g_object_set(g->sl_noise_reduction_factor, "tooltip-text", _("the noise reduction factor lambda.\n" - "For the `best` method, default is 1000, use 12000 to 30000 to speed up the convergence.\n" - "Lower values don't help to reduce the noise, decrease the `ringing_facter` instead."), (char *)NULL); - g_signal_connect(G_OBJECT(g->sl_noise_reduction_factor), "value-changed", G_CALLBACK(rlucy_noise_reduction_factor_callback), self); - - - gtk_box_pack_start(GTK_BOX(self->widget), g->sl_deblur_strength, TRUE, TRUE, 0); - - gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(g->cmb_blur_type), TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(self->widget), g->sl_blur_width, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(self->widget), g->sl_blur_strength, TRUE, TRUE, 0); - - gtk_box_pack_start(GTK_BOX(self->widget), g->chk_refine, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(self->widget), g->sl_refine_quality, TRUE, TRUE, 0); - - gtk_box_pack_start(GTK_BOX(self->widget), g->sl_ringing_factor, TRUE, TRUE, 0); - - gtk_box_pack_start(GTK_BOX(self->widget), g->sl_auto_quality, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(self->widget), g->sl_noise_reduction_factor, TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(self->widget), hbox_mask, TRUE, TRUE, 0); - + // Tooltips + gtk_widget_set_tooltip_text( + g->sl_noise_reduction_factor, + _("an higher value may lead to a sharper result but may increase the noise as well")); + gtk_widget_set_tooltip_text(g->bt_draw_focus_zone, _("activates focus zone drawing")); + gtk_widget_set_tooltip_text(g->chk_use_mask, _("select the area of interest to force the focus")); + gtk_widget_set_tooltip_text(g->sl_quality, + _("number of iterations to perform. It should be around the size of the blur")); + gtk_widget_set_tooltip_text(g->sl_blur_width, _("the width of the blur in px")); + gtk_widget_set_tooltip_text( + g->sl_ringing_factor, + _("increase this factor for a more dramatic effect, decrease it if ringing grows out of control")); + gtk_widget_set_tooltip_text(g->cmb_blur_type, _("blur type.")); + + // Map GUI events + g_signal_connect(G_OBJECT(g->cmb_blur_type), "value-changed", G_CALLBACK(rlucy_blur_type_callback), self); + g_signal_connect(G_OBJECT(g->sl_noise_reduction_factor), "value-changed", + G_CALLBACK(rlucy_noise_reduction_factor_callback), self); + g_signal_connect(G_OBJECT(g->sl_quality), "value-changed", G_CALLBACK(rlucy_quality_callback), self); + g_signal_connect(G_OBJECT(g->chk_use_mask), "toggled", G_CALLBACK(rlucy_chk_use_mask_callback), self); + g_signal_connect(G_OBJECT(g->sl_ringing_factor), "value-changed", G_CALLBACK(rlucy_ringing_factor_callback), + self); + g_signal_connect(G_OBJECT(g->bt_draw_focus_zone), "toggled", G_CALLBACK(rlucy_draw_focus_zone_callback), self); + g_signal_connect(G_OBJECT(g->sl_blur_width), "value-changed", G_CALLBACK(rlucy_blur_width_callback), self); } void init_global(dt_iop_module_so_t *module) { module->data = NULL; - - // FIXME: this should go into dt startup -#ifdef HAVE_FFTW3_OMP -#ifdef _OPENMP - - fftwf_init_threads(); - -#endif -#endif - } void cleanup_global(dt_iop_module_so_t *module) { module->data = NULL; - - // FIXME: this should go into dt cleanup -#ifdef HAVE_FFTW3_OMP -#ifdef _OPENMP - - fftwf_cleanup_threads(); - -#endif -#endif - } void gui_cleanup(struct dt_iop_module_t *self) @@ -498,31 +398,31 @@ void gui_cleanup(struct dt_iop_module_t *self) self->gui_data = NULL; } -void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, int32_t height, - int32_t pointerx, int32_t pointery) + +void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, + int32_t pointery) { dt_develop_t *dev = self->dev; dt_iop_rlucydeblur_gui_data_t *g = (dt_iop_rlucydeblur_gui_data_t *)self->gui_data; dt_iop_rlucydeblur_params_t *p = (dt_iop_rlucydeblur_params_t *)self->params; - if (!g) return; - if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g->bt_draw_focus_zone))) return; + if(!g) return; + if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g->bt_draw_focus_zone))) return; const float bb_width = dev->preview_pipe->backbuf_width; const float bb_height = dev->preview_pipe->backbuf_height; - const float scale = MAX (bb_width, bb_height); - if (bb_width < 1.0 || bb_height < 1.0) - return; + const float scale = MAX(bb_width, bb_height); + if(bb_width < 1.0 || bb_height < 1.0) return; - const float zoom_x = dt_control_get_dev_zoom_x (); - const float zoom_y = dt_control_get_dev_zoom_y (); - const float zoom_scale = get_zoom_scale (dev); + const float zoom_x = dt_control_get_dev_zoom_x(); + const float zoom_y = dt_control_get_dev_zoom_y(); + const float zoom_scale = get_zoom_scale(dev); double dashes = DT_PIXEL_APPLY_DPI(5.0) * (1.0 / (scale * zoom_scale)); float x, y, w, h; - if (g->drawing) + if(g->drawing) { x = MIN(g->pt_down_x, g->pt_last_x); y = MIN(g->pt_down_y, g->pt_last_y); @@ -543,15 +443,15 @@ void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, i float to_scale = 1.0 / scale; distord_rec(self, dev, dev->preview_pipe, from_scale, to_scale, 0, 9999999, &x, &y, &w, &h); - if (w <= 0. || h <= 0.) return; + if(w <= 0. || h <= 0.) return; cairo_save(cr); // setup CAIRO coordinate system - cairo_translate (cr, 0.5 * width, 0.5 * height); // origin @ center of view - cairo_scale (cr, zoom_scale, zoom_scale); // the zoom - cairo_translate (cr, -bb_width * (0.5 + zoom_x), -bb_height * (0.5 + zoom_y)); - cairo_scale (cr, scale, scale); + cairo_translate(cr, 0.5 * width, 0.5 * height); // origin @ center of view + cairo_scale(cr, zoom_scale, zoom_scale); // the zoom + cairo_translate(cr, -bb_width * (0.5 + zoom_x), -bb_height * (0.5 + zoom_y)); + cairo_scale(cr, scale, scale); cairo_set_line_width(cr, dashes / 2.0); cairo_rectangle(cr, x, y, w, h); @@ -559,143 +459,125 @@ void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, i cairo_stroke(cr); cairo_restore(cr); - } int mouse_moved(struct dt_iop_module_t *self, double x, double y, double pressure, int which) { - dt_iop_rlucydeblur_gui_data_t *g = (dt_iop_rlucydeblur_gui_data_t *)self->gui_data; - if (g->drawing) - { - float pt_x, pt_y; - float scale; + dt_iop_rlucydeblur_gui_data_t *g = (dt_iop_rlucydeblur_gui_data_t *)self->gui_data; + if(g->drawing) + { + float pt_x, pt_y; + float scale; + + get_point_scale(self, x, y, &pt_x, &pt_y, &scale); - get_point_scale(self, x, y, &pt_x, &pt_y, &scale); + g->pt_last_x = pt_x; + g->pt_last_y = pt_y; - g->pt_last_x = pt_x; - g->pt_last_y = pt_y; + dt_control_queue_redraw_center(); - dt_control_queue_redraw_center(); - - return 1; - } + return 1; + } - return 0; + return 0; } int button_pressed(struct dt_iop_module_t *self, double x, double y, double pressure, int which, int type, uint32_t state) { - dt_iop_rlucydeblur_gui_data_t *g = (dt_iop_rlucydeblur_gui_data_t *)self->gui_data; - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g->bt_draw_focus_zone))) - { - float pt_x, pt_y; - float scale; - - get_point_scale(self, x, y, &pt_x, &pt_y, &scale); - - g->pt_down_x = g->pt_last_x = pt_x; - g->pt_down_y = g->pt_last_y = pt_y; - - g->drawing = 1; - - return 1; - } - - return 0; + dt_iop_rlucydeblur_gui_data_t *g = (dt_iop_rlucydeblur_gui_data_t *)self->gui_data; + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g->bt_draw_focus_zone))) + { + float pt_x, pt_y; + float scale; + + get_point_scale(self, x, y, &pt_x, &pt_y, &scale); + + g->pt_down_x = g->pt_last_x = pt_x; + g->pt_down_y = g->pt_last_y = pt_y; + + g->drawing = 1; + + return 1; + } + + return 0; } int button_released(struct dt_iop_module_t *self, double x, double y, int which, uint32_t state) { - dt_iop_rlucydeblur_gui_data_t *g = (dt_iop_rlucydeblur_gui_data_t *)self->gui_data; - dt_iop_rlucydeblur_params_t *p = (dt_iop_rlucydeblur_params_t *)self->params; - if (g->drawing) - { - float pt_x, pt_y; - float scale; - - get_point_scale(self, x, y, &pt_x, &pt_y, &scale); - - g->pt_last_x = pt_x; - g->pt_last_y = pt_y; - - //----------------------------- - - pt_x = MIN(g->pt_down_x, g->pt_last_x); - pt_y = MIN(g->pt_down_y, g->pt_last_y); - float pt_w = fabs(g->pt_down_x - g->pt_last_x); - float pt_h = fabs(g->pt_down_y - g->pt_last_y); - - float from_scale = 1.0; //iscale; - float to_scale = 1.0 ;/// scale; - - distord_rec(self, self->dev, self->dev->preview_pipe, from_scale, to_scale, 0, 9999999, &pt_x, &pt_y, &pt_w, &pt_h); - - p->mask[0] = pt_x; - p->mask[1] = pt_y; - p->mask[2] = pt_w; - p->mask[3] = pt_h; - - g->pt_down_x = g->pt_last_x = 0.; - g->pt_down_y = g->pt_last_y = 0.; - - dt_dev_add_history_item (darktable.develop, self, TRUE); - - //-------------------------------- - - g->drawing = 0; - - return 1; - } - - return 0; + dt_iop_rlucydeblur_gui_data_t *g = (dt_iop_rlucydeblur_gui_data_t *)self->gui_data; + dt_iop_rlucydeblur_params_t *p = (dt_iop_rlucydeblur_params_t *)self->params; + if(g->drawing) + { + float pt_x, pt_y; + float scale; + + get_point_scale(self, x, y, &pt_x, &pt_y, &scale); + + g->pt_last_x = pt_x; + g->pt_last_y = pt_y; + + //----------------------------- + + pt_x = MIN(g->pt_down_x, g->pt_last_x); + pt_y = MIN(g->pt_down_y, g->pt_last_y); + float pt_w = fabs(g->pt_down_x - g->pt_last_x); + float pt_h = fabs(g->pt_down_y - g->pt_last_y); + + float from_scale = 1.0; // iscale; + float to_scale = 1.0; /// scale; + + distord_rec(self, self->dev, self->dev->preview_pipe, from_scale, to_scale, 0, 9999999, &pt_x, &pt_y, &pt_w, + &pt_h); + + p->mask[0] = pt_x; + p->mask[1] = pt_y; + p->mask[2] = pt_w; + p->mask[3] = pt_h; + + g->pt_down_x = g->pt_last_x = 0.; + g->pt_down_y = g->pt_last_y = 0.; + + //-------------------------------- + + g->drawing = 0; + + return 1; + } + + return 0; } -static void check_nan(const float* im, const int size) +static void check_nan(const float *im, const int size) { - int i_nan = 0; - - for (int i = 0; i < size; i++) if ( isnan(im[i]) ) i_nan++; - - if (i_nan > 0) printf("Richardson-Lucy deconvolution nan: %i\n", i_nan); + int i_nan = 0; + + for(int i = 0; i < size; i++) + if(isnan(im[i])) i_nan++; + + if(i_nan > 0) printf("Richardson-Lucy deconvolution nan: %i\n", i_nan); } -void rlucy_process_internal(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid, - const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, const int use_sse) +void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, + void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) { + const dt_iop_rlucydeblur_data_t *const p = (const dt_iop_rlucydeblur_data_t *const)piece->data; dt_develop_t *dev = self->dev; - - const dt_iop_colorspace_type_t cst = dt_iop_module_colorspace(self); const int ch = piece->colors; - - float *im_tmp = NULL; - float *kernel = NULL; - - int blur_type = p->blur_type; - int deblur_strength = p->deblur_strength; - int blur_width = p->blur_width; - int blur_strength = p->blur_strength; - int refine = p->refine; - float ringing_factor = p->ringing_factor; - float auto_quality = p->auto_quality; - float noise_reduction_factor = p->noise_reduction_factor; - int refine_quality = p->refine_quality; - float effect_strength = 1.f; - int denoise = 0; - int method = rlucy_method_best; - - float *psf_in = NULL; int *mask = NULL; float pt_x = p->mask[0]; float pt_y = p->mask[1]; float pt_w = p->mask[2]; float pt_h = p->mask[3]; - int rl_mask[4] = {0}; + int rl_mask[4] = { 0 }; + - if (p->use_mask) + + if(p->use_mask) { float from_scale = 1.0; float to_scale = roi_in->scale / piece->iscale; @@ -705,119 +587,35 @@ void rlucy_process_internal(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t pt_x -= (float)roi_in->x; pt_y -= (float)roi_in->y; - if (pt_w > 0. && pt_h > 0.) + if(pt_w > 0. && pt_h > 0.) { rl_mask[0] = MAX(pt_x, 0.); rl_mask[1] = MAX(pt_y, 0.); - if (pt_x < 0.) + if(pt_x < 0.) rl_mask[2] = pt_w + pt_x; else rl_mask[2] = pt_w; - if (pt_y < 0.) + if(pt_y < 0.) rl_mask[3] = pt_h + pt_y; else rl_mask[3] = pt_h; - rl_mask[2] = MIN(rl_mask[2], roi_in->width-rl_mask[0]); - rl_mask[3] = MIN(rl_mask[3], roi_in->height-rl_mask[1]); + rl_mask[2] = MIN(rl_mask[2], roi_in->width - rl_mask[0]); + rl_mask[3] = MIN(rl_mask[3], roi_in->height - rl_mask[1]); - if (rl_mask[2] > 0 && rl_mask[3] > 0) + if(rl_mask[2] > 0 && rl_mask[3] > 0) { mask = rl_mask; } } } - if (cst == iop_cs_rgb) - { - rlucy_deblur_module((float*)ivoid, - blur_type, - blur_width, - noise_reduction_factor, - deblur_strength, - blur_strength, - auto_quality, - ringing_factor, - refine, - refine_quality, - mask, - effect_strength, - psf_in, - denoise, - method, - (float*)ovoid, - roi_out->width, - roi_out->height, - ch); - } - else if (cst == iop_cs_Lab) - { - memcpy(ovoid, ivoid, roi_in->width * roi_in->height * ch * sizeof(float)); - - im_tmp = (float*)dt_alloc_align(64, roi_out->width * roi_out->height * sizeof(float)); - kernel = (float*)dt_alloc_align(64, blur_width * blur_width * sizeof(float)); - if (im_tmp && kernel) - { - float *im_src = (float*)ivoid; + rlucy_deblur_module((float *)ivoid, p->blur_type, p->blur_width, p->noise_reduction_factor, p->quality, + p->ringing_factor, mask, rlucy_method_best, (float *)ovoid, roi_out->width, + roi_out->height, ch); - for (int i = 0; i < roi_out->width * roi_out->height; i++) - { - im_tmp[i] = im_src[i*ch] * (1.f / 100.f); - } - - rlucy_deblur_module(im_tmp, - blur_type, - blur_width, - noise_reduction_factor, - deblur_strength, - blur_strength, - auto_quality, - ringing_factor, - refine, - refine_quality, - mask, - effect_strength, - psf_in, - denoise, - method, - im_tmp, - roi_out->width, - roi_out->height, - 1); - - float *im_dest = (float*)ovoid; - - for (int i = 0; i < roi_out->width * roi_out->height; i++) - { - im_dest[i*ch] = im_tmp[i] * 100.f; - } - } - } - else - { - memcpy(ovoid, ivoid, roi_in->width * roi_in->height * ch * sizeof(float)); - } - - check_nan((float*)ovoid, roi_out->width*roi_out->height*ch); - - if (im_tmp) dt_free_align(im_tmp); - if (kernel) dt_free_align(kernel); - -} - -void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid, - const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) -{ - rlucy_process_internal(self, piece, ivoid, ovoid, roi_in, roi_out, 0); + check_nan((float *)ovoid, roi_out->width * roi_out->height * ch); } -#if defined(__SSE__x) -void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid, - const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) -{ - rlucy_process_internal(self, piece, ivoid, ovoid, roi_in, roi_out, 1); -} -#endif - // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh // vim: shiftwidth=2 expandtab tabstop=2 cindent // kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified; diff --git a/src/iop/rotatepixels.c b/src/iop/rotatepixels.c index 4c5dce21a595..e1d8bf2381b7 100644 --- a/src/iop/rotatepixels.c +++ b/src/iop/rotatepixels.c @@ -84,8 +84,7 @@ int operation_tags() return IOP_TAG_DISTORT; } -static void transform(const dt_dev_pixelpipe_iop_t *const piece, const float scale, const float *const x, - float *o) +static void transform(const dt_dev_pixelpipe_iop_t *const piece, const float scale, const float *const x, float *o) { dt_iop_rotatepixels_data_t *d = (dt_iop_rotatepixels_data_t *)piece->data; @@ -126,8 +125,7 @@ int distort_transform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, floa return 1; } -int distort_backtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, float *points, - size_t points_count) +int distort_backtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, float *points, size_t points_count) { const float scale = piece->buf_in.scale / piece->iscale; @@ -178,8 +176,7 @@ void modify_roi_out(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, dt_iop const float scale = roi_in->scale / piece->iscale, T = (float)d->ry * scale; - const float y = sqrtf(2.0f * T * T), - x = sqrtf(2.0f * ((float)roi_in->width - T) * ((float)roi_in->width - T)); + const float y = sqrtf(2.0f * T * T), x = sqrtf(2.0f * ((float)roi_in->width - T) * ((float)roi_in->width - T)); const struct dt_interpolation *interpolation = dt_interpolation_new(DT_INTERPOLATION_USERPREF); const float IW = (float)interpolation->width * scale; @@ -314,7 +311,7 @@ void reload_defaults(dt_iop_module_t *self) const dt_image_t *const image = &(self->dev->image_storage); - tmp = (dt_iop_rotatepixels_params_t){ .rx = 0u, .ry = image->fuji_rotation_pos, .angle = -45.0f }; + tmp = (dt_iop_rotatepixels_params_t){.rx = 0u, .ry = image->fuji_rotation_pos, .angle = -45.0f }; self->default_enabled = ((tmp.rx != 0u) || (tmp.ry != 0u)); @@ -341,7 +338,7 @@ void init(dt_iop_module_t *self) self->default_params = calloc(1, sizeof(dt_iop_rotatepixels_params_t)); self->params_size = sizeof(dt_iop_rotatepixels_params_t); self->gui_data = NULL; - self->priority = 235; // module order created by iop_dependencies.py, do not edit! + self->priority = 246; // module order created by iop_dependencies.py, do not edit! } void cleanup(dt_iop_module_t *self) diff --git a/src/iop/scalepixels.c b/src/iop/scalepixels.c index e506128e6de3..f5b1924dc519 100644 --- a/src/iop/scalepixels.c +++ b/src/iop/scalepixels.c @@ -44,7 +44,8 @@ typedef struct dt_iop_scalepixels_gui_data_t GtkWidget *pixel_aspect_ratio; } dt_iop_scalepixels_gui_data_t; -typedef struct dt_iop_scalepixels_data_t { +typedef struct dt_iop_scalepixels_data_t +{ float pixel_aspect_ratio; float x_scale; float y_scale; @@ -103,14 +104,13 @@ int distort_transform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, floa for(size_t i = 0; i < points_count * 2; i += 2) { points[i] /= d->x_scale; - points[i+1] /= d->y_scale; + points[i + 1] /= d->y_scale; } return 1; } -int distort_backtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, float *points, - size_t points_count) +int distort_backtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, float *points, size_t points_count) { precalculate_scale(self, piece); dt_iop_scalepixels_data_t *d = piece->data; @@ -118,7 +118,7 @@ int distort_backtransform(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, for(size_t i = 0; i < points_count * 2; i += 2) { points[i] *= d->x_scale; - points[i+1] *= d->y_scale; + points[i + 1] *= d->y_scale; } return 1; @@ -153,13 +153,13 @@ void modify_roi_in(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const d *roi_in = *roi_out; // If possible try to get an image that's strictly larger than what we want to output - float hw[2] = {roi_out->height, roi_out->width}; + float hw[2] = { roi_out->height, roi_out->width }; transform(piece, hw); // transform() is used reversed here intentionally roi_in->height = hw[0]; roi_in->width = hw[1]; float reduction_ratio = MAX(hw[0] / (piece->buf_in.height * 1.0f), hw[1] / (piece->buf_in.width * 1.0f)); - if (reduction_ratio > 1.0f) + if(reduction_ratio > 1.0f) { roi_in->height /= reduction_ratio; roi_in->width /= reduction_ratio; @@ -180,7 +180,7 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c const int ch = piece->colors; const int ch_width = ch * roi_in->width; const struct dt_interpolation *interpolation = dt_interpolation_new(DT_INTERPOLATION_USERPREF); - const dt_iop_scalepixels_data_t * const d = piece->data; + const dt_iop_scalepixels_data_t *const d = piece->data; #ifdef _OPENMP #pragma omp parallel for schedule(static) default(none) shared(interpolation) @@ -192,11 +192,11 @@ void process(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *c float *out = ((float *)ovoid) + (size_t)4 * j * roi_out->width; for(int i = 0; i < roi_out->width; i++, out += 4) { - float x = i*d->x_scale; - float y = j*d->y_scale; + float x = i * d->x_scale; + float y = j * d->y_scale; - dt_interpolation_compute_pixel4c(interpolation, (float *)ivoid, out, x, y, roi_in->width, - roi_in->height, ch_width); + dt_interpolation_compute_pixel4c(interpolation, (float *)ivoid, out, x, y, roi_in->width, roi_in->height, + ch_width); } } } @@ -229,7 +229,7 @@ void cleanup_pipe(dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelp void reload_defaults(dt_iop_module_t *self) { - dt_iop_scalepixels_params_t tmp = (dt_iop_scalepixels_params_t){ .pixel_aspect_ratio = 1.0f }; + dt_iop_scalepixels_params_t tmp = (dt_iop_scalepixels_params_t){.pixel_aspect_ratio = 1.0f }; // we might be called from presets update infrastructure => there is no image if(!self->dev) goto end; @@ -266,7 +266,7 @@ void init(dt_iop_module_t *self) self->default_params = calloc(1, sizeof(dt_iop_scalepixels_params_t)); self->default_enabled = (!isnan(image->pixel_aspect_ratio) && image->pixel_aspect_ratio > 0.0f && image->pixel_aspect_ratio != 1.0f); - self->priority = 249; // module order created by iop_dependencies.py, do not edit! + self->priority = 260; // module order created by iop_dependencies.py, do not edit! self->params_size = sizeof(dt_iop_scalepixels_params_t); self->gui_data = NULL; } diff --git a/src/iop/shadhi.c b/src/iop/shadhi.c index d1d6a0a67019..582ae1bda7ed 100644 --- a/src/iop/shadhi.c +++ b/src/iop/shadhi.c @@ -53,8 +53,8 @@ #define UNBOUND_HIGHLIGHTS_B (UNBOUND_B << 3) /* 32 */ #define UNBOUND_GAUSSIAN 64 #define UNBOUND_BILATERAL 128 /* not implemented yet */ -#define UNBOUND_DEFAULT \ - (UNBOUND_SHADOWS_L | UNBOUND_SHADOWS_A | UNBOUND_SHADOWS_B | UNBOUND_HIGHLIGHTS_L | UNBOUND_HIGHLIGHTS_A \ +#define UNBOUND_DEFAULT \ + (UNBOUND_SHADOWS_L | UNBOUND_SHADOWS_A | UNBOUND_SHADOWS_B | UNBOUND_HIGHLIGHTS_L | UNBOUND_HIGHLIGHTS_A \ | UNBOUND_HIGHLIGHTS_B | UNBOUND_GAUSSIAN) #define CLAMPF(a, mn, mx) ((a) < (mn) ? (mn) : ((a) > (mx) ? (mx) : (a))) @@ -187,8 +187,8 @@ int groups() return IOP_GROUP_BASIC; } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 1 && new_version == 5) { @@ -331,10 +331,10 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const const float whitepoint = fmax(1.0f - data->whitepoint / 100.0f, 0.01f); const float compress = fmin(fmax(0, (data->compress / 100.0f)), 0.99f); // upper limit 0.99f to avoid division by zero later - const float shadows_ccorrect = (fmin(fmax(0.0f, (data->shadows_ccorrect / 100.0f)), 1.0f) - 0.5f) - * sign(shadows) + 0.5f; - const float highlights_ccorrect = (fmin(fmax(0.0f, (data->highlights_ccorrect / 100.0f)), 1.0f) - 0.5f) - * sign(-highlights) + 0.5f; + const float shadows_ccorrect = (fmin(fmax(0.0f, (data->shadows_ccorrect / 100.0f)), 1.0f) - 0.5f) * sign(shadows) + + 0.5f; + const float highlights_ccorrect + = (fmin(fmax(0.0f, (data->highlights_ccorrect / 100.0f)), 1.0f) - 0.5f) * sign(-highlights) + 0.5f; const unsigned int flags = data->flags; const int unbound_mask = ((data->shadhi_algo == SHADHI_ALGO_BILATERAL) && (flags & UNBOUND_BILATERAL)) || ((data->shadhi_algo == SHADHI_ALGO_GAUSSIAN) && (flags & UNBOUND_GAUSSIAN)); @@ -419,8 +419,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const highlights2 -= 1.0f; ta[0] = la * (1.0 - optrans) - + (la > halfmax ? lmax - (lmax - doublemax * (la - halfmax)) * (lmax - lb) : doublemax * la - * lb) * optrans; + + (la > halfmax ? lmax - (lmax - doublemax * (la - halfmax)) * (lmax - lb) : doublemax * la * lb) + * optrans; ta[0] = (flags & UNBOUND_HIGHLIGHTS_L) ? ta[0] : CLAMP_RANGE(ta[0], lmin, lmax); @@ -456,8 +456,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const shadows2 -= 1.0f; ta[0] = la * (1.0 - optrans) - + (la > halfmax ? lmax - (lmax - doublemax * (la - halfmax)) * (lmax - lb) : doublemax * la - * lb) * optrans; + + (la > halfmax ? lmax - (lmax - doublemax * (la - halfmax)) * (lmax - lb) : doublemax * la * lb) + * optrans; ta[0] = (flags & UNBOUND_SHADOWS_L) ? ta[0] : CLAMP_RANGE(ta[0], lmin, lmax); @@ -477,7 +477,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const _Lab_rescale(ta, &out[j]); } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } @@ -506,8 +507,8 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m = fmin(fmax(0.0f, (d->compress / 100.0f)), 0.99f); // upper limit 0.99f to avoid division by zero later const float shadows_ccorrect = (fmin(fmax(0.0f, (d->shadows_ccorrect / 100.0f)), 1.0f) - 0.5f) * sign(shadows) + 0.5f; - const float highlights_ccorrect = (fmin(fmax(0.0f, (d->highlights_ccorrect / 100.0f)), 1.0f) - 0.5f) - * sign(-highlights) + 0.5f; + const float highlights_ccorrect + = (fmin(fmax(0.0f, (d->highlights_ccorrect / 100.0f)), 1.0f) - 0.5f) * sign(-highlights) + 0.5f; const float low_approximation = d->low_approximation; const unsigned int flags = d->flags; const int unbound_mask = ((d->shadhi_algo == SHADHI_ALGO_BILATERAL) && (flags & UNBOUND_BILATERAL)) @@ -575,16 +576,13 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m dt_opencl_set_kernel_arg(devid, gd->kernel_shadows_highlights_mix, 5, sizeof(float), (void *)&shadows); dt_opencl_set_kernel_arg(devid, gd->kernel_shadows_highlights_mix, 6, sizeof(float), (void *)&highlights); dt_opencl_set_kernel_arg(devid, gd->kernel_shadows_highlights_mix, 7, sizeof(float), (void *)&compress); - dt_opencl_set_kernel_arg(devid, gd->kernel_shadows_highlights_mix, 8, sizeof(float), - (void *)&shadows_ccorrect); + dt_opencl_set_kernel_arg(devid, gd->kernel_shadows_highlights_mix, 8, sizeof(float), (void *)&shadows_ccorrect); dt_opencl_set_kernel_arg(devid, gd->kernel_shadows_highlights_mix, 9, sizeof(float), (void *)&highlights_ccorrect); dt_opencl_set_kernel_arg(devid, gd->kernel_shadows_highlights_mix, 10, sizeof(unsigned int), (void *)&flags); dt_opencl_set_kernel_arg(devid, gd->kernel_shadows_highlights_mix, 11, sizeof(int), (void *)&unbound_mask); - dt_opencl_set_kernel_arg(devid, gd->kernel_shadows_highlights_mix, 12, sizeof(float), - (void *)&low_approximation); - dt_opencl_set_kernel_arg(devid, gd->kernel_shadows_highlights_mix, 13, sizeof(float), - (void *)&whitepoint); + dt_opencl_set_kernel_arg(devid, gd->kernel_shadows_highlights_mix, 12, sizeof(float), (void *)&low_approximation); + dt_opencl_set_kernel_arg(devid, gd->kernel_shadows_highlights_mix, 13, sizeof(float), (void *)&whitepoint); err = dt_opencl_enqueue_kernel_2d(devid, gd->kernel_shadows_highlights_mix, sizes); if(err != CL_SUCCESS) goto error; @@ -601,8 +599,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m #endif void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling) + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling) { dt_iop_shadhi_data_t *d = (dt_iop_shadhi_data_t *)piece->data; @@ -620,7 +617,8 @@ void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t if(d->shadhi_algo == SHADHI_ALGO_BILATERAL) { // bilateral filter - tiling->factor = 2.0f + fmax(1.0f, (float)dt_bilateral_memory_use(width, height, sigma_s, sigma_r) / basebuffer); + tiling->factor = 2.0f + + fmax(1.0f, (float)dt_bilateral_memory_use(width, height, sigma_s, sigma_r) / basebuffer); tiling->maxbuf = fmax(1.0f, (float)dt_bilateral_singlebuffer_size(width, height, sigma_s, sigma_r) / basebuffer); } @@ -769,12 +767,12 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_shadhi_params_t)); module->default_params = calloc(1, sizeof(dt_iop_shadhi_params_t)); module->default_enabled = 0; - module->priority = 558; // module order created by iop_dependencies.py, do not edit! + module->priority = 565; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_shadhi_params_t); module->gui_data = NULL; dt_iop_shadhi_params_t tmp - = (dt_iop_shadhi_params_t){ DT_IOP_GAUSSIAN_ZERO, 100.0f, 50.0f, 0.0f, -50.0f, 0.0f, 50.0f, 100.0f, - 50.0f, UNBOUND_DEFAULT, 0.000001f, SHADHI_ALGO_GAUSSIAN }; + = (dt_iop_shadhi_params_t){ DT_IOP_GAUSSIAN_ZERO, 100.0f, 50.0f, 0.0f, -50.0f, 0.0f, 50.0f, 100.0f, 50.0f, + UNBOUND_DEFAULT, 0.000001f, SHADHI_ALGO_GAUSSIAN }; memcpy(module->params, &tmp, sizeof(dt_iop_shadhi_params_t)); memcpy(module->default_params, &tmp, sizeof(dt_iop_shadhi_params_t)); } @@ -782,8 +780,7 @@ void init(dt_iop_module_t *module) void init_global(dt_iop_module_so_t *module) { const int program = 6; // gaussian.cl, from programs.conf - dt_iop_shadhi_global_data_t *gd - = (dt_iop_shadhi_global_data_t *)malloc(sizeof(dt_iop_shadhi_global_data_t)); + dt_iop_shadhi_global_data_t *gd = (dt_iop_shadhi_global_data_t *)malloc(sizeof(dt_iop_shadhi_global_data_t)); module->data = gd; gd->kernel_shadows_highlights_mix = dt_opencl_create_kernel(program, "shadows_highlights_mix"); } @@ -863,7 +860,8 @@ void gui_init(struct dt_iop_module_t *self) g_signal_connect(G_OBJECT(g->shadhi_algo), "value-changed", G_CALLBACK(shadhi_algo_callback), self); g_signal_connect(G_OBJECT(g->compress), "value-changed", G_CALLBACK(compress_callback), self); g_signal_connect(G_OBJECT(g->shadows_ccorrect), "value-changed", G_CALLBACK(shadows_ccorrect_callback), self); - g_signal_connect(G_OBJECT(g->highlights_ccorrect), "value-changed", G_CALLBACK(highlights_ccorrect_callback), self); + g_signal_connect(G_OBJECT(g->highlights_ccorrect), "value-changed", G_CALLBACK(highlights_ccorrect_callback), + self); } void gui_cleanup(struct dt_iop_module_t *self) diff --git a/src/iop/sharpen.c b/src/iop/sharpen.c index ff8f6d6d78c4..c3c066cf2518 100644 --- a/src/iop/sharpen.c +++ b/src/iop/sharpen.c @@ -87,8 +87,7 @@ void init_presets(dt_iop_module_so_t *self) { dt_iop_sharpen_params_t tmp = (dt_iop_sharpen_params_t){ 2.0, 0.5, 0.5 }; // add the preset. - dt_gui_presets_add_generic(_("sharpen"), self->op, self->version(), &tmp, sizeof(dt_iop_sharpen_params_t), - 1); + dt_gui_presets_add_generic(_("sharpen"), self->op, self->version(), &tmp, sizeof(dt_iop_sharpen_params_t), 1); // restrict to raw images dt_gui_presets_update_ldr(_("sharpen"), self->op, self->version(), FOR_RAW); // make it auto-apply for matching images: @@ -159,10 +158,14 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m for(int l = -rad; l <= rad; l++) m[l] /= weight; int hblocksize; - dt_opencl_local_buffer_t hlocopt - = (dt_opencl_local_buffer_t){ .xoffset = 2 * rad, .xfactor = 1, .yoffset = 0, .yfactor = 1, - .cellsize = sizeof(float), .overhead = 0, - .sizex = 1 << 16, .sizey = 1 }; + dt_opencl_local_buffer_t hlocopt = (dt_opencl_local_buffer_t){.xoffset = 2 * rad, + .xfactor = 1, + .yoffset = 0, + .yfactor = 1, + .cellsize = sizeof(float), + .overhead = 0, + .sizex = 1 << 16, + .sizey = 1 }; if(dt_opencl_local_buffer_opt(devid, gd->kernel_sharpen_hblur, &hlocopt)) hblocksize = hlocopt.sizex; @@ -170,10 +173,14 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m hblocksize = 1; int vblocksize; - dt_opencl_local_buffer_t vlocopt - = (dt_opencl_local_buffer_t){ .xoffset = 1, .xfactor = 1, .yoffset = 2 * rad, .yfactor = 1, - .cellsize = sizeof(float), .overhead = 0, - .sizex = 1, .sizey = 1 << 16 }; + dt_opencl_local_buffer_t vlocopt = (dt_opencl_local_buffer_t){.xoffset = 1, + .xfactor = 1, + .yoffset = 2 * rad, + .yfactor = 1, + .cellsize = sizeof(float), + .overhead = 0, + .sizex = 1, + .sizey = 1 << 16 }; if(dt_opencl_local_buffer_opt(devid, gd->kernel_sharpen_vblur, &vlocopt)) vblocksize = vlocopt.sizey; @@ -259,8 +266,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling) + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling) { dt_iop_sharpen_data_t *d = (dt_iop_sharpen_data_t *)piece->data; const int rad = MIN(MAXR, ceilf(d->radius * roi_in->scale / piece->iscale)); @@ -409,11 +415,11 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const // fill unsharpened border for(int j = 0; j < rad; j++) - memcpy(((float *)ovoid) + (size_t)ch * j * roi_out->width, - ((float *)ivoid) + (size_t)ch * j * roi_in->width, (size_t)ch * sizeof(float) * roi_out->width); + memcpy(((float *)ovoid) + (size_t)ch * j * roi_out->width, ((float *)ivoid) + (size_t)ch * j * roi_in->width, + (size_t)ch * sizeof(float) * roi_out->width); for(int j = roi_out->height - rad; j < roi_out->height; j++) - memcpy(((float *)ovoid) + (size_t)ch * j * roi_out->width, - ((float *)ivoid) + (size_t)ch * j * roi_in->width, (size_t)ch * sizeof(float) * roi_out->width); + memcpy(((float *)ovoid) + (size_t)ch * j * roi_out->width, ((float *)ivoid) + (size_t)ch * j * roi_in->width, + (size_t)ch * sizeof(float) * roi_out->width); dt_free_align(tmp); @@ -454,7 +460,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const } } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #if defined(__SSE__) @@ -517,8 +524,8 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c for(int k = 0; k < wd4 * 4; k += 4, inp += 4 * ch) { - msum = _mm_add_ps( - msum, _mm_mul_ps(_mm_load_ps(mat + k), _mm_set_ps(inp[3 * ch], inp[2 * ch], inp[ch], inp[0]))); + msum = _mm_add_ps(msum, + _mm_mul_ps(_mm_load_ps(mat + k), _mm_set_ps(inp[3 * ch], inp[2 * ch], inp[ch], inp[0]))); } _mm_store_ps(sum, msum); *out = sum[0] + sum[1] + sum[2] + sum[3]; @@ -561,8 +568,8 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c for(int k = 0; k < wd4 * 4; k += 4, inp += step * 4) { - msum = _mm_add_ps(msum, _mm_mul_ps(_mm_load_ps(mat + k), - _mm_set_ps(inp[3 * step], inp[2 * step], inp[step], inp[0]))); + msum = _mm_add_ps( + msum, _mm_mul_ps(_mm_load_ps(mat + k), _mm_set_ps(inp[3 * step], inp[2 * step], inp[step], inp[0]))); } _mm_store_ps(sum, msum); *out = sum[0] + sum[1] + sum[2] + sum[3]; @@ -597,11 +604,11 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c // fill unsharpened border for(int j = 0; j < rad; j++) - memcpy(((float *)ovoid) + (size_t)ch * j * roi_out->width, - ((float *)ivoid) + (size_t)ch * j * roi_in->width, (size_t)ch * sizeof(float) * roi_out->width); + memcpy(((float *)ovoid) + (size_t)ch * j * roi_out->width, ((float *)ivoid) + (size_t)ch * j * roi_in->width, + (size_t)ch * sizeof(float) * roi_out->width); for(int j = roi_out->height - rad; j < roi_out->height; j++) - memcpy(((float *)ovoid) + (size_t)ch * j * roi_out->width, - ((float *)ivoid) + (size_t)ch * j * roi_in->width, (size_t)ch * sizeof(float) * roi_out->width); + memcpy(((float *)ovoid) + (size_t)ch * j * roi_out->width, ((float *)ivoid) + (size_t)ch * j * roi_in->width, + (size_t)ch * sizeof(float) * roi_out->width); dt_free_align(tmp); @@ -642,7 +649,8 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c } } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #endif @@ -713,7 +721,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_sharpen_params_t)); module->default_params = calloc(1, sizeof(dt_iop_sharpen_params_t)); module->default_enabled = 0; - module->priority = 735; // module order created by iop_dependencies.py, do not edit! + module->priority = 739; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_sharpen_params_t); module->gui_data = NULL; dt_iop_sharpen_params_t tmp = (dt_iop_sharpen_params_t){ 2.0, 0.5, 0.5 }; @@ -724,8 +732,7 @@ void init(dt_iop_module_t *module) void init_global(dt_iop_module_so_t *module) { const int program = 7; // sharpen.cl, from programs.conf - dt_iop_sharpen_global_data_t *gd - = (dt_iop_sharpen_global_data_t *)malloc(sizeof(dt_iop_sharpen_global_data_t)); + dt_iop_sharpen_global_data_t *gd = (dt_iop_sharpen_global_data_t *)malloc(sizeof(dt_iop_sharpen_global_data_t)); module->data = gd; gd->kernel_sharpen_hblur = dt_opencl_create_kernel(program, "sharpen_hblur"); gd->kernel_sharpen_vblur = dt_opencl_create_kernel(program, "sharpen_vblur"); diff --git a/src/iop/soften.c b/src/iop/soften.c index ce3ea5b91ca7..929f7296419a 100644 --- a/src/iop/soften.c +++ b/src/iop/soften.c @@ -435,10 +435,14 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m // printf("\n"); int hblocksize; - dt_opencl_local_buffer_t hlocopt - = (dt_opencl_local_buffer_t){ .xoffset = 2 * wdh, .xfactor = 1, .yoffset = 0, .yfactor = 1, - .cellsize = 4 * sizeof(float), .overhead = 0, - .sizex = 1 << 16, .sizey = 1 }; + dt_opencl_local_buffer_t hlocopt = (dt_opencl_local_buffer_t){.xoffset = 2 * wdh, + .xfactor = 1, + .yoffset = 0, + .yfactor = 1, + .cellsize = 4 * sizeof(float), + .overhead = 0, + .sizex = 1 << 16, + .sizey = 1 }; if(dt_opencl_local_buffer_opt(devid, gd->kernel_soften_hblur, &hlocopt)) hblocksize = hlocopt.sizex; @@ -446,10 +450,14 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m hblocksize = 1; int vblocksize; - dt_opencl_local_buffer_t vlocopt - = (dt_opencl_local_buffer_t){ .xoffset = 1, .xfactor = 1, .yoffset = 2 * wdh, .yfactor = 1, - .cellsize = 4 * sizeof(float), .overhead = 0, - .sizex = 1, .sizey = 1 << 16 }; + dt_opencl_local_buffer_t vlocopt = (dt_opencl_local_buffer_t){.xoffset = 1, + .xfactor = 1, + .yoffset = 2 * wdh, + .yfactor = 1, + .cellsize = 4 * sizeof(float), + .overhead = 0, + .sizex = 1, + .sizey = 1 << 16 }; if(dt_opencl_local_buffer_opt(devid, gd->kernel_soften_vblur, &vlocopt)) vblocksize = vlocopt.sizey; @@ -498,8 +506,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m dt_opencl_set_kernel_arg(devid, gd->kernel_soften_hblur, 4, sizeof(int), (void *)&width); dt_opencl_set_kernel_arg(devid, gd->kernel_soften_hblur, 5, sizeof(int), (void *)&height); dt_opencl_set_kernel_arg(devid, gd->kernel_soften_hblur, 6, sizeof(int), (void *)&hblocksize); - dt_opencl_set_kernel_arg(devid, gd->kernel_soften_hblur, 7, (hblocksize + 2 * wdh) * 4 * sizeof(float), - NULL); + dt_opencl_set_kernel_arg(devid, gd->kernel_soften_hblur, 7, (hblocksize + 2 * wdh) * 4 * sizeof(float), NULL); err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_soften_hblur, sizes, local); if(err != CL_SUCCESS) goto error; @@ -518,8 +525,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m dt_opencl_set_kernel_arg(devid, gd->kernel_soften_vblur, 4, sizeof(int), (void *)&width); dt_opencl_set_kernel_arg(devid, gd->kernel_soften_vblur, 5, sizeof(int), (void *)&height); dt_opencl_set_kernel_arg(devid, gd->kernel_soften_vblur, 6, sizeof(int), (void *)&vblocksize); - dt_opencl_set_kernel_arg(devid, gd->kernel_soften_vblur, 7, (vblocksize + 2 * wdh) * 4 * sizeof(float), - NULL); + dt_opencl_set_kernel_arg(devid, gd->kernel_soften_vblur, 7, (vblocksize + 2 * wdh) * 4 * sizeof(float), NULL); err = dt_opencl_enqueue_kernel_2d_with_local(devid, gd->kernel_soften_vblur, sizes, local); if(err != CL_SUCCESS) goto error; } @@ -552,8 +558,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m #endif void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, - struct dt_develop_tiling_t *tiling) + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out, struct dt_develop_tiling_t *tiling) { dt_iop_soften_data_t *d = (dt_iop_soften_data_t *)piece->data; @@ -581,8 +586,7 @@ void tiling_callback(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t void init_global(dt_iop_module_so_t *module) { const int program = 9; // soften.cl, from programs.conf - dt_iop_soften_global_data_t *gd - = (dt_iop_soften_global_data_t *)malloc(sizeof(dt_iop_soften_global_data_t)); + dt_iop_soften_global_data_t *gd = (dt_iop_soften_global_data_t *)malloc(sizeof(dt_iop_soften_global_data_t)); module->data = gd; gd->kernel_soften_overexposed = dt_opencl_create_kernel(program, "soften_overexposed"); gd->kernel_soften_hblur = dt_opencl_create_kernel(program, "soften_hblur"); @@ -679,7 +683,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_soften_params_t)); module->default_params = calloc(1, sizeof(dt_iop_soften_params_t)); module->default_enabled = 0; - module->priority = 838; // module order created by iop_dependencies.py, do not edit! + module->priority = 840; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_soften_params_t); module->gui_data = NULL; dt_iop_soften_params_t tmp = (dt_iop_soften_params_t){ 50, 100.0, 0.33, 50 }; diff --git a/src/iop/splittoning.c b/src/iop/splittoning.c index f5103d743b30..1625d9c598d8 100644 --- a/src/iop/splittoning.c +++ b/src/iop/splittoning.c @@ -454,7 +454,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_splittoning_params_t)); module->default_params = calloc(1, sizeof(dt_iop_splittoning_params_t)); module->default_enabled = 0; - module->priority = 867; // module order created by iop_dependencies.py, do not edit! + module->priority = 869; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_splittoning_params_t); module->gui_data = NULL; dt_iop_splittoning_params_t tmp = (dt_iop_splittoning_params_t){ 0, 0.5, 0.2, 0.5, 0.5, 33.0 }; @@ -469,7 +469,7 @@ void cleanup(dt_iop_module_t *module) } static inline int gui_init_tab(struct dt_iop_module_t *self, int line, const char *name, GtkWidget **ppcolor, - const GdkRGBA *c, GtkWidget **pphue, GtkWidget **ppsaturation) + const GdkRGBA *c, GtkWidget **pphue, GtkWidget **ppsaturation) { GtkGrid *grid = GTK_GRID(self->widget); gtk_grid_attach(grid, dt_ui_section_label_new(name), 0, line++, 2, 1); diff --git a/src/iop/spots.c b/src/iop/spots.c index 7c08ba0937aa..5f9a2725804c 100644 --- a/src/iop/spots.c +++ b/src/iop/spots.c @@ -64,8 +64,8 @@ int flags() return IOP_FLAGS_SUPPORTS_BLENDING | IOP_FLAGS_NO_MASKS; } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 1 && new_version == 2) { @@ -161,16 +161,16 @@ static void _resynch_params(struct dt_iop_module_t *self) static void _reset_form_creation(GtkWidget *widget, dt_iop_module_t *self) { dt_iop_spots_gui_data_t *g = (dt_iop_spots_gui_data_t *)self->gui_data; - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g->bt_path)) || - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g->bt_circle)) || - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g->bt_ellipse))) + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g->bt_path)) + || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g->bt_circle)) + || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g->bt_ellipse))) { // we unset the creation mode dt_masks_change_form_gui(NULL); } - if (widget != g->bt_path) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->bt_path), FALSE); - if (widget != g->bt_circle) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->bt_circle), FALSE); - if (widget != g->bt_ellipse) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->bt_ellipse), FALSE); + if(widget != g->bt_path) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->bt_path), FALSE); + if(widget != g->bt_circle) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->bt_circle), FALSE); + if(widget != g->bt_ellipse) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->bt_ellipse), FALSE); } static gboolean _add_path(GtkWidget *widget, GdkEventButton *e, dt_iop_module_t *self) @@ -217,9 +217,8 @@ static gboolean _add_ellipse(GtkWidget *widget, GdkEventButton *e, dt_iop_module } -static gboolean masks_form_is_in_roi(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, - dt_masks_form_t *form, const dt_iop_roi_t *roi_in, - const dt_iop_roi_t *roi_out) +static gboolean masks_form_is_in_roi(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, dt_masks_form_t *form, + const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out) { // we get the area for the form int fl, ft, fw, fh; @@ -242,8 +241,8 @@ void modify_roi_out(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t } // needed if mask dest is in roi and mask src is not -void modify_roi_in(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi_out, dt_iop_roi_t *roi_in) +void modify_roi_in(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t *piece, const dt_iop_roi_t *roi_out, + dt_iop_roi_t *roi_in) { *roi_in = *roi_out; @@ -302,8 +301,8 @@ void modify_roi_in(struct dt_iop_module_t *self, struct dt_dev_pixelpipe_iop_t * roi_in->height = CLAMP(roib - roi_in->y, 1, scheight + .5f - roi_in->y); } -static void masks_point_denormalize(dt_dev_pixelpipe_iop_t *piece, const dt_iop_roi_t *roi, - const float *points, size_t points_count, float *new) +static void masks_point_denormalize(dt_dev_pixelpipe_iop_t *piece, const dt_iop_roi_t *roi, const float *points, + size_t points_count, float *new) { const float scalex = piece->pipe->iwidth * roi->scale, scaley = piece->pipe->iheight * roi->scale; @@ -314,9 +313,8 @@ static void masks_point_denormalize(dt_dev_pixelpipe_iop_t *piece, const dt_iop_ } } -static int masks_point_calc_delta(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, - const dt_iop_roi_t *roi, const float *target, const float *source, int *dx, - int *dy) +static int masks_point_calc_delta(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const dt_iop_roi_t *roi, + const float *target, const float *source, int *dx, int *dy) { float points[4]; masks_point_denormalize(piece, roi, target, 1, points); @@ -468,7 +466,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const out[4 * ((size_t)roi_out->width * (yy - roi_out->y) + xx - roi_out->x) + c] = out[4 * ((size_t)roi_out->width * (yy - roi_out->y) + xx - roi_out->x) + c] * (1.0f - f) + in[4 * ((size_t)roi_in->width * (yy - posy + posy_source - roi_in->y) + xx - posx - + posx_source - roi_in->x) + c] * f; + + posx_source - roi_in->x) + + c] * f; } } @@ -538,7 +537,7 @@ void init(dt_iop_module_t *module) // our module is disabled by default // by default: module->default_enabled = 0; - module->priority = 176; // module order created by iop_dependencies.py, do not edit! + module->priority = 188; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_spots_params_t); module->gui_data = NULL; // init defaults: @@ -569,7 +568,7 @@ void gui_focus(struct dt_iop_module_t *self, gboolean in) else { // lost focus, hide all shapes - if (darktable.develop->form_gui->creation && darktable.develop->form_gui->creation_module == self) + if(darktable.develop->form_gui->creation && darktable.develop->form_gui->creation_module == self) dt_masks_change_form_gui(NULL); dt_iop_spots_gui_data_t *g = (dt_iop_spots_gui_data_t *)self->gui_data; gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->bt_path), FALSE); @@ -649,16 +648,14 @@ void gui_init(dt_iop_module_t *self) gtk_widget_set_size_request(GTK_WIDGET(g->bt_path), bs, bs); gtk_box_pack_end(GTK_BOX(hbox), g->bt_path, FALSE, FALSE, 0); - g->bt_ellipse - = dtgtk_togglebutton_new(dtgtk_cairo_paint_masks_ellipse, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); + g->bt_ellipse = dtgtk_togglebutton_new(dtgtk_cairo_paint_masks_ellipse, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); g_signal_connect(G_OBJECT(g->bt_ellipse), "button-press-event", G_CALLBACK(_add_ellipse), self); gtk_widget_set_tooltip_text(g->bt_ellipse, _("add ellipse")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->bt_ellipse), FALSE); gtk_widget_set_size_request(GTK_WIDGET(g->bt_ellipse), bs, bs); gtk_box_pack_end(GTK_BOX(hbox), g->bt_ellipse, FALSE, FALSE, 0); - g->bt_circle - = dtgtk_togglebutton_new(dtgtk_cairo_paint_masks_circle, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); + g->bt_circle = dtgtk_togglebutton_new(dtgtk_cairo_paint_masks_circle, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); g_signal_connect(G_OBJECT(g->bt_circle), "button-press-event", G_CALLBACK(_add_circle), self); gtk_widget_set_tooltip_text(g->bt_circle, _("add circle")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->bt_circle), FALSE); @@ -684,19 +681,19 @@ void gui_cleanup(dt_iop_module_t *self) self->gui_data = NULL; } -void init_key_accels (dt_iop_module_so_t *module) +void init_key_accels(dt_iop_module_so_t *module) { - dt_accel_register_iop (module, TRUE, NC_("accel", "spot circle tool"), 0, 0); - dt_accel_register_iop (module, TRUE, NC_("accel", "spot elipse tool"), 0, 0); - dt_accel_register_iop (module, TRUE, NC_("accel", "spot path tool"), 0, 0); - dt_accel_register_iop (module, TRUE, NC_("accel", "spot show or hide"), 0, 0); + dt_accel_register_iop(module, TRUE, NC_("accel", "spot circle tool"), 0, 0); + dt_accel_register_iop(module, TRUE, NC_("accel", "spot elipse tool"), 0, 0); + dt_accel_register_iop(module, TRUE, NC_("accel", "spot path tool"), 0, 0); + dt_accel_register_iop(module, TRUE, NC_("accel", "spot show or hide"), 0, 0); } static gboolean _add_circle_key_accel(GtkAccelGroup *accel_group, GObject *acceleratable, guint keyval, GdkModifierType modifier, gpointer data) { dt_iop_module_t *module = (dt_iop_module_t *)data; - const dt_iop_spots_gui_data_t *g = (dt_iop_spots_gui_data_t *) module->gui_data; + const dt_iop_spots_gui_data_t *g = (dt_iop_spots_gui_data_t *)module->gui_data; _add_circle(GTK_WIDGET(g->bt_circle), NULL, module); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->bt_circle), TRUE); return TRUE; @@ -706,7 +703,7 @@ static gboolean _add_ellipse_key_accel(GtkAccelGroup *accel_group, GObject *acce GdkModifierType modifier, gpointer data) { dt_iop_module_t *module = (dt_iop_module_t *)data; - const dt_iop_spots_gui_data_t *g = (dt_iop_spots_gui_data_t *) module->gui_data; + const dt_iop_spots_gui_data_t *g = (dt_iop_spots_gui_data_t *)module->gui_data; _add_ellipse(GTK_WIDGET(g->bt_ellipse), NULL, module); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->bt_ellipse), TRUE); return TRUE; @@ -716,7 +713,7 @@ static gboolean _add_path_key_accel(GtkAccelGroup *accel_group, GObject *acceler GdkModifierType modifier, gpointer data) { dt_iop_module_t *module = (dt_iop_module_t *)data; - const dt_iop_spots_gui_data_t *g = (dt_iop_spots_gui_data_t *) module->gui_data; + const dt_iop_spots_gui_data_t *g = (dt_iop_spots_gui_data_t *)module->gui_data; _add_path(GTK_WIDGET(g->bt_path), NULL, module); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->bt_path), TRUE); return TRUE; @@ -726,25 +723,26 @@ static gboolean _show_hide_key_accel(GtkAccelGroup *accel_group, GObject *accele GdkModifierType modifier, gpointer data) { dt_iop_module_t *module = (dt_iop_module_t *)data; - dt_masks_set_edit_mode(module, module->dev->form_gui->edit_mode == DT_MASKS_EDIT_FULL ? DT_MASKS_EDIT_OFF : DT_MASKS_EDIT_FULL); + dt_masks_set_edit_mode(module, module->dev->form_gui->edit_mode == DT_MASKS_EDIT_FULL ? DT_MASKS_EDIT_OFF + : DT_MASKS_EDIT_FULL); return TRUE; } -void connect_key_accels (dt_iop_module_t *module) +void connect_key_accels(dt_iop_module_t *module) { GClosure *closure; closure = g_cclosure_new(G_CALLBACK(_add_circle_key_accel), (gpointer)module, NULL); - dt_accel_connect_iop (module, "spot circle tool", closure); + dt_accel_connect_iop(module, "spot circle tool", closure); closure = g_cclosure_new(G_CALLBACK(_add_ellipse_key_accel), (gpointer)module, NULL); - dt_accel_connect_iop (module, "spot elipse tool", closure); + dt_accel_connect_iop(module, "spot elipse tool", closure); closure = g_cclosure_new(G_CALLBACK(_add_path_key_accel), (gpointer)module, NULL); - dt_accel_connect_iop (module, "spot path tool", closure); + dt_accel_connect_iop(module, "spot path tool", closure); closure = g_cclosure_new(G_CALLBACK(_show_hide_key_accel), (gpointer)module, NULL); - dt_accel_connect_iop (module, "spot show or hide", closure); + dt_accel_connect_iop(module, "spot show or hide", closure); } // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh diff --git a/src/iop/svd.h b/src/iop/svd.h index 73638729520d..1b7d6c7e8e53 100644 --- a/src/iop/svd.h +++ b/src/iop/svd.h @@ -1,10 +1,10 @@ -/* - * svdcomp - SVD decomposition routine. +/* + * svdcomp - SVD decomposition routine. * Takes an mxn matrix a and decomposes it into udv, where u,v are - * left and right orthogonal transformation matrices, and d is a + * left and right orthogonal transformation matrices, and d is a * diagonal matrix of singular values. * - * This routine is adapted from svdecomp.c in XLISP-STAT 2.1 which is + * This routine is adapted from svdecomp.c in XLISP-STAT 2.1 which is * adapted by Luke Tierney and David Betz. * * the now dead xlisp-stat package seems to have been distributed @@ -30,9 +30,18 @@ static inline double PYTHAG(double a, double b) { double at = fabs(a), bt = fabs(b), ct, result; - if (at > bt) { ct = bt / at; result = at * sqrt(1.0 + ct * ct); } - else if (bt > 0.0) { ct = at / bt; result = bt * sqrt(1.0 + ct * ct); } - else result = 0.0; + if(at > bt) + { + ct = bt / at; + result = at * sqrt(1.0 + ct * ct); + } + else if(bt > 0.0) + { + ct = at / bt; + result = bt * sqrt(1.0 + ct * ct); + } + else + result = 0.0; return result; } @@ -44,214 +53,195 @@ static inline double PYTHAG(double a, double b) // | | | | | | // // where the data layout of a (in) and u (out) is strided by str for every row -static inline int dsvd( - double *a, // input matrix a[j*str + i] is j-th row and i-th column. will be overwritten by u - int m, // number of rows of a and u - int n, // number of cols of a and u - int str, // row stride of a and u - double *w, // output singular values w[n] - double *v) // output v matrix v[n*n] +static inline int +dsvd(double *a, // input matrix a[j*str + i] is j-th row and i-th column. will be overwritten by u + int m, // number of rows of a and u + int n, // number of cols of a and u + int str, // row stride of a and u + double *w, // output singular values w[n] + double *v) // output v matrix v[n*n] { int flag, i, its, j, jj, k, l, nm; double c, f, h, s, x, y, z; double anorm = 0.0, g = 0.0, scale = 0.0; - if (m < n) + if(m < n) { fprintf(stderr, "[svd] #rows must be >= #cols \n"); - return(0); + return (0); } double *rv1 = malloc(n * sizeof(double)); /* Householder reduction to bidiagonal form */ - for (i = 0; i < n; i++) + for(i = 0; i < n; i++) { /* left-hand reduction */ l = i + 1; rv1[i] = scale * g; g = s = scale = 0.0; - if (i < m) + if(i < m) { - for (k = i; k < m; k++) - scale += fabs(a[k*str+i]); - if (scale) + for(k = i; k < m; k++) scale += fabs(a[k * str + i]); + if(scale) { - for (k = i; k < m; k++) + for(k = i; k < m; k++) { - a[k*str+i] = a[k*str+i]/scale; - s += a[k*str+i] * a[k*str+i]; + a[k * str + i] = a[k * str + i] / scale; + s += a[k * str + i] * a[k * str + i]; } - f = a[i*str+i]; + f = a[i * str + i]; g = -SIGN(sqrt(s), f); h = f * g - s; - a[i*str+i] = f - g; - if (i != n - 1) + a[i * str + i] = f - g; + if(i != n - 1) { - for (j = l; j < n; j++) + for(j = l; j < n; j++) { - for (s = 0.0, k = i; k < m; k++) - s += a[k*str+i] * a[k*str+j]; + for(s = 0.0, k = i; k < m; k++) s += a[k * str + i] * a[k * str + j]; f = s / h; - for (k = i; k < m; k++) - a[k*str+j] += f * a[k*str+i]; + for(k = i; k < m; k++) a[k * str + j] += f * a[k * str + i]; } } - for (k = i; k < m; k++) - a[k*str+i] = a[k*str+i]*scale; + for(k = i; k < m; k++) a[k * str + i] = a[k * str + i] * scale; } } w[i] = scale * g; /* right-hand reduction */ g = s = scale = 0.0; - if (i < m && i != n - 1) + if(i < m && i != n - 1) { - for (k = l; k < n; k++) - scale += fabs(a[i*str+k]); - if (scale) + for(k = l; k < n; k++) scale += fabs(a[i * str + k]); + if(scale) { - for (k = l; k < n; k++) + for(k = l; k < n; k++) { - a[i*str+k] = a[i*str+k]/scale; - s += a[i*str+k] * a[i*str+k]; + a[i * str + k] = a[i * str + k] / scale; + s += a[i * str + k] * a[i * str + k]; } - f = a[i*str+l]; + f = a[i * str + l]; g = -SIGN(sqrt(s), f); h = f * g - s; - a[i*str+l] = f - g; - for (k = l; k < n; k++) - rv1[k] = a[i*str+k] / h; - if (i != m - 1) + a[i * str + l] = f - g; + for(k = l; k < n; k++) rv1[k] = a[i * str + k] / h; + if(i != m - 1) { - for (j = l; j < m; j++) + for(j = l; j < m; j++) { - for (s = 0.0, k = l; k < n; k++) - s += a[j*str+k] * a[i*str+k]; - for (k = l; k < n; k++) - a[j*str+k] += s * rv1[k]; + for(s = 0.0, k = l; k < n; k++) s += a[j * str + k] * a[i * str + k]; + for(k = l; k < n; k++) a[j * str + k] += s * rv1[k]; } } - for (k = l; k < n; k++) - a[i*str+k] = a[i*str+k]*scale; + for(k = l; k < n; k++) a[i * str + k] = a[i * str + k] * scale; } } anorm = MAX(anorm, (fabs(w[i]) + fabs(rv1[i]))); } /* accumulate the right-hand transformation */ - for (i = n - 1; i >= 0; i--) + for(i = n - 1; i >= 0; i--) { - if (i < n - 1) + if(i < n - 1) { - if (g) + if(g) { - for (j = l; j < n; j++) - v[j*n+i] = a[i*str+j] / a[i*str+l] / g; + for(j = l; j < n; j++) v[j * n + i] = a[i * str + j] / a[i * str + l] / g; /* double division to avoid underflow */ - for (j = l; j < n; j++) + for(j = l; j < n; j++) { - for (s = 0.0, k = l; k < n; k++) - s += a[i*str+k] * v[k*n+j]; - for (k = l; k < n; k++) - v[k*n+j] += s * v[k*n+i]; + for(s = 0.0, k = l; k < n; k++) s += a[i * str + k] * v[k * n + j]; + for(k = l; k < n; k++) v[k * n + j] += s * v[k * n + i]; } } - for (j = l; j < n; j++) - v[i*n+j] = v[j*n+i] = 0.0; + for(j = l; j < n; j++) v[i * n + j] = v[j * n + i] = 0.0; } - v[i*n+i] = 1.0; + v[i * n + i] = 1.0; g = rv1[i]; l = i; } /* accumulate the left-hand transformation */ - for (i = n - 1; i >= 0; i--) + for(i = n - 1; i >= 0; i--) { l = i + 1; g = w[i]; - if (i < n - 1) - for (j = l; j < n; j++) - a[i*str+j] = 0.0; - if (g) + if(i < n - 1) + for(j = l; j < n; j++) a[i * str + j] = 0.0; + if(g) { g = 1.0 / g; - if (i != n - 1) + if(i != n - 1) { - for (j = l; j < n; j++) + for(j = l; j < n; j++) { - for (s = 0.0, k = l; k < m; k++) - s += a[k*str+i] * a[k*str+j]; - f = (s / a[i*str+i]) * g; - for (k = i; k < m; k++) - a[k*str+j] += f * a[k*str+i]; + for(s = 0.0, k = l; k < m; k++) s += a[k * str + i] * a[k * str + j]; + f = (s / a[i * str + i]) * g; + for(k = i; k < m; k++) a[k * str + j] += f * a[k * str + i]; } } - for (j = i; j < m; j++) - a[j*str+i] = a[j*str+i]*g; + for(j = i; j < m; j++) a[j * str + i] = a[j * str + i] * g; } - else + else { - for (j = i; j < m; j++) - a[j*str+i] = 0.0; + for(j = i; j < m; j++) a[j * str + i] = 0.0; } - ++a[i*str+i]; + ++a[i * str + i]; } /* diagonalize the bidiagonal form */ - for (k = n - 1; k >= 0; k--) - { /* loop over singular values */ - for (its = 0; its < 30; its++) - { /* loop over allowed iterations */ + for(k = n - 1; k >= 0; k--) + { /* loop over singular values */ + for(its = 0; its < 30; its++) + { /* loop over allowed iterations */ flag = 1; - for (l = k; l >= 0; l--) - { /* test for splitting */ + for(l = k; l >= 0; l--) + { /* test for splitting */ nm = MAX(0, l - 1); - if (fabs(rv1[l]) + anorm == anorm) + if(fabs(rv1[l]) + anorm == anorm) { flag = 0; break; } - if (l == 0 || fabs(w[nm]) + anorm == anorm) - break; + if(l == 0 || fabs(w[nm]) + anorm == anorm) break; } - if (flag) + if(flag) { c = 0.0; s = 1.0; - for (i = l; i <= k; i++) + for(i = l; i <= k; i++) { f = s * rv1[i]; - if (fabs(f) + anorm != anorm) + if(fabs(f) + anorm != anorm) { g = w[i]; h = PYTHAG(f, g); - w[i] = h; + w[i] = h; h = 1.0 / h; c = g * h; - s = (- f * h); - for (j = 0; j < m; j++) + s = (-f * h); + for(j = 0; j < m; j++) { - y = a[j*str+nm]; - z = a[j*str+i]; - a[j*str+nm] = y * c + z * s; - a[j*str+i] = z * c - y * s; + y = a[j * str + nm]; + z = a[j * str + i]; + a[j * str + nm] = y * c + z * s; + a[j * str + i] = z * c - y * s; } } } } z = w[k]; - if (l == k) - { /* convergence */ - if (z < 0.0) - { /* make singular value nonnegative */ + if(l == k) + { /* convergence */ + if(z < 0.0) + { /* make singular value nonnegative */ w[k] = -z; - for (j = 0; j < n; j++) - v[j*n+k] = (-v[j*n+k]); + for(j = 0; j < n; j++) v[j * n + k] = (-v[j * n + k]); } break; } - if (its >= 30) { + if(its >= 30) + { fprintf(stderr, "[svd] no convergence after 30,000! iterations\n"); free(rv1); return 0; @@ -269,7 +259,7 @@ static inline int dsvd( /* next QR transformation */ c = s = 1.0; - for (j = l; j <= nm; j++) + for(j = l; j <= nm; j++) { i = j + 1; g = rv1[i]; @@ -284,16 +274,16 @@ static inline int dsvd( g = g * c - x * s; h = y * s; y = y * c; - for (jj = 0; jj < n; jj++) + for(jj = 0; jj < n; jj++) { - x = v[jj*n+j]; - z = v[jj*n+i]; - v[jj*n+j] = x * c + z * s; - v[jj*n+i] = z * c - x * s; + x = v[jj * n + j]; + z = v[jj * n + i]; + v[jj * n + j] = x * c + z * s; + v[jj * n + i] = z * c - x * s; } z = PYTHAG(f, h); w[j] = z; - if (z) + if(z) { z = 1.0 / z; c = f * z; @@ -301,12 +291,12 @@ static inline int dsvd( } f = (c * g) + (s * y); x = (c * y) - (s * g); - for (jj = 0; jj < m; jj++) + for(jj = 0; jj < m; jj++) { - y = a[jj*str+j]; - z = a[jj*str+i]; - a[jj*str+j] = y * c + z * s; - a[jj*str+i] = z * c - y * s; + y = a[jj * str + j]; + z = a[jj * str + i]; + a[jj * str + j] = y * c + z * s; + a[jj * str + i] = z * c - y * s; } } rv1[l] = 0.0; @@ -317,4 +307,3 @@ static inline int dsvd( free(rv1); return 1; } - diff --git a/src/iop/temperature.c b/src/iop/temperature.c index d6bb6122826c..46bdee7c6444 100644 --- a/src/iop/temperature.c +++ b/src/iop/temperature.c @@ -89,8 +89,8 @@ typedef struct dt_iop_temperature_global_data_t int kernel_whitebalance_1f_xtrans; } dt_iop_temperature_global_data_t; -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 2 && new_version == 3) { @@ -129,31 +129,17 @@ static int ignore_missing_wb(dt_image_t *img) { // Ignore files that end with "-hdr.dng" since these are broken files we // generated without any proper WB tagged - if(g_str_has_suffix(img->filename,"-hdr.dng")) - return TRUE; + if(g_str_has_suffix(img->filename, "-hdr.dng")) return TRUE; static const char *const ignored_cameras[] = { - "Canon PowerShot A610", - "Canon PowerShot S3 IS", - "Canon PowerShot A620", - "Canon PowerShot A720 IS", - "Canon PowerShot A630", - "Canon PowerShot A640", - "Canon PowerShot A650", - "Canon PowerShot SX110 IS", - "Mamiya ZD", - "Canon EOS D2000C", - "Kodak EOS DCS 1", - "Kodak DCS560C", - "Kodak DCS460D", - "Nikon E5700", - "Sony DSC-F828", - "GITUP GIT2", + "Canon PowerShot A610", "Canon PowerShot S3 IS", "Canon PowerShot A620", "Canon PowerShot A720 IS", + "Canon PowerShot A630", "Canon PowerShot A640", "Canon PowerShot A650", "Canon PowerShot SX110 IS", + "Mamiya ZD", "Canon EOS D2000C", "Kodak EOS DCS 1", "Kodak DCS560C", "Kodak DCS460D", "Nikon E5700", + "Sony DSC-F828", "GITUP GIT2", }; - for(int i=0; i < sizeof(ignored_cameras)/sizeof(ignored_cameras[1]); i++) - if(!strcmp(img->camera_makermodel, ignored_cameras[i])) - return TRUE; + for(int i = 0; i < sizeof(ignored_cameras) / sizeof(ignored_cameras[1]); i++) + if(!strcmp(img->camera_makermodel, ignored_cameras[i])) return TRUE; return FALSE; } @@ -295,9 +281,8 @@ static double spd_daylight(unsigned long int wavelength, double TempK) m1 = (-1.3515 - 1.7703 * WhitePoint.x + 5.9114 * WhitePoint.y) / M, m2 = (0.0300 - 31.4424 * WhitePoint.x + 30.0717 * WhitePoint.y) / M; - const unsigned long int j - = ((wavelength - cie_daylight_components[0].wavelength) - / (cie_daylight_components[1].wavelength - cie_daylight_components[0].wavelength)); + const unsigned long int j = ((wavelength - cie_daylight_components[0].wavelength) + / (cie_daylight_components[1].wavelength - cie_daylight_components[0].wavelength)); return (cie_daylight_components[j].S[0] + m1 * cie_daylight_components[j].S[1] + m2 * cie_daylight_components[j].S[2]); @@ -447,7 +432,7 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) { const uint32_t filters = piece->pipe->dsc.filters; - const uint8_t(*const xtrans)[6] = (const uint8_t(*const)[6])piece->pipe->dsc.xtrans; + const uint8_t (*const xtrans)[6] = (const uint8_t (*const)[6])piece->pipe->dsc.xtrans; const dt_iop_temperature_data_t *const d = (dt_iop_temperature_data_t *)piece->data; const float *const in = (const float *const)ivoid; @@ -497,7 +482,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const } } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } piece->pipe->dsc.temperature.enabled = 1; @@ -513,7 +499,7 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) { const uint32_t filters = piece->pipe->dsc.filters; - const uint8_t(*const xtrans)[6] = (const uint8_t(*const)[6])piece->pipe->dsc.xtrans; + const uint8_t (*const xtrans)[6] = (const uint8_t (*const)[6])piece->pipe->dsc.xtrans; dt_iop_temperature_data_t *d = (dt_iop_temperature_data_t *)piece->data; if(filters == 9u) { // xtrans float mosaiced @@ -616,7 +602,8 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c } _mm_sfence(); - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } piece->pipe->dsc.temperature.enabled = 1; @@ -762,7 +749,7 @@ void gui_update(struct dt_iop_module_t *self) for(int i = 0; i < wb_preset_count; i++) { if(g->preset_cnt >= 50) break; - if(!strcmp(wb_preset[i].make, self->dev->image_storage.camera_maker) + if(!strcmp(wb_preset[i].make, self->dev->image_storage.camera_maker) && !strcmp(wb_preset[i].model, self->dev->image_storage.camera_model)) { if(!wb_name || strcmp(wb_name, wb_preset[i].name)) @@ -799,10 +786,10 @@ void gui_update(struct dt_iop_module_t *self) for(int j = DT_IOP_NUM_OF_STD_TEMP_PRESETS; !found && (j < g->preset_cnt); j++) { // look through all variants of this preset, with different tuning - for(int i = g->preset_num[j]; !found && (i < wb_preset_count) - && !strcmp(wb_preset[i].make, self->dev->image_storage.camera_maker) - && !strcmp(wb_preset[i].model, self->dev->image_storage.camera_model) - && !strcmp(wb_preset[i].name, wb_preset[g->preset_num[j]].name); + for(int i = g->preset_num[j]; + !found && (i < wb_preset_count) && !strcmp(wb_preset[i].make, self->dev->image_storage.camera_maker) + && !strcmp(wb_preset[i].model, self->dev->image_storage.camera_model) + && !strcmp(wb_preset[i].name, wb_preset[g->preset_num[j]].name); i++) { float coeffs[3]; @@ -882,7 +869,7 @@ static int calculate_bogus_daylight_wb(dt_iop_module_t *module, double bwb[4]) } double mul[4]; - if (dt_colorspaces_conversion_matrices_rgb(module->dev->image_storage.camera_makermodel, NULL, NULL, mul)) + if(dt_colorspaces_conversion_matrices_rgb(module->dev->image_storage.camera_makermodel, NULL, NULL, mul)) { // normalize green: bwb[0] = mul[0] / mul[1]; @@ -920,8 +907,8 @@ static void prepare_matrices(dt_iop_module_t *module) } char *camera = module->dev->image_storage.camera_makermodel; - if (!dt_colorspaces_conversion_matrices_xyz(camera, module->dev->image_storage.d65_color_matrix, - g->XYZ_to_CAM, g->CAM_to_XYZ)) + if(!dt_colorspaces_conversion_matrices_xyz(camera, module->dev->image_storage.d65_color_matrix, g->XYZ_to_CAM, + g->CAM_to_XYZ)) { fprintf(stderr, "[temperature] `%s' color matrix not found for image\n", camera); dt_control_log(_("`%s' color matrix not found for image"), camera); @@ -930,8 +917,7 @@ static void prepare_matrices(dt_iop_module_t *module) void reload_defaults(dt_iop_module_t *module) { - dt_iop_temperature_params_t tmp - = (dt_iop_temperature_params_t){.coeffs = { 1.0, 1.0, 1.0, 1.0 } }; + dt_iop_temperature_params_t tmp = (dt_iop_temperature_params_t){.coeffs = { 1.0, 1.0, 1.0, 1.0 } }; // we might be called from presets update infrastructure => there is no image if(!module->dev) goto end; @@ -1048,7 +1034,7 @@ void reload_defaults(dt_iop_module_t *module) // we're normalizing that to be D65 for(int i = 0; i < wb_preset_count; i++) { - if(!strcmp(wb_preset[i].make, module->dev->image_storage.camera_maker) + if(!strcmp(wb_preset[i].make, module->dev->image_storage.camera_maker) && !strcmp(wb_preset[i].model, module->dev->image_storage.camera_model) && !strcmp(wb_preset[i].name, Daylight) && wb_preset[i].tuning == 0) { @@ -1091,7 +1077,7 @@ void init(dt_iop_module_t *module) { module->params = calloc(1, sizeof(dt_iop_temperature_params_t)); module->default_params = calloc(1, sizeof(dt_iop_temperature_params_t)); - module->priority = 44; // module order created by iop_dependencies.py, do not edit! + module->priority = 43; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_temperature_params_t); module->gui_data = NULL; } @@ -1248,18 +1234,17 @@ static void apply_preset(dt_iop_module_t *self) self->request_color_pick = DT_REQUEST_COLORPICK_MODULE; /* set the area sample size*/ - if(self->request_color_pick != DT_REQUEST_COLORPICK_OFF) - dt_lib_colorpicker_set_area(darktable.lib, 0.99); + if(self->request_color_pick != DT_REQUEST_COLORPICK_OFF) dt_lib_colorpicker_set_area(darktable.lib, 0.99); break; default: // camera WB presets { gboolean found = FALSE; // look through all variants of this preset, with different tuning - for(int i = g->preset_num[pos]; (i < wb_preset_count) - && !strcmp(wb_preset[i].make, self->dev->image_storage.camera_maker) - && !strcmp(wb_preset[i].model, self->dev->image_storage.camera_model) - && !strcmp(wb_preset[i].name, wb_preset[g->preset_num[pos]].name); + for(int i = g->preset_num[pos]; + (i < wb_preset_count) && !strcmp(wb_preset[i].make, self->dev->image_storage.camera_maker) + && !strcmp(wb_preset[i].model, self->dev->image_storage.camera_model) + && !strcmp(wb_preset[i].name, wb_preset[g->preset_num[pos]].name); i++) { if(wb_preset[i].tuning == tune) @@ -1367,10 +1352,9 @@ void gui_init(struct dt_iop_module_t *self) g_signal_connect(G_OBJECT(self->widget), "draw", G_CALLBACK(draw), self); for(int k = 0; k < 4; k++) g->daylight_wb[k] = 1.0; - g->scale_tint - = dt_bauhaus_slider_new_with_range(self, DT_IOP_LOWEST_TINT, DT_IOP_HIGHEST_TINT, .01, 1.0, 3); - g->scale_k = dt_bauhaus_slider_new_with_range(self, DT_IOP_LOWEST_TEMPERATURE, DT_IOP_HIGHEST_TEMPERATURE, - 10., 5000.0, 0); + g->scale_tint = dt_bauhaus_slider_new_with_range(self, DT_IOP_LOWEST_TINT, DT_IOP_HIGHEST_TINT, .01, 1.0, 3); + g->scale_k = dt_bauhaus_slider_new_with_range(self, DT_IOP_LOWEST_TEMPERATURE, DT_IOP_HIGHEST_TEMPERATURE, 10., + 5000.0, 0); g->coeff_widgets = gtk_box_new(GTK_ORIENTATION_VERTICAL, DT_BAUHAUS_SPACE); g->scale_r = dt_bauhaus_slider_new_with_range(self, 0.0, 8.0, .001, p->coeffs[0], 3); @@ -1379,13 +1363,14 @@ void gui_init(struct dt_iop_module_t *self) g->scale_g2 = dt_bauhaus_slider_new_with_range(self, 0.0, 8.0, .001, p->coeffs[3], 3); // reflect actual black body colors for the temperature slider - const double temp_step = (double)(DT_IOP_HIGHEST_TEMPERATURE - DT_IOP_LOWEST_TEMPERATURE) / (DT_BAUHAUS_SLIDER_MAX_STOPS - 1.0); + const double temp_step = (double)(DT_IOP_HIGHEST_TEMPERATURE - DT_IOP_LOWEST_TEMPERATURE) + / (DT_BAUHAUS_SLIDER_MAX_STOPS - 1.0); for(int i = 0; i < DT_BAUHAUS_SLIDER_MAX_STOPS; i++) { const float stop = i / (DT_BAUHAUS_SLIDER_MAX_STOPS - 1.0); const double K = DT_IOP_LOWEST_TEMPERATURE + i * temp_step; cmsCIEXYZ cmsXYZ = temperature_to_XYZ(K); - float sRGB[3], XYZ[3] = {cmsXYZ.X, cmsXYZ.Y, cmsXYZ.Z}; + float sRGB[3], XYZ[3] = { cmsXYZ.X, cmsXYZ.Y, cmsXYZ.Z }; dt_XYZ_to_sRGB_clipped(XYZ, sRGB); dt_bauhaus_slider_set_stop(g->scale_k, stop, sRGB[0], sRGB[1], sRGB[2]); } diff --git a/src/iop/tonecurve.c b/src/iop/tonecurve.c index 318f3202a899..31d58dbaa90a 100644 --- a/src/iop/tonecurve.c +++ b/src/iop/tonecurve.c @@ -72,13 +72,13 @@ typedef struct dt_iop_tonecurve_node_t typedef enum dt_iop_tonecurve_autoscale_t { - s_scale_manual = 0, // user specified curves - s_scale_automatic = 1, // automatically adjust saturation based on L_out/L_in - s_scale_automatic_xyz = 2, // automatically adjust saturation by - // transforming the curve C to C' like: - // L_out=C(L_in) -> Y_out=C'(Y_in) and applying C' to the X and Z - // channels, too (and then transforming it back to Lab of course) - s_scale_automatic_rgb = 3, // similar to above but use an rgb working space + s_scale_manual = 0, // user specified curves + s_scale_automatic = 1, // automatically adjust saturation based on L_out/L_in + s_scale_automatic_xyz = 2, // automatically adjust saturation by + // transforming the curve C to C' like: + // L_out=C(L_in) -> Y_out=C'(Y_in) and applying C' to the X and Z + // channels, too (and then transforming it back to Lab of course) + s_scale_automatic_rgb = 3, // similar to above but use an rgb working space } dt_iop_tonecurve_autoscale_t; // parameter structure of tonecurve 1st version, needed for use in legacy_params() @@ -163,8 +163,8 @@ int flags() return IOP_FLAGS_SUPPORTS_BLENDING | IOP_FLAGS_ALLOW_TILING; } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 1 && new_version == 4) { @@ -329,14 +329,12 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const { // new style handling of a/b curves: lut lookup with two-sided extrapolation; // mind the x-axis reversal for the left-handed side - out[1] = (a_in > xm_ar) - ? dt_iop_eval_exp(d->unbounded_coeffs_ab, a_in) - : ((a_in < xm_al) ? dt_iop_eval_exp(d->unbounded_coeffs_ab + 3, 1.0f - a_in) - : d->table[ch_a][CLAMP((int)(a_in * 0x10000ul), 0, 0xffff)]); - out[2] = (b_in > xm_br) - ? dt_iop_eval_exp(d->unbounded_coeffs_ab + 6, b_in) - : ((b_in < xm_bl) ? dt_iop_eval_exp(d->unbounded_coeffs_ab + 9, 1.0f - b_in) - : d->table[ch_b][CLAMP((int)(b_in * 0x10000ul), 0, 0xffff)]); + out[1] = (a_in > xm_ar) ? dt_iop_eval_exp(d->unbounded_coeffs_ab, a_in) + : ((a_in < xm_al) ? dt_iop_eval_exp(d->unbounded_coeffs_ab + 3, 1.0f - a_in) + : d->table[ch_a][CLAMP((int)(a_in * 0x10000ul), 0, 0xffff)]); + out[2] = (b_in > xm_br) ? dt_iop_eval_exp(d->unbounded_coeffs_ab + 6, b_in) + : ((b_in < xm_bl) ? dt_iop_eval_exp(d->unbounded_coeffs_ab + 9, 1.0f - b_in) + : d->table[ch_b][CLAMP((int)(b_in * 0x10000ul), 0, 0xffff)]); } } else if(autoscale_ab == s_scale_automatic) @@ -357,16 +355,16 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const { float XYZ[3]; dt_Lab_to_XYZ(in, XYZ); - for(int c=0;c<3;c++) + for(int c = 0; c < 3; c++) XYZ[c] = (XYZ[c] < xm_L) ? d->table[ch_L][CLAMP((int)(XYZ[c] * 0x10000ul), 0, 0xffff)] : dt_iop_eval_exp(d->unbounded_coeffs_L, XYZ[c]); dt_XYZ_to_Lab(XYZ, out); } else if(autoscale_ab == s_scale_automatic_rgb) { - float rgb[3] = {0, 0, 0}; + float rgb[3] = { 0, 0, 0 }; dt_Lab_to_prophotorgb(in, rgb); - for(int c=0;c<3;c++) + for(int c = 0; c < 3; c++) rgb[c] = (rgb[c] < xm_L) ? d->table[ch_L][CLAMP((int)(rgb[c] * 0x10000ul), 0, 0xffff)] : dt_iop_eval_exp(d->unbounded_coeffs_L, rgb[c]); dt_prophotorgb_to_Lab(rgb, out); @@ -465,7 +463,7 @@ void init_presets(dt_iop_module_so_t *self) for(int k = 1; k < 5; k++) p.tonecurve[ch_L][k].y = powf(p.tonecurve[ch_L][k].y, 2.2f); dt_gui_presets_add_generic(_("high contrast"), self->op, self->version(), &p, sizeof(p), 1); - for (int k=0; k<sizeof(preset_camera_curves)/sizeof(preset_camera_curves[0]); k++) + for(int k = 0; k < sizeof(preset_camera_curves) / sizeof(preset_camera_curves[0]); k++) { // insert the preset dt_gui_presets_add_generic(preset_camera_curves[k].name, self->op, self->version(), @@ -525,12 +523,12 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix if(p->tonecurve_autoscale_ab == s_scale_automatic_xyz) { // derive curve for XYZ: - for(int k=0;k<0x10000;k++) + for(int k = 0; k < 0x10000; k++) { - float XYZ[3] = {k/(float)0x10000, k/(float)0x10000, k/(float)0x10000}; - float Lab[3] = {0.0}; + float XYZ[3] = { k / (float)0x10000, k / (float)0x10000, k / (float)0x10000 }; + float Lab[3] = { 0.0 }; dt_XYZ_to_Lab(XYZ, Lab); - Lab[0] = d->table[ch_L][CLAMP((int)(Lab[0]/100.0f * 0x10000), 0, 0xffff)]; + Lab[0] = d->table[ch_L][CLAMP((int)(Lab[0] / 100.0f * 0x10000), 0, 0xffff)]; dt_Lab_to_XYZ(Lab, XYZ); d->table[ch_L][k] = XYZ[1]; // now mapping Y_in to Y_out } @@ -538,12 +536,12 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix else if(p->tonecurve_autoscale_ab == s_scale_automatic_rgb) { // derive curve for rgb: - for(int k=0;k<0x10000;k++) + for(int k = 0; k < 0x10000; k++) { - float rgb[3] = {k/(float)0x10000, k/(float)0x10000, k/(float)0x10000}; - float Lab[3] = {0.0}; + float rgb[3] = { k / (float)0x10000, k / (float)0x10000, k / (float)0x10000 }; + float Lab[3] = { 0.0 }; dt_prophotorgb_to_Lab(rgb, Lab); - Lab[0] = d->table[ch_L][CLAMP((int)(Lab[0]/100.0f * 0x10000), 0, 0xffff)]; + Lab[0] = d->table[ch_L][CLAMP((int)(Lab[0] / 100.0f * 0x10000), 0, 0xffff)]; dt_Lab_to_prophotorgb(Lab, rgb); d->table[ch_L][k] = rgb[1]; // now mapping G_in to G_out } @@ -648,14 +646,13 @@ void init(dt_iop_module_t *module) module->default_params = calloc(1, sizeof(dt_iop_tonecurve_params_t)); module->default_enabled = 0; module->request_histogram |= (DT_REQUEST_ON); - module->priority = 676; // module order created by iop_dependencies.py, do not edit! + module->priority = 681; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_tonecurve_params_t); module->gui_data = NULL; dt_iop_tonecurve_params_t tmp = (dt_iop_tonecurve_params_t){ { { // three curves (L, a, b) with a number of nodes { 0.0, 0.0 }, - { 1.0, 1.0 } - }, + { 1.0, 1.0 } }, { { 0.0, 0.0 }, { 0.5, 0.5 }, { 1.0, 1.0 } }, { { 0.0, 0.0 }, { 0.5, 0.5 }, { 1.0, 1.0 } } }, { 2, 3, 3 }, // number of nodes per curve @@ -911,18 +908,21 @@ void gui_init(struct dt_iop_module_t *self) // tabs c->channel_tabs = GTK_NOTEBOOK(gtk_notebook_new()); - gtk_notebook_append_page(GTK_NOTEBOOK(c->channel_tabs), - GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)), gtk_label_new(_(" L "))); - gtk_widget_set_tooltip_text(gtk_notebook_get_tab_label(c->channel_tabs, gtk_notebook_get_nth_page(c->channel_tabs, -1)), - _("tonecurve for L channel")); - gtk_notebook_append_page(GTK_NOTEBOOK(c->channel_tabs), - GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)), gtk_label_new(_(" a "))); - gtk_widget_set_tooltip_text(gtk_notebook_get_tab_label(c->channel_tabs, gtk_notebook_get_nth_page(c->channel_tabs, -1)), - _("tonecurve for a channel")); - gtk_notebook_append_page(GTK_NOTEBOOK(c->channel_tabs), - GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)), gtk_label_new(_(" b "))); - gtk_widget_set_tooltip_text(gtk_notebook_get_tab_label(c->channel_tabs, gtk_notebook_get_nth_page(c->channel_tabs, -1)), - _("tonecurve for b channel")); + gtk_notebook_append_page(GTK_NOTEBOOK(c->channel_tabs), GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)), + gtk_label_new(_(" L "))); + gtk_widget_set_tooltip_text( + gtk_notebook_get_tab_label(c->channel_tabs, gtk_notebook_get_nth_page(c->channel_tabs, -1)), + _("tonecurve for L channel")); + gtk_notebook_append_page(GTK_NOTEBOOK(c->channel_tabs), GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)), + gtk_label_new(_(" a "))); + gtk_widget_set_tooltip_text( + gtk_notebook_get_tab_label(c->channel_tabs, gtk_notebook_get_nth_page(c->channel_tabs, -1)), + _("tonecurve for a channel")); + gtk_notebook_append_page(GTK_NOTEBOOK(c->channel_tabs), GTK_WIDGET(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0)), + gtk_label_new(_(" b "))); + gtk_widget_set_tooltip_text( + gtk_notebook_get_tab_label(c->channel_tabs, gtk_notebook_get_nth_page(c->channel_tabs, -1)), + _("tonecurve for b channel")); gtk_widget_show_all(GTK_WIDGET(gtk_notebook_get_nth_page(c->channel_tabs, c->channel))); gtk_notebook_set_current_page(GTK_NOTEBOOK(c->channel_tabs), c->channel); @@ -947,8 +947,8 @@ void gui_init(struct dt_iop_module_t *self) gtk_widget_add_events(GTK_WIDGET(c->area), GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK - | GDK_SMOOTH_SCROLL_MASK | GDK_KEY_PRESS_MASK); + | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK + | GDK_KEY_PRESS_MASK); gtk_widget_set_can_focus(GTK_WIDGET(c->area), TRUE); g_signal_connect(G_OBJECT(c->area), "draw", G_CALLBACK(dt_iop_tonecurve_draw), self); g_signal_connect(G_OBJECT(c->area), "button-press-event", G_CALLBACK(dt_iop_tonecurve_button_press), self); @@ -1018,11 +1018,9 @@ static gboolean dt_iop_tonecurve_draw(GtkWidget *widget, cairo_t *crf, gpointer dt_iop_tonecurve_params_t *p = (dt_iop_tonecurve_params_t *)self->params; dt_develop_t *dev = darktable.develop; - const float color_labels_left[3][3] - = { { 0.3f, 0.3f, 0.3f }, { 0.0f, 0.34f, 0.27f }, { 0.0f, 0.27f, 0.58f } }; + const float color_labels_left[3][3] = { { 0.3f, 0.3f, 0.3f }, { 0.0f, 0.34f, 0.27f }, { 0.0f, 0.27f, 0.58f } }; - const float color_labels_right[3][3] - = { { 0.3f, 0.3f, 0.3f }, { 0.53f, 0.08f, 0.28f }, { 0.81f, 0.66f, 0.0f } }; + const float color_labels_right[3][3] = { { 0.3f, 0.3f, 0.3f }, { 0.53f, 0.08f, 0.28f }, { 0.81f, 0.66f, 0.0f } }; int ch = c->channel; int nodes = p->tonecurve_nodes[ch]; @@ -1201,7 +1199,7 @@ static gboolean dt_iop_tonecurve_draw(GtkWidget *widget, cairo_t *crf, gpointer snprintf(text, sizeof(text), "100.00 / 100.00 ( +100.00)"); pango_layout_set_text(layout, text, -1); pango_layout_get_pixel_extents(layout, &ink, NULL); - pango_font_description_set_absolute_size(desc, width*1.0/ink.width * PANGO_SCALE); + pango_font_description_set_absolute_size(desc, width * 1.0 / ink.width * PANGO_SCALE); pango_layout_set_font_description(layout, desc); cairo_set_source_rgba(cr, 0.7, 0.5, 0.5, 0.33); @@ -1243,7 +1241,7 @@ static gboolean dt_iop_tonecurve_draw(GtkWidget *widget, cairo_t *crf, gpointer snprintf(text, sizeof(text), "100.00 / 100.00 ( +100.00)"); pango_layout_set_text(layout, text, -1); pango_layout_get_pixel_extents(layout, &ink, NULL); - pango_font_description_set_absolute_size(desc, width*1.0/ink.width * PANGO_SCALE); + pango_font_description_set_absolute_size(desc, width * 1.0 / ink.width * PANGO_SCALE); pango_layout_set_font_description(layout, desc); const float min_scale_value = ch == ch_L ? 0.0f : -128.0f; @@ -1265,8 +1263,8 @@ static gboolean dt_iop_tonecurve_draw(GtkWidget *widget, cairo_t *crf, gpointer // enlarge selected node cairo_set_source_rgb(cr, .9, .9, .9); - cairo_arc(cr, tonecurve[c->selected].x * width, -tonecurve[c->selected].y * height, DT_PIXEL_APPLY_DPI(4), - 0, 2. * M_PI); + cairo_arc(cr, tonecurve[c->selected].x * width, -tonecurve[c->selected].y * height, DT_PIXEL_APPLY_DPI(4), 0, + 2. * M_PI); cairo_stroke(cr); } @@ -1378,8 +1376,7 @@ static gboolean dt_iop_tonecurve_motion_notify(GtkWidget *widget, GdkEventMotion int nearest = -1; for(int k = 0; k < nodes; k++) { - float dist = (my - tonecurve[k].y) * (my - tonecurve[k].y) - + (mx - tonecurve[k].x) * (mx - tonecurve[k].x); + float dist = (my - tonecurve[k].y) * (my - tonecurve[k].y) + (mx - tonecurve[k].x) * (mx - tonecurve[k].x); if(dist < min) { min = dist; @@ -1439,8 +1436,8 @@ static gboolean dt_iop_tonecurve_button_press(GtkWidget *widget, GdkEventButton if(selected == -1) selected = nodes; // > 0 -> check distance to left neighbour // < nodes -> check distance to right neighbour - if(!((selected > 0 && mx - tonecurve[selected - 1].x <= 0.025) || - (selected < nodes && tonecurve[selected].x - mx <= 0.025))) + if(!((selected > 0 && mx - tonecurve[selected - 1].x <= 0.025) + || (selected < nodes && tonecurve[selected].x - mx <= 0.025))) { // evaluate the curve at the current x position const float y = dt_draw_curve_calc_value(c->minmax_curve[ch], mx); diff --git a/src/iop/tonemap.cc b/src/iop/tonemap.cc index 47d10822f9b3..d7f4cebdf467 100644 --- a/src/iop/tonemap.cc +++ b/src/iop/tonemap.cc @@ -266,7 +266,7 @@ void init(dt_iop_module_t *module) module->params = (dt_iop_params_t *)malloc(sizeof(dt_iop_tonemapping_params_t)); module->default_params = (dt_iop_params_t *)malloc(sizeof(dt_iop_tonemapping_params_t)); module->default_enabled = 0; - module->priority = 147; // module order created by iop_dependencies.py, do not edit! + module->priority = 159; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_tonemapping_params_t); module->gui_data = NULL; } diff --git a/src/iop/useless.c b/src/iop/useless.c index fdd77106ec8d..bc8fd5ceb2e8 100644 --- a/src/iop/useless.c +++ b/src/iop/useless.c @@ -108,7 +108,7 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const { float *in = ((float *)i) + (size_t)ch * roi_in->width - * j; // make sure to address input, output and temp buffers with size_t as we want to also + * j; // make sure to address input, output and temp buffers with size_t as we want to also float *out = ((float *)o) + (size_t)ch * roi_out->width * j; // correctly handle huge images for(int i = 0; i < roi_out->width; i++) { diff --git a/src/iop/velvia.c b/src/iop/velvia.c index 56e74f984a58..91399e955a86 100644 --- a/src/iop/velvia.c +++ b/src/iop/velvia.c @@ -110,8 +110,8 @@ void connect_key_accels(dt_iop_module_t *self) } #endif -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 1 && new_version == 2) { @@ -165,7 +165,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const } } - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #if defined(__SSE__) @@ -199,7 +200,7 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c float pweight = CLAMPS(((1.0f - (1.5f * psat)) + ((1.0f + (fabsf(plum - 0.5f) * 2.0f)) * (1.0f - data->bias))) - / (1.0f + (1.0f - data->bias)), + / (1.0f + (1.0f - data->bias)), 0.0f, 1.0f); // The weight of pixel float saturation = strength * pweight; // So lets calculate the final affection of filter on pixel @@ -209,15 +210,14 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c const __m128 min_m = _mm_set1_ps(0.0f); const __m128 max_m = _mm_set1_ps(1.0f); - const __m128 inp_shuffled - = _mm_mul_ps(_mm_add_ps(_mm_shuffle_ps(inp_m, inp_m, _MM_SHUFFLE(3, 0, 2, 1)), - _mm_shuffle_ps(inp_m, inp_m, _MM_SHUFFLE(3, 1, 0, 2))), - _mm_set1_ps(0.5f)); + const __m128 inp_shuffled = _mm_mul_ps(_mm_add_ps(_mm_shuffle_ps(inp_m, inp_m, _MM_SHUFFLE(3, 0, 2, 1)), + _mm_shuffle_ps(inp_m, inp_m, _MM_SHUFFLE(3, 1, 0, 2))), + _mm_set1_ps(0.5f)); _mm_stream_ps( - outp, _mm_min_ps( - max_m, - _mm_max_ps(min_m, _mm_add_ps(inp_m, _mm_mul_ps(boost, _mm_sub_ps(inp_m, inp_shuffled)))))); + outp, + _mm_min_ps(max_m, + _mm_max_ps(min_m, _mm_add_ps(inp_m, _mm_mul_ps(boost, _mm_sub_ps(inp_m, inp_shuffled)))))); // equivalent to: /* @@ -229,7 +229,8 @@ void process_sse2(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, c } _mm_sfence(); - if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); + if(piece->pipe->mask_display & DT_DEV_PIXELPIPE_DISPLAY_MASK) + dt_iop_alpha_copy(ivoid, ovoid, roi_out->width, roi_out->height); } #endif @@ -281,8 +282,7 @@ int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_m void init_global(dt_iop_module_so_t *module) { const int program = 8; // extended.cl, from programs.conf - dt_iop_velvia_global_data_t *gd - = (dt_iop_velvia_global_data_t *)malloc(sizeof(dt_iop_velvia_global_data_t)); + dt_iop_velvia_global_data_t *gd = (dt_iop_velvia_global_data_t *)malloc(sizeof(dt_iop_velvia_global_data_t)); module->data = gd; gd->kernel_velvia = dt_opencl_create_kernel(program, "velvia"); } @@ -350,7 +350,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_velvia_params_t)); module->default_params = calloc(1, sizeof(dt_iop_velvia_params_t)); module->default_enabled = 0; - module->priority = 882; // module order created by iop_dependencies.py, do not edit! + module->priority = 884; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_velvia_params_t); module->gui_data = NULL; dt_iop_velvia_params_t tmp = (dt_iop_velvia_params_t){ 25, 1.0 }; diff --git a/src/iop/vibrance.c b/src/iop/vibrance.c index a78ef4ff7ea4..b7c6454587f2 100644 --- a/src/iop/vibrance.c +++ b/src/iop/vibrance.c @@ -214,7 +214,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_vibrance_params_t)); module->default_params = calloc(1, sizeof(dt_iop_vibrance_params_t)); module->default_enabled = 0; - module->priority = 426; // module order created by iop_dependencies.py, do not edit! + module->priority = 434; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_vibrance_params_t); module->gui_data = NULL; dt_iop_vibrance_params_t tmp = (dt_iop_vibrance_params_t){ 25 }; diff --git a/src/iop/vignette.c b/src/iop/vignette.c index 8711292758b7..0a1de302cef1 100644 --- a/src/iop/vignette.c +++ b/src/iop/vignette.c @@ -191,8 +191,8 @@ void connect_key_accels(dt_iop_module_t *self) dt_accel_connect_slider_iop(self, "dithering", GTK_WIDGET(g->dithering)); } -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 1 && new_version == 4) { @@ -364,8 +364,8 @@ static void draw_overlay(cairo_t *cr, float x, float y, float fx, float fy, int // FIXME: For portrait images the overlay is a bit off. The coordinates in mouse_moved seem to be ok though. // WTF? -void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, int32_t height, - int32_t pointerx, int32_t pointery) +void gui_post_expose(struct dt_iop_module_t *self, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, + int32_t pointery) { dt_develop_t *dev = self->dev; // dt_iop_vignette_gui_data_t *g = (dt_iop_vignette_gui_data_t *)self->gui_data; @@ -778,8 +778,7 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const if(weight > 0) { // Then apply falloff vignette - float falloff = (data->brightness < 0) ? (1.0 + (weight * data->brightness)) - : (weight * data->brightness); + float falloff = (data->brightness < 0) ? (1.0 + (weight * data->brightness)) : (weight * data->brightness); col0 = data->brightness < 0 ? col0 * falloff + dith : col0 + falloff + dith; col1 = data->brightness < 0 ? col1 * falloff + dith : col1 + falloff + dith; col2 = data->brightness < 0 ? col2 * falloff + dith : col2 + falloff + dith; @@ -1100,7 +1099,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_vignette_params_t)); module->default_params = calloc(1, sizeof(dt_iop_vignette_params_t)); module->default_enabled = 0; - module->priority = 852; // module order created by iop_dependencies.py, do not edit! + module->priority = 855; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_vignette_params_t); module->gui_data = NULL; dt_iop_vignette_params_t tmp @@ -1178,7 +1177,8 @@ void gui_init(struct dt_iop_module_t *self) gtk_widget_set_tooltip_text(g->center_y, _("vertical offset of center of the effect")); gtk_widget_set_tooltip_text(g->shape, _("shape factor\n0 produces a rectangle\n1 produces a circle or ellipse\n" "2 produces a diamond")); - gtk_widget_set_tooltip_text(GTK_WIDGET(g->autoratio), _("enable to have the ratio automatically follow the image size")); + gtk_widget_set_tooltip_text(GTK_WIDGET(g->autoratio), + _("enable to have the ratio automatically follow the image size")); gtk_widget_set_tooltip_text(g->whratio, _("width-to-height ratio")); gtk_widget_set_tooltip_text(g->dithering, _("add some level of random noise to prevent banding")); diff --git a/src/iop/watermark.c b/src/iop/watermark.c index fd2312874a7f..709d00a4f6e7 100644 --- a/src/iop/watermark.c +++ b/src/iop/watermark.c @@ -95,20 +95,20 @@ typedef struct dt_iop_watermark_data_t typedef struct dt_iop_watermark_gui_data_t { - GtkWidget *watermarks; // watermark - GList *watermarks_filenames; // the actual filenames. the dropdown lacks file extensions - GtkWidget *refresh; // refresh watermarks... - GtkWidget *align[9]; // Alignment buttons - GtkWidget *opacity, *scale, *x_offset, *y_offset; // opacity, scale, xoffs, yoffs - GtkWidget *sizeto; // relative size to + GtkWidget *watermarks; // watermark + GList *watermarks_filenames; // the actual filenames. the dropdown lacks file extensions + GtkWidget *refresh; // refresh watermarks... + GtkWidget *align[9]; // Alignment buttons + GtkWidget *opacity, *scale, *x_offset, *y_offset; // opacity, scale, xoffs, yoffs + GtkWidget *sizeto; // relative size to GtkWidget *rotate; GtkWidget *text; GtkWidget *colorpick; GtkWidget *fontsel; } dt_iop_watermark_gui_data_t; -int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, - void *new_params, const int new_version) +int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, + const int new_version) { if(old_version == 1 && new_version == 4) { @@ -300,8 +300,7 @@ static gchar *_string_substitute(gchar *string, const gchar *search, const gchar return result; } -static gchar *_watermark_get_svgdoc(dt_iop_module_t *self, dt_iop_watermark_data_t *data, - const dt_image_t *image) +static gchar *_watermark_get_svgdoc(dt_iop_module_t *self, dt_iop_watermark_data_t *data, const dt_image_t *image) { gsize length; @@ -328,8 +327,8 @@ static gchar *_watermark_get_svgdoc(dt_iop_module_t *self, dt_iop_watermark_data // EXIF datetime struct tm tt_exif = { 0 }; - if(sscanf(image->exif_datetime_taken, "%d:%d:%d %d:%d:%d", &tt_exif.tm_year, &tt_exif.tm_mon, - &tt_exif.tm_mday, &tt_exif.tm_hour, &tt_exif.tm_min, &tt_exif.tm_sec) == 6) + if(sscanf(image->exif_datetime_taken, "%d:%d:%d %d:%d:%d", &tt_exif.tm_year, &tt_exif.tm_mon, &tt_exif.tm_mday, + &tt_exif.tm_hour, &tt_exif.tm_min, &tt_exif.tm_sec) == 6) { tt_exif.tm_year -= 1900; tt_exif.tm_mon--; @@ -361,7 +360,7 @@ static gchar *_watermark_get_svgdoc(dt_iop_module_t *self, dt_iop_watermark_data // Simple text from watermark module gchar buffer[1024]; - if (data->font[0] && data->text[0]) + if(data->font[0] && data->text[0]) { g_snprintf(buffer, sizeof(buffer), "%s", data->text); svgdoc = _string_substitute(svgdata, "$(WATERMARK_TEXT)", buffer); @@ -383,17 +382,17 @@ static gchar *_watermark_get_svgdoc(dt_iop_module_t *self, dt_iop_watermark_data svgdata = svgdoc; } - switch (font_style) + switch(font_style) { - case PANGO_STYLE_OBLIQUE: - g_strlcpy(buffer, "oblique", sizeof(buffer)); - break; - case PANGO_STYLE_ITALIC: - g_strlcpy(buffer, "italic", sizeof(buffer)); - break; - default: - g_strlcpy(buffer, "normal", sizeof(buffer)); - break; + case PANGO_STYLE_OBLIQUE: + g_strlcpy(buffer, "oblique", sizeof(buffer)); + break; + case PANGO_STYLE_ITALIC: + g_strlcpy(buffer, "italic", sizeof(buffer)); + break; + default: + g_strlcpy(buffer, "normal", sizeof(buffer)); + break; } svgdoc = _string_substitute(svgdata, "$(WATERMARK_FONT_STYLE)", buffer); if(svgdoc != svgdata) @@ -768,7 +767,6 @@ static gchar *_watermark_get_svgdoc(dt_iop_module_t *self, dt_iop_watermark_data g_free(longitude); g_free(elevation); g_free(location); - } return svgdoc; } @@ -795,8 +793,8 @@ void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const /* create cairo memory surface */ guint8 *image = (guint8 *)g_malloc0_n(roi_out->height, stride); - cairo_surface_t *surface = cairo_image_surface_create_for_data(image, CAIRO_FORMAT_ARGB32, roi_out->width, - roi_out->height, stride); + cairo_surface_t *surface + = cairo_image_surface_create_for_data(image, CAIRO_FORMAT_ARGB32, roi_out->width, roi_out->height, stride); if(cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) { // fprintf(stderr,"Cairo surface error: %s\n",cairo_status_to_string(cairo_surface_status(surface))); @@ -1014,8 +1012,7 @@ static void load_watermarks(const char *basedir, dt_iop_watermark_gui_data_t *g) if(dir) { const gchar *d_name; - while((d_name = g_dir_read_name(dir))) - files = g_list_append(files, g_strdup(d_name)); + while((d_name = g_dir_read_name(dir))) files = g_list_append(files, g_strdup(d_name)); g_dir_close(dir); } @@ -1211,12 +1208,11 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix snprintf(d->filename, sizeof(d->filename), "%s", p->filename); memset(d->text, 0, sizeof(d->text)); snprintf(d->text, sizeof(d->text), "%s", p->text); - for (int k=0; k<3; k++) - d->color[k] = p->color[k]; + for(int k = 0; k < 3; k++) d->color[k] = p->color[k]; memset(d->font, 0, sizeof(d->font)); snprintf(d->font, sizeof(d->font), "%s", p->font); -// fprintf(stderr,"Commit params: %s...\n",d->filename); + // fprintf(stderr,"Commit params: %s...\n",d->filename); } void init_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece) @@ -1261,12 +1257,21 @@ void init(dt_iop_module_t *module) module->params_size = sizeof(dt_iop_watermark_params_t); module->default_params = calloc(1, sizeof(dt_iop_watermark_params_t)); module->default_enabled = 0; - module->priority = 970; // module order created by iop_dependencies.py, do not edit! + module->priority = 971; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_watermark_params_t); module->gui_data = NULL; - dt_iop_watermark_params_t tmp = (dt_iop_watermark_params_t){ - 100.0, 100.0, 0.0, 0.0, 4, 0.0, DT_SCALE_IMAGE, { "darktable.svg" }, { "" }, {0.0, 0.0, 0.0}, {"DejaVu Sans 10"} - }; // opacity,scale,xoffs,yoffs,alignment + dt_iop_watermark_params_t tmp + = (dt_iop_watermark_params_t){ 100.0, + 100.0, + 0.0, + 0.0, + 4, + 0.0, + DT_SCALE_IMAGE, + { "darktable.svg" }, + { "" }, + { 0.0, 0.0, 0.0 }, + { "DejaVu Sans 10" } }; // opacity,scale,xoffs,yoffs,alignment memcpy(module->params, &tmp, sizeof(dt_iop_watermark_params_t)); memcpy(module->default_params, &tmp, sizeof(dt_iop_watermark_params_t)); } @@ -1340,13 +1345,13 @@ void gui_init(struct dt_iop_module_t *self) // Text font label = dtgtk_reset_label_new(_("font"), self, &p->font, sizeof(p->font)); str = dt_conf_get_string("plugins/darkroom/watermark/font"); - g->fontsel = gtk_font_button_new_with_font(str==NULL?"DejaVu Sans 10":str); + g->fontsel = gtk_font_button_new_with_font(str == NULL ? "DejaVu Sans 10" : str); GList *childs = gtk_container_get_children(GTK_CONTAINER(gtk_bin_get_child(GTK_BIN(g->fontsel)))); gtk_label_set_ellipsize(GTK_LABEL(childs->data), PANGO_ELLIPSIZE_MIDDLE); g_list_free(childs); gtk_widget_set_tooltip_text(g->fontsel, _("text font, tags:\n$(WATERMARK_FONT_FAMILY)\n" "$(WATERMARK_FONT_STYLE)\n$(WATERMARK_FONT_WEIGHT)")); - gtk_font_button_set_show_size (GTK_FONT_BUTTON(g->fontsel), FALSE); + gtk_font_button_set_show_size(GTK_FONT_BUTTON(g->fontsel), FALSE); g_free(str); gtk_grid_attach(GTK_GRID(self->widget), label, 0, line++, 1, 1); gtk_grid_attach_next_to(GTK_GRID(self->widget), g->fontsel, label, GTK_POS_RIGHT, 2, 1); @@ -1388,7 +1393,7 @@ void gui_init(struct dt_iop_module_t *self) { g->align[i] = dtgtk_togglebutton_new(dtgtk_cairo_paint_alignment, CPF_STYLE_FLAT | (CPF_SPECIAL_FLAG << i)); gtk_widget_set_size_request(GTK_WIDGET(g->align[i]), DT_PIXEL_APPLY_DPI(16), DT_PIXEL_APPLY_DPI(16)); - gtk_grid_attach(GTK_GRID(bat), GTK_WIDGET(g->align[i]), i%3, i/3, 1, 1); + gtk_grid_attach(GTK_GRID(bat), GTK_WIDGET(g->align[i]), i % 3, i / 3, 1, 1); g_signal_connect(G_OBJECT(g->align[i]), "toggled", G_CALLBACK(alignment_callback), self); } gtk_grid_attach(GTK_GRID(self->widget), label, 0, line++, 1, 1); diff --git a/src/iop/zonesystem.c b/src/iop/zonesystem.c index 8b4704ee019a..8f715fba8329 100644 --- a/src/iop/zonesystem.c +++ b/src/iop/zonesystem.c @@ -192,8 +192,8 @@ static void process_common_setup(struct dt_iop_module_t *self, dt_dev_pixelpipe_ } static void process_common_cleanup(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, - const void *const ivoid, void *const ovoid, - const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out) + const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, + const dt_iop_roi_t *const roi_out) { dt_iop_zonesystem_data_t *d = (dt_iop_zonesystem_data_t *)piece->data; dt_iop_zonesystem_gui_data_t *g = (dt_iop_zonesystem_gui_data_t *)self->gui_data; @@ -428,8 +428,7 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix // precompute scale and offset for(int k = 0; k < size - 1; k++) d->zonemap_scale[k] = (zonemap[k + 1] - zonemap[k]) * (size - 1); - for(int k = 0; k < size - 1; k++) - d->zonemap_offset[k] = 100.0f * ((k + 1) * zonemap[k] - k * zonemap[k + 1]); + for(int k = 0; k < size - 1; k++) d->zonemap_offset[k] = 100.0f * ((k + 1) * zonemap[k] - k * zonemap[k + 1]); } void init_pipe(struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece) @@ -457,7 +456,7 @@ void init(dt_iop_module_t *module) module->params = calloc(1, sizeof(dt_iop_zonesystem_params_t)); module->default_params = calloc(1, sizeof(dt_iop_zonesystem_params_t)); module->default_enabled = 0; - module->priority = 661; // module order created by iop_dependencies.py, do not edit! + module->priority = 666; // module order created by iop_dependencies.py, do not edit! module->params_size = sizeof(dt_iop_zonesystem_params_t); module->gui_data = NULL; dt_iop_zonesystem_params_t tmp = (dt_iop_zonesystem_params_t){ @@ -483,12 +482,10 @@ static gboolean dt_iop_zonesystem_bar_motion_notify(GtkWidget *widget, GdkEventM dt_iop_module_t *self); static gboolean dt_iop_zonesystem_bar_leave_notify(GtkWidget *widget, GdkEventCrossing *event, dt_iop_module_t *self); -static gboolean dt_iop_zonesystem_bar_button_press(GtkWidget *widget, GdkEventButton *event, - dt_iop_module_t *self); +static gboolean dt_iop_zonesystem_bar_button_press(GtkWidget *widget, GdkEventButton *event, dt_iop_module_t *self); static gboolean dt_iop_zonesystem_bar_button_release(GtkWidget *widget, GdkEventButton *event, dt_iop_module_t *self); -static gboolean dt_iop_zonesystem_bar_scrolled(GtkWidget *widget, GdkEventScroll *event, - dt_iop_module_t *self); +static gboolean dt_iop_zonesystem_bar_scrolled(GtkWidget *widget, GdkEventScroll *event, dt_iop_module_t *self); static void size_allocate_callback(GtkWidget *widget, GtkAllocation *allocation, gpointer user_data) @@ -533,8 +530,8 @@ void gui_init(struct dt_iop_module_t *self) g_signal_connect(G_OBJECT(g->preview), "size-allocate", G_CALLBACK(size_allocate_callback), self); g_signal_connect(G_OBJECT(g->preview), "draw", G_CALLBACK(dt_iop_zonesystem_preview_draw), self); gtk_widget_add_events(GTK_WIDGET(g->preview), GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_LEAVE_NOTIFY_MASK); + | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + | GDK_LEAVE_NOTIFY_MASK); /* create the zonesystem bar widget */ g->zones = gtk_drawing_area_new(); @@ -544,17 +541,15 @@ void gui_init(struct dt_iop_module_t *self) g_signal_connect(G_OBJECT(g->zones), "draw", G_CALLBACK(dt_iop_zonesystem_bar_draw), self); g_signal_connect(G_OBJECT(g->zones), "motion-notify-event", G_CALLBACK(dt_iop_zonesystem_bar_motion_notify), self); - g_signal_connect(G_OBJECT(g->zones), "leave-notify-event", G_CALLBACK(dt_iop_zonesystem_bar_leave_notify), - self); - g_signal_connect(G_OBJECT(g->zones), "button-press-event", G_CALLBACK(dt_iop_zonesystem_bar_button_press), + g_signal_connect(G_OBJECT(g->zones), "leave-notify-event", G_CALLBACK(dt_iop_zonesystem_bar_leave_notify), self); + g_signal_connect(G_OBJECT(g->zones), "button-press-event", G_CALLBACK(dt_iop_zonesystem_bar_button_press), self); + g_signal_connect(G_OBJECT(g->zones), "button-release-event", G_CALLBACK(dt_iop_zonesystem_bar_button_release), self); - g_signal_connect(G_OBJECT(g->zones), "button-release-event", - G_CALLBACK(dt_iop_zonesystem_bar_button_release), self); g_signal_connect(G_OBJECT(g->zones), "scroll-event", G_CALLBACK(dt_iop_zonesystem_bar_scrolled), self); gtk_widget_add_events(GTK_WIDGET(g->zones), GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK - | GDK_SMOOTH_SCROLL_MASK); + | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK + | GDK_SMOOTH_SCROLL_MASK); gtk_widget_set_size_request(g->zones, -1, DT_PIXEL_APPLY_DPI(40)); gtk_box_pack_start(GTK_BOX(self->widget), g->preview, TRUE, TRUE, 0); @@ -652,11 +647,11 @@ static gboolean dt_iop_zonesystem_bar_draw(GtkWidget *widget, cairo_t *crf, dt_i { float nzw = zonemap[k + 1] - zonemap[k]; float pzw = zonemap[k] - zonemap[k - 1]; - if((((g->mouse_x / width) > (zonemap[k] - (pzw / 2.0))) - && ((g->mouse_x / width) < (zonemap[k] + (nzw / 2.0)))) || p->zone[k] != -1) + if((((g->mouse_x / width) > (zonemap[k] - (pzw / 2.0))) && ((g->mouse_x / width) < (zonemap[k] + (nzw / 2.0)))) + || p->zone[k] != -1) { - gboolean is_under_mouse = ((width * zonemap[k]) - arrw * .5f < g->mouse_x - && (width * zonemap[k]) + arrw * .5f > g->mouse_x); + gboolean is_under_mouse + = ((width * zonemap[k]) - arrw * .5f < g->mouse_x && (width * zonemap[k]) + arrw * .5f > g->mouse_x); cairo_move_to(cr, inset + (width * zonemap[k]), height + (2 * inset) - 1); cairo_rel_line_to(cr, -arrw * .5f, 0); @@ -681,8 +676,7 @@ static gboolean dt_iop_zonesystem_bar_draw(GtkWidget *widget, cairo_t *crf, dt_i return TRUE; } -static gboolean dt_iop_zonesystem_bar_button_press(GtkWidget *widget, GdkEventButton *event, - dt_iop_module_t *self) +static gboolean dt_iop_zonesystem_bar_button_press(GtkWidget *widget, GdkEventButton *event, dt_iop_module_t *self) { dt_iop_zonesystem_params_t *p = (dt_iop_zonesystem_params_t *)self->params; dt_iop_zonesystem_gui_data_t *g = (dt_iop_zonesystem_gui_data_t *)self->gui_data; @@ -758,8 +752,7 @@ static gboolean dt_iop_zonesystem_bar_leave_notify(GtkWidget *widget, GdkEventCr return TRUE; } -static gboolean dt_iop_zonesystem_bar_motion_notify(GtkWidget *widget, GdkEventMotion *event, - dt_iop_module_t *self) +static gboolean dt_iop_zonesystem_bar_motion_notify(GtkWidget *widget, GdkEventMotion *event, dt_iop_module_t *self) { dt_iop_zonesystem_params_t *p = (dt_iop_zonesystem_params_t *)self->params; dt_iop_zonesystem_gui_data_t *g = (dt_iop_zonesystem_gui_data_t *)self->gui_data; @@ -778,8 +771,7 @@ static gboolean dt_iop_zonesystem_bar_motion_notify(GtkWidget *widget, GdkEventM if(g->is_dragging) { - if((g->mouse_x / width) > zonemap[g->current_zone - 1] - && (g->mouse_x / width) < zonemap[g->current_zone + 1]) + if((g->mouse_x / width) > zonemap[g->current_zone - 1] && (g->mouse_x / width) < zonemap[g->current_zone + 1]) { p->zone[g->current_zone] = (g->mouse_x / width); dt_dev_add_history_item(darktable.develop, self, TRUE); @@ -883,8 +875,7 @@ static gboolean dt_iop_zonesystem_preview_draw(GtkWidget *widget, cairo_t *crf, if(g->image) { GdkRGBA *color; - gtk_style_context_get(context, gtk_widget_get_state_flags(self->expander), "background-color", &color, - NULL); + gtk_style_context_get(context, gtk_widget_get_state_flags(self->expander), "background-color", &color, NULL); cairo_set_source_surface(cr, g->image, (width - g->image_width) * 0.5, (height - g->image_height) * 0.5); cairo_rectangle(cr, 0, 0, width, height); diff --git a/src/libs/backgroundjobs.c b/src/libs/backgroundjobs.c index 5fae91c4d980..8c4905767130 100644 --- a/src/libs/backgroundjobs.c +++ b/src/libs/backgroundjobs.c @@ -55,7 +55,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"*", NULL}; + static const char *v[] = { "*", NULL }; return v; } @@ -243,7 +243,8 @@ static gboolean _cancellable_gui_thread(gpointer user_data) GtkBox *hbox = GTK_BOX(params->instance->hbox); GtkWidget *button = dtgtk_button_new(dtgtk_cairo_paint_cancel, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); gtk_widget_set_size_request(button, DT_PIXEL_APPLY_DPI(17), DT_PIXEL_APPLY_DPI(17)); - g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(_lib_backgroundjobs_cancel_callback_new), params->progress); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(_lib_backgroundjobs_cancel_callback_new), + params->progress); gtk_box_pack_start(hbox, GTK_WIDGET(button), FALSE, FALSE, 0); gtk_widget_show_all(button); diff --git a/src/libs/camera.c b/src/libs/camera.c index 87f8262e9cc9..010438777e3d 100644 --- a/src/libs/camera.c +++ b/src/libs/camera.c @@ -52,9 +52,9 @@ typedef struct dt_lib_camera_t GtkWidget *timer, *count, *brackets, *steps; GtkWidget *button1; - int rows; // the number of row in the grid + int rows; // the number of row in the grid int prop_start; // the row of the grid above the first property - int prop_end; // the row of the grid where to insert new properties + int prop_end; // the row of the grid where to insert new properties GtkWidget *plabel, *pname; // propertylabel,widget GList *properties; // a list of dt_lib_camera_property_t @@ -80,7 +80,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"tethering", NULL}; + static const char *v[] = { "tethering", NULL }; return v; } @@ -138,18 +138,17 @@ static dt_lib_camera_property_t *_lib_property_add_new(dt_lib_camera_t *lib, con dt_bauhaus_widget_set_label(prop->values, NULL, label); g_object_ref_sink(prop->values); - prop->osd = DTGTK_TOGGLEBUTTON(dtgtk_togglebutton_new(dtgtk_cairo_paint_eye, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER)); + prop->osd = DTGTK_TOGGLEBUTTON( + dtgtk_togglebutton_new(dtgtk_cairo_paint_eye, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER)); g_object_ref_sink(prop->osd); gtk_widget_set_size_request(GTK_WIDGET(prop->osd), DT_PIXEL_APPLY_DPI(14), -1); gtk_widget_set_tooltip_text(GTK_WIDGET(prop->osd), _("toggle view property in center view")); do { dt_bauhaus_combobox_add(prop->values, g_dgettext("libgphoto2-2", value)); - if(!strcmp(current_value, g_dgettext("libgphoto2-2", value))) - dt_bauhaus_combobox_set(prop->values, i); + if(!strcmp(current_value, g_dgettext("libgphoto2-2", value))) dt_bauhaus_combobox_set(prop->values, i); i++; - } while((value = dt_camctl_camera_property_get_next_choice(darktable.camctl, NULL, propertyname)) - != NULL); + } while((value = dt_camctl_camera_property_get_next_choice(darktable.camctl, NULL, propertyname)) != NULL); lib->gui.properties = g_list_append(lib->gui.properties, prop); // Does dead lock!!! g_signal_connect(G_OBJECT(prop->values), "value-changed", G_CALLBACK(property_changed_callback), @@ -162,7 +161,7 @@ static dt_lib_camera_property_t *_lib_property_add_new(dt_lib_camera_t *lib, con static void _lib_property_free(gpointer data) { - dt_lib_camera_property_t * prop = (dt_lib_camera_property_t *)data; + dt_lib_camera_property_t *prop = (dt_lib_camera_property_t *)data; g_object_unref(prop->osd); g_object_unref(prop->values); free(prop->name); @@ -188,7 +187,7 @@ static void _camera_property_value_changed(const dt_camera_t *camera, const char int i = 0; for(const GList *iter = dt_bauhaus_combobox_get_labels(prop->values); iter; iter = g_list_next(iter), i++) { - if(!g_strcmp0((gchar*)iter->data, value)) + if(!g_strcmp0((gchar *)iter->data, value)) { dt_bauhaus_combobox_set(prop->values, i); return; @@ -198,8 +197,8 @@ static void _camera_property_value_changed(const dt_camera_t *camera, const char } /** Invoked when accesibility of a property is changed. */ -static void _camera_property_accessibility_changed(const dt_camera_t *camera, const char *name, - gboolean read_only, void *data) +static void _camera_property_accessibility_changed(const dt_camera_t *camera, const char *name, gboolean read_only, + void *data) { } @@ -333,8 +332,8 @@ static void _toggle_capture_mode_clicked(GtkWidget *widget, gpointer user_data) #define BAR_HEIGHT DT_PIXEL_APPLY_DPI(18) /* also change in views/tethering.c */ -static void _expose_info_bar(dt_lib_module_t *self, cairo_t *cr, int32_t width, int32_t height, - int32_t pointerx, int32_t pointery) +static void _expose_info_bar(dt_lib_module_t *self, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, + int32_t pointery) { dt_lib_camera_t *lib = (dt_lib_camera_t *)self->data; @@ -367,7 +366,8 @@ static void _expose_info_bar(dt_lib_module_t *self, cairo_t *cr, int32_t width, snprintf(battery, sizeof(battery), "%s: %s", _("battery"), battery_value ? battery_value : _("n/a")); pango_layout_set_text(layout, battery, -1); pango_layout_get_pixel_extents(layout, &ink, NULL); - cairo_move_to(cr, width - ink.width - DT_PIXEL_APPLY_DPI(5), DT_PIXEL_APPLY_DPI(1) + BAR_HEIGHT - ink.height / 2 - fontsize); + cairo_move_to(cr, width - ink.width - DT_PIXEL_APPLY_DPI(5), + DT_PIXEL_APPLY_DPI(1) + BAR_HEIGHT - ink.height / 2 - fontsize); pango_cairo_show_layout(cr, layout); // Let's cook up the middle part of infobar @@ -475,10 +475,14 @@ void gui_init(dt_lib_module_t *self) lib->gui.count = gtk_spin_button_new_with_range(1, 500, 1); lib->gui.brackets = gtk_spin_button_new_with_range(1, 5, 1); lib->gui.steps = gtk_spin_button_new_with_range(1, 9, 1); - gtk_grid_attach_next_to(GTK_GRID(self->widget), GTK_WIDGET(lib->gui.timer), GTK_WIDGET(timer_label), GTK_POS_RIGHT, 1, 1); - gtk_grid_attach_next_to(GTK_GRID(self->widget), GTK_WIDGET(lib->gui.count), GTK_WIDGET(count_label), GTK_POS_RIGHT, 1, 1); - gtk_grid_attach_next_to(GTK_GRID(self->widget), GTK_WIDGET(lib->gui.brackets), GTK_WIDGET(brackets_label), GTK_POS_RIGHT, 1, 1); - gtk_grid_attach_next_to(GTK_GRID(self->widget), GTK_WIDGET(lib->gui.steps), GTK_WIDGET(steps_label), GTK_POS_RIGHT, 1, 1); + gtk_grid_attach_next_to(GTK_GRID(self->widget), GTK_WIDGET(lib->gui.timer), GTK_WIDGET(timer_label), + GTK_POS_RIGHT, 1, 1); + gtk_grid_attach_next_to(GTK_GRID(self->widget), GTK_WIDGET(lib->gui.count), GTK_WIDGET(count_label), + GTK_POS_RIGHT, 1, 1); + gtk_grid_attach_next_to(GTK_GRID(self->widget), GTK_WIDGET(lib->gui.brackets), GTK_WIDGET(brackets_label), + GTK_POS_RIGHT, 1, 1); + gtk_grid_attach_next_to(GTK_GRID(self->widget), GTK_WIDGET(lib->gui.steps), GTK_WIDGET(steps_label), + GTK_POS_RIGHT, 1, 1); lib->gui.button1 = gtk_button_new_with_label(_("capture image(s)")); gtk_grid_attach(GTK_GRID(self->widget), GTK_WIDGET(lib->gui.button1), 0, lib->gui.rows++, 2, 1); @@ -486,15 +490,19 @@ void gui_init(dt_lib_module_t *self) gtk_widget_set_tooltip_text(GTK_WIDGET(lib->gui.toggle_timer), _("toggle delayed capture mode")); gtk_widget_set_tooltip_text(GTK_WIDGET(lib->gui.toggle_sequence), _("toggle sequenced capture mode")); gtk_widget_set_tooltip_text(GTK_WIDGET(lib->gui.toggle_bracket), _("toggle bracketed capture mode")); - gtk_widget_set_tooltip_text(GTK_WIDGET(lib->gui.timer), _("the count of seconds before actually doing a capture")); - gtk_widget_set_tooltip_text(GTK_WIDGET(lib->gui.count), - _("the amount of images to capture in a sequence,\nyou can use this in conjunction with " - "delayed mode to create stop-motion sequences.")); - gtk_widget_set_tooltip_text(GTK_WIDGET(lib->gui.brackets), - _("the amount of brackets on each side of centered shoot, amount of images = (brackets*2)+1.")); - gtk_widget_set_tooltip_text(GTK_WIDGET(lib->gui.steps), - _("the amount of steps per bracket, steps is camera configurable and usually 3 steps per " - "stop\nwith other words, 3 steps is 1EV exposure step between brackets.")); + gtk_widget_set_tooltip_text(GTK_WIDGET(lib->gui.timer), + _("the count of seconds before actually doing a capture")); + gtk_widget_set_tooltip_text( + GTK_WIDGET(lib->gui.count), + _("the amount of images to capture in a sequence,\nyou can use this in conjunction with " + "delayed mode to create stop-motion sequences.")); + gtk_widget_set_tooltip_text( + GTK_WIDGET(lib->gui.brackets), + _("the amount of brackets on each side of centered shoot, amount of images = (brackets*2)+1.")); + gtk_widget_set_tooltip_text( + GTK_WIDGET(lib->gui.steps), + _("the amount of steps per bracket, steps is camera configurable and usually 3 steps per " + "stop\nwith other words, 3 steps is 1EV exposure step between brackets.")); g_signal_connect(G_OBJECT(lib->gui.toggle_timer), "clicked", G_CALLBACK(_toggle_capture_mode_clicked), lib); g_signal_connect(G_OBJECT(lib->gui.toggle_sequence), "clicked", G_CALLBACK(_toggle_capture_mode_clicked), lib); @@ -516,7 +524,7 @@ void gui_init(dt_lib_module_t *self) label = dt_ui_section_label_new(_("properties")); gtk_grid_attach(GTK_GRID(self->widget), GTK_WIDGET(label), 0, lib->gui.rows++, 2, 1); - lib->gui.prop_start = lib->gui.rows -1; + lib->gui.prop_start = lib->gui.rows - 1; lib->gui.prop_end = lib->gui.rows; @@ -530,7 +538,8 @@ void gui_init(dt_lib_module_t *self) gtk_entry_set_width_chars(GTK_ENTRY(lib->gui.plabel), 0); dt_gui_key_accel_block_on_focus_connect(lib->gui.plabel); gtk_grid_attach(GTK_GRID(self->widget), GTK_WIDGET(label), 0, lib->gui.rows++, 1, 1); - gtk_grid_attach_next_to(GTK_GRID(self->widget), GTK_WIDGET(lib->gui.plabel), GTK_WIDGET(label), GTK_POS_RIGHT, 1, 1); + gtk_grid_attach_next_to(GTK_GRID(self->widget), GTK_WIDGET(lib->gui.plabel), GTK_WIDGET(label), GTK_POS_RIGHT, 1, + 1); hbox = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, DT_PIXEL_APPLY_DPI(5))); label = gtk_label_new(_("property")); @@ -550,8 +559,6 @@ void gui_init(dt_lib_module_t *self) g_signal_connect(G_OBJECT(widget), "clicked", G_CALLBACK(_add_property_button_clicked), lib); gtk_widget_show(widget); gtk_grid_attach(GTK_GRID(self->widget), GTK_WIDGET(widget), 0, lib->gui.rows++, 2, 1); - - } void gui_cleanup(dt_lib_module_t *self) @@ -565,13 +572,12 @@ void gui_cleanup(dt_lib_module_t *self) self->data = NULL; } -void view_enter(struct dt_lib_module_t *self,struct dt_view_t *old_view,struct dt_view_t *new_view) +void view_enter(struct dt_lib_module_t *self, struct dt_view_t *old_view, struct dt_view_t *new_view) { dt_lib_camera_t *lib = self->data; /* add all camera properties to the widget */ dt_lib_camera_property_t *prop; - if((prop = _lib_property_add_new(lib, _("program"), "expprogram")) != NULL) - _lib_property_add_to_gui(prop, lib); + if((prop = _lib_property_add_new(lib, _("program"), "expprogram")) != NULL) _lib_property_add_to_gui(prop, lib); if((prop = _lib_property_add_new(lib, _("focus mode"), "focusmode")) != NULL) _lib_property_add_to_gui(prop, lib); @@ -591,17 +597,14 @@ void view_enter(struct dt_lib_module_t *self,struct dt_view_t *old_view,struct d else if((prop = _lib_property_add_new(lib, _("shutterspeed"), "shutterspeed")) != NULL) // Canon, again _lib_property_add_to_gui(prop, lib); - if((prop = _lib_property_add_new(lib, _("ISO"), "iso")) != NULL) - _lib_property_add_to_gui(prop, lib); + if((prop = _lib_property_add_new(lib, _("ISO"), "iso")) != NULL) _lib_property_add_to_gui(prop, lib); - if((prop = _lib_property_add_new(lib, _("WB"), "whitebalance")) != NULL) - _lib_property_add_to_gui(prop, lib); + if((prop = _lib_property_add_new(lib, _("WB"), "whitebalance")) != NULL) _lib_property_add_to_gui(prop, lib); if((prop = _lib_property_add_new(lib, _("quality"), "imagequality")) != NULL) _lib_property_add_to_gui(prop, lib); - if((prop = _lib_property_add_new(lib, _("size"), "imagesize")) != NULL) - _lib_property_add_to_gui(prop, lib); + if((prop = _lib_property_add_new(lib, _("size"), "imagesize")) != NULL) _lib_property_add_to_gui(prop, lib); /* add user widgets */ GSList *options = dt_conf_all_string_entries("plugins/capture/tethering/properties"); @@ -636,7 +639,7 @@ void view_enter(struct dt_lib_module_t *self,struct dt_view_t *old_view,struct d // Get camera model name lib->data.camera_model = dt_camctl_camera_get_model(darktable.camctl, NULL); } -void view_leave(struct dt_lib_module_t *self,struct dt_view_t *old_view,struct dt_view_t *new_view) +void view_leave(struct dt_lib_module_t *self, struct dt_view_t *old_view, struct dt_view_t *new_view) { dt_lib_camera_t *lib = self->data; // remove listener from camera control.. @@ -645,13 +648,14 @@ void view_leave(struct dt_lib_module_t *self,struct dt_view_t *old_view,struct d gtk_widget_destroy(GTK_WIDGET(lib->gui.properties_menu)); lib->gui.properties_menu = NULL; // remove all properties - while(lib->gui.prop_end > lib->gui.prop_start +1) { - gtk_grid_remove_row(lib->gui.main_grid,lib->gui.prop_start +1); + while(lib->gui.prop_end > lib->gui.prop_start + 1) + { + gtk_grid_remove_row(lib->gui.main_grid, lib->gui.prop_start + 1); lib->gui.rows--; lib->gui.prop_end--; } // no need to free widgets, they are freed when the line of the grid is destroyed - g_list_free_full(lib->gui.properties,_lib_property_free); + g_list_free_full(lib->gui.properties, _lib_property_free); lib->gui.properties = NULL; } // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh diff --git a/src/libs/collect.c b/src/libs/collect.c index 0cfb952e24e3..fc5adc0eac89 100644 --- a/src/libs/collect.c +++ b/src/libs/collect.c @@ -71,9 +71,9 @@ typedef struct dt_lib_collect_t typedef struct dt_lib_collect_params_rule_t { - uint32_t item : 16; - uint32_t mode : 16; - char string[PARAM_STRING_SIZE]; + uint32_t item : 16; + uint32_t mode : 16; + char string[PARAM_STRING_SIZE]; } dt_lib_collect_params_rule_t; typedef struct dt_lib_collect_params_t @@ -105,7 +105,7 @@ typedef struct _image_t static void _lib_collect_gui_update(dt_lib_module_t *self); static void _lib_folders_update_collection(const gchar *filmroll); static void entry_insert_text(GtkWidget *entry, gchar *new_text, gint new_length, gpointer *position, - dt_lib_collect_rule_t *d); + dt_lib_collect_rule_t *d); static void entry_changed(GtkEntry *entry, dt_lib_collect_rule_t *dr); static void row_activated(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *col, dt_lib_collect_t *d); @@ -205,7 +205,7 @@ int set_params(dt_lib_module_t *self, const void *params, int size) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"lighttable", "map", "print", NULL}; + static const char *v[] = { "lighttable", "map", "print", NULL }; return v; } @@ -229,16 +229,15 @@ static void view_popup_menu_onSearchFilmroll(GtkWidget *menuitem, gpointer userd model = gtk_tree_view_get_model(treeview); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); - if (!gtk_tree_selection_get_selected(selection, &model, &iter)) - return; + if(!gtk_tree_selection_get_selected(selection, &model, &iter)) return; child = iter; gtk_tree_model_iter_parent(model, &iter, &child); gtk_tree_model_get(model, &child, DT_LIB_COLLECT_COL_PATH, &tree_path, -1); - filechooser = gtk_file_chooser_dialog_new( - _("search filmroll"), GTK_WINDOW(win), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, _("_cancel"), - GTK_RESPONSE_CANCEL, _("_open"), GTK_RESPONSE_ACCEPT, (char *)NULL); + filechooser = gtk_file_chooser_dialog_new(_("search filmroll"), GTK_WINDOW(win), + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, _("_cancel"), + GTK_RESPONSE_CANCEL, _("_open"), GTK_RESPONSE_ACCEPT, (char *)NULL); #ifdef GDK_WINDOWING_QUARTZ dt_osx_disallow_fullscreen(filechooser); #endif @@ -339,7 +338,7 @@ static void view_popup_menu_onRemove(GtkWidget *menuitem, gpointer userdata) /* Get info about the filmroll (or parent) selected */ model = gtk_tree_view_get_model(treeview); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); - if (gtk_tree_selection_get_selected(selection, &model, &iter)) + if(gtk_tree_selection_get_selected(selection, &model, &iter)) { gtk_tree_model_get(model, &iter, DT_LIB_COLLECT_COL_PATH, &filmroll_path, -1); @@ -351,7 +350,7 @@ static void view_popup_menu_onRemove(GtkWidget *menuitem, gpointer userdata) filmroll_path); DT_DEBUG_SQLITE3_EXEC(dt_database_get(darktable.db), fullq, NULL, NULL, NULL); - if (dt_control_remove_images()) + if(dt_control_remove_images()) { gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &model_iter, &iter); gtk_tree_store_remove(GTK_TREE_STORE(gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model))), @@ -401,8 +400,8 @@ static gboolean view_onButtonPressed(GtkWidget *treeview, GdkEventButton *event, GtkTreePath *path; /* Get tree path for row that was clicked */ - if(gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(treeview), (gint)event->x, (gint)event->y, &path, NULL, - NULL, NULL)) + if(gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(treeview), (gint)event->x, (gint)event->y, &path, NULL, NULL, + NULL)) { gtk_tree_selection_unselect_all(selection); gtk_tree_selection_select_path(selection, path); @@ -487,16 +486,16 @@ static gboolean tree_expand(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter gtk_tree_view_expand_to_path(d->view, path); } - if(strlen(needle)==0) + if(strlen(needle) == 0) { - //nothing to do, we keep the tree collapsed + // nothing to do, we keep the tree collapsed } else if(strcmp(haystack, needle) == 0) { gtk_tree_view_expand_to_path(d->view, path); gtk_tree_selection_select_path(gtk_tree_view_get_selection(d->view), path); } - else if(startwildcard && g_strrstr(haystack, needle+1) != NULL) + else if(startwildcard && g_strrstr(haystack, needle + 1) != NULL) { gtk_tree_view_expand_to_path(d->view, path); } @@ -726,9 +725,8 @@ static GtkTreeModel *_create_filtered_model(GtkTreeModel *model, dt_lib_collect_ if(level > 0) { - if(level > 0 && - gtk_tree_model_iter_n_children(model, &iter) == 0 && - gtk_tree_model_iter_parent(model, &child, &iter)) + if(level > 0 && gtk_tree_model_iter_n_children(model, &iter) == 0 + && gtk_tree_model_iter_parent(model, &child, &iter)) { path = gtk_tree_model_get_path(model, &child); } @@ -765,7 +763,7 @@ static char **split_path(const char *path) #ifdef _WIN32 - if(! (g_ascii_isalpha(tokens[0][0]) && tokens[0][strlen(tokens[0]) - 1] == ':') ) + if(!(g_ascii_isalpha(tokens[0][0]) && tokens[0][strlen(tokens[0]) - 1] == ':')) { g_strfreev(tokens); tokens = NULL; @@ -779,8 +777,7 @@ static char **split_path(const char *path) unsigned int size = g_strv_length(tokens); result = malloc(size * sizeof(char *)); - for(unsigned int i = 0; i < size; i++) - result[i] = tokens[i + 1]; + for(unsigned int i = 0; i < size; i++) result[i] = tokens[i + 1]; g_free(tokens[0]); g_free(tokens); @@ -819,8 +816,9 @@ static void tree_view(dt_lib_collect_rule_t *dr) gtk_widget_hide(GTK_WIDGET(d->sw2)); /* query construction */ - const char *query = folders ? "SELECT DISTINCT folder, id FROM main.film_rolls ORDER BY UPPER(folder) DESC" : - tags ? "SELECT DISTINCT name, id FROM data.tags ORDER BY UPPER(name) DESC" : NULL; + const char *query = folders + ? "SELECT DISTINCT folder, id FROM main.film_rolls ORDER BY UPPER(folder) DESC" + : tags ? "SELECT DISTINCT name, id FROM data.tags ORDER BY UPPER(name) DESC" : NULL; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), query, -1, &stmt, NULL); @@ -839,15 +837,14 @@ static void tree_view(dt_lib_collect_rule_t *dr) if(!uncategorized.stamp) { gtk_tree_store_insert(GTK_TREE_STORE(model), &uncategorized, NULL, 0); - gtk_tree_store_set(GTK_TREE_STORE(model), &uncategorized, DT_LIB_COLLECT_COL_TEXT, - _(UNCATEGORIZED_TAG), DT_LIB_COLLECT_COL_PATH, "", DT_LIB_COLLECT_COL_VISIBLE, - TRUE, -1); + gtk_tree_store_set(GTK_TREE_STORE(model), &uncategorized, DT_LIB_COLLECT_COL_TEXT, _(UNCATEGORIZED_TAG), + DT_LIB_COLLECT_COL_PATH, "", DT_LIB_COLLECT_COL_VISIBLE, TRUE, -1); } /* adding an uncategorized tag */ gtk_tree_store_insert(GTK_TREE_STORE(model), &temp, &uncategorized, 0); - gtk_tree_store_set(GTK_TREE_STORE(model), &temp, DT_LIB_COLLECT_COL_TEXT, name, - DT_LIB_COLLECT_COL_PATH, name, DT_LIB_COLLECT_COL_VISIBLE, TRUE, -1); + gtk_tree_store_set(GTK_TREE_STORE(model), &temp, DT_LIB_COLLECT_COL_TEXT, name, DT_LIB_COLLECT_COL_PATH, + name, DT_LIB_COLLECT_COL_VISIBLE, TRUE, -1); } else { @@ -860,7 +857,7 @@ static void tree_view(dt_lib_collect_rule_t *dr) if(tokens != NULL) { // find the number of common parts at the beginning of tokens and last_tokens - GtkTreeIter parent = {0}; + GtkTreeIter parent = { 0 }; int tokens_length = string_array_length(tokens); int common_length = 0; if(last_tokens) @@ -889,8 +886,7 @@ static void tree_view(dt_lib_collect_rule_t *dr) #ifndef _WIN32 if(folders) pth = g_strdup("/"); #endif - for(int i = 0; i < common_length; i++) - pth = dt_util_dstrcat(pth, format_separator, tokens[i]); + for(int i = 0; i < common_length; i++) pth = dt_util_dstrcat(pth, format_separator, tokens[i]); for(char **token = &tokens[common_length]; *token; token++) { @@ -975,7 +971,8 @@ static void list_view(dt_lib_collect_rule_t *dr) switch(property) { - case DT_COLLECTION_PROP_CAMERA:; // camera + case DT_COLLECTION_PROP_CAMERA: + ; // camera GList *makermodels = NULL; dt_collection_get_makermodel("", &makermodels, NULL); GList *element = makermodels; @@ -984,9 +981,9 @@ static void list_view(dt_lib_collect_rule_t *dr) { gchar *value = (gchar *)element->data; gtk_list_store_append(GTK_LIST_STORE(model), &iter); - gtk_list_store_set(GTK_LIST_STORE(model), &iter, DT_LIB_COLLECT_COL_TEXT, value, - DT_LIB_COLLECT_COL_ID, index, DT_LIB_COLLECT_COL_TOOLTIP, value, - DT_LIB_COLLECT_COL_PATH, value, DT_LIB_COLLECT_COL_VISIBLE, TRUE, -1); + gtk_list_store_set(GTK_LIST_STORE(model), &iter, DT_LIB_COLLECT_COL_TEXT, value, DT_LIB_COLLECT_COL_ID, + index, DT_LIB_COLLECT_COL_TOOLTIP, value, DT_LIB_COLLECT_COL_PATH, value, + DT_LIB_COLLECT_COL_VISIBLE, TRUE, -1); g_free(value); index++; element = element->next; @@ -1018,9 +1015,9 @@ static void list_view(dt_lib_collect_rule_t *dr) case DT_COLLECTION_PROP_COLORLABEL: // colorlabels gtk_list_store_append(GTK_LIST_STORE(model), &iter); - gtk_list_store_set(GTK_LIST_STORE(model), &iter, DT_LIB_COLLECT_COL_TEXT, _("red"), - DT_LIB_COLLECT_COL_ID, 0, DT_LIB_COLLECT_COL_TOOLTIP, _("red"), - DT_LIB_COLLECT_COL_VISIBLE, TRUE, DT_LIB_COLLECT_COL_PATH, _("red"), -1); + gtk_list_store_set(GTK_LIST_STORE(model), &iter, DT_LIB_COLLECT_COL_TEXT, _("red"), DT_LIB_COLLECT_COL_ID, + 0, DT_LIB_COLLECT_COL_TOOLTIP, _("red"), DT_LIB_COLLECT_COL_VISIBLE, TRUE, + DT_LIB_COLLECT_COL_PATH, _("red"), -1); gtk_list_store_append(GTK_LIST_STORE(model), &iter); gtk_list_store_set(GTK_LIST_STORE(model), &iter, DT_LIB_COLLECT_COL_TEXT, _("yellow"), DT_LIB_COLLECT_COL_ID, 1, DT_LIB_COLLECT_COL_TOOLTIP, _("yellow"), @@ -1030,9 +1027,9 @@ static void list_view(dt_lib_collect_rule_t *dr) DT_LIB_COLLECT_COL_ID, 2, DT_LIB_COLLECT_COL_TOOLTIP, _("green"), DT_LIB_COLLECT_COL_VISIBLE, TRUE, DT_LIB_COLLECT_COL_PATH, _("green"), -1); gtk_list_store_append(GTK_LIST_STORE(model), &iter); - gtk_list_store_set(GTK_LIST_STORE(model), &iter, DT_LIB_COLLECT_COL_TEXT, _("blue"), - DT_LIB_COLLECT_COL_ID, 3, DT_LIB_COLLECT_COL_TOOLTIP, _("blue"), - DT_LIB_COLLECT_COL_VISIBLE, TRUE, DT_LIB_COLLECT_COL_PATH, _("blue"), -1); + gtk_list_store_set(GTK_LIST_STORE(model), &iter, DT_LIB_COLLECT_COL_TEXT, _("blue"), DT_LIB_COLLECT_COL_ID, + 3, DT_LIB_COLLECT_COL_TOOLTIP, _("blue"), DT_LIB_COLLECT_COL_VISIBLE, TRUE, + DT_LIB_COLLECT_COL_PATH, _("blue"), -1); gtk_list_store_append(GTK_LIST_STORE(model), &iter); gtk_list_store_set(GTK_LIST_STORE(model), &iter, DT_LIB_COLLECT_COL_TEXT, _("purple"), DT_LIB_COLLECT_COL_ID, 4, DT_LIB_COLLECT_COL_TOOLTIP, _("purple"), @@ -1128,10 +1125,9 @@ static void list_view(dt_lib_collect_rule_t *dr) gchar *escaped_text = g_markup_escape_text(text, -1); - gtk_list_store_set(GTK_LIST_STORE(model), &iter, DT_LIB_COLLECT_COL_TEXT, folder, - DT_LIB_COLLECT_COL_ID, sqlite3_column_int(stmt, 1), DT_LIB_COLLECT_COL_TOOLTIP, - escaped_text, DT_LIB_COLLECT_COL_PATH, value, DT_LIB_COLLECT_COL_VISIBLE, TRUE, - -1); + gtk_list_store_set(GTK_LIST_STORE(model), &iter, DT_LIB_COLLECT_COL_TEXT, folder, DT_LIB_COLLECT_COL_ID, + sqlite3_column_int(stmt, 1), DT_LIB_COLLECT_COL_TOOLTIP, escaped_text, + DT_LIB_COLLECT_COL_PATH, value, DT_LIB_COLLECT_COL_VISIBLE, TRUE, -1); g_free(text); g_free(escaped_text); } @@ -1357,15 +1353,12 @@ static void row_activated(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColum g_signal_handlers_block_matched(d->rule[active].text, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, entry_changed, NULL); gtk_entry_set_text(GTK_ENTRY(d->rule[active].text), text); gtk_editable_set_position(GTK_EDITABLE(d->rule[active].text), -1); - g_signal_handlers_unblock_matched(d->rule[active].text, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, entry_insert_text, - NULL); - g_signal_handlers_unblock_matched(d->rule[active].text, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, entry_changed, - NULL); + g_signal_handlers_unblock_matched(d->rule[active].text, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, entry_insert_text, NULL); + g_signal_handlers_unblock_matched(d->rule[active].text, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, entry_changed, NULL); g_free(text); - if(item == DT_COLLECTION_PROP_TAG || item == DT_COLLECTION_PROP_FOLDERS - || item == DT_COLLECTION_PROP_COLORLABEL || item == DT_COLLECTION_PROP_GEOTAGGING - || item == DT_COLLECTION_PROP_HISTORY) + if(item == DT_COLLECTION_PROP_TAG || item == DT_COLLECTION_PROP_FOLDERS || item == DT_COLLECTION_PROP_COLORLABEL + || item == DT_COLLECTION_PROP_GEOTAGGING || item == DT_COLLECTION_PROP_HISTORY) set_properties(d->rule + active); // we just have to set the selection else update_view(d->rule + active); // we have to update visible items too @@ -1399,7 +1392,7 @@ static void entry_activated(GtkWidget *entry, dt_lib_collect_rule_t *d) { gchar *text; const int item = gtk_combo_box_get_active(GTK_COMBO_BOX(d->combo)); - if(item == DT_COLLECTION_PROP_FILMROLL || // get full path for film rolls + if(item == DT_COLLECTION_PROP_FILMROLL || // get full path for film rolls item == DT_COLLECTION_PROP_TAG || item == DT_COLLECTION_PROP_FOLDERS) // or folders gtk_tree_model_get(model, &iter, DT_LIB_COLLECT_COL_PATH, &text, -1); else @@ -1421,7 +1414,7 @@ static void entry_activated(GtkWidget *entry, dt_lib_collect_rule_t *d) } static void entry_insert_text(GtkWidget *entry, gchar *new_text, gint new_length, gpointer *position, - dt_lib_collect_rule_t *d) + dt_lib_collect_rule_t *d) { d->typing = TRUE; } @@ -1571,7 +1564,7 @@ static void filmrolls_removed(gpointer instance, gpointer self) dt_lib_collect_t *d = (dt_lib_collect_t *)dm->data; // update tree - if (d->view_rule != DT_COLLECTION_PROP_FOLDERS) + if(d->view_rule != DT_COLLECTION_PROP_FOLDERS) { d->view_rule = -1; } @@ -1791,20 +1784,15 @@ void gui_init(dt_lib_module_t *self) _lib_collect_gui_update(self); - dt_control_signal_connect(darktable.signals, DT_SIGNAL_COLLECTION_CHANGED, G_CALLBACK(collection_updated), - self); + dt_control_signal_connect(darktable.signals, DT_SIGNAL_COLLECTION_CHANGED, G_CALLBACK(collection_updated), self); - dt_control_signal_connect(darktable.signals, DT_SIGNAL_FILMROLLS_CHANGED, G_CALLBACK(filmrolls_updated), - self); + dt_control_signal_connect(darktable.signals, DT_SIGNAL_FILMROLLS_CHANGED, G_CALLBACK(filmrolls_updated), self); - dt_control_signal_connect(darktable.signals, DT_SIGNAL_FILMROLLS_IMPORTED, G_CALLBACK(filmrolls_imported), - self); + dt_control_signal_connect(darktable.signals, DT_SIGNAL_FILMROLLS_IMPORTED, G_CALLBACK(filmrolls_imported), self); - dt_control_signal_connect(darktable.signals, DT_SIGNAL_FILMROLLS_REMOVED, G_CALLBACK(filmrolls_removed), - self); + dt_control_signal_connect(darktable.signals, DT_SIGNAL_FILMROLLS_REMOVED, G_CALLBACK(filmrolls_removed), self); - dt_control_signal_connect(darktable.signals, DT_SIGNAL_TAG_CHANGED, G_CALLBACK(tag_changed), - self); + dt_control_signal_connect(darktable.signals, DT_SIGNAL_TAG_CHANGED, G_CALLBACK(tag_changed), self); } void gui_cleanup(dt_lib_module_t *self) @@ -1834,11 +1822,11 @@ void gui_cleanup(dt_lib_module_t *self) #ifdef USE_LUA -static int new_rule_cb(lua_State*L) +static int new_rule_cb(lua_State *L) { dt_lib_collect_params_rule_t rule; - memset(&rule,0, sizeof(dt_lib_collect_params_rule_t)); - luaA_push(L,dt_lib_collect_params_rule_t,&rule); + memset(&rule, 0, sizeof(dt_lib_collect_params_rule_t)); + luaA_push(L, dt_lib_collect_params_rule_t, &rule); return 1; } static int filter_cb(lua_State *L) @@ -1846,37 +1834,41 @@ static int filter_cb(lua_State *L) dt_lib_module_t *self = lua_touserdata(L, lua_upvalueindex(1)); int size; - dt_lib_collect_params_t *p = get_params(self,&size); + dt_lib_collect_params_t *p = get_params(self, &size); // put it in stack so memory is not lost if a lua exception is raised - if(lua_gettop(L) > 0) { - luaL_checktype(L,1,LUA_TTABLE); - dt_lib_collect_params_t *new_p = get_params(self,&size); + if(lua_gettop(L) > 0) + { + luaL_checktype(L, 1, LUA_TTABLE); + dt_lib_collect_params_t *new_p = get_params(self, &size); new_p->rules = 0; - do { - lua_pushinteger(L,new_p->rules + 1); - lua_gettable(L,1); - if(lua_isnil(L,-1)) break; - luaA_to(L,dt_lib_collect_params_rule_t,&new_p->rule[new_p->rules],-1); + do + { + lua_pushinteger(L, new_p->rules + 1); + lua_gettable(L, 1); + if(lua_isnil(L, -1)) break; + luaA_to(L, dt_lib_collect_params_rule_t, &new_p->rule[new_p->rules], -1); new_p->rules++; - }while(new_p->rules < MAX_RULES); - if(new_p->rules == MAX_RULES) { - lua_pushinteger(L,new_p->rules + 1); - lua_gettable(L,1); - if(!lua_isnil(L,-1)) { - luaL_error(L,"Number of rules given excedes max allowed (%d)",MAX_RULES); + } while(new_p->rules < MAX_RULES); + if(new_p->rules == MAX_RULES) + { + lua_pushinteger(L, new_p->rules + 1); + lua_gettable(L, 1); + if(!lua_isnil(L, -1)) + { + luaL_error(L, "Number of rules given excedes max allowed (%d)", MAX_RULES); } } - set_params(self,new_p,size); + set_params(self, new_p, size); free(new_p); - } lua_newtable(L); - for(int i = 0; i < p->rules; i++) { - luaA_push(L,dt_lib_collect_params_rule_t,&p->rule[i]); - luaL_ref(L,-2); + for(int i = 0; i < p->rules; i++) + { + luaA_push(L, dt_lib_collect_params_rule_t, &p->rule[i]); + luaL_ref(L, -2); } free(p); return 1; @@ -1884,40 +1876,43 @@ static int filter_cb(lua_State *L) static int mode_member(lua_State *L) { - dt_lib_collect_params_rule_t *rule = luaL_checkudata(L,1,"dt_lib_collect_params_rule_t"); - if(lua_gettop(L) > 2) { + dt_lib_collect_params_rule_t *rule = luaL_checkudata(L, 1, "dt_lib_collect_params_rule_t"); + if(lua_gettop(L) > 2) + { dt_lib_collect_mode_t value; - luaA_to(L,dt_lib_collect_mode_t,&value,3); + luaA_to(L, dt_lib_collect_mode_t, &value, 3); rule->mode = value; return 0; } const dt_lib_collect_mode_t tmp = rule->mode; // temp buffer because of bitfield in the original struct - luaA_push(L,dt_lib_collect_mode_t,&tmp); + luaA_push(L, dt_lib_collect_mode_t, &tmp); return 1; } static int item_member(lua_State *L) { - dt_lib_collect_params_rule_t *rule = luaL_checkudata(L,1,"dt_lib_collect_params_rule_t"); + dt_lib_collect_params_rule_t *rule = luaL_checkudata(L, 1, "dt_lib_collect_params_rule_t"); - if(lua_gettop(L) > 2) { + if(lua_gettop(L) > 2) + { dt_collection_properties_t value; - luaA_to(L,dt_collection_properties_t,&value,3); + luaA_to(L, dt_collection_properties_t, &value, 3); rule->item = value; return 0; } const dt_collection_properties_t tmp = rule->item; // temp buffer because of bitfield in the original struct - luaA_push(L,dt_collection_properties_t,&tmp); + luaA_push(L, dt_collection_properties_t, &tmp); return 1; } static int data_member(lua_State *L) { - dt_lib_collect_params_rule_t *rule = luaL_checkudata(L,1,"dt_lib_collect_params_rule_t"); + dt_lib_collect_params_rule_t *rule = luaL_checkudata(L, 1, "dt_lib_collect_params_rule_t"); - if(lua_gettop(L) > 2) { + if(lua_gettop(L) > 2) + { size_t tgt_size; - const char*data = luaL_checklstring(L,3,&tgt_size); + const char *data = luaL_checklstring(L, 3, &tgt_size); if(tgt_size > PARAM_STRING_SIZE) { return luaL_error(L, "string '%s' too long (max is %d)", data, PARAM_STRING_SIZE); @@ -1925,7 +1920,7 @@ static int data_member(lua_State *L) g_strlcpy(rule->string, data, sizeof(rule->string)); return 0; } - lua_pushstring(L,rule->string); + lua_pushstring(L, rule->string); return 1; } @@ -1937,7 +1932,7 @@ void init(struct dt_lib_module_t *self) lua_State *L = darktable.lua_state.state; int my_type = dt_lua_module_entry_get_type(L, "lib", self->plugin_name); lua_pushlightuserdata(L, self); - lua_pushcclosure(L, filter_cb,1); + lua_pushcclosure(L, filter_cb, 1); dt_lua_gtk_wrap(L); lua_pushcclosure(L, dt_lua_type_member_common, 1); dt_lua_type_register_const_type(L, my_type, "filter"); @@ -1945,41 +1940,40 @@ void init(struct dt_lib_module_t *self) lua_pushcclosure(L, dt_lua_type_member_common, 1); dt_lua_type_register_const_type(L, my_type, "new_rule"); - dt_lua_init_type(L,dt_lib_collect_params_rule_t); - lua_pushcfunction(L,mode_member); + dt_lua_init_type(L, dt_lib_collect_params_rule_t); + lua_pushcfunction(L, mode_member); dt_lua_type_register(L, dt_lib_collect_params_rule_t, "mode"); - lua_pushcfunction(L,item_member); + lua_pushcfunction(L, item_member); dt_lua_type_register(L, dt_lib_collect_params_rule_t, "item"); - lua_pushcfunction(L,data_member); + lua_pushcfunction(L, data_member); dt_lua_type_register(L, dt_lib_collect_params_rule_t, "data"); - luaA_enum(L,dt_lib_collect_mode_t); - luaA_enum_value(L,dt_lib_collect_mode_t,DT_LIB_COLLECT_MODE_AND); - luaA_enum_value(L,dt_lib_collect_mode_t,DT_LIB_COLLECT_MODE_OR); - luaA_enum_value(L,dt_lib_collect_mode_t,DT_LIB_COLLECT_MODE_AND_NOT); - - luaA_enum(L,dt_collection_properties_t); - luaA_enum_value(L,dt_collection_properties_t,DT_COLLECTION_PROP_FILMROLL); - luaA_enum_value(L,dt_collection_properties_t,DT_COLLECTION_PROP_FOLDERS); - luaA_enum_value(L,dt_collection_properties_t,DT_COLLECTION_PROP_CAMERA); - luaA_enum_value(L,dt_collection_properties_t,DT_COLLECTION_PROP_TAG); - luaA_enum_value(L,dt_collection_properties_t,DT_COLLECTION_PROP_DAY); - luaA_enum_value(L,dt_collection_properties_t,DT_COLLECTION_PROP_TIME); - luaA_enum_value(L,dt_collection_properties_t,DT_COLLECTION_PROP_HISTORY); - luaA_enum_value(L,dt_collection_properties_t,DT_COLLECTION_PROP_COLORLABEL); - luaA_enum_value(L,dt_collection_properties_t,DT_COLLECTION_PROP_TITLE); - luaA_enum_value(L,dt_collection_properties_t,DT_COLLECTION_PROP_DESCRIPTION); - luaA_enum_value(L,dt_collection_properties_t,DT_COLLECTION_PROP_CREATOR); - luaA_enum_value(L,dt_collection_properties_t,DT_COLLECTION_PROP_PUBLISHER); - luaA_enum_value(L,dt_collection_properties_t,DT_COLLECTION_PROP_RIGHTS); - luaA_enum_value(L,dt_collection_properties_t,DT_COLLECTION_PROP_LENS); - luaA_enum_value(L,dt_collection_properties_t,DT_COLLECTION_PROP_FOCAL_LENGTH); - luaA_enum_value(L,dt_collection_properties_t,DT_COLLECTION_PROP_ISO); - luaA_enum_value(L,dt_collection_properties_t,DT_COLLECTION_PROP_APERTURE); - luaA_enum_value(L,dt_collection_properties_t,DT_COLLECTION_PROP_FILENAME); - luaA_enum_value(L,dt_collection_properties_t,DT_COLLECTION_PROP_GEOTAGGING); - + luaA_enum(L, dt_lib_collect_mode_t); + luaA_enum_value(L, dt_lib_collect_mode_t, DT_LIB_COLLECT_MODE_AND); + luaA_enum_value(L, dt_lib_collect_mode_t, DT_LIB_COLLECT_MODE_OR); + luaA_enum_value(L, dt_lib_collect_mode_t, DT_LIB_COLLECT_MODE_AND_NOT); + + luaA_enum(L, dt_collection_properties_t); + luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_FILMROLL); + luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_FOLDERS); + luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_CAMERA); + luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_TAG); + luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_DAY); + luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_TIME); + luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_HISTORY); + luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_COLORLABEL); + luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_TITLE); + luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_DESCRIPTION); + luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_CREATOR); + luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_PUBLISHER); + luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_RIGHTS); + luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_LENS); + luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_FOCAL_LENGTH); + luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_ISO); + luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_APERTURE); + luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_FILENAME); + luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_GEOTAGGING); } #endif #undef MAX_RULES diff --git a/src/libs/collect.h b/src/libs/collect.h index 00fd333f6c5b..21ce0f55ac81 100644 --- a/src/libs/collect.h +++ b/src/libs/collect.h @@ -29,13 +29,11 @@ typedef enum dt_lib_collect_mode_t DT_LIB_COLLECT_MODE_AND_NOT } dt_lib_collect_mode_t; -const char *dt_lib_collect_string[] = { N_("film roll"), N_("folders"), N_("camera"), - N_("tag"), N_("date"), N_("time"), - N_("history"), N_("color label"), N_("title"), - N_("description"), N_("creator"), N_("publisher"), - N_("rights"), N_("lens"), N_("focal length"), - N_("ISO"), N_("aperture"), N_("filename"), - N_("geotagging") }; +const char *dt_lib_collect_string[] + = { N_("film roll"), N_("folders"), N_("camera"), N_("tag"), N_("date"), + N_("time"), N_("history"), N_("color label"), N_("title"), N_("description"), + N_("creator"), N_("publisher"), N_("rights"), N_("lens"), N_("focal length"), + N_("ISO"), N_("aperture"), N_("filename"), N_("geotagging") }; const int dt_lib_collect_string_cnt = sizeof(dt_lib_collect_string) / sizeof(dt_lib_collect_string[0]); // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh diff --git a/src/libs/colorpicker.c b/src/libs/colorpicker.c index 55589f200097..83ec845456dc 100644 --- a/src/libs/colorpicker.c +++ b/src/libs/colorpicker.c @@ -54,7 +54,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"darkroom", NULL}; + static const char *v[] = { "darkroom", NULL }; return v; } @@ -95,9 +95,9 @@ static gboolean main_draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data width = gtk_widget_get_allocated_width(widget); height = gtk_widget_get_allocated_height(widget); - gdk_cairo_set_source_rgba (cr, &d->rgb); + gdk_cairo_set_source_rgba(cr, &d->rgb); cairo_rectangle(cr, 0, 0, width, height); - cairo_fill (cr); + cairo_fill(cr); return FALSE; } @@ -111,7 +111,7 @@ static gboolean sample_draw_callback(GtkWidget *widget, cairo_t *cr, gpointer da height = gtk_widget_get_allocated_height(widget); gdk_cairo_set_source_rgba(cr, &sample->rgb); cairo_rectangle(cr, 0, 0, width, height); - cairo_fill (cr); + cairo_fill(cr); // if the sample is locked we want to add a lock if(sample->locked) @@ -122,7 +122,8 @@ static gboolean sample_draw_callback(GtkWidget *widget, cairo_t *cr, gpointer da if(icon_width > 0 && icon_height > 0) { GdkRGBA fg_color; - gtk_style_context_get_color(gtk_widget_get_style_context(widget), gtk_widget_get_state_flags(widget), &fg_color); + gtk_style_context_get_color(gtk_widget_get_style_context(widget), gtk_widget_get_state_flags(widget), + &fg_color); gdk_cairo_set_source_rgba(cr, &fg_color); dtgtk_cairo_paint_lock(cr, border, border, icon_width, icon_height, 0); @@ -361,15 +362,12 @@ static void _add_sample(GtkButton *widget, gpointer self) gtk_widget_set_size_request(sample->color_patch, DT_PIXEL_APPLY_DPI(40), -1); gtk_widget_set_events(sample->color_patch, GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK); gtk_widget_set_tooltip_text(sample->color_patch, _("hover to highlight sample on canvas, " - "click to lock sample")); + "click to lock sample")); gtk_box_pack_start(GTK_BOX(sample->container), sample->color_patch, FALSE, FALSE, 0); - g_signal_connect(G_OBJECT(sample->color_patch), "enter-notify-event", G_CALLBACK(_live_sample_enter), - sample); - g_signal_connect(G_OBJECT(sample->color_patch), "leave-notify-event", G_CALLBACK(_live_sample_leave), - sample); - g_signal_connect(G_OBJECT(sample->color_patch), "button-press-event", G_CALLBACK(_sample_lock_toggle), - sample); + g_signal_connect(G_OBJECT(sample->color_patch), "enter-notify-event", G_CALLBACK(_live_sample_enter), sample); + g_signal_connect(G_OBJECT(sample->color_patch), "leave-notify-event", G_CALLBACK(_live_sample_leave), sample); + g_signal_connect(G_OBJECT(sample->color_patch), "button-press-event", G_CALLBACK(_sample_lock_toggle), sample); g_signal_connect(G_OBJECT(sample->color_patch), "draw", G_CALLBACK(sample_draw_callback), sample); sample->output_label = gtk_label_new(""); @@ -434,8 +432,7 @@ static void _set_sample_area(dt_lib_module_t *self, float size) { darktable.develop->gui_module->color_picker_box[0] = darktable.develop->gui_module->color_picker_box[1] = 1.0 - size; - darktable.develop->gui_module->color_picker_box[2] = darktable.develop->gui_module->color_picker_box[3] - = size; + darktable.develop->gui_module->color_picker_box[2] = darktable.develop->gui_module->color_picker_box[3] = size; } gtk_combo_box_set_active(GTK_COMBO_BOX(d->size_selector), 1); @@ -532,8 +529,7 @@ void gui_init(dt_lib_module_t *self) gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(data->statistic_selector), _("mean")); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(data->statistic_selector), _("min")); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(data->statistic_selector), _("max")); - gtk_combo_box_set_active(GTK_COMBO_BOX(data->statistic_selector), - dt_conf_get_int("ui_last/colorpicker_mode")); + gtk_combo_box_set_active(GTK_COMBO_BOX(data->statistic_selector), dt_conf_get_int("ui_last/colorpicker_mode")); gtk_widget_set_sensitive(data->statistic_selector, dt_conf_get_int("ui_last/colorpicker_size")); gtk_box_pack_start(GTK_BOX(output_options), data->statistic_selector, TRUE, TRUE, 0); @@ -542,8 +538,7 @@ void gui_init(dt_lib_module_t *self) data->color_mode_selector = gtk_combo_box_text_new(); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(data->color_mode_selector), _("RGB")); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(data->color_mode_selector), _("Lab")); - gtk_combo_box_set_active(GTK_COMBO_BOX(data->color_mode_selector), - dt_conf_get_int("ui_last/colorpicker_model")); + gtk_combo_box_set_active(GTK_COMBO_BOX(data->color_mode_selector), dt_conf_get_int("ui_last/colorpicker_model")); gtk_box_pack_start(GTK_BOX(output_options), data->color_mode_selector, TRUE, TRUE, 0); g_signal_connect(G_OBJECT(data->color_mode_selector), "changed", G_CALLBACK(_color_mode_changed), self); @@ -556,8 +551,7 @@ void gui_init(dt_lib_module_t *self) restrict_button = gtk_check_button_new_with_label(_("restrict histogram to selection")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(restrict_button), dt_conf_get_int("ui_last/colorpicker_restrict_histogram")); - darktable.lib->proxy.colorpicker.restrict_histogram - = dt_conf_get_int("ui_last/colorpicker_restrict_histogram"); + darktable.lib->proxy.colorpicker.restrict_histogram = dt_conf_get_int("ui_last/colorpicker_restrict_histogram"); gtk_box_pack_start(GTK_BOX(container), restrict_button, TRUE, TRUE, 0); g_signal_connect(G_OBJECT(restrict_button), "toggled", G_CALLBACK(_restrict_histogram_changed), NULL); @@ -574,8 +568,8 @@ void gui_init(dt_lib_module_t *self) dt_conf_get_int("ui_last/colorsamples_mode")); gtk_box_pack_start(GTK_BOX(samples_options_row), data->samples_statistic_selector, TRUE, TRUE, 0); - g_signal_connect(G_OBJECT(data->samples_statistic_selector), "changed", - G_CALLBACK(_samples_statistic_changed), self); + g_signal_connect(G_OBJECT(data->samples_statistic_selector), "changed", G_CALLBACK(_samples_statistic_changed), + self); data->samples_mode_selector = gtk_combo_box_text_new(); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(data->samples_mode_selector), _("RGB")); @@ -619,11 +613,9 @@ void gui_cleanup(dt_lib_module_t *self) free(darktable.lib->proxy.colorpicker.picked_color_lab_mean); free(darktable.lib->proxy.colorpicker.picked_color_lab_min); free(darktable.lib->proxy.colorpicker.picked_color_lab_max); - darktable.lib->proxy.colorpicker.picked_color_rgb_mean - = darktable.lib->proxy.colorpicker.picked_color_rgb_min + darktable.lib->proxy.colorpicker.picked_color_rgb_mean = darktable.lib->proxy.colorpicker.picked_color_rgb_min = darktable.lib->proxy.colorpicker.picked_color_rgb_max = NULL; - darktable.lib->proxy.colorpicker.picked_color_lab_mean - = darktable.lib->proxy.colorpicker.picked_color_lab_min + darktable.lib->proxy.colorpicker.picked_color_lab_mean = darktable.lib->proxy.colorpicker.picked_color_lab_min = darktable.lib->proxy.colorpicker.picked_color_lab_max = NULL; diff --git a/src/libs/copy_history.c b/src/libs/copy_history.c index c4aa6aa7fdf1..3f66f24d4047 100644 --- a/src/libs/copy_history.c +++ b/src/libs/copy_history.c @@ -56,7 +56,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"lighttable", NULL}; + static const char *v[] = { "lighttable", NULL }; return v; } @@ -74,8 +74,8 @@ static void load_button_clicked(GtkWidget *widget, dt_lib_module_t *self) { GtkWidget *win = dt_ui_main_window(darktable.gui->ui); GtkWidget *filechooser = gtk_file_chooser_dialog_new( - _("open sidecar file"), GTK_WINDOW(win), GTK_FILE_CHOOSER_ACTION_OPEN, _("_cancel"), - GTK_RESPONSE_CANCEL, _("_open"), GTK_RESPONSE_ACCEPT, (char *)NULL); + _("open sidecar file"), GTK_WINDOW(win), GTK_FILE_CHOOSER_ACTION_OPEN, _("_cancel"), GTK_RESPONSE_CANCEL, + _("_open"), GTK_RESPONSE_ACCEPT, (char *)NULL); #ifdef GDK_WINDOWING_QUARTZ dt_osx_disallow_fullscreen(filechooser); #endif @@ -118,8 +118,8 @@ static int get_selected_image(void) /* get imageid for source if history past */ sqlite3_stmt *stmt; - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT imgid FROM main.selected_images", - -1, &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT imgid FROM main.selected_images", -1, &stmt, + NULL); if(sqlite3_step(stmt) == SQLITE_ROW) { /* copy history of first image in selection */ @@ -184,17 +184,18 @@ static void delete_button_clicked(GtkWidget *widget, gpointer user_data) const GtkWidget *win = dt_ui_main_window(darktable.gui->ui); int number; - if (dt_view_get_image_to_act_on() != -1) + if(dt_view_get_image_to_act_on() != -1) number = 1; else number = dt_collection_get_selected_count(darktable.collection); - if (number == 0) return; + if(number == 0) return; GtkWidget *dialog = gtk_message_dialog_new( GTK_WINDOW(win), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, ngettext("do you really want to clear history of %d selected image?", - "do you really want to clear history of %d selected images?", number), number); + "do you really want to clear history of %d selected images?", number), + number); gtk_window_set_title(GTK_WINDOW(dialog), _("delete images' history?")); res = gtk_dialog_run(GTK_DIALOG(dialog)); @@ -260,7 +261,8 @@ int position() return 600; } -#define ellipsize_button(button) gtk_label_set_ellipsize(GTK_LABEL(gtk_bin_get_child(GTK_BIN(button))), PANGO_ELLIPSIZE_END); +#define ellipsize_button(button) \ + gtk_label_set_ellipsize(GTK_LABEL(gtk_bin_get_child(GTK_BIN(button))), PANGO_ELLIPSIZE_END); void gui_init(dt_lib_module_t *self) { dt_lib_copy_history_t *d = (dt_lib_copy_history_t *)malloc(sizeof(dt_lib_copy_history_t)); diff --git a/src/libs/export.c b/src/libs/export.c index 0b13d68df03b..d5be94948b75 100644 --- a/src/libs/export.c +++ b/src/libs/export.c @@ -66,7 +66,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"lighttable", NULL}; + static const char *v[] = { "lighttable", NULL }; return v; } @@ -84,8 +84,10 @@ static void export_button_clicked(GtkWidget *widget, gpointer user_data) int max_width = dt_conf_get_int("plugins/lighttable/export/width"); int max_height = dt_conf_get_int("plugins/lighttable/export/height"); - // get the format_name and storage_name settings which are plug-ins name and not necessary what is displayed on the combobox. - // note that we cannot take directly the combobox entry index as depending on the storage some format are not listed. + // get the format_name and storage_name settings which are plug-ins name and not necessary what is displayed on + // the combobox. + // note that we cannot take directly the combobox entry index as depending on the storage some format are not + // listed. char *format_name = dt_conf_get_string("plugins/lighttable/export/format_name"); char *storage_name = dt_conf_get_string("plugins/lighttable/export/storage_name"); const int format_index = dt_imageio_get_index_of_format(dt_imageio_get_format_by_name(format_name)); @@ -94,11 +96,13 @@ static void export_button_clicked(GtkWidget *widget, gpointer user_data) g_free(format_name); g_free(storage_name); - if(format_index == -1) { + if(format_index == -1) + { dt_control_log("invalid format for export selected"); return; } - if(storage_index == -1) { + if(storage_index == -1) + { dt_control_log("invalid storage for export selected"); return; } @@ -124,8 +128,8 @@ static void export_button_clicked(GtkWidget *widget, gpointer user_data) else list = dt_collection_get_selected(darktable.collection, -1); - dt_control_export(list, max_width, max_height, format_index, storage_index, high_quality, upscale, - style, style_append, icc_type, icc_filename, icc_intent); + dt_control_export(list, max_width, max_height, format_index, storage_index, high_quality, upscale, style, + style_append, icc_type, icc_filename, icc_intent); g_free(icc_filename); } @@ -169,8 +173,8 @@ void gui_reset(dt_lib_module_t *self) for(GList *profiles = darktable.color_profiles->profiles; profiles; profiles = g_list_next(profiles)) { dt_colorspaces_color_profile_t *pp = (dt_colorspaces_color_profile_t *)profiles->data; - if(pp->out_pos > -1 && - icctype == pp->type && (icctype != DT_COLORSPACE_FILE || !strcmp(iccfilename, pp->filename))) + if(pp->out_pos > -1 && icctype == pp->type + && (icctype != DT_COLORSPACE_FILE || !strcmp(iccfilename, pp->filename))) { dt_bauhaus_combobox_set(d->profile, pp->out_pos + 1); break; @@ -196,7 +200,7 @@ void gui_reset(dt_lib_module_t *self) // style mode to overwrite as it was the initial behavior dt_bauhaus_combobox_set(d->style_mode, dt_conf_get_bool("plugins/lighttable/export/style_append")); - gtk_widget_set_sensitive(GTK_WIDGET(d->style_mode), dt_bauhaus_combobox_get(d->style)==0?FALSE:TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(d->style_mode), dt_bauhaus_combobox_get(d->style) == 0 ? FALSE : TRUE); dt_imageio_module_format_t *mformat = dt_imageio_get_format(); if(mformat) mformat->gui_reset(mformat); @@ -219,21 +223,25 @@ static void set_format_by_name(dt_lib_export_t *d, const char *name) } } while((it = g_list_next(it))); - if(!module) { + if(!module) + { gtk_widget_hide(d->format_extra_container); return; - } else if(module->widget) { + } + else if(module->widget) + { gtk_widget_show_all(d->format_extra_container); gtk_stack_set_visible_child(GTK_STACK(d->format_extra_container), module->widget); - } else { + } + else + { gtk_widget_hide(d->format_extra_container); } // Store the new format dt_conf_set_string("plugins/lighttable/export/format_name", module->plugin_name); - if(_combo_box_set_active_text(d->format, module->name()) == FALSE) - dt_bauhaus_combobox_set(d->format, 0); + if(_combo_box_set_active_text(d->format, module->name()) == FALSE) dt_bauhaus_combobox_set(d->format, 0); // Let's also update combination of storage/format dimension restrictions _update_dimensions(d); @@ -290,21 +298,27 @@ static void set_storage_by_name(dt_lib_export_t *d, const char *name) if(it != NULL) do { k++; - if(strcmp(((dt_imageio_module_storage_t *)it->data)->name(((dt_imageio_module_storage_t *)it->data)), - name) == 0 || strcmp(((dt_imageio_module_storage_t *)it->data)->plugin_name, name) == 0) + if(strcmp(((dt_imageio_module_storage_t *)it->data)->name(((dt_imageio_module_storage_t *)it->data)), name) + == 0 + || strcmp(((dt_imageio_module_storage_t *)it->data)->plugin_name, name) == 0) { module = (dt_imageio_module_storage_t *)it->data; break; } } while((it = g_list_next(it))); - if(!module) { + if(!module) + { gtk_widget_hide(d->storage_extra_container); return; - } else if(module->widget) { + } + else if(module->widget) + { gtk_widget_show_all(d->storage_extra_container); - gtk_stack_set_visible_child(GTK_STACK(d->storage_extra_container),module->widget); - } else { + gtk_stack_set_visible_child(GTK_STACK(d->storage_extra_container), module->widget); + } + else + { gtk_widget_hide(d->storage_extra_container); } dt_bauhaus_combobox_set(d->storage, k); @@ -417,7 +431,7 @@ static gboolean _combo_box_set_active_text(GtkWidget *cb, const gchar *text) int i = 0; while(iter) { - if(!g_strcmp0((gchar*)iter->data, text)) + if(!g_strcmp0((gchar *)iter->data, text)) { dt_bauhaus_combobox_set(cb, i); return TRUE; @@ -466,20 +480,20 @@ static void on_storage_list_changed(gpointer instance, dt_lib_module_t *self) children = gtk_container_get_children(GTK_CONTAINER(d->storage_extra_container)); for(iter = children; iter != NULL; iter = g_list_next(iter)) - gtk_container_remove(GTK_CONTAINER(d->storage_extra_container),GTK_WIDGET(iter->data)); + gtk_container_remove(GTK_CONTAINER(d->storage_extra_container), GTK_WIDGET(iter->data)); g_list_free(children); GList *it = darktable.imageio->plugins_storage; if(it != NULL) do - { - dt_imageio_module_storage_t *module = (dt_imageio_module_storage_t *)it->data; - dt_bauhaus_combobox_add(d->storage, module->name(module)); - if(module->widget) { - gtk_container_add(GTK_CONTAINER(d->storage_extra_container), module->widget); - } - } while((it = g_list_next(it))); + dt_imageio_module_storage_t *module = (dt_imageio_module_storage_t *)it->data; + dt_bauhaus_combobox_add(d->storage, module->name(module)); + if(module->widget) + { + gtk_container_add(GTK_CONTAINER(d->storage_extra_container), module->widget); + } + } while((it = g_list_next(it))); dt_bauhaus_combobox_set(d->storage, dt_imageio_get_index_of_storage(storage)); } @@ -520,18 +534,18 @@ void gui_init(dt_lib_module_t *self) // add all storage widgets to the stack widget d->storage_extra_container = gtk_stack_new(); - gtk_stack_set_homogeneous(GTK_STACK(d->storage_extra_container),FALSE); + gtk_stack_set_homogeneous(GTK_STACK(d->storage_extra_container), FALSE); gtk_box_pack_start(GTK_BOX(self->widget), d->storage_extra_container, FALSE, TRUE, 0); GList *it = g_list_first(darktable.imageio->plugins_storage); if(it != NULL) do - { - dt_imageio_module_storage_t *module = (dt_imageio_module_storage_t *)it->data; - dt_bauhaus_combobox_add(d->storage, module->name(module)); - if(module->widget) { - gtk_container_add(GTK_CONTAINER(d->storage_extra_container), module->widget); - } - } while((it = g_list_next(it))); + dt_imageio_module_storage_t *module = (dt_imageio_module_storage_t *)it->data; + dt_bauhaus_combobox_add(d->storage, module->name(module)); + if(module->widget) + { + gtk_container_add(GTK_CONTAINER(d->storage_extra_container), module->widget); + } + } while((it = g_list_next(it))); // postponed so we can do the two steps in one loop dt_control_signal_connect(darktable.signals, DT_SIGNAL_IMAGEIO_STORAGE_CHANGE, @@ -549,17 +563,17 @@ void gui_init(dt_lib_module_t *self) // add all format widgets to the stack widget d->format_extra_container = gtk_stack_new(); - gtk_stack_set_homogeneous(GTK_STACK(d->format_extra_container),FALSE); + gtk_stack_set_homogeneous(GTK_STACK(d->format_extra_container), FALSE); gtk_box_pack_start(GTK_BOX(self->widget), d->format_extra_container, FALSE, TRUE, 0); it = g_list_first(darktable.imageio->plugins_format); if(it != NULL) do - { - dt_imageio_module_format_t *module = (dt_imageio_module_format_t *)it->data; - if(module->widget) { - gtk_container_add(GTK_CONTAINER(d->format_extra_container), module->widget); - } - } while((it = g_list_next(it))); + dt_imageio_module_format_t *module = (dt_imageio_module_format_t *)it->data; + if(module->widget) + { + gtk_container_add(GTK_CONTAINER(d->format_extra_container), module->widget); + } + } while((it = g_list_next(it))); label = dt_ui_section_label_new(_("global options")); gtk_widget_set_margin_top(label, DT_PIXEL_APPLY_DPI(20)); @@ -611,8 +625,7 @@ void gui_init(dt_lib_module_t *self) dt_bauhaus_combobox_set(d->profile, 0); char tooltip[1024]; - snprintf(tooltip, sizeof(tooltip), _("output ICC profiles in %s/color/out or %s/color/out"), confdir, - datadir); + snprintf(tooltip, sizeof(tooltip), _("output ICC profiles in %s/color/out or %s/color/out"), confdir, datadir); gtk_widget_set_tooltip_text(d->profile, tooltip); // Add intent combo @@ -689,17 +702,17 @@ void gui_cleanup(dt_lib_module_t *self) GList *it = g_list_first(darktable.imageio->plugins_storage); if(it != NULL) do - { - dt_imageio_module_storage_t *module = (dt_imageio_module_storage_t *)it->data; - if(module->widget) gtk_container_remove(GTK_CONTAINER(d->storage_extra_container), module->widget); - } while((it = g_list_next(it))); + { + dt_imageio_module_storage_t *module = (dt_imageio_module_storage_t *)it->data; + if(module->widget) gtk_container_remove(GTK_CONTAINER(d->storage_extra_container), module->widget); + } while((it = g_list_next(it))); it = g_list_first(darktable.imageio->plugins_format); if(it != NULL) do - { - dt_imageio_module_format_t *module = (dt_imageio_module_format_t *)it->data; - if(module->widget) gtk_container_remove(GTK_CONTAINER(d->format_extra_container), module->widget); - } while((it = g_list_next(it))); + { + dt_imageio_module_format_t *module = (dt_imageio_module_format_t *)it->data; + if(module->widget) gtk_container_remove(GTK_CONTAINER(d->format_extra_container), module->widget); + } while((it = g_list_next(it))); free(self->data); self->data = NULL; @@ -792,16 +805,14 @@ void init_presets(dt_lib_module_t *self) if(fversion < new_fversion) { if(!(fmod->legacy_params - && (new_fdata = fmod->legacy_params(fmod, fdata, fsize, fversion, new_fversion, &new_fsize)) - != NULL)) + && (new_fdata = fmod->legacy_params(fmod, fdata, fsize, fversion, new_fversion, &new_fsize)) != NULL)) goto delete_preset; } if(sversion < new_sversion) { if(!(smod->legacy_params - && (new_sdata = smod->legacy_params(smod, sdata, ssize, sversion, new_sversion, &new_ssize)) - != NULL)) + && (new_sdata = smod->legacy_params(smod, sdata, ssize, sversion, new_sversion, &new_ssize)) != NULL)) goto delete_preset; } @@ -833,8 +844,8 @@ void init_presets(dt_lib_module_t *self) // write the updated preset back to db fprintf(stderr, - "[export_init_presets] updating export preset '%s' from versions %d/%d to versions %d/%d\n", - name, fversion, sversion, new_fversion, new_sversion); + "[export_init_presets] updating export preset '%s' from versions %d/%d to versions %d/%d\n", name, + fversion, sversion, new_fversion, new_sversion); sqlite3_stmt *innerstmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "UPDATE data.presets SET op_params=?1 WHERE rowid=?2", -1, &innerstmt, NULL); @@ -925,7 +936,8 @@ void *legacy_params(dt_lib_module_t *self, const void *const old_params, const s void *new_params = calloc(1, new_params_size); memcpy(new_params, old_params, 2 * sizeof(int32_t)); - memcpy(new_params + 3 * sizeof(int32_t), old_params + 2 * sizeof(int32_t), old_params_size - 2 * sizeof(int32_t)); + memcpy(new_params + 3 * sizeof(int32_t), old_params + 2 * sizeof(int32_t), + old_params_size - 2 * sizeof(int32_t)); *new_size = new_params_size; *new_version = 3; @@ -1119,8 +1131,8 @@ int set_params(dt_lib_module_t *self, const void *params, int size) for(GList *iter = darktable.color_profiles->profiles; iter; iter = g_list_next(iter)) { dt_colorspaces_color_profile_t *pp = (dt_colorspaces_color_profile_t *)iter->data; - if(pp->out_pos > -1 && - icctype == pp->type && (icctype != DT_COLORSPACE_FILE || !strcmp(iccfilename, pp->filename))) + if(pp->out_pos > -1 && icctype == pp->type + && (icctype != DT_COLORSPACE_FILE || !strcmp(iccfilename, pp->filename))) { dt_bauhaus_combobox_set(d->profile, pp->out_pos + 1); break; @@ -1151,7 +1163,7 @@ int set_params(dt_lib_module_t *self, const void *params, int size) if(size != strlen(fname) + strlen(sname) + 2 + 4 * sizeof(int32_t) + fsize + ssize + 5 * sizeof(int32_t) - + strlen(iccfilename) + 1) + + strlen(iccfilename) + 1) return 1; if(fversion != fmod->version() || sversion != smod->version()) return 1; diff --git a/src/libs/geotagging.c b/src/libs/geotagging.c index d4a17fd2ae72..94d519c11c59 100644 --- a/src/libs/geotagging.c +++ b/src/libs/geotagging.c @@ -49,7 +49,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"lighttable", NULL}; + static const char *v[] = { "lighttable", NULL }; return v; } @@ -134,7 +134,7 @@ static gboolean _lib_geotagging_parse_offset(const char *str, long int *seconds) { numbers[fields++] = 10 * (str[0] - '0') + (str[1] - '0'); str += 2; -// len -= 2; + // len -= 2; } // end @@ -312,8 +312,8 @@ static void _lib_geotagging_calculate_offset_callback(GtkWidget *widget, dt_lib_ gint minute; gint second; - if(sscanf(cimg->exif_datetime_taken, "%d:%d:%d %d:%d:%d", (int *)&year, (int *)&month, - (int *)&day, (int *)&hour, (int *)&minute, (int *)&second) == 6) + if(sscanf(cimg->exif_datetime_taken, "%d:%d:%d %d:%d:%d", (int *)&year, (int *)&month, (int *)&day, + (int *)&hour, (int *)&minute, (int *)&second) == 6) { // calculate the offset long int exif_seconds = hour * 60 * 60 + minute * 60 + second; @@ -400,8 +400,8 @@ static void _lib_geotagging_show_offset_window(GtkWidget *widget, dt_lib_module_ gtk_editable_select_region(GTK_EDITABLE(d->floating_window_entry), 0, -1); gtk_box_pack_start(GTK_BOX(vbox), d->floating_window_entry, TRUE, TRUE, 0); - g_signal_connect(d->floating_window_entry, "key-press-event", - G_CALLBACK(_lib_geotagging_floating_key_press), self); + g_signal_connect(d->floating_window_entry, "key-press-event", G_CALLBACK(_lib_geotagging_floating_key_press), + self); GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); GtkWidget *cancel_button = gtk_button_new_with_label(_("cancel")); @@ -409,10 +409,8 @@ static void _lib_geotagging_show_offset_window(GtkWidget *widget, dt_lib_module_ gtk_box_pack_start(GTK_BOX(hbox), cancel_button, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox), ok_button, TRUE, TRUE, 0); - g_signal_connect_swapped(G_OBJECT(cancel_button), "clicked", G_CALLBACK(gtk_widget_destroy), - d->floating_window); - g_signal_connect(G_OBJECT(ok_button), "clicked", G_CALLBACK(_lib_geotagging_calculate_offset_callback), - self); + g_signal_connect_swapped(G_OBJECT(cancel_button), "clicked", G_CALLBACK(gtk_widget_destroy), d->floating_window); + g_signal_connect(G_OBJECT(ok_button), "clicked", G_CALLBACK(_lib_geotagging_calculate_offset_callback), self); gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); @@ -583,7 +581,8 @@ static GList *_lib_geotagging_get_timezones(void) // sometimes files are not separated by single tabs but multiple spaces, resulting in empty strings in tokens // so we have to look for the 3rd non-empty entry int n_found = -1, i; - for(i = 0; tokens[i] && n_found < 2; i++) if(*tokens[i]) n_found++; + for(i = 0; tokens[i] && n_found < 2; i++) + if(*tokens[i]) n_found++; if(n_found != 2) { g_strfreev(tokens); diff --git a/src/libs/histogram.c b/src/libs/histogram.c index befafb802a5e..17ac7ec6824e 100644 --- a/src/libs/histogram.c +++ b/src/libs/histogram.c @@ -45,10 +45,8 @@ typedef struct dt_lib_histogram_t } dt_lib_histogram_t; static gboolean _lib_histogram_draw_callback(GtkWidget *widget, cairo_t *cr, gpointer user_data); -static gboolean _lib_histogram_motion_notify_callback(GtkWidget *widget, GdkEventMotion *event, - gpointer user_data); -static gboolean _lib_histogram_button_press_callback(GtkWidget *widget, GdkEventButton *event, - gpointer user_data); +static gboolean _lib_histogram_motion_notify_callback(GtkWidget *widget, GdkEventMotion *event, gpointer user_data); +static gboolean _lib_histogram_button_press_callback(GtkWidget *widget, GdkEventButton *event, gpointer user_data); static gboolean _lib_histogram_button_release_callback(GtkWidget *widget, GdkEventButton *event, gpointer user_data); static gboolean _lib_histogram_scroll_callback(GtkWidget *widget, GdkEventScroll *event, gpointer user_data); @@ -64,7 +62,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"darkroom", "tethering", NULL}; + static const char *v[] = { "darkroom", "tethering", NULL }; return v; } @@ -127,23 +125,23 @@ void gui_init(dt_lib_module_t *self) self->widget = gtk_drawing_area_new(); gtk_widget_add_events(self->widget, GDK_LEAVE_NOTIFY_MASK | GDK_ENTER_NOTIFY_MASK | GDK_POINTER_MOTION_MASK - | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | - // GDK_STRUCTURE_MASK | - GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK); + | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | + // GDK_STRUCTURE_MASK | + GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK); /* connect callbacks */ gtk_widget_set_tooltip_text(self->widget, _("drag to change exposure,\ndoubleclick resets")); g_signal_connect(G_OBJECT(self->widget), "draw", G_CALLBACK(_lib_histogram_draw_callback), self); - g_signal_connect(G_OBJECT(self->widget), "button-press-event", - G_CALLBACK(_lib_histogram_button_press_callback), self); + g_signal_connect(G_OBJECT(self->widget), "button-press-event", G_CALLBACK(_lib_histogram_button_press_callback), + self); g_signal_connect(G_OBJECT(self->widget), "button-release-event", G_CALLBACK(_lib_histogram_button_release_callback), self); g_signal_connect(G_OBJECT(self->widget), "motion-notify-event", G_CALLBACK(_lib_histogram_motion_notify_callback), self); - g_signal_connect(G_OBJECT(self->widget), "leave-notify-event", - G_CALLBACK(_lib_histogram_leave_notify_callback), self); - g_signal_connect(G_OBJECT(self->widget), "enter-notify-event", - G_CALLBACK(_lib_histogram_enter_notify_callback), self); + g_signal_connect(G_OBJECT(self->widget), "leave-notify-event", G_CALLBACK(_lib_histogram_leave_notify_callback), + self); + g_signal_connect(G_OBJECT(self->widget), "enter-notify-event", G_CALLBACK(_lib_histogram_enter_notify_callback), + self); g_signal_connect(G_OBJECT(self->widget), "scroll-event", G_CALLBACK(_lib_histogram_scroll_callback), self); // g_signal_connect (G_OBJECT (self->widget), "configure-event", // G_CALLBACK (_lib_histogram_configure_callback), self); @@ -234,14 +232,14 @@ static void _draw_mode_toggle(cairo_t *cr, float x, float y, float width, float cairo_save(cr); cairo_scale(cr, 1, -1); cairo_translate(cr, 0, -height); - cairo_rectangle(cr, 1.5 * border + (width - 3.0 * border) * 0.2, 1.5 * border, - (width - 3.0 * border) * 0.6, height - 3.0 * border); + cairo_rectangle(cr, 1.5 * border + (width - 3.0 * border) * 0.2, 1.5 * border, (width - 3.0 * border) * 0.6, + height - 3.0 * border); cairo_set_source(cr, pattern); cairo_fill(cr); cairo_restore(cr); - cairo_rectangle(cr, 1.5 * border + (width - 3.0 * border) * 0.7, 1.5 * border, - (width - 3.0 * border) * 0.3, height - 3.0 * border); + cairo_rectangle(cr, 1.5 * border + (width - 3.0 * border) * 0.7, 1.5 * border, (width - 3.0 * border) * 0.3, + height - 3.0 * border); cairo_set_source(cr, pattern); cairo_fill(cr); @@ -448,8 +446,7 @@ static gboolean _lib_histogram_draw_callback(GtkWidget *widget, cairo_t *crf, gp return TRUE; } -static gboolean _lib_histogram_motion_notify_callback(GtkWidget *widget, GdkEventMotion *event, - gpointer user_data) +static gboolean _lib_histogram_motion_notify_callback(GtkWidget *widget, GdkEventMotion *event, gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_histogram_t *d = (dt_lib_histogram_t *)self->data; @@ -502,18 +499,20 @@ static gboolean _lib_histogram_motion_notify_callback(GtkWidget *widget, GdkEven else if(x > d->red_x && x < d->red_x + d->color_w && y > d->button_y && y < d->button_y + d->button_h) { d->highlight = 4; - gtk_widget_set_tooltip_text(widget, d->red ? _("click to hide red channel") : _("click to show red channel")); + gtk_widget_set_tooltip_text(widget, + d->red ? _("click to hide red channel") : _("click to show red channel")); } else if(x > d->green_x && x < d->green_x + d->color_w && y > d->button_y && y < d->button_y + d->button_h) { d->highlight = 5; - gtk_widget_set_tooltip_text(widget, d->red ? _("click to hide green channel") - : _("click to show green channel")); + gtk_widget_set_tooltip_text(widget, + d->red ? _("click to hide green channel") : _("click to show green channel")); } else if(x > d->blue_x && x < d->blue_x + d->color_w && y > d->button_y && y < d->button_y + d->button_h) { d->highlight = 6; - gtk_widget_set_tooltip_text(widget, d->red ? _("click to hide blue channel") : _("click to show blue channel")); + gtk_widget_set_tooltip_text(widget, + d->red ? _("click to hide blue channel") : _("click to show blue channel")); } else if(pos < 0.2) { @@ -529,22 +528,20 @@ static gboolean _lib_histogram_motion_notify_callback(GtkWidget *widget, GdkEven } gint x, y; // notify gtk for motion_hint. #if GTK_CHECK_VERSION(3, 20, 0) - gdk_window_get_device_position(gtk_widget_get_window(widget), - gdk_seat_get_pointer(gdk_display_get_default_seat( - gdk_window_get_display(event->window))), - &x, &y, 0); + gdk_window_get_device_position( + gtk_widget_get_window(widget), + gdk_seat_get_pointer(gdk_display_get_default_seat(gdk_window_get_display(event->window))), &x, &y, 0); #else - gdk_window_get_device_position(event->window, - gdk_device_manager_get_client_pointer( - gdk_display_get_device_manager(gdk_window_get_display(event->window))), - &x, &y, NULL); + gdk_window_get_device_position( + event->window, + gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gdk_window_get_display(event->window))), + &x, &y, NULL); #endif return TRUE; } -static gboolean _lib_histogram_button_press_callback(GtkWidget *widget, GdkEventButton *event, - gpointer user_data) +static gboolean _lib_histogram_button_press_callback(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_histogram_t *d = (dt_lib_histogram_t *)self->data; @@ -622,8 +619,7 @@ static gboolean _lib_histogram_scroll_callback(GtkWidget *widget, GdkEventScroll return TRUE; } -static gboolean _lib_histogram_button_release_callback(GtkWidget *widget, GdkEventButton *event, - gpointer user_data) +static gboolean _lib_histogram_button_release_callback(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_histogram_t *d = (dt_lib_histogram_t *)self->data; @@ -631,15 +627,13 @@ static gboolean _lib_histogram_button_release_callback(GtkWidget *widget, GdkEve return TRUE; } -static gboolean _lib_histogram_enter_notify_callback(GtkWidget *widget, GdkEventCrossing *event, - gpointer user_data) +static gboolean _lib_histogram_enter_notify_callback(GtkWidget *widget, GdkEventCrossing *event, gpointer user_data) { dt_control_change_cursor(GDK_HAND1); return TRUE; } -static gboolean _lib_histogram_leave_notify_callback(GtkWidget *widget, GdkEventCrossing *event, - gpointer user_data) +static gboolean _lib_histogram_leave_notify_callback(GtkWidget *widget, GdkEventCrossing *event, gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_histogram_t *d = (dt_lib_histogram_t *)self->data; diff --git a/src/libs/history.c b/src/libs/history.c index 5bbdce17a798..c3b308393cd9 100644 --- a/src/libs/history.c +++ b/src/libs/history.c @@ -43,7 +43,7 @@ typedef struct dt_lib_history_t /* vbox with managed history items */ GtkWidget *history_box; GtkWidget *create_button; -// GtkWidget *apply_button; + // GtkWidget *apply_button; GtkWidget *compress_button; gboolean record_undo; } dt_lib_history_t; @@ -65,7 +65,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"darkroom", NULL}; + static const char *v[] = { "darkroom", NULL }; return v; } @@ -82,7 +82,7 @@ int position() void init_key_accels(dt_lib_module_t *self) { dt_accel_register_lib(self, NC_("accel", "create style from history"), 0, 0); -// dt_accel_register_lib(self, NC_("accel", "apply style from popup menu"), 0, 0); + // dt_accel_register_lib(self, NC_("accel", "apply style from popup menu"), 0, 0); dt_accel_register_lib(self, NC_("accel", "compress history stack"), 0, 0); } @@ -91,7 +91,7 @@ void connect_key_accels(dt_lib_module_t *self) dt_lib_history_t *d = (dt_lib_history_t *)self->data; dt_accel_connect_button_lib(self, "create style from history", d->create_button); -// dt_accel_connect_button_lib(self, "apply style from popup menu", d->apply_button); + // dt_accel_connect_button_lib(self, "apply style from popup menu", d->apply_button); dt_accel_connect_button_lib(self, "compress history stack", d->compress_button); } @@ -109,10 +109,12 @@ void gui_init(dt_lib_module_t *self) GtkWidget *hhbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, DT_PIXEL_APPLY_DPI(5)); - d->compress_button = dtgtk_button_new(NULL, /*CPF_DO_NOT_USE_BORDER | CPF_STYLE_FLAT*/0); + d->compress_button = dtgtk_button_new(NULL, /*CPF_DO_NOT_USE_BORDER | CPF_STYLE_FLAT*/ 0); gtk_button_set_label(GTK_BUTTON(d->compress_button), _("compress history stack")); - gtk_widget_set_tooltip_text(d->compress_button, _("create a minimal history stack which produces the same image")); - g_signal_connect(G_OBJECT(d->compress_button), "clicked", G_CALLBACK(_lib_history_compress_clicked_callback), NULL); + gtk_widget_set_tooltip_text(d->compress_button, + _("create a minimal history stack which produces the same image")); + g_signal_connect(G_OBJECT(d->compress_button), "clicked", G_CALLBACK(_lib_history_compress_clicked_callback), + NULL); /* add toolbar button for creating style */ d->create_button = dtgtk_button_new(dtgtk_cairo_paint_styles, CPF_DO_NOT_USE_BORDER); @@ -147,8 +149,8 @@ void gui_cleanup(dt_lib_module_t *self) self->data = NULL; } -static GtkWidget *_lib_history_create_button(dt_lib_module_t *self, int num, const char *label, - gboolean enabled, gboolean selected) +static GtkWidget *_lib_history_create_button(dt_lib_module_t *self, int num, const char *label, gboolean enabled, + gboolean selected) { /* create label */ GtkWidget *widget = NULL; @@ -213,7 +215,7 @@ static dt_iop_module_t *get_base_module(dt_develop_t *dev, char *op) while(modules) { dt_iop_module_t *mod = (dt_iop_module_t *)modules->data; - if(strcmp(mod->op,op)==0) + if(strcmp(mod->op, op) == 0) { result = mod; break; @@ -226,11 +228,11 @@ static dt_iop_module_t *get_base_module(dt_develop_t *dev, char *op) static void _reset_module_instance(GList *hist, dt_iop_module_t *module, int multi_priority) { - while (hist) + while(hist) { dt_dev_history_item_t *hit = (dt_dev_history_item_t *)hist->data; - if (!hit->module && strcmp(hit->multi_name,module->op)==0 && hit->multi_priority==multi_priority) + if(!hit->module && strcmp(hit->multi_name, module->op) == 0 && hit->multi_priority == multi_priority) { hit->module = module; snprintf(hit->multi_name, sizeof(hit->multi_name), "%s", module->multi_name); @@ -270,13 +272,13 @@ static void _pop_undo(gpointer user_data, dt_undo_type_t type, dt_undo_data_t *d GList *l = g_list_first(darktable.develop->history); gboolean done = FALSE; - while (l) + while(l) { GList *next = g_list_next(l); dt_dev_history_item_t *hitem = (dt_dev_history_item_t *)l->data; // this fixes the duplicate module when undo: hitem->multi_priority = 0; - if (hitem->module == NULL) + if(hitem->module == NULL) { const dt_iop_module_t *base = get_base_module(darktable.develop, hitem->multi_name); @@ -325,7 +327,7 @@ static void _pop_undo(gpointer user_data, dt_undo_type_t type, dt_undo_data_t *d // if not already done, set the module to all others same instance - if (!done) + if(!done) { GList *h = g_list_first(darktable.develop->history); _reset_module_instance(h, module, hitem->multi_priority); @@ -382,20 +384,20 @@ static void _lib_history_change_callback(gpointer instance, gpointer user_data) /* add default which always should be */ int num = -1; - gtk_box_pack_start(GTK_BOX(d->history_box), - _lib_history_create_button(self, num, _("original"), FALSE, darktable.develop->history_end == 0), + gtk_box_pack_start(GTK_BOX(d->history_box), _lib_history_create_button(self, num, _("original"), FALSE, + darktable.develop->history_end == 0), TRUE, TRUE, 0); num++; - if (d->record_undo == TRUE) + if(d->record_undo == TRUE) { /* record undo/redo history snapshot */ dt_undo_history_t *hist = malloc(sizeof(dt_undo_history_t)); hist->snapshot = _duplicate_history(darktable.develop->history); hist->end = darktable.develop->history_end; - dt_undo_record(darktable.undo, self, DT_UNDO_HISTORY, (dt_undo_data_t *)hist, - _pop_undo, _history_undo_data_free); + dt_undo_record(darktable.undo, self, DT_UNDO_HISTORY, (dt_undo_data_t *)hist, _pop_undo, + _history_undo_data_free); } else d->record_undo = TRUE; @@ -444,7 +446,8 @@ static void _lib_history_compress_clicked_callback(GtkWidget *widget, gpointer u DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "DELETE FROM main.history WHERE imgid = ?1 AND num " "NOT IN (SELECT MAX(num) FROM main.history WHERE " "imgid = ?1 AND num < ?2 GROUP BY operation, " - "multi_priority)", -1, &stmt, NULL); + "multi_priority)", + -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, darktable.develop->history_end); sqlite3_step(stmt); @@ -457,11 +460,11 @@ static void _lib_history_compress_clicked_callback(GtkWidget *widget, gpointer u // then we can get the item to select in the new clean-up history retrieve the position of the module // corresponding to the history end. DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT IFNULL(MAX(num)+1, 0) FROM main.history " - "WHERE imgid=?1", -1, &stmt, NULL); + "WHERE imgid=?1", + -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); - if (sqlite3_step(stmt) == SQLITE_ROW) - darktable.develop->history_end = sqlite3_column_int(stmt, 0); + if(sqlite3_step(stmt) == SQLITE_ROW) darktable.develop->history_end = sqlite3_column_int(stmt, 0); sqlite3_finalize(stmt); // select the new history end corresponding to the one before the history compression diff --git a/src/libs/image.c b/src/libs/image.c index 9cd209986672..5f734fcee9d4 100644 --- a/src/libs/image.c +++ b/src/libs/image.c @@ -42,8 +42,8 @@ DT_MODULE(1) typedef struct dt_lib_image_t { GtkWidget *rotate_cw_button, *rotate_ccw_button, *remove_button, *delete_button, *create_hdr_button, - *duplicate_button, *reset_button, *move_button, *copy_button, *group_button, *ungroup_button, - *cache_button, *uncache_button; + *duplicate_button, *reset_button, *move_button, *copy_button, *group_button, *ungroup_button, *cache_button, + *uncache_button; } dt_lib_image_t; const char *name(dt_lib_module_t *self) @@ -53,7 +53,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"lighttable", NULL}; + static const char *v[] = { "lighttable", NULL }; return v; } @@ -68,8 +68,8 @@ static void _group_helper_function(void) { int new_group_id = darktable.gui->expanded_group_id; sqlite3_stmt *stmt; - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT imgid FROM main.selected_images", -1, - &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT imgid FROM main.selected_images", -1, &stmt, + NULL); while(sqlite3_step(stmt) == SQLITE_ROW) { int id = sqlite3_column_int(stmt, 0); @@ -89,8 +89,8 @@ static void _group_helper_function(void) static void _ungroup_helper_function(void) { sqlite3_stmt *stmt; - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT imgid FROM main.selected_images", -1, - &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT imgid FROM main.selected_images", -1, &stmt, + NULL); while(sqlite3_step(stmt) == SQLITE_ROW) { int id = sqlite3_column_int(stmt, 0); @@ -134,26 +134,26 @@ static void button_clicked(GtkWidget *widget, gpointer user_data) dt_control_reset_local_copy_images(); } -static const char* _image_get_delete_button_label() +static const char *_image_get_delete_button_label() { -if (dt_conf_get_bool("send_to_trash")) - return _("trash"); -else - return _("delete"); + if(dt_conf_get_bool("send_to_trash")) + return _("trash"); + else + return _("delete"); } -static const char* _image_get_delete_button_tooltip() +static const char *_image_get_delete_button_tooltip() { -if (dt_conf_get_bool("send_to_trash")) - return _("send file to trash"); -else - return _("physically delete from disk"); + if(dt_conf_get_bool("send_to_trash")) + return _("send file to trash"); + else + return _("physically delete from disk"); } static void _image_preference_changed(gpointer instance, gpointer user_data) { - dt_lib_module_t *self = (dt_lib_module_t*)user_data; + dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_image_t *d = (dt_lib_image_t *)self->data; gtk_button_set_label(GTK_BUTTON(d->delete_button), _image_get_delete_button_label()); gtk_widget_set_tooltip_text(d->delete_button, _image_get_delete_button_tooltip()); @@ -164,7 +164,8 @@ int position() return 700; } -#define ellipsize_button(button) gtk_label_set_ellipsize(GTK_LABEL(gtk_bin_get_child(GTK_BIN(button))), PANGO_ELLIPSIZE_END); +#define ellipsize_button(button) \ + gtk_label_set_ellipsize(GTK_LABEL(gtk_bin_get_child(GTK_BIN(button))), PANGO_ELLIPSIZE_END); void gui_init(dt_lib_module_t *self) { dt_lib_image_t *d = (dt_lib_image_t *)malloc(sizeof(dt_lib_image_t)); @@ -273,11 +274,8 @@ void gui_init(dt_lib_module_t *self) g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(button_clicked), GINT_TO_POINTER(11)); /* connect preference changed signal */ - dt_control_signal_connect( - darktable.signals, - DT_SIGNAL_PREFERENCES_CHANGE, - G_CALLBACK(_image_preference_changed), - (gpointer)self); + dt_control_signal_connect(darktable.signals, DT_SIGNAL_PREFERENCES_CHANGE, G_CALLBACK(_image_preference_changed), + (gpointer)self); } #undef ellipsize_button @@ -320,20 +318,21 @@ void connect_key_accels(dt_lib_module_t *self) } #ifdef USE_LUA -typedef struct { - const char* key; - dt_lib_module_t * self; +typedef struct +{ + const char *key; + dt_lib_module_t *self; } lua_callback_data; -static int lua_button_clicked_cb(lua_State* L) +static int lua_button_clicked_cb(lua_State *L) { - lua_callback_data * data = lua_touserdata(L,1); - dt_lua_module_entry_push(L,"lib",data->self->plugin_name); - lua_getuservalue(L,-1); - lua_getfield(L,-1,"callbacks"); - lua_getfield(L,-1,data->key); - lua_pushstring(L,data->key); + lua_callback_data *data = lua_touserdata(L, 1); + dt_lua_module_entry_push(L, "lib", data->self->plugin_name); + lua_getuservalue(L, -1); + lua_getfield(L, -1, "callbacks"); + lua_getfield(L, -1, data->key); + lua_pushstring(L, data->key); GList *image = dt_collection_get_selected(darktable.collection, -1); lua_newtable(L); @@ -344,41 +343,40 @@ static int lua_button_clicked_cb(lua_State* L) image = g_list_delete_link(image, image); } - lua_call(L,2,0); + lua_call(L, 2, 0); return 0; } static void lua_button_clicked(GtkWidget *widget, gpointer user_data) { - dt_lua_async_call_alien(lua_button_clicked_cb, - 0,NULL,NULL, - LUA_ASYNC_TYPENAME,"void*", user_data, - LUA_ASYNC_DONE); + dt_lua_async_call_alien(lua_button_clicked_cb, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "void*", user_data, + LUA_ASYNC_DONE); } static int lua_register_action(lua_State *L) { - lua_settop(L,3); + lua_settop(L, 3); dt_lib_module_t *self = lua_touserdata(L, lua_upvalueindex(1)); - dt_lua_module_entry_push(L,"lib",self->plugin_name); - lua_getuservalue(L,-1); - const char* key = luaL_checkstring(L,1); - luaL_checktype(L,2,LUA_TFUNCTION); - - lua_getfield(L,-1,"callbacks"); - lua_pushstring(L,key); - lua_pushvalue(L,2); - lua_settable(L,-3); - - GtkWidget* button = gtk_button_new_with_label(key); - const char * tooltip = lua_tostring(L,3); - if(tooltip) { + dt_lua_module_entry_push(L, "lib", self->plugin_name); + lua_getuservalue(L, -1); + const char *key = luaL_checkstring(L, 1); + luaL_checktype(L, 2, LUA_TFUNCTION); + + lua_getfield(L, -1, "callbacks"); + lua_pushstring(L, key); + lua_pushvalue(L, 2); + lua_settable(L, -3); + + GtkWidget *button = gtk_button_new_with_label(key); + const char *tooltip = lua_tostring(L, 3); + if(tooltip) + { gtk_widget_set_tooltip_text(button, tooltip); } gtk_grid_attach_next_to(GTK_GRID(self->widget), button, NULL, GTK_POS_BOTTOM, 4, 1); - lua_callback_data * data = malloc(sizeof(lua_callback_data)); + lua_callback_data *data = malloc(sizeof(lua_callback_data)); data->key = strdup(key); data->self = self; g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(lua_button_clicked), data); @@ -392,16 +390,16 @@ void init(struct dt_lib_module_t *self) lua_State *L = darktable.lua_state.state; int my_type = dt_lua_module_entry_get_type(L, "lib", self->plugin_name); lua_pushlightuserdata(L, self); - lua_pushcclosure(L, lua_register_action,1); + lua_pushcclosure(L, lua_register_action, 1); dt_lua_gtk_wrap(L); lua_pushcclosure(L, dt_lua_type_member_common, 1); dt_lua_type_register_const_type(L, my_type, "register_action"); - dt_lua_module_entry_push(L,"lib",self->plugin_name); - lua_getuservalue(L,-1); + dt_lua_module_entry_push(L, "lib", self->plugin_name); + lua_getuservalue(L, -1); lua_newtable(L); - lua_setfield(L,-2,"callbacks"); - lua_pop(L,2); + lua_setfield(L, -2, "callbacks"); + lua_pop(L, 2); } #endif // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh diff --git a/src/libs/import.c b/src/libs/import.c index 59ae46db5eb7..e1eeb7090e4a 100644 --- a/src/libs/import.c +++ b/src/libs/import.c @@ -109,7 +109,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"lighttable", NULL}; + static const char *v[] = { "lighttable", NULL }; return v; } @@ -223,8 +223,7 @@ void _lib_import_ui_devices_update(dt_lib_module_t *self) } else { - snprintf(buffer, sizeof(buffer), _("device \"%s\" connected on port \"%s\"."), camera->model, - camera->port); + snprintf(buffer, sizeof(buffer), _("device \"%s\" connected on port \"%s\"."), camera->model, camera->port); gtk_widget_set_tooltip_text(label, buffer); } @@ -233,14 +232,13 @@ void _lib_import_ui_devices_update(dt_lib_module_t *self) GtkWidget *vbx = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); if(camera->can_import == TRUE) { - gtk_box_pack_start(GTK_BOX(vbx), (ib = gtk_button_new_with_label(_("import from camera"))), FALSE, - FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbx), (ib = gtk_button_new_with_label(_("import from camera"))), FALSE, FALSE, + 0); d->import_camera = GTK_BUTTON(ib); } if(camera->can_tether == TRUE) { - gtk_box_pack_start(GTK_BOX(vbx), (tb = gtk_button_new_with_label(_("tethered shoot"))), FALSE, FALSE, - 0); + gtk_box_pack_start(GTK_BOX(vbx), (tb = gtk_button_new_with_label(_("tethered shoot"))), FALSE, FALSE, 0); d->tethered_shoot = GTK_BUTTON(tb); } @@ -307,11 +305,11 @@ static gboolean _camctl_camera_control_status_callback_gui_thread(gpointer user_ GList *list, *child; list = child = gtk_container_get_children(GTK_CONTAINER(d->devices)); if(child) do - { - if(!(GTK_IS_TOGGLE_BUTTON(child->data) - && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(child->data)) == TRUE)) - gtk_widget_set_sensitive(GTK_WIDGET(child->data), FALSE); - } while((child = g_list_next(child))); + { + if(!(GTK_IS_TOGGLE_BUTTON(child->data) + && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(child->data)) == TRUE)) + gtk_widget_set_sensitive(GTK_WIDGET(child->data), FALSE); + } while((child = g_list_next(child))); g_list_free(list); } break; @@ -322,9 +320,9 @@ static gboolean _camctl_camera_control_status_callback_gui_thread(gpointer user_ GList *list, *child; list = child = gtk_container_get_children(GTK_CONTAINER(d->devices)); if(child) do - { - gtk_widget_set_sensitive(GTK_WIDGET(child->data), TRUE); - } while((child = g_list_next(child))); + { + gtk_widget_set_sensitive(GTK_WIDGET(child->data), TRUE); + } while((child = g_list_next(child))); g_list_free(list); } break; @@ -399,13 +397,11 @@ static void _lib_import_presets_changed(GtkWidget *widget, dt_lib_import_metadat } #ifdef USE_LUA -static void reset_child(GtkWidget* child, gpointer user_data) +static void reset_child(GtkWidget *child, gpointer user_data) { - dt_lua_async_call_alien(dt_lua_widget_trigger_callback, - 0,NULL,NULL, - LUA_ASYNC_TYPENAME,"lua_widget",child, // the GtkWidget is an alias for the lua_widget - LUA_ASYNC_TYPENAME,"const char*","reset", - LUA_ASYNC_DONE); + dt_lua_async_call_alien(dt_lua_widget_trigger_callback, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "lua_widget", + child, // the GtkWidget is an alias for the lua_widget + LUA_ASYNC_TYPENAME, "const char*", "reset", LUA_ASYNC_DONE); } // remove the extra portion from the filechooser before destroying it @@ -418,11 +414,11 @@ static void detach_lua_widgets(GtkWidget *extra_lua_widgets) static void _check_button_callback(GtkWidget *widget, gpointer data) { - dt_conf_set_bool("ui_last/import_ignore_jpegs", - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))); + dt_conf_set_bool("ui_last/import_ignore_jpegs", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))); } -static GtkWidget *_lib_import_get_extra_widget(dt_lib_module_t *self,dt_lib_import_metadata_t *data, gboolean import_folder) +static GtkWidget *_lib_import_get_extra_widget(dt_lib_module_t *self, dt_lib_import_metadata_t *data, + gboolean import_folder) { // add extra lines to 'extra'. don't forget to destroy the widgets later. GtkWidget *expander = gtk_expander_new(_("import options")); @@ -464,11 +460,9 @@ static GtkWidget *_lib_import_get_extra_widget(dt_lib_module_t *self,dt_lib_impo ignore_jpeg = gtk_check_button_new_with_label(_("ignore JPEG files")); gtk_widget_set_tooltip_text(ignore_jpeg, _("do not load files with an extension of .jpg or .jpeg. this " "can be useful when there are raw+JPEG in a directory.")); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ignore_jpeg), - dt_conf_get_bool("ui_last/import_ignore_jpegs")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ignore_jpeg), dt_conf_get_bool("ui_last/import_ignore_jpegs")); gtk_box_pack_start(GTK_BOX(extra), ignore_jpeg, FALSE, FALSE, 0); - g_signal_connect(G_OBJECT(ignore_jpeg), "clicked", - G_CALLBACK(_check_button_callback), ignore_jpeg); + g_signal_connect(G_OBJECT(ignore_jpeg), "clicked", G_CALLBACK(_check_button_callback), ignore_jpeg); } // default metadata @@ -494,13 +488,13 @@ static GtkWidget *_lib_import_get_extra_widget(dt_lib_module_t *self,dt_lib_impo grid = gtk_grid_new(); gtk_grid_set_row_spacing(GTK_GRID(grid), DT_PIXEL_APPLY_DPI(5)); gtk_grid_set_column_spacing(GTK_GRID(grid), DT_PIXEL_APPLY_DPI(10)); - gtk_widget_set_margin_start(grid, 2 * (indicator_spacing + indicator_size)); + gtk_widget_set_margin_start(grid, 2 * (indicator_spacing + indicator_size)); gtk_box_pack_start(GTK_BOX(extra), grid, FALSE, FALSE, 0); #ifdef USE_LUA dt_lib_import_t *d = (dt_lib_import_t *)self->data; - gtk_box_pack_start(GTK_BOX(extra),d->extra_lua_widgets , FALSE, FALSE, 0); - gtk_container_foreach(GTK_CONTAINER(d->extra_lua_widgets),reset_child,NULL); + gtk_box_pack_start(GTK_BOX(extra), d->extra_lua_widgets, FALSE, FALSE, 0); + gtk_container_foreach(GTK_CONTAINER(d->extra_lua_widgets), reset_child, NULL); #endif creator = gtk_entry_new(); @@ -613,7 +607,8 @@ static GtkWidget *_lib_import_get_extra_widget(dt_lib_module_t *self,dt_lib_impo } g_signal_connect(apply_metadata, "toggled", G_CALLBACK(_lib_import_apply_metadata_toggled), grid); - // needed since the apply_metadata starts being turned off, and setting it to off doesn't emit the 'toggled' signal ... + // needed since the apply_metadata starts being turned off, and setting it to off doesn't emit the 'toggled' + // signal ... _lib_import_apply_metadata_toggled(apply_metadata, grid); g_signal_connect(presets, "changed", G_CALLBACK(_lib_import_presets_changed), data); @@ -628,8 +623,7 @@ static void _lib_import_evaluate_extra_widget(dt_lib_import_metadata_t *data, gb { if(import_folder == TRUE) { - dt_conf_set_bool("ui_last/import_recursive", - gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->recursive))); + dt_conf_set_bool("ui_last/import_recursive", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->recursive))); dt_conf_set_bool("ui_last/import_ignore_jpegs", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->ignore_jpeg))); } @@ -679,8 +673,8 @@ static void _lib_import_update_preview(GtkFileChooser *file_chooser, gpointer da // Scale the image to the correct size GdkPixbuf *tmp; GdkPixbufLoader *loader = gdk_pixbuf_loader_new(); - if (!gdk_pixbuf_loader_write(loader, buffer, size, NULL)) goto cleanup; - if (!(tmp = gdk_pixbuf_loader_get_pixbuf(loader))) goto cleanup; + if(!gdk_pixbuf_loader_write(loader, buffer, size, NULL)) goto cleanup; + if(!(tmp = gdk_pixbuf_loader_get_pixbuf(loader))) goto cleanup; float ratio = 1.0 * gdk_pixbuf_get_height(tmp) / gdk_pixbuf_get_width(tmp); int width = 128, height = 128 * ratio; pixbuf = gdk_pixbuf_scale_simple(tmp, width, height, GDK_INTERP_BILINEAR); @@ -749,11 +743,11 @@ static void _lib_import_update_preview(GtkFileChooser *file_chooser, gpointer da static void _lib_import_single_image_callback(GtkWidget *widget, gpointer user_data) { - dt_lib_module_t* self = (dt_lib_module_t*)user_data; + dt_lib_module_t *self = (dt_lib_module_t *)user_data; GtkWidget *win = dt_ui_main_window(darktable.gui->ui); - GtkWidget *filechooser = gtk_file_chooser_dialog_new( - _("import image"), GTK_WINDOW(win), GTK_FILE_CHOOSER_ACTION_OPEN, _("_cancel"), GTK_RESPONSE_CANCEL, - _("_open"), GTK_RESPONSE_ACCEPT, (char *)NULL); + GtkWidget *filechooser + = gtk_file_chooser_dialog_new(_("import image"), GTK_WINDOW(win), GTK_FILE_CHOOSER_ACTION_OPEN, _("_cancel"), + GTK_RESPONSE_CANCEL, _("_open"), GTK_RESPONSE_ACCEPT, (char *)NULL); #ifdef GDK_WINDOWING_QUARTZ dt_osx_disallow_fullscreen(filechooser); #endif @@ -856,11 +850,11 @@ static void _lib_import_single_image_callback(GtkWidget *widget, gpointer user_d static void _lib_import_folder_callback(GtkWidget *widget, gpointer user_data) { - dt_lib_module_t* self= (dt_lib_module_t*) user_data; + dt_lib_module_t *self = (dt_lib_module_t *)user_data; GtkWidget *win = dt_ui_main_window(darktable.gui->ui); GtkWidget *filechooser = gtk_file_chooser_dialog_new( - _("import film"), GTK_WINDOW(win), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, _("_cancel"), - GTK_RESPONSE_CANCEL, _("_open"), GTK_RESPONSE_ACCEPT, (char *)NULL); + _("import film"), GTK_WINDOW(win), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, _("_cancel"), GTK_RESPONSE_CANCEL, + _("_open"), GTK_RESPONSE_ACCEPT, (char *)NULL); #ifdef GDK_WINDOWING_QUARTZ dt_osx_disallow_fullscreen(filechooser); #endif @@ -946,9 +940,9 @@ static int lua_register_widget(lua_State *L) dt_lib_module_t *self = lua_touserdata(L, lua_upvalueindex(1)); dt_lib_import_t *d = (dt_lib_import_t *)self->data; lua_widget widget; - luaA_to(L,lua_widget,&widget,1); - dt_lua_widget_bind(L,widget); - gtk_box_pack_start(GTK_BOX(d->extra_lua_widgets),widget->widget, TRUE, TRUE, 0); + luaA_to(L, lua_widget, &widget, 1); + dt_lua_widget_bind(L, widget); + gtk_box_pack_start(GTK_BOX(d->extra_lua_widgets), widget->widget, TRUE, TRUE, 0); return 0; } @@ -957,8 +951,8 @@ void init(dt_lib_module_t *self) { lua_State *L = darktable.lua_state.state; int my_type = dt_lua_module_entry_get_type(L, "lib", self->plugin_name); - lua_pushlightuserdata(L,self); - lua_pushcclosure(L, lua_register_widget,1); + lua_pushlightuserdata(L, self); + lua_pushcclosure(L, lua_register_widget, 1); dt_lua_gtk_wrap(L); lua_pushcclosure(L, dt_lua_type_member_common, 1); dt_lua_type_register_const_type(L, my_type, "register_widget"); @@ -1012,12 +1006,11 @@ void gui_init(dt_lib_module_t *self) d->camctl_listener.control_status = _camctl_camera_control_status_callback; d->camctl_listener.camera_disconnected = _camctl_camera_disconnected_callback; dt_camctl_register_listener(darktable.camctl, &d->camctl_listener); - dt_control_signal_connect(darktable.signals, DT_SIGNAL_CAMERA_DETECTED, G_CALLBACK(_camera_detected), - self); + dt_control_signal_connect(darktable.signals, DT_SIGNAL_CAMERA_DETECTED, G_CALLBACK(_camera_detected), self); #endif #ifdef USE_LUA /* initialize the lua area and make sure it survives its parent's destruction*/ - d->extra_lua_widgets = gtk_box_new(GTK_ORIENTATION_VERTICAL,5); + d->extra_lua_widgets = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); g_object_ref_sink(d->extra_lua_widgets); #endif } diff --git a/src/libs/lib.c b/src/libs/lib.c index 9f5bb32c992a..aabcefcf80a5 100644 --- a/src/libs/lib.c +++ b/src/libs/lib.c @@ -562,8 +562,7 @@ static int dt_lib_load_module(void *m, const char *libname, const char *plugin_n module->expandable = _lib_default_expandable; if(!g_module_symbol(module->module, "init", (gpointer) & (module->init))) module->init = NULL; - if(!g_module_symbol(module->module, "gui_reset", (gpointer) & (module->gui_reset))) - module->gui_reset = NULL; + if(!g_module_symbol(module->module, "gui_reset", (gpointer) & (module->gui_reset))) module->gui_reset = NULL; if(!g_module_symbol(module->module, "gui_init", (gpointer) & (module->gui_init))) goto error; if(!g_module_symbol(module->module, "gui_cleanup", (gpointer) & (module->gui_cleanup))) goto error; @@ -581,8 +580,7 @@ static int dt_lib_load_module(void *m, const char *libname, const char *plugin_n module->button_released = NULL; if(!g_module_symbol(module->module, "button_pressed", (gpointer) & (module->button_pressed))) module->button_pressed = NULL; - if(!g_module_symbol(module->module, "configure", (gpointer) & (module->configure))) - module->configure = NULL; + if(!g_module_symbol(module->module, "configure", (gpointer) & (module->configure))) module->configure = NULL; if(!g_module_symbol(module->module, "scrolled", (gpointer) & (module->scrolled))) module->scrolled = NULL; if(!g_module_symbol(module->module, "position", (gpointer) & (module->position))) module->position = NULL; if(!g_module_symbol(module->module, "legacy_params", (gpointer) & (module->legacy_params))) @@ -626,9 +624,8 @@ static int dt_lib_load_module(void *m, const char *libname, const char *plugin_n return 1; } -static void *_update_params(dt_lib_module_t *module, - const void *const old_params, size_t old_params_size, int old_version, - int target_version, size_t *new_size) +static void *_update_params(dt_lib_module_t *module, const void *const old_params, size_t old_params_size, + int old_version, int target_version, size_t *new_size) { // make a copy of the old params so we can free it in the loop void *params = malloc(old_params_size); @@ -692,12 +689,11 @@ void dt_lib_init_presets(dt_lib_module_t *module) size_t new_params_size = 0; void *new_params = NULL; - if(module->legacy_params - && (new_params = _update_params(module, op_params, op_params_size, op_version, version, &new_params_size))) + if(module->legacy_params && (new_params = _update_params(module, op_params, op_params_size, op_version, + version, &new_params_size))) { // write the updated preset back to db - fprintf(stderr, - "[lighttable_init_presets] updating '%s' preset '%s' from version %d to version %d\n", + fprintf(stderr, "[lighttable_init_presets] updating '%s' preset '%s' from version %d to version %d\n", module->plugin_name, name, op_version, version); sqlite3_stmt *innerstmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), @@ -979,8 +975,7 @@ GtkWidget *dt_lib_gui_get_expander(dt_lib_module_t *module) GtkWidget *pluginui_frame = dtgtk_expander_get_frame(DTGTK_EXPANDER(expander)); /* setup the header box */ - g_signal_connect(G_OBJECT(header_evb), "button-press-event", G_CALLBACK(_lib_plugin_header_button_press), - module); + g_signal_connect(G_OBJECT(header_evb), "button-press-event", G_CALLBACK(_lib_plugin_header_button_press), module); /* setup plugin content frame */ gtk_frame_set_shadow_type(GTK_FRAME(pluginui_frame), GTK_SHADOW_IN); @@ -1078,7 +1073,7 @@ void dt_lib_cleanup(dt_lib_t *lib) while(lib->plugins) { dt_lib_module_t *module = (dt_lib_module_t *)(lib->plugins->data); - if(module) + if(module) { if(module->data != NULL) { @@ -1154,8 +1149,7 @@ void dt_lib_set_visible(dt_lib_module_t *module, gboolean visible) void dt_lib_connect_common_accels(dt_lib_module_t *module) { - if(module->reset_button) - dt_accel_connect_button_lib(module, "reset module parameters", module->reset_button); + if(module->reset_button) dt_accel_connect_button_lib(module, "reset module parameters", module->reset_button); if(module->presets_button) dt_accel_connect_button_lib(module, "show preset menu", module->presets_button); if(module->init_presets) { diff --git a/src/libs/lib.h b/src/libs/lib.h index e3e62ca26be4..4066b5e3cff6 100644 --- a/src/libs/lib.h +++ b/src/libs/lib.h @@ -108,9 +108,9 @@ typedef struct dt_lib_module_t void (*gui_reset)(struct dt_lib_module_t *self); /** entering a view, only called if lib is displayed on the new view */ - void (*view_enter)(struct dt_lib_module_t *self,struct dt_view_t *old_view,struct dt_view_t *new_view); + void (*view_enter)(struct dt_lib_module_t *self, struct dt_view_t *old_view, struct dt_view_t *new_view); /** entering a view, only called if lib is displayed on the old view */ - void (*view_leave)(struct dt_lib_module_t *self,struct dt_view_t *old_view,struct dt_view_t *new_view); + void (*view_leave)(struct dt_lib_module_t *self, struct dt_view_t *old_view, struct dt_view_t *new_view); /** optional event callbacks for big center widget. */ /** optional method called after lighttable expose. */ @@ -119,15 +119,15 @@ typedef struct dt_lib_module_t int (*mouse_leave)(struct dt_lib_module_t *self); int (*mouse_moved)(struct dt_lib_module_t *self, double x, double y, double pressure, int which); int (*button_released)(struct dt_lib_module_t *self, double x, double y, int which, uint32_t state); - int (*button_pressed)(struct dt_lib_module_t *self, double x, double y, double pressure, int which, - int type, uint32_t state); + int (*button_pressed)(struct dt_lib_module_t *self, double x, double y, double pressure, int which, int type, + uint32_t state); int (*scrolled)(struct dt_lib_module_t *self, double x, double y, int up); void (*configure)(struct dt_lib_module_t *self, int width, int height); int (*position)(const struct dt_lib_module_t *self); /** implement these three if you want customizable presets to be stored in db. */ /** legacy_params can run in iterations, just return to what version you updated the preset. */ - void *(*legacy_params)(struct dt_lib_module_t *self, const void *const old_params, - const size_t old_params_size, const int old_version, int *new_version, size_t *new_size); + void *(*legacy_params)(struct dt_lib_module_t *self, const void *const old_params, const size_t old_params_size, + const int old_version, int *new_version, size_t *new_size); void *(*get_params)(struct dt_lib_module_t *self, int *size); int (*set_params)(struct dt_lib_module_t *self, const void *params, int size); void (*init_presets)(struct dt_lib_module_t *self); diff --git a/src/libs/lib_api.h b/src/libs/lib_api.h index 512e004441dd..9efbe900f216 100644 --- a/src/libs/lib_api.h +++ b/src/libs/lib_api.h @@ -68,8 +68,8 @@ void view_leave(struct dt_lib_module_t *self, struct dt_view_t *old_view, struct /** optional event callbacks for big center widget. */ /** optional method called after lighttable expose. */ -void gui_post_expose(struct dt_lib_module_t *self, cairo_t *cr, int32_t width, int32_t height, - int32_t pointerx, int32_t pointery); +void gui_post_expose(struct dt_lib_module_t *self, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, + int32_t pointery); int mouse_leave(struct dt_lib_module_t *self); int mouse_moved(struct dt_lib_module_t *self, double x, double y, double pressure, int which); int button_released(struct dt_lib_module_t *self, double x, double y, int which, uint32_t state); diff --git a/src/libs/live_view.c b/src/libs/live_view.c index 1789fbb264e9..4c8636f61b73 100644 --- a/src/libs/live_view.c +++ b/src/libs/live_view.c @@ -36,9 +36,9 @@ typedef enum dt_lib_live_view_flip_t { FLAG_FLIP_NONE = 0, - FLAG_FLIP_HORIZONTAL = 1<<0, - FLAG_FLIP_VERTICAL = 1<<1, - FLAG_FLIP_BOTH = FLAG_FLIP_HORIZONTAL|FLAG_FLIP_VERTICAL + FLAG_FLIP_HORIZONTAL = 1 << 0, + FLAG_FLIP_VERTICAL = 1 << 1, + FLAG_FLIP_BOTH = FLAG_FLIP_HORIZONTAL | FLAG_FLIP_VERTICAL } dt_lib_live_view_flip_t; typedef enum dt_lib_live_view_overlay_t @@ -50,16 +50,16 @@ typedef enum dt_lib_live_view_overlay_t #define HANDLE_SIZE 0.02 -static const cairo_operator_t _overlay_modes[] = { - CAIRO_OPERATOR_OVER, CAIRO_OPERATOR_XOR, CAIRO_OPERATOR_ADD, CAIRO_OPERATOR_SATURATE +static const cairo_operator_t _overlay_modes[] + = { CAIRO_OPERATOR_OVER, CAIRO_OPERATOR_XOR, CAIRO_OPERATOR_ADD, CAIRO_OPERATOR_SATURATE #if(CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 10, 0)) - , - CAIRO_OPERATOR_MULTIPLY, CAIRO_OPERATOR_SCREEN, CAIRO_OPERATOR_OVERLAY, CAIRO_OPERATOR_DARKEN, - CAIRO_OPERATOR_LIGHTEN, CAIRO_OPERATOR_COLOR_DODGE, CAIRO_OPERATOR_COLOR_BURN, CAIRO_OPERATOR_HARD_LIGHT, - CAIRO_OPERATOR_SOFT_LIGHT, CAIRO_OPERATOR_DIFFERENCE, CAIRO_OPERATOR_EXCLUSION, CAIRO_OPERATOR_HSL_HUE, - CAIRO_OPERATOR_HSL_SATURATION, CAIRO_OPERATOR_HSL_COLOR, CAIRO_OPERATOR_HSL_LUMINOSITY + , + CAIRO_OPERATOR_MULTIPLY, CAIRO_OPERATOR_SCREEN, CAIRO_OPERATOR_OVERLAY, CAIRO_OPERATOR_DARKEN, + CAIRO_OPERATOR_LIGHTEN, CAIRO_OPERATOR_COLOR_DODGE, CAIRO_OPERATOR_COLOR_BURN, CAIRO_OPERATOR_HARD_LIGHT, + CAIRO_OPERATOR_SOFT_LIGHT, CAIRO_OPERATOR_DIFFERENCE, CAIRO_OPERATOR_EXCLUSION, CAIRO_OPERATOR_HSL_HUE, + CAIRO_OPERATOR_HSL_SATURATION, CAIRO_OPERATOR_HSL_COLOR, CAIRO_OPERATOR_HSL_LUMINOSITY #endif -}; + }; DT_MODULE(1) @@ -142,7 +142,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"tethering", NULL}; + static const char *v[] = { "tethering", NULL }; return v; } @@ -278,10 +278,10 @@ void gui_init(dt_lib_module_t *self) lib->live_view_zoom = dtgtk_button_new( dtgtk_cairo_paint_zoom, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); // TODO: see _zoom_live_view_clicked lib->rotate_ccw = dtgtk_button_new(dtgtk_cairo_paint_refresh, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); - lib->rotate_cw = dtgtk_button_new(dtgtk_cairo_paint_refresh, - CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER | CPF_DIRECTION_UP); - lib->flip = dtgtk_togglebutton_new(dtgtk_cairo_paint_flip, - CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER | CPF_DIRECTION_UP); + lib->rotate_cw + = dtgtk_button_new(dtgtk_cairo_paint_refresh, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER | CPF_DIRECTION_UP); + lib->flip + = dtgtk_togglebutton_new(dtgtk_cairo_paint_flip, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER | CPF_DIRECTION_UP); gtk_box_pack_start(GTK_BOX(box), lib->live_view, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(box), lib->live_view_zoom, TRUE, TRUE, 0); @@ -307,10 +307,10 @@ void gui_init(dt_lib_module_t *self) lib->focus_in_big = dtgtk_button_new(dtgtk_cairo_paint_solid_triangle, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER | CPF_DIRECTION_LEFT); lib->focus_in_small - = dtgtk_button_new(dtgtk_cairo_paint_arrow, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER - | CPF_DIRECTION_LEFT); // TODO icon not centered + = dtgtk_button_new(dtgtk_cairo_paint_arrow, + CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER | CPF_DIRECTION_LEFT); // TODO icon not centered lib->focus_out_small = dtgtk_button_new(dtgtk_cairo_paint_arrow, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER - | CPF_DIRECTION_RIGHT); // TODO same here + | CPF_DIRECTION_RIGHT); // TODO same here lib->focus_out_big = dtgtk_button_new(dtgtk_cairo_paint_solid_triangle, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER | CPF_DIRECTION_RIGHT); @@ -325,17 +325,14 @@ void gui_init(dt_lib_module_t *self) gtk_widget_set_tooltip_text(lib->focus_out_big, _("move focus point out (big steps)")); // Near 3 - g_signal_connect(G_OBJECT(lib->focus_in_big), "clicked", G_CALLBACK(_focus_button_clicked), - GINT_TO_POINTER(2)); + g_signal_connect(G_OBJECT(lib->focus_in_big), "clicked", G_CALLBACK(_focus_button_clicked), GINT_TO_POINTER(2)); // Near 1 - g_signal_connect(G_OBJECT(lib->focus_in_small), "clicked", G_CALLBACK(_focus_button_clicked), - GINT_TO_POINTER(0)); + g_signal_connect(G_OBJECT(lib->focus_in_small), "clicked", G_CALLBACK(_focus_button_clicked), GINT_TO_POINTER(0)); // Far 1 g_signal_connect(G_OBJECT(lib->focus_out_small), "clicked", G_CALLBACK(_focus_button_clicked), GINT_TO_POINTER(4)); // Far 3 - g_signal_connect(G_OBJECT(lib->focus_out_big), "clicked", G_CALLBACK(_focus_button_clicked), - GINT_TO_POINTER(6)); + g_signal_connect(G_OBJECT(lib->focus_out_big), "clicked", G_CALLBACK(_focus_button_clicked), GINT_TO_POINTER(6)); // Guides lib->guide_selector = dt_bauhaus_combobox_new(NULL); @@ -436,8 +433,7 @@ void gui_init(dt_lib_module_t *self) dt_bauhaus_combobox_add(lib->overlay_splitline, _("on")); gtk_widget_set_tooltip_text(lib->overlay_splitline, _("only draw part of the overlay")); dt_bauhaus_combobox_set(lib->overlay_splitline, dt_conf_get_int("plugins/lighttable/live_view/splitline")); - g_signal_connect(G_OBJECT(lib->overlay_splitline), "value-changed", G_CALLBACK(_overlay_splitline_changed), - lib); + g_signal_connect(G_OBJECT(lib->overlay_splitline), "value-changed", G_CALLBACK(_overlay_splitline_changed), lib); gtk_box_pack_start(GTK_BOX(self->widget), lib->overlay_splitline, TRUE, TRUE, 0); gtk_widget_set_visible(GTK_WIDGET(lib->overlay_mode), FALSE); @@ -462,7 +458,7 @@ void gui_cleanup(dt_lib_module_t *self) self->data = NULL; } -void view_enter(struct dt_lib_module_t *self,struct dt_view_t *old_view,struct dt_view_t *new_view) +void view_enter(struct dt_lib_module_t *self, struct dt_view_t *old_view, struct dt_view_t *new_view) { // disable buttons that won't work with this camera // TODO: initialize tethering mode outside of libs/camera.s so we can use darktable.camctl->active_camera @@ -539,8 +535,7 @@ void gui_post_expose(dt_lib_module_t *self, cairo_t *cr, int32_t width, int32_t if(buf.buf) { const int32_t stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, buf.width); - surface = cairo_image_surface_create_for_data(buf.buf, CAIRO_FORMAT_RGB24, buf.width, - buf.height, stride); + surface = cairo_image_surface_create_for_data(buf.buf, CAIRO_FORMAT_RGB24, buf.width, buf.height, stride); if(zoom == 1) { scale = fminf(fminf(w, pw) / (float)buf.width, fminf(h, ph) / (float)buf.height); @@ -750,8 +745,7 @@ int button_pressed(struct dt_lib_module_t *self, double x, double y, double pres double sl_x = lib->overlay_x0 + lib->splitline_x * width; double sl_y = lib->overlay_y0 + lib->splitline_y * height; - gboolean mouse_over_control = (lib->splitline_rotation % 2 == 0) ? (fabs(sl_x - x) < 5) - : (fabs(sl_y - y) < 5); + gboolean mouse_over_control = (lib->splitline_rotation % 2 == 0) ? (fabs(sl_x - x) < 5) : (fabs(sl_y - y) < 5); /* do the split rotating */ if(which == 1 && fabs(sl_x - x) < 7 && fabs(sl_y - y) < 7) diff --git a/src/libs/location.c b/src/libs/location.c index 6a53c8c4d673..d324e7a24591 100644 --- a/src/libs/location.c +++ b/src/libs/location.c @@ -95,7 +95,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"map", NULL}; + static const char *v[] = { "map", NULL }; return v; } @@ -129,8 +129,7 @@ void gui_init(dt_lib_module_t *self) dt_gui_key_accel_block_on_focus_connect(GTK_WIDGET(lib->search)); gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(lib->search), FALSE, FALSE, 0); - g_signal_connect(G_OBJECT(lib->search), "activate", G_CALLBACK(_lib_location_entry_activated), - (gpointer)self); + g_signal_connect(G_OBJECT(lib->search), "activate", G_CALLBACK(_lib_location_entry_activated), (gpointer)self); /* add result vbox */ lib->result = gtk_box_new(GTK_ORIENTATION_VERTICAL, DT_PIXEL_APPLY_DPI(10)); @@ -322,8 +321,8 @@ static gboolean _lib_location_search(gpointer user_data) _clear_markers(lib); /* build the query url */ - query = dt_util_dstrcat(query, "http://nominatim.openstreetmap.org/search/%s?format=xml&limit=%d&polygon_text=1", text, - LIMIT_RESULT); + query = dt_util_dstrcat(query, "http://nominatim.openstreetmap.org/search/%s?format=xml&limit=%d&polygon_text=1", + text, LIMIT_RESULT); /* load url */ curl = curl_easy_init(); if(!curl) goto bail_out; @@ -467,13 +466,11 @@ static void _lib_location_parser_start_element(GMarkupParseContext *cxt, const c place->bbox_lat1 = lat1; place->bbox_lon2 = lon2; place->bbox_lat2 = lat2; -broken_bbox: + broken_bbox: ; } // only use the first 'geotext' entry - else if(show_outline && - strcmp(*aname, "geotext") == 0 && - place->marker_type == MAP_DISPLAY_NONE) + else if(show_outline && strcmp(*aname, "geotext") == 0 && place->marker_type == MAP_DISPLAY_NONE) { if(g_str_has_prefix(*avalue, "POINT")) { @@ -491,10 +488,9 @@ static void _lib_location_parser_start_element(GMarkupParseContext *cxt, const c } else if(g_str_has_prefix(*avalue, "LINESTRING") #ifdef HAVE_OSMGPSMAP_110_OR_NEWER - || g_str_has_prefix(*avalue, "POLYGON") - || g_str_has_prefix(*avalue, "MULTIPOLYGON") + || g_str_has_prefix(*avalue, "POLYGON") || g_str_has_prefix(*avalue, "MULTIPOLYGON") #endif - ) + ) { gboolean error = FALSE; const char *startptr = *avalue; @@ -518,7 +514,7 @@ static void _lib_location_parser_start_element(GMarkupParseContext *cxt, const c p->lon = lon; p->lat = lat; place->marker_points = g_list_append(place->marker_points, p); - startptr = endptr+1; + startptr = endptr + 1; i++; } diff --git a/src/libs/map_settings.c b/src/libs/map_settings.c index 19d29c5b19e1..cfaa6a5d130a 100644 --- a/src/libs/map_settings.c +++ b/src/libs/map_settings.c @@ -39,7 +39,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"map", NULL}; + static const char *v[] = { "map", NULL }; return v; } @@ -105,7 +105,8 @@ void gui_init(dt_lib_module_t *self) GtkListStore *model = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); d->map_source_dropdown = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model)); - gtk_widget_set_tooltip_text(d->map_source_dropdown, _("select the source of the map. some entries might not work")); + gtk_widget_set_tooltip_text(d->map_source_dropdown, + _("select the source of the map. some entries might not work")); GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(d->map_source_dropdown), renderer, FALSE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(d->map_source_dropdown), renderer, "text", 0, NULL); diff --git a/src/libs/masks.c b/src/libs/masks.c index df531accb3a3..5cc025007e74 100644 --- a/src/libs/masks.c +++ b/src/libs/masks.c @@ -58,7 +58,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"darkroom", NULL}; + static const char *v[] = { "darkroom", NULL }; return v; } @@ -362,8 +362,7 @@ static void _tree_inverse(GtkButton *button, dt_lib_module_t *self) pt->state &= ~DT_MASKS_STATE_INVERSE; else pt->state |= DT_MASKS_STATE_INVERSE; - _set_iter_name(lm, dt_masks_get_from_id(darktable.develop, id), pt->state, pt->opacity, model, - &iter); + _set_iter_name(lm, dt_masks_get_from_id(darktable.develop, id), pt->state, pt->opacity, model, &iter); change = 1; break; } @@ -428,8 +427,7 @@ static void _tree_intersection(GtkButton *button, dt_lib_module_t *self) else if(pt->state & DT_MASKS_STATE_EXCLUSION) pt->state &= ~DT_MASKS_STATE_EXCLUSION; pt->state |= DT_MASKS_STATE_INTERSECTION; - _set_iter_name(lm, dt_masks_get_from_id(darktable.develop, id), pt->state, pt->opacity, model, - &iter); + _set_iter_name(lm, dt_masks_get_from_id(darktable.develop, id), pt->state, pt->opacity, model, &iter); change = 1; } break; @@ -495,8 +493,7 @@ static void _tree_difference(GtkButton *button, dt_lib_module_t *self) else if(pt->state & DT_MASKS_STATE_EXCLUSION) pt->state &= ~DT_MASKS_STATE_EXCLUSION; pt->state |= DT_MASKS_STATE_DIFFERENCE; - _set_iter_name(lm, dt_masks_get_from_id(darktable.develop, id), pt->state, pt->opacity, model, - &iter); + _set_iter_name(lm, dt_masks_get_from_id(darktable.develop, id), pt->state, pt->opacity, model, &iter); change = 1; } break; @@ -562,8 +559,7 @@ static void _tree_exclusion(GtkButton *button, dt_lib_module_t *self) else if(pt->state & DT_MASKS_STATE_UNION) pt->state &= ~DT_MASKS_STATE_UNION; pt->state |= DT_MASKS_STATE_EXCLUSION; - _set_iter_name(lm, dt_masks_get_from_id(darktable.develop, id), pt->state, pt->opacity, model, - &iter); + _set_iter_name(lm, dt_masks_get_from_id(darktable.develop, id), pt->state, pt->opacity, model, &iter); change = 1; } break; @@ -629,8 +625,7 @@ static void _tree_union(GtkButton *button, dt_lib_module_t *self) else if(pt->state & DT_MASKS_STATE_EXCLUSION) pt->state &= ~DT_MASKS_STATE_EXCLUSION; pt->state |= DT_MASKS_STATE_UNION; - _set_iter_name(lm, dt_masks_get_from_id(darktable.develop, id), pt->state, pt->opacity, model, - &iter); + _set_iter_name(lm, dt_masks_get_from_id(darktable.develop, id), pt->state, pt->opacity, model, &iter); change = 1; } break; @@ -808,8 +803,7 @@ static void _tree_cell_editing_started(GtkCellRenderer *cell, GtkCellEditable *e { dt_control_key_accelerators_off(darktable.control); } -static void _tree_cell_edited(GtkCellRendererText *cell, gchar *path_string, gchar *new_text, - dt_lib_module_t *self) +static void _tree_cell_edited(GtkCellRendererText *cell, gchar *path_string, gchar *new_text, dt_lib_module_t *self) { dt_control_key_accelerators_on(darktable.control); dt_lib_masks_t *lm = (dt_lib_masks_t *)self->data; @@ -894,8 +888,7 @@ static void _tree_selection_change(GtkTreeSelection *selection, dt_lib_masks_t * gtk_tree_model_get_value(model, &iter, TREE_MODULE, &gv2); dt_iop_module_t *module = g_value_peek_pointer(&gv2); g_value_unset(&gv2); - if(module && (module->flags() & IOP_FLAGS_SUPPORTS_BLENDING) - && !(module->flags() & IOP_FLAGS_NO_MASKS)) + if(module && (module->flags() & IOP_FLAGS_SUPPORTS_BLENDING) && !(module->flags() & IOP_FLAGS_NO_MASKS)) { dt_iop_gui_blend_data_t *bd = (dt_iop_gui_blend_data_t *)module->blend_data; bd->masks_shown = 1; @@ -1220,8 +1213,8 @@ static gboolean _tree_restrict_select(GtkTreeSelection *selection, GtkTreeModel return TRUE; } -static gboolean _tree_query_tooltip(GtkWidget *widget, gint x, gint y, gboolean keyboard_tip, - GtkTooltip *tooltip, gpointer data) +static gboolean _tree_query_tooltip(GtkWidget *widget, gint x, gint y, gboolean keyboard_tip, GtkTooltip *tooltip, + gpointer data) { GtkTreeIter iter; GtkTreeView *tree_view = GTK_TREE_VIEW(widget); @@ -1318,11 +1311,10 @@ static void _lib_masks_list_recurs(GtkTreeStore *treestore, GtkTreeIter *topleve // we just add it to the tree GtkTreeIter child; gtk_tree_store_append(treestore, &child, toplevel); - gtk_tree_store_set(treestore, &child, TREE_TEXT, str, TREE_MODULE, module, TREE_GROUPID, grp_id, - TREE_FORMID, form->formid, TREE_EDITABLE, (grp_id == 0), TREE_IC_OP, icop, - TREE_IC_OP_VISIBLE, (icop != NULL), TREE_IC_INVERSE, icinv, TREE_IC_INVERSE_VISIBLE, - (icinv != NULL), TREE_IC_USED, icuse, TREE_IC_USED_VISIBLE, (nbuse > 0), - TREE_USED_TEXT, str2, -1); + gtk_tree_store_set(treestore, &child, TREE_TEXT, str, TREE_MODULE, module, TREE_GROUPID, grp_id, TREE_FORMID, + form->formid, TREE_EDITABLE, (grp_id == 0), TREE_IC_OP, icop, TREE_IC_OP_VISIBLE, + (icop != NULL), TREE_IC_INVERSE, icinv, TREE_IC_INVERSE_VISIBLE, (icinv != NULL), + TREE_IC_USED, icuse, TREE_IC_USED_VISIBLE, (nbuse > 0), TREE_USED_TEXT, str2, -1); _set_iter_name(lm, form, gstate, opacity, GTK_TREE_MODEL(treestore), &child); } else @@ -1347,11 +1339,10 @@ static void _lib_masks_list_recurs(GtkTreeStore *treestore, GtkTreeIter *topleve // we add the group node to the tree GtkTreeIter child; gtk_tree_store_append(treestore, &child, toplevel); - gtk_tree_store_set(treestore, &child, TREE_TEXT, str, TREE_MODULE, module, TREE_GROUPID, grp_id, - TREE_FORMID, form->formid, TREE_EDITABLE, (grp_id == 0), TREE_IC_OP, icop, - TREE_IC_OP_VISIBLE, (icop != NULL), TREE_IC_INVERSE, icinv, TREE_IC_INVERSE_VISIBLE, - (icinv != NULL), TREE_IC_USED, icuse, TREE_IC_USED_VISIBLE, (nbuse > 0), - TREE_USED_TEXT, str2, -1); + gtk_tree_store_set(treestore, &child, TREE_TEXT, str, TREE_MODULE, module, TREE_GROUPID, grp_id, TREE_FORMID, + form->formid, TREE_EDITABLE, (grp_id == 0), TREE_IC_OP, icop, TREE_IC_OP_VISIBLE, + (icop != NULL), TREE_IC_INVERSE, icinv, TREE_IC_INVERSE_VISIBLE, (icinv != NULL), + TREE_IC_USED, icuse, TREE_IC_USED_VISIBLE, (nbuse > 0), TREE_USED_TEXT, str2, -1); _set_iter_name(lm, form, gstate, opacity, GTK_TREE_MODEL(treestore), &child); // we add all nodes to the tree GList *forms = g_list_first(form->points); @@ -1359,8 +1350,7 @@ static void _lib_masks_list_recurs(GtkTreeStore *treestore, GtkTreeIter *topleve { dt_masks_point_group_t *grpt = (dt_masks_point_group_t *)forms->data; dt_masks_form_t *f = dt_masks_get_from_id(darktable.develop, grpt->formid); - if(f) - _lib_masks_list_recurs(treestore, &child, f, form->formid, module, grpt->state, grpt->opacity, lm); + if(f) _lib_masks_list_recurs(treestore, &child, f, form->formid, module, grpt->state, grpt->opacity, lm); forms = g_list_next(forms); } } @@ -1378,9 +1368,9 @@ static void _lib_masks_recreate_list(dt_lib_module_t *self) GtkTreeStore *treestore; // we store : text ; *module ; groupid ; formid - treestore = gtk_tree_store_new(TREE_COUNT, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_INT, - G_TYPE_BOOLEAN, GDK_TYPE_PIXBUF, G_TYPE_BOOLEAN, GDK_TYPE_PIXBUF, - G_TYPE_BOOLEAN, GDK_TYPE_PIXBUF, G_TYPE_BOOLEAN, G_TYPE_STRING); + treestore = gtk_tree_store_new(TREE_COUNT, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_INT, G_TYPE_BOOLEAN, + GDK_TYPE_PIXBUF, G_TYPE_BOOLEAN, GDK_TYPE_PIXBUF, G_TYPE_BOOLEAN, GDK_TYPE_PIXBUF, + G_TYPE_BOOLEAN, G_TYPE_STRING); // we first add all groups GList *forms = g_list_first(darktable.develop->forms); @@ -1649,16 +1639,14 @@ void gui_init(dt_lib_module_t *self) gtk_widget_set_size_request(GTK_WIDGET(d->bt_path), bs, bs); gtk_box_pack_end(GTK_BOX(hbox), d->bt_path, FALSE, FALSE, bs); - d->bt_ellipse - = dtgtk_togglebutton_new(dtgtk_cairo_paint_masks_ellipse, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); + d->bt_ellipse = dtgtk_togglebutton_new(dtgtk_cairo_paint_masks_ellipse, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); g_signal_connect(G_OBJECT(d->bt_ellipse), "button-press-event", G_CALLBACK(_bt_add_ellipse), self); gtk_widget_set_tooltip_text(d->bt_ellipse, _("add ellipse")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(d->bt_ellipse), FALSE); gtk_widget_set_size_request(GTK_WIDGET(d->bt_ellipse), bs, bs); gtk_box_pack_end(GTK_BOX(hbox), d->bt_ellipse, FALSE, FALSE, 0); - d->bt_circle - = dtgtk_togglebutton_new(dtgtk_cairo_paint_masks_circle, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); + d->bt_circle = dtgtk_togglebutton_new(dtgtk_cairo_paint_masks_circle, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); g_signal_connect(G_OBJECT(d->bt_circle), "button-press-event", G_CALLBACK(_bt_add_circle), self); gtk_widget_set_tooltip_text(d->bt_circle, _("add circle")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(d->bt_circle), FALSE); @@ -1675,8 +1663,7 @@ void gui_init(dt_lib_module_t *self) gtk_box_pack_start(GTK_BOX(self->widget), hbox, TRUE, TRUE, 0); d->scroll_window = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(d->scroll_window), GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(d->scroll_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start(GTK_BOX(self->widget), d->scroll_window, TRUE, TRUE, 0); d->treeview = gtk_tree_view_new(); diff --git a/src/libs/metadata.c b/src/libs/metadata.c index ced3764b8cd8..4b2fe7d030bf 100644 --- a/src/libs/metadata.c +++ b/src/libs/metadata.c @@ -58,7 +58,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"lighttable", "tethering", NULL}; + static const char *v[] = { "lighttable", "tethering", NULL }; return v; } @@ -80,8 +80,7 @@ static void fill_combo_box_entry(GtkComboBox *box, uint32_t count, GList *items, if(count > 1) { - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(box), - _("<leave unchanged>")); // FIXME: should be italic! + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(box), _("<leave unchanged>")); // FIXME: should be italic! gtk_combo_box_set_button_sensitivity(GTK_COMBO_BOX(box), GTK_SENSITIVITY_AUTO); *multi = TRUE; } @@ -222,8 +221,7 @@ static void write_metadata(dt_lib_module_t *self) dt_metadata_set(mouse_over_id, "Xmp.dc.description", description); if(rights != NULL && (d->multi_rights == FALSE || gtk_combo_box_get_active(GTK_COMBO_BOX(d->rights)) != 0)) dt_metadata_set(mouse_over_id, "Xmp.dc.rights", rights); - if(creator != NULL - && (d->multi_creator == FALSE || gtk_combo_box_get_active(GTK_COMBO_BOX(d->creator)) != 0)) + if(creator != NULL && (d->multi_creator == FALSE || gtk_combo_box_get_active(GTK_COMBO_BOX(d->creator)) != 0)) dt_metadata_set(mouse_over_id, "Xmp.dc.creator", creator); if(publisher != NULL && (d->multi_publisher == FALSE || gtk_combo_box_get_active(GTK_COMBO_BOX(d->publisher)) != 0)) @@ -499,8 +497,7 @@ int set_params(dt_lib_module_t *self, const void *params, int size) if(!publisher) return 1; const int publisher_len = strlen(publisher) + 1; - if(size != title_len + description_len + rights_len + creator_len + publisher_len) - return 1; + if(size != title_len + description_len + rights_len + creator_len + publisher_len) return 1; if(title != NULL && title[0] != '\0') dt_metadata_set(-1, "Xmp.dc.title", title); if(description != NULL && description[0] != '\0') dt_metadata_set(-1, "Xmp.dc.description", description); diff --git a/src/libs/metadata_view.c b/src/libs/metadata_view.c index e8092189f18a..64984158fc3d 100644 --- a/src/libs/metadata_view.c +++ b/src/libs/metadata_view.c @@ -135,7 +135,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"*", NULL}; + static const char *v[] = { "*", NULL }; return v; } @@ -193,7 +193,7 @@ static void _metadata_update_value_end(GtkLabel *label, const char *value) #ifdef USE_LUA -static int lua_update_metadata(lua_State*L); +static int lua_update_metadata(lua_State *L); #endif /* update all values to reflect mouse over image id or no data at all */ static void _metadata_view_update_values(dt_lib_module_t *self) @@ -257,28 +257,20 @@ static void _metadata_view_update_values(dt_lib_module_t *self) snprintf(value, sizeof(value), "%s", (img->flags & DT_IMAGE_LOCAL_COPY) ? _("yes") : _("no")); _metadata_update_value(d->metadata[md_internal_local_copy], value); - // TODO: decide if this should be removed for a release. maybe #ifdef'ing to only add it to git compiles? +// TODO: decide if this should be removed for a release. maybe #ifdef'ing to only add it to git compiles? - // the bits of the flags +// the bits of the flags #if SHOW_FLAGS { - #define EMPTY_FIELD '.' - #define FALSE_FIELD '.' - #define TRUE_FIELD '!' +#define EMPTY_FIELD '.' +#define FALSE_FIELD '.' +#define TRUE_FIELD '!' char *flags_tooltip = NULL; - char *flag_descriptions[] = { N_("unused"), - N_("unused/deprecated"), - N_("ldr"), - N_("raw"), - N_("hdr"), - N_("marked for deletion"), - N_("auto-applying presets applied"), - N_("legacy flag. set for all new images"), - N_("local copy"), - N_("has .txt"), - N_("has .wav") - }; + char *flag_descriptions[] + = { N_("unused"), N_("unused/deprecated"), N_("ldr"), N_("raw"), N_("hdr"), N_("marked for deletion"), + N_("auto-applying presets applied"), N_("legacy flag. set for all new images"), N_("local copy"), + N_("has .txt"), N_("has .wav") }; char *tooltip_parts[14] = { 0 }; int next_tooltip_part = 0; @@ -294,7 +286,8 @@ static void _metadata_view_update_values(dt_lib_module_t *self) else { value[0] = '0' + stars; - tooltip_parts[next_tooltip_part++] = star_string = g_strdup_printf(ngettext("image has %d star", "image has %d stars", stars), stars); + tooltip_parts[next_tooltip_part++] = star_string + = g_strdup_printf(ngettext("image has %d star", "image has %d stars", stars), stars); } @@ -372,19 +365,16 @@ static void _metadata_view_update_values(dt_lib_module_t *self) { char *tooltip; char flag; - } loaders[] = - { - { N_("unknown"), EMPTY_FIELD}, - { N_("tiff"), 't'}, - { N_("png"), 'p'}, - { N_("j2k"), 'J'}, - { N_("jpeg"), 'j'}, - { N_("exr"), 'e'}, - { N_("rgbe"), 'R'}, - { N_("pfm"), 'P'}, - { N_("GraphicsMagick"), 'g'}, - { N_("rawspeed"), 'r'} - }; + } loaders[] = { { N_("unknown"), EMPTY_FIELD }, + { N_("tiff"), 't' }, + { N_("png"), 'p' }, + { N_("j2k"), 'J' }, + { N_("jpeg"), 'j' }, + { N_("exr"), 'e' }, + { N_("rgbe"), 'R' }, + { N_("pfm"), 'P' }, + { N_("GraphicsMagick"), 'g' }, + { N_("rawspeed"), 'r' } }; int loader = (unsigned int)img->loader < sizeof(loaders) / sizeof(*loaders) ? img->loader : 0; value[12] = loaders[loader].flag; @@ -402,9 +392,9 @@ static void _metadata_view_update_values(dt_lib_module_t *self) g_free(star_string); g_free(flags_tooltip); - #undef EMPTY_FIELD - #undef FALSE_FIELD - #undef TRUE_FIELD +#undef EMPTY_FIELD +#undef FALSE_FIELD +#undef TRUE_FIELD } #endif // SHOW_FLAGS @@ -439,8 +429,8 @@ static void _metadata_view_update_values(dt_lib_module_t *self) _metadata_update_value(d->metadata[md_exif_iso], value); struct tm tt_exif = { 0 }; - if(sscanf(img->exif_datetime_taken, "%d:%d:%d %d:%d:%d", &tt_exif.tm_year, &tt_exif.tm_mon, - &tt_exif.tm_mday, &tt_exif.tm_hour, &tt_exif.tm_min, &tt_exif.tm_sec) == 6) + if(sscanf(img->exif_datetime_taken, "%d:%d:%d %d:%d:%d", &tt_exif.tm_year, &tt_exif.tm_mon, &tt_exif.tm_mday, + &tt_exif.tm_hour, &tt_exif.tm_min, &tt_exif.tm_sec) == 6) { char datetime[200]; tt_exif.tm_year -= 1900; @@ -556,10 +546,8 @@ static void _metadata_view_update_values(dt_lib_module_t *self) dt_image_cache_read_release(darktable.image_cache, img); #ifdef USE_LUA - dt_lua_async_call_alien(lua_update_metadata, - 0,NULL,NULL, - LUA_ASYNC_TYPENAME,"void*",self, - LUA_ASYNC_TYPENAME,"int32_t",mouse_over_id,LUA_ASYNC_DONE); + dt_lua_async_call_alien(lua_update_metadata, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "void*", self, + LUA_ASYNC_TYPENAME, "int32_t", mouse_over_id, LUA_ASYNC_DONE); #endif } @@ -569,10 +557,8 @@ static void _metadata_view_update_values(dt_lib_module_t *self) fill_minuses: for(int k = 0; k < md_size; k++) _metadata_update_value(d->metadata[k], NODATA_STRING); #ifdef USE_LUA - dt_lua_async_call_alien(lua_update_metadata, - 0,NULL,NULL, - LUA_ASYNC_TYPENAME,"void*",self, - LUA_ASYNC_TYPENAME,"int32_t",-1,LUA_ASYNC_DONE); + dt_lua_async_call_alien(lua_update_metadata, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "void*", self, + LUA_ASYNC_TYPENAME, "int32_t", -1, LUA_ASYNC_DONE); #endif } @@ -642,7 +628,7 @@ void gui_init(dt_lib_module_t *self) self->widget = gtk_grid_new(); gtk_grid_set_column_spacing(GTK_GRID(self->widget), DT_PIXEL_APPLY_DPI(5)); -// GtkWidget *last = NULL; + // GtkWidget *last = NULL; /* initialize the metadata name/value labels */ for(int k = 0; k < md_size; k++) @@ -685,69 +671,69 @@ void gui_cleanup(dt_lib_module_t *self) self->data = NULL; } #ifdef USE_LUA -static int lua_update_widgets(lua_State*L) +static int lua_update_widgets(lua_State *L) { dt_lib_module_t *self = lua_touserdata(L, 1); - dt_lua_module_entry_push(L,"lib",self->plugin_name); - lua_getuservalue(L,2); - lua_getfield(L,3,"values"); - lua_getfield(L,3,"widgets"); + dt_lua_module_entry_push(L, "lib", self->plugin_name); + lua_getuservalue(L, 2); + lua_getfield(L, 3, "values"); + lua_getfield(L, 3, "widgets"); lua_pushnil(L); while(lua_next(L, 4) != 0) { - lua_getfield(L,5,lua_tostring(L,-2)); - GtkLabel *widget = lua_touserdata(L,-1); - _metadata_update_value_end(widget,luaL_checkstring(L,7)); - lua_pop(L,2); + lua_getfield(L, 5, lua_tostring(L, -2)); + GtkLabel *widget = lua_touserdata(L, -1); + _metadata_update_value_end(widget, luaL_checkstring(L, 7)); + lua_pop(L, 2); } return 0; } -static int lua_update_metadata(lua_State*L) +static int lua_update_metadata(lua_State *L) { dt_lib_module_t *self = lua_touserdata(L, 1); - int32_t imgid = lua_tointeger(L,2); - dt_lua_module_entry_push(L,"lib",self->plugin_name); - lua_getuservalue(L,-1); - lua_getfield(L,4,"callbacks"); - lua_getfield(L,4,"values"); + int32_t imgid = lua_tointeger(L, 2); + dt_lua_module_entry_push(L, "lib", self->plugin_name); + lua_getuservalue(L, -1); + lua_getfield(L, 4, "callbacks"); + lua_getfield(L, 4, "values"); lua_pushnil(L); while(lua_next(L, 5) != 0) { - lua_pushvalue(L,-1); - luaA_push(L,dt_lua_image_t,&imgid); - lua_call(L,1,1); - lua_pushvalue(L,7); - lua_pushvalue(L,9); - lua_settable(L,6); + lua_pushvalue(L, -1); + luaA_push(L, dt_lua_image_t, &imgid); + lua_call(L, 1, 1); + lua_pushvalue(L, 7); + lua_pushvalue(L, 9); + lua_settable(L, 6); lua_pop(L, 2); } - lua_pushcfunction(L,lua_update_widgets); + lua_pushcfunction(L, lua_update_widgets); dt_lua_gtk_wrap(L); - lua_pushlightuserdata(L,self); - lua_call(L,1,0); + lua_pushlightuserdata(L, self); + lua_call(L, 1, 0); return 0; } static int lua_register_info(lua_State *L) { dt_lib_module_t *self = lua_touserdata(L, lua_upvalueindex(1)); - dt_lua_module_entry_push(L,"lib",self->plugin_name); - lua_getuservalue(L,-1); - const char* key = luaL_checkstring(L,1); - luaL_checktype(L,2,LUA_TFUNCTION); + dt_lua_module_entry_push(L, "lib", self->plugin_name); + lua_getuservalue(L, -1); + const char *key = luaL_checkstring(L, 1); + luaL_checktype(L, 2, LUA_TFUNCTION); { - lua_getfield(L,-1,"callbacks"); - lua_pushstring(L,key); - lua_pushvalue(L,2); - lua_settable(L,5); - lua_pop(L,1); + lua_getfield(L, -1, "callbacks"); + lua_pushstring(L, key); + lua_pushvalue(L, 2); + lua_settable(L, 5); + lua_pop(L, 1); } { - lua_getfield(L,-1,"values"); - lua_pushstring(L,key); - lua_pushstring(L,"-"); - lua_settable(L,5); - lua_pop(L,1); + lua_getfield(L, -1, "values"); + lua_pushstring(L, key); + lua_pushstring(L, "-"); + lua_settable(L, 5); + lua_pop(L, 1); } { GtkWidget *evb = gtk_event_box_new(); @@ -762,11 +748,11 @@ static int lua_register_info(lua_State *L) gtk_grid_attach_next_to(GTK_GRID(self->widget), GTK_WIDGET(evb), GTK_WIDGET(name), GTK_POS_RIGHT, 1, 1); gtk_widget_show_all(self->widget); { - lua_getfield(L,-1,"widgets"); - lua_pushstring(L,key); - lua_pushlightuserdata(L,value); - lua_settable(L,5); - lua_pop(L,1); + lua_getfield(L, -1, "widgets"); + lua_pushstring(L, key); + lua_pushlightuserdata(L, value); + lua_settable(L, 5); + lua_pop(L, 1); } } return 0; @@ -778,20 +764,20 @@ void init(struct dt_lib_module_t *self) lua_State *L = darktable.lua_state.state; int my_type = dt_lua_module_entry_get_type(L, "lib", self->plugin_name); lua_pushlightuserdata(L, self); - lua_pushcclosure(L, lua_register_info,1); + lua_pushcclosure(L, lua_register_info, 1); dt_lua_gtk_wrap(L); lua_pushcclosure(L, dt_lua_type_member_common, 1); dt_lua_type_register_const_type(L, my_type, "register_info"); - dt_lua_module_entry_push(L,"lib",self->plugin_name); - lua_getuservalue(L,-1); + dt_lua_module_entry_push(L, "lib", self->plugin_name); + lua_getuservalue(L, -1); lua_newtable(L); - lua_setfield(L,-2,"callbacks"); + lua_setfield(L, -2, "callbacks"); lua_newtable(L); - lua_setfield(L,-2,"values"); + lua_setfield(L, -2, "values"); lua_newtable(L); - lua_setfield(L,-2,"widgets"); - lua_pop(L,2); + lua_setfield(L, -2, "widgets"); + lua_pop(L, 2); } #endif // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh diff --git a/src/libs/modulegroups.c b/src/libs/modulegroups.c index 21ca207e0f93..79fa47aaa0b5 100644 --- a/src/libs/modulegroups.c +++ b/src/libs/modulegroups.c @@ -61,8 +61,8 @@ static gboolean _lib_modulegroups_test(dt_lib_module_t *self, uint32_t group, ui static void _lib_modulegroups_switch_group(dt_lib_module_t *self, dt_iop_module_t *module); /* hook up with viewmanager view change to initialize modulegroup */ -static void _lib_modulegroups_viewchanged_callback(gpointer instance, dt_view_t *old_view, - dt_view_t *new_view, gpointer data); +static void _lib_modulegroups_viewchanged_callback(gpointer instance, dt_view_t *old_view, dt_view_t *new_view, + gpointer data); const char *name(dt_lib_module_t *self) { @@ -71,7 +71,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"darkroom", NULL}; + static const char *v[] = { "darkroom", NULL }; return v; } @@ -104,15 +104,13 @@ void gui_init(dt_lib_module_t *self) /* favorites */ d->buttons[DT_MODULEGROUP_FAVORITES] = dtgtk_togglebutton_new(dtgtk_cairo_paint_modulegroup_favorites, pf); - g_signal_connect(d->buttons[DT_MODULEGROUP_FAVORITES], "toggled", G_CALLBACK(_lib_modulegroups_toggle), - self); + g_signal_connect(d->buttons[DT_MODULEGROUP_FAVORITES], "toggled", G_CALLBACK(_lib_modulegroups_toggle), self); gtk_widget_set_tooltip_text(d->buttons[DT_MODULEGROUP_FAVORITES], _("show only your favourite modules (selected in `more modules' below)")); /* active */ d->buttons[DT_MODULEGROUP_ACTIVE_PIPE] = dtgtk_togglebutton_new(dtgtk_cairo_paint_modulegroup_active, pf); - g_signal_connect(d->buttons[DT_MODULEGROUP_ACTIVE_PIPE], "toggled", G_CALLBACK(_lib_modulegroups_toggle), - self); + g_signal_connect(d->buttons[DT_MODULEGROUP_ACTIVE_PIPE], "toggled", G_CALLBACK(_lib_modulegroups_toggle), self); gtk_widget_set_tooltip_text(d->buttons[DT_MODULEGROUP_ACTIVE_PIPE], _("show only active modules")); /* basic */ @@ -185,8 +183,8 @@ void gui_cleanup(dt_lib_module_t *self) self->data = NULL; } -static void _lib_modulegroups_viewchanged_callback(gpointer instance, dt_view_t *old_view, - dt_view_t *new_view, gpointer data) +static void _lib_modulegroups_viewchanged_callback(gpointer instance, dt_view_t *old_view, dt_view_t *new_view, + gpointer data) { } @@ -271,8 +269,7 @@ static void _lib_modulegroups_update_iop_visibility(dt_lib_module_t *self) default: { - if(_lib_modulegroups_test(self, d->current, module->groups()) - && module->so->state != dt_iop_state_HIDDEN + if(_lib_modulegroups_test(self, d->current, module->groups()) && module->so->state != dt_iop_state_HIDDEN && (!(module->flags() & IOP_FLAGS_DEPRECATED) || module->enabled)) gtk_widget_show(w); else @@ -293,8 +290,7 @@ static void _lib_modulegroups_toggle(GtkWidget *button, gpointer user_data) /* block all button callbacks */ for(int k = 0; k < DT_MODULEGROUP_SIZE; k++) - g_signal_handlers_block_matched(d->buttons[k], G_SIGNAL_MATCH_FUNC, 0, 0, NULL, _lib_modulegroups_toggle, - NULL); + g_signal_handlers_block_matched(d->buttons[k], G_SIGNAL_MATCH_FUNC, 0, 0, NULL, _lib_modulegroups_toggle, NULL); /* deactivate all buttons */ uint32_t cb = 0; @@ -316,8 +312,8 @@ static void _lib_modulegroups_toggle(GtkWidget *button, gpointer user_data) /* unblock all button callbacks */ for(int k = 0; k < DT_MODULEGROUP_SIZE; k++) - g_signal_handlers_unblock_matched(d->buttons[k], G_SIGNAL_MATCH_FUNC, 0, 0, NULL, - _lib_modulegroups_toggle, NULL); + g_signal_handlers_unblock_matched(d->buttons[k], G_SIGNAL_MATCH_FUNC, 0, 0, NULL, _lib_modulegroups_toggle, + NULL); /* update visibility */ _lib_modulegroups_update_iop_visibility(self); diff --git a/src/libs/modulelist.c b/src/libs/modulelist.c index 3e239b790084..9dc9914f6aaf 100644 --- a/src/libs/modulelist.c +++ b/src/libs/modulelist.c @@ -59,7 +59,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"darkroom", NULL}; + static const char *v[] = { "darkroom", NULL }; return v; } @@ -78,8 +78,8 @@ void gui_init(dt_lib_module_t *self) /* initialize ui widgets */ dt_lib_modulelist_t *d = (dt_lib_modulelist_t *)g_malloc0(sizeof(dt_lib_modulelist_t)); self->data = (void *)d; - self->widget = gtk_scrolled_window_new( - NULL, NULL); // GTK_ADJUSTMENT(gtk_adjustment_new(200, 100, 200, 10, 100, 100)) + self->widget + = gtk_scrolled_window_new(NULL, NULL); // GTK_ADJUSTMENT(gtk_adjustment_new(200, 100, 200, 10, 100, 100)) gtk_widget_set_size_request(self->widget, -1, DT_PIXEL_APPLY_DPI(208)); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(self->widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); d->tree = GTK_TREE_VIEW(gtk_tree_view_new()); @@ -91,8 +91,7 @@ void gui_init(dt_lib_module_t *self) dt_control_signal_connect(darktable.signals, DT_SIGNAL_DEVELOP_INITIALIZE, G_CALLBACK(_lib_modulelist_populate_callback), self); g_signal_connect(GTK_WIDGET(d->tree), "style-set", G_CALLBACK(_lib_modulelist_style_set), self); - g_signal_connect(GTK_WIDGET(d->tree), "cursor-changed", G_CALLBACK(_lib_modulelist_row_changed_callback), - NULL); + g_signal_connect(GTK_WIDGET(d->tree), "cursor-changed", G_CALLBACK(_lib_modulelist_row_changed_callback), NULL); darktable.view_manager->proxy.more_module.module = self; darktable.view_manager->proxy.more_module.update = _lib_modulelist_gui_update; @@ -173,7 +172,7 @@ static void _lib_modulelist_populate_callback(gpointer instance, gpointer user_d GtkCellRenderer *pix_renderer, *fav_renderer, *text_renderer; GdkRGBA color; GtkStyleContext *context = gtk_widget_get_style_context(view); - gboolean color_found = gtk_style_context_lookup_color (context, "selected_bg_color", &color); + gboolean color_found = gtk_style_context_lookup_color(context, "selected_bg_color", &color); if(!color_found) { color.red = 1.0; @@ -227,8 +226,8 @@ static void _lib_modulelist_populate_callback(gpointer instance, gpointer user_d image_renderer_function, NULL, NULL); col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 2); if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col); - gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(view), 2, "name", text_renderer, - text_renderer_function, NULL, NULL); + gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(view), 2, "name", text_renderer, text_renderer_function, + NULL, NULL); /* go thru list of iop modules and add them to the list */ GList *modules = g_list_last(darktable.iop); @@ -265,8 +264,8 @@ static void _lib_modulelist_populate_callback(gpointer instance, gpointer user_d end: gtk_list_store_append(store, &iter); - gtk_list_store_set(store, &iter, COL_IMAGE, pixbuf, COL_MODULE, module, - COL_DESCRIPTION, module->description ? module->description() : module->name(), -1); + gtk_list_store_set(store, &iter, COL_IMAGE, pixbuf, COL_MODULE, module, COL_DESCRIPTION, + module->description ? module->description() : module->name(), -1); g_object_unref(pixbuf); } diff --git a/src/libs/navigation.c b/src/libs/navigation.c index 1f40b23bbc0b..bc79fb657df9 100644 --- a/src/libs/navigation.c +++ b/src/libs/navigation.c @@ -35,7 +35,7 @@ typedef struct dt_lib_navigation_t { int dragging; int zoom_w, zoom_h; - unsigned char* buffer; + unsigned char *buffer; int wd; int ht; int timestamp; @@ -48,8 +48,7 @@ static gboolean _lib_navigation_draw_callback(GtkWidget *widget, cairo_t *crf, g static gboolean _lib_navigation_motion_notify_callback(GtkWidget *widget, GdkEventMotion *event, gpointer user_data); /* button press callback */ -static gboolean _lib_navigation_button_press_callback(GtkWidget *widget, GdkEventButton *event, - gpointer user_data); +static gboolean _lib_navigation_button_press_callback(GtkWidget *widget, GdkEventButton *event, gpointer user_data); /* button release callback */ static gboolean _lib_navigation_button_release_callback(GtkWidget *widget, GdkEventButton *event, gpointer user_data); @@ -67,7 +66,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"darkroom", NULL}; + static const char *v[] = { "darkroom", NULL }; return v; } @@ -106,21 +105,20 @@ void gui_init(dt_lib_module_t *self) /* create drawingarea */ self->widget = gtk_drawing_area_new(); - gtk_widget_set_events(self->widget, GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK - | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK - | GDK_BUTTON_RELEASE_MASK | GDK_STRUCTURE_MASK); + gtk_widget_set_events(self->widget, GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK + | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_STRUCTURE_MASK); /* connect callbacks */ gtk_widget_set_app_paintable(self->widget, TRUE); g_signal_connect(G_OBJECT(self->widget), "draw", G_CALLBACK(_lib_navigation_draw_callback), self); - g_signal_connect(G_OBJECT(self->widget), "button-press-event", - G_CALLBACK(_lib_navigation_button_press_callback), self); + g_signal_connect(G_OBJECT(self->widget), "button-press-event", G_CALLBACK(_lib_navigation_button_press_callback), + self); g_signal_connect(G_OBJECT(self->widget), "button-release-event", G_CALLBACK(_lib_navigation_button_release_callback), self); g_signal_connect(G_OBJECT(self->widget), "motion-notify-event", G_CALLBACK(_lib_navigation_motion_notify_callback), self); - g_signal_connect(G_OBJECT(self->widget), "leave-notify-event", - G_CALLBACK(_lib_navigation_leave_notify_callback), self); + g_signal_connect(G_OBJECT(self->widget), "leave-notify-event", G_CALLBACK(_lib_navigation_leave_notify_callback), + self); /* set size of navigation draw area */ int panel_width = dt_conf_get_int("panel_width"); @@ -202,8 +200,7 @@ static gboolean _lib_navigation_draw_callback(GtkWidget *widget, cairo_t *crf, g const float scale = fminf(width / (float)wd, height / (float)ht); const int stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, wd); - cairo_surface_t *surface - = cairo_image_surface_create_for_data(d->buffer, CAIRO_FORMAT_RGB24, wd, ht, stride); + cairo_surface_t *surface = cairo_image_surface_create_for_data(d->buffer, CAIRO_FORMAT_RGB24, wd, ht, stride); cairo_translate(cr, width / 2.0, height / 2.0f); cairo_scale(cr, scale, scale); cairo_translate(cr, -.5f * wd, -.5f * ht); @@ -272,7 +269,7 @@ static gboolean _lib_navigation_draw_callback(GtkWidget *widget, cairo_t *crf, g h = d->zoom_h = ink.height; w = d->zoom_w = ink.width; - cairo_move_to(cr, width - w - h * 1.1 - ink.x, - fontsize); + cairo_move_to(cr, width - w - h * 1.1 - ink.x, -fontsize); cairo_save(cr); cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(2.0)); @@ -290,7 +287,6 @@ static gboolean _lib_navigation_draw_callback(GtkWidget *widget, cairo_t *crf, g gdk_rgba_free(color); pango_font_description_free(desc); g_object_unref(layout); - } else { @@ -378,11 +374,9 @@ void _lib_navigation_set_position(dt_lib_module_t *self, double x, double y, int int iwd, iht; dt_dev_get_processed_size(dev, &iwd, &iht); zoom_x = fmaxf( - -.5, - fminf(((x - inset) / width - .5f) / (iwd * fminf(wd / (float)iwd, ht / (float)iht) / (float)wd), .5)); + -.5, fminf(((x - inset) / width - .5f) / (iwd * fminf(wd / (float)iwd, ht / (float)iht) / (float)wd), .5)); zoom_y = fmaxf( - -.5, fminf(((y - inset) / height - .5f) / (iht * fminf(wd / (float)iwd, ht / (float)iht) / (float)ht), - .5)); + -.5, fminf(((y - inset) / height - .5f) / (iht * fminf(wd / (float)iwd, ht / (float)iht) / (float)ht), .5)); dt_dev_check_zoom_bounds(darktable.develop, &zoom_x, &zoom_y, zoom, closeup, NULL, NULL); dt_control_set_dev_zoom_x(zoom_x); dt_control_set_dev_zoom_y(zoom_y); @@ -396,8 +390,7 @@ void _lib_navigation_set_position(dt_lib_module_t *self, double x, double y, int } } -static gboolean _lib_navigation_motion_notify_callback(GtkWidget *widget, GdkEventMotion *event, - gpointer user_data) +static gboolean _lib_navigation_motion_notify_callback(GtkWidget *widget, GdkEventMotion *event, gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; GtkAllocation allocation; @@ -405,15 +398,14 @@ static gboolean _lib_navigation_motion_notify_callback(GtkWidget *widget, GdkEve _lib_navigation_set_position(self, event->x, event->y, allocation.width, allocation.height); gint x, y; // notify gtk for motion_hint. #if GTK_CHECK_VERSION(3, 20, 0) - gdk_window_get_device_position(event->window, - gdk_seat_get_pointer(gdk_display_get_default_seat( - gdk_window_get_display(event->window))), - &x, &y, 0); + gdk_window_get_device_position( + event->window, gdk_seat_get_pointer(gdk_display_get_default_seat(gdk_window_get_display(event->window))), &x, + &y, 0); #else - gdk_window_get_device_position(event->window, - gdk_device_manager_get_client_pointer( - gdk_display_get_device_manager(gdk_window_get_display(event->window))), - &x, &y, NULL); + gdk_window_get_device_position( + event->window, + gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gdk_window_get_display(event->window))), + &x, &y, NULL); #endif return TRUE; } @@ -482,8 +474,7 @@ static void _zoom_preset_2(GtkButton *button, gpointer user_data) _zoom_preset_change(3); } -static gboolean _lib_navigation_button_press_callback(GtkWidget *widget, GdkEventButton *event, - gpointer user_data) +static gboolean _lib_navigation_button_press_callback(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_navigation_t *d = (dt_lib_navigation_t *)self->data; @@ -492,8 +483,7 @@ static gboolean _lib_navigation_button_press_callback(GtkWidget *widget, GdkEven gtk_widget_get_allocation(widget, &allocation); int w = allocation.width; int h = allocation.height; - if(event->x >= w - DT_NAVIGATION_INSET - d->zoom_h - d->zoom_w - && event->y >= h - DT_NAVIGATION_INSET - d->zoom_h) + if(event->x >= w - DT_NAVIGATION_INSET - d->zoom_h - d->zoom_w && event->y >= h - DT_NAVIGATION_INSET - d->zoom_h) { // we show the zoom menu GtkMenuShell *menu = GTK_MENU_SHELL(gtk_menu_new()); diff --git a/src/libs/print_settings.c b/src/libs/print_settings.c index 49e8f766cd17..b11b03c88f3b 100644 --- a/src/libs/print_settings.c +++ b/src/libs/print_settings.c @@ -45,7 +45,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"print", NULL}; + static const char *v[] = { "print", NULL }; return v; } @@ -64,7 +64,7 @@ typedef struct dt_lib_print_settings_t GtkButton *print_button; GtkToggleButton *lock_button; GtkWidget *b_top, *b_bottom, *b_left, *b_right; - GtkDarktableToggleButton *dtba[9]; // Alignment buttons + GtkDarktableToggleButton *dtba[9]; // Alignment buttons GList *paper_list; gboolean lock_activated; dt_print_info_t prt; @@ -83,7 +83,7 @@ typedef struct dt_lib_export_profile_t dt_colorspaces_color_profile_type_t type; // filename is only used for type DT_COLORSPACE_FILE char filename[512]; // icc file name char name[512]; // product name - int pos, ppos; // position in combo boxen + int pos, ppos; // position in combo boxen } dt_lib_export_profile_t; typedef struct _dialog_description @@ -91,14 +91,13 @@ typedef struct _dialog_description const char *name; } dialog_description_t; -static double units[3] = {1.0, 0.1, 1.0/25.4}; +static double units[3] = { 1.0, 0.1, 1.0 / 25.4 }; -static void _update_slider (dt_lib_print_settings_t *ps); +static void _update_slider(dt_lib_print_settings_t *ps); static const int min_borders = -100; // this is in mm -int -position () +int position() { return 990; } @@ -132,21 +131,20 @@ static const char *mime(dt_imageio_module_data_t *data) return "memory"; } -static int write_image(dt_imageio_module_data_t *data, const char *filename, const void *in, - void *exif, int exif_len, int imgid, int num, int total) +static int write_image(dt_imageio_module_data_t *data, const char *filename, const void *in, void *exif, + int exif_len, int imgid, int num, int total) { dt_print_format_t *d = (dt_print_format_t *)data; - d->ps->buf = (uint16_t *)malloc(d->width * d->height * 3 * (d->bpp == 8?1:2)); + d->ps->buf = (uint16_t *)malloc(d->width * d->height * 3 * (d->bpp == 8 ? 1 : 2)); - if (d->bpp == 8) + if(d->bpp == 8) { const uint8_t *in_ptr = (const uint8_t *)in; uint8_t *out_ptr = (uint8_t *)d->ps->buf; for(int y = 0; y < d->height; y++) { - for(int x = 0; x < d->width; x++, in_ptr += 4, out_ptr += 3) - memcpy(out_ptr, in_ptr, 3); + for(int x = 0; x < d->width; x++, in_ptr += 4, out_ptr += 3) memcpy(out_ptr, in_ptr, 3); } } else @@ -155,33 +153,31 @@ static int write_image(dt_imageio_module_data_t *data, const char *filename, con uint16_t *out_ptr = (uint16_t *)d->ps->buf; for(int y = 0; y < d->height; y++) { - for(int x = 0; x < d->width; x++, in_ptr += 4, out_ptr += 3) - memcpy(out_ptr, in_ptr, 6); + for(int x = 0; x < d->width; x++, in_ptr += 4, out_ptr += 3) memcpy(out_ptr, in_ptr, 6); } } return 0; } -static void -_print_button_clicked (GtkWidget *widget, gpointer user_data) +static void _print_button_clicked(GtkWidget *widget, gpointer user_data) { const dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; const int imgid = dt_view_filmstrip_get_activated_imgid(darktable.view_manager); - if (imgid == -1) + if(imgid == -1) { dt_control_log(_("cannot print until a picture is selected")); return; } - if (strlen(ps->prt.printer.name) == 0 || ps->prt.printer.resolution == 0) + if(strlen(ps->prt.printer.name) == 0 || ps->prt.printer.resolution == 0) { dt_control_log(_("cannot print until a printer is selected")); return; } - if (ps->prt.paper.width == 0 || ps->prt.paper.height == 0) + if(ps->prt.paper.width == 0 || ps->prt.paper.height == 0) { dt_control_log(_("cannot print until a paper is selected")); return; @@ -194,7 +190,7 @@ _print_button_clicked (GtkWidget *widget, gpointer user_data) double margin_w = ps->prt.page.margin_left + ps->prt.page.margin_right; double margin_h = ps->prt.page.margin_top + ps->prt.page.margin_bottom; - if (ps->prt.page.landscape) + if(ps->prt.page.landscape) { width = ps->prt.paper.height; height = ps->prt.paper.width; @@ -212,17 +208,18 @@ _print_button_clicked (GtkWidget *widget, gpointer user_data) const int32_t width_pix = (width * ps->prt.printer.resolution) / 25.4; const int32_t height_pix = (height * ps->prt.printer.resolution) / 25.4; - const double pa_width = (width - margin_w) / 25.4; + const double pa_width = (width - margin_w) / 25.4; const double pa_height = (height - margin_h) / 25.4; dt_print(DT_DEBUG_PRINT, "[print] printable area for image %u : %3.2fin x %3.2fin\n", imgid, pa_width, pa_height); // compute the needed size for picture for the given printer resolution - const int max_width = (pa_width * ps->prt.printer.resolution); + const int max_width = (pa_width * ps->prt.printer.resolution); const int max_height = (pa_height * ps->prt.printer.resolution); - dt_print(DT_DEBUG_PRINT, "[print] max image size %d x %d (at resolution %d)\n", max_width, max_height, ps->prt.printer.resolution); + dt_print(DT_DEBUG_PRINT, "[print] max image size %d x %d (at resolution %d)\n", max_width, max_height, + ps->prt.printer.resolution); dt_imageio_module_format_t buf; buf.mime = mime; @@ -238,8 +235,8 @@ _print_button_clicked (GtkWidget *widget, gpointer user_data) dat.bpp = *ps->v_piccprofile ? 16 : 8; // set to 16bit when a profile is to be applied dat.ps = ps; - char* style = dt_conf_get_string("plugins/print/print/style"); - if (style) + char *style = dt_conf_get_string("plugins/print/print/style"); + if(style) { g_strlcpy(dat.style, style, sizeof(dat.style)); g_free(style); @@ -250,60 +247,55 @@ _print_button_clicked (GtkWidget *widget, gpointer user_data) dt_colorspaces_color_profile_type_t icc_type = dt_conf_get_int("plugins/print/print/icctype"); gchar *icc_filename = dt_conf_get_string("plugins/print/print/iccprofile"); dt_iop_color_intent_t icc_intent = dt_conf_get_int("plugins/print/print/iccintent"); - dt_imageio_export_with_flags(imgid, "unused", &buf, (dt_imageio_module_data_t *)&dat, 1, 0, high_quality, upscale, 0, - NULL, FALSE, icc_type, icc_filename, icc_intent, NULL, NULL, 1, 1); + dt_imageio_export_with_flags(imgid, "unused", &buf, (dt_imageio_module_data_t *)&dat, 1, 0, high_quality, + upscale, 0, NULL, FALSE, icc_type, icc_filename, icc_intent, NULL, NULL, 1, 1); g_free(icc_filename); // after exporting we know the real size of the image, compute the layout // compute print-area (in inches) - int32_t px=0, py=0, pwidth=0, pheight=0; - int32_t ax=0, ay=0, awidth=0, aheight=0; - int32_t ix=0, iy=0, iwidth=0, iheight=0; - int32_t iwpix=dat.width, ihpix=dat.height; - - dt_get_print_layout (imgid, &ps->prt, width_pix, height_pix, - &iwpix, &ihpix, - &px, &py, &pwidth, &pheight, - &ax, &ay, &awidth, &aheight, - &ix, &iy, &iwidth, &iheight); - - const int margin_top = iy; - const int margin_left = ix; - const int margin_right = pwidth - iwidth - ix; + int32_t px = 0, py = 0, pwidth = 0, pheight = 0; + int32_t ax = 0, ay = 0, awidth = 0, aheight = 0; + int32_t ix = 0, iy = 0, iwidth = 0, iheight = 0; + int32_t iwpix = dat.width, ihpix = dat.height; + + dt_get_print_layout(imgid, &ps->prt, width_pix, height_pix, &iwpix, &ihpix, &px, &py, &pwidth, &pheight, &ax, + &ay, &awidth, &aheight, &ix, &iy, &iwidth, &iheight); + + const int margin_top = iy; + const int margin_left = ix; + const int margin_right = pwidth - iwidth - ix; const int margin_bottom = pheight - iheight - iy; - dt_print(DT_DEBUG_PRINT, "[print] margins top %d ; bottom %d ; left %d ; right %d\n", - margin_top, margin_bottom, margin_left, margin_right); + dt_print(DT_DEBUG_PRINT, "[print] margins top %d ; bottom %d ; left %d ; right %d\n", margin_top, margin_bottom, + margin_left, margin_right); // we have the exported buffer, let's apply the printer profile - if (*ps->v_piccprofile) + if(*ps->v_piccprofile) { - const dt_colorspaces_color_profile_t *pprof = dt_colorspaces_get_profile(ps->v_picctype, ps->v_piccprofile, - DT_PROFILE_DIRECTION_OUT); + const dt_colorspaces_color_profile_t *pprof + = dt_colorspaces_get_profile(ps->v_picctype, ps->v_piccprofile, DT_PROFILE_DIRECTION_OUT); - if (!pprof) + if(!pprof) { dt_control_log(_("cannot open printer profile `%s'"), ps->v_piccprofile); fprintf(stderr, "cannot open printer profile `%s'\n", ps->v_piccprofile); dt_control_queue_redraw(); return; } - else - if (dt_apply_printer_profile(imgid, (void **)&(dat.ps->buf), dat.width, dat.height, dat.bpp, - pprof->profile, - ps->v_pintent, ps->v_black_point_compensation)) - { - free(dat.ps->buf); - dt_control_log(_("cannot apply printer profile `%s'"), ps->v_piccprofile); - fprintf(stderr, "cannot apply printer profile `%s'\n", ps->v_piccprofile); - dt_control_queue_redraw(); - return; - } + else if(dt_apply_printer_profile(imgid, (void **)&(dat.ps->buf), dat.width, dat.height, dat.bpp, + pprof->profile, ps->v_pintent, ps->v_black_point_compensation)) + { + free(dat.ps->buf); + dt_control_log(_("cannot apply printer profile `%s'"), ps->v_piccprofile); + fprintf(stderr, "cannot apply printer profile `%s'\n", ps->v_piccprofile); + dt_control_queue_redraw(); + return; + } } - const float page_width = dt_pdf_mm_to_point(width); + const float page_width = dt_pdf_mm_to_point(width); const float page_height = dt_pdf_mm_to_point(height); char filename[PATH_MAX] = { 0 }; @@ -322,22 +314,23 @@ _print_button_clicked (GtkWidget *widget, gpointer user_data) const int icc_id = 0; - dt_pdf_t *pdf = dt_pdf_start(filename, page_width, page_height, ps->prt.printer.resolution, DT_PDF_STREAM_ENCODER_FLATE); + dt_pdf_t *pdf + = dt_pdf_start(filename, page_width, page_height, ps->prt.printer.resolution, DT_PDF_STREAM_ENCODER_FLATE); -/* - // ??? should a profile be embedded here? - if (*printer_profile) - icc_id = dt_pdf_add_icc(pdf, printer_profile); -*/ + /* + // ??? should a profile be embedded here? + if (*printer_profile) + icc_id = dt_pdf_add_icc(pdf, printer_profile); + */ dt_pdf_image_t *pdf_image = dt_pdf_add_image(pdf, (uint8_t *)dat.ps->buf, dat.width, dat.height, 8, icc_id, 0.0); // PDF bounding-box has origin on bottom-left - pdf_image->bb_x = dt_pdf_pixel_to_point((float)margin_left, ps->prt.printer.resolution); - pdf_image->bb_y = dt_pdf_pixel_to_point((float)margin_bottom, ps->prt.printer.resolution); - pdf_image->bb_width = dt_pdf_pixel_to_point((float)iwidth, ps->prt.printer.resolution); + pdf_image->bb_x = dt_pdf_pixel_to_point((float)margin_left, ps->prt.printer.resolution); + pdf_image->bb_y = dt_pdf_pixel_to_point((float)margin_bottom, ps->prt.printer.resolution); + pdf_image->bb_width = dt_pdf_pixel_to_point((float)iwidth, ps->prt.printer.resolution); pdf_image->bb_height = dt_pdf_pixel_to_point((float)iheight, ps->prt.printer.resolution); - if (ps->prt.page.landscape && (dat.width > dat.height)) + if(ps->prt.page.landscape && (dat.width > dat.height)) pdf_image->rotate_to_fit = TRUE; else pdf_image->rotate_to_fit = FALSE; @@ -347,13 +340,13 @@ _print_button_clicked (GtkWidget *widget, gpointer user_data) // free memory - free (dat.ps->buf); - free (pdf_image); - free (pdf_page); + free(dat.ps->buf); + free(pdf_image); + free(pdf_page); // send to CUPS - dt_print_file (imgid, filename, &ps->prt); + dt_print_file(imgid, filename, &ps->prt); g_unlink(filename); @@ -361,7 +354,7 @@ _print_button_clicked (GtkWidget *widget, gpointer user_data) char tag[256] = { 0 }; guint tagid = 0; - snprintf (tag, sizeof(tag), "darktable|printed|%s", ps->prt.printer.name); + snprintf(tag, sizeof(tag), "darktable|printed|%s", ps->prt.printer.name); dt_tag_new(tag, &tagid); dt_tag_attach(tagid, imgid); } @@ -369,9 +362,9 @@ _print_button_clicked (GtkWidget *widget, gpointer user_data) static void _set_printer(const dt_lib_module_t *self, const char *printer_name) { dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; - dt_printer_info_t *printer = dt_get_printer_info (printer_name); + dt_printer_info_t *printer = dt_get_printer_info(printer_name); - if (!printer) return; + if(!printer) return; memcpy(&ps->prt.printer, printer, sizeof(dt_printer_info_t)); free(printer); @@ -379,22 +372,22 @@ static void _set_printer(const dt_lib_module_t *self, const char *printer_name) // if there is 0 hardware margins, set the user marging to 15mm - if (ps->prt.printer.hw_margin_top == 0) + if(ps->prt.printer.hw_margin_top == 0) { ps->prt.page.margin_top = 15; gtk_spin_button_set_value(GTK_SPIN_BUTTON(ps->b_top), ps->prt.page.margin_top * units[ps->unit]); } - if (ps->prt.printer.hw_margin_bottom == 0) + if(ps->prt.printer.hw_margin_bottom == 0) { ps->prt.page.margin_bottom = 15; gtk_spin_button_set_value(GTK_SPIN_BUTTON(ps->b_bottom), ps->prt.page.margin_bottom * units[ps->unit]); } - if (ps->prt.printer.hw_margin_left == 0) + if(ps->prt.printer.hw_margin_left == 0) { ps->prt.page.margin_left = 15; gtk_spin_button_set_value(GTK_SPIN_BUTTON(ps->b_left), ps->prt.page.margin_left * units[ps->unit]); } - if (ps->prt.printer.hw_margin_right == 0) + if(ps->prt.printer.hw_margin_right == 0) { ps->prt.page.margin_right = 15; gtk_spin_button_set_value(GTK_SPIN_BUTTON(ps->b_right), ps->prt.page.margin_right * units[ps->unit]); @@ -414,58 +407,53 @@ static void _set_printer(const dt_lib_module_t *self, const char *printer_name) if(ps->paper_list) g_list_free_full(ps->paper_list, free); - ps->paper_list = dt_get_papers (printer_name); + ps->paper_list = dt_get_papers(printer_name); GList *papers = ps->paper_list; int np = 0; gboolean ispaperset = FALSE; - while (papers) + while(papers) { const dt_paper_info_t *p = (dt_paper_info_t *)papers->data; dt_bauhaus_combobox_add(ps->papers, p->common_name); - if (ispaperset == FALSE && (!g_strcmp0(default_paper, p->common_name) || default_paper[0] == '\0')) + if(ispaperset == FALSE && (!g_strcmp0(default_paper, p->common_name) || default_paper[0] == '\0')) { dt_bauhaus_combobox_set(ps->papers, np); ispaperset = TRUE; } np++; - papers = g_list_next (papers); + papers = g_list_next(papers); } const dt_paper_info_t *paper = dt_get_paper(ps->paper_list, default_paper); - if (paper) - memcpy(&ps->prt.paper, paper, sizeof(dt_paper_info_t)); + if(paper) memcpy(&ps->prt.paper, paper, sizeof(dt_paper_info_t)); - g_free (default_paper); + g_free(default_paper); dt_view_print_settings(darktable.view_manager, &ps->prt); } -static void -_printer_changed (GtkWidget *combo, const dt_lib_module_t *self) +static void _printer_changed(GtkWidget *combo, const dt_lib_module_t *self) { const gchar *printer_name = dt_bauhaus_combobox_get_text(combo); - if (printer_name) - _set_printer (self, printer_name); + if(printer_name) _set_printer(self, printer_name); } -static void -_paper_changed (GtkWidget *combo, const dt_lib_module_t *self) +static void _paper_changed(GtkWidget *combo, const dt_lib_module_t *self) { dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; const gchar *paper_name = dt_bauhaus_combobox_get_text(combo); - if (!paper_name) return; + if(!paper_name) return; const dt_paper_info_t *paper = dt_get_paper(ps->paper_list, paper_name); - if (paper) - memcpy(&ps->prt.paper, paper, sizeof(dt_paper_info_t)); + if(paper) memcpy(&ps->prt.paper, paper, sizeof(dt_paper_info_t)); ps->iwidth = ps->iheight = 0; @@ -480,22 +468,21 @@ static double to_mm(dt_lib_print_settings_t *ps, double value) return value / units[ps->unit]; } -static void -_update_slider (dt_lib_print_settings_t *ps) +static void _update_slider(dt_lib_print_settings_t *ps) { dt_view_print_settings(darktable.view_manager, &ps->prt); // if widget are created, let's display the current image size - if (ps->image_id != -1 && ps->width && ps->height && ps->info) + if(ps->image_id != -1 && ps->width && ps->height && ps->info) { - int32_t px=0, py=0, pwidth=0, pheight=0; - int32_t ax=0, ay=0, awidth=0, aheight=0; - int32_t ix=0, iy=0, iwidth=0, iheight=0; - int32_t iwpix=ps->iwidth, ihpix=ps->iheight; + int32_t px = 0, py = 0, pwidth = 0, pheight = 0; + int32_t ax = 0, ay = 0, awidth = 0, aheight = 0; + int32_t ix = 0, iy = 0, iwidth = 0, iheight = 0; + int32_t iwpix = ps->iwidth, ihpix = ps->iheight; int32_t pa_width, pa_height; - if (ps->prt.page.landscape) + if(ps->prt.page.landscape) { pa_height = (int32_t)ps->prt.paper.width; pa_width = (int32_t)ps->prt.paper.height; @@ -506,13 +493,10 @@ _update_slider (dt_lib_print_settings_t *ps) pa_height = (int32_t)ps->prt.paper.height; } - dt_get_print_layout(ps->image_id, &ps->prt, pa_width, pa_height, - &iwpix, &ihpix, - &px, &py, &pwidth, &pheight, - &ax, &ay, &awidth, &aheight, - &ix, &iy, &iwidth, &iheight); + dt_get_print_layout(ps->image_id, &ps->prt, pa_width, pa_height, &iwpix, &ihpix, &px, &py, &pwidth, &pheight, + &ax, &ay, &awidth, &aheight, &ix, &iy, &iwidth, &iheight); - if (ps->iwidth==0 || ps->iheight==0) + if(ps->iwidth == 0 || ps->iheight == 0) { ps->iwidth = iwpix; ps->iheight = ihpix; @@ -533,33 +517,36 @@ _update_slider (dt_lib_print_settings_t *ps) // compute the image down/up scale and report information double scale; - if (iwidth >= awidth) + if(iwidth >= awidth) scale = dt_pdf_point_to_pixel(dt_pdf_mm_to_point((double)awidth), ps->prt.printer.resolution) / ps->iwidth; else scale = dt_pdf_point_to_pixel(dt_pdf_mm_to_point((double)aheight), ps->prt.printer.resolution) / ps->iheight; - value = g_strdup_printf(_("%3.2f (dpi:%d)"), scale, scale<=1.0 ? (int)ps->prt.printer.resolution : (int)(ps->prt.printer.resolution / scale)); + value = g_strdup_printf(_("%3.2f (dpi:%d)"), scale, scale <= 1.0 ? (int)ps->prt.printer.resolution + : (int)(ps->prt.printer.resolution / scale)); gtk_label_set_text(GTK_LABEL(ps->info), value); g_free(value); } - // set the max range for the borders depending on the others border and never allow to have an image size of 0 or less + // set the max range for the borders depending on the others border and never allow to have an image size of 0 or + // less const int min_size = 5; // minimum size in mm - const int pa_max_height = ps->prt.paper.height - ps->prt.printer.hw_margin_top - ps->prt.printer.hw_margin_bottom - min_size; - const int pa_max_width = ps->prt.paper.width - ps->prt.printer.hw_margin_left - ps->prt.printer.hw_margin_right - min_size; - - gtk_spin_button_set_range (GTK_SPIN_BUTTON(ps->b_top), - min_borders * units[ps->unit], (pa_max_height - ps->prt.page.margin_bottom) * units[ps->unit]); - gtk_spin_button_set_range (GTK_SPIN_BUTTON(ps->b_left), - min_borders * units[ps->unit], (pa_max_width - ps->prt.page.margin_right) * units[ps->unit]); - gtk_spin_button_set_range (GTK_SPIN_BUTTON(ps->b_right), - min_borders * units[ps->unit], (pa_max_width - ps->prt.page.margin_left) * units[ps->unit]); - gtk_spin_button_set_range (GTK_SPIN_BUTTON(ps->b_bottom), - min_borders * units[ps->unit], (pa_max_height - ps->prt.page.margin_top) * units[ps->unit]); + const int pa_max_height = ps->prt.paper.height - ps->prt.printer.hw_margin_top - ps->prt.printer.hw_margin_bottom + - min_size; + const int pa_max_width = ps->prt.paper.width - ps->prt.printer.hw_margin_left - ps->prt.printer.hw_margin_right + - min_size; + + gtk_spin_button_set_range(GTK_SPIN_BUTTON(ps->b_top), min_borders * units[ps->unit], + (pa_max_height - ps->prt.page.margin_bottom) * units[ps->unit]); + gtk_spin_button_set_range(GTK_SPIN_BUTTON(ps->b_left), min_borders * units[ps->unit], + (pa_max_width - ps->prt.page.margin_right) * units[ps->unit]); + gtk_spin_button_set_range(GTK_SPIN_BUTTON(ps->b_right), min_borders * units[ps->unit], + (pa_max_width - ps->prt.page.margin_left) * units[ps->unit]); + gtk_spin_button_set_range(GTK_SPIN_BUTTON(ps->b_bottom), min_borders * units[ps->unit], + (pa_max_height - ps->prt.page.margin_top) * units[ps->unit]); } -static void -_top_border_callback (GtkWidget *spin, gpointer user_data) +static void _top_border_callback(GtkWidget *spin, gpointer user_data) { const dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; @@ -567,7 +554,7 @@ _top_border_callback (GtkWidget *spin, gpointer user_data) ps->prt.page.margin_top = to_mm(ps, value); - if (ps->lock_activated == TRUE) + if(ps->lock_activated == TRUE) { ps->prt.page.margin_bottom = to_mm(ps, value); ps->prt.page.margin_left = to_mm(ps, value); @@ -578,44 +565,40 @@ _top_border_callback (GtkWidget *spin, gpointer user_data) gtk_spin_button_set_value(GTK_SPIN_BUTTON(ps->b_right), value); } - _update_slider (ps); + _update_slider(ps); } -static void -_bottom_border_callback (GtkWidget *spin, gpointer user_data) +static void _bottom_border_callback(GtkWidget *spin, gpointer user_data) { const dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; const double value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin)); ps->prt.page.margin_bottom = to_mm(ps, value); - _update_slider (ps); + _update_slider(ps); } -static void -_left_border_callback (GtkWidget *spin, gpointer user_data) +static void _left_border_callback(GtkWidget *spin, gpointer user_data) { const dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; const double value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin)); ps->prt.page.margin_left = to_mm(ps, value); - _update_slider (ps); + _update_slider(ps); } -static void -_right_border_callback (GtkWidget *spin, gpointer user_data) +static void _right_border_callback(GtkWidget *spin, gpointer user_data) { const dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; const double value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin)); ps->prt.page.margin_right = to_mm(ps, value); - _update_slider (ps); + _update_slider(ps); } -static void -_lock_callback (GtkWidget *button, gpointer user_data) +static void _lock_callback(GtkWidget *button, gpointer user_data) { const dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; @@ -635,47 +618,45 @@ _lock_callback (GtkWidget *button, gpointer user_data) gtk_spin_button_set_value(GTK_SPIN_BUTTON(ps->b_left), value); gtk_spin_button_set_value(GTK_SPIN_BUTTON(ps->b_right), value); - _update_slider (ps); + _update_slider(ps); } -static void -_alignment_callback(GtkWidget *tb, gpointer user_data) +static void _alignment_callback(GtkWidget *tb, gpointer user_data) { - int index=-1; + int index = -1; const dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; - for(int i=0; i<9; i++) + for(int i = 0; i < 9; i++) { /* block signal handler */ - g_signal_handlers_block_by_func (ps->dtba[i],_alignment_callback,user_data); + g_signal_handlers_block_by_func(ps->dtba[i], _alignment_callback, user_data); - if( GTK_WIDGET(ps->dtba[i]) == tb ) + if(GTK_WIDGET(ps->dtba[i]) == tb) { - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ps->dtba[i]),TRUE); - index=i; + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ps->dtba[i]), TRUE); + index = i; } - else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ps->dtba[i]),FALSE); + else + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ps->dtba[i]), FALSE); /* unblock signal handler */ - g_signal_handlers_unblock_by_func (ps->dtba[i],_alignment_callback,user_data); + g_signal_handlers_unblock_by_func(ps->dtba[i], _alignment_callback, user_data); } ps->prt.page.alignment = index; - _update_slider (ps); + _update_slider(ps); } -static void -_orientation_changed (GtkWidget *combo, dt_lib_module_t *self) +static void _orientation_changed(GtkWidget *combo, dt_lib_module_t *self) { dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; - ps->prt.page.landscape = dt_bauhaus_combobox_get (combo); + ps->prt.page.landscape = dt_bauhaus_combobox_get(combo); - _update_slider (ps); + _update_slider(ps); } -static void -_unit_changed (GtkWidget *combo, dt_lib_module_t *self) +static void _unit_changed(GtkWidget *combo, dt_lib_module_t *self) { dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; @@ -691,10 +672,10 @@ _unit_changed (GtkWidget *combo, dt_lib_module_t *self) const int n_digits = (int)(1.0 / (units[ps->unit] * 10.0)); - gtk_spin_button_set_digits(GTK_SPIN_BUTTON(ps->b_top), n_digits); + gtk_spin_button_set_digits(GTK_SPIN_BUTTON(ps->b_top), n_digits); gtk_spin_button_set_digits(GTK_SPIN_BUTTON(ps->b_bottom), n_digits); - gtk_spin_button_set_digits(GTK_SPIN_BUTTON(ps->b_left), n_digits); - gtk_spin_button_set_digits(GTK_SPIN_BUTTON(ps->b_right), n_digits); + gtk_spin_button_set_digits(GTK_SPIN_BUTTON(ps->b_left), n_digits); + gtk_spin_button_set_digits(GTK_SPIN_BUTTON(ps->b_right), n_digits); const float incr = units[ps->unit]; @@ -703,18 +684,16 @@ _unit_changed (GtkWidget *combo, dt_lib_module_t *self) gtk_spin_button_set_increments(GTK_SPIN_BUTTON(ps->b_left), incr, incr); gtk_spin_button_set_increments(GTK_SPIN_BUTTON(ps->b_right), incr, incr); - _update_slider (ps); + _update_slider(ps); // convert margins to new unit - gtk_spin_button_set_value(GTK_SPIN_BUTTON(ps->b_top), margin_top * units[ps->unit]); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(ps->b_top), margin_top * units[ps->unit]); gtk_spin_button_set_value(GTK_SPIN_BUTTON(ps->b_bottom), margin_bottom * units[ps->unit]); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(ps->b_left), margin_left * units[ps->unit]); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(ps->b_right), margin_right * units[ps->unit]); - + gtk_spin_button_set_value(GTK_SPIN_BUTTON(ps->b_left), margin_left * units[ps->unit]); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(ps->b_right), margin_right * units[ps->unit]); } -static void -_style_callback(GtkWidget *widget, dt_lib_module_t *self) +static void _style_callback(GtkWidget *widget, dt_lib_module_t *self) { dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; @@ -734,8 +713,7 @@ _style_callback(GtkWidget *widget, dt_lib_module_t *self) ps->v_style = dt_conf_get_string("plugins/print/print/style"); } -static void -_style_mode_changed(GtkWidget *widget, dt_lib_module_t *self) +static void _style_mode_changed(GtkWidget *widget, dt_lib_module_t *self) { dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; @@ -747,8 +725,7 @@ _style_mode_changed(GtkWidget *widget, dt_lib_module_t *self) dt_conf_set_bool("plugins/print/print/style_append", ps->v_style_append); } -static void -_profile_changed(GtkWidget *widget, dt_lib_module_t *self) +static void _profile_changed(GtkWidget *widget, dt_lib_module_t *self) { dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; const int pos = dt_bauhaus_combobox_get(widget); @@ -774,8 +751,7 @@ _profile_changed(GtkWidget *widget, dt_lib_module_t *self) ps->v_iccprofile = g_strdup(""); } -static void -_printer_profile_changed(GtkWidget *widget, dt_lib_module_t *self) +static void _printer_profile_changed(GtkWidget *widget, dt_lib_module_t *self) { dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; const int pos = dt_bauhaus_combobox_get(widget); @@ -807,8 +783,7 @@ _printer_profile_changed(GtkWidget *widget, dt_lib_module_t *self) gtk_widget_set_sensitive(GTK_WIDGET(ps->black_point_compensation), FALSE); } -static void -_printer_intent_callback (GtkWidget *widget, dt_lib_module_t *self) +static void _printer_intent_callback(GtkWidget *widget, dt_lib_module_t *self) { dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; const int pos = dt_bauhaus_combobox_get(widget); @@ -816,16 +791,14 @@ _printer_intent_callback (GtkWidget *widget, dt_lib_module_t *self) ps->v_pintent = pos; } -static void -_printer_bpc_callback (GtkWidget *widget, dt_lib_module_t *self) +static void _printer_bpc_callback(GtkWidget *widget, dt_lib_module_t *self) { dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; ps->v_black_point_compensation = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ps->black_point_compensation)); dt_conf_set_bool("plugins/print/print/black_point_compensation", ps->v_black_point_compensation); } -static void -_intent_callback (GtkWidget *widget, dt_lib_module_t *self) +static void _intent_callback(GtkWidget *widget, dt_lib_module_t *self) { dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; const int pos = dt_bauhaus_combobox_get(widget); @@ -836,13 +809,12 @@ _intent_callback (GtkWidget *widget, dt_lib_module_t *self) static void _set_orientation(dt_lib_print_settings_t *ps) { - if (ps->image_id <= 0) - return; + if(ps->image_id <= 0) return; dt_mipmap_buffer_t buf; dt_mipmap_cache_get(darktable.mipmap_cache, &buf, ps->image_id, DT_MIPMAP_3, DT_MIPMAP_BEST_EFFORT, 'r'); - if (buf.width > buf.height) + if(buf.width > buf.height) ps->prt.page.landscape = TRUE; else ps->prt.page.landscape = FALSE; @@ -850,7 +822,7 @@ static void _set_orientation(dt_lib_print_settings_t *ps) dt_mipmap_cache_release(darktable.mipmap_cache, &buf); } -static void _print_settings_filmstrip_activate_callback(gpointer instance,gpointer user_data) +static void _print_settings_filmstrip_activate_callback(gpointer instance, gpointer user_data) { const dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; @@ -858,12 +830,12 @@ static void _print_settings_filmstrip_activate_callback(gpointer instance,gpoint ps->image_id = dt_view_filmstrip_get_activated_imgid(darktable.view_manager); ps->iwidth = ps->iheight = 0; - _set_orientation (ps); + _set_orientation(ps); - dt_bauhaus_combobox_set (ps->orientation, ps->prt.page.landscape==TRUE?1:0); + dt_bauhaus_combobox_set(ps->orientation, ps->prt.page.landscape == TRUE ? 1 : 0); } -static GList* _get_profiles () +static GList *_get_profiles() { // Create list of profiles GList *list = NULL; @@ -905,7 +877,7 @@ static void _new_printer_callback(dt_printer_info_t *printer, void *user_data) { static int count = 0; const dt_lib_module_t *self = (dt_lib_module_t *)user_data; - const dt_lib_print_settings_t *d = (dt_lib_print_settings_t*)self->data; + const dt_lib_print_settings_t *d = (dt_lib_print_settings_t *)self->data; char *default_printer = dt_conf_get_string("plugins/print/print/printer"); @@ -913,7 +885,7 @@ static void _new_printer_callback(dt_printer_info_t *printer, void *user_data) dt_bauhaus_combobox_add(d->printers, printer->name); - if (!g_strcmp0(default_printer, printer->name) || default_printer[0]=='\0') + if(!g_strcmp0(default_printer, printer->name) || default_printer[0] == '\0') { dt_bauhaus_combobox_set(d->printers, count); _set_printer(self, printer->name); @@ -924,10 +896,9 @@ static void _new_printer_callback(dt_printer_info_t *printer, void *user_data) g_signal_handlers_unblock_by_func(G_OBJECT(d->printers), G_CALLBACK(_printer_changed), NULL); } -void -gui_init (dt_lib_module_t *self) +void gui_init(dt_lib_module_t *self) { - dt_lib_print_settings_t *d = (dt_lib_print_settings_t*)malloc(sizeof(dt_lib_print_settings_t)); + dt_lib_print_settings_t *d = (dt_lib_print_settings_t *)malloc(sizeof(dt_lib_print_settings_t)); self->data = d; self->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); @@ -950,10 +921,8 @@ gui_init (dt_lib_module_t *self) dt_init_print_info(&d->prt); dt_view_print_settings(darktable.view_manager, &d->prt); - dt_control_signal_connect(darktable.signals, - DT_SIGNAL_VIEWMANAGER_FILMSTRIP_ACTIVATE, - G_CALLBACK(_print_settings_filmstrip_activate_callback), - self); + dt_control_signal_connect(darktable.signals, DT_SIGNAL_VIEWMANAGER_FILMSTRIP_ACTIVATE, + G_CALLBACK(_print_settings_filmstrip_activate_callback), self); d->profiles = _get_profiles(); @@ -973,15 +942,15 @@ gui_init (dt_lib_module_t *self) // create the spin-button now as values could be set when the printer has no hardware margin - d->b_top = gtk_spin_button_new_with_range(0, 1000, 1); - d->b_left = gtk_spin_button_new_with_range(0, 1000, 1); - d->b_right = gtk_spin_button_new_with_range(0, 1000, 1); + d->b_top = gtk_spin_button_new_with_range(0, 1000, 1); + d->b_left = gtk_spin_button_new_with_range(0, 1000, 1); + d->b_right = gtk_spin_button_new_with_range(0, 1000, 1); d->b_bottom = gtk_spin_button_new_with_range(0, 1000, 1); - gtk_entry_set_alignment (GTK_ENTRY(d->b_top), 1); - gtk_entry_set_alignment (GTK_ENTRY(d->b_left), 1); - gtk_entry_set_alignment (GTK_ENTRY(d->b_right), 1); - gtk_entry_set_alignment (GTK_ENTRY(d->b_bottom), 1); + gtk_entry_set_alignment(GTK_ENTRY(d->b_top), 1); + gtk_entry_set_alignment(GTK_ENTRY(d->b_left), 1); + gtk_entry_set_alignment(GTK_ENTRY(d->b_right), 1); + gtk_entry_set_alignment(GTK_ENTRY(d->b_bottom), 1); dt_gui_key_accel_block_on_focus_connect(GTK_WIDGET(d->b_top)); dt_gui_key_accel_block_on_focus_connect(GTK_WIDGET(d->b_left)); @@ -1024,8 +993,8 @@ gui_init (dt_lib_module_t *self) { dt_bauhaus_combobox_add(d->pprofile, prof->name); prof->ppos = ++n; - if(prof->type == printer_profile_type && - (prof->type != DT_COLORSPACE_FILE || !g_strcmp0(prof->filename, printer_profile))) + if(prof->type == printer_profile_type + && (prof->type != DT_COLORSPACE_FILE || !g_strcmp0(prof->filename, printer_profile))) { g_free(d->v_piccprofile); d->v_picctype = printer_profile_type; @@ -1036,10 +1005,10 @@ gui_init (dt_lib_module_t *self) l = g_list_next(l); } - g_free (printer_profile); + g_free(printer_profile); // profile not found, maybe a profile has been removed? revert to none - if (combo_idx == -1) + if(combo_idx == -1) { dt_conf_set_int("plugins/print/printer/icctype", DT_COLORSPACE_NONE); dt_conf_set_string("plugins/print/printer/iccprofile", ""); @@ -1067,7 +1036,7 @@ gui_init (dt_lib_module_t *self) d->v_pintent = dt_conf_get_int("plugins/print/printer/iccintent"); dt_bauhaus_combobox_set(d->pintent, d->v_pintent); - g_signal_connect (G_OBJECT (d->pintent), "value-changed", G_CALLBACK (_printer_intent_callback), (gpointer)self); + g_signal_connect(G_OBJECT(d->pintent), "value-changed", G_CALLBACK(_printer_intent_callback), (gpointer)self); d->black_point_compensation = gtk_check_button_new_with_label(_("black point compensation")); gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(d->black_point_compensation), TRUE, FALSE, 0); @@ -1079,8 +1048,8 @@ gui_init (dt_lib_module_t *self) gtk_widget_set_tooltip_text(d->black_point_compensation, _("activate black point compensation when applying the printer profile")); - gtk_widget_set_sensitive(GTK_WIDGET(d->pintent), combo_idx==0?FALSE:TRUE); - gtk_widget_set_sensitive(GTK_WIDGET(d->black_point_compensation), combo_idx==0?FALSE:TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(d->pintent), combo_idx == 0 ? FALSE : TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(d->black_point_compensation), combo_idx == 0 ? FALSE : TRUE); ////////////////////////// PAGE SETTINGS @@ -1115,32 +1084,31 @@ gui_init (dt_lib_module_t *self) d->unit = dt_conf_get_int("plugins/print/print/unit"); dt_bauhaus_combobox_set(ucomb, d->unit); - dt_bauhaus_combobox_set (d->orientation, d->prt.page.landscape?1:0); + dt_bauhaus_combobox_set(d->orientation, d->prt.page.landscape ? 1 : 0); //// image dimensions, create them now as we need them - GtkWidget *hboxdim = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0); + GtkWidget *hboxdim = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); label = gtk_label_new(_("image width/height")); - gtk_box_pack_start(GTK_BOX(hboxdim),GTK_WIDGET(label),TRUE,TRUE,0); + gtk_box_pack_start(GTK_BOX(hboxdim), GTK_WIDGET(label), TRUE, TRUE, 0); d->width = gtk_label_new(_("width")); - gtk_box_pack_start(GTK_BOX(hboxdim),GTK_WIDGET(d->width),TRUE,TRUE,0); + gtk_box_pack_start(GTK_BOX(hboxdim), GTK_WIDGET(d->width), TRUE, TRUE, 0); label = gtk_label_new(_(" x ")); - gtk_box_pack_start(GTK_BOX(hboxdim),GTK_WIDGET(label),TRUE,TRUE,0); + gtk_box_pack_start(GTK_BOX(hboxdim), GTK_WIDGET(label), TRUE, TRUE, 0); d->height = gtk_label_new(_("height")); - gtk_box_pack_start(GTK_BOX(hboxdim),GTK_WIDGET(d->height),TRUE,TRUE,0); + gtk_box_pack_start(GTK_BOX(hboxdim), GTK_WIDGET(d->height), TRUE, TRUE, 0); //// image information (downscale/upscale) - GtkWidget *hboxinfo = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0); + GtkWidget *hboxinfo = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); label = gtk_label_new(_("scale factor")); - gtk_box_pack_start(GTK_BOX(hboxinfo),GTK_WIDGET(label),TRUE,TRUE,0); + gtk_box_pack_start(GTK_BOX(hboxinfo), GTK_WIDGET(label), TRUE, TRUE, 0); d->info = gtk_label_new("1.0"); - gtk_box_pack_start(GTK_BOX(hboxinfo),GTK_WIDGET(d->info),TRUE,TRUE,0); - gtk_widget_set_tooltip_text(hboxinfo, - _("image scale factor from native printer DPI:\n" - " < 1 means that it is downscaled (best quality)\n" - " > 1 means that the image is upscaled\n" - " a too large value may result in poor print quality")); + gtk_box_pack_start(GTK_BOX(hboxinfo), GTK_WIDGET(d->info), TRUE, TRUE, 0); + gtk_widget_set_tooltip_text(hboxinfo, _("image scale factor from native printer DPI:\n" + " < 1 means that it is downscaled (best quality)\n" + " > 1 means that the image is upscaled\n" + " a too large value may result in poor print quality")); //// borders @@ -1150,11 +1118,11 @@ gui_init (dt_lib_module_t *self) d->lock_activated = FALSE; - //d->b_top = gtk_spin_button_new_with_range(0, 10000, 1); + // d->b_top = gtk_spin_button_new_with_range(0, 10000, 1); gtk_widget_set_tooltip_text(GTK_WIDGET(d->b_top), _("top margin")); gtk_grid_attach(bds, GTK_WIDGET(d->b_top), 1, 0, 1, 1); - //d->b_left = gtk_spin_button_new_with_range(0, 10000, 1); + // d->b_left = gtk_spin_button_new_with_range(0, 10000, 1); gtk_widget_set_tooltip_text(GTK_WIDGET(d->b_left), _("left margin")); gtk_grid_attach(bds, GTK_WIDGET(d->b_left), 0, 1, 1, 1); @@ -1162,26 +1130,21 @@ gui_init (dt_lib_module_t *self) gtk_widget_set_tooltip_text(GTK_WIDGET(d->lock_button), _("change all margins uniformly")); gtk_grid_attach(bds, GTK_WIDGET(d->lock_button), 1, 1, 1, 1); - //d->b_right = gtk_spin_button_new_with_range(0, 10000, 1); + // d->b_right = gtk_spin_button_new_with_range(0, 10000, 1); gtk_widget_set_tooltip_text(GTK_WIDGET(d->b_right), _("right margin")); gtk_grid_attach(bds, GTK_WIDGET(d->b_right), 2, 1, 1, 1); - //d->b_bottom = gtk_spin_button_new_with_range(0, 10000, 1); + // d->b_bottom = gtk_spin_button_new_with_range(0, 10000, 1); gtk_widget_set_tooltip_text(GTK_WIDGET(d->b_bottom), _("bottom margin")); gtk_grid_attach(bds, GTK_WIDGET(d->b_bottom), 1, 2, 1, 1); gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(bds), TRUE, TRUE, 0); - g_signal_connect (G_OBJECT (d->b_top), "value-changed", - G_CALLBACK (_top_border_callback), self); - g_signal_connect (G_OBJECT (d->b_bottom), "value-changed", - G_CALLBACK (_bottom_border_callback), self); - g_signal_connect (G_OBJECT (d->b_left), "value-changed", - G_CALLBACK (_left_border_callback), self); - g_signal_connect (G_OBJECT (d->b_right), "value-changed", - G_CALLBACK (_right_border_callback), self); - g_signal_connect (G_OBJECT(d->lock_button), "toggled", - G_CALLBACK(_lock_callback), self); + g_signal_connect(G_OBJECT(d->b_top), "value-changed", G_CALLBACK(_top_border_callback), self); + g_signal_connect(G_OBJECT(d->b_bottom), "value-changed", G_CALLBACK(_bottom_border_callback), self); + g_signal_connect(G_OBJECT(d->b_left), "value-changed", G_CALLBACK(_left_border_callback), self); + g_signal_connect(G_OBJECT(d->b_right), "value-changed", G_CALLBACK(_right_border_callback), self); + g_signal_connect(G_OBJECT(d->lock_button), "toggled", G_CALLBACK(_lock_callback), self); const gboolean lock_active = dt_conf_get_bool("plugins/print/print/lock_borders"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(d->lock_button), lock_active); @@ -1197,18 +1160,19 @@ gui_init (dt_lib_module_t *self) GtkGrid *bat = GTK_GRID(gtk_grid_new()); gtk_grid_set_row_spacing(bat, DT_PIXEL_APPLY_DPI(3)); gtk_grid_set_column_spacing(bat, DT_PIXEL_APPLY_DPI(3)); - for(int i=0; i<9; i++) + for(int i = 0; i < 9; i++) { - d->dtba[i] = DTGTK_TOGGLEBUTTON (dtgtk_togglebutton_new (dtgtk_cairo_paint_alignment,CPF_STYLE_FLAT|(CPF_SPECIAL_FLAG<<i))); - gtk_grid_attach (GTK_GRID (bat), GTK_WIDGET (d->dtba[i]), (i%3), i/3, 1, 1); - g_signal_connect (G_OBJECT (d->dtba[i]), "toggled",G_CALLBACK (_alignment_callback), self); + d->dtba[i] = DTGTK_TOGGLEBUTTON( + dtgtk_togglebutton_new(dtgtk_cairo_paint_alignment, CPF_STYLE_FLAT | (CPF_SPECIAL_FLAG << i))); + gtk_grid_attach(GTK_GRID(bat), GTK_WIDGET(d->dtba[i]), (i % 3), i / 3, 1, 1); + g_signal_connect(G_OBJECT(d->dtba[i]), "toggled", G_CALLBACK(_alignment_callback), self); } d->prt.page.alignment = ALIGNMENT_CENTER; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(d->dtba[d->prt.page.alignment]),TRUE); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(d->dtba[d->prt.page.alignment]), TRUE); - GtkWidget *hbox22 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0); + GtkWidget *hbox22 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); GtkWidget *label4 = gtk_label_new(_("alignment")); - gtk_box_pack_start(GTK_BOX(hbox22),GTK_WIDGET(label4),TRUE,TRUE,0); + gtk_box_pack_start(GTK_BOX(hbox22), GTK_WIDGET(label4), TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox22), GTK_WIDGET(bat), TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(hbox22), TRUE, TRUE, 0); @@ -1246,7 +1210,7 @@ gui_init (dt_lib_module_t *self) l = g_list_next(l); } - if (combo_idx == -1) + if(combo_idx == -1) { dt_conf_set_int("plugins/print/print/icctype", DT_COLORSPACE_NONE); dt_conf_set_string("plugins/print/print/iccprofile", ""); @@ -1255,7 +1219,7 @@ gui_init (dt_lib_module_t *self) d->v_iccprofile = g_strdup(""); combo_idx = 0; } - g_free (iccprofile); + g_free(iccprofile); dt_bauhaus_combobox_set(d->profile, combo_idx); @@ -1277,7 +1241,7 @@ gui_init (dt_lib_module_t *self) dt_bauhaus_combobox_set(d->intent, dt_conf_get_int("plugins/print/print/iccintent") + 1); - g_signal_connect (G_OBJECT (d->intent), "value-changed", G_CALLBACK (_intent_callback), (gpointer)self); + g_signal_connect(G_OBJECT(d->intent), "value-changed", G_CALLBACK(_intent_callback), (gpointer)self); // Add export style combo @@ -1288,20 +1252,21 @@ gui_init (dt_lib_module_t *self) GList *styles = dt_styles_get_list(""); gchar *current_style = dt_conf_get_string("plugins/print/print/style"); - combo_idx = -1; n=0; + combo_idx = -1; + n = 0; - while (styles) + while(styles) { - dt_style_t *style=(dt_style_t *)styles->data; + dt_style_t *style = (dt_style_t *)styles->data; dt_bauhaus_combobox_add(d->style, style->name); n++; - if (g_strcmp0(style->name,current_style)==0) + if(g_strcmp0(style->name, current_style) == 0) { g_free(d->v_style); d->v_style = g_strdup(current_style); - combo_idx=n; + combo_idx = n; } - styles=g_list_next(styles); + styles = g_list_next(styles); } g_free(current_style); g_list_free_full(styles, dt_style_free); @@ -1309,18 +1274,16 @@ gui_init (dt_lib_module_t *self) gtk_widget_set_tooltip_text(d->style, _("temporary style to use while printing")); // style not found, maybe a style has been removed? revert to none - if (combo_idx == -1) + if(combo_idx == -1) { dt_conf_set_string("plugins/print/print/style", ""); g_free(d->v_style); d->v_style = g_strdup(""); - combo_idx=0; + combo_idx = 0; } dt_bauhaus_combobox_set(d->style, combo_idx); - g_signal_connect (G_OBJECT (d->style), "value-changed", - G_CALLBACK (_style_callback), - (gpointer)self); + g_signal_connect(G_OBJECT(d->style), "value-changed", G_CALLBACK(_style_callback), (gpointer)self); // Whether to add/replace style items @@ -1331,13 +1294,13 @@ gui_init (dt_lib_module_t *self) dt_bauhaus_combobox_add(d->style_mode, _("append history")); d->v_style_append = dt_conf_get_bool("plugins/print/print/style_append"); - dt_bauhaus_combobox_set(d->style_mode, d->v_style_append?1:0); + dt_bauhaus_combobox_set(d->style_mode, d->v_style_append ? 1 : 0); gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(d->style_mode), TRUE, TRUE, 0); gtk_widget_set_tooltip_text(d->style_mode, _("whether the style items are appended to the history or replacing the history")); - gtk_widget_set_sensitive(GTK_WIDGET(d->style_mode), combo_idx==0?FALSE:TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(d->style_mode), combo_idx == 0 ? FALSE : TRUE); g_signal_connect(G_OBJECT(d->style_mode), "value-changed", G_CALLBACK(_style_mode_changed), (gpointer)self); @@ -1348,9 +1311,7 @@ gui_init (dt_lib_module_t *self) gtk_widget_set_tooltip_text(GTK_WIDGET(button), _("print with current settings")); gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(button), TRUE, TRUE, 0); - g_signal_connect (G_OBJECT (button), "clicked", - G_CALLBACK (_print_button_clicked), - (gpointer)self); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(_print_button_clicked), (gpointer)self); // Let's start the printer discovery now @@ -1366,7 +1327,7 @@ static gboolean _bauhaus_combobox_set_active_text(GtkWidget *cb, const gchar *te int i = 0; while(iter) { - if(!g_strcmp0((gchar*)iter->data, text)) + if(!g_strcmp0((gchar *)iter->data, text)) { dt_bauhaus_combobox_set(cb, i); return TRUE; @@ -1422,7 +1383,7 @@ void *legacy_params(dt_lib_module_t *self, const void *const old_params, const s // landscape const int32_t landscape = *(int32_t *)buf; - buf += sizeof(int32_t); + buf += sizeof(int32_t); // profile const char *profile = buf; @@ -1538,23 +1499,23 @@ int set_params(dt_lib_module_t *self, const void *params, int size) // get individual items const char *printer = buf; - if (!printer) return 1; + if(!printer) return 1; const int32_t printer_len = strlen(printer) + 1; buf += printer_len; const char *paper = buf; - if (!paper) return 1; + if(!paper) return 1; const int32_t paper_len = strlen(paper) + 1; buf += paper_len; const int32_t landscape = *(int32_t *)buf; - buf += sizeof(int32_t); + buf += sizeof(int32_t); const int32_t f_profile_type = *(int32_t *)buf; - buf += sizeof(int32_t); + buf += sizeof(int32_t); const char *f_profile = buf; - if (!f_profile) return 1; + if(!f_profile) return 1; const int32_t profile_len = strlen(f_profile) + 1; buf += profile_len; @@ -1562,10 +1523,10 @@ int set_params(dt_lib_module_t *self, const void *params, int size) buf += sizeof(int32_t); const int32_t f_pprofile_type = *(int32_t *)buf; - buf += sizeof(int32_t); + buf += sizeof(int32_t); const char *f_pprofile = buf; - if (!f_pprofile) return 1; + if(!f_pprofile) return 1; const int32_t pprofile_len = strlen(f_pprofile) + 1; buf += pprofile_len; @@ -1576,7 +1537,7 @@ int set_params(dt_lib_module_t *self, const void *params, int size) buf += sizeof(int32_t); const char *style = buf; - if (!style) return 1; + if(!style) return 1; const int32_t style_len = strlen(style) + 1; buf += style_len; @@ -1596,20 +1557,19 @@ int set_params(dt_lib_module_t *self, const void *params, int size) buf += sizeof(double); const int32_t alignment = *(int32_t *)buf; -// buf += sizeof(int32_t); + // buf += sizeof(int32_t); // ensure that the size is correct - if(size != printer_len + paper_len + profile_len + pprofile_len + style_len + 8 * sizeof(int32_t) + 4 * sizeof(double)) + if(size + != printer_len + paper_len + profile_len + pprofile_len + style_len + 8 * sizeof(int32_t) + 4 * sizeof(double)) return 1; // set the GUI with corresponding values - if (printer[0] != '\0') - _bauhaus_combobox_set_active_text(ps->printers, printer); + if(printer[0] != '\0') _bauhaus_combobox_set_active_text(ps->printers, printer); - if (paper[0] != '\0') - _bauhaus_combobox_set_active_text(ps->papers, paper); + if(paper[0] != '\0') _bauhaus_combobox_set_active_text(ps->papers, paper); - dt_bauhaus_combobox_set (ps->orientation, landscape); + dt_bauhaus_combobox_set(ps->orientation, landscape); dt_bauhaus_combobox_set(ps->profile, 0); for(GList *iter = ps->profiles; iter; iter = g_list_next(iter)) @@ -1622,7 +1582,7 @@ int set_params(dt_lib_module_t *self, const void *params, int size) } } - dt_bauhaus_combobox_set (ps->intent, intent); + dt_bauhaus_combobox_set(ps->intent, intent); dt_bauhaus_combobox_set(ps->pprofile, 0); for(GList *iter = ps->profiles; iter; iter = g_list_next(iter)) @@ -1635,18 +1595,17 @@ int set_params(dt_lib_module_t *self, const void *params, int size) } } - dt_bauhaus_combobox_set (ps->pintent, pintent); + dt_bauhaus_combobox_set(ps->pintent, pintent); - if (style[0] != '\0') - _bauhaus_combobox_set_active_text(ps->style, style); - dt_bauhaus_combobox_set (ps->style_mode, style_mode); + if(style[0] != '\0') _bauhaus_combobox_set_active_text(ps->style, style); + dt_bauhaus_combobox_set(ps->style_mode, style_mode); - gtk_spin_button_set_value (GTK_SPIN_BUTTON(ps->b_top), b_top * units[ps->unit]); - gtk_spin_button_set_value (GTK_SPIN_BUTTON(ps->b_bottom), b_bottom * units[ps->unit]); - gtk_spin_button_set_value (GTK_SPIN_BUTTON(ps->b_left), b_left * units[ps->unit]); - gtk_spin_button_set_value (GTK_SPIN_BUTTON(ps->b_right), b_right * units[ps->unit]); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(ps->b_top), b_top * units[ps->unit]); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(ps->b_bottom), b_bottom * units[ps->unit]); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(ps->b_left), b_left * units[ps->unit]); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(ps->b_right), b_right * units[ps->unit]); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ps->dtba[alignment]),TRUE); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ps->dtba[alignment]), TRUE); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ps->black_point_compensation), bpc); return 0; @@ -1660,11 +1619,11 @@ void *get_params(dt_lib_module_t *self, int *size) const char *printer = dt_bauhaus_combobox_get_text(ps->printers); const char *paper = dt_bauhaus_combobox_get_text(ps->papers); const int32_t profile_pos = dt_bauhaus_combobox_get(ps->profile); - const int32_t intent = dt_bauhaus_combobox_get(ps->intent); + const int32_t intent = dt_bauhaus_combobox_get(ps->intent); const char *style = dt_bauhaus_combobox_get_text(ps->style); const int32_t style_mode = dt_bauhaus_combobox_get(ps->style_mode); const int32_t pprofile_pos = dt_bauhaus_combobox_get(ps->pprofile); - const int32_t pintent = dt_bauhaus_combobox_get(ps->pintent); + const int32_t pintent = dt_bauhaus_combobox_get(ps->pintent); const int32_t landscape = dt_bauhaus_combobox_get(ps->orientation); const int32_t bpc = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ps->black_point_compensation)); const double b_top = ps->prt.page.margin_top; @@ -1695,53 +1654,54 @@ void *get_params(dt_lib_module_t *self, int *size) if(!paper) paper = ""; // compute the size of individual items, always get the \0 for strings - const int32_t printer_len = strlen (printer) + 1; - const int32_t paper_len = strlen (paper) + 1; - const int32_t profile_len = strlen (profile) + 1; - const int32_t pprofile_len = strlen (pprofile) + 1; - const int32_t style_len = strlen (style) + 1; + const int32_t printer_len = strlen(printer) + 1; + const int32_t paper_len = strlen(paper) + 1; + const int32_t profile_len = strlen(profile) + 1; + const int32_t pprofile_len = strlen(pprofile) + 1; + const int32_t style_len = strlen(style) + 1; // compute the size of all parameters - *size = printer_len + paper_len + profile_len + pprofile_len + style_len + 8 * sizeof(int32_t) + 4 * sizeof(double); + *size = printer_len + paper_len + profile_len + pprofile_len + style_len + 8 * sizeof(int32_t) + + 4 * sizeof(double); // allocate the parameter buffer char *params = (char *)malloc(*size); int pos = 0; - memcpy(params+pos, printer, printer_len); + memcpy(params + pos, printer, printer_len); pos += printer_len; - memcpy(params+pos, paper, paper_len); + memcpy(params + pos, paper, paper_len); pos += paper_len; - memcpy(params+pos, &landscape, sizeof(int32_t)); + memcpy(params + pos, &landscape, sizeof(int32_t)); pos += sizeof(int32_t); - memcpy(params+pos, &profile_type, sizeof(int32_t)); + memcpy(params + pos, &profile_type, sizeof(int32_t)); pos += sizeof(int32_t); - memcpy(params+pos, profile, profile_len); + memcpy(params + pos, profile, profile_len); pos += profile_len; - memcpy(params+pos, &intent, sizeof(int32_t)); + memcpy(params + pos, &intent, sizeof(int32_t)); pos += sizeof(int32_t); - memcpy(params+pos, &pprofile_type, sizeof(int32_t)); + memcpy(params + pos, &pprofile_type, sizeof(int32_t)); pos += sizeof(int32_t); - memcpy(params+pos, pprofile, pprofile_len); + memcpy(params + pos, pprofile, pprofile_len); pos += pprofile_len; - memcpy(params+pos, &pintent, sizeof(int32_t)); + memcpy(params + pos, &pintent, sizeof(int32_t)); pos += sizeof(int32_t); - memcpy(params+pos, &bpc, sizeof(int32_t)); + memcpy(params + pos, &bpc, sizeof(int32_t)); pos += sizeof(int32_t); - memcpy(params+pos, style, style_len); + memcpy(params + pos, style, style_len); pos += style_len; - memcpy(params+pos, &style_mode, sizeof(int32_t)); + memcpy(params + pos, &style_mode, sizeof(int32_t)); pos += sizeof(int32_t); - memcpy(params+pos, &b_top, sizeof(double)); + memcpy(params + pos, &b_top, sizeof(double)); pos += sizeof(double); - memcpy(params+pos, &b_bottom, sizeof(double)); + memcpy(params + pos, &b_bottom, sizeof(double)); pos += sizeof(double); - memcpy(params+pos, &b_left, sizeof(double)); + memcpy(params + pos, &b_left, sizeof(double)); pos += sizeof(double); - memcpy(params+pos, &b_right, sizeof(double)); + memcpy(params + pos, &b_right, sizeof(double)); pos += sizeof(double); - memcpy(params+pos, &alignment, sizeof(int32_t)); + memcpy(params + pos, &alignment, sizeof(int32_t)); pos += sizeof(int32_t); g_assert(pos == *size); @@ -1749,8 +1709,7 @@ void *get_params(dt_lib_module_t *self, int *size) return params; } -void -gui_cleanup (dt_lib_module_t *self) +void gui_cleanup(dt_lib_module_t *self) { dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; @@ -1759,9 +1718,7 @@ gui_cleanup (dt_lib_module_t *self) dt_gui_key_accel_block_on_focus_disconnect(GTK_WIDGET(ps->b_right)); dt_gui_key_accel_block_on_focus_disconnect(GTK_WIDGET(ps->b_bottom)); - dt_control_signal_disconnect(darktable.signals, - G_CALLBACK(_print_settings_filmstrip_activate_callback), - self); + dt_control_signal_disconnect(darktable.signals, G_CALLBACK(_print_settings_filmstrip_activate_callback), self); g_list_free_full(ps->profiles, g_free); g_list_free_full(ps->paper_list, free); @@ -1774,8 +1731,7 @@ gui_cleanup (dt_lib_module_t *self) self->data = NULL; } -void -gui_reset (dt_lib_module_t *self) +void gui_reset(dt_lib_module_t *self) { dt_lib_print_settings_t *ps = (dt_lib_print_settings_t *)self->data; @@ -1797,9 +1753,9 @@ gui_reset (dt_lib_module_t *self) // reset page orientation to fit the picture - _set_orientation (ps); + _set_orientation(ps); - dt_bauhaus_combobox_set (ps->orientation, ps->prt.page.landscape?1:0); + dt_bauhaus_combobox_set(ps->orientation, ps->prt.page.landscape ? 1 : 0); } void init_key_accels(dt_lib_module_t *self) diff --git a/src/libs/recentcollect.c b/src/libs/recentcollect.c index 21bc01b77de9..6ba941d98ce1 100644 --- a/src/libs/recentcollect.c +++ b/src/libs/recentcollect.c @@ -53,7 +53,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"lighttable", "map", NULL}; + static const char *v[] = { "lighttable", "map", NULL }; return v; } @@ -288,8 +288,7 @@ static void _lib_recentcollection_updated(gpointer instance, gpointer user_data) gtk_button_set_label(GTK_BUTTON(d->item[k].button), str); } GtkWidget *child = gtk_bin_get_child(GTK_BIN(d->item[k].button)); - if(child) - gtk_widget_set_halign(child, GTK_ALIGN_START); + if(child) gtk_widget_set_halign(child, GTK_ALIGN_START); gtk_widget_set_no_show_all(d->item[k].button, TRUE); gtk_widget_set_visible(d->item[k].button, FALSE); } @@ -298,8 +297,7 @@ static void _lib_recentcollection_updated(gpointer instance, gpointer user_data) gtk_widget_set_no_show_all(d->item[k].button, FALSE); gtk_widget_set_visible(d->item[k].button, TRUE); } - if((new_pos != -1) && (new_pos != curr_pos)) - dt_view_lighttable_set_position(darktable.view_manager, new_pos); + if((new_pos != -1) && (new_pos != curr_pos)) dt_view_lighttable_set_position(darktable.view_manager, new_pos); } void gui_reset(dt_lib_module_t *self) @@ -334,8 +332,7 @@ void gui_init(dt_lib_module_t *self) gtk_widget_set_no_show_all(d->item[k].button, TRUE); gtk_widget_set_visible(d->item[k].button, FALSE); GtkWidget *child = gtk_bin_get_child(GTK_BIN(d->item[k].button)); - if(child) - gtk_widget_set_halign(child, GTK_ALIGN_START); + if(child) gtk_widget_set_halign(child, GTK_ALIGN_START); } _lib_recentcollection_updated(NULL, self); diff --git a/src/libs/select.c b/src/libs/select.c index 7f05509af221..74d3cc02aab1 100644 --- a/src/libs/select.c +++ b/src/libs/select.c @@ -42,7 +42,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"lighttable", NULL}; + static const char *v[] = { "lighttable", NULL }; return v; } @@ -85,7 +85,8 @@ int position() return 800; } -#define ellipsize_button(button) gtk_label_set_ellipsize(GTK_LABEL(gtk_bin_get_child(GTK_BIN(button))), PANGO_ELLIPSIZE_END); +#define ellipsize_button(button) \ + gtk_label_set_ellipsize(GTK_LABEL(gtk_bin_get_child(GTK_BIN(button))), PANGO_ELLIPSIZE_END); void gui_init(dt_lib_module_t *self) { dt_lib_select_t *d = (dt_lib_select_t *)malloc(sizeof(dt_lib_select_t)); @@ -123,7 +124,8 @@ void gui_init(dt_lib_module_t *self) button = gtk_button_new_with_label(_("select film roll")); ellipsize_button(button); d->select_film_roll_button = button; - gtk_widget_set_tooltip_text(button, _("select all images which are in the same\nfilm roll as the selected images")); + gtk_widget_set_tooltip_text(button, + _("select all images which are in the same\nfilm roll as the selected images")); gtk_grid_attach(grid, button, 1, line++, 1, 1); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(button_clicked), GINT_TO_POINTER(3)); @@ -144,20 +146,21 @@ void gui_cleanup(dt_lib_module_t *self) } #ifdef USE_LUA -typedef struct { - const char* key; - dt_lib_module_t * self; +typedef struct +{ + const char *key; + dt_lib_module_t *self; } lua_callback_data; -static int lua_button_clicked_cb(lua_State* L) +static int lua_button_clicked_cb(lua_State *L) { - lua_callback_data * data = lua_touserdata(L,1); - dt_lua_module_entry_push(L,"lib",data->self->plugin_name); - lua_getuservalue(L,-1); - lua_getfield(L,-1,"callbacks"); - lua_getfield(L,-1,data->key); - lua_pushstring(L,data->key); + lua_callback_data *data = lua_touserdata(L, 1); + dt_lua_module_entry_push(L, "lib", data->self->plugin_name); + lua_getuservalue(L, -1); + lua_getfield(L, -1, "callbacks"); + lua_getfield(L, -1, data->key); + lua_pushstring(L, data->key); GList *image = dt_collection_get_all(darktable.collection, -1); lua_newtable(L); @@ -168,7 +171,7 @@ static int lua_button_clicked_cb(lua_State* L) image = g_list_delete_link(image, image); } - lua_call(L,2,1); + lua_call(L, 2, 1); GList *new_selection = NULL; luaL_checktype(L, -1, LUA_TTABLE); @@ -186,40 +189,38 @@ static int lua_button_clicked_cb(lua_State* L) dt_selection_select_list(darktable.selection, new_selection); g_list_free(new_selection); return 0; - } static void lua_button_clicked(GtkWidget *widget, gpointer user_data) { - dt_lua_async_call_alien(lua_button_clicked_cb, - 0,NULL,NULL, - LUA_ASYNC_TYPENAME,"void*", user_data, - LUA_ASYNC_DONE); + dt_lua_async_call_alien(lua_button_clicked_cb, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "void*", user_data, + LUA_ASYNC_DONE); } static int lua_register_selection(lua_State *L) { - lua_settop(L,3); + lua_settop(L, 3); dt_lib_module_t *self = lua_touserdata(L, lua_upvalueindex(1)); - dt_lua_module_entry_push(L,"lib",self->plugin_name); - lua_getuservalue(L,-1); - const char* key = luaL_checkstring(L,1); - luaL_checktype(L,2,LUA_TFUNCTION); - - lua_getfield(L,-1,"callbacks"); - lua_pushstring(L,key); - lua_pushvalue(L,2); - lua_settable(L,-3); - - GtkWidget* button = gtk_button_new_with_label(key); - const char * tooltip = lua_tostring(L,3); - if(tooltip) { + dt_lua_module_entry_push(L, "lib", self->plugin_name); + lua_getuservalue(L, -1); + const char *key = luaL_checkstring(L, 1); + luaL_checktype(L, 2, LUA_TFUNCTION); + + lua_getfield(L, -1, "callbacks"); + lua_pushstring(L, key); + lua_pushvalue(L, 2); + lua_settable(L, -3); + + GtkWidget *button = gtk_button_new_with_label(key); + const char *tooltip = lua_tostring(L, 3); + if(tooltip) + { gtk_widget_set_tooltip_text(button, tooltip); } gtk_grid_attach_next_to(GTK_GRID(self->widget), button, NULL, GTK_POS_BOTTOM, 2, 1); - lua_callback_data * data = malloc(sizeof(lua_callback_data)); + lua_callback_data *data = malloc(sizeof(lua_callback_data)); data->key = strdup(key); data->self = self; g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(lua_button_clicked), data); @@ -233,16 +234,16 @@ void init(struct dt_lib_module_t *self) lua_State *L = darktable.lua_state.state; int my_type = dt_lua_module_entry_get_type(L, "lib", self->plugin_name); lua_pushlightuserdata(L, self); - lua_pushcclosure(L, lua_register_selection ,1); + lua_pushcclosure(L, lua_register_selection, 1); dt_lua_gtk_wrap(L); lua_pushcclosure(L, dt_lua_type_member_common, 1); dt_lua_type_register_const_type(L, my_type, "register_selection"); - dt_lua_module_entry_push(L,"lib",self->plugin_name); - lua_getuservalue(L,-1); + dt_lua_module_entry_push(L, "lib", self->plugin_name); + lua_getuservalue(L, -1); lua_newtable(L); - lua_setfield(L,-2,"callbacks"); - lua_pop(L,2); + lua_setfield(L, -2, "callbacks"); + lua_pop(L, 2); } #endif diff --git a/src/libs/session.c b/src/libs/session.c index ceebd5253c8b..a3e473ea0910 100644 --- a/src/libs/session.c +++ b/src/libs/session.c @@ -49,7 +49,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"tethering", NULL}; + static const char *v[] = { "tethering", NULL }; return v; } diff --git a/src/libs/snapshots.c b/src/libs/snapshots.c index 0f7ddbedbaa7..dc2c177c8776 100644 --- a/src/libs/snapshots.c +++ b/src/libs/snapshots.c @@ -81,7 +81,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"darkroom", NULL}; + static const char *v[] = { "darkroom", NULL }; return v; } @@ -121,10 +121,8 @@ void gui_post_expose(dt_lib_module_t *self, cairo_t *cri, int32_t width, int32_t /* set x,y,w,h of surface depending on split align and invert */ double x = d->vertical ? (d->inverted ? width * d->vp_xpointer : 0) : 0; double y = d->vertical ? 0 : (d->inverted ? height * d->vp_ypointer : 0); - double w = d->vertical ? (d->inverted ? (width * (1.0 - d->vp_xpointer)) : width * d->vp_xpointer) - : width; - double h = d->vertical ? height - : (d->inverted ? (height * (1.0 - d->vp_ypointer)) : height * d->vp_ypointer); + double w = d->vertical ? (d->inverted ? (width * (1.0 - d->vp_xpointer)) : width * d->vp_xpointer) : width; + double h = d->vertical ? height : (d->inverted ? (height * (1.0 - d->vp_ypointer)) : height * d->vp_ypointer); cairo_set_source_surface(cri, d->snapshot_image, 0, 0); // cairo_rectangle(cri, 0, 0, width*d->vp_xpointer, height); @@ -183,10 +181,9 @@ int button_pressed(struct dt_lib_module_t *self, double x, double y, double pres /* do the split rotating */ double hhs = HANDLE_SIZE * 0.5; - if(which == 1 - && (((d->vertical && xp > d->vp_xpointer - hhs && xp < d->vp_xpointer + hhs) && yp > 0.5 - hhs - && yp < 0.5 + hhs) - || ((yp > d->vp_ypointer - hhs && yp < d->vp_ypointer + hhs) && xp > 0.5 - hhs && xp < 0.5 + hhs))) + if(which == 1 && (((d->vertical && xp > d->vp_xpointer - hhs && xp < d->vp_xpointer + hhs) && yp > 0.5 - hhs + && yp < 0.5 + hhs) || ((yp > d->vp_ypointer - hhs && yp < d->vp_ypointer + hhs) + && xp > 0.5 - hhs && xp < 0.5 + hhs))) { /* let's rotate */ _lib_snapshot_rotation_cnt++; @@ -284,15 +281,13 @@ void gui_init(dt_lib_module_t *self) /* create snapshot button */ d->snapshot[k].button = gtk_toggle_button_new_with_label(wdname); gtk_widget_set_halign(gtk_bin_get_child(GTK_BIN(d->snapshot[k].button)), GTK_ALIGN_START); - g_signal_connect(G_OBJECT(d->snapshot[k].button), "clicked", G_CALLBACK(_lib_snapshots_toggled_callback), - self); + g_signal_connect(G_OBJECT(d->snapshot[k].button), "clicked", G_CALLBACK(_lib_snapshots_toggled_callback), self); /* assign snapshot number to widget */ g_object_set_data(G_OBJECT(d->snapshot[k].button), "snapshot", GINT_TO_POINTER(k + 1)); /* setup filename for snapshot */ - snprintf(d->snapshot[k].filename, sizeof(d->snapshot[k].filename), "%s/dt_snapshot_%d.png", localtmpdir, - k); + snprintf(d->snapshot[k].filename, sizeof(d->snapshot[k].filename), "%s/dt_snapshot_%d.png", localtmpdir, k); /* add button to snapshot box */ gtk_box_pack_start(GTK_BOX(d->snapshots_box), d->snapshot[k].button, TRUE, TRUE, 0); @@ -343,8 +338,8 @@ static void _lib_snapshots_add_button_clicked_callback(GtkWidget *widget, gpoint const gchar *name = _("original"); if(darktable.develop->history_end > 0) { - dt_dev_history_item_t *history_item = g_list_nth_data(darktable.develop->history, - darktable.develop->history_end - 1); + dt_dev_history_item_t *history_item + = g_list_nth_data(darktable.develop->history, darktable.develop->history_end - 1); if(history_item && history_item->module) name = history_item->module->name(); else @@ -571,10 +566,12 @@ static int number_member(lua_State *L) dt_lib_module_t *self = *(dt_lib_module_t **)lua_touserdata(L, 1); dt_lib_snapshots_t *d = (dt_lib_snapshots_t *)self->data; int index = luaL_checkinteger(L, 2); - if( index < 1) + if(index < 1) { return luaL_error(L, "Accessing a non-existant snapshot"); - }else if(index > d->num_snapshots ) { + } + else if(index > d->num_snapshots) + { lua_pushnil(L); return 1; } @@ -667,7 +664,7 @@ void init(struct dt_lib_module_t *self) lua_pushlightuserdata(L, self); lua_pushcclosure(L, name_member, 1); dt_lua_gtk_wrap(L); - dt_lua_type_setmetafield(L,dt_lua_snapshot_t,"__tostring"); + dt_lua_type_setmetafield(L, dt_lua_snapshot_t, "__tostring"); diff --git a/src/libs/styles.c b/src/libs/styles.c index dc248aa6824d..4a19eebd9c66 100644 --- a/src/libs/styles.c +++ b/src/libs/styles.c @@ -51,7 +51,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"lighttable", NULL}; + static const char *v[] = { "lighttable", NULL }; return v; } @@ -111,8 +111,7 @@ static void _gui_styles_update_view(dt_lib_styles_t *d) if(style->description && *style->description) { - tooltip - = g_strconcat("<b>", g_markup_escape_text(style->description, -1), "</b>\n", items_string, NULL); + tooltip = g_strconcat("<b>", g_markup_escape_text(style->description, -1), "</b>\n", items_string, NULL); } else { @@ -232,9 +231,9 @@ static void export_clicked(GtkWidget *w, gpointer user_data) static void import_clicked(GtkWidget *w, gpointer user_data) { GtkWidget *win = dt_ui_main_window(darktable.gui->ui); - GtkWidget *filechooser = gtk_file_chooser_dialog_new( - _("select style"), GTK_WINDOW(win), GTK_FILE_CHOOSER_ACTION_OPEN, _("_cancel"), GTK_RESPONSE_CANCEL, - _("_open"), GTK_RESPONSE_ACCEPT, (char *)NULL); + GtkWidget *filechooser + = gtk_file_chooser_dialog_new(_("select style"), GTK_WINDOW(win), GTK_FILE_CHOOSER_ACTION_OPEN, _("_cancel"), + GTK_RESPONSE_CANCEL, _("_open"), GTK_RESPONSE_ACCEPT, (char *)NULL); #ifdef GDK_WINDOWING_QUARTZ dt_osx_disallow_fullscreen(filechooser); #endif diff --git a/src/libs/tagging.c b/src/libs/tagging.c index 200dca085075..adf4684f3ecb 100644 --- a/src/libs/tagging.c +++ b/src/libs/tagging.c @@ -68,8 +68,8 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v1[] = {"lighttable", "darkroom", "map", "tethering", NULL}; - static const char *v2[] = {"lighttable", "map", "tethering", NULL}; + static const char *v1[] = { "lighttable", "darkroom", "map", "tethering", NULL }; + static const char *v2[] = { "lighttable", "map", "tethering", NULL }; if(dt_conf_get_bool("plugins/darkroom/tagging/visible")) return v1; @@ -170,8 +170,7 @@ static void attach_selected_tag(dt_lib_module_t *self, dt_lib_tagging_t *d) GtkTreeModel *model = NULL; GtkTreeView *view = d->related; GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); - if(!gtk_tree_selection_get_selected(selection, &model, &iter) - && !gtk_tree_model_get_iter_first(model, &iter)) + if(!gtk_tree_selection_get_selected(selection, &model, &iter) && !gtk_tree_model_get_iter_first(model, &iter)) return; guint tagid; gtk_tree_model_get(model, &iter, DT_LIB_TAGGING_COL_ID, &tagid, -1); @@ -369,10 +368,9 @@ static void import_button_clicked(GtkButton *button, gpointer user_data) } GtkWidget *win = dt_ui_main_window(darktable.gui->ui); - GtkWidget *filechooser = gtk_file_chooser_dialog_new(_("Select a keyword file"), GTK_WINDOW(win), - GTK_FILE_CHOOSER_ACTION_OPEN, - _("_cancel"), GTK_RESPONSE_CANCEL, - _("_import"), GTK_RESPONSE_ACCEPT, (char *)NULL); + GtkWidget *filechooser = gtk_file_chooser_dialog_new( + _("Select a keyword file"), GTK_WINDOW(win), GTK_FILE_CHOOSER_ACTION_OPEN, _("_cancel"), GTK_RESPONSE_CANCEL, + _("_import"), GTK_RESPONSE_ACCEPT, (char *)NULL); #ifdef GDK_WINDOWING_QUARTZ dt_osx_disallow_fullscreen(filechooser); #endif @@ -409,10 +407,9 @@ static void export_button_clicked(GtkButton *button, gpointer user_data) } GtkWidget *win = dt_ui_main_window(darktable.gui->ui); - GtkWidget *filechooser = gtk_file_chooser_dialog_new(_("Select file to export to"), GTK_WINDOW(win), - GTK_FILE_CHOOSER_ACTION_SAVE, - _("_cancel"), GTK_RESPONSE_CANCEL, - _("_export"), GTK_RESPONSE_ACCEPT, (char *)NULL); + GtkWidget *filechooser = gtk_file_chooser_dialog_new( + _("Select file to export to"), GTK_WINDOW(win), GTK_FILE_CHOOSER_ACTION_SAVE, _("_cancel"), + GTK_RESPONSE_CANCEL, _("_export"), GTK_RESPONSE_ACCEPT, (char *)NULL); #ifdef GDK_WINDOWING_QUARTZ dt_osx_disallow_fullscreen(filechooser); #endif diff --git a/src/libs/tools/colorlabels.c b/src/libs/tools/colorlabels.c index 951dc93f7e20..401b4df0aa5e 100644 --- a/src/libs/tools/colorlabels.c +++ b/src/libs/tools/colorlabels.c @@ -42,7 +42,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"lighttable", "tethering", NULL}; + static const char *v[] = { "lighttable", "tethering", NULL }; return v; } diff --git a/src/libs/tools/darktable.c b/src/libs/tools/darktable.c index 45b259c2fa0f..b5f746c85810 100644 --- a/src/libs/tools/darktable.c +++ b/src/libs/tools/darktable.c @@ -46,8 +46,7 @@ typedef struct dt_lib_darktable_t /* expose function for darktable module */ static gboolean _lib_darktable_draw_callback(GtkWidget *widget, cairo_t *cr, gpointer user_data); /* button press callback */ -static gboolean _lib_darktable_button_press_callback(GtkWidget *widget, GdkEventButton *event, - gpointer user_data); +static gboolean _lib_darktable_button_press_callback(GtkWidget *widget, GdkEventButton *event, gpointer user_data); /* show the about dialog */ static void _lib_darktable_show_about_dialog(); @@ -58,7 +57,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"*", NULL}; + static const char *v[] = { "*", NULL }; return v; } @@ -88,8 +87,8 @@ void gui_init(dt_lib_module_t *self) /* connect callbacks */ g_signal_connect(G_OBJECT(self->widget), "draw", G_CALLBACK(_lib_darktable_draw_callback), self); - g_signal_connect(G_OBJECT(self->widget), "button-press-event", - G_CALLBACK(_lib_darktable_button_press_callback), self); + g_signal_connect(G_OBJECT(self->widget), "button-press-event", G_CALLBACK(_lib_darktable_button_press_callback), + self); /* create a cairo surface of dt icon */ @@ -122,8 +121,7 @@ void gui_init(dt_lib_module_t *self) d->image = NULL; goto done; } - int png_width = cairo_image_surface_get_width(surface), - png_height = cairo_image_surface_get_height(surface); + int png_width = cairo_image_surface_get_width(surface), png_height = cairo_image_surface_get_height(surface); // blow up the PNG. Ugly, but at least it has the correct size afterwards :-/ int width = DT_PIXEL_APPLY_DPI(png_width) * darktable.gui->ppd, @@ -131,8 +129,7 @@ void gui_init(dt_lib_module_t *self) int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); d->image_buffer = (guint8 *)calloc(stride * height, sizeof(guint8)); - d->image - = dt_cairo_image_surface_create_for_data(d->image_buffer, CAIRO_FORMAT_ARGB32, width, height, stride); + d->image = dt_cairo_image_surface_create_for_data(d->image_buffer, CAIRO_FORMAT_ARGB32, width, height, stride); if(cairo_surface_status(d->image) != CAIRO_STATUS_SUCCESS) { free(d->image_buffer); @@ -226,8 +223,7 @@ static gboolean _lib_darktable_draw_callback(GtkWidget *widget, cairo_t *cr, gpo return TRUE; } -static gboolean _lib_darktable_button_press_callback(GtkWidget *widget, GdkEventButton *event, - gpointer user_data) +static gboolean _lib_darktable_button_press_callback(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { /* show about box */ _lib_darktable_show_about_dialog(); @@ -242,8 +238,7 @@ static void _lib_darktable_show_about_dialog() char *copyright = g_strdup_printf(_("copyright (c) the authors 2009-%s"), darktable_last_commit_year); gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog), copyright); g_free(copyright); - gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog), - _("organize and develop images from digital cameras")); + gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog), _("organize and develop images from digital cameras")); gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(dialog), "https://www.darktable.org/"); dt_logo_season_t season = dt_util_get_logo_season(); char *icon; diff --git a/src/libs/tools/filmstrip.c b/src/libs/tools/filmstrip.c index dd3565edb1d9..41290114f397 100644 --- a/src/libs/tools/filmstrip.c +++ b/src/libs/tools/filmstrip.c @@ -78,12 +78,10 @@ static void _lib_filmstrip_scroll_to_image(dt_lib_module_t *self, gint imgid, gb static int32_t _lib_filmstrip_get_activated_imgid(dt_lib_module_t *self); static GtkWidget *_lib_filmstrip_get_widget(dt_lib_module_t *self); -static gboolean _lib_filmstrip_size_handle_button_callback(GtkWidget *w, GdkEventButton *e, - gpointer user_data); +static gboolean _lib_filmstrip_size_handle_button_callback(GtkWidget *w, GdkEventButton *e, gpointer user_data); static gboolean _lib_filmstrip_size_handle_motion_notify_callback(GtkWidget *w, GdkEventButton *e, gpointer user_data); -static gboolean _lib_filmstrip_size_handle_cursor_callback(GtkWidget *w, GdkEventCrossing *e, - gpointer user_data); +static gboolean _lib_filmstrip_size_handle_cursor_callback(GtkWidget *w, GdkEventCrossing *e, gpointer user_data); /* motion notify event handler */ static gboolean _lib_filmstrip_motion_notify_callback(GtkWidget *w, GdkEventMotion *e, gpointer user_data); @@ -94,8 +92,7 @@ static gboolean _lib_filmstrip_scroll_callback(GtkWidget *w, GdkEventScroll *e, /* expose function for filmstrip module */ static gboolean _lib_filmstrip_draw_callback(GtkWidget *widget, cairo_t *cr, gpointer user_data); /* button press callback */ -static gboolean _lib_filmstrip_button_press_callback(GtkWidget *widget, GdkEventButton *event, - gpointer user_data); +static gboolean _lib_filmstrip_button_press_callback(GtkWidget *widget, GdkEventButton *event, gpointer user_data); /* button release callback */ static gboolean _lib_filmstrip_button_release_callback(GtkWidget *widget, GdkEventButton *event, gpointer user_data); @@ -103,19 +100,18 @@ static gboolean _lib_filmstrip_button_release_callback(GtkWidget *widget, GdkEve static void _lib_filmstrip_collection_changed_callback(gpointer instance, gpointer user_data); /* key accelerators callback */ -static gboolean _lib_filmstrip_copy_history_key_accel_callback(GtkAccelGroup *accel_group, - GObject *aceeleratable, guint keyval, - GdkModifierType modifier, gpointer data); +static gboolean _lib_filmstrip_copy_history_key_accel_callback(GtkAccelGroup *accel_group, GObject *aceeleratable, + guint keyval, GdkModifierType modifier, + gpointer data); static gboolean _lib_filmstrip_copy_history_parts_key_accel_callback(GtkAccelGroup *accel_group, GObject *aceeleratable, guint keyval, GdkModifierType modifier, gpointer data); -static gboolean _lib_filmstrip_paste_history_key_accel_callback(GtkAccelGroup *accel_group, - GObject *aceeleratable, guint keyval, - GdkModifierType modifier, gpointer data); +static gboolean _lib_filmstrip_paste_history_key_accel_callback(GtkAccelGroup *accel_group, GObject *aceeleratable, + guint keyval, GdkModifierType modifier, + gpointer data); static gboolean _lib_filmstrip_paste_history_parts_key_accel_callback(GtkAccelGroup *accel_group, GObject *aceeleratable, guint keyval, - GdkModifierType modifier, - gpointer data); + GdkModifierType modifier, gpointer data); static gboolean _lib_filmstrip_discard_history_key_accel_callback(GtkAccelGroup *accel_group, GObject *aceeleratable, guint keyval, GdkModifierType modifier, gpointer data); @@ -123,14 +119,12 @@ static gboolean _lib_filmstrip_duplicate_image_key_accel_callback(GtkAccelGroup GObject *aceeleratable, guint keyval, GdkModifierType modifier, gpointer data); static gboolean _lib_filmstrip_ratings_key_accel_callback(GtkAccelGroup *accel_group, GObject *aceeleratable, - guint keyval, GdkModifierType modifier, - gpointer data); -static gboolean _lib_filmstrip_colorlabels_key_accel_callback(GtkAccelGroup *accel_group, - GObject *aceeleratable, guint keyval, - GdkModifierType modifier, gpointer data); + guint keyval, GdkModifierType modifier, gpointer data); +static gboolean _lib_filmstrip_colorlabels_key_accel_callback(GtkAccelGroup *accel_group, GObject *aceeleratable, + guint keyval, GdkModifierType modifier, + gpointer data); static gboolean _lib_filmstrip_select_key_accel_callback(GtkAccelGroup *accel_group, GObject *aceeleratable, - guint keyval, GdkModifierType modifier, - gpointer data); + guint keyval, GdkModifierType modifier, gpointer data); /* drag'n'drop callbacks */ static void _lib_filmstrip_dnd_get_callback(GtkWidget *widget, GdkDragContext *context, @@ -145,7 +139,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"darkroom", "tethering", "map", "print", NULL}; + static const char *v[] = { "darkroom", "tethering", "map", "print", NULL }; return v; } @@ -178,11 +172,9 @@ void init_key_accels(dt_lib_module_t *self) /* setup history key accelerators */ dt_accel_register_lib(self, NC_("accel", "copy history"), GDK_KEY_c, GDK_CONTROL_MASK); - dt_accel_register_lib(self, NC_("accel", "copy history parts"), GDK_KEY_c, - GDK_CONTROL_MASK | GDK_SHIFT_MASK); + dt_accel_register_lib(self, NC_("accel", "copy history parts"), GDK_KEY_c, GDK_CONTROL_MASK | GDK_SHIFT_MASK); dt_accel_register_lib(self, NC_("accel", "paste history"), GDK_KEY_v, GDK_CONTROL_MASK); - dt_accel_register_lib(self, NC_("accel", "paste history parts"), GDK_KEY_v, - GDK_CONTROL_MASK | GDK_SHIFT_MASK); + dt_accel_register_lib(self, NC_("accel", "paste history parts"), GDK_KEY_v, GDK_CONTROL_MASK | GDK_SHIFT_MASK); dt_accel_register_lib(self, NC_("accel", "discard history"), 0, 0); dt_accel_register_lib(self, NC_("accel", "duplicate image"), GDK_KEY_d, GDK_CONTROL_MASK); @@ -219,9 +211,8 @@ void connect_key_accels(dt_lib_module_t *self) GINT_TO_POINTER(DT_VIEW_STAR_4), NULL)); dt_accel_connect_lib(self, "rate 5", g_cclosure_new(G_CALLBACK(_lib_filmstrip_ratings_key_accel_callback), GINT_TO_POINTER(DT_VIEW_STAR_5), NULL)); - dt_accel_connect_lib(self, "rate reject", - g_cclosure_new(G_CALLBACK(_lib_filmstrip_ratings_key_accel_callback), - GINT_TO_POINTER(DT_VIEW_REJECT), NULL)); + dt_accel_connect_lib(self, "rate reject", g_cclosure_new(G_CALLBACK(_lib_filmstrip_ratings_key_accel_callback), + GINT_TO_POINTER(DT_VIEW_REJECT), NULL)); // History key accels dt_accel_connect_lib( @@ -230,33 +221,31 @@ void connect_key_accels(dt_lib_module_t *self) dt_accel_connect_lib(self, "copy history parts", g_cclosure_new(G_CALLBACK(_lib_filmstrip_copy_history_parts_key_accel_callback), (gpointer)self->data, NULL)); - dt_accel_connect_lib(self, "paste history", - g_cclosure_new(G_CALLBACK(_lib_filmstrip_paste_history_key_accel_callback), - (gpointer)self->data, NULL)); + dt_accel_connect_lib( + self, "paste history", + g_cclosure_new(G_CALLBACK(_lib_filmstrip_paste_history_key_accel_callback), (gpointer)self->data, NULL)); dt_accel_connect_lib(self, "paste history parts", g_cclosure_new(G_CALLBACK(_lib_filmstrip_paste_history_parts_key_accel_callback), (gpointer)self->data, NULL)); - dt_accel_connect_lib(self, "discard history", - g_cclosure_new(G_CALLBACK(_lib_filmstrip_discard_history_key_accel_callback), - (gpointer)self->data, NULL)); + dt_accel_connect_lib( + self, "discard history", + g_cclosure_new(G_CALLBACK(_lib_filmstrip_discard_history_key_accel_callback), (gpointer)self->data, NULL)); - dt_accel_connect_lib(self, "duplicate image", - g_cclosure_new(G_CALLBACK(_lib_filmstrip_duplicate_image_key_accel_callback), - (gpointer)self->data, NULL)); + dt_accel_connect_lib( + self, "duplicate image", + g_cclosure_new(G_CALLBACK(_lib_filmstrip_duplicate_image_key_accel_callback), (gpointer)self->data, NULL)); // Color label accels - dt_accel_connect_lib( - self, "color red", - g_cclosure_new(G_CALLBACK(_lib_filmstrip_colorlabels_key_accel_callback), GINT_TO_POINTER(0), NULL)); + dt_accel_connect_lib(self, "color red", g_cclosure_new(G_CALLBACK(_lib_filmstrip_colorlabels_key_accel_callback), + GINT_TO_POINTER(0), NULL)); dt_accel_connect_lib( self, "color yellow", g_cclosure_new(G_CALLBACK(_lib_filmstrip_colorlabels_key_accel_callback), GINT_TO_POINTER(1), NULL)); dt_accel_connect_lib( self, "color green", g_cclosure_new(G_CALLBACK(_lib_filmstrip_colorlabels_key_accel_callback), GINT_TO_POINTER(2), NULL)); - dt_accel_connect_lib( - self, "color blue", - g_cclosure_new(G_CALLBACK(_lib_filmstrip_colorlabels_key_accel_callback), GINT_TO_POINTER(3), NULL)); + dt_accel_connect_lib(self, "color blue", g_cclosure_new(G_CALLBACK(_lib_filmstrip_colorlabels_key_accel_callback), + GINT_TO_POINTER(3), NULL)); dt_accel_connect_lib( self, "color purple", g_cclosure_new(G_CALLBACK(_lib_filmstrip_colorlabels_key_accel_callback), GINT_TO_POINTER(4), NULL)); @@ -264,9 +253,8 @@ void connect_key_accels(dt_lib_module_t *self) // Selection accels dt_accel_connect_lib(self, "select all", g_cclosure_new(G_CALLBACK(_lib_filmstrip_select_key_accel_callback), GINT_TO_POINTER(0), NULL)); - dt_accel_connect_lib( - self, "select none", - g_cclosure_new(G_CALLBACK(_lib_filmstrip_select_key_accel_callback), GINT_TO_POINTER(1), NULL)); + dt_accel_connect_lib(self, "select none", g_cclosure_new(G_CALLBACK(_lib_filmstrip_select_key_accel_callback), + GINT_TO_POINTER(1), NULL)); dt_accel_connect_lib( self, "invert selection", g_cclosure_new(G_CALLBACK(_lib_filmstrip_select_key_accel_callback), GINT_TO_POINTER(2), NULL)); @@ -303,42 +291,39 @@ void gui_init(dt_lib_module_t *self) */ gtk_drag_source_set(d->filmstrip, GDK_BUTTON1_MASK, target_list_all, n_targets_all, GDK_ACTION_COPY); #ifdef HAVE_MAP - gtk_drag_dest_set(d->filmstrip, GTK_DEST_DEFAULT_ALL, target_list_internal, n_targets_internal, - GDK_ACTION_COPY); + gtk_drag_dest_set(d->filmstrip, GTK_DEST_DEFAULT_ALL, target_list_internal, n_targets_internal, GDK_ACTION_COPY); #endif g_signal_connect_after(d->filmstrip, "drag-begin", G_CALLBACK(_lib_filmstrip_dnd_begin_callback), self); g_signal_connect(d->filmstrip, "drag-data-get", G_CALLBACK(_lib_filmstrip_dnd_get_callback), self); gtk_widget_add_events(d->filmstrip, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK - | GDK_LEAVE_NOTIFY_MASK); + | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_SCROLL_MASK + | GDK_SMOOTH_SCROLL_MASK | GDK_LEAVE_NOTIFY_MASK); /* connect callbacks */ g_signal_connect(G_OBJECT(d->filmstrip), "draw", G_CALLBACK(_lib_filmstrip_draw_callback), self); - g_signal_connect(G_OBJECT(d->filmstrip), "button-press-event", - G_CALLBACK(_lib_filmstrip_button_press_callback), self); + g_signal_connect(G_OBJECT(d->filmstrip), "button-press-event", G_CALLBACK(_lib_filmstrip_button_press_callback), + self); g_signal_connect(G_OBJECT(d->filmstrip), "button-release-event", G_CALLBACK(_lib_filmstrip_button_release_callback), self); g_signal_connect(G_OBJECT(d->filmstrip), "scroll-event", G_CALLBACK(_lib_filmstrip_scroll_callback), self); g_signal_connect(G_OBJECT(d->filmstrip), "motion-notify-event", G_CALLBACK(_lib_filmstrip_motion_notify_callback), self); - g_signal_connect(G_OBJECT(d->filmstrip), "leave-notify-event", - G_CALLBACK(_lib_filmstrip_mouse_leave_callback), self); + g_signal_connect(G_OBJECT(d->filmstrip), "leave-notify-event", G_CALLBACK(_lib_filmstrip_mouse_leave_callback), + self); /* set size of filmstrip */ int32_t height = dt_conf_get_int("plugins/lighttable/filmstrip/height"); - gtk_widget_set_size_request(d->filmstrip, -1, - CLAMP(height, DT_PIXEL_APPLY_DPI(64), DT_PIXEL_APPLY_DPI(400))); + gtk_widget_set_size_request(d->filmstrip, -1, CLAMP(height, DT_PIXEL_APPLY_DPI(64), DT_PIXEL_APPLY_DPI(400))); /* create the resize handle */ GtkWidget *size_handle = gtk_event_box_new(); gtk_widget_set_size_request(size_handle, -1, DT_PIXEL_APPLY_DPI(10)); - gtk_widget_add_events(size_handle, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK - | GDK_LEAVE_NOTIFY_MASK); + gtk_widget_add_events(size_handle, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK + | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK + | GDK_LEAVE_NOTIFY_MASK); g_signal_connect(G_OBJECT(size_handle), "button-press-event", G_CALLBACK(_lib_filmstrip_size_handle_button_callback), self); @@ -398,8 +383,7 @@ static gboolean _lib_filmstrip_mouse_leave_callback(GtkWidget *w, GdkEventCrossi return TRUE; } -static gboolean _lib_filmstrip_size_handle_cursor_callback(GtkWidget *w, GdkEventCrossing *e, - gpointer user_data) +static gboolean _lib_filmstrip_size_handle_cursor_callback(GtkWidget *w, GdkEventCrossing *e, gpointer user_data) { dt_control_change_cursor((e->type == GDK_ENTER_NOTIFY) ? GDK_SB_V_DOUBLE_ARROW : GDK_LEFT_PTR); return TRUE; @@ -414,7 +398,7 @@ static gboolean _lib_filmstrip_size_handle_button_callback(GtkWidget *w, GdkEven { if(e->type == GDK_BUTTON_PRESS) { - /* store current mousepointer position */ +/* store current mousepointer position */ #if GTK_CHECK_VERSION(3, 20, 0) gdk_window_get_device_position(e->window, gdk_seat_get_pointer(gdk_display_get_default_seat(gdk_window_get_display( @@ -447,9 +431,9 @@ static gboolean _lib_filmstrip_size_handle_motion_notify_callback(GtkWidget *w, gint x, y, sx, sy; #if GTK_CHECK_VERSION(3, 20, 0) gdk_window_get_device_position(e->window, - gdk_seat_get_pointer(gdk_display_get_default_seat( - gdk_window_get_display(gtk_widget_get_window(dt_ui_main_window(darktable.gui->ui))))), - &x, &y, 0); + gdk_seat_get_pointer(gdk_display_get_default_seat(gdk_window_get_display( + gtk_widget_get_window(dt_ui_main_window(darktable.gui->ui))))), + &x, &y, 0); #else gdk_window_get_device_position( gtk_widget_get_window(dt_ui_main_window(darktable.gui->ui)), @@ -459,8 +443,7 @@ static gboolean _lib_filmstrip_size_handle_motion_notify_callback(GtkWidget *w, #endif gtk_widget_get_size_request(d->filmstrip, &sx, &sy); - sy = CLAMP(d->size_handle_height + (d->size_handle_y - y), DT_PIXEL_APPLY_DPI(64), - DT_PIXEL_APPLY_DPI(400)); + sy = CLAMP(d->size_handle_height + (d->size_handle_y - y), DT_PIXEL_APPLY_DPI(64), DT_PIXEL_APPLY_DPI(400)); dt_conf_set_int("plugins/lighttable/filmstrip/height", sy); @@ -494,7 +477,7 @@ static gboolean _lib_filmstrip_scroll_callback(GtkWidget *w, GdkEventScroll *e, int delta_x, delta_y; if(dt_gui_get_scroll_unit_deltas(e, &delta_x, &delta_y)) { - strip->offset = CLAMP(strip->offset + delta_x + delta_y, 0, strip->collection_count-1); + strip->offset = CLAMP(strip->offset + delta_x + delta_y, 0, strip->collection_count - 1); gtk_widget_queue_draw(self->widget); } @@ -518,8 +501,7 @@ static gboolean _lib_filmstrip_imgid_in_collection(const dt_collection_t *collec } DT_DEBUG_SQLITE3_BIND_INT(stmt, 3, imgid); - if(sqlite3_step(stmt) == SQLITE_ROW) - image_in_collection = (sqlite3_column_int(stmt, 0) > 0); + if(sqlite3_step(stmt) == SQLITE_ROW) image_in_collection = (sqlite3_column_int(stmt, 0) > 0); sqlite3_finalize(stmt); g_free(count_query); return image_in_collection; @@ -728,7 +710,8 @@ static gboolean _lib_filmstrip_draw_callback(GtkWidget *widget, cairo_t *cr, gpo // getting it from the matrix ... cairo_matrix_t m; cairo_get_matrix(cr, &m); - dt_view_image_expose(&(strip->image_over), id, cr, wd, ht, max_cols, img_pointerx, img_pointery, FALSE, FALSE); + dt_view_image_expose(&(strip->image_over), id, cr, wd, ht, max_cols, img_pointerx, img_pointery, FALSE, + FALSE); cairo_restore(cr); } else if(step_res == SQLITE_DONE) @@ -807,9 +790,9 @@ static GtkWidget *_lib_filmstrip_get_widget(dt_lib_module_t *self) return strip->filmstrip; } -static gboolean _lib_filmstrip_copy_history_key_accel_callback(GtkAccelGroup *accel_group, - GObject *aceeleratable, guint keyval, - GdkModifierType modifier, gpointer data) +static gboolean _lib_filmstrip_copy_history_key_accel_callback(GtkAccelGroup *accel_group, GObject *aceeleratable, + guint keyval, GdkModifierType modifier, + gpointer data) { dt_lib_filmstrip_t *strip = (dt_lib_filmstrip_t *)data; int32_t mouse_over_id = dt_control_get_mouse_over_id(); @@ -829,17 +812,16 @@ static gboolean _lib_filmstrip_copy_history_parts_key_accel_callback(GtkAccelGro if(_lib_filmstrip_copy_history_key_accel_callback(accel_group, aceeleratable, keyval, modifier, data)) { dt_lib_filmstrip_t *strip = (dt_lib_filmstrip_t *)data; - if(dt_gui_hist_dialog_new(&(strip->dg), strip->history_copy_imgid, TRUE) == GTK_RESPONSE_CANCEL) - return FALSE; + if(dt_gui_hist_dialog_new(&(strip->dg), strip->history_copy_imgid, TRUE) == GTK_RESPONSE_CANCEL) return FALSE; return TRUE; } else return FALSE; } -static gboolean _lib_filmstrip_paste_history_key_accel_callback(GtkAccelGroup *accel_group, - GObject *aceeleratable, guint keyval, - GdkModifierType modifier, gpointer data) +static gboolean _lib_filmstrip_paste_history_key_accel_callback(GtkAccelGroup *accel_group, GObject *aceeleratable, + guint keyval, GdkModifierType modifier, + gpointer data) { dt_lib_filmstrip_t *strip = (dt_lib_filmstrip_t *)data; int mode = dt_conf_get_int("plugins/lighttable/copy_history/pastemode"); @@ -914,8 +896,7 @@ static gboolean _lib_filmstrip_duplicate_image_key_accel_callback(GtkAccelGroup } static gboolean _lib_filmstrip_ratings_key_accel_callback(GtkAccelGroup *accel_group, GObject *aceeleratable, - guint keyval, GdkModifierType modifier, - gpointer data) + guint keyval, GdkModifierType modifier, gpointer data) { int num = GPOINTER_TO_INT(data); switch(num) @@ -959,9 +940,9 @@ static gboolean _lib_filmstrip_ratings_key_accel_callback(GtkAccelGroup *accel_g return TRUE; } -static gboolean _lib_filmstrip_colorlabels_key_accel_callback(GtkAccelGroup *accel_group, - GObject *acceleratable, guint keyval, - GdkModifierType modifier, gpointer data) +static gboolean _lib_filmstrip_colorlabels_key_accel_callback(GtkAccelGroup *accel_group, GObject *acceleratable, + guint keyval, GdkModifierType modifier, + gpointer data) { dt_colorlabels_key_accel_callback(NULL, NULL, 0, 0, data); /* redraw filmstrip */ @@ -971,8 +952,7 @@ static gboolean _lib_filmstrip_colorlabels_key_accel_callback(GtkAccelGroup *acc } static gboolean _lib_filmstrip_select_key_accel_callback(GtkAccelGroup *accel_group, GObject *acceleratable, - guint keyval, GdkModifierType modifier, - gpointer data) + guint keyval, GdkModifierType modifier, gpointer data) { switch(GPOINTER_TO_INT(data)) { @@ -1014,8 +994,8 @@ static void _lib_filmstrip_dnd_get_callback(GtkWidget *widget, GdkDragContext *c case DND_TARGET_IMGID: { int id = ((count == 1) ? mouse_over_id : -1); - gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data), _DWORD, - (guchar *)&id, sizeof(id)); + gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data), _DWORD, (guchar *)&id, + sizeof(id)); break; } default: // return the location of the file as a last resort @@ -1027,16 +1007,16 @@ static void _lib_filmstrip_dnd_get_callback(GtkWidget *widget, GdkDragContext *c gboolean from_cache = TRUE; dt_image_full_path(mouse_over_id, pathname, sizeof(pathname), &from_cache); gchar *uri = g_strdup_printf("file://%s", pathname); // TODO: should we add the host? - gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data), _BYTE, - (guchar *)uri, strlen(uri)); + gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data), _BYTE, (guchar *)uri, + strlen(uri)); g_free(uri); } else { sqlite3_stmt *stmt; GList *images = NULL; - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), - "SELECT imgid FROM main.selected_images", -1, &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT imgid FROM main.selected_images", -1, + &stmt, NULL); while(sqlite3_step(stmt) == SQLITE_ROW) { int id = sqlite3_column_int(stmt, 0); @@ -1102,8 +1082,8 @@ static void _lib_filmstrip_dnd_begin_callback(GtkWidget *widget, GdkDragContext else h = (buf.height * ts) / buf.width; // landscape - GdkPixbuf *source = gdk_pixbuf_new_from_data(buf.buf, GDK_COLORSPACE_RGB, TRUE, 8, buf.width, - buf.height, buf.width * 4, NULL, NULL); + GdkPixbuf *source = gdk_pixbuf_new_from_data(buf.buf, GDK_COLORSPACE_RGB, TRUE, 8, buf.width, buf.height, + buf.width * 4, NULL, NULL); GdkPixbuf *scaled = gdk_pixbuf_scale_simple(source, w, h, GDK_INTERP_HYPER); gtk_drag_set_icon_pixbuf(context, scaled, 0, h); diff --git a/src/libs/tools/filter.c b/src/libs/tools/filter.c index d374b9ed4240..a6241626c486 100644 --- a/src/libs/tools/filter.c +++ b/src/libs/tools/filter.c @@ -65,7 +65,7 @@ const char **views(dt_lib_module_t *self) unloading/loading a module while switching views. */ - static const char *v[] = {"*", NULL}; + static const char *v[] = { "*", NULL }; return v; } @@ -150,8 +150,8 @@ void gui_init(dt_lib_module_t *self) g_signal_connect(G_OBJECT(widget), "changed", G_CALLBACK(_lib_filter_sort_combobox_changed), (gpointer)self); /* reverse order checkbutton */ - d->reverse = widget - = dtgtk_togglebutton_new(dtgtk_cairo_paint_solid_arrow, CPF_DO_NOT_USE_BORDER | CPF_STYLE_BOX | CPF_DIRECTION_UP); + d->reverse = widget = dtgtk_togglebutton_new(dtgtk_cairo_paint_solid_arrow, + CPF_DO_NOT_USE_BORDER | CPF_STYLE_BOX | CPF_DIRECTION_UP); if(darktable.collection->params.descending) dtgtk_togglebutton_set_paint(DTGTK_TOGGLEBUTTON(widget), dtgtk_cairo_paint_solid_arrow, CPF_DO_NOT_USE_BORDER | CPF_STYLE_BOX | CPF_DIRECTION_DOWN); @@ -159,18 +159,16 @@ void gui_init(dt_lib_module_t *self) gtk_box_pack_start(GTK_BOX(self->widget), widget, FALSE, FALSE, 0); /* select the last value and connect callback */ - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), - dt_collection_get_sort_descending(darktable.collection)); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), dt_collection_get_sort_descending(darktable.collection)); - g_signal_connect(G_OBJECT(widget), "toggled", G_CALLBACK(_lib_filter_reverse_button_changed), - (gpointer)self); + g_signal_connect(G_OBJECT(widget), "toggled", G_CALLBACK(_lib_filter_reverse_button_changed), (gpointer)self); /* initialize proxy */ darktable.view_manager->proxy.filter.module = self; darktable.view_manager->proxy.filter.reset_filter = _lib_filter_reset; - g_signal_connect_swapped(G_OBJECT(d->comparator), "map", - G_CALLBACK(_lib_filter_sync_combobox_and_comparator), self); + g_signal_connect_swapped(G_OBJECT(d->comparator), "map", G_CALLBACK(_lib_filter_sync_combobox_and_comparator), + self); } void gui_cleanup(dt_lib_module_t *self) @@ -212,20 +210,20 @@ static void _lib_filter_combobox_changed(GtkComboBox *widget, gpointer user_data if(i == 0) // all dt_collection_set_filter_flags(darktable.collection, dt_collection_get_filter_flags(darktable.collection) - & ~(COLLECTION_FILTER_ATLEAST_RATING | COLLECTION_FILTER_EQUAL_RATING - | COLLECTION_FILTER_CUSTOM_COMPARE)); + & ~(COLLECTION_FILTER_ATLEAST_RATING | COLLECTION_FILTER_EQUAL_RATING + | COLLECTION_FILTER_CUSTOM_COMPARE)); else if(i == 1 || i == 7) // unstarred only || rejected only dt_collection_set_filter_flags( darktable.collection, (dt_collection_get_filter_flags(darktable.collection) | COLLECTION_FILTER_EQUAL_RATING) - & ~(COLLECTION_FILTER_ATLEAST_RATING | COLLECTION_FILTER_CUSTOM_COMPARE)); + & ~(COLLECTION_FILTER_ATLEAST_RATING | COLLECTION_FILTER_CUSTOM_COMPARE)); else if(i == 8) // all except rejected dt_collection_set_filter_flags(darktable.collection, (dt_collection_get_filter_flags(darktable.collection) | COLLECTION_FILTER_ATLEAST_RATING) & ~COLLECTION_FILTER_CUSTOM_COMPARE); else // explicit stars dt_collection_set_filter_flags(darktable.collection, dt_collection_get_filter_flags(darktable.collection) - | COLLECTION_FILTER_CUSTOM_COMPARE); + | COLLECTION_FILTER_CUSTOM_COMPARE); /* set the star filter in collection */ dt_collection_set_rating(darktable.collection, i); @@ -243,9 +241,11 @@ static void _lib_filter_reverse_button_changed(GtkDarktableToggleButton *widget, gboolean reverse = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); if(reverse) - dtgtk_togglebutton_set_paint(widget, dtgtk_cairo_paint_solid_arrow, CPF_DO_NOT_USE_BORDER | CPF_STYLE_BOX | CPF_DIRECTION_DOWN); + dtgtk_togglebutton_set_paint(widget, dtgtk_cairo_paint_solid_arrow, + CPF_DO_NOT_USE_BORDER | CPF_STYLE_BOX | CPF_DIRECTION_DOWN); else - dtgtk_togglebutton_set_paint(widget, dtgtk_cairo_paint_solid_arrow, CPF_DO_NOT_USE_BORDER | CPF_STYLE_BOX | CPF_DIRECTION_UP); + dtgtk_togglebutton_set_paint(widget, dtgtk_cairo_paint_solid_arrow, + CPF_DO_NOT_USE_BORDER | CPF_STYLE_BOX | CPF_DIRECTION_UP); gtk_widget_queue_draw(GTK_WIDGET(widget)); /* update last settings */ diff --git a/src/libs/tools/global_toolbox.c b/src/libs/tools/global_toolbox.c index 901f956e8c8a..458c4e552f41 100644 --- a/src/libs/tools/global_toolbox.c +++ b/src/libs/tools/global_toolbox.c @@ -48,7 +48,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"*", NULL}; + static const char *v[] = { "*", NULL }; return v; } @@ -83,8 +83,7 @@ void gui_init(dt_lib_module_t *self) gtk_widget_set_tooltip_text(d->grouping_button, _("expand grouped images")); else gtk_widget_set_tooltip_text(d->grouping_button, _("collapse grouped images")); - g_signal_connect(G_OBJECT(d->grouping_button), "clicked", G_CALLBACK(_lib_filter_grouping_button_clicked), - NULL); + g_signal_connect(G_OBJECT(d->grouping_button), "clicked", G_CALLBACK(_lib_filter_grouping_button_clicked), NULL); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(d->grouping_button), darktable.gui->grouping); /* create the "show/hide overlays" button */ @@ -103,8 +102,7 @@ void gui_init(dt_lib_module_t *self) gtk_widget_set_size_request(d->preferences_button, DT_PIXEL_APPLY_DPI(18), DT_PIXEL_APPLY_DPI(18)); gtk_box_pack_end(GTK_BOX(self->widget), d->preferences_button, FALSE, FALSE, 2); gtk_widget_set_tooltip_text(d->preferences_button, _("show global preferences")); - g_signal_connect(G_OBJECT(d->preferences_button), "clicked", G_CALLBACK(_lib_preferences_button_clicked), - NULL); + g_signal_connect(G_OBJECT(d->preferences_button), "clicked", G_CALLBACK(_lib_preferences_button_clicked), NULL); } void gui_cleanup(dt_lib_module_t *self) @@ -131,11 +129,9 @@ static void _lib_filter_grouping_button_clicked(GtkWidget *widget, gpointer user dt_collection_update_query(darktable.collection); #ifdef USE_LUA - dt_lua_async_call_alien(dt_lua_event_trigger_wrapper, - 0,NULL,NULL, - LUA_ASYNC_TYPENAME,"const char*","global_toolbox-grouping_toggle", - LUA_ASYNC_TYPENAME,"bool",darktable.gui->grouping, - LUA_ASYNC_DONE); + dt_lua_async_call_alien(dt_lua_event_trigger_wrapper, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "const char*", + "global_toolbox-grouping_toggle", LUA_ASYNC_TYPENAME, "bool", darktable.gui->grouping, + LUA_ASYNC_DONE); #endif // USE_LUA } @@ -150,11 +146,9 @@ static void _lib_overlays_button_clicked(GtkWidget *widget, gpointer user_data) dt_control_signal_raise(darktable.signals, DT_SIGNAL_COLLECTION_CHANGED); #ifdef USE_LUA - dt_lua_async_call_alien(dt_lua_event_trigger_wrapper, - 0,NULL,NULL, - LUA_ASYNC_TYPENAME,"const char*","global_toolbox-overlay_toggle", - LUA_ASYNC_TYPENAME,"bool",darktable.gui->show_overlays, - LUA_ASYNC_DONE); + dt_lua_async_call_alien(dt_lua_event_trigger_wrapper, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "const char*", + "global_toolbox-overlay_toggle", LUA_ASYNC_TYPENAME, "bool", + darktable.gui->show_overlays, LUA_ASYNC_DONE); #endif // USE_LUA } diff --git a/src/libs/tools/hinter.c b/src/libs/tools/hinter.c index cd3f83f27899..08d9eccf764d 100644 --- a/src/libs/tools/hinter.c +++ b/src/libs/tools/hinter.c @@ -44,7 +44,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"lighttable", "darkroom", "tethering", NULL}; + static const char *v[] = { "lighttable", "darkroom", "tethering", NULL }; return v; } diff --git a/src/libs/tools/lighttable.c b/src/libs/tools/lighttable.c index d52b26f3310e..d61b98cb2b7b 100644 --- a/src/libs/tools/lighttable.c +++ b/src/libs/tools/lighttable.c @@ -42,21 +42,16 @@ static void _lib_lighttable_layout_changed(GtkComboBox *widget, gpointer user_da /* zoom slider change callback */ static void _lib_lighttable_zoom_slider_changed(GtkRange *range, gpointer user_data); /* zoom entry change callback */ -static gboolean _lib_lighttable_zoom_entry_changed(GtkWidget *entry, GdkEventKey *event, - dt_lib_module_t *self); +static gboolean _lib_lighttable_zoom_entry_changed(GtkWidget *entry, GdkEventKey *event, dt_lib_module_t *self); /* zoom key accel callback */ -static gboolean _lib_lighttable_key_accel_zoom_max_callback(GtkAccelGroup *accel_group, - GObject *acceleratable, guint keyval, - GdkModifierType modifier, gpointer data); -static gboolean _lib_lighttable_key_accel_zoom_min_callback(GtkAccelGroup *accel_group, - GObject *acceleratable, guint keyval, - GdkModifierType modifier, gpointer data); +static gboolean _lib_lighttable_key_accel_zoom_max_callback(GtkAccelGroup *accel_group, GObject *acceleratable, + guint keyval, GdkModifierType modifier, gpointer data); +static gboolean _lib_lighttable_key_accel_zoom_min_callback(GtkAccelGroup *accel_group, GObject *acceleratable, + guint keyval, GdkModifierType modifier, gpointer data); static gboolean _lib_lighttable_key_accel_zoom_in_callback(GtkAccelGroup *accel_group, GObject *acceleratable, - guint keyval, GdkModifierType modifier, - gpointer data); -static gboolean _lib_lighttable_key_accel_zoom_out_callback(GtkAccelGroup *accel_group, - GObject *acceleratable, guint keyval, - GdkModifierType modifier, gpointer data); + guint keyval, GdkModifierType modifier, gpointer data); +static gboolean _lib_lighttable_key_accel_zoom_out_callback(GtkAccelGroup *accel_group, GObject *acceleratable, + guint keyval, GdkModifierType modifier, gpointer data); const char *name(dt_lib_module_t *self) @@ -66,7 +61,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"lighttable", NULL}; + static const char *v[] = { "lighttable", NULL }; return v; } @@ -255,9 +250,8 @@ static void _lib_lighttable_set_zoom(dt_lib_module_t *self, gint zoom) gtk_range_set_value(GTK_RANGE(d->zoom), zoom); } -static gboolean _lib_lighttable_key_accel_zoom_max_callback(GtkAccelGroup *accel_group, - GObject *acceleratable, guint keyval, - GdkModifierType modifier, gpointer data) +static gboolean _lib_lighttable_key_accel_zoom_max_callback(GtkAccelGroup *accel_group, GObject *acceleratable, + guint keyval, GdkModifierType modifier, gpointer data) { dt_lib_module_t *self = (dt_lib_module_t *)data; dt_lib_tool_lighttable_t *d = (dt_lib_tool_lighttable_t *)self->data; @@ -266,9 +260,8 @@ static gboolean _lib_lighttable_key_accel_zoom_max_callback(GtkAccelGroup *accel return TRUE; } -static gboolean _lib_lighttable_key_accel_zoom_min_callback(GtkAccelGroup *accel_group, - GObject *acceleratable, guint keyval, - GdkModifierType modifier, gpointer data) +static gboolean _lib_lighttable_key_accel_zoom_min_callback(GtkAccelGroup *accel_group, GObject *acceleratable, + guint keyval, GdkModifierType modifier, gpointer data) { dt_lib_module_t *self = (dt_lib_module_t *)data; dt_lib_tool_lighttable_t *d = (dt_lib_tool_lighttable_t *)self->data; @@ -277,8 +270,7 @@ static gboolean _lib_lighttable_key_accel_zoom_min_callback(GtkAccelGroup *accel } static gboolean _lib_lighttable_key_accel_zoom_in_callback(GtkAccelGroup *accel_group, GObject *acceleratable, - guint keyval, GdkModifierType modifier, - gpointer data) + guint keyval, GdkModifierType modifier, gpointer data) { dt_lib_module_t *self = (dt_lib_module_t *)data; dt_lib_tool_lighttable_t *d = (dt_lib_tool_lighttable_t *)self->data; @@ -291,9 +283,8 @@ static gboolean _lib_lighttable_key_accel_zoom_in_callback(GtkAccelGroup *accel_ return TRUE; } -static gboolean _lib_lighttable_key_accel_zoom_out_callback(GtkAccelGroup *accel_group, - GObject *acceleratable, guint keyval, - GdkModifierType modifier, gpointer data) +static gboolean _lib_lighttable_key_accel_zoom_out_callback(GtkAccelGroup *accel_group, GObject *acceleratable, + guint keyval, GdkModifierType modifier, gpointer data) { dt_lib_module_t *self = (dt_lib_module_t *)data; dt_lib_tool_lighttable_t *d = (dt_lib_tool_lighttable_t *)self->data; diff --git a/src/libs/tools/module_toolbox.c b/src/libs/tools/module_toolbox.c index 5009a0b58915..196cdedeefae 100644 --- a/src/libs/tools/module_toolbox.c +++ b/src/libs/tools/module_toolbox.c @@ -30,7 +30,7 @@ static void _lib_module_toolbox_add(dt_lib_module_t *self, GtkWidget *widget, dt typedef struct child_data_t { - GtkWidget * child; + GtkWidget *child; dt_view_type_flags_t views; } child_data_t; @@ -38,7 +38,7 @@ typedef struct child_data_t typedef struct dt_lib_module_toolbox_t { GtkWidget *container; - GList * child_views; + GList *child_views; } dt_lib_module_toolbox_t; const char *name(dt_lib_module_t *self) @@ -48,7 +48,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"darkroom", "lighttable", "tethering", NULL}; + static const char *v[] = { "darkroom", "lighttable", "tethering", NULL }; return v; } @@ -85,20 +85,20 @@ void gui_init(dt_lib_module_t *self) void gui_cleanup(dt_lib_module_t *self) { dt_lib_module_toolbox_t *d = (dt_lib_module_toolbox_t *)self->data; - g_list_free_full(d->child_views,free); + g_list_free_full(d->child_views, free); g_free(self->data); self->data = NULL; } -void view_enter(struct dt_lib_module_t *self,struct dt_view_t *old_view,struct dt_view_t *new_view) +void view_enter(struct dt_lib_module_t *self, struct dt_view_t *old_view, struct dt_view_t *new_view) { dt_lib_module_toolbox_t *d = (dt_lib_module_toolbox_t *)self->data; GList *child_elt = d->child_views; - dt_view_type_flags_t nv= new_view->view(new_view); + dt_view_type_flags_t nv = new_view->view(new_view); while(child_elt) { - child_data_t* child_data = (child_data_t*)child_elt->data; - if(child_data->views & nv) + child_data_t *child_data = (child_data_t *)child_elt->data; + if(child_data->views & nv) { gtk_widget_show_all(child_data->child); } @@ -119,8 +119,7 @@ static void _lib_module_toolbox_add(dt_lib_module_t *self, GtkWidget *widget, dt child_data_t *child_data = malloc(sizeof(child_data_t)); child_data->child = widget; child_data->views = views; - d->child_views = g_list_prepend(d->child_views,child_data); - + d->child_views = g_list_prepend(d->child_views, child_data); } // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh // vim: shiftwidth=2 expandtab tabstop=2 cindent diff --git a/src/libs/tools/ratings.c b/src/libs/tools/ratings.c index ff81b85197dc..cea48107542e 100644 --- a/src/libs/tools/ratings.c +++ b/src/libs/tools/ratings.c @@ -37,17 +37,13 @@ typedef struct dt_lib_ratings_t /* redraw the ratings */ static gboolean _lib_ratings_draw_callback(GtkWidget *widget, cairo_t *cr, gpointer user_data); /* motion notify handler*/ -static gboolean _lib_ratings_motion_notify_callback(GtkWidget *widget, GdkEventMotion *event, - gpointer user_data); +static gboolean _lib_ratings_motion_notify_callback(GtkWidget *widget, GdkEventMotion *event, gpointer user_data); /* motion leavel handler */ -static gboolean _lib_ratings_leave_notify_callback(GtkWidget *widget, GdkEventCrossing *event, - gpointer user_data); +static gboolean _lib_ratings_leave_notify_callback(GtkWidget *widget, GdkEventCrossing *event, gpointer user_data); /* button press handler */ -static gboolean _lib_ratings_button_press_callback(GtkWidget *widget, GdkEventButton *event, - gpointer user_data); +static gboolean _lib_ratings_button_press_callback(GtkWidget *widget, GdkEventButton *event, gpointer user_data); /* button release handler */ -static gboolean _lib_ratings_button_release_callback(GtkWidget *widget, GdkEventButton *event, - gpointer user_data); +static gboolean _lib_ratings_button_release_callback(GtkWidget *widget, GdkEventButton *event, gpointer user_data); const char *name(dt_lib_module_t *self) { @@ -56,7 +52,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"lighttable", "tethering", NULL}; + static const char *v[] = { "lighttable", "tethering", NULL }; return v; } @@ -88,17 +84,20 @@ void gui_init(dt_lib_module_t *self) gtk_widget_set_halign(self->widget, GTK_ALIGN_CENTER); gtk_widget_set_valign(self->widget, GTK_ALIGN_CENTER); gtk_widget_set_events(self->widget, GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK - | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_STRUCTURE_MASK); + | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + | GDK_STRUCTURE_MASK); /* connect callbacks */ gtk_widget_set_app_paintable(self->widget, TRUE); g_signal_connect(G_OBJECT(self->widget), "draw", G_CALLBACK(_lib_ratings_draw_callback), self); - g_signal_connect(G_OBJECT(self->widget), "button-press-event", G_CALLBACK(_lib_ratings_button_press_callback), self); - g_signal_connect(G_OBJECT(self->widget), "button-release-event", G_CALLBACK(_lib_ratings_button_release_callback), + g_signal_connect(G_OBJECT(self->widget), "button-press-event", G_CALLBACK(_lib_ratings_button_press_callback), + self); + g_signal_connect(G_OBJECT(self->widget), "button-release-event", + G_CALLBACK(_lib_ratings_button_release_callback), self); + g_signal_connect(G_OBJECT(self->widget), "motion-notify-event", G_CALLBACK(_lib_ratings_motion_notify_callback), + self); + g_signal_connect(G_OBJECT(self->widget), "leave-notify-event", G_CALLBACK(_lib_ratings_leave_notify_callback), self); - g_signal_connect(G_OBJECT(self->widget), "motion-notify-event", G_CALLBACK(_lib_ratings_motion_notify_callback), self); - g_signal_connect(G_OBJECT(self->widget), "leave-notify-event", G_CALLBACK(_lib_ratings_leave_notify_callback), self); /* set size of navigation draw area */ gtk_widget_set_size_request(self->widget, (STAR_SIZE * 6) + (STAR_SPACING * 5), STAR_SIZE); @@ -120,8 +119,7 @@ static gboolean _lib_ratings_draw_callback(GtkWidget *widget, cairo_t *crf, gpoi GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); - cairo_surface_t *cst - = dt_cairo_image_surface_create(CAIRO_FORMAT_ARGB32, allocation.width, allocation.height); + cairo_surface_t *cst = dt_cairo_image_surface_create(CAIRO_FORMAT_ARGB32, allocation.width, allocation.height); cairo_t *cr = cairo_create(cst); GtkStyleContext *context = gtk_widget_get_style_context(widget); @@ -163,8 +161,7 @@ static gboolean _lib_ratings_draw_callback(GtkWidget *widget, cairo_t *crf, gpoi return TRUE; } -static gboolean _lib_ratings_motion_notify_callback(GtkWidget *widget, GdkEventMotion *event, - gpointer user_data) +static gboolean _lib_ratings_motion_notify_callback(GtkWidget *widget, GdkEventMotion *event, gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_ratings_t *d = (dt_lib_ratings_t *)self->data; @@ -174,17 +171,16 @@ static gboolean _lib_ratings_motion_notify_callback(GtkWidget *widget, GdkEventM event->window, gdk_seat_get_pointer(gdk_display_get_default_seat(gtk_widget_get_display(widget))), &d->pointerx, &d->pointery, 0); #else - gdk_window_get_device_position(event->window, - gdk_device_manager_get_client_pointer( - gdk_display_get_device_manager(gdk_window_get_display(event->window))), - &d->pointerx, &d->pointery, NULL); + gdk_window_get_device_position( + event->window, + gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gdk_window_get_display(event->window))), + &d->pointerx, &d->pointery, NULL); #endif gtk_widget_queue_draw(self->widget); return TRUE; } -static gboolean _lib_ratings_button_press_callback(GtkWidget *widget, GdkEventButton *event, - gpointer user_data) +static gboolean _lib_ratings_button_press_callback(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_ratings_t *d = (dt_lib_ratings_t *)self->data; @@ -210,16 +206,14 @@ static gboolean _lib_ratings_button_press_callback(GtkWidget *widget, GdkEventBu return TRUE; } -static gboolean _lib_ratings_button_release_callback(GtkWidget *widget, GdkEventButton *event, - gpointer user_data) +static gboolean _lib_ratings_button_release_callback(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { /* dt_lib_module_t *self = (dt_lib_module_t *)user_data; self=NULL;*/ return TRUE; } -static gboolean _lib_ratings_leave_notify_callback(GtkWidget *widget, GdkEventCrossing *event, - gpointer user_data) +static gboolean _lib_ratings_leave_notify_callback(GtkWidget *widget, GdkEventCrossing *event, gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_ratings_t *d = (dt_lib_ratings_t *)self->data; diff --git a/src/libs/tools/view_toolbox.c b/src/libs/tools/view_toolbox.c index 0358c17b801c..52b781db820f 100644 --- a/src/libs/tools/view_toolbox.c +++ b/src/libs/tools/view_toolbox.c @@ -30,7 +30,7 @@ static void _lib_view_toolbox_add(dt_lib_module_t *self, GtkWidget *widget, dt_v typedef struct child_data_t { - GtkWidget * child; + GtkWidget *child; dt_view_type_flags_t views; } child_data_t; @@ -38,7 +38,7 @@ typedef struct child_data_t typedef struct dt_lib_view_toolbox_t { GtkWidget *container; - GList * child_views; + GList *child_views; } dt_lib_view_toolbox_t; const char *name(dt_lib_module_t *self) @@ -48,7 +48,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"darkroom", "lighttable", "tethering", NULL}; + static const char *v[] = { "darkroom", "lighttable", "tethering", NULL }; return v; } @@ -84,20 +84,20 @@ void gui_init(dt_lib_module_t *self) void gui_cleanup(dt_lib_module_t *self) { dt_lib_view_toolbox_t *d = (dt_lib_view_toolbox_t *)self->data; - g_list_free_full(d->child_views,free); + g_list_free_full(d->child_views, free); g_free(self->data); self->data = NULL; } -void view_enter(struct dt_lib_module_t *self,struct dt_view_t *old_view,struct dt_view_t *new_view) +void view_enter(struct dt_lib_module_t *self, struct dt_view_t *old_view, struct dt_view_t *new_view) { dt_lib_view_toolbox_t *d = (dt_lib_view_toolbox_t *)self->data; GList *child_elt = d->child_views; - dt_view_type_flags_t nv= new_view->view(new_view); + dt_view_type_flags_t nv = new_view->view(new_view); while(child_elt) { - child_data_t* child_data = (child_data_t*)child_elt->data; - if(child_data->views & nv) + child_data_t *child_data = (child_data_t *)child_elt->data; + if(child_data->views & nv) { gtk_widget_show_all(child_data->child); } @@ -119,8 +119,7 @@ static void _lib_view_toolbox_add(dt_lib_module_t *self, GtkWidget *widget, dt_v child_data_t *child_data = malloc(sizeof(child_data_t)); child_data->child = widget; child_data->views = views; - d->child_views = g_list_prepend(d->child_views,child_data); - + d->child_views = g_list_prepend(d->child_views, child_data); } // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh // vim: shiftwidth=2 expandtab tabstop=2 cindent diff --git a/src/libs/tools/viewswitcher.c b/src/libs/tools/viewswitcher.c index ee2186d08445..406b4b5ec265 100644 --- a/src/libs/tools/viewswitcher.c +++ b/src/libs/tools/viewswitcher.c @@ -49,8 +49,8 @@ static gboolean _lib_viewswitcher_button_press_callback(GtkWidget *w, GdkEventBu /* helper function to create a label */ static GtkWidget *_lib_viewswitcher_create_label(dt_view_t *view); /* callback when view changed signal happens */ -static void _lib_viewswitcher_view_changed_callback(gpointer instance, dt_view_t *old_view, - dt_view_t *new_view, gpointer user_data); +static void _lib_viewswitcher_view_changed_callback(gpointer instance, dt_view_t *old_view, dt_view_t *new_view, + gpointer user_data); static void _switch_view(const dt_view_t *view); const char *name(dt_lib_module_t *self) @@ -60,7 +60,7 @@ const char *name(dt_lib_module_t *self) const char **views(dt_lib_module_t *self) { - static const char *v[] = {"*", NULL}; + static const char *v[] = { "*", NULL }; return v; } @@ -138,20 +138,22 @@ void gui_init(dt_lib_module_t *self) gtk_widget_set_name(d->dropdown, "view_dropdown"); GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(d->dropdown), renderer, FALSE); - gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(d->dropdown), renderer, "markup", TEXT_COLUMN, - "sensitive", SENSITIVE_COLUMN, NULL); + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(d->dropdown), renderer, "markup", TEXT_COLUMN, "sensitive", + SENSITIVE_COLUMN, NULL); gtk_list_store_append(model, &tree_iter); -// char *italic = g_strdup_printf("<i>%s</i>", _("other")); - gtk_list_store_set(model, &tree_iter, TEXT_COLUMN, /*italic*/ _("other"), VIEW_COLUMN, NULL, SENSITIVE_COLUMN, 0, -1); -// g_free(italic); + // char *italic = g_strdup_printf("<i>%s</i>", _("other")); + gtk_list_store_set(model, &tree_iter, TEXT_COLUMN, /*italic*/ _("other"), VIEW_COLUMN, NULL, + SENSITIVE_COLUMN, 0, -1); + // g_free(italic); gtk_box_pack_start(GTK_BOX(self->widget), d->dropdown, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(d->dropdown), "changed", G_CALLBACK(_dropdown_changed), d); } gtk_list_store_append(model, &tree_iter); - gtk_list_store_set(model, &tree_iter, TEXT_COLUMN, view->name(view), VIEW_COLUMN, view, SENSITIVE_COLUMN, 1, -1); + gtk_list_store_set(model, &tree_iter, TEXT_COLUMN, view->name(view), VIEW_COLUMN, view, SENSITIVE_COLUMN, 1, + -1); } } @@ -191,8 +193,8 @@ static void _lib_viewswitcher_leave_notify_callback(GtkWidget *w, GdkEventCrossi } } -static void _lib_viewswitcher_view_changed_callback(gpointer instance, dt_view_t *old_view, - dt_view_t *new_view, gpointer user_data) +static void _lib_viewswitcher_view_changed_callback(gpointer instance, dt_view_t *old_view, dt_view_t *new_view, + gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_viewswitcher_t *d = (dt_lib_viewswitcher_t *)self->data; @@ -225,18 +227,18 @@ static void _lib_viewswitcher_view_changed_callback(gpointer instance, dt_view_t GtkTreeIter iter; uint32_t index = 0; if(gtk_tree_model_get_iter_first(model, &iter) == TRUE) do - { - gchar *str; - gtk_tree_model_get(model, &iter, TEXT_COLUMN, &str, -1); - if(!g_strcmp0(str, name)) { - gtk_combo_box_set_active(GTK_COMBO_BOX(d->dropdown), index); - gtk_widget_set_state_flags(d->dropdown, GTK_STATE_FLAG_SELECTED, TRUE); - break; - } - g_free(str); - index++; - } while(gtk_tree_model_iter_next(model, &iter) == TRUE); + gchar *str; + gtk_tree_model_get(model, &iter, TEXT_COLUMN, &str, -1); + if(!g_strcmp0(str, name)) + { + gtk_combo_box_set_active(GTK_COMBO_BOX(d->dropdown), index); + gtk_widget_set_state_flags(d->dropdown, GTK_STATE_FLAG_SELECTED, TRUE); + break; + } + g_free(str); + index++; + } while(gtk_tree_model_iter_next(model, &iter) == TRUE); } g_signal_handlers_unblock_by_func(d->dropdown, _dropdown_changed, d); diff --git a/src/lua/call.c b/src/lua/call.c index 17da0231b3cf..ef21fe367e5a 100644 --- a/src/lua/call.c +++ b/src/lua/call.c @@ -27,29 +27,29 @@ #include <sys/select.h> #endif -int dt_lua_check_print_error(lua_State* L, int result) +int dt_lua_check_print_error(lua_State *L, int result) { if(result == LUA_OK) return result; if(darktable.unmuted & DT_DEBUG_LUA) { dt_print(DT_DEBUG_LUA, "LUA ERROR : %s\n", lua_tostring(L, -1)); } - lua_pop(L,1); // remove the error message, it has been handled + lua_pop(L, 1); // remove the error message, it has been handled return result; } -static int create_backtrace(lua_State*L) +static int create_backtrace(lua_State *L) { - luaL_traceback(L,L,lua_tostring(L,-1),0); + luaL_traceback(L, L, lua_tostring(L, -1), 0); return 1; } -int dt_lua_treated_pcall(lua_State*L, int nargs, int nresults) +int dt_lua_treated_pcall(lua_State *L, int nargs, int nresults) { - lua_pushcfunction(L,create_backtrace); - lua_insert(L,1); - int result = dt_lua_check_print_error(L,lua_pcall(L,nargs,nresults,1)); - lua_remove(L,1); + lua_pushcfunction(L, create_backtrace); + lua_insert(L, 1); + int result = dt_lua_check_print_error(L, lua_pcall(L, nargs, nresults, 1)); + lua_remove(L, 1); return result; } @@ -58,7 +58,8 @@ int dt_lua_treated_pcall(lua_State*L, int nargs, int nresults) /* THREAD * threads are a way to store some work that will be done later - * threads are saved in the table at REGISTRY_INDEX "dt_lua_bg_thread", that table is manipulated with save_thread, get_thread, drop_thread. They have a unique integer ID + * threads are saved in the table at REGISTRY_INDEX "dt_lua_bg_thread", that table is manipulated with + save_thread, get_thread, drop_thread. They have a unique integer ID * each thread is a lua_State with the folowing convention for its stack -- top of the stack -- * args @@ -86,72 +87,75 @@ int dt_lua_treated_pcall(lua_State*L, int nargs, int nresults) * check all call, pcall etc... sites * lua lock et recursivité * réimplémenter l'intégration avec la boucle gtk pour mieux faire le bounce - ? add a name in the thread stack for debug purpose + ? add a name in the thread stack for debug purpose * two pcall with no tracebacks: call.c and lua.c */ -static int save_thread(lua_State* L) +static int save_thread(lua_State *L) { lua_getfield(L, LUA_REGISTRYINDEX, "dt_lua_bg_threads"); - lua_pushvalue(L,-2); - const int thread_num = luaL_ref(L,-2); - lua_pop(L,2); + lua_pushvalue(L, -2); + const int thread_num = luaL_ref(L, -2); + lua_pop(L, 2); return thread_num; } -static lua_State* get_thread(lua_State* L, int thread_num) +static lua_State *get_thread(lua_State *L, int thread_num) { lua_getfield(L, LUA_REGISTRYINDEX, "dt_lua_bg_threads"); - lua_pushinteger(L,thread_num); - lua_gettable(L,-2); - lua_State* thread = lua_tothread(L,-1); - lua_pop(L,2); + lua_pushinteger(L, thread_num); + lua_gettable(L, -2); + lua_State *thread = lua_tothread(L, -1); + lua_pop(L, 2); return thread; } -static void drop_thread(lua_State*L, int thread_num) +static void drop_thread(lua_State *L, int thread_num) { lua_getfield(L, LUA_REGISTRYINDEX, "dt_lua_bg_threads"); - lua_pushinteger(L,thread_num); + lua_pushinteger(L, thread_num); lua_pushnil(L); - lua_settable(L,-3); - lua_pop(L,1); + lua_settable(L, -3); + lua_pop(L, 1); } -static void run_async_thread_main(gpointer data,gpointer user_data) +static void run_async_thread_main(gpointer data, gpointer user_data) { // lua lock ownership transfered from parent thread int thread_num = GPOINTER_TO_INT(data); - lua_State*L = darktable.lua_state.state; - lua_State* thread = get_thread(L,thread_num); - if(!thread) { + lua_State *L = darktable.lua_state.state; + lua_State *thread = get_thread(L, thread_num); + if(!thread) + { dt_print(DT_DEBUG_LUA, "LUA ERROR : no thread found, this should never happen\n"); return; } - dt_lua_finish_callback cb = lua_touserdata(thread,1); - void * cb_data = lua_touserdata(thread,2); + dt_lua_finish_callback cb = lua_touserdata(thread, 1); + void *cb_data = lua_touserdata(thread, 2); int nresults = lua_tointeger(thread, 3); - lua_pushcfunction(thread,create_backtrace); - lua_insert(thread,4); - int thread_result = lua_pcall(thread, lua_gettop(thread)-5,nresults,4); - if(cb) { - cb(thread,thread_result,cb_data); - } else { - dt_lua_check_print_error(thread,thread_result); + lua_pushcfunction(thread, create_backtrace); + lua_insert(thread, 4); + int thread_result = lua_pcall(thread, lua_gettop(thread) - 5, nresults, 4); + if(cb) + { + cb(thread, thread_result, cb_data); + } + else + { + dt_lua_check_print_error(thread, thread_result); } - drop_thread(L,thread_num); + drop_thread(L, thread_num); dt_lua_unlock(); return; - } -static void run_async_thread(lua_State* L, int thread_num) +static void run_async_thread(lua_State *L, int thread_num) { - g_thread_pool_push(darktable.lua_state.pool,GINT_TO_POINTER(thread_num),NULL); + g_thread_pool_push(darktable.lua_state.pool, GINT_TO_POINTER(thread_num), NULL); // lock ownership is transfered to the new thread. We want to block until it is returned to us // either because the other thread finished or because it paused dt_lua_lock(); @@ -162,80 +166,74 @@ static void run_async_thread(lua_State* L, int thread_num) END JOB This is a source that deals with DT termination. it triggers when DT exits */ -static gboolean end_job_prepare (GSource *source, gint *timeout) +static gboolean end_job_prepare(GSource *source, gint *timeout) { return darktable.lua_state.ending; } -static gboolean end_job_dispatch (GSource* source, GSourceFunc callback, gpointer user_data) +static gboolean end_job_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) { g_main_loop_quit(darktable.lua_state.loop); - g_thread_pool_free(darktable.lua_state.pool,false,true); + g_thread_pool_free(darktable.lua_state.pool, false, true); return G_SOURCE_REMOVE; } -static GSourceFuncs end_job_funcs = -{ - end_job_prepare, - NULL, /* check */ - end_job_dispatch, - NULL, +static GSourceFuncs end_job_funcs = { + end_job_prepare, NULL, /* check */ + end_job_dispatch, NULL, }; static void end_job_init() { - GSource *source = g_source_new (&end_job_funcs, sizeof (GSource)); - g_source_set_name (source, "lua_end_job_source"); + GSource *source = g_source_new(&end_job_funcs, sizeof(GSource)); + g_source_set_name(source, "lua_end_job_source"); // make sure to finish any non-blocking job before we quit - g_source_set_priority(source,G_PRIORITY_DEFAULT_IDLE); - g_source_attach(source,darktable.lua_state.context); + g_source_set_priority(source, G_PRIORITY_DEFAULT_IDLE); + g_source_attach(source, darktable.lua_state.context); } /* STACKED JOB - This is a source that deals with lua jobs that are put on the stack to + This is a source that deals with lua jobs that are put on the stack to be run on the lua thread. */ -static gboolean stacked_job_prepare (GSource *source, gint *timeout) +static gboolean stacked_job_prepare(GSource *source, gint *timeout) { return (g_async_queue_length(darktable.lua_state.stacked_job_queue) > 0); } -static gboolean stacked_job_dispatch (GSource* source, GSourceFunc callback, gpointer user_data) +static gboolean stacked_job_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) { gpointer message; - message = g_async_queue_try_pop (darktable.lua_state.stacked_job_queue); - if (message == NULL) + message = g_async_queue_try_pop(darktable.lua_state.stacked_job_queue); + if(message == NULL) { return TRUE; } dt_lua_lock(); - lua_State* L= darktable.lua_state.state; + lua_State *L = darktable.lua_state.state; int reference = GPOINTER_TO_INT(message); - run_async_thread(L,reference); + run_async_thread(L, reference); dt_lua_unlock(); return G_SOURCE_CONTINUE; } -static void stacked_job_finalize (GSource *source) +static void stacked_job_finalize(GSource *source) { g_async_queue_unref(darktable.lua_state.stacked_job_queue); darktable.lua_state.stacked_job_queue = NULL; } -static GSourceFuncs stacked_job_funcs = -{ - stacked_job_prepare, - NULL, /* check */ - stacked_job_dispatch, - stacked_job_finalize, +static GSourceFuncs stacked_job_funcs = { + stacked_job_prepare, NULL, /* check */ + stacked_job_dispatch, stacked_job_finalize, }; static void stacked_job_init() { darktable.lua_state.stacked_job_queue = g_async_queue_new(); - GSource *source = g_source_new (&stacked_job_funcs, sizeof (GSource)); - g_source_set_name (source, "lua_stacked_job_source"); - g_source_attach(source,darktable.lua_state.context); + GSource *source = g_source_new(&stacked_job_funcs, sizeof(GSource)); + g_source_set_name(source, "lua_stacked_job_source"); + g_source_attach(source, darktable.lua_state.context); } /* @@ -244,45 +242,48 @@ static void stacked_job_init() varags. This is used to queue a lua job without owning the lua lock */ -typedef struct { +typedef struct +{ lua_CFunction pusher; - GList* extra; + GList *extra; dt_lua_finish_callback cb; - void * cb_data; + void *cb_data; int nresults; -}async_call_data; +} async_call_data; -static gboolean alien_job_prepare (GSource *source, gint *timeout) +static gboolean alien_job_prepare(GSource *source, gint *timeout) { return (g_async_queue_length(darktable.lua_state.alien_job_queue) > 0); } static void alien_job_destroy(void *data_ptr) { - async_call_data* data = data_ptr; + async_call_data *data = data_ptr; - GList* cur_elt = data->extra; - while(cur_elt) { - GList * type_type_elt = cur_elt; + GList *cur_elt = data->extra; + while(cur_elt) + { + GList *type_type_elt = cur_elt; cur_elt = g_list_next(cur_elt); - //GList * type_elt = cur_elt; + // GList * type_elt = cur_elt; cur_elt = g_list_next(cur_elt); - GList * data_elt = cur_elt; + GList *data_elt = cur_elt; cur_elt = g_list_next(cur_elt); - switch(GPOINTER_TO_INT(type_type_elt->data)) { + switch(GPOINTER_TO_INT(type_type_elt->data)) + { case LUA_ASYNC_TYPEID_WITH_FREE: case LUA_ASYNC_TYPENAME_WITH_FREE: - { - GList *destructor_elt = cur_elt; - cur_elt = g_list_next(cur_elt); - GValue to_free = G_VALUE_INIT; - g_value_init(&to_free,G_TYPE_POINTER); - g_value_set_pointer(&to_free,data_elt->data); - g_closure_invoke(destructor_elt->data,NULL,1,&to_free,NULL); - g_closure_unref (destructor_elt->data); - } - break; + { + GList *destructor_elt = cur_elt; + cur_elt = g_list_next(cur_elt); + GValue to_free = G_VALUE_INIT; + g_value_init(&to_free, G_TYPE_POINTER); + g_value_set_pointer(&to_free, data_elt->data); + g_closure_invoke(destructor_elt->data, NULL, 1, &to_free, NULL); + g_closure_unref(destructor_elt->data); + } + break; case LUA_ASYNC_TYPEID: case LUA_ASYNC_TYPENAME: break; @@ -297,47 +298,49 @@ static void alien_job_destroy(void *data_ptr) free(data); } -static gboolean alien_job_dispatch (GSource* source, GSourceFunc callback, gpointer user_data) +static gboolean alien_job_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) { gpointer message; - message = g_async_queue_try_pop (darktable.lua_state.alien_job_queue); - if (message == NULL) + message = g_async_queue_try_pop(darktable.lua_state.alien_job_queue); + if(message == NULL) { return TRUE; } - async_call_data* data = (async_call_data*)message; + async_call_data *data = (async_call_data *)message; dt_lua_lock(); - lua_State* L= darktable.lua_state.state; + lua_State *L = darktable.lua_state.state; lua_State *new_thread = lua_newthread(L); int reference = save_thread(L); - lua_pushlightuserdata(new_thread,data->cb); - lua_pushlightuserdata(new_thread,data->cb_data); - lua_pushinteger(new_thread,data->nresults); - lua_pushcfunction(new_thread,data->pusher); - - GList* cur_elt = data->extra; - while(cur_elt) { - GList * type_type_elt = cur_elt; + lua_pushlightuserdata(new_thread, data->cb); + lua_pushlightuserdata(new_thread, data->cb_data); + lua_pushinteger(new_thread, data->nresults); + lua_pushcfunction(new_thread, data->pusher); + + GList *cur_elt = data->extra; + while(cur_elt) + { + GList *type_type_elt = cur_elt; cur_elt = g_list_next(cur_elt); - GList * type_elt = cur_elt; + GList *type_elt = cur_elt; cur_elt = g_list_next(cur_elt); - GList * data_elt = cur_elt; + GList *data_elt = cur_elt; cur_elt = g_list_next(cur_elt); - switch(GPOINTER_TO_INT(type_type_elt->data)) { + switch(GPOINTER_TO_INT(type_type_elt->data)) + { case LUA_ASYNC_TYPEID_WITH_FREE: // skip the destructor cur_elt = g_list_next(cur_elt); - // do not break + // do not break case LUA_ASYNC_TYPEID: - luaA_push_type(new_thread,GPOINTER_TO_INT(type_elt->data),data_elt->data); + luaA_push_type(new_thread, GPOINTER_TO_INT(type_elt->data), data_elt->data); break; case LUA_ASYNC_TYPENAME_WITH_FREE: // skip the destructor cur_elt = g_list_next(cur_elt); - // do not break + // do not break case LUA_ASYNC_TYPENAME: - luaA_push_type(new_thread,luaA_type_find(L,type_elt->data),&data_elt->data); + luaA_push_type(new_thread, luaA_type_find(L, type_elt->data), &data_elt->data); break; case LUA_ASYNC_DONE: default: @@ -346,37 +349,34 @@ static gboolean alien_job_dispatch (GSource* source, GSourceFunc callback, gpoin break; } } - run_async_thread(L,reference); + run_async_thread(L, reference); dt_lua_unlock(); alien_job_destroy(data); return G_SOURCE_CONTINUE; } -static void alien_job_finalize (GSource *source) +static void alien_job_finalize(GSource *source) { - gpointer message = g_async_queue_try_pop (darktable.lua_state.alien_job_queue); - while(message) { + gpointer message = g_async_queue_try_pop(darktable.lua_state.alien_job_queue); + while(message) + { alien_job_destroy(message); - message = g_async_queue_try_pop (darktable.lua_state.alien_job_queue); - + message = g_async_queue_try_pop(darktable.lua_state.alien_job_queue); } g_async_queue_unref(darktable.lua_state.alien_job_queue); darktable.lua_state.alien_job_queue = NULL; } -static GSourceFuncs alien_job_funcs = -{ - alien_job_prepare, - NULL, /* check */ - alien_job_dispatch, - alien_job_finalize, +static GSourceFuncs alien_job_funcs = { + alien_job_prepare, NULL, /* check */ + alien_job_dispatch, alien_job_finalize, }; static void alien_job_init() { darktable.lua_state.alien_job_queue = g_async_queue_new(); - GSource *source = g_source_new (&alien_job_funcs, sizeof (GSource)); - g_source_set_name (source, "lua_alien_job_source"); - g_source_attach(source,darktable.lua_state.context); + GSource *source = g_source_new(&alien_job_funcs, sizeof(GSource)); + g_source_set_name(source, "lua_alien_job_source"); + g_source_attach(source, darktable.lua_state.context); } /* @@ -384,238 +384,245 @@ static void alien_job_init() This is a source that deals with lua jobs that are gien as lua strings */ -typedef struct { - char* function; +typedef struct +{ + char *function; dt_lua_finish_callback cb; - void * cb_data; + void *cb_data; int nresults; -}string_call_data; +} string_call_data; -static gboolean string_job_prepare (GSource *source, gint *timeout) +static gboolean string_job_prepare(GSource *source, gint *timeout) { return (g_async_queue_length(darktable.lua_state.string_job_queue) > 0); } -static void string_data_destroy(string_call_data * data) +static void string_data_destroy(string_call_data *data) { free(data->function); free(data); } -static gboolean string_job_dispatch (GSource* source, GSourceFunc callback, gpointer user_data) +static gboolean string_job_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) { gpointer message; - message = g_async_queue_try_pop (darktable.lua_state.string_job_queue); - if (message == NULL) + message = g_async_queue_try_pop(darktable.lua_state.string_job_queue); + if(message == NULL) { return TRUE; } - string_call_data* data = (string_call_data*)message; + string_call_data *data = (string_call_data *)message; dt_lua_lock(); - lua_State* L= darktable.lua_state.state; + lua_State *L = darktable.lua_state.state; lua_State *new_thread = lua_newthread(L); int reference = save_thread(L); - lua_pushlightuserdata(new_thread,data->cb); - lua_pushlightuserdata(new_thread,data->cb_data); - lua_pushinteger(new_thread,data->nresults); + lua_pushlightuserdata(new_thread, data->cb); + lua_pushlightuserdata(new_thread, data->cb_data); + lua_pushinteger(new_thread, data->nresults); int load_result = luaL_loadstring(new_thread, data->function); if(load_result != LUA_OK) { - if(data->cb) { - data->cb(new_thread,load_result,data->cb_data); - } else { - dt_lua_check_print_error(new_thread,load_result); + if(data->cb) + { + data->cb(new_thread, load_result, data->cb_data); + } + else + { + dt_lua_check_print_error(new_thread, load_result); } - drop_thread(L,reference); + drop_thread(L, reference); dt_lua_unlock(); string_data_destroy(data); return G_SOURCE_CONTINUE; } - run_async_thread(L,reference); + run_async_thread(L, reference); dt_lua_unlock(); string_data_destroy(data); return G_SOURCE_CONTINUE; } -static void string_job_finalize (GSource *source) +static void string_job_finalize(GSource *source) { - gpointer message = g_async_queue_try_pop (darktable.lua_state.string_job_queue); - while(message) { + gpointer message = g_async_queue_try_pop(darktable.lua_state.string_job_queue); + while(message) + { string_data_destroy(message); - message = g_async_queue_try_pop (darktable.lua_state.string_job_queue); - + message = g_async_queue_try_pop(darktable.lua_state.string_job_queue); } g_async_queue_unref(darktable.lua_state.string_job_queue); darktable.lua_state.string_job_queue = NULL; } -static GSourceFuncs string_job_funcs = -{ - string_job_prepare, - NULL, /* check */ - string_job_dispatch, - string_job_finalize, +static GSourceFuncs string_job_funcs = { + string_job_prepare, NULL, /* check */ + string_job_dispatch, string_job_finalize, }; static void string_job_init() { darktable.lua_state.string_job_queue = g_async_queue_new(); - GSource *source = g_source_new (&string_job_funcs, sizeof (GSource)); - g_source_set_name (source, "lua_string_job_source"); - g_source_attach(source,darktable.lua_state.context); + GSource *source = g_source_new(&string_job_funcs, sizeof(GSource)); + g_source_set_name(source, "lua_string_job_source"); + g_source_attach(source, darktable.lua_state.context); } -void dt_lua_async_call_internal(const char* function, int line,lua_State *L, int nargs,int nresults,dt_lua_finish_callback cb, void*data) +void dt_lua_async_call_internal(const char *function, int line, lua_State *L, int nargs, int nresults, + dt_lua_finish_callback cb, void *data) { #ifdef _DEBUG - dt_print(DT_DEBUG_LUA,"LUA DEBUG : %s called from %s %d, nargs : %d\n",__FUNCTION__,function,line,nargs); + dt_print(DT_DEBUG_LUA, "LUA DEBUG : %s called from %s %d, nargs : %d\n", __FUNCTION__, function, line, nargs); #endif - + lua_State *new_thread = lua_newthread(L); - lua_pushlightuserdata(new_thread,cb); - lua_pushlightuserdata(new_thread,data); - lua_pushinteger(new_thread,nresults); + lua_pushlightuserdata(new_thread, cb); + lua_pushlightuserdata(new_thread, data); + lua_pushinteger(new_thread, nresults); int reference = save_thread(L); - lua_xmove(L,new_thread,nargs+1); - g_async_queue_push(darktable.lua_state.stacked_job_queue,GINT_TO_POINTER(reference)); + lua_xmove(L, new_thread, nargs + 1); + g_async_queue_push(darktable.lua_state.stacked_job_queue, GINT_TO_POINTER(reference)); g_main_context_wakeup(darktable.lua_state.context); } -void dt_lua_async_call_alien_internal(const char * call_function, int line,lua_CFunction pusher,int nresults,dt_lua_finish_callback cb, void*cb_data, dt_lua_async_call_arg_type arg_type,...) +void dt_lua_async_call_alien_internal(const char *call_function, int line, lua_CFunction pusher, int nresults, + dt_lua_finish_callback cb, void *cb_data, + dt_lua_async_call_arg_type arg_type, ...) { - if(!darktable.lua_state.alien_job_queue) { - // early call before lua has properly been initialized, ignore + if(!darktable.lua_state.alien_job_queue) + { +// early call before lua has properly been initialized, ignore #ifdef _DEBUG - dt_print(DT_DEBUG_LUA,"LUA DEBUG : %s called early. probably ok.\n",__FUNCTION__); + dt_print(DT_DEBUG_LUA, "LUA DEBUG : %s called early. probably ok.\n", __FUNCTION__); #endif return; } #ifdef _DEBUG - dt_print(DT_DEBUG_LUA,"LUA DEBUG : %s called from %s %d\n",__FUNCTION__,call_function,line); + dt_print(DT_DEBUG_LUA, "LUA DEBUG : %s called from %s %d\n", __FUNCTION__, call_function, line); #endif - async_call_data*data = malloc(sizeof(async_call_data)); + async_call_data *data = malloc(sizeof(async_call_data)); data->pusher = pusher; - data->extra=NULL; + data->extra = NULL; data->cb = cb; data->cb_data = cb_data; data->nresults = nresults; va_list ap; - va_start(ap,arg_type); + va_start(ap, arg_type); dt_lua_async_call_arg_type cur_type = arg_type; - while(cur_type != LUA_ASYNC_DONE){ - data->extra=g_list_append(data->extra,GINT_TO_POINTER(cur_type)); - switch(cur_type) { + while(cur_type != LUA_ASYNC_DONE) + { + data->extra = g_list_append(data->extra, GINT_TO_POINTER(cur_type)); + switch(cur_type) + { case LUA_ASYNC_TYPEID: - data->extra=g_list_append(data->extra,GINT_TO_POINTER(va_arg(ap,luaA_Type))); - data->extra=g_list_append(data->extra,va_arg(ap,gpointer)); + data->extra = g_list_append(data->extra, GINT_TO_POINTER(va_arg(ap, luaA_Type))); + data->extra = g_list_append(data->extra, va_arg(ap, gpointer)); break; case LUA_ASYNC_TYPEID_WITH_FREE: - { - data->extra=g_list_append(data->extra,GINT_TO_POINTER(va_arg(ap,luaA_Type))); - data->extra=g_list_append(data->extra,va_arg(ap,gpointer)); - GClosure* closure = va_arg(ap,GClosure*); - g_closure_ref (closure); - g_closure_sink (closure); - g_closure_set_marshal(closure, g_cclosure_marshal_generic); - data->extra=g_list_append(data->extra,closure); - } - break; + { + data->extra = g_list_append(data->extra, GINT_TO_POINTER(va_arg(ap, luaA_Type))); + data->extra = g_list_append(data->extra, va_arg(ap, gpointer)); + GClosure *closure = va_arg(ap, GClosure *); + g_closure_ref(closure); + g_closure_sink(closure); + g_closure_set_marshal(closure, g_cclosure_marshal_generic); + data->extra = g_list_append(data->extra, closure); + } + break; case LUA_ASYNC_TYPENAME: - data->extra=g_list_append(data->extra,va_arg(ap,char *)); - data->extra=g_list_append(data->extra,va_arg(ap,gpointer)); + data->extra = g_list_append(data->extra, va_arg(ap, char *)); + data->extra = g_list_append(data->extra, va_arg(ap, gpointer)); break; case LUA_ASYNC_TYPENAME_WITH_FREE: - { - data->extra=g_list_append(data->extra,va_arg(ap,char *)); - data->extra=g_list_append(data->extra,va_arg(ap,gpointer)); - GClosure* closure = va_arg(ap,GClosure*); - g_closure_ref (closure); - g_closure_sink (closure); - g_closure_set_marshal(closure, g_cclosure_marshal_generic); - data->extra=g_list_append(data->extra,closure); - } - break; + { + data->extra = g_list_append(data->extra, va_arg(ap, char *)); + data->extra = g_list_append(data->extra, va_arg(ap, gpointer)); + GClosure *closure = va_arg(ap, GClosure *); + g_closure_ref(closure); + g_closure_sink(closure); + g_closure_set_marshal(closure, g_cclosure_marshal_generic); + data->extra = g_list_append(data->extra, closure); + } + break; default: // should never happen g_assert(false); break; } - cur_type = va_arg(ap,dt_lua_async_call_arg_type); + cur_type = va_arg(ap, dt_lua_async_call_arg_type); } va_end(ap); - g_async_queue_push(darktable.lua_state.alien_job_queue,(gpointer)data); + g_async_queue_push(darktable.lua_state.alien_job_queue, (gpointer)data); g_main_context_wakeup(darktable.lua_state.context); } -void dt_lua_async_call_string_internal(const char* function, int line,const char* lua_string,int nresults,dt_lua_finish_callback cb, void*cb_data) +void dt_lua_async_call_string_internal(const char *function, int line, const char *lua_string, int nresults, + dt_lua_finish_callback cb, void *cb_data) { #ifdef _DEBUG - dt_print(DT_DEBUG_LUA,"LUA DEBUG : %s called from %s %d, string %s\n",__FUNCTION__,function,line,lua_string); + dt_print(DT_DEBUG_LUA, "LUA DEBUG : %s called from %s %d, string %s\n", __FUNCTION__, function, line, lua_string); #endif - string_call_data*data = malloc(sizeof(string_call_data)); + string_call_data *data = malloc(sizeof(string_call_data)); data->function = strdup(lua_string); data->cb = cb; data->cb_data = cb_data; data->nresults = nresults; - g_async_queue_push(darktable.lua_state.string_job_queue,(gpointer)data); + g_async_queue_push(darktable.lua_state.string_job_queue, (gpointer)data); g_main_context_wakeup(darktable.lua_state.context); - } static gpointer lua_thread_main(gpointer data) { - darktable.lua_state.pool = g_thread_pool_new(run_async_thread_main,NULL,-1,false,NULL); - darktable.lua_state.loop = g_main_loop_new(darktable.lua_state.context,false); + darktable.lua_state.pool = g_thread_pool_new(run_async_thread_main, NULL, -1, false, NULL); + darktable.lua_state.loop = g_main_loop_new(darktable.lua_state.context, false); g_main_loop_run(darktable.lua_state.loop); return 0; } static int dispatch_cb(lua_State *L) { - dt_lua_async_call(L,lua_gettop(L)-1,0,NULL,NULL); + dt_lua_async_call(L, lua_gettop(L) - 1, 0, NULL, NULL); return 0; } static int ending_cb(lua_State *L) { - lua_pushboolean(L,darktable.lua_state.ending); + lua_pushboolean(L, darktable.lua_state.ending); return 1; } -static int execute_cb(lua_State*L) +static int execute_cb(lua_State *L) { const char *cmd = luaL_optstring(L, 1, NULL); dt_lua_unlock(); int stat = system(cmd); dt_lua_lock(); - lua_pushinteger(L,stat); + lua_pushinteger(L, stat); return 1; } -static int sleep_cb(lua_State*L) +static int sleep_cb(lua_State *L) { const int delay = luaL_optinteger(L, 1, 0); dt_lua_unlock(); - g_usleep(delay*1000); + g_usleep(delay * 1000); dt_lua_lock(); return 0; } -#if !defined (_WIN32) -static int read_cb(lua_State*L) +#if !defined(_WIN32) +static int read_cb(lua_State *L) { - luaL_checkudata(L,1,LUA_FILEHANDLE); + luaL_checkudata(L, 1, LUA_FILEHANDLE); luaL_Stream *stream = lua_touserdata(L, 1); int myfileno = fileno(stream->f); fd_set fdset; @@ -628,7 +635,8 @@ static int read_cb(lua_State*L) } #endif -typedef struct gtk_wrap_communication { +typedef struct gtk_wrap_communication +{ GCond end_cond; GMutex end_mutex; lua_State *L; @@ -638,24 +646,27 @@ typedef struct gtk_wrap_communication { gboolean dt_lua_gtk_wrap_callback(gpointer data) { dt_lua_lock_silent(); - gtk_wrap_communication *communication = (gtk_wrap_communication*)data; + gtk_wrap_communication *communication = (gtk_wrap_communication *)data; g_mutex_lock(&communication->end_mutex); // TODO : propre stack unwinding - communication->retval = lua_pcall(communication->L,lua_gettop(communication->L)-1,LUA_MULTRET,0); + communication->retval = lua_pcall(communication->L, lua_gettop(communication->L) - 1, LUA_MULTRET, 0); g_cond_signal(&communication->end_cond); g_mutex_unlock(&communication->end_mutex); dt_lua_unlock(); return false; -} - -static int gtk_wrap(lua_State*L) -{ - lua_pushvalue(L,lua_upvalueindex(1)); - lua_insert(L,1); - if(pthread_equal(darktable.control->gui_thread, pthread_self())) { - lua_call(L, lua_gettop(L)-1, LUA_MULTRET); +} + +static int gtk_wrap(lua_State *L) +{ + lua_pushvalue(L, lua_upvalueindex(1)); + lua_insert(L, 1); + if(pthread_equal(darktable.control->gui_thread, pthread_self())) + { + lua_call(L, lua_gettop(L) - 1, LUA_MULTRET); return lua_gettop(L); - } else { + } + else + { #ifdef _DEBUG dt_print(DT_DEBUG_LUA, "LUA DEBUG : %s called from %s %llu\n", __FUNCTION__, lua_tostring(L, lua_upvalueindex(2)), lua_tointeger(L, lua_upvalueindex(3))); @@ -666,8 +677,8 @@ static int gtk_wrap(lua_State*L) g_cond_init(&communication.end_cond); communication.L = L; g_mutex_lock(&communication.end_mutex); - g_main_context_invoke(NULL,dt_lua_gtk_wrap_callback,&communication); - g_cond_wait(&communication.end_cond,&communication.end_mutex); + g_main_context_invoke(NULL, dt_lua_gtk_wrap_callback, &communication); + g_cond_wait(&communication.end_cond, &communication.end_mutex); g_mutex_unlock(&communication.end_mutex); g_mutex_clear(&communication.end_mutex); dt_lua_lock(); @@ -675,20 +686,22 @@ static int gtk_wrap(lua_State*L) dt_print(DT_DEBUG_LUA, "LUA DEBUG : %s return for call from from %s %llu\n", __FUNCTION__, lua_tostring(L, lua_upvalueindex(2)), lua_tointeger(L, lua_upvalueindex(3))); #endif - if(communication.retval == LUA_OK) { + if(communication.retval == LUA_OK) + { return lua_gettop(L); - } else { + } + else + { return lua_error(L); } } - } -void dt_lua_gtk_wrap_internal(lua_State*L,const char* function, int line) +void dt_lua_gtk_wrap_internal(lua_State *L, const char *function, int line) { - lua_pushstring(L,function); - lua_pushinteger(L,line); - lua_pushcclosure(L,gtk_wrap,3); + lua_pushstring(L, function); + lua_pushinteger(L, line); + lua_pushcclosure(L, gtk_wrap, 3); } int dt_lua_init_call(lua_State *L) { @@ -697,20 +710,20 @@ int dt_lua_init_call(lua_State *L) luaA_Type type_id = dt_lua_init_singleton(L, "control", NULL); lua_setfield(L, -2, "control"); lua_pop(L, 1); - + lua_pushcfunction(L, ending_cb); dt_lua_type_register_const_type(L, type_id, "ending"); lua_pushcfunction(L, dispatch_cb); lua_pushcclosure(L, dt_lua_type_member_common, 1); dt_lua_type_register_const_type(L, type_id, "dispatch"); - lua_pushcfunction(L,execute_cb); + lua_pushcfunction(L, execute_cb); lua_pushcclosure(L, dt_lua_type_member_common, 1); dt_lua_type_register_const_type(L, type_id, "execute"); - lua_pushcfunction(L,sleep_cb); + lua_pushcfunction(L, sleep_cb); lua_pushcclosure(L, dt_lua_type_member_common, 1); dt_lua_type_register_const_type(L, type_id, "sleep"); -#if !defined (_WIN32) - lua_pushcfunction(L,read_cb); +#if !defined(_WIN32) + lua_pushcfunction(L, read_cb); lua_pushcclosure(L, dt_lua_type_member_common, 1); dt_lua_type_register_const_type(L, type_id, "read"); #endif @@ -724,7 +737,7 @@ int dt_lua_init_call(lua_State *L) string_job_init(); end_job_init(); - g_thread_new("lua thread",lua_thread_main,NULL); + g_thread_new("lua thread", lua_thread_main, NULL); return 0; } diff --git a/src/lua/call.h b/src/lua/call.h index 88d4eb2c4300..5f0615848700 100644 --- a/src/lua/call.h +++ b/src/lua/call.h @@ -24,20 +24,20 @@ pop a function from the top of the stack, push a new version on the stack that will be called from the GTK main thread */ -#define dt_lua_gtk_wrap(L) dt_lua_gtk_wrap_internal(L,__FUNCTION__,__LINE__) -void dt_lua_gtk_wrap_internal(lua_State*L,const char* function, int line); +#define dt_lua_gtk_wrap(L) dt_lua_gtk_wrap_internal(L, __FUNCTION__, __LINE__) +void dt_lua_gtk_wrap_internal(lua_State *L, const char *function, int line); /* similar to pcall, but in case of error, it will call dt_lua_check_print_error with a proper stack */ -int dt_lua_treated_pcall(lua_State*L, int nargs, int nresults); -/* +int dt_lua_treated_pcall(lua_State *L, int nargs, int nresults); +/* deal wil lua_pcall calling convention * print the string on the top of L if result != LUA_OK * pop the error string - * return result + * return result */ -int dt_lua_check_print_error(lua_State* L, int result); +int dt_lua_check_print_error(lua_State *L, int result); /* @@ -46,10 +46,12 @@ int dt_lua_check_print_error(lua_State* L, int result); if no callback is provided, a message will be printed in case of error */ -typedef void (*dt_lua_finish_callback)(lua_State* L,int result,void* data); +typedef void (*dt_lua_finish_callback)(lua_State *L, int result, void *data); -void dt_lua_async_call_internal(const char * function, int line,lua_State *L, int nargs,int nresults,dt_lua_finish_callback cb, void*data); -#define dt_lua_async_call(L,nargs,nresults,cb,data) dt_lua_async_call_internal(__FUNCTION__,__LINE__,L,nargs,nresults,cb,data) +void dt_lua_async_call_internal(const char *function, int line, lua_State *L, int nargs, int nresults, + dt_lua_finish_callback cb, void *data); +#define dt_lua_async_call(L, nargs, nresults, cb, data) \ + dt_lua_async_call_internal(__FUNCTION__, __LINE__, L, nargs, nresults, cb, data) /* @@ -62,24 +64,30 @@ void dt_lua_async_call_internal(const char * function, int line,lua_State *L, in * LUA_ASYNC_TYPEID : the type description is a luaA_Typeid * LUA_ASYNC_TYPENAME : the type description is a const char * which is a type name for the lua typing system * ..._WITH_FREE : the value is a pointer that must be freed after being pushed on the stack - add a GClosure parameter : the freeing function. will be invoked with the pointer to free plus any extra data given at closure creation + add a GClosure parameter : the freeing function. will be invoked with the pointer to free plus any extra + data given at closure creation */ -typedef enum { +typedef enum +{ LUA_ASYNC_TYPEID, LUA_ASYNC_TYPEID_WITH_FREE, LUA_ASYNC_TYPENAME, LUA_ASYNC_TYPENAME_WITH_FREE, LUA_ASYNC_DONE } dt_lua_async_call_arg_type; -void dt_lua_async_call_alien_internal(const char * call_function, int line,lua_CFunction function,int nresults,dt_lua_finish_callback cb, void*data, dt_lua_async_call_arg_type arg_type,...); -#define dt_lua_async_call_alien(fn,nresults,cb,data,arg,...) dt_lua_async_call_alien_internal(__FUNCTION__,__LINE__,fn,nresults,cb,data,arg,__VA_ARGS__) - +void dt_lua_async_call_alien_internal(const char *call_function, int line, lua_CFunction function, int nresults, + dt_lua_finish_callback cb, void *data, dt_lua_async_call_arg_type arg_type, + ...); +#define dt_lua_async_call_alien(fn, nresults, cb, data, arg, ...) \ + dt_lua_async_call_alien_internal(__FUNCTION__, __LINE__, fn, nresults, cb, data, arg, __VA_ARGS__) -void dt_lua_async_call_string_internal(const char* function, int line,const char* lua_string,int nresults,dt_lua_finish_callback cb, void*cb_data); -#define dt_lua_async_call_string(lua_string,nresults,cb,data) dt_lua_async_call_string_internal(__FUNCTION__,__LINE__,lua_string,nresults,cb,data) +void dt_lua_async_call_string_internal(const char *function, int line, const char *lua_string, int nresults, + dt_lua_finish_callback cb, void *cb_data); +#define dt_lua_async_call_string(lua_string, nresults, cb, data) \ + dt_lua_async_call_string_internal(__FUNCTION__, __LINE__, lua_string, nresults, cb, data) diff --git a/src/lua/configuration.c b/src/lua/configuration.c index d7a3468bb902..12b7b15ef4a0 100644 --- a/src/lua/configuration.c +++ b/src/lua/configuration.c @@ -26,7 +26,7 @@ static int check_version(lua_State *L) { const char *module_name = "<unnamed module>"; - if(!lua_isnil(L,1)) module_name = luaL_checkstring(L, 1); + if(!lua_isnil(L, 1)) module_name = luaL_checkstring(L, 1); gboolean valid = false; for(int i = 2; i <= lua_gettop(L); i++) { diff --git a/src/lua/database.c b/src/lua/database.c index 63e423bdd9d0..6312bcca79da 100644 --- a/src/lua/database.c +++ b/src/lua/database.c @@ -167,8 +167,7 @@ static int database_numindex(lua_State *L) } sqlite3_stmt *stmt = NULL; char query[1024]; - snprintf(query, sizeof(query), "SELECT id FROM main.images ORDER BY id LIMIT 1 OFFSET %d", - index - 1); + snprintf(query, sizeof(query), "SELECT id FROM main.images ORDER BY id LIMIT 1 OFFSET %d", index - 1); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), query, -1, &stmt, NULL); if(sqlite3_step(stmt) == SQLITE_ROW) { @@ -197,24 +196,23 @@ static int collection_numindex(lua_State *L) { return luaL_error(L, "incorrect index in database"); } - int imgid = dt_collection_get_nth(darktable.collection,index-1); - if (imgid >0) + int imgid = dt_collection_get_nth(darktable.collection, index - 1); + if(imgid > 0) { luaA_push(L, dt_lua_image_t, &imgid); - } else { + } + else + { lua_pushnil(L); } return 1; - } static void on_film_imported(gpointer instance, uint32_t id, gpointer user_data) { - dt_lua_async_call_alien(dt_lua_event_trigger_wrapper, - 0,NULL,NULL, - LUA_ASYNC_TYPENAME,"const char*","post-import-film", - LUA_ASYNC_TYPENAME,"dt_lua_film_t",GINT_TO_POINTER(id), - LUA_ASYNC_DONE); + dt_lua_async_call_alien(dt_lua_event_trigger_wrapper, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "const char*", + "post-import-film", LUA_ASYNC_TYPENAME, "dt_lua_film_t", GINT_TO_POINTER(id), + LUA_ASYNC_DONE); } int dt_lua_init_database(lua_State *L) @@ -258,8 +256,7 @@ int dt_lua_init_database(lua_State *L) lua_pushcfunction(L, dt_lua_event_multiinstance_register); lua_pushcfunction(L, dt_lua_event_multiinstance_trigger); dt_lua_event_add(L, "post-import-film"); - dt_control_signal_connect(darktable.signals, DT_SIGNAL_FILMROLLS_IMPORTED, G_CALLBACK(on_film_imported), - NULL); + dt_control_signal_connect(darktable.signals, DT_SIGNAL_FILMROLLS_IMPORTED, G_CALLBACK(on_film_imported), NULL); lua_pushcfunction(L, dt_lua_event_multiinstance_register); lua_pushcfunction(L, dt_lua_event_multiinstance_trigger); diff --git a/src/lua/events.c b/src/lua/events.c index c4a855184c1b..a57d0294fbde 100644 --- a/src/lua/events.c +++ b/src/lua/events.c @@ -31,7 +31,7 @@ void dt_lua_event_trigger(lua_State *L, const char *event, int nargs) lua_getfield(L, LUA_REGISTRYINDEX, "dt_lua_event_list"); if(lua_isnil(L, -1)) { // events have been disabled - lua_pop(L, nargs+1); + lua_pop(L, nargs + 1); return; } lua_getfield(L, -1, event); @@ -49,17 +49,17 @@ void dt_lua_event_trigger(lua_State *L, const char *event, int nargs) lua_getfield(L, -2, "on_event"); lua_getfield(L, -3, "data"); lua_pushstring(L, event); - for(int i = 1; i <= nargs; i++) lua_pushvalue(L, -6 -nargs); - dt_lua_treated_pcall(L,nargs+2,0); + for(int i = 1; i <= nargs; i++) lua_pushvalue(L, -6 - nargs); + dt_lua_treated_pcall(L, nargs + 2, 0); lua_pop(L, nargs + 3); dt_lua_redraw_screen(); } -int dt_lua_event_trigger_wrapper(lua_State *L) +int dt_lua_event_trigger_wrapper(lua_State *L) { - const char*event = luaL_checkstring(L,1); - int nargs = lua_gettop(L) -1; - dt_lua_event_trigger(L,event,nargs); + const char *event = luaL_checkstring(L, 1); + int nargs = lua_gettop(L) - 1; + dt_lua_event_trigger(L, event, nargs); return 0; } @@ -141,15 +141,14 @@ int dt_lua_event_keyed_trigger(lua_State *L) lua_getfield(L, 1, luaL_checkstring(L, 3)); if(lua_isnil(L, -1)) { - luaL_error(L, "event %s triggered for unregistered key %s", luaL_checkstring(L, 2), - luaL_checkstring(L, 3)); + luaL_error(L, "event %s triggered for unregistered key %s", luaL_checkstring(L, 2), luaL_checkstring(L, 3)); } const int callback_marker = lua_gettop(L); for(int i = 2; i < callback_marker; i++) { lua_pushvalue(L, i); } - dt_lua_treated_pcall(L,callback_marker-2,0); + dt_lua_treated_pcall(L, callback_marker - 2, 0); return 0; } @@ -190,7 +189,7 @@ int dt_lua_event_multiinstance_trigger(lua_State *L) { lua_pushvalue(L, i); } - dt_lua_treated_pcall(L,arg_top-1,0); + dt_lua_treated_pcall(L, arg_top - 1, 0); } return 0; } @@ -247,11 +246,9 @@ int dt_lua_init_early_events(lua_State *L) static gboolean shortcut_callback(GtkAccelGroup *accel_group, GObject *acceleratable, guint keyval, GdkModifierType modifier, gpointer p) { - dt_lua_async_call_alien(dt_lua_event_trigger_wrapper, - 0, NULL, NULL, - LUA_ASYNC_TYPENAME,"const char*","shortcut", - LUA_ASYNC_TYPENAME_WITH_FREE,"char*",strdup(p),g_cclosure_new(G_CALLBACK(&free),NULL,NULL), - LUA_ASYNC_DONE); + dt_lua_async_call_alien(dt_lua_event_trigger_wrapper, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "const char*", + "shortcut", LUA_ASYNC_TYPENAME_WITH_FREE, "char*", strdup(p), + g_cclosure_new(G_CALLBACK(&free), NULL, NULL), LUA_ASYNC_DONE); return TRUE; } @@ -280,14 +277,14 @@ static int register_shortcut_event(lua_State *L) */ -static void format_destructor(void* arg, dt_imageio_module_format_t *format) +static void format_destructor(void *arg, dt_imageio_module_format_t *format) { - format->free_params(format,arg); + format->free_params(format, arg); } -static void storage_destructor(void* arg, dt_imageio_module_storage_t *storage) +static void storage_destructor(void *arg, dt_imageio_module_storage_t *storage) { - storage->free_params(storage,arg); + storage->free_params(storage, arg); } static void on_export_image_tmpfile(gpointer instance, int imgid, char *filename, @@ -295,30 +292,30 @@ static void on_export_image_tmpfile(gpointer instance, int imgid, char *filename dt_imageio_module_storage_t *storage, dt_imageio_module_data_t *sdata, gpointer user_data) { - if(storage){ + if(storage) + { dt_imageio_module_data_t *format_copy = format->get_params(format); - memcpy(format_copy,fdata,format->params_size(format)); + memcpy(format_copy, fdata, format->params_size(format)); dt_imageio_module_data_t *storage_copy = storage->get_params(storage); - memcpy(storage_copy,sdata,storage->params_size(storage)); - dt_lua_async_call_alien(dt_lua_event_trigger_wrapper, - 0, NULL, NULL, - LUA_ASYNC_TYPENAME,"const char*","intermediate-export-image", - LUA_ASYNC_TYPENAME,"dt_lua_image_t",imgid, - LUA_ASYNC_TYPENAME_WITH_FREE,"char*",strdup(filename),g_cclosure_new(G_CALLBACK(&free),NULL,NULL), - LUA_ASYNC_TYPEID_WITH_FREE,format->parameter_lua_type,format_copy,g_cclosure_new(G_CALLBACK(&format_destructor),format,NULL), - LUA_ASYNC_TYPEID_WITH_FREE,storage->parameter_lua_type,storage_copy,g_cclosure_new(G_CALLBACK(&storage_destructor),storage,NULL), - LUA_ASYNC_DONE); - }else{ + memcpy(storage_copy, sdata, storage->params_size(storage)); + dt_lua_async_call_alien( + dt_lua_event_trigger_wrapper, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "const char*", + "intermediate-export-image", LUA_ASYNC_TYPENAME, "dt_lua_image_t", imgid, LUA_ASYNC_TYPENAME_WITH_FREE, + "char*", strdup(filename), g_cclosure_new(G_CALLBACK(&free), NULL, NULL), LUA_ASYNC_TYPEID_WITH_FREE, + format->parameter_lua_type, format_copy, g_cclosure_new(G_CALLBACK(&format_destructor), format, NULL), + LUA_ASYNC_TYPEID_WITH_FREE, storage->parameter_lua_type, storage_copy, + g_cclosure_new(G_CALLBACK(&storage_destructor), storage, NULL), LUA_ASYNC_DONE); + } + else + { dt_imageio_module_data_t *format_copy = format->get_params(format); - memcpy(format_copy,fdata,format->params_size(format)); - dt_lua_async_call_alien(dt_lua_event_trigger_wrapper, - 0, NULL, NULL, - LUA_ASYNC_TYPENAME,"const char*","intermediate-export-image", - LUA_ASYNC_TYPENAME_WITH_FREE,"char*",strdup(filename),g_cclosure_new(G_CALLBACK(&free),NULL,NULL), - LUA_ASYNC_TYPENAME,"dt_lua_image_t",imgid, - LUA_ASYNC_TYPEID_WITH_FREE,format->parameter_lua_type,format_copy,g_cclosure_new(G_CALLBACK(&format_destructor),format,NULL), - LUA_ASYNC_TYPENAME,"void",NULL, - LUA_ASYNC_DONE); + memcpy(format_copy, fdata, format->params_size(format)); + dt_lua_async_call_alien(dt_lua_event_trigger_wrapper, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "const char*", + "intermediate-export-image", LUA_ASYNC_TYPENAME_WITH_FREE, "char*", strdup(filename), + g_cclosure_new(G_CALLBACK(&free), NULL, NULL), LUA_ASYNC_TYPENAME, "dt_lua_image_t", + imgid, LUA_ASYNC_TYPEID_WITH_FREE, format->parameter_lua_type, format_copy, + g_cclosure_new(G_CALLBACK(&format_destructor), format, NULL), LUA_ASYNC_TYPENAME, + "void", NULL, LUA_ASYNC_DONE); } } @@ -335,12 +332,12 @@ int dt_lua_init_events(lua_State *L) lua_pushcfunction(L, dt_lua_event_multiinstance_register); lua_pushcfunction(L, dt_lua_event_multiinstance_trigger); dt_lua_event_add(L, "intermediate-export-image"); - dt_control_signal_connect(darktable.signals, DT_SIGNAL_IMAGE_EXPORT_TMPFILE, - G_CALLBACK(on_export_image_tmpfile), NULL); + dt_control_signal_connect(darktable.signals, DT_SIGNAL_IMAGE_EXPORT_TMPFILE, G_CALLBACK(on_export_image_tmpfile), + NULL); lua_pushcfunction(L, dt_lua_event_multiinstance_register); lua_pushcfunction(L, dt_lua_event_multiinstance_trigger); - dt_lua_event_add(L,"pre-import"); + dt_lua_event_add(L, "pre-import"); return 0; } // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh diff --git a/src/lua/events.h b/src/lua/events.h index a2a76725eed3..fed17ee21052 100644 --- a/src/lua/events.h +++ b/src/lua/events.h @@ -57,7 +57,7 @@ void dt_lua_event_trigger(lua_State *L, const char *event, int nargs); first parameter is the event name other parameters will be passed to the event handler */ -int dt_lua_event_trigger_wrapper(lua_State *L) ; +int dt_lua_event_trigger_wrapper(lua_State *L); ///////////////////// // HELPERS // diff --git a/src/lua/film.c b/src/lua/film.c index 73c772b5d0fd..ee6eac161b5c 100644 --- a/src/lua/film.c +++ b/src/lua/film.c @@ -234,7 +234,7 @@ int dt_lua_init_film(lua_State *L) lua_pushcclosure(L, dt_lua_type_member_common, 1); dt_lua_type_register_const(L, dt_lua_film_t, "copy_image"); lua_pushcfunction(L, film_tostring); - dt_lua_type_setmetafield(L,dt_lua_film_t,"__tostring"); + dt_lua_type_setmetafield(L, dt_lua_film_t, "__tostring"); /* film table */ dt_lua_push_darktable_lib(L); diff --git a/src/lua/format.c b/src/lua/format.c index 6f2a04cf0860..58fee9bdf18e 100644 --- a/src/lua/format.c +++ b/src/lua/format.c @@ -159,8 +159,8 @@ static int write_image(lua_State *L) dt_lua_unlock(); gboolean high_quality = dt_conf_get_bool("plugins/lighttable/export/high_quality_processing"); // TODO: expose icc overwrites to the user! - gboolean result = dt_imageio_export(imgid, filename, format, fdata, high_quality, upscale, FALSE, DT_COLORSPACE_NONE, - NULL, DT_INTENT_LAST, NULL, NULL, 1, 1); + gboolean result = dt_imageio_export(imgid, filename, format, fdata, high_quality, upscale, FALSE, + DT_COLORSPACE_NONE, NULL, DT_INTENT_LAST, NULL, NULL, 1, 1); dt_lua_lock(); lua_pushboolean(L, result); format->free_params(format, fdata); @@ -171,7 +171,7 @@ void dt_lua_register_format_type(lua_State *L, dt_imageio_module_format_t *modul { dt_lua_type_register_parent_type(L, type_id, luaA_type_find(L, "dt_imageio_module_format_t")); lua_pushlightuserdata(L, module); - dt_lua_type_setmetafield_type(L,type_id,"__associated_object"); + dt_lua_type_setmetafield_type(L, type_id, "__associated_object"); // add to the table lua_pushlightuserdata(L, module); lua_pushcclosure(L, get_format_params, 1); diff --git a/src/lua/format.h b/src/lua/format.h index 408745e75e80..afbde6417f4e 100644 --- a/src/lua/format.h +++ b/src/lua/format.h @@ -28,7 +28,7 @@ struct dt_imageio_module_format_t; /** helper for formats to declare their lua interface */ -#define dt_lua_register_format(L, format, type_name) \ +#define dt_lua_register_format(L, format, type_name) \ dt_lua_register_format_type(L, format, luaA_type_find(#type_name)) void dt_lua_register_format_type(lua_State *L, struct dt_imageio_module_format_t *module, luaA_Type type_id); diff --git a/src/lua/gettext.c b/src/lua/gettext.c index 7e0a5eb61c26..3f171c2ea78b 100644 --- a/src/lua/gettext.c +++ b/src/lua/gettext.c @@ -19,71 +19,71 @@ #include "lua/lua.h" // function used by the lua interpreter to load darktable -static int lua_gettext(lua_State*L) +static int lua_gettext(lua_State *L) { - const char* msgid = luaL_checkstring(L,1); - lua_pushstring(L,gettext(msgid)); + const char *msgid = luaL_checkstring(L, 1); + lua_pushstring(L, gettext(msgid)); return 1; } -static int lua_dgettext(lua_State*L) +static int lua_dgettext(lua_State *L) { - const char* domainname = luaL_checkstring(L,1); - const char* msgid = luaL_checkstring(L,2); - lua_pushstring(L,dgettext(domainname,msgid)); + const char *domainname = luaL_checkstring(L, 1); + const char *msgid = luaL_checkstring(L, 2); + lua_pushstring(L, dgettext(domainname, msgid)); return 1; } -static int lua_ngettext(lua_State*L) +static int lua_ngettext(lua_State *L) { - const char* msgid = luaL_checkstring(L,1); - const char* msgid_plural = luaL_checkstring(L,2); - int n = luaL_checkinteger(L,3); - lua_pushstring(L,ngettext(msgid,msgid_plural,n)); + const char *msgid = luaL_checkstring(L, 1); + const char *msgid_plural = luaL_checkstring(L, 2); + int n = luaL_checkinteger(L, 3); + lua_pushstring(L, ngettext(msgid, msgid_plural, n)); return 1; } -static int lua_dngettext(lua_State*L) +static int lua_dngettext(lua_State *L) { - const char* domainname = luaL_checkstring(L,1); - const char* msgid = luaL_checkstring(L,2); - const char* msgid_plural = luaL_checkstring(L,3); - int n = luaL_checkinteger(L,4); - lua_pushstring(L,dngettext(domainname,msgid,msgid_plural,n)); + const char *domainname = luaL_checkstring(L, 1); + const char *msgid = luaL_checkstring(L, 2); + const char *msgid_plural = luaL_checkstring(L, 3); + int n = luaL_checkinteger(L, 4); + lua_pushstring(L, dngettext(domainname, msgid, msgid_plural, n)); return 1; } -static int lua_bindtextdomain(lua_State*L) +static int lua_bindtextdomain(lua_State *L) { - const char* domainname = luaL_checkstring(L,1); - const char* dirname = luaL_checkstring(L,2); - bindtextdomain(domainname,dirname); + const char *domainname = luaL_checkstring(L, 1); + const char *dirname = luaL_checkstring(L, 2); + bindtextdomain(domainname, dirname); return 0; } int dt_lua_init_gettext(lua_State *L) { - + dt_lua_push_darktable_lib(L); - dt_lua_goto_subtable(L,"gettext"); + dt_lua_goto_subtable(L, "gettext"); - lua_pushcfunction(L,lua_gettext); - lua_setfield(L,-2,"gettext"); - lua_pushcfunction(L,lua_dgettext); - lua_setfield(L,-2,"dgettext"); - //lua_pushcfunction(L,lua_dcgettext); - //lua_setfield(L,-2,"dcgettext"); - lua_pushcfunction(L,lua_ngettext); - lua_setfield(L,-2,"ngettext"); - lua_pushcfunction(L,lua_dngettext); - lua_setfield(L,-2,"dngettext"); - //lua_pushcfunction(L,lua_dcngettext); - //lua_setfield(L,-2,"dcngettext"); - lua_pushcfunction(L,lua_bindtextdomain); - lua_setfield(L,-2,"bindtextdomain"); + lua_pushcfunction(L, lua_gettext); + lua_setfield(L, -2, "gettext"); + lua_pushcfunction(L, lua_dgettext); + lua_setfield(L, -2, "dgettext"); + // lua_pushcfunction(L,lua_dcgettext); + // lua_setfield(L,-2,"dcgettext"); + lua_pushcfunction(L, lua_ngettext); + lua_setfield(L, -2, "ngettext"); + lua_pushcfunction(L, lua_dngettext); + lua_setfield(L, -2, "dngettext"); + // lua_pushcfunction(L,lua_dcngettext); + // lua_setfield(L,-2,"dcngettext"); + lua_pushcfunction(L, lua_bindtextdomain); + lua_setfield(L, -2, "bindtextdomain"); - lua_pop(L,1); + lua_pop(L, 1); return 0; } // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh diff --git a/src/lua/glist.h b/src/lua/glist.h index 596c5f038f69..911f2815e862 100644 --- a/src/lua/glist.h +++ b/src/lua/glist.h @@ -24,11 +24,11 @@ // handle list of data who's elementes are type_name* (!!not type_name casted) -#define dt_lua_push_glist(L, list, type_name) dt_lua_push_glist_type(L, list, luaA_type_find(L,type_name)) +#define dt_lua_push_glist(L, list, type_name) dt_lua_push_glist_type(L, list, luaA_type_find(L, type_name)) void dt_lua_push_glist_type(lua_State *L, GList *list, luaA_Type elt_type); // return a malloced list who's elements are malloced type_name* -#define dt_lua_to_glist(L, type_name, index) dt_lua_to_glist_type(L, luaA_type_find(L,type_name), index) +#define dt_lua_to_glist(L, type_name, index) dt_lua_to_glist_type(L, luaA_type_find(L, type_name), index) GList *dt_lua_to_glist_type(lua_State *L, luaA_Type elt_type, int index); diff --git a/src/lua/gui.c b/src/lua/gui.c index 4bea25174cd4..4c291c08f291 100644 --- a/src/lua/gui.c +++ b/src/lua/gui.c @@ -122,17 +122,15 @@ static int job_canceled(lua_State *L) lua_getuservalue(L, 1); lua_getfield(L, -1, "cancel_callback"); lua_pushvalue(L, -3); - lua_call(L,1,0); + lua_call(L, 1, 0); lua_pop(L, 2); return 0; } static void lua_job_cancelled(dt_progress_t *progress, gpointer user_data) { - dt_lua_async_call_alien(job_canceled, - 0, NULL,NULL, - LUA_ASYNC_TYPENAME,"dt_lua_backgroundjob_t",progress, - LUA_ASYNC_DONE); + dt_lua_async_call_alien(job_canceled, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "dt_lua_backgroundjob_t", progress, + LUA_ASYNC_DONE); } static int lua_create_job(lua_State *L) @@ -216,17 +214,16 @@ static int lua_job_valid(lua_State *L) static void on_mouse_over_image_changed(gpointer instance, gpointer user_data) { int imgid = dt_control_get_mouse_over_id(); - if(imgid != -1) { - dt_lua_async_call_alien(dt_lua_event_trigger_wrapper, - 0, NULL,NULL, - LUA_ASYNC_TYPENAME,"char*","mouse-over-image-changed", - LUA_ASYNC_TYPENAME,"dt_lua_image_t",imgid, - LUA_ASYNC_DONE); - } else { - dt_lua_async_call_alien(dt_lua_event_trigger_wrapper, - 0, NULL,NULL, - LUA_ASYNC_TYPENAME,"char*","mouse-over-image-changed", - LUA_ASYNC_DONE); + if(imgid != -1) + { + dt_lua_async_call_alien(dt_lua_event_trigger_wrapper, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "char*", + "mouse-over-image-changed", LUA_ASYNC_TYPENAME, "dt_lua_image_t", imgid, + LUA_ASYNC_DONE); + } + else + { + dt_lua_async_call_alien(dt_lua_event_trigger_wrapper, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "char*", + "mouse-over-image-changed", LUA_ASYNC_DONE); } } @@ -276,7 +273,8 @@ int dt_lua_init_gui(lua_State *L) lua_pushcfunction(L, dt_lua_event_multiinstance_register); lua_pushcfunction(L, dt_lua_event_multiinstance_trigger); dt_lua_event_add(L, "mouse-over-image-changed"); - dt_control_signal_connect(darktable.signals, DT_SIGNAL_MOUSE_OVER_IMAGE_CHANGE, G_CALLBACK(on_mouse_over_image_changed), NULL); + dt_control_signal_connect(darktable.signals, DT_SIGNAL_MOUSE_OVER_IMAGE_CHANGE, + G_CALLBACK(on_mouse_over_image_changed), NULL); } return 0; } diff --git a/src/lua/guides.c b/src/lua/guides.c index 3fc0a52f2001..057f6df4652c 100644 --- a/src/lua/guides.c +++ b/src/lua/guides.c @@ -28,8 +28,7 @@ typedef struct callback_data_t int gui_callback_id; } callback_data_t; -static void _guides_draw_callback(cairo_t *cr, const float x, const float y, - const float w, const float h, +static void _guides_draw_callback(cairo_t *cr, const float x, const float y, const float w, const float h, const float zoom_scale, void *user_data) { callback_data_t *d = (callback_data_t *)user_data; @@ -47,9 +46,9 @@ static void _guides_draw_callback(cairo_t *cr, const float x, const float y, lua_pushnumber(L, zoom_scale); // this will be called directly from the gui thread so we can just execute it, without caring about the gtk lock - dt_lua_treated_pcall(L,6,0); + dt_lua_treated_pcall(L, 6, 0); - dt_lua_type_gpointer_drop(L,cr); + dt_lua_type_gpointer_drop(L, cr); dt_lua_unlock(); } @@ -60,13 +59,13 @@ static GtkWidget *_guides_gui_callback(dt_iop_module_t *self, void *user_data) dt_lua_lock_silent(); // this code is called from the C side so we have to lock lua_State *L = darktable.lua_state.state; lua_rawgeti(L, LUA_REGISTRYINDEX, d->gui_callback_id); - dt_lua_treated_pcall(L,0,1); + dt_lua_treated_pcall(L, 0, 1); -// dt_lua_debug_stack(L); + // dt_lua_debug_stack(L); lua_widget widget; luaA_to(L, lua_widget, &widget, -1); dt_lua_widget_bind(L, widget); - lua_pop(L,1); + lua_pop(L, 1); dt_lua_unlock(); @@ -91,8 +90,7 @@ static int register_guide(lua_State *L) else lua_pop(L, 1); // get rid of the nil - if(lua_isnil(L, 2)) - return luaL_error(L, "missing draw callback"); + if(lua_isnil(L, 2)) return luaL_error(L, "missing draw callback"); luaL_checktype(L, 2, LUA_TFUNCTION); draw_callback_id = luaL_ref(L, LUA_REGISTRYINDEX); diff --git a/src/lua/image.c b/src/lua/image.c index 91995e47b280..15f83e801a5a 100644 --- a/src/lua/image.c +++ b/src/lua/image.c @@ -515,7 +515,7 @@ int dt_lua_init_image(lua_State *L) luaA_struct_member(L, dt_image_t, width, const int32_t); luaA_struct_member(L, dt_image_t, height, const int32_t); luaA_struct_member(L, dt_image_t, longitude, protected_double); // set to NAN if value is not set - luaA_struct_member(L, dt_image_t, latitude, protected_double); // set to NAN if value is not set + luaA_struct_member(L, dt_image_t, latitude, protected_double); // set to NAN if value is not set luaA_struct_member(L, dt_image_t, elevation, protected_double); // set to NAN if value is not set dt_lua_init_int_type(L, dt_lua_image_t); @@ -624,7 +624,7 @@ int dt_lua_init_image(lua_State *L) lua_pushcclosure(L, dt_lua_type_member_common, 1); dt_lua_type_register_const(L, dt_lua_image_t, "drop_cache"); lua_pushcfunction(L, image_tostring); - dt_lua_type_setmetafield(L,dt_lua_image_t,"__tostring"); + dt_lua_type_setmetafield(L, dt_lua_image_t, "__tostring"); return 0; } diff --git a/src/lua/init.c b/src/lua/init.c index 5b760a77abc2..b6faff702d22 100644 --- a/src/lua/init.c +++ b/src/lua/init.c @@ -45,11 +45,11 @@ #include "lua/view.h" #include "lua/widget/widget.h" -static int dt_lua_init_init(lua_State*L) +static int dt_lua_init_init(lua_State *L) { lua_pushcfunction(L, dt_lua_event_multiinstance_register); lua_pushcfunction(L, dt_lua_event_multiinstance_trigger); - dt_lua_event_add(L,"exit"); + dt_lua_event_add(L, "exit"); return 0; } // closed on GC of the dt lib, usually when the lua interpreter closes @@ -63,9 +63,8 @@ static int dt_luacleanup(lua_State *L) static lua_CFunction early_init_funcs[] - = { dt_lua_init_early_types, dt_lua_init_early_events, dt_lua_init_early_modules, - dt_lua_init_early_format, dt_lua_init_early_storage, dt_lua_init_early_lib, - dt_lua_init_early_view, NULL }; + = { dt_lua_init_early_types, dt_lua_init_early_events, dt_lua_init_early_modules, dt_lua_init_early_format, + dt_lua_init_early_storage, dt_lua_init_early_lib, dt_lua_init_early_view, NULL }; static int dt_call_after_load(lua_State *L) { @@ -80,9 +79,12 @@ void dt_lua_init_early(lua_State *L) } darktable.lua_state.state = L; darktable.lua_state.ending = false; - darktable.lua_state.loop = NULL;; - darktable.lua_state.context = NULL;; - darktable.lua_state.stacked_job_queue = NULL;; + darktable.lua_state.loop = NULL; + ; + darktable.lua_state.context = NULL; + ; + darktable.lua_state.stacked_job_queue = NULL; + ; dt_lua_init_lock(); // lock is initialized in the locked state luaL_openlibs(darktable.lua_state.state); luaA_open(L); @@ -105,7 +107,7 @@ void dt_lua_init_early(lua_State *L) } } -static int run_early_script(lua_State* L) +static int run_early_script(lua_State *L) { char basedir[PATH_MAX] = { 0 }; // run global init script @@ -121,9 +123,10 @@ static int run_early_script(lua_State* L) dt_lua_check_print_error(L, luaL_dofile(L, luarc)); g_free(luarc); } - if(!lua_isnil(L,1)){ + if(!lua_isnil(L, 1)) + { const char *lua_command = lua_tostring(L, 1); - dt_lua_check_print_error(L,luaL_dostring(L,lua_command)); + dt_lua_check_print_error(L, luaL_dostring(L, lua_command)); } dt_lua_redraw_screen(); return 0; @@ -177,10 +180,10 @@ void dt_lua_init(lua_State *L, const char *lua_command) - lua_pushcfunction(L,run_early_script); - lua_pushstring(L,lua_command); + lua_pushcfunction(L, run_early_script); + lua_pushstring(L, lua_command); - dt_lua_async_call(L,1,0,NULL,NULL); + dt_lua_async_call(L, 1, 0, NULL, NULL); // allow other threads to wake up and do their job dt_lua_unlock(); } @@ -216,8 +219,9 @@ static int load_from_lua(lua_State *L) argv[argc] = NULL; argv_copy[argc] = NULL; gtk_init(&argc, &argv); - if(dt_init(argc, argv, FALSE, TRUE, L)) { - luaL_error(L,"Starting darktable failed."); + if(dt_init(argc, argv, FALSE, TRUE, L)) + { + luaL_error(L, "Starting darktable failed."); } for(int i = 0; i < argc; i++) { @@ -242,7 +246,7 @@ void dt_lua_finalize_early() { darktable.lua_state.ending = true; dt_lua_lock(); - dt_lua_event_trigger(darktable.lua_state.state,"exit",0); + dt_lua_event_trigger(darktable.lua_state.state, "exit", 0); dt_lua_unlock(); g_main_context_wakeup(darktable.lua_state.context); } diff --git a/src/lua/lib.c b/src/lua/lib.c index c72ad6332887..012d4d89c5b4 100644 --- a/src/lua/lib.c +++ b/src/lua/lib.c @@ -86,31 +86,34 @@ static int on_screen_member(lua_State *L) return 1; } -static int position_member(lua_State*L) { - dt_lib_module_t * module = *(dt_lib_module_t**)lua_touserdata(L,1); - lua_pushinteger(L,module->position(module)); +static int position_member(lua_State *L) +{ + dt_lib_module_t *module = *(dt_lib_module_t **)lua_touserdata(L, 1); + lua_pushinteger(L, module->position(module)); return 1; } -static int container_member(lua_State*L) { - dt_lib_module_t * module = *(dt_lib_module_t**)lua_touserdata(L,1); +static int container_member(lua_State *L) +{ + dt_lib_module_t *module = *(dt_lib_module_t **)lua_touserdata(L, 1); dt_ui_container_t container; container = module->container(module); - luaA_push(L,dt_ui_container_t,&container); + luaA_push(L, dt_ui_container_t, &container); return 1; } -static int views_member(lua_State*L) { - dt_lib_module_t * module = *(dt_lib_module_t**)lua_touserdata(L,1); +static int views_member(lua_State *L) +{ + dt_lib_module_t *module = *(dt_lib_module_t **)lua_touserdata(L, 1); lua_newtable(L); for(GList *iter = darktable.view_manager->views; iter; iter = g_list_next(iter)) { const dt_view_t *view = (const dt_view_t *)iter->data; if(dt_lib_is_visible_in_view(module, view)) { - dt_lua_module_entry_push(L,"view",(view->module_name)); - luaL_ref(L,-2); + dt_lua_module_entry_push(L, "view", (view->module_name)); + luaL_ref(L, -2); } } return 1; @@ -139,29 +142,29 @@ void dt_lua_lib_register(lua_State *L, dt_lib_module_t *module) int my_type = dt_lua_module_entry_get_type(L, "lib", module->plugin_name); dt_lua_type_register_parent_type(L, my_type, luaA_type_find(L, "dt_lua_lib_t")); lua_pushcfunction(L, lib_tostring); - dt_lua_type_setmetafield_type(L,my_type,"__tostring"); + dt_lua_type_setmetafield_type(L, my_type, "__tostring"); }; int dt_lua_init_early_lib(lua_State *L) { - luaA_enum(L,dt_ui_container_t); - luaA_enum_value(L,dt_ui_container_t,DT_UI_CONTAINER_PANEL_LEFT_TOP); - luaA_enum_value(L,dt_ui_container_t,DT_UI_CONTAINER_PANEL_LEFT_CENTER); - luaA_enum_value(L,dt_ui_container_t,DT_UI_CONTAINER_PANEL_LEFT_BOTTOM); - luaA_enum_value(L,dt_ui_container_t,DT_UI_CONTAINER_PANEL_RIGHT_TOP); - luaA_enum_value(L,dt_ui_container_t,DT_UI_CONTAINER_PANEL_RIGHT_CENTER); - luaA_enum_value(L,dt_ui_container_t,DT_UI_CONTAINER_PANEL_RIGHT_BOTTOM); - luaA_enum_value(L,dt_ui_container_t,DT_UI_CONTAINER_PANEL_TOP_LEFT); - luaA_enum_value(L,dt_ui_container_t,DT_UI_CONTAINER_PANEL_TOP_CENTER); - luaA_enum_value(L,dt_ui_container_t,DT_UI_CONTAINER_PANEL_TOP_RIGHT); - luaA_enum_value(L,dt_ui_container_t,DT_UI_CONTAINER_PANEL_CENTER_TOP_LEFT); - luaA_enum_value(L,dt_ui_container_t,DT_UI_CONTAINER_PANEL_CENTER_TOP_CENTER); - luaA_enum_value(L,dt_ui_container_t,DT_UI_CONTAINER_PANEL_CENTER_TOP_RIGHT); - luaA_enum_value(L,dt_ui_container_t,DT_UI_CONTAINER_PANEL_CENTER_BOTTOM_LEFT); - luaA_enum_value(L,dt_ui_container_t,DT_UI_CONTAINER_PANEL_CENTER_BOTTOM_CENTER); - luaA_enum_value(L,dt_ui_container_t,DT_UI_CONTAINER_PANEL_CENTER_BOTTOM_RIGHT); - luaA_enum_value(L,dt_ui_container_t,DT_UI_CONTAINER_PANEL_BOTTOM); + luaA_enum(L, dt_ui_container_t); + luaA_enum_value(L, dt_ui_container_t, DT_UI_CONTAINER_PANEL_LEFT_TOP); + luaA_enum_value(L, dt_ui_container_t, DT_UI_CONTAINER_PANEL_LEFT_CENTER); + luaA_enum_value(L, dt_ui_container_t, DT_UI_CONTAINER_PANEL_LEFT_BOTTOM); + luaA_enum_value(L, dt_ui_container_t, DT_UI_CONTAINER_PANEL_RIGHT_TOP); + luaA_enum_value(L, dt_ui_container_t, DT_UI_CONTAINER_PANEL_RIGHT_CENTER); + luaA_enum_value(L, dt_ui_container_t, DT_UI_CONTAINER_PANEL_RIGHT_BOTTOM); + luaA_enum_value(L, dt_ui_container_t, DT_UI_CONTAINER_PANEL_TOP_LEFT); + luaA_enum_value(L, dt_ui_container_t, DT_UI_CONTAINER_PANEL_TOP_CENTER); + luaA_enum_value(L, dt_ui_container_t, DT_UI_CONTAINER_PANEL_TOP_RIGHT); + luaA_enum_value(L, dt_ui_container_t, DT_UI_CONTAINER_PANEL_CENTER_TOP_LEFT); + luaA_enum_value(L, dt_ui_container_t, DT_UI_CONTAINER_PANEL_CENTER_TOP_CENTER); + luaA_enum_value(L, dt_ui_container_t, DT_UI_CONTAINER_PANEL_CENTER_TOP_RIGHT); + luaA_enum_value(L, dt_ui_container_t, DT_UI_CONTAINER_PANEL_CENTER_BOTTOM_LEFT); + luaA_enum_value(L, dt_ui_container_t, DT_UI_CONTAINER_PANEL_CENTER_BOTTOM_CENTER); + luaA_enum_value(L, dt_ui_container_t, DT_UI_CONTAINER_PANEL_CENTER_BOTTOM_RIGHT); + luaA_enum_value(L, dt_ui_container_t, DT_UI_CONTAINER_PANEL_BOTTOM); dt_lua_init_type(L, dt_lua_lib_t); lua_pushcfunction(L, lib_reset); @@ -178,12 +181,12 @@ int dt_lua_init_early_lib(lua_State *L) lua_pushcfunction(L, expanded_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, dt_lua_lib_t, "expanded"); - lua_pushcfunction(L,position_member); - dt_lua_type_register_const(L,dt_lua_lib_t,"position"); - lua_pushcfunction(L,container_member); - dt_lua_type_register_const(L,dt_lua_lib_t,"container"); - lua_pushcfunction(L,views_member); - dt_lua_type_register_const(L,dt_lua_lib_t,"views"); + lua_pushcfunction(L, position_member); + dt_lua_type_register_const(L, dt_lua_lib_t, "position"); + lua_pushcfunction(L, container_member); + dt_lua_type_register_const(L, dt_lua_lib_t, "container"); + lua_pushcfunction(L, views_member); + dt_lua_type_register_const(L, dt_lua_lib_t, "views"); lua_pushcfunction(L, visible_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, dt_lua_lib_t, "visible"); diff --git a/src/lua/lib.h b/src/lua/lib.h index 6c9b45ff2d72..53621745b391 100644 --- a/src/lua/lib.h +++ b/src/lua/lib.h @@ -23,7 +23,7 @@ struct dt_lib_module_t; -typedef struct dt_lib_module_t* dt_lua_lib_t; +typedef struct dt_lib_module_t *dt_lua_lib_t; void dt_lua_lib_register(lua_State *L, struct dt_lib_module_t *self); diff --git a/src/lua/lua.c b/src/lua/lua.c index f22792042b51..b33059d405e7 100644 --- a/src/lua/lua.c +++ b/src/lua/lua.c @@ -30,7 +30,7 @@ void dt_lua_debug_stack_internal(lua_State *L, const char *function, int line) } else { - printf("(size %d),\n",lua_gettop(L)); //usefull to detect underflows + printf("(size %d),\n", lua_gettop(L)); // usefull to detect underflows } for(int i = 1; i <= lua_gettop(L); i++) { @@ -38,31 +38,34 @@ void dt_lua_debug_stack_internal(lua_State *L, const char *function, int line) printf("\t%d:%s %s\n", i, lua_typename(L, lua_type(L, i)), luaL_tolstring(L, i, NULL)); lua_pop(L, 1); // remove the result of luaL_tolstring() from the stack #else - // no tolstring when stack is really screwed up - printf("\t%d:%s %p\n", i, lua_typename(L, lua_type(L, i)),lua_topointer(L,i)); + // no tolstring when stack is really screwed up + printf("\t%d:%s %p\n", i, lua_typename(L, lua_type(L, i)), lua_topointer(L, i)); #endif } } void dt_lua_debug_table_internal(lua_State *L, int t, const char *function, int line) { - t = lua_absindex(L,t); + t = lua_absindex(L, t); /* table is in the stack at index 't' */ - lua_len(L,t); - printf("lua table at index %d at %s:%d (length %f)\n", t, function, line,lua_tonumber(L,-1)); - lua_pop(L,1); + lua_len(L, t); + printf("lua table at index %d at %s:%d (length %f)\n", t, function, line, lua_tonumber(L, -1)); + lua_pop(L, 1); if(lua_type(L, t) != LUA_TTABLE) { printf("\tnot a table: %s\n", lua_typename(L, lua_type(L, t))); return; } lua_pushnil(L); /* first key */ - while(lua_next(L, t ) != 0) + while(lua_next(L, t) != 0) { /* uses 'key' (at index -2) and 'value' (at index -1) */ - if(lua_type(L,-2) != LUA_TNUMBER) { + if(lua_type(L, -2) != LUA_TNUMBER) + { printf("%s - %s\n", lua_tostring(L, -2), lua_typename(L, lua_type(L, -1))); - } else { + } + else + { printf("%f - %s\n", luaL_checknumber(L, -2), lua_typename(L, lua_type(L, -1))); } @@ -111,7 +114,7 @@ void dt_lua_goto_subtable(lua_State *L, const char *sub_name) that the lua code from the first thread is followed from the lua code in the second thread with no other lua thread having a chance to run in the middle - pthread_mutex (and glib mutexes) have undefined behaviour if unlocked from + pthread_mutex (and glib mutexes) have undefined behaviour if unlocked from a different thread. So we replace the simple mutex with a boolean protected by a pthread_cond, protected by a pthread_mutex */ @@ -120,10 +123,10 @@ void dt_lua_init_lock() { pthread_mutexattr_t a; pthread_mutexattr_init(&a); - //pthread_mutexattr_settype(&a, PTHREAD_MUTEX_RECURSIVE); + // pthread_mutexattr_settype(&a, PTHREAD_MUTEX_RECURSIVE); dt_pthread_mutex_init(&darktable.lua_state.mutex, &a); pthread_mutexattr_destroy(&a); - pthread_cond_init(&darktable.lua_state.cond,NULL); + pthread_cond_init(&darktable.lua_state.cond, NULL); // we want our lock initialized locked so that code between dt_lua_init_early() and dt_lua_init() can't use lua dt_pthread_mutex_lock(&darktable.lua_state.mutex); darktable.lua_state.exec_lock = true; @@ -135,26 +138,27 @@ void dt_lua_lock_internal(const char *function, const char *file, int line, gboo if(!silent && !darktable.lua_state.ending && pthread_equal(darktable.control->gui_thread, pthread_self()) != 0) { dt_print(DT_DEBUG_LUA, "LUA WARNING locking from the gui thread should be avoided\n"); - //g_assert(false); + // g_assert(false); } #ifdef _DEBUG - dt_print(DT_DEBUG_LUA,"LUA DEBUG : thread %p waiting from %s:%d\n", g_thread_self(), function, line); + dt_print(DT_DEBUG_LUA, "LUA DEBUG : thread %p waiting from %s:%d\n", g_thread_self(), function, line); #endif dt_pthread_mutex_lock(&darktable.lua_state.mutex); - while(darktable.lua_state.exec_lock == true) { - dt_pthread_cond_wait(&darktable.lua_state.cond,&darktable.lua_state.mutex); + while(darktable.lua_state.exec_lock == true) + { + dt_pthread_cond_wait(&darktable.lua_state.cond, &darktable.lua_state.mutex); } darktable.lua_state.exec_lock = true; dt_pthread_mutex_unlock(&darktable.lua_state.mutex); #ifdef _DEBUG - dt_print(DT_DEBUG_LUA,"LUA DEBUG : thread %p taken from %s:%d\n", g_thread_self(), function, line); + dt_print(DT_DEBUG_LUA, "LUA DEBUG : thread %p taken from %s:%d\n", g_thread_self(), function, line); #endif } void dt_lua_unlock_internal(const char *function, int line) { #ifdef _DEBUG - dt_print(DT_DEBUG_LUA,"LUA DEBUG : thread %p released from %s:%d\n",g_thread_self(), function,line); + dt_print(DT_DEBUG_LUA, "LUA DEBUG : thread %p released from %s:%d\n", g_thread_self(), function, line); #endif dt_pthread_mutex_lock(&darktable.lua_state.mutex); darktable.lua_state.exec_lock = false; @@ -172,7 +176,7 @@ void dt_lua_redraw_screen() { if(darktable.gui != NULL) { - g_idle_add(async_redraw,NULL); + g_idle_add(async_redraw, NULL); } } diff --git a/src/lua/lua.h b/src/lua/lua.h index 62f1d6c2e528..f0f76a98911f 100644 --- a/src/lua/lua.h +++ b/src/lua/lua.h @@ -61,24 +61,25 @@ void dt_lua_debug_table_internal(lua_State *L, int t, const char *function, int #define dt_lua_lock() dt_lua_lock_internal(__FUNCTION__, __FILE__, __LINE__, FALSE) #define dt_lua_lock_silent() dt_lua_lock_internal(__FUNCTION__, __FILE__, __LINE__, TRUE) -#define dt_lua_unlock() dt_lua_unlock_internal( __FUNCTION__, __LINE__) +#define dt_lua_unlock() dt_lua_unlock_internal(__FUNCTION__, __LINE__) typedef struct { - lua_State *state; // main lua context + lua_State *state; // main lua context - dt_pthread_mutex_t mutex; // mutex protecting the lua condition variabe - pthread_cond_t cond; // condition variable to wait for the lua lock - bool exec_lock; // true if some lua code is running. this is logically a mutex + dt_pthread_mutex_t mutex; // mutex protecting the lua condition variabe + pthread_cond_t cond; // condition variable to wait for the lua lock + bool exec_lock; // true if some lua code is running. this is logically a mutex - bool ending; // true if we are in the process of terminating DT + bool ending; // true if we are in the process of terminating DT - GMainLoop *loop; // loop running the lua context - GMainContext *context; // the lua context responsible for dispatching tasks - GThreadPool *pool; // pool of threads to run lua tasks on (should be one or two at most, unless lot of blocking lua threads - GAsyncQueue * stacked_job_queue; // queue of jobs whose arguments are on a lua stack - GAsyncQueue * alien_job_queue; // queue of jobs coming from C, args are passed in a glist - GAsyncQueue * string_job_queue; // queue of jobs as lua expressions, passed with args as a string + GMainLoop *loop; // loop running the lua context + GMainContext *context; // the lua context responsible for dispatching tasks + GThreadPool *pool; // pool of threads to run lua tasks on (should be one or two at most, unless lot of blocking + // lua threads + GAsyncQueue *stacked_job_queue; // queue of jobs whose arguments are on a lua stack + GAsyncQueue *alien_job_queue; // queue of jobs coming from C, args are passed in a glist + GAsyncQueue *string_job_queue; // queue of jobs as lua expressions, passed with args as a string } dt_lua_state_t; diff --git a/src/lua/lualib.c b/src/lua/lualib.c index d3204efa7306..e91222951c60 100644 --- a/src/lua/lualib.c +++ b/src/lua/lualib.c @@ -56,23 +56,20 @@ static const char *name_wrapper(struct dt_lib_module_t *self) static void gui_init_wrapper(struct dt_lib_module_t *self) { - lua_lib_data_t *gui_data =self->data; + lua_lib_data_t *gui_data = self->data; self->widget = gui_data->widget->widget; } static void gui_reset_wrapper(struct dt_lib_module_t *self) { - lua_lib_data_t *gui_data =self->data; - dt_lua_async_call_alien(dt_lua_widget_trigger_callback, - 0, NULL,NULL, - LUA_ASYNC_TYPENAME,"lua_widget",gui_data->widget, - LUA_ASYNC_TYPENAME,"const char*","reset", - LUA_ASYNC_DONE); + lua_lib_data_t *gui_data = self->data; + dt_lua_async_call_alien(dt_lua_widget_trigger_callback, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "lua_widget", + gui_data->widget, LUA_ASYNC_TYPENAME, "const char*", "reset", LUA_ASYNC_DONE); } static void gui_cleanup_wrapper(struct dt_lib_module_t *self) { - lua_lib_data_t *gui_data =self->data; + lua_lib_data_t *gui_data = self->data; free(gui_data->name); free(gui_data->views); g_list_free(gui_data->position_descriptions); @@ -121,52 +118,45 @@ int position_wrapper(const struct dt_lib_module_t *self) return 0; } -static int async_lib_call(lua_State * L) +static int async_lib_call(lua_State *L) { - //lua_getfield(L, LUA_REGISTRYINDEX, "dt_lua_libs"); - const char* event = lua_tostring(L,1); - dt_lib_module_t * module = *(dt_lib_module_t**)lua_touserdata(L,2); - dt_lua_module_entry_push(L,"lib",module->plugin_name); - lua_getuservalue(L,-1); - lua_getfield(L,-1,event); - if(lua_isnoneornil(L,-1)) { - lua_pop(L,7); + // lua_getfield(L, LUA_REGISTRYINDEX, "dt_lua_libs"); + const char *event = lua_tostring(L, 1); + dt_lib_module_t *module = *(dt_lib_module_t **)lua_touserdata(L, 2); + dt_lua_module_entry_push(L, "lib", module->plugin_name); + lua_getuservalue(L, -1); + lua_getfield(L, -1, event); + if(lua_isnoneornil(L, -1)) + { + lua_pop(L, 7); return 0; } - lua_pushvalue(L,2); - lua_pushvalue(L,3); - lua_pushvalue(L,4); - lua_call(L,3,0); - lua_pop(L,6); + lua_pushvalue(L, 2); + lua_pushvalue(L, 3); + lua_pushvalue(L, 4); + lua_call(L, 3, 0); + lua_pop(L, 6); return 0; } -static void view_enter_wrapper(struct dt_lib_module_t *self,struct dt_view_t *old_view,struct dt_view_t *new_view) +static void view_enter_wrapper(struct dt_lib_module_t *self, struct dt_view_t *old_view, struct dt_view_t *new_view) { - dt_lua_async_call_alien(async_lib_call, - 0, NULL,NULL, - LUA_ASYNC_TYPENAME,"const char*","view_enter", - LUA_ASYNC_TYPENAME,"dt_lua_lib_t",self, - LUA_ASYNC_TYPENAME,"dt_lua_view_t",old_view, - LUA_ASYNC_TYPENAME,"dt_lua_view_t",new_view, - LUA_ASYNC_DONE); + dt_lua_async_call_alien(async_lib_call, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "const char*", "view_enter", + LUA_ASYNC_TYPENAME, "dt_lua_lib_t", self, LUA_ASYNC_TYPENAME, "dt_lua_view_t", old_view, + LUA_ASYNC_TYPENAME, "dt_lua_view_t", new_view, LUA_ASYNC_DONE); } -static void view_leave_wrapper(struct dt_lib_module_t *self,struct dt_view_t *old_view,struct dt_view_t *new_view) +static void view_leave_wrapper(struct dt_lib_module_t *self, struct dt_view_t *old_view, struct dt_view_t *new_view) { - dt_lua_async_call_alien(async_lib_call, - 0, NULL,NULL, - LUA_ASYNC_TYPENAME,"const char*","view_leave", - LUA_ASYNC_TYPENAME,"dt_lua_lib_t",self, - LUA_ASYNC_TYPENAME,"dt_lua_view_t",old_view, - LUA_ASYNC_TYPENAME,"dt_lua_view_t",new_view, - LUA_ASYNC_DONE); + dt_lua_async_call_alien(async_lib_call, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "const char*", "view_leave", + LUA_ASYNC_TYPENAME, "dt_lua_lib_t", self, LUA_ASYNC_TYPENAME, "dt_lua_view_t", old_view, + LUA_ASYNC_TYPENAME, "dt_lua_view_t", new_view, LUA_ASYNC_DONE); } static dt_lib_module_t ref_lib = { .module = NULL, .dt = &darktable, .data = NULL, - .plugin_name ={ 0 }, + .plugin_name = { 0 }, .widget = NULL, .expander = NULL, .version = version_wrapper, @@ -210,8 +200,8 @@ static int register_lib(lua_State *L) g_strlcpy(lib->plugin_name, plugin_name, sizeof(lib->plugin_name)); dt_lua_lib_register(L, lib); /* push the object on the stack to have its metadata */ - dt_lua_module_entry_push(L,"lib",lib->plugin_name); - lua_getuservalue(L,-1); + dt_lua_module_entry_push(L, "lib", lib->plugin_name); + lua_getuservalue(L, -1); lua_pushvalue(L, 1); lua_setfield(L, -2, "plugin_name"); const char *name = luaL_checkstring(L, 2); @@ -220,11 +210,12 @@ static int register_lib(lua_State *L) data->name = strdup(name); data->widget = NULL; - luaL_checktype(L,3,LUA_TBOOLEAN); - data->expandable = lua_toboolean(L,3); + luaL_checktype(L, 3, LUA_TBOOLEAN); + data->expandable = lua_toboolean(L, 3); - luaL_checktype(L,4,LUA_TBOOLEAN); - if(!lua_toboolean(L,4)) { + luaL_checktype(L, 4, LUA_TBOOLEAN); + if(!lua_toboolean(L, 4)) + { lib->gui_reset = NULL; } @@ -242,18 +233,18 @@ static int register_lib(lua_State *L) position_description->view = tmp_view->module_name; // get the container - lua_pushinteger(L,1); - lua_gettable(L,-2); + lua_pushinteger(L, 1); + lua_gettable(L, -2); dt_ui_container_t container; - luaA_to(L,dt_ui_container_t,&container,-1); - lua_pop(L,1); + luaA_to(L, dt_ui_container_t, &container, -1); + lua_pop(L, 1); position_description->container = container; // get the position - lua_pushinteger(L,2); - lua_gettable(L,-2); - position_description->position = luaL_checkinteger(L,-1); - lua_pop(L,1); + lua_pushinteger(L, 2); + lua_gettable(L, -2); + position_description->position = luaL_checkinteger(L, -1); + lua_pop(L, 1); lua_pop(L, 1); } @@ -266,30 +257,34 @@ static int register_lib(lua_State *L) } lua_widget widget; - luaA_to(L,lua_widget,&widget,6); - dt_lua_widget_bind(L,widget); + luaA_to(L, lua_widget, &widget, 6); + dt_lua_widget_bind(L, widget); data->widget = widget; - if(lua_isfunction(L,7)) { + if(lua_isfunction(L, 7)) + { lua_pushvalue(L, 7); lua_setfield(L, -2, "view_enter"); - } else { + } + else + { lib->view_enter = NULL; } - if(lua_isfunction(L,8)) { + if(lua_isfunction(L, 8)) + { lua_pushvalue(L, 8); lua_setfield(L, -2, "view_leave"); - } else { + } + else + { lib->view_leave = NULL; } - lua_pop(L,2); - + lua_pop(L, 2); - if(lib->gui_reset) { dt_accel_register_lib(lib, NC_("accel", "reset lib parameters"), 0, 0); diff --git a/src/lua/luastorage.c b/src/lua/luastorage.c index 2325b10861ba..60a1c6ed5f80 100644 --- a/src/lua/luastorage.c +++ b/src/lua/luastorage.c @@ -40,7 +40,7 @@ typedef struct lua_widget widget; } lua_storage_gui_t; -static void push_lua_data(lua_State*L,lua_storage_t *d) +static void push_lua_data(lua_State *L, lua_storage_t *d) { if(!d->data_created) { @@ -110,13 +110,12 @@ static int store_wrapper(struct dt_imageio_module_storage_t *self, struct dt_ima dt_lua_lock(); lua_State *L = darktable.lua_state.state; - push_lua_data(L,d); - dt_lua_goto_subtable(L,"files"); + push_lua_data(L, d); + dt_lua_goto_subtable(L, "files"); luaA_push(L, dt_lua_image_t, &(imgid)); lua_pushstring(L, complete_name); lua_settable(L, -3); - lua_pop(L,1); - + lua_pop(L, 1); @@ -139,9 +138,9 @@ static int store_wrapper(struct dt_imageio_module_storage_t *self, struct dt_ima lua_pushinteger(L, num); lua_pushinteger(L, total); lua_pushboolean(L, high_quality); - push_lua_data(L,d); - dt_lua_goto_subtable(L,"extra"); - dt_lua_treated_pcall(L,8,0); + push_lua_data(L, d); + dt_lua_goto_subtable(L, "extra"); + dt_lua_treated_pcall(L, 8, 0); lua_pop(L, 2); dt_lua_unlock(); g_free(filename); @@ -181,14 +180,14 @@ static int initialize_store_wrapper(struct dt_imageio_module_storage_t *self, dt lua_pushboolean(L, high_quality); lua_storage_t *d = (lua_storage_t *)data; - push_lua_data(L,d); - dt_lua_goto_subtable(L,"extra"); + push_lua_data(L, d); + dt_lua_goto_subtable(L, "extra"); - dt_lua_treated_pcall(L,5,1); + dt_lua_treated_pcall(L, 5, 1); if(!lua_isnoneornil(L, -1)) { g_list_free(*images); - if(lua_type(L,-1) != LUA_TTABLE) + if(lua_type(L, -1) != LUA_TTABLE) { dt_print(DT_DEBUG_LUA, "LUA ERROR initialization function of storage did not return nil or table\n"); dt_lua_unlock(); @@ -229,13 +228,13 @@ static void finalize_store_wrapper(struct dt_imageio_module_storage_t *self, dt_ luaA_push_type(L, self->parameter_lua_type, data); lua_storage_t *d = (lua_storage_t *)data; - push_lua_data(L,d); - dt_lua_goto_subtable(L,"files"); + push_lua_data(L, d); + dt_lua_goto_subtable(L, "files"); - push_lua_data(L,d); - dt_lua_goto_subtable(L,"extra"); + push_lua_data(L, d); + dt_lua_goto_subtable(L, "extra"); - dt_lua_treated_pcall(L,3,0); + dt_lua_treated_pcall(L, 3, 0); lua_pop(L, 2); dt_lua_unlock(); } @@ -255,7 +254,7 @@ typedef struct lua_storage_t *data; } free_param_wrapper_data; -static void free_param_wrapper_destroy(void * data) +static void free_param_wrapper_destroy(void *data) { if(!data) return; free_param_wrapper_data *params = data; @@ -318,18 +317,15 @@ static int version_wrapper() static void gui_init_wrapper(struct dt_imageio_module_storage_t *self) { - lua_storage_gui_t *gui_data =self->gui_data; + lua_storage_gui_t *gui_data = self->gui_data; self->widget = gui_data->widget->widget; } static void gui_reset_wrapper(struct dt_imageio_module_storage_t *self) { - lua_storage_gui_t *gui_data =self->gui_data; - dt_lua_async_call_alien(dt_lua_widget_trigger_callback, - 0,NULL,NULL, - LUA_ASYNC_TYPENAME,"lua_widget",gui_data->widget, - LUA_ASYNC_TYPENAME,"const char*","reset", - LUA_ASYNC_DONE); + lua_storage_gui_t *gui_data = self->gui_data; + dt_lua_async_call_alien(dt_lua_widget_trigger_callback, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "lua_widget", + gui_data->widget, LUA_ASYNC_TYPENAME, "const char*", "reset", LUA_ASYNC_DONE); } static void gui_cleanup_wrapper(struct dt_imageio_module_storage_t *self) @@ -434,8 +430,8 @@ static int register_storage(lua_State *L) else { lua_widget widget; - luaA_to(L,lua_widget,&widget,7); - dt_lua_widget_bind(L,widget); + luaA_to(L, lua_widget, &widget, 7); + dt_lua_widget_bind(L, widget); data->widget = widget; } @@ -464,7 +460,7 @@ static int register_storage(lua_State *L) luaA_push_type(L, format->parameter_lua_type, fdata); format->free_params(format, fdata); storage->free_params(storage, sdata); - dt_lua_treated_pcall(L,2,1); + dt_lua_treated_pcall(L, 2, 1); int result = lua_toboolean(L, -1); lua_pop(L, 1); if(result) diff --git a/src/lua/modules.h b/src/lua/modules.h index e9674f2d7d11..b85c56c18f6b 100644 --- a/src/lua/modules.h +++ b/src/lua/modules.h @@ -22,13 +22,14 @@ #include <lua/lua.h> -#define dt_lua_register_module_member(L, storage, struct_type, member, member_type) \ - luaA_struct_member_type(L, storage->parameter_lua_type, #member, luaA_type(L, member_type), \ +#define dt_lua_register_module_member(L, storage, struct_type, member, member_type) \ + luaA_struct_member_type(L, storage->parameter_lua_type, #member, luaA_type(L, member_type), \ offsetof(struct_type, member)) -#define dt_lua_register_module_member_indirect(L, storage, struct_type, struct_member, child_type,child_member, member_type) \ - luaA_struct_member_type(L, storage->parameter_lua_type, #child_member, luaA_type(L, member_type), \ - offsetof(struct_type, struct_member)+offsetof( child_type, child_member)) +#define dt_lua_register_module_member_indirect(L, storage, struct_type, struct_member, child_type, child_member, \ + member_type) \ + luaA_struct_member_type(L, storage->parameter_lua_type, #child_member, luaA_type(L, member_type), \ + offsetof(struct_type, struct_member) + offsetof(child_type, child_member)) // define a new module type void dt_lua_module_new(lua_State *L, const char *module_type_name); @@ -47,7 +48,7 @@ void dt_lua_module_entry_push(lua_State *L, const char *module_type_name, const luaA_Type dt_lua_module_entry_get_type(lua_State *L, const char *module_type_name, const char *entry_name); /// preset handling -#define dt_lua_register_module_presets(L, module, entry, type) \ +#define dt_lua_register_module_presets(L, module, entry, type) \ dt_lua_register_module_presets_type(L, module, entry, luaA_type_id(type)) void dt_lua_register_module_presets_type(lua_State *L, const char *module_type_name, const char *entry_name, luaA_Type preset_type); diff --git a/src/lua/preferences.c b/src/lua/preferences.c index d4fff10b3cc0..e461030c5661 100644 --- a/src/lua/preferences.c +++ b/src/lua/preferences.c @@ -85,15 +85,15 @@ typedef union all_data_t } all_data_t; struct pref_element; -typedef void (update_widget_function)(struct pref_element* ,GtkWidget* ,GtkWidget* ); -static void update_widget_enum(struct pref_element* cur_elt,GtkWidget* dialog,GtkWidget* labelev); -static void update_widget_dir(struct pref_element* cur_elt,GtkWidget* dialog,GtkWidget* labelev); -static void update_widget_file(struct pref_element* cur_elt,GtkWidget* dialog,GtkWidget* labelev); -static void update_widget_string(struct pref_element* cur_elt,GtkWidget* dialog,GtkWidget* labelev); -static void update_widget_bool(struct pref_element* cur_elt,GtkWidget* dialog,GtkWidget* labelev); -static void update_widget_int(struct pref_element* cur_elt,GtkWidget* dialog,GtkWidget* labelev); -static void update_widget_float(struct pref_element* cur_elt,GtkWidget* dialog,GtkWidget* labelev); -static void update_widget_lua(struct pref_element* cur_elt,GtkWidget* dialog,GtkWidget* labelev); +typedef void(update_widget_function)(struct pref_element *, GtkWidget *, GtkWidget *); +static void update_widget_enum(struct pref_element *cur_elt, GtkWidget *dialog, GtkWidget *labelev); +static void update_widget_dir(struct pref_element *cur_elt, GtkWidget *dialog, GtkWidget *labelev); +static void update_widget_file(struct pref_element *cur_elt, GtkWidget *dialog, GtkWidget *labelev); +static void update_widget_string(struct pref_element *cur_elt, GtkWidget *dialog, GtkWidget *labelev); +static void update_widget_bool(struct pref_element *cur_elt, GtkWidget *dialog, GtkWidget *labelev); +static void update_widget_int(struct pref_element *cur_elt, GtkWidget *dialog, GtkWidget *labelev); +static void update_widget_float(struct pref_element *cur_elt, GtkWidget *dialog, GtkWidget *labelev); +static void update_widget_lua(struct pref_element *cur_elt, GtkWidget *dialog, GtkWidget *labelev); typedef struct pref_element { @@ -107,7 +107,7 @@ typedef struct pref_element all_data_t type_data; // The widget used for this preference GtkWidget *widget; - update_widget_function* update_widget; + update_widget_function *update_widget; } pref_element; @@ -224,7 +224,7 @@ static int write_pref(lua_State *L) switch(i) { case pref_enum: - luaA_to_type(L, luaA_type_find(L,pref_name), &tmp, 4); + luaA_to_type(L, luaA_type_find(L, pref_name), &tmp, 4); dt_conf_set_string(pref_name, lua_tostring(L, 4)); break; case pref_dir: @@ -327,11 +327,11 @@ static void response_callback_lua(GtkDialog *dialog, gint response_id, pref_elem if(response_id == GTK_RESPONSE_ACCEPT) { dt_lua_lock_silent(); - lua_State * L = darktable.lua_state.state; - lua_pushcfunction(L,dt_lua_widget_trigger_callback); - luaA_push(L,lua_widget,&cur_elt->widget); - lua_pushstring(L,"set_pref"); - lua_call(L,2,0); + lua_State *L = darktable.lua_state.state; + lua_pushcfunction(L, dt_lua_widget_trigger_callback); + luaA_push(L, lua_widget, &cur_elt->widget); + lua_pushstring(L, "set_pref"); + lua_call(L, 2, 0); dt_lua_unlock(); } } @@ -360,8 +360,7 @@ static gboolean reset_widget_file(GtkWidget *label, GdkEventButton *event, pref_ { if(event->type == GDK_2BUTTON_PRESS) { - gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(cur_elt->widget), - cur_elt->type_data.file_data.default_value); + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(cur_elt->widget), cur_elt->type_data.file_data.default_value); return TRUE; } return FALSE; @@ -379,8 +378,7 @@ static gboolean reset_widget_bool(GtkWidget *label, GdkEventButton *event, pref_ { if(event->type == GDK_2BUTTON_PRESS) { - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cur_elt->widget), - cur_elt->type_data.bool_data.default_value); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cur_elt->widget), cur_elt->type_data.bool_data.default_value); return TRUE; } return FALSE; @@ -412,12 +410,12 @@ static gboolean reset_widget_lua(GtkWidget *label, GdkEventButton *event, pref_e char *old_str = dt_conf_get_string(pref_name); dt_conf_set_string(pref_name, cur_elt->type_data.lua_data.default_value); dt_lua_lock_silent(); - lua_State * L = darktable.lua_state.state; - lua_pushcfunction(L,dt_lua_widget_trigger_callback); - luaA_push(L,lua_widget,&cur_elt->widget); - luaA_push(L,lua_widget,&cur_elt->widget); - lua_pushstring(L,"set_pref"); - lua_call(L,3,0); + lua_State *L = darktable.lua_state.state; + lua_pushcfunction(L, dt_lua_widget_trigger_callback); + luaA_push(L, lua_widget, &cur_elt->widget); + luaA_push(L, lua_widget, &cur_elt->widget); + lua_pushstring(L, "set_pref"); + lua_call(L, 3, 0); dt_lua_unlock(); dt_conf_set_string(pref_name, old_str); return TRUE; @@ -427,32 +425,39 @@ static gboolean reset_widget_lua(GtkWidget *label, GdkEventButton *event, pref_e -static void update_widget_enum(pref_element* cur_elt,GtkWidget* dialog,GtkWidget* labelev) +static void update_widget_enum(pref_element *cur_elt, GtkWidget *dialog, GtkWidget *labelev) { char pref_name[1024]; get_pref_name(pref_name, sizeof(pref_name), cur_elt->script, cur_elt->name); g_signal_connect(G_OBJECT(labelev), "button-press-event", G_CALLBACK(reset_widget_enum), cur_elt); g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(response_callback_enum), cur_elt); gtk_combo_box_set_active(GTK_COMBO_BOX(cur_elt->widget), 0); - char*value= dt_conf_get_string(pref_name); - do { - char * active_entry = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(cur_elt->widget)); - if(!active_entry) { + char *value = dt_conf_get_string(pref_name); + do + { + char *active_entry = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(cur_elt->widget)); + if(!active_entry) + { gtk_combo_box_set_active(GTK_COMBO_BOX(cur_elt->widget), -1); g_free(active_entry); break; - }else if(!strcmp(active_entry,value )) { + } + else if(!strcmp(active_entry, value)) + { g_free(active_entry); break; - } else { - gtk_combo_box_set_active(GTK_COMBO_BOX(cur_elt->widget), gtk_combo_box_get_active(GTK_COMBO_BOX(cur_elt->widget))+1); + } + else + { + gtk_combo_box_set_active(GTK_COMBO_BOX(cur_elt->widget), + gtk_combo_box_get_active(GTK_COMBO_BOX(cur_elt->widget)) + 1); g_free(active_entry); } - } while (true); + } while(true); free(value); } -static void update_widget_dir(pref_element* cur_elt,GtkWidget* dialog,GtkWidget* labelev) +static void update_widget_dir(pref_element *cur_elt, GtkWidget *dialog, GtkWidget *labelev) { char pref_name[1024]; get_pref_name(pref_name, sizeof(pref_name), cur_elt->script, cur_elt->name); @@ -463,7 +468,7 @@ static void update_widget_dir(pref_element* cur_elt,GtkWidget* dialog,GtkWidget* g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(response_callback_dir), cur_elt); } -static void update_widget_file(pref_element* cur_elt,GtkWidget* dialog,GtkWidget* labelev) +static void update_widget_file(pref_element *cur_elt, GtkWidget *dialog, GtkWidget *labelev) { char pref_name[1024]; get_pref_name(pref_name, sizeof(pref_name), cur_elt->script, cur_elt->name); @@ -474,18 +479,18 @@ static void update_widget_file(pref_element* cur_elt,GtkWidget* dialog,GtkWidget g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(response_callback_file), cur_elt); } -static void update_widget_string(pref_element* cur_elt,GtkWidget* dialog,GtkWidget* labelev) +static void update_widget_string(pref_element *cur_elt, GtkWidget *dialog, GtkWidget *labelev) { char pref_name[1024]; get_pref_name(pref_name, sizeof(pref_name), cur_elt->script, cur_elt->name); g_signal_connect(G_OBJECT(labelev), "button-press-event", G_CALLBACK(reset_widget_string), cur_elt); g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(response_callback_string), cur_elt); - char* str = dt_conf_get_string(pref_name); + char *str = dt_conf_get_string(pref_name); gtk_entry_set_text(GTK_ENTRY(cur_elt->widget), str); g_free(str); } -static void update_widget_bool(pref_element* cur_elt,GtkWidget* dialog,GtkWidget* labelev) +static void update_widget_bool(pref_element *cur_elt, GtkWidget *dialog, GtkWidget *labelev) { char pref_name[1024]; get_pref_name(pref_name, sizeof(pref_name), cur_elt->script, cur_elt->name); @@ -494,7 +499,7 @@ static void update_widget_bool(pref_element* cur_elt,GtkWidget* dialog,GtkWidget gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cur_elt->widget), dt_conf_get_bool(pref_name)); } -static void update_widget_int(pref_element* cur_elt,GtkWidget* dialog,GtkWidget* labelev) +static void update_widget_int(pref_element *cur_elt, GtkWidget *dialog, GtkWidget *labelev) { char pref_name[1024]; get_pref_name(pref_name, sizeof(pref_name), cur_elt->script, cur_elt->name); @@ -503,7 +508,7 @@ static void update_widget_int(pref_element* cur_elt,GtkWidget* dialog,GtkWidget* g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(response_callback_int), cur_elt); } -static void update_widget_float(pref_element* cur_elt,GtkWidget* dialog,GtkWidget* labelev) +static void update_widget_float(pref_element *cur_elt, GtkWidget *dialog, GtkWidget *labelev) { char pref_name[1024]; get_pref_name(pref_name, sizeof(pref_name), cur_elt->script, cur_elt->name); @@ -512,14 +517,14 @@ static void update_widget_float(pref_element* cur_elt,GtkWidget* dialog,GtkWidge g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(response_callback_float), cur_elt); } -static void update_widget_lua(pref_element* cur_elt,GtkWidget* dialog,GtkWidget* labelev) +static void update_widget_lua(pref_element *cur_elt, GtkWidget *dialog, GtkWidget *labelev) { dt_lua_lock_silent(); - lua_State * L = darktable.lua_state.state; - lua_pushcfunction(L,dt_lua_widget_trigger_callback); - luaA_push(L,lua_widget,&cur_elt->widget); - lua_pushstring(L,"reset"); - lua_call(L,2,0); + lua_State *L = darktable.lua_state.state; + lua_pushcfunction(L, dt_lua_widget_trigger_callback); + luaA_push(L, lua_widget, &cur_elt->widget); + lua_pushstring(L, "reset"); + lua_call(L, 2, 0); dt_lua_unlock(); g_signal_connect(G_OBJECT(labelev), "button-press-event", G_CALLBACK(reset_widget_lua), cur_elt); g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(response_callback_lua), cur_elt); @@ -571,14 +576,15 @@ static int register_pref_sub(lua_State *L) value++; } - if(!dt_conf_key_exists(pref_name)) { + if(!dt_conf_key_exists(pref_name)) + { dt_conf_set_string(pref_name, built_elt->type_data.enum_data.default_value); } g_object_ref_sink(G_OBJECT(built_elt->widget)); - built_elt->tooltip_reset = g_strdup_printf( _("double click to reset to `%s'"), - built_elt->type_data.enum_data.default_value); + built_elt->tooltip_reset + = g_strdup_printf(_("double click to reset to `%s'"), built_elt->type_data.enum_data.default_value); built_elt->update_widget = update_widget_enum; break; } @@ -586,13 +592,16 @@ static int register_pref_sub(lua_State *L) built_elt->type_data.dir_data.default_value = strdup(luaL_checkstring(L, cur_param)); cur_param++; - if(!dt_conf_key_exists(pref_name)) { + if(!dt_conf_key_exists(pref_name)) + { dt_conf_set_string(pref_name, built_elt->type_data.dir_data.default_value); } - built_elt->widget = gtk_file_chooser_button_new(_("select directory"), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); + built_elt->widget + = gtk_file_chooser_button_new(_("select directory"), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); gtk_file_chooser_button_set_width_chars(GTK_FILE_CHOOSER_BUTTON(built_elt->widget), 20); g_object_ref_sink(G_OBJECT(built_elt->widget)); - built_elt->tooltip_reset = g_strdup_printf( _("double click to reset to `%s'"), built_elt->type_data.dir_data.default_value); + built_elt->tooltip_reset + = g_strdup_printf(_("double click to reset to `%s'"), built_elt->type_data.dir_data.default_value); built_elt->update_widget = update_widget_dir; break; case pref_file: @@ -604,7 +613,8 @@ static int register_pref_sub(lua_State *L) built_elt->widget = gtk_file_chooser_button_new(_("select file"), GTK_FILE_CHOOSER_ACTION_OPEN); gtk_file_chooser_button_set_width_chars(GTK_FILE_CHOOSER_BUTTON(built_elt->widget), 20); - built_elt->tooltip_reset= g_strdup_printf( _("double click to reset to `%s'"), built_elt->type_data.file_data.default_value); + built_elt->tooltip_reset + = g_strdup_printf(_("double click to reset to `%s'"), built_elt->type_data.file_data.default_value); g_object_ref_sink(G_OBJECT(built_elt->widget)); built_elt->update_widget = update_widget_file; break; @@ -616,8 +626,8 @@ static int register_pref_sub(lua_State *L) dt_conf_set_string(pref_name, built_elt->type_data.string_data.default_value); built_elt->widget = gtk_entry_new(); - built_elt->tooltip_reset= g_strdup_printf( _("double click to reset to `%s'"), - built_elt->type_data.string_data.default_value); + built_elt->tooltip_reset + = g_strdup_printf(_("double click to reset to `%s'"), built_elt->type_data.string_data.default_value); g_object_ref_sink(G_OBJECT(built_elt->widget)); built_elt->update_widget = update_widget_string; break; @@ -626,94 +636,92 @@ static int register_pref_sub(lua_State *L) built_elt->type_data.bool_data.default_value = lua_toboolean(L, cur_param); cur_param++; - if(!dt_conf_key_exists(pref_name)) - dt_conf_set_bool(pref_name, built_elt->type_data.bool_data.default_value); + if(!dt_conf_key_exists(pref_name)) dt_conf_set_bool(pref_name, built_elt->type_data.bool_data.default_value); built_elt->widget = gtk_check_button_new(); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(built_elt->widget), dt_conf_get_bool(pref_name)); g_object_ref_sink(G_OBJECT(built_elt->widget)); - built_elt->tooltip_reset = g_strdup_printf( _("double click to reset to `%s'"), - built_elt->type_data.bool_data.default_value ? "true" : "false"); + built_elt->tooltip_reset = g_strdup_printf(_("double click to reset to `%s'"), + built_elt->type_data.bool_data.default_value ? "true" : "false"); built_elt->update_widget = update_widget_bool; break; case pref_int: - { - luaL_checktype(L, cur_param, LUA_TNUMBER); - built_elt->type_data.int_data.default_value = lua_tointeger(L, cur_param); - cur_param++; + { + luaL_checktype(L, cur_param, LUA_TNUMBER); + built_elt->type_data.int_data.default_value = lua_tointeger(L, cur_param); + cur_param++; - luaL_checktype(L, cur_param, LUA_TNUMBER); - int min = lua_tointeger(L, cur_param); - cur_param++; + luaL_checktype(L, cur_param, LUA_TNUMBER); + int min = lua_tointeger(L, cur_param); + cur_param++; - luaL_checktype(L, cur_param, LUA_TNUMBER); - int max = lua_tointeger(L, cur_param); - cur_param++; + luaL_checktype(L, cur_param, LUA_TNUMBER); + int max = lua_tointeger(L, cur_param); + cur_param++; - if(!dt_conf_key_exists(pref_name)) - dt_conf_set_int(pref_name, built_elt->type_data.int_data.default_value); - built_elt->widget = gtk_spin_button_new_with_range(min, max, 1); - gtk_spin_button_set_digits(GTK_SPIN_BUTTON(built_elt->widget), 0); - g_object_ref_sink(G_OBJECT(built_elt->widget)); - built_elt->tooltip_reset = g_strdup_printf( _("double click to reset to `%d'"), - built_elt->type_data.int_data.default_value); - built_elt->update_widget = update_widget_int; - break; - } + if(!dt_conf_key_exists(pref_name)) dt_conf_set_int(pref_name, built_elt->type_data.int_data.default_value); + built_elt->widget = gtk_spin_button_new_with_range(min, max, 1); + gtk_spin_button_set_digits(GTK_SPIN_BUTTON(built_elt->widget), 0); + g_object_ref_sink(G_OBJECT(built_elt->widget)); + built_elt->tooltip_reset + = g_strdup_printf(_("double click to reset to `%d'"), built_elt->type_data.int_data.default_value); + built_elt->update_widget = update_widget_int; + break; + } case pref_float: - { - luaL_checktype(L, cur_param, LUA_TNUMBER); - built_elt->type_data.float_data.default_value = lua_tonumber(L, cur_param); - cur_param++; + { + luaL_checktype(L, cur_param, LUA_TNUMBER); + built_elt->type_data.float_data.default_value = lua_tonumber(L, cur_param); + cur_param++; - luaL_checktype(L, cur_param, LUA_TNUMBER); - float min = lua_tonumber(L, cur_param); - cur_param++; + luaL_checktype(L, cur_param, LUA_TNUMBER); + float min = lua_tonumber(L, cur_param); + cur_param++; - luaL_checktype(L, cur_param, LUA_TNUMBER); - float max = lua_tonumber(L, cur_param); - cur_param++; + luaL_checktype(L, cur_param, LUA_TNUMBER); + float max = lua_tonumber(L, cur_param); + cur_param++; - luaL_checktype(L, cur_param, LUA_TNUMBER); - float step = lua_tonumber(L, cur_param); - cur_param++; + luaL_checktype(L, cur_param, LUA_TNUMBER); + float step = lua_tonumber(L, cur_param); + cur_param++; - if(!dt_conf_key_exists(pref_name)) - dt_conf_set_float(pref_name, built_elt->type_data.float_data.default_value); + if(!dt_conf_key_exists(pref_name)) + dt_conf_set_float(pref_name, built_elt->type_data.float_data.default_value); - built_elt->widget = gtk_spin_button_new_with_range(min, max, step); - built_elt->tooltip_reset = g_strdup_printf( _("double click to reset to `%f'"), - built_elt->type_data.float_data.default_value); - g_object_ref_sink(G_OBJECT(built_elt->widget)); - built_elt->update_widget = update_widget_float; - break; - } + built_elt->widget = gtk_spin_button_new_with_range(min, max, step); + built_elt->tooltip_reset + = g_strdup_printf(_("double click to reset to `%f'"), built_elt->type_data.float_data.default_value); + g_object_ref_sink(G_OBJECT(built_elt->widget)); + built_elt->update_widget = update_widget_float; + break; + } case pref_lua: - { - built_elt->type_data.lua_data.default_value = strdup(luaL_checkstring(L, cur_param)); - cur_param++; + { + built_elt->type_data.lua_data.default_value = strdup(luaL_checkstring(L, cur_param)); + cur_param++; - if(!dt_conf_key_exists(pref_name)) - dt_conf_set_string(pref_name, built_elt->type_data.lua_data.default_value); + if(!dt_conf_key_exists(pref_name)) + dt_conf_set_string(pref_name, built_elt->type_data.lua_data.default_value); - built_elt->tooltip_reset= g_strdup_printf( _("double click to reset to `%s'"), - built_elt->type_data.lua_data.default_value); + built_elt->tooltip_reset + = g_strdup_printf(_("double click to reset to `%s'"), built_elt->type_data.lua_data.default_value); - lua_widget widget; - luaA_to(L,lua_widget,&widget,cur_param); - cur_param++; - dt_lua_widget_bind(L,widget); - built_elt->widget = widget->widget; - built_elt->update_widget = update_widget_lua; + lua_widget widget; + luaA_to(L, lua_widget, &widget, cur_param); + cur_param++; + dt_lua_widget_bind(L, widget); + built_elt->widget = widget->widget; + built_elt->update_widget = update_widget_lua; - luaL_checktype(L,cur_param,LUA_TFUNCTION); - luaA_push(L,lua_widget,widget); - lua_pushvalue(L,cur_param); - dt_lua_widget_set_callback(L,-2,"set_pref"); - lua_pop(L,1); + luaL_checktype(L, cur_param, LUA_TFUNCTION); + luaA_push(L, lua_widget, widget); + lua_pushvalue(L, cur_param); + dt_lua_widget_set_callback(L, -2, "set_pref"); + lua_pop(L, 1); - break; - } + break; + } } return 0; } @@ -727,7 +735,7 @@ static int register_pref(lua_State *L) dt_lua_gtk_wrap(L); lua_insert(L, 1); lua_pushlightuserdata(L, &built_elt); - int result = dt_lua_treated_pcall(L,lua_gettop(L)-1,0); + int result = dt_lua_treated_pcall(L, lua_gettop(L) - 1, 0); if(result == LUA_OK) { built_elt->next = pref_list; @@ -742,7 +750,7 @@ static int register_pref(lua_State *L) } -GtkGrid* init_tab_lua(GtkWidget *dialog, GtkWidget *tab) +GtkGrid *init_tab_lua(GtkWidget *dialog, GtkWidget *tab) { if(!pref_list) return NULL; // no option registered => don't create the tab GtkWidget *label, *labelev, *viewport; @@ -774,7 +782,7 @@ GtkGrid* init_tab_lua(GtkWidget *dialog, GtkWidget *tab) labelev = gtk_event_box_new(); gtk_widget_add_events(labelev, GDK_BUTTON_PRESS_MASK); gtk_container_add(GTK_CONTAINER(labelev), label); - cur_elt->update_widget(cur_elt,dialog,label); + cur_elt->update_widget(cur_elt, dialog, label); gtk_widget_set_tooltip_text(labelev, cur_elt->tooltip_reset); gtk_event_box_set_visible_window(GTK_EVENT_BOX(labelev), FALSE); gtk_widget_set_tooltip_text(cur_elt->widget, cur_elt->tooltip); @@ -789,7 +797,7 @@ GtkGrid* init_tab_lua(GtkWidget *dialog, GtkWidget *tab) void destroy_tab_lua(GtkGrid *grid) { if(!grid) return; - gtk_grid_remove_column(grid,1); // detach all special widgets to avoid having them destroyed + gtk_grid_remove_column(grid, 1); // detach all special widgets to avoid having them destroyed } int dt_lua_init_preferences(lua_State *L) { diff --git a/src/lua/preferences.h b/src/lua/preferences.h index 5638fa1bd037..175eaffe4026 100644 --- a/src/lua/preferences.h +++ b/src/lua/preferences.h @@ -21,8 +21,8 @@ #include <gtk/gtk.h> #include <lua/lua.h> -GtkGrid* init_tab_lua(GtkWidget *dialog, GtkWidget *tab); -void destroy_tab_lua( GtkGrid *grid); +GtkGrid *init_tab_lua(GtkWidget *dialog, GtkWidget *tab); +void destroy_tab_lua(GtkGrid *grid); int dt_lua_init_preferences(lua_State *L); diff --git a/src/lua/storage.c b/src/lua/storage.c index 683a0e6455ba..30dce6cad3a1 100644 --- a/src/lua/storage.c +++ b/src/lua/storage.c @@ -127,7 +127,7 @@ void dt_lua_register_storage_type(lua_State *L, dt_imageio_module_storage_t *mod { dt_lua_type_register_parent_type(L, type_id, luaA_type_find(L, "dt_imageio_module_storage_t")); lua_pushlightuserdata(L, module); - dt_lua_type_setmetafield_type(L,type_id,"__associated_object"); + dt_lua_type_setmetafield_type(L, type_id, "__associated_object"); // add to the table lua_pushlightuserdata(L, module); lua_pushcclosure(L, get_storage_params, 1); diff --git a/src/lua/storage.h b/src/lua/storage.h index e6bbdb4bcc05..b641cb99c24d 100644 --- a/src/lua/storage.h +++ b/src/lua/storage.h @@ -25,7 +25,7 @@ struct dt_imageio_module_storage_t; -#define dt_lua_register_storage(L, storage, type_name) \ +#define dt_lua_register_storage(L, storage, type_name) \ dt_lua_register_storage_type(L, storage, luaA_type_find(#type_name)) void dt_lua_register_storage_type(lua_State *L, struct dt_imageio_module_storage_t *module, luaA_Type type_id); diff --git a/src/lua/styles.c b/src/lua/styles.c index 7d9f334f6819..f24905721e44 100644 --- a/src/lua/styles.c +++ b/src/lua/styles.c @@ -307,9 +307,9 @@ int dt_lua_init_styles(lua_State *L) lua_pushcclosure(L, dt_lua_type_member_common, 1); dt_lua_type_register_const(L, dt_style_t, "export"); lua_pushcfunction(L, style_gc); - dt_lua_type_setmetafield(L,dt_style_t,"__gc"); + dt_lua_type_setmetafield(L, dt_style_t, "__gc"); lua_pushcfunction(L, style_tostring); - dt_lua_type_setmetafield(L,dt_style_t,"__tostring"); + dt_lua_type_setmetafield(L, dt_style_t, "__tostring"); // dt_style_item_t dt_lua_init_type(L, dt_style_item_t); @@ -319,9 +319,9 @@ int dt_lua_init_styles(lua_State *L) lua_pushcfunction(L, dt_lua_type_member_luaautoc); dt_lua_type_register_struct(L, dt_style_item_t); lua_pushcfunction(L, style_item_gc); - dt_lua_type_setmetafield(L,dt_style_item_t,"__gc"); + dt_lua_type_setmetafield(L, dt_style_item_t, "__gc"); lua_pushcfunction(L, style_item_tostring); - dt_lua_type_setmetafield(L,dt_style_item_t,"__tostring"); + dt_lua_type_setmetafield(L, dt_style_item_t, "__tostring"); diff --git a/src/lua/tags.c b/src/lua/tags.c index a0a52458fbe3..1ded6f0f11d4 100644 --- a/src/lua/tags.c +++ b/src/lua/tags.c @@ -148,7 +148,7 @@ static int tag_delete(lua_State *L) { dt_lua_tag_t tagid; luaA_to(L, dt_lua_tag_t, &tagid, -1); - + GList *tagged_images = NULL; sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT imgid FROM main.tagged_images WHERE tagid=?1", @@ -268,7 +268,7 @@ int dt_lua_init_tags(lua_State *L) lua_pushcclosure(L, dt_lua_type_member_common, 1); dt_lua_type_register_const(L, dt_lua_tag_t, "detach"); lua_pushcfunction(L, tag_tostring); - dt_lua_type_setmetafield(L,dt_lua_tag_t,"__tostring"); + dt_lua_type_setmetafield(L, dt_lua_tag_t, "__tostring"); /* tags */ dt_lua_push_darktable_lib(L); diff --git a/src/lua/types.c b/src/lua/types.c index 2e32ddb84c04..f74f4d56f534 100644 --- a/src/lua/types.c +++ b/src/lua/types.c @@ -195,9 +195,9 @@ static int autotype_next(lua_State *L) lua_pushvalue(L, -4); lua_pushvalue(L, -2); // hacky way to avoid a subfunction just to do a pcall around getting a value in a table - luaL_loadstring(L,"args ={...}; return args[1][args[2]]"); - lua_insert(L,-3); - int result = dt_lua_treated_pcall(L,2,1); + luaL_loadstring(L, "args ={...}; return args[1][args[2]]"); + lua_insert(L, -3); + int result = dt_lua_treated_pcall(L, 2, 1); if(result == LUA_OK) { return 2; @@ -283,8 +283,7 @@ static int autotype_newindex(lua_State *L) { lua_pop(L, 1); luaL_getmetafield(L, -4, "__luaA_TypeName"); - return luaL_error(L, "field \"%s\" can't be written for type %s\n", lua_tostring(L, -4), - lua_tostring(L, -1)); + return luaL_error(L, "field \"%s\" can't be written for type %s\n", lua_tostring(L, -4), lua_tostring(L, -1)); } lua_pushvalue(L, -5); lua_pushvalue(L, -5); @@ -297,15 +296,18 @@ static int autotype_newindex(lua_State *L) static int autotype_tostring(lua_State *L) { - if(luaL_getmetafield(L,1,"__real_tostring")) { - lua_insert(L,1); - lua_call(L,1,1); + if(luaL_getmetafield(L, 1, "__real_tostring")) + { + lua_insert(L, 1); + lua_call(L, 1, 1); return 1; - } else { + } + else + { char tmp[256]; - luaL_getmetafield(L,1,"__luaA_TypeName"); - snprintf(tmp,sizeof(tmp),"%s (%p)",lua_tostring(L,-1),lua_topointer(L,1)); - lua_pushstring(L,tmp); + luaL_getmetafield(L, 1, "__luaA_TypeName"); + snprintf(tmp, sizeof(tmp), "%s (%p)", lua_tostring(L, -1), lua_topointer(L, 1)); + lua_pushstring(L, tmp); return 1; } } @@ -341,12 +343,13 @@ static int full_pushfunc(lua_State *L, luaA_Type type_id, const void *cin) static void full_tofunc(lua_State *L, luaA_Type type_id, void *cout, int index) { - if(!dt_lua_isa_type(L,index,type_id)) { + if(!dt_lua_isa_type(L, index, type_id)) + { char error_msg[256]; - snprintf(error_msg,sizeof(error_msg),"%s expected",luaA_typename(L,type_id)); - luaL_argerror(L,index,error_msg); - } - void* udata = lua_touserdata(L,index); + snprintf(error_msg, sizeof(error_msg), "%s expected", luaA_typename(L, type_id)); + luaL_argerror(L, index, error_msg); + } + void *udata = lua_touserdata(L, index); memcpy(cout, udata, luaA_typesize(L, type_id)); } @@ -381,19 +384,21 @@ static int int_pushfunc(lua_State *L, luaA_Type type_id, const void *cin) static void int_tofunc(lua_State *L, luaA_Type type_id, void *cout, int index) { - if(!dt_lua_isa_type(L,index,type_id)) { + if(!dt_lua_isa_type(L, index, type_id)) + { char error_msg[256]; - snprintf(error_msg,sizeof(error_msg),"%s expected",luaA_typename(L,type_id)); - luaL_argerror(L,index,error_msg); - } - void* udata = lua_touserdata(L,index); + snprintf(error_msg, sizeof(error_msg), "%s expected", luaA_typename(L, type_id)); + luaL_argerror(L, index, error_msg); + } + void *udata = lua_touserdata(L, index); memcpy(cout, udata, sizeof(int)); } static int gpointer_pushfunc(lua_State *L, luaA_Type type_id, const void *cin) { gpointer singleton = *(gpointer *)cin; - if(!singleton) { + if(!singleton) + { lua_pushnil(L); return 1; } @@ -418,28 +423,31 @@ static int gpointer_pushfunc(lua_State *L, luaA_Type type_id, const void *cin) lua_call(L, 2, 0); } } - lua_remove(L, -2); //dt_lua_gpointer_values + lua_remove(L, -2); // dt_lua_gpointer_values return 1; } static void gpointer_tofunc(lua_State *L, luaA_Type type_id, void *cout, int index) { - if(!dt_lua_isa_type(L,index,type_id)) { + if(!dt_lua_isa_type(L, index, type_id)) + { char error_msg[256]; - snprintf(error_msg,sizeof(error_msg),"%s expected",luaA_typename(L,type_id)); - luaL_argerror(L,index,error_msg); - } - gpointer* udata = lua_touserdata(L,index); + snprintf(error_msg, sizeof(error_msg), "%s expected", luaA_typename(L, type_id)); + luaL_argerror(L, index, error_msg); + } + gpointer *udata = lua_touserdata(L, index); memcpy(cout, udata, sizeof(gpointer)); - if(!*udata) { - luaL_error(L,"Attempting to access of type %s after its destruction\n",luaA_typename(L,type_id)); + if(!*udata) + { + luaL_error(L, "Attempting to access of type %s after its destruction\n", luaA_typename(L, type_id)); } } static int unknown_pushfunc(lua_State *L, luaA_Type type_id, const void *cin) { gpointer singleton = *(gpointer *)cin; - if(!singleton) { + if(!singleton) + { lua_pushnil(L); return 1; } @@ -448,9 +456,9 @@ static int unknown_pushfunc(lua_State *L, luaA_Type type_id, const void *cin) lua_gettable(L, -2); if(lua_isnoneornil(L, -1)) { - return luaL_error(L,"Attempting to push a pointer of unknown type on the stack\n"); + return luaL_error(L, "Attempting to push a pointer of unknown type on the stack\n"); } - lua_remove(L, -2); //dt_lua_gpointer_values + lua_remove(L, -2); // dt_lua_gpointer_values return 1; } @@ -562,8 +570,7 @@ int dt_lua_type_member_common(lua_State *L) if(lua_gettop(L) != 2) { luaL_getmetafield(L, 1, "__luaA_TypeName"); - return luaL_error(L, "field \"%s\" can't be written for type %s\n", lua_tostring(L, 2), - lua_tostring(L, -1)); + return luaL_error(L, "field \"%s\" can't be written for type %s\n", lua_tostring(L, 2), lua_tostring(L, -1)); } lua_pushvalue(L, lua_upvalueindex(1)); return 1; @@ -582,12 +589,15 @@ void dt_lua_type_register_parent_type(lua_State *L, luaA_Type type_id, luaA_Type lua_pushnil(L); /* first key */ while(lua_next(L, -2) != 0) { - lua_getfield(L,-4,lua_tostring(L,-2)); - if(lua_isnil(L,-1)) { - lua_pop(L,1); - lua_setfield(L, -4, lua_tostring(L,-2)); - } else { - lua_pop(L,2); + lua_getfield(L, -4, lua_tostring(L, -2)); + if(lua_isnil(L, -1)) + { + lua_pop(L, 1); + lua_setfield(L, -4, lua_tostring(L, -2)); + } + else + { + lua_pop(L, 2); } } lua_pop(L, 2); @@ -597,12 +607,15 @@ void dt_lua_type_register_parent_type(lua_State *L, luaA_Type type_id, luaA_Type lua_pushnil(L); /* first key */ while(lua_next(L, -2) != 0) { - lua_getfield(L,-4,lua_tostring(L,-2)); - if(lua_isnil(L,-1)) { - lua_pop(L,1); - lua_setfield(L, -4, lua_tostring(L,-2)); - } else { - lua_pop(L,2); + lua_getfield(L, -4, lua_tostring(L, -2)); + if(lua_isnil(L, -1)) + { + lua_pop(L, 1); + lua_setfield(L, -4, lua_tostring(L, -2)); + } + else + { + lua_pop(L, 2); } } lua_pop(L, 2); @@ -610,12 +623,15 @@ void dt_lua_type_register_parent_type(lua_State *L, luaA_Type type_id, luaA_Type lua_pushnil(L); /* first key */ while(lua_next(L, -2) != 0) { - lua_getfield(L,-4,lua_tostring(L,-2)); - if(lua_isnil(L,-1)) { - lua_pop(L,1); - lua_setfield(L, -4, lua_tostring(L,-2)); - } else { - lua_pop(L,2); + lua_getfield(L, -4, lua_tostring(L, -2)); + if(lua_isnil(L, -1)) + { + lua_pop(L, 1); + lua_setfield(L, -4, lua_tostring(L, -2)); + } + else + { + lua_pop(L, 2); } } @@ -691,9 +707,9 @@ luaA_Type dt_lua_init_singleton(lua_State *L, const char *unique_name, void *dat *udata = data; luaL_getsubtable(L, LUA_REGISTRYINDEX, "dt_lua_gpointer_values"); lua_pushlightuserdata(L, data); - lua_pushvalue(L,-3); - lua_settable(L,-3); - lua_pop(L,1); + lua_pushvalue(L, -3); + lua_settable(L, -3); + lua_pop(L, 1); } lua_pushvalue(L, -1); @@ -780,14 +796,15 @@ luaA_Type dt_lua_init_int_type_type(lua_State *L, luaA_Type type_id) return type_id; } -static int gpointer_wrapper(lua_State*L) +static int gpointer_wrapper(lua_State *L) { - gpointer *udata = (gpointer*)lua_touserdata(L,1); - if(!*udata) { - luaL_getmetafield(L,1,"__luaA_TypeName"); - luaL_error(L,"Attempting to access an invalid object of type %s",lua_tostring(L,-1)); + gpointer *udata = (gpointer *)lua_touserdata(L, 1); + if(!*udata) + { + luaL_getmetafield(L, 1, "__luaA_TypeName"); + luaL_error(L, "Attempting to access an invalid object of type %s", lua_tostring(L, -1)); } - lua_CFunction callback = lua_tocfunction(L,lua_upvalueindex(1)); + lua_CFunction callback = lua_tocfunction(L, lua_upvalueindex(1)); return callback(L); } @@ -796,24 +813,24 @@ luaA_Type dt_lua_init_gpointer_type_type(lua_State *L, luaA_Type type_id) { init_metatable(L, type_id); - lua_getfield(L,-1,"__next"); - lua_pushcclosure(L, gpointer_wrapper,1); + lua_getfield(L, -1, "__next"); + lua_pushcclosure(L, gpointer_wrapper, 1); lua_setfield(L, -2, "__next"); - lua_getfield(L,-1,"__index"); - lua_pushcclosure(L, gpointer_wrapper,1); + lua_getfield(L, -1, "__index"); + lua_pushcclosure(L, gpointer_wrapper, 1); lua_setfield(L, -2, "__index"); - lua_getfield(L,-1,"__newindex"); - lua_pushcclosure(L, gpointer_wrapper,1); + lua_getfield(L, -1, "__newindex"); + lua_pushcclosure(L, gpointer_wrapper, 1); lua_setfield(L, -2, "__newindex"); - lua_getfield(L,-1,"__pairs"); - lua_pushcclosure(L, gpointer_wrapper,1); + lua_getfield(L, -1, "__pairs"); + lua_pushcclosure(L, gpointer_wrapper, 1); lua_setfield(L, -2, "__pairs"); - lua_getfield(L,-1,"__tostring"); - lua_pushcclosure(L, gpointer_wrapper,1); + lua_getfield(L, -1, "__tostring"); + lua_pushcclosure(L, gpointer_wrapper, 1); lua_setfield(L, -2, "__tostring"); lua_pop(L, 1); @@ -822,43 +839,41 @@ luaA_Type dt_lua_init_gpointer_type_type(lua_State *L, luaA_Type type_id) return type_id; } -void dt_lua_type_gpointer_alias_type(lua_State*L,luaA_Type type_id,void* pointer,void* alias) +void dt_lua_type_gpointer_alias_type(lua_State *L, luaA_Type type_id, void *pointer, void *alias) { luaL_getsubtable(L, LUA_REGISTRYINDEX, "dt_lua_gpointer_values"); lua_pushlightuserdata(L, pointer); lua_gettable(L, -2); if(lua_isnoneornil(L, -1)) { - luaL_error(L,"Adding an alias to an unknown object for type %s",luaA_typename(L,type_id)); + luaL_error(L, "Adding an alias to an unknown object for type %s", luaA_typename(L, type_id)); } - lua_pushlightuserdata(L,alias); - lua_insert(L,-2); - lua_settable(L,-3); - lua_pop(L,1); - - + lua_pushlightuserdata(L, alias); + lua_insert(L, -2); + lua_settable(L, -3); + lua_pop(L, 1); } -void dt_lua_type_gpointer_drop(lua_State*L, void* pointer) +void dt_lua_type_gpointer_drop(lua_State *L, void *pointer) { luaL_getsubtable(L, LUA_REGISTRYINDEX, "dt_lua_gpointer_values"); lua_pushlightuserdata(L, pointer); - lua_gettable(L,-2); - gpointer *udata = (gpointer*)lua_touserdata(L,-1); - if(lua_isnil(L,-1)) { - lua_pop(L,2); + lua_gettable(L, -2); + gpointer *udata = (gpointer *)lua_touserdata(L, -1); + if(lua_isnil(L, -1)) + { + lua_pop(L, 2); return; // this table is weak, the object has been gc } *udata = NULL; - lua_pop(L,1); + lua_pop(L, 1); lua_pushlightuserdata(L, pointer); lua_pushnil(L); - lua_settable(L,-3); - - lua_pop(L,1); + lua_settable(L, -3); + lua_pop(L, 1); } gboolean dt_lua_isa_type(lua_State *L, int index, luaA_Type type_id) @@ -885,54 +900,51 @@ gboolean dt_lua_typeisa_type(lua_State *L, luaA_Type obj_type, luaA_Type type_id return dt_lua_typeisa_type(L, parent_type, type_id); } -void dt_lua_type_setmetafield_type(lua_State*L,luaA_Type type_id,const char* method_name) +void dt_lua_type_setmetafield_type(lua_State *L, luaA_Type type_id, const char *method_name) { // These metafields should never be overridden by user code - if( - !strcmp(method_name,"__index") || - !strcmp(method_name,"__newindex") || - !strcmp(method_name,"__number_index") || - !strcmp(method_name,"__number_newindex") || - !strcmp(method_name,"__pairs") || - !strcmp(method_name,"__next") || - !strcmp(method_name,"__get") || - !strcmp(method_name,"__set") || - !strcmp(method_name,"__len") || - !strcmp(method_name,"__luaA_Type") || - !strcmp(method_name,"__luaA_TypeName") || - !strcmp(method_name,"__luaA_ParentMetatable") || - !strcmp(method_name,"__init") || - !strcmp(method_name,"__values") || - !strcmp(method_name,"__singleton") || - !strcmp(method_name,"__pusher") || - !strcmp(method_name,"__getter") || - !strcmp(method_name,"__mode") || - 0) { - luaL_error(L,"non-core lua code is not allowed to change meta-field %s\n",method_name); - } else if(!strcmp(method_name,"__tostring")) { + if(!strcmp(method_name, "__index") || !strcmp(method_name, "__newindex") + || !strcmp(method_name, "__number_index") || !strcmp(method_name, "__number_newindex") + || !strcmp(method_name, "__pairs") || !strcmp(method_name, "__next") || !strcmp(method_name, "__get") + || !strcmp(method_name, "__set") || !strcmp(method_name, "__len") || !strcmp(method_name, "__luaA_Type") + || !strcmp(method_name, "__luaA_TypeName") || !strcmp(method_name, "__luaA_ParentMetatable") + || !strcmp(method_name, "__init") || !strcmp(method_name, "__values") || !strcmp(method_name, "__singleton") + || !strcmp(method_name, "__pusher") || !strcmp(method_name, "__getter") || !strcmp(method_name, "__mode") + || 0) + { + luaL_error(L, "non-core lua code is not allowed to change meta-field %s\n", method_name); + } + else if(!strcmp(method_name, "__tostring")) + { luaL_getmetatable(L, luaA_typename(L, type_id)); - lua_pushvalue(L,-2); + lua_pushvalue(L, -2); lua_setfield(L, -2, "__real_tostring"); lua_pop(L, 2); // pop the metatable and the value return; - // whitelist for specific types - } else if( + // whitelist for specific types + } + else if( // if you add a type here, make sure it handles inheritence of metamethods itself // typically, set the metamethod not for the parent type but just after inheritence - ( !strcmp(method_name,"__associated_object")&& dt_lua_typeisa_type(L,type_id,luaA_type_find(L,"dt_imageio_module_format_t"))) || - ( !strcmp(method_name,"__associated_object")&& dt_lua_typeisa_type(L,type_id,luaA_type_find(L,"dt_imageio_module_storage_t"))) || - ( !strcmp(method_name,"__gc")&& dt_lua_typeisa_type(L,type_id,luaA_type_find(L,"dt_style_t"))) || - ( !strcmp(method_name,"__gc")&& dt_lua_typeisa_type(L,type_id,luaA_type_find(L,"dt_style_item_t"))) || - ( !strcmp(method_name,"__gc")&& dt_lua_typeisa_type(L,type_id,luaA_type_find(L,"lua_widget"))) || - ( !strcmp(method_name,"__call")&& dt_lua_typeisa_type(L,type_id,luaA_type_find(L,"lua_widget"))) || - ( !strcmp(method_name,"__gtk_signals")&& dt_lua_typeisa_type(L,type_id,luaA_type_find(L,"lua_widget"))) || - 0) { + (!strcmp(method_name, "__associated_object") + && dt_lua_typeisa_type(L, type_id, luaA_type_find(L, "dt_imageio_module_format_t"))) + || (!strcmp(method_name, "__associated_object") + && dt_lua_typeisa_type(L, type_id, luaA_type_find(L, "dt_imageio_module_storage_t"))) + || (!strcmp(method_name, "__gc") && dt_lua_typeisa_type(L, type_id, luaA_type_find(L, "dt_style_t"))) + || (!strcmp(method_name, "__gc") && dt_lua_typeisa_type(L, type_id, luaA_type_find(L, "dt_style_item_t"))) + || (!strcmp(method_name, "__gc") && dt_lua_typeisa_type(L, type_id, luaA_type_find(L, "lua_widget"))) + || (!strcmp(method_name, "__call") && dt_lua_typeisa_type(L, type_id, luaA_type_find(L, "lua_widget"))) + || (!strcmp(method_name, "__gtk_signals") + && dt_lua_typeisa_type(L, type_id, luaA_type_find(L, "lua_widget"))) || 0) + { // Nothign to be done - } else { - luaL_error(L,"metafield not handled :%s for type %s\n",method_name,luaA_typename(L,type_id)); + } + else + { + luaL_error(L, "metafield not handled :%s for type %s\n", method_name, luaA_typename(L, type_id)); } luaL_getmetatable(L, luaA_typename(L, type_id)); - lua_pushvalue(L,-2); + lua_pushvalue(L, -2); lua_setfield(L, -2, method_name); lua_pop(L, 2); // pop the metatable and the value } @@ -965,7 +977,7 @@ int dt_lua_init_early_types(lua_State *L) luaA_conversion(L, protected_double, push_protected_double, luaA_to_double); luaA_conversion(L, progress_double, push_progress_double, to_progress_double); - luaA_conversion_push_type(L, luaA_type_add(L,"unknown",sizeof(void*)), unknown_pushfunc); + luaA_conversion_push_type(L, luaA_type_add(L, "unknown", sizeof(void *)), unknown_pushfunc); // table of gpointer values lua_newtable(L); lua_newtable(L); @@ -975,9 +987,9 @@ int dt_lua_init_early_types(lua_State *L) lua_setfield(L, LUA_REGISTRYINDEX, "dt_lua_gpointer_values"); - luaA_enum(L,dt_lua_orientation_t); - luaA_enum_value_name(L,dt_lua_orientation_t,GTK_ORIENTATION_HORIZONTAL,"horizontal"); - luaA_enum_value_name(L,dt_lua_orientation_t,GTK_ORIENTATION_VERTICAL,"vertical"); + luaA_enum(L, dt_lua_orientation_t); + luaA_enum_value_name(L, dt_lua_orientation_t, GTK_ORIENTATION_HORIZONTAL, "horizontal"); + luaA_enum_value_name(L, dt_lua_orientation_t, GTK_ORIENTATION_VERTICAL, "vertical"); luaA_enum(L, dt_lua_align_t); luaA_enum_value_name(L, dt_lua_align_t, GTK_ALIGN_FILL, "fill"); diff --git a/src/lua/types.h b/src/lua/types.h index 9f53ff1a54a5..b4db4378bae2 100644 --- a/src/lua/types.h +++ b/src/lua/types.h @@ -40,8 +40,8 @@ typedef char *char_filename_length; typedef char *char_path_length; typedef const char *const_string; // string that has no push function typedef double protected_double; // like double, but NAN is mapped to nil -typedef double progress_double; // a double in [0.0,1.0] any value out of bound will be silently converted to - // the bound both at push and pull time +typedef double progress_double; // a double in [0.0,1.0] any value out of bound will be silently converted to + // the bound both at push and pull time // Types added to the lua type system and useable externally typedef GtkOrientation dt_lua_orientation_t; @@ -78,28 +78,27 @@ luaA_Type dt_lua_init_type_type(lua_State *L, luaA_Type type_id); /* MEMBER REGISTRATION FUNCTIONS */ /*********************************/ /// register a read-only member, the member function is poped from the stack -#define dt_lua_type_register_const(L, type_name, name) \ +#define dt_lua_type_register_const(L, type_name, name) \ dt_lua_type_register_const_type(L, luaA_type_find(L, #type_name), name) void dt_lua_type_register_const_type(lua_State *L, luaA_Type type_id, const char *name); /// register a read-write member, the member function is poped from the stack -#define dt_lua_type_register(L, type_name, name) \ - dt_lua_type_register_type(L, luaA_type_find(L, #type_name), name) +#define dt_lua_type_register(L, type_name, name) dt_lua_type_register_type(L, luaA_type_find(L, #type_name), name) void dt_lua_type_register_type(lua_State *L, luaA_Type type_id, const char *name); /// register a function for all fields of luaautoc struct, the member function is poped from the stack /// detects red-only vs read-write automatically -#define dt_lua_type_register_struct(L, type_name) \ +#define dt_lua_type_register_struct(L, type_name) \ dt_lua_type_register_struct_type(L, luaA_type_find(L, #type_name)) void dt_lua_type_register_struct_type(lua_State *L, luaA_Type type_id); // register a function for number index // first push the len function (can be nil) // then push the member function -#define dt_lua_type_register_number(L, type_name) \ +#define dt_lua_type_register_number(L, type_name) \ dt_lua_type_register_number_type(L, luaA_type_find(L, #type_name)) void dt_lua_type_register_number_type(lua_State *L, luaA_Type type_id); -#define dt_lua_type_register_number_const(L, type_name) \ +#define dt_lua_type_register_number_const(L, type_name) \ dt_lua_type_register_number_const_type(L, luaA_type_find(L, #type_name)) void dt_lua_type_register_number_const_type(lua_State *L, luaA_Type type_id); @@ -107,7 +106,7 @@ void dt_lua_type_register_number_const_type(lua_State *L, luaA_Type type_id); /// the type will reuse all members and metafiels from the parent (unless it has its own) /// inheritence will be marked in __luaA_ParentMetatable /// THIS FUNCTION MUST BE CALLED AFTER PARENT WAS COMPLETELY DEFINED -#define dt_lua_type_register_parent(L, type_name, parent_type_name) \ +#define dt_lua_type_register_parent(L, type_name, parent_type_name) \ dt_lua_type_register_parent_type(L, luaA_type_find(L, #type_name), luaA_type_find(L, #parent_type_name)) void dt_lua_type_register_parent_type(lua_State *L, luaA_Type type_id, luaA_Type parent_type_id); @@ -136,12 +135,12 @@ luaA_Type dt_lua_init_int_type_type(lua_State *L, luaA_Type type_id); luaA_Type dt_lua_init_gpointer_type_type(lua_State *L, luaA_Type type_id); /** - * make a pointer an alias of another pointer. Both pointers will push the same lua object + * make a pointer an alias of another pointer. Both pointers will push the same lua object * when pushed on the stack. The object contains the original pointer */ -#define dt_lua_type_gpointer_alias(L,type_name,pointer,alias) \ - dt_lua_type_gpointer_alias_type(L,luaA_type(L,type_name),pointer,alias) -void dt_lua_type_gpointer_alias_type(lua_State*L,luaA_Type type_id,void* pointer,void* alias); +#define dt_lua_type_gpointer_alias(L, type_name, pointer, alias) \ + dt_lua_type_gpointer_alias_type(L, luaA_type(L, type_name), pointer, alias) +void dt_lua_type_gpointer_alias_type(lua_State *L, luaA_Type type_id, void *pointer, void *alias); /** @@ -151,7 +150,7 @@ void dt_lua_type_gpointer_alias_type(lua_State*L,luaA_Type type_id,void* pointer * luaA_to will also raise an error * NOTE : if the object had aliases, the aliases will return NULL too. */ -void dt_lua_type_gpointer_drop(lua_State*L, void* pointer); +void dt_lua_type_gpointer_drop(lua_State *L, void *pointer); /** * similar to dt_lua_init_type but creates a singleton type @@ -175,8 +174,9 @@ luaA_Type dt_lua_init_wrapped_singleton(lua_State *L, lua_CFunction pusher, lua_ gboolean dt_lua_isa_type(lua_State *L, int index, luaA_Type type_id); gboolean dt_lua_typeisa_type(lua_State *L, luaA_Type obj_type, luaA_Type type_id); -#define dt_lua_type_setmetafield(L,type_name,name) dt_lua_type_setmetafield_type(L,luaA_type(L,type_name),name) -void dt_lua_type_setmetafield_type(lua_State*L,luaA_Type type,const char* method_name); +#define dt_lua_type_setmetafield(L, type_name, name) \ + dt_lua_type_setmetafield_type(L, luaA_type(L, type_name), name) +void dt_lua_type_setmetafield_type(lua_State *L, luaA_Type type, const char *method_name); int dt_lua_init_early_types(lua_State *L); diff --git a/src/lua/view.c b/src/lua/view.c index 627347cd5527..1299c01eda93 100644 --- a/src/lua/view.c +++ b/src/lua/view.c @@ -49,18 +49,15 @@ void dt_lua_register_view(lua_State *L, dt_view_t *module) int my_type = dt_lua_module_entry_get_type(L, "view", module->module_name); dt_lua_type_register_parent_type(L, my_type, luaA_type_find(L, "dt_lua_view_t")); lua_pushcfunction(L, view_tostring); - dt_lua_type_setmetafield_type(L,my_type,"__tostring"); + dt_lua_type_setmetafield_type(L, my_type, "__tostring"); }; static void on_view_changed(gpointer instance, dt_view_t *old_view, dt_view_t *new_view, gpointer user_data) { - dt_lua_async_call_alien(dt_lua_event_trigger_wrapper, - 0,NULL,NULL, - LUA_ASYNC_TYPENAME,"const char*","view-changed", - LUA_ASYNC_TYPENAME,"unknown",old_view, - LUA_ASYNC_TYPENAME,"unknown",new_view, - LUA_ASYNC_DONE); + dt_lua_async_call_alien(dt_lua_event_trigger_wrapper, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "const char*", + "view-changed", LUA_ASYNC_TYPENAME, "unknown", old_view, LUA_ASYNC_TYPENAME, "unknown", + new_view, LUA_ASYNC_DONE); } int dt_lua_init_early_view(lua_State *L) @@ -82,8 +79,8 @@ int dt_lua_init_view(lua_State *L) lua_pushcfunction(L, dt_lua_event_multiinstance_register); lua_pushcfunction(L, dt_lua_event_multiinstance_trigger); dt_lua_event_add(L, "view-changed"); - dt_control_signal_connect(darktable.signals, DT_SIGNAL_VIEWMANAGER_VIEW_CHANGED, - G_CALLBACK(on_view_changed), NULL); + dt_control_signal_connect(darktable.signals, DT_SIGNAL_VIEWMANAGER_VIEW_CHANGED, G_CALLBACK(on_view_changed), + NULL); return 0; } // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh diff --git a/src/lua/view.h b/src/lua/view.h index c1ef370d1d33..b43e52c19bdc 100644 --- a/src/lua/view.h +++ b/src/lua/view.h @@ -24,7 +24,7 @@ struct dt_view_t; -typedef struct dt_view_t* dt_lua_view_t; +typedef struct dt_view_t *dt_lua_view_t; void dt_lua_register_view(lua_State *L, struct dt_view_t *self); diff --git a/src/lua/widget/box.c b/src/lua/widget/box.c index 5a0f8f6c3fd5..2136015c3891 100644 --- a/src/lua/widget/box.c +++ b/src/lua/widget/box.c @@ -20,20 +20,18 @@ #include "lua/types.h" #include "lua/widget/common.h" -static void box_init(lua_State* L); -static dt_lua_widget_type_t box_type = { - .name = "box", - .gui_init = box_init, - .gui_cleanup = NULL, - .alloc_size = sizeof(dt_lua_container_t), - .parent= &container_type -}; +static void box_init(lua_State *L); +static dt_lua_widget_type_t box_type = {.name = "box", + .gui_init = box_init, + .gui_cleanup = NULL, + .alloc_size = sizeof(dt_lua_container_t), + .parent = &container_type }; -static void box_init(lua_State* L) +static void box_init(lua_State *L) { lua_box box; - luaA_to(L,lua_box,&box,-1); - gtk_orientable_set_orientation(GTK_ORIENTABLE(box->widget),GTK_ORIENTATION_VERTICAL); + luaA_to(L, lua_box, &box, -1); + gtk_orientable_set_orientation(GTK_ORIENTABLE(box->widget), GTK_ORIENTATION_VERTICAL); gtk_box_set_spacing(GTK_BOX(box->widget), DT_PIXEL_APPLY_DPI(5)); } @@ -41,23 +39,24 @@ static void box_init(lua_State* L) static int orientation_member(lua_State *L) { lua_box box; - luaA_to(L,lua_box,&box,1); + luaA_to(L, lua_box, &box, 1); dt_lua_orientation_t orientation; - if(lua_gettop(L) > 2) { - luaA_to(L,dt_lua_orientation_t,&orientation,3); - gtk_orientable_set_orientation(GTK_ORIENTABLE(box->widget),orientation); + if(lua_gettop(L) > 2) + { + luaA_to(L, dt_lua_orientation_t, &orientation, 3); + gtk_orientable_set_orientation(GTK_ORIENTABLE(box->widget), orientation); return 0; } orientation = gtk_orientable_get_orientation(GTK_ORIENTABLE(box->widget)); - luaA_push(L,dt_lua_orientation_t,&orientation); + luaA_push(L, dt_lua_orientation_t, &orientation); return 1; } -int dt_lua_init_widget_box(lua_State* L) +int dt_lua_init_widget_box(lua_State *L) { - dt_lua_init_widget_type(L,&box_type,lua_box,GTK_TYPE_BOX); + dt_lua_init_widget_type(L, &box_type, lua_box, GTK_TYPE_BOX); - lua_pushcfunction(L,orientation_member); + lua_pushcfunction(L, orientation_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_box, "orientation"); return 0; diff --git a/src/lua/widget/button.c b/src/lua/widget/button.c index 1cb9f6301001..e70aa54b87e4 100644 --- a/src/lua/widget/button.c +++ b/src/lua/widget/button.c @@ -18,36 +18,31 @@ #include "lua/types.h" #include "lua/widget/common.h" -static dt_lua_widget_type_t button_type = { - .name = "button", - .gui_init = NULL, - .gui_cleanup = NULL, - .alloc_size = sizeof(dt_lua_widget_t), - .parent= &widget_type -}; +static dt_lua_widget_type_t button_type = {.name = "button", + .gui_init = NULL, + .gui_cleanup = NULL, + .alloc_size = sizeof(dt_lua_widget_t), + .parent = &widget_type }; static void clicked_callback(GtkButton *widget, gpointer user_data) { - dt_lua_async_call_alien(dt_lua_widget_trigger_callback, - 0,NULL,NULL, - LUA_ASYNC_TYPENAME,"lua_widget",user_data, - LUA_ASYNC_TYPENAME,"const char*","clicked", - LUA_ASYNC_DONE); + dt_lua_async_call_alien(dt_lua_widget_trigger_callback, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "lua_widget", + user_data, LUA_ASYNC_TYPENAME, "const char*", "clicked", LUA_ASYNC_DONE); } - static int label_member(lua_State *L) { lua_button button; - luaA_to(L,lua_button,&button,1); - if(lua_gettop(L) > 2) { - const char * label = luaL_checkstring(L,3); - gtk_button_set_label(GTK_BUTTON(button->widget),label); + luaA_to(L, lua_button, &button, 1); + if(lua_gettop(L) > 2) + { + const char *label = luaL_checkstring(L, 3); + gtk_button_set_label(GTK_BUTTON(button->widget), label); return 0; } - lua_pushstring(L,gtk_button_get_label(GTK_BUTTON(button->widget))); + lua_pushstring(L, gtk_button_get_label(GTK_BUTTON(button->widget))); return 1; } @@ -62,17 +57,17 @@ static int tostring_member(lua_State *L) return 1; } -int dt_lua_init_widget_button(lua_State* L) +int dt_lua_init_widget_button(lua_State *L) { - dt_lua_init_widget_type(L,&button_type,lua_button,GTK_TYPE_BUTTON); + dt_lua_init_widget_type(L, &button_type, lua_button, GTK_TYPE_BUTTON); lua_pushcfunction(L, tostring_member); dt_lua_gtk_wrap(L); dt_lua_type_setmetafield(L, lua_button, "__tostring"); - lua_pushcfunction(L,label_member); + lua_pushcfunction(L, label_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_button, "label"); - dt_lua_widget_register_gtk_callback(L,lua_button,"clicked","clicked_callback",G_CALLBACK(clicked_callback)); + dt_lua_widget_register_gtk_callback(L, lua_button, "clicked", "clicked_callback", G_CALLBACK(clicked_callback)); return 0; } diff --git a/src/lua/widget/check_button.c b/src/lua/widget/check_button.c index 66022af40ade..3313cb73072b 100644 --- a/src/lua/widget/check_button.c +++ b/src/lua/widget/check_button.c @@ -18,47 +18,44 @@ #include "lua/types.h" #include "lua/widget/common.h" -static dt_lua_widget_type_t check_button_type = { - .name = "check_button", - .gui_init = NULL, - .gui_cleanup = NULL, - .alloc_size = sizeof(dt_lua_widget_t), - .parent= &widget_type -}; +static dt_lua_widget_type_t check_button_type = {.name = "check_button", + .gui_init = NULL, + .gui_cleanup = NULL, + .alloc_size = sizeof(dt_lua_widget_t), + .parent = &widget_type }; static void clicked_callback(GtkButton *widget, gpointer user_data) { - dt_lua_async_call_alien(dt_lua_widget_trigger_callback, - 0,NULL,NULL, - LUA_ASYNC_TYPENAME,"lua_widget",user_data, - LUA_ASYNC_TYPENAME,"const char*","clicked", - LUA_ASYNC_DONE); + dt_lua_async_call_alien(dt_lua_widget_trigger_callback, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "lua_widget", + user_data, LUA_ASYNC_TYPENAME, "const char*", "clicked", LUA_ASYNC_DONE); } static int label_member(lua_State *L) { lua_check_button check_button; - luaA_to(L,lua_check_button,&check_button,1); - if(lua_gettop(L) > 2) { - const char * label = luaL_checkstring(L,3); - gtk_button_set_label(GTK_BUTTON(check_button->widget),label); + luaA_to(L, lua_check_button, &check_button, 1); + if(lua_gettop(L) > 2) + { + const char *label = luaL_checkstring(L, 3); + gtk_button_set_label(GTK_BUTTON(check_button->widget), label); return 0; } - lua_pushstring(L,gtk_button_get_label(GTK_BUTTON(check_button->widget))); + lua_pushstring(L, gtk_button_get_label(GTK_BUTTON(check_button->widget))); return 1; } static int value_member(lua_State *L) { lua_check_button check_button; - luaA_to(L,lua_check_button,&check_button,1); - if(lua_gettop(L) > 2) { - luaL_checktype(L,3,LUA_TBOOLEAN); - gboolean value = lua_toboolean(L,3); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_button->widget),value); + luaA_to(L, lua_check_button, &check_button, 1); + if(lua_gettop(L) > 2) + { + luaL_checktype(L, 3, LUA_TBOOLEAN); + gboolean value = lua_toboolean(L, 3); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_button->widget), value); return 0; } - lua_pushboolean(L,gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_button->widget))); + lua_pushboolean(L, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_button->widget))); return 1; } @@ -73,20 +70,21 @@ static int tostring_member(lua_State *L) return 1; } -int dt_lua_init_widget_check_button(lua_State* L) +int dt_lua_init_widget_check_button(lua_State *L) { - dt_lua_init_widget_type(L,&check_button_type,lua_check_button,GTK_TYPE_CHECK_BUTTON); + dt_lua_init_widget_type(L, &check_button_type, lua_check_button, GTK_TYPE_CHECK_BUTTON); lua_pushcfunction(L, tostring_member); dt_lua_gtk_wrap(L); dt_lua_type_setmetafield(L, lua_check_button, "__tostring"); - lua_pushcfunction(L,value_member); + lua_pushcfunction(L, value_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_check_button, "value"); - lua_pushcfunction(L,label_member); + lua_pushcfunction(L, label_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_check_button, "label"); - dt_lua_widget_register_gtk_callback(L,lua_check_button,"clicked","clicked_callback",G_CALLBACK(clicked_callback)); + dt_lua_widget_register_gtk_callback(L, lua_check_button, "clicked", "clicked_callback", + G_CALLBACK(clicked_callback)); return 0; } diff --git a/src/lua/widget/combobox.c b/src/lua/widget/combobox.c index 6dfb25f55ad7..4d358b3bc475 100644 --- a/src/lua/widget/combobox.c +++ b/src/lua/widget/combobox.c @@ -21,146 +21,169 @@ #include "lua/widget/common.h" static void combobox_init(lua_State *L); -static dt_lua_widget_type_t combobox_type = { - .name = "combobox", - .gui_init = combobox_init, - .gui_cleanup = NULL, - .alloc_size = sizeof(dt_lua_widget_t), - .parent= &widget_type -}; +static dt_lua_widget_type_t combobox_type = {.name = "combobox", + .gui_init = combobox_init, + .gui_cleanup = NULL, + .alloc_size = sizeof(dt_lua_widget_t), + .parent = &widget_type }; -static void combobox_init(lua_State*L) +static void combobox_init(lua_State *L) { lua_combobox combobox; - luaA_to(L,lua_combobox,&combobox,-1); - dt_bauhaus_combobox_from_widget(DT_BAUHAUS_WIDGET(combobox->widget),NULL); - + luaA_to(L, lua_combobox, &combobox, -1); + dt_bauhaus_combobox_from_widget(DT_BAUHAUS_WIDGET(combobox->widget), NULL); } -static int combobox_len(lua_State*L) +static int combobox_len(lua_State *L) { lua_combobox combobox; - luaA_to(L,lua_combobox,&combobox,1); - lua_pushinteger(L,dt_bauhaus_combobox_length(combobox->widget)); + luaA_to(L, lua_combobox, &combobox, 1); + lua_pushinteger(L, dt_bauhaus_combobox_length(combobox->widget)); return 1; } -static int combobox_numindex(lua_State*L) +static int combobox_numindex(lua_State *L) { lua_combobox combobox; - luaA_to(L,lua_combobox,&combobox,1); - int key = lua_tointeger(L,2); + luaA_to(L, lua_combobox, &combobox, 1); + int key = lua_tointeger(L, 2); int length = dt_bauhaus_combobox_length(combobox->widget); - if(lua_gettop(L) > 2) { - if(key <= 0 || key > length +1) { - return luaL_error(L,"Invalid index for combobox : %d\n",key); - } else if(key == length +1) { - const char * string = luaL_checkstring(L,3); - dt_bauhaus_combobox_add(combobox->widget,string); - } else if(lua_isnil(L,3)){ - dt_bauhaus_combobox_remove_at(combobox->widget,key-1); - } else { - const char * string = luaL_checkstring(L,3); - dt_bauhaus_combobox_remove_at(combobox->widget,key-1); - dt_bauhaus_combobox_insert(combobox->widget,string,key-1); + if(lua_gettop(L) > 2) + { + if(key <= 0 || key > length + 1) + { + return luaL_error(L, "Invalid index for combobox : %d\n", key); + } + else if(key == length + 1) + { + const char *string = luaL_checkstring(L, 3); + dt_bauhaus_combobox_add(combobox->widget, string); + } + else if(lua_isnil(L, 3)) + { + dt_bauhaus_combobox_remove_at(combobox->widget, key - 1); + } + else + { + const char *string = luaL_checkstring(L, 3); + dt_bauhaus_combobox_remove_at(combobox->widget, key - 1); + dt_bauhaus_combobox_insert(combobox->widget, string, key - 1); } return 0; } - if(key <= 0 || key > length) { - return luaL_error(L,"Invalid index for combo box : %d\n",key); - } else if (key > length) { + if(key <= 0 || key > length) + { + return luaL_error(L, "Invalid index for combo box : %d\n", key); + } + else if(key > length) + { lua_pushnil(L); return 1; } const GList *labels = dt_bauhaus_combobox_get_labels(combobox->widget); - lua_pushstring(L,g_list_nth_data((GList*)labels,key-1)); + lua_pushstring(L, g_list_nth_data((GList *)labels, key - 1)); return 1; } static int label_member(lua_State *L) { lua_combobox combobox; - luaA_to(L,lua_combobox,&combobox,1); - if(lua_gettop(L) > 2) { + luaA_to(L, lua_combobox, &combobox, 1); + if(lua_gettop(L) > 2) + { char tmp[256]; - luaA_to(L,char_256,&tmp,3); - dt_bauhaus_widget_set_label(combobox->widget,NULL,tmp); + luaA_to(L, char_256, &tmp, 3); + dt_bauhaus_widget_set_label(combobox->widget, NULL, tmp); return 0; } - lua_pushstring(L,dt_bauhaus_widget_get_label(combobox->widget)); + lua_pushstring(L, dt_bauhaus_widget_get_label(combobox->widget)); return 1; } static int editable_member(lua_State *L) { lua_combobox combobox; - luaA_to(L,lua_combobox,&combobox,1); - if(lua_gettop(L) > 2) { - gboolean editable = lua_toboolean(L,3); - dt_bauhaus_combobox_set_editable(combobox->widget,editable); + luaA_to(L, lua_combobox, &combobox, 1); + if(lua_gettop(L) > 2) + { + gboolean editable = lua_toboolean(L, 3); + dt_bauhaus_combobox_set_editable(combobox->widget, editable); return 0; } - lua_pushboolean(L,dt_bauhaus_combobox_get_editable(combobox->widget)); + lua_pushboolean(L, dt_bauhaus_combobox_get_editable(combobox->widget)); return 1; } -static int value_member(lua_State*L) +static int value_member(lua_State *L) { lua_combobox combobox; - luaA_to(L,lua_combobox,&combobox,1); + luaA_to(L, lua_combobox, &combobox, 1); int length = dt_bauhaus_combobox_length(combobox->widget); - if(lua_gettop(L) > 2) { - if(lua_isnil(L,3)) { - dt_bauhaus_combobox_set(combobox->widget,-1); - } else if(lua_isnumber(L,3)) { - int index = lua_tointeger(L,3) ; - if(index < 1 || index > length) { - return luaL_error(L,"Invalid index for combo box : %d\n",index); + if(lua_gettop(L) > 2) + { + if(lua_isnil(L, 3)) + { + dt_bauhaus_combobox_set(combobox->widget, -1); + } + else if(lua_isnumber(L, 3)) + { + int index = lua_tointeger(L, 3); + if(index < 1 || index > length) + { + return luaL_error(L, "Invalid index for combo box : %d\n", index); } - dt_bauhaus_combobox_set(combobox->widget,index -1); - } else if(lua_isstring(L,3)&& dt_bauhaus_combobox_get_editable(combobox->widget)) { - const char * string = lua_tostring(L,3); - dt_bauhaus_combobox_set_text(combobox->widget,string); - } else { - return luaL_error(L,"Invalid type for combo box value\n"); + dt_bauhaus_combobox_set(combobox->widget, index - 1); + } + else if(lua_isstring(L, 3) && dt_bauhaus_combobox_get_editable(combobox->widget)) + { + const char *string = lua_tostring(L, 3); + dt_bauhaus_combobox_set_text(combobox->widget, string); + } + else + { + return luaL_error(L, "Invalid type for combo box value\n"); } return 0; } - lua_pushstring(L,dt_bauhaus_combobox_get_text(combobox->widget)); + lua_pushstring(L, dt_bauhaus_combobox_get_text(combobox->widget)); return 1; } -static int selected_member(lua_State*L) +static int selected_member(lua_State *L) { lua_combobox combobox; - luaA_to(L,lua_combobox,&combobox,1); + luaA_to(L, lua_combobox, &combobox, 1); int length = dt_bauhaus_combobox_length(combobox->widget); - if(lua_gettop(L) > 2) { - if(lua_isnil(L,3)) { - dt_bauhaus_combobox_set(combobox->widget,-1); - } else if(lua_isnumber(L,3)) { - int index = lua_tointeger(L,3) ; - if(index < 0 || index > length) { - return luaL_error(L,"Invalid index for combo box : %d\n",index); + if(lua_gettop(L) > 2) + { + if(lua_isnil(L, 3)) + { + dt_bauhaus_combobox_set(combobox->widget, -1); + } + else if(lua_isnumber(L, 3)) + { + int index = lua_tointeger(L, 3); + if(index < 0 || index > length) + { + return luaL_error(L, "Invalid index for combo box : %d\n", index); } - dt_bauhaus_combobox_set(combobox->widget,index -1); - } else { - return luaL_error(L,"Invalid type for combo box selected\n"); + dt_bauhaus_combobox_set(combobox->widget, index - 1); + } + else + { + return luaL_error(L, "Invalid type for combo box selected\n"); } return 0; } - lua_pushinteger(L,dt_bauhaus_combobox_get(combobox->widget) + 1); + lua_pushinteger(L, dt_bauhaus_combobox_get(combobox->widget) + 1); return 1; } static void changed_callback(GtkButton *widget, gpointer user_data) { - dt_lua_async_call_alien(dt_lua_widget_trigger_callback, - 0,NULL,NULL, - LUA_ASYNC_TYPENAME,"lua_widget",user_data, - LUA_ASYNC_TYPENAME,"const char*","value-changed", - LUA_ASYNC_DONE); + dt_lua_async_call_alien(dt_lua_widget_trigger_callback, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "lua_widget", + user_data, LUA_ASYNC_TYPENAME, "const char*", "value-changed", LUA_ASYNC_DONE); } static int tostring_member(lua_State *L) @@ -174,30 +197,31 @@ static int tostring_member(lua_State *L) return 1; } -int dt_lua_init_widget_combobox(lua_State* L) +int dt_lua_init_widget_combobox(lua_State *L) { - dt_lua_init_widget_type(L,&combobox_type,lua_combobox,DT_BAUHAUS_WIDGET_TYPE); + dt_lua_init_widget_type(L, &combobox_type, lua_combobox, DT_BAUHAUS_WIDGET_TYPE); lua_pushcfunction(L, tostring_member); dt_lua_gtk_wrap(L); dt_lua_type_setmetafield(L, lua_combobox, "__tostring"); - lua_pushcfunction(L,combobox_len); + lua_pushcfunction(L, combobox_len); dt_lua_gtk_wrap(L); - lua_pushcfunction(L,combobox_numindex); + lua_pushcfunction(L, combobox_numindex); dt_lua_gtk_wrap(L); - dt_lua_type_register_number(L,lua_combobox); - lua_pushcfunction(L,value_member); + dt_lua_type_register_number(L, lua_combobox); + lua_pushcfunction(L, value_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_combobox, "value"); - lua_pushcfunction(L,selected_member); + lua_pushcfunction(L, selected_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_combobox, "selected"); - dt_lua_widget_register_gtk_callback(L,lua_combobox,"value-changed","changed_callback",G_CALLBACK(changed_callback)); - lua_pushcfunction(L,label_member); + dt_lua_widget_register_gtk_callback(L, lua_combobox, "value-changed", "changed_callback", + G_CALLBACK(changed_callback)); + lua_pushcfunction(L, label_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_combobox, "label"); - lua_pushcfunction(L,editable_member); + lua_pushcfunction(L, editable_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_combobox, "editable"); diff --git a/src/lua/widget/common.h b/src/lua/widget/common.h index 0f4fc9d4d4df..69900d335171 100644 --- a/src/lua/widget/common.h +++ b/src/lua/widget/common.h @@ -21,39 +21,39 @@ #include "lua/widget/widget.h" -typedef dt_lua_widget_t* lua_separator; -typedef dt_lua_widget_t* lua_label; -typedef dt_lua_widget_t* lua_section_label; -typedef dt_lua_widget_t* lua_file_chooser_button; -typedef dt_lua_widget_t* lua_entry; -typedef dt_lua_widget_t* lua_combobox; -typedef dt_lua_widget_t* lua_check_button; -typedef dt_lua_widget_t* lua_button; -typedef dt_lua_widget_t* lua_slider; -typedef dt_lua_widget_t* lua_text_view; +typedef dt_lua_widget_t *lua_separator; +typedef dt_lua_widget_t *lua_label; +typedef dt_lua_widget_t *lua_section_label; +typedef dt_lua_widget_t *lua_file_chooser_button; +typedef dt_lua_widget_t *lua_entry; +typedef dt_lua_widget_t *lua_combobox; +typedef dt_lua_widget_t *lua_check_button; +typedef dt_lua_widget_t *lua_button; +typedef dt_lua_widget_t *lua_slider; +typedef dt_lua_widget_t *lua_text_view; // containers can be inherited extern dt_lua_widget_type_t container_type; typedef dt_lua_widget_t dt_lua_container_t; -typedef dt_lua_container_t* lua_container; -typedef dt_lua_container_t* lua_box; -typedef dt_lua_container_t* lua_stack; +typedef dt_lua_container_t *lua_container; +typedef dt_lua_container_t *lua_box; +typedef dt_lua_container_t *lua_stack; // Various functions to init various widget types -int dt_lua_init_widget_box(lua_State* L); -int dt_lua_init_widget_button(lua_State* L); -int dt_lua_init_widget_check_button(lua_State* L); -int dt_lua_init_widget_label(lua_State* L); -int dt_lua_init_widget_section_label(lua_State* L); -int dt_lua_init_widget_entry(lua_State* L); -int dt_lua_init_widget_file_chooser_button(lua_State* L); -int dt_lua_init_widget_separator(lua_State* L); -int dt_lua_init_widget_combobox(lua_State* L); -int dt_lua_init_widget_container(lua_State* L); -int dt_lua_init_widget_stack(lua_State* L); -int dt_lua_init_widget_slider(lua_State* L); -int dt_lua_init_widget_text_view(lua_State* L); +int dt_lua_init_widget_box(lua_State *L); +int dt_lua_init_widget_button(lua_State *L); +int dt_lua_init_widget_check_button(lua_State *L); +int dt_lua_init_widget_label(lua_State *L); +int dt_lua_init_widget_section_label(lua_State *L); +int dt_lua_init_widget_entry(lua_State *L); +int dt_lua_init_widget_file_chooser_button(lua_State *L); +int dt_lua_init_widget_separator(lua_State *L); +int dt_lua_init_widget_combobox(lua_State *L); +int dt_lua_init_widget_container(lua_State *L); +int dt_lua_init_widget_stack(lua_State *L); +int dt_lua_init_widget_slider(lua_State *L); +int dt_lua_init_widget_text_view(lua_State *L); // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh // vim: shiftwidth=2 expandtab tabstop=2 cindent diff --git a/src/lua/widget/container.c b/src/lua/widget/container.c index 5e553e4ada3c..3a9cf5cbd41a 100644 --- a/src/lua/widget/container.c +++ b/src/lua/widget/container.c @@ -19,64 +19,58 @@ #include "lua/types.h" #include "lua/widget/common.h" -static void container_init(lua_State* L); -static void container_cleanup(lua_State* L,lua_widget widget); -dt_lua_widget_type_t container_type = { - .name = "container", - .gui_init = container_init, - .gui_cleanup = container_cleanup, - .alloc_size = sizeof(dt_lua_container_t), - .parent= &widget_type -}; - -static int container_reset(lua_State* L) +static void container_init(lua_State *L); +static void container_cleanup(lua_State *L, lua_widget widget); +dt_lua_widget_type_t container_type = {.name = "container", + .gui_init = container_init, + .gui_cleanup = container_cleanup, + .alloc_size = sizeof(dt_lua_container_t), + .parent = &widget_type }; + +static int container_reset(lua_State *L) { lua_container container; - luaA_to(L,lua_container,&container,1); - lua_getuservalue(L,1); - GList*children = gtk_container_get_children(GTK_CONTAINER(container->widget)); - GList*curelt = children; - while(curelt) { - lua_pushcfunction(L,dt_lua_widget_trigger_callback); - GtkWidget* cur_widget = curelt->data; - luaA_push(L,lua_widget,&cur_widget); - lua_pushstring(L,"reset"); - lua_call(L,2,0); + luaA_to(L, lua_container, &container, 1); + lua_getuservalue(L, 1); + GList *children = gtk_container_get_children(GTK_CONTAINER(container->widget)); + GList *curelt = children; + while(curelt) + { + lua_pushcfunction(L, dt_lua_widget_trigger_callback); + GtkWidget *cur_widget = curelt->data; + luaA_push(L, lua_widget, &cur_widget); + lua_pushstring(L, "reset"); + lua_call(L, 2, 0); curelt = g_list_next(curelt); } - lua_pop(L,1); + lua_pop(L, 1); g_list_free(children); return 0; } -static void on_child_added(GtkContainer *container,GtkWidget *child,lua_container user_data) +static void on_child_added(GtkContainer *container, GtkWidget *child, lua_container user_data) { - dt_lua_async_call_alien(dt_lua_widget_trigger_callback, - 0,NULL,NULL, - LUA_ASYNC_TYPENAME,"lua_widget",user_data, - LUA_ASYNC_TYPENAME,"const char*","add", - LUA_ASYNC_TYPENAME,"lua_widget",child, - LUA_ASYNC_DONE); + dt_lua_async_call_alien(dt_lua_widget_trigger_callback, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "lua_widget", + user_data, LUA_ASYNC_TYPENAME, "const char*", "add", LUA_ASYNC_TYPENAME, "lua_widget", + child, LUA_ASYNC_DONE); } -static void on_child_removed(GtkContainer *container,GtkWidget *child,lua_container user_data) +static void on_child_removed(GtkContainer *container, GtkWidget *child, lua_container user_data) { - dt_lua_async_call_alien(dt_lua_widget_trigger_callback, - 0,NULL,NULL, - LUA_ASYNC_TYPENAME,"lua_widget",user_data, - LUA_ASYNC_TYPENAME,"const char*","remove", - LUA_ASYNC_TYPENAME,"lua_widget",child, - LUA_ASYNC_DONE); + dt_lua_async_call_alien(dt_lua_widget_trigger_callback, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "lua_widget", + user_data, LUA_ASYNC_TYPENAME, "const char*", "remove", LUA_ASYNC_TYPENAME, "lua_widget", + child, LUA_ASYNC_DONE); } -static void container_cleanup(lua_State* L,lua_widget widget) +static void container_cleanup(lua_State *L, lua_widget widget) { - GList * children = gtk_container_get_children(GTK_CONTAINER(widget->widget)); - GList * cur_child = children; + GList *children = gtk_container_get_children(GTK_CONTAINER(widget->widget)); + GList *cur_child = children; g_signal_handlers_disconnect_by_func(widget->widget, G_CALLBACK(on_child_removed), widget); - while(cur_child) { - gtk_container_remove(GTK_CONTAINER(widget->widget),GTK_WIDGET(cur_child->data)); + while(cur_child) + { + gtk_container_remove(GTK_CONTAINER(widget->widget), GTK_WIDGET(cur_child->data)); cur_child = g_list_next(cur_child); } g_list_free(children); @@ -86,97 +80,106 @@ static void container_cleanup(lua_State* L,lua_widget widget) static int child_added(lua_State *L) { lua_widget widget; - luaA_to(L, lua_widget,&widget,2); - lua_getuservalue(L,1); - luaA_push(L,lua_widget,&widget); - lua_pushvalue(L,2); - lua_settable(L,-3); + luaA_to(L, lua_widget, &widget, 2); + lua_getuservalue(L, 1); + luaA_push(L, lua_widget, &widget); + lua_pushvalue(L, 2); + lua_settable(L, -3); return 0; } static int child_removed(lua_State *L) { lua_widget widget; - luaA_to(L, lua_widget,&widget,2), - lua_getuservalue(L,1); - luaA_push(L,lua_widget,&widget); + luaA_to(L, lua_widget, &widget, 2), lua_getuservalue(L, 1); + luaA_push(L, lua_widget, &widget); lua_pushnil(L); - lua_settable(L,-3); + lua_settable(L, -3); return 0; } -static void container_init(lua_State* L) +static void container_init(lua_State *L) { lua_container container; - luaA_to(L,lua_container,&container,-1); - lua_pushcfunction(L,container_reset); - dt_lua_widget_set_callback(L,-2,"reset"); - lua_pushcfunction(L,child_added); - dt_lua_widget_set_callback(L,-2,"add"); - lua_pushcfunction(L,child_removed); - dt_lua_widget_set_callback(L,-2,"remove"); + luaA_to(L, lua_container, &container, -1); + lua_pushcfunction(L, container_reset); + dt_lua_widget_set_callback(L, -2, "reset"); + lua_pushcfunction(L, child_added); + dt_lua_widget_set_callback(L, -2, "add"); + lua_pushcfunction(L, child_removed); + dt_lua_widget_set_callback(L, -2, "remove"); g_signal_connect(container->widget, "add", G_CALLBACK(on_child_added), container); g_signal_connect(container->widget, "remove", G_CALLBACK(on_child_removed), container); } -static int container_len(lua_State*L) +static int container_len(lua_State *L) { lua_container container; - luaA_to(L,lua_container,&container,1); - GList * children = gtk_container_get_children(GTK_CONTAINER(container->widget)); - lua_pushinteger(L,g_list_length(children)); + luaA_to(L, lua_container, &container, 1); + GList *children = gtk_container_get_children(GTK_CONTAINER(container->widget)); + lua_pushinteger(L, g_list_length(children)); g_list_free(children); return 1; } -static int container_numindex(lua_State*L) +static int container_numindex(lua_State *L) { lua_container container; - luaA_to(L,lua_container,&container,1); - GList * children = gtk_container_get_children(GTK_CONTAINER(container->widget)); - int index = lua_tointeger(L,2) -1; - if(lua_gettop(L) >2) { + luaA_to(L, lua_container, &container, 1); + GList *children = gtk_container_get_children(GTK_CONTAINER(container->widget)); + int index = lua_tointeger(L, 2) - 1; + if(lua_gettop(L) > 2) + { int length = g_list_length(children); - if(!lua_isnil(L,3) && index == length) { + if(!lua_isnil(L, 3) && index == length) + { lua_widget widget; - luaA_to(L, lua_widget,&widget,3); - gtk_container_add(GTK_CONTAINER(container->widget),widget->widget); - // the following lines add the widget to the container's user_value to guarentee it's referenced on the lua side - // they should be done by child_added, but + luaA_to(L, lua_widget, &widget, 3); + gtk_container_add(GTK_CONTAINER(container->widget), widget->widget); + // the following lines add the widget to the container's user_value to guarentee it's referenced on the lua + // side + // they should be done by child_added, but // there can be a race with lua's GC, so do it now. // child_added doing it a second time is harmless - lua_getuservalue(L,1); - luaA_push(L,lua_widget,&widget); - lua_pushvalue(L,3); - lua_settable(L,-3); - lua_pop(L,1); - } else if(lua_isnil(L,3) && index < length) { - GtkWidget *searched_widget = g_list_nth_data(children,index); - gtk_container_remove(GTK_CONTAINER(container->widget),searched_widget); - } else { - luaL_error(L,"Incorrect index or value when setting the child of a container : you can only append, not change a child in the middle"); + lua_getuservalue(L, 1); + luaA_push(L, lua_widget, &widget); + lua_pushvalue(L, 3); + lua_settable(L, -3); + lua_pop(L, 1); + } + else if(lua_isnil(L, 3) && index < length) + { + GtkWidget *searched_widget = g_list_nth_data(children, index); + gtk_container_remove(GTK_CONTAINER(container->widget), searched_widget); + } + else + { + luaL_error(L, "Incorrect index or value when setting the child of a container : you can only append, not " + "change a child in the middle"); } g_list_free(children); return 0; - } else { - GtkWidget *searched_widget = g_list_nth_data(children,index); + } + else + { + GtkWidget *searched_widget = g_list_nth_data(children, index); g_list_free(children); - lua_getuservalue(L,1); - lua_pushlightuserdata(L,searched_widget); - lua_gettable(L,-2); + lua_getuservalue(L, 1); + lua_pushlightuserdata(L, searched_widget); + lua_gettable(L, -2); return 1; } } -int dt_lua_init_widget_container(lua_State* L) +int dt_lua_init_widget_container(lua_State *L) { - dt_lua_init_widget_type(L,&container_type,lua_container,GTK_TYPE_CONTAINER); + dt_lua_init_widget_type(L, &container_type, lua_container, GTK_TYPE_CONTAINER); - lua_pushcfunction(L,container_len); + lua_pushcfunction(L, container_len); dt_lua_gtk_wrap(L); - lua_pushcfunction(L,container_numindex); + lua_pushcfunction(L, container_numindex); dt_lua_gtk_wrap(L); - dt_lua_type_register_number(L,lua_container); + dt_lua_type_register_number(L, lua_container); return 0; } diff --git a/src/lua/widget/entry.c b/src/lua/widget/entry.c index dcc011ea91dc..4acfac868f9d 100644 --- a/src/lua/widget/entry.c +++ b/src/lua/widget/entry.c @@ -19,25 +19,23 @@ #include "lua/types.h" #include "lua/widget/common.h" -static void entry_init(lua_State* L); -static void entry_cleanup(lua_State* L,lua_widget widget); -static dt_lua_widget_type_t entry_type = { - .name = "entry", - .gui_init = entry_init, - .gui_cleanup = entry_cleanup, - .alloc_size = sizeof(dt_lua_widget_t), - .parent= &widget_type -}; - - -static void entry_init(lua_State* L) +static void entry_init(lua_State *L); +static void entry_cleanup(lua_State *L, lua_widget widget); +static dt_lua_widget_type_t entry_type = {.name = "entry", + .gui_init = entry_init, + .gui_cleanup = entry_cleanup, + .alloc_size = sizeof(dt_lua_widget_t), + .parent = &widget_type }; + + +static void entry_init(lua_State *L) { lua_entry entry; - luaA_to(L,lua_entry,&entry,1); + luaA_to(L, lua_entry, &entry, 1); dt_gui_key_accel_block_on_focus_connect(GTK_WIDGET(entry->widget)); } -static void entry_cleanup(lua_State* L,lua_widget widget) +static void entry_cleanup(lua_State *L, lua_widget widget) { dt_gui_key_accel_block_on_focus_disconnect(widget->widget); } @@ -46,54 +44,58 @@ static void entry_cleanup(lua_State* L,lua_widget widget) static int text_member(lua_State *L) { lua_entry entry; - luaA_to(L,lua_entry,&entry,1); - if(lua_gettop(L) > 2) { - const char * text = luaL_checkstring(L,3); - gtk_entry_set_text(GTK_ENTRY(entry->widget),text); + luaA_to(L, lua_entry, &entry, 1); + if(lua_gettop(L) > 2) + { + const char *text = luaL_checkstring(L, 3); + gtk_entry_set_text(GTK_ENTRY(entry->widget), text); return 0; } - lua_pushstring(L,gtk_entry_get_text(GTK_ENTRY(entry->widget))); + lua_pushstring(L, gtk_entry_get_text(GTK_ENTRY(entry->widget))); return 1; } static int is_password_member(lua_State *L) { lua_entry entry; - luaA_to(L,lua_entry,&entry,1); - if(lua_gettop(L) > 2) { - const gboolean visibility = lua_toboolean(L,3); - gtk_entry_set_visibility(GTK_ENTRY(entry->widget),visibility); + luaA_to(L, lua_entry, &entry, 1); + if(lua_gettop(L) > 2) + { + const gboolean visibility = lua_toboolean(L, 3); + gtk_entry_set_visibility(GTK_ENTRY(entry->widget), visibility); return 0; } - lua_pushboolean(L,gtk_entry_get_visibility(GTK_ENTRY(entry->widget))); + lua_pushboolean(L, gtk_entry_get_visibility(GTK_ENTRY(entry->widget))); return 1; } static int placeholder_member(lua_State *L) { lua_entry entry; - luaA_to(L,lua_entry,&entry,1); - if(lua_gettop(L) > 2) { - const char * placeholder = luaL_checkstring(L,3); - gtk_entry_set_placeholder_text(GTK_ENTRY(entry->widget),placeholder); + luaA_to(L, lua_entry, &entry, 1); + if(lua_gettop(L) > 2) + { + const char *placeholder = luaL_checkstring(L, 3); + gtk_entry_set_placeholder_text(GTK_ENTRY(entry->widget), placeholder); return 0; } - lua_pushstring(L,gtk_entry_get_placeholder_text(GTK_ENTRY(entry->widget))); + lua_pushstring(L, gtk_entry_get_placeholder_text(GTK_ENTRY(entry->widget))); return 1; } static int editable_member(lua_State *L) { lua_entry entry; - luaA_to(L,lua_entry,&entry,1); + luaA_to(L, lua_entry, &entry, 1); gboolean editable; - if(lua_gettop(L) > 2) { - editable = lua_toboolean(L,3); + if(lua_gettop(L) > 2) + { + editable = lua_toboolean(L, 3); g_object_set(G_OBJECT(entry->widget), "editable", editable, (gchar *)0); return 0; } - g_object_get(G_OBJECT(entry->widget),"editable",&editable,NULL); - lua_pushboolean(L,editable); + g_object_get(G_OBJECT(entry->widget), "editable", &editable, NULL); + lua_pushboolean(L, editable); return 1; } @@ -108,27 +110,27 @@ static int tostring_member(lua_State *L) return 1; } -int dt_lua_init_widget_entry(lua_State* L) +int dt_lua_init_widget_entry(lua_State *L) { - dt_lua_init_widget_type(L,&entry_type,lua_entry,GTK_TYPE_ENTRY); + dt_lua_init_widget_type(L, &entry_type, lua_entry, GTK_TYPE_ENTRY); lua_pushcfunction(L, tostring_member); dt_lua_gtk_wrap(L); dt_lua_type_setmetafield(L, lua_entry, "__tostring"); - lua_pushcfunction(L,text_member); + lua_pushcfunction(L, text_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_entry, "text"); - lua_pushcfunction(L,is_password_member); + lua_pushcfunction(L, is_password_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_entry, "is_password"); - lua_pushcfunction(L,placeholder_member); + lua_pushcfunction(L, placeholder_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_entry, "placeholder"); - lua_pushcfunction(L,editable_member); + lua_pushcfunction(L, editable_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_entry, "editable"); diff --git a/src/lua/widget/file_chooser.c b/src/lua/widget/file_chooser.c index 52164d97c23e..0a39dcceadf4 100644 --- a/src/lua/widget/file_chooser.c +++ b/src/lua/widget/file_chooser.c @@ -19,60 +19,61 @@ #include "lua/types.h" #include "lua/widget/common.h" -static dt_lua_widget_type_t file_chooser_button_type = { - .name = "file_chooser_button", - .gui_init = NULL, - .gui_cleanup = NULL, - .alloc_size = sizeof(dt_lua_widget_t), - .parent= &widget_type -}; +static dt_lua_widget_type_t file_chooser_button_type = {.name = "file_chooser_button", + .gui_init = NULL, + .gui_cleanup = NULL, + .alloc_size = sizeof(dt_lua_widget_t), + .parent = &widget_type }; static void file_set_callback(GtkButton *widget, gpointer user_data) { - dt_lua_async_call_alien(dt_lua_widget_trigger_callback, - 0,NULL,NULL, - LUA_ASYNC_TYPENAME,"lua_widget",user_data, - LUA_ASYNC_TYPENAME,"const char*","file-set", - LUA_ASYNC_DONE); + dt_lua_async_call_alien(dt_lua_widget_trigger_callback, 0, NULL, NULL, LUA_ASYNC_TYPENAME, "lua_widget", + user_data, LUA_ASYNC_TYPENAME, "const char*", "file-set", LUA_ASYNC_DONE); } static int is_directory_member(lua_State *L) { lua_file_chooser_button file_chooser_button; - luaA_to(L,lua_file_chooser_button,&file_chooser_button,1); - if(lua_gettop(L) > 2) { - const gboolean is_directory = lua_toboolean(L,3); - gtk_file_chooser_set_action(GTK_FILE_CHOOSER(file_chooser_button->widget),is_directory?GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:GTK_FILE_CHOOSER_ACTION_OPEN); + luaA_to(L, lua_file_chooser_button, &file_chooser_button, 1); + if(lua_gettop(L) > 2) + { + const gboolean is_directory = lua_toboolean(L, 3); + gtk_file_chooser_set_action(GTK_FILE_CHOOSER(file_chooser_button->widget), + is_directory ? GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER + : GTK_FILE_CHOOSER_ACTION_OPEN); return 0; } - lua_pushboolean(L,gtk_file_chooser_get_action(GTK_FILE_CHOOSER(file_chooser_button->widget)) == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); + lua_pushboolean(L, gtk_file_chooser_get_action(GTK_FILE_CHOOSER(file_chooser_button->widget)) + == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); return 1; } static int title_member(lua_State *L) { lua_file_chooser_button file_chooser_button; - luaA_to(L,lua_file_chooser_button,&file_chooser_button,1); - if(lua_gettop(L) > 2) { - const char * title = luaL_checkstring(L,3); - gtk_file_chooser_button_set_title(GTK_FILE_CHOOSER_BUTTON(file_chooser_button->widget),title); + luaA_to(L, lua_file_chooser_button, &file_chooser_button, 1); + if(lua_gettop(L) > 2) + { + const char *title = luaL_checkstring(L, 3); + gtk_file_chooser_button_set_title(GTK_FILE_CHOOSER_BUTTON(file_chooser_button->widget), title); return 0; } - lua_pushstring(L,gtk_file_chooser_button_get_title(GTK_FILE_CHOOSER_BUTTON(file_chooser_button->widget))); + lua_pushstring(L, gtk_file_chooser_button_get_title(GTK_FILE_CHOOSER_BUTTON(file_chooser_button->widget))); return 1; } static int value_member(lua_State *L) { lua_file_chooser_button file_chooser_button; - luaA_to(L,lua_file_chooser_button,&file_chooser_button,1); - if(lua_gettop(L) > 2) { - const char * value = luaL_checkstring(L,3); - gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(file_chooser_button->widget),value); + luaA_to(L, lua_file_chooser_button, &file_chooser_button, 1); + if(lua_gettop(L) > 2) + { + const char *value = luaL_checkstring(L, 3); + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(file_chooser_button->widget), value); return 0; } - lua_pushstring(L,gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(file_chooser_button->widget))); + lua_pushstring(L, gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(file_chooser_button->widget))); return 1; } @@ -87,27 +88,28 @@ static int tostring_member(lua_State *L) return 1; } -int dt_lua_init_widget_file_chooser_button(lua_State* L) +int dt_lua_init_widget_file_chooser_button(lua_State *L) { - dt_lua_init_widget_type(L,&file_chooser_button_type,lua_file_chooser_button,GTK_TYPE_FILE_CHOOSER_BUTTON); + dt_lua_init_widget_type(L, &file_chooser_button_type, lua_file_chooser_button, GTK_TYPE_FILE_CHOOSER_BUTTON); lua_pushcfunction(L, tostring_member); dt_lua_gtk_wrap(L); dt_lua_type_setmetafield(L, lua_file_chooser_button, "__tostring"); - lua_pushcfunction(L,title_member); + lua_pushcfunction(L, title_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_file_chooser_button, "title"); - lua_pushcfunction(L,is_directory_member); + lua_pushcfunction(L, is_directory_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_file_chooser_button, "is_directory"); - lua_pushcfunction(L,value_member); + lua_pushcfunction(L, value_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_file_chooser_button, "value"); - dt_lua_widget_register_gtk_callback(L,lua_file_chooser_button,"file-set","changed_callback",G_CALLBACK(file_set_callback)); + dt_lua_widget_register_gtk_callback(L, lua_file_chooser_button, "file-set", "changed_callback", + G_CALLBACK(file_set_callback)); return 0; } diff --git a/src/lua/widget/label.c b/src/lua/widget/label.c index cb9f884798d9..f692dfb1cfef 100644 --- a/src/lua/widget/label.c +++ b/src/lua/widget/label.c @@ -19,38 +19,38 @@ #include "lua/types.h" #include "lua/widget/common.h" -static dt_lua_widget_type_t label_type = { - .name = "label", - .gui_init = NULL, - .gui_cleanup = NULL, - .alloc_size = sizeof(dt_lua_widget_t), - .parent= &widget_type -}; +static dt_lua_widget_type_t label_type = {.name = "label", + .gui_init = NULL, + .gui_cleanup = NULL, + .alloc_size = sizeof(dt_lua_widget_t), + .parent = &widget_type }; static int label_member(lua_State *L) { lua_label label; - luaA_to(L,lua_label,&label,1); - if(lua_gettop(L) > 2) { - const char * text = luaL_checkstring(L,3); - gtk_label_set_text(GTK_LABEL(label->widget),text); + luaA_to(L, lua_label, &label, 1); + if(lua_gettop(L) > 2) + { + const char *text = luaL_checkstring(L, 3); + gtk_label_set_text(GTK_LABEL(label->widget), text); return 0; } - lua_pushstring(L,gtk_label_get_text(GTK_LABEL(label->widget))); + lua_pushstring(L, gtk_label_get_text(GTK_LABEL(label->widget))); return 1; } static int selectable_member(lua_State *L) { lua_label label; - luaA_to(L,lua_label,&label,1); - if(lua_gettop(L) > 2) { - gboolean selectable = lua_toboolean(L,3); - gtk_label_set_selectable(GTK_LABEL(label->widget),selectable); + luaA_to(L, lua_label, &label, 1); + if(lua_gettop(L) > 2) + { + gboolean selectable = lua_toboolean(L, 3); + gtk_label_set_selectable(GTK_LABEL(label->widget), selectable); return 0; } - lua_pushboolean(L,gtk_label_get_selectable(GTK_LABEL(label->widget))); + lua_pushboolean(L, gtk_label_get_selectable(GTK_LABEL(label->widget))); return 1; } @@ -59,7 +59,8 @@ static int halign_member(lua_State *L) lua_label label; luaA_to(L, lua_label, &label, 1); dt_lua_align_t align; - if(lua_gettop(L) > 2) { + if(lua_gettop(L) > 2) + { luaA_to(L, dt_lua_align_t, &align, 3); gtk_widget_set_halign(GTK_WIDGET(label->widget), align); return 0; @@ -74,7 +75,8 @@ static int ellipsize_member(lua_State *L) lua_label label; luaA_to(L, lua_label, &label, 1); dt_lua_ellipsize_mode_t ellipsize; - if(lua_gettop(L) > 2) { + if(lua_gettop(L) > 2) + { luaA_to(L, dt_lua_ellipsize_mode_t, &ellipsize, 3); gtk_label_set_ellipsize(GTK_LABEL(label->widget), ellipsize); return 0; @@ -95,23 +97,23 @@ static int tostring_member(lua_State *L) return 1; } -int dt_lua_init_widget_label(lua_State* L) +int dt_lua_init_widget_label(lua_State *L) { - dt_lua_init_widget_type(L,&label_type,lua_label,GTK_TYPE_LABEL); + dt_lua_init_widget_type(L, &label_type, lua_label, GTK_TYPE_LABEL); lua_pushcfunction(L, tostring_member); dt_lua_gtk_wrap(L); dt_lua_type_setmetafield(L, lua_label, "__tostring"); - lua_pushcfunction(L,label_member); + lua_pushcfunction(L, label_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_label, "label"); - lua_pushcfunction(L,selectable_member); + lua_pushcfunction(L, selectable_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_label, "selectable"); lua_pushcfunction(L, halign_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_label, "halign"); - lua_pushcfunction(L,ellipsize_member); + lua_pushcfunction(L, ellipsize_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_label, "ellipsize"); return 0; diff --git a/src/lua/widget/section_label.c b/src/lua/widget/section_label.c index 4aab94a3fa8f..1768efb336ad 100644 --- a/src/lua/widget/section_label.c +++ b/src/lua/widget/section_label.c @@ -20,19 +20,17 @@ #include "lua/widget/common.h" #include "gui/gtk.h" -static void section_label_init(lua_State* L); -static dt_lua_widget_type_t section_label_type = { - .name = "section_label", - .gui_init = section_label_init, - .gui_cleanup = NULL, - .alloc_size = sizeof(dt_lua_widget_t), - .parent= &widget_type -}; +static void section_label_init(lua_State *L); +static dt_lua_widget_type_t section_label_type = {.name = "section_label", + .gui_init = section_label_init, + .gui_cleanup = NULL, + .alloc_size = sizeof(dt_lua_widget_t), + .parent = &widget_type }; -static void section_label_init(lua_State* L) +static void section_label_init(lua_State *L) { lua_section_label label; - luaA_to(L,lua_section_label,&label,1); + luaA_to(L, lua_section_label, &label, 1); dt_ui_section_label_set(label->widget); } @@ -40,13 +38,14 @@ static void section_label_init(lua_State* L) static int section_label_member(lua_State *L) { lua_section_label label; - luaA_to(L,lua_section_label,&label,1); - if(lua_gettop(L) > 2) { - const char * text = luaL_checkstring(L,3); - gtk_label_set_text(GTK_LABEL(label->widget),text); + luaA_to(L, lua_section_label, &label, 1); + if(lua_gettop(L) > 2) + { + const char *text = luaL_checkstring(L, 3); + gtk_label_set_text(GTK_LABEL(label->widget), text); return 0; } - lua_pushstring(L,gtk_label_get_text(GTK_LABEL(label->widget))); + lua_pushstring(L, gtk_label_get_text(GTK_LABEL(label->widget))); return 1; } @@ -62,14 +61,14 @@ static int tostring_member(lua_State *L) return 1; } -int dt_lua_init_widget_section_label(lua_State* L) +int dt_lua_init_widget_section_label(lua_State *L) { - dt_lua_init_widget_type(L,&section_label_type,lua_section_label,GTK_TYPE_LABEL); + dt_lua_init_widget_type(L, &section_label_type, lua_section_label, GTK_TYPE_LABEL); lua_pushcfunction(L, tostring_member); dt_lua_gtk_wrap(L); dt_lua_type_setmetafield(L, lua_section_label, "__tostring"); - lua_pushcfunction(L,section_label_member); + lua_pushcfunction(L, section_label_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_section_label, "label"); return 0; diff --git a/src/lua/widget/separator.c b/src/lua/widget/separator.c index 17558598530f..089481260273 100644 --- a/src/lua/widget/separator.c +++ b/src/lua/widget/separator.c @@ -19,36 +19,36 @@ #include "lua/types.h" #include "lua/widget/common.h" -static dt_lua_widget_type_t separator_type = { - .name = "separator", - .gui_init = NULL, - .gui_cleanup = NULL, - .alloc_size = sizeof(dt_lua_widget_t), - .parent= &widget_type +static dt_lua_widget_type_t separator_type = {.name = "separator", + .gui_init = NULL, + .gui_cleanup = NULL, + .alloc_size = sizeof(dt_lua_widget_t), + .parent = &widget_type }; static int orientation_member(lua_State *L) { lua_separator separator; - luaA_to(L,lua_separator,&separator,1); + luaA_to(L, lua_separator, &separator, 1); dt_lua_orientation_t orientation; - if(lua_gettop(L) > 2) { - luaA_to(L,dt_lua_orientation_t,&orientation,3); - gtk_orientable_set_orientation(GTK_ORIENTABLE(separator->widget),orientation); + if(lua_gettop(L) > 2) + { + luaA_to(L, dt_lua_orientation_t, &orientation, 3); + gtk_orientable_set_orientation(GTK_ORIENTABLE(separator->widget), orientation); return 0; } orientation = gtk_orientable_get_orientation(GTK_ORIENTABLE(separator->widget)); - luaA_push(L,dt_lua_orientation_t,&orientation); + luaA_push(L, dt_lua_orientation_t, &orientation); return 1; } -int dt_lua_init_widget_separator(lua_State* L) +int dt_lua_init_widget_separator(lua_State *L) { - dt_lua_init_widget_type(L,&separator_type,lua_separator,GTK_TYPE_SEPARATOR); + dt_lua_init_widget_type(L, &separator_type, lua_separator, GTK_TYPE_SEPARATOR); - lua_pushcfunction(L,orientation_member); + lua_pushcfunction(L, orientation_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_separator, "orientation"); return 0; diff --git a/src/lua/widget/slider.c b/src/lua/widget/slider.c index 264919e2b632..b8a41c6aa27a 100644 --- a/src/lua/widget/slider.c +++ b/src/lua/widget/slider.c @@ -22,112 +22,117 @@ #include "lua/widget/common.h" static void slider_init(lua_State *L); -static dt_lua_widget_type_t slider_type = { - .name = "slider", - .gui_init = slider_init, - .gui_cleanup = NULL, - .alloc_size = sizeof(dt_lua_widget_t), - .parent= &widget_type -}; +static dt_lua_widget_type_t slider_type = {.name = "slider", + .gui_init = slider_init, + .gui_cleanup = NULL, + .alloc_size = sizeof(dt_lua_widget_t), + .parent = &widget_type }; -static void slider_init(lua_State*L) +static void slider_init(lua_State *L) { lua_slider slider; - luaA_to(L,lua_slider,&slider,-1); - dt_bauhaus_slider_from_widget(DT_BAUHAUS_WIDGET(slider->widget),NULL, 0.0, 1.0, 0.1, 0.5, 3,0); + luaA_to(L, lua_slider, &slider, -1); + dt_bauhaus_slider_from_widget(DT_BAUHAUS_WIDGET(slider->widget), NULL, 0.0, 1.0, 0.1, 0.5, 3, 0); } static int label_member(lua_State *L) { lua_slider slider; - luaA_to(L,lua_slider,&slider,1); - if(lua_gettop(L) > 2) { + luaA_to(L, lua_slider, &slider, 1); + if(lua_gettop(L) > 2) + { char tmp[256]; - luaA_to(L,char_256,&tmp,3); - dt_bauhaus_widget_set_label(slider->widget,NULL,tmp); + luaA_to(L, char_256, &tmp, 3); + dt_bauhaus_widget_set_label(slider->widget, NULL, tmp); return 0; } - lua_pushstring(L,dt_bauhaus_widget_get_label(slider->widget)); + lua_pushstring(L, dt_bauhaus_widget_get_label(slider->widget)); return 1; } -static int digits_member(lua_State*L) +static int digits_member(lua_State *L) { lua_slider slider; - luaA_to(L,lua_slider,&slider,1); - if(lua_gettop(L) > 2) { - int value = lua_tointeger(L,3); - dt_bauhaus_slider_set_digits(slider->widget,value); + luaA_to(L, lua_slider, &slider, 1); + if(lua_gettop(L) > 2) + { + int value = lua_tointeger(L, 3); + dt_bauhaus_slider_set_digits(slider->widget, value); return 0; } - lua_pushinteger(L,dt_bauhaus_slider_get_digits(slider->widget)); + lua_pushinteger(L, dt_bauhaus_slider_get_digits(slider->widget)); return 1; } -static int step_member(lua_State*L) +static int step_member(lua_State *L) { lua_slider slider; - luaA_to(L,lua_slider,&slider,1); - if(lua_gettop(L) > 2) { - float value = luaL_checknumber(L,3); - dt_bauhaus_slider_set_step(slider->widget,value); + luaA_to(L, lua_slider, &slider, 1); + if(lua_gettop(L) > 2) + { + float value = luaL_checknumber(L, 3); + dt_bauhaus_slider_set_step(slider->widget, value); return 0; } - lua_pushnumber(L,dt_bauhaus_slider_get_step(slider->widget)); + lua_pushnumber(L, dt_bauhaus_slider_get_step(slider->widget)); return 1; } -static int hard_min_member(lua_State*L) +static int hard_min_member(lua_State *L) { lua_slider slider; - luaA_to(L,lua_slider,&slider,1); - if(lua_gettop(L) > 2) { - float value = luaL_checknumber(L,3); - dt_bauhaus_slider_set_hard_min(slider->widget,value); + luaA_to(L, lua_slider, &slider, 1); + if(lua_gettop(L) > 2) + { + float value = luaL_checknumber(L, 3); + dt_bauhaus_slider_set_hard_min(slider->widget, value); return 0; } - lua_pushnumber(L,dt_bauhaus_slider_get_hard_min(slider->widget)); + lua_pushnumber(L, dt_bauhaus_slider_get_hard_min(slider->widget)); return 1; } -static int hard_max_member(lua_State*L) +static int hard_max_member(lua_State *L) { lua_slider slider; - luaA_to(L,lua_slider,&slider,1); - if(lua_gettop(L) > 2) { - float value = luaL_checknumber(L,3); - dt_bauhaus_slider_set_hard_max(slider->widget,value); + luaA_to(L, lua_slider, &slider, 1); + if(lua_gettop(L) > 2) + { + float value = luaL_checknumber(L, 3); + dt_bauhaus_slider_set_hard_max(slider->widget, value); return 0; } - lua_pushnumber(L,dt_bauhaus_slider_get_hard_max(slider->widget)); + lua_pushnumber(L, dt_bauhaus_slider_get_hard_max(slider->widget)); return 1; } -static int soft_min_member(lua_State*L) +static int soft_min_member(lua_State *L) { lua_slider slider; - luaA_to(L,lua_slider,&slider,1); - if(lua_gettop(L) > 2) { - float value = luaL_checknumber(L,3); - dt_bauhaus_slider_set_soft_min(slider->widget,value); + luaA_to(L, lua_slider, &slider, 1); + if(lua_gettop(L) > 2) + { + float value = luaL_checknumber(L, 3); + dt_bauhaus_slider_set_soft_min(slider->widget, value); return 0; } - lua_pushnumber(L,dt_bauhaus_slider_get_soft_min(slider->widget)); + lua_pushnumber(L, dt_bauhaus_slider_get_soft_min(slider->widget)); return 1; } -static int soft_max_member(lua_State*L) +static int soft_max_member(lua_State *L) { lua_slider slider; - luaA_to(L,lua_slider,&slider,1); - if(lua_gettop(L) > 2) { - float value = luaL_checknumber(L,3); - dt_bauhaus_slider_set_soft_max(slider->widget,value); + luaA_to(L, lua_slider, &slider, 1); + if(lua_gettop(L) > 2) + { + float value = luaL_checknumber(L, 3); + dt_bauhaus_slider_set_soft_max(slider->widget, value); return 0; } - lua_pushnumber(L,dt_bauhaus_slider_get_soft_max(slider->widget)); + lua_pushnumber(L, dt_bauhaus_slider_get_soft_max(slider->widget)); return 1; } @@ -135,13 +140,14 @@ static int soft_max_member(lua_State*L) static int value_member(lua_State *L) { lua_slider slider; - luaA_to(L,lua_slider,&slider,1); - if(lua_gettop(L) > 2) { - float value = luaL_checknumber(L,3); - dt_bauhaus_slider_set_soft(slider->widget,value); + luaA_to(L, lua_slider, &slider, 1); + if(lua_gettop(L) > 2) + { + float value = luaL_checknumber(L, 3); + dt_bauhaus_slider_set_soft(slider->widget, value); return 0; } - lua_pushnumber(L,dt_bauhaus_slider_get(slider->widget)); + lua_pushnumber(L, dt_bauhaus_slider_get(slider->widget)); return 1; } @@ -156,35 +162,35 @@ static int tostring_member(lua_State *L) return 1; } -int dt_lua_init_widget_slider(lua_State* L) +int dt_lua_init_widget_slider(lua_State *L) { - dt_lua_init_widget_type(L,&slider_type,lua_slider,DT_BAUHAUS_WIDGET_TYPE); + dt_lua_init_widget_type(L, &slider_type, lua_slider, DT_BAUHAUS_WIDGET_TYPE); lua_pushcfunction(L, tostring_member); dt_lua_gtk_wrap(L); dt_lua_type_setmetafield(L, lua_slider, "__tostring"); - lua_pushcfunction(L,digits_member); + lua_pushcfunction(L, digits_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_slider, "digits"); - lua_pushcfunction(L,step_member); + lua_pushcfunction(L, step_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_slider, "step"); - lua_pushcfunction(L,hard_min_member); + lua_pushcfunction(L, hard_min_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_slider, "hard_min"); - lua_pushcfunction(L,hard_max_member); + lua_pushcfunction(L, hard_max_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_slider, "hard_max"); - lua_pushcfunction(L,soft_min_member); + lua_pushcfunction(L, soft_min_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_slider, "soft_min"); - lua_pushcfunction(L,soft_max_member); + lua_pushcfunction(L, soft_max_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_slider, "soft_max"); - lua_pushcfunction(L,value_member); + lua_pushcfunction(L, value_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_slider, "value"); - lua_pushcfunction(L,label_member); + lua_pushcfunction(L, label_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_slider, "label"); return 0; diff --git a/src/lua/widget/stack.c b/src/lua/widget/stack.c index ec56120cd181..ab07502190d4 100644 --- a/src/lua/widget/stack.c +++ b/src/lua/widget/stack.c @@ -19,56 +19,62 @@ #include "lua/types.h" #include "lua/widget/common.h" -static dt_lua_widget_type_t stack_type = { - .name = "stack", - .gui_init = NULL, - .gui_cleanup = NULL, - .alloc_size = sizeof(dt_lua_container_t), - .parent= &container_type -}; +static dt_lua_widget_type_t stack_type = {.name = "stack", + .gui_init = NULL, + .gui_cleanup = NULL, + .alloc_size = sizeof(dt_lua_container_t), + .parent = &container_type }; -static int active_member(lua_State*L) +static int active_member(lua_State *L) { lua_stack stack; - luaA_to(L,lua_stack,&stack,1); - if(lua_gettop(L) > 2) { - GList * children = gtk_container_get_children(GTK_CONTAINER(stack->widget)); + luaA_to(L, lua_stack, &stack, 1); + if(lua_gettop(L) > 2) + { + GList *children = gtk_container_get_children(GTK_CONTAINER(stack->widget)); int length = g_list_length(children); - if(lua_isnumber(L,3)) { - int index = lua_tointeger(L,3) ; - if(index < 1 || index > length) { + if(lua_isnumber(L, 3)) + { + int index = lua_tointeger(L, 3); + if(index < 1 || index > length) + { g_list_free(children); - return luaL_error(L,"Invalid index for stack widget : %d\n",index); + return luaL_error(L, "Invalid index for stack widget : %d\n", index); } - gtk_stack_set_visible_child(GTK_STACK(stack->widget),g_list_nth_data(children,index-1)); - } else if(dt_lua_isa(L,3,lua_widget)) { + gtk_stack_set_visible_child(GTK_STACK(stack->widget), g_list_nth_data(children, index - 1)); + } + else if(dt_lua_isa(L, 3, lua_widget)) + { lua_widget child; - luaA_to(L,lua_widget,&child,3); - if(!g_list_find(children,child->widget)) { + luaA_to(L, lua_widget, &child, 3); + if(!g_list_find(children, child->widget)) + { g_list_free(children); - return luaL_error(L,"Active child of stack widget is not in the stack\n"); + return luaL_error(L, "Active child of stack widget is not in the stack\n"); } - gtk_stack_set_visible_child(GTK_STACK(stack->widget),child->widget); - } else { + gtk_stack_set_visible_child(GTK_STACK(stack->widget), child->widget); + } + else + { g_list_free(children); - return luaL_error(L,"Invalid type for stack active child\n"); + return luaL_error(L, "Invalid type for stack active child\n"); } g_list_free(children); return 0; } - GtkWidget * child = gtk_stack_get_visible_child(GTK_STACK(stack->widget)); - if(child) - luaA_push(L,lua_widget,&child); - else + GtkWidget *child = gtk_stack_get_visible_child(GTK_STACK(stack->widget)); + if(child) + luaA_push(L, lua_widget, &child); + else lua_pushnil(L); return 1; } -int dt_lua_init_widget_stack(lua_State* L) +int dt_lua_init_widget_stack(lua_State *L) { - dt_lua_init_widget_type(L,&stack_type,lua_stack,GTK_TYPE_STACK); + dt_lua_init_widget_type(L, &stack_type, lua_stack, GTK_TYPE_STACK); - lua_pushcfunction(L,active_member); + lua_pushcfunction(L, active_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_stack, "active"); return 0; diff --git a/src/lua/widget/text_view.c b/src/lua/widget/text_view.c index d70ffaba8ef6..ff3161751e21 100644 --- a/src/lua/widget/text_view.c +++ b/src/lua/widget/text_view.c @@ -20,62 +20,62 @@ #include "lua/types.h" #include "lua/widget/common.h" -static void text_view_init(lua_State* L); -static void text_view_cleanup(lua_State* L,lua_widget widget); -static dt_lua_widget_type_t textview_type = { - .name = "text_view", - .gui_init = text_view_init, - .gui_cleanup = text_view_cleanup, - .alloc_size = sizeof(dt_lua_widget_t), - .parent= &widget_type -}; +static void text_view_init(lua_State *L); +static void text_view_cleanup(lua_State *L, lua_widget widget); +static dt_lua_widget_type_t textview_type = {.name = "text_view", + .gui_init = text_view_init, + .gui_cleanup = text_view_cleanup, + .alloc_size = sizeof(dt_lua_widget_t), + .parent = &widget_type }; -static void text_view_init(lua_State* L) +static void text_view_init(lua_State *L) { lua_text_view text_view; - luaA_to(L,lua_text_view,&text_view,1); + luaA_to(L, lua_text_view, &text_view, 1); dt_gui_key_accel_block_on_focus_connect(GTK_WIDGET(text_view->widget)); } -static void text_view_cleanup(lua_State* L,lua_widget widget) +static void text_view_cleanup(lua_State *L, lua_widget widget) { dt_gui_key_accel_block_on_focus_disconnect(widget->widget); } -static gchar* gtk_text_buffer_get_all_text(GtkTextBuffer *buffer) +static gchar *gtk_text_buffer_get_all_text(GtkTextBuffer *buffer) { GtkTextIter start; GtkTextIter end; - gtk_text_buffer_get_start_iter(buffer,&start); - gtk_text_buffer_get_end_iter(buffer,&end); - return gtk_text_buffer_get_text(buffer,&start,&end,false); + gtk_text_buffer_get_start_iter(buffer, &start); + gtk_text_buffer_get_end_iter(buffer, &end); + return gtk_text_buffer_get_text(buffer, &start, &end, false); } static int text_member(lua_State *L) { lua_text_view textview; - luaA_to(L,lua_text_view,&textview,1); - GtkTextBuffer * textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview->widget)); - if(lua_gettop(L) > 2) { - const char * text = luaL_checkstring(L,3); - gtk_text_buffer_set_text(textbuffer,text,-1); + luaA_to(L, lua_text_view, &textview, 1); + GtkTextBuffer *textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview->widget)); + if(lua_gettop(L) > 2) + { + const char *text = luaL_checkstring(L, 3); + gtk_text_buffer_set_text(textbuffer, text, -1); return 0; } - lua_pushstring(L,gtk_text_buffer_get_all_text(textbuffer)); + lua_pushstring(L, gtk_text_buffer_get_all_text(textbuffer)); return 1; } static int editable_member(lua_State *L) { lua_text_view text_view; - luaA_to(L,lua_text_view,&text_view,1); - if(lua_gettop(L) > 2) { - gboolean editable = lua_toboolean(L,3); - gtk_text_view_set_editable(GTK_TEXT_VIEW(text_view->widget),editable); + luaA_to(L, lua_text_view, &text_view, 1); + if(lua_gettop(L) > 2) + { + gboolean editable = lua_toboolean(L, 3); + gtk_text_view_set_editable(GTK_TEXT_VIEW(text_view->widget), editable); return 0; } - lua_pushboolean(L,gtk_text_view_get_editable(GTK_TEXT_VIEW(text_view->widget))); + lua_pushboolean(L, gtk_text_view_get_editable(GTK_TEXT_VIEW(text_view->widget))); return 1; } @@ -83,7 +83,7 @@ static int tostring_member(lua_State *L) { lua_text_view widget; luaA_to(L, lua_text_view, &widget, 1); - GtkTextBuffer * textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget->widget)); + GtkTextBuffer *textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget->widget)); const gchar *text = gtk_text_buffer_get_all_text(textbuffer); gchar *res = g_strdup_printf("%s (\"%s\")", G_OBJECT_TYPE_NAME(widget->widget), text ? text : ""); lua_pushstring(L, res); @@ -91,17 +91,17 @@ static int tostring_member(lua_State *L) return 1; } -int dt_lua_init_widget_text_view(lua_State* L) +int dt_lua_init_widget_text_view(lua_State *L) { - dt_lua_init_widget_type(L,&textview_type,lua_text_view,GTK_TYPE_TEXT_VIEW); + dt_lua_init_widget_type(L, &textview_type, lua_text_view, GTK_TYPE_TEXT_VIEW); lua_pushcfunction(L, tostring_member); dt_lua_gtk_wrap(L); dt_lua_type_setmetafield(L, lua_text_view, "__tostring"); - lua_pushcfunction(L,text_member); + lua_pushcfunction(L, text_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_text_view, "text"); - lua_pushcfunction(L,editable_member); + lua_pushcfunction(L, editable_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_text_view, "editable"); return 0; diff --git a/src/lua/widget/widget.c b/src/lua/widget/widget.c index 67b14fa785b8..3cf592bad4bb 100644 --- a/src/lua/widget/widget.c +++ b/src/lua/widget/widget.c @@ -34,29 +34,25 @@ widget names : implement for CSS ? #pragma GCC diagnostic ignored "-Wshadow" dt_lua_widget_type_t widget_type = { - .name = "widget", - .gui_init = NULL, - .gui_cleanup = NULL, - .alloc_size = sizeof(dt_lua_widget_t), - .parent = NULL + .name = "widget", .gui_init = NULL, .gui_cleanup = NULL, .alloc_size = sizeof(dt_lua_widget_t), .parent = NULL }; -static void cleanup_widget_sub(lua_State *L,dt_lua_widget_type_t*widget_type,lua_widget widget); -static void cleanup_widget_sub(lua_State *L,dt_lua_widget_type_t*widget_type,lua_widget widget) { - if(widget_type->parent) - cleanup_widget_sub(L,widget_type->parent,widget); - if(widget_type->gui_cleanup) { - widget_type->gui_cleanup(L,widget); +static void cleanup_widget_sub(lua_State *L, dt_lua_widget_type_t *widget_type, lua_widget widget); +static void cleanup_widget_sub(lua_State *L, dt_lua_widget_type_t *widget_type, lua_widget widget) +{ + if(widget_type->parent) cleanup_widget_sub(L, widget_type->parent, widget); + if(widget_type->gui_cleanup) + { + widget_type->gui_cleanup(L, widget); } } -static void init_widget_sub(lua_State *L,dt_lua_widget_type_t*widget_type); -static void init_widget_sub(lua_State *L,dt_lua_widget_type_t*widget_type) { - if(widget_type->parent) - init_widget_sub(L,widget_type->parent); - if(widget_type->gui_init) - widget_type->gui_init(L); +static void init_widget_sub(lua_State *L, dt_lua_widget_type_t *widget_type); +static void init_widget_sub(lua_State *L, dt_lua_widget_type_t *widget_type) +{ + if(widget_type->parent) init_widget_sub(L, widget_type->parent); + if(widget_type->gui_init) widget_type->gui_init(L); } static void on_destroy(GtkWidget *widget, gpointer user_data) @@ -65,24 +61,27 @@ static void on_destroy(GtkWidget *widget, gpointer user_data) static gboolean on_destroy_wrapper(gpointer user_data) { - gtk_widget_destroy((GtkWidget*) user_data); + gtk_widget_destroy((GtkWidget *)user_data); return false; } static int widget_gc(lua_State *L) { lua_widget lwidget; - luaA_to(L,lua_widget,&lwidget,1); + luaA_to(L, lua_widget, &lwidget, 1); if(!lwidget) return 0; // object has been destroyed - if(gtk_widget_get_parent(lwidget->widget)) { - luaL_error(L,"Destroying a widget which is still parented, this should never happen (%s at %p)\n",lwidget->type->name,lwidget); + if(gtk_widget_get_parent(lwidget->widget)) + { + luaL_error(L, "Destroying a widget which is still parented, this should never happen (%s at %p)\n", + lwidget->type->name, lwidget); } - cleanup_widget_sub(L,lwidget->type,lwidget); - dt_lua_widget_unbind(L,lwidget); - // no need to drop, the pointer table is weak and the widget is already being GC, so it's not in the table anymore - //dt_lua_type_gpointer_drop(L,lwidget); - //dt_lua_type_gpointer_drop(L,lwidget->widget); - g_idle_add(on_destroy_wrapper,lwidget->widget); + cleanup_widget_sub(L, lwidget->type, lwidget); + dt_lua_widget_unbind(L, lwidget); + // no need to drop, the pointer table is weak and the widget is already being GC, so it's not in the table + // anymore + // dt_lua_type_gpointer_drop(L,lwidget); + // dt_lua_type_gpointer_drop(L,lwidget->widget); + g_idle_add(on_destroy_wrapper, lwidget->widget); free(lwidget); return 0; } @@ -90,41 +89,43 @@ static int widget_gc(lua_State *L) static int get_widget_params(lua_State *L) { struct dt_lua_widget_type_t *widget_type = lua_touserdata(L, lua_upvalueindex(1)); - if(G_TYPE_IS_ABSTRACT(widget_type->gtk_type)){ - luaL_error(L,"Trying to create a widget of an abstract type : %s\n",widget_type->name); + if(G_TYPE_IS_ABSTRACT(widget_type->gtk_type)) + { + luaL_error(L, "Trying to create a widget of an abstract type : %s\n", widget_type->name); } - lua_widget widget= malloc(widget_type->alloc_size); - widget->widget = gtk_widget_new(widget_type->gtk_type,NULL); - gtk_widget_show(widget->widget);// widgets are invisible by default + lua_widget widget = malloc(widget_type->alloc_size); + widget->widget = gtk_widget_new(widget_type->gtk_type, NULL); + gtk_widget_show(widget->widget); // widgets are invisible by default g_object_ref_sink(widget->widget); widget->type = widget_type; - luaA_push_type(L,widget_type->associated_type,&widget); - dt_lua_type_gpointer_alias_type(L,widget_type->associated_type,widget,widget->widget); - init_widget_sub(L,widget_type); + luaA_push_type(L, widget_type->associated_type, &widget); + dt_lua_type_gpointer_alias_type(L, widget_type->associated_type, widget, widget->widget); + init_widget_sub(L, widget_type); - luaL_getmetafield(L,-1,"__gtk_signals"); + luaL_getmetafield(L, -1, "__gtk_signals"); lua_pushnil(L); /* first key */ while(lua_next(L, -2) != 0) { - g_signal_connect(widget->widget, lua_tostring(L,-2), G_CALLBACK(lua_touserdata(L,-1)), widget); - lua_pop(L,1); + g_signal_connect(widget->widget, lua_tostring(L, -2), G_CALLBACK(lua_touserdata(L, -1)), widget); + lua_pop(L, 1); } - lua_pop(L,1); - g_signal_connect(widget->widget,"destroy",G_CALLBACK(on_destroy),widget); + lua_pop(L, 1); + g_signal_connect(widget->widget, "destroy", G_CALLBACK(on_destroy), widget); return 1; } -luaA_Type dt_lua_init_widget_type_type(lua_State *L, dt_lua_widget_type_t* widget_type,const char* lua_type,GType gtk_type) +luaA_Type dt_lua_init_widget_type_type(lua_State *L, dt_lua_widget_type_t *widget_type, const char *lua_type, + GType gtk_type) { - luaA_Type type_id = dt_lua_init_gpointer_type_type(L,luaA_type_add(L,lua_type,sizeof(gpointer))); + luaA_Type type_id = dt_lua_init_gpointer_type_type(L, luaA_type_add(L, lua_type, sizeof(gpointer))); widget_type->associated_type = type_id; widget_type->gtk_type = gtk_type; dt_lua_type_register_parent_type(L, type_id, widget_type->parent->associated_type); lua_newtable(L); - dt_lua_type_setmetafield_type(L,type_id,"__gtk_signals"); + dt_lua_type_setmetafield_type(L, type_id, "__gtk_signals"); // add to the table lua_pushlightuserdata(L, widget_type); lua_pushcclosure(L, get_widget_params, 1); @@ -140,43 +141,45 @@ static int new_widget(lua_State *L) { const char *entry_name = luaL_checkstring(L, 1); dt_lua_module_entry_push(L, "widget", entry_name); - lua_insert(L,2); - lua_call(L, lua_gettop(L)-2, 1); + lua_insert(L, 2); + lua_call(L, lua_gettop(L) - 2, 1); return 1; } -void dt_lua_widget_set_callback(lua_State *L,int index,const char* name) +void dt_lua_widget_set_callback(lua_State *L, int index, const char *name) { luaL_argcheck(L, dt_lua_isa(L, index, lua_widget), index, "lua_widget expected"); - luaL_checktype(L,-1,LUA_TFUNCTION); - lua_getuservalue(L,index); - lua_pushvalue(L,-2); - lua_setfield(L,-2,name); - lua_pop(L,2); + luaL_checktype(L, -1, LUA_TFUNCTION); + lua_getuservalue(L, index); + lua_pushvalue(L, -2); + lua_setfield(L, -2, name); + lua_pop(L, 2); } -void dt_lua_widget_get_callback(lua_State *L,int index,const char* name) +void dt_lua_widget_get_callback(lua_State *L, int index, const char *name) { luaL_argcheck(L, dt_lua_isa(L, index, lua_widget), index, "lua_widget expected"); - lua_getuservalue(L,index); - lua_getfield(L,-1,name); - lua_remove(L,-2); + lua_getuservalue(L, index); + lua_getfield(L, -1, name); + lua_remove(L, -2); } int dt_lua_widget_trigger_callback(lua_State *L) { - int nargs = lua_gettop(L) -2; + int nargs = lua_gettop(L) - 2; lua_widget widget; - luaA_to(L,lua_widget,&widget,1); - const char* name = lua_tostring(L,2); - lua_getuservalue(L,1); - lua_getfield(L,-1,name); - if(!lua_isnil(L,-1)) { - lua_pushvalue(L,1); - for(int i = 0 ; i < nargs ; i++) { - lua_pushvalue(L,i+3); + luaA_to(L, lua_widget, &widget, 1); + const char *name = lua_tostring(L, 2); + lua_getuservalue(L, 1); + lua_getfield(L, -1, name); + if(!lua_isnil(L, -1)) + { + lua_pushvalue(L, 1); + for(int i = 0; i < nargs; i++) + { + lua_pushvalue(L, i + 3); } - dt_lua_treated_pcall(L,nargs+1,0); + dt_lua_treated_pcall(L, nargs + 1, 0); dt_lua_redraw_screen(); } return 0; @@ -184,11 +187,12 @@ int dt_lua_widget_trigger_callback(lua_State *L) static int reset_member(lua_State *L) { - if(lua_gettop(L) > 2) { - dt_lua_widget_set_callback(L,1,"reset"); + if(lua_gettop(L) > 2) + { + dt_lua_widget_set_callback(L, 1, "reset"); return 0; } - dt_lua_widget_get_callback(L,1,"reset"); + dt_lua_widget_get_callback(L, 1, "reset"); return 1; } @@ -196,18 +200,22 @@ static int reset_member(lua_State *L) static int tooltip_member(lua_State *L) { lua_widget widget; - luaA_to(L,lua_widget,&widget,1); - if(lua_gettop(L) > 2) { - if(lua_isnil(L,3)) { - gtk_widget_set_tooltip_text(widget->widget,NULL); - } else { - const char * text = luaL_checkstring(L,3); - gtk_widget_set_tooltip_text(widget->widget,text); + luaA_to(L, lua_widget, &widget, 1); + if(lua_gettop(L) > 2) + { + if(lua_isnil(L, 3)) + { + gtk_widget_set_tooltip_text(widget->widget, NULL); + } + else + { + const char *text = luaL_checkstring(L, 3); + gtk_widget_set_tooltip_text(widget->widget, text); } return 0; } - char* result = gtk_widget_get_tooltip_text(widget->widget); - lua_pushstring(L,result); + char *result = gtk_widget_get_tooltip_text(widget->widget); + lua_pushstring(L, result); free(result); return 1; } @@ -215,14 +223,15 @@ static int tooltip_member(lua_State *L) static int sensitive_member(lua_State *L) { lua_widget widget; - luaA_to(L,lua_widget,&widget,1); - if(lua_gettop(L) > 2) { - gboolean value = lua_toboolean(L,3); - gtk_widget_set_sensitive(widget->widget,value); + luaA_to(L, lua_widget, &widget, 1); + if(lua_gettop(L) > 2) + { + gboolean value = lua_toboolean(L, 3); + gtk_widget_set_sensitive(widget->widget, value); return 0; } gboolean result = gtk_widget_get_sensitive(widget->widget); - lua_pushboolean(L,result); + lua_pushboolean(L, result); return 1; } @@ -237,27 +246,28 @@ int dt_lua_widget_tostring_member(lua_State *L) static int gtk_signal_member(lua_State *L) { - const char *signal = lua_tostring(L,lua_upvalueindex(1)); - if(lua_gettop(L) > 2) { - dt_lua_widget_set_callback(L,1,signal); + const char *signal = lua_tostring(L, lua_upvalueindex(1)); + if(lua_gettop(L) > 2) + { + dt_lua_widget_set_callback(L, 1, signal); return 0; } - dt_lua_widget_get_callback(L,1,signal); + dt_lua_widget_get_callback(L, 1, signal); return 1; } -void dt_lua_widget_register_gtk_callback_type(lua_State *L,luaA_Type type_id,const char* signal_name, const char* lua_name,GCallback callback) +void dt_lua_widget_register_gtk_callback_type(lua_State *L, luaA_Type type_id, const char *signal_name, + const char *lua_name, GCallback callback) { - lua_pushstring(L,signal_name); - lua_pushcclosure(L,gtk_signal_member,1); + lua_pushstring(L, signal_name); + lua_pushcclosure(L, gtk_signal_member, 1); dt_lua_type_register_type(L, type_id, lua_name); luaL_newmetatable(L, luaA_typename(L, type_id)); - lua_getfield(L,-1,"__gtk_signals"); - lua_pushlightuserdata(L,callback); - lua_setfield(L,-2,signal_name); - lua_pop(L,2); - + lua_getfield(L, -1, "__gtk_signals"); + lua_pushlightuserdata(L, callback); + lua_setfield(L, -2, signal_name); + lua_pop(L, 2); } int widget_call(lua_State *L) @@ -265,65 +275,66 @@ int widget_call(lua_State *L) lua_pushnil(L); /* first key */ while(lua_next(L, 2) != 0) { - lua_pushvalue(L,-2); - lua_pushvalue(L,-2); - lua_settable(L,1); - lua_pop(L,1); + lua_pushvalue(L, -2); + lua_pushvalue(L, -2); + lua_settable(L, 1); + lua_pop(L, 1); } - lua_pop(L,1); + lua_pop(L, 1); return 1; } void dt_lua_widget_bind(lua_State *L, lua_widget widget) { /* check that widget isn't already parented */ - if(gtk_widget_get_parent (widget->widget) != NULL) { - luaL_error(L,"Attempting to bind a widget which already has a parent\n"); + if(gtk_widget_get_parent(widget->widget) != NULL) + { + luaL_error(L, "Attempting to bind a widget which already has a parent\n"); } /* store it as a toplevel widget */ - lua_getfield(L, LUA_REGISTRYINDEX,"dt_lua_widget_bind_table"); - lua_pushlightuserdata(L,widget); - luaA_push(L,lua_widget,&widget); - lua_settable(L,-3); - lua_pop(L,1); + lua_getfield(L, LUA_REGISTRYINDEX, "dt_lua_widget_bind_table"); + lua_pushlightuserdata(L, widget); + luaA_push(L, lua_widget, &widget); + lua_settable(L, -3); + lua_pop(L, 1); } void dt_lua_widget_unbind(lua_State *L, lua_widget widget) { - lua_getfield(L, LUA_REGISTRYINDEX,"dt_lua_widget_bind_table"); - lua_pushlightuserdata(L,widget); + lua_getfield(L, LUA_REGISTRYINDEX, "dt_lua_widget_bind_table"); + lua_pushlightuserdata(L, widget); lua_pushnil(L); - lua_settable(L,-3); - lua_pop(L,1); + lua_settable(L, -3); + lua_pop(L, 1); } -int dt_lua_init_widget(lua_State* L) +int dt_lua_init_widget(lua_State *L) { lua_newtable(L); - lua_setfield(L, LUA_REGISTRYINDEX,"dt_lua_widget_bind_table"); + lua_setfield(L, LUA_REGISTRYINDEX, "dt_lua_widget_bind_table"); - dt_lua_module_new(L,"widget"); + dt_lua_module_new(L, "widget"); - widget_type.associated_type = dt_lua_init_gpointer_type(L,lua_widget); - lua_pushcfunction(L,tooltip_member); + widget_type.associated_type = dt_lua_init_gpointer_type(L, lua_widget); + lua_pushcfunction(L, tooltip_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_widget, "tooltip"); - lua_pushcfunction(L,widget_gc); + lua_pushcfunction(L, widget_gc); dt_lua_gtk_wrap(L); - dt_lua_type_setmetafield(L,lua_widget,"__gc"); - lua_pushcfunction(L,reset_member); + dt_lua_type_setmetafield(L, lua_widget, "__gc"); + lua_pushcfunction(L, reset_member); dt_lua_type_register(L, lua_widget, "reset_callback"); - lua_pushcfunction(L,widget_call); - dt_lua_type_setmetafield(L,lua_widget,"__call"); - lua_pushcfunction(L,sensitive_member); + lua_pushcfunction(L, widget_call); + dt_lua_type_setmetafield(L, lua_widget, "__call"); + lua_pushcfunction(L, sensitive_member); dt_lua_gtk_wrap(L); dt_lua_type_register(L, lua_widget, "sensitive"); lua_pushcfunction(L, dt_lua_widget_tostring_member); dt_lua_gtk_wrap(L); - dt_lua_type_setmetafield(L,lua_widget,"__tostring"); + dt_lua_type_setmetafield(L, lua_widget, "__tostring"); dt_lua_init_widget_container(L); diff --git a/src/lua/widget/widget.h b/src/lua/widget/widget.h index 31ac939ee97b..4c2a76830d6c 100644 --- a/src/lua/widget/widget.h +++ b/src/lua/widget/widget.h @@ -22,18 +22,20 @@ #include "lua/lua.h" #include <gtk/gtk.h> struct dt_lua_widget_type_t; -typedef struct { +typedef struct +{ GtkWidget *widget; - struct dt_lua_widget_type_t* type; + struct dt_lua_widget_type_t *type; } dt_lua_widget_t; -typedef dt_lua_widget_t* lua_widget; +typedef dt_lua_widget_t *lua_widget; -typedef struct dt_lua_widget_type_t{ +typedef struct dt_lua_widget_type_t +{ void (*gui_init)(lua_State *L); void (*gui_cleanup)(lua_State *L, lua_widget widget); - const char * name; - size_t alloc_size; + const char *name; + size_t alloc_size; struct dt_lua_widget_type_t *parent; // private, do not override luaA_Type associated_type; @@ -44,13 +46,13 @@ extern dt_lua_widget_type_t widget_type; -/** pop a function from the top of the stack, +/** pop a function from the top of the stack, register as a callback named "name" for the object (not type) at index index */ -void dt_lua_widget_set_callback(lua_State *L,int index,const char* name); +void dt_lua_widget_set_callback(lua_State *L, int index, const char *name); /** push the callback for name "name" on the stack, or nil if not available */ -void dt_lua_widget_get_callback(lua_State *L,int index,const char* name); -/** triggers a callback for the object, +void dt_lua_widget_get_callback(lua_State *L, int index, const char *name); +/** triggers a callback for the object, * first param : the lua_storage to trigger * second param : the name of the event to fire * other params : passed to the callback @@ -62,18 +64,20 @@ void dt_lua_widget_get_callback(lua_State *L,int index,const char* name); int dt_lua_widget_trigger_callback(lua_State *L); /* wrapper to automatically implement a callback on a GTK signal */ -#define dt_lua_widget_register_gtk_callback(L,widget_type,signal_name,lua_name,callback) \ - dt_lua_widget_register_gtk_callback_type(L,luaA_type_find(L, #widget_type),signal_name,lua_name,callback) -void dt_lua_widget_register_gtk_callback_type(lua_State *L,luaA_Type type_id,const char* signal_name, const char* lua_name,GCallback callback); +#define dt_lua_widget_register_gtk_callback(L, widget_type, signal_name, lua_name, callback) \ + dt_lua_widget_register_gtk_callback_type(L, luaA_type_find(L, #widget_type), signal_name, lua_name, callback) +void dt_lua_widget_register_gtk_callback_type(lua_State *L, luaA_Type type_id, const char *signal_name, + const char *lua_name, GCallback callback); -#define dt_lua_init_widget_type(L, widget_type,lua_type,gtk_type) \ - dt_lua_init_widget_type_type(L, widget_type, #lua_type,gtk_type) -luaA_Type dt_lua_init_widget_type_type(lua_State *L, dt_lua_widget_type_t* widget_type,const char* lua_type,GType gtk_type); +#define dt_lua_init_widget_type(L, widget_type, lua_type, gtk_type) \ + dt_lua_init_widget_type_type(L, widget_type, #lua_type, gtk_type) +luaA_Type dt_lua_init_widget_type_type(lua_State *L, dt_lua_widget_type_t *widget_type, const char *lua_type, + GType gtk_type); /** Bind a lua widget, i.e prevent it from being destroyed by the lua GC. - after that, the lua object is guaranteed to exist until it is unbound or + after that, the lua object is guaranteed to exist until it is unbound or the associated GtkWidget is destroyed You want to call that on widget you add to the UI so they stay alive. diff --git a/src/main.c b/src/main.c index 3d9a919f65f4..ff2d1070ba2a 100644 --- a/src/main.c +++ b/src/main.c @@ -34,12 +34,13 @@ int main(int argc, char *argv[]) // make sure to not redirect output when the output is already being redirected, either to a file or a pipe. int out_type = GetFileType(GetStdHandle(STD_OUTPUT_HANDLE)); int err_type = GetFileType(GetStdHandle(STD_ERROR_HANDLE)); - gboolean redirect_output = ((out_type != FILE_TYPE_DISK && out_type != FILE_TYPE_PIPE) && - (err_type != FILE_TYPE_DISK && err_type != FILE_TYPE_PIPE)); + gboolean redirect_output = ((out_type != FILE_TYPE_DISK && out_type != FILE_TYPE_PIPE) + && (err_type != FILE_TYPE_DISK && err_type != FILE_TYPE_PIPE)); if(redirect_output) { - // something like C:\Users\username\AppData\Local\Microsoft\Windows\Temporary Internet Files\darktable\darktable-log.txt + // something like C:\Users\username\AppData\Local\Microsoft\Windows\Temporary Internet + // Files\darktable\darktable-log.txt char *logdir = g_build_filename(g_get_user_cache_dir(), "darktable", NULL); char *logfile = g_build_filename(logdir, "darktable-log.txt", NULL); @@ -52,8 +53,10 @@ int main(int argc, char *argv[]) g_free(logfile); // don't buffer stdout/stderr. we have basically two options: unbuffered or line buffered. - // unbuffered keeps the order in which things are printed but concurrent threads printing can lead to intermangled output. ugly. - // line buffered should keep lines together but in my tests the order of things no longer matches. ugly and potentially confusing. + // unbuffered keeps the order in which things are printed but concurrent threads printing can lead to + // intermangled output. ugly. + // line buffered should keep lines together but in my tests the order of things no longer matches. ugly and + // potentially confusing. // thus we are doing the thing that is just ugly (in rare cases) but at least not confusing. setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0); diff --git a/src/osx/osx.h b/src/osx/osx.h index 1bdb2a4b9b3b..1a6be5fdc670 100644 --- a/src/osx/osx.h +++ b/src/osx/osx.h @@ -1,17 +1,17 @@ /* * This file is part of darktable, * copyright (c) 2014 tobias ellinghaus. - * + * * darktable is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * darktable is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with darktable. If not, see <http://www.gnu.org/licenses/>. */ diff --git a/src/tests/variables.c b/src/tests/variables.c index 09decae38dac..853fede53806 100644 --- a/src/tests/variables.c +++ b/src/tests/variables.c @@ -18,8 +18,8 @@ int run_test(const test_t *test, int *n_tests, int *n_failed) { dt_variables_params_t *params; dt_variables_params_init(&params); - params->filename = test->filename;//"abcdef12345abcdef"; - params->jobcode = test->jobcode;//"ABCDEF12345ABCDEF"; + params->filename = test->filename; //"abcdef12345abcdef"; + params->jobcode = test->jobcode; //"ABCDEF12345ABCDEF"; params->sequence = test->sequence; *n_failed = 0; @@ -31,7 +31,8 @@ int run_test(const test_t *test, int *n_tests, int *n_failed) if(g_strcmp0(result, test_case->expected_result)) { (*n_failed)++; - printf(" [FAIL] input: '%s', result: '%s', expected: '%s'\n", test_case->input, result, test_case->expected_result); + printf(" [FAIL] input: '%s', result: '%s', expected: '%s'\n", test_case->input, result, + test_case->expected_result); } else printf(" [OK] input: '%s', result: '%s'\n", test_case->input, result); @@ -42,160 +43,153 @@ int run_test(const test_t *test, int *n_tests, int *n_failed) return *n_failed > 0 ? 1 : 0; } -static const test_t test_variables = { - "abcdef12345abcdef", "ABCDEF12345ABCDEF", 23, - { - {"$(FILE_NAME)", "abcdef12345abcdef"}, - {"foo-$(FILE_NAME)-bar", "foo-abcdef12345abcdef-bar"}, - {"äöü-$(FILE_NAME)-äöü", "äöü-abcdef12345abcdef-äöü"}, - {"$(FILE_NAME).$(SEQUENCE)", "abcdef12345abcdef.0023"}, - {"$(NONEXISTANT)", ""}, - {"foo-$(NONEXISTANT)-bar", "foo--bar"}, - - {NULL, NULL} - } -}; - -static const test_t test_simple_substitutions = { - "abcdef12345abcdef", "ABCDEF12345ABCDEF", 23, - { - {"$(NONEXISTANT-invälid)", "invälid"}, - {"$(FILE_NAME-invälid)", "abcdef12345abcdef"}, - - {"$(NONEXISTANT+exißts)", ""}, - {"$(FILE_NAME+exißts)", "exißts"}, - - {"$(NONEXISTANT:0)", ""}, - {"$(FILE_NAME:0)", "abcdef12345abcdef"}, - {"$(FILE_NAME:5)", "f12345abcdef"}, - {"$(FILE_NAME:42)", ""}, - {"$(FILE_NAME:-5)", "bcdef"}, - {"$(FILE_NAME:-42)", "abcdef12345abcdef"}, - {"$(FILE_NAME:0:5)", "abcde"}, - {"$(FILE_NAME:5:3)", "f12"}, - {"$(FILE_NAME:5:42)", "f12345abcdef"}, - {"$(FILE_NAME:-5:3)", "bcd"}, - {"$(FILE_NAME:-7:-2)", "5abcd"}, - {"$(FILE_NAME:)", "abcdef12345abcdef"}, - {"$(FILE_NAME:5:)", ""}, - - {"$(NONEXISTANT#abc)", ""}, - {"$(FILE_NAME#abc)", "def12345abcdef"}, - {"$(FILE_NAME#def)", "abcdef12345abcdef"}, - - {"$(NONEXISTANT%abc)", ""}, - {"$(FILE_NAME%abc)", "abcdef12345abcdef"}, - {"$(FILE_NAME%def)", "abcdef12345abc"}, - - {"$(NONEXISTANT/abc/def)", ""}, - {"$(FILE_NAME/abc/foobar)", "foobardef12345abcdef"}, - {"$(FILE_NAME/def/foobar)", "abcfoobar12345abcdef"}, - {"$(FILE_NAME//abc/foobar)", "foobardef12345foobardef"}, - {"$(FILE_NAME//def/foobar)", "abcfoobar12345abcfoobar"}, - {"$(FILE_NAME/#abc/foobar)", "foobardef12345abcdef"}, - {"$(FILE_NAME/#def/foobar)", "abcdef12345abcdef"}, - {"$(FILE_NAME/%abc/foobar)", "abcdef12345abcdef"}, - {"$(FILE_NAME/%def/foobar)", "abcdef12345abcfoobar"}, - - {"$(NONEXISTANT^)", ""}, - {"$(NONEXISTANT^^)", ""}, - {"$(FILE_NAME^)", "Abcdef12345abcdef"}, - {"$(FILE_NAME^^)", "ABCDEF12345ABCDEF"}, - - {"$(NONEXISTANT,)", ""}, - {"$(NONEXISTANT,,)", ""}, - {"$(JOBCODE,)", "aBCDEF12345ABCDEF"}, - {"$(JOBCODE,,)", "abcdef12345abcdef"}, - - {NULL, NULL} - } -}; - -static const test_t test_recursive_substitutions = { - "abcdef12345abcdef", "ABCDEF12345ABCDEF", 23, - { - {"x$(TITLE-$(FILE_NAME))y", "xabcdef12345abcdefy"}, - {"x$(TITLE-a-$(FILE_NAME)-b)y", "xa-abcdef12345abcdef-by"}, - {"x$(SEQUENCE-$(FILE_NAME))y", "x0023y"}, - {"x$(FILE_NAME/12345/$(SEQUENCE))y", "xabcdef0023abcdefy"}, - {"x$(FILE_NAME/12345/.$(SEQUENCE).)y", "xabcdef.0023.abcdefy"}, - - {NULL, NULL} - } -}; - -static const test_t test_broken_variables = { - "abcdef12345abcdef", "ABCDEF12345ABCDEF", 23, - { - {"$(NONEXISTANT", "$(NONEXISTANT"}, - {"x(NONEXISTANT23", "x(NONEXISTANT23"}, - {"$(FILE_NAME", "$(FILE_NAME"}, - {"x$(FILE_NAME", "x$(FILE_NAME"}, - {"x$(TITLE-$(FILE_NAME)", "x$(TITLE-abcdef12345abcdef"}, - - {NULL, NULL} +static const test_t test_variables = { "abcdef12345abcdef", + "ABCDEF12345ABCDEF", + 23, + { { "$(FILE_NAME)", "abcdef12345abcdef" }, + { "foo-$(FILE_NAME)-bar", "foo-abcdef12345abcdef-bar" }, + { "äöü-$(FILE_NAME)-äöü", "äöü-abcdef12345abcdef-äöü" }, + { "$(FILE_NAME).$(SEQUENCE)", "abcdef12345abcdef.0023" }, + { "$(NONEXISTANT)", "" }, + { "foo-$(NONEXISTANT)-bar", "foo--bar" }, + + { NULL, NULL } } }; + +static const test_t test_simple_substitutions = { "abcdef12345abcdef", + "ABCDEF12345ABCDEF", + 23, + { { "$(NONEXISTANT-invälid)", "invälid" }, + { "$(FILE_NAME-invälid)", "abcdef12345abcdef" }, + + { "$(NONEXISTANT+exißts)", "" }, + { "$(FILE_NAME+exißts)", "exißts" }, + + { "$(NONEXISTANT:0)", "" }, + { "$(FILE_NAME:0)", "abcdef12345abcdef" }, + { "$(FILE_NAME:5)", "f12345abcdef" }, + { "$(FILE_NAME:42)", "" }, + { "$(FILE_NAME:-5)", "bcdef" }, + { "$(FILE_NAME:-42)", "abcdef12345abcdef" }, + { "$(FILE_NAME:0:5)", "abcde" }, + { "$(FILE_NAME:5:3)", "f12" }, + { "$(FILE_NAME:5:42)", "f12345abcdef" }, + { "$(FILE_NAME:-5:3)", "bcd" }, + { "$(FILE_NAME:-7:-2)", "5abcd" }, + { "$(FILE_NAME:)", "abcdef12345abcdef" }, + { "$(FILE_NAME:5:)", "" }, + + { "$(NONEXISTANT#abc)", "" }, + { "$(FILE_NAME#abc)", "def12345abcdef" }, + { "$(FILE_NAME#def)", "abcdef12345abcdef" }, + + { "$(NONEXISTANT%abc)", "" }, + { "$(FILE_NAME%abc)", "abcdef12345abcdef" }, + { "$(FILE_NAME%def)", "abcdef12345abc" }, + + { "$(NONEXISTANT/abc/def)", "" }, + { "$(FILE_NAME/abc/foobar)", "foobardef12345abcdef" }, + { "$(FILE_NAME/def/foobar)", "abcfoobar12345abcdef" }, + { "$(FILE_NAME//abc/foobar)", "foobardef12345foobardef" }, + { "$(FILE_NAME//def/foobar)", "abcfoobar12345abcfoobar" }, + { "$(FILE_NAME/#abc/foobar)", "foobardef12345abcdef" }, + { "$(FILE_NAME/#def/foobar)", "abcdef12345abcdef" }, + { "$(FILE_NAME/%abc/foobar)", "abcdef12345abcdef" }, + { "$(FILE_NAME/%def/foobar)", "abcdef12345abcfoobar" }, + + { "$(NONEXISTANT^)", "" }, + { "$(NONEXISTANT^^)", "" }, + { "$(FILE_NAME^)", "Abcdef12345abcdef" }, + { "$(FILE_NAME^^)", "ABCDEF12345ABCDEF" }, + + { "$(NONEXISTANT,)", "" }, + { "$(NONEXISTANT,,)", "" }, + { "$(JOBCODE,)", "aBCDEF12345ABCDEF" }, + { "$(JOBCODE,,)", "abcdef12345abcdef" }, + + { NULL, NULL } } }; + +static const test_t test_recursive_substitutions + = { "abcdef12345abcdef", + "ABCDEF12345ABCDEF", + 23, + { { "x$(TITLE-$(FILE_NAME))y", "xabcdef12345abcdefy" }, + { "x$(TITLE-a-$(FILE_NAME)-b)y", "xa-abcdef12345abcdef-by" }, + { "x$(SEQUENCE-$(FILE_NAME))y", "x0023y" }, + { "x$(FILE_NAME/12345/$(SEQUENCE))y", "xabcdef0023abcdefy" }, + { "x$(FILE_NAME/12345/.$(SEQUENCE).)y", "xabcdef.0023.abcdefy" }, + + { NULL, NULL } } }; + +static const test_t test_broken_variables = { "abcdef12345abcdef", + "ABCDEF12345ABCDEF", + 23, + { { "$(NONEXISTANT", "$(NONEXISTANT" }, + { "x(NONEXISTANT23", "x(NONEXISTANT23" }, + { "$(FILE_NAME", "$(FILE_NAME" }, + { "x$(FILE_NAME", "x$(FILE_NAME" }, + { "x$(TITLE-$(FILE_NAME)", "x$(TITLE-abcdef12345abcdef" }, + + { NULL, NULL } } }; + +static const test_t test_escapes + = { "/home/test/Images/IMG_0123.CR2", + "/home/test/", + 23, + { { "foobarbaz", "foobarbaz" }, + { "foo/bar/baz", "foo/bar/baz" }, + { "foo\\bar\\baz", "foobarbaz" }, + { "foo\\\\bar\\\\baz", "foo\\bar\\baz" }, + { "foo\\$(bar", "foo$(bar" }, + { "foo$\\(bar", "foo$(bar" }, + { "foo\\$\\(bar", "foo$(bar" }, + { "foo\\$(bar$(SEQUENCE)baz", "foo$(bar0023baz" }, + { "foo$(bar$(SEQUENCE)baz", "foo$(bar0023baz" }, + { "$(FILE_FOLDER)/darktable_exported/img_$(SEQUENCE)", "/home/test/Images/darktable_exported/img_0023" }, + { "$(FILE_FOLDER)/darktable_exported/$(FILE_NAME)", "/home/test/Images/darktable_exported/IMG_0123" }, + + { NULL, NULL } } }; + +static const test_t test_real_paths + = { "/home/test/Images/0023/IMG_0123.CR2", + "/home/test", + 23, + { { "$(FILE_FOLDER#$(JOBCODE))", "/Images/0023" }, + { "$(FILE_FOLDER#$(JOBCODE)/Images)", "/0023" }, + + { "$(FILE_FOLDER%$(SEQUENCE))", "/home/test/Images/" }, + { "$(FILE_FOLDER%/$(SEQUENCE))", "/home/test/Images" }, + + { "$(FILE_FOLDER/test/$(SEQUENCE))", "/home/0023/Images/0023" }, + { "$(FILE_FOLDER/test/$(SEQUENCE)-$(SEQUENCE))", "/home/0023-0023/Images/0023" }, + { "$(FILE_FOLDER/test/$(SEQUENCE//0/o))", "/home/oo23/Images/0023" }, + { "$(FILE_FOLDER/$(SEQUENCE)/XXX)", "/home/test/Images/XXX" }, + { "$(FILE_FOLDER/$(JOBCODE)\\///media/)", "/media/Images/0023" }, + { "$(FILE_FOLDER/\\/home\\/test\\///media/exports/)/darktable_exported/img_$(SEQUENCE)", + "/media/exports/Images/0023/darktable_exported/img_0023" }, + + { "$(FILE_FOLDER/", "$(FILE_FOLDER/" }, + { "$(FILE_FOLDER/home", "$(FILE_FOLDER/home" }, + { "$(FILE_FOLDER/home/media", "$(FILE_FOLDER/home/media" }, + { "$(FILE_FOLDER/home/media)", "/media/test/Images/0023" }, + + { NULL, NULL } } }; + + +#define TEST(t) \ + { \ + int n_failed = 0, n_tests = 0; \ + n_test_functions++; \ + printf("running test '" #t "'\n"); \ + n_test_functions_failed += run_test(&t, &n_tests, &n_failed); \ + n_tests_overall += n_tests; \ + n_failed_overall += n_failed; \ + printf("%d / %d tests failed\n\n", n_failed, n_tests); \ } -}; - -static const test_t test_escapes = { - "/home/test/Images/IMG_0123.CR2", "/home/test/", 23, - { - {"foobarbaz", "foobarbaz"}, - {"foo/bar/baz", "foo/bar/baz"}, - {"foo\\bar\\baz", "foobarbaz"}, - {"foo\\\\bar\\\\baz", "foo\\bar\\baz"}, - {"foo\\$(bar", "foo$(bar"}, - {"foo$\\(bar", "foo$(bar"}, - {"foo\\$\\(bar", "foo$(bar"}, - {"foo\\$(bar$(SEQUENCE)baz", "foo$(bar0023baz"}, - {"foo$(bar$(SEQUENCE)baz", "foo$(bar0023baz"}, - {"$(FILE_FOLDER)/darktable_exported/img_$(SEQUENCE)", "/home/test/Images/darktable_exported/img_0023"}, - {"$(FILE_FOLDER)/darktable_exported/$(FILE_NAME)", "/home/test/Images/darktable_exported/IMG_0123"}, - - {NULL, NULL} - } -}; - -static const test_t test_real_paths = { - "/home/test/Images/0023/IMG_0123.CR2", "/home/test", 23, - { - {"$(FILE_FOLDER#$(JOBCODE))", "/Images/0023"}, - {"$(FILE_FOLDER#$(JOBCODE)/Images)", "/0023"}, - - {"$(FILE_FOLDER%$(SEQUENCE))", "/home/test/Images/"}, - {"$(FILE_FOLDER%/$(SEQUENCE))", "/home/test/Images"}, - - {"$(FILE_FOLDER/test/$(SEQUENCE))", "/home/0023/Images/0023"}, - {"$(FILE_FOLDER/test/$(SEQUENCE)-$(SEQUENCE))", "/home/0023-0023/Images/0023"}, - {"$(FILE_FOLDER/test/$(SEQUENCE//0/o))", "/home/oo23/Images/0023"}, - {"$(FILE_FOLDER/$(SEQUENCE)/XXX)", "/home/test/Images/XXX"}, - {"$(FILE_FOLDER/$(JOBCODE)\\///media/)", "/media/Images/0023"}, - {"$(FILE_FOLDER/\\/home\\/test\\///media/exports/)/darktable_exported/img_$(SEQUENCE)", "/media/exports/Images/0023/darktable_exported/img_0023"}, - - {"$(FILE_FOLDER/", "$(FILE_FOLDER/"}, - {"$(FILE_FOLDER/home", "$(FILE_FOLDER/home"}, - {"$(FILE_FOLDER/home/media", "$(FILE_FOLDER/home/media"}, - {"$(FILE_FOLDER/home/media)", "/media/test/Images/0023"}, - - {NULL, NULL} - } -}; - - -#define TEST(t) \ -{\ - int n_failed = 0, n_tests = 0;\ - n_test_functions++;\ - printf("running test '" #t "'\n");\ - n_test_functions_failed += run_test(&t, &n_tests, &n_failed);\ - n_tests_overall += n_tests;\ - n_failed_overall += n_failed;\ - printf("%d / %d tests failed\n\n", n_failed, n_tests);\ -} int main() { - char *argv[] = {"darktable-test-variables", "--library", ":memory:", "--conf", "write_sidecar_files=FALSE", NULL}; + char *argv[] + = { "darktable-test-variables", "--library", ":memory:", "--conf", "write_sidecar_files=FALSE", NULL }; int argc = sizeof(argv) / sizeof(*argv) - 1; // init dt without gui and without data.db: @@ -215,10 +209,7 @@ int main() TEST(test_real_paths) - printf("%d / %d tests failed (%d / %d)\n", - n_failed_overall, - n_tests_overall, - n_test_functions_failed, + printf("%d / %d tests failed (%d / %d)\n", n_failed_overall, n_tests_overall, n_test_functions_failed, n_test_functions); dt_cleanup(); diff --git a/src/views/darkroom.c b/src/views/darkroom.c index 613f0219c78f..992782c5eb1d 100644 --- a/src/views/darkroom.c +++ b/src/views/darkroom.c @@ -116,18 +116,11 @@ static cairo_status_t write_snapshot_data(void *closure, const unsigned char *da { int fd = GPOINTER_TO_INT(closure); ssize_t res = write(fd, data, length); - if(res != length) - return CAIRO_STATUS_WRITE_ERROR; + if(res != length) return CAIRO_STATUS_WRITE_ERROR; return CAIRO_STATUS_SUCCESS; } -void expose( - dt_view_t *self, - cairo_t *cri, - int32_t width, - int32_t height, - int32_t pointerx, - int32_t pointery) +void expose(dt_view_t *self, cairo_t *cri, int32_t width, int32_t height, int32_t pointerx, int32_t pointery) { cairo_set_source_rgb(cri, .2, .2, .2); cairo_save(cri); @@ -171,8 +164,7 @@ void expose( static int image_surface_width = 0, image_surface_height = 0, image_surface_imgid = -1; static float roi_hash_old = -1.0f; // compute patented dreggn hash so we don't need to check all values: - const float roi_hash = width + 7.0f * height + 23.0f * zoom + 42.0f * zoom_x + 91.0f * zoom_y - + 666.0f * zoom; + const float roi_hash = width + 7.0f * height + 23.0f * zoom + 42.0f * zoom_x + 91.0f * zoom_y + 666.0f * zoom; if(image_surface_width != width || image_surface_height != height || image_surface == NULL) { @@ -240,11 +232,10 @@ void expose( const float zoom_scale = dt_dev_get_zoom_scale(dev, zoom, closeup ? 2 : 1, 1); dt_gui_gtk_set_source_rgb(cr, DT_GUI_COLOR_DARKROOM_BG); cairo_paint(cr); - cairo_rectangle(cr, tb, tb, width-2*tb, height-2*tb); + cairo_rectangle(cr, tb, tb, width - 2 * tb, height - 2 * tb); cairo_clip(cr); stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, wd); - surface - = cairo_image_surface_create_for_data(dev->preview_pipe->backbuf, CAIRO_FORMAT_RGB24, wd, ht, stride); + surface = cairo_image_surface_create_for_data(dev->preview_pipe->backbuf, CAIRO_FORMAT_RGB24, wd, ht, stride); cairo_translate(cr, width / 2.0, height / 2.0f); cairo_scale(cr, zoom_scale, zoom_scale); cairo_translate(cr, -.5f * wd - zoom_x * wd, -.5f * ht - zoom_y * ht); @@ -323,8 +314,8 @@ void expose( cairo_set_source_rgb(cri, .8, 0, 0); else cairo_set_source_rgb(cri, 0, 0, .8); - cairo_rectangle(cri, box[0] * wd + 1.0 / zoom_scale, box[1] * ht, - (box[2] - box[0]) * wd - 3. / zoom_scale, (box[3] - box[1]) * ht - 2. / zoom_scale); + cairo_rectangle(cri, box[0] * wd + 1.0 / zoom_scale, box[1] * ht, (box[2] - box[0]) * wd - 3. / zoom_scale, + (box[3] - box[1]) * ht - 2. / zoom_scale); cairo_stroke(cri); } else @@ -375,8 +366,8 @@ void expose( cairo_stroke(cri); cairo_translate(cri, 1.0 / zoom_scale, 1.0 / zoom_scale); cairo_set_source_rgb(cri, .8, .8, .8); - cairo_rectangle(cri, box[0] * wd + 1.0 / zoom_scale, box[1] * ht, - (box[2] - box[0]) * wd - 3. / zoom_scale, (box[3] - box[1]) * ht - 2. / zoom_scale); + cairo_rectangle(cri, box[0] * wd + 1.0 / zoom_scale, box[1] * ht, (box[2] - box[0]) * wd - 3. / zoom_scale, + (box[3] - box[1]) * ht - 2. / zoom_scale); cairo_stroke(cri); } else if(point[0] >= 0.0f && point[0] <= 1.0f && point[1] >= 0.0f && point[1] <= 1.0f) @@ -385,9 +376,8 @@ void expose( cairo_stroke(cri); cairo_set_source_rgb(cri, .8, .8, .8); - cairo_rectangle(cri, (point[0] - 0.01) * wd + 1.0 / zoom_scale, - point[1] * ht - 0.01 * wd + 1.0 / zoom_scale, .02 * wd - 2. / zoom_scale, - .02 * wd - 2. / zoom_scale); + cairo_rectangle(cri, (point[0] - 0.01) * wd + 1.0 / zoom_scale, point[1] * ht - 0.01 * wd + 1.0 / zoom_scale, + .02 * wd - 2. / zoom_scale, .02 * wd - 2. / zoom_scale); cairo_move_to(cri, point[0] * wd, point[1] * ht - .01 * wd + 1. / zoom_scale); cairo_line_to(cri, point[0] * wd, point[1] * ht + .01 * wd - 1. / zoom_scale); cairo_move_to(cri, point[0] * wd - .01 * wd + 1. / zoom_scale, point[1] * ht); @@ -398,8 +388,7 @@ void expose( else { // masks - if(dev->form_visible) - dt_masks_events_post_expose(dev->gui_module, cri, width, height, pointerx, pointery); + if(dev->form_visible) dt_masks_events_post_expose(dev->gui_module, cri, width, height, pointerx, pointery); // module if(dev->gui_module && dev->gui_module->gui_post_expose) dev->gui_module->gui_post_expose(dev->gui_module, cri, width, height, pointerx, pointery); @@ -669,8 +658,8 @@ static void dt_dev_change_image(dt_develop_t *dev, const uint32_t imgid) gtk_container_child_get_property( GTK_CONTAINER(dt_ui_get_container(darktable.gui->ui, DT_UI_CONTAINER_PANEL_RIGHT_CENTER)), base->expander, "position", &gv); - gtk_box_reorder_child(dt_ui_get_container(darktable.gui->ui, DT_UI_CONTAINER_PANEL_RIGHT_CENTER), - expander, g_value_get_int(&gv) + pos_base - pos_module); + gtk_box_reorder_child(dt_ui_get_container(darktable.gui->ui, DT_UI_CONTAINER_PANEL_RIGHT_CENTER), expander, + g_value_get_int(&gv) + pos_base - pos_module); dt_iop_gui_set_expanded(module, TRUE, FALSE); dt_iop_gui_update_blending(module); } @@ -873,8 +862,8 @@ static gboolean export_key_accel_callback(GtkAccelGroup *accel_group, GObject *a dt_iop_color_intent_t icc_intent = dt_conf_get_int("plugins/lighttable/export/iccintent"); // darkroom is for single images, so only export the one the user is working on GList *l = g_list_append(NULL, GINT_TO_POINTER(dev->image_storage.id)); - dt_control_export(l, max_width, max_height, format_index, storage_index, high_quality, upscale, style, style_append, - icc_type, icc_filename, icc_intent); + dt_control_export(l, max_width, max_height, format_index, storage_index, high_quality, upscale, style, + style_append, icc_type, icc_filename, icc_intent); g_free(format_name); g_free(storage_name); g_free(style); @@ -961,8 +950,7 @@ static void _darkroom_ui_apply_style_popupmenu(GtkWidget *w, gpointer user_data) gtk_widget_set_tooltip_markup(mi, tooltip); gtk_menu_shell_append(menu, mi); - g_signal_connect_swapped(G_OBJECT(mi), "activate", - G_CALLBACK(_darkroom_ui_apply_style_activate_callback), + g_signal_connect_swapped(G_OBJECT(mi), "activate", G_CALLBACK(_darkroom_ui_apply_style_activate_callback), (gpointer)g_strdup(style->name)); gtk_widget_show(mi); @@ -1128,7 +1116,7 @@ static void rawoverexposed_threshold_callback(GtkWidget *slider, gpointer user_d } static gboolean _toolbox_toggle_callback(GtkAccelGroup *accel_group, GObject *acceleratable, guint keyval, - GdkModifierType modifier, gpointer data) + GdkModifierType modifier, gpointer data) { gtk_button_clicked(GTK_BUTTON(data)); return TRUE; @@ -1214,8 +1202,10 @@ static void _update_softproof_gamut_checking(dt_develop_t *d) g_signal_handlers_block_by_func(d->profile.softproof_button, _softproof_quickbutton_clicked, d); g_signal_handlers_block_by_func(d->profile.gamut_button, _gamut_quickbutton_clicked, d); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(d->profile.softproof_button), darktable.color_profiles->mode == DT_PROFILE_SOFTPROOF); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(d->profile.gamut_button), darktable.color_profiles->mode == DT_PROFILE_GAMUTCHECK); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(d->profile.softproof_button), + darktable.color_profiles->mode == DT_PROFILE_SOFTPROOF); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(d->profile.gamut_button), + darktable.color_profiles->mode == DT_PROFILE_GAMUTCHECK); g_signal_handlers_unblock_by_func(d->profile.softproof_button, _softproof_quickbutton_clicked, d); g_signal_handlers_unblock_by_func(d->profile.gamut_button, _gamut_quickbutton_clicked, d); @@ -1263,8 +1253,8 @@ static void softproof_profile_callback(GtkWidget *combo, gpointer user_data) if(pp->out_pos == pos) { if(darktable.color_profiles->softproof_type != pp->type - || (darktable.color_profiles->softproof_type == DT_COLORSPACE_FILE - && strcmp(darktable.color_profiles->softproof_filename, pp->filename))) + || (darktable.color_profiles->softproof_type == DT_COLORSPACE_FILE + && strcmp(darktable.color_profiles->softproof_filename, pp->filename))) { darktable.color_profiles->softproof_type = pp->type; @@ -1297,8 +1287,8 @@ static void display_profile_callback(GtkWidget *combo, gpointer user_data) if(pp->display_pos == pos) { if(darktable.color_profiles->display_type != pp->type - || (darktable.color_profiles->display_type == DT_COLORSPACE_FILE - && strcmp(darktable.color_profiles->display_filename, pp->filename))) + || (darktable.color_profiles->display_type == DT_COLORSPACE_FILE + && strcmp(darktable.color_profiles->display_filename, pp->filename))) { darktable.color_profiles->display_type = pp->type; g_strlcpy(darktable.color_profiles->display_filename, pp->filename, @@ -1310,7 +1300,8 @@ static void display_profile_callback(GtkWidget *combo, gpointer user_data) } // profile not found, fall back to system display profile. shouldn't happen - fprintf(stderr, "can't find display profile `%s', using system display profile instead\n", dt_bauhaus_combobox_get_text(combo)); + fprintf(stderr, "can't find display profile `%s', using system display profile instead\n", + dt_bauhaus_combobox_get_text(combo)); profile_changed = darktable.color_profiles->display_type != DT_COLORSPACE_DISPLAY; darktable.color_profiles->display_type = DT_COLORSPACE_DISPLAY; darktable.color_profiles->display_filename[0] = '\0'; @@ -1494,8 +1485,8 @@ void gui_init(dt_view_t *self) = dtgtk_togglebutton_new(dtgtk_cairo_paint_overexposed, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); gtk_widget_set_tooltip_text(dev->overexposed.button, _("toggle over/under exposed indication\nright click for options")); - g_signal_connect(G_OBJECT(dev->overexposed.button), "clicked", - G_CALLBACK(_overexposed_quickbutton_clicked), dev); + g_signal_connect(G_OBJECT(dev->overexposed.button), "clicked", G_CALLBACK(_overexposed_quickbutton_clicked), + dev); g_signal_connect(G_OBJECT(dev->overexposed.button), "button-press-event", G_CALLBACK(_overexposed_quickbutton_pressed), dev); g_signal_connect(G_OBJECT(dev->overexposed.button), "button-release-event", @@ -1553,7 +1544,7 @@ void gui_init(dt_view_t *self) { // the softproof button dev->profile.softproof_button - = dtgtk_togglebutton_new(dtgtk_cairo_paint_softproof, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); + = dtgtk_togglebutton_new(dtgtk_cairo_paint_softproof, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); gtk_widget_set_tooltip_text(dev->profile.softproof_button, _("toggle softproofing\nright click for profile options")); g_signal_connect(G_OBJECT(dev->profile.softproof_button), "clicked", @@ -1566,11 +1557,10 @@ void gui_init(dt_view_t *self) // the gamut check button dev->profile.gamut_button - = dtgtk_togglebutton_new(dtgtk_cairo_paint_gamut_check, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); + = dtgtk_togglebutton_new(dtgtk_cairo_paint_gamut_check, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); gtk_widget_set_tooltip_text(dev->profile.gamut_button, - _("toggle gamut checking\nright click for profile options")); - g_signal_connect(G_OBJECT(dev->profile.gamut_button), "clicked", - G_CALLBACK(_gamut_quickbutton_clicked), dev); + _("toggle gamut checking\nright click for profile options")); + g_signal_connect(G_OBJECT(dev->profile.gamut_button), "clicked", G_CALLBACK(_gamut_quickbutton_clicked), dev); g_signal_connect(G_OBJECT(dev->profile.gamut_button), "button-press-event", G_CALLBACK(_gamut_quickbutton_pressed), dev); g_signal_connect(G_OBJECT(dev->profile.gamut_button), "button-release-event", @@ -1628,8 +1618,8 @@ void gui_init(dt_view_t *self) { dt_bauhaus_combobox_add(display_profile, prof->name); if(prof->type == darktable.color_profiles->display_type - && (prof->type != DT_COLORSPACE_FILE - || !strcmp(prof->filename, darktable.color_profiles->display_filename))) + && (prof->type != DT_COLORSPACE_FILE + || !strcmp(prof->filename, darktable.color_profiles->display_filename))) { dt_bauhaus_combobox_set(display_profile, prof->display_pos); } @@ -1639,16 +1629,15 @@ void gui_init(dt_view_t *self) { dt_bauhaus_combobox_add(softproof_profile, prof->name); if(prof->type == darktable.color_profiles->softproof_type - && (prof->type != DT_COLORSPACE_FILE - || !strcmp(prof->filename, darktable.color_profiles->softproof_filename))) + && (prof->type != DT_COLORSPACE_FILE + || !strcmp(prof->filename, darktable.color_profiles->softproof_filename))) dt_bauhaus_combobox_set(softproof_profile, prof->out_pos); } l = g_list_next(l); } char tooltip[1024]; - snprintf(tooltip, sizeof(tooltip), _("display ICC profiles in %s/color/out or %s/color/out"), confdir, - datadir); + snprintf(tooltip, sizeof(tooltip), _("display ICC profiles in %s/color/out or %s/color/out"), confdir, datadir); gtk_widget_set_tooltip_text(display_profile, tooltip); snprintf(tooltip, sizeof(tooltip), _("softproof ICC profiles in %s/color/out or %s/color/out"), confdir, datadir); @@ -1661,8 +1650,8 @@ void gui_init(dt_view_t *self) _update_softproof_gamut_checking(dev); // update the gui when the preferences changed (i.e. show intent when using lcms2) - dt_control_signal_connect(darktable.signals, DT_SIGNAL_PREFERENCES_CHANGE, - G_CALLBACK(_preference_changed), (gpointer)display_intent); + dt_control_signal_connect(darktable.signals, DT_SIGNAL_PREFERENCES_CHANGE, G_CALLBACK(_preference_changed), + (gpointer)display_intent); } } @@ -1888,8 +1877,8 @@ void mouse_leave(dt_view_t *self) void mouse_moved(dt_view_t *self, double x, double y, double pressure, int which) { const int32_t tb = DT_PIXEL_APPLY_DPI(dt_conf_get_int("plugins/darkroom/ui/border_size")); - const int32_t capwd = self->width - 2*tb; - const int32_t capht = self->height - 2*tb; + const int32_t capwd = self->width - 2 * tb; + const int32_t capht = self->height - 2 * tb; dt_develop_t *dev = (dt_develop_t *)self->data; // if we are not hovering over a thumbnail in the filmstrip -> show metadata of opened image. @@ -1969,8 +1958,8 @@ void mouse_moved(dt_view_t *self, double x, double y, double pressure, int which int button_released(dt_view_t *self, double x, double y, int which, uint32_t state) { const int32_t tb = DT_PIXEL_APPLY_DPI(dt_conf_get_int("plugins/darkroom/ui/border_size")); - const int32_t capwd = self->width - 2*tb; - const int32_t capht = self->height - 2*tb; + const int32_t capwd = self->width - 2 * tb; + const int32_t capht = self->height - 2 * tb; dt_develop_t *dev = darktable.develop; const int32_t width_i = self->width; const int32_t height_i = self->height; @@ -1993,8 +1982,8 @@ int button_released(dt_view_t *self, double x, double y, int which, uint32_t sta int button_pressed(dt_view_t *self, double x, double y, double pressure, int which, int type, uint32_t state) { const int32_t tb = DT_PIXEL_APPLY_DPI(dt_conf_get_int("plugins/darkroom/ui/border_size")); - const int32_t capwd = self->width - 2*tb; - const int32_t capht = self->height - 2*tb; + const int32_t capwd = self->width - 2 * tb; + const int32_t capht = self->height - 2 * tb; dt_develop_t *dev = (dt_develop_t *)self->data; const int32_t width_i = self->width; const int32_t height_i = self->height; @@ -2080,8 +2069,8 @@ int button_pressed(dt_view_t *self, double x, double y, double pressure, int whi void scrolled(dt_view_t *self, double x, double y, int up, int state) { const int32_t tb = DT_PIXEL_APPLY_DPI(dt_conf_get_int("plugins/darkroom/ui/border_size")); - const int32_t capwd = self->width - 2*tb; - const int32_t capht = self->height - 2*tb; + const int32_t capwd = self->width - 2 * tb; + const int32_t capht = self->height - 2 * tb; dt_develop_t *dev = (dt_develop_t *)self->data; const int32_t width_i = self->width; const int32_t height_i = self->height; @@ -2169,8 +2158,7 @@ int key_released(dt_view_t *self, guint key, guint state) const dt_control_accels_t *accels = &darktable.control->accels; dt_develop_t *lib = (dt_develop_t *)self->data; - if(!darktable.control->key_accelerators_on) - return 0; + if(!darktable.control->key_accelerators_on) return 0; if(key == accels->darkroom_preview.accel_key && state == accels->darkroom_preview.accel_mods && lib->full_preview) { @@ -2194,8 +2182,7 @@ int key_pressed(dt_view_t *self, guint key, guint state) const dt_control_accels_t *accels = &darktable.control->accels; dt_develop_t *lib = (dt_develop_t *)self->data; - if(!darktable.control->key_accelerators_on) - return 0; + if(!darktable.control->key_accelerators_on) return 0; if(key == accels->darkroom_preview.accel_key && state == accels->darkroom_preview.accel_mods) { @@ -2203,13 +2190,12 @@ int key_pressed(dt_view_t *self, guint key, guint state) { lib->full_preview = TRUE; // we hide all panels - for(int k = 0; k < DT_UI_PANEL_SIZE; k++) - dt_ui_panel_show(darktable.gui->ui, k, FALSE, FALSE); + for(int k = 0; k < DT_UI_PANEL_SIZE; k++) dt_ui_panel_show(darktable.gui->ui, k, FALSE, FALSE); // we remember the masks edit state if(darktable.develop->gui_module) { dt_iop_gui_blend_data_t *bd = (dt_iop_gui_blend_data_t *)darktable.develop->gui_module->blend_data; - if (bd) lib->full_preview_masks_state = bd->masks_shown; + if(bd) lib->full_preview_masks_state = bd->masks_shown; } // we set the zoom values to "fit" lib->full_preview_last_zoom = dt_control_get_dev_zoom(); @@ -2287,7 +2273,6 @@ void init_key_accels(dt_view_t *self) // undo/redo dt_accel_register_view(self, NC_("accel", "undo"), GDK_KEY_z, GDK_CONTROL_MASK); dt_accel_register_view(self, NC_("accel", "redo"), GDK_KEY_y, GDK_CONTROL_MASK); - } static gboolean _darkroom_undo_callback(GtkAccelGroup *accel_group, GObject *acceleratable, guint keyval, diff --git a/src/views/knight.c b/src/views/knight.c index 56c3c7c23d78..a178166c456f 100644 --- a/src/views/knight.c +++ b/src/views/knight.c @@ -33,7 +33,7 @@ DT_MODULE(1) #define MAX_ALIEN_SHOTS 3 // max shots in the air from the big alien block. mystery goes extra #define N_ALIENS_X 11 // number of aliens in the block in x direction #define N_ALIENS_Y 5 // number of aliens in the block in y direction -#define ALIEN_DEATH_TIME \ +#define ALIEN_DEATH_TIME \ (0.3 * 1000.0 / LOOP_SPEED) // number frames to show explosions + freeze alien movement on hit #define ALIEN_SHOT_PROBABILITY 20 // rand() % ALIEN_SHOT_PROBABILITY == 0 is the test @@ -345,8 +345,8 @@ uint32_t flags() } // turn a monochrome pixel buffer into a cairo pattern for later usage -static inline cairo_pattern_t *_new_sprite(const uint8_t *data, const int width, const int height, - int *_stride, GList **bufs, GList **surfaces, GList **patterns) +static inline cairo_pattern_t *_new_sprite(const uint8_t *data, const int width, const int height, int *_stride, + GList **bufs, GList **surfaces, GList **patterns) { const int32_t stride = cairo_format_stride_for_width(CAIRO_FORMAT_A8, width); uint8_t *buf = (uint8_t *)malloc(stride * height); @@ -421,8 +421,8 @@ void init(dt_view_t *self) = _new_sprite(alien[i], ALIEN_WIDTH, ALIEN_HEIGHT, NULL, &(d->bufs), &(d->surfaces), &(d->patterns)); // player for(int i = 0; i < 3; i++) - d->player_sprite[i] = _new_sprite(player[i], PLAYER_WIDTH, PLAYER_HEIGHT, NULL, &(d->bufs), - &(d->surfaces), &(d->patterns)); + d->player_sprite[i] + = _new_sprite(player[i], PLAYER_WIDTH, PLAYER_HEIGHT, NULL, &(d->bufs), &(d->surfaces), &(d->patterns)); // mystery ship d->mystery_sprite = _new_sprite(mystery_ship, MYSTERY_SHIP_WIDTH, MYSTERY_SHIP_HEIGHT, NULL, &(d->bufs), &(d->surfaces), &(d->patterns)); @@ -576,10 +576,10 @@ static gboolean _hit_bunker(dt_knight_t *d, const dt_knight_shot_t *shot) { // destroy it! _destroy_bunker(d, i, pixel_x, pixel_y); - const float _x - = bunker_x + pixel_x * BUNKER_TARGET_WIDTH / BUNKER_WIDTH - 0.5 * EXPLOSION_TARGET_WIDTH; - const float _y - = BUNKER_Y + pixel_y * BUNKER_TARGET_HEIGHT / BUNKER_HEIGHT - 0.5 * EXPLOSION_TARGET_HEIGHT; + const float _x = bunker_x + pixel_x * BUNKER_TARGET_WIDTH / BUNKER_WIDTH + - 0.5 * EXPLOSION_TARGET_WIDTH; + const float _y = BUNKER_Y + pixel_y * BUNKER_TARGET_HEIGHT / BUNKER_HEIGHT + - 0.5 * EXPLOSION_TARGET_HEIGHT; dt_knight_explosion_t *explosion = _new_explosion(_x, _y, ALIEN_DEATH_TIME, d->explosion_sprite[EXPLOSION_SHOT]); d->explosions = g_list_append(d->explosions, explosion); @@ -671,8 +671,7 @@ static gboolean _event_loop_game(dt_knight_t *d) // handle movement in the event loop to not be affected by X's keyboard repeat rates and delay if(!d->total_freeze) - d->player_x - = CLAMP(d->player_x + d->move * PLAYER_TARGET_WIDTH * STEP_SIZE, 0.0, 1.0 - PLAYER_TARGET_WIDTH); + d->player_x = CLAMP(d->player_x + d->move * PLAYER_TARGET_WIDTH * STEP_SIZE, 0.0, 1.0 - PLAYER_TARGET_WIDTH); // spawn a mystery ship roughly every 25 seconds d->time_until_mystery_ship--; @@ -709,8 +708,7 @@ static gboolean _event_loop_game(dt_knight_t *d) d->n_alien_shots++; d->alien_shots[s].active = TRUE; d->alien_shots[s].x = d->aliens[i].x + 0.5 * ALIEN_TARGET_WIDTH; - d->alien_shots[s].y = d->alien_shots[s].start - = d->aliens[i].y + ALIEN_TARGET_HEIGHT + SHOT_LENGTH; + d->alien_shots[s].y = d->alien_shots[s].start = d->aliens[i].y + ALIEN_TARGET_HEIGHT + SHOT_LENGTH; d->alien_shots[s].direction = -1.0; goto alien_shots_fired; } @@ -750,8 +748,7 @@ static gboolean _event_loop_game(dt_knight_t *d) { dt_knight_alien_t *alien = &d->aliens[i]; if(!alien->alive) continue; - if(d->player_shot.x >= alien->x - half_gap - && d->player_shot.x <= alien->x + ALIEN_TARGET_WIDTH + half_gap + if(d->player_shot.x >= alien->x - half_gap && d->player_shot.x <= alien->x + ALIEN_TARGET_WIDTH + half_gap && d->player_shot.y >= alien->y - SHOT_LENGTH && d->player_shot.y <= alien->y + ALIEN_TARGET_HEIGHT) { // we hit an alien @@ -774,8 +771,8 @@ static gboolean _event_loop_game(dt_knight_t *d) // we hit the top of the board d->player_shot.active = FALSE; dt_knight_explosion_t *explosion - = _new_explosion(d->player_shot.x - 0.5 * EXPLOSION_TARGET_WIDTH, 2.5 * LETTER_HEIGHT, - ALIEN_DEATH_TIME, d->explosion_sprite[EXPLOSION_TOP]); + = _new_explosion(d->player_shot.x - 0.5 * EXPLOSION_TARGET_WIDTH, 2.5 * LETTER_HEIGHT, ALIEN_DEATH_TIME, + d->explosion_sprite[EXPLOSION_TOP]); d->explosions = g_list_append(d->explosions, explosion); } else if(d->player_shot.x >= d->mystery_ship_x @@ -810,9 +807,8 @@ static gboolean _event_loop_game(dt_knight_t *d) shot->y += SHOT_LENGTH; - if(shot->x >= d->player_x - 0.2 * PLAYER_TARGET_WIDTH - && shot->x <= d->player_x + 1.2 * PLAYER_TARGET_WIDTH && shot->y >= PLAYER_Y - && shot->y <= PLAYER_Y + PLAYER_TARGET_HEIGHT + SHOT_LENGTH) + if(shot->x >= d->player_x - 0.2 * PLAYER_TARGET_WIDTH && shot->x <= d->player_x + 1.2 * PLAYER_TARGET_WIDTH + && shot->y >= PLAYER_Y && shot->y <= PLAYER_Y + PLAYER_TARGET_HEIGHT + SHOT_LENGTH) { // we hit the player. he is immune when the alien was directly above him! if(shot->start <= PLAYER_Y - ALIEN_TARGET_HEIGHT && !was_hit) @@ -833,8 +829,8 @@ static gboolean _event_loop_game(dt_knight_t *d) d->n_alien_shots--; if(rand() % 2 == 0) d->player_shot.active = FALSE; dt_knight_explosion_t *explosion - = _new_explosion(d->player_shot.x - 0.5 * EXPLOSION_TARGET_WIDTH, d->player_shot.y, - ALIEN_DEATH_TIME, d->explosion_sprite[EXPLOSION_SHOT]); + = _new_explosion(d->player_shot.x - 0.5 * EXPLOSION_TARGET_WIDTH, d->player_shot.y, ALIEN_DEATH_TIME, + d->explosion_sprite[EXPLOSION_SHOT]); d->explosions = g_list_append(d->explosions, explosion); } else if(_hit_bunker(d, shot)) @@ -1020,8 +1016,7 @@ static void _show_text(cairo_t *cr, cairo_pattern_t **letters, const char *text, cairo_translate(cr, x, y); if(justify == 'c') { - const float justify_offset - = (-1 * (int)(l / 2.0 + 0.5) * LETTER_SPACING + LETTER_SPACING - LETTER_WIDTH) * w; + const float justify_offset = (-1 * (int)(l / 2.0 + 0.5) * LETTER_SPACING + LETTER_SPACING - LETTER_WIDTH) * w; cairo_translate(cr, justify_offset, 0); } else if(justify == 'r') @@ -1058,8 +1053,8 @@ static void _show_score_2(dt_knight_t *d, cairo_t *cr, int32_t w, int32_t h) { char text[64]; snprintf(text, sizeof(text), "%04d", d->score_2); - _show_text(cr, d->letters, text, (1.0 - (LETTER_WIDTH + LETTER_SPACING * 2)) * w, 2 * LETTER_HEIGHT * w, w, - h, 'r'); + _show_text(cr, d->letters, text, (1.0 - (LETTER_WIDTH + LETTER_SPACING * 2)) * w, 2 * LETTER_HEIGHT * w, w, h, + 'r'); } static void _show_high_score(dt_knight_t *d, cairo_t *cr, int32_t w, int32_t h) @@ -1073,8 +1068,8 @@ static void _show_credit(dt_knight_t *d, cairo_t *cr, int32_t w, int32_t h) { char text[64]; snprintf(text, sizeof(text), "CREDIT %02d", d->credit); - _show_text(cr, d->letters, text, (1.0 - LETTER_WIDTH - LETTER_SPACING) * w, h - (2 * LETTER_HEIGHT) * w, w, - h, 'r'); + _show_text(cr, d->letters, text, (1.0 - LETTER_WIDTH - LETTER_SPACING) * w, h - (2 * LETTER_HEIGHT) * w, w, h, + 'r'); } static void _show_lifes(dt_knight_t *d, cairo_t *cr, int32_t w, int32_t h) diff --git a/src/views/knight_font.h b/src/views/knight_font.h index 7a9417e818d3..2cb622a344ce 100644 --- a/src/views/knight_font.h +++ b/src/views/knight_font.h @@ -61,1131 +61,379 @@ static const uint8_t font[][FONT_WIDTH * FONT_HEIGHT] = { { 0x00 }, // ! { - _____, - __X__, - __X__, - __X__, - __X__, - __X__, - _____, - __X__, - _____, + _____, __X__, __X__, __X__, __X__, __X__, _____, __X__, _____, }, // " { - _____, - _X_X_, - _X_X_, - _____, - _____, - _____, - _____, - _____, - _____, + _____, _X_X_, _X_X_, _____, _____, _____, _____, _____, _____, }, // # { - _____, - _X_X_, - _X_X_, - XXXXX, - _X_X_, - XXXXX, - _X_X_, - _X_X_, - _____, + _____, _X_X_, _X_X_, XXXXX, _X_X_, XXXXX, _X_X_, _X_X_, _____, }, // $ { - __X__, - _XXX_, - X_X_X, - X_X__, - _XXX_, - __X_X, - X_X_X, - _XXX_, - __X__, + __X__, _XXX_, X_X_X, X_X__, _XXX_, __X_X, X_X_X, _XXX_, __X__, }, // % { - _____, - XX_X_, - XX_X_, - __X__, - __X__, - __X__, - _X_XX, - _X_XX, - _____, + _____, XX_X_, XX_X_, __X__, __X__, __X__, _X_XX, _X_XX, _____, }, // & { - _____, - _XX__, - X__X_, - X__X_, - _XX__, - X__X_, - X___X, - _XXXX, - _____, + _____, _XX__, X__X_, X__X_, _XX__, X__X_, X___X, _XXXX, _____, }, // ' { - _____, - ___X_, - __X__, - _____, - _____, - _____, - _____, - _____, - _____, + _____, ___X_, __X__, _____, _____, _____, _____, _____, _____, }, // ( { - _____, - ___X_, - __X__, - _X___, - _X___, - _X___, - __X__, - ___X_, - _____, + _____, ___X_, __X__, _X___, _X___, _X___, __X__, ___X_, _____, }, // ) { - _____, - _X___, - __X__, - ___X_, - ___X_, - ___X_, - __X__, - _X___, - _____, + _____, _X___, __X__, ___X_, ___X_, ___X_, __X__, _X___, _____, }, // * { - _____, - __X__, - X_X_X, - _XXX_, - __X__, - _XXX_, - X_X_X, - __X__, - _____, + _____, __X__, X_X_X, _XXX_, __X__, _XXX_, X_X_X, __X__, _____, }, // + { - _____, - _____, - __X__, - __X__, - XXXXX, - __X__, - __X__, - _____, - _____, + _____, _____, __X__, __X__, XXXXX, __X__, __X__, _____, _____, }, // , { - _____, - _____, - _____, - _____, - _____, - _____, - _____, - __X__, - __X__, + _____, _____, _____, _____, _____, _____, _____, __X__, __X__, }, // - { - _____, - _____, - _____, - _____, - XXXXX, - _____, - _____, - _____, - _____, + _____, _____, _____, _____, XXXXX, _____, _____, _____, _____, }, // . { - _____, - _____, - _____, - _____, - _____, - _____, - _____, - __X__, - _____, + _____, _____, _____, _____, _____, _____, _____, __X__, _____, }, // / { - _____, - ___X_, - ___X_, - __X__, - __X__, - __X__, - _X___, - _X___, - _____, + _____, ___X_, ___X_, __X__, __X__, __X__, _X___, _X___, _____, }, // 0 { - _____, - _XXX_, - X___X, - X__XX, - X_X_X, - XX__X, - X___X, - _XXX_, - _____, + _____, _XXX_, X___X, X__XX, X_X_X, XX__X, X___X, _XXX_, _____, }, // 1 { - _____, - __X__, - _XX__, - __X__, - __X__, - __X__, - __X__, - _XXX_, - _____, + _____, __X__, _XX__, __X__, __X__, __X__, __X__, _XXX_, _____, }, // 2 { - _____, - _XXX_, - X___X, - ____X, - __XX_, - _X___, - X____, - XXXXX, - _____, + _____, _XXX_, X___X, ____X, __XX_, _X___, X____, XXXXX, _____, }, // 3 { - _____, - XXXXX, - ____X, - ___X_, - __XX_, - ____X, - X___X, - _XXX_, - _____, + _____, XXXXX, ____X, ___X_, __XX_, ____X, X___X, _XXX_, _____, }, // 4 { - _____, - ___X_, - __XX_, - _X_X_, - X__X_, - XXXXX, - ___X_, - ___X_, - _____, + _____, ___X_, __XX_, _X_X_, X__X_, XXXXX, ___X_, ___X_, _____, }, // 5 { - _____, - XXXXX, - X____, - X____, - _XXX_, - ____X, - X___X, - _XXX_, - _____, + _____, XXXXX, X____, X____, _XXX_, ____X, X___X, _XXX_, _____, }, // 6 { - _____, - __XXX, - _X___, - X____, - XXXX_, - X___X, - X___X, - _XXX_, - _____, + _____, __XXX, _X___, X____, XXXX_, X___X, X___X, _XXX_, _____, }, // 7 { - _____, - XXXXX, - ____X, - ___X_, - __X__, - _X___, - _X___, - _X___, - _____, + _____, XXXXX, ____X, ___X_, __X__, _X___, _X___, _X___, _____, }, // 8 { - _____, - _XXX_, - X___X, - X___X, - _XXX_, - X___X, - X___X, - _XXX_, - _____, + _____, _XXX_, X___X, X___X, _XXX_, X___X, X___X, _XXX_, _____, }, // 9 { - _____, - _XXX_, - X___X, - X___X, - _XXXX, - ____X, - ___X_, - XXX__, - _____, + _____, _XXX_, X___X, X___X, _XXXX, ____X, ___X_, XXX__, _____, }, // : { - _____, - _____, - __X__, - _____, - _____, - _____, - _____, - __X__, - _____, + _____, _____, __X__, _____, _____, _____, _____, __X__, _____, }, // ; { - _____, - _____, - __X__, - _____, - _____, - _____, - _____, - __X__, - __X__, + _____, _____, __X__, _____, _____, _____, _____, __X__, __X__, }, // < { - _____, - ___X_, - __X__, - _X___, - X____, - _X___, - __X__, - ___X_, - _____, + _____, ___X_, __X__, _X___, X____, _X___, __X__, ___X_, _____, }, // = { - _____, - _____, - _____, - _XXXX, - _____, - _XXXX, - _____, - _____, - _____, + _____, _____, _____, _XXXX, _____, _XXXX, _____, _____, _____, }, // > { - _____, - _X___, - __X__, - ___X_, - ____X, - ___X_, - __X__, - _X___, - _____, + _____, _X___, __X__, ___X_, ____X, ___X_, __X__, _X___, _____, }, // ? { - _____, - _XXX_, - X___X, - ___X_, - __X__, - __X__, - _____, - __X__, - _____, + _____, _XXX_, X___X, ___X_, __X__, __X__, _____, __X__, _____, }, // @ { - _____, - _XXX_, - X___X, - X_X_X, - XX_XX, - X_X__, - X___X, - _XXX_, - _____, + _____, _XXX_, X___X, X_X_X, XX_XX, X_X__, X___X, _XXX_, _____, }, // A { - _____, - __X__, - _X_X_, - X___X, - X___X, - XXXXX, - X___X, - X___X, - _____, + _____, __X__, _X_X_, X___X, X___X, XXXXX, X___X, X___X, _____, }, // B { - _____, - XXXX_, - X___X, - X___X, - XXXX_, - X___X, - X___X, - XXXX_, - _____, + _____, XXXX_, X___X, X___X, XXXX_, X___X, X___X, XXXX_, _____, }, // C { - _____, - _XXX_, - X___X, - X____, - X____, - X____, - X___X, - _XXX_, - _____, + _____, _XXX_, X___X, X____, X____, X____, X___X, _XXX_, _____, }, // D { - _____, - XXXX_, - X___X, - X___X, - X___X, - X___X, - X___X, - XXXX_, - _____, + _____, XXXX_, X___X, X___X, X___X, X___X, X___X, XXXX_, _____, }, // E { - _____, - XXXXX, - X____, - X____, - XXXX_, - X____, - X____, - XXXXX, - _____, + _____, XXXXX, X____, X____, XXXX_, X____, X____, XXXXX, _____, }, // F { - _____, - XXXXX, - X____, - X____, - XXXX_, - X____, - X____, - X____, - _____, + _____, XXXXX, X____, X____, XXXX_, X____, X____, X____, _____, }, // G { - _____, - _XXX_, - X___X, - X____, - X_XXX, - X___X, - X___X, - _XXX_, - _____, + _____, _XXX_, X___X, X____, X_XXX, X___X, X___X, _XXX_, _____, }, // H { - _____, - X___X, - X___X, - X___X, - XXXXX, - X___X, - X___X, - X___X, - _____, + _____, X___X, X___X, X___X, XXXXX, X___X, X___X, X___X, _____, }, // I { - _____, - _XXX_, - __X__, - __X__, - __X__, - __X__, - __X__, - _XXX_, - _____, + _____, _XXX_, __X__, __X__, __X__, __X__, __X__, _XXX_, _____, }, // J { - _____, - ____X, - ____X, - ____X, - ____X, - ____X, - X___X, - _XXX_, - _____, + _____, ____X, ____X, ____X, ____X, ____X, X___X, _XXX_, _____, }, // K { - _____, - X___X, - X__X_, - X_X__, - XX___, - X_X__, - X__X_, - X___X, - _____, + _____, X___X, X__X_, X_X__, XX___, X_X__, X__X_, X___X, _____, }, // L { - _____, - X____, - X____, - X____, - X____, - X____, - X____, - XXXXX, - _____, + _____, X____, X____, X____, X____, X____, X____, XXXXX, _____, }, // M { - _____, - X___X, - XX_XX, - X_X_X, - X_X_X, - X___X, - X___X, - X___X, - _____, + _____, X___X, XX_XX, X_X_X, X_X_X, X___X, X___X, X___X, _____, }, // N { - _____, - X___X, - X___X, - XX__X, - X_X_X, - X__XX, - X___X, - X___X, - _____, + _____, X___X, X___X, XX__X, X_X_X, X__XX, X___X, X___X, _____, }, // O { - _____, - _XXX_, - X___X, - X___X, - X___X, - X___X, - X___X, - _XXX_, - _____, + _____, _XXX_, X___X, X___X, X___X, X___X, X___X, _XXX_, _____, }, // P { - _____, - XXXX_, - X___X, - X___X, - XXXX_, - X____, - X____, - X____, - _____, + _____, XXXX_, X___X, X___X, XXXX_, X____, X____, X____, _____, }, // Q { - _____, - _XXX_, - X___X, - X___X, - X___X, - X_X_X, - X__XX, - _XXXX, - _____, + _____, _XXX_, X___X, X___X, X___X, X_X_X, X__XX, _XXXX, _____, }, // R { - _____, - XXXX_, - X___X, - X___X, - XXXX_, - X_X__, - X__X_, - X___X, - _____, + _____, XXXX_, X___X, X___X, XXXX_, X_X__, X__X_, X___X, _____, }, // S { - _____, - _XXX_, - X___X, - X____, - _XXX_, - ____X, - X___X, - _XXX_, - _____, + _____, _XXX_, X___X, X____, _XXX_, ____X, X___X, _XXX_, _____, }, // T { - _____, - XXXXX, - __X__, - __X__, - __X__, - __X__, - __X__, - __X__, - _____, + _____, XXXXX, __X__, __X__, __X__, __X__, __X__, __X__, _____, }, // U { - _____, - X___X, - X___X, - X___X, - X___X, - X___X, - X___X, - _XXX_, - _____, + _____, X___X, X___X, X___X, X___X, X___X, X___X, _XXX_, _____, }, // V { - _____, - X___X, - X___X, - X___X, - X___X, - X___X, - _X_X_, - __X__, - _____, + _____, X___X, X___X, X___X, X___X, X___X, _X_X_, __X__, _____, }, // W { - _____, - X___X, - X___X, - X___X, - X_X_X, - X_X_X, - XX_XX, - X___X, - _____, + _____, X___X, X___X, X___X, X_X_X, X_X_X, XX_XX, X___X, _____, }, // X { - _____, - X___X, - X___X, - _X_X_, - __X__, - _X_X_, - X___X, - X___X, - _____, + _____, X___X, X___X, _X_X_, __X__, _X_X_, X___X, X___X, _____, }, // Y { - _____, - X___X, - X___X, - _X_X_, - __X__, - __X__, - __X__, - __X__, - _____, + _____, X___X, X___X, _X_X_, __X__, __X__, __X__, __X__, _____, }, // Z { - _____, - XXXXX, - ____X, - ___X_, - __X__, - _X___, - X____, - XXXXX, - _____, + _____, XXXXX, ____X, ___X_, __X__, _X___, X____, XXXXX, _____, }, // [ { - _____, - __XX_, - _X___, - _X___, - _X___, - _X___, - _X___, - __XX_, - _____, + _____, __XX_, _X___, _X___, _X___, _X___, _X___, __XX_, _____, }, // \ . { - _____, - _X___, - _X___, - __X__, - __X__, - __X__, - ___X_, - ___X_, - _____, + _____, _X___, _X___, __X__, __X__, __X__, ___X_, ___X_, _____, }, // ] { - _____, - _XX__, - ___X_, - ___X_, - ___X_, - ___X_, - ___X_, - _XX__, - _____, + _____, _XX__, ___X_, ___X_, ___X_, ___X_, ___X_, _XX__, _____, }, // ^ { - _____, - __X__, - _X_X_, - X___X, - _____, - _____, - _____, - _____, - _____, + _____, __X__, _X_X_, X___X, _____, _____, _____, _____, _____, }, // _ { - _____, - _____, - _____, - _____, - _____, - _____, - _____, - XXXXX, - _____, + _____, _____, _____, _____, _____, _____, _____, XXXXX, _____, }, // ` { - _____, - __X__, - ___X_, - _____, - _____, - _____, - _____, - _____, - _____, + _____, __X__, ___X_, _____, _____, _____, _____, _____, _____, }, // a { - _____, - __X__, - _X_X_, - X___X, - X___X, - XXXXX, - X___X, - X___X, - _____, + _____, __X__, _X_X_, X___X, X___X, XXXXX, X___X, X___X, _____, }, // b { - _____, - XXXX_, - X___X, - X___X, - XXXX_, - X___X, - X___X, - XXXX_, - _____, + _____, XXXX_, X___X, X___X, XXXX_, X___X, X___X, XXXX_, _____, }, // c { - _____, - _XXX_, - X___X, - X____, - X____, - X____, - X___X, - _XXX_, - _____, + _____, _XXX_, X___X, X____, X____, X____, X___X, _XXX_, _____, }, // d { - _____, - XXXX_, - X___X, - X___X, - X___X, - X___X, - X___X, - XXXX_, - _____, + _____, XXXX_, X___X, X___X, X___X, X___X, X___X, XXXX_, _____, }, // e { - _____, - XXXXX, - X____, - X____, - XXXX_, - X____, - X____, - XXXXX, - _____, + _____, XXXXX, X____, X____, XXXX_, X____, X____, XXXXX, _____, }, // f { - _____, - XXXXX, - X____, - X____, - XXXX_, - X____, - X____, - X____, - _____, + _____, XXXXX, X____, X____, XXXX_, X____, X____, X____, _____, }, // g { - _____, - _XXX_, - X___X, - X____, - X_XXX, - X___X, - X___X, - _XXX_, - _____, + _____, _XXX_, X___X, X____, X_XXX, X___X, X___X, _XXX_, _____, }, // h { - _____, - X___X, - X___X, - X___X, - XXXXX, - X___X, - X___X, - X___X, - _____, + _____, X___X, X___X, X___X, XXXXX, X___X, X___X, X___X, _____, }, // i { - _____, - _XXX_, - __X__, - __X__, - __X__, - __X__, - __X__, - _XXX_, - _____, + _____, _XXX_, __X__, __X__, __X__, __X__, __X__, _XXX_, _____, }, // j { - _____, - ____X, - ____X, - ____X, - ____X, - ____X, - X___X, - _XXX_, - _____, + _____, ____X, ____X, ____X, ____X, ____X, X___X, _XXX_, _____, }, // k { - _____, - X___X, - X__X_, - X_X__, - XX___, - X_X__, - X__X_, - X___X, - _____, + _____, X___X, X__X_, X_X__, XX___, X_X__, X__X_, X___X, _____, }, // l { - _____, - X____, - X____, - X____, - X____, - X____, - X____, - XXXXX, - _____, + _____, X____, X____, X____, X____, X____, X____, XXXXX, _____, }, // m { - _____, - X___X, - XX_XX, - X_X_X, - X_X_X, - X___X, - X___X, - X___X, - _____, + _____, X___X, XX_XX, X_X_X, X_X_X, X___X, X___X, X___X, _____, }, // n { - _____, - X___X, - X___X, - XX__X, - X_X_X, - X__XX, - X___X, - X___X, - _____, + _____, X___X, X___X, XX__X, X_X_X, X__XX, X___X, X___X, _____, }, // o { - _____, - _XXX_, - X___X, - X___X, - X___X, - X___X, - X___X, - _XXX_, - _____, + _____, _XXX_, X___X, X___X, X___X, X___X, X___X, _XXX_, _____, }, // p { - _____, - XXXX_, - X___X, - X___X, - XXXX_, - X____, - X____, - X____, - _____, + _____, XXXX_, X___X, X___X, XXXX_, X____, X____, X____, _____, }, // q { - _____, - _XXX_, - X___X, - X___X, - X___X, - X_X_X, - X__XX, - _XXXX, - _____, + _____, _XXX_, X___X, X___X, X___X, X_X_X, X__XX, _XXXX, _____, }, // r { - _____, - XXXX_, - X___X, - X___X, - XXXX_, - X_X__, - X__X_, - X___X, - _____, + _____, XXXX_, X___X, X___X, XXXX_, X_X__, X__X_, X___X, _____, }, // s { - _____, - _XXX_, - X___X, - X____, - _XXX_, - ____X, - X___X, - _XXX_, - _____, + _____, _XXX_, X___X, X____, _XXX_, ____X, X___X, _XXX_, _____, }, // t { - _____, - XXXXX, - __X__, - __X__, - __X__, - __X__, - __X__, - __X__, - _____, + _____, XXXXX, __X__, __X__, __X__, __X__, __X__, __X__, _____, }, // u { - _____, - X___X, - X___X, - X___X, - X___X, - X___X, - X___X, - _XXX_, - _____, + _____, X___X, X___X, X___X, X___X, X___X, X___X, _XXX_, _____, }, // v { - _____, - X___X, - X___X, - X___X, - X___X, - X___X, - _X_X_, - __X__, - _____, + _____, X___X, X___X, X___X, X___X, X___X, _X_X_, __X__, _____, }, // w { - _____, - X___X, - X___X, - X___X, - X_X_X, - X_X_X, - XX_XX, - X___X, - _____, + _____, X___X, X___X, X___X, X_X_X, X_X_X, XX_XX, X___X, _____, }, // x { - _____, - X___X, - X___X, - _X_X_, - __X__, - _X_X_, - X___X, - X___X, - _____, + _____, X___X, X___X, _X_X_, __X__, _X_X_, X___X, X___X, _____, }, // y { - _____, - X___X, - X___X, - _X_X_, - __X__, - __X__, - __X__, - __X__, - _____, + _____, X___X, X___X, _X_X_, __X__, __X__, __X__, __X__, _____, }, // z { - _____, - XXXXX, - ____X, - ___X_, - __X__, - _X___, - X____, - XXXXX, - _____, + _____, XXXXX, ____X, ___X_, __X__, _X___, X____, XXXXX, _____, }, // { { - _____, - ___X_, - __X__, - __X__, - _X___, - __X__, - __X__, - ___X_, - _____, + _____, ___X_, __X__, __X__, _X___, __X__, __X__, ___X_, _____, }, // | { - _____, - __X__, - __X__, - __X__, - __X__, - __X__, - __X__, - __X__, - _____, + _____, __X__, __X__, __X__, __X__, __X__, __X__, __X__, _____, }, // } { - _____, - _X___, - __X__, - __X__, - ___X_, - __X__, - __X__, - _X___, - _____, + _____, _X___, __X__, __X__, ___X_, __X__, __X__, _X___, _____, }, // ~ { - _____, - _____, - _____, - __X_X, - _X_X_, - _____, - _____, - _____, - _____, + _____, _____, _____, __X_X, _X_X_, _____, _____, _____, _____, } }; diff --git a/src/views/lighttable.c b/src/views/lighttable.c index 3e614e630bb2..9d6c16b81c5c 100644 --- a/src/views/lighttable.c +++ b/src/views/lighttable.c @@ -145,7 +145,8 @@ uint32_t view(const dt_view_t *self) return DT_VIEW_LIGHTTABLE; } -typedef enum dt_lighttable_direction_t { +typedef enum dt_lighttable_direction_t +{ DIRECTION_UP = 0, DIRECTION_DOWN = 1, DIRECTION_LEFT = 2, @@ -197,13 +198,13 @@ static void move_view(dt_library_t *lib, dt_lighttable_direction_t dir) break; case DIRECTION_PGUP: { - lib->offset -= (lib->max_rows - 1 ) * iir; + lib->offset -= (lib->max_rows - 1) * iir; while(lib->offset < 0) lib->offset += iir; } break; case DIRECTION_PGDOWN: { - lib->offset += (lib->max_rows - 1 ) * iir; + lib->offset += (lib->max_rows - 1) * iir; while(lib->offset >= lib->collection_count) lib->offset -= iir; } break; @@ -284,7 +285,7 @@ static void _update_collected_images(dt_view_t *self) // a temporary (in-memory) table (collected_images). // // 0. get current lower rowid - if (lib->full_preview_id != -1) + if(lib->full_preview_id != -1) { DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT MIN(rowid) FROM memory.collected_images", -1, &stmt, NULL); @@ -297,11 +298,11 @@ static void _update_collected_images(dt_view_t *self) // 1. drop previous data - DT_DEBUG_SQLITE3_EXEC(dt_database_get(darktable.db), "DELETE FROM memory.collected_images", NULL, NULL, - NULL); + DT_DEBUG_SQLITE3_EXEC(dt_database_get(darktable.db), "DELETE FROM memory.collected_images", NULL, NULL, NULL); // reset autoincrement. need in star_key_accel_callback DT_DEBUG_SQLITE3_EXEC(dt_database_get(darktable.db), "DELETE FROM memory.sqlite_sequence WHERE " - "name='collected_images'", NULL, NULL, NULL); + "name='collected_images'", + NULL, NULL, NULL); // 2. insert collected images into the temporary table @@ -318,7 +319,7 @@ static void _update_collected_images(dt_view_t *self) g_free(ins_query); // 3. get new low-bound, then update the full preview rowid accordingly - if (lib->full_preview_id != -1) + if(lib->full_preview_id != -1) { DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT MIN(rowid) FROM memory.collected_images", -1, &stmt, NULL); @@ -334,12 +335,13 @@ static void _update_collected_images(dt_view_t *self) lib->full_preview_rowid += (min_after - min_before); char col_query[128] = { 0 }; - snprintf(col_query, sizeof(col_query), "SELECT imgid FROM memory.collected_images WHERE rowid=%d", lib->full_preview_rowid); + snprintf(col_query, sizeof(col_query), "SELECT imgid FROM memory.collected_images WHERE rowid=%d", + lib->full_preview_rowid); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), col_query, -1, &stmt, NULL); if(sqlite3_step(stmt) == SQLITE_ROW) { int nid = sqlite3_column_int(stmt, 0); - if (nid != lib->full_preview_id) + if(nid != lib->full_preview_id) { lib->full_preview_id = sqlite3_column_int(stmt, 0); dt_control_set_mouse_over_id(lib->full_preview_id); @@ -465,7 +467,7 @@ grid_to_index (int row, int col, int stride, int offset) #endif static int expose_filemanager(dt_view_t *self, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, - int32_t pointery) + int32_t pointery) { dt_library_t *lib = (dt_library_t *)self->data; gboolean offset_changed = FALSE; @@ -630,7 +632,7 @@ static int expose_filemanager(dt_view_t *self, cairo_t *cr, int32_t width, int32 int current_image = 0; int before_mouse_over_id = 0; - if (lib->using_arrows) + if(lib->using_arrows) { before_mouse_over_id = dt_control_get_mouse_over_id(); } @@ -658,7 +660,7 @@ static int expose_filemanager(dt_view_t *self, cairo_t *cr, int32_t width, int32 if(iir == 1 && row) continue; /* set mouse over id if pointer is in current row / col */ - if (lib->using_arrows) + if(lib->using_arrows) { if(before_mouse_over_id == -1) @@ -669,56 +671,56 @@ static int expose_filemanager(dt_view_t *self, cairo_t *cr, int32_t width, int32 if(before_mouse_over_id == id) { // I would like to jump from before_mouse_over_id to query_ids[idx] - int idx = current_image+lib->key_jump_offset-1; - int current_row = (int)((current_image-1)/iir); - int current_col = current_image%iir; + int idx = current_image + lib->key_jump_offset - 1; + int current_row = (int)((current_image - 1) / iir); + int current_col = current_image % iir; // detect if the current movement need some extra movement (page adjust) - if (current_row == (int)(max_rows-1.5) && lib->key_jump_offset == iir) + if(current_row == (int)(max_rows - 1.5) && lib->key_jump_offset == iir) // going DOWN from last row move_view(lib, DIRECTION_DOWN); - else if (current_row == 0 && lib->key_jump_offset == iir*-1) + else if(current_row == 0 && lib->key_jump_offset == iir * -1) { // going UP from first row move_view(lib, DIRECTION_UP); } - else if (current_row == (int)(max_rows-1.5) && current_col == 0 && lib->key_jump_offset == 1) + else if(current_row == (int)(max_rows - 1.5) && current_col == 0 && lib->key_jump_offset == 1) // going RIGHT from last visible move_view(lib, DIRECTION_DOWN); - else if (current_row == 0 && current_col == 1 && lib->key_jump_offset == -1) + else if(current_row == 0 && current_col == 1 && lib->key_jump_offset == -1) // going LEFT from first visible move_view(lib, DIRECTION_UP); - if (idx > -1 && idx < lib->collection_count && query_ids[idx]) + if(idx > -1 && idx < lib->collection_count && query_ids[idx]) { - // offset is valid..we know where to jump - mouse_over_id = query_ids[idx]; + // offset is valid..we know where to jump + mouse_over_id = query_ids[idx]; } else // going into a non existing position. Do nothing mouse_over_id = before_mouse_over_id; - if (lib->key_jump_offset != 0) + if(lib->key_jump_offset != 0) { - if (lib->key_select) + if(lib->key_select) { // managing shift + movement int direction = (lib->key_jump_offset > 0) ? DIRECTION_RIGHT : DIRECTION_LEFT; - if (lib->key_select_direction != direction ) + if(lib->key_select_direction != direction) { - lib->key_select_direction = direction; + lib->key_select_direction = direction; dt_selection_toggle(darktable.selection, before_mouse_over_id); } int loop_count = abs(lib->key_jump_offset); // ex: from -10 to 1 // from 10 to 1 int to_toggle = 0; - while (loop_count--) + while(loop_count--) { // ex shift + down toggle selection on images_in_row images - to_toggle = idx+(-1*lib->key_jump_offset/abs(lib->key_jump_offset)*loop_count); - if (query_ids[to_toggle]) - dt_selection_toggle(darktable.selection, query_ids[to_toggle]); + to_toggle = idx + (-1 * lib->key_jump_offset / abs(lib->key_jump_offset) * loop_count); + if(query_ids[to_toggle]) dt_selection_toggle(darktable.selection, query_ids[to_toggle]); } } - lib->key_jump_offset = 0; // avoid key_release events move cursor. TBD: return the right value in key_pressed and trash the flag + lib->key_jump_offset = 0; // avoid key_release events move cursor. TBD: return the right value in + // key_pressed and trash the flag } } } @@ -737,7 +739,7 @@ static int expose_filemanager(dt_view_t *self, cairo_t *cr, int32_t width, int32 dt_selection_select_single(darktable.selection, id); } missing += dt_view_image_expose(&(lib->image_over), id, cr, wd, iir == 1 ? height : ht, iir, img_pointerx, - img_pointery, FALSE, FALSE); + img_pointery, FALSE, FALSE); cairo_restore(cr); } @@ -915,8 +917,8 @@ static int expose_filemanager(dt_view_t *self, cairo_t *cr, int32_t width, int32 imgids[imgids_num++] = sqlite3_column_int(lib->statements.main_query, 0); float imgwd = iir == 1 ? 0.97 : 0.8; - dt_mipmap_size_t mip = dt_mipmap_cache_get_matching_size(darktable.mipmap_cache, imgwd * wd, - imgwd * (iir == 1 ? height : ht)); + dt_mipmap_size_t mip + = dt_mipmap_cache_get_matching_size(darktable.mipmap_cache, imgwd * wd, imgwd * (iir == 1 ? height : ht)); while(imgids_num > 0) { imgids_num--; @@ -956,7 +958,7 @@ static int expose_filemanager(dt_view_t *self, cairo_t *cr, int32_t width, int32 #define DT_LIBRARY_MAX_ZOOM 13 static int expose_zoomable(dt_view_t *self, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, - int32_t pointery) + int32_t pointery) { dt_library_t *lib = (dt_library_t *)self->data; float zoom, zoom_x, zoom_y; @@ -1174,8 +1176,8 @@ static int expose_zoomable(dt_view_t *self, cairo_t *cr, int32_t width, int32_t cairo_save(cr); // if(zoom == 1) dt_image_prefetch(image, DT_IMAGE_MIPF); - missing += dt_view_image_expose(&(lib->image_over), id, cr, wd, zoom == 1 ? height : ht, zoom, img_pointerx, - img_pointery, FALSE, FALSE); + missing += dt_view_image_expose(&(lib->image_over), id, cr, wd, zoom == 1 ? height : ht, zoom, + img_pointerx, img_pointery, FALSE, FALSE); cairo_restore(cr); if(zoom == 1) { @@ -1231,20 +1233,20 @@ static int expose_full_preview(dt_view_t *self, cairo_t *cr, int32_t width, int3 gboolean preload = preload_num > 0; preload_num = CLAMPS(preload_num, 1, 99999); - gchar *stmt_string = g_strdup_printf("SELECT col.imgid AS id, col.rowid FROM memory.collected_images AS col %s " - "WHERE col.rowid %s %d ORDER BY col.rowid %s LIMIT %d", - (sel_img_count <= 1) ? - /* We want to operate on the currently collected images, - * so there's no need to match against the selection */ - "" : - /* Limit the matches to the current selection */ - "INNER JOIN main.selected_images AS sel ON col.imgid = sel.imgid", - (offset >= 0) ? ">" : "<", - lib->full_preview_rowid, - /* Direction of our navigation -- when showing for the first time, - * i.e. when offset == 0, assume forward navigation */ - (offset >= 0) ? "ASC" : "DESC", - preload_num); + gchar *stmt_string + = g_strdup_printf("SELECT col.imgid AS id, col.rowid FROM memory.collected_images AS col %s " + "WHERE col.rowid %s %d ORDER BY col.rowid %s LIMIT %d", + (sel_img_count <= 1) ? + /* We want to operate on the currently collected images, + * so there's no need to match against the selection */ + "" + : + /* Limit the matches to the current selection */ + "INNER JOIN main.selected_images AS sel ON col.imgid = sel.imgid", + (offset >= 0) ? ">" : "<", lib->full_preview_rowid, + /* Direction of our navigation -- when showing for the first time, + * i.e. when offset == 0, assume forward navigation */ + (offset >= 0) ? "ASC" : "DESC", preload_num); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), stmt_string, -1, &stmt, NULL); /* Walk through the "next" images, activate preload and find out where to go if moving */ @@ -1255,7 +1257,7 @@ static int expose_full_preview(dt_view_t *self, cairo_t *cr, int32_t width, int3 } int count = 0; - while (sqlite3_step(stmt) == SQLITE_ROW) + while(sqlite3_step(stmt) == SQLITE_ROW) { /* Check if we're about to move */ if(count == 0 && offset != 0) @@ -1302,18 +1304,17 @@ static int expose_full_preview(dt_view_t *self, cairo_t *cr, int32_t width, int3 free(lib->full_res_thumb); lib->full_res_thumb = NULL; dt_colorspaces_color_profile_type_t color_space; - if(!dt_imageio_large_thumbnail(filename, &lib->full_res_thumb, - &lib->full_res_thumb_wd, - &lib->full_res_thumb_ht, - &color_space)) { + if(!dt_imageio_large_thumbnail(filename, &lib->full_res_thumb, &lib->full_res_thumb_wd, + &lib->full_res_thumb_ht, &color_space)) + { lib->full_res_thumb_orientation = ORIENTATION_NONE; lib->full_res_thumb_id = lib->full_preview_id; } if(lib->full_res_thumb_id == lib->full_preview_id) { - dt_focus_create_clusters(lib->full_res_focus, frows, fcols, lib->full_res_thumb, - lib->full_res_thumb_wd, lib->full_res_thumb_ht); + dt_focus_create_clusters(lib->full_res_focus, frows, fcols, lib->full_res_thumb, lib->full_res_thumb_wd, + lib->full_res_thumb_ht); } } } @@ -1375,12 +1376,12 @@ static int expose_full_preview(dt_view_t *self, cairo_t *cr, int32_t width, int3 } else #endif - const int missing = dt_view_image_expose(&(lib->image_over), lib->full_preview_id, cr, - width, height, 1, pointerx, pointery, TRUE, FALSE); + const int missing = dt_view_image_expose(&(lib->image_over), lib->full_preview_id, cr, width, height, 1, + pointerx, pointery, TRUE, FALSE); if(lib->display_focus && (lib->full_res_thumb_id == lib->full_preview_id)) - dt_focus_draw_clusters(cr, width, height, lib->full_preview_id, lib->full_res_thumb_wd, - lib->full_res_thumb_ht, lib->full_res_focus, frows, fcols); + dt_focus_draw_clusters(cr, width, height, lib->full_preview_id, lib->full_res_thumb_wd, lib->full_res_thumb_ht, + lib->full_res_focus, frows, fcols); return missing; } @@ -1427,8 +1428,7 @@ void expose(dt_view_t *self, cairo_t *cr, int32_t width, int32_t height, int32_t const double end = dt_get_wtime(); if(darktable.unmuted & DT_DEBUG_PERF) dt_print(DT_DEBUG_LIGHTTABLE, "[lighttable] expose took %0.04f sec\n", end - start); - if(missing_thumbnails) - g_timeout_add(500, _expose_again, 0); + if(missing_thumbnails) g_timeout_add(500, _expose_again, 0); } static gboolean go_up_key_accel_callback(GtkAccelGroup *accel_group, GObject *acceleratable, guint keyval, @@ -1513,7 +1513,7 @@ static gboolean realign_key_accel_callback(GtkAccelGroup *accel_group, GObject * } static gboolean select_toggle_callback(GtkAccelGroup *accel_group, GObject *acceleratable, guint keyval, - GdkModifierType modifier, gpointer data) + GdkModifierType modifier, gpointer data) { uint32_t id = dt_control_get_mouse_over_id(); dt_selection_toggle(darktable.selection, id); @@ -1521,7 +1521,7 @@ static gboolean select_toggle_callback(GtkAccelGroup *accel_group, GObject *acce } static gboolean select_single_callback(GtkAccelGroup *accel_group, GObject *acceleratable, guint keyval, - GdkModifierType modifier, gpointer data) + GdkModifierType modifier, gpointer data) { uint32_t id = dt_control_get_mouse_over_id(); dt_selection_select_single(darktable.selection, id); @@ -1544,8 +1544,8 @@ static gboolean star_key_accel_callback(GtkAccelGroup *accel_group, GObject *acc int imgid_for_offset; sqlite3_stmt *stmt; - DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), - "SELECT MIN(imgid) FROM main.selected_images", -1, &stmt, NULL); + DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT MIN(imgid) FROM main.selected_images", -1, + &stmt, NULL); if(sqlite3_step(stmt) == SQLITE_ROW) { sqlite3_stmt *inner_stmt; @@ -1557,12 +1557,11 @@ static gboolean star_key_accel_callback(GtkAccelGroup *accel_group, GObject *acc } DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), - //"SELECT imgid FROM memory.collected_images", -1, &inner_stmt, - "SELECT rowid FROM memory.collected_images WHERE imgid=?1", -1, &inner_stmt, - NULL); + //"SELECT imgid FROM memory.collected_images", -1, &inner_stmt, + "SELECT rowid FROM memory.collected_images WHERE imgid=?1", -1, &inner_stmt, + NULL); DT_DEBUG_SQLITE3_BIND_INT(inner_stmt, 1, imgid_for_offset); - if(sqlite3_step(inner_stmt) == SQLITE_ROW) - next_image_rowid = sqlite3_column_int(inner_stmt, 0); + if(sqlite3_step(inner_stmt) == SQLITE_ROW) next_image_rowid = sqlite3_column_int(inner_stmt, 0); sqlite3_finalize(inner_stmt); } sqlite3_finalize(stmt); @@ -1588,11 +1587,10 @@ static gboolean star_key_accel_callback(GtkAccelGroup *accel_group, GObject *acc sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT imgid FROM memory.collected_images WHERE rowid=?1 OR rowid=?1 - 1 " - "ORDER BY rowid DESC LIMIT 1", -1, &stmt, - NULL); + "ORDER BY rowid DESC LIMIT 1", + -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, next_image_rowid); - if(sqlite3_step(stmt) == SQLITE_ROW) - mouse_over_id = sqlite3_column_int(stmt, 0); + if(sqlite3_step(stmt) == SQLITE_ROW) mouse_over_id = sqlite3_column_int(stmt, 0); sqlite3_finalize(stmt); dt_control_set_mouse_over_id(mouse_over_id); } @@ -1606,8 +1604,7 @@ static void _lighttable_mipmaps_updated_signal_callback(gpointer instance, gpoin } static void drag_and_drop_received(GtkWidget *widget, GdkDragContext *context, gint x, gint y, - GtkSelectionData *selection_data, guint target_type, guint time, - gpointer data) + GtkSelectionData *selection_data, guint target_type, guint time, gpointer data) { gboolean success = FALSE; @@ -1621,8 +1618,9 @@ static void drag_and_drop_received(GtkWidget *widget, GdkDragContext *context, g { if(**image_to_load) { - dt_load_from_string(*image_to_load, FALSE, NULL); // TODO: do we want to open the image in darkroom mode? If - // yes -> set to TRUE. + dt_load_from_string(*image_to_load, FALSE, + NULL); // TODO: do we want to open the image in darkroom mode? If + // yes -> set to TRUE. } image_to_load++; } @@ -1636,10 +1634,8 @@ static void drag_and_drop_received(GtkWidget *widget, GdkDragContext *context, g void enter(dt_view_t *self) { // init drag&drop of files/folders - gtk_drag_dest_set(dt_ui_center(darktable.gui->ui), GTK_DEST_DEFAULT_ALL, target_list, n_targets, - GDK_ACTION_COPY); - g_signal_connect(dt_ui_center(darktable.gui->ui), "drag-data-received", G_CALLBACK(drag_and_drop_received), - self); + gtk_drag_dest_set(dt_ui_center(darktable.gui->ui), GTK_DEST_DEFAULT_ALL, target_list, n_targets, GDK_ACTION_COPY); + g_signal_connect(dt_ui_center(darktable.gui->ui), "drag-data-received", G_CALLBACK(drag_and_drop_received), self); /* connect to signals */ dt_control_signal_connect(darktable.signals, DT_SIGNAL_DEVELOP_MIPMAP_UPDATED, @@ -1702,10 +1698,11 @@ void reset(dt_view_t *self) void mouse_enter(dt_view_t *self) { - // TODO: In gtk.c the function center_leave return true. It is not needed when using arrows. the same for mouse_leave, mouse_move + // TODO: In gtk.c the function center_leave return true. It is not needed when using arrows. the same for + // mouse_leave, mouse_move dt_library_t *lib = (dt_library_t *)self->data; uint32_t id = dt_control_get_mouse_over_id(); - if (lib->using_arrows == 0) + if(lib->using_arrows == 0) { if(id == -1) dt_control_set_mouse_over_id( @@ -1716,7 +1713,7 @@ void mouse_enter(dt_view_t *self) void mouse_leave(dt_view_t *self) { dt_library_t *lib = (dt_library_t *)self->data; - if (lib->using_arrows == 0) + if(lib->using_arrows == 0) { lib->last_mouse_over_id = dt_control_get_mouse_over_id(); // see mouse_enter (re: fluxbox) if(!lib->pan && dt_conf_get_int("plugins/lighttable/images_in_row") != 1) @@ -1835,7 +1832,7 @@ int button_pressed(dt_view_t *self, double x, double y, double pressure, int whi case DT_VIEW_DESERT: { - if (lib->using_arrows) + if(lib->using_arrows) { // in this case dt_control_get_mouse_over_id() means "last image visited with arrows" lib->using_arrows = 0; @@ -1893,8 +1890,8 @@ int button_pressed(dt_view_t *self, double x, double y, double pressure, int whi sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2( dt_database_get(darktable.db), - "INSERT OR IGNORE INTO main.selected_images SELECT id FROM main.images WHERE group_id = ?1", - -1, &stmt, NULL); + "INSERT OR IGNORE INTO main.selected_images SELECT id FROM main.images WHERE group_id = ?1", -1, + &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, group_id); sqlite3_step(stmt); sqlite3_finalize(stmt); @@ -1935,7 +1932,7 @@ int button_pressed(dt_view_t *self, double x, double y, double pressure, int whi char *argv[] = { player, filename, NULL }; gboolean ret = g_spawn_async(NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH - | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, + | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, &lib->audio_player_pid, NULL); if(ret) @@ -1981,8 +1978,7 @@ int key_released(dt_view_t *self, guint key, guint state) lib->full_preview_id = -1; lib->full_preview_rowid = -1; - if(!lib->using_arrows) - dt_control_set_mouse_over_id(-1); + if(!lib->using_arrows) dt_control_set_mouse_over_id(-1); dt_ui_panel_show(darktable.gui->ui, DT_UI_PANEL_LEFT, (lib->full_preview & 1), FALSE); dt_ui_panel_show(darktable.gui->ui, DT_UI_PANEL_RIGHT, (lib->full_preview & 2), FALSE); @@ -2017,8 +2013,7 @@ int key_pressed(dt_view_t *self, guint key, guint state) { lib->full_preview_id = -1; lib->full_preview_rowid = -1; - if(!lib->using_arrows) - dt_control_set_mouse_over_id(-1); + if(!lib->using_arrows) dt_control_set_mouse_over_id(-1); dt_ui_panel_show(darktable.gui->ui, DT_UI_PANEL_LEFT, (lib->full_preview & 1), FALSE); dt_ui_panel_show(darktable.gui->ui, DT_UI_PANEL_RIGHT, (lib->full_preview & 2), FALSE); @@ -2060,8 +2055,7 @@ int key_pressed(dt_view_t *self, guint key, guint state) { sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), - "SELECT rowid FROM memory.collected_images WHERE imgid=?1", -1, &stmt, - NULL); + "SELECT rowid FROM memory.collected_images WHERE imgid=?1", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, lib->full_preview_id); if(sqlite3_step(stmt) == SQLITE_ROW) { @@ -2097,18 +2091,19 @@ int key_pressed(dt_view_t *self, guint key, guint state) return 0; } - if (key == GDK_KEY_Shift_L || key == GDK_KEY_Shift_R) + if(key == GDK_KEY_Shift_L || key == GDK_KEY_Shift_R) { lib->key_select = 1; } - if((key == accels->lighttable_left.accel_key && state == accels->lighttable_left.accel_mods) || ( key == accels->lighttable_left.accel_key && layout == 1 && zoom != 1 )) + if((key == accels->lighttable_left.accel_key && state == accels->lighttable_left.accel_mods) + || (key == accels->lighttable_left.accel_key && layout == 1 && zoom != 1)) { if(lib->full_preview_id > -1) lib->track = -DT_LIBRARY_MAX_ZOOM; else if(layout == 1) { - if (zoom == 1) + if(zoom == 1) { move_view(lib, DIRECTION_UP); lib->using_arrows = 0; @@ -2125,14 +2120,15 @@ int key_pressed(dt_view_t *self, guint key, guint state) return 1; } - //if(key == accels->lighttable_right.accel_key && state == accels->lighttable_right.accel_mods) - if((key == accels->lighttable_right.accel_key && state == accels->lighttable_right.accel_mods) || ( key == accels->lighttable_right.accel_key && layout == 1 && zoom != 1 )) + // if(key == accels->lighttable_right.accel_key && state == accels->lighttable_right.accel_mods) + if((key == accels->lighttable_right.accel_key && state == accels->lighttable_right.accel_mods) + || (key == accels->lighttable_right.accel_key && layout == 1 && zoom != 1)) { if(lib->full_preview_id > -1) lib->track = +DT_LIBRARY_MAX_ZOOM; else if(layout == 1) { - if (zoom == 1) + if(zoom == 1) { move_view(lib, DIRECTION_DOWN); lib->using_arrows = 0; @@ -2149,20 +2145,22 @@ int key_pressed(dt_view_t *self, guint key, guint state) return 1; } - if((key == accels->lighttable_up.accel_key && state == accels->lighttable_up.accel_mods) || ( key == accels->lighttable_up.accel_key && layout == 1 && zoom != 1 )) + if((key == accels->lighttable_up.accel_key && state == accels->lighttable_up.accel_mods) + || (key == accels->lighttable_up.accel_key && layout == 1 && zoom != 1)) { if(lib->full_preview_id > -1) lib->track = -DT_LIBRARY_MAX_ZOOM; else if(layout == 1) { - if (zoom == 1) + if(zoom == 1) { move_view(lib, DIRECTION_UP); lib->using_arrows = 0; } - else { + else + { lib->using_arrows = 1; - lib->key_jump_offset = zoom*-1; + lib->key_jump_offset = zoom * -1; } } else @@ -2170,13 +2168,14 @@ int key_pressed(dt_view_t *self, guint key, guint state) return 1; } - if((key == accels->lighttable_down.accel_key && state == accels->lighttable_down.accel_mods) || ( key == accels->lighttable_down.accel_key && layout == 1 && zoom != 1 )) + if((key == accels->lighttable_down.accel_key && state == accels->lighttable_down.accel_mods) + || (key == accels->lighttable_down.accel_key && layout == 1 && zoom != 1)) { if(lib->full_preview_id > -1) lib->track = +DT_LIBRARY_MAX_ZOOM; - else if(layout == 1) + else if(layout == 1) { - if (zoom == 1) + if(zoom == 1) { move_view(lib, DIRECTION_DOWN); lib->using_arrows = 0; @@ -2317,8 +2316,8 @@ static void display_profile_callback(GtkWidget *combo, gpointer user_data) if(pp->display_pos == pos) { if(darktable.color_profiles->display_type != pp->type - || (darktable.color_profiles->display_type == DT_COLORSPACE_FILE - && strcmp(darktable.color_profiles->display_filename, pp->filename))) + || (darktable.color_profiles->display_type == DT_COLORSPACE_FILE + && strcmp(darktable.color_profiles->display_filename, pp->filename))) { darktable.color_profiles->display_type = pp->type; g_strlcpy(darktable.color_profiles->display_filename, pp->filename, @@ -2330,7 +2329,8 @@ static void display_profile_callback(GtkWidget *combo, gpointer user_data) } // profile not found, fall back to system display profile. shouldn't happen - fprintf(stderr, "can't find display profile `%s', using system display profile instead\n", dt_bauhaus_combobox_get_text(combo)); + fprintf(stderr, "can't find display profile `%s', using system display profile instead\n", + dt_bauhaus_combobox_get_text(combo)); profile_changed = darktable.color_profiles->display_type != DT_COLORSPACE_DISPLAY; darktable.color_profiles->display_type = DT_COLORSPACE_DISPLAY; darktable.color_profiles->display_filename[0] = '\0'; @@ -2350,7 +2350,8 @@ void gui_init(dt_view_t *self) dt_library_t *lib = (dt_library_t *)self->data; // create display profile button - GtkWidget *const profile_button = dtgtk_button_new(dtgtk_cairo_paint_display, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); + GtkWidget *const profile_button + = dtgtk_button_new(dtgtk_cairo_paint_display, CPF_STYLE_FLAT | CPF_DO_NOT_USE_BORDER); gtk_widget_set_tooltip_text(profile_button, _("set display profile")); dt_view_manager_module_toolbox_add(darktable.view_manager, profile_button, DT_VIEW_LIGHTTABLE); @@ -2362,7 +2363,8 @@ void gui_init(dt_view_t *self) #if GTK_CHECK_VERSION(3, 16, 0) g_object_set(G_OBJECT(lib->profile_floating_window), "transitions-enabled", FALSE, NULL); #endif - g_signal_connect_swapped(G_OBJECT(profile_button), "button-press-event", G_CALLBACK(gtk_widget_show_all), lib->profile_floating_window); + g_signal_connect_swapped(G_OBJECT(profile_button), "button-press-event", G_CALLBACK(gtk_widget_show_all), + lib->profile_floating_window); GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); gtk_widget_set_margin_start(vbox, DT_PIXEL_APPLY_DPI(8)); @@ -2397,8 +2399,8 @@ void gui_init(dt_view_t *self) { dt_bauhaus_combobox_add(display_profile, prof->name); if(prof->type == darktable.color_profiles->display_type - && (prof->type != DT_COLORSPACE_FILE - || !strcmp(prof->filename, darktable.color_profiles->display_filename))) + && (prof->type != DT_COLORSPACE_FILE + || !strcmp(prof->filename, darktable.color_profiles->display_filename))) { dt_bauhaus_combobox_set(display_profile, prof->display_pos); } @@ -2406,8 +2408,7 @@ void gui_init(dt_view_t *self) } char tooltip[1024]; - snprintf(tooltip, sizeof(tooltip), _("display ICC profiles in %s/color/out or %s/color/out"), confdir, - datadir); + snprintf(tooltip, sizeof(tooltip), _("display ICC profiles in %s/color/out or %s/color/out"), confdir, datadir); gtk_widget_set_tooltip_text(display_profile, tooltip); g_signal_connect(G_OBJECT(display_intent), "value-changed", G_CALLBACK(display_intent_callback), NULL); diff --git a/src/views/map.c b/src/views/map.c index 11589ed8e075..fc304a5396e1 100644 --- a/src/views/map.c +++ b/src/views/map.c @@ -99,8 +99,7 @@ static void _view_map_collection_changed(gpointer instance, gpointer user_data); static void _view_map_filmstrip_activate_callback(gpointer instance, gpointer user_data); /* callback when an image is dropped from filmstrip */ static void drag_and_drop_received(GtkWidget *widget, GdkDragContext *context, gint x, gint y, - GtkSelectionData *selection_data, guint target_type, guint time, - gpointer data); + GtkSelectionData *selection_data, guint target_type, guint time, gpointer data); /* callback when the user drags images FROM the map */ static void _view_map_dnd_get_callback(GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint target_type, guint time, @@ -255,9 +254,9 @@ static int zoom_member(lua_State *L) // Copyright (C) 2014 Martijn Goedhart <goedhart.martijn@gmail.com> #if FLT_RADIX == 2 - #define LOG2(x) (ilogb(x)) +#define LOG2(x) (ilogb(x)) #else - #define LOG2(x) ((int)floor(log2(abs(x)))) +#define LOG2(x) ((int)floor(log2(abs(x)))) #endif #define TILESIZE 256 @@ -286,12 +285,14 @@ static int latlon2zoom(int pix_height, int pix_width, float lat1, float lat2, fl // // Contributions by // Everaldo Canuto 2009 <everaldo.canuto@gmail.com> -static void osm_gps_map_zoom_fit_bbox(OsmGpsMap *map, float latitude1, float latitude2, float longitude1, float longitude2) +static void osm_gps_map_zoom_fit_bbox(OsmGpsMap *map, float latitude1, float latitude2, float longitude1, + float longitude2) { GtkAllocation allocation; int zoom; - gtk_widget_get_allocation(GTK_WIDGET (map), &allocation); - zoom = latlon2zoom(allocation.height, allocation.width, deg2rad(latitude1), deg2rad(latitude2), deg2rad(longitude1), deg2rad(longitude2)); + gtk_widget_get_allocation(GTK_WIDGET(map), &allocation); + zoom = latlon2zoom(allocation.height, allocation.width, deg2rad(latitude1), deg2rad(latitude2), + deg2rad(longitude1), deg2rad(longitude2)); osm_gps_map_set_center(map, (latitude1 + latitude2) / 2, (longitude1 + longitude2) / 2); osm_gps_map_set_zoom(map, zoom); } @@ -410,8 +411,8 @@ void init(dt_view_t *self) GtkWidget *parent = gtk_widget_get_parent(dt_ui_center(darktable.gui->ui)); gtk_box_pack_start(GTK_BOX(parent), GTK_WIDGET(lib->map), TRUE, TRUE, 0); - lib->osd = g_object_new(OSM_TYPE_GPS_MAP_OSD, "show-scale", TRUE, "show-coordinates", TRUE, "show-dpad", - TRUE, "show-zoom", TRUE, NULL); + lib->osd = g_object_new(OSM_TYPE_GPS_MAP_OSD, "show-scale", TRUE, "show-coordinates", TRUE, "show-dpad", TRUE, + "show-zoom", TRUE, NULL); if(dt_conf_get_bool("plugins/map/show_map_osd")) { @@ -423,10 +424,9 @@ void init(dt_view_t *self) GDK_ACTION_COPY); g_signal_connect(GTK_WIDGET(lib->map), "drag-data-received", G_CALLBACK(drag_and_drop_received), self); g_signal_connect(GTK_WIDGET(lib->map), "changed", G_CALLBACK(_view_map_changed_callback), self); - g_signal_connect_after(G_OBJECT(lib->map), "button-press-event", - G_CALLBACK(_view_map_button_press_callback), self); - g_signal_connect(G_OBJECT(lib->map), "motion-notify-event", G_CALLBACK(_view_map_motion_notify_callback), - self); + g_signal_connect_after(G_OBJECT(lib->map), "button-press-event", G_CALLBACK(_view_map_button_press_callback), + self); + g_signal_connect(G_OBJECT(lib->map), "motion-notify-event", G_CALLBACK(_view_map_motion_notify_callback), self); /* allow drag&drop of images from the map, too */ g_signal_connect(GTK_WIDGET(lib->map), "drag-data-get", G_CALLBACK(_view_map_dnd_get_callback), self); @@ -517,8 +517,7 @@ static void _view_map_changed_callback(OsmGpsMap *map, dt_view_t *self) /* make the bounding box a little bigger to the west and south */ float lat0 = 0.0, lon0 = 0.0, lat1 = 0.0, lon1 = 0.0; - OsmGpsMapPoint *pt0 = osm_gps_map_point_new_degrees(0.0, 0.0), - *pt1 = osm_gps_map_point_new_degrees(0.0, 0.0); + OsmGpsMapPoint *pt0 = osm_gps_map_point_new_degrees(0.0, 0.0), *pt1 = osm_gps_map_point_new_degrees(0.0, 0.0); osm_gps_map_convert_screen_to_geographic(map, 0, 0, pt0); osm_gps_map_convert_screen_to_geographic(map, 1.5 * thumb_size, 1.5 * thumb_size, pt1); osm_gps_map_point_get_degrees(pt0, &lat0, &lon0); @@ -587,13 +586,13 @@ static void _view_map_changed_callback(OsmGpsMap *map, dt_view_t *self) h = (buf.height * _thumb_size) / buf.width; // landscape // next we get a pixbuf for the image - source = gdk_pixbuf_new_from_data(buf.buf, GDK_COLORSPACE_RGB, TRUE, 8, buf.width, buf.height, - buf.width * 4, NULL, NULL); + source = gdk_pixbuf_new_from_data(buf.buf, GDK_COLORSPACE_RGB, TRUE, 8, buf.width, buf.height, buf.width * 4, + NULL, NULL); if(!source) goto map_changed_failure; // now we want a slightly larger pixbuf that we can put the image on - thumb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w + 2 * _thumb_border, - h + 2 * _thumb_border + _pin_size); + thumb + = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w + 2 * _thumb_border, h + 2 * _thumb_border + _pin_size); if(!thumb) goto map_changed_failure; gdk_pixbuf_fill(thumb, thumb_frame_color); @@ -640,9 +639,8 @@ static void _view_map_changed_callback(OsmGpsMap *map, dt_view_t *self) // case in the initialization phase. if(!lib->drop_filmstrip_activated && darktable.view_manager->proxy.filmstrip.module) { - g_signal_connect( - darktable.view_manager->proxy.filmstrip.widget(darktable.view_manager->proxy.filmstrip.module), - "drag-data-received", G_CALLBACK(_view_map_dnd_remove_callback), self); + g_signal_connect(darktable.view_manager->proxy.filmstrip.widget(darktable.view_manager->proxy.filmstrip.module), + "drag-data-received", G_CALLBACK(_view_map_dnd_remove_callback), self); lib->drop_filmstrip_activated = TRUE; } } @@ -660,8 +658,7 @@ static int _view_map_get_img_at_pos(dt_view_t *self, double x, double y) gint img_x = 0, img_y = 0; osm_gps_map_convert_geographic_to_screen(lib->map, pt, &img_x, &img_y); img_y -= DT_PIXEL_APPLY_DPI(image_pin_size); - if(x >= img_x && x <= img_x + entry->width && y <= img_y && y >= img_y - entry->height) - return entry->imgid; + if(x >= img_x && x <= img_x + entry->width && y <= img_y && y >= img_y - entry->height) return entry->imgid; } return 0; @@ -708,8 +705,8 @@ static gboolean _view_map_motion_notify_callback(GtkWidget *widget, GdkEventMoti h = (buf.height * _thumb_size) / buf.width; // landscape // next we get a pixbuf for the image - source = gdk_pixbuf_new_from_data(buf.buf, GDK_COLORSPACE_RGB, TRUE, 8, buf.width, buf.height, - buf.width * 4, NULL, NULL); + source = gdk_pixbuf_new_from_data(buf.buf, GDK_COLORSPACE_RGB, TRUE, 8, buf.width, buf.height, buf.width * 4, + NULL, NULL); // now we want a slightly larger pixbuf that we can put the image on thumb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w + 2 * _thumb_border, h + 2 * _thumb_border); @@ -719,8 +716,8 @@ static gboolean _view_map_motion_notify_callback(GtkWidget *widget, GdkEventMoti gdk_pixbuf_scale(source, thumb, _thumb_border, _thumb_border, w, h, _thumb_border, _thumb_border, (1.0 * w) / buf.width, (1.0 * h) / buf.height, GDK_INTERP_HYPER); - GdkDragContext *context = gtk_drag_begin_with_coordinates(GTK_WIDGET(lib->map), targets, - GDK_ACTION_COPY, 1, (GdkEvent *)e, -1, -1); + GdkDragContext *context = gtk_drag_begin_with_coordinates(GTK_WIDGET(lib->map), targets, GDK_ACTION_COPY, 1, + (GdkEvent *)e, -1, -1); gtk_drag_set_icon_pixbuf(context, thumb, 0, h + 2 * _thumb_border); @@ -962,12 +959,12 @@ static OsmGpsMapPolygon *_view_map_add_polygon(const dt_view_t *view, GList *poi dt_map_t *lib = (dt_map_t *)view->data; OsmGpsMapPolygon *poly = osm_gps_map_polygon_new(); - OsmGpsMapTrack* track = osm_gps_map_track_new(); + OsmGpsMapTrack *track = osm_gps_map_track_new(); for(GList *iter = g_list_first(points); iter; iter = g_list_next(iter)) { dt_geo_map_display_point_t *p = (dt_geo_map_display_point_t *)iter->data; - OsmGpsMapPoint* point = osm_gps_map_point_new_degrees(p->lat, p->lon); + OsmGpsMapPoint *point = osm_gps_map_point_new_degrees(p->lat, p->lon); osm_gps_map_track_add_point(track, point); } @@ -990,12 +987,12 @@ static OsmGpsMapTrack *_view_map_add_track(const dt_view_t *view, GList *points) { dt_map_t *lib = (dt_map_t *)view->data; - OsmGpsMapTrack* track = osm_gps_map_track_new(); + OsmGpsMapTrack *track = osm_gps_map_track_new(); for(GList *iter = g_list_first(points); iter; iter = g_list_next(iter)) { dt_geo_map_display_point_t *p = (dt_geo_map_display_point_t *)iter->data; - OsmGpsMapPoint* point = osm_gps_map_point_new_degrees(p->lat, p->lon); + OsmGpsMapPoint *point = osm_gps_map_point_new_degrees(p->lat, p->lon); osm_gps_map_track_add_point(track, point); } @@ -1016,12 +1013,16 @@ static GObject *_view_map_add_marker(const dt_view_t *view, dt_geo_map_display_t { switch(type) { - case MAP_DISPLAY_POINT: return G_OBJECT(_view_map_add_pin(view, points)); - case MAP_DISPLAY_TRACK: return G_OBJECT(_view_map_add_track(view, points)); + case MAP_DISPLAY_POINT: + return G_OBJECT(_view_map_add_pin(view, points)); + case MAP_DISPLAY_TRACK: + return G_OBJECT(_view_map_add_track(view, points)); #ifdef HAVE_OSMGPSMAP_110_OR_NEWER - case MAP_DISPLAY_POLYGON: return G_OBJECT(_view_map_add_polygon(view, points)); + case MAP_DISPLAY_POLYGON: + return G_OBJECT(_view_map_add_polygon(view, points)); #endif - default: return NULL; + default: + return NULL; } } @@ -1031,12 +1032,16 @@ static gboolean _view_map_remove_marker(const dt_view_t *view, dt_geo_map_displa switch(type) { - case MAP_DISPLAY_POINT: return _view_map_remove_pin(view, OSM_GPS_MAP_IMAGE(marker)); - case MAP_DISPLAY_TRACK: return _view_map_remove_track(view, OSM_GPS_MAP_TRACK(marker)); + case MAP_DISPLAY_POINT: + return _view_map_remove_pin(view, OSM_GPS_MAP_IMAGE(marker)); + case MAP_DISPLAY_TRACK: + return _view_map_remove_track(view, OSM_GPS_MAP_TRACK(marker)); #ifdef HAVE_OSMGPSMAP_110_OR_NEWER - case MAP_DISPLAY_POLYGON: return _view_map_remove_polygon(view, OSM_GPS_MAP_POLYGON(marker)); + case MAP_DISPLAY_POLYGON: + return _view_map_remove_polygon(view, OSM_GPS_MAP_POLYGON(marker)); #endif - default: return FALSE; + default: + return FALSE; } } @@ -1122,8 +1127,7 @@ static void _check_imgid(gpointer user_data, dt_undo_type_t type, dt_undo_data_t { dt_undo_geotag_t *geotag = (dt_undo_geotag_t *)item; int *state = (int *)user_data; - if (geotag->imgid == state[0]) - state[1] = 1; + if(geotag->imgid == state[0]) state[1] = 1; } static gboolean _in_undo(int imgid) @@ -1167,13 +1171,11 @@ static void _view_map_record_current_location(dt_view_t *self, int imgid) { float longitude, latitude, elevation; _get_image_location(self, imgid, &longitude, &latitude, &elevation); - if (!_in_undo(imgid)) - _push_position(self, imgid, longitude, latitude, elevation); + if(!_in_undo(imgid)) _push_position(self, imgid, longitude, latitude, elevation); } static void drag_and_drop_received(GtkWidget *widget, GdkDragContext *context, gint x, gint y, - GtkSelectionData *selection_data, guint target_type, guint time, - gpointer data) + GtkSelectionData *selection_data, guint target_type, guint time, gpointer data) { dt_view_t *self = (dt_view_t *)data; dt_map_t *lib = (dt_map_t *)self->data; @@ -1201,13 +1203,11 @@ static void drag_and_drop_received(GtkWidget *widget, GdkDragContext *context, g // create an undo group for current image position - while(sqlite3_step(stmt) == SQLITE_ROW) - _view_map_record_current_location(self, sqlite3_column_int(stmt, 0)); + while(sqlite3_step(stmt) == SQLITE_ROW) _view_map_record_current_location(self, sqlite3_column_int(stmt, 0)); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT DISTINCT imgid FROM main.selected_images", -1, &stmt, NULL); - while(sqlite3_step(stmt) == SQLITE_ROW) - _view_map_add_image_to_map(self, sqlite3_column_int(stmt, 0), x, y); + while(sqlite3_step(stmt) == SQLITE_ROW) _view_map_add_image_to_map(self, sqlite3_column_int(stmt, 0), x, y); sqlite3_finalize(stmt); success = TRUE; } @@ -1239,8 +1239,8 @@ static void _view_map_dnd_get_callback(GtkWidget *widget, GdkDragContext *contex gboolean from_cache = TRUE; dt_image_full_path(imgid, pathname, sizeof(pathname), &from_cache); gchar *uri = g_strdup_printf("file://%s", pathname); // TODO: should we add the host? - gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data), _BYTE, - (guchar *)uri, strlen(uri)); + gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data), _BYTE, (guchar *)uri, + strlen(uri)); g_free(uri); break; } @@ -1307,8 +1307,8 @@ static void _view_map_build_main_query(dt_map_t *lib) "latitude NOT NULL ORDER BY ABS(latitude - ?5), ABS(longitude - ?6) LIMIT 0, %d) " "ORDER BY (180 - latitude), id", lib->filter_images_drawn - ? "main.images i INNER JOIN memory.collected_images c ON i.id = c.imgid" - : "main.images", + ? "main.images i INNER JOIN memory.collected_images c ON i.id = c.imgid" + : "main.images", lib->max_images_drawn); /* prepare the main query statement */ diff --git a/src/views/print.c b/src/views/print.c index 583b6c3a1e1a..66be54dc3bb5 100644 --- a/src/views/print.c +++ b/src/views/print.c @@ -43,11 +43,9 @@ typedef struct dt_print_t int32_t image_id; int32_t iwidth, iheight; dt_print_info_t *pinfo; -} -dt_print_t; +} dt_print_t; -const char -*name(dt_view_t *self) +const char *name(dt_view_t *self) { return C_("view", "print"); } @@ -64,13 +62,12 @@ static void _print_mipmaps_updated_signal_callback(gpointer instance, gpointer u static void _set_orientation(dt_print_t *prt) { - if (prt->image_id <= 0) - return; + if(prt->image_id <= 0) return; dt_mipmap_buffer_t buf; dt_mipmap_cache_get(darktable.mipmap_cache, &buf, prt->image_id, DT_MIPMAP_3, DT_MIPMAP_BEST_EFFORT, 'r'); - if (buf.width > buf.height) + if(buf.width > buf.height) prt->pinfo->page.landscape = TRUE; else prt->pinfo->page.landscape = FALSE; @@ -98,11 +95,11 @@ static void _film_strip_activated(const int imgid, void *data) dt_control_queue_redraw(); } -static void _view_print_filmstrip_activate_callback(gpointer instance,gpointer user_data) +static void _view_print_filmstrip_activate_callback(gpointer instance, gpointer user_data) { int32_t imgid = 0; - if ((imgid=dt_view_filmstrip_get_activated_imgid(darktable.view_manager))>0) - _film_strip_activated(imgid,user_data); + if((imgid = dt_view_filmstrip_get_activated_imgid(darktable.view_manager)) > 0) + _film_strip_activated(imgid, user_data); } static void _view_print_settings(const dt_view_t *view, dt_print_info_t *pinfo) @@ -113,8 +110,7 @@ static void _view_print_settings(const dt_view_t *view, dt_print_info_t *pinfo) dt_control_queue_redraw(); } -void -init(dt_view_t *self) +void init(dt_view_t *self) { self->data = malloc(sizeof(dt_print_t)); dt_print_t *prt = (dt_print_t *)self->data; @@ -135,24 +131,21 @@ void cleanup(dt_view_t *self) free(prt); } -static void expose_print_page(dt_view_t *self, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, int32_t pointery) +static void expose_print_page(dt_view_t *self, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, + int32_t pointery) { dt_print_t *prt = (dt_print_t *)self->data; - int32_t px=0, py=0, pwidth=0, pheight=0; - int32_t ax=0, ay=0, awidth=0, aheight=0; - int32_t ix=0, iy=0, iwidth=0, iheight=0; - int32_t iwpix=0, ihpix=0; - - if (prt->pinfo == NULL) - return; - - dt_get_print_layout (prt->image_id, prt->pinfo, width, height, - &iwpix, &ihpix, - &px, &py, &pwidth, &pheight, - &ax, &ay, &awidth, &aheight, - &ix, &iy, &iwidth, &iheight); + int32_t px = 0, py = 0, pwidth = 0, pheight = 0; + int32_t ax = 0, ay = 0, awidth = 0, aheight = 0; + int32_t ix = 0, iy = 0, iwidth = 0, iheight = 0; + int32_t iwpix = 0, ihpix = 0; + + if(prt->pinfo == NULL) return; + + dt_get_print_layout(prt->image_id, prt->pinfo, width, height, &iwpix, &ihpix, &px, &py, &pwidth, &pheight, &ax, + &ay, &awidth, &aheight, &ix, &iy, &iwidth, &iheight); // page w/h - double pg_width = prt->pinfo->paper.width; + double pg_width = prt->pinfo->paper.width; double pg_height = prt->pinfo->paper.height; // non-printable @@ -162,18 +155,18 @@ static void expose_print_page(dt_view_t *self, cairo_t *cr, int32_t width, int32 double np_bottom = prt->pinfo->printer.hw_margin_bottom; // handle the landscape mode if needed - if (prt->pinfo->page.landscape) + if(prt->pinfo->page.landscape) { double tmp = pg_width; pg_width = pg_height; pg_height = tmp; // rotate the non-printable margins - tmp = np_top; - np_top = np_right; - np_right = np_bottom; + tmp = np_top; + np_top = np_right; + np_right = np_bottom; np_bottom = np_left; - np_left = tmp; + np_left = tmp; } const int32_t pright = px + pwidth; @@ -181,12 +174,12 @@ static void expose_print_page(dt_view_t *self, cairo_t *cr, int32_t width, int32 // x page -> x display // (x / pg_width) * p_width + p_x - cairo_set_source_rgb (cr, 0.9, 0.9, 0.9); - cairo_rectangle (cr, px, py, pwidth, pheight); - cairo_fill (cr); + cairo_set_source_rgb(cr, 0.9, 0.9, 0.9); + cairo_rectangle(cr, px, py, pwidth, pheight); + cairo_fill(cr); // display non-printable area - cairo_set_source_rgb (cr, 0.1, 0.1, 0.1); + cairo_set_source_rgb(cr, 0.1, 0.1, 0.1); const int np1x = px + (np_left / pg_width) * pwidth; const int np1y = py + (np_top / pg_height) * pheight; @@ -194,53 +187,57 @@ static void expose_print_page(dt_view_t *self, cairo_t *cr, int32_t width, int32 const int np2y = pbottom - (np_bottom / pg_height) * pheight; // top-left - cairo_move_to (cr, np1x-10, np1y); - cairo_line_to (cr, np1x, np1y); cairo_line_to (cr, np1x, np1y-10); - cairo_stroke (cr); + cairo_move_to(cr, np1x - 10, np1y); + cairo_line_to(cr, np1x, np1y); + cairo_line_to(cr, np1x, np1y - 10); + cairo_stroke(cr); // top-right // npy = p_y + (np_top / pg_height) * p_height; - cairo_move_to (cr, np2x+10, np1y); - cairo_line_to (cr, np2x, np1y); cairo_line_to (cr, np2x, np1y-10); - cairo_stroke (cr); + cairo_move_to(cr, np2x + 10, np1y); + cairo_line_to(cr, np2x, np1y); + cairo_line_to(cr, np2x, np1y - 10); + cairo_stroke(cr); // bottom-left - cairo_move_to (cr, np1x-10, np2y); - cairo_line_to (cr, np1x, np2y); cairo_line_to (cr, np1x, np2y+10); - cairo_stroke (cr); + cairo_move_to(cr, np1x - 10, np2y); + cairo_line_to(cr, np1x, np2y); + cairo_line_to(cr, np1x, np2y + 10); + cairo_stroke(cr); // bottom-right - cairo_move_to (cr, np2x+10, np2y); - cairo_line_to (cr, np2x, np2y); cairo_line_to (cr, np2x, np2y+10); - cairo_stroke (cr); + cairo_move_to(cr, np2x + 10, np2y); + cairo_line_to(cr, np2x, np2y); + cairo_line_to(cr, np2x, np2y + 10); + cairo_stroke(cr); - // clip to this area to ensure that the image won't be larger, this is needed when using negative margin to enlarge the print + // clip to this area to ensure that the image won't be larger, this is needed when using negative margin to + // enlarge the print - cairo_rectangle (cr, np1x, np1y, np2x-np1x, np2y-np1y); + cairo_rectangle(cr, np1x, np1y, np2x - np1x, np2y - np1y); cairo_clip(cr); - cairo_set_source_rgb (cr, 0.77, 0.77, 0.77); - cairo_rectangle (cr, ax, ay, awidth, aheight); - cairo_fill (cr); + cairo_set_source_rgb(cr, 0.77, 0.77, 0.77); + cairo_rectangle(cr, ax, ay, awidth, aheight); + cairo_fill(cr); dt_view_image_only_expose(prt->image_id, cr, iwidth, iheight, ix, iy); } void expose(dt_view_t *self, cairo_t *cri, int32_t width_i, int32_t height_i, int32_t pointerx, int32_t pointery) { - const dt_print_t *prt=(dt_print_t*)self->data; + const dt_print_t *prt = (dt_print_t *)self->data; // clear the current surface - cairo_set_source_rgb (cri, 0.1, 0.1, 0.1); + cairo_set_source_rgb(cri, 0.1, 0.1, 0.1); cairo_paint(cri); - if (prt->image_id > 0) - expose_print_page (self, cri, width_i, height_i, pointerx, pointery); + if(prt->image_id > 0) expose_print_page(self, cri, width_i, height_i, pointerx, pointery); } int try_enter(dt_view_t *self) { - dt_print_t *prt=(dt_print_t*)self->data; + dt_print_t *prt = (dt_print_t *)self->data; // now check that there is at least one selected image @@ -294,7 +291,7 @@ int try_enter(dt_view_t *self) void enter(dt_view_t *self) { - dt_print_t *prt=(dt_print_t*)self->data; + dt_print_t *prt = (dt_print_t *)self->data; /* scroll filmstrip to the first selected image */ GList *selected_images = dt_collection_get_selected(darktable.collection, 1); @@ -309,13 +306,10 @@ void enter(dt_view_t *self) _set_orientation(prt); dt_control_signal_connect(darktable.signals, DT_SIGNAL_DEVELOP_MIPMAP_UPDATED, - G_CALLBACK(_print_mipmaps_updated_signal_callback), - (gpointer)self); + G_CALLBACK(_print_mipmaps_updated_signal_callback), (gpointer)self); - dt_control_signal_connect(darktable.signals, - DT_SIGNAL_VIEWMANAGER_FILMSTRIP_ACTIVATE, - G_CALLBACK(_view_print_filmstrip_activate_callback), - self); + dt_control_signal_connect(darktable.signals, DT_SIGNAL_VIEWMANAGER_FILMSTRIP_ACTIVATE, + G_CALLBACK(_view_print_filmstrip_activate_callback), self); gtk_widget_grab_focus(dt_ui_center(darktable.gui->ui)); @@ -333,8 +327,7 @@ void leave(dt_view_t *self) (gpointer)self); /* disconnect from filmstrip image activate */ - dt_control_signal_disconnect(darktable.signals, - G_CALLBACK(_view_print_filmstrip_activate_callback), + dt_control_signal_disconnect(darktable.signals, G_CALLBACK(_view_print_filmstrip_activate_callback), (gpointer)self); } diff --git a/src/views/slideshow.c b/src/views/slideshow.c index 033cd6a2cb78..5ed29051d8c0 100644 --- a/src/views/slideshow.c +++ b/src/views/slideshow.c @@ -186,8 +186,8 @@ static int process_next_image(dt_slideshow_t *d) const int high_quality = dt_conf_get_bool("plugins/slideshow/high_quality"); if(id) // the flags are: ignore exif, display byteorder, high quality, upscale, thumbnail - dt_imageio_export_with_flags(id, "unused", &buf, (dt_imageio_module_data_t *)&dat, 1, 1, high_quality, 1, 0, - 0, 0, DT_COLORSPACE_DISPLAY, NULL, DT_INTENT_LAST, NULL, NULL, 1, 1); + dt_imageio_export_with_flags(id, "unused", &buf, (dt_imageio_module_data_t *)&dat, 1, 1, high_quality, 1, 0, 0, + 0, DT_COLORSPACE_DISPLAY, NULL, DT_INTENT_LAST, NULL, NULL, 1, 1); return 0; } @@ -424,14 +424,15 @@ void expose(dt_view_t *self, cairo_t *cr, int32_t width, int32_t height, int32_t cairo_restore(cr); // pop control cairo_reset_clip(cr); cairo_save(cr); - cairo_translate(cr, (d->width - d->front_width) * .5f / darktable.gui->ppd, (d->height - d->front_height) * .5f / darktable.gui->ppd); + cairo_translate(cr, (d->width - d->front_width) * .5f / darktable.gui->ppd, + (d->height - d->front_height) * .5f / darktable.gui->ppd); cairo_surface_t *surface = NULL; const int32_t stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, d->front_width); surface = dt_cairo_image_surface_create_for_data((uint8_t *)d->front, CAIRO_FORMAT_RGB24, d->front_width, - d->front_height, stride); + d->front_height, stride); cairo_set_source_surface(cr, surface, 0, 0); cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST); - cairo_rectangle(cr, 0, 0, d->front_width/darktable.gui->ppd, d->front_height/darktable.gui->ppd); + cairo_rectangle(cr, 0, 0, d->front_width / darktable.gui->ppd, d->front_height / darktable.gui->ppd); cairo_fill(cr); cairo_surface_destroy(surface); cairo_restore(cr); @@ -455,8 +456,10 @@ void mouse_moved(dt_view_t *self, double x, double y, double pressure, int which { dt_slideshow_t *d = (dt_slideshow_t *)self->data; - if(d->mouse_timeout > 0) g_source_remove(d->mouse_timeout); - else dt_control_change_cursor(GDK_LEFT_PTR); + if(d->mouse_timeout > 0) + g_source_remove(d->mouse_timeout); + else + dt_control_change_cursor(GDK_LEFT_PTR); d->mouse_timeout = g_timeout_add_seconds(1, _hide_mouse, self); } diff --git a/src/views/tethering.c b/src/views/tethering.c index 8cb9abd18718..34700ebf9490 100644 --- a/src/views/tethering.c +++ b/src/views/tethering.c @@ -104,7 +104,7 @@ static void _view_capture_filmstrip_activate_callback(gpointer instance, gpointe } static gboolean film_strip_key_accel(GtkAccelGroup *accel_group, GObject *acceleratable, guint keyval, - GdkModifierType modifier, gpointer data) + GdkModifierType modifier, gpointer data) { dt_lib_module_t *m = darktable.view_manager->proxy.filmstrip.module; gboolean vs = dt_lib_is_visible(m); @@ -164,7 +164,7 @@ void configure(dt_view_t *self, int wd, int ht) #define MARGIN DT_PIXEL_APPLY_DPI(20) #define BAR_HEIGHT DT_PIXEL_APPLY_DPI(18) /* see libs/camera.c */ static void _expose_tethered_mode(dt_view_t *self, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, - int32_t pointery) + int32_t pointery) { dt_capture_t *lib = (dt_capture_t *)self->data; dt_camera_t *cam = (dt_camera_t *)darktable.camctl->active_camera; @@ -203,14 +203,13 @@ static void _expose_tethered_mode(dt_view_t *self, cairo_t *cr, int32_t width, i else if(lib->image_id >= 0) // First of all draw image if availble { cairo_translate(cr, MARGIN, MARGIN); - dt_view_image_expose(&(lib->image_over), lib->image_id, cr, width - (MARGIN * 2.0f), - height - (MARGIN * 2.0f), 1, pointerx, pointery, FALSE, FALSE); + dt_view_image_expose(&(lib->image_over), lib->image_id, cr, width - (MARGIN * 2.0f), height - (MARGIN * 2.0f), + 1, pointerx, pointery, FALSE, FALSE); } } -void expose(dt_view_t *self, cairo_t *cri, int32_t width, int32_t height, int32_t pointerx, - int32_t pointery) +void expose(dt_view_t *self, cairo_t *cri, int32_t width, int32_t height, int32_t pointerx, int32_t pointery) { cairo_set_source_rgb(cri, .2, .2, .2); cairo_rectangle(cri, 0, 0, width, height); diff --git a/src/views/view.c b/src/views/view.c index 7924023aa5a0..ecc2634a77d0 100644 --- a/src/views/view.c +++ b/src/views/view.c @@ -56,7 +56,8 @@ void dt_view_manager_init(dt_view_manager_t *vm) { /* prepare statements */ DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT imgid FROM main.selected_images " - "WHERE imgid = ?1", -1, &vm->statements.is_selected, NULL); + "WHERE imgid = ?1", + -1, &vm->statements.is_selected, NULL); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "DELETE FROM main.selected_images WHERE imgid = ?1", -1, &vm->statements.delete_from_selected, NULL); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), @@ -110,7 +111,7 @@ const dt_view_t *dt_view_manager_get_current_view(dt_view_manager_t *vm) // anything not hardcoded will be put alphabetically wrt. localised names. static gint sort_views(gconstpointer a, gconstpointer b) { - static const char *view_order[] = {"lighttable", "darkroom"}; + static const char *view_order[] = { "lighttable", "darkroom" }; static const int n_view_order = G_N_ELEMENTS(view_order); dt_view_t *av = (dt_view_t *)a; @@ -179,20 +180,15 @@ static int dt_view_load_module(void *v, const char *libname, const char *module_ if(!g_module_symbol(view->module, "enter", (gpointer) & (view->enter))) view->enter = NULL; if(!g_module_symbol(view->module, "leave", (gpointer) & (view->leave))) view->leave = NULL; if(!g_module_symbol(view->module, "reset", (gpointer) & (view->reset))) view->reset = NULL; - if(!g_module_symbol(view->module, "mouse_enter", (gpointer) & (view->mouse_enter))) - view->mouse_enter = NULL; - if(!g_module_symbol(view->module, "mouse_leave", (gpointer) & (view->mouse_leave))) - view->mouse_leave = NULL; - if(!g_module_symbol(view->module, "mouse_moved", (gpointer) & (view->mouse_moved))) - view->mouse_moved = NULL; + if(!g_module_symbol(view->module, "mouse_enter", (gpointer) & (view->mouse_enter))) view->mouse_enter = NULL; + if(!g_module_symbol(view->module, "mouse_leave", (gpointer) & (view->mouse_leave))) view->mouse_leave = NULL; + if(!g_module_symbol(view->module, "mouse_moved", (gpointer) & (view->mouse_moved))) view->mouse_moved = NULL; if(!g_module_symbol(view->module, "button_released", (gpointer) & (view->button_released))) view->button_released = NULL; if(!g_module_symbol(view->module, "button_pressed", (gpointer) & (view->button_pressed))) view->button_pressed = NULL; - if(!g_module_symbol(view->module, "key_pressed", (gpointer) & (view->key_pressed))) - view->key_pressed = NULL; - if(!g_module_symbol(view->module, "key_released", (gpointer) & (view->key_released))) - view->key_released = NULL; + if(!g_module_symbol(view->module, "key_pressed", (gpointer) & (view->key_pressed))) view->key_pressed = NULL; + if(!g_module_symbol(view->module, "key_released", (gpointer) & (view->key_released))) view->key_released = NULL; if(!g_module_symbol(view->module, "configure", (gpointer) & (view->configure))) view->configure = NULL; if(!g_module_symbol(view->module, "scrolled", (gpointer) & (view->scrolled))) view->scrolled = NULL; if(!g_module_symbol(view->module, "init_key_accels", (gpointer) & (view->init_key_accels))) @@ -237,18 +233,18 @@ void dt_vm_remove_child(GtkWidget *widget, gpointer data) When expanders get destoyed, they destroy the child so remove the child before that */ -static void _remove_child(GtkWidget *child,GtkContainer *container) +static void _remove_child(GtkWidget *child, GtkContainer *container) { - if(DTGTK_IS_EXPANDER(child)) - { - GtkWidget * evb = dtgtk_expander_get_body_event_box(DTGTK_EXPANDER(child)); - gtk_container_remove(GTK_CONTAINER(evb),dtgtk_expander_get_body(DTGTK_EXPANDER(child))); - gtk_widget_destroy(child); - } - else - { - gtk_container_remove(container,child); - } + if(DTGTK_IS_EXPANDER(child)) + { + GtkWidget *evb = dtgtk_expander_get_body_event_box(DTGTK_EXPANDER(child)); + gtk_container_remove(GTK_CONTAINER(evb), dtgtk_expander_get_body(DTGTK_EXPANDER(child))); + gtk_widget_destroy(child); + } + else + { + gtk_container_remove(container, child); + } } static void bitness_nagging() @@ -265,18 +261,17 @@ static void bitness_nagging() flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT; dialog = gtk_dialog_new_with_buttons( _("you are making a mistake!"), GTK_WINDOW(dt_ui_main_window(darktable.gui->ui)), flags, - _("_yes, i understood. please let me suffer by using 32-bit darktable."), GTK_RESPONSE_NONE, - NULL); + _("_yes, i understood. please let me suffer by using 32-bit darktable."), GTK_RESPONSE_NONE, NULL); #ifdef GDK_WINDOWING_QUARTZ dt_osx_disallow_fullscreen(dialog); #endif content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); const gchar *msg = _("warning!\nyou are using a 32-bit build of darktable.\nthe 32-bit build has " - "severely limited virtual address space.\nwe have had numerous reports that " - "darktable exhibits sporadic issues and crashes when using 32-bit builds.\nwe " - "strongly recommend you switch to a proper 64-bit build.\notherwise, you are " - "GUARANTEED to experience issues which cannot be fixed.\n"); + "severely limited virtual address space.\nwe have had numerous reports that " + "darktable exhibits sporadic issues and crashes when using 32-bit builds.\nwe " + "strongly recommend you switch to a proper 64-bit build.\notherwise, you are " + "GUARANTEED to experience issues which cannot be fixed.\n"); gtk_container_add(GTK_CONTAINER(content_area), gtk_label_new(msg)); gtk_widget_show_all(dialog); @@ -357,8 +352,7 @@ int dt_view_manager_switch_by_view(dt_view_manager_t *vm, const dt_view_t *nv) } /* remove all widgets in all containers */ - for(int l = 0; l < DT_UI_CONTAINER_SIZE; l++) - dt_ui_container_destroy_children(darktable.gui->ui, l); + for(int l = 0; l < DT_UI_CONTAINER_SIZE; l++) dt_ui_container_destroy_children(darktable.gui->ui, l); vm->current_view = NULL; return 0; } @@ -399,7 +393,7 @@ int dt_view_manager_switch_by_view(dt_view_manager_t *vm, const dt_view_t *nv) /* remove all widets in all containers */ for(int l = 0; l < DT_UI_CONTAINER_SIZE; l++) - dt_ui_container_foreach(darktable.gui->ui, l,(GtkCallback)_remove_child); + dt_ui_container_foreach(darktable.gui->ui, l, (GtkCallback)_remove_child); } /* change current view to the new view */ @@ -493,8 +487,8 @@ const char *dt_view_manager_name(dt_view_manager_t *vm) return vm->current_view->module_name; } -void dt_view_manager_expose(dt_view_manager_t *vm, cairo_t *cr, int32_t width, int32_t height, - int32_t pointerx, int32_t pointery) +void dt_view_manager_expose(dt_view_manager_t *vm, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, + int32_t pointery) { if(!vm->current_view) { @@ -605,8 +599,8 @@ int dt_view_manager_button_released(dt_view_manager_t *vm, double x, double y, i return 0; } -int dt_view_manager_button_pressed(dt_view_manager_t *vm, double x, double y, double pressure, int which, - int type, uint32_t state) +int dt_view_manager_button_pressed(dt_view_manager_t *vm, double x, double y, double pressure, int which, int type, + uint32_t state) { if(!vm->current_view) return 0; dt_view_t *v = vm->current_view; @@ -636,18 +630,8 @@ int dt_view_manager_key_pressed(dt_view_manager_t *vm, guint key, guint state) { // ↑ ↑ ↓ ↓ ← → ← → b a static int konami_state = 0; - static guint konami_sequence[] = { - GDK_KEY_Up, - GDK_KEY_Up, - GDK_KEY_Down, - GDK_KEY_Down, - GDK_KEY_Left, - GDK_KEY_Right, - GDK_KEY_Left, - GDK_KEY_Right, - GDK_KEY_b, - GDK_KEY_a - }; + static guint konami_sequence[] = { GDK_KEY_Up, GDK_KEY_Up, GDK_KEY_Down, GDK_KEY_Down, GDK_KEY_Left, + GDK_KEY_Right, GDK_KEY_Left, GDK_KEY_Right, GDK_KEY_b, GDK_KEY_a }; if(key == konami_sequence[konami_state]) { konami_state++; @@ -782,8 +766,8 @@ int32_t dt_view_get_image_to_act_on() // it only affects the selection. const int32_t mouse_over_id = dt_control_get_mouse_over_id(); - const int zoom = darktable.view_manager->proxy.lighttable.get_images_in_row( - darktable.view_manager->proxy.lighttable.view); + const int zoom + = darktable.view_manager->proxy.lighttable.get_images_in_row(darktable.view_manager->proxy.lighttable.view); const int full_preview_id = darktable.view_manager->proxy.lighttable.get_full_preview_id( darktable.view_manager->proxy.lighttable.view); @@ -809,13 +793,14 @@ int32_t dt_view_get_image_to_act_on() } int dt_view_image_expose(dt_view_image_over_t *image_over, uint32_t imgid, cairo_t *cr, int32_t width, - int32_t height, int32_t zoom, int32_t px, int32_t py, gboolean full_preview, gboolean image_only) + int32_t height, int32_t zoom, int32_t px, int32_t py, gboolean full_preview, + gboolean image_only) { int missing = 0; const double start = dt_get_wtime(); -// some performance tuning stuff, for your pleasure. -// on my machine with 7 image per row it seems grouping has the largest -// impact from around 400ms -> 55ms per redraw. + // some performance tuning stuff, for your pleasure. + // on my machine with 7 image per row it seems grouping has the largest + // impact from around 400ms -> 55ms per redraw. // active if zoom>1 or in the proper area const gboolean in_metadata_zone = (px < width && py < height / 2) || (zoom > 1); @@ -833,9 +818,10 @@ int dt_view_image_expose(dt_view_image_over_t *image_over, uint32_t imgid, cairo float bgcol = 0.4, fontcol = 0.425, bordercol = 0.1, outlinecol = 0.2; int selected = 0, is_grouped = 0; // this is a gui thread only thing. no mutex required: - const int imgsel = dt_control_get_mouse_over_id(); // darktable.control->global_settings.lib_image_mouse_over_id; + const int imgsel + = dt_control_get_mouse_over_id(); // darktable.control->global_settings.lib_image_mouse_over_id; - if (draw_selected) + if(draw_selected) { /* clear and reset statements */ DT_DEBUG_SQLITE3_CLEAR_BINDINGS(darktable.view_manager->statements.is_selected); @@ -872,7 +858,7 @@ int dt_view_image_expose(dt_view_image_over_t *image_over, uint32_t imgid, cairo } float imgwd = 0.90f; - if (image_only) + if(image_only) { imgwd = 1.0; } @@ -926,19 +912,17 @@ int dt_view_image_expose(dt_view_image_over_t *image_over, uint32_t imgid, cairo pango_cairo_show_layout(cr, layout); pango_font_description_free(desc); g_object_unref(layout); - } } dt_mipmap_buffer_t buf; - dt_mipmap_size_t mip - = dt_mipmap_cache_get_matching_size(darktable.mipmap_cache, imgwd * width, imgwd * height); + dt_mipmap_size_t mip = dt_mipmap_cache_get_matching_size(darktable.mipmap_cache, imgwd * width, imgwd * height); dt_mipmap_cache_get(darktable.mipmap_cache, &buf, imgid, mip, DT_MIPMAP_BEST_EFFORT, 'r'); // if we got a different mip than requested, and it's not a skull (8x8 px), we count // this thumbnail as missing (to trigger re-exposure) if(buf.size != mip && buf.width != 8 && buf.height != 8) missing = 1; - if (draw_thumb) + if(draw_thumb) { float scale = 1.0; @@ -957,14 +941,14 @@ int dt_view_image_expose(dt_view_image_over_t *image_over, uint32_t imgid, cairo pthread_rwlock_rdlock(&darktable.color_profiles->xprofile_lock); have_lock = TRUE; - // we only color manage when a thumbnail is sRGB or AdobeRGB. everything else just gets dumped to the screen - if(buf.color_space == DT_COLORSPACE_SRGB && - darktable.color_profiles->transform_srgb_to_display) + // we only color manage when a thumbnail is sRGB or AdobeRGB. everything else just gets dumped to the + // screen + if(buf.color_space == DT_COLORSPACE_SRGB && darktable.color_profiles->transform_srgb_to_display) { transform = darktable.color_profiles->transform_srgb_to_display; } - else if(buf.color_space == DT_COLORSPACE_ADOBERGB && - darktable.color_profiles->transform_adobe_rgb_to_display) + else if(buf.color_space == DT_COLORSPACE_ADOBERGB + && darktable.color_profiles->transform_adobe_rgb_to_display) { transform = darktable.color_profiles->transform_adobe_rgb_to_display; } @@ -978,14 +962,15 @@ int dt_view_image_expose(dt_view_image_over_t *image_over, uint32_t imgid, cairo } else if(buf.color_space != DT_COLORSPACE_DISPLAY) { - fprintf(stderr, "oops, there seems to be a code path setting an unhandled color space of thumbnails (%s)!\n", + fprintf(stderr, + "oops, there seems to be a code path setting an unhandled color space of thumbnails (%s)!\n", dt_colorspaces_get_name(buf.color_space, "from file")); } } } #ifdef _OPENMP - #pragma omp parallel for schedule(static) default(none) shared(buf, rgbbuf, transform) +#pragma omp parallel for schedule(static) default(none) shared(buf, rgbbuf, transform) #endif for(int i = 0; i < buf.height; i++) { @@ -1009,8 +994,7 @@ int dt_view_image_expose(dt_view_image_over_t *image_over, uint32_t imgid, cairo if(have_lock) pthread_rwlock_unlock(&darktable.color_profiles->xprofile_lock); const int32_t stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, buf.width); - surface - = cairo_image_surface_create_for_data(rgbbuf, CAIRO_FORMAT_RGB24, buf.width, buf.height, stride); + surface = cairo_image_surface_create_for_data(rgbbuf, CAIRO_FORMAT_RGB24, buf.width, buf.height, stride); } if(zoom == 1 && !image_only) @@ -1025,7 +1009,7 @@ int dt_view_image_expose(dt_view_image_over_t *image_over, uint32_t imgid, cairo // draw centered and fitted: cairo_save(cr); - if (image_only) // in this case we want to display the picture exactly at (px, py) + if(image_only) // in this case we want to display the picture exactly at (px, py) cairo_translate(cr, px, py); else cairo_translate(cr, width / 2.0, height / 2.0); @@ -1034,7 +1018,7 @@ int dt_view_image_expose(dt_view_image_over_t *image_over, uint32_t imgid, cairo if(buf.buf && surface) { - if (!image_only) cairo_translate(cr, -0.5 * buf.width, -0.5 * buf.height); + if(!image_only) cairo_translate(cr, -0.5 * buf.width, -0.5 * buf.height); cairo_set_source_surface(cr, surface, 0, 0); // set filter no nearest: // in skull mode, we want to see big pixels. @@ -1051,7 +1035,7 @@ int dt_view_image_expose(dt_view_image_over_t *image_over, uint32_t imgid, cairo free(rgbbuf); - if (image_only) + if(image_only) { cairo_restore(cr); cairo_save(cr); @@ -1279,7 +1263,7 @@ int dt_view_image_expose(dt_view_image_over_t *image_over, uint32_t imgid, cairo // kill all paths, in case img was not loaded yet, or is blocked: cairo_new_path(cr); - if (draw_colorlabels) + if(draw_colorlabels) { // TODO: make mouse sensitive, just as stars! // TODO: cache in image struct! @@ -1310,7 +1294,7 @@ int dt_view_image_expose(dt_view_image_over_t *image_over, uint32_t imgid, cairo } } - if (draw_local_copy) + if(draw_local_copy) { if(img && width > DECORATION_SIZE_LIMIT) { @@ -1353,12 +1337,11 @@ int dt_view_image_expose(dt_view_image_over_t *image_over, uint32_t imgid, cairo cairo_fill(cr); pango_font_description_free(desc); g_object_unref(layout); - } // draw custom metadata from accompanying text file: - if(draw_metadata && img && (img->flags & DT_IMAGE_HAS_TXT) && dt_conf_get_bool("plugins/lighttable/draw_custom_metadata") - && (zoom == 1)) + if(draw_metadata && img && (img->flags & DT_IMAGE_HAS_TXT) + && dt_conf_get_bool("plugins/lighttable/draw_custom_metadata") && (zoom == 1)) { char *path = dt_image_get_text_path(img->id); if(path) @@ -1397,7 +1380,6 @@ int dt_view_image_expose(dt_view_image_over_t *image_over, uint32_t imgid, cairo fclose(f); pango_font_description_free(desc); g_object_unref(layout); - } g_free(path); } @@ -1412,14 +1394,8 @@ int dt_view_image_expose(dt_view_image_over_t *image_over, uint32_t imgid, cairo return missing; } -void -dt_view_image_only_expose( - uint32_t imgid, - cairo_t *cr, - int32_t width, - int32_t height, - int32_t offsetx, - int32_t offsety) +void dt_view_image_only_expose(uint32_t imgid, cairo_t *cr, int32_t width, int32_t height, int32_t offsetx, + int32_t offsety) { dt_view_image_over_t image_over; dt_view_image_expose(&image_over, imgid, cr, width, height, 1, offsetx, offsety, TRUE, TRUE); @@ -1694,8 +1670,7 @@ gboolean dt_view_map_remove_marker(const dt_view_manager_t *vm, dt_geo_map_displ #ifdef HAVE_PRINT void dt_view_print_settings(const dt_view_manager_t *vm, dt_print_info_t *pinfo) { - if (vm->proxy.print.view) - vm->proxy.print.print_settings(vm->proxy.print.view, pinfo); + if(vm->proxy.print.view) vm->proxy.print.print_settings(vm->proxy.print.view, pinfo); } #endif diff --git a/src/views/view.h b/src/views/view.h index 4b9257db8e02..782435a058cc 100644 --- a/src/views/view.h +++ b/src/views/view.h @@ -46,7 +46,7 @@ control which view the module should be available in also which placement in the panels the module have. */ -typedef enum +typedef enum { DT_VIEW_LIGHTTABLE = 1, DT_VIEW_DARKROOM = 2, @@ -61,12 +61,12 @@ typedef enum typedef enum dt_view_flags_t { VIEW_FLAGS_NONE = 0, - VIEW_FLAGS_HIDDEN = 1 << 0, // Hide the view from userinterface + VIEW_FLAGS_HIDDEN = 1 << 0, // Hide the view from userinterface } dt_view_flags_t; -#define DT_VIEW_ALL \ - (DT_VIEW_LIGHTTABLE | DT_VIEW_DARKROOM | DT_VIEW_TETHERING | DT_VIEW_MAP | DT_VIEW_SLIDESHOW | \ - DT_VIEW_PRINT | DT_VIEW_KNIGHT) +#define DT_VIEW_ALL \ + (DT_VIEW_LIGHTTABLE | DT_VIEW_DARKROOM | DT_VIEW_TETHERING | DT_VIEW_MAP | DT_VIEW_SLIDESHOW | DT_VIEW_PRINT \ + | DT_VIEW_KNIGHT) /** * main dt view module (as lighttable or darkroom) @@ -95,9 +95,9 @@ typedef struct dt_view_t void (*expose)(struct dt_view_t *self, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, int32_t pointery); // expose the module (gtk callback) int (*try_enter)(struct dt_view_t *self); // test if enter can succeed. - void (*enter)(struct dt_view_t *self); // mode entered, this module got focus. return non-null on failure. - void (*leave)(struct dt_view_t *self); // mode left (is called after the new try_enter has succeded). - void (*reset)(struct dt_view_t *self); // reset default appearance + void (*enter)(struct dt_view_t *self); // mode entered, this module got focus. return non-null on failure. + void (*leave)(struct dt_view_t *self); // mode left (is called after the new try_enter has succeded). + void (*reset)(struct dt_view_t *self); // reset default appearance // event callbacks: void (*mouse_enter)(struct dt_view_t *self); @@ -138,19 +138,14 @@ int32_t dt_view_get_image_to_act_on(); /** expose an image, set image over flags. return != 0 if thumbnail wasn't loaded yet. */ int dt_view_image_expose(dt_view_image_over_t *image_over, uint32_t index, cairo_t *cr, int32_t width, - int32_t height, int32_t zoom, int32_t px, int32_t py, gboolean full_preview, gboolean image_only); + int32_t height, int32_t zoom, int32_t px, int32_t py, gboolean full_preview, + gboolean image_only); /* expose only the image imgid at position (offsetx,offsety) into the cairo surface occupying width/height pixels. this routine does not output any meta-data as the version above. */ -void -dt_view_image_only_expose( - uint32_t imgid, - cairo_t *cr, - int32_t width, - int32_t height, - int32_t offsetx, - int32_t offsety); +void dt_view_image_only_expose(uint32_t imgid, cairo_t *cr, int32_t width, int32_t height, int32_t offsetx, + int32_t offsety); /** Set the selection bit to a given value for the specified image */ @@ -198,7 +193,7 @@ typedef struct dt_view_manager_t struct { struct dt_lib_module_t *module; - void (*add)(struct dt_lib_module_t *, GtkWidget *, dt_view_type_flags_t ); + void (*add)(struct dt_lib_module_t *, GtkWidget *, dt_view_type_flags_t); } view_toolbox; /* module toolbox proxy object */ @@ -274,7 +269,7 @@ typedef struct dt_view_manager_t } map; #endif - /* map view proxy object */ +/* map view proxy object */ #ifdef HAVE_PRINT struct { @@ -297,8 +292,8 @@ const char *dt_view_manager_name(dt_view_manager_t *vm); int dt_view_manager_switch(dt_view_manager_t *vm, const char *view_name); int dt_view_manager_switch_by_view(dt_view_manager_t *vm, const dt_view_t *new_view); /** expose current module. */ -void dt_view_manager_expose(dt_view_manager_t *vm, cairo_t *cr, int32_t width, int32_t height, - int32_t pointerx, int32_t pointery); +void dt_view_manager_expose(dt_view_manager_t *vm, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, + int32_t pointery); /** reset current view. */ void dt_view_manager_reset(dt_view_manager_t *vm); /** get current view of the view manager. */ @@ -308,8 +303,8 @@ void dt_view_manager_mouse_enter(dt_view_manager_t *vm); void dt_view_manager_mouse_leave(dt_view_manager_t *vm); void dt_view_manager_mouse_moved(dt_view_manager_t *vm, double x, double y, double pressure, int which); int dt_view_manager_button_released(dt_view_manager_t *vm, double x, double y, int which, uint32_t state); -int dt_view_manager_button_pressed(dt_view_manager_t *vm, double x, double y, double pressure, int which, - int type, uint32_t state); +int dt_view_manager_button_pressed(dt_view_manager_t *vm, double x, double y, double pressure, int which, int type, + uint32_t state); int dt_view_manager_key_pressed(dt_view_manager_t *vm, guint key, guint state); int dt_view_manager_key_released(dt_view_manager_t *vm, guint key, guint state); void dt_view_manager_configure(dt_view_manager_t *vm, int width, int height); @@ -375,7 +370,8 @@ void dt_view_filmstrip_prefetch(); */ #ifdef HAVE_MAP void dt_view_map_center_on_location(const dt_view_manager_t *vm, gdouble lon, gdouble lat, gdouble zoom); -void dt_view_map_center_on_bbox(const dt_view_manager_t *vm, gdouble lon1, gdouble lat1, gdouble lon2, gdouble lat2); +void dt_view_map_center_on_bbox(const dt_view_manager_t *vm, gdouble lon1, gdouble lat1, gdouble lon2, + gdouble lat2); void dt_view_map_show_osd(const dt_view_manager_t *vm, gboolean enabled); void dt_view_map_set_map_source(const dt_view_manager_t *vm, OsmGpsMapSource_t map_source); GObject *dt_view_map_add_marker(const dt_view_manager_t *vm, dt_geo_map_display_t type, GList *points); diff --git a/src/win/getrusage.h b/src/win/getrusage.h index 5fc8fb479b32..ccf3e06eab78 100644 --- a/src/win/getrusage.h +++ b/src/win/getrusage.h @@ -28,23 +28,24 @@ #include <sys/time.h> /* for struct timeval */ -struct rusage { - struct timeval ru_utime; /* user CPU time used */ - struct timeval ru_stime; /* system CPU time used */ - long ru_maxrss; /* maximum resident set size */ - long ru_ixrss; /* integral shared memory size */ - long ru_idrss; /* integral unshared data size */ - long ru_isrss; /* integral unshared stack size */ - long ru_minflt; /* page reclaims (soft page faults) */ - long ru_majflt; /* page faults (hard page faults) */ - long ru_nswap; /* swaps */ - long ru_inblock; /* block input operations */ - long ru_oublock; /* block output operations */ - long ru_msgsnd; /* IPC messages sent */ - long ru_msgrcv; /* IPC messages received */ - long ru_nsignals; /* signals received */ - long ru_nvcsw; /* voluntary context switches */ - long ru_nivcsw; /* involuntary context switches */ +struct rusage +{ + struct timeval ru_utime; /* user CPU time used */ + struct timeval ru_stime; /* system CPU time used */ + long ru_maxrss; /* maximum resident set size */ + long ru_ixrss; /* integral shared memory size */ + long ru_idrss; /* integral unshared data size */ + long ru_isrss; /* integral unshared stack size */ + long ru_minflt; /* page reclaims (soft page faults) */ + long ru_majflt; /* page faults (hard page faults) */ + long ru_nswap; /* swaps */ + long ru_inblock; /* block input operations */ + long ru_oublock; /* block output operations */ + long ru_msgsnd; /* IPC messages sent */ + long ru_msgrcv; /* IPC messages received */ + long ru_nsignals; /* signals received */ + long ru_nvcsw; /* voluntary context switches */ + long ru_nivcsw; /* involuntary context switches */ }; #ifndef RUSAGE_SELF diff --git a/src/win/main_wrapper.h b/src/win/main_wrapper.h index 3737d9f41197..60252213d7c6 100644 --- a/src/win/main_wrapper.h +++ b/src/win/main_wrapper.h @@ -10,8 +10,7 @@ int main(int argc, char *argv[]); int wmain(int argc, wchar_t *argv[]) { char **_argv = g_malloc0((argc + 1) * sizeof(char *)); - for(int i = 0; i < argc; i++) - _argv[i] = g_utf16_to_utf8(argv[i], -1, NULL, NULL, NULL); + for(int i = 0; i < argc; i++) _argv[i] = g_utf16_to_utf8(argv[i], -1, NULL, NULL, NULL); int res = main(argc, _argv); g_strfreev(_argv); return res; diff --git a/src/win/statvfs.c b/src/win/statvfs.c index 2add4726036d..441a107b41cd 100644 --- a/src/win/statvfs.c +++ b/src/win/statvfs.c @@ -66,7 +66,7 @@ int statvfs(const char *path, struct statvfs *buf) wchar_t *wszDrive = g_utf8_to_utf16(szDrive, -1, NULL, NULL, NULL); res = GetDiskFreeSpaceW(wszDrive, &lpSectorsPerCluster, &lpBytesPerSector, &lpNumberOfFreeClusters, - &lpTotalNumberOfClusters); + &lpTotalNumberOfClusters); g_free(wszDrive); diff --git a/tools/iop_dependencies.py b/tools/iop_dependencies.py index e6409e348a9d..6581c82ec725 100755 --- a/tools/iop_dependencies.py +++ b/tools/iop_dependencies.py @@ -68,6 +68,7 @@ def add_edges(gr): gr.add_edge(('demosaic', 'rawdenoise')) gr.add_edge(('demosaic', 'cacorrect')) + # highlights come directly after whitebalance gr.add_edge(('highlights', 'temperature')) @@ -75,11 +76,13 @@ def add_edges(gr): gr.add_edge(('hotpixels', 'cacorrect')) gr.add_edge(('rawdenoise', 'cacorrect')) + # all these need white balanced and clipped input: gr.add_edge(('rawdenoise', 'highlights')) gr.add_edge(('hotpixels', 'highlights')) gr.add_edge(('cacorrect', 'highlights')) + # we want cropped and B/W rescaled pixels, # after after uint16 -> float conversion gr.add_edge(('temperature', 'rawprepare')) @@ -96,6 +99,7 @@ def add_edges(gr): # these need to be in camera color space (linear input rgb): gr.add_edge(('colorin', 'exposure')) gr.add_edge(('colorin', 'highlights')) + gr.add_edge(('colorin', 'rlucy_deblur')) gr.add_edge(('colorin', 'graduatednd')) gr.add_edge(('colorin', 'basecurve')) gr.add_edge(('colorin', 'lens')) @@ -124,7 +128,7 @@ def add_edges(gr): gr.add_edge(('flip', 'spots')) gr.add_edge(('flip', 'liquify')) gr.add_edge(('flip', 'ashift')) - + # ashift wants a lens corrected image with straight lines. # therefore lens shoucl come before and liquify should come after ashift gr.add_edge(('ashift', 'lens')) @@ -479,6 +483,11 @@ def add_edges(gr): gr.add_edge(('colorbalance', 'vibrance')) gr.add_edge(('colorize', 'vibrance')) + gr.add_edge(('exposure', 'rlucy_deblur')) + gr.add_edge(('rlucy_deblur', 'demosaic')) + gr.add_edge(('tonemap', 'rlucy_deblur')) + + gr = digraph() gr.add_nodes([ 'atrous', @@ -535,6 +544,7 @@ def add_edges(gr): 'relight', 'scalepixels', 'rotatepixels', + 'rlucy_deblur', 'shadhi', 'sharpen', 'soften',