- automap color fix.

This commit is contained in:
Christoph Oelckers 2020-01-30 22:05:18 +01:00
parent 08a5c5ff4d
commit eac1007c56
10 changed files with 40 additions and 52 deletions

View file

@ -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,

View file

@ -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:

View file

@ -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)

View file

@ -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)

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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));
}
}

View file

@ -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;

View file

@ -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));
}
}