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