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