Merge pull request #15831 from j-jorge/premultiplied-alpha-config

Add a config option to enable or disable the premultiplied alpha code.
This commit is contained in:
minggo 2016-06-23 13:57:41 +08:00 committed by GitHub
commit 08898db883
2 changed files with 13 additions and 0 deletions

View File

@ -397,4 +397,12 @@ THE SOFTWARE.
#define CC_FILEUTILS_APPLE_ENABLE_OBJC 1
#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__

View File

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