diff --git a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems
index 00d15716a2..9c5ba13194 100644
--- a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems
+++ b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems
@@ -472,6 +472,7 @@
+
@@ -1027,6 +1028,7 @@
+
diff --git a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters
index bb797c3e11..147ee82956 100644
--- a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters
+++ b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters
@@ -1743,6 +1743,9 @@
3d
+
+ platform\winrt
+
@@ -3315,6 +3318,9 @@
cocostudio\json
+
+ platform\winrt
+
diff --git a/cocos/2d/winrt_8.1_props/cocos2d_winrt_8.1.props b/cocos/2d/winrt_8.1_props/cocos2d_winrt_8.1.props
index ded7698462..55a7c3a2a4 100644
--- a/cocos/2d/winrt_8.1_props/cocos2d_winrt_8.1.props
+++ b/cocos/2d/winrt_8.1_props/cocos2d_winrt_8.1.props
@@ -18,8 +18,8 @@
4056;4244;4251;4756;4453;28204;
- libGLESv2.lib;libEGL.lib;ws2_32.lib;libwebsockets.lib;libcurl.lib;chipmunk.lib;zlib.lib;libpng.lib;libjpeg.lib;libtiff.lib;freetype.lib;sqlite3.lib;d2d1.lib;d3d11.lib;dxgi.lib;windowscodecs.lib;dwrite.lib;dxguid.lib;xaudio2.lib;mfcore.lib;mfplat.lib;mfreadwrite.lib;mfuuid.lib;%(AdditionalDependencies)
- $(EngineRoot)external\$(COCOS2D_PLATFORM)-specific\angle\prebuilt\$(Platform);$(EngineRoot)external\curl\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\websockets\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\chipmunk\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\$(COCOS2D_PLATFORM)-specific\zlib\prebuilt\$(Platform);$(EngineRoot)external\png\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\tiff\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\jpeg\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\sqlite3\libraries\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\freetype2\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);%(AdditionalLibraryDirectories);
+ libGLESv2.lib;libEGL.lib;ws2_32.lib;libwebsockets.lib;libcurl.lib;chipmunk.lib;zlib.lib;freetype.lib;sqlite3.lib;d2d1.lib;d3d11.lib;dxgi.lib;windowscodecs.lib;dwrite.lib;dxguid.lib;xaudio2.lib;mfcore.lib;mfplat.lib;mfreadwrite.lib;mfuuid.lib;%(AdditionalDependencies)
+ $(EngineRoot)external\$(COCOS2D_PLATFORM)-specific\angle\prebuilt\$(Platform);$(EngineRoot)external\curl\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\websockets\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\chipmunk\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\$(COCOS2D_PLATFORM)-specific\zlib\prebuilt\$(Platform);$(EngineRoot)external\sqlite3\libraries\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\freetype2\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);%(AdditionalLibraryDirectories);
/IGNORE:4264 %(AdditionalOptions)
diff --git a/cocos/base/ccConfig.h b/cocos/base/ccConfig.h
index 292fdcff92..87f59cf931 100644
--- a/cocos/base/ccConfig.h
+++ b/cocos/base/ccConfig.h
@@ -257,6 +257,12 @@ THE SOFTWARE.
#define CC_USE_CULLING 1
#endif
+/** Support PNG or not. If your application don't use png format picture, you can undefine this macro to save package size.
+*/
+#ifndef CC_USE_PNG
+#define CC_USE_PNG 1
+#endif // CC_USE_PNG
+
/** Support JPEG or not. If your application don't use jpeg format picture, you can undefine this macro to save package size.
*/
#ifndef CC_USE_JPEG
@@ -277,6 +283,17 @@ THE SOFTWARE.
#endif
#endif // CC_USE_WEBP
+ /** Support WIC (Windows Image Component) or not. Replaces PNG, TIFF and JPEG
+ */
+#ifndef CC_USE_WIC
+#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
+#define CC_USE_WIC 1
+#undef CC_USE_TIFF
+#undef CC_USE_JPEG
+#undef CC_USE_PNG
+#endif
+#endif // CC_USE_WIC
+
/** Enable Script binding. */
#ifndef CC_ENABLE_SCRIPT_BINDING
#define CC_ENABLE_SCRIPT_BINDING 1
diff --git a/cocos/platform/CCImage.cpp b/cocos/platform/CCImage.cpp
index d2fcf9b9ce..03f6ab82a0 100644
--- a/cocos/platform/CCImage.cpp
+++ b/cocos/platform/CCImage.cpp
@@ -54,8 +54,11 @@ extern "C"
}
#endif
#endif
+
+#if CC_USE_PNG
#include "png.h"
-
+#endif //CC_USE_PNG
+
#if CC_USE_TIFF
#include "tiffio.h"
#endif //CC_USE_TIFF
@@ -409,7 +412,8 @@ namespace
ssize_t size;
int offset;
}tImageSource;
-
+
+#ifdef CC_USE_PNG
static void pngReadCallback(png_structp png_ptr, png_bytep data, png_size_t length)
{
tImageSource* isource = (tImageSource*)png_get_io_ptr(png_ptr);
@@ -424,6 +428,7 @@ namespace
png_error(png_ptr, "pngReaderCallback failed");
}
}
+#endif //CC_USE_PNG
}
Texture2D::PixelFormat getDevicePixelFormat(Texture2D::PixelFormat format)
@@ -819,9 +824,75 @@ namespace
#endif // CC_USE_JPEG
}
+#ifdef CC_USE_WIC
+bool Image::decodeWithWIC(const unsigned char *data, ssize_t dataLen)
+{
+ bool bRet = false;
+ WICImageLoader img;
+
+ if (img.decodeImageData(data, dataLen))
+ {
+ _width = img.getWidth();
+ _height = img.getHeight();
+ _hasPremultipliedAlpha = false;
+
+ WICPixelFormatGUID format = img.getPixelFormat();
+
+ if (memcmp(&format, &GUID_WICPixelFormat8bppGray, sizeof(WICPixelFormatGUID)) == 0)
+ {
+ _renderFormat = Texture2D::PixelFormat::I8;
+ }
+
+ if (memcmp(&format, &GUID_WICPixelFormat8bppAlpha, sizeof(WICPixelFormatGUID)) == 0)
+ {
+ _renderFormat = Texture2D::PixelFormat::AI88;
+ }
+
+ if (memcmp(&format, &GUID_WICPixelFormat24bppRGB, sizeof(WICPixelFormatGUID)) == 0)
+ {
+ _renderFormat = Texture2D::PixelFormat::RGB888;
+ }
+
+ if (memcmp(&format, &GUID_WICPixelFormat32bppRGBA, sizeof(WICPixelFormatGUID)) == 0)
+ {
+ _renderFormat = Texture2D::PixelFormat::RGBA8888;
+ }
+
+ if (memcmp(&format, &GUID_WICPixelFormat32bppBGRA, sizeof(WICPixelFormatGUID)) == 0)
+ {
+ _renderFormat = Texture2D::PixelFormat::BGRA8888;
+ }
+
+ _dataLen = img.getImageDataSize();
+
+ CCAssert(_dataLen > 0, "Image: Decompressed data length is invalid");
+
+ _data = new (std::nothrow) unsigned char[_dataLen];
+ bRet = (img.getImageData(_data, _dataLen) > 0);
+
+ if (_renderFormat == Texture2D::PixelFormat::RGBA8888) {
+ premultipliedAlpha();
+ }
+ }
+
+ return bRet;
+}
+
+bool Image::encodeWithWIC(const std::string& filePath, bool isToRGB, GUID containerFormat)
+{
+ WICPixelFormatGUID format = isToRGB ? GUID_WICPixelFormat24bppRGB : GUID_WICPixelFormat32bppRGBA;
+
+ WICImageLoader img;
+ return img.encodeImageData(filePath, _data, _dataLen, format, _width, _height, containerFormat);
+}
+
+#endif //CC_USE_WIC
+
bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen)
{
-#if CC_USE_JPEG
+#if defined(CC_USE_WIC)
+ return decodeWithWIC(data, dataLen);
+#elif defined(CC_USE_JPEG)
/* these are standard libjpeg structures for reading(decompression) */
struct jpeg_decompress_struct cinfo;
/* We use our private extension JPEG error handler.
@@ -908,12 +979,16 @@ bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen)
return ret;
#else
+ CCLOG("jpeg is not enabled, please enable it in ccConfig.h");
return false;
#endif // CC_USE_JPEG
}
bool Image::initWithPngData(const unsigned char * data, ssize_t dataLen)
{
+#if defined(CC_USE_WIC)
+ return decodeWithWIC(data, dataLen);
+#elif defined(CC_USE_PNG)
// length of bytes to check if it is a valid png file
#define PNGSIGSIZE 8
bool ret = false;
@@ -1060,6 +1135,10 @@ bool Image::initWithPngData(const unsigned char * data, ssize_t dataLen)
png_destroy_read_struct(&png_ptr, (info_ptr) ? &info_ptr : 0, 0);
}
return ret;
+#else
+ CCLOG("png is not enabled, please enable it in ccConfig.h");
+ return false;
+#endif //CC_USE_PNG
}
#if CC_USE_TIFF
@@ -1176,7 +1255,9 @@ namespace
bool Image::initWithTiffData(const unsigned char * data, ssize_t dataLen)
{
-#if CC_USE_TIFF
+#if defined(CC_USE_WIC)
+ return decodeWithWIC(data, dataLen);
+#elif defined(CC_USE_TIFF)
bool ret = false;
do
{
@@ -1235,9 +1316,9 @@ bool Image::initWithTiffData(const unsigned char * data, ssize_t dataLen)
} while (0);
return ret;
#else
- CCLOG("tiff is not enabled, please enalbe it in ccConfig.h");
+ CCLOG("tiff is not enabled, please enable it in ccConfig.h");
return false;
-#endif
+#endif //CC_USE_TIFF
}
namespace
@@ -2139,8 +2220,11 @@ bool Image::saveToFile(const std::string& filename, bool isToRGB)
bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB)
{
+#if defined(CC_USE_WIC)
+ return encodeWithWIC(filePath, isToRGB, GUID_ContainerFormatPng);
+#elif defined(CC_USE_PNG)
bool ret = false;
- do
+ do
{
FILE *fp;
png_structp png_ptr;
@@ -2280,10 +2364,17 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB)
ret = true;
} while (0);
return ret;
+#else
+ CCLOG("png is not enabled, please enable it in ccConfig.h");
+ return false;
+#endif // CC_USE_PNG
}
+
bool Image::saveImageToJPG(const std::string& filePath)
{
-#if CC_USE_JPEG
+#if defined(CC_USE_WIC)
+ return encodeWithWIC(filePath, false, GUID_ContainerFormatJpeg);
+#elif defined(CC_USE_JPEG)
bool ret = false;
do
{
diff --git a/cocos/platform/CCImage.h b/cocos/platform/CCImage.h
index 6abedd5c57..b03f4a7db9 100644
--- a/cocos/platform/CCImage.h
+++ b/cocos/platform/CCImage.h
@@ -30,6 +30,10 @@ THE SOFTWARE.
#include "base/CCRef.h"
#include "renderer/CCTexture2D.h"
+#if defined(CC_USE_WIC)
+#include "WICImageLoader-win.h"
+#endif
+
// premultiply alpha, or the effect will wrong when want to use other pixel format in Texture2D,
// such as RGB888, RGB5A1
#define CC_RGB_PREMULTIPLY_ALPHA(vr, vg, vb, va) \
@@ -150,6 +154,10 @@ public:
static void setPVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied);
protected:
+#if defined(CC_USE_WIC)
+ bool encodeWithWIC(const std::string& filePath, bool isToRGB, GUID containerFormat);
+ bool decodeWithWIC(const unsigned char *data, ssize_t dataLen);
+#endif
bool initWithJpgData(const unsigned char * data, ssize_t dataLen);
bool initWithPngData(const unsigned char * data, ssize_t dataLen);
bool initWithTiffData(const unsigned char * data, ssize_t dataLen);