From 8035fc366cdbaa4c273e37ea159b4bf8325e3476 Mon Sep 17 00:00:00 2001 From: natural-law Date: Thu, 17 Feb 2011 16:16:50 +0800 Subject: [PATCH] [uphone]Support read image file from zip file. --- HelloWorld/AppDelegate.cpp | 8 ++--- .../platform/uphone/CCXFileUtils_uphone.cpp | 4 +-- cocos2dx/textures/CCTextureCache.cpp | 11 ++++-- platform_support/include/ccxImage.h | 1 - platform_support/src/ccxImage.cpp | 35 +++++++------------ .../src/uphone/ccxImage_uphone.cpp | 5 ++- 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/HelloWorld/AppDelegate.cpp b/HelloWorld/AppDelegate.cpp index 0ff577b28f..535912ee2d 100644 --- a/HelloWorld/AppDelegate.cpp +++ b/HelloWorld/AppDelegate.cpp @@ -42,10 +42,10 @@ bool AppDelegate::applicationDidFinishLaunching() #if (CCX_TARGET_PLATFORM == CCX_PLATFORM_UPHONE) -// on uphone emulator, we copy resources files to Work7/TG3/APP/ folder instead of zip file -// #ifndef _TRANZDA_VM_ -// cocos2d::CCFileUtils::setResource("HelloWorld.zip"); -// #endif +#ifndef _TRANZDA_VM_ + // on uphone emulator, we copy resources files to Work7/TG3/APP/ folder instead of zip file + cocos2d::CCFileUtils::setResource("HelloWorld.zip"); +#endif #endif diff --git a/cocos2dx/platform/uphone/CCXFileUtils_uphone.cpp b/cocos2dx/platform/uphone/CCXFileUtils_uphone.cpp index 4e22e86339..2ef55c8b23 100644 --- a/cocos2dx/platform/uphone/CCXFileUtils_uphone.cpp +++ b/cocos2dx/platform/uphone/CCXFileUtils_uphone.cpp @@ -260,8 +260,8 @@ void setZipFilePath(const char* pZipFileName) strErr += " not exist!"; TUChar szText[EOS_FILE_MAX_PATH] = { 0 }; TUString::StrUtf8ToStrUnicode(szText,(Char*)strErr.c_str()); - // TApplication::GetCurrentApplication()->MessageBox(szText,NULL,WMB_OK); - TMessageBox box(szText, NULL, WMB_OK); // to be fix. This line isn't work, but not block + TMessageBox box(szText, NULL, WMB_OK); + box.Show(); return; } diff --git a/cocos2dx/textures/CCTextureCache.cpp b/cocos2dx/textures/CCTextureCache.cpp index bae1832c9b..d607ff2ed8 100644 --- a/cocos2dx/textures/CCTextureCache.cpp +++ b/cocos2dx/textures/CCTextureCache.cpp @@ -33,6 +33,7 @@ THE SOFTWARE. #include "platform/platform.h" #include "CCXFileUtils.h" #include "ccxImage.h" +#include "support/file_support/FileData.h" namespace cocos2d { @@ -206,7 +207,10 @@ CCTexture2D * CCTextureCache::addImage(const char * path) else if (std::string::npos != lowerCase.find(".jpg") || std::string::npos != lowerCase.find(".jpeg")) { ccxImage * image = new ccxImage(); - if(! image->initWithImageFile(fullpath.c_str(), ccxImage::kFmtJpg)) + FileData data; + unsigned long nSize = 0; + unsigned char* pBuffer = data.getFileData(fullpath.c_str(), "rb", &nSize); + if(! image->initWithImageData((void*)pBuffer, nSize, ccxImage::kFmtJpg)) { delete image; break; @@ -234,7 +238,10 @@ CCTexture2D * CCTextureCache::addImage(const char * path) #else // prevents overloading the autorelease pool ccxImage * image = new ccxImage(); - if(! image->initWithImageFile(fullpath.c_str(), ccxImage::kFmtPng)) + FileData data; + unsigned long nSize = 0; + unsigned char* pBuffer = data.getFileData(fullpath.c_str(), "rb", &nSize); + if(! image->initWithImageData((void*)pBuffer, nSize, ccxImage::kFmtPng)) { delete image; break; diff --git a/platform_support/include/ccxImage.h b/platform_support/include/ccxImage.h index 7318ea6dea..58726a148b 100644 --- a/platform_support/include/ccxImage.h +++ b/platform_support/include/ccxImage.h @@ -115,7 +115,6 @@ public: protected: bool _initWithJpgData(void * pData, int nDatalen); - bool _initWithJpgFile(const char * strPath); bool _initWithPngData(void * pData, int nDatalen); ccxScopedArray m_pData; diff --git a/platform_support/src/ccxImage.cpp b/platform_support/src/ccxImage.cpp index 0b0823e5b0..eccebcc0bc 100644 --- a/platform_support/src/ccxImage.cpp +++ b/platform_support/src/ccxImage.cpp @@ -85,13 +85,6 @@ bool ccxImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = unsigned char *buffer = NULL; do { - if (kFmtJpg == eImgFmt) - { - bRet = _initWithJpgFile(strPath); - break; - } - CCX_BREAK_IF(kFmtPng != eImgFmt); - // open file fp = fopen(strPath, "rb"); CCX_BREAK_IF(! fp); @@ -108,9 +101,14 @@ bool ccxImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = // read data size = fread(buffer, sizeof(unsigned char), size, fp); - bRet = _initWithPngData(buffer, size); - - bRet = true; + if (kFmtJpg == eImgFmt) + { + bRet = _initWithJpgData(buffer, size); + } + else + { + bRet = _initWithPngData(buffer, size); + } } while (0); CCX_SAFE_DELETE_ARRAY(buffer); @@ -143,7 +141,7 @@ bool ccxImage::initWithImageData(void * pData, int nDataLen, EImageFormat eFmt/* } else if (kFmtJpg == eFmt) { -// bRet = _initWithJpgData(pData, nDataLen); + bRet = _initWithJpgData(pData, nDataLen); break; } } while (0); @@ -162,7 +160,7 @@ bool ccxImage::getIsPopupNotify() return s_bPopupNotify; } -bool ccxImage::_initWithJpgFile(const char * strFileName) +bool ccxImage::_initWithJpgData(void * data, int nSize) { /* these are standard libjpeg structures for reading(decompression) */ struct jpeg_decompress_struct cinfo; @@ -170,15 +168,9 @@ bool ccxImage::_initWithJpgFile(const char * strFileName) /* libjpeg data structure for storing one row, that is, scanline of an image */ JSAMPROW row_pointer[1]; - FILE *infile = fopen( strFileName, "rb" ); unsigned long location = 0; unsigned int i = 0; - if ( !infile ) - { - return false; - } - /* here we set up the standard libjpeg error handler */ cinfo.err = jpeg_std_error( &jerr ); @@ -186,7 +178,7 @@ bool ccxImage::_initWithJpgFile(const char * strFileName) jpeg_create_decompress( &cinfo ); /* this makes the library read from infile */ - jpeg_stdio_src( &cinfo, infile ); + jpeg_mem_src( &cinfo, (unsigned char *) data, nSize ); /* reading the image header which contains image information */ jpeg_read_header( &cinfo, true ); @@ -208,8 +200,8 @@ bool ccxImage::_initWithJpgFile(const char * strFileName) jpeg_start_decompress( &cinfo ); /* init image info */ - m_nWidth = (ccxInt16)cinfo.image_width; - m_nHeight = (ccxInt16)cinfo.image_height; + m_nWidth = cinfo.image_width; + m_nHeight = cinfo.image_height; m_bHasAlpha = false; m_bPreMulti = false; m_nBitsPerComponent = 8; @@ -231,7 +223,6 @@ bool ccxImage::_initWithJpgFile(const char * strFileName) jpeg_finish_decompress( &cinfo ); jpeg_destroy_decompress( &cinfo ); delete row_pointer[0]; - fclose( infile ); return true; } diff --git a/platform_support/src/uphone/ccxImage_uphone.cpp b/platform_support/src/uphone/ccxImage_uphone.cpp index 1913ad8e96..af595f3b36 100644 --- a/platform_support/src/uphone/ccxImage_uphone.cpp +++ b/platform_support/src/uphone/ccxImage_uphone.cpp @@ -28,7 +28,10 @@ NS_CC_BEGIN void ccxMessageBox(const ccxString& msg, const ccxString& title) { - //MessageBoxA(NULL, msg.c_str(), title.c_str(), MB_OK); + TUChar szText[256] = { 0 }; + TUString::StrUtf8ToStrUnicode(szText,(Char*)msg.c_str()); + TMessageBox box(szText, NULL, WMB_OK); + box.Show(); } class BitmapDC