From: Koichi KAMICHI Date: Mon, 29 Mar 2004 08:51:02 +0000 (+0000) Subject: Replace to original source for polygon drawing. X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=79e4363ccbdd740f3f70cbf7feee81cfb914bc6a;p=chise%2Fkage.git Replace to original source for polygon drawing. No need to use xlib(X11). --- diff --git a/kagecgi/Makefile b/kagecgi/Makefile index 39330de..9500ba6 100755 --- a/kagecgi/Makefile +++ b/kagecgi/Makefile @@ -13,12 +13,12 @@ DBURL=http://fonts.jp/kagedb/kagedb #LIBS= -L/usr/local/lib -lpng -ldb -lglib-2.0 #for linux -CFLAGS= -I/usr/local/include -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/X11R6/include -LIBS= -L/usr/local/lib -lpng -ldb -lglib-2.0 -L/usr/X11R6/lib -lX11 +CFLAGS= -I/usr/local/include -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include +LIBS= -L/usr/local/lib -lpng -ldb -lglib-2.0 #for MacOSX with fink -#CFLAGS= -I/sw/include -I/sw/include/glib-2.0 -I/sw/lib/glib-2.0/include/ -I/sw/include/libpng/ -I/usr/include -I/usr/X11R6/include/ -#LIBS= -L/sw/lib -lpng -lglib-2.0 -L/usr/lib -ldbm -L/usr/X11R6/lib -lX11 +#CFLAGS= -I/sw/include -I/sw/include/db3 -I/sw/include/glib-2.0 -I/sw/lib/glib-2.0/include/ -I/sw/include/libpng/ -I/usr/include +#LIBS= -L/sw/lib -lpng -lglib-2.0 -L/usr/lib -ldb all: kage.cgi diff --git a/kagecgi/README.en b/kagecgi/README.en index dba7588..c39d2a2 100644 --- a/kagecgi/README.en +++ b/kagecgi/README.en @@ -11,7 +11,6 @@ KAGE/cgi needs following librarys: - Berkely DB 3 - libpng - glib2.0 - - xlib CONFIGURATION diff --git a/kagecgi/kage.h b/kagecgi/kage.h index ee352c7..56f96ce 100755 --- a/kagecgi/kage.h +++ b/kagecgi/kage.h @@ -29,8 +29,6 @@ struct kPoint{ double Y; }; -XPoint xpoly[kResolution]; - struct kPoint poly[kResolution]; struct kPoint poly2[3]; struct kPoint poly3[5]; diff --git a/kagecgi/kagepoly.c b/kagecgi/kagepoly.c index 571ca15..b5fe2a4 100755 --- a/kagecgi/kagepoly.c +++ b/kagecgi/kagepoly.c @@ -3,26 +3,102 @@ #include "kage.h" #include "kagecgi.h" -#include "sysdep.h" void fillPolygon(struct kPoint *p, int number, int col, unsigned char **image){ - int i, ix, iy; - Region rgn; - XRectangle rect; - - for(i = 0; i < number; i++){ - xpoly[i].x = p[i].X; - xpoly[i].y = p[i].Y; + int miny, maxy; + int cross[16], num; + int i, j, k, l, m; + double a, b; + + miny = 10000; + maxy = -10000; + //detect max/min y-point + for(i = 0; i < number; i++){ + if(p[i].Y < miny) miny = p[i].Y; + if(p[i].Y > maxy) maxy = p[i].Y; + //fprintf(stderr,"%.1f:%.1f\n",p[i].X,p[i].Y); + } + //detect crossing point of each y-point and draw + for(j = miny; j <= maxy; j++){ + num = 0; + for(i = 0; i < number; i++){ + //if two points are tha same position, do nothing + if(p[i].X == p[(i + 1) % number].X && + p[i].Y == p[(i + 1) % number].Y) continue; + //if be parallel to x-axis + if(p[i].Y == p[(i + 1) % number].Y){ + if(p[i].Y == j){ + cross[num] = p[(i + 1) % number].X; + //fprintf(stderr,"[%d]",cross[num]); + num++; + } + } + //if be parallel to y-axis + else if(p[i].X == p[(i + 1) % number].X){ + if((p[i].Y < j && j <= p[(i + 1) % number].Y) || + (p[(i + 1) % number].Y <= j && j < p[i].Y)){ + cross[num] = p[i].X; + //fprintf(stderr,"[%d]",cross[num]); + num++; + //spearhead: add one more + if(p[(i + 1) % number].Y == j && + ((p[i].Y > p[(i + 1) % number].Y && + p[(i + 1) % number].Y < p[(i + 2) % number].Y) || + (p[i].Y < p[(i + 1) % number].Y && + p[(i + 1) % number].Y > p[(i + 2) % number].Y))){ + cross[num] = p[(i + 1) % number].X; + //fprintf(stderr,"[%d]",cross[num]); + num++; + //fprintf(stderr,"(add:%d)",j); + } + } + } + //detect crossing point of each vector + else if((p[i].Y < j && j <= p[(i + 1) % number].Y) || + (p[(i + 1) % number].Y <= j && j < p[i].Y)){ + a = (p[(i + 1) % number].Y - p[i].Y) + / (p[(i + 1) % number].X - p[i].X); + b = p[i].Y - a * p[i].X; + cross[num] = (j - b) / a; + //fprintf(stderr,"[%d]",cross[num]); + num++; + //spearhead: add one more + if(p[(i + 1) % number].Y == j && + ((p[i].Y > p[(i + 1) % number].Y && + p[(i + 1) % number].Y < p[(i + 2) % number].Y) || + (p[i].Y < p[(i + 1) % number].Y && + p[(i + 1) % number].Y > p[(i + 2) % number].Y))){ + cross[num] = p[(i + 1) % number].X; + //fprintf(stderr,"[%d]",cross[num]); + num++; + //fprintf(stderr,"(add:%d)",j); + } + } + } + if(num != 0){ + if(num % 2 != 0)fprintf(stderr,"y:%d(%d)\n",j,num); + //if(num != 0 && num % 2 == 0){ + //sort crossing point + for(k = 0; k < num - 1; k++){ + for(l = num - 1; l > k; l--){ + if(cross[l] < cross[l - 1]){ + m = cross[l]; + cross[l] = cross[l - 1]; + cross[l - 1] = m; + } } - rgn = XPolygonRegion(xpoly, number, EvenOddRule); - XClipBox(rgn, &rect); - - for(ix = rect.x ; ix <= rect.x + rect.width; ix++){ - for(iy = rect.y ; iy <= rect.y + rect.height; iy++){ - if(XPointInRegion(rgn, ix, iy) && ix >= 0 && iy >= 0 && ix < canvasWidth && iy < canvasHeight){ - image[iy][ix] = col; - } - } + } + //for(k=0;k -#include -#include - #include