From c4be9ed19990dfcd99a0070fcc8bc19aa3353d1b Mon Sep 17 00:00:00 2001 From: Pascal Obry Date: Mon, 29 Apr 2024 07:45:51 +0200 Subject: [PATCH] Rework the tests for empty glist check. Introduce a macro g_list_is_empty() and used it. It is clearer to read: if(g_list_is_empty(list)) than if(!list) Also change some check for singleton by g_list_is_singleton(). --- src/common/collection.c | 6 +- src/common/colorlabels.c | 5 +- src/common/darktable.h | 23 +++++ src/common/metadata.c | 18 ++-- src/common/metadata_export.c | 5 +- src/common/ratings.c | 31 +++++-- src/common/styles.c | 6 +- src/common/tags.c | 14 +-- src/common/utility.h | 23 ----- src/develop/masks/brush.c | 3 +- src/dtgtk/range.c | 17 ++-- src/libs/export_metadata.c | 5 +- src/libs/modulegroups.c | 19 +++-- src/libs/styles.c | 2 +- src/views/tethering.c | 160 ++++++++++++++++++++++++++--------- 15 files changed, 225 insertions(+), 112 deletions(-) diff --git a/src/common/collection.c b/src/common/collection.c index c40aa3d2dd91..f64ec7298892 100644 --- a/src/common/collection.c +++ b/src/common/collection.c @@ -1996,7 +1996,7 @@ static gchar *get_query_string(const dt_collection_properties_t property, const g_free(name); // free the original filename } - if(list) subquery = dt_util_glist_to_str(" OR ", list); + if(!g_list_is_empty(list)) subquery = dt_util_glist_to_str(" OR ", list); g_list_free_full(list, g_free); // free the SQL clauses as well as the list } if(g_strv_length(elems) > 1) @@ -2031,7 +2031,7 @@ static gchar *get_query_string(const dt_collection_properties_t property, const g_free(name); // free the original filename } - if(list) + if(!g_list_is_empty(list)) { if(subquery) { @@ -2518,7 +2518,7 @@ void dt_collection_update_query(const dt_collection_t *collection, if(!collection->clone) { - if(list) + if(!g_list_is_empty(list)) { // for changing offsets, thumbtable needs to know the first // untouched imageid after the list we do this here diff --git a/src/common/colorlabels.c b/src/common/colorlabels.c index 96a2dcdb98c8..c3d08e72571b 100644 --- a/src/common/colorlabels.c +++ b/src/common/colorlabels.c @@ -224,10 +224,11 @@ void dt_colorlabels_set_labels(const GList *img, const gboolean clear_on, const gboolean undo_on) { - if(img) + if(!g_list_is_empty(img)) { GList *undo = NULL; - if(undo_on) dt_undo_start_group(darktable.undo, DT_UNDO_COLORLABELS); + if(undo_on) + dt_undo_start_group(darktable.undo, DT_UNDO_COLORLABELS); _colorlabels_execute(img, labels, &undo, undo_on, clear_on ? DT_CA_SET : DT_CA_ADD); diff --git a/src/common/darktable.h b/src/common/darktable.h index fa5b86618f8f..f2ee52df483d 100644 --- a/src/common/darktable.h +++ b/src/common/darktable.h @@ -798,6 +798,7 @@ static inline void copy_pixel(float *const __restrict__ out, // a few macros and helper functions to speed up certain frequently-used GLib operations #define g_list_is_singleton(list) ((list) && (!(list)->next)) +#define g_list_is_empty(list) (!list) static inline gboolean g_list_shorter_than(const GList *list, unsigned len) @@ -833,6 +834,28 @@ static inline const GList *g_list_prev_wraparound(const GList *list) return g_list_previous(list) ? g_list_previous(list) : g_list_last((GList*)list); } +// returns true if the two GLists have the same length +static inline gboolean dt_list_length_equal(GList *l1, GList *l2) +{ + while (l1 && l2) + { + l1 = g_list_next(l1); + l2 = g_list_next(l2); + } + return !l1 && !l2; +} + +// returns true if the two GSLists have the same length +static inline gboolean dt_slist_length_equal(GSList *l1, GSList *l2) +{ + while (l1 && l2) + { + l1 = g_slist_next(l1); + l2 = g_slist_next(l2); + } + return !l1 && !l2; +} + // checks internally for DT_DEBUG_MEMORY void dt_print_mem_usage(); diff --git a/src/common/metadata.c b/src/common/metadata.c index 8357e371c212..83c27d745b69 100644 --- a/src/common/metadata.c +++ b/src/common/metadata.c @@ -594,7 +594,10 @@ static void _metadata_execute(const GList *imgs, const GList *metadata, GList ** } } -void dt_metadata_set(const dt_imgid_t imgid, const char *key, const char *value, const gboolean undo_on) +void dt_metadata_set(const dt_imgid_t imgid, + const char *key, + const char *value, + const gboolean undo_on) { if(!key || !imgid) return; @@ -606,7 +609,7 @@ void dt_metadata_set(const dt_imgid_t imgid, const char *key, const char *value, imgs = dt_act_on_get_images(TRUE, TRUE, FALSE); else imgs = g_list_prepend(imgs, GINT_TO_POINTER(imgid)); - if(imgs) + if(!g_list_is_empty(imgs)) { GList *undo = NULL; if(undo_on) dt_undo_start_group(darktable.undo, DT_UNDO_METADATA); @@ -650,7 +653,7 @@ void dt_metadata_set_import(const dt_imgid_t imgid, const char *key, const char { GList *imgs = NULL; imgs = g_list_prepend(imgs, GINT_TO_POINTER(imgid)); - if(imgs) + if(!g_list_is_empty(imgs)) { GList *undo = NULL; @@ -705,7 +708,8 @@ void dt_metadata_set_list(const GList *imgs, GList *key_value, const gboolean un if(undo_on) { - dt_undo_record(darktable.undo, NULL, DT_UNDO_METADATA, undo, _pop_undo, _metadata_undo_data_free); + dt_undo_record(darktable.undo, NULL, + DT_UNDO_METADATA, undo, _pop_undo, _metadata_undo_data_free); dt_undo_end_group(darktable.undo); } @@ -751,10 +755,12 @@ void dt_metadata_clear(const GList *imgs, const gboolean undo_on) } } -void dt_metadata_set_list_id(const GList *img, const GList *metadata, const gboolean clear_on, +void dt_metadata_set_list_id(const GList *img, + const GList *metadata, + const gboolean clear_on, const gboolean undo_on) { - if(img) + if(!g_list_is_empty(img)) { GList *undo = NULL; if(undo_on) dt_undo_start_group(darktable.undo, DT_UNDO_METADATA); diff --git a/src/common/metadata_export.c b/src/common/metadata_export.c index 906e40acbe07..ac42339bfbfa 100644 --- a/src/common/metadata_export.c +++ b/src/common/metadata_export.c @@ -77,13 +77,13 @@ void dt_lib_export_metadata_set_conf(const char *metadata_presets) int i = 0; char *conf_keyword = NULL; char *nameformula = NULL; - if(list) + if(!g_list_is_empty(list)) { char *flags_hexa = list->data; dt_conf_set_string(flags_keyword, flags_hexa); list = g_list_remove(list, flags_hexa); g_free(flags_hexa); - if(list) + if(!g_list_is_empty(list)) { for(GList *tags = list; tags; tags = g_list_next(tags)) { @@ -120,4 +120,3 @@ void dt_lib_export_metadata_set_conf(const char *metadata_presets) // vim: shiftwidth=2 expandtab tabstop=2 cindent // kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified; // clang-format on - diff --git a/src/common/ratings.c b/src/common/ratings.c index e08477a554e3..8ff06b405051 100644 --- a/src/common/ratings.c +++ b/src/common/ratings.c @@ -103,7 +103,10 @@ static void _ratings_undo_data_free(gpointer data) } // wrapper that does some precalculation to deal with toggle effects and rating increase/decrease -static void _ratings_apply(const GList *imgs, const int rating, GList **undo, const gboolean undo_on) +static void _ratings_apply(const GList *imgs, + const int rating, + GList **undo, + const gboolean undo_on) { // REJECTION and SINGLE_STAR rating can have a toggle effect // but we only toggle off if ALL images have that rating @@ -177,9 +180,11 @@ static void _ratings_apply(const GList *imgs, const int rating, GList **undo, co } } -void dt_ratings_apply_on_list(const GList *img, const int rating, const gboolean undo_on) +void dt_ratings_apply_on_list(const GList *img, + const int rating, + const gboolean undo_on) { - if(img) + if(!g_list_is_empty(img)) { GList *undo = NULL; if(undo_on) dt_undo_start_group(darktable.undo, DT_UNDO_RATINGS); @@ -195,15 +200,19 @@ void dt_ratings_apply_on_list(const GList *img, const int rating, const gboolean } } -void dt_ratings_apply_on_image(const dt_imgid_t imgid, const int rating, const gboolean single_star_toggle, - const gboolean undo_on, const gboolean group_on) +void dt_ratings_apply_on_image(const dt_imgid_t imgid, + const int rating, + const gboolean single_star_toggle, + const gboolean undo_on, + const gboolean group_on) { GList *imgs = NULL; int new_rating = rating; - if(dt_is_valid_imgid(imgid)) imgs = g_list_prepend(imgs, GINT_TO_POINTER(imgid)); + if(dt_is_valid_imgid(imgid)) + imgs = g_list_prepend(imgs, GINT_TO_POINTER(imgid)); - if(imgs) + if(!g_list_is_empty(imgs)) { GList *undo = NULL; if(undo_on) dt_undo_start_group(darktable.undo, DT_UNDO_RATINGS); @@ -213,7 +222,8 @@ void dt_ratings_apply_on_image(const dt_imgid_t imgid, const int rating, const g if(undo_on) { - dt_undo_record(darktable.undo, NULL, DT_UNDO_RATINGS, undo, _pop_undo, _ratings_undo_data_free); + dt_undo_record(darktable.undo, NULL, + DT_UNDO_RATINGS, undo, _pop_undo, _ratings_undo_data_free); dt_undo_end_group(darktable.undo); } g_list_free(imgs); @@ -229,7 +239,10 @@ enum DT_ACTION_EFFECT_DOWNGRADE = DT_ACTION_EFFECT_DEFAULT_DOWN, }; -static float _action_process_rating(gpointer target, dt_action_element_t element, dt_action_effect_t effect, float move_size) +static float _action_process_rating(gpointer target, + dt_action_element_t element, + dt_action_effect_t effect, + float move_size) { float return_value = DT_ACTION_NOT_VALID; diff --git a/src/common/styles.c b/src/common/styles.c index 47f902cee8c6..b95c53b7df4b 100644 --- a/src/common/styles.c +++ b/src/common/styles.c @@ -703,17 +703,17 @@ void dt_multiple_styles_apply_to_list(GList *styles, if(dt_view_get_current() == DT_VIEW_DARKROOM) dt_dev_write_history(darktable.develop); - if(!styles && !list) + if(g_list_is_empty(styles) && g_list_is_empty(list)) { dt_control_log(_("no images nor styles selected!")); return; } - else if(!styles) + else if(g_list_is_empty(styles)) { dt_control_log(_("no styles selected!")); return; } - else if(!list) + else if(g_list_is_empty(list)) { dt_control_log(_("no image selected!")); return; diff --git a/src/common/tags.c b/src/common/tags.c index 8d01ae403a37..2d701ee5ae70 100644 --- a/src/common/tags.c +++ b/src/common/tags.c @@ -470,12 +470,13 @@ gboolean dt_tag_attach_images(const guint tagid, const GList *img, const gboolean undo_on) { - if(!img) return FALSE; + if(g_list_is_empty(img)) return FALSE; GList *undo = NULL; GList *tags = NULL; tags = g_list_prepend(tags, GINT_TO_POINTER(tagid)); - if(undo_on) dt_undo_start_group(darktable.undo, DT_UNDO_TAGS); + if(undo_on) + dt_undo_start_group(darktable.undo, DT_UNDO_TAGS); const gboolean res = _tag_execute(tags, img, &undo, undo_on, DT_TA_ATTACH); @@ -518,10 +519,11 @@ gboolean dt_tag_set_tags(const GList *tags, const gboolean clear_on, const gboolean undo_on) { - if(img) + if(!g_list_is_empty(img)) { GList *undo = NULL; - if(undo_on) dt_undo_start_group(darktable.undo, DT_UNDO_TAGS); + if(undo_on) + dt_undo_start_group(darktable.undo, DT_UNDO_TAGS); const gboolean res = _tag_execute (tags, img, &undo, undo_on, @@ -563,7 +565,7 @@ gboolean dt_tag_attach_string_list(const gchar *tags, } // attach newly created tags - if(img) + if(!g_list_is_empty(img)) { GList *undo = NULL; if(undo_on) dt_undo_start_group(darktable.undo, DT_UNDO_TAGS); @@ -587,7 +589,7 @@ gboolean dt_tag_detach_images(const guint tagid, const GList *img, const gboolean undo_on) { - if(img) + if(!g_list_is_empty(img)) { GList *tags = NULL; tags = g_list_prepend(tags, GINT_TO_POINTER(tagid)); diff --git a/src/common/utility.h b/src/common/utility.h index 4d239ad93ff8..26834c479826 100644 --- a/src/common/utility.h +++ b/src/common/utility.h @@ -128,29 +128,6 @@ gboolean dt_is_scene_referred(void); // returns true if current settings is display-referred gboolean dt_is_display_referred(void); -// returns true if the two GLists have the same length -static inline gboolean dt_list_length_equal(GList *l1, GList *l2) -{ - while (l1 && l2) - { - l1 = g_list_next(l1); - l2 = g_list_next(l2); - } - return !l1 && !l2; -} - -// returns true if the two GSLists have the same length -static inline gboolean dt_slist_length_equal(GSList *l1, GSList *l2) -{ - while (l1 && l2) - { - l1 = g_slist_next(l1); - l2 = g_slist_next(l2); - } - return !l1 && !l2; -} - - G_END_DECLS // clang-format off diff --git a/src/develop/masks/brush.c b/src/develop/masks/brush.c index b5ab9c56d348..2503bf6d8ce2 100644 --- a/src/develop/masks/brush.c +++ b/src/develop/masks/brush.c @@ -328,7 +328,8 @@ static void _brush_catmull_to_bezier(const float x1, static void _brush_init_ctrl_points(dt_masks_form_t *form) { // if we have less than 2 points, what to do ?? - if(g_list_shorter_than(form->points, 2)) return; + if(g_list_shorter_than(form->points, 2)) + return; // we need extra points to deal with curve ends dt_masks_point_brush_t start_point[2], end_point[2]; diff --git a/src/dtgtk/range.c b/src/dtgtk/range.c index 23e13d6cb22d..78c99fd3127e 100644 --- a/src/dtgtk/range.c +++ b/src/dtgtk/range.c @@ -151,17 +151,24 @@ static void _range_select_destroy(GtkWidget *widget) DT_DEBUG_CONTROL_SIGNAL_DISCONNECT(darktable.signals, G_CALLBACK(_dt_pref_changed), range); - if(range->markers) g_list_free_full(range->markers, g_free); + if(!g_list_is_empty(range->markers)) + g_list_free_full(range->markers, g_free); range->markers = NULL; - if(range->blocks) g_list_free_full(range->blocks, g_free); + + if(!g_list_is_empty(range->blocks)) + g_list_free_full(range->blocks, g_free); range->blocks = NULL; - if(range->icons) g_list_free_full(range->icons, g_free); + + if(!g_list_is_empty(range->icons)) + g_list_free_full(range->icons, g_free); range->icons = NULL; - if(range->surface) cairo_surface_destroy(range->surface); + if(range->surface) + cairo_surface_destroy(range->surface); range->surface = NULL; - if(range->cur_help) g_free(range->cur_help); + if(range->cur_help) + g_free(range->cur_help); range->cur_help = NULL; GTK_WIDGET_CLASS(dtgtk_range_select_parent_class)->destroy(widget); diff --git a/src/libs/export_metadata.c b/src/libs/export_metadata.c index 450536717191..1105d0262d4d 100644 --- a/src/libs/export_metadata.c +++ b/src/libs/export_metadata.c @@ -387,13 +387,13 @@ char *dt_lib_export_metadata_configuration_dialog(char *metadata_presets, const d->taglist = (GList *)dt_exif_get_exiv2_taglist(); GList *list = dt_util_str_to_glist("\1", metadata_presets); int32_t flags = 0; - if(list) + if(!g_list_is_empty(list)) { char *flags_hexa = list->data; flags = strtol(flags_hexa, NULL, 16); list = g_list_remove(list, flags_hexa); g_free(flags_hexa); - if(list) + if(!g_list_is_empty(list)) { for(GList *tags = list; tags; tags = g_list_next(tags)) { @@ -484,4 +484,3 @@ char *dt_lib_export_metadata_configuration_dialog(char *metadata_presets, const // vim: shiftwidth=2 expandtab tabstop=2 cindent // kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified; // clang-format on - diff --git a/src/libs/modulegroups.c b/src/libs/modulegroups.c index 9f79fff99d52..ebae653ffda5 100644 --- a/src/libs/modulegroups.c +++ b/src/libs/modulegroups.c @@ -3027,8 +3027,11 @@ static void _buttons_update(dt_lib_module_t *self) // first, we destroy all existing buttons except active one an preset one GList *children = gtk_container_get_children(GTK_CONTAINER(d->hbox_groups)); GList *l = children; - if(l) l = g_list_next(l); // skip basics group - if(l) l = g_list_next(l); // skip active group + if(!g_list_is_empty(l)) + l = g_list_next(l); // skip basics group + if(!g_list_is_empty(l)) + l = g_list_next(l); // skip active group + for(; l; l = g_list_next(l)) { GtkWidget *bt = (GtkWidget *)l->data; @@ -3163,7 +3166,9 @@ static void _manage_editor_group_remove(GtkWidget *widget, { dt_lib_modulegroups_t *d = (dt_lib_modulegroups_t *)self->data; // we don't allow to remove the last group if no quick access or searchbox - if(g_list_length(d->edit_groups) == 1 && !d->edit_basics_show && !d->edit_show_search) + if(g_list_is_singleton(d->edit_groups) + && !d->edit_basics_show + && !d->edit_show_search) { return; } @@ -3531,7 +3536,9 @@ static void _manage_editor_basics_toggle(GtkWidget *button, if(d->editor_reset) return; const gboolean state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)); // we don't allow that to be false if there's no group or search - if(!state && !d->edit_groups && !d->edit_show_search) + if(!state + && g_list_is_empty(d->edit_groups) + && !d->edit_show_search) { d->editor_reset = TRUE; gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); @@ -3548,7 +3555,9 @@ static void _manage_editor_search_toggle(GtkWidget *button, if(d->editor_reset) return; const gboolean state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)); // we don't allow that to be false if there's no group or quick access - if(!state && !d->edit_groups && !d->edit_basics_show) + if(!state + && g_list_is_empty(d->edit_groups) + && !d->edit_basics_show) { d->editor_reset = TRUE; gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); diff --git a/src/libs/styles.c b/src/libs/styles.c index eddde6f16adb..0442eb7ba8a1 100644 --- a/src/libs/styles.c +++ b/src/libs/styles.c @@ -273,7 +273,7 @@ static void _apply_clicked(GtkWidget *w, gpointer user_data) GList *list = dt_act_on_get_images(TRUE, TRUE, FALSE); - if(list) + if(!g_list_is_empty(list)) dt_multiple_styles_apply_to_list (style_names, list, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(d->duplicate))); diff --git a/src/views/tethering.c b/src/views/tethering.c index 62351e5305ee..fcc39b2dc45e 100644 --- a/src/views/tethering.c +++ b/src/views/tethering.c @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2014-2023 darktable developers. + Copyright (C) 2014-2024 darktable developers. darktable is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -91,7 +91,9 @@ typedef struct dt_capture_t } dt_capture_t; /* signal handler for filmstrip image switching */ -static void _view_capture_filmstrip_activate_callback(gpointer instance, dt_imgid_t imgid, gpointer user_data); +static void _view_capture_filmstrip_activate_callback(gpointer instance, + dt_imgid_t imgid, + gpointer user_data); static void _capture_view_set_jobcode(const dt_view_t *view, const char *name); static const char *_capture_view_get_jobcode(const dt_view_t *view); @@ -107,7 +109,9 @@ uint32_t view(const dt_view_t *self) return DT_VIEW_TETHERING; } -static void _view_capture_filmstrip_activate_callback(gpointer instance, dt_imgid_t imgid, gpointer user_data) +static void _view_capture_filmstrip_activate_callback(gpointer instance, + dt_imgid_t imgid, + gpointer user_data) { dt_view_t *self = (dt_view_t *)user_data; dt_capture_t *lib = (dt_capture_t *)self->data; @@ -132,7 +136,8 @@ void init(dt_view_t *self) darktable.view_manager->proxy.tethering.view = self; darktable.view_manager->proxy.tethering.get_job_code = _capture_view_get_jobcode; darktable.view_manager->proxy.tethering.set_job_code = _capture_view_set_jobcode; - darktable.view_manager->proxy.tethering.get_selected_imgid = _capture_view_get_selected_imgid; + darktable.view_manager->proxy.tethering.get_selected_imgid = + _capture_view_get_selected_imgid; } void cleanup(dt_view_t *self) @@ -148,7 +153,8 @@ static int32_t _capture_view_get_selected_imgid(const dt_view_t *view) return cv->image_id; } -static void _capture_view_set_jobcode(const dt_view_t *view, const char *name) +static void _capture_view_set_jobcode(const dt_view_t *view, + const char *name) { g_assert(view != NULL); dt_capture_t *cv = (dt_capture_t *)view->data; @@ -190,10 +196,18 @@ static int _tethering_bpp(dt_imageio_module_data_t *data) return 32; } -static int _tethering_write_image(dt_imageio_module_data_t *data, const char *filename, const void *in, - dt_colorspaces_color_profile_type_t over_type, const char *over_filename, - void *exif, int exif_len, dt_imgid_t imgid, int num, int total, - dt_dev_pixelpipe_t *pipe, const gboolean export_masks) +static int _tethering_write_image(dt_imageio_module_data_t *data, + const char *filename, + const void *in, + dt_colorspaces_color_profile_type_t over_type, + const char *over_filename, + void *exif, + int exif_len, + dt_imgid_t imgid, + int num, + int total, + dt_dev_pixelpipe_t *pipe, + const gboolean export_masks) { _tethering_format_t *d = (_tethering_format_t *)data; d->buf = (float *)malloc(sizeof(float) * 4 * d->head.width * d->head.height); @@ -210,7 +224,11 @@ static gboolean _expose_again(gpointer user_data) return FALSE; } -static void _expose_tethered_mode(dt_view_t *self, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, +static void _expose_tethered_mode(dt_view_t *self, + cairo_t *cr, + int32_t width, + int32_t height, + int32_t pointerx, int32_t pointery) { dt_capture_t *lib = (dt_capture_t *)self->data; @@ -219,7 +237,9 @@ static void _expose_tethered_mode(dt_view_t *self, cairo_t *cr, int32_t width, i lib->image_over = DT_VIEW_DESERT; GSList *l = dt_view_active_images_get(); - if(l) lib->image_id = GPOINTER_TO_INT(l->data); + + if(!g_list_is_empty(l)) + lib->image_id = GPOINTER_TO_INT(l->data); lib->image_over = lib->image_id; @@ -239,12 +259,14 @@ static void _expose_tethered_mode(dt_view_t *self, cairo_t *cr, int32_t width, i const int stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, pw); pthread_rwlock_rdlock(&darktable.color_profiles->xprofile_lock); // FIXME: if liveview image is tagged and we can read its colorspace, use that - cmsDoTransformLineStride(darktable.color_profiles->transform_srgb_to_display, p_buf, tmp_i, pw, ph, pw * 4, + cmsDoTransformLineStride(darktable.color_profiles->transform_srgb_to_display, + p_buf, tmp_i, pw, ph, pw * 4, stride, 0, 0); pthread_rwlock_unlock(&darktable.color_profiles->xprofile_lock); cairo_surface_t *source - = dt_cairo_image_surface_create_for_data(tmp_i, CAIRO_FORMAT_RGB24, pw, ph, stride); + = dt_cairo_image_surface_create_for_data(tmp_i, CAIRO_FORMAT_RGB24, + pw, ph, stride); if(cairo_surface_status(source) == CAIRO_STATUS_SUCCESS) { const float w = width - (MARGIN * 2.0f); @@ -284,14 +306,19 @@ static void _expose_tethered_mode(dt_view_t *self, cairo_t *cr, int32_t width, i for(size_t p = 0; p < (size_t)4 * pw * ph; p += 4) { uint32_t DT_ALIGNED_ARRAY state[4] - = { splitmix32(p + 1), splitmix32((p + 1) * (p + 3)), splitmix32(1337), splitmix32(666) }; + = { splitmix32(p + 1), + splitmix32((p + 1) * (p + 3)), + splitmix32(1337), + splitmix32(666) }; + xoshiro128plus(state); xoshiro128plus(state); xoshiro128plus(state); xoshiro128plus(state); for(int k = 0; k < 3; k++) - tmp_f[p + k] = dt_noise_generator(DT_NOISE_UNIFORM, p_buf[p + k], 0.5f, 0, state) / 255.0f; + tmp_f[p + k] = + dt_noise_generator(DT_NOISE_UNIFORM, p_buf[p + k], 0.5f, 0, state) / 255.0f; } // We need to do special cases for work/export colorspace @@ -299,14 +326,17 @@ static void _expose_tethered_mode(dt_view_t *self, cairo_t *cr, int32_t width, i // when not in darkroom view. const dt_iop_order_iccprofile_info_t *profile_to = NULL; const dt_iop_order_iccprofile_info_t *const srgb_profile = - dt_ioppr_add_profile_info_to_list(dev, DT_COLORSPACE_SRGB, "", DT_INTENT_RELATIVE_COLORIMETRIC); + dt_ioppr_add_profile_info_to_list(dev, DT_COLORSPACE_SRGB, "", + DT_INTENT_RELATIVE_COLORIMETRIC); if(darktable.color_profiles->histogram_type == DT_COLORSPACE_WORK) { // The work profile of a SOC JPEG is nonsensical. So that // the histogram will have some relationship to a captured // image's profile, go with the standard work profile. // FIXME: can figure out the current default work colorspace via checking presets? - profile_to = dt_ioppr_add_profile_info_to_list(dev, DT_COLORSPACE_LIN_REC2020, "", DT_INTENT_RELATIVE_COLORIMETRIC); + profile_to = dt_ioppr_add_profile_info_to_list(dev, + DT_COLORSPACE_LIN_REC2020, "", + DT_INTENT_RELATIVE_COLORIMETRIC); } else if(darktable.color_profiles->histogram_type == DT_COLORSPACE_EXPORT) { @@ -321,7 +351,8 @@ static void _expose_tethered_mode(dt_view_t *self, cairo_t *cr, int32_t width, i } // FIXME: if liveview image is tagged and we can read its colorspace, use that - darktable.lib->proxy.histogram.process(darktable.lib->proxy.histogram.module, tmp_f, pw, ph, + darktable.lib->proxy.histogram.process(darktable.lib->proxy.histogram.module, + tmp_f, pw, ph, srgb_profile, profile_to); dt_control_queue_redraw_widget(darktable.lib->proxy.histogram.module->widget); dt_free_align(tmp_f); @@ -333,8 +364,9 @@ static void _expose_tethered_mode(dt_view_t *self, cairo_t *cr, int32_t width, i { // FIXME: every time the mouse moves over the center view this redraws, which isn't necessary cairo_surface_t *surf = NULL; - const dt_view_surface_value_t res = dt_view_image_get_surface(lib->image_id, width - (MARGIN * 2.0f), - height - (MARGIN * 2.0f), &surf, FALSE); + const dt_view_surface_value_t res = + dt_view_image_get_surface(lib->image_id, width - (MARGIN * 2.0f), + height - (MARGIN * 2.0f), &surf, FALSE); if(res != DT_VIEW_SURFACE_OK) { // if the image is missing, we reload it again @@ -394,13 +426,20 @@ static void _expose_tethered_mode(dt_view_t *self, cairo_t *cr, int32_t width, i // as we're not competing with the full pixelpipe, it's a // reasonable trade-off for a histogram which matches that in // darkroom view - // FIXME: instead export image in work profile, then pass that to histogram process as well as converting to display profile for output, eliminating dt_view_image_get_surface() above - if(!dt_imageio_export_with_flags(lib->image_id, "unused", &format, (dt_imageio_module_data_t *)&dat, TRUE, - FALSE, FALSE, FALSE, FALSE, FALSE, NULL, FALSE, FALSE, histogram_type, histogram_filename, + + // FIXME: instead export image in work profile, then pass that to + // histogram process as well as converting to display profile for + // output, eliminating dt_view_image_get_surface() above + + if(!dt_imageio_export_with_flags(lib->image_id, "unused", + &format, (dt_imageio_module_data_t *)&dat, TRUE, + FALSE, FALSE, FALSE, FALSE, FALSE, NULL, + FALSE, FALSE, histogram_type, histogram_filename, DT_INTENT_PERCEPTUAL, NULL, NULL, 1, 1, NULL, -1)) { const dt_iop_order_iccprofile_info_t *const histogram_profile = - dt_ioppr_add_profile_info_to_list(darktable.develop, histogram_type, histogram_filename, + dt_ioppr_add_profile_info_to_list(darktable.develop, histogram_type, + histogram_filename, DT_INTENT_RELATIVE_COLORIMETRIC); darktable.lib->proxy.histogram.process(darktable.lib->proxy.histogram.module, dat.buf, dat.head.width, dat.head.height, @@ -412,13 +451,19 @@ static void _expose_tethered_mode(dt_view_t *self, cairo_t *cr, int32_t width, i else // not in live view, no image selected { // if we just left live view, blank out its histogram - darktable.lib->proxy.histogram.process(darktable.lib->proxy.histogram.module, NULL, 0, 0, NULL, NULL); + darktable.lib->proxy.histogram.process(darktable.lib->proxy.histogram.module, + NULL, 0, 0, NULL, NULL); dt_control_queue_redraw_widget(darktable.lib->proxy.histogram.module->widget); } } -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); @@ -432,7 +477,9 @@ void expose(dt_view_t *self, cairo_t *cri, int32_t width, int32_t height, int32_ cairo_restore(cri); // post expose to modules - for(const GList *modules = darktable.lib->plugins; modules; modules = g_list_next(modules)) + for(const GList *modules = darktable.lib->plugins; + modules; + modules = g_list_next(modules)) { dt_lib_module_t *module = (dt_lib_module_t *)(modules->data); if(module->gui_post_expose && dt_lib_is_visible_in_view(module, self)) @@ -449,7 +496,9 @@ gboolean try_enter(dt_view_t *self) return TRUE; } -static void _capture_mipmaps_updated_signal_callback(gpointer instance, dt_imgid_t imgid, gpointer user_data) +static void _capture_mipmaps_updated_signal_callback(gpointer instance, + dt_imgid_t imgid, + gpointer user_data) { dt_view_t *self = (dt_view_t *)user_data; struct dt_capture_t *lib = (dt_capture_t *)self->data; @@ -464,8 +513,10 @@ static void _capture_mipmaps_updated_signal_callback(gpointer instance, dt_imgid /** callbacks to deal with images taken in tethering mode */ -static const char *_camera_request_image_filename(const dt_camera_t *camera, const char *filename, - const dt_image_basic_exif_t *basic_exif, void *data) +static const char *_camera_request_image_filename(const dt_camera_t *camera, + const char *filename, + const dt_image_basic_exif_t *basic_exif, + void *data) { struct dt_capture_t *lib = (dt_capture_t *)data; @@ -479,20 +530,26 @@ static const char *_camera_request_image_filename(const dt_camera_t *camera, con return g_strdup(file); } -static const char *_camera_request_image_path(const dt_camera_t *camera, const dt_image_basic_exif_t *basic_exif, void *data) +static const char *_camera_request_image_path(const dt_camera_t *camera, + const dt_image_basic_exif_t *basic_exif, + void *data) { struct dt_capture_t *lib = (dt_capture_t *)data; return dt_import_session_path(lib->session, FALSE); } -static void _camera_capture_image_downloaded(const dt_camera_t *camera, const char *in_folder, - const char *in_filename, const char *filename, void *data) +static void _camera_capture_image_downloaded(const dt_camera_t *camera, + const char *in_folder, + const char *in_filename, + const char *filename, + void *data) { dt_capture_t *lib = (dt_capture_t *)data; /* create an import job of downloaded image */ dt_control_add_job(darktable.control, DT_JOB_QUEUE_USER_BG, - dt_image_import_job_create(dt_import_session_film_id(lib->session), filename)); + dt_image_import_job_create(dt_import_session_film_id(lib->session), + filename)); } @@ -520,12 +577,15 @@ void enter(dt_view_t *self) /* connect signal for mipmap update for a redraw */ DT_DEBUG_CONTROL_SIGNAL_CONNECT(darktable.signals, DT_SIGNAL_DEVELOP_MIPMAP_UPDATED, - G_CALLBACK(_capture_mipmaps_updated_signal_callback), (gpointer)self); + G_CALLBACK(_capture_mipmaps_updated_signal_callback), + (gpointer)self); /* connect signal for fimlstrip image activate */ - DT_DEBUG_CONTROL_SIGNAL_CONNECT(darktable.signals, DT_SIGNAL_VIEWMANAGER_THUMBTABLE_ACTIVATE, - G_CALLBACK(_view_capture_filmstrip_activate_callback), self); + DT_DEBUG_CONTROL_SIGNAL_CONNECT(darktable.signals, + DT_SIGNAL_VIEWMANAGER_THUMBTABLE_ACTIVATE, + G_CALLBACK(_view_capture_filmstrip_activate_callback), + self); // register listener lib->listener = g_malloc0(sizeof(dt_camctl_listener_t)); @@ -548,11 +608,13 @@ void leave(dt_view_t *self) dt_import_session_destroy(cv->session); /* disconnect from mipmap updated signal */ - DT_DEBUG_CONTROL_SIGNAL_DISCONNECT(darktable.signals, G_CALLBACK(_capture_mipmaps_updated_signal_callback), + DT_DEBUG_CONTROL_SIGNAL_DISCONNECT(darktable.signals, + G_CALLBACK(_capture_mipmaps_updated_signal_callback), (gpointer)self); /* disconnect from filmstrip image activate */ - DT_DEBUG_CONTROL_SIGNAL_DISCONNECT(darktable.signals, G_CALLBACK(_view_capture_filmstrip_activate_callback), + DT_DEBUG_CONTROL_SIGNAL_DISCONNECT(darktable.signals, + G_CALLBACK(_view_capture_filmstrip_activate_callback), (gpointer)self); } @@ -561,7 +623,11 @@ void reset(dt_view_t *self) // dt_control_set_mouse_over_id(NO_IMGID); } -void mouse_moved(dt_view_t *self, double x, double y, double pressure, int which) +void mouse_moved(dt_view_t *self, + double x, + double y, + double pressure, + int which) { dt_capture_t *lib = (dt_capture_t *)self->data; dt_camera_t *cam = (dt_camera_t *)darktable.camctl->active_camera; @@ -601,7 +667,13 @@ void mouse_moved(dt_view_t *self, double x, double y, double pressure, int which dt_control_queue_redraw_center(); } -int button_pressed(dt_view_t *self, double x, double y, double pressure, int which, int type, uint32_t state) +int button_pressed(dt_view_t *self, + double x, + double y, + double pressure, + int which, + int type, + uint32_t state) { dt_camera_t *cam = (dt_camera_t *)darktable.camctl->active_camera; dt_capture_t *lib = (dt_capture_t *)self->data; @@ -626,7 +698,11 @@ int button_pressed(dt_view_t *self, double x, double y, double pressure, int whi return 0; } -int button_released(dt_view_t *self, double x, double y, int which, uint32_t state) +int button_released(dt_view_t *self, + double x, + double y, + int which, + uint32_t state) { dt_camera_t *cam = (dt_camera_t *)darktable.camctl->active_camera; if(which == 1)