shithub: qk1

Download patch

ref: a1da754ee85d9f5b17f6f67a61945f4994565c9b
parent: a83a58dac35a9723d02f7b36361f07f41ace5cde
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Oct 16 18:12:42 EDT 2023

build an alpha map for each new alpha value

--- a/d_scan.c
+++ b/d_scan.c
@@ -66,8 +66,7 @@
 	}
 }
 
-static byte *alphamap;
-static byte mapalpha;
+static byte *alphamap[256];
 
 static void
 buildalpha(int alpha)
@@ -75,38 +74,38 @@
 	extern s32int fbpal[256];
 	int a, b;
 	byte *ca, *cb, *p;
-	int r0, g0, b0;
-	int r1, g1, b1;
 	int rr, gg, bb;
 	int i, dst, x, best;
 
-	if(alphamap == nil)
-		alphamap = malloc(256*256);
-	for(a = 0; a < 256; a++){
-		ca = (byte*)&fbpal[a];
-		r0 = ca[0]; g0 = ca[1]; b0 = ca[2];
-		for(b = 0; b < 256; b++){
-				cb = (byte*)&fbpal[b];
-				r1 = cb[0]; g1 = cb[1]; b1 = cb[2];
-				rr = (alpha*r0 + (255 - alpha)*r1)/255;
-				gg = (alpha*g0 + (255 - alpha)*g1)/255;
-				bb = (alpha*b0 + (255 - alpha)*b1)/255;
-				dst = 9999999;
-				best = 255;
-				p = (byte*)fbpal;
-				for(i = 0; i < 768; i += 4){
-					if((x = (rr-p[i])*(rr-p[i])+(gg-p[i+1])*(gg-p[i+1])+(bb-p[i+2])*(bb-p[i+2])) < dst){
+	if(alphamap[alpha] != nil)
+		return;
+	alphamap[alpha] = malloc(256*256);
+	p = (byte*)fbpal;
+	ca = p;
+	for(a = 0; a < 256; a++, ca += 4){
+		cb = p;
+		for(b = 0; b < 256; b++, cb++){
+			rr = (alpha*ca[0] + (255 - alpha)*(*cb++))>>8;
+			gg = (alpha*ca[1] + (255 - alpha)*(*cb++))>>8;
+			bb = (alpha*ca[2] + (255 - alpha)*(*cb++))>>8;
+			dst = 9999999;
+			best = 255;
+			for(i = 0; i < 768; i += 4){
+				x = (rr-p[i+0])*(rr-p[i+0]) +
+					(gg-p[i+1])*(gg-p[i+1]) +
+					(bb-p[i+2])*(bb-p[i+2]);
+				if(x < dst){
 					dst = x;
 					best = i;
 				}
-				alphamap[a<<8 | b] = best/4;
 			}
+			alphamap[alpha][a<<8 | b] = best/4;
 		}
 	}
 }
 
 #define blendalpha(a, b, alpha) \
-	alphamap[(u16int)((a)<<8 | (b))]
+	alphamap[alpha][(u16int)((a)<<8 | (b))]
 
 /*
 =============
@@ -161,12 +160,8 @@
 	zi16stepu = d_zistepu * 16;
 	alpha = clamp(alpha, 0.0, 1.0);
 	balpha = alpha * 255;
+	buildalpha(balpha);
 
-	if(balpha != 255 && (alphamap == nil || balpha != mapalpha)){
-		mapalpha = balpha;
-		buildalpha(balpha);
-	}
-
 	do
 	{
 		r_turb_pdest = (unsigned char *)((byte *)d_viewbuffer +
@@ -446,6 +441,7 @@
 	float			sdivz, tdivz, zi, z, du, dv, spancountminus1;
 	float			sdivzstepu, tdivzstepu, zistepu;
 
+	USED(alpha);
 	sstep = 0;	// keep compiler happy
 	tstep = 0;	// ditto
 
--- a/qk1.c
+++ b/qk1.c
@@ -5,7 +5,7 @@
 #include "quakedef.h"
 #include "fns.h"
 
-int mainstacksize = 4*1024*1024;
+int mainstacksize = 1*1024*1024;
 char *netmtpt = "/net";
 char *game;
 int debug;