Rename colmatch functions

git-svn-id: https://svn.eduke32.com/eduke32@8488 1a8010ca-5511-0410-912e-c29ae57300e0

# Conflicts:
#	source/build/include/colmatch.h
#	source/build/src/build.cpp
#	source/build/src/defs.cpp
#	source/build/src/palette.cpp
#	source/duke3d/src/lunatic/dynsymlist_editor.lds
#	source/duke3d/src/lunatic/dynsymlist_game.lds
#	source/duke3d/src/lunatic/engine.lua
#	source/tools/src/transpal.cpp
This commit is contained in:
hendricks266 2019-12-23 07:03:42 +00:00 committed by Christoph Oelckers
parent 7db49ea20a
commit 0a7f5f558a
5 changed files with 38 additions and 38 deletions

View file

@ -1,15 +1,15 @@
#include "compat.h" #include "compat.h"
extern void initfastcolorlookup_scale(int32_t rscale, int32_t gscale, int32_t bscale); extern void paletteInitClosestColorScale(int32_t rscale, int32_t gscale, int32_t bscale);
extern void initfastcolorlookup_palette(uint8_t const * pal) ATTRIBUTE((nonnull(1))); extern void paletteInitClosestColorMap(uint8_t const * pal) ATTRIBUTE((nonnull(1)));
extern void initfastcolorlookup_gridvectors(void); extern void paletteInitClosestColorGrid(void);
extern int32_t getclosestcol_lim(int32_t r, int32_t g, int32_t b, int32_t lastokcol); extern int32_t paletteGetClosestColorUpToIndex(int32_t r, int32_t g, int32_t b, int32_t lastokcol);
extern int32_t getclosestcol_nocache_lim(int32_t r, int32_t g, int32_t b, int32_t lastokcol); extern int32_t paletteGetClosestColorUpToIndexNoCache(int32_t r, int32_t g, int32_t b, int32_t lastokcol);
extern void getclosestcol_flush(void); extern void paletteFlushClosestColor(void);
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 getclosestcol_lim(r, g, b, 255); return paletteGetClosestColorUpToIndex(r, g, b, 255);
} }

View file

@ -19,9 +19,9 @@ static uint8_t const * colmatch_palette;
#define pow2char(x) (1u << (x)) #define pow2char(x) (1u << (x))
// //
// initfastcolorlookup // paletteInitClosestColor
// //
void initfastcolorlookup_scale(int32_t rscale, int32_t gscale, int32_t bscale) void paletteInitClosestColorScale(int32_t rscale, int32_t gscale, int32_t bscale)
{ {
int32_t j = 0; int32_t j = 0;
for (bssize_t i=256; i>=0; i--) for (bssize_t i=256; i>=0; i--)
@ -33,7 +33,7 @@ void initfastcolorlookup_scale(int32_t rscale, int32_t gscale, int32_t bscale)
j += FASTPALRGBDIST-(i<<1); j += FASTPALRGBDIST-(i<<1);
} }
} }
void initfastcolorlookup_palette(uint8_t const * const pal) void paletteInitClosestColorMap(uint8_t const * const pal)
{ {
Bmemset(colhere,0,sizeof(colhere)); Bmemset(colhere,0,sizeof(colhere));
Bmemset(colhead,0,sizeof(colhead)); Bmemset(colhead,0,sizeof(colhead));
@ -51,9 +51,9 @@ void initfastcolorlookup_palette(uint8_t const * const pal)
colhere[j>>3] |= pow2char(j&7); colhere[j>>3] |= pow2char(j&7);
} }
getclosestcol_flush(); paletteFlushClosestColor();
} }
void initfastcolorlookup_gridvectors(void) void paletteInitClosestColorGrid(void)
{ {
int i = 0; int i = 0;
int32_t x, y, z; int32_t x, y, z;
@ -71,18 +71,18 @@ void initfastcolorlookup_gridvectors(void)
#define COLRESULTSIZ 4096 #define COLRESULTSIZ 4096
static uint32_t getclosestcol_results[COLRESULTSIZ]; static uint32_t colmatchresults[COLRESULTSIZ];
static int32_t numclosestcolresults; static int32_t numcolmatchresults;
void getclosestcol_flush(void) void paletteFlushClosestColor(void)
{ {
Bmemset(getclosestcol_results, 0, COLRESULTSIZ * sizeof(uint32_t)); Bmemset(colmatchresults, 0, COLRESULTSIZ * sizeof(uint32_t));
numclosestcolresults = 0; numcolmatchresults = 0;
} }
// 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 getclosestcol_lim(int32_t const r, int32_t const g, int32_t const b, int32_t const lastokcol) int32_t paletteGetClosestColorUpToIndex(int32_t const r, int32_t const g, int32_t const b, int32_t const lastokcol)
{ {
#ifdef DEBUGGINGAIDS #ifdef DEBUGGINGAIDS
Bassert(lastokcol >= 0 && lastokcol <= 255); Bassert(lastokcol >= 0 && lastokcol <= 255);
@ -92,37 +92,37 @@ int32_t getclosestcol_lim(int32_t const r, int32_t const g, int32_t const b, int
int mindist = -1; int mindist = -1;
int const k = (numclosestcolresults > COLRESULTSIZ) ? COLRESULTSIZ : numclosestcolresults; int const k = (numcolmatchresults > COLRESULTSIZ) ? COLRESULTSIZ : numcolmatchresults;
if (!numclosestcolresults) goto skip; if (!numcolmatchresults) goto skip;
if (col == (getclosestcol_results[(numclosestcolresults-1) & (COLRESULTSIZ-1)] & 0x00ffffff)) if (col == (colmatchresults[(numcolmatchresults-1) & (COLRESULTSIZ-1)] & 0x00ffffff))
return getclosestcol_results[(numclosestcolresults-1) & (COLRESULTSIZ-1)]>>24; return colmatchresults[(numcolmatchresults-1) & (COLRESULTSIZ-1)]>>24;
int i; int i;
for (i = 0; i <= k-4; i+=4) for (i = 0; i <= k-4; i+=4)
{ {
if (col == (getclosestcol_results[i] & 0x00ffffff)) { mindist = i; break; } if (col == (colmatchresults[i] & 0x00ffffff)) { mindist = i; break; }
if (col == (getclosestcol_results[i+1] & 0x00ffffff)) { mindist = i+1; break; } if (col == (colmatchresults[i+1] & 0x00ffffff)) { mindist = i+1; break; }
if (col == (getclosestcol_results[i+2] & 0x00ffffff)) { mindist = i+2; break; } if (col == (colmatchresults[i+2] & 0x00ffffff)) { mindist = i+2; break; }
if (col == (getclosestcol_results[i+3] & 0x00ffffff)) { mindist = i+3; break; } if (col == (colmatchresults[i+3] & 0x00ffffff)) { mindist = i+3; break; }
} }
if (mindist == -1) if (mindist == -1)
for (; i < k; i++) for (; i < k; i++)
if (col == (getclosestcol_results[i] & 0x00ffffff)) { mindist = i; break; } if (col == (colmatchresults[i] & 0x00ffffff)) { mindist = i; break; }
if (mindist != -1 && getclosestcol_results[mindist]>>24 < (unsigned)lastokcol) if (mindist != -1 && colmatchresults[mindist]>>24 < (unsigned)lastokcol)
return getclosestcol_results[mindist]>>24; return colmatchresults[mindist]>>24;
skip: skip:
i = getclosestcol_nocache_lim(r, g, b, lastokcol); i = paletteGetClosestColorUpToIndexNoCache(r, g, b, lastokcol);
getclosestcol_results[numclosestcolresults++ & (COLRESULTSIZ-1)] = col | (i << 24); colmatchresults[numcolmatchresults++ & (COLRESULTSIZ-1)] = col | (i << 24);
return i; return i;
} }
int32_t getclosestcol_nocache_lim(int32_t r, int32_t g, int32_t b, int32_t const lastokcol) int32_t paletteGetClosestColorUpToIndexNoCache(int32_t r, int32_t g, int32_t b, int32_t const lastokcol)
{ {
#ifdef DEBUGGINGAIDS #ifdef DEBUGGINGAIDS
Bassert(lastokcol >= 0 && lastokcol <= 255); Bassert(lastokcol >= 0 && lastokcol <= 255);

View file

@ -2713,7 +2713,7 @@ static int32_t defsparser(scriptfile *script)
if (didLoadPal && id == 0) if (didLoadPal && id == 0)
{ {
initfastcolorlookup_palette(palette); paletteInitClosestColorMap(palette);
paletteloaded |= PALETTE_MAIN; paletteloaded |= PALETTE_MAIN;
} }

View file

@ -164,8 +164,8 @@ inline bool read_and_test(FileReader& handle, void* buffer, int32_t leng)
// //
void paletteLoadFromDisk(void) void paletteLoadFromDisk(void)
{ {
initfastcolorlookup_scale(30, 59, 11); paletteInitClosestColorScale(30, 59, 11);
initfastcolorlookup_gridvectors(); paletteInitClosestColorGrid();
#ifdef USE_OPENGL #ifdef USE_OPENGL
for (auto & x : glblend) for (auto & x : glblend)
@ -191,7 +191,7 @@ void paletteLoadFromDisk(void)
for (unsigned char & k : palette) for (unsigned char & k : palette)
k <<= 2; k <<= 2;
initfastcolorlookup_palette(palette); paletteInitClosestColorMap(palette);
paletteloaded |= PALETTE_MAIN; paletteloaded |= PALETTE_MAIN;
@ -361,7 +361,7 @@ void palettePostLoadTables(void)
for (size_t i = 0; i<16; i++) for (size_t i = 0; i<16; i++)
{ {
palette_t *edcol = (palette_t *) &vgapal16[4*i]; palette_t *edcol = (palette_t *) &vgapal16[4*i];
editorcolors[i] = getclosestcol_lim(edcol->b, edcol->g, edcol->r, playing_blood ? 254 : 239); editorcolors[i] = paletteGetClosestColorUpToIndex(edcol->b, edcol->g, edcol->r, playing_blood ? 254 : 239);
} }
// Bmemset(PaletteIndexFullbrights, 0, sizeof(PaletteIndexFullbrights)); // Bmemset(PaletteIndexFullbrights, 0, sizeof(PaletteIndexFullbrights));

View file

@ -5829,7 +5829,7 @@ badindex:
{ {
tw = *insptr++; tw = *insptr++;
int32_t const rgb = Gv_GetVar(*insptr++); int32_t const rgb = Gv_GetVar(*insptr++);
Gv_SetVar(tw, getclosestcol_lim(rgb & 0xFF, (rgb >> 8) & 0xFF, (rgb >> 16) & 0xFF, Gv_GetVar(*insptr++))); Gv_SetVar(tw, paletteGetClosestColorUpToIndex(rgb & 0xFF, (rgb >> 8) & 0xFF, (rgb >> 16) & 0xFF, Gv_GetVar(*insptr++)));
} }
dispatch(); dispatch();