This is a fairly hacky approach, but it’s possible to read the param
values from the XML file by unpacking the binary data, provided you know the expected struct format.
As a simple example, if you look at the source for the temperature module, you can find the definition for the dt_iop_temperature_params_t
(link). This module simply stores four float values in the param struct.
Finding the temperature
operation element in the XML file for my test image, the param value is f3b420400000803f6ae5d43f0000807f
. Which can be unpacked in a Python interpreter using the struct module (docs).
>>> from struct import *
>>> unpack('ffff', bytearray.fromhex('f3b420400000803f6ae5d43f0000807f'))
(2.5110442638397217, 1.0, 1.6632511615753174, inf)
These match the expected coefficients I see in the darktable UI for the white balance module.
To write values, you can use:
>>> pack('ffff', 1.0, 2.0, 1.2, float('inf')).hex()
'0000803f000000409a99993f0000807f'
Pasting this value back into the XML file should update it. (When I tried, I had to reimport the sidecar. Also, it’s helpful to pay attention to the state of the history stack, I made sure it was fully compressed before doing this.)
I tried decoding a couple modules, and this approach seemed reliable. With the more complex modules, the number of params can be significantly higher, and some modules use base64 encode the params rather than simply writing hex strings. Not sure if this is per-module or based on the length of the param values. Additionally, I didn’t dig into the mask or blendop values, but I’d imagine they’re stored similarly.
With a little manual work to grab the param struct formats, it should be possible to turn this into a simple Python script that could read/write specific module values.