potracelib.h /size: 4686 b    last modification: 2025-02-21 11:03
1/* Copyright (C) 2001-2019 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# if defined(LUAMETATEX_USE_MIMALLOC)
9
10    # include "libraries/mimalloc/include/mimalloc-override.h"
11
12# endif 
13
14/* this file defines the API for the core Potrace library. For a more
15   detailed description of the API, see potracelib.pdf */
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21/* ---------------------------------------------------------------------- */
22/* tracing parameters */
23
24/* turn policies */
25#define POTRACE_TURNPOLICY_BLACK 0
26#define POTRACE_TURNPOLICY_WHITE 1
27#define POTRACE_TURNPOLICY_LEFT 2
28#define POTRACE_TURNPOLICY_RIGHT 3
29#define POTRACE_TURNPOLICY_MINORITY 4
30#define POTRACE_TURNPOLICY_MAJORITY 5
31#define POTRACE_TURNPOLICY_RANDOM 6
32
33/* structure to hold progress bar callback data */
34struct potrace_progress_s {
35  void (*callback)(double progress, void *privdata); /* callback fn */
36  void *data;          /* callback function's private data */
37  double min, max;     /* desired range of progress, e.g. 0.0 to 1.0 */
38  double epsilon;      /* granularity: can skip smaller increments */
39};
40typedef struct potrace_progress_s potrace_progress_t;
41
42/* structure to hold tracing parameters */
43struct potrace_param_s {
44  int turdsize;        /* area of largest path to be ignored */
45  int turnpolicy;      /* resolves ambiguous turns in path decomposition */
46  double alphamax;     /* corner threshold */
47  int opticurve;       /* use curve optimization? */
48  double opttolerance; /* curve optimization tolerance */
49  potrace_progress_t progress; /* progress callback function */
50};
51typedef struct potrace_param_s potrace_param_t;
52
53/* ---------------------------------------------------------------------- */
54/* bitmaps */
55
56/* native word size */
57typedef unsigned long potrace_word;
58
59/* Internal bitmap format. The n-th scanline starts at scanline(n) =
60   (map + n*dy). Raster data is stored as a sequence of potrace_words
61   (NOT bytes). The leftmost bit of scanline n is the most significant
62   bit of scanline(n)[0]. */
63struct potrace_bitmap_s {
64  int w, h;              /* width and height, in pixels */
65  int dy;                /* words per scanline (not bytes) */
66  potrace_word *map;     /* raw data, dy*h words */
67};
68typedef struct potrace_bitmap_s potrace_bitmap_t;
69
70/* ---------------------------------------------------------------------- */
71/* curves */
72
73/* point */
74struct potrace_dpoint_s {
75  double x, y;
76};
77typedef struct potrace_dpoint_s potrace_dpoint_t;
78
79/* segment tags */
80#define POTRACE_CURVETO 1
81#define POTRACE_CORNER 2
82
83/* closed curve segment */
84struct potrace_curve_s {
85  int n;                    /* number of segments */
86  int *tag;                 /* tag[n]: POTRACE_CURVETO or POTRACE_CORNER */
87  potrace_dpoint_t (*c)[3]; /* c[n][3]: control points. 
88			       c[n][0] is unused for tag[n]=POTRACE_CORNER */
89};
90typedef struct potrace_curve_s potrace_curve_t;
91
92/* Linked list of signed curve segments. Also carries a tree structure. */
93struct potrace_path_s {
94  int area;                         /* area of the bitmap path */
95  int sign;                         /* '+' or '-', depending on orientation */
96  potrace_curve_t curve;            /* this path's vector data */
97
98  struct potrace_path_s *next;      /* linked list structure */
99
100  struct potrace_path_s *childlist; /* tree structure */
101  struct potrace_path_s *sibling;   /* tree structure */
102
103  struct potrace_privpath_s *priv;  /* private state */
104};
105typedef struct potrace_path_s potrace_path_t;  
106
107/* ---------------------------------------------------------------------- */
108/* Potrace state */
109
110#define POTRACE_STATUS_OK         0
111#define POTRACE_STATUS_INCOMPLETE 1
112
113struct potrace_state_s {
114  int status;                       
115  potrace_path_t *plist;            /* vector data */
116
117  struct potrace_privstate_s *priv; /* private state */
118};
119typedef struct potrace_state_s potrace_state_t;
120
121/* ---------------------------------------------------------------------- */
122/* API functions */
123
124/* get default parameters */
125potrace_param_t *potrace_param_default(void);
126
127/* free parameter set */
128void potrace_param_free(potrace_param_t *p);
129
130/* trace a bitmap */
131potrace_state_t *potrace_trace(const potrace_param_t *param, 
132			       const potrace_bitmap_t *bm);
133
134/* free a Potrace state */
135void potrace_state_free(potrace_state_t *st);
136
137/* return a static plain text version string identifying this version
138   of potracelib */
139const char *potrace_version(void);
140
141#ifdef  __cplusplus
142} /* end of extern "C" */
143#endif
144
145#endif /* POTRACELIB_H */
146