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

📄 hplx_analysis.c

📁 JPEG2000实现的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
  char **params;
  int p, pidx, value;

  alpha[tnum] = 0.0F;
  beta[tnum] = 0.0F;
  minlevel[tnum] = 1;
  win_width[tnum] = 6;
  bits_retained[tnum] = 9;
  respect_block_boundaries[tnum] = 1;

  value = pidx = 0;
  if ((p = cmdl->extract(cmdl,"-Xmask",tnum,&params)) >= 0)
    {
      value = 1;
      if (pidx < p) {
        if (strcmp(params[0],"Y") == 0) {
          value = 1;
          pidx++;
        }
        else if (strcmp(params[0],"N") == 0) {
          value = 0;
          pidx++;
        }
      }
      if (value) {
        alpha[tnum] = 0.7F; /* New default value */
        if (pidx < p) {
          sscanf(params[pidx], "%f", &(alpha[tnum]));
          pidx++;
        }
        if (pidx < p) {
          sscanf(params[pidx], "%f", &(beta[tnum]));
          pidx++;
        }
        if (pidx < p) {
          sscanf(params[pidx], "%d", &(respect_block_boundaries[tnum]));
          pidx++;
        }
        if (pidx < p) {
          sscanf(params[pidx], "%d", &(win_width[tnum]));
          pidx++;
        }
        if (pidx < p) {
          sscanf(params[pidx], "%d", &(bits_retained[tnum]));
          pidx++;
        }
        if (pidx < p) {
          sscanf(params[pidx], "%d", &(minlevel[tnum]));
          pidx++;
        }
        if (pidx < p) {
          local_error("The `-Xmask' argument only accepts up to seven "
                      "parameters!");
        }

      }
      else if (pidx < p) {
        local_error("The `-Xmask N' argument does not accept any "
                    "parameters!");
      }

      stream->declare_marker_elt(stream,tnum,MARKER_VMS_S,
                                 0,8,value);
      if (value)
        stream->set_marker_val(stream,tnum,MARKER_VMS_S,0,
                               (respect_block_boundaries[tnum] << 7) + 
                                minlevel[tnum],0);
      stream->declare_marker_elt(stream,tnum,MARKER_VMS_W,
                                 0,8,value);
      if (value)
        stream->set_marker_val(stream,tnum,MARKER_VMS_W,0,win_width[tnum],0);
      stream->declare_marker_elt(stream,tnum,MARKER_VMS_R,
                                 0,8,value);
      if (value)
        stream->set_marker_val(stream,tnum,MARKER_VMS_R,0,
                               bits_retained[tnum],0);
      stream->declare_marker_elt(stream,tnum,MARKER_VMS_A,
                                 0,8,value);
      if (value) {
        unsigned char alpha_quant = 
          (unsigned char) ((128.0 * alpha[tnum]) + 0.5);
        alpha[tnum] = alpha_quant/128.0F;
        stream->set_marker_val(stream,tnum,MARKER_VMS_A,0,alpha_quant,0);
      }
      stream->declare_marker_elt(stream,tnum,MARKER_VMS_B,
                                 0,8,value);
      if (value) {
        unsigned char beta_quant = 
          (unsigned char) ((128.0 * beta[tnum]) + 0.5);
        beta[tnum] = beta_quant/128.0F;
        stream->set_marker_val(stream,tnum,MARKER_VMS_B,0,beta_quant,0);
      }
    }
}
/* SAIC/Sharp/Fuji Xmask end */


/* ========================================================================= */
/* ------------------ Implementation of Interface Functions ---------------- */
/* ========================================================================= */

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

static void
  __initialize(analysis_ref base, int num_components,
               forward_info_ref info, quantizer_ref quantizer,

               /* SAIC/Sharp/Fuji Xmask begin */
               encoder_ref encoder,
               /* SAIC/Sharp/Fuji Xmask end */

               stream_out_ref stream, cmdl_ref cmdl)
{
  hplx_analysis_ref self = (hplx_analysis_ref) base;
  int num_tiles, tnum, p;

  /* Is point-symmetric extension to be used */

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

  /* OTLPF_CONVENTION begin; JX Wei ADFA, WJ Zeng Sharp */
  if ((p = cmdl->extract(cmdl,"-Fotlpf_conv",-1,NULL)) >= 0)
    {
      if (p != 0)
        local_error("The `-Fotlpf_conv' argument takes no parameters!");
      self->otlpf_convention = 1;
    }
  /* OTLPF_CONVENTION end; JX Wei ADFA, WJ Zeng Sharp */

  if (self->usePsExtension)
    { /* Use a simple CME marker here for now.  This is sufficient for
         experimental purposes until the future of PSE is more clear. */
      stream->set_main_cmetag(stream,CME_PSE,0,NULL);
    }

  /* Initialize basic parameters. */

  self->info = info;
  self->quantizer = quantizer;
  self->num_components = num_components;
  self->components = (hplx_analysis_stage_ref *)
    local_malloc(XFORM_MEM_KEY,sizeof(hplx_analysis_stage_ref)*num_components);

  tnum=0;

  /* Begin Aerospace MCT mods */
  while (info->get_fixed_tile_info(info,-1,tnum,NULL,NULL,NULL,NULL,NULL,
                                   NULL,NULL,NULL,NULL,NULL))
  /* End Aerospace MCT mods */

    tnum++;
  num_tiles = tnum;
  self->sso_ext = (int *)
    local_malloc(XFORM_MEM_KEY,sizeof(int)*num_components*num_tiles);
  for (tnum=-1; tnum < num_tiles; tnum++)
    set_and_signal_sso_ext(cmdl,tnum,self->sso_ext,num_components,stream);

  /* SAIC/Sharp/Fuji Xmask begin */
  self->encoder = encoder;
  self->alpha = (float *) local_malloc(XFORM_MEM_KEY,sizeof(float)*(num_tiles + 1));
  self->beta = (float *) local_malloc(XFORM_MEM_KEY,sizeof(float)*(num_tiles + 1));
  self->minlevel = (int *) local_malloc(XFORM_MEM_KEY,sizeof(int)*(num_tiles + 1));
  self->win_width = (int *) local_malloc(XFORM_MEM_KEY,sizeof(int)*(num_tiles + 1));
  self->bits_retained = 
    (int *) local_malloc(XFORM_MEM_KEY,sizeof(int)*(num_tiles + 1));
  self->respect_block_boundaries = 
    (int *) local_malloc(XFORM_MEM_KEY,sizeof(int)*(num_tiles + 1));
  self->alpha += 1;
  self->beta += 1;
  self->minlevel += 1;
  self->win_width += 1;
  self->bits_retained += 1;
  self->respect_block_boundaries += 1;
  for (tnum=-1; tnum < num_tiles; tnum++)
    set_and_signal_Xmask(cmdl,tnum,self->alpha,self->beta,self->minlevel,
                         self->win_width,self->bits_retained,
                         self->respect_block_boundaries,stream);
  /* SAIC/Sharp/Fuji Xmask end */

  /* All the real initialization happens in the `start_tile' function. */

  start_tile(self);
}

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

static char **
  __get_usage(analysis_ref base)
{
  static char *args[] =
    {"-XpsExt",
       "Use point-symmetric extension instead of normal symmetric extension.",

     /* SAIC/Sharp/Fuji Xmask begin */
     "-Xmask[+<tnum>] [Y|N] [alpha=0.7] [beta=0.0] "
     "[respect_block_boundaries=1] [win_width=6] [bits_retained=9] "
     "[minlevel=1]",
     "This option indicates use of visual masking in the transform "
     "operation and may accept up to seven additional parameters. "
     "The first two parameters specify the alpha (point) and beta "
     "(neighborhood) powers respectively to use for visual masking. "
     "The third parameter specifies if the neighborhood masking should "
     "respect entropy encoder block boundaries.  "
     "The fourth and fifth parameters are the window width and the number "
     "of precision bits to lose for neighborhood masking.  The sixth "
     "parameter specifies the minlevel as defined in WG1 N1135.",
     /* SAIC/Sharp/Fuji Xmask end */

     "-Xsso_ext[+<tnum>] [Y|N [Y|N [...]] (default=symmetric extension)",
       "This argument forces the selection of SSO-DWT style boundary "
       "extension, in which the boundary sample is left unchanged, skipping "
       "all update steps at the boundary, on all tile boundaries whose "
       "samples are those which are modified during the update lifting "
       "steps (i.e. even indexed boundary locations).  This can have "
       "beneficial effects in hiding tile boundaries when used in "
       "conjunction with overlapping tiles and appropriate selection of "
       "the various parameters.  See `-Fovlp' for more information on this.  "
       "By default, symmetric extension is applied at tile boundaries and "
       "SSO-DWT extension is applied at most at the internal boundaries "
       "between frames within a tile.  The argument takes zero or more "
       "parameters.  Each optional parameter must consist of one of the "
       "characters `Y' (use SSO-DWT style extension) or `N' (use symmetric "
       "extension).  The first parameter identifies the extension style "
       "for the first image component in the relevant tile(s).  Subsequent "
       "parameters correspond to consecutive image components, with the "
       "last parameter applying to any remaining image components.  If "
       "no parameters are supplied, all components in the relevant tile(s) "
       "will adopt the SSO-DWT style boundary extension.",

     /* SAIC General Decomp. End */
     "`-Xwt_output' <output wavelet PPM file> (default = none)",
       "Specifies a file for outputing a viewable PPM file for the wavelet "
       "transform used in encoding.  Note that this argument can provide "
       "significant utility in debugging `-Fgen_decomp' strings.  Also note "
       "that this option does not currently work for tiled images.",
     /* SAIC General Decomp. End */

     NULL};

  return(args);
}

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

static void
  __next_tile(analysis_ref base)
{
  hplx_analysis_ref self = (hplx_analysis_ref) base;

  self->current_tnum++;
  start_tile(self);
  self->quantizer->next_tile(self->quantizer);
}

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

static void
  __push_line(analysis_ref base, ifc_int *line_buf, int component_idx,
              int width)
{
  hplx_analysis_ref self = (hplx_analysis_ref) base;
  hplx_analysis_stage_ref stage;

  assert(component_idx < self->num_components);
  stage = self->components[component_idx];
  stage->push_line_fixed(stage,line_buf,width);
}

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

static void
  __terminate(analysis_ref base)
{
  hplx_analysis_ref self = (hplx_analysis_ref) base;
  int c;

  if (self->components != NULL)
    {
      for (c=0; c < self->num_components; c++)
        {
          /* SAIC/Fuji LRA begin mods */
          if (self->info->set_stats != NULL)
            look_for_stats(self->components[c], self->info);
          /* SAIC/Fuji LRA end mods */

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

          if (self->components[c] != NULL)
            self->components[c]->terminate(self->components[c]);
        }
      local_free(self->components);
    }
  if (self->sso_ext != NULL)
    local_free(self->sso_ext);
  local_free(self);
}

/*****************************************************************************/
/* EXTERN                      create_hplx_analysis                          */
/*****************************************************************************/

analysis_ref
  create_hplx_analysis(void)
{
  hplx_analysis_ref result;

  result = (hplx_analysis_ref)
    local_malloc(XFORM_MEM_KEY,sizeof(hplx_analysis_obj));
  result->base.initialize = __initialize;
  result->base.get_usage = __get_usage;
  result->base.push_line = __push_line;
  result->base.next_tile = __next_tile;
  result->base.terminate = __terminate;
  return((analysis_ref) result);
}

⌨️ 快捷键说明

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