- consolidated the two averageColor instances.

This commit is contained in:
Christoph Oelckers 2017-06-07 22:42:19 +02:00
parent 55df3a91ec
commit 8b19ae98ea
3 changed files with 29 additions and 75 deletions

View file

@ -167,50 +167,6 @@ void gl_GenerateGlobalBrightmapFromColormap()
}
}
//===========================================================================
//
// averageColor
// input is RGBA8 pixel format.
// The resulting RGB color can be scaled uniformly so that the highest
// component becomes one.
//
//===========================================================================
static PalEntry averageColor(const uint32_t *data, int size, int maxout)
{
int i;
unsigned int r, g, b;
// First clear them.
r = g = b = 0;
if (size==0)
{
return PalEntry(255,255,255);
}
for(i = 0; i < size; i++)
{
r += BPART(data[i]);
g += GPART(data[i]);
b += RPART(data[i]);
}
r = r/size;
g = g/size;
b = b/size;
int maxv=MAX(MAX(r,g),b);
if(maxv && maxout)
{
r = Scale(r, maxout, maxv);
g = Scale(g, maxout, maxv);
b = Scale(b, maxout, maxv);
}
return PalEntry(255,r,g,b);
}
//==========================================================================
//

View file

@ -848,40 +848,37 @@ void FTexture::SetScaledSize(int fitwidth, int fitheight)
//
//===========================================================================
namespace
PalEntry FTexture::averageColor(const uint32_t *data, int size, int maxout)
{
PalEntry averageColor(const uint32_t *data, int size, int maxout)
int i;
unsigned int r, g, b;
// First clear them.
r = g = b = 0;
if (size == 0)
{
int i;
unsigned int r, g, b;
// First clear them.
r = g = b = 0;
if (size == 0)
{
return PalEntry(255, 255, 255);
}
for (i = 0; i < size; i++)
{
b += BPART(data[i]);
g += GPART(data[i]);
r += RPART(data[i]);
}
r = r / size;
g = g / size;
b = b / size;
int maxv = MAX(MAX(r, g), b);
if (maxv && maxout)
{
r = Scale(r, maxout, maxv);
g = Scale(g, maxout, maxv);
b = Scale(b, maxout, maxv);
}
return PalEntry(255, r, g, b);
return PalEntry(255, 255, 255);
}
for (i = 0; i < size; i++)
{
b += BPART(data[i]);
g += GPART(data[i]);
r += RPART(data[i]);
}
r = r / size;
g = g / size;
b = b / size;
int maxv = MAX(MAX(r, g), b);
if (maxv && maxout)
{
r = ::Scale(r, maxout, maxv);
g = ::Scale(g, maxout, maxv);
b = ::Scale(b, maxout, maxv);
}
return PalEntry(255, r, g, b);
}
PalEntry FTexture::GetSkyCapColor(bool bottom)

View file

@ -307,6 +307,7 @@ public:
void SetScaledSize(int fitwidth, int fitheight);
PalEntry GetSkyCapColor(bool bottom);
static PalEntry averageColor(const uint32_t *data, int size, int maxout);
virtual void HackHack (int newheight); // called by FMultipatchTexture to discover corrupt patches.