Add a config option to enable or disable the premultiplied alpha code.

This commit is contained in:
Julien Jorge 2016-06-20 17:25:31 +02:00
parent c25550e1a4
commit 6fb3946c51
2 changed files with 13 additions and 0 deletions

View File

@ -397,4 +397,12 @@ THE SOFTWARE.
#define CC_FILEUTILS_APPLE_ENABLE_OBJC 1 #define CC_FILEUTILS_APPLE_ENABLE_OBJC 1
#endif #endif
/** @def CC_ENABLE_PREMULTIPLIED_ALPHA
* If enabled, all textures will be preprocessed to multiply its rgb components
* by its alpha component.
*/
#ifndef CC_ENABLE_PREMULTIPLIED_ALPHA
# define CC_ENABLE_PREMULTIPLIED_ALPHA 1
#endif
#endif // __CCCONFIG_H__ #endif // __CCCONFIG_H__

View File

@ -2451,6 +2451,10 @@ bool Image::saveImageToJPG(const std::string& filePath)
void Image::premultipliedAlpha() void Image::premultipliedAlpha()
{ {
#if CC_ENABLE_PREMULTIPLIED_ALPHA == 0
_hasPremultipliedAlpha = false;
return;
#else
CCASSERT(_renderFormat == Texture2D::PixelFormat::RGBA8888, "The pixel format should be RGBA8888!"); CCASSERT(_renderFormat == Texture2D::PixelFormat::RGBA8888, "The pixel format should be RGBA8888!");
unsigned int* fourBytes = (unsigned int*)_data; unsigned int* fourBytes = (unsigned int*)_data;
@ -2461,6 +2465,7 @@ void Image::premultipliedAlpha()
} }
_hasPremultipliedAlpha = true; _hasPremultipliedAlpha = true;
#endif
} }