📄 dst_arith_encoder.h
字号:
int __pel = 0; \
\
if (_pel_) \
__pel=1; \
_areg_ -= *(lszE + n_st); /* Upper area width */ \
if (__pel == n_mps) \
{ /* Process CODEMPS */ \
if (_areg_ >= ENC_HALF) \
{ \
_creg_ += *(lszE + n_st); \
} \
else \
{ \
if (_areg_ >= *(lszE + n_st)) /* !CE */ \
{ /* Upper area is selected! */ \
_creg_ += *(lszE + n_st); \
renorme(_areg_,_creg_,_ct_,_state_) \
} \
else \
{ /* CE */ \
_areg_ = *(lszE + n_st); \
renorme(_areg_,_creg_,_ct_,_state_) \
} \
trans_mps(_st_,n_st,n_mps) \
} \
} \
else \
{ /* Process CODELPS */ \
if (_areg_ >= *(lszE + n_st)) /* !CE */ \
{ /* Lower area is selected! */ \
_areg_ = *(lszE + n_st); \
renorme(_areg_,_creg_,_ct_,_state_) \
} \
else \
{ /* CE */ \
_creg_ += *(lszE + n_st); \
renorme(_areg_,_creg_,_ct_,_state_) \
} \
trans_lps(_st_,n_st,n_mps) \
} \
}
/*****************************************************************************/
/* MACRO dst_emit_raw_bit */
/*****************************************************************************/
#ifdef DST_LOG_SYMBOLS
#define dst_emit_raw_bit(__lsb,__word,__symbol,__state) \
{ \
dst_arith_coder__log_symbol(__state,0,__symbol); \
_dst_emit_raw_bit(__lsb,__word,__symbol,__state); \
}
#else
# define dst_emit_raw_bit _dst_emit_raw_bit
#endif
/*****************************************************************************/
/* MACRO _dst_emit_raw_bit */
/*****************************************************************************/
#define _dst_emit_raw_bit(_lsb,_word,_symbol,_state) \
{ \
assert((!(_state)->mqe.active) && \
(_lsb > 0) && (_lsb <= 32) && \
((((std_int)(_symbol))&~1)==0)); \
_lsb--; \
_word += ((std_int)(_symbol))<<_lsb; \
if ((_lsb & 7) == 0) \
{ /* Reached byte boundary; may need to stuff a bit. */ \
int _have_ff = (((_word >> _lsb) & 0x00FF) == 0x00FF); \
if (_lsb == 0) \
{ \
dst_arith_coder__output_word(_state,_word); \
_word = 0; \
_lsb = 32; \
} \
_lsb -= _have_ff; \
} \
}
/*****************************************************************************/
/* MACRO dst_emit_symbol */
/*****************************************************************************/
#ifdef DST_LOG_SYMBOLS
#define dst_emit_symbol(__areg,__creg,__ct,__state,__symbol,__ctxt) \
{ \
dst_arith_coder__log_symbol(__state,__ctxt,__symbol); \
_dst_emit_symbol(__areg, __creg, __ct, __state,__symbol,__ctxt) \
}
#else
# define dst_emit_symbol _dst_emit_symbol
#endif /* DST_LOG_SYMBOLS */
/*****************************************************************************/
/* MACRO _dst_emit_symbol */
/*****************************************************************************/
/* Begin David T mod */
#define _dst_emit_symbol(_areg_,_creg_,_ct_,_state_,_sym_,_ctxt_) \
{ \
_addto_symbol_count(1); \
mqenc(_areg_,_creg_,_ct_,_state_,_sym_,_ctxt_); \
}
/* End David T mod */
/* ========================================================================= */
/* ------------------------- External Functions ---------------------------- */
/* ========================================================================= */
extern void
dst_arith_coder__initialize(dst_arith_state_ptr state,
int num_contexts, dst_context_state_ptr contexts,
dst_heap_unit_ptr heap, int next_heap_pos,
dst_codeword_heap_ref code_mgr,
int error_resilient_termination);
/* After this call, raw binary digits may be emitted, but arithmetic
codeword segment generation may not begin until after the first call
to `dst_arith_coder__activate'. Note that the context models are
not initialized until a subsequent call to
`dst_arith_coder__model_init'. If `error_resilient_termination' is
true (non-zero), the encoder embeds error resilience information into
the spare code space left at each termination point (on average about
3.5 bits are left after byte alignment). The decoder
need not be aware of this, but suitably equipped decoders can use this
information to detect errors in the current or previously terminated
segements. */
void
dst_arith_coder__model_init(dst_arith_state_ptr state,
dst_context_state_ptr initial_states);
extern void
dst_arith_coder__output_word(dst_arith_state_ptr state, std_int word);
extern std_int
dst_arith_coder__byteout(std_int creg, std_short *ct,
dst_arith_state_ptr state);
/* Internal function for MQ coder, usually invoked through macros.
Returns the new value of the `creg' variable. */
extern void
dst_arith_coder__activate(dst_arith_state_ptr state);
/* Activates the embedded arithmetic coding engine to code symbols. Note
that between initialization or a previous call to
`dst_arith_coder__deactivate' and the activation call, any number of
`raw' binary digits may be included in the bit-stream without compromising
any of the properties of the final interleaved bit-stream. The activate
call first byte aligns the bit-stream segment pushed out so far in
preparation for MQ codeword generation. */
extern int
dst_arith_coder__deactivate(dst_arith_state_ptr state, int easy);
/* Terminates current codeword segment at a minimal number of whole
bytes, such that the decoder will be able to correctly decode all
coded symbols after appending an infinite sequence of FF's to the
terminated codeword segment. The embedded arithmetic coding engine
is then deactivated so that any further arithmetic coding calls are
illegal until the coder is activated for generation of a new
arithmetic codeword segment by a call to `dst_arith_coder__activate'.
The function returns the number of bytes output to the code stream
up to the termination point.
The function may be called even if the arithmetic coder has not
yet been activated, in which case there is nothing to terminate and
the function instead byte aligns any portion of the code stream which
has been written out and returns the number of bytes which have been
output so far.
The `easy' argument identifies whether or not a standard "simple"
algorithm should be used to compute the termination length, rather than
a near optimal algorithm which is otherwise used. */
extern void
dst_arith_coder__flush(dst_arith_state_ptr state);
/* The encoder must be deactivated before calling flush, unless it was
never activated once. */
extern int
dst_arith_coder__get_minimum_bytes(dst_arith_state_ptr state,
dst_heap_unit_ptr heap, int heap_pos,
int min_bytes, int max_bytes);
#ifdef DST_LOG_SYMBOLS
extern void
dst_arith_coder__log_symbol(dst_arith_state_ptr state,
dst_context_state_ptr ctxt,
std_int symbol); /* David T mod */
#endif /* DST_LOG_SYMBOLS */
#endif /* DST_ARITH_ENCODER_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -