File indexing completed on 2024-05-12 15:58:39

0001 /*
0002  *  This file is part of the KDE project
0003  *
0004  *  SPDX-FileCopyrightText: 2008 Cyrille Berger <cberger@cberger.net>
0005  *
0006  *  SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #ifndef _KIS_RANDOM_GENERATOR_H_
0010 #define _KIS_RANDOM_GENERATOR_H_
0011 
0012 #include <kritaimage_export.h>
0013 
0014 #include <QtGlobal>
0015 
0016 /**
0017  * This is a class that return a pseudo-random number that will be constant for a given
0018  * pixel coordinate.
0019  * The rational is that filters that use random number (such as noises, or raindrops)
0020  * needs to always get the same random value at each run, or else the result will constantly
0021  * changes when used as an adjustment layer.
0022  */
0023 class KRITAIMAGE_EXPORT KisRandomGenerator
0024 {
0025 public:
0026     /**
0027      * Creates a new instance of a random generator with the given seed.
0028      */
0029     KisRandomGenerator(quint64 seed);
0030     ~KisRandomGenerator();
0031     /**
0032      * @return the constant random value corresponding to a given pixel, the value is between 0
0033      *         and RAND_MAX
0034      */
0035     quint64 randomAt(qint64 x, qint64 y);
0036     /**
0037      * @return the constant random value corresponding to a given pixel, the value is between 0
0038      *         and 1.0
0039      */
0040     double doubleRandomAt(qint64 x, qint64 y);
0041 private:
0042     struct Private;
0043     Private* const d;
0044 };
0045 
0046 #endif