📄 hpdz_quant.c
字号:
/*****************************************************************************/
/* Copyright 1998, Hewlett-Packard Company */
/* All rights reserved */
/* File: "hpdz_quant.c" */
/* Description: Deadzone quantizer implementation. */
/* Author: David Taubman */
/* Affiliation: Hewlett-Packard and */
/* The University of New South Wales, Australia */
/* Version: VM9.0 */
/* Last Revised: 20 April, 2001 */
/*****************************************************************************/
/*****************************************************************************/
/* Modified by David Taubman to support interface modifications, arbitrary */
/* changes in coding parameters from component to component and from tile */
/* to tile, to support the full generality of PART-1 of the JPEG2000 */
/* standard, and to support most anticipated generality of PART-2. Changes */
/* are too numerous to flag individually within the code, which in some */
/* places has been completely rewritten. All changes copyrighted by HP with */
/* all rights reserved for the modified parts. */
/*****************************************************************************/
/*****************************************************************************/
/* Modified for general wavelet decompositions. */
/* Copyright 2000 Science Applications International Corporation (SAIC). */
/* Copyright 1995 University of Arizona, Arizona Board of Regents. */
/* All Rights Reserved for modified parts. */
/*****************************************************************************/
/*****************************************************************************/
/* Modified for general offset and scalar quantization. */
/* Copyright 2000 The MITRE Corporation. */
/* All Rights Reserved for modified parts. */
/*****************************************************************************/
#include <local_services.h>
#include <stdlib.h>
/* SAIC General Decomp. Begin */
#include <stdio.h>
#ifndef MAX
#define MAX(A,B) ((A)>(B)?(A):(B))
#endif
/* SAIC General Decomp. End */
#include <math.h>
#include <string.h>
#include <assert.h>
#include <ifc.h>
#include <markers.h>
#include "hpdz_quant_local.h"
/* ========================================================================= */
/* ---------------------------- Internal Functions ------------------------- */
/* ========================================================================= */
/*****************************************************************************/
/* STATIC destroy_component_structures */
/*****************************************************************************/
static void
destroy_component_structures(hpdz_component_info_ptr comp)
{
hpdz_level_info_ptr lev;
int n;
if (comp->levels == NULL)
return;
for (n=0; n <= comp->num_levels; n++)
{
lev = comp->levels + n;
if (lev->bands != NULL)
local_free(lev->bands);
}
local_free(comp->levels);
}
/*****************************************************************************/
/* STATIC start_tile */
/*****************************************************************************/
static void
start_tile(hpdz_quantizer_ref self)
{
forward_info_ref info = self->info;
hpdz_component_info_ptr comp;
hpdz_level_info_ptr lev;
hpdz_band_info_ptr band;
int num_components, num_levels, c, n, b;
num_components = self->num_components;
for (c=0; c < num_components; c++)
{
comp = self->components + c;
destroy_component_structures(comp);
comp->num_levels = num_levels =
info->get_var_tile_info(info,c,NULL,NULL,NULL,NULL,NULL);
comp->levels = (hpdz_level_info_ptr)
local_malloc(HPDZ_MEM_KEY,sizeof(hpdz_level_info)*(num_levels+1));
for (n=0; n <= num_levels; n++)
{
int max_hp_descent;
float step_size, scale_nz;
int exponent, extra_lsbs;
int valid_band;
lev = comp->levels + n;
if (n == 0)
lev->min_band = lev->max_band = LL_BAND;
else
{
info->get_level_info(info,c,n,NULL,&max_hp_descent,NULL,NULL);
if (max_hp_descent == 0)
{
lev->min_band = 0;
lev->max_band = -1;
continue;
}
else
{
lev->min_band = 1 << (max_hp_descent+max_hp_descent-2);
lev->max_band = (1<<(max_hp_descent+max_hp_descent)) - 1;
}
}
lev->bands = (hpdz_band_info_ptr)
local_malloc(HPDZ_MEM_KEY,
sizeof(hpdz_band_info)*(lev->max_band+1));
for (b=lev->min_band; b <= lev->max_band; b++)
{
band = lev->bands + b;
info->get_band_info(info,c,n,b,NULL,NULL,NULL,NULL,NULL,NULL,&valid_band);
if (!valid_band)
continue;
info->get_quant_info(info,c,n,b,&step_size,&exponent,NULL,
&extra_lsbs, NULL, &scale_nz);
if (extra_lsbs >= 0)
band->scale = ((float)(1<<extra_lsbs)) / step_size;
else
band->scale = 1.0F / (step_size * ((float)(1<<-extra_lsbs)));
band->right_shift = (ifc_int)(exponent - extra_lsbs);
/* MITRE General Offset/SQ Begin */
band->nz = (float)(scale_nz*step_size);
if (n==0 && b==lev->min_band && scale_nz != 0)
local_printf(0,76," Comp %d Scale_nz = %f\n", c,
scale_nz);
/* MITRE General Offset/SQ End */
}
}
}
}
/* ========================================================================= */
/* ------------------------- Interface Implementation ---------------------- */
/* ========================================================================= */
/*****************************************************************************/
/* STATIC __initialize */
/*****************************************************************************/
static void
__initialize(quantizer_ref base, int num_components,
forward_info_ref info, encoder_ref encoder,
stream_out_ref stream, cmdl_ref cmdl)
{
hpdz_quantizer_ref self = (hpdz_quantizer_ref) base;
std_uint choice = 0;
stream->declare_marker_elt(stream,-1,MARKER_QCD_WHICH,0,2,1);
stream->set_marker_val(stream,-1,MARKER_QCD_WHICH,0,choice,0);
self->num_components = num_components;
self->encoder = encoder;
self->info = info;
self->components = (hpdz_component_info_ptr)
local_malloc(HPDZ_MEM_KEY,sizeof(hpdz_component_info)*num_components);
/* SAIC General Decomp. Begin */
{
canvas_dims tile_dims;
int max_hp_descent;
int num_levels;
int b, n, p, ptiles;
char **params;
if ((p = cmdl->extract(cmdl,"-Xwt_output",-1,¶ms)) >= 0) {
if ((ptiles = cmdl->extract(cmdl,"-Ftiles",-1,¶ms)) >= 0) {
local_printf(0, 80, "The `-Xwt_output' option should not be used with "
"`-Ftiles'. Therefore, `-Xwt_output' is ignored");
}
else {
if (p != 1)
local_error("The `-Xwt_output' argument requires on parameter!");
self->wt_output_file = params[0];
/* Begin Aerospace MCT mods */
self->info->get_fixed_tile_info(self->info, 0, 0, NULL, NULL, &tile_dims,
NULL, NULL, NULL, NULL,NULL,NULL,NULL);
/* End Aerospace MCT mods */
self->wt_output = (float **)
local_malloc(HPDZ_MEM_KEY, tile_dims.rows*sizeof(float *));
self->wt_output -= tile_dims.top_row;
self->wt_output[tile_dims.top_row] = (float *)
local_malloc(HPDZ_MEM_KEY, tile_dims.rows * tile_dims.cols *
sizeof(float));
self->wt_output[tile_dims.top_row] -= tile_dims.left_col;
for (n=(tile_dims.top_row+1); n<(tile_dims.top_row+tile_dims.rows); n++) {
self->wt_output[n] = self->wt_output[n-1] + tile_dims.cols;
}
num_levels = info->get_var_tile_info(info,0,NULL,NULL,NULL,NULL,NULL);
self->min_band = (int *)
local_malloc(HPDZ_MEM_KEY, (num_levels+1)*sizeof(int));
self->max_band = (int *)
local_malloc(HPDZ_MEM_KEY, (num_levels+1)*sizeof(int));
self->band_dims = (canvas_dims **)
local_malloc(HPDZ_MEM_KEY, (num_levels+1)*sizeof(canvas_dims *));
self->current_band_line = (int **)
local_malloc(HPDZ_MEM_KEY, (num_levels+1)*sizeof(int *));
self->valid_band = (int **)
local_malloc(HPDZ_MEM_KEY, (num_levels+1)*sizeof(int *));
for (n=0; n<(num_levels+1); n++) {
if (n == 0)
self->min_band[n] = self->max_band[n] = LL_BAND;
else {
info->get_level_info(self->info,0,n,NULL, &max_hp_descent,NULL,NULL);
self->min_band[n] = 1 << (max_hp_descent+max_hp_descent-2);
self->max_band[n] = (1<<(max_hp_descent+max_hp_descent)) - 1;
}
self->band_dims[n] = (canvas_dims *)
local_malloc(HPDZ_MEM_KEY, sizeof(canvas_dims)*(self->max_band[n]+1));
self->current_band_line[n] = (int *)
local_malloc(HPDZ_MEM_KEY, sizeof(int)*(self->max_band[n]+1));
self->valid_band[n] = (int *)
local_malloc(HPDZ_MEM_KEY, sizeof(int)*(self->max_band[n]+1));
for (b=self->min_band[n]; b<=self->max_band[n];
b++) {
self->info->get_band_info(info,0,n,b,NULL,NULL,NULL,NULL,NULL,NULL,
&(self->valid_band[n][b]));
if (!self->valid_band[n][b])
continue;
self->info->get_band_location_info(info,0,n,b,&(self->band_dims[n][b]));
}
}
}
}
}
/* SAIC General Decomp. End */
start_tile(self);
}
/*****************************************************************************/
/* STATIC __get_usage */
/*****************************************************************************/
static char **
__get_usage(quantizer_ref base)
{
static char *args[] =
{ "-Qtcq",
"Use trellis coded quantization on entropy coder blocks.",
/* MITRE General Offset/SQ Begin */
"-Qnz <nz> (default nz=0.0)",
"Use generalized scalar quantization, with a zero bin of sized to "
"2(1-nz)*stepsize. nz in (-1,1). This only works with the irreversible "
"filters. Default behavior is the Part 1 deadzone.",
/* MITRE General Offset/SQ End */
NULL };
return(args);
}
/*****************************************************************************/
/* STATIC __next_tile */
/*****************************************************************************/
static void
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -