Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Context Class Reference

Context structure for arithmetic coding. More...

#include <context.h>

Inheritance diagram for Context:

ContextBase List of all members.

Public Methods

 Context (void)
 A constructor. More...

 Context (int, ContextType)
 A constructor. Sets the size and type directly. More...

virtual ~Context (void)
 A destructor. More...

virtual void setType (int, ContextType)
 Initialization of the context with given size and type. More...

virtual int initialize (void)
 Initialize the context. More...

virtual int lastFixedSymbol (void)
 Return the value of last fixed symbol in the context.

virtual int encode (int) throw (ExaltContextNotInitializedException, ExaltIOException)
 Encode symbol using given arithmetic codec. More...

virtual int encodeEndOfMessage () throw (ExaltContextNotInitializedException, ExaltIOException)
 Encode the "end of message" symbol.

virtual int decode (void) throw (ExaltContextNotInitializedException, ExaltIOException)
 Decode symbol using given arithmetic codec. More...

virtual void purgeContext (void)
 Purge the contents of the context. More...

virtual int installSymbol (int)
 Install new symbol. More...


Protected Methods

virtual void getInterval (FreqValue *, FreqValue *, int)
 Get interval for given symbol. More...

virtual void halveContext (void)
 Halve frequencies in the context. More...

virtual void initZeroFreq ()
 Initialize number of singletons. More...


Protected Attributes

int initialSize
 Original size of context.

int maxLength
 Length of the tree and current length.

int length
 Length of the tree and current length.

FreqValue nSingletons
 Number of symbols with frequency = 1.

ContextType type
 Type of the context.

int nSymbols
 Count of installed symbols.

FreqValue total
 Total sum of all frequencies.

FreqValuetree
 Fenwick's binary index tree.

FreqValue incr
 Current increment.

int mostFreqSymbol
 Symbol with highest frequency.

FreqValue mostFreqCount
 The highest frequency.

FreqValue mostFreqPos
 Position of the most frequent symbol.


Detailed Description

Context structure for arithmetic coding.

Class represents a frequency table using a Fenwick's binary index tree. Table may be static or dynamic. Dynamic tables may grow above their intial length as new symbols are installed.

Definition at line 109 of file context.h.


Constructor & Destructor Documentation

Context::Context void   
 

A constructor.

Calls construcotr of class ContextBase.

Definition at line 164 of file context.cpp.

References tree.

Context::Context int    size,
ContextType    type
 

A constructor. Sets the size and type directly.

Calls initContext().

Parameters:
size  Initial size of the context.
type  Type of the context.

Definition at line 178 of file context.cpp.

References ContextType, setType, tree, and type.

Context::~Context void    [virtual]
 

A destructor.

Frees the memory occupied by Fenwick's tree.

Definition at line 190 of file context.cpp.

References tree.


Member Function Documentation

int Context::decode void    throw (ExaltContextNotInitializedException, ExaltIOException) [virtual]
 

Decode symbol using given arithmetic codec.

Decode symbol based on current context.

Returns:
Decoded symbol.

Implements ContextBase.

Definition at line 489 of file context.cpp.

References ADJUST_ZERO_FREQ, DynamicContext, FreqValue, GET_COUNT, INCR_SYMBOL_PROB, MAX_FREQUENCY, and ContextBase::NotKnown.

Referenced by XmlCodec::decode.

int Context::encode int    symbol throw (ExaltContextNotInitializedException, ExaltIOException) [virtual]
 

Encode symbol using given arithmetic codec.

Encode a symbol given its context. The lower and upper bounds are determined using the frequency table, and then passed on to the coder. If the symbol has zero frequency, code an escape symbol and return Context::NotKnown, otherwise return Context::Ok.

Parameters:
symbol  Encoded symbol
Return values:
Context::NotKnown  Encoding unknown symbol.
Context::Ok  Success.

Implements ContextBase.

Definition at line 389 of file context.cpp.

References ADJUST_ZERO_FREQ, DynamicContext, FATAL, FreqValue, INCR_SYMBOL_PROB, MAX_FREQUENCY, ContextBase::NotKnown, ContextBase::Ok, and ZERO_FREQ_PROB.

void Context::getInterval FreqValue   pLow,
FreqValue   pHigh,
int    symbol
[protected, virtual]
 

Get interval for given symbol.

Get the low and high limits of the frequency interval occupied by a symbol.

Parameters:
pLow  Low frequency linit.
pHigh  High frequency linit.
symbol  Symbol.

Definition at line 620 of file context.cpp.

References FORW, FreqValue, GET_COUNT, maxLength, and tree.

Referenced by halveContext, and installSymbol.

void Context::halveContext void    [protected, virtual]
 

Halve frequencies in the context.

This method is responsible for halving all the frequency counts in a context. It halves context in linear time by converting tree to list of freqs and then back again. It ensures the most probable symbol size and range stay updated. If halving the context gives rise to a sudden drop in the ZERO_FREQ_PROB(), and if it was the most probable symbol, it will stay recorded as the most probable symbol even if it isn't. This may cause slight compression inefficiency. (The ZERO_FREQ_PROB() as implemented does not have this characteristic, and in this case the inefficiency cannot occur.)

Definition at line 649 of file context.cpp.

References ADJUST_ZERO_FREQ, FreqValue, getInterval, incr, maxLength, MIN_INCR, mostFreqCount, mostFreqPos, mostFreqSymbol, nSingletons, StaticContext, total, tree, type, and ZERO_FREQ_PROB.

Referenced by installSymbol.

int Context::initialize void    [virtual]
 

Initialize the context.

Install all symbols of the initial context.

Returns:
Index of last symbol in the table.

Implements ContextBase.

Definition at line 274 of file context.cpp.

References ContextBase::endOfMessage, FATAL, ContextBase::initialized, installSymbol, and ContextBase::TooManySymbols.

Referenced by XmlCodec::decode.

void Context::initZeroFreq   [protected, virtual]
 

Initialize number of singletons.

If context is dynamic, nSingletons will be equal to incr` otherwise it will be 0.

Definition at line 201 of file context.cpp.

References DynamicContext, incr, nSingletons, and type.

Referenced by purgeContext, and setType.

int Context::installSymbol int    symbol [virtual]
 

Install new symbol.

Install a new symbol in a context's frequency table.

Parameters:
symbol  Installed symbol.
Return values:
Context::Ok  Success
Context::TooManySymbols  Too many symbols in the table.
Context::NoMemory  No memory left for the symbol.

Implements ContextBase.

Definition at line 307 of file context.cpp.

References ADJUST_ZERO_FREQ, DynamicContext, ERR, FreqValue, getInterval, halveContext, incr, INCR_SYMBOL_PROB, length, MAX_FREQUENCY, maxLength, ContextBase::NoMemory, nSingletons, nSymbols, ContextBase::Ok, ContextBase::TooManySymbols, total, tree, and type.

Referenced by initialize.

void Context::purgeContext void    [virtual]
 

Purge the contents of the context.

Frees memory allocated for a context and initialize empty context of original size.

Implements ContextBase.

Definition at line 722 of file context.cpp.

References ADJUST_ZERO_FREQ, F_BITS, FATAL, FreqValue, incr, initialSize, initZeroFreq, length, maxLength, mostFreqCount, mostFreqPos, mostFreqSymbol, nSingletons, nSymbols, total, and tree.

void Context::setType int    len,
ContextType    ct
[virtual]
 

Initialization of the context with given size and type.

Create a new frequency table using a binary index tree. Table may be static or dynamic depending on the type parameter. Dynamic tables may grow above their initial length as new symbols are installed. Maximum length (maxLength) is set to 2^ceil(log_2 length).

Valid tree indices are 1..maxLength - 1 (maxLength refers to the maximum length of the structure before it needs to expand).

Parameters:
len  Initial size of the context.
ct  type of the context.

Implements ContextBase.

Definition at line 221 of file context.cpp.

References ADJUST_ZERO_FREQ, ContextType, ContextBase::endOfMessage, F_BITS, FATAL, FreqValue, incr, initialSize, initZeroFreq, length, maxLength, mostFreqCount, mostFreqPos, mostFreqSymbol, nSingletons, nSymbols, total, tree, and type.

Referenced by Context, and XmlCodec::decode.


The documentation for this class was generated from the following files:
Generated on Wed Feb 5 10:43:04 2003 for Exalt by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002