Working with modules from Lua scripts in darktable

OK, thanks, I’ll try that!

My approach is evolving: By now I only apply the crop if necessary, i.e. if the camera’s automatic “shading compensation” (i.e. vignetting correction) is active. I read the EXIF tag using exiv2 from Lua. This works very nicely.

I now deactivated my camera’s built-in vignetting correction, because it introduces artifacts and compromises the sensors “ISO invariance”. Instead I’d like to use a second instance of “lens correction” in Darktable set to correct vignetting using Lensfun data. (Distortion & TCA are corrected based on embedded data.)

I think that I can write a function that activates Lensfun vignetting correction. (A preset won’t work, since it fixes all the parameters.)

Now I see two possibilities:

  • I can call this function automatically on import, just like I do for the crop. The vignetting correction would be applied whenever it is clear from EXIF that the camera’s own vignetting correction is not active.

  • I can bind the function to a shortcut and run it manually.

Option 1 has the advantage of being automatic, but then there won’t be any way to deactivate the vignetting correction if I ever don’t want to have it. Option 2 can be applied or not, but it is not automatic.

Does anyone see a scheme that combines the advantages of both options, i.e. having an automatic vignetting correction that can be disabled manually? Here is one idea:

I could add an auto-preset that creates a second instance of the lens corrections module, named “Lensfun: vignetting” (that second instance would be either deactivated, or active but set to do nothing.) Now, my function for activating vignetting correction would check for the presence of such a second instance (or whether it is enabled): if present (or if active), vignetting correction through Lensfun would be set up there.

In this way vignetting correction would be automatically set up whenever necessary, but could be disabled by removing the second instance (or by disabling it).

Does this sound like a workable approach? (Is there a better one?) I think I know how to do everything necessary, except querying from Lua whether a second instance of a module (with a specific name) is either present or enabled. Is this even possible?