Krita Source Code Documentation
Loading...
Searching...
No Matches
KisConvolutionKernel Class Reference

#include <kis_convolution_kernel.h>

+ Inheritance diagram for KisConvolutionKernel:

Public Member Functions

Eigen::Matrix< qreal, Eigen::Dynamic, Eigen::Dynamic > & data ()
 
const Eigen::Matrix< qreal, Eigen::Dynamic, Eigen::Dynamic > * data () const
 
qreal factor () const
 
quint32 height () const
 
 KisConvolutionKernel (quint32 width, quint32 height, qreal offset, qreal factor)
 
qreal offset () const
 
void setFactor (qreal)
 
void setSize (quint32 width, quint32 height)
 
quint32 width () const
 
virtual ~KisConvolutionKernel ()
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 
- Public Member Functions inherited from KisShared
bool deref ()
 
bool ref ()
 
int refCount ()
 
QAtomicInt * sharedWeakReference ()
 

Static Public Member Functions

static KisConvolutionKernelSP fromMaskGenerator (KisMaskGenerator *, qreal angle=0.0)
 
static KisConvolutionKernelSP fromMatrix (Eigen::Matrix< qreal, Eigen::Dynamic, Eigen::Dynamic > matrix, qreal offset, qreal factor)
 
static KisConvolutionKernelSP fromQImage (const QImage &image)
 

Public Attributes

Eigen::Matrix< qreal, Eigen::Dynamic, Eigen::Dynamic > data
 
qreal factor
 
qreal offset
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Private Attributes

Private *const d
 

Additional Inherited Members

- Protected Member Functions inherited from KisShared
 KisShared ()
 
 ~KisShared ()
 

Detailed Description

Definition at line 14 of file kis_convolution_kernel.cc.

Constructor & Destructor Documentation

◆ KisConvolutionKernel()

KisConvolutionKernel::KisConvolutionKernel ( quint32 width,
quint32 height,
qreal offset,
qreal factor )

Definition at line 20 of file kis_convolution_kernel.cc.

20 : d(new Private)
21{
22 d->offset = _offset;
23 d->factor = _factor;
24 setSize(_width, _height);
25}
void setSize(quint32 width, quint32 height)

References d, and setSize().

◆ ~KisConvolutionKernel()

KisConvolutionKernel::~KisConvolutionKernel ( )
virtual

Definition at line 27 of file kis_convolution_kernel.cc.

28{
29 delete d;
30}

References d.

Member Function Documentation

◆ data() [1/2]

Eigen::Matrix< qreal, Eigen::Dynamic, Eigen::Dynamic > & KisConvolutionKernel::data ( )

◆ data() [2/2]

const Eigen::Matrix< qreal, Eigen::Dynamic, Eigen::Dynamic > * KisConvolutionKernel::data ( ) const

◆ factor()

qreal KisConvolutionKernel::factor ( ) const

◆ fromMaskGenerator()

KisConvolutionKernelSP KisConvolutionKernel::fromMaskGenerator ( KisMaskGenerator * kmg,
qreal angle = 0.0 )
static

Definition at line 94 of file kis_convolution_kernel.cc.

95{
96 Q_UNUSED(angle);
97
98 qint32 width = (int)(kmg->width() + 0.5);
99 qint32 height = (int)(kmg->height() + 0.5);
100
102
103 qreal cosa = cos(angle);
104 qreal sina = sin(angle);
105 qreal xc = 0.5 * width - 0.5;
106 qreal yc = 0.5 * height - 0.5;
107
108 Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic>& data = kernel->data();
109 qreal factor = 0;
110
111// dbgImage << ppVar(xc) << ppVar(yc);
112 for (int r = 0; r < height; ++r) {
113 for (int c = 0; c < width; ++c) {
114 qreal x_ = (c - xc);
115 qreal y_ = (r - yc);
116 qreal x = cosa * x_ - sina * y_;
117 qreal y = sina * x_ + cosa * y_;
118// dbgImage << ppVar(x) << ppVar(y) << ppVar(x_) << ppVar(y_) << ppVar( kmg->interpolatedValueAt( x,y) );
119 uint value = 255 - kmg->valueAt(x, y);
120 data(r, c) = value;
121 factor += value;
122 }
123 }
124 kernel->setFactor(factor);
125 return kernel;
126}
float value(const T *src, size_t ch)
unsigned int uint
virtual quint8 valueAt(qreal x, qreal y) const =0
KisConvolutionKernel(quint32 width, quint32 height, qreal offset, qreal factor)
Eigen::Matrix< qreal, Eigen::Dynamic, Eigen::Dynamic > data

References data, factor, KisMaskGenerator::height(), height(), KisConvolutionKernel(), setFactor(), value(), KisMaskGenerator::valueAt(), KisMaskGenerator::width(), and width().

◆ fromMatrix()

KisConvolutionKernelSP KisConvolutionKernel::fromMatrix ( Eigen::Matrix< qreal, Eigen::Dynamic, Eigen::Dynamic > matrix,
qreal offset,
qreal factor )
static

Definition at line 128 of file kis_convolution_kernel.cc.

129{
130 KisConvolutionKernelSP kernel = new KisConvolutionKernel(matrix.cols(), matrix.rows(), offset, factor);
131 kernel->data() = matrix;
132
133 return kernel;
134}

References data, factor, KisConvolutionKernel(), and offset.

◆ fromQImage()

KisConvolutionKernelSP KisConvolutionKernel::fromQImage ( const QImage & image)
static

Definition at line 73 of file kis_convolution_kernel.cc.

74{
75 KisConvolutionKernelSP kernel = new KisConvolutionKernel(image.width(), image.height(), 0, 0);
76
77 Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic>& data = kernel->data();
78 const quint8* itImage = image.constBits();
79 qreal factor = 0;
80
81 for (int r = 0; r < image.height(); r++) {
82 for (int c = 0; c < image.width(); c++, itImage += 4)
83 {
84 uint value = 255 - (*itImage + *(itImage + 1) + *(itImage + 2)) / 3;
85 data(r, c) = value;
86 factor += value;
87 }
88 }
89
90 kernel->setFactor(factor);
91 return kernel;
92}

References data, factor, KisConvolutionKernel(), setFactor(), and value().

◆ height()

quint32 KisConvolutionKernel::height ( ) const

Definition at line 37 of file kis_convolution_kernel.cc.

38{
39 return d->data.rows();
40}

References d.

◆ offset()

qreal KisConvolutionKernel::offset ( ) const

◆ setFactor()

void KisConvolutionKernel::setFactor ( qreal factor)

Definition at line 58 of file kis_convolution_kernel.cc.

59{
60 d->factor = factor;
61}

References d, and factor.

◆ setSize()

void KisConvolutionKernel::setSize ( quint32 width,
quint32 height )

Change the size of a kernel, it won't reallocate, and therefore it must keep the same kernel size ( oldwidth * oldheight = newwidth*newheight)

Definition at line 42 of file kis_convolution_kernel.cc.

43{
44 d->data.resize(height, width);
45}

References d, height(), and width().

◆ width()

quint32 KisConvolutionKernel::width ( ) const

Definition at line 32 of file kis_convolution_kernel.cc.

33{
34 return d->data.cols();
35}

References d.

Member Data Documentation

◆ d

Private* const KisConvolutionKernel::d
private

Definition at line 43 of file kis_convolution_kernel.h.

◆ data

const Eigen::Matrix< qreal, Eigen::Dynamic, Eigen::Dynamic > * KisConvolutionKernel::data

Definition at line 17 of file kis_convolution_kernel.cc.

◆ factor

qreal KisConvolutionKernel::factor

Definition at line 16 of file kis_convolution_kernel.cc.

◆ offset

qreal KisConvolutionKernel::offset

Definition at line 15 of file kis_convolution_kernel.cc.


The documentation for this class was generated from the following files: