shithub: sce

Download patch

ref: d9d02c1e3bfea2805a241fec8f6036389da47fb1
parent: d3ecaa35ddf467c0545c6c1bb10a5ceea356bc93
author: qwx <qwx@sciops.net>
date: Sat Oct 3 13:52:17 EDT 2020

drw: add alpha blending for ground glow effects

readjust color channels, generate correct images
don't load RGB24 pcx image as RGBA32

--- a/drw.c
+++ b/drw.c
@@ -165,6 +165,44 @@
 }
 
 static void
+drawpicalpha(int x, int y, Pic *pic)
+{
+	int n, Δp, Δq;
+	u8int k, a, b;
+	u32int o, A, B, *p, *e, *q;
+	Rectangle r;
+
+	if(pic->p == nil)
+		sysfatal("drawpic: empty pic");
+	q = pic->p;
+	r = Rect(x + pic->dx, y + pic->dy, pic->w, pic->h);
+	if(boundpic(&r, &q) < 0)
+		return;
+	Δq = pic->w - r.max.x / scale;
+	p = fb + r.min.y * fbws + r.min.x;
+	Δp = fbws - r.max.x;
+	while(r.max.y-- > 0){
+		e = p + r.max.x;
+		while(p < e){
+			A = *q++;
+			k = A >> 24;
+			B = *p;
+			for(n=0; n<24; n+=8){
+				a = A >> n;
+				b = B >> n;
+				o = k * (a - b);
+				o = (o + 1 + (o >> 8)) >> 8;
+				B = B & ~(0xff << n) | (o + b & 0xff) << n;
+			}
+			for(n=0; n<scale; n++)
+				*p++ = B;
+		}
+		q += Δq;
+		p += Δp;
+	}
+}
+
+static void
 drawshadow(int x, int y, Pic *pic)
 {
 	int n, Δp, Δq;
@@ -330,6 +368,20 @@
 				if(mo->o->f & Fair)
 					break;
 				drawpic(mo->px, mo->py, frm(mo, PTbase), addvis(mo));
+			}
+		}
+		m += mapwidth - (mr.max.x - mr.min.x);
+	}
+	for(y=mr.min.y, m=map+y*mapwidth+mr.min.x; y<mr.max.y; y++){
+		for(x=mr.min.x; x<mr.max.x; x++, m++){
+			for(ml=m->ml.l; ml!=&m->ml; ml=ml->l){
+				mo = ml->mo;
+				if(mo->o->f & Fair)
+					break;
+				if(mo->state != OSmove
+				|| mo->o->pics[OSmove][PTglow].pic == nil)
+					continue;
+				drawpicalpha(mo->px, mo->py, frm(mo, PTglow));
 			}
 		}
 		m += mapwidth - (mr.max.x - mr.min.x);
--- a/fs.c
+++ b/fs.c
@@ -66,7 +66,7 @@
 	if((i = readimage(display, fd, 0)) == nil)
 		sysfatal("readimage: %r");
 	close(fd);
-	if(alpha && i->chan != RGBA32 || !alpha && i->chan != RGB24)
+	if(alpha && i->chan != ARGB32 || !alpha && i->chan != RGB24)
 		sysfatal("loadpic %s: inappropriate image format", name);
 	dx = Dx(i->r);
 	dy = Dy(i->r);
@@ -85,7 +85,7 @@
 	while(n-- > 0){
 		v = s[2] << 16 | s[1] << 8 | s[0];
 		if(alpha)
-			v |= s[3] << 24; 
+			v |= s[3] << 24;
 		else if(v != bgcol)
 			v |= 0xff << 24;
 		*p++ = v;
--- a/utils/genspr
+++ b/utils/genspr
@@ -33,7 +33,7 @@
 			crop -t $3 $4 $1^.grp.^00^$n^.bit >a
 			mv a $1^.^$id($i)^.^`{echo $n | awk '{printf "%02d", ($1%17) / (32/'^$2^')}'}^.bit
 		}
-		scerot $1^.^$id($i) $2 r8g8b8a8
+		scerot $1^.^$id($i) $2 a8r8g8b8
 	}
 }
 
--- a/utils/grp.c
+++ b/utils/grp.c
@@ -82,8 +82,8 @@
 	if((im = readmemimage(fd)) == nil)
 		sysfatal("readmemimage: %r");
 	close(fd);
-	if(im->chan != RGBA32){
-		if((im1 = allocmemimage(im->r, RGBA32)) == nil)
+	if(im->chan != RGB24){
+		if((im1 = allocmemimage(im->r, RGB24)) == nil)
 			sysfatal("allocmemimage: %r");
 		memfillcolor(im1, DBlack);
 		memimagedraw(im1, im1->r, im, im->r.min, memopaque, ZP, S);
@@ -99,9 +99,9 @@
 		sysfatal("unloadmemimage: %r");
 	freememimage(im);
 	/* FIXME */
-	//for(i=0, p=pal, bp=buf; i<npal; i++, p++, bp+=256*4){
-	for(i=0, p=pal, bp=buf+20*4; i<npal; i++, p++, bp+=256*4){
-		v = bp[1] << 16 | bp[2]<<8 | bp[3];
+	//for(i=0, p=pal, bp=buf; i<npal; i++, p++, bp+=256*3){
+	for(i=0, p=pal, bp=buf+20*3; i<npal; i++, p++, bp+=256*3){
+		v = bp[0] << 24 | bp[1] << 16 | bp[2] << 8;
 		a = 0x7f;
 		switch(npal){
 		case 63:
@@ -116,7 +116,7 @@
 		case 1: break;
 		default: sysfatal("unknown palette size %d", npal);
 		}
-		*p = a<<24 | v;
+		*p = v | a;
 	}
 	free(buf);
 }
@@ -200,7 +200,7 @@
 	bufp = buf;
 	if(!split && (bo = Bfdopen(1, OWRITE)) == nil)
 		sysfatal("Bfdopen: %r");
-	chantostr(c, pcx ? RGBA32 : RGB24);
+	chantostr(c, pcx ? ARGB32 : RGB24);
 	for(hp=h; hp<h+ni; hp++){
 		if(split){
 			sprint(s, "%s.%05zd.bit", argv[1], hp-h);