📄 kdu_transcode.cpp
字号:
static void parse_simple_args(kdu_args &args, char * &ifname, char * &ofname, std::ostream * &record_stream, int &discard_levels, int &skip_components, int &max_components, float &max_bpp, bool &transpose, bool &vflip, bool &hflip, bool &mem, bool &quiet) /* Parses most simple arguments (those involving a dash). Note that `max_bpp' is returned as negative if the bit-rate is not explicitly set. */{ if ((args.get_first() == NULL) || (args.find("-about") != NULL)) print_about(args.get_prog_name()); if (args.find("-u") != NULL) print_usage(args.get_prog_name()); if (args.find("-usage") != NULL) print_usage(args.get_prog_name(),true); ifname = NULL; ofname = NULL; record_stream = NULL; discard_levels = 0; skip_components = 0; max_components = 0; max_bpp = -1.0; int rotate = 0; mem = false; quiet = false; if (args.find("-i") != NULL) { if ((ifname = args.advance()) == NULL) { kdu_error e; e << "\"-i\" argument requires a file name!"; } 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("-reduce") != NULL) { char *string = args.advance(); if ((string == NULL) || (sscanf(string,"%d",&discard_levels) != 1) || (discard_levels < 0)) { kdu_error e; e << "\"-reduce\" argument requires a non-negative " "integer parameter!"; } args.advance(); } if (args.find("-skip_components") != NULL) { char *string = args.advance(); if ((string == NULL) || (sscanf(string,"%d",&skip_components) != 1) || (skip_components < 0)) { kdu_error e; e << "\"-skip_components\" argument requires a " "non-negative integer parameter!"; } args.advance(); } if (args.find("-components") != NULL) { char *string = args.advance(); if ((string == NULL) || (sscanf(string,"%d",&max_components) != 1) || (max_components <= 0)) { kdu_error e; e << "\"-components\" argument requires a positive " "integer parameter!"; } args.advance(); } if (args.find("-rate") != NULL) { char *string = args.advance(); if ((string == NULL) || (sscanf(string,"%f",&max_bpp) != 1) || (max_bpp <= 0.0F)) { kdu_error e; e << "\"-rate\" argument requires a positive " "numeric parameter!"; } args.advance(); } 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("-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 ((ifname == NULL) || (ofname == NULL)) { kdu_error e; e << "Must at least supply the names of an input and an " "output file."; } while (rotate >= 4) rotate -= 4; while (rotate < 0) rotate += 4; switch (rotate) { /* Note: we will be applying the geometric transformations to the input code-stream. */ case 0: transpose = false; vflip = false; hflip = false; break; case 1: transpose = true; vflip = false; hflip = true; break; case 2: transpose = false; vflip = true; hflip = true; break; case 3: transpose = true; vflip = true; hflip = false; break; }}/*****************************************************************************//* STATIC check_jp2_compatible_suffix *//*****************************************************************************/static bool check_jp2_compatible_suffix(char *fname) /* Returns true if the file-name has the suffix, ".jp2" or ".jpx", 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') && (*cp != 'x') && (*cp != 'X')) return false; return true;}/*****************************************************************************//* STATIC set_error_behaviour *//*****************************************************************************/static void set_error_behaviour(kdu_args &args, kdu_codestream codestream){ bool fussy = false; bool resilient = false; bool ubiquitous_sops = false; if (args.find("-fussy") != NULL) { args.advance(); fussy = true; } if (args.find("-resilient") != NULL) { args.advance(); resilient = true; } if (args.find("-resilient_sop") != NULL) { args.advance(); resilient = true; ubiquitous_sops = true; } if (resilient) codestream.set_resilient(ubiquitous_sops); else if (fussy) codestream.set_fussy(); else codestream.set_fast();}/*****************************************************************************//* 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 copy_block *//*****************************************************************************/ static void copy_block(kdu_block *in, kdu_block *out){ if (in->K_max_prime != out->K_max_prime) { kdu_error e; e << "Cannot copy blocks belonging to subbands with " "different quantization parameters."; } assert(!(out->transpose || out->vflip || out->hflip)); kdu_coords size = in->size; if (in->transpose) size.transpose(); if ((size.x != out->size.x) || (size.y != out->size.y)) { kdu_error e; e << "Cannot copy code-blocks with different dimensions."; } out->missing_msbs = in->missing_msbs; if (out->max_passes < (in->num_passes+2)) // Gives us enough to round up out->set_max_passes(in->num_passes+2,false); // to the next whole bit-plane out->num_passes = in->num_passes; int num_bytes = 0; for (int z=0; z < in->num_passes; z++) { num_bytes += (out->pass_lengths[z] = in->pass_lengths[z]); out->pass_slopes[z] = in->pass_slopes[z]; } if ((in->modes != out->modes) || (in->orientation != out->orientation) || in->transpose || in->vflip || in->hflip) { // Need to transcode the individual code-blocks. kdu_block_decoder decoder; decoder.decode(in); out->num_passes = in->num_passes; // Just in case we couldn't decode all if (out->num_passes == 0) return; int num_samples = in->size.x*in->size.y; if (num_samples > out->max_samples) out->set_max_samples((num_samples>4096)?num_samples:4096); if (in->transpose || in->vflip || in->hflip) { // Need geometric transformation and termination at whole bit-plane int row_gap_in = in->size.x; int row_gap_out = out->size.x; kdu_int32 *sp, *spp = in->sample_buffer; kdu_int32 *dp, *dpp = out->sample_buffer; int out_cinc = 1; if (in->vflip) { dpp += (size.y-1)*row_gap_out; row_gap_out = -row_gap_out; } if (in->hflip) { dpp += size.x-1; out_cinc = -out_cinc; } int r, c; if (!in->transpose) { // Non-transposed copy for (r=size.y; r > 0; r--, spp+=row_gap_in, dpp+=row_gap_out ) { // Unroll loop a little for speed. for (sp=spp, dp=dpp, c=size.x; c > 3; c-=4) { *dp = *(sp++); dp += out_cinc; *dp = *(sp++); dp += out_cinc; *dp = *(sp++); dp += out_cinc; *dp = *(sp++); dp += out_cinc; } while (c--) { *dp = *(sp++); dp += out_cinc; } } } else { // Transposed copy for (r=size.y; r > 0; r--, spp++, dpp+=row_gap_out) { // Unroll loop a little for speed. for (sp=spp, dp=dpp, c=size.x; c > 3; c-=4) { *dp = *sp; sp += row_gap_in; dp += out_cinc; *dp = *sp; sp += row_gap_in; dp += out_cinc;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -