📄 ebcot_lite_decode_passes.c
字号:
/*****************************************************************************/
/* Copyright 1998, Hewlett-Packard Company */
/* All rights reserved */
/* File: "ebcot_lite_decode_passes.c" */
/* Description: Entropy decoding passes for EBCOT (lite) */
/* Author: David Taubman */
/* Affiliation: Hewlett-Packard and */
/* The University of New South Wales, Australia */
/* Version: VM7.0 */
/* Last Revised: 30 March, 2000 */
/*****************************************************************************/
/*****************************************************************************/
/* Modified to incorporate MQ-coder by Mitsubishi Electric Corp. */
/* Copyright 1999, Mitsubishi Electric Corp. */
/* All rights reserved for modified parts */
/*****************************************************************************/
/*****************************************************************************/
/* Modified by David Taubman to improve implementation efficiency. Copyright */
/* 1999 by Hewlett-Packard Company with all rights reserved for the modified */
/* parts. */
/*****************************************************************************/
/*****************************************************************************/
/* Modified to combine entropy coders */
/* Copyright 1999 Science Applications International Corporation (SAIC). */
/* Copyright 1999 University of Arizona, Arizona Board of Regents. */
/* All Rights Reserved for modified parts. */
/*****************************************************************************/
#include <local_services.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <ifc.h>
#include "ebcot_common.h"
#include "ebcot_decoder.h"
/* ========================================================================= */
/* -------------------- Simpler Decoding Pass Functions -------------------- */
/* ========================================================================= */
/* The following functions are implemented in a manner which can be
easily carried to any number of different software/dsp platforms.
Further improvements in execution speed may be obtained by targeting
64-bit architectures or by resorting to the implementation tricks
which appear in the "su_..." versions of the functions in the section
following the banner, "Speedup Decoding Pass Functions". The latter
functions, however, are significantly more difficult to understand. */
/*****************************************************************************/
/* STATIC first_pass_func */
/*****************************************************************************/
static void
first_pass_func(block_master_ptr master)
/* This function must be applied once, at the start of each quantization
layer (bit plane). It looks for all samples whose context word has the
IS_REFINED flag turned off. These samples are brought up to date with
the current bit plane, while all other samples simply have their
IS_REFINED flag turned off in preparation for future passes. Note that
bringing samples up to date with the current bit plane never involves
magnitude refinement. */
{
register std_short *cp;
register std_int cum_delta, thresh;
register ifc_int *dp;
register int c;
register std_short ctxt;
register ifc_int shift;
register dst_arith_state_ptr state;
register dst_context_state_ptr csp;
register ifc_int val, symbol;
register unsigned long creg;
register std_int areg;
int ct;
ifc_int lsb;
std_short non_causal;
std_byte *zc_lut;
int cols, stripe_gap, r;
dst_context_state_ptr csp_base;
state = &(master->coder_state);
if (!state->mqd.active)
dst_arith_coder__activate(state);
assert((master->bit_idx > 0) &&
((master->interleaved_row_gap & 3) == 0));
shift = master->bit_idx;
lsb = 1 << shift;
areg = state->mqd.areg; creg = state->mqd.creg; ct = state->mqd.ct;
dst_compute_ac_thresh(areg,creg,thresh); cum_delta = 0;
csp_base = state->contexts;
zc_lut = master->zc_lut;
non_causal = 1 - master->causal;
cols = master->width;
stripe_gap = master->interleaved_row_gap;
cp = master->interleaved_context_buffer;
dp = master->interleaved_sample_buffer;
for (r=master->stripes; r > 0; r--,
dp+=stripe_gap-(cols<<2), cp+=stripe_gap-(cols<<2))
for (c=cols; c > 0; c--, dp+=4, cp+=4)
{
if ((((std_int *) cp)[0] | ((std_int *) cp)[1]) == 0)
{ /* Special processing to reduce average symbol count. */
csp = csp_base + AGG_OFFSET;
dst_get_symbol_skewed(areg,creg,thresh,cum_delta,
ct,state,symbol,csp);
if (!symbol)
continue;
else
{ /* Get the run-length and jump into the appropriate
location in the regular decoding procedure. */
csp = csp_base + UNI_OFFSET;
dst_get_symbol_skewed(areg,creg,thresh,cum_delta,
ct,state,symbol,csp);
ctxt = symbol<<1;
dst_get_symbol_skewed(areg,creg,thresh,cum_delta,
ct,state,symbol,csp);
ctxt |= symbol;
switch (ctxt) {
case 0: ctxt = cp[0]; goto new_sig0;
case 1: ctxt = cp[1]; goto new_sig1;
case 2: ctxt = cp[2]; goto new_sig2;
case 3: ctxt = cp[3]; goto new_sig3;
}
}
}
ctxt = cp[0];
if (!(ctxt & (SELF_SIG | OUT_OF_BOUNDS | IS_REFINED)))
{
csp = csp_base + (ZC_OFFSET + zc_lut[ctxt & ZC_MASK]);
dst_get_symbol_skewed(areg,creg,thresh,cum_delta,
ct,state,symbol,csp);
if (symbol)
{ /* New significant value; update contexts & get sign. */
new_sig0:
val = ebcot_sc_lut[(ctxt>>SIGN_POS)&0x00FF];
csp = csp_base + SC_OFFSET + (val & 0x000F);
val &= MIN_IFC_INT;
dst_get_symbol_skewed(areg,creg,thresh,cum_delta,
ct,state,symbol,csp);
val ^= (symbol << (IMPLEMENTATION_PRECISION-1));
ctxt |= SELF_SIG;
cp[(-stripe_gap+3)-4] |= (non_causal << BR_POS);
cp[(-stripe_gap+3)+4] |= (non_causal << BL_POS);
cp[1-4] |= TR_SIG;
cp[1+4] |= TL_SIG;
if (val)
{ /* Negative sample. */
cp[4] |= CL_SIG | H_NVE_SIG;
cp[-4] |= CR_SIG | H_NVE_SIG;
cp[(-stripe_gap+3)]|= (non_causal << BC_POS) |
(non_causal << V_NVE_POS);
cp[1] |= TC_SIG | V_NVE_SIG;
}
else
{ /* Positive sample. */
cp[4] |= CL_SIG | H_PVE_SIG;
cp[-4] |= CR_SIG | H_PVE_SIG;
cp[(-stripe_gap+3)]|= (non_causal << BC_POS) |
(non_causal << V_PVE_POS);
cp[1] |= TC_SIG | V_PVE_SIG;
}
val |= lsb + (lsb>>1);
dp[0] = val; /* Write new non-zero value back to buffer. */
}
}
cp[0] = ctxt & ~IS_REFINED;
ctxt = cp[1];
if (!(ctxt & (SELF_SIG | OUT_OF_BOUNDS | IS_REFINED)))
{
csp = csp_base + (ZC_OFFSET + zc_lut[ctxt & ZC_MASK]);
dst_get_symbol_skewed(areg,creg,thresh,cum_delta,
ct,state,symbol,csp);
if (symbol)
{ /* New significant value; update contexts & get sign. */
new_sig1:
val = ebcot_sc_lut[(ctxt>>SIGN_POS)&0x00FF];
csp = csp_base + SC_OFFSET + (val & 0x000F);
val &= MIN_IFC_INT;
dst_get_symbol_skewed(areg,creg,thresh,cum_delta,
ct,state,symbol,csp);
val ^= (symbol << (IMPLEMENTATION_PRECISION-1));
ctxt |= SELF_SIG;
cp[0-4] |= BR_SIG;
cp[0+4] |= BL_SIG;
cp[2-4] |= TR_SIG;
cp[2+4] |= TL_SIG;
if (val)
{ /* Negative sample. */
cp[1+4] |= CL_SIG | H_NVE_SIG;
cp[1-4] |= CR_SIG | H_NVE_SIG;
cp[0] |= BC_SIG | V_NVE_SIG;
cp[2] |= TC_SIG | V_NVE_SIG;
}
else
{ /* Positive sample. */
cp[1+4] |= CL_SIG | H_PVE_SIG;
cp[1-4] |= CR_SIG | H_PVE_SIG;
cp[0] |= BC_SIG | V_PVE_SIG;
cp[2] |= TC_SIG | V_PVE_SIG;
}
val |= lsb + (lsb>>1);
dp[1] = val; /* Write new non-zero value back to buffer. */
}
}
cp[1] = ctxt & ~IS_REFINED;
ctxt = cp[2];
if (!(ctxt & (SELF_SIG | OUT_OF_BOUNDS | IS_REFINED)))
{
csp = csp_base + (ZC_OFFSET + zc_lut[ctxt & ZC_MASK]);
dst_get_symbol_skewed(areg,creg,thresh,cum_delta,
ct,state,symbol,csp);
if (symbol)
{ /* New significant value; update contexts & get sign. */
new_sig2:
val = ebcot_sc_lut[(ctxt>>SIGN_POS)&0x00FF];
csp = csp_base + SC_OFFSET + (val & 0x000F);
val &= MIN_IFC_INT;
dst_get_symbol_skewed(areg,creg,thresh,cum_delta,
ct,state,symbol,csp);
val ^= (symbol << (IMPLEMENTATION_PRECISION-1));
ctxt |= SELF_SIG;
cp[1-4] |= BR_SIG;
cp[1+4] |= BL_SIG;
cp[3-4] |= TR_SIG;
cp[3+4] |= TL_SIG;
if (val)
{ /* Negative sample. */
cp[2+4] |= CL_SIG | H_NVE_SIG;
cp[2-4] |= CR_SIG | H_NVE_SIG;
cp[1] |= BC_SIG | V_NVE_SIG;
cp[3] |= TC_SIG | V_NVE_SIG;
}
else
{ /* Positive sample. */
cp[2+4] |= CL_SIG | H_PVE_SIG;
cp[2-4] |= CR_SIG | H_PVE_SIG;
cp[1] |= BC_SIG | V_PVE_SIG;
cp[3] |= TC_SIG | V_PVE_SIG;
}
val |= lsb + (lsb>>1);
dp[2] = val; /* Write new non-zero value back to buffer. */
}
}
cp[2] = ctxt & ~IS_REFINED;
ctxt = cp[3];
if (!(ctxt & (SELF_SIG | OUT_OF_BOUNDS | IS_REFINED)))
{
csp = csp_base + (ZC_OFFSET + zc_lut[ctxt & ZC_MASK]);
dst_get_symbol_skewed(areg,creg,thresh,cum_delta,
ct,state,symbol,csp);
if (symbol)
{ /* New significant value; update contexts & get sign. */
new_sig3:
val = ebcot_sc_lut[(ctxt>>SIGN_POS)&0x00FF];
csp = csp_base + SC_OFFSET + (val & 0x000F);
val &= MIN_IFC_INT;
dst_get_symbol_skewed(areg,creg,thresh,cum_delta,
ct,state,symbol,csp);
val ^= (symbol << (IMPLEMENTATION_PRECISION-1));
ctxt |= SELF_SIG;
cp[2-4] |= BR_SIG;
cp[2+4] |= BL_SIG;
cp[stripe_gap-4] |= TR_SIG;
cp[stripe_gap+4] |= TL_SIG;
if (val)
{ /* Negative sample. */
cp[3+4] |= CL_SIG | H_NVE_SIG;
cp[3-4] |= CR_SIG | H_NVE_SIG;
cp[2] |= BC_SIG | V_NVE_SIG;
cp[stripe_gap] |= TC_SIG | V_NVE_SIG;
}
else
{ /* Positive sample. */
cp[3+4] |= CL_SIG | H_PVE_SIG;
cp[3-4] |= CR_SIG | H_PVE_SIG;
cp[2] |= BC_SIG | V_PVE_SIG;
cp[stripe_gap] |= TC_SIG | V_PVE_SIG;
}
val |= lsb + (lsb>>1);
dp[3] = val; /* Write new non-zero value back to buffer. */
}
}
cp[3] = ctxt & ~IS_REFINED;
}
areg -= cum_delta; creg -= ((unsigned) cum_delta) << 16;
state->mqd.areg = areg; state->mqd.creg = creg; state->mqd.ct = ct;
}
/*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -