Skip to content

Commit 77c4058

Browse files
committed
Added logging code and a workaround for darktable-org/darktable#17528 in 9.4.0.
1 parent ecc3fb2 commit 77c4058

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

.DS_Store

6 KB
Binary file not shown.

contrib/ultrahdr.lua

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ local gettext = dt.gettext.gettext
4747

4848
local namespace = "module_ultrahdr"
4949

50+
local LOG_LEVEL = log.info
51+
5052
-- works with darktable API version from 4.8.0 on
5153
du.check_min_api_version("9.3.0", "ultrahdr")
5254

@@ -118,7 +120,19 @@ local COLORSPACE_TO_GUI_ACTION = {
118120
[DT_COLORSPACE_DISPLAY_P3] = 11
119121
}
120122

123+
124+
local function set_log_level(level)
125+
local old_log_level = log.log_level()
126+
log.log_level(level)
127+
return old_log_level
128+
end
129+
130+
local function restore_log_level(level)
131+
log.log_level(level)
132+
end
133+
121134
local function generate_metadata_file(settings)
135+
local old_log_level = set_log_level(LOG_LEVEL)
122136
local metadata_file_fmt = [[--maxContentBoost %f
123137
--minContentBoost %f
124138
--gamma 1.0
@@ -137,10 +151,12 @@ local function generate_metadata_file(settings)
137151
settings.metadata.min_content_boost, settings.metadata.hdr_capacity_min, settings.metadata.hdr_capacity_max)
138152
f:write(content)
139153
f:close()
154+
restore_log_level(old_log_level)
140155
return filename
141156
end
142157

143158
local function save_preferences()
159+
local old_log_level = set_log_level(LOG_LEVEL)
144160
dt.preferences.write(namespace, "encoding_variant", "integer", GUI.optionwidgets.encoding_variant_combo.selected)
145161
dt.preferences.write(namespace, "selection_type", "integer", GUI.optionwidgets.selection_type_combo.selected)
146162
dt.preferences.write(namespace, "output_filepath_pattern", "string", GUI.optionwidgets.output_filepath_widget.text)
@@ -158,7 +174,7 @@ local function save_preferences()
158174
GUI.optionwidgets.gainmap_downsampling_widget.value)
159175
dt.preferences.write(namespace, "target_display_peak_nits", "integer",
160176
(GUI.optionwidgets.target_display_peak_nits_widget.value + 0.5) // 1)
161-
177+
restore_log_level(old_log_level)
162178
end
163179

164180
local function default_to(value, default)
@@ -169,6 +185,7 @@ local function default_to(value, default)
169185
end
170186

171187
local function load_preferences()
188+
local old_log_level = set_log_level(LOG_LEVEL)
172189
-- Since the option #1 is the default, and empty numeric prefs are 0, we can use math.max
173190
GUI.optionwidgets.encoding_variant_combo.selected = math.max(
174191
dt.preferences.read(namespace, "encoding_variant", "integer"), ENCODING_VARIANT_SDR_AND_GAINMAP)
@@ -192,6 +209,7 @@ local function load_preferences()
192209
dt.preferences.read(namespace, "target_display_peak_nits", "integer"), 10000)
193210
GUI.optionwidgets.gainmap_downsampling_widget.value = default_to(
194211
dt.preferences.read(namespace, "gainmap_downsampling", "integer"), 0)
212+
restore_log_level(old_log_level)
195213
end
196214

197215
local function set_profile(colorspace)
@@ -201,7 +219,7 @@ local function set_profile(colorspace)
201219
-- New method, with hardcoded export profile values.
202220
local old = dt.gui.action("lib/export/profile", 0, "selection", "", "") * -1
203221
local new = COLORSPACE_TO_GUI_ACTION[colorspace] or colorspace
204-
log.msg(log.debug, string.format("%d %d %d %d", colorspace, new, old, new - old))
222+
log.msg(log.debug, string.format("Changing export profile from %d to %d", old, new))
205223
dt.gui.action("lib/export/profile", 0, "selection", "next", new - old)
206224
return old
207225
else
@@ -213,6 +231,7 @@ end
213231
-- Changes the combobox selection blindly until a paired config value is set.
214232
-- Workaround for https://github.com/darktable-org/lua-scripts/issues/522
215233
local function set_combobox(path, instance, config_name, new_config_value)
234+
local old_log_level = set_log_level(LOG_LEVEL)
216235
local pref = dt.preferences.read("darktable", config_name, "integer")
217236
if pref == new_config_value then
218237
return new_config_value
@@ -231,9 +250,11 @@ local function set_combobox(path, instance, config_name, new_config_value)
231250
end
232251
end
233252
log.msg(log.error, string.format(_("Could not change %s from %d to %d"), config_name, pref, new_config_value))
253+
restore_log_level(old_log_level)
234254
end
235255

236256
local function assert_settings_correct(encoding_variant)
257+
local old_log_level = set_log_level(LOG_LEVEL)
237258
local errors = {}
238259
local settings = {
239260
bin = {
@@ -273,7 +294,7 @@ local function assert_settings_correct(encoding_variant)
273294
table.insert(errors, _("hdr_capacity_min should not be greater than hdr_capacity_max"))
274295
end
275296
end
276-
297+
restore_log_level(old_log_level)
277298
if #errors > 0 then
278299
return nil, errors
279300
end
@@ -288,6 +309,7 @@ local function get_dimensions(image)
288309
end
289310

290311
local function get_stacks(images, encoding_variant, selection_type)
312+
local old_log_level = set_log_level(LOG_LEVEL)
291313
local stacks = {}
292314
local primary = "sdr"
293315
local extra
@@ -356,6 +378,7 @@ local function get_stacks(images, encoding_variant, selection_type)
356378
count = count + 1
357379
end
358380
end
381+
restore_log_level(old_log_level)
359382
return stacks, count
360383
end
361384

@@ -374,6 +397,7 @@ local function file_size(path)
374397
end
375398

376399
local function generate_ultrahdr(encoding_variant, images, settings, step, total_steps)
400+
local old_log_level = set_log_level(LOG_LEVEL)
377401
local total_substeps
378402
local substep = 0
379403
local best_source_image
@@ -402,6 +426,8 @@ local function generate_ultrahdr(encoding_variant, images, settings, step, total
402426
end
403427

404428
function copy_or_export(src_image, dest, format, colorspace, props)
429+
-- Workaround for https://github.com/darktable-org/darktable/issues/17528
430+
local needs_workaround = dt.configuration.api_version_string == "9.3.0" or dt.configuration.api_version_string == "9.4.0"
405431
if not settings.force_export and df.get_filetype(src_image.filename) == df.get_filetype(dest) and
406432
not src_image.is_altered then
407433
return df.file_copy(src_image.path .. PS .. src_image.filename, dest)
@@ -415,11 +441,10 @@ local function generate_ultrahdr(encoding_variant, images, settings, step, total
415441
exporter[k] = v
416442
end
417443
local ok = exporter:write_image(src_image, dest)
418-
if dt.configuration.api_version_string == "9.3.0" then
419-
-- Workaround for https://github.com/darktable-org/darktable/issues/17528
444+
if needs_workaround then
420445
ok = not ok
421446
end
422-
447+
log.msg(log.info, string.format("Exporting %s to %s (format: %s): %s", src_image.filename, dest, format, ok))
423448
if prev then
424449
set_profile(prev)
425450
end
@@ -695,10 +720,12 @@ local function generate_ultrahdr(encoding_variant, images, settings, step, total
695720
local msg = string.format(_("Generated %s."), df.get_filename(output_file))
696721
log.msg(log.info, msg)
697722
dt.print(msg)
723+
restore_log_level(old_log_level)
698724
return true, nil
699725
end
700726

701727
local function main()
728+
local old_log_level = set_log_level(LOG_LEVEL)
702729
save_preferences()
703730

704731
local selection_type = GUI.optionwidgets.selection_type_combo.selected
@@ -741,6 +768,7 @@ local function main()
741768
msg = string.format(_("Generated %d UltraHDR image(s)."), count)
742769
log.msg(log.info, msg)
743770
dt.print(msg)
771+
restore_log_level(old_log_level)
744772
end
745773

746774
GUI.optionwidgets.settings_label = dt.new_widget("section_label") {

0 commit comments

Comments
 (0)