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

📄 ref_reverse_roi.c

📁 JPEG2000实现的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************************/
/* Copyright 1998, Hewlett-Packard Company                                   */
/* All rights reserved                                                       */
/* File: "ref_reverse_roi.c"                                                 */
/* Description: Reference implementation of the `reverse_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_reverse_roi_local.h"

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

/* 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,
                                  reverse_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,
                                               &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;
  info->get_kernel_type(info,INFO__VERTICAL,INFO__SYNTHESIS,component_idx,
                        num_levels,&low_neg,&low_pos,&high_neg,&high_pos);
  vert_stage = ref_roi_create_vertical_stage();

  vert_stage->vert_limit = vert_limit;
  vert_stage->horiz_limit = horiz_limit;

  if (vert_limit > 1) {
    vert_stage->branch_neg_supports[0] = low_neg;
    vert_stage->branch_pos_supports[0] = low_pos;
    vert_stage->branch_neg_supports[1] = high_neg;
    vert_stage->branch_pos_supports[1] = high_pos;
  }
  else {
    vert_stage->branch_neg_supports[0] = 0;
    vert_stage->branch_pos_supports[0] = 0;
    vert_stage->branch_neg_supports[1] = 0;
    vert_stage->branch_pos_supports[1] = 0;
  }

  vert_stage->direction = INFO__VERTICAL;
  vert_stage->parent = parent;
  info->get_kernel_type(info,INFO__HORIZONTAL,INFO__SYNTHESIS,component_idx,
                        num_levels,&low_neg,&low_pos,&high_neg,&high_pos);
  for (vert_idx=0; vert_idx < vert_limit; vert_idx++)
    {
      hor_stage = ref_roi_create_horizontal_stage();
      vert_stage->branches[vert_idx] = hor_stage;

      hor_stage->vert_limit = vert_limit;
      hor_stage->horiz_limit = horiz_limit;

      if (horiz_limit > 1) {
        hor_stage->branch_neg_supports[0] = low_neg;
        hor_stage->branch_pos_supports[0] = low_pos;
        hor_stage->branch_neg_supports[1] = high_neg;
        hor_stage->branch_pos_supports[1] = high_pos;
      }
      else {
        hor_stage->branch_neg_supports[0] = 0;
        hor_stage->branch_pos_supports[0] = 0;
        hor_stage->branch_neg_supports[1] = 0;
        hor_stage->branch_pos_supports[1] = 0;
      }

      hor_stage->direction = INFO__HORIZONTAL;
      hor_stage->parent = vert_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))
            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 LL band for the level.  Propagate split into
                 next level. */
              assert(first_split_in_level);
              hor_stage->branches[hor_idx] =
                create_roi_mask_generation_tree(num_levels-1,component_idx,
                                                info,lev-1,hor_stage,0,0,
                                                0, 0, 0, 0,
                                                new_decomp_sequence,
                                                &new_decomp_sequence_pos,
                                                first_max_horiz_hp_descent,
                                                first_max_vert_hp_descent);

              if (!lev->roi_generation_needed)
                return(vert_stage);
            }
          else if ((remaining_hp_descent > 1) &&
                   ((remaining_max_vert_hp_descent >
                     (first_max_vert_hp_descent - vert_hp_descent + 1)) ||
                   ((remaining_max_horiz_hp_descent >
                     (first_max_horiz_hp_descent - horiz_hp_descent + 1)))))

            { /* Band needs to be further decomposed within current
                 level. */
              int new_vert_limit=2, new_horiz_limit=2;
              int new_remaining_max_vert_hp_descent = remaining_max_vert_hp_descent-1;
              int new_remaining_max_horiz_hp_descent = remaining_max_horiz_hp_descent-1;

              current_opcode = decomp_sequence[*decomp_sequence_pos];
              (*decomp_sequence_pos)++;
              assert(current_opcode > 0);
              switch (current_opcode) {
                case 1:
                  new_vert_limit = 2;
                  new_horiz_limit = 2;
                  new_remaining_max_vert_hp_descent = remaining_max_vert_hp_descent-1;
                  new_remaining_max_horiz_hp_descent = remaining_max_horiz_hp_descent-1;
                  break;
                case 2:
                  new_vert_limit = 1;
                  new_horiz_limit = 2;
                  new_remaining_max_vert_hp_descent = remaining_max_vert_hp_descent;
                  new_remaining_max_horiz_hp_descent = remaining_max_horiz_hp_descent-1;
                  break;

⌨️ 快捷键说明

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