📄 hplx_analysis.c
字号:
/*****************************************************************************/
/* Copyright 1998, Hewlett-Packard Company */
/* All rights reserved */
/* File: "hplx_analysis.c" */
/* Description: Reference implementation of the `hplx_analysis' object. */
/* Author: David Taubman */
/* Affiliation: Hewlett-Packard and */
/* The University of New South Wales, Australia */
/* Acknowledgements: Partly developed in collaboration with */
/* Christos Chrysafis of HP Labs */
/* Version: VM9.0 */
/* Last Revised: 27 April, 2001 */
/*****************************************************************************/
/*****************************************************************************/
/* Modified to include Lagrangian Rate Allocation */
/* Copyright 1999 Fujifilm Software Colifornia Inc. */
/* Copyright 1999 Science Applications International Corporation (SAIC). */
/* Copyright 1995 University of Arizona, Arizona Board of Regents. */
/* All Rights Reserved for modified parts. */
/*****************************************************************************/
/*****************************************************************************/
/* 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 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 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 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 <assert.h>
#include <ifc.h>
#include <markers.h>
#include <stdio.h>
#include <stdlib.h>
#include "hplx_analysis_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_analysis_stage_ref
create_hplx_vert_analysis_by_convolution(void);
extern hplx_analysis_stage_ref
create_hplx_hor_analysis_by_convolution(void);
extern hplx_analysis_stage_ref
create_hplx_vert_analysis_by_lifting(void);
extern hplx_analysis_stage_ref
create_hplx_hor_analysis_by_lifting(void);
static hplx_analysis_stage_ref
create_hplx_analysis_leaf(void); /* This is a forward declaration. */
/* ========================================================================= */
/* --------------------------- Internal Functions -------------------------- */
/* ========================================================================= */
/* SAIC General Decomp. Begin mods */
/*****************************************************************************/
/* STATIC create_decomposition_tree */
/*****************************************************************************/
static hplx_analysis_stage_ref
create_decomposition_tree(int num_levels, int component_idx,
forward_info_ref info, quantizer_ref quantizer,
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 */
encoder_ref encoder, 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_analysis_stage' object at the root of the
transformation tree. The function fills in all the public member
fields of the base `hplx_analysis_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_max_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_analysis_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_analysis_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->quant = quantizer;
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/Fuji LRA begin */
if (info->set_stats != NULL)
result->get_lra_stats = 1;
/* SAIC/Fuji LRA end */
/* SAIC/Sharp/Fuji Xmask begin */
result->encoder = encoder;
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,quantizer,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 */
encoder, 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__ANALYSIS,component_idx,
num_levels,NULL,NULL,NULL,NULL);
vert_kernel_type =
info->get_kernel_type(info,INFO__VERTICAL,INFO__ANALYSIS,component_idx,
num_levels,NULL,NULL,NULL,NULL);
if (vert_kernel_type == INFO__CONVOLUTION)
result = create_hplx_vert_analysis_by_convolution();
else
result = create_hplx_vert_analysis_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->quant = NULL; /* Not a leaf stage. */
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/Fuji LRA begin */
if (info->set_stats != NULL)
result->get_lra_stats = 1;
/* SAIC/Fuji LRA end */
/* SAIC/Sharp/Fuji Xmask begin */
result->encoder = encoder;
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 */
result->band_idx = -1;
for (vert_idx=0; vert_idx < vert_limit; vert_idx++)
{
if (hor_kernel_type == INFO__CONVOLUTION)
stage = create_hplx_hor_analysis_by_convolution();
else
stage = create_hplx_hor_analysis_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->quant = NULL;
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/Fuji LRA begin */
if (info->set_stats != NULL)
stage->get_lra_stats = 1;
/* SAIC/Fuji LRA end */
/* SAIC/Sharp/Fuji Xmask begin */
stage->encoder = encoder;
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 */
stage->band_idx = -1; /* Not a leaf stage. */
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))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -