📄 kdu_compress.cpp
字号:
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";}/*****************************************************************************//* STATIC get_bpp_dims *//*****************************************************************************/static int get_bpp_dims(siz_params *siz){ int comps, max_width, max_height, n; siz->get(Scomponents,0,0,comps); max_width = max_height = 0; for (n=0; n < comps; n++) { int width, height; siz->get(Sdims,n,0,height); siz->get(Sdims,n,1,width); if (width > max_width) max_width = width; if (height > max_height) max_height = height; } return max_height * max_width;}/*****************************************************************************//* STATIC check_jp2_suffix *//*****************************************************************************/static bool check_jp2_suffix(char *fname) /* Returns true if the file-name has the suffix, ".jp2", where the check is case insensitive. */{ char *cp = strrchr(fname,'.'); if (cp == NULL) return false; cp++; if ((*cp != 'j') && (*cp != 'J')) return false; cp++; if ((*cp != 'p') && (*cp != 'P')) return false; cp++; if (*cp != '2') return false; return true;}/*****************************************************************************//* STATIC set_jp2_attributes *//*****************************************************************************/static void set_jp2_attributes(jp2_target &jp2_out, siz_params *siz, kdu_rgb8_palette &palette, int num_components, kdu_args &args){ // Set dimensional information (all redundant with the SIZ marker segment) jp2_dimensions dims = jp2_out.access_dimensions(); dims.init(siz); // Set resolution information (optional) if (args.find("-jp2_aspect") != NULL) { float aspect_ratio; char *string = args.advance(); if ((string == NULL) || (sscanf(string,"%f",&aspect_ratio) != 1) || (aspect_ratio <= 0.0F)) { kdu_error e; e << "Missing or illegal aspect ratio " "parameter supplied with the `-jp2_aspect' argument!"; } args.advance(); jp2_resolution res = jp2_out.access_resolution(); res.init(aspect_ratio); } // Set colour space information (mandatory) jp2_colour colour = jp2_out.access_colour(); int num_colours = (num_components < 3)?1:3; if (palette.exists()) num_colours = (palette.is_monochrome())?1:3; if (args.find("-jp2_space") != NULL) { char *string = args.advance(); if (string == NULL) { kdu_error e; e << "The `-jp2_space' argument requires a parameter " "string!"; } char *delim = strchr(string,','); if (delim != NULL) *delim = '\0'; if (strcmp(string,"sRGB") == 0) colour.init(JP2_sRGB_SPACE); else if (strcmp(string,"sYCC") == 0) colour.init(JP2_sYCC_SPACE); else if (strcmp(string,"sLUM") == 0) colour.init(JP2_sLUM_SPACE); else if (strcmp(string,"iccLUM") == 0) { float gamma, beta; string = delim+1; if ((delim == NULL) || ((delim = strchr(string,',')) == NULL) || ((*delim = '\0') > 0) || (sscanf(string,"%f",&gamma) != 1) || (sscanf(delim+1,"%f",&beta) != 1) || (gamma < 1.0F) || (beta < 0.0F) || (beta >= 1.0F)) { kdu_error e; e << "Missing or illegal gamma/beta parameters " "supplied in comma-separated parameter list which must follow " "the \"sLUM\" JP2 colour space specification supplied via the " "`-jp2_space' argument. `gamma' must be no less than 1 and " "`beta' must be in the range 0 to 1."; } colour.init(gamma,beta); } else if (strcmp(string,"iccRGB") == 0) { float val, gamma, beta, matrix3x3[9]; for (int p=0; p < 11; p++) { string = delim+1; if ((delim == NULL) || ((p < 10) && ((delim = strchr(string,',')) == NULL)) || ((*delim = '\0') > 0) || (sscanf(string,"%f",&val) != 1)) { kdu_error e; e << "The \"iccRGB\" specification must be " "followed immediately by a comma-separated list of 11 " "parameters, all within the single parameter string " "supplied with the `-jp2_space' argument. For more details " "review the usage statement."; } if (p == 0) gamma = val; else if (p == 1) beta = val; else matrix3x3[p-2] = val; } if ((gamma < 1.0F) || (beta < 0.0F) || (beta >= 1.0F)) { kdu_error e; e << "Illegal gamma or beta value supplied in the " "\"iccRGB\" specification following the `-jp2_space' argument. " "`gamma' must not be less than 1 and `beta' must be in the " "range 0 to 1."; } colour.init(matrix3x3,gamma,beta); } else { kdu_error e; e << "Invalid parameter string following `-jp2_space' " "argument. The string must identify the colour space as one of " "\"sLUM\", \"sRGB\", \"sYCC\", \"iccLUM\" or \"iccRGB\"."; } args.advance(); if (colour.get_num_colours() > num_colours) { kdu_error e; e << "Colour space specified using `-jp2_space' " "requires more image components or a colour palette."; } } else colour.init((num_colours==3)?JP2_sRGB_SPACE:JP2_sLUM_SPACE); // Set the colour palette and channel mapping as needed. if (palette.exists())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -