Krita Source Code Documentation
Loading...
Searching...
No Matches
KisQmicImportTools Namespace Reference

Functions

KUndo2CommandapplyLayerNameChanges (const KisQMicImage &srcGmicImage, KisNode *node, KisSelectionSP selection)
 
void gmicImageToPaintDevice (const KisQMicImage &srcGmicImage, KisPaintDeviceSP dst, KisSelectionSP selection, const QRect &dstRect)
 
KisNodeListSP inputNodes (KisImageSP image, InputLayerMode inputMode, KisNodeSP currentNode)
 

Function Documentation

◆ applyLayerNameChanges()

KUndo2Command * KisQmicImportTools::applyLayerNameChanges ( const KisQMicImage & srcGmicImage,
KisNode * node,
KisSelectionSP selection )

Definition at line 33 of file kis_qmic_import_tools.cpp.

36{
37 dbgPlugins << "KisQmicImportTools::applyLayerNameChanges";
38
39 auto *cmd = new KisCommandUtils::CompositeCommand();
40
41 dbgPlugins << "Layer name: " << srcGmicImage.m_layerName;
42
43 {
44 const QRegExp modeRe(R"(mode\‍(\s*([^)]*)\s*\))");
45 if (modeRe.indexIn(srcGmicImage.m_layerName) != -1) {
46 QString modeStr = modeRe.cap(1).trimmed();
47 auto translatedMode =
49 dbgPlugins << "Detected mode: " << modeStr << " => "
50 << translatedMode;
51 if (!translatedMode.isNull()) {
52 cmd->addCommand(
53 new KisNodeCompositeOpCommand(node, translatedMode));
54 }
55 }
56 }
57
58 {
59 const QRegExp opacityRe(R"(opacity\‍(\s*([^)]*)\s*\))");
60
61 if (opacityRe.indexIn(srcGmicImage.m_layerName) != -1) {
62 const auto opacity = opacityRe.cap(1).toFloat();
63 dbgPlugins << "Detected opacity: " << opacity
64 << std::lround(opacity / 100.f * 255.f);
65 cmd->addCommand(
66 new KisNodeOpacityCommand(node,
67 static_cast<quint8>(std::lround(
68 float(opacity * 255) / 100.f))));
69 }
70 }
71
72 {
73 const QRegExp nameRe(R"(name\‍(\s*([^)]*)\s*\))");
74
75 if (nameRe.indexIn(srcGmicImage.m_layerName) != -1) {
76 const auto name = nameRe.cap(1);
77 dbgPlugins << "Detected layer name: " << name;
78 cmd->addCommand(new KisNodeRenameCommand(node, node->name(), name));
79 // apply command
80 }
81 }
82
83 if (!selection) {
84 // Some GMic filters encode layer position into the layer name.
85 // E.g. from extract foreground: "name([unnamed]
86 // [foreground]),pos(55,35)"
87 const QRegularExpression positionPattern(
88 R"(pos\‍(\s*(-?\d*)[^)](-?\d*)\s*\))");
89 const QRegularExpressionMatch match =
90 positionPattern.match(srcGmicImage.m_layerName);
91 if (match.hasMatch()) {
92 const auto x = match.captured(1).toInt();
93 const auto y = match.captured(2).toInt();
94 const QPoint oldPos(node->x(), node->y());
95 const QPoint newPos(x, y);
96 dbgPlugins << "Detected layer position: " << oldPos << newPos
97 << node->paintDevice()->exactBounds();
98 cmd->addCommand(new KisNodeMoveCommand2(node, oldPos, newPos));
99 }
100 }
101
102 return cmd;
103}
The command for setting the composite op.
The command for setting the node opacity.
The command for setting the node's name.
QRect exactBounds() const
static QString stringToBlendingMode(QString str)
#define dbgPlugins
Definition kis_debug.h:51
const char * name(StandardAction id)
virtual qint32 y() const
virtual qint32 x() const
virtual KisPaintDeviceSP paintDevice() const =0
QString name() const

References dbgPlugins, KisPaintDevice::exactBounds(), KisQMicImage::m_layerName, KisBaseNode::name(), KisBaseNode::paintDevice(), KisQmicSimpleConvertor::stringToBlendingMode(), KisBaseNode::x(), and KisBaseNode::y().

◆ gmicImageToPaintDevice()

void KisQmicImportTools::gmicImageToPaintDevice ( const KisQMicImage & srcGmicImage,
KisPaintDeviceSP dst,
KisSelectionSP selection,
const QRect & dstRect )

Definition at line 105 of file kis_qmic_import_tools.cpp.

109{
110 dbgPlugins << "KisQmicImportTools::gmicImageToPaintDevice()" << dstRect;
111
112 if (selection) {
114 KisQmicSimpleConvertor::convertFromGmicFast(srcGmicImage, src, 255.0f);
115 KisPainter painter(dst, selection);
116 painter.setCompositeOpId(COMPOSITE_COPY);
117 painter.bitBlt(dstRect.topLeft(),
118 src,
119 QRect(QPoint(0, 0), dstRect.size()));
120 } else {
121 KisQmicSimpleConvertor::convertFromGmicFast(srcGmicImage, dst, 255.0f);
122 }
123}
const QString COMPOSITE_COPY
const KoColorSpace * colorSpace() const
static void convertFromGmicFast(const KisQMicImage &gmicImage, KisPaintDeviceSP dst, float gmicUnitValue)
Fast versions.

References KisPainter::bitBlt(), KisPaintDevice::colorSpace(), COMPOSITE_COPY, KisQmicSimpleConvertor::convertFromGmicFast(), dbgPlugins, and KisPainter::setCompositeOpId().

◆ inputNodes()

KisNodeListSP KisQmicImportTools::inputNodes ( KisImageSP image,
InputLayerMode inputMode,
KisNodeSP currentNode )

Definition at line 126 of file kis_qmic_import_tools.cpp.

127{
128 /*
129 ACTIVE_LAYER,
130 ALL_LAYERS,
131 ACTIVE_LAYER_BELOW_LAYER,
132 ACTIVE_LAYER_ABOVE_LAYER,
133 ALL_VISIBLE_LAYERS,
134 ALL_INVISIBLE_LAYERS,
135 ALL_VISIBLE_LAYERS_DECR,
136 ALL_INVISIBLE_DECR,
137 ALL_DECR
138 */
139 const auto isAvailable = [](KisNodeSP node) -> bool {
140 auto *paintLayer = dynamic_cast<KisPaintLayer *>(node.data());
141 return paintLayer && paintLayer->visible(false);
142 };
143
144 KisNodeListSP result(new QList<KisNodeSP>());
145 switch (inputMode) {
147 break;
148 }
150 if (isAvailable(currentNode)) {
151 result->prepend(currentNode);
152 }
153 break; // drop down in case of one more layer modes
154 }
155 case InputLayerMode::All: {
156 result = [&]() {
159 image->root(),
160 [&](KisNodeSP item) {
161 auto *paintLayer =
162 dynamic_cast<KisPaintLayer *>(item.data());
163 if (paintLayer) {
164 r->prepend(item);
165 }
166 });
167 return r;
168 }();
169 break;
170 }
172 if (isAvailable(currentNode)) {
173 result->prepend(currentNode);
174 if (isAvailable(currentNode->prevSibling())) {
175 result->prepend(currentNode->prevSibling());
176 }
177 }
178 break;
179 }
181 if (isAvailable(currentNode)) {
182 result->prepend(currentNode);
183 if (isAvailable(currentNode->nextSibling())) {
184 result->prepend(currentNode->nextSibling());
185 }
186 }
187 break;
188 }
191 const bool visibility = (inputMode == InputLayerMode::AllInvisible);
192
193 result = [&]() {
196 image->root(),
197 [&](KisNodeSP item) {
198 auto *paintLayer =
199 dynamic_cast<KisPaintLayer *>(item.data());
200 if (paintLayer
201 && paintLayer->visible(false) == visibility) {
202 r->prepend(item);
203 }
204 });
205 return r;
206 }();
207 break;
208 }
210 default: {
211 qWarning()
212 << "Inputmode" << static_cast<int>(inputMode)
213 << "must be specified by GMic or is not implemented in Krita";
214 break;
215 }
216 }
217 return result;
218}
void recursiveApplyNodes(NodePointer node, Functor func)
virtual bool visible(bool recursive=false) const
KisNodeSP prevSibling() const
Definition kis_node.cpp:402
KisNodeSP nextSibling() const
Definition kis_node.cpp:408

References Active, ActiveAndAbove, ActiveAndBelow, All, AllInvisible, AllVisible, KisNode::nextSibling(), NoInput, KisNode::prevSibling(), KisLayerUtils::recursiveApplyNodes(), KisNodeFacade::root, and KisBaseNode::visible().