Merge pull request #153 from cigno5/master
enfuse: convert raws to tiff automatically
This commit is contained in:
@@ -51,6 +51,12 @@ end
|
||||
-- is enfuse installed?
|
||||
local enfuse_installed = df.check_if_bin_exists("enfuse")
|
||||
|
||||
-- instance of DT tiff exporter
|
||||
local tiff_exporter = dt.new_format("tiff")
|
||||
tiff_exporter.bpp = 16
|
||||
tiff_exporter.max_height = 0
|
||||
tiff_exporter.max_width = 0
|
||||
|
||||
-- check the version so that we can use the correct arguments
|
||||
|
||||
local version = nil
|
||||
@@ -121,7 +127,7 @@ dt.register_lib(
|
||||
dt.new_widget("button")
|
||||
{
|
||||
label = enfuse_installed and "run enfuse" or "enfuse not installed",
|
||||
clicked_callback = function (_)
|
||||
clicked_callback = function ()
|
||||
-- remember exposure_mu
|
||||
-- TODO: find a way to save it whenever the value changes
|
||||
local mu = exposure_mu.value
|
||||
@@ -135,7 +141,7 @@ dt.register_lib(
|
||||
local response_file = os.tmpname()
|
||||
local f = io.open(response_file, "w")
|
||||
if not f then
|
||||
dt.print("error writing to `"..response_file.."'")
|
||||
dt.print(string.format(_("Error writing to `%s`"), response_file))
|
||||
os.remove(response_file)
|
||||
return
|
||||
end
|
||||
@@ -144,28 +150,41 @@ dt.register_lib(
|
||||
local cnt = 0
|
||||
local n_skipped = 0
|
||||
local target_dir
|
||||
for _, i in ipairs(dt.gui.action_images) do
|
||||
-- only use ldr files as enfuse can't open raws. alternatively we could export raws that we encounter
|
||||
for i_, i in ipairs(dt.gui.action_images) do
|
||||
|
||||
-- only use ldr files as enfuse can't open raws
|
||||
if i.is_ldr then
|
||||
cnt = cnt + 1
|
||||
f:write(i.path.."/"..i.filename.."\n")
|
||||
target_dir = i.path
|
||||
|
||||
-- alternatively raws will be exported as tiff
|
||||
elseif i.is_raw then
|
||||
local tmp_exported = os.tmpname()..".tiff"
|
||||
dt.print(string.format(_("Converting raw file '%s' to tiff..."), i.filename))
|
||||
tiff_exporter.write_image(tiff_exporter, i, tmp_exported, false)
|
||||
dt.print_log(string.format("Raw file '%s' converted to '%s'", i.filename, tmp_exported))
|
||||
|
||||
cnt = cnt + 1
|
||||
f:write(tmp_exported.."\n")
|
||||
target_dir = i.path
|
||||
|
||||
-- other images will be skipped
|
||||
else
|
||||
dt.print("skipping "..i.filename)
|
||||
dt.print(string.format(_("Skipping %s..."), i.filename))
|
||||
n_skipped = n_skipped + 1
|
||||
end
|
||||
end
|
||||
f:close()
|
||||
-- bail out if there is nothing to do
|
||||
if cnt == 0 then
|
||||
dt.print("no suitable images selected, nothing to do for enfuse")
|
||||
dt.print(_("No suitable images selected, nothing to do for enfuse"))
|
||||
os.remove(response_file)
|
||||
return
|
||||
end
|
||||
if n_skipped == 1 then
|
||||
dt.print(n_skipped.." image skipped")
|
||||
elseif n_skipped > 1 then
|
||||
dt.print(n_skipped.." images skipped")
|
||||
|
||||
if n_skipped > 0 then
|
||||
dt.print(string.format(_("%d image(s) skipped"), n_skipped))
|
||||
end
|
||||
|
||||
-- call enfuse on the response file
|
||||
@@ -177,10 +196,10 @@ dt.register_lib(
|
||||
if version < "4.2" then
|
||||
exposure_option = " --exposure-mu "
|
||||
end
|
||||
local command = "enfuse --depth "..depth.value..exposure_option..ugly_decimal_point_hack
|
||||
local command = enfuse_installed.." --depth "..depth.value..exposure_option..ugly_decimal_point_hack
|
||||
.." -o \""..output_image.."\" \"@"..response_file.."\""
|
||||
if dt.control.execute( command) > 0 then
|
||||
dt.print("enfuse failed, see terminal output for details")
|
||||
dt.print(_("Enfuse failed, see terminal output for details"))
|
||||
os.remove(response_file)
|
||||
return
|
||||
end
|
||||
@@ -192,9 +211,9 @@ dt.register_lib(
|
||||
local image = dt.database.import(output_image)
|
||||
|
||||
-- tell the user that everything worked
|
||||
dt.print("enfuse was successful, resulting image was imported")
|
||||
dt.print(_("enfuse was successful, resulting image has been imported"))
|
||||
-- normally printing to stdout is bad, but we allow enfuse to show its output, so adding one extra line is ok
|
||||
print("enfuse: done, resulting image '"..output_image.."' was imported with id "..image.id)
|
||||
print(string.format(_("enfuse: done, resulting image '%s' has been imported with id %d"), output_image, image.id))
|
||||
end
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user