ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

cjpeg.c
Go to the documentation of this file.
00001 /*
00002  * cjpeg.c
00003  *
00004  * Copyright (C) 1991-1998, Thomas G. Lane.
00005  * Modified 2003-2010 by Guido Vollbeding.
00006  * This file is part of the Independent JPEG Group's software.
00007  * For conditions of distribution and use, see the accompanying README file.
00008  *
00009  * This file contains a command-line user interface for the JPEG compressor.
00010  * It should work on any system with Unix- or MS-DOS-style command lines.
00011  *
00012  * Two different command line styles are permitted, depending on the
00013  * compile-time switch TWO_FILE_COMMANDLINE:
00014  *  cjpeg [options]  inputfile outputfile
00015  *  cjpeg [options]  [inputfile]
00016  * In the second style, output is always to standard output, which you'd
00017  * normally redirect to a file or pipe to some other program.  Input is
00018  * either from a named file or from standard input (typically redirected).
00019  * The second style is convenient on Unix but is unhelpful on systems that
00020  * don't support pipes.  Also, you MUST use the first style if your system
00021  * doesn't do binary I/O to stdin/stdout.
00022  * To simplify script writing, the "-outfile" switch is provided.  The syntax
00023  *  cjpeg [options]  -outfile outputfile  inputfile
00024  * works regardless of which command line style is used.
00025  */
00026 
00027 #include "cdjpeg.h"     /* Common decls for cjpeg/djpeg applications */
00028 #include "jversion.h"       /* for version message */
00029 
00030 #ifdef USE_CCOMMAND     /* command-line reader for Macintosh */
00031 #ifdef __MWERKS__
00032 #include <SIOUX.h>              /* Metrowerks needs this */
00033 #include <console.h>        /* ... and this */
00034 #endif
00035 #ifdef THINK_C
00036 #include <console.h>        /* Think declares it here */
00037 #endif
00038 #endif
00039 
00040 
00041 /* Create the add-on message string table. */
00042 
00043 #define JMESSAGE(code,string)   string ,
00044 
00045 static const char * const cdjpeg_message_table[] = {
00046 #include "cderror.h"
00047   NULL
00048 };
00049 
00050 
00051 /*
00052  * This routine determines what format the input file is,
00053  * and selects the appropriate input-reading module.
00054  *
00055  * To determine which family of input formats the file belongs to,
00056  * we may look only at the first byte of the file, since C does not
00057  * guarantee that more than one character can be pushed back with ungetc.
00058  * Looking at additional bytes would require one of these approaches:
00059  *     1) assume we can fseek() the input file (fails for piped input);
00060  *     2) assume we can push back more than one character (works in
00061  *        some C implementations, but unportable);
00062  *     3) provide our own buffering (breaks input readers that want to use
00063  *        stdio directly, such as the RLE library);
00064  * or  4) don't put back the data, and modify the input_init methods to assume
00065  *        they start reading after the start of file (also breaks RLE library).
00066  * #1 is attractive for MS-DOS but is untenable on Unix.
00067  *
00068  * The most portable solution for file types that can't be identified by their
00069  * first byte is to make the user tell us what they are.  This is also the
00070  * only approach for "raw" file types that contain only arbitrary values.
00071  * We presently apply this method for Targa files.  Most of the time Targa
00072  * files start with 0x00, so we recognize that case.  Potentially, however,
00073  * a Targa file could start with any byte value (byte 0 is the length of the
00074  * seldom-used ID field), so we provide a switch to force Targa input mode.
00075  */
00076 
00077 static boolean is_targa;    /* records user -targa switch */
00078 
00079 
00080 LOCAL(cjpeg_source_ptr)
00081 select_file_type (j_compress_ptr cinfo, FILE * infile)
00082 {
00083   int c;
00084 
00085   if (is_targa) {
00086 #ifdef TARGA_SUPPORTED
00087     return jinit_read_targa(cinfo);
00088 #else
00089     ERREXIT(cinfo, JERR_TGA_NOTCOMP);
00090 #endif
00091   }
00092 
00093   if ((c = getc(infile)) == EOF)
00094     ERREXIT(cinfo, JERR_INPUT_EMPTY);
00095   if (ungetc(c, infile) == EOF)
00096     ERREXIT(cinfo, JERR_UNGETC_FAILED);
00097 
00098   switch (c) {
00099 #ifdef BMP_SUPPORTED
00100   case 'B':
00101     return jinit_read_bmp(cinfo);
00102 #endif
00103 #ifdef GIF_SUPPORTED
00104   case 'G':
00105     return jinit_read_gif(cinfo);
00106 #endif
00107 #ifdef PPM_SUPPORTED
00108   case 'P':
00109     return jinit_read_ppm(cinfo);
00110 #endif
00111 #ifdef RLE_SUPPORTED
00112   case 'R':
00113     return jinit_read_rle(cinfo);
00114 #endif
00115 #ifdef TARGA_SUPPORTED
00116   case 0x00:
00117     return jinit_read_targa(cinfo);
00118 #endif
00119   default:
00120     ERREXIT(cinfo, JERR_UNKNOWN_FORMAT);
00121     break;
00122   }
00123 
00124   return NULL;          /* suppress compiler warnings */
00125 }
00126 
00127 
00128 /*
00129  * Argument-parsing code.
00130  * The switch parser is designed to be useful with DOS-style command line
00131  * syntax, ie, intermixed switches and file names, where only the switches
00132  * to the left of a given file name affect processing of that file.
00133  * The main program in this file doesn't actually use this capability...
00134  */
00135 
00136 
00137 static const char * progname;   /* program name for error messages */
00138 static char * outfilename;  /* for -outfile switch */
00139 
00140 
00141 LOCAL(void)
00142 usage (void)
00143 /* complain about bad command line */
00144 {
00145   fprintf(stderr, "usage: %s [switches] ", progname);
00146 #ifdef TWO_FILE_COMMANDLINE
00147   fprintf(stderr, "inputfile outputfile\n");
00148 #else
00149   fprintf(stderr, "[inputfile]\n");
00150 #endif
00151 
00152   fprintf(stderr, "Switches (names may be abbreviated):\n");
00153   fprintf(stderr, "  -quality N[,...]   Compression quality (0..100; 5-95 is useful range)\n");
00154   fprintf(stderr, "  -grayscale     Create monochrome JPEG file\n");
00155 #ifdef ENTROPY_OPT_SUPPORTED
00156   fprintf(stderr, "  -optimize      Optimize Huffman table (smaller file, but slow compression)\n");
00157 #endif
00158 #ifdef C_PROGRESSIVE_SUPPORTED
00159   fprintf(stderr, "  -progressive   Create progressive JPEG file\n");
00160 #endif
00161 #ifdef DCT_SCALING_SUPPORTED
00162   fprintf(stderr, "  -scale M/N     Scale image by fraction M/N, eg, 1/2\n");
00163 #endif
00164 #ifdef TARGA_SUPPORTED
00165   fprintf(stderr, "  -targa         Input file is Targa format (usually not needed)\n");
00166 #endif
00167   fprintf(stderr, "Switches for advanced users:\n");
00168 #ifdef DCT_SCALING_SUPPORTED
00169   fprintf(stderr, "  -block N       DCT block size (1..16; default is 8)\n");
00170 #endif
00171 #ifdef DCT_ISLOW_SUPPORTED
00172   fprintf(stderr, "  -dct int       Use integer DCT method%s\n",
00173       (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
00174 #endif
00175 #ifdef DCT_IFAST_SUPPORTED
00176   fprintf(stderr, "  -dct fast      Use fast integer DCT (less accurate)%s\n",
00177       (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
00178 #endif
00179 #ifdef DCT_FLOAT_SUPPORTED
00180   fprintf(stderr, "  -dct float     Use floating-point DCT method%s\n",
00181       (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
00182 #endif
00183   fprintf(stderr, "  -nosmooth      Don't use high-quality downsampling\n");
00184   fprintf(stderr, "  -restart N     Set restart interval in rows, or in blocks with B\n");
00185 #ifdef INPUT_SMOOTHING_SUPPORTED
00186   fprintf(stderr, "  -smooth N      Smooth dithered input (N=1..100 is strength)\n");
00187 #endif
00188   fprintf(stderr, "  -maxmemory N   Maximum memory to use (in kbytes)\n");
00189   fprintf(stderr, "  -outfile name  Specify name for output file\n");
00190   fprintf(stderr, "  -verbose  or  -debug   Emit debug output\n");
00191   fprintf(stderr, "Switches for wizards:\n");
00192 #ifdef C_ARITH_CODING_SUPPORTED
00193   fprintf(stderr, "  -arithmetic    Use arithmetic coding\n");
00194 #endif
00195   fprintf(stderr, "  -baseline      Force baseline quantization tables\n");
00196   fprintf(stderr, "  -qtables file  Use quantization tables given in file\n");
00197   fprintf(stderr, "  -qslots N[,...]    Set component quantization tables\n");
00198   fprintf(stderr, "  -sample HxV[,...]  Set component sampling factors\n");
00199 #ifdef C_MULTISCAN_FILES_SUPPORTED
00200   fprintf(stderr, "  -scans file    Create multi-scan JPEG per script file\n");
00201 #endif
00202   exit(EXIT_FAILURE);
00203 }
00204 
00205 
00206 LOCAL(int)
00207 parse_switches (j_compress_ptr cinfo, int argc, char **argv,
00208         int last_file_arg_seen, boolean for_real)
00209 /* Parse optional switches.
00210  * Returns argv[] index of first file-name argument (== argc if none).
00211  * Any file names with indexes <= last_file_arg_seen are ignored;
00212  * they have presumably been processed in a previous iteration.
00213  * (Pass 0 for last_file_arg_seen on the first or only iteration.)
00214  * for_real is FALSE on the first (dummy) pass; we may skip any expensive
00215  * processing.
00216  */
00217 {
00218   int argn;
00219   char * arg;
00220   boolean force_baseline;
00221   boolean simple_progressive;
00222   char * qualityarg = NULL; /* saves -quality parm if any */
00223   char * qtablefile = NULL; /* saves -qtables filename if any */
00224   char * qslotsarg = NULL;  /* saves -qslots parm if any */
00225   char * samplearg = NULL;  /* saves -sample parm if any */
00226   char * scansarg = NULL;   /* saves -scans parm if any */
00227 
00228   /* Set up default JPEG parameters. */
00229 
00230   force_baseline = FALSE;   /* by default, allow 16-bit quantizers */
00231   simple_progressive = FALSE;
00232   is_targa = FALSE;
00233   outfilename = NULL;
00234   cinfo->err->trace_level = 0;
00235 
00236   /* Scan command line options, adjust parameters */
00237 
00238   for (argn = 1; argn < argc; argn++) {
00239     arg = argv[argn];
00240     if (*arg != '-') {
00241       /* Not a switch, must be a file name argument */
00242       if (argn <= last_file_arg_seen) {
00243     outfilename = NULL; /* -outfile applies to just one input file */
00244     continue;       /* ignore this name if previously processed */
00245       }
00246       break;            /* else done parsing switches */
00247     }
00248     arg++;          /* advance past switch marker character */
00249 
00250     if (keymatch(arg, "arithmetic", 1)) {
00251       /* Use arithmetic coding. */
00252 #ifdef C_ARITH_CODING_SUPPORTED
00253       cinfo->arith_code = TRUE;
00254 #else
00255       fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
00256           progname);
00257       exit(EXIT_FAILURE);
00258 #endif
00259 
00260     } else if (keymatch(arg, "baseline", 2)) {
00261       /* Force baseline-compatible output (8-bit quantizer values). */
00262       force_baseline = TRUE;
00263 
00264     } else if (keymatch(arg, "block", 2)) {
00265       /* Set DCT block size. */
00266 #if defined(DCT_SCALING_SUPPORTED) && defined(JPEG_LIB_VERSION_MAJOR) && \
00267     (JPEG_LIB_VERSION_MAJOR > 8 || (JPEG_LIB_VERSION_MAJOR == 8 && \
00268      defined(JPEG_LIB_VERSION_MINOR) && JPEG_LIB_VERSION_MINOR >= 3))
00269       int val;
00270 
00271       if (++argn >= argc)   /* advance to next argument */
00272     usage();
00273       if (sscanf(argv[argn], "%d", &val) != 1)
00274     usage();
00275       if (val < 1 || val > 16)
00276     usage();
00277       cinfo->block_size = val;
00278 #else
00279       fprintf(stderr, "%s: sorry, block size setting not supported\n",
00280           progname);
00281       exit(EXIT_FAILURE);
00282 #endif
00283 
00284     } else if (keymatch(arg, "dct", 2)) {
00285       /* Select DCT algorithm. */
00286       if (++argn >= argc)   /* advance to next argument */
00287     usage();
00288       if (keymatch(argv[argn], "int", 1)) {
00289     cinfo->dct_method = JDCT_ISLOW;
00290       } else if (keymatch(argv[argn], "fast", 2)) {
00291     cinfo->dct_method = JDCT_IFAST;
00292       } else if (keymatch(argv[argn], "float", 2)) {
00293     cinfo->dct_method = JDCT_FLOAT;
00294       } else
00295     usage();
00296 
00297     } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
00298       /* Enable debug printouts. */
00299       /* On first -d, print version identification */
00300       static boolean printed_version = FALSE;
00301 
00302       if (! printed_version) {
00303     fprintf(stderr, "Independent JPEG Group's CJPEG, version %s\n%s\n",
00304         JVERSION, JCOPYRIGHT);
00305     printed_version = TRUE;
00306       }
00307       cinfo->err->trace_level++;
00308 
00309     } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) {
00310       /* Force a monochrome JPEG file to be generated. */
00311       jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
00312 
00313     } else if (keymatch(arg, "maxmemory", 3)) {
00314       /* Maximum memory in Kb (or Mb with 'm'). */
00315       long lval;
00316       char ch = 'x';
00317 
00318       if (++argn >= argc)   /* advance to next argument */
00319     usage();
00320       if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
00321     usage();
00322       if (ch == 'm' || ch == 'M')
00323     lval *= 1000L;
00324       cinfo->mem->max_memory_to_use = lval * 1000L;
00325 
00326     } else if (keymatch(arg, "nosmooth", 3)) {
00327       /* Suppress fancy downsampling */
00328       cinfo->do_fancy_downsampling = FALSE;
00329 
00330     } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
00331       /* Enable entropy parm optimization. */
00332 #ifdef ENTROPY_OPT_SUPPORTED
00333       cinfo->optimize_coding = TRUE;
00334 #else
00335       fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n",
00336           progname);
00337       exit(EXIT_FAILURE);
00338 #endif
00339 
00340     } else if (keymatch(arg, "outfile", 4)) {
00341       /* Set output file name. */
00342       if (++argn >= argc)   /* advance to next argument */
00343     usage();
00344       outfilename = argv[argn]; /* save it away for later use */
00345 
00346     } else if (keymatch(arg, "progressive", 1)) {
00347       /* Select simple progressive mode. */
00348 #ifdef C_PROGRESSIVE_SUPPORTED
00349       simple_progressive = TRUE;
00350       /* We must postpone execution until num_components is known. */
00351 #else
00352       fprintf(stderr, "%s: sorry, progressive output was not compiled\n",
00353           progname);
00354       exit(EXIT_FAILURE);
00355 #endif
00356 
00357     } else if (keymatch(arg, "quality", 1)) {
00358       /* Quality ratings (quantization table scaling factors). */
00359       if (++argn >= argc)   /* advance to next argument */
00360     usage();
00361       qualityarg = argv[argn];
00362 
00363     } else if (keymatch(arg, "qslots", 2)) {
00364       /* Quantization table slot numbers. */
00365       if (++argn >= argc)   /* advance to next argument */
00366     usage();
00367       qslotsarg = argv[argn];
00368       /* Must delay setting qslots until after we have processed any
00369        * colorspace-determining switches, since jpeg_set_colorspace sets
00370        * default quant table numbers.
00371        */
00372 
00373     } else if (keymatch(arg, "qtables", 2)) {
00374       /* Quantization tables fetched from file. */
00375       if (++argn >= argc)   /* advance to next argument */
00376     usage();
00377       qtablefile = argv[argn];
00378       /* We postpone actually reading the file in case -quality comes later. */
00379 
00380     } else if (keymatch(arg, "restart", 1)) {
00381       /* Restart interval in MCU rows (or in MCUs with 'b'). */
00382       long lval;
00383       char ch = 'x';
00384 
00385       if (++argn >= argc)   /* advance to next argument */
00386     usage();
00387       if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
00388     usage();
00389       if (lval < 0 || lval > 65535L)
00390     usage();
00391       if (ch == 'b' || ch == 'B') {
00392     cinfo->restart_interval = (unsigned int) lval;
00393     cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
00394       } else {
00395     cinfo->restart_in_rows = (int) lval;
00396     /* restart_interval will be computed during startup */
00397       }
00398 
00399     } else if (keymatch(arg, "sample", 2)) {
00400       /* Set sampling factors. */
00401       if (++argn >= argc)   /* advance to next argument */
00402     usage();
00403       samplearg = argv[argn];
00404       /* Must delay setting sample factors until after we have processed any
00405        * colorspace-determining switches, since jpeg_set_colorspace sets
00406        * default sampling factors.
00407        */
00408 
00409     } else if (keymatch(arg, "scale", 4)) {
00410       /* Scale the image by a fraction M/N. */
00411       if (++argn >= argc)   /* advance to next argument */
00412     usage();
00413       if (sscanf(argv[argn], "%d/%d",
00414          &cinfo->scale_num, &cinfo->scale_denom) != 2)
00415     usage();
00416 
00417     } else if (keymatch(arg, "scans", 4)) {
00418       /* Set scan script. */
00419 #ifdef C_MULTISCAN_FILES_SUPPORTED
00420       if (++argn >= argc)   /* advance to next argument */
00421     usage();
00422       scansarg = argv[argn];
00423       /* We must postpone reading the file in case -progressive appears. */
00424 #else
00425       fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n",
00426           progname);
00427       exit(EXIT_FAILURE);
00428 #endif
00429 
00430     } else if (keymatch(arg, "smooth", 2)) {
00431       /* Set input smoothing factor. */
00432       int val;
00433 
00434       if (++argn >= argc)   /* advance to next argument */
00435     usage();
00436       if (sscanf(argv[argn], "%d", &val) != 1)
00437     usage();
00438       if (val < 0 || val > 100)
00439     usage();
00440       cinfo->smoothing_factor = val;
00441 
00442     } else if (keymatch(arg, "targa", 1)) {
00443       /* Input file is Targa format. */
00444       is_targa = TRUE;
00445 
00446     } else {
00447       usage();          /* bogus switch */
00448     }
00449   }
00450 
00451   /* Post-switch-scanning cleanup */
00452 
00453   if (for_real) {
00454 
00455     /* Set quantization tables for selected quality. */
00456     /* Some or all may be overridden if -qtables is present. */
00457     if (qualityarg != NULL) /* process -quality if it was present */
00458       if (! set_quality_ratings(cinfo, qualityarg, force_baseline))
00459     usage();
00460 
00461     if (qtablefile != NULL) /* process -qtables if it was present */
00462       if (! read_quant_tables(cinfo, qtablefile, force_baseline))
00463     usage();
00464 
00465     if (qslotsarg != NULL)  /* process -qslots if it was present */
00466       if (! set_quant_slots(cinfo, qslotsarg))
00467     usage();
00468 
00469     if (samplearg != NULL)  /* process -sample if it was present */
00470       if (! set_sample_factors(cinfo, samplearg))
00471     usage();
00472 
00473 #ifdef C_PROGRESSIVE_SUPPORTED
00474     if (simple_progressive) /* process -progressive; -scans can override */
00475       jpeg_simple_progression(cinfo);
00476 #endif
00477 
00478 #ifdef C_MULTISCAN_FILES_SUPPORTED
00479     if (scansarg != NULL)   /* process -scans if it was present */
00480       if (! read_scan_script(cinfo, scansarg))
00481     usage();
00482 #endif
00483   }
00484 
00485   return argn;          /* return index of next arg (file name) */
00486 }
00487 
00488 
00489 /*
00490  * The main program.
00491  */
00492 
00493 int
00494 main (int argc, char **argv)
00495 {
00496   struct jpeg_compress_struct cinfo;
00497   struct jpeg_error_mgr jerr;
00498 #ifdef PROGRESS_REPORT
00499   struct cdjpeg_progress_mgr progress;
00500 #endif
00501   int file_index;
00502   cjpeg_source_ptr src_mgr;
00503   FILE * input_file;
00504   FILE * output_file;
00505   JDIMENSION num_scanlines;
00506 
00507   /* On Mac, fetch a command line. */
00508 #ifdef USE_CCOMMAND
00509   argc = ccommand(&argv);
00510 #endif
00511 
00512   progname = argv[0];
00513   if (progname == NULL || progname[0] == 0)
00514     progname = "cjpeg";     /* in case C library doesn't provide it */
00515 
00516   /* Initialize the JPEG compression object with default error handling. */
00517   cinfo.err = jpeg_std_error(&jerr);
00518   jpeg_create_compress(&cinfo);
00519   /* Add some application-specific error messages (from cderror.h) */
00520   jerr.addon_message_table = cdjpeg_message_table;
00521   jerr.first_addon_message = JMSG_FIRSTADDONCODE;
00522   jerr.last_addon_message = JMSG_LASTADDONCODE;
00523 
00524   /* Now safe to enable signal catcher. */
00525 #ifdef NEED_SIGNAL_CATCHER
00526   enable_signal_catcher((j_common_ptr) &cinfo);
00527 #endif
00528 
00529   /* Initialize JPEG parameters.
00530    * Much of this may be overridden later.
00531    * In particular, we don't yet know the input file's color space,
00532    * but we need to provide some value for jpeg_set_defaults() to work.
00533    */
00534 
00535   cinfo.in_color_space = JCS_RGB; /* arbitrary guess */
00536   jpeg_set_defaults(&cinfo);
00537 
00538   /* Scan command line to find file names.
00539    * It is convenient to use just one switch-parsing routine, but the switch
00540    * values read here are ignored; we will rescan the switches after opening
00541    * the input file.
00542    */
00543 
00544   file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
00545 
00546 #ifdef TWO_FILE_COMMANDLINE
00547   /* Must have either -outfile switch or explicit output file name */
00548   if (outfilename == NULL) {
00549     if (file_index != argc-2) {
00550       fprintf(stderr, "%s: must name one input and one output file\n",
00551           progname);
00552       usage();
00553     }
00554     outfilename = argv[file_index+1];
00555   } else {
00556     if (file_index != argc-1) {
00557       fprintf(stderr, "%s: must name one input and one output file\n",
00558           progname);
00559       usage();
00560     }
00561   }
00562 #else
00563   /* Unix style: expect zero or one file name */
00564   if (file_index < argc-1) {
00565     fprintf(stderr, "%s: only one input file\n", progname);
00566     usage();
00567   }
00568 #endif /* TWO_FILE_COMMANDLINE */
00569 
00570   /* Open the input file. */
00571   if (file_index < argc) {
00572     if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
00573       fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
00574       exit(EXIT_FAILURE);
00575     }
00576   } else {
00577     /* default input file is stdin */
00578     input_file = read_stdin();
00579   }
00580 
00581   /* Open the output file. */
00582   if (outfilename != NULL) {
00583     if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
00584       fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
00585       exit(EXIT_FAILURE);
00586     }
00587   } else {
00588     /* default output file is stdout */
00589     output_file = write_stdout();
00590   }
00591 
00592 #ifdef PROGRESS_REPORT
00593   start_progress_monitor((j_common_ptr) &cinfo, &progress);
00594 #endif
00595 
00596   /* Figure out the input file format, and set up to read it. */
00597   src_mgr = select_file_type(&cinfo, input_file);
00598   src_mgr->input_file = input_file;
00599 
00600   /* Read the input file header to obtain file size & colorspace. */
00601   (*src_mgr->start_input) (&cinfo, src_mgr);
00602 
00603   /* Now that we know input colorspace, fix colorspace-dependent defaults */
00604   jpeg_default_colorspace(&cinfo);
00605 
00606   /* Adjust default compression parameters by re-parsing the options */
00607   file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
00608 
00609   /* Specify data destination for compression */
00610   jpeg_stdio_dest(&cinfo, output_file);
00611 
00612   /* Start compressor */
00613   jpeg_start_compress(&cinfo, TRUE);
00614 
00615   /* Process data */
00616   while (cinfo.next_scanline < cinfo.image_height) {
00617     num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);
00618     (void) jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines);
00619   }
00620 
00621   /* Finish compression and release memory */
00622   (*src_mgr->finish_input) (&cinfo, src_mgr);
00623   jpeg_finish_compress(&cinfo);
00624   jpeg_destroy_compress(&cinfo);
00625 
00626   /* Close files, if we opened them */
00627   if (input_file != stdin)
00628     fclose(input_file);
00629   if (output_file != stdout)
00630     fclose(output_file);
00631 
00632 #ifdef PROGRESS_REPORT
00633   end_progress_monitor((j_common_ptr) &cinfo);
00634 #endif
00635 
00636   /* All done. */
00637   exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
00638   return 0;         /* suppress no-return-value warnings */
00639 }

Generated on Thu May 24 2012 04:19:30 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.