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

Function DecodeDist

3rdParty/PKWare/explode.cpp:360–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

358// current output buffer position
359
360static unsigned int PKWAREAPI DecodeDist(TDcmpStruct * pWork, unsigned int rep_length)
361{
362 unsigned int dist_pos_code; // Distance position code
363 unsigned int dist_pos_bits; // Number of bits of distance position
364 unsigned int distance; // Distance position
365
366 // Next 2-8 bits in the input buffer is the distance position code
367 dist_pos_code = pWork->DistPosCodes[pWork->bit_buff & 0xFF];
368 dist_pos_bits = pWork->DistBits[dist_pos_code];
369 if(WasteBits(pWork, dist_pos_bits))
370 return 0;
371
372 if(rep_length == 2)
373 {
374 // If the repetition is only 2 bytes length,
375 // then take 2 bits from the stream in order to get the distance
376 distance = (dist_pos_code << 2) | (pWork->bit_buff & 0x03);
377 if(WasteBits(pWork, 2))
378 return 0;
379 }
380 else
381 {
382 // If the repetition is more than 2 bytes length,
383 // then take "dsize_bits" bits in order to get the distance
384 distance = (dist_pos_code << pWork->dsize_bits) | (pWork->bit_buff & pWork->dsize_mask);
385 if(WasteBits(pWork, pWork->dsize_bits))
386 return 0;
387 }
388 return distance + 1;
389}
390
391static unsigned int PKWAREAPI Expand(TDcmpStruct * pWork)
392{

Callers 1

ExpandFunction · 0.85

Calls 1

WasteBitsFunction · 0.85

Tested by

no test coverage detected