Revision 31974
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_11/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_11/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_11/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_11/libraries/libjni-potrace/src/main/native/jpotrace/potracelib.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 |
#include <stdlib.h> |
|
6 |
#include <string.h> |
|
7 |
|
|
8 |
#include "potracelib.h" |
|
9 |
#include "curve.h" |
|
10 |
#include "decompose.h" |
|
11 |
#include "trace.h" |
|
12 |
#include "progress.h" |
|
13 |
|
|
14 |
#ifdef HAVE_CONFIG_H |
|
15 |
#include "config.h" |
|
16 |
#endif |
|
17 |
|
|
18 |
/* default parameters */ |
|
19 |
static const potrace_param_t param_default = { |
|
20 |
2, /* turdsize */ |
|
21 |
POTRACE_TURNPOLICY_MINORITY, /* turnpolicy */ |
|
22 |
1.0, /* alphamax */ |
|
23 |
1, /* opticurve */ |
|
24 |
0.2, /* opttolerance */ |
|
25 |
{ |
|
26 |
NULL, /* callback function */ |
|
27 |
NULL, /* callback data */ |
|
28 |
0.0, 1.0, /* progress range */ |
|
29 |
0.0, /* granularity */ |
|
30 |
}, |
|
31 |
}; |
|
32 |
|
|
33 |
/* Return a fresh copy of the set of default parameters, or NULL on |
|
34 |
failure with errno set. */ |
|
35 |
potrace_param_t *potrace_param_default(void) { |
|
36 |
potrace_param_t *p; |
|
37 |
|
|
38 |
p = (potrace_param_t *) malloc(sizeof(potrace_param_t)); |
|
39 |
if (!p) { |
|
40 |
return NULL; |
|
41 |
} |
|
42 |
memcpy(p, ¶m_default, sizeof(potrace_param_t)); |
|
43 |
return p; |
|
44 |
} |
|
45 |
|
|
46 |
/* On success, returns a Potrace state st with st->status == |
|
47 |
POTRACE_STATUS_OK. On failure, returns NULL if no Potrace state |
|
48 |
could be created (with errno set), or returns an incomplete Potrace |
|
49 |
state (with st->status == POTRACE_STATUS_INCOMPLETE). Complete or |
|
50 |
incomplete Potrace state can be freed with potrace_state_free(). */ |
|
51 |
potrace_state_t *potrace_trace(const potrace_param_t *param, const potrace_bitmap_t *bm) { |
|
52 |
int r; |
|
53 |
path_t *plist = NULL; |
|
54 |
potrace_state_t *st; |
|
55 |
progress_t prog; |
|
56 |
progress_t subprog; |
|
57 |
|
|
58 |
/* prepare private progress bar state */ |
|
59 |
prog.callback = param->progress.callback; |
|
60 |
prog.data = param->progress.data; |
|
61 |
prog.min = param->progress.min; |
|
62 |
prog.max = param->progress.max; |
|
63 |
prog.epsilon = param->progress.epsilon; |
|
64 |
prog.d_prev = param->progress.min; |
|
65 |
|
|
66 |
/* allocate state object */ |
|
67 |
st = (potrace_state_t *)malloc(sizeof(potrace_state_t)); |
|
68 |
if (!st) { |
|
69 |
return NULL; |
|
70 |
} |
|
71 |
|
|
72 |
progress_subrange_start(0.0, 0.1, &prog, &subprog); |
|
73 |
|
|
74 |
/* process the image */ |
|
75 |
r = bm_to_pathlist(bm, &plist, param, &subprog); |
|
76 |
if (r) { |
|
77 |
free(st); |
|
78 |
return NULL; |
|
79 |
} |
|
80 |
|
|
81 |
st->status = POTRACE_STATUS_OK; |
|
82 |
st->plist = plist; |
|
83 |
st->priv = NULL; /* private state currently unused */ |
|
84 |
|
|
85 |
progress_subrange_end(&prog, &subprog); |
|
86 |
|
|
87 |
progress_subrange_start(0.1, 1.0, &prog, &subprog); |
|
88 |
|
|
89 |
/* partial success. */ |
|
90 |
r = process_path(plist, param, &subprog); |
|
91 |
if (r) { |
|
92 |
st->status = POTRACE_STATUS_INCOMPLETE; |
|
93 |
} |
|
94 |
|
|
95 |
progress_subrange_end(&prog, &subprog); |
|
96 |
|
|
97 |
return st; |
|
98 |
} |
|
99 |
|
|
100 |
/* free a Potrace state, without disturbing errno. */ |
|
101 |
void potrace_state_free(potrace_state_t *st) { |
|
102 |
pathlist_free(st->plist); |
|
103 |
free(st); |
|
104 |
} |
|
105 |
|
|
106 |
/* free a parameter list, without disturbing errno. */ |
|
107 |
void potrace_param_free(potrace_param_t *p) { |
|
108 |
free(p); |
|
109 |
} |
|
110 |
|
|
111 |
char *potrace_version(void) { |
|
112 |
return "potracelib "VERSION""; |
|
113 |
} |
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_11/libraries/libjni-potrace/src/main/native/jpotrace/curve.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: curve.c 147 2007-04-09 00:44:09Z selinger $ */ |
|
6 |
/* private part of the path and curve data structures */ |
|
7 |
|
|
8 |
#include <stdio.h> |
|
9 |
#include <stdlib.h> |
|
10 |
#include <string.h> |
|
11 |
|
|
12 |
#include "potracelib.h" |
|
13 |
#include "lists.h" |
|
14 |
#include "curve.h" |
|
15 |
|
|
16 |
#define SAFE_MALLOC(var, n, typ) \ |
|
17 |
if ((var = (typ *)malloc((n)*sizeof(typ))) == NULL) goto malloc_error |
|
18 |
|
|
19 |
/* ---------------------------------------------------------------------- */ |
|
20 |
/* allocate and free path objects */ |
|
21 |
|
|
22 |
path_t *path_new(void) { |
|
23 |
path_t *p = NULL; |
|
24 |
privpath_t *priv = NULL; |
|
25 |
|
|
26 |
SAFE_MALLOC(p, 1, path_t); |
|
27 |
memset(p, 0, sizeof(path_t)); |
|
28 |
SAFE_MALLOC(priv, 1, privpath_t); |
|
29 |
memset(priv, 0, sizeof(privpath_t)); |
|
30 |
p->priv = priv; |
|
31 |
return p; |
|
32 |
|
|
33 |
malloc_error: |
|
34 |
free(p); |
|
35 |
free(priv); |
|
36 |
return NULL; |
|
37 |
} |
|
38 |
|
|
39 |
/* free the members of the given curve structure. Leave errno unchanged. */ |
|
40 |
static void privcurve_free_members(privcurve_t *curve) { |
|
41 |
free(curve->tag); |
|
42 |
free(curve->c); |
|
43 |
free(curve->vertex); |
|
44 |
free(curve->alpha); |
|
45 |
free(curve->alpha0); |
|
46 |
free(curve->beta); |
|
47 |
} |
|
48 |
|
|
49 |
/* free a path. Leave errno untouched. */ |
|
50 |
void path_free(path_t *p) { |
|
51 |
if (p) { |
|
52 |
if (p->priv) { |
|
53 |
free(p->priv->pt); |
|
54 |
free(p->priv->lon); |
|
55 |
free(p->priv->sums); |
|
56 |
free(p->priv->po); |
|
57 |
privcurve_free_members(&p->priv->curve); |
|
58 |
privcurve_free_members(&p->priv->ocurve); |
|
59 |
} |
|
60 |
free(p->priv); |
|
61 |
/* do not free p->fcurve ! */ |
|
62 |
} |
|
63 |
free(p); |
|
64 |
} |
|
65 |
|
|
66 |
/* free a pathlist, leaving errno untouched. */ |
|
67 |
void pathlist_free(path_t *plist) { |
|
68 |
path_t *p; |
|
69 |
|
|
70 |
list_forall_unlink(p, plist) { |
|
71 |
path_free(p); |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
/* ---------------------------------------------------------------------- */ |
|
76 |
/* initialize and finalize curve structures */ |
|
77 |
|
|
78 |
typedef dpoint_t dpoint3_t[3]; |
|
79 |
|
|
80 |
/* initialize the members of the given curve structure to size m. |
|
81 |
Return 0 on success, 1 on error with errno set. */ |
|
82 |
int privcurve_init(privcurve_t *curve, int n) { |
|
83 |
memset(curve, 0, sizeof(privcurve_t)); |
|
84 |
curve->n = n; |
|
85 |
SAFE_MALLOC(curve->tag, n, int); |
|
86 |
SAFE_MALLOC(curve->c, n, dpoint3_t); |
|
87 |
SAFE_MALLOC(curve->vertex, n, dpoint_t); |
|
88 |
SAFE_MALLOC(curve->alpha, n, double); |
|
89 |
SAFE_MALLOC(curve->alpha0, n, double); |
|
90 |
SAFE_MALLOC(curve->beta, n, double); |
|
91 |
return 0; |
|
92 |
|
|
93 |
malloc_error: |
|
94 |
free(curve->tag); |
|
95 |
free(curve->c); |
|
96 |
free(curve->vertex); |
|
97 |
free(curve->alpha); |
|
98 |
free(curve->alpha0); |
|
99 |
free(curve->beta); |
|
100 |
return 1; |
|
101 |
} |
|
102 |
|
|
103 |
/* copy private to public curve structure */ |
|
104 |
void privcurve_to_curve(privcurve_t *pc, potrace_curve_t *c) { |
|
105 |
c->n = pc->n; |
|
106 |
c->tag = pc->tag; |
|
107 |
c->c = pc->c; |
|
108 |
} |
|
109 |
|
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_11/libraries/libjni-potrace/src/main/native/jpotrace/backend_pdf.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: backend_pdf.h 147 2007-04-09 00:44:09Z selinger $ */ |
|
6 |
|
|
7 |
#ifndef BACKEND_PDF_H |
|
8 |
#define BACKEND_PDF_H |
|
9 |
|
|
10 |
#include "potracelib.h" |
|
11 |
#include "main.h" |
|
12 |
|
|
13 |
int init_pdf(FILE *fout); |
|
14 |
int page_pdf(FILE *fout, potrace_path_t *plist, imginfo_t *imginfo); |
|
15 |
int term_pdf(FILE *fout); |
|
16 |
|
|
17 |
int page_pdf(FILE *fout, potrace_path_t *plist, imginfo_t *imginfo); |
|
18 |
|
|
19 |
#endif /* BACKEND_PDF_H */ |
|
20 |
|
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_11/libraries/libjni-potrace/src/main/native/jpotrace/potracelib_demo.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 |
/* A simple and self-contained demo of the potracelib API */ |
|
6 |
|
|
7 |
#include <stdio.h> |
|
8 |
#include <string.h> |
|
9 |
#include <errno.h> |
|
10 |
#include <stdlib.h> |
|
11 |
|
|
12 |
#include "potracelib.h" |
|
13 |
|
|
14 |
#define WIDTH 250 |
|
15 |
#define HEIGHT 250 |
|
16 |
|
|
17 |
/* ---------------------------------------------------------------------- */ |
|
18 |
/* auxiliary bitmap functions */ |
|
19 |
|
|
20 |
/* macros for writing individual bitmap pixels */ |
|
21 |
#define BM_WORDSIZE ((int)sizeof(potrace_word)) |
|
22 |
#define BM_WORDBITS (8*BM_WORDSIZE) |
|
23 |
#define BM_HIBIT (((potrace_word)1)<<(BM_WORDBITS-1)) |
|
24 |
#define bm_scanline(bm, y) ((bm)->map + (y)*(bm)->dy) |
|
25 |
#define bm_index(bm, x, y) (&bm_scanline(bm, y)[(x)/BM_WORDBITS]) |
|
26 |
#define bm_mask(x) (BM_HIBIT >> ((x) & (BM_WORDBITS-1))) |
|
27 |
#define bm_range(x, a) ((int)(x) >= 0 && (int)(x) < (a)) |
|
28 |
#define bm_safe(bm, x, y) (bm_range(x, (bm)->w) && bm_range(y, (bm)->h)) |
|
29 |
#define BM_USET(bm, x, y) (*bm_index(bm, x, y) |= bm_mask(x)) |
|
30 |
#define BM_UCLR(bm, x, y) (*bm_index(bm, x, y) &= ~bm_mask(x)) |
|
31 |
#define BM_UPUT(bm, x, y, b) ((b) ? BM_USET(bm, x, y) : BM_UCLR(bm, x, y)) |
|
32 |
#define BM_PUT(bm, x, y, b) (bm_safe(bm, x, y) ? BM_UPUT(bm, x, y, b) : 0) |
|
33 |
|
|
34 |
/* return new un-initialized bitmap. NULL with errno on error */ |
|
35 |
static potrace_bitmap_t *bm_new(int w, int h) { |
|
36 |
potrace_bitmap_t *bm; |
|
37 |
int dy = (w + BM_WORDBITS - 1) / BM_WORDBITS; |
|
38 |
|
|
39 |
bm = (potrace_bitmap_t *) malloc(sizeof(potrace_bitmap_t)); |
|
40 |
if (!bm) { |
|
41 |
return NULL; |
|
42 |
} |
|
43 |
bm->w = w; |
|
44 |
bm->h = h; |
|
45 |
bm->dy = dy; |
|
46 |
bm->map = (potrace_word *) malloc(dy * h * BM_WORDSIZE); |
|
47 |
if (!bm->map) { |
|
48 |
free(bm); |
|
49 |
return NULL; |
|
50 |
} |
|
51 |
return bm; |
|
52 |
} |
|
53 |
|
|
54 |
/* free a bitmap */ |
|
55 |
static void bm_free(potrace_bitmap_t *bm) { |
|
56 |
if (bm != NULL) { |
|
57 |
free(bm->map); |
|
58 |
} |
|
59 |
free(bm); |
|
60 |
} |
|
61 |
|
|
62 |
/* ---------------------------------------------------------------------- */ |
|
63 |
/* demo */ |
|
64 |
|
|
65 |
int main() { |
|
66 |
int x, y, i; |
|
67 |
potrace_bitmap_t *bm; |
|
68 |
potrace_param_t *param; |
|
69 |
potrace_path_t *p; |
|
70 |
potrace_state_t *st; |
|
71 |
int n, *tag; |
|
72 |
potrace_dpoint_t (*c)[3]; |
|
73 |
|
|
74 |
/* create a bitmap */ |
|
75 |
bm = bm_new(WIDTH, HEIGHT); |
|
76 |
if (!bm) { |
|
77 |
fprintf(stderr, "Error allocating bitmap: %s\n", strerror(errno)); |
|
78 |
return 1; |
|
79 |
} |
|
80 |
|
|
81 |
/* fill the bitmap with some pattern */ |
|
82 |
for (y=0; y<HEIGHT; y++) { |
|
83 |
for (x=0; x<WIDTH; x++) { |
|
84 |
BM_PUT(bm, x, y, ((x*x + y*y*y) % 10000 < 5000) ? 1 : 0); |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
88 |
/* set tracing parameters, starting from defaults */ |
|
89 |
param = potrace_param_default(); |
|
90 |
if (!param) { |
|
91 |
fprintf(stderr, "Error allocating parameters: %s\n", strerror(errno)); |
|
92 |
return 1; |
|
93 |
} |
|
94 |
param->turdsize = 0; |
|
95 |
|
|
96 |
/* trace the bitmap */ |
|
97 |
st = potrace_trace(param, bm); |
|
98 |
if (!st || st->status != POTRACE_STATUS_OK) { |
|
99 |
fprintf(stderr, "Error tracing bitmap: %s\n", strerror(errno)); |
|
100 |
return 1; |
|
101 |
} |
|
102 |
bm_free(bm); |
|
103 |
|
|
104 |
/* output vector data, e.g. as a rudimentary EPS file */ |
|
105 |
printf("%%!PS-Adobe-3.0 EPSF-3.0\n"); |
|
106 |
printf("%%%%BoundingBox: 0 0 %d %d\n", WIDTH, HEIGHT); |
|
107 |
printf("gsave\n"); |
|
108 |
|
|
109 |
/* draw each curve */ |
|
110 |
p = st->plist; |
|
111 |
while (p != NULL) { |
|
112 |
n = p->curve.n; |
|
113 |
tag = p->curve.tag; |
|
114 |
c = p->curve.c; |
|
115 |
printf("%f %f moveto\n", c[n-1][2].x, c[n-1][2].y); |
|
116 |
for (i=0; i<n; i++) { |
|
117 |
switch (tag[i]) { |
|
118 |
case POTRACE_CORNER: |
|
119 |
printf("%f %f lineto\n", c[i][1].x, c[i][1].y); |
|
120 |
printf("%f %f lineto\n", c[i][2].x, c[i][2].y); |
|
121 |
break; |
|
122 |
case POTRACE_CURVETO: |
|
123 |
printf("%f %f %f %f %f %f curveto\n", |
|
124 |
c[i][0].x, c[i][0].y, |
|
125 |
c[i][1].x, c[i][1].y, |
|
126 |
c[i][2].x, c[i][2].y); |
|
127 |
break; |
|
128 |
} |
|
129 |
} |
|
130 |
/* at the end of a group of a positive path and its negative |
|
131 |
children, fill. */ |
|
132 |
if (p->next == NULL || p->next->sign == '+') { |
|
133 |
printf("0 setgray fill\n"); |
|
134 |
} |
|
135 |
p = p->next; |
|
136 |
} |
|
137 |
printf("grestore\n"); |
|
138 |
printf("%%EOF\n"); |
|
139 |
|
|
140 |
potrace_state_free(st); |
|
141 |
potrace_param_free(param); |
|
142 |
|
|
143 |
return 0; |
|
144 |
} |
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_11/libraries/libjni-potrace/src/main/native/jpotrace/potracelib.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 POTRACELIB_H |
|
6 |
#define POTRACELIB_H |
|
7 |
|
|
8 |
/* this file defines the API for the core Potrace library. For a more |
|
9 |
detailed description of the API, see doc/potracelib.txt */ |
|
10 |
|
|
11 |
/* ---------------------------------------------------------------------- */ |
|
12 |
/* tracing parameters */ |
|
13 |
|
|
14 |
/* turn policies */ |
|
15 |
#define POTRACE_TURNPOLICY_BLACK 0 |
|
16 |
#define POTRACE_TURNPOLICY_WHITE 1 |
|
17 |
#define POTRACE_TURNPOLICY_LEFT 2 |
|
18 |
#define POTRACE_TURNPOLICY_RIGHT 3 |
|
19 |
#define POTRACE_TURNPOLICY_MINORITY 4 |
|
20 |
#define POTRACE_TURNPOLICY_MAJORITY 5 |
|
21 |
#define POTRACE_TURNPOLICY_RANDOM 6 |
|
22 |
|
|
23 |
/* structure to hold progress bar callback data */ |
|
24 |
struct potrace_progress_s { |
|
25 |
void (*callback)(double progress, void *privdata); /* callback fn */ |
|
26 |
void *data; /* callback function's private data */ |
|
27 |
double min, max; /* desired range of progress, e.g. 0.0 to 1.0 */ |
|
28 |
double epsilon; /* granularity: can skip smaller increments */ |
|
29 |
}; |
|
30 |
typedef struct potrace_progress_s potrace_progress_t; |
|
31 |
|
|
32 |
/* structure to hold tracing parameters */ |
|
33 |
struct potrace_param_s { |
|
34 |
int turdsize; /* area of largest path to be ignored */ |
|
35 |
int turnpolicy; /* resolves ambiguous turns in path decomposition */ |
|
36 |
double alphamax; /* corner threshold */ |
|
37 |
int opticurve; /* use curve optimization? */ |
|
38 |
double opttolerance; /* curve optimization tolerance */ |
|
39 |
potrace_progress_t progress; /* progress callback function */ |
|
40 |
}; |
|
41 |
typedef struct potrace_param_s potrace_param_t; |
|
42 |
|
|
43 |
/* ---------------------------------------------------------------------- */ |
|
44 |
/* bitmaps */ |
|
45 |
|
|
46 |
/* native word size */ |
|
47 |
typedef unsigned long potrace_word; |
|
48 |
|
|
49 |
/* Internal bitmap format. The n-th scanline starts at scanline(n) = |
|
50 |
(map + n*dy). Raster data is stored as a sequence of potrace_words |
|
51 |
(NOT bytes). The leftmost bit of scanline n is the most significant |
|
52 |
bit of scanline(n)[0]. */ |
|
53 |
struct potrace_bitmap_s { |
|
54 |
int w, h; /* width and height, in pixels */ |
|
55 |
int dy; /* words per scanline (not bytes) */ |
|
56 |
potrace_word *map; /* raw data, dy*h words */ |
|
57 |
}; |
|
58 |
typedef struct potrace_bitmap_s potrace_bitmap_t; |
|
59 |
|
|
60 |
/* ---------------------------------------------------------------------- */ |
|
61 |
/* curves */ |
|
62 |
|
|
63 |
/* point */ |
|
64 |
struct potrace_dpoint_s { |
|
65 |
double x, y; |
|
66 |
}; |
|
67 |
typedef struct potrace_dpoint_s potrace_dpoint_t; |
|
68 |
|
|
69 |
/* segment tags */ |
|
70 |
#define POTRACE_CURVETO 1 |
|
71 |
#define POTRACE_CORNER 2 |
|
72 |
|
|
73 |
/* closed curve segment */ |
|
74 |
struct potrace_curve_s { |
|
75 |
int n; /* number of segments */ |
|
76 |
int *tag; /* tag[n]: POTRACE_CURVETO or POTRACE_CORNER */ |
|
77 |
potrace_dpoint_t (*c)[3]; /* c[n][3]: control points. |
|
78 |
c[n][0] is unused for tag[n]=POTRACE_CORNER */ |
|
79 |
}; |
|
80 |
typedef struct potrace_curve_s potrace_curve_t; |
|
81 |
|
|
82 |
/* Linked list of signed curve segments. Also carries a tree structure. */ |
|
83 |
struct potrace_path_s { |
|
84 |
int area; /* area of the bitmap path */ |
|
85 |
int sign; /* '+' or '-', depending on orientation */ |
|
86 |
potrace_curve_t curve; /* this path's vector data */ |
|
87 |
|
|
88 |
struct potrace_path_s *next; /* linked list structure */ |
|
89 |
|
|
90 |
struct potrace_path_s *childlist; /* tree structure */ |
|
91 |
struct potrace_path_s *sibling; /* tree structure */ |
|
92 |
|
|
93 |
struct potrace_privpath_s *priv; /* private state */ |
|
94 |
}; |
|
95 |
typedef struct potrace_path_s potrace_path_t; |
|
96 |
|
|
97 |
/* ---------------------------------------------------------------------- */ |
|
98 |
/* Potrace state */ |
|
99 |
|
|
100 |
#define POTRACE_STATUS_OK 0 |
|
101 |
#define POTRACE_STATUS_INCOMPLETE 1 |
|
102 |
|
|
103 |
struct potrace_state_s { |
|
104 |
int status; |
|
105 |
potrace_path_t *plist; /* vector data */ |
|
106 |
|
|
107 |
struct potrace_privstate_s *priv; /* private state */ |
|
108 |
}; |
|
109 |
typedef struct potrace_state_s potrace_state_t; |
|
110 |
|
|
111 |
/* ---------------------------------------------------------------------- */ |
|
112 |
/* API functions */ |
|
113 |
|
|
114 |
/* get default parameters */ |
|
115 |
potrace_param_t *potrace_param_default(void); |
|
116 |
|
|
117 |
/* free parameter set */ |
|
118 |
void potrace_param_free(potrace_param_t *p); |
|
119 |
|
|
120 |
/* trace a bitmap*/ |
|
121 |
potrace_state_t *potrace_trace(const potrace_param_t *param, |
|
122 |
const potrace_bitmap_t *bm); |
|
123 |
|
|
124 |
/* free a Potrace state */ |
|
125 |
void potrace_state_free(potrace_state_t *st); |
|
126 |
|
|
127 |
/* return a static plain text version string identifying this version |
|
128 |
of potracelib */ |
|
129 |
char *potrace_version(void); |
|
130 |
|
|
131 |
#endif /* POTRACELIB_H */ |
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_11/libraries/libjni-potrace/src/main/native/jpotrace/platform.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 |
/* this header file contains some platform dependent stuff */ |
|
6 |
|
|
7 |
#ifndef PLATFORM_H |
|
8 |
#define PLATFORM_H |
|
9 |
|
|
10 |
#ifdef HAVE_CONFIG_H |
|
11 |
#include "config.h" |
|
12 |
#endif |
|
13 |
|
|
14 |
/* in Windows, set all file i/o to binary */ |
|
15 |
#ifdef __MINGW32__ |
|
16 |
#include <fcntl.h> |
|
17 |
unsigned int _CRT_fmode = _O_BINARY; |
|
18 |
#endif |
|
19 |
|
|
20 |
#ifdef __CYGWIN__ |
|
21 |
#include <fcntl.h> |
|
22 |
#include <io.h> |
|
23 |
static inline void platform_init(void) { |
|
24 |
setmode(0,O_BINARY); |
|
25 |
setmode(1,O_BINARY); |
|
26 |
} |
|
27 |
#else |
|
28 |
static inline void platform_init(void) { |
|
29 |
/* NOP */ |
|
30 |
} |
|
31 |
#endif |
|
32 |
|
|
33 |
#endif /* PLATFORM_H */ |
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_11/libraries/libjni-potrace/src/main/native/jpotrace/curve.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 CURVE_H |
|
6 |
#define CURVE_H |
|
7 |
|
|
8 |
#include "auxiliary.h" |
|
9 |
|
|
10 |
/* vertex is c[1] for tag=POTRACE_CORNER, and the intersection of |
|
11 |
.c[-1][2]..c[0] and c[1]..c[2] for tag=POTRACE_CURVETO. alpha is only |
|
12 |
defined for tag=POTRACE_CURVETO and is the alpha parameter of the curve: |
|
13 |
.c[-1][2]..c[0] = alpha*(.c[-1][2]..vertex), and |
|
14 |
c[2]..c[1] = alpha*(c[2]..vertex). |
|
15 |
Beta is so that (.beta[i])[.vertex[i],.vertex[i+1]] = .c[i][2]. |
|
16 |
*/ |
|
17 |
|
|
18 |
struct privcurve_s { |
|
19 |
int n; /* number of segments */ |
|
20 |
int *tag; /* tag[n]: POTRACE_CORNER or POTRACE_CURVETO */ |
|
21 |
dpoint_t (*c)[3]; /* c[n][i]: control points. |
|
22 |
c[n][0] is unused for tag[n]=POTRACE_CORNER */ |
|
23 |
/* the remainder of this structure is special to privcurve, and is |
|
24 |
used in EPS debug output and special EPS "short coding". These |
|
25 |
fields are valid only if "alphacurve" is set. */ |
|
26 |
int alphacurve; /* have the following fields been initialized? */ |
|
27 |
dpoint_t *vertex; /* for POTRACE_CORNER, this equals c[1] */ |
|
28 |
double *alpha; /* only for POTRACE_CURVETO */ |
|
29 |
double *alpha0; /* "uncropped" alpha parameter - for debug output only */ |
|
30 |
double *beta; |
|
31 |
}; |
|
32 |
typedef struct privcurve_s privcurve_t; |
|
33 |
|
|
34 |
struct sums_s { |
|
35 |
double x; |
|
36 |
double y; |
|
37 |
double x2; |
|
38 |
double xy; |
|
39 |
double y2; |
|
40 |
}; |
|
41 |
typedef struct sums_s sums_t; |
|
42 |
|
|
43 |
/* the path structure is filled in with information about a given path |
|
44 |
as it is accumulated and passed through the different stages of the |
|
45 |
Potrace algorithm. Backends only need to read the fcurve and fm |
|
46 |
fields of this data structure, but debugging backends may read |
|
47 |
other fields. */ |
|
48 |
struct potrace_privpath_s { |
|
49 |
int len; |
|
50 |
point_t *pt; /* pt[len]: path as extracted from bitmap */ |
|
51 |
int *lon; /* lon[len]: (i,lon[i]) = longest straight line from i */ |
|
52 |
|
|
53 |
int x0, y0; /* origin for sums */ |
|
54 |
sums_t *sums; /* sums[len+1]: cache for fast summing */ |
|
55 |
|
|
56 |
int m; /* length of optimal polygon */ |
|
57 |
int *po; /* po[m]: optimal polygon */ |
|
58 |
|
|
59 |
privcurve_t curve; /* curve[m]: array of curve elements */ |
|
60 |
privcurve_t ocurve; /* ocurve[om]: array of curve elements */ |
|
61 |
privcurve_t *fcurve; /* final curve: this points to either curve or |
|
62 |
ocurve. Do not free this separately. */ |
|
63 |
}; |
|
64 |
typedef struct potrace_privpath_s potrace_privpath_t; |
|
65 |
|
|
66 |
/* shorter names */ |
|
67 |
typedef potrace_privpath_t privpath_t; |
|
68 |
typedef potrace_path_t path_t; |
|
69 |
|
|
70 |
path_t *path_new(void); |
|
71 |
void path_free(path_t *p); |
|
72 |
void pathlist_free(path_t *plist); |
|
73 |
int privcurve_init(privcurve_t *curve, int n); |
|
74 |
void privcurve_to_curve(privcurve_t *pc, potrace_curve_t *c); |
|
75 |
|
|
76 |
#endif /* CURVE_H */ |
|
77 |
|
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_11/libraries/libjni-potrace/src/main/native/jpotrace/flate.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: flate.c 147 2007-04-09 00:44:09Z selinger $ */ |
|
6 |
|
|
7 |
/* the PostScript compression module of Potrace. The basic interface |
|
8 |
is through the *_xship function, which processes a byte array and |
|
9 |
outputs it in compressed or verbatim form, depending on whether |
|
10 |
filter is 1 or 0. To flush the output, simply call with the empty |
|
11 |
string and filter=0. filter=2 is used to output encoded text but |
|
12 |
without the PostScript header to turn on the encoding. Each |
|
13 |
function has variants for shipping a single character, a |
|
14 |
null-terminated string, or a byte array. */ |
|
15 |
|
|
16 |
/* different compression algorithms are available. There is |
|
17 |
dummy_xship, which is just the identity, and flate_xship, which |
|
18 |
uses zlib compression. Also, lzw_xship provides LZW compression |
|
19 |
from the file lzw.c/h. a85_xship provides a85-encoding without |
|
20 |
compression. Each function returns the actual number of characters |
|
21 |
written. */ |
|
22 |
|
|
23 |
/* note: the functions provided here have global state and are not |
|
24 |
reentrant */ |
|
25 |
|
|
26 |
#ifdef HAVE_CONFIG_H |
|
27 |
#include "config.h" |
|
28 |
#endif |
|
29 |
|
|
30 |
#include <stdio.h> |
|
31 |
#include <string.h> |
|
32 |
#include <stdlib.h> |
|
33 |
#include <errno.h> |
|
34 |
|
|
35 |
#ifdef HAVE_ZLIB |
|
36 |
#include <zlib.h> |
|
37 |
#endif |
|
38 |
|
|
39 |
#include "flate.h" |
|
40 |
#include "lzw.h" |
|
41 |
|
|
42 |
#define OUTSIZE 1000 |
|
43 |
|
|
44 |
static int a85init(FILE *f); |
|
45 |
static int a85finish(FILE *f); |
|
46 |
static int a85write(FILE *f, char *buf, int n); |
|
47 |
static int a85out(FILE *f, int n); |
|
48 |
static int a85spool(FILE *f, char c); |
|
49 |
|
|
50 |
/* ---------------------------------------------------------------------- */ |
|
51 |
/* dummy interface: no encoding */ |
|
52 |
|
|
53 |
int dummy_xship(FILE *f, int filter, char *s, int len) { |
|
54 |
fwrite(s, 1, len, f); |
|
55 |
return len; |
|
56 |
} |
|
57 |
|
|
58 |
/* ---------------------------------------------------------------------- */ |
|
59 |
/* flate interface: zlib (=postscript level 3) compression and a85 */ |
|
60 |
|
|
61 |
#ifdef HAVE_ZLIB |
|
62 |
|
|
63 |
int pdf_xship(FILE *f, int filter, char *s, int len) { |
|
64 |
static int fstate = 0; |
|
65 |
static z_stream c_stream; |
|
66 |
char outbuf[OUTSIZE]; |
|
67 |
int err; |
|
68 |
int n=0; |
|
69 |
|
|
70 |
if (filter && !fstate) { |
|
71 |
/* switch on filtering */ |
|
72 |
c_stream.zalloc = Z_NULL; |
|
73 |
c_stream.zfree = Z_NULL; |
|
74 |
c_stream.opaque = Z_NULL; |
|
75 |
err = deflateInit(&c_stream, 9); |
|
76 |
if (err != Z_OK) { |
|
77 |
fprintf(stderr, "deflateInit: %s (%d)\n", c_stream.msg, err); |
|
78 |
exit(1); |
|
79 |
} |
|
80 |
c_stream.avail_in = 0; |
|
81 |
fstate = 1; |
|
82 |
} else if (!filter && fstate) { |
|
83 |
/* switch off filtering */ |
|
84 |
/* flush stream */ |
|
85 |
do { |
|
86 |
c_stream.next_out = (Bytef*)outbuf; |
|
87 |
c_stream.avail_out = OUTSIZE; |
|
88 |
|
|
89 |
err = deflate(&c_stream, Z_FINISH); |
|
90 |
if (err != Z_OK && err != Z_STREAM_END) { |
|
91 |
fprintf(stderr, "deflate: %s (%d)\n", c_stream.msg, err); |
|
92 |
exit(1); |
|
93 |
} |
|
94 |
n += fwrite(outbuf, 1, OUTSIZE-c_stream.avail_out, f); |
|
95 |
} while (err != Z_STREAM_END); |
|
96 |
|
|
97 |
fstate = 0; |
|
98 |
} |
|
99 |
if (!fstate) { |
|
100 |
fwrite(s, 1, len, f); |
|
101 |
return n+len; |
|
102 |
} |
|
103 |
|
|
104 |
/* do the actual compression */ |
|
105 |
c_stream.next_in = (Bytef*) s; |
|
106 |
c_stream.avail_in = len; |
|
107 |
|
|
108 |
do { |
|
109 |
c_stream.next_out = (Bytef*) outbuf; |
|
110 |
c_stream.avail_out = OUTSIZE; |
|
111 |
|
|
112 |
err = deflate(&c_stream, Z_NO_FLUSH); |
|
113 |
if (err != Z_OK) { |
|
114 |
fprintf(stderr, "deflate: %s (%d)\n", c_stream.msg, err); |
|
115 |
exit(1); |
|
116 |
} |
|
117 |
n += fwrite(outbuf, 1, OUTSIZE-c_stream.avail_out, f); |
|
118 |
} while (!c_stream.avail_out); |
|
119 |
|
|
120 |
return n; |
|
121 |
} |
|
122 |
|
|
123 |
/* ship len bytes from s using zlib compression. */ |
|
124 |
int flate_xship(FILE *f, int filter, char *s, int len) { |
|
125 |
static int fstate = 0; |
|
126 |
static z_stream c_stream; |
|
127 |
char outbuf[OUTSIZE]; |
|
128 |
int err; |
|
129 |
int n=0; |
|
130 |
|
|
131 |
if (filter && !fstate) { |
|
132 |
/* switch on filtering */ |
|
133 |
if (filter == 1) { |
|
134 |
n += fprintf(f, "currentfile /ASCII85Decode filter /FlateDecode filter cvx exec\n"); |
|
135 |
} |
|
136 |
c_stream.zalloc = Z_NULL; |
|
137 |
c_stream.zfree = Z_NULL; |
|
138 |
c_stream.opaque = Z_NULL; |
|
139 |
err = deflateInit(&c_stream, 9); |
|
140 |
if (err != Z_OK) { |
|
141 |
fprintf(stderr, "deflateInit: %s (%d)\n", c_stream.msg, err); |
|
142 |
exit(1); |
|
143 |
} |
|
144 |
c_stream.avail_in = 0; |
|
145 |
n += a85init(f); |
|
146 |
fstate = 1; |
|
147 |
} else if (!filter && fstate) { |
|
148 |
/* switch off filtering */ |
|
149 |
/* flush stream */ |
|
150 |
do { |
|
151 |
c_stream.next_out = (Bytef*)outbuf; |
|
152 |
c_stream.avail_out = OUTSIZE; |
|
153 |
|
|
154 |
err = deflate(&c_stream, Z_FINISH); |
|
155 |
if (err != Z_OK && err != Z_STREAM_END) { |
|
156 |
fprintf(stderr, "deflate: %s (%d)\n", c_stream.msg, err); |
|
157 |
exit(1); |
|
158 |
} |
|
159 |
n += a85write(f, outbuf, OUTSIZE-c_stream.avail_out); |
|
160 |
} while (err != Z_STREAM_END); |
|
161 |
|
|
162 |
n += a85finish(f); |
|
163 |
|
|
164 |
fstate = 0; |
|
165 |
} |
|
166 |
if (!fstate) { |
|
167 |
fwrite(s, 1, len, f); |
|
168 |
return n+len; |
|
169 |
} |
|
170 |
|
|
171 |
/* do the actual compression */ |
|
172 |
c_stream.next_in = (Bytef*) s; |
|
173 |
c_stream.avail_in = len; |
|
174 |
|
|
175 |
do { |
|
176 |
c_stream.next_out = (Bytef*) outbuf; |
|
177 |
c_stream.avail_out = OUTSIZE; |
|
178 |
|
|
179 |
err = deflate(&c_stream, Z_NO_FLUSH); |
|
180 |
if (err != Z_OK) { |
|
181 |
fprintf(stderr, "deflate: %s (%d)\n", c_stream.msg, err); |
|
182 |
exit(1); |
|
183 |
} |
|
184 |
n += a85write(f, outbuf, OUTSIZE-c_stream.avail_out); |
|
185 |
} while (!c_stream.avail_out); |
|
186 |
|
|
187 |
return n; |
|
188 |
} |
|
189 |
|
|
190 |
#else /* HAVE_ZLIB */ |
|
191 |
|
|
192 |
int pdf_xship(FILE *f, int filter, char *s, int len) { |
|
193 |
return dummy_xship(f, filter, s, len); |
|
194 |
} |
|
195 |
|
|
196 |
int flate_xship(FILE *f, int filter, char *s, int len) { |
|
197 |
return dummy_xship(f, filter, s, len); |
|
198 |
} |
|
199 |
|
|
200 |
#endif /* HAVE_ZLIB */ |
|
201 |
|
|
202 |
/* ---------------------------------------------------------------------- */ |
|
203 |
/* lzw interface: LZW (=postscript level 2) compression with a85. |
|
204 |
This relies on lzw.c/h to do the actual compression. */ |
|
205 |
|
Also available in: Unified diff