From 6f69256c483c318b4917e403b74c96eff0f2383d Mon Sep 17 00:00:00 2001 From: kervala Date: Mon, 4 Jan 2016 13:58:54 +0100 Subject: [PATCH] Fixed: If mask is using colors, convert it to grayscale using Red value (compatible with previous algorithm) --- .../tools/3d/panoply_maker/panoply_maker.cpp | 69 ++++++++++--------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/code/nel/tools/3d/panoply_maker/panoply_maker.cpp b/code/nel/tools/3d/panoply_maker/panoply_maker.cpp index 70e3b979e..dc0ace2a3 100644 --- a/code/nel/tools/3d/panoply_maker/panoply_maker.cpp +++ b/code/nel/tools/3d/panoply_maker/panoply_maker.cpp @@ -791,41 +791,49 @@ static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::str throw NLMISC::Exception("Failed to load mask"); } - // masks can be converted to grayscale files - if (bi.OptimizeTextures > 0 && maskDepth > 8) + // convert color mask to grayscale (red is the new gray value) + if (li.Mask.getPixelFormat() == CBitmap::RGBA) { - if (!li.Mask.isGrayscale()) + // display a warning if checks enabled + if (bi.OptimizeTextures > 0 && !li.Mask.isGrayscale()) { nlwarning("Mask %s is using colors, results may by incorrect! Use OptimizeTextures = 2 to fix it.", maskFileName.c_str()); } + // 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 + if (li.Mask.PixelFormat != NLMISC::CBitmap::Luminance) + { + li.Mask.convertToType(NLMISC::CBitmap::Luminance); + } + + // masks can be converted to grayscale files + if (bi.OptimizeTextures > 0 && maskDepth > 8) + { 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)) @@ -855,11 +863,6 @@ static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::str } } - if (li.Mask.PixelFormat != NLMISC::CBitmap::Luminance) - { - li.Mask.convertToType(NLMISC::CBitmap::Luminance); - } - /// make sure the mask has the same size if (li.Mask.getWidth() != srcBitmap.getWidth() || li.Mask.getHeight() != srcBitmap.getHeight())