From 6fb3946c51d6bb4f6ec80016978689147b197ca2 Mon Sep 17 00:00:00 2001 From: Julien Jorge Date: Mon, 20 Jun 2016 17:25:31 +0200 Subject: [PATCH] Add a config option to enable or disable the premultiplied alpha code. --- cocos/base/ccConfig.h | 8 ++++++++ cocos/platform/CCImage.cpp | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/cocos/base/ccConfig.h b/cocos/base/ccConfig.h index 4a251b7646..a79c1875a6 100644 --- a/cocos/base/ccConfig.h +++ b/cocos/base/ccConfig.h @@ -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__ diff --git a/cocos/platform/CCImage.cpp b/cocos/platform/CCImage.cpp index ee977724c6..b9806628e4 100644 --- a/cocos/platform/CCImage.cpp +++ b/cocos/platform/CCImage.cpp @@ -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 }