From 37da2899f40661e3e9631e497da8dc59b971cbd0 Mon Sep 17 00:00:00 2001 From: "Charles.Forsyth" Date: Fri, 22 Dec 2006 17:07:39 +0000 Subject: 20060303a --- libdraw/poly.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 libdraw/poly.c (limited to 'libdraw/poly.c') diff --git a/libdraw/poly.c b/libdraw/poly.c new file mode 100644 index 00000000..ec643690 --- /dev/null +++ b/libdraw/poly.c @@ -0,0 +1,86 @@ +#include "lib9.h" +#include "draw.h" + +static +uchar* +addcoord(uchar *p, int oldx, int newx) +{ + int dx; + + dx = newx-oldx; + /* does dx fit in 7 signed bits? */ + if((unsigned)(dx - -0x40) <= 0x7F) + *p++ = dx&0x7F; + else{ + *p++ = 0x80 | (newx&0x7F); + *p++ = newx>>7; + *p++ = newx>>15; + } + return p; +} + +static +void +dopoly(int cmd, Image *dst, Point *pp, int np, int end0, int end1, int radius, Image *src, Point *sp, Drawop op) +{ + uchar *a, *t, *u; + int i, ox, oy; + + if(np == 0) + return; + t = malloc(np*2*3); + if(t == nil) + return; + u = t; + ox = oy = 0; + for(i=0; idisplay, op); + + a = bufimage(dst->display, 1+4+2+4+4+4+4+2*4+(u-t)); + if(a == 0){ + free(t); + _drawprint(2, "image poly: %r\n"); + return; + } + a[0] = cmd; + BPLONG(a+1, dst->id); + BPSHORT(a+5, np-1); + BPLONG(a+7, end0); + BPLONG(a+11, end1); + BPLONG(a+15, radius); + BPLONG(a+19, src->id); + BPLONG(a+23, sp->x); + BPLONG(a+27, sp->y); + memmove(a+31, t, u-t); + free(t); +} + +void +poly(Image *dst, Point *p, int np, int end0, int end1, int radius, Image *src, Point sp) +{ + dopoly('p', dst, p, np, end0, end1, radius, src, &sp, SoverD); +} + +void +polyop(Image *dst, Point *p, int np, int end0, int end1, int radius, Image *src, Point sp, Drawop op) +{ + dopoly('p', dst, p, np, end0, end1, radius, src, &sp, op); +} + +void +fillpoly(Image *dst, Point *p, int np, int wind, Image *src, Point sp) +{ + dopoly('P', dst, p, np, wind, 0, 0, src, &sp, SoverD); +} + +void +fillpolyop(Image *dst, Point *p, int np, int wind, Image *src, Point sp, Drawop op) +{ + dopoly('P', dst, p, np, wind, 0, 0, src, &sp, op); +} -- cgit v1.2.3