Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_inpaint.cpp File Reference
#include <boost/multi_array.hpp>
#include <random>
#include <iostream>
#include <functional>
#include "kis_paint_device.h"
#include "kis_painter.h"
#include "kis_selection.h"
#include "kis_debug.h"
#include "kis_paint_device_debug_utils.h"
#include <QtMath>
#include <QList>
#include <kis_transform_worker.h>
#include <kis_filter_strategy.h>
#include "KoColor.h"
#include "KoColorSpace.h"
#include "KoChannelInfo.h"
#include "KoMixColorsOp.h"
#include "KoColorModelStandardIds.h"
#include "KoColorSpaceRegistry.h"
#include "KoColorSpaceTraits.h"

Go to the source code of this file.

Classes

class  ImageData
 
class  ImageView
 
class  Inpaint
 
class  MaskedImage
 
class  NearestNeighborField
 
struct  NNPixel
 
struct  Vote_elem
 

Typedefs

typedef KisSharedPtr< MaskedImageMaskedImageSP
 
typedef KisSharedPtr< NearestNeighborFieldNearestNeighborFieldSP
 
typedef boost::multi_array< NNPixel, 2 > NNArray_type
 
typedef boost::multi_array< Vote_elem, 2 > Vote_type
 

Functions

template<typename T >
float distance_impl (const MaskedImage &my, int x, int y, const MaskedImage &other, int xo, int yo)
 
QRect getMaskBoundingBox (KisPaintDeviceSP maskDev)
 
QRect patchImage (const KisPaintDeviceSP imageDev, const KisPaintDeviceSP maskDev, int patchRadius, int accuracy, KisSelectionSP selection)
 

Variables

const quint8 MASK_CLEAR = 0
 
const quint8 MASK_SET = 255
 
const int MAX_DIST = 65535
 

Typedef Documentation

◆ MaskedImageSP

Definition at line 499 of file kis_inpaint.cpp.

◆ NearestNeighborFieldSP

◆ NNArray_type

typedef boost::multi_array<NNPixel, 2> NNArray_type

Definition at line 506 of file kis_inpaint.cpp.

◆ Vote_type

typedef boost::multi_array<Vote_elem, 2> Vote_type

Definition at line 512 of file kis_inpaint.cpp.

Function Documentation

◆ distance_impl()

template<typename T >
float distance_impl ( const MaskedImage & my,
int x,
int y,
const MaskedImage & other,
int xo,
int yo )

Definition at line 481 of file kis_inpaint.cpp.

482{
483 float dsq = 0;
484 quint32 nchannels = my.channelCount();
485 T *v1 = reinterpret_cast<T*>(my.imageData(x, y));
486 T *v2 = reinterpret_cast<T*>(other.imageData(xo, yo));
487
488 for (quint32 chan = 0; chan < nchannels; chan++) {
489 //It's very important not to lose precision in the next line
490 float v = ((float)(*(v1 + chan)) - (float)(*(v2 + chan)));
491 dsq += v * v;
492 }
493
494 // in HDR color spaces the value of the channel may become bigger than the unitValue
495 return qMin((float)(nchannels * MAX_DIST), dsq / (pow2((float)KoColorSpaceMathsTraits<T>::unitValue) / MAX_DIST ));
496}
qreal v
int channelCount(void) const
ImageData imageData
T pow2(const T &x)
Definition kis_global.h:166
const int MAX_DIST

◆ getMaskBoundingBox()

QRect getMaskBoundingBox ( KisPaintDeviceSP maskDev)

Definition at line 972 of file kis_inpaint.cpp.

973{
974 QRect maskRect = maskDev->nonDefaultPixelArea();
975 return maskRect;
976}
QRect nonDefaultPixelArea() const

References KisPaintDevice::nonDefaultPixelArea().

◆ patchImage()

QRect patchImage ( const KisPaintDeviceSP imageDev,
const KisPaintDeviceSP maskDev,
int patchRadius,
int accuracy,
KisSelectionSP selection )

Definition at line 979 of file kis_inpaint.cpp.

980{
981 QRect maskRect = getMaskBoundingBox(maskDev);
982 QRect imageRect = imageDev->exactBounds();
983
984 float scale = 1.0 + (accuracy / 25.0); //higher accuracy means we include more surrounding area around the patch. Minimum 2x padding.
985 int dx = maskRect.width() * scale;
986 int dy = maskRect.height() * scale;
987 maskRect.adjust(-dx, -dy, dx, dy);
988 maskRect = maskRect.intersected(imageRect);
989
990 if (!maskRect.isEmpty()) {
991 Inpaint inpaint(imageDev, maskDev, patchRadius, maskRect);
992 MaskedImageSP output = inpaint.patch();
993 output->toPaintDevice(imageDev, maskRect, selection);
994 }
995
996 return maskRect;
997}
QRect exactBounds() const
void toPaintDevice(KisPaintDeviceSP imageDev, QRect rect, KisSelectionSP selection)
QRect getMaskBoundingBox(KisPaintDeviceSP maskDev)

References KisPaintDevice::exactBounds(), getMaskBoundingBox(), Inpaint::patch(), and MaskedImage::toPaintDevice().

Variable Documentation

◆ MASK_CLEAR

const quint8 MASK_CLEAR = 0

Definition at line 46 of file kis_inpaint.cpp.

◆ MASK_SET

const quint8 MASK_SET = 255

Definition at line 45 of file kis_inpaint.cpp.

◆ MAX_DIST

const int MAX_DIST = 65535

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

Definition at line 44 of file kis_inpaint.cpp.