shithub: riscv

Download patch

ref: 9f880e595c9b6a3bb606339f87ea9c6c2e368671
parent: 5935eeb6de5597072b083fadbcc3f9e94d1e36c1
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Dec 30 07:44:42 EST 2014

libmemdraw: never point Buffer.alpha to nil (thanks mischief)

the boolcopy optimization doesnt doesnt use Buffer.alpha, tho
the debug function dumpbuf() still can dereference it. to keep
it simple, always have Buffer.alpha point to the channel or
&ones when not used.

--- a/sys/src/libmemdraw/draw.c
+++ b/sys/src/libmemdraw/draw.c
@@ -405,7 +405,7 @@
 	uchar	*red;
 	uchar	*grn;
 	uchar	*blu;
-	uchar	*alpha;
+	uchar	*alpha;	/* is &ones when unused, never nil */
 	uchar	*grey;
 	ulong	*rgba;
 	int	delta;	/* number of bytes to add to pointer to get next pixel to the right */
@@ -1677,7 +1677,7 @@
 		b.grey = buf+copyalpha;
 		b.red = b.grn = b.blu = buf+copyalpha;
 		b.delta = copyalpha+1;
-DBG print("alpha %x grey %x\n", b.alpha ? *b.alpha : 0xFF, *b.grey);
+DBG print("alpha %x grey %x\n", *b.alpha, *b.grey);
 	}else{
 		b.blu = buf+copyalpha;
 		b.grn = buf+copyalpha+1;
@@ -1695,7 +1695,7 @@
 {
 	Memimage *img;
 	int i, isalpha, isgrey, nb, delta, dx, adelta;
-	uchar ff, *red, *grn, *blu, *grey, *alpha;
+	uchar *red, *grn, *blu, *grey, *alpha;
 	ulong u, mask;
 
 	img = p->img;
@@ -1714,11 +1714,8 @@
 	isgrey = img->flags&Fgrey;
 	adelta = src.delta;
 
-	if(isalpha && (alpha == nil || alpha == &ones)){
-		ff = 0xFF;
-		alpha = &ff;
+	if(isalpha && alpha == &ones)
 		adelta = 0;
-	}
 
 	if((img->flags&Fbytes) != 0){
 		int ogry, ored, ogrn, oblu, oalp;
@@ -1829,7 +1826,8 @@
 	USED(s);
 	q = p->bytermin + y*p->bwidth;
 	b.red = q;	/* ptr to data */
-	b.grn = b.blu = b.grey = b.alpha = nil;
+	b.grn = b.blu = b.grey = nil;
+	b.alpha = &ones;
 	b.rgba = (ulong*)q;
 	b.delta = p->img->depth/8;
 	return b;
@@ -1947,7 +1945,8 @@
 	}
 
 	b.red = buf;
-	b.blu = b.grn = b.grey = b.alpha = nil;
+	b.blu = b.grn = b.grey = nil;
+	b.alpha = &ones;
 	b.rgba = (ulong*)buf;
 	b.delta = 0;