Changeset View
Changeset View
Standalone View
Standalone View
libs/image/kis_gauss_rect_mask_generator.cpp
Context not available. | |||||
21 | #include <cmath> | 21 | #include <cmath> | ||
---|---|---|---|---|---|
22 | #include <algorithm> | 22 | #include <algorithm> | ||
23 | 23 | | |||
24 | #include <config-vc.h> | ||||
25 | #ifdef HAVE_VC | ||||
26 | #if defined(__clang__) | ||||
27 | #pragma GCC diagnostic ignored "-Wundef" | ||||
28 | #pragma GCC diagnostic ignored "-Wlocal-type-template-args" | ||||
29 | #endif | ||||
30 | #if defined _MSC_VER | ||||
31 | // Lets shut up the "possible loss of data" and "forcing value to bool 'true' or 'false' | ||||
32 | #pragma warning ( push ) | ||||
33 | #pragma warning ( disable : 4244 ) | ||||
34 | #pragma warning ( disable : 4800 ) | ||||
35 | #endif | ||||
36 | #include <Vc/Vc> | ||||
37 | #include <Vc/IO> | ||||
38 | #if defined _MSC_VER | ||||
39 | #pragma warning ( pop ) | ||||
40 | #endif | ||||
41 | #endif | ||||
42 | | ||||
24 | #include <QDomDocument> | 43 | #include <QDomDocument> | ||
25 | #include <QVector> | 44 | #include <QVector> | ||
26 | #include <QPointF> | 45 | #include <QPointF> | ||
Context not available. | |||||
30 | #include "kis_fast_math.h" | 49 | #include "kis_fast_math.h" | ||
31 | 50 | | |||
32 | #include "kis_base_mask_generator.h" | 51 | #include "kis_base_mask_generator.h" | ||
33 | #include "kis_gauss_rect_mask_generator.h" | | |||
34 | #include "kis_antialiasing_fade_maker.h" | 52 | #include "kis_antialiasing_fade_maker.h" | ||
53 | #include "kis_brush_mask_applicator_factories.h" | ||||
54 | #include "kis_brush_mask_applicator_base.h" | ||||
55 | #include "kis_gauss_rect_mask_generator.h" | ||||
56 | #include "kis_gauss_rect_mask_generator_p.h" | ||||
35 | 57 | | |||
36 | #define M_SQRT_2 1.41421356237309504880 | 58 | #define M_SQRT_2 1.41421356237309504880 | ||
37 | 59 | | |||
Context not available. | |||||
41 | #define erf(x) boost::math::erf(x) | 63 | #define erf(x) boost::math::erf(x) | ||
42 | #endif | 64 | #endif | ||
43 | 65 | | |||
44 | struct Q_DECL_HIDDEN KisGaussRectangleMaskGenerator::Private | | |||
45 | { | | |||
46 | Private(bool enableAntialiasing) | | |||
47 | : fadeMaker(*this, enableAntialiasing) | | |||
48 | { | | |||
49 | } | | |||
50 | | ||||
51 | Private(const Private &rhs) | | |||
52 | : xfade(rhs.xfade), | | |||
53 | yfade(rhs.yfade), | | |||
54 | halfWidth(rhs.halfWidth), | | |||
55 | halfHeight(rhs.halfHeight), | | |||
56 | alphafactor(rhs.alphafactor), | | |||
57 | fadeMaker(rhs.fadeMaker, *this) | | |||
58 | { | | |||
59 | } | | |||
60 | | ||||
61 | qreal xfade, yfade; | | |||
62 | qreal halfWidth, halfHeight; | | |||
63 | qreal alphafactor; | | |||
64 | 66 | | |||
65 | KisAntialiasingFadeMaker2D <Private> fadeMaker; | | |||
66 | | ||||
67 | inline quint8 value(qreal x, qreal y) const; | | |||
68 | }; | | |||
69 | 67 | | |||
70 | KisGaussRectangleMaskGenerator::KisGaussRectangleMaskGenerator(qreal diameter, qreal ratio, qreal fh, qreal fv, int spikes, bool antialiasEdges) | 68 | KisGaussRectangleMaskGenerator::KisGaussRectangleMaskGenerator(qreal diameter, qreal ratio, qreal fh, qreal fv, int spikes, bool antialiasEdges) | ||
71 | : KisMaskGenerator(diameter, ratio, fh, fv, spikes, antialiasEdges, RECTANGLE, GaussId), d(new Private(antialiasEdges)) | 69 | : KisMaskGenerator(diameter, ratio, fh, fv, spikes, antialiasEdges, RECTANGLE, GaussId), d(new Private(antialiasEdges)) | ||
72 | { | 70 | { | ||
73 | setScale(1.0, 1.0); | 71 | setScale(1.0, 1.0); | ||
72 | | ||||
73 | d->applicator.reset(createOptimizedClass<MaskApplicatorFactory<KisGaussRectangleMaskGenerator, KisBrushMaskVectorApplicator> >(this)); | ||||
74 | } | 74 | } | ||
75 | 75 | | |||
76 | KisGaussRectangleMaskGenerator::KisGaussRectangleMaskGenerator(const KisGaussRectangleMaskGenerator &rhs) | 76 | KisGaussRectangleMaskGenerator::KisGaussRectangleMaskGenerator(const KisGaussRectangleMaskGenerator &rhs) | ||
77 | : KisMaskGenerator(rhs), | 77 | : KisMaskGenerator(rhs), | ||
78 | d(new Private(*rhs.d)) | 78 | d(new Private(*rhs.d)) | ||
79 | { | 79 | { | ||
80 | d->applicator.reset(createOptimizedClass<MaskApplicatorFactory<KisGaussRectangleMaskGenerator, KisBrushMaskVectorApplicator> >(this)); | ||||
80 | } | 81 | } | ||
81 | 82 | | |||
82 | KisMaskGenerator* KisGaussRectangleMaskGenerator::clone() const | 83 | KisMaskGenerator* KisGaussRectangleMaskGenerator::clone() const | ||
Context not available. | |||||
99 | d->halfHeight = height * 0.5 - 2.5 * yfade; | 100 | d->halfHeight = height * 0.5 - 2.5 * yfade; | ||
100 | d->alphafactor = 255.0 / (4.0 * erf(d->halfWidth * d->xfade) * erf(d->halfHeight * d->yfade)); | 101 | d->alphafactor = 255.0 / (4.0 * erf(d->halfWidth * d->xfade) * erf(d->halfHeight * d->yfade)); | ||
101 | 102 | | |||
103 | if (isnan(d->alphafactor)) d->alphafactor = 0.0f; // erf can return nan if ratio is 0 | ||||
104 | | ||||
102 | d->fadeMaker.setLimits(0.5 * width, 0.5 * height); | 105 | d->fadeMaker.setLimits(0.5 * width, 0.5 * height); | ||
103 | } | 106 | } | ||
104 | 107 | | |||
Context not available. | |||||
126 | 129 | | |||
127 | return d->value(xr, yr); | 130 | return d->value(xr, yr); | ||
128 | } | 131 | } | ||
132 | | ||||
133 | bool KisGaussRectangleMaskGenerator::shouldVectorize() const | ||||
134 | { | ||||
135 | return !shouldSupersample() && spikes() == 2; | ||||
136 | } | ||||
137 | | ||||
138 | KisBrushMaskApplicatorBase* KisGaussRectangleMaskGenerator::applicator() | ||||
139 | { | ||||
140 | return d->applicator.data(); | ||||
141 | } | ||||
142 | | ||||
143 | void KisGaussRectangleMaskGenerator::resetMaskApplicator(bool forceScalar) | ||||
144 | { | ||||
145 | d->applicator.reset(createOptimizedClass<MaskApplicatorFactory<KisGaussRectangleMaskGenerator, KisBrushMaskVectorApplicator> >(this,forceScalar)); | ||||
146 | } | ||||
Context not available. |