📄 hplx_synthesis.c
字号:
/*****************************************************************************/
/* Copyright 1998, Hewlett-Packard Company */
/* All rights reserved */
/* File: "hplx_synthesis.c" */
/* Description: Reference implementation of the `hplx_synthesis' object. */
/* Author: David Taubman */
/* Affiliation: Hewlett-Packard and */
/* The University of New South Wales, Australia */
/* Acknowledgements: Partly developed in collaboration with */
/* Christos Chrysafix of HP Labs */
/* Version: VM9.0 */
/* Last Revised: 20 April, 2001 */
/*****************************************************************************/
/*****************************************************************************/
/* Modified by David Taubman to support arbitrary reference points for the */
/* transform and the various regular partitions, so as to facilitate */
/* cropping and geometric transformations in the compressed domain and to */
/* enable full support for CRF's single-sample overlap Wavelet transform, */
/* as originally documented in Seoul. Changes are too numerous to flag */
/* individually within the code. Changes copyrighted by HP with all rights */
/* reserved for the modified parts. */
/*****************************************************************************/
/*****************************************************************************/
/* Modified by David Taubman to allow SSO-DWT style extension at tile */
/* boundaries. 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. */
/*****************************************************************************/
/*****************************************************************************/
/* Modified by Jianxin Wei, Australian Defence Force Academy (ADFA) */
/* to implement the Odd Tile-Size Low-Pass First Convention (OTLPF_CONVENTION)*/
/* Copyright 2000 University of New South Wales, Australia. */
/* All rights reserved for modified parts. */
/*****************************************************************************/
#include <local_services.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <ifc.h>
#include <markers.h>
#include "hplx_synthesis_local.h"
/* SAIC/Sharp/Fuji Xmask begin */
#ifndef MAX
#define MAX(A,B) ((A)>(B)?(A):(B))
#endif
#ifndef MIN
#define MIN(A,B) ((A)<(B)?(A):(B))
#endif
/* SAIC/Sharp/Fuji Xmask end */
extern hplx_synthesis_stage_ref
create_hplx_vert_synthesis_by_convolution(void);
extern hplx_synthesis_stage_ref
create_hplx_hor_synthesis_by_convolution(void);
extern hplx_synthesis_stage_ref
create_hplx_vert_synthesis_by_lifting(void);
extern hplx_synthesis_stage_ref
create_hplx_hor_synthesis_by_lifting(void);
static hplx_synthesis_stage_ref
create_hplx_synthesis_leaf(void); /* This is a forward declaration. */
/* ========================================================================= */
/* --------------------------- Internal Functions -------------------------- */
/* ========================================================================= */
/* SAIC General Decomp. Begin mods */
/*****************************************************************************/
/* STATIC create_decomposition_tree */
/*****************************************************************************/
static hplx_synthesis_stage_ref
create_decomposition_tree(int num_levels, int component_idx,
reverse_info_ref info, dequantizer_ref dequantizer,
int use_floats, int remaining_hp_descent,
int root_band_idx, int usePsExtension, int sso_ext,
/* OTLPF_CONVENTION begin; JX Wei ADFA, WJ Zeng Sharp */
int otlpf_convention,
/* OTLPF_CONVENTION end; JX Wei ADFA, WJ Zeng Sharp */
/* SAIC/Sharp/Fuji Xmask begin */
decoder_ref decoder, float alpha, float beta,
int minlevel, int win_width, int bits_retained, int respect_block_boundaries,
/* SAIC/Sharp/Fuji Xmask end */
int vert_limit, int horiz_limit,
int remaining_max_vert_hp_descent,
int remaining_max_horiz_hp_descent,
int *decomp_sequence,
int *decomp_sequence_pos,
int first_max_horiz_hp_descent,
int first_max_vert_hp_descent)
/* This is the key function in this source file. It is responsible for
constructing the Wavelet transformation tree for the indicated component,
returning the `hplx_synthesis_stage' object at the root of the
transformation tree. The function fills in all the public member
fields of the base `hplx_synthesis_stage' objects, but does not invoke
their initialization functions.
The function is implemented recursively. The last two arguments
are introduced to extend the recursive implementation to assist in
the creation of non-Mallat decomposition structures. At the root of
any resolution level, both of these will hold 0. If, however, a
high-pass subband in some resolution level needs to be further
decomposed with additional four-way splits, then the
`remaining_hp_descent' will hold the difference between the `max_hp_descent'
value for the resolution level and the number of four-way splits which
have been applied already to arrive at this point. In this case, the
`root_band_idx' argument holds the index which the subband which needs
to be further split would have if no further splitting were required.
This allows correct band indices to be formed for the new subbands
obtained by splitting the root of the high-pass descent tree,
according to the rules prescribed in the "ifc.h" header file, under the
topic entitled "Interpretation of Level and Band Indices". */
{
hplx_synthesis_stage_ref result, stage;
int hor_kernel_type, vert_kernel_type, vert_idx, hor_idx, band_idx;
int first_split_in_level;
int current_opcode;
int new_decomp_sequence[16];
int new_decomp_sequence_pos = 0;
if (num_levels == 0)
{ /* Create single `hplx_analysis_leaf' object and terminate recursion. */
assert(root_band_idx == LL_BAND);
result = create_hplx_synthesis_leaf();
result->sso_ext = sso_ext;
result->use_floats = use_floats;
result->component_idx = component_idx;
result->level_idx = 0;
result->band_idx = root_band_idx;
result->branches[0] = result->branches[1] = NULL;
result->dequant = dequantizer;
result->usePsExtension = usePsExtension;
/* OTLPF_CONVENTION begin; JX Wei ADFA, WJ Zeng Sharp */
result->otlpf_convention = otlpf_convention;
/* OTLPF_CONVENTION end; JX Wei ADFA, WJ Zeng Sharp */
/* SAIC/Sharp/Fuji Xmask begin */
result->decoder = decoder;
result->alpha = alpha;
result->beta = beta;
result->minlevel = minlevel;
result->win_width = win_width;
result->bits_retained = bits_retained;
result->respect_block_boundaries = respect_block_boundaries;
result->info = info;
/* SAIC/Sharp/Fuji Xmask end */
return(result);
}
if (remaining_hp_descent == 0)
{
info->get_level_info(info,component_idx,num_levels,NULL,
&remaining_hp_descent,NULL,decomp_sequence);
remaining_max_vert_hp_descent = remaining_hp_descent;
remaining_max_horiz_hp_descent = remaining_hp_descent;
first_max_vert_hp_descent = remaining_hp_descent;
first_max_horiz_hp_descent = remaining_hp_descent;
if (remaining_hp_descent == 0) /* This is an empty level. Skip over. */
return(create_decomposition_tree(num_levels-1,component_idx,
info,dequantizer,use_floats,0,0,
usePsExtension,sso_ext,
/* OTLPF_CONVENTION begin; JX Wei ADFA, WJ Zeng Sharp */
otlpf_convention,
/* OTLPF_CONVENTION end; JX Wei ADFA, WJ Zeng Sharp */
/* SAIC/Sharp/Fuji Xmask begin */
decoder, alpha, beta, minlevel, win_width, bits_retained,
respect_block_boundaries,
/* SAIC/Sharp/Fuji Xmask end */
0, 0, 0, 0,
new_decomp_sequence,
&new_decomp_sequence_pos,
first_max_horiz_hp_descent,
first_max_vert_hp_descent));
first_split_in_level = 1;
current_opcode = decomp_sequence[*decomp_sequence_pos];
(*decomp_sequence_pos)++;
assert(current_opcode > 0);
switch (current_opcode) {
case 1:
vert_limit = 2;
horiz_limit = 2;
break;
case 2:
vert_limit = 1;
horiz_limit = 2;
remaining_max_vert_hp_descent++; /* Offset dis-joint splitting */
break;
case 3:
vert_limit = 2;
horiz_limit = 1;
remaining_max_horiz_hp_descent++; /* Offset dis-joint splitting */
break;
}
}
else
first_split_in_level = 0;
hor_kernel_type =
info->get_kernel_type(info,INFO__HORIZONTAL,INFO__SYNTHESIS,component_idx,
num_levels,NULL,NULL,NULL,NULL);
vert_kernel_type =
info->get_kernel_type(info,INFO__VERTICAL,INFO__SYNTHESIS,component_idx,
num_levels,NULL,NULL,NULL,NULL);
if (vert_kernel_type == INFO__CONVOLUTION)
result = create_hplx_vert_synthesis_by_convolution();
else
result = create_hplx_vert_synthesis_by_lifting();
result->vert_limit = vert_limit;
result->horiz_limit = horiz_limit;
result->sso_ext = sso_ext;
result->use_floats = use_floats;
result->component_idx = component_idx;
result->level_idx = num_levels;
result->direction = INFO__VERTICAL;
result->dequant = NULL; /* Not a leaf stage. */
result->band_idx = -1;
result->usePsExtension = usePsExtension;
/* OTLPF_CONVENTION begin; JX Wei ADFA, WJ Zeng Sharp */
result->otlpf_convention = otlpf_convention;
/* OTLPF_CONVENTION end; JX Wei ADFA, WJ Zeng Sharp */
/* SAIC/Sharp/Fuji Xmask begin */
result->decoder = decoder;
result->alpha = alpha;
result->beta = beta;
result->minlevel = minlevel;
result->win_width = win_width;
result->bits_retained = bits_retained;
result->respect_block_boundaries = respect_block_boundaries;
result->info = info;
/* SAIC/Sharp/Fuji Xmask end */
for (vert_idx=0; vert_idx < vert_limit; vert_idx++)
{
if (hor_kernel_type == INFO__CONVOLUTION)
stage = create_hplx_hor_synthesis_by_convolution();
else
stage = create_hplx_hor_synthesis_by_lifting();
result->branches[vert_idx] = stage;
stage->vert_limit = vert_limit;
stage->horiz_limit = horiz_limit;
stage->sso_ext = sso_ext;
stage->use_floats = use_floats;
stage->component_idx = component_idx;
stage->level_idx = num_levels;
stage->direction = INFO__HORIZONTAL;
stage->dequant = NULL;
stage->band_idx = -1; /* Not a leaf stage. */
stage->usePsExtension = usePsExtension;
/* OTLPF_CONVENTION begin; JX Wei ADFA, WJ Zeng Sharp */
stage->otlpf_convention = otlpf_convention;
/* OTLPF_CONVENTION end; JX Wei ADFA, WJ Zeng Sharp */
/* SAIC/Sharp/Fuji Xmask begin */
stage->decoder = decoder;
stage->alpha = alpha;
stage->beta = beta;
stage->minlevel = minlevel;
stage->win_width = win_width;
stage->bits_retained = bits_retained;
stage->respect_block_boundaries = respect_block_boundaries;
stage->info = info;
/* SAIC/Sharp/Fuji Xmask end */
for (hor_idx=0; hor_idx < horiz_limit; hor_idx++)
{
int orient;
int vert_hp_descent, horiz_hp_descent;
if ((vert_idx == 0) && (hor_idx == 0))
orient = LL_BAND;
else if ((vert_idx == 0) && (hor_idx == 1))
orient = HL_BAND;
else if ((vert_idx == 1) && (hor_idx == 0))
orient = LH_BAND;
else
orient = HH_BAND;
band_idx = root_band_idx + orient *
(1 << 2*(remaining_hp_descent - 1));
info->get_band_info(info,component_idx,num_levels,band_idx,
NULL,NULL,&vert_hp_descent,&horiz_hp_descent,NULL,NULL,NULL);
if (band_idx == 0)
{ /* Must be the LL band for the level. Propagate split into
next level. */
assert(first_split_in_level);
stage->branches[hor_idx] =
create_decomposition_tree(num_levels-1,component_idx,info,
dequantizer,use_floats,0,0,
usePsExtension,sso_ext,
/* OTLPF_CONVENTION begin; JX Wei ADFA, WJ Zeng Sharp */
otlpf_convention,
/* OTLPF_CONVENTION end; JX Wei ADFA, WJ Zeng Sharp */
/* SAIC/Sharp/Fuji Xmask begin */
decoder, alpha, beta, minlevel, win_width, bits_retained,
respect_block_boundaries,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -