From 5adb8364b6d7b01ccf8e0428df43354381230ac3 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Wed, 29 Nov 2017 07:29:30 +0000 Subject: [PATCH] Calculate the perceptual (i.e. "real") max shade in the given tables. git-svn-id: https://svn.eduke32.com/eduke32@6514 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/build/include/palette.h | 3 +++ source/build/src/palette.cpp | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/source/build/include/palette.h b/source/build/include/palette.h index 4e5454757..43c0c5217 100644 --- a/source/build/include/palette.h +++ b/source/build/include/palette.h @@ -38,6 +38,9 @@ typedef struct { extern palette_t curpalette[256], curpalettefaded[256], palfadergb; extern char palfadedelta; +extern int32_t realmaxshade; +extern float frealmaxshade; + extern int32_t globalblend; extern uint32_t g_lastpalettesum; extern palette_t getpal(int32_t col); diff --git a/source/build/src/palette.cpp b/source/build/src/palette.cpp index f6edc91cf..2a24cd16b 100644 --- a/source/build/src/palette.cpp +++ b/source/build/src/palette.cpp @@ -20,6 +20,9 @@ palette_t palfadergb = { 0, 0, 0, 0 }; char palfadedelta = 0; uint8_t blackcol; +int32_t realmaxshade; +float frealmaxshade; + #if defined(USE_OPENGL) palette_t palookupfog[MAXPALOOKUPS]; #endif @@ -310,6 +313,21 @@ void E_PostLoadPalette(void) PostLoad_NotFullbright: ; } + + uint8_t const * const blackcolor = &palette[blackcol*3]; + size_t s; + for (s = numshades < 2 ? 0 : numshades-2; s > 0; --s) + { + for (size_t c = s*256, c_end = c+255; c < c_end; ++c) // skipping transparent color + { + uint8_t const index = palookup0[c]; + uint8_t const * const color = &palette[index*3]; + if (!IsPaletteIndexFullbright(index) && memcmp(blackcolor, color, sizeof(rgb24_t))) + goto PostLoad_FoundShade; + } + } + PostLoad_FoundShade: ; + frealmaxshade = (float)(realmaxshade = s+1); } void E_ReplaceTransparentColorWithBlack(void)