📄 hpdz_dequant.c
字号:
dz_dequantizer_ref self = (dz_dequantizer_ref) base;
component_info_ptr comp_info;
float scale, *dp, **dpp;
ifc_int **cast_buf, *sp, **spp, val;
int i, j;
comp_info = self->components + component_idx;
assert((component_idx < self->num_components) &&
(band_idx < comp_info->num_bands));
scale = comp_info->info[comp_info->num_bands*level_idx+band_idx].scale;
cast_buf = (ifc_int **) block_buf;
self->decoder->pull_block(self->decoder,cast_buf,component_idx,level_idx,
band_idx,block_rows,block_cols,top_row,left_col);
if (self->three_eighths)
for (spp=cast_buf, dpp=block_buf, j=block_rows; j > 0; j--, spp++, dpp++)
for (sp=*spp, dp=*dpp, i=block_cols; i > 0; i--, sp++, dp++)
{
val = *sp;
three_eighths_convert(val);
val = (val<0)?(MIN_IFC_INT-val):val; /* Convert to two's-comp. */
*dp = ((float) val) * scale;
}
else
for (spp=cast_buf, dpp=block_buf, j=block_rows; j > 0; j--, spp++, dpp++)
for (sp=*spp, dp=*dpp, i=block_cols; i > 0; i--, sp++, dp++)
{
val = *sp;
val = (val<0)?(MIN_IFC_INT-val):val; /* Convert to two's-comp. */
*dp = ((float) val) * scale;
}
}
/*****************************************************************************/
/* STATIC __pull_block_fixed */
/*****************************************************************************/
static void
__pull_block_fixed(dequantizer_ref base, ifc_int **block_buf,
int component_idx, int level_idx, int band_idx,
int block_rows, int block_cols,
int top_row, int left_col)
{
dz_dequantizer_ref self = (dz_dequantizer_ref) base;
component_info_ptr comp_info;
ifc_int *sp, **spp, shift, val;
int i, j;
comp_info = self->components + component_idx;
assert((component_idx < self->num_components) &&
(band_idx < comp_info->num_bands));
shift = comp_info->info[comp_info->num_bands*level_idx+band_idx].left_shift;
self->decoder->pull_block(self->decoder,block_buf,component_idx,level_idx,
band_idx,block_rows,block_cols,top_row,left_col);
if (self->three_eighths)
{
if (shift == 0)
for (spp=block_buf, j=block_rows; j > 0; j--, spp++)
for (sp=*spp, i=block_cols; i > 0; i--, sp++)
{ /* The `shift'=0 case occurs almost always in practice. */
val = *sp;
three_eighths_convert(val);
val = (val<0)?(MIN_IFC_INT-val):val;
*sp = val;
}
else if (shift > 0)
for (spp=block_buf, j=block_rows; j > 0; j--, spp++)
for (sp=*spp, i=block_cols; i > 0; i--, sp++)
{
val = *sp;
three_eighths_convert(val);
if (val < 0)
val = - ((val & MAX_IFC_MAG) << shift);
else
val <<= shift;
*sp = val;
}
else
for (shift=-shift, spp=block_buf, j=block_rows; j > 0; j--, spp++)
for (sp=*spp, i=block_cols; i > 0; i--, sp++)
{
val = *sp;
three_eighths_convert(val);
if (val < 0)
val = - ((val & MAX_IFC_MAG) >> shift);
else
val >>= shift;
*sp = val;
}
}
else
{
if (shift == 0)
for (spp=block_buf, j=block_rows; j > 0; j--, spp++)
for (sp=*spp, i=block_cols; i > 0; i--, sp++)
{ /* The `shift'=0 case occurs almost always in practice. */
val = *sp;
val = (val<0)?(MIN_IFC_INT-val):val;
*sp = val;
}
else if (shift > 0)
for (spp=block_buf, j=block_rows; j > 0; j--, spp++)
for (sp=*spp, i=block_cols; i > 0; i--, sp++)
{
val = *sp;
if (val < 0)
val = - ((val & MAX_IFC_MAG) << shift);
else
val <<= shift;
*sp = val;
}
else
for (shift=-shift, spp=block_buf, j=block_rows; j > 0; j--, spp++)
for (sp=*spp, i=block_cols; i > 0; i--, sp++)
{
val = *sp;
if (val < 0)
val = - ((val & MAX_IFC_MAG) >> shift);
else
val >>= shift;
*sp = val;
}
}
}
/*****************************************************************************/
/* STATIC __pull_tree_float */
/*****************************************************************************/
static void
__pull_tree_float(dequantizer_ref base, float **tree_buf,
int levels, int component_idx, int root_row, int root_col)
{
dz_dequantizer_ref self = (dz_dequantizer_ref) base;
component_info_ptr comp_info;
float *scp, **scpp, *dp, **dpp;
ifc_int **cast_buf, *sp, **spp, val;
int i, j;
assert(component_idx < self->num_components);
comp_info = self->components + component_idx;
if (comp_info->tree_scales == NULL)
{
int lev, b, r, c;
float scale;
if (comp_info->num_bands != 4)
{
fprintf(stderr,"The dequantizer's `pull_tree' functions may be used "
"only with\n Mallat-style decompositions!\n");
exit(-1);
}
comp_info->tree_scales = scpp = (float **)
local_malloc(sizeof(float *)*(size_t)(1<<comp_info->num_levels));
for (r=0; r < (1<<comp_info->num_levels); r++)
scpp[r] = (float *)
local_malloc(sizeof(float)*(size_t)(1<<comp_info->num_levels));
for (lev=0; lev < comp_info->num_levels; lev++)
{
for (b=(lev==0)?0:1; b < 4; b++)
{
scale = comp_info->info[comp_info->num_bands*lev+b].scale;
switch (b) {
case LL_BAND: r = c = 0; break;
case HL_BAND: r = 0; c = (1<<lev); break;
case LH_BAND: r = (1<<lev); c = 0; break;
case HH_BAND: r = c = (1<<lev); break;
default: assert(0);
}
for (j=1<<lev; j > 0; j--, r++)
for (scp=scpp[r]+c, i=1<<lev; i > 0; i--)
*(scp++) = scale;
}
}
}
cast_buf = (ifc_int **) tree_buf;
self->decoder->pull_tree(self->decoder,cast_buf,levels,
component_idx,root_row,root_col);
if (self->three_eighths)
for (scpp=comp_info->tree_scales, spp=cast_buf, dpp=tree_buf,
j=1<<levels; j > 0; j--, scpp++, spp++, dpp++)
for (scp=*scpp, sp=*spp, dp=*dpp,
i=1<<levels; i > 0; i--, sp++, dp++, scp++)
{
val = *sp;
three_eighths_convert(val);
val = (val<0)?(MIN_IFC_INT-val):val; /* Convert to two's-comp. */
*dp = ((float) val) * *scp;
}
else
for (scpp=comp_info->tree_scales, spp=cast_buf, dpp=tree_buf,
j=1<<levels; j > 0; j--, scpp++, spp++, dpp++)
for (scp=*scpp, sp=*spp, dp=*dpp,
i=1<<levels; i > 0; i--, sp++, dp++, scp++)
{
val = *sp;
val = (val<0)?(MIN_IFC_INT-val):val; /* Convert to two's-comp. */
*dp = ((float) val) * *scp;
}
}
/*****************************************************************************/
/* STATIC __pull_tree_fixed */
/*****************************************************************************/
static void
__pull_tree_fixed(dequantizer_ref base, ifc_int **tree_buf, int levels,
int component_idx, int root_row, int root_col)
{
dz_dequantizer_ref self = (dz_dequantizer_ref) base;
component_info_ptr comp_info;
ifc_int *shp, **shpp, *sp, **spp, shift, val;
int i, j;
assert(component_idx < self->num_components);
comp_info = self->components + component_idx;
if (comp_info->tree_scales == NULL)
{
int lev, b, r, c;
ifc_int shift;
if (comp_info->num_bands != 4)
{
fprintf(stderr,"The dequantizer's `pull_tree' functions may be used "
"only with\n Mallat-style decompositions!\n");
exit(-1);
}
comp_info->tree_shifts = shpp = (ifc_int **)
local_malloc(sizeof(ifc_int *)*(size_t)(1<<comp_info->num_levels));
for (r=0; r < (1<<comp_info->num_levels); r++)
shpp[r] = (ifc_int *)
local_malloc(sizeof(ifc_int)*(size_t)(1<<comp_info->num_levels));
for (lev=0; lev < comp_info->num_levels; lev++)
{
for (b=(lev==0)?0:1; b < 4; b++)
{
shift=comp_info->info[comp_info->num_bands*lev+b].left_shift;
switch (b) {
case LL_BAND: r = c = 0; break;
case HL_BAND: r = 0; c = (1<<lev); break;
case LH_BAND: r = (1<<lev); c = 0; break;
case HH_BAND: r = c = (1<<lev); break;
default: assert(0);
}
for (j=1<<lev; j > 0; j--, r++)
for (shp=shpp[r]+c, i=1<<lev; i > 0; i--)
*(shp++) = shift;
}
}
}
self->decoder->pull_tree(self->decoder,tree_buf,levels,
component_idx,root_row,root_col);
if (self->three_eighths)
{
for (shpp=comp_info->tree_shifts, spp=tree_buf,
j=1<<levels; j > 0; j--, shpp++, spp++)
for (shp=*shpp, sp=*spp, i=1<<levels; i > 0; i--, sp++, shp++)
{
val = *sp;
shift = *shp;
three_eighths_convert(val);
if (shift >= 0)
{
if (val < 0)
val = -((val & MAX_IFC_MAG) << shift);
else
val <<= shift;
}
else
{
if (val < 0)
val = -((val & MAX_IFC_MAG) >> shift);
else
val >>= shift;
}
*sp = val;
}
}
else
{
for (shpp=comp_info->tree_shifts, spp=tree_buf,
j=1<<levels; j > 0; j--, shpp++, spp++)
for (shp=*shpp, sp=*spp, i=1<<levels; i > 0; i--, sp++, shp++)
{
val = *sp;
shift = *shp;
if (shift >= 0)
{
if (val < 0)
val = -((val & MAX_IFC_MAG) << shift);
else
val <<= shift;
}
else
{
if (val < 0)
val = -((val & MAX_IFC_MAG) >> shift);
else
val >>= shift;
}
*sp = val;
}
}
}
/*****************************************************************************/
/* STATIC __terminate */
/*****************************************************************************/
static void
__terminate(dequantizer_ref base)
{
dz_dequantizer_ref self = (dz_dequantizer_ref) base;
component_info_ptr comp_info;
int comp, r;
if (self->components != NULL)
{
for (comp=0; comp < self->num_components; comp++)
{
comp_info = self->components + comp;
local_free(comp_info->info);
if (comp_info->tree_scales != NULL)
{
for (r=0; r < (1<<comp_info->num_levels); r++)
local_free(comp_info->tree_scales[r]);
local_free(comp_info->tree_scales);
}
if (comp_info->tree_shifts != NULL)
{
for (r=0; r < (1<<comp_info->num_levels); r++)
local_free(comp_info->tree_shifts[r]);
local_free(comp_info->tree_shifts);
}
}
local_free(self->components);
}
local_free(self);
}
/*****************************************************************************/
/* EXTERN create_deadzone_dequantizer */
/*****************************************************************************/
dequantizer_ref
create_deadzone_dequantizer(void)
{
dz_dequantizer_ref result;
result = (dz_dequantizer_ref)
local_malloc(sizeof(dz_dequantizer_obj));
memset(result,0,sizeof(dz_dequantizer_obj));
result->base.initialize = __initialize;
result->base.print_usage = __print_usage;
result->base.pull_line_float = __pull_line_float;
result->base.pull_line_fixed = __pull_line_fixed;
result->base.pull_block_float = __pull_block_float;
result->base.pull_block_fixed = __pull_block_fixed;
result->base.pull_tree_float = __pull_tree_float;
result->base.pull_tree_fixed = __pull_tree_fixed;
result->base.terminate = __terminate;
return((dequantizer_ref) result);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -