Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Burger::DecompressDeflate Class Reference

Decompress Deflate format. More...

Inheritance diagram for Burger::DecompressDeflate:
Inheritance graph
[legend]
Collaboration diagram for Burger::DecompressDeflate:
Collaboration graph
[legend]

Classes

struct  DeflateHuft_t
 Deflate huffman tree definition. More...
 

Public Member Functions

const Burger::StaticRTTIget_StaticRTTI (void) const noexcept override
 Get the description to the class.
 
 DecompressDeflate ()
 Default constructor.
 
virtual ~DecompressDeflate ()
 Release any allocated memory.
 
eError Reset (void) override
 Reset the decompressor.
 
eError Process (void *pOutput, uintptr_t uOutputChunkLength, const void *pInput, uintptr_t uInputChunkLength) override
 Decompress data using Deflate compression.
 
- Public Member Functions inherited from Burger::Decompress
 Decompress (void)
 Default constructor.
 
uintptr_t GetTotalInputSize (void) const noexcept
 Get the total processed input data in bytes.
 
uintptr_t GetTotalOutputSize (void) const noexcept
 Get the total processed output data in bytes.
 
uintptr_t GetProcessedInputSize (void) const noexcept
 Get the total processed output data in bytes from the last process pass.
 
uintptr_t GetProcessedOutputSize (void) const noexcept
 Get the total processed output data in bytes from the last process pass.
 
uint32_t GetSignature (void) const noexcept
 Return the signature for this decompressor.
 
- Public Member Functions inherited from Burger::Base
const char * get_class_name (void) const noexcept
 Get the name of the class.
 
virtual ~Base () noexcept=default
 Destructor.
 

Static Public Attributes

static const Burger::StaticRTTI g_StaticRTTI
 The global description of the class.
 
static const uint32_t Signature = 0x5A4C4942
 'ZLIB'
 
- Static Public Attributes inherited from Burger::Decompress
static const Burger::StaticRTTI g_StaticRTTI
 The global description of the class.
 
- Static Public Attributes inherited from Burger::Base
static const Burger::StaticRTTI g_StaticRTTI
 The global description of the class.
 

Protected Types

enum  eState {
  STATE_METHOD , STATE_FLAG , STATE_DICT4 , STATE_DICT3 ,
  STATE_DICT2 , STATE_DICT1 , STATE_DICT0 , STATE_BLOCKS ,
  STATE_CHECK4 , STATE_CHECK3 , STATE_CHECK2 , STATE_CHECK1 ,
  STATE_COMPLETE , STATE_ABORT
}
 
enum  eBlockMode {
  BLOCKMODE_TYPE , BLOCKMODE_LENS , BLOCKMODE_STORED , BLOCKMODE_TABLE ,
  BLOCKMODE_BTREE , BLOCKMODE_DTREE , BLOCKMODE_CODES , BLOCKMODE_DRY ,
  BLOCKMODE_COMPLETED , BLOCKMODE_ABORT
}
 
enum  eCodesMode {
  CODES_START , CODES_LEN , CODES_LENEXT , CODES_DIST ,
  CODES_DISTEXT , CODES_COPY , CODES_LITERAL , CODES_WASH ,
  CODES_END , CODES_ABORT
}
 
enum  {
  FIXED_BLOCKLENGTH =9 , FIXED_BLOCKDISTANCE =5 , MAX_WBITS =15 , MAXTREEDYNAMICSIZE =1440 ,
  PRESET_DICT =0x20 , Z_DEFLATED =8
}
 

Protected Member Functions

int Flush (int iErrorCode)
 Copy as much as possible from the sliding window to the output area.
 
int Fast (uint_t uBitLength, uint_t uBitDistance, const DeflateHuft_t *pHuffmanLength, const DeflateHuft_t *pHuffmanDistance)
 Optimized decompression code.
 
int ProcessCodes (int iErrorCode)
 Process the decompression codes.
 
void CodesReset (uint_t bCodeLengthBits, uint_t bCodeDistanceBits, const DeflateHuft_t *pCodeTreeLength, const DeflateHuft_t *pCodeTreeDistance)
 Reset the code state.
 
void BlocksReset (void)
 Reset the decompression state.
 
int ProcessBlocks (int iErrorCode)
 Process the data blocks.
 

Static Protected Member Functions

static int BuildHuffmanTrees (const uint_t *pSampleCounts, uint_t uNumberSamples, uint_t uMaxSample, const uint_t *pDefaultLengths, const uint_t *pDefaultBits, DeflateHuft_t **ppNewTree, uint_t *pNewTreeSize, DeflateHuft_t *pExistingTree, uint_t *pHuffmanCount, uint_t *pWorkArea)
 Create a huffman tree.
 
static int TreesBits (const uint_t *pSampleCounts, uint_t *pNewTreeSize, DeflateHuft_t **ppNewTree, DeflateHuft_t *pExistingTree)
 Set the default huffman trees.
 
static int TreesDynamic (uint_t uNumberSamples, uint_t uNumberDistance, const uint_t *pSampleCounts, uint_t *pNewTreeSize, uint_t *pNewDistanceSize, DeflateHuft_t **ppNewTree, DeflateHuft_t **ppNewDistance, DeflateHuft_t *pExistingTree)
 Create the dynamic huffman tree.
 

Protected Attributes

const uint8_t * m_pInput
 Packed data pointer.
 
uint8_t * m_pOutput
 Output data pointer.
 
const uint8_t * m_pWindowRead
 Window read pointer.
 
uint8_t * m_pWindowWrite
 Window write pointer.
 
const DeflateHuft_tm_pCodeTree
 Pointer into tree.
 
const DeflateHuft_tm_pCodeTreeLength
 Pointer to literal/length/eob tree.
 
const DeflateHuft_tm_pCodeTreeDistance
 Pointer distance tree.
 
uint_tm_pTreesLengths
 Pointer to bit lengths of codes.
 
DeflateHuft_tm_pTreesHuffman
 Pointer to bit length decoding tree.
 
uintptr_t m_uInputChunkLength
 Number of packed bytes remaining.
 
uintptr_t m_uOutputChunkLength
 Number of bytes in the output buffer.
 
uintptr_t m_uStoredBytesToCopy
 If STORED, bytes left to copy.
 
eState m_eState
 State of the decompression.
 
eBlockMode m_eBlockMode
 Current decompression block mode.
 
eCodesMode m_eCodesMode
 Current inflate_codes mode.
 
uint32_t m_uChecksumOfChunk
 Computed checksum value of decompressed data.
 
uint32_t m_uChecksumInStream
 32 bit literal pulled from the big endian data stream (Must match DecompressDeflate::m_uChecksumInStream)
 
uint32_t m_uAlder32Checksum
 Checksum on output.
 
uint32_t m_uBitBucket
 Bit buffer.
 
uint_t m_uCompressionMethod
 Compression method type.
 
uint_t m_bLastBlock
 TRUE if this block is the last block.
 
uint_t m_uBitCount
 Bits in bit buffer.
 
uint_t m_uCodeLength
 Length in bits of the last code.
 
uint_t m_uCodeTreeNeed
 Bits needed.
 
uint_t m_uCodeLiteral
 Literal code fetched.
 
uint_t m_uCodeCopyGet
 Bits to get for extra token.
 
uint_t m_uCodeCopyDistance
 Distance back to copy from.
 
uint_t m_uTreesTable
 Table lengths (14 bits)
 
uint_t m_uTreesIndex
 Index into blends (or border)
 
uint_t m_uTreesDepth
 Bit length tree depth.
 
uint8_t m_bCodeLengthBits
 Length tree bits decoded per branch.
 
uint8_t m_bCodeDistanceBits
 Distance tree bits decoder per branch.
 
uint8_t m_WindowBuffer [1<< MAX_WBITS]
 Sliding window.
 
DeflateHuft_t m_HuffmanTable [MAXTREEDYNAMICSIZE]
 Single data chunk for tree space.
 
- Protected Attributes inherited from Burger::Decompress
uintptr_t m_uTotalInput
 Total number of bytes processed for input.
 
uintptr_t m_uTotalOutput
 Total number of bytes processed for output.
 
uintptr_t m_uInputLength
 Number of input bytes processed from the last call to Process()
 
uintptr_t m_uOutputLength
 Number of output bytes processed from the last call to Process()
 
uint32_t m_uSignature
 4 character code to identify this decompresser
 

Static Protected Attributes

static const DeflateHuft_t s_FixedTreeLiteral []
 Table for preset literal codes.
 
static const DeflateHuft_t s_FixedTreeDistance []
 Table for preset distance codes.
 

Detailed Description

Decompress Deflate format.


Decompress data in Deflate format which is the format used by ZLIB (Documented here Burger::CompressDeflate )

See also
Burger::Decompress and Burger::CompressDeflate

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected
Enumerator
FIXED_BLOCKLENGTH 

Length in 2^?? bits.

FIXED_BLOCKDISTANCE 

Distance in 2^?? bits.

MAX_WBITS 

Maximum bits for the depth of the huffman tree.

MAXTREEDYNAMICSIZE 

Maximum size of the dynamic tree.

PRESET_DICT 

Preset dictionary flag in zlib header.

Z_DEFLATED 

ZLib flag for deflation decompression.

◆ eBlockMode

Enumerator
BLOCKMODE_TYPE 

Get type bits (3, including end bit)

BLOCKMODE_LENS 

Get lengths for stored.

BLOCKMODE_STORED 

Processing stored block.

BLOCKMODE_TABLE 

Get table lengths.

BLOCKMODE_BTREE 

Get bit lengths tree for a dynamic block.

BLOCKMODE_DTREE 

Get length, distance trees for a dynamic block.

BLOCKMODE_CODES 

Processing fixed or dynamic block.

BLOCKMODE_DRY 

Output remaining window bytes.

BLOCKMODE_COMPLETED 

Block completed.

BLOCKMODE_ABORT 

Block aborted (Fatal)

◆ eCodesMode

Enumerator
CODES_START 

Set up for CODES_LEN.

CODES_LEN 

Input / Get length/literal/eob next.

CODES_LENEXT 

Input / Getting length extra (have base)

CODES_DIST 

Input / Get distance next.

CODES_DISTEXT 

Input / Getting distance extra.

CODES_COPY 

Output / Copying bytes in window, waiting for space.

CODES_LITERAL 

Output / Got literal, waiting for output space.

CODES_WASH 

Output / Got end of byte, possibly still output waiting.

CODES_END 

Got end of byte and all data flushed.

CODES_ABORT 

Aborted due to error.

◆ eState

Enumerator
STATE_METHOD 

Waiting for method byte.

STATE_FLAG 

Waiting for flag byte.

STATE_DICT4 

Four dictionary check bytes to go.

STATE_DICT3 

Three dictionary check bytes to go.

STATE_DICT2 

Two dictionary check bytes to go.

STATE_DICT1 

One dictionary check byte to go.

STATE_DICT0 

Waiting for inflateSetDictionary.

STATE_BLOCKS 

Decompressing blocks.

STATE_CHECK4 

Four check bytes to go.

STATE_CHECK3 

Three check bytes to go.

STATE_CHECK2 

Two check bytes to go.

STATE_CHECK1 

One check byte to go.

STATE_COMPLETE 

Decompression completed.

STATE_ABORT 

Decompression aborted (Fatal)

Constructor & Destructor Documentation

◆ DecompressDeflate()

Burger::DecompressDeflate::DecompressDeflate ( )

Default constructor.


◆ ~DecompressDeflate()

Burger::DecompressDeflate::~DecompressDeflate ( )
virtual

Release any allocated memory.


Member Function Documentation

◆ BlocksReset()

void Burger::DecompressDeflate::BlocksReset ( void )
protected

Reset the decompression state.


◆ BuildHuffmanTrees()

int Burger::DecompressDeflate::BuildHuffmanTrees ( const uint_t * pSampleCounts,
uint_t uNumberSamples,
uint_t uMaxSample,
const uint_t * pDefaultLengths,
const uint_t * pDefaultBits,
DeflateHuft_t ** ppNewTree,
uint_t * pNewTreeSize,
DeflateHuft_t * pExistingTree,
uint_t * pHuffmanCount,
uint_t * pWorkArea )
staticprotected

Create a huffman tree.


Parameters
pSampleCountsPointer to the sample count array
uNumberSamplesNumber of sample count entries
uMaxSampleMaximum value of a sample
pDefaultLengthsPointer to the default length
pDefaultBitsPointer to the default bits
ppNewTreePointer to receive the new tree
pNewTreeSizePointer to receive the size of the new tree
pExistingTreePointer to an existing huffman tree
pHuffmanCountPointer to receive the adjusted huffman tree size
pWorkAreaPointer to a work buffer

◆ CodesReset()

void Burger::DecompressDeflate::CodesReset ( uint_t bCodeLengthBits,
uint_t bCodeDistanceBits,
const DeflateHuft_t * pCodeTreeLength,
const DeflateHuft_t * pCodeTreeDistance )
protected

Reset the code state.


Parameters
bCodeLengthBitsDefault code length bits
bCodeDistanceBitsDefault code distance bits
pCodeTreeLengthPointer to the code length huffman tree
pCodeTreeDistancePointer to the code distance huffman tree

◆ Fast()

int Burger::DecompressDeflate::Fast ( uint_t uBitLength,
uint_t uBitDistance,
const DeflateHuft_t * pHuffmanLength,
const DeflateHuft_t * pHuffmanDistance )
protected

Optimized decompression code.


Called with number of bytes left to write in window at least 258 (the maximum string length) and number of input bytes available at least ten. The ten bytes are six bytes for the longest length/ distance pair plus four bytes for overloading the bit buffer.

Parameters
uBitLengthLength of the bit stream
uBitDistanceBit distance for huffman decoding
pHuffmanLengthPointer to the huffman table for length entries
pHuffmanDistancePointer to the huffman table for distance entries
Returns
Error code

◆ Flush()

int Burger::DecompressDeflate::Flush ( int iErrorCode)
protected

Copy as much as possible from the sliding window to the output area.


Parameters
iErrorCodeCurrent error code
Returns
Adjusted error code

◆ get_StaticRTTI()

const Burger::StaticRTTI * Burger::DecompressDeflate::get_StaticRTTI ( void ) const
overridevirtualnoexcept

Get the description to the class.


This virtual function will pull the pointer to the StaticRTTI instance that has the name of the class. Due to it being virtual, it will be the name of the most derived class.

Returns
Pointer to a global, read only instance of StaticRTTI for the true class

Reimplemented from Burger::Decompress.

◆ Process()

Burger::eError Burger::DecompressDeflate::Process ( void * pOutput,
uintptr_t uOutputChunkLength,
const void * pInput,
uintptr_t uInputChunkLength )
overridevirtual

Decompress data using Deflate compression.


Using the Deflate (ZLIB) compression algorithm, decompress the data

Parameters
pOutputPointer to the buffer to accept the decompressed data
uOutputChunkLengthNumber of bytes in the output buffer
pInputPointer to data to compress
uInputChunkLengthNumber of bytes in the data to decompress
Returns
Decompress::eError code with zero if no failure, non-zero is an error code
See also
Burger::SimpleDecompressDeflate()

Implements Burger::Decompress.

◆ ProcessBlocks()

int Burger::DecompressDeflate::ProcessBlocks ( int iErrorCode)
protected

Process the data blocks.


Parameters
iErrorCodeDefault error code to return
Returns
Error code, if any

◆ ProcessCodes()

int Burger::DecompressDeflate::ProcessCodes ( int iErrorCode)
protected

Process the decompression codes.


Parameters
iErrorCodeCurrent error code
Returns
Adjusted error code

◆ Reset()

Burger::eError Burger::DecompressDeflate::Reset ( void )
overridevirtual

Reset the decompressor.


Returns
Zero if no error, non-zero if error

Implements Burger::Decompress.

◆ TreesBits()

int Burger::DecompressDeflate::TreesBits ( const uint_t * pSampleCounts,
uint_t * pNewTreeSize,
DeflateHuft_t ** ppNewTree,
DeflateHuft_t * pExistingTree )
staticprotected

Set the default huffman trees.


Parameters
pSampleCountsPointer to the sample count array
pNewTreeSizePointer to receive the size of the new tree
ppNewTreePointer to receive the new tree
pExistingTreePointer to an existing huffman tree

◆ TreesDynamic()

int Burger::DecompressDeflate::TreesDynamic ( uint_t uNumberSamples,
uint_t uNumberDistance,
const uint_t * pSampleCounts,
uint_t * pNewTreeSize,
uint_t * pNewDistanceSize,
DeflateHuft_t ** ppNewTree,
DeflateHuft_t ** ppNewDistance,
DeflateHuft_t * pExistingTree )
staticprotected

Create the dynamic huffman tree.


Parameters
uNumberSamplesNumber of sample count entries
uNumberDistanceNumber of distance sample entries
pSampleCountsPointer to the sample count array
pNewTreeSizePointer to receive the size of the new tree
pNewDistanceSizePointer to receive the size of the new distance tree
ppNewTreePointer to receive the new tree
ppNewDistancePointer to receive the new distance tree
pExistingTreePointer to an existing huffman tree
Returns
Error code, if any

Member Data Documentation

◆ g_StaticRTTI

const Burger::StaticRTTI Burger::DecompressDeflate::g_StaticRTTI
static

The global description of the class.


This record contains the name of this class and a reference to the parent

◆ m_bCodeDistanceBits

uint8_t Burger::DecompressDeflate::m_bCodeDistanceBits
protected

Distance tree bits decoder per branch.

◆ m_bCodeLengthBits

uint8_t Burger::DecompressDeflate::m_bCodeLengthBits
protected

Length tree bits decoded per branch.

◆ m_bLastBlock

uint_t Burger::DecompressDeflate::m_bLastBlock
protected

TRUE if this block is the last block.

◆ m_eBlockMode

eBlockMode Burger::DecompressDeflate::m_eBlockMode
protected

Current decompression block mode.

◆ m_eCodesMode

eCodesMode Burger::DecompressDeflate::m_eCodesMode
protected

Current inflate_codes mode.

◆ m_eState

eState Burger::DecompressDeflate::m_eState
protected

State of the decompression.

◆ m_HuffmanTable

DeflateHuft_t Burger::DecompressDeflate::m_HuffmanTable[MAXTREEDYNAMICSIZE]
protected

Single data chunk for tree space.

◆ m_pCodeTree

const DeflateHuft_t* Burger::DecompressDeflate::m_pCodeTree
protected

Pointer into tree.

◆ m_pCodeTreeDistance

const DeflateHuft_t* Burger::DecompressDeflate::m_pCodeTreeDistance
protected

Pointer distance tree.

◆ m_pCodeTreeLength

const DeflateHuft_t* Burger::DecompressDeflate::m_pCodeTreeLength
protected

Pointer to literal/length/eob tree.

◆ m_pInput

const uint8_t* Burger::DecompressDeflate::m_pInput
protected

Packed data pointer.

◆ m_pOutput

uint8_t* Burger::DecompressDeflate::m_pOutput
protected

Output data pointer.

◆ m_pTreesHuffman

DeflateHuft_t* Burger::DecompressDeflate::m_pTreesHuffman
protected

Pointer to bit length decoding tree.

◆ m_pTreesLengths

uint_t* Burger::DecompressDeflate::m_pTreesLengths
protected

Pointer to bit lengths of codes.

◆ m_pWindowRead

const uint8_t* Burger::DecompressDeflate::m_pWindowRead
protected

Window read pointer.

◆ m_pWindowWrite

uint8_t* Burger::DecompressDeflate::m_pWindowWrite
protected

Window write pointer.

◆ m_uAlder32Checksum

uint32_t Burger::DecompressDeflate::m_uAlder32Checksum
protected

Checksum on output.

◆ m_uBitBucket

uint32_t Burger::DecompressDeflate::m_uBitBucket
protected

Bit buffer.

◆ m_uBitCount

uint_t Burger::DecompressDeflate::m_uBitCount
protected

Bits in bit buffer.

◆ m_uChecksumInStream

uint32_t Burger::DecompressDeflate::m_uChecksumInStream
protected

32 bit literal pulled from the big endian data stream (Must match DecompressDeflate::m_uChecksumInStream)

◆ m_uChecksumOfChunk

uint32_t Burger::DecompressDeflate::m_uChecksumOfChunk
protected

Computed checksum value of decompressed data.

◆ m_uCodeCopyDistance

uint_t Burger::DecompressDeflate::m_uCodeCopyDistance
protected

Distance back to copy from.

◆ m_uCodeCopyGet

uint_t Burger::DecompressDeflate::m_uCodeCopyGet
protected

Bits to get for extra token.

◆ m_uCodeLength

uint_t Burger::DecompressDeflate::m_uCodeLength
protected

Length in bits of the last code.

◆ m_uCodeLiteral

uint_t Burger::DecompressDeflate::m_uCodeLiteral
protected

Literal code fetched.

◆ m_uCodeTreeNeed

uint_t Burger::DecompressDeflate::m_uCodeTreeNeed
protected

Bits needed.

◆ m_uCompressionMethod

uint_t Burger::DecompressDeflate::m_uCompressionMethod
protected

Compression method type.

◆ m_uInputChunkLength

uintptr_t Burger::DecompressDeflate::m_uInputChunkLength
protected

Number of packed bytes remaining.

◆ m_uOutputChunkLength

uintptr_t Burger::DecompressDeflate::m_uOutputChunkLength
protected

Number of bytes in the output buffer.

◆ m_uStoredBytesToCopy

uintptr_t Burger::DecompressDeflate::m_uStoredBytesToCopy
protected

If STORED, bytes left to copy.

◆ m_uTreesDepth

uint_t Burger::DecompressDeflate::m_uTreesDepth
protected

Bit length tree depth.

◆ m_uTreesIndex

uint_t Burger::DecompressDeflate::m_uTreesIndex
protected

Index into blends (or border)

◆ m_uTreesTable

uint_t Burger::DecompressDeflate::m_uTreesTable
protected

Table lengths (14 bits)

◆ m_WindowBuffer

uint8_t Burger::DecompressDeflate::m_WindowBuffer[1<< MAX_WBITS]
protected

Sliding window.

◆ s_FixedTreeDistance

const Burger::DecompressDeflate::DeflateHuft_t Burger::DecompressDeflate::s_FixedTreeDistance
staticprotected
Initial value:
= {
{80,5, 1}, {87,5, 257}, {83,5, 17}, { 91,5, 4097},
{81,5, 5}, {89,5,1025}, {85,5, 65}, { 93,5,16385},
{80,5, 3}, {88,5, 513}, {84,5, 33}, { 92,5, 8193},
{82,5, 9}, {90,5,2049}, {86,5,129}, {192,5,24577},
{80,5, 2}, {87,5, 385}, {83,5, 25}, { 91,5, 6145},
{81,5, 7}, {89,5,1537}, {85,5, 97}, { 93,5,24577},
{80,5, 4}, {88,5, 769}, {84,5, 49}, { 92,5,12289},
{82,5,13}, {90,5,3073}, {86,5,193}, {192,5,24577}
}

Table for preset distance codes.


◆ s_FixedTreeLiteral

const Burger::DecompressDeflate::DeflateHuft_t Burger::DecompressDeflate::s_FixedTreeLiteral
staticprotected

Table for preset literal codes.


◆ Signature

const uint32_t Burger::DecompressDeflate::Signature = 0x5A4C4942
static

'ZLIB'