blob: f59d290be2d076d055168958d36bd843beef901b [file] [log] [blame]
DRCcf763c02013-01-01 09:51:37 +00001.TH CJPEG 1 "1 January 2013"
Thomas G. Lanebd543f01991-12-13 00:00:00 +00002.SH NAME
3cjpeg \- compress an image file to a JPEG file
4.SH SYNOPSIS
5.B cjpeg
6[
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +00007.I options
Thomas G. Lane4a6b7301992-03-17 00:00:00 +00008]
9[
Thomas G. Lanebd543f01991-12-13 00:00:00 +000010.I filename
11]
12.LP
13.SH DESCRIPTION
14.LP
15.B cjpeg
16compresses the named image file, or the standard input if no file is
17named, and produces a JPEG/JFIF file on the standard output.
Thomas G. Lane88aeed41992-12-10 00:00:00 +000018The currently supported input file formats are: PPM (PBMPLUS color
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000019format), PGM (PBMPLUS gray-scale format), BMP, Targa, and RLE (Utah Raster
Thomas G. Lanebd543f01991-12-13 00:00:00 +000020Toolkit format). (RLE is supported only if the URT library is available.)
21.SH OPTIONS
Thomas G. Lane88aeed41992-12-10 00:00:00 +000022All switch names may be abbreviated; for example,
23.B \-grayscale
24may be written
25.B \-gray
26or
27.BR \-gr .
28Most of the "basic" switches can be abbreviated to as little as one letter.
29Upper and lower case are equivalent (thus
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000030.B \-BMP
Thomas G. Lane88aeed41992-12-10 00:00:00 +000031is the same as
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000032.BR \-bmp ).
Thomas G. Lane88aeed41992-12-10 00:00:00 +000033British spellings are also accepted (e.g.,
34.BR \-greyscale ),
35though for brevity these are not mentioned below.
36.PP
37The basic switches are:
Thomas G. Lanebd543f01991-12-13 00:00:00 +000038.TP
Guido Vollbeding5996a252009-06-27 00:00:00 +000039.BI \-quality " N[,...]"
Thomas G. Lanebd543f01991-12-13 00:00:00 +000040Scale quantization tables to adjust image quality. Quality is 0 (worst) to
41100 (best); default is 75. (See below for more info.)
42.TP
Thomas G. Lane88aeed41992-12-10 00:00:00 +000043.B \-grayscale
44Create monochrome JPEG file from color input. Be sure to use this switch when
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000045compressing a grayscale BMP file, because
Thomas G. Lane88aeed41992-12-10 00:00:00 +000046.B cjpeg
Thomas G. Lane5ead57a1998-03-27 00:00:00 +000047isn't bright enough to notice whether a BMP file uses only shades of gray.
Thomas G. Lane88aeed41992-12-10 00:00:00 +000048By saying
49.BR \-grayscale ,
50you'll get a smaller JPEG file that takes less time to process.
51.TP
52.B \-optimize
Thomas G. Lanebd543f01991-12-13 00:00:00 +000053Perform optimization of entropy encoding parameters. Without this, default
54encoding parameters are used.
Thomas G. Lane88aeed41992-12-10 00:00:00 +000055.B \-optimize
Thomas G. Lanebd543f01991-12-13 00:00:00 +000056usually makes the JPEG file a little smaller, but
57.B cjpeg
Thomas G. Lane4a6b7301992-03-17 00:00:00 +000058runs somewhat slower and needs much more memory. Image quality and speed of
59decompression are unaffected by
Thomas G. Lane88aeed41992-12-10 00:00:00 +000060.BR \-optimize .
Thomas G. Lanebd543f01991-12-13 00:00:00 +000061.TP
Thomas G. Lanebc79e061995-08-02 00:00:00 +000062.B \-progressive
63Create progressive JPEG file (see below).
64.TP
Thomas G. Lane88aeed41992-12-10 00:00:00 +000065.B \-targa
Thomas G. Lanebd543f01991-12-13 00:00:00 +000066Input file is Targa format. Targa files that contain an "identification"
67field will not be automatically recognized by
68.BR cjpeg ;
69for such files you must specify
Thomas G. Lane88aeed41992-12-10 00:00:00 +000070.B \-targa
71to make
Thomas G. Lanebd543f01991-12-13 00:00:00 +000072.B cjpeg
Thomas G. Lane88aeed41992-12-10 00:00:00 +000073treat the input as Targa format.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000074For most Targa files, you won't need this switch.
Thomas G. Lanebd543f01991-12-13 00:00:00 +000075.PP
76The
Thomas G. Lane88aeed41992-12-10 00:00:00 +000077.B \-quality
Thomas G. Lanebd543f01991-12-13 00:00:00 +000078switch lets you trade off compressed file size against quality of the
Thomas G. Lane88aeed41992-12-10 00:00:00 +000079reconstructed image: the higher the quality setting, the larger the JPEG file,
80and the closer the output image will be to the original input. Normally you
81want to use the lowest quality setting (smallest file) that decompresses into
82something visually indistinguishable from the original image. For this
83purpose the quality setting should be between 50 and 95; the default of 75 is
84often about right. If you see defects at
85.B \-quality
Thomas G. Lanebd543f01991-12-13 00:00:00 +00008675, then go up 5 or 10 counts at a time until you are happy with the output
87image. (The optimal setting will vary from one image to another.)
88.PP
Thomas G. Lane88aeed41992-12-10 00:00:00 +000089.B \-quality
Thomas G. Lanebc79e061995-08-02 00:00:00 +000090100 will generate a quantization table of all 1's, minimizing loss in the
Thomas G. Lanebd543f01991-12-13 00:00:00 +000091quantization step (but there is still information loss in subsampling, as well
92as roundoff error). This setting is mainly of interest for experimental
Thomas G. Lane88aeed41992-12-10 00:00:00 +000093purposes. Quality values above about 95 are
Thomas G. Lanebd543f01991-12-13 00:00:00 +000094.B not
95recommended for normal use; the compressed file size goes up dramatically for
96hardly any gain in output image quality.
97.PP
Thomas G. Lane88aeed41992-12-10 00:00:00 +000098In the other direction, quality values below 50 will produce very small files
99of low image quality. Settings around 5 to 10 might be useful in preparing an
100index of a large image library, for example. Try
101.B \-quality
1022 (or so) for some amusing Cubist effects. (Note: quality
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000103values below about 25 generate 2-byte quantization tables, which are
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000104considered optional in the JPEG standard.
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000105.B cjpeg
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000106emits a warning message when you give such a quality value, because some
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000107other JPEG programs may be unable to decode the resulting file. Use
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000108.B \-baseline
109if you need to ensure compatibility at low quality values.)
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000110.PP
DRC39ea5622010-10-12 01:55:31 +0000111The \fB-quality\fR option has been extended in this version of \fBcjpeg\fR to
112support separate quality settings for luminance and chrominance (or, in
113general, separate settings for every quantization table slot.) The principle
114is the same as chrominance subsampling: since the human eye is more sensitive
115to spatial changes in brightness than spatial changes in color, the chrominance
116components can be quantized more than the luminance components without
117incurring any visible image quality loss. However, unlike subsampling, this
118feature reduces data in the frequency domain instead of the spatial domain,
119which allows for more fine-grained control. This option is useful in
120quality-sensitive applications, for which the artifacts generated by
121subsampling may be unacceptable.
122.PP
123The \fB-quality\fR option accepts a comma-separated list of parameters, which
DRCccd1bfd2012-01-31 09:53:46 +0000124respectively refer to the quality levels that should be assigned to the
DRC39ea5622010-10-12 01:55:31 +0000125quantization table slots. If there are more q-table slots than parameters,
126then the last parameter is replicated. Thus, if only one quality parameter is
127given, this is used for both luminance and chrominance (slots 0 and 1,
128respectively), preserving the legacy behavior of cjpeg v6b and prior.
129More (or customized) quantization tables can be set with the \fB-qtables\fR
130option and assigned to components with the \fB-qslots\fR option (see the
131"wizard" switches below.)
132.PP
133JPEG files generated with separate luminance and chrominance quality are fully
134compliant with standard JPEG decoders.
135.PP
136.BR CAUTION:
137For this setting to be useful, be sure to pass an argument of \fB-sample 1x1\fR
138to \fBcjpeg\fR to disable chrominance subsampling. Otherwise, the default
139subsampling level (2x2, AKA "4:2:0") will be used.
Guido Vollbeding5996a252009-06-27 00:00:00 +0000140.PP
141The
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000142.B \-progressive
143switch creates a "progressive JPEG" file. In this type of JPEG file, the data
144is stored in multiple scans of increasing quality. If the file is being
145transmitted over a slow communications link, the decoder can use the first
146scan to display a low-quality image very quickly, and can then improve the
147display with each subsequent scan. The final image is exactly equivalent to a
148standard JPEG file of the same quality setting, and the total file size is
149about the same --- often a little smaller.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000150.PP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000151Switches for advanced users:
152.TP
DRCd657ba62012-01-27 09:41:20 +0000153.B \-arithmetic
154Use arithmetic coding.
155.B Caution:
156arithmetic coded JPEG is not yet widely implemented, so many decoders will be
157unable to view an arithmetic coded JPEG file at all.
158.TP
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000159.B \-dct int
160Use integer DCT method (default).
161.TP
162.B \-dct fast
163Use fast integer DCT (less accurate).
164.TP
165.B \-dct float
166Use floating-point DCT method.
Thomas G. Lanea8b67c41995-03-15 00:00:00 +0000167The float method is very slightly more accurate than the int method, but is
168much slower unless your machine has very fast floating-point hardware. Also
169note that results of the floating-point method may vary slightly across
170machines, while the integer methods should give the same results everywhere.
171The fast integer method is much less accurate than the other two.
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000172.TP
173.BI \-restart " N"
174Emit a JPEG restart marker every N MCU rows, or every N MCU blocks if "B" is
175attached to the number.
176.B \-restart 0
177(the default) means no restart markers.
178.TP
179.BI \-smooth " N"
180Smooth the input image to eliminate dithering noise. N, ranging from 1 to
181100, indicates the strength of smoothing. 0 (the default) means no smoothing.
182.TP
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000183.BI \-maxmemory " N"
184Set limit for amount of memory to use in processing large images. Value is
185in thousands of bytes, or millions of bytes if "M" is attached to the
186number. For example,
187.B \-max 4m
188selects 4000000 bytes. If more space is needed, temporary files will be used.
189.TP
190.BI \-outfile " name"
191Send output image to the named file, not to standard output.
192.TP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000193.B \-verbose
194Enable debug printout. More
195.BR \-v 's
196give more output. Also, version information is printed at startup.
197.TP
198.B \-debug
199Same as
200.BR \-verbose .
201.PP
202The
203.B \-restart
204option inserts extra markers that allow a JPEG decoder to resynchronize after
205a transmission error. Without restart markers, any damage to a compressed
206file will usually ruin the image from the point of the error to the end of the
207image; with restart markers, the damage is usually confined to the portion of
208the image up to the next restart marker. Of course, the restart markers
209occupy extra space. We recommend
210.B \-restart 1
211for images that will be transmitted across unreliable networks such as Usenet.
212.PP
213The
214.B \-smooth
215option filters the input to eliminate fine-scale noise. This is often useful
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000216when converting dithered images to JPEG: a moderate smoothing factor of 10 to
21750 gets rid of dithering patterns in the input file, resulting in a smaller
218JPEG file and a better-looking image. Too large a smoothing factor will
219visibly blur the image, however.
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000220.PP
221Switches for wizards:
222.TP
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000223.B \-baseline
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000224Force baseline-compatible quantization tables to be generated. This clamps
225quantization values to 8 bits even at low quality settings. (This switch is
226poorly named, since it does not ensure that the output is actually baseline
227JPEG. For example, you can use
228.B \-baseline
229and
230.B \-progressive
231together.)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000232.TP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000233.BI \-qtables " file"
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000234Use the quantization tables given in the specified text file.
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000235.TP
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000236.BI \-qslots " N[,...]"
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000237Select which quantization table to use for each color component.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000238.TP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000239.BI \-sample " HxV[,...]"
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000240Set JPEG sampling factors for each color component.
241.TP
242.BI \-scans " file"
243Use the scan script given in the specified text file.
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000244.PP
245The "wizard" switches are intended for experimentation with JPEG. If you
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000246don't know what you are doing, \fBdon't use them\fR. These switches are
Guido Vollbeding5996a252009-06-27 00:00:00 +0000247documented further in the file wizard.txt.
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000248.SH EXAMPLES
249.LP
250This example compresses the PPM file foo.ppm with a quality factor of
25160 and saves the output as foo.jpg:
252.IP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000253.B cjpeg \-quality
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000254.I 60 foo.ppm
255.B >
256.I foo.jpg
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000257.SH HINTS
258Color GIF files are not the ideal input for JPEG; JPEG is really intended for
259compressing full-color (24-bit) images. In particular, don't try to convert
260cartoons, line drawings, and other images that have only a few distinct
261colors. GIF works great on these, JPEG does not. If you want to convert a
262GIF to JPEG, you should experiment with
263.BR cjpeg 's
264.B \-quality
265and
266.B \-smooth
267options to get a satisfactory conversion.
268.B \-smooth 10
269or so is often helpful.
270.PP
271Avoid running an image through a series of JPEG compression/decompression
272cycles. Image quality loss will accumulate; after ten or so cycles the image
273may be noticeably worse than it was after one cycle. It's best to use a
274lossless format while manipulating an image, then convert to JPEG format when
275you are ready to file the image away.
276.PP
277The
278.B \-optimize
279option to
280.B cjpeg
281is worth using when you are making a "final" version for posting or archiving.
282It's also a win when you are using low quality settings to make very small
283JPEG files; the percentage improvement is often a lot more than it is on
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000284larger files. (At present,
285.B \-optimize
286mode is always selected when generating progressive JPEG files.)
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000287.SH ENVIRONMENT
288.TP
289.B JPEGMEM
290If this environment variable is set, its value is the default memory limit.
291The value is specified as described for the
292.B \-maxmemory
293switch.
294.B JPEGMEM
295overrides the default value specified when the program was compiled, and
296itself is overridden by an explicit
297.BR \-maxmemory .
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000298.SH SEE ALSO
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000299.BR djpeg (1),
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000300.BR jpegtran (1),
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000301.BR rdjpgcom (1),
302.BR wrjpgcom (1)
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000303.br
Thomas G. Lane4a6b7301992-03-17 00:00:00 +0000304.BR ppm (5),
305.BR pgm (5)
306.br
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000307Wallace, Gregory K. "The JPEG Still Picture Compression Standard",
308Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
309.SH AUTHOR
310Independent JPEG Group
DRCcf763c02013-01-01 09:51:37 +0000311.PP
312This file was modified by The libjpeg-turbo Project to include only information
313relevant to libjpeg-turbo and to wordsmith certain sections.
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000314.SH BUGS
DRC39ea5622010-10-12 01:55:31 +0000315Support for GIF input files was removed in cjpeg v6b due to concerns over
316the Unisys LZW patent. Although this patent expired in 2006, cjpeg still
317lacks GIF support, for these historical reasons. (Conversion of GIF files to
318JPEG is usually a bad idea anyway.)
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000319.PP
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000320Not all variants of BMP and Targa file formats are supported.
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000321.PP
322The
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000323.B \-targa
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000324switch is not a bug, it's a feature. (It would be a bug if the Targa format
325designers had not been clueless.)