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 <QObject> 0010 0011 #include "math/bezier/bezier.hpp" 0012 #include "model/shapes/image.hpp" 0013 #include "model/shapes/group.hpp" 0014 #include "utils/trace.hpp" 0015 0016 namespace glaxnimate::utils::trace { 0017 0018 class TraceWrapper : public QObject 0019 { 0020 Q_OBJECT 0021 0022 public: 0023 struct TraceResult 0024 { 0025 QColor color; 0026 math::bezier::MultiBezier bezier; 0027 std::vector<QRectF> rects; 0028 }; 0029 0030 enum Preset 0031 { 0032 ComplexPreset, 0033 FlatPreset, 0034 PixelPreset, 0035 }; 0036 0037 explicit TraceWrapper(model::Image* image); 0038 explicit TraceWrapper(model::Composition* comp, const QImage& image, const QString& name); 0039 ~TraceWrapper(); 0040 0041 void trace_mono(const QColor& color, bool inverted, int alpha_threshold, std::vector<TraceResult>& result); 0042 void trace_exact(const std::vector<QRgb>& colors, int tolerance, std::vector<TraceResult>& result); 0043 void trace_closest(const std::vector<QRgb>& colors, std::vector<TraceResult>& result); 0044 void trace_pixel(std::vector<TraceResult>& result); 0045 0046 model::Group* apply(std::vector<TraceResult>& result, qreal stroke_width); 0047 0048 QSize size() const; 0049 0050 TraceOptions& options(); 0051 const QImage& image() const; 0052 0053 const std::vector<QRgb>& eem_colors() const; 0054 0055 Preset preset_suggestion() const; 0056 void trace_preset(Preset preset, int complex_posterization, std::vector<QRgb> &colors, std::vector<TraceResult>& result); 0057 0058 Q_SIGNALS: 0059 void progress_max_changed(int max); 0060 void progress_changed(int value); 0061 0062 private: 0063 class Private; 0064 std::unique_ptr<Private> d; 0065 0066 }; 0067 0068 } // namespace glaxnimate::utils::trace