static void usage() { cmdinfo(); jas_eprintf("usage:\n"); jas_eprintf("%s ", cmdname); jas_eprintf("[-f image_file]\n"); exit(EXIT_FAILURE); }
static void usage() { char *s; int i; cmdinfo(); jas_eprintf("usage: %s [options] [file1 file2 ...]\n", cmdname); for (i = 0, s = helpinfo[i]; s; ++i, s = helpinfo[i]) { jas_eprintf("%s", s); } cleanupandexit(EXIT_FAILURE); }
Bscript::ObjArray* GetCommandsInPackage( Plib::Package* m_pkg, int cmdlvl_num ) { if ( cmdlvl_num >= static_cast<int>( gamestate.cmdlevels.size() ) ) cmdlvl_num = static_cast<int>( gamestate.cmdlevels.size() - 1 ); CmdLevel& cmdlevel = gamestate.cmdlevels[cmdlvl_num]; std::unique_ptr<Bscript::ObjArray> script_names( new Bscript::ObjArray ); for ( unsigned diridx = 0; diridx < cmdlevel.searchlist.size(); ++diridx ) { CmdLevel::SearchDir* search_dir = &cmdlevel.searchlist[diridx]; Plib::Package* pkg = search_dir->pkg; std::string dir_name = search_dir->dir; if ( ( !pkg && m_pkg ) || ( pkg && !m_pkg ) ) continue; if ( pkg && m_pkg ) { if ( pkg != m_pkg ) continue; dir_name = std::string( pkg->dir().c_str() ) + dir_name; } for ( Clib::DirList dl( dir_name.c_str() ); !dl.at_end(); dl.next() ) { std::string name = dl.name(), ext; if ( name[0] == '.' ) continue; std::string::size_type pos = name.rfind( '.' ); if ( pos != std::string::npos ) ext = name.substr( pos ); if ( pos != std::string::npos && ( !ext.compare( ".ecl" ) ) ) { std::unique_ptr<Bscript::BStruct> cmdinfo( new Bscript::BStruct ); cmdinfo->addMember( "dir", new Bscript::String( search_dir->dir ) ); cmdinfo->addMember( "script", new Bscript::String( name.c_str() ) ); script_names->addElement( cmdinfo.release() ); } } } if ( script_names->ref_arr.size() > 0 ) return script_names.release(); else return nullptr; }
static void usage() { cmdinfo(); jas_eprintf("usage:\n"); jas_eprintf("%s ", cmdname); jas_eprintf( "-f reference_image_file -F other_image_file [-m metric]\n" ); jas_eprintf( "The metric argument may assume one of the following values:\n" " psnr .... peak signal to noise ratio\n" " mse ..... mean squared error\n" " rmse .... root mean squared error\n" " pae ..... peak absolute error\n" " mae ..... mean absolute error\n" " equal ... equality (boolean)\n" ); exit(EXIT_FAILURE); }
int tar_cmd(const HWND hwnd, LPCSTR szCmdLine,LPSTR szOutput, const DWORD dwSize, int *pWriteSize) { CTar32CmdInfo cmdinfo(szOutput, dwSize-1); int ret; try{ tar_cmd_parser(szCmdLine,cmdinfo); ret = tar_cmd_itr(hwnd, szCmdLine,szOutput,dwSize,cmdinfo); }catch(CTar32Exception &e){ cmdinfo.output << "TAR32 Error(0x" << std::hex << e.m_code << "): " << e.m_str << "\n"; cmdinfo.output << "Tar((HWND)" << (unsigned)hwnd << ",(LPCSTR)" << szCmdLine << ",,(DWORD)" << (unsigned)dwSize << ")\n"; ret = e.m_code; cmd_usage(cmdinfo); } // int len = strlen(cmdinfo.output.str()); int len = cmdinfo.output.rdbuf()->pcount(); if(dwSize>0)szOutput[len] = '\0'; if(pWriteSize){*pWriteSize = len;} return ret; }
void cmdusage() { int fmtid; jas_image_fmtinfo_t *fmtinfo; char *s; int i; cmdinfo(); jas_eprintf("usage: %s [options]\n", cmdname); for (i = 0, s = helpinfo[i]; s; ++i, s = helpinfo[i]) { jas_eprintf("%s", s); } jas_eprintf("The following formats are supported:\n"); for (fmtid = 0;; ++fmtid) { if (!(fmtinfo = jas_image_lookupfmtbyid(fmtid))) { break; } jas_eprintf(" %-5s %s\n", fmtinfo->name, fmtinfo->desc); } exit(EXIT_FAILURE); }
int main(int argc, char **argv) { jas_image_t *image; cmdopts_t *cmdopts; jas_stream_t *in; jas_stream_t *out; clock_t startclk; clock_t endclk; long dectime; long enctime; int_fast16_t numcmpts; int i; /* Determine the base name of this command. */ if ((cmdname = strrchr(argv[0], '/'))) { ++cmdname; } else { cmdname = argv[0]; } if (jas_init()) { errprint(0, "error: cannot initialize jasper library\n"); abort(); } /* set our error callback */ jas_set_error_cb(errprint); /* Parse the command line options. */ if (!(cmdopts = cmdopts_parse(argc, argv))) { jas_eprintf("error: cannot parse command line\n"); exit(EXIT_FAILURE); } if (cmdopts->version) { jas_eprintf("%s\n", JAS_VERSION); jas_eprintf("libjasper %s\n", jas_getversion()); exit(EXIT_SUCCESS); } jas_setdbglevel(cmdopts->debug); if (cmdopts->verbose) { cmdinfo(); } /* Open the input image file. */ if (cmdopts->infile) { /* The input image is to be read from a file. */ if (!(in = jas_stream_fopen(cmdopts->infile, "rb"))) { jas_eprintf("error: cannot open input image file %s\n", cmdopts->infile); exit(EXIT_FAILURE); } } else { /* The input image is to be read from standard input. */ if (!(in = jas_stream_fdopen(0, "rb"))) { jas_eprintf("error: cannot open standard input\n"); exit(EXIT_FAILURE); } } /* Open the output image file. */ if (cmdopts->outfile) { /* The output image is to be written to a file. */ if (!(out = jas_stream_fopen(cmdopts->outfile, "w+b"))) { jas_eprintf("error: cannot open output image file %s\n", cmdopts->outfile); exit(EXIT_FAILURE); } } else { /* The output image is to be written to standard output. */ if (!(out = jas_stream_fdopen(1, "w+b"))) { jas_eprintf("error: cannot open standard output\n"); exit(EXIT_FAILURE); } } if (cmdopts->infmt < 0) { if ((cmdopts->infmt = jas_image_getfmt(in)) < 0) { jas_eprintf("error: input image has unknown format\n"); exit(EXIT_FAILURE); } } /* Get the input image data. */ startclk = clock(); if (!(image = jas_image_decode(in, cmdopts->infmt, cmdopts->inopts))) { jas_eprintf("error: cannot load image data\n"); exit(EXIT_FAILURE); } endclk = clock(); dectime = endclk - startclk; /* If requested, throw away all of the components except one. Why might this be desirable? It is a hack, really. None of the image formats other than the JPEG-2000 ones support images with two, four, five, or more components. This hack allows such images to be decoded with the non-JPEG-2000 decoders, one component at a time. */ numcmpts = jas_image_numcmpts(image); if (cmdopts->cmptno >= 0 && cmdopts->cmptno < numcmpts) { for (i = numcmpts - 1; i >= 0; --i) { if (i != cmdopts->cmptno) { jas_image_delcmpt(image, i); } } } if (cmdopts->srgb) { jas_image_t *newimage; jas_cmprof_t *outprof; jas_eprintf("forcing conversion to sRGB\n"); if (!(outprof = jas_cmprof_createfromclrspc(JAS_CLRSPC_SRGB))) { jas_eprintf("cannot create sRGB profile\n"); exit(EXIT_FAILURE); } if (!(newimage = jas_image_chclrspc(image, outprof, JAS_CMXFORM_INTENT_PER))) { jas_eprintf("cannot convert to sRGB\n"); exit(EXIT_FAILURE); } jas_image_destroy(image); jas_cmprof_destroy(outprof); image = newimage; } /* Generate the output image data. */ startclk = clock(); if (jas_image_encode(image, out, cmdopts->outfmt, cmdopts->outopts)) { jas_eprintf("error: cannot encode image\n"); exit(EXIT_FAILURE); } jas_stream_flush(out); endclk = clock(); enctime = endclk - startclk; if (cmdopts->verbose) { jas_eprintf("decoding time = %f\n", dectime / (double) CLOCKS_PER_SEC); jas_eprintf("encoding time = %f\n", enctime / (double) CLOCKS_PER_SEC); } /* If this fails, we don't care. */ (void) jas_stream_close(in); /* Close the output image stream. */ if (jas_stream_close(out)) { jas_eprintf("error: cannot close output image file\n"); exit(EXIT_FAILURE); } cmdopts_destroy(cmdopts); jas_image_destroy(image); jas_image_clearfmts(); /* Success at last! :-) */ return EXIT_SUCCESS; }
int main(int argc, char **argv) { char *origpath; char *reconpath; int verbose; char *metricname; int metric; int id; jas_image_t *origimage; jas_image_t *reconimage; jas_matrix_t *origdata; jas_matrix_t *recondata; jas_image_t *diffimage; jas_stream_t *diffstream; int width; int height; int depth; int numcomps; double d; double maxdist; double mindist; int compno; jas_stream_t *origstream; jas_stream_t *reconstream; char *diffpath; int maxonly; int minonly; int fmtid; verbose = 0; origpath = 0; reconpath = 0; metricname = 0; metric = metricid_none; diffpath = 0; maxonly = 0; minonly = 0; if (jas_init()) { errprint(0, "error: cannot initialize jasper library\n"); abort(); } /* set our error callback */ jas_set_error_cb(errprint); cmdname = argv[0]; /* Parse the command line options. */ while ((id = jas_getopt(argc, argv, opts)) >= 0) { switch (id) { case OPT_MAXONLY: maxonly = 1; break; case OPT_MINONLY: minonly = 1; break; case OPT_METRIC: metricname = jas_optarg; break; case OPT_ORIG: origpath = jas_optarg; break; case OPT_RECON: reconpath = jas_optarg; break; case OPT_VERBOSE: verbose = 1; break; case OPT_DIFFIMAGE: diffpath = jas_optarg; break; case OPT_VERSION: printf("%s\n", JAS_VERSION); exit(EXIT_SUCCESS); break; case OPT_HELP: default: usage(); break; } } if (verbose) { cmdinfo(); } /* Ensure that files are given for both the original and reconstructed images. */ if (!origpath || !reconpath) { usage(); } /* If a metric was specified, process it. */ if (metricname) { if ((metric = (jas_taginfo_nonull(jas_taginfos_lookup(metrictab, metricname))->id)) < 0) { usage(); } } /* Open the original image file. */ if (!(origstream = jas_stream_fopen(origpath, "rb"))) { jas_eprintf("cannot open %s\n", origpath); return EXIT_FAILURE; } /* Open the reconstructed image file. */ if (!(reconstream = jas_stream_fopen(reconpath, "rb"))) { jas_eprintf("cannot open %s\n", reconpath); return EXIT_FAILURE; } /* Decode the original image. */ if (!(origimage = jas_image_decode(origstream, -1, 0))) { jas_eprintf("cannot load original image\n"); return EXIT_FAILURE; } /* Decoder the reconstructed image. */ if (!(reconimage = jas_image_decode(reconstream, -1, 0))) { jas_eprintf("cannot load reconstructed image\n"); return EXIT_FAILURE; } /* Close the original image file. */ jas_stream_close(origstream); /* Close the reconstructed image file. */ jas_stream_close(reconstream); /* Ensure that both images have the same number of components. */ numcomps = jas_image_numcmpts(origimage); if (jas_image_numcmpts(reconimage) != numcomps) { jas_eprintf("number of components differ\n"); return EXIT_FAILURE; } /* Compute the difference for each component. */ maxdist = 0; mindist = FLT_MAX; for (compno = 0; compno < numcomps; ++compno) { width = jas_image_cmptwidth(origimage, compno); height = jas_image_cmptheight(origimage, compno); depth = jas_image_cmptprec(origimage, compno); if (jas_image_cmptwidth(reconimage, compno) != width || jas_image_cmptheight(reconimage, compno) != height) { jas_eprintf("image dimensions differ\n"); return EXIT_FAILURE; } if (jas_image_cmptprec(reconimage, compno) != depth) { jas_eprintf("precisions differ\n"); return EXIT_FAILURE; } if (!(origdata = jas_matrix_create(height, width))) { jas_eprintf("internal error\n"); return EXIT_FAILURE; } if (!(recondata = jas_matrix_create(height, width))) { jas_eprintf("internal error\n"); return EXIT_FAILURE; } if (jas_image_readcmpt(origimage, compno, 0, 0, width, height, origdata)) { jas_eprintf("cannot read component data\n"); return EXIT_FAILURE; } if (jas_image_readcmpt(reconimage, compno, 0, 0, width, height, recondata)) { jas_eprintf("cannot read component data\n"); return EXIT_FAILURE; } if (diffpath) { if (!(diffstream = jas_stream_fopen(diffpath, "rwb"))) { jas_eprintf("cannot open diff stream\n"); return EXIT_FAILURE; } if (!(diffimage = makediffimage(origdata, recondata))) { jas_eprintf("cannot make diff image\n"); return EXIT_FAILURE; } fmtid = jas_image_strtofmt("pnm"); if (jas_image_encode(diffimage, diffstream, fmtid, 0)) { jas_eprintf("cannot save\n"); return EXIT_FAILURE; } jas_stream_close(diffstream); jas_image_destroy(diffimage); } if (metric != metricid_none) { d = getdistortion(origdata, recondata, depth, metric); if (d > maxdist) { maxdist = d; } if (d < mindist) { mindist = d; } if (!maxonly && !minonly) { if (metric == metricid_pae || metric == metricid_equal) { printf("%ld\n", (long) ceil(d)); } else { printf("%f\n", d); } } } jas_matrix_destroy(origdata); jas_matrix_destroy(recondata); } if (metric != metricid_none && (maxonly || minonly)) { if (maxonly) { d = maxdist; } else if (minonly) { d = mindist; } else { abort(); } if (metric == metricid_pae || metric == metricid_equal) { jas_eprintf("%ld\n", (long) ceil(d)); } else { jas_eprintf("%f\n", d); } } jas_image_destroy(origimage); jas_image_destroy(reconimage); jas_image_clearfmts(); return EXIT_SUCCESS; }