kusano 7d535a
USAGE instructions for the Independent JPEG Group's JPEG software
kusano 7d535a
=================================================================
kusano 7d535a
kusano 7d535a
This file describes usage of the JPEG conversion programs cjpeg and djpeg,
kusano 7d535a
as well as the utility programs jpegtran, rdjpgcom and wrjpgcom.  (See
kusano 7d535a
the other documentation files if you wish to use the JPEG library within
kusano 7d535a
your own programs.)
kusano 7d535a
kusano 7d535a
If you are on a Unix machine you may prefer to read the Unix-style manual
kusano 7d535a
pages in files cjpeg.1, djpeg.1, jpegtran.1, rdjpgcom.1, wrjpgcom.1.
kusano 7d535a
kusano 7d535a
kusano 7d535a
INTRODUCTION
kusano 7d535a
kusano 7d535a
These programs implement JPEG image encoding, decoding, and transcoding.
kusano 7d535a
JPEG (pronounced "jay-peg") is a standardized compression method for
kusano 7d535a
full-color and gray-scale images.
kusano 7d535a
kusano 7d535a
kusano 7d535a
GENERAL USAGE
kusano 7d535a
kusano 7d535a
We provide two programs, cjpeg to compress an image file into JPEG format,
kusano 7d535a
and djpeg to decompress a JPEG file back into a conventional image format.
kusano 7d535a
kusano 7d535a
On Unix-like systems, you say:
kusano 7d535a
	cjpeg [switches] [imagefile] >jpegfile
kusano 7d535a
or
kusano 7d535a
	djpeg [switches] [jpegfile]  >imagefile
kusano 7d535a
The programs read the specified input file, or standard input if none is
kusano 7d535a
named.  They always write to standard output (with trace/error messages to
kusano 7d535a
standard error).  These conventions are handy for piping images between
kusano 7d535a
programs.
kusano 7d535a
kusano 7d535a
On most non-Unix systems, you say:
kusano 7d535a
	cjpeg [switches] imagefile jpegfile
kusano 7d535a
or
kusano 7d535a
	djpeg [switches] jpegfile  imagefile
kusano 7d535a
i.e., both the input and output files are named on the command line.  This
kusano 7d535a
style is a little more foolproof, and it loses no functionality if you don't
kusano 7d535a
have pipes.  (You can get this style on Unix too, if you prefer, by defining
kusano 7d535a
TWO_FILE_COMMANDLINE when you compile the programs; see install.txt.)
kusano 7d535a
kusano 7d535a
You can also say:
kusano 7d535a
	cjpeg [switches] -outfile jpegfile  imagefile
kusano 7d535a
or
kusano 7d535a
	djpeg [switches] -outfile imagefile  jpegfile
kusano 7d535a
This syntax works on all systems, so it is useful for scripts.
kusano 7d535a
kusano 7d535a
The currently supported image file formats are: PPM (PBMPLUS color format),
kusano 7d535a
PGM (PBMPLUS gray-scale format), BMP, Targa, and RLE (Utah Raster Toolkit
kusano 7d535a
format).  (RLE is supported only if the URT library is available.)
kusano 7d535a
cjpeg recognizes the input image format automatically, with the exception
kusano 7d535a
of some Targa-format files.  You have to tell djpeg which format to generate.
kusano 7d535a
kusano 7d535a
JPEG files are in the defacto standard JFIF file format.  There are other,
kusano 7d535a
less widely used JPEG-based file formats, but we don't support them.
kusano 7d535a
kusano 7d535a
All switch names may be abbreviated; for example, -grayscale may be written
kusano 7d535a
-gray or -gr.  Most of the "basic" switches can be abbreviated to as little as
kusano 7d535a
one letter.  Upper and lower case are equivalent (-BMP is the same as -bmp).
kusano 7d535a
British spellings are also accepted (e.g., -greyscale), though for brevity
kusano 7d535a
these are not mentioned below.
kusano 7d535a
kusano 7d535a
kusano 7d535a
CJPEG DETAILS
kusano 7d535a
kusano 7d535a
The basic command line switches for cjpeg are:
kusano 7d535a
kusano 7d535a
	-quality N[,...]  Scale quantization tables to adjust image quality.
kusano 7d535a
			Quality is 0 (worst) to 100 (best); default is 75.
kusano 7d535a
			(See below for more info.)
kusano 7d535a
kusano 7d535a
	-grayscale	Create monochrome JPEG file from color input.
kusano 7d535a
			Be sure to use this switch when compressing a grayscale
kusano 7d535a
			BMP file, because cjpeg isn't bright enough to notice
kusano 7d535a
			whether a BMP file uses only shades of gray.  By
kusano 7d535a
			saying -grayscale, you'll get a smaller JPEG file that
kusano 7d535a
			takes less time to process.
kusano 7d535a
kusano 7d535a
	-rgb		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
			-block N switch (see below) for lossless JPEG coding.
kusano 7d535a
			See also the -rgb1 switch below.
kusano 7d535a
kusano 7d535a
	-optimize	Perform optimization of entropy encoding parameters.
kusano 7d535a
			Without this, default encoding parameters are used.
kusano 7d535a
			-optimize usually makes the JPEG file a little smaller,
kusano 7d535a
			but cjpeg runs somewhat slower and needs much more
kusano 7d535a
			memory.  Image quality and speed of decompression are
kusano 7d535a
			unaffected by -optimize.
kusano 7d535a
kusano 7d535a
	-progressive	Create progressive JPEG file (see below).
kusano 7d535a
kusano 7d535a
	-scale M/N	Scale the output image by a factor M/N.  Currently
kusano 7d535a
			supported scale factors are M/N with all N from 1 to
kusano 7d535a
			16, where M is the destination DCT size, which is 8 by
kusano 7d535a
			default (see -block N switch below).
kusano 7d535a
kusano 7d535a
	-targa		Input file is Targa format.  Targa files that contain
kusano 7d535a
			an "identification" field will not be automatically
kusano 7d535a
			recognized by cjpeg; for such files you must specify
kusano 7d535a
			-targa to make cjpeg treat the input as Targa format.
kusano 7d535a
			For most Targa files, you won't need this switch.
kusano 7d535a
kusano 7d535a
The -quality switch lets you trade off compressed file size against quality of
kusano 7d535a
the reconstructed image: the higher the quality setting, the larger the JPEG
kusano 7d535a
file, and the closer the output image will be to the original input.  Normally
kusano 7d535a
you want to use the lowest quality setting (smallest file) that decompresses
kusano 7d535a
into 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 -quality 75, then go up 5 or 10
kusano 7d535a
counts at a time until you are happy with the output image.  (The optimal
kusano 7d535a
setting will vary from one image to another.)
kusano 7d535a
kusano 7d535a
-quality 100 will generate a quantization table of all 1's, minimizing loss
kusano 7d535a
in the quantization step (but there is still information loss in subsampling,
kusano 7d535a
as well as roundoff error).  This setting is mainly of interest for
kusano 7d535a
experimental purposes.  Quality values above about 95 are NOT recommended for
kusano 7d535a
normal use; the compressed file size goes up dramatically for hardly any gain
kusano 7d535a
in output image quality.
kusano 7d535a
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 -quality 2 (or so) for some
kusano 7d535a
amusing Cubist effects.  (Note: quality values below about 25 generate 2-byte
kusano 7d535a
quantization tables, which are considered optional in the JPEG standard.
kusano 7d535a
cjpeg 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 -baseline
kusano 7d535a
if you need to ensure compatibility at low quality values.)
kusano 7d535a
kusano 7d535a
The -quality option has been extended in IJG version 7 for support of separate
kusano 7d535a
quality settings for luminance and chrominance (or in general, for every
kusano 7d535a
provided 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 -quality ratings refer to the quantization table slots, and that
kusano 7d535a
the last value is replicated if there are more q-table slots than parameters.
kusano 7d535a
The default q-table slots are 0 for luminance and 1 for chrominance with
kusano 7d535a
default tables as given in the JPEG standard.  This is compatible with the old
kusano 7d535a
behaviour in case that only one parameter is given, which is then used for
kusano 7d535a
both luminance and chrominance (slots 0 and 1).  More or custom quantization
kusano 7d535a
tables can be set with -qtables and assigned to components with -qslots
kusano 7d535a
parameter (see the "wizard" switches below).
kusano 7d535a
CAUTION: You must explicitly add -sample 1x1 for efficient separate color
kusano 7d535a
quality selection, since the default value used by library is 2x2!
kusano 7d535a
kusano 7d535a
The -progressive switch creates a "progressive JPEG" file.  In this type of
kusano 7d535a
JPEG file, the data is stored in multiple scans of increasing quality.  If the
kusano 7d535a
file is being transmitted over a slow communications link, the decoder can use
kusano 7d535a
the first scan to display a low-quality image very quickly, and can then
kusano 7d535a
improve the display with each subsequent scan.  The final image is exactly
kusano 7d535a
equivalent to a standard JPEG file of the same quality setting, and the total
kusano 7d535a
file size is about the same --- often a little smaller.
kusano 7d535a
kusano 7d535a
Switches for advanced users:
kusano 7d535a
kusano 7d535a
	-arithmetic	Use arithmetic coding.  CAUTION: arithmetic coded JPEG
kusano 7d535a
			is not yet widely implemented, so many decoders will
kusano 7d535a
			be unable to view an arithmetic coded JPEG file at
kusano 7d535a
			all.
kusano 7d535a
kusano 7d535a
	-block N	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
kusano 7d535a
			default quality of 75 and default Luminance qtable
kusano 7d535a
			the DCT+Quantization stage is lossless for N=1).
kusano 7d535a
			CAUTION: An implementation of the JPEG SmartScale
kusano 7d535a
			extension is required for this feature.  SmartScale
kusano 7d535a
			enabled JPEG is not yet widely implemented, so many
kusano 7d535a
			decoders will be unable to view a SmartScale extended
kusano 7d535a
			JPEG file at all.
kusano 7d535a
kusano 7d535a
	-rgb1		Create RGB JPEG file with reversible color transform.
kusano 7d535a
			Works like the -rgb switch (see above) and inserts a
kusano 7d535a
			simple reversible color transform into the processing
kusano 7d535a
			which significantly improves the compression.
kusano 7d535a
			Use this switch in combination with the -block N
kusano 7d535a
			switch (see above) for lossless JPEG coding.
kusano 7d535a
			CAUTION: A decoder with inverse color transform
kusano 7d535a
			support is required for this feature.  Reversible
kusano 7d535a
			color transform support is not yet widely implemented,
kusano 7d535a
			so many decoders will be unable to view a reversible
kusano 7d535a
			color transformed JPEG file at all.
kusano 7d535a
kusano 7d535a
	-dct int	Use integer DCT method (default).
kusano 7d535a
	-dct fast	Use fast integer DCT (less accurate).
kusano 7d535a
	-dct float	Use floating-point DCT method.
kusano 7d535a
			The float method is very slightly more accurate than
kusano 7d535a
			the int method, but is much slower unless your machine
kusano 7d535a
			has very fast floating-point hardware.  Also note that
kusano 7d535a
			results of the floating-point method may vary slightly
kusano 7d535a
			across machines, while the integer methods should give
kusano 7d535a
			the same results everywhere.  The fast integer method
kusano 7d535a
			is much less accurate than the other two.
kusano 7d535a
kusano 7d535a
	-nosmooth	Don't use high-quality downsampling.
kusano 7d535a
kusano 7d535a
	-restart N	Emit a JPEG restart marker every N MCU rows, or every
kusano 7d535a
			N MCU blocks if "B" is attached to the number.
kusano 7d535a
			-restart 0 (the default) means no restart markers.
kusano 7d535a
kusano 7d535a
	-smooth N	Smooth the input image to eliminate dithering noise.
kusano 7d535a
			N, ranging from 1 to 100, indicates the strength of
kusano 7d535a
			smoothing.  0 (the default) means no smoothing.
kusano 7d535a
kusano 7d535a
	-maxmemory N	Set limit for amount of memory to use in processing
kusano 7d535a
			large images.  Value is in thousands of bytes, or
kusano 7d535a
			millions of bytes if "M" is attached to the number.
kusano 7d535a
			For example, -max 4m selects 4000000 bytes.  If more
kusano 7d535a
			space is needed, temporary files will be used.
kusano 7d535a
kusano 7d535a
	-verbose	Enable debug printout.  More -v's give more printout.
kusano 7d535a
	or  -debug	Also, version information is printed at startup.
kusano 7d535a
kusano 7d535a
The -restart option inserts extra markers that allow a JPEG decoder to
kusano 7d535a
resynchronize after a transmission error.  Without restart markers, any damage
kusano 7d535a
to a compressed file will usually ruin the image from the point of the error
kusano 7d535a
to the end of the image; with restart markers, the damage is usually confined
kusano 7d535a
to the portion of the image up to the next restart marker.  Of course, the
kusano 7d535a
restart markers occupy extra space.  We recommend -restart 1 for images that
kusano 7d535a
will be transmitted across unreliable networks such as Usenet.
kusano 7d535a
kusano 7d535a
The -smooth option filters the input to eliminate fine-scale noise.  This is
kusano 7d535a
often useful when converting dithered images to JPEG: a moderate smoothing
kusano 7d535a
factor of 10 to 50 gets rid of dithering patterns in the input file, resulting
kusano 7d535a
in a smaller JPEG file and a better-looking image.  Too large a smoothing
kusano 7d535a
factor will visibly blur the image, however.
kusano 7d535a
kusano 7d535a
Switches for wizards:
kusano 7d535a
kusano 7d535a
	-baseline	Force baseline-compatible quantization tables to be
kusano 7d535a
			generated.  This clamps quantization values to 8 bits
kusano 7d535a
			even at low quality settings.  (This switch is poorly
kusano 7d535a
			named, since it does not ensure that the output is
kusano 7d535a
			actually baseline JPEG.  For example, you can use
kusano 7d535a
			-baseline and -progressive together.)
kusano 7d535a
kusano 7d535a
	-qtables file	Use the quantization tables given in the specified
kusano 7d535a
			text file.
kusano 7d535a
kusano 7d535a
	-qslots N[,...] Select which quantization table to use for each color
kusano 7d535a
			component.
kusano 7d535a
kusano 7d535a
	-sample HxV[,...]  Set JPEG sampling factors for each color component.
kusano 7d535a
kusano 7d535a
	-scans file	Use the scan script given in the specified text file.
kusano 7d535a
kusano 7d535a
The "wizard" switches are intended for experimentation with JPEG.  If you
kusano 7d535a
don't know what you are doing, DON'T USE THEM.  These switches are documented
kusano 7d535a
further in the file wizard.txt.
kusano 7d535a
kusano 7d535a
kusano 7d535a
DJPEG DETAILS
kusano 7d535a
kusano 7d535a
The basic command line switches for djpeg are:
kusano 7d535a
kusano 7d535a
	-colors N	Reduce image to at most N colors.  This reduces the
kusano 7d535a
	or -quantize N	number of colors used in the output image, so that it
kusano 7d535a
			can be displayed on a colormapped display or stored in
kusano 7d535a
			a colormapped file format.  For example, if you have
kusano 7d535a
			an 8-bit display, you'd need to reduce to 256 or fewer
kusano 7d535a
			colors.  (-colors is the recommended name, -quantize
kusano 7d535a
			is provided only for backwards compatibility.)
kusano 7d535a
kusano 7d535a
	-fast		Select recommended processing options for fast, low
kusano 7d535a
			quality output.  (The default options are chosen for
kusano 7d535a
			highest quality output.)  Currently, this is equivalent
kusano 7d535a
			to "-dct fast -nosmooth -onepass -dither ordered".
kusano 7d535a
kusano 7d535a
	-grayscale	Force gray-scale output even if JPEG file is color.
kusano 7d535a
			Useful for viewing on monochrome displays; also,
kusano 7d535a
			djpeg runs noticeably faster in this mode.
kusano 7d535a
kusano 7d535a
	-scale M/N	Scale the output image by a factor M/N.  Currently
kusano 7d535a
			supported scale factors are M/N with all M from 1 to
kusano 7d535a
			16, where N is the source DCT size, which is 8 for
kusano 7d535a
			baseline JPEG.  If the /N part is omitted, then M
kusano 7d535a
			specifies the DCT scaled size to be applied on the
kusano 7d535a
			given input.  For baseline JPEG this is equivalent to
kusano 7d535a
			M/8 scaling, since the source DCT size for baseline
kusano 7d535a
			JPEG is 8.  Scaling is handy if the image is larger
kusano 7d535a
			than your screen; also, djpeg runs much faster when
kusano 7d535a
			scaling down the output.
kusano 7d535a
kusano 7d535a
	-bmp		Select BMP output format (Windows flavor).  8-bit
kusano 7d535a
			colormapped format is emitted if -colors or -grayscale
kusano 7d535a
			is specified, or if the JPEG file is gray-scale;
kusano 7d535a
			otherwise, 24-bit full-color format is emitted.
kusano 7d535a
kusano 7d535a
	-gif		Select GIF output format.  Since GIF does not support
kusano 7d535a
			more than 256 colors, -colors 256 is assumed (unless
kusano 7d535a
			you specify a smaller number of colors).  If you
kusano 7d535a
			specify -fast, the default number of colors is 216.
kusano 7d535a
kusano 7d535a
	-os2		Select BMP output format (OS/2 1.x flavor).  8-bit
kusano 7d535a
			colormapped format is emitted if -colors or -grayscale
kusano 7d535a
			is specified, or if the JPEG file is gray-scale;
kusano 7d535a
			otherwise, 24-bit full-color format is emitted.
kusano 7d535a
kusano 7d535a
	-pnm		Select PBMPLUS (PPM/PGM) output format (this is the
kusano 7d535a
			default format).  PGM is emitted if the JPEG file is
kusano 7d535a
			gray-scale or if -grayscale is specified; otherwise
kusano 7d535a
			PPM is emitted.
kusano 7d535a
kusano 7d535a
	-rle		Select RLE output format.  (Requires URT library.)
kusano 7d535a
kusano 7d535a
	-targa		Select Targa output format.  Gray-scale format is
kusano 7d535a
			emitted if the JPEG file is gray-scale or if
kusano 7d535a
			-grayscale is specified; otherwise, colormapped format
kusano 7d535a
			is emitted if -colors is specified; otherwise, 24-bit
kusano 7d535a
			full-color format is emitted.
kusano 7d535a
kusano 7d535a
Switches for advanced users:
kusano 7d535a
kusano 7d535a
	-dct int	Use integer DCT method (default).
kusano 7d535a
	-dct fast	Use fast integer DCT (less accurate).
kusano 7d535a
	-dct float	Use floating-point DCT method.
kusano 7d535a
			The float method is very slightly more accurate than
kusano 7d535a
			the int method, but is much slower unless your machine
kusano 7d535a
			has very fast floating-point hardware.  Also note that
kusano 7d535a
			results of the floating-point method may vary slightly
kusano 7d535a
			across machines, while the integer methods should give
kusano 7d535a
			the same results everywhere.  The fast integer method
kusano 7d535a
			is much less accurate than the other two.
kusano 7d535a
kusano 7d535a
	-dither fs	Use Floyd-Steinberg dithering in color quantization.
kusano 7d535a
	-dither ordered	Use ordered dithering in color quantization.
kusano 7d535a
	-dither none	Do not use dithering in color quantization.
kusano 7d535a
			By default, Floyd-Steinberg dithering is applied when
kusano 7d535a
			quantizing colors; this is slow but usually produces
kusano 7d535a
			the best results.  Ordered dither is a compromise
kusano 7d535a
			between speed and quality; no dithering is fast but
kusano 7d535a
			usually looks awful.  Note that these switches have
kusano 7d535a
			no effect unless color quantization is being done.
kusano 7d535a
			Ordered dither is only available in -onepass mode.
kusano 7d535a
kusano 7d535a
	-map FILE	Quantize to the colors used in the specified image
kusano 7d535a
			file.  This is useful for producing multiple files
kusano 7d535a
			with identical color maps, or for forcing a predefined
kusano 7d535a
			set of colors to be used.  The FILE must be a GIF
kusano 7d535a
			or PPM file.  This option overrides -colors and
kusano 7d535a
			-onepass.
kusano 7d535a
kusano 7d535a
	-nosmooth	Don't use high-quality upsampling.
kusano 7d535a
kusano 7d535a
	-onepass	Use one-pass instead of two-pass color quantization.
kusano 7d535a
			The one-pass method is faster and needs less memory,
kusano 7d535a
			but it produces a lower-quality image.  -onepass is
kusano 7d535a
			ignored unless you also say -colors N.  Also,
kusano 7d535a
			the one-pass method is always used for gray-scale
kusano 7d535a
			output (the two-pass method is no improvement then).
kusano 7d535a
kusano 7d535a
	-maxmemory N	Set limit for amount of memory to use in processing
kusano 7d535a
			large images.  Value is in thousands of bytes, or
kusano 7d535a
			millions of bytes if "M" is attached to the number.
kusano 7d535a
			For example, -max 4m selects 4000000 bytes.  If more
kusano 7d535a
			space is needed, temporary files will be used.
kusano 7d535a
kusano 7d535a
	-verbose	Enable debug printout.  More -v's give more printout.
kusano 7d535a
	or  -debug	Also, version information is printed at startup.
kusano 7d535a
kusano 7d535a
kusano 7d535a
HINTS FOR CJPEG
kusano 7d535a
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 cjpeg's -quality and -smooth options
kusano 7d535a
to get a satisfactory conversion.  -smooth 10 or so is often helpful.
kusano 7d535a
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
kusano 7d535a
The -optimize option to cjpeg is worth using when you are making a "final"
kusano 7d535a
version for posting or archiving.  It's also a win when you are using low
kusano 7d535a
quality settings to make very small JPEG files; the percentage improvement
kusano 7d535a
is often a lot more than it is on larger files.  (At present, -optimize
kusano 7d535a
mode is always selected when generating progressive JPEG files.)
kusano 7d535a
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
kusano 7d535a
kusano 7d535a
HINTS FOR DJPEG
kusano 7d535a
kusano 7d535a
To get a quick preview of an image, use the -grayscale and/or -scale switches.
kusano 7d535a
"-grayscale -scale 1/8" is the fastest case.
kusano 7d535a
kusano 7d535a
Several options are available that trade off image quality to gain speed.
kusano 7d535a
"-fast" turns on the recommended settings.
kusano 7d535a
kusano 7d535a
"-dct fast" and/or "-nosmooth" gain speed at a small sacrifice in quality.
kusano 7d535a
When producing a color-quantized image, "-onepass -dither ordered" is fast but
kusano 7d535a
much lower quality than the default behavior.  "-dither none" may give
kusano 7d535a
acceptable results in two-pass mode, but is seldom tolerable in one-pass mode.
kusano 7d535a
kusano 7d535a
If you are fortunate enough to have very fast floating point hardware,
kusano 7d535a
"-dct float" may be even faster than "-dct fast".  But on most machines
kusano 7d535a
"-dct float" is slower than "-dct int"; in this case it is not worth using,
kusano 7d535a
because its theoretical accuracy advantage is too small to be significant
kusano 7d535a
in practice.
kusano 7d535a
kusano 7d535a
Two-pass color quantization requires a good deal of memory; on MS-DOS machines
kusano 7d535a
it may run out of memory even with -maxmemory 0.  In that case you can still
kusano 7d535a
decompress, with some loss of image quality, by specifying -onepass for
kusano 7d535a
one-pass quantization.
kusano 7d535a
kusano 7d535a
To avoid the Unisys LZW patent, djpeg produces uncompressed GIF files.  These
kusano 7d535a
are larger than they should be, but are readable by standard GIF decoders.
kusano 7d535a
kusano 7d535a
kusano 7d535a
HINTS FOR BOTH PROGRAMS
kusano 7d535a
kusano 7d535a
If more space is needed than will fit in the available main memory (as
kusano 7d535a
determined by -maxmemory), temporary files will be used.  (MS-DOS versions
kusano 7d535a
will try to get extended or expanded memory first.)  The temporary files are
kusano 7d535a
often rather large: in typical cases they occupy three bytes per pixel, for
kusano 7d535a
example 3*800*600 = 1.44Mb for an 800x600 image.  If you don't have enough
kusano 7d535a
free disk space, leave out -progressive and -optimize (for cjpeg) or specify
kusano 7d535a
-onepass (for djpeg).
kusano 7d535a
kusano 7d535a
On MS-DOS, the temporary files are created in the directory named by the TMP
kusano 7d535a
or TEMP environment variable, or in the current directory if neither of those
kusano 7d535a
exist.  Amiga implementations put the temp files in the directory named by
kusano 7d535a
JPEGTMP:, so be sure to assign JPEGTMP: to a disk partition with adequate free
kusano 7d535a
space.
kusano 7d535a
kusano 7d535a
The default memory usage limit (-maxmemory) is set when the software is
kusano 7d535a
compiled.  If you get an "insufficient memory" error, try specifying a smaller
kusano 7d535a
-maxmemory value, even -maxmemory 0 to use the absolute minimum space.  You
kusano 7d535a
may want to recompile with a smaller default value if this happens often.
kusano 7d535a
kusano 7d535a
On machines that have "environment" variables, you can define the environment
kusano 7d535a
variable JPEGMEM to set the default memory limit.  The value is specified as
kusano 7d535a
described for the -maxmemory switch.  JPEGMEM overrides the default value
kusano 7d535a
specified when the program was compiled, and itself is overridden by an
kusano 7d535a
explicit -maxmemory switch.
kusano 7d535a
kusano 7d535a
On MS-DOS machines, -maxmemory is the amount of main (conventional) memory to
kusano 7d535a
use.  (Extended or expanded memory is also used if available.)  Most
kusano 7d535a
DOS-specific versions of this software do their own memory space estimation
kusano 7d535a
and do not need you to specify -maxmemory.
kusano 7d535a
kusano 7d535a
kusano 7d535a
JPEGTRAN
kusano 7d535a
kusano 7d535a
jpegtran performs various useful transformations of JPEG files.
kusano 7d535a
It can translate the coded representation from one variant of JPEG to another,
kusano 7d535a
for example from baseline JPEG to progressive JPEG or vice versa.  It can also
kusano 7d535a
perform some rearrangements of the image data, for example turning an image
kusano 7d535a
from landscape to portrait format by rotation.
kusano 7d535a
kusano 7d535a
jpegtran works by rearranging the compressed data (DCT coefficients), without
kusano 7d535a
ever fully decoding the image.  Therefore, its transformations are lossless:
kusano 7d535a
there is no image degradation at all, which would not be true if you used
kusano 7d535a
djpeg followed by cjpeg to accomplish the same conversion.  But by the same
kusano 7d535a
token, jpegtran cannot perform lossy operations such as changing the image
kusano 7d535a
quality.
kusano 7d535a
kusano 7d535a
jpegtran uses a command line syntax similar to cjpeg or djpeg.
kusano 7d535a
On Unix-like systems, you say:
kusano 7d535a
	jpegtran [switches] [inputfile] >outputfile
kusano 7d535a
On most non-Unix systems, you say:
kusano 7d535a
	jpegtran [switches] inputfile outputfile
kusano 7d535a
where both the input and output files are JPEG files.
kusano 7d535a
kusano 7d535a
To specify the coded JPEG representation used in the output file,
kusano 7d535a
jpegtran accepts a subset of the switches recognized by cjpeg:
kusano 7d535a
	-optimize	Perform optimization of entropy encoding parameters.
kusano 7d535a
	-progressive	Create progressive JPEG file.
kusano 7d535a
	-arithmetic	Use arithmetic coding.
kusano 7d535a
	-restart N	Emit a JPEG restart marker every N MCU rows, or every
kusano 7d535a
			N MCU blocks if "B" is attached to the number.
kusano 7d535a
	-scans file	Use the scan script given in the specified text file.
kusano 7d535a
See the previous discussion of cjpeg for more details about these switches.
kusano 7d535a
If you specify none of these switches, you get a plain baseline-JPEG output
kusano 7d535a
file.  The quality setting and so forth are determined by the input file.
kusano 7d535a
kusano 7d535a
The image can be losslessly transformed by giving one of these switches:
kusano 7d535a
	-flip horizontal	Mirror image horizontally (left-right).
kusano 7d535a
	-flip vertical		Mirror image vertically (top-bottom).
kusano 7d535a
	-rotate 90		Rotate image 90 degrees clockwise.
kusano 7d535a
	-rotate 180		Rotate image 180 degrees.
kusano 7d535a
	-rotate 270		Rotate image 270 degrees clockwise (or 90 ccw).
kusano 7d535a
	-transpose		Transpose image (across UL-to-LR axis).
kusano 7d535a
	-transverse		Transverse transpose (across UR-to-LL axis).
kusano 7d535a
kusano 7d535a
The transpose transformation has no restrictions regarding image dimensions.
kusano 7d535a
The other transformations operate rather oddly if the image dimensions are not
kusano 7d535a
a multiple of the iMCU size (usually 8 or 16 pixels), because they can only
kusano 7d535a
transform complete blocks of DCT coefficient data in the desired way.
kusano 7d535a
kusano 7d535a
jpegtran's default behavior when transforming an odd-size image is designed
kusano 7d535a
to preserve exact reversibility and mathematical consistency of the
kusano 7d535a
transformation set.  As stated, transpose is able to flip the entire image
kusano 7d535a
area.  Horizontal mirroring leaves any partial iMCU column at the right edge
kusano 7d535a
untouched, but is able to flip all rows of the image.  Similarly, vertical
kusano 7d535a
mirroring leaves any partial iMCU row at the bottom edge untouched, but is
kusano 7d535a
able to flip all columns.  The other transforms can be built up as sequences
kusano 7d535a
of transpose and flip operations; for consistency, their actions on edge
kusano 7d535a
pixels are defined to be the same as the end result of the corresponding
kusano 7d535a
transpose-and-flip sequence.
kusano 7d535a
kusano 7d535a
For practical use, you may prefer to discard any untransformable edge pixels
kusano 7d535a
rather than having a strange-looking strip along the right and/or bottom edges
kusano 7d535a
of a transformed image.  To do this, add the -trim switch:
kusano 7d535a
	-trim		Drop non-transformable edge blocks.
kusano 7d535a
Obviously, a transformation with -trim is not reversible, so strictly speaking
kusano 7d535a
jpegtran with this switch is not lossless.  Also, the expected mathematical
kusano 7d535a
equivalences between the transformations no longer hold.  For example,
kusano 7d535a
"-rot 270 -trim" trims only the bottom edge, but "-rot 90 -trim" followed by
kusano 7d535a
"-rot 180 -trim" trims both edges.
kusano 7d535a
kusano 7d535a
If you are only interested in perfect transformation, add the -perfect switch:
kusano 7d535a
	-perfect	Fails with an error if the transformation is not
kusano 7d535a
			perfect.
kusano 7d535a
For example you may want to do
kusano 7d535a
  jpegtran -rot 90 -perfect foo.jpg || djpeg foo.jpg | pnmflip -r90 | cjpeg
kusano 7d535a
to do a perfect rotation if available or an approximated one if not.
kusano 7d535a
kusano 7d535a
We also offer a lossless-crop option, which discards data outside a given
kusano 7d535a
image region but losslessly preserves what is inside.  Like the rotate and
kusano 7d535a
flip transforms, lossless crop is restricted by the current JPEG format: the
kusano 7d535a
upper left corner of the selected region must fall on an iMCU boundary.  If
kusano 7d535a
this does not hold for the given crop parameters, we silently move the upper
kusano 7d535a
left corner up and/or left to make it so, simultaneously increasing the region
kusano 7d535a
dimensions to keep the lower right crop corner unchanged.  (Thus, the output
kusano 7d535a
image covers at least the requested region, but may cover more.)
kusano 7d535a
kusano 7d535a
The image can be losslessly cropped by giving the switch:
kusano 7d535a
	-crop WxH+X+Y	Crop to a rectangular subarea of width W, height H
kusano 7d535a
			starting at point X,Y.
kusano 7d535a
kusano 7d535a
Other not-strictly-lossless transformation switches are:
kusano 7d535a
kusano 7d535a
	-grayscale	Force grayscale output.
kusano 7d535a
This option discards the chrominance channels if the input image is YCbCr
kusano 7d535a
(ie, a standard color JPEG), resulting in a grayscale JPEG file.  The
kusano 7d535a
luminance channel is preserved exactly, so this is a better method of reducing
kusano 7d535a
to grayscale than decompression, conversion, and recompression.  This switch
kusano 7d535a
is particularly handy for fixing a monochrome picture that was mistakenly
kusano 7d535a
encoded as a color JPEG.  (In such a case, the space savings from getting rid
kusano 7d535a
of the near-empty chroma channels won't be large; but the decoding time for
kusano 7d535a
a grayscale JPEG is substantially less than that for a color JPEG.)
kusano 7d535a
kusano 7d535a
	-scale M/N	Scale the output image by a factor M/N.
kusano 7d535a
Currently supported scale factors are M/N with all M from 1 to 16, where N is
kusano 7d535a
the source DCT size, which is 8 for baseline JPEG.  If the /N part is omitted,
kusano 7d535a
then M specifies the DCT scaled size to be applied on the given input.  For
kusano 7d535a
baseline JPEG this is equivalent to M/8 scaling, since the source DCT size
kusano 7d535a
for baseline JPEG is 8.  CAUTION: An implementation of the JPEG SmartScale
kusano 7d535a
extension is required for this feature.  SmartScale enabled JPEG is not yet
kusano 7d535a
widely implemented, so many decoders will be unable to view a SmartScale
kusano 7d535a
extended JPEG file at all.
kusano 7d535a
kusano 7d535a
jpegtran also recognizes these switches that control what to do with "extra"
kusano 7d535a
markers, such as comment blocks:
kusano 7d535a
	-copy none	Copy no extra markers from source file.  This setting
kusano 7d535a
			suppresses all comments and other excess baggage
kusano 7d535a
			present in the source file.
kusano 7d535a
	-copy comments	Copy only comment markers.  This setting copies
kusano 7d535a
			comments from the source file, but discards
kusano 7d535a
			any other inessential (for image display) data.
kusano 7d535a
	-copy all	Copy all extra markers.  This setting preserves
kusano 7d535a
			miscellaneous markers found in the source file, such
kusano 7d535a
			as JFIF thumbnails, Exif data, and Photoshop settings.
kusano 7d535a
			In some files these extra markers can be sizable.
kusano 7d535a
The default behavior is -copy comments.  (Note: in IJG releases v6 and v6a,
kusano 7d535a
jpegtran always did the equivalent of -copy none.)
kusano 7d535a
kusano 7d535a
Additional switches recognized by jpegtran are:
kusano 7d535a
	-outfile filename
kusano 7d535a
	-maxmemory N
kusano 7d535a
	-verbose
kusano 7d535a
	-debug
kusano 7d535a
These work the same as in cjpeg or djpeg.
kusano 7d535a
kusano 7d535a
kusano 7d535a
THE COMMENT UTILITIES
kusano 7d535a
kusano 7d535a
The JPEG standard allows "comment" (COM) blocks to occur within a JPEG file.
kusano 7d535a
Although the standard doesn't actually define what COM blocks are for, they
kusano 7d535a
are widely used to hold user-supplied text strings.  This lets you add
kusano 7d535a
annotations, titles, index terms, etc to your JPEG files, and later retrieve
kusano 7d535a
them as text.  COM blocks do not interfere with the image stored in the JPEG
kusano 7d535a
file.  The maximum size of a COM block is 64K, but you can have as many of
kusano 7d535a
them as you like in one JPEG file.
kusano 7d535a
kusano 7d535a
We provide two utility programs to display COM block contents and add COM
kusano 7d535a
blocks to a JPEG file.
kusano 7d535a
kusano 7d535a
rdjpgcom searches a JPEG file and prints the contents of any COM blocks on
kusano 7d535a
standard output.  The command line syntax is
kusano 7d535a
	rdjpgcom [-raw] [-verbose] [inputfilename]
kusano 7d535a
The switch "-raw" (or just "-r") causes rdjpgcom to also output non-printable
kusano 7d535a
characters in comments, which are normally escaped for security reasons.
kusano 7d535a
The switch "-verbose" (or just "-v") causes rdjpgcom to also display the JPEG
kusano 7d535a
image dimensions.  If you omit the input file name from the command line,
kusano 7d535a
the JPEG file is read from standard input.  (This may not work on some
kusano 7d535a
operating systems, if binary data can't be read from stdin.)
kusano 7d535a
kusano 7d535a
wrjpgcom adds a COM block, containing text you provide, to a JPEG file.
kusano 7d535a
Ordinarily, the COM block is added after any existing COM blocks, but you
kusano 7d535a
can delete the old COM blocks if you wish.  wrjpgcom produces a new JPEG
kusano 7d535a
file; it does not modify the input file.  DO NOT try to overwrite the input
kusano 7d535a
file by directing wrjpgcom's output back into it; on most systems this will
kusano 7d535a
just destroy your file.
kusano 7d535a
kusano 7d535a
The command line syntax for wrjpgcom is similar to cjpeg's.  On Unix-like
kusano 7d535a
systems, it is
kusano 7d535a
	wrjpgcom [switches] [inputfilename]
kusano 7d535a
The output file is written to standard output.  The input file comes from
kusano 7d535a
the named file, or from standard input if no input file is named.
kusano 7d535a
kusano 7d535a
On most non-Unix systems, the syntax is
kusano 7d535a
	wrjpgcom [switches] inputfilename outputfilename
kusano 7d535a
where both input and output file names must be given explicitly.
kusano 7d535a
kusano 7d535a
wrjpgcom understands three switches:
kusano 7d535a
	-replace		 Delete any existing COM blocks from the file.
kusano 7d535a
	-comment "Comment text"	 Supply new COM text on command line.
kusano 7d535a
	-cfile name		 Read text for new COM block from named file.
kusano 7d535a
(Switch names can be abbreviated.)  If you have only one line of comment text
kusano 7d535a
to add, you can provide it on the command line with -comment.  The comment
kusano 7d535a
text must be surrounded with quotes so that it is treated as a single
kusano 7d535a
argument.  Longer comments can be read from a text file.
kusano 7d535a
kusano 7d535a
If you give neither -comment nor -cfile, then wrjpgcom will read the comment
kusano 7d535a
text from standard input.  (In this case an input image file name MUST be
kusano 7d535a
supplied, so that the source JPEG file comes from somewhere else.)  You can
kusano 7d535a
enter multiple lines, up to 64KB worth.  Type an end-of-file indicator
kusano 7d535a
(usually control-D or control-Z) to terminate the comment text entry.
kusano 7d535a
kusano 7d535a
wrjpgcom will not add a COM block if the provided comment string is empty.
kusano 7d535a
Therefore -replace -comment "" can be used to delete all COM blocks from a
kusano 7d535a
file.
kusano 7d535a
kusano 7d535a
These utility programs do not depend on the IJG JPEG library.  In
kusano 7d535a
particular, the source code for rdjpgcom is intended as an illustration of
kusano 7d535a
the minimum amount of code required to parse a JPEG file header correctly.