diff --git a/plugins/extensions/qmic/kis_import_qmic_processing_visitor.cpp b/plugins/extensions/qmic/kis_import_qmic_processing_visitor.cpp index ad1884c4c7..4fa032b362 100644 --- a/plugins/extensions/qmic/kis_import_qmic_processing_visitor.cpp +++ b/plugins/extensions/qmic/kis_import_qmic_processing_visitor.cpp @@ -1,95 +1,106 @@ /* * Copyright (c) 2013 Dmitry Kazakov * Copyright (c) 2013 Lukáš Tvrdý * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include "kis_qmic_simple_convertor.h" #include #include #include #include #include #include #include +#include #include "kis_import_qmic_processing_visitor.h" #include "gmic.h" KisImportQmicProcessingVisitor::KisImportQmicProcessingVisitor(const KisNodeListSP nodes, QVector *> images, const QRect &dstRect, KisSelectionSP selection) : m_nodes(nodes), m_images(images), m_dstRect(dstRect), m_selection(selection) { dbgPlugins << "KisImportQmicProcessingVisitor"; } void KisImportQmicProcessingVisitor::gmicImageToPaintDevice(gmic_image& srcGmicImage, KisPaintDeviceSP dst, KisSelectionSP selection, const QRect &dstRect) { dbgPlugins << "KisImportQmicProcessingVisitor::gmicImageToPaintDevice();"; if (selection) { KisPaintDeviceSP src = new KisPaintDevice(dst->colorSpace()); KisQmicSimpleConvertor::convertFromGmicFast(srcGmicImage, src, 255.0f); KisPainter painter(dst, selection); painter.setCompositeOp(COMPOSITE_COPY); painter.bitBlt(dstRect.topLeft(), src, QRect(QPoint(0,0),dstRect.size())); } else { KisQmicSimpleConvertor::convertFromGmicFast(srcGmicImage, dst, 255.0f); } + + // Some GMic filters encode layer position into the layer name. + // E.g. from extract foreground: "name([unnamed] [foreground]),pos(55,35)" + const QRegularExpression positionPattern(R"(\Wpos\((\d+),(\d+)\))"); + const QRegularExpressionMatch match = positionPattern.match(srcGmicImage.name); + if (match.hasMatch()) { + int x = match.captured(1).toInt(); + int y = match.captured(2).toInt(); + dst->moveTo(x, y); + } } void KisImportQmicProcessingVisitor::visitNodeWithPaintDevice(KisNode *node, KisUndoAdapter *undoAdapter) { int index = m_nodes->indexOf(node); if (index >= 0) { gmic_image *gimg = m_images[index]; dbgPlugins << "Importing layer index" << index << "Size: "<< gimg->_width << "x" << gimg->_height << "colorchannels: " << gimg->_spectrum; KisPaintDeviceSP dst = node->paintDevice(); KisTransaction transaction(dst); KisImportQmicProcessingVisitor::gmicImageToPaintDevice(*gimg, dst, m_selection, m_dstRect); if (undoAdapter) { transaction.commit(undoAdapter); node->setDirty(m_dstRect); } } } void KisImportQmicProcessingVisitor::visitExternalLayer(KisExternalLayer *layer, KisUndoAdapter *undoAdapter) { Q_UNUSED(layer); Q_UNUSED(undoAdapter); } void KisImportQmicProcessingVisitor::visitColorizeMask(KisColorizeMask *mask, KisUndoAdapter *undoAdapter) { Q_UNUSED(mask); Q_UNUSED(undoAdapter); }