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.
This commit is contained in:
parent
5935eeb6de
commit
9f880e595c
|
@ -405,7 +405,7 @@ struct Buffer {
|
||||||
uchar *red;
|
uchar *red;
|
||||||
uchar *grn;
|
uchar *grn;
|
||||||
uchar *blu;
|
uchar *blu;
|
||||||
uchar *alpha;
|
uchar *alpha; /* is &ones when unused, never nil */
|
||||||
uchar *grey;
|
uchar *grey;
|
||||||
ulong *rgba;
|
ulong *rgba;
|
||||||
int delta; /* number of bytes to add to pointer to get next pixel to the right */
|
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.grey = buf+copyalpha;
|
||||||
b.red = b.grn = b.blu = buf+copyalpha;
|
b.red = b.grn = b.blu = buf+copyalpha;
|
||||||
b.delta = copyalpha+1;
|
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{
|
}else{
|
||||||
b.blu = buf+copyalpha;
|
b.blu = buf+copyalpha;
|
||||||
b.grn = buf+copyalpha+1;
|
b.grn = buf+copyalpha+1;
|
||||||
|
@ -1695,7 +1695,7 @@ writebyte(Param *p, uchar *w, Buffer src)
|
||||||
{
|
{
|
||||||
Memimage *img;
|
Memimage *img;
|
||||||
int i, isalpha, isgrey, nb, delta, dx, adelta;
|
int i, isalpha, isgrey, nb, delta, dx, adelta;
|
||||||
uchar ff, *red, *grn, *blu, *grey, *alpha;
|
uchar *red, *grn, *blu, *grey, *alpha;
|
||||||
ulong u, mask;
|
ulong u, mask;
|
||||||
|
|
||||||
img = p->img;
|
img = p->img;
|
||||||
|
@ -1714,11 +1714,8 @@ writebyte(Param *p, uchar *w, Buffer src)
|
||||||
isgrey = img->flags&Fgrey;
|
isgrey = img->flags&Fgrey;
|
||||||
adelta = src.delta;
|
adelta = src.delta;
|
||||||
|
|
||||||
if(isalpha && (alpha == nil || alpha == &ones)){
|
if(isalpha && alpha == &ones)
|
||||||
ff = 0xFF;
|
|
||||||
alpha = &ff;
|
|
||||||
adelta = 0;
|
adelta = 0;
|
||||||
}
|
|
||||||
|
|
||||||
if((img->flags&Fbytes) != 0){
|
if((img->flags&Fbytes) != 0){
|
||||||
int ogry, ored, ogrn, oblu, oalp;
|
int ogry, ored, ogrn, oblu, oalp;
|
||||||
|
@ -1829,7 +1826,8 @@ readptr(Param *p, uchar *s, int y)
|
||||||
USED(s);
|
USED(s);
|
||||||
q = p->bytermin + y*p->bwidth;
|
q = p->bytermin + y*p->bwidth;
|
||||||
b.red = q; /* ptr to data */
|
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.rgba = (ulong*)q;
|
||||||
b.delta = p->img->depth/8;
|
b.delta = p->img->depth/8;
|
||||||
return b;
|
return b;
|
||||||
|
@ -1947,7 +1945,8 @@ genconv(Param *p, uchar *buf, int y)
|
||||||
}
|
}
|
||||||
|
|
||||||
b.red = buf;
|
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.rgba = (ulong*)buf;
|
||||||
b.delta = 0;
|
b.delta = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue