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

#include <KisRandomGenerator2D.h>

+ Inheritance diagram for KisRandomGenerator2D:

Public Member Functions

double doubleRandomAt (qint64 x, qint64 y)
 
 KisRandomGenerator2D (quint64 seed)
 
quint64 randomAt (qint64 x, qint64 y)
 
 ~KisRandomGenerator2D ()
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Public Attributes

quint64 seed
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Private Attributes

Private *const d
 

Detailed Description

This is a class that return a pseudo-random number that will be constant for a given pixel coordinate. The rational is that filters that use random number (such as noises, or raindrops) needs to always get the same random value at each run, or else the result will constantly changes when used as an adjustment layer.

Definition at line 34 of file KisRandomGenerator2D.cpp.

Constructor & Destructor Documentation

◆ KisRandomGenerator2D()

KisRandomGenerator2D::KisRandomGenerator2D ( quint64 seed)

Creates a new instance of a random generator with the given seed.

Definition at line 38 of file KisRandomGenerator2D.cpp.

38 : d(new Private)
39{
40 d->seed = seed;
41}

References d, and seed.

◆ ~KisRandomGenerator2D()

KisRandomGenerator2D::~KisRandomGenerator2D ( )

Definition at line 43 of file KisRandomGenerator2D.cpp.

44{
45 delete d;
46}

References d.

Member Function Documentation

◆ doubleRandomAt()

double KisRandomGenerator2D::doubleRandomAt ( qint64 x,
qint64 y )
Returns
the constant random value corresponding to a given pixel, the value is between 0 and 1.0

Definition at line 72 of file KisRandomGenerator2D.cpp.

73{
74 return randomAt(x, y) / (double)UINT64_MAX;
75}
quint64 randomAt(qint64 x, qint64 y)

References randomAt().

◆ randomAt()

quint64 KisRandomGenerator2D::randomAt ( qint64 x,
qint64 y )
Returns
the constant random value corresponding to a given pixel, the value is between 0 and RAND_MAX

Definition at line 48 of file KisRandomGenerator2D.cpp.

49{
50 const quint64 kxa = 427140578808118991LL;
51 const quint64 kya = 166552399647317237LL;
52 const quint64 kxb = 48058817213113801LL;
53 const quint64 kyb = 9206429469018994469LL;
54
55 // Generate salts
56 quint64 n1 = (quint64(x + 5) * kxa) * d->seed;
57 quint64 n2 = (quint64(y + 7) * kya) + (d->seed * 1040097393733LL);
58 n1 = permuteWhole(n1, 8759824322359LL, 13);
59 n2 = permuteWhole(n2, 200560490131LL, 2707);
60 n1 = (n1 >> 32) ^ (n1 << 32);
61 n2 = (n2 >> 32) ^ (n2 << 32);
62 n1 ^= x ^ (quint64(y ^ d->seed) * kyb);
63 n2 ^= y ^ (quint64(x + 13) * kxb);
64
65 // Combine salts
66 quint64 v = 0;
67 for (int p = 0; p < 8; ++p)
68 v |= part(n1, n2, p);
69 return v;
70}
const Params2D p
qreal v
quint64 part(quint64 n1, quint64 n2, int p)
quint64 permuteWhole(quint64 n, quint64 a, quint64 b)

References d, p, part(), permuteWhole(), and v.

Member Data Documentation

◆ d

Private* const KisRandomGenerator2D::d
private

Definition at line 43 of file KisRandomGenerator2D.h.

◆ seed

quint64 KisRandomGenerator2D::seed

Definition at line 35 of file KisRandomGenerator2D.cpp.


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