Removed unused scanline fill code. :^/

This commit is contained in:
William Kendrick 2005-01-14 08:21:53 +00:00
parent 46cd85a3c1
commit ab09f3bd59
2 changed files with 2 additions and 478 deletions

View file

@ -180,7 +180,8 @@ http://www.newbreedsoftware.com/tuxpaint/
Albert Cahalan <albert@users.sf.net>
Bill Kendrick <bill@newbreedsoftware.com>
* Gave up on 'HQ4X' scaler, for the time being. (Removed unused code.)
* Gave up on 'HQ4X' scaler and scanline polygon filling, for the
time being. (i.e., removed unused code.)
* Documentation updates:
----------------------

View file

@ -2218,12 +2218,6 @@ static int do_png_save(FILE * fi, const char * const fname, SDL_Surface * surf);
static void get_new_file_id(void);
static int do_quit(void);
static int do_open(int want_new_tool);
#ifdef SCAN_FILL
static void scan_fill(int cnt, point_type * pts);
#endif
#ifdef SCANLINE_POLY_FILL
static int clip_polygon(int n, fpoint_type * pin, fpoint_type * pout);
#endif
static void wait_for_sfx(void);
static int stamp_colorable(int stamp);
static int stamp_tintable(int stamp);
@ -11671,14 +11665,7 @@ static void do_shape(int cx, int cy, int ox, int oy, int rotn, int use_brush)
int side, angle_skip, init_ang, rx, ry, rmax, x1, y1, x2, y2, xp, yp,
old_brush, step;
float a1, a2, rotn_rad;
#ifdef SCAN_FILL
point_type pts[1024]; /* Careful! */
fpoint_type fpts_orig[1024], fpts_new[1024];
int i;
int num_pts;
#else
int xx;
#endif
/* Determine radius/shape of the shape to draw: */
@ -11725,11 +11712,6 @@ static void do_shape(int cx, int cy, int ox, int oy, int rotn, int use_brush)
init_ang = shape_init_ang[cur_shape];
#ifdef SCAN_FILL
num_pts = 0;
#endif
step = 1;
if (dont_do_xor && !use_brush)
@ -11796,30 +11778,11 @@ static void do_shape(int cx, int cy, int ox, int oy, int rotn, int use_brush)
brush_draw(x1, y1, x2, y2, 0);
}
#ifdef SCAN_FILL
fpts_orig[num_pts].x = (float) x2;
fpts_orig[num_pts].y = (float) y2;
num_pts++;
#endif
}
if (use_brush && shape_filled[cur_shape])
{
#ifdef SCAN_FILL
/* FIXME: This is all broken!!! */
num_pts = clip_polygon(num_pts, fpts_orig, fpts_new);
for (i = 0; i < num_pts; i++)
{
pts[i].x = (int) (fpts_new[i].x);
pts[i].y = (int) (fpts_new[i].y);
}
scan_fill(num_pts, pts);
#else
/* FIXME: In the meantime, we'll do this lame radius-based fill: */
for (xx = abs(rx); xx >= 0; xx--)
@ -11872,7 +11835,6 @@ static void do_shape(int cx, int cy, int ox, int oy, int rotn, int use_brush)
if (xx % 10 == 0)
update_canvas(0, 0, WINDOW_WIDTH - 96, (48 * 7) + 40 + HEIGHTOFFSET);
}
#endif
}
@ -13510,445 +13472,6 @@ static int do_open(int want_new_tool)
return(want_new_tool);
}
/* -------------- Poly Fill Stuff -------------- */
#ifdef SCANLINE_POLY_FILL
static void insert_edge(edge * list, edge * edg)
{
edge * p, * q;
debug("insert_edge()");
q = list;
p = q->next;
while (p != NULL)
{
if (edg->x_intersect < p->x_intersect)
{
p = NULL;
}
else
{
q = p;
p = p->next;
}
}
edg->next = q->next;
q->next = edg;
}
static int y_next(int k, int cnt, point_type * pts)
{
int j;
debug("y_next()");
if ((k + 1) > (cnt - 1))
j = 0;
else
j = k + 1;
while (pts[k].y == pts[j].y)
{
if ((j + 1) > (cnt - 1))
j = 0;
else
j++;
}
return (pts[j].y);
}
static void make_edge_rec(point_type lower, point_type upper,
int y_comp, edge * edg, edge * edges[])
{
debug("make_edge_rec()");
edg->dx_per_scan = (float)((upper.x - lower.x) / (upper.y - lower.y));
edg->x_intersect = lower.x;
if (upper.y < y_comp)
edg->y_upper = upper.y - 1;
else
edg->y_upper = upper.y;
insert_edge(edges[lower.y], edg);
}
static void build_edge_list(int cnt, point_type * pts, edge * edges[])
{
edge * edg;
point_type v1, v2;
int i, y_prev;
debug("build_edge_list()");
y_prev = pts[cnt - 2].y;
v1.x = pts[cnt - 1].x;
v1.y = pts[cnt - 1].y;
for (i = 0; i < cnt; i++)
{
v2 = pts[i];
if (v1.y != v2.y)
{
edg = (edge *) malloc(sizeof(edge));
if (v1.y < v2.y)
make_edge_rec(v1, v2, y_next(i, cnt, pts), edg, edges);
else
make_edge_rec(v2, v1, y_prev, edg, edges);
}
y_prev = v1.y;
v1 = v2;
}
}
static void build_active_list(int scan, edge * active, edge * edges[])
{
edge * p, * q;
debug("build_active_list()");
p = edges[scan]->next;
while (p != NULL)
{
q = p->next;
insert_edge(active, p);
p = q;
}
}
static void fill_scan(int scan, edge * active)
{
edge * p1, * p2;
int i;
Uint32 color;
void (*putpixel)(SDL_Surface *, int, int, Uint32) = putpixels[canvas->format->BytesPerPixel];
debug("fill_scan()");
color = SDL_MapRGB(canvas->format,
color_hexes[cur_color][0] / 2,
color_hexes[cur_color][1] / 2,
color_hexes[cur_color][2] / 2);
SDL_LockSurface(canvas);
p1 = active->next;
while (p1 != NULL)
{
p2 = p1->next;
for (i = p1->x_intersect; i < p2->x_intersect; i++)
{
putpixel(canvas, i, scan, color);
}
p1 = p2->next;
}
SDL_UnlockSurface(canvas);
}
static void delete_after(edge * q)
{
edge * p;
debug("delete_after()");
p = q->next;
q->next = p->next;
free(p);
}
static void update_active_list(int scan, edge * active)
{
edge * q, * p;
debug("update_active_list()");
q = active;
p = active->next;
while (p != NULL)
{
if (scan >= p->y_upper)
{
p = p->next;
delete_after(q);
}
else
{
p->x_intersect = p->x_intersect + p->dx_per_scan;
q = p;
p = p->next;
}
}
}
static void resort_active_list(edge * active)
{
edge * q, * p;
debug("resort_active_list()");
p = active->next;
active->next = NULL;
while (p != NULL)
{
q = p->next;
insert_edge(active, p);
p = q;
}
}
static void scan_fill(int cnt, point_type * pts)
{
/* edge * edges[48 * 7 + 40 + HEIGHTOFFSET + 5], * active; */
edge * * edges = alloca((48 * 7 + 40 + HEIGHTOFFSET + 5) * sizeof(edge*)),
* active;
int i, scan;
debug("scan_fill()");
/* Create empty edges: */
for (i = 0; i < 48 * 7 + 40 + HEIGHTOFFSET + 5; i++)
{
edges[i] = (edge *) malloc(sizeof(edge));
edges[i]->next = NULL;
}
/* Build edge list: */
build_edge_list(cnt, pts, edges);
/* Set active edge: */
active = (edge *) malloc(sizeof(edge));
active->next = NULL;
/* Scan! */
for (scan = 0; scan < 48 * 7 + 40 + HEIGHTOFFSET; scan++)
{
build_active_list(scan, active, edges);
if (active->next)
{
fill_scan(scan, active);
update_canvas(0, scan, WINDOW_WIDTH - 96, scan);
SDL_Flip(screen);
SDL_Delay(10);
update_active_list(scan, active);
resort_active_list(active);
}
}
/* Free edge list: */
debug("Freeing...");
for (i = 0; i < 48 * 7 + 40 + HEIGHTOFFSET; i++)
{
free(edges[i]);
}
}
/* ------------- Poly clipping stuff: -------------- */
static int inside(fpoint_type p, an_edge b)
{
if (b == Left)
{
if (p.x < 0)
return 0;
}
else if (b == Right)
{
if (p.x >= WINDOW_WIDTH - 96)
return 0;
}
else if (b == Bottom)
{
if (p.y >= 48 * 7 + 40 + HEIGHTOFFSET)
return 0;
}
else if (b == Top)
{
if (p.y < 0)
return 0;
}
return 1;
}
static int cross(fpoint_type p1, fpoint_type p2, an_edge b)
{
if (inside(p1, b) == inside(p2, b))
return 0;
else
return 1;
}
static fpoint_type intersect(fpoint_type p1, fpoint_type p2, an_edge b)
{
fpoint_type ipt;
float m;
if (p1.x != p2.x)
m = (p1.y - p2.y) / (p1.x - p2.x);
else
m = 1.0;
if (b == Left)
{
ipt.x = 0;
ipt.y = p2.y + (-p2.x) * m;
}
else if (b == Right)
{
ipt.x = WINDOW_WIDTH - 96 - 1;
ipt.y = p2.y + ((WINDOW_WIDTH - 96 - 1) - p2.x) * m;
}
else if (b == Top)
{
ipt.y = 0;
if (p1.x != p2.x)
ipt.x = p2.x + (-p2.y) / m;
else
ipt.x = p2.x;
}
else if (b == Bottom)
{
ipt.y = (48 * 7 + 40 + HEIGHTOFFSET) - 1;
if (p1.x != p2.x)
ipt.x = p2.x + (((48 * 7 + 40 + HEIGHTOFFSET) - 1) - p2.y) / m;
else
ipt.x = p2.x;
}
return(ipt);
}
static void clip_point(fpoint_type p, an_edge b, fpoint_type * pout, int * cnt,
fpoint_type * first[], fpoint_type * s)
{
fpoint_type ipt;
if (first[b] == NULL)
{
first[b] = &p;
}
else
{
if (cross(p, s[b], b))
{
ipt = intersect(p, s[b], b);
if (b < Top) /* Should be NUM_EDGES? */
{
clip_point(ipt, b + 1, pout, cnt, first, s);
}
else
{
pout[*cnt] = ipt;
(*cnt)++;
}
}
}
s[b] = p;
if (inside(p, b))
{
if (b < Top) /* Should be NUM_EDGES? */
{
clip_point(p, b + 1, pout, cnt, first, s);
}
else
{
pout[*cnt] = p;
(*cnt)++;
}
}
}
static void close_clip(fpoint_type * pout, int * cnt, fpoint_type * first[],
fpoint_type * s)
{
fpoint_type i;
an_edge b;
for (b = Left; b <= Top; b++)
{
if (cross(s[b], *first[b], b))
{
i = intersect(s[b], *first[b], b);
if (b < Top)
{
clip_point(i, b + 1, pout, cnt, first, s);
}
else
{
pout[*cnt] = i;
(*cnt)++;
}
}
}
}
static int clip_polygon(int n, fpoint_type * pin, fpoint_type * pout)
{
fpoint_type * first[NUM_EDGES] = {0, 0, 0, 0};
fpoint_type s[NUM_EDGES];
int i, cnt;
cnt = 0;
for (i = 0; i < n; i++)
{
clip_point(pin[i], Left, pout, &cnt, first, s);
}
close_clip(pout, &cnt, first, s);
return(cnt);
}
#endif
/* Let sound effects (e.g., "Save" sfx) play out before quitting... */