📄 ebcot_lite_encode_passes.c
字号:
assert(val == (val & MSE_LUT_MASK));
delta_mse_acc += ebcot_initial_mse_lut[val];
symbol = ebcot_sc_lut[(ctxt>>SIGN_POS)&0x00FF];
csp = csp_base + SC_OFFSET + (symbol & 0x000F);
symbol &= MIN_IFC_INT;
symbol ^= sign;
emit_symbol(state,A,C,word,avail,rho,symbol,csp);
ctxt |= SELF_SIG;
cp[-row_gap-2+1] |= FAR_SIG;
cp[-row_gap-1+1] |= BR_SIG;
cp[-row_gap+1+1] |= BL_SIG;
cp[-row_gap+2+1] |= FAR_SIG;
cp[row_gap-2+1] |= FAR_SIG;
cp[row_gap-1+1] |= TR_SIG;
cp[row_gap+1+1] |= TL_SIG;
cp[row_gap+2+1] |= FAR_SIG;
cp[-2+1] |= FAR_SIG;
cp[2+1] |= FAR_SIG;
if (sign)
{ /* Negative sample. */
cp[-1+1] |= CR_SIG | H_NVE_SIG;
cp[1+1] |= CL_SIG | H_NVE_SIG;
cp[-row_gap+1] |= BC_SIG | V_NVE_SIG;
cp[row_gap+1] |= TC_SIG | V_NVE_SIG;
}
else
{ /* Positive sample. */
cp[-1+1] |= CR_SIG | H_PVE_SIG;
cp[1+1] |= CL_SIG | H_PVE_SIG;
cp[-row_gap+1] |= BC_SIG | V_PVE_SIG;
cp[row_gap+1] |= TC_SIG | V_PVE_SIG;
}
}
cp[1] = ctxt;
}
ctxt = cp[0];
if ((ctxt & context_mask) &&
!(ctxt & (IS_REFINED | SELF_SIG | OUT_OF_BOUNDS)))
{
ctxt |= IS_REFINED;
val = dp[0];
symbol = (val & mask);
csp = csp_base + (ZC_OFFSET + zc_lut[ctxt & ZC_MASK]);
emit_symbol(state,A,C,word,avail,rho,symbol,csp);
if (symbol)
{ /* New significant value; update contexts & code sign */
ifc_int sign;
sign = val & MIN_IFC_INT; /* Save sign bit. */
val &= MAX_IFC_INT;
val >>= mse_downshift; val <<= mse_upshift;
assert(val == (val & MSE_LUT_MASK));
delta_mse_acc += ebcot_initial_mse_lut[val];
symbol = ebcot_sc_lut[(ctxt>>SIGN_POS)&0x00FF];
csp = csp_base + SC_OFFSET + (symbol & 0x000F);
symbol &= MIN_IFC_INT;
symbol ^= sign;
emit_symbol(state,A,C,word,avail,rho,symbol,csp);
ctxt |= SELF_SIG;
cp[-row_gap-2] |= FAR_SIG;
cp[-row_gap-1] |= BR_SIG;
cp[-row_gap+1] |= BL_SIG;
cp[-row_gap+2] |= FAR_SIG;
cp[row_gap-2] |= FAR_SIG;
cp[row_gap-1] |= TR_SIG;
cp[row_gap+1] |= TL_SIG;
cp[row_gap+2] |= FAR_SIG;
cp[-2] |= FAR_SIG;
cp[2] |= FAR_SIG;
if (sign)
{ /* Negative sample. */
cp[-1] |= CR_SIG | H_NVE_SIG;
cp[1] |= CL_SIG | H_NVE_SIG;
cp[-row_gap] |= BC_SIG | V_NVE_SIG;
cp[row_gap] |= TC_SIG | V_NVE_SIG;
}
else
{ /* Positive sample. */
cp[-1] |= CR_SIG | H_PVE_SIG;
cp[1] |= CL_SIG | H_PVE_SIG;
cp[-row_gap] |= BC_SIG | V_PVE_SIG;
cp[row_gap] |= TC_SIG | V_PVE_SIG;
}
}
cp[0] = ctxt;
}
}
}
state->A=A; state->C=C; state->word=word; state->rho=rho;
state->available_bits=avail;
return((delta_mse_acc+2)>>2);
}
/*****************************************************************************/
/* STATIC mag_refinement_pass_func */
/*****************************************************************************/
static std_int
mag_refinement_pass_func(block_master_ptr master)
/* This function refines all samples which have already been found to be
significant. */
{
register std_int *d_cp;
register std_int d_mask;
register std_short *cp;
register ifc_int *dp;
register int c;
register std_short ctxt;
register arith_state_ptr state;
register std_int A, C, word, rho;
register context_state_ptr csp;
std_short avail;
ifc_int val, symbol, mask, lsb, shift;
ifc_int mse_upshift, mse_downshift;
std_int delta_mse_acc;
int rows, cols, row_gap, half_inter_row, r;
std_short *context;
ifc_int *data;
context_state_ptr csp_base;
code_subblock_ptr subblock, last_subblock;
shift = master->bit_idx - 1;
assert(shift > 0);
lsb = 1 << shift;
mask = (ifc_int)(MAX_IFC_INT & ((-1)<<shift));
data = master->sample_buffer;
context = master->context_buffer;
d_mask = SELF_SIG; d_mask <<= 16; d_mask |= SELF_SIG;
row_gap = master->row_gap;
assert(!(row_gap & 1));
delta_mse_acc = 0;
mse_downshift = shift - (MSE_LUT_BITS-1);
mse_upshift = (mse_downshift<0)?-mse_downshift:0;
mse_downshift += mse_upshift;
state = &(master->coder_state);
A=state->A; C=state->C; word=state->word; rho=state->rho;
avail=state->available_bits; csp_base = state->contexts;
last_subblock = master->last_subblock;
for (subblock=master->first_subblock; subblock <= last_subblock; subblock++)
if (subblock->significant)
{
rows = subblock->rows;
cols = subblock->cols;
half_inter_row = (row_gap-cols)>>1;
dp = data + subblock->offset;
cp = context + subblock->offset;
d_cp = (std_int *) cp;
for (r=rows; r > 0; r--, dp+=half_inter_row<<1, cp+=half_inter_row<<1,
d_cp+=half_inter_row)
for (c=cols; c > 0; c-=2, dp+=2, cp+=2, d_cp++)
{
if (!((*d_cp) & d_mask))
continue;
ctxt = cp[0];
if ((ctxt & SELF_SIG) && !(ctxt & (IS_REFINED | OUT_OF_BOUNDS)))
{
val = dp[0];
val &= MAX_IFC_INT;
symbol = val >> shift;
val >>= mse_downshift; val <<= mse_upshift;
delta_mse_acc +=
ebcot_refinement_mse_lut[val & MSE_LUT_MASK];
csp = csp_base + MAG_OFFSET;
if (symbol < 4)
{
if (ctxt & 0x00FF)
csp++;
}
else
csp += 2;
symbol &= 1; /* New magnitude bit. */
emit_symbol(state,A,C,word,avail,rho,symbol,csp);
}
ctxt = cp[1];
if ((ctxt & SELF_SIG) && !(ctxt & (IS_REFINED | OUT_OF_BOUNDS)))
{
val = dp[1];
val &= MAX_IFC_INT;
symbol = val >> shift;
val >>= mse_downshift; val <<= mse_upshift;
delta_mse_acc +=
ebcot_refinement_mse_lut[val & MSE_LUT_MASK];
csp = csp_base + MAG_OFFSET;
if (symbol < 4)
{
if (ctxt & 0x00FF)
csp++;
}
else
csp += 2;
symbol &= 1; /* New magnitude bit. */
emit_symbol(state,A,C,word,avail,rho,symbol,csp);
}
}
}
state->A=A; state->C=C; state->word=word; state->rho=rho;
state->available_bits=avail;
return((delta_mse_acc+2)>>2);
}
/*****************************************************************************/
/* STATIC dummy_pass_func */
/*****************************************************************************/
static std_int
dummy_pass_func(block_master_ptr master)
/* This function may be installed into the `pass_funcs' array managed
by any subband in order to render one or more passes impotent. It
simply returns zero, indicating that the pass had no effect on
reconstruction error. */
{
return(0);
}
/* ========================================================================= */
/* --------------------------- External Functions -------------------------- */
/* ========================================================================= */
/*****************************************************************************/
/* EXTERN ebcot_set_pass_funcs_and_masks */
/*****************************************************************************/
void
ebcot_set_pass_funcs_and_masks(band_info_ptr band, int band_idx)
{
int p;
band->pass_funcs[0] = first_pass_func; band->pass_masks[0] = 0;
for (p=1; p < PASSES_PER_BITPLANE; p++)
if (p == 1)
{
band->pass_funcs[p] = zero_refinement_pass_func;
if (band_idx == LL_BAND)
band->pass_masks[p] = 0x00FF;
else if (band_idx == HH_BAND)
band->pass_masks[p] = TL_SIG | TR_SIG | BL_SIG | BR_SIG;
else
band->pass_masks[p] = CL_SIG | CR_SIG;
}
else if (p == 2)
{
band->pass_funcs[p] = reverse_zero_refinement_pass_func;
band->pass_masks[p] = 0x00FF;
}
else if (p == 3)
{
band->pass_funcs[p] = mag_refinement_pass_func;
band->pass_masks[p] = 0; /* Mask is not used during mag refinment. */
}
else
{
band->pass_funcs[p] = dummy_pass_func;
band->pass_masks[p] = 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -