mirror of https://github.com/axmolengine/axmol.git
added Windows Image Component support for Windows 8.1 Universal App
This commit is contained in:
parent
01135f892f
commit
b1c9c34c19
|
@ -472,6 +472,7 @@
|
|||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\platform\winrt\Keyboard-winrt.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\platform\winrt\pch.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\platform\winrt\sha1.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\platform\winrt\WICImageLoader-win.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCBatchCommand.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCCustomCommand.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCGLProgram.h" />
|
||||
|
@ -1027,6 +1028,7 @@
|
|||
</ForcedIncludeFiles>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\platform\winrt\sha1.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\platform\winrt\WICImageLoader-win.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCBatchCommand.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCCustomCommand.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\renderer\CCGLProgram.cpp" />
|
||||
|
|
|
@ -1743,6 +1743,9 @@
|
|||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\3d\CCTerrain.h">
|
||||
<Filter>3d</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\platform\winrt\WICImageLoader-win.h">
|
||||
<Filter>platform\winrt</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\cocos2d.cpp" />
|
||||
|
@ -3315,6 +3318,9 @@
|
|||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\CocoStudio.cpp">
|
||||
<Filter>cocostudio\json</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\platform\winrt\WICImageLoader-win.cpp">
|
||||
<Filter>platform\winrt</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="2d">
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
<DisableSpecificWarnings>4056;4244;4251;4756;4453;28204;</DisableSpecificWarnings>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>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)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(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);</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>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)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(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);</AdditionalLibraryDirectories>
|
||||
<AdditionalOptions>/IGNORE:4264 %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue