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