This program is part of Netpbm(1).
ppmtoarbtxt 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).
ppmtoarbtxt reads a PPM image as input. For each pixel in the image, ppmtoarbtxt writes the contents of
the template file bodytmpl, with certain substitutions based on the value of the pixel, to Standard
Output.
You may also supply a head template file, in which case ppmtoarbtxt generates text from the template
file, based on the image dimensions, and includes it in the output before anything else.
Likewise, you may supply a tail template file to cause text to be placed at the end of the output.
TemplateFiles
The text that ppmtoarbtxt 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 #(...).
ppmtoarbtxt 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, ppmtoarbtxt ignores it --
it does not include it in the output.
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,
Wrong: #(flum %%%2.2f 0 1)
Right: %#(flum %2.2f 0 1)
The valid substitution specifiers are as follows. Text that has the form of a substitution specifier but
is not actually valid (e.g. #(randomjunk) usually just specifies its literal value, but if it is close
enough to something valid, ppmtoarbtxt assumes you made a mistake and fails.
Useful in a body template, to do substitutions based on a particular pixel:
#(iredformatblackrefwhiteref)
generates an integer in the range blackref to whiteref in a format specified by format
representing the red intensity of the pixel. A red intensity of 0 becomes blackref; a red
intensity of maxval becomes whiteref, with the rest linearly interpolated in between.
format is a printf-like format specifier like "%d". ppmtoarbtxt uses as the entire format string
to a fprintf POSIX library call whose only other argument is the red itensity as an integer data
type. ppmtoarbtxt 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.
#(ired) is equivalent to #(ired%d0255).
#(igreenformatblackrefwhiteref)
Same as #(ired..., but for green.
#(iblueformatblackrefwhiteref)
Same as #(ired..., but for blue.
#(ilumformatblackrefwhiteref)
Same as #(ired..., but representing the luminance value (0.299*red + 0.587*green + 0.114*blue) of
the pixel.
#(fredformatblackrefwhiteref)
Same as #(ired..., but generates a floating point number instead of an integer.
In this case, the second argument to the fprintf that uses format has a double precision floating
point data type.
#(fred) is equivalent to #(fred%f0.01.0).
#(fgreenformatblackrefwhiteref)
Same as #(fred..., but for green.
#(fblueformatblackrefwhiteref)
Same as #(fred..., but for blue.
#(flumformatblackrefwhiteref)
Same as #(fred..., but representing the luminance value (0.299*red + 0.587*green + 0.114*blue) of
the pixel.
#(posxformat)
Generates the horizontal position of the pixel, in pixels from the left edge of the image.
The second argument to the fprintf that uses format has an unsigned integer data type.
format defaults to %u#(posyformat)
Same as #(width..., but for the vertical position.
If you use any of the above substitution specifiers in a head or tail template, the result is undefined.
Useful in a head or tail template, to do substitutions based on whole-image attributes:
#(widthformat)
Generates the width in pixels of the image.
The second argument to the fprintf that uses format has an unsigned integer data type.
format defaults to %u#(heightformat)
Same as #(width..., but for the height of the image.