mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-12-29 03:40:55 +00:00
Changed: Implement and use CBitmap::makeTransparentPixelsBlack()
This commit is contained in:
parent
673ba8cfa3
commit
7d4833b37e
3 changed files with 54 additions and 0 deletions
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
\*-------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------*/
|
||||||
|
|
|
@ -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))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue