@@ -47,6 +47,8 @@ local gettext = dt.gettext.gettext
47
47
48
48
local namespace = " module_ultrahdr"
49
49
50
+ local LOG_LEVEL = log .info
51
+
50
52
-- works with darktable API version from 4.8.0 on
51
53
du .check_min_api_version (" 9.3.0" , " ultrahdr" )
52
54
@@ -118,7 +120,19 @@ local COLORSPACE_TO_GUI_ACTION = {
118
120
[DT_COLORSPACE_DISPLAY_P3 ] = 11
119
121
}
120
122
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
+
121
134
local function generate_metadata_file (settings )
135
+ local old_log_level = set_log_level (LOG_LEVEL )
122
136
local metadata_file_fmt = [[ --maxContentBoost %f
123
137
--minContentBoost %f
124
138
--gamma 1.0
@@ -137,10 +151,12 @@ local function generate_metadata_file(settings)
137
151
settings .metadata .min_content_boost , settings .metadata .hdr_capacity_min , settings .metadata .hdr_capacity_max )
138
152
f :write (content )
139
153
f :close ()
154
+ restore_log_level (old_log_level )
140
155
return filename
141
156
end
142
157
143
158
local function save_preferences ()
159
+ local old_log_level = set_log_level (LOG_LEVEL )
144
160
dt .preferences .write (namespace , " encoding_variant" , " integer" , GUI .optionwidgets .encoding_variant_combo .selected )
145
161
dt .preferences .write (namespace , " selection_type" , " integer" , GUI .optionwidgets .selection_type_combo .selected )
146
162
dt .preferences .write (namespace , " output_filepath_pattern" , " string" , GUI .optionwidgets .output_filepath_widget .text )
@@ -158,7 +174,7 @@ local function save_preferences()
158
174
GUI .optionwidgets .gainmap_downsampling_widget .value )
159
175
dt .preferences .write (namespace , " target_display_peak_nits" , " integer" ,
160
176
(GUI .optionwidgets .target_display_peak_nits_widget .value + 0.5 ) // 1 )
161
-
177
+ restore_log_level ( old_log_level )
162
178
end
163
179
164
180
local function default_to (value , default )
@@ -169,6 +185,7 @@ local function default_to(value, default)
169
185
end
170
186
171
187
local function load_preferences ()
188
+ local old_log_level = set_log_level (LOG_LEVEL )
172
189
-- Since the option #1 is the default, and empty numeric prefs are 0, we can use math.max
173
190
GUI .optionwidgets .encoding_variant_combo .selected = math.max (
174
191
dt .preferences .read (namespace , " encoding_variant" , " integer" ), ENCODING_VARIANT_SDR_AND_GAINMAP )
@@ -192,6 +209,7 @@ local function load_preferences()
192
209
dt .preferences .read (namespace , " target_display_peak_nits" , " integer" ), 10000 )
193
210
GUI .optionwidgets .gainmap_downsampling_widget .value = default_to (
194
211
dt .preferences .read (namespace , " gainmap_downsampling" , " integer" ), 0 )
212
+ restore_log_level (old_log_level )
195
213
end
196
214
197
215
local function set_profile (colorspace )
@@ -201,7 +219,7 @@ local function set_profile(colorspace)
201
219
-- New method, with hardcoded export profile values.
202
220
local old = dt .gui .action (" lib/export/profile" , 0 , " selection" , " " , " " ) * - 1
203
221
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 ))
205
223
dt .gui .action (" lib/export/profile" , 0 , " selection" , " next" , new - old )
206
224
return old
207
225
else
213
231
-- Changes the combobox selection blindly until a paired config value is set.
214
232
-- Workaround for https://github.com/darktable-org/lua-scripts/issues/522
215
233
local function set_combobox (path , instance , config_name , new_config_value )
234
+ local old_log_level = set_log_level (LOG_LEVEL )
216
235
local pref = dt .preferences .read (" darktable" , config_name , " integer" )
217
236
if pref == new_config_value then
218
237
return new_config_value
@@ -231,9 +250,11 @@ local function set_combobox(path, instance, config_name, new_config_value)
231
250
end
232
251
end
233
252
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 )
234
254
end
235
255
236
256
local function assert_settings_correct (encoding_variant )
257
+ local old_log_level = set_log_level (LOG_LEVEL )
237
258
local errors = {}
238
259
local settings = {
239
260
bin = {
@@ -273,7 +294,7 @@ local function assert_settings_correct(encoding_variant)
273
294
table.insert (errors , _ (" hdr_capacity_min should not be greater than hdr_capacity_max" ))
274
295
end
275
296
end
276
-
297
+ restore_log_level ( old_log_level )
277
298
if # errors > 0 then
278
299
return nil , errors
279
300
end
@@ -288,6 +309,7 @@ local function get_dimensions(image)
288
309
end
289
310
290
311
local function get_stacks (images , encoding_variant , selection_type )
312
+ local old_log_level = set_log_level (LOG_LEVEL )
291
313
local stacks = {}
292
314
local primary = " sdr"
293
315
local extra
@@ -356,6 +378,7 @@ local function get_stacks(images, encoding_variant, selection_type)
356
378
count = count + 1
357
379
end
358
380
end
381
+ restore_log_level (old_log_level )
359
382
return stacks , count
360
383
end
361
384
@@ -374,6 +397,7 @@ local function file_size(path)
374
397
end
375
398
376
399
local function generate_ultrahdr (encoding_variant , images , settings , step , total_steps )
400
+ local old_log_level = set_log_level (LOG_LEVEL )
377
401
local total_substeps
378
402
local substep = 0
379
403
local best_source_image
@@ -402,6 +426,8 @@ local function generate_ultrahdr(encoding_variant, images, settings, step, total
402
426
end
403
427
404
428
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"
405
431
if not settings .force_export and df .get_filetype (src_image .filename ) == df .get_filetype (dest ) and
406
432
not src_image .is_altered then
407
433
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
415
441
exporter [k ] = v
416
442
end
417
443
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
420
445
ok = not ok
421
446
end
422
-
447
+ log . msg ( log . info , string.format ( " Exporting %s to %s (format: %s): %s " , src_image . filename , dest , format , ok ))
423
448
if prev then
424
449
set_profile (prev )
425
450
end
@@ -695,10 +720,12 @@ local function generate_ultrahdr(encoding_variant, images, settings, step, total
695
720
local msg = string.format (_ (" Generated %s." ), df .get_filename (output_file ))
696
721
log .msg (log .info , msg )
697
722
dt .print (msg )
723
+ restore_log_level (old_log_level )
698
724
return true , nil
699
725
end
700
726
701
727
local function main ()
728
+ local old_log_level = set_log_level (LOG_LEVEL )
702
729
save_preferences ()
703
730
704
731
local selection_type = GUI .optionwidgets .selection_type_combo .selected
@@ -741,6 +768,7 @@ local function main()
741
768
msg = string.format (_ (" Generated %d UltraHDR image(s)." ), count )
742
769
log .msg (log .info , msg )
743
770
dt .print (msg )
771
+ restore_log_level (old_log_level )
744
772
end
745
773
746
774
GUI .optionwidgets .settings_label = dt .new_widget (" section_label" ) {
0 commit comments