Merge pull request #3414 from boyu0/iss2522_unpackccz

closed #2522: Let Image::initWithImageData() support the packed data.
This commit is contained in:
minggo 2013-08-15 21:44:43 -07:00
commit 77f89956a3
4 changed files with 183 additions and 165 deletions

View File

@ -47,7 +47,7 @@ static Texture2D* getDefaultTexture()
pImage = new Image();
CC_BREAK_IF(NULL == pImage);
bRet = pImage->initWithImageData((void*)__firePngData, sizeof(__firePngData));
bRet = pImage->initWithImageData(__firePngData, sizeof(__firePngData));
CC_BREAK_IF(!bRet);
texture = TextureCache::getInstance()->addUIImage(pImage, key);

View File

@ -109,10 +109,10 @@ public:
@param dataLen data length expressed in (number of) bytes.
@return true if loaded correctly.
*/
bool initWithImageData(const void * data, int dataLen);
bool initWithImageData(const unsigned char * data, int dataLen);
// @warning kFmtRawData only support RGBA8888
bool initWithRawData(const void * data, int dataLen, int width, int height, int bitsPerComponent, bool preMulti = false);
bool initWithRawData(const unsigned char * data, int dataLen, int width, int height, int bitsPerComponent, bool preMulti = false);
/**
@brief Create image with specified string.
@ -185,15 +185,15 @@ public:
protected:
bool initWithJpgData(const void *data, int dataLen);
bool initWithPngData(const void *data, int dataLen);
bool initWithTiffData(const void *data, int dataLen);
bool initWithWebpData(const void *data, int dataLen);
bool initWithPVRData(const void *data, int dataLen);
bool initWithPVRv2Data(const void *data, int dataLen);
bool initWithPVRv3Data(const void *data, int dataLen);
bool initWithETCData(const void *data, int dataLen);
bool initWithS3TCData(const void *data, int dataLen);
bool initWithJpgData(const unsigned char * data, int dataLen);
bool initWithPngData(const unsigned char * data, int dataLen);
bool initWithTiffData(const unsigned char * data, int dataLen);
bool initWithWebpData(const unsigned char * data, int dataLen);
bool initWithPVRData(const unsigned char * data, int dataLen);
bool initWithPVRv2Data(const unsigned char * data, int dataLen);
bool initWithPVRv3Data(const unsigned char * data, int dataLen);
bool initWithETCData(const unsigned char * data, int dataLen);
bool initWithS3TCData(const unsigned char * data, int dataLen);
bool saveImageToPNG(const char *filePath, bool isToRGB = true);
bool saveImageToJPG(const char *filePath);
@ -231,14 +231,14 @@ private:
*/
bool initWithImageFileThreadSafe(const char *fullpath);
Format detectFormat(const void* data, int dataLen);
bool isPng(const void *data, int dataLen);
bool isJpg(const void *data, int dataLen);
bool isTiff(const void *data, int dataLen);
bool isWebp(const void *data, int dataLen);
bool isPvr(const void *data, int dataLen);
bool isEtc(const void *data, int dataLen);
bool isS3TC(const void *data,int dataLen);
Format detectFormat(const unsigned char * data, int dataLen);
bool isPng(const unsigned char * data, int dataLen);
bool isJpg(const unsigned char * data, int dataLen);
bool isTiff(const unsigned char * data, int dataLen);
bool isWebp(const unsigned char * data, int dataLen);
bool isPvr(const unsigned char * data, int dataLen);
bool isEtc(const unsigned char * data, int dataLen);
bool isS3TC(const unsigned char * data,int dataLen);
};

View File

@ -70,7 +70,8 @@ namespace
static const int PVR_TEXTURE_FLAG_TYPE_MASK = 0xff;
// Values taken from PVRTexture.h from http://www.imgtec.com
enum class PVR2TextureFlag{
enum class PVR2TextureFlag
{
Mipmap = (1<<8), // has mip map levels
Twiddle = (1<<9), // is twiddled
Bumpmap = (1<<10), // has normals encoded for a bump map
@ -104,113 +105,114 @@ namespace
PVRTC4BPP_RGBA,
BGRA8888,
A8,
};
};
// v3
enum class PVR3TexturePixelFormat : uint64_t
{
PVRTC2BPP_RGB = 0ULL,
PVRTC2BPP_RGBA = 1ULL,
PVRTC4BPP_RGB = 2ULL,
PVRTC4BPP_RGBA = 3ULL,
// v3
enum class PVR3TexturePixelFormat : uint64_t
{
PVRTC2BPP_RGB = 0ULL,
PVRTC2BPP_RGBA = 1ULL,
PVRTC4BPP_RGB = 2ULL,
PVRTC4BPP_RGBA = 3ULL,
BGRA8888 = 0x0808080861726762ULL,
RGBA8888 = 0x0808080861626772ULL,
RGBA4444 = 0x0404040461626772ULL,
RGBA5551 = 0x0105050561626772ULL,
RGB565 = 0x0005060500626772ULL,
RGB888 = 0x0008080800626772ULL,
A8 = 0x0000000800000061ULL,
L8 = 0x000000080000006cULL,
LA88 = 0x000008080000616cULL,
};
BGRA8888 = 0x0808080861726762ULL,
RGBA8888 = 0x0808080861626772ULL,
RGBA4444 = 0x0404040461626772ULL,
RGBA5551 = 0x0105050561626772ULL,
RGB565 = 0x0005060500626772ULL,
RGB888 = 0x0008080800626772ULL,
A8 = 0x0000000800000061ULL,
L8 = 0x000000080000006cULL,
LA88 = 0x000008080000616cULL,
};
// v2
typedef const std::map<PVR2TexturePixelFormat, Texture2D::PixelFormat> _pixel2_formathash;
static const _pixel2_formathash::value_type v2_pixel_formathash_value[] =
{
_pixel2_formathash::value_type(PVR2TexturePixelFormat::BGRA8888, Texture2D::PixelFormat::BGRA8888),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA8888, Texture2D::PixelFormat::RGBA8888),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA4444, Texture2D::PixelFormat::RGBA4444),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA5551, Texture2D::PixelFormat::RGB5A1),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::RGB565, Texture2D::PixelFormat::RGB565),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::RGB888, Texture2D::PixelFormat::RGB888),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::A8, Texture2D::PixelFormat::A8),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::I8, Texture2D::PixelFormat::I8),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::AI88, Texture2D::PixelFormat::AI88),
// v2
typedef const std::map<PVR2TexturePixelFormat, Texture2D::PixelFormat> _pixel2_formathash;
static const _pixel2_formathash::value_type v2_pixel_formathash_value[] =
{
_pixel2_formathash::value_type(PVR2TexturePixelFormat::BGRA8888, Texture2D::PixelFormat::BGRA8888),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA8888, Texture2D::PixelFormat::RGBA8888),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA4444, Texture2D::PixelFormat::RGBA4444),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA5551, Texture2D::PixelFormat::RGB5A1),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::RGB565, Texture2D::PixelFormat::RGB565),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::RGB888, Texture2D::PixelFormat::RGB888),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::A8, Texture2D::PixelFormat::A8),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::I8, Texture2D::PixelFormat::I8),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::AI88, Texture2D::PixelFormat::AI88),
#ifdef GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG
_pixel2_formathash::value_type(PVR2TexturePixelFormat::PVRTC2BPP_RGBA, Texture2D::PixelFormat::PVRTC2A),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::PVRTC4BPP_RGBA, Texture2D::PixelFormat::PVRTC4A),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::PVRTC2BPP_RGBA, Texture2D::PixelFormat::PVRTC2A),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::PVRTC4BPP_RGBA, Texture2D::PixelFormat::PVRTC4A),
#endif
};
};
static const int PVR2_MAX_TABLE_ELEMENTS = sizeof(v2_pixel_formathash_value) / sizeof(v2_pixel_formathash_value[0]);
static const _pixel2_formathash v2_pixel_formathash(v2_pixel_formathash_value, v2_pixel_formathash_value + PVR2_MAX_TABLE_ELEMENTS);
static const int PVR2_MAX_TABLE_ELEMENTS = sizeof(v2_pixel_formathash_value) / sizeof(v2_pixel_formathash_value[0]);
static const _pixel2_formathash v2_pixel_formathash(v2_pixel_formathash_value, v2_pixel_formathash_value + PVR2_MAX_TABLE_ELEMENTS);
// v3
typedef const std::map<PVR3TexturePixelFormat, Texture2D::PixelFormat> _pixel3_formathash;
static _pixel3_formathash::value_type v3_pixel_formathash_value[] =
{
_pixel3_formathash::value_type(PVR3TexturePixelFormat::BGRA8888, Texture2D::PixelFormat::BGRA8888),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA8888, Texture2D::PixelFormat::RGBA8888),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA4444, Texture2D::PixelFormat::RGBA4444),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA5551, Texture2D::PixelFormat::RGB5A1),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::RGB565, Texture2D::PixelFormat::RGB565),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::RGB888, Texture2D::PixelFormat::RGB888),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::A8, Texture2D::PixelFormat::A8),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::L8, Texture2D::PixelFormat::I8),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::LA88, Texture2D::PixelFormat::AI88),
// v3
typedef const std::map<PVR3TexturePixelFormat, Texture2D::PixelFormat> _pixel3_formathash;
static _pixel3_formathash::value_type v3_pixel_formathash_value[] =
{
_pixel3_formathash::value_type(PVR3TexturePixelFormat::BGRA8888, Texture2D::PixelFormat::BGRA8888),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA8888, Texture2D::PixelFormat::RGBA8888),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA4444, Texture2D::PixelFormat::RGBA4444),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA5551, Texture2D::PixelFormat::RGB5A1),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::RGB565, Texture2D::PixelFormat::RGB565),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::RGB888, Texture2D::PixelFormat::RGB888),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::A8, Texture2D::PixelFormat::A8),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::L8, Texture2D::PixelFormat::I8),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::LA88, Texture2D::PixelFormat::AI88),
#ifdef GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG
_pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC2BPP_RGB, Texture2D::PixelFormat::PVRTC2),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC2BPP_RGBA, Texture2D::PixelFormat::PVRTC2A),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC4BPP_RGB, Texture2D::PixelFormat::PVRTC4),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC4BPP_RGBA, Texture2D::PixelFormat::PVRTC4A),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC2BPP_RGB, Texture2D::PixelFormat::PVRTC2),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC2BPP_RGBA, Texture2D::PixelFormat::PVRTC2A),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC4BPP_RGB, Texture2D::PixelFormat::PVRTC4),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC4BPP_RGBA, Texture2D::PixelFormat::PVRTC4A),
#endif
};
};
static const int PVR3_MAX_TABLE_ELEMENTS = sizeof(v3_pixel_formathash_value) / sizeof(v3_pixel_formathash_value[0]);
static const int PVR3_MAX_TABLE_ELEMENTS = sizeof(v3_pixel_formathash_value) / sizeof(v3_pixel_formathash_value[0]);
static const _pixel3_formathash v3_pixel_formathash(v3_pixel_formathash_value, v3_pixel_formathash_value + PVR3_MAX_TABLE_ELEMENTS);
static const _pixel3_formathash v3_pixel_formathash(v3_pixel_formathash_value, v3_pixel_formathash_value + PVR3_MAX_TABLE_ELEMENTS);
typedef struct _PVRTexHeader
{
unsigned int headerLength;
unsigned int height;
unsigned int width;
unsigned int numMipmaps;
unsigned int flags;
unsigned int dataLength;
unsigned int bpp;
unsigned int bitmaskRed;
unsigned int bitmaskGreen;
unsigned int bitmaskBlue;
unsigned int bitmaskAlpha;
unsigned int pvrTag;
unsigned int numSurfs;
} PVRv2TexHeader;
typedef struct _PVRTexHeader
{
unsigned int headerLength;
unsigned int height;
unsigned int width;
unsigned int numMipmaps;
unsigned int flags;
unsigned int dataLength;
unsigned int bpp;
unsigned int bitmaskRed;
unsigned int bitmaskGreen;
unsigned int bitmaskBlue;
unsigned int bitmaskAlpha;
unsigned int pvrTag;
unsigned int numSurfs;
} PVRv2TexHeader;
#ifdef _MSC_VER
#pragma pack(push,1)
#endif
typedef struct {
uint32_t version;
uint32_t flags;
uint64_t pixelFormat;
uint32_t colorSpace;
uint32_t channelType;
uint32_t height;
uint32_t width;
uint32_t depth;
uint32_t numberOfSurfaces;
uint32_t numberOfFaces;
uint32_t numberOfMipmaps;
uint32_t metadataLength;
typedef struct
{
uint32_t version;
uint32_t flags;
uint64_t pixelFormat;
uint32_t colorSpace;
uint32_t channelType;
uint32_t height;
uint32_t width;
uint32_t depth;
uint32_t numberOfSurfaces;
uint32_t numberOfFaces;
uint32_t numberOfMipmaps;
uint32_t metadataLength;
#ifdef _MSC_VER
} PVRv3TexHeader;
} PVRv3TexHeader;
#pragma pack(pop)
#else
} __attribute__((packed)) PVRv3TexHeader;
@ -319,7 +321,7 @@ namespace
{
typedef struct
{
unsigned char* data;
const unsigned char * data;
int size;
int offset;
}tImageSource;
@ -389,22 +391,9 @@ bool Image::initWithImageFile(const char * strPath)
SDL_FreeSurface(iSurf);
#else
unsigned long bufferLen = 0;
unsigned char* buffer = nullptr;
//detecgt and unzip the compress file
if (ZipUtils::ccIsCCZFile(fullPath.c_str()))
{
bufferLen = ZipUtils::ccInflateCCZFile(fullPath.c_str(), &buffer);
}else if (ZipUtils::ccIsGZipFile(fullPath.c_str()))
{
bufferLen = ZipUtils::ccInflateGZipFile(fullPath.c_str(), &buffer);
}
else
{
buffer = FileUtils::getInstance()->getFileData(fullPath.c_str(), "rb", &bufferLen);
}
unsigned char* buffer = FileUtils::getInstance()->getFileData(fullPath.c_str(), "rb", &bufferLen);
if (buffer != NULL && bufferLen > 0)
if (buffer != nullptr && bufferLen > 0)
{
bRet = initWithImageData(buffer, bufferLen);
}
@ -433,41 +422,70 @@ bool Image::initWithImageFileThreadSafe(const char *fullpath)
return bRet;
}
bool Image::initWithImageData(const void * data, int dataLen)
bool Image::initWithImageData(const unsigned char * data, int dataLen)
{
do
bool ret = false;
do
{
CC_BREAK_IF(! data || dataLen <= 0);
unsigned char* unpackedData = nullptr;
int unpackedLen = 0;
//detecgt and unzip the compress file
if (ZipUtils::ccIsCCZBuffer(data, dataLen))
{
unpackedLen = ZipUtils::ccInflateCCZBuffer(data, dataLen, &unpackedData);
}else if (ZipUtils::ccIsGZipBuffer(data, dataLen))
{
unpackedLen = ZipUtils::ccInflateMemory(const_cast<unsigned char*>(data), dataLen, &unpackedData);
}else
{
unpackedData = const_cast<unsigned char*>(data);
unpackedLen = dataLen;
}
_fileType = detectFormat(data, dataLen);
_fileType = detectFormat(unpackedData, unpackedLen);
switch (_fileType)
{
case Format::PNG:
return initWithPngData(data, dataLen);
ret = initWithPngData(unpackedData, unpackedLen);
break;
case Format::JPG:
return initWithJpgData(data, dataLen);
ret = initWithJpgData(unpackedData, unpackedLen);
break;
case Format::TIFF:
return initWithTiffData(data, dataLen);
ret = initWithTiffData(unpackedData, unpackedLen);
break;
case Format::WEBP:
return initWithWebpData(data, dataLen);
ret = initWithWebpData(unpackedData, unpackedLen);
break;
case Format::PVR:
return initWithPVRData(data, dataLen);
ret = initWithPVRData(unpackedData, unpackedLen);
break;
case Format::ETC:
return initWithETCData(data, dataLen);
ret = initWithETCData(unpackedData, unpackedLen);
break;
case Format::S3TC:
return initWithS3TCData(data, dataLen);
ret = initWithS3TCData(unpackedData, unpackedLen);
break;
default:
CCAssert(false, "unsupport image format!");
return false;
break;
}
if(unpackedData != data)
{
free(unpackedData);
}
} while (0);
return false;
return ret;
}
bool Image::isPng(const void *data, int dataLen)
bool Image::isPng(const unsigned char * data, int dataLen)
{
if (dataLen <= 8)
{
@ -480,13 +498,13 @@ bool Image::isPng(const void *data, int dataLen)
}
bool Image::isEtc(const void *data, int dataLen)
bool Image::isEtc(const unsigned char * data, int dataLen)
{
return etc1_pkm_is_valid((etc1_byte*)data) ? true : false;
}
bool Image::isS3TC(const void *data, int dataLen)
bool Image::isS3TC(const unsigned char * data, int dataLen)
{
S3TCTexHeader *header = (S3TCTexHeader *)data;
@ -499,7 +517,7 @@ bool Image::isS3TC(const void *data, int dataLen)
return true;
}
bool Image::isJpg(const void *data, int dataLen)
bool Image::isJpg(const unsigned char * data, int dataLen)
{
if (dataLen <= 4)
{
@ -511,7 +529,7 @@ bool Image::isJpg(const void *data, int dataLen)
return memcmp(data, JPG_SOI, 2) == 0;
}
bool Image::isTiff(const void *data, int dataLen)
bool Image::isTiff(const unsigned char * data, int dataLen)
{
if (dataLen <= 4)
{
@ -525,7 +543,7 @@ bool Image::isTiff(const void *data, int dataLen)
(memcmp(data, TIFF_MM, 2) == 0 && *(static_cast<const unsigned char*>(data) + 2) == 0 && *(static_cast<const unsigned char*>(data) + 3) == 42);
}
bool Image::isWebp(const void *data, int dataLen)
bool Image::isWebp(const unsigned char * data, int dataLen)
{
if (dataLen <= 12)
{
@ -539,21 +557,21 @@ bool Image::isWebp(const void *data, int dataLen)
&& memcmp(static_cast<const unsigned char*>(data) + 8, WEBP_WEBP, 4) == 0;
}
bool Image::isPvr(const void *data, int dataLen)
bool Image::isPvr(const unsigned char * data, int dataLen)
{
if (dataLen < sizeof(PVRv2TexHeader) || dataLen < sizeof(PVRv3TexHeader))
{
return false;
}
const PVRv2TexHeader* headerv2 = static_cast<const PVRv2TexHeader*>(data);
const PVRv3TexHeader* headerv3 = static_cast<const PVRv3TexHeader*>(data);
const PVRv2TexHeader* headerv2 = static_cast<const PVRv2TexHeader*>(static_cast<const void*>(data));
const PVRv3TexHeader* headerv3 = static_cast<const PVRv3TexHeader*>(static_cast<const void*>(data));
return memcmp(&headerv2->pvrTag, gPVRTexIdentifier, strlen(gPVRTexIdentifier)) == 0 || CC_SWAP_INT32_BIG_TO_HOST(headerv3->version) == 0x50565203;
}
Image::Format Image::detectFormat(const void* data, int dataLen)
Image::Format Image::detectFormat(const unsigned char * data, int dataLen)
{
if (isPng(data, dataLen))
{
@ -655,7 +673,7 @@ namespace
}
}
bool Image::initWithJpgData(const void * data, int dataLen)
bool Image::initWithJpgData(const unsigned char * data, int dataLen)
{
/* these are standard libjpeg structures for reading(decompression) */
struct jpeg_decompress_struct cinfo;
@ -688,7 +706,7 @@ bool Image::initWithJpgData(const void * data, int dataLen)
jpeg_create_decompress( &cinfo );
#ifndef CC_TARGET_QT5
jpeg_mem_src( &cinfo, (unsigned char *) data, dataLen );
jpeg_mem_src( &cinfo, const_cast<unsigned char*>(data), dataLen );
#endif /* CC_TARGET_QT5 */
/* reading the image header which contains image information */
@ -713,8 +731,8 @@ bool Image::initWithJpgData(const void * data, int dataLen)
jpeg_start_decompress( &cinfo );
/* init image info */
_width = (short)(cinfo.output_width);
_height = (short)(cinfo.output_height);
_width = cinfo.output_width;
_height = cinfo.output_height;
_preMulti = false;
row_pointer[0] = new unsigned char[cinfo.output_width*cinfo.output_components];
CC_BREAK_IF(! row_pointer[0]);
@ -749,7 +767,7 @@ bool Image::initWithJpgData(const void * data, int dataLen)
return bRet;
}
bool Image::initWithPngData(const void * data, int dataLen)
bool Image::initWithPngData(const unsigned char * data, int dataLen)
{
// length of bytes to check if it is a valid png file
#define PNGSIGSIZE 8
@ -990,14 +1008,14 @@ namespace
}
}
bool Image::initWithTiffData(const void* data, int dataLen)
bool Image::initWithTiffData(const unsigned char * data, int dataLen)
{
bool bRet = false;
do
{
// set the read call back function
tImageSource imageSource;
imageSource.data = (unsigned char*)data;
imageSource.data = data;
imageSource.size = dataLen;
imageSource.offset = 0;
@ -1084,14 +1102,14 @@ namespace
}
}
bool Image::initWithPVRv2Data(const void *data, int dataLen)
bool Image::initWithPVRv2Data(const unsigned char * data, int dataLen)
{
int dataLength = 0, dataOffset = 0, dataSize = 0;
int blockSize = 0, widthBlocks = 0, heightBlocks = 0;
int width = 0, height = 0;
//Cast first sizeof(PVRTexHeader) bytes of data stream as PVRTexHeader
const PVRv2TexHeader *header = static_cast<const PVRv2TexHeader *>(data);
const PVRv2TexHeader *header = static_cast<const PVRv2TexHeader *>(static_cast<const void*>(data));
//Make sure that tag is in correct formatting
if (memcmp(&header->pvrTag, gPVRTexIdentifier, strlen(gPVRTexIdentifier)) != 0)
@ -1210,14 +1228,14 @@ bool Image::initWithPVRv2Data(const void *data, int dataLen)
return true;
}
bool Image::initWithPVRv3Data(const void *data, int dataLen)
bool Image::initWithPVRv3Data(const unsigned char * data, int dataLen)
{
if (dataLen < sizeof(PVRv3TexHeader))
{
return false;
}
const PVRv3TexHeader *header = static_cast<const PVRv3TexHeader *>(data);
const PVRv3TexHeader *header = static_cast<const PVRv3TexHeader *>(static_cast<const void*>(data));
// validate version
if (CC_SWAP_INT32_BIG_TO_HOST(header->version) != 0x50565203)
@ -1336,7 +1354,7 @@ bool Image::initWithPVRv3Data(const void *data, int dataLen)
return true;
}
bool Image::initWithETCData(const void *data, int dataLen)
bool Image::initWithETCData(const unsigned char * data, int dataLen)
{
const etc1_byte* header = static_cast<const etc1_byte*>(data);
@ -1396,7 +1414,7 @@ namespace
}
}
bool Image::initWithS3TCData(const void *data, int dataLen)
bool Image::initWithS3TCData(const unsigned char * data, int dataLen)
{
const uint32_t FOURCC_DXT1 = makeFourCC('D', 'X', 'T', '1');
@ -1407,7 +1425,7 @@ bool Image::initWithS3TCData(const void *data, int dataLen)
S3TCTexHeader *header = (S3TCTexHeader *)data;
unsigned char *pixelData = new unsigned char [dataLen - sizeof(S3TCTexHeader)];
memcpy((void *)pixelData, (unsigned char*)data + sizeof(S3TCTexHeader), dataLen - sizeof(S3TCTexHeader));
memcpy((void *)pixelData, data + sizeof(S3TCTexHeader), dataLen - sizeof(S3TCTexHeader));
_width = header->ddsd.width;
_height = header->ddsd.height;
@ -1513,12 +1531,12 @@ bool Image::initWithS3TCData(const void *data, int dataLen)
return true;
}
bool Image::initWithPVRData(const void *data, int dataLen)
bool Image::initWithPVRData(const unsigned char * data, int dataLen)
{
return initWithPVRv2Data(data, dataLen) || initWithPVRv3Data(data, dataLen);
}
bool Image::initWithWebpData(const void *data, int dataLen)
bool Image::initWithWebpData(const unsigned char * data, int dataLen)
{
bool bRet = false;
do
@ -1553,7 +1571,7 @@ bool Image::initWithWebpData(const void *data, int dataLen)
return bRet;
}
bool Image::initWithRawData(const void * data, int dataLen, int width, int height, int bitsPerComponent, bool preMulti)
bool Image::initWithRawData(const unsigned char * data, int dataLen, int width, int height, int bitsPerComponent, bool preMulti)
{
bool bRet = false;
do

View File

@ -653,7 +653,7 @@ void VolatileTexture::reloadAllTextures()
unsigned long nSize = 0;
unsigned char* pBuffer = FileUtils::getInstance()->getFileData(vt->_fileName.c_str(), "rb", &nSize);
if (pImage && pImage->initWithImageData((void*)pBuffer, nSize))
if (pImage && pImage->initWithImageData(pBuffer, nSize))
{
Texture2D::PixelFormat oldPixelFormat = Texture2D::getDefaultAlphaPixelFormat();
Texture2D::setDefaultAlphaPixelFormat(vt->_pixelFormat);