kusano 7d535a
.TH CJPEG 1 "4 May 2012"
kusano 7d535a
.SH NAME
kusano 7d535a
cjpeg \- compress an image file to a JPEG file
kusano 7d535a
.SH SYNOPSIS
kusano 7d535a
.B cjpeg
kusano 7d535a
[
kusano 7d535a
.I options
kusano 7d535a
]
kusano 7d535a
[
kusano 7d535a
.I filename
kusano 7d535a
]
kusano 7d535a
.LP
kusano 7d535a
.SH DESCRIPTION
kusano 7d535a
.LP
kusano 7d535a
.B cjpeg
kusano 7d535a
compresses the named image file, or the standard input if no file is
kusano 7d535a
named, and produces a JPEG/JFIF file on the standard output.
kusano 7d535a
The currently supported input file formats are: PPM (PBMPLUS color
kusano 7d535a
format), PGM (PBMPLUS gray-scale format), BMP, Targa, and RLE (Utah Raster
kusano 7d535a
Toolkit format).  (RLE is supported only if the URT library is available.)
kusano 7d535a
.SH OPTIONS
kusano 7d535a
All switch names may be abbreviated; for example,
kusano 7d535a
.B \-grayscale
kusano 7d535a
may be written
kusano 7d535a
.B \-gray
kusano 7d535a
or
kusano 7d535a
.BR \-gr .
kusano 7d535a
Most of the "basic" switches can be abbreviated to as little as one letter.
kusano 7d535a
Upper and lower case are equivalent (thus
kusano 7d535a
.B \-BMP
kusano 7d535a
is the same as
kusano 7d535a
.BR \-bmp ).
kusano 7d535a
British spellings are also accepted (e.g.,
kusano 7d535a
.BR \-greyscale ),
kusano 7d535a
though for brevity these are not mentioned below.
kusano 7d535a
.PP
kusano 7d535a
The basic switches are:
kusano 7d535a
.TP
kusano 7d535a
.BI \-quality " N[,...]"
kusano 7d535a
Scale quantization tables to adjust image quality.  Quality is 0 (worst) to
kusano 7d535a
100 (best); default is 75.  (See below for more info.)
kusano 7d535a
.TP
kusano 7d535a
.B \-grayscale
kusano 7d535a
Create monochrome JPEG file from color input.  Be sure to use this switch when
kusano 7d535a
compressing a grayscale BMP file, because
kusano 7d535a
.B cjpeg
kusano 7d535a
isn't bright enough to notice whether a BMP file uses only shades of gray.
kusano 7d535a
By saying
kusano 7d535a
.BR \-grayscale ,
kusano 7d535a
you'll get a smaller JPEG file that takes less time to process.
kusano 7d535a
.TP
kusano 7d535a
.B \-rgb
kusano 7d535a
Create RGB JPEG file.
kusano 7d535a
Using this switch suppresses the conversion from RGB
kusano 7d535a
colorspace input to the default YCbCr JPEG colorspace.
kusano 7d535a
You can use this switch in combination with the
kusano 7d535a
.BI \-block " N"
kusano 7d535a
switch (see below) for lossless JPEG coding.
kusano 7d535a
See also the
kusano 7d535a
.B \-rgb1
kusano 7d535a
switch below.
kusano 7d535a
.TP
kusano 7d535a
.B \-optimize
kusano 7d535a
Perform optimization of entropy encoding parameters.  Without this, default
kusano 7d535a
encoding parameters are used.
kusano 7d535a
.B \-optimize
kusano 7d535a
usually makes the JPEG file a little smaller, but
kusano 7d535a
.B cjpeg
kusano 7d535a
runs somewhat slower and needs much more memory.  Image quality and speed of
kusano 7d535a
decompression are unaffected by
kusano 7d535a
.BR \-optimize .
kusano 7d535a
.TP
kusano 7d535a
.B \-progressive
kusano 7d535a
Create progressive JPEG file (see below).
kusano 7d535a
.TP
kusano 7d535a
.BI \-scale " M/N"
kusano 7d535a
Scale the output image by a factor M/N.  Currently supported scale factors are
kusano 7d535a
M/N with all N from 1 to 16, where M is the destination DCT size, which is 8
kusano 7d535a
by default (see
kusano 7d535a
.BI \-block " N"
kusano 7d535a
switch below).
kusano 7d535a
.TP
kusano 7d535a
.B \-targa
kusano 7d535a
Input file is Targa format.  Targa files that contain an "identification"
kusano 7d535a
field will not be automatically recognized by
kusano 7d535a
.BR cjpeg ;
kusano 7d535a
for such files you must specify
kusano 7d535a
.B \-targa
kusano 7d535a
to make
kusano 7d535a
.B cjpeg
kusano 7d535a
treat the input as Targa format.
kusano 7d535a
For most Targa files, you won't need this switch.
kusano 7d535a
.PP
kusano 7d535a
The
kusano 7d535a
.B \-quality
kusano 7d535a
switch lets you trade off compressed file size against quality of the
kusano 7d535a
reconstructed image: the higher the quality setting, the larger the JPEG file,
kusano 7d535a
and the closer the output image will be to the original input.  Normally you
kusano 7d535a
want to use the lowest quality setting (smallest file) that decompresses into
kusano 7d535a
something visually indistinguishable from the original image.  For this
kusano 7d535a
purpose the quality setting should be between 50 and 95; the default of 75 is
kusano 7d535a
often about right.  If you see defects at
kusano 7d535a
.B \-quality
kusano 7d535a
75, then go up 5 or 10 counts at a time until you are happy with the output
kusano 7d535a
image.  (The optimal setting will vary from one image to another.)
kusano 7d535a
.PP
kusano 7d535a
.B \-quality
kusano 7d535a
100 will generate a quantization table of all 1's, minimizing loss in the
kusano 7d535a
quantization step (but there is still information loss in subsampling, as well
kusano 7d535a
as roundoff error).  This setting is mainly of interest for experimental
kusano 7d535a
purposes.  Quality values above about 95 are
kusano 7d535a
.B not
kusano 7d535a
recommended for normal use; the compressed file size goes up dramatically for
kusano 7d535a
hardly any gain in output image quality.
kusano 7d535a
.PP
kusano 7d535a
In the other direction, quality values below 50 will produce very small files
kusano 7d535a
of low image quality.  Settings around 5 to 10 might be useful in preparing an
kusano 7d535a
index of a large image library, for example.  Try
kusano 7d535a
.B \-quality
kusano 7d535a
2 (or so) for some amusing Cubist effects.  (Note: quality
kusano 7d535a
values below about 25 generate 2-byte quantization tables, which are
kusano 7d535a
considered optional in the JPEG standard.
kusano 7d535a
.B cjpeg
kusano 7d535a
emits a warning message when you give such a quality value, because some
kusano 7d535a
other JPEG programs may be unable to decode the resulting file.  Use
kusano 7d535a
.B \-baseline
kusano 7d535a
if you need to ensure compatibility at low quality values.)
kusano 7d535a
.PP
kusano 7d535a
The
kusano 7d535a
.B \-quality
kusano 7d535a
option has been extended in IJG version 7 for support of separate quality
kusano 7d535a
settings for luminance and chrominance (or in general, for every provided
kusano 7d535a
quantization table slot).  This feature is useful for high-quality
kusano 7d535a
applications which cannot accept the damage of color data by coarse
kusano 7d535a
subsampling settings.  You can now easily reduce the color data amount more
kusano 7d535a
smoothly with finer control without separate subsampling.  The resulting file
kusano 7d535a
is fully compliant with standard JPEG decoders.
kusano 7d535a
Note that the
kusano 7d535a
.B \-quality
kusano 7d535a
ratings refer to the quantization table slots, and that the last value is
kusano 7d535a
replicated if there are more q-table slots than parameters.  The default
kusano 7d535a
q-table slots are 0 for luminance and 1 for chrominance with default tables as
kusano 7d535a
given in the JPEG standard.  This is compatible with the old behaviour in case
kusano 7d535a
that only one parameter is given, which is then used for both luminance and
kusano 7d535a
chrominance (slots 0 and 1).  More or custom quantization tables can be set
kusano 7d535a
with
kusano 7d535a
.B \-qtables
kusano 7d535a
and assigned to components with
kusano 7d535a
.B \-qslots
kusano 7d535a
parameter (see the "wizard" switches below).
kusano 7d535a
.B Caution:
kusano 7d535a
You must explicitly add
kusano 7d535a
.BI \-sample " 1x1"
kusano 7d535a
for efficient separate color
kusano 7d535a
quality selection, since the default value used by library is 2x2!
kusano 7d535a
.PP
kusano 7d535a
The
kusano 7d535a
.B \-progressive
kusano 7d535a
switch creates a "progressive JPEG" file.  In this type of JPEG file, the data
kusano 7d535a
is stored in multiple scans of increasing quality.  If the file is being
kusano 7d535a
transmitted over a slow communications link, the decoder can use the first
kusano 7d535a
scan to display a low-quality image very quickly, and can then improve the
kusano 7d535a
display with each subsequent scan.  The final image is exactly equivalent to a
kusano 7d535a
standard JPEG file of the same quality setting, and the total file size is
kusano 7d535a
about the same --- often a little smaller.
kusano 7d535a
.PP
kusano 7d535a
Switches for advanced users:
kusano 7d535a
.TP
kusano 7d535a
.B \-arithmetic
kusano 7d535a
Use arithmetic coding.
kusano 7d535a
.B Caution:
kusano 7d535a
arithmetic coded JPEG is not yet widely implemented, so many decoders will
kusano 7d535a
be unable to view an arithmetic coded JPEG file at all.
kusano 7d535a
.TP
kusano 7d535a
.BI \-block " N"
kusano 7d535a
Set DCT block size.  All N from 1 to 16 are possible.
kusano 7d535a
Default is 8 (baseline format).
kusano 7d535a
Larger values produce higher compression,
kusano 7d535a
smaller values produce higher quality
kusano 7d535a
(exact DCT stage possible with 1 or 2; with the default quality of 75 and
kusano 7d535a
default Luminance qtable the DCT+Quantization stage is lossless for N=1).
kusano 7d535a
.B Caution:
kusano 7d535a
An implementation of the JPEG SmartScale extension is required for this
kusano 7d535a
feature.  SmartScale enabled JPEG is not yet widely implemented, so many
kusano 7d535a
decoders will be unable to view a SmartScale extended JPEG file at all.
kusano 7d535a
.TP
kusano 7d535a
.B \-rgb1
kusano 7d535a
Create RGB JPEG file with reversible color transform.
kusano 7d535a
Works like the
kusano 7d535a
.B \-rgb
kusano 7d535a
switch (see above) and inserts a simple reversible color transform
kusano 7d535a
into the processing which significantly improves the compression.
kusano 7d535a
Use this switch in combination with the
kusano 7d535a
.BI \-block " N"
kusano 7d535a
switch (see above) for lossless JPEG coding.
kusano 7d535a
.B Caution:
kusano 7d535a
A decoder with inverse color transform support is required for
kusano 7d535a
this feature.  Reversible color transform support is not yet
kusano 7d535a
widely implemented, so many decoders will be unable to view
kusano 7d535a
a reversible color transformed JPEG file at all.
kusano 7d535a
.TP
kusano 7d535a
.B \-dct int
kusano 7d535a
Use integer DCT method (default).
kusano 7d535a
.TP
kusano 7d535a
.B \-dct fast
kusano 7d535a
Use fast integer DCT (less accurate).
kusano 7d535a
.TP
kusano 7d535a
.B \-dct float
kusano 7d535a
Use floating-point DCT method.
kusano 7d535a
The float method is very slightly more accurate than the int method, but is
kusano 7d535a
much slower unless your machine has very fast floating-point hardware.  Also
kusano 7d535a
note that results of the floating-point method may vary slightly across
kusano 7d535a
machines, while the integer methods should give the same results everywhere.
kusano 7d535a
The fast integer method is much less accurate than the other two.
kusano 7d535a
.TP
kusano 7d535a
.B \-nosmooth
kusano 7d535a
Don't use high-quality downsampling.
kusano 7d535a
.TP
kusano 7d535a
.BI \-restart " N"
kusano 7d535a
Emit a JPEG restart marker every N MCU rows, or every N MCU blocks if "B" is
kusano 7d535a
attached to the number.
kusano 7d535a
.B \-restart 0
kusano 7d535a
(the default) means no restart markers.
kusano 7d535a
.TP
kusano 7d535a
.BI \-smooth " N"
kusano 7d535a
Smooth the input image to eliminate dithering noise.  N, ranging from 1 to
kusano 7d535a
100, indicates the strength of smoothing.  0 (the default) means no smoothing.
kusano 7d535a
.TP
kusano 7d535a
.BI \-maxmemory " N"
kusano 7d535a
Set limit for amount of memory to use in processing large images.  Value is
kusano 7d535a
in thousands of bytes, or millions of bytes if "M" is attached to the
kusano 7d535a
number.  For example,
kusano 7d535a
.B \-max 4m
kusano 7d535a
selects 4000000 bytes.  If more space is needed, temporary files will be used.
kusano 7d535a
.TP
kusano 7d535a
.BI \-outfile " name"
kusano 7d535a
Send output image to the named file, not to standard output.
kusano 7d535a
.TP
kusano 7d535a
.B \-verbose
kusano 7d535a
Enable debug printout.  More
kusano 7d535a
.BR \-v 's
kusano 7d535a
give more output.  Also, version information is printed at startup.
kusano 7d535a
.TP
kusano 7d535a
.B \-debug
kusano 7d535a
Same as
kusano 7d535a
.BR \-verbose .
kusano 7d535a
.PP
kusano 7d535a
The
kusano 7d535a
.B \-restart
kusano 7d535a
option inserts extra markers that allow a JPEG decoder to resynchronize after
kusano 7d535a
a transmission error.  Without restart markers, any damage to a compressed
kusano 7d535a
file will usually ruin the image from the point of the error to the end of the
kusano 7d535a
image; with restart markers, the damage is usually confined to the portion of
kusano 7d535a
the image up to the next restart marker.  Of course, the restart markers
kusano 7d535a
occupy extra space.  We recommend
kusano 7d535a
.B \-restart 1
kusano 7d535a
for images that will be transmitted across unreliable networks such as Usenet.
kusano 7d535a
.PP
kusano 7d535a
The
kusano 7d535a
.B \-smooth
kusano 7d535a
option filters the input to eliminate fine-scale noise.  This is often useful
kusano 7d535a
when converting dithered images to JPEG: a moderate smoothing factor of 10 to
kusano 7d535a
50 gets rid of dithering patterns in the input file, resulting in a smaller
kusano 7d535a
JPEG file and a better-looking image.  Too large a smoothing factor will
kusano 7d535a
visibly blur the image, however.
kusano 7d535a
.PP
kusano 7d535a
Switches for wizards:
kusano 7d535a
.TP
kusano 7d535a
.B \-baseline
kusano 7d535a
Force baseline-compatible quantization tables to be generated.  This clamps
kusano 7d535a
quantization values to 8 bits even at low quality settings.  (This switch is
kusano 7d535a
poorly named, since it does not ensure that the output is actually baseline
kusano 7d535a
JPEG.  For example, you can use
kusano 7d535a
.B \-baseline
kusano 7d535a
and
kusano 7d535a
.B \-progressive
kusano 7d535a
together.)
kusano 7d535a
.TP
kusano 7d535a
.BI \-qtables " file"
kusano 7d535a
Use the quantization tables given in the specified text file.
kusano 7d535a
.TP
kusano 7d535a
.BI \-qslots " N[,...]"
kusano 7d535a
Select which quantization table to use for each color component.
kusano 7d535a
.TP
kusano 7d535a
.BI \-sample " HxV[,...]"
kusano 7d535a
Set JPEG sampling factors for each color component.
kusano 7d535a
.TP
kusano 7d535a
.BI \-scans " file"
kusano 7d535a
Use the scan script given in the specified text file.
kusano 7d535a
.PP
kusano 7d535a
The "wizard" switches are intended for experimentation with JPEG.  If you
kusano 7d535a
don't know what you are doing, \fBdon't use them\fR.  These switches are
kusano 7d535a
documented further in the file wizard.txt.
kusano 7d535a
.SH EXAMPLES
kusano 7d535a
.LP
kusano 7d535a
This example compresses the PPM file foo.ppm with a quality factor of
kusano 7d535a
60 and saves the output as foo.jpg:
kusano 7d535a
.IP
kusano 7d535a
.B cjpeg \-quality
kusano 7d535a
.I 60 foo.ppm
kusano 7d535a
.B >
kusano 7d535a
.I foo.jpg
kusano 7d535a
.SH HINTS
kusano 7d535a
Color GIF files are not the ideal input for JPEG; JPEG is really intended for
kusano 7d535a
compressing full-color (24-bit) images.  In particular, don't try to convert
kusano 7d535a
cartoons, line drawings, and other images that have only a few distinct
kusano 7d535a
colors.  GIF works great on these, JPEG does not.  If you want to convert a
kusano 7d535a
GIF to JPEG, you should experiment with
kusano 7d535a
.BR cjpeg 's
kusano 7d535a
.B \-quality
kusano 7d535a
and
kusano 7d535a
.B \-smooth
kusano 7d535a
options to get a satisfactory conversion.
kusano 7d535a
.B \-smooth 10
kusano 7d535a
or so is often helpful.
kusano 7d535a
.PP
kusano 7d535a
Avoid running an image through a series of JPEG compression/decompression
kusano 7d535a
cycles.  Image quality loss will accumulate; after ten or so cycles the image
kusano 7d535a
may be noticeably worse than it was after one cycle.  It's best to use a
kusano 7d535a
lossless format while manipulating an image, then convert to JPEG format when
kusano 7d535a
you are ready to file the image away.
kusano 7d535a
.PP
kusano 7d535a
The
kusano 7d535a
.B \-optimize
kusano 7d535a
option to
kusano 7d535a
.B cjpeg
kusano 7d535a
is worth using when you are making a "final" version for posting or archiving.
kusano 7d535a
It's also a win when you are using low quality settings to make very small
kusano 7d535a
JPEG files; the percentage improvement is often a lot more than it is on
kusano 7d535a
larger files.  (At present,
kusano 7d535a
.B \-optimize
kusano 7d535a
mode is always selected when generating progressive JPEG files.)
kusano 7d535a
.SH ENVIRONMENT
kusano 7d535a
.TP
kusano 7d535a
.B JPEGMEM
kusano 7d535a
If this environment variable is set, its value is the default memory limit.
kusano 7d535a
The value is specified as described for the
kusano 7d535a
.B \-maxmemory
kusano 7d535a
switch.
kusano 7d535a
.B JPEGMEM
kusano 7d535a
overrides the default value specified when the program was compiled, and
kusano 7d535a
itself is overridden by an explicit
kusano 7d535a
.BR \-maxmemory .
kusano 7d535a
.SH SEE ALSO
kusano 7d535a
.BR djpeg (1),
kusano 7d535a
.BR jpegtran (1),
kusano 7d535a
.BR rdjpgcom (1),
kusano 7d535a
.BR wrjpgcom (1)
kusano 7d535a
.br
kusano 7d535a
.BR ppm (5),
kusano 7d535a
.BR pgm (5)
kusano 7d535a
.br
kusano 7d535a
Wallace, Gregory K.  "The JPEG Still Picture Compression Standard",
kusano 7d535a
Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
kusano 7d535a
.SH AUTHOR
kusano 7d535a
Independent JPEG Group
kusano 7d535a
.SH BUGS
kusano 7d535a
GIF input files are no longer supported, to avoid the Unisys LZW patent.
kusano 7d535a
(Conversion of GIF files to JPEG is usually a bad idea anyway.)
kusano 7d535a
.PP
kusano 7d535a
Not all variants of BMP and Targa file formats are supported.
kusano 7d535a
.PP
kusano 7d535a
The
kusano 7d535a
.B \-targa
kusano 7d535a
switch is not a bug, it's a feature.  (It would be a bug if the Targa format
kusano 7d535a
designers had not been clueless.)