Revision 32248

View differences:

tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_13/libraries/libjni-potrace/build.xml
1
	<project name="libjni-potrace" default="main" basedir=".">
2
	<description>
3
		Compila la librería jpotrace
4
	</description>
5
		
6
	<property name="src-java" location="src/main/java" />
7
	<property name="src-tet-java" location="src/test/java" />
8
	<property name="jar-dist" location="jar-dist" />
9
	<property name="build" location="bin/" />
10
	<property name="cmake_build" location="." />
11
	<property environment="env"/>
12
	<condition property="jpotrace_version" value="0.0.1">
13
		<os family="unix"/>
14
	</condition>
15
	<condition property="jpotrace_version" value="001">
16
		<os family="windows"/>
17
	</condition>
18
	<property name="jpotrace-jar" location="jpotrace-0.0.1.jar" />
19
	<condition property="cmake_generator" value="'Unix Makefiles'">
20
		<os family="unix"/>
21
	</condition>
22
	<condition property="cmake_generator" value="'NMake Makefiles'">
23
		<os family="windows"/>
24
	</condition>		
25

  
26
	<target name="main" description="compile java code, make jars, prepare and compile natives" depends="clean,jar,prepare-natives,compile-natives">
27
	</target>
28

  
29
	<target name="jar" description="makes jar file">
30
		<mkdir dir="${build}" />
31
		<javac srcdir="${src-java}" destdir="${build}" debug="true" />
32
		<mkdir dir="${jar-dist}" />
33
		<jar jarfile="${jpotrace-jar}" basedir="${build}" includes="es/gva/cit/**, org/gvsig/**" />
34
		<move file="${jpotrace-jar}" todir="${jar-dist}" />
35
	</target>
36

  
37
	<target name="prepare-natives" description="prepares the natives to be compiled">
38
		<mkdir dir="${cmake_build}"/>
39
		<delete file="${cmake_build}/CMakeCache.txt"/>
40
		<exec dir="${cmake_build}" executable="cmake" os="Linux" >
41
			<arg line="." />
42
			<arg line="-G${cmake_generator}" />
43
			<arg line="-DCMAKE_BUILD_TYPE=Release" />
44
			<arg line="-DJPOTRACE_VERSION=${jpotrace_version}" />
45
		</exec>
46
		<exec dir="${cmake_build}" executable="cmake" os="Windows 98,Windows 2000,Windows XP,Windows NT (Unknown)">
47
			<arg line="." />
48
			<arg line="-G${cmake_generator}" />
49
			<arg line="-DCMAKE_BUILD_TYPE=Release" />
50
			<arg line="-DJPOTRACE_VERSION=${jpotrace_version}" />
51
		</exec>
52
	</target>
53

  
54
	<target name="compile-natives" description="compiles natives">
55
		<exec dir="${cmake_build}" executable="make" os="Linux">
56
		</exec>
57
		<exec dir="${cmake_build}" executable="nmake" os="Windows 98,Windows 2000,Windows XP,Windows NT (Unknown)">
58
			<arg line="install" />
59
		</exec>
60
	</target>
61
		
62
	<target name="clean" description="clean distribution">
63
		<delete dir="jar-dist"/>
64
		<delete dir="lib-dist"/>
65
		<delete dir="BMCMake"/>
66
	</target>
67
</project>
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_13/libraries/libjni-potrace/.classpath
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="src" path="src/main/java"/>
4
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5
	<classpathentry kind="output" path="bin"/>
6
</classpath>
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_13/libraries/libjni-potrace/.project
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>libjni-potrace</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
	</buildSpec>
14
	<natures>
15
		<nature>org.eclipse.jdt.core.javanature</nature>
16
	</natures>
17
</projectDescription>
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_13/libraries/libjni-potrace/src/main/native/jpotrace/render.c
1
/* Copyright (C) 2001-2007 Peter Selinger.
2
   This file is part of Potrace. It is free software and it is covered
3
   by the GNU General Public License. See the file COPYING for details. */
4

  
5
/* $Id: render.c 147 2007-04-09 00:44:09Z selinger $ */
6

  
7
#include <stdio.h>
8
#include <stdlib.h>
9
#include <math.h>
10
#include <string.h>
11

  
12
#include "render.h"
13
#include "greymap.h"
14
#include "auxiliary.h"
15

  
16
/* ---------------------------------------------------------------------- */
17
/* routines for anti-aliased rendering of curves */
18

  
19
/* we use the following method. Given a point (x,y) (with real-valued
20
   coordinates) in the plane, let (xi,yi) be the integer part of the
21
   coordinates, i.e., xi=floor(x), yi=floor(y). Define a path from
22
   (x,y) to infinity as follows: path(x,y) =
23
   (x,y)--(xi+1,y)--(xi+1,yi)--(+infty,yi).  Now as the point (x,y)
24
   moves smoothly across the plane, the path path(x,y) sweeps
25
   (non-smoothly) across a certain area. We proportionately blacken
26
   the area as the path moves "downward", and we whiten the area as
27
   the path moves "upward". This way, after the point has traversed a
28
   closed curve, the interior of the curve has been darkened
29
   (counterclockwise movement) or lightened (clockwise movement). (The
30
   "grey shift" is actually proportional to the winding number). By
31
   choosing the above path with mostly integer coordinates, we achieve
32
   that only pixels close to (x,y) receive grey values and are subject
33
   to round-off errors. The grey value of pixels far away from (x,y)
34
   is always in "integer" (where 0=black, 1=white).  As a special
35
   trick, we keep an accumulator rm->a1, which holds a double value to
36
   be added to the grey value to be added to the current pixel
37
   (xi,yi).  Only when changing "current" pixels, we convert this
38
   double value to an integer. This way we avoid round-off errors at
39
   the meeting points of line segments. Another speedup measure is
40
   that we sometimes use the rm->incrow_buf array to postpone
41
   incrementing or decrementing an entire row. If incrow_buf[y]=x+1!=0,
42
   then all the pixels (x,y),(x+1,y),(x+2,y),... are scheduled to be
43
   incremented/decremented (which one is the case will be clear from 
44
   context). This keeps the greymap operations reasonably local. */
45

  
46
/* allocate a new rendering state */
47
render_t *render_new(greymap_t *gm) {
48
  render_t *rm;
49

  
50
  rm = (render_t *) malloc(sizeof(render_t));
51
  if (!rm) {
52
    return NULL;
53
  }
54
  memset(rm, 0, sizeof(render_t));
55
  rm->gm = gm;
56
  rm->incrow_buf = (int *) malloc(gm->h * sizeof(int));
57
  if (!rm->incrow_buf) {
58
    free(rm);
59
    return NULL;
60
  }
61
  memset(rm->incrow_buf, 0, gm->h * sizeof(int));
62
  return rm;
63
}
64

  
65
/* free a given rendering state. Note: this does not free the
66
   underlying greymap. */
67
void render_free(render_t *rm) {
68
  free(rm->incrow_buf);
69
  free(rm);
70
}
71

  
72
/* close path */
73
void render_close(render_t *rm) {
74
  if (rm->x0 != rm->x1 || rm->y0 != rm->y1) {
75
    render_lineto(rm, rm->x0, rm->y0);
76
  }
77
  GM_INC(rm->gm, rm->x0i, rm->y0i, (rm->a0+rm->a1)*255);
78

  
79
  /* assert (rm->x0i != rm->x1i || rm->y0i != rm->y1i); */
80
  
81
  /* the persistent state is now undefined */
82
}
83

  
84
/* move point */
85
void render_moveto(render_t *rm, double x, double y) {
86
  /* close the previous path */
87
  render_close(rm);
88

  
89
  rm->x0 = rm->x1 = x;
90
  rm->y0 = rm->y1 = y;
91
  rm->x0i = (int)floor(rm->x0);
92
  rm->x1i = (int)floor(rm->x1);
93
  rm->y0i = (int)floor(rm->y0);
94
  rm->y1i = (int)floor(rm->y1);
95
  rm->a0 = rm->a1 = 0;
96
}
97

  
98
/* add b to pixels (x,y) and all pixels to the right of it. However,
99
   use rm->incrow_buf as a buffer to economize on multiple calls */
100
static void incrow(render_t *rm, int x, int y, int b) {
101
  int i, x0;
102

  
103
  if (y < 0 || y >= rm->gm->h) {
104
    return;
105
  }
106

  
107
  if (x < 0) {
108
    x = 0;
109
  } else if (x > rm->gm->w) {
110
    x = rm->gm->w;
111
  }
112
  if (rm->incrow_buf[y] == 0) {
113
    rm->incrow_buf[y] = x+1; /* store x+1 so that we can use 0 for "vacant" */
114
    return;
115
  }
116
  x0 = rm->incrow_buf[y]-1;
117
  rm->incrow_buf[y] = 0;
118
  if (x0 < x) {
119
    for (i=x0; i<x; i++) {
120
      GM_INC(rm->gm, i, y, -b);
121
    }
122
  } else {
123
    for (i=x; i<x0; i++) {
124
      GM_INC(rm->gm, i, y, b);
125
    }
126
  }    
127
}
128

  
129
/* render a straight line */
130
void render_lineto(render_t *rm, double x2, double y2) {
131
  int x2i, y2i;
132
  double t0=2, s0=2;
133
  int sn, tn;
134
  double ss=2, ts=2;
135
  double r0, r1;
136
  int i, j;
137
  int rxi, ryi;
138
  int s;
139

  
140
  x2i = (int)floor(x2);
141
  y2i = (int)floor(y2);
142

  
143
  sn = abs(x2i - rm->x1i);
144
  tn = abs(y2i - rm->y1i);
145

  
146
  if (sn) {
147
    s0 = ((x2>rm->x1 ? rm->x1i+1 : rm->x1i) - rm->x1)/(x2-rm->x1);
148
    ss = fabs(1.0/(x2-rm->x1));
149
  }
150
  if (tn) {
151
    t0 = ((y2>rm->y1 ? rm->y1i+1 : rm->y1i) - rm->y1)/(y2-rm->y1);
152
    ts = fabs(1.0/(y2-rm->y1));
153
  }
154

  
155
  r0 = 0;
156

  
157
  i = 0;
158
  j = 0;
159

  
160
  rxi = rm->x1i;
161
  ryi = rm->y1i;
162

  
163
  while (i<sn || j<tn) {
164
    if (j>=tn || (i<sn && s0+i*ss < t0+j*ts)) {
165
      r1 = s0+i*ss;
166
      i++;
167
      s = 1;
168
    } else {
169
      r1 = t0+j*ts;
170
      j++;
171
      s = 0;
172
    }
173
    /* render line from r0 to r1 segment of (rm->x1,rm->y1)..(x2,y2) */
174
    
175
    /* move point to r1 */
176
    rm->a1 += (r1-r0)*(y2-rm->y1)*(rxi+1-((r0+r1)/2.0*(x2-rm->x1)+rm->x1));
177

  
178
    /* move point across pixel boundary */
179
    if (s && x2>rm->x1) {
180
      GM_INC(rm->gm, rxi, ryi, rm->a1*255);
181
      rm->a1 = 0;
182
      rxi++;
183
      rm->a1 += rm->y1+r1*(y2-rm->y1)-ryi;
184
    } else if (!s && y2>rm->y1) {
185
      GM_INC(rm->gm, rxi, ryi, rm->a1*255);
186
      rm->a1 = 0;
187
      incrow(rm, rxi+1, ryi, 255);
188
      ryi++;
189
    } else if (s && x2<=rm->x1) {
190
      rm->a1 -= rm->y1+r1*(y2-rm->y1)-ryi;
191
      GM_INC(rm->gm, rxi, ryi, rm->a1*255);
192
      rm->a1 = 0;
193
      rxi--;
194
    } else if (!s && y2<=rm->y1) {
195
      GM_INC(rm->gm, rxi, ryi, rm->a1*255);
196
      rm->a1 = 0;
197
      ryi--;
198
      incrow(rm, rxi+1, ryi, -255);
199
    }
200

  
201
    r0 = r1;
202
  }
203
  
204
  /* move point to (x2,y2) */
205
  
206
  r1 = 1;
207
  rm->a1 += (r1-r0)*(y2-rm->y1)*(rxi+1-((r0+r1)/2.0*(x2-rm->x1)+rm->x1));
208

  
209
  rm->x1i = x2i;
210
  rm->y1i = y2i;
211
  rm->x1 = x2;
212
  rm->y1 = y2;
213

  
214
  /* assert (rxi != rm->x1i || ryi != rm->y1i); */
215
}
216

  
217
/* render a Bezier curve. */
218
void render_curveto(render_t *rm, double x2, double y2, double x3, double y3, double x4, double y4) {
219
  double x1, y1, dd0, dd1, dd, delta, e2, epsilon, t;
220

  
221
  x1 = rm->x1;  /* starting point */
222
  y1 = rm->y1;
223

  
224
  /* we approximate the curve by small line segments. The interval
225
     size, epsilon, is determined on the fly so that the distance
226
     between the true curve and its approximation does not exceed the
227
     desired accuracy delta. */
228

  
229
  delta = .1;  /* desired accuracy, in pixels */
230

  
231
  /* let dd = maximal value of 2nd derivative over curve - this must
232
     occur at an endpoint. */
233
  dd0 = sq(x1-2*x2+x3) + sq(y1-2*y2+y3);
234
  dd1 = sq(x2-2*x3+x4) + sq(y2-2*y3+y4);
235
  dd = 6*sqrt(max(dd0, dd1));
236
  e2 = 8*delta <= dd ? 8*delta/dd : 1;
237
  epsilon = sqrt(e2);  /* necessary interval size */
238

  
239
  for (t=epsilon; t<1; t+=epsilon) {
240
    render_lineto(rm, x1*cu(1-t)+3*x2*sq(1-t)*t+3*x3*(1-t)*sq(t)+x4*cu(t),
241
		  y1*cu(1-t)+3*y2*sq(1-t)*t+3*y3*(1-t)*sq(t)+y4*cu(t));
242
  }
243
  render_lineto(rm, x4, y4);
244
}
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_13/libraries/libjni-potrace/src/main/native/jpotrace/backend_pdf.c
1
/* Copyright (C) 2001-2007 Peter Selinger.
2
   This file is part of Potrace. It is free software and it is covered
3
   by the GNU General Public License. See the file COPYING for details. */
4

  
5
/* $Id: backend_pdf.c 147 2007-04-09 00:44:09Z selinger $ */
6

  
7
/* The PDF backend of Potrace. Stream compression is optionally
8
	supplied via the functions in flate.c. */
9

  
10
#include <stdio.h>
11
#include <stdarg.h>
12
#include <string.h>
13
#include <math.h>
14
#include <stdlib.h>
15

  
16
#include "main.h"
17
#include "backend_pdf.h"
18
#include "flate.h"
19
#include "lists.h"
20
#include "potracelib.h"
21
#include "auxiliary.h"
22

  
23
#ifdef HAVE_CONFIG_H
24
#include "config.h"
25
#endif
26

  
27
#ifndef M_PI
28
	#define M_PI 3.14159265358979323846
29
#endif
30

  
31

  
32
typedef int color_t;
33

  
34
#define black  0x000000
35
#define red    0xff0000
36
#define green  0x008000
37
#define blue   0x0000ff
38

  
39
/* ---------------------------------------------------------------------- */
40
/* auxiliary: growing arrays */
41

  
42
struct intarray_s {
43
  int size;
44
  int *data;
45
};
46
typedef struct intarray_s intarray_t;
47

  
48
static inline void intarray_init(intarray_t *ar) {
49
  ar->size = 0;
50
  ar->data = NULL;
51
}
52

  
53
static inline void intarray_term(intarray_t *ar) {
54
  free(ar->data);
55
  ar->size = 0;
56
  ar->data = NULL;
57
}
58

  
59
/* Set ar[n]=val. Expects n>=0. Grows array if necessary. Return 0 on
60
   success and -1 on error with errno set. */
61
static inline int intarray_set(intarray_t *ar, int n, int val) {
62
  int *p;
63
  int s;
64

  
65
  if (n >= ar->size) {
66
    s = n+1024;
67
    p = (int *)realloc(ar->data, s * sizeof(int));
68
    if (!p) {
69
      return -1;
70
    }
71
    ar->data = p;
72
    ar->size = s;
73
  }
74
  ar->data[n] = val;
75
  return 0;
76
}
77

  
78
/* ---------------------------------------------------------------------- */
79
/* some global variables */
80

  
81
static intarray_t xref;
82
static int nxref = 0;
83
static intarray_t pages;
84
static int npages;
85
static int streamofs;
86
static size_t outcount;  /* output file position */
87

  
88
/* ---------------------------------------------------------------------- */
89
/* functions for interfacing with compression backend */
90

  
91
/* xship: callback function that must be initialized before calling
92
   any other functions of the "ship" family. xship_file must be
93
   initialized too. */
94

  
95
/* print the token to f, but filtered through a compression
96
   filter in case filter!=0 */
97
static int (*xship)(FILE *f, int filter, char *s, int len);
98
static FILE *xship_file;
99

  
100
/* ship PDF code, filtered */
101
static int ship(const char *fmt, ...) {
102
  va_list args;
103
  static char buf[4096]; /* static string limit is okay here because
104
			    we only use constant format strings - for
105
			    the same reason, it is okay to use
106
			    vsprintf instead of vsnprintf below. */
107
  va_start(args, fmt);
108
  vsprintf(buf, fmt, args);
109
  buf[4095] = 0;
110
  va_end(args);
111

  
112
  outcount += xship(xship_file, 1, buf, strlen(buf));
113
  return 0;
114
}  
115

  
116
/* ship PDF code, unfiltered */
117
static int shipclear(char *fmt, ...) {
118
  static char buf[4096];
119
  va_list args;
120

  
121
  va_start(args, fmt);
122
  vsprintf(buf, fmt, args);
123
  buf[4095] = 0;
124
  va_end(args);
125

  
126
  outcount += xship(xship_file, 0, buf, strlen(buf));
127
  return 0;
128
}
129

  
130
/* set all callback functions */
131
static void pdf_callbacks(FILE *fout) {
132

  
133
  if (info.compress) {
134
    xship = pdf_xship;
135
  } else {
136
    xship = dummy_xship;
137
  }
138
  xship_file = fout;
139
}  
140

  
141
/* ---------------------------------------------------------------------- */
142
/* PDF path-drawing auxiliary functions */
143

  
144
/* coordinate quantization */
145
static inline point_t unit(dpoint_t p) {
146
  point_t q;
147

  
148
  q.x = (long)(floor(p.x*info.unit+.5));
149
  q.y = (long)(floor(p.y*info.unit+.5));
150
  return q;
151
}
152

  
153
static void pdf_coords(dpoint_t p) {
154
  point_t cur = unit(p);
155
  ship("%ld %ld ", cur.x, cur.y);
156
}
157

  
158
static void pdf_moveto(dpoint_t p) {
159
  pdf_coords(p);
160
  ship("m\n");
161
}
162

  
163
static void pdf_lineto(dpoint_t p) {
164
  pdf_coords(p);
165
  ship("l\n");
166
}
167

  
168
static void pdf_curveto(dpoint_t p1, dpoint_t p2, dpoint_t p3) {
169
  point_t q1, q2, q3;
170

  
171
  q1 = unit(p1);
172
  q2 = unit(p2);
173
  q3 = unit(p3);
174

  
175
  ship("%ld %ld %ld %ld %ld %ld c\n", q1.x, q1.y, q2.x, q2.y, q3.x, q3.y);
176
}
177

  
178
/* this procedure returns a statically allocated string */
179
static char *pdf_colorstring(const color_t col) {
180
  double r, g, b;
181
  static char buf[100];
182

  
183
  r = (col & 0xff0000) >> 16;
184
  g = (col & 0x00ff00) >> 8;
185
  b = (col & 0x0000ff) >> 0;
186

  
187
  if (r==0 && g==0 && b==0) {
188
    return "0 g";
189
  } else if (r==255 && g==255 && b==255) {
190
    return "1 g";
191
  } else if (r == g && g == b) {
192
    sprintf(buf, "%.3f g", r/255.0);
193
    return buf;
194
  } else {
195
    sprintf(buf, "%.3f %.3f %.3f rg", r/255.0, g/255.0, b/255.0);
196
    return buf;
197
  }
198
}
199

  
200
static color_t pdf_color = -1;
201
static double pdf_width = -1;
202

  
203
static void pdf_setcolor(const color_t col) {
204
  if (col == pdf_color) {
205
    return;
206
  }
207
  pdf_color = col;
208

  
209
  ship("%s\n", pdf_colorstring(col));
210
}
211

  
212
/* explicit encoding, does not use special macros */
213
static int pdf_path(potrace_curve_t *curve) {
214
  int i;
215
  dpoint_t *c;
216
  int m = curve->n;
217

  
218
  c = curve->c[m-1];
219
  pdf_moveto(c[2]);
220

  
221
  for (i=0; i<m; i++) {
222
    c = curve->c[i];
223
    switch (curve->tag[i]) {
224
    case POTRACE_CORNER:
225
      pdf_lineto(c[1]);
226
      pdf_lineto(c[2]);
227
      break;
228
    case POTRACE_CURVETO:
229
      pdf_curveto(c[0], c[1], c[2]);
230
      break;
231
    }
232
  }
233
  return 0;
234
}
235

  
236
/* ---------------------------------------------------------------------- */
237
/* Backends for various types of output. */
238

  
239
/* Normal output: black on transparent */
240
static int render0(potrace_path_t *plist) {
241
  potrace_path_t *p;
242

  
243
  pdf_setcolor(info.color);
244
  list_forall (p, plist) {
245
    pdf_path(&p->curve);
246
    ship("h\n");
247
    if (p->next == NULL || p->next->sign == '+') {
248
      ship("f\n");
249
    }
250
  }
251
  return 0;
252
}
253

  
254
/* Opaque output: alternating black and white */
255
static int render0_opaque(potrace_path_t *plist) {
256
  potrace_path_t *p;
257
  
258
  list_forall (p, plist) {
259
    pdf_path(&p->curve);
260
    ship("h\n");
261
    pdf_setcolor(p->sign=='+' ? info.color : info.fillcolor);
262
    ship("f\n");
263
  }
264
  return 0;
265
}
266

  
267
/* select the appropriate rendering function from above */
268
static int pdf_render(potrace_path_t *plist)
269
{
270
  if (info.opaque) {
271
    return render0_opaque(plist);
272
  }
273
  return render0(plist);
274
}  
275

  
276
/* ---------------------------------------------------------------------- */
277
/* PDF header and footer */
278

  
279
int init_pdf(FILE *fout)
280
{
281
        intarray_init(&xref);
282
	intarray_init(&pages);
283
	nxref = 0;
284
	npages = 0;
285

  
286
	/* set callback functions for shipping routines */
287
	pdf_callbacks(fout);
288
	outcount = 0;
289

  
290
	shipclear("%%PDF-1.3\n");
291

  
292
	intarray_set(&xref, nxref++, outcount);
293
	shipclear("1 0 obj\n<</Type/Catalog/Pages 3 0 R>>\nendobj\n");
294

  
295
	intarray_set(&xref, nxref++, outcount);
296
	shipclear("2 0 obj\n"
297
		"<</Creator"
298
		"("POTRACE" "VERSION", written by Peter Selinger 2001-2007)>>\n"
299
		"endobj\n");
300

  
301
	/* delay obj #3 (pages) until end */
302
	nxref++;
303

  
304
	fflush(fout);
305
	return 0;
306
}
307

  
308
int term_pdf(FILE *fout)
309
{
310
	int startxref;
311
	int i;
312

  
313
	pdf_callbacks(fout);
314

  
315
	intarray_set(&xref, 2, outcount);
316
	shipclear("3 0 obj\n"
317
		"<</Type/Pages/Count %d/Kids[\n", npages);
318
	for (i = 0; i < npages; i++)
319
		shipclear("%d 0 R\n", pages.data[i]);
320
	shipclear("]>>\nendobj\n");
321

  
322
	startxref = outcount;
323

  
324
	shipclear("xref\n0 %d\n", nxref + 1);
325
	shipclear("0000000000 65535 f \n");
326
	for (i = 0; i < nxref; i++)
327
		shipclear("%0.10d 00000 n \n", xref.data[i]);
328

  
329
	shipclear("trailer\n<</Size %d/Root 1 0 R/Info 2 0 R>>\n", nxref + 1);
330
	shipclear("startxref\n%d\n%%%%EOF\n", startxref);
331

  
332
	fflush(fout);
333
	intarray_term(&xref);
334
	intarray_term(&pages);
335
	return 0;
336
}
337

  
338
static void pdf_pageinit(imginfo_t *imginfo)
339
{
340
	double s, c;
341

  
342
	double origx = imginfo->trans.orig[0] + imginfo->lmar;
343
	double origy = imginfo->trans.orig[1] + imginfo->bmar;
344
	double scalex = imginfo->width / imginfo->pixwidth / info.unit;
345
	double scaley = imginfo->height / imginfo->pixheight / info.unit;
346
	int pagew = (int)ceil(imginfo->trans.bb[0]+imginfo->lmar+imginfo->rmar);
347
	int pageh = (int)ceil(imginfo->trans.bb[1]+imginfo->tmar+imginfo->bmar);
348

  
349
	pdf_color = -1;
350
	pdf_width = -1;
351

  
352
	intarray_set(&xref, nxref++, outcount);
353
	shipclear("%d 0 obj\n", nxref);
354
	shipclear("<</Type/Page/Parent 3 0 R/Resources<</ProcSet[/PDF]>>");
355
	shipclear("/MediaBox[0 0 %d %d]", pagew, pageh);
356
	shipclear("/Contents %d 0 R>>\n", nxref + 1);
357
	shipclear("endobj\n");
358

  
359
	intarray_set(&pages, npages++, nxref);
360

  
361
	intarray_set(&xref, nxref++, outcount);
362
	shipclear("%d 0 obj\n", nxref);
363
	if (info.compress)
364
		shipclear("<</Filter/FlateDecode/Length %d 0 R>>\n", nxref + 1);
365
	else
366
		shipclear("<</Length %d 0 R>>\n", nxref + 1);
367
	shipclear("stream\n");
368

  
369
	streamofs = outcount;
370

  
371
	s = sin(info.angle * M_PI / 180.0);
372
	c = cos(info.angle * M_PI / 180.0);
373

  
374
	ship("%f %f %f %f %.0f %.0f cm\n", scalex*c, scalex*s, -scaley*s, scaley*c, origx, origy);
375
}
376

  
377
static void pdf_pageterm(void)
378
{
379
	int streamlen;
380

  
381
	shipclear("");
382

  
383
	streamlen = outcount - streamofs;
384
	shipclear("endstream\nendobj\n");
385
	
386
	intarray_set(&xref, nxref++, outcount);
387
	shipclear("%d 0 obj\n%d\nendobj\n", nxref, streamlen);
388
}
389

  
390
int page_pdf(FILE *fout, potrace_path_t *plist, imginfo_t *imginfo)
391
{
392
  int r;
393

  
394
  pdf_callbacks(fout);
395

  
396
  pdf_pageinit(imginfo);
397

  
398
  r = pdf_render(plist);
399
  if (r) {
400
    return r;
401
  }
402

  
403
  pdf_pageterm();
404

  
405
  fflush(fout);
406

  
407
  return 0;
408
}
409

  
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_13/libraries/libjni-potrace/src/main/native/jpotrace/bitmap.h
1
/* Copyright (C) 2001-2007 Peter Selinger.
2
   This file is part of Potrace. It is free software and it is covered
3
   by the GNU General Public License. See the file COPYING for details. */
4

  
5
#ifndef BITMAP_H
6
#define BITMAP_H
7

  
8
#ifdef HAVE_CONFIG_H
9
#include "config.h"
10
#endif
11

  
12
#include <string.h>
13
#include <stdlib.h>
14

  
15
/* The bitmap type is defined in potracelib.h */
16
#include "potracelib.h"
17

  
18
/* The present file defines some convenient macros and static inline
19
   functions for accessing bitmaps. Since they only produce inline
20
   code, they can be conveniently shared by the library and frontends,
21
   if desired */
22

  
23
/* ---------------------------------------------------------------------- */
24
/* some measurements */
25

  
26
#define BM_WORDSIZE ((int)sizeof(potrace_word))
27
#define BM_WORDBITS (8*BM_WORDSIZE)
28
#define BM_HIBIT (((potrace_word)1)<<(BM_WORDBITS-1))
29
#define BM_ALLBITS (~(potrace_word)0)
30

  
31
/* macros for accessing pixel at index (x,y). U* macros omit the
32
   bounds check. */
33

  
34
#define bm_scanline(bm, y) ((bm)->map + (y)*(bm)->dy)
35
#define bm_index(bm, x, y) (&bm_scanline(bm, y)[(x)/BM_WORDBITS])
36
#define bm_mask(x) (BM_HIBIT >> ((x) & (BM_WORDBITS-1)))
37
#define bm_range(x, a) ((int)(x) >= 0 && (int)(x) < (a))
38
#define bm_safe(bm, x, y) (bm_range(x, (bm)->w) && bm_range(y, (bm)->h))
39
#define BM_UGET(bm, x, y) ((*bm_index(bm, x, y) & bm_mask(x)) != 0)
40
#define BM_USET(bm, x, y) (*bm_index(bm, x, y) |= bm_mask(x))
41
#define BM_UCLR(bm, x, y) (*bm_index(bm, x, y) &= ~bm_mask(x))
42
#define BM_UINV(bm, x, y) (*bm_index(bm, x, y) ^= bm_mask(x))
43
#define BM_UPUT(bm, x, y, b) ((b) ? BM_USET(bm, x, y) : BM_UCLR(bm, x, y))
44
#define BM_GET(bm, x, y) (bm_safe(bm, x, y) ? BM_UGET(bm, x, y) : 0)
45
#define BM_SET(bm, x, y) (bm_safe(bm, x, y) ? BM_USET(bm, x, y) : 0)
46
#define BM_CLR(bm, x, y) (bm_safe(bm, x, y) ? BM_UCLR(bm, x, y) : 0)
47
#define BM_INV(bm, x, y) (bm_safe(bm, x, y) ? BM_UINV(bm, x, y) : 0)
48
#define BM_PUT(bm, x, y, b) (bm_safe(bm, x, y) ? BM_UPUT(bm, x, y, b) : 0)
49

  
50
/* free the given bitmap. Leaves errno untouched. */
51
static inline void bm_free(potrace_bitmap_t *bm) {
52
  if (bm) {
53
    free(bm->map);
54
  }
55
  free(bm);
56
}
57

  
58
/* return new un-initialized bitmap. NULL with errno on error */
59
static inline potrace_bitmap_t *bm_new(int w, int h) {
60
  potrace_bitmap_t *bm;
61
  int dy = (w + BM_WORDBITS - 1) / BM_WORDBITS;
62

  
63
  bm = (potrace_bitmap_t *) malloc(sizeof(potrace_bitmap_t));
64
  if (!bm) {
65
    return NULL;
66
  }
67
  bm->w = w;
68
  bm->h = h;
69
  bm->dy = dy;
70
  bm->map = (potrace_word *) malloc(dy * h * BM_WORDSIZE);
71
  if (!bm->map) {
72
    free(bm);
73
    return NULL;
74
  }
75
  return bm;
76
}
77

  
78
/* clear the given bitmap. Set all bits to c. */
79
static inline void bm_clear(potrace_bitmap_t *bm, int c) {
80
  memset(bm->map, c ? -1 : 0, bm->dy * bm->h * BM_WORDSIZE);
81
}
82

  
83
/* duplicate the given bitmap. Return NULL on error with errno set. */
84
static inline potrace_bitmap_t *bm_dup(const potrace_bitmap_t *bm) {
85
  potrace_bitmap_t *bm1 = bm_new(bm->w, bm->h);
86
  if (!bm1) {
87
    return NULL;
88
  }
89
  memcpy(bm1->map, bm->map, bm->dy * bm->h * BM_WORDSIZE);
90
  return bm1;
91
}
92

  
93
/* invert the given bitmap. */
94
static inline void bm_invert(potrace_bitmap_t *bm) {
95
  int i;
96
  for (i = 0; i < bm->dy * bm->h; i++) {
97
    bm->map[i] ^= BM_ALLBITS;
98
  }
99
}
100

  
101
#endif /* BITMAP_H */
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_13/libraries/libjni-potrace/src/main/native/jpotrace/potrace_raster.h
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
#ifndef POTRACE_RASTER_H
20
#define POTRACE_RASTER_H
21

  
22
#include "potracelib.h"
23

  
24
/* structure to hold a tilted rectangle */
25
struct rect_s {
26
	double bb[2];    /* dimensions of bounding box */
27
	double orig[2];  /* origin relative to bounding box */
28
};
29
typedef struct rect_s rect_t;
30

  
31
#ifdef USE_A4
32
#define DEFAULT_PAPERWIDTH 595
33
#define DEFAULT_PAPERHEIGHT 842
34
#define DEFAULT_PAPERFORMAT "a4"
35
#else
36
#define DEFAULT_PAPERWIDTH 612
37
#define DEFAULT_PAPERHEIGHT 792
38
#define DEFAULT_PAPERFORMAT "letter"
39
#endif
40

  
41
/* structure to hold a dimensioned value */
42
struct dim_s {
43
	double x; /* value */
44
	double d; /* dimension (in pt), or 0 if not given */
45
};
46
typedef struct dim_s dim_t;
47

  
48
/* structure to hold command line options */
49
struct info_s {
50
	struct backend_s *backend;  /* type of backend (eps,ps,pgm etc) */
51
	potrace_param_t *param;  /* tracing parameters, see potracelib.h */
52
	int debug;         /* type of output (0-2) (for BACKEND_PS/EPS only) */
53
	dim_t width_d;     /* desired width of image */
54
	dim_t height_d;    /* desired height of image */
55
	double rx;         /* desired x resolution (in dpi) */
56
	double ry;         /* desired y resolution (in dpi) */
57
	double sx;         /* desired x scaling factor */
58
	double sy;         /* desired y scaling factor */
59
	double stretch;    /* ry/rx, if not otherwise determined */
60
	dim_t lmar_d, rmar_d, tmar_d, bmar_d;   /* margins */
61
	double angle;      /* rotate by this many degrees */
62
	int paperwidth, paperheight;  /* paper size for ps backend (in pt) */
63
	double unit;       /* granularity of output grid */
64
	int compress;      /* apply compression? */
65
	int pslevel;       /* postscript level to use: affects only compression */
66
	int color;         /* rgb color code 0xrrggbb: line color */
67
	int fillcolor;     /* rgb color code 0xrrggbb: fill color */
68
	double gamma;      /* gamma value for pgm backend */
69
	int longcoding;    /* do not optimize for file size? */
70
	char *outfile;     /* output filename, if given */
71
	char **infiles;    /* array of input filenames */
72
	int infilecount;   /* number of input filenames */
73
	double blacklevel; /* 0 to 1: black/white cutoff in input file */
74
	int invert;        /* invert bitmap? */
75
	int opaque;        /* paint white shapes opaquely? */
76
	int group;         /* group paths together? */
77
	int progress;      /* should we display a progress bar? */
78
};
79
typedef struct info_s info_t;
80

  
81
extern info_t info;
82

  
83
/* structure to hold per-image information, set e.g. by calc_dimensions */
84
struct imginfo_s {
85
	int pixwidth;        /* width of input pixmap */
86
	int pixheight;       /* height of input pixmap */
87
	double width;        /* desired width of image (in pt or pixels) */
88
	double height;       /* desired height of image (in pt or pixels) */
89
	double lmar, rmar, tmar, bmar;   /* requested margins (in pt) */
90
	rect_t trans;        /* specify relative position of a tilted rectangle */
91
};
92
typedef struct imginfo_s imginfo_t;
93

  
94
double* vectorizarBuffer(const long *cbufferIn, int width, int height, int argc, char *argv[]);
95

  
96
#endif /* POTRACE_RASTER_H */
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_13/libraries/libjni-potrace/src/main/native/jpotrace/getopt1.c
1
/* getopt_long and getopt_long_only entry points for GNU getopt.
2
   Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98
3
     Free Software Foundation, Inc.
4
   This file is part of the GNU C Library.
5

  
6
   The GNU C Library is free software; you can redistribute it and/or
7
   modify it under the terms of the GNU Library General Public License as
8
   published by the Free Software Foundation; either version 2 of the
9
   License, or (at your option) any later version.
10

  
11
   The GNU C Library is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
   Library General Public License for more details.
15

  
16
   You should have received a copy of the GNU Library General Public
17
   License along with the GNU C Library; see the file COPYING.LIB.  If not,
18
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
   Boston, MA 02111-1307, USA.  */
20

21
#ifdef HAVE_CONFIG_H
22
#include "config.h"
23
#endif
24

  
25
#include "getopt.h"
26

  
27
#if !defined __STDC__ || !__STDC__
28
/* This is a separate conditional since some stdc systems
29
   reject `defined (const)'.  */
30
#ifndef const
31
#define const
32
#endif
33
#endif
34

  
35
#include <stdio.h>
36

  
37
/* Comment out all this code if we are using the GNU C Library, and are not
38
   actually compiling the library itself.  This code is part of the GNU C
39
   Library, but also included in many other GNU distributions.  Compiling
40
   and linking in this code is a waste when using the GNU C library
41
   (especially if it is a shared library).  Rather than having every GNU
42
   program understand `configure --with-gnu-libc' and omit the object files,
43
   it is simpler to just do this in the source for each such file.  */
44

  
45
#define GETOPT_INTERFACE_VERSION 2
46
#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
47
#include <gnu-versions.h>
48
#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
49
#define ELIDE_CODE
50
#endif
51
#endif
52

  
53
#ifndef ELIDE_CODE
54

  
55

  
56
/* This needs to come after some library #include
57
   to get __GNU_LIBRARY__ defined.  */
58
#ifdef __GNU_LIBRARY__
59
#include <stdlib.h>
60
#endif
61

  
62
#ifndef	NULL
63
#define NULL 0
64
#endif
65

  
66
int
67
getopt_long (argc, argv, options, long_options, opt_index)
68
     int argc;
69
     char *const *argv;
70
     const char *options;
71
     const struct option *long_options;
72
     int *opt_index;
73
{
74
  return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
75
}
76

  
77
/* Like getopt_long, but '-' as well as '--' can indicate a long option.
78
   If an option that starts with '-' (not '--') doesn't match a long option,
79
   but does match a short option, it is parsed as a short option
80
   instead.  */
81

  
82
int
83
getopt_long_only (argc, argv, options, long_options, opt_index)
84
     int argc;
85
     char *const *argv;
86
     const char *options;
87
     const struct option *long_options;
88
     int *opt_index;
89
{
90
  return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
91
}
92

  
93

  
94
#endif	/* Not ELIDE_CODE.  */
95

96
#ifdef TEST
97

  
98
#include <stdio.h>
99

  
100
int
101
main (argc, argv)
102
     int argc;
103
     char **argv;
104
{
105
  int c;
106
  int digit_optind = 0;
107

  
108
  while (1)
109
    {
110
      int this_option_optind = optind ? optind : 1;
111
      int option_index = 0;
112
      static struct option long_options[] =
113
      {
114
	{"add", 1, 0, 0},
115
	{"append", 0, 0, 0},
116
	{"delete", 1, 0, 0},
117
	{"verbose", 0, 0, 0},
118
	{"create", 0, 0, 0},
119
	{"file", 1, 0, 0},
120
	{0, 0, 0, 0}
121
      };
122

  
123
      c = getopt_long (argc, argv, "abc:d:0123456789",
124
		       long_options, &option_index);
125
      if (c == -1)
126
	break;
127

  
128
      switch (c)
129
	{
130
	case 0:
131
	  printf ("option %s", long_options[option_index].name);
132
	  if (optarg)
133
	    printf (" with arg %s", optarg);
134
	  printf ("\n");
135
	  break;
136

  
137
	case '0':
138
	case '1':
139
	case '2':
140
	case '3':
141
	case '4':
142
	case '5':
143
	case '6':
144
	case '7':
145
	case '8':
146
	case '9':
147
	  if (digit_optind != 0 && digit_optind != this_option_optind)
148
	    printf ("digits occur in two different argv-elements.\n");
149
	  digit_optind = this_option_optind;
150
	  printf ("option %c\n", c);
151
	  break;
152

  
153
	case 'a':
154
	  printf ("option a\n");
155
	  break;
156

  
157
	case 'b':
158
	  printf ("option b\n");
159
	  break;
160

  
161
	case 'c':
162
	  printf ("option c with value `%s'\n", optarg);
163
	  break;
164

  
165
	case 'd':
166
	  printf ("option d with value `%s'\n", optarg);
167
	  break;
168

  
169
	case '?':
170
	  break;
171

  
172
	default:
173
	  printf ("?? getopt returned character code 0%o ??\n", c);
174
	}
175
    }
176

  
177
  if (optind < argc)
178
    {
179
      printf ("non-option ARGV-elements: ");
180
      while (optind < argc)
181
	printf ("%s ", argv[optind++]);
182
      printf ("\n");
183
    }
184

  
185
  exit (0);
186
}
187

  
188
#endif /* TEST */
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_13/libraries/libjni-potrace/src/main/native/jpotrace/render.h
1
/* Copyright (C) 2001-2007 Peter Selinger.
2
   This file is part of Potrace. It is free software and it is covered
3
   by the GNU General Public License. See the file COPYING for details. */
4

  
5
/* $Id: render.h 147 2007-04-09 00:44:09Z selinger $ */
6

  
7
#ifndef RENDER_H
8
#define RENDER_H
9

  
10
#include "greymap.h"
11

  
12
struct render_s {
13
  greymap_t *gm;
14
  double x0, y0, x1, y1;
15
  int x0i, y0i, x1i, y1i;
16
  double a0, a1;
17
  int *incrow_buf;
18
};
19
typedef struct render_s render_t;
20

  
21
render_t *render_new(greymap_t *gm);
22
void render_free(render_t *rm);
23
void render_close(render_t *rm);
24
void render_moveto(render_t *rm, double x, double y);
25
void render_lineto(render_t *rm, double x, double y);
26
void render_curveto(render_t *rm, double x2, double y2, double x3, double y3, double x4, double y4);
27

  
28
#endif /* RENDER_H */
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_13/libraries/libjni-potrace/src/main/native/jpotrace/main.c
1
/* Copyright (C) 2001-2007 Peter Selinger.
2
   This file is part of Potrace. It is free software and it is covered
3
   by the GNU General Public License. See the file COPYING for details. */
4

  
5
/* $Id: main.c 147 2007-04-09 00:44:09Z selinger $ */
6

  
7
#include <stdio.h>
8
#include <stdlib.h>
9
#include <errno.h>
10
#include <string.h>
11
#include <getopt.h>
12
#include <math.h>
13

  
14
#include "main.h"
15
#include "potracelib.h"
16
#include "backend_pdf.h"
17
#include "backend_eps.h"
18
#include "backend_pgm.h"
19
#include "backend_svg.h"
20
#include "backend_gimp.h"
21
#include "backend_xfig.h"
22
#include "potracelib.h"
23
#include "bitmap_io.h"
24
#include "bitmap.h"
25
#include "platform.h"
26
#include "auxiliary.h"
27

  
28
#ifdef HAVE_CONFIG_H
29
#include "config.h"
30
#endif
31

  
32
#ifndef M_PI
33
#define M_PI 3.14159265358979323846
34
#endif
35

  
36
#define UNDEF ((double)(1e30))   /* a value to represent "undefined" */
37
#define INFTY ((double)(1e30))   /* a value to represent +infinity */
38

  
39
struct info_s info;
40

  
41
#define COL0 "\033[G"  /* reset cursor to column 0 */
42

  
43
/* ---------------------------------------------------------------------- */
44
/* callback function for progress bar */
45

  
46
struct simple_progress_s {
47
  char name[22];          /* filename for status bar */
48
  double dnext;           /* threshold value for next tick */
49
};
50
typedef struct simple_progress_s simple_progress_t;
51

  
52
/* print a simple progress bar. This is a callback function that is
53
   potentially called often; thus, it has been optimized for the
54
   typical case, which is when the progress bar does not need updating. */
55
static void simple_progress(double d, void *data) {
56
  simple_progress_t *p = (simple_progress_t *)data;
57
  static char b[] = "========================================";
58
  int tick;    /* number of visible tickmarks, 0..40 */
59
  int perc;    /* visible percentage, 0..100 */
60

  
61
  /* note: the 0.01 and 0.025 ensure that we always end on 40
62
     tickmarks and 100%, despite any rounding errors. The 0.995
63
     ensures that tick always increases when d >= p->dnext. */
64
  if (d >= p->dnext) {
65
    tick = (int) floor(d*40+0.01);
66
    perc = (int) floor(d*100+0.025);
67
    fprintf(stderr, "%-21s |%-40s| %d%% "COL0"", p->name, b+40-tick, perc);
68
    p->dnext = (tick+0.995) / 40.0;
69
  }
70
}
71

  
72
/* Initialize parameters for simple progress bar. The caller passes an
73
   allocated simple_progress_t structure to avoid having to malloc it
74
   here and free it later. */
75
static inline void init_progress(potrace_progress_t *prog, simple_progress_t *p, const char *filename, int count) {
76
  const char *q, *s;
77
  int len;
78

  
79
  /* initialize callback function's data */
80
  p->dnext = 0;
81

  
82
  if (count != 0) {
83
    sprintf(p->name, " (p.%d):", count+1);
84
  } else {
85
    s = filename;
86
    if ((q = strrchr(s, '/')) != NULL) {
87
      s = q+1;
88
    }
89
    len = strlen(s);
90
    strncpy(p->name, s, 21);
91
    p->name[20] = 0;
92
    if (len > 20) {
93
      p->name[17] = '.';
94
      p->name[18] = '.';
95
      p->name[19] = '.';
96
    }
97
    strcat(p->name, ":");
98
  }
99

  
100
  /* initialize progress parameters */
101
  prog->callback = &simple_progress;
102
  prog->data = (void *)p;
103
  prog->min = 0.0;
104
  prog->max = 1.0;
105
  prog->epsilon = 0.0;
106
  
107
  /* draw first progress bar */
108
  simple_progress(0.0, prog->data);
109
  return;
110
}
111

  
112
/* ---------------------------------------------------------------------- */
113
/* some data structures for option processing */
114

  
115
struct pageformat_s {
116
  char *name;
117
  int w, h;
118
};
119
typedef struct pageformat_s pageformat_t;
120

  
121
/* dimensions of the various page formats, in postscript points */
122
static pageformat_t pageformat[] = {
123
  { "a4",        595,  842 },
124
  { "a3",        842, 1191 },
125
  { "a5",        421,  595 },
126
  { "b5",        516,  729 },
127
  { "letter",    612,  792 },
128
  { "legal",     612, 1008 },
129
  { "tabloid",   792, 1224 },
130
  { "statement", 396,  612 },
131
  { "executive", 540,  720 },
132
  { "folio",     612,  936 },
133
  { "quarto",    610,  780 },
134
  { "10x14",     720, 1008 },
135
  { NULL, 0, 0 },
136
};
137

  
138
struct turnpolicy_s {
139
  char *name;
140
  int n;
141
};
142
typedef struct turnpolicy_s turnpolicy_t;
143

  
144
/* names of turn policies */
145
static turnpolicy_t turnpolicy[] = {
146
  {"black",    POTRACE_TURNPOLICY_BLACK},
147
  {"white",    POTRACE_TURNPOLICY_WHITE},
148
  {"left",     POTRACE_TURNPOLICY_LEFT},
149
  {"right",    POTRACE_TURNPOLICY_RIGHT},
150
  {"minority", POTRACE_TURNPOLICY_MINORITY},
151
  {"majority", POTRACE_TURNPOLICY_MAJORITY},
152
  {"random",   POTRACE_TURNPOLICY_RANDOM},
153
  {NULL, 0},
154
};
155

  
156
/* backends and their characteristics */
157
struct backend_s {
158
  char *name;       /* name of this backend */
159
  char *ext;        /* file extension */
160
  int fixed;        /* fixed page size backend? */
161
  int pixel;        /* pixel-based backend? */
162
  int multi;        /* multi-page backend? */
163
  int (*init_f)(FILE *fout);                 /* initialization function */
164
  int (*page_f)(FILE *fout, potrace_path_t *plist, imginfo_t *imginfo);
165
                                             /* per-bitmap function */
166
  int (*term_f)(FILE *fout);                 /* finalization function */
167
  int opticurve;    /* opticurve capable (true Bezier curves?) */
168
};
169
typedef struct backend_s backend_t;  
170

  
171
static backend_t backend[] = {
172
  {"eps",        ".eps",      0, 0, 0, NULL,    page_eps,   NULL,     1},
173
  {"postscript", ".ps",       1, 0, 1, init_ps, page_ps,    term_ps,  1},
174
  {"ps",         ".ps",       1, 0, 1, init_ps, page_ps,    term_ps,  1},
175
  {"pdf",        ".pdf",      0, 0, 1, init_pdf,page_pdf,   term_pdf, 1},
176
  {"svg",        ".svg",      0, 0, 0, NULL,    page_svg,   NULL,     1},
177
  {"pgm",        ".pgm",      0, 1, 1, NULL,    page_pgm,   NULL,     1},
178
  {"gimppath",   ".gimppath", 0, 1, 0, NULL,    page_gimp,  NULL,     1},
179
  {"xfig",       ".fig",      1, 0, 0, NULL,    page_xfig,  NULL,     0},
180
  {NULL, NULL, 0, 0, 0, NULL, NULL, NULL},
181
};
182

  
183
/* look up a backend by name. If found, return 0 and set *bp. If not
184
   found leave *bp unchanged and return 1, or 2 on ambiguous
185
   prefix. */
186
static int backend_lookup(char *name, backend_t **bp) {
187
  int i;
188
  int m=0;  /* prefix matches */
189
  backend_t *b = NULL;
190

  
191
  for (i=0; backend[i].name; i++) {
192
    if (strcasecmp(backend[i].name, name)==0) {
193
      *bp = &backend[i];
194
      return 0;
195
    } else if (strncasecmp(backend[i].name, name, strlen(name))==0) {
196
      m++;
197
      b = &backend[i];
198
    }      
199
  }
200
  /* if there was no exact match, and exactly one prefix match, use that */
201
  if (m==1) {  
202
    *bp = b;
203
    return 0;
204
  } else if (m) {
205
    return 2;
206
  } else {
207
    return 1;
208
  }
209
}
210

  
211
/* list all available backends by name, in a comma separated list.
212
   Assume the cursor starts in column j, and break lines at length
213
   linelen. Do not output any trailing punctuation. Return the column
214
   the cursor is in. */
215
static int backend_list(FILE *fout, int j, int linelen) {
216
  int i;
217

  
218
  for (i=0; backend[i].name; i++) {
219
    if (j + (int)strlen(backend[i].name) > linelen) {
220
      fprintf(fout, "\n");
221
      j = 0;
222
    }
223
    j += fprintf(fout, "%s", backend[i].name);
224
    if (backend[i+1].name) {
225
      j += fprintf(fout, ", ");
226
    }
227
  }
228
  return j;
229
}
230

  
231
/* ---------------------------------------------------------------------- */
232
/* some info functions */
233

  
234
static void license(FILE *f) {
235
  fprintf(f, 
236
  "This program is free software; you can redistribute it and/or modify\n"
237
  "it under the terms of the GNU General Public License as published by\n"
238
  "the Free Software Foundation; either version 2 of the License, or\n"
239
  "(at your option) any later version.\n"
240
  "\n"
241
  "This program is distributed in the hope that it will be useful,\n"
242
  "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
243
  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
244
  "GNU General Public License for more details.\n"
245
  "\n"
246
  "You should have received a copy of the GNU General Public License\n"
247
  "along with this program; if not, write to the Free Software\n"
248
  "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.\n"
249
	  );
250
}
251

  
252
static void show_defaults(FILE *f) {
253
  fprintf(f, "This version of Potrace was compiled with the following defaults:\n");
254
  fprintf(f, "Default unit: "DEFAULT_DIM_NAME"\n");
255
  fprintf(f, "Default page size: "DEFAULT_PAPERFORMAT"\n");
256
}
257

  
258
static void usage(FILE *f) {
259
  int j;
260

  
261
  fprintf(f, "Usage: "POTRACE" [options] [file...]\n");
262
  fprintf(f, "General options:\n");
263
  fprintf(f, " -h, --help                 - print this help message and exit\n");
264
  fprintf(f, " -v, --version              - print version info and exit\n");
265
  fprintf(f, " -l, --license              - print license info and exit\n");
266
  fprintf(f, " -V, --show-defaults        - print compiled-in defaults and exit\n");
267
  fprintf(f, " --progress                 - show progress bar\n");
268
  fprintf(f, "Input/output options:\n");
269
  fprintf(f, " -o, --output <file>        - output to file\n");
270
  fprintf(f, "Backend selection:\n");
271
  fprintf(f, " -e, --eps                  - EPS backend (encapsulated postscript) (default)\n");
272
  fprintf(f, " -p, --postscript           - Postscript backend\n");
273
  fprintf(f, " -s, --svg                  - SVG backend (scalable vector graphics)\n");
274
  fprintf(f, " -g, --pgm                  - PGM backend (portable greymap)\n");
275
  fprintf(f, " -b, --backend <name>       - select backend by name\n");
276
  fprintf(f, "Algorithm options:\n");
277
  fprintf(f, " -z, --turnpolicy <policy>  - how to resolve ambiguities in path decomposition\n");
278
  fprintf(f, " -t, --turdsize <n>         - suppress speckles of up to this size (default 2)\n");
279
  fprintf(f, " -a, --alphamax <n>         - corner threshold parameter (default 1)\n");
280
  fprintf(f, " -n, --longcurve            - turn off curve optimization\n");
281
  fprintf(f, " -O, --opttolerance <n>     - curve optimization tolerance (default 0.2)\n");
282
  fprintf(f, " -u, --unit <n>             - quantize output to 1/unit pixels (default 10)\n");
283
  fprintf(f, " -d, --debug <n>            - produce debugging output of type n (n=1,2,3)\n");
284
  fprintf(f, "Scaling and placement options:\n");
285
  fprintf(f, " -W, --width <dim>          - width of output image\n");
286
  fprintf(f, " -H, --height <dim>         - height of output image\n");
287
  fprintf(f, " -r, --resolution <n>[x<n>] - resolution (in dpi)\n");
288
  fprintf(f, " -x, --scale <n>[x<n>]      - scaling factor (pgm backend)\n");
289
  fprintf(f, " -S, --stretch <n>          - yresolution/xresolution\n");
290
  fprintf(f, " -A, --rotate <angle>       - rotate counterclockwise by angle\n");
291
  fprintf(f, " -M, --margin <dim>         - margin\n");
292
  fprintf(f, " -L, --leftmargin <dim>     - left margin\n");
293
  fprintf(f, " -R, --rightmargin <dim>    - right margin\n");
294
  fprintf(f, " -T, --topmargin <dim>      - top margin\n");
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff