From 8fd439eb349e5d97ecdacc5baeb547a35edc16ce Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 1 Oct 2016 18:43:48 +0200 Subject: [PATCH] Merge with develop --- code/nel/src/misc/bitmap.cpp | 56 ++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/code/nel/src/misc/bitmap.cpp b/code/nel/src/misc/bitmap.cpp index 5574a8597..3f22dc752 100644 --- a/code/nel/src/misc/bitmap.cpp +++ b/code/nel/src/misc/bitmap.cpp @@ -1792,7 +1792,7 @@ void CBitmap::releaseMipMaps() \*-------------------------------------------------------------------*/ void CBitmap::resample(sint32 nNewWidth, sint32 nNewHeight) { - nlassert(PixelFormat == RGBA || PixelFormat == Luminance); + nlassert(PixelFormat == RGBA || PixelFormat == Luminance || PixelFormat == AlphaLuminance); bool needRebuild = false; // Deleting mipmaps @@ -1832,6 +1832,58 @@ void CBitmap::resample(sint32 nNewWidth, sint32 nNewHeight) resamplePicture8 (&_Data[0][0], pDestGray, _Width, _Height, nNewWidth, nNewHeight); //logResample("Resample: 60"); } + else if (PixelFormat == AlphaLuminance) + { + pDestui.resize(nNewWidth*nNewHeight*2); + + uint16 *pSrc = (uint16*)&_Data[0][0]; + uint16 *pDest = (uint16*)&pDestui[0]; + + size_t srcSize = _Width*_Width; + uint8 *pSrcGray = new uint8[srcSize]; + uint8 *pSrcAlpha = new uint8[srcSize]; + + // set iterators + uint16 *i = (uint16*)pSrc; + uint16 *iEnd = (uint16*)i + srcSize; + uint8 *iGray = pSrcGray; + uint8 *iAlpha = pSrcAlpha; + + // copy alpha and gray in distinct arrays + while (i < iEnd) + { + *(iGray++) = (*i) & 0xff; + *(iAlpha++) = ((*i) >> 8) & 0xff; + ++i; + } + + size_t destSize = nNewWidth*nNewHeight; + + // resample gray values array + uint8 *pDestGray = new uint8[destSize]; + resamplePicture8(pSrcGray, pDestGray, _Width, _Height, nNewWidth, nNewHeight); + delete[] pSrcGray; + + // resample alpha values array + uint8 *pDestAlpha = new uint8[destSize]; + resamplePicture8(pSrcAlpha, pDestAlpha, _Width, _Height, nNewWidth, nNewHeight); + delete[] pSrcAlpha; + + // set iterators + i = (uint16*)pDest; + iEnd = (uint16*)i + destSize; + iGray = pDestGray; + iAlpha = pDestAlpha; + + // merge alpha and gray in destination array + while (i < iEnd) + { + *(i++) = *(iGray++) | (*(iAlpha++) << 8); + } + + delete[] pDestGray; + delete[] pDestAlpha; + } NLMISC::contReset(_Data[0]); // free memory //logResample("Resample: 70"); @@ -2148,7 +2200,7 @@ void CBitmap::resamplePicture32Fast (const NLMISC::CRGBA *pSrc, NLMISC::CRGBA *p /*-------------------------------------------------------------------*\ - resamplePicture32 + resamplePicture8 \*-------------------------------------------------------------------*/ void CBitmap::resamplePicture8 (const uint8 *pSrc, uint8 *pDest, sint32 nSrcWidth, sint32 nSrcHeight,