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

📄 std_reverse_info.c

📁 JPEG2000实现的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
static void
  retrieve_quantization_info_from_stream(stream_in_ref stream, int tnum,
                                         std_component_info_ptr comp_info)
 /* Retrieves quantization step size information from the QCC marker whose
    instance corresponds to the index of the supplied image component. */

{
  int instance, is_reversible, implicit, n, b, idx;
  std_level_info_ptr lev;
  std_band_info_ptr band;
  int base_exponent = 0;
  int base_mantissa = 0;
  /* MITRE General SQ Begin */
  int implicit_nz;
  float base_nz;
  /* MITRE General SQ End */

  instance = comp_info->component_idx;
  is_reversible = comp_info->reversible == INFO__REVERSIBLE;
  implicit = 0;
  if (!is_reversible)
    implicit =
      (stream->size_marker_elt(stream,tnum,MARKER_QCC_STEP,instance) == 1);
  comp_info->implicit_quantization = implicit;

  /* MITRE General SQ Begin */
  implicit_nz = 0;
  if (comp_info->any_nz)
    implicit_nz =
      (stream->size_marker_elt(stream,tnum,MARKER_QCC_NZ,instance) == 1);
  /* MITRE General SQ End */

  /* Write quantization elements. */

  idx=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++, idx++)
        {
          band = lev->bands + b;
          if (!band->valid_band) {
            idx--;
            continue;
          }
          if (is_reversible)
            {
              band->rel_step_exponent =
                stream->get_marker_val(stream,tnum,MARKER_QCC_REV,
                                       instance,idx);
              band->rel_step_mantissa = 0;
            }
          else
            {
              if ((n==0) || (!implicit))
                {
                  int val;
                  signed short sval;

                  val = stream->get_marker_val(stream,tnum,MARKER_QCC_STEP,
                                               instance,idx);
                  band->rel_step_mantissa = val & ~((-1)<<STEP_MANTISSA_BITS);
                  band->rel_step_exponent =
                    (val >> STEP_MANTISSA_BITS) & ~((-1)<<STEP_EXPONENT_BITS);
                  /* MITRE General SQ Begin */
                  if (comp_info->any_nz==0) {
                    band->scale_nz = 0.0F;
                    base_nz = band->scale_nz;
                  } else if ((n==0) || !implicit_nz) {
                    sval = stream->get_marker_val(stream,tnum,MARKER_QCC_NZ,
                                               instance,idx);
                    band->scale_nz = (float)sval/(1<<15);
                  } else
                    band->scale_nz = base_nz;
                  /* MITRE General SQ End */
                  if (n == 0)
                    {
                      base_exponent = band->rel_step_exponent;
                      base_mantissa = band->rel_step_mantissa;
                      base_nz = band->scale_nz; /* MITRE General SQ */
                    }
                }
              else
                {
                  /* SAIC General Decomp. Begin mods */
                  band->rel_step_exponent = base_exponent + 
                    (band->vert_hp_descent + band->horiz_hp_descent)/2;
                  band->rel_step_mantissa = base_mantissa;
                  if ((band->vert_hp_descent+band->horiz_hp_descent) % 2) {
                    /* Account for half-integer number of levels (i.e., 
                       horizontal and vertical subsampling factors that do not
                       match) */
                    if (band->rel_step_mantissa >= 849) {
                      band->rel_step_mantissa++;
                      band->rel_step_mantissa = (int) 
                        (((1 << 11) + band->rel_step_mantissa) * 0.070106781F -
                         (1 << 11));
                    }
                    else {
                      band->rel_step_mantissa = (int) 
                        (((1 << 11) + band->rel_step_mantissa) * 1.414213562 -
                         (1 << 11));
                    }
                  }
                  /* SAIC General Decomp. End mods */
                  band->scale_nz = base_nz; /* MITRE General SQ */
                }
            }
        }
      if (implicit)
        base_exponent--;
    }
}

/*****************************************************************************/
/* STATIC                retrieve_overlap_info_from_stream                   */
/*****************************************************************************/

static void
  retrieve_overlap_info_from_stream(stream_in_ref stream, int tnum,
                                    std_component_info_ptr comp_info)
 /* Retrieves the four boundary tile overlap flags from the QCC marker
    whose instance corresponds to the index of the supplied image component. */

{
  int instance;
  std_int value;

  instance = comp_info->component_idx;
  value = 0;
  if (stream->size_marker_elt(stream,tnum,MARKER_COC_OVLP,instance))
    value = stream->get_marker_val(stream,tnum,MARKER_COC_OVLP,instance,0);
  comp_info->ovlp_top = (value & 1)?1:0;
  comp_info->ovlp_bottom = (value & 2)?1:0;
  comp_info->ovlp_left = (value & 4)?1:0;
  comp_info->ovlp_right = (value & 8)?1:0;
}

/* MITRE General Offset/SQ Begin */
/*****************************************************************************/
/* STATIC                retrieve_nz_info_from_stream                        */
/*****************************************************************************/

static void
  retrieve_nz_info_from_stream(stream_in_ref stream, int tnum,
                                    std_component_info_ptr comp_info)
 /* Figures out if there is any nz info in bitstream. */             
                             
{
  int instance;
  int type;
 
  instance = comp_info->component_idx;

  /* Temporary fix to problem w/ -Qtcq */
  type = stream->get_marker_val(stream,tnum,MARKER_QCD_WHICH,instance,0);
  if (type == 2) { comp_info->any_nz = 0; return; }

  type = stream->get_marker_val(stream,tnum,MARKER_QCC_TYPE,instance,0);
  comp_info->any_nz = (type<3 || (type>5 && type<7))? 0:1;
}

/*****************************************************************************/
/* STATIC                retrieve_off_info_from_stream                   */
/*****************************************************************************/

static void
  retrieve_off_info_from_stream(stream_in_ref stream, int tnum,
                                 std_component_info_ptr comp_info)
 /* Retrieves the offsets from the bitstream. */

{
  int instance;
  int value;
 
  instance = comp_info->component_idx;
 
  if (stream->size_marker_elt(stream,tnum, MARKER_DCO_VALUE,instance)) {
    value = stream->get_marker_val(stream,tnum,MARKER_DCO_VALUE,instance,0);
    comp_info->adjust_dc = ieee32_to_val(value);
  }
  else {
    if (comp_info->is_signed)
      comp_info->adjust_dc = 0;
    else
      comp_info->adjust_dc = (1<<(comp_info->bitdepth-1));
  }

  /* Begin Aerospace MCT mods (TSW) */
  /* This value must be overridden and set to zero if a multi-component
     linear transform is performed on this tile */
  if ( stream->get_marker_val(stream,tnum,MARKER_COD_CXFORM,0,0) ==
       MIXING_XFORM_LIN )
    comp_info->adjust_dc = 0;  
  /* End Aerospace MCT mods */

}
/* MITRE General Offset/SQ End */

/*****************************************************************************/
/* STATIC                  initialize_tile_specific                          */
/*****************************************************************************/

static void
  initialize_tile_specific(std_reverse_info_ref self, int tnum,
                           std_component_info_ptr components,
                           stream_in_ref stream)

 /* On entry, the top-level fields in the `self' structure have been
    filled in and the sub-sampling parameters in the `default_components'
    array in `self' have also been set.  This function fills in the contents
    of the supplied `components' array and all subordinate structures,
    using the information which is already available, together with
    marker elements (global marker elements if `tnum' is negative, else the
    relevant tile-specific marker elements) retrieved from the supplied
    `stream' object. */

{
  int num_components, c;
  std_component_info_ptr comp_info, def_info;

  num_components = self->num_components;
  for (c=0; c < num_components; c++)
    {
      comp_info = components + c;
      def_info = self->default_components + c;
      assert(def_info->component_idx == c);
      comp_info->component_idx = c;
      comp_info->bitdepth = def_info->bitdepth;
      comp_info->is_signed = def_info->is_signed;
      comp_info->hor_subsampling = def_info->hor_subsampling;
      comp_info->vert_subsampling = def_info->vert_subsampling;
      comp_info->adjust_dc = def_info->adjust_dc; /* David T. fix */
      retrieve_num_guard_bits_from_stream(stream,tnum,comp_info);
      retrieve_reversibility_from_stream(stream,tnum,comp_info);
      retrieve_partition_info_from_stream(stream,tnum,comp_info);
      retrieve_decomp_info_from_stream(stream,tnum,comp_info);
      build_level_structure(comp_info,self->use_convolution);
      retrieve_kernel_info_from_stream(stream,tnum,comp_info);
      retrieve_nz_info_from_stream(stream, tnum, comp_info);
      retrieve_quantization_info_from_stream(stream,tnum,comp_info);
      retrieve_overlap_info_from_stream(stream,tnum,comp_info);

      /* MITRE General Offset/SQ Begin */
      retrieve_off_info_from_stream(stream, tnum, comp_info);
      /* MITRE General Offset/SQ End */

    }

}


/* ========================================================================= */
/* ------------------ Implementation of std_reverse_info ------------------- */
/* ========================================================================= */

/*****************************************************************************/
/* STATIC                         __initialize                               */
/*****************************************************************************/

static void
  __initialize(reverse_info_ref base, int num_components,
               stream_in_ref stream, cmdl_ref cmdl)
{
  std_reverse_info_ref self = (std_reverse_info_ref) base;
  std_tile_info_ptr tile;
  std_component_info_ptr comp_info;
  int c, p;

  /* OTLPF_CONVENTION begin; JX Wei ADFA, WJ Zeng Sharp */
  int size;
  /* OTLPF_CONVENTION end; JX Wei ADFA, WJ Zeng Sharp */

  /* Check command-line arguments. */

  if ((p=cmdl->extract(cmdl,"-Fconv",-1,NULL)) >= 0)
    {
      if (p != 0)
        local_error("The `-Fconv' argument takes no parameters!");
      self->use_convolution = 1;
    }

  /* MITRE General Offset/SQ Begin */
  if ((p=cmdl->extract(cmdl,"-Qno_nz",-1,NULL)) >= 0)
    {
      if (p != 0)
        local_error("The `-Qno_nz' argument takes no parameters!");
      comp_info->any_nz = 0;
    }
  /* MITRE General Offset/SQ End */

  self->stream = stream;

  /* Create a default components array with only those fields which cannot
     be tile-specific initialized here. */

  self->num_components = num_components;
  self->default_components = (std_component_info_ptr)
    local_malloc(INFO_MEM_KEY,sizeof(std_component_info)*num_components);
  for (c=0; c < num_components; c++)
    {
      comp_info = self->default_components + c;
      comp_info->component_idx = c;
    }

  /* OTLPF_CONVENTION begin; JX Wei ADFA, WJ Zeng Sharp */
  self->otlpf_convention = (int) stream->get_main_cmetag(stream, 0xFD00, 0, &size);
  self->use_convolution = 1;
  /* OTLPF_CONVENTION end; JX Wei ADFA, WJ Zeng Sharp */

  /* Get canvas parameters and set up tile structure. */

  retrieve_size_info_from_stream(stream,&(self->grid_dims),&(self->tile_dims),
                                 num_components,self->default_components);
  if ((self->grid_dims.top_row >=
       (self->tile_dims.top_row+self->tile_dims.rows)) ||
      (self->grid_dims.left_col >=
       (self->tile_dims.left_col+self->tile_dims.cols)))
    local_error("The upper left hand corner of the image has been displaced "
                "so far from the origin of the canvas coordinate system that "
                "the first tile of the image is completely empty.  Supply "
                "different coordinates to the `-Fref' argument!");
  self->tiles_high =
    CEIL_RATIO(self->grid_dims.rows + self->grid_dims.top_row -
               self->tile_dims.top_row,self->tile_dims.rows);

⌨️ 快捷键说明

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