Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Use KisRandomSource in Dissolve blendmode
Dmitry Kazakov0daffa932a79
diff --git a/libs/global/CMakeLists.txt b/libs/global/CMakeLists.txtindex e0f68f6276..8822dc4d41 100644--- a/libs/global/CMakeLists.txt+++ b/libs/global/CMakeLists.txt@@ -43,6 +43,7 @@ set(kritaglobal_LIB_SRCSKisBackup.cppKisSampleRectIterator.cppKisCursorOverrideLock.cpp+ kis_random_source.cpp)if(WIN32)diff --git a/libs/image/brushengine/kis_random_source.cpp b/libs/global/kis_random_source.cppsimilarity index 100%rename from libs/image/brushengine/kis_random_source.cpprename to libs/global/kis_random_source.cppdiff --git a/libs/image/brushengine/kis_random_source.h b/libs/global/kis_random_source.hsimilarity index 94%rename from libs/image/brushengine/kis_random_source.hrename to libs/global/kis_random_source.hindex 9e2e546be6..4ec9c3b895 100644--- a/libs/image/brushengine/kis_random_source.h+++ b/libs/global/kis_random_source.h@@ -11,7 +11,7 @@#include "kis_shared.h"#include "kis_shared_ptr.h"-#include "kritaimage_export.h"+#include "kritaglobal_export.h"/*** KisRandomSource is a special object that wraps around random number@@ -29,7 +29,7 @@* 3) Copying of a KisRandomSource object is fast. It uses Tauss88* algorithm to achieve this.*/-class KRITAIMAGE_EXPORT KisRandomSource : public KisShared+class KRITAGLOBAL_EXPORT KisRandomSource : public KisShared{public:KisRandomSource();diff --git a/libs/image/CMakeLists.txt b/libs/image/CMakeLists.txtindex 7375f01a3e..8389ac01b5 100644--- a/libs/image/CMakeLists.txt+++ b/libs/image/CMakeLists.txt@@ -57,7 +57,6 @@ set(kritaimage_LIB_SRCSkis_progress_updater.cppKisAnimatedOpacityProperty.cppbrushengine/kis_paint_information.cc- brushengine/kis_random_source.cppbrushengine/KisPerStrokeRandomSource.cppbrushengine/kis_stroke_random_source.cppbrushengine/kis_paintop.ccdiff --git a/libs/pigment/compositeops/KoCompositeOpDissolve.h b/libs/pigment/compositeops/KoCompositeOpDissolve.hindex 462fe0dafa..6f064f2e41 100644--- a/libs/pigment/compositeops/KoCompositeOpDissolve.h+++ b/libs/pigment/compositeops/KoCompositeOpDissolve.h@@ -10,7 +10,7 @@#include <KoColorSpaceMaths.h>#include <KoCompositeOp.h>-#include <QRandomGenerator>+#include <kis_random_source.h>#include <QThreadStorage>template<class Traits>@@ -21,32 +21,7 @@ class KoCompositeOpDissolve: public KoCompositeOpstatic const qint32 channels_nb = Traits::channels_nb;static const qint32 alpha_pos = Traits::alpha_pos;- inline static quint8 getRandomValue(quint32 i)- {- static const quint8 randomValues[256] =- {- 0x50, 0xAD, 0x7D, 0xA9, 0x10, 0x75, 0xCA, 0x57, 0xE2, 0x06, 0x77, 0x39, 0xD9, 0xFA, 0x5C, 0x24,- 0xEB, 0x1A, 0x6F, 0x15, 0xE7, 0x8B, 0x11, 0x71, 0xF0, 0xB9, 0x44, 0x8A, 0x27, 0x5E, 0xA1, 0x6A,- 0x47, 0x94, 0x03, 0xD5, 0xB7, 0x56, 0xEF, 0x45, 0xED, 0xBE, 0xE8, 0xB2, 0x4C, 0x0D, 0x65, 0x9E,- 0x55, 0xD7, 0x30, 0x0F, 0x52, 0xA6, 0x4D, 0x86, 0xAF, 0x66, 0x33, 0x6B, 0x3E, 0x89, 0xBD, 0xFB,- 0x00, 0xC4, 0x36, 0xFC, 0x8D, 0x4E, 0x19, 0x3F, 0x91, 0xC1, 0x40, 0x14, 0x67, 0x80, 0x17, 0x3A,- 0xF2, 0xB4, 0xD1, 0xFF, 0x35, 0xA7, 0xF7, 0x1C, 0x84, 0x2A, 0xBF, 0x46, 0xC6, 0x2B, 0x98, 0x41,- 0xF4, 0xB8, 0xA0, 0x78, 0x5A, 0xBC, 0x3B, 0x62, 0xB6, 0x7A, 0x2E, 0x07, 0x8F, 0x4A, 0xAB, 0x2F,- 0x79, 0x54, 0x81, 0x69, 0x18, 0x4F, 0xA5, 0x21, 0xD3, 0x26, 0x7C, 0x9F, 0xCF, 0xB0, 0x34, 0xCC,- 0x8C, 0xAA, 0xDB, 0x32, 0xE5, 0x1F, 0x7B, 0x37, 0x64, 0x0A, 0xF9, 0x63, 0xF5, 0x38, 0x13, 0xA2,- 0x12, 0xF6, 0xC9, 0x5D, 0xDF, 0xC7, 0x97, 0xC0, 0x51, 0xE1, 0x9A, 0x58, 0x76, 0xC3, 0x83, 0xC2,- 0x04, 0x22, 0x60, 0x9D, 0xF1, 0x5F, 0xEC, 0x6D, 0x4B, 0xE0, 0x6C, 0xD8, 0xAC, 0x25, 0xA8, 0x1E,- 0x96, 0x7E, 0x49, 0x61, 0xCD, 0x0E, 0xE3, 0xC5, 0x7F, 0x5B, 0x05, 0x6E, 0xBA, 0x0C, 0x8E, 0xF8,- 0x82, 0xDA, 0x72, 0x01, 0x23, 0x9B, 0xD2, 0x99, 0xE9, 0xC8, 0xB1, 0x28, 0xD4, 0xAE, 0x48, 0xFD,- 0x95, 0x2C, 0xE4, 0x93, 0x09, 0x3D, 0x70, 0x85, 0x43, 0x20, 0xBB, 0xDE, 0x90, 0xB3, 0x3C, 0xDD,- 0xA3, 0x73, 0x9C, 0x16, 0xDC, 0x42, 0xEA, 0x74, 0x92, 0xE6, 0xCB, 0x53, 0x08, 0xEE, 0x59, 0x02,- 0xF3, 0x29, 0xFE, 0xA4, 0x1B, 0xD6, 0x87, 0xB5, 0xCE, 0x1D, 0x68, 0x88, 0x31, 0x0B, 0x2D, 0xD0- };-- return randomValues[i];- }-- mutable QThreadStorage<QRandomGenerator> m_randomGenerator;+ mutable QThreadStorage<KisRandomSource> m_randomGenerator;public:KoCompositeOpDissolve(const KoColorSpace* cs, const QString& category)@@ -60,9 +35,12 @@ public:/*** Initialize local per-thread random generator from the global one, it will* reduce contestion over the global generator in the main compositing loop.+ *+ * KisRandomSource is automatically initialized from QRandomGenerator::global()+ * internally.*/if (!m_randomGenerator.hasLocalData()) {- m_randomGenerator.setLocalData(QRandomGenerator(QRandomGenerator::global()->generate()));+ m_randomGenerator.setLocalData(KisRandomSource());}const QBitArray& flags = params.channelFlags.isEmpty() ? QBitArray(channels_nb,true) : params.channelFlags;@@ -92,7 +70,7 @@ public:channels_type dstAlpha = (alpha_pos == -1) ? unitValue : dst[alpha_pos];channels_type blend = useMask ? mul(opacity, scale<channels_type>(*mask), srcAlpha) : mul(opacity, srcAlpha);- if (m_randomGenerator.localData().bounded(256) <= scale<quint8>(blend)+ if (m_randomGenerator.localData().generate(0, 255) <= scale<quint8>(blend)&& blend != KoColorSpaceMathsTraits<channels_type>::zeroValue) {for(qint32 i=0; i <channels_nb; i++) {if(i != alpha_pos && flags.testBit(i))diff --git a/plugins/paintops/libpaintop/kis_color_source.cpp b/plugins/paintops/libpaintop/kis_color_source.cppindex 4d468eac8c..10939157c8 100644--- a/plugins/paintops/libpaintop/kis_color_source.cpp+++ b/plugins/paintops/libpaintop/kis_color_source.cpp@@ -15,7 +15,7 @@#include <kis_fill_painter.h>#include "kis_iterator_ng.h"#include "kis_selection.h"-#include <brushengine/kis_random_source.h>+#include <kis_random_source.h>#include <brushengine/kis_paint_information.h>#include <random>diff --git a/plugins/paintops/spray/spray_brush.h b/plugins/paintops/spray/spray_brush.hindex 7308972810..6cebc004f0 100644--- a/plugins/paintops/spray/spray_brush.h+++ b/plugins/paintops/spray/spray_brush.h@@ -12,7 +12,7 @@#include "kis_types.h"#include "kis_painter.h"-#include <brushengine/kis_random_source.h>+#include <kis_random_source.h>#include "KisColorOptionData.h"#include "KisSprayOpOptionData.h"#include "KisSprayOpOption.h"