File indexing completed on 2024-05-12 15:58:10

0001 /*
0002  *  SPDX-FileCopyrightText: 2012 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef __KIS_BRUSH_MASK_APPLICATOR_BASE_H
0008 #define __KIS_BRUSH_MASK_APPLICATOR_BASE_H
0009 
0010 #include "kis_types.h"
0011 #include "kis_fixed_paint_device.h"
0012 #include "math.h"
0013 
0014 
0015 struct MaskProcessingData {
0016     MaskProcessingData(KisFixedPaintDeviceSP _device,
0017                        const KoColorSpace* _colorSpace,
0018                        const quint8* _color,
0019                        qreal _randomness,
0020                        qreal _density,
0021                        double _centerX,
0022                        double _centerY,
0023                        double _angle)
0024         {
0025             device = _device;
0026             colorSpace = _colorSpace;
0027             color = _color;
0028             randomness = _randomness;
0029             density = _density;
0030             centerX = _centerX;
0031             centerY = _centerY;
0032             cosa = cos(_angle);
0033             sina = sin(_angle);
0034             pixelSize = colorSpace->pixelSize();
0035         }
0036 
0037 
0038 
0039     KisFixedPaintDeviceSP device;
0040     const KoColorSpace* colorSpace;
0041     const quint8* color;
0042     qreal randomness;
0043     qreal density;
0044     double centerX;
0045     double centerY;
0046 
0047     double cosa;
0048     double sina;
0049 
0050     qint32 pixelSize;
0051 };
0052 
0053 class KisBrushMaskApplicatorBase
0054 {
0055 public:
0056     virtual ~KisBrushMaskApplicatorBase() {}
0057     virtual void process(const QRect &rect) = 0;
0058 
0059     inline void initializeData(const MaskProcessingData *data) {
0060         m_d = data;
0061     }
0062 
0063 protected:
0064     const MaskProcessingData *m_d;
0065 };
0066 
0067 struct OperatorWrapper {
0068     OperatorWrapper(KisBrushMaskApplicatorBase *applicator)
0069         : m_applicator(applicator) {}
0070 
0071     inline void operator() (const QRect& rect) {
0072         m_applicator->process(rect);
0073     }
0074 
0075     KisBrushMaskApplicatorBase *m_applicator;
0076 };
0077 
0078 #endif /* __KIS_BRUSH_MASK_APPLICATOR_BASE_H */