diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-06-25 14:50:24 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-06-25 14:50:24 +0400 |
commit | 1755a0ada6a16f41a492739edbfc6c9ff8e51bc6 (patch) | |
tree | e6e643a39c6dd2f82a0a01269434eaebd83774f0 /source/blender/compositor/nodes/COM_KeyingNode.cpp | |
parent | 3c8a4c458bc66cfe54e83c00f2d4460a52e04535 (diff) |
Added feather control to keying node
Behaves in the same way as feather dilate/erode node, applies
after dilate/erode in node.
Also use distance dilate/erode instead of size.
Diffstat (limited to 'source/blender/compositor/nodes/COM_KeyingNode.cpp')
-rw-r--r-- | source/blender/compositor/nodes/COM_KeyingNode.cpp | 59 |
1 files changed, 54 insertions, 5 deletions
diff --git a/source/blender/compositor/nodes/COM_KeyingNode.cpp b/source/blender/compositor/nodes/COM_KeyingNode.cpp index d81092f21d7..be5fd773b60 100644 --- a/source/blender/compositor/nodes/COM_KeyingNode.cpp +++ b/source/blender/compositor/nodes/COM_KeyingNode.cpp @@ -40,6 +40,9 @@ #include "COM_SetAlphaOperation.h" +#include "COM_GaussianAlphaXBlurOperation.h" +#include "COM_GaussianAlphaYBlurOperation.h" + KeyingNode::KeyingNode(bNode *editorNode) : Node(editorNode) { /* pass */ @@ -116,15 +119,15 @@ OutputSocket *KeyingNode::setupPostBlur(ExecutionSystem *graph, OutputSocket *po OutputSocket *KeyingNode::setupDilateErode(ExecutionSystem *graph, OutputSocket *dilateErodeInput, int distance) { - DilateStepOperation *dilateErodeOperation; + DilateDistanceOperation *dilateErodeOperation; if (distance > 0) { - dilateErodeOperation = new DilateStepOperation(); - dilateErodeOperation->setIterations(distance); + dilateErodeOperation = new DilateDistanceOperation(); + dilateErodeOperation->setDistance(distance); } else { - dilateErodeOperation = new ErodeStepOperation(); - dilateErodeOperation->setIterations(-distance); + dilateErodeOperation = new ErodeDistanceOperation(); + dilateErodeOperation->setDistance(-distance); } addLink(graph, dilateErodeInput, dilateErodeOperation->getInputSocket(0)); @@ -134,6 +137,46 @@ OutputSocket *KeyingNode::setupDilateErode(ExecutionSystem *graph, OutputSocket return dilateErodeOperation->getOutputSocket(0); } +OutputSocket *KeyingNode::setupFeather(ExecutionSystem *graph, CompositorContext *context, + OutputSocket *featherInput, int falloff, int distance) +{ + /* this uses a modified gaussian blur function otherwise its far too slow */ + CompositorQuality quality = context->getQuality(); + + /* initialize node data */ + NodeBlurData *data = (NodeBlurData *)&this->alpha_blur; + memset(data, 0, sizeof(*data)); + data->filtertype = R_FILTER_GAUSS; + + if (distance > 0) { + data->sizex = data->sizey = distance; + } + else { + data->sizex = data->sizey = -distance; + } + + GaussianAlphaXBlurOperation *operationx = new GaussianAlphaXBlurOperation(); + operationx->setData(data); + operationx->setQuality(quality); + operationx->setSize(1.0f); + operationx->setSubtract(distance < 0); + operationx->setFalloff(falloff); + graph->addOperation(operationx); + + GaussianAlphaYBlurOperation *operationy = new GaussianAlphaYBlurOperation(); + operationy->setData(data); + operationy->setQuality(quality); + operationy->setSize(1.0f); + operationy->setSubtract(distance < 0); + operationy->setFalloff(falloff); + graph->addOperation(operationy); + + addLink(graph, featherInput, operationx->getInputSocket(0)); + addLink(graph, operationx->getOutputSocket(), operationy->getInputSocket(0)); + + return operationy->getOutputSocket(); +} + OutputSocket *KeyingNode::setupDespill(ExecutionSystem *graph, OutputSocket *despillInput, OutputSocket *inputScreen, float factor) { KeyingDespillOperation *despillOperation = new KeyingDespillOperation(); @@ -225,6 +268,12 @@ void KeyingNode::convertToOperations(ExecutionSystem *graph, CompositorContext * postprocessedMatte = setupDilateErode(graph, postprocessedMatte, keying_data->dilate_distance); } + /* matte feather */ + if (keying_data->feather_distance != 0) { + postprocessedMatte = setupFeather(graph, context, postprocessedMatte, keying_data->feather_falloff, + keying_data->feather_distance); + } + /* set alpha channel to output image */ SetAlphaOperation *alphaOperation = new SetAlphaOperation(); addLink(graph, originalImage, alphaOperation->getInputSocket(0)); |