Commit c94c9f4a authored by Gilles Caulier's avatar Gilles Caulier 🗼
Browse files

Mosaic effect : add support of multicore CPU based on QtConcurrents API....

Mosaic effect : add support of multicore CPU based on QtConcurrents API. Computation time is divided by 2 with i7 (8 core CPU)
CCBUGS: 289204
parent 80301217
......@@ -140,7 +140,7 @@ void BlurFXFilter::filterImage()
}
}
void BlurFXFilter::zoomBlurMultithreaded(const Args1& prm)
void BlurFXFilter::zoomBlurMultithreaded(const Args& prm)
{
int nh, nw;
int sumR, sumG, sumB, nCount=0;
......@@ -255,7 +255,7 @@ void BlurFXFilter::zoomBlur(DImg* const orgImage, DImg* const destImage, int X,
QList<uint> vals = multithreadedSteps(xMax, xMin);
QList <QFuture<void> > tasks;
Args1 prm;
Args prm;
prm.orgImage = orgImage;
prm.destImage = destImage;
prm.X = X;
......@@ -289,7 +289,7 @@ void BlurFXFilter::zoomBlur(DImg* const orgImage, DImg* const destImage, int X,
}
}
void BlurFXFilter::radialBlurMultithreaded(const Args1& prm)
void BlurFXFilter::radialBlurMultithreaded(const Args& prm)
{
int Width = prm.orgImage->width();
int Height = prm.orgImage->height();
......@@ -411,7 +411,7 @@ void BlurFXFilter::radialBlur(DImg* const orgImage, DImg* const destImage, int X
QList<uint> vals = multithreadedSteps(xMax, xMin);
QList <QFuture<void> > tasks;
Args1 prm;
Args prm;
prm.orgImage = orgImage;
prm.destImage = destImage;
prm.X = X;
......@@ -1241,12 +1241,49 @@ void BlurFXFilter::frostGlass(DImg* const orgImage, DImg* const destImage, int F
}
}
void BlurFXFilter::mosaicMultithreaded(const Args& prm)
{
int Width = prm.orgImage->width();
int Height = prm.orgImage->height();
uchar* data = prm.orgImage->bits();
bool sixteenBit = prm.orgImage->sixteenBit();
int bytesDepth = prm.orgImage->bytesDepth();
uchar* pResBits = prm.destImage->bits();
DColor color;
int offsetCenter, offset;
for (uint w = prm.start; runningFlag() && (w < prm.stop); w += prm.SizeW)
{
// we have to find the center pixel for mosaic's rectangle
offsetCenter = GetOffsetAdjusted(Width, Height, w + (prm.SizeW / 2), prm.h + (prm.SizeH / 2), bytesDepth);
color.setColor(data + offsetCenter, sixteenBit);
// now, we fill the mosaic's rectangle with the center pixel color
for (uint subw = w; runningFlag() && (subw <= w + prm.SizeW); ++subw)
{
for (uint subh = prm.h; runningFlag() && (subh <= prm.h + prm.SizeH); ++subh)
{
// if is inside...
if (IsInside(Width, Height, subw, subh))
{
// set color
offset = GetOffset(Width, subw, subh, bytesDepth);
color.setPixel(pResBits + offset);
}
}
}
}
}
/* Function to apply the mosaic effect backported from ImageProcessing version 2
*
* data => The image data in RGBA mode.
* Width => Width of image.
* Height => Height of image.
* Size => Size of mosaic .
* Size => Size of mosaic.
*
* Theory => Ok, you can find some mosaic effects on PSC, but this one
* has a great feature, if you see a mosaic in other code you will
......@@ -1260,13 +1297,6 @@ void BlurFXFilter::mosaic(DImg* const orgImage, DImg* const destImage, int SizeW
{
int progress;
int Width = orgImage->width();
int Height = orgImage->height();
uchar* data = orgImage->bits();
bool sixteenBit = orgImage->sixteenBit();
int bytesDepth = orgImage->bytesDepth();
uchar* pResBits = destImage->bits();
// we need to check for valid values
if (SizeW < 1)
{
......@@ -1283,39 +1313,35 @@ void BlurFXFilter::mosaic(DImg* const orgImage, DImg* const destImage, int SizeW
return;
}
DColor color;
int offsetCenter, offset;
QList<uint> vals = multithreadedSteps(orgImage->width());
QList <QFuture<void> > tasks;
Args prm;
prm.orgImage = orgImage;
prm.destImage = destImage;
prm.SizeW = SizeW;
prm.SizeH = SizeH;
// this loop will never look for transparent colors
for (int h = 0; runningFlag() && (h < Height); h += SizeH)
for (uint h = 0; runningFlag() && (h < orgImage->height()); h += SizeH)
{
for (int w = 0; runningFlag() && (w < Width); w += SizeW)
for (int j = 0 ; runningFlag() && (j < vals.count()-1) ; ++j)
{
// we have to find the center pixel for mosaic's rectangle
offsetCenter = GetOffsetAdjusted(Width, Height, w + (SizeW / 2), h + (SizeH / 2), bytesDepth);
color.setColor(data + offsetCenter, sixteenBit);
// now, we fill the mosaic's rectangle with the center pixel color
for (int subw = w; runningFlag() && (subw <= w + SizeW); ++subw)
{
for (int subh = h; runningFlag() && (subh <= h + SizeH); ++subh)
{
// if is inside...
if (IsInside(Width, Height, subw, subh))
{
// set color
offset = GetOffset(Width, subw, subh, bytesDepth);
color.setPixel(pResBits + offset);
}
}
}
prm.start = vals[j];
prm.stop = vals[j+1];
prm.h = h;
tasks.append(QtConcurrent::run(this,
&BlurFXFilter::mosaicMultithreaded,
prm
));
}
foreach(QFuture<void> t, tasks)
t.waitForFinished();
// Update the progress bar in dialog.
progress = (int)(((double)h * 100.0) / Height);
progress = (int)(((double)h * 100.0) / orgImage->height());
if (progress % 5 == 0)
{
......
......@@ -97,7 +97,7 @@ public:
private:
struct Args1
struct Args
{
uint start;
uint stop;
......@@ -107,6 +107,9 @@ private:
int X;
int Y;
int Distance;
int SizeW;
int SizeH;
};
private:
......@@ -120,10 +123,10 @@ private:
// Backported from ImageProcessing version 2
void zoomBlur(DImg* const orgImage, DImg* const destImage, int X, int Y, int Distance, const QRect& pArea=QRect());
void zoomBlurMultithreaded(const Args1& prm);
void zoomBlurMultithreaded(const Args& prm);
void radialBlur(DImg* const orgImage, DImg* const destImage, int X, int Y, int Distance, const QRect& pArea=QRect());
void radialBlurMultithreaded(const Args1& prm);
void radialBlurMultithreaded(const Args& prm);
void focusBlur(DImg* const orgImage, DImg* const destImage, int X, int Y, int BlurRadius, int BlendRadius,
bool bInversed=false, const QRect& pArea=QRect());
......@@ -131,7 +134,9 @@ private:
void farBlur(DImg* const orgImage, DImg* const destImage, int Distance);
void motionBlur(DImg* const orgImage, DImg* const destImage, int Distance, double Angle=0.0);
void smartBlur(DImg* const orgImage, DImg* const destImage, int Radius, int Strength);
void mosaic(DImg* const orgImage, DImg* const destImage, int SizeW, int SizeH);
void mosaicMultithreaded(const Args& prm);
private:
......
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