From c853ffb5b2f75f5a889ed2e3ef89b818a736e87a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:50:49 +0200 Subject: Adding upstream version 1.3+ds. Signed-off-by: Daniel Baumann --- src/trace/potrace/inkscape-potrace.h | 140 +++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 src/trace/potrace/inkscape-potrace.h (limited to 'src/trace/potrace/inkscape-potrace.h') diff --git a/src/trace/potrace/inkscape-potrace.h b/src/trace/potrace/inkscape-potrace.h new file mode 100644 index 0000000..0e4a9c6 --- /dev/null +++ b/src/trace/potrace/inkscape-potrace.h @@ -0,0 +1,140 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * This is the C++ glue between Inkscape and Potrace + * + * Authors: + * Bob Jamison + * Stéphane Gimenez + * + * 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. + * + */ +#ifndef INKSCAPE_TRACE_POTRACE_H +#define INKSCAPE_TRACE_POTRACE_H + +#include +#include +#include +#include <2geom/point.h> +#include <2geom/path-sink.h> +#include "trace/trace.h" +#include "trace/imagemap.h" +using potrace_param_t = struct potrace_param_s; +using potrace_path_t = struct potrace_path_s; + +namespace Inkscape { +namespace Trace { +namespace Potrace { + +enum class TraceType +{ + BRIGHTNESS, + BRIGHTNESS_MULTI, + CANNY, + QUANT, + QUANT_COLOR, + QUANT_MONO, + // Used in tracedialog.cpp + AUTOTRACE_SINGLE, + AUTOTRACE_MULTI, + AUTOTRACE_CENTERLINE +}; + +// Todo: Make lib2geom types hashable. +struct geom_point_hash +{ + std::size_t operator()(Geom::Point const &pt) const + { + std::size_t hash = 0; + boost::hash_combine(hash, pt.x()); + boost::hash_combine(hash, pt.y()); + return hash; + } +}; + +class PotraceTracingEngine final + : public TracingEngine +{ +public: + PotraceTracingEngine(); + PotraceTracingEngine(TraceType traceType, + bool invert, + int quantizationNrColors, + double brightnessThreshold, + double brightnessFloor, + double cannyHighThreshold, + int multiScanNrColors, + bool multiScanStack, + bool multiScanSmooth , + bool multiScanRemoveBackground); + ~PotraceTracingEngine() override; + + TraceResult trace(Glib::RefPtr const &pixbuf, Async::Progress &progress) override; + Glib::RefPtr preview(Glib::RefPtr const &pixbuf) override; + + TraceResult traceGrayMap(GrayMap const &grayMap, Async::Progress &progress); + + void setOptiCurve(int); + void setOptTolerance(double); + void setAlphaMax(double); + void setTurdSize(int); + +private: + potrace_param_t *potraceParams; + + TraceType traceType = TraceType::BRIGHTNESS; + + // Whether the image should be inverted at the end. + bool invert = false; + + // Color -> b&w quantization + int quantizationNrColors = 8; + + // Brightness items + double brightnessThreshold = 0.45; + double brightnessFloor = 0.0; + + // Canny items + double cannyHighThreshold = 0.65; + + // Color -> multiscan quantization + int multiScanNrColors = 8; + bool multiScanStack = true; // do we tile or stack? + bool multiScanSmooth = false; // do we use gaussian filter? + bool multiScanRemoveBackground = false; // do we remove the bottom trace? + + void common_init(); + + TraceResult traceQuant (Glib::RefPtr const &pixbuf, Async::Progress &progress); + TraceResult traceBrightnessMulti(Glib::RefPtr const &pixbuf, Async::Progress &progress); + TraceResult traceSingle (Glib::RefPtr const &pixbuf, Async::Progress &progress); + + IndexedMap filterIndexed(Glib::RefPtr const &pixbuf) const; + std::optional filter(Glib::RefPtr const &pixbuf) const; + + Geom::PathVector grayMapToPath(GrayMap const &gm, Async::Progress &progress); + + void writePaths(potrace_path_t *paths, Geom::PathBuilder &builder, std::unordered_set &points, Async::Progress &progress) const; +}; + +} // namespace Potrace +} // namespace Trace +} // namespace Inkscape + +#endif // INKSCAPE_TRACE_POTRACE_H + +/* + 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 : -- cgit v1.2.3