3 Image, draw, drawop, gendraw, gendrawop, drawreplxy, drawrepl,
4 replclipr, line, lineop, poly, polyop, fillpoly, fillpolyop, bezier, bezierop,
5 bezspline, bezsplineop, bezsplinepts, fillbezier, fillbezierop,
6 fillbezspline, fillbezsplineop, ellipse, ellipseop,
7 fillellipse, fillellipseop, arc, arcop, fillarc, fillarcop,
8 icossin, icossin2, border, borderop, string, stringop, stringn, stringnop,
9 runestring, runestringop, runestringn, runestringnop, stringbg,
10 stringbgop, stringnbg, stringnbgop, runestringbg, runestringbgop,
11 runestringnbg, runestringnbgop, _string, ARROW, drawsetdebug \- graphics functions
31 Display *display; /* display holding data */
32 int id; /* id of system-held Image */
33 Rectangle r; /* rectangle in data area, local coords */
34 Rectangle clipr; /* clipping region */
35 ulong chan; /* pixel channel format descriptor */
36 int depth; /* number of bits per pixel */
37 int repl; /* flag: data replicates to tile clipr */
38 Screen *screen; /* 0 if not a window */
39 Image *next; /* next in list of windows */
44 /* Porter-Duff compositing operators */
53 SoverD = SinD|SoutD|DoutS,
58 DoverS = DinS|DoutS|SoutD,
60 DxorS = DoutS|SoutD, /* == SxorD */
66 .ta +\w'\fL 'u +\w'\fL 'u +6n +4n
67 void draw(Image *dst, Rectangle r, Image *src,
70 void drawop(Image *dst, Rectangle r, Image *src,
71 Image *mask, Point p, Drawop op)
73 void gendraw(Image *dst, Rectangle r, Image *src, Point sp,
74 Image *mask, Point mp)
76 void gendrawop(Image *dst, Rectangle r, Image *src, Point sp,
77 Image *mask, Point mp, Drawop op)
79 int drawreplxy(int min, int max, int x)
81 Point drawrepl(Rectangle r, Point p)
83 void replclipr(Image *i, int repl, Rectangle clipr)
85 void line(Image *dst, Point p0, Point p1, int end0, int end1,
86 int radius, Image *src, Point sp)
88 void lineop(Image *dst, Point p0, Point p1, int end0, int end1,
89 int radius, Image *src, Point sp, Drawop op)
91 void poly(Image *dst, Point *p, int np, int end0, int end1,
92 int radius, Image *src, Point sp)
94 void polyop(Image *dst, Point *p, int np, int end0, int end1,
95 int radius, Image *src, Point sp, Drawop op)
97 void fillpoly(Image *dst, Point *p, int np, int wind,
100 void fillpolyop(Image *dst, Point *p, int np, int wind,
101 Image *src, Point sp, Drawop op)
103 int bezier(Image *dst, Point p0, Point p1, Point p2, Point p3,
104 int end0, int end1, int radius, Image *src, Point sp)
106 int bezierop(Image *dst, Point p0, Point p1, Point p2, Point p3,
107 int end0, int end1, int radius, Image *src, Point sp,
110 int bezspline(Image *dst, Point *pt, int npt, int end0, int end1,
111 int radius, Image *src, Point sp)
113 int bezsplineop(Image *dst, Point *pt, int npt, int end0, int end1,
114 int radius, Image *src, Point sp, Drawop op)
116 int bezsplinepts(Point *pt, int npt, Point **pp)
118 int fillbezier(Image *dst, Point p0, Point p1, Point p2, Point p3,
119 int w, Image *src, Point sp)
121 int fillbezierop(Image *dst, Point p0, Point p1, Point p2, Point p3,
122 int w, Image *src, Point sp, Drawop op)
124 int fillbezspline(Image *dst, Point *pt, int npt, int w,
125 Image *src, Point sp)
127 int fillbezsplineop(Image *dst, Point *pt, int npt, int w,
128 Image *src, Point sp, Drawop op)
130 void ellipse(Image *dst, Point c, int a, int b, int thick,
131 Image *src, Point sp)
133 void ellipseop(Image *dst, Point c, int a, int b, int thick,
134 Image *src, Point sp, Drawop op)
136 void fillellipse(Image *dst, Point c, int a, int b,
137 Image *src, Point sp)
139 void fillellipseop(Image *dst, Point c, int a, int b,
140 Image *src, Point sp, Drawop op)
142 void arc(Image *dst, Point c, int a, int b, int thick,
143 Image *src, Point sp, int alpha, int phi)
145 void arcop(Image *dst, Point c, int a, int b, int thick,
146 Image *src, Point sp, int alpha, int phi, Drawop op)
148 void fillarc(Image *dst, Point c, int a, int b, Image *src,
149 Point sp, int alpha, int phi)
151 void fillarcop(Image *dst, Point c, int a, int b, Image *src,
152 Point sp, int alpha, int phi, Drawop op)
154 int icossin(int deg, int *cosp, int *sinp)
156 int icossin2(int x, int y, int *cosp, int *sinp)
158 void border(Image *dst, Rectangle r, int i, Image *color, Point sp)
160 void borderop(Image *im, Rectangle r, int i, Image *color, Point sp,
164 Point string(Image *dst, Point p, Image *src, Point sp,
167 Point stringop(Image *dst, Point p, Image *src, Point sp,
168 Font *f, char *s, Drawop op)
170 Point stringn(Image *dst, Point p, Image *src, Point sp,
171 Font *f, char *s, int len)
173 Point stringnop(Image *dst, Point p, Image *src, Point sp,
174 Font *f, char *s, int len, Drawop op)
176 Point runestring(Image *dst, Point p, Image *src, Point sp,
179 Point runestringop(Image *dst, Point p, Image *src, Point sp,
180 Font *f, Rune *r, Drawop op)
182 Point runestringn(Image *dst, Point p, Image *src, Point sp,
183 Font *f, Rune *r, int len)
185 Point runestringnop(Image *dst, Point p, Image *src, Point sp,
186 Font *f, Rune *r, int len, Drawop op)
188 Point stringbg(Image *dst, Point p, Image *src, Point sp,
189 Font *f, char *s, Image *bg, Point bgp)
191 Point stringbgop(Image *dst, Point p, Image *src, Point sp,
192 Font *f, char *s, Image *bg, Point bgp, Drawop op)
194 Point stringnbg(Image *dst, Point p, Image *src, Point sp,
195 Font *f, char *s, int len, Image *bg, Point bgp)
197 Point stringnbgop(Image *dst, Point p, Image *src, Point sp,
198 Font *f, char *s, int len, Image *bg, Point bgp, Drawop op)
200 Point runestringbg(Image *dst, Point p, Image *src, Point sp,
201 Font *f, Rune *r, Image *bg, Point bgp)
203 Point runestringbgop(Image *dst, Point p, Image *src, Point sp,
204 Font *f, Rune *r, Image *bg, Point bgp, Drawop op)
206 Point runestringnbg(Image *dst, Point p, Image *src, Point sp,
207 Font *f, Rune *r, int len, Image *bg, Point bgp)
209 Point runestringnbgop(Image *dst, Point p, Image *src, Point sp,
210 Font *f, Rune *r, int len, Image *bg, Point bgp, Drawop op)
212 Point _string(Image *dst, Point p, Image *src,
213 Point sp, Font *f, char *s, Rune *r, int len,
214 Rectangle clipr, Image *bg, Point bgp, Drawop op)
216 void drawsetdebug(int on)
228 #define ARROW(a, b, c) (Endarrow|((a)<<5)|((b)<<14)|((c)<<23))
232 type defines rectangular pictures and the methods to draw upon them;
233 it is also the building block for higher level objects such as
235 In particular, a window is represented as an
237 no special operators are needed to draw on a window.
241 The coordinates of the rectangle in the plane for which the
243 has defined pixel values.
244 It should not be modified after the image is created.
247 The clipping rectangle: operations that read or write
248 the image will not access pixels outside
254 but it may differ; see in particular the discussion of
256 The clipping region may be modified dynamically using
261 The pixel channel format descriptor, as described in
263 The value should not be modified after the image is created.
267 number of bits per pixel in the picture;
272 and is provided as a convenience.
273 The value should not be modified after the image is created.
276 A boolean value specifying whether the image is tiled to cover
277 the plane when used as a source for a drawing operation.
280 is zero, operations are restricted to the intersection of
288 defines the tile to be replicated and
290 defines the portion of the plane covered by the tiling, in other words,
292 is replicated to cover
300 For example, a replicated image with
302 set to ((0,\ 0),\ (1,\ 1)) and
304 set to ((0,\ 0),\ (100,\ 100)),
305 with the single pixel of
308 behaves identically to an image with
312 both set to ((0,\ 0),\ (100,\ 100)) and all pixels set to blue.
314 the first image requires far less memory.
315 The replication flag may be modified dynamically using
319 Most of the drawing functions come in two forms:
320 a basic form, and an extended form that takes an extra
322 to specify a Porter-Duff compositing operator to use.
323 The basic forms assume the operator is
325 which suffices for the vast majority of applications.
326 The extended forms are named by adding an
328 suffix to the basic form.
329 Only the basic forms are listed below.
331 .BI draw( dst\fP,\fP\ r\fP,\fP\ src\fP,\fP\ mask\fP,\fP\ p )
333 is the standard drawing function.
334 Only those pixels within the intersection of
342 The operation proceeds as follows
343 (this is a description of the behavior, not the implementation):
352 replicate their contents to fill
353 their clip rectangles.
366 to the intersection of
377 is false, also intersect
388 is false, also intersect
399 pixel using the alpha value
405 has an explicit alpha channel, the alpha value
408 pixel is simply that pixel's alpha channel.
409 Otherwise, the alpha value is the NTSC greyscale equivalent
410 of the color value, with white meaning opaque and black transparent.
411 In terms of the Porter-Duff compositing algebra,
421 (In the extended form,
422 ``over'' is replaced by
427 pixel channel formats
428 involved need not be identical.
429 If the channels involved are smaller than 8-bits, they will
430 be promoted before the calculation by replicating the extant bits;
431 after the calculation, they will be truncated to their proper sizes.
433 \f5gendraw(\f2dst\fP, \f2r\fP, \f2src\fP, \f2p0\fP, \f2mask\fP, \f2p1\f5)\fP
438 aligns the source and mask differently:
450 For most purposes with simple masks and source images,
454 is the general operator and the one all other drawing primitives are built upon.
456 .BI drawreplxy( min , max , x\f5)
459 to be in the half-open interval [\fImin\fP, \fImax\fP) by adding
460 or subtracting a multiple of \fImax-min\fP.
462 .BI drawrepl( r , p )
463 Clips the point \fIp\fP to be within the rectangle \fIr\fP
464 by translating the point horizontally by an integer multiple of rectangle width
465 and vertically by the height.
467 .BI replclipr( i , repl , clipr\f5)
468 Because the image data is stored on the server, local modifications to the
470 data structure itself will have no effect.
478 fields, and notifies the server of their modification.
480 \f5line(\f2dst\fP, \f2p0\fP, \f2p1\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
486 pixels joining points
490 The line is drawn using pixels from the
494 in the source corresponds to
497 The line touches both
505 specify how the ends of the line are drawn.
507 terminates the line perpendicularly to the direction of the line; a thick line with
509 on both ends will be a rectangle.
511 terminates the line by drawing a disc of diameter
513 centered on the end point.
515 terminates the line with an arrowhead whose tip touches the endpoint.
519 permits explicit control of the shape of the arrow.
520 If all three parameters are zero, it produces the default arrowhead,
523 sets the distance along line from end of the regular line to tip,
525 sets the distance along line from the barb to the tip,
528 sets the distance perpendicular to the line from edge of line to the tip of the barb,
532 and the other geometrical operators are equivalent to calls to
534 using a mask produced by the geometric procedure.
536 \f5poly(\f2dst\fP, \f2p\fP, \f2np\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
538 draws a general polygon; it
539 is conceptually equivalent to a series of calls to
541 joining adjacent points in the
548 The ends of the polygon are specified as in
550 interior lines are terminated with
552 to make smooth joins.
553 The source is aligned so
558 \f5fillpoly(\f2dst\fP, \f2p\fP, \f2np\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
562 but fills in the resulting polygon rather than outlining it.
563 The source is aligned so
567 The winding rule parameter
569 resolves ambiguities about what to fill if the polygon is self-intersecting.
574 a pixel is inside the polygon if the polygon's winding number about the point
580 a pixel is inside if the winding number is odd.
581 Complementary values (0 or ~1) cause outside pixels to be filled.
582 The meaning of other values is undefined.
583 The polygon is closed with a line if necessary.
585 \f5bezier(\f2dst\fP, \f2a\fP, \f2b\fP, \f2c\fP, \f2d\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
588 cubic Bezier curve defined by
595 The end styles are determined by
599 the thickness of the curve is
601 The source is aligned so
610 \f5bezspline(\f2dst\fP, \f2p\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
612 takes the same arguments as
614 but draws a quadratic B-spline (despite its name) rather than a polygon.
615 If the first and last points in
617 are equal, the spline has periodic end conditions.
619 \f5bezsplinepts(\f2pt\fP, \f2npt\fP, \f2pp\fP)
623 a list of points making up the open polygon that
626 The caller is responsible for freeing
629 \f5fillbezier(\f2dst\fP, \f2a\fP, \f2b\fP, \f2c\fP, \f2d\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
638 \f5fillbezspline(\f2dst\fP, \f2p\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
642 but fills the quadratic B-spline rather than the polygon outlined by
644 The spline is closed with a line if necessary.
646 \f5ellipse(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
650 an ellipse centered on
652 with horizontal and vertical semiaxes
656 The source is aligned so
664 The ellipse is drawn with thickness
667 \f5fillellipse(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2src\fP, \f2sp\fP)
671 but fills the ellipse rather than outlining it.
673 \f5arc(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2thick\fP, \f2src\fP, \f2sp\fP, \f2alpha\fP, \f2phi\fP)
677 but draws only that portion of the ellipse starting at angle
679 and extending through an angle of
681 The angles are measured in degrees counterclockwise from the positive
685 \f5fillarc(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2src\fP, \f2sp\fP, \f2alpha\fP, \f2phi\fP)
689 but fills the sector with the source color.
691 \f5icossin(\f2deg\fP, \f2cosp\fP, \f2sinp\fP)
697 scaled integers representing the cosine and sine of the angle
699 measured in integer degrees.
700 The values are scaled so cos(0) is 1024.
702 \f5icossin2(\f2x\fP, \f2y\fP, \f2cosp\fP, \f2sinp\fP)
706 with the angle represented not in degrees but implicitly by the point
717 .BI border( dst\fP,\fP\ r\fP,\fP\ i\fP,\fP\ color\fP,\fP\ sp\fP)
719 draws an outline of rectangle
723 The outline has width
725 if positive, the border goes inside the rectangle; negative, outside.
726 The source is aligned so
731 .BI string( dst\fP,\fP\ p\fP,\fP\ src\fP,\fP\ sp\fP,\fP\ font\fP,\fP\ s )
735 characters specified by the string
739 it is equivalent to a series of calls to
743 and masks determined by the character shapes.
744 The text is positioned with the left of the first character at
746 and the top of the line of text at
748 The source is positioned so
759 that is the position of the next character that would be drawn if the string were longer.
761 For characters with undefined
762 or zero-width images in the font, the character at font position 0 (NUL) is drawn.
764 The other string routines are variants of this basic form, and
765 have names that encode their variant behavior.
766 Routines whose names contain
768 accept a string of Runes rather than
775 that defines the number of characters to draw rather than accepting a NUL-terminated
779 draw the background behind the characters in the specified color
784 normally the text is drawn leaving the background intact.
788 captures all this behavior into a single operator. Whether it draws a
791 or Rune string depends on whether
795 is null (the string length is always determined by
799 is non-null, it is used as a background color.
802 argument allows further management of clipping when drawing the string;
803 it is intersected with the usual clipping rectangles to further limit the extent of the text.
805 .BI drawsetdebug( on )
806 Turns on or off debugging output (usually
807 to a serial line) according to whether
820 ``Compositing Digital Images'',
821 .I "Computer Graphics
822 (Proc. SIGGRAPH), 18:3, pp. 253-259, 1984.
824 These routines call the graphics error function on fatal errors.
826 Anti-aliased characters can be drawn by defining a font
827 with multiple bits per pixel, but there are
828 no anti-aliasing geometric primitives.