Krita

ColorizeMask.h
1/*
2 * SPDX-FileCopyrightText: 2017 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6#ifndef LIBKIS_COLORIZEMASK_H
7#define LIBKIS_COLORIZEMASK_H
8
9#include <QObject>
10#include "Node.h"
11#include "ManagedColor.h"
12
13#include <kis_types.h>
14
15#include "kritalibkis_export.h"
16#include "libkis.h"
17
18/**
19 * @brief The ColorizeMask class
20 * A colorize mask is a mask type node that can be used
21 * to color in line art.
22 *
23@code
24window = Krita.instance().activeWindow()
25doc = Krita.instance().createDocument(10, 3, "Test", "RGBA", "U8", "", 120.0)
26window.addView(doc)
27root = doc.rootNode();
28node = doc.createNode("layer", "paintLayer")
29root.addChildNode(node, None)
30nodeData = QByteArray.fromBase64(b"AAAAAAAAAAAAAAAAEQYMBhEGDP8RBgz/EQYMAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARBgz5EQYM/xEGDAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEQYMAhEGDAkRBgwCAAAAAAAAAAAAAAAA");
31node.setPixelData(nodeData,0,0,10,3)
32
33cols = [ ManagedColor('RGBA','U8',''), ManagedColor('RGBA','U8','') ]
34cols[0].setComponents([0.65490198135376, 0.345098048448563, 0.474509805440903, 1.0]);
35cols[1].setComponents([0.52549022436142, 0.666666686534882, 1.0, 1.0]);
36keys = [
37 QByteArray.fromBase64(b"/48AAAAAAAAAAAAAAAAAAAAAAACmCwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"),
38 QByteArray.fromBase64(b"AAAAAAAAAACO9ocAAAAAAAAAAAAAAAAAAAAAAMD/uQAAAAAAAAAAAAAAAAAAAAAAGoMTAAAAAAAAAAAA")
39 ]
40
41mask = doc.createColorizeMask('c1')
42node.addChildNode(mask,None)
43mask.setEditKeyStrokes(True)
44
45mask.setUseEdgeDetection(True)
46mask.setEdgeDetectionSize(4.0)
47mask.setCleanUpAmount(70.0)
48mask.setLimitToDeviceBounds(True)
49mask.initializeKeyStrokeColors(cols)
50
51for col,key in zip(cols,keys):
52 mask.setKeyStrokePixelData(key,col,0,0,20,3)
53
54mask.updateMask()
55mask.setEditKeyStrokes(False);
56mask.setShowOutput(True);
57@endcode
58 */
59class KRITALIBKIS_EXPORT ColorizeMask : public Node
60{
61 Q_OBJECT
62 Q_DISABLE_COPY(ColorizeMask)
63
64public:
65 explicit ColorizeMask(KisImageSP image, QString name, QObject *parent = 0);
66 explicit ColorizeMask(KisImageSP image, KisColorizeMaskSP mask, QObject *parent = 0);
67 ~ColorizeMask() override;
68public Q_SLOTS:
69
70 /**
71 * @brief type Krita has several types of nodes, split in layers and masks. Group
72 * layers can contain other layers, any layer can contain masks.
73 *
74 * @return colorizemask
75 *
76 * If the Node object isn't wrapping a valid Krita layer or mask object, and
77 * empty string is returned.
78 */
79 virtual QString type() const override;
80
81 /**
82 * @brief keyStrokesColors
83 * Colors used in the Colorize Mask's keystrokes.
84 * @return a ManagedColor list containing the colors of keystrokes.
85 */
86 QList<ManagedColor*> keyStrokesColors() const;
87
88 /**
89 * @brief initializeKeyStrokeColors
90 * Set the colors to use for the Colorize Mask's keystrokes.
91 * @param colors a list of ManagedColor to use for the keystrokes.
92 * @param transparentIndex index of the color that should be marked as transparent.
93 */
94 void initializeKeyStrokeColors(QList<ManagedColor*> colors, int transparentIndex = -1);
95
96 /**
97 * @brief removeKeyStroke
98 * Remove a color from the Colorize Mask's keystrokes.
99 * @param color a ManagedColor to be removed from the keystrokes.
100 */
101 void removeKeyStroke(ManagedColor* color);
102
103 /**
104 * @brief transparencyIndex
105 * Index of the transparent color.
106 * @return an integer containing the index of the current color marked as transparent.
107 */
108 int transparencyIndex() const;
109
110 /**
111 * @brief keyStrokePixelData
112 * reads the given rectangle from the keystroke image data and returns it as a byte
113 * array. The pixel data starts top-left, and is ordered row-first.
114 * @param color a ManagedColor to get keystrokes pixeldata from.
115 * @param x x position from where to start reading
116 * @param y y position from where to start reading
117 * @param w row length to read
118 * @param h number of rows to read
119 * @return a QByteArray with the pixel data. The byte array may be empty.
120 */
121 QByteArray keyStrokePixelData(ManagedColor* color, int x, int y, int w, int h) const;
122
123 /**
124 * @brief setKeyStrokePixelData
125 * writes the given bytes, of which there must be enough, into the
126 * keystroke, the keystroke's original pixels are overwritten
127 *
128 * @param value the byte array representing the pixels. There must be enough bytes available.
129 * Krita will take the raw pointer from the QByteArray and start reading, not stopping before
130 * (number of channels * size of channel * w * h) bytes are read.
131 *
132 * @param color a ManagedColor to set keystrokes pixeldata for.
133 * @param x the x position to start writing from
134 * @param y the y position to start writing from
135 * @param w the width of each row
136 * @param h the number of rows to write
137 * @return true if writing the pixeldata worked
138 */
139 bool setKeyStrokePixelData(QByteArray value, ManagedColor* color, int x, int y, int w, int h);
140
141 /**
142 * @brief setUseEdgeDetection
143 * Activate this for line art with large solid areas, for example shadows on an object.
144 * @param value true to enable edge detection, false to disable.
145 */
146 void setUseEdgeDetection(bool value);
147
148 /**
149 * @brief useEdgeDetection
150 * @return true if Edge detection is enabled, false if disabled.
151 */
152 bool useEdgeDetection() const;
153
154 /**
155 * @brief setEdgeDetectionSize
156 * Set the value to the thinnest line on the image.
157 * @param value a float value of the edge size to detect in pixels.
158 */
159 void setEdgeDetectionSize(qreal value);
160
161 /**
162 * @brief edgeDetectionSize
163 * @return a float value of the edge detection size in pixels.
164 */
165 qreal edgeDetectionSize() const;
166
167 /**
168 * @brief setCleanUpAmount
169 * This will attempt to handle messy strokes that overlap the line art where they shouldn't.
170 * @param value a float value from 0.0 to 100.00 where 0.0 is no cleanup is done and 100.00 is most aggressive.
171 */
172 void setCleanUpAmount(qreal value);
173
174 /**
175 * @brief cleanUpAmount
176 * @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.
177 */
178 qreal cleanUpAmount() const;
179
180 /**
181 * @brief setLimitToDeviceBounds
182 * 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.
183 * @param value set true to enabled limit bounds, false to disable.
184 */
185 void setLimitToDeviceBounds(bool value);
186
187 /**
188 * @brief limitToDeviceBounds
189 * @return true if limit bounds is enabled, false if disabled.
190 */
191 bool limitToDeviceBounds() const;
192
193 /**
194 * @brief updateMask
195 * Process the Colorize Mask's keystrokes and generate a projection of the computed colors.
196 * @param force force an update
197 */
198 void updateMask(bool force = false);
199
200 void resetCache();
201
202 /**
203 * @brief showOutput
204 * Show output mode allows the user to see the result of the Colorize Mask's algorithm.
205 * @return true if edit show coloring mode is enabled, false if disabled.
206 */
207 bool showOutput() const;
208
209 /**
210 * @brief setShowOutput
211 * Toggle Colorize Mask's show output mode.
212 * @param enabled set true to enable show coloring mode and false to disable it.
213 */
214 void setShowOutput(bool enabled);
215
216 /**
217 * @brief editKeyStrokes
218 * Edit keystrokes mode allows the user to modify keystrokes on the active Colorize Mask.
219 * @return true if edit keystrokes mode is enabled, false if disabled.
220 */
221 bool editKeyStrokes() const;
222
223 /**
224 * @brief setEditKeyStrokes
225 * Toggle Colorize Mask's edit keystrokes mode.
226 * @param enabled set true to enable edit keystrokes mode and false to disable it.
227 */
228 void setEditKeyStrokes(bool enabled);
229
230};
231
232#endif // LIBKIS_COLORIZEMASK_H
233
234
The ColorizeMask class A colorize mask is a mask type node that can be used to color in line art.
The ManagedColor class is a class to handle colors that are color managed.
Node represents a layer or mask in a Krita image's Node hierarchy.
Definition Node.h:24
virtual QString type() const
type Krita has several types of nodes, split in layers and masks.
Definition Node.cpp:462
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.