--- pixelblending.org.c	Thu Mar 27 00:39:45 2003
+++ pixelblending.c	Thu Mar 27 00:52:23 2003
@@ -75,35 +75,22 @@
   ever. Strange thing is that colours keep overflowing...
 
 */
-void applyKeyAlphaCharCol(char* target) {
 
-	if ((!(target[3] == 0))
-		|| (target[3] == 255)) {
-		/* else: nothing to do */
-		/* check whether div-ing is enough */
-		float cf[4];
-		cf[0] = target[0]/target[3];
-		cf[1] = target[1]/target[3];
-		cf[2] = target[2]/target[3];
-		if ((cf[0] <= 1.0) && (cf[1] <= 1.0) && (cf[2] <= 1.0)) {
-			/* all colours remain properly scaled? */
-			/* scale to alpha */
-			cf[0] = (float) target[0] * (255.0/ (float)target[3]);
-			cf[1] = (float) target[1] * (255.0/ (float)target[3]);
-			cf[2] = (float) target[2] * (255.0/ (float)target[3]);
-
-			/* Clipping is important. */
-			target[0] = (cf[0] > 255.0 ? 255 : (char) cf[0]);
-			target[1] = (cf[1] > 255.0 ? 255 : (char) cf[1]);
-			target[2] = (cf[2] > 255.0 ? 255 : (char) cf[2]);
-			
+void applyKeyAlphaCharCol(unsigned char *target) {
+	int i, x;
+	unsigned char alpha = target[3];
+	if (!(alpha == 0 || alpha == 255)) {
+		if (target[0] <= alpha && target[1] <= alpha && target[2] <= alpha) {
+			for (i=0; i<3; i++) {
+				x = ((int) target[i]) * 255 / ((int) alpha);
+				target[i] = (x <= 255) ? x : 255;
+			}
 		} else {
 			/* shouldn't happen! we were premul, remember? */
-/* should go to error handler: 			printf("Non-premul colour detected\n"); */
+			fprintf(stderr, "appleKeyAlphaCharCol(): Non-premul colour detected\n");
 		}
 	}
-
-} /* end of void applyKeyAlphaCharCol(char* target) */
+} /* end of void applyKeyAlphaCharCol(unsigned char *target) */
 
 /* ------------------------------------------------------------------------- */
 
