3 Image, draw, gendraw, drawreplxy, drawrepl,
4 replclipr, line, poly, fillpoly, bezier, bezspline, fillbezier, fillbezspline, ellipse,
5 fillellipse, arc, fillarc, icossin, icossin2, border, string, stringn,
6 runestring, runestringn, stringbg, stringnbg, runestringbg,
7 runestringnbg, _string, ARROW, drawsetdebug \- graphics functions
27 Display *display; /* display holding data */
28 int id; /* id of system-held Image */
29 Rectangle r; /* rectangle in data area, local coords */
30 Rectangle clipr; /* clipping region */
31 ulong chan; /* pixel channel format descriptor */
32 int depth; /* number of bits per pixel */
33 int repl; /* flag: data replicates to tile clipr */
34 Screen *screen; /* 0 if not a window */
35 Image *next; /* next in list of windows */
40 /* Porter-Duff compositing operators */
49 SoverD = SinD|SoutD|DoutS,
54 DoverS = DinS|DoutS|SoutD,
56 DxorS = DoutS|SoutD, /* == SxorD */
62 .ta +\w'\fL 'u +\w'\fL 'u +6n +4n
63 void draw(Image *dst, Rectangle r, Image *src,
66 void drawop(Image *dst, Rectangle r, Image *src,
67 Image *mask, Point p, Drawop op)
69 void gendraw(Image *dst, Rectangle r, Image *src, Point sp,
70 Image *mask, Point mp)
72 void gendrawop(Image *dst, Rectangle r, Image *src, Point sp,
73 Image *mask, Point mp, Drawop op)
75 int drawreplxy(int min, int max, int x)
77 Point drawrepl(Rectangle r, Point p)
79 void replclipr(Image *i, int repl, Rectangle clipr)
81 void line(Image *dst, Point p0, Point p1, int end0, int end1,
82 int radius, Image *src, Point sp)
84 void lineop(Image *dst, Point p0, Point p1, int end0, int end1,
85 int radius, Image *src, Point sp, Drawop op)
87 void poly(Image *dst, Point *p, int np, int end0, int end1,
88 int radius, Image *src, Point sp)
90 void polyop(Image *dst, Point *p, int np, int end0, int end1,
91 int radius, Image *src, Point sp, Drawop op)
93 void fillpoly(Image *dst, Point *p, int np, int wind,
96 void fillpolyop(Image *dst, Point *p, int np, int wind,
97 Image *src, Point sp, Drawop op)
99 int bezier(Image *dst, Point p0, Point p1, Point p2, Point p3,
100 int end0, int end1, int radius, Image *src, Point sp)
102 int bezierop(Image *dst, Point p0, Point p1, Point p2, Point p3,
103 int end0, int end1, int radius, Image *src, Point sp,
106 int bezierpts(Point p0, Point p1, Point p2, Point p3, Point **pp)
108 int bezspline(Image *dst, Point *pt, int npt, int end0, int end1,
109 int radius, Image *src, Point sp)
111 int bezsplineop(Image *dst, Point *pt, int npt, int end0, int end1,
112 int radius, Image *src, Point sp, Drawop op)
114 int bezsplinepts(Point *pt, int npt, Point **pp)
116 int fillbezier(Image *dst, Point p0, Point p1, Point p2, Point p3,
117 int w, Image *src, Point sp)
119 int fillbezierop(Image *dst, Point p0, Point p1, Point p2, Point p3,
120 int w, Image *src, Point sp, Drawop op)
122 int fillbezspline(Image *dst, Point *pt, int npt, int w,
123 Image *src, Point sp)
125 int fillbezsplineop(Image *dst, Point *pt, int npt, int w,
126 Image *src, Point sp, Drawop op)
128 void ellipse(Image *dst, Point c, int a, int b, int thick,
129 Image *src, Point sp)
131 void ellipseop(Image *dst, Point c, int a, int b, int thick,
132 Image *src, Point sp, Drawop op)
134 void fillellipse(Image *dst, Point c, int a, int b,
135 Image *src, Point sp)
137 void fillellipseop(Image *dst, Point c, int a, int b,
138 Image *src, Point sp, Drawop op)
140 void arc(Image *dst, Point c, int a, int b, int thick,
141 Image *src, Point sp, int alpha, int phi)
143 void arcop(Image *dst, Point c, int a, int b, int thick,
144 Image *src, Point sp, int alpha, int phi, Drawop op)
146 void fillarc(Image *dst, Point c, int a, int b, Image *src,
147 Point sp, int alpha, int phi)
149 void fillarcop(Image *dst, Point c, int a, int b, Image *src,
150 Point sp, int alpha, int phi, Drawop op)
152 void icossin(int deg, int *cosp, int *sinp)
154 void icossin2(int x, int y, int *cosp, int *sinp)
156 void border(Image *dst, Rectangle r, int i, Image *color, Point sp)
158 void borderop(Image *dst, Rectangle r, int i, Image *color, Point sp,
162 Point string(Image *dst, Point p, Image *src, Point sp,
165 Point stringop(Image *dst, Point p, Image *src, Point sp,
166 Font *f, char *s, Drawop op)
168 Point stringn(Image *dst, Point p, Image *src, Point sp,
169 Font *f, char *s, int len)
171 Point stringnop(Image *dst, Point p, Image *src, Point sp,
172 Font *f, char *s, int len, Drawop op)
174 Point runestring(Image *dst, Point p, Image *src, Point sp,
177 Point runestringop(Image *dst, Point p, Image *src, Point sp,
178 Font *f, Rune *r, Drawop op)
180 Point runestringn(Image *dst, Point p, Image *src, Point sp,
181 Font *f, Rune *r, int len)
183 Point runestringnop(Image *dst, Point p, Image *src, Point sp,
184 Font *f, Rune *r, int len, Drawop op)
186 Point stringbg(Image *dst, Point p, Image *src, Point sp,
187 Font *f, char *s, Image *bg, Point bgp)
189 Point stringbgop(Image *dst, Point p, Image *src, Point sp,
190 Font *f, char *s, Image *bg, Point bgp, Drawop op)
192 Point stringnbg(Image *dst, Point p, Image *src, Point sp,
193 Font *f, char *s, int len, Image *bg, Point bgp)
195 Point stringnbgop(Image *dst, Point p, Image *src, Point sp,
196 Font *f, char *s, int len, Image *bg, Point bgp, Drawop op)
198 Point runestringbg(Image *dst, Point p, Image *src, Point sp,
199 Font *f, Rune *r, Image *bg, Point bgp)
201 Point runestringbgop(Image *dst, Point p, Image *src, Point sp,
202 Font *f, Rune *r, Image *bg, Point bgp, Drawop op)
204 Point runestringnbg(Image *dst, Point p, Image *src, Point sp,
205 Font *f, Rune *r, int len, Image *bg, Point bgp)
207 Point runestringnbgop(Image *dst, Point p, Image *src, Point sp,
208 Font *f, Rune *r, int len, Image *bg, Point bgp, Drawop op)
210 Point _string(Image *dst, Point p, Image *src,
211 Point sp, Font *f, char *s, Rune *r, int len,
212 Rectangle clipr, Image *bg, Point bgp, Drawop op)
214 void drawsetdebug(int on)
226 #define ARROW(a, b, c) (Endarrow|((a)<<5)|((b)<<14)|((c)<<23))
230 type defines rectangular pictures and the methods to draw upon them;
231 it is also the building block for higher level objects such as
233 In particular, a window is represented as an
235 no special operators are needed to draw on a window.
239 The coordinates of the rectangle in the plane for which the
241 has defined pixel values.
242 It should not be modified after the image is created.
245 The clipping rectangle: operations that read or write
246 the image will not access pixels outside
252 but it may differ; see in particular the discussion of
254 The clipping region may be modified dynamically using
259 The pixel channel format descriptor, as described in
261 The value should not be modified after the image is created.
265 number of bits per pixel in the picture;
270 and is provided as a convenience.
271 The value should not be modified after the image is created.
274 A boolean value specifying whether the image is tiled to cover
275 the plane when used as a source for a drawing operation.
278 is zero, operations are restricted to the intersection of
286 defines the tile to be replicated and
288 defines the portion of the plane covered by the tiling, in other words,
290 is replicated to cover
298 For example, a replicated image with
300 set to ((0,\ 0),\ (1,\ 1)) and
302 set to ((0,\ 0),\ (100,\ 100)),
303 with the single pixel of
306 behaves identically to an image with
310 both set to ((0,\ 0),\ (100,\ 100)) and all pixels set to blue.
312 the first image requires far less memory.
313 The replication flag may be modified dynamically using
317 Most of the drawing functions come in two forms:
318 a basic form, and an extended form that takes an extra
320 to specify a Porter-Duff compositing operator to use.
321 The basic forms assume the operator is
323 which suffices for the vast majority of applications.
324 The extended forms are named by adding an
326 suffix to the basic form.
327 Only the basic forms are listed below.
329 .BI draw( dst\fP,\fP\ r\fP,\fP\ src\fP,\fP\ mask\fP,\fP\ p )
331 is the standard drawing function.
332 Only those pixels within the intersection of
340 The operation proceeds as follows
341 (this is a description of the behavior, not the implementation):
350 replicate their contents to fill
351 their clip rectangles.
364 to the intersection of
375 is false, also intersect
386 is false, also intersect
397 pixel using the alpha value
403 has an explicit alpha channel, the alpha value
406 pixel is simply that pixel's alpha channel.
407 Otherwise, the alpha value is the NTSC greyscale equivalent
408 of the color value, with white meaning opaque and black transparent.
409 In terms of the Porter-Duff compositing algebra,
419 (In the extended form,
420 ``over'' is replaced by
425 pixel channel formats
426 involved need not be identical.
427 If the channels involved are smaller than 8-bits, they will
428 be promoted before the calculation by replicating the extant bits;
429 after the calculation, they will be truncated to their proper sizes.
431 \f5gendraw(\f2dst\fP, \f2r\fP, \f2src\fP, \f2p0\fP, \f2mask\fP, \f2p1\f5)\fP
436 aligns the source and mask differently:
448 For most purposes with simple masks and source images,
452 is the general operator and the one all other drawing primitives are built upon.
454 .BI drawreplxy( min , max , x\f5)
457 to be in the half-open interval [\fImin\fP, \fImax\fP) by adding
458 or subtracting a multiple of \fImax-min\fP.
460 .BI drawrepl( r , p )
461 Clips the point \fIp\fP to be within the rectangle \fIr\fP
462 by translating the point horizontally by an integer multiple of rectangle width
463 and vertically by the height.
465 .BI replclipr( i , repl , clipr\f5)
466 Because the image data is stored on the server, local modifications to the
468 data structure itself will have no effect.
476 fields, and notifies the server of their modification.
478 \f5line(\f2dst\fP, \f2p0\fP, \f2p1\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
484 pixels joining points
488 The line is drawn using pixels from the
492 in the source corresponds to
495 The line touches both
503 specify how the ends of the line are drawn.
505 terminates the line perpendicularly to the direction of the line; a thick line with
507 on both ends will be a rectangle.
509 terminates the line by drawing a disc of diameter
511 centered on the end point.
513 terminates the line with an arrowhead whose tip touches the endpoint.
517 permits explicit control of the shape of the arrow.
518 If all three parameters are zero, it produces the default arrowhead,
521 sets the distance along line from end of the regular line to tip,
523 sets the distance along line from the barb to the tip,
526 sets the distance perpendicular to the line from edge of line to the tip of the barb,
530 and the other geometrical operators are equivalent to calls to
532 using a mask produced by the geometric procedure.
534 \f5poly(\f2dst\fP, \f2p\fP, \f2np\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
536 draws a general polygon; it
537 is conceptually equivalent to a series of calls to
539 joining adjacent points in the
546 The ends of the polygon are specified as in
548 interior lines are terminated with
550 to make smooth joins.
551 The source is aligned so
556 \f5fillpoly(\f2dst\fP, \f2p\fP, \f2np\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
560 but fills in the resulting polygon rather than outlining it.
561 The source is aligned so
565 The winding rule parameter
567 resolves ambiguities about what to fill if the polygon is self-intersecting.
572 a pixel is inside the polygon if the polygon's winding number about the point
578 a pixel is inside if the winding number is odd.
579 Complementary values (0 or ~1) cause outside pixels to be filled.
580 The meaning of other values is undefined.
581 The polygon is closed with a line if necessary.
583 \f5bezier(\f2dst\fP, \f2a\fP, \f2b\fP, \f2c\fP, \f2d\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
586 cubic Bezier curve defined by
593 The end styles are determined by
597 the thickness of the curve is
599 The source is aligned so
608 \f5bezierpts(\f2a\fP, \f2b\fP, \f2c\fP, \f2d\fP, \f2pp\fP)
612 a list of points making up the open polygon that
615 The caller is responsible for freeing
618 \f5bezspline(\f2dst\fP, \f2p\fP, \f2np\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
620 takes the same arguments as
622 but draws a quadratic B-spline (despite its name) rather than a polygon.
623 If the first and last points in
625 are equal, the spline has periodic end conditions.
627 \f5bezsplinepts(\f2pt\fP, \f2npt\fP, \f2pp\fP)
631 a list of points making up the open polygon that
634 The caller is responsible for freeing
637 \f5fillbezier(\f2dst\fP, \f2a\fP, \f2b\fP, \f2c\fP, \f2d\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
646 \f5fillbezspline(\f2dst\fP, \f2p\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
650 but fills the quadratic B-spline rather than the polygon outlined by
652 The spline is closed with a line if necessary.
654 \f5ellipse(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
658 an ellipse centered on
660 with horizontal and vertical semiaxes
664 The source is aligned so
672 The ellipse is drawn with thickness
675 \f5fillellipse(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2src\fP, \f2sp\fP)
679 but fills the ellipse rather than outlining it.
681 \f5arc(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2thick\fP, \f2src\fP, \f2sp\fP, \f2alpha\fP, \f2phi\fP)
685 but draws only that portion of the ellipse starting at angle
687 and extending through an angle of
689 The angles are measured in degrees counterclockwise from the positive
693 \f5fillarc(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2src\fP, \f2sp\fP, \f2alpha\fP, \f2phi\fP)
697 but fills the sector with the source color.
699 \f5icossin(\f2deg\fP, \f2cosp\fP, \f2sinp\fP)
705 scaled integers representing the cosine and sine of the angle
707 measured in integer degrees.
708 The values are scaled so cos(0) is 1024.
710 \f5icossin2(\f2x\fP, \f2y\fP, \f2cosp\fP, \f2sinp\fP)
714 with the angle represented not in degrees but implicitly by the point
725 .BI border( dst\fP,\fP\ r\fP,\fP\ i\fP,\fP\ color\fP,\fP\ sp\fP)
727 draws an outline of rectangle
731 The outline has width
733 if positive, the border goes inside the rectangle; negative, outside.
734 The source is aligned so
739 .BI string( dst\fP,\fP\ p\fP,\fP\ src\fP,\fP\ sp\fP,\fP\ font\fP,\fP\ s )
743 characters specified by the string
747 it is equivalent to a series of calls to
751 and masks determined by the character shapes.
752 The text is positioned with the left of the first character at
754 and the top of the line of text at
756 The source is positioned so
767 that is the position of the next character that would be drawn if the string were longer.
769 For characters with undefined
770 or zero-width images in the font, the character at font position 0 (NUL) is drawn.
772 The other string routines are variants of this basic form, and
773 have names that encode their variant behavior.
774 Routines whose names contain
776 accept a string of Runes rather than
783 that defines the number of characters to draw rather than accepting a NUL-terminated
787 draw the background behind the characters in the specified color
792 normally the text is drawn leaving the background intact.
796 captures all this behavior into a single operator. Whether it draws a
799 or Rune string depends on whether
803 is null (the string length is always determined by
807 is non-null, it is used as a background color.
810 argument allows further management of clipping when drawing the string;
811 it is intersected with the usual clipping rectangles to further limit the extent of the text.
813 .BI drawsetdebug( on )
814 Turns on or off debugging output (usually
815 to a serial line) according to whether
828 ``Compositing Digital Images'',
829 .I "Computer Graphics
830 (Proc. SIGGRAPH), 18:3, pp. 253-259, 1984.
832 These routines call the graphics error function on fatal errors.
834 Anti-aliased characters can be drawn by defining a font
835 with multiple bits per pixel, but there are
836 no anti-aliasing geometric primitives.