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 bezspline(Image *dst, Point *pt, int npt, int end0, int end1,
107 int radius, Image *src, Point sp)
109 int bezsplineop(Image *dst, Point *pt, int npt, int end0, int end1,
110 int radius, Image *src, Point sp, Drawop op)
112 int bezsplinepts(Point *pt, int npt, Point **pp)
114 int fillbezier(Image *dst, Point p0, Point p1, Point p2, Point p3,
115 int w, Image *src, Point sp)
117 int fillbezierop(Image *dst, Point p0, Point p1, Point p2, Point p3,
118 int w, Image *src, Point sp, Drawop op)
120 int fillbezspline(Image *dst, Point *pt, int npt, int w,
121 Image *src, Point sp)
123 int fillbezsplineop(Image *dst, Point *pt, int npt, int w,
124 Image *src, Point sp, Drawop op)
126 void ellipse(Image *dst, Point c, int a, int b, int thick,
127 Image *src, Point sp)
129 void ellipseop(Image *dst, Point c, int a, int b, int thick,
130 Image *src, Point sp, Drawop op)
132 void fillellipse(Image *dst, Point c, int a, int b,
133 Image *src, Point sp)
135 void fillellipseop(Image *dst, Point c, int a, int b,
136 Image *src, Point sp, Drawop op)
138 void arc(Image *dst, Point c, int a, int b, int thick,
139 Image *src, Point sp, int alpha, int phi)
141 void arcop(Image *dst, Point c, int a, int b, int thick,
142 Image *src, Point sp, int alpha, int phi, Drawop op)
144 void fillarc(Image *dst, Point c, int a, int b, Image *src,
145 Point sp, int alpha, int phi)
147 void fillarcop(Image *dst, Point c, int a, int b, Image *src,
148 Point sp, int alpha, int phi, Drawop op)
150 int icossin(int deg, int *cosp, int *sinp)
152 int icossin2(int x, int y, int *cosp, int *sinp)
154 void border(Image *dst, Rectangle r, int i, Image *color, Point sp)
156 void borderop(Image *dst, Rectangle r, int i, Image *color, Point sp,
160 Point string(Image *dst, Point p, Image *src, Point sp,
163 Point stringop(Image *dst, Point p, Image *src, Point sp,
164 Font *f, char *s, Drawop op)
166 Point stringn(Image *dst, Point p, Image *src, Point sp,
167 Font *f, char *s, int len)
169 Point stringnop(Image *dst, Point p, Image *src, Point sp,
170 Font *f, char *s, int len, Drawop op)
172 Point runestring(Image *dst, Point p, Image *src, Point sp,
175 Point runestringop(Image *dst, Point p, Image *src, Point sp,
176 Font *f, Rune *r, Drawop op)
178 Point runestringn(Image *dst, Point p, Image *src, Point sp,
179 Font *f, Rune *r, int len)
181 Point runestringnop(Image *dst, Point p, Image *src, Point sp,
182 Font *f, Rune *r, int len, Drawop op)
184 Point stringbg(Image *dst, Point p, Image *src, Point sp,
185 Font *f, char *s, Image *bg, Point bgp)
187 Point stringbgop(Image *dst, Point p, Image *src, Point sp,
188 Font *f, char *s, Image *bg, Point bgp, Drawop op)
190 Point stringnbg(Image *dst, Point p, Image *src, Point sp,
191 Font *f, char *s, int len, Image *bg, Point bgp)
193 Point stringnbgop(Image *dst, Point p, Image *src, Point sp,
194 Font *f, char *s, int len, Image *bg, Point bgp, Drawop op)
196 Point runestringbg(Image *dst, Point p, Image *src, Point sp,
197 Font *f, Rune *r, Image *bg, Point bgp)
199 Point runestringbgop(Image *dst, Point p, Image *src, Point sp,
200 Font *f, Rune *r, Image *bg, Point bgp, Drawop op)
202 Point runestringnbg(Image *dst, Point p, Image *src, Point sp,
203 Font *f, Rune *r, int len, Image *bg, Point bgp)
205 Point runestringnbgop(Image *dst, Point p, Image *src, Point sp,
206 Font *f, Rune *r, int len, Image *bg, Point bgp, Drawop op)
208 Point _string(Image *dst, Point p, Image *src,
209 Point sp, Font *f, char *s, Rune *r, int len,
210 Rectangle clipr, Image *bg, Point bgp, Drawop op)
212 void drawsetdebug(int on)
224 #define ARROW(a, b, c) (Endarrow|((a)<<5)|((b)<<14)|((c)<<23))
228 type defines rectangular pictures and the methods to draw upon them;
229 it is also the building block for higher level objects such as
231 In particular, a window is represented as an
233 no special operators are needed to draw on a window.
237 The coordinates of the rectangle in the plane for which the
239 has defined pixel values.
240 It should not be modified after the image is created.
243 The clipping rectangle: operations that read or write
244 the image will not access pixels outside
250 but it may differ; see in particular the discussion of
252 The clipping region may be modified dynamically using
257 The pixel channel format descriptor, as described in
259 The value should not be modified after the image is created.
263 number of bits per pixel in the picture;
268 and is provided as a convenience.
269 The value should not be modified after the image is created.
272 A boolean value specifying whether the image is tiled to cover
273 the plane when used as a source for a drawing operation.
276 is zero, operations are restricted to the intersection of
284 defines the tile to be replicated and
286 defines the portion of the plane covered by the tiling, in other words,
288 is replicated to cover
296 For example, a replicated image with
298 set to ((0,\ 0),\ (1,\ 1)) and
300 set to ((0,\ 0),\ (100,\ 100)),
301 with the single pixel of
304 behaves identically to an image with
308 both set to ((0,\ 0),\ (100,\ 100)) and all pixels set to blue.
310 the first image requires far less memory.
311 The replication flag may be modified dynamically using
315 Most of the drawing functions come in two forms:
316 a basic form, and an extended form that takes an extra
318 to specify a Porter-Duff compositing operator to use.
319 The basic forms assume the operator is
321 which suffices for the vast majority of applications.
322 The extended forms are named by adding an
324 suffix to the basic form.
325 Only the basic forms are listed below.
327 .BI draw( dst\fP,\fP\ r\fP,\fP\ src\fP,\fP\ mask\fP,\fP\ p )
329 is the standard drawing function.
330 Only those pixels within the intersection of
338 The operation proceeds as follows
339 (this is a description of the behavior, not the implementation):
348 replicate their contents to fill
349 their clip rectangles.
362 to the intersection of
373 is false, also intersect
384 is false, also intersect
395 pixel using the alpha value
401 has an explicit alpha channel, the alpha value
404 pixel is simply that pixel's alpha channel.
405 Otherwise, the alpha value is the NTSC greyscale equivalent
406 of the color value, with white meaning opaque and black transparent.
407 In terms of the Porter-Duff compositing algebra,
417 (In the extended form,
418 ``over'' is replaced by
423 pixel channel formats
424 involved need not be identical.
425 If the channels involved are smaller than 8-bits, they will
426 be promoted before the calculation by replicating the extant bits;
427 after the calculation, they will be truncated to their proper sizes.
429 \f5gendraw(\f2dst\fP, \f2r\fP, \f2src\fP, \f2p0\fP, \f2mask\fP, \f2p1\f5)\fP
434 aligns the source and mask differently:
446 For most purposes with simple masks and source images,
450 is the general operator and the one all other drawing primitives are built upon.
452 .BI drawreplxy( min , max , x\f5)
455 to be in the half-open interval [\fImin\fP, \fImax\fP) by adding
456 or subtracting a multiple of \fImax-min\fP.
458 .BI drawrepl( r , p )
459 Clips the point \fIp\fP to be within the rectangle \fIr\fP
460 by translating the point horizontally by an integer multiple of rectangle width
461 and vertically by the height.
463 .BI replclipr( i , repl , clipr\f5)
464 Because the image data is stored on the server, local modifications to the
466 data structure itself will have no effect.
474 fields, and notifies the server of their modification.
476 \f5line(\f2dst\fP, \f2p0\fP, \f2p1\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
482 pixels joining points
486 The line is drawn using pixels from the
490 in the source corresponds to
493 The line touches both
501 specify how the ends of the line are drawn.
503 terminates the line perpendicularly to the direction of the line; a thick line with
505 on both ends will be a rectangle.
507 terminates the line by drawing a disc of diameter
509 centered on the end point.
511 terminates the line with an arrowhead whose tip touches the endpoint.
515 permits explicit control of the shape of the arrow.
516 If all three parameters are zero, it produces the default arrowhead,
519 sets the distance along line from end of the regular line to tip,
521 sets the distance along line from the barb to the tip,
524 sets the distance perpendicular to the line from edge of line to the tip of the barb,
528 and the other geometrical operators are equivalent to calls to
530 using a mask produced by the geometric procedure.
532 \f5poly(\f2dst\fP, \f2p\fP, \f2np\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
534 draws a general polygon; it
535 is conceptually equivalent to a series of calls to
537 joining adjacent points in the
544 The ends of the polygon are specified as in
546 interior lines are terminated with
548 to make smooth joins.
549 The source is aligned so
554 \f5fillpoly(\f2dst\fP, \f2p\fP, \f2np\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
558 but fills in the resulting polygon rather than outlining it.
559 The source is aligned so
563 The winding rule parameter
565 resolves ambiguities about what to fill if the polygon is self-intersecting.
570 a pixel is inside the polygon if the polygon's winding number about the point
576 a pixel is inside if the winding number is odd.
577 Complementary values (0 or ~1) cause outside pixels to be filled.
578 The meaning of other values is undefined.
579 The polygon is closed with a line if necessary.
581 \f5bezier(\f2dst\fP, \f2a\fP, \f2b\fP, \f2c\fP, \f2d\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
584 cubic Bezier curve defined by
591 The end styles are determined by
595 the thickness of the curve is
597 The source is aligned so
606 \f5bezspline(\f2dst\fP, \f2p\fP, \f2np\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
608 takes the same arguments as
610 but draws a quadratic B-spline (despite its name) rather than a polygon.
611 If the first and last points in
613 are equal, the spline has periodic end conditions.
615 \f5bezsplinepts(\f2pt\fP, \f2npt\fP, \f2pp\fP)
619 a list of points making up the open polygon that
622 The caller is responsible for freeing
625 \f5fillbezier(\f2dst\fP, \f2a\fP, \f2b\fP, \f2c\fP, \f2d\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
634 \f5fillbezspline(\f2dst\fP, \f2p\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
638 but fills the quadratic B-spline rather than the polygon outlined by
640 The spline is closed with a line if necessary.
642 \f5ellipse(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
646 an ellipse centered on
648 with horizontal and vertical semiaxes
652 The source is aligned so
660 The ellipse is drawn with thickness
663 \f5fillellipse(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2src\fP, \f2sp\fP)
667 but fills the ellipse rather than outlining it.
669 \f5arc(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2thick\fP, \f2src\fP, \f2sp\fP, \f2alpha\fP, \f2phi\fP)
673 but draws only that portion of the ellipse starting at angle
675 and extending through an angle of
677 The angles are measured in degrees counterclockwise from the positive
681 \f5fillarc(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2src\fP, \f2sp\fP, \f2alpha\fP, \f2phi\fP)
685 but fills the sector with the source color.
687 \f5icossin(\f2deg\fP, \f2cosp\fP, \f2sinp\fP)
693 scaled integers representing the cosine and sine of the angle
695 measured in integer degrees.
696 The values are scaled so cos(0) is 1024.
698 \f5icossin2(\f2x\fP, \f2y\fP, \f2cosp\fP, \f2sinp\fP)
702 with the angle represented not in degrees but implicitly by the point
713 .BI border( dst\fP,\fP\ r\fP,\fP\ i\fP,\fP\ color\fP,\fP\ sp\fP)
715 draws an outline of rectangle
719 The outline has width
721 if positive, the border goes inside the rectangle; negative, outside.
722 The source is aligned so
727 .BI string( dst\fP,\fP\ p\fP,\fP\ src\fP,\fP\ sp\fP,\fP\ font\fP,\fP\ s )
731 characters specified by the string
735 it is equivalent to a series of calls to
739 and masks determined by the character shapes.
740 The text is positioned with the left of the first character at
742 and the top of the line of text at
744 The source is positioned so
755 that is the position of the next character that would be drawn if the string were longer.
757 For characters with undefined
758 or zero-width images in the font, the character at font position 0 (NUL) is drawn.
760 The other string routines are variants of this basic form, and
761 have names that encode their variant behavior.
762 Routines whose names contain
764 accept a string of Runes rather than
771 that defines the number of characters to draw rather than accepting a NUL-terminated
775 draw the background behind the characters in the specified color
780 normally the text is drawn leaving the background intact.
784 captures all this behavior into a single operator. Whether it draws a
787 or Rune string depends on whether
791 is null (the string length is always determined by
795 is non-null, it is used as a background color.
798 argument allows further management of clipping when drawing the string;
799 it is intersected with the usual clipping rectangles to further limit the extent of the text.
801 .BI drawsetdebug( on )
802 Turns on or off debugging output (usually
803 to a serial line) according to whether
816 ``Compositing Digital Images'',
817 .I "Computer Graphics
818 (Proc. SIGGRAPH), 18:3, pp. 253-259, 1984.
820 These routines call the graphics error function on fatal errors.
822 Anti-aliased characters can be drawn by defining a font
823 with multiple bits per pixel, but there are
824 no anti-aliasing geometric primitives.