From a0018555ee0c4eccc0792f4e709334a3b3a4c158 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Sat, 10 Oct 2015 06:57:32 +0000 Subject: [PATCH] Split the colormatching portion of getclosestcol_lim into getclosestcol_nocache_lim in case speed is desired when processing an image with mostly unique colors. git-svn-id: https://svn.eduke32.com/eduke32@5376 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/colmatch.h | 5 ++++ polymer/eduke32/build/src/colmatch.c | 33 ++++++++++++++---------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/polymer/eduke32/build/include/colmatch.h b/polymer/eduke32/build/include/colmatch.h index cf8ae0adc..fed501c90 100644 --- a/polymer/eduke32/build/include/colmatch.h +++ b/polymer/eduke32/build/include/colmatch.h @@ -10,12 +10,17 @@ extern void initfastcolorlookup_palette(uint8_t const * pal) ATTRIBUTE((nonnull( extern void initfastcolorlookup_gridvectors(void); extern int32_t getclosestcol_lim(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 void getclosestcol_flush(void); FORCE_INLINE int32_t getclosestcol(int32_t r, int32_t g, int32_t b) { return getclosestcol_lim(r, g, b, 255); } +FORCE_INLINE int32_t getclosestcol_nocache(int32_t r, int32_t g, int32_t b) +{ + return getclosestcol_nocache_lim(r, g, b, 255); +} #ifdef __cplusplus } diff --git a/polymer/eduke32/build/src/colmatch.c b/polymer/eduke32/build/src/colmatch.c index 222b70c5f..ca982b490 100644 --- a/polymer/eduke32/build/src/colmatch.c +++ b/polymer/eduke32/build/src/colmatch.c @@ -82,13 +82,8 @@ void getclosestcol_flush(void) // Finds a color index in [0 .. lastokcol] closest to (r, g, b). // must be in [0 .. 255]. -int32_t getclosestcol_lim(int32_t r, int32_t g, int32_t b, int32_t lastokcol) +int32_t getclosestcol_lim(int32_t const r, int32_t const g, int32_t const b, int32_t const lastokcol) { - const int j = (r>>FASTPALRIGHTSHIFT)*FASTPALGRIDSIZ*FASTPALGRIDSIZ - + (g>>FASTPALRIGHTSHIFT)*FASTPALGRIDSIZ + (b>>FASTPALRIGHTSHIFT) - + FASTPALGRIDSIZ*FASTPALGRIDSIZ - + FASTPALGRIDSIZ + 1; - #ifdef DEBUGGINGAIDS Bassert(lastokcol >= 0 && lastokcol <= 255); #endif @@ -122,13 +117,27 @@ int32_t getclosestcol_lim(int32_t r, int32_t g, int32_t b, int32_t lastokcol) return getclosestcol_results[mindist]>>24; skip: - getclosestcol_results[numclosestcolresults & (COLRESULTSIZ-1)] = col; + i = getclosestcol_nocache_lim(r, g, b, lastokcol); + getclosestcol_results[numclosestcolresults++ & (COLRESULTSIZ-1)] = col | (i << 24); + return i; +} + +int32_t getclosestcol_nocache_lim(int32_t r, int32_t g, int32_t b, int32_t const lastokcol) +{ +#ifdef DEBUGGINGAIDS + Bassert(lastokcol >= 0 && lastokcol <= 255); +#endif + + int const j = (r>>FASTPALRIGHTSHIFT)*FASTPALGRIDSIZ*FASTPALGRIDSIZ + + (g>>FASTPALRIGHTSHIFT)*FASTPALGRIDSIZ + (b>>FASTPALRIGHTSHIFT) + + FASTPALGRIDSIZ*FASTPALGRIDSIZ + + FASTPALGRIDSIZ + 1; int const minrdist = rdist[coldist[r&FASTPALCOLDISTMASK]+FASTPALCOLDEPTH]; int const mingdist = gdist[coldist[g&FASTPALCOLDISTMASK]+FASTPALCOLDEPTH]; int const minbdist = bdist[coldist[b&FASTPALCOLDISTMASK]+FASTPALCOLDEPTH]; - mindist = min(minrdist, mingdist); + int mindist = min(minrdist, mingdist); mindist = min(mindist, minbdist) + 1; r = FASTPALCOLDEPTH-r, g = FASTPALCOLDEPTH-g, b = FASTPALCOLDEPTH-b; @@ -137,7 +146,7 @@ skip: for (int k=26; k>=0; k--) { - i = colscan[k]+j; + int i = colscan[k]+j; if ((colhere[i>>3]&pow2char(i&7)) == 0) continue; @@ -160,14 +169,11 @@ skip: } if (retcol >= 0) - { - getclosestcol_results[numclosestcolresults++ & (COLRESULTSIZ-1)] |= retcol<<24; return retcol; - } mindist = INT32_MAX; - for (i = 0; i < lastokcol; ++i) + for (int i = 0; i < lastokcol; ++i) { char const * const pal1 = (char *)&colmatch_palette[i*3]; int dist = gdist[pal1[1]+g]; @@ -180,6 +186,5 @@ skip: retcol = i; } - getclosestcol_results[numclosestcolresults++ & (COLRESULTSIZ-1)] |= retcol<<24; return retcol; }