cjpeg - compress an image file to a JPEG file
cjpeg [options] [filename]
cjpeg compresses the named image file, or the standard input if no file is named, and produces a JPEG/JFIF file on the standard output. The following input file formats are currently supported:
o PGM, the PBMPLUS gray-scale format
o PPM, the PBMPLUS color format
o RLE, the Utah Raster Toolkit format
RLE is supported only if the URT library is available.
All options may be abbreviated. For example, -grayscale may be written -gray or -gr. Upper and lower case are equivalent. For example, -BMP is the same as -bmp. British spellings are also accepted. For example, -greyscale.
The following basic options are supported:
-grayscale Create a monochrome JPEG file from color input. You should use this switch when compressing a grayscale BMP file, because cjpeg cannot detect whether a BMP file uses only shades of gray. By specifying the -grayscale option, you create a smaller JPEG file that takes less time to process.
-optimize Optimize the entropy encoding parameters. If you do not specify this option, default encoding parameters are used. -optimize usually makes the JPEG file a little smaller, but cjpeg runs more slowly and needs much more memory. Image quality and speed of decompression are unaffected by the -optimize option.
-progressive Create a progressive JPEG file. For more information about the -progressive option, see the Extended Description section.
-quality N Scale the quantization tables to adjust image quality. N ranges from 0 (worst) to 100 (best). The default value is 75. For more information about the -quality option, see the Extended Description section.
-targa Specify that the input file is in Targa format. Targa files that contain an "identification" field are not automatically recognized by cjpeg. For such files, you must specify -targa to make cjpeg treat the input as Targa format. For most Targa files, you do not need this switch.
The following intermediate options are supported:
-dct fast Use the fast integer DCT method. This method is less accurate than the integer DCT method or the floating-point DCT method.
-dct float Use the floating-point DCT method. The float method is very slightly more accurate than the int method, but is much slower unless your machine has very fast floating-point hardware. The results of the floating-point method may vary slightly across machines, while the integer methods should give the same results everywhere.
-dct int Use the integer DCT method. This is the default method.
-maxmemory N Set the limit for the amount of memory to use in processing large images. N is specified in thousands of bytes, or in millions of bytes if "M" is specified with the number. For example, -max 4m selects 4000000 bytes. If more space is needed, temporary files are used.
-outfile name Send the output image to the named file, instead of to the standard output.
-restart N Emit a JPEG restart marker every N MCU rows, or every N MCU blocks if "B" is specified with the number. The default value is -restart 0, which means no restart markers. For more information about the -restart option, see the Extended Description section.
-smooth N Smooth the input image to eliminate dithering noise. N ranges from 1 to 100, and indicates the strength of smoothing. The default value is -smooth 0, which means no smoothing. For more information about the -smooth option, see the Extended Description section.
-verbose Display version information at startup, and enable debug printout. The -vv option displays more verbose output than the -v option. The -vvv option displays the most verbose output.
You can also use -debug to specify this option.
The following advanced options are supported for advanced users only:
-baseline Force baseline-compatible quantization tables to be generated. This clamps the quantization values to 8 bits, even at low quality settings. This option is poorly named, because -baseline does not ensure that the output is actually baseline JPEG. For example, you can use the -baseline and -progressive options together.
-qslots N[,...] Select which quantization table to use for each color component.
-qtables file Use the quantization tables provided in the specified text file.
-sample HxV[,...] Set the JPEG sampling factors for each color component.
-scans file Use the scan script provided in the specified text file.
The following operands are supported:
filename The name of the image file to be compressed.
The -quality Option
The -quality option enables you to trade compressed file size against the quality of the reconstructed image: the higher the quality setting, the larger the JPEG file, and the greater the similarity between the output image and the original input. Normally, you use the lowest quality setting that decompresses into an output image that is visually indistinguishable from the original image. For this purpose, the quality setting should be between 50 and 95. The default value of 75 is often just right. If you see defects at -quality 75, increase the quality by 5 until you are happy with the output image. The optimal setting varies from one image to another.
A value of -quality 100 generates a quantization table of ones. This minimizes loss in the quantization step, but information is still lost in subsampling, as well as roundoff error. The -quality 100 setting is mainly of interest for experimental purposes. Quality values above 95 are not recommended for normal use, as the compressed file size increases dramatically for very little gain in output image quality.
Quality values below 50 produce very small files of low image quality. Settings of 5 to 10 might be useful in preparing an index of a large image library, for example. Quality values below 25 generate 2-byte quantization tables, which are considered optional in the JPEG standard. cjpeg emits a warning message when you specify such a quality value, because some other JPEG programs might be unable to decode the resulting file. Use -baseline if you need to ensure compatibility at low quality values.
The -progressive Option
The -progressive option creates a "progressive JPEG" file. In this type of JPEG file, the data is stored in multiple scans of increasing quality. If the file is transmitted over a slow communications link, the decoder can use the first scan to display a low-quality image very quickly, and can then improve the display with each subsequent scan. The final image is exactly equivalent to a standard JPEG file of the same quality setting, and the total file size is about the same, or a little smaller. Caution: progressive JPEG is not yet widely implemented, so many decoders are unable to view a progressive JPEG file at all.
The -restart Option
The -restart option inserts extra markers that allow a JPEG decoder to resynchronize after a transmission error. Without restart markers, any damage to a compressed file usually ruins the image from the point of the error to the end of the image. With restart markers, the damage is usually confined to the portion of the image from the point of the error to the next restart marker. The restart markers occupy extra space. We recommend -restart 1 for images that are transmitted across unreliable networks.
The -smooth Option
The -smooth option filters the input to eliminate fine-scale noise. This option is often useful when you convert dithered images to JPEG: a moderate smoothing factor of 10 to 50 deletes dithering patterns from the input file, resulting in a smaller JPEG file and a better-looking image. If the smoothing factor is too large, the image visibly blurs.
Color GIF files are not the ideal input for JPEG. JPEG is really intended for the compression of full-color 24-bit images. In particular, do not try to convert cartoons, line drawings, or other images that have only a few distinct colors. GIF works well on these, but JPEG does not. If you want to convert a GIF file to JPEG, you should experiment with the -quality and -smooth options to get a satisfactory conversion. A value of -smooth 10 is often helpful.
Avoid running an image through a series of JPEG compression/decompression cycles. Image quality loss will accumulate. After ten cycles, the image may be noticeably worse than it was after one cycle. Use a lossless format while manipulating an image, then convert to JPEG format when you are ready to file the image away.
Use the -optimize option when you make a "final" version for posting or archiving. Also, when you use low quality settings, make very small JPEG files. The percentage improvement is often much greater than on larger files. At present, the -optimize option is always selected when generating progressive JPEG files.
Example 1: Compressing the PPM File test.ppm With a Quality Factor of 60 and Saving the Output as test.jpg
example% cjpeg -quality 60 test.ppm > test.jpg
cjpeg uses the following environment variables:
JPEGMEM The value of this environment variable, if set, is the default memory limit. The value is specified as described for the -maxmemory option. JPEGMEM overrides the default value specified when the program was compiled, and is in turn overridden by an explicit -maxmemory option.
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE ATTRIBUTE VALUE Availability SUNWjpg Interface stability Evolving
Wallace, Gregory K., The JPEG Still Picture Compression Standard Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
djpeg(1), jpegtran(1), rdjpgcom(1), wrjpgcom(1)
Arithmetic coding is not supported. GIF input files are not supported. Not all variants of BMP and Targa file formats are supported.
This man page was originally written by the Independent JPEG Group. Updated by Breda McColgan, Sun Microsystems Inc., 2004.
|SunOS 5.11||cjpeg (1)||26 Mar 2004|