Deprecate Texture2D::PVRImagesHavePremultipliedAlpha(), move Texture2D::PVRImagesHavePremultipliedAlpha() to Image.

This commit is contained in:
boyu0 2014-07-25 18:19:04 +08:00
parent e3b79f4150
commit 34a8d26124
4 changed files with 26 additions and 21 deletions

View File

@ -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<PVR2TexturePixelFormat>(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

View File

@ -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);

View File

@ -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
//

View File

@ -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:
/**