ewwwww - fix infinte loop bug... :)

SVN revision: 4152
This commit is contained in:
Carsten Haitzler 2001-01-26 03:29:55 +00:00
parent 9cc5944b2b
commit 45ba00f3fd
2 changed files with 85 additions and 17 deletions

View File

@ -2140,8 +2140,8 @@ span(ImlibImage * im, int y, int x1, int x2, DATA8 r, DATA8 g,
typedef struct _span Span; typedef struct _span Span;
struct _span struct _span
{ {
int x, xstart, ystart, vert; int x, xstart, ystart, vert, xend, yend;
int pol; int pol, point;
double gradient; double gradient;
Span *next; Span *next;
}; };
@ -2231,7 +2231,7 @@ __imlib_draw_polygon_filled(ImlibImage * im, ImlibPoly poly, int clip_xmin,
else dir = -1; else dir = -1;
} }
else dir = -1; else dir = -1;
for (j = 0; j < poly->pointcount; j += dir) for (j = 0; (j != poly->pointcount) && (j != -poly->pointcount); j += dir)
{ {
int pt1, pt2, x1, y1, x2, y2, vert, step; int pt1, pt2, x1, y1, x2, y2, vert, step;
double grad; double grad;
@ -2285,26 +2285,30 @@ __imlib_draw_polygon_filled(ImlibImage * im, ImlibPoly poly, int clip_xmin,
{ {
/* for every scanline this line spans add a span point */ /* for every scanline this line spans add a span point */
s = malloc(sizeof(Span)); s = malloc(sizeof(Span));
if (pol == 1) if (pol == 1) s->x = x + 1;
s->x = x + 1; else s->x = x;
else s->pol = pol;
s->x = x; s->xstart = x1;
s->pol = pol; s->ystart = y1;
s->xstart = x1; s->xend = x2;
s->ystart = y1; s->yend = y2;
s->vert = vert; s->vert = vert;
s->gradient = grad; s->gradient = grad;
s->next = NULL; s->next = NULL;
if ((i == y1) || (i == y2)) s->point = 1;
else s->point = 0;
/* actually add the scan point to the scan list array */ /* actually add the scan point to the scan list array */
if (!spans[i - clip_ymin]) spans[i - clip_ymin] = s; if (!(spans[i - clip_ymin])) spans[i - clip_ymin] = s;
else else
{ {
Span *ps, *ss; Span *ps, *ss;
for (ps = NULL, ss = spans[i - clip_ymin]; ps = NULL;
for (ss = spans[i - clip_ymin];
ss; ss;
ps = ss, ss = ss->next) ss = ss->next)
{ {
if (s->x <= ss->x) if (s->x <= ss->x)
{ {
@ -2313,13 +2317,17 @@ __imlib_draw_polygon_filled(ImlibImage * im, ImlibPoly poly, int clip_xmin,
s->next = ss; s->next = ss;
goto nospans; goto nospans;
} }
ps = ss;
} }
/* last span on line and still not < ss->x */
if (ps) ps->next = s;
nospans: nospans:
} }
} }
if (i == y2) break; if (i == y2) goto nolines;
i += step; i += step;
} }
nolines:
} }
for (i = 0; i < h; i++) for (i = 0; i < h; i++)
{ {
@ -2331,7 +2339,8 @@ __imlib_draw_polygon_filled(ImlibImage * im, ImlibPoly poly, int clip_xmin,
{ {
if ((s->next) && if ((s->next) &&
(s->next->x == s->x) && (s->next->x == s->x) &&
(s->next->pol == s->pol)) (s->next->pol == s->pol)
)
{ {
Span *ss; Span *ss;

View File

@ -73,6 +73,7 @@ int main (int argc, char **argv)
int interactive = 1; int interactive = 1;
int blendtest = 0; int blendtest = 0;
int filter = 0; int filter = 0;
int pol = 0;
int rotate = 0; int rotate = 0;
int rottest = 0; int rottest = 0;
int scaleup = 0; int scaleup = 0;
@ -118,6 +119,7 @@ int main (int argc, char **argv)
printf ("-maxcolors <n>\t\tLimit color allocation count to n colors.\n"); // require parameter nb colors printf ("-maxcolors <n>\t\tLimit color allocation count to n colors.\n"); // require parameter nb colors
printf ("-text\t\tDisplays the text following this option. Need a loaded font.\n"); printf ("-text\t\tDisplays the text following this option. Need a loaded font.\n");
printf ("-font\t\tLoads a font. The parameter must follow the police_name/size format. Example: loading the grunge font at size 18 is : grunge/18.\n\t\tThe XFD font also can be specified. Ex. 'notepad/32,-*--24-*'.\n"); printf ("-font\t\tLoads a font. The parameter must follow the police_name/size format. Example: loading the grunge font at size 18 is : grunge/18.\n\t\tThe XFD font also can be specified. Ex. 'notepad/32,-*--24-*'.\n");
printf ("-poly\t\tPerforms a poly test\n");
printf ("The following options requires a file to work properly.\n"); printf ("The following options requires a file to work properly.\n");
printf ("-textdir\t\tText Direction. 0: L to R, 1: R to L\n"); printf ("-textdir\t\tText Direction. 0: L to R, 1: R to L\n");
printf (" 2: U to D, 3: D to U, 4: angle\n"); printf (" 2: U to D, 3: D to U, 4: angle\n");
@ -155,6 +157,8 @@ int main (int argc, char **argv)
origone = 1; origone = 1;
else if (!strcmp(argv[i], "-blend")) else if (!strcmp(argv[i], "-blend"))
blend = 1; blend = 1;
else if (!strcmp(argv[i], "-poly"))
pol = 1;
else if (!strcmp(argv[i], "-blendtest")) else if (!strcmp(argv[i], "-blendtest"))
{ {
blendtest = 1; blendtest = 1;
@ -344,6 +348,61 @@ int main (int argc, char **argv)
imlib_polygon_add_point(poly3, 350,300); imlib_polygon_add_point(poly3, 350,300);
#define A90 (3.141592654 / 2)
if (pol)
{
Imlib_Image im_bg, im;
int w, h;
int i;
double a, points[8][2];
if (file)
im_bg = imlib_load_image(file);
else
im_bg = imlib_load_image("test_images/bg.png");
imlib_context_set_image(im_bg);
w = imlib_image_get_width();
h = imlib_image_get_height();
XResizeWindow(disp, win, w, h);
XSync(disp, False);
im = imlib_create_image(w, h);
srand(time(NULL));
for (i = 0; i < 8; i++)
{
points[i][0] = (rand()%w) - (w / 2);
points[i][1] = (rand()%h) - (h / 2);
}
a = 0.0;
for (;;)
{
imlib_context_set_image(im);
imlib_blend_image_onto_image(im_bg, 0, 0, 0, w, h, 0, 0, w, h);
poly = imlib_polygon_new();
for (i = 0; i < 8; i++)
{
double xx, yy;
xx = (w / 2) +
(cos(a) * points[i][0]) +
(cos(a + A90) * points[i][1]);
yy = (h / 2) +
(sin(a) * points[i][0]) +
(sin(a + A90) * points[i][1]);
imlib_polygon_add_point(poly, xx, yy);
}
printf("draw angle %3.3f\n", a);
imlib_context_set_color(255, 255, 255, 100);
imlib_image_fill_polygon(poly);
imlib_context_set_color(0, 0, 0, 20);
imlib_image_draw_polygon(poly, 1);
imlib_polygon_free(poly);
imlib_render_image_on_drawable(0, 0);
a += 0.05;
}
}
if (loop) if (loop)
{ {
printf("loop\n"); printf("loop\n");