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

📄 std_reverse_info.c

📁 JPEG2000实现的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*****************************************************************************/
/* Copyright 1998, Hewlett-Packard Company                                   */
/* All rights reserved                                                       */
/* File: "std_reverse_info.c"                                                */
/* Description: Standard implementation of the `reverse_info' object.        */
/* Author: David Taubman                                                     */
/* Affiliation: Hewlett-Packard and                                          */
/*              The University of New South Wales, Australia                 */
/* Version: VM9.0                                                            */
/* Last Revised: 19 April, 2001                                              */
/*****************************************************************************/

/*****************************************************************************/
/* Modifications tagged with comment lines or delimiters involving the       */
/* string, "David T mod" or "mod by David T", have been made by David        */
/* Taubman; they are copyrighted by Hewlett-Packard Company with all rights  */
/* reserved for the 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 reflect slight modifications in the canvas   */
/* coordinate system conventions.  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 overlapping tiles.  Changes            */
/* copyrighted by HP with all rights reserved for the modified parts.        */
/*****************************************************************************/

/*****************************************************************************/
/* Modified by David Taubman to implement changes in Tokyo between CD and    */
/* FCD for Part-1 of the standard.  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 <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <assert.h>
#include <ifc.h>
#include <markers.h>
#include "std_reverse_info_local.h"

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

/*****************************************************************************/
/* MACRO                          CEIL_RATIO                                 */
/*****************************************************************************/

#define CEIL_RATIO(_num,_den) (((_num)+(_den)-1)/(_den))


/*****************************************************************************/
/* STATIC                       initialize_tiles                             */
/*****************************************************************************/

static void
  initialize_tiles(std_reverse_info_ref self)

 /* Sets the coordinates for each tile in the newly created array of tiles
    referenced from `self' and initializes the `components' field for each
    tile to point to the `default_components' array in the `self' object,
    corresponding to the default coding parameters. */

{
  canvas_dims_ptr tile_ref, grid_ref;
  std_tile_info_ptr info;
  int tiles_wide, tiles_high, left, top, next_left, next_top, r, c, idx;

  tile_ref = &(self->tile_dims);
  grid_ref = &(self->grid_dims);
  tiles_wide = self->tiles_wide;
  tiles_high = self->tiles_high;
  assert((tiles_wide > 0) && (tiles_high > 0));
  for (idx=0, top=tile_ref->top_row,
       r=0; r < tiles_high; r++, top=next_top)
    {
      next_top = top + tile_ref->rows;
      if (top < grid_ref->top_row)
        top = grid_ref->top_row;
      if (next_top > (grid_ref->top_row+grid_ref->rows))
        next_top = grid_ref->top_row + grid_ref->rows;
      for (left=tile_ref->left_col,
           c=0; c < tiles_wide; c++, left=next_left, idx++)
        {
          next_left = left + tile_ref->cols;
          if (left < grid_ref->left_col)
            left = grid_ref->left_col;
          if (next_left > (grid_ref->left_col+grid_ref->cols))
            next_left = grid_ref->left_col + grid_ref->cols;
          info = self->tiles + idx;
          info->idx = idx;
          info->x_idx = c;
          info->y_idx = r;
          info->components = self->default_components;
          info->dims.left_col = left;
          info->dims.top_row = top;
          info->dims.cols = next_left - left;
          info->dims.rows = next_top - top;
        }
    }
}

/* SAIC General Decomp. Begin */
/*****************************************************************************/
/* STATIC                 decode_general_decomp_sequence                     */
/*****************************************************************************/

static int
  decode_general_decomp_sequence(std_level_info_ptr lev, int level_idx,
                                 int all_hp_descent, int vert_hp_descent,
                                 int horiz_hp_descent, int root_band_idx,
                                 int *decomp_sequence, int *decomp_sequence_pos,
                                 int vert_limit, int hor_limit,
                                 int *vert_hp_descent_chg,
                                 int *horiz_hp_descent_chg, int chg_pos)

 /* This function provides for much more general wavelet decompositions.  It
    does so by allowing the band->hp_descent value to differ from the
    lev->max_hp_descent value for the parent level of band.  The input
    `decomp_sequence_pos' specifies how to split a level with a series of
    integers from 0 to 3.  Value 0 indicates that the current subband should
    not be decomposed further.  Value 1 indicates that the current subband
    should be split both horizontally and vertically.  Value 2 indicates that
    the current subband should be split in just the horizontal direction.
    Value 3 indicates that the current subband should be split in just the
    vertical direction.  The input `decomp_sequence_pos' string provides
    information for at least the current level.  Information in this string
    after that required for the current level specifies spliting information
    for remaining levels.  This function returns the character position to the
    string for the next level.  If the character at that position is NULL, the
    previous character position passed to this routine will be used for
    remaining levels.  Note that this function assumes that the LL_BAND
    resulting from the first horizontal and vertical splits of a level are
    ignored unless that subband is the only subband for level 0. */

{
  std_band_info_ptr band;
  int vert_idx, hor_idx, band_idx;
  int first_decomp_sequence_pos;
  int orient;
  int retval = 0;
  int decomp_sequence_length = 0;
  int current_opcode;
  int n;

  assert(chg_pos < 4);

  while (decomp_sequence[decomp_sequence_length] != -1)
    decomp_sequence_length++;

  if ((vert_limit < 0) && (hor_limit < 0)) {
    first_decomp_sequence_pos = *decomp_sequence_pos;
    if (level_idx == 0) {
      if (lev->bands != NULL) {
        band = lev->bands;
        band->vert_hp_descent = 0;
        band->horiz_hp_descent = 0;
        band->valid_band = 1;
        for (n=0; n<4; n++) {
          band->vert_hp_descent_chg[n] = 1;
          band->horiz_hp_descent_chg[n] = 1;
        }
      }
      return(0);
    }
    if ((*decomp_sequence_pos + 1) > decomp_sequence_length)
      local_error("Decomposition string for `-Fgen_decomp' is too short.  "
                  "Check string to avoid errors!");
    current_opcode = decomp_sequence[*decomp_sequence_pos];
    (*decomp_sequence_pos)++;
    switch(current_opcode) {
      case 0:
        local_error("Decomposition string for `-Fgen_decomp' is either too "
                    "short or too long since a character `0' has been detected "
                    "at the base of a resolution level!\n");
        break;
      case 1:
        vert_hp_descent_chg[chg_pos] = 1;
        horiz_hp_descent_chg[chg_pos] = 1;
        break;
      case 2:
        vert_hp_descent_chg[chg_pos] = 0;
        horiz_hp_descent_chg[chg_pos] = 1;
        break;
      case 3:
        vert_hp_descent_chg[chg_pos] = 1;
        horiz_hp_descent_chg[chg_pos] = 0;
        break;
    }
    if (current_opcode > 0)
      decode_general_decomp_sequence(lev, level_idx, all_hp_descent+1,
                                     vert_hp_descent+vert_hp_descent_chg[chg_pos],
                                     horiz_hp_descent+horiz_hp_descent_chg[chg_pos],
                                     root_band_idx, decomp_sequence,
                                     decomp_sequence_pos,
                                     1+vert_hp_descent_chg[chg_pos],
                                     1+horiz_hp_descent_chg[chg_pos],
                                     vert_hp_descent_chg, horiz_hp_descent_chg, chg_pos+1);

    lev->bands[0].vert_hp_descent_chg[0] = 1;
    lev->bands[0].horiz_hp_descent_chg[0] = 1;
    lev->decomp_sequence = (int *)
      local_malloc(INFO_MEM_KEY,
        (*decomp_sequence_pos - first_decomp_sequence_pos + 1) * sizeof(int));
    for (n=first_decomp_sequence_pos; n<*decomp_sequence_pos; n++) {
      lev->decomp_sequence[n-first_decomp_sequence_pos] = decomp_sequence[n];
    }
    lev->decomp_sequence[n-first_decomp_sequence_pos] = -1;

    if (*decomp_sequence_pos == decomp_sequence_length)
      retval = 1;
    return(retval);
  }

  for (vert_idx=0; vert_idx < vert_limit; vert_idx++) {
    for (hor_idx=0; hor_idx < hor_limit; hor_idx++) {
      if ((vert_idx == 0) && (hor_idx == 0))
        if ((level_idx != 0) && (all_hp_descent <= 1))
          continue;
        else
          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 << ((lev->max_hp_descent - all_hp_descent) +
                        (lev->max_hp_descent - all_hp_descent)));
      if (all_hp_descent < lev->max_hp_descent) {
        if ((*decomp_sequence_pos + 1) > decomp_sequence_length)
          local_error("Decomposition string for `-Fgen_decomp' is too short.  "
                      "Check string to avoid errors!");
        current_opcode = decomp_sequence[*decomp_sequence_pos];
        (*decomp_sequence_pos)++;
      }
      else {
        current_opcode = 0;
      }
      switch(current_opcode) {
        case 0:
          if (lev->bands != NULL) {
            band = lev->bands + band_idx;
            band->vert_hp_descent = vert_hp_descent;
            band->horiz_hp_descent = horiz_hp_descent;
            band->valid_band = 1;
            for (n=0; n<chg_pos; n++) {
              band->vert_hp_descent_chg[n] = vert_hp_descent_chg[n];
              band->horiz_hp_descent_chg[n] = horiz_hp_descent_chg[n];
            }
            for (; n<4; n++) {
              band->vert_hp_descent_chg[n] = 2;
              band->horiz_hp_descent_chg[n] = 2;
            }
          }
          break;
        case 1:
          vert_hp_descent_chg[chg_pos] = 1;
          horiz_hp_descent_chg[chg_pos] = 1;
          break;
        case 2:
          vert_hp_descent_chg[chg_pos] = 0;
          horiz_hp_descent_chg[chg_pos] = 1;
          break;
        case 3:
          vert_hp_descent_chg[chg_pos] = 1;
          horiz_hp_descent_chg[chg_pos] = 0;
          break;
      }
      if (current_opcode > 0)
        decode_general_decomp_sequence(lev, level_idx, all_hp_descent+1,
                                       vert_hp_descent+vert_hp_descent_chg[chg_pos],
                                       horiz_hp_descent+horiz_hp_descent_chg[chg_pos],
                                       band_idx, decomp_sequence,
                                       decomp_sequence_pos,
                                       1+vert_hp_descent_chg[chg_pos],
                                       1+horiz_hp_descent_chg[chg_pos],
                                       vert_hp_descent_chg, horiz_hp_descent_chg, chg_pos+1);

⌨️ 快捷键说明

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