Skip to content

Commit 2c91de8

Browse files
Stephan KleinertStephan Kleinert
authored andcommitted
adds fix_sigma_foveon_dngs script
1 parent 8c2d0dd commit 2c91de8

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

contrib/fix_sigma_foveon_dngs.lua

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
--[[ fix-sigma-foveon-dngs-v0.1
2+
3+
Fix Sigma Foveon DNGs white balance handling
4+
5+
Copyright (C) 2025 Stephan Kleinert <[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+
23+
--[[About this Plugin
24+
25+
This plugin provides a workaround for a bug that causes the colors in a
26+
Sigma Foveon DNG to be displayed incorrectly. The bug is described in
27+
depth here:
28+
29+
https://github.com/darktable-org/darktable/issues/16586
30+
31+
It works by disabling color calibration and resetting white balance
32+
to "as shot" upon first loading a Sigma Foveon DNG image in the darkroom. It
33+
is applied only once, i.e., you're free to adjust the white balance
34+
setting as you see fit without the plugin interfering on the next load.
35+
36+
With many thanks to Bill Ferguson for pointing me on the right track.
37+
38+
]]
39+
40+
local dt = require "darktable"
41+
local du = require "lib/dtutils"
42+
local gettext = dt.gettext.gettext
43+
44+
du.check_min_api_version("7.0.0", "fix_sigma_foveon_dngs")
45+
46+
local function _(msgid)
47+
return gettext(msgid)
48+
end
49+
50+
-- return data structure for script_manager
51+
52+
local script_data = {}
53+
54+
script_data.metadata = {
55+
name = _("Fix Sigma Foveon DNG files"),
56+
purpose = _("Workaround for Sigma Foveon DNG white balance problems"),
57+
author = "Stephan Kleinert <[email protected]>",
58+
help = "https://schallundstille.de/"
59+
}
60+
61+
script_data.destroy = nil -- function to destory the script
62+
script_data.destroy_method = nil -- set to hide for libs since we can't destroy them commpletely yet, otherwise leave as nil
63+
script_data.restart = nil -- how to restart the (lib) script after it's been hidden - i.e. make it visible again
64+
script_data.show = nil -- only required for libs since the destroy_method only hides them
65+
66+
sad_cameras = { "sd Quattro", "sd Quattro H", "SIGMA dp2 Quattro", -- unfortunately, I've only ever had these
67+
"SIGMA dp3 Quattro", "SIGMA dp1 Quattro", "SIGMA dp0 Quattro" } -- not sure about these
68+
69+
dt_fixed_tag = dt.tags.create("darktable|foveon_fixed")
70+
71+
function contains(list, target)
72+
for _, value in ipairs(list) do
73+
if value == target then
74+
return true
75+
end
76+
end
77+
return false
78+
end
79+
80+
local function fix_image()
81+
-- first, disable colour calibration, as it wreaks havoc with sigma foveon DNGs
82+
dt.gui.action("iop/channelmixerrgb/adaptation", "selection", "item:none (bypass)", 1,000, 0)
83+
-- then, set white balance to "as shot", forcing the white balance module to re-read the white balance data from the DNG
84+
-- (if there was a way to simply re-apply *this* setting via a preset, none of this would be necessary, just saying)
85+
dt.gui.action("iop/temperature/settings/as shot", "", "on", 1,000)
86+
end
87+
88+
local function fix_on_load(event, clean, image)
89+
if not clean then
90+
return
91+
end
92+
if image.exif_maker ~= "SIGMA" then
93+
dt.print_log("[fix_sigma_foveon_dngs] ignoring non-Sigma image")
94+
return
95+
end
96+
if not contains(sad_cameras, image.exif_model) then
97+
dt.print_log("[fix_sigma_foveon_dngs] ignoring (seemingly) non-foveon camera: "..image.exif_model)
98+
return
99+
end
100+
if contains(dt.tags.get_tags(image), dt_fixed_tag) then
101+
dt.print_log("image already foveon_fixed")
102+
return
103+
end
104+
fix_image()
105+
dt.tags.attach(dt_fixed_tag, image)
106+
end
107+
108+
dt.register_event("fix_sigma_foveon_dngs", "darkroom-image-loaded", fix_on_load)
109+
110+
dt.print_log("[fix_sigma_foveon_dngs] loaded")

0 commit comments

Comments
 (0)