File: mi_api.c

package info (click to toggle)
plotutils 2.4.1-15
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 11,072 kB
  • ctags: 6,952
  • sloc: ansic: 76,305; cpp: 12,402; sh: 8,475; yacc: 2,604; makefile: 894; lex: 144
file content (272 lines) | stat: -rw-r--r-- 7,571 bytes parent folder | download | duplicates (4)
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
/* This file defines the core libxmi API, consisting of:

   1. miDrawPoints, miDrawLines, miFillPolygon.
   2. miDrawRectangles, miFillRectangles.
   3. miDrawArcs, miFillArcs.  Also the reentrant miDrawArcs_r.

Each of these is a wrapper around an internal function that takes as first
argument a (miPaintedSet *).  A miPaintedSet struct is a structure that is
used by Joel McCormack's span-merging module to implement the
`touch-each-pixel-once' rule.  See mi_spans.c and mi_spans.h. */

#include "sys-defines.h"
#include "extern.h"

#include "xmi.h"
#include "mi_spans.h"
#include "mi_gc.h"
#include "mi_api.h"

#define MI_SETUP_PAINTED_SET(paintedSet, pGC) \
{\
}

#define MI_TEAR_DOWN_PAINTED_SET(paintedSet) \
{\
  miUniquifyPaintedSet (paintedSet); \
}

void
#ifdef _HAVE_PROTOS
miDrawPoints (miPaintedSet *paintedSet, const miGC *pGC, miCoordMode mode, int npt, const miPoint *pPts)
#else
miDrawPoints (paintedSet, pGC, mode, npt, pPts)
     miPaintedSet *paintedSet;
     const miGC *pGC;		/* unused */
     miCoordMode mode;		/* mode = Origin or Previous */
     int npt;
     const miPoint *pPts;
#endif
{
  MI_SETUP_PAINTED_SET(paintedSet, pGC)
  miDrawPoints_internal (paintedSet, pGC, mode, npt, pPts);
  MI_TEAR_DOWN_PAINTED_SET(paintedSet)
}

void
#ifdef _HAVE_PROTOS
miDrawLines (miPaintedSet *paintedSet, const miGC *pGC, miCoordMode mode, int npt, const miPoint *pPts)
#else
miDrawLines (paintedSet, pGC, mode, npt, pPts)
     miPaintedSet *paintedSet;
     const miGC *pGC;
     miCoordMode mode;
     int npt;
     const miPoint *pPts;
#endif
{
  MI_SETUP_PAINTED_SET(paintedSet, pGC)
  miDrawLines_internal (paintedSet, pGC, mode, npt, pPts);
  MI_TEAR_DOWN_PAINTED_SET(paintedSet)
}

void
#ifdef _HAVE_PROTOS
miFillPolygon (miPaintedSet *paintedSet, const miGC *pGC, miPolygonShape shape, miCoordMode mode, int count, const miPoint *pPts)
#else
miFillPolygon (paintedSet, pGC, shape, mode, count, pPts)
     miPaintedSet *paintedSet;
     const miGC *pGC;
     miPolygonShape shape;
     miCoordMode mode;
     int count;
     const miPoint *pPts;
#endif
{
  MI_SETUP_PAINTED_SET(paintedSet, pGC)
  miFillPolygon_internal (paintedSet, pGC, shape, mode, count, pPts);
  MI_TEAR_DOWN_PAINTED_SET(paintedSet)
}

void
#ifdef _HAVE_PROTOS
miDrawRectangles (miPaintedSet *paintedSet, const miGC *pGC, int nrects, const miRectangle *prectInit)
#else
miDrawRectangles (paintedSet, pGC, nrects, prectInit)
     miPaintedSet *paintedSet;
     const miGC *pGC;
     int nrects; 
     const miRectangle *prectInit;
#endif
{
  MI_SETUP_PAINTED_SET(paintedSet, pGC);
  miDrawRectangles_internal (paintedSet, pGC, nrects, prectInit);
  MI_TEAR_DOWN_PAINTED_SET(paintedSet)
}

void
#ifdef _HAVE_PROTOS
miFillRectangles (miPaintedSet *paintedSet, const miGC *pGC, int nrectFill, const miRectangle *prectInit)
#else
miFillRectangles (paintedSet, pGC, nrectFill, prectInit)
     miPaintedSet *paintedSet;
     const miGC *pGC;		/* unused */
     int nrectFill; 
     const miRectangle *prectInit;
#endif
{
  MI_SETUP_PAINTED_SET(paintedSet, pGC);
  miFillRectangles_internal (paintedSet, pGC, nrectFill, prectInit);
  MI_TEAR_DOWN_PAINTED_SET(paintedSet)
}

#ifndef NO_NONREENTRANT_POLYARC_SUPPORT
void
#ifdef _HAVE_PROTOS
miDrawArcs (miPaintedSet *paintedSet, const miGC *pGC, int narcs, const miArc *parcs)
#else
miDrawArcs (paintedSet, pGC, narcs, parcs)
     miPaintedSet *paintedSet;
     const miGC *pGC;
     int narcs;
     const miArc *parcs;
#endif
{
  MI_SETUP_PAINTED_SET(paintedSet, pGC)
  miDrawArcs_internal (paintedSet, pGC, narcs, parcs);
  MI_TEAR_DOWN_PAINTED_SET(paintedSet)
}
#endif /* not NO_NONREENTRANT_POLYARC_SUPPORT */

void
#ifdef _HAVE_PROTOS
miFillArcs (miPaintedSet *paintedSet, const miGC *pGC, int narcs, const miArc *parcs)
#else
miFillArcs (paintedSet, pGC, narcs, parcs)
     miPaintedSet *paintedSet;
     const miGC *pGC;
     int narcs;
     const miArc *parcs;
#endif
{
  MI_SETUP_PAINTED_SET(paintedSet, pGC)
  miFillArcs_internal (paintedSet, pGC, narcs, parcs);
  MI_TEAR_DOWN_PAINTED_SET(paintedSet)
}

void
#ifdef _HAVE_PROTOS
miDrawArcs_r (miPaintedSet *paintedSet, const miGC *pGC, int narcs, const miArc *parcs, miEllipseCache *ellipseCache)
#else
miDrawArcs_r (paintedSet, pGC, narcs, parcs, ellipseCache)
     miPaintedSet *paintedSet;
     const miGC *pGC;
     int narcs;
     const miArc *parcs;
     miEllipseCache *ellipseCache; /* pointer to ellipse data cache */
#endif
{
  MI_SETUP_PAINTED_SET(paintedSet, pGC)
  miDrawArcs_r_internal (paintedSet, pGC, narcs, parcs, ellipseCache);
  MI_TEAR_DOWN_PAINTED_SET(paintedSet)
}

/**********************************************************************/
/* Further wrappers that should really be moved to other file(s). */
/**********************************************************************/

void
#ifdef _HAVE_PROTOS
miDrawArcs_r_internal (miPaintedSet *paintedSet, const miGC *pGC, int narcs, const miArc *parcs, miEllipseCache *ellipseCache)
#else
miDrawArcs_r_internal (paintedSet, pGC, narcs, parcs, ellipseCache)
     miPaintedSet *paintedSet;
     const miGC *pGC;
     int narcs;
     const miArc *parcs;
     miEllipseCache *ellipseCache; /* pointer to ellipse data cache */
#endif
{
  if (pGC->lineWidth == 0)
    /* use Bresenham algorithm */
    miZeroPolyArc_r (paintedSet, pGC, narcs, parcs, ellipseCache);
  else
    miPolyArc_r (paintedSet, pGC, narcs, parcs, ellipseCache);
}

#ifndef NO_NONREENTRANT_POLYARC_SUPPORT
void
#ifdef _HAVE_PROTOS
miDrawArcs_internal (miPaintedSet *paintedSet, const miGC *pGC, int narcs, const miArc *parcs)
#else
miDrawArcs_internal (paintedSet, pGC, narcs, parcs)
     miPaintedSet *paintedSet;
     const miGC *pGC;
     int narcs;
     const miArc *parcs;
#endif
{
  if (pGC->lineWidth == 0)
    /* use Bresenham algorithm */
    miZeroPolyArc (paintedSet, pGC, narcs, parcs);
  else
    miPolyArc (paintedSet, pGC, narcs, parcs);
}
#endif /* not NO_NONREENTRANT_POLYARC_SUPPORT */

void
#ifdef _HAVE_PROTOS
miDrawLines_internal (miPaintedSet *paintedSet, const miGC *pGC, miCoordMode mode, int npt, const miPoint *pPts)
#else
miDrawLines_internal (paintedSet, pGC, mode, npt, pPts)
     miPaintedSet *paintedSet;
     const miGC *pGC;
     miCoordMode mode;
     int npt;
     const miPoint *pPts;
#endif
{
  if (pGC->lineWidth == 0)
    {
    /* use Bresenham algorithm */
      if (pGC->lineStyle == (int)MI_LINE_SOLID)
	miZeroLine (paintedSet, pGC, mode, npt, pPts);
      else
	miZeroDash (paintedSet, pGC, mode, npt, pPts);
    }
  else
    {
      if (pGC->lineStyle == (int)MI_LINE_SOLID)
	miWideLine (paintedSet, pGC, mode, npt, pPts);
      else
	miWideDash (paintedSet, pGC, mode, npt, pPts);
    }
}

void
#ifdef _HAVE_PROTOS
miDrawRectangles_internal (miPaintedSet *paintedSet, const miGC *pGC, int nrects, const miRectangle *prectInit)
#else
miDrawRectangles_internal (paintedSet, pGC, nrects, prectInit)
     miPaintedSet *paintedSet;
     const miGC *pGC;
     int nrects; 
     const miRectangle *prectInit;
#endif
{
  const miRectangle *pR = prectInit;
  miPoint rect[5];
  int i;

  for (i = 0; i < nrects; i++)
    {
      rect[0].x = pR->x;
      rect[0].y = pR->y;
      
      rect[1].x = pR->x + (int) pR->width;
      rect[1].y = rect[0].y;
      
      rect[2].x = rect[1].x;
      rect[2].y = pR->y + (int) pR->height;
      
      rect[3].x = rect[0].x;
      rect[3].y = rect[2].y;
      
      /* close the polyline */
      rect[4].x = rect[0].x;
      rect[4].y = rect[0].y;
      
      miDrawLines_internal (paintedSet, pGC, MI_COORD_MODE_ORIGIN, 5, rect);
      pR++;
    }
}