1 /*
2 * A generic interface for plugging different
3 * autotracers into Inkscape.
4 *
5 * Authors:
6 * Bob Jamison <rjamison@titan.com>
7 *
8 * Copyright (C) 2004 Bob Jamison
9 *
10 * Released under GNU GPL, read the file 'COPYING' for more information
11 */
12 #ifndef __TRACE_H__
13 #define __TRACE_H__
15 #ifdef HAVE_CONFIG_H
16 # include "config.h"
17 #endif
19 #ifdef HAVE_STDLIB_H
20 # include <stdlib.h>
21 #endif
23 #ifdef HAVE_STRING_H
24 # include <string.h>
25 #endif
27 #include <gdk/gdkpixbuf.h>
29 #include <vector>
31 struct SPImage;
32 struct SPItem;
34 namespace Inkscape {
36 namespace Trace {
40 /**
41 *
42 */
43 class TracingEngineResult
44 {
46 public:
48 /**
49 *
50 */
51 TracingEngineResult(char *theStyle, char *thePathData, long theNodeCount)
52 {
53 next = NULL;
54 style = strdup(theStyle);
55 pathData = strdup(thePathData);
56 nodeCount = theNodeCount;
57 }
59 /**
60 *
61 */
62 virtual ~TracingEngineResult()
63 {
64 if (next)
65 delete next;
66 if (style)
67 free(style);
68 if (pathData)
69 free(pathData);
70 }
73 /**
74 *
75 */
76 char *getStyle()
77 { return style; }
79 /**
80 *
81 */
82 char *getPathData()
83 { return pathData; }
85 /**
86 *
87 */
88 long getNodeCount()
89 { return nodeCount; }
91 /**
92 *
93 */
94 TracingEngineResult *next;
96 private:
98 char *style;
100 char *pathData;
102 long nodeCount;
104 };
108 /**
109 *
110 */
111 class TracingEngine
112 {
114 public:
116 /**
117 *
118 */
119 TracingEngine()
120 {}
122 /**
123 *
124 */
125 virtual ~TracingEngine()
126 {}
128 /**
129 * This is the working method of this interface, and all
130 * implementing classes. Take a GdkPixbuf, trace it, and
131 * return a style attribute and the path data that is
132 * compatible with the d="" attribute
133 * of an SVG <path> element.
134 */
135 virtual TracingEngineResult *trace(GdkPixbuf *pixbuf, int *nrPaths)
136 { return NULL; }
139 /**
140 * Abort the thread that is executing getPathDataFromPixbuf()
141 */
142 virtual void abort()
143 {}
147 };//class TracingEngine
157 /**
158 * This simple class allows a generic wrapper around a given
159 * TracingEngine object. Its purpose is to provide a gateway
160 * to a variety of tracing engines, while maintaining a
161 * consistent interface.
162 */
163 class Tracer
164 {
166 public:
169 /**
170 *
171 */
172 Tracer()
173 {
174 engine = NULL;
175 sioxEnabled = false;
176 }
180 /**
181 *
182 */
183 ~Tracer()
184 {}
187 /**
188 * A convenience method to allow other software to 'see' the
189 * same image that this class sees.
190 */
191 GdkPixbuf *getSelectedImage();
193 /**
194 * This is the main working method. Trace the selected image, if
195 * any, and create a <path> element from it, inserting it into
196 * the current document.
197 */
198 void trace(TracingEngine *engine);
201 /**
202 * Abort the thread that is executing convertImageToPath()
203 */
204 void abort();
206 /**
207 * Whether we want to enable SIOX subimage selection
208 */
209 void enableSiox(bool enable);
212 private:
214 /**
215 * This is the single path code that is called by its counterpart above.
216 */
217 void traceThread();
219 /**
220 * This is true during execution. Setting it to false (like abort()
221 * does) should inform the threaded code that it needs to stop
222 */
223 bool keepGoing;
225 /**
226 * During tracing, this is Non-null, and refers to the
227 * engine that is currently doing the tracing.
228 */
229 TracingEngine *engine;
231 SPImage *getSelectedSPImage();
233 std::vector<SPItem *> sioxItems;
235 bool sioxEnabled;
237 GdkPixbuf *sioxProcessImage(SPImage *img, GdkPixbuf *origPixbuf);
239 };//class Tracer
244 } // namespace Trace
246 } // namespace Inkscape
250 #endif //__TRACE_H__
252 //#########################################################################
253 //# E N D O F F I L E
254 //#########################################################################