diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-06-15 19:04:56 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-06-15 19:04:56 +0400 |
commit | 2ca89f7add1949295ac58de6697534d44508bca3 (patch) | |
tree | 1e01dca23380d77500345398619596a49b887b4e /source/blender/compositor/operations/COM_DilateErodeOperation.cpp | |
parent | 77ec3ae9d100ba32e3bd32e2208cf2686b2c6ded (diff) |
style cleanup
Diffstat (limited to 'source/blender/compositor/operations/COM_DilateErodeOperation.cpp')
-rw-r--r-- | source/blender/compositor/operations/COM_DilateErodeOperation.cpp | 170 |
1 files changed, 85 insertions, 85 deletions
diff --git a/source/blender/compositor/operations/COM_DilateErodeOperation.cpp b/source/blender/compositor/operations/COM_DilateErodeOperation.cpp index bdd7362952a..17b043009ac 100644 --- a/source/blender/compositor/operations/COM_DilateErodeOperation.cpp +++ b/source/blender/compositor/operations/COM_DilateErodeOperation.cpp @@ -24,7 +24,7 @@ #include "BLI_math.h" // DilateErode Distance Threshold -DilateErodeThresholdOperation::DilateErodeThresholdOperation(): NodeOperation() +DilateErodeThresholdOperation::DilateErodeThresholdOperation() : NodeOperation() { this->addInputSocket(COM_DT_VALUE); this->addOutputSocket(COM_DT_VALUE); @@ -38,11 +38,11 @@ void DilateErodeThresholdOperation::initExecution() { this->inputProgram = this->getInputSocketReader(0); if (this->distance < 0.0f) { - this->scope = - this->distance + this->inset; + this->scope = -this->distance + this->inset; } else { - if (this->inset*2 > this->distance) { - this->scope = max(this->inset*2 - this->distance, this->distance); + if (this->inset * 2 > this->distance) { + this->scope = max(this->inset * 2 - this->distance, this->distance); } else { this->scope = distance; @@ -67,45 +67,45 @@ void DilateErodeThresholdOperation::executePixel(float *color, int x, int y, Mem float pixelvalue; const float rd = scope * scope; const float inset = this->inset; - float mindist = rd*2; + float mindist = rd * 2; - MemoryBuffer *inputBuffer = (MemoryBuffer*)data; + MemoryBuffer *inputBuffer = (MemoryBuffer *)data; float *buffer = inputBuffer->getBuffer(); rcti *rect = inputBuffer->getRect(); const int minx = max(x - scope, rect->xmin); const int miny = max(y - scope, rect->ymin); const int maxx = min(x + scope, rect->xmax); const int maxy = min(y + scope, rect->ymax); - const int bufferWidth = rect->xmax-rect->xmin; + const int bufferWidth = rect->xmax - rect->xmin; int offset; this->inputProgram->read(inputValue, x, y, inputBuffers, NULL); - if (inputValue[0]>sw) { - for (int yi = miny ; yi<maxy;yi++) { - offset = ((yi-rect->ymin)*bufferWidth+(minx-rect->xmin))*4; - for (int xi = minx ; xi<maxx;xi++) { - if (buffer[offset]<sw) { - const float dx = xi-x; - const float dy = yi-y; - const float dis = dx*dx+dy*dy; + if (inputValue[0] > sw) { + for (int yi = miny; yi < maxy; yi++) { + offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin)) * 4; + for (int xi = minx; xi < maxx; xi++) { + if (buffer[offset] < sw) { + const float dx = xi - x; + const float dy = yi - y; + const float dis = dx * dx + dy * dy; mindist = min(mindist, dis); } - offset +=4; + offset += 4; } } pixelvalue = -sqrtf(mindist); } else { - for (int yi = miny ; yi<maxy;yi++) { - offset = ((yi-rect->ymin)*bufferWidth+(minx-rect->xmin))*4; - for (int xi = minx ; xi<maxx;xi++) { - if (buffer[offset]>sw) { - const float dx = xi-x; - const float dy = yi-y; - const float dis = dx*dx+dy*dy; + for (int yi = miny; yi < maxy; yi++) { + offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin)) * 4; + for (int xi = minx; xi < maxx; xi++) { + if (buffer[offset] > sw) { + const float dx = xi - x; + const float dy = yi - y; + const float dis = dx * dx + dy * dy; mindist = min(mindist, dis); } - offset +=4; + offset += 4; } } @@ -119,7 +119,7 @@ void DilateErodeThresholdOperation::executePixel(float *color, int x, int y, Mem color[0] = 1.0f; } else { - color[0] = delta/inset; + color[0] = delta / inset; } } else { @@ -127,13 +127,13 @@ void DilateErodeThresholdOperation::executePixel(float *color, int x, int y, Mem } } else { - const float delta = -distance+pixelvalue; + const float delta = -distance + pixelvalue; if (delta < 0.0f) { if (delta < -inset) { color[0] = 1.0f; } else { - color[0] = (-delta)/inset; + color[0] = (-delta) / inset; } } else { @@ -160,7 +160,7 @@ bool DilateErodeThresholdOperation::determineDependingAreaOfInterest(rcti *input } // Dilate Distance -DilateDistanceOperation::DilateDistanceOperation(): NodeOperation() +DilateDistanceOperation::DilateDistanceOperation() : NodeOperation() { this->addInputSocket(COM_DT_VALUE); this->addOutputSocket(COM_DT_VALUE); @@ -189,28 +189,28 @@ void DilateDistanceOperation::executePixel(float *color, int x, int y, MemoryBuf const float distance = this->distance; float mindist = distance * distance; - MemoryBuffer *inputBuffer = (MemoryBuffer*)data; + MemoryBuffer *inputBuffer = (MemoryBuffer *)data; float *buffer = inputBuffer->getBuffer(); rcti *rect = inputBuffer->getRect(); const int minx = max(x - scope, rect->xmin); const int miny = max(y - scope, rect->ymin); const int maxx = min(x + scope, rect->xmax); const int maxy = min(y + scope, rect->ymax); - const int bufferWidth = rect->xmax-rect->xmin; + const int bufferWidth = rect->xmax - rect->xmin; int offset; float value = 0.0f; - for (int yi = miny ; yi<maxy;yi++) { - offset = ((yi-rect->ymin)*bufferWidth+(minx-rect->xmin))*4; - for (int xi = minx ; xi<maxx;xi++) { - const float dx = xi-x; - const float dy = yi-y; - const float dis = dx*dx+dy*dy; + for (int yi = miny; yi < maxy; yi++) { + offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin)) * 4; + for (int xi = minx; xi < maxx; xi++) { + const float dx = xi - x; + const float dy = yi - y; + const float dis = dx * dx + dy * dy; if (dis <= mindist) { value = max(buffer[offset], value); } - offset +=4; + offset += 4; } } color[0] = value; @@ -235,14 +235,14 @@ bool DilateDistanceOperation::determineDependingAreaOfInterest(rcti *input, Read static cl_kernel dilateKernel = 0; void DilateDistanceOperation::executeOpenCL(cl_context context, cl_program program, cl_command_queue queue, - MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, - MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, - list<cl_kernel> *clKernelsToCleanUp) + MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, + MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, + list<cl_kernel> *clKernelsToCleanUp) { if (!dilateKernel) { dilateKernel = COM_clCreateKernel(program, "dilateKernel", NULL); } - cl_int distanceSquared = this->distance*this->distance; + cl_int distanceSquared = this->distance * this->distance; cl_int scope = this->scope; COM_clAttachMemoryBufferToKernelParameter(context, dilateKernel, 0, 2, clMemToCleanUp, inputMemoryBuffers, this->inputProgram); @@ -264,28 +264,28 @@ void ErodeDistanceOperation::executePixel(float *color, int x, int y, MemoryBuff const float distance = this->distance; float mindist = distance * distance; - MemoryBuffer *inputBuffer = (MemoryBuffer*)data; + MemoryBuffer *inputBuffer = (MemoryBuffer *)data; float *buffer = inputBuffer->getBuffer(); rcti *rect = inputBuffer->getRect(); const int minx = max(x - scope, rect->xmin); const int miny = max(y - scope, rect->ymin); const int maxx = min(x + scope, rect->xmax); const int maxy = min(y + scope, rect->ymax); - const int bufferWidth = rect->xmax-rect->xmin; + const int bufferWidth = rect->xmax - rect->xmin; int offset; float value = 1.0f; - for (int yi = miny ; yi<maxy;yi++) { - offset = ((yi-rect->ymin)*bufferWidth+(minx-rect->xmin))*4; - for (int xi = minx ; xi<maxx;xi++) { - const float dx = xi-x; - const float dy = yi-y; - const float dis = dx*dx+dy*dy; + for (int yi = miny; yi < maxy; yi++) { + offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin)) * 4; + for (int xi = minx; xi < maxx; xi++) { + const float dx = xi - x; + const float dy = yi - y; + const float dis = dx * dx + dy * dy; if (dis <= mindist) { value = min(buffer[offset], value); } - offset +=4; + offset += 4; } } color[0] = value; @@ -293,14 +293,14 @@ void ErodeDistanceOperation::executePixel(float *color, int x, int y, MemoryBuff static cl_kernel erodeKernel = 0; void ErodeDistanceOperation::executeOpenCL(cl_context context, cl_program program, cl_command_queue queue, - MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, - MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, - list<cl_kernel> *clKernelsToCleanUp) + MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, + MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, + list<cl_kernel> *clKernelsToCleanUp) { if (!erodeKernel) { erodeKernel = COM_clCreateKernel(program, "erodeKernel", NULL); } - cl_int distanceSquared = this->distance*this->distance; + cl_int distanceSquared = this->distance * this->distance; cl_int scope = this->scope; COM_clAttachMemoryBufferToKernelParameter(context, erodeKernel, 0, 2, clMemToCleanUp, inputMemoryBuffers, this->inputProgram); @@ -313,7 +313,7 @@ void ErodeDistanceOperation::executeOpenCL(cl_context context, cl_program progra } // Dilate step -DilateStepOperation::DilateStepOperation(): NodeOperation() +DilateStepOperation::DilateStepOperation() : NodeOperation() { this->addInputSocket(COM_DT_VALUE); this->addOutputSocket(COM_DT_VALUE); @@ -334,37 +334,37 @@ void *DilateStepOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryB } lockMutex(); if (this->cached_buffer == NULL) { - MemoryBuffer *buffer = (MemoryBuffer*)inputProgram->initializeTileData(NULL, memoryBuffers); + MemoryBuffer *buffer = (MemoryBuffer *)inputProgram->initializeTileData(NULL, memoryBuffers); float *rectf = buffer->convertToValueBuffer(); int x, y, i; float *p; int bwidth = buffer->getWidth(); int bheight = buffer->getHeight(); - for (i = 0 ; i < this->iterations ; i ++) { - for (y=0; y < bheight; y++) { - for (x=0; x < bwidth-1; x++) { - p = rectf + (bwidth*y + x); + for (i = 0; i < this->iterations; i++) { + for (y = 0; y < bheight; y++) { + for (x = 0; x < bwidth - 1; x++) { + p = rectf + (bwidth * y + x); *p = MAX2(*p, *(p + 1)); } } - for (y=0; y < bheight; y++) { - for (x=bwidth-1; x >= 1; x--) { - p = rectf + (bwidth*y + x); + for (y = 0; y < bheight; y++) { + for (x = bwidth - 1; x >= 1; x--) { + p = rectf + (bwidth * y + x); *p = MAX2(*p, *(p - 1)); } } - for (x=0; x < bwidth; x++) { - for (y=0; y < bheight-1; y++) { - p = rectf + (bwidth*y + x); + for (x = 0; x < bwidth; x++) { + for (y = 0; y < bheight - 1; y++) { + p = rectf + (bwidth * y + x); *p = MAX2(*p, *(p + bwidth)); } } - for (x=0; x < bwidth; x++) { - for (y=bheight-1; y >= 1; y--) { - p = rectf + (bwidth*y + x); + for (x = 0; x < bwidth; x++) { + for (y = bheight - 1; y >= 1; y--) { + p = rectf + (bwidth * y + x); *p = MAX2(*p, *(p - bwidth)); } } @@ -378,7 +378,7 @@ void *DilateStepOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryB void DilateStepOperation::executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data) { - color[0] = this->cached_buffer[y*this->getWidth()+x]; + color[0] = this->cached_buffer[y * this->getWidth() + x]; } void DilateStepOperation::deinitExecution() @@ -409,7 +409,7 @@ bool DilateStepOperation::determineDependingAreaOfInterest(rcti *input, ReadBuff } // Erode step -ErodeStepOperation::ErodeStepOperation(): DilateStepOperation() +ErodeStepOperation::ErodeStepOperation() : DilateStepOperation() { } @@ -420,37 +420,37 @@ void *ErodeStepOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBu } lockMutex(); if (this->cached_buffer == NULL) { - MemoryBuffer *buffer = (MemoryBuffer*)inputProgram->initializeTileData(NULL, memoryBuffers); + MemoryBuffer *buffer = (MemoryBuffer *)inputProgram->initializeTileData(NULL, memoryBuffers); float *rectf = buffer->convertToValueBuffer(); int x, y, i; float *p; int bwidth = buffer->getWidth(); int bheight = buffer->getHeight(); - for (i = 0 ; i < this->iterations ; i ++) { - for (y=0; y < bheight; y++) { - for (x=0; x < bwidth-1; x++) { - p = rectf + (bwidth*y + x); + for (i = 0; i < this->iterations; i++) { + for (y = 0; y < bheight; y++) { + for (x = 0; x < bwidth - 1; x++) { + p = rectf + (bwidth * y + x); *p = MIN2(*p, *(p + 1)); } } - for (y=0; y < bheight; y++) { - for (x=bwidth-1; x >= 1; x--) { - p = rectf + (bwidth*y + x); + for (y = 0; y < bheight; y++) { + for (x = bwidth - 1; x >= 1; x--) { + p = rectf + (bwidth * y + x); *p = MIN2(*p, *(p - 1)); } } - for (x=0; x < bwidth; x++) { - for (y=0; y < bheight-1; y++) { - p = rectf + (bwidth*y + x); + for (x = 0; x < bwidth; x++) { + for (y = 0; y < bheight - 1; y++) { + p = rectf + (bwidth * y + x); *p = MIN2(*p, *(p + bwidth)); } } - for (x=0; x < bwidth; x++) { - for (y=bheight-1; y >= 1; y--) { - p = rectf + (bwidth*y + x); + for (x = 0; x < bwidth; x++) { + for (y = bheight - 1; y >= 1; y--) { + p = rectf + (bwidth * y + x); *p = MIN2(*p, *(p - bwidth)); } } |