From 2ba402dc7404116d38b54b2878046fb161ede18a Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 17 Dec 2016 04:11:52 -0500 Subject: [PATCH 01/15] - Implementing RGB666 colormatching to replace less precise RGB555 in some parts of the code. --- src/r_draw_pal.cpp | 91 ++++++++++++++++++++++++++++++++++++- src/textures/pngtexture.cpp | 13 ++++++ src/textures/tgatexture.cpp | 12 +++++ src/v_draw.cpp | 2 +- src/v_video.cpp | 11 +++++ src/v_video.h | 10 ++++ 6 files changed, 137 insertions(+), 2 deletions(-) diff --git a/src/r_draw_pal.cpp b/src/r_draw_pal.cpp index cfb55a670..439321e53 100644 --- a/src/r_draw_pal.cpp +++ b/src/r_draw_pal.cpp @@ -314,10 +314,17 @@ namespace swrenderer uint8_t pix = source[frac >> bits]; if (pix != 0) { +#ifdef NO_RGB666 uint32_t fg = fg2rgb[colormap[pix]]; uint32_t bg = bg2rgb[*dest]; fg = (fg + bg) | 0x1f07c1f; *dest = RGB32k.All[fg & (fg >> 15)]; +#else + uint32_t r = clamp(GPalette.BaseColors[colormap[pix]].r + GPalette.BaseColors[*dest].r, 0, 255); + uint32_t g = clamp(GPalette.BaseColors[colormap[pix]].g + GPalette.BaseColors[*dest].g, 0, 255); + uint32_t b = clamp(GPalette.BaseColors[colormap[pix]].b + GPalette.BaseColors[*dest].b, 0, 255); + *dest = RGB256k.RGB[r>>2][g>>2][b>>2]; +#endif } frac += fracstep; dest += pitch; @@ -357,10 +364,17 @@ namespace swrenderer uint8_t pix = _bufplce[i][vplce[i] >> bits]; if (pix != 0) { +#ifdef NO_RGB666 uint32_t fg = fg2rgb[_palookupoffse[i][pix]]; uint32_t bg = bg2rgb[dest[i]]; fg = (fg + bg) | 0x1f07c1f; dest[i] = RGB32k.All[fg & (fg >> 15)]; +#else + uint32_t r = clamp(GPalette.BaseColors[_palookupoffse[i][pix]].r + GPalette.BaseColors[dest[i]].r, 0, 255); + uint32_t g = clamp(GPalette.BaseColors[_palookupoffse[i][pix]].g + GPalette.BaseColors[dest[i]].g, 0, 255); + uint32_t b = clamp(GPalette.BaseColors[_palookupoffse[i][pix]].b + GPalette.BaseColors[dest[i]].b, 0, 255); + dest[i] = RGB256k.RGB[r>>2][g>>2][b>>2]; +#endif } vplce[i] += vince[i]; } @@ -396,6 +410,7 @@ namespace swrenderer uint8_t pix = source[frac >> bits]; if (pix != 0) { +#ifdef NO_RGB666 uint32_t a = fg2rgb[colormap[pix]] + bg2rgb[*dest]; uint32_t b = a; @@ -405,6 +420,12 @@ namespace swrenderer b = b - (b >> 5); a |= b; *dest = RGB32k.All[a & (a >> 15)]; +#else + uint32_t r = clamp(GPalette.BaseColors[colormap[pix]].r + GPalette.BaseColors[*dest].r, 0, 255); + uint32_t g = clamp(GPalette.BaseColors[colormap[pix]].g + GPalette.BaseColors[*dest].g, 0, 255); + uint32_t b = clamp(GPalette.BaseColors[colormap[pix]].b + GPalette.BaseColors[*dest].b, 0, 255); + *dest = RGB256k.RGB[r>>2][g>>2][b>>2]; +#endif } frac += fracstep; dest += pitch; @@ -444,6 +465,7 @@ namespace swrenderer uint8_t pix = _bufplce[i][vplce[i] >> bits]; if (pix != 0) { +#ifdef NO_RGB666 uint32_t a = fg2rgb[_palookupoffse[i][pix]] + bg2rgb[dest[i]]; uint32_t b = a; @@ -453,6 +475,12 @@ namespace swrenderer b = b - (b >> 5); a |= b; dest[i] = RGB32k.All[a & (a >> 15)]; +#else + uint32_t r = clamp(GPalette.BaseColors[_palookupoffse[i][pix]].r + GPalette.BaseColors[dest[i]].r, 0, 255); + uint32_t g = clamp(GPalette.BaseColors[_palookupoffse[i][pix]].g + GPalette.BaseColors[dest[i]].g, 0, 255); + uint32_t b = clamp(GPalette.BaseColors[_palookupoffse[i][pix]].b + GPalette.BaseColors[dest[i]].b, 0, 255); + dest[i] = RGB256k.RGB[r>>2][g>>2][b>>2]; +#endif } vplce[i] += vince[i]; } @@ -488,6 +516,7 @@ namespace swrenderer uint8_t pix = source[frac >> bits]; if (pix != 0) { +#ifdef NO_RGB666 uint32_t a = (fg2rgb[colormap[pix]] | 0x40100400) - bg2rgb[*dest]; uint32_t b = a; @@ -496,6 +525,12 @@ namespace swrenderer a &= b; a |= 0x01f07c1f; *dest = RGB32k.All[a & (a >> 15)]; +#else + uint32_t r = clamp(-GPalette.BaseColors[colormap[pix]].r + GPalette.BaseColors[*dest].r, 0, 255); + uint32_t g = clamp(-GPalette.BaseColors[colormap[pix]].g + GPalette.BaseColors[*dest].g, 0, 255); + uint32_t b = clamp(-GPalette.BaseColors[colormap[pix]].b + GPalette.BaseColors[*dest].b, 0, 255); + *dest = RGB256k.RGB[r>>2][g>>2][b>>2]; +#endif } frac += fracstep; dest += pitch; @@ -535,6 +570,7 @@ namespace swrenderer uint8_t pix = _bufplce[i][vplce[i] >> bits]; if (pix != 0) { +#ifdef NO_RGB666 uint32_t a = (fg2rgb[_palookupoffse[i][pix]] | 0x40100400) - bg2rgb[dest[i]]; uint32_t b = a; @@ -543,6 +579,12 @@ namespace swrenderer a &= b; a |= 0x01f07c1f; dest[i] = RGB32k.All[a & (a >> 15)]; +#else + uint32_t r = clamp(-GPalette.BaseColors[_palookupoffse[i][pix]].r + GPalette.BaseColors[dest[i]].r, 0, 255); + uint32_t g = clamp(-GPalette.BaseColors[_palookupoffse[i][pix]].g + GPalette.BaseColors[dest[i]].g, 0, 255); + uint32_t b = clamp(-GPalette.BaseColors[_palookupoffse[i][pix]].b + GPalette.BaseColors[dest[i]].b, 0, 255); + dest[i] = RGB256k.RGB[r>>2][g>>2][b>>2]; +#endif } vplce[i] += vince[i]; } @@ -578,6 +620,7 @@ namespace swrenderer uint8_t pix = source[frac >> bits]; if (pix != 0) { +#ifdef NO_RGB666 uint32_t a = (bg2rgb[*dest] | 0x40100400) - fg2rgb[colormap[pix]]; uint32_t b = a; @@ -586,6 +629,12 @@ namespace swrenderer a &= b; a |= 0x01f07c1f; *dest = RGB32k.All[a & (a >> 15)]; +#else + uint32_t r = clamp(GPalette.BaseColors[colormap[pix]].r - GPalette.BaseColors[*dest].r, 0, 255); + uint32_t g = clamp(GPalette.BaseColors[colormap[pix]].g - GPalette.BaseColors[*dest].g, 0, 255); + uint32_t b = clamp(GPalette.BaseColors[colormap[pix]].b - GPalette.BaseColors[*dest].b, 0, 255); + *dest = RGB256k.RGB[r>>2][g>>2][b>>2]; +#endif } frac += fracstep; dest += pitch; @@ -625,6 +674,7 @@ namespace swrenderer uint8_t pix = _bufplce[i][vplce[i] >> bits]; if (pix != 0) { +#ifdef NO_RGB666 uint32_t a = (bg2rgb[dest[i]] | 0x40100400) - fg2rgb[_palookupoffse[i][pix]]; uint32_t b = a; @@ -633,6 +683,12 @@ namespace swrenderer a &= b; a |= 0x01f07c1f; dest[i] = RGB32k.All[a & (a >> 15)]; +#else + uint32_t r = clamp(GPalette.BaseColors[_palookupoffse[i][pix]].r - GPalette.BaseColors[dest[i]].r, 0, 255); + uint32_t g = clamp(GPalette.BaseColors[_palookupoffse[i][pix]].g - GPalette.BaseColors[dest[i]].g, 0, 255); + uint32_t b = clamp(GPalette.BaseColors[_palookupoffse[i][pix]].b - GPalette.BaseColors[dest[i]].b, 0, 255); + dest[i] = RGB256k.RGB[r>>2][g>>2][b>>2]; +#endif } vplce[i] += vince[i]; } @@ -716,7 +772,11 @@ namespace swrenderer c_red = (c_red * alpha_bottom + solid_bottom_r * inv_alpha_bottom) >> 8; c_green = (c_green * alpha_bottom + solid_bottom_g * inv_alpha_bottom) >> 8; c_blue = (c_blue * alpha_bottom + solid_bottom_b * inv_alpha_bottom) >> 8; +#ifdef NO_RGB666 *dest = RGB32k.RGB[(c_red >> 3)][(c_green >> 3)][(c_blue >> 3)]; +#else + *dest = RGB256k.RGB[(c_red >> 2)][(c_green >> 2)][(c_blue >> 2)]; +#endif } frac += fracstep; @@ -744,8 +804,13 @@ namespace swrenderer int solid_bottom_r = RPART(solid_bottom); int solid_bottom_g = GPART(solid_bottom); int solid_bottom_b = BPART(solid_bottom); +#ifdef NO_RGB666 uint32_t solid_top_fill = RGB32k.RGB[(solid_top_r >> 3)][(solid_top_g >> 3)][(solid_top_b >> 3)]; uint32_t solid_bottom_fill = RGB32k.RGB[(solid_bottom_r >> 3)][(solid_bottom_g >> 3)][(solid_bottom_b >> 3)]; +#else + uint32_t solid_top_fill = RGB256k.RGB[(solid_top_r >> 2)][(solid_top_g >> 2)][(solid_top_b >> 2)]; + uint32_t solid_bottom_fill = RGB256k.RGB[(solid_bottom_r >> 2)][(solid_bottom_g >> 2)][(solid_bottom_b >> 2)]; +#endif solid_top_fill = (solid_top_fill << 24) | (solid_top_fill << 16) | (solid_top_fill << 8) | solid_top_fill; solid_bottom_fill = (solid_bottom_fill << 24) | (solid_bottom_fill << 16) | (solid_bottom_fill << 8) | solid_bottom_fill; @@ -805,8 +870,11 @@ namespace swrenderer c_red = (c_red * alpha_top + solid_top_r * inv_alpha_top) >> 8; c_green = (c_green * alpha_top + solid_top_g * inv_alpha_top) >> 8; c_blue = (c_blue * alpha_top + solid_top_b * inv_alpha_top) >> 8; +#ifdef NO_RGB666 output[col] = RGB32k.RGB[(c_red >> 3)][(c_green >> 3)][(c_blue >> 3)]; - +#else + output[col] = RGB256k.RGB[(c_red >> 2)][(c_green >> 2)][(c_blue >> 2)]; +#endif frac[col] += fracstep[col]; } *((uint32_t*)dest) = *((uint32_t*)output); @@ -847,7 +915,11 @@ namespace swrenderer c_red = (c_red * alpha_bottom + solid_bottom_r * inv_alpha_bottom) >> 8; c_green = (c_green * alpha_bottom + solid_bottom_g * inv_alpha_bottom) >> 8; c_blue = (c_blue * alpha_bottom + solid_bottom_b * inv_alpha_bottom) >> 8; +#ifdef NO_RGB666 output[col] = RGB32k.RGB[(c_red >> 3)][(c_green >> 3)][(c_blue >> 3)]; +#else + output[col] = RGB256k.RGB[(c_red >> 2)][(c_green >> 2)][(c_blue >> 2)]; +#endif frac[col] += fracstep[col]; } @@ -929,7 +1001,11 @@ namespace swrenderer c_red = (c_red * alpha_bottom + solid_bottom_r * inv_alpha_bottom) >> 8; c_green = (c_green * alpha_bottom + solid_bottom_g * inv_alpha_bottom) >> 8; c_blue = (c_blue * alpha_bottom + solid_bottom_b * inv_alpha_bottom) >> 8; +#ifdef NO_RGB666 *dest = RGB32k.RGB[(c_red >> 3)][(c_green >> 3)][(c_blue >> 3)]; +#else + *dest = RGB256k.RGB[(c_red >> 2)][(c_green >> 2)][(c_blue >> 2)]; +#endif } frac += fracstep; @@ -959,8 +1035,13 @@ namespace swrenderer int solid_bottom_r = RPART(solid_bottom); int solid_bottom_g = GPART(solid_bottom); int solid_bottom_b = BPART(solid_bottom); +#ifdef NO_RGB666 uint32_t solid_top_fill = RGB32k.RGB[(solid_top_r >> 3)][(solid_top_g >> 3)][(solid_top_b >> 3)]; uint32_t solid_bottom_fill = RGB32k.RGB[(solid_bottom_r >> 3)][(solid_bottom_g >> 3)][(solid_bottom_b >> 3)]; +#else + uint32_t solid_top_fill = RGB256k.RGB[(solid_top_r >> 2)][(solid_top_g >> 2)][(solid_top_b >> 2)]; + uint32_t solid_bottom_fill = RGB256k.RGB[(solid_bottom_r >> 2)][(solid_bottom_g >> 2)][(solid_bottom_b >> 2)]; +#endif solid_top_fill = (solid_top_fill << 24) | (solid_top_fill << 16) | (solid_top_fill << 8) | solid_top_fill; solid_bottom_fill = (solid_bottom_fill << 24) | (solid_bottom_fill << 16) | (solid_bottom_fill << 8) | solid_bottom_fill; @@ -1026,7 +1107,11 @@ namespace swrenderer c_red = (c_red * alpha_top + solid_top_r * inv_alpha_top) >> 8; c_green = (c_green * alpha_top + solid_top_g * inv_alpha_top) >> 8; c_blue = (c_blue * alpha_top + solid_top_b * inv_alpha_top) >> 8; +#ifdef NO_RGB666 output[col] = RGB32k.RGB[(c_red >> 3)][(c_green >> 3)][(c_blue >> 3)]; +#else + output[col] = RGB256k.RGB[(c_red >> 2)][(c_green >> 2)][(c_blue >> 2)]; +#endif frac[col] += fracstep[col]; } @@ -1080,7 +1165,11 @@ namespace swrenderer c_red = (c_red * alpha_bottom + solid_bottom_r * inv_alpha_bottom) >> 8; c_green = (c_green * alpha_bottom + solid_bottom_g * inv_alpha_bottom) >> 8; c_blue = (c_blue * alpha_bottom + solid_bottom_b * inv_alpha_bottom) >> 8; +#ifdef NO_RGB666 output[col] = RGB32k.RGB[(c_red >> 3)][(c_green >> 3)][(c_blue >> 3)]; +#else + output[col] = RGB256k.RGB[(c_red >> 2)][(c_green >> 2)][(c_blue >> 2)]; +#endif frac[col] += fracstep[col]; } diff --git a/src/textures/pngtexture.cpp b/src/textures/pngtexture.cpp index d24cd92d1..e13944173 100644 --- a/src/textures/pngtexture.cpp +++ b/src/textures/pngtexture.cpp @@ -536,7 +536,12 @@ void FPNGTexture::MakeTexture () { if (!HaveTrans) { +#ifdef NO_RGB666 *out++ = RGB32k.RGB[in[0]>>3][in[1]>>3][in[2]>>3]; +#else + *out++ = RGB256k.RGB[in[0]>>2][in[1]>>2][in[2]>>2]; +#endif + } else { @@ -548,7 +553,11 @@ void FPNGTexture::MakeTexture () } else { +#ifdef NO_RGB666 *out++ = RGB32k.RGB[in[0]>>3][in[1]>>3][in[2]>>3]; +#else + *out++ = RGB256k.RGB[in[0]>>2][in[1]>>2][in[2]>>2]; +#endif } } in += pitch; @@ -593,7 +602,11 @@ void FPNGTexture::MakeTexture () { for (y = Height; y > 0; --y) { +#ifdef NO_RGB666 *out++ = in[3] < 128 ? 0 : RGB32k.RGB[in[0]>>3][in[1]>>3][in[2]>>3]; +#else + *out++ = in[3] < 128 ? 0 : RGB256k.RGB[in[0]>>2][in[1]>>2][in[2]>>2]; +#endif in += pitch; } in -= backstep; diff --git a/src/textures/tgatexture.cpp b/src/textures/tgatexture.cpp index b208a51a3..e24b926ca 100644 --- a/src/textures/tgatexture.cpp +++ b/src/textures/tgatexture.cpp @@ -405,7 +405,11 @@ void FTGATexture::MakeTexture () BYTE * p = ptr + y * Pitch; for(int x=0;x>3][p[1]>>3][p[0]>>3]; +#else + Pixels[x*Height+y] = RGB256k.RGB[p[2]>>2][p[1]>>2][p[0]>>2]; +#endif p+=step_x; } } @@ -419,7 +423,11 @@ void FTGATexture::MakeTexture () BYTE * p = ptr + y * Pitch; for(int x=0;x>3][p[1]>>3][p[0]>>3]; +#else + Pixels[x*Height+y] = RGB256k.RGB[p[2]>>2][p[1]>>2][p[0]>>2]; +#endif p+=step_x; } } @@ -431,7 +439,11 @@ void FTGATexture::MakeTexture () BYTE * p = ptr + y * Pitch; for(int x=0;x= 128? RGB32k.RGB[p[2]>>3][p[1]>>3][p[0]>>3] : 0; +#else + Pixels[x*Height+y] = p[3] >= 128? RGB256k.RGB[p[2]>>2][p[1]>>2][p[0]>>2] : 0; +#endif p+=step_x; } } diff --git a/src/v_draw.cpp b/src/v_draw.cpp index 1524c7ba4..bf7ccaab4 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -1031,7 +1031,7 @@ void DCanvas::PUTTRANSDOT (int xx, int yy, int basecolor, int level) DWORD *fg2rgb = Col2RGB8[63-level]; DWORD fg = fg2rgb[basecolor]; DWORD bg = bg2rgb[*spot]; - bg = (fg+bg) | 0x1f07c1f; + bg = (fg+bg) | 0x01f07c1f; *spot = RGB32k.All[bg&(bg>>15)]; } diff --git a/src/v_video.cpp b/src/v_video.cpp index efe93aa04..92992220b 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -144,8 +144,12 @@ DWORD Col2RGB8[65][256]; DWORD *Col2RGB8_LessPrecision[65]; DWORD Col2RGB8_Inverse[65][256]; ColorTable32k RGB32k; +#ifndef NO_RGB666 +ColorTable256k RGB256k; +#endif } + static DWORD Col2RGB8_2[63][256]; // [RH] The framebuffer is no longer a mere byte array. @@ -669,6 +673,13 @@ static void BuildTransTable (const PalEntry *palette) for (g = 0; g < 32; g++) for (b = 0; b < 32; b++) RGB32k.RGB[r][g][b] = ColorMatcher.Pick ((r<<3)|(r>>2), (g<<3)|(g>>2), (b<<3)|(b>>2)); +#ifndef NO_RGB666 + // create the RGB666 lookup table + for (r = 0; r < 64; r++) + for (g = 0; g < 64; g++) + for (b = 0; b < 64; b++) + RGB256k.RGB[r][g][b] = ColorMatcher.Pick ((r<<2)|(r>>4), (g<<2)|(g>>4), (b<<2)|(b>>4)); +#endif int x, y; diff --git a/src/v_video.h b/src/v_video.h index b72f67094..2079ff64b 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -462,6 +462,16 @@ union ColorTable32k }; extern "C" ColorTable32k RGB32k; +// [SP] RGB666 support +#ifndef NO_RGB666 +union ColorTable256k +{ + BYTE RGB[64][64][64]; + BYTE All[64 *64 *64]; +}; +extern "C" ColorTable256k RGB256k; +#endif + // Col2RGB8 is a pre-multiplied palette for color lookup. It is stored in a // special R10B10G10 format for efficient blending computation. // --RRRRRrrr--BBBBBbbb--GGGGGggg-- at level 64 From 179c7dba8315723495b1f08f3dff056f3c1ef446 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 17 Dec 2016 10:25:35 -0500 Subject: [PATCH 02/15] - Yeah, it's time to take a break. Have fun with this! :D --- src/r_draw_pal.cpp | 99 ++++++++++------------------------------------ src/r_things.cpp | 39 ++++-------------- src/v_draw.cpp | 33 +++------------- src/v_video.cpp | 30 ++++++-------- 4 files changed, 47 insertions(+), 154 deletions(-) diff --git a/src/r_draw_pal.cpp b/src/r_draw_pal.cpp index 439321e53..5a6c94327 100644 --- a/src/r_draw_pal.cpp +++ b/src/r_draw_pal.cpp @@ -320,9 +320,9 @@ namespace swrenderer fg = (fg + bg) | 0x1f07c1f; *dest = RGB32k.All[fg & (fg >> 15)]; #else - uint32_t r = clamp(GPalette.BaseColors[colormap[pix]].r + GPalette.BaseColors[*dest].r, 0, 255); - uint32_t g = clamp(GPalette.BaseColors[colormap[pix]].g + GPalette.BaseColors[*dest].g, 0, 255); - uint32_t b = clamp(GPalette.BaseColors[colormap[pix]].b + GPalette.BaseColors[*dest].b, 0, 255); + uint32_t r = MIN(GPalette.BaseColors[colormap[pix]].r + GPalette.BaseColors[*dest].r, 255); + uint32_t g = MIN(GPalette.BaseColors[colormap[pix]].g + GPalette.BaseColors[*dest].g, 255); + uint32_t b = MIN(GPalette.BaseColors[colormap[pix]].b + GPalette.BaseColors[*dest].b, 255); *dest = RGB256k.RGB[r>>2][g>>2][b>>2]; #endif } @@ -370,9 +370,9 @@ namespace swrenderer fg = (fg + bg) | 0x1f07c1f; dest[i] = RGB32k.All[fg & (fg >> 15)]; #else - uint32_t r = clamp(GPalette.BaseColors[_palookupoffse[i][pix]].r + GPalette.BaseColors[dest[i]].r, 0, 255); - uint32_t g = clamp(GPalette.BaseColors[_palookupoffse[i][pix]].g + GPalette.BaseColors[dest[i]].g, 0, 255); - uint32_t b = clamp(GPalette.BaseColors[_palookupoffse[i][pix]].b + GPalette.BaseColors[dest[i]].b, 0, 255); + uint32_t r = MIN(GPalette.BaseColors[_palookupoffse[i][pix]].r + GPalette.BaseColors[dest[i]].r, 255); + uint32_t g = MIN(GPalette.BaseColors[_palookupoffse[i][pix]].g + GPalette.BaseColors[dest[i]].g, 255); + uint32_t b = MIN(GPalette.BaseColors[_palookupoffse[i][pix]].b + GPalette.BaseColors[dest[i]].b, 255); dest[i] = RGB256k.RGB[r>>2][g>>2][b>>2]; #endif } @@ -410,22 +410,10 @@ namespace swrenderer uint8_t pix = source[frac >> bits]; if (pix != 0) { -#ifdef NO_RGB666 - uint32_t a = fg2rgb[colormap[pix]] + bg2rgb[*dest]; - uint32_t b = a; - - a |= 0x01f07c1f; - b &= 0x40100400; - a &= 0x3fffffff; - b = b - (b >> 5); - a |= b; - *dest = RGB32k.All[a & (a >> 15)]; -#else - uint32_t r = clamp(GPalette.BaseColors[colormap[pix]].r + GPalette.BaseColors[*dest].r, 0, 255); - uint32_t g = clamp(GPalette.BaseColors[colormap[pix]].g + GPalette.BaseColors[*dest].g, 0, 255); - uint32_t b = clamp(GPalette.BaseColors[colormap[pix]].b + GPalette.BaseColors[*dest].b, 0, 255); + uint32_t r = MIN(GPalette.BaseColors[colormap[pix]].r + GPalette.BaseColors[*dest].r, 255); + uint32_t g = MIN(GPalette.BaseColors[colormap[pix]].g + GPalette.BaseColors[*dest].g, 255); + uint32_t b = MIN(GPalette.BaseColors[colormap[pix]].b + GPalette.BaseColors[*dest].b, 255); *dest = RGB256k.RGB[r>>2][g>>2][b>>2]; -#endif } frac += fracstep; dest += pitch; @@ -465,22 +453,10 @@ namespace swrenderer uint8_t pix = _bufplce[i][vplce[i] >> bits]; if (pix != 0) { -#ifdef NO_RGB666 - uint32_t a = fg2rgb[_palookupoffse[i][pix]] + bg2rgb[dest[i]]; - uint32_t b = a; - - a |= 0x01f07c1f; - b &= 0x40100400; - a &= 0x3fffffff; - b = b - (b >> 5); - a |= b; - dest[i] = RGB32k.All[a & (a >> 15)]; -#else - uint32_t r = clamp(GPalette.BaseColors[_palookupoffse[i][pix]].r + GPalette.BaseColors[dest[i]].r, 0, 255); - uint32_t g = clamp(GPalette.BaseColors[_palookupoffse[i][pix]].g + GPalette.BaseColors[dest[i]].g, 0, 255); - uint32_t b = clamp(GPalette.BaseColors[_palookupoffse[i][pix]].b + GPalette.BaseColors[dest[i]].b, 0, 255); + uint32_t r = MIN(GPalette.BaseColors[_palookupoffse[i][pix]].r + GPalette.BaseColors[dest[i]].r, 255); + uint32_t g = MIN(GPalette.BaseColors[_palookupoffse[i][pix]].g + GPalette.BaseColors[dest[i]].g, 255); + uint32_t b = MIN(GPalette.BaseColors[_palookupoffse[i][pix]].b + GPalette.BaseColors[dest[i]].b, 255); dest[i] = RGB256k.RGB[r>>2][g>>2][b>>2]; -#endif } vplce[i] += vince[i]; } @@ -516,21 +492,10 @@ namespace swrenderer uint8_t pix = source[frac >> bits]; if (pix != 0) { -#ifdef NO_RGB666 - uint32_t a = (fg2rgb[colormap[pix]] | 0x40100400) - bg2rgb[*dest]; - uint32_t b = a; - - b &= 0x40100400; - b = b - (b >> 5); - a &= b; - a |= 0x01f07c1f; - *dest = RGB32k.All[a & (a >> 15)]; -#else - uint32_t r = clamp(-GPalette.BaseColors[colormap[pix]].r + GPalette.BaseColors[*dest].r, 0, 255); - uint32_t g = clamp(-GPalette.BaseColors[colormap[pix]].g + GPalette.BaseColors[*dest].g, 0, 255); - uint32_t b = clamp(-GPalette.BaseColors[colormap[pix]].b + GPalette.BaseColors[*dest].b, 0, 255); + int r = clamp(-GPalette.BaseColors[colormap[pix]].r + GPalette.BaseColors[*dest].r, 0, 255); + int g = clamp(-GPalette.BaseColors[colormap[pix]].g + GPalette.BaseColors[*dest].g, 0, 255); + int b = clamp(-GPalette.BaseColors[colormap[pix]].b + GPalette.BaseColors[*dest].b, 0, 255); *dest = RGB256k.RGB[r>>2][g>>2][b>>2]; -#endif } frac += fracstep; dest += pitch; @@ -570,21 +535,10 @@ namespace swrenderer uint8_t pix = _bufplce[i][vplce[i] >> bits]; if (pix != 0) { -#ifdef NO_RGB666 - uint32_t a = (fg2rgb[_palookupoffse[i][pix]] | 0x40100400) - bg2rgb[dest[i]]; - uint32_t b = a; - - b &= 0x40100400; - b = b - (b >> 5); - a &= b; - a |= 0x01f07c1f; - dest[i] = RGB32k.All[a & (a >> 15)]; -#else - uint32_t r = clamp(-GPalette.BaseColors[_palookupoffse[i][pix]].r + GPalette.BaseColors[dest[i]].r, 0, 255); - uint32_t g = clamp(-GPalette.BaseColors[_palookupoffse[i][pix]].g + GPalette.BaseColors[dest[i]].g, 0, 255); - uint32_t b = clamp(-GPalette.BaseColors[_palookupoffse[i][pix]].b + GPalette.BaseColors[dest[i]].b, 0, 255); + int r = clamp(-GPalette.BaseColors[_palookupoffse[i][pix]].r + GPalette.BaseColors[dest[i]].r, 0, 255); + int g = clamp(-GPalette.BaseColors[_palookupoffse[i][pix]].g + GPalette.BaseColors[dest[i]].g, 0, 255); + int b = clamp(-GPalette.BaseColors[_palookupoffse[i][pix]].b + GPalette.BaseColors[dest[i]].b, 0, 255); dest[i] = RGB256k.RGB[r>>2][g>>2][b>>2]; -#endif } vplce[i] += vince[i]; } @@ -620,21 +574,10 @@ namespace swrenderer uint8_t pix = source[frac >> bits]; if (pix != 0) { -#ifdef NO_RGB666 - uint32_t a = (bg2rgb[*dest] | 0x40100400) - fg2rgb[colormap[pix]]; - uint32_t b = a; - - b &= 0x40100400; - b = b - (b >> 5); - a &= b; - a |= 0x01f07c1f; - *dest = RGB32k.All[a & (a >> 15)]; -#else - uint32_t r = clamp(GPalette.BaseColors[colormap[pix]].r - GPalette.BaseColors[*dest].r, 0, 255); - uint32_t g = clamp(GPalette.BaseColors[colormap[pix]].g - GPalette.BaseColors[*dest].g, 0, 255); - uint32_t b = clamp(GPalette.BaseColors[colormap[pix]].b - GPalette.BaseColors[*dest].b, 0, 255); + int r = clamp(GPalette.BaseColors[colormap[pix]].r - GPalette.BaseColors[*dest].r, 0, 255); + int g = clamp(GPalette.BaseColors[colormap[pix]].g - GPalette.BaseColors[*dest].g, 0, 255); + int b = clamp(GPalette.BaseColors[colormap[pix]].b - GPalette.BaseColors[*dest].b, 0, 255); *dest = RGB256k.RGB[r>>2][g>>2][b>>2]; -#endif } frac += fracstep; dest += pitch; diff --git a/src/r_things.cpp b/src/r_things.cpp index 9e9b161cd..7c178ce8b 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -2634,10 +2634,8 @@ static void R_DrawMaskedSegsBehindParticle (const vissprite_t *vis) void R_DrawParticle_C (vissprite_t *vis) { - DWORD *bg2rgb; int spacing; BYTE *dest; - DWORD fg; BYTE color = vis->Style.colormap[vis->startfrac]; int yl = vis->y1; int ycount = vis->y2 - yl + 1; @@ -2649,33 +2647,10 @@ void R_DrawParticle_C (vissprite_t *vis) DrawerCommandQueue::WaitForWorkers(); // vis->renderflags holds translucency level (0-255) - { - fixed_t fglevel, bglevel; - DWORD *fg2rgb; + fixed_t fglevel, bglevel; - fglevel = ((vis->renderflags + 1) << 8) & ~0x3ff; - bglevel = FRACUNIT-fglevel; - fg2rgb = Col2RGB8[fglevel>>10]; - bg2rgb = Col2RGB8[bglevel>>10]; - fg = fg2rgb[color]; - } - - /* - - spacing = RenderTarget->GetPitch() - countbase; - dest = ylookup[yl] + x1 + dc_destorg; - - do - { - int count = countbase; - do - { - DWORD bg = bg2rgb[*dest]; - bg = (fg+bg) | 0x1f07c1f; - *dest++ = RGB32k.All[bg & (bg>>15)]; - } while (--count); - dest += spacing; - } while (--ycount);*/ + fglevel = ((vis->renderflags + 1) << 8) & ~0x3ff; + bglevel = FRACUNIT-fglevel; // original was row-wise // width = countbase @@ -2691,9 +2666,11 @@ void R_DrawParticle_C (vissprite_t *vis) dest = ylookup[yl] + x + dc_destorg; for (int y = 0; y < ycount; y++) { - DWORD bg = bg2rgb[*dest]; - bg = (fg+bg) | 0x1f07c1f; - *dest = RGB32k.All[bg & (bg>>15)]; + int dest_r = (GPalette.BaseColors[*dest].r * bglevel + GPalette.BaseColors[color].r * fglevel) >> 10; + int dest_g = (GPalette.BaseColors[*dest].g * bglevel + GPalette.BaseColors[color].g * fglevel) >> 10; + int dest_b = (GPalette.BaseColors[*dest].b * bglevel + GPalette.BaseColors[color].b * fglevel) >> 10; + + *dest = RGB256k.RGB[dest_r][dest_g][dest_b]; dest += spacing; } } diff --git a/src/v_draw.cpp b/src/v_draw.cpp index bf7ccaab4..34db09356 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -989,27 +989,6 @@ void DCanvas::PUTTRANSDOT (int xx, int yy, int basecolor, int level) static int oldyy; static int oldyyshifted; -#if 0 - if(xx < 32) - cc += 7-(xx>>2); - else if(xx > (finit_width - 32)) - cc += 7-((finit_width-xx) >> 2); -// if(cc==oldcc) //make sure that we don't double fade the corners. -// { - if(yy < 32) - cc += 7-(yy>>2); - else if(yy > (finit_height - 32)) - cc += 7-((finit_height-yy) >> 2); -// } - if(cc > cm && cm != NULL) - { - cc = cm; - } - else if(cc > oldcc+6) // don't let the color escape from the fade table... - { - cc=oldcc+6; - } -#endif if (yy == oldyy+1) { oldyy++; @@ -1027,12 +1006,12 @@ void DCanvas::PUTTRANSDOT (int xx, int yy, int basecolor, int level) } BYTE *spot = GetBuffer() + oldyyshifted + xx; - DWORD *bg2rgb = Col2RGB8[1+level]; - DWORD *fg2rgb = Col2RGB8[63-level]; - DWORD fg = fg2rgb[basecolor]; - DWORD bg = bg2rgb[*spot]; - bg = (fg+bg) | 0x01f07c1f; - *spot = RGB32k.All[bg&(bg>>15)]; + + uint32_t r = (GPalette.BaseColors[*spot].r * (64 - level) + GPalette.BaseColors[basecolor].r * level) / 64; + uint32_t g = (GPalette.BaseColors[*spot].g * (64 - level) + GPalette.BaseColors[basecolor].g * level) / 64; + uint32_t b = (GPalette.BaseColors[*spot].b * (64 - level) + GPalette.BaseColors[basecolor].b * level) / 64; + + *spot = (BYTE)RGB256k.RGB[r][g][b]; } void DCanvas::DrawLine(int x0, int y0, int x1, int y1, int palColor, uint32 realcolor) diff --git a/src/v_video.cpp b/src/v_video.cpp index 92992220b..6e333f840 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -349,8 +349,6 @@ void DCanvas::Dim (PalEntry color, float damount, int x1, int y1, int w, int h) if (damount == 0.f) return; - DWORD *bg2rgb; - DWORD fg; int gap; BYTE *spot; int x, y; @@ -372,28 +370,23 @@ void DCanvas::Dim (PalEntry color, float damount, int x1, int y1, int w, int h) return; } - { - int amount; - - amount = (int)(damount * 64); - bg2rgb = Col2RGB8[64-amount]; - - fg = (((color.r * amount) >> 4) << 20) | - ((color.g * amount) >> 4) | - (((color.b * amount) >> 4) << 10); - } spot = Buffer + x1 + y1*Pitch; gap = Pitch - w; + + int alpha = (int)((float)64 * damount); + int ialpha = 64 - alpha; + int dimmedcolor_r = color.r * alpha; + int dimmedcolor_g = color.g * alpha; + int dimmedcolor_b = color.b * alpha; for (y = h; y != 0; y--) { for (x = w; x != 0; x--) { - DWORD bg; - - bg = bg2rgb[(*spot)&0xff]; - bg = (fg+bg) | 0x1f07c1f; - *spot = RGB32k.All[bg&(bg>>15)]; + uint32_t r = (dimmedcolor_r + GPalette.BaseColors[*spot].r * ialpha) >> 8; + uint32_t g = (dimmedcolor_g + GPalette.BaseColors[*spot].g * ialpha) >> 8; + uint32_t b = (dimmedcolor_b + GPalette.BaseColors[*spot].b * ialpha) >> 8; + *spot = (BYTE)RGB256k.RGB[r][g][b]; spot++; } spot += gap; @@ -672,7 +665,8 @@ static void BuildTransTable (const PalEntry *palette) for (r = 0; r < 32; r++) for (g = 0; g < 32; g++) for (b = 0; b < 32; b++) - RGB32k.RGB[r][g][b] = ColorMatcher.Pick ((r<<3)|(r>>2), (g<<3)|(g>>2), (b<<3)|(b>>2)); + //RGB32k.RGB[r][g][b] = ColorMatcher.Pick ((r<<3)|(r>>2), (g<<3)|(g>>2), (b<<3)|(b>>2)); + RGB32k.RGB[r][g][b] = 2; #ifndef NO_RGB666 // create the RGB666 lookup table for (r = 0; r < 64; r++) From 6235b12cfcd28e699285af405ca25b1443d4cbd5 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 17 Dec 2016 21:26:08 -0500 Subject: [PATCH 03/15] - No matter how many drawers you have, you have more drawers to do. --- src/r_draw_pal.h | 2 + src/r_drawt_pal.cpp | 148 +++++++++-------------------- src/textures/ddstexture.cpp | 8 +- src/textures/jpegtexture.cpp | 4 +- src/textures/multipatchtexture.cpp | 2 +- src/textures/pngtexture.cpp | 13 --- src/textures/tgatexture.cpp | 14 +-- 7 files changed, 53 insertions(+), 138 deletions(-) diff --git a/src/r_draw_pal.h b/src/r_draw_pal.h index f2b1f0571..262b70387 100644 --- a/src/r_draw_pal.h +++ b/src/r_draw_pal.h @@ -303,6 +303,8 @@ namespace swrenderer const uint32_t *_srcblend; const uint32_t *_destblend; const uint8_t *_translation; + fixed_t _srcalpha; + fixed_t _destalpha; int _color; }; diff --git a/src/r_drawt_pal.cpp b/src/r_drawt_pal.cpp index 3356592d2..16d24ecaf 100644 --- a/src/r_drawt_pal.cpp +++ b/src/r_drawt_pal.cpp @@ -173,6 +173,8 @@ namespace swrenderer _colormap = dc_colormap; _srcblend = dc_srcblend; _destblend = dc_destblend; + _srcalpha = dc_srcalpha; + _destalpha = dc_destalpha; _translation = dc_translation; _color = dc_color; } @@ -440,8 +442,6 @@ namespace swrenderer if (count <= 0) return; - const uint32_t *fg2rgb = _srcblend; - const uint32_t *bg2rgb = _destblend; dest = ylookup[yl + thread->skipped_by_thread(yl)] + sx + _destorg; source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4 + hx]; pitch = _pitch * thread->num_cores; @@ -451,10 +451,10 @@ namespace swrenderer uint32_t fg = colormap[*source]; uint32_t bg = *dest; - fg = fg2rgb[fg]; - bg = bg2rgb[bg]; - fg = (fg+bg) | 0x1f07c1f; - *dest = RGB32k.All[fg & (fg>>15)]; + int r = MIN((GPalette.BaseColors[fg].r * _srcalpha + GPalette.BaseColors[bg].r * _destalpha)>>18, 63); + int g = MIN((GPalette.BaseColors[fg].g * _srcalpha + GPalette.BaseColors[bg].g * _destalpha)>>18, 63); + int b = MIN((GPalette.BaseColors[fg].b * _srcalpha + GPalette.BaseColors[bg].b * _destalpha)>>18, 63); + *dest = RGB256k.RGB[r][g][b]; source += 4; dest += pitch; } while (--count); @@ -472,42 +472,21 @@ namespace swrenderer if (count <= 0) return; - const uint32_t *fg2rgb = _srcblend; - const uint32_t *bg2rgb = _destblend; dest = ylookup[yl + thread->skipped_by_thread(yl)] + sx + _destorg; source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4]; pitch = _pitch * thread->num_cores; colormap = _colormap; do { - uint32_t fg = colormap[source[0]]; - uint32_t bg = dest[0]; - fg = fg2rgb[fg]; - bg = bg2rgb[bg]; - fg = (fg+bg) | 0x1f07c1f; - dest[0] = RGB32k.All[fg & (fg>>15)]; - - fg = colormap[source[1]]; - bg = dest[1]; - fg = fg2rgb[fg]; - bg = bg2rgb[bg]; - fg = (fg+bg) | 0x1f07c1f; - dest[1] = RGB32k.All[fg & (fg>>15)]; - - - fg = colormap[source[2]]; - bg = dest[2]; - fg = fg2rgb[fg]; - bg = bg2rgb[bg]; - fg = (fg+bg) | 0x1f07c1f; - dest[2] = RGB32k.All[fg & (fg>>15)]; - - fg = colormap[source[3]]; - bg = dest[3]; - fg = fg2rgb[fg]; - bg = bg2rgb[bg]; - fg = (fg+bg) | 0x1f07c1f; - dest[3] = RGB32k.All[fg & (fg>>15)]; + for (int ks = 0; ks < 4; ks++) + { // [SP] this 4col function was a block of copy-pasted code. 4 times. I regret nothing. + uint32_t fg = colormap[source[ks]]; + uint32_t bg = dest[ks]; + int r = MIN((GPalette.BaseColors[fg].r * _srcalpha + GPalette.BaseColors[bg].r * _destalpha)>>18, 63); + int g = MIN((GPalette.BaseColors[fg].g * _srcalpha + GPalette.BaseColors[bg].g * _destalpha)>>18, 63); + int b = MIN((GPalette.BaseColors[fg].b * _srcalpha + GPalette.BaseColors[bg].b * _destalpha)>>18, 63); + dest[ks] = RGB256k.RGB[r][g][b]; + } source += 4; dest += pitch; @@ -534,10 +513,11 @@ namespace swrenderer pitch = _pitch * thread->num_cores; do { - uint32_t val = colormap[*source]; - uint32_t fg = fgstart[val<<8]; - val = (Col2RGB8[64-val][*dest] + fg) | 0x1f07c1f; - *dest = RGB32k.All[val & (val>>15)]; + uint32_t val = *source; + int r = (GPalette.BaseColors[*dest].r * (63-val) + GPalette.BaseColors[_color].r * val) >> 8; + int g = (GPalette.BaseColors[*dest].g * (63-val) + GPalette.BaseColors[_color].g * val) >> 8; + int b = (GPalette.BaseColors[*dest].b * (63-val) + GPalette.BaseColors[_color].b * val) >> 8; + *dest = RGB256k.RGB[MIN(r,63)][MIN(g,63)][MIN(b,63)]; source += 4; dest += pitch; } while (--count); @@ -564,22 +544,15 @@ namespace swrenderer do { uint32_t val; - - val = colormap[source[0]]; - val = (Col2RGB8[64-val][dest[0]] + fgstart[val<<8]) | 0x1f07c1f; - dest[0] = RGB32k.All[val & (val>>15)]; - val = colormap[source[1]]; - val = (Col2RGB8[64-val][dest[1]] + fgstart[val<<8]) | 0x1f07c1f; - dest[1] = RGB32k.All[val & (val>>15)]; - - val = colormap[source[2]]; - val = (Col2RGB8[64-val][dest[2]] + fgstart[val<<8]) | 0x1f07c1f; - dest[2] = RGB32k.All[val & (val>>15)]; - - val = colormap[source[3]]; - val = (Col2RGB8[64-val][dest[3]] + fgstart[val<<8]) | 0x1f07c1f; - dest[3] = RGB32k.All[val & (val>>15)]; + for (int ks = 0; ks < 4; ks++) + { + val = source[ks]; + int r = (GPalette.BaseColors[dest[ks]].r * (63-val) + GPalette.BaseColors[_color].r * val) >> 8; + int g = (GPalette.BaseColors[dest[ks]].g * (63-val) + GPalette.BaseColors[_color].g * val) >> 8; + int b = (GPalette.BaseColors[dest[ks]].b * (63-val) + GPalette.BaseColors[_color].b * val) >> 8; + dest[ks] = RGB256k.RGB[MIN(r,63)][MIN(g,63)][MIN(b,63)]; + } source += 4; dest += pitch; @@ -598,23 +571,18 @@ namespace swrenderer if (count <= 0) return; - const uint32_t *fg2rgb = _srcblend; - const uint32_t *bg2rgb = _destblend; dest = ylookup[yl + thread->skipped_by_thread(yl)] + sx + _destorg; source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4 + hx]; pitch = _pitch * thread->num_cores; colormap = _colormap; do { - uint32_t a = fg2rgb[colormap[*source]] + bg2rgb[*dest]; - uint32_t b = a; - - a |= 0x01f07c1f; - b &= 0x40100400; - a &= 0x3fffffff; - b = b - (b >> 5); - a |= b; - *dest = RGB32k.All[(a>>15) & a]; + int fg = *source; + int bg = *dest; + int r = MIN((GPalette.BaseColors[fg].r * _srcalpha + GPalette.BaseColors[bg].r * _destalpha)>>18, 63); + int g = MIN((GPalette.BaseColors[fg].g * _srcalpha + GPalette.BaseColors[bg].g * _destalpha)>>18, 63); + int b = MIN((GPalette.BaseColors[fg].b * _srcalpha + GPalette.BaseColors[bg].b * _destalpha)>>18, 63); + *dest = RGB256k.RGB[r][g][b]; source += 4; dest += pitch; } while (--count); @@ -637,46 +605,16 @@ namespace swrenderer pitch = _pitch * thread->num_cores; colormap = _colormap; - const uint32_t *fg2rgb = _srcblend; - const uint32_t *bg2rgb = _destblend; - do { - uint32_t a = fg2rgb[colormap[source[0]]] + bg2rgb[dest[0]]; - uint32_t b = a; - - a |= 0x01f07c1f; - b &= 0x40100400; - a &= 0x3fffffff; - b = b - (b >> 5); - a |= b; - dest[0] = RGB32k.All[(a>>15) & a]; - - a = fg2rgb[colormap[source[1]]] + bg2rgb[dest[1]]; - b = a; - a |= 0x01f07c1f; - b &= 0x40100400; - a &= 0x3fffffff; - b = b - (b >> 5); - a |= b; - dest[1] = RGB32k.All[(a>>15) & a]; - - a = fg2rgb[colormap[source[2]]] + bg2rgb[dest[2]]; - b = a; - a |= 0x01f07c1f; - b &= 0x40100400; - a &= 0x3fffffff; - b = b - (b >> 5); - a |= b; - dest[2] = RGB32k.All[(a>>15) & a]; - - a = fg2rgb[colormap[source[3]]] + bg2rgb[dest[3]]; - b = a; - a |= 0x01f07c1f; - b &= 0x40100400; - a &= 0x3fffffff; - b = b - (b >> 5); - a |= b; - dest[3] = RGB32k.All[(a>>15) & a]; + for (int ks = 0; ks < 4; ks++) + { + int fg = source[ks]; + int bg = dest[ks]; + int r = MIN((GPalette.BaseColors[fg].r * _srcalpha + GPalette.BaseColors[bg].r * _destalpha)>>18, 63); + int g = MIN((GPalette.BaseColors[fg].g * _srcalpha + GPalette.BaseColors[bg].g * _destalpha)>>18, 63); + int b = MIN((GPalette.BaseColors[fg].b * _srcalpha + GPalette.BaseColors[bg].b * _destalpha)>>18, 63); + dest[ks] = RGB256k.RGB[r][g][b]; + } source += 4; dest += pitch; diff --git a/src/textures/ddstexture.cpp b/src/textures/ddstexture.cpp index 31e748022..a2c69b38b 100644 --- a/src/textures/ddstexture.cpp +++ b/src/textures/ddstexture.cpp @@ -551,7 +551,7 @@ void FDDSTexture::ReadRGB (FWadLump &lump, BYTE *tcbuf) DWORD r = (c & RMask) << RShiftL; r |= r >> RShiftR; DWORD g = (c & GMask) << GShiftL; g |= g >> GShiftR; DWORD b = (c & BMask) << BShiftL; b |= b >> BShiftR; - *pixelp = RGB32k.RGB[r >> 27][g >> 27][b >> 27]; + *pixelp = RGB256k.RGB[r >> 26][g >> 26][b >> 26]; } else { @@ -637,7 +637,7 @@ void FDDSTexture::DecompressDXT1 (FWadLump &lump, BYTE *tcbuf) // Pick colors from the palette for each of the four colors. /*if (!tcbuf)*/ for (i = 3; i >= 0; --i) { - palcol[i] = color[i].a ? RGB32k.RGB[color[i].r >> 3][color[i].g >> 3][color[i].b >> 3] : 0; + palcol[i] = color[i].a ? RGB256k.RGB[color[i].r >> 2][color[i].g >> 2][color[i].b >> 2] : 0; } // Now decode this 4x4 block to the pixel buffer. for (y = 0; y < 4; ++y) @@ -717,7 +717,7 @@ void FDDSTexture::DecompressDXT3 (FWadLump &lump, bool premultiplied, BYTE *tcbu // Pick colors from the palette for each of the four colors. if (!tcbuf) for (i = 3; i >= 0; --i) { - palcol[i] = RGB32k.RGB[color[i].r >> 3][color[i].g >> 3][color[i].b >> 3]; + palcol[i] = RGB256k.RGB[color[i].r >> 2][color[i].g >> 2][color[i].b >> 2]; } // Now decode this 4x4 block to the pixel buffer. for (y = 0; y < 4; ++y) @@ -822,7 +822,7 @@ void FDDSTexture::DecompressDXT5 (FWadLump &lump, bool premultiplied, BYTE *tcbu // Pick colors from the palette for each of the four colors. if (!tcbuf) for (i = 3; i >= 0; --i) { - palcol[i] = RGB32k.RGB[color[i].r >> 3][color[i].g >> 3][color[i].b >> 3]; + palcol[i] = RGB256k.RGB[color[i].r >> 2][color[i].g >> 2][color[i].b >> 2]; } // Now decode this 4x4 block to the pixel buffer. for (y = 0; y < 4; ++y) diff --git a/src/textures/jpegtexture.cpp b/src/textures/jpegtexture.cpp index 225396598..c138edbfa 100644 --- a/src/textures/jpegtexture.cpp +++ b/src/textures/jpegtexture.cpp @@ -406,7 +406,7 @@ void FJPEGTexture::MakeTexture () case JCS_RGB: for (int x = Width; x > 0; --x) { - *out = RGB32k.RGB[in[0]>>3][in[1]>>3][in[2]>>3]; + *out = RGB256k.RGB[in[0]>>2][in[1]>>2][in[2]>>2]; out += Height; in += 3; } @@ -430,7 +430,7 @@ void FJPEGTexture::MakeTexture () int r = in[3] - (((256-in[0])*in[3]) >> 8); int g = in[3] - (((256-in[1])*in[3]) >> 8); int b = in[3] - (((256-in[2])*in[3]) >> 8); - *out = RGB32k.RGB[r >> 3][g >> 3][b >> 3]; + *out = RGB256k.RGB[r >> 2][g >> 2][b >> 2]; out += Height; in += 4; } diff --git a/src/textures/multipatchtexture.cpp b/src/textures/multipatchtexture.cpp index e68c4e20f..991893845 100644 --- a/src/textures/multipatchtexture.cpp +++ b/src/textures/multipatchtexture.cpp @@ -531,7 +531,7 @@ void FMultiPatchTexture::MakeTexture () { if (*out == 0 && in[3] != 0) { - *out = RGB32k.RGB[in[2]>>3][in[1]>>3][in[0]>>3]; + *out = RGB256k.RGB[in[2]>>2][in[1]>>2][in[0]>>2]; } out += Height; in += 4; diff --git a/src/textures/pngtexture.cpp b/src/textures/pngtexture.cpp index e13944173..414c424b8 100644 --- a/src/textures/pngtexture.cpp +++ b/src/textures/pngtexture.cpp @@ -536,12 +536,7 @@ void FPNGTexture::MakeTexture () { if (!HaveTrans) { -#ifdef NO_RGB666 - *out++ = RGB32k.RGB[in[0]>>3][in[1]>>3][in[2]>>3]; -#else *out++ = RGB256k.RGB[in[0]>>2][in[1]>>2][in[2]>>2]; -#endif - } else { @@ -553,11 +548,7 @@ void FPNGTexture::MakeTexture () } else { -#ifdef NO_RGB666 - *out++ = RGB32k.RGB[in[0]>>3][in[1]>>3][in[2]>>3]; -#else *out++ = RGB256k.RGB[in[0]>>2][in[1]>>2][in[2]>>2]; -#endif } } in += pitch; @@ -602,11 +593,7 @@ void FPNGTexture::MakeTexture () { for (y = Height; y > 0; --y) { -#ifdef NO_RGB666 - *out++ = in[3] < 128 ? 0 : RGB32k.RGB[in[0]>>3][in[1]>>3][in[2]>>3]; -#else *out++ = in[3] < 128 ? 0 : RGB256k.RGB[in[0]>>2][in[1]>>2][in[2]>>2]; -#endif in += pitch; } in -= backstep; diff --git a/src/textures/tgatexture.cpp b/src/textures/tgatexture.cpp index e24b926ca..331747cfe 100644 --- a/src/textures/tgatexture.cpp +++ b/src/textures/tgatexture.cpp @@ -393,7 +393,7 @@ void FTGATexture::MakeTexture () for(int x=0;x>10) & 0x1f][(v>>5) & 0x1f][v & 0x1f]; + Pixels[x*Height+y] = RGB256k.RGB[((v>>10) & 0x1f)*2][((v>>5) & 0x1f)*2][(v & 0x1f)*2]; p+=step_x; } } @@ -405,11 +405,7 @@ void FTGATexture::MakeTexture () BYTE * p = ptr + y * Pitch; for(int x=0;x>3][p[1]>>3][p[0]>>3]; -#else Pixels[x*Height+y] = RGB256k.RGB[p[2]>>2][p[1]>>2][p[0]>>2]; -#endif p+=step_x; } } @@ -423,11 +419,7 @@ void FTGATexture::MakeTexture () BYTE * p = ptr + y * Pitch; for(int x=0;x>3][p[1]>>3][p[0]>>3]; -#else Pixels[x*Height+y] = RGB256k.RGB[p[2]>>2][p[1]>>2][p[0]>>2]; -#endif p+=step_x; } } @@ -439,11 +431,7 @@ void FTGATexture::MakeTexture () BYTE * p = ptr + y * Pitch; for(int x=0;x= 128? RGB32k.RGB[p[2]>>3][p[1]>>3][p[0]>>3] : 0; -#else Pixels[x*Height+y] = p[3] >= 128? RGB256k.RGB[p[2]>>2][p[1]>>2][p[0]>>2] : 0; -#endif p+=step_x; } } From 9fbd9985c8b77ba4ba1a0613d1d1708e09046763 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sun, 18 Dec 2016 05:33:39 -0500 Subject: [PATCH 04/15] - more work on rgb666 --- src/r_draw_pal.cpp | 82 +++--------------- src/r_drawt_pal.cpp | 160 ++++++++++++++---------------------- src/textures/pcxtexture.cpp | 2 +- 3 files changed, 72 insertions(+), 172 deletions(-) diff --git a/src/r_draw_pal.cpp b/src/r_draw_pal.cpp index 5a6c94327..33c482934 100644 --- a/src/r_draw_pal.cpp +++ b/src/r_draw_pal.cpp @@ -314,17 +314,10 @@ namespace swrenderer uint8_t pix = source[frac >> bits]; if (pix != 0) { -#ifdef NO_RGB666 - uint32_t fg = fg2rgb[colormap[pix]]; - uint32_t bg = bg2rgb[*dest]; - fg = (fg + bg) | 0x1f07c1f; - *dest = RGB32k.All[fg & (fg >> 15)]; -#else uint32_t r = MIN(GPalette.BaseColors[colormap[pix]].r + GPalette.BaseColors[*dest].r, 255); uint32_t g = MIN(GPalette.BaseColors[colormap[pix]].g + GPalette.BaseColors[*dest].g, 255); uint32_t b = MIN(GPalette.BaseColors[colormap[pix]].b + GPalette.BaseColors[*dest].b, 255); *dest = RGB256k.RGB[r>>2][g>>2][b>>2]; -#endif } frac += fracstep; dest += pitch; @@ -364,17 +357,10 @@ namespace swrenderer uint8_t pix = _bufplce[i][vplce[i] >> bits]; if (pix != 0) { -#ifdef NO_RGB666 - uint32_t fg = fg2rgb[_palookupoffse[i][pix]]; - uint32_t bg = bg2rgb[dest[i]]; - fg = (fg + bg) | 0x1f07c1f; - dest[i] = RGB32k.All[fg & (fg >> 15)]; -#else uint32_t r = MIN(GPalette.BaseColors[_palookupoffse[i][pix]].r + GPalette.BaseColors[dest[i]].r, 255); uint32_t g = MIN(GPalette.BaseColors[_palookupoffse[i][pix]].g + GPalette.BaseColors[dest[i]].g, 255); uint32_t b = MIN(GPalette.BaseColors[_palookupoffse[i][pix]].b + GPalette.BaseColors[dest[i]].b, 255); dest[i] = RGB256k.RGB[r>>2][g>>2][b>>2]; -#endif } vplce[i] += vince[i]; } @@ -617,21 +603,10 @@ namespace swrenderer uint8_t pix = _bufplce[i][vplce[i] >> bits]; if (pix != 0) { -#ifdef NO_RGB666 - uint32_t a = (bg2rgb[dest[i]] | 0x40100400) - fg2rgb[_palookupoffse[i][pix]]; - uint32_t b = a; - - b &= 0x40100400; - b = b - (b >> 5); - a &= b; - a |= 0x01f07c1f; - dest[i] = RGB32k.All[a & (a >> 15)]; -#else uint32_t r = clamp(GPalette.BaseColors[_palookupoffse[i][pix]].r - GPalette.BaseColors[dest[i]].r, 0, 255); uint32_t g = clamp(GPalette.BaseColors[_palookupoffse[i][pix]].g - GPalette.BaseColors[dest[i]].g, 0, 255); uint32_t b = clamp(GPalette.BaseColors[_palookupoffse[i][pix]].b - GPalette.BaseColors[dest[i]].b, 0, 255); dest[i] = RGB256k.RGB[r>>2][g>>2][b>>2]; -#endif } vplce[i] += vince[i]; } @@ -715,11 +690,7 @@ namespace swrenderer c_red = (c_red * alpha_bottom + solid_bottom_r * inv_alpha_bottom) >> 8; c_green = (c_green * alpha_bottom + solid_bottom_g * inv_alpha_bottom) >> 8; c_blue = (c_blue * alpha_bottom + solid_bottom_b * inv_alpha_bottom) >> 8; -#ifdef NO_RGB666 - *dest = RGB32k.RGB[(c_red >> 3)][(c_green >> 3)][(c_blue >> 3)]; -#else *dest = RGB256k.RGB[(c_red >> 2)][(c_green >> 2)][(c_blue >> 2)]; -#endif } frac += fracstep; @@ -747,13 +718,8 @@ namespace swrenderer int solid_bottom_r = RPART(solid_bottom); int solid_bottom_g = GPART(solid_bottom); int solid_bottom_b = BPART(solid_bottom); -#ifdef NO_RGB666 - uint32_t solid_top_fill = RGB32k.RGB[(solid_top_r >> 3)][(solid_top_g >> 3)][(solid_top_b >> 3)]; - uint32_t solid_bottom_fill = RGB32k.RGB[(solid_bottom_r >> 3)][(solid_bottom_g >> 3)][(solid_bottom_b >> 3)]; -#else uint32_t solid_top_fill = RGB256k.RGB[(solid_top_r >> 2)][(solid_top_g >> 2)][(solid_top_b >> 2)]; uint32_t solid_bottom_fill = RGB256k.RGB[(solid_bottom_r >> 2)][(solid_bottom_g >> 2)][(solid_bottom_b >> 2)]; -#endif solid_top_fill = (solid_top_fill << 24) | (solid_top_fill << 16) | (solid_top_fill << 8) | solid_top_fill; solid_bottom_fill = (solid_bottom_fill << 24) | (solid_bottom_fill << 16) | (solid_bottom_fill << 8) | solid_bottom_fill; @@ -813,11 +779,7 @@ namespace swrenderer c_red = (c_red * alpha_top + solid_top_r * inv_alpha_top) >> 8; c_green = (c_green * alpha_top + solid_top_g * inv_alpha_top) >> 8; c_blue = (c_blue * alpha_top + solid_top_b * inv_alpha_top) >> 8; -#ifdef NO_RGB666 - output[col] = RGB32k.RGB[(c_red >> 3)][(c_green >> 3)][(c_blue >> 3)]; -#else output[col] = RGB256k.RGB[(c_red >> 2)][(c_green >> 2)][(c_blue >> 2)]; -#endif frac[col] += fracstep[col]; } *((uint32_t*)dest) = *((uint32_t*)output); @@ -858,11 +820,7 @@ namespace swrenderer c_red = (c_red * alpha_bottom + solid_bottom_r * inv_alpha_bottom) >> 8; c_green = (c_green * alpha_bottom + solid_bottom_g * inv_alpha_bottom) >> 8; c_blue = (c_blue * alpha_bottom + solid_bottom_b * inv_alpha_bottom) >> 8; -#ifdef NO_RGB666 - output[col] = RGB32k.RGB[(c_red >> 3)][(c_green >> 3)][(c_blue >> 3)]; -#else output[col] = RGB256k.RGB[(c_red >> 2)][(c_green >> 2)][(c_blue >> 2)]; -#endif frac[col] += fracstep[col]; } @@ -944,11 +902,7 @@ namespace swrenderer c_red = (c_red * alpha_bottom + solid_bottom_r * inv_alpha_bottom) >> 8; c_green = (c_green * alpha_bottom + solid_bottom_g * inv_alpha_bottom) >> 8; c_blue = (c_blue * alpha_bottom + solid_bottom_b * inv_alpha_bottom) >> 8; -#ifdef NO_RGB666 - *dest = RGB32k.RGB[(c_red >> 3)][(c_green >> 3)][(c_blue >> 3)]; -#else *dest = RGB256k.RGB[(c_red >> 2)][(c_green >> 2)][(c_blue >> 2)]; -#endif } frac += fracstep; @@ -978,13 +932,8 @@ namespace swrenderer int solid_bottom_r = RPART(solid_bottom); int solid_bottom_g = GPART(solid_bottom); int solid_bottom_b = BPART(solid_bottom); -#ifdef NO_RGB666 - uint32_t solid_top_fill = RGB32k.RGB[(solid_top_r >> 3)][(solid_top_g >> 3)][(solid_top_b >> 3)]; - uint32_t solid_bottom_fill = RGB32k.RGB[(solid_bottom_r >> 3)][(solid_bottom_g >> 3)][(solid_bottom_b >> 3)]; -#else uint32_t solid_top_fill = RGB256k.RGB[(solid_top_r >> 2)][(solid_top_g >> 2)][(solid_top_b >> 2)]; uint32_t solid_bottom_fill = RGB256k.RGB[(solid_bottom_r >> 2)][(solid_bottom_g >> 2)][(solid_bottom_b >> 2)]; -#endif solid_top_fill = (solid_top_fill << 24) | (solid_top_fill << 16) | (solid_top_fill << 8) | solid_top_fill; solid_bottom_fill = (solid_bottom_fill << 24) | (solid_bottom_fill << 16) | (solid_bottom_fill << 8) | solid_bottom_fill; @@ -1050,11 +999,7 @@ namespace swrenderer c_red = (c_red * alpha_top + solid_top_r * inv_alpha_top) >> 8; c_green = (c_green * alpha_top + solid_top_g * inv_alpha_top) >> 8; c_blue = (c_blue * alpha_top + solid_top_b * inv_alpha_top) >> 8; -#ifdef NO_RGB666 - output[col] = RGB32k.RGB[(c_red >> 3)][(c_green >> 3)][(c_blue >> 3)]; -#else output[col] = RGB256k.RGB[(c_red >> 2)][(c_green >> 2)][(c_blue >> 2)]; -#endif frac[col] += fracstep[col]; } @@ -1108,11 +1053,7 @@ namespace swrenderer c_red = (c_red * alpha_bottom + solid_bottom_r * inv_alpha_bottom) >> 8; c_green = (c_green * alpha_bottom + solid_bottom_g * inv_alpha_bottom) >> 8; c_blue = (c_blue * alpha_bottom + solid_bottom_b * inv_alpha_bottom) >> 8; -#ifdef NO_RGB666 - output[col] = RGB32k.RGB[(c_red >> 3)][(c_green >> 3)][(c_blue >> 3)]; -#else output[col] = RGB256k.RGB[(c_red >> 2)][(c_green >> 2)][(c_blue >> 2)]; -#endif frac[col] += fracstep[col]; } @@ -1244,9 +1185,12 @@ namespace swrenderer do { - uint32_t bg; - bg = (fg + bg2rgb[*dest]) | 0x1f07c1f; - *dest = RGB32k.All[bg & (bg >> 15)]; + const PalEntry* pal = GPalette.BaseColors; + // *** [SP] this is incomplete, not sure what to do here. + /*int r = clamp((int)pal[_srccolor].r, 0, 255) >> 2; + int g = clamp((int)pal[_srccolor].g, 0, 255) >> 2; + int b = clamp((int)pal[_srccolor].b, 0, 255) >> 2; + *dest = RGB256k.RGB[r][g][b];*/ dest += pitch; } while (--count); @@ -1276,15 +1220,11 @@ namespace swrenderer do { - uint32_t a = fg + bg2rgb[*dest]; - uint32_t b = a; - - a |= 0x01f07c1f; - b &= 0x40100400; - a &= 0x3fffffff; - b = b - (b >> 5); - a |= b; - *dest = RGB32k.All[a & (a >> 15)]; + const PalEntry* pal = GPalette.BaseColors; + int r = clamp(pal[*dest].r + pal[fg].r, 0, 255) >> 2; + int g = clamp(pal[*dest].g + pal[fg].g, 0, 255) >> 2; + int b = clamp(pal[*dest].b + pal[fg].b, 0, 255) >> 2; + *dest = RGB256k.RGB[r][g][b]; dest += pitch; } while (--count); } diff --git a/src/r_drawt_pal.cpp b/src/r_drawt_pal.cpp index 16d24ecaf..156e97ba6 100644 --- a/src/r_drawt_pal.cpp +++ b/src/r_drawt_pal.cpp @@ -446,14 +446,15 @@ namespace swrenderer source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4 + hx]; pitch = _pitch * thread->num_cores; colormap = _colormap; + const PalEntry *palette = GPalette.BaseColors; do { uint32_t fg = colormap[*source]; uint32_t bg = *dest; - int r = MIN((GPalette.BaseColors[fg].r * _srcalpha + GPalette.BaseColors[bg].r * _destalpha)>>18, 63); - int g = MIN((GPalette.BaseColors[fg].g * _srcalpha + GPalette.BaseColors[bg].g * _destalpha)>>18, 63); - int b = MIN((GPalette.BaseColors[fg].b * _srcalpha + GPalette.BaseColors[bg].b * _destalpha)>>18, 63); + int r = MIN((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 63); + int g = MIN((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 63); + int b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); *dest = RGB256k.RGB[r][g][b]; source += 4; dest += pitch; @@ -476,15 +477,16 @@ namespace swrenderer source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4]; pitch = _pitch * thread->num_cores; colormap = _colormap; + const PalEntry *palette = GPalette.BaseColors; do { for (int ks = 0; ks < 4; ks++) { // [SP] this 4col function was a block of copy-pasted code. 4 times. I regret nothing. uint32_t fg = colormap[source[ks]]; uint32_t bg = dest[ks]; - int r = MIN((GPalette.BaseColors[fg].r * _srcalpha + GPalette.BaseColors[bg].r * _destalpha)>>18, 63); - int g = MIN((GPalette.BaseColors[fg].g * _srcalpha + GPalette.BaseColors[bg].g * _destalpha)>>18, 63); - int b = MIN((GPalette.BaseColors[fg].b * _srcalpha + GPalette.BaseColors[bg].b * _destalpha)>>18, 63); + int r = MIN((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 63); + int g = MIN((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 63); + int b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); dest[ks] = RGB256k.RGB[r][g][b]; } @@ -511,13 +513,14 @@ namespace swrenderer dest = ylookup[yl + thread->skipped_by_thread(yl)] + sx + _destorg; source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4 + hx]; pitch = _pitch * thread->num_cores; + const PalEntry *palette = GPalette.BaseColors; do { uint32_t val = *source; - int r = (GPalette.BaseColors[*dest].r * (63-val) + GPalette.BaseColors[_color].r * val) >> 8; - int g = (GPalette.BaseColors[*dest].g * (63-val) + GPalette.BaseColors[_color].g * val) >> 8; - int b = (GPalette.BaseColors[*dest].b * (63-val) + GPalette.BaseColors[_color].b * val) >> 8; - *dest = RGB256k.RGB[MIN(r,63)][MIN(g,63)][MIN(b,63)]; + int r = (palette[*dest].r * (255-val)) >> 10; + int g = (palette[*dest].g * (255-val)) >> 10; + int b = (palette[*dest].b * (255-val)) >> 10; + *dest = RGB256k.RGB[clamp(r,0,63)][clamp(g,0,63)][clamp(b,0,63)]; source += 4; dest += pitch; } while (--count); @@ -541,6 +544,7 @@ namespace swrenderer dest = ylookup[yl + thread->skipped_by_thread(yl)] + sx + _destorg; source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4]; pitch = _pitch * thread->num_cores; + const PalEntry *palette = GPalette.BaseColors; do { uint32_t val; @@ -548,10 +552,10 @@ namespace swrenderer for (int ks = 0; ks < 4; ks++) { val = source[ks]; - int r = (GPalette.BaseColors[dest[ks]].r * (63-val) + GPalette.BaseColors[_color].r * val) >> 8; - int g = (GPalette.BaseColors[dest[ks]].g * (63-val) + GPalette.BaseColors[_color].g * val) >> 8; - int b = (GPalette.BaseColors[dest[ks]].b * (63-val) + GPalette.BaseColors[_color].b * val) >> 8; - dest[ks] = RGB256k.RGB[MIN(r,63)][MIN(g,63)][MIN(b,63)]; + int r = (palette[dest[ks]].r * (255-val)) >> 10; + int g = (palette[dest[ks]].g * (255-val)) >> 10; + int b = (palette[dest[ks]].b * (255-val)) >> 10; + dest[ks] = RGB256k.RGB[clamp(r,0,63)][clamp(g,0,63)][clamp(b,0,63)]; } source += 4; @@ -575,13 +579,14 @@ namespace swrenderer source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4 + hx]; pitch = _pitch * thread->num_cores; colormap = _colormap; + const PalEntry *palette = GPalette.BaseColors; do { int fg = *source; int bg = *dest; - int r = MIN((GPalette.BaseColors[fg].r * _srcalpha + GPalette.BaseColors[bg].r * _destalpha)>>18, 63); - int g = MIN((GPalette.BaseColors[fg].g * _srcalpha + GPalette.BaseColors[bg].g * _destalpha)>>18, 63); - int b = MIN((GPalette.BaseColors[fg].b * _srcalpha + GPalette.BaseColors[bg].b * _destalpha)>>18, 63); + int r = MIN((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 63); + int g = MIN((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 63); + int b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); *dest = RGB256k.RGB[r][g][b]; source += 4; dest += pitch; @@ -604,15 +609,16 @@ namespace swrenderer source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4]; pitch = _pitch * thread->num_cores; colormap = _colormap; + const PalEntry *palette = GPalette.BaseColors; do { for (int ks = 0; ks < 4; ks++) { int fg = source[ks]; int bg = dest[ks]; - int r = MIN((GPalette.BaseColors[fg].r * _srcalpha + GPalette.BaseColors[bg].r * _destalpha)>>18, 63); - int g = MIN((GPalette.BaseColors[fg].g * _srcalpha + GPalette.BaseColors[bg].g * _destalpha)>>18, 63); - int b = MIN((GPalette.BaseColors[fg].b * _srcalpha + GPalette.BaseColors[bg].b * _destalpha)>>18, 63); + int r = MIN((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 63); + int g = MIN((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 63); + int b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); dest[ks] = RGB256k.RGB[r][g][b]; } @@ -639,16 +645,15 @@ namespace swrenderer source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4 + hx]; pitch = _pitch * thread->num_cores; colormap = _colormap; + const PalEntry *palette = GPalette.BaseColors; do { - uint32_t a = (fg2rgb[colormap[*source]] | 0x40100400) - bg2rgb[*dest]; - uint32_t b = a; - - b &= 0x40100400; - b = b - (b >> 5); - a &= b; - a |= 0x01f07c1f; - *dest = RGB32k.All[(a>>15) & a]; + int fg = *source; + int bg = *dest; + int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + *dest = RGB256k.RGB[r][g][b]; source += 4; dest += pitch; } while (--count); @@ -672,40 +677,18 @@ namespace swrenderer source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4]; pitch = _pitch * thread->num_cores; colormap = _colormap; + const PalEntry *palette = GPalette.BaseColors; do { - uint32_t a = (fg2rgb[colormap[source[0]]] | 0x40100400) - bg2rgb[dest[0]]; - uint32_t b = a; - - b &= 0x40100400; - b = b - (b >> 5); - a &= b; - a |= 0x01f07c1f; - dest[0] = RGB32k.All[(a>>15) & a]; - - a = (fg2rgb[colormap[source[1]]] | 0x40100400) - bg2rgb[dest[1]]; - b = a; - b &= 0x40100400; - b = b - (b >> 5); - a &= b; - a |= 0x01f07c1f; - dest[1] = RGB32k.All[(a>>15) & a]; - - a = (fg2rgb[colormap[source[2]]] | 0x40100400) - bg2rgb[dest[2]]; - b = a; - b &= 0x40100400; - b = b - (b >> 5); - a &= b; - a |= 0x01f07c1f; - dest[2] = RGB32k.All[(a>>15) & a]; - - a = (fg2rgb[colormap[source[3]]] | 0x40100400) - bg2rgb[dest[3]]; - b = a; - b &= 0x40100400; - b = b - (b >> 5); - a &= b; - a |= 0x01f07c1f; - dest[3] = RGB32k.All[(a>>15) & a]; + for (int ks = 0; ks < 4; ks++) + { + int fg = source[ks]; + int bg = dest[ks]; + int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + dest[ks] = RGB256k.RGB[r][g][b]; + } source += 4; dest += pitch; @@ -730,16 +713,15 @@ namespace swrenderer source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4 + hx]; pitch = _pitch * thread->num_cores; colormap = _colormap; + const PalEntry *palette = GPalette.BaseColors; do { - uint32_t a = (bg2rgb[*dest] | 0x40100400) - fg2rgb[colormap[*source]]; - uint32_t b = a; - - b &= 0x40100400; - b = b - (b >> 5); - a &= b; - a |= 0x01f07c1f; - *dest = RGB32k.All[(a>>15) & a]; + int fg = *source; + int bg = *dest; + int r = MAX((-palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((-palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((-palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); + *dest = RGB256k.RGB[r][g][b]; source += 4; dest += pitch; } while (--count); @@ -763,40 +745,18 @@ namespace swrenderer source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4]; pitch = _pitch * thread->num_cores; colormap = _colormap; + const PalEntry *palette = GPalette.BaseColors; do { - uint32_t a = (bg2rgb[dest[0]] | 0x40100400) - fg2rgb[colormap[source[0]]]; - uint32_t b = a; - - b &= 0x40100400; - b = b - (b >> 5); - a &= b; - a |= 0x01f07c1f; - dest[0] = RGB32k.All[(a>>15) & a]; - - a = (bg2rgb[dest[1]] | 0x40100400) - fg2rgb[colormap[source[1]]]; - b = a; - b &= 0x40100400; - b = b - (b >> 5); - a &= b; - a |= 0x01f07c1f; - dest[1] = RGB32k.All[(a>>15) & a]; - - a = (bg2rgb[dest[2]] | 0x40100400) - fg2rgb[colormap[source[2]]]; - b = a; - b &= 0x40100400; - b = b - (b >> 5); - a &= b; - a |= 0x01f07c1f; - dest[2] = RGB32k.All[(a>>15) & a]; - - a = (bg2rgb[dest[3]] | 0x40100400) - fg2rgb[colormap[source[3]]]; - b = a; - b &= 0x40100400; - b = b - (b >> 5); - a &= b; - a |= 0x01f07c1f; - dest[3] = RGB32k.All[(a>>15) & a]; + for (int ks = 0; ks < 4; ks++) + { + int fg = source[ks]; + int bg = dest[ks]; + int r = MAX((-palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((-palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((-palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); + dest[ks] = RGB256k.RGB[r][g][b]; + } source += 4; dest += pitch; diff --git a/src/textures/pcxtexture.cpp b/src/textures/pcxtexture.cpp index 0ec5d2933..dda431993 100644 --- a/src/textures/pcxtexture.cpp +++ b/src/textures/pcxtexture.cpp @@ -528,7 +528,7 @@ void FPCXTexture::MakeTexture() { for(int x=0; x < Width; x++) { - Pixels[y+Height*x] = RGB32k.RGB[row[0]>>3][row[1]>>3][row[2]>>3]; + Pixels[y+Height*x] = RGB256k.RGB[row[0]>>2][row[1]>>2][row[2]>>2]; row+=3; } } From e4e0f0bcd912f11b9867ce7e72dd9fa8b43ee032 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sun, 18 Dec 2016 08:34:33 -0500 Subject: [PATCH 05/15] - playing a bit with the fill drawers --- src/r_draw_pal.cpp | 15 +++++++++------ src/v_video.cpp | 6 +----- src/v_video.h | 2 -- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/r_draw_pal.cpp b/src/r_draw_pal.cpp index 33c482934..9d15460af 100644 --- a/src/r_draw_pal.cpp +++ b/src/r_draw_pal.cpp @@ -1183,14 +1183,17 @@ namespace swrenderer dest = thread->dest_for_thread(_dest_y, pitch, dest); pitch *= thread->num_cores; + const PalEntry* pal = GPalette.BaseColors; + int _srcalpha = 32768, _destalpha = 32768; do { - const PalEntry* pal = GPalette.BaseColors; - // *** [SP] this is incomplete, not sure what to do here. - /*int r = clamp((int)pal[_srccolor].r, 0, 255) >> 2; - int g = clamp((int)pal[_srccolor].g, 0, 255) >> 2; - int b = clamp((int)pal[_srccolor].b, 0, 255) >> 2; - *dest = RGB256k.RGB[r][g][b];*/ + int src_r = ((_srccolor << 3) & 0x78) * _srcalpha; + int src_g = ((_srccolor >> 17) & 0x78) * _srcalpha; + int src_b = ((_srccolor >> 7) & 0x78) * _srcalpha; + int r = clamp((src_r + pal[*dest].r * _destalpha)>>18, 0, 255); + int g = clamp((src_g + pal[*dest].g * _destalpha)>>18, 0, 255); + int b = clamp((src_b + pal[*dest].b * _destalpha)>>18, 0, 255); + *dest = RGB256k.RGB[r][g][b]; dest += pitch; } while (--count); diff --git a/src/v_video.cpp b/src/v_video.cpp index 6e333f840..62a587281 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -144,9 +144,7 @@ DWORD Col2RGB8[65][256]; DWORD *Col2RGB8_LessPrecision[65]; DWORD Col2RGB8_Inverse[65][256]; ColorTable32k RGB32k; -#ifndef NO_RGB666 ColorTable256k RGB256k; -#endif } @@ -666,14 +664,12 @@ static void BuildTransTable (const PalEntry *palette) for (g = 0; g < 32; g++) for (b = 0; b < 32; b++) //RGB32k.RGB[r][g][b] = ColorMatcher.Pick ((r<<3)|(r>>2), (g<<3)|(g>>2), (b<<3)|(b>>2)); - RGB32k.RGB[r][g][b] = 2; -#ifndef NO_RGB666 + RGB32k.RGB[r][g][b] = 4; // create the RGB666 lookup table for (r = 0; r < 64; r++) for (g = 0; g < 64; g++) for (b = 0; b < 64; b++) RGB256k.RGB[r][g][b] = ColorMatcher.Pick ((r<<2)|(r>>4), (g<<2)|(g>>4), (b<<2)|(b>>4)); -#endif int x, y; diff --git a/src/v_video.h b/src/v_video.h index 2079ff64b..57d15869c 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -463,14 +463,12 @@ union ColorTable32k extern "C" ColorTable32k RGB32k; // [SP] RGB666 support -#ifndef NO_RGB666 union ColorTable256k { BYTE RGB[64][64][64]; BYTE All[64 *64 *64]; }; extern "C" ColorTable256k RGB256k; -#endif // Col2RGB8 is a pre-multiplied palette for color lookup. It is stored in a // special R10B10G10 format for efficient blending computation. From 1b50620a87d4dc477daf0aef24d0fb0be9a6840b Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sun, 18 Dec 2016 09:05:14 -0500 Subject: [PATCH 06/15] - finally decoded _srccolor in the fill drawers. still need to figure out how to get _srcalpha and _destalpha in there. --- src/r_draw_pal.cpp | 19 ++++++++++++------- src/r_draw_pal.h | 2 ++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/r_draw_pal.cpp b/src/r_draw_pal.cpp index 9d15460af..81975e23c 100644 --- a/src/r_draw_pal.cpp +++ b/src/r_draw_pal.cpp @@ -1187,9 +1187,9 @@ namespace swrenderer int _srcalpha = 32768, _destalpha = 32768; do { - int src_r = ((_srccolor << 3) & 0x78) * _srcalpha; - int src_g = ((_srccolor >> 17) & 0x78) * _srcalpha; - int src_b = ((_srccolor >> 7) & 0x78) * _srcalpha; + int src_r = ((_srccolor >> 16) & 0xff) * _srcalpha; + int src_g = ((_srccolor >> 0) & 0xff) * _srcalpha; + int src_b = ((_srccolor >> 8) & 0xff) * _srcalpha; int r = clamp((src_r + pal[*dest].r * _destalpha)>>18, 0, 255); int g = clamp((src_g + pal[*dest].g * _destalpha)>>18, 0, 255); int b = clamp((src_b + pal[*dest].b * _destalpha)>>18, 0, 255); @@ -1221,12 +1221,17 @@ namespace swrenderer dest = thread->dest_for_thread(_dest_y, pitch, dest); pitch *= thread->num_cores; + const PalEntry* pal = GPalette.BaseColors; + int _srcalpha = 32768, _destalpha = 32768; + do { - const PalEntry* pal = GPalette.BaseColors; - int r = clamp(pal[*dest].r + pal[fg].r, 0, 255) >> 2; - int g = clamp(pal[*dest].g + pal[fg].g, 0, 255) >> 2; - int b = clamp(pal[*dest].b + pal[fg].b, 0, 255) >> 2; + int src_r = ((_srccolor >> 16) & 0xff) * _srcalpha; + int src_g = ((_srccolor >> 0) & 0xff) * _srcalpha; + int src_b = ((_srccolor >> 8) & 0xff) * _srcalpha; + int r = clamp((src_r + pal[*dest].r * _destalpha)>>18, 0, 255); + int g = clamp((src_g + pal[*dest].g * _destalpha)>>18, 0, 255); + int b = clamp((src_b + pal[*dest].b * _destalpha)>>18, 0, 255); *dest = RGB256k.RGB[r][g][b]; dest += pitch; } while (--count); diff --git a/src/r_draw_pal.h b/src/r_draw_pal.h index 262b70387..54c74dc15 100644 --- a/src/r_draw_pal.h +++ b/src/r_draw_pal.h @@ -106,6 +106,8 @@ namespace swrenderer uint32_t *_srcblend; uint32_t *_destblend; uint32_t _srccolor; + fixed_t _srcalpha; + fixed_t _destalpha; }; class DrawColumnPalCommand : public PalColumnCommand { public: void Execute(DrawerThread *thread) override; }; From d687e52009384105fcf4ef6eb43919e5b76625e0 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sun, 18 Dec 2016 17:08:56 -0500 Subject: [PATCH 07/15] - renamed R_DrawParticle_C to R_DrawParticle to remove vestigial ASM hook. - fixed particle crashes, fixed particle color math. --- src/r_draw.cpp | 4 ---- src/r_draw.h | 1 - src/r_things.cpp | 10 ++++++---- src/r_things.h | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/r_draw.cpp b/src/r_draw.cpp index a461e1877..2c5d6fd91 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -1352,8 +1352,4 @@ namespace swrenderer } } - void R_DrawParticle(vissprite_t *sprite) - { - R_DrawParticle_C(sprite); - } } diff --git a/src/r_draw.h b/src/r_draw.h index 58934981b..f47179c51 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -201,5 +201,4 @@ namespace swrenderer void R_MapTiltedPlane(int y, int x1); void R_MapColoredPlane(int y, int x1); - void R_DrawParticle(vissprite_t *); } diff --git a/src/r_things.cpp b/src/r_things.cpp index 7c178ce8b..03900b321 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -2632,7 +2632,9 @@ static void R_DrawMaskedSegsBehindParticle (const vissprite_t *vis) } } -void R_DrawParticle_C (vissprite_t *vis) +//inline int clamp(int x, int y, int z) { return ((x < y) ? x : (z < y) ? z : y); } + +void R_DrawParticle (vissprite_t *vis) { int spacing; BYTE *dest; @@ -2666,9 +2668,9 @@ void R_DrawParticle_C (vissprite_t *vis) dest = ylookup[yl] + x + dc_destorg; for (int y = 0; y < ycount; y++) { - int dest_r = (GPalette.BaseColors[*dest].r * bglevel + GPalette.BaseColors[color].r * fglevel) >> 10; - int dest_g = (GPalette.BaseColors[*dest].g * bglevel + GPalette.BaseColors[color].g * fglevel) >> 10; - int dest_b = (GPalette.BaseColors[*dest].b * bglevel + GPalette.BaseColors[color].b * fglevel) >> 10; + uint32_t dest_r = MIN((GPalette.BaseColors[*dest].r * bglevel + GPalette.BaseColors[color].r * fglevel) >> 18, 63); + uint32_t dest_g = MIN((GPalette.BaseColors[*dest].g * bglevel + GPalette.BaseColors[color].g * fglevel) >> 18, 63); + uint32_t dest_b = MIN((GPalette.BaseColors[*dest].b * bglevel + GPalette.BaseColors[color].b * fglevel) >> 18, 63); *dest = RGB256k.RGB[dest_r][dest_g][dest_b]; dest += spacing; diff --git a/src/r_things.h b/src/r_things.h index bf32b655f..6b789cdc5 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -101,7 +101,7 @@ struct vissprite_t vissprite_t() {} }; -void R_DrawParticle_C (vissprite_t *); +void R_DrawParticle (vissprite_t *); void R_ProjectParticle (particle_t *, const sector_t *sector, int shade, int fakeside); extern int MaxVisSprites; From b7629fcf0e0f2980469b5608567d20783db0bc78 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Mon, 19 Dec 2016 03:08:10 -0500 Subject: [PATCH 08/15] - This space intentionally left blank. - And white rabbits. --- src/r_draw_pal.cpp | 297 +++++++++++++++++++++------------------------ src/r_draw_pal.h | 2 + 2 files changed, 137 insertions(+), 162 deletions(-) diff --git a/src/r_draw_pal.cpp b/src/r_draw_pal.cpp index 81975e23c..9f474911e 100644 --- a/src/r_draw_pal.cpp +++ b/src/r_draw_pal.cpp @@ -4,6 +4,7 @@ **--------------------------------------------------------------------------- ** Copyright 1998-2016 Randy Heit ** Copyright 2016 Magnus Norddahl +** Copyright 2016 Rachael Alexanderson ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without @@ -1089,6 +1090,8 @@ namespace swrenderer _srcblend = dc_srcblend; _destblend = dc_destblend; _srccolor = dc_srccolor; + _srcalpha = dc_srcalpha; + _destalpha = dc_destalpha; } void DrawColumnPalCommand::Execute(DrawerThread *thread) @@ -1184,7 +1187,7 @@ namespace swrenderer pitch *= thread->num_cores; const PalEntry* pal = GPalette.BaseColors; - int _srcalpha = 32768, _destalpha = 32768; + do { int src_r = ((_srccolor >> 16) & 0xff) * _srcalpha; @@ -1222,7 +1225,6 @@ namespace swrenderer pitch *= thread->num_cores; const PalEntry* pal = GPalette.BaseColors; - int _srcalpha = 32768, _destalpha = 32768; do { @@ -1245,11 +1247,7 @@ namespace swrenderer count = _count; dest = _dest; - uint32_t *bg2rgb; - uint32_t fg; - bg2rgb = _destblend; - fg = _srccolor | 0x40100400; int pitch = _pitch; count = thread->count_for_thread(_dest_y, count); @@ -1259,16 +1257,19 @@ namespace swrenderer dest = thread->dest_for_thread(_dest_y, pitch, dest); pitch *= thread->num_cores; + const PalEntry* palette = GPalette.BaseColors; + do { - uint32_t a = fg - bg2rgb[*dest]; - uint32_t b = a; + int src_r = ((_srccolor >> 16) & 0xff) * _srcalpha; + int src_g = ((_srccolor >> 0) & 0xff) * _srcalpha; + int src_b = ((_srccolor >> 8) & 0xff) * _srcalpha; + int bg = *dest; + int r = MAX((src_r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); + int g = MAX((src_g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); + int b = MAX((src_b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); - b &= 0x40100400; - b = b - (b >> 5); - a &= b; - a |= 0x01f07c1f; - *dest = RGB32k.All[a & (a >> 15)]; + *dest = RGB256k.RGB[r][g][b]; dest += pitch; } while (--count); } @@ -1283,11 +1284,7 @@ namespace swrenderer return; dest = _dest; - uint32_t *bg2rgb; - uint32_t fg; - bg2rgb = _destblend; - fg = _srccolor; int pitch = _pitch; count = thread->count_for_thread(_dest_y, count); @@ -1297,16 +1294,19 @@ namespace swrenderer dest = thread->dest_for_thread(_dest_y, pitch, dest); pitch *= thread->num_cores; + const PalEntry *palette = GPalette.BaseColors; + do { - uint32_t a = (bg2rgb[*dest] | 0x40100400) - fg; - uint32_t b = a; + int src_r = ((_srccolor >> 16) & 0xff) * _srcalpha; + int src_g = ((_srccolor >> 0) & 0xff) * _srcalpha; + int src_b = ((_srccolor >> 8) & 0xff) * _srcalpha; + int bg = *dest; + int r = MAX((src_r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); + int g = MAX((src_g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); + int b = MAX((src_b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); - b &= 0x40100400; - b = b - (b >> 5); - a &= b; - a |= 0x01f07c1f; - *dest = RGB32k.All[a & (a >> 15)]; + *dest = RGB256k.RGB[r][g][b]; dest += pitch; } while (--count); } @@ -1334,20 +1334,18 @@ namespace swrenderer fracstep *= thread->num_cores; pitch *= thread->num_cores; - uint32_t *fg2rgb = _srcblend; - uint32_t *bg2rgb = _destblend; const uint8_t *colormap = _colormap; const uint8_t *source = _source; + const PalEntry *palette = GPalette.BaseColors; do { uint32_t fg = colormap[source[frac >> FRACBITS]]; uint32_t bg = *dest; - - fg = fg2rgb[fg]; - bg = bg2rgb[bg]; - fg = (fg + bg) | 0x1f07c1f; - *dest = RGB32k.All[fg & (fg >> 15)]; + uint32_t r = MIN((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 63); + uint32_t g = MIN((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 63); + uint32_t b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); + *dest = RGB256k.RGB[r][g][b]; dest += pitch; frac += fracstep; } while (--count); @@ -1414,21 +1412,20 @@ namespace swrenderer fracstep *= thread->num_cores; pitch *= thread->num_cores; - uint32_t *fg2rgb = _srcblend; - uint32_t *bg2rgb = _destblend; const uint8_t *translation = _translation; const uint8_t *colormap = _colormap; const uint8_t *source = _source; + const PalEntry *palette = GPalette.BaseColors; + do { uint32_t fg = colormap[translation[source[frac >> FRACBITS]]]; uint32_t bg = *dest; - - fg = fg2rgb[fg]; - bg = bg2rgb[bg]; - fg = (fg + bg) | 0x1f07c1f; - *dest = RGB32k.All[fg & (fg >> 15)]; + uint32_t r = MIN((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 63); + uint32_t g = MIN((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 63); + uint32_t b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); + *dest = RGB256k.RGB[r][g][b]; dest += pitch; frac += fracstep; } while (--count); @@ -1460,12 +1457,16 @@ namespace swrenderer const uint8_t *colormap = _colormap; uint32_t *fgstart = &Col2RGB8[0][_color]; + const PalEntry *palette = GPalette.BaseColors; + do { - uint32_t val = colormap[source[frac >> FRACBITS]]; - uint32_t fg = fgstart[val << 8]; - val = (Col2RGB8[64 - val][*dest] + fg) | 0x1f07c1f; - *dest = RGB32k.All[val & (val >> 15)]; + uint32_t val = source[frac >> FRACBITS]; + + int r = (palette[*dest].r * (255-val)) >> 10; + int g = (palette[*dest].g * (255-val)) >> 10; + int b = (palette[*dest].b * (255-val)) >> 10; + *dest = RGB256k.RGB[clamp(r,0,63)][clamp(g,0,63)][clamp(b,0,63)]; dest += pitch; frac += fracstep; @@ -1497,20 +1498,16 @@ namespace swrenderer const uint8_t *colormap = _colormap; const uint8_t *source = _source; - uint32_t *fg2rgb = _srcblend; - uint32_t *bg2rgb = _destblend; + const PalEntry *palette = GPalette.BaseColors; do { - uint32_t a = fg2rgb[colormap[source[frac >> FRACBITS]]] + bg2rgb[*dest]; - uint32_t b = a; - - a |= 0x01f07c1f; - b &= 0x40100400; - a &= 0x3fffffff; - b = b - (b >> 5); - a |= b; - *dest = RGB32k.All[a & (a >> 15)]; + int fg = colormap[source[frac >> FRACBITS]]; + int bg = *dest; + int r = MIN((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 63); + int g = MIN((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 63); + int b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); + *dest = RGB256k.RGB[r][g][b]; dest += pitch; frac += fracstep; } while (--count); @@ -1542,20 +1539,16 @@ namespace swrenderer const uint8_t *translation = _translation; const uint8_t *colormap = _colormap; const uint8_t *source = _source; - uint32_t *fg2rgb = _srcblend; - uint32_t *bg2rgb = _destblend; + const PalEntry *palette = GPalette.BaseColors; do { - uint32_t a = fg2rgb[colormap[translation[source[frac >> FRACBITS]]]] + bg2rgb[*dest]; - uint32_t b = a; - - a |= 0x01f07c1f; - b &= 0x40100400; - a &= 0x3fffffff; - b = b - (b >> 5); - a |= b; - *dest = RGB32k.All[(a >> 15) & a]; + int fg = colormap[translation[source[frac >> FRACBITS]]]; + int bg = *dest; + int r = MIN((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 63); + int g = MIN((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 63); + int b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); + *dest = RGB256k.RGB[r][g][b]; dest += pitch; frac += fracstep; } while (--count); @@ -1586,19 +1579,16 @@ namespace swrenderer const uint8_t *colormap = _colormap; const uint8_t *source = _source; - uint32_t *fg2rgb = _srcblend; - uint32_t *bg2rgb = _destblend; + const PalEntry *palette = GPalette.BaseColors; do { - uint32_t a = (fg2rgb[colormap[source[frac >> FRACBITS]]] | 0x40100400) - bg2rgb[*dest]; - uint32_t b = a; - - b &= 0x40100400; - b = b - (b >> 5); - a &= b; - a |= 0x01f07c1f; - *dest = RGB32k.All[a & (a >> 15)]; + int fg = colormap[source[frac >> FRACBITS]]; + int bg = *dest; + int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + *dest = RGB256k.RGB[r][g][b]; dest += pitch; frac += fracstep; } while (--count); @@ -1630,19 +1620,16 @@ namespace swrenderer const uint8_t *translation = _translation; const uint8_t *colormap = _colormap; const uint8_t *source = _source; - uint32_t *fg2rgb = _srcblend; - uint32_t *bg2rgb = _destblend; + const PalEntry *palette = GPalette.BaseColors; do { - uint32_t a = (fg2rgb[colormap[translation[source[frac >> FRACBITS]]]] | 0x40100400) - bg2rgb[*dest]; - uint32_t b = a; - - b &= 0x40100400; - b = b - (b >> 5); - a &= b; - a |= 0x01f07c1f; - *dest = RGB32k.All[(a >> 15) & a]; + int fg = colormap[translation[source[frac >> FRACBITS]]]; + int bg = *dest; + int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + *dest = RGB256k.RGB[r][g][b]; dest += pitch; frac += fracstep; } while (--count); @@ -1673,19 +1660,16 @@ namespace swrenderer const uint8_t *colormap = _colormap; const uint8_t *source = _source; - uint32_t *fg2rgb = _srcblend; - uint32_t *bg2rgb = _destblend; + const PalEntry *palette = GPalette.BaseColors; do { - uint32_t a = (bg2rgb[*dest] | 0x40100400) - fg2rgb[colormap[source[frac >> FRACBITS]]]; - uint32_t b = a; - - b &= 0x40100400; - b = b - (b >> 5); - a &= b; - a |= 0x01f07c1f; - *dest = RGB32k.All[a & (a >> 15)]; + int fg = colormap[source[frac >> FRACBITS]]; + int bg = *dest; + int r = MAX((-palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((-palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((-palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); + *dest = RGB256k.RGB[r][g][b]; dest += pitch; frac += fracstep; } while (--count); @@ -1717,19 +1701,16 @@ namespace swrenderer const uint8_t *translation = _translation; const uint8_t *colormap = _colormap; const uint8_t *source = _source; - uint32_t *fg2rgb = _srcblend; - uint32_t *bg2rgb = _destblend; + const PalEntry *palette = GPalette.BaseColors; do { - uint32_t a = (bg2rgb[*dest] | 0x40100400) - fg2rgb[colormap[translation[source[frac >> FRACBITS]]]]; - uint32_t b = a; - - b &= 0x40100400; - b = b - (b >> 5); - a &= b; - a |= 0x01f07c1f; - *dest = RGB32k.All[(a >> 15) & a]; + int fg = colormap[translation[source[frac >> FRACBITS]]]; + int bg = *dest; + int r = MAX((-palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((-palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((-palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); + *dest = RGB256k.RGB[r][g][b]; dest += pitch; frac += fracstep; } while (--count); @@ -1845,6 +1826,8 @@ namespace swrenderer _srcblend = dc_srcblend; _destblend = dc_destblend; _color = ds_color; + _srcalpha = dc_srcalpha; + _destalpha = dc_destalpha; } void DrawSpanPalCommand::Execute(DrawerThread *thread) @@ -1990,8 +1973,6 @@ namespace swrenderer const uint8_t *colormap = _colormap; int count; int spot; - uint32_t *fg2rgb = _srcblend; - uint32_t *bg2rgb = _destblend; xfrac = _xfrac; yfrac = _yfrac; @@ -2003,6 +1984,8 @@ namespace swrenderer xstep = _xstep; ystep = _ystep; + const PalEntry *palette = GPalette.BaseColors; + if (_xbits == 6 && _ybits == 6) { // 64x64 is the most common case by far, so special case it. @@ -2011,10 +1994,11 @@ namespace swrenderer spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); uint32_t fg = colormap[source[spot]]; uint32_t bg = *dest; - fg = fg2rgb[fg]; - bg = bg2rgb[bg]; - fg = (fg + bg) | 0x1f07c1f; - *dest++ = RGB32k.All[fg & (fg >> 15)]; + int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + *dest++ = RGB256k.RGB[r][g][b]; + xfrac += xstep; yfrac += ystep; } while (--count); @@ -2029,10 +2013,11 @@ namespace swrenderer spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); uint32_t fg = colormap[source[spot]]; uint32_t bg = *dest; - fg = fg2rgb[fg]; - bg = bg2rgb[bg]; - fg = (fg + bg) | 0x1f07c1f; - *dest++ = RGB32k.All[fg & (fg >> 15)]; + int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + *dest++ = RGB256k.RGB[r][g][b]; + xfrac += xstep; yfrac += ystep; } while (--count); @@ -2053,8 +2038,8 @@ namespace swrenderer const uint8_t *colormap = _colormap; int count; int spot; - uint32_t *fg2rgb = _srcblend; - uint32_t *bg2rgb = _destblend; + + const PalEntry *palette = GPalette.BaseColors; xfrac = _xfrac; yfrac = _yfrac; @@ -2079,10 +2064,10 @@ namespace swrenderer { uint32_t fg = colormap[texdata]; uint32_t bg = *dest; - fg = fg2rgb[fg]; - bg = bg2rgb[bg]; - fg = (fg + bg) | 0x1f07c1f; - *dest = RGB32k.All[fg & (fg >> 15)]; + int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + *dest = RGB256k.RGB[r][g][b]; } dest++; xfrac += xstep; @@ -2104,10 +2089,10 @@ namespace swrenderer { uint32_t fg = colormap[texdata]; uint32_t bg = *dest; - fg = fg2rgb[fg]; - bg = bg2rgb[bg]; - fg = (fg + bg) | 0x1f07c1f; - *dest = RGB32k.All[fg & (fg >> 15)]; + int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + *dest = RGB256k.RGB[r][g][b]; } dest++; xfrac += xstep; @@ -2130,8 +2115,7 @@ namespace swrenderer const uint8_t *colormap = _colormap; int count; int spot; - uint32_t *fg2rgb = _srcblend; - uint32_t *bg2rgb = _destblend; + const PalEntry *palette = GPalette.BaseColors; xfrac = _xfrac; yfrac = _yfrac; @@ -2149,15 +2133,13 @@ namespace swrenderer do { spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); - uint32_t a = fg2rgb[colormap[source[spot]]] + bg2rgb[*dest]; - uint32_t b = a; + uint32_t fg = colormap[source[spot]]; + uint32_t bg = *dest; + int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + *dest++ = RGB256k.RGB[r][g][b]; - a |= 0x01f07c1f; - b &= 0x40100400; - a &= 0x3fffffff; - b = b - (b >> 5); - a |= b; - *dest++ = RGB32k.All[a & (a >> 15)]; xfrac += xstep; yfrac += ystep; } while (--count); @@ -2170,15 +2152,13 @@ namespace swrenderer do { spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); - uint32_t a = fg2rgb[colormap[source[spot]]] + bg2rgb[*dest]; - uint32_t b = a; + uint32_t fg = colormap[source[spot]]; + uint32_t bg = *dest; + int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + *dest++ = RGB256k.RGB[r][g][b]; - a |= 0x01f07c1f; - b &= 0x40100400; - a &= 0x3fffffff; - b = b - (b >> 5); - a |= b; - *dest++ = RGB32k.All[a & (a >> 15)]; xfrac += xstep; yfrac += ystep; } while (--count); @@ -2199,8 +2179,7 @@ namespace swrenderer const uint8_t *colormap = _colormap; int count; int spot; - uint32_t *fg2rgb = _srcblend; - uint32_t *bg2rgb = _destblend; + const PalEntry *palette = GPalette.BaseColors; xfrac = _xfrac; yfrac = _yfrac; @@ -2223,15 +2202,12 @@ namespace swrenderer texdata = source[spot]; if (texdata != 0) { - uint32_t a = fg2rgb[colormap[texdata]] + bg2rgb[*dest]; - uint32_t b = a; - - a |= 0x01f07c1f; - b &= 0x40100400; - a &= 0x3fffffff; - b = b - (b >> 5); - a |= b; - *dest = RGB32k.All[a & (a >> 15)]; + uint32_t fg = colormap[texdata]; + uint32_t bg = *dest; + int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + *dest = RGB256k.RGB[r][g][b]; } dest++; xfrac += xstep; @@ -2251,15 +2227,12 @@ namespace swrenderer texdata = source[spot]; if (texdata != 0) { - uint32_t a = fg2rgb[colormap[texdata]] + bg2rgb[*dest]; - uint32_t b = a; - - a |= 0x01f07c1f; - b &= 0x40100400; - a &= 0x3fffffff; - b = b - (b >> 5); - a |= b; - *dest = RGB32k.All[a & (a >> 15)]; + uint32_t fg = colormap[texdata]; + uint32_t bg = *dest; + int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + *dest = RGB256k.RGB[r][g][b]; } dest++; xfrac += xstep; diff --git a/src/r_draw_pal.h b/src/r_draw_pal.h index 54c74dc15..0b1a5eebf 100644 --- a/src/r_draw_pal.h +++ b/src/r_draw_pal.h @@ -166,6 +166,8 @@ namespace swrenderer uint32_t *_srcblend; uint32_t *_destblend; int _color; + fixed_t _srcalpha; + fixed_t _destalpha; }; class DrawSpanPalCommand : public PalSpanCommand { public: void Execute(DrawerThread *thread) override; }; From c7d4d7cd1db1b5418150b5a74a6bc478c2aa2850 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Mon, 19 Dec 2016 03:51:54 -0500 Subject: [PATCH 09/15] - fixed: Sometimes it helps to stay positive. Especially when deciding whether to add or subtract the background in the span drawers. --- src/r_draw_pal.cpp | 48 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/r_draw_pal.cpp b/src/r_draw_pal.cpp index 9f474911e..a1bddb16b 100644 --- a/src/r_draw_pal.cpp +++ b/src/r_draw_pal.cpp @@ -1994,9 +1994,9 @@ namespace swrenderer spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); uint32_t fg = colormap[source[spot]]; uint32_t bg = *dest; - int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); - int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); - int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); *dest++ = RGB256k.RGB[r][g][b]; xfrac += xstep; @@ -2013,9 +2013,9 @@ namespace swrenderer spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); uint32_t fg = colormap[source[spot]]; uint32_t bg = *dest; - int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); - int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); - int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); *dest++ = RGB256k.RGB[r][g][b]; xfrac += xstep; @@ -2064,9 +2064,9 @@ namespace swrenderer { uint32_t fg = colormap[texdata]; uint32_t bg = *dest; - int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); - int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); - int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); *dest = RGB256k.RGB[r][g][b]; } dest++; @@ -2089,9 +2089,9 @@ namespace swrenderer { uint32_t fg = colormap[texdata]; uint32_t bg = *dest; - int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); - int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); - int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); *dest = RGB256k.RGB[r][g][b]; } dest++; @@ -2135,9 +2135,9 @@ namespace swrenderer spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); uint32_t fg = colormap[source[spot]]; uint32_t bg = *dest; - int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); - int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); - int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); *dest++ = RGB256k.RGB[r][g][b]; xfrac += xstep; @@ -2154,9 +2154,9 @@ namespace swrenderer spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); uint32_t fg = colormap[source[spot]]; uint32_t bg = *dest; - int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); - int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); - int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); *dest++ = RGB256k.RGB[r][g][b]; xfrac += xstep; @@ -2204,9 +2204,9 @@ namespace swrenderer { uint32_t fg = colormap[texdata]; uint32_t bg = *dest; - int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); - int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); - int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); *dest = RGB256k.RGB[r][g][b]; } dest++; @@ -2229,9 +2229,9 @@ namespace swrenderer { uint32_t fg = colormap[texdata]; uint32_t bg = *dest; - int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); - int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); - int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); *dest = RGB256k.RGB[r][g][b]; } dest++; From 2d0960044c12439f81800628129c4b2b2ec540d1 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Mon, 19 Dec 2016 04:01:25 -0500 Subject: [PATCH 10/15] - Added colormap checking to some blending drawers that were missing it. --- src/r_drawt_pal.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/r_drawt_pal.cpp b/src/r_drawt_pal.cpp index 156e97ba6..ebf0ea00e 100644 --- a/src/r_drawt_pal.cpp +++ b/src/r_drawt_pal.cpp @@ -582,7 +582,7 @@ namespace swrenderer const PalEntry *palette = GPalette.BaseColors; do { - int fg = *source; + int fg = colormap[*source]; int bg = *dest; int r = MIN((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 63); int g = MIN((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 63); @@ -614,7 +614,7 @@ namespace swrenderer do { for (int ks = 0; ks < 4; ks++) { - int fg = source[ks]; + int fg = colormap[source[ks]]; int bg = dest[ks]; int r = MIN((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 63); int g = MIN((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 63); @@ -648,7 +648,7 @@ namespace swrenderer const PalEntry *palette = GPalette.BaseColors; do { - int fg = *source; + int fg = colormap[*source]; int bg = *dest; int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); @@ -682,7 +682,7 @@ namespace swrenderer do { for (int ks = 0; ks < 4; ks++) { - int fg = source[ks]; + int fg = colormap[source[ks]]; int bg = dest[ks]; int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); @@ -716,7 +716,7 @@ namespace swrenderer const PalEntry *palette = GPalette.BaseColors; do { - int fg = *source; + int fg = colormap[*source]; int bg = *dest; int r = MAX((-palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); int g = MAX((-palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); @@ -750,7 +750,7 @@ namespace swrenderer do { for (int ks = 0; ks < 4; ks++) { - int fg = source[ks]; + int fg = colormap[source[ks]]; int bg = dest[ks]; int r = MAX((-palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); int g = MAX((-palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); From e2be28f92556249cae3f610042f5593c88af58bc Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Mon, 19 Dec 2016 04:27:56 -0500 Subject: [PATCH 11/15] - 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; From 1e9d48216c6578bbce183252dab32757ec820bb5 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Mon, 19 Dec 2016 04:45:08 -0500 Subject: [PATCH 12/15] - removed all references to COL2RGB8 and RGB32k. Everything has now been transformed to RGB256k. --- src/f_wipe.cpp | 2 -- src/r_draw.cpp | 6 ------ src/r_draw_pal.cpp | 1 - src/r_drawt_pal.cpp | 2 -- src/r_plane.cpp | 16 ++++++++-------- src/v_video.cpp | 37 ------------------------------------- src/v_video.h | 39 --------------------------------------- 7 files changed, 8 insertions(+), 95 deletions(-) diff --git a/src/f_wipe.cpp b/src/f_wipe.cpp index 352122007..8d5f072f6 100644 --- a/src/f_wipe.cpp +++ b/src/f_wipe.cpp @@ -346,8 +346,6 @@ bool wipe_doFade (int ticks) { int x, y; int bglevel = 64 - fade; - DWORD *fg2rgb = Col2RGB8[fade]; - DWORD *bg2rgb = Col2RGB8[bglevel]; BYTE *fromnew = (BYTE *)wipe_scr_end; BYTE *fromold = (BYTE *)wipe_scr_start; BYTE *to = screen->GetBuffer(); diff --git a/src/r_draw.cpp b/src/r_draw.cpp index 2d86ee985..62e92273e 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -238,22 +238,16 @@ namespace swrenderer } if (flags & STYLEF_InvertSource) { - dc_srcblend = Col2RGB8_Inverse[fglevel >> 10]; - dc_destblend = Col2RGB8_LessPrecision[bglevel >> 10]; dc_srcalpha = fglevel; dc_destalpha = bglevel; } else if (op == STYLEOP_Add && fglevel + bglevel <= FRACUNIT) { - dc_srcblend = Col2RGB8[fglevel >> 10]; - dc_destblend = Col2RGB8[bglevel >> 10]; dc_srcalpha = fglevel; dc_destalpha = bglevel; } else { - dc_srcblend = Col2RGB8_LessPrecision[fglevel >> 10]; - dc_destblend = Col2RGB8_LessPrecision[bglevel >> 10]; dc_srcalpha = fglevel; dc_destalpha = bglevel; } diff --git a/src/r_draw_pal.cpp b/src/r_draw_pal.cpp index a1bddb16b..b99f58f88 100644 --- a/src/r_draw_pal.cpp +++ b/src/r_draw_pal.cpp @@ -1455,7 +1455,6 @@ namespace swrenderer const uint8_t *source = _source; const uint8_t *colormap = _colormap; - uint32_t *fgstart = &Col2RGB8[0][_color]; const PalEntry *palette = GPalette.BaseColors; diff --git a/src/r_drawt_pal.cpp b/src/r_drawt_pal.cpp index ebf0ea00e..27c2a4294 100644 --- a/src/r_drawt_pal.cpp +++ b/src/r_drawt_pal.cpp @@ -508,7 +508,6 @@ namespace swrenderer if (count <= 0) return; - fgstart = &Col2RGB8[0][_color]; colormap = _colormap; dest = ylookup[yl + thread->skipped_by_thread(yl)] + sx + _destorg; source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4 + hx]; @@ -539,7 +538,6 @@ namespace swrenderer if (count <= 0) return; - fgstart = &Col2RGB8[0][_color]; colormap = _colormap; dest = ylookup[yl + thread->skipped_by_thread(yl)] + sx + _destorg; source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4]; diff --git a/src/r_plane.cpp b/src/r_plane.cpp index eafc9fa26..1a7758923 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -1500,14 +1500,14 @@ void R_DrawNormalPlane (visplane_t *pl, double _xscale, double _yscale, fixed_t if (!additive) { spanfunc = R_DrawSpanMaskedTranslucent; - dc_srcblend = Col2RGB8[alpha>>10]; - dc_destblend = Col2RGB8[(OPAQUE-alpha)>>10]; + dc_srcalpha = alpha; + dc_destalpha = OPAQUE-alpha; } else { spanfunc = R_DrawSpanMaskedAddClamp; - dc_srcblend = Col2RGB8_LessPrecision[alpha>>10]; - dc_destblend = Col2RGB8_LessPrecision[FRACUNIT>>10]; + dc_srcalpha = alpha; + dc_destalpha = FRACUNIT; } } else @@ -1522,14 +1522,14 @@ void R_DrawNormalPlane (visplane_t *pl, double _xscale, double _yscale, fixed_t if (!additive) { spanfunc = R_DrawSpanTranslucent; - dc_srcblend = Col2RGB8[alpha>>10]; - dc_destblend = Col2RGB8[(OPAQUE-alpha)>>10]; + dc_srcalpha = alpha; + dc_destalpha = OPAQUE-alpha; } else { spanfunc = R_DrawSpanAddClamp; - dc_srcblend = Col2RGB8_LessPrecision[alpha>>10]; - dc_destblend = Col2RGB8_LessPrecision[FRACUNIT>>10]; + dc_srcalpha = alpha; + dc_destalpha = OPAQUE-alpha; } } else diff --git a/src/v_video.cpp b/src/v_video.cpp index 62a587281..b639939ee 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -143,7 +143,6 @@ extern "C" { DWORD Col2RGB8[65][256]; DWORD *Col2RGB8_LessPrecision[65]; DWORD Col2RGB8_Inverse[65][256]; -ColorTable32k RGB32k; ColorTable256k RGB256k; } @@ -659,48 +658,12 @@ static void BuildTransTable (const PalEntry *palette) { int r, g, b; - // create the RGB555 lookup table - for (r = 0; r < 32; r++) - for (g = 0; g < 32; g++) - for (b = 0; b < 32; b++) - //RGB32k.RGB[r][g][b] = ColorMatcher.Pick ((r<<3)|(r>>2), (g<<3)|(g>>2), (b<<3)|(b>>2)); - RGB32k.RGB[r][g][b] = 4; // create the RGB666 lookup table for (r = 0; r < 64; r++) for (g = 0; g < 64; g++) for (b = 0; b < 64; b++) RGB256k.RGB[r][g][b] = ColorMatcher.Pick ((r<<2)|(r>>4), (g<<2)|(g>>4), (b<<2)|(b>>4)); - int x, y; - - // create the swizzled palette - for (x = 0; x < 65; x++) - for (y = 0; y < 256; y++) - Col2RGB8[x][y] = (((palette[y].r*x)>>4)<<20) | - ((palette[y].g*x)>>4) | - (((palette[y].b*x)>>4)<<10); - - // create the swizzled palette with the lsb of red and blue forced to 0 - // (for green, a 1 is okay since it never gets added into) - for (x = 1; x < 64; x++) - { - Col2RGB8_LessPrecision[x] = Col2RGB8_2[x-1]; - for (y = 0; y < 256; y++) - { - Col2RGB8_2[x-1][y] = Col2RGB8[x][y] & 0x3feffbff; - } - } - Col2RGB8_LessPrecision[0] = Col2RGB8[0]; - Col2RGB8_LessPrecision[64] = Col2RGB8[64]; - - // create the inverse swizzled palette - for (x = 0; x < 65; x++) - for (y = 0; y < 256; y++) - { - Col2RGB8_Inverse[x][y] = (((((255-palette[y].r)*x)>>4)<<20) | - (((255-palette[y].g)*x)>>4) | - ((((255-palette[y].b)*x)>>4)<<10)) & 0x3feffbff; - } } //========================================================================== diff --git a/src/v_video.h b/src/v_video.h index 57d15869c..0da6b9b50 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -448,20 +448,6 @@ EXTERN_CVAR (Float, Gamma) // Translucency tables -// RGB32k is a normal R5G5B5 -> palette lookup table. - -// Use a union so we can "overflow" without warnings. -// Otherwise, we get stuff like this from Clang (when compiled -// with -fsanitize=bounds) while running: -// src/v_video.cpp:390:12: runtime error: index 1068 out of bounds for type 'BYTE [32]' -// src/r_draw.cpp:273:11: runtime error: index 1057 out of bounds for type 'BYTE [32]' -union ColorTable32k -{ - BYTE RGB[32][32][32]; - BYTE All[32 *32 *32]; -}; -extern "C" ColorTable32k RGB32k; - // [SP] RGB666 support union ColorTable256k { @@ -470,31 +456,6 @@ union ColorTable256k }; extern "C" ColorTable256k RGB256k; -// Col2RGB8 is a pre-multiplied palette for color lookup. It is stored in a -// special R10B10G10 format for efficient blending computation. -// --RRRRRrrr--BBBBBbbb--GGGGGggg-- at level 64 -// --------rrrr------bbbb------gggg at level 1 -extern "C" DWORD Col2RGB8[65][256]; - -// Col2RGB8_LessPrecision is the same as Col2RGB8, but the LSB for red -// and blue are forced to zero, so if the blend overflows, it won't spill -// over into the next component's value. -// --RRRRRrrr-#BBBBBbbb-#GGGGGggg-- at level 64 -// --------rrr#------bbb#------gggg at level 1 -extern "C" DWORD *Col2RGB8_LessPrecision[65]; - -// Col2RGB8_Inverse is the same as Col2RGB8_LessPrecision, except the source -// palette has been inverted. -extern "C" DWORD Col2RGB8_Inverse[65][256]; - -// "Magic" numbers used during the blending: -// --000001111100000111110000011111 = 0x01f07c1f -// -0111111111011111111101111111111 = 0x3FEFFBFF -// -1000000000100000000010000000000 = 0x40100400 -// ------10000000001000000000100000 = 0x40100400 >> 5 -// --11111-----11111-----11111----- = 0x40100400 - (0x40100400 >> 5) aka "white" -// --111111111111111111111111111111 = 0x3FFFFFFF - // Allocates buffer screens, call before R_Init. void V_Init (bool restart); From 42fbe6358493f0cb7587745aa39b59921c565522 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Mon, 19 Dec 2016 05:02:44 -0500 Subject: [PATCH 13/15] - fixed: blood decals are now red. --- src/r_draw_pal.cpp | 6 +++--- src/r_drawt_pal.cpp | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/r_draw_pal.cpp b/src/r_draw_pal.cpp index b99f58f88..fe6c63b6d 100644 --- a/src/r_draw_pal.cpp +++ b/src/r_draw_pal.cpp @@ -1462,9 +1462,9 @@ namespace swrenderer { uint32_t val = source[frac >> FRACBITS]; - int r = (palette[*dest].r * (255-val)) >> 10; - int g = (palette[*dest].g * (255-val)) >> 10; - int b = (palette[*dest].b * (255-val)) >> 10; + int r = (palette[*dest].r * (255-val) + palette[_color].r * val) >> 10; + int g = (palette[*dest].g * (255-val) + palette[_color].g * val) >> 10; + int b = (palette[*dest].b * (255-val) + palette[_color].b * val) >> 10; *dest = RGB256k.RGB[clamp(r,0,63)][clamp(g,0,63)][clamp(b,0,63)]; dest += pitch; diff --git a/src/r_drawt_pal.cpp b/src/r_drawt_pal.cpp index 27c2a4294..26cb56221 100644 --- a/src/r_drawt_pal.cpp +++ b/src/r_drawt_pal.cpp @@ -516,9 +516,9 @@ namespace swrenderer do { uint32_t val = *source; - int r = (palette[*dest].r * (255-val)) >> 10; - int g = (palette[*dest].g * (255-val)) >> 10; - int b = (palette[*dest].b * (255-val)) >> 10; + int r = (palette[*dest].r * (255-val) + palette[_color].r * val) >> 10; + int g = (palette[*dest].g * (255-val) + palette[_color].g * val) >> 10; + int b = (palette[*dest].b * (255-val) + palette[_color].b * val) >> 10; *dest = RGB256k.RGB[clamp(r,0,63)][clamp(g,0,63)][clamp(b,0,63)]; source += 4; dest += pitch; @@ -550,9 +550,9 @@ namespace swrenderer for (int ks = 0; ks < 4; ks++) { val = source[ks]; - int r = (palette[dest[ks]].r * (255-val)) >> 10; - int g = (palette[dest[ks]].g * (255-val)) >> 10; - int b = (palette[dest[ks]].b * (255-val)) >> 10; + int r = (palette[dest[ks]].r * (255-val) + palette[_color].r * val) >> 10; + int g = (palette[dest[ks]].g * (255-val) + palette[_color].g * val) >> 10; + int b = (palette[dest[ks]].b * (255-val) + palette[_color].b * val) >> 10; dest[ks] = RGB256k.RGB[clamp(r,0,63)][clamp(g,0,63)][clamp(b,0,63)]; } From 4a95ef93ed07ef6252bd0897ac11dcbab356c902 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Mon, 19 Dec 2016 05:19:10 -0500 Subject: [PATCH 14/15] - Added names to r_drawt_pal.cpp copyright notice. --- src/r_drawt_pal.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/r_drawt_pal.cpp b/src/r_drawt_pal.cpp index 26cb56221..e2af7bbf1 100644 --- a/src/r_drawt_pal.cpp +++ b/src/r_drawt_pal.cpp @@ -4,6 +4,8 @@ ** **--------------------------------------------------------------------------- ** Copyright 1998-2006 Randy Heit +** Copyright 2016 Magnus Norddahl +** Copyright 2016 Rachael Alexanderson ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without From c1352d6ecb1782cff6ca4899fe4ad5a2444071dd Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Mon, 19 Dec 2016 06:06:19 -0500 Subject: [PATCH 15/15] - fixed: One of these floors was supposed to be additive, not translucent... --- src/r_plane.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 1a7758923..581e8b732 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -1529,7 +1529,7 @@ void R_DrawNormalPlane (visplane_t *pl, double _xscale, double _yscale, fixed_t { spanfunc = R_DrawSpanAddClamp; dc_srcalpha = alpha; - dc_destalpha = OPAQUE-alpha; + dc_destalpha = FRACUNIT; } } else