summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1b3e44c)
raw | patch | inline | side by side (parent: 1b3e44c)
author | ishmal <ishmal@users.sourceforge.net> | |
Fri, 26 Oct 2007 21:01:30 +0000 (21:01 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Fri, 26 Oct 2007 21:01:30 +0000 (21:01 +0000) |
18 files changed:
diff --git a/src/trace/.cvsignore b/src/trace/.cvsignore
--- a/src/trace/.cvsignore
+++ /dev/null
@@ -1,4 +0,0 @@
-.deps
-.dirstamp
-makefile
-
diff --git a/src/trace/potrace/.cvsignore b/src/trace/potrace/.cvsignore
+++ /dev/null
@@ -1,3 +0,0 @@
-.deps
-.dirstamp
-
index 18573ad53ec14861ff73e8cdfb6b2e17b3958665..7baab851cff36d7d6eb4b6bcc1f55b2dfb09062f 100644 (file)
-/* Copyright (C) 2001-2005 Peter Selinger.
- This file is part of potrace. It is free software and it is covered
+/* Copyright (C) 2001-2007 Peter Selinger.
+ This file is part of Potrace. It is free software and it is covered
by the GNU General Public License. See the file COPYING for details. */
/* This header file collects some general-purpose macros (and static
#ifndef AUXILIARY_H
#define AUXILIARY_H
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
/* ---------------------------------------------------------------------- */
/* point arithmetic */
}
/* ---------------------------------------------------------------------- */
+/* some useful macros. Note: the "mod" macro works correctly for
+ negative a. Also note that the test for a>=n, while redundant,
+ speeds up the mod function by 70% in the average case (significant
+ since the program spends about 16% of its time here - or 40%
+ without the test). The "floordiv" macro returns the largest integer
+ <= a/n, and again this works correctly for negative a, as long as
+ a,n are integers and n>0. */
+
/* integer arithmetic */
static inline int mod(int a, int n) {
}
/* Note: the following work for integers and other numeric types. */
+#undef sign
+#undef abs
+#undef min
+#undef max
+#undef sq
+#undef cu
#define sign(x) ((x)>0 ? 1 : (x)<0 ? -1 : 0)
#define abs(a) ((a)>0 ? (a) : -(a))
#define min(a,b) ((a)<(b) ? (a) : (b))
index f55762f289baff1a57249ef49e56272dde6333ea..2a172b1ad6a416490bae36ba483b51df08e9cb44 100644 (file)
-/* Copyright (C) 2001-2005 Peter Selinger.
- This file is part of potrace. It is free software and it is covered
+/* Copyright (C) 2001-2007 Peter Selinger.
+ This file is part of Potrace. It is free software and it is covered
by the GNU General Public License. See the file COPYING for details. */
#ifndef BITMAP_H
#define BITMAP_H
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <string.h>
#include <stdlib.h>
index 89b6ee5fd872186664e290067430b83234679d59..c9a6fbe047268ca4204f3b492012dce50f62ce28 100644 (file)
-/* Copyright (C) 2001-2005 Peter Selinger.
- This file is part of potrace. It is free software and it is covered
+/* Copyright (C) 2001-2007 Peter Selinger.
+ This file is part of Potrace. It is free software and it is covered
by the GNU General Public License. See the file COPYING for details. */
/* $Id$ */
/* private part of the path and curve data structures */
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "potracelib.h"
#include "lists.h"
#include "curve.h"
return NULL;
}
+/* free the members of the given curve structure. Leave errno unchanged. */
+static void privcurve_free_members(privcurve_t *curve) {
+ free(curve->tag);
+ free(curve->c);
+ free(curve->vertex);
+ free(curve->alpha);
+ free(curve->alpha0);
+ free(curve->beta);
+}
+
/* free a path. Leave errno untouched. */
void path_free(path_t *p) {
if (p) {
return 1;
}
-/* free the members of the given curve structure */
-void privcurve_free_members(privcurve_t *curve) {
- free(curve->tag);
- free(curve->c);
- free(curve->vertex);
- free(curve->alpha);
- free(curve->alpha0);
- free(curve->beta);
-}
-
/* copy private to public curve structure */
void privcurve_to_curve(privcurve_t *pc, potrace_curve_t *c) {
c->n = pc->n;
index 5744335182ab33fb6cca068eb4368665158ab0f2..45c0790bee3139f70c519b95dd81fa47372e5d15 100644 (file)
-/* Copyright (C) 2001-2005 Peter Selinger.
- This file is part of potrace. It is free software and it is covered
+/* Copyright (C) 2001-2007 Peter Selinger.
+ This file is part of Potrace. It is free software and it is covered
by the GNU General Public License. See the file COPYING for details. */
#ifndef CURVE_H
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
/* the path structure is filled in with information about a given path
as it is accumulated and passed through the different stages of the
- potrace algorithm. Backends only need to read the fcurve and fm
+ Potrace algorithm. Backends only need to read the fcurve and fm
fields of this data structure, but debugging backends may read
other fields. */
struct potrace_privpath_s {
void path_free(path_t *p);
void pathlist_free(path_t *plist);
int privcurve_init(privcurve_t *curve, int n);
-void privcurve_free_members(privcurve_t *curve);
void privcurve_to_curve(privcurve_t *pc, potrace_curve_t *c);
#endif /* CURVE_H */
index 512d9f4fe92adc6c9cf3d9e91da3c0c3f0a554f6..15c39825ecf45cb7dab386453fa27ce0d95ae0cb 100644 (file)
-/* Copyright (C) 2001-2005 Peter Selinger.
- This file is part of potrace. It is free software and it is covered
+/* Copyright (C) 2001-2007 Peter Selinger.
+ This file is part of Potrace. It is free software and it is covered
by the GNU General Public License. See the file COPYING for details. */
/* $Id$ */
+#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <limits.h>
+#include "potracelib.h"
+#include "curve.h"
#include "lists.h"
+#include "auxiliary.h"
#include "bitmap.h"
#include "decompose.h"
+#include "progress.h"
/* ---------------------------------------------------------------------- */
/* auxiliary bitmap manipulations */
/* ---------------------------------------------------------------------- */
/* auxiliary functions */
-/* return a "random" value which deterministically depends on x,y */
+/* deterministically and efficiently hash (x,y) into a pseudo-random bit */
static inline int detrand(int x, int y) {
- srand(x+123456789*y);
- return rand();
+ unsigned int z;
+ static const unsigned char t[256] = {
+ /* non-linear sequence: constant term of inverse in GF(8),
+ mod x^8+x^4+x^3+x+1 */
+ 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1,
+ 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0,
+ 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
+ 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1,
+ 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0,
+ 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0,
+ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0,
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1,
+ 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0,
+ 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1,
+ 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
+ };
+
+ /* 0x04b3e375 and 0x05a8ef93 are chosen to contain every possible
+ 5-bit sequence */
+ z = ((0x04b3e375 * x) ^ y) * 0x05a8ef93;
+ z = t[z & 0xff] ^ t[(z>>8) & 0xff] ^ t[(z>>16) & 0xff] ^ t[(z>>24) & 0xff];
+ return z & 1;
}
/* return the "majority" value of bitmap bm at intersection (x,y). We
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,13 +209,12 @@ 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;
+ size += 100;
+ size = (int)(1.3 * size);
pt1 = (point_t *)realloc(pt, size * sizeof(point_t));
if (!pt1) {
goto error;
@@ -199,26 +224,26 @@ 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 == '+')
|| (turnpolicy == POTRACE_TURNPOLICY_WHITE && sign == '-')
- || (turnpolicy == POTRACE_TURNPOLICY_RANDOM && (detrand(x,y) & 1))
+ || (turnpolicy == POTRACE_TURNPOLICY_RANDOM && detrand(x,y))
|| (turnpolicy == POTRACE_TURNPOLICY_MAJORITY && majority(bm, x, y))
|| (turnpolicy == POTRACE_TURNPOLICY_MINORITY && !majority(bm, x, y))) {
tmp = dirx; /* right turn */
@@ -252,10 +277,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 */
@@ -441,7 +466,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 346b7866a2e466bfdf6245c78bfbfaf925c344a4..5552fa0a1426ed71a852f4bf4ad8133eaad79ba9 100644 (file)
-/* Copyright (C) 2001-2005 Peter Selinger.
- This file is part of potrace. It is free software and it is covered
+/* Copyright (C) 2001-2007 Peter Selinger.
+ This file is part of Potrace. It is free software and it is covered
by the GNU General Public License. See the file COPYING for details. */
/* $Id$ */
#define DECOMPOSE_H
#include "potracelib.h"
-#include "curve.h"
#include "progress.h"
int bm_to_pathlist(const potrace_bitmap_t *bm, path_t **plistp, const potrace_param_t *param, progress_t *progress);
index 7d46304cda1fda6f7751d5f4722d5b88176e4247..53c703aa406a686e5f72acfec49e0e278ab1adc7 100644 (file)
-/* Copyright (C) 2001-2005 Peter Selinger.
- This file is part of potrace. It is free software and it is covered
+/* Copyright (C) 2001-2007 Peter Selinger.
+ This file is part of Potrace. It is free software and it is covered
by the GNU General Public License. See the file COPYING for details. */
/* $Id$ */
}
/* reset padding boundary */
-static void bmp_pad_reset() {
+static void bmp_pad_reset(void) {
bmp_count = 0;
}
although most specifications only allow 1,4,8,24,32. We can also
read both the old and new OS/2 BMP formats in addition to the
Windows BMP format. */
-int gm_readbody_bmp(FILE *f, greymap_t **gmp) {
+static int gm_readbody_bmp(FILE *f, greymap_t **gmp) {
bmp_info_t bmpinfo;
int *coltable;
unsigned int b, c;
index 816566205747fdd6fa72a764d7bc98836dba3ec1..05e01667d7173589494e58bc3e227668b1c32ed4 100644 (file)
-/* Copyright (C) 2001-2005 Peter Selinger.
- This file is part of potrace. It is free software and it is covered
+/* Copyright (C) 2001-2007 Peter Selinger.
+ This file is part of Potrace. It is free software and it is covered
by the GNU General Public License. See the file COPYING for details. */
/* $Id$ */
index fe689e4c568f33c23dc39f06610cf04f43468be6..fc853398a2db4903d4b46f2181b7961649b0c778 100644 (file)
-/* Copyright (C) 2001-2005 Peter Selinger.
- This file is part of potrace. It is free software and it is covered
+/* Copyright (C) 2001-2007 Peter Selinger.
+ This file is part of Potrace. It is free software and it is covered
by the GNU General Public License. See the file COPYING for details. */
/* $Id$ */
index efd9b14d284dc49f11a7a710d789f72ffffaa4bd..215d3b457cc7cd48ec355dc26b51c6b77bf7e2d2 100644 (file)
-/* Copyright (C) 2001-2005 Peter Selinger.
- This file is part of potrace. It is free software and it is covered
+/* Copyright (C) 2001-2007 Peter Selinger.
+ This file is part of Potrace. It is free software and it is covered
by the GNU General Public License. See the file COPYING for details. */
#include <stdlib.h>
#include <string.h>
+#include "potracelib.h"
+#include "curve.h"
#include "decompose.h"
#include "trace.h"
+#include "progress.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
/* Return a fresh copy of the set of default parameters, or NULL on
failure with errno set. */
-potrace_param_t *potrace_param_default() {
+potrace_param_t *potrace_param_default(void) {
potrace_param_t *p;
p = (potrace_param_t *) malloc(sizeof(potrace_param_t));
return p;
}
-/* On success, returns a potrace state st with st->status ==
- POTRACE_STATUS_OK. On failure, returns NULL if no potrace state
- could be created (with errno set), or returns an incomplete potrace
+/* On success, returns a Potrace state st with st->status ==
+ POTRACE_STATUS_OK. On failure, returns NULL if no Potrace state
+ could be created (with errno set), or returns an incomplete Potrace
state (with st->status == POTRACE_STATUS_INCOMPLETE). Complete or
- incomplete potrace state can be freed with potrace_state_free(). */
+ incomplete Potrace state can be freed with potrace_state_free(). */
potrace_state_t *potrace_trace(const potrace_param_t *param, const potrace_bitmap_t *bm) {
int r;
path_t *plist = 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;
+ st->priv = NULL; /* private state currently unused */
progress_subrange_end(&prog, &subprog);
return st;
}
-/* free a potrace state, without disturbing errno. */
+/* free a Potrace state, without disturbing errno. */
void potrace_state_free(potrace_state_t *st) {
pathlist_free(st->plist);
free(st);
free(p);
}
-char *potrace_version() {
+char *potrace_version(void) {
return "potracelib "VERSION"";
}
index 141f1d3be016d3042ae2e9a18266e72aa543582a..0b93d65deba09e691c3a9c8d2233ce389f06491c 100644 (file)
-/* Copyright (C) 2001-2005 Peter Selinger.
- This file is part of potrace. It is free software and it is covered
+/* Copyright (C) 2001-2007 Peter Selinger.
+ This file is part of Potrace. It is free software and it is covered
by the GNU General Public License. See the file COPYING for details. */
#ifndef POTRACELIB_H
#define POTRACELIB_H
-/* this file defines the API for the core potrace library. For a more
+/* this file defines the API for the core Potrace library. For a more
detailed description of the API, see doc/potracelib.txt */
/* ---------------------------------------------------------------------- */
/* API functions */
/* get default parameters */
-potrace_param_t *potrace_param_default();
+potrace_param_t *potrace_param_default(void);
/* free parameter set */
void potrace_param_free(potrace_param_t *p);
potrace_state_t *potrace_trace(const potrace_param_t *param,
const potrace_bitmap_t *bm);
-/* free a potrace state */
+/* free a Potrace state */
void potrace_state_free(potrace_state_t *st);
/* return a static plain text version string identifying this version
of potracelib */
-char *potrace_version();
+char *potrace_version(void);
#endif /* POTRACELIB_H */
index 3f617c4d1dfc049169d2e148bd8c2eb6a6c01581..0e077430d7f168e2cfd2141e44aff6fe0f7a4a3d 100644 (file)
-/* Copyright (C) 2001-2005 Peter Selinger.
- This file is part of potrace. It is free software and it is covered
+/* Copyright (C) 2001-2007 Peter Selinger.
+ This file is part of Potrace. It is free software and it is covered
by the GNU General Public License. See the file COPYING for details. */
/* operations on potrace_progress_t objects, which are defined in
index 78b15fc6065e1599a2af569eb17da1b51a1766aa..f9183b9315c641cc9e582d1667819f5d1c5b1e36 100644 (file)
-/* Copyright (C) 2001-2005 Peter Selinger.
- This file is part of potrace. It is free software and it is covered
+/* Copyright (C) 2001-2007 Peter Selinger.
+ This file is part of Potrace. It is free software and it is covered
by the GNU General Public License. See the file COPYING for details. */
/* $Id$ */
+#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "render.h"
+#include "greymap.h"
#include "auxiliary.h"
/* ---------------------------------------------------------------------- */
index 0d3835c9e4da3f078169c2e8065c176124863571..9c9d921d2b21f1d238ec63ffa2ce96d5fe85d3b2 100644 (file)
-/* Copyright (C) 2001-2005 Peter Selinger.
- This file is part of potrace. It is free software and it is covered
+/* Copyright (C) 2001-2007 Peter Selinger.
+ This file is part of Potrace. It is free software and it is covered
by the GNU General Public License. See the file COPYING for details. */
/* $Id$ */
index ae9f756b023f01c0f2362612fdddd093df0ffcec..909ffb7128336c2ba4e38cd9f3921e96f5a4d1e4 100644 (file)
-/* Copyright (C) 2001-2005 Peter Selinger.
- This file is part of potrace. It is free software and it is covered
+/* Copyright (C) 2001-2007 Peter Selinger.
+ This file is part of Potrace. It is free software and it is covered
by the GNU General Public License. See the file COPYING for details. */
/* $Id$ */
/* transform jaggy paths into smooth curves */
+#include <stdio.h>
#include <math.h>
#include <stdlib.h>
+#include <string.h>
+#include "potracelib.h"
#include "curve.h"
#include "lists.h"
+#include "auxiliary.h"
+#include "trace.h"
#include "progress.h"
#define INFTY 10000000 /* it suffices that this is longer than any
#define COS179 -0.999847695156 /* the cosine of 179 degrees */
/* ---------------------------------------------------------------------- */
-/* some useful macros. Note: the "mod" macro works correctly for
- negative a. Also note that the test for a>=n, while redundant,
- speeds up the mod function by 70% in the average case (significant
- since the program spends about 16% of its time here - or 40%
- without the test). The "floordiv" macro returns the largest integer
- <= a/n, and again this works correctly for negative a, as long as
- 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 +97,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 +237,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;
satisfy xprod(constraint[0], cur) >= 0 and xprod(constraint[1],
cur) <= 0. */
-/* Remark for potrace 1.1: the current implementation of calc_lon is
- more complex than the implementation found in potrace 1.0, but it
+/* Remark for Potrace 1.1: the current implementation of calc_lon is
+ more complex than the implementation found in Potrace 1.0, but it
is considerably faster. The introduction of the "nc" data structure
means that we only have to test the constraints for "corner"
points. On a typical input file, this speeds up the calc_lon
function by a factor of 31.2, thereby decreasing its time share
- within the overall potrace algorithm from 72.6% to 7.82%, and
+ within the overall Potrace algorithm from 72.6% to 7.82%, and
speeding up the overall algorithm by a factor of 3.36. On another
input file, calc_lon was sped up by a factor of 6.7, decreasing its
time share from 51.4% to 13.61%, and speeding up the overall
/* 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->beta[j] = 0.5;
}
curve->alphacurve = 1;
+
return 0;
}
@@ -962,8 +960,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 +969,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;
}
j = m;
for (i=om-1; i>=0; i--) {
if (pt[j]==j-1) {
- pp->ocurve.tag[i] = pp->curve.tag[mod(j,m)];
- pp->ocurve.c[i][0] = pp->curve.c[mod(j,m)][0];
- pp->ocurve.c[i][1] = pp->curve.c[mod(j,m)][1];
- pp->ocurve.c[i][2] = pp->curve.c[mod(j,m)][2];
- pp->ocurve.vertex[i] = pp->curve.vertex[mod(j,m)];
- pp->ocurve.alpha[i] = pp->curve.alpha[mod(j,m)];
- pp->ocurve.alpha0[i] = pp->curve.alpha0[mod(j,m)];
- pp->ocurve.beta[i] = pp->curve.beta[mod(j,m)];
+ pp->ocurve.tag[i] = pp->curve.tag[mod(j,m)];
+ pp->ocurve.c[i][0] = pp->curve.c[mod(j,m)][0];
+ pp->ocurve.c[i][1] = pp->curve.c[mod(j,m)][1];
+ pp->ocurve.c[i][2] = pp->curve.c[mod(j,m)][2];
+ pp->ocurve.vertex[i] = pp->curve.vertex[mod(j,m)];
+ pp->ocurve.alpha[i] = pp->curve.alpha[mod(j,m)];
+ pp->ocurve.alpha0[i] = pp->curve.alpha0[mod(j,m)];
+ pp->ocurve.beta[i] = pp->curve.beta[mod(j,m)];
s[i] = t[i] = 1.0;
} else {
pp->ocurve.tag[i] = POTRACE_CURVETO;
@@ -1201,7 +1199,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));
index e6cac9d977e2ba4aee93ab73c62e50349764745e..b33f8ba4de6811943d32df58c9fee150e866c4b1 100644 (file)
-/* Copyright (C) 2001-2005 Peter Selinger.
- This file is part of potrace. It is free software and it is covered
+/* Copyright (C) 2001-2007 Peter Selinger.
+ This file is part of Potrace. It is free software and it is covered
by the GNU General Public License. See the file COPYING for details. */
/* $Id$ */