From 2649307b3d505e3b49b8e9199a5cea90f0205b81 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 17 Apr 2008 22:43:15 +0000 Subject: Have Paint Bucket generate the necessary GrayMap for potrace directly, skipping the standard, slower potrace filtering routines. (bzr r5466) --- src/flood-context.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/flood-context.cpp') 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); -- cgit v1.2.3