821 lines · 18.9 KB · Text
RawDownload
.TH DRAW 2.SH NAMEImage, draw, gendraw, drawreplxy, drawrepl,replclipr, line, poly, fillpoly, bezier, bezspline, fillbezier, fillbezspline, ellipse,fillellipse, arc, fillarc, icossin, icossin2, border, string, stringn,runestring, runestringn, stringbg, stringnbg, runestringbg,runestringnbg, _string, ARROW, drawsetdebug \- graphics functions.de PB.PP.ft L.nf...SH SYNOPSIS.de PB.PP.ft L.nf...PB#include <u.h>#include <libc.h>#include <draw.h>.PBtypedefstruct Image{	Display	*display;	/* display holding data */	int		id;		/* id of system-held Image */	Rectangle	r;		/* rectangle in data area, local coords */	Rectangle clipr;	/* clipping region */	ulong	chan;	/* pixel channel format descriptor */	int		depth;	/* number of bits per pixel */	int		repl;	/* flag: data replicates to tile clipr */	Screen	*screen;	/* 0 if not a window */	Image	*next;	/* next in list of windows */} Image;.PBtypedef enum{	/* Porter-Duff compositing operators */	Clear	= 0,.sp 0.1	SinD	= 8,	DinS	= 4,	SoutD	= 2,	DoutS	= 1,.sp 0.1	S		= SinD|SoutD,	SoverD	= SinD|SoutD|DoutS,	SatopD	= SinD|DoutS,	SxorD	= SoutD|DoutS,.sp 0.1	D		= DinS|DoutS,	DoverS	= DinS|DoutS|SoutD,	DatopS	= DinS|SoutD,	DxorS	= DoutS|SoutD,	/* == SxorD */.sp 0.1	Ncomp = 12,} Drawop;.PB.PD 0.ta +\w'\fL      'u +\w'\fL    'u +6n +4nvoid	draw(Image *dst, Rectangle r, Image *src,		Image *mask, Point p).PBvoid	drawop(Image *dst, Rectangle r, Image *src,		Image *mask, Point p, Drawop op).PBvoid	gendraw(Image *dst, Rectangle r, Image *src, Point sp,		Image *mask, Point mp).PBvoid	gendrawop(Image *dst, Rectangle r, Image *src, Point sp,		Image *mask, Point mp, Drawop op).PBint	drawreplxy(int min, int max, int x).PBPoint	drawrepl(Rectangle r, Point p).PBvoid	replclipr(Image *i, int repl, Rectangle clipr).PBvoid	line(Image *dst, Point p0, Point p1, int end0, int end1,		int radius, Image *src, Point sp).PBvoid	lineop(Image *dst, Point p0, Point p1, int end0, int end1,		int radius, Image *src, Point sp, Drawop op).PBvoid	poly(Image *dst, Point *p, int np, int end0, int end1,		int radius, Image *src, Point sp).PBvoid	polyop(Image *dst, Point *p, int np, int end0, int end1,		int radius, Image *src, Point sp, Drawop op).PBvoid	fillpoly(Image *dst, Point *p, int np, int wind,		Image *src, Point sp).PBvoid	fillpolyop(Image *dst, Point *p, int np, int wind,		Image *src, Point sp, Drawop op).PBint	bezier(Image *dst, Point p0, Point p1, Point p2, Point p3,		int end0, int end1, int radius, Image *src, Point sp).PBint	bezierop(Image *dst, Point p0, Point p1, Point p2, Point p3,		int end0, int end1, int radius, Image *src, Point sp,		Drawop op).PBint	bezspline(Image *dst, Point *pt, int npt, int end0, int end1,		int radius, Image *src, Point sp).PBint	bezsplineop(Image *dst, Point *pt, int npt, int end0, int end1,		int radius, Image *src, Point sp, Drawop op).PBint	bezsplinepts(Point *pt, int npt, Point **pp).PBint	fillbezier(Image *dst, Point p0, Point p1, Point p2, Point p3,		int w, Image *src, Point sp).PBint	fillbezierop(Image *dst, Point p0, Point p1, Point p2, Point p3,		int w, Image *src, Point sp, Drawop op).PBint	fillbezspline(Image *dst, Point *pt, int npt, int w,		Image *src, Point sp).PBint	fillbezsplineop(Image *dst, Point *pt, int npt, int w,		Image *src, Point sp, Drawop op).PBvoid	ellipse(Image *dst, Point c, int a, int b, int thick,		Image *src, Point sp).PBvoid	ellipseop(Image *dst, Point c, int a, int b, int thick,		Image *src, Point sp, Drawop op).PBvoid	fillellipse(Image *dst, Point c, int a, int b,		Image *src, Point sp).PBvoid	fillellipseop(Image *dst, Point c, int a, int b,		Image *src, Point sp, Drawop op).PBvoid	arc(Image *dst, Point c, int a, int b, int thick,		Image *src, Point sp, int alpha, int phi).PBvoid	arcop(Image *dst, Point c, int a, int b, int thick,		Image *src, Point sp, int alpha, int phi, Drawop op).PBvoid	fillarc(Image *dst, Point c, int a, int b, Image *src,		Point sp, int alpha, int phi).PBvoid	fillarcop(Image *dst, Point c, int a, int b, Image *src,		Point sp, int alpha, int phi, Drawop op).PBint	icossin(int deg, int *cosp, int *sinp).PBint	icossin2(int x, int y, int *cosp, int *sinp).PBvoid	border(Image *dst, Rectangle r, int i, Image *color, Point sp).br.PBPoint	string(Image *dst, Point p, Image *src, Point sp,		Font *f, char *s).PBPoint	stringop(Image *dst, Point p, Image *src, Point sp,		Font *f, char *s, Drawop op).PBPoint	stringn(Image *dst, Point p, Image *src, Point sp,		Font *f, char *s, int len).PBPoint	stringnop(Image *dst, Point p, Image *src, Point sp,		Font *f, char *s, int len, Drawop op).PBPoint	runestring(Image *dst, Point p, Image *src, Point sp,		Font *f, Rune *r).PBPoint	runestringop(Image *dst, Point p, Image *src, Point sp,		Font *f, Rune *r, Drawop op).PBPoint	runestringn(Image *dst, Point p, Image *src, Point sp,		Font *f, Rune *r, int len).PBPoint	runestringnop(Image *dst, Point p, Image *src, Point sp,		Font *f, Rune *r, int len, Drawop op).PBPoint	stringbg(Image *dst, Point p, Image *src, Point sp,		Font *f, char *s, Image *bg, Point bgp).PBPoint	stringbgop(Image *dst, Point p, Image *src, Point sp,		Font *f, char *s, Image *bg, Point bgp, Drawop op).PBPoint	stringnbg(Image *dst, Point p, Image *src, Point sp,		Font *f, char *s, int len, Image *bg, Point bgp).PBPoint	stringnbgop(Image *dst, Point p, Image *src, Point sp,		Font *f, char *s, int len, Image *bg, Point bgp, Drawop op).PBPoint	runestringbg(Image *dst, Point p, Image *src, Point sp,		Font *f, Rune *r, Image *bg, Point bgp).PBPoint	runestringbgop(Image *dst, Point p, Image *src, Point sp,		Font *f, Rune *r, Image *bg, Point bgp, Drawop op).PBPoint	runestringnbg(Image *dst, Point p, Image *src, Point sp,		Font *f, Rune *r, int len, Image *bg, Point bgp).PBPoint	runestringnbgop(Image *dst, Point p, Image *src, Point sp,		Font *f, Rune *r, int len, Image *bg, Point bgp, Drawop op).PBPoint	_string(Image *dst, Point p, Image *src,		Point sp, Font *f, char *s, Rune *r, int len,		Rectangle clipr, Image *bg, Point bgp, Drawop op).PBvoid	drawsetdebug(int on).PD.PBenum{	/* line ends */	Endsquare	= 0,	Enddisc		= 1,	Endarrow	= 2,	Endmask		= 0x1F};.PB#define ARROW(a, b, c) (Endarrow|((a)<<5)|((b)<<14)|((c)<<23)).SH DESCRIPTIONThe.B Imagetype defines rectangular pictures and the methods to draw upon them;it is also the building block for higher level objects such aswindows and fonts.In particular, a window is represented as an.BR Image ;no special operators are needed to draw on a window..PP.TP 10.B rThe coordinates of the rectangle in the plane for which the.B Imagehas defined pixel values.It should not be modified after the image is created..TP.B cliprThe clipping rectangle: operations that read or writethe image will not access pixels outside.BR clipr .Frequently,.B clipris the same as.BR r ,but it may differ; see in particular the discussion of.BR repl .The clipping region may be modified dynamically using.I replclipr.RI ( q.v. )..TP.B chanThe pixel channel format descriptor, as described in.IR image (6).The value should not be modified after the image is created..TP.B depthThenumber of bits per pixel in the picture;it is identically.B chantodepth(chan)(see.IR graphics (2))and is provided as a convenience.The value should not be modified after the image is created..TP.B replA boolean value specifying whether the image is tiled to coverthe plane when used as a source for a drawing operation.If.B replis zero, operations are restricted to the intersection of.B rand.BR clipr .If.B replis set,.B rdefines the tile to be replicated and.B cliprdefines the portion of the plane covered by the tiling, in other words,.B ris replicated to cover.BR clipr ;in such cases.B rand.B cliprare independent..IPFor example, a replicated image with.B rset to ((0,\ 0),\ (1,\ 1)) and.B cliprset to ((0,\ 0),\ (100,\ 100)),with the single pixel of.B rset to blue,behaves identically to an image with.B rand.B cliprboth set to ((0,\ 0),\ (100,\ 100)) and all pixels set to blue.However,the first image requires far less memory.The replication flag may be modified dynamically using.I replclipr.RI ( q.v. )..PPMost of the drawing functions come in two forms:a basic form, and an extended form that takes an extra.B Drawopto specify a Porter-Duff compositing operator to use.The basic forms assume the operator is.BR SoverD ,which suffices for the vast majority of applications.The extended forms are named by adding an.RB - opsuffix to the basic form.Only the basic forms are listed below..TP.BI draw( dst\fP,\fP\ r\fP,\fP\ src\fP,\fP\ mask\fP,\fP\ p ).I Drawis the standard drawing function.Only those pixels within the intersection of.IB dst ->rand.IB dst ->cliprwill be affected;.I drawignores.IB dst ->repl\fR.The operation proceeds as follows(this is a description of the behavior, not the implementation):.RS.IP 1.If.B replis set in.I srcor.IR mask ,replicate their contents to filltheir clip rectangles..IP 2.Translate.I srcand.I maskso.I pis aligned with.IB r .min\fR..IP 3.Set.I rto the intersection of.I rand.IB dst ->r\fR..IP 4.Intersect.I rwith.IB src ->clipr\fR.If.IB src ->replis false, also intersect.I rwith.IB src ->r\fR..IP 5.Intersect.I rwith.IB mask ->clipr\fR.If.IB mask ->replis false, also intersect.I rwith.IB mask ->r\fR..IP 6.For each location in.IR r ,combine the.I dstpixel with the.I srcpixel using the alpha valuecorresponding to the.I maskpixel.If the.I maskhas an explicit alpha channel, the alpha valuecorresponding to the.I maskpixel is simply that pixel's alpha channel.Otherwise, the alpha value is the NTSC greyscale equivalentof the color value, with white meaning opaque and black transparent.In terms of the Porter-Duff compositing algebra,.I drawreplaces the.I dstpixels with.RI ( srcin.IR mask )over.IR dst .(In the extended form,``over'' is replaced by.IR op )..RE.IPThe variouspixel channel formatsinvolved need not be identical.If the channels involved are smaller than 8-bits, they willbe promoted before the calculation by replicating the extant bits;after the calculation, they will be truncated to their proper sizes..TP\f5gendraw(\f2dst\fP, \f2r\fP, \f2src\fP, \f2p0\fP, \f2mask\fP, \f2p1\f5)\fPSimilar to.I drawexcept that.I gendrawaligns the source and mask differently:.I srcis aligned so.I p0corresponds to.IB r .minand.I maskis aligned so.I p1corresponds to.IB r .min .For most purposes with simple masks and source images,.B drawis sufficient, but.B gendrawis the general operator and the one all other drawing primitives are built upon..TP.BI drawreplxy( min ,  max ,  x\f5)Clips.I xto be in the half-open interval [\fImin\fP, \fImax\fP) by addingor subtracting a multiple of \fImax-min\fP..TP.BI drawrepl( r , p )Clips the point \fIp\fP to be within the rectangle \fIr\fPby translating the point horizontally by an integer multiple of rectangle widthand vertically by the height..TP.BI replclipr( i ,  repl ,  clipr\f5)Because the image data is stored on the server, local modifications to the.B Imagedata structure itself will have no effect..I Repcliprmodifies the local.B Imagedata structure's.B repland.B cliprfields, and notifies the server of their modification..TP\f5line(\f2dst\fP, \f2p0\fP, \f2p1\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)Linedraws in.I dsta line of width.RI 1+2* thickpixels joining points.I p0and.IR p1 .The line is drawn using pixels from the.I srcimage aligned so.I spin the source corresponds to.I p0in the destination.The line touches both.I p0and.IR p1 ,and.I end0and.I end1specify how the ends of the line are drawn..B Endsquareterminates the line perpendicularly to the direction of the line; a thick line with

Lines 1–500 of 821.