Working with modules from Lua scripts in darktable

I think you will see it comes from added exposure and the clarity preset… I found a small typo in the code…after that things seem to work properly for me…

EDIT @Ulrich_Gesing

This is the bit…note the labels for the options… the values for setting the module option were also set like this for the function… I have changed the comma out for a period and it seems to work… that typo seems to have caused the weird errors I saw in 4.21. I didn’t have the lua logging on to confirm but that could confirm…

function StepContrastEqualizer:Init()
self.ComboBoxValues =
{
“unchanged”,
“reset to default”,
“clarity, strength 0,25”,
“clarity, strength 0,50”,
“denoise & sharpen, strength 0,25”,
“denoise & sharpen, strength 0,50”
}

self.Widget = dt.new_widget(“combobox”)
{
changed_callback = ComboBoxChangedCallback,
label = “contrast equalizer”,
tooltip = self.Tooltip,
table.unpack(self.ComboBoxValues)
}
end

function StepContrastEqualizer:Run()
local selection = self.Widget.value

if (selection == “unchanged”) then
return
end

self:LogStepMessage()
self:EnableDarkroomModule(“iop/atrous”)
GuiActionWaitForPixelPipe(“iop/atrous”, 0, “reset”, “”, 1.0)

if (selection == “clarity, strength 0,25”) then
GuiActionWaitForPixelPipe(“iop/atrous/preset/clarity”, 0, “button”, “on”, 1.0)
GuiActionWaitForPixelPipe(“iop/atrous/mix”, 0, “value”, “set”, “0.25”)
end

if (selection == “clarity, strength 0,50”) then
GuiActionWaitForPixelPipe(“iop/atrous/preset/clarity”, 0, “button”, “on”, 1.0)
GuiActionWaitForPixelPipe(“iop/atrous/mix”, 0, “value”, “set”, “0.5”)
end

if (selection == “denoise & sharpen, strength 0,25”) then
GuiActionWaitForPixelPipe(“iop/atrous/preset/denoise & sharpen”, 0, “button”, “on”, 1.0)
GuiActionWaitForPixelPipe(“iop/atrous/mix”, 0, “value”, “set”, “0.25”)
end

if (selection == “denoise & sharpen, strength 0,50”) then
GuiActionWaitForPixelPipe(“iop/atrous/preset/denoise & sharpen”, 0, “button”, “on”, 1.0)
GuiActionWaitForPixelPipe(“iop/atrous/mix”, 0, “value”, “set”, “0.5”)
end
end

If you haven’t changed it then look at the color balance module. Do you have 15 and 25 as the settings for chroma and sat and if you go to the mask tab are the fulcrum settings changed… if not then you have the same baseline as it has in 4.21. The changes you see are from auto exposure and the full clarity setting in the contrast eq which is quite strong. Correcting the typo in the script gives the full functioning of the macro. If you can confirm that then we know it works in WIndows up to your version but gets broken between 4.3 _705 and +750…

This is what I see:
image
One thing that is funny, though, that when I try to run a second set of pictures it will not do anything. If I quit and restart darktable it then will do. It appears it works only on the first execution

Not sure where that comes from… run it on a duplicate…??? Ah your adding one of the presets…I was just setting the mask tab option…

image

In any case it didn’t work fully until I made the edit to the script… And it works in 4.21 fully now but not in my current version…

Okay I think now maybe it a language/local setting… I am in Canada and so 0,25 was not correctly interpreted but maybe its not a typo and gets used correctly in the region(s) where the settings would accept a comma as a decimal…

1 Like

Thank you for your research! The analysis sounds plausible, here with my German locale setting it works. I will adjust it.

Thanks, Uli, for all your hard work on this. I can confirm Todd’s finding that changing 0,25 and 0,50 to 0.25 and 0.50 fixes the hang at the contrast equalizer stage (I’m in the US, that’s probably why).

However, for me, the script still exhibits the same problem as before namely that is sometimes processes images multiple times, failing to move on to the next image. Sometimes it moves on, sometimes it doesn’t, it seems random. I know there was a discussion about timing of events etc. not sure what the conclusion was on this.

BTW: I am using darktable 4.2.0 on Win 10.

It a great script. Now I just have to see if I can find where it got broken along the line to the current master… There were a couple of changes made to model naming. It seems to run throught the script and activate all the specified modules but none of the setting are applied… maybe it’s doing the reset part but not continuing??

1 Like

I can reproduce it now: After each GuiAction, the script waits for a “pixelpipe-processing-complete” event. If an exception occurs, the event remains registered. Next execution/event registration fails and the script does nothing until you restart Darktable. I fixed that. An additional “destroy_event” helps.

1 Like

I could reproduce it after switching my desktop to “Canadian”. There is a simple solution: I replaced the string parameters “0,25” with their decimal equivalents 0.25. This avoids the conversion. Attached you can find the new version.

InitialWorkflowModule.zip (10.4 KB)

1 Like

Right now, I cannot reproduce that. Could you explain, how you do it? How do you select the images?

Could you send me a logfile, as described in darktable lua documentation - troubleshooting

log.txt (6.7 KB)
log2.txt (6.1 KB)
log3.txt (5.4 KB)
log4.txt (5.6 KB)

Here are a few log files… after looking at the first one I though thought the raw CA was the issue so I set it to unchanged…things seemed to go a bit further but a similar error would pop up…

So this is the behaviour from the current master… maybe a little behind now a day or so… running Win11

4.3 + 750…

I will take a look at this.

@Claes Thank you for your howto “How to get the master branch compiled on my local EndeavourOs machine” (with my brand new github account :-))

image

2 Likes

With 4.3.0+801: The script checks if the module is already enabled before activating it:

local status = dt.gui.action(“iop/cacorrect”, 0, “enable”, “”, nil)

That does not work anymore, it is the same for other modules:
LUA ERROR : bad argument #5 to ‘?’ (number expected, got nil)

Apparently the API has changed? How can you read this value now?

@dterrahe @wpferguson One of you two might know??

Maybe answer lies in here…

that’s it!

I removed the last two parameters from
local status = dt.gui.action(“iop/cacorrect”, 0, “enable”, “”, nil)

after that it works, but take a look at the following part of the discussion. It should work with both versions:

I have now made this change and made all except the first argument (the action itself) optional while still supporting the previous order (as long as in that case all parameters are specified, which used to be a requirement).

log.txt (57.0 KB)

Here is a sample log file. I selected 9 images in the lighttable to process, then started the script. after processing the first image, it moved on to the next image in the filmstrip, but the main image window stayed on image number 1 and reprocessed it. This repeated until it finally loaded image 8 and processed it twice. So, from 9 selected images, only two got processed, as I can also see in the .xmp files.

Funny enough, on my work laptop (same darktable version, but Win11), it seems to work perfectly fine.

I’m sorry, I didn’t realise people used nil to indicate NAN as the move_size parameter. So I only tested if “” and 0/0 worked. Anyway, I’d recommend moving to the new “format” as you probably barely are using the “instance” parameter. So you can just use
local status = dt.gui.action(“iop/cacorrect”, “enable”)

2 Likes

Sounds like a timing problem.

Perhaps the event, the script is waiting for, should come later. Perhaps the loading process is currently being aborted and the processing of the image is started too early?

Is your working PC significantly faster?

I will try to reproduce it, maybe a slow virtual machine can help.