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

📄 kdu_compress.cpp

📁 JPEG2000压缩解压图像源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    {      out.flush();      exit(0);    }  strbuf.set_master_indent(0);  out << "Notes:\n";  strbuf.set_master_indent(3);  out << "    Arguments which commence with an upper case letter (rather than "         "a dash) are used to set up code-stream parameter attributes. "         "These arguments have the general form:"         "  <arg name>={fld1,fld2,...},{fld1,fld2,...},..., "         "where curly braces enclose records and each record is composed of "         "fields.  The type and acceptable values for the fields are "         "identified in the usage statements, along with whether or not "         "multiple records are allowed.  In the special case where only one "         "field is defined per record, the curly braces may be omitted. "         "In no event may any spaces appear inside an attribute argument.\n";  out << "    Most of the code-stream parameter attributes take an optional "         "tile-component modifier, consisting of a colon, followed by a "         "tile specifier, a component specifier, or both.  The tile specifier "         "consists of the letter `T', followed immediately be the tile index "         "(tiles are numbered in raster order, starting from 0).  Similarly, "         "the component specifier consists of the letter `C', followed "         "immediately by the component index (starting from 0). These "         "modifiers may be used to specify parameter changes in specific "         "tiles, components, or tile-components.\n";  out << "    If you do not remember the exact form or description of one of "         "the code-stream attribute arguments, simply give the attribute name "         "on the command-line and the program will exit with a detailed "         "description of the attribute.\n";  out << "    If SIZ parameters are to be supplied explicitly on the "         "command line, be aware that these may be affected by simultaneous "         "specification of geometric transformations.  If uncertain of the "         "behaviour, use `-record' to determine the final compressed "         "code-stream parameters which were used.\n";  out << "    If you are compressing a 3 component image using the "         "reversible or irreversible colour transform (this is the default), "         "the program will automatically introduce a reasonable set of visual "         "weighting factors, unless you use the \"Clev_weights\" or "         "\"Cband_weights\" options yourself.  This does not happen "         "automatically in the case of single component images, which are "         "optimized purely for MSE by default.  To see whether weighting "         "factors were used, you may like to use the `-record' option.\n";  out.flush();  exit(0);}/*****************************************************************************//* STATIC                     parse_simple_args                              *//*****************************************************************************/static kdc_file_binding *  parse_simple_args(kdu_args &args, char * &ofname,                    std::ostream * &record_stream,                    bool &transpose, bool &vflip, bool &hflip,                    bool &allow_rate_prediction, bool &allow_shorts,                    bool &no_weights, bool &no_palette, int &cpu_iterations,                    bool &mem, bool &quiet)  /* Parses most simple arguments (those involving a dash). Most parameters are     returned via the reference arguments, with the exception of the input     file names, which are returned via a linked list of `kdc_file_binding'     objects.  Only the `fname' field of each `kdc_file_binding' record is     filled out here.  The value returned via `cpu_iterations' is negative     unless CPU times are required. */{  int rotate;  kdc_file_binding *files, *last_file, *new_file;  if ((args.get_first() == NULL) || (args.find("-u") != NULL))    print_usage(args.get_prog_name());  if (args.find("-usage") != NULL)    print_usage(args.get_prog_name(),true);  files = last_file = NULL;  ofname = NULL;  record_stream = NULL;  rotate = 0;  allow_rate_prediction = true;  allow_shorts = true;  no_weights = false;  no_palette = false;  cpu_iterations = -1;  mem = false;  quiet = false;  if (args.find("-i") != NULL)    {      char *string, *cp;      int len;      if ((string = args.advance()) == NULL)        { kdu_error e; e << "\"-i\" argument requires a file name!"; }      while ((len=strlen(string)) > 0)        {          cp = strchr(string,',');          if (cp == NULL)            cp = string+len;          new_file = new kdc_file_binding(string,cp-string);          if (last_file == NULL)            files = last_file = new_file;          else            last_file = last_file->next = new_file;          if (*cp == ',') cp++;          string = cp;        }      args.advance();    }  if (args.find("-o") != NULL)    {      if ((ofname = args.advance()) == NULL)        { kdu_error e; e << "\"-o\" argument requires a file name!"; }      args.advance();    }  if (args.find("-full") != NULL)    {      args.advance();      allow_rate_prediction = false;    }  if (args.find("-precise") != NULL)    {      args.advance();      allow_shorts = false;    }  if (args.find("-rotate") != NULL)    {      char *string = args.advance();      if ((string == NULL) || (sscanf(string,"%d",&rotate) != 1) ||          ((rotate % 90) != 0))        { kdu_error e; e << "\"-rotate\" argument requires an integer "          "multiple of 90 degrees!"; }      args.advance();      rotate /= 90;    }  if (args.find("-cpu") != NULL)    {      char *string = args.advance();      if ((string == NULL) || (sscanf(string,"%d",&cpu_iterations) != 1) ||          (cpu_iterations < 0))        { kdu_error e; e << "\"-cpu\" argument requires a non-negative "          "integer, specifying the number of times to execute the block "          "coder within a timing loop."; }      args.advance();    }  if (args.find("-no_weights") != NULL)    {      no_weights = true;      args.advance();    }  if (args.find("-no_palette") != NULL)    {      no_palette = true;      args.advance();    }  if (args.find("-mem") != NULL)    {      mem = true;      args.advance();    }  if (args.find("-quiet") != NULL)    {      quiet = true;      args.advance();    }  if (args.find("-record") != NULL)    {      char *fname = args.advance();      if (fname == NULL)        { kdu_error e; e << "\"-record\" argument requires a file name!"; }      record_stream = new std::ofstream(fname);      if (record_stream->fail())        { kdu_error e; e << "Unable to open record file, \"" << fname << "\"."; }      args.advance();    }  if (files == NULL)    { kdu_error e; e << "Must provide one or more input files!"; }  if (ofname == NULL)    { kdu_error e; e << "Must provide an output file name!"; }  while (rotate >= 4)    rotate -= 4;  while (rotate < 0)    rotate += 4;  switch (rotate) {    case 0: transpose = false; vflip = false; hflip = false; break;    case 1: transpose = true; vflip = true; hflip = false; break;    case 2: transpose = false; vflip = true; hflip = true; break;    case 3: transpose = true; vflip = false; hflip = true; break;    }  return(files);}/*****************************************************************************//* STATIC                   set_jp2_coding_defaults                          *//*****************************************************************************/static void  set_jp2_coding_defaults(jp2_target &out, kdu_params *siz){  kdu_params *cod = siz->access_cluster(COD_params);  assert(cod != NULL);  int num_colours = out.access_colour().get_num_colours();  bool using_palette = (out.access_palette().get_num_components() > 0);  bool use_ycc, reversible;  int dwt_levels;  if (((num_colours < 3) ||       (out.access_colour().get_space() == JP2_sYCC_SPACE) ||       using_palette) &&      !cod->get(Cycc,0,0,use_ycc))    cod->set(Cycc,0,0,use_ycc=false);  if (using_palette && !cod->get(Creversible,0,0,reversible))    cod->set(Creversible,0,0,reversible=true);  if (using_palette && !cod->get(Clevels,0,0,dwt_levels))    cod->set(Clevels,0,0,dwt_levels=0);}/*****************************************************************************//* STATIC                  set_default_colour_weights                        *//*****************************************************************************/static void  set_default_colour_weights(kdu_params *siz, bool quiet){  kdu_params *cod = siz->access_cluster(COD_params);  assert(cod != NULL);  bool can_use_ycc = true;  bool rev0=false;  int depth0=0, sub_x0=1, sub_y0=1;  for (int c=0; c < 3; c++)    {      int depth=0; siz->get(Sprecision,c,0,depth);      int sub_y=1; siz->get(Ssampling,c,0,sub_y);      int sub_x=1; siz->get(Ssampling,c,1,sub_x);      kdu_params *coc = cod->access_relation(-1,c);      bool rev=false; coc->get(Creversible,0,0,rev);      if (c == 0)        { rev0=rev; depth0=depth; sub_x0=sub_x; sub_y0=sub_y; }      else if ((rev != rev0) || (depth != depth0) ||        (sub_x != sub_x0) || (sub_y != sub_y0))        can_use_ycc = false;    }  if (!can_use_ycc)    return;  bool use_ycc;  if (!cod->get(Cycc,0,0,use_ycc))    cod->set(Cycc,0,0,use_ycc=true);  if (!use_ycc)    return;  float weight;  if (cod->get(Clev_weights,0,0,weight) ||      cod->get(Cband_weights,0,0,weight))    return; // Weights already specified explicitly.  /* These example weights are adapted from numbers generated by Marcus Nadenau     at EPFL, for a viewing distance of 15 cm and a display resolution of     300 DPI. */    cod->parse_string("Cband_weights:C0="                    "{0.0901},{0.2758},{0.2758},"                    "{0.7018},{0.8378},{0.8378},{1}");  cod->parse_string("Cband_weights:C1="                    "{0.0263},{0.0863},{0.0863},"                    "{0.1362},{0.2564},{0.2564},"                    "{0.3346},{0.4691},{0.4691},"                    "{0.5444},{0.6523},{0.6523},"                    "{0.7078},{0.7797},{0.7797},{1}");  cod->parse_string("Cband_weights:C2="                    "{0.0773},{0.1835},{0.1835},"                    "{0.2598},{0.4130},{0.4130},"                    "{0.5040},{0.6464},{0.6464},"                    "{0.7220},{0.8254},{0.8254},"                    "{0.8769},{0.9424},{0.9424},{1}");  if (!quiet)    pretty_cout << "Note:\n\tThe default rate control policy for colour "                   "images employs visual (CSF) weighting factors.  To "                   "minimize MSE instead, specify `-no_weights'.\n";}

⌨️ 快捷键说明

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