summaryrefslogtreecommitdiff
path: root/cjpeg.c
diff options
context:
space:
mode:
Diffstat (limited to 'cjpeg.c')
-rw-r--r--cjpeg.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/cjpeg.c b/cjpeg.c
index f2a929f..b55ad6f 100644
--- a/cjpeg.c
+++ b/cjpeg.c
@@ -149,7 +149,7 @@ usage (void)
#endif
fprintf(stderr, "Switches (names may be abbreviated):\n");
- fprintf(stderr, " -quality N Compression quality (0..100; 5-95 is useful range)\n");
+ fprintf(stderr, " -quality N[,...] Compression quality (0..100; 5-95 is useful range)\n");
fprintf(stderr, " -grayscale Create monochrome JPEG file\n");
#ifdef ENTROPY_OPT_SUPPORTED
fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n");
@@ -157,6 +157,9 @@ usage (void)
#ifdef C_PROGRESSIVE_SUPPORTED
fprintf(stderr, " -progressive Create progressive JPEG file\n");
#endif
+#ifdef DCT_SCALING_SUPPORTED
+ fprintf(stderr, " -scale M/N Scale image by fraction M/N, eg, 1/2\n");
+#endif
#ifdef TARGA_SUPPORTED
fprintf(stderr, " -targa Input file is Targa format (usually not needed)\n");
#endif
@@ -209,21 +212,16 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
{
int argn;
char * arg;
- int quality; /* -quality parameter */
- int q_scale_factor; /* scaling percentage for -qtables */
boolean force_baseline;
boolean simple_progressive;
+ char * qualityarg = NULL; /* saves -quality parm if any */
char * qtablefile = NULL; /* saves -qtables filename if any */
char * qslotsarg = NULL; /* saves -qslots parm if any */
char * samplearg = NULL; /* saves -sample parm if any */
char * scansarg = NULL; /* saves -scans parm if any */
/* Set up default JPEG parameters. */
- /* Note that default -quality level need not, and does not,
- * match the default scaling for an explicit -qtables argument.
- */
- quality = 75; /* default -quality value */
- q_scale_factor = 100; /* default to no scaling for -qtables */
+
force_baseline = FALSE; /* by default, allow 16-bit quantizers */
simple_progressive = FALSE;
is_targa = FALSE;
@@ -328,13 +326,10 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
#endif
} else if (keymatch(arg, "quality", 1)) {
- /* Quality factor (quantization table scaling factor). */
+ /* Quality ratings (quantization table scaling factors). */
if (++argn >= argc) /* advance to next argument */
usage();
- if (sscanf(argv[argn], "%d", &quality) != 1)
- usage();
- /* Change scale factor in case -qtables is present. */
- q_scale_factor = jpeg_quality_scaling(quality);
+ qualityarg = argv[argn];
} else if (keymatch(arg, "qslots", 2)) {
/* Quantization table slot numbers. */
@@ -382,7 +377,15 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
* default sampling factors.
*/
- } else if (keymatch(arg, "scans", 2)) {
+ } else if (keymatch(arg, "scale", 4)) {
+ /* Scale the image by a fraction M/N. */
+ if (++argn >= argc) /* advance to next argument */
+ usage();
+ if (sscanf(argv[argn], "%d/%d",
+ &cinfo->scale_num, &cinfo->scale_denom) != 2)
+ usage();
+
+ } else if (keymatch(arg, "scans", 4)) {
/* Set scan script. */
#ifdef C_MULTISCAN_FILES_SUPPORTED
if (++argn >= argc) /* advance to next argument */
@@ -422,11 +425,12 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
/* Set quantization tables for selected quality. */
/* Some or all may be overridden if -qtables is present. */
- jpeg_set_quality(cinfo, quality, force_baseline);
+ if (qualityarg != NULL) /* process -quality if it was present */
+ if (! set_quality_ratings(cinfo, qualityarg, force_baseline))
+ usage();
if (qtablefile != NULL) /* process -qtables if it was present */
- if (! read_quant_tables(cinfo, qtablefile,
- q_scale_factor, force_baseline))
+ if (! read_quant_tables(cinfo, qtablefile, force_baseline))
usage();
if (qslotsarg != NULL) /* process -qslots if it was present */