Skip to content

Commit 188e90a

Browse files
committed
Added gainmap downsampling.
1 parent c26bd7b commit 188e90a

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

contrib/ultrahdr.lua

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ local GUI = {
7777
metadata_box = {},
7878
edit_executables_button = {},
7979
executable_path_widget = {},
80-
quality_widget = {}
80+
quality_widget = {},
81+
gainmap_downsampling_widget = {},
8182
},
8283
options = {},
8384
run = {}
@@ -145,6 +146,7 @@ local function save_preferences()
145146
dt.preferences.write(namespace, "hdr_capacity_max", "float", GUI.optionwidgets.hdr_capacity_max.value)
146147
end
147148
dt.preferences.write(namespace, "quality", "integer", GUI.optionwidgets.quality_widget.value)
149+
dt.preferences.write(namespace, "gainmap_downsampling", "integer", GUI.optionwidgets.gainmap_downsampling_widget.value)
148150
end
149151

150152
local function default_to(value, default)
@@ -177,6 +179,7 @@ local function load_preferences()
177179
GUI.optionwidgets.hdr_capacity_max.value = default_to(dt.preferences.read(namespace, "hdr_capacity_max", "float"),
178180
6.0)
179181
GUI.optionwidgets.quality_widget.value = default_to(dt.preferences.read(namespace, "quality", "integer"), 95)
182+
GUI.optionwidgets.gainmap_downsampling_widget.value = default_to(dt.preferences.read(namespace, "gainmap_downsampling", "integer"), 0)
180183
end
181184

182185
-- Changes the combobox selection blindly until a paired config value is set.
@@ -221,6 +224,7 @@ local function assert_settings_correct(encoding_variant)
221224
hdr_capacity_max = GUI.optionwidgets.hdr_capacity_max.value
222225
},
223226
quality = GUI.optionwidgets.quality_widget.value,
227+
downsample = 2^GUI.optionwidgets.gainmap_downsampling_widget.value,
224228
tmpdir = dt.configuration.tmp_dir,
225229
skip_cleanup = false -- keep temporary files around, for debugging.
226230
}
@@ -531,7 +535,7 @@ local function generate_ultrahdr(encoding_variant, images, settings, step, total
531535
cmd = settings.bin.ultrahdr_app .. " -m 0 -y " .. df.sanitize_filename(sdr_raw) .. " -p " ..
532536
df.sanitize_filename(hdr_raw) ..
533537
string.format(" -a 0 -b 3 -c 1 -C 1 -t 2 -M 0 -s 1 -q %d -Q %d -D 1 ", settings.quality,
534-
settings.quality) .. " -w " .. tostring(sdr_w - sdr_w % 2) .. " -h " .. tostring(sdr_h - sdr_h % 2) ..
538+
settings.quality) .. string.format(" -s %d ", settings.downsample) .. " -w " .. tostring(sdr_w - sdr_w % 2) .. " -h " .. tostring(sdr_h - sdr_h % 2) ..
535539
" -z " .. df.sanitize_filename(uhdr)
536540
if not execute_cmd(cmd, string.format(_("Error merging %s"), uhdr)) then
537541
return cleanup(), errors
@@ -742,8 +746,10 @@ You can force the image into a specific stack slot by attaching "hdr" / "gainmap
742746
GUI.run.sensitive = self.selected and self.selected > 0
743747
if self.selected == ENCODING_VARIANT_SDR_AND_GAINMAP or self.selected == ENCODING_VARIANT_SDR_AUTO_GAINMAP then
744748
GUI.optionwidgets.metadata_box.visible = true
749+
GUI.optionwidgets.gainmap_downsampling_widget.visible = false
745750
else
746751
GUI.optionwidgets.metadata_box.visible = false
752+
GUI.optionwidgets.gainmap_downsampling_widget.visible = true
747753
end
748754
end,
749755
_("SDR + gain map"), -- ENCODING_VARIANT_SDR_AND_GAINMAP
@@ -781,11 +787,26 @@ GUI.optionwidgets.quality_widget = dt.new_widget("slider") {
781787
end
782788
}
783789

790+
GUI.optionwidgets.gainmap_downsampling_widget = dt.new_widget("slider") {
791+
label = _('gain map downsampling steps'),
792+
tooltip = _('Exponent (2^x) of the gain map downsampling factor.\nDownsampling reduces the file size, at the expense of quality.\n\n0 = don\'t downsample the gain map, 7 = maximum downsampling (128x)'),
793+
hard_min = 0,
794+
hard_max = 7,
795+
soft_min = 0,
796+
soft_max = 7,
797+
step = 1,
798+
digits = 0,
799+
reset_callback = function(self)
800+
self.value = 0
801+
end
802+
}
803+
784804
GUI.optionwidgets.encoding_settings_box = dt.new_widget("box") {
785805
orientation = "vertical",
786806
GUI.optionwidgets.selection_type_combo,
787807
GUI.optionwidgets.encoding_variant_combo,
788808
GUI.optionwidgets.quality_widget,
809+
GUI.optionwidgets.gainmap_downsampling_widget,
789810
GUI.optionwidgets.metadata_box
790811
}
791812

0 commit comments

Comments
 (0)