Merge remote-tracking branch 'origin/capsky' into qzdoom

This commit is contained in:
Magnus Norddahl 2016-10-20 00:13:58 +02:00
commit 0888fc0cde
5 changed files with 174 additions and 104 deletions

View file

@ -841,6 +841,78 @@ void FTexture::SetScaledSize(int fitwidth, int fitheight)
if (int(Scale.Y * fitheight) != Height) Scale.Y += (1 / 65536.);
}
//===========================================================================
//
// Gets the average color of a texture for use as a sky cap color
//
//===========================================================================
namespace
{
PalEntry averageColor(const DWORD *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);
}
}
PalEntry FTexture::GetSWSkyCapColor(bool bottom)
{
PalEntry col;
int w;
int h;
if (!bSWSkyColorDone)
{
bSWSkyColorDone = true;
FBitmap bitmap;
bitmap.Create(GetWidth(), GetHeight());
CopyTrueColorPixels(&bitmap, 0, 0);
int w = GetWidth();
int h = GetHeight();
const uint32_t *buffer = (const uint32_t *)bitmap.GetPixels();
if (buffer)
{
SWCeilingSkyColor = averageColor((DWORD *)buffer, w * MIN(30, h), 0);
if (h>30)
{
SWFloorSkyColor = averageColor(((DWORD *)buffer) + (h - 30)*w, w * 30, 0);
}
else SWFloorSkyColor = SWCeilingSkyColor;
}
}
return bottom ? SWFloorSkyColor : SWCeilingSkyColor;
}
FDummyTexture::FDummyTexture ()
{