summary refs log tree commit diff
path: root/libnetpbm_draw.html
blob: 6e9c3690e86f8e1b541c3e7252a79110d1449070 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.3//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: April 2018
<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.

<p>Note that the Netpbm program <b>ppmdraw</b> is essentially a command-line
interface to the functions of this library.  You can use that program's source
code as an example, or just invoke that program instead of calling these
functions.  The netpbm program <b>ppmlabel</b> is another good example of
using these functions.


<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_pathbuilder_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_pathbuilder_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_line">ppmd_line</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>