From 9daab2de569ccc52fc8e6876c8fdaf672e6316ee Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Wed, 10 Jul 2019 18:48:52 +0200 Subject: Fix centerline trace --- src/trace/autotrace/inkscape-autotrace.cpp | 38 ++++++++++++++++++++++++++---- src/trace/autotrace/inkscape-autotrace.h | 2 +- 2 files changed, 35 insertions(+), 5 deletions(-) (limited to 'src/trace') diff --git a/src/trace/autotrace/inkscape-autotrace.cpp b/src/trace/autotrace/inkscape-autotrace.cpp index 6a1758ccf..dcd9ce96f 100644 --- a/src/trace/autotrace/inkscape-autotrace.cpp +++ b/src/trace/autotrace/inkscape-autotrace.cpp @@ -52,6 +52,26 @@ namespace Trace { namespace Autotrace { +static guchar* to_3channels(GdkPixbuf* input) { + int imgsize = gdk_pixbuf_get_height(input) * gdk_pixbuf_get_width(input); + guchar *out = (guchar*)malloc(3 * imgsize); + int x=0; + guchar* pix = gdk_pixbuf_get_pixels (input); + int rs = gdk_pixbuf_get_rowstride (input); + for(int row=0;rowbackground_color = at_color_new(255,255,255); + autotrace_init(); } AutotraceTracingEngine::~AutotraceTracingEngine() { at_fitting_opts_free(opts); } @@ -70,7 +92,12 @@ AutotraceTracingEngine::~AutotraceTracingEngine() { at_fitting_opts_free(opts); // TODO -Glib::RefPtr AutotraceTracingEngine::preview(Glib::RefPtr thePixbuf) { return thePixbuf; } +Glib::RefPtr AutotraceTracingEngine::preview(Glib::RefPtr thePixbuf) { + //auto x = thePixbuf.copy(); + guchar *pb = to_3channels(thePixbuf->gobj()); + return Gdk::Pixbuf::create_from_data(pb, thePixbuf->get_colorspace(), false, 8, thePixbuf->get_width(), thePixbuf->get_height(), (thePixbuf->get_width()*3)); + +} /** * This is the working method of this interface, and all @@ -80,11 +107,14 @@ Glib::RefPtr AutotraceTracingEngine::preview(Glib::RefPtr AutotraceTracingEngine::trace(Glib::RefPtr pixbuf) { - GdkPixbuf *pb = pixbuf->gobj(); + GdkPixbuf *pb1 = pixbuf->gobj(); + guchar *pb = to_3channels(pb1); at_bitmap *bitmap = - at_bitmap_new(gdk_pixbuf_get_width(pb), gdk_pixbuf_get_height(pb), gdk_pixbuf_get_n_channels(pb)); - bitmap->bitmap = gdk_pixbuf_get_pixels(pb); +// at_bitmap_new(gdk_pixbuf_get_width(pb), gdk_pixbuf_get_height(pb), gdk_pixbuf_get_n_channels(pb)); +// bitmap->bitmap = gdk_pixbuf_get_pixels(pb); + at_bitmap_new(gdk_pixbuf_get_width(pb1), gdk_pixbuf_get_height(pb1), 3); + bitmap->bitmap = pb; at_splines_type *splines = at_splines_new_full(bitmap, opts, NULL, NULL, NULL, NULL, NULL, NULL); // at_output_write_func wfunc = at_output_get_handler_by_suffix("svg"); diff --git a/src/trace/autotrace/inkscape-autotrace.h b/src/trace/autotrace/inkscape-autotrace.h index eea5b3678..f12eb35d8 100644 --- a/src/trace/autotrace/inkscape-autotrace.h +++ b/src/trace/autotrace/inkscape-autotrace.h @@ -69,7 +69,7 @@ class AutotraceTracingEngine : public TracingEngine { */ int keepGoing; - private: + //private: // autotrace_param_t *autotraceParams; TraceType traceType; at_fitting_opts_type *opts; -- cgit v1.2.3