From 7d4833b37ee1888e64579143d76e1df015fc6f55 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 22 Oct 2016 16:47:25 +0200 Subject: [PATCH] Changed: Implement and use CBitmap::makeTransparentPixelsBlack() --- code/nel/include/nel/misc/bitmap.h | 6 +++ code/nel/src/misc/bitmap.cpp | 45 ++++++++++++++++++++++ code/nel/tools/3d/build_interface/main.cpp | 3 ++ 3 files changed, 54 insertions(+) diff --git a/code/nel/include/nel/misc/bitmap.h b/code/nel/include/nel/misc/bitmap.h index 0466cd673..b7e5462a0 100644 --- a/code/nel/include/nel/misc/bitmap.h +++ b/code/nel/include/nel/misc/bitmap.h @@ -375,6 +375,12 @@ public: void makeOpaque(); + /** + * Make fully transparent pixels (alpha 0) black. + */ + void makeTransparentPixelsBlack(); + + /** * Return if the bitmap has uniform alpha values for all pixels. * \param alpha return the uniform value if return is true diff --git a/code/nel/src/misc/bitmap.cpp b/code/nel/src/misc/bitmap.cpp index 3f22dc752..a996c8546 100644 --- a/code/nel/src/misc/bitmap.cpp +++ b/code/nel/src/misc/bitmap.cpp @@ -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 \*-------------------------------------------------------------------*/ diff --git a/code/nel/tools/3d/build_interface/main.cpp b/code/nel/tools/3d/build_interface/main.cpp index c56934662..266cd410b 100644 --- a/code/nel/tools/3d/build_interface/main.cpp +++ b/code/nel/tools/3d/build_interface/main.cpp @@ -350,6 +350,9 @@ int main(int argc, char **argv) UVMax[i].V = UVMax[i].V / (float)GlobalTexture.getHeight(); } + // make sure transparent pixels are black + GlobalTexture.makeTransparentPixelsBlack(); + // Write global texture file if (writeFileDependingOnFilename(fmtName, GlobalTexture)) {