Skip to content

Commit b08d7f2

Browse files
committed
fujifilm_dynamic_range : first draft
Read RawExposureBias and adjust "EXIF Exposure Bias" based upon this.
1 parent 62753d1 commit b08d7f2

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

contrib/fujifilm_dynamic_range.lua

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
--[[ fujifilm_dynamic_range-0.1
2+
3+
Compensate for Fujifilm raw files made using "dynamic range".
4+
5+
Copyright (C) 2020 Dan Torop <[email protected]>
6+
7+
This program is free software; you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published by
9+
the Free Software Foundation; either version 2 of the License, or
10+
(at your option) any later version.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU General Public License along
18+
with this program; if not, write to the Free Software Foundation, Inc.,
19+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20+
]]
21+
22+
--[[About this Plugin
23+
Support for adjusting darktable exposure by Fujifilm raw exposure
24+
bias. This corrects for a DR100/DR200/DR400 "dynamic range" setting.
25+
26+
Dependencies:
27+
- exiftool (https://www.sno.phy.queensu.ca/~phil/exiftool/)
28+
29+
Based upon fujifilm_ratings by Ben Mendis
30+
31+
--]]
32+
33+
local dt = require "darktable"
34+
local du = require "lib/dtutils"
35+
local df = require "lib/dtutils.file"
36+
local gettext = dt.gettext
37+
38+
du.check_min_api_version("4.0.0", "fujifilm_dynamic_range")
39+
40+
gettext.bindtextdomain("fujifilm_dynamic_range", dt.configuration.config_dir.."/lua/locale/")
41+
42+
local function _(msgid)
43+
return gettext.dgettext("fujifilm_dynamic_range", msgid)
44+
end
45+
46+
local function detect_dynamic_range(event, image)
47+
-- exiftool knows about the RawExposureBias tag, unlike exiv2, but it is also 10x slower
48+
if not df.check_if_bin_exists("exiftool") then
49+
dt.print_error(_("exiftool not found"))
50+
return
51+
end
52+
local RAF_filename = df.sanitize_filename(tostring(image))
53+
local command = "exiftool -RawExposureBias " .. RAF_filename
54+
dt.print_error(command)
55+
output = io.popen(command)
56+
local raf_result = output:read("*all")
57+
output:close()
58+
if string.len(raf_result) > 0 then
59+
raf_result = string.gsub(raf_result, "^Raw Exposure Bias.-([%d%.%-]+)", "%1")
60+
if image.exif_exposure_bias ~= image.exif_exposure_bias then
61+
-- is NAN (this is unlikely as RAFs should have ExposureBiasValue set)
62+
image.exif_exposure_bias = 0
63+
end
64+
-- this should be auto-applied if plugins/darkroom/workflow is scene-referred
65+
-- FIXME: scene-referred workflow pushes exposure up 0.5 EV, but DR100 pushes up 0.7 EV -- should reduce this by 0.5 EV?
66+
image.exif_exposure_bias = image.exif_exposure_bias + tonumber(raf_result)
67+
dt.print_error(_("Using RAF exposure bias: ") .. tostring(raf_result))
68+
end
69+
end
70+
71+
dt.register_event("post-import-image", detect_dynamic_range)
72+
73+
print(_("fujifilm_dynamic_range loaded."))

0 commit comments

Comments
 (0)