summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f8d2244)
raw | patch | inline | side by side (parent: f8d2244)
author | ishmal <ishmal@users.sourceforge.net> | |
Tue, 28 Feb 2006 23:16:27 +0000 (23:16 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Tue, 28 Feb 2006 23:16:27 +0000 (23:16 +0000) |
index 9b08f2d377251c08e11b2e3df4cebe50b36da175..5744335182ab33fb6cca068eb4368665158ab0f2 100644 (file)
struct privcurve_s {
int n; /* number of segments */
int *tag; /* tag[n]: POTRACE_CORNER or POTRACE_CURVETO */
- dpoint_t (*c)[3]; /* c[n][i]: control points.
+ dpoint_t (*c)[3]; /* c[n][i]: control points.
c[n][0] is unused for tag[n]=POTRACE_CORNER */
+ /* the remainder of this structure is special to privcurve, and is
+ used in EPS debug output and special EPS "short coding". These
+ fields are valid only if "alphacurve" is set. */
+ int alphacurve; /* have the following fields been initialized? */
dpoint_t *vertex; /* for POTRACE_CORNER, this equals c[1] */
double *alpha; /* only for POTRACE_CURVETO */
double *alpha0; /* "uncropped" alpha parameter - for debug output only */
index 7c88068f02c6f9b76a38fbdf7c1cb62947bcdd6d..512d9f4fe92adc6c9cf3d9e91da3c0c3f0a554f6 100644 (file)
int xhi = x & -BM_WORDBITS;
int xlo = x & (BM_WORDBITS-1); /* = x % BM_WORDBITS */
int i;
-
+
if (xhi<xa) {
for (i = xhi; i < xa; i+=BM_WORDBITS) {
*bm_index(bm, i, y) ^= BM_ALLBITS;
@@ -183,11 +183,13 @@ static path_t *findpath(potrace_bitmap_t *bm, int x0, int y0, int sign, int turn
len = size = 0;
pt = NULL;
area = 0;
-
+
while (1) {
/* add point to path */
if (len>=size) {
size+=100;
+ //size*=1.3;
+ size = size * 13 / 10;
pt1 = (point_t *)realloc(pt, size * sizeof(point_t));
if (!pt1) {
goto error;
@@ -197,21 +199,21 @@ static path_t *findpath(potrace_bitmap_t *bm, int x0, int y0, int sign, int turn
pt[len].x = x;
pt[len].y = y;
len++;
-
+
/* move to next point */
x += dirx;
y += diry;
area += x*diry;
-
+
/* path complete? */
if (x==x0 && y==y0) {
break;
}
-
+
/* determine next direction */
c = BM_GET(bm, x + (dirx+diry-1)/2, y + (diry-dirx-1)/2);
d = BM_GET(bm, x + (dirx-diry-1)/2, y + (diry+dirx-1)/2);
-
+
if (c && !d) { /* ambiguous turn */
if (turnpolicy == POTRACE_TURNPOLICY_RIGHT
|| (turnpolicy == POTRACE_TURNPOLICY_BLACK && sign == '+')
@@ -250,10 +252,10 @@ static path_t *findpath(potrace_bitmap_t *bm, int x0, int y0, int sign, int turn
p->sign = sign;
return p;
-
+
error:
free(pt);
- return NULL;
+ return NULL;
}
/* Give a tree structure to the given path list, based on "insideness"
path_t *head;
path_t **hook, **hook_in, **hook_out; /* for fast appending to linked list */
bbox_t bbox;
-
+
bm_clear(bm, 0);
/* save original "next" pointers */
p->sibling = p->next;
p->childlist = NULL;
}
-
+
heap = plist;
/* the heap holds a list of lists of paths. Use "childlist" field
cur = heap;
heap = heap->childlist;
cur->childlist = NULL;
-
+
/* unlink first path */
head = cur;
cur = cur->next;
heap = head->childlist;
}
}
-
+
/* copy sibling structure from "next" to "sibling" component */
p = plist;
while (p) {
/* p is a positive path */
/* append to linked list */
list_insert_beforehook(p, hook);
-
+
/* go through its children */
for (p1=p->childlist; p1; p1=p1->sibling) {
/* append to linked list */
@@ -439,7 +441,7 @@ int bm_to_pathlist(const potrace_bitmap_t *bm, path_t **plistp, const potrace_pa
/* iterate through components */
y = bm1->h - 1;
- while (findnext(bm1, &x, &y) == 0) {
+ while (findnext(bm1, &x, &y) == 0) {
/* calculate the sign by looking at the original */
sign = BM_GET(bm, x, y) ? '+' : '-';
index a51afd81e5e9637ebc8aa48991508165de335d0f..c86c0e4c205406b8cc74b894a0aa3c03f32de472 100644 (file)
potrace_param_t *potrace_param_default() {
potrace_param_t *p;
- p = (potrace_param_t *) malloc(sizeof(potrace_param_t));
+ p = (potrace_param_t *) malloc(sizeof(potrace_param_t *));
if (!p) {
return NULL;
}
potrace_state_t *st;
progress_t prog;
progress_t subprog;
-
+
/* prepare private progress bar state */
prog.callback = param->progress.callback;
prog.data = param->progress.data;
st->status = POTRACE_STATUS_OK;
st->plist = plist;
+ st->priv = NULL;
progress_subrange_end(&prog, &subprog);
index 78388d3e9d12847f57f1f454208de86c8c811312..ae9f756b023f01c0f2362612fdddd093df0ffcec 100644 (file)
a,n are integers and n>0. */
#define SAFE_MALLOC(var, n, typ) \
- if ((var = (typ *)malloc((n)*sizeof(typ))) == NULL) goto malloc_error
+ if ((var = (typ *)malloc((n)*sizeof(typ))) == NULL) goto malloc_error
/* ---------------------------------------------------------------------- */
/* auxiliary functions */
but then restricted to one of the major wind directions (n, nw, w, etc) */
static inline point_t dorth_infty(dpoint_t p0, dpoint_t p2) {
point_t r;
-
+
r.y = sign(p2.x-p0.x);
r.x = -sign(p2.y-p0.y);
@@ -100,21 +100,21 @@ static void pointslope(privpath_t *pp, int i, int j, dpoint_t *ctr, dpoint_t *di
i+=n;
r+=1;
}
-
+
x = sums[j+1].x-sums[i].x+r*sums[n].x;
y = sums[j+1].y-sums[i].y+r*sums[n].y;
x2 = sums[j+1].x2-sums[i].x2+r*sums[n].x2;
xy = sums[j+1].xy-sums[i].xy+r*sums[n].xy;
y2 = sums[j+1].y2-sums[i].y2+r*sums[n].y2;
k = j+1-i+r*n;
-
+
ctr->x = x/k;
ctr->y = y/k;
a = (x2-(double)x*x/k)/k;
b = (xy-(double)x*y/k)/k;
c = (y2-(double)y*y/k)/k;
-
+
lambda2 = (a+c+sqrt((a-c)*(a-c)+4*b*b))/2; /* larger e.value */
/* now find e.vector for lambda2 */
@@ -240,7 +240,7 @@ static double tangent(dpoint_t p0, dpoint_t p1, dpoint_t p2, dpoint_t p3, dpoint
a = A - 2*B + C;
b = -2*A + 2*B;
c = A;
-
+
d = b*b - 4*a*c;
if (a==0 || d<0) {
pp->sums[i+1].xy = pp->sums[i].xy + x*y;
pp->sums[i+1].y2 = pp->sums[i].y2 + y*y;
}
- return 0;
+ return 0;
malloc_error:
return 1;
/* determine pivot points: for each i, let pivk[i] be the furthest k
such that all j with i<j<k lie on a line connecting i,k. */
-
+
for (i=n-1; i>=0; i--) {
ct[0] = ct[1] = ct[2] = ct[3] = 0;
k = nc[i];
k1 = i;
while (1) {
-
+
dir = (3+3*sign(pt[k].x-pt[k1].x)+sign(pt[k].y-pt[k1].y))/2;
ct[dir]++;
if (xprod(constraint[1], off) <= 0) {
constraint[1] = off;
}
- }
+ }
k1 = k;
k = nc[k1];
if (!cyclic(k,i,k1)) {
/* ---------------------------------------------------------------------- */
-/* Stage 2: calculate the optimal polygon (Sec. 2.2.2-2.2.4). */
+/* Stage 2: calculate the optimal polygon (Sec. 2.2.2-2.2.4). */
/* Auxiliary function: calculate the penalty of an edge from i to j in
the given path. This needs the "lon" and "sum*" data. */
j-=n;
r+=1;
}
-
+
x = sums[j+1].x-sums[i].x+r*sums[n].x;
y = sums[j+1].y-sums[i].y+r*sums[n].y;
x2 = sums[j+1].x2-sums[i].x2+r*sums[n].x2;
xy = sums[j+1].xy-sums[i].xy+r*sums[n].xy;
y2 = sums[j+1].y2-sums[i].y2+r*sums[n].y2;
k = j+1-i+r*n;
-
+
px = (pt[i].x+pt[j].x)/2.0-pt[0].x;
py = (pt[i].y+pt[j].y)/2.0-pt[0].y;
ey = (pt[j].x-pt[i].x);
a = ((x2-2*x*px)/k+px*px);
b = ((xy-x*py-y*px)/k+px*py);
c = ((y2-2*y*py)/k+py*py);
-
+
s = ex*ex*a + 2*ex*ey*b + ey*ey*c;
return sqrt(s);
is in the polygon. Fixme: ### implement cyclic version. */
static int bestpolygon(privpath_t *pp)
{
- int i, j, m, k;
+ int i, j, m, k;
int n = pp->len;
double *pen = NULL; /* pen[n+1]: penalty vector */
int *prev = NULL; /* prev[n+1]: best path pointer vector */
free(seg0);
free(seg1);
return 0;
-
+
malloc_error:
free(pen);
free(prev);
if (r) {
goto malloc_error;
}
-
+
/* calculate "optimal" point-slope representation for each line
segment */
for (i=0; i<m; i++) {
Q[l][k] = q[j][l][k] + q[i][l][k];
}
}
-
+
while(1) {
/* minimize the quadratic form Q on the unit square */
/* find intersection */
/* work around gcc bug #12243 */
free(NULL);
#endif
-
+
det = Q[0][0]*Q[1][1] - Q[0][1]*Q[1][0];
if (det != 0.0) {
w.x = (-Q[0][2]*Q[1][1] + Q[1][2]*Q[0][1]) / det;
curve->alpha[j] = alpha; /* store the "cropped" value of alpha */
curve->beta[j] = 0.5;
}
-
+ curve->alphacurve = 1;
return 0;
}
@@ -962,8 +962,8 @@ static int opti_penalty(privpath_t *pp, int i, int j, opti_t *res, double opttol
A2 = dpara(p0, p1, p3);
A3 = dpara(p0, p2, p3);
/* A4 = dpara(p1, p2, p3); */
- A4 = A1+A3-A2;
-
+ A4 = A1+A3-A2;
+
if (A2 == A1) { /* this should never happen */
return 1;
}
@@ -971,7 +971,7 @@ static int opti_penalty(privpath_t *pp, int i, int j, opti_t *res, double opttol
t = A3/(A3-A4);
s = A2/(A2-A1);
A = A2 * t / 2.0;
-
+
if (A == 0.0) { /* this should never happen */
return 1;
}
i1 = mod(i+1,om);
pp->ocurve.beta[i] = s[i] / (s[i] + t[i1]);
}
+ pp->ocurve.alphacurve = 1;
free(pt);
free(pen);
@@ -1200,7 +1201,7 @@ int process_path(path_t *plist, const potrace_param_t *param, progress_t *progre
}
cn = 0;
}
-
+
/* call downstream function with each path */
list_forall (p, plist) {
TRY(calc_sums(p->priv));