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

📄 tcq_dequant.c

📁 JPEG2000实现的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
    return;

  for (n=0; n <= comp->num_levels; n++)
    {
      lev = comp->levels + n;
      if (lev->bands != NULL)
        {
          for (b = lev->min_band; b <= lev->max_band; b++)
            {
              band = lev->bands + b;
              if (!band->valid_band)
                continue;
              DeleteBlockBuffer(band->line_buffer);
            }
          local_free(lev->bands);
        }
    }
  local_free(comp->levels);
}

/*****************************************************************************/
/* STATIC                            start_tile                              */
/*****************************************************************************/

static void
  start_tile(tcq_dequantizer_ref self)
{
  reverse_info_ref info = self->info;
  decoder_ref decoder = self->decoder;
  int num_components = self->num_components;
  tcq_component_info_ptr comp;
  tcq_level_info_ptr lev;
  tcq_band_info_ptr band;
  int reversible, c, n, b;

  for (c=0; c < num_components; c++)
    {
      comp = self->components + c;
      destroy_component_structures(comp);

      comp->num_levels =
        info->get_var_tile_info(info,c,NULL,NULL,&reversible,NULL,NULL);
      if (reversible)
        local_error("Cannot use TCQ with reversible decompositions!");
      comp->levels = (tcq_level_info_ptr)
        local_malloc(TCQ_MEM_KEY,sizeof(tcq_level_info)*(comp->num_levels+1));
      for (n=0; n <= comp->num_levels; n++)
        {
          int max_hp_descent;
          float step_size;
          int exponent, extra_lsbs;

          lev = comp->levels + n;
          if (n == 0)
            lev->min_band = lev->max_band = LL_BAND;
          else
            {
              info->get_level_info(info,c,n,NULL,&max_hp_descent,NULL,NULL);
              if (max_hp_descent == 0)
                {
                  lev->min_band = 0;
                  lev->max_band = -1;
                  continue;
                }
              else
                {
                  lev->min_band = 1 << (max_hp_descent+max_hp_descent-2);
                  lev->max_band = (1<<(max_hp_descent+max_hp_descent)) - 1;
                }
            }
          lev->bands = (tcq_band_info_ptr)
            local_malloc(TCQ_MEM_KEY,
                         sizeof(tcq_band_info)*(lev->max_band+1));
          for (b=lev->min_band; b <= lev->max_band; b++)
            {
              band = lev->bands + b;
              info->get_band_info(info,c,n,b,NULL,NULL,NULL,NULL,NULL,NULL,&(band->valid_band));
              if (!band->valid_band)
                continue;

              /* MITRE General Offset/SQ Begin */
              info->get_quant_info(info,c,n,b,&step_size,&exponent,
                                   &extra_lsbs,NULL);
              /* MITRE General Offset/SQ End */

	      band->extra_lsbs = extra_lsbs;
	      band->line_buffer = NULL;
	      band->scale = step_size;
            }
        }
    }

  /* Now set up the block structure. */

  for (c=0; c < self->num_components; c++)
    {
      comp = self->components + c;
      for (n=0; n <= comp->num_levels; n++)
        {
          canvas_dims dims;
          frame_info frame;

          lev = comp->levels + n;
          for (b=lev->min_band; b <= lev->max_band; b++)
            {
              int block_height, block_width;

              band = lev->bands + b;
              if (!band->valid_band)
                continue;
              info->get_band_info(info,c,n,b,&dims,&frame,NULL,NULL,NULL,NULL,NULL);
              decoder->get_block_ht_wd(decoder,c,n,b,
                                       &block_height,&block_width);
              assert(is_power_of_2(block_width) &&
                     is_power_of_2(block_height));
              band->first_block_width = block_width -
                ((dims.left_col - frame.dims.left_col) & (block_width - 1));
              band->first_block_height = block_height -
                ((dims.top_row - frame.dims.top_row) & (block_height - 1));
              if (band->first_block_height > dims.rows)
                band->first_block_height = dims.rows;
              if (band->first_block_width > dims.cols)
                band->first_block_width = dims.cols;
              band->block_width = block_width;
              band->block_height = block_height;
              band->next_line_idx = 0;
              band->lines_left_in_buffer = 0;
              band->remaining_tile_height = dims.rows;
              band->next_block_height = band->first_block_height;
            }
        }
    }
}


/* ========================================================================= */
/* ------------------------- Interface Implementation ---------------------- */
/* ========================================================================= */

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

static void
  __initialize(dequantizer_ref base, int num_components,
               reverse_info_ref info, decoder_ref decoder,
               stream_in_ref stream, cmdl_ref cmdl)
{
  tcq_dequantizer_ref self = (tcq_dequantizer_ref) base;
  int p;

  self->num_components = num_components;
  self->decoder = decoder;
  self->stream = stream;
  self->info = info;
  self->components = (tcq_component_info_ptr)
    local_malloc(TCQ_MEM_KEY,sizeof(tcq_component_info)*num_components);

  /* SAIC General Decomp. Begin */
  {
    canvas_dims tile_dims;
    int max_hp_descent;
    int num_levels;
    int b, n, p;
    char **params;

    if ((p = cmdl->extract(cmdl,"-Xwt_output",-1,&params)) >= 0) {
      if (p != 1)
        local_error("The `-Xwt_output' argument requires on parameter!");
      self->wt_output_file = params[0];
      /* Begin Aerospace MCT mods */
      self->info->get_fixed_tile_info(self->info, 0, 0, NULL, NULL, &tile_dims,
                                      NULL, NULL, NULL, NULL,NULL,NULL,NULL);
      /* End Aerospace MCT mods */
      self->wt_output = (float **)
        local_malloc(TCQ_MEM_KEY, tile_dims.rows*sizeof(float *));
      self->wt_output -= tile_dims.top_row;
      self->wt_output[tile_dims.top_row] = (float *)
        local_malloc(TCQ_MEM_KEY, tile_dims.rows * tile_dims.cols *
                                   sizeof(float));
      self->wt_output[tile_dims.top_row] -= tile_dims.left_col;
      for (n=(tile_dims.top_row+1); n<(tile_dims.top_row+tile_dims.rows); n++) {
        self->wt_output[n] = self->wt_output[n-1] + tile_dims.cols;
      }
      num_levels = info->get_var_tile_info(info,0,NULL,NULL,NULL,NULL,NULL);
      self->min_band = (int *)
        local_malloc(TCQ_MEM_KEY, (num_levels+1)*sizeof(int));
      self->max_band = (int *)
        local_malloc(TCQ_MEM_KEY, (num_levels+1)*sizeof(int));
      self->band_dims = (canvas_dims **)
        local_malloc(TCQ_MEM_KEY, (num_levels+1)*sizeof(canvas_dims *));
      self->current_band_line = (int **)
        local_malloc(TCQ_MEM_KEY, (num_levels+1)*sizeof(int *));
      self->valid_band = (int **)
        local_malloc(TCQ_MEM_KEY, (num_levels+1)*sizeof(int *));
      for (n=0; n<(num_levels+1); n++) {
        if (n == 0)
          self->min_band[n] = self->max_band[n] = LL_BAND;
        else {
          info->get_level_info(self->info,0,n,NULL, &max_hp_descent,NULL,NULL);
          self->min_band[n] = 1 << (max_hp_descent+max_hp_descent-2);
          self->max_band[n] = (1<<(max_hp_descent+max_hp_descent)) - 1;

        }
        self->band_dims[n] = (canvas_dims *)
          local_malloc(TCQ_MEM_KEY, sizeof(canvas_dims)*(self->max_band[n]+1));
        self->current_band_line[n] = (int *)
          local_malloc(TCQ_MEM_KEY, sizeof(int)*(self->max_band[n]+1));
        self->valid_band[n] = (int *)
          local_malloc(TCQ_MEM_KEY, sizeof(int)*(self->max_band[n]+1));
        for (b=self->min_band[n]; b<=self->max_band[n];
             b++) {
          self->info->get_band_info(info,0,n,b,NULL,NULL,NULL,NULL,NULL,NULL,&(self->valid_band[n][b]));
          if (!self->valid_band[n][b])
            continue;
          self->info->get_band_location_info(info,0,n,b,&(self->band_dims[n][b]));
        }
      }
    }
  }
  /* SAIC General Decomp. End */

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

/*****************************************************************************/
/* STATIC                          __get_usage                               */
/*****************************************************************************/

static char **
  __get_usage(dequantizer_ref base)
{
  static char *args[] =
    {"-Q3_8 <max magnitude> (default = 0)",
      "This argument allows the user to control the representation levels "
      "used for quantized sample values with small magnitudes.  By default, "
      "all sample values are represented by the mid-point of the relevant "
      "quantization interval, i.e. half way between the two thresholds which "
      "delineate the interval.  If this argument is provided, however, then "
      "some samples will be represented by a value which lies only 3/8 of "
      "a step past the threshold of lower magnitude, toward the threshold "
      "of larger magnitude.  The samples which are treated in this way are "
      "all those whose quantized symbol indices have a magnitude no larger "
      "than M, where M is the <max magnitude> value.  It should be noted "
      "that this quantized magnitude is assessed with respect to the "
      "effective quantizer associated with the decoding process, which may "
      "be much coarser than that which was originally used during encoding, "
      "since one or more bit-planes may have been discarded.  Moreover, this "
      "interpretation may vary from sample to sample, not just from subband "
      "to subband, since bit-plane discarding is modulated at the individual "
      "sample level.  Typical values of M range from 1 to 4.",
     "-Qno_tcq",
      "If the input encoded file was obtained using TCQ, this option will "
      "turn off inverse TCQ processing and instead use the same scalar "
      "dequantizer like process which is used for non-fully decoded TCQ "
      "files.",
     NULL};

  return(args);
}

/*****************************************************************************/
/* STATIC                         __next_tile                                */
/*****************************************************************************/

static void
  __next_tile(dequantizer_ref base)
{
  tcq_dequantizer_ref self = (tcq_dequantizer_ref) base;

  self->decoder->next_tile(self->decoder);
  self->tnum++;
  start_tile(self);
}

/*****************************************************************************/
/* STATIC                      __pull_line_float                             */
/*****************************************************************************/

⌨️ 快捷键说明

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