changeset 1474:529a65694e40

more optimization
author arpi
date Thu, 09 Aug 2001 20:07:45 +0000
parents e5e6c26c1aa1
children 1a4c9a7e9b67
files TOOLS/subfont-c/subfont.c
diffstat 1 files changed, 28 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/TOOLS/subfont-c/subfont.c	Thu Aug 09 18:40:06 2001 +0000
+++ b/TOOLS/subfont-c/subfont.c	Thu Aug 09 20:07:45 2001 +0000
@@ -55,6 +55,7 @@
 
 
 unsigned char	*buffer;
+unsigned char	*ebuffer; // temporary buffer for alphamap creation (edges)
 unsigned char	*abuffer;
 int		width, height;
 static FT_ULong	ustring[256];
@@ -252,6 +253,7 @@
     eprintf("bitmap size: %ix%i\n", width, height);
 
     buffer = (unsigned char*)malloc(width*height);
+    ebuffer = (unsigned char*)malloc(width*height);
     abuffer = (unsigned char*)malloc(width*height);
     if (buffer==NULL || abuffer==NULL) ERROR("malloc failed.",NULL);
 
@@ -358,15 +360,13 @@
 
     /* This is not a gaussian blur! */
     /* And is very slow */
-    for (y = 0; y<height; ++y){
-	for (x = 0; x<width; ++x) {
-	    float max = 0;
-	    for (my = -r; my<=r; ++my)
-		if (y+my>0 && y+my<height-1){
-		    int ay=(y+my)*width;
-		    for (mx = -r; mx<=r; ++mx) {
-			int ax=x+mx;
-			if (ax>0 && ax<width-1) {
+    
+    // PASS-1 : build edge mask:
+    memset(ebuffer,0,width*height); // clear
+    for (y = 1; y<height-1; ++y){
+	int ay=y*width;
+	int ax;
+	for (ax = 1; ax<width-1; ++ax) {
 			    int p =
 
 			  ( (buffer[ax-1+ay-width]) +
@@ -381,11 +381,25 @@
 
 			    (buffer[ax+ay]) ) ;
 			    
-			    max+=(p>255?255:p)*m[mx+r+(my+r)*w];
-			}
-		    
-		    }
+			    ebuffer[ax+ay]=(p>255)?255:p;
+	}
+//	printf("\n");
+    }
+
+    // PASS-2 : blur
+    for (y = 0; y<height; ++y){
+	for (x = 0; x<width; ++x) {
+	    float max = 0;
+	    for (my = -r; my<=r; ++my){
+		int ay=y+my;
+		if(ay>0 && ay<height){
+		    int by=r+(my+r)*w;
+		    ay*=width;
+		    for (mx = -r; mx<=r; ++mx)
+			if(x+mx>0 && x+mx<width)
+			    max+=ebuffer[x+mx+ay]*m[mx+by];
 		}
+	    }
 	    max*=alpha_factor/(float)sum;
 //	    printf("%5.3f ",max);
 	    if(max>255) max=255;
@@ -393,6 +407,7 @@
 	}
 //	printf("\n");
     }
+
     free(m);
 }