[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17394] trunk/blender/source/blender/imbuf /intern/imageprocess.c: bicubic_interpolation function was re-calculating a variable it didnt need to - (was calling 32 pow()'s per pixel, now only 8 - approx 3-4x speedup on my system).

Campbell Barton ideasman42 at gmail.com
Tue Nov 11 02:13:05 CET 2008


Revision: 17394
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17394
Author:   campbellbarton
Date:     2008-11-11 02:13:05 +0100 (Tue, 11 Nov 2008)

Log Message:
-----------
bicubic_interpolation function was re-calculating a variable it didnt need to - (was calling 32 pow()'s per pixel, now only 8 - approx 3-4x speedup on my system).

Modified Paths:
--------------
    trunk/blender/source/blender/imbuf/intern/imageprocess.c

Modified: trunk/blender/source/blender/imbuf/intern/imageprocess.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/imageprocess.c	2008-11-10 22:17:40 UTC (rev 17393)
+++ trunk/blender/source/blender/imbuf/intern/imageprocess.c	2008-11-11 01:13:05 UTC (rev 17394)
@@ -92,17 +92,13 @@
 /*  More info: http://wiki.blender.org/index.php/User:Damiles#Bicubic_pixel_interpolation
 */
 /* function assumes out to be zero'ed, only does RGBA */
-static float P(float k){
-	float aux;
-	aux=(float)(1.0f/6.0f)*( pow( MAX2(k+2.0f,0) , 3.0f ) - 4.0f * pow( MAX2(k+1.0f,0) , 3.0f ) + 6.0f * pow( MAX2(k,0) , 3.0f ) - 4.0f * pow( MAX2(k-1.0f,0) , 3.0f));
-	return aux ;
-}
+#define P(k) (float)(1.0f/6.0f)*( pow( MAX2((k)+2.0f,0) , 3.0f ) - 4.0f * pow( MAX2((k)+1.0f,0) , 3.0f ) + 6.0f * pow( MAX2((k),0) , 3.0f ) - 4.0f * pow( MAX2((k)-1.0f,0) , 3.0f))
 
 void bicubic_interpolation(ImBuf *in, ImBuf *out, float x, float y, int xout, int yout)
 {
 	int i,j,n,m,x1,y1;
 	unsigned char *dataI,*outI;
-	float a,b, outR,outG,outB,outA,*dataF,*outF;
+	float a,b,w, outR,outG,outB,outA,*dataF,*outF;
 	int do_rect, do_float;
 
 	if (in == NULL) return;
@@ -125,19 +121,20 @@
 			x1= i+n;
 			y1= j+m;
 			if (x1>0 && x1 < in->x && y1>0 && y1<in->y) {
+				w = P(n-a) * P(b-m);
 				if (do_float) {
 					dataF= in->rect_float + in->x * y1 * 4 + 4*x1;
-					outR+= dataF[0] * P(n-a) * P(b-m);
-					outG+= dataF[1] * P(n-a) * P(b-m);
-					outB+= dataF[2] * P(n-a) * P(b-m);
-					outA+= dataF[3] * P(n-a) * P(b-m);
+					outR+= dataF[0] * w;
+					outG+= dataF[1] * w;
+					outB+= dataF[2] * w;
+					outA+= dataF[3] * w;
 				}
 				if (do_rect) {
 					dataI= (unsigned char*)in->rect + in->x * y1 * 4 + 4*x1;
-					outR+= dataI[0] * P(n-a) * P(b-m);
-					outG+= dataI[1] * P(n-a) * P(b-m);
-					outB+= dataI[2] * P(n-a) * P(b-m);
-					outA+= dataI[3] * P(n-a) * P(b-m);
+					outR+= dataI[0] * w;
+					outG+= dataI[1] * w;
+					outB+= dataI[2] * w;
+					outA+= dataI[3] * w;
 				}
 			}
 		}





More information about the Bf-blender-cvs mailing list