17dd7cddfSDavid du ColombierUSAGE instructions for the Independent JPEG Group's JPEG software 27dd7cddfSDavid du Colombier================================================================= 37dd7cddfSDavid du Colombier 47dd7cddfSDavid du ColombierThis file describes usage of the JPEG conversion programs cjpeg and djpeg, 57dd7cddfSDavid du Colombieras well as the utility programs jpegtran, rdjpgcom and wrjpgcom. (See 67dd7cddfSDavid du Colombierthe other documentation files if you wish to use the JPEG library within 77dd7cddfSDavid du Colombieryour own programs.) 87dd7cddfSDavid du Colombier 97dd7cddfSDavid du ColombierIf you are on a Unix machine you may prefer to read the Unix-style manual 107dd7cddfSDavid du Colombierpages in files cjpeg.1, djpeg.1, jpegtran.1, rdjpgcom.1, wrjpgcom.1. 117dd7cddfSDavid du Colombier 127dd7cddfSDavid du Colombier 137dd7cddfSDavid du ColombierINTRODUCTION 147dd7cddfSDavid du Colombier 157dd7cddfSDavid du ColombierThese programs implement JPEG image compression and decompression. JPEG 167dd7cddfSDavid du Colombier(pronounced "jay-peg") is a standardized compression method for full-color 177dd7cddfSDavid du Colombierand gray-scale images. JPEG is designed to handle "real-world" scenes, 187dd7cddfSDavid du Colombierfor example scanned photographs. Cartoons, line drawings, and other 197dd7cddfSDavid du Colombiernon-realistic images are not JPEG's strong suit; on that sort of material 207dd7cddfSDavid du Colombieryou may get poor image quality and/or little compression. 217dd7cddfSDavid du Colombier 227dd7cddfSDavid du ColombierJPEG is lossy, meaning that the output image is not necessarily identical to 237dd7cddfSDavid du Colombierthe input image. Hence you should not use JPEG if you have to have identical 247dd7cddfSDavid du Colombieroutput bits. However, on typical real-world images, very good compression 257dd7cddfSDavid du Colombierlevels can be obtained with no visible change, and amazingly high compression 267dd7cddfSDavid du Colombieris possible if you can tolerate a low-quality image. You can trade off image 277dd7cddfSDavid du Colombierquality against file size by adjusting the compressor's "quality" setting. 287dd7cddfSDavid du Colombier 297dd7cddfSDavid du Colombier 307dd7cddfSDavid du ColombierGENERAL USAGE 317dd7cddfSDavid du Colombier 327dd7cddfSDavid du ColombierWe provide two programs, cjpeg to compress an image file into JPEG format, 337dd7cddfSDavid du Colombierand djpeg to decompress a JPEG file back into a conventional image format. 347dd7cddfSDavid du Colombier 357dd7cddfSDavid du ColombierOn Unix-like systems, you say: 367dd7cddfSDavid du Colombier cjpeg [switches] [imagefile] >jpegfile 377dd7cddfSDavid du Colombieror 387dd7cddfSDavid du Colombier djpeg [switches] [jpegfile] >imagefile 397dd7cddfSDavid du ColombierThe programs read the specified input file, or standard input if none is 407dd7cddfSDavid du Colombiernamed. They always write to standard output (with trace/error messages to 417dd7cddfSDavid du Colombierstandard error). These conventions are handy for piping images between 427dd7cddfSDavid du Colombierprograms. 437dd7cddfSDavid du Colombier 447dd7cddfSDavid du ColombierOn most non-Unix systems, you say: 457dd7cddfSDavid du Colombier cjpeg [switches] imagefile jpegfile 467dd7cddfSDavid du Colombieror 477dd7cddfSDavid du Colombier djpeg [switches] jpegfile imagefile 487dd7cddfSDavid du Colombieri.e., both the input and output files are named on the command line. This 497dd7cddfSDavid du Colombierstyle is a little more foolproof, and it loses no functionality if you don't 507dd7cddfSDavid du Colombierhave pipes. (You can get this style on Unix too, if you prefer, by defining 517dd7cddfSDavid du ColombierTWO_FILE_COMMANDLINE when you compile the programs; see install.doc.) 527dd7cddfSDavid du Colombier 537dd7cddfSDavid du ColombierYou can also say: 547dd7cddfSDavid du Colombier cjpeg [switches] -outfile jpegfile imagefile 557dd7cddfSDavid du Colombieror 567dd7cddfSDavid du Colombier djpeg [switches] -outfile imagefile jpegfile 577dd7cddfSDavid du ColombierThis syntax works on all systems, so it is useful for scripts. 587dd7cddfSDavid du Colombier 597dd7cddfSDavid du ColombierThe currently supported image file formats are: PPM (PBMPLUS color format), 60*593dc095SDavid du ColombierPGM (PBMPLUS gray-scale format), BMP, Targa, and RLE (Utah Raster Toolkit 617dd7cddfSDavid du Colombierformat). (RLE is supported only if the URT library is available.) 627dd7cddfSDavid du Colombiercjpeg recognizes the input image format automatically, with the exception 637dd7cddfSDavid du Colombierof some Targa-format files. You have to tell djpeg which format to generate. 647dd7cddfSDavid du Colombier 657dd7cddfSDavid du ColombierJPEG files are in the defacto standard JFIF file format. There are other, 667dd7cddfSDavid du Colombierless widely used JPEG-based file formats, but we don't support them. 677dd7cddfSDavid du Colombier 687dd7cddfSDavid du ColombierAll switch names may be abbreviated; for example, -grayscale may be written 697dd7cddfSDavid du Colombier-gray or -gr. Most of the "basic" switches can be abbreviated to as little as 70*593dc095SDavid du Colombierone letter. Upper and lower case are equivalent (-BMP is the same as -bmp). 717dd7cddfSDavid du ColombierBritish spellings are also accepted (e.g., -greyscale), though for brevity 727dd7cddfSDavid du Colombierthese are not mentioned below. 737dd7cddfSDavid du Colombier 747dd7cddfSDavid du Colombier 757dd7cddfSDavid du ColombierCJPEG DETAILS 767dd7cddfSDavid du Colombier 777dd7cddfSDavid du ColombierThe basic command line switches for cjpeg are: 787dd7cddfSDavid du Colombier 797dd7cddfSDavid du Colombier -quality N Scale quantization tables to adjust image quality. 807dd7cddfSDavid du Colombier Quality is 0 (worst) to 100 (best); default is 75. 817dd7cddfSDavid du Colombier (See below for more info.) 827dd7cddfSDavid du Colombier 837dd7cddfSDavid du Colombier -grayscale Create monochrome JPEG file from color input. 847dd7cddfSDavid du Colombier Be sure to use this switch when compressing a grayscale 85*593dc095SDavid du Colombier BMP file, because cjpeg isn't bright enough to notice 86*593dc095SDavid du Colombier whether a BMP file uses only shades of gray. By 877dd7cddfSDavid du Colombier saying -grayscale, you'll get a smaller JPEG file that 887dd7cddfSDavid du Colombier takes less time to process. 897dd7cddfSDavid du Colombier 907dd7cddfSDavid du Colombier -optimize Perform optimization of entropy encoding parameters. 917dd7cddfSDavid du Colombier Without this, default encoding parameters are used. 927dd7cddfSDavid du Colombier -optimize usually makes the JPEG file a little smaller, 937dd7cddfSDavid du Colombier but cjpeg runs somewhat slower and needs much more 947dd7cddfSDavid du Colombier memory. Image quality and speed of decompression are 957dd7cddfSDavid du Colombier unaffected by -optimize. 967dd7cddfSDavid du Colombier 977dd7cddfSDavid du Colombier -progressive Create progressive JPEG file (see below). 987dd7cddfSDavid du Colombier 997dd7cddfSDavid du Colombier -targa Input file is Targa format. Targa files that contain 1007dd7cddfSDavid du Colombier an "identification" field will not be automatically 1017dd7cddfSDavid du Colombier recognized by cjpeg; for such files you must specify 1027dd7cddfSDavid du Colombier -targa to make cjpeg treat the input as Targa format. 1037dd7cddfSDavid du Colombier For most Targa files, you won't need this switch. 1047dd7cddfSDavid du Colombier 1057dd7cddfSDavid du ColombierThe -quality switch lets you trade off compressed file size against quality of 1067dd7cddfSDavid du Colombierthe reconstructed image: the higher the quality setting, the larger the JPEG 1077dd7cddfSDavid du Colombierfile, and the closer the output image will be to the original input. Normally 1087dd7cddfSDavid du Colombieryou want to use the lowest quality setting (smallest file) that decompresses 1097dd7cddfSDavid du Colombierinto something visually indistinguishable from the original image. For this 1107dd7cddfSDavid du Colombierpurpose the quality setting should be between 50 and 95; the default of 75 is 1117dd7cddfSDavid du Colombieroften about right. If you see defects at -quality 75, then go up 5 or 10 1127dd7cddfSDavid du Colombiercounts at a time until you are happy with the output image. (The optimal 1137dd7cddfSDavid du Colombiersetting will vary from one image to another.) 1147dd7cddfSDavid du Colombier 1157dd7cddfSDavid du Colombier-quality 100 will generate a quantization table of all 1's, minimizing loss 1167dd7cddfSDavid du Colombierin the quantization step (but there is still information loss in subsampling, 1177dd7cddfSDavid du Colombieras well as roundoff error). This setting is mainly of interest for 1187dd7cddfSDavid du Colombierexperimental purposes. Quality values above about 95 are NOT recommended for 1197dd7cddfSDavid du Colombiernormal use; the compressed file size goes up dramatically for hardly any gain 1207dd7cddfSDavid du Colombierin output image quality. 1217dd7cddfSDavid du Colombier 1227dd7cddfSDavid du ColombierIn the other direction, quality values below 50 will produce very small files 1237dd7cddfSDavid du Colombierof low image quality. Settings around 5 to 10 might be useful in preparing an 1247dd7cddfSDavid du Colombierindex of a large image library, for example. Try -quality 2 (or so) for some 1257dd7cddfSDavid du Colombieramusing Cubist effects. (Note: quality values below about 25 generate 2-byte 1267dd7cddfSDavid du Colombierquantization tables, which are considered optional in the JPEG standard. 1277dd7cddfSDavid du Colombiercjpeg emits a warning message when you give such a quality value, because some 1287dd7cddfSDavid du Colombierother JPEG programs may be unable to decode the resulting file. Use -baseline 1297dd7cddfSDavid du Colombierif you need to ensure compatibility at low quality values.) 1307dd7cddfSDavid du Colombier 1317dd7cddfSDavid du ColombierThe -progressive switch creates a "progressive JPEG" file. In this type of 1327dd7cddfSDavid du ColombierJPEG file, the data is stored in multiple scans of increasing quality. If the 1337dd7cddfSDavid du Colombierfile is being transmitted over a slow communications link, the decoder can use 1347dd7cddfSDavid du Colombierthe first scan to display a low-quality image very quickly, and can then 1357dd7cddfSDavid du Colombierimprove the display with each subsequent scan. The final image is exactly 1367dd7cddfSDavid du Colombierequivalent to a standard JPEG file of the same quality setting, and the total 1377dd7cddfSDavid du Colombierfile size is about the same --- often a little smaller. CAUTION: progressive 1387dd7cddfSDavid du ColombierJPEG is not yet widely implemented, so many decoders will be unable to view a 1397dd7cddfSDavid du Colombierprogressive JPEG file at all. 1407dd7cddfSDavid du Colombier 1417dd7cddfSDavid du ColombierSwitches for advanced users: 1427dd7cddfSDavid du Colombier 1437dd7cddfSDavid du Colombier -dct int Use integer DCT method (default). 1447dd7cddfSDavid du Colombier -dct fast Use fast integer DCT (less accurate). 1457dd7cddfSDavid du Colombier -dct float Use floating-point DCT method. 1467dd7cddfSDavid du Colombier The float method is very slightly more accurate than 1477dd7cddfSDavid du Colombier the int method, but is much slower unless your machine 1487dd7cddfSDavid du Colombier has very fast floating-point hardware. Also note that 1497dd7cddfSDavid du Colombier results of the floating-point method may vary slightly 1507dd7cddfSDavid du Colombier across machines, while the integer methods should give 1517dd7cddfSDavid du Colombier the same results everywhere. The fast integer method 1527dd7cddfSDavid du Colombier is much less accurate than the other two. 1537dd7cddfSDavid du Colombier 1547dd7cddfSDavid du Colombier -restart N Emit a JPEG restart marker every N MCU rows, or every 1557dd7cddfSDavid du Colombier N MCU blocks if "B" is attached to the number. 1567dd7cddfSDavid du Colombier -restart 0 (the default) means no restart markers. 1577dd7cddfSDavid du Colombier 1587dd7cddfSDavid du Colombier -smooth N Smooth the input image to eliminate dithering noise. 1597dd7cddfSDavid du Colombier N, ranging from 1 to 100, indicates the strength of 1607dd7cddfSDavid du Colombier smoothing. 0 (the default) means no smoothing. 1617dd7cddfSDavid du Colombier 1627dd7cddfSDavid du Colombier -maxmemory N Set limit for amount of memory to use in processing 1637dd7cddfSDavid du Colombier large images. Value is in thousands of bytes, or 1647dd7cddfSDavid du Colombier millions of bytes if "M" is attached to the number. 1657dd7cddfSDavid du Colombier For example, -max 4m selects 4000000 bytes. If more 1667dd7cddfSDavid du Colombier space is needed, temporary files will be used. 1677dd7cddfSDavid du Colombier 1687dd7cddfSDavid du Colombier -verbose Enable debug printout. More -v's give more printout. 1697dd7cddfSDavid du Colombier or -debug Also, version information is printed at startup. 1707dd7cddfSDavid du Colombier 1717dd7cddfSDavid du ColombierThe -restart option inserts extra markers that allow a JPEG decoder to 1727dd7cddfSDavid du Colombierresynchronize after a transmission error. Without restart markers, any damage 1737dd7cddfSDavid du Colombierto a compressed file will usually ruin the image from the point of the error 1747dd7cddfSDavid du Colombierto the end of the image; with restart markers, the damage is usually confined 1757dd7cddfSDavid du Colombierto the portion of the image up to the next restart marker. Of course, the 1767dd7cddfSDavid du Colombierrestart markers occupy extra space. We recommend -restart 1 for images that 1777dd7cddfSDavid du Colombierwill be transmitted across unreliable networks such as Usenet. 1787dd7cddfSDavid du Colombier 1797dd7cddfSDavid du ColombierThe -smooth option filters the input to eliminate fine-scale noise. This is 180*593dc095SDavid du Colombieroften useful when converting dithered images to JPEG: a moderate smoothing 181*593dc095SDavid du Colombierfactor of 10 to 50 gets rid of dithering patterns in the input file, resulting 182*593dc095SDavid du Colombierin a smaller JPEG file and a better-looking image. Too large a smoothing 183*593dc095SDavid du Colombierfactor will visibly blur the image, however. 1847dd7cddfSDavid du Colombier 1857dd7cddfSDavid du ColombierSwitches for wizards: 1867dd7cddfSDavid du Colombier 187*593dc095SDavid du Colombier -baseline Force baseline-compatible quantization tables to be 188*593dc095SDavid du Colombier generated. This clamps quantization values to 8 bits 189*593dc095SDavid du Colombier even at low quality settings. (This switch is poorly 190*593dc095SDavid du Colombier named, since it does not ensure that the output is 191*593dc095SDavid du Colombier actually baseline JPEG. For example, you can use 192*593dc095SDavid du Colombier -baseline and -progressive together.) 1937dd7cddfSDavid du Colombier 1947dd7cddfSDavid du Colombier -qtables file Use the quantization tables given in the specified 1957dd7cddfSDavid du Colombier text file. 1967dd7cddfSDavid du Colombier 1977dd7cddfSDavid du Colombier -qslots N[,...] Select which quantization table to use for each color 1987dd7cddfSDavid du Colombier component. 1997dd7cddfSDavid du Colombier 2007dd7cddfSDavid du Colombier -sample HxV[,...] Set JPEG sampling factors for each color component. 2017dd7cddfSDavid du Colombier 2027dd7cddfSDavid du Colombier -scans file Use the scan script given in the specified text file. 2037dd7cddfSDavid du Colombier 2047dd7cddfSDavid du ColombierThe "wizard" switches are intended for experimentation with JPEG. If you 2057dd7cddfSDavid du Colombierdon't know what you are doing, DON'T USE THEM. These switches are documented 2067dd7cddfSDavid du Colombierfurther in the file wizard.doc. 2077dd7cddfSDavid du Colombier 2087dd7cddfSDavid du Colombier 2097dd7cddfSDavid du ColombierDJPEG DETAILS 2107dd7cddfSDavid du Colombier 2117dd7cddfSDavid du ColombierThe basic command line switches for djpeg are: 2127dd7cddfSDavid du Colombier 2137dd7cddfSDavid du Colombier -colors N Reduce image to at most N colors. This reduces the 2147dd7cddfSDavid du Colombier or -quantize N number of colors used in the output image, so that it 2157dd7cddfSDavid du Colombier can be displayed on a colormapped display or stored in 2167dd7cddfSDavid du Colombier a colormapped file format. For example, if you have 2177dd7cddfSDavid du Colombier an 8-bit display, you'd need to reduce to 256 or fewer 2187dd7cddfSDavid du Colombier colors. (-colors is the recommended name, -quantize 2197dd7cddfSDavid du Colombier is provided only for backwards compatibility.) 2207dd7cddfSDavid du Colombier 2217dd7cddfSDavid du Colombier -fast Select recommended processing options for fast, low 2227dd7cddfSDavid du Colombier quality output. (The default options are chosen for 2237dd7cddfSDavid du Colombier highest quality output.) Currently, this is equivalent 2247dd7cddfSDavid du Colombier to "-dct fast -nosmooth -onepass -dither ordered". 2257dd7cddfSDavid du Colombier 2267dd7cddfSDavid du Colombier -grayscale Force gray-scale output even if JPEG file is color. 2277dd7cddfSDavid du Colombier Useful for viewing on monochrome displays; also, 2287dd7cddfSDavid du Colombier djpeg runs noticeably faster in this mode. 2297dd7cddfSDavid du Colombier 2307dd7cddfSDavid du Colombier -scale M/N Scale the output image by a factor M/N. Currently 2317dd7cddfSDavid du Colombier the scale factor must be 1/1, 1/2, 1/4, or 1/8. 2327dd7cddfSDavid du Colombier Scaling is handy if the image is larger than your 2337dd7cddfSDavid du Colombier screen; also, djpeg runs much faster when scaling 2347dd7cddfSDavid du Colombier down the output. 2357dd7cddfSDavid du Colombier 2367dd7cddfSDavid du Colombier -bmp Select BMP output format (Windows flavor). 8-bit 2377dd7cddfSDavid du Colombier colormapped format is emitted if -colors or -grayscale 2387dd7cddfSDavid du Colombier is specified, or if the JPEG file is gray-scale; 2397dd7cddfSDavid du Colombier otherwise, 24-bit full-color format is emitted. 2407dd7cddfSDavid du Colombier 2417dd7cddfSDavid du Colombier -gif Select GIF output format. Since GIF does not support 2427dd7cddfSDavid du Colombier more than 256 colors, -colors 256 is assumed (unless 2437dd7cddfSDavid du Colombier you specify a smaller number of colors). If you 2447dd7cddfSDavid du Colombier specify -fast, the default number of colors is 216. 2457dd7cddfSDavid du Colombier 2467dd7cddfSDavid du Colombier -os2 Select BMP output format (OS/2 1.x flavor). 8-bit 2477dd7cddfSDavid du Colombier colormapped format is emitted if -colors or -grayscale 2487dd7cddfSDavid du Colombier is specified, or if the JPEG file is gray-scale; 2497dd7cddfSDavid du Colombier otherwise, 24-bit full-color format is emitted. 2507dd7cddfSDavid du Colombier 2517dd7cddfSDavid du Colombier -pnm Select PBMPLUS (PPM/PGM) output format (this is the 2527dd7cddfSDavid du Colombier default format). PGM is emitted if the JPEG file is 2537dd7cddfSDavid du Colombier gray-scale or if -grayscale is specified; otherwise 2547dd7cddfSDavid du Colombier PPM is emitted. 2557dd7cddfSDavid du Colombier 2567dd7cddfSDavid du Colombier -rle Select RLE output format. (Requires URT library.) 2577dd7cddfSDavid du Colombier 2587dd7cddfSDavid du Colombier -targa Select Targa output format. Gray-scale format is 2597dd7cddfSDavid du Colombier emitted if the JPEG file is gray-scale or if 2607dd7cddfSDavid du Colombier -grayscale is specified; otherwise, colormapped format 2617dd7cddfSDavid du Colombier is emitted if -colors is specified; otherwise, 24-bit 2627dd7cddfSDavid du Colombier full-color format is emitted. 2637dd7cddfSDavid du Colombier 2647dd7cddfSDavid du ColombierSwitches for advanced users: 2657dd7cddfSDavid du Colombier 2667dd7cddfSDavid du Colombier -dct int Use integer DCT method (default). 2677dd7cddfSDavid du Colombier -dct fast Use fast integer DCT (less accurate). 2687dd7cddfSDavid du Colombier -dct float Use floating-point DCT method. 2697dd7cddfSDavid du Colombier The float method is very slightly more accurate than 2707dd7cddfSDavid du Colombier the int method, but is much slower unless your machine 2717dd7cddfSDavid du Colombier has very fast floating-point hardware. Also note that 2727dd7cddfSDavid du Colombier results of the floating-point method may vary slightly 2737dd7cddfSDavid du Colombier across machines, while the integer methods should give 2747dd7cddfSDavid du Colombier the same results everywhere. The fast integer method 2757dd7cddfSDavid du Colombier is much less accurate than the other two. 2767dd7cddfSDavid du Colombier 2777dd7cddfSDavid du Colombier -dither fs Use Floyd-Steinberg dithering in color quantization. 2787dd7cddfSDavid du Colombier -dither ordered Use ordered dithering in color quantization. 2797dd7cddfSDavid du Colombier -dither none Do not use dithering in color quantization. 2807dd7cddfSDavid du Colombier By default, Floyd-Steinberg dithering is applied when 2817dd7cddfSDavid du Colombier quantizing colors; this is slow but usually produces 2827dd7cddfSDavid du Colombier the best results. Ordered dither is a compromise 2837dd7cddfSDavid du Colombier between speed and quality; no dithering is fast but 2847dd7cddfSDavid du Colombier usually looks awful. Note that these switches have 2857dd7cddfSDavid du Colombier no effect unless color quantization is being done. 2867dd7cddfSDavid du Colombier Ordered dither is only available in -onepass mode. 2877dd7cddfSDavid du Colombier 2887dd7cddfSDavid du Colombier -map FILE Quantize to the colors used in the specified image 2897dd7cddfSDavid du Colombier file. This is useful for producing multiple files 2907dd7cddfSDavid du Colombier with identical color maps, or for forcing a predefined 2917dd7cddfSDavid du Colombier set of colors to be used. The FILE must be a GIF 2927dd7cddfSDavid du Colombier or PPM file. This option overrides -colors and 2937dd7cddfSDavid du Colombier -onepass. 2947dd7cddfSDavid du Colombier 2957dd7cddfSDavid du Colombier -nosmooth Use a faster, lower-quality upsampling routine. 2967dd7cddfSDavid du Colombier 2977dd7cddfSDavid du Colombier -onepass Use one-pass instead of two-pass color quantization. 2987dd7cddfSDavid du Colombier The one-pass method is faster and needs less memory, 2997dd7cddfSDavid du Colombier but it produces a lower-quality image. -onepass is 3007dd7cddfSDavid du Colombier ignored unless you also say -colors N. Also, 3017dd7cddfSDavid du Colombier the one-pass method is always used for gray-scale 3027dd7cddfSDavid du Colombier output (the two-pass method is no improvement then). 3037dd7cddfSDavid du Colombier 3047dd7cddfSDavid du Colombier -maxmemory N Set limit for amount of memory to use in processing 3057dd7cddfSDavid du Colombier large images. Value is in thousands of bytes, or 3067dd7cddfSDavid du Colombier millions of bytes if "M" is attached to the number. 3077dd7cddfSDavid du Colombier For example, -max 4m selects 4000000 bytes. If more 3087dd7cddfSDavid du Colombier space is needed, temporary files will be used. 3097dd7cddfSDavid du Colombier 3107dd7cddfSDavid du Colombier -verbose Enable debug printout. More -v's give more printout. 3117dd7cddfSDavid du Colombier or -debug Also, version information is printed at startup. 3127dd7cddfSDavid du Colombier 3137dd7cddfSDavid du Colombier 3147dd7cddfSDavid du ColombierHINTS FOR CJPEG 3157dd7cddfSDavid du Colombier 3167dd7cddfSDavid du ColombierColor GIF files are not the ideal input for JPEG; JPEG is really intended for 3177dd7cddfSDavid du Colombiercompressing full-color (24-bit) images. In particular, don't try to convert 3187dd7cddfSDavid du Colombiercartoons, line drawings, and other images that have only a few distinct 3197dd7cddfSDavid du Colombiercolors. GIF works great on these, JPEG does not. If you want to convert a 3207dd7cddfSDavid du ColombierGIF to JPEG, you should experiment with cjpeg's -quality and -smooth options 3217dd7cddfSDavid du Colombierto get a satisfactory conversion. -smooth 10 or so is often helpful. 3227dd7cddfSDavid du Colombier 3237dd7cddfSDavid du ColombierAvoid running an image through a series of JPEG compression/decompression 3247dd7cddfSDavid du Colombiercycles. Image quality loss will accumulate; after ten or so cycles the image 3257dd7cddfSDavid du Colombiermay be noticeably worse than it was after one cycle. It's best to use a 3267dd7cddfSDavid du Colombierlossless format while manipulating an image, then convert to JPEG format when 3277dd7cddfSDavid du Colombieryou are ready to file the image away. 3287dd7cddfSDavid du Colombier 3297dd7cddfSDavid du ColombierThe -optimize option to cjpeg is worth using when you are making a "final" 3307dd7cddfSDavid du Colombierversion for posting or archiving. It's also a win when you are using low 3317dd7cddfSDavid du Colombierquality settings to make very small JPEG files; the percentage improvement 3327dd7cddfSDavid du Colombieris often a lot more than it is on larger files. (At present, -optimize 3337dd7cddfSDavid du Colombiermode is always selected when generating progressive JPEG files.) 3347dd7cddfSDavid du Colombier 335*593dc095SDavid du ColombierGIF input files are no longer supported, to avoid the Unisys LZW patent. 336*593dc095SDavid du ColombierUse a Unisys-licensed program if you need to read a GIF file. (Conversion 337*593dc095SDavid du Colombierof GIF files to JPEG is usually a bad idea anyway.) 338*593dc095SDavid du Colombier 3397dd7cddfSDavid du Colombier 3407dd7cddfSDavid du ColombierHINTS FOR DJPEG 3417dd7cddfSDavid du Colombier 3427dd7cddfSDavid du ColombierTo get a quick preview of an image, use the -grayscale and/or -scale switches. 3437dd7cddfSDavid du Colombier"-grayscale -scale 1/8" is the fastest case. 3447dd7cddfSDavid du Colombier 3457dd7cddfSDavid du ColombierSeveral options are available that trade off image quality to gain speed. 3467dd7cddfSDavid du Colombier"-fast" turns on the recommended settings. 3477dd7cddfSDavid du Colombier 3487dd7cddfSDavid du Colombier"-dct fast" and/or "-nosmooth" gain speed at a small sacrifice in quality. 3497dd7cddfSDavid du ColombierWhen producing a color-quantized image, "-onepass -dither ordered" is fast but 3507dd7cddfSDavid du Colombiermuch lower quality than the default behavior. "-dither none" may give 3517dd7cddfSDavid du Colombieracceptable results in two-pass mode, but is seldom tolerable in one-pass mode. 3527dd7cddfSDavid du Colombier 3537dd7cddfSDavid du ColombierIf you are fortunate enough to have very fast floating point hardware, 3547dd7cddfSDavid du Colombier"-dct float" may be even faster than "-dct fast". But on most machines 3557dd7cddfSDavid du Colombier"-dct float" is slower than "-dct int"; in this case it is not worth using, 3567dd7cddfSDavid du Colombierbecause its theoretical accuracy advantage is too small to be significant 3577dd7cddfSDavid du Colombierin practice. 3587dd7cddfSDavid du Colombier 3597dd7cddfSDavid du ColombierTwo-pass color quantization requires a good deal of memory; on MS-DOS machines 3607dd7cddfSDavid du Colombierit may run out of memory even with -maxmemory 0. In that case you can still 3617dd7cddfSDavid du Colombierdecompress, with some loss of image quality, by specifying -onepass for 3627dd7cddfSDavid du Colombierone-pass quantization. 3637dd7cddfSDavid du Colombier 364*593dc095SDavid du ColombierTo avoid the Unisys LZW patent, djpeg produces uncompressed GIF files. These 365*593dc095SDavid du Colombierare larger than they should be, but are readable by standard GIF decoders. 366*593dc095SDavid du Colombier 3677dd7cddfSDavid du Colombier 3687dd7cddfSDavid du ColombierHINTS FOR BOTH PROGRAMS 3697dd7cddfSDavid du Colombier 3707dd7cddfSDavid du ColombierIf more space is needed than will fit in the available main memory (as 3717dd7cddfSDavid du Colombierdetermined by -maxmemory), temporary files will be used. (MS-DOS versions 3727dd7cddfSDavid du Colombierwill try to get extended or expanded memory first.) The temporary files are 3737dd7cddfSDavid du Colombieroften rather large: in typical cases they occupy three bytes per pixel, for 3747dd7cddfSDavid du Colombierexample 3*800*600 = 1.44Mb for an 800x600 image. If you don't have enough 3757dd7cddfSDavid du Colombierfree disk space, leave out -progressive and -optimize (for cjpeg) or specify 3767dd7cddfSDavid du Colombier-onepass (for djpeg). 3777dd7cddfSDavid du Colombier 3787dd7cddfSDavid du ColombierOn MS-DOS, the temporary files are created in the directory named by the TMP 3797dd7cddfSDavid du Colombieror TEMP environment variable, or in the current directory if neither of those 3807dd7cddfSDavid du Colombierexist. Amiga implementations put the temp files in the directory named by 3817dd7cddfSDavid du ColombierJPEGTMP:, so be sure to assign JPEGTMP: to a disk partition with adequate free 3827dd7cddfSDavid du Colombierspace. 3837dd7cddfSDavid du Colombier 3847dd7cddfSDavid du ColombierThe default memory usage limit (-maxmemory) is set when the software is 3857dd7cddfSDavid du Colombiercompiled. If you get an "insufficient memory" error, try specifying a smaller 3867dd7cddfSDavid du Colombier-maxmemory value, even -maxmemory 0 to use the absolute minimum space. You 3877dd7cddfSDavid du Colombiermay want to recompile with a smaller default value if this happens often. 3887dd7cddfSDavid du Colombier 3897dd7cddfSDavid du ColombierOn machines that have "environment" variables, you can define the environment 3907dd7cddfSDavid du Colombiervariable JPEGMEM to set the default memory limit. The value is specified as 3917dd7cddfSDavid du Colombierdescribed for the -maxmemory switch. JPEGMEM overrides the default value 3927dd7cddfSDavid du Colombierspecified when the program was compiled, and itself is overridden by an 3937dd7cddfSDavid du Colombierexplicit -maxmemory switch. 3947dd7cddfSDavid du Colombier 3957dd7cddfSDavid du ColombierOn MS-DOS machines, -maxmemory is the amount of main (conventional) memory to 3967dd7cddfSDavid du Colombieruse. (Extended or expanded memory is also used if available.) Most 3977dd7cddfSDavid du ColombierDOS-specific versions of this software do their own memory space estimation 3987dd7cddfSDavid du Colombierand do not need you to specify -maxmemory. 3997dd7cddfSDavid du Colombier 4007dd7cddfSDavid du Colombier 4017dd7cddfSDavid du ColombierJPEGTRAN 4027dd7cddfSDavid du Colombier 403*593dc095SDavid du Colombierjpegtran performs various useful transformations of JPEG files. 404*593dc095SDavid du ColombierIt can translate the coded representation from one variant of JPEG to another, 405*593dc095SDavid du Colombierfor example from baseline JPEG to progressive JPEG or vice versa. It can also 406*593dc095SDavid du Colombierperform some rearrangements of the image data, for example turning an image 407*593dc095SDavid du Colombierfrom landscape to portrait format by rotation. 4087dd7cddfSDavid du Colombier 409*593dc095SDavid du Colombierjpegtran works by rearranging the compressed data (DCT coefficients), without 410*593dc095SDavid du Colombierever fully decoding the image. Therefore, its transformations are lossless: 411*593dc095SDavid du Colombierthere is no image degradation at all, which would not be true if you used 412*593dc095SDavid du Colombierdjpeg followed by cjpeg to accomplish the same conversion. But by the same 413*593dc095SDavid du Colombiertoken, jpegtran cannot perform lossy operations such as changing the image 414*593dc095SDavid du Colombierquality. 4157dd7cddfSDavid du Colombier 416*593dc095SDavid du Colombierjpegtran uses a command line syntax similar to cjpeg or djpeg. 417*593dc095SDavid du ColombierOn Unix-like systems, you say: 418*593dc095SDavid du Colombier jpegtran [switches] [inputfile] >outputfile 419*593dc095SDavid du ColombierOn most non-Unix systems, you say: 420*593dc095SDavid du Colombier jpegtran [switches] inputfile outputfile 421*593dc095SDavid du Colombierwhere both the input and output files are JPEG files. 422*593dc095SDavid du Colombier 423*593dc095SDavid du ColombierTo specify the coded JPEG representation used in the output file, 4247dd7cddfSDavid du Colombierjpegtran accepts a subset of the switches recognized by cjpeg: 425*593dc095SDavid du Colombier -optimize Perform optimization of entropy encoding parameters. 426*593dc095SDavid du Colombier -progressive Create progressive JPEG file. 427*593dc095SDavid du Colombier -restart N Emit a JPEG restart marker every N MCU rows, or every 428*593dc095SDavid du Colombier N MCU blocks if "B" is attached to the number. 429*593dc095SDavid du Colombier -scans file Use the scan script given in the specified text file. 430*593dc095SDavid du ColombierSee the previous discussion of cjpeg for more details about these switches. 431*593dc095SDavid du ColombierIf you specify none of these switches, you get a plain baseline-JPEG output 432*593dc095SDavid du Colombierfile. The quality setting and so forth are determined by the input file. 433*593dc095SDavid du Colombier 434*593dc095SDavid du ColombierThe image can be losslessly transformed by giving one of these switches: 435*593dc095SDavid du Colombier -flip horizontal Mirror image horizontally (left-right). 436*593dc095SDavid du Colombier -flip vertical Mirror image vertically (top-bottom). 437*593dc095SDavid du Colombier -rotate 90 Rotate image 90 degrees clockwise. 438*593dc095SDavid du Colombier -rotate 180 Rotate image 180 degrees. 439*593dc095SDavid du Colombier -rotate 270 Rotate image 270 degrees clockwise (or 90 ccw). 440*593dc095SDavid du Colombier -transpose Transpose image (across UL-to-LR axis). 441*593dc095SDavid du Colombier -transverse Transverse transpose (across UR-to-LL axis). 442*593dc095SDavid du Colombier 443*593dc095SDavid du ColombierThe transpose transformation has no restrictions regarding image dimensions. 444*593dc095SDavid du ColombierThe other transformations operate rather oddly if the image dimensions are not 445*593dc095SDavid du Colombiera multiple of the iMCU size (usually 8 or 16 pixels), because they can only 446*593dc095SDavid du Colombiertransform complete blocks of DCT coefficient data in the desired way. 447*593dc095SDavid du Colombier 448*593dc095SDavid du Colombierjpegtran's default behavior when transforming an odd-size image is designed 449*593dc095SDavid du Colombierto preserve exact reversibility and mathematical consistency of the 450*593dc095SDavid du Colombiertransformation set. As stated, transpose is able to flip the entire image 451*593dc095SDavid du Colombierarea. Horizontal mirroring leaves any partial iMCU column at the right edge 452*593dc095SDavid du Colombieruntouched, but is able to flip all rows of the image. Similarly, vertical 453*593dc095SDavid du Colombiermirroring leaves any partial iMCU row at the bottom edge untouched, but is 454*593dc095SDavid du Colombierable to flip all columns. The other transforms can be built up as sequences 455*593dc095SDavid du Colombierof transpose and flip operations; for consistency, their actions on edge 456*593dc095SDavid du Colombierpixels are defined to be the same as the end result of the corresponding 457*593dc095SDavid du Colombiertranspose-and-flip sequence. 458*593dc095SDavid du Colombier 459*593dc095SDavid du ColombierFor practical use, you may prefer to discard any untransformable edge pixels 460*593dc095SDavid du Colombierrather than having a strange-looking strip along the right and/or bottom edges 461*593dc095SDavid du Colombierof a transformed image. To do this, add the -trim switch: 462*593dc095SDavid du Colombier -trim Drop non-transformable edge blocks. 463*593dc095SDavid du ColombierObviously, a transformation with -trim is not reversible, so strictly speaking 464*593dc095SDavid du Colombierjpegtran with this switch is not lossless. Also, the expected mathematical 465*593dc095SDavid du Colombierequivalences between the transformations no longer hold. For example, 466*593dc095SDavid du Colombier"-rot 270 -trim" trims only the bottom edge, but "-rot 90 -trim" followed by 467*593dc095SDavid du Colombier"-rot 180 -trim" trims both edges. 468*593dc095SDavid du Colombier 469*593dc095SDavid du ColombierAnother not-strictly-lossless transformation switch is: 470*593dc095SDavid du Colombier -grayscale Force grayscale output. 471*593dc095SDavid du ColombierThis option discards the chrominance channels if the input image is YCbCr 472*593dc095SDavid du Colombier(ie, a standard color JPEG), resulting in a grayscale JPEG file. The 473*593dc095SDavid du Colombierluminance channel is preserved exactly, so this is a better method of reducing 474*593dc095SDavid du Colombierto grayscale than decompression, conversion, and recompression. This switch 475*593dc095SDavid du Colombieris particularly handy for fixing a monochrome picture that was mistakenly 476*593dc095SDavid du Colombierencoded as a color JPEG. (In such a case, the space savings from getting rid 477*593dc095SDavid du Colombierof the near-empty chroma channels won't be large; but the decoding time for 478*593dc095SDavid du Colombiera grayscale JPEG is substantially less than that for a color JPEG.) 479*593dc095SDavid du Colombier 480*593dc095SDavid du Colombierjpegtran also recognizes these switches that control what to do with "extra" 481*593dc095SDavid du Colombiermarkers, such as comment blocks: 482*593dc095SDavid du Colombier -copy none Copy no extra markers from source file. This setting 483*593dc095SDavid du Colombier suppresses all comments and other excess baggage 484*593dc095SDavid du Colombier present in the source file. 485*593dc095SDavid du Colombier -copy comments Copy only comment markers. This setting copies 486*593dc095SDavid du Colombier comments from the source file, but discards 487*593dc095SDavid du Colombier any other inessential data. 488*593dc095SDavid du Colombier -copy all Copy all extra markers. This setting preserves 489*593dc095SDavid du Colombier miscellaneous markers found in the source file, such 490*593dc095SDavid du Colombier as JFIF thumbnails and Photoshop settings. In some 491*593dc095SDavid du Colombier files these extra markers can be sizable. 492*593dc095SDavid du ColombierThe default behavior is -copy comments. (Note: in IJG releases v6 and v6a, 493*593dc095SDavid du Colombierjpegtran always did the equivalent of -copy none.) 494*593dc095SDavid du Colombier 495*593dc095SDavid du ColombierAdditional switches recognized by jpegtran are: 4967dd7cddfSDavid du Colombier -outfile filename 4977dd7cddfSDavid du Colombier -maxmemory N 4987dd7cddfSDavid du Colombier -verbose 4997dd7cddfSDavid du Colombier -debug 500*593dc095SDavid du ColombierThese work the same as in cjpeg or djpeg. 5017dd7cddfSDavid du Colombier 5027dd7cddfSDavid du Colombier 5037dd7cddfSDavid du ColombierTHE COMMENT UTILITIES 5047dd7cddfSDavid du Colombier 5057dd7cddfSDavid du ColombierThe JPEG standard allows "comment" (COM) blocks to occur within a JPEG file. 5067dd7cddfSDavid du ColombierAlthough the standard doesn't actually define what COM blocks are for, they 5077dd7cddfSDavid du Colombierare widely used to hold user-supplied text strings. This lets you add 5087dd7cddfSDavid du Colombierannotations, titles, index terms, etc to your JPEG files, and later retrieve 5097dd7cddfSDavid du Colombierthem as text. COM blocks do not interfere with the image stored in the JPEG 5107dd7cddfSDavid du Colombierfile. The maximum size of a COM block is 64K, but you can have as many of 5117dd7cddfSDavid du Colombierthem as you like in one JPEG file. 5127dd7cddfSDavid du Colombier 5137dd7cddfSDavid du ColombierWe provide two utility programs to display COM block contents and add COM 5147dd7cddfSDavid du Colombierblocks to a JPEG file. 5157dd7cddfSDavid du Colombier 5167dd7cddfSDavid du Colombierrdjpgcom searches a JPEG file and prints the contents of any COM blocks on 5177dd7cddfSDavid du Colombierstandard output. The command line syntax is 5187dd7cddfSDavid du Colombier rdjpgcom [-verbose] [inputfilename] 5197dd7cddfSDavid du ColombierThe switch "-verbose" (or just "-v") causes rdjpgcom to also display the JPEG 5207dd7cddfSDavid du Colombierimage dimensions. If you omit the input file name from the command line, 5217dd7cddfSDavid du Colombierthe JPEG file is read from standard input. (This may not work on some 5227dd7cddfSDavid du Colombieroperating systems, if binary data can't be read from stdin.) 5237dd7cddfSDavid du Colombier 5247dd7cddfSDavid du Colombierwrjpgcom adds a COM block, containing text you provide, to a JPEG file. 5257dd7cddfSDavid du ColombierOrdinarily, the COM block is added after any existing COM blocks, but you 5267dd7cddfSDavid du Colombiercan delete the old COM blocks if you wish. wrjpgcom produces a new JPEG 5277dd7cddfSDavid du Colombierfile; it does not modify the input file. DO NOT try to overwrite the input 5287dd7cddfSDavid du Colombierfile by directing wrjpgcom's output back into it; on most systems this will 5297dd7cddfSDavid du Colombierjust destroy your file. 5307dd7cddfSDavid du Colombier 5317dd7cddfSDavid du ColombierThe command line syntax for wrjpgcom is similar to cjpeg's. On Unix-like 5327dd7cddfSDavid du Colombiersystems, it is 5337dd7cddfSDavid du Colombier wrjpgcom [switches] [inputfilename] 5347dd7cddfSDavid du ColombierThe output file is written to standard output. The input file comes from 5357dd7cddfSDavid du Colombierthe named file, or from standard input if no input file is named. 5367dd7cddfSDavid du Colombier 5377dd7cddfSDavid du ColombierOn most non-Unix systems, the syntax is 5387dd7cddfSDavid du Colombier wrjpgcom [switches] inputfilename outputfilename 5397dd7cddfSDavid du Colombierwhere both input and output file names must be given explicitly. 5407dd7cddfSDavid du Colombier 5417dd7cddfSDavid du Colombierwrjpgcom understands three switches: 5427dd7cddfSDavid du Colombier -replace Delete any existing COM blocks from the file. 5437dd7cddfSDavid du Colombier -comment "Comment text" Supply new COM text on command line. 5447dd7cddfSDavid du Colombier -cfile name Read text for new COM block from named file. 5457dd7cddfSDavid du Colombier(Switch names can be abbreviated.) If you have only one line of comment text 5467dd7cddfSDavid du Colombierto add, you can provide it on the command line with -comment. The comment 5477dd7cddfSDavid du Colombiertext must be surrounded with quotes so that it is treated as a single 5487dd7cddfSDavid du Colombierargument. Longer comments can be read from a text file. 5497dd7cddfSDavid du Colombier 5507dd7cddfSDavid du ColombierIf you give neither -comment nor -cfile, then wrjpgcom will read the comment 5517dd7cddfSDavid du Colombiertext from standard input. (In this case an input image file name MUST be 5527dd7cddfSDavid du Colombiersupplied, so that the source JPEG file comes from somewhere else.) You can 5537dd7cddfSDavid du Colombierenter multiple lines, up to 64KB worth. Type an end-of-file indicator 5547dd7cddfSDavid du Colombier(usually control-D or control-Z) to terminate the comment text entry. 5557dd7cddfSDavid du Colombier 5567dd7cddfSDavid du Colombierwrjpgcom will not add a COM block if the provided comment string is empty. 5577dd7cddfSDavid du ColombierTherefore -replace -comment "" can be used to delete all COM blocks from a 5587dd7cddfSDavid du Colombierfile. 5597dd7cddfSDavid du Colombier 5607dd7cddfSDavid du ColombierThese utility programs do not depend on the IJG JPEG library. In 5617dd7cddfSDavid du Colombierparticular, the source code for rdjpgcom is intended as an illustration of 5627dd7cddfSDavid du Colombierthe minimum amount of code required to parse a JPEG file header correctly. 563