|
3 | 3 |
|
4 | 4 | copyright (c) 2014 Wolfgang Goetz
|
5 | 5 | copyright (c) 2015 Christian Kanzian
|
| 6 | + copyright (c) 2015 Tobias Jakobs |
6 | 7 |
|
7 | 8 | darktable is free software: you can redistribute it and/or modify
|
8 | 9 | it under the terms of the GNU General Public License as published by
|
@@ -32,38 +33,87 @@ USAGE
|
32 | 33 | This plugin will add a new storage option and calls hugin after export.
|
33 | 34 | ]]
|
34 | 35 |
|
35 |
| -dt = require "darktable" |
| 36 | +local dt = require "darktable" |
36 | 37 |
|
37 | 38 | -- should work with darktable API version 2.0.0
|
38 | 39 | dt.configuration.check_version(...,{2,0,0})
|
39 | 40 |
|
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) |
67 | 117 |
|
68 | 118 | --
|
69 | 119 | -- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua
|
0 commit comments