pvr.ccz 是把pvr用zlib算法壓縮後的圖像格式,其優勢是能夠提高文件讀取效率。 c++
大多數狀況下咱們能夠用一些工具來將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; }