Comments added, minor updates
I have added comments throughout, mainly to the functions I improved the performance of the CleanSpaces() function Improved communication to user via dt.print()
This commit is contained in:
@@ -58,7 +58,7 @@ dt.preferences.register("executable_paths", "HDRMerge", -- name
|
|||||||
"HDRMerge" -- default
|
"HDRMerge" -- default
|
||||||
)
|
)
|
||||||
local temp
|
local temp
|
||||||
local HDRM = {
|
local HDRM = { --HDRMerge Program Table
|
||||||
name = 'HDRMerge',
|
name = 'HDRMerge',
|
||||||
bin = '',
|
bin = '',
|
||||||
first_run = true,
|
first_run = true,
|
||||||
@@ -72,7 +72,7 @@ local HDRM = {
|
|||||||
gap ={text = '-g ', style = 'integer'}
|
gap ={text = '-g ', style = 'integer'}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
local GUI = {
|
local GUI = { --GUI Elements Table
|
||||||
HDR = {
|
HDR = {
|
||||||
bps ={},
|
bps ={},
|
||||||
size ={},
|
size ={},
|
||||||
@@ -102,9 +102,8 @@ local function InRange(test, low, high) --tests if test value is within range of
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function GetFileName(full_path)
|
local function GetFileName(full_path) --Parses a full path (path/filename_identifier.extension) into individual parts
|
||||||
--[[Parses a full path (path/filename_identifier.extension) into individual parts
|
--[[Input: Folder1/Folder2/Folder3/Img_0001.CR2
|
||||||
Input: Folder1/Folder2/Folder3/Img_0001.CR2
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
path: Folder1/Folder2/Folder3/
|
path: Folder1/Folder2/Folder3/
|
||||||
@@ -122,24 +121,18 @@ local function GetFileName(full_path)
|
|||||||
return path, filename, identifier, extension
|
return path, filename, identifier, extension
|
||||||
end
|
end
|
||||||
|
|
||||||
local function CleanSpaces(text) --removes spaces from the front and back of the passed in text string
|
local function CleanSpaces(text) --removes spaces from the front and back of passed in text
|
||||||
front = string.match(text, '^%s')
|
text = string.gsub(text,'^%s*','')
|
||||||
back = string.match(text, '%s$')
|
text = string.gsub(text,'%s*$','')
|
||||||
if front then
|
|
||||||
text = string.sub(text,2)
|
|
||||||
end
|
|
||||||
if back then
|
|
||||||
text = string.sub(text,1,-2)
|
|
||||||
end
|
|
||||||
return text
|
return text
|
||||||
end
|
end
|
||||||
|
|
||||||
local function BuildExecuteCmd(prog_table)
|
local function BuildExecuteCmd(prog_table) --creates a program command using elements of the passed in program table
|
||||||
local result = prog_table.bin..' '..prog_table.arg_string..' '..prog_table.images_string
|
local result = CleanSpaces(prog_table.bin)..' '..CleanSpaces(prog_table.arg_string)..' '..CleanSpaces(prog_table.images_string)
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
local function PreCall(prog_tbl)
|
local function PreCall(prog_tbl) --looks to see if this is the first call, if so checks to see if program is installed properly
|
||||||
for _,prog in pairs(prog_tbl) do
|
for _,prog in pairs(prog_tbl) do
|
||||||
if prog.first_run then
|
if prog.first_run then
|
||||||
prog.bin = df.check_if_bin_exists(prog.name)
|
prog.bin = df.check_if_bin_exists(prog.name)
|
||||||
@@ -153,30 +146,27 @@ local function PreCall(prog_tbl)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function UpdateActivePreference()
|
local function UpdateActivePreference() --sliders & entry boxes do not have a click/changed callback, so their values must be saved to the active preference
|
||||||
temp = GUI.HDR.gap.value
|
temp = GUI.HDR.gap.value
|
||||||
dt.preferences.write(mod, 'active_gap', 'integer', temp)
|
dt.preferences.write(mod, 'active_gap', 'integer', temp)
|
||||||
temp = GUI.Target.add_tags.text
|
temp = GUI.Target.add_tags.text
|
||||||
dt.preferences.write(mod, 'active_add_tags', 'string', temp)
|
dt.preferences.write(mod, 'active_add_tags', 'string', temp)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function HDRMerge_main()
|
local function main()
|
||||||
PreCall({HDRM})
|
PreCall({HDRM}) --check if furst run then check if install OK
|
||||||
if HDRM.install_error then
|
if HDRM.install_error then
|
||||||
dt.print_error('HDRMerge install issue, please ensure the binary path is proper')
|
dt.print_error('HDRMerge install issue')
|
||||||
|
dt.print('HDRMerge install issue, please ensure the binary path is proper')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
images = dt.gui.selection()
|
images = dt.gui.selection() --get selected images
|
||||||
local count = 0
|
if #images < 2 then --ensure enough images selected
|
||||||
for _,image in pairs(images) do
|
dt.print('not enough images selected, select at least 2 images to merge')
|
||||||
count = count + 1
|
|
||||||
end
|
|
||||||
if count < 2 then
|
|
||||||
dt.print_error('not enough images selected, select at least 2 images to merge')
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
UpdateActivePreference()
|
UpdateActivePreference() --save current gui elements to active preference so those values will be pre-loaded at next startup
|
||||||
|
|
||||||
--create image string and output path
|
--create image string and output path
|
||||||
HDRM.images_string = ''
|
HDRM.images_string = ''
|
||||||
@@ -185,7 +175,7 @@ local function HDRMerge_main()
|
|||||||
local smallest_name = ''
|
local smallest_name = ''
|
||||||
local largest_id = 0
|
local largest_id = 0
|
||||||
local source_raw = {}
|
local source_raw = {}
|
||||||
for _,image in pairs(images) do
|
for _,image in pairs(images) do --loop to concat the images string, also track the image indexes for use in creating the final image name (eg; IMG_1034-1037.dng)
|
||||||
local curr_image = image.path..os_path_seperator..image.filename
|
local curr_image = image.path..os_path_seperator..image.filename
|
||||||
HDRM.images_string = HDRM.images_string..df.sanitize_filename(curr_image).." "
|
HDRM.images_string = HDRM.images_string..df.sanitize_filename(curr_image).." "
|
||||||
out_path = image.path
|
out_path = image.path
|
||||||
@@ -198,7 +188,6 @@ local function HDRMerge_main()
|
|||||||
end
|
end
|
||||||
if source_id > largest_id then largest_id = source_id end
|
if source_id > largest_id then largest_id = source_id end
|
||||||
end
|
end
|
||||||
HDRM.images_string = CleanSpaces(HDRM.images_string)
|
|
||||||
out_path = out_path..os_path_seperator..smallest_name..'-'..largest_id..'.dng'
|
out_path = out_path..os_path_seperator..smallest_name..'-'..largest_id..'.dng'
|
||||||
out_path = df.create_unique_filename(out_path)
|
out_path = df.create_unique_filename(out_path)
|
||||||
|
|
||||||
@@ -209,38 +198,40 @@ local function HDRMerge_main()
|
|||||||
else
|
else
|
||||||
HDRM.arg_string = HDRM.arg_string..'-o '..df.sanitize_filename(out_path)
|
HDRM.arg_string = HDRM.arg_string..'-o '..df.sanitize_filename(out_path)
|
||||||
end
|
end
|
||||||
HDRM.arg_string = CleanSpaces(HDRM.arg_string)
|
|
||||||
|
|
||||||
-- create run command and execute
|
-- create run command and execute
|
||||||
local run_cmd = BuildExecuteCmd(HDRM)
|
local run_cmd = BuildExecuteCmd(HDRM)
|
||||||
resp = dsys.external_command(run_cmd)
|
resp = dsys.external_command(run_cmd)
|
||||||
|
|
||||||
if resp == 0 and not GUI.HDR.batch.value then
|
if resp == 0 and not GUI.HDR.batch.value then
|
||||||
local imported = dt.database.import(out_path)
|
local imported = dt.database.import(out_path) -- import the new file
|
||||||
if GUI.Target.style.selected > 1 then
|
if GUI.Target.style.selected > 1 then -- apply selected style
|
||||||
local set_style = styles[GUI.Target.style.selected - 1]
|
local set_style = styles[GUI.Target.style.selected - 1]
|
||||||
dt.styles.apply(set_style , imported)
|
dt.styles.apply(set_style , imported)
|
||||||
end
|
end
|
||||||
if GUI.Target.copy_tags.value then
|
if GUI.Target.copy_tags.value then -- copy tags from the original file (ignore 'darktable' generated tags)
|
||||||
local all_tags = dt.tags.get_tags(source_raw)
|
local all_tags = dt.tags.get_tags(source_raw)
|
||||||
for _,tag in pairs(all_tags) do
|
for _,tag in pairs(all_tags) do
|
||||||
if string.match(tag.name, 'darktable|') == nil then dt.tags.attach(tag, imported) end
|
if string.match(tag.name, 'darktable|') == nil then dt.tags.attach(tag, imported) end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local set_tag = GUI.Target.add_tags.text
|
local set_tag = GUI.Target.add_tags.text
|
||||||
if set_tag ~= nil then
|
if set_tag ~= nil then -- add additional user-specified tags
|
||||||
for tag in string.gmatch(set_tag, '[^,]+') do
|
for tag in string.gmatch(set_tag, '[^,]+') do
|
||||||
tag = CleanSpaces(tag)
|
tag = CleanSpaces(tag)
|
||||||
tag = dt.tags.create(tag)
|
tag = dt.tags.create(tag)
|
||||||
dt.tags.attach(tag, imported)
|
dt.tags.attach(tag, imported)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
dt.print('HDRMerge completed successfully')
|
||||||
else
|
else
|
||||||
dt.print_error('HDRMerge failed')
|
dt.print_error('HDRMerge failed')
|
||||||
|
dt.print('HDRMerge failed')
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- GUI Elements --
|
||||||
local lbl_hdr = dt.new_widget('section_label'){
|
local lbl_hdr = dt.new_widget('section_label'){
|
||||||
label = 'HDRMerge options'
|
label = 'HDRMerge options'
|
||||||
}
|
}
|
||||||
@@ -347,9 +338,9 @@ GUI.Target.add_tags = dt.new_widget("entry"){
|
|||||||
GUI.run = dt.new_widget("button"){
|
GUI.run = dt.new_widget("button"){
|
||||||
label = 'merge',
|
label = 'merge',
|
||||||
tooltip ='run HDRMerge with the above specified settings',
|
tooltip ='run HDRMerge with the above specified settings',
|
||||||
clicked_callback = function() HDRMerge_main() end
|
clicked_callback = function() main() end
|
||||||
}
|
}
|
||||||
dt.register_lib(
|
dt.register_lib( -- register HDRMerge module
|
||||||
"HDRMerge_Lib", -- Module name
|
"HDRMerge_Lib", -- Module name
|
||||||
"HDRMerge", -- name
|
"HDRMerge", -- name
|
||||||
true, -- expandable
|
true, -- expandable
|
||||||
@@ -369,4 +360,3 @@ dt.register_lib(
|
|||||||
GUI.run
|
GUI.run
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user