Blob Blame History Raw
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML><HEAD><TITLE>Ppmtoarbtxt User Manual</TITLE></HEAD>
<BODY>
<H1>ppmtoarbtxt</H1>
<BR>
Updated: 26 November 2014
<BR>
<A HREF="#index">Table Of Contents</A>

<H2>NAME</H2>
ppmtoarbtxt - generate image in arbitrary text format from PPM image

<H2 id="synopsis">SYNOPSIS</H2>

<B>ppmtoarbtxt</B>
<I>bodytmpl</I>
[<B>-hd</B> <I>headtmpl</I>]
[<B>-tl</B> <I>tailtmpl</I>]
[<I>ppmfile</I>]

<H2 id="description">DESCRIPTION</H2>

<p>This program is part of <a href="index.html">Netpbm</a>.

<p><b>ppmtoarbtxt</b> generates simple text-based graphics formats based on
format descriptions given as input.  A text-based graphics format is one in
which an image is represented by text (like PNM plain format, but unlike
PNM raw format).

<b>ppmtoarbtxt</b> reads a PPM image as input.  For each pixel in the
image, <b>ppmtoarbtxt</b> writes the contents of the template file
<I>bodytmpl</I>, with certain substitutions based on the value of the
pixel, to Standard Output.

<p>You may also supply a head template file, in which case <b>ppmtoarbtxt</b>
generates text from the template file, based on the image dimensions, and
includes it in the output before anything else.

<p>Likewise, you may supply a tail template file to cause text to be placed
at the end of the output.


<h3 id="templatefiles">Template Files</h3>

<p>The text that <b>ppmtoarbtxt</b> generates from a template file is the
literal text of the template file, except with substitution specifier replaced
with something else.  The program recognizes a substitution specifier as
text of the form <b>#(</b>...<b>)</b>.

<P><b>ppmtoarbtxt</b> treats white space in the template files the same as any
other characters, placing it in the output, with one exception: If the
template file ends with a newline character, <b>ppmtoarbtxt</b> ignores it --
it does not include it in the output.

<p>Many substitution specifiers use format strings (another form of template)
to specify the substitution.  You should make these format strings as minimal
as possible, placing literal text outside the substitution specifier instead
of inside the format string.  For example,

<p>Wrong: <kbd>#(flum %%%2.2f 0 1) </kbd>

<p>Right: <kbd>%#(flum %2.2f 0 1) </kbd>

<p>The valid substitution specifiers are as follows.  Text that has the
form of a substitution specifier but is not actually valid (e.g.
<b>#(random junk)</b> usually just specifies its literal value, but if it is
close enough to something valid, <b>ppmtoarbtxt</b> assumes you made a mistake
and fails.

<p>Useful in a body template, to do substitutions based on a particular pixel:

<DL COMPACT>
<DT><B>#(ired</B><I> format blackref whiteref</I><B>)</B>

<DD>generates an integer in the range <I>blackref</I> to
<I>whiteref</I> in a format specified by <I>format</I> representing the red
intensity of the pixel.  A red intensity of 0 becomes <I>blackref</I>; a red
intensity of maxval becomes <I>whiteref</I>, with the rest linearly
interpolated in between.

<p><i>format</i> is a printf-like format specifier like "%d".
<b>ppmtoarbtxt</b> uses as the entire format string to a <b>fprintf</b> POSIX
library call whose only other argument is the red itensity as an integer data
type.  <b>ppmtoarbtxt</b> does not necessarily verify that your format string
makes sense; there are values you could specify that could even crash the
program.  To avoid unexpected behavior, keep format strings simple and
hardcoded, and never include a per cent sign or newline.

<p><B>#(ired)</B> is equivalent to <B>#(ired %d 0 255)</B>.

<DT><B>#(igreen</B><I> format blackref whiteref</I><B>)</B>

<DD>Same as <B>#(ired...</B>, but for green.

<DT><B>#(iblue</B><I> format blackref whiteref</I><B>)</B>

<DD>Same as <B>#(ired...</B>, but for blue.

<DT><B>#(ilum</B><I> format blackref whiteref</I><B>)</B>

<DD>Same as <B>#(ired...</B>, but representing the luminance value
(0.299*red + 0.587*green + 0.114*blue) of the pixel.

<DT><B>#(fred</B><I> format blackref whiteref</I><B>)</B>

<DD>Same as <B>#(ired...</B>, but generates a floating point number instead
of an integer.

<p>In this case, the second argument to the <b>fprintf</b> that uses 
<i>format</i> has a double precision floating point data type.

<p><B>#(fred)</B> is equivalent to <B>#(fred %f 0.0 1.0)</B>.

<DT><B>#(fgreen </B><I>format blackref whiteref</I><B>)</B>

<DD>Same as <B>#(fred...</B>, but for green.

<DT><B>#(fblue </B><I>format blackref whiteref</I><B>)</B>

<DD>Same as <B>#(fred...</B>, but for blue.

<DT><B>#(flum </B><I>format blackref whiteref</I><B>)</B>

<DD>Same as <B>#(fred...</B>, but representing the luminance value
(0.299*red + 0.587*green + 0.114*blue) of the pixel.

<DT><B>#(posx </B><i>format</i><b>)</b>

<DD>Generates the horizontal position of the pixel, in pixels from the left
edge of the image.

<p>The second argument to the <b>fprintf</b> that uses <i>format</i> has an
unsigned integer data type.

<p><i>format</i> defaults to <b>%u</b>

<DT><B>#(posy </B><i>format</i><b>)</b>

<DD>Same as <b>#(width...</b>, but for the vertical position.

</DL>

<p>If you use any of the above substitution specifiers in a head or tail
template, the result is undefined.

<p>Useful in a head or tail template, to do substitutions based on whole-image
attributes:

<DL COMPACT>
<DT><B>#(width </B><i>format</i><b>)</b>

<DD>Generates the width in pixels of the image.

<p>The second argument to the <b>fprintf</b> that uses <i>format</i>
has an unsigned integer data type.

<p><i>format</i> defaults to <b>%u</b>

<DT><B>#(height </B><i>format</i><b>)</b>

<DD>Same as <b>#(width...</b>, but for the height of the image.

</dl>


<H2 id="options">OPTIONS</H2>

<DL COMPACT>
<DT><B>-hd</B> <I>headtmpl</I>

<DD>This option specifies a head template (<i>headtmpl</i> is the name of the
head template file); it causes <b>ppmtoarbtxt</b> to place the contents of the
file named <I>headtmpl</I> at the beginning of the output

<DT><B>-tl</B> <I>tailtmpl</I>

<DD>This option specifies a tail template; it is analogous to <b>-hd</b>.

</DL>

<H2 id="examples">EXAMPLES</H2>

<h3>gray inversion</H3>

<P>Here we generate a PGM plain-format image with gray inversion
(like <b>ppmtopgm | pnminvert</b>).

<p>Contents of our head template file:

<pre>
P2
#(width) #(height)
255
</pre>

<P>Contents of our body skeleton file:

<pre>
#(ilum %d 255 0)
</pre>

<h3>povray file</h3>

<P>Here we generate a povray file where each pixel is represented by a
sphere at location (x,y,z) = (posx,height-posy,luminance).  The color
of the sphere is the color of the pixel.

<p>Contents of our head skeleton:

<pre>
#include "colors.inc"
#include "textures.inc"
camera {
   location  &lt;#(width) * 0.6, #(height) * 0.7, 80&gt;
   look_at   &lt;#(width) * 0.5, #(height) * 0.5, 0&gt;
}

light_source { &lt;#(width) * 0.5, #(height) * 0.5, 25&gt; color White
}
</pre>

<p>Contents of our body skeleton:

<pre>
sphere { &lt;#(posx),#(height)-#(posy),#(ilum %d 0 10)&gt;, 0.5
  texture {
    pigment {
      color rgb &lt;#(fred),#(fgreen),#(fblue)&gt;
    }
    finish {
      phong 1
    }
  }
}
</pre>

<H2 id="seealso">SEE ALSO</H2>

<A href="pnmtoplainpnm.html">pnmtoplainpnm</A>
<A href="pamtable.html">pamtable</A>
<A href="ppm.html">ppm</A>

<H2 id="history">HISTORY</H2>

<P><B>ppmtoarbtxt</b> was added to Netpbm in Release 10.14 (March 2003).
It existed under the name <b>ppmtotxt</b> since 1995.

<H2 id="author">AUTHOR</H2>

Copyright (C) 1995 by Peter Kirchgessner

<HR>
<H2 id="index">Table Of Contents</H2>
<UL>
<LI><A HREF="#synopsis">SYNOPSIS</A>
<LI><A HREF="#description">DESCRIPTION</A>
<ul>
  <li><A HREF="#templatefiles">Template Files</A>
  </ul>
<LI><A HREF="#options">OPTIONS</A>
<LI><A HREF="#examples">EXAMPLES</A>
<LI><A HREF="#seealso">SEE ALSO</A>
<LI><A HREF="#history">HISTORY</A>
<LI><A HREF="#author">AUTHOR</A>
</UL>
</BODY>
</HTML>