mirror of https://github.com/axmolengine/axmol.git
issue #1557: Fixed particle crash.We should check the file format by the file header when the format isn't defined.
This commit is contained in:
parent
c79cac3af6
commit
a3437d09df
|
@ -552,27 +552,77 @@ bool CCImage::initWithImageData(void * pData,
|
|||
int nHeight,
|
||||
int nBitsPerComponent)
|
||||
{
|
||||
bool bRet = false;
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(! pData || nDataLen <= 0);
|
||||
|
||||
if (kFmtPng == eFmt)
|
||||
{
|
||||
bRet = _initWithPngData(pData, nDataLen);
|
||||
break;
|
||||
}
|
||||
else if (kFmtJpg == eFmt)
|
||||
{
|
||||
bRet = _initWithJpgData(pData, nDataLen);
|
||||
break;
|
||||
}
|
||||
else if (kFmtTiff == eFmt)
|
||||
{
|
||||
bRet = _initWithTiffData(pData, nDataLen);
|
||||
break;
|
||||
}
|
||||
} while (0);
|
||||
bool bRet = false;
|
||||
do
|
||||
{
|
||||
CC_BREAK_IF(! pData || nDataLen <= 0);
|
||||
|
||||
if (kFmtPng == eFmt)
|
||||
{
|
||||
bRet = _initWithPngData(pData, nDataLen);
|
||||
break;
|
||||
}
|
||||
else if (kFmtJpg == eFmt)
|
||||
{
|
||||
bRet = _initWithJpgData(pData, nDataLen);
|
||||
break;
|
||||
}
|
||||
else if (kFmtTiff == eFmt)
|
||||
{
|
||||
bRet = _initWithTiffData(pData, nDataLen);
|
||||
break;
|
||||
}
|
||||
else if (kFmtRawData == eFmt)
|
||||
{
|
||||
bRet = _initWithRawData(pData, nDataLen, nWidth, nHeight, nBitsPerComponent);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// if it is a png file buffer.
|
||||
if (nDataLen > 8)
|
||||
{
|
||||
unsigned char* pHead = (unsigned char*)pData;
|
||||
if ( pHead[0] == 0x89
|
||||
&& pHead[1] == 0x50
|
||||
&& pHead[2] == 0x4E
|
||||
&& pHead[3] == 0x47
|
||||
&& pHead[4] == 0x0D
|
||||
&& pHead[5] == 0x0A
|
||||
&& pHead[6] == 0x1A
|
||||
&& pHead[7] == 0x0A)
|
||||
{
|
||||
bRet = _initWithPngData(pData, nDataLen);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if it is a tiff file buffer.
|
||||
if (nDataLen > 2)
|
||||
{
|
||||
unsigned char* pHead = (unsigned char*)pData;
|
||||
if ( (pHead[0] == 0x49 && pHead[1] == 0x49)
|
||||
|| (pHead[0] == 0x4d && pHead[1] == 0x4d)
|
||||
)
|
||||
{
|
||||
bRet = _initWithTiffData(pData, nDataLen);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if it is a jpeg file buffer.
|
||||
if (nDataLen > 2)
|
||||
{
|
||||
unsigned char* pHead = (unsigned char*)pData;
|
||||
if ( pHead[0] == 0xff
|
||||
&& pHead[1] == 0xd8)
|
||||
{
|
||||
bRet = _initWithJpgData(pData, nDataLen);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
return bRet;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue