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, 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)
161 Point string(Image *dst, Point p, Image *src, Point sp,
164 Point stringop(Image *dst, Point p, Image *src, Point sp,
165 Font *f, char *s, Drawop op)
167 Point stringn(Image *dst, Point p, Image *src, Point sp,
168 Font *f, char *s, int len)
170 Point stringnop(Image *dst, Point p, Image *src, Point sp,
171 Font *f, char *s, int len, Drawop op)
173 Point runestring(Image *dst, Point p, Image *src, Point sp,
176 Point runestringop(Image *dst, Point p, Image *src, Point sp,
177 Font *f, Rune *r, Drawop op)
179 Point runestringn(Image *dst, Point p, Image *src, Point sp,
180 Font *f, Rune *r, int len)
182 Point runestringnop(Image *dst, Point p, Image *src, Point sp,
183 Font *f, Rune *r, int len, Drawop op)
185 Point stringbg(Image *dst, Point p, Image *src, Point sp,
186 Font *f, char *s, Image *bg, Point bgp)
188 Point stringbgop(Image *dst, Point p, Image *src, Point sp,
189 Font *f, char *s, Image *bg, Point bgp, Drawop op)
191 Point stringnbg(Image *dst, Point p, Image *src, Point sp,
192 Font *f, char *s, int len, Image *bg, Point bgp)
194 Point stringnbgop(Image *dst, Point p, Image *src, Point sp,
195 Font *f, char *s, int len, Image *bg, Point bgp, Drawop op)
197 Point runestringbg(Image *dst, Point p, Image *src, Point sp,
198 Font *f, Rune *r, Image *bg, Point bgp)
200 Point runestringbgop(Image *dst, Point p, Image *src, Point sp,
201 Font *f, Rune *r, Image *bg, Point bgp, Drawop op)
203 Point runestringnbg(Image *dst, Point p, Image *src, Point sp,
204 Font *f, Rune *r, int len, Image *bg, Point bgp)
206 Point runestringnbgop(Image *dst, Point p, Image *src, Point sp,
207 Font *f, Rune *r, int len, Image *bg, Point bgp, Drawop op)
209 Point _string(Image *dst, Point p, Image *src,
210 Point sp, Font *f, char *s, Rune *r, int len,
211 Rectangle clipr, Image *bg, Point bgp, Drawop op)
213 void drawsetdebug(int on)
225 #define ARROW(a, b, c) (Endarrow|((a)<<5)|((b)<<14)|((c)<<23))
229 type defines rectangular pictures and the methods to draw upon them;
230 it is also the building block for higher level objects such as
232 In particular, a window is represented as an
234 no special operators are needed to draw on a window.
238 The coordinates of the rectangle in the plane for which the
240 has defined pixel values.
241 It should not be modified after the image is created.
244 The clipping rectangle: operations that read or write
245 the image will not access pixels outside
251 but it may differ; see in particular the discussion of
253 The clipping region may be modified dynamically using
258 The pixel channel format descriptor, as described in
260 The value should not be modified after the image is created.
264 number of bits per pixel in the picture;
269 and is provided as a convenience.
270 The value should not be modified after the image is created.
273 A boolean value specifying whether the image is tiled to cover
274 the plane when used as a source for a drawing operation.
277 is zero, operations are restricted to the intersection of
285 defines the tile to be replicated and
287 defines the portion of the plane covered by the tiling, in other words,
289 is replicated to cover
297 For example, a replicated image with
299 set to ((0,\ 0),\ (1,\ 1)) and
301 set to ((0,\ 0),\ (100,\ 100)),
302 with the single pixel of
305 behaves identically to an image with
309 both set to ((0,\ 0),\ (100,\ 100)) and all pixels set to blue.
311 the first image requires far less memory.
312 The replication flag may be modified dynamically using
316 Most of the drawing functions come in two forms:
317 a basic form, and an extended form that takes an extra
319 to specify a Porter-Duff compositing operator to use.
320 The basic forms assume the operator is
322 which suffices for the vast majority of applications.
323 The extended forms are named by adding an
325 suffix to the basic form.
326 Only the basic forms are listed below.
328 .BI draw( dst\fP,\fP\ r\fP,\fP\ src\fP,\fP\ mask\fP,\fP\ p )
330 is the standard drawing function.
331 Only those pixels within the intersection of
339 The operation proceeds as follows
340 (this is a description of the behavior, not the implementation):
349 replicate their contents to fill
350 their clip rectangles.
363 to the intersection of
374 is false, also intersect
385 is false, also intersect
396 pixel using the alpha value
402 has an explicit alpha channel, the alpha value
405 pixel is simply that pixel's alpha channel.
406 Otherwise, the alpha value is the NTSC greyscale equivalent
407 of the color value, with white meaning opaque and black transparent.
408 In terms of the Porter-Duff compositing algebra,
418 (In the extended form,
419 ``over'' is replaced by
424 pixel channel formats
425 involved need not be identical.
426 If the channels involved are smaller than 8-bits, they will
427 be promoted before the calculation by replicating the extant bits;
428 after the calculation, they will be truncated to their proper sizes.
430 \f5gendraw(\f2dst\fP, \f2r\fP, \f2src\fP, \f2p0\fP, \f2mask\fP, \f2p1\f5)\fP
435 aligns the source and mask differently:
447 For most purposes with simple masks and source images,
451 is the general operator and the one all other drawing primitives are built upon.
453 .BI drawreplxy( min , max , x\f5)
456 to be in the half-open interval [\fImin\fP, \fImax\fP) by adding
457 or subtracting a multiple of \fImax-min\fP.
459 .BI drawrepl( r , p )
460 Clips the point \fIp\fP to be within the rectangle \fIr\fP
461 by translating the point horizontally by an integer multiple of rectangle width
462 and vertically by the height.
464 .BI replclipr( i , repl , clipr\f5)
465 Because the image data is stored on the server, local modifications to the
467 data structure itself will have no effect.
475 fields, and notifies the server of their modification.
477 \f5line(\f2dst\fP, \f2p0\fP, \f2p1\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
483 pixels joining points
487 The line is drawn using pixels from the
491 in the source corresponds to
494 The line touches both
502 specify how the ends of the line are drawn.
504 terminates the line perpendicularly to the direction of the line; a thick line with
506 on both ends will be a rectangle.
508 terminates the line by drawing a disc of diameter
510 centered on the end point.
512 terminates the line with an arrowhead whose tip touches the endpoint.
516 permits explicit control of the shape of the arrow.
517 If all three parameters are zero, it produces the default arrowhead,
520 sets the distance along line from end of the regular line to tip,
522 sets the distance along line from the barb to the tip,
525 sets the distance perpendicular to the line from edge of line to the tip of the barb,
529 and the other geometrical operators are equivalent to calls to
531 using a mask produced by the geometric procedure.
533 \f5poly(\f2dst\fP, \f2p\fP, \f2np\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
535 draws a general polygon; it
536 is conceptually equivalent to a series of calls to
538 joining adjacent points in the
545 The ends of the polygon are specified as in
547 interior lines are terminated with
549 to make smooth joins.
550 The source is aligned so
555 \f5fillpoly(\f2dst\fP, \f2p\fP, \f2np\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
559 but fills in the resulting polygon rather than outlining it.
560 The source is aligned so
564 The winding rule parameter
566 resolves ambiguities about what to fill if the polygon is self-intersecting.
571 a pixel is inside the polygon if the polygon's winding number about the point
577 a pixel is inside if the winding number is odd.
578 Complementary values (0 or ~1) cause outside pixels to be filled.
579 The meaning of other values is undefined.
580 The polygon is closed with a line if necessary.
582 \f5bezier(\f2dst\fP, \f2a\fP, \f2b\fP, \f2c\fP, \f2d\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
585 cubic Bezier curve defined by
592 The end styles are determined by
596 the thickness of the curve is
598 The source is aligned so
607 \f5bezspline(\f2dst\fP, \f2p\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
609 takes the same arguments as
611 but draws a quadratic B-spline (despite its name) rather than a polygon.
612 If the first and last points in
614 are equal, the spline has periodic end conditions.
616 \f5bezsplinepts(\f2pt\fP, \f2npt\fP, \f2pp\fP)
620 a list of points making up the open polygon that
623 The caller is responsible for freeing
626 \f5fillbezier(\f2dst\fP, \f2a\fP, \f2b\fP, \f2c\fP, \f2d\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
635 \f5fillbezspline(\f2dst\fP, \f2p\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
639 but fills the quadratic B-spline rather than the polygon outlined by
641 The spline is closed with a line if necessary.
643 \f5ellipse(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
647 an ellipse centered on
649 with horizontal and vertical semiaxes
653 The source is aligned so
661 The ellipse is drawn with thickness
664 \f5fillellipse(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2src\fP, \f2sp\fP)
668 but fills the ellipse rather than outlining it.
670 \f5arc(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2thick\fP, \f2src\fP, \f2sp\fP, \f2alpha\fP, \f2phi\fP)
674 but draws only that portion of the ellipse starting at angle
676 and extending through an angle of
678 The angles are measured in degrees counterclockwise from the positive
682 \f5fillarc(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2src\fP, \f2sp\fP, \f2alpha\fP, \f2phi\fP)
686 but fills the sector with the source color.
688 \f5icossin(\f2deg\fP, \f2cosp\fP, \f2sinp\fP)
694 scaled integers representing the cosine and sine of the angle
696 measured in integer degrees.
697 The values are scaled so cos(0) is 1024.
699 \f5icossin2(\f2x\fP, \f2y\fP, \f2cosp\fP, \f2sinp\fP)
703 with the angle represented not in degrees but implicitly by the point
714 .BI border( dst\fP,\fP\ r\fP,\fP\ i\fP,\fP\ color\fP,\fP\ sp\fP)
716 draws an outline of rectangle
720 The outline has width
722 if positive, the border goes inside the rectangle; negative, outside.
723 The source is aligned so
728 .BI string( dst\fP,\fP\ p\fP,\fP\ src\fP,\fP\ sp\fP,\fP\ font\fP,\fP\ s )
732 characters specified by the string
736 it is equivalent to a series of calls to
740 and masks determined by the character shapes.
741 The text is positioned with the left of the first character at
743 and the top of the line of text at
745 The source is positioned so
756 that is the position of the next character that would be drawn if the string were longer.
758 For characters with undefined
759 or zero-width images in the font, the character at font position 0 (NUL) is drawn.
761 The other string routines are variants of this basic form, and
762 have names that encode their variant behavior.
763 Routines whose names contain
765 accept a string of Runes rather than
772 that defines the number of characters to draw rather than accepting a NUL-terminated
776 draw the background behind the characters in the specified color
781 normally the text is drawn leaving the background intact.
785 captures all this behavior into a single operator. Whether it draws a
788 or Rune string depends on whether
792 is null (the string length is always determined by
796 is non-null, it is used as a background color.
799 argument allows further management of clipping when drawing the string;
800 it is intersected with the usual clipping rectangles to further limit the extent of the text.
802 .BI drawsetdebug( on )
803 Turns on or off debugging output (usually
804 to a serial line) according to whether
817 ``Compositing Digital Images'',
818 .I "Computer Graphics
819 (Proc. SIGGRAPH), 18:3, pp. 253-259, 1984.
821 These routines call the graphics error function on fatal errors.
823 Anti-aliased characters can be drawn by defining a font
824 with multiple bits per pixel, but there are
825 no anti-aliasing geometric primitives.