blob: e338c80c15de2fe1a7690bf73eeb968925242036 [file] [log] [blame]
DRC9665f5e2014-11-22 04:04:38 +00001.TH CJPEG 1 "21 November 2014"
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
DRC90d6c382014-05-12 09:08:39 +000019format), PGM (PBMPLUS grayscale 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
Guido Vollbeding5829cb22012-01-15 00:00:00 +000052.B \-rgb
53Create RGB JPEG file.
54Using this switch suppresses the conversion from RGB
55colorspace input to the default YCbCr JPEG colorspace.
Guido Vollbeding5829cb22012-01-15 00:00:00 +000056.TP
Thomas G. Lane88aeed41992-12-10 00:00:00 +000057.B \-optimize
Thomas G. Lanebd543f01991-12-13 00:00:00 +000058Perform optimization of entropy encoding parameters. Without this, default
59encoding parameters are used.
Thomas G. Lane88aeed41992-12-10 00:00:00 +000060.B \-optimize
Thomas G. Lanebd543f01991-12-13 00:00:00 +000061usually makes the JPEG file a little smaller, but
62.B cjpeg
Thomas G. Lane4a6b7301992-03-17 00:00:00 +000063runs somewhat slower and needs much more memory. Image quality and speed of
64decompression are unaffected by
Thomas G. Lane88aeed41992-12-10 00:00:00 +000065.BR \-optimize .
Thomas G. Lanebd543f01991-12-13 00:00:00 +000066.TP
Thomas G. Lanebc79e061995-08-02 00:00:00 +000067.B \-progressive
68Create progressive JPEG file (see below).
69.TP
Thomas G. Lane88aeed41992-12-10 00:00:00 +000070.B \-targa
Thomas G. Lanebd543f01991-12-13 00:00:00 +000071Input file is Targa format. Targa files that contain an "identification"
72field will not be automatically recognized by
73.BR cjpeg ;
74for such files you must specify
Thomas G. Lane88aeed41992-12-10 00:00:00 +000075.B \-targa
76to make
Thomas G. Lanebd543f01991-12-13 00:00:00 +000077.B cjpeg
Thomas G. Lane88aeed41992-12-10 00:00:00 +000078treat the input as Targa format.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000079For most Targa files, you won't need this switch.
Thomas G. Lanebd543f01991-12-13 00:00:00 +000080.PP
81The
Thomas G. Lane88aeed41992-12-10 00:00:00 +000082.B \-quality
Thomas G. Lanebd543f01991-12-13 00:00:00 +000083switch lets you trade off compressed file size against quality of the
Thomas G. Lane88aeed41992-12-10 00:00:00 +000084reconstructed image: the higher the quality setting, the larger the JPEG file,
85and the closer the output image will be to the original input. Normally you
86want to use the lowest quality setting (smallest file) that decompresses into
87something visually indistinguishable from the original image. For this
88purpose the quality setting should be between 50 and 95; the default of 75 is
89often about right. If you see defects at
90.B \-quality
Thomas G. Lanebd543f01991-12-13 00:00:00 +00009175, then go up 5 or 10 counts at a time until you are happy with the output
92image. (The optimal setting will vary from one image to another.)
93.PP
Thomas G. Lane88aeed41992-12-10 00:00:00 +000094.B \-quality
Thomas G. Lanebc79e061995-08-02 00:00:00 +000095100 will generate a quantization table of all 1's, minimizing loss in the
Thomas G. Lanebd543f01991-12-13 00:00:00 +000096quantization step (but there is still information loss in subsampling, as well
97as roundoff error). This setting is mainly of interest for experimental
Thomas G. Lane88aeed41992-12-10 00:00:00 +000098purposes. Quality values above about 95 are
Thomas G. Lanebd543f01991-12-13 00:00:00 +000099.B not
100recommended for normal use; the compressed file size goes up dramatically for
101hardly any gain in output image quality.
102.PP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000103In the other direction, quality values below 50 will produce very small files
104of low image quality. Settings around 5 to 10 might be useful in preparing an
105index of a large image library, for example. Try
106.B \-quality
1072 (or so) for some amusing Cubist effects. (Note: quality
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000108values below about 25 generate 2-byte quantization tables, which are
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000109considered optional in the JPEG standard.
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000110.B cjpeg
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000111emits a warning message when you give such a quality value, because some
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000112other JPEG programs may be unable to decode the resulting file. Use
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000113.B \-baseline
114if you need to ensure compatibility at low quality values.)
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000115.PP
DRC39ea5622010-10-12 01:55:31 +0000116The \fB-quality\fR option has been extended in this version of \fBcjpeg\fR to
117support separate quality settings for luminance and chrominance (or, in
118general, separate settings for every quantization table slot.) The principle
119is the same as chrominance subsampling: since the human eye is more sensitive
120to spatial changes in brightness than spatial changes in color, the chrominance
121components can be quantized more than the luminance components without
122incurring any visible image quality loss. However, unlike subsampling, this
123feature reduces data in the frequency domain instead of the spatial domain,
124which allows for more fine-grained control. This option is useful in
125quality-sensitive applications, for which the artifacts generated by
126subsampling may be unacceptable.
127.PP
128The \fB-quality\fR option accepts a comma-separated list of parameters, which
DRCccd1bfd2012-01-31 09:53:46 +0000129respectively refer to the quality levels that should be assigned to the
DRC39ea5622010-10-12 01:55:31 +0000130quantization table slots. If there are more q-table slots than parameters,
131then the last parameter is replicated. Thus, if only one quality parameter is
132given, this is used for both luminance and chrominance (slots 0 and 1,
133respectively), preserving the legacy behavior of cjpeg v6b and prior.
134More (or customized) quantization tables can be set with the \fB-qtables\fR
135option and assigned to components with the \fB-qslots\fR option (see the
136"wizard" switches below.)
137.PP
138JPEG files generated with separate luminance and chrominance quality are fully
139compliant with standard JPEG decoders.
140.PP
141.BR CAUTION:
142For this setting to be useful, be sure to pass an argument of \fB-sample 1x1\fR
143to \fBcjpeg\fR to disable chrominance subsampling. Otherwise, the default
144subsampling level (2x2, AKA "4:2:0") will be used.
Guido Vollbeding5996a252009-06-27 00:00:00 +0000145.PP
146The
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000147.B \-progressive
148switch creates a "progressive JPEG" file. In this type of JPEG file, the data
149is stored in multiple scans of increasing quality. If the file is being
150transmitted over a slow communications link, the decoder can use the first
151scan to display a low-quality image very quickly, and can then improve the
152display with each subsequent scan. The final image is exactly equivalent to a
153standard JPEG file of the same quality setting, and the total file size is
154about the same --- often a little smaller.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000155.PP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000156Switches for advanced users:
157.TP
DRCd657ba62012-01-27 09:41:20 +0000158.B \-arithmetic
159Use arithmetic coding.
160.B Caution:
161arithmetic coded JPEG is not yet widely implemented, so many decoders will be
162unable to view an arithmetic coded JPEG file at all.
163.TP
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000164.B \-dct int
165Use integer DCT method (default).
166.TP
167.B \-dct fast
168Use fast integer DCT (less accurate).
DRC8940e6c2014-05-11 09:46:28 +0000169In libjpeg-turbo, the fast method is generally about 5-15% faster than the int
170method when using the x86/x86-64 SIMD extensions (results may vary with other
171SIMD implementations, or when using libjpeg-turbo without SIMD extensions.)
172For quality levels of 90 and below, there should be little or no perceptible
173difference between the two algorithms. For quality levels above 90, however,
174the difference between the fast and the int methods becomes more pronounced.
175With quality=97, for instance, the fast method incurs generally about a 1-3 dB
176loss (in PSNR) relative to the int method, but this can be larger for some
177images. Do not use the fast method with quality levels above 97. The
178algorithm often degenerates at quality=98 and above and can actually produce a
DRC05524e62014-05-11 23:14:43 +0000179more lossy image than if lower quality levels had been used. Also, in
180libjpeg-turbo, the fast method is not fully accelerated for quality levels
181above 97, so it will be slower than the int method.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000182.TP
183.B \-dct float
184Use floating-point DCT method.
DRC05524e62014-05-11 23:14:43 +0000185The float method is mainly a legacy feature. It does not produce significantly
DRC8940e6c2014-05-11 09:46:28 +0000186more accurate results than the int method, and it is much slower. The float
187method may also give different results on different machines due to varying
188roundoff behavior, whereas the integer methods should give the same results on
189all machines.
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000190.TP
191.BI \-restart " N"
192Emit a JPEG restart marker every N MCU rows, or every N MCU blocks if "B" is
193attached to the number.
194.B \-restart 0
195(the default) means no restart markers.
196.TP
197.BI \-smooth " N"
198Smooth the input image to eliminate dithering noise. N, ranging from 1 to
199100, indicates the strength of smoothing. 0 (the default) means no smoothing.
200.TP
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000201.BI \-maxmemory " N"
202Set limit for amount of memory to use in processing large images. Value is
203in thousands of bytes, or millions of bytes if "M" is attached to the
204number. For example,
205.B \-max 4m
206selects 4000000 bytes. If more space is needed, temporary files will be used.
207.TP
208.BI \-outfile " name"
209Send output image to the named file, not to standard output.
210.TP
DRCab706232013-01-18 23:42:31 +0000211.BI \-memdst
212Compress to memory instead of a file. This feature was implemented mainly as a
213way of testing the in-memory destination manager (jpeg_mem_dest()), but it is
214also useful for benchmarking, since it reduces the I/O overhead.
215.TP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000216.B \-verbose
217Enable debug printout. More
218.BR \-v 's
219give more output. Also, version information is printed at startup.
220.TP
221.B \-debug
222Same as
223.BR \-verbose .
DRC9665f5e2014-11-22 04:04:38 +0000224.TP
225.B \-version
226Print version information and exit.
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000227.PP
228The
229.B \-restart
230option inserts extra markers that allow a JPEG decoder to resynchronize after
231a transmission error. Without restart markers, any damage to a compressed
232file will usually ruin the image from the point of the error to the end of the
233image; with restart markers, the damage is usually confined to the portion of
234the image up to the next restart marker. Of course, the restart markers
235occupy extra space. We recommend
236.B \-restart 1
237for images that will be transmitted across unreliable networks such as Usenet.
238.PP
239The
240.B \-smooth
241option filters the input to eliminate fine-scale noise. This is often useful
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000242when converting dithered images to JPEG: a moderate smoothing factor of 10 to
24350 gets rid of dithering patterns in the input file, resulting in a smaller
244JPEG file and a better-looking image. Too large a smoothing factor will
245visibly blur the image, however.
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000246.PP
247Switches for wizards:
248.TP
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000249.B \-baseline
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000250Force baseline-compatible quantization tables to be generated. This clamps
251quantization values to 8 bits even at low quality settings. (This switch is
252poorly named, since it does not ensure that the output is actually baseline
253JPEG. For example, you can use
254.B \-baseline
255and
256.B \-progressive
257together.)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000258.TP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000259.BI \-qtables " file"
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000260Use the quantization tables given in the specified text file.
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000261.TP
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000262.BI \-qslots " N[,...]"
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000263Select which quantization table to use for each color component.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000264.TP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000265.BI \-sample " HxV[,...]"
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000266Set JPEG sampling factors for each color component.
267.TP
268.BI \-scans " file"
269Use the scan script given in the specified text file.
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000270.PP
271The "wizard" switches are intended for experimentation with JPEG. If you
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000272don't know what you are doing, \fBdon't use them\fR. These switches are
Guido Vollbeding5996a252009-06-27 00:00:00 +0000273documented further in the file wizard.txt.
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000274.SH EXAMPLES
275.LP
276This example compresses the PPM file foo.ppm with a quality factor of
27760 and saves the output as foo.jpg:
278.IP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000279.B cjpeg \-quality
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000280.I 60 foo.ppm
281.B >
282.I foo.jpg
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000283.SH HINTS
284Color GIF files are not the ideal input for JPEG; JPEG is really intended for
285compressing full-color (24-bit) images. In particular, don't try to convert
286cartoons, line drawings, and other images that have only a few distinct
287colors. GIF works great on these, JPEG does not. If you want to convert a
288GIF to JPEG, you should experiment with
289.BR cjpeg 's
290.B \-quality
291and
292.B \-smooth
293options to get a satisfactory conversion.
294.B \-smooth 10
295or so is often helpful.
296.PP
297Avoid running an image through a series of JPEG compression/decompression
298cycles. Image quality loss will accumulate; after ten or so cycles the image
299may be noticeably worse than it was after one cycle. It's best to use a
300lossless format while manipulating an image, then convert to JPEG format when
301you are ready to file the image away.
302.PP
303The
304.B \-optimize
305option to
306.B cjpeg
307is worth using when you are making a "final" version for posting or archiving.
308It's also a win when you are using low quality settings to make very small
309JPEG files; the percentage improvement is often a lot more than it is on
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000310larger files. (At present,
311.B \-optimize
312mode is always selected when generating progressive JPEG files.)
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000313.SH ENVIRONMENT
314.TP
315.B JPEGMEM
316If this environment variable is set, its value is the default memory limit.
317The value is specified as described for the
318.B \-maxmemory
319switch.
320.B JPEGMEM
321overrides the default value specified when the program was compiled, and
322itself is overridden by an explicit
323.BR \-maxmemory .
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000324.SH SEE ALSO
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000325.BR djpeg (1),
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000326.BR jpegtran (1),
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000327.BR rdjpgcom (1),
328.BR wrjpgcom (1)
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000329.br
Thomas G. Lane4a6b7301992-03-17 00:00:00 +0000330.BR ppm (5),
331.BR pgm (5)
332.br
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000333Wallace, Gregory K. "The JPEG Still Picture Compression Standard",
334Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
335.SH AUTHOR
336Independent JPEG Group
DRCcf763c02013-01-01 09:51:37 +0000337.PP
338This file was modified by The libjpeg-turbo Project to include only information
DRCab706232013-01-18 23:42:31 +0000339relevant to libjpeg-turbo, to wordsmith certain sections, and to describe
340features not present in libjpeg.
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000341.SH BUGS
DRC39ea5622010-10-12 01:55:31 +0000342Support for GIF input files was removed in cjpeg v6b due to concerns over
343the Unisys LZW patent. Although this patent expired in 2006, cjpeg still
344lacks GIF support, for these historical reasons. (Conversion of GIF files to
345JPEG is usually a bad idea anyway.)
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000346.PP
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000347Not all variants of BMP and Targa file formats are supported.
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000348.PP
349The
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000350.B \-targa
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000351switch is not a bug, it's a feature. (It would be a bug if the Targa format
352designers had not been clueless.)