blob: a3e47babd4611991e6b5f1f897f3b49fd17b593d [file] [log] [blame]
Leon Scroggins IIIbd7903e2018-02-28 14:05:04 -05001.TH CJPEG 1 "18 March 2017"
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
Leon Scroggins III3993b372018-07-16 10:43:45 -040049.BR \-grayscale,
Thomas G. Lane88aeed41992-12-10 00:00:00 +000050you'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
Alex Naidis6eb7d372016-10-16 23:10:08 +020088purpose the quality setting should generally be between 50 and 95 (the default
89is 75) for photographic images. If you see defects at
Thomas G. Lane88aeed41992-12-10 00:00:00 +000090.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
Alex Naidis6eb7d372016-10-16 23:10:08 +020097as roundoff error.) For most images, specifying a quality value above
98about 95 will increase the size of the compressed file dramatically, and while
99the quality gain from these higher quality values is measurable (using metrics
100such as PSNR or SSIM), it is rarely perceivable by human vision.
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000101.PP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000102In the other direction, quality values below 50 will produce very small files
103of low image quality. Settings around 5 to 10 might be useful in preparing an
104index of a large image library, for example. Try
105.B \-quality
1062 (or so) for some amusing Cubist effects. (Note: quality
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000107values below about 25 generate 2-byte quantization tables, which are
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000108considered optional in the JPEG standard.
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000109.B cjpeg
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000110emits a warning message when you give such a quality value, because some
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000111other JPEG programs may be unable to decode the resulting file. Use
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000112.B \-baseline
113if you need to ensure compatibility at low quality values.)
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000114.PP
DRC39ea5622010-10-12 01:55:31 +0000115The \fB-quality\fR option has been extended in this version of \fBcjpeg\fR to
116support separate quality settings for luminance and chrominance (or, in
117general, separate settings for every quantization table slot.) The principle
118is the same as chrominance subsampling: since the human eye is more sensitive
119to spatial changes in brightness than spatial changes in color, the chrominance
120components can be quantized more than the luminance components without
121incurring any visible image quality loss. However, unlike subsampling, this
122feature reduces data in the frequency domain instead of the spatial domain,
123which allows for more fine-grained control. This option is useful in
124quality-sensitive applications, for which the artifacts generated by
125subsampling may be unacceptable.
126.PP
127The \fB-quality\fR option accepts a comma-separated list of parameters, which
DRCccd1bfd2012-01-31 09:53:46 +0000128respectively refer to the quality levels that should be assigned to the
DRC39ea5622010-10-12 01:55:31 +0000129quantization table slots. If there are more q-table slots than parameters,
130then the last parameter is replicated. Thus, if only one quality parameter is
131given, this is used for both luminance and chrominance (slots 0 and 1,
132respectively), preserving the legacy behavior of cjpeg v6b and prior.
133More (or customized) quantization tables can be set with the \fB-qtables\fR
134option and assigned to components with the \fB-qslots\fR option (see the
135"wizard" switches below.)
136.PP
137JPEG files generated with separate luminance and chrominance quality are fully
138compliant with standard JPEG decoders.
139.PP
140.BR CAUTION:
141For this setting to be useful, be sure to pass an argument of \fB-sample 1x1\fR
142to \fBcjpeg\fR to disable chrominance subsampling. Otherwise, the default
143subsampling level (2x2, AKA "4:2:0") will be used.
Guido Vollbeding5996a252009-06-27 00:00:00 +0000144.PP
145The
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000146.B \-progressive
147switch creates a "progressive JPEG" file. In this type of JPEG file, the data
148is stored in multiple scans of increasing quality. If the file is being
149transmitted over a slow communications link, the decoder can use the first
150scan to display a low-quality image very quickly, and can then improve the
151display with each subsequent scan. The final image is exactly equivalent to a
152standard JPEG file of the same quality setting, and the total file size is
153about the same --- often a little smaller.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000154.PP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000155Switches for advanced users:
156.TP
DRCd657ba62012-01-27 09:41:20 +0000157.B \-arithmetic
158Use arithmetic coding.
159.B Caution:
160arithmetic coded JPEG is not yet widely implemented, so many decoders will be
161unable to view an arithmetic coded JPEG file at all.
162.TP
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000163.B \-dct int
164Use integer DCT method (default).
165.TP
166.B \-dct fast
167Use fast integer DCT (less accurate).
DRC8940e6c2014-05-11 09:46:28 +0000168In libjpeg-turbo, the fast method is generally about 5-15% faster than the int
169method when using the x86/x86-64 SIMD extensions (results may vary with other
170SIMD implementations, or when using libjpeg-turbo without SIMD extensions.)
171For quality levels of 90 and below, there should be little or no perceptible
172difference between the two algorithms. For quality levels above 90, however,
173the difference between the fast and the int methods becomes more pronounced.
174With quality=97, for instance, the fast method incurs generally about a 1-3 dB
175loss (in PSNR) relative to the int method, but this can be larger for some
176images. Do not use the fast method with quality levels above 97. The
177algorithm often degenerates at quality=98 and above and can actually produce a
DRC05524e62014-05-11 23:14:43 +0000178more lossy image than if lower quality levels had been used. Also, in
179libjpeg-turbo, the fast method is not fully accelerated for quality levels
180above 97, so it will be slower than the int method.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000181.TP
182.B \-dct float
183Use floating-point DCT method.
DRC05524e62014-05-11 23:14:43 +0000184The float method is mainly a legacy feature. It does not produce significantly
DRC8940e6c2014-05-11 09:46:28 +0000185more accurate results than the int method, and it is much slower. The float
186method may also give different results on different machines due to varying
187roundoff behavior, whereas the integer methods should give the same results on
188all machines.
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000189.TP
Leon Scroggins III3993b372018-07-16 10:43:45 -0400190.BI \-icc " file"
191Embed ICC color management profile contained in the specified file.
192.TP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000193.BI \-restart " N"
194Emit a JPEG restart marker every N MCU rows, or every N MCU blocks if "B" is
195attached to the number.
196.B \-restart 0
197(the default) means no restart markers.
198.TP
199.BI \-smooth " N"
200Smooth the input image to eliminate dithering noise. N, ranging from 1 to
201100, indicates the strength of smoothing. 0 (the default) means no smoothing.
202.TP
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000203.BI \-maxmemory " N"
204Set limit for amount of memory to use in processing large images. Value is
205in thousands of bytes, or millions of bytes if "M" is attached to the
206number. For example,
207.B \-max 4m
Leon Scroggins IIIbd7903e2018-02-28 14:05:04 -0500208selects 4000000 bytes. If more space is needed, an error will occur.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000209.TP
210.BI \-outfile " name"
211Send output image to the named file, not to standard output.
212.TP
DRCab706232013-01-18 23:42:31 +0000213.BI \-memdst
214Compress to memory instead of a file. This feature was implemented mainly as a
215way of testing the in-memory destination manager (jpeg_mem_dest()), but it is
216also useful for benchmarking, since it reduces the I/O overhead.
217.TP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000218.B \-verbose
219Enable debug printout. More
220.BR \-v 's
221give more output. Also, version information is printed at startup.
222.TP
223.B \-debug
224Same as
225.BR \-verbose .
DRC9665f5e2014-11-22 04:04:38 +0000226.TP
227.B \-version
228Print version information and exit.
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000229.PP
230The
231.B \-restart
232option inserts extra markers that allow a JPEG decoder to resynchronize after
233a transmission error. Without restart markers, any damage to a compressed
234file will usually ruin the image from the point of the error to the end of the
235image; with restart markers, the damage is usually confined to the portion of
236the image up to the next restart marker. Of course, the restart markers
237occupy extra space. We recommend
238.B \-restart 1
239for images that will be transmitted across unreliable networks such as Usenet.
240.PP
241The
242.B \-smooth
243option filters the input to eliminate fine-scale noise. This is often useful
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000244when converting dithered images to JPEG: a moderate smoothing factor of 10 to
24550 gets rid of dithering patterns in the input file, resulting in a smaller
246JPEG file and a better-looking image. Too large a smoothing factor will
247visibly blur the image, however.
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000248.PP
249Switches for wizards:
250.TP
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000251.B \-baseline
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000252Force baseline-compatible quantization tables to be generated. This clamps
253quantization values to 8 bits even at low quality settings. (This switch is
254poorly named, since it does not ensure that the output is actually baseline
255JPEG. For example, you can use
256.B \-baseline
257and
258.B \-progressive
259together.)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000260.TP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000261.BI \-qtables " file"
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000262Use the quantization tables given in the specified text file.
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000263.TP
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000264.BI \-qslots " N[,...]"
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000265Select which quantization table to use for each color component.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000266.TP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000267.BI \-sample " HxV[,...]"
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000268Set JPEG sampling factors for each color component.
269.TP
270.BI \-scans " file"
271Use the scan script given in the specified text file.
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000272.PP
273The "wizard" switches are intended for experimentation with JPEG. If you
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000274don't know what you are doing, \fBdon't use them\fR. These switches are
Guido Vollbeding5996a252009-06-27 00:00:00 +0000275documented further in the file wizard.txt.
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000276.SH EXAMPLES
277.LP
278This example compresses the PPM file foo.ppm with a quality factor of
27960 and saves the output as foo.jpg:
280.IP
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000281.B cjpeg \-quality
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000282.I 60 foo.ppm
283.B >
284.I foo.jpg
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000285.SH HINTS
286Color GIF files are not the ideal input for JPEG; JPEG is really intended for
287compressing full-color (24-bit) images. In particular, don't try to convert
288cartoons, line drawings, and other images that have only a few distinct
289colors. GIF works great on these, JPEG does not. If you want to convert a
290GIF to JPEG, you should experiment with
291.BR cjpeg 's
292.B \-quality
293and
294.B \-smooth
295options to get a satisfactory conversion.
296.B \-smooth 10
297or so is often helpful.
298.PP
299Avoid running an image through a series of JPEG compression/decompression
300cycles. Image quality loss will accumulate; after ten or so cycles the image
301may be noticeably worse than it was after one cycle. It's best to use a
302lossless format while manipulating an image, then convert to JPEG format when
303you are ready to file the image away.
304.PP
305The
306.B \-optimize
307option to
308.B cjpeg
309is worth using when you are making a "final" version for posting or archiving.
310It's also a win when you are using low quality settings to make very small
311JPEG files; the percentage improvement is often a lot more than it is on
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000312larger files. (At present,
313.B \-optimize
314mode is always selected when generating progressive JPEG files.)
Thomas G. Lane88aeed41992-12-10 00:00:00 +0000315.SH ENVIRONMENT
316.TP
317.B JPEGMEM
318If this environment variable is set, its value is the default memory limit.
319The value is specified as described for the
320.B \-maxmemory
321switch.
322.B JPEGMEM
323overrides the default value specified when the program was compiled, and
324itself is overridden by an explicit
325.BR \-maxmemory .
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000326.SH SEE ALSO
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000327.BR djpeg (1),
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000328.BR jpegtran (1),
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000329.BR rdjpgcom (1),
330.BR wrjpgcom (1)
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000331.br
Thomas G. Lane4a6b7301992-03-17 00:00:00 +0000332.BR ppm (5),
333.BR pgm (5)
334.br
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000335Wallace, Gregory K. "The JPEG Still Picture Compression Standard",
336Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
337.SH AUTHOR
338Independent JPEG Group
DRCcf763c02013-01-01 09:51:37 +0000339.PP
340This file was modified by The libjpeg-turbo Project to include only information
DRCab706232013-01-18 23:42:31 +0000341relevant to libjpeg-turbo, to wordsmith certain sections, and to describe
342features not present in libjpeg.
Alex Naidis6eb7d372016-10-16 23:10:08 +0200343.SH ISSUES
DRC39ea5622010-10-12 01:55:31 +0000344Support for GIF input files was removed in cjpeg v6b due to concerns over
345the Unisys LZW patent. Although this patent expired in 2006, cjpeg still
346lacks GIF support, for these historical reasons. (Conversion of GIF files to
Alex Naidis6eb7d372016-10-16 23:10:08 +0200347JPEG is usually a bad idea anyway, since GIF is a 256-color format.)
Thomas G. Lane5ead57a1998-03-27 00:00:00 +0000348.PP
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000349Not all variants of BMP and Targa file formats are supported.
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000350.PP
351The
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000352.B \-targa
Thomas G. Lanebd543f01991-12-13 00:00:00 +0000353switch is not a bug, it's a feature. (It would be a bug if the Targa format
354designers had not been clueless.)