1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
/*
* This is the C++ glue between Inkscape and Potrace
*
* Authors:
* Bob Jamison <rjamison@titan.com>
* Stéphane Gimenez <dev@gim.name>
*
* Copyright (C) 2004-2006 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*
* Potrace, the wonderful tracer located at http://potrace.sourceforge.net,
* is provided by the generosity of Peter Selinger, to whom we are grateful.
*
*/
#ifndef __INKSCAPE_POTRACE_H__
#define __INKSCAPE_POTRACE_H__
#include <gtkmm.h>
#include <trace/trace.h>
#include <trace/imagemap.h>
#include "potracelib.h"
namespace Inkscape {
namespace Trace {
namespace Potrace {
typedef enum
{
TRACE_BRIGHTNESS,
TRACE_BRIGHTNESS_MULTI,
TRACE_CANNY,
TRACE_QUANT,
TRACE_QUANT_COLOR,
TRACE_QUANT_MONO
} TraceType;
class PotraceTracingEngine : public TracingEngine
{
public:
/**
*
*/
PotraceTracingEngine();
/**
*
*/
~PotraceTracingEngine();
/**
* Sets/gets potrace parameters
*/
void setParamsTurdSize(int val)
{
potraceParams->turdsize = val;
}
int getParamsTurdSize()
{
return potraceParams->turdsize;
}
void setParamsAlphaMax(double val)
{
potraceParams->alphamax = val;
}
double getParamsAlphaMax()
{
return potraceParams->alphamax;
}
void setParamsOptiCurve(bool val)
{
potraceParams->opticurve = val;
}
bool getParamsOptiCurve()
{
return potraceParams->opticurve;
}
void setParamsOptTolerance(double val)
{
potraceParams->opttolerance = val;
}
double getParamsOptTolerance()
{
return potraceParams->opttolerance;
}
void setTraceType(TraceType val)
{
traceType = val;
}
TraceType getTraceType()
{
return traceType;
}
/**
* Sets/gets whether I invert the product of the other filter(s)
*/
void setInvert(bool val)
{
invert = val;
}
bool getInvert()
{
return invert;
}
/**
* Sets the halfway point for black/white
*/
void setQuantizationNrColors(int val)
{
quantizationNrColors = val;
}
int getQuantizationNrColors()
{
return quantizationNrColors;
}
/**
* Sets the halfway point for black/white
*/
void setBrightnessThreshold(double val)
{
brightnessThreshold = val;
}
double getBrightnessThreshold()
{
return brightnessThreshold;
}
/**
* Sets the lower consideration point for black/white
*/
void setBrightnessFloor(double val)
{
brightnessFloor = val;
}
double getBrightnessFloor()
{
return brightnessFloor;
}
/**
* Sets upper cutoff for canny non-maximalizing
*/
void setCannyHighThreshold(double val)
{
cannyHighThreshold = val;
}
double getCannyHighThreshold()
{
return cannyHighThreshold;
}
/**
* Sets the number of colors for quant multiscan
*/
void setMultiScanNrColors(int val)
{
multiScanNrColors = val;
}
int getMultiScanNrColors()
{
return multiScanNrColors;
}
/**
* Sets whether we tile regions side-by-side or stack them
*/
void setMultiScanStack(bool val)
{
multiScanStack = val;
}
bool setMultiScanStack()
{
return multiScanStack;
}
/**
* Sets whether we want gaussian smoothing of bitmaps before quantizing
*/
void setMultiScanSmooth(bool val)
{
multiScanSmooth = val;
}
bool getMultiScanSmooth()
{
return multiScanSmooth;
}
/**
* Sets whether we want to remove the background (bottom) trace
*/
void setMultiScanRemoveBackground(bool val)
{
multiScanRemoveBackground= val;
}
bool getMultiScanRemoveBackground()
{
return multiScanRemoveBackground;
}
/**
* This is the working method of this implementing class, and all
* implementing classes. Take a GdkPixbuf, trace it, and
* return the path data that is compatible with the d="" attribute
* of an SVG <path> element.
*/
virtual std::vector<TracingEngineResult> trace(
Glib::RefPtr<Gdk::Pixbuf> pixbuf);
/**
* Abort the thread that is executing getPathDataFromPixbuf()
*/
virtual void abort();
/**
*
*/
Glib::RefPtr<Gdk::Pixbuf> preview(Glib::RefPtr<Gdk::Pixbuf> pixbuf);
/**
*
*/
int keepGoing;
std::vector<TracingEngineResult>traceGrayMap(GrayMap *grayMap);
private:
potrace_param_t *potraceParams;
TraceType traceType;
//## do i invert at the end?
bool invert;
//## Color-->b&w quantization
int quantizationNrColors;
//## brightness items
double brightnessThreshold;
double brightnessFloor; //usually 0.0
//## canny items
double cannyHighThreshold;
//## Color-->multiscan quantization
int multiScanNrColors;
bool multiScanStack; //do we tile or stack?
bool multiScanSmooth;//do we use gaussian filter?
bool multiScanRemoveBackground; //do we remove the bottom trace?
/**
* This is the actual wrapper of the call to Potrace. nodeCount
* returns the count of nodes created. May be NULL if ignored.
*/
std::string grayMapToPath(GrayMap *gm, long *nodeCount);
std::vector<TracingEngineResult>traceBrightnessMulti(GdkPixbuf *pixbuf);
std::vector<TracingEngineResult>traceQuant(GdkPixbuf *pixbuf);
std::vector<TracingEngineResult>traceSingle(GdkPixbuf *pixbuf);
};//class PotraceTracingEngine
} // namespace Potrace
} // namespace Trace
} // namespace Inkscape
#endif //__INKSCAPE_POTRACE_H__
|