⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ref_forward_roi.c

📁 JPEG2000实现的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
/*****************************************************************************/
/* Copyright 1998, Hewlett-Packard Company                                   */
/* All rights reserved                                                       */
/* File: "ref_forward_roi.c"                                                 */
/* Description: Reference implementation of the `forward_roi' object.        */
/* Author: David Taubman                                                     */
/* Affiliation: Hewlett-Packard and                                          */
/*              The University of New South Wales, Australia                 */
/* Acknowledgements: Partly developed in collaboration with Mathias Larsson  */
/*                   and his colleagues at Ericsson, Sweden                  */
/* Version: VM9.0                                                            */
/* Last Revised: 19 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 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>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <ifc.h>
#include <markers.h>
#include "ref_forward_roi_local.h"

/* ========================================================================= */
/* ---------------------------- Internal Functions ------------------------- */
/* ========================================================================= */

/*****************************************************************************/
/* STATIC                  install_rectangular_region                        */
/*****************************************************************************/

static void
  install_rectangular_region(roi_tile_ptr tile, canvas_dims_ptr comp_dims,
                             int boost,
                             float top, float left, float height, float width)

 /* Maps the relative coordinates for a new rectangular region of interest
    into each of the image components and adds a new element to each of the
    corresponding component region lists. */

{
  roi_region_ptr region;
  int max_dim;
  double val;

  max_dim = (comp_dims->rows > comp_dims->cols)?
            comp_dims->rows:comp_dims->cols;
  region = (roi_region_ptr)
    local_malloc(ROI_MEM_KEY,sizeof(roi_region));
  region->is_rectangular = 1;
  region->boost = boost;
  region->rect.left = (int)(left*comp_dims->cols);
  region->rect.right = (int)((left+width)*comp_dims->cols) - 1;
  region->rect.top = (int)(top*comp_dims->rows);
  region->rect.bottom = (int)((top+height)*comp_dims->rows) - 1;
  region->circle.centre_row = (comp_dims->rows >> 1);
  region->circle.centre_col = (comp_dims->cols >> 1);
  region->circle.radius = max_dim;
  val = ((double)(region->circle.radius)) + 0.5;
  region->circle.radius_squared = val*val;
  region->rect.left += comp_dims->left_col;
  region->rect.right += comp_dims->left_col;
  region->circle.centre_col += comp_dims->left_col;
  region->rect.top += comp_dims->top_row;
  region->rect.bottom += comp_dims->top_row;
  region->circle.centre_row += comp_dims->top_row;
  region->next = tile->regions;
  tile->regions = region;
}

/*****************************************************************************/
/* STATIC                    install_circular_region                         */
/*****************************************************************************/

static void
  install_circular_region(roi_tile_ptr tile, canvas_dims_ptr comp_dims,
                          int boost,
                          float centre_row, float centre_col, float radius)

 /* Maps the relative coordinates for a new circular region of interest
    into each of the image components and adds a new element to each of the
    corresponding component region lists. */

{
  roi_region_ptr region;
  int max_dim;
  double val;

  max_dim = (comp_dims->rows > comp_dims->cols)?
            comp_dims->rows:comp_dims->cols;
  region = (roi_region_ptr)
    local_malloc(ROI_MEM_KEY,sizeof(roi_region));
  region->boost = boost;
  region->circle.centre_row = (int)(centre_row*comp_dims->rows);
  region->circle.centre_col = (int)(centre_col*comp_dims->cols);
  region->circle.radius = (int)(radius*max_dim + 0.5);
  val = ((double)(region->circle.radius));
  region->circle.radius_squared = val*val;
  region->circle.centre_row += comp_dims->top_row;
  region->circle.centre_col += comp_dims->left_col;
  region->rect.top = region->circle.centre_row - region->circle.radius;
  region->rect.bottom = region->circle.centre_row + region->circle.radius;
  region->rect.left = region->circle.centre_col - region->circle.radius;
  region->rect.right = region->circle.centre_col + region->circle.radius;
  region->next = tile->regions;
  tile->regions = region;
}

/*****************************************************************************/
/* STATIC                 check_partition_implicit                           */
/*****************************************************************************/

static void
  check_partition_implicit(roi_component_info_ptr comp_info,
                           int component_idx, forward_info_ref info)

 /* This function determines whether or not a partition is implicitly
    recoverable at the decoder, based upon the following criteria:
    1) there must be only one non-zero `boost' value; and 2) the boost, B,
    must satisfy B >= (M-E), where M is the number of magnitude bits in an
    `ifc_int' word, i.e. M=IMPLEMENTATION_PRECISION-1, and E is the number
    of extra least significant bits returned by `forward_info__get_quant_info'.
    This relationship must hold for all subbands in the relevant component
    within the current tile.  If these conditions are not satisfied, the
    function generates an error message which indicates how the boost values
    must be changed to be compatible with implict recovery of the ROI
    partition at the decoder.  The test should be repeated for each tile. */

{
  roi_tile_ptr tile;
  roi_level_info_ptr lev;
  roi_region_ptr region;
  int n, b;
  int min_boost, extra_lsbs;

  /* SAIC General Decomp. Begin */
  int valid_band;
  /* SAIC General Decomp. End */

  tile = comp_info->tiles + comp_info->current_tile_idx;
  for (region=tile->regions; region != NULL; region=region->next)
    if (region->boost != tile->max_boost)
      local_error("The `-Rmax_shift' flag may only be used in conjunction "
                  "with a single region boost, of sufficiently large "
                  "magnitude.  You cannot have multiple regions with "
                  "different boosts!");
  min_boost = 0;
  for (n=0; n <= comp_info->num_levels; n++)
    {
      lev = comp_info->levels + n;

      for (b=lev->min_band; b <= lev->max_band; b++)
        {
          info->get_band_info(info,component_idx,n,b,NULL,NULL,NULL,NULL,NULL,NULL,&valid_band);
          if (!valid_band)
            continue;
          info->get_quant_info(info,component_idx,n,b,
                               NULL,NULL,NULL,&extra_lsbs, NULL, NULL);
          if (min_boost < (IMPLEMENTATION_PRECISION-1-extra_lsbs))
            min_boost = IMPLEMENTATION_PRECISION-1-extra_lsbs;
        }
    }
  if (tile->max_boost < min_boost)
    local_error("The `-Rmax_shift' flag may not be used with the supplied "
                "region boost values.  For the decoder to be able to "
                "implicitly recover the ROI partition information from the "
                "decoded sample values themselves, it is necessary to use "
                "a boost value of at least %d in specifying the regions of "
                "interest!",min_boost);
}

/* SAIC General Decomp. Begin mods */
/*****************************************************************************/
/* STATIC                create_roi_mask_generation_tree                     */
/*****************************************************************************/

static roi_stage_ref
  create_roi_mask_generation_tree(int num_levels, int component_idx,
                                  forward_info_ref info,
                                  roi_level_info_ptr lev, roi_stage_ref parent,
                                  int remaining_hp_descent, 
                                  int root_band_idx,
                                  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 ROI mask generation tree, returning a reference to
    the `roi_stage' object which is at root of the tree.  The function fills
    in all public member fields of the base `roi_stage' objects, with the
    exception of the `frame_size' field, the contents of the `buffer' field
    and the root object's `regions' field.
        The function is implemented recursively.  The last two arguments are
    introduced to extend the recursive implementation to assist in the
    creation of mask generation trees for 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 spits, then the
    `remaining_max_hp_descent' argument 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 furhter 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". */

{
  roi_stage_ref leaf_stage, vert_stage, hor_stage;
  int vert_idx, hor_idx, band_idx;
  int first_split_in_level;
  int low_neg, low_pos, high_neg, high_pos;

  int current_opcode;
  int new_decomp_sequence[16];
  int new_decomp_sequence_pos = 0;

  if (num_levels == 0)
    { /* Create an `roi_band' leaf object to terminate the recursion. */
      assert(root_band_idx == LL_BAND);
      if (!lev->roi_generation_needed)
        leaf_stage = NULL;
      else
        {
          leaf_stage = ref_roi_create_band_stage();
          leaf_stage->parent = parent;
        }
      lev->bands[LL_BAND] = (roi_band_ref) leaf_stage;
      return(leaf_stage);
    }
  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_roi_mask_generation_tree(num_levels-1,component_idx,
                                               info,lev-1,parent,0,0,
                                               0, 0, 0, 0,
                                               new_decomp_sequence,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -