Working with modules from Lua scripts in darktable

Just to be sure, does it work in the lighttable or in the darkroom view?

You start in lighttable view. You select the images you want to change. You click the display in darkroom button to start the process. When it’s finished, the script returns to lighttable view.

The PR with the event changes got merged a few hours ago, so this is now available in master. I’ll attach an updated script that uses the events I added.

display_in_darkroom.zip (1.1 KB)

1 Like

First: This is a very exciting thread. Thank you for the many good ideas! I recently came up with a similar idea to simplify my often-same workflow. I’ve experimented a bit with scripts, but I quickly reach my limits.

So three questions:

  1. How do I find out how to address the GUI elements? How do I get code like this. Is there documentation for this?
  1. Concrete example: How do I click the “adjust the exposure correction” magic wand in the exposure module?
  2. Is there a way to debug the Lua scripts while they are running?

Thank you and best regards,
Uli.

In master (I’m not sure about 4.0.1) you click the define shortcuts button (to the left of the gear icon at the top) and then hover over the item you wish to know about. A popup should appear with the necessary lua code.

darktable.gui.action("iop/exposure/exposure", 0, "button", "on", 1.0)

wait for a period of time or catch the pixelpipe-complete event

darktable.gui.action("iop/exposure/exposure", 0, "button", "off", 1.0)

print statements and run darktable with the -d lua flag.

2 Likes

Thank you for your prompt reply!

In 4.0.1 the define shortcut button shows a popup but without the LUA code. That will probably only come with 4.2. Not sure if I should switch to 4.1, let’s see :slight_smile:

I had already suspected that the LUA scripts cannot be debugged comfortable from an IDE. Then it has to be via print.

I’ll keep experimenting with this and will post it here if it shows meaningful results.

Thanks and regards,
Uli.

1 Like

@wpferguson @donda : After a few experiments I have now created my first script. You can find it attached.

It offers a new “inital workflow” module both in lighttable and darkroom view. This script can be used to do some configuration for an initial image workflow. It calls some automatisms of different modules in the darkroom view. If this suits your workflow, the script saves some clicks and time.

I am looking forward to your comments :slight_smile:
InitialWorkflowModule.zip (4.3 KB)

Best regards,
Uli.

6 Likes

Thanks for sharing your work…

I tried this and if works as intended from what I can see…very cool. I wonder…it seems like it could be a bit slow for a large number of images… I wonder is there a way to have the changes applied as the script is process without each module needing to be activated and opened and updated in the UI… That might speed it up but I am not sure if that is something that could be done by altering the code… I guess @wpferguson might be the one to know…

Very nice little script thanks for sharing … I think it will give a lot of ideas to possible version of this for others

EDIT:
One thing if you open images as I do with legacy wb I don’t think your WB settings can be applied as you intend…you may say that …but unchanged I assume would leave it at camera reference and you assume Cat16 is not set to bypass. If it is then none of your selections for CC illuminant work… I think all possible combinations work if you apply your script to an image with the default modern WB …but not if it is set at legacy… to handle legacy you would need an option to select camera reference and a means to enable or detect the status of CAT ie bypass vs one of the transforms… Perhaps you mention this

1 Like

@priort Thank you for the feedback :slight_smile:

If you are using dt4.1 you can speed it up by using the new event “pixelpipe-processing-complete”. To do that, edit function WaitForPixelPipe and replace darkroom-image-history-changed with pixelpipe-processing-complete.

The note on legacy white balance is correct. I use the modern workflow. I will try to add a check to the script.

Best regards,
Uli.

2 Likes

darktable.gui.action() only provides a way to manipulate the GUI.

My solution so far is to use a combination of styles (with a lot of modules turned off) and darktable.gui.action() to manipulate the style (turn modules on and off, manipulate the settings, etc). I built the equivalent style using darktable.gui.action() and it is slow.

You could have a script that caught the darkroom-image-loaded event, then checked to see if the image had been processed or not. If not, then a style could be applied using darktable.styles(), then manipulated using darktable.gui.action().

2 Likes

That is an interesting approach… I guess the only thing here is Ulrich is firing off auto exposure and black and white levels in filmic so no way to do that with your approach at least I don’t think. But it could be useful for other edits …

You could do it the first time you open the image, after you’ve applied the style. You could set a tag after you’ve done the auto levels/exposure or just check the status of exposure and see if it’s set to auto. I haven’t had time to look at the script yet, so those are just off the top of my head.

I think he is doing what I do now and using the picker with the spot exposure setting to 50% to give the base starting point…. This works pretty well. I do this with new images and then if I don’t like it I can select the main area of interest and it will boost or drop exposure…. I don’t think he is using the auto setting of the exposure module….

Hi @priort and @wpferguson ,

there is a new version of my script, you can find it attached. In the end, this script executes some automatic functions that can also be accessed via the GUI (click the magic wands).

With Darktable 4.2, this script has been accelerated. It uses the new “pixelpipe-processing-complete event”. It should be about twice as fast (less thread.sleep()).

From now, the white balance is only adjusted by default for the modern workflow of Darktable. The script distinguishes between modern and legacy workflow and keeps white balance unchanged by default, if using legacy workflow.

It was a little bit difficult to figure out how to do this: dt.preferences.read(“darktable”, “plugins/darkroom/chromatic-adaptation”, “string”). The documenation points to another way: “The name of the preference displayed in the preference screen”, I assumed “auto-apply chromatic adaptation defaults”.

I am looking forward to your comments :slight_smile:

InitialWorkflowModule.zip (4.9 KB)

Best Regards,
Uli.

by the way: Many thanks to all developers of DT! For me it is one of the most exciting software projects and I am very happy that DT exists! It’s open source, it runs on Linux, it’s always evolving, it can be automated and so on - and I have nicer pictures :slight_smile: . Thank you very much!

6 Likes

@Claes there is a new version of my script, perhaps this can be helpful.

Best Regards,
Uli.

Danke vielmals :slight_smile:

Thanks for sharing. I have promoted it a few times and shown a screen shot of the layout…I get back hey what module is that, what version of DT are you running… :slight_smile:

I must say I have not put it to good use yet as I have been really busy at work and have really not had any photo’s to edit but I will install this new one and check it out… I will do a few tests… I think you pointed me to that function in our initial discussion and I had made the change so maybe I won’t notice that 2x bump but never the less thanks it really shows what is possible…

I think one nice addition if you can figure it out would be to set the auto pickers for the rgb CB module mask… the white fulcrum and contrast grey to set up the mask for the tonal ranges…

image

2 Likes

Hi @priort , thank you for the promotion :slight_smile:

Yes, that is based on the start of the discussion and the new event you implemented. This is very useful. Performance is already “normal” for you as developer, so you won’t see any gain in performance.

You propose an extension for the color calibration module. I’ll look at that in two weeks after my vacation, that should be easy to do.

Best regards,
Uli.

This is awesome news! That’s exactly what I was looking for last year!

I wonder what kind of “dynamic preset” shenanigans we can come up with, with this capability. Most of my immediate ideas would involve some sort of measurements, though. I could probably fake an approximate exposure estimate by, say, enabling the auto mask exposure compensation in the tone equalizer, and then reading the mask exposure compensation value.

Or is it possible to place/read color pickers? One could even imagine placing several pickers over various image parts, to do weighted exposure evaluations. Information about under- or overexposed areas might also be useful…

I can’t wait to play with this!

It runs the exposure auto picker which by default is 50 percent that works a lot of the time but you could adjust it if not…