From 12747d9054f75674fe12052b92c9ed6b85ce5198 Mon Sep 17 00:00:00 2001 From: Till Theato Date: Wed, 18 Feb 2015 20:57:04 +0100 Subject: [PATCH] Add cr2hdr.lua script. This script automates the steps involved to process an image created with the Magic Lantern Dual ISO module. Upon invoking the script with a shortcut "cr2hdr" provided by Magic Lantern is run on the selected images. The processed files are imported. They are also made group leaders to hide the original files. --- contrib/cr2hdr.lua | 79 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 contrib/cr2hdr.lua diff --git a/contrib/cr2hdr.lua b/contrib/cr2hdr.lua new file mode 100644 index 0000000..9a5d1ba --- /dev/null +++ b/contrib/cr2hdr.lua @@ -0,0 +1,79 @@ +--[[ + Copyright (C) 2015 Till Theato . + + 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 . +]] +--[[ +cr2hdr … + +This script … + +USAGE +* require this script from your main lua file +* … +]] + +local darktable = require "darktable" + +-- Tested with darktable 1.6.2 +darktable.configuration.check_version(...,{2,0,2}) + +local processed_files = {} + +function file_imported(event, image) + local filename = image.path .. "/" .. image.filename + if processed_files[filename] then + image.make_group_leader(image) + processed_files[filename] = nil + end +end + +-- Source: http://lua-users.org/wiki/SplitJoin +function lines(str) + local t = {} + local function helper(line) table.insert(t, line) return "" end + helper((str:gsub("(.-)\r?\n", helper))) + return t +end + +function convert_image(image) + if string.sub(image.filename, -3) == "CR2" then + local filename = image.path .. "/" .. image.filename + local handle = io.popen("cr2hdr " .. filename) + local result = handle:read("*a") + handle:close() + local out_filename = string.gsub(filename, ".CR2", ".DNG") + local file = io.open(out_filename) + if file then + file:close() + processed_files[out_filename] = true + darktable.database.import(out_filename) + else + result = lines(result) + darktable.print_error(image.filename .. ": cr2hdr failed: " .. result[#result-1]) + end + else + darktable.print_error(image.filename .. " is not a Canon RAW.") + end +end + +function convert_action_images(shortcut) + local images = darktable.gui.action_images + for _,image in pairs(images) do + convert_image(image) + end +end + +darktable.register_event("shortcut", convert_action_images, "Run cr2hdr (Magic Lantern DualISO converter) on ... images") +darktable.register_event("post-import-image", file_imported)