diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-05-31 15:58:14 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-05-31 15:58:14 +0400 |
commit | 3c194601f47f11f0d8f0c582f01901a089996619 (patch) | |
tree | afd788833650588dd493bd513e0c2d628f8c84dc | |
parent | efe289f3121f1eb9a7d85520cf5bfaeed88bcf50 (diff) | |
parent | ceea98be2f54ed72691a130ea8eed613726e4521 (diff) |
svn merge ^/trunk/blender -r47253:47272
-rw-r--r-- | source/blender/blenlib/BLI_math_vector.h | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector.c | 42 | ||||
-rw-r--r-- | source/blender/compositor/nodes/COM_DilateErodeNode.cpp | 20 | ||||
-rw-r--r-- | source/blender/compositor/nodes/COM_ImageNode.cpp | 1 | ||||
-rw-r--r-- | source/blender/compositor/operations/COM_DilateErodeOperation.cpp | 110 | ||||
-rw-r--r-- | source/blender/compositor/operations/COM_DilateErodeOperation.h | 41 | ||||
-rw-r--r-- | source/blender/editors/space_node/drawnode.c | 2 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_node_types.h | 5 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_nodetree.c | 5 |
9 files changed, 222 insertions, 8 deletions
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index 374da46a686..7ff52a5824f 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -228,8 +228,12 @@ void mul_vn_fl(float *array_tar, const int size, const float f); void mul_vn_vn_fl(float *array_tar, const float *array_src, const int size, const float f); void add_vn_vn(float *array_tar, const float *array_src, const int size); void add_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const int size); +void madd_vn_vn(float *array_tar, const float *array_src, const float f, const int size); +void madd_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const float f, const int size); void sub_vn_vn(float *array_tar, const float *array_src, const int size); void sub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const int size); +void msub_vn_vn(float *array_tar, const float *array_src, const float f, const int size); +void msub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const float f, const int size); void fill_vn_i(int *array_tar, const int size, const int val); void fill_vn_ushort(unsigned short *array_tar, const int size, const unsigned short val); void fill_vn_fl(float *array_tar, const int size, const float val); diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index 90e6a4cb945..d939576904e 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -550,6 +550,27 @@ void add_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_ } } +void madd_vn_vn(float *array_tar, const float *array_src, const float f, const int size) +{ + float *tar = array_tar + (size - 1); + const float *src = array_src + (size - 1); + int i = size; + while (i--) { + *(tar--) += *(src--) * f; + } +} + +void madd_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const float f, const int size) +{ + float *tar = array_tar + (size - 1); + const float *src_a = array_src_a + (size - 1); + const float *src_b = array_src_b + (size - 1); + int i = size; + while (i--) { + *(tar--) = *(src_a--) + (*(src_b--) * f); + } +} + void sub_vn_vn(float *array_tar, const float *array_src, const int size) { float *tar = array_tar + (size - 1); @@ -571,6 +592,27 @@ void sub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_ } } +void msub_vn_vn(float *array_tar, const float *array_src, const float f, const int size) +{ + float *tar = array_tar + (size - 1); + const float *src = array_src + (size - 1); + int i = size; + while (i--) { + *(tar--) -= *(src--) * f; + } +} + +void msub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const float f, const int size) +{ + float *tar = array_tar + (size - 1); + const float *src_a = array_src_a + (size - 1); + const float *src_b = array_src_b + (size - 1); + int i = size; + while (i--) { + *(tar--) = *(src_a--) - (*(src_b--) * f); + } +} + void fill_vn_i(int *array_tar, const int size, const int val) { int *tar = array_tar + (size - 1); diff --git a/source/blender/compositor/nodes/COM_DilateErodeNode.cpp b/source/blender/compositor/nodes/COM_DilateErodeNode.cpp index cc96f672ebd..b722e40a875 100644 --- a/source/blender/compositor/nodes/COM_DilateErodeNode.cpp +++ b/source/blender/compositor/nodes/COM_DilateErodeNode.cpp @@ -35,7 +35,7 @@ void DilateErodeNode::convertToOperations(ExecutionSystem *graph, CompositorCont { bNode *editorNode = this->getbNode(); - if (editorNode->custom1 == CMP_NODE_DILATEERODE_DISTANCE) { + if (editorNode->custom1 == CMP_NODE_DILATEERODE_DISTANCE_THRESH) { DilateErodeDistanceOperation *operation = new DilateErodeDistanceOperation(); operation->setDistance(editorNode->custom2); operation->setInset(editorNode->custom3); @@ -52,8 +52,22 @@ void DilateErodeNode::convertToOperations(ExecutionSystem *graph, CompositorCont this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0)); } graph->addOperation(operation); - } - else { + } else if (editorNode->custom1 == CMP_NODE_DILATEERODE_DISTANCE) { + if (editorNode->custom2 > 0) { + DilateDistanceOperation * operation = new DilateDistanceOperation(); + operation->setDistance(editorNode->custom2); + this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); + this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0)); + graph->addOperation(operation); + } + else { + ErodeDistanceOperation * operation = new ErodeDistanceOperation(); + operation->setDistance(-editorNode->custom2); + this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); + this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0)); + graph->addOperation(operation); + } + } else { if (editorNode->custom2 > 0) { DilateStepOperation * operation = new DilateStepOperation(); operation->setIterations(editorNode->custom2); diff --git a/source/blender/compositor/nodes/COM_ImageNode.cpp b/source/blender/compositor/nodes/COM_ImageNode.cpp index 5300d2deffc..7f14b068136 100644 --- a/source/blender/compositor/nodes/COM_ImageNode.cpp +++ b/source/blender/compositor/nodes/COM_ImageNode.cpp @@ -66,6 +66,7 @@ void ImageNode::convertToOperations(ExecutionSystem *graph, CompositorContext * ImageUser *imageuser = (ImageUser*)editorNode->storage; int framenumber = context->getFramenumber(); int numberOfOutputs = this->getNumberOfOutputSockets(); + BKE_image_user_frame_calc(imageuser, context->getFramenumber(), 0); /* force a load, we assume iuser index will be set OK anyway */ if (image && image->type==IMA_TYPE_MULTILAYER) { diff --git a/source/blender/compositor/operations/COM_DilateErodeOperation.cpp b/source/blender/compositor/operations/COM_DilateErodeOperation.cpp index a73f76030ab..7bc49fa695c 100644 --- a/source/blender/compositor/operations/COM_DilateErodeOperation.cpp +++ b/source/blender/compositor/operations/COM_DilateErodeOperation.cpp @@ -23,6 +23,7 @@ #include "COM_DilateErodeOperation.h" #include "BLI_math.h" +// DilateErode Distance Threshold DilateErodeDistanceOperation::DilateErodeDistanceOperation(): NodeOperation() { this->addInputSocket(COM_DT_VALUE); @@ -158,6 +159,115 @@ bool DilateErodeDistanceOperation::determineDependingAreaOfInterest(rcti *input, return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output); } +// Dilate Distance +DilateDistanceOperation::DilateDistanceOperation(): NodeOperation() +{ + this->addInputSocket(COM_DT_VALUE); + this->addOutputSocket(COM_DT_VALUE); + this->setComplex(true); + this->inputProgram = NULL; + this->distance = 0.0f; +} +void DilateDistanceOperation::initExecution() +{ + this->inputProgram = this->getInputSocketReader(0); + this->scope = distance; + if (scope < 3) { + scope = 3; + } +} + +void *DilateDistanceOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers) +{ + void *buffer = inputProgram->initializeTileData(NULL, memoryBuffers); + return buffer; +} + +void DilateDistanceOperation::executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data) +{ + const float distance = this->distance; + float mindist = distance * distance; + + 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; + 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; + if (dis <= mindist) { + value = max(buffer[offset], value); + } + offset +=4; + } + } + color[0] = value; +} + +void DilateDistanceOperation::deinitExecution() +{ + this->inputProgram = NULL; +} + +bool DilateDistanceOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) +{ + rcti newInput; + + newInput.xmax = input->xmax + scope; + newInput.xmin = input->xmin - scope; + newInput.ymax = input->ymax + scope; + newInput.ymin = input->ymin - scope; + + return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output); +} +// Erode Distance +ErodeDistanceOperation::ErodeDistanceOperation() : DilateDistanceOperation() +{ +} + +void ErodeDistanceOperation::executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data) +{ + const float distance = this->distance; + float mindist = distance * distance; + + 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; + 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; + if (dis <= mindist) { + value = min(buffer[offset], value); + } + offset +=4; + } + } + color[0] = value; +} + // Dilate step DilateStepOperation::DilateStepOperation(): NodeOperation() { diff --git a/source/blender/compositor/operations/COM_DilateErodeOperation.h b/source/blender/compositor/operations/COM_DilateErodeOperation.h index 7f01ea94494..71bbab74a4b 100644 --- a/source/blender/compositor/operations/COM_DilateErodeOperation.h +++ b/source/blender/compositor/operations/COM_DilateErodeOperation.h @@ -68,6 +68,47 @@ public: }; +class DilateDistanceOperation : public NodeOperation { +private: + /** + * Cached reference to the inputProgram + */ + SocketReader * inputProgram; +protected: + float distance; + int scope; +public: + DilateDistanceOperation(); + + /** + * the inner loop of this program + */ + void executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data); + + /** + * Initialize the execution + */ + void initExecution(); + + void *initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers); + /** + * Deinitialize the execution + */ + void deinitExecution(); + + void setDistance(float distance) {this->distance = distance;} + bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); +}; +class ErodeDistanceOperation : public DilateDistanceOperation { +public: + ErodeDistanceOperation(); + + /** + * the inner loop of this program + */ + void executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data); +}; + class DilateStepOperation : public NodeOperation { protected: /** diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 2db808e7a59..5c9f066937a 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -1641,7 +1641,7 @@ static void node_composit_buts_dilateerode(uiLayout *layout, bContext *UNUSED(C) { uiItemR(layout, ptr, "type", 0, NULL, ICON_NONE); uiItemR(layout, ptr, "distance", 0, NULL, ICON_NONE); - if (RNA_enum_get(ptr, "type") == CMP_NODE_DILATEERODE_DISTANCE) { + if (RNA_enum_get(ptr, "type") == CMP_NODE_DILATEERODE_DISTANCE_THRESH) { uiItemR(layout, ptr, "edge", 0, NULL, ICON_NONE); } } diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index d605e9ac38f..39f3fda1157 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -350,8 +350,9 @@ typedef struct bNodeSocketValueRGBA { #define CMP_NODE_LENSFLARE_CIRCLE 4 #define CMP_NODE_LENSFLARE_STREAKS 8 -#define CMP_NODE_DILATEERODE_STEP 0 -#define CMP_NODE_DILATEERODE_DISTANCE 1 +#define CMP_NODE_DILATEERODE_STEP 0 +#define CMP_NODE_DILATEERODE_DISTANCE_THRESH 1 +#define CMP_NODE_DILATEERODE_DISTANCE 2 typedef struct NodeFrame { short flag; diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 8604fa0ef31..1f574ba2473 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -1994,8 +1994,9 @@ static void def_cmp_dilate_erode(StructRNA *srna) PropertyRNA *prop; static EnumPropertyItem type_items[] = { - {CMP_NODE_DILATEERODE_STEP, "STEP", 0, "Step", ""}, - {CMP_NODE_DILATEERODE_DISTANCE, "DISTANCE", 0, "Distance", ""}, + {CMP_NODE_DILATEERODE_STEP, "STEP", 0, "Step", ""}, + {CMP_NODE_DILATEERODE_DISTANCE_THRESH, "THRESHOLD", 0, "Threshold", ""}, + {CMP_NODE_DILATEERODE_DISTANCE, "DISTANCE", 0, "Distance", ""}, {0, NULL, 0, NULL, NULL} }; |