DRC | a73e870 | 2012-12-31 02:52:30 +0000 | [diff] [blame^] | 1 | NOTE: This file was modified by The libjpeg-turbo Project to include only |
| 2 | information relevant to libjpeg-turbo and to clarify certain passages. |
| 3 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 4 | USAGE instructions for the Independent JPEG Group's JPEG software |
| 5 | ================================================================= |
| 6 | |
| 7 | This file describes usage of the JPEG conversion programs cjpeg and djpeg, |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 8 | as well as the utility programs jpegtran, rdjpgcom and wrjpgcom. (See |
| 9 | the other documentation files if you wish to use the JPEG library within |
| 10 | your own programs.) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 11 | |
| 12 | If you are on a Unix machine you may prefer to read the Unix-style manual |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 13 | pages in files cjpeg.1, djpeg.1, jpegtran.1, rdjpgcom.1, wrjpgcom.1. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 14 | |
| 15 | |
| 16 | INTRODUCTION |
| 17 | |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 18 | These programs implement JPEG image encoding, decoding, and transcoding. |
| 19 | JPEG (pronounced "jay-peg") is a standardized compression method for |
| 20 | full-color and gray-scale images. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 21 | |
| 22 | |
| 23 | GENERAL USAGE |
| 24 | |
| 25 | We provide two programs, cjpeg to compress an image file into JPEG format, |
| 26 | and djpeg to decompress a JPEG file back into a conventional image format. |
| 27 | |
| 28 | On Unix-like systems, you say: |
| 29 | cjpeg [switches] [imagefile] >jpegfile |
| 30 | or |
| 31 | djpeg [switches] [jpegfile] >imagefile |
| 32 | The programs read the specified input file, or standard input if none is |
| 33 | named. They always write to standard output (with trace/error messages to |
| 34 | standard error). These conventions are handy for piping images between |
| 35 | programs. |
| 36 | |
| 37 | On most non-Unix systems, you say: |
| 38 | cjpeg [switches] imagefile jpegfile |
| 39 | or |
| 40 | djpeg [switches] jpegfile imagefile |
| 41 | i.e., both the input and output files are named on the command line. This |
| 42 | style is a little more foolproof, and it loses no functionality if you don't |
| 43 | have pipes. (You can get this style on Unix too, if you prefer, by defining |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 44 | TWO_FILE_COMMANDLINE when you compile the programs; see install.txt.) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 45 | |
| 46 | You can also say: |
| 47 | cjpeg [switches] -outfile jpegfile imagefile |
| 48 | or |
| 49 | djpeg [switches] -outfile imagefile jpegfile |
| 50 | This syntax works on all systems, so it is useful for scripts. |
| 51 | |
| 52 | The currently supported image file formats are: PPM (PBMPLUS color format), |
Thomas G. Lane | 5ead57a | 1998-03-27 00:00:00 +0000 | [diff] [blame] | 53 | PGM (PBMPLUS gray-scale format), BMP, Targa, and RLE (Utah Raster Toolkit |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 54 | format). (RLE is supported only if the URT library is available.) |
| 55 | cjpeg recognizes the input image format automatically, with the exception |
| 56 | of some Targa-format files. You have to tell djpeg which format to generate. |
| 57 | |
| 58 | JPEG files are in the defacto standard JFIF file format. There are other, |
| 59 | less widely used JPEG-based file formats, but we don't support them. |
| 60 | |
| 61 | All switch names may be abbreviated; for example, -grayscale may be written |
| 62 | -gray or -gr. Most of the "basic" switches can be abbreviated to as little as |
Thomas G. Lane | 5ead57a | 1998-03-27 00:00:00 +0000 | [diff] [blame] | 63 | one letter. Upper and lower case are equivalent (-BMP is the same as -bmp). |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 64 | British spellings are also accepted (e.g., -greyscale), though for brevity |
| 65 | these are not mentioned below. |
| 66 | |
| 67 | |
| 68 | CJPEG DETAILS |
| 69 | |
| 70 | The basic command line switches for cjpeg are: |
| 71 | |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 72 | -quality N[,...] Scale quantization tables to adjust image quality. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 73 | Quality is 0 (worst) to 100 (best); default is 75. |
| 74 | (See below for more info.) |
| 75 | |
| 76 | -grayscale Create monochrome JPEG file from color input. |
| 77 | Be sure to use this switch when compressing a grayscale |
Thomas G. Lane | 5ead57a | 1998-03-27 00:00:00 +0000 | [diff] [blame] | 78 | BMP file, because cjpeg isn't bright enough to notice |
| 79 | whether a BMP file uses only shades of gray. By |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 80 | saying -grayscale, you'll get a smaller JPEG file that |
| 81 | takes less time to process. |
| 82 | |
| 83 | -optimize Perform optimization of entropy encoding parameters. |
| 84 | Without this, default encoding parameters are used. |
| 85 | -optimize usually makes the JPEG file a little smaller, |
| 86 | but cjpeg runs somewhat slower and needs much more |
| 87 | memory. Image quality and speed of decompression are |
| 88 | unaffected by -optimize. |
| 89 | |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 90 | -progressive Create progressive JPEG file (see below). |
| 91 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 92 | -targa Input file is Targa format. Targa files that contain |
| 93 | an "identification" field will not be automatically |
| 94 | recognized by cjpeg; for such files you must specify |
| 95 | -targa to make cjpeg treat the input as Targa format. |
| 96 | For most Targa files, you won't need this switch. |
| 97 | |
| 98 | The -quality switch lets you trade off compressed file size against quality of |
| 99 | the reconstructed image: the higher the quality setting, the larger the JPEG |
| 100 | file, and the closer the output image will be to the original input. Normally |
| 101 | you want to use the lowest quality setting (smallest file) that decompresses |
| 102 | into something visually indistinguishable from the original image. For this |
| 103 | purpose the quality setting should be between 50 and 95; the default of 75 is |
| 104 | often about right. If you see defects at -quality 75, then go up 5 or 10 |
| 105 | counts at a time until you are happy with the output image. (The optimal |
| 106 | setting will vary from one image to another.) |
| 107 | |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 108 | -quality 100 will generate a quantization table of all 1's, minimizing loss |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 109 | in the quantization step (but there is still information loss in subsampling, |
| 110 | as well as roundoff error). This setting is mainly of interest for |
| 111 | experimental purposes. Quality values above about 95 are NOT recommended for |
| 112 | normal use; the compressed file size goes up dramatically for hardly any gain |
| 113 | in output image quality. |
| 114 | |
| 115 | In the other direction, quality values below 50 will produce very small files |
| 116 | of low image quality. Settings around 5 to 10 might be useful in preparing an |
| 117 | index of a large image library, for example. Try -quality 2 (or so) for some |
| 118 | amusing Cubist effects. (Note: quality values below about 25 generate 2-byte |
| 119 | quantization tables, which are considered optional in the JPEG standard. |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 120 | cjpeg emits a warning message when you give such a quality value, because some |
| 121 | other JPEG programs may be unable to decode the resulting file. Use -baseline |
| 122 | if you need to ensure compatibility at low quality values.) |
| 123 | |
DRC | 39ea562 | 2010-10-12 01:55:31 +0000 | [diff] [blame] | 124 | The -quality option has been extended in this version of cjpeg to support |
| 125 | separate quality settings for luminance and chrominance (or, in general, |
| 126 | separate settings for every quantization table slot.) The principle is the |
| 127 | same as chrominance subsampling: since the human eye is more sensitive to |
| 128 | spatial changes in brightness than spatial changes in color, the chrominance |
| 129 | components can be quantized more than the luminance components without |
| 130 | incurring any visible image quality loss. However, unlike subsampling, this |
| 131 | feature reduces data in the frequency domain instead of the spatial domain, |
| 132 | which allows for more fine-grained control. This option is useful in |
| 133 | quality-sensitive applications, for which the artifacts generated by |
| 134 | subsampling may be unacceptable. |
| 135 | |
| 136 | The -quality option accepts a comma-separated list of parameters, which |
DRC | ccd1bfd | 2012-01-31 09:53:46 +0000 | [diff] [blame] | 137 | respectively refer to the quality levels that should be assigned to the |
DRC | 39ea562 | 2010-10-12 01:55:31 +0000 | [diff] [blame] | 138 | quantization table slots. If there are more q-table slots than parameters, |
| 139 | then the last parameter is replicated. Thus, if only one quality parameter is |
| 140 | given, this is used for both luminance and chrominance (slots 0 and 1, |
| 141 | respectively), preserving the legacy behavior of cjpeg v6b and prior. More (or |
| 142 | customized) quantization tables can be set with the -qtables option and |
| 143 | assigned to components with the -qslots option (see the "wizard" switches |
| 144 | below.) |
| 145 | |
| 146 | JPEG files generated with separate luminance and chrominance quality are |
| 147 | fully compliant with standard JPEG decoders. |
| 148 | |
| 149 | CAUTION: For this setting to be useful, be sure to pass an argument of |
| 150 | -sample 1x1 to cjpeg to disable chrominance subsampling. Otherwise, the |
| 151 | default subsampling level (2x2, AKA "4:2:0") will be used. |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 152 | |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 153 | The -progressive switch creates a "progressive JPEG" file. In this type of |
| 154 | JPEG file, the data is stored in multiple scans of increasing quality. If the |
| 155 | file is being transmitted over a slow communications link, the decoder can use |
| 156 | the first scan to display a low-quality image very quickly, and can then |
| 157 | improve the display with each subsequent scan. The final image is exactly |
| 158 | equivalent to a standard JPEG file of the same quality setting, and the total |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 159 | file size is about the same --- often a little smaller. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 160 | |
| 161 | Switches for advanced users: |
| 162 | |
Guido Vollbeding | 5829cb2 | 2012-01-15 00:00:00 +0000 | [diff] [blame] | 163 | -arithmetic Use arithmetic coding. CAUTION: arithmetic coded JPEG |
| 164 | is not yet widely implemented, so many decoders will |
| 165 | be unable to view an arithmetic coded JPEG file at |
| 166 | all. |
| 167 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 168 | -dct int Use integer DCT method (default). |
| 169 | -dct fast Use fast integer DCT (less accurate). |
| 170 | -dct float Use floating-point DCT method. |
Thomas G. Lane | a8b67c4 | 1995-03-15 00:00:00 +0000 | [diff] [blame] | 171 | The float method is very slightly more accurate than |
| 172 | the int method, but is much slower unless your machine |
| 173 | has very fast floating-point hardware. Also note that |
| 174 | results of the floating-point method may vary slightly |
| 175 | across machines, while the integer methods should give |
| 176 | the same results everywhere. The fast integer method |
| 177 | is much less accurate than the other two. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 178 | |
| 179 | -restart N Emit a JPEG restart marker every N MCU rows, or every |
| 180 | N MCU blocks if "B" is attached to the number. |
| 181 | -restart 0 (the default) means no restart markers. |
| 182 | |
| 183 | -smooth N Smooth the input image to eliminate dithering noise. |
| 184 | N, ranging from 1 to 100, indicates the strength of |
| 185 | smoothing. 0 (the default) means no smoothing. |
| 186 | |
| 187 | -maxmemory N Set limit for amount of memory to use in processing |
| 188 | large images. Value is in thousands of bytes, or |
| 189 | millions of bytes if "M" is attached to the number. |
| 190 | For example, -max 4m selects 4000000 bytes. If more |
| 191 | space is needed, temporary files will be used. |
| 192 | |
| 193 | -verbose Enable debug printout. More -v's give more printout. |
| 194 | or -debug Also, version information is printed at startup. |
| 195 | |
| 196 | The -restart option inserts extra markers that allow a JPEG decoder to |
| 197 | resynchronize after a transmission error. Without restart markers, any damage |
| 198 | to a compressed file will usually ruin the image from the point of the error |
| 199 | to the end of the image; with restart markers, the damage is usually confined |
| 200 | to the portion of the image up to the next restart marker. Of course, the |
| 201 | restart markers occupy extra space. We recommend -restart 1 for images that |
| 202 | will be transmitted across unreliable networks such as Usenet. |
| 203 | |
| 204 | The -smooth option filters the input to eliminate fine-scale noise. This is |
Thomas G. Lane | 5ead57a | 1998-03-27 00:00:00 +0000 | [diff] [blame] | 205 | often useful when converting dithered images to JPEG: a moderate smoothing |
| 206 | factor of 10 to 50 gets rid of dithering patterns in the input file, resulting |
| 207 | in a smaller JPEG file and a better-looking image. Too large a smoothing |
| 208 | factor will visibly blur the image, however. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 209 | |
| 210 | Switches for wizards: |
| 211 | |
Thomas G. Lane | 5ead57a | 1998-03-27 00:00:00 +0000 | [diff] [blame] | 212 | -baseline Force baseline-compatible quantization tables to be |
| 213 | generated. This clamps quantization values to 8 bits |
| 214 | even at low quality settings. (This switch is poorly |
| 215 | named, since it does not ensure that the output is |
| 216 | actually baseline JPEG. For example, you can use |
| 217 | -baseline and -progressive together.) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 218 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 219 | -qtables file Use the quantization tables given in the specified |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 220 | text file. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 221 | |
| 222 | -qslots N[,...] Select which quantization table to use for each color |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 223 | component. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 224 | |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 225 | -sample HxV[,...] Set JPEG sampling factors for each color component. |
| 226 | |
| 227 | -scans file Use the scan script given in the specified text file. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 228 | |
| 229 | The "wizard" switches are intended for experimentation with JPEG. If you |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 230 | don't know what you are doing, DON'T USE THEM. These switches are documented |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 231 | further in the file wizard.txt. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 232 | |
| 233 | |
| 234 | DJPEG DETAILS |
| 235 | |
| 236 | The basic command line switches for djpeg are: |
| 237 | |
| 238 | -colors N Reduce image to at most N colors. This reduces the |
| 239 | or -quantize N number of colors used in the output image, so that it |
| 240 | can be displayed on a colormapped display or stored in |
| 241 | a colormapped file format. For example, if you have |
| 242 | an 8-bit display, you'd need to reduce to 256 or fewer |
| 243 | colors. (-colors is the recommended name, -quantize |
| 244 | is provided only for backwards compatibility.) |
| 245 | |
| 246 | -fast Select recommended processing options for fast, low |
| 247 | quality output. (The default options are chosen for |
| 248 | highest quality output.) Currently, this is equivalent |
| 249 | to "-dct fast -nosmooth -onepass -dither ordered". |
| 250 | |
| 251 | -grayscale Force gray-scale output even if JPEG file is color. |
| 252 | Useful for viewing on monochrome displays; also, |
| 253 | djpeg runs noticeably faster in this mode. |
| 254 | |
| 255 | -scale M/N Scale the output image by a factor M/N. Currently |
| 256 | the scale factor must be 1/1, 1/2, 1/4, or 1/8. |
| 257 | Scaling is handy if the image is larger than your |
| 258 | screen; also, djpeg runs much faster when scaling |
| 259 | down the output. |
| 260 | |
| 261 | -bmp Select BMP output format (Windows flavor). 8-bit |
| 262 | colormapped format is emitted if -colors or -grayscale |
| 263 | is specified, or if the JPEG file is gray-scale; |
| 264 | otherwise, 24-bit full-color format is emitted. |
| 265 | |
| 266 | -gif Select GIF output format. Since GIF does not support |
| 267 | more than 256 colors, -colors 256 is assumed (unless |
| 268 | you specify a smaller number of colors). If you |
| 269 | specify -fast, the default number of colors is 216. |
| 270 | |
| 271 | -os2 Select BMP output format (OS/2 1.x flavor). 8-bit |
| 272 | colormapped format is emitted if -colors or -grayscale |
| 273 | is specified, or if the JPEG file is gray-scale; |
| 274 | otherwise, 24-bit full-color format is emitted. |
| 275 | |
| 276 | -pnm Select PBMPLUS (PPM/PGM) output format (this is the |
| 277 | default format). PGM is emitted if the JPEG file is |
| 278 | gray-scale or if -grayscale is specified; otherwise |
| 279 | PPM is emitted. |
| 280 | |
| 281 | -rle Select RLE output format. (Requires URT library.) |
| 282 | |
| 283 | -targa Select Targa output format. Gray-scale format is |
| 284 | emitted if the JPEG file is gray-scale or if |
| 285 | -grayscale is specified; otherwise, colormapped format |
| 286 | is emitted if -colors is specified; otherwise, 24-bit |
| 287 | full-color format is emitted. |
| 288 | |
| 289 | Switches for advanced users: |
| 290 | |
| 291 | -dct int Use integer DCT method (default). |
| 292 | -dct fast Use fast integer DCT (less accurate). |
| 293 | -dct float Use floating-point DCT method. |
Thomas G. Lane | a8b67c4 | 1995-03-15 00:00:00 +0000 | [diff] [blame] | 294 | The float method is very slightly more accurate than |
| 295 | the int method, but is much slower unless your machine |
| 296 | has very fast floating-point hardware. Also note that |
| 297 | results of the floating-point method may vary slightly |
| 298 | across machines, while the integer methods should give |
| 299 | the same results everywhere. The fast integer method |
| 300 | is much less accurate than the other two. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 301 | |
| 302 | -dither fs Use Floyd-Steinberg dithering in color quantization. |
| 303 | -dither ordered Use ordered dithering in color quantization. |
| 304 | -dither none Do not use dithering in color quantization. |
| 305 | By default, Floyd-Steinberg dithering is applied when |
| 306 | quantizing colors; this is slow but usually produces |
| 307 | the best results. Ordered dither is a compromise |
| 308 | between speed and quality; no dithering is fast but |
| 309 | usually looks awful. Note that these switches have |
| 310 | no effect unless color quantization is being done. |
| 311 | Ordered dither is only available in -onepass mode. |
| 312 | |
| 313 | -map FILE Quantize to the colors used in the specified image |
| 314 | file. This is useful for producing multiple files |
| 315 | with identical color maps, or for forcing a predefined |
| 316 | set of colors to be used. The FILE must be a GIF |
| 317 | or PPM file. This option overrides -colors and |
| 318 | -onepass. |
| 319 | |
| 320 | -nosmooth Use a faster, lower-quality upsampling routine. |
| 321 | |
| 322 | -onepass Use one-pass instead of two-pass color quantization. |
| 323 | The one-pass method is faster and needs less memory, |
| 324 | but it produces a lower-quality image. -onepass is |
| 325 | ignored unless you also say -colors N. Also, |
| 326 | the one-pass method is always used for gray-scale |
| 327 | output (the two-pass method is no improvement then). |
| 328 | |
| 329 | -maxmemory N Set limit for amount of memory to use in processing |
| 330 | large images. Value is in thousands of bytes, or |
| 331 | millions of bytes if "M" is attached to the number. |
| 332 | For example, -max 4m selects 4000000 bytes. If more |
| 333 | space is needed, temporary files will be used. |
| 334 | |
| 335 | -verbose Enable debug printout. More -v's give more printout. |
| 336 | or -debug Also, version information is printed at startup. |
| 337 | |
| 338 | |
| 339 | HINTS FOR CJPEG |
| 340 | |
| 341 | Color GIF files are not the ideal input for JPEG; JPEG is really intended for |
| 342 | compressing full-color (24-bit) images. In particular, don't try to convert |
| 343 | cartoons, line drawings, and other images that have only a few distinct |
| 344 | colors. GIF works great on these, JPEG does not. If you want to convert a |
| 345 | GIF to JPEG, you should experiment with cjpeg's -quality and -smooth options |
| 346 | to get a satisfactory conversion. -smooth 10 or so is often helpful. |
| 347 | |
| 348 | Avoid running an image through a series of JPEG compression/decompression |
| 349 | cycles. Image quality loss will accumulate; after ten or so cycles the image |
| 350 | may be noticeably worse than it was after one cycle. It's best to use a |
| 351 | lossless format while manipulating an image, then convert to JPEG format when |
| 352 | you are ready to file the image away. |
| 353 | |
| 354 | The -optimize option to cjpeg is worth using when you are making a "final" |
| 355 | version for posting or archiving. It's also a win when you are using low |
| 356 | quality settings to make very small JPEG files; the percentage improvement |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 357 | is often a lot more than it is on larger files. (At present, -optimize |
| 358 | mode is always selected when generating progressive JPEG files.) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 359 | |
DRC | 39ea562 | 2010-10-12 01:55:31 +0000 | [diff] [blame] | 360 | Support for GIF input files was removed in cjpeg v6b due to concerns over |
| 361 | the Unisys LZW patent. Although this patent expired in 2006, cjpeg still |
| 362 | lacks GIF support, for these historical reasons. (Conversion of GIF files to |
| 363 | JPEG is usually a bad idea anyway.) |
Thomas G. Lane | 5ead57a | 1998-03-27 00:00:00 +0000 | [diff] [blame] | 364 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 365 | |
| 366 | HINTS FOR DJPEG |
| 367 | |
| 368 | To get a quick preview of an image, use the -grayscale and/or -scale switches. |
| 369 | "-grayscale -scale 1/8" is the fastest case. |
| 370 | |
| 371 | Several options are available that trade off image quality to gain speed. |
| 372 | "-fast" turns on the recommended settings. |
| 373 | |
| 374 | "-dct fast" and/or "-nosmooth" gain speed at a small sacrifice in quality. |
| 375 | When producing a color-quantized image, "-onepass -dither ordered" is fast but |
| 376 | much lower quality than the default behavior. "-dither none" may give |
| 377 | acceptable results in two-pass mode, but is seldom tolerable in one-pass mode. |
| 378 | |
| 379 | If you are fortunate enough to have very fast floating point hardware, |
Thomas G. Lane | a8b67c4 | 1995-03-15 00:00:00 +0000 | [diff] [blame] | 380 | "-dct float" may be even faster than "-dct fast". But on most machines |
| 381 | "-dct float" is slower than "-dct int"; in this case it is not worth using, |
| 382 | because its theoretical accuracy advantage is too small to be significant |
| 383 | in practice. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 384 | |
| 385 | Two-pass color quantization requires a good deal of memory; on MS-DOS machines |
| 386 | it may run out of memory even with -maxmemory 0. In that case you can still |
| 387 | decompress, with some loss of image quality, by specifying -onepass for |
| 388 | one-pass quantization. |
| 389 | |
Thomas G. Lane | 5ead57a | 1998-03-27 00:00:00 +0000 | [diff] [blame] | 390 | To avoid the Unisys LZW patent, djpeg produces uncompressed GIF files. These |
| 391 | are larger than they should be, but are readable by standard GIF decoders. |
| 392 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 393 | |
| 394 | HINTS FOR BOTH PROGRAMS |
| 395 | |
| 396 | If more space is needed than will fit in the available main memory (as |
| 397 | determined by -maxmemory), temporary files will be used. (MS-DOS versions |
| 398 | will try to get extended or expanded memory first.) The temporary files are |
| 399 | often rather large: in typical cases they occupy three bytes per pixel, for |
| 400 | example 3*800*600 = 1.44Mb for an 800x600 image. If you don't have enough |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 401 | free disk space, leave out -progressive and -optimize (for cjpeg) or specify |
| 402 | -onepass (for djpeg). |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 403 | |
| 404 | On MS-DOS, the temporary files are created in the directory named by the TMP |
| 405 | or TEMP environment variable, or in the current directory if neither of those |
| 406 | exist. Amiga implementations put the temp files in the directory named by |
| 407 | JPEGTMP:, so be sure to assign JPEGTMP: to a disk partition with adequate free |
| 408 | space. |
| 409 | |
| 410 | The default memory usage limit (-maxmemory) is set when the software is |
| 411 | compiled. If you get an "insufficient memory" error, try specifying a smaller |
| 412 | -maxmemory value, even -maxmemory 0 to use the absolute minimum space. You |
| 413 | may want to recompile with a smaller default value if this happens often. |
| 414 | |
| 415 | On machines that have "environment" variables, you can define the environment |
| 416 | variable JPEGMEM to set the default memory limit. The value is specified as |
| 417 | described for the -maxmemory switch. JPEGMEM overrides the default value |
| 418 | specified when the program was compiled, and itself is overridden by an |
| 419 | explicit -maxmemory switch. |
| 420 | |
| 421 | On MS-DOS machines, -maxmemory is the amount of main (conventional) memory to |
| 422 | use. (Extended or expanded memory is also used if available.) Most |
| 423 | DOS-specific versions of this software do their own memory space estimation |
| 424 | and do not need you to specify -maxmemory. |
| 425 | |
| 426 | |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 427 | JPEGTRAN |
| 428 | |
Thomas G. Lane | 5ead57a | 1998-03-27 00:00:00 +0000 | [diff] [blame] | 429 | jpegtran performs various useful transformations of JPEG files. |
| 430 | It can translate the coded representation from one variant of JPEG to another, |
| 431 | for example from baseline JPEG to progressive JPEG or vice versa. It can also |
| 432 | perform some rearrangements of the image data, for example turning an image |
| 433 | from landscape to portrait format by rotation. |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 434 | |
Thomas G. Lane | 5ead57a | 1998-03-27 00:00:00 +0000 | [diff] [blame] | 435 | jpegtran works by rearranging the compressed data (DCT coefficients), without |
| 436 | ever fully decoding the image. Therefore, its transformations are lossless: |
| 437 | there is no image degradation at all, which would not be true if you used |
| 438 | djpeg followed by cjpeg to accomplish the same conversion. But by the same |
| 439 | token, jpegtran cannot perform lossy operations such as changing the image |
| 440 | quality. |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 441 | |
Thomas G. Lane | 5ead57a | 1998-03-27 00:00:00 +0000 | [diff] [blame] | 442 | jpegtran uses a command line syntax similar to cjpeg or djpeg. |
| 443 | On Unix-like systems, you say: |
| 444 | jpegtran [switches] [inputfile] >outputfile |
| 445 | On most non-Unix systems, you say: |
| 446 | jpegtran [switches] inputfile outputfile |
| 447 | where both the input and output files are JPEG files. |
| 448 | |
| 449 | To specify the coded JPEG representation used in the output file, |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 450 | jpegtran accepts a subset of the switches recognized by cjpeg: |
Thomas G. Lane | 5ead57a | 1998-03-27 00:00:00 +0000 | [diff] [blame] | 451 | -optimize Perform optimization of entropy encoding parameters. |
| 452 | -progressive Create progressive JPEG file. |
Guido Vollbeding | 5829cb2 | 2012-01-15 00:00:00 +0000 | [diff] [blame] | 453 | -arithmetic Use arithmetic coding. |
Thomas G. Lane | 5ead57a | 1998-03-27 00:00:00 +0000 | [diff] [blame] | 454 | -restart N Emit a JPEG restart marker every N MCU rows, or every |
| 455 | N MCU blocks if "B" is attached to the number. |
| 456 | -scans file Use the scan script given in the specified text file. |
| 457 | See the previous discussion of cjpeg for more details about these switches. |
| 458 | If you specify none of these switches, you get a plain baseline-JPEG output |
| 459 | file. The quality setting and so forth are determined by the input file. |
| 460 | |
| 461 | The image can be losslessly transformed by giving one of these switches: |
| 462 | -flip horizontal Mirror image horizontally (left-right). |
| 463 | -flip vertical Mirror image vertically (top-bottom). |
| 464 | -rotate 90 Rotate image 90 degrees clockwise. |
| 465 | -rotate 180 Rotate image 180 degrees. |
| 466 | -rotate 270 Rotate image 270 degrees clockwise (or 90 ccw). |
| 467 | -transpose Transpose image (across UL-to-LR axis). |
| 468 | -transverse Transverse transpose (across UR-to-LL axis). |
| 469 | |
| 470 | The transpose transformation has no restrictions regarding image dimensions. |
| 471 | The other transformations operate rather oddly if the image dimensions are not |
| 472 | a multiple of the iMCU size (usually 8 or 16 pixels), because they can only |
| 473 | transform complete blocks of DCT coefficient data in the desired way. |
| 474 | |
| 475 | jpegtran's default behavior when transforming an odd-size image is designed |
| 476 | to preserve exact reversibility and mathematical consistency of the |
| 477 | transformation set. As stated, transpose is able to flip the entire image |
| 478 | area. Horizontal mirroring leaves any partial iMCU column at the right edge |
| 479 | untouched, but is able to flip all rows of the image. Similarly, vertical |
| 480 | mirroring leaves any partial iMCU row at the bottom edge untouched, but is |
| 481 | able to flip all columns. The other transforms can be built up as sequences |
| 482 | of transpose and flip operations; for consistency, their actions on edge |
| 483 | pixels are defined to be the same as the end result of the corresponding |
| 484 | transpose-and-flip sequence. |
| 485 | |
| 486 | For practical use, you may prefer to discard any untransformable edge pixels |
| 487 | rather than having a strange-looking strip along the right and/or bottom edges |
| 488 | of a transformed image. To do this, add the -trim switch: |
| 489 | -trim Drop non-transformable edge blocks. |
| 490 | Obviously, a transformation with -trim is not reversible, so strictly speaking |
| 491 | jpegtran with this switch is not lossless. Also, the expected mathematical |
| 492 | equivalences between the transformations no longer hold. For example, |
| 493 | "-rot 270 -trim" trims only the bottom edge, but "-rot 90 -trim" followed by |
| 494 | "-rot 180 -trim" trims both edges. |
| 495 | |
DRC | 39ea562 | 2010-10-12 01:55:31 +0000 | [diff] [blame] | 496 | If you are only interested in perfect transformations, add the -perfect switch: |
| 497 | -perfect Fail with an error if the transformation is not |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 498 | perfect. |
DRC | 39ea562 | 2010-10-12 01:55:31 +0000 | [diff] [blame] | 499 | For example, you may want to do |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 500 | jpegtran -rot 90 -perfect foo.jpg || djpeg foo.jpg | pnmflip -r90 | cjpeg |
DRC | 39ea562 | 2010-10-12 01:55:31 +0000 | [diff] [blame] | 501 | to do a perfect rotation, if available, or an approximated one if not. |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 502 | |
DRC | 39ea562 | 2010-10-12 01:55:31 +0000 | [diff] [blame] | 503 | This version of jpegtran also offers a lossless crop option, which discards |
| 504 | data outside of a given image region but losslessly preserves what is inside. |
| 505 | Like the rotate and flip transforms, lossless crop is restricted by the current |
| 506 | JPEG format; the upper left corner of the selected region must fall on an iMCU |
| 507 | boundary. If it doesn't, then it is silently moved up and/or left to the |
| 508 | nearest iMCU boundary (the lower right corner is unchanged.) |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 509 | |
| 510 | The image can be losslessly cropped by giving the switch: |
DRC | 39ea562 | 2010-10-12 01:55:31 +0000 | [diff] [blame] | 511 | -crop WxH+X+Y Crop to a rectangular region of width W and height H, |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 512 | starting at point X,Y. |
| 513 | |
Guido Vollbeding | 989630f | 2010-01-10 00:00:00 +0000 | [diff] [blame] | 514 | Other not-strictly-lossless transformation switches are: |
| 515 | |
Thomas G. Lane | 5ead57a | 1998-03-27 00:00:00 +0000 | [diff] [blame] | 516 | -grayscale Force grayscale output. |
| 517 | This option discards the chrominance channels if the input image is YCbCr |
| 518 | (ie, a standard color JPEG), resulting in a grayscale JPEG file. The |
| 519 | luminance channel is preserved exactly, so this is a better method of reducing |
| 520 | to grayscale than decompression, conversion, and recompression. This switch |
| 521 | is particularly handy for fixing a monochrome picture that was mistakenly |
| 522 | encoded as a color JPEG. (In such a case, the space savings from getting rid |
| 523 | of the near-empty chroma channels won't be large; but the decoding time for |
| 524 | a grayscale JPEG is substantially less than that for a color JPEG.) |
| 525 | |
| 526 | jpegtran also recognizes these switches that control what to do with "extra" |
| 527 | markers, such as comment blocks: |
| 528 | -copy none Copy no extra markers from source file. This setting |
| 529 | suppresses all comments and other excess baggage |
| 530 | present in the source file. |
| 531 | -copy comments Copy only comment markers. This setting copies |
DRC | 39ea562 | 2010-10-12 01:55:31 +0000 | [diff] [blame] | 532 | comments from the source file but discards |
DRC | ccd1bfd | 2012-01-31 09:53:46 +0000 | [diff] [blame] | 533 | any other data that is inessential for image display. |
Thomas G. Lane | 5ead57a | 1998-03-27 00:00:00 +0000 | [diff] [blame] | 534 | -copy all Copy all extra markers. This setting preserves |
| 535 | miscellaneous markers found in the source file, such |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 536 | as JFIF thumbnails, Exif data, and Photoshop settings. |
DRC | 39ea562 | 2010-10-12 01:55:31 +0000 | [diff] [blame] | 537 | In some files, these extra markers can be sizable. |
Thomas G. Lane | 5ead57a | 1998-03-27 00:00:00 +0000 | [diff] [blame] | 538 | The default behavior is -copy comments. (Note: in IJG releases v6 and v6a, |
| 539 | jpegtran always did the equivalent of -copy none.) |
| 540 | |
| 541 | Additional switches recognized by jpegtran are: |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 542 | -outfile filename |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 543 | -maxmemory N |
| 544 | -verbose |
| 545 | -debug |
Thomas G. Lane | 5ead57a | 1998-03-27 00:00:00 +0000 | [diff] [blame] | 546 | These work the same as in cjpeg or djpeg. |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 547 | |
| 548 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 549 | THE COMMENT UTILITIES |
| 550 | |
| 551 | The JPEG standard allows "comment" (COM) blocks to occur within a JPEG file. |
| 552 | Although the standard doesn't actually define what COM blocks are for, they |
| 553 | are widely used to hold user-supplied text strings. This lets you add |
| 554 | annotations, titles, index terms, etc to your JPEG files, and later retrieve |
| 555 | them as text. COM blocks do not interfere with the image stored in the JPEG |
| 556 | file. The maximum size of a COM block is 64K, but you can have as many of |
| 557 | them as you like in one JPEG file. |
| 558 | |
| 559 | We provide two utility programs to display COM block contents and add COM |
| 560 | blocks to a JPEG file. |
| 561 | |
| 562 | rdjpgcom searches a JPEG file and prints the contents of any COM blocks on |
| 563 | standard output. The command line syntax is |
Guido Vollbeding | 5996a25 | 2009-06-27 00:00:00 +0000 | [diff] [blame] | 564 | rdjpgcom [-raw] [-verbose] [inputfilename] |
DRC | 39ea562 | 2010-10-12 01:55:31 +0000 | [diff] [blame] | 565 | The switch "-raw" (or just "-r") causes rdjpgcom to output non-printable |
| 566 | characters in JPEG comments. These characters are normally escaped for |
| 567 | security reasons. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 568 | The switch "-verbose" (or just "-v") causes rdjpgcom to also display the JPEG |
| 569 | image dimensions. If you omit the input file name from the command line, |
| 570 | the JPEG file is read from standard input. (This may not work on some |
| 571 | operating systems, if binary data can't be read from stdin.) |
| 572 | |
| 573 | wrjpgcom adds a COM block, containing text you provide, to a JPEG file. |
| 574 | Ordinarily, the COM block is added after any existing COM blocks, but you |
| 575 | can delete the old COM blocks if you wish. wrjpgcom produces a new JPEG |
| 576 | file; it does not modify the input file. DO NOT try to overwrite the input |
| 577 | file by directing wrjpgcom's output back into it; on most systems this will |
| 578 | just destroy your file. |
| 579 | |
| 580 | The command line syntax for wrjpgcom is similar to cjpeg's. On Unix-like |
| 581 | systems, it is |
| 582 | wrjpgcom [switches] [inputfilename] |
| 583 | The output file is written to standard output. The input file comes from |
| 584 | the named file, or from standard input if no input file is named. |
| 585 | |
| 586 | On most non-Unix systems, the syntax is |
| 587 | wrjpgcom [switches] inputfilename outputfilename |
| 588 | where both input and output file names must be given explicitly. |
| 589 | |
| 590 | wrjpgcom understands three switches: |
| 591 | -replace Delete any existing COM blocks from the file. |
| 592 | -comment "Comment text" Supply new COM text on command line. |
Thomas G. Lane | 5ead57a | 1998-03-27 00:00:00 +0000 | [diff] [blame] | 593 | -cfile name Read text for new COM block from named file. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 594 | (Switch names can be abbreviated.) If you have only one line of comment text |
| 595 | to add, you can provide it on the command line with -comment. The comment |
| 596 | text must be surrounded with quotes so that it is treated as a single |
| 597 | argument. Longer comments can be read from a text file. |
| 598 | |
| 599 | If you give neither -comment nor -cfile, then wrjpgcom will read the comment |
| 600 | text from standard input. (In this case an input image file name MUST be |
| 601 | supplied, so that the source JPEG file comes from somewhere else.) You can |
| 602 | enter multiple lines, up to 64KB worth. Type an end-of-file indicator |
| 603 | (usually control-D or control-Z) to terminate the comment text entry. |
| 604 | |
| 605 | wrjpgcom will not add a COM block if the provided comment string is empty. |
| 606 | Therefore -replace -comment "" can be used to delete all COM blocks from a |
| 607 | file. |
| 608 | |
| 609 | These utility programs do not depend on the IJG JPEG library. In |
| 610 | particular, the source code for rdjpgcom is intended as an illustration of |
| 611 | the minimum amount of code required to parse a JPEG file header correctly. |