Commit 5776c84b authored by Gilles Caulier's avatar Gilles Caulier 🗼
Browse files

Emboss Tool : add support of multicore CPU based on QtConcurrent API.

CCBUGS: 289204
parent 31d8429a
......@@ -17,6 +17,7 @@ Editor : Sharpen tool support multicore CPU.
Editor : Blur tool support multicore CPU.
Editor : Charcoal tool support multicore CPU.
Editor : OilPaint tool support multicore CPU.
Editor : Emboss tool support multicore CPU.
Showfoto : Port of Thumbbar to Qt Model/view.
......
......@@ -26,7 +26,7 @@ filters
/colorfx DONE TODO DONE DONE
/charcoal DONE DONE DONE TODO
/distortionfx DONE TODO TODO TODO
/emboss DONE TODO DONE TODO
/emboss DONE DONE DONE TODO
/oilpaint DONE DONE DONE TODO
/blurfx DONE TODO DONE TODO
/raindrop DONE TODO NO TODO
......
......@@ -6,7 +6,7 @@
* Date : 2005-05-25
* Description : Emboss threaded image filter.
*
* Copyright (C) 2005-2013 by Gilles Caulier <caulier dot gilles at gmail dot com>
* Copyright (C) 2005-2014 by Gilles Caulier <caulier dot gilles at gmail dot com>
* Copyright (C) 2006-2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
* Copyright (C) 2010 by Martin Klapetek <martin dot klapetek at gmail dot com>
*
......@@ -33,6 +33,11 @@
#include <cmath>
#include <cstdlib>
// Qt includes
#include <qmath.h>
#include <QtConcurrentRun>
// Local includes
#include "dimg.h"
......@@ -67,60 +72,90 @@ EmbossFilter::~EmbossFilter()
* understand. You get the difference between the colors and
* increase it. After this, get the gray tone
*/
void EmbossFilter::filterImage()
void EmbossFilter::embossMultithreaded(uint start, uint stop, uint h, double Depth)
{
int Width = m_orgImage.width();
int Height = m_orgImage.height();
uchar* data = m_orgImage.bits();
bool sixteenBit = m_orgImage.sixteenBit();
int bytesDepth = m_orgImage.bytesDepth();
uchar* const Bits = m_destImage.bits();
int red, green, blue, gray;
DColor color, colorOther;
int offset, offsetOther;
for (uint w = start ; runningFlag() && (w < stop) ; ++w)
{
offset = getOffset(Width, w, h, bytesDepth);
offsetOther = getOffset(Width, w + Lim_Max(w, 1, Width), h + Lim_Max(h, 1, Height), bytesDepth);
color.setColor(Bits + offset, sixteenBit);
colorOther.setColor(Bits + offsetOther, sixteenBit);
if (sixteenBit)
{
red = abs((int)((color.red() - colorOther.red()) * Depth + 32768));
green = abs((int)((color.green() - colorOther.green()) * Depth + 32768));
blue = abs((int)((color.blue() - colorOther.blue()) * Depth + 32768));
gray = CLAMP065535((red + green + blue) / 3);
}
else
{
red = abs((int)((color.red() - colorOther.red()) * Depth + 128));
green = abs((int)((color.green() - colorOther.green()) * Depth + 128));
blue = abs((int)((color.blue() - colorOther.blue()) * Depth + 128));
gray = CLAMP0255((red + green + blue) / 3);
}
// Overwrite RGB values to destination. Alpha remains unchanged.
color.setRed(gray);
color.setGreen(gray);
color.setBlue(gray);
color.setPixel(Bits + offset);
}
}
void EmbossFilter::filterImage()
{
// Initial copy
memcpy(Bits, data, m_destImage.numBytes());
memcpy(m_destImage.bits(), m_orgImage.bits(), m_destImage.numBytes());
double Depth = m_depth / 10.0;
int progress;
int red, green, blue, gray;
DColor color, colorOther;
int offset, offsetOther;
for (int h = 0 ; runningFlag() && (h < Height) ; ++h)
uint nbCore = QThreadPool::globalInstance()->maxThreadCount();
float step = m_orgImage.width() / nbCore;
uint vals[nbCore+1];
vals[0] = 0;
vals[nbCore] = m_orgImage.width();
for (uint i = 1 ; i < nbCore ; ++i)
vals[i] = vals[i-1] + step;
for (uint h = 0 ; runningFlag() && (h < m_orgImage.height()) ; ++h)
{
for (int w = 0 ; runningFlag() && (w < Width) ; ++w)
QList <QFuture<void> > tasks;
for (uint j = 0 ; runningFlag() && (j < nbCore) ; ++j)
{
offset = getOffset(Width, w, h, bytesDepth);
offsetOther = getOffset(Width, w + Lim_Max(w, 1, Width), h + Lim_Max(h, 1, Height), bytesDepth);
color.setColor(Bits + offset, sixteenBit);
colorOther.setColor(Bits + offsetOther, sixteenBit);
if (sixteenBit)
{
red = abs((int)((color.red() - colorOther.red()) * Depth + 32768));
green = abs((int)((color.green() - colorOther.green()) * Depth + 32768));
blue = abs((int)((color.blue() - colorOther.blue()) * Depth + 32768));
gray = CLAMP065535((red + green + blue) / 3);
}
else
{
red = abs((int)((color.red() - colorOther.red()) * Depth + 128));
green = abs((int)((color.green() - colorOther.green()) * Depth + 128));
blue = abs((int)((color.blue() - colorOther.blue()) * Depth + 128));
gray = CLAMP0255((red + green + blue) / 3);
}
// Overwrite RGB values to destination. Alpha remains unchanged.
color.setRed(gray);
color.setGreen(gray);
color.setBlue(gray);
color.setPixel(Bits + offset);
tasks.append(QtConcurrent::run(this,
&EmbossFilter::embossMultithreaded,
vals[j],
vals[j+1],
h,
Depth
));
}
progress = (int)(((double)h * 100.0) / Height);
foreach(QFuture<void> t, tasks)
t.waitForFinished();
progress = (int)(((double)h * 100.0) / m_orgImage.height());
if (progress % 5 == 0)
{
......
......@@ -6,7 +6,7 @@
* Date : 2005-05-25
* Description : Emboss threaded image filter.
*
* Copyright (C) 2005-2013 by Gilles Caulier <caulier dot gilles at gmail dot com>
* Copyright (C) 2005-2014 by Gilles Caulier <caulier dot gilles at gmail dot com>
* Copyright (C) 2006-2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
* Copyright (C) 2010 by Martin Klapetek <martin dot klapetek at gmail dot com>
*
......@@ -78,6 +78,7 @@ public:
private:
void filterImage();
void embossMultithreaded(uint start, uint stop, uint h, double Depth);
inline int Lim_Max (int Now, int Up, int Max);
inline int getOffset(int Width, int X, int Y, int bytesDepth);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment