blob: 569dc3fa3f9f6374235d50dde9f567fc184b1e1d [file] [log] [blame]
Jonathan Wrightbbb82822020-11-25 13:36:43 +00001.TH CJPEG 1 "4 November 2020"
Tom Hudson0d47d2d2016-05-04 13:22:56 -04002.SH NAME
3cjpeg \- compress an image file to a JPEG file
4.SH SYNOPSIS
5.B cjpeg
6[
7.I options
8]
9[
10.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.
18The currently supported input file formats are: PPM (PBMPLUS color
Jonathan Wrightbbb82822020-11-25 13:36:43 +000019format), PGM (PBMPLUS grayscale format), BMP, GIF, and Targa.
Tom Hudson0d47d2d2016-05-04 13:22:56 -040020.SH OPTIONS
21All switch names may be abbreviated; for example,
22.B \-grayscale
23may be written
24.B \-gray
25or
26.BR \-gr .
27Most of the "basic" switches can be abbreviated to as little as one letter.
28Upper and lower case are equivalent (thus
29.B \-BMP
30is the same as
31.BR \-bmp ).
32British spellings are also accepted (e.g.,
33.BR \-greyscale ),
34though for brevity these are not mentioned below.
35.PP
36The basic switches are:
37.TP
38.BI \-quality " N[,...]"
39Scale quantization tables to adjust image quality. Quality is 0 (worst) to
40100 (best); default is 75. (See below for more info.)
41.TP
42.B \-grayscale
43Create monochrome JPEG file from color input. Be sure to use this switch when
Jonathan Wrightbbb82822020-11-25 13:36:43 +000044compressing a grayscale BMP or GIF file, because
Tom Hudson0d47d2d2016-05-04 13:22:56 -040045.B cjpeg
Jonathan Wrightbbb82822020-11-25 13:36:43 +000046isn't bright enough to notice whether a BMP or GIF file uses only shades of
47gray. By saying
Chris Blumecca8c4d2019-03-01 01:09:50 -080048.BR \-grayscale,
Tom Hudson0d47d2d2016-05-04 13:22:56 -040049you'll get a smaller JPEG file that takes less time to process.
50.TP
51.B \-rgb
52Create RGB JPEG file.
53Using this switch suppresses the conversion from RGB
54colorspace input to the default YCbCr JPEG colorspace.
55.TP
56.B \-optimize
57Perform optimization of entropy encoding parameters. Without this, default
58encoding parameters are used.
59.B \-optimize
60usually makes the JPEG file a little smaller, but
61.B cjpeg
62runs somewhat slower and needs much more memory. Image quality and speed of
63decompression are unaffected by
64.BR \-optimize .
65.TP
66.B \-progressive
67Create progressive JPEG file (see below).
68.TP
69.B \-targa
70Input file is Targa format. Targa files that contain an "identification"
71field will not be automatically recognized by
72.BR cjpeg ;
73for such files you must specify
74.B \-targa
75to make
76.B cjpeg
77treat the input as Targa format.
78For most Targa files, you won't need this switch.
79.PP
80The
81.B \-quality
82switch lets you trade off compressed file size against quality of the
83reconstructed image: the higher the quality setting, the larger the JPEG file,
84and the closer the output image will be to the original input. Normally you
85want to use the lowest quality setting (smallest file) that decompresses into
86something visually indistinguishable from the original image. For this
87purpose the quality setting should generally be between 50 and 95 (the default
88is 75) for photographic images. If you see defects at
89.B \-quality
9075, then go up 5 or 10 counts at a time until you are happy with the output
91image. (The optimal setting will vary from one image to another.)
92.PP
93.B \-quality
94100 will generate a quantization table of all 1's, minimizing loss in the
95quantization step (but there is still information loss in subsampling, as well
96as roundoff error.) For most images, specifying a quality value above
97about 95 will increase the size of the compressed file dramatically, and while
98the quality gain from these higher quality values is measurable (using metrics
99such as PSNR or SSIM), it is rarely perceivable by human vision.
100.PP
101In the other direction, quality values below 50 will produce very small files
102of low image quality. Settings around 5 to 10 might be useful in preparing an
103index of a large image library, for example. Try
104.B \-quality
1052 (or so) for some amusing Cubist effects. (Note: quality
106values below about 25 generate 2-byte quantization tables, which are
107considered optional in the JPEG standard.
108.B cjpeg
109emits a warning message when you give such a quality value, because some
110other JPEG programs may be unable to decode the resulting file. Use
111.B \-baseline
112if you need to ensure compatibility at low quality values.)
113.PP
114The \fB-quality\fR option has been extended in this version of \fBcjpeg\fR to
115support separate quality settings for luminance and chrominance (or, in
116general, separate settings for every quantization table slot.) The principle
117is the same as chrominance subsampling: since the human eye is more sensitive
118to spatial changes in brightness than spatial changes in color, the chrominance
119components can be quantized more than the luminance components without
120incurring any visible image quality loss. However, unlike subsampling, this
121feature reduces data in the frequency domain instead of the spatial domain,
122which allows for more fine-grained control. This option is useful in
123quality-sensitive applications, for which the artifacts generated by
124subsampling may be unacceptable.
125.PP
126The \fB-quality\fR option accepts a comma-separated list of parameters, which
127respectively refer to the quality levels that should be assigned to the
128quantization table slots. If there are more q-table slots than parameters,
129then the last parameter is replicated. Thus, if only one quality parameter is
130given, this is used for both luminance and chrominance (slots 0 and 1,
131respectively), preserving the legacy behavior of cjpeg v6b and prior.
132More (or customized) quantization tables can be set with the \fB-qtables\fR
133option and assigned to components with the \fB-qslots\fR option (see the
134"wizard" switches below.)
135.PP
136JPEG files generated with separate luminance and chrominance quality are fully
137compliant with standard JPEG decoders.
138.PP
139.BR CAUTION:
140For this setting to be useful, be sure to pass an argument of \fB-sample 1x1\fR
141to \fBcjpeg\fR to disable chrominance subsampling. Otherwise, the default
142subsampling level (2x2, AKA "4:2:0") will be used.
143.PP
144The
145.B \-progressive
146switch creates a "progressive JPEG" file. In this type of JPEG file, the data
147is stored in multiple scans of increasing quality. If the file is being
148transmitted over a slow communications link, the decoder can use the first
149scan to display a low-quality image very quickly, and can then improve the
150display with each subsequent scan. The final image is exactly equivalent to a
151standard JPEG file of the same quality setting, and the total file size is
152about the same --- often a little smaller.
153.PP
154Switches for advanced users:
155.TP
156.B \-arithmetic
157Use arithmetic coding.
158.B Caution:
159arithmetic coded JPEG is not yet widely implemented, so many decoders will be
160unable to view an arithmetic coded JPEG file at all.
161.TP
162.B \-dct int
Jonathan Wrightbbb82822020-11-25 13:36:43 +0000163Use accurate integer DCT method (default).
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400164.TP
165.B \-dct fast
Jonathan Wrightbbb82822020-11-25 13:36:43 +0000166Use less accurate integer DCT method [legacy feature].
167When the Independent JPEG Group's software was first released in 1991, the
168compression time for a 1-megapixel JPEG image on a mainstream PC was measured
169in minutes. Thus, the \fBfast\fR integer DCT algorithm provided noticeable
170performance benefits. On modern CPUs running libjpeg-turbo, however, the
171compression time for a 1-megapixel JPEG image is measured in milliseconds, and
172thus the performance benefits of the \fBfast\fR algorithm are much less
173noticeable. On modern x86/x86-64 CPUs that support AVX2 instructions, the
174\fBfast\fR and \fBint\fR methods have similar performance. On other types of
175CPUs, the \fBfast\fR method is generally about 5-15% faster than the \fBint\fR
176method.
177
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400178For quality levels of 90 and below, there should be little or no perceptible
Jonathan Wrightbbb82822020-11-25 13:36:43 +0000179quality difference between the two algorithms. For quality levels above 90,
180however, the difference between the \fBfast\fR and \fBint\fR methods becomes
181more pronounced. With quality=97, for instance, the \fBfast\fR method incurs
182generally about a 1-3 dB loss in PSNR relative to the \fBint\fR method, but
183this can be larger for some images. Do not use the \fBfast\fR method with
184quality levels above 97. The algorithm often degenerates at quality=98 and
185above and can actually produce a more lossy image than if lower quality levels
186had been used. Also, in libjpeg-turbo, the \fBfast\fR method is not fully
187accelerated for quality levels above 97, so it will be slower than the
188\fBint\fR method.
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400189.TP
190.B \-dct float
Jonathan Wrightbbb82822020-11-25 13:36:43 +0000191Use floating-point DCT method [legacy feature].
192The \fBfloat\fR method does not produce significantly more accurate results
193than the \fBint\fR method, and it is much slower. The \fBfloat\fR method may
194also give different results on different machines due to varying roundoff
195behavior, whereas the integer methods should give the same results on all
196machines.
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400197.TP
Chris Blumecca8c4d2019-03-01 01:09:50 -0800198.BI \-icc " file"
199Embed ICC color management profile contained in the specified file.
200.TP
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400201.BI \-restart " N"
202Emit a JPEG restart marker every N MCU rows, or every N MCU blocks if "B" is
203attached to the number.
204.B \-restart 0
205(the default) means no restart markers.
206.TP
207.BI \-smooth " N"
208Smooth the input image to eliminate dithering noise. N, ranging from 1 to
209100, indicates the strength of smoothing. 0 (the default) means no smoothing.
210.TP
211.BI \-maxmemory " N"
212Set limit for amount of memory to use in processing large images. Value is
213in thousands of bytes, or millions of bytes if "M" is attached to the
214number. For example,
215.B \-max 4m
Chris Blumecca8c4d2019-03-01 01:09:50 -0800216selects 4000000 bytes. If more space is needed, an error will occur.
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400217.TP
218.BI \-outfile " name"
219Send output image to the named file, not to standard output.
220.TP
221.BI \-memdst
222Compress to memory instead of a file. This feature was implemented mainly as a
223way of testing the in-memory destination manager (jpeg_mem_dest()), but it is
224also useful for benchmarking, since it reduces the I/O overhead.
225.TP
Jonathan Wrightbbb82822020-11-25 13:36:43 +0000226.BI \-report
227Report compression progress.
228.TP
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400229.B \-verbose
230Enable debug printout. More
231.BR \-v 's
232give more output. Also, version information is printed at startup.
233.TP
234.B \-debug
235Same as
236.BR \-verbose .
237.TP
238.B \-version
239Print version information and exit.
240.PP
241The
242.B \-restart
243option inserts extra markers that allow a JPEG decoder to resynchronize after
244a transmission error. Without restart markers, any damage to a compressed
245file will usually ruin the image from the point of the error to the end of the
246image; with restart markers, the damage is usually confined to the portion of
247the image up to the next restart marker. Of course, the restart markers
248occupy extra space. We recommend
249.B \-restart 1
250for images that will be transmitted across unreliable networks such as Usenet.
251.PP
252The
253.B \-smooth
254option filters the input to eliminate fine-scale noise. This is often useful
255when converting dithered images to JPEG: a moderate smoothing factor of 10 to
25650 gets rid of dithering patterns in the input file, resulting in a smaller
257JPEG file and a better-looking image. Too large a smoothing factor will
258visibly blur the image, however.
259.PP
260Switches for wizards:
261.TP
262.B \-baseline
263Force baseline-compatible quantization tables to be generated. This clamps
264quantization values to 8 bits even at low quality settings. (This switch is
265poorly named, since it does not ensure that the output is actually baseline
266JPEG. For example, you can use
267.B \-baseline
268and
269.B \-progressive
270together.)
271.TP
272.BI \-qtables " file"
273Use the quantization tables given in the specified text file.
274.TP
275.BI \-qslots " N[,...]"
276Select which quantization table to use for each color component.
277.TP
278.BI \-sample " HxV[,...]"
279Set JPEG sampling factors for each color component.
280.TP
281.BI \-scans " file"
282Use the scan script given in the specified text file.
283.PP
284The "wizard" switches are intended for experimentation with JPEG. If you
285don't know what you are doing, \fBdon't use them\fR. These switches are
286documented further in the file wizard.txt.
287.SH EXAMPLES
288.LP
289This example compresses the PPM file foo.ppm with a quality factor of
29060 and saves the output as foo.jpg:
291.IP
292.B cjpeg \-quality
293.I 60 foo.ppm
294.B >
295.I foo.jpg
296.SH HINTS
297Color GIF files are not the ideal input for JPEG; JPEG is really intended for
298compressing full-color (24-bit) images. In particular, don't try to convert
299cartoons, line drawings, and other images that have only a few distinct
300colors. GIF works great on these, JPEG does not. If you want to convert a
301GIF to JPEG, you should experiment with
302.BR cjpeg 's
303.B \-quality
304and
305.B \-smooth
306options to get a satisfactory conversion.
307.B \-smooth 10
308or so is often helpful.
309.PP
310Avoid running an image through a series of JPEG compression/decompression
311cycles. Image quality loss will accumulate; after ten or so cycles the image
312may be noticeably worse than it was after one cycle. It's best to use a
313lossless format while manipulating an image, then convert to JPEG format when
314you are ready to file the image away.
315.PP
316The
317.B \-optimize
318option to
319.B cjpeg
320is worth using when you are making a "final" version for posting or archiving.
321It's also a win when you are using low quality settings to make very small
322JPEG files; the percentage improvement is often a lot more than it is on
323larger files. (At present,
324.B \-optimize
325mode is always selected when generating progressive JPEG files.)
326.SH ENVIRONMENT
327.TP
328.B JPEGMEM
329If this environment variable is set, its value is the default memory limit.
330The value is specified as described for the
331.B \-maxmemory
332switch.
333.B JPEGMEM
334overrides the default value specified when the program was compiled, and
335itself is overridden by an explicit
336.BR \-maxmemory .
337.SH SEE ALSO
338.BR djpeg (1),
339.BR jpegtran (1),
340.BR rdjpgcom (1),
341.BR wrjpgcom (1)
342.br
343.BR ppm (5),
344.BR pgm (5)
345.br
346Wallace, Gregory K. "The JPEG Still Picture Compression Standard",
347Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
348.SH AUTHOR
349Independent JPEG Group
350.PP
351This file was modified by The libjpeg-turbo Project to include only information
352relevant to libjpeg-turbo, to wordsmith certain sections, and to describe
353features not present in libjpeg.
354.SH ISSUES
Tom Hudson0d47d2d2016-05-04 13:22:56 -0400355Not all variants of BMP and Targa file formats are supported.
356.PP
357The
358.B \-targa
359switch is not a bug, it's a feature. (It would be a bug if the Targa format
360designers had not been clueless.)