Changed: Convert masks to 8 bits grayscale instead of using only Red component of RGBA bitmaps
This commit is contained in:
parent
459d6b611b
commit
fc90365c18
3 changed files with 40 additions and 14 deletions
|
@ -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 *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];
|
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);
|
result.B = CalcBrightnessContrast(result.B, Luminosity, Contrast, grey);
|
||||||
|
|
||||||
// blend to the destination by using the mask alpha
|
// 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
|
/// keep alpha from the source
|
||||||
dest->R = result.R;
|
dest->R = result.R;
|
||||||
|
@ -111,7 +111,7 @@ void CColorModifier::evalBitmapStats(const NLMISC::CBitmap &srcBitmap,
|
||||||
float gTotal = 0;
|
float gTotal = 0;
|
||||||
|
|
||||||
const NLMISC::CRGBA *src = (NLMISC::CRGBA *) &srcBitmap.getPixels()[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)
|
for (uint y = 0; y < srcBitmap.getHeight(); ++y)
|
||||||
{
|
{
|
||||||
|
@ -119,7 +119,7 @@ void CColorModifier::evalBitmapStats(const NLMISC::CBitmap &srcBitmap,
|
||||||
{
|
{
|
||||||
float h, l, s;
|
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);
|
bool achromatic = src->convertToHLS(h, l, s);
|
||||||
|
|
||||||
float grey = 0.299f * src->R + 0.587f * src->G + 0.114f * src->B;
|
float grey = 0.299f * src->R + 0.587f * src->G + 0.114f * src->B;
|
||||||
|
|
|
@ -43,18 +43,15 @@ void CHLSBankTextureInfo::serial(NLMISC::IStream &f)
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CHLSBankTextureInfo::CMaskBitmap::build(const NLMISC::CBitmap &src)
|
void CHLSBankTextureInfo::CMaskBitmap::build(const NLMISC::CBitmap &src)
|
||||||
{
|
{
|
||||||
nlassert(src.getPixelFormat()==CBitmap::RGBA);
|
nlassert(src.getPixelFormat()==CBitmap::Luminance);
|
||||||
Width= src.getWidth();
|
Width= src.getWidth();
|
||||||
Height= src.getHeight();
|
Height= src.getHeight();
|
||||||
Pixels.resize(Width*Height);
|
Pixels.resize(Width*Height);
|
||||||
if(!Pixels.empty())
|
if(!Pixels.empty())
|
||||||
{
|
{
|
||||||
CRGBA *pSrc= (CRGBA*)(&src.getPixels()[0]);
|
uint8 *pSrc = (uint8*)src.getPixels().getPtr();
|
||||||
uint8 *pDst= &Pixels[0];
|
uint8 *pDst = &Pixels[0];
|
||||||
for(uint i=0; i<Pixels.size(); i++)
|
memcpy(pDst, pSrc, Pixels.size());
|
||||||
{
|
|
||||||
pDst[i]= pSrc[i].R;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -795,8 +795,38 @@ static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::str
|
||||||
// masks can be converted to grayscale files
|
// masks can be converted to grayscale files
|
||||||
if (bi.OptimizeTextures > 0 && maskDepth > 8)
|
if (bi.OptimizeTextures > 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)
|
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;
|
NLMISC::COFile os;
|
||||||
|
|
||||||
if (os.open(maskFileName))
|
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
|
/// 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());
|
nlerror("Couldn't write %s", fullHlsInfoPath.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue