diff --git a/plugins/tools/tool_smart_patch/kis_inpaint.cpp b/plugins/tools/tool_smart_patch/kis_inpaint.cpp index 7d3321330b..f639d409c7 100644 --- a/plugins/tools/tool_smart_patch/kis_inpaint.cpp +++ b/plugins/tools/tool_smart_patch/kis_inpaint.cpp @@ -1,967 +1,974 @@ /* * Copyright (c) 2017 Eugene Ingerman * * 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. */ /** * Inpaint using the PatchMatch Algorithm * * | PatchMatch : A Randomized Correspondence Algorithm for Structural Image Editing * | by Connelly Barnes and Eli Shechtman and Adam Finkelstein and Dan B Goldman * | ACM Transactions on Graphics (Proc. SIGGRAPH), vol.28, aug-2009 * * Original author Xavier Philippeau * Code adopted from: David Chatting https://github.com/davidchatting/PatchMatch */ #include #include #include #include "kis_paint_device.h" #include "kis_debug.h" #include "kis_paint_device_debug_utils.h" -#include "kis_random_accessor_ng.h" +//#include "kis_random_accessor_ng.h" #include #include #include #include "KoColor.h" #include "KoColorSpace.h" #include "KoChannelInfo.h" #include "KoMixColorsOp.h" #include "KoColorModelStandardIds.h" #include "KoColorSpaceRegistry.h" -#include -#include +//#include +//#include -#include -#include -#include -#include +//#include +//#include +//#include +//#include const int MAX_DIST = 65535; const quint8 MASK_SET = 0; const quint8 MASK_CLEAR = 255; void patchImage(KisPaintDeviceSP, KisPaintDeviceSP, int radius); class ImageView { protected: quint8* m_data; int m_imageWidth; int m_imageHeight; int m_pixelSize; public: void Init(quint8* _data, int _imageWidth, int _imageHeight, int _pixelSize) { m_data = _data; m_imageWidth = _imageWidth; m_imageHeight = _imageHeight; m_pixelSize = _pixelSize; } ImageView() : m_data(nullptr) { m_imageHeight = m_imageWidth = m_pixelSize = 0; } ImageView(quint8* _data, int _imageWidth, int _imageHeight, int _pixelSize) { Init(_data, _imageWidth, _imageHeight, _pixelSize); } quint8* operator()(int x, int y) const { Q_ASSERT(m_data); Q_ASSERT((x >= 0) && (x < m_imageWidth) && (y >= 0) && (y < m_imageHeight)); return (m_data + x * m_pixelSize + y * m_imageWidth * m_pixelSize); } ImageView& operator=(const ImageView& other) { if (this != &other) { if (other.num_bytes() != num_bytes()) { delete[] m_data; m_data = nullptr; //to preserve invariance if next line throws exception m_data = new quint8[other.num_bytes()]; } std::copy(other.data(), other.data() + other.num_bytes(), m_data); m_imageHeight = other.m_imageHeight; m_imageWidth = other.m_imageWidth; m_pixelSize = other.m_pixelSize; } return *this; } //move assignement operator ImageView& operator=(ImageView&& other) noexcept { if (this != &other) { delete[] m_data; m_data = nullptr; Init(other.data(), other.m_imageWidth, other.m_imageHeight, other.m_pixelSize); other.m_data = nullptr; } return *this; } virtual ~ImageView() {} //this class doesn't own m_data, so it ain't going to delete it either. quint8* data(void) const { return m_data; } inline int num_elements(void) const { return m_imageHeight * m_imageWidth; } inline int num_bytes(void) const { return m_imageHeight * m_imageWidth * m_pixelSize; } inline int pixel_size(void) const { return m_pixelSize; } void saveToDevice(KisPaintDeviceSP outDev) { QRect imSize(QPoint(0, 0), QSize(m_imageWidth, m_imageHeight)); - Q_ASSERT(outDev->colorSpace()->pixelSize() == m_pixelSize); + Q_ASSERT(outDev->colorSpace()->pixelSize() == (quint32) m_pixelSize); outDev->writeBytes(m_data, imSize); } void DebugDump(const QString& fnamePrefix) { QRect imSize(QPoint(0, 0), QSize(m_imageWidth, m_imageHeight)); const KoColorSpace* cs = (m_pixelSize == 1) ? KoColorSpaceRegistry::instance()->alpha8() : (m_pixelSize == 3) ? KoColorSpaceRegistry::instance()->colorSpace("RGB", "U8", "") : KoColorSpaceRegistry::instance()->colorSpace("RGBA", "U8", ""); KisPaintDeviceSP dbout = new KisPaintDevice(cs); saveToDevice(dbout); KIS_DUMP_DEVICE_2(dbout, imSize, fnamePrefix, "/home/eugening/Projects/img"); } }; class ImageData : public ImageView { public: ImageData() : ImageView() {} void Init(int _imageWidth, int _imageHeight, int _pixelSize) { m_data = new quint8[ _imageWidth * _imageHeight * _pixelSize ]; ImageView::Init(m_data, _imageWidth, _imageHeight, _pixelSize); } ImageData(int _imageWidth, int _imageHeight, int _pixelSize) : ImageView() { Init(_imageWidth, _imageHeight, _pixelSize); } void Init(KisPaintDeviceSP imageDev, const QRect& imageSize) { const KoColorSpace* cs = imageDev->colorSpace(); m_pixelSize = cs->pixelSize(); m_data = new quint8[ imageSize.width()*imageSize.height()*cs->pixelSize() ]; imageDev->readBytes(m_data, imageSize.x(), imageSize.y(), imageSize.width(), imageSize.height()); ImageView::Init(m_data, imageSize.width(), imageSize.height(), m_pixelSize); } ImageData(KisPaintDeviceSP imageDev, const QRect& imageSize) : ImageView() { Init(imageDev, imageSize); } virtual ~ImageData() { delete[] m_data; //ImageData owns m_data, so it has to delete it } }; class MaskedImage : public KisShared { private: QRect imageSize; int nChannels; const KoColorSpace* cs; const KoColorSpace* csMask; ImageData maskData; ImageData imageData; void cacheImageSize(KisPaintDeviceSP imageDev) { imageSize = imageDev->exactBounds(); } void cacheImage(KisPaintDeviceSP imageDev) { Q_ASSERT(!imageSize.isEmpty() && imageSize.isValid()); cs = imageDev->colorSpace(); nChannels = cs->channelCount(); imageData.Init(imageDev, imageSize); } void cacheMask(KisPaintDeviceSP maskDev) { Q_ASSERT(!imageSize.isEmpty() && imageSize.isValid()); Q_ASSERT(maskDev->colorSpace()->pixelSize() == 1); csMask = maskDev->colorSpace(); maskData.Init(maskDev, imageSize); } MaskedImage() {} public: void toPaintDevice(KisPaintDeviceSP imageDev) { imageData.saveToDevice(imageDev); } void DebugDump(const QString& name) { imageData.DebugDump(name); } void clearMask(void) { std::fill(maskData.data(), maskData.data() + maskData.num_bytes(), MASK_CLEAR); } void initialize(KisPaintDeviceSP _imageDev, KisPaintDeviceSP _maskDev) { cacheImageSize(_imageDev); cacheImage(_imageDev); cacheMask(_maskDev); } -// void clone(const MaskeImageSP other) -// { -// return new MaskedImage(imageDev, maskDev); -// } - MaskedImage(KisPaintDeviceSP _imageDev, KisPaintDeviceSP _maskDev) { initialize(_imageDev, _maskDev); } void downsample2x(void) { int H = imageSize.height(); int W = imageSize.width(); int newW = W / 2, newH = H / 2; KisPaintDeviceSP imageDev = new KisPaintDevice(cs); KisPaintDeviceSP maskDev = new KisPaintDevice(csMask); imageDev->writeBytes(imageData.data(), 0, 0, W, H); maskDev->writeBytes(maskData.data(), 0, 0, W, H); ImageData newImage(newW, newH, cs->pixelSize()); ImageData newMask(newW, newH, 1); KoDummyUpdater updater; KisTransformWorker worker(imageDev, 1. / 2., 1. / 2., 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, &updater, KisFilterStrategyRegistry::instance()->value("Bicubic")); worker.run(); KisTransformWorker workerMask(maskDev, 1. / 2., 1. / 2., 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, &updater, KisFilterStrategyRegistry::instance()->value("Bicubic")); workerMask.run(); imageDev->readBytes(newImage.data(), 0, 0, newW, newH); maskDev->readBytes(newMask.data(), 0, 0, newW, newH); imageData = std::move(newImage); maskData = std::move(newMask); for (int i = 0; i < imageData.num_elements(); ++i) { quint8* maskPix = maskData.data() + i * maskData.pixel_size(); if (*maskPix < MASK_CLEAR ) { for (int k = 0; k < imageData.pixel_size(); k++) *(imageData.data() + i * imageData.pixel_size() + k) = 0; } else { *maskPix = MASK_CLEAR; } } imageSize = QRect(0, 0, newW, newH); // int nmasked = countMasked(); // printf("Masked: %d size: %dx%d\n", nmasked, newW, newH); // maskData.DebugDump("maskData"); } void upscale(int newW, int newH) { int H = imageSize.height(); int W = imageSize.width(); ImageData newImage(newW, newH, cs->pixelSize()); ImageData newMask(newW, newH, 1); QVector colors(nChannels, 0.f); QVector v(nChannels, 0.f); for (int y = 0; y < newH; ++y) { for (int x = 0; x < newW; ++x) { // original pixel int xs = (x * W) / newW; int ys = (y * H) / newH; // copy to new image if (!isMasked(xs, ys)) { std::copy(imageData(xs, ys), imageData(xs, ys) + imageData.pixel_size(), newImage(x, y)); *newMask(x, y) = MASK_CLEAR; } else { std::fill(newImage(x, y), newImage(x, y) + newImage.pixel_size(), 0); *newMask(x, y) = MASK_SET; } } } imageData = std::move(newImage); maskData = std::move(newMask); imageSize = QRect(0, 0, newW, newH); } QRect size() { return imageSize; } KisSharedPtr copy(void) { KisSharedPtr clone = new MaskedImage(); clone->imageSize = this->imageSize; clone->nChannels = this->nChannels; clone->maskData = this->maskData; clone->imageData = this->imageData; clone->cs = this->cs; clone->csMask = this->csMask; return clone; } int countMasked(void) { int count = std::count_if(maskData.data(), maskData.data() + maskData.num_elements(), [](quint8 v) { return v < MASK_CLEAR; }); return count; } inline bool isMasked(int x, int y) { return (*maskData(x, y) < MASK_CLEAR); } //returns true if the patch contains a masked pixel bool containsMasked(int x, int y, int S) { for (int dy = -S; dy <= S; ++dy) { int ys = y + dy; if (ys < 0 || ys >= imageSize.height()) continue; for (int dx = -S; dx <= S; ++dx) { int xs = x + dx; if (xs < 0 || xs >= imageSize.width()) continue; if (isMasked(xs, ys)) return true; } } return false; } inline quint8 getImagePixelU8(int x, int y, int chan) const { return cs->scaleToU8(imageData(x, y), chan); } inline QVector getImagePixels(int x, int y) const { QVector v(cs->channelCount()); cs->normalisedChannelsValue(imageData(x, y), v); return v; } inline quint8* getImagePixel(int x, int y) { return imageData(x, y); } inline void setImagePixels(int x, int y, QVector& value) { cs->fromNormalisedChannelsValue(imageData(x, y), value); } inline void mixColors(std::vector< quint8* > pixels, std::vector< float > w, float wsum, quint8* dst) { const KoMixColorsOp* mixOp = cs->mixColorsOp(); size_t n = w.size(); assert(pixels.size() == n); std::vector< qint16 > weights; weights.clear(); float dif = 0; float scale = 255 / (wsum + 0.001); for (auto& v : w) { //compensated summation to increase accuracy float v1 = v * scale + dif; float v2 = std::round(v1); dif = v1 - v2; weights.push_back(v2); } mixOp->mixColors(pixels.data(), weights.data(), n, dst); } inline void setMask(int x, int y, quint8 v) { *(maskData(x, y)) = v; } inline int channelCount(void) const { return cs->channelCount(); } float distance(int x, int y, const MaskedImage& other, int xo, int yo) { float dsq = 0; quint32 nchannels = channelCount(); quint8* v1 = imageData(x, y); quint8* v2 = other.imageData(xo, yo); for (quint32 chan = 0; chan < nchannels; chan++) { //It's very important not to lose precision in the next line //TODO: This code only works for 8bpp data. Refactor to make it universal. float v = (float)(*((quint8*)v1 + chan)) - (float)(*((quint8*)v2 + chan)); dsq += v * v; } return dsq; } }; typedef KisSharedPtr MaskedImageSP; struct NNPixel { int x; int y; int distance; }; typedef boost::multi_array NNArray_type; struct Vote_elem { QVector channel_values; float w; }; typedef boost::multi_array Vote_type; class NearestNeighborField : public KisShared { private: template< typename T> T randomInt(T range) { return rand() % range; } //compute intial value of the distance term void initialize(void) { for (int y = 0; y < imSize.height(); y++) { for (int x = 0; x < imSize.width(); x++) { field[x][y].distance = distance(x, y, field[x][y].x, field[x][y].y); //if the distance is "infinity", try to find a better link int iter = 0; const int maxretry = 20; while (field[x][y].distance == MAX_DIST && iter < maxretry) { field[x][y].x = randomInt(imSize.width() + 1); field[x][y].y = randomInt(imSize.height() + 1); field[x][y].distance = distance(x, y, field[x][y].x, field[x][y].y); iter++; } } } } void init_similarity_curve(void) { float s_zero = 0.999; float t_halfmax = 0.10; float x = (s_zero - 0.5) * 2; float invtanh = 0.5 * std::log((1. + x) / (1. - x)); float coef = invtanh / t_halfmax; similarity.resize(MAX_DIST + 1); for (int i = 0; i < (int)similarity.size(); i++) { float t = (float)i / similarity.size(); similarity[i] = 0.5 - 0.5 * std::tanh(coef * (t - t_halfmax)); } } private: int patchSize; //patch size public: MaskedImageSP input; MaskedImageSP output; QRect imSize; NNArray_type field; std::vector similarity; quint32 nColors; QList channels; public: NearestNeighborField(const MaskedImageSP _input, MaskedImageSP _output, int _patchsize) : patchSize(_patchsize), input(_input), output(_output) { imSize = input->size(); field.resize(boost::extents[imSize.width()][imSize.height()]); init_similarity_curve(); nColors = input->channelCount(); //only color count, doesn't include alpha channels } void randomize(void) { for (int y = 0; y < imSize.height(); y++) { for (int x = 0; x < imSize.width(); x++) { field[x][y].x = randomInt(imSize.width() + 1); field[x][y].y = randomInt(imSize.height() + 1); field[x][y].distance = MAX_DIST; } } initialize(); } //initialize field from an existing (possibly smaller) nearest neighbor field void initialize(const NearestNeighborField& nnf) { float xscale = imSize.width() / nnf.imSize.width(); float yscale = imSize.height() / nnf.imSize.height(); for (int y = 0; y < imSize.height(); y++) { for (int x = 0; x < imSize.width(); x++) { int xlow = std::min((int)(x / xscale), nnf.imSize.width() - 1); int ylow = std::min((int)(y / yscale), nnf.imSize.height() - 1); field[x][y].x = nnf.field[xlow][ylow].x * xscale; field[x][y].y = nnf.field[xlow][ylow].y * yscale; field[x][y].distance = MAX_DIST; } } initialize(); } //multi-pass NN-field minimization (see "PatchMatch" - page 4) void minimize(int pass) { int min_x = 0; int min_y = 0; int max_x = imSize.width() - 1; int max_y = imSize.height() - 1; for (int i = 0; i < pass; i++) { //scanline order for (int y = min_y; y < max_y; y++) for (int x = min_x; x <= max_x; x++) if (field[x][y].distance > 0) minimizeLink(x, y, 1); //reverse scanline order for (int y = max_y; y >= min_y; y--) for (int x = max_x; x >= min_x; x--) if (field[x][y].distance > 0) minimizeLink(x, y, -1); } } void minimizeLink(int x, int y, int dir) { int xp, yp, dp; //Propagation Left/Right if (x - dir > 0 && x - dir < imSize.width()) { xp = field[x - dir][y].x + dir; yp = field[x - dir][y].y; dp = distance(x, y, xp, yp); if (dp < field[x][y].distance) { field[x][y].x = xp; field[x][y].y = yp; field[x][y].distance = dp; } } //Propagation Up/Down if (y - dir > 0 && y - dir < imSize.height()) { xp = field[x][y - dir].x; yp = field[x][y - dir].y + dir; dp = distance(x, y, xp, yp); if (dp < field[x][y].distance) { field[x][y].x = xp; field[x][y].y = yp; field[x][y].distance = dp; } } //Random search int wi = std::max(output->size().width(), output->size().height()); int xpi = field[x][y].x; int ypi = field[x][y].y; while (wi > 0) { xp = xpi + randomInt(2 * wi) - wi; yp = ypi + randomInt(2 * wi) - wi; xp = std::max(0, std::min(output->size().width() - 1, xp)); yp = std::max(0, std::min(output->size().height() - 1, yp)); dp = distance(x, y, xp, yp); if (dp < field[x][y].distance) { field[x][y].x = xp; field[x][y].y = yp; field[x][y].distance = dp; } wi /= 2; } } //compute distance between two patches int distance(int x, int y, int xp, int yp) { float distance = 0; float wsum = 0; float ssdmax = nColors * 255 * 255; //for each pixel in the source patch for (int dy = -patchSize; dy <= patchSize; dy++) { for (int dx = -patchSize; dx <= patchSize; dx++) { wsum += ssdmax; int xks = x + dx; int yks = y + dy; if (xks < 0 || xks >= input->size().width()) { distance += ssdmax; continue; } if (yks < 0 || yks >= input->size().height()) { distance += ssdmax; continue; } //cannot use masked pixels as a valid source of information if (input->isMasked(xks, yks)) { distance += ssdmax; continue; } //corresponding pixel in target patch int xkt = xp + dx; int ykt = yp + dy; if (xkt < 0 || xkt >= output->size().width()) { distance += ssdmax; continue; } if (ykt < 0 || ykt >= output->size().height()) { distance += ssdmax; continue; } //cannot use masked pixels as a valid source of information if (output->isMasked(xkt, ykt)) { distance += ssdmax; continue; } //SSD distance between pixels float ssd = input->distance(xks, yks, *output, xkt, ykt); //long ssd = input->distance(xks, yks, *input, xkt, ykt); distance += ssd; } } return (int)(MAX_DIST * (distance / wsum)); } static MaskedImageSP ExpectationMaximization(KisSharedPtr TargetToSource, int level, int radius, QList& pyramid); static void ExpectationStep(KisSharedPtr nnf, MaskedImageSP source, MaskedImageSP target, bool upscale); void EM_Step(MaskedImageSP source, MaskedImageSP target, int R, bool upscaled); }; typedef KisSharedPtr NearestNeighborFieldSP; class Inpaint { private: KisPaintDeviceSP devCache; MaskedImageSP initial; NearestNeighborFieldSP nnf_TargetToSource; NearestNeighborFieldSP nnf_SourceToTarget; int radius; QList pyramid; public: Inpaint(KisPaintDeviceSP dev, KisPaintDeviceSP devMask, int _radius) { initial = new MaskedImage(dev, devMask); radius = _radius; devCache = dev; } MaskedImageSP patch(void); MaskedImageSP patch_simple(void); }; MaskedImageSP Inpaint::patch() { MaskedImageSP source = initial->copy(); pyramid.append(initial); QRect size = source->size(); - std::cerr << "countMasked: " << source->countMasked() << "\n"; + //qDebug() << "countMasked: " << source->countMasked() << "\n"; while ((size.width() > radius) && (size.height() > radius) && source->countMasked() > 0) { - std::cerr << "countMasked: " << source->countMasked() << "\n"; source->downsample2x(); //source->DebugDump("Pyramid"); - std::cerr << "countMasked1: " << source->countMasked() << "\n"; + //qDebug() << "countMasked1: " << source->countMasked() << "\n"; pyramid.append(source->copy()); size = source->size(); } int maxlevel = pyramid.size(); - std::cerr << "MaxLevel: " << maxlevel << "\n"; + //qDebug() << "MaxLevel: " << maxlevel << "\n"; // The initial target is the same as the smallest source. // We consider that this target contains no masked pixels MaskedImageSP target = source->copy(); target->clearMask(); //recursively building nearest neighbor field for (int level = maxlevel - 1; level > 0; level--) { source = pyramid.at(level); if (level == maxlevel - 1) { //random initial guess nnf_TargetToSource = new NearestNeighborField(target, source, radius); nnf_TargetToSource->randomize(); } else { // then, we use the rebuilt (upscaled) target // and reuse the previous NNF as initial guess NearestNeighborFieldSP new_nnf_rev = new NearestNeighborField(target, source, radius); new_nnf_rev->initialize(*nnf_TargetToSource); nnf_TargetToSource = new_nnf_rev; } //Build an upscaled target by EM-like algorithm (see "PatchMatch" - page 6) target = NearestNeighborField::ExpectationMaximization(nnf_TargetToSource, level, radius, pyramid); - target->DebugDump( "target" ); + //target->DebugDump( "target" ); } return target; } //EM-Like algorithm (see "PatchMatch" - page 6) //Returns a float sized target image MaskedImageSP NearestNeighborField::ExpectationMaximization(NearestNeighborFieldSP nnf_TargetToSource, int level, int radius, QList& pyramid) { int iterEM = std::min(2 * level, 4); int iterNNF = std::min(5, 1 + level); MaskedImageSP source = nnf_TargetToSource->output; MaskedImageSP target = nnf_TargetToSource->input; MaskedImageSP newtarget = nullptr; //EM loop for (int emloop = 1; emloop <= iterEM; emloop++) { //set the new target as current target if (!newtarget.isNull()) { nnf_TargetToSource->input = newtarget; target = newtarget; newtarget = nullptr; } for (int x = 0; x < target->size().width(); ++x) { for (int y = 0; y < target->size().height(); ++y) { if (!source->containsMasked(x, y, radius)) { nnf_TargetToSource->field[x][y].x = x; nnf_TargetToSource->field[x][y].y = y; nnf_TargetToSource->field[x][y].distance = 0; } } } //minimize the NNF nnf_TargetToSource->minimize(iterNNF); - //DebugSaver::instance()->debugDumpField("T2S", nnf_TargetToSource->field); - //Now we rebuild the target using best patches from source MaskedImageSP newsource = nullptr; bool upscaled = false; // Instead of upsizing the final target, we build the last target from the next level source image // So the final target is less blurry (see "Space-Time Video Completion" - page 5) if (level >= 1 && (emloop == iterEM)) { newsource = pyramid.at(level - 1); QRect sz = newsource->size(); newtarget = target->copy(); newtarget->upscale(sz.width(), sz.height()); upscaled = true; } else { newsource = pyramid.at(level); newtarget = target->copy(); upscaled = false; } //EM Step //EM_Step(newsource, newtarget, radius, upscaled); ExpectationStep(nnf_TargetToSource, newsource, newtarget, upscaled); } - //DebugSaver::instance()->debugDumpField("T2S_Final", nnf_TargetToSource->field); return newtarget; } void NearestNeighborField::ExpectationStep(NearestNeighborFieldSP nnf, MaskedImageSP source, MaskedImageSP target, bool upscale) { //int*** field = nnf->field; int R = nnf->patchSize; if (upscale) R *= 2; int H_nnf = nnf->input->size().height(); int W_nnf = nnf->input->size().width(); int H_target = target->size().height(); int W_target = target->size().width(); int H_source = source->size().height(); int W_source = source->size().width(); std::vector< quint8* > pixels; std::vector< float > weights; pixels.reserve(R * R); weights.reserve(R * R); for (int x = 0 ; x < W_target ; ++x) { for (int y = 0 ; y < H_target; ++y) { float wsum = 0; pixels.clear(); weights.clear(); if (!source->containsMasked(x, y, R + 4) /*&& upscale*/) { //speedup computation by copying parts that are not masked. pixels.push_back(source->getImagePixel(x, y)); weights.push_back(1.f); target->mixColors(pixels, weights, 1.f, target->getImagePixel(x, y)); } else { for (int dx = -R ; dx <= R; ++dx) { for (int dy = -R ; dy <= R ; ++dy) { // xpt,ypt = center pixel of the target patch int xpt = x + dx; int ypt = y + dy; int xst, yst; float w; if (!upscale) { if (xpt < 0 || xpt >= W_nnf || ypt < 0 || ypt >= H_nnf) continue; xst = nnf->field[xpt][ypt].x; yst = nnf->field[xpt][ypt].y; float dp = nnf->field[xpt][ypt].distance; // similarity measure between the two patches w = nnf->similarity[dp]; } else { if (xpt < 0 || (xpt / 2) >= W_nnf || ypt < 0 || (ypt / 2) >= H_nnf) continue; xst = 2 * nnf->field[xpt / 2][ypt / 2].x + (xpt % 2); yst = 2 * nnf->field[xpt / 2][ypt / 2].y + (ypt % 2); float dp = nnf->field[xpt / 2][ypt / 2].distance; // similarity measure between the two patches w = nnf->similarity[dp]; } int xs = xst - dx; int ys = yst - dy; if (xs < 0 || xs >= W_source || ys < 0 || ys >= H_source) continue; if (source->isMasked(xs, ys)) continue; pixels.push_back(source->getImagePixel(xs, ys)); weights.push_back(w); wsum += w; } } if (wsum < 1) continue; target->mixColors(pixels, weights, wsum, target->getImagePixel(x, y)); } } } } -void patchImage(KisPaintDeviceSP imageDev, KisPaintDeviceSP maskDev, int radius) +void patchImage(KisPaintDeviceSP imageDev, KisPaintDeviceSP maskDev, int patchRadius, int accuracy) { - Inpaint inpaint(imageDev, maskDev, radius); + maskDev->setDefaultPixel( KoColor(Qt::white, maskDev->colorSpace())); + + QRect maskRect = maskDev->nonDefaultPixelArea(); + QRect imageRect = imageDev->exactBounds(); + + float scale = 1 + (accuracy / 25); //basically higher accuracy means we include more surrouding area around the patch + int dx = maskRect.width()*scale; + int dy = maskRect.height()*scale; + maskRect.adjust(-dx, -dy, dx, dy); + maskRect = maskRect.intersected(imageRect); + + KisPaintDeviceSP tempImageDev = new KisPaintDevice( imageDev->colorSpace() ); + KisPaintDeviceSP tempMaskDev = new KisPaintDevice( maskDev->colorSpace() ); + tempImageDev->makeCloneFrom( imageDev, maskRect ); + tempMaskDev->makeCloneFrom( maskDev, maskRect ); + + Inpaint inpaint(tempImageDev, tempMaskDev, patchRadius); MaskedImageSP output = inpaint.patch(); output->toPaintDevice( imageDev ); } diff --git a/plugins/tools/tool_smart_patch/kis_tool_smart_patch.cpp b/plugins/tools/tool_smart_patch/kis_tool_smart_patch.cpp index c77fac379a..232a5345b8 100644 --- a/plugins/tools/tool_smart_patch/kis_tool_smart_patch.cpp +++ b/plugins/tools/tool_smart_patch/kis_tool_smart_patch.cpp @@ -1,202 +1,210 @@ /* * Copyright (c) 2017 Eugene Ingerman * * 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 "kis_tool_smart_patch.h" #include #include #include #include #include #include #include #include "kis_canvas2.h" #include "kis_cursor.h" #include "kis_config.h" #include "kundo2magicstring.h" #include "KoProperties.h" #include "KoColorSpaceRegistry.h" #include "kis_node_manager.h" #include "kis_tool_smart_patch_options_widget.h" #include "libs/image/kis_paint_device_debug_utils.h" #include "kis_resources_snapshot.h" -void patchImage(KisPaintDeviceSP imageDev, KisPaintDeviceSP maskDev, int radius); +void patchImage(KisPaintDeviceSP imageDev, KisPaintDeviceSP maskDev, int radius, int accuracy); struct KisToolSmartPatch::Private { KisNodeSP maskNode = nullptr; KisNodeSP paintNode = nullptr; KisPaintDeviceSP imageDev = nullptr; KisPaintDeviceSP maskDev = nullptr; KisResourcesSnapshotSP resources = nullptr; KoColor currentFgColor; + KisToolSmartPatchOptionsWidget *optionsWidget = nullptr; }; KisToolSmartPatch::KisToolSmartPatch(KoCanvasBase * canvas) : KisToolFreehand(canvas, KisCursor::load("tool_freehand_cursor.png", 5, 5), kundo2_i18n("Smart Patch Stroke")), m_d(new Private) { setObjectName("tool_SmartPatch"); } KisToolSmartPatch::~KisToolSmartPatch() { + m_d->optionsWidget = nullptr; } void KisToolSmartPatch::activate(ToolActivation activation, const QSet &shapes) { KisToolFreehand::activate(activation, shapes); } void KisToolSmartPatch::deactivate() { KisToolFreehand::deactivate(); } void KisToolSmartPatch::resetCursorStyle() { KisToolFreehand::resetCursorStyle(); } bool KisToolSmartPatch::canCreateInpaintMask() const { KisNodeSP node = currentNode(); return node && node->inherits("KisLayer"); } +void KisToolSmartPatch::inpaintImage(KisPaintDeviceSP maskDev, KisPaintDeviceSP imageDev) +{ + int accuracy = 0; + int patchRadius = 2; + + + if( !m_d.isNull() && m_d->optionsWidget ){ + accuracy = m_d->optionsWidget->getAccuracy(); + patchRadius = m_d->optionsWidget->getPatchRadius(); + } + patchImage( imageDev, maskDev, patchRadius, accuracy ); + +} + void KisToolSmartPatch::activatePrimaryAction() { KisToolFreehand::activatePrimaryAction(); - -// if (!canCreateInpaintMask()) { -// QString message = i18n("Smart patch tool cannot paint on this layer. Please select a paint layer."); -// static_cast(canvas())->viewManager()->showFloatingMessage(message, koIcon("object-locked")); -// } } void KisToolSmartPatch::deactivatePrimaryAction() { KisToolFreehand::deactivatePrimaryAction(); } void KisToolSmartPatch::beginPrimaryAction(KoPointerEvent *event) { qDebug() << __FUNCTION__ << " 0"; KisNodeSP node = currentNode(); if (!node) return; KisCanvas2 * kiscanvas = static_cast(canvas()); KisViewManager* viewManager = kiscanvas->viewManager(); if (!m_d->maskNode.isNull()) { viewManager->nodeManager()->slotNonUiActivatedNode(m_d->maskNode); qDebug() << __FUNCTION__ << " 1"; } else { m_d->paintNode = viewManager->nodeManager()->activeNode(); m_d->imageDev = m_d->paintNode->paintDevice(); viewManager->nodeManager()->createNode("KisInpaintMask", true); m_d->maskNode = currentNode(); if ( ! m_d->maskNode.isNull() ){ m_d->maskNode->setProperty("visible", false); m_d->maskNode->setProperty("temporary", true); m_d->maskNode->setProperty("inpaintmask", true); } viewManager->nodeManager()->slotNonUiActivatedNode(m_d->maskNode); qDebug() << __FUNCTION__ << " 2"; KisToolFreehand::beginPrimaryAction(event); qDebug() << __FUNCTION__ << " 3"; m_d->currentFgColor = canvas()->resourceManager()->foregroundColor(); //resource(KoCanvasResourceManager::ForegroundColor).value(); canvas()->resourceManager()->setForegroundColor(KoColor(Qt::black, KoColorSpaceRegistry::instance()->alpha8())); //maybe we should use alpha color space here } } void KisToolSmartPatch::continuePrimaryAction(KoPointerEvent *event) { KisToolFreehand::continuePrimaryAction(event); } void KisToolSmartPatch::endPrimaryAction(KoPointerEvent *event) { qDebug() << __FUNCTION__ << " 0"; if( mode() != KisTool::PAINT_MODE ) return; KisToolFreehand::endPrimaryAction(event); qDebug() << __FUNCTION__ << " 1"; //Next line is important. We need to wait for the paint operation to finish otherwise //mask will be incomplete. image()->waitForDone(); m_d->maskDev = new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha8()); m_d->maskDev->makeCloneFrom(currentNode()->paintDevice(), currentNode()->paintDevice()->extent()); - patchImage( m_d->imageDev, m_d->maskDev, 4 ); + + inpaintImage( m_d->maskDev, m_d->imageDev ); + + KIS_DUMP_DEVICE_2(m_d->imageDev, m_d->imageDev->extent(), "patched", "/home/eugening/Projects/Out"); KIS_DUMP_DEVICE_2(m_d->maskDev, m_d->imageDev->extent(), "output", "/home/eugening/Projects/Out"); KisCanvas2 * kiscanvas = static_cast(canvas()); KisViewManager* viewManager = kiscanvas->viewManager(); if( ! m_d->maskNode.isNull() ) viewManager->nodeManager()->removeSingleNode(m_d->maskNode); if( ! m_d->paintNode.isNull() ) viewManager->nodeManager()->slotNonUiActivatedNode( m_d->paintNode ); m_d->paintNode = nullptr; m_d->maskNode = nullptr; canvas()->resourceManager()->setForegroundColor(m_d->currentFgColor); qDebug() << __FUNCTION__ << " 3"; } QWidget * KisToolSmartPatch::createOptionWidget() { KisCanvas2 * kiscanvas = dynamic_cast(canvas()); - QWidget *optionsWidget = new KisToolSmartPatchOptionsWidget(kiscanvas->viewManager()->resourceProvider(), 0); - optionsWidget->setObjectName(toolId() + "option widget"); - - // // See https://bugs.kde.org/show_bug.cgi?id=316896 - // QWidget *specialSpacer = new QWidget(optionsWidget); - // specialSpacer->setObjectName("SpecialSpacer"); - // specialSpacer->setFixedSize(0, 0); - // optionsWidget->layout()->addWidget(specialSpacer); + m_d->optionsWidget = new KisToolSmartPatchOptionsWidget(kiscanvas->viewManager()->resourceProvider(), 0); + m_d->optionsWidget->setObjectName(toolId() + "option widget"); - return optionsWidget; + return m_d->optionsWidget; } diff --git a/plugins/tools/tool_smart_patch/kis_tool_smart_patch.h b/plugins/tools/tool_smart_patch/kis_tool_smart_patch.h index 7cd081621b..1cc5386a02 100644 --- a/plugins/tools/tool_smart_patch/kis_tool_smart_patch.h +++ b/plugins/tools/tool_smart_patch/kis_tool_smart_patch.h @@ -1,99 +1,100 @@ /* * Copyright (c) 2017 Eugene Ingerman * * 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. */ #ifndef KIS_TOOL_SMART_PATCH_H_ #define KIS_TOOL_SMART_PATCH_H_ #include #include "kis_tool_freehand.h" #include "KoToolFactoryBase.h" #include #include #include #include #include #include class KActionCollection; class KoCanvasBase; class KisToolSmartPatch : public KisToolFreehand { Q_OBJECT public: KisToolSmartPatch(KoCanvasBase * canvas); virtual ~KisToolSmartPatch(); QWidget * createOptionWidget(); void activatePrimaryAction(); void deactivatePrimaryAction(); void beginPrimaryAction(KoPointerEvent *event); void continuePrimaryAction(KoPointerEvent *event); void endPrimaryAction(KoPointerEvent *event); protected Q_SLOTS: void resetCursorStyle(); public Q_SLOTS: virtual void activate(ToolActivation toolActivation, const QSet &shapes); void deactivate(); Q_SIGNALS: private: bool canCreateInpaintMask() const; + void inpaintImage( KisPaintDeviceSP maskDev, KisPaintDeviceSP imageDev ); private: struct Private; const QScopedPointer m_d; }; class KisToolSmartPatchFactory : public KoToolFactoryBase { public: KisToolSmartPatchFactory() : KoToolFactoryBase("KritaShape/KisToolSmartPatch") { setToolTip(i18n("Smart Patch Tool")); // Temporarily setSection(TOOL_TYPE_FILL); setIconName(koIconNameCStr("krita_tool_smart_patch")); //setShortcut(QKeySequence(Qt::Key_Shift + Qt::Key_B)); setPriority(4); setActivationShapeId(KRITA_TOOL_ACTIVATION_ID); } virtual ~KisToolSmartPatchFactory() {} virtual KoToolBase * createTool(KoCanvasBase *canvas) { return new KisToolSmartPatch(canvas); } }; #endif // KIS_TOOL_SMART_PATCH_H_ diff --git a/plugins/tools/tool_smart_patch/kis_tool_smart_patch_options_widget.cpp b/plugins/tools/tool_smart_patch/kis_tool_smart_patch_options_widget.cpp index ba78c29fb1..58a704585f 100644 --- a/plugins/tools/tool_smart_patch/kis_tool_smart_patch_options_widget.cpp +++ b/plugins/tools/tool_smart_patch/kis_tool_smart_patch_options_widget.cpp @@ -1,290 +1,68 @@ /* * Copyright (c) 2017 Eugene Ingerman * * 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 "kis_tool_smart_patch_options_widget.h" #include "ui_kis_tool_smart_patch_options_widget.h" #include #include "KisPaletteModel.h" #include "kis_config.h" #include #include "kis_canvas_resource_provider.h" -#include "kis_signal_auto_connection.h" -#include "lazybrush/kis_colorize_mask.h" -#include "kis_image.h" -#include "kis_signals_blocker.h" -#include "kis_signal_compressor.h" -#include "kis_layer_properties_icons.h" struct KisToolSmartPatchOptionsWidget::Private { Private() - : transparentColorIndex(-1), - baseNodeChangedCompressor(500, KisSignalCompressor::FIRST_ACTIVE) { } Ui_KisToolSmartPatchOptionsWidget *ui; - KisPaletteModel *colorModel; - KisCanvasResourceProvider *provider; - KisSignalAutoConnectionsStore providerSignals; - KisSignalAutoConnectionsStore maskSignals; - KisColorizeMaskSP activeMask; - - KoColorSet colorSet; - int transparentColorIndex = -1; - - KisSignalCompressor baseNodeChangedCompressor; + int getPatchRadius(void){ + return ui->patchRadius->value(); + } + int getAccuracy(void){ + return ui->accuracySlider->value(); + } }; KisToolSmartPatchOptionsWidget::KisToolSmartPatchOptionsWidget(KisCanvasResourceProvider *provider, QWidget *parent) : QWidget(parent), m_d(new Private) { m_d->ui = new Ui_KisToolSmartPatchOptionsWidget(); m_d->ui->setupUi(this); - m_d->colorModel = new KisPaletteModel(this); - m_d->ui->colorView->setPaletteModel(m_d->colorModel); - m_d->ui->colorView->setCrossedKeyword("transparent"); - - connect(m_d->ui->colorView, SIGNAL(clicked(QModelIndex)), this, SLOT(entrySelected(QModelIndex))); - connect(m_d->ui->btnTransparent, SIGNAL(toggled(bool)), this, SLOT(slotMakeTransparent(bool))); - connect(m_d->ui->btnRemove, SIGNAL(clicked()), this, SLOT(slotRemove())); - - connect(m_d->ui->chkAutoUpdates, SIGNAL(toggled(bool)), m_d->ui->btnUpdate, SLOT(setDisabled(bool))); - - connect(m_d->ui->btnUpdate, SIGNAL(clicked()), this, SLOT(slotUpdate())); - connect(m_d->ui->chkAutoUpdates, SIGNAL(toggled(bool)), this, SLOT(slotSetAutoUpdates(bool))); - connect(m_d->ui->chkShowKeyStrokes, SIGNAL(toggled(bool)), this, SLOT(slotSetShowKeyStrokes(bool))); - connect(m_d->ui->chkShowOutput, SIGNAL(toggled(bool)), this, SLOT(slotSetShowOutput(bool))); - - connect(&m_d->baseNodeChangedCompressor, SIGNAL(timeout()), this, SLOT(slotUpdateNodeProperties())); - - - m_d->provider = provider; - - const KoColorSpace *cs = KoColorSpaceRegistry::instance()->rgb8(); - - m_d->colorSet.add(KoColorSetEntry(KoColor(Qt::red, cs), "color1")); - m_d->colorSet.add(KoColorSetEntry(KoColor(Qt::green, cs), "color2")); - m_d->colorSet.add(KoColorSetEntry(KoColor(Qt::blue, cs), "color3")); - - m_d->colorModel->setColorSet(&m_d->colorSet); } KisToolSmartPatchOptionsWidget::~KisToolSmartPatchOptionsWidget() { } -void KisToolSmartPatchOptionsWidget::showEvent(QShowEvent *event) -{ - QWidget::showEvent(event); - - m_d->providerSignals.addConnection( - m_d->provider, SIGNAL(sigNodeChanged(KisNodeSP)), - this, SLOT(slotCurrentNodeChanged(KisNodeSP))); - - m_d->providerSignals.addConnection( - m_d->provider, SIGNAL(sigFGColorChanged(const KoColor&)), - this, SLOT(slotCurrentFgColorChanged(const KoColor&))); - - slotCurrentNodeChanged(m_d->provider->currentNode()); - slotCurrentFgColorChanged(m_d->provider->fgColor()); -} - -void KisToolSmartPatchOptionsWidget::hideEvent(QHideEvent *event) -{ - QWidget::hideEvent(event); - - m_d->providerSignals.clear(); -} - -void KisToolSmartPatchOptionsWidget::entrySelected(QModelIndex index) -{ - if (!index.isValid()) return; - - const int i = m_d->colorModel->idFromIndex(index); - - if (i >= 0 && i < m_d->colorSet.nColors()) { - KoColorSetEntry entry = m_d->colorSet.getColor(i); - m_d->provider->setFGColor(entry.color); - } - - const bool transparentChecked = i >= 0 && i == m_d->transparentColorIndex; - KisSignalsBlocker b(m_d->ui->btnTransparent); - m_d->ui->btnTransparent->setChecked(transparentChecked); -} - -void KisToolSmartPatchOptionsWidget::slotCurrentFgColorChanged(const KoColor &color) -{ - int selectedIndex = -1; - - for (int i = 0; i < m_d->colorSet.nColors(); i++) { - KoColorSetEntry entry = m_d->colorSet.getColor(i); - if (entry.color == color) { - selectedIndex = i; - break; - } - } - - m_d->ui->btnRemove->setEnabled(selectedIndex >= 0); - m_d->ui->btnTransparent->setEnabled(selectedIndex >= 0); - - if (selectedIndex < 0) { - KisSignalsBlocker b(m_d->ui->btnTransparent); - m_d->ui->btnTransparent->setChecked(false); - } - - QModelIndex newIndex = m_d->colorModel->indexFromId(selectedIndex); - - if (newIndex != m_d->ui->colorView->currentIndex()) { - m_d->ui->colorView->setCurrentIndex(newIndex); - } -} - -void KisToolSmartPatchOptionsWidget::slotColorLabelsChanged() -{ - m_d->colorSet.clear(); - m_d->transparentColorIndex = -1; - - if (m_d->activeMask) { - KisColorizeMask::KeyStrokeColors colors = m_d->activeMask->keyStrokesColors(); - m_d->transparentColorIndex = colors.transparentIndex; - - for (int i = 0; i < colors.colors.size(); i++) { - const QString name = i == m_d->transparentColorIndex ? "transparent" : ""; - m_d->colorSet.add(KoColorSetEntry(colors.colors[i], name)); - } - } - - m_d->colorModel->setColorSet(&m_d->colorSet); - slotCurrentFgColorChanged(m_d->provider->fgColor()); -} - -void KisToolSmartPatchOptionsWidget::slotUpdateNodeProperties() -{ - KisSignalsBlocker b(m_d->ui->chkAutoUpdates, - m_d->ui->btnUpdate, - m_d->ui->chkShowKeyStrokes, - m_d->ui->chkShowOutput); - - // not implemented yet! - //m_d->ui->chkAutoUpdates->setEnabled(m_d->activeMask); - m_d->ui->chkAutoUpdates->setEnabled(false); - - bool value = false; - - value = m_d->activeMask && !KisLayerPropertiesIcons::nodeProperty(m_d->activeMask, KisLayerPropertiesIcons::colorizeNeedsUpdate, true).toBool(); - m_d->ui->btnUpdate->setEnabled(m_d->activeMask && !m_d->ui->chkAutoUpdates->isChecked()); - m_d->ui->btnUpdate->setChecked(value); - - value = m_d->activeMask && KisLayerPropertiesIcons::nodeProperty(m_d->activeMask, KisLayerPropertiesIcons::colorizeEditKeyStrokes, true).toBool(); - m_d->ui->chkShowKeyStrokes->setEnabled(m_d->activeMask); - m_d->ui->chkShowKeyStrokes->setChecked(value); - - value = m_d->activeMask && KisLayerPropertiesIcons::nodeProperty(m_d->activeMask, KisLayerPropertiesIcons::colorizeShowColoring, true).toBool(); - m_d->ui->chkShowOutput->setEnabled(m_d->activeMask); - m_d->ui->chkShowOutput->setChecked(value); -} - -void KisToolSmartPatchOptionsWidget::slotCurrentNodeChanged(KisNodeSP node) -{ - m_d->maskSignals.clear(); - - KisColorizeMask *mask = dynamic_cast(node.data()); - m_d->activeMask = mask; - - if (m_d->activeMask) { - m_d->maskSignals.addConnection( - m_d->activeMask, SIGNAL(sigKeyStrokesListChanged()), - this, SLOT(slotColorLabelsChanged())); - - m_d->maskSignals.addConnection( - m_d->provider->currentImage(), SIGNAL(sigNodeChanged(KisNodeSP)), - this, SLOT(slotUpdateNodeProperties())); - } - - slotColorLabelsChanged(); - slotUpdateNodeProperties(); - m_d->ui->colorView->setEnabled(m_d->activeMask); -} - -void KisToolSmartPatchOptionsWidget::slotMakeTransparent(bool value) -{ - KIS_ASSERT_RECOVER_RETURN(m_d->activeMask); - - QModelIndex index = m_d->ui->colorView->currentIndex(); - if (!index.isValid()) return; - - const int activeIndex = m_d->colorModel->idFromIndex(index); - KIS_ASSERT_RECOVER_RETURN(activeIndex >= 0); - - KisColorizeMask::KeyStrokeColors colors; - - for (int i = 0; i < m_d->colorSet.nColors(); i++) { - colors.colors << m_d->colorSet.getColor(i).color; - } - - colors.transparentIndex = value ? activeIndex : -1; - - m_d->activeMask->setKeyStrokesColors(colors); -} - -void KisToolSmartPatchOptionsWidget::slotRemove() -{ - KIS_ASSERT_RECOVER_RETURN(m_d->activeMask); - - QModelIndex index = m_d->ui->colorView->currentIndex(); - if (!index.isValid()) return; - - const int activeIndex = m_d->colorModel->idFromIndex(index); - KIS_ASSERT_RECOVER_RETURN(activeIndex >= 0); - - - const KoColor color = m_d->colorSet.getColor(activeIndex).color; - m_d->activeMask->removeKeyStroke(color); -} - -void KisToolSmartPatchOptionsWidget::slotUpdate() -{ - KIS_SAFE_ASSERT_RECOVER_RETURN(m_d->activeMask); - KisLayerPropertiesIcons::setNodeProperty(m_d->activeMask, KisLayerPropertiesIcons::colorizeNeedsUpdate, false, m_d->provider->currentImage()); +int KisToolSmartPatchOptionsWidget::getPatchRadius(){ + return m_d->getPatchRadius(); } -void KisToolSmartPatchOptionsWidget::slotSetAutoUpdates(bool value) -{ - ENTER_FUNCTION() << ppVar(value); +int KisToolSmartPatchOptionsWidget::getAccuracy(){ + return m_d->getAccuracy(); } -void KisToolSmartPatchOptionsWidget::slotSetShowKeyStrokes(bool value) -{ - KIS_SAFE_ASSERT_RECOVER_RETURN(m_d->activeMask); - KisLayerPropertiesIcons::setNodeProperty(m_d->activeMask, KisLayerPropertiesIcons::colorizeEditKeyStrokes, value, m_d->provider->currentImage()); -} - -void KisToolSmartPatchOptionsWidget::slotSetShowOutput(bool value) -{ - KIS_SAFE_ASSERT_RECOVER_RETURN(m_d->activeMask); - KisLayerPropertiesIcons::setNodeProperty(m_d->activeMask, KisLayerPropertiesIcons::colorizeShowColoring, value, m_d->provider->currentImage()); -} diff --git a/plugins/tools/tool_smart_patch/kis_tool_smart_patch_options_widget.h b/plugins/tools/tool_smart_patch/kis_tool_smart_patch_options_widget.h index 3b3761d872..023895c951 100644 --- a/plugins/tools/tool_smart_patch/kis_tool_smart_patch_options_widget.h +++ b/plugins/tools/tool_smart_patch/kis_tool_smart_patch_options_widget.h @@ -1,64 +1,47 @@ /* * Copyright (c) 2017 Eugene Ingerman * * 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. */ #ifndef __KIS_TOOL_SMART_PATCH_OPTIONS_WIDGET_H #define __KIS_TOOL_SMART_PATCH_OPTIONS_WIDGET_H #include #include #include #include "kis_types.h" class KisCanvasResourceProvider; class KoColor; class KisToolSmartPatchOptionsWidget : public QWidget { Q_OBJECT public: KisToolSmartPatchOptionsWidget(KisCanvasResourceProvider *provider, QWidget *parent); ~KisToolSmartPatchOptionsWidget(); -private Q_SLOTS: - void entrySelected(QModelIndex index); - void slotCurrentFgColorChanged(const KoColor &color); - void slotCurrentNodeChanged(KisNodeSP node); - void slotColorLabelsChanged(); - - void slotMakeTransparent(bool value); - void slotRemove(); - - void slotUpdate(); - void slotSetAutoUpdates(bool value); - void slotSetShowKeyStrokes(bool value); - void slotSetShowOutput(bool value); - - void slotUpdateNodeProperties(); - -protected: - void showEvent(QShowEvent *event); - void hideEvent(QHideEvent *event); + int getPatchRadius( void ); + int getAccuracy( void ); private: struct Private; const QScopedPointer m_d; }; #endif /* __KIS_TOOL_SMART_PATCH_OPTIONS_WIDGET_H */ diff --git a/plugins/tools/tool_smart_patch/kis_tool_smart_patch_options_widget.ui b/plugins/tools/tool_smart_patch/kis_tool_smart_patch_options_widget.ui index 35e025744e..e1815ce9fa 100644 --- a/plugins/tools/tool_smart_patch/kis_tool_smart_patch_options_widget.ui +++ b/plugins/tools/tool_smart_patch/kis_tool_smart_patch_options_widget.ui @@ -1,143 +1,141 @@ KisToolSmartPatchOptionsWidget 0 0 - 233 - 264 + 340 + 235 - + 2 2 2 2 2 - - - - - Auto updates - - - - - - - Update - - - true - - - - - - - - - Edit key strokes - - - - - - - Show output - - - - - - - Qt::Vertical - - - QSizePolicy::Minimum - - + + - 20 - 10 + 200 + 200 - - - - - Key Strokes - - - true + Inpaint Tool - - - 0 + + + + 20 + 40 + 311 + 161 + - - 0 + + Qt::Vertical - - 0 - - - - - - 0 - 16 - - - - - - - - - - Transparent - - - true - - - + + + + 200 + 80 + + + + QFrame::StyledPanel + + + QFrame::Raised + + - - - Remove + + + Qt::Vertical + + + 25 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 25 + + + + + Qt::Horizontal + + + + Fast + + + + + Qt::LeftToRight + + + Accurate + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + - - + + + + Qt::Horizontal + + + + Patch Radius + + + label + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 1 + + + 6 + + + + - - - KisPaletteView - QTableView -
kis_palette_view.h
-
-