From 7303dd6c64e408e7bd85061b15277bb1925c9e3c Mon Sep 17 00:00:00 2001 From: johncoswell Date: Thu, 17 Apr 2008 22:43:15 +0000 Subject: [PATCH] Have Paint Bucket generate the necessary GrayMap for potrace directly, skipping the standard, slower potrace filtering routines. --- src/flood-context.cpp | 34 +++++++++++++------------- src/trace/potrace/inkscape-potrace.cpp | 24 ++++++++++++++++++ src/trace/potrace/inkscape-potrace.h | 1 + 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/flood-context.cpp b/src/flood-context.cpp index c6335cb0f..f58ab0830 100644 --- a/src/flood-context.cpp +++ b/src/flood-context.cpp @@ -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 results = pte.traceGrayMap(gray_map); + gray_map->destroy(gray_map); - Glib::RefPtr pixbuf = Glib::wrap(px, true); - - std::vector 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, _("Only the visible part of the bounded area was filled. 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); diff --git a/src/trace/potrace/inkscape-potrace.cpp b/src/trace/potrace/inkscape-potrace.cpp index bad4278e2..9a305cc7c 100644 --- a/src/trace/potrace/inkscape-potrace.cpp +++ b/src/trace/potrace/inkscape-potrace.cpp @@ -444,6 +444,30 @@ PotraceTracingEngine::traceSingle(GdkPixbuf * thePixbuf) } +/** + * This allow routines that already generate GrayMaps to skip image filtering, + * increasing performance. + */ +std::vector +PotraceTracingEngine::traceGrayMap(GrayMap *grayMap) +{ + + std::vector 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 */ diff --git a/src/trace/potrace/inkscape-potrace.h b/src/trace/potrace/inkscape-potrace.h index 838a1363a..b32ab6461 100644 --- a/src/trace/potrace/inkscape-potrace.h +++ b/src/trace/potrace/inkscape-potrace.h @@ -237,6 +237,7 @@ class PotraceTracingEngine : public TracingEngine */ int keepGoing; + std::vectortraceGrayMap(GrayMap *grayMap); private: -- 2.30.2