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

Function DecodeLit

3rdParty/PKWare/explode.cpp:270–354  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

268// 0x306: Error
269
270static unsigned int PKWAREAPI DecodeLit(TDcmpStruct * pWork)
271{
272 unsigned int extra_length_bits; // Number of bits of extra literal length
273 unsigned int length_code; // Length code
274 unsigned int value;
275
276 // Test the current bit in byte buffer. If is not set, simply return the next 8 bits.
277 if(pWork->bit_buff & 1)
278 {
279 // Remove one bit from the input data
280 if(WasteBits(pWork, 1))
281 return 0x306;
282
283 // The next 8 bits hold the index to the length code table
284 length_code = pWork->LengthCodes[pWork->bit_buff & 0xFF];
285
286 // Remove the apropriate number of bits
287 if(WasteBits(pWork, pWork->LenBits[length_code]))
288 return 0x306;
289
290 // Are there some extra bits for the obtained length code ?
291 if((extra_length_bits = pWork->ExLenBits[length_code]) != 0)
292 {
293 unsigned int extra_length = pWork->bit_buff & ((1 << extra_length_bits) - 1);
294
295 if(WasteBits(pWork, extra_length_bits))
296 {
297 if((length_code + extra_length) != 0x10E)
298 return 0x306;
299 }
300 length_code = pWork->LenBase[length_code] + extra_length;
301 }
302
303 // In order to distinguish uncompressed byte from repetition length,
304 // we have to add 0x100 to the length.
305 return length_code + 0x100;
306 }
307
308 // Remove one bit from the input data
309 if(WasteBits(pWork, 1))
310 return 0x306;
311
312 // If the binary compression type, read 8 bits and return them as one byte.
313 if(pWork->ctype == CMP_BINARY)
314 {
315 unsigned int uncompressed_byte = pWork->bit_buff & 0xFF;
316
317 if(WasteBits(pWork, 8))
318 return 0x306;
319 return uncompressed_byte;
320 }
321
322 // When ASCII compression ...
323 if(pWork->bit_buff & 0xFF)
324 {
325 value = pWork->offs2C34[pWork->bit_buff & 0xFF];
326
327 if(value == 0xFF)

Callers 1

ExpandFunction · 0.85

Calls 1

WasteBitsFunction · 0.85

Tested by

no test coverage detected