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 <glib.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 }
162 /**
163 * This is the working method of this implementing class, and all
164 * implementing classes. Take a GdkPixbuf, trace it, and
165 * return the path data that is compatible with the d="" attribute
166 * of an SVG <path> element.
167 */
168 virtual TracingEngineResult *trace(GdkPixbuf *pixbuf, int *nrPaths);
170 /**
171 * Abort the thread that is executing getPathDataFromPixbuf()
172 */
173 virtual void abort();
175 /**
176 *
177 */
178 GdkPixbuf *preview(GdkPixbuf * pixbuf);
180 /**
181 *
182 */
183 int keepGoing;
187 private:
189 TraceType traceType;
191 //## do i invert at the end?
192 bool invert;
194 //## Color-->b&w quantization
195 int quantizationNrColors;
197 //## brightness items
198 double brightnessThreshold;
199 double brightnessFloor; //usually 0.0
201 //## canny items
202 double cannyHighThreshold;
204 //## Color-->multiscan quantization
205 int multiScanNrColors;
206 bool multiScanStack; //do we tile or stack?
207 bool multiScanSmooth;//do we use gaussian filter?
209 /**
210 * This is the actual wrapper of the call to Potrace. nodeCount
211 * returns the count of nodes created. May be NULL if ignored.
212 */
213 char *grayMapToPath(GrayMap *gm, long *nodeCount);
215 TracingEngineResult *traceBrightnessMulti(GdkPixbuf *pixbuf, int *nrPaths);
216 TracingEngineResult *traceQuant(GdkPixbuf *pixbuf, int *nrPaths);
217 TracingEngineResult *traceSingle(GdkPixbuf *pixbuf, int *nrPaths);
220 };//class PotraceTracingEngine
224 } // namespace Potrace
225 } // namespace Trace
226 } // namespace Inkscape
229 #endif //__INKSCAPE_POTRACE_H__