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