gdImagePtr im = (gdImagePtr) job->surface;
pointf p0, p1, V[4];
int i, j, step, pen;
+ boolean pen_ok, fill_ok;
gdImagePtr brush = NULL;
gdPoint F[4];
return;
pen = gdgen_set_penstyle(job, im, brush);
- if (pen == gdImageGetTransparent(im))
- return;
-
- V[3] = A[0];
- PF2P(A[0], F[0]);
- PF2P(A[n-1], F[3]);
- for (i = 0; i + 3 < n; i += 3) {
- V[0] = V[3];
- for (j = 1; j <= 3; j++)
- V[j] = A[i + j];
- p0 = V[0];
- for (step = 1; step <= BEZIERSUBDIVISION; step++) {
- p1 = Bezier(V, 3, (double) step / BEZIERSUBDIVISION, NULL, NULL);
- PF2P(p0, F[1]);
- PF2P(p1, F[2]);
- gdImageLine(im, F[1].x, F[1].y, F[2].x, F[2].y, pen);
- if (filled)
- gdImageFilledPolygon(im, F, 4, obj->fillcolor.u.index);
- p0 = p1;
- }
+ pen_ok = (pen != gdImageGetTransparent(im));
+ fill_ok = (filled && obj->fillcolor.u.index != gdImageGetTransparent(im));
+
+ if (pen_ok || fill_ok) {
+ V[3] = A[0];
+ PF2P(A[0], F[0]);
+ PF2P(A[n-1], F[3]);
+ for (i = 0; i + 3 < n; i += 3) {
+ V[0] = V[3];
+ for (j = 1; j <= 3; j++)
+ V[j] = A[i + j];
+ p0 = V[0];
+ for (step = 1; step <= BEZIERSUBDIVISION; step++) {
+ p1 = Bezier(V, 3, (double) step / BEZIERSUBDIVISION, NULL, NULL);
+ PF2P(p0, F[1]);
+ PF2P(p1, F[2]);
+ if (pen_ok)
+ gdImageLine(im, F[1].x, F[1].y, F[2].x, F[2].y, pen);
+ if (fill_ok)
+ gdImageFilledPolygon(im, F, 4, obj->fillcolor.u.index);
+ p0 = p1;
+ }
+ }
}
if (brush)
gdImageDestroy(brush);
}
+static gdPoint *points;
+static int points_allocated;
+
static void gdgen_polygon(GVJ_t * job, pointf * A, int n, int filled)
{
obj_state_t *obj = job->obj;
gdImagePtr im = (gdImagePtr) job->surface;
gdImagePtr brush = NULL;
int i;
- gdPoint *points;
int pen;
+ boolean pen_ok, fill_ok;
if (!im)
return;
pen = gdgen_set_penstyle(job, im, brush);
- if (pen == gdImageGetTransparent(im))
- return;
+ pen_ok = (pen != gdImageGetTransparent(im));
+ fill_ok = (filled && obj->fillcolor.u.index != gdImageGetTransparent(im));
- points = malloc(n * sizeof(gdPoint));
- for (i = 0; i < n; i++) {
- points[i].x = ROUND(A[i].x);
- points[i].y = ROUND(A[i].y);
+ if (pen_ok || fill_ok) {
+ if (n > points_allocated) {
+ points = realloc(points, n * sizeof(gdPoint));
+ points_allocated = n;
+ }
+ for (i = 0; i < n; i++) {
+ points[i].x = ROUND(A[i].x);
+ points[i].y = ROUND(A[i].y);
+ }
+ if (fill_ok)
+ gdImageFilledPolygon(im, points, n, obj->fillcolor.u.index);
+
+ if (pen_ok)
+ gdImagePolygon(im, points, n, pen);
}
- if (filled)
- gdImageFilledPolygon(im, points, n, obj->fillcolor.u.index);
-
- gdImagePolygon(im, points, n, pen);
- free(points);
if (brush)
gdImageDestroy(brush);
}
gdImagePtr im = (gdImagePtr) job->surface;
double dx, dy;
int pen;
+ boolean pen_ok, fill_ok;
gdImagePtr brush = NULL;
if (!im)
return;
pen = gdgen_set_penstyle(job, im, brush);
-fprintf(stderr,"ellipse pen=%d\n", pen);
- if (pen == gdImageGetTransparent(im))
- return;
+ pen_ok = (pen != gdImageGetTransparent(im));
+ fill_ok = (filled && obj->fillcolor.u.index != gdImageGetTransparent(im));
dx = 2 * (A[1].x - A[0].x);
dy = 2 * (A[1].y - A[0].y);
- if (filled)
+ if (fill_ok)
gdImageFilledEllipse(im, ROUND(A[0].x), ROUND(A[0].y),
ROUND(dx), ROUND(dy),
obj->fillcolor.u.index);
- gdImageArc(im, ROUND(A[0].x), ROUND(A[0].y), ROUND(dx), ROUND(dy),
- 0, 360, pen);
+ if (pen_ok)
+ gdImageArc(im, ROUND(A[0].x), ROUND(A[0].y), ROUND(dx), ROUND(dy),
+ 0, 360, pen);
if (brush)
gdImageDestroy(brush);
}
pointf p, p1;
int i;
int pen;
+ boolean pen_ok;
gdImagePtr brush = NULL;
if (!im)
return;
pen = gdgen_set_penstyle(job, im, brush);
- if (pen == gdImageGetTransparent(im))
- return;
-
- p = A[0];
- for (i = 1; i < n; i++) {
- p1 = A[i];
- gdImageLine(im, ROUND(p.x), ROUND(p.y),
- ROUND(p1.x), ROUND(p1.y), pen);
- p = p1;
+ pen_ok = (pen != gdImageGetTransparent(im));
+
+ if (pen_ok) {
+ p = A[0];
+ for (i = 1; i < n; i++) {
+ p1 = A[i];
+ gdImageLine(im, ROUND(p.x), ROUND(p.y),
+ ROUND(p1.x), ROUND(p1.y), pen);
+ p = p1;
+ }
}
if (brush)
gdImageDestroy(brush);