From eac1007c56b2d1422c763e76f8cf814f4efa7231 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 30 Jan 2020 22:05:18 +0100 Subject: [PATCH] - automap color fix. --- source/build/include/build.h | 3 +-- source/build/src/defs.cpp | 5 ---- source/build/src/palette.cpp | 13 +++------- source/common/2d/v_2ddrawer.cpp | 6 ++++- .../postprocessing/hw_postprocess.cpp | 2 +- source/common/textures/imagehelpers.cpp | 12 ++++------ source/common/textures/imagehelpers.h | 3 +-- source/duke3d/src/screens.cpp | 20 ++++++++-------- source/exhumed/src/map.cpp | 4 ++-- source/rr/src/screens.cpp | 24 +++++++++---------- 10 files changed, 40 insertions(+), 52 deletions(-) diff --git a/source/build/include/build.h b/source/build/include/build.h index 301bc51bf..a5b6a1e27 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -655,8 +655,6 @@ EXTERN char show2dsprite[(MAXSPRITES+7)>>3]; EXTERN uint8_t gotpic[(MAXTILES+7)>>3]; EXTERN char gotsector[(MAXSECTORS+7)>>3]; -EXTERN char editorcolors[256]; -EXTERN char editorcolorsdef[256]; EXTERN char editwall[(MAXWALLS+7)>>3]; @@ -874,6 +872,7 @@ void rotatesprite_(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnu int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2); void renderDrawLine(int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint8_t col); void drawlinergb(int32_t x1, int32_t y1, int32_t x2, int32_t y2, palette_t p); +void drawlinergb(int32_t x1, int32_t y1, int32_t x2, int32_t y2, PalEntry p); ////////// specialized rotatesprite wrappers for (very) often used cases ////////// static FORCE_INLINE void rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, diff --git a/source/build/src/defs.cpp b/source/build/src/defs.cpp index 1c48f01bf..5c824229f 100644 --- a/source/build/src/defs.cpp +++ b/source/build/src/defs.cpp @@ -460,11 +460,6 @@ static int32_t defsparser(scriptfile *script) if (scriptfile_getnumber(script,&idx)) break; if (scriptfile_getnumber(script,&idxend)) break; - while ((unsigned)col < 256 && idx <= idxend) - { - editorcolorsdef[col] = 1; - editorcolors[col++] = idx++; - } } break; case T_FOGPAL: diff --git a/source/build/src/palette.cpp b/source/build/src/palette.cpp index 2bd1e446e..a3d419250 100644 --- a/source/build/src/palette.cpp +++ b/source/build/src/palette.cpp @@ -297,7 +297,9 @@ void palettePostLoadTables(void) for (bssize_t i=256; i<512; i++) palookup0[i] = palookup0[i+(16<<8)]; #endif - + PalEntry pe[256]; + for (int i = 0; i < 256; i++) pe[i] = PalEntry(palette[i * 3], palette[i * 3 + 1], palette[i * 3 + 2]); + ImageHelpers::SetPalette(pe); blackcol = ImageHelpers::BestColor(0, 0, 0); whitecol = ImageHelpers::BestColor(255, 255, 255); redcol = ImageHelpers::BestColor(255, 0, 0); @@ -338,15 +340,6 @@ void palettePostLoadTables(void) PostLoad_FoundShade: ; frealmaxshade = (float)(realmaxshade = s+1); } - - for (size_t i = 0; i<256; i++) - { - if (editorcolorsdef[i]) - continue; - - palette_t *edcol = (palette_t *) &vgapal16[4*i]; - editorcolors[i] = ImageHelpers::BestColor(edcol->b, edcol->g, edcol->r, 254); - } } void paletteFixTranslucencyMask(void) diff --git a/source/common/2d/v_2ddrawer.cpp b/source/common/2d/v_2ddrawer.cpp index 4baf9d6be..f3ac81637 100644 --- a/source/common/2d/v_2ddrawer.cpp +++ b/source/common/2d/v_2ddrawer.cpp @@ -829,10 +829,14 @@ void F2DDrawer::FillPolygon(int *rx1, int *ry1, int *xb1, int32_t npoints, int p AddPoly(TileFiles.tiles[picnum], points.Data(), points.Size(), indices.data(), indices.size(), palette, shade, (props >> 7)& DAMETH_MASKPROPS, clipx1, clipy1, clipx2, clipy2); } +void drawlinergb(int32_t x1, int32_t y1, int32_t x2, int32_t y2, PalEntry p) +{ + twod->AddLine(x1 / 4096.f, y1 / 4096.f, x2 / 4096.f, y2 / 4096.f, windowxy1.x, windowxy1.y, windowxy2.x, windowxy2.y, p); +} void drawlinergb(int32_t x1, int32_t y1, int32_t x2, int32_t y2, palette_t p) { - twod->AddLine(x1 / 4096.f, y1 / 4096.f, x2 / 4096.f, y2 / 4096.f, windowxy1.x, windowxy1.y, windowxy2.x, windowxy2.y, PalEntry(p.r, p.g, p.b)); + drawlinergb(x1, y1, x2, y2, PalEntry(p.r, p.g, p.b)); } void renderDrawLine(int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint8_t col) diff --git a/source/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp b/source/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp index 00a5ac358..a1e566a7e 100644 --- a/source/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp +++ b/source/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp @@ -542,7 +542,7 @@ void PPTonemap::UpdateTextures() { for (int b = 0; b < 64; b++) { - PalEntry color = ImageHelpers::BaseColors[(uint8_t)ImageHelpers::PTM_BestColor((r << 2) | (r >> 4), (g << 2) | (g >> 4), (b << 2) | (b >> 4), + PalEntry color = ImageHelpers::BasePalette[(uint8_t)ImageHelpers::PTM_BestColor((r << 2) | (r >> 4), (g << 2) | (g >> 4), (b << 2) | (b >> 4), gl_paltonemap_reverselookup, gl_paltonemap_powtable, 0, 256)]; int index = ((r * 64 + g) * 64 + b) * 4; lut[index] = color.r; diff --git a/source/common/textures/imagehelpers.cpp b/source/common/textures/imagehelpers.cpp index 77bc4c4a0..e1842956c 100644 --- a/source/common/textures/imagehelpers.cpp +++ b/source/common/textures/imagehelpers.cpp @@ -40,21 +40,19 @@ namespace ImageHelpers { uint8_t GrayMap[256]; - PalEntry BaseColors[256]; - PalEntry BasePalette[256]; // same as above, but with a being a proper alpha channel. + PalEntry BasePalette[256]; int WhiteIndex, BlackIndex; int alphaThreshold; ColorTable256k RGB256k; int BestColor(int r, int g, int b, int first, int num) { - const PalEntry* pal = BaseColors; + const PalEntry* pal = BasePalette; int bestcolor = first; int bestdist = 257 * 257 + 257 * 257 + 257 * 257; for (int color = first; color < num; color++) { - if (pal[color].a > 0) continue; // marks a fullbright color which we should not pick here int x = r - pal[color].r; int y = g - pal[color].g; int z = b - pal[color].b; @@ -75,7 +73,7 @@ namespace ImageHelpers int PTM_BestColor(int r, int g, int b, bool reverselookup, float powtable_val, int first, int num) { - const PalEntry* pal = BaseColors; + const PalEntry* pal = BasePalette; static double powtable[256]; static bool firstTime = true; static float trackpowtable = 0.; @@ -113,10 +111,10 @@ namespace ImageHelpers { for (int i = 0; i < 255; i++) { - BasePalette[i] = BaseColors[i] = colors[i]; + BasePalette[i] = colors[i]; BasePalette[i].a = 255; } - BasePalette[255] = BaseColors[255] = 0; // 255 is always translucent black - whatever color the original data has here + BasePalette[255] = 0; // 255 is always translucent black - whatever color the original data has here // Find white and black from the original palette so that they can be // used to make an educated guess of the translucency % for a diff --git a/source/common/textures/imagehelpers.h b/source/common/textures/imagehelpers.h index 34e64c7b2..69807042d 100644 --- a/source/common/textures/imagehelpers.h +++ b/source/common/textures/imagehelpers.h @@ -51,8 +51,7 @@ namespace ImageHelpers }; extern uint8_t GrayMap[256]; - extern PalEntry BaseColors[256]; - extern PalEntry BasePalette[256]; // same as above, but with a being a proper alpha channel. + extern PalEntry BasePalette[256]; extern int WhiteIndex, BlackIndex; extern ColorTable256k RGB256k; extern int alphaThreshold; diff --git a/source/duke3d/src/screens.cpp b/source/duke3d/src/screens.cpp index 92f41b92a..11f9d003f 100644 --- a/source/duke3d/src/screens.cpp +++ b/source/duke3d/src/screens.cpp @@ -233,7 +233,7 @@ static void G_DrawOverheadMap(int32_t cposx, int32_t cposy, int32_t czoom, int16 int32_t xrepeat, yrepeat, z1, z2, startwall, endwall, tilenum, daang; int32_t xvect, yvect, xvect2, yvect2; int16_t p; - char col; + PalEntry col; uwallptr_t wal, wal2; spritetype *spr; @@ -265,8 +265,8 @@ static void G_DrawOverheadMap(int32_t cposx, int32_t cposy, int32_t czoom, int16 if (sector[wal->nextsector].ceilingz == z1 && sector[wal->nextsector].floorz == z2) if (((wal->cstat|wall[wal->nextwall].cstat)&(16+32)) == 0) continue; - if (!(show2dsector[wal->nextsector>>3]&pow2char[wal->nextsector&7])) - col = editorcolors[7]; + if (!(show2dsector[wal->nextsector >> 3] & pow2char[wal->nextsector & 7])) + col = PalEntry(170, 170, 170); else continue; ox = wal->x-cposx; @@ -280,7 +280,7 @@ static void G_DrawOverheadMap(int32_t cposx, int32_t cposy, int32_t czoom, int16 x2 = dmulscale16(ox, xvect, -oy, yvect)+(xdim<<11); y2 = dmulscale16(oy, xvect2, ox, yvect2)+(ydim<<11); - renderDrawLine(x1, y1, x2, y2, col); + drawlinergb(x1, y1, x2, y2, col); } } @@ -295,8 +295,8 @@ static void G_DrawOverheadMap(int32_t cposx, int32_t cposy, int32_t czoom, int16 if (j == k || (spr->cstat&0x8000) || spr->cstat == 257 || spr->xrepeat == 0) continue; - col = editorcolors[6]; //cyan - if (spr->cstat&1) col = editorcolors[5]; //magenta + col = PalEntry(0, 170, 170); + if (spr->cstat & 1) col = PalEntry(170, 0, 170); sprx = spr->x; spry = spr->y; @@ -319,11 +319,11 @@ static void G_DrawOverheadMap(int32_t cposx, int32_t cposy, int32_t czoom, int16 x3 = mulscale16(x2, yxaspect); y3 = mulscale16(y2, yxaspect); - renderDrawLine(x1-x2+(xdim<<11), y1-y3+(ydim<<11), + drawlinergb(x1-x2+(xdim<<11), y1-y3+(ydim<<11), x1+x2+(xdim<<11), y1+y3+(ydim<<11), col); - renderDrawLine(x1-y2+(xdim<<11), y1+x3+(ydim<<11), + drawlinergb(x1-y2+(xdim<<11), y1+x3+(ydim<<11), x1+x2+(xdim<<11), y1+y3+(ydim<<11), col); - renderDrawLine(x1+y2+(xdim<<11), y1-x3+(ydim<<11), + drawlinergb(x1+y2+(xdim<<11), y1-x3+(ydim<<11), x1+x2+(xdim<<11), y1+y3+(ydim<<11), col); break; @@ -465,7 +465,7 @@ static void G_DrawOverheadMap(int32_t cposx, int32_t cposy, int32_t czoom, int16 x2 = dmulscale16(ox, xvect, -oy, yvect)+(xdim<<11); y2 = dmulscale16(oy, xvect2, ox, yvect2)+(ydim<<11); - renderDrawLine(x1, y1, x2, y2, editorcolors[7]); + drawlinergb(x1, y1, x2, y2, PalEntry(170, 170, 170)); } } diff --git a/source/exhumed/src/map.cpp b/source/exhumed/src/map.cpp index 20ee6b7ae..192318dbf 100644 --- a/source/exhumed/src/map.cpp +++ b/source/exhumed/src/map.cpp @@ -370,8 +370,8 @@ static void G_DrawOverheadMap(int32_t cposx, int32_t cposy, int32_t czoom, int16 if (j == k || (spr->cstat&0x8000) || spr->cstat == 257 || spr->xrepeat == 0) continue; - col = editorcolors[6]; //cyan - if (spr->cstat&1) col = editorcolors[5]; //magenta + col = PalEntry(0, 170, 170); + if (spr->cstat & 1) col = PalEntry(170, 0, 170); sprx = spr->x; spry = spr->y; diff --git a/source/rr/src/screens.cpp b/source/rr/src/screens.cpp index 3d8985e90..6a1182814 100644 --- a/source/rr/src/screens.cpp +++ b/source/rr/src/screens.cpp @@ -229,7 +229,7 @@ static void G_DrawOverheadMap(int32_t cposx, int32_t cposy, int32_t czoom, int16 int32_t xrepeat, yrepeat, z1, z2, startwall, endwall, tilenum, daang; int32_t xvect, yvect, xvect2, yvect2; int16_t p; - char col; + PalEntry col; uwalltype *wal, *wal2; spritetype *spr; @@ -262,11 +262,11 @@ static void G_DrawOverheadMap(int32_t cposx, int32_t cposy, int32_t czoom, int16 if (sector[wal->nextsector].floorz == z2) if (((wal->cstat|wall[wal->nextwall].cstat)&(16+32)) == 0) continue; - col = editorcolors[1]; //red - if ((wal->cstat|wall[wal->nextwall].cstat)&1) col = editorcolors[5]; //magenta + col = PalEntry(255, 0, 0); + if ((wal->cstat | wall[wal->nextwall].cstat) & 1) col = PalEntry(170, 0, 170); - if (!(show2dsector[wal->nextsector>>3]&(1<<(wal->nextsector&7)))) - col = editorcolors[7]; + if (!(show2dsector[wal->nextsector >> 3] & (1 << (wal->nextsector & 7)))) + col = PalEntry(170, 170, 170); else continue; ox = wal->x-cposx; @@ -280,7 +280,7 @@ static void G_DrawOverheadMap(int32_t cposx, int32_t cposy, int32_t czoom, int16 x2 = dmulscale16(ox, xvect, -oy, yvect)+(xdim<<11); y2 = dmulscale16(oy, xvect2, ox, yvect2)+(ydim<<11); - renderDrawLine(x1, y1, x2, y2, col); + drawlinergb(x1, y1, x2, y2, col); } } @@ -295,8 +295,8 @@ static void G_DrawOverheadMap(int32_t cposx, int32_t cposy, int32_t czoom, int16 if (j == k || (spr->cstat&0x8000) || spr->cstat == 257 || spr->xrepeat == 0) continue; - col = editorcolors[6]; //cyan - if (spr->cstat&1) col = editorcolors[5]; //magenta + col = PalEntry(0, 170, 170); + if (spr->cstat & 1) col = PalEntry(170, 0, 170); sprx = spr->x; spry = spr->y; @@ -319,11 +319,11 @@ static void G_DrawOverheadMap(int32_t cposx, int32_t cposy, int32_t czoom, int16 x3 = mulscale16(x2, yxaspect); y3 = mulscale16(y2, yxaspect); - renderDrawLine(x1-x2+(xdim<<11), y1-y3+(ydim<<11), + drawlinergb(x1-x2+(xdim<<11), y1-y3+(ydim<<11), x1+x2+(xdim<<11), y1+y3+(ydim<<11), col); - renderDrawLine(x1-y2+(xdim<<11), y1+x3+(ydim<<11), + drawlinergb(x1-y2+(xdim<<11), y1+x3+(ydim<<11), x1+x2+(xdim<<11), y1+y3+(ydim<<11), col); - renderDrawLine(x1+y2+(xdim<<11), y1-x3+(ydim<<11), + drawlinergb(x1+y2+(xdim<<11), y1-x3+(ydim<<11), x1+x2+(xdim<<11), y1+y3+(ydim<<11), col); break; @@ -465,7 +465,7 @@ static void G_DrawOverheadMap(int32_t cposx, int32_t cposy, int32_t czoom, int16 x2 = dmulscale16(ox, xvect, -oy, yvect)+(xdim<<11); y2 = dmulscale16(oy, xvect2, ox, yvect2)+(ydim<<11); - renderDrawLine(x1, y1, x2, y2, editorcolors[7]); + renderDrawLine(x1, y1, x2, y2, PalEntry(170, 170, 170)); } }