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

📄 compress.c

📁 JPEG2000实现的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
                        upshift=-upshift;
                        /* Added the short cast below (JHK). */
                        offset=(short) floor(comps[n].offset+0.5);
                        offset+=(1<<(upshift-1)); /* Add rounding offset. */
                        for(sp=work,r=tile_cols;r>0;r--){
                            val=*sp;
                            val+=offset;
                            val>>=upshift;
                            *(sp++)=val;
                        }
                    }
                    }
                    /* End Aerospace MCT mods */
                    mixer->push_line(mixer,work,n,tile_cols);
                }
            } while(!done);

            /* Adjust counters for next horizontal tile. */
            for(n=0;n<num_components;n++)
                comps[n].row_offset+=comps[n].tile_cols;

            if(info->next_tile(info,0))
                mixer->next_tile(mixer);
        }
    }

    /* Cleanup. */
    for(n=0;n<num_components;n++){
        int r;

        for(r=0;r<comps[n].max_buffer_rows;r++)
            local_free(comps[n].buffer[r]);
        local_free(comps[n].buffer);
    }
    local_free(comps);
    local_free(work);
}

/*****************************************************************************/
/* STATIC                     find_enc_constructors                          */
/*****************************************************************************/

static void find_enc_constructors(enc_constructor_info_ptr constructors,
                      cmdl_ref cmdl)
     /* Fills out the entries of the `constructors' structure.  May use command
    line arguments to decide between different implementations
    of some object.  See the quantizer object as an example for how to do 
    this */
     
{
  extern image_reader_ref create_simple_image_reader(void);
  extern stream_out_ref create_reference_stream_out(void);
  extern forward_info_ref create_std_forward_info(void);
  extern encoder_ref create_ebcot_encoder(void);
  extern forward_roi_ref create_reference_forward_roi(void);
  
  extern quantizer_ref create_deadzone_quantizer(void);
  extern quantizer_ref create_tcq_quantizer(void);
  
  extern analysis_ref create_hplx_analysis(void);
  extern component_mix_ref create_component_mix(void);
  
  /* EKC mct begin */
  extern image_reader_ref create_mcraw_image_reader(void);
  int k, num_args, have_pgx, have_mcraw;
  char **params;
  /* EKC mct end */
  
  int p;
  
  constructors->stream_out = create_reference_stream_out;
  constructors->forward_info = create_std_forward_info;
  constructors->encoder = create_ebcot_encoder;
  {
    /* Since we are using the EBCOT encoder, we pause here to verify that
       `-iter' is not being used without `-Cno_trunc', since the coder and
       the invocation environment will otherwise attempt to implement
       incompatible rate control policies. */
    int have_iter, have_no_trunc;
    
    have_iter = have_no_trunc = 0;
    if (cmdl->extract(cmdl,"-Cno_trunc",-1,NULL) >= 0)
      have_no_trunc = 1;
    if (cmdl->extract(cmdl,"-iter",-1,NULL) >= 0)
      have_iter = 1;
    if (have_iter && !have_no_trunc)
      local_error("The `-iter' argument must not be supplied without "
          "`-Cno_trunc', since otherwise the EBCOT coding "
          "algorithm and the compressor's invocation environment "
          "will both be implementing incompatible rate control "
          "algorithms!");
  }
  constructors->forward_roi = create_reference_forward_roi;
  constructors->quantizer = create_deadzone_quantizer;
  if ((p = cmdl->extract(cmdl,"-Qtcq",-1,NULL)) >= 0) {
    if (p != 0)
      local_error("The `-Qtcq' argument takes no parameters!");
    constructors->quantizer = create_tcq_quantizer;
  }
  constructors->analysis = create_hplx_analysis;
  constructors->component_mix = create_component_mix;
  constructors->image_reader = create_simple_image_reader;
  
  /* EKC mct begin */
  if ((num_args = cmdl->extract(cmdl,"-i",-1,&params)) <= 0) {
    return;
  }
  
  have_pgx = have_mcraw = 0;
  for (k=0; k < num_args; k++) {
    if ((strstr(params[k], ".img") != NULL) ||
    (strstr(params[k], ".nrm") != NULL) ||
    (strstr(params[k], ".bil") != NULL) ||
    (strstr(params[k], ".raw") != NULL) ||
    (strstr(params[k], ".bsq") != NULL) ||
    (strstr(params[k], ".bip") != NULL))
      have_mcraw = 1;
    else
      have_pgx = 1;
  }
  if ((have_pgx + have_mcraw) > 1) {
    local_error("Unable to support different input file formats on the "
        "same command line...");
  }
  if (have_mcraw) {
    constructors->image_reader = create_mcraw_image_reader;
  }
  /* EKC mct end */
}

/*****************************************************************************/
/* STATIC                      print_generic_usage                           */
/*****************************************************************************/

static void print_generic_usage(char **usage)
     /* Formats and prints the usage information recovered from the `get_usage'
    function offered by any of the standard objects. */
{
  if (usage == NULL)
    return;
  for (; *usage != NULL; usage += 2)
    {
      local_printf(4,70,"%s",usage[0]);
      if (usage[1] != NULL)
    local_printf(7,70,"%s",usage[1]);
    }
}

/*****************************************************************************/
/* STATIC                          print_usage                               */
/*****************************************************************************/

static void print_usage(float default_max_bpp,
            float default_low_rate_tol, /* SAIC/FUJI */
            float default_hi_rate_tol, /* SAIC/FUJI */
            float default_base_step, int default_iterations,
            int default_verbose,
            enc_constructor_info_ptr constructors)
{
  /* EKC mct begin */
  extern image_reader_ref create_simple_image_reader(void);
  extern image_reader_ref create_mcraw_image_reader(void);
  /* EKC mct end */
  
  image_reader_ref image;
  stream_out_ref stream;
  forward_info_ref info;
  encoder_ref encoder;
  forward_roi_ref roi;
  quantizer_ref quantizer;
  analysis_ref analysis;
  component_mix_ref mixer;
  
  local_printf(0,70,"\nThe following arguments are recognized:");
  
  /* EKC mct begin mods */
  image = create_simple_image_reader();
  print_generic_usage(image->get_usage(image));
  image->terminate(image);
  
  image = create_mcraw_image_reader();
  print_generic_usage(image->get_usage(image));
  image->terminate(image);
  /* EKC mct end mods */
  
  local_printf(4,70,"-o <name of file for compressed bit-stream>");
  local_printf(4,70,"-rate <max rate in bpp> (default = %g)",
           default_max_bpp);
  /* SAIC/Fuji LRA begin */
  local_printf(4,70,"-low_rate_tol <lower tolerance to max_rate in bpp> "
           "(default = %g)",default_low_rate_tol);
  local_printf(4,70,"-hi_rate_tol <higher tolerance to max_rate in bpp> "
           "(default = %g)",default_hi_rate_tol);
  /* SAIC/Fuji LRA end */
  local_printf(4,70,"-step <normalized base step> (default = %g)",
           default_base_step);
  local_printf(4,70,"-iter <num rate-control iterations> (default = %d)\n",
           default_iterations);
  local_printf(4,70,"-mem [<stop id>]");  /* SAIC addition */
  local_printf(7,70,"Print memory usage report.  If the optional `stop_id' "
           "parameter is supplied, the program will halt when allocating "
           "memory with the supplied non-zero identifier.  This is the "
           "same identifier printed by the memory report if memory "
           "leaks are detected.");
  local_printf(4,70,"-verbose (default = %s)",
           (default_verbose)?"verbose":"quiet");
  local_printf(4,70,"-quiet (default = %s)",
           (default_verbose)?"verbose":"quiet");
  
  stream = constructors->stream_out();
  print_generic_usage(stream->get_usage(stream));
  stream->terminate(stream);
  info = constructors->forward_info();
  print_generic_usage(info->get_usage(info));
  info->terminate(info, 0);
  encoder = constructors->encoder();
  print_generic_usage(encoder->get_usage(encoder));
  encoder->terminate(encoder);
  roi = constructors->forward_roi();
  print_generic_usage(roi->get_usage(roi));
  roi->terminate(roi);
  quantizer = constructors->quantizer();
  print_generic_usage(quantizer->get_usage(quantizer));
  quantizer->terminate(quantizer);
  analysis = constructors->analysis();
  print_generic_usage(analysis->get_usage(analysis));
  analysis->terminate(analysis);
  mixer = constructors->component_mix();
  print_generic_usage(mixer->get_usage(mixer));
  mixer->terminate(mixer);
  
  local_printf(4,70,"-u");
  local_printf(7,70,"Print this usage statement and exit.  Overrides other "
           "arguments.");
}

/*****************************************************************************/
/* STATIC                    parse_common_arguments                          */
/*****************************************************************************/
static void parse_common_arguments(float *max_bpp,
                   float *low_rate_tol, /* SAIC/FUJI */
                   float *hi_rate_tol, /* SAIC/FUJI */
                   int *Flra_flag, /* SAIC/FUJI */
                   float *base_step,int *iterations,
                   int *verbose,char **compressed_filename,
                   int *memory_report,int *memory_stop_id,
                   cmdl_ref cmdl, int argc,
                   enc_constructor_info_ptr constructors)
{
  int p;
  char **params;
  
  /* SAIC/Fuji LRA begin */
  int tcq_flag = 0;
  int lra_flag = 0;
  int no_lra_flag = 0;
  int rate_flag = 0;
  /* SAIC/Fuji LRA end */
  
  if (argc <= 1)
    {
      local_printf(0,76,"Use `-u' for usage!");
      local_exit(-1);
    }
  if ((p=cmdl->extract(cmdl,"-u",-1,&params)) >= 0)
    {
      print_usage(*max_bpp,*low_rate_tol, *hi_rate_tol,*base_step,
          *iterations,*verbose,constructors);
      local_exit(0);
    }
  *compressed_filename = NULL;
  *memory_report = *memory_stop_id = 0;
  
  /* SAIC/Fuji LRA begin */
  if (cmdl->extract(cmdl,"-Qtcq",-1,&params) >= 0)
    {
      tcq_flag = 1;
      *iterations = 10;
    }
  if (cmdl->extract(cmdl,"-Flra",-1,&params) >= 0)
    {
      lra_flag = 1;
      *iterations = 10; 
    } 
  if (cmdl->extract(cmdl,"-Fno_lra",-1,&params) >= 0)
    no_lra_flag = 1;
  /* SAIC/Fuji LRA end */
  
  if ((p = cmdl->extract(cmdl,"-o",-1,&params)) >= 0)
    {
      if (p != 1)
    local_error("The `-o' argument requires exactly one parameter!");
      *compressed_filename = params[0];
    }
  if ((p = cmdl->extract(cmdl,"-rate",-1,&params)) >= 0)
    {
      if ((p != 1) || (sscanf(params[0],"%f",max_bpp) == 0))
    local_error("The `-rate' argument requires exactly one numeric "
            "parameter!");
      rate_flag = 1;
    }
  if ((p = cmdl->extract(cmdl,"-low_rate_tol",-1,&params)) >= 0)
    {
      if ((p != 1) || (sscanf(params[0],"%f",low_rate_tol) == 0))
    local_error("The `-low_rate_tol' argument requires exactly one "
            "numeric parameter!");
    }
  if ((p = cmdl->extract(cmdl,"-hi_rate_tol",-1,&params)) >= 0)
    {
      if ((p != 1) || (sscanf(params[0],"%f",hi_rate_tol) == 0))
    local_error("The `-hi_rate_tol' argument requires exactly one "
            "numeric parameter!");
    }
  if ((p = cmdl->extract(cmdl,"-step",-1,&params)) >= 0)
    {
      if ((p != 1) || (sscanf(params[0],"%f",base_step) == 0) ||
      (*base_step <= 0.0F) || (*base_step > 1.0F))
    local_error("The `-step' argument requires exactly one "
            "numeric parameter in the interval (0,1]!");
    }
  if ((p = cmdl->extract(cmdl,"-iter",-1,&params)) >= 0)
    {
      if ((p != 1) || (sscanf(params[0],"%d",iterations) == 0))
    local_error("The `-iter' argument requires the number of "
            "rate-control iterations!");
    }

⌨️ 快捷键说明

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