use log2 from stdc
[AROS.git] / workbench / libs / jpeg / usage.txt
blob88158d633d6797862a8c1b01204f6c47b7e6fefd
1 USAGE instructions for the Independent JPEG Group's JPEG software
2 =================================================================
4 This file describes usage of the JPEG conversion programs cjpeg and djpeg,
5 as well as the utility programs jpegtran, rdjpgcom and wrjpgcom.  (See
6 the other documentation files if you wish to use the JPEG library within
7 your own programs.)
9 If you are on a Unix machine you may prefer to read the Unix-style manual
10 pages in files cjpeg.1, djpeg.1, jpegtran.1, rdjpgcom.1, wrjpgcom.1.
13 INTRODUCTION
15 These programs implement JPEG image encoding, decoding, and transcoding.
16 JPEG (pronounced "jay-peg") is a standardized compression method for
17 full-color and gray-scale images.
20 GENERAL USAGE
22 We provide two programs, cjpeg to compress an image file into JPEG format,
23 and djpeg to decompress a JPEG file back into a conventional image format.
25 On Unix-like systems, you say:
26         cjpeg [switches] [imagefile] >jpegfile
28         djpeg [switches] [jpegfile]  >imagefile
29 The programs read the specified input file, or standard input if none is
30 named.  They always write to standard output (with trace/error messages to
31 standard error).  These conventions are handy for piping images between
32 programs.
34 On most non-Unix systems, you say:
35         cjpeg [switches] imagefile jpegfile
37         djpeg [switches] jpegfile  imagefile
38 i.e., both the input and output files are named on the command line.  This
39 style is a little more foolproof, and it loses no functionality if you don't
40 have pipes.  (You can get this style on Unix too, if you prefer, by defining
41 TWO_FILE_COMMANDLINE when you compile the programs; see install.txt.)
43 You can also say:
44         cjpeg [switches] -outfile jpegfile  imagefile
46         djpeg [switches] -outfile imagefile  jpegfile
47 This syntax works on all systems, so it is useful for scripts.
49 The currently supported image file formats are: PPM (PBMPLUS color format),
50 PGM (PBMPLUS gray-scale format), BMP, Targa, and RLE (Utah Raster Toolkit
51 format).  (RLE is supported only if the URT library is available.)
52 cjpeg recognizes the input image format automatically, with the exception
53 of some Targa-format files.  You have to tell djpeg which format to generate.
55 JPEG files are in the defacto standard JFIF file format.  There are other,
56 less widely used JPEG-based file formats, but we don't support them.
58 All switch names may be abbreviated; for example, -grayscale may be written
59 -gray or -gr.  Most of the "basic" switches can be abbreviated to as little as
60 one letter.  Upper and lower case are equivalent (-BMP is the same as -bmp).
61 British spellings are also accepted (e.g., -greyscale), though for brevity
62 these are not mentioned below.
65 CJPEG DETAILS
67 The basic command line switches for cjpeg are:
69         -quality N[,...]  Scale quantization tables to adjust image quality.
70                         Quality is 0 (worst) to 100 (best); default is 75.
71                         (See below for more info.)
73         -grayscale      Create monochrome JPEG file from color input.
74                         Be sure to use this switch when compressing a grayscale
75                         BMP file, because cjpeg isn't bright enough to notice
76                         whether a BMP file uses only shades of gray.  By
77                         saying -grayscale, you'll get a smaller JPEG file that
78                         takes less time to process.
80         -rgb            Create RGB JPEG file.
81                         Using this switch suppresses the conversion from RGB
82                         colorspace input to the default YCbCr JPEG colorspace.
83                         You can use this switch in combination with the
84                         -block N switch (see below) for lossless JPEG coding.
85                         See also the -rgb1 switch below.
87         -optimize       Perform optimization of entropy encoding parameters.
88                         Without this, default encoding parameters are used.
89                         -optimize usually makes the JPEG file a little smaller,
90                         but cjpeg runs somewhat slower and needs much more
91                         memory.  Image quality and speed of decompression are
92                         unaffected by -optimize.
94         -progressive    Create progressive JPEG file (see below).
96         -scale M/N      Scale the output image by a factor M/N.  Currently
97                         supported scale factors are M/N with all N from 1 to
98                         16, where M is the destination DCT size, which is 8 by
99                         default (see -block N switch below).
101         -targa          Input file is Targa format.  Targa files that contain
102                         an "identification" field will not be automatically
103                         recognized by cjpeg; for such files you must specify
104                         -targa to make cjpeg treat the input as Targa format.
105                         For most Targa files, you won't need this switch.
107 The -quality switch lets you trade off compressed file size against quality of
108 the reconstructed image: the higher the quality setting, the larger the JPEG
109 file, and the closer the output image will be to the original input.  Normally
110 you want to use the lowest quality setting (smallest file) that decompresses
111 into something visually indistinguishable from the original image.  For this
112 purpose the quality setting should be between 50 and 95; the default of 75 is
113 often about right.  If you see defects at -quality 75, then go up 5 or 10
114 counts at a time until you are happy with the output image.  (The optimal
115 setting will vary from one image to another.)
117 -quality 100 will generate a quantization table of all 1's, minimizing loss
118 in the quantization step (but there is still information loss in subsampling,
119 as well as roundoff error).  This setting is mainly of interest for
120 experimental purposes.  Quality values above about 95 are NOT recommended for
121 normal use; the compressed file size goes up dramatically for hardly any gain
122 in output image quality.
124 In the other direction, quality values below 50 will produce very small files
125 of low image quality.  Settings around 5 to 10 might be useful in preparing an
126 index of a large image library, for example.  Try -quality 2 (or so) for some
127 amusing Cubist effects.  (Note: quality values below about 25 generate 2-byte
128 quantization tables, which are considered optional in the JPEG standard.
129 cjpeg emits a warning message when you give such a quality value, because some
130 other JPEG programs may be unable to decode the resulting file.  Use -baseline
131 if you need to ensure compatibility at low quality values.)
133 The -quality option has been extended in IJG version 7 for support of separate
134 quality settings for luminance and chrominance (or in general, for every
135 provided quantization table slot).  This feature is useful for high-quality
136 applications which cannot accept the damage of color data by coarse
137 subsampling settings.  You can now easily reduce the color data amount more
138 smoothly with finer control without separate subsampling.  The resulting file
139 is fully compliant with standard JPEG decoders.
140 Note that the -quality ratings refer to the quantization table slots, and that
141 the last value is replicated if there are more q-table slots than parameters.
142 The default q-table slots are 0 for luminance and 1 for chrominance with
143 default tables as given in the JPEG standard.  This is compatible with the old
144 behaviour in case that only one parameter is given, which is then used for
145 both luminance and chrominance (slots 0 and 1).  More or custom quantization
146 tables can be set with -qtables and assigned to components with -qslots
147 parameter (see the "wizard" switches below).
148 CAUTION: You must explicitly add -sample 1x1 for efficient separate color
149 quality selection, since the default value used by library is 2x2!
151 The -progressive switch creates a "progressive JPEG" file.  In this type of
152 JPEG file, the data is stored in multiple scans of increasing quality.  If the
153 file is being transmitted over a slow communications link, the decoder can use
154 the first scan to display a low-quality image very quickly, and can then
155 improve the display with each subsequent scan.  The final image is exactly
156 equivalent to a standard JPEG file of the same quality setting, and the total
157 file size is about the same --- often a little smaller.
159 Switches for advanced users:
161         -arithmetic     Use arithmetic coding.  CAUTION: arithmetic coded JPEG
162                         is not yet widely implemented, so many decoders will
163                         be unable to view an arithmetic coded JPEG file at
164                         all.
166         -block N        Set DCT block size.  All N from 1 to 16 are possible.
167                         Default is 8 (baseline format).
168                         Larger values produce higher compression,
169                         smaller values produce higher quality
170                         (exact DCT stage possible with 1 or 2; with the
171                         default quality of 75 and default Luminance qtable
172                         the DCT+Quantization stage is lossless for N=1).
173                         CAUTION: An implementation of the JPEG SmartScale
174                         extension is required for this feature.  SmartScale
175                         enabled JPEG is not yet widely implemented, so many
176                         decoders will be unable to view a SmartScale extended
177                         JPEG file at all.
179         -rgb1           Create RGB JPEG file with reversible color transform.
180                         Works like the -rgb switch (see above) and inserts a
181                         simple reversible color transform into the processing
182                         which significantly improves the compression.
183                         Use this switch in combination with the -block N
184                         switch (see above) for lossless JPEG coding.
185                         CAUTION: A decoder with inverse color transform
186                         support is required for this feature.  Reversible
187                         color transform support is not yet widely implemented,
188                         so many decoders will be unable to view a reversible
189                         color transformed JPEG file at all.
191         -dct int        Use integer DCT method (default).
192         -dct fast       Use fast integer DCT (less accurate).
193         -dct float      Use floating-point DCT method.
194                         The float method is very slightly more accurate than
195                         the int method, but is much slower unless your machine
196                         has very fast floating-point hardware.  Also note that
197                         results of the floating-point method may vary slightly
198                         across machines, while the integer methods should give
199                         the same results everywhere.  The fast integer method
200                         is much less accurate than the other two.
202         -nosmooth       Don't use high-quality downsampling.
204         -restart N      Emit a JPEG restart marker every N MCU rows, or every
205                         N MCU blocks if "B" is attached to the number.
206                         -restart 0 (the default) means no restart markers.
208         -smooth N       Smooth the input image to eliminate dithering noise.
209                         N, ranging from 1 to 100, indicates the strength of
210                         smoothing.  0 (the default) means no smoothing.
212         -maxmemory N    Set limit for amount of memory to use in processing
213                         large images.  Value is in thousands of bytes, or
214                         millions of bytes if "M" is attached to the number.
215                         For example, -max 4m selects 4000000 bytes.  If more
216                         space is needed, temporary files will be used.
218         -verbose        Enable debug printout.  More -v's give more printout.
219         or  -debug      Also, version information is printed at startup.
221 The -restart option inserts extra markers that allow a JPEG decoder to
222 resynchronize after a transmission error.  Without restart markers, any damage
223 to a compressed file will usually ruin the image from the point of the error
224 to the end of the image; with restart markers, the damage is usually confined
225 to the portion of the image up to the next restart marker.  Of course, the
226 restart markers occupy extra space.  We recommend -restart 1 for images that
227 will be transmitted across unreliable networks such as Usenet.
229 The -smooth option filters the input to eliminate fine-scale noise.  This is
230 often useful when converting dithered images to JPEG: a moderate smoothing
231 factor of 10 to 50 gets rid of dithering patterns in the input file, resulting
232 in a smaller JPEG file and a better-looking image.  Too large a smoothing
233 factor will visibly blur the image, however.
235 Switches for wizards:
237         -baseline       Force baseline-compatible quantization tables to be
238                         generated.  This clamps quantization values to 8 bits
239                         even at low quality settings.  (This switch is poorly
240                         named, since it does not ensure that the output is
241                         actually baseline JPEG.  For example, you can use
242                         -baseline and -progressive together.)
244         -qtables file   Use the quantization tables given in the specified
245                         text file.
247         -qslots N[,...] Select which quantization table to use for each color
248                         component.
250         -sample HxV[,...]  Set JPEG sampling factors for each color component.
252         -scans file     Use the scan script given in the specified text file.
254 The "wizard" switches are intended for experimentation with JPEG.  If you
255 don't know what you are doing, DON'T USE THEM.  These switches are documented
256 further in the file wizard.txt.
259 DJPEG DETAILS
261 The basic command line switches for djpeg are:
263         -colors N       Reduce image to at most N colors.  This reduces the
264         or -quantize N  number of colors used in the output image, so that it
265                         can be displayed on a colormapped display or stored in
266                         a colormapped file format.  For example, if you have
267                         an 8-bit display, you'd need to reduce to 256 or fewer
268                         colors.  (-colors is the recommended name, -quantize
269                         is provided only for backwards compatibility.)
271         -fast           Select recommended processing options for fast, low
272                         quality output.  (The default options are chosen for
273                         highest quality output.)  Currently, this is equivalent
274                         to "-dct fast -nosmooth -onepass -dither ordered".
276         -grayscale      Force gray-scale output even if JPEG file is color.
277                         Useful for viewing on monochrome displays; also,
278                         djpeg runs noticeably faster in this mode.
280         -scale M/N      Scale the output image by a factor M/N.  Currently
281                         supported scale factors are M/N with all M from 1 to
282                         16, where N is the source DCT size, which is 8 for
283                         baseline JPEG.  If the /N part is omitted, then M
284                         specifies the DCT scaled size to be applied on the
285                         given input.  For baseline JPEG this is equivalent to
286                         M/8 scaling, since the source DCT size for baseline
287                         JPEG is 8.  Scaling is handy if the image is larger
288                         than your screen; also, djpeg runs much faster when
289                         scaling down the output.
291         -bmp            Select BMP output format (Windows flavor).  8-bit
292                         colormapped format is emitted if -colors or -grayscale
293                         is specified, or if the JPEG file is gray-scale;
294                         otherwise, 24-bit full-color format is emitted.
296         -gif            Select GIF output format.  Since GIF does not support
297                         more than 256 colors, -colors 256 is assumed (unless
298                         you specify a smaller number of colors).  If you
299                         specify -fast, the default number of colors is 216.
301         -os2            Select BMP output format (OS/2 1.x flavor).  8-bit
302                         colormapped format is emitted if -colors or -grayscale
303                         is specified, or if the JPEG file is gray-scale;
304                         otherwise, 24-bit full-color format is emitted.
306         -pnm            Select PBMPLUS (PPM/PGM) output format (this is the
307                         default format).  PGM is emitted if the JPEG file is
308                         gray-scale or if -grayscale is specified; otherwise
309                         PPM is emitted.
311         -rle            Select RLE output format.  (Requires URT library.)
313         -targa          Select Targa output format.  Gray-scale format is
314                         emitted if the JPEG file is gray-scale or if
315                         -grayscale is specified; otherwise, colormapped format
316                         is emitted if -colors is specified; otherwise, 24-bit
317                         full-color format is emitted.
319 Switches for advanced users:
321         -dct int        Use integer DCT method (default).
322         -dct fast       Use fast integer DCT (less accurate).
323         -dct float      Use floating-point DCT method.
324                         The float method is very slightly more accurate than
325                         the int method, but is much slower unless your machine
326                         has very fast floating-point hardware.  Also note that
327                         results of the floating-point method may vary slightly
328                         across machines, while the integer methods should give
329                         the same results everywhere.  The fast integer method
330                         is much less accurate than the other two.
332         -dither fs      Use Floyd-Steinberg dithering in color quantization.
333         -dither ordered Use ordered dithering in color quantization.
334         -dither none    Do not use dithering in color quantization.
335                         By default, Floyd-Steinberg dithering is applied when
336                         quantizing colors; this is slow but usually produces
337                         the best results.  Ordered dither is a compromise
338                         between speed and quality; no dithering is fast but
339                         usually looks awful.  Note that these switches have
340                         no effect unless color quantization is being done.
341                         Ordered dither is only available in -onepass mode.
343         -map FILE       Quantize to the colors used in the specified image
344                         file.  This is useful for producing multiple files
345                         with identical color maps, or for forcing a predefined
346                         set of colors to be used.  The FILE must be a GIF
347                         or PPM file.  This option overrides -colors and
348                         -onepass.
350         -nosmooth       Don't use high-quality upsampling.
352         -onepass        Use one-pass instead of two-pass color quantization.
353                         The one-pass method is faster and needs less memory,
354                         but it produces a lower-quality image.  -onepass is
355                         ignored unless you also say -colors N.  Also,
356                         the one-pass method is always used for gray-scale
357                         output (the two-pass method is no improvement then).
359         -maxmemory N    Set limit for amount of memory to use in processing
360                         large images.  Value is in thousands of bytes, or
361                         millions of bytes if "M" is attached to the number.
362                         For example, -max 4m selects 4000000 bytes.  If more
363                         space is needed, temporary files will be used.
365         -verbose        Enable debug printout.  More -v's give more printout.
366         or  -debug      Also, version information is printed at startup.
369 HINTS FOR CJPEG
371 Color GIF files are not the ideal input for JPEG; JPEG is really intended for
372 compressing full-color (24-bit) images.  In particular, don't try to convert
373 cartoons, line drawings, and other images that have only a few distinct
374 colors.  GIF works great on these, JPEG does not.  If you want to convert a
375 GIF to JPEG, you should experiment with cjpeg's -quality and -smooth options
376 to get a satisfactory conversion.  -smooth 10 or so is often helpful.
378 Avoid running an image through a series of JPEG compression/decompression
379 cycles.  Image quality loss will accumulate; after ten or so cycles the image
380 may be noticeably worse than it was after one cycle.  It's best to use a
381 lossless format while manipulating an image, then convert to JPEG format when
382 you are ready to file the image away.
384 The -optimize option to cjpeg is worth using when you are making a "final"
385 version for posting or archiving.  It's also a win when you are using low
386 quality settings to make very small JPEG files; the percentage improvement
387 is often a lot more than it is on larger files.  (At present, -optimize
388 mode is always selected when generating progressive JPEG files.)
390 GIF input files are no longer supported, to avoid the Unisys LZW patent.
391 (Conversion of GIF files to JPEG is usually a bad idea anyway.)
394 HINTS FOR DJPEG
396 To get a quick preview of an image, use the -grayscale and/or -scale switches.
397 "-grayscale -scale 1/8" is the fastest case.
399 Several options are available that trade off image quality to gain speed.
400 "-fast" turns on the recommended settings.
402 "-dct fast" and/or "-nosmooth" gain speed at a small sacrifice in quality.
403 When producing a color-quantized image, "-onepass -dither ordered" is fast but
404 much lower quality than the default behavior.  "-dither none" may give
405 acceptable results in two-pass mode, but is seldom tolerable in one-pass mode.
407 If you are fortunate enough to have very fast floating point hardware,
408 "-dct float" may be even faster than "-dct fast".  But on most machines
409 "-dct float" is slower than "-dct int"; in this case it is not worth using,
410 because its theoretical accuracy advantage is too small to be significant
411 in practice.
413 Two-pass color quantization requires a good deal of memory; on MS-DOS machines
414 it may run out of memory even with -maxmemory 0.  In that case you can still
415 decompress, with some loss of image quality, by specifying -onepass for
416 one-pass quantization.
418 To avoid the Unisys LZW patent, djpeg produces uncompressed GIF files.  These
419 are larger than they should be, but are readable by standard GIF decoders.
422 HINTS FOR BOTH PROGRAMS
424 If more space is needed than will fit in the available main memory (as
425 determined by -maxmemory), temporary files will be used.  (MS-DOS versions
426 will try to get extended or expanded memory first.)  The temporary files are
427 often rather large: in typical cases they occupy three bytes per pixel, for
428 example 3*800*600 = 1.44Mb for an 800x600 image.  If you don't have enough
429 free disk space, leave out -progressive and -optimize (for cjpeg) or specify
430 -onepass (for djpeg).
432 On MS-DOS, the temporary files are created in the directory named by the TMP
433 or TEMP environment variable, or in the current directory if neither of those
434 exist.  Amiga implementations put the temp files in the directory named by
435 JPEGTMP:, so be sure to assign JPEGTMP: to a disk partition with adequate free
436 space.
438 The default memory usage limit (-maxmemory) is set when the software is
439 compiled.  If you get an "insufficient memory" error, try specifying a smaller
440 -maxmemory value, even -maxmemory 0 to use the absolute minimum space.  You
441 may want to recompile with a smaller default value if this happens often.
443 On machines that have "environment" variables, you can define the environment
444 variable JPEGMEM to set the default memory limit.  The value is specified as
445 described for the -maxmemory switch.  JPEGMEM overrides the default value
446 specified when the program was compiled, and itself is overridden by an
447 explicit -maxmemory switch.
449 On MS-DOS machines, -maxmemory is the amount of main (conventional) memory to
450 use.  (Extended or expanded memory is also used if available.)  Most
451 DOS-specific versions of this software do their own memory space estimation
452 and do not need you to specify -maxmemory.
455 JPEGTRAN
457 jpegtran performs various useful transformations of JPEG files.
458 It can translate the coded representation from one variant of JPEG to another,
459 for example from baseline JPEG to progressive JPEG or vice versa.  It can also
460 perform some rearrangements of the image data, for example turning an image
461 from landscape to portrait format by rotation.
463 jpegtran works by rearranging the compressed data (DCT coefficients), without
464 ever fully decoding the image.  Therefore, its transformations are lossless:
465 there is no image degradation at all, which would not be true if you used
466 djpeg followed by cjpeg to accomplish the same conversion.  But by the same
467 token, jpegtran cannot perform lossy operations such as changing the image
468 quality.
470 jpegtran uses a command line syntax similar to cjpeg or djpeg.
471 On Unix-like systems, you say:
472         jpegtran [switches] [inputfile] >outputfile
473 On most non-Unix systems, you say:
474         jpegtran [switches] inputfile outputfile
475 where both the input and output files are JPEG files.
477 To specify the coded JPEG representation used in the output file,
478 jpegtran accepts a subset of the switches recognized by cjpeg:
479         -optimize       Perform optimization of entropy encoding parameters.
480         -progressive    Create progressive JPEG file.
481         -arithmetic     Use arithmetic coding.
482         -restart N      Emit a JPEG restart marker every N MCU rows, or every
483                         N MCU blocks if "B" is attached to the number.
484         -scans file     Use the scan script given in the specified text file.
485 See the previous discussion of cjpeg for more details about these switches.
486 If you specify none of these switches, you get a plain baseline-JPEG output
487 file.  The quality setting and so forth are determined by the input file.
489 The image can be losslessly transformed by giving one of these switches:
490         -flip horizontal        Mirror image horizontally (left-right).
491         -flip vertical          Mirror image vertically (top-bottom).
492         -rotate 90              Rotate image 90 degrees clockwise.
493         -rotate 180             Rotate image 180 degrees.
494         -rotate 270             Rotate image 270 degrees clockwise (or 90 ccw).
495         -transpose              Transpose image (across UL-to-LR axis).
496         -transverse             Transverse transpose (across UR-to-LL axis).
498 The transpose transformation has no restrictions regarding image dimensions.
499 The other transformations operate rather oddly if the image dimensions are not
500 a multiple of the iMCU size (usually 8 or 16 pixels), because they can only
501 transform complete blocks of DCT coefficient data in the desired way.
503 jpegtran's default behavior when transforming an odd-size image is designed
504 to preserve exact reversibility and mathematical consistency of the
505 transformation set.  As stated, transpose is able to flip the entire image
506 area.  Horizontal mirroring leaves any partial iMCU column at the right edge
507 untouched, but is able to flip all rows of the image.  Similarly, vertical
508 mirroring leaves any partial iMCU row at the bottom edge untouched, but is
509 able to flip all columns.  The other transforms can be built up as sequences
510 of transpose and flip operations; for consistency, their actions on edge
511 pixels are defined to be the same as the end result of the corresponding
512 transpose-and-flip sequence.
514 For practical use, you may prefer to discard any untransformable edge pixels
515 rather than having a strange-looking strip along the right and/or bottom edges
516 of a transformed image.  To do this, add the -trim switch:
517         -trim           Drop non-transformable edge blocks.
518 Obviously, a transformation with -trim is not reversible, so strictly speaking
519 jpegtran with this switch is not lossless.  Also, the expected mathematical
520 equivalences between the transformations no longer hold.  For example,
521 "-rot 270 -trim" trims only the bottom edge, but "-rot 90 -trim" followed by
522 "-rot 180 -trim" trims both edges.
524 If you are only interested in perfect transformation, add the -perfect switch:
525         -perfect        Fails with an error if the transformation is not
526                         perfect.
527 For example you may want to do
528   jpegtran -rot 90 -perfect foo.jpg || djpeg foo.jpg | pnmflip -r90 | cjpeg
529 to do a perfect rotation if available or an approximated one if not.
531 We also offer a lossless-crop option, which discards data outside a given
532 image region but losslessly preserves what is inside.  Like the rotate and
533 flip transforms, lossless crop is restricted by the current JPEG format: the
534 upper left corner of the selected region must fall on an iMCU boundary.  If
535 this does not hold for the given crop parameters, we silently move the upper
536 left corner up and/or left to make it so, simultaneously increasing the region
537 dimensions to keep the lower right crop corner unchanged.  (Thus, the output
538 image covers at least the requested region, but may cover more.)
540 The image can be losslessly cropped by giving the switch:
541         -crop WxH+X+Y   Crop to a rectangular subarea of width W, height H
542                         starting at point X,Y.
544 Other not-strictly-lossless transformation switches are:
546         -grayscale      Force grayscale output.
547 This option discards the chrominance channels if the input image is YCbCr
548 (ie, a standard color JPEG), resulting in a grayscale JPEG file.  The
549 luminance channel is preserved exactly, so this is a better method of reducing
550 to grayscale than decompression, conversion, and recompression.  This switch
551 is particularly handy for fixing a monochrome picture that was mistakenly
552 encoded as a color JPEG.  (In such a case, the space savings from getting rid
553 of the near-empty chroma channels won't be large; but the decoding time for
554 a grayscale JPEG is substantially less than that for a color JPEG.)
556         -scale M/N      Scale the output image by a factor M/N.
557 Currently supported scale factors are M/N with all M from 1 to 16, where N is
558 the source DCT size, which is 8 for baseline JPEG.  If the /N part is omitted,
559 then M specifies the DCT scaled size to be applied on the given input.  For
560 baseline JPEG this is equivalent to M/8 scaling, since the source DCT size
561 for baseline JPEG is 8.  CAUTION: An implementation of the JPEG SmartScale
562 extension is required for this feature.  SmartScale enabled JPEG is not yet
563 widely implemented, so many decoders will be unable to view a SmartScale
564 extended JPEG file at all.
566 jpegtran also recognizes these switches that control what to do with "extra"
567 markers, such as comment blocks:
568         -copy none      Copy no extra markers from source file.  This setting
569                         suppresses all comments and other excess baggage
570                         present in the source file.
571         -copy comments  Copy only comment markers.  This setting copies
572                         comments from the source file, but discards
573                         any other inessential (for image display) data.
574         -copy all       Copy all extra markers.  This setting preserves
575                         miscellaneous markers found in the source file, such
576                         as JFIF thumbnails, Exif data, and Photoshop settings.
577                         In some files these extra markers can be sizable.
578 The default behavior is -copy comments.  (Note: in IJG releases v6 and v6a,
579 jpegtran always did the equivalent of -copy none.)
581 Additional switches recognized by jpegtran are:
582         -outfile filename
583         -maxmemory N
584         -verbose
585         -debug
586 These work the same as in cjpeg or djpeg.
589 THE COMMENT UTILITIES
591 The JPEG standard allows "comment" (COM) blocks to occur within a JPEG file.
592 Although the standard doesn't actually define what COM blocks are for, they
593 are widely used to hold user-supplied text strings.  This lets you add
594 annotations, titles, index terms, etc to your JPEG files, and later retrieve
595 them as text.  COM blocks do not interfere with the image stored in the JPEG
596 file.  The maximum size of a COM block is 64K, but you can have as many of
597 them as you like in one JPEG file.
599 We provide two utility programs to display COM block contents and add COM
600 blocks to a JPEG file.
602 rdjpgcom searches a JPEG file and prints the contents of any COM blocks on
603 standard output.  The command line syntax is
604         rdjpgcom [-raw] [-verbose] [inputfilename]
605 The switch "-raw" (or just "-r") causes rdjpgcom to also output non-printable
606 characters in comments, which are normally escaped for security reasons.
607 The switch "-verbose" (or just "-v") causes rdjpgcom to also display the JPEG
608 image dimensions.  If you omit the input file name from the command line,
609 the JPEG file is read from standard input.  (This may not work on some
610 operating systems, if binary data can't be read from stdin.)
612 wrjpgcom adds a COM block, containing text you provide, to a JPEG file.
613 Ordinarily, the COM block is added after any existing COM blocks, but you
614 can delete the old COM blocks if you wish.  wrjpgcom produces a new JPEG
615 file; it does not modify the input file.  DO NOT try to overwrite the input
616 file by directing wrjpgcom's output back into it; on most systems this will
617 just destroy your file.
619 The command line syntax for wrjpgcom is similar to cjpeg's.  On Unix-like
620 systems, it is
621         wrjpgcom [switches] [inputfilename]
622 The output file is written to standard output.  The input file comes from
623 the named file, or from standard input if no input file is named.
625 On most non-Unix systems, the syntax is
626         wrjpgcom [switches] inputfilename outputfilename
627 where both input and output file names must be given explicitly.
629 wrjpgcom understands three switches:
630         -replace                 Delete any existing COM blocks from the file.
631         -comment "Comment text"  Supply new COM text on command line.
632         -cfile name              Read text for new COM block from named file.
633 (Switch names can be abbreviated.)  If you have only one line of comment text
634 to add, you can provide it on the command line with -comment.  The comment
635 text must be surrounded with quotes so that it is treated as a single
636 argument.  Longer comments can be read from a text file.
638 If you give neither -comment nor -cfile, then wrjpgcom will read the comment
639 text from standard input.  (In this case an input image file name MUST be
640 supplied, so that the source JPEG file comes from somewhere else.)  You can
641 enter multiple lines, up to 64KB worth.  Type an end-of-file indicator
642 (usually control-D or control-Z) to terminate the comment text entry.
644 wrjpgcom will not add a COM block if the provided comment string is empty.
645 Therefore -replace -comment "" can be used to delete all COM blocks from a
646 file.
648 These utility programs do not depend on the IJG JPEG library.  In
649 particular, the source code for rdjpgcom is intended as an illustration of
650 the minimum amount of code required to parse a JPEG file header correctly.