Blame gtkmm-osx/jpeg-6b/usage.doc

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