From 5f6350c21807cd89c6f8b56af0716b0d1dabf7f5 Mon Sep 17 00:00:00 2001 From: Tobias Ellinghaus Date: Thu, 1 Oct 2015 21:55:19 +0200 Subject: [PATCH 01/12] Add helper that checks GitHub for new dt releases --- official/check_for_updates.lua | 89 ++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 official/check_for_updates.lua diff --git a/official/check_for_updates.lua b/official/check_for_updates.lua new file mode 100644 index 0000000..1e7977b --- /dev/null +++ b/official/check_for_updates.lua @@ -0,0 +1,89 @@ +--[[ + This file is part of darktable, + copyright (c) 2015 Tobias Ellinghaus + + darktable is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + darktable is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with darktable. If not, see . +]] +--[[ +CHECK FOR UPDATES +a simple script that will automatically look for newer releases on github and inform +when there is something. it will only check on startup and only once a week. + +USAGE +* install luasec and cjson for Lua 5.2 on your system +* require this script from your main lua file +* restart darktable + +]] + +local dt = require "darktable" +local https = require "ssl.https" +local cjson = require "cjson" + +dt.configuration.check_version(...,{2,0,0}) + +-- compare two version strings of the form "major.minor.patch" +-- returns -1, 0, 1 if the first version is smaller, equal, greater than the second version, +-- or nil if one or both are of the wrong format +-- strings like "release-1.2.3" and "1.2.3+456~gb00b5" are fine, too +local function compare_versions(a, b) + local a_major, a_minor, a_patch = a:match("(%d+)%.(%d+)%.(%d+)") + local b_major, b_minor, b_patch = b:match("(%d+)%.(%d+)%.(%d+)") + if a_major and a_minor and a_patch and b_major and b_minor and b_patch then + if a_major < b_major then return -1 end + if a_major > b_major then return 1 end + + if a_minor < b_minor then return -1 end + if a_minor > b_minor then return 1 end + + if a_patch < b_patch then return -1 end + if a_patch > b_patch then return 1 end + + return 0 + else + return + end +end + + +-- check stored timestamp and skip the check if the last time was not too long ago +-- for now we are assuming that os.time() returns seconds. that's not guaranteed but the case on many systems. +-- the reference date doesn't matter, as long as it's currently positive (we start with 0 the first time) +-- see http://lua-users.org/wiki/DateAndTime +local now = os.time() +local back_then = dt.preferences.read("check_for_updates", "timestamp", "integer") + +-- check once a week +if now > (back_then + 60 * 60 * 24 * 7) then + + -- try to get the latest release's version from github and compare to what we are running + -- see https://developer.github.com/v3/repos/releases/ for the api docs + -- just ignore when anything fails and retry at some other time + local result, error_code = https.request("https://api.github.com/repos/darktable-org/darktable/releases/latest") + + if error_code == 200 then + local name = cjson.decode(result)["name"] -- http://www.kyne.com.au/~mark/software/lua-cjson-manual.html + if name then + local cmp = compare_versions(name, dt.configuration.version) + if cmp then + if cmp > 0 then + dt.print("there seems to be a newer release than what you are running. better update") + end + -- update timestamp to not check again for a while + dt.preferences.write("check_for_updates", "timestamp", "integer", now) + end + end + end + +end From ae627d9f5516ef55187fda1a461e64f9539f6ca1 Mon Sep 17 00:00:00 2001 From: Tobias Ellinghaus Date: Sat, 14 Nov 2015 13:43:19 +0100 Subject: [PATCH 02/12] Make update check work with RCs --- official/check_for_updates.lua | 50 ++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/official/check_for_updates.lua b/official/check_for_updates.lua index 1e7977b..659bc28 100644 --- a/official/check_for_updates.lua +++ b/official/check_for_updates.lua @@ -37,9 +37,25 @@ dt.configuration.check_version(...,{2,0,0}) -- returns -1, 0, 1 if the first version is smaller, equal, greater than the second version, -- or nil if one or both are of the wrong format -- strings like "release-1.2.3" and "1.2.3+456~gb00b5" are fine, too +local function parse_version(s) + local rc = 0 + local major, minor, patch = s:match("(%d+)%.(%d+)%.(%d+)") + if not major then + patch = 0 + major, minor, rc = s:match("(%d+)%.(%d+)rc(%d+)") + end + if not major then + patch = 0 + rc = 0 + major, minor = s:match("(%d+)%.(%d+)") + end + return tonumber(major), tonumber(minor), tonumber(patch), tonumber(rc) +end + local function compare_versions(a, b) - local a_major, a_minor, a_patch = a:match("(%d+)%.(%d+)%.(%d+)") - local b_major, b_minor, b_patch = b:match("(%d+)%.(%d+)%.(%d+)") + local a_major, a_minor, a_patch, a_rc = parse_version(a) + local b_major, b_minor, b_patch, b_rc = parse_version(b) + if a_major and a_minor and a_patch and b_major and b_minor and b_patch then if a_major < b_major then return -1 end if a_major > b_major then return 1 end @@ -50,6 +66,13 @@ local function compare_versions(a, b) if a_patch < b_patch then return -1 end if a_patch > b_patch then return 1 end + -- when rc == 0 then it's a proper release and newer than the rcs + local m = math.max(a_rc, b_rc) + 1 + if a_rc == 0 then a_rc = m end + if b_rc == 0 then b_rc = m end + if a_rc < b_rc then return -1 end + if a_rc > b_rc then return 1 end + return 0 else return @@ -57,6 +80,29 @@ local function compare_versions(a, b) end +-- local function test(a, b, r) +-- local cmp = compare_versions(a, b) +-- if(not cmp) then +-- print(a .. " ./. " .. b .. " => MALFORMED INPUT") +-- elseif(cmp == r) then +-- print(a .. " ./. " .. b .. " => PASSED") +-- else +-- print(a .. " ./. " .. b .. " => FAILED") +-- end +-- end +-- +-- test("malformed", "1.0.0", 0) +-- test("2.0rc1+135~ge456b2b-dirty", "release-1.6.9", 1) +-- test("release-1.6.9", "2.0rc1+135~ge456b2b-dirty", -1) +-- test("2.0rc1+135~ge456b2b-dirty", "2.0rc2+135~ge456b2b-dirty", -1) +-- test("2.0rc2+135~ge456b2b-dirty", "2.0rc1+135~ge456b2b-dirty", 1) +-- test("2.0rc3+135~ge456b2b-dirty", "release-2.0", -1) +-- test("2.0rc3+135~ge456b2b-dirty", "release-2.0.0", -1) +-- test("1.0.0", "2.0.0", -1) +-- test("2.0.0", "1.0.0", 1) +-- test("3.0.0", "3.0.0", 0) + + -- check stored timestamp and skip the check if the last time was not too long ago -- for now we are assuming that os.time() returns seconds. that's not guaranteed but the case on many systems. -- the reference date doesn't matter, as long as it's currently positive (we start with 0 the first time) From f4f96d71585beeed1134a486cac42668a4f9628b Mon Sep 17 00:00:00 2001 From: Tobias Ellinghaus Date: Wed, 16 Dec 2015 11:52:35 +0100 Subject: [PATCH 03/12] Ellipsize a label with image path Otherwise it will make the side panel too wide, breaking the whole gui. --- official/image_path_in_ui.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/official/image_path_in_ui.lua b/official/image_path_in_ui.lua index 7026bfb..ba93d2d 100644 --- a/official/image_path_in_ui.lua +++ b/official/image_path_in_ui.lua @@ -1,17 +1,17 @@ --[[ This file is part of darktable, copyright (c) 2014 Jérémy Rosen - + darktable is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + darktable is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with darktable. If not, see . ]] @@ -31,9 +31,9 @@ This plugin will add a widget at the bottom of the left column in lighttable mod local dt = require "darktable" dt.configuration.check_version(...,{2,0,0}) -local main_label = dt.new_widget("label"){selectable = true} +local main_label = dt.new_widget("label"){selectable = true, ellipsize = "middle", halign = "start"} -local function reset_widget() +local function reset_widget() local selection = dt.gui.selection() local result = "" local array = {} From a4e26365d8f0a324e141799144a459abfc62cb90 Mon Sep 17 00:00:00 2001 From: Robert William Hutton Date: Sat, 19 Dec 2015 22:33:11 +1100 Subject: [PATCH 04/12] Specify location of luarc file in the README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 640a201..3dd001b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ lua-scripts The Lua scripts in this repository are meant to be used together with darktable. Either copy them individually to `~/.config/darktable/lua` (you might have to create that folder) or just copy/symlink the whole repository there. That allows to update all your scripts with a simple call to `git pull`. -To enable one of the scripts you have to add a line like `require "official/hello_world"` which would enable the example script in `official/hello_world.lua`. +To enable one of the scripts you have to add a line like `require "official/hello_world"` to your `~/.config/darktable/luarc` file which will enable the example script in `official/hello_world.lua` (note the lack of the `.lua` suffix). Each script includes its own documentation and usage in its header, please refer to them. From 1dc1f5f9efe6fba5a5910f3b4758ae6f6ad3f0e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rosen?= Date: Wed, 23 Dec 2015 15:20:24 +0100 Subject: [PATCH 05/12] disable image_path_in_ui since it relies on a disabled feature --- official/image_path_in_ui.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/official/image_path_in_ui.lua b/official/image_path_in_ui.lua index ba93d2d..0c081c0 100644 --- a/official/image_path_in_ui.lua +++ b/official/image_path_in_ui.lua @@ -28,6 +28,7 @@ This plugin will add a widget at the bottom of the left column in lighttable mod ]] +--[[ local dt = require "darktable" dt.configuration.check_version(...,{2,0,0}) @@ -58,6 +59,6 @@ dt.register_lib("image_path_no_ui","Selected Images path",true,false,{ ); dt.register_event("mouse-over-image-changed",reset_widget); - +]] -- -- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua From ff1f07653682ee253915da7c9273a0ed9bc7a9f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rosen?= Date: Wed, 23 Dec 2015 15:21:38 +0100 Subject: [PATCH 06/12] Revert "disable image_path_in_ui since it relies on a disabled feature" This reverts commit 1dc1f5f9efe6fba5a5910f3b4758ae6f6ad3f0e1. --- official/image_path_in_ui.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/official/image_path_in_ui.lua b/official/image_path_in_ui.lua index 0c081c0..ba93d2d 100644 --- a/official/image_path_in_ui.lua +++ b/official/image_path_in_ui.lua @@ -28,7 +28,6 @@ This plugin will add a widget at the bottom of the left column in lighttable mod ]] ---[[ local dt = require "darktable" dt.configuration.check_version(...,{2,0,0}) @@ -59,6 +58,6 @@ dt.register_lib("image_path_no_ui","Selected Images path",true,false,{ ); dt.register_event("mouse-over-image-changed",reset_widget); -]] + -- -- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua From 5d729048499379c6b29b8722b1709f43d3be2ea8 Mon Sep 17 00:00:00 2001 From: chrik5 Date: Sun, 27 Dec 2015 14:52:21 +0100 Subject: [PATCH 07/12] make check_api_version work with API 3 --- contrib/copy_attach_detach_tags.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/copy_attach_detach_tags.lua b/contrib/copy_attach_detach_tags.lua index d5a7ec8..5081732 100644 --- a/contrib/copy_attach_detach_tags.lua +++ b/contrib/copy_attach_detach_tags.lua @@ -34,7 +34,7 @@ USAGE ]] local dt = require "darktable" -dt.configuration.check_version(...,{2,0,0}) +dt.configuration.check_version(...,{2,0,0},{3,0,0}) local image_tags = {} From 08151e7e2149c1d2c737349a1cde2c269c77f695 Mon Sep 17 00:00:00 2001 From: Laurent Navet Date: Wed, 30 Dec 2015 22:02:18 +0100 Subject: [PATCH 08/12] Fix some typos --- contrib/hugin.lua | 2 +- contrib/kml_export.lua | 4 ++-- contrib/preferenceExamples.lua | 2 +- contrib/video_mencoder.lua | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/contrib/hugin.lua b/contrib/hugin.lua index a87437f..b7ffbfb 100644 --- a/contrib/hugin.lua +++ b/contrib/hugin.lua @@ -24,7 +24,7 @@ HUGIN Add a new storage option to send images to hugin. Images are exported to darktable tmp dir first. -ADDITIANAL SOFTWARE NEEDED FOR THIS SCRIPT +ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT * hugin USAGE diff --git a/contrib/kml_export.lua b/contrib/kml_export.lua index fc6a804..da3c2d4 100644 --- a/contrib/kml_export.lua +++ b/contrib/kml_export.lua @@ -18,7 +18,7 @@ --[[ darktable KML export script -ADDITIANAL SOFTWARE NEEDED FOR THIS SCRIPT +ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT * mkdir * zip (only if you create KMZ files) * convert (ImageMagick) @@ -26,7 +26,7 @@ ADDITIANAL SOFTWARE NEEDED FOR THIS SCRIPT * xdg-user-dir WARNING -This script is only testet with Linux +This script is only tested with Linux USAGE * require this script from your main lua file diff --git a/contrib/preferenceExamples.lua b/contrib/preferenceExamples.lua index 18a6553..34117e6 100644 --- a/contrib/preferenceExamples.lua +++ b/contrib/preferenceExamples.lua @@ -16,7 +16,7 @@ along with this program. If not, see . ]] --[[ -darktable script to show the different prefference types that are possible with the Lua +darktable script to show the different preference types that are possible with Lua USAGE * require this script from your main lua file diff --git a/contrib/video_mencoder.lua b/contrib/video_mencoder.lua index e0ba2b6..18ddc25 100644 --- a/contrib/video_mencoder.lua +++ b/contrib/video_mencoder.lua @@ -18,13 +18,13 @@ --[[ darktable video export script -ADDITIANAL SOFTWARE NEEDED FOR THIS SCRIPT +ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT * mencoder (MEncoder is from the MPlayer Team) * xdg-open * xdg-user-dir WARNING -This script is only testet with Linux +This script is only tested with Linux USAGE * require this script from your main lua file From 28d73b44a6e30e81a11198dbca7ead8af5627fdc Mon Sep 17 00:00:00 2001 From: ribmo Date: Sat, 2 Jan 2016 12:58:35 +0000 Subject: [PATCH 09/12] Shortcuts to rate/reject all images within a group --- contrib/rate_group.lua | 84 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 contrib/rate_group.lua diff --git a/contrib/rate_group.lua b/contrib/rate_group.lua new file mode 100644 index 0000000..b6b7a75 --- /dev/null +++ b/contrib/rate_group.lua @@ -0,0 +1,84 @@ +--[[ + + Rate Group: + + Script to provide shortcuts for rating or rejecting all images within a group; + particularly useful for RAW+JPEG shooters employing a star rating workflow + like the below: + + http://blog.chasejarvis.com/blog/2011/03/photo-editing-101/ + + + Installation and usage: + + 1. Copy this file into ~/.config/darktable/lua/ + + 2. Add `require "rate_group"` to new line in ~/.config/darktable/luarc + + 3. Restart darktable + + 4. Assign a keyboard shortcut to each action via settings > shortcuts > lua + + I use the following shortcuts: + + * Reject group: Ctrl+R + * Rate group 1: Ctrl+1 + * Rate group 2: Ctrl+2 + * Rate group 3: Ctrl+3 + * Rate group 4: Ctrl+4 + * Rate group 5: Ctrl+5 + * Rate group 0: Ctrl+0 + + + Author: Dom H (dom@hxy.io) + License: GPLv2 + + This script is based on Thibault Jouannic's `reject_group` script: + http://redmine.darktable.org/issues/8968#note-20 + +]] + +local dt = require "darktable" + +local function apply_rating(rating) + local images = dt.gui.action_images + for _, i in ipairs(images) do + local members = i:get_group_members() + for _, m in ipairs(members) do + m.rating = rating + end + end + if rating < 0 then + dt.print("rejecting group(s)") + else + dt.print("applying rating " ..rating.. " to group(s)") + end +end + +dt.register_event("shortcut",function(event, shortcut) + apply_rating(-1) +end, "Reject group") + +dt.register_event("shortcut",function(event, shortcut) + apply_rating(0) +end, "Rate group 0") + +dt.register_event("shortcut",function(event, shortcut) + apply_rating(1) +end, "Rate group 1") + +dt.register_event("shortcut",function(event, shortcut) + apply_rating(2) +end, "Rate group 2") + +dt.register_event("shortcut",function(event, shortcut) + apply_rating(3) +end, "Rate group 3") + +dt.register_event("shortcut",function(event, shortcut) + apply_rating(4) +end, "Rate group 4") + +dt.register_event("shortcut",function(event, shortcut) + apply_rating(5) +end, "Rate group 5") \ No newline at end of file From 39531eb4f0a0b4cb2d69c18a23d69d2eee097519 Mon Sep 17 00:00:00 2001 From: spaceChRiS Date: Sun, 3 Jan 2016 10:44:14 +0100 Subject: [PATCH 10/12] Take care for code in for loop to be run even for the last image. The problem: If the last image is a jpeg/raw pair, the code to remove the jpeg from the import list is not run since it is the last image. This is solved by adding an empty line to the images array. It will be counted as new base and therefore the jpeg removal code will be run one more time. I don't know if this is a good solution but I think it solves the problem without adding complexity. --- official/import_filters.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/official/import_filters.lua b/official/import_filters.lua index 5980a72..04a8d5c 100644 --- a/official/import_filters.lua +++ b/official/import_filters.lua @@ -50,6 +50,7 @@ dt.register_import_filter("prefer raw over jpeg", function(event, images) local current_base = "" local jpg_indices = {} local other_format_found = false + table.insert(images, "") for i, img in ipairs(images) do local extension = img:match("[^.]*$"):upper() local base = img:match("^.*[.]") From fe18256c259836e472700893ac60e3a2320b42d8 Mon Sep 17 00:00:00 2001 From: spaceChRiS Date: Mon, 4 Jan 2016 10:44:41 +0100 Subject: [PATCH 11/12] Remove extra line from image list. --- official/import_filters.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/official/import_filters.lua b/official/import_filters.lua index 04a8d5c..e3d595c 100644 --- a/official/import_filters.lua +++ b/official/import_filters.lua @@ -75,6 +75,7 @@ dt.register_import_filter("prefer raw over jpeg", function(event, images) end end + table.remove(images) end) -- vim: shiftwidth=2 expandtab tabstop=2 cindent From 895ad62757e548e4c7e6802c48ba56b6433c12a4 Mon Sep 17 00:00:00 2001 From: Tobias Ellinghaus Date: Mon, 4 Jan 2016 14:49:12 +0100 Subject: [PATCH 12/12] Fix line endings --- contrib/hugin.lua | 238 ++++++++++++++++++------------------ contrib/video_mencoder.lua | 240 ++++++++++++++++++------------------- 2 files changed, 239 insertions(+), 239 deletions(-) diff --git a/contrib/hugin.lua b/contrib/hugin.lua index b7ffbfb..819e5b2 100644 --- a/contrib/hugin.lua +++ b/contrib/hugin.lua @@ -1,119 +1,119 @@ ---[[ - Hugin storage for darktable - - 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - darktable is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with darktable. If not, see . -]] - ---[[ -HUGIN -Add a new storage option to send images to hugin. -Images are exported to darktable tmp dir first. - -ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT -* hugin - -USAGE -* require this file from your main luarc config file. - -This plugin will add a new storage option and calls hugin after export. -]] - -local dt = require "darktable" - --- should work with darktable API version 2.0.0 -dt.configuration.check_version(...,{2,0,0}) - -local function checkIfBinExists(bin) - local handle = io.popen("which "..bin) - local result = handle:read() - local ret - handle:close() - if (result) then - dt.print_error("true checkIfBinExists: "..bin) - ret = true - else - dt.print_error(bin.." not found") - ret = false - end - - - 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 - darktable.print_error("hugin not found") - 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 - - -- 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") - - local huginStartCommand - if (hugin_executor) then - 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 +--[[ + Hugin storage for darktable + + 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + darktable is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with darktable. If not, see . +]] + +--[[ +HUGIN +Add a new storage option to send images to hugin. +Images are exported to darktable tmp dir first. + +ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT +* hugin + +USAGE +* require this file from your main luarc config file. + +This plugin will add a new storage option and calls hugin after export. +]] + +local dt = require "darktable" + +-- should work with darktable API version 2.0.0 +dt.configuration.check_version(...,{2,0,0}) + +local function checkIfBinExists(bin) + local handle = io.popen("which "..bin) + local result = handle:read() + local ret + handle:close() + if (result) then + dt.print_error("true checkIfBinExists: "..bin) + ret = true + else + dt.print_error(bin.." not found") + ret = false + end + + + 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 + darktable.print_error("hugin not found") + 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 + + -- 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") + + local huginStartCommand + if (hugin_executor) then + 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 diff --git a/contrib/video_mencoder.lua b/contrib/video_mencoder.lua index 18ddc25..8198780 100644 --- a/contrib/video_mencoder.lua +++ b/contrib/video_mencoder.lua @@ -1,120 +1,120 @@ ---[[ - This file is part of darktable, - Copyright 2014 by Tobias Jakobs. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -]] ---[[ -darktable video export script - -ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT -* mencoder (MEncoder is from the MPlayer Team) -* xdg-open -* xdg-user-dir - -WARNING -This script is only tested with Linux - -USAGE -* require this script from your main lua file -]] - -local dt = require "darktable" -dt.configuration.check_version(...,{2,0,1}) - -local function show_status(storage, image, format, filename, number, total, high_quality, extra_data) - dt.print("Export Image "..tostring(number).."/"..tostring(total)) -end - -local function checkIfBinExists(bin) - local handle = io.popen("which "..bin) - local result = handle:read() - local ret - handle:close() - if (result) then - --dt.print_error("true checkIfBinExists: "..bin) - ret = true - else - dt.print_error(bin.." not found") - ret = false - end - - return ret -end - -local function create_video_mencoder(storage, image_table, extra_data) - if not checkIfBinExists("mencoder") then - return - end - if not checkIfBinExists("xdg-open") then - return - end - if not checkIfBinExists("xdg-user-dir") then - return - end - - exportDirectory = dt.preferences.read("video_mencoder","ExportDirectory","string") - exportFilename = "output.avi" - framsePerSecond = dt.preferences.read("video_mencoder","FramesPerSecond","integer") - - dt.print_error("Will try to create video now") - -- Set the codec - local codec = "" - local codecPreferences = "" - - codecPreferences = dt.preferences.read("video_mencoder","Codec","string") - if (codecPreferences == "H.264 encoding") then - codec = 'x264' - end - if (codecPreferences == "XviD encoding") then - codec = 'xvid' - end - if not codecPreferences then - codec = 'x264' - end - - -- Create the command - local command = "mencoder -idx -nosound -noskip -ovc "..codec.." -lavcopts vcodec=mjpeg -o "..exportDirectory.."/"..exportFilename.." -mf fps="..framsePerSecond .." mf://" - - for _,v in pairs(image_table) do - command = command..v.."," - end - - dt.print_error("this is the command: "..command) - -- USE coroutine.yield. It does not block the UI - coroutine.yield("RUN_COMMAND", command) - - dt.print("Video created in "..exportDirectory) - - if ( dt.preferences.read("video_mencoder","OpenVideo","bool") == true ) then - -- USE coroutine.yield. It does not block the UI - local playVideoCommand = "xdg-open "..exportDirectory.."/"..exportFilename - coroutine.yield("RUN_COMMAND", playVideoCommand) - end -end - --- Preferences -dt.preferences.register("video_mencoder", "FramesPerSecond", "float", "Video exort (MEncoder): Frames per second", "Frames per Second in the Video export", 15, 1, 99, 0.1 ) -dt.preferences.register("video_mencoder", "OpenVideo", "bool", "Video exort (MEncoder): Open video after export", "Opens the Video after the export with the standard video player", false ) - -local handle = io.popen("xdg-user-dir VIDEOS") -local result = handle:read() -handle:close() -dt.preferences.register("video_mencoder", "ExportDirectory", "directory", "Video exort (MEncoder): Video export directory","A directory that will be used to export a Video",result) - --- Get the MEncoder codec list with: mencoder -ovc help -dt.preferences.register("video_mencoder", "Codec", "enum", "Video exort (MEncoder): Codec","Video codec","H.264 encoding","H.264 encoding","XviD encoding") - --- Register -dt.register_storage("video_mencoder", "Video Export (MEncoder)", show_status, create_video) +--[[ + This file is part of darktable, + Copyright 2014 by Tobias Jakobs. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +]] +--[[ +darktable video export script + +ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT +* mencoder (MEncoder is from the MPlayer Team) +* xdg-open +* xdg-user-dir + +WARNING +This script is only tested with Linux + +USAGE +* require this script from your main lua file +]] + +local dt = require "darktable" +dt.configuration.check_version(...,{2,0,1}) + +local function show_status(storage, image, format, filename, number, total, high_quality, extra_data) + dt.print("Export Image "..tostring(number).."/"..tostring(total)) +end + +local function checkIfBinExists(bin) + local handle = io.popen("which "..bin) + local result = handle:read() + local ret + handle:close() + if (result) then + --dt.print_error("true checkIfBinExists: "..bin) + ret = true + else + dt.print_error(bin.." not found") + ret = false + end + + return ret +end + +local function create_video_mencoder(storage, image_table, extra_data) + if not checkIfBinExists("mencoder") then + return + end + if not checkIfBinExists("xdg-open") then + return + end + if not checkIfBinExists("xdg-user-dir") then + return + end + + exportDirectory = dt.preferences.read("video_mencoder","ExportDirectory","string") + exportFilename = "output.avi" + framsePerSecond = dt.preferences.read("video_mencoder","FramesPerSecond","integer") + + dt.print_error("Will try to create video now") + -- Set the codec + local codec = "" + local codecPreferences = "" + + codecPreferences = dt.preferences.read("video_mencoder","Codec","string") + if (codecPreferences == "H.264 encoding") then + codec = 'x264' + end + if (codecPreferences == "XviD encoding") then + codec = 'xvid' + end + if not codecPreferences then + codec = 'x264' + end + + -- Create the command + local command = "mencoder -idx -nosound -noskip -ovc "..codec.." -lavcopts vcodec=mjpeg -o "..exportDirectory.."/"..exportFilename.." -mf fps="..framsePerSecond .." mf://" + + for _,v in pairs(image_table) do + command = command..v.."," + end + + dt.print_error("this is the command: "..command) + -- USE coroutine.yield. It does not block the UI + coroutine.yield("RUN_COMMAND", command) + + dt.print("Video created in "..exportDirectory) + + if ( dt.preferences.read("video_mencoder","OpenVideo","bool") == true ) then + -- USE coroutine.yield. It does not block the UI + local playVideoCommand = "xdg-open "..exportDirectory.."/"..exportFilename + coroutine.yield("RUN_COMMAND", playVideoCommand) + end +end + +-- Preferences +dt.preferences.register("video_mencoder", "FramesPerSecond", "float", "Video exort (MEncoder): Frames per second", "Frames per Second in the Video export", 15, 1, 99, 0.1 ) +dt.preferences.register("video_mencoder", "OpenVideo", "bool", "Video exort (MEncoder): Open video after export", "Opens the Video after the export with the standard video player", false ) + +local handle = io.popen("xdg-user-dir VIDEOS") +local result = handle:read() +handle:close() +dt.preferences.register("video_mencoder", "ExportDirectory", "directory", "Video exort (MEncoder): Video export directory","A directory that will be used to export a Video",result) + +-- Get the MEncoder codec list with: mencoder -ovc help +dt.preferences.register("video_mencoder", "Codec", "enum", "Video exort (MEncoder): Codec","Video codec","H.264 encoding","H.264 encoding","XviD encoding") + +-- Register +dt.register_storage("video_mencoder", "Video Export (MEncoder)", show_status, create_video)