1 /*
2 * This is the C++ glue between Inkscape and Potrace
3 *
4 * Authors:
5 * Bob Jamison <rjamison@titan.com>
6 *
7 * Copyright (C) 2004 Bob Jamison
8 *
9 * Released under GNU GPL, read the file 'COPYING' for more information
10 *
11 * Potrace, the wonderful tracer located at http://potrace.sourceforge.net,
12 * is provided by the generosity of Peter Selinger, to whom we are grateful.
13 *
14 */
16 #ifndef __INKSCAPE_POTRACE_H__
17 #define __INKSCAPE_POTRACE_H__
19 #include <gtkmm.h>
20 #include <trace/trace.h>
21 #include <trace/imagemap.h>
23 namespace Inkscape {
25 namespace Trace {
27 namespace Potrace {
29 typedef enum
30 {
31 TRACE_BRIGHTNESS,
32 TRACE_BRIGHTNESS_MULTI,
33 TRACE_CANNY,
34 TRACE_QUANT,
35 TRACE_QUANT_COLOR,
36 TRACE_QUANT_MONO
37 } TraceType;
40 class PotraceTracingEngine : public TracingEngine
41 {
43 public:
45 /**
46 *
47 */
48 PotraceTracingEngine();
50 /**
51 *
52 */
53 virtual ~PotraceTracingEngine()
54 {}
56 void setTraceType(TraceType val)
57 {
58 traceType = val;
59 }
60 TraceType getTraceType()
61 {
62 return traceType;
63 }
65 /**
66 * Sets/gets whether I invert the product of the other filter(s)
67 */
68 void setInvert(bool val)
69 {
70 invert = val;
71 }
72 bool getInvert()
73 {
74 return invert;
75 }
77 /**
78 * Sets the halfway point for black/white
79 */
80 void setQuantizationNrColors(int val)
81 {
82 quantizationNrColors = val;
83 }
84 int getQuantizationNrColors()
85 {
86 return quantizationNrColors;
87 }
89 /**
90 * Sets the halfway point for black/white
91 */
92 void setBrightnessThreshold(double val)
93 {
94 brightnessThreshold = val;
95 }
96 double getBrightnessThreshold()
97 {
98 return brightnessThreshold;
99 }
101 /**
102 * Sets the lower consideration point for black/white
103 */
104 void setBrightnessFloor(double val)
105 {
106 brightnessFloor = val;
107 }
108 double getBrightnessFloor()
109 {
110 return brightnessFloor;
111 }
113 /**
114 * Sets upper cutoff for canny non-maximalizing
115 */
116 void setCannyHighThreshold(double val)
117 {
118 cannyHighThreshold = val;
119 }
120 double getCannyHighThreshold()
121 {
122 return cannyHighThreshold;
123 }
125 /**
126 * Sets the number of colors for quant multiscan
127 */
128 void setMultiScanNrColors(int val)
129 {
130 multiScanNrColors = val;
131 }
132 int getMultiScanNrColors()
133 {
134 return multiScanNrColors;
135 }
137 /**
138 * Sets whether we tile regions side-by-side or stack them
139 */
140 void setMultiScanStack(bool val)
141 {
142 multiScanStack = val;
143 }
144 bool setMultiScanStack()
145 {
146 return multiScanStack;
147 }
149 /**
150 * Sets whether we want gaussian smoothing of bitmaps before quantizing
151 */
152 void setMultiScanSmooth(bool val)
153 {
154 multiScanSmooth = val;
155 }
156 bool getMultiScanSmooth()
157 {
158 return multiScanSmooth;
159 }
161 /**
162 * Sets whether we want to remove the background (bottom) trace
163 */
164 void setMultiScanRemoveBackground(bool val)
165 {
166 multiScanRemoveBackground= val;
167 }
168 bool getMultiScanRemoveBackground()
169 {
170 return multiScanRemoveBackground;
171 }
174 /**
175 * This is the working method of this implementing class, and all
176 * implementing classes. Take a GdkPixbuf, trace it, and
177 * return the path data that is compatible with the d="" attribute
178 * of an SVG <path> element.
179 */
180 virtual std::vector<TracingEngineResult> trace(
181 Glib::RefPtr<Gdk::Pixbuf> pixbuf);
183 /**
184 * Abort the thread that is executing getPathDataFromPixbuf()
185 */
186 virtual void abort();
188 /**
189 *
190 */
191 Glib::RefPtr<Gdk::Pixbuf> preview(Glib::RefPtr<Gdk::Pixbuf> pixbuf);
193 /**
194 *
195 */
196 int keepGoing;
200 private:
202 TraceType traceType;
204 //## do i invert at the end?
205 bool invert;
207 //## Color-->b&w quantization
208 int quantizationNrColors;
210 //## brightness items
211 double brightnessThreshold;
212 double brightnessFloor; //usually 0.0
214 //## canny items
215 double cannyHighThreshold;
217 //## Color-->multiscan quantization
218 int multiScanNrColors;
219 bool multiScanStack; //do we tile or stack?
220 bool multiScanSmooth;//do we use gaussian filter?
221 bool multiScanRemoveBackground; //do we remove the bottom trace?
222 /**
223 * This is the actual wrapper of the call to Potrace. nodeCount
224 * returns the count of nodes created. May be NULL if ignored.
225 */
226 std::string grayMapToPath(GrayMap *gm, long *nodeCount);
228 std::vector<TracingEngineResult>traceBrightnessMulti(GdkPixbuf *pixbuf);
229 std::vector<TracingEngineResult>traceQuant(GdkPixbuf *pixbuf);
230 std::vector<TracingEngineResult>traceSingle(GdkPixbuf *pixbuf);
233 };//class PotraceTracingEngine
237 } // namespace Potrace
238 } // namespace Trace
239 } // namespace Inkscape
242 #endif //__INKSCAPE_POTRACE_H__