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

📄 hplx_vert.c

📁 JPEG2000 EBCOT算法源码
💻 C
📖 第 1 页 / 共 5 页
字号:
  
    if(self->UsedAsAnalysis)
       self->frd->terminate(self->frd);
    else
      self->inv->terminate(self->inv);
  
    if (self->next != NULL)
      {
        internal_terminate_fixed(self->next);
        local_free(self->next);
      }
  
    local_free(self->BufFast);
    local_free(self->_data_I[0]);
    local_free(self->_data_I);
    local_free(self->SecBuf_I);
  
    if(self->LoneLine)
      local_free(self->ExtraLine_I);

    for (k=0; k < 2; k++)
      {
        local_free(self->LowA_I[k]);
        local_free(self->HighA_I[k]);
        local_free(self->LowS_I[k]);
        local_free(self->HighS_I[k]);
      }
  }
}
#endif /* IMPLEMENTATION_PRECISION */

/*****************************************************************************/
/* STATIC                       internal_terminate                           */
/*****************************************************************************/

static void
  internal_terminate(transform_ref self)
{
  int m;

#if (IMPLEMENTATION_PRECISION == 16)
  if (self->fixed)
    {
      internal_terminate_fixed(self);
      return;
    }
#endif

  if(!self->CmpLevel) {
    if(self->UsedAsAnalysis){
    self->term=1;
    for (m=0;m<self->Middle*((1<<self->ZLevel)-1)+(self->ImageRows&1); m++)
        push_line_float(self,NULL); }}
  
  if (self->ZLevel)
    {
      if(self->UsedAsAnalysis)
        self->frd->terminate(self->frd);
      else
        self->inv->terminate(self->inv);
    }
  if (self->next != NULL)
    {
      internal_terminate(self->next);
      local_free(self->next);
    }
  
  local_free(self->_data[0]);
  local_free(self->_data);
  local_free(self->SecBuf);
  
  if(self->LoneLine)
    local_free(self->ExtraLine);

  local_free(self->LowA );
  local_free(self->HighA);
  local_free(self->LowS);
  local_free(self->HighS);
}

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

/*****************************************************************************/
/* STATIC                      analysis__initialize                          */
/*****************************************************************************/

static void
  analysis__initialize(analysis_ref base, int decomposition, int levels,
                       int components, int component_rows[],
                       int component_cols[], filter_info_ref info,
                       quantizer_ref quantizer, int argc, char *argv[])
{
  the_analysis_ref self = (the_analysis_ref) base;
  transform_ref xform;
  int comp;
  int i, precision, flag;

  if (decomposition != DECOMPOSITION__MALLAT)
    {
      fprintf(stderr,"Analysis engine currently only supports Mallat style "
              "decompositions!\n");
      exit(-1);
    }

  flag = precision= 0;
  for (i=1; i < argc; i++)
    if (strcmp(argv[i],"-Xfix") == 0)
      {
        argv[i] = "";
        if ((i == argc - 1 ) || (argv[i+1][0] == '-') || (argv[i+1][0]=='\0'))
          precision = 14;
        else
          {
            sscanf(argv[i+1],"%d",&precision);
            argv[i+1] = "";
          }
      }
#if (IMPLEMENTATION_PRECISION == 32)
    precision = flag = 0;
#endif

  self->num_levels = levels;
  self->num_components = components;
  self->components = (transform_ref)
    local_malloc(sizeof(transform_obj)*(size_t) components);
  memset(self->components,0,sizeof(transform_obj)*(size_t) components);
  for (comp=0; comp < components; comp++)
    {
      xform = self->components + comp;
      xform->UsedAsAnalysis = 1;
#if (IMPLEMENTATION_PRECISION == 16)
      if (precision)
        internal_initialize_fixed(xform,comp,component_rows[comp],
                                  component_cols[comp],0,levels,info,
                                  (quantizer_ref) quantizer,precision);
      else
#endif /* IMPLEMENTATION_PRECISION */
        internal_initialize(xform,comp,component_rows[comp],
                            component_cols[comp],0,levels,info,
                            (quantizer_ref) quantizer);
    }
}

/*****************************************************************************/
/* STATIC                      synthesis__initialize                         */
/*****************************************************************************/

static void
  synthesis__initialize(synthesis_ref base, int decomposition, int levels,
                        int components, int component_rows[],
                        int component_cols[], filter_info_ref info,
                        dequantizer_ref dequantizer, int argc, char *argv[])
{
  the_synthesis_ref self = (the_synthesis_ref) base;
  transform_ref xform;
  int comp;
  int i, precision, flag;

  if (decomposition != DECOMPOSITION__MALLAT)
    {
      fprintf(stderr,"Synthesis engine currently only supports Mallat style "
              "decompositions!\n");
      exit(-1);
    }

  flag = precision= 0;
  for (i=1; i < argc; i++)
    if (strcmp(argv[i],"-Xfix") == 0)
      {
        argv[i] = "";
        if ((i == argc - 1 ) || (argv[i+1][0] == '-') || (argv[i+1][0]=='\0'))
          precision = 14;
        else
          {
            sscanf(argv[i+1],"%d",&precision);
            argv[i+1] = "";
          }
      }
#if (IMPLEMENTATION_PRECISION == 32)
    precision = flag = 0;
#endif

  self->num_levels = levels;
  self->num_components = components;
  self->components = (transform_ref)
    local_malloc(sizeof(transform_obj)*(size_t) components);
  memset(self->components,0,sizeof(transform_obj)*(size_t) components);
  for (comp=0; comp < components; comp++)
    {
      xform = self->components + comp;
      xform->UsedAsAnalysis = 0;
#if (IMPLEMENTATION_PRECISION == 16)
      if (precision)
        internal_initialize_fixed(xform,comp,component_rows[comp],
                                  component_cols[comp],0,levels,info,
                                  (quantizer_ref) dequantizer,precision);
      else
#endif /* IMPLEMENTATION_PRECISION */
        internal_initialize(xform,comp,component_rows[comp],
                            component_cols[comp],0,levels,info,
                            (quantizer_ref) dequantizer);
    }
}

/*****************************************************************************/
/* STATIC                         __print_usage                              */
/*****************************************************************************/

static void
  __print_usage(analysis_ref self, FILE *dest)
{
  fprintf(dest,">> Arguments for HP Line-Based Wavelet Transform\n"
    "   -Xfix [<coefficient precision>] (default = 14 bits)\n"
    "     -- selects fixed-point implementation of transform\n");
}

/*****************************************************************************/
/* STATIC                      __push_line                                   */
/*****************************************************************************/

static void
  __push_line(analysis_ref base, ifc_int *line_buf, int component_idx)
{
  the_analysis_ref self = (the_analysis_ref) base;
  transform_ref xform;

  assert(component_idx < self->num_components);
  xform = self->components + component_idx;
#if (IMPLEMENTATION_PRECISION == 16)
  if (xform->fixed)
    {
      if (self->num_levels == 0)
        push_line_fixed_zero(xform,line_buf);
      else
        push_line_fixed(xform,line_buf);
    }
  else
#endif
    {
      if (self->num_levels == 0)
        push_line_float_zero(xform,line_buf);
      else
        push_line_float(xform,line_buf);
    }
}

/*****************************************************************************/
/* STATIC                      __push_image                                  */
/*****************************************************************************/

static void
  __push_image(analysis_ref base, ifc_int **image_buf, int component_idx)
{
  the_analysis_ref self = (the_analysis_ref) base;
  transform_ref xform;
  int r;

  assert(component_idx < self->num_components);
  xform = self->components + component_idx;
#if (IMPLEMENTATION_PRECISION == 16)
  if (xform->fixed)
    {
      if (self->num_levels == 0)
        for (r=0; r < xform->ImageRows; r++)
          push_line_fixed_zero(xform,image_buf[r]);
      else
        for (r=0; r < xform->ImageRows; r++)
          push_line_fixed(xform,image_buf[r]);
    }
  else
#endif
    {
      if (self->num_levels == 0)
        for (r=0; r < xform->ImageRows; r++)
          push_line_float_zero(xform,image_buf[r]);
      else
        for (r=0; r < xform->ImageRows; r++)
          push_line_float(xform,image_buf[r]);
    }
}

/*****************************************************************************/
/* STATIC                      __pull_line                                   */
/*****************************************************************************/

static void
  __pull_line(synthesis_ref base, ifc_int *line_buf, int component_idx)
{
  the_synthesis_ref self = (the_synthesis_ref) base;
  transform_ref xform;

  assert(component_idx < self->num_components);
  xform = self->components + component_idx;
#if (IMPLEMENTATION_PRECISION == 16)
  if (xform->fixed)
    {
      if (self->num_levels == 0)
        pull_line_fixed_zero(xform,line_buf);
      else
        pull_line_fixed(xform,line_buf);
    }
  else
#endif
    {
      if (self->num_levels == 0)
        pull_line_float_zero(xform,line_buf);
      else
        pull_line_float(xform,line_buf);
    }
}

/*****************************************************************************/
/* STATIC                      __pull_image                                  */
/*****************************************************************************/

static void
  __pull_image(synthesis_ref base, ifc_int **image_buf, int component_idx)
{
  the_synthesis_ref self = (the_synthesis_ref) base;
  transform_ref xform;
  int r;

  assert(component_idx < self->num_components);
  xform = self->components + component_idx;
#if (IMPLEMENTATION_PRECISION == 16)
  if (xform->fixed)
    {
      if (self->num_levels == 0)
        for (r=0; r < xform->ImageRows; r++)
          pull_line_fixed_zero(xform,image_buf[r]);
      else
        for (r=0; r < xform->ImageRows; r++)
          pull_line_fixed(xform,image_buf[r]);
    }
  else
#endif
    {
      if (self->num_levels == 0)
        for (r=0; r < xform->ImageRows; r++)
          pull_line_float_zero(xform,image_buf[r]);
      else
        for (r=0; r < xform->ImageRows; r++)
          pull_line_float(xform,image_buf[r]);
    }
}

/*****************************************************************************/
/* STATIC                       __terminate                                  */
/*****************************************************************************/

static void
  __terminate(analysis_ref base)
{
  the_analysis_ref self = (the_analysis_ref) base;
  int comp;
  transform_ref xform;

  if (self->components != NULL)
    {
      for (comp=0; comp < self->num_components; comp++)
        {
          xform = self->components + comp;
          internal_terminate(xform);
        }
      local_free(self->components);
    }
  local_free(self);
}

/***************************************************************/
/*
*  Create an analysis object
*/
/***************************************************************/
analysis_ref
  create_hp_line_analysis(void)
{
  the_analysis_ref result;
  
  result = (the_analysis_ref)
    local_malloc(sizeof(the_analysis_obj));
  memset(result,0,sizeof(the_analysis_obj));
  result->base.initialize         = analysis__initialize;
  result->base.print_usage        = __print_usage;
  result->base.push_line          = __push_line;
  result->base.push_image         = __push_image;
  result->base.terminate          = __terminate;
  return((analysis_ref) result);
}

/***************************************************************/
/*
*  Create a synthesis object
*/
/****************************************************************/
synthesis_ref
  create_hp_line_synthesis(void)
{
  the_synthesis_ref result;
  
  result = (the_synthesis_ref)
    local_m

⌨️ 快捷键说明

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