From 18861adce83dabc75c01c2a6d71c77a01ebc1ded Mon Sep 17 00:00:00 2001 From: Mario Zimmermann Date: Wed, 11 Jun 2025 10:42:51 +0200 Subject: [PATCH] fix scaling being read during running export job During a running export job the image scaling factor is read from the GUI/settings for each exported image, resulting in different export sizes if the scaling factor is changed. --- src/cli/main.c | 5 +++-- src/common/gimp.c | 18 ++++++++++-------- src/common/mipmap_cache.c | 2 +- src/control/jobs/control_jobs.c | 11 ++++++++++- src/imageio/imageio.c | 15 ++++++--------- src/imageio/imageio_common.h | 5 ++++- src/imageio/imageio_module.h | 2 +- src/imageio/storage/disk.c | 7 +++++-- src/imageio/storage/email.c | 7 +++++-- src/imageio/storage/gallery.c | 8 ++++++-- src/imageio/storage/imageio_storage_api.h | 6 ++++-- src/imageio/storage/latex.c | 6 ++++-- src/imageio/storage/piwigo.c | 6 ++++-- src/libs/print_settings.c | 3 ++- src/lua/format.c | 14 ++++++++++++-- src/lua/luastorage.c | 8 +++++--- src/views/tethering.c | 4 ++-- 17 files changed, 84 insertions(+), 43 deletions(-) diff --git a/src/cli/main.c b/src/cli/main.c index ab35c753781d..9690a7f18ee1 100644 --- a/src/cli/main.c +++ b/src/cli/main.c @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2012-2023 darktable developers. + Copyright (C) 2012-2025 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 @@ -778,7 +778,8 @@ int main(int argc, char *arg[]) dt_export_metadata_t metadata; metadata.flags = dt_lib_export_metadata_default_flags(); metadata.list = NULL; - if(storage->store(storage, sdata, id, format, fdata, num, total, high_quality, upscale, export_masks, + if(storage->store(storage, sdata, id, format, fdata, num, total, high_quality, + upscale, FALSE, 1.0, export_masks, icc_type, icc_filename, icc_intent, &metadata) != 0) res = 1; } diff --git a/src/common/gimp.c b/src/common/gimp.c index 61485e292593..348e4b9de297 100644 --- a/src/common/gimp.c +++ b/src/common/gimp.c @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2024 darktable developers. + Copyright (C) 2025 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 @@ -54,13 +54,15 @@ gboolean dt_export_gimp_file(const dt_imgid_t imgid) fdata->style_append = FALSE; storage->store(storage, sdata, imgid, format, fdata, 1, 1, - thumb ? FALSE : TRUE, // high_quality, - FALSE, // never upscale - thumb ? FALSE : TRUE, // export_masks - thumb ? DT_COLORSPACE_SRGB : DT_COLORSPACE_LIN_REC709, - NULL, // icc_filename - DT_INTENT_PERCEPTUAL, - NULL); // &metadata + thumb ? FALSE : TRUE, // high_quality, + FALSE, // never upscale + FALSE, + 1.0, + thumb ? FALSE : TRUE, // export_masks + thumb ? DT_COLORSPACE_SRGB : DT_COLORSPACE_LIN_REC709, + NULL, // icc_filename + DT_INTENT_PERCEPTUAL, + NULL); // &metadata printf("<<data); dt_imageio_export_with_flags(imgid, "unused", &buf, (dt_imageio_module_data_t *)&dat, - TRUE, FALSE, TRUE, TRUE, FALSE, + TRUE, FALSE, TRUE, TRUE, FALSE, 1.0, FALSE, "pre:rawprepare", FALSE, FALSE, DT_COLORSPACE_NONE, NULL, DT_INTENT_LAST, NULL, NULL, num, total, NULL, -1); @@ -1864,6 +1864,14 @@ static int32_t _control_export_job_run(dt_job_t *job) "\x1b%G"); // ESC % G } + // scaling + const gboolean is_scaling = + dt_conf_is_equal("plugins/lighttable/export/resizing", "scaling"); + + double _num, _denum; + dt_imageio_resizing_factor_get_and_parsing(&_num, &_denum); + const double scale_factor = is_scaling? _num / _denum : 1.0; + dt_export_metadata_t metadata; metadata.flags = 0; metadata.list = dt_util_str_to_glist("\1", settings->metadata_export); @@ -1907,6 +1915,7 @@ static int32_t _control_export_job_run(dt_job_t *job) dt_image_cache_read_release(image); if(mstorage->store(mstorage, sdata, imgid, mformat, fdata, num, total, settings->high_quality, settings->upscale, + is_scaling, scale_factor, settings->export_masks, settings->icc_type, settings->icc_filename, settings->icc_intent, &metadata) != 0) diff --git a/src/imageio/imageio.c b/src/imageio/imageio.c index d36678c09762..e2b49fb5db7a 100644 --- a/src/imageio/imageio.c +++ b/src/imageio/imageio.c @@ -977,6 +977,8 @@ gboolean dt_imageio_export(const dt_imgid_t imgid, dt_imageio_module_data_t *format_params, const gboolean high_quality, const gboolean upscale, + const gboolean is_scaling, + const double scale_factor, const gboolean copy_metadata, const gboolean export_masks, const dt_colorspaces_color_profile_type_t icc_type, @@ -995,12 +997,9 @@ gboolean dt_imageio_export(const dt_imgid_t imgid, export_masks)) != 0; else { - const gboolean is_scaling = - dt_conf_is_equal("plugins/lighttable/export/resizing", "scaling"); - return dt_imageio_export_with_flags(imgid, filename, format, format_params, FALSE, FALSE, high_quality, upscale, - is_scaling, FALSE, NULL, copy_metadata, + is_scaling, scale_factor, FALSE, NULL, copy_metadata, export_masks, icc_type, icc_filename, icc_intent, storage, storage_params, num, total, metadata, -1); @@ -1035,6 +1034,7 @@ gboolean dt_imageio_export_with_flags(const dt_imgid_t imgid, const gboolean high_quality, const gboolean upscale, const gboolean is_scaling, + const double scale_factor, const gboolean thumbnail_export, const char *filter, const gboolean copy_metadata, @@ -1268,10 +1268,6 @@ gboolean dt_imageio_export_with_flags(const dt_imgid_t imgid, if(is_scaling) { - // scaling - double _num, _denum; - dt_imageio_resizing_factor_get_and_parsing(&_num, &_denum); - const double scale_factor = _num / _denum; if(!thumbnail_export) { scale = fmin(scale_factor, max_scale); @@ -1735,10 +1731,11 @@ cairo_surface_t *dt_imageio_preview(const dt_imgid_t imgid, const gboolean upscale = TRUE; const gboolean export_masks = FALSE; const gboolean is_scaling = FALSE; + const double scale_factor = 1.0; dt_imageio_export_with_flags (imgid, "preview", &buf, (dt_imageio_module_data_t *)&dat, TRUE, TRUE, - high_quality, upscale, is_scaling, FALSE, NULL, FALSE, export_masks, + high_quality, upscale, is_scaling, scale_factor, FALSE, NULL, FALSE, export_masks, DT_COLORSPACE_DISPLAY, NULL, DT_INTENT_LAST, NULL, NULL, 1, 1, NULL, history_end); diff --git a/src/imageio/imageio_common.h b/src/imageio/imageio_common.h index fd2583f9a920..fe3b1f96fe8a 100644 --- a/src/imageio/imageio_common.h +++ b/src/imageio/imageio_common.h @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2009-2024 darktable developers. + Copyright (C) 2009-2025 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,6 +91,8 @@ gboolean dt_imageio_export(const dt_imgid_t imgid, struct dt_imageio_module_data_t *format_params, const gboolean high_quality, const gboolean upscale, + const gboolean is_scaling, + const double scale_factor, const gboolean copy_metadata, const gboolean export_masks, dt_colorspaces_color_profile_type_t icc_type, @@ -110,6 +112,7 @@ gboolean dt_imageio_export_with_flags(const dt_imgid_t imgid, const char *filena const gboolean high_quality, const gboolean upscale, const gboolean is_scaling, + const double scale_factor, const gboolean thumbnail_export, const char *filter, const gboolean copy_metadata, diff --git a/src/imageio/imageio_module.h b/src/imageio/imageio_module.h index 4b02b4b8cee5..aaca3fa69542 100644 --- a/src/imageio/imageio_module.h +++ b/src/imageio/imageio_module.h @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2010-2021 darktable developers. + Copyright (C) 2010-2025 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 diff --git a/src/imageio/storage/disk.c b/src/imageio/storage/disk.c index cf9cbb9c0ae5..1f6b72149fc1 100644 --- a/src/imageio/storage/disk.c +++ b/src/imageio/storage/disk.c @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2010-2024 darktable developers. + Copyright (C) 2010-2025 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 @@ -323,6 +323,8 @@ int store(dt_imageio_module_storage_t *self, const int total, const gboolean high_quality, const gboolean upscale, + const gboolean is_scaling, + const double scale_factor, const gboolean export_masks, dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename, @@ -486,7 +488,8 @@ int store(dt_imageio_module_storage_t *self, /* export image to file */ if(dt_imageio_export(imgid, filename, format, fdata, high_quality, - upscale, TRUE, export_masks, icc_type, + upscale, is_scaling, scale_factor, + TRUE, export_masks, icc_type, icc_filename, icc_intent, self, sdata, num, total, metadata) != 0) { diff --git a/src/imageio/storage/email.c b/src/imageio/storage/email.c index 8cb98c69ab37..0287ba3118e3 100644 --- a/src/imageio/storage/email.c +++ b/src/imageio/storage/email.c @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2010-2023 darktable developers. + Copyright (C) 2010-2025 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 @@ -141,6 +141,8 @@ int store(dt_imageio_module_storage_t *self, const int total, const gboolean high_quality, const gboolean upscale, + const gboolean is_scaling, + const double scale_factor, const gboolean export_masks, dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename, @@ -176,7 +178,8 @@ 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, - upscale, TRUE, export_masks, icc_type, + upscale, is_scaling, scale_factor, + TRUE, export_masks, icc_type, icc_filename, icc_intent, self, sdata, num, total, metadata) != 0) { dt_print(DT_DEBUG_ALWAYS, diff --git a/src/imageio/storage/gallery.c b/src/imageio/storage/gallery.c index d003b617d074..5b6549d5372e 100644 --- a/src/imageio/storage/gallery.c +++ b/src/imageio/storage/gallery.c @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2011-2024 darktable developers. + Copyright (C) 2011-2025 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 @@ -255,6 +255,8 @@ int store(dt_imageio_module_storage_t *self, const int total, const gboolean high_quality, const gboolean upscale, + const gboolean is_scaling, + const double scale_factor, const gboolean export_masks, dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename, @@ -395,7 +397,8 @@ 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, - upscale, TRUE, export_masks, icc_type, + upscale, is_scaling, scale_factor, + TRUE, export_masks, icc_type, icc_filename, icc_intent, self, sdata, num, total, metadata) != 0) { dt_print(DT_DEBUG_ALWAYS, @@ -436,6 +439,7 @@ int store(dt_imageio_module_storage_t *self, ext = format->extension(fdata); sprintf(c, "-thumb.%s", ext); if(dt_imageio_export(imgid, filename, format, fdata, FALSE, TRUE, FALSE, + is_scaling, scale_factor, export_masks, icc_type, icc_filename, icc_intent, self, sdata, num, total, NULL) != 0) { diff --git a/src/imageio/storage/imageio_storage_api.h b/src/imageio/storage/imageio_storage_api.h index c671ffa956df..9fa998e6f8e3 100644 --- a/src/imageio/storage/imageio_storage_api.h +++ b/src/imageio/storage/imageio_storage_api.h @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2016-2023 darktable developers. + Copyright (C) 2016-2025 darktable developers. darktable is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -67,7 +67,9 @@ OPTIONAL(int, initialize_store, struct dt_imageio_module_storage_t *self, struct /* this actually does the work */ REQUIRED(int, store, struct dt_imageio_module_storage_t *self, struct dt_imageio_module_data_t *self_data, const dt_imgid_t 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, const gboolean export_masks, + const int total, const gboolean high_quality, const gboolean upscale, + const gboolean is_scaling, const double scale_factor, + const gboolean export_masks, const enum dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename, enum dt_iop_color_intent_t icc_intent, struct dt_export_metadata_t *metadata); /* called once at the end (after exporting all images), if implemented. */ diff --git a/src/imageio/storage/latex.c b/src/imageio/storage/latex.c index 93b14e02d611..b3d7b441ac30 100644 --- a/src/imageio/storage/latex.c +++ b/src/imageio/storage/latex.c @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2012-2024 darktable developers. + Copyright (C) 2012-2025 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 @@ -224,7 +224,8 @@ 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 dt_imgid_t 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 gboolean export_masks, + const gboolean high_quality, const gboolean upscale, const gboolean is_scaling, + const double scale_factor, const gboolean export_masks, dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename, dt_iop_color_intent_t icc_intent, dt_export_metadata_t *metadata) { @@ -362,6 +363,7 @@ int store(dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, co /* export image to file */ dt_imageio_export(imgid, filename, format, fdata, high_quality, upscale, + is_scaling, scale_factor, TRUE, export_masks, icc_type, icc_filename, icc_intent, self, sdata, num, total, metadata); diff --git a/src/imageio/storage/piwigo.c b/src/imageio/storage/piwigo.c index b5a366c435b9..e5d3eaadfe57 100644 --- a/src/imageio/storage/piwigo.c +++ b/src/imageio/storage/piwigo.c @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2018-2024 darktable developers. + Copyright (C) 2018-2025 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 @@ -1271,6 +1271,8 @@ int store(dt_imageio_module_storage_t *self, const int total, const gboolean high_quality, const gboolean upscale, + const gboolean is_scaling, + const double scale_factor, const gboolean export_masks, const dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename, @@ -1353,8 +1355,8 @@ int store(dt_imageio_module_storage_t *self, g_free(filename); dt_image_cache_read_release(img); - if(dt_imageio_export(imgid, fname, format, fdata, high_quality, upscale, + is_scaling, scale_factor, TRUE, export_masks, icc_type, icc_filename, icc_intent, self, sdata, num, total, metadata) != 0) { diff --git a/src/libs/print_settings.c b/src/libs/print_settings.c index a382c1cf5f21..5757b32e8974 100644 --- a/src/libs/print_settings.c +++ b/src/libs/print_settings.c @@ -372,10 +372,11 @@ static int _export_image(dt_job_t *job, dt_image_box *img) const gboolean upscale = TRUE; const gboolean export_masks = FALSE; const gboolean is_scaling = FALSE; + const double scale_factor = 1.0; dt_imageio_export_with_flags (img->imgid, "unused", &buf, (dt_imageio_module_data_t *)&dat, TRUE, FALSE, - high_quality, upscale, is_scaling, FALSE, NULL, + high_quality, upscale, is_scaling, scale_factor, FALSE, NULL, FALSE, export_masks, params->buf_icc_type, params->buf_icc_profile, params->buf_icc_intent, NULL, NULL, 1, 1, NULL, -1); diff --git a/src/lua/format.c b/src/lua/format.c index eb81302e1f28..a81f8bb92176 100644 --- a/src/lua/format.c +++ b/src/lua/format.c @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2014-2023 darktable developers. + Copyright (C) 2014-2025 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 @@ -164,7 +164,17 @@ static int write_image(lua_State *L) // TODO: expose icc overwrites to the user! dt_colorspaces_color_profile_type_t icc_type = dt_conf_get_int("plugins/lighttable/export/icctype"); const char *icc_filename = dt_conf_get_string_const("plugins/lighttable/export/iccprofile"); - gboolean result = dt_imageio_export(imgid, filename, format, fdata, high_quality, upscale, FALSE, export_masks, + + // scaling + const gboolean is_scaling = + dt_conf_is_equal("plugins/lighttable/export/resizing", "scaling"); + + double _num, _denum; + dt_imageio_resizing_factor_get_and_parsing(&_num, &_denum); + const double scale_factor = is_scaling? _num / _denum : 1.0; + + gboolean result = dt_imageio_export(imgid, filename, format, fdata, high_quality, upscale, is_scaling, scale_factor, + FALSE, export_masks, icc_type, icc_filename, DT_INTENT_LAST, NULL, NULL, 1, 1, NULL); dt_lua_lock(); // mitigate 17938 by returning sane values (true for success, false for failure) diff --git a/src/lua/luastorage.c b/src/lua/luastorage.c index a939bbefa13e..7479e01ad687 100644 --- a/src/lua/luastorage.c +++ b/src/lua/luastorage.c @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2014-2023 darktable developers. + Copyright (C) 2014-2025 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,6 +91,8 @@ static int store_wrapper(struct dt_imageio_module_storage_t *self, const int total, const gboolean high_quality, const gboolean upscale, + const gboolean is_scaling, + const double scale_factor, const gboolean export_masks, dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename, @@ -111,8 +113,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, is_scaling, scale_factor, + TRUE, export_masks, icc_type, icc_filename, icc_intent, self, self_data, num, total, metadata) != 0) { dt_print(DT_DEBUG_ALWAYS, "[lua] %s: could not export to file `%s'!", self->name(self), complete_name); diff --git a/src/views/tethering.c b/src/views/tethering.c index c63b75dc5b21..b1c43790993d 100644 --- a/src/views/tethering.c +++ b/src/views/tethering.c @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2014-2024 darktable developers. + Copyright (C) 2014-2025 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 @@ -438,7 +438,7 @@ static void _expose_tethered_mode(dt_view_t *self, 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, FALSE, FALSE, 1.0, FALSE, NULL, FALSE, FALSE, histogram_type, histogram_filename, DT_INTENT_PERCEPTUAL, NULL, NULL, 1, 1, NULL, -1)) {