Commit 70ed071c authored by Gilles Caulier's avatar Gilles Caulier 🗼
Browse files

Polar effects : add support of multicore CPU based on QtConcurrents API....

Polar effects : add support of multicore CPU based on QtConcurrents API. Computation time is divided by 2 with i7 (8 core CPU)
CCBUGS: 289204
parent c1bec9e2
......@@ -1005,33 +1005,21 @@ void DistortionFXFilter::circularWaves(DImg* orgImage, DImg* destImage, int X, i
}
}
/* Function to apply the Polar Coordinates effect backported from ImageProcesqSing version 2
*
* data => The image data in RGBA mode.
* Width => Width of image.
* Height => Height of image.
* Type => if true Polar Coordinate to Polar else inverse.
* Antialias => Smart blurring result.
*
* Theory => Similar to PolarCoordinates from Photoshop. We apply the polar
* transformation in a proportional (Height and Width) radius.
*/
void DistortionFXFilter::polarCoordinates(DImg* orgImage, DImg* destImage, bool Type, bool AntiAlias)
void DistortionFXFilter::polarCoordinatesMultithreaded(const Args& prm)
{
int Width = orgImage->width();
int Height = orgImage->height();
uchar* data = orgImage->bits();
bool sixteenBit = orgImage->sixteenBit();
int bytesDepth = orgImage->bytesDepth();
uchar* pResBits = destImage->bits();
int h, w;
double nh, nw, th, tw;
int progress;
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();
int nHalfW = Width / 2, nHalfH = Height / 2;
double lfXScale = 1.0, lfYScale = 1.0;
int nHalfW = Width / 2;
int nHalfH = Height / 2;
double lfXScale = 1.0;
double lfYScale = 1.0;
double lfAngle, lfRadius, lfRadMax;
double nh, nw, tw;
if (Width > Height)
{
......@@ -1044,43 +1032,82 @@ void DistortionFXFilter::polarCoordinates(DImg* orgImage, DImg* destImage, bool
lfRadMax = (double)qMax(Height, Width) / 2.0;
// main loop
double th = lfYScale * (double)(prm.h - nHalfH);
for (h = 0; runningFlag() && (h < Height); ++h)
for (int w = prm.start; runningFlag() && (w < prm.stop); ++w)
{
th = lfYScale * (double)(h - nHalfH);
tw = lfXScale * (double)(w - nHalfW);
for (w = 0; runningFlag() && (w < Width); ++w)
if (prm.Type)
{
tw = lfXScale * (double)(w - nHalfW);
// now, we get the distance
lfRadius = qSqrt(th * th + tw * tw);
// we find the angle from the center
lfAngle = qAtan2(tw, th);
if (Type)
{
// now, we get the distance
lfRadius = qSqrt(th * th + tw * tw);
// we find the angle from the center
lfAngle = qAtan2(tw, th);
// now we find the exact position's x and y
nh = lfRadius * (double) Height / lfRadMax;
nw = lfAngle * (double) Width / (2 * M_PI);
// now we find the exact position's x and y
nh = lfRadius * (double) Height / lfRadMax;
nw = lfAngle * (double) Width / (2 * M_PI);
nw = (double)nHalfW + nw;
}
else
{
lfRadius = (double)(prm.h) * lfRadMax / (double)Height;
lfAngle = (double)(w) * (2 * M_PI) / (double) Width;
nw = (double)nHalfW + nw;
}
else
{
lfRadius = (double)(h) * lfRadMax / (double)Height;
lfAngle = (double)(w) * (2 * M_PI) / (double) Width;
nw = (double)nHalfW - (lfRadius / lfXScale) * qSin(lfAngle);
nh = (double)nHalfH - (lfRadius / lfYScale) * qCos(lfAngle);
}
nw = (double)nHalfW - (lfRadius / lfXScale) * qSin(lfAngle);
nh = (double)nHalfH - (lfRadius / lfYScale) * qCos(lfAngle);
}
setPixelFromOther(Width, Height, sixteenBit, bytesDepth, data, pResBits, w, prm.h, nw, nh, prm.AntiAlias);
}
}
setPixelFromOther(Width, Height, sixteenBit, bytesDepth, data, pResBits, w, h, nw, nh, AntiAlias);
/* Function to apply the Polar Coordinates effect backported from ImageProcesqSing version 2
*
* data => The image data in RGBA mode.
* Width => Width of image.
* Height => Height of image.
* Type => if true Polar Coordinate to Polar else inverse.
* Antialias => Smart blurring result.
*
* Theory => Similar to PolarCoordinates from Photoshop. We apply the polar
* transformation in a proportional (Height and Width) radius.
*/
void DistortionFXFilter::polarCoordinates(DImg* orgImage, DImg* destImage, bool Type, bool AntiAlias)
{
int progress;
QList<int> vals = multithreadedSteps(orgImage->width());
QList <QFuture<void> > tasks;
Args prm;
prm.orgImage = orgImage;
prm.destImage = destImage;
prm.Type = Type;
prm.AntiAlias = AntiAlias;
// main loop
for (int h = 0; runningFlag() && (h < (int)orgImage->height()); ++h)
{
for (int j = 0 ; runningFlag() && (j < vals.count()-1) ; ++j)
{
prm.start = vals[j];
prm.stop = vals[j+1];
prm.h = h;
tasks.append(QtConcurrent::run(this,
&DistortionFXFilter::polarCoordinatesMultithreaded,
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)
{
......
......@@ -124,6 +124,7 @@ private:
double Phase;
bool WavesType;
bool FillSides;
bool Type;
};
private:
......@@ -145,6 +146,7 @@ private:
void multipleCornersMultithreaded(const Args& prm);
void polarCoordinates(DImg* orgImage, DImg* destImage, bool Type, bool AntiAlias=true);
void polarCoordinatesMultithreaded(const Args& prm);
void circularWaves(DImg* orgImage, DImg* destImage, int X, int Y, double Amplitude,
double Frequency, double Phase, bool WavesType, bool AntiAlias=true);
......
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