- backend sync with Raze

Mostly code reformatting plus license and copyright adjustments
This commit is contained in:
Christoph Oelckers 2020-05-26 22:59:50 +02:00
commit c892fb1ddb
18 changed files with 126 additions and 98 deletions

View file

@ -76,7 +76,7 @@ FTexture::FTexture (int lumpnum)
//
//===========================================================================
FBitmap FTexture::GetBgraBitmap(const PalEntry *remap, int *ptrans)
FBitmap FTexture::GetBgraBitmap(const PalEntry* remap, int* ptrans)
{
FBitmap bmp;
bmp.Create(Width, Height);
@ -116,9 +116,9 @@ int FTexture::CheckRealHeight()
//
//===========================================================================
bool FTexture::FindHoles(const unsigned char * buffer, int w, int h)
bool FTexture::FindHoles(const unsigned char* buffer, int w, int h)
{
const unsigned char * li;
const unsigned char* li;
int y, x;
int startdraw, lendraw;
int gaps[5][2];
@ -134,11 +134,11 @@ bool FTexture::FindHoles(const unsigned char * buffer, int w, int h)
startdraw = -1;
lendraw = 0;
for (y = 0; y<h; y++)
for (y = 0; y < h; y++)
{
li = buffer + w * y * 4 + 3;
for (x = 0; x<w; x++, li += 4)
for (x = 0; x < w; x++, li += 4)
{
if (*li != 0) break;
}
@ -204,15 +204,15 @@ bool FTexture::FindHoles(const unsigned char * buffer, int w, int h)
//
//----------------------------------------------------------------------------
void FTexture::CheckTrans(unsigned char * buffer, int size, int trans)
void FTexture::CheckTrans(unsigned char* buffer, int size, int trans)
{
if (bTranslucent == -1)
{
bTranslucent = trans;
if (trans == -1)
{
uint32_t * dwbuf = (uint32_t*)buffer;
for (int i = 0; i<size; i++)
uint32_t* dwbuf = (uint32_t*)buffer;
for (int i = 0; i < size; i++)
{
uint32_t alpha = dwbuf[i] >> 24;
@ -244,13 +244,13 @@ void FTexture::CheckTrans(unsigned char * buffer, int size, int trans)
#define CHKPIX(ofs) (l1[(ofs)*4+MSB]==255 ? (( ((uint32_t*)l1)[0] = ((uint32_t*)l1)[ofs]&SOME_MASK), trans=true ) : false)
bool FTexture::SmoothEdges(unsigned char * buffer, int w, int h)
bool FTexture::SmoothEdges(unsigned char* buffer, int w, int h)
{
int x, y;
bool trans = buffer[MSB] == 0; // If I set this to false here the code won't detect textures
// that only contain transparent pixels.
bool semitrans = false;
unsigned char * l1;
unsigned char* l1;
if (h <= 1 || w <= 1) return false; // makes (a) no sense and (b) doesn't work with this code!
@ -258,42 +258,42 @@ bool FTexture::SmoothEdges(unsigned char * buffer, int w, int h)
if (l1[MSB] == 0 && !CHKPIX(1)) CHKPIX(w);
else if (l1[MSB]<255) semitrans = true;
else if (l1[MSB] < 255) semitrans = true;
l1 += 4;
for (x = 1; x<w - 1; x++, l1 += 4)
for (x = 1; x < w - 1; x++, l1 += 4)
{
if (l1[MSB] == 0 && !CHKPIX(-1) && !CHKPIX(1)) CHKPIX(w);
else if (l1[MSB]<255) semitrans = true;
else if (l1[MSB] < 255) semitrans = true;
}
if (l1[MSB] == 0 && !CHKPIX(-1)) CHKPIX(w);
else if (l1[MSB]<255) semitrans = true;
else if (l1[MSB] < 255) semitrans = true;
l1 += 4;
for (y = 1; y<h - 1; y++)
for (y = 1; y < h - 1; y++)
{
if (l1[MSB] == 0 && !CHKPIX(-w) && !CHKPIX(1)) CHKPIX(w);
else if (l1[MSB]<255) semitrans = true;
else if (l1[MSB] < 255) semitrans = true;
l1 += 4;
for (x = 1; x<w - 1; x++, l1 += 4)
for (x = 1; x < w - 1; x++, l1 += 4)
{
if (l1[MSB] == 0 && !CHKPIX(-w) && !CHKPIX(-1) && !CHKPIX(1) && !CHKPIX(-w - 1) && !CHKPIX(-w + 1) && !CHKPIX(w - 1) && !CHKPIX(w + 1)) CHKPIX(w);
else if (l1[MSB]<255) semitrans = true;
else if (l1[MSB] < 255) semitrans = true;
}
if (l1[MSB] == 0 && !CHKPIX(-w) && !CHKPIX(-1)) CHKPIX(w);
else if (l1[MSB]<255) semitrans = true;
else if (l1[MSB] < 255) semitrans = true;
l1 += 4;
}
if (l1[MSB] == 0 && !CHKPIX(-w)) CHKPIX(1);
else if (l1[MSB]<255) semitrans = true;
else if (l1[MSB] < 255) semitrans = true;
l1 += 4;
for (x = 1; x<w - 1; x++, l1 += 4)
for (x = 1; x < w - 1; x++, l1 += 4)
{
if (l1[MSB] == 0 && !CHKPIX(-w) && !CHKPIX(-1)) CHKPIX(1);
else if (l1[MSB]<255) semitrans = true;
else if (l1[MSB] < 255) semitrans = true;
}
if (l1[MSB] == 0 && !CHKPIX(-w)) CHKPIX(-1);
else if (l1[MSB]<255) semitrans = true;
else if (l1[MSB] < 255) semitrans = true;
return trans || semitrans;
}
@ -304,7 +304,7 @@ bool FTexture::SmoothEdges(unsigned char * buffer, int w, int h)
//
//===========================================================================
bool FTexture::ProcessData(unsigned char * buffer, int w, int h, bool ispatch)
bool FTexture::ProcessData(unsigned char* buffer, int w, int h, bool ispatch)
{
if (Masked)
{
@ -324,7 +324,7 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
{
FTextureBuffer result;
unsigned char * buffer = nullptr;
unsigned char* buffer = nullptr;
int W, H;
int isTransparent = -1;
bool checkonly = !!(flags & CTF_CheckOnly);
@ -336,7 +336,7 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
if (!checkonly)
{
buffer = new unsigned char[W*(H + 1) * 4];
buffer = new unsigned char[W * (H + 1) * 4];
memset(buffer, 0, W * (H + 1) * 4);
auto remap = translation <= 0 ? nullptr : GPalette.TranslationToTable(translation);
@ -344,12 +344,12 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
FBitmap bmp(buffer, W * 4, W, H);
int trans;
auto Pixels = GetBgraBitmap(remap? remap->Palette : nullptr, &trans);
auto Pixels = GetBgraBitmap(remap ? remap->Palette : nullptr, &trans);
bmp.Blit(exx, exx, Pixels);
if (remap == nullptr)
{
CheckTrans(buffer, W*H, trans);
CheckTrans(buffer, W * H, trans);
isTransparent = bTranslucent;
}
else
@ -375,9 +375,10 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
result.mHeight = H;
// Only do postprocessing for image-backed textures. (i.e. not for the burn texture which can also pass through here.)
if (GetImage() && flags & CTF_ProcessData)
if (GetImage() && flags & CTF_ProcessData)
{
if (flags & CTF_Upscale) CreateUpsampledTextureBuffer(result, !!isTransparent, checkonly);
if (!checkonly) ProcessData(result.mBuffer, result.mWidth, result.mHeight, false);
}
@ -392,8 +393,8 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
bool FTexture::DetermineTranslucency()
{
// This will calculate all we need, so just discard the result.
CreateTexBuffer(0);
// This will calculate all we need, so just discard the result.
CreateTexBuffer(0);
return !!bTranslucent;
}
@ -512,10 +513,10 @@ IHardwareTexture* FTexture::GetHardwareTexture(int translation, int scaleflags)
{
IHardwareTexture* hwtex = SystemTextures.GetHardwareTexture(translation, scaleflags);
if (hwtex == nullptr)
{
{
hwtex = CreateHardwareTexture();
SystemTextures.AddHardwareTexture(translation, scaleflags, hwtex);
}
}
return hwtex;
}
return nullptr;
@ -539,4 +540,3 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits)
SystemTextures.AddHardwareTexture(0, false, hwtex);
}