Bug 482491 - Cross-channel color adjustment filter could not be configured by script
Summary: Cross-channel color adjustment filter could not be configured by script
Status: REPORTED
Alias: None
Product: krita
Classification: Applications
Component: Scripting (other bugs)
Version First Reported In: 5.2.2
Platform: Microsoft Windows Microsoft Windows
: NOR normal
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
: 475827 482490 (view as bug list)
Depends on: 482490
Blocks:
  Show dependency treegraph
 
Reported: 2024-03-05 20:51 UTC by mbcnve
Modified: 2025-11-07 18:07 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments
fig.1 Test code (61.94 KB, image/png)
2024-03-05 20:53 UTC, mbcnve
Details
Fig.2 Source code about 'nTransfer' (228.90 KB, image/png)
2024-03-05 20:54 UTC, mbcnve
Details
Fig3. Driver Channel (49.27 KB, image/png)
2024-03-05 20:55 UTC, mbcnve
Details
test script (572 bytes, text/plain)
2024-03-05 20:56 UTC, mbcnve
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mbcnve 2024-03-05 20:51:28 UTC
Cross-channel color adjustment filter could not be configured by script. When such a filter is created by code, its configuration property is initialized to {'nTransfers': 0}. However, a normal color adjustment filter created by GUI dialog has configuration properties like  {'curve0': '0,0.5;1,0.5;', 'curve1': '0,0.5;1,0.5;', 'curve2': '0,0.5;1,0.5;', 'curve3': '0,0.5;1,0.5;', 'curve4': '0,0;1,0.5;', 'curve5': '0,0.5;1,0.5;', 'curve6': '0,0.5;1,0.5;', 'curve7': '0,0.5;1,0.5;', 'nTransfers': 8}. Then, I tried to add these curve information to the initial empty configuration created by script. However, the code didn't work as expected, that the curve 0-7 is added to filter configuration while property 'nTransfers' always remains 0. (fig.1)

According to the source code (fig.2), property 'nTransfers' should change with the curve information added, but it didn't work. Furthermore,the curve information is also ignored, the filter created by the script didn't work as the curve info I specified.

Moreover, the curve 0-7 only specify the mapping curve for 8 output channels. However, the driver channel is not specified by the filter configuration, which means that driver channel information could not be accessed by script.(fig.3)

Similar problem with other color adjustment filter: https://krita-artists.org/t/scripting-with-colour-adjustment-filter-layer/23229
Comment 1 mbcnve 2024-03-05 20:52:54 UTC
*** Bug 482490 has been marked as a duplicate of this bug. ***
Comment 2 mbcnve 2024-03-05 20:53:59 UTC
Created attachment 166441 [details]
fig.1 Test code
Comment 3 mbcnve 2024-03-05 20:54:45 UTC
Created attachment 166442 [details]
Fig.2 Source code about 'nTransfer'
Comment 4 mbcnve 2024-03-05 20:55:26 UTC
Created attachment 166443 [details]
Fig3. Driver Channel
Comment 5 mbcnve 2024-03-05 20:56:44 UTC
Created attachment 166444 [details]
test script
Comment 6 Dmitry Kazakov 2025-01-22 18:01:54 UTC
Hi, mbcnve!

Just to let you know a workaround, if you add an explicit line of `nTransfers` before other properties, then script will work:

```python
from krita import *

app = Krita.instance()
doc = app.activeDocument()
currentNode = doc.activeNode()

myFilter = app.filter('crosschannel')
myFilterConfig = myFilter.configuration()
print(myFilterConfig.properties())

myFilterConfig.setProperties({'nTransfer': 8})
myFilterConfig.setProperties(
    {'curve0': '0,0.5;1,0.5;', 
    'curve1': '0,0.5;1,0.5;', 
    'curve2': '0,0.5;1,0.5;', 
    'curve3': '0,0.5;1,0.5;', 
    'curve4': '0,0;1,0.5;', 
    'curve5': '0,0.5;1,0.5;', 
    'curve6': '0,0.5;1,0.5;', 
    'curve7': '0,0.5;1,0.5;'})
print(myFilterConfig.properties())
```

That is technically a bug, though I don't know how to solve it properly :)
Comment 7 Dmitry Kazakov 2025-01-22 18:14:27 UTC
*** Bug 475827 has been marked as a duplicate of this bug. ***
Comment 8 Yncke 2025-02-07 17:12:03 UTC
Thank you for your suggestion, Dmitry.  I tried it, and I'm not succeeding in getting it to work with Krita 5.2.9 (Debian 12, appimage). (I'm assuming 'nTransfer' is a typo and should be 'nTransfers'). 
When setting it to '8' and printing the values, 'nTransfers' remains '0'. If I open the GUI in Krita, all settings remain on the default. Even if I only set the 'nTransfers' to '8' without touching the curves it remains '0'. 

Should I wait for a new release?
Comment 9 Yncke 2025-11-07 18:07:38 UTC
Retested with Krita 5.2.13 (Debian 12, AppImage) and the workaround doesn't seem to be working, I'm afraid.

I'm using this script: 
```python
from krita import *

app = Krita.instance()
doc = app.activeDocument()
currentNode = doc.activeNode()
filter = app.filter("perchannel")

config = filter.configuration()
config.setProperty("nTransfers", "8")
config.setProperty("curve0", "0.168092,0;0.962877,1;")
for index in range(1, 8):
    config.setProperty(f"curve{index}", "0,0;1,1;")
filter.setConfiguration(config)
colorAdjustment = doc.createFilterMask("Color Adjustment", filter, currentNode)
currentNode.addChildNode(colorAdjustment, None)
```

Indeed, if you print the config properties in the script, it says the value is set. But when I then open the Color Adjustment layer in Krita itself, the first (or zeroth, depending on how you count) is the set to the default curve.