From 84c0fd74143fe2b2e24fbe7f9eef0fa18176981b Mon Sep 17 00:00:00 2001 From: BzKevin <36381472+BzKevin@users.noreply.github.com> Date: Sat, 30 Jun 2018 14:58:50 -0400 Subject: [PATCH 1/9] Add 3 new Pulg-Ins HDRMerge: Add easy access to HDRMerge from within dt enfuse_pro_2: Updated version of Holger Klemm's popular enfuse plug-in. Adds some features and cross-platform compatability OpenInPS: add ability to open or export selected file with Photoshop --- contrib/HDRMerge.lua | 396 ++++++++++++++ contrib/OpenInPS.lua | 199 ++++++++ contrib/enfuse_pro_2.lua | 1051 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 1646 insertions(+) create mode 100644 contrib/HDRMerge.lua create mode 100644 contrib/OpenInPS.lua create mode 100644 contrib/enfuse_pro_2.lua diff --git a/contrib/HDRMerge.lua b/contrib/HDRMerge.lua new file mode 100644 index 0000000..f8ea9d5 --- /dev/null +++ b/contrib/HDRMerge.lua @@ -0,0 +1,396 @@ +--[[ HDRMerge plugin for darktable + + copyright (c) 2018 Kevin Ertel + + darktable is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + darktable is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with darktable. If not, see . +]] + +--[[ Version 1.0.2 3/20/2018 + +This plugin adds the module "HDRMerge" to darktable's lighttable view + +****Dependencies**** +OS: Windows (tested), Linux (not verified), MacOS (not verified) +HDRMerge 4.5 or greater + +****How to use**** +Require this file from your luarc file, as with any other dt plug-in. +On initial run setup HDRMerge's install path via the settings > lua options dialog. Restart may be required. +Select a group of photos you desire to merge and press HDRMerge + +****Options**** +Bits Per Sample - Bit depth of the final image +Preview Size - Preview size of the built-in preview +Batch - Allows user to select multiple groups and HDRMerge will auto-group them based on time seperation "gap" +Gap - Time seperation between groupings when running in batch mode +Style - Style to be applied when image is auto-imported (Auto-import only supported in non-batch mode) +Copy Tags - Enable to copy tags from first file in selection +Additional Tags - Additional tags to be added, works with or without Copy Tags enabled. + +****Known Bugs / Deficiencies****: +CMD window pops up when run +Slider double-click sets to 31, not 3 +Removes spaces from tags (desired to only removed spaces at front and end) + +****Features for future releases**** + + +****Versions**** +Version 0.1 - Implemented via "Selected Images" +Version 0.2 - Implemented as it's own module - windows only +Version 0.3 - Improved cross-platform compatibility, improved performance ( switched from io.popen() to dt.control.execute() ) +Version 1.0 - Added: + Copy Tags Option + Additional Tags Option + User Defined Default Style + Progress Bar + 1.0.1 - Added check for at least 2 images selected + Fixed issue with status bar not disappearing when HDRmerge not installed or not enough images selected + 1.0.2 - Changes for grabbing executable path and setting preference (to imporve cross-platform support) + Changes to building the run_cmd (to improve cross-platform support) +]] + +local dt = require "darktable" +local df = require "lib/dtutils.file" +require "official/yield" + +--Detect OS and modify accordingly-- +op_sys = dt.configuration.running_os +if op_sys == "windows" then + os_path_seperator = "\\" +else + os_path_seperator = "/" +end + +-- READ PREFERENCES -- +pref_bps = dt.preferences.read("module_HDRMerge", "bits_per_sample", "enum") +if pref_bps == "32" then + pref_bps_enum = 3 +elseif pref_bps == "24" then + pref_bps_enum = 2 +else + pref_bps_enum = 1 +end +pref_size = dt.preferences.read("module_HDRMerge", "preview_size", "enum") +if pref_size == "none" then + pref_size_enum = 3 +elseif pref_size == "full" then + pref_size_enum = 2 +else + pref_size_enum = 1 +end +pref_cpytags = dt.preferences.read("module_HDRMerge", "copy_tags", "bool") +pref_addtags = dt.preferences.read("module_HDRMerge", "add_tags", "string") +pref_style = dt.preferences.read("module_HDRMerge", "style", "string") + +--Detect User Styles-- +styles = dt.styles +styles_count = 1 -- "none" = 1 +for _,i in pairs(dt.styles) do + if type(i) == "userdata" then styles_count = styles_count + 1 end +end + +local function build_execute_command(cmd, args, file_list) + local result = false + + if dt.configuration.running_os == "macos" then + cmd = string.gsub(cmd, "open", "") + cmd = string.gsub(cmd, "-W", "") + cmd = string.gsub(cmd, "-a", "") + -- result = cmd.." "..file_list.." "..args + --else + -- result = cmd..""..args.." "..file_list + end + result = cmd.." "..args.." "..file_list + return result +end + +-- FUNCTION -- +local function HDRMerge() + dt.print_log("Running HDRMerge") + dt.print("Running HDRMerge") + gui_job = dt.gui.create_job("HDRMerge", 1) + df.set_executable_path_preference("hdrmerge", dt.preferences.read("module_HDRMerge", "bin_path", "string")) + dt.print_log("Executable Path Preference: "..df.get_executable_path_preference("hdrmerge")) + + --Inits-- + local images = dt.gui.selection() + local images_to_merge = "" + local image_path = "" + local curr_image = "" + local first_image = "" + local last_image = "" + local output_file = "" + local num_images = 0 + + --Read Settings-- + set_bps = HDRMerge_cmbx_bps.value + set_size = HDRMerge_cmbx_size.value + set_batch = HDRMerge_chkbtn_batch.value + set_gap = HDRMerge_sldr_gap.value + set_cpytags = HDRMerge_chkbtn_cpytags.value + set_tag = HDRMerge_entry_tag.text + + --Create Images String-- + for _,image in pairs(images) do + curr_image = image.path..os_path_seperator..image.filename + images_to_merge = images_to_merge..curr_image.." " + last_image = string.gsub(string.match(image.filename,'^.*%.'), "%." , "") + image_path = image.path + if _ == 1 then first_image = last_image end + num_images = num_images + 1 + end + output_file = image_path..os_path_seperator..first_image.."-"..string.match(last_image, '%d*$')..".dng" + + --Check if at least 2 images selected-- + if num_images < 2 then + dt.print_error("Less than 2 images selected") + dt.print("ERROR - please select at least 2 images") + gui_job.valid = false + return + end + + --Check if HDRMerge is installed-- + local HDRMerge_Path = df.check_if_bin_exists("hdrmerge") + if not HDRMerge_Path then + dt.print_error("HDRMerge not found") + dt.print("ERROR - HDRMerge not found") + gui_job.valid = false + return + end + + --Create Command Args-- + cmd_args = "-b "..set_bps.." -p "..set_size + if (set_batch) then + cmd_args = cmd_args.." -B -g "..set_gap.." -a" + else --add ability to launch with gui here by omiting -o arg + cmd_args = cmd_args.." -o "..output_file + end + + gui_job.percent = .1 + + --Execute with Run Command-- + run_cmd = build_execute_command(HDRMerge_Path, cmd_args, images_to_merge) + dt.print_log("run_cmd = "..run_cmd) + resp = dt.control.execute(run_cmd) + + gui_job.percent = .9 + + if resp == 0 and not(set_batch) then + --Import Image-- + imported = dt.database.import(output_file) + + --Apply Selected Style (IF)-- + if HDRMerge_cmbx_style.selected > 1 then + set_style = styles[HDRMerge_cmbx_style.selected - 1] + dt.styles.apply(set_style , imported) + end + + --Copy Tags (IF)-- + if (set_cpytags) then + all_tags = dt.tags.get_tags(images[1]) + for _,tag in pairs(all_tags) do + if string.match(tag.name, 'darktable|') == nil then + dt.tags.attach(tag, imported) + end + end + end + + --Apply Entered Tags (IF)-- + if set_tag ~= nil then + for tag in string.gmatch(set_tag, '[^,]+') do + tag = string.gsub(tag, " ", "") + tag = dt.tags.create(tag) + dt.tags.attach(tag, imported) + end + end + + dt.print_log("Merge Successful") + dt.print("Merge Successful") + elseif resp == 0 then + dt.print_log("Merge Successful") + dt.print("Merge Successful") + else + dt.print_error("Merge Not Successful") + dt.print("ERROR - Merge Not Successful") + end + gui_job.percent = 1 + gui_job.valid = false +end + +-- GUI -- +local executables = {"hdrmerge"} +if dt.configuration.running_os ~= "linux" then + path_widget = df.executable_path_widget(executables) +end + +HDRMerge_lbl_base= dt.new_widget("section_label"){ + label = "Base Options", + } +HDRMerge_cmbx_bps = dt.new_widget("combobox"){ + label = 'Bits Per Sample', + tooltip = 'Output file\'s bit depth \ndefault: '..pref_bps, + value = pref_bps_enum, + "16", "24", "32", + } +HDRMerge_cmbx_size = dt.new_widget("combobox"){ + label = 'Preview Size', + tooltip = 'Output file\'s built-in preview size \ndefault: '..pref_size, + value = pref_size_enum, + "half", "full", "none", + } +HDRMerge_lbl_batch= dt.new_widget("section_label"){ + label = "Batch Options", + } +HDRMerge_chkbtn_batch = dt.new_widget("check_button"){ + label = ' Batch Mode', + value = false, --pref_batch, + tooltip ='Operate in batch mode. When operating in batch mode output files will NOT be auto-imported \ndefault: (false).', + } +HDRMerge_sldr_gap = dt.new_widget("slider"){ + label = 'Batch Gap [sec.]', + tooltip = 'Gap, in seconds, between batch mode groups \ndefault: (3).', + soft_min = 1, + soft_max = 60, + hard_min = 1, + hard_max = 60, + step = 1, + digits = 0, + value = 3, --pref_gap, + } +HDRMerge_lbl_out= dt.new_widget("section_label"){ + label = "Auto-import Options", + } +HDRMerge_cmbx_style = dt.new_widget("combobox"){ + label = "Apply Style on Import", + tooltip = "Apply selected style on auto-import to newly created HDRMerge DNG\nDoes not apply when in Batch mode.", + value = 1, + "none", + } +pref_style_enum = 1 + for k=1, (styles_count-1) do + HDRMerge_cmbx_style[k+1] = styles[k].name + if styles[k].name == pref_style then pref_style_enum = k+1 end +end +HDRMerge_cmbx_style.value = pref_style_enum +HDRMerge_chkbtn_cpytags = dt.new_widget("check_button"){ + label = ' Copy Tags', + value = pref_cpytags, + tooltip ='Copy tags from first image. When operating in batch mode this will NOT be performed. \ndefault: (true).', + } +HDRMerge_lbl_tags= dt.new_widget("label"){ + label = 'Additional Tags', + } +HDRMerge_entry_tag = dt.new_widget("entry"){ + tooltip = "Additional tags to be added on import. Seperate with commas, all spaces will be removed", + text = pref_addtags, + placeholder = "Enter tags, seperated by commas", + editable = true +} +HDRMerge_btn_run = dt.new_widget("button"){ + label = "Run HDRMerge", + tooltip = "Runs HDRMerge on selected images, with selected settings", + clicked_callback = function() HDRMerge() end + } +HDRMerge_lbl_note= dt.new_widget("label"){ + label = 'Defaults can be adjusted under:\n"Settings > lua options"', + } +dt.register_lib( + "HDRMerge_Lib", -- Module name + "HDRMerge", -- name + true, -- expandable + false, -- resetable + {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 99}}, -- containers + dt.new_widget("box"){ + orientation = "vertical", + HDRMerge_lbl_base, + HDRMerge_cmbx_bps, + HDRMerge_cmbx_size, + HDRMerge_lbl_batch, + HDRMerge_chkbtn_batch, + HDRMerge_sldr_gap, + HDRMerge_lbl_out, + HDRMerge_cmbx_style, + HDRMerge_chkbtn_cpytags, + HDRMerge_lbl_tags, + HDRMerge_entry_tag, + HDRMerge_btn_run, + HDRMerge_lbl_note + } +) + +-- PREFERENCES -- +entry_widget_tags = dt.new_widget("entry"){ + tooltip = "Seperate with commas, all spaces will be removed", + text = nil, + placeholder = "Enter default tags", + editable = true +} +dt.preferences.register("module_HDRMerge", "add_tags", -- name + "string", -- type + 'HDRMerge: Defualt additional tags', -- label + 'Changes DEFAULT entry in the additional tags option. Requires restart to take effect.', -- tooltip + "", -- default + entry_widget_tags +) +entry_widget_style = dt.new_widget("entry"){ + tooltip = "Enter the style name exactly as it is", + text = nil, + placeholder = "Enter Style name", + editable = true +} +dt.preferences.register("module_HDRMerge", "style", -- name + "string", -- type + 'HDRMerge: Defualt Style', -- label + 'Changes DEFAULT entry in the Style option. Requires restart to take effect.', -- tooltip + "", -- default + entry_widget_style +) +dt.preferences.register("module_HDRMerge", "copy_tags", -- name + "bool", -- type + 'HDRMerge: Copy tags from first image by default', -- label + 'Changes DEFAULT selection for Copy Tags, Requires restart to take effect.', -- tooltip + true -- default +) +dt.preferences.register("module_HDRMerge", "preview_size", -- name + "enum", -- type + 'HDRMerge: Default DNG Preview Size', -- label + "Change the DEFAULT preview size. Requires restart to take effect.", -- tooltip + "half", -- default + "full", "none" --values +) +dt.preferences.register("module_HDRMerge", "bits_per_sample", -- name + "enum", -- type + 'HDRMerge: Default Bits Per Sample', -- label + 'Change the DEFAULT bit depth. Requires restart to take effect.', -- tooltip + "16", -- default + "24","32" --value +) +executable = "hdrmerge" +bin_path = df.get_executable_path_preference(executable) +if not bin_path then + bin_path = "" +end +path_widget = dt.new_widget("file_chooser_button"){ + title = "Select HDRMerge[.exe] file", + value = bin_path, + is_directory = false, +} +dt.preferences.register("module_HDRMerge", "bin_path", -- name + "file", -- type + 'HDRMerge: Binary Location', -- label + 'Install location of HDRMerge[.exe]. Requires restart to take effect.', -- tooltip + "hdrmerge", -- default + path_widget +) diff --git a/contrib/OpenInPS.lua b/contrib/OpenInPS.lua new file mode 100644 index 0000000..faca5de --- /dev/null +++ b/contrib/OpenInPS.lua @@ -0,0 +1,199 @@ +--[[ OpenInPS plugin for darktable + + copyright (c) 2018 Kevin Ertel + + darktable is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + darktable is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with darktable. If not, see . +]] + +--[[ Version 1.1.0 6/30/2018 + +This plugin adds the module "OpenInPS" to darktable's lighttable view + +****Dependencies**** +OS: Windows (tested), Linux (not verified), MacOS (not verified) +Photoshop + +****How to use**** +Require this file from your luarc file, as with any other dt plug-in. +On initial run, setup the Photoshop executable path via the settings > lua options dialog. Restart may be required. +Select the photo(s) you wish to open in Photoshop and press Open from the Open in Photoshop box + RAW files will open in ACR inside Photoshop + JPG, Tif, etc will open as a new file inside PS + Since this is opening the file, not exporting and then opening, it will NOT have any of your Darktable edits +Select the photo(s) you wish to export to Photoshop and select the desired destination folder, set the rest of + the export settings as with any other export from darktable. Since this is "exporting" file will be converted + from RAW to your chosen format and darktable edits WILL carry over. Note the files created by this will NOT be + automatically deleted or cleaned up, ever. +]] + +local dt = require "darktable" +local df = require "lib/dtutils.file" +require "official/yield" + +--Detect OS and modify accordingly-- +op_sys = dt.configuration.running_os +if op_sys == "windows" then + os_path_seperator = "\\" +else + os_path_seperator = "/" +end + +-- READ PREFERENCES -- +df.set_executable_path_preference("openinps", dt.preferences.read("module_OpenInPS", "bin_path", "string")) +dt.print_log("OpenInPS - Executable Path Preference: "..df.get_executable_path_preference("openinps")) +last_used_location = dt.preferences.read("module_OpenInPS", "export_path", "string") + +local function build_execute_command(cmd, args, file_list) + local result = false + + if dt.configuration.running_os == "macos" then + cmd = string.gsub(cmd, "open", "", 1) + cmd = string.gsub(cmd, "-W", "", 1) + cmd = string.gsub(cmd, "-a", "", 1) + end + result = cmd.." "..args.." "..file_list + return result +end + +-- FUNCTION -- +local function truncate(x) + return x<0 and math.ceil(x) or math.floor(x) +end +local function show_status(storage, image, format, filename, --Store: Called on each exported image + number, total, high_quality, extra_data) + dt.print('Export to Photoshop: '..tostring(truncate(number)).." / "..tostring(truncate(total))) +end + +local function OpenInPS() --OPEN in Photoshop + dt.print_log("Opening in Photoshop") + dt.print("Opening In Photoshop") + + local PS_Path = df.check_if_bin_exists("openinps") + if not PS_Path then + dt.print_error("Photoshop not found") + dt.print("ERROR - Photoshop not found") + return + end + + --Inits-- + local images = dt.gui.selection() + local curr_image = "" + local images_to_open = "" + + for _,image in pairs(images) do + curr_image = image.path..os_path_seperator..image.filename + images_to_open = images_to_open.." "..curr_image + end + run_cmd = build_execute_command(PS_Path, "" , images_to_open) + dt.print_log("OpenInPS run_cmd = "..run_cmd) + dt.print("Opening in Photoshop") + resp = dt.control.execute(run_cmd) +end +local function ExportToPS(storage, image_table, extra_data) --EXPORT to Photoshop + dt.print_log("Exporting to Photoshop") + dt.print("Exporting to Photoshop") + + local PS_Path = df.check_if_bin_exists("openinps") + if not PS_Path then + dt.print_error("Photoshop not found") + dt.print("ERROR - Photoshop not found") + return + end + + --Inits-- + local image_path = "" + local images_to_open = "" + local chooser_path = file_chooser_button_path.value + dt.preferences.write("module_OpenInPS", "export_path", "string", chooser_path) + + + for image,temp_path in pairs(image_table) do + dt.print_log(image.filename) + new_path = chooser_path..os_path_seperator..image.filename + while df.check_if_file_exists(new_path) do + new_path = df.filename_increment(new_path) + -- limit to 99 more exports of the original export + if string.match(df.get_basename(new_path), "_(d-)$") == "99" then + break + end + end + result = df.file_move(temp_path, new_path) + images_to_open = images_to_open..new_path.." " + end + dt.print_log("Result: "..tostring(result)) + run_cmd = build_execute_command(PS_Path, "" , images_to_open) + dt.print_log("ExportToPS run_cmd = "..run_cmd) + dt.print("Opening in Photoshop") + resp = dt.control.execute(run_cmd) +end + +-- GUI -- +local executables = {"openinps"} +if dt.configuration.running_os ~= "linux" then + path_widget = df.executable_path_widget(executables) +end +OpenInPS_btn_run = dt.new_widget("button"){ + label = "Open", + tooltip = "Opens selected image in Photoshop", + clicked_callback = function() OpenInPS() end + } +dt.register_lib( --OpenInPS + "OpenInPS_Lib", -- Module name + "Open In Photoshop", -- name + true, -- expandable + false, -- resetable + {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 99}}, -- containers + dt.new_widget("box"){ + orientation = "vertical", + OpenInPS_btn_run + } +) + +file_chooser_button_path = dt.new_widget("file_chooser_button"){ + title = 'Select export path', -- The title of the window when choosing a file + value = last_used_location, + is_directory = true, -- True if the file chooser button only allows directories to be selected + tooltip ='select the target directory for the image(s)', +} +dt.register_storage( + "ExportToPS_Storage", --Module name + "Export to Photoshop", --Name + show_status, --store: called once per exported image + ExportToPS, --finalize: + nil, --supported: + nil, --initialize: + dt.new_widget("box"){ + orientation = "vertical", + file_chooser_button_path + } + ) + +-- PREFERENCES -- +executable = "hdrmerge" +bin_path = df.get_executable_path_preference(executable) +if not bin_path then + bin_path = "" +end +path_widget = dt.new_widget("file_chooser_button"){ + title = "Select Photoshop executable", + value = bin_path, + is_directory = false, +} +dt.preferences.register("module_OpenInPS", "bin_path", -- name + "file", -- type + 'OpenInPS: Photoshop exe location', -- label + 'Location of Photoshop executable. Requires restart to take effect.', -- tooltip + "Please Select", -- default + path_widget +) \ No newline at end of file diff --git a/contrib/enfuse_pro_2.lua b/contrib/enfuse_pro_2.lua new file mode 100644 index 0000000..7349ac4 --- /dev/null +++ b/contrib/enfuse_pro_2.lua @@ -0,0 +1,1051 @@ +--[[ + Enfuse professional plugin for darktable 2.2.X and 2.4.X + + copyright (c) 2017, 2018 Holger Klemm (Original Linux-only version) + + darktable is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + darktable is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with darktable. If not, see . +]] + +--[[ Enfuse Pro 2 - cross-platform compatible +Modified by: Kevin Ertel + +ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT +* align_image_stack +* enfuse +* exiftool + +USAGE +* require this file from your main luarc config file. + +This plugin will add the new export modul "fusion to DRI or DFF image". +]] + +local dt = require "darktable" +local df = require "lib/dtutils.file" +local gettext = dt.gettext + +-- works with LUA API version 4.0.0 and 5.0.0 +dt.configuration.check_version(...,{4,0,0},{5,0,0}) + +-- Tell gettext where to find the .mo file translating messages for a particular domain +gettext.bindtextdomain("enfuse_pro",dt.configuration.config_dir.."/lua/") + +local function _(msgid) + return gettext.dgettext("enfuse_pro", msgid) +end + +--Detect User Styles-- +styles = dt.styles +styles_count = 1 -- "none" = 1 +for _,i in pairs(dt.styles) do + if type(i) == "userdata" then styles_count = styles_count + 1 end +end + +-- INITS -- +pref_style = dt.preferences.read("module_enfuse_pro", "style", "string") +pref_cpytags = dt.preferences.read("module_enfuse_pro", "copy_tags", "bool") +pref_addtags = dt.preferences.read("module_enfuse_pro", "add_tags", "string") +--[[ +cmd_tmp_path="" +cmd_output_path="" +cmd_output_image="" +cmd_output_image_index = 0 +path_with_filename="" +homepath=os.getenv("Public") +tmppath=homepath.."/.local/tmp" +cmd_exif_copy_exif="" +cmd_suffix_output_format="" +alignStartCommand="" +enfuseStartCommand="" +exifStartCommand="" +outputindex = 0 +job = 0 +]] +if dt.configuration.running_os == "windows" then + os_path_seperator = "\\" +else + os_path_seperator = "/" +end + + +-- align defaults +--dt.preferences.write("enfuse_pro", "initialized", "bool", false) +if not(dt.preferences.read("enfuse_pro", "initialized", "bool")) then + dt.preferences.write("enfuse_pro", "selected_fusion", "integer", 1) + dt.preferences.write("enfuse_pro", "def_radial_distortion", "bool", false) + dt.preferences.write("enfuse_pro", "def_optimize_field", "bool", false) + dt.preferences.write("enfuse_pro", "def_optimize_image_center", "bool", true) + dt.preferences.write("enfuse_pro", "def_auto_crop", "bool", true) + dt.preferences.write("enfuse_pro", "def_distortion", "bool", true) + dt.preferences.write("enfuse_pro", "def_grid_size", "integer", 5) + dt.preferences.write("enfuse_pro", "def_control_points", "integer", 8) + dt.preferences.write("enfuse_pro", "def_control_points_remove", "integer", 3) + dt.preferences.write("enfuse_pro", "def_correlation", "integer", 9) + + -- enfuse defaults + dt.preferences.write("enfuse_pro", "def_fusion_type", "integer", 1) + dt.preferences.write("enfuse_pro", "def_image_variants", "bool", false) + dt.preferences.write("enfuse_pro", "def_hard_masks", "bool", false) + dt.preferences.write("enfuse_pro", "def_save_masks", "bool", false) + dt.preferences.write("enfuse_pro", "def_contrast_window_size", "integer", 3) + dt.preferences.write("enfuse_pro", "def_contrast_edge_scale", "integer", 1) + dt.preferences.write("enfuse_pro", "def_contrast_min_curvature", "integer", 1) + dt.preferences.write("enfuse_pro", "def_exposure_weight", "float", 1.0) + dt.preferences.write("enfuse_pro", "def_saturation_weight", "float", 0.2) + dt.preferences.write("enfuse_pro", "def_contrast_weight", "float", 0.0) + dt.preferences.write("enfuse_pro", "def_exposure_optimum_weight", "float", 0.5) + dt.preferences.write("enfuse_pro", "def_exposure_width_weight", "float",0.2) + dt.preferences.write("enfuse_pro", "selected_overwrite", "integer",1) + dt.preferences.write("enfuse_pro", "sentitiv_overwrite", "bool",true) + + -- preset DRI 1 + temp_text = {"dri1_","dri2_","dri3_"} + for i,preset in pairs(temp_text) do + dt.preferences.write("enfuse_pro", preset.."hard_masks", "bool", false) + dt.preferences.write("enfuse_pro", preset.."save_masks", "bool", false) + dt.preferences.write("enfuse_pro", preset.."contrast_window_size", "integer", 3) + dt.preferences.write("enfuse_pro", preset.."contrast_edge_scale", "integer", 1) + dt.preferences.write("enfuse_pro", preset.."contrast_min_curvature", "integer", 1) + dt.preferences.write("enfuse_pro", preset.."exposure_weight", "float", 1.0) + dt.preferences.write("enfuse_pro", preset.."saturation_weight", "float", 0.2) + dt.preferences.write("enfuse_pro", preset.."contrast_weight", "float", 0.0) + dt.preferences.write("enfuse_pro", preset.."exposure_optimum_weight", "float", 0.5) + dt.preferences.write("enfuse_pro", preset.."exposure_width_weight", "float",0.2) + end + + -- preset DFF 1 + temp_text = {"dff1_","dff2_","dff3_"} + for i,preset in pairs(temp_text) do + dt.preferences.write("enfuse_pro", preset.."hard_masks", "bool", true) + dt.preferences.write("enfuse_pro", preset.."save_masks", "bool", false) + dt.preferences.write("enfuse_pro", preset.."contrast_window_size", "integer", 3) + dt.preferences.write("enfuse_pro", preset.."contrast_edge_scale", "integer", 1) + dt.preferences.write("enfuse_pro", preset.."contrast_min_curvature", "integer", 1) + dt.preferences.write("enfuse_pro", preset.."exposure_weight", "float", 0.0) + dt.preferences.write("enfuse_pro", preset.."saturation_weight", "float", 0.0) + dt.preferences.write("enfuse_pro", preset.."contrast_weight", "float", 1.0) + dt.preferences.write("enfuse_pro", preset.."exposure_optimum_weight", "float", 0.5) + dt.preferences.write("enfuse_pro", preset.."exposure_width_weight", "float",0.2) + end + + -- preset FREE + dt.preferences.write("enfuse_pro", "free_hard_masks", "bool", false) + dt.preferences.write("enfuse_pro", "free_save_masks", "bool", false) + dt.preferences.write("enfuse_pro", "free_contrast_window_size", "integer", 3) + dt.preferences.write("enfuse_pro", "free_contrast_edge_scale", "integer", 1) + dt.preferences.write("enfuse_pro", "free_contrast_min_curvature", "integer", 1) + dt.preferences.write("enfuse_pro", "free_exposure_weight", "float", 0.0) + dt.preferences.write("enfuse_pro", "free_saturation_weight", "float", 0.0) + dt.preferences.write("enfuse_pro", "free_contrast_weight", "float", 0.0) + dt.preferences.write("enfuse_pro", "free_exposure_optimum_weight", "float", 0.0) + dt.preferences.write("enfuse_pro", "free_exposure_width_weight", "float",0.0) + + -- output + dt.preferences.write("enfuse_pro", "selected_output_format", "integer", 1) + dt.preferences.write("enfuse_pro", "initialized", "bool", true) +end + +--GUI +j=0 +local separator1 = dt.new_widget("separator"){} +local separator1b = dt.new_widget("separator"){} +local separator2 = dt.new_widget("separator"){} +local separator2b = dt.new_widget("separator"){} +local label_align_options= dt.new_widget("section_label"){ + label = _('image align options') +} +local label_enfuse_options= dt.new_widget("section_label"){ + label = _('image fusion options') +} +local label_output_format= dt.new_widget("section_label"){ + label = _('target file') +} +local label_path = dt.new_widget("label"){ + label = _('directory'), + ellipsize = "start", + halign = "start" +} +chkbtn_radial_distortion = dt.new_widget("check_button"){ + label = _('optimize radial distortion for all images'), + value = dt.preferences.read("enfuse_pro", "def_radial_distortion", "bool"), + tooltip = _('optimize radial distortion for all images, \nexcept for first'), +} +chkbtn_optimize_field = dt.new_widget("check_button"){ + label = _('optimize field of view for all images'), + value = dt.preferences.read("enfuse_pro", "def_optimize_field", "bool"), + tooltip =_('optimize field of view for all images, except for first. \nUseful for aligning focus stacks (DFF) with slightly \ndifferent magnification.'), +} +chkbtn_optimize_image_center = dt.new_widget("check_button"){ + label = _('optimize image center shift for all images'), + value = dt.preferences.read("enfuse_pro", "def_optimize_image_center", "bool"), + tooltip =_('optimize image center shift for all images, \nexcept for first.'), +} +chkbtn_auto_crop = dt.new_widget("check_button"){ + label = _('auto crop the image'), + value = dt.preferences.read("enfuse_pro", "def_auto_crop", "bool"), + tooltip =_('auto crop the image to the area covered by all images.'), +} +chkbtn_distortion = dt.new_widget("check_button"){ + label = _('load distortion from lens database'), + value = dt.preferences.read("enfuse_pro", "def_distortion", "bool"), + tooltip =_('try to load distortion information from lens database'), +} +chkbtn_hard_masks = dt.new_widget("check_button"){ + label = _('hard mask'), + value = dt.preferences.read("enfuse_pro", "def_hard_masks", "bool"), + tooltip =_('force hard blend masks on the finest scale. this avoids \naveraging of fine details (only), at the expense \nof increasing the noise. this improves the \nsharpness of focus stacks considerably.\ndefault (soft mask)'), + reset_callback = function(self) + self.value = dt.preferences.read("enfuse_pro", "def_hard_masks", "bool") + end +} +chkbtn_save_masks = dt.new_widget("check_button"){ + label = _('save masks'), + value = dt.preferences.read("enfuse_pro", "def_save_masks", "bool"), + tooltip =_('Save the generated weight masks to your home directory,\nenblend saves masks as 8 bit grayscale, \ni.e. single channel images. \nfor accuracy we recommend to choose a lossless format.'), + reset_callback = function(self) + self.value = dt.preferences.read("enfuse_pro", "def_save_masks", "bool") + end +} +chkbtn_cpytags = dt.new_widget("check_button"){ + label = ' Copy Tags', + value = pref_cpytags, + tooltip ='Copy tags from first image.', +} +sldr_exposure_weight = dt.new_widget("slider"){ + label = _('exposure weight'), + tooltip = _('set the relative weight of the well-exposedness criterion \nas defined by the chosen exposure weight function. \nincreasing this weight relative to the others will\n make well-exposed pixels contribute more to\n the final output. \ndefault: (1.0)'), + hard_min = 0, + hard_max = 1, + value = dt.preferences.read("enfuse_pro", "def_exposure_weight", "float") --1 def +} +sldr_saturation_weight = dt.new_widget("slider"){ + label = _('saturation weight'), + tooltip = _('set the relative weight of high-saturation pixels. \nincreasing this weight makes pixels with high \nsaturation contribute more to the final output. \ndefault: (0.2)'), + hard_min = 0, + hard_max = 1, + value = dt.preferences.read("enfuse_pro", "def_saturation_weight", "float"), --0.5 +} +sldr_contrast_weight = dt.new_widget("slider"){ + label = _('contrast weight'), + tooltip = _('sets the relative weight of high local-contrast pixels. \ndefault: (0.0).'), + hard_min = 0, + hard_max = 1, + value = dt.preferences.read("enfuse_pro", "def_contrast_weight", "float")--0 default +} +sldr_exposure_optimum_weight = dt.new_widget("slider"){ + label = _('exposure optimum'), + tooltip = _('determine at what normalized exposure value\n the optimum exposure of the input images\n is. this is, set the position of the maximum\n of the exposure weight curve. use this \noption to fine-tune exposure weighting. \ndefault: (0.5)'), + hard_min = 0, + hard_max = 1, + value = dt.preferences.read("enfuse_pro", "def_exposure_optimum_weight", "float")--0.5 default0 +} +sldr_exposure_width_weight = dt.new_widget("slider"){ + label = _('exposure width'), + tooltip = _('set the characteristic width (FWHM) of the exposure \nweight function. low numbers give less weight to \npixels that are far from the user-defined \noptimum and vice versa. use this option to \nfine-tune exposure weighting. \ndefault: (0.2)'), + hard_min = 0, + hard_max = 1, + value = dt.preferences.read("enfuse_pro", "def_exposure_width_weight", "float") --0.2 default +} +file_chooser_button_path = dt.new_widget("file_chooser_button"){ + title = _('Select export path'), -- The title of the window when choosing a file + is_directory = true, -- True if the file chooser button only allows directories to be selecte + tooltip =_('select the target directory for the fused image. \nthe filename is created automatically.'), +} +chkbtn_source_location = dt.new_widget("check_button"){ + label = _('save to source image location'), + value = true, + tooltip =_('If checked ignores the location below and saves output image(s) to the same location as the source images.'), + reset_callback = function(self) + self.value = true + end +} +cmbx_grid_size = dt.new_widget("combobox"){ + label = _('image grid size'), + tooltip =_('break image into a rectangular grid \nand attempt to find num control points in each section.\ndefault: (5x5)'), + value = dt.preferences.read("enfuse_pro", "def_grid_size", "integer"), --5 + "1", "2", "3","4","5","6","7","8","9", + reset_callback = function(self) + self.value = dt.preferences.read("enfuse_pro", "def_grid_size", "integer") + end +} +cmbx_control_points = dt.new_widget("combobox"){ + label = _('control points/grid'), + tooltip =_('number of control points (per grid, see option -g) \nto create between adjacent images \ndefault: (8).'), + value = dt.preferences.read("enfuse_pro", "def_control_points", "integer"), --8, "1", "2", "3","4","5","6","7","8","9", + "1", "2", "3","4","5","6","7","8","9", + reset_callback = function(self) + self.value = dt.preferences.read("enfuse_pro", "def_control_points", "integer") + end +} +cmbx_control_points_remove = dt.new_widget("combobox"){ + label = _('remove control points with error'), + tooltip =_('remove all control points with an error higher \nthan num pixels \ndefault: (3)'), + value = dt.preferences.read("enfuse_pro", "def_control_points_remove", "integer"), --3, "1", "2", "3","4","5","6","7","8","9", + "1", "2", "3","4","5","6","7","8","9", + reset_callback = function(self) + self.value = dt.preferences.read("enfuse_pro", "def_control_points_remove", "integer") + end +} +cmbx_correlation = dt.new_widget("combobox"){ + label = _('correlation threshold for control points'), + tooltip =_('correlation threshold for identifying \ncontrol points \ndefault: (0.9).'), + value = dt.preferences.read("enfuse_pro", "def_correlation", "integer"), --9, "0,1", "0,2", "0,3","0,4","0,5","0,6","0,7","0,8","0,9", + "0.1", "0.2", "0.3","0.4","0.5","0.6","0.7","0.8","0.9","1.0", + reset_callback = function(self) + self.value = dt.preferences.read("enfuse_pro", "def_correlation", "integer") + end +} +cmbx_contrast_window_size = dt.new_widget("combobox"){ + label = _('contrast window size'), + tooltip =_('set the window size for local contrast analysis. \nthe window will be a square of size × size pixels. \nif given an even size, Enfuse will \nautomatically use the next odd number.\nfor contrast analysis size values larger \nthan 5 pixels might result in a \nblurry composite image. values of 3 and \n5 pixels have given good results on \nfocus stacks. \ndefault: (5) pixels'), + value = dt.preferences.read("enfuse_pro", "def_contrast_window_size", "integer"), --3, "3","4","5","6","7","8","9","10", + "3", "4", "5","6","7","8","9","10", +} +cmbx_contrast_edge_scale = dt.new_widget("combobox"){ + label = _('contrast edge scale'), + tooltip =_('a non-zero value for EDGE-SCALE switches on the \nLaplacian-of-Gaussian (LoG) edge detection algorithm.\n edage-scale is the radius of the Gaussian used \nin the search for edges. a positive LCE-SCALE \nturns on local contrast enhancement (LCE) \nbefore the LoG edge detection. \nDefault: (0.0) pixels.'), + value = dt.preferences.read("enfuse_pro", "def_contrast_edge_scale", "integer"), --1, "0:0:0", + "0.0","0.1","0.2","0.3","0.4","0.5", + +} +cmbx_contrast_min_curvature = dt.new_widget("combobox"){ + label = _('contrast min curvature'), + tooltip =_('define the minimum curvature for the LoG edge detection. Append a ‘%’ to specify the minimum curvature relative to maximum pixel value in the source image. Default: (0.0%)'), + value = dt.preferences.read("enfuse_pro", "def_contrast_min_curvature", "integer"), --1, "0.0%","0.1%", "0.2%", "0.3%","0.4%","0.5%","0.6%","0.7%","0.8%","0.9%","1.0%", + "0.0%", "0.1%", "0.2%","0.3%","0.4%","0.5%","0.6%","0.7%","0.8%","0.9%","1.0%", +} +cmbx_existing_file = dt.new_widget("combobox"){ + label = _('on conflict'), + value = dt.preferences.read("enfuse_pro", "selected_overwrite", "integer"), --1, + sensitive= dt.preferences.read("enfuse_pro", "sentitiv_overwrite", "bool"), --1, + _('create unique filename'),_('overwrite'), + reset_callback = function(self) + self.value = dt.preferences.read("enfuse_pro", "selected_overwrite", "integer") + end +} +cmbx_style = dt.new_widget("combobox"){ + label = "Apply Style on Import", + tooltip = "Apply selected style on auto-import to newly created blended image", + value = 1, + "none", + } +pref_style_enum = 1 +for k=1, (styles_count-1) do + cmbx_style[k+1] = styles[k].name + if styles[k].name == pref_style then pref_style_enum = k+1 end +end +cmbx_style.value = pref_style_enum +chkbtn_image_variations = dt.new_widget("check_button"){ + label = _('create image variants with saved presets'), + value = dt.preferences.read("enfuse_pro", "def_image_variants", "bool"), + tooltip =_('creates image variants with the three \nsaved DRI or DFF presets'), + sensitive=true, + clicked_callback = function(self) + if (self.value) then + dt.preferences.write("enfuse_pro", "def_image_variants", "bool", true) + dt.preferences.write("enfuse_pro", "sentitiv_overwrite", "bool",false) + cmbx_existing_file.value=1 + cmbx_existing_file.sensitive=false + else + dt.preferences.write("enfuse_pro", "def_image_variants", "bool", false) + dt.preferences.write("enfuse_pro", "sentitiv_overwrite", "bool",true) + cmbx_existing_file.sensitive=true + end + end, + reset_callback = function(self) + dt.preferences.write("enfuse_pro", "def_image_variants", "bool", false) + dt.preferences.write("enfuse_pro", "sentitiv_overwrite", "bool",true) + self.value = false + cmbx_existing_file.sensitive=true + end + +} +button_save_preset = dt.new_widget("button"){ + label = _('save fusion preset'), + tooltip =_('save the selected fusion preset'), + clicked_callback = function() + pref_text = "" + if (cmbx_fusion_type.value == "1 - DRI image") then + pref_text = "dri1_" + elseif (cmbx_fusion_type.value == "2 - DRI image") then + pref_text = "dri2_" + elseif (cmbx_fusion_type.value == "3 - DRI image") then + pref_text = "dri3_" + elseif (cmbx_fusion_type.value == "1 - DFF image") then + pref_text = "dff1_" + elseif (cmbx_fusion_type.value == "2 - DFF image") then + pref_text = "dff2_" + elseif (cmbx_fusion_type.value == "3 - DFF image") then + pref_text = "dff3_" + elseif (cmbx_fusion_type.value == "free preset") then + pref_text = "free_" + else + dt.print(_('unkown error')) + end + -- Write Preset + if pref_text ~= "" then + dt.preferences.write("enfuse_pro", pref_text.."hard_masks", "bool", chkbtn_hard_masks.value) + dt.preferences.write("enfuse_pro", pref_text.."save_masks", "bool", chkbtn_save_masks.value) + dt.preferences.write("enfuse_pro", pref_text.."contrast_window_size", "integer", cmbx_contrast_window_size.selected) + dt.preferences.write("enfuse_pro", pref_text.."contrast_edge_scale", "integer", cmbx_contrast_edge_scale.selected) + dt.preferences.write("enfuse_pro", pref_text.."contrast_min_curvature", "integer", cmbx_contrast_min_curvature.selected) + dt.preferences.write("enfuse_pro", pref_text.."exposure_weight", "float", sldr_exposure_weight.value) + dt.preferences.write("enfuse_pro", pref_text.."saturation_weight", "float", sldr_saturation_weight.value) + dt.preferences.write("enfuse_pro", pref_text.."contrast_weight", "float", sldr_contrast_weight.value) + dt.preferences.write("enfuse_pro", pref_text.."exposure_optimum_weight", "float", sldr_exposure_optimum_weight.value) + dt.preferences.write("enfuse_pro", pref_text.."exposure_width_weight", "float",sldr_exposure_width_weight.value) + dt.print(_('preset '..pref_text..' saved')) + end + end +} +button_load_preset = dt.new_widget("button"){ + label = _('load fusion defaults'), + tooltip =_('load the default fusion settings'), + clicked_callback = function() + chkbtn_hard_masks.value=dt.preferences.read("enfuse_pro", "def_hard_masks", "bool") + chkbtn_save_masks.value=dt.preferences.read("enfuse_pro", "def_save_masks", "bool") + cmbx_contrast_window_size.value=dt.preferences.read("enfuse_pro", "def_contrast_window_size", "integer") + cmbx_contrast_edge_scale.value=dt.preferences.read("enfuse_pro", "def_contrast_edge_scale", "integer") + cmbx_contrast_min_curvature.value=dt.preferences.read("enfuse_pro", "def_contrast_min_curvature", "integer") + sldr_exposure_weight.value=dt.preferences.read("enfuse_pro", "def_exposure_weight", "float") + sldr_saturation_weight.value=dt.preferences.read("enfuse_pro", "def_saturation_weight", "float") + sldr_contrast_weight.value=dt.preferences.read("enfuse_pro", "def_contrast_weight", "float") + sldr_exposure_optimum_weight.value=dt.preferences.read("enfuse_pro", "def_exposure_optimum_weight", "float") + sldr_exposure_width_weight.value=dt.preferences.read("enfuse_pro", "def_exposure_width_weight", "float") + end + +} +cmbx_output_format = dt.new_widget("combobox"){ + label = _('file format'), + value = dt.preferences.read("enfuse_pro", "selected_output_format", "integer"), --1, "TIFF", "JPEG", "PNG","PNM","PBM","PGM","PPM", + changed_callback = function(self) + dt.preferences.write("enfuse_pro", "selected_output_format", "integer", self.selected) + end, + "TIFF", "JPEG", "PNG","PNM","PBM","PPM", + reset_callback = function(self) + self.value = dt.preferences.read("enfuse_pro", "selected_output_format", "integer") + end +} +cmbx_fusion_type = dt.new_widget("combobox"){ + label = _('fusion preset'), + tooltip =_('select the preset and save the preset\n if you want to reuse it or create an image\n variant'), + value = 1, --dt.preferences.read("enfuse_pro", "def_fusion_type", "integer"), --1, "DRI image", "DFF image", "without preset", + changed_callback = function(self) + dt.preferences.write("enfuse_pro", "def_fusion_type", "integer", self.selected) + + if (self.value == "1 - DRI image") then + pref_text = "dri1_" + elseif (self.value == "2 - DRI image") then + pref_text = "dri2_" + elseif (self.value == "3 - DRI image") then + pref_text = "dri3_" + elseif (self.value == "1 - DFF image") then + pref_text = "dff1_" + elseif (self.value == "2 - DFF image") then + pref_text = "dff2_" + elseif (self.value == "3 - DFF image") then + pref_text = "dff3_" + elseif (self.value == "free preset") then + pref_text = "free_" + end + + if string.match(pref_text,"^dri")~=nil then + chkbtn_hard_masks.sensitive=false + chkbtn_hard_masks.value=false + sldr_contrast_weight.sensitive=true + elseif string.match(pref_text,"^dff")~=nil then + chkbtn_hard_masks.sensitive=false + chkbtn_hard_masks.value=true + sldr_contrast_weight.sensitive=false + else + chkbtn_hard_masks.sensitive=true + chkbtn_hard_masks.value=false + sldr_contrast_weight.sensitive=true + end + + chkbtn_hard_masks.value=dt.preferences.read("enfuse_pro", pref_text.."hard_masks", "bool") + chkbtn_save_masks.value=dt.preferences.read("enfuse_pro", pref_text.."save_masks", "bool") + cmbx_contrast_window_size.value=dt.preferences.read("enfuse_pro", pref_text.."contrast_window_size", "integer") + cmbx_contrast_edge_scale.value=dt.preferences.read("enfuse_pro", pref_text.."contrast_edge_scale", "integer") + cmbx_contrast_min_curvature.value=dt.preferences.read("enfuse_pro", pref_text.."contrast_min_curvature", "integer") + sldr_exposure_weight.value=dt.preferences.read("enfuse_pro", pref_text.."exposure_weight", "float") + sldr_saturation_weight.value=dt.preferences.read("enfuse_pro", pref_text.."saturation_weight", "float") + sldr_contrast_weight.value=dt.preferences.read("enfuse_pro", pref_text.."contrast_weight", "float") + sldr_exposure_optimum_weight.value=dt.preferences.read("enfuse_pro", pref_text.."exposure_optimum_weight", "float") + sldr_exposure_width_weight.value=dt.preferences.read("enfuse_pro", pref_text.."exposure_width_weight", "float") + + end, + "1 - DRI image", "2 - DRI image","3 - DRI image","1 - DFF image", "2 - DFF image","3 - DFF image","free preset", + + reset_callback = function(self_type) + cmbx_fusion_type.value = dt.preferences.read("enfuse_pro", "def_fusion_type", "integer") + end +} +entry_tag = dt.new_widget("entry"){ + tooltip = "Additional tags to be added on import. Seperate with commas, all spaces will be removed", + text = pref_addtags, + placeholder = "Enter tags, seperated by commas", + editable = true +} +local widget = dt.new_widget("box") { + orientation = "vertical", + label_align_options, + chkbtn_radial_distortion, + chkbtn_optimize_field, + chkbtn_optimize_image_center, + chkbtn_auto_crop, + chkbtn_distortion, + cmbx_grid_size, + cmbx_control_points, + cmbx_control_points_remove, + cmbx_correlation, + separator1, + separator1b, + label_enfuse_options, + cmbx_fusion_type, + chkbtn_image_variations, + sldr_exposure_weight, + sldr_saturation_weight, + sldr_contrast_weight, + sldr_exposure_optimum_weight, + sldr_exposure_width_weight, + chkbtn_hard_masks, + chkbtn_save_masks, + cmbx_contrast_edge_scale, + cmbx_contrast_min_curvature, + cmbx_contrast_window_size, + button_save_preset, + button_load_preset, + separator2, + separator2b, + label_output_format, + cmbx_output_format, + label_path, + file_chooser_button_path, + chkbtn_source_location, + cmbx_existing_file, + cmbx_style, + chkbtn_cpytags, + entry_tag, +} + +-- FUNCTION -- +local function GetFileName(full_path) + --[[Parses a full path (path/filename_identifier.extension) into individual parts + Input: Folder1/Folder2/Folder3/Img_0001.CR2 + + Returns: + path: Folder1/Folder2/Folder3/ + filename: Img_0001 + identifier: 0001 + extension: .CR2 + + EX: + path_1, file_1, id_1, ext_1 = GetFileName(full_path_1) + ]] + local path = string.match(full_path, ".*[\\/]") + local filename = string.gsub(string.match(full_path, "[%w-_]*%.") , "%." , "" ) + local identifier = string.match(filename, "%d*$") + local extension = string.match(full_path, "%.%w*") + return path, filename, identifier, extension +end +local function truncate(x) + return x<0 and math.ceil(x) or math.floor(x) +end +local function replace_comma_to_dot(s) + return string.gsub(s, "%,", ".") +end +local function file_exists(name) + local f=io.open(""..name.."","r") + if f~=nil then + io.close(f) + return true + else + return false + end +end +local function remove_temp_files() + if dt.configuration.running_os == "windows" then + dt.print_log("Deleting temp files...") + dt.control.execute("del "..images_to_align) + dt.control.execute("del "..images_to_blend) + dt.print_log("Done deleting") + else + dt.print_log("Deleting temp files...") + dt.control.execute("rm "..images_to_align) + dt.control.execute("rm "..images_to_blend) + dt.print_log("Done deleting") + end + + --[[ + dt.print_error("rm "..images_to_align) + result_to_align_images=dt.control.execute("rm "..images_to_align) + dt.print_error("rm "..tmppath.."/aligned_*.tif") + result_aligned_images=dt.control.execute("rm "..tmppath.."/aligned_*.tif") + ]] +end +local function build_execute_command(cmd, args, file_list) + local result = false + + if dt.configuration.running_os == "macos" then + cmd = string.gsub(cmd, "open", "") + cmd = string.gsub(cmd, "-W", "") + cmd = string.gsub(cmd, "-a", "") + -- result = cmd.." "..file_list.." "..args + --else + -- result = cmd..""..args.." "..file_list + end + result = cmd.." "..args.." "..file_list + return result +end +function copy_exif() + exiftool_path = string.gsub(exiftool_path, "open", "") + exiftool_path = string.gsub(exiftool_path, "-W", "") + exiftool_path = string.gsub(exiftool_path, "-a", "") + exifStartCommand = exiftool_path.." -TagsFromFile "..source_file.." -exif:all --subifd:all -overwrite_original "..path_with_filename + dt.print_log("EXIFTool Start Command: "..exifStartCommand) + resultexif=dt.control.execute(exifStartCommand) + if (resultexif == 0) then + dt.print_log("EXIFTool copy successful") + dt.print("Copied EXIF data") + else + dt.print(_('ERROR: exiftool doesn\'t work. for more informations see terminal output')) + dt.print_error("exif copy failed") + end +end +function align_images() + dt.print(_('aligning images')) + + --Setup Align Image Stack Arguments-- + align_args = "" + if (chkbtn_radial_distortion.value) then align_args = align_args.." -d" end + if (chkbtn_optimize_field.value) then align_args = align_args.." -m" end + if (chkbtn_optimize_image_center.value) then align_args = align_args.." -i" end + if (chkbtn_auto_crop.value) then align_args = align_args.." -C" end + if (chkbtn_distortion.value) then align_args = align_args.." --distortion" end + align_args = align_args.." -g "..cmbx_grid_size.value + align_args = align_args.." -c "..cmbx_control_points.value + align_args = align_args.." -t "..cmbx_control_points_remove.value + align_args = align_args.." --corr="..cmbx_correlation.value + if (dt.preferences.read("module_enfuse_pro", "align_use_gpu", "bool")) then align_args = align_args.." --gpu" end + + align_args = align_args.." -a "..first_path.."aligned_ " + alignStartCommand = build_execute_command(AIS_path, align_args, images_to_align) + dt.print_log("Align Start Command: "..alignStartCommand) + resp = dt.control.execute(alignStartCommand) + dt.print_log("Completed Align") + return resp +end +function blend_images() + blend_args = "" + if from_preset then --load args from preset preferences + blend_args=blend_args.." --exposure-weight="..(replace_comma_to_dot(dt.preferences.read("enfuse_pro", preset_text.."_exposure_weight", "float"))) + blend_args=blend_args.." --saturation-weight="..(replace_comma_to_dot(dt.preferences.read("enfuse_pro", preset_text.."_saturation_weight", "float"))) + blend_args=blend_args.." --contrast-weight="..(replace_comma_to_dot(dt.preferences.read("enfuse_pro", preset_text.."_contrast_weight", "float"))) + blend_args=blend_args.." --exposure-optimum="..(replace_comma_to_dot(dt.preferences.read("enfuse_pro", preset_text.."_exposure_optimum_weight", "float"))) + blend_args=blend_args.." --exposure-width="..(replace_comma_to_dot(dt.preferences.read("enfuse_pro", preset_text.."_exposure_width_weight", "float"))) + if (chkbtn_hard_masks.value) then blend_args=blend_args.."--hard-mask" end + if (chkbtn_save_masks.value) then blend_args=blend_args.."--save-masks" end + blend_args=blend_args.." --contrast-window-size="..dt.preferences.read("enfuse_pro", preset_text.."_contrast_window_size", "integer") + blend_args=blend_args.." --contrast-edge-scale="..dt.preferences.read("enfuse_pro", preset_text.."_contrast_edge_scale", "integer") + blend_args=blend_args.." --contrast-min-curvature="..dt.preferences.read("enfuse_pro", preset_text.."_contrast_min_curvature", "integer") + blend_args=blend_args.." --depth="..dt.preferences.read("module_enfuse_pro", "image_color_depth", "enum") + else --load args from GUI values + blend_args = blend_args.." --exposure-weight="..(replace_comma_to_dot(sldr_exposure_weight.value)) + blend_args = blend_args.." --saturation-weight="..(replace_comma_to_dot(sldr_saturation_weight.value)) + blend_args = blend_args.." --contrast-weight="..(replace_comma_to_dot(sldr_contrast_weight.value)) + blend_args = blend_args.." --exposure-optimum="..(replace_comma_to_dot(sldr_exposure_optimum_weight.value)) + blend_args = blend_args.." --exposure-width="..(replace_comma_to_dot(sldr_exposure_width_weight.value)) + if (chkbtn_hard_masks.value) then blend_args = blend_args.." --hard-mask" end + if (chkbtn_save_masks.value) then blend_args = blend_args.." --save-masks" end + blend_args = blend_args.." --contrast-window-size="..cmbx_contrast_window_size.value + blend_args = blend_args.." --contrast-edge-scale="..cmbx_contrast_edge_scale.value + blend_args = blend_args.." --contrast-min-curvature="..cmbx_contrast_min_curvature.value + blend_args = blend_args.." --depth="..dt.preferences.read("module_enfuse_pro", "image_color_depth", "enum") + end + + --set output format per GUI selection + if (cmbx_output_format.value == "TIFF") then + cmd_suffix_output_format="tif" + blend_args = blend_args.." --compression="..dt.preferences.read("module_enfuse_pro", "compression_tiff", "enum") + elseif (cmbx_output_format.value == "JPEG") then + cmd_suffix_output_format="jpg" + blend_args = blend_args.." --compression="..truncate(dt.preferences.read("module_enfuse_pro", "compression_jpeg", "integer")) + elseif (cmbx_output_format.value == "PNG") then + cmd_suffix_output_format="png" + elseif (cmbx_output_format.value == "PNM") then + cmd_suffix_output_format="pnm" + elseif (cmbx_output_format.value == "PBM") then + cmd_suffix_output_format="pbm" + elseif (cmbx_output_format.value == "PPM") then + cmd_suffix_output_format="ppm" + end + + --Set output path and add filename + if (chkbtn_source_location.value) then + cmd_output_path = source_path + else + cmd_output_path=file_chooser_button_path.value --FUTURE FEATURE: add gui option for "same as source images" + end + path_with_filename = cmd_output_path..os_path_seperator..first_filename.."-"..last_id.."."..cmd_suffix_output_format + + --Create unique name with index if GUI selection create unique name (don't overwrite), also do this if user selected to make variants from presets + if (cmbx_existing_file.selected == 1) or (from_preset) then + cmd_output_image_index=0 + while (file_exists(path_with_filename)) do + cmd_output_image_index = cmd_output_image_index+1 + if cmd_output_image_index <= 9 then + outputindex="0"..tostring(cmd_output_image_index) + else + outputindex=tostring(cmd_output_image_index) + end + path_with_filename = cmd_output_path..os_path_seperator..first_filename.."-"..last_id.."-"..outputindex.."."..cmd_suffix_output_format + end + end + cmd_output_image = " --output="..path_with_filename + blend_args = blend_args..cmd_output_image + + --images_to_blend = first_path.."aligned_*.tif" + images_to_blend = "" + for j=0, counted_images-1 do + if j < 10 then + id = "000"..tostring(j) + else + id = "00"..tostring(j) + end + images_to_blend = images_to_blend..first_path.."aligned_"..id..".tif " + end + + BlendStartCommand=build_execute_command(enfuse_path, blend_args, images_to_blend) + + dt.print_log("Blend Start Command: "..BlendStartCommand) + resultBlend=dt.control.execute(BlendStartCommand) + dt.print_log("Completed Blend") + + return resultBlend, path_with_filename +end +local function show_status(storage, image, format, filename, --Store: Called on each exported image + number, total, high_quality, extra_data) + dt.print(_('export TIFF for image fusion ')..tostring(truncate(number)).." / "..tostring(truncate(total))) +end +function create_image_fusion(storage, image_table, extra_data) --Finalize: Called once when all images are done exporting +--Create Images String-- + images_to_align = "" + images_to_blend = "" + counted_images=0 + first_id = "999999999999999999999999" + last_id = "0" + for source_image,image_path in pairs(image_table) do + counted_images=counted_images+1 + images_to_align = images_to_align..image_path.." " + curr_path, curr_filename, curr_id, curr_ext = GetFileName(image_path) + if (curr_id < first_id) then + first_path = curr_path + first_filename = curr_filename + first_id = curr_id + first_ext = curr_ext + dt_source_image = source_image + end + if (curr_id > last_id) then + last_path = curr_path + last_filename = curr_filename + last_id = curr_id + last_ext = curr_ext + end + source_path = source_image.path + source_file = source_image.path..os_path_seperator..source_image.filename + end + +--Check if at least 2 images selected-- + if (counted_images<=1) then + dt.print(_('ERROR: not enough pictures selected. please select two or more images\nfrom the same object, but with different camera settings.')) + dt.print_error("Not enough pictures selected") + remove_temp_files() + return + end + +--Ensure Required Software is Installed-- + df.set_executable_path_preference("align_image_stack", dt.preferences.read("module_enfuse_pro", "ais_path", "string")) + dt.print_log("Executable Path Preference: "..df.get_executable_path_preference("align_image_stack")) + AIS_path = df.check_if_bin_exists("align_image_stack") + if not AIS_path then + dt.print_error("align image stack not found") + dt.print("ERROR - align image stack not found") + remove_temp_files() + return + end + + df.set_executable_path_preference("enfuse", dt.preferences.read("module_enfuse_pro", "enfuse_path", "string")) + dt.print_log("Executable Path Preference: "..df.get_executable_path_preference("enfuse")) + enfuse_path = df.check_if_bin_exists("enfuse") + if not enfuse_path then + dt.print_error("enfuse not found") + dt.print("ERROR - enfuse not found") + remove_temp_files() + return + end + + df.set_executable_path_preference("exiftool", dt.preferences.read("module_enfuse_pro", "exiftool_path", "string")) + dt.print_log("Executable Path Preference: "..df.get_executable_path_preference("exiftool")) + exiftool_path = df.check_if_bin_exists("exiftool") + if not exiftool_path then + dt.print_error("exiftool not found") + dt.print("ERROR - exiftool not found") + remove_temp_files() + return + end + +--Ensure proper version of Enfuse installed-- + --[[ + enfuseVersionStartCommand='enfuse --version | grep "enfuse 4.2"' + enfuse_version=dt.control.execute(enfuseVersionStartCommand) + if (enfuse_version ~= 0) then + dt.print(_('ERROR: wrong enfuse version found. the plugin works only with enfuse 4.2! please install enfuse version 4.2')) + return + end]] + +--Check that output path selected + cmd_output_path = file_chooser_button_path.value + if (cmd_output_path == nil) and not(chkbtn_source_location.value) then + dt.print(_('ERROR: no target directory selected')) + remove_temp_files() + return + end + + dt.print_log("Starting Image Fusion") + job = dt.gui.create_job(_('Creating DRI/DFF image'), true, stop_selection) + + percent_step = .33 + if (chkbtn_image_variations.value) then percent_step = .2 end + job.percent = job.percent + percent_step + +--Align Images-- + resultalign = align_images() + if (resultalign ~= 0) then --Aling Image Stack Failed-- + dt.print(_('ERROR: align_image_stack doesn\'t work. For more information see terminal output')) + dt.print_error("Align Image Stack Failed") + remove_temp_files() + job.valid = false + return + end + dt.print(_('aligning complete')) + job.percent = job.percent + percent_step + +--Blend Images-- + from_preset = false + iterations = 1 + pref_text = "" + if (chkbtn_image_variations.value) then + iterations = 3 + from_preset = true + if string.match(cmbx_fusion_type.value, "DRI") then + pref_text = "dri" + elseif string.match(cmbx_fusion_type.value, "DFF") then + pref_text = "dff" + else --if "variants" selected, but not using DRI or DFF preset then cannot create variants + dt.print("Error, must select a DRI or DFF preset when starting a fustion with variants") + dt.print_error("DRI or DFF preset not selected when variants option was checked") + remove_temp_files() + job.valid = false + return + end + end + + for j = 1, iterations do + if (from_preset) then + preset_text=pref_text..j + else + preset_text="" + end + resultBlend, blended_image = blend_images() --Check here to ensure enfuse worked properly + if resultBlend ~= 0 then + dt.print(_('ERROR: enfuse didn\'t work. For more information see terminal output')) + dt.print_error("Enfuse failed") + remove_temp_files() + job.valid = false + return + end + --Copy EXIF Data (IF)-- + if (dt.preferences.read("module_enfuse_pro", "exiftool_copy_tags", "bool")) then copy_exif() end + --Auto-Import-- + if (dt.preferences.read("module_enfuse_pro", "add_image_to_db", "bool")) then + local imported = dt.database.import(path_with_filename) + --Apply Selected Style (IF)-- + if cmbx_style.selected > 1 then + set_style = styles[cmbx_style.selected - 1] + dt.styles.apply(set_style , imported) + end + --Copy Tags (IF)-- + if (chkbtn_cpytags.value) then + all_tags = dt.tags.get_tags(dt_source_image) + for _,tag in pairs(all_tags) do + if string.match(tag.name, 'darktable|') == nil then + dt.tags.attach(tag, imported) + end + end + end + --Apply Entered Tags (IF)-- + set_tag = entry_tag.text + if set_tag ~= nil then + for tag in string.gmatch(set_tag, '[^,]+') do + tag = string.gsub(tag, " ", "") + tag = dt.tags.create(tag) + dt.tags.attach(tag, imported) + end + end + end + job.percent = job.percent + percent_step + end + + --Copy EXIF Data (IF)-- + + remove_temp_files() + dt.print("Image fusion process complete") + dt.print_log("Image fusion process complete") + job.valid = false +end +local function support_format(storage, format) --Supported: Check to make sure image type is supported by darktable + fmt = string.lower(format.name) + if string.match(fmt,"tiff") == nil then + return false + else + return true + end +end + +-- REGISTER -- +dt.register_storage("module_enfuse_pro", _('DRI or DFF image'), show_status, create_image_fusion, support_format, nil, widget) + +-- PREFERENCES -- +entry_widget_style = dt.new_widget("entry"){ + tooltip = "Enter the style name exactly as it is", + text = nil, + placeholder = "Enter Style name", + editable = true +} +dt.preferences.register("module_enfuse_pro", "style", -- name + "string", -- type + 'enfuse_pro: Defualt Style', -- label + 'Changes DEFAULT entry in the Style option. Requires restart to take effect.', -- tooltip + "", -- default + entry_widget_style +) +entry_widget_tags = dt.new_widget("entry"){ + tooltip = "Seperate with commas, all spaces will be removed", + text = nil, + placeholder = "Enter default tags", + editable = true +} +dt.preferences.register("module_enfuse_pro", "add_tags", -- name + "string", -- type + 'enfuse_pro: Defualt additional tags', -- label + 'Changes DEFAULT entry in the additional tags option. Requires restart to take effect.', -- tooltip + "", -- default + entry_widget_tags +) +dt.preferences.register("module_enfuse_pro", "copy_tags", -- name + "bool", -- type + 'enfuse_pro: Copy tags from first image by default', -- label + 'Changes DEFAULT selection for Copy Tags, Requires restart to take effect.', -- tooltip + true -- default +) +dt.preferences.register("module_enfuse_pro", "exiftool_copy_tags", -- name + "bool", -- type + _('enfuse pro: copy exif data'), -- label + _('copy the exif tags from the first image to the target'), -- tooltip + true) -- default +dt.preferences.register("module_enfuse_pro", "add_image_to_db", -- name + "bool", -- type + _('enfuse pro: add fused image to database'), -- label + _('add the fused image to the darktable database'), -- tooltip + false) -- default +dt.preferences.register("module_enfuse_pro", "align_use_gpu", -- name + "bool", -- type + _('enfuse pro: use GPU for remaping'), -- label + _('set the GPU remapping for image align'), -- tooltip + false) +dt.preferences.register("module_enfuse_pro", "compression_jpeg", -- name + "integer", -- type + _('enfuse pro: JPEG compression'), -- label + _('set the compression for JPEG files'), -- tooltip + 98, -- default + 50, -- min + 100) -- max +dt.preferences.register("module_enfuse_pro", "compression_tiff", -- name + "enum", -- type + _('enfuse pro: TIFF compression'), -- label + _('set the compression type for tiff files'), -- tooltip + "LZW", -- default + "NONE", "DEFLATE","PACKBITS") -- va +dt.preferences.register("module_enfuse_pro", "image_color_depth", -- name + "enum", -- type + _('enfuse pro: image color depth (bit)'), -- label + _('set the output color depth'), -- tooltip + "16", -- default + "8","32","r32","r64") -- values + +--AIS bin location +AIS_path = df.get_executable_path_preference("align_image_stack") +if not AIS_path then + AIS_path = "" +end +AIS_path_widget = dt.new_widget("file_chooser_button"){ + title = "Select align_image_stack[.exe] file", + value = AIS_path, + is_directory = false, +} +dt.preferences.register("module_enfuse_pro", "ais_path", -- name + "file", -- type + 'enfuse_pro: Align Image Stack Location', -- label + 'Install location of align_image_stack. Requires restart to take effect.', -- tooltip + "align_image_stack", -- default + AIS_path_widget +) + +--enfuse bin location +enfuse_path = df.get_executable_path_preference("enfuse") +if not enfuse_path then + enfuse_path = "" +end +enfuse_path_widget = dt.new_widget("file_chooser_button"){ + title = "Select enfuse[.exe] file", + value = enfuse_path, + is_directory = false, +} +dt.preferences.register("module_enfuse_pro", "enfuse_path", -- name + "file", -- type + 'enfuse_pro: enfuse Location', -- label + 'Install location of enfuse. Requires restart to take effect.', -- tooltip + "enfuse", -- default + enfuse_path_widget +) + +--exiftool bin location +exiftool_path = df.get_executable_path_preference("exiftool") +if not exiftool_path then + exiftool_path = "" +end +exiftool_path_widget = dt.new_widget("file_chooser_button"){ + title = "Select exiftool[.exe] file", + value = exiftool_path, + is_directory = false, +} +dt.preferences.register("module_enfuse_pro", "exiftool_path", -- name + "file", -- type + 'enfuse_pro: exiftool Location', -- label + 'Install location of exiftool. Requires restart to take effect.', -- tooltip + "exiftool", -- default + exiftool_path_widget +) + From b5e79abf08ea0f19465e6c118e6b3a930daf39c6 Mon Sep 17 00:00:00 2001 From: BzKevin <36381472+BzKevin@users.noreply.github.com> Date: Sun, 1 Jul 2018 19:51:26 -0400 Subject: [PATCH 2/9] Delete HDRMerge.lua --- contrib/HDRMerge.lua | 396 ------------------------------------------- 1 file changed, 396 deletions(-) delete mode 100644 contrib/HDRMerge.lua diff --git a/contrib/HDRMerge.lua b/contrib/HDRMerge.lua deleted file mode 100644 index f8ea9d5..0000000 --- a/contrib/HDRMerge.lua +++ /dev/null @@ -1,396 +0,0 @@ ---[[ HDRMerge plugin for darktable - - copyright (c) 2018 Kevin Ertel - - darktable is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - darktable is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with darktable. If not, see . -]] - ---[[ Version 1.0.2 3/20/2018 - -This plugin adds the module "HDRMerge" to darktable's lighttable view - -****Dependencies**** -OS: Windows (tested), Linux (not verified), MacOS (not verified) -HDRMerge 4.5 or greater - -****How to use**** -Require this file from your luarc file, as with any other dt plug-in. -On initial run setup HDRMerge's install path via the settings > lua options dialog. Restart may be required. -Select a group of photos you desire to merge and press HDRMerge - -****Options**** -Bits Per Sample - Bit depth of the final image -Preview Size - Preview size of the built-in preview -Batch - Allows user to select multiple groups and HDRMerge will auto-group them based on time seperation "gap" -Gap - Time seperation between groupings when running in batch mode -Style - Style to be applied when image is auto-imported (Auto-import only supported in non-batch mode) -Copy Tags - Enable to copy tags from first file in selection -Additional Tags - Additional tags to be added, works with or without Copy Tags enabled. - -****Known Bugs / Deficiencies****: -CMD window pops up when run -Slider double-click sets to 31, not 3 -Removes spaces from tags (desired to only removed spaces at front and end) - -****Features for future releases**** - - -****Versions**** -Version 0.1 - Implemented via "Selected Images" -Version 0.2 - Implemented as it's own module - windows only -Version 0.3 - Improved cross-platform compatibility, improved performance ( switched from io.popen() to dt.control.execute() ) -Version 1.0 - Added: - Copy Tags Option - Additional Tags Option - User Defined Default Style - Progress Bar - 1.0.1 - Added check for at least 2 images selected - Fixed issue with status bar not disappearing when HDRmerge not installed or not enough images selected - 1.0.2 - Changes for grabbing executable path and setting preference (to imporve cross-platform support) - Changes to building the run_cmd (to improve cross-platform support) -]] - -local dt = require "darktable" -local df = require "lib/dtutils.file" -require "official/yield" - ---Detect OS and modify accordingly-- -op_sys = dt.configuration.running_os -if op_sys == "windows" then - os_path_seperator = "\\" -else - os_path_seperator = "/" -end - --- READ PREFERENCES -- -pref_bps = dt.preferences.read("module_HDRMerge", "bits_per_sample", "enum") -if pref_bps == "32" then - pref_bps_enum = 3 -elseif pref_bps == "24" then - pref_bps_enum = 2 -else - pref_bps_enum = 1 -end -pref_size = dt.preferences.read("module_HDRMerge", "preview_size", "enum") -if pref_size == "none" then - pref_size_enum = 3 -elseif pref_size == "full" then - pref_size_enum = 2 -else - pref_size_enum = 1 -end -pref_cpytags = dt.preferences.read("module_HDRMerge", "copy_tags", "bool") -pref_addtags = dt.preferences.read("module_HDRMerge", "add_tags", "string") -pref_style = dt.preferences.read("module_HDRMerge", "style", "string") - ---Detect User Styles-- -styles = dt.styles -styles_count = 1 -- "none" = 1 -for _,i in pairs(dt.styles) do - if type(i) == "userdata" then styles_count = styles_count + 1 end -end - -local function build_execute_command(cmd, args, file_list) - local result = false - - if dt.configuration.running_os == "macos" then - cmd = string.gsub(cmd, "open", "") - cmd = string.gsub(cmd, "-W", "") - cmd = string.gsub(cmd, "-a", "") - -- result = cmd.." "..file_list.." "..args - --else - -- result = cmd..""..args.." "..file_list - end - result = cmd.." "..args.." "..file_list - return result -end - --- FUNCTION -- -local function HDRMerge() - dt.print_log("Running HDRMerge") - dt.print("Running HDRMerge") - gui_job = dt.gui.create_job("HDRMerge", 1) - df.set_executable_path_preference("hdrmerge", dt.preferences.read("module_HDRMerge", "bin_path", "string")) - dt.print_log("Executable Path Preference: "..df.get_executable_path_preference("hdrmerge")) - - --Inits-- - local images = dt.gui.selection() - local images_to_merge = "" - local image_path = "" - local curr_image = "" - local first_image = "" - local last_image = "" - local output_file = "" - local num_images = 0 - - --Read Settings-- - set_bps = HDRMerge_cmbx_bps.value - set_size = HDRMerge_cmbx_size.value - set_batch = HDRMerge_chkbtn_batch.value - set_gap = HDRMerge_sldr_gap.value - set_cpytags = HDRMerge_chkbtn_cpytags.value - set_tag = HDRMerge_entry_tag.text - - --Create Images String-- - for _,image in pairs(images) do - curr_image = image.path..os_path_seperator..image.filename - images_to_merge = images_to_merge..curr_image.." " - last_image = string.gsub(string.match(image.filename,'^.*%.'), "%." , "") - image_path = image.path - if _ == 1 then first_image = last_image end - num_images = num_images + 1 - end - output_file = image_path..os_path_seperator..first_image.."-"..string.match(last_image, '%d*$')..".dng" - - --Check if at least 2 images selected-- - if num_images < 2 then - dt.print_error("Less than 2 images selected") - dt.print("ERROR - please select at least 2 images") - gui_job.valid = false - return - end - - --Check if HDRMerge is installed-- - local HDRMerge_Path = df.check_if_bin_exists("hdrmerge") - if not HDRMerge_Path then - dt.print_error("HDRMerge not found") - dt.print("ERROR - HDRMerge not found") - gui_job.valid = false - return - end - - --Create Command Args-- - cmd_args = "-b "..set_bps.." -p "..set_size - if (set_batch) then - cmd_args = cmd_args.." -B -g "..set_gap.." -a" - else --add ability to launch with gui here by omiting -o arg - cmd_args = cmd_args.." -o "..output_file - end - - gui_job.percent = .1 - - --Execute with Run Command-- - run_cmd = build_execute_command(HDRMerge_Path, cmd_args, images_to_merge) - dt.print_log("run_cmd = "..run_cmd) - resp = dt.control.execute(run_cmd) - - gui_job.percent = .9 - - if resp == 0 and not(set_batch) then - --Import Image-- - imported = dt.database.import(output_file) - - --Apply Selected Style (IF)-- - if HDRMerge_cmbx_style.selected > 1 then - set_style = styles[HDRMerge_cmbx_style.selected - 1] - dt.styles.apply(set_style , imported) - end - - --Copy Tags (IF)-- - if (set_cpytags) then - all_tags = dt.tags.get_tags(images[1]) - for _,tag in pairs(all_tags) do - if string.match(tag.name, 'darktable|') == nil then - dt.tags.attach(tag, imported) - end - end - end - - --Apply Entered Tags (IF)-- - if set_tag ~= nil then - for tag in string.gmatch(set_tag, '[^,]+') do - tag = string.gsub(tag, " ", "") - tag = dt.tags.create(tag) - dt.tags.attach(tag, imported) - end - end - - dt.print_log("Merge Successful") - dt.print("Merge Successful") - elseif resp == 0 then - dt.print_log("Merge Successful") - dt.print("Merge Successful") - else - dt.print_error("Merge Not Successful") - dt.print("ERROR - Merge Not Successful") - end - gui_job.percent = 1 - gui_job.valid = false -end - --- GUI -- -local executables = {"hdrmerge"} -if dt.configuration.running_os ~= "linux" then - path_widget = df.executable_path_widget(executables) -end - -HDRMerge_lbl_base= dt.new_widget("section_label"){ - label = "Base Options", - } -HDRMerge_cmbx_bps = dt.new_widget("combobox"){ - label = 'Bits Per Sample', - tooltip = 'Output file\'s bit depth \ndefault: '..pref_bps, - value = pref_bps_enum, - "16", "24", "32", - } -HDRMerge_cmbx_size = dt.new_widget("combobox"){ - label = 'Preview Size', - tooltip = 'Output file\'s built-in preview size \ndefault: '..pref_size, - value = pref_size_enum, - "half", "full", "none", - } -HDRMerge_lbl_batch= dt.new_widget("section_label"){ - label = "Batch Options", - } -HDRMerge_chkbtn_batch = dt.new_widget("check_button"){ - label = ' Batch Mode', - value = false, --pref_batch, - tooltip ='Operate in batch mode. When operating in batch mode output files will NOT be auto-imported \ndefault: (false).', - } -HDRMerge_sldr_gap = dt.new_widget("slider"){ - label = 'Batch Gap [sec.]', - tooltip = 'Gap, in seconds, between batch mode groups \ndefault: (3).', - soft_min = 1, - soft_max = 60, - hard_min = 1, - hard_max = 60, - step = 1, - digits = 0, - value = 3, --pref_gap, - } -HDRMerge_lbl_out= dt.new_widget("section_label"){ - label = "Auto-import Options", - } -HDRMerge_cmbx_style = dt.new_widget("combobox"){ - label = "Apply Style on Import", - tooltip = "Apply selected style on auto-import to newly created HDRMerge DNG\nDoes not apply when in Batch mode.", - value = 1, - "none", - } -pref_style_enum = 1 - for k=1, (styles_count-1) do - HDRMerge_cmbx_style[k+1] = styles[k].name - if styles[k].name == pref_style then pref_style_enum = k+1 end -end -HDRMerge_cmbx_style.value = pref_style_enum -HDRMerge_chkbtn_cpytags = dt.new_widget("check_button"){ - label = ' Copy Tags', - value = pref_cpytags, - tooltip ='Copy tags from first image. When operating in batch mode this will NOT be performed. \ndefault: (true).', - } -HDRMerge_lbl_tags= dt.new_widget("label"){ - label = 'Additional Tags', - } -HDRMerge_entry_tag = dt.new_widget("entry"){ - tooltip = "Additional tags to be added on import. Seperate with commas, all spaces will be removed", - text = pref_addtags, - placeholder = "Enter tags, seperated by commas", - editable = true -} -HDRMerge_btn_run = dt.new_widget("button"){ - label = "Run HDRMerge", - tooltip = "Runs HDRMerge on selected images, with selected settings", - clicked_callback = function() HDRMerge() end - } -HDRMerge_lbl_note= dt.new_widget("label"){ - label = 'Defaults can be adjusted under:\n"Settings > lua options"', - } -dt.register_lib( - "HDRMerge_Lib", -- Module name - "HDRMerge", -- name - true, -- expandable - false, -- resetable - {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 99}}, -- containers - dt.new_widget("box"){ - orientation = "vertical", - HDRMerge_lbl_base, - HDRMerge_cmbx_bps, - HDRMerge_cmbx_size, - HDRMerge_lbl_batch, - HDRMerge_chkbtn_batch, - HDRMerge_sldr_gap, - HDRMerge_lbl_out, - HDRMerge_cmbx_style, - HDRMerge_chkbtn_cpytags, - HDRMerge_lbl_tags, - HDRMerge_entry_tag, - HDRMerge_btn_run, - HDRMerge_lbl_note - } -) - --- PREFERENCES -- -entry_widget_tags = dt.new_widget("entry"){ - tooltip = "Seperate with commas, all spaces will be removed", - text = nil, - placeholder = "Enter default tags", - editable = true -} -dt.preferences.register("module_HDRMerge", "add_tags", -- name - "string", -- type - 'HDRMerge: Defualt additional tags', -- label - 'Changes DEFAULT entry in the additional tags option. Requires restart to take effect.', -- tooltip - "", -- default - entry_widget_tags -) -entry_widget_style = dt.new_widget("entry"){ - tooltip = "Enter the style name exactly as it is", - text = nil, - placeholder = "Enter Style name", - editable = true -} -dt.preferences.register("module_HDRMerge", "style", -- name - "string", -- type - 'HDRMerge: Defualt Style', -- label - 'Changes DEFAULT entry in the Style option. Requires restart to take effect.', -- tooltip - "", -- default - entry_widget_style -) -dt.preferences.register("module_HDRMerge", "copy_tags", -- name - "bool", -- type - 'HDRMerge: Copy tags from first image by default', -- label - 'Changes DEFAULT selection for Copy Tags, Requires restart to take effect.', -- tooltip - true -- default -) -dt.preferences.register("module_HDRMerge", "preview_size", -- name - "enum", -- type - 'HDRMerge: Default DNG Preview Size', -- label - "Change the DEFAULT preview size. Requires restart to take effect.", -- tooltip - "half", -- default - "full", "none" --values -) -dt.preferences.register("module_HDRMerge", "bits_per_sample", -- name - "enum", -- type - 'HDRMerge: Default Bits Per Sample', -- label - 'Change the DEFAULT bit depth. Requires restart to take effect.', -- tooltip - "16", -- default - "24","32" --value -) -executable = "hdrmerge" -bin_path = df.get_executable_path_preference(executable) -if not bin_path then - bin_path = "" -end -path_widget = dt.new_widget("file_chooser_button"){ - title = "Select HDRMerge[.exe] file", - value = bin_path, - is_directory = false, -} -dt.preferences.register("module_HDRMerge", "bin_path", -- name - "file", -- type - 'HDRMerge: Binary Location', -- label - 'Install location of HDRMerge[.exe]. Requires restart to take effect.', -- tooltip - "hdrmerge", -- default - path_widget -) From 67232094c9272483a3b917011de362f8f9755edb Mon Sep 17 00:00:00 2001 From: BzKevin <36381472+BzKevin@users.noreply.github.com> Date: Sun, 1 Jul 2018 19:51:39 -0400 Subject: [PATCH 3/9] Delete OpenInPS.lua --- contrib/OpenInPS.lua | 199 ------------------------------------------- 1 file changed, 199 deletions(-) delete mode 100644 contrib/OpenInPS.lua diff --git a/contrib/OpenInPS.lua b/contrib/OpenInPS.lua deleted file mode 100644 index faca5de..0000000 --- a/contrib/OpenInPS.lua +++ /dev/null @@ -1,199 +0,0 @@ ---[[ OpenInPS plugin for darktable - - copyright (c) 2018 Kevin Ertel - - darktable is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - darktable is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with darktable. If not, see . -]] - ---[[ Version 1.1.0 6/30/2018 - -This plugin adds the module "OpenInPS" to darktable's lighttable view - -****Dependencies**** -OS: Windows (tested), Linux (not verified), MacOS (not verified) -Photoshop - -****How to use**** -Require this file from your luarc file, as with any other dt plug-in. -On initial run, setup the Photoshop executable path via the settings > lua options dialog. Restart may be required. -Select the photo(s) you wish to open in Photoshop and press Open from the Open in Photoshop box - RAW files will open in ACR inside Photoshop - JPG, Tif, etc will open as a new file inside PS - Since this is opening the file, not exporting and then opening, it will NOT have any of your Darktable edits -Select the photo(s) you wish to export to Photoshop and select the desired destination folder, set the rest of - the export settings as with any other export from darktable. Since this is "exporting" file will be converted - from RAW to your chosen format and darktable edits WILL carry over. Note the files created by this will NOT be - automatically deleted or cleaned up, ever. -]] - -local dt = require "darktable" -local df = require "lib/dtutils.file" -require "official/yield" - ---Detect OS and modify accordingly-- -op_sys = dt.configuration.running_os -if op_sys == "windows" then - os_path_seperator = "\\" -else - os_path_seperator = "/" -end - --- READ PREFERENCES -- -df.set_executable_path_preference("openinps", dt.preferences.read("module_OpenInPS", "bin_path", "string")) -dt.print_log("OpenInPS - Executable Path Preference: "..df.get_executable_path_preference("openinps")) -last_used_location = dt.preferences.read("module_OpenInPS", "export_path", "string") - -local function build_execute_command(cmd, args, file_list) - local result = false - - if dt.configuration.running_os == "macos" then - cmd = string.gsub(cmd, "open", "", 1) - cmd = string.gsub(cmd, "-W", "", 1) - cmd = string.gsub(cmd, "-a", "", 1) - end - result = cmd.." "..args.." "..file_list - return result -end - --- FUNCTION -- -local function truncate(x) - return x<0 and math.ceil(x) or math.floor(x) -end -local function show_status(storage, image, format, filename, --Store: Called on each exported image - number, total, high_quality, extra_data) - dt.print('Export to Photoshop: '..tostring(truncate(number)).." / "..tostring(truncate(total))) -end - -local function OpenInPS() --OPEN in Photoshop - dt.print_log("Opening in Photoshop") - dt.print("Opening In Photoshop") - - local PS_Path = df.check_if_bin_exists("openinps") - if not PS_Path then - dt.print_error("Photoshop not found") - dt.print("ERROR - Photoshop not found") - return - end - - --Inits-- - local images = dt.gui.selection() - local curr_image = "" - local images_to_open = "" - - for _,image in pairs(images) do - curr_image = image.path..os_path_seperator..image.filename - images_to_open = images_to_open.." "..curr_image - end - run_cmd = build_execute_command(PS_Path, "" , images_to_open) - dt.print_log("OpenInPS run_cmd = "..run_cmd) - dt.print("Opening in Photoshop") - resp = dt.control.execute(run_cmd) -end -local function ExportToPS(storage, image_table, extra_data) --EXPORT to Photoshop - dt.print_log("Exporting to Photoshop") - dt.print("Exporting to Photoshop") - - local PS_Path = df.check_if_bin_exists("openinps") - if not PS_Path then - dt.print_error("Photoshop not found") - dt.print("ERROR - Photoshop not found") - return - end - - --Inits-- - local image_path = "" - local images_to_open = "" - local chooser_path = file_chooser_button_path.value - dt.preferences.write("module_OpenInPS", "export_path", "string", chooser_path) - - - for image,temp_path in pairs(image_table) do - dt.print_log(image.filename) - new_path = chooser_path..os_path_seperator..image.filename - while df.check_if_file_exists(new_path) do - new_path = df.filename_increment(new_path) - -- limit to 99 more exports of the original export - if string.match(df.get_basename(new_path), "_(d-)$") == "99" then - break - end - end - result = df.file_move(temp_path, new_path) - images_to_open = images_to_open..new_path.." " - end - dt.print_log("Result: "..tostring(result)) - run_cmd = build_execute_command(PS_Path, "" , images_to_open) - dt.print_log("ExportToPS run_cmd = "..run_cmd) - dt.print("Opening in Photoshop") - resp = dt.control.execute(run_cmd) -end - --- GUI -- -local executables = {"openinps"} -if dt.configuration.running_os ~= "linux" then - path_widget = df.executable_path_widget(executables) -end -OpenInPS_btn_run = dt.new_widget("button"){ - label = "Open", - tooltip = "Opens selected image in Photoshop", - clicked_callback = function() OpenInPS() end - } -dt.register_lib( --OpenInPS - "OpenInPS_Lib", -- Module name - "Open In Photoshop", -- name - true, -- expandable - false, -- resetable - {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 99}}, -- containers - dt.new_widget("box"){ - orientation = "vertical", - OpenInPS_btn_run - } -) - -file_chooser_button_path = dt.new_widget("file_chooser_button"){ - title = 'Select export path', -- The title of the window when choosing a file - value = last_used_location, - is_directory = true, -- True if the file chooser button only allows directories to be selected - tooltip ='select the target directory for the image(s)', -} -dt.register_storage( - "ExportToPS_Storage", --Module name - "Export to Photoshop", --Name - show_status, --store: called once per exported image - ExportToPS, --finalize: - nil, --supported: - nil, --initialize: - dt.new_widget("box"){ - orientation = "vertical", - file_chooser_button_path - } - ) - --- PREFERENCES -- -executable = "hdrmerge" -bin_path = df.get_executable_path_preference(executable) -if not bin_path then - bin_path = "" -end -path_widget = dt.new_widget("file_chooser_button"){ - title = "Select Photoshop executable", - value = bin_path, - is_directory = false, -} -dt.preferences.register("module_OpenInPS", "bin_path", -- name - "file", -- type - 'OpenInPS: Photoshop exe location', -- label - 'Location of Photoshop executable. Requires restart to take effect.', -- tooltip - "Please Select", -- default - path_widget -) \ No newline at end of file From a867791165c56b2a4e34e12e1a01c667f81dc34e Mon Sep 17 00:00:00 2001 From: BzKevin <36381472+BzKevin@users.noreply.github.com> Date: Sun, 1 Jul 2018 19:52:47 -0400 Subject: [PATCH 4/9] Delete enfuse_pro_2.lua --- contrib/enfuse_pro_2.lua | 1051 -------------------------------------- 1 file changed, 1051 deletions(-) delete mode 100644 contrib/enfuse_pro_2.lua diff --git a/contrib/enfuse_pro_2.lua b/contrib/enfuse_pro_2.lua deleted file mode 100644 index 7349ac4..0000000 --- a/contrib/enfuse_pro_2.lua +++ /dev/null @@ -1,1051 +0,0 @@ ---[[ - Enfuse professional plugin for darktable 2.2.X and 2.4.X - - copyright (c) 2017, 2018 Holger Klemm (Original Linux-only version) - - darktable is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - darktable is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with darktable. If not, see . -]] - ---[[ Enfuse Pro 2 - cross-platform compatible -Modified by: Kevin Ertel - -ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT -* align_image_stack -* enfuse -* exiftool - -USAGE -* require this file from your main luarc config file. - -This plugin will add the new export modul "fusion to DRI or DFF image". -]] - -local dt = require "darktable" -local df = require "lib/dtutils.file" -local gettext = dt.gettext - --- works with LUA API version 4.0.0 and 5.0.0 -dt.configuration.check_version(...,{4,0,0},{5,0,0}) - --- Tell gettext where to find the .mo file translating messages for a particular domain -gettext.bindtextdomain("enfuse_pro",dt.configuration.config_dir.."/lua/") - -local function _(msgid) - return gettext.dgettext("enfuse_pro", msgid) -end - ---Detect User Styles-- -styles = dt.styles -styles_count = 1 -- "none" = 1 -for _,i in pairs(dt.styles) do - if type(i) == "userdata" then styles_count = styles_count + 1 end -end - --- INITS -- -pref_style = dt.preferences.read("module_enfuse_pro", "style", "string") -pref_cpytags = dt.preferences.read("module_enfuse_pro", "copy_tags", "bool") -pref_addtags = dt.preferences.read("module_enfuse_pro", "add_tags", "string") ---[[ -cmd_tmp_path="" -cmd_output_path="" -cmd_output_image="" -cmd_output_image_index = 0 -path_with_filename="" -homepath=os.getenv("Public") -tmppath=homepath.."/.local/tmp" -cmd_exif_copy_exif="" -cmd_suffix_output_format="" -alignStartCommand="" -enfuseStartCommand="" -exifStartCommand="" -outputindex = 0 -job = 0 -]] -if dt.configuration.running_os == "windows" then - os_path_seperator = "\\" -else - os_path_seperator = "/" -end - - --- align defaults ---dt.preferences.write("enfuse_pro", "initialized", "bool", false) -if not(dt.preferences.read("enfuse_pro", "initialized", "bool")) then - dt.preferences.write("enfuse_pro", "selected_fusion", "integer", 1) - dt.preferences.write("enfuse_pro", "def_radial_distortion", "bool", false) - dt.preferences.write("enfuse_pro", "def_optimize_field", "bool", false) - dt.preferences.write("enfuse_pro", "def_optimize_image_center", "bool", true) - dt.preferences.write("enfuse_pro", "def_auto_crop", "bool", true) - dt.preferences.write("enfuse_pro", "def_distortion", "bool", true) - dt.preferences.write("enfuse_pro", "def_grid_size", "integer", 5) - dt.preferences.write("enfuse_pro", "def_control_points", "integer", 8) - dt.preferences.write("enfuse_pro", "def_control_points_remove", "integer", 3) - dt.preferences.write("enfuse_pro", "def_correlation", "integer", 9) - - -- enfuse defaults - dt.preferences.write("enfuse_pro", "def_fusion_type", "integer", 1) - dt.preferences.write("enfuse_pro", "def_image_variants", "bool", false) - dt.preferences.write("enfuse_pro", "def_hard_masks", "bool", false) - dt.preferences.write("enfuse_pro", "def_save_masks", "bool", false) - dt.preferences.write("enfuse_pro", "def_contrast_window_size", "integer", 3) - dt.preferences.write("enfuse_pro", "def_contrast_edge_scale", "integer", 1) - dt.preferences.write("enfuse_pro", "def_contrast_min_curvature", "integer", 1) - dt.preferences.write("enfuse_pro", "def_exposure_weight", "float", 1.0) - dt.preferences.write("enfuse_pro", "def_saturation_weight", "float", 0.2) - dt.preferences.write("enfuse_pro", "def_contrast_weight", "float", 0.0) - dt.preferences.write("enfuse_pro", "def_exposure_optimum_weight", "float", 0.5) - dt.preferences.write("enfuse_pro", "def_exposure_width_weight", "float",0.2) - dt.preferences.write("enfuse_pro", "selected_overwrite", "integer",1) - dt.preferences.write("enfuse_pro", "sentitiv_overwrite", "bool",true) - - -- preset DRI 1 - temp_text = {"dri1_","dri2_","dri3_"} - for i,preset in pairs(temp_text) do - dt.preferences.write("enfuse_pro", preset.."hard_masks", "bool", false) - dt.preferences.write("enfuse_pro", preset.."save_masks", "bool", false) - dt.preferences.write("enfuse_pro", preset.."contrast_window_size", "integer", 3) - dt.preferences.write("enfuse_pro", preset.."contrast_edge_scale", "integer", 1) - dt.preferences.write("enfuse_pro", preset.."contrast_min_curvature", "integer", 1) - dt.preferences.write("enfuse_pro", preset.."exposure_weight", "float", 1.0) - dt.preferences.write("enfuse_pro", preset.."saturation_weight", "float", 0.2) - dt.preferences.write("enfuse_pro", preset.."contrast_weight", "float", 0.0) - dt.preferences.write("enfuse_pro", preset.."exposure_optimum_weight", "float", 0.5) - dt.preferences.write("enfuse_pro", preset.."exposure_width_weight", "float",0.2) - end - - -- preset DFF 1 - temp_text = {"dff1_","dff2_","dff3_"} - for i,preset in pairs(temp_text) do - dt.preferences.write("enfuse_pro", preset.."hard_masks", "bool", true) - dt.preferences.write("enfuse_pro", preset.."save_masks", "bool", false) - dt.preferences.write("enfuse_pro", preset.."contrast_window_size", "integer", 3) - dt.preferences.write("enfuse_pro", preset.."contrast_edge_scale", "integer", 1) - dt.preferences.write("enfuse_pro", preset.."contrast_min_curvature", "integer", 1) - dt.preferences.write("enfuse_pro", preset.."exposure_weight", "float", 0.0) - dt.preferences.write("enfuse_pro", preset.."saturation_weight", "float", 0.0) - dt.preferences.write("enfuse_pro", preset.."contrast_weight", "float", 1.0) - dt.preferences.write("enfuse_pro", preset.."exposure_optimum_weight", "float", 0.5) - dt.preferences.write("enfuse_pro", preset.."exposure_width_weight", "float",0.2) - end - - -- preset FREE - dt.preferences.write("enfuse_pro", "free_hard_masks", "bool", false) - dt.preferences.write("enfuse_pro", "free_save_masks", "bool", false) - dt.preferences.write("enfuse_pro", "free_contrast_window_size", "integer", 3) - dt.preferences.write("enfuse_pro", "free_contrast_edge_scale", "integer", 1) - dt.preferences.write("enfuse_pro", "free_contrast_min_curvature", "integer", 1) - dt.preferences.write("enfuse_pro", "free_exposure_weight", "float", 0.0) - dt.preferences.write("enfuse_pro", "free_saturation_weight", "float", 0.0) - dt.preferences.write("enfuse_pro", "free_contrast_weight", "float", 0.0) - dt.preferences.write("enfuse_pro", "free_exposure_optimum_weight", "float", 0.0) - dt.preferences.write("enfuse_pro", "free_exposure_width_weight", "float",0.0) - - -- output - dt.preferences.write("enfuse_pro", "selected_output_format", "integer", 1) - dt.preferences.write("enfuse_pro", "initialized", "bool", true) -end - ---GUI -j=0 -local separator1 = dt.new_widget("separator"){} -local separator1b = dt.new_widget("separator"){} -local separator2 = dt.new_widget("separator"){} -local separator2b = dt.new_widget("separator"){} -local label_align_options= dt.new_widget("section_label"){ - label = _('image align options') -} -local label_enfuse_options= dt.new_widget("section_label"){ - label = _('image fusion options') -} -local label_output_format= dt.new_widget("section_label"){ - label = _('target file') -} -local label_path = dt.new_widget("label"){ - label = _('directory'), - ellipsize = "start", - halign = "start" -} -chkbtn_radial_distortion = dt.new_widget("check_button"){ - label = _('optimize radial distortion for all images'), - value = dt.preferences.read("enfuse_pro", "def_radial_distortion", "bool"), - tooltip = _('optimize radial distortion for all images, \nexcept for first'), -} -chkbtn_optimize_field = dt.new_widget("check_button"){ - label = _('optimize field of view for all images'), - value = dt.preferences.read("enfuse_pro", "def_optimize_field", "bool"), - tooltip =_('optimize field of view for all images, except for first. \nUseful for aligning focus stacks (DFF) with slightly \ndifferent magnification.'), -} -chkbtn_optimize_image_center = dt.new_widget("check_button"){ - label = _('optimize image center shift for all images'), - value = dt.preferences.read("enfuse_pro", "def_optimize_image_center", "bool"), - tooltip =_('optimize image center shift for all images, \nexcept for first.'), -} -chkbtn_auto_crop = dt.new_widget("check_button"){ - label = _('auto crop the image'), - value = dt.preferences.read("enfuse_pro", "def_auto_crop", "bool"), - tooltip =_('auto crop the image to the area covered by all images.'), -} -chkbtn_distortion = dt.new_widget("check_button"){ - label = _('load distortion from lens database'), - value = dt.preferences.read("enfuse_pro", "def_distortion", "bool"), - tooltip =_('try to load distortion information from lens database'), -} -chkbtn_hard_masks = dt.new_widget("check_button"){ - label = _('hard mask'), - value = dt.preferences.read("enfuse_pro", "def_hard_masks", "bool"), - tooltip =_('force hard blend masks on the finest scale. this avoids \naveraging of fine details (only), at the expense \nof increasing the noise. this improves the \nsharpness of focus stacks considerably.\ndefault (soft mask)'), - reset_callback = function(self) - self.value = dt.preferences.read("enfuse_pro", "def_hard_masks", "bool") - end -} -chkbtn_save_masks = dt.new_widget("check_button"){ - label = _('save masks'), - value = dt.preferences.read("enfuse_pro", "def_save_masks", "bool"), - tooltip =_('Save the generated weight masks to your home directory,\nenblend saves masks as 8 bit grayscale, \ni.e. single channel images. \nfor accuracy we recommend to choose a lossless format.'), - reset_callback = function(self) - self.value = dt.preferences.read("enfuse_pro", "def_save_masks", "bool") - end -} -chkbtn_cpytags = dt.new_widget("check_button"){ - label = ' Copy Tags', - value = pref_cpytags, - tooltip ='Copy tags from first image.', -} -sldr_exposure_weight = dt.new_widget("slider"){ - label = _('exposure weight'), - tooltip = _('set the relative weight of the well-exposedness criterion \nas defined by the chosen exposure weight function. \nincreasing this weight relative to the others will\n make well-exposed pixels contribute more to\n the final output. \ndefault: (1.0)'), - hard_min = 0, - hard_max = 1, - value = dt.preferences.read("enfuse_pro", "def_exposure_weight", "float") --1 def -} -sldr_saturation_weight = dt.new_widget("slider"){ - label = _('saturation weight'), - tooltip = _('set the relative weight of high-saturation pixels. \nincreasing this weight makes pixels with high \nsaturation contribute more to the final output. \ndefault: (0.2)'), - hard_min = 0, - hard_max = 1, - value = dt.preferences.read("enfuse_pro", "def_saturation_weight", "float"), --0.5 -} -sldr_contrast_weight = dt.new_widget("slider"){ - label = _('contrast weight'), - tooltip = _('sets the relative weight of high local-contrast pixels. \ndefault: (0.0).'), - hard_min = 0, - hard_max = 1, - value = dt.preferences.read("enfuse_pro", "def_contrast_weight", "float")--0 default -} -sldr_exposure_optimum_weight = dt.new_widget("slider"){ - label = _('exposure optimum'), - tooltip = _('determine at what normalized exposure value\n the optimum exposure of the input images\n is. this is, set the position of the maximum\n of the exposure weight curve. use this \noption to fine-tune exposure weighting. \ndefault: (0.5)'), - hard_min = 0, - hard_max = 1, - value = dt.preferences.read("enfuse_pro", "def_exposure_optimum_weight", "float")--0.5 default0 -} -sldr_exposure_width_weight = dt.new_widget("slider"){ - label = _('exposure width'), - tooltip = _('set the characteristic width (FWHM) of the exposure \nweight function. low numbers give less weight to \npixels that are far from the user-defined \noptimum and vice versa. use this option to \nfine-tune exposure weighting. \ndefault: (0.2)'), - hard_min = 0, - hard_max = 1, - value = dt.preferences.read("enfuse_pro", "def_exposure_width_weight", "float") --0.2 default -} -file_chooser_button_path = dt.new_widget("file_chooser_button"){ - title = _('Select export path'), -- The title of the window when choosing a file - is_directory = true, -- True if the file chooser button only allows directories to be selecte - tooltip =_('select the target directory for the fused image. \nthe filename is created automatically.'), -} -chkbtn_source_location = dt.new_widget("check_button"){ - label = _('save to source image location'), - value = true, - tooltip =_('If checked ignores the location below and saves output image(s) to the same location as the source images.'), - reset_callback = function(self) - self.value = true - end -} -cmbx_grid_size = dt.new_widget("combobox"){ - label = _('image grid size'), - tooltip =_('break image into a rectangular grid \nand attempt to find num control points in each section.\ndefault: (5x5)'), - value = dt.preferences.read("enfuse_pro", "def_grid_size", "integer"), --5 - "1", "2", "3","4","5","6","7","8","9", - reset_callback = function(self) - self.value = dt.preferences.read("enfuse_pro", "def_grid_size", "integer") - end -} -cmbx_control_points = dt.new_widget("combobox"){ - label = _('control points/grid'), - tooltip =_('number of control points (per grid, see option -g) \nto create between adjacent images \ndefault: (8).'), - value = dt.preferences.read("enfuse_pro", "def_control_points", "integer"), --8, "1", "2", "3","4","5","6","7","8","9", - "1", "2", "3","4","5","6","7","8","9", - reset_callback = function(self) - self.value = dt.preferences.read("enfuse_pro", "def_control_points", "integer") - end -} -cmbx_control_points_remove = dt.new_widget("combobox"){ - label = _('remove control points with error'), - tooltip =_('remove all control points with an error higher \nthan num pixels \ndefault: (3)'), - value = dt.preferences.read("enfuse_pro", "def_control_points_remove", "integer"), --3, "1", "2", "3","4","5","6","7","8","9", - "1", "2", "3","4","5","6","7","8","9", - reset_callback = function(self) - self.value = dt.preferences.read("enfuse_pro", "def_control_points_remove", "integer") - end -} -cmbx_correlation = dt.new_widget("combobox"){ - label = _('correlation threshold for control points'), - tooltip =_('correlation threshold for identifying \ncontrol points \ndefault: (0.9).'), - value = dt.preferences.read("enfuse_pro", "def_correlation", "integer"), --9, "0,1", "0,2", "0,3","0,4","0,5","0,6","0,7","0,8","0,9", - "0.1", "0.2", "0.3","0.4","0.5","0.6","0.7","0.8","0.9","1.0", - reset_callback = function(self) - self.value = dt.preferences.read("enfuse_pro", "def_correlation", "integer") - end -} -cmbx_contrast_window_size = dt.new_widget("combobox"){ - label = _('contrast window size'), - tooltip =_('set the window size for local contrast analysis. \nthe window will be a square of size × size pixels. \nif given an even size, Enfuse will \nautomatically use the next odd number.\nfor contrast analysis size values larger \nthan 5 pixels might result in a \nblurry composite image. values of 3 and \n5 pixels have given good results on \nfocus stacks. \ndefault: (5) pixels'), - value = dt.preferences.read("enfuse_pro", "def_contrast_window_size", "integer"), --3, "3","4","5","6","7","8","9","10", - "3", "4", "5","6","7","8","9","10", -} -cmbx_contrast_edge_scale = dt.new_widget("combobox"){ - label = _('contrast edge scale'), - tooltip =_('a non-zero value for EDGE-SCALE switches on the \nLaplacian-of-Gaussian (LoG) edge detection algorithm.\n edage-scale is the radius of the Gaussian used \nin the search for edges. a positive LCE-SCALE \nturns on local contrast enhancement (LCE) \nbefore the LoG edge detection. \nDefault: (0.0) pixels.'), - value = dt.preferences.read("enfuse_pro", "def_contrast_edge_scale", "integer"), --1, "0:0:0", - "0.0","0.1","0.2","0.3","0.4","0.5", - -} -cmbx_contrast_min_curvature = dt.new_widget("combobox"){ - label = _('contrast min curvature'), - tooltip =_('define the minimum curvature for the LoG edge detection. Append a ‘%’ to specify the minimum curvature relative to maximum pixel value in the source image. Default: (0.0%)'), - value = dt.preferences.read("enfuse_pro", "def_contrast_min_curvature", "integer"), --1, "0.0%","0.1%", "0.2%", "0.3%","0.4%","0.5%","0.6%","0.7%","0.8%","0.9%","1.0%", - "0.0%", "0.1%", "0.2%","0.3%","0.4%","0.5%","0.6%","0.7%","0.8%","0.9%","1.0%", -} -cmbx_existing_file = dt.new_widget("combobox"){ - label = _('on conflict'), - value = dt.preferences.read("enfuse_pro", "selected_overwrite", "integer"), --1, - sensitive= dt.preferences.read("enfuse_pro", "sentitiv_overwrite", "bool"), --1, - _('create unique filename'),_('overwrite'), - reset_callback = function(self) - self.value = dt.preferences.read("enfuse_pro", "selected_overwrite", "integer") - end -} -cmbx_style = dt.new_widget("combobox"){ - label = "Apply Style on Import", - tooltip = "Apply selected style on auto-import to newly created blended image", - value = 1, - "none", - } -pref_style_enum = 1 -for k=1, (styles_count-1) do - cmbx_style[k+1] = styles[k].name - if styles[k].name == pref_style then pref_style_enum = k+1 end -end -cmbx_style.value = pref_style_enum -chkbtn_image_variations = dt.new_widget("check_button"){ - label = _('create image variants with saved presets'), - value = dt.preferences.read("enfuse_pro", "def_image_variants", "bool"), - tooltip =_('creates image variants with the three \nsaved DRI or DFF presets'), - sensitive=true, - clicked_callback = function(self) - if (self.value) then - dt.preferences.write("enfuse_pro", "def_image_variants", "bool", true) - dt.preferences.write("enfuse_pro", "sentitiv_overwrite", "bool",false) - cmbx_existing_file.value=1 - cmbx_existing_file.sensitive=false - else - dt.preferences.write("enfuse_pro", "def_image_variants", "bool", false) - dt.preferences.write("enfuse_pro", "sentitiv_overwrite", "bool",true) - cmbx_existing_file.sensitive=true - end - end, - reset_callback = function(self) - dt.preferences.write("enfuse_pro", "def_image_variants", "bool", false) - dt.preferences.write("enfuse_pro", "sentitiv_overwrite", "bool",true) - self.value = false - cmbx_existing_file.sensitive=true - end - -} -button_save_preset = dt.new_widget("button"){ - label = _('save fusion preset'), - tooltip =_('save the selected fusion preset'), - clicked_callback = function() - pref_text = "" - if (cmbx_fusion_type.value == "1 - DRI image") then - pref_text = "dri1_" - elseif (cmbx_fusion_type.value == "2 - DRI image") then - pref_text = "dri2_" - elseif (cmbx_fusion_type.value == "3 - DRI image") then - pref_text = "dri3_" - elseif (cmbx_fusion_type.value == "1 - DFF image") then - pref_text = "dff1_" - elseif (cmbx_fusion_type.value == "2 - DFF image") then - pref_text = "dff2_" - elseif (cmbx_fusion_type.value == "3 - DFF image") then - pref_text = "dff3_" - elseif (cmbx_fusion_type.value == "free preset") then - pref_text = "free_" - else - dt.print(_('unkown error')) - end - -- Write Preset - if pref_text ~= "" then - dt.preferences.write("enfuse_pro", pref_text.."hard_masks", "bool", chkbtn_hard_masks.value) - dt.preferences.write("enfuse_pro", pref_text.."save_masks", "bool", chkbtn_save_masks.value) - dt.preferences.write("enfuse_pro", pref_text.."contrast_window_size", "integer", cmbx_contrast_window_size.selected) - dt.preferences.write("enfuse_pro", pref_text.."contrast_edge_scale", "integer", cmbx_contrast_edge_scale.selected) - dt.preferences.write("enfuse_pro", pref_text.."contrast_min_curvature", "integer", cmbx_contrast_min_curvature.selected) - dt.preferences.write("enfuse_pro", pref_text.."exposure_weight", "float", sldr_exposure_weight.value) - dt.preferences.write("enfuse_pro", pref_text.."saturation_weight", "float", sldr_saturation_weight.value) - dt.preferences.write("enfuse_pro", pref_text.."contrast_weight", "float", sldr_contrast_weight.value) - dt.preferences.write("enfuse_pro", pref_text.."exposure_optimum_weight", "float", sldr_exposure_optimum_weight.value) - dt.preferences.write("enfuse_pro", pref_text.."exposure_width_weight", "float",sldr_exposure_width_weight.value) - dt.print(_('preset '..pref_text..' saved')) - end - end -} -button_load_preset = dt.new_widget("button"){ - label = _('load fusion defaults'), - tooltip =_('load the default fusion settings'), - clicked_callback = function() - chkbtn_hard_masks.value=dt.preferences.read("enfuse_pro", "def_hard_masks", "bool") - chkbtn_save_masks.value=dt.preferences.read("enfuse_pro", "def_save_masks", "bool") - cmbx_contrast_window_size.value=dt.preferences.read("enfuse_pro", "def_contrast_window_size", "integer") - cmbx_contrast_edge_scale.value=dt.preferences.read("enfuse_pro", "def_contrast_edge_scale", "integer") - cmbx_contrast_min_curvature.value=dt.preferences.read("enfuse_pro", "def_contrast_min_curvature", "integer") - sldr_exposure_weight.value=dt.preferences.read("enfuse_pro", "def_exposure_weight", "float") - sldr_saturation_weight.value=dt.preferences.read("enfuse_pro", "def_saturation_weight", "float") - sldr_contrast_weight.value=dt.preferences.read("enfuse_pro", "def_contrast_weight", "float") - sldr_exposure_optimum_weight.value=dt.preferences.read("enfuse_pro", "def_exposure_optimum_weight", "float") - sldr_exposure_width_weight.value=dt.preferences.read("enfuse_pro", "def_exposure_width_weight", "float") - end - -} -cmbx_output_format = dt.new_widget("combobox"){ - label = _('file format'), - value = dt.preferences.read("enfuse_pro", "selected_output_format", "integer"), --1, "TIFF", "JPEG", "PNG","PNM","PBM","PGM","PPM", - changed_callback = function(self) - dt.preferences.write("enfuse_pro", "selected_output_format", "integer", self.selected) - end, - "TIFF", "JPEG", "PNG","PNM","PBM","PPM", - reset_callback = function(self) - self.value = dt.preferences.read("enfuse_pro", "selected_output_format", "integer") - end -} -cmbx_fusion_type = dt.new_widget("combobox"){ - label = _('fusion preset'), - tooltip =_('select the preset and save the preset\n if you want to reuse it or create an image\n variant'), - value = 1, --dt.preferences.read("enfuse_pro", "def_fusion_type", "integer"), --1, "DRI image", "DFF image", "without preset", - changed_callback = function(self) - dt.preferences.write("enfuse_pro", "def_fusion_type", "integer", self.selected) - - if (self.value == "1 - DRI image") then - pref_text = "dri1_" - elseif (self.value == "2 - DRI image") then - pref_text = "dri2_" - elseif (self.value == "3 - DRI image") then - pref_text = "dri3_" - elseif (self.value == "1 - DFF image") then - pref_text = "dff1_" - elseif (self.value == "2 - DFF image") then - pref_text = "dff2_" - elseif (self.value == "3 - DFF image") then - pref_text = "dff3_" - elseif (self.value == "free preset") then - pref_text = "free_" - end - - if string.match(pref_text,"^dri")~=nil then - chkbtn_hard_masks.sensitive=false - chkbtn_hard_masks.value=false - sldr_contrast_weight.sensitive=true - elseif string.match(pref_text,"^dff")~=nil then - chkbtn_hard_masks.sensitive=false - chkbtn_hard_masks.value=true - sldr_contrast_weight.sensitive=false - else - chkbtn_hard_masks.sensitive=true - chkbtn_hard_masks.value=false - sldr_contrast_weight.sensitive=true - end - - chkbtn_hard_masks.value=dt.preferences.read("enfuse_pro", pref_text.."hard_masks", "bool") - chkbtn_save_masks.value=dt.preferences.read("enfuse_pro", pref_text.."save_masks", "bool") - cmbx_contrast_window_size.value=dt.preferences.read("enfuse_pro", pref_text.."contrast_window_size", "integer") - cmbx_contrast_edge_scale.value=dt.preferences.read("enfuse_pro", pref_text.."contrast_edge_scale", "integer") - cmbx_contrast_min_curvature.value=dt.preferences.read("enfuse_pro", pref_text.."contrast_min_curvature", "integer") - sldr_exposure_weight.value=dt.preferences.read("enfuse_pro", pref_text.."exposure_weight", "float") - sldr_saturation_weight.value=dt.preferences.read("enfuse_pro", pref_text.."saturation_weight", "float") - sldr_contrast_weight.value=dt.preferences.read("enfuse_pro", pref_text.."contrast_weight", "float") - sldr_exposure_optimum_weight.value=dt.preferences.read("enfuse_pro", pref_text.."exposure_optimum_weight", "float") - sldr_exposure_width_weight.value=dt.preferences.read("enfuse_pro", pref_text.."exposure_width_weight", "float") - - end, - "1 - DRI image", "2 - DRI image","3 - DRI image","1 - DFF image", "2 - DFF image","3 - DFF image","free preset", - - reset_callback = function(self_type) - cmbx_fusion_type.value = dt.preferences.read("enfuse_pro", "def_fusion_type", "integer") - end -} -entry_tag = dt.new_widget("entry"){ - tooltip = "Additional tags to be added on import. Seperate with commas, all spaces will be removed", - text = pref_addtags, - placeholder = "Enter tags, seperated by commas", - editable = true -} -local widget = dt.new_widget("box") { - orientation = "vertical", - label_align_options, - chkbtn_radial_distortion, - chkbtn_optimize_field, - chkbtn_optimize_image_center, - chkbtn_auto_crop, - chkbtn_distortion, - cmbx_grid_size, - cmbx_control_points, - cmbx_control_points_remove, - cmbx_correlation, - separator1, - separator1b, - label_enfuse_options, - cmbx_fusion_type, - chkbtn_image_variations, - sldr_exposure_weight, - sldr_saturation_weight, - sldr_contrast_weight, - sldr_exposure_optimum_weight, - sldr_exposure_width_weight, - chkbtn_hard_masks, - chkbtn_save_masks, - cmbx_contrast_edge_scale, - cmbx_contrast_min_curvature, - cmbx_contrast_window_size, - button_save_preset, - button_load_preset, - separator2, - separator2b, - label_output_format, - cmbx_output_format, - label_path, - file_chooser_button_path, - chkbtn_source_location, - cmbx_existing_file, - cmbx_style, - chkbtn_cpytags, - entry_tag, -} - --- FUNCTION -- -local function GetFileName(full_path) - --[[Parses a full path (path/filename_identifier.extension) into individual parts - Input: Folder1/Folder2/Folder3/Img_0001.CR2 - - Returns: - path: Folder1/Folder2/Folder3/ - filename: Img_0001 - identifier: 0001 - extension: .CR2 - - EX: - path_1, file_1, id_1, ext_1 = GetFileName(full_path_1) - ]] - local path = string.match(full_path, ".*[\\/]") - local filename = string.gsub(string.match(full_path, "[%w-_]*%.") , "%." , "" ) - local identifier = string.match(filename, "%d*$") - local extension = string.match(full_path, "%.%w*") - return path, filename, identifier, extension -end -local function truncate(x) - return x<0 and math.ceil(x) or math.floor(x) -end -local function replace_comma_to_dot(s) - return string.gsub(s, "%,", ".") -end -local function file_exists(name) - local f=io.open(""..name.."","r") - if f~=nil then - io.close(f) - return true - else - return false - end -end -local function remove_temp_files() - if dt.configuration.running_os == "windows" then - dt.print_log("Deleting temp files...") - dt.control.execute("del "..images_to_align) - dt.control.execute("del "..images_to_blend) - dt.print_log("Done deleting") - else - dt.print_log("Deleting temp files...") - dt.control.execute("rm "..images_to_align) - dt.control.execute("rm "..images_to_blend) - dt.print_log("Done deleting") - end - - --[[ - dt.print_error("rm "..images_to_align) - result_to_align_images=dt.control.execute("rm "..images_to_align) - dt.print_error("rm "..tmppath.."/aligned_*.tif") - result_aligned_images=dt.control.execute("rm "..tmppath.."/aligned_*.tif") - ]] -end -local function build_execute_command(cmd, args, file_list) - local result = false - - if dt.configuration.running_os == "macos" then - cmd = string.gsub(cmd, "open", "") - cmd = string.gsub(cmd, "-W", "") - cmd = string.gsub(cmd, "-a", "") - -- result = cmd.." "..file_list.." "..args - --else - -- result = cmd..""..args.." "..file_list - end - result = cmd.." "..args.." "..file_list - return result -end -function copy_exif() - exiftool_path = string.gsub(exiftool_path, "open", "") - exiftool_path = string.gsub(exiftool_path, "-W", "") - exiftool_path = string.gsub(exiftool_path, "-a", "") - exifStartCommand = exiftool_path.." -TagsFromFile "..source_file.." -exif:all --subifd:all -overwrite_original "..path_with_filename - dt.print_log("EXIFTool Start Command: "..exifStartCommand) - resultexif=dt.control.execute(exifStartCommand) - if (resultexif == 0) then - dt.print_log("EXIFTool copy successful") - dt.print("Copied EXIF data") - else - dt.print(_('ERROR: exiftool doesn\'t work. for more informations see terminal output')) - dt.print_error("exif copy failed") - end -end -function align_images() - dt.print(_('aligning images')) - - --Setup Align Image Stack Arguments-- - align_args = "" - if (chkbtn_radial_distortion.value) then align_args = align_args.." -d" end - if (chkbtn_optimize_field.value) then align_args = align_args.." -m" end - if (chkbtn_optimize_image_center.value) then align_args = align_args.." -i" end - if (chkbtn_auto_crop.value) then align_args = align_args.." -C" end - if (chkbtn_distortion.value) then align_args = align_args.." --distortion" end - align_args = align_args.." -g "..cmbx_grid_size.value - align_args = align_args.." -c "..cmbx_control_points.value - align_args = align_args.." -t "..cmbx_control_points_remove.value - align_args = align_args.." --corr="..cmbx_correlation.value - if (dt.preferences.read("module_enfuse_pro", "align_use_gpu", "bool")) then align_args = align_args.." --gpu" end - - align_args = align_args.." -a "..first_path.."aligned_ " - alignStartCommand = build_execute_command(AIS_path, align_args, images_to_align) - dt.print_log("Align Start Command: "..alignStartCommand) - resp = dt.control.execute(alignStartCommand) - dt.print_log("Completed Align") - return resp -end -function blend_images() - blend_args = "" - if from_preset then --load args from preset preferences - blend_args=blend_args.." --exposure-weight="..(replace_comma_to_dot(dt.preferences.read("enfuse_pro", preset_text.."_exposure_weight", "float"))) - blend_args=blend_args.." --saturation-weight="..(replace_comma_to_dot(dt.preferences.read("enfuse_pro", preset_text.."_saturation_weight", "float"))) - blend_args=blend_args.." --contrast-weight="..(replace_comma_to_dot(dt.preferences.read("enfuse_pro", preset_text.."_contrast_weight", "float"))) - blend_args=blend_args.." --exposure-optimum="..(replace_comma_to_dot(dt.preferences.read("enfuse_pro", preset_text.."_exposure_optimum_weight", "float"))) - blend_args=blend_args.." --exposure-width="..(replace_comma_to_dot(dt.preferences.read("enfuse_pro", preset_text.."_exposure_width_weight", "float"))) - if (chkbtn_hard_masks.value) then blend_args=blend_args.."--hard-mask" end - if (chkbtn_save_masks.value) then blend_args=blend_args.."--save-masks" end - blend_args=blend_args.." --contrast-window-size="..dt.preferences.read("enfuse_pro", preset_text.."_contrast_window_size", "integer") - blend_args=blend_args.." --contrast-edge-scale="..dt.preferences.read("enfuse_pro", preset_text.."_contrast_edge_scale", "integer") - blend_args=blend_args.." --contrast-min-curvature="..dt.preferences.read("enfuse_pro", preset_text.."_contrast_min_curvature", "integer") - blend_args=blend_args.." --depth="..dt.preferences.read("module_enfuse_pro", "image_color_depth", "enum") - else --load args from GUI values - blend_args = blend_args.." --exposure-weight="..(replace_comma_to_dot(sldr_exposure_weight.value)) - blend_args = blend_args.." --saturation-weight="..(replace_comma_to_dot(sldr_saturation_weight.value)) - blend_args = blend_args.." --contrast-weight="..(replace_comma_to_dot(sldr_contrast_weight.value)) - blend_args = blend_args.." --exposure-optimum="..(replace_comma_to_dot(sldr_exposure_optimum_weight.value)) - blend_args = blend_args.." --exposure-width="..(replace_comma_to_dot(sldr_exposure_width_weight.value)) - if (chkbtn_hard_masks.value) then blend_args = blend_args.." --hard-mask" end - if (chkbtn_save_masks.value) then blend_args = blend_args.." --save-masks" end - blend_args = blend_args.." --contrast-window-size="..cmbx_contrast_window_size.value - blend_args = blend_args.." --contrast-edge-scale="..cmbx_contrast_edge_scale.value - blend_args = blend_args.." --contrast-min-curvature="..cmbx_contrast_min_curvature.value - blend_args = blend_args.." --depth="..dt.preferences.read("module_enfuse_pro", "image_color_depth", "enum") - end - - --set output format per GUI selection - if (cmbx_output_format.value == "TIFF") then - cmd_suffix_output_format="tif" - blend_args = blend_args.." --compression="..dt.preferences.read("module_enfuse_pro", "compression_tiff", "enum") - elseif (cmbx_output_format.value == "JPEG") then - cmd_suffix_output_format="jpg" - blend_args = blend_args.." --compression="..truncate(dt.preferences.read("module_enfuse_pro", "compression_jpeg", "integer")) - elseif (cmbx_output_format.value == "PNG") then - cmd_suffix_output_format="png" - elseif (cmbx_output_format.value == "PNM") then - cmd_suffix_output_format="pnm" - elseif (cmbx_output_format.value == "PBM") then - cmd_suffix_output_format="pbm" - elseif (cmbx_output_format.value == "PPM") then - cmd_suffix_output_format="ppm" - end - - --Set output path and add filename - if (chkbtn_source_location.value) then - cmd_output_path = source_path - else - cmd_output_path=file_chooser_button_path.value --FUTURE FEATURE: add gui option for "same as source images" - end - path_with_filename = cmd_output_path..os_path_seperator..first_filename.."-"..last_id.."."..cmd_suffix_output_format - - --Create unique name with index if GUI selection create unique name (don't overwrite), also do this if user selected to make variants from presets - if (cmbx_existing_file.selected == 1) or (from_preset) then - cmd_output_image_index=0 - while (file_exists(path_with_filename)) do - cmd_output_image_index = cmd_output_image_index+1 - if cmd_output_image_index <= 9 then - outputindex="0"..tostring(cmd_output_image_index) - else - outputindex=tostring(cmd_output_image_index) - end - path_with_filename = cmd_output_path..os_path_seperator..first_filename.."-"..last_id.."-"..outputindex.."."..cmd_suffix_output_format - end - end - cmd_output_image = " --output="..path_with_filename - blend_args = blend_args..cmd_output_image - - --images_to_blend = first_path.."aligned_*.tif" - images_to_blend = "" - for j=0, counted_images-1 do - if j < 10 then - id = "000"..tostring(j) - else - id = "00"..tostring(j) - end - images_to_blend = images_to_blend..first_path.."aligned_"..id..".tif " - end - - BlendStartCommand=build_execute_command(enfuse_path, blend_args, images_to_blend) - - dt.print_log("Blend Start Command: "..BlendStartCommand) - resultBlend=dt.control.execute(BlendStartCommand) - dt.print_log("Completed Blend") - - return resultBlend, path_with_filename -end -local function show_status(storage, image, format, filename, --Store: Called on each exported image - number, total, high_quality, extra_data) - dt.print(_('export TIFF for image fusion ')..tostring(truncate(number)).." / "..tostring(truncate(total))) -end -function create_image_fusion(storage, image_table, extra_data) --Finalize: Called once when all images are done exporting ---Create Images String-- - images_to_align = "" - images_to_blend = "" - counted_images=0 - first_id = "999999999999999999999999" - last_id = "0" - for source_image,image_path in pairs(image_table) do - counted_images=counted_images+1 - images_to_align = images_to_align..image_path.." " - curr_path, curr_filename, curr_id, curr_ext = GetFileName(image_path) - if (curr_id < first_id) then - first_path = curr_path - first_filename = curr_filename - first_id = curr_id - first_ext = curr_ext - dt_source_image = source_image - end - if (curr_id > last_id) then - last_path = curr_path - last_filename = curr_filename - last_id = curr_id - last_ext = curr_ext - end - source_path = source_image.path - source_file = source_image.path..os_path_seperator..source_image.filename - end - ---Check if at least 2 images selected-- - if (counted_images<=1) then - dt.print(_('ERROR: not enough pictures selected. please select two or more images\nfrom the same object, but with different camera settings.')) - dt.print_error("Not enough pictures selected") - remove_temp_files() - return - end - ---Ensure Required Software is Installed-- - df.set_executable_path_preference("align_image_stack", dt.preferences.read("module_enfuse_pro", "ais_path", "string")) - dt.print_log("Executable Path Preference: "..df.get_executable_path_preference("align_image_stack")) - AIS_path = df.check_if_bin_exists("align_image_stack") - if not AIS_path then - dt.print_error("align image stack not found") - dt.print("ERROR - align image stack not found") - remove_temp_files() - return - end - - df.set_executable_path_preference("enfuse", dt.preferences.read("module_enfuse_pro", "enfuse_path", "string")) - dt.print_log("Executable Path Preference: "..df.get_executable_path_preference("enfuse")) - enfuse_path = df.check_if_bin_exists("enfuse") - if not enfuse_path then - dt.print_error("enfuse not found") - dt.print("ERROR - enfuse not found") - remove_temp_files() - return - end - - df.set_executable_path_preference("exiftool", dt.preferences.read("module_enfuse_pro", "exiftool_path", "string")) - dt.print_log("Executable Path Preference: "..df.get_executable_path_preference("exiftool")) - exiftool_path = df.check_if_bin_exists("exiftool") - if not exiftool_path then - dt.print_error("exiftool not found") - dt.print("ERROR - exiftool not found") - remove_temp_files() - return - end - ---Ensure proper version of Enfuse installed-- - --[[ - enfuseVersionStartCommand='enfuse --version | grep "enfuse 4.2"' - enfuse_version=dt.control.execute(enfuseVersionStartCommand) - if (enfuse_version ~= 0) then - dt.print(_('ERROR: wrong enfuse version found. the plugin works only with enfuse 4.2! please install enfuse version 4.2')) - return - end]] - ---Check that output path selected - cmd_output_path = file_chooser_button_path.value - if (cmd_output_path == nil) and not(chkbtn_source_location.value) then - dt.print(_('ERROR: no target directory selected')) - remove_temp_files() - return - end - - dt.print_log("Starting Image Fusion") - job = dt.gui.create_job(_('Creating DRI/DFF image'), true, stop_selection) - - percent_step = .33 - if (chkbtn_image_variations.value) then percent_step = .2 end - job.percent = job.percent + percent_step - ---Align Images-- - resultalign = align_images() - if (resultalign ~= 0) then --Aling Image Stack Failed-- - dt.print(_('ERROR: align_image_stack doesn\'t work. For more information see terminal output')) - dt.print_error("Align Image Stack Failed") - remove_temp_files() - job.valid = false - return - end - dt.print(_('aligning complete')) - job.percent = job.percent + percent_step - ---Blend Images-- - from_preset = false - iterations = 1 - pref_text = "" - if (chkbtn_image_variations.value) then - iterations = 3 - from_preset = true - if string.match(cmbx_fusion_type.value, "DRI") then - pref_text = "dri" - elseif string.match(cmbx_fusion_type.value, "DFF") then - pref_text = "dff" - else --if "variants" selected, but not using DRI or DFF preset then cannot create variants - dt.print("Error, must select a DRI or DFF preset when starting a fustion with variants") - dt.print_error("DRI or DFF preset not selected when variants option was checked") - remove_temp_files() - job.valid = false - return - end - end - - for j = 1, iterations do - if (from_preset) then - preset_text=pref_text..j - else - preset_text="" - end - resultBlend, blended_image = blend_images() --Check here to ensure enfuse worked properly - if resultBlend ~= 0 then - dt.print(_('ERROR: enfuse didn\'t work. For more information see terminal output')) - dt.print_error("Enfuse failed") - remove_temp_files() - job.valid = false - return - end - --Copy EXIF Data (IF)-- - if (dt.preferences.read("module_enfuse_pro", "exiftool_copy_tags", "bool")) then copy_exif() end - --Auto-Import-- - if (dt.preferences.read("module_enfuse_pro", "add_image_to_db", "bool")) then - local imported = dt.database.import(path_with_filename) - --Apply Selected Style (IF)-- - if cmbx_style.selected > 1 then - set_style = styles[cmbx_style.selected - 1] - dt.styles.apply(set_style , imported) - end - --Copy Tags (IF)-- - if (chkbtn_cpytags.value) then - all_tags = dt.tags.get_tags(dt_source_image) - for _,tag in pairs(all_tags) do - if string.match(tag.name, 'darktable|') == nil then - dt.tags.attach(tag, imported) - end - end - end - --Apply Entered Tags (IF)-- - set_tag = entry_tag.text - if set_tag ~= nil then - for tag in string.gmatch(set_tag, '[^,]+') do - tag = string.gsub(tag, " ", "") - tag = dt.tags.create(tag) - dt.tags.attach(tag, imported) - end - end - end - job.percent = job.percent + percent_step - end - - --Copy EXIF Data (IF)-- - - remove_temp_files() - dt.print("Image fusion process complete") - dt.print_log("Image fusion process complete") - job.valid = false -end -local function support_format(storage, format) --Supported: Check to make sure image type is supported by darktable - fmt = string.lower(format.name) - if string.match(fmt,"tiff") == nil then - return false - else - return true - end -end - --- REGISTER -- -dt.register_storage("module_enfuse_pro", _('DRI or DFF image'), show_status, create_image_fusion, support_format, nil, widget) - --- PREFERENCES -- -entry_widget_style = dt.new_widget("entry"){ - tooltip = "Enter the style name exactly as it is", - text = nil, - placeholder = "Enter Style name", - editable = true -} -dt.preferences.register("module_enfuse_pro", "style", -- name - "string", -- type - 'enfuse_pro: Defualt Style', -- label - 'Changes DEFAULT entry in the Style option. Requires restart to take effect.', -- tooltip - "", -- default - entry_widget_style -) -entry_widget_tags = dt.new_widget("entry"){ - tooltip = "Seperate with commas, all spaces will be removed", - text = nil, - placeholder = "Enter default tags", - editable = true -} -dt.preferences.register("module_enfuse_pro", "add_tags", -- name - "string", -- type - 'enfuse_pro: Defualt additional tags', -- label - 'Changes DEFAULT entry in the additional tags option. Requires restart to take effect.', -- tooltip - "", -- default - entry_widget_tags -) -dt.preferences.register("module_enfuse_pro", "copy_tags", -- name - "bool", -- type - 'enfuse_pro: Copy tags from first image by default', -- label - 'Changes DEFAULT selection for Copy Tags, Requires restart to take effect.', -- tooltip - true -- default -) -dt.preferences.register("module_enfuse_pro", "exiftool_copy_tags", -- name - "bool", -- type - _('enfuse pro: copy exif data'), -- label - _('copy the exif tags from the first image to the target'), -- tooltip - true) -- default -dt.preferences.register("module_enfuse_pro", "add_image_to_db", -- name - "bool", -- type - _('enfuse pro: add fused image to database'), -- label - _('add the fused image to the darktable database'), -- tooltip - false) -- default -dt.preferences.register("module_enfuse_pro", "align_use_gpu", -- name - "bool", -- type - _('enfuse pro: use GPU for remaping'), -- label - _('set the GPU remapping for image align'), -- tooltip - false) -dt.preferences.register("module_enfuse_pro", "compression_jpeg", -- name - "integer", -- type - _('enfuse pro: JPEG compression'), -- label - _('set the compression for JPEG files'), -- tooltip - 98, -- default - 50, -- min - 100) -- max -dt.preferences.register("module_enfuse_pro", "compression_tiff", -- name - "enum", -- type - _('enfuse pro: TIFF compression'), -- label - _('set the compression type for tiff files'), -- tooltip - "LZW", -- default - "NONE", "DEFLATE","PACKBITS") -- va -dt.preferences.register("module_enfuse_pro", "image_color_depth", -- name - "enum", -- type - _('enfuse pro: image color depth (bit)'), -- label - _('set the output color depth'), -- tooltip - "16", -- default - "8","32","r32","r64") -- values - ---AIS bin location -AIS_path = df.get_executable_path_preference("align_image_stack") -if not AIS_path then - AIS_path = "" -end -AIS_path_widget = dt.new_widget("file_chooser_button"){ - title = "Select align_image_stack[.exe] file", - value = AIS_path, - is_directory = false, -} -dt.preferences.register("module_enfuse_pro", "ais_path", -- name - "file", -- type - 'enfuse_pro: Align Image Stack Location', -- label - 'Install location of align_image_stack. Requires restart to take effect.', -- tooltip - "align_image_stack", -- default - AIS_path_widget -) - ---enfuse bin location -enfuse_path = df.get_executable_path_preference("enfuse") -if not enfuse_path then - enfuse_path = "" -end -enfuse_path_widget = dt.new_widget("file_chooser_button"){ - title = "Select enfuse[.exe] file", - value = enfuse_path, - is_directory = false, -} -dt.preferences.register("module_enfuse_pro", "enfuse_path", -- name - "file", -- type - 'enfuse_pro: enfuse Location', -- label - 'Install location of enfuse. Requires restart to take effect.', -- tooltip - "enfuse", -- default - enfuse_path_widget -) - ---exiftool bin location -exiftool_path = df.get_executable_path_preference("exiftool") -if not exiftool_path then - exiftool_path = "" -end -exiftool_path_widget = dt.new_widget("file_chooser_button"){ - title = "Select exiftool[.exe] file", - value = exiftool_path, - is_directory = false, -} -dt.preferences.register("module_enfuse_pro", "exiftool_path", -- name - "file", -- type - 'enfuse_pro: exiftool Location', -- label - 'Install location of exiftool. Requires restart to take effect.', -- tooltip - "exiftool", -- default - exiftool_path_widget -) - From 927bf12243cd75698b1b38b8204ca686cfe80f54 Mon Sep 17 00:00:00 2001 From: BzKevin <36381472+BzKevin@users.noreply.github.com> Date: Sun, 1 Jul 2018 19:54:15 -0400 Subject: [PATCH 5/9] Add enfuse_pro_2 Enhanced version of Holger Klemm's enfuse_pro that adds features and X-platform compatibility. --- contrib/enfuse_pro_2.lua | 1050 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 1050 insertions(+) create mode 100644 contrib/enfuse_pro_2.lua diff --git a/contrib/enfuse_pro_2.lua b/contrib/enfuse_pro_2.lua new file mode 100644 index 0000000..f03d3b5 --- /dev/null +++ b/contrib/enfuse_pro_2.lua @@ -0,0 +1,1050 @@ +--[[Enfuse professional plugin for darktable 2.2.X and 2.4.X + + copyright (c) 2017, 2018 Holger Klemm (Original Linux-only version) + + darktable is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + darktable is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with darktable. If not, see . +]] + +--[[ Enfuse Pro 2 - cross-platform compatible +Modified by: Kevin Ertel + +ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT +* align_image_stack +* enfuse +* exiftool + +USAGE +* require this file from your main luarc config file. + +This plugin will add the new export modul "fusion to DRI or DFF image". +]] + +local dt = require "darktable" +local df = require "lib/dtutils.file" +local gettext = dt.gettext + +-- works with LUA API version 4.0.0 and 5.0.0 +dt.configuration.check_version(...,{4,0,0},{5,0,0}) + +-- Tell gettext where to find the .mo file translating messages for a particular domain +gettext.bindtextdomain("enfuse_pro",dt.configuration.config_dir.."/lua/") + +local function _(msgid) + return gettext.dgettext("enfuse_pro", msgid) +end + +--Detect User Styles-- +styles = dt.styles +styles_count = 1 -- "none" = 1 +for _,i in pairs(dt.styles) do + if type(i) == "userdata" then styles_count = styles_count + 1 end +end + +-- INITS -- +pref_style = dt.preferences.read("module_enfuse_pro", "style", "string") +pref_cpytags = dt.preferences.read("module_enfuse_pro", "copy_tags", "bool") +pref_addtags = dt.preferences.read("module_enfuse_pro", "add_tags", "string") +--[[ +cmd_tmp_path="" +cmd_output_path="" +cmd_output_image="" +cmd_output_image_index = 0 +path_with_filename="" +homepath=os.getenv("Public") +tmppath=homepath.."/.local/tmp" +cmd_exif_copy_exif="" +cmd_suffix_output_format="" +alignStartCommand="" +enfuseStartCommand="" +exifStartCommand="" +outputindex = 0 +job = 0 +]] +if dt.configuration.running_os == "windows" then + os_path_seperator = "\\" +else + os_path_seperator = "/" +end + + +-- align defaults +--dt.preferences.write("enfuse_pro", "initialized", "bool", false) +if not(dt.preferences.read("enfuse_pro", "initialized", "bool")) then + dt.preferences.write("enfuse_pro", "selected_fusion", "integer", 1) + dt.preferences.write("enfuse_pro", "def_radial_distortion", "bool", false) + dt.preferences.write("enfuse_pro", "def_optimize_field", "bool", false) + dt.preferences.write("enfuse_pro", "def_optimize_image_center", "bool", true) + dt.preferences.write("enfuse_pro", "def_auto_crop", "bool", true) + dt.preferences.write("enfuse_pro", "def_distortion", "bool", true) + dt.preferences.write("enfuse_pro", "def_grid_size", "integer", 5) + dt.preferences.write("enfuse_pro", "def_control_points", "integer", 8) + dt.preferences.write("enfuse_pro", "def_control_points_remove", "integer", 3) + dt.preferences.write("enfuse_pro", "def_correlation", "integer", 9) + + -- enfuse defaults + dt.preferences.write("enfuse_pro", "def_fusion_type", "integer", 1) + dt.preferences.write("enfuse_pro", "def_image_variants", "bool", false) + dt.preferences.write("enfuse_pro", "def_hard_masks", "bool", false) + dt.preferences.write("enfuse_pro", "def_save_masks", "bool", false) + dt.preferences.write("enfuse_pro", "def_contrast_window_size", "integer", 3) + dt.preferences.write("enfuse_pro", "def_contrast_edge_scale", "integer", 1) + dt.preferences.write("enfuse_pro", "def_contrast_min_curvature", "integer", 1) + dt.preferences.write("enfuse_pro", "def_exposure_weight", "float", 1.0) + dt.preferences.write("enfuse_pro", "def_saturation_weight", "float", 0.2) + dt.preferences.write("enfuse_pro", "def_contrast_weight", "float", 0.0) + dt.preferences.write("enfuse_pro", "def_exposure_optimum_weight", "float", 0.5) + dt.preferences.write("enfuse_pro", "def_exposure_width_weight", "float",0.2) + dt.preferences.write("enfuse_pro", "selected_overwrite", "integer",1) + dt.preferences.write("enfuse_pro", "sentitiv_overwrite", "bool",true) + + -- preset DRI 1 + temp_text = {"dri1_","dri2_","dri3_"} + for i,preset in pairs(temp_text) do + dt.preferences.write("enfuse_pro", preset.."hard_masks", "bool", false) + dt.preferences.write("enfuse_pro", preset.."save_masks", "bool", false) + dt.preferences.write("enfuse_pro", preset.."contrast_window_size", "integer", 3) + dt.preferences.write("enfuse_pro", preset.."contrast_edge_scale", "integer", 1) + dt.preferences.write("enfuse_pro", preset.."contrast_min_curvature", "integer", 1) + dt.preferences.write("enfuse_pro", preset.."exposure_weight", "float", 1.0) + dt.preferences.write("enfuse_pro", preset.."saturation_weight", "float", 0.2) + dt.preferences.write("enfuse_pro", preset.."contrast_weight", "float", 0.0) + dt.preferences.write("enfuse_pro", preset.."exposure_optimum_weight", "float", 0.5) + dt.preferences.write("enfuse_pro", preset.."exposure_width_weight", "float",0.2) + end + + -- preset DFF 1 + temp_text = {"dff1_","dff2_","dff3_"} + for i,preset in pairs(temp_text) do + dt.preferences.write("enfuse_pro", preset.."hard_masks", "bool", true) + dt.preferences.write("enfuse_pro", preset.."save_masks", "bool", false) + dt.preferences.write("enfuse_pro", preset.."contrast_window_size", "integer", 3) + dt.preferences.write("enfuse_pro", preset.."contrast_edge_scale", "integer", 1) + dt.preferences.write("enfuse_pro", preset.."contrast_min_curvature", "integer", 1) + dt.preferences.write("enfuse_pro", preset.."exposure_weight", "float", 0.0) + dt.preferences.write("enfuse_pro", preset.."saturation_weight", "float", 0.0) + dt.preferences.write("enfuse_pro", preset.."contrast_weight", "float", 1.0) + dt.preferences.write("enfuse_pro", preset.."exposure_optimum_weight", "float", 0.5) + dt.preferences.write("enfuse_pro", preset.."exposure_width_weight", "float",0.2) + end + + -- preset FREE + dt.preferences.write("enfuse_pro", "free_hard_masks", "bool", false) + dt.preferences.write("enfuse_pro", "free_save_masks", "bool", false) + dt.preferences.write("enfuse_pro", "free_contrast_window_size", "integer", 3) + dt.preferences.write("enfuse_pro", "free_contrast_edge_scale", "integer", 1) + dt.preferences.write("enfuse_pro", "free_contrast_min_curvature", "integer", 1) + dt.preferences.write("enfuse_pro", "free_exposure_weight", "float", 0.0) + dt.preferences.write("enfuse_pro", "free_saturation_weight", "float", 0.0) + dt.preferences.write("enfuse_pro", "free_contrast_weight", "float", 0.0) + dt.preferences.write("enfuse_pro", "free_exposure_optimum_weight", "float", 0.0) + dt.preferences.write("enfuse_pro", "free_exposure_width_weight", "float",0.0) + + -- output + dt.preferences.write("enfuse_pro", "selected_output_format", "integer", 1) + dt.preferences.write("enfuse_pro", "initialized", "bool", true) +end + +--GUI +j=0 +local separator1 = dt.new_widget("separator"){} +local separator1b = dt.new_widget("separator"){} +local separator2 = dt.new_widget("separator"){} +local separator2b = dt.new_widget("separator"){} +local label_align_options= dt.new_widget("section_label"){ + label = _('image align options') +} +local label_enfuse_options= dt.new_widget("section_label"){ + label = _('image fusion options') +} +local label_output_format= dt.new_widget("section_label"){ + label = _('target file') +} +local label_path = dt.new_widget("label"){ + label = _('directory'), + ellipsize = "start", + halign = "start" +} +chkbtn_radial_distortion = dt.new_widget("check_button"){ + label = _('optimize radial distortion for all images'), + value = dt.preferences.read("enfuse_pro", "def_radial_distortion", "bool"), + tooltip = _('optimize radial distortion for all images, \nexcept for first'), +} +chkbtn_optimize_field = dt.new_widget("check_button"){ + label = _('optimize field of view for all images'), + value = dt.preferences.read("enfuse_pro", "def_optimize_field", "bool"), + tooltip =_('optimize field of view for all images, except for first. \nUseful for aligning focus stacks (DFF) with slightly \ndifferent magnification.'), +} +chkbtn_optimize_image_center = dt.new_widget("check_button"){ + label = _('optimize image center shift for all images'), + value = dt.preferences.read("enfuse_pro", "def_optimize_image_center", "bool"), + tooltip =_('optimize image center shift for all images, \nexcept for first.'), +} +chkbtn_auto_crop = dt.new_widget("check_button"){ + label = _('auto crop the image'), + value = dt.preferences.read("enfuse_pro", "def_auto_crop", "bool"), + tooltip =_('auto crop the image to the area covered by all images.'), +} +chkbtn_distortion = dt.new_widget("check_button"){ + label = _('load distortion from lens database'), + value = dt.preferences.read("enfuse_pro", "def_distortion", "bool"), + tooltip =_('try to load distortion information from lens database'), +} +chkbtn_hard_masks = dt.new_widget("check_button"){ + label = _('hard mask'), + value = dt.preferences.read("enfuse_pro", "def_hard_masks", "bool"), + tooltip =_('force hard blend masks on the finest scale. this avoids \naveraging of fine details (only), at the expense \nof increasing the noise. this improves the \nsharpness of focus stacks considerably.\ndefault (soft mask)'), + reset_callback = function(self) + self.value = dt.preferences.read("enfuse_pro", "def_hard_masks", "bool") + end +} +chkbtn_save_masks = dt.new_widget("check_button"){ + label = _('save masks'), + value = dt.preferences.read("enfuse_pro", "def_save_masks", "bool"), + tooltip =_('Save the generated weight masks to your home directory,\nenblend saves masks as 8 bit grayscale, \ni.e. single channel images. \nfor accuracy we recommend to choose a lossless format.'), + reset_callback = function(self) + self.value = dt.preferences.read("enfuse_pro", "def_save_masks", "bool") + end +} +chkbtn_cpytags = dt.new_widget("check_button"){ + label = ' Copy Tags', + value = pref_cpytags, + tooltip ='Copy tags from first image.', +} +sldr_exposure_weight = dt.new_widget("slider"){ + label = _('exposure weight'), + tooltip = _('set the relative weight of the well-exposedness criterion \nas defined by the chosen exposure weight function. \nincreasing this weight relative to the others will\n make well-exposed pixels contribute more to\n the final output. \ndefault: (1.0)'), + hard_min = 0, + hard_max = 1, + value = dt.preferences.read("enfuse_pro", "def_exposure_weight", "float") --1 def +} +sldr_saturation_weight = dt.new_widget("slider"){ + label = _('saturation weight'), + tooltip = _('set the relative weight of high-saturation pixels. \nincreasing this weight makes pixels with high \nsaturation contribute more to the final output. \ndefault: (0.2)'), + hard_min = 0, + hard_max = 1, + value = dt.preferences.read("enfuse_pro", "def_saturation_weight", "float"), --0.5 +} +sldr_contrast_weight = dt.new_widget("slider"){ + label = _('contrast weight'), + tooltip = _('sets the relative weight of high local-contrast pixels. \ndefault: (0.0).'), + hard_min = 0, + hard_max = 1, + value = dt.preferences.read("enfuse_pro", "def_contrast_weight", "float")--0 default +} +sldr_exposure_optimum_weight = dt.new_widget("slider"){ + label = _('exposure optimum'), + tooltip = _('determine at what normalized exposure value\n the optimum exposure of the input images\n is. this is, set the position of the maximum\n of the exposure weight curve. use this \noption to fine-tune exposure weighting. \ndefault: (0.5)'), + hard_min = 0, + hard_max = 1, + value = dt.preferences.read("enfuse_pro", "def_exposure_optimum_weight", "float")--0.5 default0 +} +sldr_exposure_width_weight = dt.new_widget("slider"){ + label = _('exposure width'), + tooltip = _('set the characteristic width (FWHM) of the exposure \nweight function. low numbers give less weight to \npixels that are far from the user-defined \noptimum and vice versa. use this option to \nfine-tune exposure weighting. \ndefault: (0.2)'), + hard_min = 0, + hard_max = 1, + value = dt.preferences.read("enfuse_pro", "def_exposure_width_weight", "float") --0.2 default +} +file_chooser_button_path = dt.new_widget("file_chooser_button"){ + title = _('Select export path'), -- The title of the window when choosing a file + is_directory = true, -- True if the file chooser button only allows directories to be selecte + tooltip =_('select the target directory for the fused image. \nthe filename is created automatically.'), +} +chkbtn_source_location = dt.new_widget("check_button"){ + label = _('save to source image location'), + value = true, + tooltip =_('If checked ignores the location below and saves output image(s) to the same location as the source images.'), + reset_callback = function(self) + self.value = true + end +} +cmbx_grid_size = dt.new_widget("combobox"){ + label = _('image grid size'), + tooltip =_('break image into a rectangular grid \nand attempt to find num control points in each section.\ndefault: (5x5)'), + value = dt.preferences.read("enfuse_pro", "def_grid_size", "integer"), --5 + "1", "2", "3","4","5","6","7","8","9", + reset_callback = function(self) + self.value = dt.preferences.read("enfuse_pro", "def_grid_size", "integer") + end +} +cmbx_control_points = dt.new_widget("combobox"){ + label = _('control points/grid'), + tooltip =_('number of control points (per grid, see option -g) \nto create between adjacent images \ndefault: (8).'), + value = dt.preferences.read("enfuse_pro", "def_control_points", "integer"), --8, "1", "2", "3","4","5","6","7","8","9", + "1", "2", "3","4","5","6","7","8","9", + reset_callback = function(self) + self.value = dt.preferences.read("enfuse_pro", "def_control_points", "integer") + end +} +cmbx_control_points_remove = dt.new_widget("combobox"){ + label = _('remove control points with error'), + tooltip =_('remove all control points with an error higher \nthan num pixels \ndefault: (3)'), + value = dt.preferences.read("enfuse_pro", "def_control_points_remove", "integer"), --3, "1", "2", "3","4","5","6","7","8","9", + "1", "2", "3","4","5","6","7","8","9", + reset_callback = function(self) + self.value = dt.preferences.read("enfuse_pro", "def_control_points_remove", "integer") + end +} +cmbx_correlation = dt.new_widget("combobox"){ + label = _('correlation threshold for control points'), + tooltip =_('correlation threshold for identifying \ncontrol points \ndefault: (0.9).'), + value = dt.preferences.read("enfuse_pro", "def_correlation", "integer"), --9, "0,1", "0,2", "0,3","0,4","0,5","0,6","0,7","0,8","0,9", + "0.1", "0.2", "0.3","0.4","0.5","0.6","0.7","0.8","0.9","1.0", + reset_callback = function(self) + self.value = dt.preferences.read("enfuse_pro", "def_correlation", "integer") + end +} +cmbx_contrast_window_size = dt.new_widget("combobox"){ + label = _('contrast window size'), + tooltip =_('set the window size for local contrast analysis. \nthe window will be a square of size × size pixels. \nif given an even size, Enfuse will \nautomatically use the next odd number.\nfor contrast analysis size values larger \nthan 5 pixels might result in a \nblurry composite image. values of 3 and \n5 pixels have given good results on \nfocus stacks. \ndefault: (5) pixels'), + value = dt.preferences.read("enfuse_pro", "def_contrast_window_size", "integer"), --3, "3","4","5","6","7","8","9","10", + "3", "4", "5","6","7","8","9","10", +} +cmbx_contrast_edge_scale = dt.new_widget("combobox"){ + label = _('contrast edge scale'), + tooltip =_('a non-zero value for EDGE-SCALE switches on the \nLaplacian-of-Gaussian (LoG) edge detection algorithm.\n edage-scale is the radius of the Gaussian used \nin the search for edges. a positive LCE-SCALE \nturns on local contrast enhancement (LCE) \nbefore the LoG edge detection. \nDefault: (0.0) pixels.'), + value = dt.preferences.read("enfuse_pro", "def_contrast_edge_scale", "integer"), --1, "0:0:0", + "0.0","0.1","0.2","0.3","0.4","0.5", + +} +cmbx_contrast_min_curvature = dt.new_widget("combobox"){ + label = _('contrast min curvature'), + tooltip =_('define the minimum curvature for the LoG edge detection. Append a ‘%’ to specify the minimum curvature relative to maximum pixel value in the source image. Default: (0.0%)'), + value = dt.preferences.read("enfuse_pro", "def_contrast_min_curvature", "integer"), --1, "0.0%","0.1%", "0.2%", "0.3%","0.4%","0.5%","0.6%","0.7%","0.8%","0.9%","1.0%", + "0.0%", "0.1%", "0.2%","0.3%","0.4%","0.5%","0.6%","0.7%","0.8%","0.9%","1.0%", +} +cmbx_existing_file = dt.new_widget("combobox"){ + label = _('on conflict'), + value = dt.preferences.read("enfuse_pro", "selected_overwrite", "integer"), --1, + sensitive= dt.preferences.read("enfuse_pro", "sentitiv_overwrite", "bool"), --1, + _('create unique filename'),_('overwrite'), + reset_callback = function(self) + self.value = dt.preferences.read("enfuse_pro", "selected_overwrite", "integer") + end +} +cmbx_style = dt.new_widget("combobox"){ + label = "Apply Style on Import", + tooltip = "Apply selected style on auto-import to newly created blended image", + value = 1, + "none", + } +pref_style_enum = 1 +for k=1, (styles_count-1) do + cmbx_style[k+1] = styles[k].name + if styles[k].name == pref_style then pref_style_enum = k+1 end +end +cmbx_style.value = pref_style_enum +chkbtn_image_variations = dt.new_widget("check_button"){ + label = _('create image variants with saved presets'), + value = dt.preferences.read("enfuse_pro", "def_image_variants", "bool"), + tooltip =_('creates image variants with the three \nsaved DRI or DFF presets'), + sensitive=true, + clicked_callback = function(self) + if (self.value) then + dt.preferences.write("enfuse_pro", "def_image_variants", "bool", true) + dt.preferences.write("enfuse_pro", "sentitiv_overwrite", "bool",false) + cmbx_existing_file.value=1 + cmbx_existing_file.sensitive=false + else + dt.preferences.write("enfuse_pro", "def_image_variants", "bool", false) + dt.preferences.write("enfuse_pro", "sentitiv_overwrite", "bool",true) + cmbx_existing_file.sensitive=true + end + end, + reset_callback = function(self) + dt.preferences.write("enfuse_pro", "def_image_variants", "bool", false) + dt.preferences.write("enfuse_pro", "sentitiv_overwrite", "bool",true) + self.value = false + cmbx_existing_file.sensitive=true + end + +} +button_save_preset = dt.new_widget("button"){ + label = _('save fusion preset'), + tooltip =_('save the selected fusion preset'), + clicked_callback = function() + pref_text = "" + if (cmbx_fusion_type.value == "1 - DRI image") then + pref_text = "dri1_" + elseif (cmbx_fusion_type.value == "2 - DRI image") then + pref_text = "dri2_" + elseif (cmbx_fusion_type.value == "3 - DRI image") then + pref_text = "dri3_" + elseif (cmbx_fusion_type.value == "1 - DFF image") then + pref_text = "dff1_" + elseif (cmbx_fusion_type.value == "2 - DFF image") then + pref_text = "dff2_" + elseif (cmbx_fusion_type.value == "3 - DFF image") then + pref_text = "dff3_" + elseif (cmbx_fusion_type.value == "free preset") then + pref_text = "free_" + else + dt.print(_('unkown error')) + end + -- Write Preset + if pref_text ~= "" then + dt.preferences.write("enfuse_pro", pref_text.."hard_masks", "bool", chkbtn_hard_masks.value) + dt.preferences.write("enfuse_pro", pref_text.."save_masks", "bool", chkbtn_save_masks.value) + dt.preferences.write("enfuse_pro", pref_text.."contrast_window_size", "integer", cmbx_contrast_window_size.selected) + dt.preferences.write("enfuse_pro", pref_text.."contrast_edge_scale", "integer", cmbx_contrast_edge_scale.selected) + dt.preferences.write("enfuse_pro", pref_text.."contrast_min_curvature", "integer", cmbx_contrast_min_curvature.selected) + dt.preferences.write("enfuse_pro", pref_text.."exposure_weight", "float", sldr_exposure_weight.value) + dt.preferences.write("enfuse_pro", pref_text.."saturation_weight", "float", sldr_saturation_weight.value) + dt.preferences.write("enfuse_pro", pref_text.."contrast_weight", "float", sldr_contrast_weight.value) + dt.preferences.write("enfuse_pro", pref_text.."exposure_optimum_weight", "float", sldr_exposure_optimum_weight.value) + dt.preferences.write("enfuse_pro", pref_text.."exposure_width_weight", "float",sldr_exposure_width_weight.value) + dt.print(_('preset '..pref_text..' saved')) + end + end +} +button_load_preset = dt.new_widget("button"){ + label = _('load fusion defaults'), + tooltip =_('load the default fusion settings'), + clicked_callback = function() + chkbtn_hard_masks.value=dt.preferences.read("enfuse_pro", "def_hard_masks", "bool") + chkbtn_save_masks.value=dt.preferences.read("enfuse_pro", "def_save_masks", "bool") + cmbx_contrast_window_size.value=dt.preferences.read("enfuse_pro", "def_contrast_window_size", "integer") + cmbx_contrast_edge_scale.value=dt.preferences.read("enfuse_pro", "def_contrast_edge_scale", "integer") + cmbx_contrast_min_curvature.value=dt.preferences.read("enfuse_pro", "def_contrast_min_curvature", "integer") + sldr_exposure_weight.value=dt.preferences.read("enfuse_pro", "def_exposure_weight", "float") + sldr_saturation_weight.value=dt.preferences.read("enfuse_pro", "def_saturation_weight", "float") + sldr_contrast_weight.value=dt.preferences.read("enfuse_pro", "def_contrast_weight", "float") + sldr_exposure_optimum_weight.value=dt.preferences.read("enfuse_pro", "def_exposure_optimum_weight", "float") + sldr_exposure_width_weight.value=dt.preferences.read("enfuse_pro", "def_exposure_width_weight", "float") + end + +} +cmbx_output_format = dt.new_widget("combobox"){ + label = _('file format'), + value = dt.preferences.read("enfuse_pro", "selected_output_format", "integer"), --1, "TIFF", "JPEG", "PNG","PNM","PBM","PGM","PPM", + changed_callback = function(self) + dt.preferences.write("enfuse_pro", "selected_output_format", "integer", self.selected) + end, + "TIFF", "JPEG", "PNG","PNM","PBM","PPM", + reset_callback = function(self) + self.value = dt.preferences.read("enfuse_pro", "selected_output_format", "integer") + end +} +cmbx_fusion_type = dt.new_widget("combobox"){ + label = _('fusion preset'), + tooltip =_('select the preset and save the preset\n if you want to reuse it or create an image\n variant'), + value = 1, --dt.preferences.read("enfuse_pro", "def_fusion_type", "integer"), --1, "DRI image", "DFF image", "without preset", + changed_callback = function(self) + dt.preferences.write("enfuse_pro", "def_fusion_type", "integer", self.selected) + + if (self.value == "1 - DRI image") then + pref_text = "dri1_" + elseif (self.value == "2 - DRI image") then + pref_text = "dri2_" + elseif (self.value == "3 - DRI image") then + pref_text = "dri3_" + elseif (self.value == "1 - DFF image") then + pref_text = "dff1_" + elseif (self.value == "2 - DFF image") then + pref_text = "dff2_" + elseif (self.value == "3 - DFF image") then + pref_text = "dff3_" + elseif (self.value == "free preset") then + pref_text = "free_" + end + + if string.match(pref_text,"^dri")~=nil then + chkbtn_hard_masks.sensitive=false + chkbtn_hard_masks.value=false + sldr_contrast_weight.sensitive=true + elseif string.match(pref_text,"^dff")~=nil then + chkbtn_hard_masks.sensitive=false + chkbtn_hard_masks.value=true + sldr_contrast_weight.sensitive=false + else + chkbtn_hard_masks.sensitive=true + chkbtn_hard_masks.value=false + sldr_contrast_weight.sensitive=true + end + + chkbtn_hard_masks.value=dt.preferences.read("enfuse_pro", pref_text.."hard_masks", "bool") + chkbtn_save_masks.value=dt.preferences.read("enfuse_pro", pref_text.."save_masks", "bool") + cmbx_contrast_window_size.value=dt.preferences.read("enfuse_pro", pref_text.."contrast_window_size", "integer") + cmbx_contrast_edge_scale.value=dt.preferences.read("enfuse_pro", pref_text.."contrast_edge_scale", "integer") + cmbx_contrast_min_curvature.value=dt.preferences.read("enfuse_pro", pref_text.."contrast_min_curvature", "integer") + sldr_exposure_weight.value=dt.preferences.read("enfuse_pro", pref_text.."exposure_weight", "float") + sldr_saturation_weight.value=dt.preferences.read("enfuse_pro", pref_text.."saturation_weight", "float") + sldr_contrast_weight.value=dt.preferences.read("enfuse_pro", pref_text.."contrast_weight", "float") + sldr_exposure_optimum_weight.value=dt.preferences.read("enfuse_pro", pref_text.."exposure_optimum_weight", "float") + sldr_exposure_width_weight.value=dt.preferences.read("enfuse_pro", pref_text.."exposure_width_weight", "float") + + end, + "1 - DRI image", "2 - DRI image","3 - DRI image","1 - DFF image", "2 - DFF image","3 - DFF image","free preset", + + reset_callback = function(self_type) + cmbx_fusion_type.value = dt.preferences.read("enfuse_pro", "def_fusion_type", "integer") + end +} +entry_tag = dt.new_widget("entry"){ + tooltip = "Additional tags to be added on import. Seperate with commas, all spaces will be removed", + text = pref_addtags, + placeholder = "Enter tags, seperated by commas", + editable = true +} +local widget = dt.new_widget("box") { + orientation = "vertical", + label_align_options, + chkbtn_radial_distortion, + chkbtn_optimize_field, + chkbtn_optimize_image_center, + chkbtn_auto_crop, + chkbtn_distortion, + cmbx_grid_size, + cmbx_control_points, + cmbx_control_points_remove, + cmbx_correlation, + separator1, + separator1b, + label_enfuse_options, + cmbx_fusion_type, + chkbtn_image_variations, + sldr_exposure_weight, + sldr_saturation_weight, + sldr_contrast_weight, + sldr_exposure_optimum_weight, + sldr_exposure_width_weight, + chkbtn_hard_masks, + chkbtn_save_masks, + cmbx_contrast_edge_scale, + cmbx_contrast_min_curvature, + cmbx_contrast_window_size, + button_save_preset, + button_load_preset, + separator2, + separator2b, + label_output_format, + cmbx_output_format, + label_path, + file_chooser_button_path, + chkbtn_source_location, + cmbx_existing_file, + cmbx_style, + chkbtn_cpytags, + entry_tag, +} + +-- FUNCTION -- +local function GetFileName(full_path) + --[[Parses a full path (path/filename_identifier.extension) into individual parts + Input: Folder1/Folder2/Folder3/Img_0001.CR2 + + Returns: + path: Folder1/Folder2/Folder3/ + filename: Img_0001 + identifier: 0001 + extension: .CR2 + + EX: + path_1, file_1, id_1, ext_1 = GetFileName(full_path_1) + ]] + local path = string.match(full_path, ".*[\\/]") + local filename = string.gsub(string.match(full_path, "[%w-_]*%.") , "%." , "" ) + local identifier = string.match(filename, "%d*$") + local extension = string.match(full_path, "%.%w*") + return path, filename, identifier, extension +end +local function truncate(x) + return x<0 and math.ceil(x) or math.floor(x) +end +local function replace_comma_to_dot(s) + return string.gsub(s, "%,", ".") +end +local function file_exists(name) + local f=io.open(""..name.."","r") + if f~=nil then + io.close(f) + return true + else + return false + end +end +local function remove_temp_files() + if dt.configuration.running_os == "windows" then + dt.print_log("Deleting temp files...") + dt.control.execute("del "..images_to_align) + dt.control.execute("del "..images_to_blend) + dt.print_log("Done deleting") + else + dt.print_log("Deleting temp files...") + dt.control.execute("rm "..images_to_align) + dt.control.execute("rm "..images_to_blend) + dt.print_log("Done deleting") + end + + --[[ + dt.print_error("rm "..images_to_align) + result_to_align_images=dt.control.execute("rm "..images_to_align) + dt.print_error("rm "..tmppath.."/aligned_*.tif") + result_aligned_images=dt.control.execute("rm "..tmppath.."/aligned_*.tif") + ]] +end +local function build_execute_command(cmd, args, file_list) + local result = false + + if dt.configuration.running_os == "macos" then + cmd = string.gsub(cmd, "open", "", 1) + cmd = string.gsub(cmd, "-W", "", 1) + cmd = string.gsub(cmd, "-a", "", 1) + -- result = cmd.." "..file_list.." "..args + --else + -- result = cmd..""..args.." "..file_list + end + result = cmd.." "..args.." "..file_list + return result +end +function copy_exif() + exiftool_path = string.gsub(exiftool_path, "open", "") + exiftool_path = string.gsub(exiftool_path, "-W", "") + exiftool_path = string.gsub(exiftool_path, "-a", "") + exifStartCommand = exiftool_path.." -TagsFromFile "..source_file.." -exif:all --subifd:all -overwrite_original "..path_with_filename + dt.print_log("EXIFTool Start Command: "..exifStartCommand) + resultexif=dt.control.execute(exifStartCommand) + if (resultexif == 0) then + dt.print_log("EXIFTool copy successful") + dt.print("Copied EXIF data") + else + dt.print(_('ERROR: exiftool doesn\'t work. for more informations see terminal output')) + dt.print_error("exif copy failed") + end +end +function align_images() + dt.print(_('aligning images')) + + --Setup Align Image Stack Arguments-- + align_args = "" + if (chkbtn_radial_distortion.value) then align_args = align_args.." -d" end + if (chkbtn_optimize_field.value) then align_args = align_args.." -m" end + if (chkbtn_optimize_image_center.value) then align_args = align_args.." -i" end + if (chkbtn_auto_crop.value) then align_args = align_args.." -C" end + if (chkbtn_distortion.value) then align_args = align_args.." --distortion" end + align_args = align_args.." -g "..cmbx_grid_size.value + align_args = align_args.." -c "..cmbx_control_points.value + align_args = align_args.." -t "..cmbx_control_points_remove.value + align_args = align_args.." --corr="..cmbx_correlation.value + if (dt.preferences.read("module_enfuse_pro", "align_use_gpu", "bool")) then align_args = align_args.." --gpu" end + + align_args = align_args.." -a "..first_path.."aligned_ " + alignStartCommand = build_execute_command(AIS_path, align_args, images_to_align) + dt.print_log("Align Start Command: "..alignStartCommand) + resp = dt.control.execute(alignStartCommand) + dt.print_log("Completed Align") + return resp +end +function blend_images() + blend_args = "" + if from_preset then --load args from preset preferences + blend_args=blend_args.." --exposure-weight="..(replace_comma_to_dot(dt.preferences.read("enfuse_pro", preset_text.."_exposure_weight", "float"))) + blend_args=blend_args.." --saturation-weight="..(replace_comma_to_dot(dt.preferences.read("enfuse_pro", preset_text.."_saturation_weight", "float"))) + blend_args=blend_args.." --contrast-weight="..(replace_comma_to_dot(dt.preferences.read("enfuse_pro", preset_text.."_contrast_weight", "float"))) + blend_args=blend_args.." --exposure-optimum="..(replace_comma_to_dot(dt.preferences.read("enfuse_pro", preset_text.."_exposure_optimum_weight", "float"))) + blend_args=blend_args.." --exposure-width="..(replace_comma_to_dot(dt.preferences.read("enfuse_pro", preset_text.."_exposure_width_weight", "float"))) + if (chkbtn_hard_masks.value) then blend_args=blend_args.."--hard-mask" end + if (chkbtn_save_masks.value) then blend_args=blend_args.."--save-masks" end + blend_args=blend_args.." --contrast-window-size="..dt.preferences.read("enfuse_pro", preset_text.."_contrast_window_size", "integer") + blend_args=blend_args.." --contrast-edge-scale="..dt.preferences.read("enfuse_pro", preset_text.."_contrast_edge_scale", "integer") + blend_args=blend_args.." --contrast-min-curvature="..dt.preferences.read("enfuse_pro", preset_text.."_contrast_min_curvature", "integer") + blend_args=blend_args.." --depth="..dt.preferences.read("module_enfuse_pro", "image_color_depth", "enum") + else --load args from GUI values + blend_args = blend_args.." --exposure-weight="..(replace_comma_to_dot(sldr_exposure_weight.value)) + blend_args = blend_args.." --saturation-weight="..(replace_comma_to_dot(sldr_saturation_weight.value)) + blend_args = blend_args.." --contrast-weight="..(replace_comma_to_dot(sldr_contrast_weight.value)) + blend_args = blend_args.." --exposure-optimum="..(replace_comma_to_dot(sldr_exposure_optimum_weight.value)) + blend_args = blend_args.." --exposure-width="..(replace_comma_to_dot(sldr_exposure_width_weight.value)) + if (chkbtn_hard_masks.value) then blend_args = blend_args.." --hard-mask" end + if (chkbtn_save_masks.value) then blend_args = blend_args.." --save-masks" end + blend_args = blend_args.." --contrast-window-size="..cmbx_contrast_window_size.value + blend_args = blend_args.." --contrast-edge-scale="..cmbx_contrast_edge_scale.value + blend_args = blend_args.." --contrast-min-curvature="..cmbx_contrast_min_curvature.value + blend_args = blend_args.." --depth="..dt.preferences.read("module_enfuse_pro", "image_color_depth", "enum") + end + + --set output format per GUI selection + if (cmbx_output_format.value == "TIFF") then + cmd_suffix_output_format="tif" + blend_args = blend_args.." --compression="..dt.preferences.read("module_enfuse_pro", "compression_tiff", "enum") + elseif (cmbx_output_format.value == "JPEG") then + cmd_suffix_output_format="jpg" + blend_args = blend_args.." --compression="..truncate(dt.preferences.read("module_enfuse_pro", "compression_jpeg", "integer")) + elseif (cmbx_output_format.value == "PNG") then + cmd_suffix_output_format="png" + elseif (cmbx_output_format.value == "PNM") then + cmd_suffix_output_format="pnm" + elseif (cmbx_output_format.value == "PBM") then + cmd_suffix_output_format="pbm" + elseif (cmbx_output_format.value == "PPM") then + cmd_suffix_output_format="ppm" + end + + --Set output path and add filename + if (chkbtn_source_location.value) then + cmd_output_path = source_path + else + cmd_output_path=file_chooser_button_path.value --FUTURE FEATURE: add gui option for "same as source images" + end + path_with_filename = cmd_output_path..os_path_seperator..first_filename.."-"..last_id.."."..cmd_suffix_output_format + + --Create unique name with index if GUI selection create unique name (don't overwrite), also do this if user selected to make variants from presets + if (cmbx_existing_file.selected == 1) or (from_preset) then + cmd_output_image_index=0 + while (file_exists(path_with_filename)) do + cmd_output_image_index = cmd_output_image_index+1 + if cmd_output_image_index <= 9 then + outputindex="0"..tostring(cmd_output_image_index) + else + outputindex=tostring(cmd_output_image_index) + end + path_with_filename = cmd_output_path..os_path_seperator..first_filename.."-"..last_id.."-"..outputindex.."."..cmd_suffix_output_format + end + end + cmd_output_image = " --output="..path_with_filename + blend_args = blend_args..cmd_output_image + + --images_to_blend = first_path.."aligned_*.tif" + images_to_blend = "" + for j=0, counted_images-1 do + if j < 10 then + id = "000"..tostring(j) + else + id = "00"..tostring(j) + end + images_to_blend = images_to_blend..first_path.."aligned_"..id..".tif " + end + + BlendStartCommand=build_execute_command(enfuse_path, blend_args, images_to_blend) + + dt.print_log("Blend Start Command: "..BlendStartCommand) + resultBlend=dt.control.execute(BlendStartCommand) + dt.print_log("Completed Blend") + + return resultBlend, path_with_filename +end +local function show_status(storage, image, format, filename, --Store: Called on each exported image + number, total, high_quality, extra_data) + dt.print(_('export TIFF for image fusion ')..tostring(truncate(number)).." / "..tostring(truncate(total))) +end +function create_image_fusion(storage, image_table, extra_data) --Finalize: Called once when all images are done exporting +--Create Images String-- + images_to_align = "" + images_to_blend = "" + counted_images=0 + first_id = "999999999999999999999999" + last_id = "0" + for source_image,image_path in pairs(image_table) do + counted_images=counted_images+1 + images_to_align = images_to_align..image_path.." " + curr_path, curr_filename, curr_id, curr_ext = GetFileName(image_path) + if (curr_id < first_id) then + first_path = curr_path + first_filename = curr_filename + first_id = curr_id + first_ext = curr_ext + dt_source_image = source_image + end + if (curr_id > last_id) then + last_path = curr_path + last_filename = curr_filename + last_id = curr_id + last_ext = curr_ext + end + source_path = source_image.path + source_file = source_image.path..os_path_seperator..source_image.filename + end + +--Check if at least 2 images selected-- + if (counted_images<=1) then + dt.print(_('ERROR: not enough pictures selected. please select two or more images\nfrom the same object, but with different camera settings.')) + dt.print_error("Not enough pictures selected") + remove_temp_files() + return + end + +--Ensure Required Software is Installed-- + df.set_executable_path_preference("align_image_stack", dt.preferences.read("module_enfuse_pro", "ais_path", "string")) + dt.print_log("Executable Path Preference: "..df.get_executable_path_preference("align_image_stack")) + AIS_path = df.check_if_bin_exists("align_image_stack") + if not AIS_path then + dt.print_error("align image stack not found") + dt.print("ERROR - align image stack not found") + remove_temp_files() + return + end + + df.set_executable_path_preference("enfuse", dt.preferences.read("module_enfuse_pro", "enfuse_path", "string")) + dt.print_log("Executable Path Preference: "..df.get_executable_path_preference("enfuse")) + enfuse_path = df.check_if_bin_exists("enfuse") + if not enfuse_path then + dt.print_error("enfuse not found") + dt.print("ERROR - enfuse not found") + remove_temp_files() + return + end + + df.set_executable_path_preference("exiftool", dt.preferences.read("module_enfuse_pro", "exiftool_path", "string")) + dt.print_log("Executable Path Preference: "..df.get_executable_path_preference("exiftool")) + exiftool_path = df.check_if_bin_exists("exiftool") + if not exiftool_path then + dt.print_error("exiftool not found") + dt.print("ERROR - exiftool not found") + remove_temp_files() + return + end + +--Ensure proper version of Enfuse installed-- + --[[ + enfuseVersionStartCommand='enfuse --version | grep "enfuse 4.2"' + enfuse_version=dt.control.execute(enfuseVersionStartCommand) + if (enfuse_version ~= 0) then + dt.print(_('ERROR: wrong enfuse version found. the plugin works only with enfuse 4.2! please install enfuse version 4.2')) + return + end]] + +--Check that output path selected + cmd_output_path = file_chooser_button_path.value + if (cmd_output_path == nil) and not(chkbtn_source_location.value) then + dt.print(_('ERROR: no target directory selected')) + remove_temp_files() + return + end + + dt.print_log("Starting Image Fusion") + job = dt.gui.create_job(_('Creating DRI/DFF image'), true, stop_selection) + + percent_step = .33 + if (chkbtn_image_variations.value) then percent_step = .2 end + job.percent = job.percent + percent_step + +--Align Images-- + resultalign = align_images() + if (resultalign ~= 0) then --Aling Image Stack Failed-- + dt.print(_('ERROR: align_image_stack doesn\'t work. For more information see terminal output')) + dt.print_error("Align Image Stack Failed") + remove_temp_files() + job.valid = false + return + end + dt.print(_('aligning complete')) + job.percent = job.percent + percent_step + +--Blend Images-- + from_preset = false + iterations = 1 + pref_text = "" + if (chkbtn_image_variations.value) then + iterations = 3 + from_preset = true + if string.match(cmbx_fusion_type.value, "DRI") then + pref_text = "dri" + elseif string.match(cmbx_fusion_type.value, "DFF") then + pref_text = "dff" + else --if "variants" selected, but not using DRI or DFF preset then cannot create variants + dt.print("Error, must select a DRI or DFF preset when starting a fustion with variants") + dt.print_error("DRI or DFF preset not selected when variants option was checked") + remove_temp_files() + job.valid = false + return + end + end + + for j = 1, iterations do + if (from_preset) then + preset_text=pref_text..j + else + preset_text="" + end + resultBlend, blended_image = blend_images() --Check here to ensure enfuse worked properly + if resultBlend ~= 0 then + dt.print(_('ERROR: enfuse didn\'t work. For more information see terminal output')) + dt.print_error("Enfuse failed") + remove_temp_files() + job.valid = false + return + end + --Copy EXIF Data (IF)-- + if (dt.preferences.read("module_enfuse_pro", "exiftool_copy_tags", "bool")) then copy_exif() end + --Auto-Import-- + if (dt.preferences.read("module_enfuse_pro", "add_image_to_db", "bool")) then + local imported = dt.database.import(path_with_filename) + --Apply Selected Style (IF)-- + if cmbx_style.selected > 1 then + set_style = styles[cmbx_style.selected - 1] + dt.styles.apply(set_style , imported) + end + --Copy Tags (IF)-- + if (chkbtn_cpytags.value) then + all_tags = dt.tags.get_tags(dt_source_image) + for _,tag in pairs(all_tags) do + if string.match(tag.name, 'darktable|') == nil then + dt.tags.attach(tag, imported) + end + end + end + --Apply Entered Tags (IF)-- + set_tag = entry_tag.text + if set_tag ~= nil then + for tag in string.gmatch(set_tag, '[^,]+') do + tag = string.gsub(tag, " ", "") + tag = dt.tags.create(tag) + dt.tags.attach(tag, imported) + end + end + end + job.percent = job.percent + percent_step + end + + --Copy EXIF Data (IF)-- + + remove_temp_files() + dt.print("Image fusion process complete") + dt.print_log("Image fusion process complete") + job.valid = false +end +local function support_format(storage, format) --Supported: Check to make sure image type is supported by darktable + fmt = string.lower(format.name) + if string.match(fmt,"tiff") == nil then + return false + else + return true + end +end + +-- REGISTER -- +dt.register_storage("module_enfuse_pro", _('DRI or DFF image'), show_status, create_image_fusion, support_format, nil, widget) + +-- PREFERENCES -- +entry_widget_style = dt.new_widget("entry"){ + tooltip = "Enter the style name exactly as it is", + text = nil, + placeholder = "Enter Style name", + editable = true +} +dt.preferences.register("module_enfuse_pro", "style", -- name + "string", -- type + 'enfuse_pro: Defualt Style', -- label + 'Changes DEFAULT entry in the Style option. Requires restart to take effect.', -- tooltip + "", -- default + entry_widget_style +) +entry_widget_tags = dt.new_widget("entry"){ + tooltip = "Seperate with commas, all spaces will be removed", + text = nil, + placeholder = "Enter default tags", + editable = true +} +dt.preferences.register("module_enfuse_pro", "add_tags", -- name + "string", -- type + 'enfuse_pro: Defualt additional tags', -- label + 'Changes DEFAULT entry in the additional tags option. Requires restart to take effect.', -- tooltip + "", -- default + entry_widget_tags +) +dt.preferences.register("module_enfuse_pro", "copy_tags", -- name + "bool", -- type + 'enfuse_pro: Copy tags from first image by default', -- label + 'Changes DEFAULT selection for Copy Tags, Requires restart to take effect.', -- tooltip + true -- default +) +dt.preferences.register("module_enfuse_pro", "exiftool_copy_tags", -- name + "bool", -- type + _('enfuse pro: copy exif data'), -- label + _('copy the exif tags from the first image to the target'), -- tooltip + true) -- default +dt.preferences.register("module_enfuse_pro", "add_image_to_db", -- name + "bool", -- type + _('enfuse pro: add fused image to database'), -- label + _('add the fused image to the darktable database'), -- tooltip + false) -- default +dt.preferences.register("module_enfuse_pro", "align_use_gpu", -- name + "bool", -- type + _('enfuse pro: use GPU for remaping'), -- label + _('set the GPU remapping for image align'), -- tooltip + false) +dt.preferences.register("module_enfuse_pro", "compression_jpeg", -- name + "integer", -- type + _('enfuse pro: JPEG compression'), -- label + _('set the compression for JPEG files'), -- tooltip + 98, -- default + 50, -- min + 100) -- max +dt.preferences.register("module_enfuse_pro", "compression_tiff", -- name + "enum", -- type + _('enfuse pro: TIFF compression'), -- label + _('set the compression type for tiff files'), -- tooltip + "LZW", -- default + "NONE", "DEFLATE","PACKBITS") -- va +dt.preferences.register("module_enfuse_pro", "image_color_depth", -- name + "enum", -- type + _('enfuse pro: image color depth (bit)'), -- label + _('set the output color depth'), -- tooltip + "16", -- default + "8","32","r32","r64") -- values + +--AIS bin location +AIS_path = df.get_executable_path_preference("align_image_stack") +if not AIS_path then + AIS_path = "" +end +AIS_path_widget = dt.new_widget("file_chooser_button"){ + title = "Select align_image_stack[.exe] file", + value = AIS_path, + is_directory = false, +} +dt.preferences.register("module_enfuse_pro", "ais_path", -- name + "file", -- type + 'enfuse_pro: Align Image Stack Location', -- label + 'Install location of align_image_stack. Requires restart to take effect.', -- tooltip + "align_image_stack", -- default + AIS_path_widget +) + +--enfuse bin location +enfuse_path = df.get_executable_path_preference("enfuse") +if not enfuse_path then + enfuse_path = "" +end +enfuse_path_widget = dt.new_widget("file_chooser_button"){ + title = "Select enfuse[.exe] file", + value = enfuse_path, + is_directory = false, +} +dt.preferences.register("module_enfuse_pro", "enfuse_path", -- name + "file", -- type + 'enfuse_pro: enfuse Location', -- label + 'Install location of enfuse. Requires restart to take effect.', -- tooltip + "enfuse", -- default + enfuse_path_widget +) + +--exiftool bin location +exiftool_path = df.get_executable_path_preference("exiftool") +if not exiftool_path then + exiftool_path = "" +end +exiftool_path_widget = dt.new_widget("file_chooser_button"){ + title = "Select exiftool[.exe] file", + value = exiftool_path, + is_directory = false, +} +dt.preferences.register("module_enfuse_pro", "exiftool_path", -- name + "file", -- type + 'enfuse_pro: exiftool Location', -- label + 'Install location of exiftool. Requires restart to take effect.', -- tooltip + "exiftool", -- default + exiftool_path_widget +) + From 050783fc8b176b4f0f84613935180cf2cd0dd130 Mon Sep 17 00:00:00 2001 From: BzKevin <36381472+BzKevin@users.noreply.github.com> Date: Sat, 7 Jul 2018 11:40:01 -0400 Subject: [PATCH 6/9] enfuse_pro_2 modified per wpferguson 1) Moved check_if_bin installed to run only once, when script first loaded (rather than every time it is called) 2) Changed executable path preferences per Bill's suggestions dt.preferences.register("executable_paths", "align_image_stack", dt.preferences.register("executable_paths", "enfuse", dt.preferences.register("executable_paths", "exiftool", 3) Replaced custom block of code with df.create_unique_filename 4) Quoted paths in run commands for linux and MacOS (I still experience failures if I quote anything in the run command aside from the .exe path on windows) 5) Changed LUA API compatability check for 5.0.0 only Tested on Windows and MacOS --- contrib/enfuse_pro_2.lua | 186 +++++++++++++++++---------------------- 1 file changed, 81 insertions(+), 105 deletions(-) diff --git a/contrib/enfuse_pro_2.lua b/contrib/enfuse_pro_2.lua index f03d3b5..b2624df 100644 --- a/contrib/enfuse_pro_2.lua +++ b/contrib/enfuse_pro_2.lua @@ -1,4 +1,5 @@ ---[[Enfuse professional plugin for darktable 2.2.X and 2.4.X +--[[ + Enfuse professional plugin for darktable 2.2.X and 2.4.X copyright (c) 2017, 2018 Holger Klemm (Original Linux-only version) @@ -26,16 +27,17 @@ ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT USAGE * require this file from your main luarc config file. +* On the initial startup go to darktable settings > lua options and set your executable paths and other preferences, then restart darktable -This plugin will add the new export modul "fusion to DRI or DFF image". +This plugin will add the new export module "fusion to DRI or DFF image". ]] local dt = require "darktable" local df = require "lib/dtutils.file" local gettext = dt.gettext --- works with LUA API version 4.0.0 and 5.0.0 -dt.configuration.check_version(...,{4,0,0},{5,0,0}) +-- works with LUA API version 5.0.0 +dt.configuration.check_version(...,{5,0,0}) -- Tell gettext where to find the .mo file translating messages for a particular domain gettext.bindtextdomain("enfuse_pro",dt.configuration.config_dir.."/lua/") @@ -55,28 +57,46 @@ end pref_style = dt.preferences.read("module_enfuse_pro", "style", "string") pref_cpytags = dt.preferences.read("module_enfuse_pro", "copy_tags", "bool") pref_addtags = dt.preferences.read("module_enfuse_pro", "add_tags", "string") ---[[ -cmd_tmp_path="" -cmd_output_path="" -cmd_output_image="" -cmd_output_image_index = 0 -path_with_filename="" -homepath=os.getenv("Public") -tmppath=homepath.."/.local/tmp" -cmd_exif_copy_exif="" -cmd_suffix_output_format="" -alignStartCommand="" -enfuseStartCommand="" -exifStartCommand="" -outputindex = 0 -job = 0 -]] if dt.configuration.running_os == "windows" then os_path_seperator = "\\" else os_path_seperator = "/" end +--Ensure Required Software is Installed-- +not_installed = 0 +dt.print_log("enfuse_pro_2 - Executable Path Preference: "..df.get_executable_path_preference("align_image_stack")) +local AIS_path = df.check_if_bin_exists("align_image_stack") +if not AIS_path then + dt.print_error("align image stack not found") + dt.print("ERROR - align image stack not found") + not_installed = 1 +end + +dt.print_log("enfuse_pro_2 - Executable Path Preference: "..df.get_executable_path_preference("enfuse")) +local enfuse_path = df.check_if_bin_exists("enfuse") +if not enfuse_path then + dt.print_error("enfuse not found") + dt.print("ERROR - enfuse not found") + not_installed = 1 +end + +dt.print_log("enfuse_pro_2 - Executable Path Preference: "..df.get_executable_path_preference("exiftool")) +local exiftool_path = df.check_if_bin_exists("exiftool") +if not exiftool_path then + dt.print_error("exiftool not found") + dt.print("ERROR - exiftool not found") + not_installed = 1 +end + +--Ensure proper version of Enfuse installed-- + --[[ + enfuseVersionStartCommand='enfuse --version | grep "enfuse 4.2"' + enfuse_version=dt.control.execute(enfuseVersionStartCommand) + if (enfuse_version ~= 0) then + dt.print(_('ERROR: wrong enfuse version found. the plugin works only with enfuse 4.2! please install enfuse version 4.2')) + not_installed = 1 + end]] -- align defaults --dt.preferences.write("enfuse_pro", "initialized", "bool", false) @@ -565,15 +585,6 @@ end local function replace_comma_to_dot(s) return string.gsub(s, "%,", ".") end -local function file_exists(name) - local f=io.open(""..name.."","r") - if f~=nil then - io.close(f) - return true - else - return false - end -end local function remove_temp_files() if dt.configuration.running_os == "windows" then dt.print_log("Deleting temp files...") @@ -586,24 +597,14 @@ local function remove_temp_files() dt.control.execute("rm "..images_to_blend) dt.print_log("Done deleting") end - - --[[ - dt.print_error("rm "..images_to_align) - result_to_align_images=dt.control.execute("rm "..images_to_align) - dt.print_error("rm "..tmppath.."/aligned_*.tif") - result_aligned_images=dt.control.execute("rm "..tmppath.."/aligned_*.tif") - ]] end local function build_execute_command(cmd, args, file_list) local result = false if dt.configuration.running_os == "macos" then - cmd = string.gsub(cmd, "open", "", 1) - cmd = string.gsub(cmd, "-W", "", 1) - cmd = string.gsub(cmd, "-a", "", 1) - -- result = cmd.." "..file_list.." "..args - --else - -- result = cmd..""..args.." "..file_list + cmd = string.gsub(cmd, "open", "") + cmd = string.gsub(cmd, "-W", "") + cmd = string.gsub(cmd, "-a", "") end result = cmd.." "..args.." "..file_list return result @@ -612,7 +613,11 @@ function copy_exif() exiftool_path = string.gsub(exiftool_path, "open", "") exiftool_path = string.gsub(exiftool_path, "-W", "") exiftool_path = string.gsub(exiftool_path, "-a", "") - exifStartCommand = exiftool_path.." -TagsFromFile "..source_file.." -exif:all --subifd:all -overwrite_original "..path_with_filename + if dt.configuration.running_os == "windows" then + exifStartCommand = exiftool_path.." -TagsFromFile "..source_file.." -exif:all --subifd:all -overwrite_original "..path_with_filename + else + exifStartCommand = exiftool_path.." -TagsFromFile "..'"'..source_file..'"'.." -exif:all --subifd:all -overwrite_original "..'"'..path_with_filename..'"' + end dt.print_log("EXIFTool Start Command: "..exifStartCommand) resultexif=dt.control.execute(exifStartCommand) if (resultexif == 0) then @@ -638,8 +643,11 @@ function align_images() align_args = align_args.." -t "..cmbx_control_points_remove.value align_args = align_args.." --corr="..cmbx_correlation.value if (dt.preferences.read("module_enfuse_pro", "align_use_gpu", "bool")) then align_args = align_args.." --gpu" end - - align_args = align_args.." -a "..first_path.."aligned_ " + if dt.configuration.running_os == "windows" then + align_args = align_args.." -a "..first_path.."aligned_ " + else + align_args = align_args.." -a "..'"'..first_path..'aligned_" ' + end alignStartCommand = build_execute_command(AIS_path, align_args, images_to_align) dt.print_log("Align Start Command: "..alignStartCommand) resp = dt.control.execute(alignStartCommand) @@ -695,27 +703,23 @@ function blend_images() if (chkbtn_source_location.value) then cmd_output_path = source_path else - cmd_output_path=file_chooser_button_path.value --FUTURE FEATURE: add gui option for "same as source images" + cmd_output_path=file_chooser_button_path.value end path_with_filename = cmd_output_path..os_path_seperator..first_filename.."-"..last_id.."."..cmd_suffix_output_format --Create unique name with index if GUI selection create unique name (don't overwrite), also do this if user selected to make variants from presets - if (cmbx_existing_file.selected == 1) or (from_preset) then - cmd_output_image_index=0 - while (file_exists(path_with_filename)) do - cmd_output_image_index = cmd_output_image_index+1 - if cmd_output_image_index <= 9 then - outputindex="0"..tostring(cmd_output_image_index) - else - outputindex=tostring(cmd_output_image_index) - end - path_with_filename = cmd_output_path..os_path_seperator..first_filename.."-"..last_id.."-"..outputindex.."."..cmd_suffix_output_format - end + if (cmbx_existing_file.selected == 1) or (from_preset) then + path_with_filename = df.create_unique_filename(path_with_filename) + end + + if dt.configuration.running_os == "windows" then + cmd_output_image = " --output="..path_with_filename + else + cmd_output_image = " --output="..'"'..path_with_filename..'"' + end - cmd_output_image = " --output="..path_with_filename blend_args = blend_args..cmd_output_image - --images_to_blend = first_path.."aligned_*.tif" images_to_blend = "" for j=0, counted_images-1 do if j < 10 then @@ -723,9 +727,12 @@ function blend_images() else id = "00"..tostring(j) end - images_to_blend = images_to_blend..first_path.."aligned_"..id..".tif " + if dt.configuration.running_os == "windows" then + images_to_blend = images_to_blend..first_path.."aligned_"..id..".tif " + else + images_to_blend = images_to_blend..'"'..first_path.."aligned_"..id..".tif"..'" ' + end end - BlendStartCommand=build_execute_command(enfuse_path, blend_args, images_to_blend) dt.print_log("Blend Start Command: "..BlendStartCommand) @@ -747,7 +754,11 @@ function create_image_fusion(storage, image_table, extra_data) --Finalize: Calle last_id = "0" for source_image,image_path in pairs(image_table) do counted_images=counted_images+1 - images_to_align = images_to_align..image_path.." " + if dt.configuration.running_os == "windows" then + images_to_align = images_to_align..image_path..' ' + else + images_to_align = images_to_align..'"'..image_path..'" ' + end curr_path, curr_filename, curr_id, curr_ext = GetFileName(image_path) if (curr_id < first_id) then first_path = curr_path @@ -774,45 +785,13 @@ function create_image_fusion(storage, image_table, extra_data) --Finalize: Calle return end ---Ensure Required Software is Installed-- - df.set_executable_path_preference("align_image_stack", dt.preferences.read("module_enfuse_pro", "ais_path", "string")) - dt.print_log("Executable Path Preference: "..df.get_executable_path_preference("align_image_stack")) - AIS_path = df.check_if_bin_exists("align_image_stack") - if not AIS_path then - dt.print_error("align image stack not found") - dt.print("ERROR - align image stack not found") +--Ensure Proper Software Installed-- + if not_installed == 1 then + dt.print_log("Required software not installed") + dt.print("Required software not installed") remove_temp_files() return - end - - df.set_executable_path_preference("enfuse", dt.preferences.read("module_enfuse_pro", "enfuse_path", "string")) - dt.print_log("Executable Path Preference: "..df.get_executable_path_preference("enfuse")) - enfuse_path = df.check_if_bin_exists("enfuse") - if not enfuse_path then - dt.print_error("enfuse not found") - dt.print("ERROR - enfuse not found") - remove_temp_files() - return - end - - df.set_executable_path_preference("exiftool", dt.preferences.read("module_enfuse_pro", "exiftool_path", "string")) - dt.print_log("Executable Path Preference: "..df.get_executable_path_preference("exiftool")) - exiftool_path = df.check_if_bin_exists("exiftool") - if not exiftool_path then - dt.print_error("exiftool not found") - dt.print("ERROR - exiftool not found") - remove_temp_files() - return - end - ---Ensure proper version of Enfuse installed-- - --[[ - enfuseVersionStartCommand='enfuse --version | grep "enfuse 4.2"' - enfuse_version=dt.control.execute(enfuseVersionStartCommand) - if (enfuse_version ~= 0) then - dt.print(_('ERROR: wrong enfuse version found. the plugin works only with enfuse 4.2! please install enfuse version 4.2')) - return - end]] + end --Check that output path selected cmd_output_path = file_chooser_button_path.value @@ -995,7 +974,6 @@ dt.preferences.register("module_enfuse_pro", "image_color_depth", -- name "8","32","r32","r64") -- values --AIS bin location -AIS_path = df.get_executable_path_preference("align_image_stack") if not AIS_path then AIS_path = "" end @@ -1004,7 +982,7 @@ AIS_path_widget = dt.new_widget("file_chooser_button"){ value = AIS_path, is_directory = false, } -dt.preferences.register("module_enfuse_pro", "ais_path", -- name +dt.preferences.register("executable_paths", "align_image_stack", -- name "file", -- type 'enfuse_pro: Align Image Stack Location', -- label 'Install location of align_image_stack. Requires restart to take effect.', -- tooltip @@ -1013,7 +991,6 @@ dt.preferences.register("module_enfuse_pro", "ais_path", -- name ) --enfuse bin location -enfuse_path = df.get_executable_path_preference("enfuse") if not enfuse_path then enfuse_path = "" end @@ -1022,7 +999,7 @@ enfuse_path_widget = dt.new_widget("file_chooser_button"){ value = enfuse_path, is_directory = false, } -dt.preferences.register("module_enfuse_pro", "enfuse_path", -- name +dt.preferences.register("executable_paths", "enfuse", -- name "file", -- type 'enfuse_pro: enfuse Location', -- label 'Install location of enfuse. Requires restart to take effect.', -- tooltip @@ -1031,7 +1008,6 @@ dt.preferences.register("module_enfuse_pro", "enfuse_path", -- name ) --exiftool bin location -exiftool_path = df.get_executable_path_preference("exiftool") if not exiftool_path then exiftool_path = "" end @@ -1040,7 +1016,7 @@ exiftool_path_widget = dt.new_widget("file_chooser_button"){ value = exiftool_path, is_directory = false, } -dt.preferences.register("module_enfuse_pro", "exiftool_path", -- name +dt.preferences.register("executable_paths", "exiftool", -- name "file", -- type 'enfuse_pro: exiftool Location', -- label 'Install location of exiftool. Requires restart to take effect.', -- tooltip From d092016729ddc8da73baec2e944fd048536629c8 Mon Sep 17 00:00:00 2001 From: BzKevin <36381472+BzKevin@users.noreply.github.com> Date: Tue, 18 Sep 2018 10:54:16 -0400 Subject: [PATCH 7/9] Add enfuseAdvanced enfuseAdvanced replaces what was previously known as enfuse_pro_2. This incorporates changes requested by wpferguson on previous versions. --- contrib/enfuseAdvanced.lua | 1045 ++++++++++++++++++++++++++++++++++++ 1 file changed, 1045 insertions(+) create mode 100644 contrib/enfuseAdvanced.lua diff --git a/contrib/enfuseAdvanced.lua b/contrib/enfuseAdvanced.lua new file mode 100644 index 0000000..11eb0db --- /dev/null +++ b/contrib/enfuseAdvanced.lua @@ -0,0 +1,1045 @@ +--[[Enfuse Advanced plugin for darktable 2.2.X and 2.4.X + + copyright (c) 2017, 2018 Holger Klemm (Original Linux-only version) + Modified by: Kevin Ertel + + darktable is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + darktable is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with darktable. If not, see . +]] + +--[[About this plugin +This plugin will add the new export module "fusion to DRI or DFF image". + +----REQUIRED SOFTWARE---- +align_image_stack +enfuse ver. 4.2 or greater +exiftool + +----USAGE---- +Install: (see here for more detail: https://github.com/darktable-org/lua-scripts ) + 1) Copy this file in to your "lua/contrib" folder where all other scripts reside. + 2) Require this file in your luarc file, as with any other dt plug-in +On the initial startup go to darktable settings > lua options and set your executable paths and other preferences, then restart darktable + +DRI = Dynamic Range Increase (Blend multiple bracket images into a single LDR file) +DFF = Depth From Focus ("Focus Stacking" - Blend multiple images with different focus into a single image) +Select multiple images that are either bracketed, or focus-shifted, set your desired operating parameters, and press the export button. A new image will be created. The image will +be auto imported into darktable if you have that option enabled. Additional tags or style can be applied on auto import as well, if you desire. + +image align options: +See align_image_stack documentation for further explanation of how it specifically works and the options provided (http://hugin.sourceforge.net/docs/manual/Align_image_stack.html) + +image fustion options: +See enfuse documentation for further explanation of how it specifically works and the options provided (https://wiki.panotools.org/Enfuse) +If you have a specific set of parameters you frequently like to use, you can save them to a preset. There are 3 presets available for DRI, and 3 for DFF. + +target file: +Select your file destination path, or check the "save to source image location" option. +Unless "Create unique filename" is check, it will overwrite existing files +Set any tags or style you desire to be added to the new image (only available if the auto-import option is enabled). You can also change the defaults for this under settings > lua options + +format options: +Same as other export modules + +global options: +Same as other export modules + +----KNOWN ISSUES---- +Cannot handle spaces in image paths on windows machienes +Pops up multiple CMD windows on windows machienes +]] + +local dt = require "darktable" +local df = require "lib/dtutils.file" +local dsys = require "lib/dtutils.system" +local gettext = dt.gettext +local preferences_version = 1 --When releasing an update increment this number by one if changes have been made to the preferences structure that would require a re-initialization + +-- works with LUA API version 5.0.0 +dt.configuration.check_version(...,{5,0,0}) + +-- Tell gettext where to find the .mo file translating messages for a particular domain +gettext.bindtextdomain("enfuseAdvanced",dt.configuration.config_dir.."/lua/") + +local function _(msgid) + return gettext.dgettext("enfuseAdvanced", msgid) +end + +--Detect User Styles-- +styles = dt.styles +styles_count = 1 -- "none" = 1 +for _,i in pairs(dt.styles) do + if type(i) == "userdata" then styles_count = styles_count + 1 end +end + +-- INITS -- +pref_style = dt.preferences.read("module_enfuseAdvanced", "style", "string") +pref_cpytags = dt.preferences.read("module_enfuseAdvanced", "copy_tags", "bool") +pref_addtags = dt.preferences.read("module_enfuseAdvanced", "add_tags", "string") +if dt.configuration.running_os == "windows" then + os_path_seperator = "\\" +else + os_path_seperator = "/" +end + +--Ensure Required Software is Installed-- +not_installed = 0 +dt.print_log("enfuseAdvanced - Executable Path Preference: "..df.get_executable_path_preference("align_image_stack")) +local AIS_path = df.check_if_bin_exists("align_image_stack") +if not AIS_path then + dt.print_error("align image stack not found") + dt.print("ERROR - align image stack not found") + not_installed = 1 +end + +dt.print_log("enfuseAdvanced - Executable Path Preference: "..df.get_executable_path_preference("enfuse")) +local enfuse_path = df.check_if_bin_exists("enfuse") +if not enfuse_path then + dt.print_error("enfuse not found") + dt.print("ERROR - enfuse not found") + not_installed = 1 +end + +dt.print_log("enfuseAdvanced - Executable Path Preference: "..df.get_executable_path_preference("exiftool")) +local exiftool_path = df.check_if_bin_exists("exiftool") +if not exiftool_path then + dt.print_error("exiftool not found") + dt.print("ERROR - exiftool not found") + not_installed = 1 +end + + +--Ensure proper version of Enfuse installed-- +--[[ +local enfuseVersionStartCommand = enfuse_path .. " --version | " .. grep .. " \"enfuse 4.2\"" +local enfuse_version = dsys.external_command(enfuseVersionStartCommand) +if enfuse_version ~= 0 then + dt.print(_('ERROR: wrong enfuse version found. the plugin works only with enfuse 4.2! please install enfuse version 4.2')) + not_installed = 1 +end +]] + +if dt.preferences.read("enfuseAdvanced", "pref_version", "integer") ~= preferences_version then + dt.print_log("enfuseAdvanced - (Re)Initializing preferences due to script load\changes detected") + -- align defaults + dt.preferences.write("enfuseAdvanced", "selected_fusion", "integer", 1) + dt.preferences.write("align_image_stack", "def_radial_distortion", "bool", false) + dt.preferences.write("align_image_stack", "def_optimize_field", "bool", false) + dt.preferences.write("align_image_stack", "def_optimize_image_center", "bool", true) + dt.preferences.write("align_image_stack", "def_auto_crop", "bool", true) + dt.preferences.write("align_image_stack", "def_distortion", "bool", true) + dt.preferences.write("align_image_stack", "def_grid_size", "integer", 5) + dt.preferences.write("align_image_stack", "def_control_points", "integer", 8) + dt.preferences.write("align_image_stack", "def_control_points_remove", "integer", 3) + dt.preferences.write("align_image_stack", "def_correlation", "integer", 9) + + -- enfuse defaults + dt.preferences.write("enfuseAdvanced", "def_fusion_type", "integer", 1) + dt.preferences.write("enfuseAdvanced", "def_image_variants", "bool", false) + dt.preferences.write("enfuseAdvanced", "def_hard_masks", "bool", false) + dt.preferences.write("enfuseAdvanced", "def_save_masks", "bool", false) + dt.preferences.write("enfuseAdvanced", "def_contrast_window_size", "integer", 3) + dt.preferences.write("enfuseAdvanced", "def_contrast_edge_scale", "integer", 1) + dt.preferences.write("enfuseAdvanced", "def_contrast_min_curvature", "integer", 1) + dt.preferences.write("enfuseAdvanced", "def_exposure_weight", "float", 1.0) + dt.preferences.write("enfuseAdvanced", "def_saturation_weight", "float", 0.2) + dt.preferences.write("enfuseAdvanced", "def_contrast_weight", "float", 0.0) + dt.preferences.write("enfuseAdvanced", "def_exposure_optimum_weight", "float", 0.5) + dt.preferences.write("enfuseAdvanced", "def_exposure_width_weight", "float",0.2) + dt.preferences.write("enfuseAdvanced", "selected_overwrite", "integer",1) + dt.preferences.write("enfuseAdvanced", "sentitiv_overwrite", "bool",true) + + -- preset DRI 1 + temp_text = {"dri1_","dri2_","dri3_"} + for i,preset in pairs(temp_text) do + dt.preferences.write("enfuseAdvanced", preset.."hard_masks", "bool", false) + dt.preferences.write("enfuseAdvanced", preset.."save_masks", "bool", false) + dt.preferences.write("enfuseAdvanced", preset.."contrast_window_size", "integer", 3) + dt.preferences.write("enfuseAdvanced", preset.."contrast_edge_scale", "integer", 1) + dt.preferences.write("enfuseAdvanced", preset.."contrast_min_curvature", "integer", 1) + dt.preferences.write("enfuseAdvanced", preset.."exposure_weight", "float", 1.0) + dt.preferences.write("enfuseAdvanced", preset.."saturation_weight", "float", 0.2) + dt.preferences.write("enfuseAdvanced", preset.."contrast_weight", "float", 0.0) + dt.preferences.write("enfuseAdvanced", preset.."exposure_optimum_weight", "float", 0.5) + dt.preferences.write("enfuseAdvanced", preset.."exposure_width_weight", "float",0.2) + end + + -- preset DFF 1 + temp_text = {"dff1_","dff2_","dff3_"} + for i,preset in pairs(temp_text) do + dt.preferences.write("enfuseAdvanced", preset.."hard_masks", "bool", true) + dt.preferences.write("enfuseAdvanced", preset.."save_masks", "bool", false) + dt.preferences.write("enfuseAdvanced", preset.."contrast_window_size", "integer", 3) + dt.preferences.write("enfuseAdvanced", preset.."contrast_edge_scale", "integer", 1) + dt.preferences.write("enfuseAdvanced", preset.."contrast_min_curvature", "integer", 1) + dt.preferences.write("enfuseAdvanced", preset.."exposure_weight", "float", 0.0) + dt.preferences.write("enfuseAdvanced", preset.."saturation_weight", "float", 0.0) + dt.preferences.write("enfuseAdvanced", preset.."contrast_weight", "float", 1.0) + dt.preferences.write("enfuseAdvanced", preset.."exposure_optimum_weight", "float", 0.5) + dt.preferences.write("enfuseAdvanced", preset.."exposure_width_weight", "float",0.2) + end + + -- preset FREE + dt.preferences.write("enfuseAdvanced", "free_hard_masks", "bool", false) + dt.preferences.write("enfuseAdvanced", "free_save_masks", "bool", false) + dt.preferences.write("enfuseAdvanced", "free_contrast_window_size", "integer", 3) + dt.preferences.write("enfuseAdvanced", "free_contrast_edge_scale", "integer", 1) + dt.preferences.write("enfuseAdvanced", "free_contrast_min_curvature", "integer", 1) + dt.preferences.write("enfuseAdvanced", "free_exposure_weight", "float", 0.0) + dt.preferences.write("enfuseAdvanced", "free_saturation_weight", "float", 0.0) + dt.preferences.write("enfuseAdvanced", "free_contrast_weight", "float", 0.0) + dt.preferences.write("enfuseAdvanced", "free_exposure_optimum_weight", "float", 0.0) + dt.preferences.write("enfuseAdvanced", "free_exposure_width_weight", "float",0.0) + + -- output + dt.preferences.write("enfuseAdvanced", "selected_output_format", "integer", 1) + + --tracking + dt.preferences.write("enfuseAdvanced", "pref_version", "integer", preferences_version) +end + +--GUI +j=0 +enf_separator1 = dt.new_widget("separator"){} +enf_separator1b = dt.new_widget("separator"){} +enf_separator2 = dt.new_widget("separator"){} +enf_separator2b = dt.new_widget("separator"){} +enf_label_align_options= dt.new_widget("section_label"){ + label = _('image align options') +} +enf_label_enfuse_options= dt.new_widget("section_label"){ + label = _('image fusion options') +} +enf_label_output_format= dt.new_widget("section_label"){ + label = _('target file') +} +enf_label_path = dt.new_widget("label"){ + label = _('directory'), + ellipsize = "start", + halign = "start" +} +enf_chkbtn_radial_distortion = dt.new_widget("check_button"){ + label = _('optimize radial distortion for all images'), + value = dt.preferences.read("align_image_stack", "def_radial_distortion", "bool"), + tooltip = _('optimize radial distortion for all images, \nexcept for first'), +} +enf_chkbtn_optimize_field = dt.new_widget("check_button"){ + label = _('optimize field of view for all images'), + value = dt.preferences.read("align_image_stack", "def_optimize_field", "bool"), + tooltip =_('optimize field of view for all images, except for first. \nUseful for aligning focus stacks (DFF) with slightly \ndifferent magnification.'), +} +enf_chkbtn_optimize_image_center = dt.new_widget("check_button"){ + label = _('optimize image center shift for all images'), + value = dt.preferences.read("align_image_stack", "def_optimize_image_center", "bool"), + tooltip =_('optimize image center shift for all images, \nexcept for first.'), +} +enf_chkbtn_auto_crop = dt.new_widget("check_button"){ + label = _('auto crop the image'), + value = dt.preferences.read("align_image_stack", "def_auto_crop", "bool"), + tooltip =_('auto crop the image to the area covered by all images.'), +} +enf_chkbtn_distortion = dt.new_widget("check_button"){ + label = _('load distortion from lens database'), + value = dt.preferences.read("align_image_stack", "def_distortion", "bool"), + tooltip =_('try to load distortion information from lens database'), +} +enf_chkbtn_hard_masks = dt.new_widget("check_button"){ + label = _('hard mask'), + value = dt.preferences.read("enfuseAdvanced", "def_hard_masks", "bool"), + tooltip =_('force hard blend masks on the finest scale. this avoids \naveraging of fine details (only), at the expense \nof increasing the noise. this improves the \nsharpness of focus stacks considerably.\ndefault (soft mask)'), + reset_callback = function(self) + self.value = dt.preferences.read("enfuseAdvanced", "def_hard_masks", "bool") + end +} +enf_chkbtn_save_masks = dt.new_widget("check_button"){ + label = _('save masks'), + value = dt.preferences.read("enfuseAdvanced", "def_save_masks", "bool"), + tooltip =_('Save the generated weight masks to your home directory,\nenblend saves masks as 8 bit grayscale, \ni.e. single channel images. \nfor accuracy we recommend to choose a lossless format.'), + reset_callback = function(self) + self.value = dt.preferences.read("enfuseAdvanced", "def_save_masks", "bool") + end +} +enf_chkbtn_cpytags = dt.new_widget("check_button"){ + label = ' Copy Tags', + value = pref_cpytags, + tooltip ='Copy tags from first image.', +} +enf_sldr_exposure_weight = dt.new_widget("slider"){ + label = _('exposure weight'), + tooltip = _('set the relative weight of the well-exposedness criterion \nas defined by the chosen exposure weight function. \nincreasing this weight relative to the others will\n make well-exposed pixels contribute more to\n the final output. \ndefault: (1.0)'), + hard_min = 0, + hard_max = 1, + value = dt.preferences.read("enfuseAdvanced", "def_exposure_weight", "float") --1 def +} +enf_sldr_saturation_weight = dt.new_widget("slider"){ + label = _('saturation weight'), + tooltip = _('set the relative weight of high-saturation pixels. \nincreasing this weight makes pixels with high \nsaturation contribute more to the final output. \ndefault: (0.2)'), + hard_min = 0, + hard_max = 1, + value = dt.preferences.read("enfuseAdvanced", "def_saturation_weight", "float"), --0.5 +} +enf_sldr_contrast_weight = dt.new_widget("slider"){ + label = _('contrast weight'), + tooltip = _('sets the relative weight of high local-contrast pixels. \ndefault: (0.0).'), + hard_min = 0, + hard_max = 1, + value = dt.preferences.read("enfuseAdvanced", "def_contrast_weight", "float")--0 default +} +enf_sldr_exposure_optimum_weight = dt.new_widget("slider"){ + label = _('exposure optimum'), + tooltip = _('determine at what normalized exposure value\n the optimum exposure of the input images\n is. this is, set the position of the maximum\n of the exposure weight curve. use this \noption to fine-tune exposure weighting. \ndefault: (0.5)'), + hard_min = 0, + hard_max = 1, + value = dt.preferences.read("enfuseAdvanced", "def_exposure_optimum_weight", "float")--0.5 default0 +} +enf_sldr_exposure_width_weight = dt.new_widget("slider"){ + label = _('exposure width'), + tooltip = _('set the characteristic width (FWHM) of the exposure \nweight function. low numbers give less weight to \npixels that are far from the user-defined \noptimum and vice versa. use this option to \nfine-tune exposure weighting. \ndefault: (0.2)'), + hard_min = 0, + hard_max = 1, + value = dt.preferences.read("enfuseAdvanced", "def_exposure_width_weight", "float") --0.2 default +} +enf_file_chooser_button_path = dt.new_widget("file_chooser_button"){ + title = _('Select export path'), -- The title of the window when choosing a file + is_directory = true, -- True if the file chooser button only allows directories to be selecte + tooltip =_('select the target directory for the fused image. \nthe filename is created automatically.'), +} +enf_chkbtn_source_location = dt.new_widget("check_button"){ + label = _('save to source image location'), + value = true, + tooltip =_('If checked ignores the location below and saves output image(s) to the same location as the source images.'), + reset_callback = function(self) + self.value = true + end +} +enf_cmbx_grid_size = dt.new_widget("combobox"){ + label = _('image grid size'), + tooltip =_('break image into a rectangular grid \nand attempt to find num control points in each section.\ndefault: (5x5)'), + value = dt.preferences.read("align_image_stack", "def_grid_size", "integer"), --5 + "1", "2", "3","4","5","6","7","8","9", + reset_callback = function(self) + self.value = dt.preferences.read("align_image_stack", "def_grid_size", "integer") + end +} +enf_cmbx_control_points = dt.new_widget("combobox"){ + label = _('control points/grid'), + tooltip =_('number of control points (per grid, see option -g) \nto create between adjacent images \ndefault: (8).'), + value = dt.preferences.read("align_image_stack", "def_control_points", "integer"), --8, "1", "2", "3","4","5","6","7","8","9", + "1", "2", "3","4","5","6","7","8","9", + reset_callback = function(self) + self.value = dt.preferences.read("align_image_stack", "def_control_points", "integer") + end +} +enf_cmbx_control_points_remove = dt.new_widget("combobox"){ + label = _('remove control points with error'), + tooltip =_('remove all control points with an error higher \nthan num pixels \ndefault: (3)'), + value = dt.preferences.read("align_image_stack", "def_control_points_remove", "integer"), --3, "1", "2", "3","4","5","6","7","8","9", + "1", "2", "3","4","5","6","7","8","9", + reset_callback = function(self) + self.value = dt.preferences.read("align_image_stack", "def_control_points_remove", "integer") + end +} +enf_cmbx_correlation = dt.new_widget("combobox"){ + label = _('correlation threshold for control points'), + tooltip =_('correlation threshold for identifying \ncontrol points \ndefault: (0.9).'), + value = dt.preferences.read("align_image_stack", "def_correlation", "integer"), --9, "0,1", "0,2", "0,3","0,4","0,5","0,6","0,7","0,8","0,9", + "0.1", "0.2", "0.3","0.4","0.5","0.6","0.7","0.8","0.9","1.0", + reset_callback = function(self) + self.value = dt.preferences.read("align_image_stack", "def_correlation", "integer") + end +} +enf_cmbx_contrast_window_size = dt.new_widget("combobox"){ + label = _('contrast window size'), + tooltip =_('set the window size for local contrast analysis. \nthe window will be a square of size × size pixels. \nif given an even size, Enfuse will \nautomatically use the next odd number.\nfor contrast analysis size values larger \nthan 5 pixels might result in a \nblurry composite image. values of 3 and \n5 pixels have given good results on \nfocus stacks. \ndefault: (5) pixels'), + value = dt.preferences.read("enfuseAdvanced", "def_contrast_window_size", "integer"), --3, "3","4","5","6","7","8","9","10", + "3", "4", "5","6","7","8","9","10", +} +enf_cmbx_contrast_edge_scale = dt.new_widget("combobox"){ + label = _('contrast edge scale'), + tooltip =_('a non-zero value for EDGE-SCALE switches on the \nLaplacian-of-Gaussian (LoG) edge detection algorithm.\n edage-scale is the radius of the Gaussian used \nin the search for edges. a positive LCE-SCALE \nturns on local contrast enhancement (LCE) \nbefore the LoG edge detection. \nDefault: (0.0) pixels.'), + value = dt.preferences.read("enfuseAdvanced", "def_contrast_edge_scale", "integer"), --1, "0:0:0", + "0.0","0.1","0.2","0.3","0.4","0.5", + +} +enf_cmbx_contrast_min_curvature = dt.new_widget("combobox"){ + label = _('contrast min curvature'), + tooltip =_('define the minimum curvature for the LoG edge detection. Append a ‘%’ to specify the minimum curvature relative to maximum pixel value in the source image. Default: (0.0%)'), + value = dt.preferences.read("enfuseAdvanced", "def_contrast_min_curvature", "integer"), --1, "0.0%","0.1%", "0.2%", "0.3%","0.4%","0.5%","0.6%","0.7%","0.8%","0.9%","1.0%", + "0.0%", "0.1%", "0.2%","0.3%","0.4%","0.5%","0.6%","0.7%","0.8%","0.9%","1.0%", +} +enf_cmbx_existing_file = dt.new_widget("combobox"){ + label = _('on conflict'), + value = dt.preferences.read("enfuseAdvanced", "selected_overwrite", "integer"), --1, + sensitive= dt.preferences.read("enfuseAdvanced", "sentitiv_overwrite", "bool"), --1, + _('create unique filename'),_('overwrite'), + reset_callback = function(self) + self.value = dt.preferences.read("enfuseAdvanced", "selected_overwrite", "integer") + end +} +enf_cmbx_style = dt.new_widget("combobox"){ + label = "Apply Style on Import", + tooltip = "Apply selected style on auto-import to newly created blended image", + value = 1, + "none", + } +pref_style_enum = 1 +for k=1, (styles_count-1) do + enf_cmbx_style[k+1] = styles[k].name + if styles[k].name == pref_style then pref_style_enum = k+1 end +end +enf_cmbx_style.value = pref_style_enum +enf_chkbtn_image_variations = dt.new_widget("check_button"){ + label = _('create image variants with saved presets'), + value = dt.preferences.read("enfuseAdvanced", "def_image_variants", "bool"), + tooltip =_('creates image variants with the three \nsaved DRI or DFF presets'), + sensitive=true, + clicked_callback = function(self) + if (self.value) then + dt.preferences.write("enfuseAdvanced", "def_image_variants", "bool", true) + dt.preferences.write("enfuseAdvanced", "sentitiv_overwrite", "bool",false) + enf_cmbx_existing_file.value=1 + enf_cmbx_existing_file.sensitive=false + else + dt.preferences.write("enfuseAdvanced", "def_image_variants", "bool", false) + dt.preferences.write("enfuseAdvanced", "sentitiv_overwrite", "bool",true) + enf_cmbx_existing_file.sensitive=true + end + end, + reset_callback = function(self) + dt.preferences.write("enfuseAdvanced", "def_image_variants", "bool", false) + dt.preferences.write("enfuseAdvanced", "sentitiv_overwrite", "bool",true) + self.value = false + enf_cmbx_existing_file.sensitive=true + end + +} +enf_button_save_preset = dt.new_widget("button"){ + label = _('save fusion preset'), + tooltip =_('save the selected fusion preset'), + clicked_callback = function() + pref_text = "" + if (enf_cmbx_fusion_type.value == "1 - DRI image") then + pref_text = "dri1_" + elseif (enf_cmbx_fusion_type.value == "2 - DRI image") then + pref_text = "dri2_" + elseif (enf_cmbx_fusion_type.value == "3 - DRI image") then + pref_text = "dri3_" + elseif (enf_cmbx_fusion_type.value == "1 - DFF image") then + pref_text = "dff1_" + elseif (enf_cmbx_fusion_type.value == "2 - DFF image") then + pref_text = "dff2_" + elseif (enf_cmbx_fusion_type.value == "3 - DFF image") then + pref_text = "dff3_" + elseif (enf_cmbx_fusion_type.value == "free preset") then + pref_text = "free_" + else + dt.print(_('unkown error')) + end + -- Write Preset + if pref_text ~= "" then + dt.preferences.write("enfuseAdvanced", pref_text.."hard_masks", "bool", enf_chkbtn_hard_masks.value) + dt.preferences.write("enfuseAdvanced", pref_text.."save_masks", "bool", enf_chkbtn_save_masks.value) + dt.preferences.write("enfuseAdvanced", pref_text.."contrast_window_size", "integer", enf_cmbx_contrast_window_size.selected) + dt.preferences.write("enfuseAdvanced", pref_text.."contrast_edge_scale", "integer", enf_cmbx_contrast_edge_scale.selected) + dt.preferences.write("enfuseAdvanced", pref_text.."contrast_min_curvature", "integer", enf_cmbx_contrast_min_curvature.selected) + dt.preferences.write("enfuseAdvanced", pref_text.."exposure_weight", "float", enf_sldr_exposure_weight.value) + dt.preferences.write("enfuseAdvanced", pref_text.."saturation_weight", "float", enf_sldr_saturation_weight.value) + dt.preferences.write("enfuseAdvanced", pref_text.."contrast_weight", "float", enf_sldr_contrast_weight.value) + dt.preferences.write("enfuseAdvanced", pref_text.."exposure_optimum_weight", "float", enf_sldr_exposure_optimum_weight.value) + dt.preferences.write("enfuseAdvanced", pref_text.."exposure_width_weight", "float",enf_sldr_exposure_width_weight.value) + dt.print(_('preset '..pref_text..' saved')) + end + end +} +enf_button_load_preset = dt.new_widget("button"){ + label = _('load fusion defaults'), + tooltip =_('load the default fusion settings'), + clicked_callback = function() + enf_chkbtn_hard_masks.value=dt.preferences.read("enfuseAdvanced", "def_hard_masks", "bool") + enf_chkbtn_save_masks.value=dt.preferences.read("enfuseAdvanced", "def_save_masks", "bool") + enf_cmbx_contrast_window_size.value=dt.preferences.read("enfuseAdvanced", "def_contrast_window_size", "integer") + enf_cmbx_contrast_edge_scale.value=dt.preferences.read("enfuseAdvanced", "def_contrast_edge_scale", "integer") + enf_cmbx_contrast_min_curvature.value=dt.preferences.read("enfuseAdvanced", "def_contrast_min_curvature", "integer") + enf_sldr_exposure_weight.value=dt.preferences.read("enfuseAdvanced", "def_exposure_weight", "float") + enf_sldr_saturation_weight.value=dt.preferences.read("enfuseAdvanced", "def_saturation_weight", "float") + enf_sldr_contrast_weight.value=dt.preferences.read("enfuseAdvanced", "def_contrast_weight", "float") + enf_sldr_exposure_optimum_weight.value=dt.preferences.read("enfuseAdvanced", "def_exposure_optimum_weight", "float") + enf_sldr_exposure_width_weight.value=dt.preferences.read("enfuseAdvanced", "def_exposure_width_weight", "float") + end + +} +enf_cmbx_output_format = dt.new_widget("combobox"){ + label = _('file format'), + value = dt.preferences.read("enfuseAdvanced", "selected_output_format", "integer"), --1, "TIFF", "JPEG", "PNG","PNM","PBM","PGM","PPM", + changed_callback = function(self) + dt.preferences.write("enfuseAdvanced", "selected_output_format", "integer", self.selected) + end, + "TIFF", "JPEG", "PNG","PNM","PBM","PPM", + reset_callback = function(self) + self.value = dt.preferences.read("enfuseAdvanced", "selected_output_format", "integer") + end +} +enf_cmbx_fusion_type = dt.new_widget("combobox"){ + label = _('fusion preset'), + tooltip =_('select the preset and save the preset\n if you want to reuse it or create an image\n variant'), + value = 1, --dt.preferences.read("enfuseAdvanced", "def_fusion_type", "integer"), --1, "DRI image", "DFF image", "without preset", + changed_callback = function(self) + dt.preferences.write("enfuseAdvanced", "def_fusion_type", "integer", self.selected) + + if (self.value == "1 - DRI image") then + pref_text = "dri1_" + elseif (self.value == "2 - DRI image") then + pref_text = "dri2_" + elseif (self.value == "3 - DRI image") then + pref_text = "dri3_" + elseif (self.value == "1 - DFF image") then + pref_text = "dff1_" + elseif (self.value == "2 - DFF image") then + pref_text = "dff2_" + elseif (self.value == "3 - DFF image") then + pref_text = "dff3_" + elseif (self.value == "free preset") then + pref_text = "free_" + end + + if string.match(pref_text,"^dri")~=nil then + enf_chkbtn_hard_masks.sensitive=false + enf_chkbtn_hard_masks.value=false + enf_sldr_contrast_weight.sensitive=true + elseif string.match(pref_text,"^dff")~=nil then + enf_chkbtn_hard_masks.sensitive=false + enf_chkbtn_hard_masks.value=true + enf_sldr_contrast_weight.sensitive=false + else + enf_chkbtn_hard_masks.sensitive=true + enf_chkbtn_hard_masks.value=false + enf_sldr_contrast_weight.sensitive=true + end + + enf_chkbtn_hard_masks.value=dt.preferences.read("enfuseAdvanced", pref_text.."hard_masks", "bool") + enf_chkbtn_save_masks.value=dt.preferences.read("enfuseAdvanced", pref_text.."save_masks", "bool") + enf_cmbx_contrast_window_size.value=dt.preferences.read("enfuseAdvanced", pref_text.."contrast_window_size", "integer") + enf_cmbx_contrast_edge_scale.value=dt.preferences.read("enfuseAdvanced", pref_text.."contrast_edge_scale", "integer") + enf_cmbx_contrast_min_curvature.value=dt.preferences.read("enfuseAdvanced", pref_text.."contrast_min_curvature", "integer") + enf_sldr_exposure_weight.value=dt.preferences.read("enfuseAdvanced", pref_text.."exposure_weight", "float") + enf_sldr_saturation_weight.value=dt.preferences.read("enfuseAdvanced", pref_text.."saturation_weight", "float") + enf_sldr_contrast_weight.value=dt.preferences.read("enfuseAdvanced", pref_text.."contrast_weight", "float") + enf_sldr_exposure_optimum_weight.value=dt.preferences.read("enfuseAdvanced", pref_text.."exposure_optimum_weight", "float") + enf_sldr_exposure_width_weight.value=dt.preferences.read("enfuseAdvanced", pref_text.."exposure_width_weight", "float") + + end, + "1 - DRI image", "2 - DRI image","3 - DRI image","1 - DFF image", "2 - DFF image","3 - DFF image","free preset", + + reset_callback = function(self_type) + enf_cmbx_fusion_type.value = dt.preferences.read("enfuseAdvanced", "def_fusion_type", "integer") + end +} +enf_entry_tag = dt.new_widget("entry"){ + tooltip = "Additional tags to be added on import. Seperate with commas, all spaces will be removed", + text = pref_addtags, + placeholder = "Enter tags, seperated by commas", + editable = true +} +enf_widget = dt.new_widget("box") { + orientation = "vertical", + enf_label_align_options, + enf_chkbtn_radial_distortion, + enf_chkbtn_optimize_field, + enf_chkbtn_optimize_image_center, + enf_chkbtn_auto_crop, + enf_chkbtn_distortion, + enf_cmbx_grid_size, + enf_cmbx_control_points, + enf_cmbx_control_points_remove, + enf_cmbx_correlation, + enf_separator1, + enf_separator1b, + enf_label_enfuse_options, + enf_cmbx_fusion_type, + enf_chkbtn_image_variations, + enf_sldr_exposure_weight, + enf_sldr_saturation_weight, + enf_sldr_contrast_weight, + enf_sldr_exposure_optimum_weight, + enf_sldr_exposure_width_weight, + enf_chkbtn_hard_masks, + enf_chkbtn_save_masks, + enf_cmbx_contrast_edge_scale, + enf_cmbx_contrast_min_curvature, + enf_cmbx_contrast_window_size, + enf_button_save_preset, + enf_button_load_preset, + enf_separator2, + enf_separator2b, + enf_label_output_format, + enf_cmbx_output_format, + enf_label_path, + enf_file_chooser_button_path, + enf_chkbtn_source_location, + enf_cmbx_existing_file, + enf_cmbx_style, + enf_chkbtn_cpytags, + enf_entry_tag, +} + +-- FUNCTION -- +local function GetFileName(full_path) + --[[Parses a full path (path/filename_identifier.extension) into individual parts + Input: Folder1/Folder2/Folder3/Img_0001.CR2 + + Returns: + path: Folder1/Folder2/Folder3/ + filename: Img_0001 + identifier: 0001 + extension: .CR2 + + EX: + path_1, file_1, id_1, ext_1 = GetFileName(full_path_1) + ]] + local path = string.match(full_path, ".*[\\/]") + local filename = string.gsub(string.match(full_path, "[%w-_]*%.") , "%." , "" ) + local identifier = string.match(filename, "%d*$") + local extension = string.match(full_path, "%.%w*") + return path, filename, identifier, extension +end +local function truncate(x) + return x<0 and math.ceil(x) or math.floor(x) +end +local function replace_comma_to_dot(s) + return string.gsub(s, "%,", ".") +end +local function remove_temp_files() + if dt.configuration.running_os == "windows" then + dt.print_log("enfuseAdvanced - Deleting temp files...") + dt.control.execute("del "..images_to_align) + dt.control.execute("del "..images_to_blend) + dt.print_log("enfuseAdvanced - Done deleting") + else + dt.print_log("enfuseAdvanced - Deleting temp files...") + dt.control.execute("rm "..images_to_align) + dt.control.execute("rm "..images_to_blend) + dt.print_log("enfuseAdvanced - Done deleting") + end +end +local function build_execute_command(cmd, args, file_list) + local result = cmd.." "..args.." "..file_list + return result +end +local function copy_exif(from_file, to_file) + exifStartCommand = exiftool_path.." -TagsFromFile "..df.sanitize_filename(from_file).." -exif:all --subifd:all -overwrite_original "..df.sanitize_filename(to_file) + dt.print_log("enfuseAdvanced - EXIFTool Start Command: "..exifStartCommand) + resultexif=dsys.external_command(exifStartCommand) + if (resultexif == 0) then + dt.print_log("enfuseAdvanced - EXIFTool copy successful") + dt.print("Copied EXIF data") + else + dt.print(_('ERROR: exiftool doesn\'t work. for more informations see terminal output')) + dt.print_error("exif copy failed") + end +end +local function align_images() + dt.print(_('aligning images')) + + --Setup Align Image Stack Arguments-- + align_args = "" + if (enf_chkbtn_radial_distortion.value) then align_args = align_args.." -d" end + if (enf_chkbtn_optimize_field.value) then align_args = align_args.." -m" end + if (enf_chkbtn_optimize_image_center.value) then align_args = align_args.." -i" end + if (enf_chkbtn_auto_crop.value) then align_args = align_args.." -C" end + if (enf_chkbtn_distortion.value) then align_args = align_args.." --distortion" end + align_args = align_args.." -g "..enf_cmbx_grid_size.value + align_args = align_args.." -c "..enf_cmbx_control_points.value + align_args = align_args.." -t "..enf_cmbx_control_points_remove.value + align_args = align_args.." --corr="..enf_cmbx_correlation.value + if (dt.preferences.read("module_enfuseAdvanced", "align_use_gpu", "bool")) then align_args = align_args.." --gpu" end + align_args = align_args.." -a "..df.sanitize_filename(first_path.."aligned_")..' ' + alignStartCommand = build_execute_command(AIS_path, align_args, images_to_align) + dt.print_log("enfuseAdvanced - Align Start Command: "..alignStartCommand) + resp = dsys.external_command(alignStartCommand) + dt.print_log("enfuseAdvanced - Completed Align") + return resp +end +local function blend_images() + blend_args = "" + if from_preset then --load args from preset preferences + blend_args=blend_args.." --exposure-weight="..(replace_comma_to_dot(dt.preferences.read("enfuseAdvanced", preset_text.."_exposure_weight", "float"))) + blend_args=blend_args.." --saturation-weight="..(replace_comma_to_dot(dt.preferences.read("enfuseAdvanced", preset_text.."_saturation_weight", "float"))) + blend_args=blend_args.." --contrast-weight="..(replace_comma_to_dot(dt.preferences.read("enfuseAdvanced", preset_text.."_contrast_weight", "float"))) + blend_args=blend_args.." --exposure-optimum="..(replace_comma_to_dot(dt.preferences.read("enfuseAdvanced", preset_text.."_exposure_optimum_weight", "float"))) + blend_args=blend_args.." --exposure-width="..(replace_comma_to_dot(dt.preferences.read("enfuseAdvanced", preset_text.."_exposure_width_weight", "float"))) + if (enf_chkbtn_hard_masks.value) then blend_args=blend_args.."--hard-mask" end + if (enf_chkbtn_save_masks.value) then blend_args=blend_args.."--save-masks" end + blend_args=blend_args.." --contrast-window-size="..dt.preferences.read("enfuseAdvanced", preset_text.."_contrast_window_size", "integer") + blend_args=blend_args.." --contrast-edge-scale="..dt.preferences.read("enfuseAdvanced", preset_text.."_contrast_edge_scale", "integer") + blend_args=blend_args.." --contrast-min-curvature="..dt.preferences.read("enfuseAdvanced", preset_text.."_contrast_min_curvature", "integer") + blend_args=blend_args.." --depth="..dt.preferences.read("module_enfuseAdvanced", "image_color_depth", "enum") + else --load args from GUI values + blend_args = blend_args.." --exposure-weight="..(replace_comma_to_dot(enf_sldr_exposure_weight.value)) + blend_args = blend_args.." --saturation-weight="..(replace_comma_to_dot(enf_sldr_saturation_weight.value)) + blend_args = blend_args.." --contrast-weight="..(replace_comma_to_dot(enf_sldr_contrast_weight.value)) + blend_args = blend_args.." --exposure-optimum="..(replace_comma_to_dot(enf_sldr_exposure_optimum_weight.value)) + blend_args = blend_args.." --exposure-width="..(replace_comma_to_dot(enf_sldr_exposure_width_weight.value)) + if (enf_chkbtn_hard_masks.value) then blend_args = blend_args.." --hard-mask" end + if (enf_chkbtn_save_masks.value) then blend_args = blend_args.." --save-masks" end + blend_args = blend_args.." --contrast-window-size="..enf_cmbx_contrast_window_size.value + blend_args = blend_args.." --contrast-edge-scale="..enf_cmbx_contrast_edge_scale.value + blend_args = blend_args.." --contrast-min-curvature="..enf_cmbx_contrast_min_curvature.value + blend_args = blend_args.." --depth="..dt.preferences.read("module_enfuseAdvanced", "image_color_depth", "enum") + end + + --set output format per GUI selection + if (enf_cmbx_output_format.value == "TIFF") then + cmd_suffix_output_format="tif" + blend_args = blend_args.." --compression="..dt.preferences.read("module_enfuseAdvanced", "compression_tiff", "enum") + elseif (enf_cmbx_output_format.value == "JPEG") then + cmd_suffix_output_format="jpg" + blend_args = blend_args.." --compression="..truncate(dt.preferences.read("module_enfuseAdvanced", "compression_jpeg", "integer")) + elseif (enf_cmbx_output_format.value == "PNG") then + cmd_suffix_output_format="png" + elseif (enf_cmbx_output_format.value == "PNM") then + cmd_suffix_output_format="pnm" + elseif (enf_cmbx_output_format.value == "PBM") then + cmd_suffix_output_format="pbm" + elseif (enf_cmbx_output_format.value == "PPM") then + cmd_suffix_output_format="ppm" + end + + --Set output path and add filename + if (enf_chkbtn_source_location.value) then + cmd_output_path = enf_source_path + else + cmd_output_path=enf_file_chooser_button_path.value + end + path_with_filename = cmd_output_path..os_path_seperator..first_filename.."-"..last_id.."."..cmd_suffix_output_format + + --Create unique name with index if GUI selection create unique name (don't overwrite), also do this if user selected to make variants from presets + if (enf_cmbx_existing_file.selected == 1) or (from_preset) then + path_with_filename = df.create_unique_filename(path_with_filename) + end + + cmd_output_image = " --output="..df.sanitize_filename(path_with_filename) + blend_args = blend_args..cmd_output_image + + images_to_blend = "" + for j=0, counted_images-1 do + if j < 10 then + id = "000"..tostring(j) + else + id = "00"..tostring(j) + end + --[[if dt.configuration.running_os == "windows" then + images_to_blend = images_to_blend..first_path.."aligned_"..id..".tif " + else + images_to_blend = images_to_blend..'"'..first_path.."aligned_"..id..".tif"..'" ' + end]] + images_to_blend = images_to_blend..first_path.."aligned_"..id..".tif " + end + BlendStartCommand=build_execute_command(enfuse_path, blend_args, images_to_blend) + + dt.print_log("enfuseAdvanced - Blend Start Command: "..BlendStartCommand) + resultBlend=dsys.external_command(BlendStartCommand) + dt.print_log("enfuseAdvanced - Completed Blend") + + return resultBlend, path_with_filename +end +local function show_status(enf_storage, image, format, filename, --Store: Called on each exported image + number, total, high_quality, extra_data) + dt.print(_('export TIFF for image fusion ')..tostring(truncate(number)).." / "..tostring(truncate(total))) +end +local function create_image_fusion(enf_storage, image_table, extra_data) --Finalize: Called once when all images are done exporting +--Create Images String-- + images_to_align = "" + images_to_blend = "" + counted_images=0 + first_id = "999999999999999999999999" + last_id = "0" + for source_image,image_path in pairs(image_table) do + counted_images=counted_images+1 + --[[if dt.configuration.running_os == "windows" then + images_to_align = images_to_align..image_path..' ' + else + images_to_align = images_to_align..'"'..image_path..'" ' + end]] + images_to_align = images_to_align..df.sanitize_filename(image_path)..' ' + curr_path, curr_filename, curr_id, curr_ext = GetFileName(image_path) + if (curr_id < first_id) then + first_path = curr_path + first_filename = curr_filename + first_id = curr_id + first_ext = curr_ext + dt_source_image = source_image + end + if (curr_id > last_id) then + last_path = curr_path + last_filename = curr_filename + last_id = curr_id + last_ext = curr_ext + end + enf_source_path = source_image.path + exif_source_file = source_image.path..os_path_seperator..source_image.filename + end + +--Check if at least 2 images selected-- + if (counted_images<=1) then + dt.print(_('ERROR: not enough pictures selected. please select two or more images\nfrom the same object, but with different camera settings.')) + dt.print_error("Not enough pictures selected") + remove_temp_files() + return + end + +--Ensure Proper Software Installed-- + if not_installed == 1 then + dt.print_log("enfuseAdvanced - Required software not found") + dt.print("Required software not found") + remove_temp_files() + return + end + +--Check that output path selected + cmd_output_path = enf_file_chooser_button_path.value + if (cmd_output_path == nil) and not(enf_chkbtn_source_location.value) then + dt.print(_('ERROR: no target directory selected')) + remove_temp_files() + return + end + + dt.print_log("enfuseAdvanced - Starting Image Fusion") + job = dt.gui.create_job(_('Creating DRI/DFF image'), true, stop_selection) + + percent_step = .33 + if (enf_chkbtn_image_variations.value) then percent_step = .2 end + job.percent = job.percent + percent_step + +--Align Images-- + resultalign = align_images() + if (resultalign ~= 0) then --Aling Image Stack Failed-- + dt.print(_('ERROR: align_image_stack doesn\'t work. For more information see terminal output')) + dt.print_error("Align Image Stack Failed") + remove_temp_files() + job.valid = false + return + end + dt.print(_('aligning complete')) + job.percent = job.percent + percent_step + +--Blend Images-- + from_preset = false + iterations = 1 + pref_text = "" + if (enf_chkbtn_image_variations.value) then + iterations = 3 + from_preset = true + if string.match(enf_cmbx_fusion_type.value, "DRI") then + pref_text = "dri" + elseif string.match(enf_cmbx_fusion_type.value, "DFF") then + pref_text = "dff" + else --if "variants" selected, but not using DRI or DFF preset then cannot create variants + dt.print("Error, must select a DRI or DFF preset when starting a fustion with variants") + dt.print_error("DRI or DFF preset not selected when variants option was checked") + remove_temp_files() + job.valid = false + return + end + end + + for j = 1, iterations do + if (from_preset) then + preset_text=pref_text..j + else + preset_text="" + end + resultBlend, blended_image = blend_images() --Check here to ensure enfuse worked properly + if resultBlend ~= 0 then + dt.print(_('ERROR: enfuse didn\'t work. For more information see terminal output')) + dt.print_error("Enfuse failed") + remove_temp_files() + job.valid = false + return + end + --Copy EXIF Data (IF)-- + if (dt.preferences.read("module_enfuseAdvanced", "exiftool_copy_tags", "bool")) then copy_exif(exif_source_file, path_with_filename) end + --Auto-Import-- + if (dt.preferences.read("module_enfuseAdvanced", "add_image_to_db", "bool")) then + local imported = dt.database.import(path_with_filename) + --Apply Selected Style (IF)-- + if enf_cmbx_style.selected > 1 then + set_style = styles[enf_cmbx_style.selected - 1] + dt.styles.apply(set_style , imported) + end + --Copy Tags (IF)-- + if (enf_chkbtn_cpytags.value) then + all_tags = dt.tags.get_tags(dt_source_image) + for _,tag in pairs(all_tags) do + if string.match(tag.name, 'darktable|') == nil then + dt.tags.attach(tag, imported) + end + end + end + --Apply Entered Tags (IF)-- + set_tag = enf_entry_tag.text + if set_tag ~= nil then + for tag in string.gmatch(set_tag, '[^,]+') do + tag = string.gsub(tag, " ", "") + tag = dt.tags.create(tag) + dt.tags.attach(tag, imported) + end + end + end + job.percent = job.percent + percent_step + end + + --Copy EXIF Data (IF)-- + + remove_temp_files() + dt.print("Image fusion process complete") + dt.print_log("enfuseAdvanced - Image fusion process complete") + job.valid = false +end +local function support_format(enf_storage, format) --Supported: Check to make sure image type is supported by darktable + if string.match(string.lower(format.name),"tiff") == nil then + return false + else + return true + end +end + +-- REGISTER -- +dt.register_storage( + "module_enfuseAdvanced", --Module name + 'DRI or DFF image', --Name + show_status, --store: called once per exported image + create_image_fusion, --finalize: called once when all images have finished exporting + support_format, --supported + nil, --initialize + enf_widget + ) + +-- PREFERENCES -- +entry_widget_style = dt.new_widget("entry"){ + tooltip = "Enter the style name exactly as it is", + text = nil, + placeholder = "Enter Style name", + editable = true +} +dt.preferences.register("module_enfuseAdvanced", "style", -- name + "string", -- type + 'enfuseAdvanced: Defualt Style', -- label + 'Changes DEFAULT entry in the Style option. Requires restart to take effect.', -- tooltip + "", -- default + entry_widget_style +) +entry_widget_tags = dt.new_widget("entry"){ + tooltip = "Seperate with commas, all spaces will be removed", + text = nil, + placeholder = "Enter default tags", + editable = true +} +dt.preferences.register("module_enfuseAdvanced", "add_tags", -- name + "string", -- type + 'enfuseAdvanced: Defualt additional tags', -- label + 'Changes DEFAULT entry in the additional tags option. Requires restart to take effect.', -- tooltip + "", -- default + entry_widget_tags +) +dt.preferences.register("module_enfuseAdvanced", "copy_tags", -- name + "bool", -- type + 'enfuseAdvanced: Copy tags from first image by default', -- label + 'Changes DEFAULT selection for Copy Tags, Requires restart to take effect.', -- tooltip + true -- default +) +dt.preferences.register("module_enfuseAdvanced", "exiftool_copy_tags", -- name + "bool", -- type + _('enfuseAdvanced: copy exif data'), -- label + _('copy the exif tags from the first image to the target'), -- tooltip + true) -- default +dt.preferences.register("module_enfuseAdvanced", "add_image_to_db", -- name + "bool", -- type + _('enfuseAdvanced: add fused image to database'), -- label + _('add the fused image to the darktable database'), -- tooltip + false) -- default +dt.preferences.register("module_enfuseAdvanced", "align_use_gpu", -- name + "bool", -- type + _('enfuseAdvanced: use GPU for remaping'), -- label + _('set the GPU remapping for image align'), -- tooltip + false) +dt.preferences.register("module_enfuseAdvanced", "compression_jpeg", -- name + "integer", -- type + _('enfuseAdvanced: JPEG compression'), -- label + _('set the compression for JPEG files'), -- tooltip + 98, -- default + 50, -- min + 100) -- max +dt.preferences.register("module_enfuseAdvanced", "compression_tiff", -- name + "enum", -- type + _('enfuseAdvanced: TIFF compression'), -- label + _('set the compression type for tiff files'), -- tooltip + "LZW", -- default + "NONE", "DEFLATE","PACKBITS") -- va +dt.preferences.register("module_enfuseAdvanced", "image_color_depth", -- name + "enum", -- type + _('enfuseAdvanced: image color depth (bit)'), -- label + _('set the output color depth'), -- tooltip + "16", -- default + "8","32","r32","r64") -- values + +--AIS bin location +if not AIS_path then + AIS_path = "" +end +local AIS_path_widget = dt.new_widget("file_chooser_button"){ + title = "Select align_image_stack[.exe] file", + value = AIS_path, + is_directory = false, +} +dt.preferences.register("executable_paths", "align_image_stack", -- name + "file", -- type + 'enfuseAdvanced: Align Image Stack Location', -- label + 'Install location of align_image_stack. Requires restart to take effect.', -- tooltip + "align_image_stack", -- default + AIS_path_widget +) + +--enfuse bin location +if not enfuse_path then + enfuse_path = "" +end +local enfuse_path_widget = dt.new_widget("file_chooser_button"){ + title = "Select enfuse[.exe] file", + value = enfuse_path, + is_directory = false, +} +dt.preferences.register("executable_paths", "enfuse", -- name + "file", -- type + 'enfuseAdvanced: enfuse Location', -- label + 'Install location of enfuse. Requires restart to take effect.', -- tooltip + "enfuse", -- default + enfuse_path_widget +) + +--exiftool bin location +if not exiftool_path then + exiftool_path = "" +end +local exiftool_path_widget = dt.new_widget("file_chooser_button"){ + title = "Select exiftool[.exe] file", + value = exiftool_path, + is_directory = false, +} +dt.preferences.register("executable_paths", "exiftool", -- name + "file", -- type + 'enfuseAdvanced: exiftool Location', -- label + 'Install location of exiftool. Requires restart to take effect.', -- tooltip + "exiftool", -- default + exiftool_path_widget +) + From 52a241c1ec6958f5901038d78bc2fbe566dfd0d8 Mon Sep 17 00:00:00 2001 From: BzKevin <36381472+BzKevin@users.noreply.github.com> Date: Tue, 18 Sep 2018 10:55:23 -0400 Subject: [PATCH 8/9] Delete enfuse_pro_2 enfuse_pro_2 is now enfuseAdvanced --- contrib/enfuse_pro_2.lua | 1026 -------------------------------------- 1 file changed, 1026 deletions(-) delete mode 100644 contrib/enfuse_pro_2.lua diff --git a/contrib/enfuse_pro_2.lua b/contrib/enfuse_pro_2.lua deleted file mode 100644 index b2624df..0000000 --- a/contrib/enfuse_pro_2.lua +++ /dev/null @@ -1,1026 +0,0 @@ ---[[ - Enfuse professional plugin for darktable 2.2.X and 2.4.X - - copyright (c) 2017, 2018 Holger Klemm (Original Linux-only version) - - darktable is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - darktable is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with darktable. If not, see . -]] - ---[[ Enfuse Pro 2 - cross-platform compatible -Modified by: Kevin Ertel - -ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT -* align_image_stack -* enfuse -* exiftool - -USAGE -* require this file from your main luarc config file. -* On the initial startup go to darktable settings > lua options and set your executable paths and other preferences, then restart darktable - -This plugin will add the new export module "fusion to DRI or DFF image". -]] - -local dt = require "darktable" -local df = require "lib/dtutils.file" -local gettext = dt.gettext - --- works with LUA API version 5.0.0 -dt.configuration.check_version(...,{5,0,0}) - --- Tell gettext where to find the .mo file translating messages for a particular domain -gettext.bindtextdomain("enfuse_pro",dt.configuration.config_dir.."/lua/") - -local function _(msgid) - return gettext.dgettext("enfuse_pro", msgid) -end - ---Detect User Styles-- -styles = dt.styles -styles_count = 1 -- "none" = 1 -for _,i in pairs(dt.styles) do - if type(i) == "userdata" then styles_count = styles_count + 1 end -end - --- INITS -- -pref_style = dt.preferences.read("module_enfuse_pro", "style", "string") -pref_cpytags = dt.preferences.read("module_enfuse_pro", "copy_tags", "bool") -pref_addtags = dt.preferences.read("module_enfuse_pro", "add_tags", "string") -if dt.configuration.running_os == "windows" then - os_path_seperator = "\\" -else - os_path_seperator = "/" -end - ---Ensure Required Software is Installed-- -not_installed = 0 -dt.print_log("enfuse_pro_2 - Executable Path Preference: "..df.get_executable_path_preference("align_image_stack")) -local AIS_path = df.check_if_bin_exists("align_image_stack") -if not AIS_path then - dt.print_error("align image stack not found") - dt.print("ERROR - align image stack not found") - not_installed = 1 -end - -dt.print_log("enfuse_pro_2 - Executable Path Preference: "..df.get_executable_path_preference("enfuse")) -local enfuse_path = df.check_if_bin_exists("enfuse") -if not enfuse_path then - dt.print_error("enfuse not found") - dt.print("ERROR - enfuse not found") - not_installed = 1 -end - -dt.print_log("enfuse_pro_2 - Executable Path Preference: "..df.get_executable_path_preference("exiftool")) -local exiftool_path = df.check_if_bin_exists("exiftool") -if not exiftool_path then - dt.print_error("exiftool not found") - dt.print("ERROR - exiftool not found") - not_installed = 1 -end - ---Ensure proper version of Enfuse installed-- - --[[ - enfuseVersionStartCommand='enfuse --version | grep "enfuse 4.2"' - enfuse_version=dt.control.execute(enfuseVersionStartCommand) - if (enfuse_version ~= 0) then - dt.print(_('ERROR: wrong enfuse version found. the plugin works only with enfuse 4.2! please install enfuse version 4.2')) - not_installed = 1 - end]] - --- align defaults ---dt.preferences.write("enfuse_pro", "initialized", "bool", false) -if not(dt.preferences.read("enfuse_pro", "initialized", "bool")) then - dt.preferences.write("enfuse_pro", "selected_fusion", "integer", 1) - dt.preferences.write("enfuse_pro", "def_radial_distortion", "bool", false) - dt.preferences.write("enfuse_pro", "def_optimize_field", "bool", false) - dt.preferences.write("enfuse_pro", "def_optimize_image_center", "bool", true) - dt.preferences.write("enfuse_pro", "def_auto_crop", "bool", true) - dt.preferences.write("enfuse_pro", "def_distortion", "bool", true) - dt.preferences.write("enfuse_pro", "def_grid_size", "integer", 5) - dt.preferences.write("enfuse_pro", "def_control_points", "integer", 8) - dt.preferences.write("enfuse_pro", "def_control_points_remove", "integer", 3) - dt.preferences.write("enfuse_pro", "def_correlation", "integer", 9) - - -- enfuse defaults - dt.preferences.write("enfuse_pro", "def_fusion_type", "integer", 1) - dt.preferences.write("enfuse_pro", "def_image_variants", "bool", false) - dt.preferences.write("enfuse_pro", "def_hard_masks", "bool", false) - dt.preferences.write("enfuse_pro", "def_save_masks", "bool", false) - dt.preferences.write("enfuse_pro", "def_contrast_window_size", "integer", 3) - dt.preferences.write("enfuse_pro", "def_contrast_edge_scale", "integer", 1) - dt.preferences.write("enfuse_pro", "def_contrast_min_curvature", "integer", 1) - dt.preferences.write("enfuse_pro", "def_exposure_weight", "float", 1.0) - dt.preferences.write("enfuse_pro", "def_saturation_weight", "float", 0.2) - dt.preferences.write("enfuse_pro", "def_contrast_weight", "float", 0.0) - dt.preferences.write("enfuse_pro", "def_exposure_optimum_weight", "float", 0.5) - dt.preferences.write("enfuse_pro", "def_exposure_width_weight", "float",0.2) - dt.preferences.write("enfuse_pro", "selected_overwrite", "integer",1) - dt.preferences.write("enfuse_pro", "sentitiv_overwrite", "bool",true) - - -- preset DRI 1 - temp_text = {"dri1_","dri2_","dri3_"} - for i,preset in pairs(temp_text) do - dt.preferences.write("enfuse_pro", preset.."hard_masks", "bool", false) - dt.preferences.write("enfuse_pro", preset.."save_masks", "bool", false) - dt.preferences.write("enfuse_pro", preset.."contrast_window_size", "integer", 3) - dt.preferences.write("enfuse_pro", preset.."contrast_edge_scale", "integer", 1) - dt.preferences.write("enfuse_pro", preset.."contrast_min_curvature", "integer", 1) - dt.preferences.write("enfuse_pro", preset.."exposure_weight", "float", 1.0) - dt.preferences.write("enfuse_pro", preset.."saturation_weight", "float", 0.2) - dt.preferences.write("enfuse_pro", preset.."contrast_weight", "float", 0.0) - dt.preferences.write("enfuse_pro", preset.."exposure_optimum_weight", "float", 0.5) - dt.preferences.write("enfuse_pro", preset.."exposure_width_weight", "float",0.2) - end - - -- preset DFF 1 - temp_text = {"dff1_","dff2_","dff3_"} - for i,preset in pairs(temp_text) do - dt.preferences.write("enfuse_pro", preset.."hard_masks", "bool", true) - dt.preferences.write("enfuse_pro", preset.."save_masks", "bool", false) - dt.preferences.write("enfuse_pro", preset.."contrast_window_size", "integer", 3) - dt.preferences.write("enfuse_pro", preset.."contrast_edge_scale", "integer", 1) - dt.preferences.write("enfuse_pro", preset.."contrast_min_curvature", "integer", 1) - dt.preferences.write("enfuse_pro", preset.."exposure_weight", "float", 0.0) - dt.preferences.write("enfuse_pro", preset.."saturation_weight", "float", 0.0) - dt.preferences.write("enfuse_pro", preset.."contrast_weight", "float", 1.0) - dt.preferences.write("enfuse_pro", preset.."exposure_optimum_weight", "float", 0.5) - dt.preferences.write("enfuse_pro", preset.."exposure_width_weight", "float",0.2) - end - - -- preset FREE - dt.preferences.write("enfuse_pro", "free_hard_masks", "bool", false) - dt.preferences.write("enfuse_pro", "free_save_masks", "bool", false) - dt.preferences.write("enfuse_pro", "free_contrast_window_size", "integer", 3) - dt.preferences.write("enfuse_pro", "free_contrast_edge_scale", "integer", 1) - dt.preferences.write("enfuse_pro", "free_contrast_min_curvature", "integer", 1) - dt.preferences.write("enfuse_pro", "free_exposure_weight", "float", 0.0) - dt.preferences.write("enfuse_pro", "free_saturation_weight", "float", 0.0) - dt.preferences.write("enfuse_pro", "free_contrast_weight", "float", 0.0) - dt.preferences.write("enfuse_pro", "free_exposure_optimum_weight", "float", 0.0) - dt.preferences.write("enfuse_pro", "free_exposure_width_weight", "float",0.0) - - -- output - dt.preferences.write("enfuse_pro", "selected_output_format", "integer", 1) - dt.preferences.write("enfuse_pro", "initialized", "bool", true) -end - ---GUI -j=0 -local separator1 = dt.new_widget("separator"){} -local separator1b = dt.new_widget("separator"){} -local separator2 = dt.new_widget("separator"){} -local separator2b = dt.new_widget("separator"){} -local label_align_options= dt.new_widget("section_label"){ - label = _('image align options') -} -local label_enfuse_options= dt.new_widget("section_label"){ - label = _('image fusion options') -} -local label_output_format= dt.new_widget("section_label"){ - label = _('target file') -} -local label_path = dt.new_widget("label"){ - label = _('directory'), - ellipsize = "start", - halign = "start" -} -chkbtn_radial_distortion = dt.new_widget("check_button"){ - label = _('optimize radial distortion for all images'), - value = dt.preferences.read("enfuse_pro", "def_radial_distortion", "bool"), - tooltip = _('optimize radial distortion for all images, \nexcept for first'), -} -chkbtn_optimize_field = dt.new_widget("check_button"){ - label = _('optimize field of view for all images'), - value = dt.preferences.read("enfuse_pro", "def_optimize_field", "bool"), - tooltip =_('optimize field of view for all images, except for first. \nUseful for aligning focus stacks (DFF) with slightly \ndifferent magnification.'), -} -chkbtn_optimize_image_center = dt.new_widget("check_button"){ - label = _('optimize image center shift for all images'), - value = dt.preferences.read("enfuse_pro", "def_optimize_image_center", "bool"), - tooltip =_('optimize image center shift for all images, \nexcept for first.'), -} -chkbtn_auto_crop = dt.new_widget("check_button"){ - label = _('auto crop the image'), - value = dt.preferences.read("enfuse_pro", "def_auto_crop", "bool"), - tooltip =_('auto crop the image to the area covered by all images.'), -} -chkbtn_distortion = dt.new_widget("check_button"){ - label = _('load distortion from lens database'), - value = dt.preferences.read("enfuse_pro", "def_distortion", "bool"), - tooltip =_('try to load distortion information from lens database'), -} -chkbtn_hard_masks = dt.new_widget("check_button"){ - label = _('hard mask'), - value = dt.preferences.read("enfuse_pro", "def_hard_masks", "bool"), - tooltip =_('force hard blend masks on the finest scale. this avoids \naveraging of fine details (only), at the expense \nof increasing the noise. this improves the \nsharpness of focus stacks considerably.\ndefault (soft mask)'), - reset_callback = function(self) - self.value = dt.preferences.read("enfuse_pro", "def_hard_masks", "bool") - end -} -chkbtn_save_masks = dt.new_widget("check_button"){ - label = _('save masks'), - value = dt.preferences.read("enfuse_pro", "def_save_masks", "bool"), - tooltip =_('Save the generated weight masks to your home directory,\nenblend saves masks as 8 bit grayscale, \ni.e. single channel images. \nfor accuracy we recommend to choose a lossless format.'), - reset_callback = function(self) - self.value = dt.preferences.read("enfuse_pro", "def_save_masks", "bool") - end -} -chkbtn_cpytags = dt.new_widget("check_button"){ - label = ' Copy Tags', - value = pref_cpytags, - tooltip ='Copy tags from first image.', -} -sldr_exposure_weight = dt.new_widget("slider"){ - label = _('exposure weight'), - tooltip = _('set the relative weight of the well-exposedness criterion \nas defined by the chosen exposure weight function. \nincreasing this weight relative to the others will\n make well-exposed pixels contribute more to\n the final output. \ndefault: (1.0)'), - hard_min = 0, - hard_max = 1, - value = dt.preferences.read("enfuse_pro", "def_exposure_weight", "float") --1 def -} -sldr_saturation_weight = dt.new_widget("slider"){ - label = _('saturation weight'), - tooltip = _('set the relative weight of high-saturation pixels. \nincreasing this weight makes pixels with high \nsaturation contribute more to the final output. \ndefault: (0.2)'), - hard_min = 0, - hard_max = 1, - value = dt.preferences.read("enfuse_pro", "def_saturation_weight", "float"), --0.5 -} -sldr_contrast_weight = dt.new_widget("slider"){ - label = _('contrast weight'), - tooltip = _('sets the relative weight of high local-contrast pixels. \ndefault: (0.0).'), - hard_min = 0, - hard_max = 1, - value = dt.preferences.read("enfuse_pro", "def_contrast_weight", "float")--0 default -} -sldr_exposure_optimum_weight = dt.new_widget("slider"){ - label = _('exposure optimum'), - tooltip = _('determine at what normalized exposure value\n the optimum exposure of the input images\n is. this is, set the position of the maximum\n of the exposure weight curve. use this \noption to fine-tune exposure weighting. \ndefault: (0.5)'), - hard_min = 0, - hard_max = 1, - value = dt.preferences.read("enfuse_pro", "def_exposure_optimum_weight", "float")--0.5 default0 -} -sldr_exposure_width_weight = dt.new_widget("slider"){ - label = _('exposure width'), - tooltip = _('set the characteristic width (FWHM) of the exposure \nweight function. low numbers give less weight to \npixels that are far from the user-defined \noptimum and vice versa. use this option to \nfine-tune exposure weighting. \ndefault: (0.2)'), - hard_min = 0, - hard_max = 1, - value = dt.preferences.read("enfuse_pro", "def_exposure_width_weight", "float") --0.2 default -} -file_chooser_button_path = dt.new_widget("file_chooser_button"){ - title = _('Select export path'), -- The title of the window when choosing a file - is_directory = true, -- True if the file chooser button only allows directories to be selecte - tooltip =_('select the target directory for the fused image. \nthe filename is created automatically.'), -} -chkbtn_source_location = dt.new_widget("check_button"){ - label = _('save to source image location'), - value = true, - tooltip =_('If checked ignores the location below and saves output image(s) to the same location as the source images.'), - reset_callback = function(self) - self.value = true - end -} -cmbx_grid_size = dt.new_widget("combobox"){ - label = _('image grid size'), - tooltip =_('break image into a rectangular grid \nand attempt to find num control points in each section.\ndefault: (5x5)'), - value = dt.preferences.read("enfuse_pro", "def_grid_size", "integer"), --5 - "1", "2", "3","4","5","6","7","8","9", - reset_callback = function(self) - self.value = dt.preferences.read("enfuse_pro", "def_grid_size", "integer") - end -} -cmbx_control_points = dt.new_widget("combobox"){ - label = _('control points/grid'), - tooltip =_('number of control points (per grid, see option -g) \nto create between adjacent images \ndefault: (8).'), - value = dt.preferences.read("enfuse_pro", "def_control_points", "integer"), --8, "1", "2", "3","4","5","6","7","8","9", - "1", "2", "3","4","5","6","7","8","9", - reset_callback = function(self) - self.value = dt.preferences.read("enfuse_pro", "def_control_points", "integer") - end -} -cmbx_control_points_remove = dt.new_widget("combobox"){ - label = _('remove control points with error'), - tooltip =_('remove all control points with an error higher \nthan num pixels \ndefault: (3)'), - value = dt.preferences.read("enfuse_pro", "def_control_points_remove", "integer"), --3, "1", "2", "3","4","5","6","7","8","9", - "1", "2", "3","4","5","6","7","8","9", - reset_callback = function(self) - self.value = dt.preferences.read("enfuse_pro", "def_control_points_remove", "integer") - end -} -cmbx_correlation = dt.new_widget("combobox"){ - label = _('correlation threshold for control points'), - tooltip =_('correlation threshold for identifying \ncontrol points \ndefault: (0.9).'), - value = dt.preferences.read("enfuse_pro", "def_correlation", "integer"), --9, "0,1", "0,2", "0,3","0,4","0,5","0,6","0,7","0,8","0,9", - "0.1", "0.2", "0.3","0.4","0.5","0.6","0.7","0.8","0.9","1.0", - reset_callback = function(self) - self.value = dt.preferences.read("enfuse_pro", "def_correlation", "integer") - end -} -cmbx_contrast_window_size = dt.new_widget("combobox"){ - label = _('contrast window size'), - tooltip =_('set the window size for local contrast analysis. \nthe window will be a square of size × size pixels. \nif given an even size, Enfuse will \nautomatically use the next odd number.\nfor contrast analysis size values larger \nthan 5 pixels might result in a \nblurry composite image. values of 3 and \n5 pixels have given good results on \nfocus stacks. \ndefault: (5) pixels'), - value = dt.preferences.read("enfuse_pro", "def_contrast_window_size", "integer"), --3, "3","4","5","6","7","8","9","10", - "3", "4", "5","6","7","8","9","10", -} -cmbx_contrast_edge_scale = dt.new_widget("combobox"){ - label = _('contrast edge scale'), - tooltip =_('a non-zero value for EDGE-SCALE switches on the \nLaplacian-of-Gaussian (LoG) edge detection algorithm.\n edage-scale is the radius of the Gaussian used \nin the search for edges. a positive LCE-SCALE \nturns on local contrast enhancement (LCE) \nbefore the LoG edge detection. \nDefault: (0.0) pixels.'), - value = dt.preferences.read("enfuse_pro", "def_contrast_edge_scale", "integer"), --1, "0:0:0", - "0.0","0.1","0.2","0.3","0.4","0.5", - -} -cmbx_contrast_min_curvature = dt.new_widget("combobox"){ - label = _('contrast min curvature'), - tooltip =_('define the minimum curvature for the LoG edge detection. Append a ‘%’ to specify the minimum curvature relative to maximum pixel value in the source image. Default: (0.0%)'), - value = dt.preferences.read("enfuse_pro", "def_contrast_min_curvature", "integer"), --1, "0.0%","0.1%", "0.2%", "0.3%","0.4%","0.5%","0.6%","0.7%","0.8%","0.9%","1.0%", - "0.0%", "0.1%", "0.2%","0.3%","0.4%","0.5%","0.6%","0.7%","0.8%","0.9%","1.0%", -} -cmbx_existing_file = dt.new_widget("combobox"){ - label = _('on conflict'), - value = dt.preferences.read("enfuse_pro", "selected_overwrite", "integer"), --1, - sensitive= dt.preferences.read("enfuse_pro", "sentitiv_overwrite", "bool"), --1, - _('create unique filename'),_('overwrite'), - reset_callback = function(self) - self.value = dt.preferences.read("enfuse_pro", "selected_overwrite", "integer") - end -} -cmbx_style = dt.new_widget("combobox"){ - label = "Apply Style on Import", - tooltip = "Apply selected style on auto-import to newly created blended image", - value = 1, - "none", - } -pref_style_enum = 1 -for k=1, (styles_count-1) do - cmbx_style[k+1] = styles[k].name - if styles[k].name == pref_style then pref_style_enum = k+1 end -end -cmbx_style.value = pref_style_enum -chkbtn_image_variations = dt.new_widget("check_button"){ - label = _('create image variants with saved presets'), - value = dt.preferences.read("enfuse_pro", "def_image_variants", "bool"), - tooltip =_('creates image variants with the three \nsaved DRI or DFF presets'), - sensitive=true, - clicked_callback = function(self) - if (self.value) then - dt.preferences.write("enfuse_pro", "def_image_variants", "bool", true) - dt.preferences.write("enfuse_pro", "sentitiv_overwrite", "bool",false) - cmbx_existing_file.value=1 - cmbx_existing_file.sensitive=false - else - dt.preferences.write("enfuse_pro", "def_image_variants", "bool", false) - dt.preferences.write("enfuse_pro", "sentitiv_overwrite", "bool",true) - cmbx_existing_file.sensitive=true - end - end, - reset_callback = function(self) - dt.preferences.write("enfuse_pro", "def_image_variants", "bool", false) - dt.preferences.write("enfuse_pro", "sentitiv_overwrite", "bool",true) - self.value = false - cmbx_existing_file.sensitive=true - end - -} -button_save_preset = dt.new_widget("button"){ - label = _('save fusion preset'), - tooltip =_('save the selected fusion preset'), - clicked_callback = function() - pref_text = "" - if (cmbx_fusion_type.value == "1 - DRI image") then - pref_text = "dri1_" - elseif (cmbx_fusion_type.value == "2 - DRI image") then - pref_text = "dri2_" - elseif (cmbx_fusion_type.value == "3 - DRI image") then - pref_text = "dri3_" - elseif (cmbx_fusion_type.value == "1 - DFF image") then - pref_text = "dff1_" - elseif (cmbx_fusion_type.value == "2 - DFF image") then - pref_text = "dff2_" - elseif (cmbx_fusion_type.value == "3 - DFF image") then - pref_text = "dff3_" - elseif (cmbx_fusion_type.value == "free preset") then - pref_text = "free_" - else - dt.print(_('unkown error')) - end - -- Write Preset - if pref_text ~= "" then - dt.preferences.write("enfuse_pro", pref_text.."hard_masks", "bool", chkbtn_hard_masks.value) - dt.preferences.write("enfuse_pro", pref_text.."save_masks", "bool", chkbtn_save_masks.value) - dt.preferences.write("enfuse_pro", pref_text.."contrast_window_size", "integer", cmbx_contrast_window_size.selected) - dt.preferences.write("enfuse_pro", pref_text.."contrast_edge_scale", "integer", cmbx_contrast_edge_scale.selected) - dt.preferences.write("enfuse_pro", pref_text.."contrast_min_curvature", "integer", cmbx_contrast_min_curvature.selected) - dt.preferences.write("enfuse_pro", pref_text.."exposure_weight", "float", sldr_exposure_weight.value) - dt.preferences.write("enfuse_pro", pref_text.."saturation_weight", "float", sldr_saturation_weight.value) - dt.preferences.write("enfuse_pro", pref_text.."contrast_weight", "float", sldr_contrast_weight.value) - dt.preferences.write("enfuse_pro", pref_text.."exposure_optimum_weight", "float", sldr_exposure_optimum_weight.value) - dt.preferences.write("enfuse_pro", pref_text.."exposure_width_weight", "float",sldr_exposure_width_weight.value) - dt.print(_('preset '..pref_text..' saved')) - end - end -} -button_load_preset = dt.new_widget("button"){ - label = _('load fusion defaults'), - tooltip =_('load the default fusion settings'), - clicked_callback = function() - chkbtn_hard_masks.value=dt.preferences.read("enfuse_pro", "def_hard_masks", "bool") - chkbtn_save_masks.value=dt.preferences.read("enfuse_pro", "def_save_masks", "bool") - cmbx_contrast_window_size.value=dt.preferences.read("enfuse_pro", "def_contrast_window_size", "integer") - cmbx_contrast_edge_scale.value=dt.preferences.read("enfuse_pro", "def_contrast_edge_scale", "integer") - cmbx_contrast_min_curvature.value=dt.preferences.read("enfuse_pro", "def_contrast_min_curvature", "integer") - sldr_exposure_weight.value=dt.preferences.read("enfuse_pro", "def_exposure_weight", "float") - sldr_saturation_weight.value=dt.preferences.read("enfuse_pro", "def_saturation_weight", "float") - sldr_contrast_weight.value=dt.preferences.read("enfuse_pro", "def_contrast_weight", "float") - sldr_exposure_optimum_weight.value=dt.preferences.read("enfuse_pro", "def_exposure_optimum_weight", "float") - sldr_exposure_width_weight.value=dt.preferences.read("enfuse_pro", "def_exposure_width_weight", "float") - end - -} -cmbx_output_format = dt.new_widget("combobox"){ - label = _('file format'), - value = dt.preferences.read("enfuse_pro", "selected_output_format", "integer"), --1, "TIFF", "JPEG", "PNG","PNM","PBM","PGM","PPM", - changed_callback = function(self) - dt.preferences.write("enfuse_pro", "selected_output_format", "integer", self.selected) - end, - "TIFF", "JPEG", "PNG","PNM","PBM","PPM", - reset_callback = function(self) - self.value = dt.preferences.read("enfuse_pro", "selected_output_format", "integer") - end -} -cmbx_fusion_type = dt.new_widget("combobox"){ - label = _('fusion preset'), - tooltip =_('select the preset and save the preset\n if you want to reuse it or create an image\n variant'), - value = 1, --dt.preferences.read("enfuse_pro", "def_fusion_type", "integer"), --1, "DRI image", "DFF image", "without preset", - changed_callback = function(self) - dt.preferences.write("enfuse_pro", "def_fusion_type", "integer", self.selected) - - if (self.value == "1 - DRI image") then - pref_text = "dri1_" - elseif (self.value == "2 - DRI image") then - pref_text = "dri2_" - elseif (self.value == "3 - DRI image") then - pref_text = "dri3_" - elseif (self.value == "1 - DFF image") then - pref_text = "dff1_" - elseif (self.value == "2 - DFF image") then - pref_text = "dff2_" - elseif (self.value == "3 - DFF image") then - pref_text = "dff3_" - elseif (self.value == "free preset") then - pref_text = "free_" - end - - if string.match(pref_text,"^dri")~=nil then - chkbtn_hard_masks.sensitive=false - chkbtn_hard_masks.value=false - sldr_contrast_weight.sensitive=true - elseif string.match(pref_text,"^dff")~=nil then - chkbtn_hard_masks.sensitive=false - chkbtn_hard_masks.value=true - sldr_contrast_weight.sensitive=false - else - chkbtn_hard_masks.sensitive=true - chkbtn_hard_masks.value=false - sldr_contrast_weight.sensitive=true - end - - chkbtn_hard_masks.value=dt.preferences.read("enfuse_pro", pref_text.."hard_masks", "bool") - chkbtn_save_masks.value=dt.preferences.read("enfuse_pro", pref_text.."save_masks", "bool") - cmbx_contrast_window_size.value=dt.preferences.read("enfuse_pro", pref_text.."contrast_window_size", "integer") - cmbx_contrast_edge_scale.value=dt.preferences.read("enfuse_pro", pref_text.."contrast_edge_scale", "integer") - cmbx_contrast_min_curvature.value=dt.preferences.read("enfuse_pro", pref_text.."contrast_min_curvature", "integer") - sldr_exposure_weight.value=dt.preferences.read("enfuse_pro", pref_text.."exposure_weight", "float") - sldr_saturation_weight.value=dt.preferences.read("enfuse_pro", pref_text.."saturation_weight", "float") - sldr_contrast_weight.value=dt.preferences.read("enfuse_pro", pref_text.."contrast_weight", "float") - sldr_exposure_optimum_weight.value=dt.preferences.read("enfuse_pro", pref_text.."exposure_optimum_weight", "float") - sldr_exposure_width_weight.value=dt.preferences.read("enfuse_pro", pref_text.."exposure_width_weight", "float") - - end, - "1 - DRI image", "2 - DRI image","3 - DRI image","1 - DFF image", "2 - DFF image","3 - DFF image","free preset", - - reset_callback = function(self_type) - cmbx_fusion_type.value = dt.preferences.read("enfuse_pro", "def_fusion_type", "integer") - end -} -entry_tag = dt.new_widget("entry"){ - tooltip = "Additional tags to be added on import. Seperate with commas, all spaces will be removed", - text = pref_addtags, - placeholder = "Enter tags, seperated by commas", - editable = true -} -local widget = dt.new_widget("box") { - orientation = "vertical", - label_align_options, - chkbtn_radial_distortion, - chkbtn_optimize_field, - chkbtn_optimize_image_center, - chkbtn_auto_crop, - chkbtn_distortion, - cmbx_grid_size, - cmbx_control_points, - cmbx_control_points_remove, - cmbx_correlation, - separator1, - separator1b, - label_enfuse_options, - cmbx_fusion_type, - chkbtn_image_variations, - sldr_exposure_weight, - sldr_saturation_weight, - sldr_contrast_weight, - sldr_exposure_optimum_weight, - sldr_exposure_width_weight, - chkbtn_hard_masks, - chkbtn_save_masks, - cmbx_contrast_edge_scale, - cmbx_contrast_min_curvature, - cmbx_contrast_window_size, - button_save_preset, - button_load_preset, - separator2, - separator2b, - label_output_format, - cmbx_output_format, - label_path, - file_chooser_button_path, - chkbtn_source_location, - cmbx_existing_file, - cmbx_style, - chkbtn_cpytags, - entry_tag, -} - --- FUNCTION -- -local function GetFileName(full_path) - --[[Parses a full path (path/filename_identifier.extension) into individual parts - Input: Folder1/Folder2/Folder3/Img_0001.CR2 - - Returns: - path: Folder1/Folder2/Folder3/ - filename: Img_0001 - identifier: 0001 - extension: .CR2 - - EX: - path_1, file_1, id_1, ext_1 = GetFileName(full_path_1) - ]] - local path = string.match(full_path, ".*[\\/]") - local filename = string.gsub(string.match(full_path, "[%w-_]*%.") , "%." , "" ) - local identifier = string.match(filename, "%d*$") - local extension = string.match(full_path, "%.%w*") - return path, filename, identifier, extension -end -local function truncate(x) - return x<0 and math.ceil(x) or math.floor(x) -end -local function replace_comma_to_dot(s) - return string.gsub(s, "%,", ".") -end -local function remove_temp_files() - if dt.configuration.running_os == "windows" then - dt.print_log("Deleting temp files...") - dt.control.execute("del "..images_to_align) - dt.control.execute("del "..images_to_blend) - dt.print_log("Done deleting") - else - dt.print_log("Deleting temp files...") - dt.control.execute("rm "..images_to_align) - dt.control.execute("rm "..images_to_blend) - dt.print_log("Done deleting") - end -end -local function build_execute_command(cmd, args, file_list) - local result = false - - if dt.configuration.running_os == "macos" then - cmd = string.gsub(cmd, "open", "") - cmd = string.gsub(cmd, "-W", "") - cmd = string.gsub(cmd, "-a", "") - end - result = cmd.." "..args.." "..file_list - return result -end -function copy_exif() - exiftool_path = string.gsub(exiftool_path, "open", "") - exiftool_path = string.gsub(exiftool_path, "-W", "") - exiftool_path = string.gsub(exiftool_path, "-a", "") - if dt.configuration.running_os == "windows" then - exifStartCommand = exiftool_path.." -TagsFromFile "..source_file.." -exif:all --subifd:all -overwrite_original "..path_with_filename - else - exifStartCommand = exiftool_path.." -TagsFromFile "..'"'..source_file..'"'.." -exif:all --subifd:all -overwrite_original "..'"'..path_with_filename..'"' - end - dt.print_log("EXIFTool Start Command: "..exifStartCommand) - resultexif=dt.control.execute(exifStartCommand) - if (resultexif == 0) then - dt.print_log("EXIFTool copy successful") - dt.print("Copied EXIF data") - else - dt.print(_('ERROR: exiftool doesn\'t work. for more informations see terminal output')) - dt.print_error("exif copy failed") - end -end -function align_images() - dt.print(_('aligning images')) - - --Setup Align Image Stack Arguments-- - align_args = "" - if (chkbtn_radial_distortion.value) then align_args = align_args.." -d" end - if (chkbtn_optimize_field.value) then align_args = align_args.." -m" end - if (chkbtn_optimize_image_center.value) then align_args = align_args.." -i" end - if (chkbtn_auto_crop.value) then align_args = align_args.." -C" end - if (chkbtn_distortion.value) then align_args = align_args.." --distortion" end - align_args = align_args.." -g "..cmbx_grid_size.value - align_args = align_args.." -c "..cmbx_control_points.value - align_args = align_args.." -t "..cmbx_control_points_remove.value - align_args = align_args.." --corr="..cmbx_correlation.value - if (dt.preferences.read("module_enfuse_pro", "align_use_gpu", "bool")) then align_args = align_args.." --gpu" end - if dt.configuration.running_os == "windows" then - align_args = align_args.." -a "..first_path.."aligned_ " - else - align_args = align_args.." -a "..'"'..first_path..'aligned_" ' - end - alignStartCommand = build_execute_command(AIS_path, align_args, images_to_align) - dt.print_log("Align Start Command: "..alignStartCommand) - resp = dt.control.execute(alignStartCommand) - dt.print_log("Completed Align") - return resp -end -function blend_images() - blend_args = "" - if from_preset then --load args from preset preferences - blend_args=blend_args.." --exposure-weight="..(replace_comma_to_dot(dt.preferences.read("enfuse_pro", preset_text.."_exposure_weight", "float"))) - blend_args=blend_args.." --saturation-weight="..(replace_comma_to_dot(dt.preferences.read("enfuse_pro", preset_text.."_saturation_weight", "float"))) - blend_args=blend_args.." --contrast-weight="..(replace_comma_to_dot(dt.preferences.read("enfuse_pro", preset_text.."_contrast_weight", "float"))) - blend_args=blend_args.." --exposure-optimum="..(replace_comma_to_dot(dt.preferences.read("enfuse_pro", preset_text.."_exposure_optimum_weight", "float"))) - blend_args=blend_args.." --exposure-width="..(replace_comma_to_dot(dt.preferences.read("enfuse_pro", preset_text.."_exposure_width_weight", "float"))) - if (chkbtn_hard_masks.value) then blend_args=blend_args.."--hard-mask" end - if (chkbtn_save_masks.value) then blend_args=blend_args.."--save-masks" end - blend_args=blend_args.." --contrast-window-size="..dt.preferences.read("enfuse_pro", preset_text.."_contrast_window_size", "integer") - blend_args=blend_args.." --contrast-edge-scale="..dt.preferences.read("enfuse_pro", preset_text.."_contrast_edge_scale", "integer") - blend_args=blend_args.." --contrast-min-curvature="..dt.preferences.read("enfuse_pro", preset_text.."_contrast_min_curvature", "integer") - blend_args=blend_args.." --depth="..dt.preferences.read("module_enfuse_pro", "image_color_depth", "enum") - else --load args from GUI values - blend_args = blend_args.." --exposure-weight="..(replace_comma_to_dot(sldr_exposure_weight.value)) - blend_args = blend_args.." --saturation-weight="..(replace_comma_to_dot(sldr_saturation_weight.value)) - blend_args = blend_args.." --contrast-weight="..(replace_comma_to_dot(sldr_contrast_weight.value)) - blend_args = blend_args.." --exposure-optimum="..(replace_comma_to_dot(sldr_exposure_optimum_weight.value)) - blend_args = blend_args.." --exposure-width="..(replace_comma_to_dot(sldr_exposure_width_weight.value)) - if (chkbtn_hard_masks.value) then blend_args = blend_args.." --hard-mask" end - if (chkbtn_save_masks.value) then blend_args = blend_args.." --save-masks" end - blend_args = blend_args.." --contrast-window-size="..cmbx_contrast_window_size.value - blend_args = blend_args.." --contrast-edge-scale="..cmbx_contrast_edge_scale.value - blend_args = blend_args.." --contrast-min-curvature="..cmbx_contrast_min_curvature.value - blend_args = blend_args.." --depth="..dt.preferences.read("module_enfuse_pro", "image_color_depth", "enum") - end - - --set output format per GUI selection - if (cmbx_output_format.value == "TIFF") then - cmd_suffix_output_format="tif" - blend_args = blend_args.." --compression="..dt.preferences.read("module_enfuse_pro", "compression_tiff", "enum") - elseif (cmbx_output_format.value == "JPEG") then - cmd_suffix_output_format="jpg" - blend_args = blend_args.." --compression="..truncate(dt.preferences.read("module_enfuse_pro", "compression_jpeg", "integer")) - elseif (cmbx_output_format.value == "PNG") then - cmd_suffix_output_format="png" - elseif (cmbx_output_format.value == "PNM") then - cmd_suffix_output_format="pnm" - elseif (cmbx_output_format.value == "PBM") then - cmd_suffix_output_format="pbm" - elseif (cmbx_output_format.value == "PPM") then - cmd_suffix_output_format="ppm" - end - - --Set output path and add filename - if (chkbtn_source_location.value) then - cmd_output_path = source_path - else - cmd_output_path=file_chooser_button_path.value - end - path_with_filename = cmd_output_path..os_path_seperator..first_filename.."-"..last_id.."."..cmd_suffix_output_format - - --Create unique name with index if GUI selection create unique name (don't overwrite), also do this if user selected to make variants from presets - if (cmbx_existing_file.selected == 1) or (from_preset) then - path_with_filename = df.create_unique_filename(path_with_filename) - end - - if dt.configuration.running_os == "windows" then - cmd_output_image = " --output="..path_with_filename - else - cmd_output_image = " --output="..'"'..path_with_filename..'"' - - end - blend_args = blend_args..cmd_output_image - - images_to_blend = "" - for j=0, counted_images-1 do - if j < 10 then - id = "000"..tostring(j) - else - id = "00"..tostring(j) - end - if dt.configuration.running_os == "windows" then - images_to_blend = images_to_blend..first_path.."aligned_"..id..".tif " - else - images_to_blend = images_to_blend..'"'..first_path.."aligned_"..id..".tif"..'" ' - end - end - BlendStartCommand=build_execute_command(enfuse_path, blend_args, images_to_blend) - - dt.print_log("Blend Start Command: "..BlendStartCommand) - resultBlend=dt.control.execute(BlendStartCommand) - dt.print_log("Completed Blend") - - return resultBlend, path_with_filename -end -local function show_status(storage, image, format, filename, --Store: Called on each exported image - number, total, high_quality, extra_data) - dt.print(_('export TIFF for image fusion ')..tostring(truncate(number)).." / "..tostring(truncate(total))) -end -function create_image_fusion(storage, image_table, extra_data) --Finalize: Called once when all images are done exporting ---Create Images String-- - images_to_align = "" - images_to_blend = "" - counted_images=0 - first_id = "999999999999999999999999" - last_id = "0" - for source_image,image_path in pairs(image_table) do - counted_images=counted_images+1 - if dt.configuration.running_os == "windows" then - images_to_align = images_to_align..image_path..' ' - else - images_to_align = images_to_align..'"'..image_path..'" ' - end - curr_path, curr_filename, curr_id, curr_ext = GetFileName(image_path) - if (curr_id < first_id) then - first_path = curr_path - first_filename = curr_filename - first_id = curr_id - first_ext = curr_ext - dt_source_image = source_image - end - if (curr_id > last_id) then - last_path = curr_path - last_filename = curr_filename - last_id = curr_id - last_ext = curr_ext - end - source_path = source_image.path - source_file = source_image.path..os_path_seperator..source_image.filename - end - ---Check if at least 2 images selected-- - if (counted_images<=1) then - dt.print(_('ERROR: not enough pictures selected. please select two or more images\nfrom the same object, but with different camera settings.')) - dt.print_error("Not enough pictures selected") - remove_temp_files() - return - end - ---Ensure Proper Software Installed-- - if not_installed == 1 then - dt.print_log("Required software not installed") - dt.print("Required software not installed") - remove_temp_files() - return - end - ---Check that output path selected - cmd_output_path = file_chooser_button_path.value - if (cmd_output_path == nil) and not(chkbtn_source_location.value) then - dt.print(_('ERROR: no target directory selected')) - remove_temp_files() - return - end - - dt.print_log("Starting Image Fusion") - job = dt.gui.create_job(_('Creating DRI/DFF image'), true, stop_selection) - - percent_step = .33 - if (chkbtn_image_variations.value) then percent_step = .2 end - job.percent = job.percent + percent_step - ---Align Images-- - resultalign = align_images() - if (resultalign ~= 0) then --Aling Image Stack Failed-- - dt.print(_('ERROR: align_image_stack doesn\'t work. For more information see terminal output')) - dt.print_error("Align Image Stack Failed") - remove_temp_files() - job.valid = false - return - end - dt.print(_('aligning complete')) - job.percent = job.percent + percent_step - ---Blend Images-- - from_preset = false - iterations = 1 - pref_text = "" - if (chkbtn_image_variations.value) then - iterations = 3 - from_preset = true - if string.match(cmbx_fusion_type.value, "DRI") then - pref_text = "dri" - elseif string.match(cmbx_fusion_type.value, "DFF") then - pref_text = "dff" - else --if "variants" selected, but not using DRI or DFF preset then cannot create variants - dt.print("Error, must select a DRI or DFF preset when starting a fustion with variants") - dt.print_error("DRI or DFF preset not selected when variants option was checked") - remove_temp_files() - job.valid = false - return - end - end - - for j = 1, iterations do - if (from_preset) then - preset_text=pref_text..j - else - preset_text="" - end - resultBlend, blended_image = blend_images() --Check here to ensure enfuse worked properly - if resultBlend ~= 0 then - dt.print(_('ERROR: enfuse didn\'t work. For more information see terminal output')) - dt.print_error("Enfuse failed") - remove_temp_files() - job.valid = false - return - end - --Copy EXIF Data (IF)-- - if (dt.preferences.read("module_enfuse_pro", "exiftool_copy_tags", "bool")) then copy_exif() end - --Auto-Import-- - if (dt.preferences.read("module_enfuse_pro", "add_image_to_db", "bool")) then - local imported = dt.database.import(path_with_filename) - --Apply Selected Style (IF)-- - if cmbx_style.selected > 1 then - set_style = styles[cmbx_style.selected - 1] - dt.styles.apply(set_style , imported) - end - --Copy Tags (IF)-- - if (chkbtn_cpytags.value) then - all_tags = dt.tags.get_tags(dt_source_image) - for _,tag in pairs(all_tags) do - if string.match(tag.name, 'darktable|') == nil then - dt.tags.attach(tag, imported) - end - end - end - --Apply Entered Tags (IF)-- - set_tag = entry_tag.text - if set_tag ~= nil then - for tag in string.gmatch(set_tag, '[^,]+') do - tag = string.gsub(tag, " ", "") - tag = dt.tags.create(tag) - dt.tags.attach(tag, imported) - end - end - end - job.percent = job.percent + percent_step - end - - --Copy EXIF Data (IF)-- - - remove_temp_files() - dt.print("Image fusion process complete") - dt.print_log("Image fusion process complete") - job.valid = false -end -local function support_format(storage, format) --Supported: Check to make sure image type is supported by darktable - fmt = string.lower(format.name) - if string.match(fmt,"tiff") == nil then - return false - else - return true - end -end - --- REGISTER -- -dt.register_storage("module_enfuse_pro", _('DRI or DFF image'), show_status, create_image_fusion, support_format, nil, widget) - --- PREFERENCES -- -entry_widget_style = dt.new_widget("entry"){ - tooltip = "Enter the style name exactly as it is", - text = nil, - placeholder = "Enter Style name", - editable = true -} -dt.preferences.register("module_enfuse_pro", "style", -- name - "string", -- type - 'enfuse_pro: Defualt Style', -- label - 'Changes DEFAULT entry in the Style option. Requires restart to take effect.', -- tooltip - "", -- default - entry_widget_style -) -entry_widget_tags = dt.new_widget("entry"){ - tooltip = "Seperate with commas, all spaces will be removed", - text = nil, - placeholder = "Enter default tags", - editable = true -} -dt.preferences.register("module_enfuse_pro", "add_tags", -- name - "string", -- type - 'enfuse_pro: Defualt additional tags', -- label - 'Changes DEFAULT entry in the additional tags option. Requires restart to take effect.', -- tooltip - "", -- default - entry_widget_tags -) -dt.preferences.register("module_enfuse_pro", "copy_tags", -- name - "bool", -- type - 'enfuse_pro: Copy tags from first image by default', -- label - 'Changes DEFAULT selection for Copy Tags, Requires restart to take effect.', -- tooltip - true -- default -) -dt.preferences.register("module_enfuse_pro", "exiftool_copy_tags", -- name - "bool", -- type - _('enfuse pro: copy exif data'), -- label - _('copy the exif tags from the first image to the target'), -- tooltip - true) -- default -dt.preferences.register("module_enfuse_pro", "add_image_to_db", -- name - "bool", -- type - _('enfuse pro: add fused image to database'), -- label - _('add the fused image to the darktable database'), -- tooltip - false) -- default -dt.preferences.register("module_enfuse_pro", "align_use_gpu", -- name - "bool", -- type - _('enfuse pro: use GPU for remaping'), -- label - _('set the GPU remapping for image align'), -- tooltip - false) -dt.preferences.register("module_enfuse_pro", "compression_jpeg", -- name - "integer", -- type - _('enfuse pro: JPEG compression'), -- label - _('set the compression for JPEG files'), -- tooltip - 98, -- default - 50, -- min - 100) -- max -dt.preferences.register("module_enfuse_pro", "compression_tiff", -- name - "enum", -- type - _('enfuse pro: TIFF compression'), -- label - _('set the compression type for tiff files'), -- tooltip - "LZW", -- default - "NONE", "DEFLATE","PACKBITS") -- va -dt.preferences.register("module_enfuse_pro", "image_color_depth", -- name - "enum", -- type - _('enfuse pro: image color depth (bit)'), -- label - _('set the output color depth'), -- tooltip - "16", -- default - "8","32","r32","r64") -- values - ---AIS bin location -if not AIS_path then - AIS_path = "" -end -AIS_path_widget = dt.new_widget("file_chooser_button"){ - title = "Select align_image_stack[.exe] file", - value = AIS_path, - is_directory = false, -} -dt.preferences.register("executable_paths", "align_image_stack", -- name - "file", -- type - 'enfuse_pro: Align Image Stack Location', -- label - 'Install location of align_image_stack. Requires restart to take effect.', -- tooltip - "align_image_stack", -- default - AIS_path_widget -) - ---enfuse bin location -if not enfuse_path then - enfuse_path = "" -end -enfuse_path_widget = dt.new_widget("file_chooser_button"){ - title = "Select enfuse[.exe] file", - value = enfuse_path, - is_directory = false, -} -dt.preferences.register("executable_paths", "enfuse", -- name - "file", -- type - 'enfuse_pro: enfuse Location', -- label - 'Install location of enfuse. Requires restart to take effect.', -- tooltip - "enfuse", -- default - enfuse_path_widget -) - ---exiftool bin location -if not exiftool_path then - exiftool_path = "" -end -exiftool_path_widget = dt.new_widget("file_chooser_button"){ - title = "Select exiftool[.exe] file", - value = exiftool_path, - is_directory = false, -} -dt.preferences.register("executable_paths", "exiftool", -- name - "file", -- type - 'enfuse_pro: exiftool Location', -- label - 'Install location of exiftool. Requires restart to take effect.', -- tooltip - "exiftool", -- default - exiftool_path_widget -) - From adb85e349a0db3197e4cb2860814e87b73a1708b Mon Sep 17 00:00:00 2001 From: BzKevin <36381472+BzKevin@users.noreply.github.com> Date: Tue, 18 Sep 2018 11:54:24 -0400 Subject: [PATCH 9/9] Update enfuseAdvanced.lua Fixing accidental "invalid escape" at line 133 --- contrib/enfuseAdvanced.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/enfuseAdvanced.lua b/contrib/enfuseAdvanced.lua index 11eb0db..7c1edd3 100644 --- a/contrib/enfuseAdvanced.lua +++ b/contrib/enfuseAdvanced.lua @@ -130,7 +130,7 @@ end ]] if dt.preferences.read("enfuseAdvanced", "pref_version", "integer") ~= preferences_version then - dt.print_log("enfuseAdvanced - (Re)Initializing preferences due to script load\changes detected") + dt.print_log("enfuseAdvanced - (Re)Initializing preferences due to script load/changes detected") -- align defaults dt.preferences.write("enfuseAdvanced", "selected_fusion", "integer", 1) dt.preferences.write("align_image_stack", "def_radial_distortion", "bool", false)