diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-06-25 12:21:55 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-06-25 12:21:55 +0400 |
commit | 44c82198d4852484493c2e33b3ca4ad67fd76fd8 (patch) | |
tree | 4bf2bc23d6034647e0006dfb0c0d2f25f0eb951c /source/blender/compositor/operations/COM_KeyingBlurOperation.cpp | |
parent | 15cb064e1b853a56fc676db1c2869db47657d91a (diff) |
Optimization of Keying Blur operation
Separate X and Y passes of blurring like it's done for flat
gaussian blur. This reduces computing difficulty from size^2
to 2*size without any visual changes in matte.
Diffstat (limited to 'source/blender/compositor/operations/COM_KeyingBlurOperation.cpp')
-rw-r--r-- | source/blender/compositor/operations/COM_KeyingBlurOperation.cpp | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/source/blender/compositor/operations/COM_KeyingBlurOperation.cpp b/source/blender/compositor/operations/COM_KeyingBlurOperation.cpp index fd80b6b5ccf..eb956403e1f 100644 --- a/source/blender/compositor/operations/COM_KeyingBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_KeyingBlurOperation.cpp @@ -33,7 +33,8 @@ KeyingBlurOperation::KeyingBlurOperation() : NodeOperation() this->addInputSocket(COM_DT_VALUE); this->addOutputSocket(COM_DT_VALUE); - this->size = 0.0f; + this->size = 0; + this->axis = 0; this->setComplex(true); } @@ -53,16 +54,28 @@ void KeyingBlurOperation::executePixel(float *color, int x, int y, MemoryBuffer int bufferWidth = inputBuffer->getWidth(); int bufferHeight = inputBuffer->getHeight(); - int i, j, count = 0; + int i, count = 0; float average = 0.0f; - for (i = -this->size + 1; i < this->size; i++) { - for (j = -this->size + 1; j < this->size; j++) { - int cx = x + j, cy = y + i; + if (this->axis == 0) { + for (i = -this->size + 1; i < this->size; i++) { + int cx = x + i; - if (cx >= 0 && cx < bufferWidth && cy >= 0 && cy < bufferHeight) { - int bufferIndex = (cy * bufferWidth + cx) * 4; + if (cx >= 0 && cx < bufferWidth) { + int bufferIndex = (y * bufferWidth + cx) * 4; + + average += buffer[bufferIndex]; + count++; + } + } + } + else { + for (i = -this->size + 1; i < this->size; i++) { + int cy = y + i; + + if (cy >= 0 && cy < bufferHeight) { + int bufferIndex = (cy * bufferWidth + x) * 4; average += buffer[bufferIndex]; count++; @@ -79,10 +92,18 @@ bool KeyingBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBuff { rcti newInput; - newInput.xmin = input->xmin - this->size; - newInput.ymin = input->ymin - this->size; - newInput.xmax = input->xmax + this->size; - newInput.ymax = input->ymax + this->size; + if (this->axis == 0) { + newInput.xmin = input->xmin - this->size; + newInput.ymin = input->ymin; + newInput.xmax = input->xmax + this->size; + newInput.ymax = input->ymax; + } + else { + newInput.xmin = input->xmin; + newInput.ymin = input->ymin - this->size; + newInput.xmax = input->xmax; + newInput.ymax = input->ymax + this->size; + } return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output); } |