[uphone]Support read image file from zip file.

This commit is contained in:
natural-law 2011-02-17 16:16:50 +08:00
parent e4063fd190
commit 8035fc366c
6 changed files with 32 additions and 32 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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;

View File

@ -115,7 +115,6 @@ public:
protected:
bool _initWithJpgData(void * pData, int nDatalen);
bool _initWithJpgFile(const char * strPath);
bool _initWithPngData(void * pData, int nDatalen);
ccxScopedArray<ccxByte> m_pData;

View File

@ -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;
}

View File

@ -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