From 18fc27ced1be8f44d387d0b4496e248fafa8a925 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Thu, 28 Jul 2016 18:37:40 +0800 Subject: [PATCH] add image lib file back --- .../cocos2d_libs.xcodeproj/project.pbxproj | 58 ++++++++--- native/cocos/platform/CCImage.cpp | 10 +- native/cocos/platform/ios/CCImage-ios.mm | 96 ------------------- 3 files changed, 47 insertions(+), 117 deletions(-) diff --git a/native/build/cocos2d_libs.xcodeproj/project.pbxproj b/native/build/cocos2d_libs.xcodeproj/project.pbxproj index 0a466ee0a4..7761028440 100644 --- a/native/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/native/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -1283,6 +1283,10 @@ B276EF641988D1D500CD400F /* CCVertexIndexBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = B276EF5D1988D1D500CD400F /* CCVertexIndexBuffer.h */; }; B276EF651988D1D500CD400F /* CCVertexIndexBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B276EF5E1988D1D500CD400F /* CCVertexIndexBuffer.cpp */; }; B276EF661988D1D500CD400F /* CCVertexIndexBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B276EF5E1988D1D500CD400F /* CCVertexIndexBuffer.cpp */; }; + B291B51B1D4A106A00BBB345 /* libjpeg.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B291B5171D4A106A00BBB345 /* libjpeg.a */; }; + B291B51C1D4A106A00BBB345 /* libpng.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B291B5181D4A106A00BBB345 /* libpng.a */; }; + B291B51D1D4A106A00BBB345 /* libtiff.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B291B5191D4A106A00BBB345 /* libtiff.a */; }; + B291B51E1D4A106A00BBB345 /* libwebp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B291B51A1D4A106A00BBB345 /* libwebp.a */; }; B29A7DC719EE1B7700872B35 /* SkeletonRenderer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B29A7D8A19EE1B7700872B35 /* SkeletonRenderer.cpp */; }; B29A7DC819EE1B7700872B35 /* SkeletonRenderer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B29A7D8A19EE1B7700872B35 /* SkeletonRenderer.cpp */; }; B29A7DC919EE1B7700872B35 /* SlotData.c in Sources */ = {isa = PBXBuildFile; fileRef = B29A7D8B19EE1B7700872B35 /* SlotData.c */; }; @@ -2205,6 +2209,10 @@ B276EF5C1988D1D500CD400F /* CCVertexIndexData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCVertexIndexData.cpp; sourceTree = ""; }; B276EF5D1988D1D500CD400F /* CCVertexIndexBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCVertexIndexBuffer.h; sourceTree = ""; }; B276EF5E1988D1D500CD400F /* CCVertexIndexBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCVertexIndexBuffer.cpp; sourceTree = ""; }; + B291B5171D4A106A00BBB345 /* libjpeg.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libjpeg.a; path = ../external/ios/libs/libjpeg.a; sourceTree = ""; }; + B291B5181D4A106A00BBB345 /* libpng.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libpng.a; path = ../external/ios/libs/libpng.a; sourceTree = ""; }; + B291B5191D4A106A00BBB345 /* libtiff.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtiff.a; path = ../external/ios/libs/libtiff.a; sourceTree = ""; }; + B291B51A1D4A106A00BBB345 /* libwebp.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libwebp.a; path = ../external/ios/libs/libwebp.a; sourceTree = ""; }; B29A7D8A19EE1B7700872B35 /* SkeletonRenderer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SkeletonRenderer.cpp; sourceTree = ""; }; B29A7D8B19EE1B7700872B35 /* SlotData.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SlotData.c; sourceTree = ""; }; B29A7D8C19EE1B7700872B35 /* Skeleton.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Skeleton.c; sourceTree = ""; }; @@ -2353,8 +2361,12 @@ files = ( A60A9D661C200E5A0070800A /* libchipmunk.a in Frameworks */, EDE5DFF81C0D6B3F0014147A /* libwebsockets.a in Frameworks */, + B291B51D1D4A106A00BBB345 /* libtiff.a in Frameworks */, ED6822341BECB14500ED75EA /* libfreetype.a in Frameworks */, + B291B51B1D4A106A00BBB345 /* libjpeg.a in Frameworks */, + B291B51E1D4A106A00BBB345 /* libwebp.a in Frameworks */, A07A4CAF1783777C0073F6A7 /* Foundation.framework in Frameworks */, + B291B51C1D4A106A00BBB345 /* libpng.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2413,19 +2425,8 @@ 1551A341158F2AB200E66CFE /* Frameworks */ = { isa = PBXGroup; children = ( - A6A554241C2A7C4400FDD954 /* libssl.a */, - A6A554221C2A7C3100FDD954 /* libcrypto.a */, - A6A554201C2A7C1300FDD954 /* libcurl.a */, - A6A5541E1C2A7BF700FDD954 /* libchipmunk.a */, - A60A9D651C200E5A0070800A /* libchipmunk.a */, - EDE5DFF71C0D6B3F0014147A /* libwebsockets.a */, - ED3057C81BEC7DA80083C3ED /* libfreetype.a */, - ED3057C91BEC7DA80083C3ED /* libglfw3.a */, - ED3057CA1BEC7DA80083C3ED /* libjpeg.a */, - ED3057CB1BEC7DA80083C3ED /* libpng.a */, - ED3057CC1BEC7DA80083C3ED /* libtiff.a */, - ED3057CD1BEC7DA80083C3ED /* libwebsockets.a */, - ED3057BE1BEC78580083C3ED /* libfreetype.a */, + B291B5161D4A0FEA00BBB345 /* ios */, + B291B5151D4A0FE300BBB345 /* mac */, B21770461977ED34009EE11B /* QuartzCore.framework */, B21770431977ED07009EE11B /* Cocoa.framework */, B21770411977ECF8009EE11B /* ApplicationServices.framework */, @@ -3645,6 +3646,37 @@ name = Armature; sourceTree = ""; }; + B291B5151D4A0FE300BBB345 /* mac */ = { + isa = PBXGroup; + children = ( + A6A554201C2A7C1300FDD954 /* libcurl.a */, + ED3057C81BEC7DA80083C3ED /* libfreetype.a */, + A6A5541E1C2A7BF700FDD954 /* libchipmunk.a */, + ED3057C91BEC7DA80083C3ED /* libglfw3.a */, + ED3057CB1BEC7DA80083C3ED /* libpng.a */, + ED3057CC1BEC7DA80083C3ED /* libtiff.a */, + ED3057CA1BEC7DA80083C3ED /* libjpeg.a */, + ED3057CD1BEC7DA80083C3ED /* libwebsockets.a */, + A6A554221C2A7C3100FDD954 /* libcrypto.a */, + A6A554241C2A7C4400FDD954 /* libssl.a */, + ); + name = mac; + sourceTree = ""; + }; + B291B5161D4A0FEA00BBB345 /* ios */ = { + isa = PBXGroup; + children = ( + B291B5171D4A106A00BBB345 /* libjpeg.a */, + B291B5181D4A106A00BBB345 /* libpng.a */, + B291B5191D4A106A00BBB345 /* libtiff.a */, + B291B51A1D4A106A00BBB345 /* libwebp.a */, + EDE5DFF71C0D6B3F0014147A /* libwebsockets.a */, + A60A9D651C200E5A0070800A /* libchipmunk.a */, + ED3057BE1BEC78580083C3ED /* libfreetype.a */, + ); + name = ios; + sourceTree = ""; + }; BA679B271CEC371100F875FA /* assets-manager */ = { isa = PBXGroup; children = ( diff --git a/native/cocos/platform/CCImage.cpp b/native/cocos/platform/CCImage.cpp index 9084240f74..bcba7994ab 100644 --- a/native/cocos/platform/CCImage.cpp +++ b/native/cocos/platform/CCImage.cpp @@ -35,8 +35,6 @@ THE SOFTWARE. extern "C" { -#if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) - #if CC_USE_PNG #include "png/png.h" #endif //CC_USE_PNG @@ -49,8 +47,6 @@ extern "C" #include "jpeg/jpeglib.h" #endif // CC_USE_JPEG -#endif // (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) - #include "base/etc1.h" } @@ -270,7 +266,6 @@ namespace int offset; }tImageSource; -#if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) #ifdef CC_USE_PNG static void pngReadCallback(png_structp png_ptr, png_bytep data, png_size_t length) @@ -288,7 +283,6 @@ namespace } } #endif //CC_USE_PNG -#endif // (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) } Texture2D::PixelFormat getDevicePixelFormat(Texture2D::PixelFormat format) @@ -1342,6 +1336,8 @@ bool Image::saveImageToJPG(const std::string& filePath) #endif // CC_USE_JPEG } +#endif // (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) + namespace { /* @@ -1834,8 +1830,6 @@ bool Image::initWithTiffData(const unsigned char * data, ssize_t dataLen) #endif //CC_USE_TIFF } -#endif // (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) - void Image::premultipliedAlpha() { CCASSERT(_renderFormat == Texture2D::PixelFormat::RGBA8888, "The pixel format should be RGBA8888!"); diff --git a/native/cocos/platform/ios/CCImage-ios.mm b/native/cocos/platform/ios/CCImage-ios.mm index 5f9c08e8a8..408a85e70e 100644 --- a/native/cocos/platform/ios/CCImage-ios.mm +++ b/native/cocos/platform/ios/CCImage-ios.mm @@ -121,102 +121,6 @@ bool cocos2d::Image::saveToFile(const std::string& filename, bool isToRGB) return true; } -bool cocos2d::Image::initWithJpgData(const unsigned char * data, ssize_t dataLen) -{ - return initWithPngData(data, dataLen); -} - -bool cocos2d::Image::initWithTiffData(const unsigned char * data, ssize_t dataLen) -{ - return initWithPngData(data, dataLen); -} - -bool cocos2d::Image::initWithPngData(const unsigned char * data, ssize_t dataLen) -{ - // create CGImage and get CGImageRef - NSData *nsData = [NSData dataWithBytes:data length:dataLen]; - UIImage *uiImage = [UIImage imageWithData:nsData]; - if (!uiImage) - return false; - - // get width and height - CGImageRef cgimageRef = uiImage.CGImage; - _width = (int)CGImageGetWidth(cgimageRef); - _height = (int)CGImageGetHeight(cgimageRef); - - // get data length and data - CFDataRef rawData = CGDataProviderCopyData(CGImageGetDataProvider(cgimageRef)); - _dataLen = CFDataGetLength(rawData); - _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); - CFDataGetBytes(rawData, CFRangeMake(0, _dataLen), _data); - CFRelease(rawData); - - // check if it is alpha premultified - CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(cgimageRef); - _hasPremultipliedAlpha = alphaInfo == kCGImageAlphaPremultipliedLast || alphaInfo == kCGImageAlphaPremultipliedFirst; - - // get render format - size_t bitsPerComponent = CGImageGetBitsPerComponent(cgimageRef); - size_t bitsPerPixel = CGImageGetBitsPerPixel(cgimageRef); - size_t channels = bitsPerPixel / bitsPerComponent; - bool hasAlpha = ((alphaInfo == kCGImageAlphaPremultipliedLast) || - (alphaInfo == kCGImageAlphaPremultipliedFirst) || - (alphaInfo == kCGImageAlphaLast) || - (alphaInfo == kCGImageAlphaFirst) - ? true : false); - - CGColorSpaceRef colorSpace = CGImageGetColorSpace(cgimageRef); - if (colorSpace) - { - switch (CGColorSpaceGetModel(colorSpace)) - { - case kCGColorSpaceModelMonochrome: - if (hasAlpha && channels == 2 && bitsPerComponent == 8) - { - _renderFormat = cocos2d::Texture2D::PixelFormat::AI88; - break; - } - // other situations continue - case kCGColorSpaceModelRGB: - if (hasAlpha && channels == 4 && bitsPerComponent == 8) - { - _renderFormat = cocos2d::Texture2D::PixelFormat::RGBA8888; - break; - } - if (!hasAlpha && channels == 3 && bitsPerComponent == 8) - { - _renderFormat = cocos2d::Texture2D::PixelFormat::RGB888; - break; - } - // other situations continue - default: - { - colorSpace = CGColorSpaceCreateDeviceRGB(); - free(_data); - _data = static_cast(malloc(_height * _width * 4)); - CGContextRef context = CGBitmapContextCreate(_data, _width, _height, 8, 4 * _width, colorSpace, kCGImageAlphaPremultipliedLast); - CGColorSpaceRelease(colorSpace); - CGContextClearRect(context, CGRectMake(0, 0, _width, _height)); - CGContextTranslateCTM(context, 0, 0); - CGContextDrawImage(context, CGRectMake(0, 0, _width, _height), cgimageRef); - CGContextRelease(context); - - _renderFormat = cocos2d::Texture2D::PixelFormat::RGBA8888; - _hasPremultipliedAlpha = true; - break; - } - } - } - else - { - // it is a mask - _renderFormat = cocos2d::Texture2D::PixelFormat::A8; - } - - - return true; -} - NS_CC_END #endif // CC_PLATFORM_IOS