Bug 424192

Summary: Cannot pass a filter configuration to a python Filter
Product: [Applications] krita Reporter: Halla Rempt <halla>
Component: ScriptingAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED WORKSFORME    
Severity: normal CC: scottpetrovic, tamtamy.tymona
Priority: NOR    
Version First Reported In: 4.3.0   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Halla Rempt 2020-07-14 12:46:12 UTC
Filter uses an InfoObject which contains a KisPropertiesConfiguration that stores all settings. In the Filter class, we have

KisFilterConfigurationSP filterConfig = static_cast<KisFilterConfiguration*>(d->configuration->configuration().data());

Since configuration() pointer is not a KisFilterConfigurationSP, this will fail.
Comment 1 Tiar 2020-07-27 18:10:56 UTC
Sounds valid, reported by a developer, no changed were made to that source, so confirming.
Comment 2 Scott Petrovic 2020-07-31 13:37:37 UTC
The filter configuration seems to want a QDomElement (which is XML). We can either make someone create a QDomElement in Python and send that in to set the filter configuration. Or add an internal conversion helper function to InfoObject that converts it to XML. I would personally pick QDomElement since that is already available in PyQt. Also less code we might have to maintain with an InfoObject converter.

where the filter configuration is being set in Python
https://invent.kde.org/graphics/krita/-/blob/master/libs/libkis/Filter.cpp#L105


filter configuration seems to store settings in XML format
https://invent.kde.org/graphics/krita/-/blob/master/libs/image/filter/kis_filter_configuration.cc#L117

A couple filter configurations

Oil Paint filter XML example
-----------------------------
<!DOCTYPE params>
<params version="1">
 <param type="internal" name="brushSize">1</param>
 <param type="internal" name="smooth">30</param>
</params>


Edge Detection Sobel XML example
------------------------------
<!DOCTYPE params>
<params version="1">
 <param type="internal" name="horizRadius">1.85</param>
 <param type="internal" name="lockAspect">true</param>
 <param type="string" name="output"><![CDATA[xFall]]></param>
 <param type="internal" name="transparency">false</param>
 <param type="string" name="type"><![CDATA[sobol]]></param>
 <param type="internal" name="vertRadius">1.85</param>
</params>
Comment 3 Scott Petrovic 2020-07-31 17:23:05 UTC
After looking at another script...I think this does actually work and this bug might be invalid. Changing the properties and running it again changes the effect of the filter. This seems to work for me in scripter...



from krita import *

#create document to work with
newDocument = Krita.instance().createDocument(500, 500, "Document name", "RGBA", "U8", "", 300.0)
Krita.instance().activeWindow().addView(newDocument) # shows it in the application

# make active node layer opacity 100% 
activeNode = newDocument.activeNode()
activeNode.setOpacity(255)

# fill with foreground color that has saturation
Krita.instance().action("fill_selection_foreground_color").trigger();
newDocument.refreshProjection() 

# see all available filters
# print(Krita.instance().filters())

randomNoiseFilter = Krita.instance().filter("noise")
config = randomNoiseFilter.configuration()
config.setProperty("level", 100)
config.setProperty("opacity", 99)
randomNoiseFilter.setConfiguration(config) 
randomNoiseFilter.apply(activeNode, 0, 0, newDocument.width(), newDocument.height())
Comment 4 Scott Petrovic 2020-07-31 17:26:09 UTC
We can probably still close this ticket, but I would be interested to know how to set values in the config that are CDATA. For example the halftone filter XML looks like this. 


<!DOCTYPE params>
<params version="1">
 <param type="internal" name="antiAliasing">true</param>
 <param type="color" name="backGroundColor"><![CDATA[<!DOCTYPE color>
<color>
 <RGB g="1" b="1" r="1" space="sRGB-elle-V2-g10.icc"/>
</color>
]]></param>
 <param type="internal" name="cellSize">8</param>
 <param type="color" name="foreGroundColor"><![CDATA[<!DOCTYPE color>
<color>
 <RGB g="0" b="0" r="0" space="sRGB-elle-V2-g10.icc"/>
</color>
]]></param>
 <param type="internal" name="invert">false</param>
 <param type="internal" name="patternAngle">45</param>
</params>
Comment 5 Bug Janitor Service 2020-08-15 04:33:18 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 6 Bug Janitor Service 2020-08-30 04:33:13 UTC
This bug has been in NEEDSINFO status with no change for at least
30 days. The bug is now closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

Thank you for helping us make KDE software even better for everyone!