summaryrefslogtreecommitdiff
path: root/Build/source/libs/potrace/potrace-src/src
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/libs/potrace/potrace-src/src')
-rw-r--r--Build/source/libs/potrace/potrace-src/src/Makefile.am4
-rw-r--r--Build/source/libs/potrace/potrace-src/src/auxiliary.h2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/backend_dxf.c20
-rw-r--r--Build/source/libs/potrace/potrace-src/src/backend_dxf.h2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/backend_eps.c64
-rw-r--r--Build/source/libs/potrace/potrace-src/src/backend_eps.h2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/backend_geojson.c4
-rw-r--r--Build/source/libs/potrace/potrace-src/src/backend_geojson.h2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/backend_pdf.c64
-rw-r--r--Build/source/libs/potrace/potrace-src/src/backend_pdf.h2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/backend_pgm.c4
-rw-r--r--Build/source/libs/potrace/potrace-src/src/backend_pgm.h2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/backend_svg.c8
-rw-r--r--Build/source/libs/potrace/potrace-src/src/backend_svg.h2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/backend_xfig.c8
-rw-r--r--Build/source/libs/potrace/potrace-src/src/backend_xfig.h2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/bbox.c2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/bbox.h2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/bitmap.h151
-rw-r--r--Build/source/libs/potrace/potrace-src/src/bitmap_io.c99
-rw-r--r--Build/source/libs/potrace/potrace-src/src/bitmap_io.h4
-rw-r--r--Build/source/libs/potrace/potrace-src/src/bitops.h2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/curve.c2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/curve.h2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/decompose.c4
-rw-r--r--Build/source/libs/potrace/potrace-src/src/decompose.h2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/flate.c38
-rw-r--r--Build/source/libs/potrace/potrace-src/src/flate.h12
-rw-r--r--Build/source/libs/potrace/potrace-src/src/greymap.c238
-rw-r--r--Build/source/libs/potrace/potrace-src/src/greymap.h26
-rw-r--r--Build/source/libs/potrace/potrace-src/src/lists.h2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/lzw.c16
-rw-r--r--Build/source/libs/potrace/potrace-src/src/lzw.h12
-rw-r--r--Build/source/libs/potrace/potrace-src/src/main.c132
-rw-r--r--Build/source/libs/potrace/potrace-src/src/main.h2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/mkbitmap.c98
-rw-r--r--Build/source/libs/potrace/potrace-src/src/platform.h2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/potracelib.c6
-rw-r--r--Build/source/libs/potrace/potrace-src/src/potracelib.h4
-rw-r--r--Build/source/libs/potrace/potrace-src/src/potracelib_demo.c2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/progress.h2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/progress_bar.c4
-rw-r--r--Build/source/libs/potrace/potrace-src/src/progress_bar.h2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/render.c3
-rw-r--r--Build/source/libs/potrace/potrace-src/src/render.h2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/trace.c2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/trace.h2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/trans.c2
-rw-r--r--Build/source/libs/potrace/potrace-src/src/trans.h2
49 files changed, 699 insertions, 374 deletions
diff --git a/Build/source/libs/potrace/potrace-src/src/Makefile.am b/Build/source/libs/potrace/potrace-src/src/Makefile.am
index bf8431223b4..1f657e08897 100644
--- a/Build/source/libs/potrace/potrace-src/src/Makefile.am
+++ b/Build/source/libs/potrace/potrace-src/src/Makefile.am
@@ -1,4 +1,4 @@
-## Copyright (C) 2001-2015 Peter Selinger.
+## Copyright (C) 2001-2017 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.
@@ -42,7 +42,7 @@ libsources = curve.c curve.h trace.c trace.h decompose.c \
lib_LTLIBRARIES = $(INSTLIBS)
EXTRA_LTLIBRARIES = libpotrace.la
libpotrace_la_SOURCES = $(libsources)
-libpotrace_la_LDFLAGS = -version-info 0:3:0 -rpath '$(libdir)' \
+libpotrace_la_LDFLAGS = -version-info 0:4:0 -rpath '$(libdir)' \
-export-symbols $(srcdir)/libpotrace-export.sym -no-undefined
libpotrace_la_LIBADD = -lm
MOSTLYCLEANFILES = libpotrace.la
diff --git a/Build/source/libs/potrace/potrace-src/src/auxiliary.h b/Build/source/libs/potrace/potrace-src/src/auxiliary.h
index b365a0b402b..bb0c6e03cb9 100644
--- a/Build/source/libs/potrace/potrace-src/src/auxiliary.h
+++ b/Build/source/libs/potrace/potrace-src/src/auxiliary.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/backend_dxf.c b/Build/source/libs/potrace/potrace-src/src/backend_dxf.c
index 39b12a9d76f..978f6d120a8 100644
--- a/Build/source/libs/potrace/potrace-src/src/backend_dxf.c
+++ b/Build/source/libs/potrace/potrace-src/src/backend_dxf.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -94,7 +94,7 @@ static int ship(FILE *fout, int gc, const char *fmt, ...) {
}
/* output the start of a polyline */
-static void ship_polyline(FILE *fout, char *layer, int closed) {
+static void ship_polyline(FILE *fout, const char *layer, int closed) {
ship(fout, 0, "POLYLINE");
ship(fout, 8, "%s", layer);
ship(fout, 66, "%d", 1);
@@ -102,7 +102,7 @@ static void ship_polyline(FILE *fout, char *layer, int closed) {
}
/* output a vertex */
-static void ship_vertex(FILE *fout, char *layer, dpoint_t v, double bulge) {
+static void ship_vertex(FILE *fout, const char *layer, dpoint_t v, double bulge) {
ship(fout, 0, "VERTEX");
ship(fout, 8, "%s", layer);
ship(fout, 10, "%f", v.x);
@@ -116,12 +116,12 @@ static void ship_seqend(FILE *fout) {
}
/* output a comment */
-static void ship_comment(FILE *fout, char *comment) {
+static void ship_comment(FILE *fout, const char *comment) {
ship(fout, 999, "%s", comment);
}
/* output the start of a section */
-static void ship_section(FILE *fout, char *name) {
+static void ship_section(FILE *fout, const char *name) {
ship(fout, 0, "SECTION");
ship(fout, 2, "%s", name);
}
@@ -141,7 +141,7 @@ static void ship_eof(FILE *fout) {
circular arcs from A to B, tangent to AC at A and to CB at
B. Segments are meant to be concatenated, so don't output the final
vertex. */
-static void pseudo_quad(FILE *fout, char *layer, dpoint_t A, dpoint_t C, dpoint_t B) {
+static void pseudo_quad(FILE *fout, const char *layer, dpoint_t A, dpoint_t C, dpoint_t B) {
dpoint_t v, w;
double v2, w2, vw, vxw, nvw;
double a, b, c, y;
@@ -185,7 +185,7 @@ static void pseudo_quad(FILE *fout, char *layer, dpoint_t A, dpoint_t C, dpoint_
made up of up to 4 circular arcs. This is particularly intended for
the case when AD and BC are parallel. Like arcs(), don't output the
final vertex. */
-static void pseudo_bezier(FILE *fout, char *layer, dpoint_t A, dpoint_t B, dpoint_t C, dpoint_t D) {
+static void pseudo_bezier(FILE *fout, const char *layer, dpoint_t A, dpoint_t B, dpoint_t C, dpoint_t D) {
dpoint_t E = interval(0.75, A, B);
dpoint_t G = interval(0.75, D, C);
dpoint_t F = interval(0.5, E, G);
@@ -199,7 +199,7 @@ static void pseudo_bezier(FILE *fout, char *layer, dpoint_t A, dpoint_t B, dpoin
/* functions for converting a path to a DXF polyline */
/* do one path. */
-static int dxf_path(FILE *fout, char *layer, potrace_curve_t *curve, trans_t t) {
+static int dxf_path(FILE *fout, const char *layer, potrace_curve_t *curve, trans_t t) {
int i;
dpoint_t *c, *c1;
int n = curve->n;
@@ -230,7 +230,7 @@ static int dxf_path(FILE *fout, char *layer, potrace_curve_t *curve, trans_t t)
int page_dxf(FILE *fout, potrace_path_t *plist, imginfo_t *imginfo) {
potrace_path_t *p;
trans_t t;
- char *layer = "0";
+ const char *layer = "0";
/* set up the coordinate transform (rotation) */
t.bb[0] = imginfo->trans.bb[0]+imginfo->lmar+imginfo->rmar;
@@ -242,7 +242,7 @@ int page_dxf(FILE *fout, potrace_path_t *plist, imginfo_t *imginfo) {
t.y[0] = imginfo->trans.y[0];
t.y[1] = imginfo->trans.y[1];
- ship_comment(fout, "DXF data, created by "POTRACE" "VERSION", written by Peter Selinger 2001-2015");
+ ship_comment(fout, "DXF data, created by " POTRACE " " VERSION ", written by Peter Selinger 2001-2017");
/* header section */
ship_section(fout, "HEADER");
diff --git a/Build/source/libs/potrace/potrace-src/src/backend_dxf.h b/Build/source/libs/potrace/potrace-src/src/backend_dxf.h
index 37906a0eaf3..f7784485915 100644
--- a/Build/source/libs/potrace/potrace-src/src/backend_dxf.h
+++ b/Build/source/libs/potrace/potrace-src/src/backend_dxf.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/backend_eps.c b/Build/source/libs/potrace/potrace-src/src/backend_eps.c
index d992a1a2cf8..8cfb91ef218 100644
--- a/Build/source/libs/potrace/potrace-src/src/backend_eps.c
+++ b/Build/source/libs/potrace/potrace-src/src/backend_eps.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -38,6 +38,8 @@ typedef int color_t;
#define green 0x008000
#define blue 0x0000ff
+#define TRY(x) if (x) goto try_error
+
/* ---------------------------------------------------------------------- */
/* functions for interfacing with compression backend */
@@ -47,7 +49,7 @@ typedef int color_t;
/* print the token to f, but filtered through a compression
filter in case filter!=0 */
-static int (*xship)(FILE *f, int filter, char *s, int len);
+static int (*xship)(FILE *f, int filter, const char *s, int len);
static FILE *xship_file;
/* ship postscript code, filtered */
@@ -67,7 +69,7 @@ static int ship(const char *fmt, ...) {
}
/* ship a postscript comment, unfiltered */
-static int shipcom(char *fmt, ...) {
+static int shipcom(const char *fmt, ...) {
static char buf[4096];
va_list args;
@@ -153,7 +155,7 @@ static void eps_curveto(dpoint_t p1, dpoint_t p2, dpoint_t p3) {
}
/* this procedure returns a statically allocated string */
-static char *eps_colorstring(const color_t col) {
+static const char *eps_colorstring(const color_t col) {
double r, g, b;
static char buf[100];
@@ -399,7 +401,7 @@ static void eps_L(privcurve_t *curve, const color_t col) {
/* postscript macros */
/* special macros for size-optimized rendering of Bezier curves */
-static char *optimacros =
+static const char *optimacros =
"/D{bind def}def\n"
"/R{roll}D\n"
"/K{copy}D\n"
@@ -427,7 +429,7 @@ static char *optimacros =
"/w{%s z fill}D\n";
/* special macros for debug output */
-static char *debugmacros =
+static const char *debugmacros =
"/unit { %f } def\n"
"/box { newpath 0 0 moveto 0 1 lineto 1 1 lineto 1 0 lineto closepath } def\n"
"/circ { newpath 0 0 1 0 360 arc closepath } def\n"
@@ -451,7 +453,7 @@ static int render0(potrace_path_t *plist) {
if (info.longcoding) {
eps_setcolor(info.color);
list_forall (p, plist) {
- eps_path(p->priv->fcurve);
+ TRY(eps_path(p->priv->fcurve));
ship("closepath\n");
if (p->next == NULL || p->next->sign == '+') {
ship("fill\n");
@@ -459,7 +461,7 @@ static int render0(potrace_path_t *plist) {
}
} else {
list_forall (p, plist) {
- eps_path(p->priv->fcurve);
+ TRY(eps_path(p->priv->fcurve));
if (p->next == NULL || p->next->sign == '+') {
ship("b\n");
} else {
@@ -468,6 +470,9 @@ static int render0(potrace_path_t *plist) {
}
}
return 0;
+
+ try_error:
+ return 1;
}
/* Opaque output: alternating black and white */
@@ -476,18 +481,21 @@ static int render0_opaque(potrace_path_t *plist) {
if (info.longcoding) {
list_forall (p, plist) {
- eps_path(p->priv->fcurve);
+ TRY(eps_path(p->priv->fcurve));
ship("closepath\n");
eps_setcolor(p->sign=='+' ? info.color : info.fillcolor);
ship("fill\n");
}
} else {
list_forall (p, plist) {
- eps_path(p->priv->fcurve);
+ TRY(eps_path(p->priv->fcurve));
ship(p->sign=='+' ? "b\n" : "w\n");
}
}
return 0;
+
+ try_error:
+ return 1;
}
/* Debug output type 1 (show optimal polygon) */
@@ -559,7 +567,7 @@ static int render2(potrace_path_t *plist) {
/* output the path */
eps_linewidth(.1);
eps_setcolor(blue);
- eps_path(&p->priv->curve);
+ TRY(eps_path(&p->priv->curve));
ship("closepath\n");
ship("stroke\n");
@@ -568,7 +576,7 @@ static int render2(potrace_path_t *plist) {
/* output opticurve */
eps_linewidth(.05);
eps_setcolor(red);
- eps_path(&p->priv->ocurve);
+ TRY(eps_path(&p->priv->ocurve));
ship("closepath\n");
ship("stroke\n");
@@ -580,6 +588,9 @@ static int render2(potrace_path_t *plist) {
}
}
return 0;
+
+ try_error:
+ return 1;
}
/* Free-style debug output */
@@ -618,7 +629,7 @@ static int render_debug(potrace_path_t *plist) {
/* output the path */
eps_linewidth(.1);
eps_setcolor(blue);
- eps_path(&p->priv->curve);
+ TRY(eps_path(&p->priv->curve));
ship("closepath\n");
ship("stroke\n");
@@ -630,7 +641,7 @@ static int render_debug(potrace_path_t *plist) {
/* output opticurve */
eps_linewidth(.05);
eps_setcolor(red);
- eps_path(&p->priv->ocurve);
+ TRY(eps_path(&p->priv->ocurve));
ship("closepath\n");
ship("stroke\n");
@@ -648,6 +659,9 @@ static int render_debug(potrace_path_t *plist) {
}
}
return 0;
+
+ try_error:
+ return 1;
}
/* select the appropriate rendering function from above */
@@ -686,7 +700,7 @@ static int eps_init(imginfo_t *imginfo) {
char *c0, *c1;
shipcom("%%!PS-Adobe-3.0 EPSF-3.0\n");
- shipcom("%%%%Creator: "POTRACE" "VERSION", written by Peter Selinger 2001-2015\n");
+ shipcom("%%%%Creator: " POTRACE " " VERSION ", written by Peter Selinger 2001-2017\n");
shipcom("%%%%LanguageLevel: %d\n", info.pslevel);
shipcom("%%%%BoundingBox: 0 0 %.0f %.0f\n",
ceil(imginfo->trans.bb[0]+imginfo->lmar+imginfo->rmar),
@@ -725,28 +739,22 @@ static int eps_init(imginfo_t *imginfo) {
return 0;
}
-static int eps_term(void) {
+static void eps_term(void) {
ship("restore\n");
shipcom("%%%%EOF\n");
- return 0;
}
/* public interface for EPS */
int page_eps(FILE *fout, potrace_path_t *plist, imginfo_t *imginfo) {
- int r;
-
eps_callbacks(fout);
- eps_init(imginfo);
-
- r = eps_render(plist);
- if (r) {
- return r;
- }
-
+ TRY(eps_init(imginfo));
+ TRY(eps_render(plist));
eps_term();
-
return 0;
+
+ try_error:
+ return 1;
}
/* ---------------------------------------------------------------------- */
@@ -761,7 +769,7 @@ int init_ps(FILE *fout) {
eps_callbacks(fout);
shipcom("%%!PS-Adobe-3.0\n");
- shipcom("%%%%Creator: "POTRACE" "VERSION", written by Peter Selinger 2001-2015\n");
+ shipcom("%%%%Creator: " POTRACE " " VERSION ", written by Peter Selinger 2001-2017\n");
shipcom("%%%%LanguageLevel: %d\n", info.pslevel);
shipcom("%%%%BoundingBox: 0 0 %d %d\n", info.paperwidth, info.paperheight);
shipcom("%%%%Pages: (atend)\n");
diff --git a/Build/source/libs/potrace/potrace-src/src/backend_eps.h b/Build/source/libs/potrace/potrace-src/src/backend_eps.h
index 90c866622cb..d0dfd650b22 100644
--- a/Build/source/libs/potrace/potrace-src/src/backend_eps.h
+++ b/Build/source/libs/potrace/potrace-src/src/backend_eps.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/backend_geojson.c b/Build/source/libs/potrace/potrace-src/src/backend_geojson.c
index d5318581f11..b929653d97c 100644
--- a/Build/source/libs/potrace/potrace-src/src/backend_geojson.c
+++ b/Build/source/libs/potrace/potrace-src/src/backend_geojson.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -30,7 +30,7 @@ static inline double bezier(double t, double x0, double x1, double x2, double x3
return s*s*s*x0 + 3*(s*s*t)*x1 + 3*(t*t*s)*x2 + t*t*t*x3;
}
-static char *format = "%f";
+static const char *format = "%f";
/* Convert a floating-point number to a string, using a pre-determined
format. The format must be previously set with set_format().
diff --git a/Build/source/libs/potrace/potrace-src/src/backend_geojson.h b/Build/source/libs/potrace/potrace-src/src/backend_geojson.h
index 985cc3c919e..02be534ef93 100644
--- a/Build/source/libs/potrace/potrace-src/src/backend_geojson.h
+++ b/Build/source/libs/potrace/potrace-src/src/backend_geojson.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/backend_pdf.c b/Build/source/libs/potrace/potrace-src/src/backend_pdf.c
index f350557a853..2cbdd70da4e 100644
--- a/Build/source/libs/potrace/potrace-src/src/backend_pdf.c
+++ b/Build/source/libs/potrace/potrace-src/src/backend_pdf.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -25,6 +25,8 @@
typedef int color_t;
+#define TRY(x) if (x) goto try_error
+
/* ---------------------------------------------------------------------- */
/* auxiliary: growing arrays */
@@ -83,7 +85,7 @@ static size_t outcount; /* output file position */
/* print the token to f, but filtered through a compression
filter in case filter!=0 */
-static int (*xship)(FILE *f, int filter, char *s, int len);
+static int (*xship)(FILE *f, int filter, const char *s, int len);
static FILE *xship_file;
/* ship PDF code, filtered */
@@ -103,7 +105,7 @@ static int ship(const char *fmt, ...) {
}
/* ship PDF code, unfiltered */
-static int shipclear(char *fmt, ...) {
+static int shipclear(const char *fmt, ...) {
static char buf[4096];
va_list args;
@@ -165,7 +167,7 @@ static void pdf_curveto(dpoint_t p1, dpoint_t p2, dpoint_t p3) {
}
/* this procedure returns a statically allocated string */
-static char *pdf_colorstring(const color_t col) {
+static const char *pdf_colorstring(const color_t col) {
double r, g, b;
static char buf[100];
@@ -277,13 +279,13 @@ int init_pdf(FILE *fout)
shipclear("%%PDF-1.3\n");
- intarray_set(&xref, nxref++, outcount);
+ TRY(intarray_set(&xref, nxref++, outcount));
shipclear("1 0 obj\n<</Type/Catalog/Pages 3 0 R>>\nendobj\n");
- intarray_set(&xref, nxref++, outcount);
+ TRY(intarray_set(&xref, nxref++, outcount));
shipclear("2 0 obj\n"
"<</Creator"
- "("POTRACE" "VERSION", written by Peter Selinger 2001-2015)>>\n"
+ "(" POTRACE " " VERSION ", written by Peter Selinger 2001-2017)>>\n"
"endobj\n");
/* delay obj #3 (pages) until end */
@@ -291,6 +293,9 @@ int init_pdf(FILE *fout)
fflush(fout);
return 0;
+
+ try_error:
+ return 1;
}
int term_pdf(FILE *fout)
@@ -300,7 +305,7 @@ int term_pdf(FILE *fout)
pdf_callbacks(fout);
- intarray_set(&xref, 2, outcount);
+ TRY(intarray_set(&xref, 2, outcount));
shipclear("3 0 obj\n"
"<</Type/Pages/Count %d/Kids[\n", npages);
for (i = 0; i < npages; i++)
@@ -321,10 +326,14 @@ int term_pdf(FILE *fout)
intarray_term(&xref);
intarray_term(&pages);
return 0;
+
+ try_error:
+ return 1;
}
-/* if largebbox is set, set bounding box to pagesize. */
-static void pdf_pageinit(imginfo_t *imginfo, int largebbox)
+/* if largebbox is set, set bounding box to pagesize. Return 0 on
+ success or 1 on error with errno set. */
+static int pdf_pageinit(imginfo_t *imginfo, int largebbox)
{
double origx = imginfo->trans.orig[0] + imginfo->lmar;
double origy = imginfo->trans.orig[1] + imginfo->bmar;
@@ -338,7 +347,7 @@ static void pdf_pageinit(imginfo_t *imginfo, int largebbox)
pdf_color = -1;
- intarray_set(&xref, nxref++, outcount);
+ TRY(intarray_set(&xref, nxref++, outcount));
shipclear("%d 0 obj\n", nxref);
shipclear("<</Type/Page/Parent 3 0 R/Resources<</ProcSet[/PDF]>>");
if (largebbox) {
@@ -349,9 +358,9 @@ static void pdf_pageinit(imginfo_t *imginfo, int largebbox)
shipclear("/Contents %d 0 R>>\n", nxref + 1);
shipclear("endobj\n");
- intarray_set(&pages, npages++, nxref);
+ TRY(intarray_set(&pages, npages++, nxref));
- intarray_set(&xref, nxref++, outcount);
+ TRY(intarray_set(&xref, nxref++, outcount));
shipclear("%d 0 obj\n", nxref);
if (info.compress)
shipclear("<</Filter/FlateDecode/Length %d 0 R>>\n", nxref + 1);
@@ -362,9 +371,14 @@ static void pdf_pageinit(imginfo_t *imginfo, int largebbox)
streamofs = outcount;
ship("%f %f %f %f %f %f cm\n", dxx, dxy, dyx, dyy, origx, origy);
+ return 0;
+
+ try_error:
+ return 1;
}
-static void pdf_pageterm(void)
+/* Return 0 on success or 1 on error with errno set. */
+static int pdf_pageterm(void)
{
int streamlen;
@@ -373,8 +387,12 @@ static void pdf_pageterm(void)
streamlen = outcount - streamofs;
shipclear("endstream\nendobj\n");
- intarray_set(&xref, nxref++, outcount);
+ TRY(intarray_set(&xref, nxref++, outcount));
shipclear("%d 0 obj\n%d\nendobj\n", nxref, streamlen);
+ return 0;
+
+ try_error:
+ return 1;
}
int page_pdf(FILE *fout, potrace_path_t *plist, imginfo_t *imginfo)
@@ -383,18 +401,20 @@ int page_pdf(FILE *fout, potrace_path_t *plist, imginfo_t *imginfo)
pdf_callbacks(fout);
- pdf_pageinit(imginfo, 0);
+ TRY(pdf_pageinit(imginfo, 0));
r = pdf_render(plist);
if (r) {
return r;
}
- pdf_pageterm();
+ TRY(pdf_pageterm());
fflush(fout);
-
return 0;
+
+ try_error:
+ return 1;
}
int page_pdfpage(FILE *fout, potrace_path_t *plist, imginfo_t *imginfo)
@@ -403,17 +423,19 @@ int page_pdfpage(FILE *fout, potrace_path_t *plist, imginfo_t *imginfo)
pdf_callbacks(fout);
- pdf_pageinit(imginfo, 1);
+ TRY(pdf_pageinit(imginfo, 1));
r = pdf_render(plist);
if (r) {
return r;
}
- pdf_pageterm();
+ TRY(pdf_pageterm());
fflush(fout);
-
return 0;
+
+ try_error:
+ return 1;
}
diff --git a/Build/source/libs/potrace/potrace-src/src/backend_pdf.h b/Build/source/libs/potrace/potrace-src/src/backend_pdf.h
index 3bad72d4755..c14c55a9c62 100644
--- a/Build/source/libs/potrace/potrace-src/src/backend_pdf.h
+++ b/Build/source/libs/potrace/potrace-src/src/backend_pdf.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/backend_pgm.c b/Build/source/libs/potrace/potrace-src/src/backend_pgm.c
index f6714258360..60f17c232e5 100644
--- a/Build/source/libs/potrace/potrace-src/src/backend_pgm.c
+++ b/Build/source/libs/potrace/potrace-src/src/backend_pgm.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -62,7 +62,7 @@ int page_pgm(FILE *fout, potrace_path_t *plist, imginfo_t *imginfo) {
int w, h;
trans_t t;
int mode;
- char *comment = "created by "POTRACE" "VERSION", written by Peter Selinger 2001-2015";
+ const char *comment = "created by " POTRACE " " VERSION ", written by Peter Selinger 2001-2017";
t.bb[0] = imginfo->trans.bb[0]+imginfo->lmar+imginfo->rmar;
t.bb[1] = imginfo->trans.bb[1]+imginfo->tmar+imginfo->bmar;
diff --git a/Build/source/libs/potrace/potrace-src/src/backend_pgm.h b/Build/source/libs/potrace/potrace-src/src/backend_pgm.h
index 499e925b425..db3545b15ff 100644
--- a/Build/source/libs/potrace/potrace-src/src/backend_pgm.h
+++ b/Build/source/libs/potrace/potrace-src/src/backend_pgm.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/backend_svg.c b/Build/source/libs/potrace/potrace-src/src/backend_svg.c
index 4dd67c8934c..717f58aa396 100644
--- a/Build/source/libs/potrace/potrace-src/src/backend_svg.c
+++ b/Build/source/libs/potrace/potrace-src/src/backend_svg.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -38,7 +38,7 @@ static char lastop = 0;
static int column = 0;
static int newline = 1;
-static void shiptoken(FILE *fout, char *token) {
+static void shiptoken(FILE *fout, const char *token) {
int c = strlen(token);
if (!newline && column+c+1 > 75) {
fprintf(fout, "\n");
@@ -53,7 +53,7 @@ static void shiptoken(FILE *fout, char *token) {
newline = 0;
}
-static void ship(FILE *fout, char *fmt, ...) {
+static void ship(FILE *fout, const char *fmt, ...) {
va_list args;
static char buf[4096]; /* static string limit is okay here because
we only use constant format strings - for
@@ -304,7 +304,7 @@ int page_svg(FILE *fout, potrace_path_t *plist, imginfo_t *imginfo) {
/* metadata: creator */
fprintf(fout, "<metadata>\n");
- fprintf(fout, "Created by "POTRACE" "VERSION", written by Peter Selinger 2001-2015\n");
+ fprintf(fout, "Created by " POTRACE " " VERSION ", written by Peter Selinger 2001-2017\n");
fprintf(fout, "</metadata>\n");
/* use a "group" tag to establish coordinate system and style */
diff --git a/Build/source/libs/potrace/potrace-src/src/backend_svg.h b/Build/source/libs/potrace/potrace-src/src/backend_svg.h
index 0bacb1c939e..2e0817846c0 100644
--- a/Build/source/libs/potrace/potrace-src/src/backend_svg.h
+++ b/Build/source/libs/potrace/potrace-src/src/backend_svg.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/backend_xfig.c b/Build/source/libs/potrace/potrace-src/src/backend_xfig.c
index a4d2947229b..bd9a4904c24 100644
--- a/Build/source/libs/potrace/potrace-src/src/backend_xfig.c
+++ b/Build/source/libs/potrace/potrace-src/src/backend_xfig.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -26,7 +26,7 @@
#endif
struct pageformat_s {
- char *name;
+ const char *name;
int w, h;
};
typedef struct pageformat_s pageformat_t;
@@ -179,7 +179,7 @@ int page_xfig(FILE *fout, potrace_path_t *plist, imginfo_t *imginfo) {
trans_t t;
double origx = imginfo->trans.orig[0] + imginfo->lmar;
double origy = - imginfo->trans.orig[1] - imginfo->bmar + info.paperheight;
- char *formatname;
+ const char *formatname;
int best, penalty;
pageformat_t *f;
int i;
@@ -215,7 +215,7 @@ int page_xfig(FILE *fout, potrace_path_t *plist, imginfo_t *imginfo) {
/* header */
fprintf(fout, "#FIG 3.2\n");
- fprintf(fout, "#created by "POTRACE" "VERSION", written by Peter Selinger 2001-2015\n");
+ fprintf(fout, "#created by " POTRACE " " VERSION ", written by Peter Selinger 2001-2017\n");
fprintf(fout, "Portrait\n");
fprintf(fout, "Center\n");
fprintf(fout, "Inches\n");
diff --git a/Build/source/libs/potrace/potrace-src/src/backend_xfig.h b/Build/source/libs/potrace/potrace-src/src/backend_xfig.h
index b1d3af2b14e..ce8df41a99a 100644
--- a/Build/source/libs/potrace/potrace-src/src/backend_xfig.h
+++ b/Build/source/libs/potrace/potrace-src/src/backend_xfig.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/bbox.c b/Build/source/libs/potrace/potrace-src/src/bbox.c
index 27b16ebcb79..45783c80739 100644
--- a/Build/source/libs/potrace/potrace-src/src/bbox.c
+++ b/Build/source/libs/potrace/potrace-src/src/bbox.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/bbox.h b/Build/source/libs/potrace/potrace-src/src/bbox.h
index 12e74626462..30b71ba6930 100644
--- a/Build/source/libs/potrace/potrace-src/src/bbox.h
+++ b/Build/source/libs/potrace/potrace-src/src/bbox.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/bitmap.h b/Build/source/libs/potrace/potrace-src/src/bitmap.h
index 7b5a94bb161..2e91ab1e7d7 100644
--- a/Build/source/libs/potrace/potrace-src/src/bitmap.h
+++ b/Build/source/libs/potrace/potrace-src/src/bitmap.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -45,26 +45,71 @@
#define BM_INV(bm, x, y) (bm_safe(bm, x, y) ? BM_UINV(bm, x, y) : 0)
#define BM_PUT(bm, x, y, b) (bm_safe(bm, x, y) ? BM_UPUT(bm, x, y, b) : 0)
+/* calculate the size, in bytes, required for the data area of a
+ bitmap of the given dy and h. Assume h >= 0. Return -1 if the size
+ does not fit into the ptrdiff_t type. */
+static inline ptrdiff_t getsize(int dy, int h) {
+ ptrdiff_t size;
+
+ if (dy < 0) {
+ dy = -dy;
+ }
+
+ size = (ptrdiff_t)dy * (ptrdiff_t)h * (ptrdiff_t)BM_WORDSIZE;
+
+ /* check for overflow error */
+ if (size < 0 || (h != 0 && dy != 0 && size / h / dy != BM_WORDSIZE)) {
+ return -1;
+ }
+
+ return size;
+}
+
+/* return the size, in bytes, of the data area of the bitmap. Return
+ -1 if the size does not fit into the ptrdiff_t type; however, this
+ cannot happen if the bitmap is well-formed, i.e., if created with
+ bm_new or bm_dup. */
+static inline ptrdiff_t bm_size(const potrace_bitmap_t *bm) {
+ return getsize(bm->dy, bm->h);
+}
+
+/* calculate the base address of the bitmap data. Assume that the
+ bitmap is well-formed, i.e., its size fits into the ptrdiff_t type.
+ This is the case if created with bm_new or bm_dup. The base address
+ may differ from bm->map if dy is negative */
+static inline potrace_word *bm_base(const potrace_bitmap_t *bm) {
+ int dy = bm->dy;
+
+ if (dy >= 0 || bm->h == 0) {
+ return bm->map;
+ } else {
+ return bm_scanline(bm, bm->h - 1);
+ }
+}
+
/* free the given bitmap. Leaves errno untouched. */
static inline void bm_free(potrace_bitmap_t *bm) {
- if (bm) {
- free(bm->map);
+ if (bm && bm->map) {
+ free(bm_base(bm));
}
free(bm);
}
-/* return new un-initialized bitmap. NULL with errno on error.
+/* return new bitmap initialized to 0. NULL with errno on error.
Assumes w, h >= 0. */
static inline potrace_bitmap_t *bm_new(int w, int h) {
potrace_bitmap_t *bm;
int dy = w == 0 ? 0 : (w - 1) / BM_WORDBITS + 1;
- ptrdiff_t size = (ptrdiff_t)dy * (ptrdiff_t)h * (ptrdiff_t)BM_WORDSIZE;
+ ptrdiff_t size;
- /* check for overflow error */
- if (size < 0 || (h != 0 && dy != 0 && size / h / dy != BM_WORDSIZE)) {
+ size = getsize(dy, h);
+ if (size < 0) {
errno = ENOMEM;
return NULL;
}
+ if (size == 0) {
+ size = 1; /* make sure calloc() doesn't return NULL */
+ }
bm = (potrace_bitmap_t *) malloc(sizeof(potrace_bitmap_t));
if (!bm) {
@@ -73,7 +118,7 @@ static inline potrace_bitmap_t *bm_new(int w, int h) {
bm->w = w;
bm->h = h;
bm->dy = dy;
- bm->map = (potrace_word *) malloc(size);
+ bm->map = (potrace_word *) calloc(1, size);
if (!bm->map) {
free(bm);
return NULL;
@@ -81,33 +126,103 @@ static inline potrace_bitmap_t *bm_new(int w, int h) {
return bm;
}
-/* clear the given bitmap. Set all bits to c. */
+/* clear the given bitmap. Set all bits to c. Assumes a well-formed
+ bitmap. */
static inline void bm_clear(potrace_bitmap_t *bm, int c) {
/* Note: if the bitmap was created with bm_new, then it is
guaranteed that size will fit into the ptrdiff_t type. */
- ptrdiff_t size = (ptrdiff_t)bm->dy * (ptrdiff_t)bm->h * (ptrdiff_t)BM_WORDSIZE;
- memset(bm->map, c ? -1 : 0, size);
+ ptrdiff_t size = bm_size(bm);
+ memset(bm_base(bm), c ? -1 : 0, size);
}
-/* duplicate the given bitmap. Return NULL on error with errno set. */
+/* duplicate the given bitmap. Return NULL on error with errno
+ set. Assumes a well-formed bitmap. */
static inline potrace_bitmap_t *bm_dup(const potrace_bitmap_t *bm) {
potrace_bitmap_t *bm1 = bm_new(bm->w, bm->h);
- ptrdiff_t size = (ptrdiff_t)bm->dy * (ptrdiff_t)bm->h * (ptrdiff_t)BM_WORDSIZE;
+ int y;
+
if (!bm1) {
return NULL;
}
- memcpy(bm1->map, bm->map, size);
+ for (y=0; y < bm->h; y++) {
+ memcpy(bm_scanline(bm1, y), bm_scanline(bm, y), (size_t)bm1->dy * (size_t)BM_WORDSIZE);
+ }
return bm1;
}
/* invert the given bitmap. */
static inline void bm_invert(potrace_bitmap_t *bm) {
- ptrdiff_t i;
- ptrdiff_t size = (ptrdiff_t)bm->dy * (ptrdiff_t)bm->h;
+ int dy = bm->dy;
+ int y;
+ int i;
+ potrace_word *p;
- for (i = 0; i < size; i++) {
- bm->map[i] ^= BM_ALLBITS;
+ if (dy < 0) {
+ dy = -dy;
+ }
+
+ for (y=0; y < bm->h; y++) {
+ p = bm_scanline(bm, y);
+ for (i=0; i < dy; i++) {
+ p[i] ^= BM_ALLBITS;
+ }
+ }
+}
+
+/* turn the given bitmap upside down. This does not move the bitmap
+ data or change the bm_base() address. */
+static inline void bm_flip(potrace_bitmap_t *bm) {
+ int dy = bm->dy;
+
+ if (bm->h == 0 || bm->h == 1) {
+ return;
+ }
+
+ bm->map = bm_scanline(bm, bm->h - 1);
+ bm->dy = -dy;
+}
+
+/* resize the bitmap to the given new height. The bitmap data remains
+ bottom-aligned (truncated at the top) when dy >= 0 and top-aligned
+ (truncated at the bottom) when dy < 0. Return 0 on success, or 1 on
+ error with errno set. If the new height is <= the old one, no error
+ should occur. If the new height is larger, the additional bitmap
+ data is *not* initialized. */
+static inline int bm_resize(potrace_bitmap_t *bm, int h) {
+ int dy = bm->dy;
+ ptrdiff_t newsize;
+ potrace_word *newmap;
+
+ if (dy < 0) {
+ bm_flip(bm);
+ }
+
+ newsize = getsize(dy, h);
+ if (newsize < 0) {
+ errno = ENOMEM;
+ goto error;
+ }
+ if (newsize == 0) {
+ newsize = 1; /* make sure realloc() doesn't return NULL */
+ }
+
+ newmap = (potrace_word *)realloc(bm->map, newsize);
+ if (newmap == NULL) {
+ goto error;
+ }
+ bm->map = newmap;
+ bm->h = h;
+
+ if (dy < 0) {
+ bm_flip(bm);
+ }
+ return 0;
+
+ error:
+ if (dy < 0) {
+ bm_flip(bm);
}
+ return 1;
}
#endif /* BITMAP_H */
diff --git a/Build/source/libs/potrace/potrace-src/src/bitmap_io.c b/Build/source/libs/potrace/potrace-src/src/bitmap_io.c
index 8bbfe2dcdaa..26c532e2b3c 100644
--- a/Build/source/libs/potrace/potrace-src/src/bitmap_io.c
+++ b/Build/source/libs/potrace/potrace-src/src/bitmap_io.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -13,12 +13,17 @@
#include "bitmap.h"
#include "bitops.h"
+#include "bitmap_io.h"
#define INTBITS (8*sizeof(int))
static int bm_readbody_bmp(FILE *f, double threshold, potrace_bitmap_t **bmp);
static int bm_readbody_pnm(FILE *f, double threshold, potrace_bitmap_t **bmp, int magic);
+#define TRY(x) if (x) goto try_error
+#define TRY_EOF(x) if (x) goto eof
+#define TRY_STD(x) if (x) goto std_error
+
/* ---------------------------------------------------------------------- */
/* routines for reading pnm streams */
@@ -111,7 +116,7 @@ static int readbit(FILE *f) {
comments), -4 if wrong magic number. If the return value is >=0,
*bmp is valid. */
-char *bm_read_error = NULL;
+const char *bm_read_error = NULL;
int bm_read(FILE *f, double threshold, potrace_bitmap_t **bmp) {
int magic[2];
@@ -144,7 +149,9 @@ static int bm_readbody_pnm(FILE *f, double threshold, potrace_bitmap_t **bmp, in
int x, y, i, b, b1, sum;
int bpr; /* bytes per row (as opposed to 4*bm->c) */
int w, h, max;
-
+ int realheight; /* in case of incomplete file, keeps track of how
+ many scan lines actually contain data */
+
bm = NULL;
w = readnum(f);
@@ -160,12 +167,11 @@ static int bm_readbody_pnm(FILE *f, double threshold, potrace_bitmap_t **bmp, in
/* allocate bitmap */
bm = bm_new(w, h);
if (!bm) {
- return -1;
+ goto std_error;
}
- /* zero it out */
- bm_clear(bm, 0);
-
+ realheight = 0;
+
switch (magic) {
default:
/* not reached */
@@ -174,7 +180,8 @@ static int bm_readbody_pnm(FILE *f, double threshold, potrace_bitmap_t **bmp, in
case '1':
/* read P1 format: PBM ascii */
- for (y=h-1; y>=0; y--) {
+ for (y=0; y<h; y++) {
+ realheight = y+1;
for (x=0; x<w; x++) {
b = readbit(f);
if (b<0) {
@@ -193,7 +200,8 @@ static int bm_readbody_pnm(FILE *f, double threshold, potrace_bitmap_t **bmp, in
goto format_error;
}
- for (y=h-1; y>=0; y--) {
+ for (y=0; y<h; y++) {
+ realheight = y+1;
for (x=0; x<w; x++) {
b = readnum(f);
if (b<0) {
@@ -212,7 +220,8 @@ static int bm_readbody_pnm(FILE *f, double threshold, potrace_bitmap_t **bmp, in
goto format_error;
}
- for (y=h-1; y>=0; y--) {
+ for (y=0; y<h; y++) {
+ realheight = y+1;
for (x=0; x<w; x++) {
sum = 0;
for (i=0; i<3; i++) {
@@ -237,7 +246,8 @@ static int bm_readbody_pnm(FILE *f, double threshold, potrace_bitmap_t **bmp, in
bpr = (w+7)/8;
- for (y=h-1; y>=0; y--) {
+ for (y=0; y<h; y++) {
+ realheight = y+1;
for (i=0; i<bpr; i++) {
b = fgetc(f);
if (b==EOF) {
@@ -261,7 +271,8 @@ static int bm_readbody_pnm(FILE *f, double threshold, potrace_bitmap_t **bmp, in
goto format_error;
}
- for (y=h-1; y>=0; y--) {
+ for (y=0; y<h; y++) {
+ realheight = y+1;
for (x=0; x<w; x++) {
b = fgetc(f);
if (b==EOF)
@@ -291,7 +302,8 @@ static int bm_readbody_pnm(FILE *f, double threshold, potrace_bitmap_t **bmp, in
goto format_error;
}
- for (y=h-1; y>=0; y--) {
+ for (y=0; y<h; y++) {
+ realheight = y+1;
for (x=0; x<w; x++) {
sum = 0;
for (i=0; i<3; i++) {
@@ -314,10 +326,13 @@ static int bm_readbody_pnm(FILE *f, double threshold, potrace_bitmap_t **bmp, in
break;
}
+ bm_flip(bm);
*bmp = bm;
return 0;
eof:
+ TRY_STD(bm_resize(bm, realheight));
+ bm_flip(bm);
*bmp = bm;
return 1;
@@ -331,6 +346,10 @@ static int bm_readbody_pnm(FILE *f, double threshold, potrace_bitmap_t **bmp, in
bm_read_error = "invalid ppm file";
}
return -2;
+
+ std_error:
+ bm_free(bm);
+ return -1;
}
/* ---------------------------------------------------------------------- */
@@ -377,7 +396,7 @@ static int bmp_readint(FILE *f, int n, unsigned int *p) {
if (b==EOF) {
return 1;
}
- sum += b << (8*i);
+ sum += (unsigned)b << (8*i);
}
bmp_count += n;
bmp_pos += n;
@@ -422,12 +441,6 @@ static int bmp_forward(FILE *f, int pos) {
return 0;
}
-#define TRY(x) if (x) goto try_error
-#define TRY_EOF(x) if (x) goto eof
-
-/* correct y-coordinate for top-down format */
-#define ycorr(y) (bmpinfo.topdown ? bmpinfo.h-1-y : y)
-
/* safe colortable access */
#define COLTABLE(c) ((c) < bmpinfo.ncolors ? coltable[(c)] : 0)
@@ -451,7 +464,9 @@ static int bm_readbody_bmp(FILE *f, double threshold, potrace_bitmap_t **bmp) {
unsigned int n;
unsigned int redshift, greenshift, blueshift;
int col1[2];
-
+ int realheight; /* in case of incomplete file, keeps track of how
+ many scan lines actually contain data */
+
bm_read_error = NULL;
bm = NULL;
coltable = NULL;
@@ -528,7 +543,7 @@ static int bm_readbody_bmp(FILE *f, double threshold, potrace_bitmap_t **bmp) {
goto format_error; /* can't handle planes */
}
- if (bmpinfo.ncolors == 0) {
+ if (bmpinfo.ncolors == 0 && bmpinfo.bits <= 8) {
bmpinfo.ncolors = 1 << bmpinfo.bits;
}
@@ -560,10 +575,9 @@ static int bm_readbody_bmp(FILE *f, double threshold, potrace_bitmap_t **bmp) {
if (!bm) {
goto std_error;
}
-
- /* zero it out */
- bm_clear(bm, 0);
+ realheight = 0;
+
switch (bmpinfo.bits + 0x100*bmpinfo.comp) {
default:
@@ -579,11 +593,12 @@ static int bm_readbody_bmp(FILE *f, double threshold, potrace_bitmap_t **bmp) {
/* raster data */
for (y=0; y<bmpinfo.h; y++) {
+ realheight = y+1;
bmp_pad_reset();
for (i=0; 8*i<bmpinfo.w; i++) {
TRY_EOF(bmp_readint(f, 1, &b));
b ^= mask;
- *bm_index(bm, i*8, ycorr(y)) |= ((potrace_word)b) << (8*(BM_WORDSIZE-1-(i % BM_WORDSIZE)));
+ *bm_index(bm, i*8, y) |= ((potrace_word)b) << (8*(BM_WORDSIZE-1-(i % BM_WORDSIZE)));
}
TRY(bmp_pad(f));
}
@@ -597,6 +612,7 @@ static int bm_readbody_bmp(FILE *f, double threshold, potrace_bitmap_t **bmp) {
case 0x007:
case 0x008:
for (y=0; y<bmpinfo.h; y++) {
+ realheight = y+1;
bmp_pad_reset();
bitbuf = 0; /* bit buffer: bits in buffer are high-aligned */
n = 0; /* number of bits currently in bitbuffer */
@@ -609,7 +625,7 @@ static int bm_readbody_bmp(FILE *f, double threshold, potrace_bitmap_t **bmp) {
b = bitbuf >> (INTBITS - bmpinfo.bits);
bitbuf <<= bmpinfo.bits;
n -= bmpinfo.bits;
- BM_UPUT(bm, x, ycorr(y), COLTABLE(b));
+ BM_UPUT(bm, x, y, COLTABLE(b));
}
TRY(bmp_pad(f));
}
@@ -625,27 +641,33 @@ static int bm_readbody_bmp(FILE *f, double threshold, potrace_bitmap_t **bmp) {
case 0x018: /* 24-bit encoding */
case 0x020: /* 32-bit encoding */
for (y=0; y<bmpinfo.h; y++) {
+ realheight = y+1;
bmp_pad_reset();
for (x=0; x<bmpinfo.w; x++) {
TRY_EOF(bmp_readint(f, bmpinfo.bits/8, &c));
c = ((c>>16) & 0xff) + ((c>>8) & 0xff) + (c & 0xff);
- BM_UPUT(bm, x, ycorr(y), c > 3 * threshold * 255 ? 0 : 1);
+ BM_UPUT(bm, x, y, c > 3 * threshold * 255 ? 0 : 1);
}
TRY(bmp_pad(f));
}
break;
case 0x320: /* 32-bit encoding with bitfields */
+ if (bmpinfo.RedMask == 0 || bmpinfo.GreenMask == 0 || bmpinfo.BlueMask == 0) {
+ goto format_error;
+ }
+
redshift = lobit(bmpinfo.RedMask);
greenshift = lobit(bmpinfo.GreenMask);
blueshift = lobit(bmpinfo.BlueMask);
for (y=0; y<bmpinfo.h; y++) {
+ realheight = y+1;
bmp_pad_reset();
for (x=0; x<bmpinfo.w; x++) {
TRY_EOF(bmp_readint(f, bmpinfo.bits/8, &c));
c = ((c & bmpinfo.RedMask) >> redshift) + ((c & bmpinfo.GreenMask) >> greenshift) + ((c & bmpinfo.BlueMask) >> blueshift);
- BM_UPUT(bm, x, ycorr(y), c > 3 * threshold * 255 ? 0 : 1);
+ BM_UPUT(bm, x, y, c > 3 * threshold * 255 ? 0 : 1);
}
TRY(bmp_pad(f));
}
@@ -670,7 +692,8 @@ static int bm_readbody_bmp(FILE *f, double threshold, potrace_bitmap_t **bmp) {
if (y>=bmpinfo.h) {
break;
}
- BM_UPUT(bm, x, ycorr(y), col[i&1]);
+ realheight = y+1;
+ BM_UPUT(bm, x, y, col[i&1]);
x++;
}
} else if (c == 0) {
@@ -699,7 +722,8 @@ static int bm_readbody_bmp(FILE *f, double threshold, potrace_bitmap_t **bmp) {
if (y>=bmpinfo.h) {
break;
}
- BM_PUT(bm, x, ycorr(y), COLTABLE((b>>(4-4*(i&1))) & 0xf));
+ realheight = y+1;
+ BM_PUT(bm, x, y, COLTABLE((b>>(4-4*(i&1))) & 0xf));
x++;
}
if ((c+1) & 2) {
@@ -726,7 +750,8 @@ static int bm_readbody_bmp(FILE *f, double threshold, potrace_bitmap_t **bmp) {
if (y>=bmpinfo.h) {
break;
}
- BM_UPUT(bm, x, ycorr(y), COLTABLE(c));
+ realheight = y+1;
+ BM_UPUT(bm, x, y, COLTABLE(c));
x++;
}
} else if (c == 0) {
@@ -753,7 +778,8 @@ static int bm_readbody_bmp(FILE *f, double threshold, potrace_bitmap_t **bmp) {
if (y>=bmpinfo.h) {
break;
}
- BM_PUT(bm, x, ycorr(y), COLTABLE(b));
+ realheight = y+1;
+ BM_PUT(bm, x, y, COLTABLE(b));
x++;
}
if (c & 1) {
@@ -771,11 +797,18 @@ static int bm_readbody_bmp(FILE *f, double threshold, potrace_bitmap_t **bmp) {
bmp_forward(f, bmpinfo.FileSize);
free(coltable);
+ if (bmpinfo.topdown) {
+ bm_flip(bm);
+ }
*bmp = bm;
return 0;
eof:
+ TRY_STD(bm_resize(bm, realheight));
free(coltable);
+ if (bmpinfo.topdown) {
+ bm_flip(bm);
+ }
*bmp = bm;
return 1;
diff --git a/Build/source/libs/potrace/potrace-src/src/bitmap_io.h b/Build/source/libs/potrace/potrace-src/src/bitmap_io.h
index 04b1c9ca1d2..5bfa5af0c3a 100644
--- a/Build/source/libs/potrace/potrace-src/src/bitmap_io.h
+++ b/Build/source/libs/potrace/potrace-src/src/bitmap_io.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -13,7 +13,7 @@
/* Note that bitmaps are stored bottom to top, i.e., the first
scanline is the bottom-most one */
-extern char *bm_read_error;
+extern const char *bm_read_error;
int bm_read(FILE *f, double blacklevel, potrace_bitmap_t **bmp);
void bm_writepbm(FILE *f, potrace_bitmap_t *bm);
diff --git a/Build/source/libs/potrace/potrace-src/src/bitops.h b/Build/source/libs/potrace/potrace-src/src/bitops.h
index ba84b53269b..e7e7ed36247 100644
--- a/Build/source/libs/potrace/potrace-src/src/bitops.h
+++ b/Build/source/libs/potrace/potrace-src/src/bitops.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/curve.c b/Build/source/libs/potrace/potrace-src/src/curve.c
index d782f22ea65..0f415559589 100644
--- a/Build/source/libs/potrace/potrace-src/src/curve.c
+++ b/Build/source/libs/potrace/potrace-src/src/curve.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/curve.h b/Build/source/libs/potrace/potrace-src/src/curve.h
index feb95b39b49..00f042cc228 100644
--- a/Build/source/libs/potrace/potrace-src/src/curve.h
+++ b/Build/source/libs/potrace/potrace-src/src/curve.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/decompose.c b/Build/source/libs/potrace/potrace-src/src/decompose.c
index 26126377ad8..060a53d28a3 100644
--- a/Build/source/libs/potrace/potrace-src/src/decompose.c
+++ b/Build/source/libs/potrace/potrace-src/src/decompose.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -432,7 +432,7 @@ static int findnext(potrace_bitmap_t *bm, int *xp, int *yp) {
x0 = (*xp) & ~(BM_WORDBITS-1);
for (y=*yp; y>=0; y--) {
- for (x=x0; x<bm->w; x+=BM_WORDBITS) {
+ for (x=x0; x<bm->w && x>=0; x+=(unsigned)BM_WORDBITS) {
if (*bm_index(bm, x, y)) {
while (!BM_GET(bm, x, y)) {
x++;
diff --git a/Build/source/libs/potrace/potrace-src/src/decompose.h b/Build/source/libs/potrace/potrace-src/src/decompose.h
index 8ae89b8adc3..a80a480ccbf 100644
--- a/Build/source/libs/potrace/potrace-src/src/decompose.h
+++ b/Build/source/libs/potrace/potrace-src/src/decompose.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/flate.c b/Build/source/libs/potrace/potrace-src/src/flate.c
index 9965d15d3f0..5c81894d910 100644
--- a/Build/source/libs/potrace/potrace-src/src/flate.c
+++ b/Build/source/libs/potrace/potrace-src/src/flate.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -42,14 +42,14 @@
static int a85init(FILE *f);
static int a85finish(FILE *f);
-static int a85write(FILE *f, char *buf, int n);
+static int a85write(FILE *f, const char *buf, int n);
static int a85out(FILE *f, int n);
static int a85spool(FILE *f, char c);
/* ---------------------------------------------------------------------- */
/* dummy interface: no encoding */
-int dummy_xship(FILE *f, int filter, char *s, int len) {
+int dummy_xship(FILE *f, int filter, const char *s, int len) {
fwrite(s, 1, len, f);
return len;
}
@@ -59,7 +59,7 @@ int dummy_xship(FILE *f, int filter, char *s, int len) {
#ifdef HAVE_ZLIB
-int pdf_xship(FILE *f, int filter, char *s, int len) {
+int pdf_xship(FILE *f, int filter, const char *s, int len) {
static int fstate = 0;
static z_stream c_stream;
char outbuf[OUTSIZE];
@@ -74,7 +74,7 @@ int pdf_xship(FILE *f, int filter, char *s, int len) {
err = deflateInit(&c_stream, 9);
if (err != Z_OK) {
fprintf(stderr, "deflateInit: %s (%d)\n", c_stream.msg, err);
- exit(1);
+ exit(2);
}
c_stream.avail_in = 0;
fstate = 1;
@@ -88,7 +88,7 @@ int pdf_xship(FILE *f, int filter, char *s, int len) {
err = deflate(&c_stream, Z_FINISH);
if (err != Z_OK && err != Z_STREAM_END) {
fprintf(stderr, "deflate: %s (%d)\n", c_stream.msg, err);
- exit(1);
+ exit(2);
}
n += fwrite(outbuf, 1, OUTSIZE-c_stream.avail_out, f);
} while (err != Z_STREAM_END);
@@ -111,7 +111,7 @@ int pdf_xship(FILE *f, int filter, char *s, int len) {
err = deflate(&c_stream, Z_NO_FLUSH);
if (err != Z_OK) {
fprintf(stderr, "deflate: %s (%d)\n", c_stream.msg, err);
- exit(1);
+ exit(2);
}
n += fwrite(outbuf, 1, OUTSIZE-c_stream.avail_out, f);
} while (!c_stream.avail_out);
@@ -120,7 +120,7 @@ int pdf_xship(FILE *f, int filter, char *s, int len) {
}
/* ship len bytes from s using zlib compression. */
-int flate_xship(FILE *f, int filter, char *s, int len) {
+int flate_xship(FILE *f, int filter, const char *s, int len) {
static int fstate = 0;
static z_stream c_stream;
char outbuf[OUTSIZE];
@@ -138,7 +138,7 @@ int flate_xship(FILE *f, int filter, char *s, int len) {
err = deflateInit(&c_stream, 9);
if (err != Z_OK) {
fprintf(stderr, "deflateInit: %s (%d)\n", c_stream.msg, err);
- exit(1);
+ exit(2);
}
c_stream.avail_in = 0;
n += a85init(f);
@@ -153,7 +153,7 @@ int flate_xship(FILE *f, int filter, char *s, int len) {
err = deflate(&c_stream, Z_FINISH);
if (err != Z_OK && err != Z_STREAM_END) {
fprintf(stderr, "deflate: %s (%d)\n", c_stream.msg, err);
- exit(1);
+ exit(2);
}
n += a85write(f, outbuf, OUTSIZE-c_stream.avail_out);
} while (err != Z_STREAM_END);
@@ -178,7 +178,7 @@ int flate_xship(FILE *f, int filter, char *s, int len) {
err = deflate(&c_stream, Z_NO_FLUSH);
if (err != Z_OK) {
fprintf(stderr, "deflate: %s (%d)\n", c_stream.msg, err);
- exit(1);
+ exit(2);
}
n += a85write(f, outbuf, OUTSIZE-c_stream.avail_out);
} while (!c_stream.avail_out);
@@ -188,11 +188,11 @@ int flate_xship(FILE *f, int filter, char *s, int len) {
#else /* HAVE_ZLIB */
-int pdf_xship(FILE *f, int filter, char *s, int len) {
+int pdf_xship(FILE *f, int filter, const char *s, int len) {
return dummy_xship(f, filter, s, len);
}
-int flate_xship(FILE *f, int filter, char *s, int len) {
+int flate_xship(FILE *f, int filter, const char *s, int len) {
return dummy_xship(f, filter, s, len);
}
@@ -203,7 +203,7 @@ int flate_xship(FILE *f, int filter, char *s, int len) {
This relies on lzw.c/h to do the actual compression. */
/* use Postscript level 2 compression. Ship len bytes from str. */
-int lzw_xship(FILE *f, int filter, char *str, int len) {
+int lzw_xship(FILE *f, int filter, const char *str, int len) {
static int fstate = 0;
static lzw_stream_t *s = NULL;
char outbuf[OUTSIZE];
@@ -218,7 +218,7 @@ int lzw_xship(FILE *f, int filter, char *str, int len) {
s = lzw_init();
if (s == NULL) {
fprintf(stderr, "lzw_init: %s\n", strerror(errno));
- exit(1);
+ exit(2);
}
n += a85init(f);
fstate = 1;
@@ -234,7 +234,7 @@ int lzw_xship(FILE *f, int filter, char *str, int len) {
err = lzw_compress(s, LZW_EOD);
if (err) {
fprintf(stderr, "lzw_compress: %s\n", strerror(errno));
- exit(1);
+ exit(2);
}
n += a85write(f, outbuf, OUTSIZE - s->avail_out);
} while (s->avail_out == 0);
@@ -262,7 +262,7 @@ int lzw_xship(FILE *f, int filter, char *str, int len) {
err = lzw_compress(s, LZW_NORMAL);
if (err) {
fprintf(stderr, "lzw_compress: %s\n", strerror(errno));
- exit(1);
+ exit(2);
}
n += a85write(f, outbuf, OUTSIZE - s->avail_out);
} while (s->avail_out == 0);
@@ -274,7 +274,7 @@ int lzw_xship(FILE *f, int filter, char *str, int len) {
/* a85 interface: a85 encoding without compression */
/* ship len bytes from s using a85 encoding only. */
-int a85_xship(FILE *f, int filter, char *s, int len) {
+int a85_xship(FILE *f, int filter, const char *s, int len) {
static int fstate = 0;
int n=0;
@@ -324,7 +324,7 @@ static int a85finish(FILE *f) {
return r+2;
}
-static int a85write(FILE *f, char *buf, int n) {
+static int a85write(FILE *f, const char *buf, int n) {
int i;
int r=0;
diff --git a/Build/source/libs/potrace/potrace-src/src/flate.h b/Build/source/libs/potrace/potrace-src/src/flate.h
index 7b51245503d..d3a9961bcfd 100644
--- a/Build/source/libs/potrace/potrace-src/src/flate.h
+++ b/Build/source/libs/potrace/potrace-src/src/flate.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -6,10 +6,10 @@
#ifndef FLATE_H
#define FLATE_H
-int dummy_xship(FILE *f, int filter, char *s, int len);
-int flate_xship(FILE *f, int filter, char *s, int len);
-int pdf_xship(FILE *f, int filter, char *s, int len);
-int lzw_xship(FILE *f, int filter, char *s, int len);
-int a85_xship(FILE *f, int filter, char *s, int len);
+int dummy_xship(FILE *f, int filter, const char *s, int len);
+int flate_xship(FILE *f, int filter, const char *s, int len);
+int pdf_xship(FILE *f, int filter, const char *s, int len);
+int lzw_xship(FILE *f, int filter, const char *s, int len);
+int a85_xship(FILE *f, int filter, const char *s, int len);
#endif /* FLATE_H */
diff --git a/Build/source/libs/potrace/potrace-src/src/greymap.c b/Build/source/libs/potrace/potrace-src/src/greymap.c
index ad8e5d7e303..785774dd8da 100644
--- a/Build/source/libs/potrace/potrace-src/src/greymap.c
+++ b/Build/source/libs/potrace/potrace-src/src/greymap.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -26,39 +26,79 @@
static int gm_readbody_pnm(FILE *f, greymap_t **gmp, int magic);
static int gm_readbody_bmp(FILE *f, greymap_t **gmp);
+#define TRY(x) if (x) goto try_error
+#define TRY_EOF(x) if (x) goto eof
+#define TRY_STD(x) if (x) goto std_error
+
/* ---------------------------------------------------------------------- */
/* basic greymap routines */
-/* return new un-initialized greymap. NULL with errno on error.
+/* calculate the size, in bytes, required for the data area of a
+ greymap of the given dy and h. Assume h >= 0. Return -1 if the size
+ does not fit into the ptrdiff_t type. */
+static inline ptrdiff_t getsize(int dy, int h) {
+ ptrdiff_t size;
+
+ if (dy < 0) {
+ dy = -dy;
+ }
+
+ size = (ptrdiff_t)dy * (ptrdiff_t)h * (ptrdiff_t)sizeof(gm_sample_t);
+
+ /* check for overflow error */
+ if (size < 0 || (h != 0 && dy != 0 && size / h / dy != sizeof(gm_sample_t))) {
+ return -1;
+ }
+
+ return size;
+}
+
+/* return the size, in bytes, of the data area of the greymap. Return
+ -1 if the size does not fit into the ptrdiff_t type; however, this
+ cannot happen if the bitmap is well-formed, i.e., if created with
+ gm_new or gm_dup. */
+static inline ptrdiff_t gm_size(const greymap_t *gm) {
+ return getsize(gm->dy, gm->h);
+}
+
+
+
+/* return new greymap initialized to 0. NULL with errno on error.
Assumes w, h >= 0. */
greymap_t *gm_new(int w, int h) {
greymap_t *gm;
- ptrdiff_t size = (ptrdiff_t)w * (ptrdiff_t)h * (ptrdiff_t)sizeof(signed short int);
-
- /* check for overflow error */
- if (size < 0 || size / w / h != sizeof(signed short int)) {
+ int dy = w;
+ ptrdiff_t size;
+
+ size = getsize(dy, h);
+ if (size < 0) {
errno = ENOMEM;
return NULL;
}
-
+ if (size == 0) {
+ size = 1; /* make surecmalloc() doesn't return NULL */
+ }
+
gm = (greymap_t *) malloc(sizeof(greymap_t));
if (!gm) {
return NULL;
}
gm->w = w;
gm->h = h;
- gm->map = (signed short int *) malloc(size);
- if (!gm->map) {
+ gm->dy = dy;
+ gm->base = (gm_sample_t *) calloc(1, size);
+ if (!gm->base) {
free(gm);
return NULL;
}
+ gm->map = gm->base;
return gm;
}
/* free the given greymap */
void gm_free(greymap_t *gm) {
if (gm) {
- free(gm->map);
+ free(gm->base);
}
free(gm);
}
@@ -66,26 +106,91 @@ void gm_free(greymap_t *gm) {
/* duplicate the given greymap. Return NULL on error with errno set. */
greymap_t *gm_dup(greymap_t *gm) {
greymap_t *gm1 = gm_new(gm->w, gm->h);
+ int y;
+
if (!gm1) {
return NULL;
}
- memcpy(gm1->map, gm->map, gm->w*gm->h*sizeof(signed short int));
+ for (y=0; y<gm->h; y++) {
+ memcpy(gm_scanline(gm1, y), gm_scanline(gm, y), (size_t)gm1->dy * sizeof(gm_sample_t));
+ }
return gm1;
}
/* clear the given greymap to color b. */
void gm_clear(greymap_t *gm, int b) {
- int i;
-
+ ptrdiff_t size = gm_size(gm);
+ int x, y;
+
if (b==0) {
- memset(gm->map, 0, gm->w*gm->h*sizeof(signed short int));
+ memset(gm->base, 0, size);
} else {
- for (i=0; i<gm->w*gm->h; i++) {
- gm->map[i] = b;
+ for (y=0; y<gm->h; y++) {
+ for (x=0; x<gm->w; x++) {
+ GM_UPUT(gm, x, y, b);
+ }
}
- }
+ }
+}
+
+/* turn the given greymap upside down. This does not move the pixel
+ data or change the base address. */
+static inline void gm_flip(greymap_t *gm) {
+ int dy = gm->dy;
+
+ if (gm->h == 0 || gm->h == 1) {
+ return;
+ }
+
+ gm->map = gm_scanline(gm, gm->h - 1);
+ gm->dy = -dy;
+}
+
+/* resize the greymap to the given new height. The pixel data remains
+ bottom-aligned (truncated at the top) when dy >= 0 and top-aligned
+ (truncated at the bottom) when dy < 0. Return 0 on success, or 1 on
+ error with errno set. If the new height is <= the old one, no error
+ should occur. If the new height is larger, the additional pixel
+ data is *not* initialized. */
+static inline int gm_resize(greymap_t *gm, int h) {
+ int dy = gm->dy;
+ ptrdiff_t newsize;
+ gm_sample_t *newbase;
+
+ if (dy < 0) {
+ gm_flip(gm);
+ }
+
+ newsize = getsize(dy, h);
+ if (newsize < 0) {
+ errno = ENOMEM;
+ goto error;
+ }
+ if (newsize == 0) {
+ newsize = 1; /* make sure realloc() doesn't return NULL */
+ }
+
+ newbase = (gm_sample_t *)realloc(gm->base, newsize);
+ if (newbase == NULL) {
+ goto error;
+ }
+ gm->base = newbase;
+ gm->map = newbase;
+ gm->h = h;
+
+ if (dy < 0) {
+ gm_flip(gm);
+ }
+ return 0;
+
+ error:
+ if (dy < 0) {
+ gm_flip(gm);
+ }
+ return 1;
}
+
/* ---------------------------------------------------------------------- */
/* routines for reading pnm streams */
@@ -178,7 +283,7 @@ static int readbit(FILE *f) {
-4 if wrong magic number. If the return value is >=0, *gmp is
valid. */
-char *gm_read_error = NULL;
+const char *gm_read_error = NULL;
int gm_read(FILE *f, greymap_t **gmp) {
int magic[2];
@@ -212,7 +317,9 @@ static int gm_readbody_pnm(FILE *f, greymap_t **gmp, int magic) {
int x, y, i, j, b, b1, sum;
int bpr; /* bytes per row (as opposed to 4*gm->c) */
int w, h, max;
-
+ int realheight; /* in case of incomplete file, keeps track of how
+ many scan lines actually contain data */
+
gm = NULL;
w = readnum(f);
@@ -228,11 +335,10 @@ static int gm_readbody_pnm(FILE *f, greymap_t **gmp, int magic) {
/* allocate greymap */
gm = gm_new(w, h);
if (!gm) {
- return -1;
+ goto std_error;
}
- /* zero it out */
- gm_clear(gm, 0);
+ realheight = 0;
switch (magic) {
default:
@@ -242,7 +348,8 @@ static int gm_readbody_pnm(FILE *f, greymap_t **gmp, int magic) {
case '1':
/* read P1 format: PBM ascii */
- for (y=h-1; y>=0; y--) {
+ for (y=0; y<h; y++) {
+ realheight = y+1;
for (x=0; x<w; x++) {
b = readbit(f);
if (b<0) {
@@ -261,7 +368,8 @@ static int gm_readbody_pnm(FILE *f, greymap_t **gmp, int magic) {
goto format_error;
}
- for (y=h-1; y>=0; y--) {
+ for (y=0; y<h; y++) {
+ realheight = y+1;
for (x=0; x<w; x++) {
b = readnum(f);
if (b<0) {
@@ -280,7 +388,8 @@ static int gm_readbody_pnm(FILE *f, greymap_t **gmp, int magic) {
goto format_error;
}
- for (y=h-1; y>=0; y--) {
+ for (y=0; y<h; y++) {
+ realheight = y+1;
for (x=0; x<w; x++) {
sum = 0;
for (i=0; i<3; i++) {
@@ -305,7 +414,8 @@ static int gm_readbody_pnm(FILE *f, greymap_t **gmp, int magic) {
bpr = (w+7)/8;
- for (y=h-1; y>=0; y--) {
+ for (y=0; y<h; y++) {
+ realheight = y+1;
for (i=0; i<bpr; i++) {
b = fgetc(f);
if (b==EOF) {
@@ -331,7 +441,8 @@ static int gm_readbody_pnm(FILE *f, greymap_t **gmp, int magic) {
goto format_error;
}
- for (y=h-1; y>=0; y--) {
+ for (y=0; y<h; y++) {
+ realheight = y+1;
for (x=0; x<w; x++) {
b = fgetc(f);
if (b==EOF)
@@ -361,7 +472,8 @@ static int gm_readbody_pnm(FILE *f, greymap_t **gmp, int magic) {
goto format_error;
}
- for (y=h-1; y>=0; y--) {
+ for (y=0; y<h; y++) {
+ realheight = y+1;
for (x=0; x<w; x++) {
sum = 0;
for (i=0; i<3; i++) {
@@ -384,10 +496,13 @@ static int gm_readbody_pnm(FILE *f, greymap_t **gmp, int magic) {
break;
}
+ gm_flip(gm);
*gmp = gm;
return 0;
eof:
+ TRY_STD(gm_resize(gm, realheight));
+ gm_flip(gm);
*gmp = gm;
return 1;
@@ -401,6 +516,10 @@ static int gm_readbody_pnm(FILE *f, greymap_t **gmp, int magic) {
gm_read_error = "invalid ppm file";
}
return -2;
+
+ std_error:
+ gm_free(gm);
+ return -1;
}
/* ---------------------------------------------------------------------- */
@@ -447,7 +566,7 @@ static int bmp_readint(FILE *f, int n, unsigned int *p) {
if (b==EOF) {
return 1;
}
- sum += b << (8*i);
+ sum += (unsigned)b << (8*i);
}
bmp_count += n;
bmp_pos += n;
@@ -492,11 +611,8 @@ static int bmp_forward(FILE *f, int pos) {
return 0;
}
-#define TRY(x) if (x) goto try_error
-#define TRY_EOF(x) if (x) goto eof
-
-/* correct y-coordinate for top-down format */
-#define ycorr(y) (bmpinfo.topdown ? bmpinfo.h-1-y : y)
+/* safe colortable access */
+#define COLTABLE(c) ((c) < bmpinfo.ncolors ? coltable[(c)] : 0)
/* read BMP stream after magic number. Return values as for gm_read.
We choose to be as permissive as possible, since there are many
@@ -516,6 +632,8 @@ static int gm_readbody_bmp(FILE *f, greymap_t **gmp) {
unsigned int bitbuf;
unsigned int n;
unsigned int redshift, greenshift, blueshift;
+ int realheight; /* in case of incomplete file, keeps track of how
+ many scan lines actually contain data */
gm_read_error = NULL;
gm = NULL;
@@ -581,6 +699,10 @@ static int gm_readbody_bmp(FILE *f, greymap_t **gmp) {
goto format_error;
}
+ if (bmpinfo.comp > 3 || bmpinfo.bits > 32) {
+ goto format_error;
+ }
+
/* forward to color table (e.g., if bmpinfo.InfoSize == 64) */
TRY(bmp_forward(f, 14+bmpinfo.InfoSize));
@@ -589,7 +711,7 @@ static int gm_readbody_bmp(FILE *f, greymap_t **gmp) {
goto format_error; /* can't handle planes */
}
- if (bmpinfo.ncolors == 0) {
+ if (bmpinfo.ncolors == 0 && bmpinfo.bits <= 8) {
bmpinfo.ncolors = 1 << bmpinfo.bits;
}
@@ -618,10 +740,9 @@ static int gm_readbody_bmp(FILE *f, greymap_t **gmp) {
if (!gm) {
goto std_error;
}
-
- /* zero it out */
- gm_clear(gm, 0);
+ realheight = 0;
+
switch (bmpinfo.bits + 0x100*bmpinfo.comp) {
default:
@@ -632,11 +753,12 @@ static int gm_readbody_bmp(FILE *f, greymap_t **gmp) {
/* raster data */
for (y=0; y<bmpinfo.h; y++) {
+ realheight = y+1;
bmp_pad_reset();
for (i=0; 8*i<bmpinfo.w; i++) {
TRY_EOF(bmp_readint(f, 1, &b));
for (j=0; j<8; j++) {
- GM_PUT(gm, i*8+j, ycorr(y), b & (0x80 >> j) ? coltable[1] : coltable[0]);
+ GM_PUT(gm, i*8+j, y, b & (0x80 >> j) ? COLTABLE(1) : COLTABLE(0));
}
}
TRY(bmp_pad(f));
@@ -651,6 +773,7 @@ static int gm_readbody_bmp(FILE *f, greymap_t **gmp) {
case 0x007:
case 0x008:
for (y=0; y<bmpinfo.h; y++) {
+ realheight = y+1;
bmp_pad_reset();
bitbuf = 0; /* bit buffer: bits in buffer are high-aligned */
n = 0; /* number of bits currently in bitbuffer */
@@ -663,7 +786,7 @@ static int gm_readbody_bmp(FILE *f, greymap_t **gmp) {
b = bitbuf >> (INTBITS - bmpinfo.bits);
bitbuf <<= bmpinfo.bits;
n -= bmpinfo.bits;
- GM_UPUT(gm, x, ycorr(y), coltable[b]);
+ GM_UPUT(gm, x, y, COLTABLE(b));
}
TRY(bmp_pad(f));
}
@@ -679,11 +802,12 @@ static int gm_readbody_bmp(FILE *f, greymap_t **gmp) {
case 0x018: /* 24-bit encoding */
case 0x020: /* 32-bit encoding */
for (y=0; y<bmpinfo.h; y++) {
+ realheight = y+1;
bmp_pad_reset();
for (x=0; x<bmpinfo.w; x++) {
TRY_EOF(bmp_readint(f, bmpinfo.bits/8, &c));
c = ((c>>16) & 0xff) + ((c>>8) & 0xff) + (c & 0xff);
- GM_UPUT(gm, x, ycorr(y), c/3);
+ GM_UPUT(gm, x, y, c/3);
}
TRY(bmp_pad(f));
}
@@ -695,11 +819,12 @@ static int gm_readbody_bmp(FILE *f, greymap_t **gmp) {
blueshift = lobit(bmpinfo.BlueMask);
for (y=0; y<bmpinfo.h; y++) {
+ realheight = y+1;
bmp_pad_reset();
for (x=0; x<bmpinfo.w; x++) {
TRY_EOF(bmp_readint(f, bmpinfo.bits/8, &c));
c = ((c & bmpinfo.RedMask) >> redshift) + ((c & bmpinfo.GreenMask) >> greenshift) + ((c & bmpinfo.BlueMask) >> blueshift);
- GM_UPUT(gm, x, ycorr(y), c/3);
+ GM_UPUT(gm, x, y, c/3);
}
TRY(bmp_pad(f));
}
@@ -713,8 +838,8 @@ static int gm_readbody_bmp(FILE *f, greymap_t **gmp) {
TRY_EOF(bmp_readint(f, 1, &c)); /* argument */
if (b>0) {
/* repeat count */
- col[0] = coltable[(c>>4) & 0xf];
- col[1] = coltable[c & 0xf];
+ col[0] = COLTABLE((c>>4) & 0xf);
+ col[1] = COLTABLE(c & 0xf);
for (i=0; i<b && x<bmpinfo.w; i++) {
if (x>=bmpinfo.w) {
x=0;
@@ -723,7 +848,8 @@ static int gm_readbody_bmp(FILE *f, greymap_t **gmp) {
if (y>=bmpinfo.h) {
break;
}
- GM_UPUT(gm, x, ycorr(y), col[i&1]);
+ realheight = y+1;
+ GM_UPUT(gm, x, y, col[i&1]);
x++;
}
} else if (c == 0) {
@@ -752,7 +878,8 @@ static int gm_readbody_bmp(FILE *f, greymap_t **gmp) {
if (y>=bmpinfo.h) {
break;
}
- GM_PUT(gm, x, ycorr(y), coltable[(b>>(4-4*(i&1))) & 0xf]);
+ realheight = y+1;
+ GM_PUT(gm, x, y, COLTABLE((b>>(4-4*(i&1))) & 0xf));
x++;
}
if ((c+1) & 2) {
@@ -779,7 +906,8 @@ static int gm_readbody_bmp(FILE *f, greymap_t **gmp) {
if (y>=bmpinfo.h) {
break;
}
- GM_UPUT(gm, x, ycorr(y), coltable[c]);
+ realheight = y+1;
+ GM_UPUT(gm, x, y, COLTABLE(c));
x++;
}
} else if (c == 0) {
@@ -806,7 +934,8 @@ static int gm_readbody_bmp(FILE *f, greymap_t **gmp) {
if (y>=bmpinfo.h) {
break;
}
- GM_PUT(gm, x, ycorr(y), coltable[b]);
+ realheight = y+1;
+ GM_PUT(gm, x, y, COLTABLE(b));
x++;
}
if (c & 1) {
@@ -824,18 +953,25 @@ static int gm_readbody_bmp(FILE *f, greymap_t **gmp) {
bmp_forward(f, bmpinfo.FileSize);
free(coltable);
+ if (bmpinfo.topdown) {
+ gm_flip(gm);
+ }
*gmp = gm;
return 0;
eof:
+ TRY_STD(gm_resize(gm, realheight));
free(coltable);
+ if (bmpinfo.topdown) {
+ gm_flip(gm);
+ }
*gmp = gm;
return 1;
format_error:
try_error:
free(coltable);
- free(gm);
+ gm_free(gm);
if (!gm_read_error) {
gm_read_error = "invalid bmp file";
}
@@ -843,7 +979,7 @@ static int gm_readbody_bmp(FILE *f, greymap_t **gmp) {
std_error:
free(coltable);
- free(gm);
+ gm_free(gm);
return -1;
}
@@ -855,7 +991,7 @@ static int gm_readbody_bmp(FILE *f, greymap_t **gmp) {
if any (set to 2.2 if the image is to look optimal on a CRT monitor,
2.8 for LCD). Set to 1.0 for no gamma correction */
-int gm_writepgm(FILE *f, greymap_t *gm, char *comment, int raw, int mode, double gamma) {
+int gm_writepgm(FILE *f, greymap_t *gm, const char *comment, int raw, int mode, double gamma) {
int x, y, v;
int gammatable[256];
diff --git a/Build/source/libs/potrace/potrace-src/src/greymap.h b/Build/source/libs/potrace/potrace-src/src/greymap.h
index 7a5011ab8f8..7471ebf64bb 100644
--- a/Build/source/libs/potrace/potrace-src/src/greymap.h
+++ b/Build/source/libs/potrace/potrace-src/src/greymap.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -10,27 +10,33 @@
#include <stdlib.h>
#include <stddef.h>
+/* type for greymap samples */
+typedef signed short int gm_sample_t;
+
/* internal format for greymaps. Note: in this format, rows are
ordered from bottom to top. The pixels in each row are given from
left to right. */
-
struct greymap_s {
- int w; /* width, in pixels */
- int h; /* height, in pixels */
- signed short int *map; /* raw data, w*h values */
+ int w; /* width, in pixels */
+ int h; /* height, in pixels */
+ int dy; /* offset between scanlines (in samples);
+ can be negative */
+ gm_sample_t *base; /* root of allocated data */
+ gm_sample_t *map; /* points to the lower left pixel */
};
typedef struct greymap_s greymap_t;
/* macros for accessing pixel at index (x,y). Note that the origin is
in the *lower* left corner. U* macros omit the bounds check. */
-#define gm_index(gm, x, y) (&(gm)->map[(x)+(y)*(ptrdiff_t)(gm)->w])
+#define gm_scanline(gm, y) ((gm)->map + (ptrdiff_t)(y)*(ptrdiff_t)(gm)->dy)
+#define gm_index(gm, x, y) (gm_scanline(gm, y) + (x))
#define gm_safe(gm, x, y) ((int)(x)>=0 && (int)(x)<(gm)->w && (int)(y)>=0 && (int)(y)<(gm)->h)
#define gm_bound(x, m) ((x)<0 ? 0 : (x)>=(m) ? (m)-1 : (x))
#define GM_UGET(gm, x, y) (*gm_index(gm, x, y))
-#define GM_UINC(gm, x, y, b) (*gm_index(gm, x, y) += (short int)(b))
+#define GM_UINC(gm, x, y, b) (*gm_index(gm, x, y) += (gm_sample_t)(b))
#define GM_UINV(gm, x, y) (*gm_index(gm, x, y) = 255 - *gm_index(gm, x, y))
-#define GM_UPUT(gm, x, y, b) (*gm_index(gm, x, y) = (short int)(b))
+#define GM_UPUT(gm, x, y, b) (*gm_index(gm, x, y) = (gm_sample_t)(b))
#define GM_GET(gm, x, y) (gm_safe(gm, x, y) ? GM_UGET(gm, x, y) : 0)
#define GM_INC(gm, x, y, b) (gm_safe(gm, x, y) ? GM_UINC(gm, x, y, b) : 0)
#define GM_INV(gm, x, y) (gm_safe(gm, x, y) ? GM_UINV(gm, x, y) : 0)
@@ -46,14 +52,14 @@ typedef struct greymap_s greymap_t;
#define GM_MODE_POSITIVE 3
#define GM_MODE_NEGATIVE 4
-extern char *gm_read_error;
+extern const char *gm_read_error;
greymap_t *gm_new(int w, int h);
greymap_t *gm_dup(greymap_t *gm);
void gm_free(greymap_t *gm);
void gm_clear(greymap_t *gm, int b);
int gm_read(FILE *f, greymap_t **gmp);
-int gm_writepgm(FILE *f, greymap_t *gm, char *comment, int raw, int mode, double gamma);
+int gm_writepgm(FILE *f, greymap_t *gm, const char *comment, int raw, int mode, double gamma);
int gm_print(FILE *f, greymap_t *gm);
#endif /* GREYMAP_H */
diff --git a/Build/source/libs/potrace/potrace-src/src/lists.h b/Build/source/libs/potrace/potrace-src/src/lists.h
index 394262c23ee..f76bdcde14b 100644
--- a/Build/source/libs/potrace/potrace-src/src/lists.h
+++ b/Build/source/libs/potrace/potrace-src/src/lists.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/lzw.c b/Build/source/libs/potrace/potrace-src/src/lzw.c
index 5281bba274b..dc9d6f761d1 100644
--- a/Build/source/libs/potrace/potrace-src/src/lzw.c
+++ b/Build/source/libs/potrace/potrace-src/src/lzw.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -86,9 +86,9 @@
created until it is accessed. */
struct lzw_dict_s {
- char c; /* last character of string represented by this entry */
- int code; /* code for the string represented by this entry */
- int freq; /* how often searched? For optimization only */
+ char c; /* last character of string represented by this entry */
+ unsigned int code; /* code for the string represented by this entry */
+ int freq; /* how often searched? For optimization only */
struct lzw_dict_s *children; /* list of sub-entries */
struct lzw_dict_s *next; /* for making a linked list */
};
@@ -104,8 +104,8 @@ typedef struct lzw_dict_s lzw_dict_t;
struct lzw_state_s {
/* dictionary state */
int n; /* current size of the dictionary */
- lzw_dict_t *d; /* pointer to dictionary */
- lzw_dict_t *s; /* pointer to current string, or NULL at beginning */
+ lzw_dict_t *d; /* pointer to dictionary */
+ lzw_dict_t *s; /* pointer to current string, or NULL at beginning */
/* buffers for pending output */
BITBUF_TYPE buf; /* bits scheduled for output - left aligned, 0 padded */
@@ -143,7 +143,7 @@ static void lzw_clear_table(lzw_state_t *st) {
/* write the code to the bit buffer. Precondition st->bufsize <= 7.
Note: this does not change the dictionary state; in particular,
n must be updated between consecutive calls. */
-static inline void lzw_emit(int code, lzw_state_t *st) {
+static inline void lzw_emit(unsigned int code, lzw_state_t *st) {
BITBUF_TYPE mask;
int bits = hibit(st->n);
@@ -232,7 +232,7 @@ static int lzw_encode_char(lzw_state_t *st, char c) {
return 1;
}
e->c = c;
- e->code = (int)(unsigned char)c;
+ e->code = (unsigned char)c;
e->freq = 0;
e->children = NULL;
list_prepend(st->d, e);
diff --git a/Build/source/libs/potrace/potrace-src/src/lzw.h b/Build/source/libs/potrace/potrace-src/src/lzw.h
index 8ac3ed6a109..f30fc49ad34 100644
--- a/Build/source/libs/potrace/potrace-src/src/lzw.h
+++ b/Build/source/libs/potrace/potrace-src/src/lzw.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -9,12 +9,12 @@
/* user visible state */
struct lzw_stream_s {
- char *next_in; /* pointer to next input character */
- int avail_in; /* number of input chars available */
- char *next_out; /* pointer to next free byte in output buffer */
- int avail_out; /* remaining size of output buffer */
+ const char *next_in; /* pointer to next input character */
+ int avail_in; /* number of input chars available */
+ char *next_out; /* pointer to next free byte in output buffer */
+ int avail_out; /* remaining size of output buffer */
- void *internal; /* internal state, not user accessible */
+ void *internal; /* internal state, not user accessible */
};
typedef struct lzw_stream_s lzw_stream_t;
diff --git a/Build/source/libs/potrace/potrace-src/src/main.c b/Build/source/libs/potrace/potrace-src/src/main.c
index a28a25ed40d..1983f97b2c0 100644
--- a/Build/source/libs/potrace/potrace-src/src/main.c
+++ b/Build/source/libs/potrace/potrace-src/src/main.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -45,7 +45,7 @@ struct info_s info;
/* some data structures for option processing */
struct pageformat_s {
- char *name;
+ const char *name;
int w, h;
};
typedef struct pageformat_s pageformat_t;
@@ -68,7 +68,7 @@ static pageformat_t pageformat[] = {
};
struct turnpolicy_s {
- char *name;
+ const char *name;
int n;
};
typedef struct turnpolicy_s turnpolicy_t;
@@ -87,8 +87,8 @@ static turnpolicy_t turnpolicy[] = {
/* backends and their characteristics */
struct backend_s {
- char *name; /* name of this backend */
- char *ext; /* file extension */
+ const char *name; /* name of this backend */
+ const char *ext; /* file extension */
int fixed; /* fixed page size backend? */
int pixel; /* pixel-based backend? */
int multi; /* multi-page backend? */
@@ -118,7 +118,7 @@ static backend_t backend[] = {
/* look up a backend by name. If found, return 0 and set *bp. If not
found leave *bp unchanged and return 1, or 2 on ambiguous
prefix. */
-static int backend_lookup(char *name, backend_t **bp) {
+static int backend_lookup(const char *name, backend_t **bp) {
int i;
int m=0; /* prefix matches */
backend_t *b = NULL;
@@ -185,14 +185,14 @@ static void license(FILE *f) {
}
static void show_defaults(FILE *f) {
- fprintf(f, "Default unit: "DEFAULT_DIM_NAME"\n");
- fprintf(f, "Default page size: "DEFAULT_PAPERFORMAT"\n");
+ fprintf(f, "Default unit: " DEFAULT_DIM_NAME "\n");
+ fprintf(f, "Default page size: " DEFAULT_PAPERFORMAT "\n");
}
static void usage(FILE *f) {
int j;
- fprintf(f, "Usage: "POTRACE" [options] [filename...]\n");
+ fprintf(f, "Usage: " POTRACE " [options] [filename...]\n");
fprintf(f, "General options:\n");
fprintf(f, " -h, --help - print this help message and exit\n");
fprintf(f, " -v, --version - print version info and exit\n");
@@ -222,7 +222,7 @@ static void usage(FILE *f) {
fprintf(f, " -u, --unit <n> - quantize output to 1/unit pixels (default 10)\n");
fprintf(f, " -d, --debug <n> - produce debugging output of type n (n=1,2,3)\n");
fprintf(f, "Scaling and placement options:\n");
- fprintf(f, " -P, --pagesize <format> - page size (default is "DEFAULT_PAPERFORMAT")\n");
+ fprintf(f, " -P, --pagesize <format> - page size (default is " DEFAULT_PAPERFORMAT ")\n");
fprintf(f, " -W, --width <dim> - width of output image\n");
fprintf(f, " -H, --height <dim> - height of output image\n");
fprintf(f, " -r, --resolution <n>[x<n>] - resolution (in dpi) (dimension-based backends)\n");
@@ -259,7 +259,7 @@ static void usage(FILE *f) {
fprintf(f, " --tty <mode> - progress bar rendering: vt100 or dumb\n");
fprintf(f, "\n");
fprintf(f, "Dimensions can have optional units, e.g. 6.5in, 15cm, 100pt.\n");
- fprintf(f, "Default is "DEFAULT_DIM_NAME" (or pixels for pgm, dxf, and gimppath backends).\n");
+ fprintf(f, "Default is " DEFAULT_DIM_NAME " (or pixels for pgm, dxf, and gimppath backends).\n");
fprintf(f, "Possible input file formats are: pnm (pbm, pgm, ppm), bmp.\n");
j = fprintf(f, "Backends are: ");
backend_list(f, j, 78);
@@ -431,7 +431,7 @@ static struct option longopts[] = {
{0, 0, 0, 0}
};
-static char *shortopts = "hvVlW:H:r:x:S:M:L:R:T:B:A:P:t:u:c23epsgb:d:C:z:G:nqa:O:o:k:i";
+static const char *shortopts = "hvVlW:H:r:x:S:M:L:R:T:B:A:P:t:u:c23epsgb:d:C:z:G:nqa:O:o:k:i";
static void dopts(int ac, char *av[]) {
int c;
@@ -465,8 +465,8 @@ static void dopts(int ac, char *av[]) {
info.gamma = 2.2;
info.param = potrace_param_default();
if (!info.param) {
- fprintf(stderr, ""POTRACE": %s\n", strerror(errno));
- exit(1);
+ fprintf(stderr, "" POTRACE ": %s\n", strerror(errno));
+ exit(2);
}
info.longcoding = 0;
info.outfile = NULL;
@@ -481,33 +481,33 @@ static void dopts(int ac, char *av[]) {
while ((c = getopt_long(ac, av, shortopts, longopts, NULL)) != -1) {
switch (c) {
case 'h':
- fprintf(stdout, ""POTRACE" "VERSION". Transforms bitmaps into vector graphics.\n\n");
+ fprintf(stdout, "" POTRACE " " VERSION ". Transforms bitmaps into vector graphics.\n\n");
usage(stdout);
exit(0);
break;
case 'v':
case 'V':
- fprintf(stdout, ""POTRACE" "VERSION". Copyright (C) 2001-2015 Peter Selinger.\n");
+ fprintf(stdout, "" POTRACE " " VERSION ". Copyright (C) 2001-2017 Peter Selinger.\n");
fprintf(stdout, "Library version: %s\n", potrace_version());
show_defaults(stdout);
exit(0);
break;
case 'l':
- fprintf(stdout, ""POTRACE" "VERSION". Copyright (C) 2001-2015 Peter Selinger.\n\n");
+ fprintf(stdout, "" POTRACE " " VERSION ". Copyright (C) 2001-2017 Peter Selinger.\n\n");
license(stdout);
exit(0);
break;
case 'W':
info.width_d = parse_dimension(optarg, &p);
if (*p) {
- fprintf(stderr, ""POTRACE": invalid dimension -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": invalid dimension -- %s\n", optarg);
exit(1);
}
break;
case 'H':
info.height_d = parse_dimension(optarg, &p);
if (*p) {
- fprintf(stderr, ""POTRACE": invalid dimension -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": invalid dimension -- %s\n", optarg);
exit(1);
}
break;
@@ -523,7 +523,7 @@ static void dopts(int ac, char *av[]) {
info.rx = info.ry = dim.x;
break;
}
- fprintf(stderr, ""POTRACE": invalid resolution -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": invalid resolution -- %s\n", optarg);
exit(1);
break;
case 'x':
@@ -538,7 +538,7 @@ static void dopts(int ac, char *av[]) {
info.sx = info.sy = dim.x;
break;
}
- fprintf(stderr, ""POTRACE": invalid scaling factor -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": invalid scaling factor -- %s\n", optarg);
exit(1);
break;
case 'S':
@@ -547,7 +547,7 @@ static void dopts(int ac, char *av[]) {
case 'M':
info.lmar_d = parse_dimension(optarg, &p);
if (*p) {
- fprintf(stderr, ""POTRACE": invalid dimension -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": invalid dimension -- %s\n", optarg);
exit(1);
}
info.rmar_d = info.tmar_d = info.bmar_d = info.lmar_d;
@@ -555,28 +555,28 @@ static void dopts(int ac, char *av[]) {
case 'L':
info.lmar_d = parse_dimension(optarg, &p);
if (*p) {
- fprintf(stderr, ""POTRACE": invalid dimension -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": invalid dimension -- %s\n", optarg);
exit(1);
}
break;
case 'R':
info.rmar_d = parse_dimension(optarg, &p);
if (*p) {
- fprintf(stderr, ""POTRACE": invalid dimension -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": invalid dimension -- %s\n", optarg);
exit(1);
}
break;
case 'T':
info.tmar_d = parse_dimension(optarg, &p);
if (*p) {
- fprintf(stderr, ""POTRACE": invalid dimension -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": invalid dimension -- %s\n", optarg);
exit(1);
}
break;
case 'B':
info.bmar_d = parse_dimension(optarg, &p);
if (*p) {
- fprintf(stderr, ""POTRACE": invalid dimension -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": invalid dimension -- %s\n", optarg);
exit(1);
}
break;
@@ -586,7 +586,7 @@ static void dopts(int ac, char *av[]) {
case 'A':
info.angle = strtod(optarg, &p);
if (*p) {
- fprintf(stderr, ""POTRACE": invalid angle -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": invalid angle -- %s\n", optarg);
exit(1);
}
break;
@@ -618,9 +618,9 @@ static void dopts(int ac, char *av[]) {
break;
}
if (matches == 0) {
- fprintf(stderr, ""POTRACE": unrecognized page format -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": unrecognized page format -- %s\n", optarg);
} else {
- fprintf(stderr, ""POTRACE": ambiguous page format -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": ambiguous page format -- %s\n", optarg);
}
j = fprintf(stderr, "Use one of: ");
for (i=0; pageformat[i].name!=NULL; i++) {
@@ -639,7 +639,7 @@ static void dopts(int ac, char *av[]) {
case 'u':
info.unit = strtod(optarg, &p);
if (*p) {
- fprintf(stderr, ""POTRACE": invalid unit -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": invalid unit -- %s\n", optarg);
exit(1);
}
break;
@@ -656,7 +656,7 @@ static void dopts(int ac, char *av[]) {
info.pslevel = 3;
info.compress = 1;
#else
- fprintf(stderr, ""POTRACE": option -3 not supported, using -2 instead.\n");
+ fprintf(stderr, "" POTRACE ": option -3 not supported, using -2 instead.\n");
fflush(stderr);
info.pslevel = 2;
info.compress = 1;
@@ -678,9 +678,9 @@ static void dopts(int ac, char *av[]) {
r = backend_lookup(optarg, &info.backend);
if (r==1 || r==2) {
if (r==1) {
- fprintf(stderr, ""POTRACE": unrecognized backend -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": unrecognized backend -- %s\n", optarg);
} else {
- fprintf(stderr, ""POTRACE": ambiguous backend -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": ambiguous backend -- %s\n", optarg);
}
j = fprintf(stderr, "Use one of: ");
backend_list(stderr, j, 70);
@@ -694,14 +694,14 @@ static void dopts(int ac, char *av[]) {
case 'C':
info.color = parse_color(optarg);
if (info.color == -1) {
- fprintf(stderr, ""POTRACE": invalid color -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": invalid color -- %s\n", optarg);
exit(1);
}
break;
case OPT_FILLCOLOR:
info.fillcolor = parse_color(optarg);
if (info.fillcolor == -1) {
- fprintf(stderr, ""POTRACE": invalid color -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": invalid color -- %s\n", optarg);
exit(1);
}
info.opaque = 1;
@@ -724,9 +724,9 @@ static void dopts(int ac, char *av[]) {
break;
}
if (matches == 0) {
- fprintf(stderr, ""POTRACE": unrecognized turnpolicy -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": unrecognized turnpolicy -- %s\n", optarg);
} else {
- fprintf(stderr, ""POTRACE": ambiguous turnpolicy -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": ambiguous turnpolicy -- %s\n", optarg);
}
j = fprintf(stderr, "Use one of: ");
for (i=0; turnpolicy[i].name!=NULL; i++) {
@@ -751,14 +751,14 @@ static void dopts(int ac, char *av[]) {
case 'a':
info.param->alphamax = strtod(optarg, &p);
if (*p) {
- fprintf(stderr, ""POTRACE": invalid alphamax -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": invalid alphamax -- %s\n", optarg);
exit(1);
}
break;
case 'O':
info.param->opttolerance = strtod(optarg, &p);
if (*p) {
- fprintf(stderr, ""POTRACE": invalid opttolerance -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": invalid opttolerance -- %s\n", optarg);
exit(1);
}
break;
@@ -766,14 +766,14 @@ static void dopts(int ac, char *av[]) {
free(info.outfile);
info.outfile = strdup(optarg);
if (!info.outfile) {
- fprintf(stderr, ""POTRACE": %s\n", strerror(errno));
+ fprintf(stderr, "" POTRACE ": %s\n", strerror(errno));
exit(2);
}
break;
case 'k':
info.blacklevel = strtod(optarg, &p);
if (*p) {
- fprintf(stderr, ""POTRACE": invalid blacklevel -- %s\n", optarg);
+ fprintf(stderr, "" POTRACE ": invalid blacklevel -- %s\n", optarg);
exit(1);
}
break;
@@ -798,7 +798,7 @@ static void dopts(int ac, char *av[]) {
} else if (strcmp(optarg, "vt100") == 0) {
info.progress_bar = progress_bar_vt100;
} else {
- fprintf(stderr, ""POTRACE": invalid tty mode -- %s. Try --help for more info\n", optarg);
+ fprintf(stderr, "" POTRACE ": invalid tty mode -- %s. Try --help for more info\n", optarg);
exit(1);
}
break;
@@ -807,7 +807,7 @@ static void dopts(int ac, char *av[]) {
exit(1);
break;
default:
- fprintf(stderr, ""POTRACE": Unimplemented option -- %c\n", c);
+ fprintf(stderr, "" POTRACE ": Unimplemented option -- %c\n", c);
exit(1);
}
}
@@ -987,7 +987,7 @@ static void calc_dimensions(imginfo_t *imginfo, potrace_path_t *plist) {
/* auxiliary functions for file handling */
/* open a file for reading. Return stdin if filename is NULL or "-" */
-static FILE *my_fopen_read(char *filename) {
+static FILE *my_fopen_read(const char *filename) {
if (filename == NULL || strcmp(filename, "-") == 0) {
return stdin;
}
@@ -995,7 +995,7 @@ static FILE *my_fopen_read(char *filename) {
}
/* open a file for writing. Return stdout if filename is NULL or "-" */
-static FILE *my_fopen_write(char *filename) {
+static FILE *my_fopen_write(const char *filename) {
if (filename == NULL || strcmp(filename, "-") == 0) {
return stdout;
}
@@ -1003,7 +1003,7 @@ static FILE *my_fopen_write(char *filename) {
}
/* close a file, but do nothing is filename is NULL or "-" */
-static void my_fclose(FILE *f, char *filename) {
+static void my_fclose(FILE *f, const char *filename) {
if (filename == NULL || strcmp(filename, "-") == 0) {
return;
}
@@ -1011,7 +1011,7 @@ static void my_fclose(FILE *f, char *filename) {
}
/* make output filename from input filename. Return an allocated value. */
-static char *make_outfilename(char *infile, char *ext) {
+static char *make_outfilename(const char *infile, const char *ext) {
char *outfile;
char *p;
@@ -1058,27 +1058,27 @@ static void process_file(backend_t *b, const char *infile, const char *outfile,
r = bm_read(fin, info.blacklevel, &bm);
switch (r) {
case -1: /* system error */
- fprintf(stderr, ""POTRACE": %s: %s\n", infile, strerror(errno));
+ fprintf(stderr, "" POTRACE ": %s: %s\n", infile, strerror(errno));
exit(2);
case -2: /* corrupt file format */
- fprintf(stderr, ""POTRACE": %s: file format error: %s\n", infile, bm_read_error);
+ fprintf(stderr, "" POTRACE ": %s: file format error: %s\n", infile, bm_read_error);
exit(2);
case -3: /* empty file */
if (count>0) { /* end of file */
return;
}
- fprintf(stderr, ""POTRACE": %s: empty file\n", infile);
+ fprintf(stderr, "" POTRACE ": %s: empty file\n", infile);
exit(2);
case -4: /* wrong magic */
if (count>0) {
- fprintf(stderr, ""POTRACE": %s: warning: junk at end of file\n", infile);
+ fprintf(stderr, "" POTRACE ": %s: warning: junk at end of file\n", infile);
return;
}
- fprintf(stderr, ""POTRACE": %s: file format not recognized\n", infile);
+ fprintf(stderr, "" POTRACE ": %s: file format not recognized\n", infile);
fprintf(stderr, "Possible input file formats are: pnm (pbm, pgm, ppm), bmp.\n");
exit(2);
case 1: /* unexpected end of file */
- fprintf(stderr, ""POTRACE": warning: %s: premature end of file\n", infile);
+ fprintf(stderr, "" POTRACE ": warning: %s: premature end of file\n", infile);
eof_flag = 1;
break;
}
@@ -1087,7 +1087,7 @@ static void process_file(backend_t *b, const char *infile, const char *outfile,
if (info.progress) {
r = info.progress_bar->init(&info.param->progress, infile, count);
if (r) {
- fprintf(stderr, ""POTRACE": %s\n", strerror(errno));
+ fprintf(stderr, "" POTRACE ": %s\n", strerror(errno));
exit(2);
}
} else {
@@ -1101,7 +1101,7 @@ static void process_file(backend_t *b, const char *infile, const char *outfile,
/* process the image */
st = potrace_trace(info.param, bm);
if (!st || st->status != POTRACE_STATUS_OK) {
- fprintf(stderr, ""POTRACE": %s: %s\n", infile, strerror(errno));
+ fprintf(stderr, "" POTRACE ": %s: %s\n", infile, strerror(errno));
exit(2);
}
@@ -1114,7 +1114,7 @@ static void process_file(backend_t *b, const char *infile, const char *outfile,
r = b->page_f(fout, st->plist, &imginfo);
if (r) {
- fprintf(stderr, ""POTRACE": %s: %s\n", outfile, strerror(errno));
+ fprintf(stderr, "" POTRACE ": %s: %s\n", outfile, strerror(errno));
exit(2);
}
@@ -1150,7 +1150,7 @@ int main(int ac, char *av[]) {
b = info.backend;
if (b==NULL) {
- fprintf(stderr, ""POTRACE": internal error: selected backend not found\n");
+ fprintf(stderr, "" POTRACE ": internal error: selected backend not found\n");
exit(1);
}
@@ -1175,7 +1175,7 @@ int main(int ac, char *av[]) {
fout = my_fopen_write(info.outfile);
if (!fout) {
- fprintf(stderr, ""POTRACE": %s: %s\n", info.outfile ? info.outfile : "stdout", strerror(errno));
+ fprintf(stderr, "" POTRACE ": %s: %s\n", info.outfile ? info.outfile : "stdout", strerror(errno));
exit(2);
}
if (b->init_f) {
@@ -1195,17 +1195,17 @@ int main(int ac, char *av[]) {
for (i=0; i<info.infilecount; i++) {
outfile = make_outfilename(info.infiles[i], b->ext);
if (!outfile) {
- fprintf(stderr, ""POTRACE": %s\n", strerror(errno));
+ fprintf(stderr, "" POTRACE ": %s\n", strerror(errno));
exit(2);
}
fin = my_fopen_read(info.infiles[i]);
if (!fin) {
- fprintf(stderr, ""POTRACE": %s: %s\n", info.infiles[i], strerror(errno));
+ fprintf(stderr, "" POTRACE ": %s: %s\n", info.infiles[i], strerror(errno));
exit(2);
}
fout = my_fopen_write(outfile);
if (!fout) {
- fprintf(stderr, ""POTRACE": %s: %s\n", outfile, strerror(errno));
+ fprintf(stderr, "" POTRACE ": %s: %s\n", outfile, strerror(errno));
exit(2);
}
if (b->init_f) {
@@ -1225,17 +1225,17 @@ int main(int ac, char *av[]) {
} else { /* infiles to single outfile */
if (!b->multi && info.infilecount >= 2) {
- fprintf(stderr, ""POTRACE": cannot use multiple input files with -o in %s mode\n", b->name);
+ fprintf(stderr, "" POTRACE ": cannot use multiple input files with -o in %s mode\n", b->name);
exit(1);
}
if (info.infilecount == 0) {
- fprintf(stderr, ""POTRACE": cannot use empty list of input files with -o\n");
+ fprintf(stderr, "" POTRACE ": cannot use empty list of input files with -o\n");
exit(1);
}
fout = my_fopen_write(info.outfile);
if (!fout) {
- fprintf(stderr, ""POTRACE": %s: %s\n", info.outfile, strerror(errno));
+ fprintf(stderr, "" POTRACE ": %s: %s\n", info.outfile, strerror(errno));
exit(2);
}
if (b->init_f) {
@@ -1244,7 +1244,7 @@ int main(int ac, char *av[]) {
for (i=0; i<info.infilecount; i++) {
fin = my_fopen_read(info.infiles[i]);
if (!fin) {
- fprintf(stderr, ""POTRACE": %s: %s\n", info.infiles[i], strerror(errno));
+ fprintf(stderr, "" POTRACE ": %s: %s\n", info.infiles[i], strerror(errno));
exit(2);
}
process_file(b, info.infiles[i], info.outfile, fin, fout);
@@ -1263,6 +1263,6 @@ int main(int ac, char *av[]) {
/* not reached */
try_error:
- fprintf(stderr, ""POTRACE": %s\n", strerror(errno));
+ fprintf(stderr, "" POTRACE ": %s\n", strerror(errno));
exit(2);
}
diff --git a/Build/source/libs/potrace/potrace-src/src/main.h b/Build/source/libs/potrace/potrace-src/src/main.h
index f052c4f2b77..a80359b67b9 100644
--- a/Build/source/libs/potrace/potrace-src/src/main.h
+++ b/Build/source/libs/potrace/potrace-src/src/main.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/mkbitmap.c b/Build/source/libs/potrace/potrace-src/src/mkbitmap.c
index c8689326145..34976591adb 100644
--- a/Build/source/libs/potrace/potrace-src/src/mkbitmap.c
+++ b/Build/source/libs/potrace/potrace-src/src/mkbitmap.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -29,19 +29,19 @@
/* structure to hold command line options */
struct info_s {
- char *outfile; /* output file */
- char **infiles; /* input files */
- int infilecount; /* how many input files? */
- int invert; /* invert input? */
- int highpass; /* use highpass filter? */
- double lambda; /* highpass filter radius */
- int lowpass; /* use lowpass filter? */
- double lambda1; /* lowpass filter radius */
- int scale; /* scaling factor */
- int linear; /* linear scaling? */
- int bilevel; /* convert to bilevel? */
- double level; /* cutoff grey level */
- char *outext; /* default output file extension */
+ char *outfile; /* output file */
+ char **infiles; /* input files */
+ int infilecount; /* how many input files? */
+ int invert; /* invert input? */
+ int highpass; /* use highpass filter? */
+ double lambda; /* highpass filter radius */
+ int lowpass; /* use lowpass filter? */
+ double lambda1; /* lowpass filter radius */
+ int scale; /* scaling factor */
+ int linear; /* linear scaling? */
+ int bilevel; /* convert to bilevel? */
+ double level; /* cutoff grey level */
+ const char *outext; /* default output file extension */
};
typedef struct info_s info_t;
@@ -56,6 +56,10 @@ static void lowpass(greymap_t *gm, double lambda) {
double B;
int x, y;
+ if (gm->h == 0 || gm->w == 0) {
+ return;
+ }
+
/* calculate filter coefficients from given lambda */
B = 1+2/(lambda*lambda);
c = B-sqrt(B*B-1);
@@ -125,6 +129,10 @@ static int highpass(greymap_t *gm, double lambda) {
double f;
int x, y;
+ if (gm->h == 0 || gm->w == 0) {
+ return 0;
+ }
+
/* create a copy */
gm1 = gm_dup(gm);
if (!gm1) {
@@ -201,7 +209,6 @@ static void *interpolate_linear(greymap_t *gm, int s, int bilevel, double c) {
if (!bm_out) {
return NULL;
}
- bm_clear(bm_out, 0);
c1 = c * 255;
} else {
gm_out = gm_new(w*s, h*s);
@@ -286,7 +293,6 @@ static void *interpolate_cubic(greymap_t *gm, int s, int bilevel, double c) {
if (!bm_out) {
goto calloc_error;
}
- bm_clear(bm_out, 0);
c1 = c * 255;
} else {
gm_out = gm_new(w*s, h*s);
@@ -375,7 +381,7 @@ static void *interpolate_cubic(greymap_t *gm, int s, int bilevel, double c) {
print error message to stderr and exit with code 2. On warning,
print warning message to stderr. */
-static void process_file(FILE *fin, FILE *fout, char *infile, char *outfile) {
+static void process_file(FILE *fin, FILE *fout, const char *infile, const char *outfile) {
int r;
greymap_t *gm;
potrace_bitmap_t *bm;
@@ -387,27 +393,27 @@ static void process_file(FILE *fin, FILE *fout, char *infile, char *outfile) {
r = gm_read(fin, &gm);
switch (r) {
case -1: /* system error */
- fprintf(stderr, ""MKBITMAP": %s: %s\n", infile, strerror(errno));
+ fprintf(stderr, "" MKBITMAP ": %s: %s\n", infile, strerror(errno));
exit(2);
case -2: /* corrupt file format */
- fprintf(stderr, ""MKBITMAP": %s: file format error: %s\n", infile, gm_read_error);
+ fprintf(stderr, "" MKBITMAP ": %s: file format error: %s\n", infile, gm_read_error);
exit(2);
case -3: /* empty file */
if (count>0) { /* end of file */
return;
}
- fprintf(stderr, ""MKBITMAP": %s: empty file\n", infile);
+ fprintf(stderr, "" MKBITMAP ": %s: empty file\n", infile);
exit(2);
case -4: /* wrong magic */
if (count>0) {
- fprintf(stderr, ""MKBITMAP": %s: warning: junk at end of file\n", infile);
+ fprintf(stderr, "" MKBITMAP ": %s: warning: junk at end of file\n", infile);
return;
}
- fprintf(stderr, ""MKBITMAP": %s: file format not recognized\n", infile);
+ fprintf(stderr, "" MKBITMAP ": %s: file format not recognized\n", infile);
fprintf(stderr, "Possible input file formats are: pnm (pbm, pgm, ppm), bmp.\n");
exit(2);
case 1: /* unexpected end of file */
- fprintf(stderr, ""MKBITMAP": %s: warning: premature end of file\n", infile);
+ fprintf(stderr, "" MKBITMAP ": %s: warning: premature end of file\n", infile);
break;
}
@@ -422,7 +428,7 @@ static void process_file(FILE *fin, FILE *fout, char *infile, char *outfile) {
if (info.highpass) {
r = highpass(gm, info.lambda);
if (r) {
- fprintf(stderr, ""MKBITMAP": %s: %s\n", infile, strerror(errno));
+ fprintf(stderr, "" MKBITMAP ": %s: %s\n", infile, strerror(errno));
exit(2);
}
}
@@ -444,7 +450,7 @@ static void process_file(FILE *fin, FILE *fout, char *infile, char *outfile) {
gm_free(gm);
}
if (!sm) {
- fprintf(stderr, ""MKBITMAP": %s: %s\n", infile, strerror(errno));
+ fprintf(stderr, "" MKBITMAP ": %s: %s\n", infile, strerror(errno));
exit(2);
}
@@ -483,7 +489,7 @@ static int license(FILE *f) {
}
static int usage(FILE *f) {
- fprintf(f, "Usage: "MKBITMAP" [options] [file...]\n");
+ fprintf(f, "Usage: " MKBITMAP " [options] [file...]\n");
fprintf(f, "Options:\n");
fprintf(f, " -h, --help - print this help message and exit\n");
fprintf(f, " -v, --version - print version info and exit\n");
@@ -529,7 +535,7 @@ static struct option longopts[] = {
{0, 0, 0, 0}
};
-static char *shortopts = "hvlo:xif:nb:s:13gt:";
+static const char *shortopts = "hvlo:xif:nb:s:13gt:";
/* process options. On error, print error message to stderr and exit
with code 1 */
@@ -555,16 +561,16 @@ static void dopts(int ac, char *av[]) {
while ((c = getopt_long(ac, av, shortopts, longopts, NULL)) != -1) {
switch (c) {
case 'h':
- fprintf(stdout, ""MKBITMAP" "VERSION". Transforms images into bitmaps with scaling and filtering.\n\n");
+ fprintf(stdout, "" MKBITMAP " " VERSION ". Transforms images into bitmaps with scaling and filtering.\n\n");
usage(stdout);
exit(0);
break;
case 'v':
- fprintf(stdout, ""MKBITMAP" "VERSION". Copyright (C) 2001-2015 Peter Selinger.\n");
+ fprintf(stdout, "" MKBITMAP " " VERSION ". Copyright (C) 2001-2017 Peter Selinger.\n");
exit(0);
break;
case 'l':
- fprintf(stdout, ""MKBITMAP" "VERSION". Copyright (C) 2001-2015 Peter Selinger.\n\n");
+ fprintf(stdout, "" MKBITMAP " " VERSION ". Copyright (C) 2001-2017 Peter Selinger.\n\n");
license(stdout);
exit(0);
break;
@@ -572,7 +578,7 @@ static void dopts(int ac, char *av[]) {
free(info.outfile);
info.outfile = strdup(optarg);
if (!info.outfile) {
- fprintf(stderr, ""MKBITMAP": %s\n", strerror(errno));
+ fprintf(stderr, "" MKBITMAP ": %s\n", strerror(errno));
exit(2);
}
break;
@@ -590,7 +596,7 @@ static void dopts(int ac, char *av[]) {
info.highpass = 1;
info.lambda = strtod(optarg, &p);
if (*p || info.lambda<0) {
- fprintf(stderr, ""MKBITMAP": invalid filter radius -- %s\n", optarg);
+ fprintf(stderr, "" MKBITMAP ": invalid filter radius -- %s\n", optarg);
exit(1);
}
break;
@@ -601,14 +607,14 @@ static void dopts(int ac, char *av[]) {
info.lowpass = 1;
info.lambda1 = strtod(optarg, &p);
if (*p || info.lambda1<0) {
- fprintf(stderr, ""MKBITMAP": invalid filter radius -- %s\n", optarg);
+ fprintf(stderr, "" MKBITMAP ": invalid filter radius -- %s\n", optarg);
exit(1);
}
break;
case 's':
info.scale = strtol(optarg, &p, 0);
if (*p || info.scale<=0) {
- fprintf(stderr, ""MKBITMAP": invalid scaling factor -- %s\n", optarg);
+ fprintf(stderr, "" MKBITMAP ": invalid scaling factor -- %s\n", optarg);
exit(1);
}
break;
@@ -627,7 +633,7 @@ static void dopts(int ac, char *av[]) {
info.outext = ".pbm";
info.level = strtod(optarg, &p);
if (*p || info.level<0) {
- fprintf(stderr, ""MKBITMAP": invalid threshold -- %s\n", optarg);
+ fprintf(stderr, "" MKBITMAP ": invalid threshold -- %s\n", optarg);
exit(1);
}
break;
@@ -636,7 +642,7 @@ static void dopts(int ac, char *av[]) {
exit(1);
break;
default:
- fprintf(stderr, ""MKBITMAP": Unimplemented option -- %c\n", c);
+ fprintf(stderr, "" MKBITMAP ": Unimplemented option -- %c\n", c);
exit(1);
}
}
@@ -649,7 +655,7 @@ static void dopts(int ac, char *av[]) {
/* auxiliary functions for file handling */
/* open a file for reading. Return stdin if filename is NULL or "-" */
-static FILE *my_fopen_read(char *filename) {
+static FILE *my_fopen_read(const char *filename) {
if (filename == NULL || strcmp(filename, "-") == 0) {
return stdin;
}
@@ -657,7 +663,7 @@ static FILE *my_fopen_read(char *filename) {
}
/* open a file for writing. Return stdout if filename is NULL or "-" */
-static FILE *my_fopen_write(char *filename) {
+static FILE *my_fopen_write(const char *filename) {
if (filename == NULL || strcmp(filename, "-") == 0) {
return stdout;
}
@@ -665,7 +671,7 @@ static FILE *my_fopen_write(char *filename) {
}
/* close a file, but do nothing is filename is NULL or "-" */
-static void my_fclose(FILE *f, char *filename) {
+static void my_fclose(FILE *f, const char *filename) {
if (filename == NULL || strcmp(filename, "-") == 0) {
return;
}
@@ -673,7 +679,7 @@ static void my_fclose(FILE *f, char *filename) {
}
/* make output filename from input filename. Return an allocated value. */
-static char *make_outfilename(char *infile, char *ext) {
+static char *make_outfilename(const char *infile, const char *ext) {
char *outfile;
char *p;
@@ -731,7 +737,7 @@ int main(int ac, char *av[]) {
fout = my_fopen_write(info.outfile);
if (!fout) {
- fprintf(stderr, ""MKBITMAP": %s: %s\n", info.outfile, strerror(errno));
+ fprintf(stderr, "" MKBITMAP ": %s: %s\n", info.outfile, strerror(errno));
exit(2);
}
process_file(stdin, fout, "stdin", info.outfile);
@@ -744,17 +750,17 @@ int main(int ac, char *av[]) {
for (i=0; i<info.infilecount; i++) {
outfile = make_outfilename(info.infiles[i], info.outext);
if (!outfile) {
- fprintf(stderr, ""MKBITMAP": %s\n", strerror(errno));
+ fprintf(stderr, "" MKBITMAP ": %s\n", strerror(errno));
exit(2);
}
fin = my_fopen_read(info.infiles[i]);
if (!fin) {
- fprintf(stderr, ""MKBITMAP": %s: %s\n", info.infiles[i], strerror(errno));
+ fprintf(stderr, "" MKBITMAP ": %s: %s\n", info.infiles[i], strerror(errno));
exit(2);
}
fout = my_fopen_write(outfile);
if (!fout) {
- fprintf(stderr, ""MKBITMAP": %s: %s\n", outfile, strerror(errno));
+ fprintf(stderr, "" MKBITMAP ": %s: %s\n", outfile, strerror(errno));
exit(2);
}
process_file(fin, fout, info.infiles[i], outfile);
@@ -768,13 +774,13 @@ int main(int ac, char *av[]) {
fout = my_fopen_write(info.outfile);
if (!fout) {
- fprintf(stderr, ""MKBITMAP": %s: %s\n", info.outfile, strerror(errno));
+ fprintf(stderr, "" MKBITMAP ": %s: %s\n", info.outfile, strerror(errno));
exit(2);
}
for (i=0; i<info.infilecount; i++) {
fin = my_fopen_read(info.infiles[i]);
if (!fin) {
- fprintf(stderr, ""MKBITMAP": %s: %s\n", info.infiles[i], strerror(errno));
+ fprintf(stderr, "" MKBITMAP ": %s: %s\n", info.infiles[i], strerror(errno));
exit(2);
}
process_file(fin, fout, info.infiles[i], info.outfile);
diff --git a/Build/source/libs/potrace/potrace-src/src/platform.h b/Build/source/libs/potrace/potrace-src/src/platform.h
index 4fa1155ac4e..5bb1589c2a3 100644
--- a/Build/source/libs/potrace/potrace-src/src/platform.h
+++ b/Build/source/libs/potrace/potrace-src/src/platform.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/potracelib.c b/Build/source/libs/potrace/potrace-src/src/potracelib.c
index 23f9669bd75..7dc9fe940ab 100644
--- a/Build/source/libs/potrace/potrace-src/src/potracelib.c
+++ b/Build/source/libs/potrace/potrace-src/src/potracelib.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -109,6 +109,6 @@ void potrace_param_free(potrace_param_t *p) {
free(p);
}
-char *potrace_version(void) {
- return "potracelib "VERSION"";
+const char *potrace_version(void) {
+ return "potracelib " VERSION "";
}
diff --git a/Build/source/libs/potrace/potrace-src/src/potracelib.h b/Build/source/libs/potrace/potrace-src/src/potracelib.h
index 0a6ddbf1f63..ed5a245ac4a 100644
--- a/Build/source/libs/potrace/potrace-src/src/potracelib.h
+++ b/Build/source/libs/potrace/potrace-src/src/potracelib.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -130,7 +130,7 @@ void potrace_state_free(potrace_state_t *st);
/* return a static plain text version string identifying this version
of potracelib */
-char *potrace_version(void);
+const char *potrace_version(void);
#ifdef __cplusplus
} /* end of extern "C" */
diff --git a/Build/source/libs/potrace/potrace-src/src/potracelib_demo.c b/Build/source/libs/potrace/potrace-src/src/potracelib_demo.c
index 65a787d61ce..49fe075e8ad 100644
--- a/Build/source/libs/potrace/potrace-src/src/potracelib_demo.c
+++ b/Build/source/libs/potrace/potrace-src/src/potracelib_demo.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/progress.h b/Build/source/libs/potrace/potrace-src/src/progress.h
index dd93d79207a..cdd637694c1 100644
--- a/Build/source/libs/potrace/potrace-src/src/progress.h
+++ b/Build/source/libs/potrace/potrace-src/src/progress.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/progress_bar.c b/Build/source/libs/potrace/potrace-src/src/progress_bar.c
index acf75658a4f..091269487a4 100644
--- a/Build/source/libs/potrace/potrace-src/src/progress_bar.c
+++ b/Build/source/libs/potrace/potrace-src/src/progress_bar.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -44,7 +44,7 @@ static void vt100_progress(double d, void *data) {
if (d >= p->dnext) {
tick = (int) floor(d*40+0.01);
perc = (int) floor(d*100+0.025);
- fprintf(stderr, "%-21s |%-40s| %d%% "COL0"", p->name, b+40-tick, perc);
+ fprintf(stderr, "%-21s |%-40s| %d%% " COL0 "", p->name, b+40-tick, perc);
fflush(stderr);
p->dnext = (tick+0.995) / 40.0;
}
diff --git a/Build/source/libs/potrace/potrace-src/src/progress_bar.h b/Build/source/libs/potrace/potrace-src/src/progress_bar.h
index c28cb8444f5..e34a578339c 100644
--- a/Build/source/libs/potrace/potrace-src/src/progress_bar.h
+++ b/Build/source/libs/potrace/potrace-src/src/progress_bar.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/render.c b/Build/source/libs/potrace/potrace-src/src/render.c
index 38ba1c70024..ff66b0f4f56 100644
--- a/Build/source/libs/potrace/potrace-src/src/render.c
+++ b/Build/source/libs/potrace/potrace-src/src/render.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
@@ -60,7 +60,6 @@ render_t *render_new(greymap_t *gm) {
free(rm);
return NULL;
}
- memset(rm->incrow_buf, 0, gm->h * sizeof(int));
return rm;
}
diff --git a/Build/source/libs/potrace/potrace-src/src/render.h b/Build/source/libs/potrace/potrace-src/src/render.h
index 0caaedff629..719fdf17068 100644
--- a/Build/source/libs/potrace/potrace-src/src/render.h
+++ b/Build/source/libs/potrace/potrace-src/src/render.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/trace.c b/Build/source/libs/potrace/potrace-src/src/trace.c
index 7f92458284d..5be6dd3ec57 100644
--- a/Build/source/libs/potrace/potrace-src/src/trace.c
+++ b/Build/source/libs/potrace/potrace-src/src/trace.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/trace.h b/Build/source/libs/potrace/potrace-src/src/trace.h
index c53cdd10f25..5976453353b 100644
--- a/Build/source/libs/potrace/potrace-src/src/trace.h
+++ b/Build/source/libs/potrace/potrace-src/src/trace.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/trans.c b/Build/source/libs/potrace/potrace-src/src/trans.c
index a3a9d95995a..287808bb0b8 100644
--- a/Build/source/libs/potrace/potrace-src/src/trans.c
+++ b/Build/source/libs/potrace/potrace-src/src/trans.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */
diff --git a/Build/source/libs/potrace/potrace-src/src/trans.h b/Build/source/libs/potrace/potrace-src/src/trans.h
index 40f37cd2ce5..07d93e6d5e6 100644
--- a/Build/source/libs/potrace/potrace-src/src/trans.h
+++ b/Build/source/libs/potrace/potrace-src/src/trans.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2015 Peter Selinger.
+/* Copyright (C) 2001-2017 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. */