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

📄 hplx_analysis.c

📁 JPEG2000实现的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* ========================================================================= */
/* ------------- Implementation of `hplx_analysis_leaf' Object ------------- */
/* ========================================================================= */

/*****************************************************************************/
/* STATIC                      leaf__initialize                              */
/*****************************************************************************/

static void
  leaf__initialize(hplx_analysis_stage_ref base, forward_info_ref info,
                   canvas_dims_ptr tile_dims, canvas_dims_ptr frame_dims)
{
  return; /* Nothing to do. */
}

/*****************************************************************************/
/*                          leaf__push_line_fixed                            */
/*****************************************************************************/

static void
  leaf__push_line_fixed(hplx_analysis_stage_ref base, ifc_int *line_buf,
                        int width)
{
  hplx_analysis_leaf_ref self = (hplx_analysis_leaf_ref) base;

  /* SAIC/Fuji LRA begin */
  if (base->get_lra_stats)
    {  /* Get stats on first iteration only */
      double xsquared;  /* Convenience variable */
      float temp;
      double temp1 = 0.0;
      double temp2 = 0.0;
      double temp3 = 0.0;
      double temp4 = 0.0;
      unsigned long new_pixel_count;
      int i;

      new_pixel_count = base->pixel_count + width;
      for (i = 0; i < width; i++)
        {
          temp = (float) line_buf[i];
          /* Use temp variable to save some mults */
          xsquared = temp * temp;
          /* Accumulate */
          temp1 += temp / ((double) new_pixel_count);
          temp2 += xsquared / ((double) new_pixel_count);
          temp3 += (xsquared * temp) / ((double) new_pixel_count);
          temp4 += (xsquared * xsquared) / ((double) new_pixel_count);
        }
      base->x1 = (base->x1 / ((double) new_pixel_count)) * 
        base->pixel_count + temp1;
      base->x2 = (base->x2 / ((double) new_pixel_count)) * 
        base->pixel_count + temp2;
      base->x3 = (base->x3 / ((double) new_pixel_count)) * 
        base->pixel_count + temp3;
      base->x4 = (base->x4 / ((double) new_pixel_count)) * 
        base->pixel_count + temp4;
      base->pixel_count = new_pixel_count;
    }
  /* SAIC/Fuji LRA end */

  if (base->use_floats)
    { /* Convert to floating point. */
      float *conv_buf, *dp;
      int n;

      if ((conv_buf = self->conversion_buf) == NULL)
        conv_buf = self->conversion_buf = (float *)
          local_malloc(XFORM_HBUF_KEY,sizeof(float)*width);
      for (dp=conv_buf, n=width; n > 0; n--)
        *(dp++) = (float)(*(line_buf++));
      base->quant->push_line_float(base->quant,conv_buf,base->component_idx,
                                   base->level_idx,base->band_idx,width);
    }
  else
    base->quant->push_line_fixed(base->quant,line_buf,base->component_idx,
                                 base->level_idx,base->band_idx,width);
}

/*****************************************************************************/
/*                          leaf__push_line_float                            */
/*****************************************************************************/

static void
  leaf__push_line_float(hplx_analysis_stage_ref base, float *line_buf,
                        int width)
{
  assert(base->use_floats); /* The only way to get floats is if the
                               decomposition is using floats, since the
                               input at the root level is fixed-point. */

  /* SAIC/Sharp/Fuji Xmask begin */
  if (base->alpha != 0.0) apply_visual_mask_float(base, line_buf, width);
  /* SAIC/Sharp/Fuji Xmask end */

  /* SAIC/Fuji LRA begin */
  if (base->get_lra_stats)
    {  /* Get stats on first iteration only */
      double xsquared; /* Convenience variable */
      float temp;
      double temp1 = 0.0;
      double temp2 = 0.0;
      double temp3 = 0.0;
      double temp4 = 0.0;
      unsigned long new_pixel_count;
      int i;

      new_pixel_count = base->pixel_count + width;
      for (i = 0; i < width; i++)
        {
          temp = line_buf[i];
          /* Use temp variable to save some mults */
          xsquared = temp * temp;
          /* Accumulate */
          temp1 += temp / ((double) new_pixel_count);
          temp2 += xsquared / ((double) new_pixel_count);
          temp3 += (xsquared * temp) / ((double) new_pixel_count);
          temp4 += (xsquared * xsquared) / ((double) new_pixel_count);
        }
      base->x1 = (base->x1 / ((double) new_pixel_count)) * 
        base->pixel_count + temp1;
      base->x2 = (base->x2 / ((double) new_pixel_count)) * 
        base->pixel_count + temp2;
      base->x3 = (base->x3 / ((double) new_pixel_count)) * 
        base->pixel_count + temp3;
      base->x4 = (base->x4 / ((double) new_pixel_count)) * 
        base->pixel_count + temp4;
      base->pixel_count = new_pixel_count;
    }
  /* SAIC/Fuji LRA end */

  base->quant->push_line_float(base->quant,line_buf,base->component_idx,
                               base->level_idx,base->band_idx,width);
}

/*****************************************************************************/
/* STATIC                      leaf__terminate                               */
/*****************************************************************************/

static void
  leaf__terminate(hplx_analysis_stage_ref base)
{
  hplx_analysis_leaf_ref self = (hplx_analysis_leaf_ref) base;

  if (self->conversion_buf != NULL)
    local_free(self->conversion_buf);
  local_free(self);
}

/*****************************************************************************/
/* STATIC                  create_hplx_analysis_leaf                         */
/*****************************************************************************/

static hplx_analysis_stage_ref
  create_hplx_analysis_leaf(void)
{
  hplx_analysis_leaf_ref result;

  result = (hplx_analysis_leaf_ref)
    local_malloc(XFORM_MEM_KEY,sizeof(hplx_analysis_leaf_obj));
  memset(result,0,sizeof(hplx_analysis_leaf_obj));
  result->base.initialize = leaf__initialize;
  result->base.push_line_fixed = leaf__push_line_fixed;
  result->base.push_line_float = leaf__push_line_float;
  result->base.terminate = leaf__terminate;
  return((hplx_analysis_stage_ref) result);
}

/* SAIC/Fuji LRA begin */
/*****************************************************************************/
/* STATIC                         look_for_stats                             */
/*****************************************************************************/

static void
  look_for_stats(hplx_analysis_stage_ref base, forward_info_ref info)

{

  if ((base->branches[0] == NULL) && (base->branches[1] == NULL))
    {
      info->set_stats(info, base->pixel_count, base->x1, base->x2,
                      base->x3, base->x4,
                      base->component_idx, base->level_idx, base->band_idx);
    }
  else
    {
      /* SAIC General Decomp. Begin mods */
      if (base->branches[0] != NULL) {
        look_for_stats(base->branches[0], info);
      }
      if (base->branches[1] != NULL) {
        look_for_stats(base->branches[1], info);
      }
      /* SAIC General Decomp. End mods */
    }
}
/* SAIC/Fuji LRA end */

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

static void
  start_tile(hplx_analysis_ref self)
{
  int num_components = self->num_components;
  forward_info_ref info = self->info;
  quantizer_ref quantizer = self->quantizer;
  canvas_dims dims;
  frame_info frame;
  hplx_analysis_stage_ref root_stage;
  int c, num_levels, reversible, sso_ext, use_floats;

  /* SAIC/Sharp/Fuji Xmask begin */
  float alpha, beta;
  int minlevel, win_width, bits_retained, respect_block_boundaries;
  /* SAIC/Sharp/Fuji Xmask end */

  for (c=0; c < num_components; c++)
    {

      /* SAIC General Decomp. Begin */
      int decomp_sequence[16];
      int decomp_sequence_pos = 0;
      /* SAIC General Decomp. End */

      if ((root_stage = self->components[c]) != NULL)
        {
          /* SAIC/Fuji/UNSW/HP LRA begin mods */
          if (self->info->set_stats != NULL)
            look_for_stats(root_stage,self->info);
          /* SAIC/Fuji/UNSW/HP LRA end mods */

          /* SAIC/Sharp/Fuji Xmask begin */
          if (self->alpha[MIN(0, self->current_tnum-1)] != 0.0) 
            destroy_Xmask_prev_rows(root_stage);
          /* SAIC/Sharp/Fuji Xmask end */

          root_stage->terminate(root_stage);
          self->components[c] = NULL;
        }
      
      num_levels = info->get_var_tile_info(info,c,NULL,NULL,&reversible,NULL,NULL);
      info->get_level_info(info,c,num_levels,&dims,NULL,&frame,NULL);
      use_floats = !reversible;
      sso_ext = self->sso_ext[self->current_tnum*num_components + c];

      /* SAIC/Sharp/Fuji Xmask begin */
      alpha = self->alpha[self->current_tnum];
      beta = self->beta[self->current_tnum];
      minlevel = self->minlevel[self->current_tnum];
      win_width = self->win_width[self->current_tnum];
      bits_retained = self->bits_retained[self->current_tnum];
      respect_block_boundaries = self->respect_block_boundaries[self->current_tnum];
      /* SAIC/Sharp/Fuji Xmask end */

      self->components[c] = root_stage =
        create_decomposition_tree(num_levels,c,info,quantizer,
                                  use_floats,0,0,self->usePsExtension,sso_ext,

                                  /* OTLPF_CONVENTION begin; JX Wei ADFA, WJ Zeng Sharp */
                                  self->otlpf_convention,
                                  /* OTLPF_CONVENTION end; JX Wei ADFA, WJ Zeng Sharp */

                                  /* SAIC/Sharp/Fuji Xmask begin */
                                  self->encoder, alpha, beta, 
                                  minlevel, win_width, bits_retained, 
                                  respect_block_boundaries,
                                  /* SAIC/Sharp/Fuji Xmask end */
                                  0, 0, 0, 0,
                                  decomp_sequence,
                                  &decomp_sequence_pos,
                                  0, 0);

      root_stage->initialize(root_stage,info,&dims,&(frame.dims));
    }
}

/*****************************************************************************/
/* STATIC                  set_and_signal_sso_ext                            */
/*****************************************************************************/

static void
  set_and_signal_sso_ext(cmdl_ref cmdl, int tnum, int *sso_ext,
                         int num_components, stream_out_ref stream)
{
  char **params;
  int p, c, value;

  value = c = 0;
  if ((p = cmdl->extract(cmdl,"-Xsso_ext",tnum,&params)) >= 0)
    {
      value = 1;
      for (; c < p; c++)
        {
          if (strcmp(params[c],"Y") == 0)
            value = 1;
          else if (strcmp(params[c],"N") == 0)
            value = 0;
          else
            local_error("The `-Xsso_ext' argument only accepts parameters "
                        "consisting of a single character, from the set "
                        "{`Y',`N'}!");
          if (c < num_components)
            {
              stream->declare_marker_elt(stream,tnum,MARKER_COC_SSOEXT,
                                         c,1,value);
              if (value)
                stream->set_marker_val(stream,tnum,MARKER_COC_SSOEXT,c,1,0);
              if (tnum >= 0)
                sso_ext[tnum*num_components + c] = value;
            }
        }
    }
  for (; c < num_components; c++)
    {
      stream->declare_marker_elt(stream,tnum,MARKER_COC_SSOEXT,
                                 c,1,value);
      if (value)
        stream->set_marker_val(stream,tnum,MARKER_COC_SSOEXT,c,1,0);
      if (tnum >= 0)
        sso_ext[tnum*num_components + c] = value;
    }
}

/* SAIC/Sharp/Fuji Xmask begin */
/*****************************************************************************/
/* STATIC                   set_and_signal_Xmask                             */
/*****************************************************************************/

static void
  set_and_signal_Xmask(cmdl_ref cmdl, int tnum, float *alpha, float *beta,
                       int *minlevel, int *win_width, int *bits_retained,
                       int *respect_block_boundaries, stream_out_ref stream)
{

⌨️ 快捷键说明

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