+void fillPolygon(kPoint *p, int number, int col, unsigned char **image){\r
+ int miny, maxy;\r
+ int cross[16], num;\r
+ int i, j, k, l, m;\r
+ kPoint tpoly[kResolution + 2];\r
+ int tnum;\r
+ double a, b;\r
+\r
+ //copy to temp buffer and detect max/min y-point\r
+ tnum = 0;\r
+ tpoly[tnum].X = p[0].X;\r
+ tpoly[tnum].Y = p[0].Y;\r
+ miny = maxy = tpoly[tnum].Y;\r
+ tnum++;\r
+ for(i = 1; i < number; i++){\r
+ if(p[i].X != tpoly[tnum - 1].X || p[i].Y != tpoly[tnum - 1].Y){\r
+ tpoly[tnum].X = p[i].X;\r
+ tpoly[tnum].Y = p[i].Y;\r
+ if(tpoly[tnum].Y < miny) miny = tpoly[tnum].Y;\r
+ if(tpoly[tnum].Y > maxy) maxy = tpoly[tnum].Y;\r
+ tnum++;\r
+ }\r
+ }\r
+ tpoly[tnum].X = tpoly[0].X;\r
+ tpoly[tnum].Y = tpoly[0].Y;\r
+ tpoly[tnum + 1].X = tpoly[1].X;\r
+ tpoly[tnum + 1].Y = tpoly[1].Y;\r
+\r
+ //detect crossing point of each y-point and draw\r
+ for(j = miny; j <= maxy; j++){\r
+ num = 0;\r
+ for(i = 0; i < tnum; i++){\r
+ //if be parallel to x-axis\r
+ if(tpoly[i].Y == tpoly[i + 1].Y){\r
+ if(tpoly[i].Y == j){\r
+ cross[num] = tpoly[i + 1].X;\r
+ num++;\r
+ }\r
+ }\r
+ //if be parallel to y-axis\r
+ else if(tpoly[i].X == tpoly[i + 1].X){\r
+ if((tpoly[i].Y < j && j <= tpoly[i + 1].Y) ||\r
+ (tpoly[i + 1].Y <= j && j < tpoly[i].Y)){\r
+ cross[num] = tpoly[i].X;\r
+ num++;\r
+ //spearhead: add one more\r
+ if(tpoly[i + 1].Y == j &&\r
+ ((tpoly[i].Y > tpoly[i + 1].Y &&\r
+ tpoly[i + 1].Y < tpoly[i + 2].Y) ||\r
+ (tpoly[i].Y < tpoly[i + 1].Y &&\r
+ tpoly[i + 1].Y > tpoly[i + 2].Y))){\r
+ cross[num] = tpoly[i + 1].X;\r
+ num++;\r
+ }\r