I wondering is this filter is exposed to Python API:
If yes, how to use it? Since there is are curve editing depending on configuration.
If no, is introduction of it is planned and for when?
I wondering is this filter is exposed to Python API:
If yes, how to use it? Since there is are curve editing depending on configuration.
If no, is introduction of it is planned and for when?
Hope this information is of use.
This first script that will print information about a FilterMask, which is distinct from FilterLayer. The configuration for both are stored in an InfoObject.
from krita import *
def print_filtermask_properties():
inst = Krita.instance()
doc = inst.activeDocument()
node = doc.activeNode()
if node.type() != "filtermask": return
f = node.filter()
print(f.name())
cfg = f.configuration()
print(cfg.properties())
print_filtermask_properties()
I created a fresh filtermask and set it to the one called “Color Adjustment”. I then selected the layer and ran the script.
The internal name seems to be perchannel.
perchannel
{'curve0': '0,0;1,1;', 'curve1': '0,0;1,1;', 'curve2': '0,0;1,1;', 'curve3': '0,0;1,1;', 'curve4': '0,0;1,1;', 'curve5': '0,0;1,1;', 'curve6': '0,0;1,1;', 'curve7': '0,0;1,1;', 'nTransfers': 8}
I added another control point to the curve and ran the script again
perchannel
{'curve0': '0,0;0.253623,0.745098;1,1;', 'curve1': '0,0;1,1;', 'curve2': '0,0;1,1;', 'curve3': '0,0;1,1;', 'curve4': '0,0;1,1;', 'curve5': '0,0;1,1;', 'curve6': '0,0;1,1;', 'curve7': '0,0;1,1;', 'nTransfers': 8}
There are 8 channels for adjusting, and it seems curve0 corresponds to channel “RGBA”.
Before: 'curve0': '0,0;1,1;'
After: 'curve0': '0,0;0.253623,0.745098;1,1;
Pairs of x,y coordinates.
I haven’t checked every single filter to see if it gives all the properties but I feel its safe assume it does.
This next script sets values for an existing filtermask.
from krita import Krita, InfoObject
def msg(msg, duration=500):
Krita.instance().activeWindow().activeView().showFloatingMessage(msg, Krita.instance().icon("16_light_warning"), duration, 1)
def func():
inst = Krita.instance()
doc = inst.activeDocument()
if not doc: return
cur_node = doc.activeNode()
if cur_node.type() != "filtermask":
msg("need to select filtermask")
return
filter_name = "hsvadjustment"
cur_filter = cur_node.filter()
if cur_filter.name() != filter_name:
msg(F"need to use {filter_name} filter")
return
props = {'colorize': True, 'compatibilityMode': False, 'h': 150, 's': 50, 'type': 1, 'v': 0}
new_filter = inst.filter(filter_name)
new_filter.setName(filter_name)
cfg = InfoObject()
cfg.setProperties(props)
new_filter.setConfiguration(cfg)
cur_node.setFilter(new_filter)
doc.refreshProjection()
print(cur_node.filter().configuration().properties())
func()
This final script will add a mask, sets its values, and set its alpha based on a selection.
Like the previous script to get a filter you have to do Krita.instance().filter(filtername).
from PyQt5.QtCore import QTimer
from krita import InfoObject, Selection
def msg(msg, duration=500):
Krita.instance().activeWindow().activeView().showFloatingMessage(msg, Krita.instance().icon("16_light_warning"), duration, 1)
def func():
inst = Krita.instance()
doc = inst.activeDocument()
node = doc.activeNode()
if node.type() != "paintlayer":
msg("need to select paint layer")
return
fn = "hsvadjustment"
msg(f"applying {fn}", 1000)
f = inst.filter(fn)
fp = InfoObject()
props = {'colorize': True, 'compatibilityMode': False, 'h': 150, 's': 50, 'type': 1, 'v': 0}
fp.setProperties(props)
f.setConfiguration(fp)
# mask should use whole document bounds
fm = doc.createFilterMask(fn, f, doc.rootNode())
# mask uses the current layer bounds
# fs = Selection()
# fs.selectAll(node, 255)
# fm = doc.createFilterMask(fn, f, fs)
node.addChildNode(fm, None)
doc.refreshProjection()
func()
Looks interesting. I will look into it. Thanks!