Working with modules from Lua scripts in darktable

I did some testing trying to figure out what are “fast” calls and “slow” calls. I tried using os.clock() but I don’t trust the values I got. However, I was logging to the terminal and the log prints an elapsed time since darktable started for every log line. So the output of my test looks like:

    10.1816 LUA starting test run
    10.1983 LUA test gui.action elapsed time for absolute adjust is 0.016851000000001
    10.2201 LUA test gui.action elapsed time for get exposure value is 0.029548999999999
    10.4871 LUA test gui.action elapsed time for relative adjust is 2.065055

An absolute adjust is just setting a value and it takes around .01 sec.

A get value about twice that or .02 sec.

A relative adjust (read the value, add an offset, then set it) takes roughly .25 sec.

How about the “set” routine does a check of the current value before applying the value and just returns if it’s the same? If it applies the setting, then wait for the pixelpipe-processing-complete event. The only things where that gets rough are comparing presets, because the return value is a number indexing into the list rather than a string so you need a table of the preset values to do a lookup and see if it’s a match.

I downloaded your earlier version of the script and looked through it trying to find issues. One thing I found is with darkroom-image-loaded. If the load isn’t clean, darktable will automatically try and reload the image so you don’t have to force a reload. Just discard the event and wait until it fires again.

The worst part of scripts like these is determining the state of the UI and the modules. That’s the reason for Workflow Automation with Lua Scripts · Issue #16722 · darktable-org/darktable · GitHub. Unfortunately I didn’t get very far with this for this release. I did manage to add get_active_preset() to libs, but I don’t have anything yet for iops (processing modules).

I’ll look at trying to figure out where the pixelpipe decides it doesn’t have to run and see if there’s a way to either send a pixelpipe-aborted event or even a pixelpipe-processing-complete from that point.

I have an action lib that is very much a work in progress/test bed, but the event handling works pretty well.

libaction.zip (3.1 KB)

I enjoyed reading your script. That’s the first time I’ve seen OO Lua. I also liked the debug.getinfo() thing. I probably need to go back and read the manual again to pick up more things I glossed over the first time I read it.

2 Likes

Its a great script with so much functionality so if it ever got to where is wasn’t so slow it would be a great way to as the name says initially process images…

@Ulrich_Gesing i tested the old version of this and i think the speed is comparable to what I’m seeing with my scripts. i just used the default settings and it took around 6 seconds to set everything. if I performed all of those settings by hand it would take several minutes and lots of clicks, so I think the module is a huge time saver.

The only thing I didn’t really like was the amount of panel width it used, but I don’t know if I have a solution for that.

i did have a thought about another way to modify this

  • Turn the current GUI into a recipe editor. Save the settings as a recipe and apply them when the image loads based on rating and/or color label.
  • Add a tag (darktable|InitialWorflow|applied) and check for it so that you don’t process it twice.
  • The user loads an image and it takes ~5 seconds to prepare it. They aren’t sitting there waiting for a bunch of images to process before they can start editing. 5 or 10 seconds isn’t a big deal, but 5 or 10 minutes is.
  • You might want to offer presets as a choice for the modules, so if the user has a colorbalancergb preset they can just apply it. Setting a preset is easy, but determining which preset is active or what the preset choices are isn’t :frowning:

Thinking… :thinking:

Thanks a lot for your thoughts. I’ll get in touch.

1 Like

Thats what I am doing. I would like to avoid checking the current value.

That would be great. The script could skip the “get value call” and wait for two events during “set value” instead.

I think I might be able to trap on history stack changed. IIRC that fires prior to causing the pixelpipe to start.