Code

fix by Preben S for LP bug 389780, flatness
[inkscape.git] / src / trace / potrace / inkscape-potrace.h
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;
240     std::vector<TracingEngineResult>traceGrayMap(GrayMap *grayMap);
243     private:
245     potrace_param_t *potraceParams;
246     TraceType traceType;
248     //## do i invert at the end?
249     bool invert;
251     //## Color-->b&w quantization
252     int quantizationNrColors;
254     //## brightness items
255     double brightnessThreshold;
256     double brightnessFloor; //usually 0.0
258     //## canny items
259     double cannyHighThreshold;
261     //## Color-->multiscan quantization
262     int multiScanNrColors;
263     bool multiScanStack; //do we tile or stack?
264     bool multiScanSmooth;//do we use gaussian filter?
265     bool multiScanRemoveBackground; //do we remove the bottom trace?
266     /**
267      * This is the actual wrapper of the call to Potrace.  nodeCount
268      * returns the count of nodes created.  May be NULL if ignored.
269      */
270     std::string grayMapToPath(GrayMap *gm, long *nodeCount);
272     std::vector<TracingEngineResult>traceBrightnessMulti(GdkPixbuf *pixbuf);
273     std::vector<TracingEngineResult>traceQuant(GdkPixbuf *pixbuf);
274     std::vector<TracingEngineResult>traceSingle(GdkPixbuf *pixbuf);
277 };//class PotraceTracingEngine
281 }  // namespace Potrace
282 }  // namespace Trace
283 }  // namespace Inkscape
286 #endif  //__INKSCAPE_POTRACE_H__