summaryrefslogtreecommitdiffstats
path: root/src/trace/depixelize/inkscape-depixelize.cpp
diff options
context:
space:
mode:
authorMarc Jeanmougin <marc@jeanmougin.fr>2019-05-27 17:32:53 +0000
committerMarc Jeanmougin <marc@jeanmougin.fr>2019-08-21 15:16:54 +0000
commitba838aef213e2b99bdedc687429c12657c669df5 (patch)
treedff70699a3916f998c60f597329ca2bec755f45d /src/trace/depixelize/inkscape-depixelize.cpp
parentImprove spellcheck dialog (diff)
downloadinkscape-ba838aef213e2b99bdedc687429c12657c669df5.tar.gz
inkscape-ba838aef213e2b99bdedc687429c12657c669df5.zip
new trace Dialog - initial implementation
Diffstat (limited to 'src/trace/depixelize/inkscape-depixelize.cpp')
-rw-r--r--src/trace/depixelize/inkscape-depixelize.cpp152
1 files changed, 152 insertions, 0 deletions
diff --git a/src/trace/depixelize/inkscape-depixelize.cpp b/src/trace/depixelize/inkscape-depixelize.cpp
new file mode 100644
index 000000000..4b8bde1d8
--- /dev/null
+++ b/src/trace/depixelize/inkscape-depixelize.cpp
@@ -0,0 +1,152 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * This is the C++ glue between Inkscape and Potrace
+ *
+ * Authors:
+ * Bob Jamison <rjamison@titan.com>
+ * Stéphane Gimenez <dev@gim.name>
+ *
+ * Copyright (C) 2004-2006 Authors
+ *
+ * Released under GNU GPL v2+, read the file 'COPYING' for more information.
+ *
+ * Potrace, the wonderful tracer located at http://potrace.sourceforge.net,
+ * is provided by the generosity of Peter Selinger, to whom we are grateful.
+ *
+ */
+
+#include "inkscape-depixelize.h"
+
+#include <glibmm/i18n.h>
+#include <gtkmm/main.h>
+#include <gtkmm.h>
+#include <iomanip>
+
+#include "desktop.h"
+#include "message-stack.h"
+
+#include "object/sp-path.h"
+
+#include <svg/path-string.h>
+#include <svg/svg.h>
+
+using Glib::ustring;
+
+
+
+namespace Inkscape {
+
+namespace Trace {
+
+namespace Depixelize {
+
+
+/**
+ *
+ */
+DepixelizeTracingEngine::DepixelizeTracingEngine()
+ : keepGoing(1)
+ , traceType(TRACE_VORONOI)
+{
+ params = new ::Tracer::Kopf2011::Options();
+}
+
+
+
+DepixelizeTracingEngine::DepixelizeTracingEngine(TraceType traceType, double curves, int islands, int sparsePixels,
+ double sparseMultiplier)
+ : keepGoing(1)
+ , traceType(traceType)
+{
+ params = new ::Tracer::Kopf2011::Options();
+ params->curvesMultiplier = curves;
+ params->islandsWeight = islands;
+ params->sparsePixelsRadius = sparsePixels;
+ params->sparsePixelsMultiplier = sparseMultiplier;
+ params->nthreads = Inkscape::Preferences::get()->getIntLimited("/options/threading/numthreads",
+#ifdef HAVE_OPENMP
+ omp_get_num_procs(),
+#else
+ 1,
+#endif // HAVE_OPENMP
+ 1, 256);
+}
+
+DepixelizeTracingEngine::~DepixelizeTracingEngine() { delete params; }
+
+std::vector<TracingEngineResult> DepixelizeTracingEngine::trace(Glib::RefPtr<Gdk::Pixbuf> pixbuf)
+{
+ if (pixbuf->get_width() > 256 || pixbuf->get_height() > 256) {
+ char *msg = _("Image looks too big. Process may take a while and it is"
+ " wise to save your document before continuing."
+ "\n\nContinue the procedure (without saving)?");
+ Gtk::MessageDialog dialog(msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK_CANCEL, true);
+
+// if (dialog.run() != Gtk::RESPONSE_OK)
+// return;
+// TODO
+ }
+
+ ::Tracer::Splines splines;
+
+ if (traceType == TRACE_VORONOI)
+ splines = ::Tracer::Kopf2011::to_voronoi(pixbuf, *params);
+ else
+ splines = ::Tracer::Kopf2011::to_splines(pixbuf, *params);
+
+ std::vector<TracingEngineResult> res;
+
+ for (::Tracer::Splines::const_iterator it = splines.begin(), end = splines.end(); it != end; ++it) {
+ /*{
+ SPCSSAttr *css = sp_repr_css_attr_new();
+
+ {
+ gchar b[64];
+ sp_svg_write_color(b, sizeof(b),
+ SP_RGBA32_U_COMPOSE(unsigned(it->rgba[0]),
+ unsigned(it->rgba[1]),
+ unsigned(it->rgba[2]),
+ unsigned(it->rgba[3])));
+
+ sp_repr_css_set_property(css, "fill", b);
+ }
+
+ {
+ Inkscape::CSSOStringStream osalpha;
+ osalpha << float(it->rgba[3]) / 255.;
+ sp_repr_css_set_property(css, "fill-opacity",
+ osalpha.str().c_str());
+ }
+
+ sp_repr_css_set(repr, css, "style");
+ sp_repr_css_attr_unref(css);
+ }
+
+ gchar *str = sp_svg_write_path(it->pathVector);
+ */
+
+ TracingEngineResult r("fill:black;", sp_svg_write_path(it->pathVector), it->pathVector.nodes().size()); //TODO
+ res.push_back(r);
+ }
+ return res;
+}
+
+void DepixelizeTracingEngine::abort() { keepGoing = 0; }
+
+Glib::RefPtr<Gdk::Pixbuf> DepixelizeTracingEngine::preview(Glib::RefPtr<Gdk::Pixbuf> pixbuf) { return pixbuf; }
+
+
+} // namespace Depixelize
+} // namespace Trace
+} // namespace Inkscape
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :