From 83dfc4cd6dc9446efb4230b411151ade9cb73607 Mon Sep 17 00:00:00 2001 From: wpferguson Date: Wed, 25 Sep 2024 12:55:06 -0400 Subject: [PATCH 1/2] fix dt_imageio_export_with_flags return values (#17529) * src/imageio/imageio.c - changed dt_imageio_export_with_flags to return TRUE on success and FALSE on error. Since dt_imageio_export calls dt_imageio_export_with_flags to do the actual export, dt_imageio_export now returns TRUE for success and FALSE for error. src/imageio/storage/disk.c src/imageio/storage/email.c src/imageio/storage/gallery.c src/imageio/storage/pwigo.c src/lua/luastorage.c - updated the places where dt_imageio_export was called to use the boolean return value for success tests. --- src/imageio/imageio.c | 4 ++-- src/imageio/storage/disk.c | 4 ++-- src/imageio/storage/email.c | 4 ++-- src/imageio/storage/gallery.c | 8 ++++---- src/imageio/storage/piwigo.c | 4 ++-- src/lua/luastorage.c | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/imageio/imageio.c b/src/imageio/imageio.c index a9418da15a65..4b1b725ed482 100644 --- a/src/imageio/imageio.c +++ b/src/imageio/imageio.c @@ -1244,7 +1244,7 @@ gboolean dt_imageio_export_with_flags(const dt_imgid_t imgid, if(!thumbnail_export) dt_set_backthumb_time(5.0); - return FALSE; // success + return TRUE; // success error: dt_dev_pixelpipe_cleanup(&pipe); @@ -1254,7 +1254,7 @@ gboolean dt_imageio_export_with_flags(const dt_imgid_t imgid, if(!thumbnail_export) dt_set_backthumb_time(5.0); - return TRUE; + return FALSE; } diff --git a/src/imageio/storage/disk.c b/src/imageio/storage/disk.c index eec7945ff63c..6858a509a751 100644 --- a/src/imageio/storage/disk.c +++ b/src/imageio/storage/disk.c @@ -468,10 +468,10 @@ int store(dt_imageio_module_storage_t *self, if(fail) return 1; /* export image to file */ - if(dt_imageio_export(imgid, filename, format, fdata, high_quality, + if(!dt_imageio_export(imgid, filename, format, fdata, high_quality, upscale, TRUE, export_masks, icc_type, icc_filename, icc_intent, self, sdata, - num, total, metadata) != 0) + num, total, metadata)) { dt_print(DT_DEBUG_ALWAYS, "[imageio_storage_disk] could not export to file: `%s'!\n", diff --git a/src/imageio/storage/email.c b/src/imageio/storage/email.c index 966c33ddf4e9..265dff3520b4 100644 --- a/src/imageio/storage/email.c +++ b/src/imageio/storage/email.c @@ -176,9 +176,9 @@ int store(dt_imageio_module_storage_t *self, attachment->file = g_build_filename(tmpdir, dirname, (char *)NULL); - if(dt_imageio_export(imgid, attachment->file, format, fdata, high_quality, + if(!dt_imageio_export(imgid, attachment->file, format, fdata, high_quality, upscale, TRUE, export_masks, icc_type, - icc_filename, icc_intent, self, sdata, num, total, metadata) != 0) + icc_filename, icc_intent, self, sdata, num, total, metadata)) { dt_print(DT_DEBUG_ALWAYS, "[imageio_storage_email] could not export to file: `%s'!\n", diff --git a/src/imageio/storage/gallery.c b/src/imageio/storage/gallery.c index f87f21718eaa..ec7be79ca30f 100644 --- a/src/imageio/storage/gallery.c +++ b/src/imageio/storage/gallery.c @@ -399,9 +399,9 @@ int store(dt_imageio_module_storage_t *self, // export image to file. need this to be able to access meaningful // fdata->width and height below. - if(dt_imageio_export(imgid, filename, format, fdata, high_quality, + if(!dt_imageio_export(imgid, filename, format, fdata, high_quality, upscale, TRUE, export_masks, icc_type, - icc_filename, icc_intent, self, sdata, num, total, metadata) != 0) + icc_filename, icc_intent, self, sdata, num, total, metadata)) { dt_print(DT_DEBUG_ALWAYS, "[imageio_storage_gallery] could not export to file: `%s'!\n", filename); @@ -440,9 +440,9 @@ int store(dt_imageio_module_storage_t *self, 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, + if(!dt_imageio_export(imgid, filename, format, fdata, FALSE, TRUE, FALSE, export_masks, icc_type, icc_filename, - icc_intent, self, sdata, num, total, NULL) != 0) + icc_intent, self, sdata, num, total, NULL)) { dt_print(DT_DEBUG_ALWAYS, "[imageio_storage_gallery] could not export to file: `%s'!\n", filename); diff --git a/src/imageio/storage/piwigo.c b/src/imageio/storage/piwigo.c index b7d983eafbce..b90c208c5c65 100644 --- a/src/imageio/storage/piwigo.c +++ b/src/imageio/storage/piwigo.c @@ -1348,9 +1348,9 @@ int store(dt_imageio_module_storage_t *self, dt_image_cache_read_release(darktable.image_cache, img); - if(dt_imageio_export(imgid, fname, format, fdata, high_quality, upscale, + if(!dt_imageio_export(imgid, fname, format, fdata, high_quality, upscale, TRUE, export_masks, icc_type, icc_filename, - icc_intent, self, sdata, num, total, metadata) != 0) + icc_intent, self, sdata, num, total, metadata)) { dt_print(DT_DEBUG_ALWAYS, "[imageio_storage_piwigo] could not export to file: `%s'!\n", diff --git a/src/lua/luastorage.c b/src/lua/luastorage.c index 6611776defab..7df397ca2ccc 100644 --- a/src/lua/luastorage.c +++ b/src/lua/luastorage.c @@ -111,8 +111,8 @@ static int store_wrapper(struct dt_imageio_module_storage_t *self, gchar *complete_name = g_build_filename(tmpdir, filename, (char *)NULL); - if(dt_imageio_export(imgid, complete_name, format, fdata, high_quality, upscale, TRUE, export_masks, - icc_type, icc_filename, icc_intent, self, self_data, num, total, metadata) != 0) + if(!dt_imageio_export(imgid, complete_name, format, fdata, high_quality, upscale, TRUE, export_masks, + icc_type, icc_filename, icc_intent, self, self_data, num, total, metadata)) { dt_print(DT_DEBUG_ALWAYS, "[lua] %s: could not export to file `%s'!\n", self->name(self), complete_name); From a25fccc0afefc74251ecdcf70f1e953b7c840a45 Mon Sep 17 00:00:00 2001 From: Pascal Obry Date: Thu, 26 Sep 2024 07:09:40 +0200 Subject: [PATCH 2/2] Fix issue introduced by 7dc0faf by doing more cleanup in gboolean vs int. Fixes #17536 --- src/common/mipmap_cache.c | 13 +++++++------ src/dtgtk/thumbnail.c | 6 +++--- src/imageio/imageio.c | 28 ++++++++++++++-------------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/common/mipmap_cache.c b/src/common/mipmap_cache.c index 4a445e3c15fb..58c282d5cef3 100644 --- a/src/common/mipmap_cache.c +++ b/src/common/mipmap_cache.c @@ -1464,7 +1464,7 @@ static void _init_8(uint8_t *buf, uint8_t *tmp = 0; int32_t thumb_width, thumb_height; res = dt_imageio_large_thumbnail(filename, &tmp, &thumb_width, &thumb_height, color_space); - if(!res) + if(res) { // if the thumbnail is not large enough, we compute one const dt_image_t *img2 = dt_image_cache_get(darktable.image_cache, imgid, 'r'); @@ -1528,10 +1528,11 @@ static void _init_8(uint8_t *buf, // export with flags: ignore exif(don't load from disk), don't // swap byte order, don't do hq processing, no upscaling and // signal we want thumbnail export - res = dt_imageio_export_with_flags(imgid, "unused", &format, (dt_imageio_module_data_t *)&dat, TRUE, FALSE, FALSE, - FALSE, FALSE, TRUE, NULL, FALSE, FALSE, DT_COLORSPACE_NONE, NULL, DT_INTENT_LAST, NULL, - NULL, 1, 1, NULL, -1); - if(!res) + res = dt_imageio_export_with_flags + (imgid, "unused", &format, (dt_imageio_module_data_t *)&dat, TRUE, FALSE, FALSE, + FALSE, FALSE, TRUE, NULL, FALSE, FALSE, DT_COLORSPACE_NONE, NULL, DT_INTENT_LAST, + NULL, NULL, 1, 1, NULL, -1); + if(res) { dt_print(DT_DEBUG_CACHE, "[mipmap_cache] generate mip %d for ID=%d from scratch\n", @@ -1548,7 +1549,7 @@ static void _init_8(uint8_t *buf, // dat.head.width, dat.head.height); // any errors? - if(res) + if(!res) { // dt_print(DT_DEBUG_ALWAYS, "[mipmap_cache] could not process thumbnail!\n"); *width = *height = 0; diff --git a/src/dtgtk/thumbnail.c b/src/dtgtk/thumbnail.c index 0beef73129af..254ef9f6ae5f 100644 --- a/src/dtgtk/thumbnail.c +++ b/src/dtgtk/thumbnail.c @@ -795,9 +795,9 @@ static gboolean _event_image_draw(GtkWidget *widget, char path[PATH_MAX] = { 0 }; gboolean from_cache = TRUE; dt_image_full_path(thumb->imgid, path, sizeof(path), &from_cache); - if(!dt_imageio_large_thumbnail(path, &full_res_thumb, - &full_res_thumb_wd, &full_res_thumb_ht, - &color_space)) + if(dt_imageio_large_thumbnail(path, &full_res_thumb, + &full_res_thumb_wd, &full_res_thumb_ht, + &color_space)) { // we look for focus areas dt_focus_cluster_t full_res_focus[49]; diff --git a/src/imageio/imageio.c b/src/imageio/imageio.c index 4b1b725ed482..e3bc80e31c3c 100644 --- a/src/imageio/imageio.c +++ b/src/imageio/imageio.c @@ -153,7 +153,7 @@ gboolean dt_imageio_large_thumbnail(const char *filename, int32_t *height, dt_colorspaces_color_profile_type_t *color_space) { - int res = TRUE; + int res = FALSE; uint8_t *buf = NULL; char *mime_type = NULL; @@ -185,7 +185,7 @@ gboolean dt_imageio_large_thumbnail(const char *filename, goto error; } - res = FALSE; + res = TRUE; } else { @@ -236,13 +236,13 @@ gboolean dt_imageio_large_thumbnail(const char *filename, } } - res = FALSE; + res = TRUE; error_gm: if(image) DestroyImage(image); if(image_info) DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); - if(res) goto error; + if(!res) goto error; #elif defined HAVE_IMAGEMAGICK MagickWand *image = NULL; MagickBooleanType mret; @@ -287,11 +287,11 @@ gboolean dt_imageio_large_thumbnail(const char *filename, goto error_im; } - res = FALSE; + res = TRUE; error_im: DestroyMagickWand(image); - if(res) goto error; + if(!res) goto error; #else dt_print(DT_DEBUG_ALWAYS, "[dt_imageio_large_thumbnail] error: The thumbnail image is not in " @@ -301,7 +301,7 @@ gboolean dt_imageio_large_thumbnail(const char *filename, #endif } - if(res) + if(!res) { dt_print(DT_DEBUG_ALWAYS, "[dt_imageio_large_thumbnail] error: Not a supported thumbnail " @@ -706,9 +706,9 @@ gboolean dt_imageio_export(const dt_imgid_t imgid, { 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, icc_type, + return format->write_image(format_params, filename, NULL, icc_type, icc_filename, NULL, 0, imgid, num, total, NULL, - export_masks)) != 0; + export_masks) == 0; else { const gboolean is_scaling = @@ -1184,20 +1184,20 @@ gboolean dt_imageio_export_with_flags(const dt_imgid_t imgid, const int length = dt_exif_read_blob(&exif_profile, pathname, imgid, sRGB, processed_width, processed_height, FALSE); - res = (format->write_image(format_params, filename, outbuf, icc_type, + res = format->write_image(format_params, filename, outbuf, icc_type, icc_filename, exif_profile, length, imgid, - num, total, &pipe, export_masks)) != 0; + num, total, &pipe, export_masks) == 0; free(exif_profile); } else { - res = (format->write_image(format_params, filename, outbuf, icc_type, + res = format->write_image(format_params, filename, outbuf, icc_type, icc_filename, NULL, 0, imgid, num, total, - &pipe, export_masks)) != 0; + &pipe, export_masks) == 0; } - if(res) + if(!res) goto error; /* now write xmp into that container, if possible */