Code

patch [ 1503865 ] Siox performance patch
[inkscape.git] / src / trace / trace.h
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 <gtkmm.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
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(Glib::RefPtr<Gdk::Pixbuf> pixbuf,
137                                         int *nrPaths)
138         { return NULL; }
141     /**
142      *  Abort the thread that is executing getPathDataFromPixbuf()
143      */
144     virtual void abort()
145         {}
149 };//class TracingEngine
159 /**
160  *  This simple class allows a generic wrapper around a given
161  *  TracingEngine object.  Its purpose is to provide a gateway
162  *  to a variety of tracing engines, while maintaining a
163  *  consistent interface.
164  */
165 class Tracer
168 public:
171     /**
172      *
173      */
174     Tracer()
175         {
176         engine       = NULL;
177         sioxEnabled  = false;
178         }
182     /**
183      *
184      */
185     ~Tracer()
186         {}
189     /**
190      *  A convenience method to allow other software to 'see' the
191      *  same image that this class sees.
192      */
193     Glib::RefPtr<Gdk::Pixbuf> getSelectedImage();
195     /**
196      * This is the main working method.  Trace the selected image, if
197      * any, and create a <path> element from it, inserting it into
198      * the current document.
199      */
200     void trace(TracingEngine *engine);
203     /**
204      *  Abort the thread that is executing convertImageToPath()
205      */
206     void abort();
208     /**
209      *  Whether we want to enable SIOX subimage selection
210      */
211     void enableSiox(bool enable);
214 private:
216     /**
217      * This is the single path code that is called by its counterpart above.
218      */
219     void traceThread();
221     /**
222      * This is true during execution. Setting it to false (like abort()
223      * does) should inform the threaded code that it needs to stop
224      */
225     bool keepGoing;
227     /**
228      *  During tracing, this is Non-null, and refers to the
229      *  engine that is currently doing the tracing.
230      */
231     TracingEngine *engine;
233     SPImage *getSelectedSPImage();
235     std::vector<SPShape *> sioxShapes;
237     bool sioxEnabled;
239     Glib::RefPtr<Gdk::Pixbuf> sioxProcessImage(
240            SPImage *img, Glib::RefPtr<Gdk::Pixbuf> origPixbuf);
242     Glib::RefPtr<Gdk::Pixbuf> lastSioxPixbuf;
243     Glib::RefPtr<Gdk::Pixbuf> lastOrigPixbuf;
245 };//class Tracer
250 } // namespace Trace
252 } // namespace Inkscape
256 #endif //__TRACE_H__
258 //#########################################################################
259 //# E N D   O F   F I L E
260 //#########################################################################