Blob Blame History Raw
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Libnetpbm PPM Drawing Function Manual</TITLE>
<META NAME="manual_section" CONTENT="3">
</HEAD>
<BODY>
<H1>Libnetpbm PPM Drawing Function Manual</H1>
Updated: February 2017
<br>
<p><A HREF="#toc">Table Of Contents</A>
<?makeman .SH NAME ?>
<?makeman libnetpbm_draw \- Libnetpbm PPM Drawing Function Manual ?>
<?makeman .SH DESCRIPTION ?>

<p>This reference manual covers functions in the <b>libnetpbm</b>
library for drawing images, using the PPM image format and the
<b>libnetpbm</b> in-memory image formats.

<p>We actually have very little information here; this is mainly a
framework for adding documentation later if someone becomes interested
in this facility.


<h2 id="basicfunctions">Basic Functions</h2>

<p>The functions are all declared in the <b>ppmdraw.h</b> header file.

<h3 id="ppmd_setlinetype"><b>ppmd_setlinetype</b></h3>

<h3 id="ppmd_setlineclip"><b>ppmd_setlineclip</b></h3>

<h3 id="ppmd_line"><b>ppmd_line</b></h3>

<h3 id="ppmd_spline3"><b>ppmd_spline3</b></h3>

<h3 id="ppmd_polyspline"><b>ppmd_polyspline</b></h3>

<h3 id="ppmd_circle"><b>ppmd_circle</b></h3>

<h3 id="ppmd_filledrectangle"><b>ppmd_filledrectangle</b></h3>

<h3 id="ppmd_fill"><b>ppmd_fill</b></h3>

<h3 id="ppmd_text"><b>ppmd_text</b></h3>

<h3 id="ppmd_text_box"><b>ppmd_text_box</b></h3>


<h2 id="drawprocs">Drawprocs</h2>

<p>Drawprocs are functions that tell how to draw a point.  You pass drawprocs
to drawing functions that require them.

<p>There are two types: <b>ppmd_drawprocp</b> and <b>ppmd_drawproc</b>.  The
only difference is that the former takes the location at which to draw the
point as an argument of point type (<b>ppmd_point</b>), whereas the latter
takes integer column and row arguments.

<h3 id="ppmd_point_drawproc"><b>ppmd_point_drawproc</b></h3>

<p>This simply fills in a single pixel.  This is usually what you want.


<h3 id="ppmd_fill_drawprocp"><b>ppmd_fill_drawprocp</b></h3>

<p>This Drawproc is useful for filling, in that it not only draws on the
canvas, but remembers where it's been, outlining an area that you can fill
with <b>ppmd_fill</b>.

<h3 id="ppmd_fill_drawproc"><b>ppmd_fill_drawproc</b></h3>

<p>This is the same thing as <b>ppmd_fill_drawprocp</b> except that it is
a <b>ppmd_drawproc</b> function instead of <b>ppmd_drawprocp</b>.


<h2 id="pathfill">Path Filling Function</h2>

<h3 id="ppmd_fill_path"><b>ppmd_fill_path</b></h3>

<h4>Synopsis</h4>

<pre>
<code>
void
ppmd_fill_path(pixel **      pixels, 
               int           cols, 
               int           rows, 
               pixval        maxval,
               ppmd_path *   pathP,
               pixel         color);
</code>
</pre>

<h4>Description</h4>

<p>This fills a closed path.

<p><i>pixels</i>, <i>cols</i>, <i>rows</i>, and <i>maxval</i> describe the
canvas on which to draw.

<p><i>pathP</i> identifies a closed path on that canvas.  If it does not end
on the same point at which it starts, 
<b>ppmd_fill_path</b> aborts the program with a call to <b>pm_error</b>.  The
path may cross itself, though, creating multiple closed areas, each of
which <b>ppmd_fill_path</b> fills.  The path must fit within the <i>cols</i>
x <i>rows</i> dimensions.  If it does not,
<b>ppmd_fill_path</b> aborts the program with a call to <b>pm_error</b>.

<p><i>color</i> is the fill color.  <b>ppmd_fill_path</b> makes every pixel
within the closed path that color.

<p><b>ppmd_fill</b> is more general, but harder to use.  With that, you can
fill with a pattern.

<p>This function was new in Netpbm 10.34 (June 2006).

<h3 id="ppmd_makeLineLeg">ppmd_makeLineLeg</h3>

<P>This function returns a data structure of type <b>ppmd_pathleg</b>, to
be used in a data structure of type <b>ppmd_path</b>, to be use with
function <b>ppmd_fill_path</b>.

<p>This function was new in Netbm 10.78 (March 2017).


<h2 id="pathbuilder">Path Builder</h2>

<p>The functions in this section are for building a path (<b>ppmd_path</b>)
for use with <b>ppmd_fill_path</b>.

<p>It is an object-oriented set of functions, where the object involved is of
type <b>ppmd_path_builder</b>.  This is an opaque structure that you should
not access directly, but only through the functions in this section.

<p>Here is an example that generates a filled rectangle:

<pre>
<code>
    pixels = ppm_allocarray(100, 100);

    unsigned int row;

    /* Initialize the canvas to all black */
    for (row = 0; row &lt; 100; ++row) {
        unsigned int col;
        for (col = 0; col &lt; 100; ++col)
            pixels[row][col] = ppm_blackpixel();
    }

    /* Create a rectangular path */
    ppmd_pathbuilder * const pathBuilderP = ppmd_pathbuilder_create();

    ppmd_pathbuilder_setBegPoint(pathBuilderP, ppmd_makePoint(5, 5));

    ppmd_pathbuilder_addLineLeg(pathBuilderP,
                                ppmd_makeLineLeg(ppmd_makePoint(5, 50)));

    ppmd_pathbuilder_addLineLeg(pathBuilderP,
                                ppmd_makeLineLeg(ppmd_makePoint(50, 50)));

    ppmd_pathbuilder_addLineLeg(pathBuilderP,
                                ppmd_makeLineLeg(ppmd_makePoint(50, 5)));

    ppmd_pathbuilder_addLineLeg(pathBuilderP,
                                ppmd_makeLineLeg(ppmd_makePoint(5, 5)));

    /* Fill the area enclosed by that path with white */
    ppmd_fill_path(pixels, 100, 100, PPM_MAXMAXVAL,
                   ppmd_pathbuilder_pathP(pathBuilderP),
                   ppm_whitepixel(PPM_MAXMAXVAL));

    /* Destroy the path */
    ppmd_pathbuilder_destroy(pathBuilderP);
</code>
</pre>

<p>There are two ways to manage the space in which the leg array of the
<b>ppmd_path</b> structure resides.  Either you supply a fixed-length array
and the path builder just uses it or you have the path builder allocate the
storage automatically.

<p>If you let the path builder allocate the space automatically, you can
nonetheless tell the path builder how much space to allocate initially, to
make the path building more efficient.

<p>This facility was new in Netpbm 10.78 (March 2017).  Before that, you
have to build the <b>ppmd_path</b> by directly setting its members.

<h3 id="ppmd_path_builder_create">ppmd_path_builder</h3>

<p>This creates a <b>ppmd_path_builder</b> object (i.e. allocates memory for
it and initializes it).  You must ultimately destroy it
with <b>ppmd_path_builder_destroy</b>.


<h3 id="ppmd_path_builder_destroy">ppmd_path_builder_destroy</h3>

<p>This destroys a <b>ppmd_path_builder</b> object created with
<b>ppmd_path_builder_create</b> (i.e. frees the memory).

<h4>Synopsis</h4>

<pre>
<code>
    void
    ppmd_pathbuilder_destroy(ppmd_pathbuilder * pathBuilderP);    
</code>
</pre>

<h3 id="ppmd_pathbuilder_setLegArray">ppmd_pathbuilder_setLegArray</h3>

<p>With this function you supply the array of legs that the path builder will
fill.  The array has a fixed size, so you must know in advance how long the
path you build might be.

<h4>Example</h4>

<pre>
<code>
    ppmd_pathleg legs[4];

    ppmd_pathbuilder_setLegArray(pathBuilderP, legs, 4);
</code>
</pre>

<h4>Synopsis</h4>

<pre>
<code>
    void
    ppmd_pathbuilder_setLegArray(ppmd_pathbuilder * pathBuilderP,
                                 ppmd_pathleg *     legs,
                                 unsigned int       legCount);
</code>
</pre>

<h4>Description</h4>

<p><i>pathBuilderP</i> is the handle of the path builder object.

<p><i>legs</i> is the array you are supplying for the object to fill in.  This
is just space; no value the array has upon invocation is meaningful.

<p><i>legCount</i> is the number of elements of space exist in <i>legs</i>.
I.e. this is the maximum number of legs the builder can put in the array.  Any
attempt to put more legs than this in the array fails.

<p>This fails if the leg array is already set up, which could be because you
previously called <b>ppmd_pathbuilder_setLegArray</b>, 
<b>ppmd_pathbuilder_preallocLegArray</b>,
or <b>ppmd_pathbuilder_addLineLeg</b>.

<h3 id="ppmd_pathbuilder_preallocLegArray">ppmd_pathbuilder_preallocLegArray</h3>

<p>This causes the object to allocate some space for the array of path legs
the path builder will create.  If it needs more space, it will reallocate.  In
fact, you need not call this at all, because the path builder will allocate
space the first time it needs it.

<h4>Synopsis</h4>

<pre>
<code>
    void
    ppmd_pathbuilder_preallocLegArray(ppmd_pathbuilder * pathBuilderP,
                                      unsigned int       legCount);
</code>
</pre>

<h4>Description</h4>

<p><i>pathBuilderP</i> is the handle of the path builder object.

<p><i>legCount</i> is how many legs' worth of space to allocate.

<p>This fails if the leg array is already set up, which could be because you
previously called <b>ppmd_pathbuilder_setLegArray</b>, 
<b>ppmd_pathbuilder_preallocLegArray</b>,
or <b>ppmd_pathbuilder_addLineLeg</b>.


<h3 id="ppmd_pathbuilder_setBegPoint">ppmd_pathbuilder_setBegPoint</h3>

<p>This sets the beginning point for the path.  Note that to use the path for
filling, you must also make this the point at which the last leg of the path
ends.

<h4>Synopsis</h4>

<pre>
<code>
    void
    ppmd_pathbuilder_setBegPoint(ppmd_pathbuilder * pathBuilderP,
                                 ppmd_piont         begPoint);
</code>
</pre>

<h4>Description</h4>

<p><i>pathBuilderP</i> is the handle of the path builder object.

<p><i>begPoint</i> is the beginning point of the path.


<h3 id="ppmd_pathbuilder_addLineLeg">ppmd_pathbuilder_addLineLeg</h3>

<p>This adds a line segment leg to the path.

<h4>Synopsis</h4>

<pre>
<code>
    void
    ppmd_pathbuilder_addLineLeg(ppmd_pathbuilder * pathBuilderP,
                                ppmd_pathleg       leg);
</code>
</pre>

<h4>Description</h4>

<p><i>pathBuilderP</i> is the handle of the path builder object.

<p><i>leg</i> is the leg to add.

<p>The leg begins wherever the end of the path currently is (i.e. where the
most recently added leg ends, or the beginning point if you have not added any
paths yet).

<h3 id="ppmd_pathbuilder_pathP">ppmd_pathbuilder_pathP</h3>

<p>This is a pointer to the path that the path builder has built.

<h4>Synopsis</h4>

<pre>
<code>
    void
    ppmd_pathbuilder_pathP(ppmd_pathbuilder * pathBuilderP);
</code>
</pre>

<h4>Description</h4>

<p><i>pathBuilderP</i> is the handle of the path builder object.

<p>The data structure belongs to the path builder, so you must not use it
after you have destroyed the <b>ppmd_pathbuilder</b> object.

<p>The pointer is valid only until you call the next path builder method other
than <b>ppmd_pathbuilder_pathP</b>.  You normally don't get the pointer until
you are done building the path.


<h2 id="fonts">Fonts</h2>

<p>
The <b>ppmd_text</b> and <b>ppmd_text_box</b> functions use fonts.
You control the fonts using functions described in this section.
There is one font that comes with Netpbm, called "standard".
It is built into the function library and is the default font.  You
can create additional fonts and use them instead.

<p>In a program that uses Netpbm drawing facilities, there is a
"current font." all drawing of text uses the current font.
When the program starts, the current font is "standard"; you
can change it after that by calling the <b>ppmd_set_font</b> function.

<p>Other than a built-in font, a font lives in file in a format
special to Netpbm called Ppmdfont.  The file typically has a name that
ends in ".ppmdfont".

<p>Use the <b>ppmddumpfont</b> program to dump the contents of a
Ppmdfont file in human readable format.

<p>Use the <b>ppmdmkfont</b> program to generate the "standard"
font as a Ppmdfont file.  You don't normally need to do this, because
"standard" is built into <b>libnetpbm</b>.

<p>Use the <b>ppmdcfont</b> program to turn a Ppmdfont file into a C
source file that you can compile into a program as a built-in font.
Though we don't give full instructions here on how to do that,
<b>libnetpbm</b>'s built-in "standard" font is a good
example.  In Netpbm source code, you will find the C source file
<b>standardppmdfont.c</b>, which was generated from the file
<b>standard.ppmdfont</b> by <b>ppmdcfont</b>.  You simply use a
pointer to the structure that the C file defines as a font handle,
just like one you would get from <b>ppmd_read_font</b>.


<h2 id="fontfileformat">Font File Format</h2>

<p>The font file starts with the characters "ppmdfont" (without
the quotation marks) in ASCII.

<p>The rest of the format is not yet documented, but it generally
describes, for each code point, a sequence of straight line plotting
commands to form the glyph for the indicated character.  I.e. it is a
vector, not raster, font.


<h2 id="fontcontrol">Font Control Functions</h2>

<p>These functions are declared in the header file <b>ppmdfont.h</b>.

<h3><b>ppmd_read_font</b></h3>

<p>This function associates a Ppmdfont file, which you identify by
naming the Ppmdfont file, with a handle that you can use to identify
the font to other functions.  Technically, this function reads the
font into memory.

<h3><b>ppmd_free_font</b></h3>

<p>This function releases the handle that you get from
<b>ppmd_read_font</b>.  It frees resources associated with it; you
can't use the handle after this.

<h3><b>ppmd_get_font</b></h3>

<p>This function returns the handle of the currently selected font.

<h3><b>ppmd_set_font</b></h3>

<p>This function sets the currently selected font.  You identify the
font to which to set it with a handle such as you get from
<b>ppmd_read_font</b> or <b>ppmd_get_font</b>.

<HR>
<H2 id="toc">Table Of Contents</H2>

<ul>
  <li><a href="#basicfunctions">Basic Functions</a>
    <ul>
      <li><a href="#ppmd_setlinetype">ppmd_setlinetype</a>
      <li><a href="#ppmd_setlineclip">ppmd_setlineclip</a>
      <li><a href="#ppmd_setline">ppmd_setline</a>
      <li><a href="#ppmd_spline3">ppmd_spline3</a>
      <li><a href="#ppmd_polyspline">ppmd_polyspline</a>
      <li><a href="#ppmd_circle">ppmd_circle</a>
      <li><a href="#ppmd_filledrectangle">ppmd_filledrectangle</a>
      <li><a href="#ppmd_fill">ppmd_fill</a>
      <li><a href="#ppmd_text">ppmd_text</a>
      <li><a href="#ppmd_text_box">ppmd_text_box</a>
      </ul>
  <li><a href="#drawprocs">Drawprocs</a>
    <ul>
      <li><a href="#ppmd_point_drawproc">ppmd_point_drawproc</a>
      <li><a href="#ppmd_fill_drawproc">ppmd_fill_drawproc</a>
      </ul>
  <li><a href="#pathfill">Path Filling Function</a>
    <ul>
      <li><a href="#ppmd_fill_path">ppmd_fill_path</a>
      <li><a href="#ppmd_makeLineLeg">ppmd_makeLineLeg</a>
      </ul>
  <li><a href="#pathbuilder">Path Builder</a>
    <ul>
      <li><a href="#ppmd_pathbuilder_create">ppmd_pathbuilder_create</a>
      <li><a href="#ppmd_pathbuilder_destroy">ppmd_pathbuilder_destroy</a>
      <li><a href="#ppmd_pathbuilder_setLegArray">ppmd_pathbuilder_setLegArray</a>
      <li><a href="#ppmd_pathbuilder_preallocLegArray">ppmd_pathbuilder_preallocLegArray</a>
      <li><a href="#ppmd_pathbuilder_setBegPoint">ppmd_pathbuilder_setBegPoint</a>
      <li><a href="#ppmd_pathbuilder_addLineLeg">ppmd_pathbuilder_addLineLeg</a>
      <li><a href="#ppmd_pathbuilder_pathP">ppmd_pathbuilder_pathP</a>
      </ul>
  <li><a href="#fonts">Fonts</a>
  <li><a href="#fontfileformat">Font File Format</a>
  <li><a href="#fontcontrol">Font Control Functions</a>
  </ul>



</BODY>
</HTML>