#include "common.h"#include "bits.h"#include "memgfx.h"#include "gfxPoly.h"Include dependency graph for mgPolygon.c:

Go to the source code of this file.
Defines | |
| #define | UPDIR 1 |
| #define | DOWNDIR 0 |
Functions | |
| void | mgDrawPolyOutline (struct memGfx *mg, struct gfxPoly *poly, Color color) |
| static void | find_pminmax (struct gfxPoly *poly) |
| static void | xor_pt (int bpr, int x, int y) |
| static void | y_xor_line (int bpr, int x1, int y1, int x2, int y2) |
| static void | drawAfterOnOff (struct memGfx *mg, Color color, int bpr, int width, int height) |
| static void | fillConcave (struct memGfx *mg, struct gfxPoly *poly, Color color) |
| void | mgDrawPoly (struct memGfx *mg, struct gfxPoly *poly, Color color, boolean filled) |
Variables | |
| static UBYTE * | on_off_buf |
| static int | pxmin |
| static int | pxmax |
| static int | pymin |
| static int | pymax |
| #define DOWNDIR 0 |
| #define UPDIR 1 |
| static void drawAfterOnOff | ( | struct memGfx * | mg, | |
| Color | color, | |||
| int | bpr, | |||
| int | width, | |||
| int | height | |||
| ) | [static] |
Definition at line 150 of file mgPolygon.c.
References bitFindSet(), mgLineH(), on_off_buf, pxmin, pymin, UBYTE, and gfxPoint::y.
Referenced by fillConcave().
00153 { 00154 UBYTE *linept = on_off_buf; 00155 int y; 00156 00157 for (y=0; y<height; ++y) 00158 { 00159 int start = 0; 00160 int end; 00161 for (;;) 00162 { 00163 start = bitFindSet(linept, start, width); 00164 if (start >= width) 00165 break; 00166 end = bitFindSet(linept, start+1, width); 00167 mgLineH(mg, y+pymin, start+pxmin, end+pxmin, color); 00168 start = end+1; 00169 } 00170 linept += bpr; 00171 } 00172 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 174 of file mgPolygon.c.
References DOWNDIR, drawAfterOnOff(), find_pminmax(), freez(), mgLineH(), needMem(), gfxPoint::next, on_off_buf, gfxPoly::ptCount, gfxPoly::ptList, pxmax, pxmin, pymax, pymin, UPDIR, gfxPoint::x, xor_pt(), gfxPoint::y, and y_xor_line().
Referenced by mgDrawPoly().
00176 { 00177 struct gfxPoint *pointpt; 00178 int x,y; 00179 int ox,oy; 00180 int lastdir; 00181 int i; 00182 int bpr; /* Bytes per row */ 00183 int width, height; 00184 long size; 00185 00186 find_pminmax(poly); 00187 if (pymin==pymax) /*Complex code can't cope with trivial case*/ 00188 { 00189 mgLineH(mg, pymin, pxmin, pxmax,color); 00190 return; 00191 } 00192 width = pxmax - pxmin + 1; 00193 height = pymax - pymin + 1; 00194 bpr = ((width+7)>>3); 00195 size = (long)bpr*height; 00196 if ((on_off_buf = needMem(size)) == NULL) 00197 return; 00198 pointpt = poly->ptList; 00199 x = pointpt->x; 00200 y = pointpt->y; 00201 00202 do 00203 { 00204 pointpt = pointpt->next; 00205 ox = pointpt->x; 00206 oy = pointpt->y; 00207 } 00208 while (oy == y); 00209 00210 if (oy>y) 00211 lastdir = UPDIR; 00212 else 00213 lastdir = DOWNDIR; 00214 00215 i = poly->ptCount; 00216 while (--i >= 0) 00217 { 00218 pointpt = pointpt->next; 00219 x = pointpt->x; 00220 y = pointpt->y; 00221 if (y!=oy) 00222 { 00223 y_xor_line(bpr,ox-pxmin,oy-pymin,x-pxmin,y-pymin); 00224 if (y>oy) 00225 if (lastdir == UPDIR) 00226 xor_pt(bpr,ox-pxmin,oy-pymin); 00227 else 00228 lastdir = UPDIR; 00229 else 00230 if (lastdir == DOWNDIR) 00231 xor_pt(bpr,ox-pxmin,oy-pymin); 00232 else 00233 lastdir = DOWNDIR; 00234 } 00235 ox = x; 00236 oy = y; 00237 } 00238 00239 drawAfterOnOff(mg, color, bpr, width, height); 00240 freez(&on_off_buf); 00241 return; 00242 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void find_pminmax | ( | struct gfxPoly * | poly | ) | [static] |
Definition at line 44 of file mgPolygon.c.
References gfxPoint::next, gfxPoly::ptCount, gfxPoly::ptList, pxmax, pxmin, pymax, pymin, gfxPoint::x, and gfxPoint::y.
Referenced by fillConcave().
00045 { 00046 struct gfxPoint *pointpt; 00047 int i; 00048 00049 pointpt = poly->ptList; 00050 pxmin = pxmax = pointpt->x; 00051 pymin = pymax = pointpt->y; 00052 pointpt = pointpt->next; 00053 00054 i = poly->ptCount; 00055 while (--i > 0) 00056 { 00057 if (pxmin > pointpt->x) pxmin = pointpt->x; 00058 if (pxmax < pointpt->x) pxmax = pointpt->x; 00059 if (pymin > pointpt->y) pymin = pointpt->y; 00060 if (pymax < pointpt->y) pymax = pointpt->y; 00061 pointpt = pointpt->next; 00062 } 00063 }
Here is the caller graph for this function:

Definition at line 426 of file mgPolygon.c.
References fillConcave(), and mgDrawPolyOutline().
Referenced by vgMgMethods().
00429 { 00430 if (filled) 00431 fillConcave(mg, poly, color); 00432 // mgDrawPolyFilled(mg, poly, color); 00433 mgDrawPolyOutline(mg, poly, color); 00434 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 15 of file mgPolygon.c.
References mgDrawLine(), gfxPoint::next, gfxPoly::ptList, gfxPoint::x, and gfxPoint::y.
Referenced by mgDrawPoly().
00017 { 00018 struct gfxPoint *a, *b, *end; 00019 00020 a = end = poly->ptList; 00021 b = a->next; 00022 for (;;) 00023 { 00024 mgDrawLine(mg, a->x, a->y, b->x, b->y, color); 00025 a = b; 00026 b = b->next; 00027 if (a == end) 00028 break; 00029 } 00030 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void xor_pt | ( | int | bpr, | |
| int | x, | |||
| int | y | |||
| ) | [static] |
Definition at line 65 of file mgPolygon.c.
References on_off_buf, and UBYTE.
Referenced by fillConcave().
00067 { 00068 UBYTE rot; 00069 00070 rot = ((unsigned)0x80) >> (x&7); 00071 on_off_buf[ bpr*y + (x>>3) ] ^= rot; 00072 }
Here is the caller graph for this function:

| static void y_xor_line | ( | int | bpr, | |
| int | x1, | |||
| int | y1, | |||
| int | x2, | |||
| int | y2 | |||
| ) | [static] |
Definition at line 75 of file mgPolygon.c.
References dots, on_off_buf, and UBYTE.
Referenced by fillConcave().
00077 { 00078 UBYTE *imagept = on_off_buf; 00079 UBYTE rot; 00080 int duty_cycle; 00081 int delta_x, delta_y; 00082 int dots; 00083 int swap; 00084 00085 if (x1 > x2) 00086 { 00087 swap = x1; 00088 x1 = x2; 00089 x2 = swap; 00090 swap = y1; 00091 y1 = y2; 00092 y2 = swap; 00093 } 00094 delta_y = y2-y1; 00095 delta_x = x2-x1; 00096 rot = ((unsigned)0x80) >> (x1&7); 00097 imagept += bpr*y1 + (x1>>3); 00098 00099 00100 if (delta_y < 0) 00101 { 00102 delta_y = -delta_y; 00103 bpr = -bpr; 00104 } 00105 duty_cycle = (delta_x - delta_y)/2; 00106 *(imagept) ^= rot; 00107 if (delta_x < delta_y) 00108 { 00109 dots = delta_y; 00110 while (--dots >= 0) 00111 { 00112 *(imagept) ^= rot; 00113 duty_cycle += delta_x; /* update duty cycle */ 00114 imagept += bpr; 00115 if (duty_cycle > 0) 00116 { 00117 duty_cycle -= delta_y; 00118 rot >>= 1; 00119 if (rot == 0) 00120 { 00121 imagept++; 00122 rot = 0x80; 00123 } 00124 } 00125 } 00126 } 00127 else 00128 { 00129 dots = delta_x; 00130 while (--dots >= 0) 00131 { 00132 duty_cycle -= delta_y; /* update duty cycle */ 00133 if (duty_cycle < 0) 00134 { 00135 *(imagept) ^= rot; 00136 duty_cycle += delta_x; 00137 imagept += bpr; 00138 } 00139 rot >>= 1; 00140 if (rot == 0) 00141 { 00142 imagept++; 00143 rot = 0x80; 00144 } 00145 } 00146 } 00147 }
Here is the caller graph for this function:

UBYTE* on_off_buf [static] |
Definition at line 40 of file mgPolygon.c.
Referenced by drawAfterOnOff(), fillConcave(), xor_pt(), and y_xor_line().
int pxmax [static] |
int pxmin [static] |
Definition at line 42 of file mgPolygon.c.
Referenced by drawAfterOnOff(), fillConcave(), and find_pminmax().
int pymax [static] |
int pymin [static] |
Definition at line 42 of file mgPolygon.c.
Referenced by drawAfterOnOff(), fillConcave(), and find_pminmax().
1.5.2