Skip to content

Commit a9fd071

Browse files
committed
fujifilm-dynamic-range: skip non-Fuji non-raws and clean-ups
Don't bother to pull EXIF data unless the imported image is a Fujifilm raw. Cleanup conditionals for error handling by immediately returning on failure, avoiding deep nested conditionals. Cleanup log/error output with clearer messages.
1 parent 6341a0a commit a9fd071

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

contrib/fujifilm_dynamic_range.lua

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,17 @@ local function _(msgid)
7171
end
7272

7373
local function detect_dynamic_range(event, image)
74+
if image.exif_maker ~= "FUJIFILM" then
75+
dt.print_log(_("[fujifilm_dynamic_range] ignoring non-Fujifilm image"))
76+
return
77+
end
78+
-- it would be nice to check image.is_raw but this appears to not yet be set
79+
if not string.match(image.filename, "%.RAF$") then
80+
dt.print_log(_("[fujifilm_dynamic_range] ignoring non-raw image"))
81+
return
82+
end
7483
if not df.check_if_bin_exists("exiftool") then
75-
dt.print_error(_("exiftool not found"))
84+
dt.print_error(_("[fujifilm_dynamic_range] exiftool not found"))
7685
return
7786
end
7887
local RAF_filename = df.sanitize_filename(tostring(image))
@@ -82,25 +91,25 @@ local function detect_dynamic_range(event, image)
8291
output = io.popen(command)
8392
local raf_result = output:read("*all")
8493
output:close()
85-
if string.len(raf_result) > 0 then
86-
raf_result = string.match(raf_result, "\t(.*)")
87-
if raf_result then
88-
if image.exif_exposure_bias ~= image.exif_exposure_bias then
89-
-- is NAN (this is unlikely as RAFs should have ExposureBiasValue set)
90-
image.exif_exposure_bias = 0
91-
end
92-
-- this should be auto-applied if plugins/darkroom/workflow is scene-referred
93-
-- note that scene-referred workflow exposure preset also pushes exposure up by 0.5 EV
94-
image.exif_exposure_bias = image.exif_exposure_bias + tonumber(raf_result)
95-
dt.print_log(_("Using RAF exposure bias: ") .. tostring(raf_result))
96-
else
97-
dt.print_error(_("Could not parse exiftool output."))
98-
end
99-
else
100-
dt.print_error(_("No output returned by exiftool."))
94+
if #raf_result == 0 then
95+
dt.print_error(_("[fujifilm_dynamic_range] no output returned by exiftool"))
96+
return
97+
end
98+
raf_result = string.match(raf_result, "\t(.*)")
99+
if not raf_result then
100+
dt.print_error(_("[fujifilm_dynamic_range] could not parse exiftool output"))
101+
return
102+
end
103+
if image.exif_exposure_bias ~= image.exif_exposure_bias then
104+
-- is NAN (this is unlikely as RAFs should have ExposureBiasValue set)
105+
image.exif_exposure_bias = 0
101106
end
107+
-- this should be auto-applied if plugins/darkroom/workflow is scene-referred
108+
-- note that scene-referred workflow exposure preset also pushes exposure up by 0.5 EV
109+
image.exif_exposure_bias = image.exif_exposure_bias + tonumber(raf_result)
110+
dt.print_log(_("[fujifilm_dynamic_range] raw exposure bias ") .. tostring(raf_result))
102111
end
103112

104113
dt.register_event("post-import-image", detect_dynamic_range)
105114

106-
dt.print_log(_("fujifilm_dynamic_range loaded."))
115+
dt.print_log(_("[fujifilm_dynamic_range] loaded"))

0 commit comments

Comments
 (0)