Replace color matching up to index 239 with the engine's fullbright mask

Should improve the color range available to non-Duke editors.

git-svn-id: https://svn.eduke32.com/eduke32@8491 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2019-12-23 07:03:55 +00:00 committed by Christoph Oelckers
parent 34ef03185d
commit 56e88b33a8
3 changed files with 27 additions and 9 deletions

View file

@ -5,10 +5,19 @@ extern void paletteInitClosestColorScale(int32_t rscale, int32_t gscale, int32_t
extern void paletteInitClosestColorMap(uint8_t const * pal) ATTRIBUTE((nonnull(1))); extern void paletteInitClosestColorMap(uint8_t const * pal) ATTRIBUTE((nonnull(1)));
extern void paletteInitClosestColorGrid(void); extern void paletteInitClosestColorGrid(void);
extern int32_t paletteGetClosestColorUpToIndex(int32_t r, int32_t g, int32_t b, int32_t lastokcol); extern int32_t paletteGetClosestColorWithBlacklist(int32_t r, int32_t g, int32_t b, int32_t lastokcol, uint8_t const * blacklist);
extern int32_t paletteGetClosestColorUpToIndexNoCache(int32_t r, int32_t g, int32_t b, int32_t lastokcol); extern int32_t paletteGetClosestColorWithBlacklistNoCache(int32_t r, int32_t g, int32_t b, int32_t lastokcol, uint8_t const * blacklist);
extern void paletteFlushClosestColor(void); extern void paletteFlushClosestColor(void);
static FORCE_INLINE int32_t paletteGetClosestColorUpToIndex(int32_t r, int32_t g, int32_t b, int32_t lastokcol)
{
return paletteGetClosestColorWithBlacklist(r, g, b, lastokcol, NULL);
}
static FORCE_INLINE int32_t paletteGetClosestColorUpToIndexNoCache(int32_t r, int32_t g, int32_t b, int32_t lastokcol)
{
return paletteGetClosestColorWithBlacklistNoCache(r, g, b, lastokcol, NULL);
}
static FORCE_INLINE int32_t paletteGetClosestColor(int32_t r, int32_t g, int32_t b) static FORCE_INLINE int32_t paletteGetClosestColor(int32_t r, int32_t g, int32_t b)
{ {
return paletteGetClosestColorUpToIndex(r, g, b, 255); return paletteGetClosestColorUpToIndex(r, g, b, 255);

View file

@ -80,9 +80,11 @@ void paletteFlushClosestColor(void)
numcolmatchresults = 0; numcolmatchresults = 0;
} }
#define checkbitfield(field, idx) ((field)[(idx)>>3] & (1u<<((idx)&7)))
// Finds a color index in [0 .. lastokcol] closest to (r, g, b). // Finds a color index in [0 .. lastokcol] closest to (r, g, b).
// <lastokcol> must be in [0 .. 255]. // <lastokcol> must be in [0 .. 255].
int32_t paletteGetClosestColorUpToIndex(int32_t const r, int32_t const g, int32_t const b, int32_t const lastokcol) int32_t paletteGetClosestColorWithBlacklist(int32_t const r, int32_t const g, int32_t const b, int32_t const lastokcol, uint8_t const * const blacklist)
{ {
#ifdef DEBUGGINGAIDS #ifdef DEBUGGINGAIDS
Bassert(lastokcol >= 0 && lastokcol <= 255); Bassert(lastokcol >= 0 && lastokcol <= 255);
@ -113,16 +115,20 @@ int32_t paletteGetClosestColorUpToIndex(int32_t const r, int32_t const g, int32_
for (; i < k; i++) for (; i < k; i++)
if (col == (colmatchresults[i] & 0x00ffffff)) { mindist = i; break; } if (col == (colmatchresults[i] & 0x00ffffff)) { mindist = i; break; }
if (mindist != -1 && colmatchresults[mindist]>>24 <= (unsigned)lastokcol) if (mindist != -1)
return colmatchresults[mindist]>>24; {
uint32_t const idx = colmatchresults[mindist]>>24;
if (idx <= (unsigned)lastokcol && (blacklist == nullptr || !checkbitfield(blacklist, idx)))
return idx;
}
skip: skip:
i = paletteGetClosestColorUpToIndexNoCache(r, g, b, lastokcol); i = paletteGetClosestColorWithBlacklistNoCache(r, g, b, lastokcol, blacklist);
colmatchresults[numcolmatchresults++ & (COLRESULTSIZ-1)] = col | (i << 24); colmatchresults[numcolmatchresults++ & (COLRESULTSIZ-1)] = col | (i << 24);
return i; return i;
} }
int32_t paletteGetClosestColorUpToIndexNoCache(int32_t r, int32_t g, int32_t b, int32_t const lastokcol) int32_t paletteGetClosestColorWithBlacklistNoCache(int32_t r, int32_t g, int32_t b, int32_t const lastokcol, uint8_t const * const blacklist)
{ {
#ifdef DEBUGGINGAIDS #ifdef DEBUGGINGAIDS
Bassert(lastokcol >= 0 && lastokcol <= 255); Bassert(lastokcol >= 0 && lastokcol <= 255);
@ -158,7 +164,7 @@ int32_t paletteGetClosestColorUpToIndexNoCache(int32_t r, int32_t g, int32_t b,
char const * const pal1 = (char const *)&colmatch_palette[i*3]; char const * const pal1 = (char const *)&colmatch_palette[i*3];
int dist = gdist[pal1[1]+g]; int dist = gdist[pal1[1]+g];
if (dist >= mindist || i > lastokcol) continue; if (dist >= mindist || i > lastokcol || (blacklist != nullptr && checkbitfield(blacklist, i))) continue;
if ((dist += rdist[pal1[0]+r]) >= mindist) continue; if ((dist += rdist[pal1[0]+r]) >= mindist) continue;
if ((dist += bdist[pal1[2]+b]) >= mindist) continue; if ((dist += bdist[pal1[2]+b]) >= mindist) continue;
@ -175,6 +181,9 @@ int32_t paletteGetClosestColorUpToIndexNoCache(int32_t r, int32_t g, int32_t b,
for (bssize_t i = 0; i <= lastokcol; ++i) for (bssize_t i = 0; i <= lastokcol; ++i)
{ {
if (blacklist != nullptr && checkbitfield(blacklist, i))
continue;
char const * const pal1 = (char const *)&colmatch_palette[i*3]; char const * const pal1 = (char const *)&colmatch_palette[i*3];
int dist = gdist[pal1[1]+g]; int dist = gdist[pal1[1]+g];

View file

@ -401,7 +401,7 @@ void palettePostLoadTables(void)
continue; continue;
palette_t *edcol = (palette_t *) &vgapal16[4*i]; palette_t *edcol = (palette_t *) &vgapal16[4*i];
editorcolors[i] = paletteGetClosestColorUpToIndex(edcol->b, edcol->g, edcol->r, 239); editorcolors[i] = paletteGetClosestColorWithBlacklist(edcol->b, edcol->g, edcol->r, 254, PaletteIndexFullbrights);
} }
} }