pvr.ccz 是把pvr用zlib算法压缩后的图像格式,其优点是可以提升文件读取效率。
大多数情况下我们可以用一些工具来将pvr压缩到pvr.ccz ,下面提供一个c++方法来完成这个过程
int CompressPvrToCCZFile(unsigned char *buffer,unsigned int fileLength, const char *newFilePath) {
//buffer pvr文件二进制数据,fileLength 文件长度,newFilePath 保存地址 unsigned long bufferSize = fileLength; char* DestBuffer=new char[(uInt)bufferSize];memset(DestBuffer, 0, bufferSize); errno_t err; //错误变量的定义 err = compress((Bytef*)DestBuffer,(uLongf*)&bufferSize,(const Bytef*)buffer,(uLongf)fileLength); // CCZHeader header; header.version = 256; header.len = ((fileLength & 0x000000ff) >> 24 | (fileLength & 0x0000ff00) >> 8 | (fileLength & 0x00ff0000) << 8 | (fileLength & 0xff000000) << 24); header.compression_type = CCZ_COMPRESSION_ZLIB; header.sig[0] = 'C'; header.sig[1] = 'C'; header.sig[2] = 'Z'; header.sig[3] = '!'; //保存文件 FILE *fp = fopen(newFilePath, "wb+"); if (!fp) { delete []DestBuffer; return -1; } fwrite(&header, sizeof(header), 1, fp); fwrite(DestBuffer, bufferSize, 1, fp); fclose(fp); delete []DestBuffer; return 1; }