style cleanup

This commit is contained in:
Campbell Barton
2012-06-13 14:33:50 +00:00
parent 342fb0a19e
commit e22aa7bc38
10 changed files with 117 additions and 104 deletions

View File

@@ -23,7 +23,7 @@
#include "COM_GlareBaseOperation.h"
#include "BLI_math.h"
GlareBaseOperation::GlareBaseOperation(): SingleThreadedNodeOperation()
GlareBaseOperation::GlareBaseOperation() : SingleThreadedNodeOperation()
{
this->addInputSocket(COM_DT_COLOR);
this->addOutputSocket(COM_DT_COLOR);
@@ -43,7 +43,7 @@ void GlareBaseOperation::deinitExecution()
MemoryBuffer *GlareBaseOperation::createMemoryBuffer(rcti *rect2, MemoryBuffer **memoryBuffers)
{
MemoryBuffer *tile = (MemoryBuffer*)inputProgram->initializeTileData(rect2, memoryBuffers);
MemoryBuffer *tile = (MemoryBuffer *)inputProgram->initializeTileData(rect2, memoryBuffers);
rcti rect;
rect.xmin = 0;
rect.ymin = 0;

View File

@@ -15,8 +15,8 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor:
* Jeroen Bakker
* Contributor:
* Jeroen Bakker
* Monique Dewanchand
*/
@@ -59,34 +59,36 @@ typedef float fRGB[4];
class GlareBaseOperation : public SingleThreadedNodeOperation {
private:
/**
* @brief Cached reference to the inputProgram
*/
SocketReader * inputProgram;
* @brief Cached reference to the inputProgram
*/
SocketReader *inputProgram;
/**
* @brief settings of the glare node.
*/
NodeGlare * settings;
* @brief settings of the glare node.
*/
NodeGlare *settings;
public:
/**
* Initialize the execution
*/
* Initialize the execution
*/
void initExecution();
/**
* Deinitialize the execution
*/
* Deinitialize the execution
*/
void deinitExecution();
void setGlareSettings(NodeGlare * settings) {this->settings = settings;}
void setGlareSettings(NodeGlare *settings) {
this->settings = settings;
}
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
protected:
GlareBaseOperation();
virtual void generateGlare(float *data, MemoryBuffer *inputTile, NodeGlare *settings) = 0;
MemoryBuffer *createMemoryBuffer(rcti *rect, MemoryBuffer **memoryBuffers);
};
#endif

View File

@@ -15,8 +15,8 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor:
* Jeroen Bakker
* Contributor:
* Jeroen Bakker
* Monique Dewanchand
*/
@@ -27,12 +27,16 @@
static float smoothMask(float x, float y)
{
float t;
x = 2.f * x - 1.f, y = 2.f * y - 1.f;
if ((t = 1.f - sqrtf(x * x + y * y)) <= 0.f) return 0.f;
return t;
x = 2.0f * x - 1.0f;
y = 2.0f * y - 1.0f;
if ((t = 1.0f - sqrtf(x * x + y * y)) > 0.0f) {
return t;
}
else {
return 0.0f;
}
}
void GlareGhostOperation::generateGlare(float *data, MemoryBuffer *inputTile, NodeGlare *settings)
{
const int qt = 1 << settings->quality;

View File

@@ -15,8 +15,8 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor:
* Jeroen Bakker
* Contributor:
* Jeroen Bakker
* Monique Dewanchand
*/
@@ -28,7 +28,8 @@
class GlareGhostOperation : public GlareBaseOperation {
public:
GlareGhostOperation() : GlareBaseOperation() {}
GlareGhostOperation() : GlareBaseOperation() {
}
protected:
void generateGlare(float *data, MemoryBuffer *inputTile, NodeGlare *settings);
};

View File

@@ -15,8 +15,8 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor:
* Jeroen Bakker
* Contributor:
* Jeroen Bakker
* Monique Dewanchand
*/
@@ -25,21 +25,21 @@
void GlareSimpleStarOperation::generateGlare(float *data, MemoryBuffer *inputTile, NodeGlare *settings)
{
int i, x, y, ym, yp, xm, xp;
float c[4] = {0,0,0,0}, tc[4] = {0,0,0,0};
const float f1 = 1.f - settings->fade, f2 = (1.f - f1)*0.5f;
float c[4] = {0, 0, 0, 0}, tc[4] = {0, 0, 0, 0};
const float f1 = 1.0f - settings->fade;
const float f2 = (1.0f - f1) * 0.5f;
MemoryBuffer *tbuf1 = inputTile->duplicate();
MemoryBuffer *tbuf2 = inputTile->duplicate();
bool breaked = false;
for (i=0; i<settings->iter && (!breaked); i++) {
for (i = 0; i < settings->iter && (!breaked); i++) {
// // (x || x-1, y-1) to (x || x+1, y+1)
// // F
for (y=0; y<this->getHeight() && (!breaked); y++) {
for (y = 0; y < this->getHeight() && (!breaked); y++) {
ym = y - i;
yp = y + i;
for (x=0; x<this->getWidth(); x++) {
for (x = 0; x < this->getWidth(); x++) {
xm = x - i;
xp = x + i;
tbuf1->read(c, x, y);
@@ -65,10 +65,10 @@ void GlareSimpleStarOperation::generateGlare(float *data, MemoryBuffer *inputTil
}
}
// // B
for (y=tbuf1->getHeight()-1 && (!breaked); y>=0; y--) {
for (y = tbuf1->getHeight() - 1 && (!breaked); y >= 0; y--) {
ym = y - i;
yp = y + i;
for (x=tbuf1->getWidth()-1; x>=0; x--) {
for (x = tbuf1->getWidth() - 1; x >= 0; x--) {
xm = x - i;
xp = x + i;
tbuf1->read(c, x, y);
@@ -95,7 +95,7 @@ void GlareSimpleStarOperation::generateGlare(float *data, MemoryBuffer *inputTil
}
}
for (i = 0 ; i < this->getWidth()*this->getHeight()*4 ; i++) {
for (i = 0; i < this->getWidth() * this->getHeight() * 4; i++) {
data[i] = tbuf1->getBuffer()[i] + tbuf2->getBuffer()[i];
}

View File

@@ -15,8 +15,8 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor:
* Jeroen Bakker
* Contributor:
* Jeroen Bakker
* Monique Dewanchand
*/
@@ -28,7 +28,8 @@
class GlareSimpleStarOperation : public GlareBaseOperation {
public:
GlareSimpleStarOperation() : GlareBaseOperation() {}
GlareSimpleStarOperation() : GlareBaseOperation() {
}
protected:
void generateGlare(float *data, MemoryBuffer *inputTile, NodeGlare *settings);
};

View File

@@ -15,8 +15,8 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor:
* Jeroen Bakker
* Contributor:
* Jeroen Bakker
* Monique Dewanchand
*/
@@ -26,73 +26,73 @@
void GlareStreaksOperation::generateGlare(float *data, MemoryBuffer *inputTile, NodeGlare *settings)
{
int x, y, n;
unsigned int nump=0;
unsigned int nump = 0;
float c1[4], c2[4], c3[4], c4[4];
float a, ang = DEG2RADF(360.0f)/(float)settings->angle;
int size = inputTile->getWidth()*inputTile->getHeight();
int size4 = size*4;
float a, ang = DEG2RADF(360.0f) / (float)settings->angle;
int size = inputTile->getWidth() * inputTile->getHeight();
int size4 = size * 4;
bool breaked = false;
MemoryBuffer *tsrc = inputTile->duplicate();
MemoryBuffer *tdst = new MemoryBuffer(NULL, inputTile->getRect());
tdst->clear();
memset(data, 0, size4*sizeof(float));
for (a=0.f; a<DEG2RADF(360.0f) && (!breaked); a+=ang) {
memset(data, 0, size4 * sizeof(float));
for (a = 0.f; a < DEG2RADF(360.0f) && (!breaked); a += ang) {
const float an = a + settings->angle_ofs;
const float vx = cos((double)an), vy = sin((double)an);
for (n=0; n<settings->iter && (!breaked); ++n) {
for (n = 0; n < settings->iter && (!breaked); ++n) {
const float p4 = pow(4.0, (double)n);
const float vxp = vx*p4, vyp = vy*p4;
const float vxp = vx * p4, vyp = vy * p4;
const float wt = pow((double)settings->fade, (double)p4);
const float cmo = 1.f - (float)pow((double)settings->colmod, (double)n+1); // colormodulation amount relative to current pass
const float cmo = 1.f - (float)pow((double)settings->colmod, (double)n + 1); // colormodulation amount relative to current pass
float *tdstcol = tdst->getBuffer();
for (y=0; y<tsrc->getHeight() && (!breaked); ++y) {
for (x=0; x<tsrc->getWidth(); ++x, tdstcol+=4) {
for (y = 0; y < tsrc->getHeight() && (!breaked); ++y) {
for (x = 0; x < tsrc->getWidth(); ++x, tdstcol += 4) {
// first pass no offset, always same for every pass, exact copy,
// otherwise results in uneven brightness, only need once
if (n==0) tsrc->read(c1, x, y); else c1[0]=c1[1]=c1[2]=0;
if (n == 0) tsrc->read(c1, x, y); else c1[0] = c1[1] = c1[2] = 0;
tsrc->readCubic(c2, x + vxp, y + vyp);
tsrc->readCubic(c3, x + vxp*2.f, y + vyp*2.f);
tsrc->readCubic(c4, x + vxp*3.f, y + vyp*3.f);
tsrc->readCubic(c3, x + vxp * 2.f, y + vyp * 2.f);
tsrc->readCubic(c4, x + vxp * 3.f, y + vyp * 3.f);
// modulate color to look vaguely similar to a color spectrum
c2[1] *= cmo;
c2[2] *= cmo;
c3[0] *= cmo;
c3[1] *= cmo;
c4[0] *= cmo;
c4[2] *= cmo;
tdstcol[0] = 0.5f*(tdstcol[0] + c1[0] + wt*(c2[0] + wt*(c3[0] + wt*c4[0])));
tdstcol[1] = 0.5f*(tdstcol[1] + c1[1] + wt*(c2[1] + wt*(c3[1] + wt*c4[1])));
tdstcol[2] = 0.5f*(tdstcol[2] + c1[2] + wt*(c2[2] + wt*(c3[2] + wt*c4[2])));
tdstcol[0] = 0.5f * (tdstcol[0] + c1[0] + wt * (c2[0] + wt * (c3[0] + wt * c4[0])));
tdstcol[1] = 0.5f * (tdstcol[1] + c1[1] + wt * (c2[1] + wt * (c3[1] + wt * c4[1])));
tdstcol[2] = 0.5f * (tdstcol[2] + c1[2] + wt * (c2[2] + wt * (c3[2] + wt * c4[2])));
tdstcol[3] = 1.0f;
}
if (isBreaked()) {
breaked = true;
}
}
memcpy(tsrc->getBuffer(), tdst->getBuffer(), sizeof(float)*size4);
memcpy(tsrc->getBuffer(), tdst->getBuffer(), sizeof(float) * size4);
}
float *sourcebuffer = tsrc->getBuffer();
float factor = 1.f/(float)(6 - settings->iter);
for (int i = 0 ; i < size4; i ++) {
float factor = 1.f / (float)(6 - settings->iter);
for (int i = 0; i < size4; i++) {
data[i] += sourcebuffer[i] * factor;
}
for (int i = 0 ; i < size; i ++) {
data[i*4+3] = 1.0f;
for (int i = 0; i < size; i++) {
data[i * 4 + 3] = 1.0f;
}
tdst->clear();
memcpy(tsrc->getBuffer(), inputTile->getBuffer(), sizeof(float)*size4);
memcpy(tsrc->getBuffer(), inputTile->getBuffer(), sizeof(float) * size4);
nump++;
}
delete tsrc;
delete tdst;
}

View File

@@ -15,8 +15,8 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor:
* Jeroen Bakker
* Contributor:
* Jeroen Bakker
* Monique Dewanchand
*/
@@ -28,7 +28,8 @@
class GlareStreaksOperation : public GlareBaseOperation {
public:
GlareStreaksOperation() : GlareBaseOperation() {}
GlareStreaksOperation() : GlareBaseOperation() {
}
protected:
void generateGlare(float *data, MemoryBuffer *inputTile, NodeGlare *settings);
};

View File

@@ -15,15 +15,15 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor:
* Jeroen Bakker
* Contributor:
* Jeroen Bakker
* Monique Dewanchand
*/
#include "COM_GlareThresholdOperation.h"
#include "BLI_math.h"
GlareThresholdOperation::GlareThresholdOperation(): NodeOperation()
GlareThresholdOperation::GlareThresholdOperation() : NodeOperation()
{
this->addInputSocket(COM_DT_COLOR);
this->addOutputSocket(COM_DT_COLOR);
@@ -37,13 +37,15 @@ void GlareThresholdOperation::initExecution()
void GlareThresholdOperation::executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
{
this->inputProgram->read(color, x, y, sampler, inputBuffers);
if ((0.212671f*color[0] + 0.71516f*color[1] + 0.072169f*color[2]) >= threshold) {
if ((0.212671f * color[0] + 0.71516f * color[1] + 0.072169f * color[2]) >= threshold) {
color[0] -= threshold, color[1] -= threshold, color[2] -= threshold;
color[0] = MAX2(color[0], 0.f);
color[1] = MAX2(color[1], 0.f);
color[2] = MAX2(color[2], 0.f);
color[0] = MAX2(color[0], 0.0f);
color[1] = MAX2(color[1], 0.0f);
color[2] = MAX2(color[2], 0.0f);
}
else {
zero_v3(color);
}
else color[0] = color[1] = color[2] = 0.f;
}
void GlareThresholdOperation::deinitExecution()

View File

@@ -15,8 +15,8 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor:
* Jeroen Bakker
* Contributor:
* Jeroen Bakker
* Monique Dewanchand
*/
@@ -28,30 +28,32 @@
class GlareThresholdOperation : public NodeOperation {
private:
/**
* @brief Cached reference to the inputProgram
*/
SocketReader * inputProgram;
* @brief Cached reference to the inputProgram
*/
SocketReader *inputProgram;
float threshold;
public:
GlareThresholdOperation();
/**
* the inner loop of this program
*/
void executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]);
* the inner loop of this program
*/
void executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer * inputBuffers[]);
/**
* Initialize the execution
*/
* Initialize the execution
*/
void initExecution();
/**
* Deinitialize the execution
*/
* Deinitialize the execution
*/
void deinitExecution();
void setThreshold(float threshold) {this->threshold = threshold;}
void setThreshold(float threshold) {
this->threshold = threshold;
}
};
#endif