Changed: Implement and use CBitmap::makeTransparentPixelsBlack()

This commit is contained in:
kervala 2016-10-22 16:47:25 +02:00
parent 3b00a6a2e0
commit d31bfa9606
3 changed files with 54 additions and 0 deletions

View file

@ -375,6 +375,12 @@ public:
void makeOpaque(); void makeOpaque();
/**
* Make fully transparent pixels (alpha 0) black.
*/
void makeTransparentPixelsBlack();
/** /**
* Return if the bitmap has uniform alpha values for all pixels. * Return if the bitmap has uniform alpha values for all pixels.
* \param alpha return the uniform value if return is true * \param alpha return the uniform value if return is true

View file

@ -369,6 +369,51 @@ void CBitmap::makeOpaque()
} }
/*-------------------------------------------------------------------*\
makeTransparentPixelsBlack
\*-------------------------------------------------------------------*/
void CBitmap::makeTransparentPixelsBlack()
{
if (_Width*_Height == 0) return;
uint pixelSize;
switch (PixelFormat)
{
case RGBA: pixelSize = 4; break;
case AlphaLuminance: pixelSize = 2; break;
default: return;
}
uint colorsSize = pixelSize - 1;
for (uint8 m = 0; m < _MipMapCount; ++m)
{
// get a pointer on original data
uint8 *data = _Data[m].getPtr();
// end of data
uint8 *endData = data + _Data[m].size();
// first alpha
data += pixelSize - 1;
// replace all alpha values by 255
while (data < endData)
{
// fully transparent pixel
if (*data == 0)
{
// make colors black
memset(data - colorsSize, 0, colorsSize);
}
data += pixelSize;
}
}
}
/*-------------------------------------------------------------------*\ /*-------------------------------------------------------------------*\
isAlphaUniform isAlphaUniform
\*-------------------------------------------------------------------*/ \*-------------------------------------------------------------------*/

View file

@ -350,6 +350,9 @@ int main(int argc, char **argv)
UVMax[i].V = UVMax[i].V / (float)GlobalTexture.getHeight(); UVMax[i].V = UVMax[i].V / (float)GlobalTexture.getHeight();
} }
// make sure transparent pixels are black
GlobalTexture.makeTransparentPixelsBlack();
// Write global texture file // Write global texture file
if (writeFileDependingOnFilename(fmtName, GlobalTexture)) if (writeFileDependingOnFilename(fmtName, GlobalTexture))
{ {