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

📄 decompress.c

📁 JPEG2000实现的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
  print_generic_usage(demixer->get_usage(demixer));
  demixer->terminate(demixer);

  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(int *level_reduction,
                         float *parse_bpp, float *truncate_bpp,
                         int *max_components, int *verbose,
                         char **compressed_filename, int *memory_report,
                         int *memory_stop_id, cmdl_ref cmdl, int argc,
                         dec_constructor_info_ptr constructors)
{
  char **params;
  int p;

  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(*verbose,constructors);
      local_exit(0);
    }
  *compressed_filename = NULL;
  *memory_report = *memory_stop_id = 0;
  *parse_bpp = -1.0F; /* No parsing. */
  *truncate_bpp = -1.0F; /* No truncation. */

  if ((p = cmdl->extract(cmdl,"-i",-1,&params)) >= 0)
    {
      if (p != 1)
        local_error("The `-i' argument requires exactly one parameter!");
      *compressed_filename = params[0];
    }
  if ((p = cmdl->extract(cmdl,"-red",-1,&params)) >= 0)
    {
      if ((p != 1) || (sscanf(params[0],"%d",level_reduction) == 0) ||
          (*level_reduction < 0))
        local_error("The `-red' argument requires exactly one non-negative "
                    "integer parameter!");
    }
  if ((p = cmdl->extract(cmdl,"-parse",-1,&params)) >= 0)
    {
      if ((p != 1) || (sscanf(params[0],"%f",parse_bpp) == 0) ||
          (*parse_bpp <= 0.0F))
        local_error("The `-parse' argument requires exactly one positive "
                    "numeric parameter!");
    }
  if ((p = cmdl->extract(cmdl,"-trunc",-1,&params)) >= 0)
    {
      if ((p != 1) || (sscanf(params[0],"%f",truncate_bpp) == 0) ||
          (*truncate_bpp <= 0.0F))
        local_error("The `-trunc' argument requires exactly one positive "
                    "numeric parameter!");
    }
  if ((p = cmdl->extract(cmdl,"-comp",-1,&params)) >= 0)
    {
      if ((p != 1) || (sscanf(params[0],"%d",max_components) == 0) ||
          (*max_components < 1))
        local_error("The `-comp' argument requires exactly one positive "
                    "integer parameter!");
    }
  if ((p = cmdl->extract(cmdl,"-mem",-1,&params)) >= 0)
    {
      *memory_report = 1;
      if (p == 1)
        {
          if (sscanf(params[0],"%d",memory_stop_id) == 0)
            local_error("The `-mem' argument takes either no parameters "
                        "or else an integer valued memory stop id; the "
                        "supplied parameter, \"%s\", is illegal!",params[0]);
        }
      else if (p != 0)
        local_error("The `-mem' argument takes at most one parameter!");
    }
  if ((p = cmdl->extract(cmdl,"-quiet",-1,&params)) >= 0)
    {
      if (p != 0)
        local_error("The `-quiet' argument takes no parameters!");
      *verbose = 0;
    }
  if ((p = cmdl->extract(cmdl,"-verbose",-1,&params)) >= 0)
    {
      if (p != 0)
        local_error("The `-verbose' argument takes no parameters!");
      *verbose = 1;
    }

  if (*compressed_filename == NULL)
    local_error("Must supply a name for the compressed input file!");
}


/* ========================================================================= */
/* -------------------------- External Functions --------------------------- */
/* ========================================================================= */

/*****************************************************************************/
/* EXTERN                             main                                   */
/*****************************************************************************/

int
  main(int argc, char *argv[])
{
  extern cmdl_ref create_std_cmdl(void);

  dec_constructor_info constructors;
  int level_reduction, max_components;
  int verbose, memory_report, memory_stop_id;
  float parse_bpp, truncate_bpp;
  char *compressed_filename;
  image_writer_ref writer;
  stream_in_ref stream;
  reverse_info_ref info;
  decoder_ref decoder;
  reverse_roi_ref roi;
  dequantizer_ref dequantizer;
  synthesis_ref synthesis;
  component_demix_ref demixer;
  cmdl_ref cmdl;
  int components_in, components_out, *bitdepths;
  canvas_dims_ptr dims;
  int max_rows, max_cols, actual_bytes, n, num_tiles;
  /* Begin Aerospace MCT mods (TSW) */
  int *dims_reference;
  /* End Aerospace MCT mods */

  /* OTLPF_CONVENTION begin; JX Wei ADFA, WJ Zeng Sharp */
  int otlpf_convention;
  int size;
  /* OTLPF_CONVENTION end; JX Wei ADFA, WJ Zeng Sharp */

  /* Initialize the memory system: must be done before any memory is
     allocated. */

  for (n=1; n < argc; n++)
    if (strcmp(argv[n],"-mem") == 0)
      local_memory_collect_stats();

  /* Create `cmdl' object and constructors. */

  cmdl = create_std_cmdl();
  cmdl->initialize(cmdl,argc,argv);
  find_dec_constructors(&constructors,cmdl);

  /* Get the common arguments. */

  level_reduction = 0;
  max_components = 256;
  verbose = 1;
  parse_common_arguments(&level_reduction,&parse_bpp,&truncate_bpp,
                         &max_components,&verbose,&compressed_filename,
                         &memory_report,&memory_stop_id,cmdl,argc,
                         &constructors);
  if (memory_stop_id)
    local_memory_set_stop_id(memory_stop_id);

  /* Create and initialize stream object */

  stream = constructors.stream_in();
  stream->initialize(stream,compressed_filename,cmdl);

  /* Based on stream header, modify constructors */

  /* EKC mct begin mods */
  modify_dec_constructors(&constructors,stream,cmdl);
  /* EKC mct end mods */
  
  /* Create other objects. */

  writer = constructors.image_writer();
  info = constructors.reverse_info();
  decoder = constructors.decoder();
  roi = constructors.reverse_roi();
  dequantizer = constructors.dequantizer();
  synthesis = constructors.synthesis();
  demixer = constructors.component_demix();

  /* Initialize objects. */

  components_in = stream->get_marker_val(stream,-1,MARKER_SIZ_C,0,0);
  /* Begin Aerospace MCT mods (TSW) */
  /* Need to check here whether the number of output components from any
     multi-component transform is different from the number of
     components present in the codestream (as given by the SIZ marker) */
  /* components_out = components_in;*/
  /*** The marker name must be changed to agree with Jim's choice;
       for now the answer is hard-wired for testing ***/
    if(stream->size_marker_elt(stream,-1,MARKER_CBD_N,0))
        components_out = stream->get_marker_val(stream,-1,MARKER_CBD_N,0,0);
    else
        components_out = components_in;
  /* components_out = 7; */
  /*  if (components_out > max_components)*/
  if ( (components_out > max_components) && (max_components < components_in) )
    components_out = max_components;
  /* End Aerospace MCT mods */

  info->initialize(info,components_in,stream,cmdl);
  dims = (canvas_dims_ptr)
    local_malloc(INVOCATION_MEM_KEY,sizeof(canvas_dims)*components_out);
  bitdepths = (int *)
    local_malloc(INVOCATION_MEM_KEY,sizeof(int)*components_out);

  /* Begin Aerospace MCT mods (TSW) */
  /* If a multi-component transform is used, it will not in general be
     possible to reconstruct fewer output components without first
     synthesizing all input components. Until there is a way to perform
     a main header check on whether or not a multi-component transform
     is used, initialize output dimensions for all input components. */
  /* OTLPF_COVENTION begin;  JX Wei, ADFA / WJ Zeng Sharp */
  otlpf_convention = (int) stream->get_main_cmetag(stream, 0xFD00, 0, &size);
  num_tiles = get_output_dims(info,components_in,otlpf_convention,level_reduction,dims);
  /* OTLPF_CONVENTION end; JX Wei ADFA, WJ Zeng Sharp */

  max_rows = max_cols = 0;

  /*  for (n=0; n < components_out; n++)*/
  for (n=0; n < components_in; n++)
    {
      if (dims[n].rows > max_rows)
        max_rows = dims[n].rows;
      if (dims[n].cols > max_cols)
        max_cols = dims[n].cols;

      /* MITRE General Offset/SQ Begin */ 
      info->get_fixed_tile_info(info,n,0,NULL,NULL,NULL,NULL,NULL,
				NULL,NULL,NULL,bitdepths+n,NULL);
      /* MITRE General Offset/SQ End */

    }

  /* Now, if a CBD marker segment is present, the bitdepths as retrieved
     here are incorrect for the output components. Therefore if the CBD
     exists, extract the correct bitdepths here. */
  if ( stream->size_marker_elt(stream,-1,MARKER_CBD_N,0) ) {
    int *bd = (int *) stream->get_marker_val_indirect(stream,-1,MARKER_CBD_BD,
                              0);
    for(n=0; n<components_out; n++)
      bitdepths[n] = bd[n];
  }
  /* End Aerospace MCT mods */
  
  if (truncate_bpp > 0.0F)
    {
      int max_bytes = (int)(0.125F*truncate_bpp*(float)(max_rows*max_cols));
      stream->set_max_bytes(stream,max_bytes);
    }
  roi->initialize(roi,level_reduction,components_in,info,stream,cmdl);

  /* Begin Aerospace MCT mods (TSW) */
  /* Again, in genereal the decoder will have to decode all input components
     when a multi-component transform is used. Until there is a global
     way to check for presence of such a transform, the decoder and
     synthesizer must be initialized for all input components. */
  /*  decoder->initialize(decoder,components_in,level_reduction,components_out,
      info,roi,stream,cmdl);*/
  decoder->initialize(decoder,components_in,level_reduction,components_in,
                      info,roi,stream,cmdl);
  dequantizer->initialize(dequantizer,components_in,info,decoder,stream,cmdl);
  /*  synthesis->initialize(synthesis,level_reduction,components_out,info,*/
  synthesis->initialize(synthesis,level_reduction,components_in,info,
  /* End Aerospace MCT mods */
                        dequantizer,

                        /* SAIC/Sharp/Fuji Xmask begin */
                        decoder,
                        /* SAIC/Sharp/Fuji Xmask end */

                        stream,cmdl);

  demixer->initialize(demixer,level_reduction,components_in,components_out,
                      info,synthesis,stream,cmdl);

  /* Begin Aerospace MCT mods */
  /* The proper referencing array for component dimensions has now been
     established by the demix object. The bitdepths array is already
     accurate, however, the dims array below contains only entries for the
     number of input components. The cross-reference array is therefore
     extracted from the demix object. It is now passed along to the writer
     initialize routine so that correct output dimensions can be derived
     in the presence of a multi-component linear transform. */
  dims_reference = demixer->get_dims_reference(demixer);
  /*  writer->initialize(writer,components_out,bitdepths,dims,cmdl);*/
  writer->initialize(writer,components_out,bitdepths,dims,dims_reference,cmdl);
  /* End Aerospace MCT mods */
  cmdl->terminate(cmdl,1);
  cmdl = NULL;
  if (parse_bpp > 0.0F)
    {
      int max_bytes = (int)(0.125F*parse_bpp*(float)(max_rows*max_cols));
      decoder->parse_to_rate(decoder,max_bytes);
    }

  /* Process the image incrementally. */

  /* OTLPF_CONVENTION begin; JX Wei ADFA, WJ Zeng Sharp */
  decompress_and_write_the_image(info,writer,demixer,components_out,
                                 otlpf_convention, level_reduction);
  /* OTLPF_CONVENTION end; JX Wei ADFA, WJ Zeng Sharp */

  /* Terminate all objects and free storage. */

  writer->terminate(writer);
  demixer->terminate(demixer);
  synthesis->terminate(synthesis);
  dequantizer->terminate(dequantizer);
  actual_bytes = decoder->terminate(decoder);
  roi->terminate(roi);
  info->terminate(info);
  stream->terminate(stream);
  local_free(dims);
  local_free(bitdepths);

  if (verbose)
    local_printf(4,70,"%d components; %d tiles; ",
                 components_out,num_tiles);
    local_printf(4,70,"Actual rate = %g bpp (i.e. %d bytes)",
                 (8.0F*(float) actual_bytes)/((float)(max_rows*max_cols)),
                 actual_bytes);
  if (parse_bpp > 0.0F)
    {
      int max_bytes = (int)(0.125F*parse_bpp*(float)(max_rows*max_cols));
      if (actual_bytes > max_bytes)
        local_error("Decoder failed to parse bit-stream correctly!!\n"
                    "Decompressed bit-stream had %d bytes more than allowed!",
                    actual_bytes-max_bytes);
    }
  if (truncate_bpp > 0.0F)
    {
      int max_bytes = (int)(0.125F*truncate_bpp*(float)(max_rows*max_cols));
      if (actual_bytes > max_bytes)
        local_error("Bit-stream object failed to truncate bit-stream "
                    "correctly!!\n"
                    "Decompressed bit-stream had %d bytes more than allowed!",
                    actual_bytes-max_bytes);
    }
  if (memory_report)
    local_memory_report();
  return(0);
}

⌨️ 快捷键说明

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