Class ColorizeMask
Build from ColorizeMask.h
Krita 5.2.0

The ColorizeMask class A colorize mask is a mask type node that can be used to color in line art.

window = Krita.instance().activeWindow()doc = Krita.instance().createDocument(10, 3, "Test", "RGBA", "U8", "", 120.0)window.addView(doc)root = doc.rootNode();node = doc.createNode("layer", "paintLayer")root.addChildNode(node, None)nodeData = QByteArray.fromBase64(b"AAAAAAAAAAAAAAAAEQYMBhEGDP8RBgz/EQYMAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARBgz5EQYM/xEGDAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEQYMAhEGDAkRBgwCAAAAAAAAAAAAAAAA");node.setPixelData(nodeData,0,0,10,3)cols = [ ManagedColor('RGBA','U8',''), ManagedColor('RGBA','U8','') ]cols[0].setComponents([0.65490198135376, 0.345098048448563, 0.474509805440903, 1.0]);cols[1].setComponents([0.52549022436142, 0.666666686534882, 1.0, 1.0]);keys = [ QByteArray.fromBase64(b"/48AAAAAAAAAAAAAAAAAAAAAAACmCwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"), QByteArray.fromBase64(b"AAAAAAAAAACO9ocAAAAAAAAAAAAAAAAAAAAAAMD/uQAAAAAAAAAAAAAAAAAAAAAAGoMTAAAAAAAAAAAA") ]mask = doc.createColorizeMask('c1')node.addChildNode(mask,None)mask.setEditKeyStrokes(True)mask.setUseEdgeDetection(True)mask.setEdgeDetectionSize(4.0)mask.setCleanUpAmount(70.0)mask.setLimitToDeviceBounds(True)mask.initializeKeyStrokeColors(cols)for col,key in zip(cols,keys): mask.setKeyStrokePixelData(key,col,0,0,20,3)mask.updateMask()mask.setEditKeyStrokes(False);mask.setShowOutput(True);

Methods

cleanUpAmount()float edgeDetectionSize()float editKeyStrokes()bool initializeKeyStrokeColors(colors: list[ManagedColor], transparentIndex: int = 1) keyStrokePixelData(color: ManagedColor, x: int, y: int, w: int, h: int)QByteArray keyStrokesColors()list[ManagedColor] limitToDeviceBounds()bool removeKeyStroke(color: ManagedColor) resetCache() setCleanUpAmount(value: float) setEdgeDetectionSize(value: float) setEditKeyStrokes(enabled: bool) setKeyStrokePixelData(value: QByteArray, color: ManagedColor, x: int, y: int, w: int, h: int)bool setLimitToDeviceBounds(value: bool) setShowOutput(enabled: bool) setUseEdgeDetection(value: bool) showOutput()bool transparencyIndex()int updateMask(force: bool = False) useEdgeDetection()bool

Re-implemented methods

type()str

Member documentation

cleanUpAmount()float
Krita 5.2.0

Return

a float value of 0.0 to 100.0 representing the cleanup amount where 0.0 is no cleanup is done and 100.00 is most aggressive.

edgeDetectionSize()float
Krita 5.2.0

Return

a float value of the edge detection size in pixels.

editKeyStrokes()bool
Krita 5.2.0

Edit keystrokes mode allows the user to modify keystrokes on the active Colorize Mask.

Return

true if edit keystrokes mode is enabled, false if disabled.

initializeKeyStrokeColors(colors: list[ManagedColor], transparentIndex: int = 1)
Krita 5.2.0

Set the colors to use for the Colorize Mask's keystrokes.

Parameters

colors

a list of ManagedColor to use for the keystrokes.

transparentIndex

index of the color that should be marked as transparent.

keyStrokePixelData(color: ManagedColor, x: int, y: int, w: int, h: int)QByteArray
Krita 5.2.0

reads the given rectangle from the keystroke image data and returns it as a byte array. The pixel data starts top-left, and is ordered row-first.

Parameters

color

a ManagedColor to get keystrokes pixeldata from.

x

x position from where to start reading

y

y position from where to start reading

w

row length to read

h

number of rows to read

Return

a QByteArray with the pixel data. The byte array may be empty.

Krita 5.2.0

Colors used in the Colorize Mask's keystrokes.

Return

a ManagedColor list containing the colors of keystrokes.

limitToDeviceBounds()bool
Krita 5.2.0

Return

true if limit bounds is enabled, false if disabled.

Krita 5.2.0

Remove a color from the Colorize Mask's keystrokes.

Parameters

color

a ManagedColor to be removed from the keystrokes.

Krita 5.2.0
setCleanUpAmount(value: float)
Krita 5.2.0

This will attempt to handle messy strokes that overlap the line art where they shouldn't.

Parameters

value

a float value from 0.0 to 100.00 where 0.0 is no cleanup is done and 100.00 is most aggressive.

setEdgeDetectionSize(value: float)
Krita 5.2.0

Set the value to the thinnest line on the image.

Parameters

value

a float value of the edge size to detect in pixels.

setEditKeyStrokes(enabled: bool)
Krita 5.2.0

Toggle Colorize Mask's edit keystrokes mode.

Parameters

enabled

set true to enable edit keystrokes mode and false to disable it.

setKeyStrokePixelData(value: QByteArray, color: ManagedColor, x: int, y: int, w: int, h: int)bool
Krita 5.2.0

writes the given bytes, of which there must be enough, into the keystroke, the keystroke's original pixels are overwritten

Parameters

value

the byte array representing the pixels. There must be enough bytes available. Krita will take the raw pointer from the QByteArray and start reading, not stopping before (number of channels * size of channel * w * h) bytes are read.

color

a ManagedColor to set keystrokes pixeldata for.

x

the x position to start writing from

y

the y position to start writing from

w

the width of each row

h

the number of rows to write

Return

true if writing the pixeldata worked

setLimitToDeviceBounds(value: bool)
Krita 5.2.0

Limit the colorize mask to the combined layer bounds of the strokes and the line art it is filling. This can speed up the use of the mask on complicated compositions, such as comic pages.

Parameters

value

set true to enabled limit bounds, false to disable.

setShowOutput(enabled: bool)
Krita 5.2.0

Toggle Colorize Mask's show output mode.

Parameters

enabled

set true to enable show coloring mode and false to disable it.

setUseEdgeDetection(value: bool)
Krita 5.2.0

Activate this for line art with large solid areas, for example shadows on an object.

Parameters

value

true to enable edge detection, false to disable.

showOutput()bool
Krita 5.2.0

Show output mode allows the user to see the result of the Colorize Mask's algorithm.

Return

true if edit show coloring mode is enabled, false if disabled.

transparencyIndex()int
Krita 5.2.0

Index of the transparent color.

Return

an integer containing the index of the current color marked as transparent.

type()str
Krita 5.2.0

Krita has several types of nodes, split in layers and masks. Group layers can contain other layers, any layer can contain masks.

Return

colorizemask

If the Node object isn't wrapping a valid Krita layer or mask object, and empty string is returned.

updateMask(force: bool = False)
Krita 5.2.0

Process the Colorize Mask's keystrokes and generate a projection of the computed colors.

Parameters

force

force an update

useEdgeDetection()bool
Krita 5.2.0

Return

true if Edge detection is enabled, false if disabled.