blob: d175a961c6a9c0f3f0884f20bf29b7ad165ad31b [file] [log] [blame]
Thomas G. Lane5ead57a1998-03-27 00:00:00 +00001.TH CJPEG 1 "20 March 1998"
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
Thomas G. Lane88aeed41992-12-10 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
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000111The
112.B \-progressive
113switch creates a "progressive JPEG" file. In this type of JPEG file, the data
114is stored in multiple scans of increasing quality. If the file is being
115transmitted over a slow communications link, the decoder can use the first
116scan to display a low-quality image very quickly, and can then improve the
117display with each subsequent scan. The final image is exactly equivalent to a
118standard JPEG file of the same quality setting, and the total file size is
119about the same --- often a little smaller.
120.B Caution:
121progressive JPEG is not yet widely implemented, so many decoders will be
122unable to view a progressive JPEG file at all.
123.PP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000124Switches for advanced users:
125.TP
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000126.B \-dct int
127Use integer DCT method (default).
128.TP
129.B \-dct fast
130Use fast integer DCT (less accurate).
131.TP
132.B \-dct float
133Use floating-point DCT method.
Thomas G. Lanea8b67c41995-03-15 00:00:00 +0000134The float method is very slightly more accurate than the int method, but is
135much slower unless your machine has very fast floating-point hardware. Also
136note that results of the floating-point method may vary slightly across
137machines, while the integer methods should give the same results everywhere.
138The fast integer method is much less accurate than the other two.
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000139.TP
140.BI \-restart " N"
141Emit a JPEG restart marker every N MCU rows, or every N MCU blocks if "B" is
142attached to the number.
143.B \-restart 0
144(the default) means no restart markers.
145.TP
146.BI \-smooth " N"
147Smooth the input image to eliminate dithering noise. N, ranging from 1 to
148100, indicates the strength of smoothing. 0 (the default) means no smoothing.
149.TP
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000150.BI \-maxmemory " N"
151Set limit for amount of memory to use in processing large images. Value is
152in thousands of bytes, or millions of bytes if "M" is attached to the
153number. For example,
154.B \-max 4m
155selects 4000000 bytes. If more space is needed, temporary files will be used.
156.TP
157.BI \-outfile " name"
158Send output image to the named file, not to standard output.
159.TP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000160.B \-verbose
161Enable debug printout. More
162.BR \-v 's
163give more output. Also, version information is printed at startup.
164.TP
165.B \-debug
166Same as
167.BR \-verbose .
168.PP
169The
170.B \-restart
171option inserts extra markers that allow a JPEG decoder to resynchronize after
172a transmission error. Without restart markers, any damage to a compressed
173file will usually ruin the image from the point of the error to the end of the
174image; with restart markers, the damage is usually confined to the portion of
175the image up to the next restart marker. Of course, the restart markers
176occupy extra space. We recommend
177.B \-restart 1
178for images that will be transmitted across unreliable networks such as Usenet.
179.PP
180The
181.B \-smooth
182option filters the input to eliminate fine-scale noise. This is often useful
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000183when converting dithered images to JPEG: a moderate smoothing factor of 10 to
18450 gets rid of dithering patterns in the input file, resulting in a smaller
185JPEG file and a better-looking image. Too large a smoothing factor will
186visibly blur the image, however.
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000187.PP
188Switches for wizards:
189.TP
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000190.B \-baseline
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000191Force baseline-compatible quantization tables to be generated. This clamps
192quantization values to 8 bits even at low quality settings. (This switch is
193poorly named, since it does not ensure that the output is actually baseline
194JPEG. For example, you can use
195.B \-baseline
196and
197.B \-progressive
198together.)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000199.TP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000200.BI \-qtables " file"
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000201Use the quantization tables given in the specified text file.
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000202.TP
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000203.BI \-qslots " N[,...]"
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000204Select which quantization table to use for each color component.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000205.TP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000206.BI \-sample " HxV[,...]"
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000207Set JPEG sampling factors for each color component.
208.TP
209.BI \-scans " file"
210Use the scan script given in the specified text file.
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000211.PP
212The "wizard" switches are intended for experimentation with JPEG. If you
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000213don't know what you are doing, \fBdon't use them\fR. These switches are
214documented further in the file wizard.doc.
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000215.SH EXAMPLES
216.LP
217This example compresses the PPM file foo.ppm with a quality factor of
21860 and saves the output as foo.jpg:
219.IP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000220.B cjpeg \-quality
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000221.I 60 foo.ppm
222.B >
223.I foo.jpg
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000224.SH HINTS
225Color GIF files are not the ideal input for JPEG; JPEG is really intended for
226compressing full-color (24-bit) images. In particular, don't try to convert
227cartoons, line drawings, and other images that have only a few distinct
228colors. GIF works great on these, JPEG does not. If you want to convert a
229GIF to JPEG, you should experiment with
230.BR cjpeg 's
231.B \-quality
232and
233.B \-smooth
234options to get a satisfactory conversion.
235.B \-smooth 10
236or so is often helpful.
237.PP
238Avoid running an image through a series of JPEG compression/decompression
239cycles. Image quality loss will accumulate; after ten or so cycles the image
240may be noticeably worse than it was after one cycle. It's best to use a
241lossless format while manipulating an image, then convert to JPEG format when
242you are ready to file the image away.
243.PP
244The
245.B \-optimize
246option to
247.B cjpeg
248is worth using when you are making a "final" version for posting or archiving.
249It's also a win when you are using low quality settings to make very small
250JPEG files; the percentage improvement is often a lot more than it is on
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000251larger files. (At present,
252.B \-optimize
253mode is always selected when generating progressive JPEG files.)
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000254.SH ENVIRONMENT
255.TP
256.B JPEGMEM
257If this environment variable is set, its value is the default memory limit.
258The value is specified as described for the
259.B \-maxmemory
260switch.
261.B JPEGMEM
262overrides the default value specified when the program was compiled, and
263itself is overridden by an explicit
264.BR \-maxmemory .
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000265.SH SEE ALSO
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000266.BR djpeg (1),
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000267.BR jpegtran (1),
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000268.BR rdjpgcom (1),
269.BR wrjpgcom (1)
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000270.br
Thomas G. Lane4a6b7301992-03-17 00:00:00 +0000271.BR ppm (5),
272.BR pgm (5)
273.br
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000274Wallace, Gregory K. "The JPEG Still Picture Compression Standard",
275Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
276.SH AUTHOR
277Independent JPEG Group
278.SH BUGS
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000279Arithmetic coding is not supported for legal reasons.
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000280.PP
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000281GIF input files are no longer supported, to avoid the Unisys LZW patent.
282Use a Unisys-licensed program if you need to read a GIF file. (Conversion
283of GIF files to JPEG is usually a bad idea anyway.)
284.PP
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000285Not all variants of BMP and Targa file formats are supported.
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000286.PP
287The
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000288.B \-targa
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000289switch is not a bug, it's a feature. (It would be a bug if the Targa format
290designers had not been clueless.)
291.PP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000292Still not as fast as we'd like.