File indexing completed on 2024-12-15 04:01:21

0001 /*
0002  * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #pragma once
0008 
0009 #include <memory>
0010 #include <QImage>
0011 #include <QObject>
0012 
0013 #include "math/bezier/bezier.hpp"
0014 
0015 namespace glaxnimate::utils::trace {
0016 
0017 class TraceOptions
0018 {
0019 public:
0020     TraceOptions();
0021     ~TraceOptions();
0022 
0023     qreal smoothness() const;
0024     void set_smoothness(qreal smoothness);
0025 
0026     int min_area() const;
0027     void set_min_area(int min_area);
0028 
0029 private:
0030     friend class Tracer;
0031     class Private;
0032     std::unique_ptr<Private> d;
0033 };
0034 
0035 class Tracer : public QObject
0036 {
0037     Q_OBJECT
0038 public:
0039     Tracer(const QImage& image, const TraceOptions& options);
0040     ~Tracer();
0041 
0042     bool trace(math::bezier::MultiBezier& output);
0043 
0044     static QString potrace_version();
0045 
0046     void set_progress_range(double min, double max);
0047 
0048     void set_target_alpha(int threshold, bool invert);
0049     void set_target_color(const QColor& color, qint32 tolerance);
0050     void set_target_index(uchar index);
0051 
0052 Q_SIGNALS:
0053     void progress(double value);
0054 
0055 private:
0056     class Private;
0057     std::unique_ptr<Private> d;
0058 };
0059 
0060 std::map<QRgb, std::vector<QRectF>> trace_pixels(QImage image);
0061 
0062 } // namespace glaxnimate::utils::trace