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:
authorSergey Sharybin <sergey.vfx@gmail.com>2014-05-23 18:02:45 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2014-05-23 18:02:45 +0400
commit4c9587d7540a2da133918719428f275785790aa6 (patch)
tree81a0595b1cc5636de6028c100aa1d2c60aa4cf5d /source/blender/compositor
parent56b7d558336a328dec76d180b6fff55a80b93903 (diff)
Optimization of keying clip operations
Gives around 20%-30% speedup by doing early exit from kernel traversal cycle.
Diffstat (limited to 'source/blender/compositor')
-rw-r--r--source/blender/compositor/operations/COM_KeyingClipOperation.cpp31
1 files changed, 16 insertions, 15 deletions
diff --git a/source/blender/compositor/operations/COM_KeyingClipOperation.cpp b/source/blender/compositor/operations/COM_KeyingClipOperation.cpp
index 909eeed8937..da6a94f8813 100644
--- a/source/blender/compositor/operations/COM_KeyingClipOperation.cpp
+++ b/source/blender/compositor/operations/COM_KeyingClipOperation.cpp
@@ -62,34 +62,35 @@ void KeyingClipOperation::executePixel(float output[4], int x, int y, void *data
int bufferWidth = inputBuffer->getWidth();
int bufferHeight = inputBuffer->getHeight();
- int i, j, count = 0, totalCount = 0;
-
float value = buffer[(y * bufferWidth + x) * 4];
bool ok = false;
+ int start_x = max_ff(0, x - delta + 1),
+ start_y = max_ff(0, y - delta + 1),
+ end_x = min_ff(x + delta - 1, bufferWidth - 1),
+ end_y = min_ff(y + delta - 1, bufferHeight - 1);
- for (i = -delta + 1; i < delta; i++) {
- for (j = -delta + 1; j < delta; j++) {
- int cx = x + j, cy = y + i;
+ int count = 0, totalCount = (end_x - start_x + 1) * (end_y - start_y + 1) - 1;
+ int thresholdCount = (float) totalCount * 0.9f + 0.5f;
- if (i == 0 && j == 0)
+ for (int cx = start_x; ok == false && cx <= end_x; ++cx) {
+ for (int cy = start_y; ok == false && cy <= end_y; ++cy) {
+ if (UNLIKELY(cx == x && cy == y)) {
continue;
+ }
- if (cx >= 0 && cx < bufferWidth && cy >= 0 && cy < bufferHeight) {
- int bufferIndex = (cy * bufferWidth + cx) * 4;
- float currentValue = buffer[bufferIndex];
+ int bufferIndex = (cy * bufferWidth + cx) * 4;
+ float currentValue = buffer[bufferIndex];
- if (fabsf(currentValue - value) < tolerance) {
- count++;
+ if (fabsf(currentValue - value) < tolerance) {
+ count++;
+ if (count >= thresholdCount) {
+ ok = true;
}
-
- totalCount++;
}
}
}
- ok = count >= (float) totalCount * 0.9f;
-
if (this->m_isEdgeMatte) {
if (ok)
output[0] = 0.0f;