Doxygen Source Code Documentation
cjpeg.c File Reference
#include "cdjpeg.h"
#include "jversion.h"
#include "cderror.h"
Go to the source code of this file.
Defines | |
#define | JMESSAGE(code, string) string , |
Functions | |
select_file_type (j_compress_ptr cinfo, FILE *infile) | |
usage (void) | |
parse_switches (j_compress_ptr cinfo, int argc, char **argv, int last_file_arg_seen, boolean for_real) | |
int | main (int argc, char **argv) |
Variables | |
const char *const | cdjpeg_message_table [] |
boolean | is_targa |
const char * | progname |
char * | outfilename |
Define Documentation
|
|
Function Documentation
|
Definition at line 593 of file cjpeg.c. References EXIT_WARNING.
00604 : EXIT_SUCCESS); 00605 return 0; /* suppress no-return-value warnings */ 00606 } |
|
Definition at line 331 of file cjpeg.c.
00339 { 00340 /* Quantization table slot numbers. */ 00341 if (++argn >= argc) /* advance to next argument */ 00342 usage(); 00343 qslotsarg = argv[argn]; 00344 /* Must delay setting qslots until after we have processed any 00345 * colorspace-determining switches, since jpeg_set_colorspace sets 00346 * default quant table numbers. 00347 */ 00348 00349 } else if (keymatch(arg, "qtables", 2)) { 00350 /* Quantization tables fetched from file. */ 00351 if (++argn >= argc) /* advance to next argument */ 00352 usage(); 00353 qtablefile = argv[argn]; 00354 /* We postpone actually reading the file in case -quality comes later. */ 00355 00356 } else if (keymatch(arg, "restart", 1)) { 00357 /* Restart interval in MCU rows (or in MCUs with 'b'). */ 00358 long lval; 00359 char ch = 'x'; 00360 00361 if (++argn >= argc) /* advance to next argument */ 00362 usage(); 00363 if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) 00364 usage(); 00365 if (lval < 0 || lval > 65535L) 00366 usage(); 00367 if (ch == 'b' || ch == 'B') { 00368 cinfo->restart_interval = (unsigned int) lval; 00369 cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */ 00370 } else { 00371 cinfo->restart_in_rows = (int) lval; 00372 /* restart_interval will be computed during startup */ 00373 } 00374 00375 } else if (keymatch(arg, "sample", 2)) { 00376 /* Set sampling factors. */ 00377 if (++argn >= argc) /* advance to next argument */ 00378 usage(); 00379 samplearg = argv[argn]; 00380 /* Must delay setting sample factors until after we have processed any 00381 * colorspace-determining switches, since jpeg_set_colorspace sets 00382 * default sampling factors. 00383 */ 00384 00385 } else if (keymatch(arg, "scans", 2)) { 00386 /* Set scan script. */ 00387 #ifdef C_MULTISCAN_FILES_SUPPORTED 00388 if (++argn >= argc) /* advance to next argument */ 00389 usage(); 00390 scansarg = argv[argn]; 00391 /* We must postpone reading the file in case -progressive appears. */ 00392 #else 00393 fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n", 00394 progname); 00395 exit(EXIT_FAILURE); 00396 #endif 00397 00398 } else if (keymatch(arg, "smooth", 2)) { 00399 /* Set input smoothing factor. */ 00400 int val; 00401 00402 if (++argn >= argc) /* advance to next argument */ 00403 usage(); 00404 if (sscanf(argv[argn], "%d", &val) != 1) 00405 usage(); 00406 if (val < 0 || val > 100) 00407 usage(); 00408 cinfo->smoothing_factor = val; 00409 00410 } else if (keymatch(arg, "targa", 1)) { 00411 /* Input file is Targa format. */ 00412 is_targa = TRUE; 00413 00414 } else { 00415 usage(); /* bogus switch */ 00416 } 00417 } 00418 00419 /* Post-switch-scanning cleanup */ 00420 00421 if (for_real) { 00422 00423 /* Set quantization tables for selected quality. */ 00424 /* Some or all may be overridden if -qtables is present. */ 00425 jpeg_set_quality(cinfo, quality, force_baseline); 00426 00427 if (qtablefile != NULL) /* process -qtables if it was present */ 00428 if (! read_quant_tables(cinfo, qtablefile, 00429 q_scale_factor, force_baseline)) 00430 usage(); 00431 00432 if (qslotsarg != NULL) /* process -qslots if it was present */ 00433 if (! set_quant_slots(cinfo, qslotsarg)) 00434 usage(); 00435 00436 if (samplearg != NULL) /* process -sample if it was present */ 00437 if (! set_sample_factors(cinfo, samplearg)) 00438 usage(); 00439 00440 #ifdef C_PROGRESSIVE_SUPPORTED 00441 if (simple_progressive) /* process -progressive; -scans can override */ 00442 jpeg_simple_progression(cinfo); 00443 #endif 00444 00445 #ifdef C_MULTISCAN_FILES_SUPPORTED 00446 if (scansarg != NULL) /* process -scans if it was present */ 00447 if (! read_scan_script(cinfo, scansarg)) 00448 usage(); 00449 #endif 00450 } 00451 00452 return argn; /* return index of next arg (file name) */ 00453 } 00454 00455 00456 /* 00457 * The main program. 00458 */ 00459 00460 int 00461 main (int argc, char **argv) 00462 { 00463 struct jpeg_compress_struct cinfo; 00464 struct jpeg_error_mgr jerr; 00465 #ifdef PROGRESS_REPORT 00466 struct cdjpeg_progress_mgr progress; 00467 #endif 00468 int file_index; 00469 cjpeg_source_ptr src_mgr; 00470 FILE * input_file; 00471 FILE * output_file; 00472 JDIMENSION num_scanlines; 00473 00474 /* On Mac, fetch a command line. */ 00475 #ifdef USE_CCOMMAND 00476 argc = ccommand(&argv); 00477 #endif 00478 00479 progname = argv[0]; 00480 if (progname == NULL || progname[0] == 0) 00481 progname = "cjpeg"; /* in case C library doesn't provide it */ 00482 00483 /* Initialize the JPEG compression object with default error handling. */ 00484 cinfo.err = jpeg_std_error(&jerr); 00485 jpeg_create_compress(&cinfo); 00486 /* Add some application-specific error messages (from cderror.h) */ 00487 jerr.addon_message_table = cdjpeg_message_table; 00488 jerr.first_addon_message = JMSG_FIRSTADDONCODE; 00489 jerr.last_addon_message = JMSG_LASTADDONCODE; 00490 00491 /* Now safe to enable signal catcher. */ 00492 #ifdef NEED_SIGNAL_CATCHER 00493 enable_signal_catcher((j_common_ptr) &cinfo); 00494 #endif 00495 00496 /* Initialize JPEG parameters. 00497 * Much of this may be overridden later. 00498 * In particular, we don't yet know the input file's color space, 00499 * but we need to provide some value for jpeg_set_defaults() to work. 00500 */ 00501 00502 cinfo.in_color_space = JCS_RGB; /* arbitrary guess */ 00503 jpeg_set_defaults(&cinfo); 00504 00505 /* Scan command line to find file names. 00506 * It is convenient to use just one switch-parsing routine, but the switch 00507 * values read here are ignored; we will rescan the switches after opening 00508 * the input file. 00509 */ 00510 00511 file_index = parse_switches(&cinfo, argc, argv, 0, FALSE); 00512 00513 #ifdef TWO_FILE_COMMANDLINE 00514 /* Must have either -outfile switch or explicit output file name */ 00515 if (outfilename == NULL) { 00516 if (file_index != argc-2) { 00517 fprintf(stderr, "%s: must name one input and one output file\n", 00518 progname); 00519 usage(); 00520 } 00521 outfilename = argv[file_index+1]; 00522 } else { 00523 if (file_index != argc-1) { 00524 fprintf(stderr, "%s: must name one input and one output file\n", 00525 progname); 00526 usage(); 00527 } 00528 } 00529 #else 00530 /* Unix style: expect zero or one file name */ 00531 if (file_index < argc-1) { 00532 fprintf(stderr, "%s: only one input file\n", progname); 00533 usage(); 00534 } 00535 #endif /* TWO_FILE_COMMANDLINE */ 00536 00537 /* Open the input file. */ 00538 if (file_index < argc) { 00539 if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) { 00540 fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]); 00541 exit(EXIT_FAILURE); 00542 } 00543 } else { 00544 /* default input file is stdin */ 00545 input_file = read_stdin(); 00546 } 00547 00548 /* Open the output file. */ 00549 if (outfilename != NULL) { 00550 if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) { 00551 fprintf(stderr, "%s: can't open %s\n", progname, outfilename); 00552 exit(EXIT_FAILURE); 00553 } 00554 } else { 00555 /* default output file is stdout */ 00556 output_file = write_stdout(); 00557 } 00558 00559 #ifdef PROGRESS_REPORT 00560 start_progress_monitor((j_common_ptr) &cinfo, &progress); 00561 #endif 00562 00563 /* Figure out the input file format, and set up to read it. */ 00564 src_mgr = select_file_type(&cinfo, input_file); 00565 src_mgr->input_file = input_file; 00566 00567 /* Read the input file header to obtain file size & colorspace. */ 00568 (*src_mgr->start_input) (&cinfo, src_mgr); 00569 00570 /* Now that we know input colorspace, fix colorspace-dependent defaults */ 00571 jpeg_default_colorspace(&cinfo); 00572 00573 /* Adjust default compression parameters by re-parsing the options */ 00574 file_index = parse_switches(&cinfo, argc, argv, 0, TRUE); 00575 00576 /* Specify data destination for compression */ 00577 jpeg_stdio_dest(&cinfo, output_file); 00578 00579 /* Start compressor */ 00580 jpeg_start_compress(&cinfo, TRUE); 00581 00582 /* Process data */ 00583 while (cinfo.next_scanline < cinfo.image_height) { 00584 num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr); 00585 (void) jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines); |
|
Definition at line 212 of file cjpeg.c. References arg, argc, jpeg_compress_struct::arith_code, jpeg_compress_struct::dct_method, is_targa, JDCT_ISLOW, keymatch(), outfilename, progname, quality, and usage().
00235 { 00236 arg = argv[argn]; 00237 if (*arg != '-') { 00238 /* Not a switch, must be a file name argument */ 00239 if (argn <= last_file_arg_seen) { 00240 outfilename = NULL; /* -outfile applies to just one input file */ 00241 continue; /* ignore this name if previously processed */ 00242 } 00243 break; /* else done parsing switches */ 00244 } 00245 arg++; /* advance past switch marker character */ 00246 00247 if (keymatch(arg, "arithmetic", 1)) { 00248 /* Use arithmetic coding. */ 00249 #ifdef C_ARITH_CODING_SUPPORTED 00250 cinfo->arith_code = TRUE; 00251 #else 00252 fprintf(stderr, "%s: sorry, arithmetic coding not supported\n", 00253 progname); 00254 exit(EXIT_FAILURE); 00255 #endif 00256 |
|
Definition at line 273 of file cjpeg.c.
00274 { 00275 /* Enable debug printouts. */ 00276 /* On first -d, print version identification */ 00277 static boolean printed_version = FALSE; 00278 00279 if (! printed_version) { 00280 fprintf(stderr, "Independent JPEG Group's CJPEG, version %s\n%s\n", 00281 JVERSION, JCOPYRIGHT); 00282 printed_version = TRUE; 00283 } 00284 cinfo->err->trace_level++; 00285 00286 } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) { 00287 /* Force a monochrome JPEG file to be generated. */ 00288 jpeg_set_colorspace(cinfo, JCS_GRAYSCALE); 00289 00290 } else if (keymatch(arg, "maxmemory", 3)) { 00291 /* Maximum memory in Kb (or Mb with 'm'). */ 00292 long lval; 00293 char ch = 'x'; 00294 00295 if (++argn >= argc) /* advance to next argument */ 00296 usage(); 00297 if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) 00298 usage(); 00299 if (ch == 'm' || ch == 'M') 00300 lval *= 1000L; 00301 cinfo->mem->max_memory_to_use = lval * 1000L; 00302 00303 } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) { 00304 /* Enable entropy parm optimization. */ 00305 #ifdef ENTROPY_OPT_SUPPORTED 00306 cinfo->optimize_coding = TRUE; 00307 #else 00308 fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n", 00309 progname); 00310 exit(EXIT_FAILURE); 00311 #endif 00312 00313 } else if (keymatch(arg, "outfile", 4)) { 00314 /* Set output file name. */ 00315 if (++argn >= argc) /* advance to next argument */ 00316 usage(); 00317 outfilename = argv[argn]; /* save it away for later use */ 00318 00319 } else if (keymatch(arg, "progressive", 1)) { 00320 /* Select simple progressive mode. */ 00321 #ifdef C_PROGRESSIVE_SUPPORTED 00322 simple_progressive = TRUE; 00323 /* We must postpone execution until num_components is known. */ 00324 #else 00325 fprintf(stderr, "%s: sorry, progressive output was not compiled\n", 00326 progname); 00327 exit(EXIT_FAILURE); |
Variable Documentation
|
|
|
Definition at line 208 of file cjpeg.c. Referenced by select_file_type(). |
|
Definition at line 269 of file cjpeg.c. Referenced by select_file_type(). |
|
Definition at line 268 of file cjpeg.c. Referenced by select_file_type(). |