summaryrefslogtreecommitdiff
path: root/sys/src/libmemdraw/draw.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2014-12-30 12:44:42 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2014-12-30 12:44:42 +0100
commit9f880e595c9b6a3bb606339f87ea9c6c2e368671 (patch)
tree7ffb4106c663f250877dbc8c8a58c38939a94c9c /sys/src/libmemdraw/draw.c
parent5935eeb6de5597072b083fadbcc3f9e94d1e36c1 (diff)
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.
Diffstat (limited to 'sys/src/libmemdraw/draw.c')
-rw-r--r--sys/src/libmemdraw/draw.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/sys/src/libmemdraw/draw.c b/sys/src/libmemdraw/draw.c
index 906949ac7..6ed2a242b 100644
--- a/sys/src/libmemdraw/draw.c
+++ b/sys/src/libmemdraw/draw.c
@@ -405,7 +405,7 @@ struct Buffer {
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 @@ DBG print("%x\n", w[-1]);
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 @@ writebyte(Param *p, uchar *w, Buffer src)
{
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 @@ writebyte(Param *p, uchar *w, Buffer src)
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 @@ readptr(Param *p, uchar *s, int y)
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 @@ genconv(Param *p, uchar *buf, int y)
}
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;