Skip to content

Commit 96fed29

Browse files
committed
Merge pull request darktable-org#15 from supertobi/master
Fixed bugs and make it work with hugin 2015.0.0
2 parents f58282b + d1a9616 commit 96fed29

File tree

1 file changed

+78
-28
lines changed

1 file changed

+78
-28
lines changed

contrib/hugin.lua

Lines changed: 78 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
copyright (c) 2014 Wolfgang Goetz
55
copyright (c) 2015 Christian Kanzian
6+
copyright (c) 2015 Tobias Jakobs
67
78
darktable is free software: you can redistribute it and/or modify
89
it under the terms of the GNU General Public License as published by
@@ -32,38 +33,87 @@ USAGE
3233
This plugin will add a new storage option and calls hugin after export.
3334
]]
3435

35-
dt = require "darktable"
36+
local dt = require "darktable"
3637

3738
-- should work with darktable API version 2.0.0
3839
dt.configuration.check_version(...,{2,0,0})
3940

40-
dt.register_storage("module_hugin","Hugin panorama",
41-
function(storage, image, format, filename,
42-
number,total,high_quality,extra_data)
43-
dt.print("Export to hugin " .. tostring(number).."/"..tostring(total))
44-
end,
45-
function(storage,image_table,extra_data) --finalize
46-
-- list of exported images
47-
local img_list
48-
49-
-- reset and create image list
50-
img_list = ""
51-
52-
for _,v in pairs(image_table) do
53-
img_list = img_list ..v.. " "
54-
end
55-
56-
dt.print("Will try to stitch now")
57-
58-
if coroutine.yield("RUN_COMMAND","hugin "..img_list)
59-
then
60-
dt.print("Command hugin failed ...")
61-
end
62-
63-
end,
64-
nil,
65-
nil
66-
)
41+
local function checkIfBinExists(bin)
42+
local handle = io.popen("which "..bin)
43+
local result = handle:read()
44+
local ret
45+
handle:close()
46+
if (result) then
47+
dt.print_error("true checkIfBinExists: "..bin)
48+
ret = true
49+
else
50+
dt.print_error(bin.." not found")
51+
ret = false
52+
end
53+
54+
55+
return ret
56+
end
57+
58+
local function show_status(storage, image, format, filename,
59+
number, total, high_quality, extra_data)
60+
dt.print("Export to Hugin "..tostring(number).."/"..tostring(total))
61+
end
62+
63+
local function create_panorama(storage, image_table, extra_data) --finalize
64+
if not checkIfBinExists("hugin") then
65+
darktable.print_error("hugin not found")
66+
return
67+
end
68+
69+
-- Since Hugin 2015.0.0 hugin provides a command line tool to start the assistant
70+
-- http://wiki.panotools.org/Hugin_executor
71+
-- We need pto_gen to create pto file for hugin_executor
72+
-- http://hugin.sourceforge.net/docs/manual/Pto_gen.html
73+
74+
local hugin_executor = false
75+
if (checkIfBinExists("hugin_executor") and checkIfBinExists("pto_gen")) then
76+
hugin_executor = true
77+
end
78+
79+
-- list of exported images
80+
local img_list
81+
82+
-- reset and create image list
83+
img_list = ""
84+
85+
for _,v in pairs(image_table) do
86+
img_list = img_list ..v.. " "
87+
end
88+
89+
dt.print("Will try to stitch now")
90+
91+
local huginStartCommand
92+
if (hugin_executor) then
93+
huginStartCommand = "pto_gen "..img_list.." -o "..dt.configuration.tmp_dir.."/project.pto"
94+
dt.print("Creating pto file")
95+
coroutine.yield("RUN_COMMAND", huginStartCommand)
96+
97+
dt.print("Running Assistent")
98+
huginStartCommand = "hugin_executor --assistant "..dt.configuration.tmp_dir.."/project.pto"
99+
coroutine.yield("RUN_COMMAND", huginStartCommand)
100+
101+
huginStartCommand = "hugin "..dt.configuration.tmp_dir.."/project.pto"
102+
else
103+
huginStartCommand = "hugin "..img_list
104+
end
105+
106+
dt.print_error(huginStartCommand)
107+
108+
if coroutine.yield("RUN_COMMAND", huginStartCommand)
109+
then
110+
dt.print("Command hugin failed ...")
111+
end
112+
113+
end
114+
115+
-- Register
116+
dt.register_storage("module_hugin", "Hugin Panorama", show_status, create_panorama)
67117

68118
--
69119
-- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua

0 commit comments

Comments
 (0)