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

#include <kis_math_toolbox.h>

Classes

struct  KisFloatRepresentation
 

Public Types

typedef KisFloatRepresentation KisWavelet
 

Public Member Functions

uint fastWaveletTotalSteps (const QRect &)
 
KisWaveletfastWaveletTransformation (KisPaintDeviceSP src, const QRect &, KisWavelet *buff=0)
 
void fastWaveletUntransformation (KisPaintDeviceSP dst, const QRect &, KisWavelet *wav, KisWavelet *buff=0)
 
bool getFromDoubleChannelPtr (QList< KoChannelInfo * > cis, QVector< PtrFromDouble > &f)
 
bool getFromDoubleCheckNullChannelPtr (QList< KoChannelInfo * > cis, QVector< PtrFromDoubleCheckNull > &f)
 
bool getToDoubleChannelPtr (QList< KoChannelInfo * > cis, QVector< PtrToDouble > &f)
 
KisWaveletinitWavelet (KisPaintDeviceSP lay, const QRect &)
 
double maxChannelValue (KoChannelInfo *)
 
double minChannelValue (KoChannelInfo *)
 

Private Member Functions

void transformFromFR (KisPaintDeviceSP dst, KisFloatRepresentation *, const QRect &)
 
void transformToFR (KisPaintDeviceSP src, KisFloatRepresentation *, const QRect &)
 
void wavetrans (KisWavelet *wav, KisWavelet *buff, uint halfsize)
 
void waveuntrans (KisWavelet *wav, KisWavelet *buff, uint halfsize)
 

Detailed Description

Definition at line 34 of file kis_math_toolbox.h.

Member Typedef Documentation

◆ KisWavelet

Member Function Documentation

◆ fastWaveletTotalSteps()

uint KisMathToolbox::fastWaveletTotalSteps ( const QRect & rect)
inline

Definition at line 129 of file kis_math_toolbox.h.

130{
131 int size, steps;
132 int maxrectsize = (rect.height() < rect.width()) ? rect.width() : rect.height();
133 steps = 0;
134 for (size = 2; size < maxrectsize; size *= 2) steps += size / 2; ;
135 return steps;
136}
int size(const Forest< T > &forest)
Definition KisForest.h:1232

◆ fastWaveletTransformation()

KisMathToolbox::KisWavelet * KisMathToolbox::fastWaveletTransformation ( KisPaintDeviceSP src,
const QRect & rect,
KisWavelet * buff = 0 )

This function reconstruct the layer from the information of a wavelet

Parameters
srclayer from which the wavelet will be computed
rectthe rectangular for reconstruction
buffif set to 0, the buffer will be initialized by the function, you might want to give a buff to the function if you want to use the same buffer in transformToWavelet and in untransformToWavelet, use initWavelet to initialize the buffer

Definition at line 328 of file kis_math_toolbox.cpp.

329{
330 if (buff == 0) {
331 buff = initWavelet(src, rect);
332 }
333 KisWavelet* wav = initWavelet(src, rect);
334 transformToFR(src, wav, rect);
335 wavetrans(wav, buff, wav->size / 2);
336
337 return wav;
338}
void transformToFR(KisPaintDeviceSP src, KisFloatRepresentation *, const QRect &)
void wavetrans(KisWavelet *wav, KisWavelet *buff, uint halfsize)
KisWavelet * initWavelet(KisPaintDeviceSP lay, const QRect &)
KisFloatRepresentation KisWavelet

References initWavelet(), KisMathToolbox::KisFloatRepresentation::size, transformToFR(), and wavetrans().

◆ fastWaveletUntransformation()

void KisMathToolbox::fastWaveletUntransformation ( KisPaintDeviceSP dst,
const QRect & rect,
KisWavelet * wav,
KisWavelet * buff = 0 )

This function reconstruct the layer from the information of a wavelet

Parameters
dstlayer on which the wavelet will be untransform
rectthe rectangular for reconstruction
wavthe wavelet
buffif set to 0, the buffer will be initialized by the function, you might want to give a buff to the function if you want to use the same buffer in transformToWavelet and in untransformToWavelet, use initWavelet to initialize the buffer

Definition at line 340 of file kis_math_toolbox.cpp.

341{
342 if (buff == 0) {
343 buff = initWavelet(dst, rect);
344 }
345
346 waveuntrans(wav, buff, 1);
347 transformFromFR(dst, wav, rect);
348}
void waveuntrans(KisWavelet *wav, KisWavelet *buff, uint halfsize)
void transformFromFR(KisPaintDeviceSP dst, KisFloatRepresentation *, const QRect &)

References initWavelet(), transformFromFR(), and waveuntrans().

◆ getFromDoubleChannelPtr()

bool KisMathToolbox::getFromDoubleChannelPtr ( QList< KoChannelInfo * > cis,
QVector< PtrFromDouble > & f )

Definition at line 153 of file kis_math_toolbox.cpp.

154{
155 qint32 channels = cis.count();
156
157 for (qint32 k = 0; k < channels; k++) {
158 switch (cis[k]->channelValueType()) {
160 f[k] = fromDouble<quint8>;
161 break;
163 f[k] = fromDouble<quint16>;
164 break;
165#ifdef HAVE_OPENEXR
167 f[k] = fromDoubleF<half>;
168 break;
169#endif
171 f[k] = fromDoubleF<float>;
172 break;
174 f[k] = fromDouble<qint8>;
175 break;
177 f[k] = fromDouble<qint16>;
178 break;
179 default:
180 warnKrita << "Unsupported value type in KisMathToolbox";
181 return false;
182 }
183 }
184
185 return true;
186}
@ UINT8
use this for an unsigned integer 8bits channel
@ UINT16
use this for an integer 16bits channel
@ INT16
use this for an integer 16bits channel
@ INT8
use this for an integer 8bits channel
@ FLOAT32
use this for a float 32bits channel
@ FLOAT16
use this for a float 16bits channel
#define warnKrita
Definition kis_debug.h:87

References KoChannelInfo::FLOAT16, KoChannelInfo::FLOAT32, KoChannelInfo::INT16, KoChannelInfo::INT8, KoChannelInfo::UINT16, KoChannelInfo::UINT8, and warnKrita.

◆ getFromDoubleCheckNullChannelPtr()

bool KisMathToolbox::getFromDoubleCheckNullChannelPtr ( QList< KoChannelInfo * > cis,
QVector< PtrFromDoubleCheckNull > & f )

Definition at line 188 of file kis_math_toolbox.cpp.

189{
190 qint32 channels = cis.count();
191
192 for (qint32 k = 0; k < channels; k++) {
193 switch (cis[k]->channelValueType()) {
195 f[k] = fromDoubleCheckNull<quint8>;
196 break;
198 f[k] = fromDoubleCheckNull<quint16>;
199 break;
200#ifdef HAVE_OPENEXR
202 f[k] = fromDoubleCheckNullF<half>;
203 break;
204#endif
206 f[k] = fromDoubleCheckNullF<float>;
207 break;
209 f[k] = fromDoubleCheckNull<qint8>;
210 break;
212 f[k] = fromDoubleCheckNull<qint16>;
213 break;
214 default:
215 warnKrita << "Unsupported value type in KisMathToolbox";
216 return false;
217 }
218 }
219
220 return true;
221}

References KoChannelInfo::FLOAT16, KoChannelInfo::FLOAT32, KoChannelInfo::INT16, KoChannelInfo::INT8, KoChannelInfo::UINT16, KoChannelInfo::UINT8, and warnKrita.

◆ getToDoubleChannelPtr()

bool KisMathToolbox::getToDoubleChannelPtr ( QList< KoChannelInfo * > cis,
QVector< PtrToDouble > & f )

Definition at line 90 of file kis_math_toolbox.cpp.

91{
92 qint32 channels = cis.count();
93
94 for (qint32 k = 0; k < channels; k++) {
95 switch (cis[k]->channelValueType()) {
97 f[k] = toDouble<quint8>;
98 break;
100 f[k] = toDouble<quint16>;
101 break;
102#ifdef HAVE_OPENEXR
104 f[k] = toDouble<half>;
105 break;
106#endif
108 f[k] = toDouble<float>;
109 break;
111 f[k] = toDouble<qint8>;
112 break;
114 f[k] = toDouble<qint16>;
115 break;
116 default:
117 warnKrita << "Unsupported value type in KisMathToolbox";
118 return false;
119 }
120 }
121
122 return true;
123}

References KoChannelInfo::FLOAT16, KoChannelInfo::FLOAT32, KoChannelInfo::INT16, KoChannelInfo::INT8, KoChannelInfo::UINT16, KoChannelInfo::UINT8, and warnKrita.

◆ initWavelet()

KisMathToolbox::KisWavelet * KisMathToolbox::initWavelet ( KisPaintDeviceSP lay,
const QRect & rect )
inline

This function initializes a wavelet structure

Parameters
laythe layer that will be used for the transformation
rectthe rectangular for transformation

Definition at line 120 of file kis_math_toolbox.h.

121{
122 int size;
123 int maxrectsize = (rect.height() < rect.width()) ? rect.width() : rect.height();
124 for (size = 2; size < maxrectsize; size *= 2) ;
125 qint32 depth = src->colorSpace()->colorChannelCount();
126 return new KisWavelet(size, depth);
127}
int depth(typename Forest< T >::const_child_iterator beginIt, typename Forest< T >::const_child_iterator endIt)
Definition KisForest.h:1213

◆ maxChannelValue()

double KisMathToolbox::maxChannelValue ( KoChannelInfo * c)

◆ minChannelValue()

◆ transformFromFR()

void KisMathToolbox::transformFromFR ( KisPaintDeviceSP dst,
KisFloatRepresentation * fr,
const QRect & rect )
private

This function transform a KisFloatRepresentation into a paint device, this function is colorspace independent, for Wavelet, Pyramid and FFT the data is always the exact value of the channel stored in a float.

Definition at line 125 of file kis_math_toolbox.cpp.

126{
127 qint32 depth = dst->colorSpace()->colorChannelCount();
129 // remove non-color channels
130 for (qint32 c = 0; c < cis.count(); ++c) {
131 if (cis[c]->channelType() != KoChannelInfo::COLOR)
132 cis.removeAt(c--);
133 }
134
136 if (!getFromDoubleChannelPtr(cis, f))
137 return;
138
139 KisHLineIteratorSP dstIt = dst->createHLineIteratorNG(rect.x(), rect.y(), rect.width());
140 for (int i = rect.y(); i < rect.height(); i++) {
141 float *srcIt = fr->coeffs + (i - rect.y()) * fr->size * fr->depth;
142 do {
143 quint8* v1 = dstIt->rawData();
144 for (int k = 0; k < depth; k++) {
145 f[k](v1, cis[k]->pos(), *srcIt);
146 ++srcIt;
147 }
148 } while(dstIt->nextPixel());
149 dstIt->nextRow();
150 }
151}
bool getFromDoubleChannelPtr(QList< KoChannelInfo * > cis, QVector< PtrFromDouble > &f)
KisHLineIteratorSP createHLineIteratorNG(qint32 x, qint32 y, qint32 w)
const KoColorSpace * colorSpace() const
@ COLOR
The channel represents a color.
QList< KoChannelInfo * > channels
virtual quint32 colorChannelCount() const =0

References KoColorSpace::channels, KisMathToolbox::KisFloatRepresentation::coeffs, KoChannelInfo::COLOR, KoColorSpace::colorChannelCount(), KisPaintDevice::colorSpace(), KisPaintDevice::createHLineIteratorNG(), KisMathToolbox::KisFloatRepresentation::depth, getFromDoubleChannelPtr(), and KisMathToolbox::KisFloatRepresentation::size.

◆ transformToFR()

void KisMathToolbox::transformToFR ( KisPaintDeviceSP src,
KisFloatRepresentation * fr,
const QRect & rect )
private

This function transform a paint device into a KisFloatRepresentation, this function is colorspace independent, for Wavelet, Pyramid and FFT the data is always the exact value of the channel stored in a float.

Definition at line 62 of file kis_math_toolbox.cpp.

63{
64 qint32 depth = src->colorSpace()->colorChannelCount();
65 QList<KoChannelInfo *> cis = src->colorSpace()->channels();
66 // remove non-color channels
67 for (qint32 c = 0; c < cis.count(); ++c) {
68 if (cis[c]->channelType() != KoChannelInfo::COLOR)
69 cis.removeAt(c--);
70 }
72 if (!getToDoubleChannelPtr(cis, f))
73 return;
74
75 KisHLineConstIteratorSP srcIt = src->createHLineIteratorNG(rect.x(), rect.y(), rect.width());
76
77 for (int i = rect.y(); i < rect.height(); i++) {
78 float *dstIt = fr->coeffs + (i - rect.y()) * fr->size * fr->depth;
79 do {
80 const quint8* v1 = srcIt->oldRawData();
81 for (int k = 0; k < depth; k++) {
82 *dstIt = f[k](v1, cis[k]->pos());
83 ++dstIt;
84 }
85 } while (srcIt->nextPixel());
86 srcIt->nextRow();
87 }
88}
virtual const quint8 * oldRawData() const =0
virtual bool nextPixel()=0
virtual void nextRow()=0
bool getToDoubleChannelPtr(QList< KoChannelInfo * > cis, QVector< PtrToDouble > &f)

References KisMathToolbox::KisFloatRepresentation::coeffs, KoChannelInfo::COLOR, KisMathToolbox::KisFloatRepresentation::depth, getToDoubleChannelPtr(), KisBaseConstIteratorNG::nextPixel(), KisHLineConstIteratorNG::nextRow(), KisBaseConstAccessor::oldRawData(), and KisMathToolbox::KisFloatRepresentation::size.

◆ wavetrans()

void KisMathToolbox::wavetrans ( KisMathToolbox::KisWavelet * wav,
KisMathToolbox::KisWavelet * buff,
uint halfsize )
private

Definition at line 259 of file kis_math_toolbox.cpp.

260{
261 uint l = (2 * halfsize) * wav->depth * sizeof(float);
262 for (uint i = 0; i < halfsize; i++) {
263 float * itLL = buff->coeffs + i * buff->size * buff->depth;
264 float * itHL = buff->coeffs + (i * buff->size + halfsize) * buff->depth;
265 float * itLH = buff->coeffs + (halfsize + i) * buff->size * buff->depth;
266 float * itHH = buff->coeffs + ((halfsize + i) * buff->size + halfsize) * buff->depth;
267 float * itS11 = wav->coeffs + 2 * i * wav->size * wav->depth;
268 float * itS12 = wav->coeffs + (2 * i * wav->size + 1) * wav->depth;
269 float * itS21 = wav->coeffs + (2 * i + 1) * wav->size * wav->depth;
270 float * itS22 = wav->coeffs + ((2 * i + 1) * wav->size + 1) * wav->depth;
271 for (uint j = 0; j < halfsize; j++) {
272 for (uint k = 0; k < wav->depth; k++) {
273 *(itLL++) = (*itS11 + *itS12 + *itS21 + *itS22) * M_SQRT1_2;
274 *(itHL++) = (*itS11 - *itS12 + *itS21 - *itS22) * M_SQRT1_2;
275 *(itLH++) = (*itS11 + *itS12 - *itS21 - *itS22) * M_SQRT1_2;
276 *(itHH++) = (*(itS11++) - *(itS12++) - *(itS21++) + *(itS22++)) * M_SQRT1_2;
277 }
278 itS11 += wav->depth; itS12 += wav->depth;
279 itS21 += wav->depth; itS22 += wav->depth;
280 }
281 }
282 for (uint i = 0; i < halfsize; i++) {
283 uint p = i * wav->size * wav->depth;
284 memcpy(wav->coeffs + p, buff->coeffs + p, l);
285 p = (i + halfsize) * wav->size * wav->depth;
286 memcpy(wav->coeffs + p, buff->coeffs + p, l);
287 }
288 if (halfsize != 1) {
289 wavetrans(wav, buff, halfsize / 2);
290 }
291}
const Params2D p
unsigned int uint

References KisMathToolbox::KisFloatRepresentation::coeffs, KisMathToolbox::KisFloatRepresentation::depth, p, KisMathToolbox::KisFloatRepresentation::size, and wavetrans().

◆ waveuntrans()

void KisMathToolbox::waveuntrans ( KisMathToolbox::KisWavelet * wav,
KisMathToolbox::KisWavelet * buff,
uint halfsize )
private

Definition at line 293 of file kis_math_toolbox.cpp.

294{
295 uint l = (2 * halfsize) * wav->depth * sizeof(float);
296 for (uint i = 0; i < halfsize; i++) {
297 float * itLL = wav->coeffs + i * buff->size * buff->depth;
298 float * itHL = wav->coeffs + (i * buff->size + halfsize) * buff->depth;
299 float * itLH = wav->coeffs + (halfsize + i) * buff->size * buff->depth;
300 float * itHH = wav->coeffs + ((halfsize + i) * buff->size + halfsize) * buff->depth;
301 float * itS11 = buff->coeffs + 2 * i * wav->size * wav->depth;
302 float * itS12 = buff->coeffs + (2 * i * wav->size + 1) * wav->depth;
303 float * itS21 = buff->coeffs + (2 * i + 1) * wav->size * wav->depth;
304 float * itS22 = buff->coeffs + ((2 * i + 1) * wav->size + 1) * wav->depth;
305 for (uint j = 0; j < halfsize; j++) {
306 for (uint k = 0; k < wav->depth; k++) {
307 *(itS11++) = (*itLL + *itHL + *itLH + *itHH) * 0.25 * M_SQRT2;
308 *(itS12++) = (*itLL - *itHL + *itLH - *itHH) * 0.25 * M_SQRT2;
309 *(itS21++) = (*itLL + *itHL - *itLH - *itHH) * 0.25 * M_SQRT2;
310 *(itS22++) = (*(itLL++) - *(itHL++) - *(itLH++) + *(itHH++)) * 0.25 * M_SQRT2;
311 }
312 itS11 += wav->depth; itS12 += wav->depth;
313 itS21 += wav->depth; itS22 += wav->depth;
314 }
315 }
316 for (uint i = 0; i < halfsize; i++) {
317 uint p = i * wav->size * wav->depth;
318 memcpy(wav->coeffs + p, buff->coeffs + p, l);
319 p = (i + halfsize) * wav->size * wav->depth;
320 memcpy(wav->coeffs + p, buff->coeffs + p, l);
321 }
322
323 if (halfsize != wav->size / 2) {
324 waveuntrans(wav, buff, halfsize*2);
325 }
326}

References KisMathToolbox::KisFloatRepresentation::coeffs, KisMathToolbox::KisFloatRepresentation::depth, p, KisMathToolbox::KisFloatRepresentation::size, and waveuntrans().


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