Code

Have Paint Bucket generate the necessary GrayMap for potrace directly, skipping the...
authorjohncoswell <johncoswell@users.sourceforge.net>
Thu, 17 Apr 2008 22:43:15 +0000 (22:43 +0000)
committerjohncoswell <johncoswell@users.sourceforge.net>
Thu, 17 Apr 2008 22:43:15 +0000 (22:43 +0000)
src/flood-context.cpp
src/trace/potrace/inkscape-potrace.cpp
src/trace/potrace/inkscape-potrace.h

index c6335cb0f90a2912b95fb0a87b1dcdefbd987d01..f58ab0830dd4730fafdcc679d8a8d4cae4faca99 100644 (file)
@@ -67,6 +67,7 @@
 #include "color.h"
 
 #include "trace/trace.h"
+#include "trace/imagemap.h"
 #include "trace/potrace/inkscape-potrace.h"
 
 static void sp_flood_context_class_init(SPFloodContextClass *klass);
@@ -402,18 +403,24 @@ inline static bool check_if_pixel_is_paintable(guchar *px, unsigned char *trace_
  * \param transform The transform to apply to the final SVG path.
  * \param union_with_selection If true, merge the final SVG path with the current selection.
  */
-static void do_trace(GdkPixbuf *px, SPDesktop *desktop, NR::Matrix transform, bool union_with_selection) {
+static void do_trace(bitmap_coords_info bci, guchar *trace_px, SPDesktop *desktop, NR::Matrix transform, bool union_with_selection) {
     SPDocument *document = sp_desktop_document(desktop);
-    
+
+    unsigned char *trace_t;
+
+    GrayMap *gray_map = GrayMapCreate(bci.width, bci.height);
+    for (unsigned int y = 0; y < bci.height ; y++) {
+        trace_t = get_pixel(trace_px, 0, y, bci.width);
+        for (unsigned int x = 0; x < bci.width ; x++) {
+            gray_map->setPixel(gray_map, x, y, is_pixel_colored(trace_t) ? GRAYMAP_BLACK : GRAYMAP_WHITE);
+            trace_t += 4;
+        }
+    }
+
     Inkscape::Trace::Potrace::PotraceTracingEngine pte;
-        
-    pte.setTraceType(Inkscape::Trace::Potrace::TRACE_BRIGHTNESS);
-    pte.setInvert(false);
+    std::vector<Inkscape::Trace::TracingEngineResult> results = pte.traceGrayMap(gray_map);
+    gray_map->destroy(gray_map);
 
-    Glib::RefPtr<Gdk::Pixbuf> pixbuf = Glib::wrap(px, true);
-    
-    std::vector<Inkscape::Trace::TracingEngineResult> results = pte.trace(pixbuf);
-    
     Inkscape::XML::Node *layer_repr = SP_GROUP(desktop->currentLayer())->repr;
     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
 
@@ -1091,16 +1098,9 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even
         desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("<b>Only the visible part of the bounded area was filled.</b> If you want to fill all of the area, undo, zoom out, and fill again.")); 
     }
     
-    GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(trace_px,
-                                      GDK_COLORSPACE_RGB,
-                                      TRUE,
-                                      8, width, height, width * 4,
-                                      (GdkPixbufDestroyNotify)g_free,
-                                      NULL);
-
     NR::Matrix inverted_affine = NR::Matrix(affine).inverse();
     
-    do_trace(pixbuf, desktop, inverted_affine, union_with_selection);
+    do_trace(bci, trace_px, desktop, inverted_affine, union_with_selection);
 
     g_free(trace_px);
     
index bad4278e2875a14f0ec99942783de244ebe25198..9a305cc7c45f7cbd761c3cb8533b0ddf7279e61e 100644 (file)
@@ -444,6 +444,30 @@ PotraceTracingEngine::traceSingle(GdkPixbuf * thePixbuf)
 }
 
 
+/**
+ *  This allow routines that already generate GrayMaps to skip image filtering,
+ *  increasing performance.
+ */
+std::vector<TracingEngineResult>
+PotraceTracingEngine::traceGrayMap(GrayMap *grayMap)
+{
+
+    std::vector<TracingEngineResult> results;
+
+    brightnessFloor = 0.0; //important to set this
+
+    long nodeCount;
+    std::string d = grayMapToPath(grayMap, &nodeCount);
+
+    char *style = "fill:#000000";
+
+    //g_message("### GOT '%s' \n", d);
+    TracingEngineResult result(style, d, nodeCount);
+    results.push_back(result);
+
+    return results;
+}
+
 /**
  *  Called for multiple-scanning algorithms
  */
index 838a1363af86dd667314eb386e3c87e1b2504480..b32ab6461c2d838ebadc5f49c9ade2f8e2828cbf 100644 (file)
@@ -237,6 +237,7 @@ class PotraceTracingEngine : public TracingEngine
      */
     int keepGoing;
 
+    std::vector<TracingEngineResult>traceGrayMap(GrayMap *grayMap);
 
 
     private: