[Bf-blender-cvs] [4c9587d] master: Optimization of keying clip operations

Sergey Sharybin noreply at git.blender.org
Fri May 23 16:09:02 CEST 2014


Commit: 4c9587d7540a2da133918719428f275785790aa6
Author: Sergey Sharybin
Date:   Fri May 23 16:02:45 2014 +0200
https://developer.blender.org/rB4c9587d7540a2da133918719428f275785790aa6

Optimization of keying clip operations

Gives around 20%-30% speedup by doing early exit from
kernel traversal cycle.

===================================================================

M	source/blender/compositor/operations/COM_KeyingClipOperation.cpp

===================================================================

diff --git a/source/blender/compositor/operations/COM_KeyingClipOperation.cpp b/source/blender/compositor/operations/COM_KeyingClipOperation.cpp
index 909eeed..da6a94f 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;




More information about the Bf-blender-cvs mailing list