From 34a8d26124313d6be9f7cc8b58829eaf5638625a Mon Sep 17 00:00:00 2001 From: boyu0 Date: Fri, 25 Jul 2014 18:19:04 +0800 Subject: [PATCH] Deprecate Texture2D::PVRImagesHavePremultipliedAlpha(), move Texture2D::PVRImagesHavePremultipliedAlpha() to Image. --- cocos/platform/CCImage.cpp | 12 ++++++++++-- cocos/platform/CCImage.h | 9 +++++++++ cocos/renderer/CCTexture2D.cpp | 22 ++++------------------ cocos/renderer/CCTexture2D.h | 4 +++- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/cocos/platform/CCImage.cpp b/cocos/platform/CCImage.cpp index 907904b302..835ab73422 100644 --- a/cocos/platform/CCImage.cpp +++ b/cocos/platform/CCImage.cpp @@ -97,6 +97,8 @@ namespace { static const int PVR_TEXTURE_FLAG_TYPE_MASK = 0xff; + static bool _PVRHaveAlphaPremultiplied = false; + // Values taken from PVRTexture.h from http://www.imgtec.com enum class PVR2TextureFlag { @@ -1287,8 +1289,8 @@ bool Image::initWithPVRv2Data(const unsigned char * data, ssize_t dataLen) Configuration *configuration = Configuration::getInstance(); - //can not detect the premultiplied alpha from pvr file. - + //can not detect the premultiplied alpha from pvr file, use _PVRHaveAlphaPremultiplied instead. + _hasPremultipliedAlpha = _PVRHaveAlphaPremultiplied; unsigned int flags = CC_SWAP_INT32_LITTLE_TO_HOST(header->flags); PVR2TexturePixelFormat formatFlags = static_cast(flags & PVR_TEXTURE_FLAG_TYPE_MASK); @@ -2355,5 +2357,11 @@ void Image::premultipliedAlpha() _hasPremultipliedAlpha = true; } + +void Image::PVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied) +{ + _PVRHaveAlphaPremultiplied = haveAlphaPremultiplied; +} + NS_CC_END diff --git a/cocos/platform/CCImage.h b/cocos/platform/CCImage.h index 46d49aa93c..e31a35c3cd 100644 --- a/cocos/platform/CCImage.h +++ b/cocos/platform/CCImage.h @@ -138,6 +138,15 @@ public: @param isToRGB whether the image is saved as RGB format. */ bool saveToFile(const std::string &filename, bool isToRGB = true); + + + /** 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. + */ + static void PVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied); protected: bool initWithJpgData(const unsigned char * data, ssize_t dataLen); diff --git a/cocos/renderer/CCTexture2D.cpp b/cocos/renderer/CCTexture2D.cpp index d120aa3112..602eed20f5 100644 --- a/cocos/renderer/CCTexture2D.cpp +++ b/cocos/renderer/CCTexture2D.cpp @@ -121,8 +121,6 @@ const Texture2D::PixelFormatInfoMap Texture2D::_pixelFormatInfoTables(TexturePix // Default is: RGBA8888 (32-bit textures) static Texture2D::PixelFormat g_defaultAlphaPixelFormat = Texture2D::PixelFormat::DEFAULT; -static bool _PVRHaveAlphaPremultiplied = false; - ////////////////////////////////////////////////////////////////////////// //conventer function @@ -779,20 +777,8 @@ bool Texture2D::initWithImage(Image *image, PixelFormat format) } // set the premultiplied tag - if (!image->hasPremultipliedAlpha()) - { - if (image->getFileType() == Image::Format::PVR) - { - _hasPremultipliedAlpha = _PVRHaveAlphaPremultiplied; - }else - { - CCLOG("wanning: We cann't find the data is premultiplied or not, we will assume it's false."); - _hasPremultipliedAlpha = false; - } - }else - { - _hasPremultipliedAlpha = image->isPremultipliedAlpha(); - } + _hasPremultipliedAlpha = image->hasPremultipliedAlpha(); + return true; } } @@ -1218,10 +1204,10 @@ void Texture2D::drawInRect(const Rect& rect) void Texture2D::PVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied) { - _PVRHaveAlphaPremultiplied = haveAlphaPremultiplied; + Image::PVRImagesHavePremultipliedAlpha(haveAlphaPremultiplied); } - + // // Use to apply MIN/MAG filter // diff --git a/cocos/renderer/CCTexture2D.h b/cocos/renderer/CCTexture2D.h index 97b515dc7e..ddd2d2f121 100644 --- a/cocos/renderer/CCTexture2D.h +++ b/cocos/renderer/CCTexture2D.h @@ -182,10 +182,12 @@ public: possible load them as if they have (or not) the alpha channel premultiplied. By default it is disabled. + + deprecated, please use Image::PVRImagesHavePremultipliedAlpha() instead. @since v0.99.5 */ - static void PVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied); + CC_DEPRECATED_ATTRIBUTE static void PVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied); public: /**