MCPcopy Create free account
hub / github.com/diasurgical/devilution / Compress_PKLIB

Function Compress_PKLIB

3rdParty/StormLib/src/SCompression.cpp:237–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

235}
236
237static void Compress_PKLIB(void * pvOutBuffer, int * pcbOutBuffer, void * pvInBuffer, int cbInBuffer, int * pCmpType, int nCmpLevel)
238{
239 TDataInfo Info; // Data information
240 char * work_buf = STORM_ALLOC(char, CMP_BUFFER_SIZE);// Pklib's work buffer
241 unsigned int dict_size; // Dictionary size
242 unsigned int ctype = CMP_BINARY; // Compression type
243
244 // Keep compilers happy
245 STORMLIB_UNUSED(pCmpType);
246 STORMLIB_UNUSED(nCmpLevel);
247
248 // Handle no-memory condition
249 if(work_buf != NULL)
250 {
251 // Fill data information structure
252 memset(work_buf, 0, CMP_BUFFER_SIZE);
253 Info.pbInBuff = (unsigned char *)pvInBuffer;
254 Info.pbInBuffEnd = (unsigned char *)pvInBuffer + cbInBuffer;
255 Info.pbOutBuff = (unsigned char *)pvOutBuffer;
256 Info.pbOutBuffEnd = (unsigned char *)pvOutBuffer + *pcbOutBuffer;
257
258 //
259 // Set the dictionary size
260 //
261 // Diablo I uses fixed dictionary size of CMP_IMPLODE_DICT_SIZE3
262 // Starcraft I uses the variable dictionary size based on algorithm below
263 //
264
265 if (cbInBuffer < 0x600)
266 dict_size = CMP_IMPLODE_DICT_SIZE1;
267 else if(0x600 <= cbInBuffer && cbInBuffer < 0xC00)
268 dict_size = CMP_IMPLODE_DICT_SIZE2;
269 else
270 dict_size = CMP_IMPLODE_DICT_SIZE3;
271
272 // Do the compression
273 if(implode(ReadInputData, WriteOutputData, work_buf, &Info, &ctype, &dict_size) == CMP_NO_ERROR)
274 *pcbOutBuffer = (int)(Info.pbOutBuff - (unsigned char *)pvOutBuffer);
275
276 STORM_FREE(work_buf);
277 }
278}
279
280static int Decompress_PKLIB(void * pvOutBuffer, int * pcbOutBuffer, void * pvInBuffer, int cbInBuffer)
281{

Callers 1

SCompImplodeFunction · 0.85

Calls 1

implodeFunction · 0.85

Tested by

no test coverage detected