blob: 5abda4ede6d6d126acd9aacf939967e619a29b2b [file] [log] [blame]
DRCa73e8702012-12-31 02:52:30 +00001NOTE: This file was modified by The libjpeg-turbo Project to include only
DRCcf763c02013-01-01 09:51:37 +00002information relevant to libjpeg-turbo and to wordsmith certain sections.
DRCa73e8702012-12-31 02:52:30 +00003
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
DRC90d6c382014-05-12 09:08:39 +000020full-color and grayscale 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:
DRCb7753512014-05-11 09:36:25 +000029 cjpeg [switches] [imagefile] >jpegfile
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000030or
DRCb7753512014-05-11 09:36:25 +000031 djpeg [switches] [jpegfile] >imagefile
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000032The 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:
DRCb7753512014-05-11 09:36:25 +000038 cjpeg [switches] imagefile jpegfile
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000039or
DRCb7753512014-05-11 09:36:25 +000040 djpeg [switches] jpegfile imagefile
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000041i.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:
DRCb7753512014-05-11 09:36:25 +000047 cjpeg [switches] -outfile jpegfile imagefile
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000048or
DRCb7753512014-05-11 09:36:25 +000049 djpeg [switches] -outfile imagefile jpegfile
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000050This syntax works on all systems, so it is useful for scripts.
51
52The currently supported image file formats are: PPM (PBMPLUS color format),
DRC90d6c382014-05-12 09:08:39 +000053PGM (PBMPLUS grayscale format), BMP, Targa, and RLE (Utah Raster Toolkit
Guido Vollbedinga560e4b2016-01-17 00:00:00 +000054format). (RLE is supported only if the URT library is available, which it
55isn't on most non-Unix systems.) cjpeg recognizes the input image format
DRCd4be4232016-02-19 10:35:41 -060056automatically, with the exception of some Targa files. You have to tell djpeg
57which format to generate.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000058
59JPEG files are in the defacto standard JFIF file format. There are other,
60less widely used JPEG-based file formats, but we don't support them.
61
62All 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
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000064one letter. Upper and lower case are equivalent (-BMP is the same as -bmp).
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000065British spellings are also accepted (e.g., -greyscale), though for brevity
66these are not mentioned below.
67
68
69CJPEG DETAILS
70
71The basic command line switches for cjpeg are:
72
DRCb7753512014-05-11 09:36:25 +000073 -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.)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000076
DRCb7753512014-05-11 09:36:25 +000077 -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.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000083
DRCb7753512014-05-11 09:36:25 +000084 -rgb Create RGB JPEG file.
85 Using this switch suppresses the conversion from RGB
86 colorspace input to the default YCbCr JPEG colorspace.
Guido Vollbeding5829cb22012-01-15 00:00:00 +000087
DRCb7753512014-05-11 09:36:25 +000088 -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.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000094
DRCb7753512014-05-11 09:36:25 +000095 -progressive Create progressive JPEG file (see below).
Thomas G. Lanebc79e061995-08-02 00:00:00 +000096
DRCb7753512014-05-11 09:36:25 +000097 -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.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000102
103The -quality switch lets you trade off compressed file size against quality of
104the reconstructed image: the higher the quality setting, the larger the JPEG
105file, and the closer the output image will be to the original input. Normally
106you want to use the lowest quality setting (smallest file) that decompresses
107into something visually indistinguishable from the original image. For this
DRC6fa5ebd2015-12-17 10:41:51 -0600108purpose the quality setting should generally be between 50 and 95 (the default
109is 75) for photographic images. If you see defects at -quality 75, then go up
1105 or 10 counts at a time until you are happy with the output image. (The
111optimal setting will vary from one image to another.)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000112
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000113-quality 100 will generate a quantization table of all 1's, minimizing loss
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000114in the quantization step (but there is still information loss in subsampling,
DRC6fa5ebd2015-12-17 10:41:51 -0600115as well as roundoff error.) For most images, specifying a quality value above
116about 95 will increase the size of the compressed file dramatically, and while
117the quality gain from these higher quality values is measurable (using metrics
118such as PSNR or SSIM), it is rarely perceivable by human vision.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000119
120In the other direction, quality values below 50 will produce very small files
121of low image quality. Settings around 5 to 10 might be useful in preparing an
122index of a large image library, for example. Try -quality 2 (or so) for some
123amusing Cubist effects. (Note: quality values below about 25 generate 2-byte
124quantization tables, which are considered optional in the JPEG standard.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000125cjpeg emits a warning message when you give such a quality value, because some
126other JPEG programs may be unable to decode the resulting file. Use -baseline
127if you need to ensure compatibility at low quality values.)
128
DRC39ea5622010-10-12 01:55:31 +0000129The -quality option has been extended in this version of cjpeg to support
130separate quality settings for luminance and chrominance (or, in general,
131separate settings for every quantization table slot.) The principle is the
132same as chrominance subsampling: since the human eye is more sensitive to
133spatial changes in brightness than spatial changes in color, the chrominance
134components can be quantized more than the luminance components without
135incurring any visible image quality loss. However, unlike subsampling, this
136feature reduces data in the frequency domain instead of the spatial domain,
137which allows for more fine-grained control. This option is useful in
138quality-sensitive applications, for which the artifacts generated by
139subsampling may be unacceptable.
140
141The -quality option accepts a comma-separated list of parameters, which
DRC66a69f02012-01-31 10:19:29 +0000142respectively refer to the quality levels that should be assigned to the
DRC39ea5622010-10-12 01:55:31 +0000143quantization table slots. If there are more q-table slots than parameters,
144then the last parameter is replicated. Thus, if only one quality parameter is
145given, this is used for both luminance and chrominance (slots 0 and 1,
146respectively), preserving the legacy behavior of cjpeg v6b and prior. More (or
147customized) quantization tables can be set with the -qtables option and
148assigned to components with the -qslots option (see the "wizard" switches
149below.)
150
151JPEG files generated with separate luminance and chrominance quality are
152fully compliant with standard JPEG decoders.
153
154CAUTION: For this setting to be useful, be sure to pass an argument of
155-sample 1x1 to cjpeg to disable chrominance subsampling. Otherwise, the
156default subsampling level (2x2, AKA "4:2:0") will be used.
Guido Vollbeding5996a252009-06-27 00:00:00 +0000157
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000158The -progressive switch creates a "progressive JPEG" file. In this type of
159JPEG file, the data is stored in multiple scans of increasing quality. If the
160file is being transmitted over a slow communications link, the decoder can use
161the first scan to display a low-quality image very quickly, and can then
162improve the display with each subsequent scan. The final image is exactly
163equivalent to a standard JPEG file of the same quality setting, and the total
Guido Vollbeding5996a252009-06-27 00:00:00 +0000164file size is about the same --- often a little smaller.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000165
166Switches for advanced users:
167
DRCb7753512014-05-11 09:36:25 +0000168 -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.
Guido Vollbeding5829cb22012-01-15 00:00:00 +0000172
DRCb7753512014-05-11 09:36:25 +0000173 -dct int Use integer DCT method (default).
174 -dct fast Use fast integer DCT (less accurate).
DRC8940e6c2014-05-11 09:46:28 +0000175 In libjpeg-turbo, the fast method is generally about
176 5-15% faster than the int method when using the
177 x86/x86-64 SIMD extensions (results may vary with other
178 SIMD implementations, or when using libjpeg-turbo
179 without SIMD extensions.) For quality levels of 90 and
180 below, there should be little or no perceptible
181 difference between the two algorithms. For quality
182 levels above 90, however, the difference between
183 the fast and the int methods becomes more pronounced.
184 With quality=97, for instance, the fast method incurs
185 generally about a 1-3 dB loss (in PSNR) relative to
186 the int method, but this can be larger for some images.
187 Do not use the fast method with quality levels above
188 97. The algorithm often degenerates at quality=98 and
189 above and can actually produce a more lossy image than
DRC05524e62014-05-11 23:14:43 +0000190 if lower quality levels had been used. Also, in
191 libjpeg-turbo, the fast method is not fully accerated
192 for quality levels above 97, so it will be slower than
193 the int method.
194 -dct float Use floating-point DCT method.
195 The float method is mainly a legacy feature. It does
196 not produce significantly more accurate results than
197 the int method, and it is much slower. The float
198 method may also give different results on different
199 machines due to varying roundoff behavior, whereas the
200 integer methods should give the same results on all
201 machines.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000202
DRCb7753512014-05-11 09:36:25 +0000203 -restart N Emit a JPEG restart marker every N MCU rows, or every
204 N MCU blocks if "B" is attached to the number.
205 -restart 0 (the default) means no restart markers.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000206
DRCb7753512014-05-11 09:36:25 +0000207 -smooth N Smooth the input image to eliminate dithering noise.
208 N, ranging from 1 to 100, indicates the strength of
209 smoothing. 0 (the default) means no smoothing.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000210
DRCb7753512014-05-11 09:36:25 +0000211 -maxmemory N Set limit for amount of memory to use in processing
212 large images. Value is in thousands of bytes, or
213 millions of bytes if "M" is attached to the number.
214 For example, -max 4m selects 4000000 bytes. If more
215 space is needed, temporary files will be used.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000216
DRCb7753512014-05-11 09:36:25 +0000217 -verbose Enable debug printout. More -v's give more printout.
218 or -debug Also, version information is printed at startup.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000219
220The -restart option inserts extra markers that allow a JPEG decoder to
221resynchronize after a transmission error. Without restart markers, any damage
222to a compressed file will usually ruin the image from the point of the error
223to the end of the image; with restart markers, the damage is usually confined
224to the portion of the image up to the next restart marker. Of course, the
225restart markers occupy extra space. We recommend -restart 1 for images that
226will be transmitted across unreliable networks such as Usenet.
227
228The -smooth option filters the input to eliminate fine-scale noise. This is
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000229often useful when converting dithered images to JPEG: a moderate smoothing
230factor of 10 to 50 gets rid of dithering patterns in the input file, resulting
231in a smaller JPEG file and a better-looking image. Too large a smoothing
232factor will visibly blur the image, however.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000233
234Switches for wizards:
235
DRCb7753512014-05-11 09:36:25 +0000236 -baseline Force baseline-compatible quantization tables to be
237 generated. This clamps quantization values to 8 bits
238 even at low quality settings. (This switch is poorly
239 named, since it does not ensure that the output is
240 actually baseline JPEG. For example, you can use
241 -baseline and -progressive together.)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000242
DRCb7753512014-05-11 09:36:25 +0000243 -qtables file Use the quantization tables given in the specified
244 text file.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000245
DRCb7753512014-05-11 09:36:25 +0000246 -qslots N[,...] Select which quantization table to use for each color
247 component.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000248
DRCb7753512014-05-11 09:36:25 +0000249 -sample HxV[,...] Set JPEG sampling factors for each color component.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000250
DRCb7753512014-05-11 09:36:25 +0000251 -scans file Use the scan script given in the specified text file.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000252
253The "wizard" switches are intended for experimentation with JPEG. If you
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000254don't know what you are doing, DON'T USE THEM. These switches are documented
Guido Vollbeding5996a252009-06-27 00:00:00 +0000255further in the file wizard.txt.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000256
257
258DJPEG DETAILS
259
260The basic command line switches for djpeg are:
261
DRCb7753512014-05-11 09:36:25 +0000262 -colors N Reduce image to at most N colors. This reduces the
263 or -quantize N number of colors used in the output image, so that it
264 can be displayed on a colormapped display or stored in
265 a colormapped file format. For example, if you have
266 an 8-bit display, you'd need to reduce to 256 or fewer
267 colors. (-colors is the recommended name, -quantize
268 is provided only for backwards compatibility.)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000269
DRCb7753512014-05-11 09:36:25 +0000270 -fast Select recommended processing options for fast, low
271 quality output. (The default options are chosen for
272 highest quality output.) Currently, this is equivalent
273 to "-dct fast -nosmooth -onepass -dither ordered".
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000274
DRC90d6c382014-05-12 09:08:39 +0000275 -grayscale Force grayscale output even if JPEG file is color.
DRCb7753512014-05-11 09:36:25 +0000276 Useful for viewing on monochrome displays; also,
277 djpeg runs noticeably faster in this mode.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000278
DRC54e6b8e2016-02-18 15:16:17 -0600279 -rgb Force RGB output even if JPEG file is grayscale.
Guido Vollbedinga560e4b2016-01-17 00:00:00 +0000280
DRCb7753512014-05-11 09:36:25 +0000281 -scale M/N Scale the output image by a factor M/N. Currently
282 the scale factor must be M/8, where M is an integer
283 between 1 and 16 inclusive, or any reduced fraction
284 thereof (such as 1/2, 3/4, etc. Scaling is handy if
285 the image is larger than your screen; also, djpeg runs
286 much faster when scaling down the output.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000287
DRCb7753512014-05-11 09:36:25 +0000288 -bmp Select BMP output format (Windows flavor). 8-bit
289 colormapped format is emitted if -colors or -grayscale
DRC90d6c382014-05-12 09:08:39 +0000290 is specified, or if the JPEG file is grayscale;
DRCb7753512014-05-11 09:36:25 +0000291 otherwise, 24-bit full-color format is emitted.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000292
DRCb7753512014-05-11 09:36:25 +0000293 -gif Select GIF output format. Since GIF does not support
294 more than 256 colors, -colors 256 is assumed (unless
295 you specify a smaller number of colors). If you
296 specify -fast, the default number of colors is 216.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000297
DRCb7753512014-05-11 09:36:25 +0000298 -os2 Select BMP output format (OS/2 1.x flavor). 8-bit
299 colormapped format is emitted if -colors or -grayscale
DRC90d6c382014-05-12 09:08:39 +0000300 is specified, or if the JPEG file is grayscale;
DRCb7753512014-05-11 09:36:25 +0000301 otherwise, 24-bit full-color format is emitted.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000302
DRCb7753512014-05-11 09:36:25 +0000303 -pnm Select PBMPLUS (PPM/PGM) output format (this is the
304 default format). PGM is emitted if the JPEG file is
DRC90d6c382014-05-12 09:08:39 +0000305 grayscale or if -grayscale is specified; otherwise
DRCb7753512014-05-11 09:36:25 +0000306 PPM is emitted.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000307
DRCb7753512014-05-11 09:36:25 +0000308 -rle Select RLE output format. (Requires URT library.)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000309
DRC90d6c382014-05-12 09:08:39 +0000310 -targa Select Targa output format. Grayscale format is
311 emitted if the JPEG file is grayscale or if
DRCb7753512014-05-11 09:36:25 +0000312 -grayscale is specified; otherwise, colormapped format
313 is emitted if -colors is specified; otherwise, 24-bit
314 full-color format is emitted.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000315
316Switches for advanced users:
317
DRCb7753512014-05-11 09:36:25 +0000318 -dct int Use integer DCT method (default).
319 -dct fast Use fast integer DCT (less accurate).
DRC8940e6c2014-05-11 09:46:28 +0000320 In libjpeg-turbo, the fast method is generally about
321 5-15% faster than the int method when using the
322 x86/x86-64 SIMD extensions (results may vary with other
323 SIMD implementations, or when using libjpeg-turbo
324 without SIMD extensions.) If the JPEG image was
325 compressed using a quality level of 85 or below, then
326 there should be little or no perceptible difference
327 between the two algorithms. When decompressing images
328 that were compressed using quality levels above 85,
329 however, the difference between the fast and int
330 methods becomes more pronounced. With images
331 compressed using quality=97, for instance, the fast
332 method incurs generally about a 4-6 dB loss (in PSNR)
333 relative to the int method, but this can be larger for
334 some images. If you can avoid it, do not use the fast
335 method when decompressing images that were compressed
336 using quality levels above 97. The algorithm often
337 degenerates for such images and can actually produce
338 a more lossy output image than if the JPEG image had
DRC05524e62014-05-11 23:14:43 +0000339 been compressed using lower quality levels.
340 -dct float Use floating-point DCT method.
341 The float method is mainly a legacy feature. It does
342  not produce significantly more accurate results than
343 the int method, and it is much slower. The float
344 method may also give different results on different
345 machines due to varying roundoff behavior, whereas the
346 integer methods should give the same results on all
347 machines.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000348
DRCb7753512014-05-11 09:36:25 +0000349 -dither fs Use Floyd-Steinberg dithering in color quantization.
350 -dither ordered Use ordered dithering in color quantization.
351 -dither none Do not use dithering in color quantization.
352 By default, Floyd-Steinberg dithering is applied when
353 quantizing colors; this is slow but usually produces
354 the best results. Ordered dither is a compromise
355 between speed and quality; no dithering is fast but
356 usually looks awful. Note that these switches have
357 no effect unless color quantization is being done.
358 Ordered dither is only available in -onepass mode.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000359
DRCb7753512014-05-11 09:36:25 +0000360 -map FILE Quantize to the colors used in the specified image
361 file. This is useful for producing multiple files
362 with identical color maps, or for forcing a predefined
363 set of colors to be used. The FILE must be a GIF
364 or PPM file. This option overrides -colors and
365 -onepass.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000366
DRCb7753512014-05-11 09:36:25 +0000367 -nosmooth Use a faster, lower-quality upsampling routine.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000368
DRCb7753512014-05-11 09:36:25 +0000369 -onepass Use one-pass instead of two-pass color quantization.
370 The one-pass method is faster and needs less memory,
371 but it produces a lower-quality image. -onepass is
372 ignored unless you also say -colors N. Also,
DRC90d6c382014-05-12 09:08:39 +0000373 the one-pass method is always used for grayscale
DRCb7753512014-05-11 09:36:25 +0000374 output (the two-pass method is no improvement then).
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000375
DRCb7753512014-05-11 09:36:25 +0000376 -maxmemory N Set limit for amount of memory to use in processing
377 large images. Value is in thousands of bytes, or
378 millions of bytes if "M" is attached to the number.
379 For example, -max 4m selects 4000000 bytes. If more
380 space is needed, temporary files will be used.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000381
DRCb7753512014-05-11 09:36:25 +0000382 -verbose Enable debug printout. More -v's give more printout.
383 or -debug Also, version information is printed at startup.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000384
385
386HINTS FOR CJPEG
387
388Color GIF files are not the ideal input for JPEG; JPEG is really intended for
389compressing full-color (24-bit) images. In particular, don't try to convert
390cartoons, line drawings, and other images that have only a few distinct
391colors. GIF works great on these, JPEG does not. If you want to convert a
392GIF to JPEG, you should experiment with cjpeg's -quality and -smooth options
393to get a satisfactory conversion. -smooth 10 or so is often helpful.
394
395Avoid running an image through a series of JPEG compression/decompression
396cycles. Image quality loss will accumulate; after ten or so cycles the image
397may be noticeably worse than it was after one cycle. It's best to use a
398lossless format while manipulating an image, then convert to JPEG format when
399you are ready to file the image away.
400
401The -optimize option to cjpeg is worth using when you are making a "final"
402version for posting or archiving. It's also a win when you are using low
403quality settings to make very small JPEG files; the percentage improvement
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000404is often a lot more than it is on larger files. (At present, -optimize
405mode is always selected when generating progressive JPEG files.)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000406
DRC39ea5622010-10-12 01:55:31 +0000407Support for GIF input files was removed in cjpeg v6b due to concerns over
408the Unisys LZW patent. Although this patent expired in 2006, cjpeg still
409lacks GIF support, for these historical reasons. (Conversion of GIF files to
410JPEG is usually a bad idea anyway.)
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000411
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000412
413HINTS FOR DJPEG
414
415To get a quick preview of an image, use the -grayscale and/or -scale switches.
416"-grayscale -scale 1/8" is the fastest case.
417
418Several options are available that trade off image quality to gain speed.
419"-fast" turns on the recommended settings.
420
421"-dct fast" and/or "-nosmooth" gain speed at a small sacrifice in quality.
422When producing a color-quantized image, "-onepass -dither ordered" is fast but
423much lower quality than the default behavior. "-dither none" may give
424acceptable results in two-pass mode, but is seldom tolerable in one-pass mode.
425
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000426Two-pass color quantization requires a good deal of memory; on MS-DOS machines
427it may run out of memory even with -maxmemory 0. In that case you can still
428decompress, with some loss of image quality, by specifying -onepass for
429one-pass quantization.
430
Guido Vollbedingfc111932014-01-19 00:00:00 +0000431To avoid the Unisys LZW patent (now expired), djpeg produces uncompressed GIF
432files. These are larger than they should be, but are readable by standard GIF
433decoders.
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000434
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000435
436HINTS FOR BOTH PROGRAMS
437
438If more space is needed than will fit in the available main memory (as
439determined by -maxmemory), temporary files will be used. (MS-DOS versions
440will try to get extended or expanded memory first.) The temporary files are
441often rather large: in typical cases they occupy three bytes per pixel, for
442example 3*800*600 = 1.44Mb for an 800x600 image. If you don't have enough
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000443free disk space, leave out -progressive and -optimize (for cjpeg) or specify
444-onepass (for djpeg).
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000445
446On MS-DOS, the temporary files are created in the directory named by the TMP
447or TEMP environment variable, or in the current directory if neither of those
448exist. Amiga implementations put the temp files in the directory named by
449JPEGTMP:, so be sure to assign JPEGTMP: to a disk partition with adequate free
450space.
451
452The default memory usage limit (-maxmemory) is set when the software is
453compiled. If you get an "insufficient memory" error, try specifying a smaller
454-maxmemory value, even -maxmemory 0 to use the absolute minimum space. You
455may want to recompile with a smaller default value if this happens often.
456
457On machines that have "environment" variables, you can define the environment
458variable JPEGMEM to set the default memory limit. The value is specified as
459described for the -maxmemory switch. JPEGMEM overrides the default value
460specified when the program was compiled, and itself is overridden by an
461explicit -maxmemory switch.
462
463On MS-DOS machines, -maxmemory is the amount of main (conventional) memory to
464use. (Extended or expanded memory is also used if available.) Most
465DOS-specific versions of this software do their own memory space estimation
466and do not need you to specify -maxmemory.
467
468
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000469JPEGTRAN
470
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000471jpegtran performs various useful transformations of JPEG files.
472It can translate the coded representation from one variant of JPEG to another,
473for example from baseline JPEG to progressive JPEG or vice versa. It can also
474perform some rearrangements of the image data, for example turning an image
Guido Vollbedinga560e4b2016-01-17 00:00:00 +0000475from landscape to portrait format by rotation. For EXIF files and JPEG files
476containing Exif data, you may prefer to use exiftran instead.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000477
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000478jpegtran works by rearranging the compressed data (DCT coefficients), without
479ever fully decoding the image. Therefore, its transformations are lossless:
480there is no image degradation at all, which would not be true if you used
481djpeg followed by cjpeg to accomplish the same conversion. But by the same
482token, jpegtran cannot perform lossy operations such as changing the image
Guido Vollbedinga560e4b2016-01-17 00:00:00 +0000483quality. However, while the image data is losslessly transformed, metadata
484can be removed. See the -copy option for specifics.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000485
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000486jpegtran uses a command line syntax similar to cjpeg or djpeg.
487On Unix-like systems, you say:
DRCb7753512014-05-11 09:36:25 +0000488 jpegtran [switches] [inputfile] >outputfile
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000489On most non-Unix systems, you say:
DRCb7753512014-05-11 09:36:25 +0000490 jpegtran [switches] inputfile outputfile
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000491where both the input and output files are JPEG files.
492
493To specify the coded JPEG representation used in the output file,
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000494jpegtran accepts a subset of the switches recognized by cjpeg:
DRCb7753512014-05-11 09:36:25 +0000495 -optimize Perform optimization of entropy encoding parameters.
496 -progressive Create progressive JPEG file.
497 -arithmetic Use arithmetic coding.
498 -restart N Emit a JPEG restart marker every N MCU rows, or every
499 N MCU blocks if "B" is attached to the number.
500 -scans file Use the scan script given in the specified text file.
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000501See the previous discussion of cjpeg for more details about these switches.
502If you specify none of these switches, you get a plain baseline-JPEG output
503file. The quality setting and so forth are determined by the input file.
504
505The image can be losslessly transformed by giving one of these switches:
DRCb7753512014-05-11 09:36:25 +0000506 -flip horizontal Mirror image horizontally (left-right).
507 -flip vertical Mirror image vertically (top-bottom).
508 -rotate 90 Rotate image 90 degrees clockwise.
509 -rotate 180 Rotate image 180 degrees.
510 -rotate 270 Rotate image 270 degrees clockwise (or 90 ccw).
511 -transpose Transpose image (across UL-to-LR axis).
512 -transverse Transverse transpose (across UR-to-LL axis).
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000513
514The transpose transformation has no restrictions regarding image dimensions.
515The other transformations operate rather oddly if the image dimensions are not
516a multiple of the iMCU size (usually 8 or 16 pixels), because they can only
517transform complete blocks of DCT coefficient data in the desired way.
518
519jpegtran's default behavior when transforming an odd-size image is designed
520to preserve exact reversibility and mathematical consistency of the
521transformation set. As stated, transpose is able to flip the entire image
522area. Horizontal mirroring leaves any partial iMCU column at the right edge
523untouched, but is able to flip all rows of the image. Similarly, vertical
524mirroring leaves any partial iMCU row at the bottom edge untouched, but is
525able to flip all columns. The other transforms can be built up as sequences
526of transpose and flip operations; for consistency, their actions on edge
527pixels are defined to be the same as the end result of the corresponding
528transpose-and-flip sequence.
529
530For practical use, you may prefer to discard any untransformable edge pixels
531rather than having a strange-looking strip along the right and/or bottom edges
532of a transformed image. To do this, add the -trim switch:
DRCb7753512014-05-11 09:36:25 +0000533 -trim Drop non-transformable edge blocks.
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000534Obviously, a transformation with -trim is not reversible, so strictly speaking
535jpegtran with this switch is not lossless. Also, the expected mathematical
536equivalences between the transformations no longer hold. For example,
537"-rot 270 -trim" trims only the bottom edge, but "-rot 90 -trim" followed by
538"-rot 180 -trim" trims both edges.
539
DRC39ea5622010-10-12 01:55:31 +0000540If you are only interested in perfect transformations, add the -perfect switch:
DRCb7753512014-05-11 09:36:25 +0000541 -perfect Fail with an error if the transformation is not
542 perfect.
DRC39ea5622010-10-12 01:55:31 +0000543For example, you may want to do
Guido Vollbeding5996a252009-06-27 00:00:00 +0000544 jpegtran -rot 90 -perfect foo.jpg || djpeg foo.jpg | pnmflip -r90 | cjpeg
DRC39ea5622010-10-12 01:55:31 +0000545to do a perfect rotation, if available, or an approximated one if not.
Guido Vollbeding5996a252009-06-27 00:00:00 +0000546
DRC39ea5622010-10-12 01:55:31 +0000547This version of jpegtran also offers a lossless crop option, which discards
548data outside of a given image region but losslessly preserves what is inside.
549Like the rotate and flip transforms, lossless crop is restricted by the current
550JPEG format; the upper left corner of the selected region must fall on an iMCU
551boundary. If it doesn't, then it is silently moved up and/or left to the
DRC54e6b8e2016-02-18 15:16:17 -0600552nearest iMCU boundary (the lower right corner is unchanged.) Thus, the output
553image covers at least the requested region, but it may cover more. The
554adjustment of the region dimensions may be optionally disabled by attaching an
555'f' character ("force") to the width or height number.
Guido Vollbeding5996a252009-06-27 00:00:00 +0000556
557The image can be losslessly cropped by giving the switch:
DRCb7753512014-05-11 09:36:25 +0000558 -crop WxH+X+Y Crop to a rectangular region of width W and height H,
559 starting at point X,Y.
Guido Vollbeding5996a252009-06-27 00:00:00 +0000560
Guido Vollbeding989630f2010-01-10 00:00:00 +0000561Other not-strictly-lossless transformation switches are:
562
DRCb7753512014-05-11 09:36:25 +0000563 -grayscale Force grayscale output.
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000564This option discards the chrominance channels if the input image is YCbCr
565(ie, a standard color JPEG), resulting in a grayscale JPEG file. The
566luminance channel is preserved exactly, so this is a better method of reducing
567to grayscale than decompression, conversion, and recompression. This switch
568is particularly handy for fixing a monochrome picture that was mistakenly
569encoded as a color JPEG. (In such a case, the space savings from getting rid
570of the near-empty chroma channels won't be large; but the decoding time for
571a grayscale JPEG is substantially less than that for a color JPEG.)
572
573jpegtran also recognizes these switches that control what to do with "extra"
574markers, such as comment blocks:
DRCb7753512014-05-11 09:36:25 +0000575 -copy none Copy no extra markers from source file. This setting
DRC54e6b8e2016-02-18 15:16:17 -0600576 suppresses all comments and other metadata in the
577 source file.
DRCb7753512014-05-11 09:36:25 +0000578 -copy comments Copy only comment markers. This setting copies
DRC54e6b8e2016-02-18 15:16:17 -0600579 comments from the source file but discards any other
580 metadata.
DRCb7753512014-05-11 09:36:25 +0000581 -copy all Copy all extra markers. This setting preserves
582 miscellaneous markers found in the source file, such
583 as JFIF thumbnails, Exif data, and Photoshop settings.
584 In some files, these extra markers can be sizable.
DRC54e6b8e2016-02-18 15:16:17 -0600585 Note that this option will copy thumbnails as-is;
586 they will not be transformed.
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000587The default behavior is -copy comments. (Note: in IJG releases v6 and v6a,
588jpegtran always did the equivalent of -copy none.)
589
590Additional switches recognized by jpegtran are:
DRCb7753512014-05-11 09:36:25 +0000591 -outfile filename
592 -maxmemory N
593 -verbose
594 -debug
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000595These work the same as in cjpeg or djpeg.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000596
597
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000598THE COMMENT UTILITIES
599
600The JPEG standard allows "comment" (COM) blocks to occur within a JPEG file.
601Although the standard doesn't actually define what COM blocks are for, they
602are widely used to hold user-supplied text strings. This lets you add
603annotations, titles, index terms, etc to your JPEG files, and later retrieve
604them as text. COM blocks do not interfere with the image stored in the JPEG
605file. The maximum size of a COM block is 64K, but you can have as many of
606them as you like in one JPEG file.
607
608We provide two utility programs to display COM block contents and add COM
609blocks to a JPEG file.
610
611rdjpgcom searches a JPEG file and prints the contents of any COM blocks on
612standard output. The command line syntax is
DRCb7753512014-05-11 09:36:25 +0000613 rdjpgcom [-raw] [-verbose] [inputfilename]
DRC39ea5622010-10-12 01:55:31 +0000614The switch "-raw" (or just "-r") causes rdjpgcom to output non-printable
615characters in JPEG comments. These characters are normally escaped for
616security reasons.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000617The switch "-verbose" (or just "-v") causes rdjpgcom to also display the JPEG
618image dimensions. If you omit the input file name from the command line,
619the JPEG file is read from standard input. (This may not work on some
620operating systems, if binary data can't be read from stdin.)
621
622wrjpgcom adds a COM block, containing text you provide, to a JPEG file.
623Ordinarily, the COM block is added after any existing COM blocks, but you
624can delete the old COM blocks if you wish. wrjpgcom produces a new JPEG
625file; it does not modify the input file. DO NOT try to overwrite the input
626file by directing wrjpgcom's output back into it; on most systems this will
627just destroy your file.
628
629The command line syntax for wrjpgcom is similar to cjpeg's. On Unix-like
630systems, it is
DRCb7753512014-05-11 09:36:25 +0000631 wrjpgcom [switches] [inputfilename]
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000632The output file is written to standard output. The input file comes from
633the named file, or from standard input if no input file is named.
634
635On most non-Unix systems, the syntax is
DRCb7753512014-05-11 09:36:25 +0000636 wrjpgcom [switches] inputfilename outputfilename
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000637where both input and output file names must be given explicitly.
638
639wrjpgcom understands three switches:
DRCb7753512014-05-11 09:36:25 +0000640 -replace Delete any existing COM blocks from the file.
641 -comment "Comment text" Supply new COM text on command line.
642 -cfile name Read text for new COM block from named file.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000643(Switch names can be abbreviated.) If you have only one line of comment text
644to add, you can provide it on the command line with -comment. The comment
645text must be surrounded with quotes so that it is treated as a single
646argument. Longer comments can be read from a text file.
647
648If you give neither -comment nor -cfile, then wrjpgcom will read the comment
649text from standard input. (In this case an input image file name MUST be
650supplied, so that the source JPEG file comes from somewhere else.) You can
651enter multiple lines, up to 64KB worth. Type an end-of-file indicator
652(usually control-D or control-Z) to terminate the comment text entry.
653
654wrjpgcom will not add a COM block if the provided comment string is empty.
655Therefore -replace -comment "" can be used to delete all COM blocks from a
656file.
657
658These utility programs do not depend on the IJG JPEG library. In
659particular, the source code for rdjpgcom is intended as an illustration of
660the minimum amount of code required to parse a JPEG file header correctly.