Libraries
Huffman Source Code
 previous   up   next 

Function Summary
msbHuffmanTable
createHuffmanTableMsb (in integer: maximumCodeLength, in array integer: numberOfCodesWithLength, in string: huffmanValues)
Create a Huffman table for reading in MSB-First order.
integer
getHuffmanSymbol (inout msbBitStream: inBitStream, in msbHuffmanTable: table)
Get a huffman symbol from a msbBitStream using the huffman table.
lsbHuffmanTable
createHuffmanTableLsb (in array integer: codeLengths)
Create a Huffman table for reading in LSB-First order.
integer
getHuffmanSymbol (inout lsbBitStream: inBitStream, in lsbHuffmanTable: table)
Get a huffman symbol from a lsbBitStream using the huffman table.

Function Detail

createHuffmanTableMsb

const func msbHuffmanTable: createHuffmanTableMsb (in integer: maximumCodeLength, in array integer: numberOfCodesWithLength, in string: huffmanValues)

Create a Huffman table for reading in MSB-First order. This Huffman encoding is used by JPEG files. It can happen that huffmanValues contains the same value twice. In that case the same symbol is encoded in two ways. This makes absolutely no sense but it can happen. For that reason it is necessary to use table.codeLengths with the same index as table.symbols.

Parameters:
numberOfCodesWithLength - Array to map bit width to number of symbols that use this bit width.
huffmanValues - String with symbols ordered by the bit width.

getHuffmanSymbol

const func integer: getHuffmanSymbol (inout msbBitStream: inBitStream, in msbHuffmanTable: table)

Get a huffman symbol from a msbBitStream using the huffman table. The read direction is from MSB (most significant bit) to LSB (least significant bit). The function peeks bits from inBitStream. By default inBitStream appends some '\16#ff;' bytes to allow that bits can be peeked always.

Parameters:
inBitStream - MSB orderd bit stream from which the bits are skipped.
table - Huffman table defining the bit sequences that encode the symbols.

createHuffmanTableLsb

const func lsbHuffmanTable: createHuffmanTableLsb (in array integer: codeLengths)

Create a Huffman table for reading in LSB-First order. This Huffman encoding is used by the deflate algorithm. E.g.: The code lengths (in bits) of

4 0 0 6 5 3 3 3 3 3 4 3 0 0 0 0 5 5 6

describe that 0 is encoded with 4 bits, 3 with 6 bits, etc. This leads to the following encoding lengths:

length 3: (5, 6, 7, 8, 9, 11)
length 4: (0, 10)
length 5: (4, 16, 17)
length 6: (3, 18)

Beginning with the lowest length the following encodings are generated:

000: 5
001: 6
...
101: 11

For the next length (4 instead of 3) the value is incremented and shifted:

1100: 0

The encoder should be able fetch the maximum length of bits and to use it as index. In order to allow that the data must be transformed. The bits must be flipped and all variants of higher bits must be added:

000000 encodes 5
000001 encodes 9
000010 encodes 7
000011 encodes 0
000100 encodes 6
...
001000 encodes 5
001001 encodes 9
001010 encodes 7
...
Parameters:
codeLengths - Array to map the codes to the number of bits used to encode this code. Zero means: This code is not used.

getHuffmanSymbol

const func integer: getHuffmanSymbol (inout lsbBitStream: inBitStream, in lsbHuffmanTable: table)

Get a huffman symbol from a lsbBitStream using the huffman table. The read direction is from LSB (least significant bit) to MSB (most significant bit). The function peeks bits from inBitStream. By default inBitStream appends some '\16#ff;' bytes to allow that bits can be peeked always.

Parameters:
inBitStream - LSB orderd bit stream from which the bits are skipped.
table - Huffman table defining the bit sequences that encode the symbols.


 previous   up   next