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

Carlos Lopez a09598
Advanced usage instructions for the Independent JPEG Group's JPEG software
Carlos Lopez a09598
==========================================================================
Carlos Lopez a09598
Carlos Lopez a09598
This file describes cjpeg's "switches for wizards".
Carlos Lopez a09598
Carlos Lopez a09598
The "wizard" switches are intended for experimentation with JPEG by persons
Carlos Lopez a09598
who are reasonably knowledgeable about the JPEG standard.  If you don't know
Carlos Lopez a09598
what you are doing, DON'T USE THESE SWITCHES.  You'll likely produce files
Carlos Lopez a09598
with worse image quality and/or poorer compression than you'd get from the
Carlos Lopez a09598
default settings.  Furthermore, these switches must be used with caution
Carlos Lopez a09598
when making files intended for general use, because not all JPEG decoders
Carlos Lopez a09598
will support unusual JPEG parameter settings.
Carlos Lopez a09598
Carlos Lopez a09598
Carlos Lopez a09598
Quantization Table Adjustment
Carlos Lopez a09598
-----------------------------
Carlos Lopez a09598
Carlos Lopez a09598
Ordinarily, cjpeg starts with a default set of tables (the same ones given
Carlos Lopez a09598
as examples in the JPEG standard) and scales them up or down according to
Carlos Lopez a09598
the -quality setting.  The details of the scaling algorithm can be found in
Carlos Lopez a09598
jcparam.c.  At very low quality settings, some quantization table entries
Carlos Lopez a09598
can get scaled up to values exceeding 255.  Although 2-byte quantization
Carlos Lopez a09598
values are supported by the IJG software, this feature is not in baseline
Carlos Lopez a09598
JPEG and is not supported by all implementations.  If you need to ensure
Carlos Lopez a09598
wide compatibility of low-quality files, you can constrain the scaled
Carlos Lopez a09598
quantization values to no more than 255 by giving the -baseline switch.
Carlos Lopez a09598
Note that use of -baseline will result in poorer quality for the same file
Carlos Lopez a09598
size, since more bits than necessary are expended on higher AC coefficients.
Carlos Lopez a09598
Carlos Lopez a09598
You can substitute a different set of quantization values by using the
Carlos Lopez a09598
-qtables switch:
Carlos Lopez a09598
Carlos Lopez a09598
	-qtables file	Use the quantization tables given in the named file.
Carlos Lopez a09598
Carlos Lopez a09598
The specified file should be a text file containing decimal quantization
Carlos Lopez a09598
values.  The file should contain one to four tables, each of 64 elements.
Carlos Lopez a09598
The tables are implicitly numbered 0,1,etc. in order of appearance.  Table
Carlos Lopez a09598
entries appear in normal array order (NOT in the zigzag order in which they
Carlos Lopez a09598
will be stored in the JPEG file).
Carlos Lopez a09598
Carlos Lopez a09598
Quantization table files are free format, in that arbitrary whitespace can
Carlos Lopez a09598
appear between numbers.  Also, comments can be included: a comment starts
Carlos Lopez a09598
with '#' and extends to the end of the line.  Here is an example file that
Carlos Lopez a09598
duplicates the default quantization tables:
Carlos Lopez a09598
Carlos Lopez a09598
	# Quantization tables given in JPEG spec, section K.1
Carlos Lopez a09598
Carlos Lopez a09598
	# This is table 0 (the luminance table):
Carlos Lopez a09598
	  16  11  10  16  24  40  51  61
Carlos Lopez a09598
	  12  12  14  19  26  58  60  55
Carlos Lopez a09598
	  14  13  16  24  40  57  69  56
Carlos Lopez a09598
	  14  17  22  29  51  87  80  62
Carlos Lopez a09598
	  18  22  37  56  68 109 103  77
Carlos Lopez a09598
	  24  35  55  64  81 104 113  92
Carlos Lopez a09598
	  49  64  78  87 103 121 120 101
Carlos Lopez a09598
	  72  92  95  98 112 100 103  99
Carlos Lopez a09598
Carlos Lopez a09598
	# This is table 1 (the chrominance table):
Carlos Lopez a09598
	  17  18  24  47  99  99  99  99
Carlos Lopez a09598
	  18  21  26  66  99  99  99  99
Carlos Lopez a09598
	  24  26  56  99  99  99  99  99
Carlos Lopez a09598
	  47  66  99  99  99  99  99  99
Carlos Lopez a09598
	  99  99  99  99  99  99  99  99
Carlos Lopez a09598
	  99  99  99  99  99  99  99  99
Carlos Lopez a09598
	  99  99  99  99  99  99  99  99
Carlos Lopez a09598
	  99  99  99  99  99  99  99  99
Carlos Lopez a09598
Carlos Lopez a09598
If the -qtables switch is used without -quality, then the specified tables
Carlos Lopez a09598
are used exactly as-is.  If both -qtables and -quality are used, then the
Carlos Lopez a09598
tables taken from the file are scaled in the same fashion that the default
Carlos Lopez a09598
tables would be scaled for that quality setting.  If -baseline appears, then
Carlos Lopez a09598
the quantization values are constrained to the range 1-255.
Carlos Lopez a09598
Carlos Lopez a09598
By default, cjpeg will use quantization table 0 for luminance components and
Carlos Lopez a09598
table 1 for chrominance components.  To override this choice, use the -qslots
Carlos Lopez a09598
switch:
Carlos Lopez a09598
Carlos Lopez a09598
	-qslots N[,...]		Select which quantization table to use for
Carlos Lopez a09598
				each color component.
Carlos Lopez a09598
Carlos Lopez a09598
The -qslots switch specifies a quantization table number for each color
Carlos Lopez a09598
component, in the order in which the components appear in the JPEG SOF marker.
Carlos Lopez a09598
For example, to create a separate table for each of Y,Cb,Cr, you could
Carlos Lopez a09598
provide a -qtables file that defines three quantization tables and say
Carlos Lopez a09598
"-qslots 0,1,2".  If -qslots gives fewer table numbers than there are color
Carlos Lopez a09598
components, then the last table number is repeated as necessary.
Carlos Lopez a09598
Carlos Lopez a09598
Carlos Lopez a09598
Sampling Factor Adjustment
Carlos Lopez a09598
--------------------------
Carlos Lopez a09598
Carlos Lopez a09598
By default, cjpeg uses 2:1 horizontal and vertical downsampling when
Carlos Lopez a09598
compressing YCbCr data, and no downsampling for all other color spaces.
Carlos Lopez a09598
You can override this default with the -sample switch:
Carlos Lopez a09598
Carlos Lopez a09598
	-sample HxV[,...]	Set JPEG sampling factors for each color
Carlos Lopez a09598
				component.
Carlos Lopez a09598
Carlos Lopez a09598
The -sample switch specifies the JPEG sampling factors for each color
Carlos Lopez a09598
component, in the order in which they appear in the JPEG SOF marker.
Carlos Lopez a09598
If you specify fewer HxV pairs than there are components, the remaining
Carlos Lopez a09598
components are set to 1x1 sampling.  For example, the default YCbCr setting
Carlos Lopez a09598
is equivalent to "-sample 2x2,1x1,1x1", which can be abbreviated to
Carlos Lopez a09598
"-sample 2x2".
Carlos Lopez a09598
Carlos Lopez a09598
There are still some JPEG decoders in existence that support only 2x1
Carlos Lopez a09598
sampling (also called 4:2:2 sampling).  Compatibility with such decoders can
Carlos Lopez a09598
be achieved by specifying "-sample 2x1".  This is not recommended unless
Carlos Lopez a09598
really necessary, since it increases file size and encoding/decoding time
Carlos Lopez a09598
with very little quality gain.
Carlos Lopez a09598
Carlos Lopez a09598
Carlos Lopez a09598
Multiple Scan / Progression Control
Carlos Lopez a09598
-----------------------------------
Carlos Lopez a09598
Carlos Lopez a09598
By default, cjpeg emits a single-scan sequential JPEG file.  The
Carlos Lopez a09598
-progressive switch generates a progressive JPEG file using a default series
Carlos Lopez a09598
of progression parameters.  You can create multiple-scan sequential JPEG
Carlos Lopez a09598
files or progressive JPEG files with custom progression parameters by using
Carlos Lopez a09598
the -scans switch:
Carlos Lopez a09598
Carlos Lopez a09598
	-scans file	Use the scan sequence given in the named file.
Carlos Lopez a09598
Carlos Lopez a09598
The specified file should be a text file containing a "scan script".
Carlos Lopez a09598
The script specifies the contents and ordering of the scans to be emitted.
Carlos Lopez a09598
Each entry in the script defines one scan.  A scan definition specifies
Carlos Lopez a09598
the components to be included in the scan, and for progressive JPEG it also
Carlos Lopez a09598
specifies the progression parameters Ss,Se,Ah,Al for the scan.  Scan
Carlos Lopez a09598
definitions are separated by semicolons (';').  A semicolon after the last
Carlos Lopez a09598
scan definition is optional.
Carlos Lopez a09598
Carlos Lopez a09598
Each scan definition contains one to four component indexes, optionally
Carlos Lopez a09598
followed by a colon (':') and the four progressive-JPEG parameters.  The
Carlos Lopez a09598
component indexes denote which color component(s) are to be transmitted in
Carlos Lopez a09598
the scan.  Components are numbered in the order in which they appear in the
Carlos Lopez a09598
JPEG SOF marker, with the first component being numbered 0.  (Note that these
Carlos Lopez a09598
indexes are not the "component ID" codes assigned to the components, just
Carlos Lopez a09598
positional indexes.)
Carlos Lopez a09598
Carlos Lopez a09598
The progression parameters for each scan are:
Carlos Lopez a09598
	Ss	Zigzag index of first coefficient included in scan
Carlos Lopez a09598
	Se	Zigzag index of last coefficient included in scan
Carlos Lopez a09598
	Ah	Zero for first scan of a coefficient, else Al of prior scan
Carlos Lopez a09598
	Al	Successive approximation low bit position for scan
Carlos Lopez a09598
If the progression parameters are omitted, the values 0,63,0,0 are used,
Carlos Lopez a09598
producing a sequential JPEG file.  cjpeg automatically determines whether
Carlos Lopez a09598
the script represents a progressive or sequential file, by observing whether
Carlos Lopez a09598
Ss and Se values other than 0 and 63 appear.  (The -progressive switch is
Carlos Lopez a09598
not needed to specify this; in fact, it is ignored when -scans appears.)
Carlos Lopez a09598
The scan script must meet the JPEG restrictions on progression sequences.
Carlos Lopez a09598
(cjpeg checks that the spec's requirements are obeyed.)
Carlos Lopez a09598
Carlos Lopez a09598
Scan script files are free format, in that arbitrary whitespace can appear
Carlos Lopez a09598
between numbers and around punctuation.  Also, comments can be included: a
Carlos Lopez a09598
comment starts with '#' and extends to the end of the line.  For additional
Carlos Lopez a09598
legibility, commas or dashes can be placed between values.  (Actually, any
Carlos Lopez a09598
single punctuation character other than ':' or ';' can be inserted.)  For
Carlos Lopez a09598
example, the following two scan definitions are equivalent:
Carlos Lopez a09598
	0 1 2: 0 63 0 0;
Carlos Lopez a09598
	0,1,2 : 0-63, 0,0 ;
Carlos Lopez a09598
Carlos Lopez a09598
Here is an example of a scan script that generates a partially interleaved
Carlos Lopez a09598
sequential JPEG file:
Carlos Lopez a09598
Carlos Lopez a09598
	0;			# Y only in first scan
Carlos Lopez a09598
	1 2;			# Cb and Cr in second scan
Carlos Lopez a09598
Carlos Lopez a09598
Here is an example of a progressive scan script using only spectral selection
Carlos Lopez a09598
(no successive approximation):
Carlos Lopez a09598
Carlos Lopez a09598
	# Interleaved DC scan for Y,Cb,Cr:
Carlos Lopez a09598
	0,1,2: 0-0,   0, 0 ;
Carlos Lopez a09598
	# AC scans:
Carlos Lopez a09598
	0:     1-2,   0, 0 ;	# First two Y AC coefficients
Carlos Lopez a09598
	0:     3-5,   0, 0 ;	# Three more
Carlos Lopez a09598
	1:     1-63,  0, 0 ;	# All AC coefficients for Cb
Carlos Lopez a09598
	2:     1-63,  0, 0 ;	# All AC coefficients for Cr
Carlos Lopez a09598
	0:     6-9,   0, 0 ;	# More Y coefficients
Carlos Lopez a09598
	0:     10-63, 0, 0 ;	# Remaining Y coefficients
Carlos Lopez a09598
Carlos Lopez a09598
Here is an example of a successive-approximation script.  This is equivalent
Carlos Lopez a09598
to the default script used by "cjpeg -progressive" for YCbCr images:
Carlos Lopez a09598
Carlos Lopez a09598
	# Initial DC scan for Y,Cb,Cr (lowest bit not sent)
Carlos Lopez a09598
	0,1,2: 0-0,   0, 1 ;
Carlos Lopez a09598
	# First AC scan: send first 5 Y AC coefficients, minus 2 lowest bits:
Carlos Lopez a09598
	0:     1-5,   0, 2 ;
Carlos Lopez a09598
	# Send all Cr,Cb AC coefficients, minus lowest bit:
Carlos Lopez a09598
	# (chroma data is usually too small to be worth subdividing further;
Carlos Lopez a09598
	#  but note we send Cr first since eye is least sensitive to Cb)
Carlos Lopez a09598
	2:     1-63,  0, 1 ;
Carlos Lopez a09598
	1:     1-63,  0, 1 ;
Carlos Lopez a09598
	# Send remaining Y AC coefficients, minus 2 lowest bits:
Carlos Lopez a09598
	0:     6-63,  0, 2 ;
Carlos Lopez a09598
	# Send next-to-lowest bit of all Y AC coefficients:
Carlos Lopez a09598
	0:     1-63,  2, 1 ;
Carlos Lopez a09598
	# At this point we've sent all but the lowest bit of all coefficients.
Carlos Lopez a09598
	# Send lowest bit of DC coefficients
Carlos Lopez a09598
	0,1,2: 0-0,   1, 0 ;
Carlos Lopez a09598
	# Send lowest bit of AC coefficients
Carlos Lopez a09598
	2:     1-63,  1, 0 ;
Carlos Lopez a09598
	1:     1-63,  1, 0 ;
Carlos Lopez a09598
	# Y AC lowest bit scan is last; it's usually the largest scan
Carlos Lopez a09598
	0:     1-63,  1, 0 ;
Carlos Lopez a09598
Carlos Lopez a09598
It may be worth pointing out that this script is tuned for quality settings
Carlos Lopez a09598
of around 50 to 75.  For lower quality settings, you'd probably want to use
Carlos Lopez a09598
a script with fewer stages of successive approximation (otherwise the
Carlos Lopez a09598
initial scans will be really bad).  For higher quality settings, you might
Carlos Lopez a09598
want to use more stages of successive approximation (so that the initial
Carlos Lopez a09598
scans are not too large).