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>
30 #include <sp-shape.h>
32 struct SPImage;
33 struct SPItem;
35 namespace Inkscape {
37 namespace Trace {
41 /**
42 *
43 */
44 class TracingEngineResult
45 {
47 public:
49 /**
50 *
51 */
52 TracingEngineResult(char *theStyle, char *thePathData, long theNodeCount)
53 {
54 next = NULL;
55 style = strdup(theStyle);
56 pathData = strdup(thePathData);
57 nodeCount = theNodeCount;
58 }
60 /**
61 *
62 */
63 virtual ~TracingEngineResult()
64 {
65 if (next)
66 delete next;
67 if (style)
68 free(style);
69 if (pathData)
70 free(pathData);
71 }
74 /**
75 *
76 */
77 char *getStyle()
78 { return style; }
80 /**
81 *
82 */
83 char *getPathData()
84 { return pathData; }
86 /**
87 *
88 */
89 long getNodeCount()
90 { return nodeCount; }
92 /**
93 *
94 */
95 TracingEngineResult *next;
97 private:
99 char *style;
101 char *pathData;
103 long nodeCount;
105 };
109 /**
110 *
111 */
112 class TracingEngine
113 {
115 public:
117 /**
118 *
119 */
120 TracingEngine()
121 {}
123 /**
124 *
125 */
126 virtual ~TracingEngine()
127 {}
129 /**
130 * This is the working method of this interface, and all
131 * implementing classes. Take a GdkPixbuf, trace it, and
132 * return a style attribute and the path data that is
133 * compatible with the d="" attribute
134 * of an SVG <path> element.
135 */
136 virtual TracingEngineResult *trace(GdkPixbuf *pixbuf, int *nrPaths)
137 { return NULL; }
140 /**
141 * Abort the thread that is executing getPathDataFromPixbuf()
142 */
143 virtual void abort()
144 {}
148 };//class TracingEngine
158 /**
159 * This simple class allows a generic wrapper around a given
160 * TracingEngine object. Its purpose is to provide a gateway
161 * to a variety of tracing engines, while maintaining a
162 * consistent interface.
163 */
164 class Tracer
165 {
167 public:
170 /**
171 *
172 */
173 Tracer()
174 {
175 engine = NULL;
176 sioxEnabled = false;
177 }
181 /**
182 *
183 */
184 ~Tracer()
185 {}
188 /**
189 * A convenience method to allow other software to 'see' the
190 * same image that this class sees.
191 */
192 GdkPixbuf *getSelectedImage();
194 /**
195 * This is the main working method. Trace the selected image, if
196 * any, and create a <path> element from it, inserting it into
197 * the current document.
198 */
199 void trace(TracingEngine *engine);
202 /**
203 * Abort the thread that is executing convertImageToPath()
204 */
205 void abort();
207 /**
208 * Whether we want to enable SIOX subimage selection
209 */
210 void enableSiox(bool enable);
213 private:
215 /**
216 * This is the single path code that is called by its counterpart above.
217 */
218 void traceThread();
220 /**
221 * This is true during execution. Setting it to false (like abort()
222 * does) should inform the threaded code that it needs to stop
223 */
224 bool keepGoing;
226 /**
227 * During tracing, this is Non-null, and refers to the
228 * engine that is currently doing the tracing.
229 */
230 TracingEngine *engine;
232 SPImage *getSelectedSPImage();
234 std::vector<SPShape *> sioxShapes;
236 bool sioxEnabled;
238 GdkPixbuf *sioxProcessImage(SPImage *img, GdkPixbuf *origPixbuf);
240 };//class Tracer
245 } // namespace Trace
247 } // namespace Inkscape
251 #endif //__TRACE_H__
253 //#########################################################################
254 //# E N D O F F I L E
255 //#########################################################################