From 2ba402dc7404116d38b54b2878046fb161ede18a Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 17 Dec 2016 04:11:52 -0500 Subject: [PATCH 01/25] - 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 cfb55a6706..439321e53f 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 d24cd92d11..e13944173d 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 b208a51a37..e24b926caa 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 1524c7ba4a..bf7ccaab4e 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 efe93aa04a..92992220b2 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 b72f670947..2079ff64b5 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/25] - 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 439321e53f..5a6c943275 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 9e9b161cdf..7c178ce8b8 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 bf7ccaab4e..34db093565 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 92992220b2..6e333f8406 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/25] - 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 f2b1f05712..262b703875 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 3356592d25..16d24ecaf8 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 31e7480221..a2c69b38b2 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 2253965987..c138edbfa3 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 e68c4e20f2..991893845b 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 e13944173d..414c424b8f 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 e24b926caa..331747cfe0 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/25] - 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 5a6c943275..33c4829346 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 16d24ecaf8..156e97ba66 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 0ec5d2933c..dda431993c 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/25] - 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 33c4829346..9d15460af9 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 6e333f8406..62a587281d 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 2079ff64b5..57d15869cd 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/25] - 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 9d15460af9..81975e23c3 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 262b703875..54c74dc15c 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/25] - 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 a461e1877d..2c5d6fd917 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 58934981b0..f47179c510 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 7c178ce8b8..03900b3211 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 bf32b655f2..6b789cdc5c 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/25] - 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 81975e23c3..9f474911e6 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 54c74dc15c..0b1a5eebf8 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/25] - 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 9f474911e6..a1bddb16b9 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/25] - 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 156e97ba66..ebf0ea00ed 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/25] - 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 a3ceb8d508..352122007a 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 2c5d6fd917..2d86ee9859 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/25] - 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 352122007a..8d5f072f62 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 2d86ee9859..62e92273ec 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 a1bddb16b9..b99f58f887 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 ebf0ea00ed..27c2a42943 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 eafc9fa26e..1a7758923f 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 62a587281d..b639939eed 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 57d15869cd..0da6b9b500 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/25] - 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 b99f58f887..fe6c63b6de 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 27c2a42943..26cb562218 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/25] - 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 26cb562218..e2af7bbf19 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/25] - 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 1a7758923f..581e8b7327 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 From 821b10a254867350af85e4d273b50fc920ac4577 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 17 Dec 2016 04:11:52 -0500 Subject: [PATCH 16/25] - Implementing RGB666 colormatching to replace less precise RGB555 in some parts of the code. --- src/f_wipe.cpp | 29 +- src/r_draw.cpp | 12 +- src/r_draw.h | 1 - src/r_draw_pal.cpp | 436 +++++++++++++---------------- src/r_draw_pal.h | 6 + src/r_drawt_pal.cpp | 272 ++++++------------ src/r_plane.cpp | 16 +- src/r_things.cpp | 43 +-- src/r_things.h | 2 +- src/textures/ddstexture.cpp | 8 +- src/textures/jpegtexture.cpp | 4 +- src/textures/multipatchtexture.cpp | 2 +- src/textures/pcxtexture.cpp | 2 +- src/textures/pngtexture.cpp | 6 +- src/textures/tgatexture.cpp | 8 +- src/v_draw.cpp | 33 +-- src/v_video.cpp | 70 ++--- src/v_video.h | 41 +-- 18 files changed, 366 insertions(+), 625 deletions(-) diff --git a/src/f_wipe.cpp b/src/f_wipe.cpp index a3ceb8d508..8d5f072f62 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; } } @@ -342,20 +346,21 @@ 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(); + 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 25297f6c84..20127f50d3 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; } @@ -450,7 +444,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; @@ -1362,8 +1356,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 ab430d2af5..d9ad7a2da1 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -203,5 +203,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_draw_pal.cpp b/src/r_draw_pal.cpp index cfb55a6706..fe6c63b6de 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 @@ -314,10 +315,10 @@ namespace swrenderer uint8_t pix = source[frac >> bits]; if (pix != 0) { - uint32_t fg = fg2rgb[colormap[pix]]; - uint32_t bg = bg2rgb[*dest]; - fg = (fg + bg) | 0x1f07c1f; - *dest = RGB32k.All[fg & (fg >> 15)]; + 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]; } frac += fracstep; dest += pitch; @@ -357,10 +358,10 @@ namespace swrenderer uint8_t pix = _bufplce[i][vplce[i] >> bits]; if (pix != 0) { - uint32_t fg = fg2rgb[_palookupoffse[i][pix]]; - uint32_t bg = bg2rgb[dest[i]]; - fg = (fg + bg) | 0x1f07c1f; - dest[i] = RGB32k.All[fg & (fg >> 15)]; + 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]; } vplce[i] += vince[i]; } @@ -396,15 +397,10 @@ namespace swrenderer uint8_t pix = source[frac >> bits]; if (pix != 0) { - 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)]; + 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]; } frac += fracstep; dest += pitch; @@ -444,15 +440,10 @@ namespace swrenderer uint8_t pix = _bufplce[i][vplce[i] >> bits]; if (pix != 0) { - 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)]; + 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]; } vplce[i] += vince[i]; } @@ -488,14 +479,10 @@ namespace swrenderer uint8_t pix = source[frac >> bits]; if (pix != 0) { - 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)]; + 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]; } frac += fracstep; dest += pitch; @@ -535,14 +522,10 @@ namespace swrenderer uint8_t pix = _bufplce[i][vplce[i] >> bits]; if (pix != 0) { - 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)]; + 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]; } vplce[i] += vince[i]; } @@ -578,14 +561,10 @@ namespace swrenderer uint8_t pix = source[frac >> bits]; if (pix != 0) { - 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)]; + 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]; } frac += fracstep; dest += pitch; @@ -625,14 +604,10 @@ namespace swrenderer uint8_t pix = _bufplce[i][vplce[i] >> bits]; if (pix != 0) { - 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)]; + 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]; } vplce[i] += vince[i]; } @@ -716,7 +691,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; - *dest = RGB32k.RGB[(c_red >> 3)][(c_green >> 3)][(c_blue >> 3)]; + *dest = RGB256k.RGB[(c_red >> 2)][(c_green >> 2)][(c_blue >> 2)]; } frac += fracstep; @@ -744,8 +719,8 @@ namespace swrenderer int solid_bottom_r = RPART(solid_bottom); int solid_bottom_g = GPART(solid_bottom); int solid_bottom_b = BPART(solid_bottom); - 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)]; + 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)]; 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 +780,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; - output[col] = RGB32k.RGB[(c_red >> 3)][(c_green >> 3)][(c_blue >> 3)]; - + output[col] = RGB256k.RGB[(c_red >> 2)][(c_green >> 2)][(c_blue >> 2)]; frac[col] += fracstep[col]; } *((uint32_t*)dest) = *((uint32_t*)output); @@ -847,7 +821,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; - output[col] = RGB32k.RGB[(c_red >> 3)][(c_green >> 3)][(c_blue >> 3)]; + output[col] = RGB256k.RGB[(c_red >> 2)][(c_green >> 2)][(c_blue >> 2)]; frac[col] += fracstep[col]; } @@ -929,7 +903,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; - *dest = RGB32k.RGB[(c_red >> 3)][(c_green >> 3)][(c_blue >> 3)]; + *dest = RGB256k.RGB[(c_red >> 2)][(c_green >> 2)][(c_blue >> 2)]; } frac += fracstep; @@ -959,8 +933,8 @@ namespace swrenderer int solid_bottom_r = RPART(solid_bottom); int solid_bottom_g = GPART(solid_bottom); int solid_bottom_b = BPART(solid_bottom); - 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)]; + 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)]; 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 +1000,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; - output[col] = RGB32k.RGB[(c_red >> 3)][(c_green >> 3)][(c_blue >> 3)]; + output[col] = RGB256k.RGB[(c_red >> 2)][(c_green >> 2)][(c_blue >> 2)]; frac[col] += fracstep[col]; } @@ -1080,7 +1054,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; - output[col] = RGB32k.RGB[(c_red >> 3)][(c_green >> 3)][(c_blue >> 3)]; + output[col] = RGB256k.RGB[(c_red >> 2)][(c_green >> 2)][(c_blue >> 2)]; frac[col] += fracstep[col]; } @@ -1116,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) @@ -1210,11 +1186,17 @@ namespace swrenderer dest = thread->dest_for_thread(_dest_y, pitch, dest); pitch *= thread->num_cores; + const PalEntry* pal = GPalette.BaseColors; + do { - uint32_t bg; - bg = (fg + bg2rgb[*dest]) | 0x1f07c1f; - *dest = RGB32k.All[bg & (bg >> 15)]; + 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); @@ -1242,17 +1224,17 @@ namespace swrenderer dest = thread->dest_for_thread(_dest_y, pitch, dest); pitch *= thread->num_cores; + const PalEntry* pal = GPalette.BaseColors; + 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)]; + 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); } @@ -1265,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); @@ -1279,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); } @@ -1303,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); @@ -1317,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); } @@ -1354,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); @@ -1434,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); @@ -1478,14 +1455,17 @@ namespace swrenderer const uint8_t *source = _source; 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) + 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; frac += fracstep; @@ -1517,20 +1497,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); @@ -1562,20 +1538,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); @@ -1606,19 +1578,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); @@ -1650,19 +1619,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); @@ -1693,19 +1659,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); @@ -1737,19 +1700,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); @@ -1865,6 +1825,8 @@ namespace swrenderer _srcblend = dc_srcblend; _destblend = dc_destblend; _color = ds_color; + _srcalpha = dc_srcalpha; + _destalpha = dc_destalpha; } void DrawSpanPalCommand::Execute(DrawerThread *thread) @@ -2010,8 +1972,6 @@ namespace swrenderer const uint8_t *colormap = _colormap; int count; int spot; - uint32_t *fg2rgb = _srcblend; - uint32_t *bg2rgb = _destblend; xfrac = _xfrac; yfrac = _yfrac; @@ -2023,6 +1983,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. @@ -2031,10 +1993,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); @@ -2049,10 +2012,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); @@ -2073,8 +2037,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; @@ -2099,10 +2063,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; @@ -2124,10 +2088,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; @@ -2150,8 +2114,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; @@ -2169,15 +2132,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); @@ -2190,15 +2151,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); @@ -2219,8 +2178,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; @@ -2243,15 +2201,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; @@ -2271,15 +2226,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 f2b1f05712..0b1a5eebf8 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; }; @@ -164,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; }; @@ -303,6 +307,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 3356592d25..e2af7bbf19 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 @@ -173,6 +175,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,21 +444,20 @@ 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; + const PalEntry *palette = GPalette.BaseColors; do { 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((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; } while (--count); @@ -472,42 +475,22 @@ 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; + const PalEntry *palette = GPalette.BaseColors; 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((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]; + } source += 4; dest += pitch; @@ -527,17 +510,18 @@ 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]; pitch = _pitch * thread->num_cores; + const PalEntry *palette = GPalette.BaseColors; 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 = (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; } while (--count); @@ -556,30 +540,23 @@ 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]; pitch = _pitch * thread->num_cores; + const PalEntry *palette = GPalette.BaseColors; 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 = (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)]; + } source += 4; dest += pitch; @@ -598,23 +575,19 @@ 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; + const PalEntry *palette = GPalette.BaseColors; 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 = 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); + int b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); + *dest = RGB256k.RGB[r][g][b]; source += 4; dest += pitch; } while (--count); @@ -636,47 +609,18 @@ namespace swrenderer source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4]; pitch = _pitch * thread->num_cores; colormap = _colormap; - - const uint32_t *fg2rgb = _srcblend; - const uint32_t *bg2rgb = _destblend; + const PalEntry *palette = GPalette.BaseColors; 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 = 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); + int b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); + dest[ks] = RGB256k.RGB[r][g][b]; + } source += 4; dest += pitch; @@ -701,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 = 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); + 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); @@ -734,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 = 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); + int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + dest[ks] = RGB256k.RGB[r][g][b]; + } source += 4; dest += pitch; @@ -792,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 = 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); + 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); @@ -825,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 = 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); + 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/r_plane.cpp b/src/r_plane.cpp index cd378aec14..865517dd11 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -1509,14 +1509,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 @@ -1531,14 +1531,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 = FRACUNIT; } } else diff --git a/src/r_things.cpp b/src/r_things.cpp index a1ace0d49c..61da979da8 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -2636,12 +2636,12 @@ 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) { - 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; @@ -2653,33 +2653,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 @@ -2695,9 +2672,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)]; + 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 6d694b8fd7..740af279a5 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; diff --git a/src/textures/ddstexture.cpp b/src/textures/ddstexture.cpp index 31e7480221..a2c69b38b2 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 2253965987..c138edbfa3 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 e68c4e20f2..991893845b 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/pcxtexture.cpp b/src/textures/pcxtexture.cpp index 0ec5d2933c..dda431993c 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; } } diff --git a/src/textures/pngtexture.cpp b/src/textures/pngtexture.cpp index d24cd92d11..414c424b8f 100644 --- a/src/textures/pngtexture.cpp +++ b/src/textures/pngtexture.cpp @@ -536,7 +536,7 @@ void FPNGTexture::MakeTexture () { if (!HaveTrans) { - *out++ = RGB32k.RGB[in[0]>>3][in[1]>>3][in[2]>>3]; + *out++ = RGB256k.RGB[in[0]>>2][in[1]>>2][in[2]>>2]; } else { @@ -548,7 +548,7 @@ void FPNGTexture::MakeTexture () } else { - *out++ = RGB32k.RGB[in[0]>>3][in[1]>>3][in[2]>>3]; + *out++ = RGB256k.RGB[in[0]>>2][in[1]>>2][in[2]>>2]; } } in += pitch; @@ -593,7 +593,7 @@ void FPNGTexture::MakeTexture () { for (y = Height; y > 0; --y) { - *out++ = in[3] < 128 ? 0 : RGB32k.RGB[in[0]>>3][in[1]>>3][in[2]>>3]; + *out++ = in[3] < 128 ? 0 : RGB256k.RGB[in[0]>>2][in[1]>>2][in[2]>>2]; in += pitch; } in -= backstep; diff --git a/src/textures/tgatexture.cpp b/src/textures/tgatexture.cpp index b208a51a37..331747cfe0 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,7 +405,7 @@ void FTGATexture::MakeTexture () BYTE * p = ptr + y * Pitch; for(int x=0;x>3][p[1]>>3][p[0]>>3]; + Pixels[x*Height+y] = RGB256k.RGB[p[2]>>2][p[1]>>2][p[0]>>2]; p+=step_x; } } @@ -419,7 +419,7 @@ void FTGATexture::MakeTexture () BYTE * p = ptr + y * Pitch; for(int x=0;x>3][p[1]>>3][p[0]>>3]; + Pixels[x*Height+y] = RGB256k.RGB[p[2]>>2][p[1]>>2][p[0]>>2]; p+=step_x; } } @@ -431,7 +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; + Pixels[x*Height+y] = p[3] >= 128? RGB256k.RGB[p[2]>>2][p[1]>>2][p[0]>>2] : 0; p+=step_x; } } diff --git a/src/v_draw.cpp b/src/v_draw.cpp index 6f8bc51988..5f0d39d4f2 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -965,27 +965,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++; @@ -1003,12 +982,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) | 0x1f07c1f; - *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 efe93aa04a..b639939eed 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -143,9 +143,10 @@ extern "C" { DWORD Col2RGB8[65][256]; DWORD *Col2RGB8_LessPrecision[65]; DWORD Col2RGB8_Inverse[65][256]; -ColorTable32k RGB32k; +ColorTable256k RGB256k; } + static DWORD Col2RGB8_2[63][256]; // [RH] The framebuffer is no longer a mere byte array. @@ -345,8 +346,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; @@ -368,28 +367,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; @@ -664,42 +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)); + // 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 b72f670947..0da6b9b500 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -448,44 +448,13 @@ 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 +// [SP] RGB666 support +union ColorTable256k { - BYTE RGB[32][32][32]; - BYTE All[32 *32 *32]; + BYTE RGB[64][64][64]; + BYTE All[64 *64 *64]; }; -extern "C" ColorTable32k RGB32k; - -// 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 +extern "C" ColorTable256k RGB256k; // Allocates buffer screens, call before R_Init. void V_Init (bool restart); From 8de11ee81a1c3ff817781afb0e9bf3841e84af1a Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 24 Dec 2016 03:49:56 -0500 Subject: [PATCH 17/25] - Begin reimplementing rgb555 again. --- src/r_draw_pal.cpp | 137 ++++++++++++++++++++++++++++++++++----------- src/v_video.cpp | 84 ++++++++++++++++++++++++--- src/v_video.h | 39 +++++++++++++ 3 files changed, 218 insertions(+), 42 deletions(-) diff --git a/src/r_draw_pal.cpp b/src/r_draw_pal.cpp index 17e77d39ae..c7adc9d87a 100644 --- a/src/r_draw_pal.cpp +++ b/src/r_draw_pal.cpp @@ -43,6 +43,9 @@ #include "v_video.h" #include "r_draw_pal.h" +// [SP] r_blendmode - false = rgb555 matching (ZDoom classic), true = rgb666 (refactored) +CVAR(Bool, r_blendmode, false, CVAR_GLOBALCONFIG | CVAR_ARCHIVE) + /* [RH] This translucency algorithm is based on DOSDoom 0.65's, but uses a 32k RGB table instead of an 8k one. At least on my machine, it's @@ -303,19 +306,39 @@ namespace swrenderer fracstep *= thread->num_cores; pitch *= thread->num_cores; - do + if (!r_blendmode) { - uint8_t pix = source[frac >> bits]; - if (pix != 0) + do { - 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]; - } - frac += fracstep; - dest += pitch; - } while (--count); + uint8_t pix = source[frac >> bits]; + if (pix != 0) + { + uint32_t fg = fg2rgb[colormap[pix]]; + uint32_t bg = bg2rgb[*dest]; + fg = (fg + bg) | 0x1f07c1f; + *dest = RGB32k.All[fg & (fg >> 15)]; + } + frac += fracstep; + dest += pitch; + } while (--count); + + } + else + { + do + { + uint8_t pix = source[frac >> bits]; + if (pix != 0) + { + 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]; + } + frac += fracstep; + dest += pitch; + } while (--count); + } } void DrawWallAdd4PalCommand::Execute(DrawerThread *thread) @@ -341,22 +364,44 @@ namespace swrenderer } pitch *= thread->num_cores; - do + if (!r_blendmode) { - for (int i = 0; i < 4; ++i) + do { - uint8_t pix = _source[i][dc_wall_texturefrac[i] >> bits]; - if (pix != 0) + for (int i = 0; i < 4; ++i) { - uint32_t r = MIN(GPalette.BaseColors[_colormap[i][pix]].r + GPalette.BaseColors[dest[i]].r, 255); - uint32_t g = MIN(GPalette.BaseColors[_colormap[i][pix]].g + GPalette.BaseColors[dest[i]].g, 255); - uint32_t b = MIN(GPalette.BaseColors[_colormap[i][pix]].b + GPalette.BaseColors[dest[i]].b, 255); - dest[i] = RGB256k.RGB[r>>2][g>>2][b>>2]; + uint8_t pix = _source[i][dc_wall_texturefrac[i] >> bits]; + if (pix != 0) + { + uint32_t fg = fg2rgb[_colormap[i][pix]]; + uint32_t bg = bg2rgb[dest[i]]; + fg = (fg + bg) | 0x1f07c1f; + dest[i] = RGB32k.All[fg & (fg >> 15)]; + } + dc_wall_texturefrac[i] += dc_wall_iscale[i]; } - dc_wall_texturefrac[i] += dc_wall_iscale[i]; - } - dest += pitch; - } while (--count); + dest += pitch; + } while (--count); + } + else + { + do + { + for (int i = 0; i < 4; ++i) + { + uint8_t pix = _source[i][dc_wall_texturefrac[i] >> bits]; + if (pix != 0) + { + uint32_t r = MIN(GPalette.BaseColors[_colormap[i][pix]].r + GPalette.BaseColors[dest[i]].r, 255); + uint32_t g = MIN(GPalette.BaseColors[_colormap[i][pix]].g + GPalette.BaseColors[dest[i]].g, 255); + uint32_t b = MIN(GPalette.BaseColors[_colormap[i][pix]].b + GPalette.BaseColors[dest[i]].b, 255); + dest[i] = RGB256k.RGB[r>>2][g>>2][b>>2]; + } + dc_wall_texturefrac[i] += dc_wall_iscale[i]; + } + dest += pitch; + } while (--count); + } } void DrawWallAddClamp1PalCommand::Execute(DrawerThread *thread) @@ -379,19 +424,43 @@ namespace swrenderer fracstep *= thread->num_cores; pitch *= thread->num_cores; - do + if (!r_blendmode) { - uint8_t pix = source[frac >> bits]; - if (pix != 0) + do { - 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]; - } - frac += fracstep; - dest += pitch; - } while (--count); + uint8_t pix = source[frac >> bits]; + if (pix != 0) + { + 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)]; + } + frac += fracstep; + dest += pitch; + } while (--count); + } + else + { + do + { + uint8_t pix = source[frac >> bits]; + if (pix != 0) + { + 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]; + } + frac += fracstep; + dest += pitch; + } while (--count); + } } void DrawWallAddClamp4PalCommand::Execute(DrawerThread *thread) diff --git a/src/v_video.cpp b/src/v_video.cpp index b639939eed..5a8ef10d59 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -143,6 +143,7 @@ extern "C" { DWORD Col2RGB8[65][256]; DWORD *Col2RGB8_LessPrecision[65]; DWORD Col2RGB8_Inverse[65][256]; +ColorTable32k RGB32k; ColorTable256k RGB256k; } @@ -346,6 +347,8 @@ 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; @@ -367,6 +370,16 @@ 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; @@ -376,17 +389,37 @@ void DCanvas::Dim (PalEntry color, float damount, int x1, int y1, int w, int h) int dimmedcolor_r = color.r * alpha; int dimmedcolor_g = color.g * alpha; int dimmedcolor_b = color.b * alpha; - for (y = h; y != 0; y--) + + if (!r_blendmode) { - for (x = w; x != 0; x--) + for (y = h; y != 0; y--) { - 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++; + for (x = w; x != 0; x--) + { + DWORD bg; + + bg = bg2rgb[(*spot)&0xff]; + bg = (fg+bg) | 0x1f07c1f; + *spot = RGB32k.All[bg&(bg>>15)]; + spot++; + } + spot += gap; + } + } + else + { + for (y = h; y != 0; y--) + { + for (x = w; x != 0; x--) + { + 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; } - spot += gap; } } @@ -658,12 +691,47 @@ 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)); // 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 0da6b9b500..57d15869cd 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -448,6 +448,20 @@ 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 { @@ -456,6 +470,31 @@ 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 9d2128a4f4af0ea16048addd40bc48917177f837 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 24 Dec 2016 04:01:50 -0500 Subject: [PATCH 18/25] - Fixed compile errors. --- src/r_draw_pal.cpp | 12 ++++++++++++ src/v_video.cpp | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/r_draw_pal.cpp b/src/r_draw_pal.cpp index c7adc9d87a..6b40621b6a 100644 --- a/src/r_draw_pal.cpp +++ b/src/r_draw_pal.cpp @@ -297,6 +297,9 @@ namespace swrenderer int bits = _fracbits; int pitch = _pitch; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; + count = thread->count_for_thread(_dest_y, count); if (count <= 0) return; @@ -347,6 +350,9 @@ namespace swrenderer int count = _count; int bits = _fracbits; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; + uint32_t dc_wall_texturefrac[4] = { _texturefrac[0], _texturefrac[1], _texturefrac[2], _texturefrac[3] }; uint32_t dc_wall_iscale[4] = { _iscale[0], _iscale[1], _iscale[2], _iscale[3] }; @@ -415,6 +421,9 @@ namespace swrenderer int bits = _fracbits; int pitch = _pitch; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; + count = thread->count_for_thread(_dest_y, count); if (count <= 0) return; @@ -469,6 +478,9 @@ namespace swrenderer int count = _count; int bits = _fracbits; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; + uint32_t dc_wall_texturefrac[4] = { _texturefrac[0], _texturefrac[1], _texturefrac[2], _texturefrac[3] }; uint32_t dc_wall_iscale[4] = { _iscale[0], _iscale[1], _iscale[2], _iscale[3] }; diff --git a/src/v_video.cpp b/src/v_video.cpp index 5a8ef10d59..9abe13f1b4 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -66,6 +66,8 @@ #include "menu/menu.h" #include "r_data/voxels.h" +EXTERN_CVAR(Bool, r_blendmode) + int active_con_scale(); FRenderer *Renderer; From 88b60389992bd8919c382accae10ff27b7805372 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 24 Dec 2016 04:35:05 -0500 Subject: [PATCH 19/25] - More rgb555 reimplements. --- src/r_draw_pal.cpp | 101 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 78 insertions(+), 23 deletions(-) diff --git a/src/r_draw_pal.cpp b/src/r_draw_pal.cpp index 6b40621b6a..19015d8e11 100644 --- a/src/r_draw_pal.cpp +++ b/src/r_draw_pal.cpp @@ -527,6 +527,9 @@ namespace swrenderer int bits = _fracbits; int pitch = _pitch; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; + count = thread->count_for_thread(_dest_y, count); if (count <= 0) return; @@ -536,19 +539,42 @@ namespace swrenderer fracstep *= thread->num_cores; pitch *= thread->num_cores; - do + if (!r_blendmode) { - uint8_t pix = source[frac >> bits]; - if (pix != 0) + do { - 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]; - } - frac += fracstep; - dest += pitch; - } while (--count); + uint8_t pix = source[frac >> bits]; + if (pix != 0) + { + 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)]; + } + frac += fracstep; + dest += pitch; + } while (--count); + } + else + { + do + { + uint8_t pix = source[frac >> bits]; + if (pix != 0) + { + 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]; + } + frac += fracstep; + dest += pitch; + } while (--count); + } } void DrawWallSubClamp4PalCommand::Execute(DrawerThread *thread) @@ -557,6 +583,9 @@ namespace swrenderer int count = _count; int bits = _fracbits; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; + uint32_t dc_wall_texturefrac[4] = { _texturefrac[0], _texturefrac[1], _texturefrac[2], _texturefrac[3] }; uint32_t dc_wall_iscale[4] = { _iscale[0], _iscale[1], _iscale[2], _iscale[3] }; @@ -574,22 +603,48 @@ namespace swrenderer } pitch *= thread->num_cores; - do + if (!r_blendmode) { - for (int i = 0; i < 4; ++i) + do { - uint8_t pix = _source[i][dc_wall_texturefrac[i] >> bits]; - if (pix != 0) + for (int i = 0; i < 4; ++i) { - int r = clamp(-GPalette.BaseColors[_colormap[i][pix]].r + GPalette.BaseColors[dest[i]].r, 0, 255); - int g = clamp(-GPalette.BaseColors[_colormap[i][pix]].g + GPalette.BaseColors[dest[i]].g, 0, 255); - int b = clamp(-GPalette.BaseColors[_colormap[i][pix]].b + GPalette.BaseColors[dest[i]].b, 0, 255); - dest[i] = RGB256k.RGB[r>>2][g>>2][b>>2]; + uint8_t pix = _source[i][dc_wall_texturefrac[i] >> bits]; + if (pix != 0) + { + uint32_t a = (fg2rgb[_colormap[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)]; + } + dc_wall_texturefrac[i] += dc_wall_iscale[i]; } - dc_wall_texturefrac[i] += dc_wall_iscale[i]; - } - dest += pitch; - } while (--count); + dest += pitch; + } while (--count); + } + else + { + do + { + for (int i = 0; i < 4; ++i) + { + uint8_t pix = _source[i][dc_wall_texturefrac[i] >> bits]; + if (pix != 0) + { + int r = clamp(-GPalette.BaseColors[_colormap[i][pix]].r + GPalette.BaseColors[dest[i]].r, 0, 255); + int g = clamp(-GPalette.BaseColors[_colormap[i][pix]].g + GPalette.BaseColors[dest[i]].g, 0, 255); + int b = clamp(-GPalette.BaseColors[_colormap[i][pix]].b + GPalette.BaseColors[dest[i]].b, 0, 255); + dest[i] = RGB256k.RGB[r>>2][g>>2][b>>2]; + } + dc_wall_texturefrac[i] += dc_wall_iscale[i]; + } + dest += pitch; + } while (--count); + } } void DrawWallRevSubClamp1PalCommand::Execute(DrawerThread *thread) From 80482e98a389c84b12770ffdfcd990065013f35c Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 24 Dec 2016 10:15:02 -0500 Subject: [PATCH 20/25] - renamed r_blendmode to r_blendmethod - did another drawer --- src/r_draw_pal.cpp | 59 ++++++++++++++++++++++++++++++++-------------- src/v_video.cpp | 4 ++-- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/src/r_draw_pal.cpp b/src/r_draw_pal.cpp index 19015d8e11..0da9e38bee 100644 --- a/src/r_draw_pal.cpp +++ b/src/r_draw_pal.cpp @@ -43,8 +43,8 @@ #include "v_video.h" #include "r_draw_pal.h" -// [SP] r_blendmode - false = rgb555 matching (ZDoom classic), true = rgb666 (refactored) -CVAR(Bool, r_blendmode, false, CVAR_GLOBALCONFIG | CVAR_ARCHIVE) +// [SP] r_blendmethod - false = rgb555 matching (ZDoom classic), true = rgb666 (refactored) +CVAR(Bool, r_blendmethod, false, CVAR_GLOBALCONFIG | CVAR_ARCHIVE) /* [RH] This translucency algorithm is based on DOSDoom 0.65's, but uses @@ -309,7 +309,7 @@ namespace swrenderer fracstep *= thread->num_cores; pitch *= thread->num_cores; - if (!r_blendmode) + if (!r_blendmethod) { do { @@ -370,7 +370,7 @@ namespace swrenderer } pitch *= thread->num_cores; - if (!r_blendmode) + if (!r_blendmethod) { do { @@ -433,7 +433,7 @@ namespace swrenderer fracstep *= thread->num_cores; pitch *= thread->num_cores; - if (!r_blendmode) + if (!r_blendmethod) { do { @@ -539,7 +539,7 @@ namespace swrenderer fracstep *= thread->num_cores; pitch *= thread->num_cores; - if (!r_blendmode) + if (!r_blendmethod) { do { @@ -603,7 +603,7 @@ namespace swrenderer } pitch *= thread->num_cores; - if (!r_blendmode) + if (!r_blendmethod) { do { @@ -667,19 +667,42 @@ namespace swrenderer fracstep *= thread->num_cores; pitch *= thread->num_cores; - do + if (!r_blendmethod) { - uint8_t pix = source[frac >> bits]; - if (pix != 0) + do { - 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]; - } - frac += fracstep; - dest += pitch; - } while (--count); + uint8_t pix = source[frac >> bits]; + if (pix != 0) + { + 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)]; + } + frac += fracstep; + dest += pitch; + } while (--count); + } + else + { + do + { + uint8_t pix = source[frac >> bits]; + if (pix != 0) + { + 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]; + } + frac += fracstep; + dest += pitch; + } while (--count); + } } void DrawWallRevSubClamp4PalCommand::Execute(DrawerThread *thread) diff --git a/src/v_video.cpp b/src/v_video.cpp index 9abe13f1b4..2b31415a2b 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -66,7 +66,7 @@ #include "menu/menu.h" #include "r_data/voxels.h" -EXTERN_CVAR(Bool, r_blendmode) +EXTERN_CVAR(Bool, r_blendmethod) int active_con_scale(); @@ -392,7 +392,7 @@ void DCanvas::Dim (PalEntry color, float damount, int x1, int y1, int w, int h) int dimmedcolor_g = color.g * alpha; int dimmedcolor_b = color.b * alpha; - if (!r_blendmode) + if (!r_blendmethod) { for (y = h; y != 0; y--) { From 101108877acc4bba39668c066fba40793863b326 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 24 Dec 2016 11:40:15 -0500 Subject: [PATCH 21/25] - Reimplemented rgb555 into all drawers in r_draw_pal.cpp including span drawers. All that remains now are the 4col drawers in r_drawt_pal.cpp. --- src/r_draw.cpp | 6 + src/r_draw_pal.cpp | 1051 ++++++++++++++++++++++++++++++++------------ src/r_plane.cpp | 8 + src/r_things.cpp | 73 ++- 4 files changed, 847 insertions(+), 291 deletions(-) diff --git a/src/r_draw.cpp b/src/r_draw.cpp index a08a204ca3..b44bc5f951 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -236,16 +236,22 @@ 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 0da9e38bee..88fe93f85a 100644 --- a/src/r_draw_pal.cpp +++ b/src/r_draw_pal.cpp @@ -658,6 +658,9 @@ namespace swrenderer int bits = _fracbits; int pitch = _pitch; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; + count = thread->count_for_thread(_dest_y, count); if (count <= 0) return; @@ -711,6 +714,9 @@ namespace swrenderer int count = _count; int bits = _fracbits; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; + uint32_t dc_wall_texturefrac[4] = { _texturefrac[0], _texturefrac[1], _texturefrac[2], _texturefrac[3] }; uint32_t dc_wall_iscale[4] = { _iscale[0], _iscale[1], _iscale[2], _iscale[3] }; @@ -728,22 +734,48 @@ namespace swrenderer } pitch *= thread->num_cores; - do + if (!r_blendmethod) { - for (int i = 0; i < 4; ++i) + do { - uint8_t pix = _source[i][dc_wall_texturefrac[i] >> bits]; - if (pix != 0) + for (int i = 0; i < 4; ++i) { - uint32_t r = clamp(GPalette.BaseColors[_colormap[i][pix]].r - GPalette.BaseColors[dest[i]].r, 0, 255); - uint32_t g = clamp(GPalette.BaseColors[_colormap[i][pix]].g - GPalette.BaseColors[dest[i]].g, 0, 255); - uint32_t b = clamp(GPalette.BaseColors[_colormap[i][pix]].b - GPalette.BaseColors[dest[i]].b, 0, 255); - dest[i] = RGB256k.RGB[r>>2][g>>2][b>>2]; + uint8_t pix = _source[i][dc_wall_texturefrac[i] >> bits]; + if (pix != 0) + { + uint32_t a = (bg2rgb[dest[i]] | 0x40100400) - fg2rgb[_colormap[i][pix]]; + uint32_t b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + dest[i] = RGB32k.All[a & (a >> 15)]; + } + dc_wall_texturefrac[i] += dc_wall_iscale[i]; } - dc_wall_texturefrac[i] += dc_wall_iscale[i]; - } - dest += _pitch; - } while (--count); + dest += _pitch; + } while (--count); + } + else + { + do + { + for (int i = 0; i < 4; ++i) + { + uint8_t pix = _source[i][dc_wall_texturefrac[i] >> bits]; + if (pix != 0) + { + uint32_t r = clamp(GPalette.BaseColors[_colormap[i][pix]].r - GPalette.BaseColors[dest[i]].r, 0, 255); + uint32_t g = clamp(GPalette.BaseColors[_colormap[i][pix]].g - GPalette.BaseColors[dest[i]].g, 0, 255); + uint32_t b = clamp(GPalette.BaseColors[_colormap[i][pix]].b - GPalette.BaseColors[dest[i]].b, 0, 255); + dest[i] = RGB256k.RGB[r>>2][g>>2][b>>2]; + } + dc_wall_texturefrac[i] += dc_wall_iscale[i]; + } + dest += _pitch; + } while (--count); + } } ///////////////////////////////////////////////////////////////////////// @@ -1319,18 +1351,30 @@ namespace swrenderer const PalEntry* pal = GPalette.BaseColors; - do + if (!r_blendmethod) { - 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); - + do + { + uint32_t bg; + bg = (fg + bg2rgb[*dest]) | 0x1f07c1f; + *dest = RGB32k.All[bg & (bg >> 15)]; + dest += pitch; + } while (--count); + } + else + { + do + { + 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); + } } void FillColumnAddClampPalCommand::Execute(DrawerThread *thread) @@ -1357,17 +1401,36 @@ namespace swrenderer const PalEntry* pal = GPalette.BaseColors; - do + if (!r_blendmethod) { - 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); + 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)]; + dest += pitch; + } while (--count); + } + else + { + do + { + 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); + } } void FillColumnSubClampPalCommand::Execute(DrawerThread *thread) @@ -1378,6 +1441,8 @@ namespace swrenderer count = _count; dest = _dest; + uint32_t *bg2rgb = _destblend; + uint32_t fg = _srccolor; int pitch = _pitch; @@ -1390,19 +1455,37 @@ namespace swrenderer const PalEntry* palette = GPalette.BaseColors; - do + if (!r_blendmethod) { - 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); + do + { + uint32_t a = fg - bg2rgb[*dest]; + uint32_t b = a; - *dest = RGB256k.RGB[r][g][b]; - dest += pitch; - } while (--count); + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + *dest = RGB32k.All[a & (a >> 15)]; + dest += pitch; + } while (--count); + } + else + { + do + { + 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); + + *dest = RGB256k.RGB[r][g][b]; + dest += pitch; + } while (--count); + } } void FillColumnRevSubClampPalCommand::Execute(DrawerThread *thread) @@ -1415,6 +1498,8 @@ namespace swrenderer return; dest = _dest; + uint32_t *bg2rgb = _destblend; + uint32_t fg = _srccolor; int pitch = _pitch; @@ -1427,19 +1512,37 @@ namespace swrenderer const PalEntry *palette = GPalette.BaseColors; - do + if (!r_blendmethod) { - 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); + do + { + uint32_t a = (bg2rgb[*dest] | 0x40100400) - fg; + uint32_t b = a; - *dest = RGB256k.RGB[r][g][b]; - dest += pitch; - } while (--count); + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + *dest = RGB32k.All[a & (a >> 15)]; + dest += pitch; + } while (--count); + } + else + { + do + { + 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); + + *dest = RGB256k.RGB[r][g][b]; + dest += pitch; + } while (--count); + } } void DrawColumnAddPalCommand::Execute(DrawerThread *thread) @@ -1465,21 +1568,41 @@ 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 + if (!r_blendmethod) { - uint32_t fg = colormap[source[frac >> FRACBITS]]; - uint32_t bg = *dest; - 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); + 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)]; + dest += pitch; + frac += fracstep; + } while (--count); + } + else + { + do + { + uint32_t fg = colormap[source[frac >> FRACBITS]]; + uint32_t bg = *dest; + 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); + } } void DrawColumnTranslatedPalCommand::Execute(DrawerThread *thread) @@ -1543,23 +1666,43 @@ 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 + if (!r_blendmethod) { - uint32_t fg = colormap[translation[source[frac >> FRACBITS]]]; - uint32_t bg = *dest; - 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); + 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)]; + dest += pitch; + frac += fracstep; + } while (--count); + } + else + { + do + { + uint32_t fg = colormap[translation[source[frac >> FRACBITS]]]; + uint32_t bg = *dest; + 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); + } } void DrawColumnShadedPalCommand::Execute(DrawerThread *thread) @@ -1586,21 +1729,37 @@ namespace swrenderer const uint8_t *source = _source; const uint8_t *colormap = _colormap; - + uint32_t *fgstart = &Col2RGB8[0][_color]; const PalEntry *palette = GPalette.BaseColors; - do + if (!r_blendmethod) { - uint32_t val = source[frac >> FRACBITS]; + 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)]; - 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; + frac += fracstep; + } while (--count); + } + else + { + do + { + uint32_t val = source[frac >> FRACBITS]; - dest += pitch; - frac += fracstep; - } while (--count); + 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; + frac += fracstep; + } while (--count); + } } void DrawColumnAddClampPalCommand::Execute(DrawerThread *thread) @@ -1628,19 +1787,41 @@ 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 + if (!r_blendmethod) { - 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); + 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)]; + dest += pitch; + frac += fracstep; + } while (--count); + } + else + { + do + { + 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); + } } void DrawColumnAddClampTranslatedPalCommand::Execute(DrawerThread *thread) @@ -1669,19 +1850,41 @@ 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 + if (!r_blendmethod) { - 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); + 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]; + dest += pitch; + frac += fracstep; + } while (--count); + } + else + { + do + { + 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); + } } void DrawColumnSubClampPalCommand::Execute(DrawerThread *thread) @@ -1709,19 +1912,40 @@ 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 + if (!r_blendmethod) { - 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); + 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)]; + dest += pitch; + frac += fracstep; + } while (--count); + } + else + { + do + { + 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); + } } void DrawColumnSubClampTranslatedPalCommand::Execute(DrawerThread *thread) @@ -1750,19 +1974,40 @@ 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 + if (!r_blendmethod) { - 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); + 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]; + dest += pitch; + frac += fracstep; + } while (--count); + } + else + { + do + { + 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); + } } void DrawColumnRevSubClampPalCommand::Execute(DrawerThread *thread) @@ -1790,19 +2035,40 @@ 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 + if (!r_blendmethod) { - 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); + 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)]; + dest += pitch; + frac += fracstep; + } while (--count); + } + else + { + do + { + 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); + } } void DrawColumnRevSubClampTranslatedPalCommand::Execute(DrawerThread *thread) @@ -1831,19 +2097,40 @@ 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 + if (!r_blendmethod) { - 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); + 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]; + dest += pitch; + frac += fracstep; + } while (--count); + } + else + { + do + { + 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); + } } ///////////////////////////////////////////////////////////////////////// @@ -2103,6 +2390,8 @@ namespace swrenderer const uint8_t *colormap = _colormap; int count; int spot; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; xfrac = _xfrac; yfrac = _yfrac; @@ -2116,41 +2405,81 @@ namespace swrenderer const PalEntry *palette = GPalette.BaseColors; - if (_xbits == 6 && _ybits == 6) + if (!r_blendmethod) { - // 64x64 is the most common case by far, so special case it. - do + if (_xbits == 6 && _ybits == 6) { - 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); - *dest++ = RGB256k.RGB[r][g][b]; - - xfrac += xstep; - yfrac += ystep; - } while (--count); + // 64x64 is the most common case by far, so special case it. + do + { + 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)]; + xfrac += xstep; + yfrac += ystep; + } while (--count); + } + else + { + uint8_t yshift = 32 - _ybits; + uint8_t xshift = yshift - _xbits; + int xmask = ((1 << _xbits) - 1) << _ybits; + do + { + 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)]; + xfrac += xstep; + yfrac += ystep; + } while (--count); + } } else { - uint8_t yshift = 32 - _ybits; - uint8_t xshift = yshift - _xbits; - int xmask = ((1 << _xbits) - 1) << _ybits; - do + if (_xbits == 6 && _ybits == 6) { - 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); - *dest++ = RGB256k.RGB[r][g][b]; + // 64x64 is the most common case by far, so special case it. + do + { + 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); + *dest++ = RGB256k.RGB[r][g][b]; - xfrac += xstep; - yfrac += ystep; - } while (--count); + xfrac += xstep; + yfrac += ystep; + } while (--count); + } + else + { + uint8_t yshift = 32 - _ybits; + uint8_t xshift = yshift - _xbits; + int xmask = ((1 << _xbits) - 1) << _ybits; + do + { + 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); + *dest++ = RGB256k.RGB[r][g][b]; + + xfrac += xstep; + yfrac += ystep; + } while (--count); + } } } @@ -2168,6 +2497,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; @@ -2181,53 +2512,107 @@ namespace swrenderer xstep = _xstep; ystep = _ystep; - if (_xbits == 6 && _ybits == 6) + if (!r_blendmethod) { - // 64x64 is the most common case by far, so special case it. - do + if (_xbits == 6 && _ybits == 6) { - uint8_t texdata; - - spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); - texdata = source[spot]; - if (texdata != 0) + // 64x64 is the most common case by far, so special case it. + do { - 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; - yfrac += ystep; - } while (--count); + uint8_t texdata; + + spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); + texdata = source[spot]; + if (texdata != 0) + { + 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)]; + } + dest++; + xfrac += xstep; + yfrac += ystep; + } while (--count); + } + else + { + uint8_t yshift = 32 - _ybits; + uint8_t xshift = yshift - _xbits; + int xmask = ((1 << _xbits) - 1) << _ybits; + do + { + uint8_t texdata; + + spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); + texdata = source[spot]; + if (texdata != 0) + { + 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)]; + } + dest++; + xfrac += xstep; + yfrac += ystep; + } while (--count); + } } else { - uint8_t yshift = 32 - _ybits; - uint8_t xshift = yshift - _xbits; - int xmask = ((1 << _xbits) - 1) << _ybits; - do + if (_xbits == 6 && _ybits == 6) { - uint8_t texdata; - - spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); - texdata = source[spot]; - if (texdata != 0) + // 64x64 is the most common case by far, so special case it. + do { - 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; - yfrac += ystep; - } while (--count); + uint8_t texdata; + + spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); + texdata = source[spot]; + if (texdata != 0) + { + 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; + yfrac += ystep; + } while (--count); + } + else + { + uint8_t yshift = 32 - _ybits; + uint8_t xshift = yshift - _xbits; + int xmask = ((1 << _xbits) - 1) << _ybits; + do + { + uint8_t texdata; + + spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); + texdata = source[spot]; + if (texdata != 0) + { + 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; + yfrac += ystep; + } while (--count); + } } } @@ -2245,6 +2630,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; @@ -2257,41 +2644,87 @@ namespace swrenderer xstep = _xstep; ystep = _ystep; - if (_xbits == 6 && _ybits == 6) + if (!r_blendmethod) { - // 64x64 is the most common case by far, so special case it. - do + if (_xbits == 6 && _ybits == 6) { - 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); - *dest++ = RGB256k.RGB[r][g][b]; + // 64x64 is the most common case by far, so special case it. + do + { + spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); + uint32_t a = fg2rgb[colormap[source[spot]]] + bg2rgb[*dest]; + uint32_t b = a; - xfrac += xstep; - yfrac += ystep; - } while (--count); + a |= 0x01f07c1f; + b &= 0x40100400; + a &= 0x3fffffff; + b = b - (b >> 5); + a |= b; + *dest++ = RGB32k.All[a & (a >> 15)]; + xfrac += xstep; + yfrac += ystep; + } while (--count); + } + else + { + uint8_t yshift = 32 - _ybits; + uint8_t xshift = yshift - _xbits; + int xmask = ((1 << _xbits) - 1) << _ybits; + do + { + spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); + uint32_t a = fg2rgb[colormap[source[spot]]] + bg2rgb[*dest]; + uint32_t b = a; + + a |= 0x01f07c1f; + b &= 0x40100400; + a &= 0x3fffffff; + b = b - (b >> 5); + a |= b; + *dest++ = RGB32k.All[a & (a >> 15)]; + xfrac += xstep; + yfrac += ystep; + } while (--count); + } } else { - uint8_t yshift = 32 - _ybits; - uint8_t xshift = yshift - _xbits; - int xmask = ((1 << _xbits) - 1) << _ybits; - do + if (_xbits == 6 && _ybits == 6) { - 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); - *dest++ = RGB256k.RGB[r][g][b]; + // 64x64 is the most common case by far, so special case it. + do + { + 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); + *dest++ = RGB256k.RGB[r][g][b]; - xfrac += xstep; - yfrac += ystep; - } while (--count); + xfrac += xstep; + yfrac += ystep; + } while (--count); + } + else + { + uint8_t yshift = 32 - _ybits; + uint8_t xshift = yshift - _xbits; + int xmask = ((1 << _xbits) - 1) << _ybits; + do + { + 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); + *dest++ = RGB256k.RGB[r][g][b]; + + xfrac += xstep; + yfrac += ystep; + } while (--count); + } } } @@ -2309,6 +2742,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; @@ -2321,53 +2756,113 @@ namespace swrenderer xstep = _xstep; ystep = _ystep; - if (_xbits == 6 && _ybits == 6) + if (!r_columnmethod) { - // 64x64 is the most common case by far, so special case it. - do + if (_xbits == 6 && _ybits == 6) { - uint8_t texdata; - - spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); - texdata = source[spot]; - if (texdata != 0) + // 64x64 is the most common case by far, so special case it. + do { - 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; - yfrac += ystep; - } while (--count); + uint8_t texdata; + + spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); + 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)]; + } + dest++; + xfrac += xstep; + yfrac += ystep; + } while (--count); + } + else + { + uint8_t yshift = 32 - _ybits; + uint8_t xshift = yshift - _xbits; + int xmask = ((1 << _xbits) - 1) << _ybits; + do + { + uint8_t texdata; + + spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); + 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)]; + } + dest++; + xfrac += xstep; + yfrac += ystep; + } while (--count); + } } else { - uint8_t yshift = 32 - _ybits; - uint8_t xshift = yshift - _xbits; - int xmask = ((1 << _xbits) - 1) << _ybits; - do + if (_xbits == 6 && _ybits == 6) { - uint8_t texdata; - - spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); - texdata = source[spot]; - if (texdata != 0) + // 64x64 is the most common case by far, so special case it. + do { - 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; - yfrac += ystep; - } while (--count); + uint8_t texdata; + + spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); + texdata = source[spot]; + if (texdata != 0) + { + 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; + yfrac += ystep; + } while (--count); + } + else + { + uint8_t yshift = 32 - _ybits; + uint8_t xshift = yshift - _xbits; + int xmask = ((1 << _xbits) - 1) << _ybits; + do + { + uint8_t texdata; + + spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); + texdata = source[spot]; + if (texdata != 0) + { + 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; + yfrac += ystep; + } while (--count); + } } } diff --git a/src/r_plane.cpp b/src/r_plane.cpp index dbecb5247d..b8368e73a7 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -1509,12 +1509,16 @@ 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; } @@ -1531,12 +1535,16 @@ 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 = FRACUNIT; } diff --git a/src/r_things.cpp b/src/r_things.cpp index 61da979da8..95b563c0d6 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -72,6 +72,7 @@ EXTERN_CVAR(Int, r_drawfuzz) EXTERN_CVAR(Bool, r_deathcamera); EXTERN_CVAR(Bool, r_drawplayersprites) EXTERN_CVAR(Bool, r_drawvoxels) +EXTERN_CVAR(Bool, r_blendmethod) CVAR(Bool, r_fullbrightignoresectorcolor, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG); //CVAR(Bool, r_splitsprites, true, CVAR_ARCHIVE) @@ -2640,8 +2641,10 @@ static void R_DrawMaskedSegsBehindParticle (const vissprite_t *vis) void R_DrawParticle (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; @@ -2655,8 +2658,32 @@ void R_DrawParticle (vissprite_t *vis) // vis->renderflags holds translucency level (0-255) fixed_t fglevel, bglevel; - fglevel = ((vis->renderflags + 1) << 8) & ~0x3ff; - bglevel = FRACUNIT-fglevel; + { + DWORD *fg2rgb; + + 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);*/ // original was row-wise // width = countbase @@ -2664,20 +2691,40 @@ void R_DrawParticle (vissprite_t *vis) spacing = RenderTarget->GetPitch(); - for (int x = x1; x < (x1+countbase); x++) + if (!r_blendmethod) { - dc_x = x; - if (R_ClipSpriteColumnWithPortals(vis)) - continue; - dest = ylookup[yl] + x + dc_destorg; - for (int y = 0; y < ycount; y++) + for (int x = x1; x < (x1+countbase); x++) { - 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); + dc_x = x; + if (R_ClipSpriteColumnWithPortals(vis)) + continue; + 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)]; + dest += spacing; + } + } + } + else + { + for (int x = x1; x < (x1+countbase); x++) + { + dc_x = x; + if (R_ClipSpriteColumnWithPortals(vis)) + continue; + dest = ylookup[yl] + x + dc_destorg; + for (int y = 0; y < ycount; y++) + { + 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; + *dest = RGB256k.RGB[dest_r][dest_g][dest_b]; + dest += spacing; + } } } } From 785b58f57a9c8b93ad407a021ab536d5ed3545b7 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 24 Dec 2016 12:30:45 -0500 Subject: [PATCH 22/25] - Reimplemented rgb555 for drawers in r_drawt_pal.cpp --- src/r_drawt_pal.cpp | 529 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 415 insertions(+), 114 deletions(-) diff --git a/src/r_drawt_pal.cpp b/src/r_drawt_pal.cpp index d07ecd67a5..dcc0a09389 100644 --- a/src/r_drawt_pal.cpp +++ b/src/r_drawt_pal.cpp @@ -50,6 +50,8 @@ #include "v_video.h" #include "r_draw_pal.h" +EXTERN_CVAR(Bool, r_blendmethod) + // I should have commented this stuff better. // // dc_temp is the buffer R_DrawColumnHoriz writes into. @@ -444,23 +446,42 @@ 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; const PalEntry *palette = GPalette.BaseColors; - do { - uint32_t fg = colormap[*source]; - uint32_t bg = *dest; + if (!r_blendmethod) + { + do { + uint32_t fg = colormap[*source]; + uint32_t 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]; - source += 4; - dest += pitch; - } while (--count); + fg = fg2rgb[fg]; + bg = bg2rgb[bg]; + fg = (fg+bg) | 0x1f07c1f; + *dest = RGB32k.All[fg & (fg>>15)]; + source += 4; + dest += pitch; + } while (--count); + } + else + { + do { + uint32_t fg = colormap[*source]; + uint32_t 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]; + source += 4; + dest += pitch; + } while (--count); + } } void DrawColumnRt4AddPalCommand::Execute(DrawerThread *thread) @@ -475,30 +496,72 @@ 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; 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((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]; - } + if (!r_blendmethod) + { + 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)]; - source += 4; - dest += pitch; - } while (--count); + 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)]; + + source += 4; + dest += pitch; + } while (--count); + } + else + { + 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((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]; + } + + source += 4; + dest += pitch; + } while (--count); + } } void DrawColumnRt1ShadedPalCommand::Execute(DrawerThread *thread) { + uint32_t *fgstart; const uint8_t *colormap; uint8_t *source; uint8_t *dest; @@ -509,25 +572,41 @@ 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]; pitch = _pitch * thread->num_cores; const PalEntry *palette = GPalette.BaseColors; - do { - uint32_t val = *source; - 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; - } while (--count); + if (!r_blendmethod) + { + 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)]; + source += 4; + dest += pitch; + } while (--count); + } + else + { + do { + uint32_t val = *source; + 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; + } while (--count); + } } void DrawColumnRt4ShadedPalCommand::Execute(DrawerThread *thread) { + uint32_t *fgstart; const uint8_t *colormap; uint8_t *source; uint8_t *dest; @@ -538,27 +617,56 @@ 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]; pitch = _pitch * thread->num_cores; const PalEntry *palette = GPalette.BaseColors; - do { - uint32_t val; + if (!r_blendmethod) + { + 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)]; - for (int ks = 0; ks < 4; ks++) - { - val = source[ks]; - 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)]; - } + val = colormap[source[1]]; + val = (Col2RGB8[64-val][dest[1]] + fgstart[val<<8]) | 0x1f07c1f; + dest[1] = RGB32k.All[val & (val>>15)]; - source += 4; - dest += pitch; - } while (--count); + 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)]; + + source += 4; + dest += pitch; + } while (--count); + } + else + { + do { + uint32_t val; + + for (int ks = 0; ks < 4; ks++) + { + val = source[ks]; + 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)]; + } + + source += 4; + dest += pitch; + } while (--count); + } } void DrawColumnRt1AddClampPalCommand::Execute(DrawerThread *thread) @@ -573,22 +681,43 @@ 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; const PalEntry *palette = GPalette.BaseColors; - do { - 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); - int b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); - *dest = RGB256k.RGB[r][g][b]; - source += 4; - dest += pitch; - } while (--count); + if (!r_blendmethod) + { + 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]; + source += 4; + dest += pitch; + } while (--count); + } + else + { + do { + 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); + int b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); + *dest = RGB256k.RGB[r][g][b]; + source += 4; + dest += pitch; + } while (--count); + } } void DrawColumnRt4AddClampPalCommand::Execute(DrawerThread *thread) @@ -609,20 +738,70 @@ namespace swrenderer colormap = _colormap; const PalEntry *palette = GPalette.BaseColors; - do { - for (int ks = 0; ks < 4; 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); - int b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); - dest[ks] = RGB256k.RGB[r][g][b]; - } + const uint32_t *fg2rgb = _srcblend; + const uint32_t *bg2rgb = _destblend; - source += 4; - dest += pitch; - } while (--count); + if (!r_blendmethod) + { + 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]; + + source += 4; + dest += pitch; + } while (--count); + } + else + { + do { + for (int ks = 0; ks < 4; 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); + int b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); + dest[ks] = RGB256k.RGB[r][g][b]; + } + + source += 4; + dest += pitch; + } while (--count); + } } void DrawColumnRt1SubClampPalCommand::Execute(DrawerThread *thread) @@ -645,16 +824,34 @@ namespace swrenderer colormap = _colormap; const PalEntry *palette = GPalette.BaseColors; - do { - 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); - 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); + if (!r_blendmethod) + { + 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]; + source += 4; + dest += pitch; + } while (--count); + } + else + { + do { + 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); + 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); + } } void DrawColumnRt4SubClampPalCommand::Execute(DrawerThread *thread) @@ -677,20 +874,63 @@ namespace swrenderer colormap = _colormap; const PalEntry *palette = GPalette.BaseColors; - do { - for (int ks = 0; ks < 4; 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); - int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); - dest[ks] = RGB256k.RGB[r][g][b]; - } + if (!r_blendmethod) + { + do { + uint32_t a = (fg2rgb[colormap[source[0]]] | 0x40100400) - bg2rgb[dest[0]]; + uint32_t b = a; - source += 4; - dest += pitch; - } while (--count); + 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]; + + source += 4; + dest += pitch; + } while (--count); + } + else + { + do { + for (int ks = 0; ks < 4; 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); + int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + dest[ks] = RGB256k.RGB[r][g][b]; + } + + source += 4; + dest += pitch; + } while (--count); + } } void DrawColumnRt1RevSubClampPalCommand::Execute(DrawerThread *thread) @@ -713,16 +953,34 @@ namespace swrenderer colormap = _colormap; const PalEntry *palette = GPalette.BaseColors; - do { - 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); - 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); + if (!r_blendmethod) + { + 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]; + source += 4; + dest += pitch; + } while (--count); + } + else + { + do { + 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); + 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); + } } void DrawColumnRt4RevSubClampPalCommand::Execute(DrawerThread *thread) @@ -745,19 +1003,62 @@ namespace swrenderer colormap = _colormap; const PalEntry *palette = GPalette.BaseColors; - do { - for (int ks = 0; ks < 4; 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); - int b = MAX((-palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); - dest[ks] = RGB256k.RGB[r][g][b]; - } + if (!r_blendmethod) + { + do { + uint32_t a = (bg2rgb[dest[0]] | 0x40100400) - fg2rgb[colormap[source[0]]]; + uint32_t b = a; - source += 4; - dest += pitch; - } while (--count); + 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]; + + source += 4; + dest += pitch; + } while (--count); + } + else + { + do { + for (int ks = 0; ks < 4; 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); + int b = MAX((-palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); + dest[ks] = RGB256k.RGB[r][g][b]; + } + + source += 4; + dest += pitch; + } while (--count); + } } } From 9ece249dbb02e5897e5cf972fd3cf8b96ea014c7 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 24 Dec 2016 12:42:27 -0500 Subject: [PATCH 23/25] - Reimplemented rgb555 into burn/crossfade in f_wipe.cpp. --- src/f_wipe.cpp | 141 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 101 insertions(+), 40 deletions(-) diff --git a/src/f_wipe.cpp b/src/f_wipe.cpp index 8d5f072f62..9d487bc9dc 100644 --- a/src/f_wipe.cpp +++ b/src/f_wipe.cpp @@ -30,6 +30,8 @@ #include "templates.h" #include "v_palette.h" +EXTERN_CVAR(Bool, r_blendmethod) + // // SCREEN WIPE PACKAGE // @@ -281,42 +283,80 @@ bool wipe_doBurn (int ticks) fromold = (BYTE *)wipe_scr_start; fromnew = (BYTE *)wipe_scr_end; - for (y = 0, firey = 0; y < SCREENHEIGHT; y++, firey += ystep) + if (!r_blendmethod) { - for (x = 0, firex = 0; x < SCREENWIDTH; x++, firex += xstep) + for (y = 0, firey = 0; y < SCREENHEIGHT; y++, firey += ystep) { - int fglevel; - - fglevel = burnarray[(firex>>SHIFT)+(firey>>SHIFT)*FIREWIDTH] / 2; - if (fglevel >= 63) + for (x = 0, firex = 0; x < SCREENWIDTH; x++, firex += xstep) { - to[x] = fromnew[x]; - } - else if (fglevel == 0) - { - to[x] = fromold[x]; - done = false; - } - else - { - int bglevel = 64-fglevel; + int fglevel; - 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; + fglevel = burnarray[(firex>>SHIFT)+(firey>>SHIFT)*FIREWIDTH] / 2; + if (fglevel >= 63) + { + to[x] = fromnew[x]; + } + else if (fglevel == 0) + { + to[x] = fromold[x]; + done = false; + } + 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)]; + done = false; + } } + fromold += SCREENWIDTH; + fromnew += SCREENWIDTH; + to += SCREENPITCH; } - fromold += SCREENWIDTH; - fromnew += SCREENWIDTH; - to += SCREENPITCH; - } + } + else + { + for (y = 0, firey = 0; y < SCREENHEIGHT; y++, firey += ystep) + { + for (x = 0, firex = 0; x < SCREENWIDTH; x++, firex += xstep) + { + int fglevel; + + fglevel = burnarray[(firex>>SHIFT)+(firey>>SHIFT)*FIREWIDTH] / 2; + if (fglevel >= 63) + { + to[x] = fromnew[x]; + } + else if (fglevel == 0) + { + to[x] = fromold[x]; + done = false; + } + else + { + int bglevel = 64-fglevel; + + 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; + } + } + fromold += SCREENWIDTH; + fromnew += SCREENWIDTH; + to += SCREENPITCH; + } + } return done || (burntime > 40); } @@ -346,25 +386,46 @@ 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(); const PalEntry *pal = GPalette.BaseColors; - for (y = 0; y < SCREENHEIGHT; y++) + if (!r_blendmethod) { - for (x = 0; x < SCREENWIDTH; x++) + for (y = 0; y < SCREENHEIGHT; y++) { - 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]; + 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)]; + } + fromnew += SCREENWIDTH; + fromold += SCREENWIDTH; + to += SCREENPITCH; + } + } + else + { + for (y = 0; y < SCREENHEIGHT; y++) + { + for (x = 0; x < SCREENWIDTH; x++) + { + 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; + to += SCREENPITCH; } - fromnew += SCREENWIDTH; - fromold += SCREENWIDTH; - to += SCREENPITCH; } } return false; From 2fa13396f20f110af422a6d86d7d1c12a5a80f5f Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 24 Dec 2016 12:50:17 -0500 Subject: [PATCH 24/25] - Added r_blendmethod to the menu. --- wadsrc/static/language.enu | 4 ++++ wadsrc/static/menudef.txt | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/wadsrc/static/language.enu b/wadsrc/static/language.enu index 28db40e649..8c2b733fda 100644 --- a/wadsrc/static/language.enu +++ b/wadsrc/static/language.enu @@ -1780,6 +1780,8 @@ DSPLYMNU_BRIGHTNESS = "Brightness"; DSPLYMNU_VSYNC = "Vertical Sync"; DSPLYMNU_CAPFPS = "Rendering Interpolation"; DSPLYMNU_COLUMNMETHOD = "Column render mode"; +DSPLYMNU_BLENDMETHOD = "Transparency render mode"; + DSPLYMNU_WIPETYPE = "Screen wipe style"; DSPLYMNU_SHOWENDOOM = "Show ENDOOM screen"; DSPLYMNU_BLOODFADE = "Blood Flash Intensity"; @@ -2189,6 +2191,8 @@ OPTVAL_INVERTED = "Inverted"; OPTVAL_NOTINVERTED = "Not Inverted"; OPTVAL_ORIGINAL = "Original"; OPTVAL_OPTIMIZED = "Optimized"; +OPTVAL_CLASSIC = "Classic (Faster)"; +OPTVAL_PRECISE = "Precise"; OPTVAL_NORMAL = "Normal"; OPTVAL_STRETCH = "Stretch"; OPTVAL_CAPPED = "Capped"; diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index 30cad4dd24..73873c7764 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -600,6 +600,12 @@ OptionValue ColumnMethods 1.0, "$OPTVAL_OPTIMIZED" } +OptionValue BlendMethods +{ + 0.0, "$OPTVAL_CLASSIC" + 1.0, "$OPTVAL_PRECISE" +} + OptionValue SkyModes { 0.0, "$OPTVAL_NORMAL" @@ -671,6 +677,7 @@ OptionMenu "VideoOptions" Slider "$DSPLYMNU_PICKUPFADE", "pickup_fade_scalar", 0.0, 1.0, 0.05, 2 Slider "$DSPLYMNU_WATERFADE", "underwater_fade_scalar", 0.0, 1.0, 0.05, 2 Option "$DSPLYMNU_COLUMNMETHOD", "r_columnmethod", "ColumnMethods" + Option "$DSPLYMNU_BLENDMETHOD", "r_blendmethod", "BlendMethods" StaticText " " Option "$DSPLYMNU_WIPETYPE", "wipetype", "Wipes" From 62e093a7da977bbaeefd730f8d1788eb301a1ca3 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 24 Dec 2016 14:10:51 -0500 Subject: [PATCH 25/25] - fixed: mistyped r_columnmethod instead of r_blendmethod in a span drawer. --- src/r_draw_pal.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_draw_pal.cpp b/src/r_draw_pal.cpp index 88fe93f85a..37d38891ef 100644 --- a/src/r_draw_pal.cpp +++ b/src/r_draw_pal.cpp @@ -2756,7 +2756,7 @@ namespace swrenderer xstep = _xstep; ystep = _ystep; - if (!r_columnmethod) + if (!r_blendmethod) { if (_xbits == 6 && _ybits == 6) {