shun-iwasawa 82a8f5
.TH CJPEG 1 "4 November 2020"
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
shun-iwasawa 82a8f5
format), PGM (PBMPLUS grayscale 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
shun-iwasawa 82a8f5
.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
.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
.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
shun-iwasawa 82a8f5
purpose the quality setting should generally be between 50 and 95 (the default
shun-iwasawa 82a8f5
is 75) for photographic images.  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
shun-iwasawa 82a8f5
as roundoff error.)  For most images, specifying a quality value above
shun-iwasawa 82a8f5
about 95 will increase the size of the compressed file dramatically, and while
shun-iwasawa 82a8f5
the quality gain from these higher quality values is measurable (using metrics
shun-iwasawa 82a8f5
such as PSNR or SSIM), it is rarely perceivable by human vision.
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
shun-iwasawa 82a8f5
The \fB-quality\fR option has been extended in this version of \fBcjpeg\fR to
shun-iwasawa 82a8f5
support separate quality settings for luminance and chrominance (or, in
shun-iwasawa 82a8f5
general, separate settings for every quantization table slot.)  The principle
shun-iwasawa 82a8f5
is the same as chrominance subsampling:  since the human eye is more sensitive
shun-iwasawa 82a8f5
to spatial changes in brightness than spatial changes in color, the chrominance
shun-iwasawa 82a8f5
components can be quantized more than the luminance components without
shun-iwasawa 82a8f5
incurring any visible image quality loss.  However, unlike subsampling, this
shun-iwasawa 82a8f5
feature reduces data in the frequency domain instead of the spatial domain,
shun-iwasawa 82a8f5
which allows for more fine-grained control.  This option is useful in
shun-iwasawa 82a8f5
quality-sensitive applications, for which the artifacts generated by
shun-iwasawa 82a8f5
subsampling may be unacceptable.
shun-iwasawa 82a8f5
.PP
shun-iwasawa 82a8f5
The \fB-quality\fR option accepts a comma-separated list of parameters, which
shun-iwasawa 82a8f5
respectively refer to the quality levels that should be assigned to the
shun-iwasawa 82a8f5
quantization table slots.  If there are more q-table slots than parameters,
shun-iwasawa 82a8f5
then the last parameter is replicated.  Thus, if only one quality parameter is
shun-iwasawa 82a8f5
given, this is used for both luminance and chrominance (slots 0 and 1,
shun-iwasawa 82a8f5
respectively), preserving the legacy behavior of cjpeg v6b and prior.
shun-iwasawa 82a8f5
More (or customized) quantization tables can be set with the \fB-qtables\fR
shun-iwasawa 82a8f5
option and assigned to components with the \fB-qslots\fR option (see the
shun-iwasawa 82a8f5
"wizard" switches below.)
shun-iwasawa 82a8f5
.PP
shun-iwasawa 82a8f5
JPEG files generated with separate luminance and chrominance quality are fully
shun-iwasawa 82a8f5
compliant with standard JPEG decoders.
shun-iwasawa 82a8f5
.PP
shun-iwasawa 82a8f5
.BR CAUTION:
shun-iwasawa 82a8f5
For this setting to be useful, be sure to pass an argument of \fB-sample 1x1\fR
shun-iwasawa 82a8f5
to \fBcjpeg\fR to disable chrominance subsampling.  Otherwise, the default
shun-iwasawa 82a8f5
subsampling level (2x2, AKA "4:2:0") will be used.
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:
shun-iwasawa 82a8f5
arithmetic coded JPEG is not yet widely implemented, so many decoders will be
shun-iwasawa 82a8f5
unable to view an arithmetic coded JPEG file at all.
kusano 7d535a
.TP
kusano 7d535a
.B \-dct int
shun-iwasawa 82a8f5
Use accurate integer DCT method (default).
kusano 7d535a
.TP
kusano 7d535a
.B \-dct fast
shun-iwasawa 82a8f5
Use less accurate integer DCT method [legacy feature].
shun-iwasawa 82a8f5
When the Independent JPEG Group's software was first released in 1991, the
shun-iwasawa 82a8f5
compression time for a 1-megapixel JPEG image on a mainstream PC was measured
shun-iwasawa 82a8f5
in minutes.  Thus, the \fBfast\fR integer DCT algorithm provided noticeable
shun-iwasawa 82a8f5
performance benefits.  On modern CPUs running libjpeg-turbo, however, the
shun-iwasawa 82a8f5
compression time for a 1-megapixel JPEG image is measured in milliseconds, and
shun-iwasawa 82a8f5
thus the performance benefits of the \fBfast\fR algorithm are much less
shun-iwasawa 82a8f5
noticeable.  On modern x86/x86-64 CPUs that support AVX2 instructions, the
shun-iwasawa 82a8f5
\fBfast\fR and \fBint\fR methods have similar performance.  On other types of
shun-iwasawa 82a8f5
CPUs, the \fBfast\fR method is generally about 5-15% faster than the \fBint\fR
shun-iwasawa 82a8f5
method.
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
For quality levels of 90 and below, there should be little or no perceptible
shun-iwasawa 82a8f5
quality difference between the two algorithms.  For quality levels above 90,
shun-iwasawa 82a8f5
however, the difference between the \fBfast\fR and \fBint\fR methods becomes
shun-iwasawa 82a8f5
more pronounced.  With quality=97, for instance, the \fBfast\fR method incurs
shun-iwasawa 82a8f5
generally about a 1-3 dB loss in PSNR relative to the \fBint\fR method, but
shun-iwasawa 82a8f5
this can be larger for some images.  Do not use the \fBfast\fR method with
shun-iwasawa 82a8f5
quality levels above 97.  The algorithm often degenerates at quality=98 and
shun-iwasawa 82a8f5
above and can actually produce a more lossy image than if lower quality levels
shun-iwasawa 82a8f5
had been used.  Also, in libjpeg-turbo, the \fBfast\fR method is not fully
shun-iwasawa 82a8f5
accelerated for quality levels above 97, so it will be slower than the
shun-iwasawa 82a8f5
\fBint\fR method.
kusano 7d535a
.TP
kusano 7d535a
.B \-dct float
shun-iwasawa 82a8f5
Use floating-point DCT method [legacy feature].
shun-iwasawa 82a8f5
The \fBfloat\fR method does not produce significantly more accurate results
shun-iwasawa 82a8f5
than the \fBint\fR method, and it is much slower.  The \fBfloat\fR method may
shun-iwasawa 82a8f5
also give different results on different machines due to varying roundoff
shun-iwasawa 82a8f5
behavior, whereas the integer methods should give the same results on all
shun-iwasawa 82a8f5
machines.
kusano 7d535a
.TP
shun-iwasawa 82a8f5
.BI \-icc " file"
shun-iwasawa 82a8f5
Embed ICC color management profile contained in the specified file.
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
shun-iwasawa 82a8f5
selects 4000000 bytes.  If more space is needed, an error will occur.
kusano 7d535a
.TP
kusano 7d535a
.BI \-outfile " name"
kusano 7d535a
Send output image to the named file, not to standard output.
kusano 7d535a
.TP
shun-iwasawa 82a8f5
.BI \-memdst
shun-iwasawa 82a8f5
Compress to memory instead of a file.  This feature was implemented mainly as a
shun-iwasawa 82a8f5
way of testing the in-memory destination manager (jpeg_mem_dest()), but it is
shun-iwasawa 82a8f5
also useful for benchmarking, since it reduces the I/O overhead.
shun-iwasawa 82a8f5
.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 .
shun-iwasawa 82a8f5
.TP
shun-iwasawa 82a8f5
.B \-version
shun-iwasawa 82a8f5
Print version information and exit.
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
shun-iwasawa 82a8f5
.PP
shun-iwasawa 82a8f5
This file was modified by The libjpeg-turbo Project to include only information
shun-iwasawa 82a8f5
relevant to libjpeg-turbo, to wordsmith certain sections, and to describe
shun-iwasawa 82a8f5
features not present in libjpeg.
shun-iwasawa 82a8f5
.SH ISSUES
shun-iwasawa 82a8f5
Support for GIF input files was removed in cjpeg v6b due to concerns over
shun-iwasawa 82a8f5
the Unisys LZW patent.  Although this patent expired in 2006, cjpeg still
shun-iwasawa 82a8f5
lacks GIF support, for these historical reasons.  (Conversion of GIF files to
shun-iwasawa 82a8f5
JPEG is usually a bad idea anyway, since GIF is a 256-color format.)
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.)