mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-11 07:11:54 +00:00
Changes the tonemap generation algorithm.
This commit is contained in:
parent
7e2e3e8768
commit
5a64307ad1
2 changed files with 40 additions and 1 deletions
|
@ -257,7 +257,7 @@ void FGLRenderer::BindTonemapPalette(int texunit)
|
||||||
{
|
{
|
||||||
for (int b = 0; b < 64; b++)
|
for (int b = 0; b < 64; b++)
|
||||||
{
|
{
|
||||||
PalEntry color = GPalette.BaseColors[ColorMatcher.Pick((r << 2) | (r >> 4), (g << 2) | (g >> 4), (b << 2) | (b >> 4))];
|
PalEntry color = GPalette.BaseColors[(BYTE)PTM_BestColor((uint32 *)GPalette.BaseColors, (r << 2) | (r >> 4), (g << 2) | (g >> 4), (b << 2) | (b >> 4), 0, 256)];
|
||||||
int index = ((r * 64 + g) * 64 + b) * 4;
|
int index = ((r * 64 + g) * 64 + b) * 4;
|
||||||
lut[index] = color.r;
|
lut[index] = color.r;
|
||||||
lut[index + 1] = color.g;
|
lut[index + 1] = color.g;
|
||||||
|
@ -472,3 +472,40 @@ void FGLRenderer::ClearBorders()
|
||||||
}
|
}
|
||||||
glDisable(GL_SCISSOR_TEST);
|
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 *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;
|
||||||
|
|
||||||
|
double fbestdist, fdist;
|
||||||
|
int bestcolor;
|
||||||
|
|
||||||
|
if (firstTime)
|
||||||
|
{
|
||||||
|
firstTime = false;
|
||||||
|
for (int x = 0; x < 256; x++) powtable[x] = pow((double)x/255,1.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 || fdist < fbestdist)
|
||||||
|
{
|
||||||
|
if (fdist == 0)
|
||||||
|
return color;
|
||||||
|
|
||||||
|
fbestdist = fdist;
|
||||||
|
bestcolor = color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bestcolor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -189,6 +189,8 @@ public:
|
||||||
void FillSimplePoly(FTexture *texture, FVector2 *points, int npoints,
|
void FillSimplePoly(FTexture *texture, FVector2 *points, int npoints,
|
||||||
double originx, double originy, double scalex, double scaley,
|
double originx, double originy, double scalex, double scaley,
|
||||||
DAngle rotation, FDynamicColormap *colormap, int lightlevel);
|
DAngle rotation, FDynamicColormap *colormap, int lightlevel);
|
||||||
|
|
||||||
|
int PTM_BestColor (const uint32 *pal_in, int r, int g, int b, int first, int num);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Global functions. Make them members of GLRenderer later?
|
// Global functions. Make them members of GLRenderer later?
|
||||||
|
|
Loading…
Reference in a new issue