Table of Contents

NAME

QccENTArithmeticModel - data structure QccENTArithmeticModel for arithmetic encoding and decoding

SYNOPSIS

#include "libQccPack.h"

void QccENTArithmeticFreeModel(QccENTArithmeticModel *model);
int QccENTArithmeticSetModelContext(QccENTArithmeticModel *model, int current_context);
void QccENTArithmeticSetModelAdaption(QccENTArithmeticModel *model, int adaptive);
int QccENTArithmeticSetModelProbabilities(QccENTArithmeticModel *model, double *probabilities, int context);
int QccENTArithmeticResetModel(QccENTArithmeticModel *model, int context);

DESCRIPTION

QccPack provides data structure QccENTArithmeticModel for representing the arithmetic-coding model to use in arithmetic encoding and decoding.

CAVEAT: The QccENTArithmeticModel data structure contains a number of variables and arrays which are used internally in the arithmetic encoding and decoding routines; these variables and arrays are described briefly below, but they should under no circumstances be accessed or modified by the user directly, as this will likely result in erroneous operation of the coder. Users who are interested in modifying the internal structure of the QccPack arithmetic-coder code should consult the paper by Witten et al. for details on the internal operation of the QccPack arithmetic coder and a thorough description of the variables and arrays internal to the QccENTArithmeticModel structure.

DATA STRUCTURE

The QccENTArithmeticModel data structure is defined as:

typedef struct
{
int num_contexts;
int *num_symbols;
int **translate_symbol_to_index;
int **translate_index_to_symbol;
int **cumulative_frequencies;
int **frequencies;
QccENTCodeValue low, high;
long bits_to_follow;
int garbage_bits;
int target_num_bits;
int adaptive_model;
QccENTArithmeticGetContext context_function;
int current_context;
QccENTCodeValue current_code_value;
} QccENTArithmeticModel;

The fields of QccENTArithmeticModel are as follows:

num_contexts
The total number of contexts.
num_symbols
An array of num_contexts entries, with each entry providing the number of symbols in the corresponding context.
translate_symbol_to_index, translate_index_to_symbol
Internal arrays for translating between symbols and internal symbol indices. See Witten et al.
cumulative_frequencies, frequencies
Together these arrays provide the probabilities and cumulative probabilities for the symbols in each context, expressed for practical reasons as integer frequencies. See Witten et al.
low, high, bit_to_follow, current_code_value
Internal storage for the current code value and known range. See Witten et al.
target_num_bits
The total number of desired bits to be read by the arithmetic decoder; useful for decoding the bitstream from packets with known sizes. A value of QCCENT_ANYNUMBITS indicates that there is no packet-length constraint; i.e., the decoder reads symbols until it reaches the end of the bitstream or the EOF symbol output by QccENTArithmeticEncodeEnd(3) .
garbage_bits
The number of bits the decoder has read beyond target_num_bits (or beyond the end of the file if target_num_bits is QCCENT_ANYNUMBITS) while attempting to decode the last symbol; needed since the decoder reads bits from the bitstream in advance of symbol output.
adaptive_model
Indicates whether adaption in the model is currently turned on or off; i.e., whether the model is adaptive or nonadaptive. In an adaptive model, symbol frequency counts are updated each time a symbol is coded. In a nonadaptive model, symbol frequency counts are not changed except through explicit setting of the frequency counts. Use QccENTArithmeticSetModelAdaption(3) to change the state of adaption in the model, and QccENTArithmeticSetModelProbabilities(3) to explicit chage frequency counts in a nonadaptive model. The model is initially created as an adaptive model.
context_function
A function that returns the current context to be used in coding when num_contexts is greater than 1. context_function can be NULL in which case the current context is retrieved from the current_context field of the model. See QccENTArithmeticGetContext(3) .
current_context
If context_function is NULL, the current context to be used in coding is retrieved from the current_context field of the arithmetic-model structure. User routines may set this field by calling QccENTArithmeticSetModelContext(3) before calling routines such as QccENTArithmeticEncode(3) and QccENTArithmeticDecode(3) .

ROUTINES

QccENTArithmeticFreeModel() frees all the arrays contained in model as well as model itself. QccENTArithmeticFreeModel() should be called after QccENTArithmeticEncodeEnd(3) or QccENTArithmeticDecode(3) to get rid of the QccENTArithmeticModel structure that has been used for encoding and decoding, when one is done encoding or decoding.

QccENTArithmeticSetModelContext() sets the current-context field of model to current_context. current_context must be greater than or equal to zero, and less than or equal to model->num_contexts. QccENTArithmeticSetModelContext() returns 0 on success, or 1 if current_context is an invalid context number.

QccENTArithmeticSetModelAdaption() changes the adaption state of the model. If adaptive is QCCENT_NONADAPTIVE, the model is made nonadaptive; otherwise, if adaptive is QCCENT_ADAPTIVE, the model becomes adaptive. The adaption mode of the model can be changed at any time during encoding, as long as the same changes to the adaption state are made during decoding as well. When model is initially created, the model is set to be adaptive.

QccENTArithmeticSetModelProbabilities() can be use to manually set the frequency counts in a particular context in a nonadaptive model according to any desired probability distribution. probabilities is a list of probability values, double-precision floating point numbers each greater than or equal to 0.0 and less than or equal to 1.0. There should be as many values in probabilities as there are symbols in context (not including the EOF symbol automatically added to the context during the call to QccENTArithmeticCreateModel(3) ; the frequency of the EOF symbol is set to automatically set to 1 by QccENTArithmeticSetModelProbabilities()). Additionally, the probability values should form a valid probability mass function; i.e., they should sum to 1.0. QccENTArithmeticSetModelProbabilities() updates model->cumulative_frequencies and model->frequencies to approximate the distribution specified by probabilities. QccENTArithmeticSetModelProbabilities() returns in error if model is not nonadaptive.

QccENTArithmeticResetModel() manually resets the frequency counts in a particular context back to their initial values; i.e., all frequency counts in the context are set to 1. Unlike QccENTArithmeticSetModelProbabilities(), model may be either adaptive or nonadaptive.

SEE ALSO

QccENTArithmeticEncode(3) , QccENTArithmeticEncodeStart(3) , QccENTArithmeticEncodeEnd(3) , QccENTArithmeticDecode(3) , QccENTArithmeticDecodeStart(3) , QccENTArithmeticDecodeRestart(3) , QccENTArithmeticGetContext(3) , QccPackENT(3) , QccPack(3)

I. H. Witten, R. M. Neal, and J. G. Cleary, "Arithmetic Coding for Data Compression," Communications of the ACM, vol. 30, no. 6, pp. 520-540, June 1987.

AUTHOR

Copyright (C) 1997-2021 James E. Fowler


Table of Contents



Get QccPack at SourceForge.net. Fast, secure and Free Open Source software downloads