From e2be28f92556249cae3f610042f5593c88af58bc Mon Sep 17 00:00:00 2001
From: Rachael Alexanderson <eruanna@drdteam.org>
Date: Mon, 19 Dec 2016 04:27:56 -0500
Subject: [PATCH] - implemented RGB256k for screen crossfade and burn

---
 src/f_wipe.cpp | 27 +++++++++++++++++----------
 src/r_draw.cpp |  2 +-
 2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/src/f_wipe.cpp b/src/f_wipe.cpp
index a3ceb8d50..352122007 100644
--- a/src/f_wipe.cpp
+++ b/src/f_wipe.cpp
@@ -28,6 +28,7 @@
 #include "f_wipe.h"
 #include "c_cvars.h"
 #include "templates.h"
+#include "v_palette.h"
 
 //
 //		SCREEN WIPE PACKAGE
@@ -299,12 +300,15 @@ bool wipe_doBurn (int ticks)
 			else
 			{
 				int bglevel = 64-fglevel;
-				DWORD *fg2rgb = Col2RGB8[fglevel];
-				DWORD *bg2rgb = Col2RGB8[bglevel];
-				DWORD fg = fg2rgb[fromnew[x]];
-				DWORD bg = bg2rgb[fromold[x]];
-				fg = (fg+bg) | 0x1f07c1f;
-				to[x] = RGB32k.All[fg & (fg>>15)];
+
+				const PalEntry* pal = GPalette.BaseColors;
+
+				DWORD fg = fromnew[x];
+				DWORD bg = fromold[x];
+				int r = MIN((pal[fg].r * fglevel + pal[bg].r * bglevel) >> 8, 63);
+				int g = MIN((pal[fg].g * fglevel + pal[bg].g * bglevel) >> 8, 63);
+				int b = MIN((pal[fg].b * fglevel + pal[bg].b * bglevel) >> 8, 63);
+				to[x] = RGB256k.RGB[r][g][b];
 				done = false;
 			}
 		}
@@ -347,15 +351,18 @@ bool wipe_doFade (int ticks)
 		BYTE *fromnew = (BYTE *)wipe_scr_end;
 		BYTE *fromold = (BYTE *)wipe_scr_start;
 		BYTE *to = screen->GetBuffer();
+		const PalEntry *pal = GPalette.BaseColors;
 
 		for (y = 0; y < SCREENHEIGHT; y++)
 		{
 			for (x = 0; x < SCREENWIDTH; x++)
 			{
-				DWORD fg = fg2rgb[fromnew[x]];
-				DWORD bg = bg2rgb[fromold[x]];
-				fg = (fg+bg) | 0x1f07c1f;
-				to[x] = RGB32k.All[fg & (fg>>15)];
+				DWORD fg = fromnew[x];
+				DWORD bg = fromold[x];
+				int r = MIN((pal[fg].r * (64-bglevel) + pal[bg].r * bglevel) >> 8, 63);
+				int g = MIN((pal[fg].g * (64-bglevel) + pal[bg].g * bglevel) >> 8, 63);
+				int b = MIN((pal[fg].b * (64-bglevel) + pal[bg].b * bglevel) >> 8, 63);
+				to[x] = RGB256k.RGB[r][g][b];
 			}
 			fromnew += SCREENWIDTH;
 			fromold += SCREENWIDTH;
diff --git a/src/r_draw.cpp b/src/r_draw.cpp
index 2c5d6fd91..2d86ee985 100644
--- a/src/r_draw.cpp
+++ b/src/r_draw.cpp
@@ -450,7 +450,7 @@ namespace swrenderer
 			uint32_t g = GPART(color);
 			uint32_t b = BPART(color);
 			// dc_color is used by the rt_* routines. It is indexed into dc_srcblend.
-			dc_color = RGB32k.RGB[r >> 3][g >> 3][b >> 3];
+			dc_color = RGB256k.RGB[r >> 2][g >> 2][b >> 2];
 			if (style.Flags & STYLEF_InvertSource)
 			{
 				r = 255 - r;