User Commands cjpeg(1)
NAME
cjpeg - compress an image file to a JPEG file
SYNOPSIS
cjpeg [options] [filename]
DESCRIPTION
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 BMP
+o PGM, the PBMPLUS gray-scale format
+o PPM, the PBMPLUS color format +o RLE, the Utah Raster Toolkit format +o Targa RLE is supported only if the URT library is available. OPTIONSAll 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.
Basic Options The following basic options are supported:-grayscale Create a monochrome JPEG file from
color input. You should use this switch when compressing a grayscaleBMP 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 param-
eters. If you do not specify this option, default encoding parametersare used. -optimize usually makes
the JPEG file a little smaller, butcjpeg runs more slowly and needs
SunOS 5.11 Last change: 26 Mar 2004 1
User Commands cjpeg(1)
much more memory. Image quality andspeed of decompression are unaf-
fected by the -optimize option.
-progressive Create a progressive JPEG file. For
more information about the -progres-
sive 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 informationabout the -quality option, see the
Extended Description section.-targa Specify that the input file is in
Targa format. Targa files that con-
tain an "identification" field are not automatically recognized bycjpeg. 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. Intermediate Options 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 thefloating-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 yourmachine has very fast floating-point
hardware. The results of thefloating-point method may vary
slightly across machines, while theSunOS 5.11 Last change: 26 Mar 2004 2
User Commands cjpeg(1)
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, tem-
porary 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. Formore 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
SunOS 5.11 Last change: 26 Mar 2004 3
User Commands cjpeg(1)
output than the -v option. The -vvv
option displays the most verbose output.You can also use -debug to specify
this option. Advanced Options The following advanced options are supported for advanced users only:-baseline Force baseline-compatible quantiza-
tion 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 -base-
line 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. OPERANDS The following operands are supported: filename The name of the image file to be compressed.SunOS 5.11 Last change: 26 Mar 2004 4
User Commands cjpeg(1)
EXTENDED DESCRIPTION
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, butinformation is still lost in subsampling, as well as round-
off 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 todecode 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 firstscan 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 ofSunOS 5.11 Last change: 26 Mar 2004 5
User Commands cjpeg(1)
the image. With restart markers, the damage is usually con-
fined to the portion of the image from the point of the error to the next restart marker. The restart markers occupyextra 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 ina smaller JPEG file and a better-looking image. If the
smoothing factor is too large, the image visibly blurs. Hints Color GIF files are not the ideal input for JPEG. JPEG isreally 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 experimentwith 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 set-
tings, make very small JPEG files. The percentage improve-
ment is often much greater than on larger files. At present,the -optimize option is always selected when generating pro-
gressive JPEG files.EXAMPLES
Example 1: Compressing the PPM File test.ppm With a Quality Factor of 60 and Saving the Output as test.jpgexample% cjpeg -quality 60 test.ppm > test.jpg
ENVIRONMENT VARIABLEScjpeg uses the following environment variables:
JPEGMEM The value of this environment vari-
able, if set, is the default memory limit. The value is specified asdescribed for the -maxmemory option.
JPEGMEM overrides the default valueSunOS 5.11 Last change: 26 Mar 2004 6
User Commands cjpeg(1)
specified when the program was com-
piled, and is in turn overridden byan explicit -maxmemory option.
ATTRIBUTES
See attributes(5) for descriptions of the following attri-
butes:____________________________________________________________
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
|_____________________________|_____________________________|
| Availability | image/library/libjpeg ||_____________________________|_____________________________|
| Interface stability | Uncommitted ||_____________________________|_____________________________|
SEE ALSO
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) NOTES 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 Last change: 26 Mar 2004 7