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