<!doctype linuxdoc system>
<article>

<!-- Title information -->

<title>Color correction for pnm2ppa
<author>The pnm2ppa project team 
<htmlurl url="mailto:ppa-rpms@sourceforge.net"
name="ppa-rpms@users.sourceforge.net">
<date> v0.6, October 28,  2000
<abstract>
Information and instructions
for color correction of pnm2ppa
color printing.
<htmlurl 
url="http://sourceforge.net/projects/pnm2ppa"
name="http://sourceforge.net/projects/pnm2ppa">
(Updated for pnm2ppa-1.0 and later.)
</abstract>

<!-- Begin the document -->


<p>
<bf> Overview of Color correction.</bf>

Color Pixmap input to <tt>pnm2ppa</tt> (ppm format, produced
by the ghostscript output devices <tt>ppmraw</tt> or <tt>ppm</tt>)
specifies the color of a pixel  as three coordinates (Red, Green, Blue) in the
range 0-255.   The program <tt>pnm2ppa</tt> converts these to relative amounts
of Cyan, Magenta and Yellow ink drops printed on the page.

<bf>Color correction</bf> allows the user to attempt to match the printed
colors to some reference colors, such as those displayed on the
terminal, or those printed on a different printer,  or those printed
on the same printer  with a different
driver (such as the Win9x drivers supplied by HP with their PPA printers).


The color output from <tt>pnm2ppa</tt> can be controlled in two ways:
<itemize>
<item> by a color correction &quot;gamma&quot; file, if it is installed.
By  default this file is 
<tt>/etc/pnm2ppa.gamma</tt>,
but it may also be specified with the pnm2ppa option 
<tt> pnm2ppa ... -F gammafile ... </tt>.
<item> if there is no gamma file,  by  three values
specified by keywords ( either
<tt>GammaR</tt>,
<tt>GammaG</tt>,
<tt>GammaB</tt>
or
<tt>RedGammaIdx</tt>, 
<tt>BlueGammaIdx</tt>, 
<tt>GreenGammaIdx</tt>) in the
<tt>pnm2ppa</tt> configuration file.
</itemize>


<tt>pnm2ppa</tt> will carry out  <bf>&quot;color correction&quot;</bf>,
unless it is called with the <bf>--noGamma</bf> command line option.
However, unless you set up a color correction scheme, the default
color correction does not change any colors.


Color correction is specified by three color intensity
functions (curves), one for each of
Red, Green, and Blue.    In their simplest form, these curves
have a standard form controlled 
by a single &quot;gamma&quot; parameter such as
<tt>GammaR</tt>.  The more sophisticated correction, in the
file <tt>pnm2ppa.gamma</tt>, specifies these curves more generally
as a table of numbers that translate each possible
color intensity value to a new value.



Note that, in principle, different color corrections are needed
for different print quality settings, and for different
brands and qualities of paper!

At present the methods for constructing a  color correction for
<tt>pnm2ppa</tt> are not very user-friendly.  If you can improve
them, please help!.

<bf>
Color correction with &quot;gamma&quot; values in the configuration file.</bf>
<p>
The PixMap (ppa) format specifies colors by an intensity for
each primary color, Red, Green and Blue, in the range 0-255, so
(0,0,0) is black, and (255,255,255) is white.
The standard color intensity enhancement function replaces the ppm
intensity <tt>i</tt> of each  primary color by 
<tt> Enh(i) </tt> which is the closest integer
to  ( i / 256)  raised to the power
<tt>Gamma</tt>, times 256.


You can specify the Gamma values in the configuration file
as decimal numbers <tt>GammaR</tt>, <tt>GammaG</tt>, <tt>GammaB</tt>,
but how do you find out what values to choose?.   Perhaps by experimenting
with changing the Gamma values.

A source of information on Gamma color correction  is
<htmlurl url="http://www.cgsd.com/papers/gamma.html"
name="www.cgsd.com/papers/gamma.html">


One method for constructing a Gamma correction
has been built into <tt>pnm2ppa</tt>, but it 
wastes quite a lot of ink, and many users
find it less effective than producing a customized
color correction curve as described in the next section.


You must first use pnm2ppa to print a color test page, and then 
generate a file <tt>gamma.ppm</tt> to compare to it.
To do this, type
<tscreen><verb>
pnm2ppa -g -i - -o /dev/lp0
</verb></tscreen>
(replace <tt>/dev/lp0</tt> by whatever printer device your PPA printer uses,
or use <tt> ... -o - | lpr -l </tt>, etc.).   Note also that
as <tt>pnm2ppa</tt> is not receiving any ghostscript input to tell it
the paper size, this must be correctly specified by a configuration
file entry or, e.g., a  <tt> -s a4 </tt> option, if the default US Letter
paper is not being used.   This procedure will print a color calibration
page.

The printed output is an array of sets of three colored bands,
red, blue and green, each of which increases in brightness from
left to right.   The topmost set of bands should be referrred to as
bands &quot;0&quot;, the next ones as &quot;1&quot;, etc.

Next, run the extra program <tt>calibrate_ppa</tt> which will produce
a (large, 10MB) PixMap (ppm) file:
<tscreen><verb>
calibrate_ppa -g -o gamma.ppm
</verb></tscreen>
This will produce the PixMap file as
<tt>gamma.ppm</tt> in the current directory.

To color-correct the printer so that its colors match those on the
terminal screen,
you should now attempt to view the file <tt>gamma.ppm</tt> 
using some application 
(such as the GNU image manipulation program <tt>gimp</tt>, or <tt>xv</tt>)
that can view <tt>.ppm</tt> files.    For each color, identify the
printed band (0, 1, 2, ... etc)
that most closely corresponds to the brightness profile
shown on the screen.    The default values are now:
<tscreen><verb>
RedGammaIdx 0
GreenGammaIdx 0
BlueGammaIdx 0
</verb></tscreen>
(i.e., no color correction).
Enter your modified values for these in the <tt>pnm2ppa</tt>
configuration file (usually <tt>/etc/pnm2ppa.conf</tt>).

The actual Gamma value is then  <bf>1.0 - 0.033*(Color)GammaIdx </bf>;

To color-correct with respect to another printer (or the Win9x drivers),
you must manage to print <tt>gamma.ppm</tt> on that other device, then
make the comparison.  (Or print the output of <tt>pnm2ppa -g  </tt>
on that device; the top line is  the same uncorrected color data as  
<tt>gamma.ppm</tt>.)

<bf>
Color correction using a &quot;gamma file&quot;.
</bf>

A &quot;gamma correction file&quot; is a binary file containing 
3 x 256 numbers, 
which are lookup tables of corrected  red green and blue
color intensities.

The program <tt>pnm2ppa</tt> will use a default correction file
<tt>/etc/pnm2ppa.gamma</tt> if it exists, unless the 
<tt>--noGamma </tt> option is used.    The default correction file
location can be changed by using the <tt>pnm2ppa</tt>
option  <tt>-F gammafile </tt>, where &quot;gammafile&quot; is the name
(including the full path) of the gamma correction file to be used.


Currently, there are two available tools for constructing a gamma
correction file:
<itemize>
<item>
A graphical utility <tt>ppagammacorrect</tt> is available in the
PPA Color Correction Utilities section of
the <tt>pnm2ppa</tt> web page 
<htmlurl 
url="http://sourceforge.net/projects/pnm2ppa"
name="http://sourceforge.net/projects/pnm2ppa">,
(but at the time of writing,
this appears to be frozen in early stages of development, with
little documentation, and may not be fully functional).
<item>
A working procedure is given in
<htmlurl 
url="http://download.sourceforge.net/pnm2ppa/color-calibrate-1.0.tar.gz"
name="http://download.sourceforge.net/pnm2ppa/color-calibrate-1.0.tar.gz">,
which is made available by Klamer Schutte.
<bf>This is the method recommended by many users.</bf>
</itemize>

</article>














