From fc90365c1804fcd4f7c2d02a67a903b28a1ce4f9 Mon Sep 17 00:00:00 2001 From: kervala Date: Sun, 3 Jan 2016 18:14:46 +0100 Subject: [PATCH] Changed: Convert masks to 8 bits grayscale instead of using only Red component of RGBA bitmaps --- .../tools/3d/panoply_maker/color_modifier.cpp | 8 ++--- .../panoply_maker/hls_bank_texture_info.cpp | 11 +++--- .../tools/3d/panoply_maker/panoply_maker.cpp | 35 +++++++++++++++++-- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/code/nel/tools/3d/panoply_maker/color_modifier.cpp b/code/nel/tools/3d/panoply_maker/color_modifier.cpp index a55936b7c..b34e021ed 100644 --- a/code/nel/tools/3d/panoply_maker/color_modifier.cpp +++ b/code/nel/tools/3d/panoply_maker/color_modifier.cpp @@ -46,7 +46,7 @@ void CColorModifier::convertBitmap(NLMISC::CBitmap &destBitmap, const NLMISC::CB const NLMISC::CRGBA *src = (NLMISC::CRGBA *) &srcBitmap.getPixels()[0]; - const NLMISC::CRGBA *mask = (NLMISC::CRGBA *) &maskBitmap.getPixels()[0]; + const uint8 *mask = &maskBitmap.getPixels()[0]; NLMISC::CRGBA *dest = (NLMISC::CRGBA *) &destBitmap.getPixels()[0]; @@ -69,7 +69,7 @@ void CColorModifier::convertBitmap(NLMISC::CBitmap &destBitmap, const NLMISC::CB result.B = CalcBrightnessContrast(result.B, Luminosity, Contrast, grey); // blend to the destination by using the mask alpha - result.blendFromui(*dest, result, mask->R); + result.blendFromui(*dest, result, *mask); /// keep alpha from the source dest->R = result.R; @@ -111,7 +111,7 @@ void CColorModifier::evalBitmapStats(const NLMISC::CBitmap &srcBitmap, float gTotal = 0; const NLMISC::CRGBA *src = (NLMISC::CRGBA *) &srcBitmap.getPixels()[0]; - const NLMISC::CRGBA *mask = (NLMISC::CRGBA *) &maskBitmap.getPixels()[0]; + const uint8 *mask = &maskBitmap.getPixels()[0]; for (uint y = 0; y < srcBitmap.getHeight(); ++y) { @@ -119,7 +119,7 @@ void CColorModifier::evalBitmapStats(const NLMISC::CBitmap &srcBitmap, { float h, l, s; - float intensity = mask->R * (1.f / 255.f); + float intensity = *mask * (1.f / 255.f); bool achromatic = src->convertToHLS(h, l, s); float grey = 0.299f * src->R + 0.587f * src->G + 0.114f * src->B; diff --git a/code/nel/tools/3d/panoply_maker/hls_bank_texture_info.cpp b/code/nel/tools/3d/panoply_maker/hls_bank_texture_info.cpp index 2fc50d28f..4e6a1693a 100644 --- a/code/nel/tools/3d/panoply_maker/hls_bank_texture_info.cpp +++ b/code/nel/tools/3d/panoply_maker/hls_bank_texture_info.cpp @@ -43,18 +43,15 @@ void CHLSBankTextureInfo::serial(NLMISC::IStream &f) // *************************************************************************** void CHLSBankTextureInfo::CMaskBitmap::build(const NLMISC::CBitmap &src) { - nlassert(src.getPixelFormat()==CBitmap::RGBA); + nlassert(src.getPixelFormat()==CBitmap::Luminance); Width= src.getWidth(); Height= src.getHeight(); Pixels.resize(Width*Height); if(!Pixels.empty()) { - CRGBA *pSrc= (CRGBA*)(&src.getPixels()[0]); - uint8 *pDst= &Pixels[0]; - for(uint i=0; i 0 && maskDepth > 8) { + if (!li.Mask.isGrayscale()) + { + nlwarning("Mask %s is using colors, results may by incorrect! Use OptimizeTextures = 2 to fix it.", maskFileName.c_str()); + } + if (bi.OptimizeTextures > 1) { + // get a pointer on original data + uint32 size = li.Mask.getPixels().size(); + uint32 *data = (uint32*)li.Mask.getPixels().getPtr(); + uint32 *endData = (uint32*)((uint8*)data + size); + + NLMISC::CRGBA *color = NULL; + + // process all pixels + while(data < endData) + { + color = (NLMISC::CRGBA*)data; + + // copy red value to green and blue, + // because only red is used for mask + color->B = color->G = color->R; + + // make opaque + color->A = 255; + + ++data; + } + + // convert image to real grayscale + li.Mask.convertToType(NLMISC::CBitmap::Luminance); + NLMISC::COFile os; if (os.open(maskFileName)) @@ -826,9 +856,9 @@ static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::str } } - if (li.Mask.PixelFormat != NLMISC::CBitmap::RGBA) + if (li.Mask.PixelFormat != NLMISC::CBitmap::Luminance) { - li.Mask.convertToType(NLMISC::CBitmap::RGBA); + li.Mask.convertToType(NLMISC::CBitmap::Luminance); } /// make sure the mask has the same size @@ -969,5 +999,4 @@ static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::str { nlerror("Couldn't write %s", fullHlsInfoPath.c_str()); } - }