Charles.Forsyth20060303-partialeea662d19 years agoHistory
909 lines · 23.1 KB · Text
RawDownload
.TH DRAW-IMAGE 2.SH NAMEImage \-pictures and drawing.SH SYNOPSIS.EXinclude	"draw.m";draw := load Draw Draw->PATH; # compositing operatorsSinD:   con 1<<3;DinS:   con 1<<2;SoutD:  con 1<<1;DoutS:  con 1<<0; S:      con SinD|SoutD;SoverD: con SinD|SoutD|DoutS;SatopD: con SinD|DoutS;SxorD:  con SoutD|DoutS; D:      con DinS|DoutS;DoverS: con DinS|DoutS|SoutD;DatopS: con DinS|SoutD;DxorS:  con DoutS|SoutD; Clear:  con 0; Image: adt{    r:          Rect;    clipr:      Rect;    chans:      Chans;    depth:      int;    repl:       int;     display:    ref Display;    screen:     ref Screen;     draw:       fn(dst: self ref Image, r: Rect, src: ref Image,                   mask: ref Image, p: Point);    drawop:       fn(dst: self ref Image, r: Rect, src: ref Image,                   mask: ref Image, p: Point, op: int);    gendraw:    fn(dst: self ref Image, r: Rect, src: ref Image,                   p0: Point, mask: ref Image, p1: Point);    gendrawop:    fn(dst: self ref Image, r: Rect, src: ref Image,                   p0: Point, mask: ref Image, p1: Point, op: int);    line:       fn(dst: self ref Image, p0,p1: Point,                   end0,end1,thick: int,                   src: ref Image, sp: Point);    lineop:       fn(dst: self ref Image, p0,p1: Point,                   end0,end1,thick: int,                   src: ref Image, sp: Point, op: int);    poly:       fn(dst: self ref Image, p: array of Point,                   end0,end1,thick: int,                   src: ref Image, sp: Point);    polyop:       fn(dst: self ref Image, p: array of Point,                   end0,end1,thick: int,                   src: ref Image, sp: Point, op: int);    bezspline:  fn(dst: self ref Image, p: array of Point,                   end0,end1,thick: int,                   src: ref Image, sp: Point);    bezsplineop:  fn(dst: self ref Image, p: array of Point,                   end0,end1,thick: int,                   src: ref Image, sp: Point, op: int);    fillpoly:   fn(dst: self ref Image, p: array of Point,                   wind: int, src: ref Image, sp: Point);    fillpolyop:   fn(dst: self ref Image, p: array of Point,                   wind: int, src: ref Image, sp: Point, op: int);    fillbezspline: fn(dst: self ref Image, p: array of Point,                   wind: int, src: ref Image, sp: Point);    fillbezsplineop: fn(dst: self ref Image, p: array of Point,                   wind: int, src: ref Image, sp: Point, op: int);    ellipse:    fn(dst: self ref Image, c: Point, a, b,                   thick: int, src: ref Image, sp: Point);    ellipseop:    fn(dst: self ref Image, c: Point, a, b,                   thick: int, src: ref Image, sp: Point, op: int);    fillellipse:fn(dst: self ref Image, c: Point, a, b: int,                   src: ref Image, sp: Point);    fillellipseop:fn(dst: self ref Image, c: Point, a, b: int,                   src: ref Image, sp: Point, op: int);    arc:        fn(dst: self ref Image, c: Point, a, b, thick: int,                   src: ref Image, sp: Point, alpha, phi: int);    arcop:      fn(dst: self ref Image, c: Point, a, b, thick: int,                   src: ref Image, sp: Point,                   alpha, phi: int, op: int);    fillarc:    fn(dst: self ref Image, c: Point, a, b: int,                   src: ref Image, sp: Point, alpha, phi: int);    fillarcop:  fn(dst: self ref Image, c: Point, a, b: int,                   src: ref Image, sp: Point,                   alpha, phi: int, op: int);    bezier:     fn(dst: self ref Image, a,b,c,d: Point,                   end0,end1,thick: int,                   src: ref Image, sp: Point);    bezierop:     fn(dst: self ref Image, a,b,c,d: Point,                   end0,end1,thick: int,                   src: ref Image, sp: Point, op: int);    fillbezier: fn(dst: self ref Image, a,b,c,d: Point, wind:int,                   src: ref Image, sp: Point);    fillbezierop: fn(dst: self ref Image, a,b,c,d: Point, wind:int,                   src: ref Image, sp: Point, op: int);    arrow:      fn(a,b,c: int): int;    text:       fn(dst: self ref Image, p: Point, src: ref Image,                   sp: Point, font: ref Font, str: string): Point;    textop:       fn(dst: self ref Image, p: Point, src: ref Image,                   sp: Point, font: ref Font, str: string,                   op: int): Point;    textbg:     fn(dst: self ref Image, p: Point, src: ref Image,                   sp: Point, font: ref Font, str: string,                   bg: ref Image, bgp: Point): Point;    textbgop:     fn(dst: self ref Image, p: Point, src: ref Image,                   sp: Point, font: ref Font, str: string,                   bg: ref Image, bgp: Point, op: int): Point;    border:     fn(dst: self ref Image, r: Rect, i: int,                   src: ref Image, sp: Point);    borderop:     fn(dst: self ref Image, r: Rect, i: int,                   src: ref Image, sp: Point, op: int);     readpixels: fn(src: self ref Image, r: Rect,                   data: array of byte): int;    writepixels:fn(dst: self ref Image, r: Rect,                   data: array of byte): int;    name:       fn(im: self ref Image, s: string, in: int): int;    top:        fn(win: self ref Image);    bottom:     fn(win: self ref Image);    flush:      fn(win: self ref Image, func: int);    origin:     fn(win: self ref Image, log, scr: Point): int;};.EE.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.Off-screen images can have an alpha channel, which gives each pixel an opacityfactor, which in turn allows non-rectangular images to be defined(ie, pixels made fully transparent by the alpha channeldo not appear when the image is displayed).Many drawing operations allow images to be shaped, or partial transparency added, by using the alphachannel of another image as a mask (also called a `matte').There are two functions in.B Imagefor each such operation.One has an.B opsuffix, and takes an explicit image compositing operator:.BR S ,.BR D ,.BR SinD , ...,.BR SoverDand so on.(See the Porter-Duff paper mentioned below for the meaning of each operation.)The other function (without the.B opsuffix) provides as its default operation the most common operation,.BR SoverD ,by which the source image, within its matte, is drawn over the destination image..PPAn.B Imagehas a pixel channel structure as described in.IR colour (6),represented by a value of the.B Chansadt,defined in.IR draw-display (2).The channel structure of an image is fixed when the image is allocated..PP.B Imagehas the following components:.TP 10.B displayTells on which display the image resides..TP.B screenIf the image is a window on a.B Screen(see.IR draw-screen (2)),this field refers to that screen; otherwise it is nil..TP.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 Image.r ,but it may differ; see in particular the discussion of.BR Image.repl .The clipping region may be modified dynamically..TP.B chansThe pixel channel structure of the image; the valueshould not be modified after the image is created..TP.B depthThe number of bits per pixel in the picture:it is simply a convenience since it is necessarily equal to.BR chans.depth() ,and it 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 Image.replis zero, operations are restricted to the intersection of.B Image.rand.BR Image.clipr .If.B Image.replis set,.B Image.rdefines the tile to be replicated and.B Image.cliprdefines the portion of the plane covered by the tiling, in other words,.B Image.ris replicated to cover.BR Image.clipr ;in such cases.B Image.rand.B Image.cliprare independent..IPFor example, a replicated image with.B Image.rset to ((0,\ 0),\ (1,\ 1)) and.B Image.cliprset to ((0,\ 0),\ (100,\ 100)),with the single pixel of.B Image.rset to blue,behaves identically to an image with.B Image.rand.B Image.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 along with the clippingrectangle..TP.IB dst .draw( r\fP,\fP\ src\fP,\fP\ mask\fP,\fP\ p\fP ).PD0.TP.IB dst .drawop( r\fP,\fP\ src\fP,\fP\ mask\fP,\fP\ p\fP,\fP\ op ).PD.B Drawis the standard drawing function.Only those pixels within the intersection of.IB dst .rand.IB dst .cliprwill be affected;.B 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 using the alpha value corresponding to the.I maskpixel.If the.I maskhas an explicit alpha channel, the alpha value corresponding to the.I maskpixel is simply that pixel's alpha channel.Otherwise, the alpha value is the NTSC greyscale equivalent of the colour value,with white meaning opaque and black transparent..RE.IPIn terms of the Porter-Duff compositing algebra,.I drawreplaces the.I dstpixels with.RI ( srcin.IR mask )over.IR dst ..I Drawopis almost identical, but applies the compositing operation.I opinstead:.RI ( srcin.IR mask ).I op.IR dst ..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.For.B drawand.B gendrawonly,if.I maskis nil, no mask is used..TP\f2dst\fP.\f5gendraw(\f2r\fP, \f2src\fP, \f2p0\fP, \f2mask\fP, \f2p1\fP)\fP.PD0.TP\f2dst\fP.\f5gendrawop(\f2r\fP, \f2src\fP, \f2p0\fP, \f2mask\fP, \f2p1\fP\f5, \f2op\fP)\fP.PDSimilar to \f5draw()\fP except that it aligns 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 the other drawing primitives are built upon..TP\f2dst\fP.\f5line(\f2p0\fP, \f2p1\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP).PD0.TP\f2dst\fP.\f5lineop(\f2p0\fP, \f2p1\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP, \f2op\fP).PD.B 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 Draw->Endsquareterminates the line perpendicularly to the direction of the line; a thick line with.B Endsquareon both ends will be a rectangle..B Draw->Enddiscterminates the line by drawing a disc of diameter.RI 1+2* thickcentered on the end point..B Draw->Endarrowterminates the line with an arrowhead whose tip touches the endpoint.See the description of.B arrowfor more information..IP.B Lineand the other geometrical operators are equivalent to calls to.B gendrawusing a mask produced by the geometric procedure..TP\f2dst\fP.\f5poly(\f2p\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP).PD0.TP\f2dst\fP.\f5polyop(\f2p\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP, \f2op\fP).PD.B Polydraws a general polygon; itis equivalent to a series of calls to.B linejoining adjacent points in the array of.B Points.IR p .The ends of the polygon are specified as in.BR line ;interior lines are terminated with.B Enddiscto make smooth joins.The source is aligned so.I spcorresponds to.IB p [0]\f1..TP\f2dst\fP.\f5bezspline(\f2p\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP).PD0.TP\f2dst\fP.\f5bezsplineop(\f2p\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP, \f2op\fP).PD.B Bezsplinetakes the same arguments as.B polybut draws a quadratic B-spline (despite its name) rather than a polygon.If the first and last points in.I pare equal, the spline has periodic end conditions..TP\f2dst\fP.\f5fillpoly(\f2p\fP, \f2wind\fP, \f2src\fP, \f2sp\fP).PD0.TP\f2dst\fP.\f5fillpolyop(\f2p\fP, \f2wind\fP, \f2src\fP, \f2sp\fP, \f2op\fP).PD.B Fillpolyis like.B polybut fills in the resulting polygon rather than outlining it.The source is aligned so.I spcorresponds to.IB p [0]\f1.The winding rule parameter.I windresolves ambiguities about what to fill if the polygon is self-intersecting.If.I windis.BR ~0 ,

Lines 1–500 of 909.