blob: ef2164afa5c821747cebf89654af5fbaf66597cd [file] [log] [blame]
DRCa73e8702012-12-31 02:52:30 +00001NOTE: This file was modified by The libjpeg-turbo Project to include only
2information relevant to libjpeg-turbo and to clarify certain passages.
3
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +00004USAGE instructions for the Independent JPEG Group's JPEG software
5=================================================================
6
7This file describes usage of the JPEG conversion programs cjpeg and djpeg,
Thomas G. Lanebc79e061995-08-02 00:00:00 +00008as well as the utility programs jpegtran, rdjpgcom and wrjpgcom. (See
9the other documentation files if you wish to use the JPEG library within
10your own programs.)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000011
12If you are on a Unix machine you may prefer to read the Unix-style manual
Thomas G. Lanebc79e061995-08-02 00:00:00 +000013pages in files cjpeg.1, djpeg.1, jpegtran.1, rdjpgcom.1, wrjpgcom.1.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000014
15
16INTRODUCTION
17
Guido Vollbeding5996a252009-06-27 00:00:00 +000018These programs implement JPEG image encoding, decoding, and transcoding.
19JPEG (pronounced "jay-peg") is a standardized compression method for
20full-color and gray-scale images.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000021
22
23GENERAL USAGE
24
25We provide two programs, cjpeg to compress an image file into JPEG format,
26and djpeg to decompress a JPEG file back into a conventional image format.
27
28On Unix-like systems, you say:
29 cjpeg [switches] [imagefile] >jpegfile
30or
31 djpeg [switches] [jpegfile] >imagefile
32The programs read the specified input file, or standard input if none is
33named. They always write to standard output (with trace/error messages to
34standard error). These conventions are handy for piping images between
35programs.
36
37On most non-Unix systems, you say:
38 cjpeg [switches] imagefile jpegfile
39or
40 djpeg [switches] jpegfile imagefile
41i.e., both the input and output files are named on the command line. This
42style is a little more foolproof, and it loses no functionality if you don't
43have pipes. (You can get this style on Unix too, if you prefer, by defining
Guido Vollbeding5996a252009-06-27 00:00:00 +000044TWO_FILE_COMMANDLINE when you compile the programs; see install.txt.)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000045
46You can also say:
47 cjpeg [switches] -outfile jpegfile imagefile
48or
49 djpeg [switches] -outfile imagefile jpegfile
50This syntax works on all systems, so it is useful for scripts.
51
52The currently supported image file formats are: PPM (PBMPLUS color format),
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000053PGM (PBMPLUS gray-scale format), BMP, Targa, and RLE (Utah Raster Toolkit
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000054format). (RLE is supported only if the URT library is available.)
55cjpeg recognizes the input image format automatically, with the exception
56of some Targa-format files. You have to tell djpeg which format to generate.
57
58JPEG files are in the defacto standard JFIF file format. There are other,
59less widely used JPEG-based file formats, but we don't support them.
60
61All switch names may be abbreviated; for example, -grayscale may be written
62-gray or -gr. Most of the "basic" switches can be abbreviated to as little as
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000063one letter. Upper and lower case are equivalent (-BMP is the same as -bmp).
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000064British spellings are also accepted (e.g., -greyscale), though for brevity
65these are not mentioned below.
66
67
68CJPEG DETAILS
69
70The basic command line switches for cjpeg are:
71
Guido Vollbeding5996a252009-06-27 00:00:00 +000072 -quality N[,...] Scale quantization tables to adjust image quality.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000073 Quality is 0 (worst) to 100 (best); default is 75.
74 (See below for more info.)
75
76 -grayscale Create monochrome JPEG file from color input.
77 Be sure to use this switch when compressing a grayscale
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000078 BMP file, because cjpeg isn't bright enough to notice
79 whether a BMP file uses only shades of gray. By
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000080 saying -grayscale, you'll get a smaller JPEG file that
81 takes less time to process.
82
83 -optimize Perform optimization of entropy encoding parameters.
84 Without this, default encoding parameters are used.
85 -optimize usually makes the JPEG file a little smaller,
86 but cjpeg runs somewhat slower and needs much more
87 memory. Image quality and speed of decompression are
88 unaffected by -optimize.
89
Thomas G. Lanebc79e061995-08-02 00:00:00 +000090 -progressive Create progressive JPEG file (see below).
91
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000092 -targa Input file is Targa format. Targa files that contain
93 an "identification" field will not be automatically
94 recognized by cjpeg; for such files you must specify
95 -targa to make cjpeg treat the input as Targa format.
96 For most Targa files, you won't need this switch.
97
98The -quality switch lets you trade off compressed file size against quality of
99the reconstructed image: the higher the quality setting, the larger the JPEG
100file, and the closer the output image will be to the original input. Normally
101you want to use the lowest quality setting (smallest file) that decompresses
102into something visually indistinguishable from the original image. For this
103purpose the quality setting should be between 50 and 95; the default of 75 is
104often about right. If you see defects at -quality 75, then go up 5 or 10
105counts at a time until you are happy with the output image. (The optimal
106setting will vary from one image to another.)
107
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000108-quality 100 will generate a quantization table of all 1's, minimizing loss
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000109in the quantization step (but there is still information loss in subsampling,
110as well as roundoff error). This setting is mainly of interest for
111experimental purposes. Quality values above about 95 are NOT recommended for
112normal use; the compressed file size goes up dramatically for hardly any gain
113in output image quality.
114
115In the other direction, quality values below 50 will produce very small files
116of low image quality. Settings around 5 to 10 might be useful in preparing an
117index of a large image library, for example. Try -quality 2 (or so) for some
118amusing Cubist effects. (Note: quality values below about 25 generate 2-byte
119quantization tables, which are considered optional in the JPEG standard.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000120cjpeg emits a warning message when you give such a quality value, because some
121other JPEG programs may be unable to decode the resulting file. Use -baseline
122if you need to ensure compatibility at low quality values.)
123
DRC39ea5622010-10-12 01:55:31 +0000124The -quality option has been extended in this version of cjpeg to support
125separate quality settings for luminance and chrominance (or, in general,
126separate settings for every quantization table slot.) The principle is the
127same as chrominance subsampling: since the human eye is more sensitive to
128spatial changes in brightness than spatial changes in color, the chrominance
129components can be quantized more than the luminance components without
130incurring any visible image quality loss. However, unlike subsampling, this
131feature reduces data in the frequency domain instead of the spatial domain,
132which allows for more fine-grained control. This option is useful in
133quality-sensitive applications, for which the artifacts generated by
134subsampling may be unacceptable.
135
136The -quality option accepts a comma-separated list of parameters, which
DRCccd1bfd2012-01-31 09:53:46 +0000137respectively refer to the quality levels that should be assigned to the
DRC39ea5622010-10-12 01:55:31 +0000138quantization table slots. If there are more q-table slots than parameters,
139then the last parameter is replicated. Thus, if only one quality parameter is
140given, this is used for both luminance and chrominance (slots 0 and 1,
141respectively), preserving the legacy behavior of cjpeg v6b and prior. More (or
142customized) quantization tables can be set with the -qtables option and
143assigned to components with the -qslots option (see the "wizard" switches
144below.)
145
146JPEG files generated with separate luminance and chrominance quality are
147fully compliant with standard JPEG decoders.
148
149CAUTION: For this setting to be useful, be sure to pass an argument of
150-sample 1x1 to cjpeg to disable chrominance subsampling. Otherwise, the
151default subsampling level (2x2, AKA "4:2:0") will be used.
Guido Vollbeding5996a252009-06-27 00:00:00 +0000152
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000153The -progressive switch creates a "progressive JPEG" file. In this type of
154JPEG file, the data is stored in multiple scans of increasing quality. If the
155file is being transmitted over a slow communications link, the decoder can use
156the first scan to display a low-quality image very quickly, and can then
157improve the display with each subsequent scan. The final image is exactly
158equivalent to a standard JPEG file of the same quality setting, and the total
Guido Vollbeding5996a252009-06-27 00:00:00 +0000159file size is about the same --- often a little smaller.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000160
161Switches for advanced users:
162
Guido Vollbeding5829cb22012-01-15 00:00:00 +0000163 -arithmetic Use arithmetic coding. CAUTION: arithmetic coded JPEG
164 is not yet widely implemented, so many decoders will
165 be unable to view an arithmetic coded JPEG file at
166 all.
167
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000168 -dct int Use integer DCT method (default).
169 -dct fast Use fast integer DCT (less accurate).
170 -dct float Use floating-point DCT method.
Thomas G. Lanea8b67c41995-03-15 00:00:00 +0000171 The float method is very slightly more accurate than
172 the int method, but is much slower unless your machine
173 has very fast floating-point hardware. Also note that
174 results of the floating-point method may vary slightly
175 across machines, while the integer methods should give
176 the same results everywhere. The fast integer method
177 is much less accurate than the other two.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000178
179 -restart N Emit a JPEG restart marker every N MCU rows, or every
180 N MCU blocks if "B" is attached to the number.
181 -restart 0 (the default) means no restart markers.
182
183 -smooth N Smooth the input image to eliminate dithering noise.
184 N, ranging from 1 to 100, indicates the strength of
185 smoothing. 0 (the default) means no smoothing.
186
187 -maxmemory N Set limit for amount of memory to use in processing
188 large images. Value is in thousands of bytes, or
189 millions of bytes if "M" is attached to the number.
190 For example, -max 4m selects 4000000 bytes. If more
191 space is needed, temporary files will be used.
192
193 -verbose Enable debug printout. More -v's give more printout.
194 or -debug Also, version information is printed at startup.
195
196The -restart option inserts extra markers that allow a JPEG decoder to
197resynchronize after a transmission error. Without restart markers, any damage
198to a compressed file will usually ruin the image from the point of the error
199to the end of the image; with restart markers, the damage is usually confined
200to the portion of the image up to the next restart marker. Of course, the
201restart markers occupy extra space. We recommend -restart 1 for images that
202will be transmitted across unreliable networks such as Usenet.
203
204The -smooth option filters the input to eliminate fine-scale noise. This is
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000205often useful when converting dithered images to JPEG: a moderate smoothing
206factor of 10 to 50 gets rid of dithering patterns in the input file, resulting
207in a smaller JPEG file and a better-looking image. Too large a smoothing
208factor will visibly blur the image, however.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000209
210Switches for wizards:
211
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000212 -baseline Force baseline-compatible quantization tables to be
213 generated. This clamps quantization values to 8 bits
214 even at low quality settings. (This switch is poorly
215 named, since it does not ensure that the output is
216 actually baseline JPEG. For example, you can use
217 -baseline and -progressive together.)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000218
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000219 -qtables file Use the quantization tables given in the specified
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000220 text file.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000221
222 -qslots N[,...] Select which quantization table to use for each color
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000223 component.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000224
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000225 -sample HxV[,...] Set JPEG sampling factors for each color component.
226
227 -scans file Use the scan script given in the specified text file.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000228
229The "wizard" switches are intended for experimentation with JPEG. If you
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000230don't know what you are doing, DON'T USE THEM. These switches are documented
Guido Vollbeding5996a252009-06-27 00:00:00 +0000231further in the file wizard.txt.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000232
233
234DJPEG DETAILS
235
236The basic command line switches for djpeg are:
237
238 -colors N Reduce image to at most N colors. This reduces the
239 or -quantize N number of colors used in the output image, so that it
240 can be displayed on a colormapped display or stored in
241 a colormapped file format. For example, if you have
242 an 8-bit display, you'd need to reduce to 256 or fewer
243 colors. (-colors is the recommended name, -quantize
244 is provided only for backwards compatibility.)
245
246 -fast Select recommended processing options for fast, low
247 quality output. (The default options are chosen for
248 highest quality output.) Currently, this is equivalent
249 to "-dct fast -nosmooth -onepass -dither ordered".
250
251 -grayscale Force gray-scale output even if JPEG file is color.
252 Useful for viewing on monochrome displays; also,
253 djpeg runs noticeably faster in this mode.
254
255 -scale M/N Scale the output image by a factor M/N. Currently
256 the scale factor must be 1/1, 1/2, 1/4, or 1/8.
257 Scaling is handy if the image is larger than your
258 screen; also, djpeg runs much faster when scaling
259 down the output.
260
261 -bmp Select BMP output format (Windows flavor). 8-bit
262 colormapped format is emitted if -colors or -grayscale
263 is specified, or if the JPEG file is gray-scale;
264 otherwise, 24-bit full-color format is emitted.
265
266 -gif Select GIF output format. Since GIF does not support
267 more than 256 colors, -colors 256 is assumed (unless
268 you specify a smaller number of colors). If you
269 specify -fast, the default number of colors is 216.
270
271 -os2 Select BMP output format (OS/2 1.x flavor). 8-bit
272 colormapped format is emitted if -colors or -grayscale
273 is specified, or if the JPEG file is gray-scale;
274 otherwise, 24-bit full-color format is emitted.
275
276 -pnm Select PBMPLUS (PPM/PGM) output format (this is the
277 default format). PGM is emitted if the JPEG file is
278 gray-scale or if -grayscale is specified; otherwise
279 PPM is emitted.
280
281 -rle Select RLE output format. (Requires URT library.)
282
283 -targa Select Targa output format. Gray-scale format is
284 emitted if the JPEG file is gray-scale or if
285 -grayscale is specified; otherwise, colormapped format
286 is emitted if -colors is specified; otherwise, 24-bit
287 full-color format is emitted.
288
289Switches for advanced users:
290
291 -dct int Use integer DCT method (default).
292 -dct fast Use fast integer DCT (less accurate).
293 -dct float Use floating-point DCT method.
Thomas G. Lanea8b67c41995-03-15 00:00:00 +0000294 The float method is very slightly more accurate than
295 the int method, but is much slower unless your machine
296 has very fast floating-point hardware. Also note that
297 results of the floating-point method may vary slightly
298 across machines, while the integer methods should give
299 the same results everywhere. The fast integer method
300 is much less accurate than the other two.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000301
302 -dither fs Use Floyd-Steinberg dithering in color quantization.
303 -dither ordered Use ordered dithering in color quantization.
304 -dither none Do not use dithering in color quantization.
305 By default, Floyd-Steinberg dithering is applied when
306 quantizing colors; this is slow but usually produces
307 the best results. Ordered dither is a compromise
308 between speed and quality; no dithering is fast but
309 usually looks awful. Note that these switches have
310 no effect unless color quantization is being done.
311 Ordered dither is only available in -onepass mode.
312
313 -map FILE Quantize to the colors used in the specified image
314 file. This is useful for producing multiple files
315 with identical color maps, or for forcing a predefined
316 set of colors to be used. The FILE must be a GIF
317 or PPM file. This option overrides -colors and
318 -onepass.
319
320 -nosmooth Use a faster, lower-quality upsampling routine.
321
322 -onepass Use one-pass instead of two-pass color quantization.
323 The one-pass method is faster and needs less memory,
324 but it produces a lower-quality image. -onepass is
325 ignored unless you also say -colors N. Also,
326 the one-pass method is always used for gray-scale
327 output (the two-pass method is no improvement then).
328
329 -maxmemory N Set limit for amount of memory to use in processing
330 large images. Value is in thousands of bytes, or
331 millions of bytes if "M" is attached to the number.
332 For example, -max 4m selects 4000000 bytes. If more
333 space is needed, temporary files will be used.
334
335 -verbose Enable debug printout. More -v's give more printout.
336 or -debug Also, version information is printed at startup.
337
338
339HINTS FOR CJPEG
340
341Color GIF files are not the ideal input for JPEG; JPEG is really intended for
342compressing full-color (24-bit) images. In particular, don't try to convert
343cartoons, line drawings, and other images that have only a few distinct
344colors. GIF works great on these, JPEG does not. If you want to convert a
345GIF to JPEG, you should experiment with cjpeg's -quality and -smooth options
346to get a satisfactory conversion. -smooth 10 or so is often helpful.
347
348Avoid running an image through a series of JPEG compression/decompression
349cycles. Image quality loss will accumulate; after ten or so cycles the image
350may be noticeably worse than it was after one cycle. It's best to use a
351lossless format while manipulating an image, then convert to JPEG format when
352you are ready to file the image away.
353
354The -optimize option to cjpeg is worth using when you are making a "final"
355version for posting or archiving. It's also a win when you are using low
356quality settings to make very small JPEG files; the percentage improvement
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000357is often a lot more than it is on larger files. (At present, -optimize
358mode is always selected when generating progressive JPEG files.)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000359
DRC39ea5622010-10-12 01:55:31 +0000360Support for GIF input files was removed in cjpeg v6b due to concerns over
361the Unisys LZW patent. Although this patent expired in 2006, cjpeg still
362lacks GIF support, for these historical reasons. (Conversion of GIF files to
363JPEG is usually a bad idea anyway.)
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000364
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000365
366HINTS FOR DJPEG
367
368To get a quick preview of an image, use the -grayscale and/or -scale switches.
369"-grayscale -scale 1/8" is the fastest case.
370
371Several options are available that trade off image quality to gain speed.
372"-fast" turns on the recommended settings.
373
374"-dct fast" and/or "-nosmooth" gain speed at a small sacrifice in quality.
375When producing a color-quantized image, "-onepass -dither ordered" is fast but
376much lower quality than the default behavior. "-dither none" may give
377acceptable results in two-pass mode, but is seldom tolerable in one-pass mode.
378
379If you are fortunate enough to have very fast floating point hardware,
Thomas G. Lanea8b67c41995-03-15 00:00:00 +0000380"-dct float" may be even faster than "-dct fast". But on most machines
381"-dct float" is slower than "-dct int"; in this case it is not worth using,
382because its theoretical accuracy advantage is too small to be significant
383in practice.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000384
385Two-pass color quantization requires a good deal of memory; on MS-DOS machines
386it may run out of memory even with -maxmemory 0. In that case you can still
387decompress, with some loss of image quality, by specifying -onepass for
388one-pass quantization.
389
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000390To avoid the Unisys LZW patent, djpeg produces uncompressed GIF files. These
391are larger than they should be, but are readable by standard GIF decoders.
392
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000393
394HINTS FOR BOTH PROGRAMS
395
396If more space is needed than will fit in the available main memory (as
397determined by -maxmemory), temporary files will be used. (MS-DOS versions
398will try to get extended or expanded memory first.) The temporary files are
399often rather large: in typical cases they occupy three bytes per pixel, for
400example 3*800*600 = 1.44Mb for an 800x600 image. If you don't have enough
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000401free disk space, leave out -progressive and -optimize (for cjpeg) or specify
402-onepass (for djpeg).
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000403
404On MS-DOS, the temporary files are created in the directory named by the TMP
405or TEMP environment variable, or in the current directory if neither of those
406exist. Amiga implementations put the temp files in the directory named by
407JPEGTMP:, so be sure to assign JPEGTMP: to a disk partition with adequate free
408space.
409
410The default memory usage limit (-maxmemory) is set when the software is
411compiled. If you get an "insufficient memory" error, try specifying a smaller
412-maxmemory value, even -maxmemory 0 to use the absolute minimum space. You
413may want to recompile with a smaller default value if this happens often.
414
415On machines that have "environment" variables, you can define the environment
416variable JPEGMEM to set the default memory limit. The value is specified as
417described for the -maxmemory switch. JPEGMEM overrides the default value
418specified when the program was compiled, and itself is overridden by an
419explicit -maxmemory switch.
420
421On MS-DOS machines, -maxmemory is the amount of main (conventional) memory to
422use. (Extended or expanded memory is also used if available.) Most
423DOS-specific versions of this software do their own memory space estimation
424and do not need you to specify -maxmemory.
425
426
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000427JPEGTRAN
428
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000429jpegtran performs various useful transformations of JPEG files.
430It can translate the coded representation from one variant of JPEG to another,
431for example from baseline JPEG to progressive JPEG or vice versa. It can also
432perform some rearrangements of the image data, for example turning an image
433from landscape to portrait format by rotation.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000434
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000435jpegtran works by rearranging the compressed data (DCT coefficients), without
436ever fully decoding the image. Therefore, its transformations are lossless:
437there is no image degradation at all, which would not be true if you used
438djpeg followed by cjpeg to accomplish the same conversion. But by the same
439token, jpegtran cannot perform lossy operations such as changing the image
440quality.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000441
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000442jpegtran uses a command line syntax similar to cjpeg or djpeg.
443On Unix-like systems, you say:
444 jpegtran [switches] [inputfile] >outputfile
445On most non-Unix systems, you say:
446 jpegtran [switches] inputfile outputfile
447where both the input and output files are JPEG files.
448
449To specify the coded JPEG representation used in the output file,
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000450jpegtran accepts a subset of the switches recognized by cjpeg:
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000451 -optimize Perform optimization of entropy encoding parameters.
452 -progressive Create progressive JPEG file.
Guido Vollbeding5829cb22012-01-15 00:00:00 +0000453 -arithmetic Use arithmetic coding.
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000454 -restart N Emit a JPEG restart marker every N MCU rows, or every
455 N MCU blocks if "B" is attached to the number.
456 -scans file Use the scan script given in the specified text file.
457See the previous discussion of cjpeg for more details about these switches.
458If you specify none of these switches, you get a plain baseline-JPEG output
459file. The quality setting and so forth are determined by the input file.
460
461The image can be losslessly transformed by giving one of these switches:
462 -flip horizontal Mirror image horizontally (left-right).
463 -flip vertical Mirror image vertically (top-bottom).
464 -rotate 90 Rotate image 90 degrees clockwise.
465 -rotate 180 Rotate image 180 degrees.
466 -rotate 270 Rotate image 270 degrees clockwise (or 90 ccw).
467 -transpose Transpose image (across UL-to-LR axis).
468 -transverse Transverse transpose (across UR-to-LL axis).
469
470The transpose transformation has no restrictions regarding image dimensions.
471The other transformations operate rather oddly if the image dimensions are not
472a multiple of the iMCU size (usually 8 or 16 pixels), because they can only
473transform complete blocks of DCT coefficient data in the desired way.
474
475jpegtran's default behavior when transforming an odd-size image is designed
476to preserve exact reversibility and mathematical consistency of the
477transformation set. As stated, transpose is able to flip the entire image
478area. Horizontal mirroring leaves any partial iMCU column at the right edge
479untouched, but is able to flip all rows of the image. Similarly, vertical
480mirroring leaves any partial iMCU row at the bottom edge untouched, but is
481able to flip all columns. The other transforms can be built up as sequences
482of transpose and flip operations; for consistency, their actions on edge
483pixels are defined to be the same as the end result of the corresponding
484transpose-and-flip sequence.
485
486For practical use, you may prefer to discard any untransformable edge pixels
487rather than having a strange-looking strip along the right and/or bottom edges
488of a transformed image. To do this, add the -trim switch:
489 -trim Drop non-transformable edge blocks.
490Obviously, a transformation with -trim is not reversible, so strictly speaking
491jpegtran with this switch is not lossless. Also, the expected mathematical
492equivalences between the transformations no longer hold. For example,
493"-rot 270 -trim" trims only the bottom edge, but "-rot 90 -trim" followed by
494"-rot 180 -trim" trims both edges.
495
DRC39ea5622010-10-12 01:55:31 +0000496If you are only interested in perfect transformations, add the -perfect switch:
497 -perfect Fail with an error if the transformation is not
Guido Vollbeding5996a252009-06-27 00:00:00 +0000498 perfect.
DRC39ea5622010-10-12 01:55:31 +0000499For example, you may want to do
Guido Vollbeding5996a252009-06-27 00:00:00 +0000500 jpegtran -rot 90 -perfect foo.jpg || djpeg foo.jpg | pnmflip -r90 | cjpeg
DRC39ea5622010-10-12 01:55:31 +0000501to do a perfect rotation, if available, or an approximated one if not.
Guido Vollbeding5996a252009-06-27 00:00:00 +0000502
DRC39ea5622010-10-12 01:55:31 +0000503This version of jpegtran also offers a lossless crop option, which discards
504data outside of a given image region but losslessly preserves what is inside.
505Like the rotate and flip transforms, lossless crop is restricted by the current
506JPEG format; the upper left corner of the selected region must fall on an iMCU
507boundary. If it doesn't, then it is silently moved up and/or left to the
508nearest iMCU boundary (the lower right corner is unchanged.)
Guido Vollbeding5996a252009-06-27 00:00:00 +0000509
510The image can be losslessly cropped by giving the switch:
DRC39ea5622010-10-12 01:55:31 +0000511 -crop WxH+X+Y Crop to a rectangular region of width W and height H,
Guido Vollbeding5996a252009-06-27 00:00:00 +0000512 starting at point X,Y.
513
Guido Vollbeding989630f2010-01-10 00:00:00 +0000514Other not-strictly-lossless transformation switches are:
515
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000516 -grayscale Force grayscale output.
517This option discards the chrominance channels if the input image is YCbCr
518(ie, a standard color JPEG), resulting in a grayscale JPEG file. The
519luminance channel is preserved exactly, so this is a better method of reducing
520to grayscale than decompression, conversion, and recompression. This switch
521is particularly handy for fixing a monochrome picture that was mistakenly
522encoded as a color JPEG. (In such a case, the space savings from getting rid
523of the near-empty chroma channels won't be large; but the decoding time for
524a grayscale JPEG is substantially less than that for a color JPEG.)
525
526jpegtran also recognizes these switches that control what to do with "extra"
527markers, such as comment blocks:
528 -copy none Copy no extra markers from source file. This setting
529 suppresses all comments and other excess baggage
530 present in the source file.
531 -copy comments Copy only comment markers. This setting copies
DRC39ea5622010-10-12 01:55:31 +0000532 comments from the source file but discards
DRCccd1bfd2012-01-31 09:53:46 +0000533 any other data that is inessential for image display.
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000534 -copy all Copy all extra markers. This setting preserves
535 miscellaneous markers found in the source file, such
Guido Vollbeding5996a252009-06-27 00:00:00 +0000536 as JFIF thumbnails, Exif data, and Photoshop settings.
DRC39ea5622010-10-12 01:55:31 +0000537 In some files, these extra markers can be sizable.
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000538The default behavior is -copy comments. (Note: in IJG releases v6 and v6a,
539jpegtran always did the equivalent of -copy none.)
540
541Additional switches recognized by jpegtran are:
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000542 -outfile filename
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000543 -maxmemory N
544 -verbose
545 -debug
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000546These work the same as in cjpeg or djpeg.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000547
548
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000549THE COMMENT UTILITIES
550
551The JPEG standard allows "comment" (COM) blocks to occur within a JPEG file.
552Although the standard doesn't actually define what COM blocks are for, they
553are widely used to hold user-supplied text strings. This lets you add
554annotations, titles, index terms, etc to your JPEG files, and later retrieve
555them as text. COM blocks do not interfere with the image stored in the JPEG
556file. The maximum size of a COM block is 64K, but you can have as many of
557them as you like in one JPEG file.
558
559We provide two utility programs to display COM block contents and add COM
560blocks to a JPEG file.
561
562rdjpgcom searches a JPEG file and prints the contents of any COM blocks on
563standard output. The command line syntax is
Guido Vollbeding5996a252009-06-27 00:00:00 +0000564 rdjpgcom [-raw] [-verbose] [inputfilename]
DRC39ea5622010-10-12 01:55:31 +0000565The switch "-raw" (or just "-r") causes rdjpgcom to output non-printable
566characters in JPEG comments. These characters are normally escaped for
567security reasons.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000568The switch "-verbose" (or just "-v") causes rdjpgcom to also display the JPEG
569image dimensions. If you omit the input file name from the command line,
570the JPEG file is read from standard input. (This may not work on some
571operating systems, if binary data can't be read from stdin.)
572
573wrjpgcom adds a COM block, containing text you provide, to a JPEG file.
574Ordinarily, the COM block is added after any existing COM blocks, but you
575can delete the old COM blocks if you wish. wrjpgcom produces a new JPEG
576file; it does not modify the input file. DO NOT try to overwrite the input
577file by directing wrjpgcom's output back into it; on most systems this will
578just destroy your file.
579
580The command line syntax for wrjpgcom is similar to cjpeg's. On Unix-like
581systems, it is
582 wrjpgcom [switches] [inputfilename]
583The output file is written to standard output. The input file comes from
584the named file, or from standard input if no input file is named.
585
586On most non-Unix systems, the syntax is
587 wrjpgcom [switches] inputfilename outputfilename
588where both input and output file names must be given explicitly.
589
590wrjpgcom understands three switches:
591 -replace Delete any existing COM blocks from the file.
592 -comment "Comment text" Supply new COM text on command line.
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000593 -cfile name Read text for new COM block from named file.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000594(Switch names can be abbreviated.) If you have only one line of comment text
595to add, you can provide it on the command line with -comment. The comment
596text must be surrounded with quotes so that it is treated as a single
597argument. Longer comments can be read from a text file.
598
599If you give neither -comment nor -cfile, then wrjpgcom will read the comment
600text from standard input. (In this case an input image file name MUST be
601supplied, so that the source JPEG file comes from somewhere else.) You can
602enter multiple lines, up to 64KB worth. Type an end-of-file indicator
603(usually control-D or control-Z) to terminate the comment text entry.
604
605wrjpgcom will not add a COM block if the provided comment string is empty.
606Therefore -replace -comment "" can be used to delete all COM blocks from a
607file.
608
609These utility programs do not depend on the IJG JPEG library. In
610particular, the source code for rdjpgcom is intended as an illustration of
611the minimum amount of code required to parse a JPEG file header correctly.