Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-06-16 18:40:16 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-06-16 18:40:16 +0400
commit6fc277c410d5ee4d13562e4b8b260bc0929f30f5 (patch)
tree5c7af757a8ae2c4d55fed565ef058843fef05209 /source/blender/compositor/operations
parente946fa443b5aab057bfe5f40f8bb4f346c84331e (diff)
support for negative feather dilate/erode
Diffstat (limited to 'source/blender/compositor/operations')
-rw-r--r--source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp16
-rw-r--r--source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h6
-rw-r--r--source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp12
-rw-r--r--source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h6
4 files changed, 32 insertions, 8 deletions
diff --git a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp b/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp
index 4a3fa7d5c12..5c6e0e4adac 100644
--- a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp
+++ b/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp
@@ -81,8 +81,14 @@ void GaussianAlphaXBlurOperation::updateGauss(MemoryBuffer **memoryBuffers)
}
}
+BLI_INLINE float finv_test(const float f, const bool test)
+{
+ return (LIKELY(test == false)) ? f : 1.0f - f;
+}
+
void GaussianAlphaXBlurOperation::executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data)
{
+ const bool do_invert = this->do_subtract;
MemoryBuffer *inputBuffer = (MemoryBuffer *)data;
float *buffer = inputBuffer->getBuffer();
int bufferwidth = inputBuffer->getWidth();
@@ -108,12 +114,12 @@ void GaussianAlphaXBlurOperation::executePixel(float *color, int x, int y, Memor
float overallmultiplyer = 0.0f;
/* dilate */
- float value_max = buffer[(x * 4) + (y * 4 * bufferwidth)]; /* init with the current color to avoid unneeded lookups */
+ float value_max = finv_test(buffer[(x * 4) + (y * 4 * bufferwidth)], do_invert); /* init with the current color to avoid unneeded lookups */
float distfacinv_max = 1.0f; /* 0 to 1 */
for (int nx = minx; nx < maxx; nx += step) {
const int index = (nx - x) + this->rad;
- float value = buffer[bufferindex];
+ float value = finv_test(buffer[bufferindex], do_invert);
float multiplyer;
/* gauss */
@@ -131,7 +137,7 @@ void GaussianAlphaXBlurOperation::executePixel(float *color, int x, int y, Memor
multiplyer = distbuf_inv[index];
#endif
value *= multiplyer;
- if ((value > value_max) == TRUE) {
+ if (value > value_max) {
value_max = value;
distfacinv_max = multiplyer;
}
@@ -143,7 +149,7 @@ void GaussianAlphaXBlurOperation::executePixel(float *color, int x, int y, Memor
/* blend between the max value and gauss blue - gives nice feather */
const float value_gauss = tempColor / overallmultiplyer;
const float value_final = (value_max * distfacinv_max) + (value_gauss * (1.0f - distfacinv_max));
- color[0] = value_final;
+ color[0] = finv_test(value_final, do_invert);
}
void GaussianAlphaXBlurOperation::deinitExecution()
@@ -164,7 +170,7 @@ bool GaussianAlphaXBlurOperation::determineDependingAreaOfInterest(rcti *input,
sizeInput.ymin = 0;
sizeInput.xmax = 5;
sizeInput.ymax = 5;
-
+
NodeOperation *operation = this->getInputOperation(1);
if (operation->determineDependingAreaOfInterest(&sizeInput, readOperation, output)) {
return true;
diff --git a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h b/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h
index 2b5e4d33673..3268e51be01 100644
--- a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h
+++ b/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h
@@ -30,6 +30,7 @@ class GaussianAlphaXBlurOperation : public BlurBaseOperation {
private:
float *gausstab;
float *distbuf_inv;
+ bool do_subtract;
int rad;
void updateGauss(MemoryBuffer **memoryBuffers);
public:
@@ -52,5 +53,10 @@ public:
void *initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers);
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
+
+ /**
+ * Set subtract for Dilate/Erode functionality
+ */
+ void setSubtract(bool subtract) { this->do_subtract = subtract; }
};
#endif
diff --git a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp b/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp
index f84f4e3b094..40f74ad4485 100644
--- a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp
+++ b/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp
@@ -79,8 +79,14 @@ void GaussianAlphaYBlurOperation::updateGauss(MemoryBuffer **memoryBuffers)
}
}
+BLI_INLINE float finv_test(const float f, const bool test)
+{
+ return (LIKELY(test == false)) ? f : 1.0f - f;
+}
+
void GaussianAlphaYBlurOperation::executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data)
{
+ const bool do_invert = this->do_subtract;
MemoryBuffer *inputBuffer = (MemoryBuffer *)data;
float *buffer = inputBuffer->getBuffer();
int bufferwidth = inputBuffer->getWidth();
@@ -104,14 +110,14 @@ void GaussianAlphaYBlurOperation::executePixel(float *color, int x, int y, Memor
float overallmultiplyer = 0.0f;
/* dilate */
- float value_max = buffer[(x * 4) + (y * 4 * bufferwidth)]; /* init with the current color to avoid unneeded lookups */
+ float value_max = finv_test(buffer[(x * 4) + (y * 4 * bufferwidth)], do_invert); /* init with the current color to avoid unneeded lookups */
float distfacinv_max = 1.0f; /* 0 to 1 */
for (int ny = miny; ny < maxy; ny += step) {
int bufferindex = ((minx - bufferstartx) * 4) + ((ny - bufferstarty) * 4 * bufferwidth);
const int index = (ny - y) + this->rad;
- float value = buffer[bufferindex];
+ float value = finv_test(buffer[bufferindex], do_invert);
float multiplyer;
/* gauss */
@@ -140,7 +146,7 @@ void GaussianAlphaYBlurOperation::executePixel(float *color, int x, int y, Memor
/* blend between the max value and gauss blue - gives nice feather */
const float value_gauss = tempColor / overallmultiplyer;
const float value_final = (value_max * distfacinv_max) + (value_gauss * (1.0f - distfacinv_max));
- color[0] = value_final;
+ color[0] = finv_test(value_final, do_invert);
}
void GaussianAlphaYBlurOperation::deinitExecution()
diff --git a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h b/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h
index 830f9b35c30..0ffc264ba98 100644
--- a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h
+++ b/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h
@@ -30,6 +30,7 @@ class GaussianAlphaYBlurOperation : public BlurBaseOperation {
private:
float *gausstab;
float *distbuf_inv;
+ bool do_subtract;
int rad;
void updateGauss(MemoryBuffer **memoryBuffers);
public:
@@ -52,5 +53,10 @@ public:
void *initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers);
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
+
+ /**
+ * Set subtract for Dilate/Erode functionality
+ */
+ void setSubtract(bool subtract) { this->do_subtract = subtract; }
};
#endif