[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47375] trunk/blender/source/blender/ compositor: minor optimizations to compositor, avoid indirections when operating array members multiple times

Campbell Barton ideasman42 at gmail.com
Sun Jun 3 18:23:58 CEST 2012


Revision: 47375
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47375
Author:   campbellbarton
Date:     2012-06-03 16:23:47 +0000 (Sun, 03 Jun 2012)
Log Message:
-----------
minor optimizations to compositor, avoid indirections when operating array members multiple times

Modified Paths:
--------------
    trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.cpp
    trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.h
    trunk/blender/source/blender/compositor/operations/COM_AlphaOverMixedOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_ColorSpillOperation.cpp

Modified: trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.cpp	2012-06-03 15:44:11 UTC (rev 47374)
+++ trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.cpp	2012-06-03 16:23:47 UTC (rev 47375)
@@ -73,12 +73,16 @@
 
 float *MemoryBuffer::convertToValueBuffer()
 {
-	int size = this->determineBufferSize();
-	int i;
-	int offset4;
+	const unsigned int size = this->determineBufferSize();
+	unsigned int i;
+
 	float *result = new float[size];
-	for (i = 0, offset4 = 0 ; i < size ; i ++, offset4 +=COM_NUMBER_OF_CHANNELS) {
-		result[i] = this->buffer[offset4];
+
+	const float *fp_src = this->buffer;
+	float       *fp_dst = result;
+
+	for (i = 0; i < size ; i++, fp_dst++, fp_src += COM_NUMBER_OF_CHANNELS) {
+		*fp_dst = *fp_src;
 	}
 
 	return result;
@@ -113,38 +117,31 @@
 	}
 }
 
-void MemoryBuffer::read(float *result, int x, int y)
+void MemoryBuffer::read(float result[4], int x, int y)
 {
 	if (x>=this->rect.xmin && x < this->rect.xmax &&
-			y>=this->rect.ymin && y < this->rect.ymax) {
-		int dx = x-this->rect.xmin;
-		int dy = y-this->rect.ymin;
-		int offset = (this->chunkWidth*dy+dx)*COM_NUMBER_OF_CHANNELS;
-		result[0] = this->buffer[offset];
-		result[1] = this->buffer[offset+1];
-		result[2] = this->buffer[offset+2];
-		result[3] = this->buffer[offset+3];
+	    y>=this->rect.ymin && y < this->rect.ymax)
+	{
+		const int dx = x - this->rect.xmin;
+		const int dy = y - this->rect.ymin;
+		const int offset = (this->chunkWidth * dy + dx) * COM_NUMBER_OF_CHANNELS;
+		copy_v4_v4(result, &this->buffer[offset]);
 	}
 	else {
-		result[0] = 0.0f;
-		result[1] = 0.0f;
-		result[2] = 0.0f;
-		result[3] = 0.0f;
+		zero_v4(result);
 	}
 }
-void MemoryBuffer::writePixel(int x, int y, float color[4])
+void MemoryBuffer::writePixel(int x, int y, const float color[4])
 {
-	if (x>=this->rect.xmin && x < this->rect.xmax &&
-			y>=this->rect.ymin && y < this->rect.ymax) {
-		int offset = (this->chunkWidth*y+x)*COM_NUMBER_OF_CHANNELS;
-		this->buffer[offset] = color[0];
-		this->buffer[offset+1] = color[1];
-		this->buffer[offset+2] = color[2];
-		this->buffer[offset+3] = color[3];
+	if (x >= this->rect.xmin && x < this->rect.xmax &&
+	    y >= this->rect.ymin && y < this->rect.ymax)
+	{
+		const int offset = (this->chunkWidth * y + x) * COM_NUMBER_OF_CHANNELS;
+		copy_v4_v4(&this->buffer[offset], color);
 	}
 }
 
-void MemoryBuffer::readCubic(float *result, float x, float y)
+void MemoryBuffer::readCubic(float result[4], float x, float y)
 {
 	int x1 = floor(x);
 	int x2 = x1 + 1;
@@ -266,9 +263,9 @@
 	return x;
 }
 
-void MemoryBuffer::readEWA(float *result, float fx, float fy, float dx, float dy)
+void MemoryBuffer::readEWA(float result[4], float fx, float fy, float dx, float dy)
 {
-	int width = this->getWidth(), height = this->getHeight();
+	const int width = this->getWidth(), height = this->getHeight();
 	
 	// scaling dxt/dyt by full resolution can cause overflow because of huge A/B/C and esp. F values,
 	// scaling by aspect ratio alone does the opposite, so try something in between instead...

Modified: trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.h
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.h	2012-06-03 15:44:11 UTC (rev 47374)
+++ trunk/blender/source/blender/compositor/intern/COM_MemoryBuffer.h	2012-06-03 16:23:47 UTC (rev 47375)
@@ -124,10 +124,10 @@
 		this->state = COM_MB_AVAILABLE;
 	}
 	
-	void read(float *result, int x, int y);
-	void writePixel(int x, int y, float color[4]);
-	void readCubic(float *result, float x, float y);
-	void readEWA(float *result, float fx, float fy, float dx, float dy);
+	void read(float result[4], int x, int y);
+	void writePixel(int x, int y, const float color[4]);
+	void readCubic(float result[4], float x, float y);
+	void readEWA(float result[4], float fx, float fy, float dx, float dy);
 	
 	/**
 	  * @brief is this MemoryBuffer a temporarily buffer (based on an area, not on a chunk)

Modified: trunk/blender/source/blender/compositor/operations/COM_AlphaOverMixedOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_AlphaOverMixedOperation.cpp	2012-06-03 15:44:11 UTC (rev 47374)
+++ trunk/blender/source/blender/compositor/operations/COM_AlphaOverMixedOperation.cpp	2012-06-03 16:23:47 UTC (rev 47375)
@@ -27,7 +27,7 @@
 	this->x = 0.0f;
 }
 
-void AlphaOverMixedOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
+void AlphaOverMixedOperation::executePixel(float outputValue[4], float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
 {
 	float inputColor1[4];
 	float inputOverColor[4];

Modified: trunk/blender/source/blender/compositor/operations/COM_ColorSpillOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_ColorSpillOperation.cpp	2012-06-03 15:44:11 UTC (rev 47374)
+++ trunk/blender/source/blender/compositor/operations/COM_ColorSpillOperation.cpp	2012-06-03 16:23:47 UTC (rev 47375)
@@ -40,40 +40,40 @@
 	this->inputImageReader = this->getInputSocketReader(0);
 	this->inputFacReader = this->getInputSocketReader(1);
 	if (spillChannel == 0) {
-		rmut = -1.0f;
-		gmut = 1.0f;
-		bmut = 1.0f;
+		this->rmut = -1.0f;
+		this->gmut = 1.0f;
+		this->bmut = 1.0f;
 		this->channel2 = 1;
 		this->channel3 = 2;
-		if (settings->unspill == 0) {
-			settings->uspillr = 1.0f;
-			settings->uspillg = 0.0f;
-			settings->uspillb = 0.0f;
+		if (this->settings->unspill == 0) {
+			this->settings->uspillr = 1.0f;
+			this->settings->uspillg = 0.0f;
+			this->settings->uspillb = 0.0f;
 		}
 	}
 	else if (spillChannel == 1) {
-		rmut = 1.0f;
-		gmut = -1.0f;
-		bmut = 1.0f;
+		this->rmut = 1.0f;
+		this->gmut = -1.0f;
+		this->bmut = 1.0f;
 		this->channel2 = 0;
 		this->channel3 = 2;
-		if (settings->unspill == 0) {
-			settings->uspillr = 0.0f;
-			settings->uspillg = 1.0f;
-			settings->uspillb = 0.0f;
+		if (this->settings->unspill == 0) {
+			this->settings->uspillr = 0.0f;
+			this->settings->uspillg = 1.0f;
+			this->settings->uspillb = 0.0f;
 		}
 	}
 	else {
-		rmut = 1.0f;
-		gmut = 1.0f;
-		bmut = -1.0f;
+		this->rmut = 1.0f;
+		this->gmut = 1.0f;
+		this->bmut = -1.0f;
 		
 		this->channel2 = 0;
 		this->channel3 = 1;
-		if (settings->unspill == 0) {
-			settings->uspillr = 0.0f;
-			settings->uspillg = 0.0f;
-			settings->uspillb = 1.0f;
+		if (this->settings->unspill == 0) {
+			this->settings->uspillr = 0.0f;
+			this->settings->uspillg = 0.0f;
+			this->settings->uspillb = 1.0f;
 		}
 	}
 }
@@ -88,27 +88,23 @@
 {
 	float fac[4];
 	float input[4];
-	float map;	
 	this->inputFacReader->read(fac, x, y, sampler, inputBuffers);
 	this->inputImageReader->read(input, x, y, sampler, inputBuffers);
 	float rfac = min(1.0f, fac[0]);
-	map = calculateMapValue(rfac, input);
-	if (map>0) {
-		outputValue[0]=input[0]+rmut*(settings->uspillr*map);
-		outputValue[1]=input[1]+gmut*(settings->uspillg*map);
-		outputValue[2]=input[2]+bmut*(settings->uspillb*map);
-		outputValue[3]=input[3];
+	float map = calculateMapValue(rfac, input);
+	if (map > 0.0f) {
+		outputValue[0] = input[0] + this->rmut * (this->settings->uspillr * map);
+		outputValue[1] = input[1] + this->gmut * (this->settings->uspillg * map);
+		outputValue[2] = input[2] + this->bmut * (this->settings->uspillb * map);
+		outputValue[3] = input[3];
 	}
 	else {
-		outputValue[0]=input[0];
-		outputValue[1]=input[1];
-		outputValue[2]=input[2];
-		outputValue[3]=input[3];
+		copy_v4_v4(outputValue, input);
 	}	
 }
 float ColorSpillOperation::calculateMapValue(float fac, float *input)
 {
-	return fac * (input[this->spillChannel]-(this->settings->limscale*input[settings->limchan]));
+	return fac * (input[this->spillChannel]-(this->settings->limscale*input[this->settings->limchan]));
 }
 
 




More information about the Bf-blender-cvs mailing list