xmi.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. /* This is xmi.h, the public header file for the machine-independent libxmi
  2. rasterization library, which is based on source files in the X Window
  3. System distribution. Written by Robert S. Maier.
  4. The eight painting functions in libxmi's core API, namely
  5. the 5 drawing functions:
  6. miDrawPoints, miDrawLines, miDrawRectangles, miDrawArcs, miDrawArcs_r
  7. the 3 filling functions:
  8. miFillPolygon, miFillRectangles, miFillArcs
  9. are declared below. The first argument of each of these is a pointer to
  10. a miPaintedSet. Conceptually, a miPaintedSet is a set of points with
  11. integer coordinates, each of which is painted some color (a miPixel).
  12. The coordinates of the points are unconstrained, i.e., the core painting
  13. functions perform no clipping.
  14. Each of the core painting functions takes as second argument a pointer
  15. to a graphics context: a miGC. A miGC is an opaque type that contains
  16. high-level drawing parameters that determine which points will be added
  17. to the miPaintedSet. (For example, the line width, line style, and dash
  18. pattern, all of which are relevant to the drawing functions, though not
  19. to the filling functions.) It also specifies the colors (miPixels) that
  20. will be used when painting the points. The core painting functions use
  21. the Painter's Algorithm, so that if a point in an miPaintedSet is
  22. painted a second time, the new color will replace the old.
  23. (By default, the painting performed by the core painting functions,
  24. i.e. by both the drawing functions and the filling functions, is
  25. `solid', i.e., non-interpolated. In `solid' painting, the color used is
  26. taken from the pixel array in the miGC. Any miGC contains an array of
  27. pixel colors, of length n>=2. Color #1 is the default color for
  28. painting, and colors 0,2,3,..,n-1 are used only by the drawing
  29. functions, when drawing in a dashed mode. In normal (on/off) dashing,
  30. the colors of the `on' dashes will cycle through 1,2,..,n-1. In
  31. so-called double dashing, the `off' dashes will be drawn too, in color #0.)
  32. After a miPaintedSet is built up by invoking one or more core painting
  33. functions, the next stage of the graphics pipeline is performed by
  34. calling miCopyPaintedSetToCanvas(). This transfers the pixels in the
  35. miPaintedSet onto a canvas structure called a miCanvas, which contains a
  36. bounded, fixed-size drawable. In the transfer, more sophisticated
  37. algorithms than the Painter's Algorithm may be used. Besides the
  38. drawable, a miCanvas may contain additional members, such as a stipple
  39. bitmap, a texture pixmap, and binary and ternary pixel-merging
  40. functions. These will affect how the pixels from the miPaintedSet are
  41. combined with the ones that already exist on the drawable. */
  42. #ifndef _XMI_H_
  43. #define _XMI_H_ 1
  44. /***********************************************************************/
  45. /* Version of GNU libxmi which this header file accompanies. This
  46. information is included beginning with version 1.2.
  47. The MI_LIBXMI_VER_STRING macro is compiled into the library, as
  48. `mi_libxmi_ver'. The MI_LIBXMI_VER macro is not compiled into it. Both
  49. are available to applications that include this header file. */
  50. #define MI_LIBXMI_VER_STRING "1.3"
  51. #define MI_LIBXMI_VER 130
  52. extern const char mi_libxmi_ver[8]; /* need room for 99.99aa */
  53. /**********************************************************************/
  54. /* support C++ */
  55. #ifdef ___BEGIN_DECLS
  56. #undef ___BEGIN_DECLS
  57. #endif
  58. #ifdef ___END_DECLS
  59. #undef ___END_DECLS
  60. #endif
  61. #ifdef __cplusplus
  62. # define ___BEGIN_DECLS extern "C" {
  63. # define ___END_DECLS }
  64. #else
  65. # define ___BEGIN_DECLS /* empty */
  66. # define ___END_DECLS /* empty */
  67. #endif
  68. /**********************************************************************/
  69. /* Structure that defines a point with integer coordinates. */
  70. typedef struct
  71. {
  72. int x, y; /* integer coordinates, y goes downward */
  73. } miPoint;
  74. /* Definition of miPixel, the pixel value datatype. By default, a miPixel
  75. is an unsigned int. The libxmi installer may alter the definition by
  76. defining the symbol MI_PIXEL_TYPE at installation time. The macro
  77. MI_SAME_PIXEL(), which tests for equality, may need to be redefined too
  78. (e.g., if MI_PIXEL_TYPE is a struct or a union). */
  79. #ifdef MI_PIXEL_TYPE
  80. typedef MI_PIXEL_TYPE miPixel;
  81. #else
  82. typedef unsigned int miPixel;
  83. #endif
  84. #ifndef MI_SAME_PIXEL
  85. #define MI_SAME_PIXEL(pixel1,pixel2) \
  86. ((pixel1) == (pixel2))
  87. #endif
  88. /**********************************************************************/
  89. /* A miPaintedSet is an opaque structure that contains a set of painted
  90. points, i.e., a set of points partitioned according to the pixel color
  91. used for painting. When any public drawing function is invoked, a
  92. pointer to a miPaintedSet is passed as its first argument. */
  93. typedef struct lib_miPaintedSet miPaintedSet;
  94. /* Constructor and destructor for the miPaintedSet class. */
  95. extern miPaintedSet * miNewPaintedSet (void);
  96. extern void miDeletePaintedSet (miPaintedSet *paintedSet);
  97. /* A function that clears any miPaintedSet (i.e. makes it the empty set). */
  98. extern void miClearPaintedSet (miPaintedSet *paintedSet);
  99. /**********************************************************************/
  100. /* A miGC is an opaque structure that contains high-level drawing
  101. parameters. When any public drawing function is invoked, a pointer to a
  102. miGC is passed as its second argument. */
  103. typedef struct lib_miGC miGC;
  104. /* Constructor, destructor, and copy constructor for the miGC class. */
  105. extern miGC * miNewGC (int npixels, const miPixel *pixels); /* npixels >= 2 */
  106. extern void miDeleteGC (miGC *pGC);
  107. extern miGC * miCopyGC (const miGC *pGC);
  108. /* Values for an miGC's miGCLineStyle attribute (default=MI_LINE_SOLID). */
  109. enum { MI_LINE_SOLID, MI_LINE_ON_OFF_DASH, MI_LINE_DOUBLE_DASH };
  110. /* Values for an miGC's miGCJoinStyle attribute (default=MI_JOIN_MITER). */
  111. enum { MI_JOIN_MITER, MI_JOIN_ROUND, MI_JOIN_BEVEL, MI_JOIN_TRIANGULAR };
  112. /* Values for an miGC's miGCCapStyle attribute (default=MI_CAP_BUTT).
  113. MI_CAP_NOT_LAST is the same as MI_CAP_BUTT except when drawing
  114. zero-width (Bresenham) polylines; it causes the final pixel not to be
  115. drawn. A polyline drawn in this way is called `continuable'. */
  116. enum { MI_CAP_NOT_LAST, MI_CAP_BUTT, MI_CAP_ROUND, MI_CAP_PROJECTING, MI_CAP_TRIANGULAR };
  117. /* Values for an miGC's miGCFillRule attribute (default=MI_EVEN_ODD_RULE). */
  118. enum { MI_EVEN_ODD_RULE, MI_WINDING_RULE };
  119. /* Values for an miGC's miGCArcMode attribute (default=MI_ARC_PIE_SLICE). */
  120. enum { MI_ARC_CHORD, MI_ARC_PIE_SLICE };
  121. /* Possibilities for the `attribute' argument of miSetGCAttrib. (All the
  122. preceding, plus MI_GC_LINE_WIDTH.) */
  123. typedef enum { MI_GC_FILL_RULE, MI_GC_JOIN_STYLE, MI_GC_CAP_STYLE, MI_GC_LINE_STYLE, MI_GC_ARC_MODE, MI_GC_LINE_WIDTH } miGCAttribute;
  124. /* A function that sets a single integer-valued miGC attribute. `value'
  125. must be one of the preceding enum's, except when
  126. attribute=MI_GC_LINE_WIDTH, in which case value>=0 is required. */
  127. extern void miSetGCAttrib (miGC *pGC, miGCAttribute attribute, int value);
  128. /* A function that sets a list of integer-value miGC attributes. */
  129. extern void miSetGCAttribs (miGC *pGC, int nattributes, const miGCAttribute *attributes, const int *values);
  130. /* Functions that set miGC attributes that are not integer-valued.
  131. Note: currently, `offset' must be nonnegative. */
  132. extern void miSetGCDashes (miGC *pGC, int ndashes, const unsigned int *dashes, int offset);
  133. extern void miSetGCMiterLimit (miGC *pGC, double miter_limit);
  134. extern void miSetGCPixels (miGC *pGC, int npixels, const miPixel *pixels); /* npixels >=2 */
  135. /* Additional functions that set miGC attributes: in particular, functions
  136. that set the paint style that will be used. Only in the case of `solid'
  137. painting (the default) is the above pixel array relevant. */
  138. extern void miSetGCPaintSolid (void);
  139. extern void miSetGCPaintInterpParallel (miPoint pts[2], miPixel pixels[2]);
  140. extern void miSetGCPaintInterpTriangular (miPoint pts[3], miPixel pixels[3]);
  141. extern void miSetGCPaintInterpElliptical (void);
  142. /*********** DECLARATIONS OF PUBLIC DRAWING FUNCTIONS ******************/
  143. /* The semantics of these drawing functions is similar to that of the
  144. corresponding X11 drawing functions. Wide polylines (polylines with
  145. line width >= 1) are treated as polygons to be rendered by filling.
  146. Zero-width polylines are not invisible: instead, they are single-pixel
  147. polylines, specially rendered by the Bresenham midpoint line algorithm.
  148. Also, adjoining polygons (those with an edge in common) are drawn
  149. without gaps. To arrange this, the `right' and `bottom' edges of any
  150. polygon are not drawn when the polygon is filled. The filling of
  151. rectangles is similar.
  152. Wide arcs and polyarcs are drawn with a circular brush, of diameter
  153. equal to the line width. Every brushed pixel is painted. Zero-width
  154. arcs and polyarcs are not invisible: instead, they are single-pixel
  155. arcs, specially rendered by the Bresenham `midpoint arc' algorithm. */
  156. /* For consistency, the first three arguments of each drawing function are
  157. (1) a pointer to a miPaintedSet, and (2) a pointer to an miGC. */
  158. /* 1. Drawing functions for points, polylines, and polygons.
  159. The final three arguments of each are a `coordinate mode' (see below), a
  160. specified number of points, and an array that contains the points.
  161. miDrawPoints draws a cloud of points, miDrawLines draws a polyline, and
  162. miFillPolygon draws a filled polygon. */
  163. /* Possible values for the `coordinate mode' argument (specifying whether
  164. the points in the points array, after the first point, are given in
  165. absolute or relative coordinates). */
  166. typedef enum { MI_COORD_MODE_ORIGIN, MI_COORD_MODE_PREVIOUS } miCoordMode;
  167. /* Possible values for the `shape' argument of miFillPolygon(). Two
  168. possibilities: (1) general (i.e., not necessarily convex, with
  169. self-intersections allowed), or (2) convex and not self-intersecting.
  170. Latter case can be drawn more rapidly. */
  171. typedef enum { MI_SHAPE_GENERAL, MI_SHAPE_CONVEX } miPolygonShape;
  172. ___BEGIN_DECLS
  173. extern void miDrawPoints (miPaintedSet *paintedSet, const miGC *pGC, miCoordMode mode, int npts, const miPoint *pPts);
  174. extern void miDrawLines (miPaintedSet *paintedSet, const miGC *pGC, miCoordMode mode, int npts, const miPoint *pPts);
  175. extern void miFillPolygon (miPaintedSet *paintedSet, const miGC *pGC, miPolygonShape shape, miCoordMode mode, int npts, const miPoint *pPts);
  176. /* 2. Rectangle-related drawing functions.
  177. These draw and fill a specified number of rectangles, supplied as an
  178. array of miRectangles. */
  179. /* Structure that defines a rectangle. Upper left corner is [x,y] and
  180. lower right corner is [x+width,y+height]. */
  181. typedef struct
  182. {
  183. int x, y; /* upper left corner */
  184. unsigned int width, height; /* width >= 1 and height >= 1 */
  185. } miRectangle;
  186. extern void miDrawRectangles (miPaintedSet *paintedSet, const miGC *pGC, int nrects, const miRectangle *pRects);
  187. extern void miFillRectangles (miPaintedSet *paintedSet, const miGC *pGC, int nrects, const miRectangle *pRects);
  188. /* 3. Arc-related drawing functions.
  189. Each of these takes as argument a multi-arc, i.e. an array of elliptic
  190. arcs. Here, an `elliptic arc' is a piece of an ellipse whose axes are
  191. aligned with the coordinate axes. The arcs are not required to be
  192. contiguous.
  193. miDrawArcs draws a multi-arc. If the arcs are contiguous, they will be
  194. joined as specified in the miGC. Note that miDrawArcs is not reentrant,
  195. i.e., not thread-safe (for a thread-safe variant, see below).
  196. miFillArcs draws a sequence of filled arcs. They are filled either as
  197. chords or as pie slices, as specified by the graphics context. */
  198. /* Structure that defines an `arc' (i.e. a segment of an ellipse whose
  199. principal axes are aligned with the coordinate axes). The upper left
  200. corner of the bounding box is [x,y], and the lower right corner is
  201. [x+width,y+height]. By convention, angle1 and angle2 are the starting
  202. polar angle and angle range that the arc would have if it were scaled
  203. into a circular arc. */
  204. typedef struct
  205. {
  206. int x, y; /* upper left corner of ellipse's bounding box */
  207. unsigned int width, height; /* dimensions; width, height >= 1 */
  208. int angle1, angle2; /* starting angle and angle range, in 1/64 degrees */
  209. } miArc;
  210. extern void miDrawArcs (miPaintedSet *paintedSet, const miGC *pGC, int narcs, const miArc *parcs);
  211. extern void miFillArcs (miPaintedSet *paintedSet, const miGC *pGC, int narcs, const miArc *parcs);
  212. /* 4. A reentrant (thread-safe) arc-drawing function. A special function
  213. is necessary because the normal arc-drawing function miDrawArcs
  214. maintains an internal, fixed-size cache of rasterized ellipses, one for
  215. each arc that is drawn. The presence of this persistent data (internal
  216. to libxmi) prevents miDrawArcs from being reentrant. miDrawArcs_r is a
  217. reentrant substitute.
  218. The caller of miDrawArcs_r must supply a pointer to an miEllipseCache
  219. object as the final argument. A pointer to such an object, which is
  220. opaque, is returned by miNewEllipseCache. After zero or more calls to
  221. miDrawArcs_r, the object may be deleted by calling
  222. miDeleteEllipseCache. */
  223. typedef struct lib_miEllipseCache miEllipseCache;
  224. extern miEllipseCache * miNewEllipseCache (void);
  225. extern void miDeleteEllipseCache (miEllipseCache *ellipseCache);
  226. extern void miDrawArcs_r (miPaintedSet *paintedSet, const miGC *pGC, int narcs, const miArc *parcs, miEllipseCache *ellipseCache);
  227. ___END_DECLS
  228. /***************** LIBXMI's Canvas-Painting ***********************/
  229. /* A miCanvas encapsulates (i) a drawable, which is a miCanvasPixmap, and
  230. (ii) parameters that specify how pixels should be painted. By default,
  231. a miCanvasPixmap is a miPixmap, i.e., basically a 2-D array of miPixels
  232. (an array of pointers to rows of miPixels). That is a low-level
  233. implementation decision that may easily be changed by the libxmi
  234. installer. */
  235. /* Binary pixel-merging function type. Such a function maps a source pixel
  236. and a destination pixel to a new, merged pixel. */
  237. typedef miPixel (*miPixelMerge2) (miPixel source, miPixel destination);
  238. /* Ternary pixel-merging function type. Such a function maps a texture
  239. pixel, a source pixel, and a destination pixel, to a new, merged
  240. pixel. */
  241. typedef miPixel (*miPixelMerge3) (miPixel texture, miPixel source, miPixel destination);
  242. /* Definitions of miBitmap and miPixmap. By convention, (0,0) is upper
  243. left hand corner. */
  244. typedef struct
  245. {
  246. int **bitmap; /* each element is 0 or 1 */
  247. unsigned int width;
  248. unsigned int height;
  249. }
  250. miBitmap;
  251. typedef struct
  252. {
  253. miPixel **pixmap; /* each element is a miPixel */
  254. unsigned int width;
  255. unsigned int height;
  256. }
  257. miPixmap;
  258. /* Definition of miCanvasPixmap, the datatype of the drawable encapsulated
  259. within a miCanvas. By default, a miCanvasPixmap is a miPixmap. The
  260. libxmi installer may alter the definition by defining the symbol
  261. MI_CANVAS_DRAWABLE_TYPE at installation time. */
  262. #ifdef MI_CANVAS_DRAWABLE_TYPE
  263. typedef MI_CANVAS_DRAWABLE_TYPE miCanvasPixmap;
  264. #else
  265. typedef miPixmap miCanvasPixmap;
  266. #endif
  267. /* Definition of the miCanvas structure. */
  268. typedef struct
  269. {
  270. /* Drawable. */
  271. miCanvasPixmap *drawable;
  272. /* A stipple. (Default is NULL, which means no stipping. If non-NULL,
  273. the canvas will be tiled with the stipple, and painting will be
  274. allowed to take place only at points where the stipple is nonzero.) */
  275. miBitmap *stipple;
  276. miPoint stippleOrigin; /* upper left corner of mask is mapped to this */
  277. /* A texture. (Default is NULL, which means no texturing. If non-NULL,
  278. the canvas will be tiled with the texture, and painting of a pixel at
  279. any point will be affected by the value of the texture pixel there.) */
  280. miPixmap *texture;
  281. miPoint textureOrigin; /* upper left corner of texture is mapped to this */
  282. /* User-specified binary pixel-merging function, if any. (Default is
  283. NULL, which means the Painter's Algorithm is used: source pixel will
  284. replace destination pixel.) */
  285. miPixelMerge2 pixelMerge2;
  286. /* User-specified ternary pixel-merging function, if any. Used when a
  287. texture has been specified. (Default is NULL, which means the
  288. Painter's Algorithm is used: texture pixel will replace destination
  289. pixel, and source pixel will be ignored.) */
  290. miPixelMerge3 pixelMerge3;
  291. } miCanvas;
  292. /* The public function that merges pixels from a miPaintedSet onto a
  293. miCanvas. `origin' is the point on the miCanvas to which the point
  294. (0,0) in the miPaintedSet is mapped. (It could be called `offset'.) */
  295. extern void miCopyPaintedSetToCanvas (const miPaintedSet *paintedSet, miCanvas *canvas, miPoint origin);
  296. /* If MI_CANVAS_DRAWABLE_TYPE is defined by the libxmi installer (see
  297. above), then the accessor macros MI_GET_CANVAS_DRAWABLE_PIXEL() and
  298. MI_SET_CANVAS_DRAWABLE_PIXEL() will also need to be defined. The
  299. default accessor macros simply access the 2-D miPixel array within a
  300. miPixmap. MI_GET_CANVAS_DRAWABLE_BOUNDS() should be defined too. */
  301. #ifndef MI_GET_CANVAS_DRAWABLE_PIXEL
  302. #define MI_GET_CANVAS_DRAWABLE_PIXEL(pCanvas, x, y, pixel) \
  303. (pixel) = (pCanvas)->drawable->pixmap[(y)][(x)];
  304. #endif
  305. #ifndef MI_SET_CANVAS_DRAWABLE_PIXEL
  306. #define MI_SET_CANVAS_DRAWABLE_PIXEL(pCanvas, x, y, pixel) \
  307. (pCanvas)->drawable->pixmap[(y)][(x)] = (pixel);
  308. #endif
  309. #ifndef MI_GET_CANVAS_DRAWABLE_BOUNDS
  310. #define MI_GET_CANVAS_DRAWABLE_BOUNDS(pCanvas, xleft, ytop, xright, ybottom) \
  311. { (xleft) = 0; (ytop) = 0; \
  312. (xright) = (pCanvas)->drawable->width - 1; \
  313. (ybottom) = (pCanvas)->drawable->height - 1; \
  314. }
  315. #endif
  316. /* Functions that set data elements of a miCanvas. */
  317. extern void miSetCanvasStipple (miCanvas *pCanvas, const miBitmap *pStipple, miPoint stippleOrigin);
  318. extern void miSetCanvasTexture (miCanvas *pCanvas, const miPixmap *pTexture, miPoint textureOrigin);
  319. /* Functions that set the binary and ternary pixel-merging functions to be
  320. used when pixels from a miPaintedSet are applied to a miCanvas. The
  321. defaults are NULL; for the meaning of NULL, see above. */
  322. extern void miSetPixelMerge2 (miCanvas *pCanvas, miPixelMerge2 pixelMerge2);
  323. extern void miSetPixelMerge3 (miCanvas *pCanvas, miPixelMerge3 pixelMerge3);
  324. /* The libxmi installer may request that the default algorithm used when
  325. applying pixels to a miPaintCanvas be something other than the Painter's
  326. Algorithm, by defining MI_DEFAULT_MERGE2_PIXEL at installation time. */
  327. #ifndef MI_DEFAULT_MERGE2_PIXEL
  328. /* use painter's algorithm */
  329. #define MI_DEFAULT_MERGE2_PIXEL(new, source, dest) { (new) = (source); }
  330. #endif
  331. /* Likewise, the libxmi installer may request that the default algorithm
  332. used when applying pixels to a miPaintCanvas, when a texture pixel is
  333. available, be something other than the `replace canvas pixel by texture
  334. pixel' algorithm. */
  335. #ifndef MI_DEFAULT_MERGE3_PIXEL
  336. /* use painter's algorithm */
  337. #define MI_DEFAULT_MERGE3_PIXEL(new, texture, source, dest) { (new) = (texture); }
  338. #endif
  339. #ifndef MI_CANVAS_DRAWABLE_TYPE
  340. /* Constructor, destructor, and copy constructor for the miCanvas class.
  341. These are declared (and defined) only if the libxmi installer doesn't
  342. redefine the type of the drawable encapsulated within a miCanvas. */
  343. extern miCanvas * miNewCanvas (unsigned int width, unsigned int height, miPixel initPixel);
  344. extern void miDeleteCanvas (miCanvas *pCanvas);
  345. extern miCanvas * miCopyCanvas (const miCanvas *pCanvas);
  346. #endif /* not MI_CANVAS_DRAWABLE_TYPE */
  347. /**********************************************************************/
  348. #endif /* not _XMI_H_ */