jasper.c.svn-base
来自「SumatraPDF是一款小型开源的pdf阅读工具。虽然玲珑小巧(只有800多K」· SVN-BASE 代码 · 共 557 行 · 第 1/2 页
SVN-BASE
557 行
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;
}
cmdopts_t *cmdopts_parse(int argc, char **argv)
{
typedef enum {
CMDOPT_HELP = 0,
CMDOPT_VERBOSE,
CMDOPT_INFILE,
CMDOPT_INFMT,
CMDOPT_INOPT,
CMDOPT_OUTFILE,
CMDOPT_OUTFMT,
CMDOPT_OUTOPT,
CMDOPT_VERSION,
CMDOPT_DEBUG,
CMDOPT_CMPTNO,
CMDOPT_SRGB
} cmdoptid_t;
static jas_opt_t cmdoptions[] = {
{CMDOPT_HELP, "help", 0},
{CMDOPT_VERBOSE, "verbose", 0},
{CMDOPT_INFILE, "input", JAS_OPT_HASARG},
{CMDOPT_INFILE, "f", JAS_OPT_HASARG},
{CMDOPT_INFMT, "input-format", JAS_OPT_HASARG},
{CMDOPT_INFMT, "t", JAS_OPT_HASARG},
{CMDOPT_INOPT, "input-option", JAS_OPT_HASARG},
{CMDOPT_INOPT, "o", JAS_OPT_HASARG},
{CMDOPT_OUTFILE, "output", JAS_OPT_HASARG},
{CMDOPT_OUTFILE, "F", JAS_OPT_HASARG},
{CMDOPT_OUTFMT, "output-format", JAS_OPT_HASARG},
{CMDOPT_OUTFMT, "T", JAS_OPT_HASARG},
{CMDOPT_OUTOPT, "output-option", JAS_OPT_HASARG},
{CMDOPT_OUTOPT, "O", JAS_OPT_HASARG},
{CMDOPT_VERSION, "version", 0},
{CMDOPT_DEBUG, "debug-level", JAS_OPT_HASARG},
{CMDOPT_CMPTNO, "cmptno", JAS_OPT_HASARG},
{CMDOPT_SRGB, "force-srgb", 0},
{CMDOPT_SRGB, "S", 0},
{-1, 0, 0}
};
cmdopts_t *cmdopts;
int c;
if (!(cmdopts = malloc(sizeof(cmdopts_t)))) {
jas_eprintf("error: insufficient memory\n");
exit(EXIT_FAILURE);
}
cmdopts->infile = 0;
cmdopts->infmt = -1;
cmdopts->inopts = 0;
cmdopts->inoptsbuf[0] = '\0';
cmdopts->outfile = 0;
cmdopts->outfmt = -1;
cmdopts->outopts = 0;
cmdopts->outoptsbuf[0] = '\0';
cmdopts->verbose = 0;
cmdopts->version = 0;
cmdopts->cmptno = -1;
cmdopts->debug = 0;
cmdopts->srgb = 0;
while ((c = jas_getopt(argc, argv, cmdoptions)) != EOF) {
switch (c) {
case CMDOPT_HELP:
cmdusage();
break;
case CMDOPT_VERBOSE:
cmdopts->verbose = 1;
break;
case CMDOPT_VERSION:
cmdopts->version = 1;
break;
case CMDOPT_DEBUG:
cmdopts->debug = atoi(jas_optarg);
break;
case CMDOPT_INFILE:
cmdopts->infile = jas_optarg;
break;
case CMDOPT_INFMT:
if ((cmdopts->infmt = jas_image_strtofmt(jas_optarg)) < 0) {
jas_eprintf("warning: ignoring invalid input format %s\n",
jas_optarg);
cmdopts->infmt = -1;
}
break;
case CMDOPT_INOPT:
addopt(cmdopts->inoptsbuf, OPTSMAX, jas_optarg);
cmdopts->inopts = cmdopts->inoptsbuf;
break;
case CMDOPT_OUTFILE:
cmdopts->outfile = jas_optarg;
break;
case CMDOPT_OUTFMT:
if ((cmdopts->outfmt = jas_image_strtofmt(jas_optarg)) < 0) {
jas_eprintf("error: invalid output format %s\n", jas_optarg);
badusage();
}
break;
case CMDOPT_OUTOPT:
addopt(cmdopts->outoptsbuf, OPTSMAX, jas_optarg);
cmdopts->outopts = cmdopts->outoptsbuf;
break;
case CMDOPT_CMPTNO:
cmdopts->cmptno = atoi(jas_optarg);
break;
case CMDOPT_SRGB:
cmdopts->srgb = 1;
break;
default:
badusage();
break;
}
}
while (jas_optind < argc) {
jas_eprintf(
"warning: ignoring bogus command line argument %s\n",
argv[jas_optind]);
++jas_optind;
}
if (cmdopts->version) {
goto done;
}
if (cmdopts->outfmt < 0 && cmdopts->outfile) {
if ((cmdopts->outfmt = jas_image_fmtfromname(cmdopts->outfile)) < 0) {
jas_eprintf(
"error: cannot guess image format from output file name\n");
}
}
if (cmdopts->outfmt < 0) {
jas_eprintf("error: no output format specified\n");
badusage();
}
done:
return cmdopts;
}
void cmdopts_destroy(cmdopts_t *cmdopts)
{
free(cmdopts);
}
int addopt(char *optstr, int maxlen, char *s)
{
int n;
int m;
n = strlen(optstr);
m = n + strlen(s) + 1;
if (m > maxlen) {
return 1;
}
if (n > 0) {
strcat(optstr, "\n");
}
strcat(optstr, s);
return 0;
}
void cmdinfo()
{
jas_eprintf("JasPer Transcoder (Version %s).\n",
JAS_VERSION);
jas_eprintf("%s\n", JAS_COPYRIGHT);
jas_eprintf("%s\n", JAS_NOTES);
}
static char *helpinfo[] = {
"The following options are supported:\n",
" --help Print this help information and exit.\n",
" --version Print version information and exit.\n",
" --verbose Enable verbose mode.\n",
" --debug-level $lev Set the debug level to $lev.\n",
" --input $file Read the input image from the file named $file\n",
" instead of standard input.\n",
" --input-format $fmt Specify the format of the input image as $fmt.\n",
" (See below for the list of supported formats.)\n",
" --input-option $opt Provide the option $opt to the decoder.\n",
" --output $file Write the output image to the file named $file\n",
" instead of standard output.\n",
" --output-format $fmt Specify the format of the output image as $fmt.\n",
" (See below for the list of supported formats.)\n",
" --output-option $opt Provide the option $opt to the encoder.\n",
" --force-srgb Force conversion to the sRGB color space.\n",
"Some of the above option names can be abbreviated as follows:\n",
" --input = -f, --input-format = -t, --input-option = -o,\n",
" --output = -F, --output-format = -T, --output-option = -O\n",
0
};
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);
}
void badusage()
{
jas_eprintf(
"For more information on how to use this command, type:\n");
jas_eprintf(" %s --help\n", cmdname);
exit(EXIT_FAILURE);
}
#if 0
jas_image_t *converttosrgb(jas_image_t *inimage)
{
jas_image_t *outimage;
jas_cmpixmap_t inpixmap;
jas_cmpixmap_t outpixmap;
jas_cmcmptfmt_t incmptfmts[16];
jas_cmcmptfmt_t outcmptfmts[16];
outprof = jas_cmprof_createfromclrspc(JAS_CLRSPC_SRGB);
assert(outprof);
xform = jas_cmxform_create(jas_image_cmprof(inimage), outprof, 0, JAS_CMXFORM_FWD, JAS_CMXFORM_INTENT_PER, 0);
assert(xform);
inpixmap.numcmpts = jas_image_numcmpts(oldimage);
outpixmap.numcmpts = 3;
for (i = 0; i < inpixmap.numcmpts; ++i) {
inpixmap.cmptfmts[i] = &incmptfmts[i];
}
for (i = 0; i < outpixmap.numcmpts; ++i)
outpixmap.cmptfmts[i] = &outcmptfmts[i];
if (jas_cmxform_apply(xform, &inpixmap, &outpixmap))
abort();
jas_xform_destroy(xform);
jas_cmprof_destroy(outprof);
return 0;
}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?