1+ #define USE_DAZ_LOG 1
2+
13#include " ImageTools.h"
24
5+ #if USE_DAZ_LOG
6+ #include < dzapp.h>
7+ #endif
8+
9+ void log (QString message)
10+ {
11+ #if USE_DAZ_LOG
12+ dzApp->log (message);
13+ #else
14+ printf (message.toLocal8Bit ().constData ());
15+ #endif
16+ }
17+
318
419// Bitwise check if number is a power of two
520bool isPowerOfTwo (int n)
@@ -41,15 +56,26 @@ int nearestPowerOfTwo(int n)
4156
4257void multiplyImageByColorMultithreaded (QImage& image, QColor color)
4358{
59+ // Crash Check
60+ int width = image.width ();
4461 int height = image.height ();
62+ int lineLength = image.bytesPerLine ();
63+ QImage::Format pixelFormat = image.format ();
64+ if (pixelFormat != QImage::Format_ARGB32 &&
65+ pixelFormat != QImage::Format_RGB32)
66+ {
67+ log (QString (" WARNING: multiplyImageByColorMultithreaded(): incompatible pixel format: %1, converting to ARGB32..." ).arg (pixelFormat));
68+ image = image.convertToFormat (QImage::Format_ARGB32);
69+ }
70+
4571 int numThreads = QThreadPool::globalInstance ()->maxThreadCount ();
4672 int step = height / numThreads;
4773
4874 for (int i = 0 ; i < numThreads; ++i)
4975 {
5076 int startY = i * step;
5177 int endY = (i == numThreads - 1 ) ? height : startY + step;
52- MultiplyImageByColorTask* task = new MultiplyImageByColorTask (&image, color, startY, endY);
78+ MultiplyImageByColorTask* task = new MultiplyImageByColorTask (&image, color, startY, endY, width, height, pixelFormat );
5379 QThreadPool::globalInstance ()->start (task);
5480 }
5581
@@ -58,15 +84,26 @@ void multiplyImageByColorMultithreaded(QImage& image, QColor color)
5884
5985void multiplyImageByStrengthMultithreaded (QImage& image, double strength)
6086{
87+ // Crash Check
88+ int width = image.width ();
6189 int height = image.height ();
90+ int lineLength = image.bytesPerLine ();
91+ QImage::Format pixelFormat = image.format ();
92+ if (pixelFormat != QImage::Format_ARGB32 &&
93+ pixelFormat != QImage::Format_RGB32)
94+ {
95+ log (QString (" WARNING: multiplyImageByStrengthMultithreaded(): incompatible pixel format: %1, converting to ARGB32..." ).arg (pixelFormat));
96+ image = image.convertToFormat (QImage::Format_ARGB32);
97+ }
98+
6299 int numThreads = QThreadPool::globalInstance ()->maxThreadCount ();
63100 int step = height / numThreads;
64101
65102 for (int i = 0 ; i < numThreads; ++i)
66103 {
67104 int startY = i * step;
68105 int endY = (i == numThreads - 1 ) ? height : startY + step;
69- MultiplyImageByStrengthTask* task = new MultiplyImageByStrengthTask (&image, strength, startY, endY);
106+ MultiplyImageByStrengthTask* task = new MultiplyImageByStrengthTask (&image, strength, startY, endY, width, height, pixelFormat );
70107 QThreadPool::globalInstance ()->start (task);
71108 }
72109
0 commit comments