shithub: riscv

Download patch

ref: fdf3883ce43eefe329c93494c32b7005a86759fb
parent: e9fddbaad81de8afbffe3f8ff626a18a551619df
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Sep 14 13:03:56 EDT 2014

libmemdraw: update drawtest to use same rounding in alpha calculation as libmemdraw

--- a/sys/src/libmemdraw/drawtest.c
+++ b/sys/src/libmemdraw/drawtest.c
@@ -974,7 +974,7 @@
 	pixtorgba(getpixel(dst, dp), &dr, &dg, &db, &da);
 	pixtorgba(getpixel(src, sp), &sr, &sg, &sb, &sa);
 	m = getmask(mask, mp);
-	M = 255-(sa*m)/255;
+	M = 255-(sa*m + 127)/255;
 
 DBG print("dst %x %x %x %x src %x %x %x %x m %x = ", dr,dg,db,da, sr,sg,sb,sa, m);
 	if(dst->flags&Fgrey){
@@ -985,18 +985,18 @@
 		 */
 		sk = RGB2K(sr, sg, sb);
 		dk = RGB2K(dr, dg, db);
-		dk = (sk*m + dk*M)/255;
+		dk = (sk*m + dk*M + 127)/255;
 		dr = dg = db = dk;
-		da = (sa*m + da*M)/255;
+		da = (sa*m + da*M + 127)/255;
 	}else{
 		/*
 		 * True color alpha calculation treats all channels (including alpha)
 		 * the same.  It might have been nice to use an array, but oh well.
 		 */
-		dr = (sr*m + dr*M)/255;
-		dg = (sg*m + dg*M)/255;
-		db = (sb*m + db*M)/255;
-		da = (sa*m + da*M)/255;
+		dr = (sr*m + dr*M + 127)/255;
+		dg = (sg*m + dg*M + 127)/255;
+		db = (sb*m + db*M + 127)/255;
+		da = (sa*m + da*M + 127)/255;
 	}
 
 DBG print("%x %x %x %x\n", dr,dg,db,da);