summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/trace/autotrace/inkscape-autotrace.cpp38
-rw-r--r--src/trace/autotrace/inkscape-autotrace.h2
-rw-r--r--src/ui/dialog/tracedialog2.cpp22
3 files changed, 51 insertions, 11 deletions
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;row<gdk_pixbuf_get_height(input);row++) {
+ for (int col=0;col<gdk_pixbuf_get_width(input);col++) {
+ char alpha = *(pix + row * rs + col * 4 + 3);
+ char white = 255 - alpha;
+ for(int chan=0;chan<3;chan++) {
+ guchar *pnew = (pix + row * rs + col * 3 + chan);
+ guchar *pold = (pix + row * rs + col * 4 + chan);
+ out[x++] = ((*pold) * alpha / 256 + white);
+ }
+ }
+ }
+ return out;
+}
+
/**
*
@@ -63,6 +83,8 @@ AutotraceTracingEngine::AutotraceTracingEngine()
{
/* get default parameters */
opts = at_fitting_opts_new();
+ opts->background_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<Gdk::Pixbuf> AutotraceTracingEngine::preview(Glib::RefPtr<Gdk::Pixbuf> thePixbuf) { return thePixbuf; }
+Glib::RefPtr<Gdk::Pixbuf> AutotraceTracingEngine::preview(Glib::RefPtr<Gdk::Pixbuf> 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<Gdk::Pixbuf> AutotraceTracingEngine::preview(Glib::RefPtr<Gdk::Pixb
*/
std::vector<TracingEngineResult> AutotraceTracingEngine::trace(Glib::RefPtr<Gdk::Pixbuf> 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;
diff --git a/src/ui/dialog/tracedialog2.cpp b/src/ui/dialog/tracedialog2.cpp
index 6f4110985..14ec1cebc 100644
--- a/src/ui/dialog/tracedialog2.cpp
+++ b/src/ui/dialog/tracedialog2.cpp
@@ -118,6 +118,7 @@ void TraceDialogImpl2::traceProcess(bool do_i_trace)
// Inkscape::Trace::Autotrace::TraceType autotraceType;
bool use_autotrace = false;
+ Inkscape::Trace::Autotrace::AutotraceTracingEngine ate; // TODO
if (type == _("Brightness cutoff"))
potraceType = Inkscape::Trace::Potrace::TRACE_BRIGHTNESS;
@@ -129,11 +130,15 @@ void TraceDialogImpl2::traceProcess(bool do_i_trace)
{
// autotraceType = Inkscape::Trace::Autotrace::TRACE_CENTERLINE
use_autotrace = true;
+ ate.opts->color_count = 2;
}
else if (type == _("Centerline tracing (autotrace)"))
{
// autotraceType = Inkscape::Trace::Autotrace::TRACE_CENTERLINE
use_autotrace = true;
+ ate.opts->color_count = 2;
+ ate.opts->centerline = true;
+ ate.opts->preserve_width = true;
}
else if (type == _("Brightness steps"))
potraceType = Inkscape::Trace::Potrace::TRACE_BRIGHTNESS_MULTI;
@@ -145,6 +150,7 @@ void TraceDialogImpl2::traceProcess(bool do_i_trace)
{
// autotraceType = Inkscape::Trace::Autotrace::TRACE_CENTERLINE
use_autotrace = true;
+ ate.opts->color_count = (int)MS_scans->get_value() + 1;
}
else
{
@@ -163,13 +169,13 @@ void TraceDialogImpl2::traceProcess(bool do_i_trace)
- Inkscape::Trace::Autotrace::AutotraceTracingEngine ate; // TODO
+ //Inkscape::Trace::Autotrace::AutotraceTracingEngine ate; // TODO
Inkscape::Trace::Depixelize::DepixelizeTracingEngine dte(RB_PA_voronoi->get_active() ? Inkscape::Trace::Depixelize::TraceType::TRACE_VORONOI : Inkscape::Trace::Depixelize::TraceType::TRACE_BSPLINES, PA_curves->get_value(), (int) PA_islands->get_value(), (int) PA_sparse1->get_value(), PA_sparse2->get_value() );
Glib::RefPtr<Gdk::Pixbuf> pixbuf = tracer.getSelectedImage();
if (pixbuf) {
- Glib::RefPtr<Gdk::Pixbuf> preview = pte.preview(pixbuf);
+ Glib::RefPtr<Gdk::Pixbuf> preview = use_autotrace ? ate.preview(pixbuf) : pte.preview(pixbuf);
if (preview) {
int width = preview->get_width();
int height = preview->get_height();
@@ -185,12 +191,16 @@ void TraceDialogImpl2::traceProcess(bool do_i_trace)
}
}
if (do_i_trace){
- if (use_autotrace)
- tracer.trace(&ate);
- else if (choice_tab->get_current_page() == 0)
+ if (use_autotrace){
+ tracer.trace(&ate);
+ printf("at\n");
+ } else if (choice_tab->get_current_page() == 0){
tracer.trace(&pte);
- else if (choice_tab->get_current_page() == 1)
+ printf("pt\n");
+ } else if (choice_tab->get_current_page() == 1){
tracer.trace(&dte);
+ printf("dt\n");
+ }
}
if (desktop)