From d4a03411eb1f0ed4de5894058916e37aa61b8a6a Mon Sep 17 00:00:00 2001 From: supertobi Date: Wed, 9 Sep 2015 09:57:25 +0200 Subject: [PATCH 1/5] Refactoring without new funktion Created two new local functions (show_status, create_panorama) to make the code more readable. --- contrib/hugin.lua | 51 +++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/contrib/hugin.lua b/contrib/hugin.lua index 95c0aa5..d64a73a 100644 --- a/contrib/hugin.lua +++ b/contrib/hugin.lua @@ -37,33 +37,32 @@ dt = require "darktable" -- should work with darktable API version 2.0.0 dt.configuration.check_version(...,{2,0,0}) -dt.register_storage("module_hugin","Hugin panorama", - function(storage, image, format, filename, - number,total,high_quality,extra_data) - dt.print("Export to hugin " .. tostring(number).."/"..tostring(total)) - end, - function(storage,image_table,extra_data) --finalize - -- list of exported images - local img_list +-- Register +dt.register_storage("module_hugin", "Hugin panorama", show_status, create_panorama, nil, nil) + +local function show_status(storage, image, format, filename, + number, total, high_quality, extra_data) + dt.print("Export to hugin "..tostring(number).."/"..tostring(total)) +end + +local function create_panorama(storage, image_table, extra_data) --finalize + -- list of exported images + local img_list + + -- reset and create image list + img_list = "" - -- reset and create image list - img_list = "" - - for _,v in pairs(image_table) do - img_list = img_list ..v.. " " - end - - dt.print("Will try to stitch now") - - if coroutine.yield("RUN_COMMAND","hugin "..img_list) - then - dt.print("Command hugin failed ...") - end - - end, - nil, - nil -) + for _,v in pairs(image_table) do + img_list = img_list ..v.. " " + end + + dt.print("Will try to stitch now") + + if coroutine.yield("RUN_COMMAND","hugin "..img_list) + then + dt.print("Command hugin failed ...") + end +end -- -- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua From cc7ba37eb603625d48bde948ddfb2d2f04de83bb Mon Sep 17 00:00:00 2001 From: supertobi Date: Wed, 9 Sep 2015 10:03:01 +0200 Subject: [PATCH 2/5] Added checkIfBinExists Added a check to test if hugin is installed. --- contrib/hugin.lua | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/contrib/hugin.lua b/contrib/hugin.lua index d64a73a..2335553 100644 --- a/contrib/hugin.lua +++ b/contrib/hugin.lua @@ -3,6 +3,7 @@ copyright (c) 2014 Wolfgang Goetz copyright (c) 2015 Christian Kanzian + copyright (c) 2015 Tobias Jakobs darktable is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -40,18 +41,35 @@ dt.configuration.check_version(...,{2,0,0}) -- Register dt.register_storage("module_hugin", "Hugin panorama", show_status, create_panorama, nil, nil) +local function checkIfBinExists(bin) + local handle = io.popen("which "..bin) + local result = handle:read() + local ret + handle:close() + if (not result) then + dt.print_error(bin.." not found") + ret = false + end + ret = true + return ret +end + local function show_status(storage, image, format, filename, number, total, high_quality, extra_data) dt.print("Export to hugin "..tostring(number).."/"..tostring(total)) end local function create_panorama(storage, image_table, extra_data) --finalize + if not checkIfBinExists("hugin") then + return + end + -- list of exported images local img_list -- reset and create image list img_list = "" - + for _,v in pairs(image_table) do img_list = img_list ..v.. " " end From 91dada71e2b4c650196d684b7934f8a49fd63d4c Mon Sep 17 00:00:00 2001 From: supertobi Date: Thu, 10 Sep 2015 10:25:27 +0200 Subject: [PATCH 3/5] hugin_executor support Hugin 2015.0.0 hugin provides a command line tool to start the assistant --- contrib/hugin.lua | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/contrib/hugin.lua b/contrib/hugin.lua index 2335553..7165dc5 100644 --- a/contrib/hugin.lua +++ b/contrib/hugin.lua @@ -64,6 +64,16 @@ local function create_panorama(storage, image_table, extra_data) --finalize return end +-- Since Hugin 2015.0.0 hugin provides a command line tool to start the assistant +-- http://wiki.panotools.org/Hugin_executor +-- We need pto_gen to create pto file for hugin_executor +-- http://hugin.sourceforge.net/docs/manual/Pto_gen.html + + local hugin_executor = false + if (checkIfBinExists("hugin_executor") and checkIfBinExists("pto_gen")) then + hugin_executor = true + end + -- list of exported images local img_list @@ -76,7 +86,14 @@ local function create_panorama(storage, image_table, extra_data) --finalize dt.print("Will try to stitch now") - if coroutine.yield("RUN_COMMAND","hugin "..img_list) + local huginStartCommand + if (hugin_executor) then + huginStartCommand = "pto_gen "..img_list.." -o project.pto | hugin_executor --assistant project.pto" + else + huginStartCommand = "hugin "..img_list + end + + if coroutine.yield("RUN_COMMAND", huginStartCommand) then dt.print("Command hugin failed ...") end From 343feb801bce7036e4a70267e546e5122d5739d2 Mon Sep 17 00:00:00 2001 From: supertobi Date: Thu, 10 Sep 2015 14:40:52 +0200 Subject: [PATCH 4/5] Use dt.configuration.tmp_dir for the pto file --- contrib/hugin.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/hugin.lua b/contrib/hugin.lua index 7165dc5..07ecba0 100644 --- a/contrib/hugin.lua +++ b/contrib/hugin.lua @@ -88,7 +88,7 @@ local function create_panorama(storage, image_table, extra_data) --finalize local huginStartCommand if (hugin_executor) then - huginStartCommand = "pto_gen "..img_list.." -o project.pto | hugin_executor --assistant project.pto" + huginStartCommand = "pto_gen "..img_list.." -o "..dt.configuration.tmp_dir.."/project.pto | hugin_executor --assistant "..dt.configuration.tmp_dir.."/project.pto" else huginStartCommand = "hugin "..img_list end From d1a9616fc8a6a03aa242b8fc206450e182819615 Mon Sep 17 00:00:00 2001 From: supertobi Date: Thu, 10 Sep 2015 19:36:04 +0200 Subject: [PATCH 5/5] Fixed bugs and make it work with hugin 2015.0.0 --- contrib/hugin.lua | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/contrib/hugin.lua b/contrib/hugin.lua index 07ecba0..a87437f 100644 --- a/contrib/hugin.lua +++ b/contrib/hugin.lua @@ -33,34 +33,36 @@ USAGE This plugin will add a new storage option and calls hugin after export. ]] -dt = require "darktable" +local dt = require "darktable" -- should work with darktable API version 2.0.0 dt.configuration.check_version(...,{2,0,0}) --- Register -dt.register_storage("module_hugin", "Hugin panorama", show_status, create_panorama, nil, nil) - local function checkIfBinExists(bin) local handle = io.popen("which "..bin) local result = handle:read() local ret handle:close() - if (not result) then + if (result) then + dt.print_error("true checkIfBinExists: "..bin) + ret = true + else dt.print_error(bin.." not found") ret = false end - ret = true + + return ret end local function show_status(storage, image, format, filename, number, total, high_quality, extra_data) - dt.print("Export to hugin "..tostring(number).."/"..tostring(total)) + dt.print("Export to Hugin "..tostring(number).."/"..tostring(total)) end local function create_panorama(storage, image_table, extra_data) --finalize if not checkIfBinExists("hugin") then + darktable.print_error("hugin not found") return end @@ -88,16 +90,30 @@ local function create_panorama(storage, image_table, extra_data) --finalize local huginStartCommand if (hugin_executor) then - huginStartCommand = "pto_gen "..img_list.." -o "..dt.configuration.tmp_dir.."/project.pto | hugin_executor --assistant "..dt.configuration.tmp_dir.."/project.pto" + huginStartCommand = "pto_gen "..img_list.." -o "..dt.configuration.tmp_dir.."/project.pto" + dt.print("Creating pto file") + coroutine.yield("RUN_COMMAND", huginStartCommand) + + dt.print("Running Assistent") + huginStartCommand = "hugin_executor --assistant "..dt.configuration.tmp_dir.."/project.pto" + coroutine.yield("RUN_COMMAND", huginStartCommand) + + huginStartCommand = "hugin "..dt.configuration.tmp_dir.."/project.pto" else huginStartCommand = "hugin "..img_list end + dt.print_error(huginStartCommand) + if coroutine.yield("RUN_COMMAND", huginStartCommand) then dt.print("Command hugin failed ...") end + end +-- Register +dt.register_storage("module_hugin", "Hugin Panorama", show_status, create_panorama) + -- -- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua