From 01cf5793ad8fd8f6f2c9de2e824a6a390d8250ae Mon Sep 17 00:00:00 2001 From: minggo Date: Tue, 20 Dec 2011 14:59:15 +0800 Subject: [PATCH] fixed #922: rename CCTexture2D::setPVRImagesHavePremultipliedAlpha() and change it to a static method --- cocos2dx/include/CCTexture2D.h | 17 ++++++++++++----- cocos2dx/textures/CCTexture2D.cpp | 13 ++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/cocos2dx/include/CCTexture2D.h b/cocos2dx/include/CCTexture2D.h index 7c7fdfea8d..e8938b940a 100755 --- a/cocos2dx/include/CCTexture2D.h +++ b/cocos2dx/include/CCTexture2D.h @@ -201,12 +201,9 @@ public: /** returns the bits-per-pixel of the in-memory OpenGL texture @since v1.0 */ - unsigned int bitsPerPixelForFormat(); - - - void setPVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied); + unsigned int bitsPerPixelForFormat(); - /** sets the default pixel format for UIImages that contains alpha channel. + /** sets the default pixel format for UIImagescontains alpha channel. If the UIImage contains alpha channel, then the options are: - generate 32-bit textures: kCCTexture2DPixelFormat_RGBA8888 (default one) - generate 24-bit textures: kCCTexture2DPixelFormat_RGB888 @@ -228,6 +225,16 @@ public: */ static CCTexture2DPixelFormat defaultAlphaPixelFormat(); + /** treats (or not) PVR files as if they have alpha premultiplied. + Since it is impossible to know at runtime if the PVR images have the alpha channel premultiplied, it is + possible load them as if they have (or not) the alpha channel premultiplied. + + By default it is disabled. + + @since v0.99.5 + */ + static void PVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied); + private: bool initPremultipliedATextureWithImage(CCImage * image, unsigned int pixelsWide, unsigned int pixelsHigh); diff --git a/cocos2dx/textures/CCTexture2D.cpp b/cocos2dx/textures/CCTexture2D.cpp index 38de313b8d..5a9534216f 100644 --- a/cocos2dx/textures/CCTexture2D.cpp +++ b/cocos2dx/textures/CCTexture2D.cpp @@ -59,6 +59,9 @@ namespace cocos2d { // Default is: RGBA8888 (32-bit textures) static CCTexture2DPixelFormat g_defaultAlphaPixelFormat = kCCTexture2DPixelFormat_Default; +// By default PVR images are treated as if they don't have the alpha channel premultiplied +static bool PVRHaveAlphaPremultiplied_ = false; + CCTexture2D::CCTexture2D() : m_uPixelsWide(0) , m_uPixelsHigh(0) @@ -538,7 +541,7 @@ bool CCTexture2D::initWithPVRTCData(const void *data, int level, int bpp, bool h m_uPixelsHigh = length; m_fMaxS = 1.0f; m_fMaxT = 1.0f; - m_bHasPremultipliedAlpha = m_bPVRHaveAlphaPremultiplied; + m_bHasPremultipliedAlpha = PVRHaveAlphaPremultiplied_; m_ePixelFormat = pixelFormat; return true; @@ -562,8 +565,8 @@ bool CCTexture2D::initWithPVRFile(const char* file) m_fMaxT = 1.0f; m_uPixelsWide = pvr->getWidth(); m_uPixelsHigh = pvr->getHeight(); - m_tContentSize = CCSizeMake(m_uPixelsWide, m_uPixelsHigh); - m_bHasPremultipliedAlpha = m_bPVRHaveAlphaPremultiplied; + m_tContentSize = CCSizeMake((float)m_uPixelsWide, (float)m_uPixelsHigh); + m_bHasPremultipliedAlpha = PVRHaveAlphaPremultiplied_; m_ePixelFormat = pvr->getFormat(); this->setAntiAliasTexParameters(); @@ -577,9 +580,9 @@ bool CCTexture2D::initWithPVRFile(const char* file) return bRet; } -void CCTexture2D::setPVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied) +void CCTexture2D::PVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied) { - m_bPVRHaveAlphaPremultiplied = haveAlphaPremultiplied; + PVRHaveAlphaPremultiplied_ = haveAlphaPremultiplied; }