📄 dst_arith_decoder.h
字号:
/*****************************************************************************/
/* Copyright 1998, Hewlett-Packard Company */
/* All rights reserved */
/* File: "dst_arith_decoder.h" */
/* Description: Master include file for the arithmetic decoder. This is the */
/* only header file which need be included by clients. */
/* Author: David Taubman */
/* Affiliation: Hewlett-Packard and */
/* The University of New South Wales, Australia */
/* Version: VM7.0 */
/* Last Revised: 24 March, 2000 */
/*****************************************************************************/
/*****************************************************************************/
/* Modified to incorporate MQ-coder by Mitsubishi Electric Corp. */
/* Copyright 1999, Mitsubishi Electric Corp. */
/* All rights reserved for modified parts */
/*****************************************************************************/
/*****************************************************************************/
/* Modified to speed up MQ-decoder */
/* Copyright 1999 Science Applications International Corporation (SAIC). */
/* All Rights Reserved for modified parts. */
/*****************************************************************************/
/*****************************************************************************/
/* Modifications tagged with comment lines or delimiters involving the */
/* string, "David T mod" or "mod by David T", have been made by David */
/* Taubman; they are copyrighted by Hewlett-Packard Company with all rights */
/* reserved for the modified parts. */
/*****************************************************************************/
/*****************************************************************************/
/* Modified by David Taubman to further speed up MQ-coder. */
/* Copyright 1999 by Hewlett-Packard Company with all rights reserved for */
/* the modified parts. */
/*****************************************************************************/
/*****************************************************************************/
/* Modified by David Taubman to support new termination methods and error */
/* resilience. Copyright 1999 by Hewlett-Packard Company with all */
/* rights reserved for the modified parts. */
/*****************************************************************************/
/*****************************************************************************/
/* Modified by David Taubman to avoid the need for byte stuffing when resync */
/* markers are in use. This simplifies the code and substantially improves */
/* the usefulness of the system for applications requiring error resilience. */
/* Changes are as follows: a) changed SOT marker to lie within intra-packet */
/* marker range 0xFF90 through 0xFFFF; b) introduced an MQ-like bit-stuffing */
/* policy in packet heads; c) introduced an MQ-like bit-stuffing policy in */
/* the raw bit-stream segments generated by the entropy coder in lazy mode; */
/* d) modified error resilient termination policy for raw bit-stream */
/* to fill unused bits with the simpler code 0101... instead of 1010...; */
/* e) eliminated the use of byte-stuffing with resync markers. In the new */
/* code, none of the packet segments (packet head, MQ segments and raw */
/* segments) may contain any two byte sequence in the range 0xFF90 through */
/* 0xFFFF; moreover, no segment can terminate with a 0xFF, so that the */
/* entire packet is guaranteed to be free of two byte sequences in the above */
/* range. All delimiting markers from the codestream (i.e. SOT, RESYNC and */
/* EOC) are guaranteed to lie within that range. */
/* Copyright 1999 by Hewlett-Packard Company with all */
/* rights reserved for the modified parts. */
/*****************************************************************************/
#ifndef DST_ARITH_DECODER_H
#define DST_ARITH_DECODER_H
#include <ifc.h>
#include <stdio.h>
#include "dst_codeword_heap.h"
#include "dst_arith_coder_common.h"
/* ========================================================================= */
/* ----------------------------- Type Definitions -------------------------- */
/* ========================================================================= */
typedef /* Mitsubishi */
struct mqd_var {
unsigned long creg;
std_int areg;
std_int word, buffer;
int ct, nextct;
int converted_doublets; /* Number of times a pair of FF's has been seen. */
int active; /* Flag indicates that the MQ coder is in use. */
} mqd_var, *mqd_var_ptr;
/*****************************************************************************/
/* dst_arith_state */
/*****************************************************************************/
typedef
struct dst_arith_state {
mqd_var mqd; /* Mitsubishi */
int error_resilient_termination;
std_int word;
std_int save_word;
int current_lsb;
int num_contexts;
dst_context_state_ptr contexts;
dst_heap_unit_ptr heap_head, heap_ptr;
int next_heap_pos;
int total_bytes_available, total_bytes_consumed;
int bytes_left_in_segment, current_segment_bytes;
int bytes_in_word;
int final_segment_word_consumed;
#ifdef DST_LOG_SYMBOLS
FILE *symbol_log;
#endif /* DST_LOG_SYMBOLS */
} dst_arith_state, *dst_arith_state_ptr;
/* This structure manages fundamental state information for the arithmetic
coding engine.
`word' is a 32-bit word which is used to buffer code bits so as
to avoid excessive access into the main bit-stream store.
`save_word' is identical to `word', except that when an attempt
is made to read beyond the current codeword segment, the policy of
appending FF's is applied only to `word' and not to `save_word'. This
allows the next codeword segment to be correctly recovered.
`current_lsb' holds the index of the last bit-position in `word'
from which data was retrieved. A value of 32 means that none of the
bits of `word' have yet been retrieved; a value of 0 means that the
next word needs to be retrieved from the code stream. The field may
equivalently be interpreted as the number of least significant bits in
`word' which have not yet been consumed.
`contexts' points to the array of context states which is currently
in use. The array itself is managed externally, but it must be capable
of storing `num_contexts'+DST_ARITH_MAX_CTXTS entries.
`heap_head' points to the head of the linked list of `heap_unit'
structures which hold the complete arithemetic code word which is
being decoded.
`heap_ptr' points to the currently active `heap_unit' structure
within the list headed by `heap_head'.
`next_heap_pos' identifies the index of the next word within the
`heap_ptr' structure from which the `word' register should be loaded
once it becomes empty.
`total_bytes_available' identifies the total number of bytes
in the code-stream which contain valid information, starting from the
head.
`total_bytes_consumed' identifies the total number of bytes
which have been retrieved from the code-stream. This value is only
accurately computed when a new word is requested via
`dst_arith_coder__input_word' and when a new segment size is set
via `dst_arith_coder__set_segment_size'.
`bytes_left_in_segment' identifies the number of code-stream
bytes from the current segment which have not yet been retrieved. Once
this reaches zero, further byte requests are satisfied by padding with
FF's without consuming any of the code stream.
`current_segment_size' indicates the number of bytes in the
current segment. At the start of the segment it holds the same value
as `bytes_left_in_segment'.
`bytes_in_word' holds the number of bytes from the current
or future segments which belong to the current word. This field is
required to reliably update `total_bytes_consumed' and
`bytes_left_in_segment' on word and segment boundaries. */
#include "mq_decoder.h" /* Mitsubishi */
/* ========================================================================= */
/* --------------------------- Utility Macros ------------------------------ */
/* ========================================================================= */
/*****************************************************************************/
/* MACRO renormd */
/*****************************************************************************/
#define renormd(_areg_, _creg_, _ct_, _state_) \
{ \
do { \
_creg_ <<= 1; \
_areg_ <<= 1; \
_ct_--; \
if (!_ct_) \
_creg_ = dst_arith_coder__bytein(_creg_, &(_ct_), _state_); \
} while(_areg_ < DEC_HALF); \
}
/* ========================================================================= */
/* ----------------------- Symbol Decoding Macros -------------------------- */
/* ========================================================================= */
/*****************************************************************************/
/* MACRO dst_compute_ac_thresh */
/*****************************************************************************/
#define dst_compute_ac_thresh(__areg__,__creg__,__ac_thresh__) \
/* [std_int __areg__, unsigned long __creg__, std_int __ac_thresh__] */ \
{ \
__ac_thresh__ = (std_int)((unsigned)(__creg__ >> 16)); \
if (__ac_thresh__ > (__areg__-DEC_HALF)) \
__ac_thresh__ = __areg__-DEC_HALF; \
}
/*****************************************************************************/
/* MACRO dst_complete_get_symbol */
/*****************************************************************************/
/* This macro represents the common decoding functionality for various
decoding macros which may be tailored to different expected distribution
skews or tied carefully into certain parts of an implementation. The
_delta_ value must have been obtained by dereferencing
(_csp_)[DST_ARITH_MAX_CTXTS]. */
#define dst_complete_get_symbol(_A_,_C_,_ct_,_state_,_sym_,_csp_,_delta_) \
{ \
_sym_ = _delta_ >> DST_ARITH_MPS_POS; /* Set to MPS for now. */ \
_delta_ &= ~(1<<DST_ARITH_MPS_POS); \
_A_ -= _delta_; \
if ((_C_>>16) >= (unsigned) _delta_) \
{ \
_C_ -= _delta_<<16; \
if (_A_ < DEC_HALF) \
{ /* Process MPS_EXCHANGE */ \
if (_A_ >= _delta_) \
{ /* MPS decoded. */ \
*(_csp_) = dst_arith_trans_mps[*(_csp_)]; \
} \
else \
{ /* LPS decoded. */ \
_sym_ = 1-_sym_; \
*(_csp_) = dst_arith_trans_lps[*(_csp_)]; \
} \
renormd(_A_,_C_,_ct_,_state_); \
(_csp_)[DST_ARITH_MAX_CTXTS] = \
dst_arith_state_to_delta[*(_csp_)]; \
} \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -