mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-26 14:01:45 +00:00
- moved PTM_BestColor to v_palette.cpp and removed its dependencies on CVARs.
This commit is contained in:
parent
9350eee0c0
commit
9e6f3787c6
4 changed files with 45 additions and 41 deletions
|
@ -601,7 +601,8 @@ void FGLRenderer::CreateTonemapPalette()
|
|||
{
|
||||
for (int b = 0; b < 64; b++)
|
||||
{
|
||||
PalEntry color = GPalette.BaseColors[(uint8_t)PTM_BestColor((uint32_t *)GPalette.BaseColors, (r << 2) | (r >> 4), (g << 2) | (g >> 4), (b << 2) | (b >> 4), 0, 256)];
|
||||
PalEntry color = GPalette.BaseColors[(uint8_t)PTM_BestColor((uint32_t *)GPalette.BaseColors, (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.b;
|
||||
lut[index + 1] = color.g;
|
||||
|
@ -914,41 +915,3 @@ void FGLRenderer::ClearBorders()
|
|||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
|
||||
// [SP] Re-implemented BestColor for more precision rather than speed. This function is only ever called once until the game palette is changed.
|
||||
|
||||
int FGLRenderer::PTM_BestColor (const uint32_t *pal_in, int r, int g, int b, int first, int num)
|
||||
{
|
||||
const PalEntry *pal = (const PalEntry *)pal_in;
|
||||
static double powtable[256];
|
||||
static bool firstTime = true;
|
||||
static float trackpowtable = 0.;
|
||||
|
||||
double fbestdist = DBL_MAX, fdist;
|
||||
int bestcolor = 0;
|
||||
|
||||
if (firstTime || trackpowtable != gl_paltonemap_powtable)
|
||||
{
|
||||
trackpowtable = gl_paltonemap_powtable;
|
||||
firstTime = false;
|
||||
for (int x = 0; x < 256; x++) powtable[x] = pow((double)x/255, (double)gl_paltonemap_powtable);
|
||||
}
|
||||
|
||||
for (int color = first; color < num; color++)
|
||||
{
|
||||
double x = powtable[abs(r-pal[color].r)];
|
||||
double y = powtable[abs(g-pal[color].g)];
|
||||
double z = powtable[abs(b-pal[color].b)];
|
||||
fdist = x + y + z;
|
||||
if (color == first || ((gl_paltonemap_reverselookup)?(fdist <= fbestdist):(fdist < fbestdist)))
|
||||
{
|
||||
if (fdist == 0 && !gl_paltonemap_reverselookup)
|
||||
return color;
|
||||
|
||||
fbestdist = fdist;
|
||||
bestcolor = color;
|
||||
}
|
||||
}
|
||||
return bestcolor;
|
||||
}
|
||||
|
||||
|
|
|
@ -202,8 +202,6 @@ public:
|
|||
double originx, double originy, double scalex, double scaley,
|
||||
DAngle rotation, const FColormap &colormap, PalEntry flatcolor, int lightlevel, int bottomclip);
|
||||
|
||||
int PTM_BestColor (const uint32_t *pal_in, int r, int g, int b, int first, int num);
|
||||
|
||||
static float GetZNear() { return 5.f; }
|
||||
static float GetZFar() { return 65536.f; }
|
||||
};
|
||||
|
|
|
@ -121,6 +121,48 @@ int BestColor (const uint32_t *pal_in, int r, int g, int b, int first, int num)
|
|||
return bestcolor;
|
||||
}
|
||||
|
||||
|
||||
// [SP] Re-implemented BestColor for more precision rather than speed. This function is only ever called once until the game palette is changed.
|
||||
|
||||
int PTM_BestColor (const uint32_t *pal_in, int r, int g, int b, bool reverselookup, float powtable_val, int first, int num)
|
||||
{
|
||||
const PalEntry *pal = (const PalEntry *)pal_in;
|
||||
static double powtable[256];
|
||||
static bool firstTime = true;
|
||||
static float trackpowtable = 0.;
|
||||
|
||||
double fbestdist = DBL_MAX, fdist;
|
||||
int bestcolor = 0;
|
||||
|
||||
if (firstTime || trackpowtable != powtable_val)
|
||||
{
|
||||
auto pt = powtable_val;
|
||||
trackpowtable = pt;
|
||||
firstTime = false;
|
||||
for (int x = 0; x < 256; x++) powtable[x] = pow((double)x/255, (double)pt);
|
||||
}
|
||||
|
||||
for (int color = first; color < num; color++)
|
||||
{
|
||||
double x = powtable[abs(r-pal[color].r)];
|
||||
double y = powtable[abs(g-pal[color].g)];
|
||||
double z = powtable[abs(b-pal[color].b)];
|
||||
fdist = x + y + z;
|
||||
if (color == first || (reverselookup?(fdist <= fbestdist):(fdist < fbestdist)))
|
||||
{
|
||||
if (fdist == 0 && !reverselookup)
|
||||
return color;
|
||||
|
||||
fbestdist = fdist;
|
||||
bestcolor = color;
|
||||
}
|
||||
}
|
||||
return bestcolor;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
FPalette::FPalette ()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -71,6 +71,7 @@ extern FPalette GPalette;
|
|||
#define DIM_OVERLAY MAKEARGB(170,0,0,0)
|
||||
|
||||
int BestColor (const uint32_t *pal, int r, int g, int b, int first=1, int num=255);
|
||||
int PTM_BestColor (const uint32_t *pal_in, int r, int g, int b, bool reverselookup, float powtable, int first=1, int num=255);
|
||||
void DoBlending (const PalEntry *from, PalEntry *to, int count, int r, int g, int b, int a);
|
||||
|
||||
void ReadPalette(int lumpnum, uint8_t *buffer);
|
||||
|
|
Loading…
Reference in a new issue