SHA256
1
0
forked from pool/potrace
potrace/potrace-1.7-io.patch

254 lines
7.6 KiB
Diff

diff -Naur potrace-1.7/ChangeLog potrace-1.7x/ChangeLog
--- potrace-1.7/ChangeLog 2005-03-06 02:32:06.000000000 -0400
+++ potrace-1.7x/ChangeLog 2005-11-11 21:15:58.000000000 -0400
@@ -1,5 +1,15 @@
ChangeLog
+ (2005/11/11) PS1 - portability: use binary file i/o in Cygwin.
+ (2005/06/24) PS1 - potracelib: fixed allocation bug. Thanks to
+ Jung Shin for reporting this bug.
+ (2005/06/23) PS1 - potracelib_demo.c: free resources properly.
+ (2005/06/23) PS1 - initialize unused private state to 0.
+ (2005/06/23) PS1 - decompose.c: improved memory allocation scheme.
+ (2005/05/06) PS1 - added "alphacurve" field to private curve
+ structure, so that backends that don't use the public interface
+ (such as the EPS backend) can be warned of non-conforming curves.
+
v1.7 2005/03/06
(2005/03/05) PS1 - fixed progress bar subrange bug.
diff -Naur potrace-1.7/check/pgmdiff.c potrace-1.7x/check/pgmdiff.c
--- potrace-1.7/check/pgmdiff.c 2005-02-22 17:31:23.000000000 -0400
+++ potrace-1.7x/check/pgmdiff.c 2005-11-11 22:30:31.000000000 -0400
@@ -24,6 +24,8 @@
double diff;
int x, y, d;
+ platform_init();
+
if (ac != 3) {
fprintf(stderr, "pgmdiff: wrong number of arguments\n");
fprintf(stderr, "Usage: pgmdiff file1 file2\n");
@@ -38,7 +40,7 @@
if (strcmp(file1, "-")==0) {
r = gm_read(stdin, &g1);
} else {
- f = fopen(file1, "r");
+ f = fopen(file1, "rb");
if (!f) {
fprintf(stderr, "pgmdiff: %s: %s\n", file1, strerror(errno));
return 2;
@@ -57,7 +59,7 @@
if (strcmp(file2, "-")==0) {
r = gm_read(stdin, &g2);
} else {
- f = fopen(file2, "r");
+ f = fopen(file2, "rb");
if (!f) {
fprintf(stderr, "pgmdiff: %s: %s\n", file2, strerror(errno));
return 2;
diff -Naur potrace-1.7/src/backend_eps.c potrace-1.7x/src/backend_eps.c
--- potrace-1.7/src/backend_eps.c 2005-02-22 17:31:23.000000000 -0400
+++ potrace-1.7x/src/backend_eps.c 2005-11-11 20:44:07.000000000 -0400
@@ -305,10 +305,10 @@
}
static int eps_path(privcurve_t *curve) {
- if (info.longcoding) {
- return eps_path_long(curve);
- } else {
+ if (info.longcoding==0 && curve->alphacurve) {
return eps_path_short(curve);
+ } else {
+ return eps_path_long(curve);
}
}
diff -Naur potrace-1.7/src/curve.h potrace-1.7x/src/curve.h
--- potrace-1.7/src/curve.h 2005-02-20 18:55:31.000000000 -0400
+++ potrace-1.7x/src/curve.h 2005-11-11 20:44:08.000000000 -0400
@@ -20,6 +20,10 @@
int *tag; /* tag[n]: POTRACE_CORNER or POTRACE_CURVETO */
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 */
diff -Naur potrace-1.7/src/decompose.c potrace-1.7x/src/decompose.c
--- potrace-1.7/src/decompose.c 2005-03-06 02:35:51.000000000 -0400
+++ potrace-1.7x/src/decompose.c 2005-11-11 20:35:42.000000000 -0400
@@ -194,6 +194,7 @@
/* add point to path */
if (len>=size) {
size+=100;
+ size*=1.3;
pt1 = (point_t *)realloc(pt, size * sizeof(point_t));
if (!pt1) {
goto error;
diff -Naur potrace-1.7/src/main.c potrace-1.7x/src/main.c
--- potrace-1.7/src/main.c 2005-02-22 17:31:23.000000000 -0400
+++ potrace-1.7x/src/main.c 2005-11-11 22:30:31.000000000 -0400
@@ -1024,7 +1024,7 @@
if (filename == NULL || strcmp(filename, "-") == 0) {
return stdin;
}
- return fopen(filename, "r");
+ return fopen(filename, "rb");
}
/* open a file for writing. Return stdout if filename is NULL or "-" */
@@ -1032,7 +1032,7 @@
if (filename == NULL || strcmp(filename, "-") == 0) {
return stdout;
}
- return fopen(filename, "w");
+ return fopen(filename, "wb");
}
/* close a file, but do nothing is filename is NULL or "-" */
@@ -1172,6 +1172,10 @@
int i;
char *outfile;
+ /* platform-specific initializations, e.g., set file i/o to binary */
+ platform_init();
+
+ /* process options */
dopts(ac, av);
b = info.backend;
diff -Naur potrace-1.7/src/mkbitmap.c potrace-1.7x/src/mkbitmap.c
--- potrace-1.7/src/mkbitmap.c 2005-02-20 18:55:33.000000000 -0400
+++ potrace-1.7x/src/mkbitmap.c 2005-11-11 21:12:48.000000000 -0400
@@ -583,7 +583,7 @@
if (filename == NULL || strcmp(filename, "-") == 0) {
return stdin;
}
- return fopen(filename, "r");
+ return fopen(filename, "rb");
}
/* open a file for writing. Return stdout if filename is NULL or "-" */
@@ -591,7 +591,7 @@
if (filename == NULL || strcmp(filename, "-") == 0) {
return stdout;
}
- return fopen(filename, "w");
+ return fopen(filename, "wb");
}
/* close a file, but do nothing is filename is NULL or "-" */
@@ -639,6 +639,9 @@
int i;
char *outfile;
+ /* platform-specific initializations, e.g., set file i/o to binary */
+ platform_init();
+
/* process options */
dopts(ac, av);
diff -Naur potrace-1.7/src/platform.h potrace-1.7x/src/platform.h
--- potrace-1.7/src/platform.h 2005-02-20 18:55:33.000000000 -0400
+++ potrace-1.7x/src/platform.h 2005-11-11 22:07:13.000000000 -0400
@@ -13,4 +13,17 @@
unsigned int _CRT_fmode = _O_BINARY;
#endif
+#ifdef __CYGWIN__
+#include <fcntl.h>
+#include <io.h>
+static inline void platform_init(void) {
+ setmode(0,O_BINARY);
+ setmode(1,O_BINARY);
+}
+#else
+static inline void platform_init(void) {
+ /* NOP */
+}
+#endif
+
#endif /* PLATFORM_H */
diff -Naur potrace-1.7/src/potracelib.c potrace-1.7x/src/potracelib.c
--- potrace-1.7/src/potracelib.c 2005-02-26 21:47:04.000000000 -0400
+++ potrace-1.7x/src/potracelib.c 2005-11-11 20:35:42.000000000 -0400
@@ -64,7 +64,7 @@
prog.d_prev = param->progress.min;
/* allocate state object */
- st = (potrace_state_t *)malloc(sizeof(potrace_state_t *));
+ st = (potrace_state_t *)malloc(sizeof(potrace_state_t));
if (!st) {
return NULL;
}
@@ -80,6 +80,7 @@
st->status = POTRACE_STATUS_OK;
st->plist = plist;
+ st->priv = NULL; /* private state currently unused */
progress_subrange_end(&prog, &subprog);
diff -Naur potrace-1.7/src/potracelib_demo.c potrace-1.7x/src/potracelib_demo.c
--- potrace-1.7/src/potracelib_demo.c 2005-02-21 13:28:12.000000000 -0400
+++ potrace-1.7x/src/potracelib_demo.c 2005-11-11 20:35:42.000000000 -0400
@@ -51,6 +51,14 @@
return bm;
}
+/* free a bitmap */
+static void bm_free(potrace_bitmap_t *bm) {
+ if (bm != NULL) {
+ free(bm->map);
+ }
+ free(bm);
+}
+
/* ---------------------------------------------------------------------- */
/* demo */
@@ -91,6 +99,7 @@
fprintf(stderr, "Error tracing bitmap: %s\n", strerror(errno));
return 1;
}
+ bm_free(bm);
/* output vector data, e.g. as a rudimentary EPS file */
printf("%%!PS-Adobe-3.0 EPSF-3.0\n");
@@ -128,9 +137,8 @@
printf("grestore\n");
printf("%%EOF\n");
+ potrace_state_free(st);
+ potrace_param_free(param);
+
return 0;
}
-
-
-
-
diff -Naurw potrace-1.7/src/trace.c potrace-1.7x/src/trace.c
--- potrace-1.7/src/trace.c 2005-02-26 21:54:08.000000000 -0400
+++ potrace-1.7x/src/trace.c 2005-05-06 20:54:42.000000000 -0300
@@ -891,6 +891,7 @@
curve->alpha[j] = alpha; /* store the "cropped" value of alpha */
curve->beta[j] = 0.5;
}
+ curve->alphacurve = 1;
return 0;
}
@@ -1165,6 +1166,7 @@
i1 = mod(i+1,om);
pp->ocurve.beta[i] = s[i] / (s[i] + t[i1]);
}
+ pp->ocurve.alphacurve = 1;
free(pt);
free(pen);